1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
33 * o Accepted ethtool cleanup patch from Stephen Hemminger
35 * o applied Anton's patch to resolve tx hang in hardware
36 * o Applied Andrew Mortons patch - e1000 stops working after resume
39 char e1000_driver_name[] = "e1000";
40 char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
41 #ifndef CONFIG_E1000_NAPI
44 #define DRIVERNAPI "-NAPI"
46 #define DRV_VERSION "6.0.60-k2"DRIVERNAPI
47 char e1000_driver_version[] = DRV_VERSION;
48 char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
50 /* e1000_pci_tbl - PCI Device ID Table
52 * Last entry must be all 0s
55 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
57 static struct pci_device_id e1000_pci_tbl[] = {
58 INTEL_E1000_ETHERNET_DEVICE(0x1000),
59 INTEL_E1000_ETHERNET_DEVICE(0x1001),
60 INTEL_E1000_ETHERNET_DEVICE(0x1004),
61 INTEL_E1000_ETHERNET_DEVICE(0x1008),
62 INTEL_E1000_ETHERNET_DEVICE(0x1009),
63 INTEL_E1000_ETHERNET_DEVICE(0x100C),
64 INTEL_E1000_ETHERNET_DEVICE(0x100D),
65 INTEL_E1000_ETHERNET_DEVICE(0x100E),
66 INTEL_E1000_ETHERNET_DEVICE(0x100F),
67 INTEL_E1000_ETHERNET_DEVICE(0x1010),
68 INTEL_E1000_ETHERNET_DEVICE(0x1011),
69 INTEL_E1000_ETHERNET_DEVICE(0x1012),
70 INTEL_E1000_ETHERNET_DEVICE(0x1013),
71 INTEL_E1000_ETHERNET_DEVICE(0x1014),
72 INTEL_E1000_ETHERNET_DEVICE(0x1015),
73 INTEL_E1000_ETHERNET_DEVICE(0x1016),
74 INTEL_E1000_ETHERNET_DEVICE(0x1017),
75 INTEL_E1000_ETHERNET_DEVICE(0x1018),
76 INTEL_E1000_ETHERNET_DEVICE(0x1019),
77 INTEL_E1000_ETHERNET_DEVICE(0x101A),
78 INTEL_E1000_ETHERNET_DEVICE(0x101D),
79 INTEL_E1000_ETHERNET_DEVICE(0x101E),
80 INTEL_E1000_ETHERNET_DEVICE(0x1026),
81 INTEL_E1000_ETHERNET_DEVICE(0x1027),
82 INTEL_E1000_ETHERNET_DEVICE(0x1028),
83 INTEL_E1000_ETHERNET_DEVICE(0x1075),
84 INTEL_E1000_ETHERNET_DEVICE(0x1076),
85 INTEL_E1000_ETHERNET_DEVICE(0x1077),
86 INTEL_E1000_ETHERNET_DEVICE(0x1078),
87 INTEL_E1000_ETHERNET_DEVICE(0x1079),
88 INTEL_E1000_ETHERNET_DEVICE(0x107A),
89 INTEL_E1000_ETHERNET_DEVICE(0x107B),
90 INTEL_E1000_ETHERNET_DEVICE(0x107C),
91 INTEL_E1000_ETHERNET_DEVICE(0x108A),
92 INTEL_E1000_ETHERNET_DEVICE(0x108B),
93 INTEL_E1000_ETHERNET_DEVICE(0x108C),
94 INTEL_E1000_ETHERNET_DEVICE(0x1099),
95 /* required last entry */
99 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
101 int e1000_up(struct e1000_adapter *adapter);
102 void e1000_down(struct e1000_adapter *adapter);
103 void e1000_reset(struct e1000_adapter *adapter);
104 int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
105 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
106 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
107 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
108 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
109 int e1000_setup_tx_resources(struct e1000_adapter *adapter,
110 struct e1000_tx_ring *txdr);
111 int e1000_setup_rx_resources(struct e1000_adapter *adapter,
112 struct e1000_rx_ring *rxdr);
113 void e1000_free_tx_resources(struct e1000_adapter *adapter,
114 struct e1000_tx_ring *tx_ring);
115 void e1000_free_rx_resources(struct e1000_adapter *adapter,
116 struct e1000_rx_ring *rx_ring);
117 void e1000_update_stats(struct e1000_adapter *adapter);
119 /* Local Function Prototypes */
121 static int e1000_init_module(void);
122 static void e1000_exit_module(void);
123 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
124 static void __devexit e1000_remove(struct pci_dev *pdev);
125 static int e1000_alloc_queues(struct e1000_adapter *adapter);
126 #ifdef CONFIG_E1000_MQ
127 static void e1000_setup_queue_mapping(struct e1000_adapter *adapter);
129 static int e1000_sw_init(struct e1000_adapter *adapter);
130 static int e1000_open(struct net_device *netdev);
131 static int e1000_close(struct net_device *netdev);
132 static void e1000_configure_tx(struct e1000_adapter *adapter);
133 static void e1000_configure_rx(struct e1000_adapter *adapter);
134 static void e1000_setup_rctl(struct e1000_adapter *adapter);
135 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
136 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
137 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
138 struct e1000_tx_ring *tx_ring);
139 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
140 struct e1000_rx_ring *rx_ring);
141 static void e1000_set_multi(struct net_device *netdev);
142 static void e1000_update_phy_info(unsigned long data);
143 static void e1000_watchdog(unsigned long data);
144 static void e1000_watchdog_task(struct e1000_adapter *adapter);
145 static void e1000_82547_tx_fifo_stall(unsigned long data);
146 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
147 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
148 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
149 static int e1000_set_mac(struct net_device *netdev, void *p);
150 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
151 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
152 struct e1000_tx_ring *tx_ring);
153 #ifdef CONFIG_E1000_NAPI
154 static int e1000_clean(struct net_device *poll_dev, int *budget);
155 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
156 struct e1000_rx_ring *rx_ring,
157 int *work_done, int work_to_do);
158 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
159 struct e1000_rx_ring *rx_ring,
160 int *work_done, int work_to_do);
162 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
163 struct e1000_rx_ring *rx_ring);
164 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
165 struct e1000_rx_ring *rx_ring);
167 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
168 struct e1000_rx_ring *rx_ring);
169 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
170 struct e1000_rx_ring *rx_ring);
171 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
172 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
174 void e1000_set_ethtool_ops(struct net_device *netdev);
175 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
176 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
177 static void e1000_tx_timeout(struct net_device *dev);
178 static void e1000_tx_timeout_task(struct net_device *dev);
179 static void e1000_smartspeed(struct e1000_adapter *adapter);
180 static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
181 struct sk_buff *skb);
183 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
184 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
185 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
186 static void e1000_restore_vlan(struct e1000_adapter *adapter);
188 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
190 static int e1000_resume(struct pci_dev *pdev);
193 #ifdef CONFIG_NET_POLL_CONTROLLER
194 /* for netdump / net console */
195 static void e1000_netpoll (struct net_device *netdev);
198 #ifdef CONFIG_E1000_MQ
199 /* for multiple Rx queues */
200 void e1000_rx_schedule(void *data);
203 /* Exported from other modules */
205 extern void e1000_check_options(struct e1000_adapter *adapter);
207 static struct pci_driver e1000_driver = {
208 .name = e1000_driver_name,
209 .id_table = e1000_pci_tbl,
210 .probe = e1000_probe,
211 .remove = __devexit_p(e1000_remove),
212 /* Power Managment Hooks */
214 .suspend = e1000_suspend,
215 .resume = e1000_resume
219 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
220 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
221 MODULE_LICENSE("GPL");
222 MODULE_VERSION(DRV_VERSION);
224 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
225 module_param(debug, int, 0);
226 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
229 * e1000_init_module - Driver Registration Routine
231 * e1000_init_module is the first routine called when the driver is
232 * loaded. All it does is register with the PCI subsystem.
236 e1000_init_module(void)
239 printk(KERN_INFO "%s - version %s\n",
240 e1000_driver_string, e1000_driver_version);
242 printk(KERN_INFO "%s\n", e1000_copyright);
244 ret = pci_module_init(&e1000_driver);
249 module_init(e1000_init_module);
252 * e1000_exit_module - Driver Exit Cleanup Routine
254 * e1000_exit_module is called just before the driver is removed
259 e1000_exit_module(void)
261 pci_unregister_driver(&e1000_driver);
264 module_exit(e1000_exit_module);
267 * e1000_irq_disable - Mask off interrupt generation on the NIC
268 * @adapter: board private structure
272 e1000_irq_disable(struct e1000_adapter *adapter)
274 atomic_inc(&adapter->irq_sem);
275 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
276 E1000_WRITE_FLUSH(&adapter->hw);
277 synchronize_irq(adapter->pdev->irq);
281 * e1000_irq_enable - Enable default interrupt generation settings
282 * @adapter: board private structure
286 e1000_irq_enable(struct e1000_adapter *adapter)
288 if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
289 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
290 E1000_WRITE_FLUSH(&adapter->hw);
294 e1000_update_mng_vlan(struct e1000_adapter *adapter)
296 struct net_device *netdev = adapter->netdev;
297 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
298 uint16_t old_vid = adapter->mng_vlan_id;
300 if(!adapter->vlgrp->vlan_devices[vid]) {
301 if(adapter->hw.mng_cookie.status &
302 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
303 e1000_vlan_rx_add_vid(netdev, vid);
304 adapter->mng_vlan_id = vid;
306 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
308 if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
310 !adapter->vlgrp->vlan_devices[old_vid])
311 e1000_vlan_rx_kill_vid(netdev, old_vid);
317 e1000_up(struct e1000_adapter *adapter)
319 struct net_device *netdev = adapter->netdev;
322 /* hardware has been reset, we need to reload some things */
324 /* Reset the PHY if it was previously powered down */
325 if(adapter->hw.media_type == e1000_media_type_copper) {
327 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
328 if(mii_reg & MII_CR_POWER_DOWN)
329 e1000_phy_reset(&adapter->hw);
332 e1000_set_multi(netdev);
334 e1000_restore_vlan(adapter);
336 e1000_configure_tx(adapter);
337 e1000_setup_rctl(adapter);
338 e1000_configure_rx(adapter);
339 for (i = 0; i < adapter->num_queues; i++)
340 adapter->alloc_rx_buf(adapter, &adapter->rx_ring[i]);
342 #ifdef CONFIG_PCI_MSI
343 if(adapter->hw.mac_type > e1000_82547_rev_2) {
344 adapter->have_msi = TRUE;
345 if((err = pci_enable_msi(adapter->pdev))) {
347 "Unable to allocate MSI interrupt Error: %d\n", err);
348 adapter->have_msi = FALSE;
352 if((err = request_irq(adapter->pdev->irq, &e1000_intr,
353 SA_SHIRQ | SA_SAMPLE_RANDOM,
354 netdev->name, netdev))) {
356 "Unable to allocate interrupt Error: %d\n", err);
360 mod_timer(&adapter->watchdog_timer, jiffies);
362 #ifdef CONFIG_E1000_NAPI
363 netif_poll_enable(netdev);
365 e1000_irq_enable(adapter);
371 e1000_down(struct e1000_adapter *adapter)
373 struct net_device *netdev = adapter->netdev;
375 e1000_irq_disable(adapter);
376 #ifdef CONFIG_E1000_MQ
377 while (atomic_read(&adapter->rx_sched_call_data.count) != 0);
379 free_irq(adapter->pdev->irq, netdev);
380 #ifdef CONFIG_PCI_MSI
381 if(adapter->hw.mac_type > e1000_82547_rev_2 &&
382 adapter->have_msi == TRUE)
383 pci_disable_msi(adapter->pdev);
385 del_timer_sync(&adapter->tx_fifo_stall_timer);
386 del_timer_sync(&adapter->watchdog_timer);
387 del_timer_sync(&adapter->phy_info_timer);
389 #ifdef CONFIG_E1000_NAPI
390 netif_poll_disable(netdev);
392 adapter->link_speed = 0;
393 adapter->link_duplex = 0;
394 netif_carrier_off(netdev);
395 netif_stop_queue(netdev);
397 e1000_reset(adapter);
398 e1000_clean_all_tx_rings(adapter);
399 e1000_clean_all_rx_rings(adapter);
401 /* If WoL is not enabled
402 * and management mode is not IAMT
403 * Power down the PHY so no link is implied when interface is down */
404 if(!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
405 adapter->hw.media_type == e1000_media_type_copper &&
406 !e1000_check_mng_mode(&adapter->hw) &&
407 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN)) {
409 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
410 mii_reg |= MII_CR_POWER_DOWN;
411 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
417 e1000_reset(struct e1000_adapter *adapter)
419 struct net_device *netdev = adapter->netdev;
421 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
422 uint16_t fc_low_water_mark = E1000_FC_LOW_DIFF;
424 /* Repartition Pba for greater than 9k mtu
425 * To take effect CTRL.RST is required.
428 switch (adapter->hw.mac_type) {
430 case e1000_82547_rev_2:
445 if((adapter->hw.mac_type != e1000_82573) &&
446 (adapter->rx_buffer_len > E1000_RXBUFFER_8192)) {
447 pba -= 8; /* allocate more FIFO for Tx */
448 /* send an XOFF when there is enough space in the
449 * Rx FIFO to hold one extra full size Rx packet
451 fc_high_water_mark = netdev->mtu + ENET_HEADER_SIZE +
452 ETHERNET_FCS_SIZE + 1;
453 fc_low_water_mark = fc_high_water_mark + 8;
457 if(adapter->hw.mac_type == e1000_82547) {
458 adapter->tx_fifo_head = 0;
459 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
460 adapter->tx_fifo_size =
461 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
462 atomic_set(&adapter->tx_fifo_stall, 0);
465 E1000_WRITE_REG(&adapter->hw, PBA, pba);
467 /* flow control settings */
468 adapter->hw.fc_high_water = (pba << E1000_PBA_BYTES_SHIFT) -
470 adapter->hw.fc_low_water = (pba << E1000_PBA_BYTES_SHIFT) -
472 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
473 adapter->hw.fc_send_xon = 1;
474 adapter->hw.fc = adapter->hw.original_fc;
476 /* Allow time for pending master requests to run */
477 e1000_reset_hw(&adapter->hw);
478 if(adapter->hw.mac_type >= e1000_82544)
479 E1000_WRITE_REG(&adapter->hw, WUC, 0);
480 if(e1000_init_hw(&adapter->hw))
481 DPRINTK(PROBE, ERR, "Hardware Error\n");
482 e1000_update_mng_vlan(adapter);
483 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
484 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
486 e1000_reset_adaptive(&adapter->hw);
487 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
488 if (adapter->en_mng_pt) {
489 manc = E1000_READ_REG(&adapter->hw, MANC);
490 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
491 E1000_WRITE_REG(&adapter->hw, MANC, manc);
496 * e1000_probe - Device Initialization Routine
497 * @pdev: PCI device information struct
498 * @ent: entry in e1000_pci_tbl
500 * Returns 0 on success, negative on failure
502 * e1000_probe initializes an adapter identified by a pci_dev structure.
503 * The OS initialization, configuring of the adapter private structure,
504 * and a hardware reset occur.
508 e1000_probe(struct pci_dev *pdev,
509 const struct pci_device_id *ent)
511 struct net_device *netdev;
512 struct e1000_adapter *adapter;
513 unsigned long mmio_start, mmio_len;
517 static int cards_found = 0;
518 int i, err, pci_using_dac;
519 uint16_t eeprom_data;
520 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
521 if((err = pci_enable_device(pdev)))
524 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
527 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
528 E1000_ERR("No usable DMA configuration, aborting\n");
534 if((err = pci_request_regions(pdev, e1000_driver_name)))
537 pci_set_master(pdev);
539 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
542 goto err_alloc_etherdev;
545 SET_MODULE_OWNER(netdev);
546 SET_NETDEV_DEV(netdev, &pdev->dev);
548 pci_set_drvdata(pdev, netdev);
549 adapter = netdev_priv(netdev);
550 adapter->netdev = netdev;
551 adapter->pdev = pdev;
552 adapter->hw.back = adapter;
553 adapter->msg_enable = (1 << debug) - 1;
555 mmio_start = pci_resource_start(pdev, BAR_0);
556 mmio_len = pci_resource_len(pdev, BAR_0);
558 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
559 if(!adapter->hw.hw_addr) {
564 for(i = BAR_1; i <= BAR_5; i++) {
565 if(pci_resource_len(pdev, i) == 0)
567 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
568 adapter->hw.io_base = pci_resource_start(pdev, i);
573 netdev->open = &e1000_open;
574 netdev->stop = &e1000_close;
575 netdev->hard_start_xmit = &e1000_xmit_frame;
576 netdev->get_stats = &e1000_get_stats;
577 netdev->set_multicast_list = &e1000_set_multi;
578 netdev->set_mac_address = &e1000_set_mac;
579 netdev->change_mtu = &e1000_change_mtu;
580 netdev->do_ioctl = &e1000_ioctl;
581 e1000_set_ethtool_ops(netdev);
582 netdev->tx_timeout = &e1000_tx_timeout;
583 netdev->watchdog_timeo = 5 * HZ;
584 #ifdef CONFIG_E1000_NAPI
585 netdev->poll = &e1000_clean;
588 netdev->vlan_rx_register = e1000_vlan_rx_register;
589 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
590 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
591 #ifdef CONFIG_NET_POLL_CONTROLLER
592 netdev->poll_controller = e1000_netpoll;
594 strcpy(netdev->name, pci_name(pdev));
596 netdev->mem_start = mmio_start;
597 netdev->mem_end = mmio_start + mmio_len;
598 netdev->base_addr = adapter->hw.io_base;
600 adapter->bd_number = cards_found;
602 /* setup the private structure */
604 if((err = e1000_sw_init(adapter)))
607 if((err = e1000_check_phy_reset_block(&adapter->hw)))
608 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
610 if(adapter->hw.mac_type >= e1000_82543) {
611 netdev->features = NETIF_F_SG |
615 NETIF_F_HW_VLAN_FILTER;
619 if((adapter->hw.mac_type >= e1000_82544) &&
620 (adapter->hw.mac_type != e1000_82547))
621 netdev->features |= NETIF_F_TSO;
623 #ifdef NETIF_F_TSO_IPV6
624 if(adapter->hw.mac_type > e1000_82547_rev_2)
625 netdev->features |= NETIF_F_TSO_IPV6;
629 netdev->features |= NETIF_F_HIGHDMA;
631 /* hard_start_xmit is safe against parallel locking */
632 netdev->features |= NETIF_F_LLTX;
634 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
636 /* before reading the EEPROM, reset the controller to
637 * put the device in a known good starting state */
639 e1000_reset_hw(&adapter->hw);
641 /* make sure the EEPROM is good */
643 if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
644 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
649 /* copy the MAC address out of the EEPROM */
651 if(e1000_read_mac_addr(&adapter->hw))
652 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
653 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
654 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
656 if(!is_valid_ether_addr(netdev->perm_addr)) {
657 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
662 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
664 e1000_get_bus_info(&adapter->hw);
666 init_timer(&adapter->tx_fifo_stall_timer);
667 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
668 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
670 init_timer(&adapter->watchdog_timer);
671 adapter->watchdog_timer.function = &e1000_watchdog;
672 adapter->watchdog_timer.data = (unsigned long) adapter;
674 INIT_WORK(&adapter->watchdog_task,
675 (void (*)(void *))e1000_watchdog_task, adapter);
677 init_timer(&adapter->phy_info_timer);
678 adapter->phy_info_timer.function = &e1000_update_phy_info;
679 adapter->phy_info_timer.data = (unsigned long) adapter;
681 INIT_WORK(&adapter->tx_timeout_task,
682 (void (*)(void *))e1000_tx_timeout_task, netdev);
684 /* we're going to reset, so assume we have no link for now */
686 netif_carrier_off(netdev);
687 netif_stop_queue(netdev);
689 e1000_check_options(adapter);
691 /* Initial Wake on LAN setting
692 * If APM wake is enabled in the EEPROM,
693 * enable the ACPI Magic Packet filter
696 switch(adapter->hw.mac_type) {
697 case e1000_82542_rev2_0:
698 case e1000_82542_rev2_1:
702 e1000_read_eeprom(&adapter->hw,
703 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
704 eeprom_apme_mask = E1000_EEPROM_82544_APM;
707 case e1000_82546_rev_3:
708 if((E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
709 && (adapter->hw.media_type == e1000_media_type_copper)) {
710 e1000_read_eeprom(&adapter->hw,
711 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
716 e1000_read_eeprom(&adapter->hw,
717 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
720 if(eeprom_data & eeprom_apme_mask)
721 adapter->wol |= E1000_WUFC_MAG;
723 /* reset the hardware with the new settings */
724 e1000_reset(adapter);
726 /* Let firmware know the driver has taken over */
727 switch(adapter->hw.mac_type) {
730 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
731 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
732 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
735 swsm = E1000_READ_REG(&adapter->hw, SWSM);
736 E1000_WRITE_REG(&adapter->hw, SWSM,
737 swsm | E1000_SWSM_DRV_LOAD);
743 strcpy(netdev->name, "eth%d");
744 if((err = register_netdev(netdev)))
747 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
755 iounmap(adapter->hw.hw_addr);
759 pci_release_regions(pdev);
764 * e1000_remove - Device Removal Routine
765 * @pdev: PCI device information struct
767 * e1000_remove is called by the PCI subsystem to alert the driver
768 * that it should release a PCI device. The could be caused by a
769 * Hot-Plug event, or because the driver is going to be removed from
773 static void __devexit
774 e1000_remove(struct pci_dev *pdev)
776 struct net_device *netdev = pci_get_drvdata(pdev);
777 struct e1000_adapter *adapter = netdev_priv(netdev);
781 flush_scheduled_work();
782 #ifdef CONFIG_E1000_NAPI
786 if(adapter->hw.mac_type >= e1000_82540 &&
787 adapter->hw.media_type == e1000_media_type_copper) {
788 manc = E1000_READ_REG(&adapter->hw, MANC);
789 if(manc & E1000_MANC_SMBUS_EN) {
790 manc |= E1000_MANC_ARP_EN;
791 E1000_WRITE_REG(&adapter->hw, MANC, manc);
795 switch(adapter->hw.mac_type) {
798 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
799 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
800 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
803 swsm = E1000_READ_REG(&adapter->hw, SWSM);
804 E1000_WRITE_REG(&adapter->hw, SWSM,
805 swsm & ~E1000_SWSM_DRV_LOAD);
812 unregister_netdev(netdev);
813 #ifdef CONFIG_E1000_NAPI
814 for (i = 0; i < adapter->num_queues; i++)
815 __dev_put(&adapter->polling_netdev[i]);
818 if(!e1000_check_phy_reset_block(&adapter->hw))
819 e1000_phy_hw_reset(&adapter->hw);
821 kfree(adapter->tx_ring);
822 kfree(adapter->rx_ring);
823 #ifdef CONFIG_E1000_NAPI
824 kfree(adapter->polling_netdev);
827 iounmap(adapter->hw.hw_addr);
828 pci_release_regions(pdev);
830 #ifdef CONFIG_E1000_MQ
831 free_percpu(adapter->cpu_netdev);
832 free_percpu(adapter->cpu_tx_ring);
836 pci_disable_device(pdev);
840 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
841 * @adapter: board private structure to initialize
843 * e1000_sw_init initializes the Adapter private data structure.
844 * Fields are initialized based on PCI device information and
845 * OS network device settings (MTU size).
849 e1000_sw_init(struct e1000_adapter *adapter)
851 struct e1000_hw *hw = &adapter->hw;
852 struct net_device *netdev = adapter->netdev;
853 struct pci_dev *pdev = adapter->pdev;
854 #ifdef CONFIG_E1000_NAPI
858 /* PCI config space info */
860 hw->vendor_id = pdev->vendor;
861 hw->device_id = pdev->device;
862 hw->subsystem_vendor_id = pdev->subsystem_vendor;
863 hw->subsystem_id = pdev->subsystem_device;
865 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
867 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
869 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
870 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
871 hw->max_frame_size = netdev->mtu +
872 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
873 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
875 /* identify the MAC */
877 if(e1000_set_mac_type(hw)) {
878 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
882 /* initialize eeprom parameters */
884 if(e1000_init_eeprom_params(hw)) {
885 E1000_ERR("EEPROM initialization failed\n");
889 switch(hw->mac_type) {
894 case e1000_82541_rev_2:
895 case e1000_82547_rev_2:
896 hw->phy_init_script = 1;
900 e1000_set_media_type(hw);
902 hw->wait_autoneg_complete = FALSE;
903 hw->tbi_compatibility_en = TRUE;
904 hw->adaptive_ifs = TRUE;
908 if(hw->media_type == e1000_media_type_copper) {
909 hw->mdix = AUTO_ALL_MODES;
910 hw->disable_polarity_correction = FALSE;
911 hw->master_slave = E1000_MASTER_SLAVE;
914 #ifdef CONFIG_E1000_MQ
915 /* Number of supported queues */
916 switch (hw->mac_type) {
919 adapter->num_queues = 2;
922 adapter->num_queues = 1;
925 adapter->num_queues = min(adapter->num_queues, num_online_cpus());
927 adapter->num_queues = 1;
930 if (e1000_alloc_queues(adapter)) {
931 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
935 #ifdef CONFIG_E1000_NAPI
936 for (i = 0; i < adapter->num_queues; i++) {
937 adapter->polling_netdev[i].priv = adapter;
938 adapter->polling_netdev[i].poll = &e1000_clean;
939 adapter->polling_netdev[i].weight = 64;
940 dev_hold(&adapter->polling_netdev[i]);
941 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
945 #ifdef CONFIG_E1000_MQ
946 e1000_setup_queue_mapping(adapter);
949 atomic_set(&adapter->irq_sem, 1);
950 spin_lock_init(&adapter->stats_lock);
956 * e1000_alloc_queues - Allocate memory for all rings
957 * @adapter: board private structure to initialize
959 * We allocate one ring per queue at run-time since we don't know the
960 * number of queues at compile-time. The polling_netdev array is
961 * intended for Multiqueue, but should work fine with a single queue.
965 e1000_alloc_queues(struct e1000_adapter *adapter)
969 size = sizeof(struct e1000_tx_ring) * adapter->num_queues;
970 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
971 if (!adapter->tx_ring)
973 memset(adapter->tx_ring, 0, size);
975 size = sizeof(struct e1000_rx_ring) * adapter->num_queues;
976 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
977 if (!adapter->rx_ring) {
978 kfree(adapter->tx_ring);
981 memset(adapter->rx_ring, 0, size);
983 #ifdef CONFIG_E1000_NAPI
984 size = sizeof(struct net_device) * adapter->num_queues;
985 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
986 if (!adapter->polling_netdev) {
987 kfree(adapter->tx_ring);
988 kfree(adapter->rx_ring);
991 memset(adapter->polling_netdev, 0, size);
994 return E1000_SUCCESS;
997 #ifdef CONFIG_E1000_MQ
998 static void __devinit
999 e1000_setup_queue_mapping(struct e1000_adapter *adapter)
1003 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1004 adapter->rx_sched_call_data.info = adapter->netdev;
1005 cpus_clear(adapter->rx_sched_call_data.cpumask);
1007 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1008 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1012 for_each_online_cpu(cpu) {
1013 *per_cpu_ptr(adapter->cpu_tx_ring, cpu) = &adapter->tx_ring[i % adapter->num_queues];
1014 /* This is incomplete because we'd like to assign separate
1015 * physical cpus to these netdev polling structures and
1016 * avoid saturating a subset of cpus.
1018 if (i < adapter->num_queues) {
1019 *per_cpu_ptr(adapter->cpu_netdev, cpu) = &adapter->polling_netdev[i];
1020 adapter->cpu_for_queue[i] = cpu;
1022 *per_cpu_ptr(adapter->cpu_netdev, cpu) = NULL;
1026 unlock_cpu_hotplug();
1031 * e1000_open - Called when a network interface is made active
1032 * @netdev: network interface device structure
1034 * Returns 0 on success, negative value on failure
1036 * The open entry point is called when a network interface is made
1037 * active by the system (IFF_UP). At this point all resources needed
1038 * for transmit and receive operations are allocated, the interrupt
1039 * handler is registered with the OS, the watchdog timer is started,
1040 * and the stack is notified that the interface is ready.
1044 e1000_open(struct net_device *netdev)
1046 struct e1000_adapter *adapter = netdev_priv(netdev);
1049 /* allocate transmit descriptors */
1051 if ((err = e1000_setup_all_tx_resources(adapter)))
1054 /* allocate receive descriptors */
1056 if ((err = e1000_setup_all_rx_resources(adapter)))
1059 if((err = e1000_up(adapter)))
1061 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1062 if((adapter->hw.mng_cookie.status &
1063 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1064 e1000_update_mng_vlan(adapter);
1067 return E1000_SUCCESS;
1070 e1000_free_all_rx_resources(adapter);
1072 e1000_free_all_tx_resources(adapter);
1074 e1000_reset(adapter);
1080 * e1000_close - Disables a network interface
1081 * @netdev: network interface device structure
1083 * Returns 0, this is not allowed to fail
1085 * The close entry point is called when an interface is de-activated
1086 * by the OS. The hardware is still under the drivers control, but
1087 * needs to be disabled. A global MAC reset is issued to stop the
1088 * hardware, and all transmit and receive resources are freed.
1092 e1000_close(struct net_device *netdev)
1094 struct e1000_adapter *adapter = netdev_priv(netdev);
1096 e1000_down(adapter);
1098 e1000_free_all_tx_resources(adapter);
1099 e1000_free_all_rx_resources(adapter);
1101 if((adapter->hw.mng_cookie.status &
1102 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1103 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1109 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1110 * @adapter: address of board private structure
1111 * @start: address of beginning of memory
1112 * @len: length of memory
1114 static inline boolean_t
1115 e1000_check_64k_bound(struct e1000_adapter *adapter,
1116 void *start, unsigned long len)
1118 unsigned long begin = (unsigned long) start;
1119 unsigned long end = begin + len;
1121 /* First rev 82545 and 82546 need to not allow any memory
1122 * write location to cross 64k boundary due to errata 23 */
1123 if (adapter->hw.mac_type == e1000_82545 ||
1124 adapter->hw.mac_type == e1000_82546) {
1125 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1132 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1133 * @adapter: board private structure
1134 * @txdr: tx descriptor ring (for a specific queue) to setup
1136 * Return 0 on success, negative on failure
1140 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1141 struct e1000_tx_ring *txdr)
1143 struct pci_dev *pdev = adapter->pdev;
1146 size = sizeof(struct e1000_buffer) * txdr->count;
1147 txdr->buffer_info = vmalloc(size);
1148 if(!txdr->buffer_info) {
1150 "Unable to allocate memory for the transmit descriptor ring\n");
1153 memset(txdr->buffer_info, 0, size);
1155 /* round up to nearest 4K */
1157 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1158 E1000_ROUNDUP(txdr->size, 4096);
1160 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1163 vfree(txdr->buffer_info);
1165 "Unable to allocate memory for the transmit descriptor ring\n");
1169 /* Fix for errata 23, can't cross 64kB boundary */
1170 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1171 void *olddesc = txdr->desc;
1172 dma_addr_t olddma = txdr->dma;
1173 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1174 "at %p\n", txdr->size, txdr->desc);
1175 /* Try again, without freeing the previous */
1176 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1178 /* Failed allocation, critical failure */
1179 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1180 goto setup_tx_desc_die;
1183 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1185 pci_free_consistent(pdev, txdr->size, txdr->desc,
1187 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1189 "Unable to allocate aligned memory "
1190 "for the transmit descriptor ring\n");
1191 vfree(txdr->buffer_info);
1194 /* Free old allocation, new allocation was successful */
1195 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1198 memset(txdr->desc, 0, txdr->size);
1200 txdr->next_to_use = 0;
1201 txdr->next_to_clean = 0;
1207 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1208 * (Descriptors) for all queues
1209 * @adapter: board private structure
1211 * If this function returns with an error, then it's possible one or
1212 * more of the rings is populated (while the rest are not). It is the
1213 * callers duty to clean those orphaned rings.
1215 * Return 0 on success, negative on failure
1219 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1223 for (i = 0; i < adapter->num_queues; i++) {
1224 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1227 "Allocation for Tx Queue %u failed\n", i);
1236 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1237 * @adapter: board private structure
1239 * Configure the Tx unit of the MAC after a reset.
1243 e1000_configure_tx(struct e1000_adapter *adapter)
1246 struct e1000_hw *hw = &adapter->hw;
1247 uint32_t tdlen, tctl, tipg, tarc;
1249 /* Setup the HW Tx Head and Tail descriptor pointers */
1251 switch (adapter->num_queues) {
1253 tdba = adapter->tx_ring[1].dma;
1254 tdlen = adapter->tx_ring[1].count *
1255 sizeof(struct e1000_tx_desc);
1256 E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
1257 E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
1258 E1000_WRITE_REG(hw, TDLEN1, tdlen);
1259 E1000_WRITE_REG(hw, TDH1, 0);
1260 E1000_WRITE_REG(hw, TDT1, 0);
1261 adapter->tx_ring[1].tdh = E1000_TDH1;
1262 adapter->tx_ring[1].tdt = E1000_TDT1;
1266 tdba = adapter->tx_ring[0].dma;
1267 tdlen = adapter->tx_ring[0].count *
1268 sizeof(struct e1000_tx_desc);
1269 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1270 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1271 E1000_WRITE_REG(hw, TDLEN, tdlen);
1272 E1000_WRITE_REG(hw, TDH, 0);
1273 E1000_WRITE_REG(hw, TDT, 0);
1274 adapter->tx_ring[0].tdh = E1000_TDH;
1275 adapter->tx_ring[0].tdt = E1000_TDT;
1279 /* Set the default values for the Tx Inter Packet Gap timer */
1281 switch (hw->mac_type) {
1282 case e1000_82542_rev2_0:
1283 case e1000_82542_rev2_1:
1284 tipg = DEFAULT_82542_TIPG_IPGT;
1285 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1286 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1289 if (hw->media_type == e1000_media_type_fiber ||
1290 hw->media_type == e1000_media_type_internal_serdes)
1291 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1293 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1294 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1295 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1297 E1000_WRITE_REG(hw, TIPG, tipg);
1299 /* Set the Tx Interrupt Delay register */
1301 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1302 if (hw->mac_type >= e1000_82540)
1303 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1305 /* Program the Transmit Control Register */
1307 tctl = E1000_READ_REG(hw, TCTL);
1309 tctl &= ~E1000_TCTL_CT;
1310 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
1311 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1313 E1000_WRITE_REG(hw, TCTL, tctl);
1315 e1000_config_collision_dist(hw);
1317 /* Setup Transmit Descriptor Settings for eop descriptor */
1318 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1321 if (hw->mac_type < e1000_82543)
1322 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1324 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1326 /* Cache if we're 82544 running in PCI-X because we'll
1327 * need this to apply a workaround later in the send path. */
1328 if (hw->mac_type == e1000_82544 &&
1329 hw->bus_type == e1000_bus_type_pcix)
1330 adapter->pcix_82544 = 1;
1334 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1335 * @adapter: board private structure
1336 * @rxdr: rx descriptor ring (for a specific queue) to setup
1338 * Returns 0 on success, negative on failure
1342 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1343 struct e1000_rx_ring *rxdr)
1345 struct pci_dev *pdev = adapter->pdev;
1348 size = sizeof(struct e1000_buffer) * rxdr->count;
1349 rxdr->buffer_info = vmalloc(size);
1350 if (!rxdr->buffer_info) {
1352 "Unable to allocate memory for the receive descriptor ring\n");
1355 memset(rxdr->buffer_info, 0, size);
1357 size = sizeof(struct e1000_ps_page) * rxdr->count;
1358 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1359 if(!rxdr->ps_page) {
1360 vfree(rxdr->buffer_info);
1362 "Unable to allocate memory for the receive descriptor ring\n");
1365 memset(rxdr->ps_page, 0, size);
1367 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1368 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1369 if(!rxdr->ps_page_dma) {
1370 vfree(rxdr->buffer_info);
1371 kfree(rxdr->ps_page);
1373 "Unable to allocate memory for the receive descriptor ring\n");
1376 memset(rxdr->ps_page_dma, 0, size);
1378 if(adapter->hw.mac_type <= e1000_82547_rev_2)
1379 desc_len = sizeof(struct e1000_rx_desc);
1381 desc_len = sizeof(union e1000_rx_desc_packet_split);
1383 /* Round up to nearest 4K */
1385 rxdr->size = rxdr->count * desc_len;
1386 E1000_ROUNDUP(rxdr->size, 4096);
1388 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1392 "Unable to allocate memory for the receive descriptor ring\n");
1394 vfree(rxdr->buffer_info);
1395 kfree(rxdr->ps_page);
1396 kfree(rxdr->ps_page_dma);
1400 /* Fix for errata 23, can't cross 64kB boundary */
1401 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1402 void *olddesc = rxdr->desc;
1403 dma_addr_t olddma = rxdr->dma;
1404 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1405 "at %p\n", rxdr->size, rxdr->desc);
1406 /* Try again, without freeing the previous */
1407 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1408 /* Failed allocation, critical failure */
1410 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1412 "Unable to allocate memory "
1413 "for the receive descriptor ring\n");
1414 goto setup_rx_desc_die;
1417 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1419 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1421 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1423 "Unable to allocate aligned memory "
1424 "for the receive descriptor ring\n");
1425 goto setup_rx_desc_die;
1427 /* Free old allocation, new allocation was successful */
1428 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1431 memset(rxdr->desc, 0, rxdr->size);
1433 rxdr->next_to_clean = 0;
1434 rxdr->next_to_use = 0;
1440 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1441 * (Descriptors) for all queues
1442 * @adapter: board private structure
1444 * If this function returns with an error, then it's possible one or
1445 * more of the rings is populated (while the rest are not). It is the
1446 * callers duty to clean those orphaned rings.
1448 * Return 0 on success, negative on failure
1452 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1456 for (i = 0; i < adapter->num_queues; i++) {
1457 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1460 "Allocation for Rx Queue %u failed\n", i);
1469 * e1000_setup_rctl - configure the receive control registers
1470 * @adapter: Board private structure
1474 e1000_setup_rctl(struct e1000_adapter *adapter)
1476 uint32_t rctl, rfctl;
1477 uint32_t psrctl = 0;
1479 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1481 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1483 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1484 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1485 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1487 if(adapter->hw.tbi_compatibility_on == 1)
1488 rctl |= E1000_RCTL_SBP;
1490 rctl &= ~E1000_RCTL_SBP;
1492 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1493 rctl &= ~E1000_RCTL_LPE;
1495 rctl |= E1000_RCTL_LPE;
1497 /* Setup buffer sizes */
1498 if(adapter->hw.mac_type >= e1000_82571) {
1499 /* We can now specify buffers in 1K increments.
1500 * BSIZE and BSEX are ignored in this case. */
1501 rctl |= adapter->rx_buffer_len << 0x11;
1503 rctl &= ~E1000_RCTL_SZ_4096;
1504 rctl |= E1000_RCTL_BSEX;
1505 switch (adapter->rx_buffer_len) {
1506 case E1000_RXBUFFER_2048:
1508 rctl |= E1000_RCTL_SZ_2048;
1509 rctl &= ~E1000_RCTL_BSEX;
1511 case E1000_RXBUFFER_4096:
1512 rctl |= E1000_RCTL_SZ_4096;
1514 case E1000_RXBUFFER_8192:
1515 rctl |= E1000_RCTL_SZ_8192;
1517 case E1000_RXBUFFER_16384:
1518 rctl |= E1000_RCTL_SZ_16384;
1523 #ifdef CONFIG_E1000_PACKET_SPLIT
1524 /* 82571 and greater support packet-split where the protocol
1525 * header is placed in skb->data and the packet data is
1526 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1527 * In the case of a non-split, skb->data is linearly filled,
1528 * followed by the page buffers. Therefore, skb->data is
1529 * sized to hold the largest protocol header.
1531 adapter->rx_ps = (adapter->hw.mac_type > e1000_82547_rev_2)
1532 && (adapter->netdev->mtu
1533 < ((3 * PAGE_SIZE) + adapter->rx_ps_bsize0));
1535 if(adapter->rx_ps) {
1536 /* Configure extra packet-split registers */
1537 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1538 rfctl |= E1000_RFCTL_EXTEN;
1539 /* disable IPv6 packet split support */
1540 rfctl |= E1000_RFCTL_IPV6_DIS;
1541 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1543 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1545 psrctl |= adapter->rx_ps_bsize0 >>
1546 E1000_PSRCTL_BSIZE0_SHIFT;
1547 psrctl |= PAGE_SIZE >>
1548 E1000_PSRCTL_BSIZE1_SHIFT;
1549 psrctl |= PAGE_SIZE <<
1550 E1000_PSRCTL_BSIZE2_SHIFT;
1551 psrctl |= PAGE_SIZE <<
1552 E1000_PSRCTL_BSIZE3_SHIFT;
1554 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1557 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1561 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1562 * @adapter: board private structure
1564 * Configure the Rx unit of the MAC after a reset.
1568 e1000_configure_rx(struct e1000_adapter *adapter)
1571 struct e1000_hw *hw = &adapter->hw;
1572 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1573 #ifdef CONFIG_E1000_MQ
1574 uint32_t reta, mrqc;
1578 if(adapter->rx_ps) {
1579 rdlen = adapter->rx_ring[0].count *
1580 sizeof(union e1000_rx_desc_packet_split);
1581 adapter->clean_rx = e1000_clean_rx_irq_ps;
1582 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1584 rdlen = adapter->rx_ring[0].count *
1585 sizeof(struct e1000_rx_desc);
1586 adapter->clean_rx = e1000_clean_rx_irq;
1587 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1590 /* disable receives while setting up the descriptors */
1591 rctl = E1000_READ_REG(hw, RCTL);
1592 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1594 /* set the Receive Delay Timer Register */
1595 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1597 if (hw->mac_type >= e1000_82540) {
1598 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1599 if(adapter->itr > 1)
1600 E1000_WRITE_REG(hw, ITR,
1601 1000000000 / (adapter->itr * 256));
1604 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1605 * the Base and Length of the Rx Descriptor Ring */
1606 switch (adapter->num_queues) {
1607 #ifdef CONFIG_E1000_MQ
1609 rdba = adapter->rx_ring[1].dma;
1610 E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
1611 E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
1612 E1000_WRITE_REG(hw, RDLEN1, rdlen);
1613 E1000_WRITE_REG(hw, RDH1, 0);
1614 E1000_WRITE_REG(hw, RDT1, 0);
1615 adapter->rx_ring[1].rdh = E1000_RDH1;
1616 adapter->rx_ring[1].rdt = E1000_RDT1;
1621 rdba = adapter->rx_ring[0].dma;
1622 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1623 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1624 E1000_WRITE_REG(hw, RDLEN, rdlen);
1625 E1000_WRITE_REG(hw, RDH, 0);
1626 E1000_WRITE_REG(hw, RDT, 0);
1627 adapter->rx_ring[0].rdh = E1000_RDH;
1628 adapter->rx_ring[0].rdt = E1000_RDT;
1632 #ifdef CONFIG_E1000_MQ
1633 if (adapter->num_queues > 1) {
1634 uint32_t random[10];
1636 get_random_bytes(&random[0], 40);
1638 if (hw->mac_type <= e1000_82572) {
1639 E1000_WRITE_REG(hw, RSSIR, 0);
1640 E1000_WRITE_REG(hw, RSSIM, 0);
1643 switch (adapter->num_queues) {
1647 mrqc = E1000_MRQC_ENABLE_RSS_2Q;
1651 /* Fill out redirection table */
1652 for (i = 0; i < 32; i++)
1653 E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
1654 /* Fill out hash function seeds */
1655 for (i = 0; i < 10; i++)
1656 E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
1658 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1659 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1660 E1000_WRITE_REG(hw, MRQC, mrqc);
1663 /* Multiqueue and packet checksumming are mutually exclusive. */
1664 if (hw->mac_type >= e1000_82571) {
1665 rxcsum = E1000_READ_REG(hw, RXCSUM);
1666 rxcsum |= E1000_RXCSUM_PCSD;
1667 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1672 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1673 if (hw->mac_type >= e1000_82543) {
1674 rxcsum = E1000_READ_REG(hw, RXCSUM);
1675 if(adapter->rx_csum == TRUE) {
1676 rxcsum |= E1000_RXCSUM_TUOFL;
1678 /* Enable 82571 IPv4 payload checksum for UDP fragments
1679 * Must be used in conjunction with packet-split. */
1680 if((adapter->hw.mac_type > e1000_82547_rev_2) &&
1682 rxcsum |= E1000_RXCSUM_IPPCSE;
1685 rxcsum &= ~E1000_RXCSUM_TUOFL;
1686 /* don't need to clear IPPCSE as it defaults to 0 */
1688 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1690 #endif /* CONFIG_E1000_MQ */
1692 if (hw->mac_type == e1000_82573)
1693 E1000_WRITE_REG(hw, ERT, 0x0100);
1695 /* Enable Receives */
1696 E1000_WRITE_REG(hw, RCTL, rctl);
1700 * e1000_free_tx_resources - Free Tx Resources per Queue
1701 * @adapter: board private structure
1702 * @tx_ring: Tx descriptor ring for a specific queue
1704 * Free all transmit software resources
1708 e1000_free_tx_resources(struct e1000_adapter *adapter,
1709 struct e1000_tx_ring *tx_ring)
1711 struct pci_dev *pdev = adapter->pdev;
1713 e1000_clean_tx_ring(adapter, tx_ring);
1715 vfree(tx_ring->buffer_info);
1716 tx_ring->buffer_info = NULL;
1718 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1720 tx_ring->desc = NULL;
1724 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1725 * @adapter: board private structure
1727 * Free all transmit software resources
1731 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1735 for (i = 0; i < adapter->num_queues; i++)
1736 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1740 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1741 struct e1000_buffer *buffer_info)
1743 if(buffer_info->dma) {
1744 pci_unmap_page(adapter->pdev,
1746 buffer_info->length,
1748 buffer_info->dma = 0;
1750 if(buffer_info->skb) {
1751 dev_kfree_skb_any(buffer_info->skb);
1752 buffer_info->skb = NULL;
1757 * e1000_clean_tx_ring - Free Tx Buffers
1758 * @adapter: board private structure
1759 * @tx_ring: ring to be cleaned
1763 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1764 struct e1000_tx_ring *tx_ring)
1766 struct e1000_buffer *buffer_info;
1770 /* Free all the Tx ring sk_buffs */
1772 if (likely(tx_ring->previous_buffer_info.skb != NULL)) {
1773 e1000_unmap_and_free_tx_resource(adapter,
1774 &tx_ring->previous_buffer_info);
1777 for(i = 0; i < tx_ring->count; i++) {
1778 buffer_info = &tx_ring->buffer_info[i];
1779 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1782 size = sizeof(struct e1000_buffer) * tx_ring->count;
1783 memset(tx_ring->buffer_info, 0, size);
1785 /* Zero out the descriptor ring */
1787 memset(tx_ring->desc, 0, tx_ring->size);
1789 tx_ring->next_to_use = 0;
1790 tx_ring->next_to_clean = 0;
1792 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1793 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1797 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1798 * @adapter: board private structure
1802 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1806 for (i = 0; i < adapter->num_queues; i++)
1807 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1811 * e1000_free_rx_resources - Free Rx Resources
1812 * @adapter: board private structure
1813 * @rx_ring: ring to clean the resources from
1815 * Free all receive software resources
1819 e1000_free_rx_resources(struct e1000_adapter *adapter,
1820 struct e1000_rx_ring *rx_ring)
1822 struct pci_dev *pdev = adapter->pdev;
1824 e1000_clean_rx_ring(adapter, rx_ring);
1826 vfree(rx_ring->buffer_info);
1827 rx_ring->buffer_info = NULL;
1828 kfree(rx_ring->ps_page);
1829 rx_ring->ps_page = NULL;
1830 kfree(rx_ring->ps_page_dma);
1831 rx_ring->ps_page_dma = NULL;
1833 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1835 rx_ring->desc = NULL;
1839 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1840 * @adapter: board private structure
1842 * Free all receive software resources
1846 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1850 for (i = 0; i < adapter->num_queues; i++)
1851 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1855 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1856 * @adapter: board private structure
1857 * @rx_ring: ring to free buffers from
1861 e1000_clean_rx_ring(struct e1000_adapter *adapter,
1862 struct e1000_rx_ring *rx_ring)
1864 struct e1000_buffer *buffer_info;
1865 struct e1000_ps_page *ps_page;
1866 struct e1000_ps_page_dma *ps_page_dma;
1867 struct pci_dev *pdev = adapter->pdev;
1871 /* Free all the Rx ring sk_buffs */
1873 for(i = 0; i < rx_ring->count; i++) {
1874 buffer_info = &rx_ring->buffer_info[i];
1875 if(buffer_info->skb) {
1876 ps_page = &rx_ring->ps_page[i];
1877 ps_page_dma = &rx_ring->ps_page_dma[i];
1878 pci_unmap_single(pdev,
1880 buffer_info->length,
1881 PCI_DMA_FROMDEVICE);
1883 dev_kfree_skb(buffer_info->skb);
1884 buffer_info->skb = NULL;
1886 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
1887 if(!ps_page->ps_page[j]) break;
1888 pci_unmap_single(pdev,
1889 ps_page_dma->ps_page_dma[j],
1890 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1891 ps_page_dma->ps_page_dma[j] = 0;
1892 put_page(ps_page->ps_page[j]);
1893 ps_page->ps_page[j] = NULL;
1898 size = sizeof(struct e1000_buffer) * rx_ring->count;
1899 memset(rx_ring->buffer_info, 0, size);
1900 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1901 memset(rx_ring->ps_page, 0, size);
1902 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1903 memset(rx_ring->ps_page_dma, 0, size);
1905 /* Zero out the descriptor ring */
1907 memset(rx_ring->desc, 0, rx_ring->size);
1909 rx_ring->next_to_clean = 0;
1910 rx_ring->next_to_use = 0;
1912 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1913 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1917 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1918 * @adapter: board private structure
1922 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1926 for (i = 0; i < adapter->num_queues; i++)
1927 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1930 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1931 * and memory write and invalidate disabled for certain operations
1934 e1000_enter_82542_rst(struct e1000_adapter *adapter)
1936 struct net_device *netdev = adapter->netdev;
1939 e1000_pci_clear_mwi(&adapter->hw);
1941 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1942 rctl |= E1000_RCTL_RST;
1943 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1944 E1000_WRITE_FLUSH(&adapter->hw);
1947 if(netif_running(netdev))
1948 e1000_clean_all_rx_rings(adapter);
1952 e1000_leave_82542_rst(struct e1000_adapter *adapter)
1954 struct net_device *netdev = adapter->netdev;
1957 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1958 rctl &= ~E1000_RCTL_RST;
1959 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1960 E1000_WRITE_FLUSH(&adapter->hw);
1963 if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
1964 e1000_pci_set_mwi(&adapter->hw);
1966 if(netif_running(netdev)) {
1967 e1000_configure_rx(adapter);
1968 e1000_alloc_rx_buffers(adapter, &adapter->rx_ring[0]);
1973 * e1000_set_mac - Change the Ethernet Address of the NIC
1974 * @netdev: network interface device structure
1975 * @p: pointer to an address structure
1977 * Returns 0 on success, negative on failure
1981 e1000_set_mac(struct net_device *netdev, void *p)
1983 struct e1000_adapter *adapter = netdev_priv(netdev);
1984 struct sockaddr *addr = p;
1986 if(!is_valid_ether_addr(addr->sa_data))
1987 return -EADDRNOTAVAIL;
1989 /* 82542 2.0 needs to be in reset to write receive address registers */
1991 if(adapter->hw.mac_type == e1000_82542_rev2_0)
1992 e1000_enter_82542_rst(adapter);
1994 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1995 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
1997 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
1999 /* With 82571 controllers, LAA may be overwritten (with the default)
2000 * due to controller reset from the other port. */
2001 if (adapter->hw.mac_type == e1000_82571) {
2002 /* activate the work around */
2003 adapter->hw.laa_is_present = 1;
2005 /* Hold a copy of the LAA in RAR[14] This is done so that
2006 * between the time RAR[0] gets clobbered and the time it
2007 * gets fixed (in e1000_watchdog), the actual LAA is in one
2008 * of the RARs and no incoming packets directed to this port
2009 * are dropped. Eventaully the LAA will be in RAR[0] and
2011 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2012 E1000_RAR_ENTRIES - 1);
2015 if(adapter->hw.mac_type == e1000_82542_rev2_0)
2016 e1000_leave_82542_rst(adapter);
2022 * e1000_set_multi - Multicast and Promiscuous mode set
2023 * @netdev: network interface device structure
2025 * The set_multi entry point is called whenever the multicast address
2026 * list or the network interface flags are updated. This routine is
2027 * responsible for configuring the hardware for proper multicast,
2028 * promiscuous mode, and all-multi behavior.
2032 e1000_set_multi(struct net_device *netdev)
2034 struct e1000_adapter *adapter = netdev_priv(netdev);
2035 struct e1000_hw *hw = &adapter->hw;
2036 struct dev_mc_list *mc_ptr;
2038 uint32_t hash_value;
2039 int i, rar_entries = E1000_RAR_ENTRIES;
2041 /* reserve RAR[14] for LAA over-write work-around */
2042 if (adapter->hw.mac_type == e1000_82571)
2045 /* Check for Promiscuous and All Multicast modes */
2047 rctl = E1000_READ_REG(hw, RCTL);
2049 if(netdev->flags & IFF_PROMISC) {
2050 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2051 } else if(netdev->flags & IFF_ALLMULTI) {
2052 rctl |= E1000_RCTL_MPE;
2053 rctl &= ~E1000_RCTL_UPE;
2055 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2058 E1000_WRITE_REG(hw, RCTL, rctl);
2060 /* 82542 2.0 needs to be in reset to write receive address registers */
2062 if(hw->mac_type == e1000_82542_rev2_0)
2063 e1000_enter_82542_rst(adapter);
2065 /* load the first 14 multicast address into the exact filters 1-14
2066 * RAR 0 is used for the station MAC adddress
2067 * if there are not 14 addresses, go ahead and clear the filters
2068 * -- with 82571 controllers only 0-13 entries are filled here
2070 mc_ptr = netdev->mc_list;
2072 for(i = 1; i < rar_entries; i++) {
2074 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2075 mc_ptr = mc_ptr->next;
2077 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2078 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2082 /* clear the old settings from the multicast hash table */
2084 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2085 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2087 /* load any remaining addresses into the hash table */
2089 for(; mc_ptr; mc_ptr = mc_ptr->next) {
2090 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2091 e1000_mta_set(hw, hash_value);
2094 if(hw->mac_type == e1000_82542_rev2_0)
2095 e1000_leave_82542_rst(adapter);
2098 /* Need to wait a few seconds after link up to get diagnostic information from
2102 e1000_update_phy_info(unsigned long data)
2104 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2105 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2109 * e1000_82547_tx_fifo_stall - Timer Call-back
2110 * @data: pointer to adapter cast into an unsigned long
2114 e1000_82547_tx_fifo_stall(unsigned long data)
2116 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2117 struct net_device *netdev = adapter->netdev;
2120 if(atomic_read(&adapter->tx_fifo_stall)) {
2121 if((E1000_READ_REG(&adapter->hw, TDT) ==
2122 E1000_READ_REG(&adapter->hw, TDH)) &&
2123 (E1000_READ_REG(&adapter->hw, TDFT) ==
2124 E1000_READ_REG(&adapter->hw, TDFH)) &&
2125 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2126 E1000_READ_REG(&adapter->hw, TDFHS))) {
2127 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2128 E1000_WRITE_REG(&adapter->hw, TCTL,
2129 tctl & ~E1000_TCTL_EN);
2130 E1000_WRITE_REG(&adapter->hw, TDFT,
2131 adapter->tx_head_addr);
2132 E1000_WRITE_REG(&adapter->hw, TDFH,
2133 adapter->tx_head_addr);
2134 E1000_WRITE_REG(&adapter->hw, TDFTS,
2135 adapter->tx_head_addr);
2136 E1000_WRITE_REG(&adapter->hw, TDFHS,
2137 adapter->tx_head_addr);
2138 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2139 E1000_WRITE_FLUSH(&adapter->hw);
2141 adapter->tx_fifo_head = 0;
2142 atomic_set(&adapter->tx_fifo_stall, 0);
2143 netif_wake_queue(netdev);
2145 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2151 * e1000_watchdog - Timer Call-back
2152 * @data: pointer to adapter cast into an unsigned long
2155 e1000_watchdog(unsigned long data)
2157 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2159 /* Do the rest outside of interrupt context */
2160 schedule_work(&adapter->watchdog_task);
2164 e1000_watchdog_task(struct e1000_adapter *adapter)
2166 struct net_device *netdev = adapter->netdev;
2167 struct e1000_tx_ring *txdr = &adapter->tx_ring[0];
2170 e1000_check_for_link(&adapter->hw);
2171 if (adapter->hw.mac_type == e1000_82573) {
2172 e1000_enable_tx_pkt_filtering(&adapter->hw);
2173 if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2174 e1000_update_mng_vlan(adapter);
2177 if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2178 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2179 link = !adapter->hw.serdes_link_down;
2181 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2184 if(!netif_carrier_ok(netdev)) {
2185 e1000_get_speed_and_duplex(&adapter->hw,
2186 &adapter->link_speed,
2187 &adapter->link_duplex);
2189 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2190 adapter->link_speed,
2191 adapter->link_duplex == FULL_DUPLEX ?
2192 "Full Duplex" : "Half Duplex");
2194 netif_carrier_on(netdev);
2195 netif_wake_queue(netdev);
2196 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2197 adapter->smartspeed = 0;
2200 if(netif_carrier_ok(netdev)) {
2201 adapter->link_speed = 0;
2202 adapter->link_duplex = 0;
2203 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2204 netif_carrier_off(netdev);
2205 netif_stop_queue(netdev);
2206 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2209 e1000_smartspeed(adapter);
2212 e1000_update_stats(adapter);
2214 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2215 adapter->tpt_old = adapter->stats.tpt;
2216 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2217 adapter->colc_old = adapter->stats.colc;
2219 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2220 adapter->gorcl_old = adapter->stats.gorcl;
2221 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2222 adapter->gotcl_old = adapter->stats.gotcl;
2224 e1000_update_adaptive(&adapter->hw);
2226 if (adapter->num_queues == 1 && !netif_carrier_ok(netdev)) {
2227 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2228 /* We've lost link, so the controller stops DMA,
2229 * but we've got queued Tx work that's never going
2230 * to get done, so reset controller to flush Tx.
2231 * (Do the reset outside of interrupt context). */
2232 schedule_work(&adapter->tx_timeout_task);
2236 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2237 if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2238 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2239 * asymmetrical Tx or Rx gets ITR=8000; everyone
2240 * else is between 2000-8000. */
2241 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2242 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2243 adapter->gotcl - adapter->gorcl :
2244 adapter->gorcl - adapter->gotcl) / 10000;
2245 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2246 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2249 /* Cause software interrupt to ensure rx ring is cleaned */
2250 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2252 /* Force detection of hung controller every watchdog period */
2253 adapter->detect_tx_hung = TRUE;
2255 /* With 82571 controllers, LAA may be overwritten due to controller
2256 * reset from the other port. Set the appropriate LAA in RAR[0] */
2257 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2258 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2260 /* Reset the timer */
2261 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2264 #define E1000_TX_FLAGS_CSUM 0x00000001
2265 #define E1000_TX_FLAGS_VLAN 0x00000002
2266 #define E1000_TX_FLAGS_TSO 0x00000004
2267 #define E1000_TX_FLAGS_IPV4 0x00000008
2268 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2269 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2272 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2273 struct sk_buff *skb)
2276 struct e1000_context_desc *context_desc;
2278 uint32_t cmd_length = 0;
2279 uint16_t ipcse = 0, tucse, mss;
2280 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2283 if(skb_shinfo(skb)->tso_size) {
2284 if (skb_header_cloned(skb)) {
2285 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2290 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2291 mss = skb_shinfo(skb)->tso_size;
2292 if(skb->protocol == ntohs(ETH_P_IP)) {
2293 skb->nh.iph->tot_len = 0;
2294 skb->nh.iph->check = 0;
2296 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2301 cmd_length = E1000_TXD_CMD_IP;
2302 ipcse = skb->h.raw - skb->data - 1;
2303 #ifdef NETIF_F_TSO_IPV6
2304 } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
2305 skb->nh.ipv6h->payload_len = 0;
2307 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2308 &skb->nh.ipv6h->daddr,
2315 ipcss = skb->nh.raw - skb->data;
2316 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2317 tucss = skb->h.raw - skb->data;
2318 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2321 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2322 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2324 i = tx_ring->next_to_use;
2325 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2327 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2328 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2329 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2330 context_desc->upper_setup.tcp_fields.tucss = tucss;
2331 context_desc->upper_setup.tcp_fields.tucso = tucso;
2332 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2333 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2334 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2335 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2337 if (++i == tx_ring->count) i = 0;
2338 tx_ring->next_to_use = i;
2347 static inline boolean_t
2348 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2349 struct sk_buff *skb)
2351 struct e1000_context_desc *context_desc;
2355 if(likely(skb->ip_summed == CHECKSUM_HW)) {
2356 css = skb->h.raw - skb->data;
2358 i = tx_ring->next_to_use;
2359 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2361 context_desc->upper_setup.tcp_fields.tucss = css;
2362 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2363 context_desc->upper_setup.tcp_fields.tucse = 0;
2364 context_desc->tcp_seg_setup.data = 0;
2365 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2367 if (unlikely(++i == tx_ring->count)) i = 0;
2368 tx_ring->next_to_use = i;
2376 #define E1000_MAX_TXD_PWR 12
2377 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2380 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2381 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2382 unsigned int nr_frags, unsigned int mss)
2384 struct e1000_buffer *buffer_info;
2385 unsigned int len = skb->len;
2386 unsigned int offset = 0, size, count = 0, i;
2388 len -= skb->data_len;
2390 i = tx_ring->next_to_use;
2393 buffer_info = &tx_ring->buffer_info[i];
2394 size = min(len, max_per_txd);
2396 /* Workaround for premature desc write-backs
2397 * in TSO mode. Append 4-byte sentinel desc */
2398 if(unlikely(mss && !nr_frags && size == len && size > 8))
2401 /* work-around for errata 10 and it applies
2402 * to all controllers in PCI-X mode
2403 * The fix is to make sure that the first descriptor of a
2404 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2406 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2407 (size > 2015) && count == 0))
2410 /* Workaround for potential 82544 hang in PCI-X. Avoid
2411 * terminating buffers within evenly-aligned dwords. */
2412 if(unlikely(adapter->pcix_82544 &&
2413 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2417 buffer_info->length = size;
2419 pci_map_single(adapter->pdev,
2423 buffer_info->time_stamp = jiffies;
2428 if(unlikely(++i == tx_ring->count)) i = 0;
2431 for(f = 0; f < nr_frags; f++) {
2432 struct skb_frag_struct *frag;
2434 frag = &skb_shinfo(skb)->frags[f];
2436 offset = frag->page_offset;
2439 buffer_info = &tx_ring->buffer_info[i];
2440 size = min(len, max_per_txd);
2442 /* Workaround for premature desc write-backs
2443 * in TSO mode. Append 4-byte sentinel desc */
2444 if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2447 /* Workaround for potential 82544 hang in PCI-X.
2448 * Avoid terminating buffers within evenly-aligned
2450 if(unlikely(adapter->pcix_82544 &&
2451 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2455 buffer_info->length = size;
2457 pci_map_page(adapter->pdev,
2462 buffer_info->time_stamp = jiffies;
2467 if(unlikely(++i == tx_ring->count)) i = 0;
2471 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2472 tx_ring->buffer_info[i].skb = skb;
2473 tx_ring->buffer_info[first].next_to_watch = i;
2479 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2480 int tx_flags, int count)
2482 struct e1000_tx_desc *tx_desc = NULL;
2483 struct e1000_buffer *buffer_info;
2484 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2487 if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2488 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2490 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2492 if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
2493 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2496 if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2497 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2498 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2501 if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2502 txd_lower |= E1000_TXD_CMD_VLE;
2503 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2506 i = tx_ring->next_to_use;
2509 buffer_info = &tx_ring->buffer_info[i];
2510 tx_desc = E1000_TX_DESC(*tx_ring, i);
2511 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2512 tx_desc->lower.data =
2513 cpu_to_le32(txd_lower | buffer_info->length);
2514 tx_desc->upper.data = cpu_to_le32(txd_upper);
2515 if(unlikely(++i == tx_ring->count)) i = 0;
2518 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2520 /* Force memory writes to complete before letting h/w
2521 * know there are new descriptors to fetch. (Only
2522 * applicable for weak-ordered memory model archs,
2523 * such as IA-64). */
2526 tx_ring->next_to_use = i;
2527 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2531 * 82547 workaround to avoid controller hang in half-duplex environment.
2532 * The workaround is to avoid queuing a large packet that would span
2533 * the internal Tx FIFO ring boundary by notifying the stack to resend
2534 * the packet at a later time. This gives the Tx FIFO an opportunity to
2535 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2536 * to the beginning of the Tx FIFO.
2539 #define E1000_FIFO_HDR 0x10
2540 #define E1000_82547_PAD_LEN 0x3E0
2543 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2545 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2546 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2548 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2550 if(adapter->link_duplex != HALF_DUPLEX)
2551 goto no_fifo_stall_required;
2553 if(atomic_read(&adapter->tx_fifo_stall))
2556 if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2557 atomic_set(&adapter->tx_fifo_stall, 1);
2561 no_fifo_stall_required:
2562 adapter->tx_fifo_head += skb_fifo_len;
2563 if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
2564 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2568 #define MINIMUM_DHCP_PACKET_SIZE 282
2570 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2572 struct e1000_hw *hw = &adapter->hw;
2573 uint16_t length, offset;
2574 if(vlan_tx_tag_present(skb)) {
2575 if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2576 ( adapter->hw.mng_cookie.status &
2577 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2580 if(htons(ETH_P_IP) == skb->protocol) {
2581 const struct iphdr *ip = skb->nh.iph;
2582 if(IPPROTO_UDP == ip->protocol) {
2583 struct udphdr *udp = (struct udphdr *)(skb->h.uh);
2584 if(ntohs(udp->dest) == 67) {
2585 offset = (uint8_t *)udp + 8 - skb->data;
2586 length = skb->len - offset;
2588 return e1000_mng_write_dhcp_info(hw,
2589 (uint8_t *)udp + 8, length);
2592 } else if((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
2593 struct ethhdr *eth = (struct ethhdr *) skb->data;
2594 if((htons(ETH_P_IP) == eth->h_proto)) {
2595 const struct iphdr *ip =
2596 (struct iphdr *)((uint8_t *)skb->data+14);
2597 if(IPPROTO_UDP == ip->protocol) {
2598 struct udphdr *udp =
2599 (struct udphdr *)((uint8_t *)ip +
2601 if(ntohs(udp->dest) == 67) {
2602 offset = (uint8_t *)udp + 8 - skb->data;
2603 length = skb->len - offset;
2605 return e1000_mng_write_dhcp_info(hw,
2615 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2617 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2619 struct e1000_adapter *adapter = netdev_priv(netdev);
2620 struct e1000_tx_ring *tx_ring;
2621 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2622 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2623 unsigned int tx_flags = 0;
2624 unsigned int len = skb->len;
2625 unsigned long flags;
2626 unsigned int nr_frags = 0;
2627 unsigned int mss = 0;
2631 len -= skb->data_len;
2633 #ifdef CONFIG_E1000_MQ
2634 tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2636 tx_ring = adapter->tx_ring;
2639 if (unlikely(skb->len <= 0)) {
2640 dev_kfree_skb_any(skb);
2641 return NETDEV_TX_OK;
2645 mss = skb_shinfo(skb)->tso_size;
2646 /* The controller does a simple calculation to
2647 * make sure there is enough room in the FIFO before
2648 * initiating the DMA for each buffer. The calc is:
2649 * 4 = ceil(buffer len/mss). To make sure we don't
2650 * overrun the FIFO, adjust the max buffer len if mss
2653 max_per_txd = min(mss << 2, max_per_txd);
2654 max_txd_pwr = fls(max_per_txd) - 1;
2657 if((mss) || (skb->ip_summed == CHECKSUM_HW))
2661 if(skb->ip_summed == CHECKSUM_HW)
2664 count += TXD_USE_COUNT(len, max_txd_pwr);
2666 if(adapter->pcix_82544)
2669 /* work-around for errata 10 and it applies to all controllers
2670 * in PCI-X mode, so add one more descriptor to the count
2672 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2676 nr_frags = skb_shinfo(skb)->nr_frags;
2677 for(f = 0; f < nr_frags; f++)
2678 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2680 if(adapter->pcix_82544)
2684 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2685 * points to just header, pull a few bytes of payload from
2686 * frags into skb->data */
2687 if (skb_shinfo(skb)->tso_size) {
2689 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2690 if (skb->data_len && (hdr_len < (skb->len - skb->data_len)) &&
2691 (adapter->hw.mac_type == e1000_82571 ||
2692 adapter->hw.mac_type == e1000_82572)) {
2693 unsigned int pull_size;
2694 pull_size = min((unsigned int)4, skb->data_len);
2695 if (!__pskb_pull_tail(skb, pull_size)) {
2696 printk(KERN_ERR "__pskb_pull_tail failed.\n");
2697 dev_kfree_skb_any(skb);
2704 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2705 e1000_transfer_dhcp_info(adapter, skb);
2707 local_irq_save(flags);
2708 if (!spin_trylock(&tx_ring->tx_lock)) {
2709 /* Collision - tell upper layer to requeue */
2710 local_irq_restore(flags);
2711 return NETDEV_TX_LOCKED;
2714 /* need: count + 2 desc gap to keep tail from touching
2715 * head, otherwise try next time */
2716 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2717 netif_stop_queue(netdev);
2718 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2719 return NETDEV_TX_BUSY;
2722 if(unlikely(adapter->hw.mac_type == e1000_82547)) {
2723 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2724 netif_stop_queue(netdev);
2725 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2726 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2727 return NETDEV_TX_BUSY;
2731 if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2732 tx_flags |= E1000_TX_FLAGS_VLAN;
2733 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2736 first = tx_ring->next_to_use;
2738 tso = e1000_tso(adapter, tx_ring, skb);
2740 dev_kfree_skb_any(skb);
2741 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2742 return NETDEV_TX_OK;
2746 tx_flags |= E1000_TX_FLAGS_TSO;
2747 else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
2748 tx_flags |= E1000_TX_FLAGS_CSUM;
2750 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2751 * 82571 hardware supports TSO capabilities for IPv6 as well...
2752 * no longer assume, we must. */
2753 if (likely(skb->protocol == ntohs(ETH_P_IP)))
2754 tx_flags |= E1000_TX_FLAGS_IPV4;
2756 e1000_tx_queue(adapter, tx_ring, tx_flags,
2757 e1000_tx_map(adapter, tx_ring, skb, first,
2758 max_per_txd, nr_frags, mss));
2760 netdev->trans_start = jiffies;
2762 /* Make sure there is space in the ring for the next send. */
2763 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
2764 netif_stop_queue(netdev);
2766 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2767 return NETDEV_TX_OK;
2771 * e1000_tx_timeout - Respond to a Tx Hang
2772 * @netdev: network interface device structure
2776 e1000_tx_timeout(struct net_device *netdev)
2778 struct e1000_adapter *adapter = netdev_priv(netdev);
2780 /* Do the reset outside of interrupt context */
2781 schedule_work(&adapter->tx_timeout_task);
2785 e1000_tx_timeout_task(struct net_device *netdev)
2787 struct e1000_adapter *adapter = netdev_priv(netdev);
2789 e1000_down(adapter);
2794 * e1000_get_stats - Get System Network Statistics
2795 * @netdev: network interface device structure
2797 * Returns the address of the device statistics structure.
2798 * The statistics are actually updated from the timer callback.
2801 static struct net_device_stats *
2802 e1000_get_stats(struct net_device *netdev)
2804 struct e1000_adapter *adapter = netdev_priv(netdev);
2806 e1000_update_stats(adapter);
2807 return &adapter->net_stats;
2811 * e1000_change_mtu - Change the Maximum Transfer Unit
2812 * @netdev: network interface device structure
2813 * @new_mtu: new value for maximum frame size
2815 * Returns 0 on success, negative on failure
2819 e1000_change_mtu(struct net_device *netdev, int new_mtu)
2821 struct e1000_adapter *adapter = netdev_priv(netdev);
2822 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2824 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2825 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2826 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2830 #define MAX_STD_JUMBO_FRAME_SIZE 9234
2831 /* might want this to be bigger enum check... */
2832 /* 82571 controllers limit jumbo frame size to 10500 bytes */
2833 if ((adapter->hw.mac_type == e1000_82571 ||
2834 adapter->hw.mac_type == e1000_82572) &&
2835 max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
2836 DPRINTK(PROBE, ERR, "MTU > 9216 bytes not supported "
2837 "on 82571 and 82572 controllers.\n");
2841 if(adapter->hw.mac_type == e1000_82573 &&
2842 max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2843 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2848 if(adapter->hw.mac_type > e1000_82547_rev_2) {
2849 adapter->rx_buffer_len = max_frame;
2850 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
2852 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
2853 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
2854 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2859 if(max_frame <= E1000_RXBUFFER_2048) {
2860 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
2861 } else if(max_frame <= E1000_RXBUFFER_4096) {
2862 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
2863 } else if(max_frame <= E1000_RXBUFFER_8192) {
2864 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
2865 } else if(max_frame <= E1000_RXBUFFER_16384) {
2866 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
2871 netdev->mtu = new_mtu;
2873 if(netif_running(netdev)) {
2874 e1000_down(adapter);
2878 adapter->hw.max_frame_size = max_frame;
2884 * e1000_update_stats - Update the board statistics counters
2885 * @adapter: board private structure
2889 e1000_update_stats(struct e1000_adapter *adapter)
2891 struct e1000_hw *hw = &adapter->hw;
2892 unsigned long flags;
2895 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2897 spin_lock_irqsave(&adapter->stats_lock, flags);
2899 /* these counters are modified from e1000_adjust_tbi_stats,
2900 * called from the interrupt context, so they must only
2901 * be written while holding adapter->stats_lock
2904 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
2905 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
2906 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
2907 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
2908 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
2909 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
2910 adapter->stats.roc += E1000_READ_REG(hw, ROC);
2911 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
2912 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
2913 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
2914 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
2915 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
2916 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
2918 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
2919 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
2920 adapter->stats.scc += E1000_READ_REG(hw, SCC);
2921 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
2922 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
2923 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
2924 adapter->stats.dc += E1000_READ_REG(hw, DC);
2925 adapter->stats.sec += E1000_READ_REG(hw, SEC);
2926 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
2927 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
2928 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
2929 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
2930 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
2931 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
2932 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
2933 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
2934 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
2935 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
2936 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
2937 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
2938 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
2939 adapter->stats.torl += E1000_READ_REG(hw, TORL);
2940 adapter->stats.torh += E1000_READ_REG(hw, TORH);
2941 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
2942 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
2943 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
2944 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
2945 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
2946 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
2947 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
2948 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
2949 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
2950 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
2951 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
2953 /* used for adaptive IFS */
2955 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
2956 adapter->stats.tpt += hw->tx_packet_delta;
2957 hw->collision_delta = E1000_READ_REG(hw, COLC);
2958 adapter->stats.colc += hw->collision_delta;
2960 if(hw->mac_type >= e1000_82543) {
2961 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
2962 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
2963 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
2964 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
2965 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
2966 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
2968 if(hw->mac_type > e1000_82547_rev_2) {
2969 adapter->stats.iac += E1000_READ_REG(hw, IAC);
2970 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
2971 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
2972 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
2973 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
2974 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
2975 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
2976 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
2977 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
2980 /* Fill out the OS statistics structure */
2982 adapter->net_stats.rx_packets = adapter->stats.gprc;
2983 adapter->net_stats.tx_packets = adapter->stats.gptc;
2984 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
2985 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
2986 adapter->net_stats.multicast = adapter->stats.mprc;
2987 adapter->net_stats.collisions = adapter->stats.colc;
2991 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
2992 adapter->stats.crcerrs + adapter->stats.algnerrc +
2993 adapter->stats.rlec + adapter->stats.mpc +
2994 adapter->stats.cexterr;
2995 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
2996 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2997 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
2998 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
2999 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3003 adapter->net_stats.tx_errors = adapter->stats.ecol +
3004 adapter->stats.latecol;
3005 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3006 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3007 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3009 /* Tx Dropped needs to be maintained elsewhere */
3013 if(hw->media_type == e1000_media_type_copper) {
3014 if((adapter->link_speed == SPEED_1000) &&
3015 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3016 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3017 adapter->phy_stats.idle_errors += phy_tmp;
3020 if((hw->mac_type <= e1000_82546) &&
3021 (hw->phy_type == e1000_phy_m88) &&
3022 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3023 adapter->phy_stats.receive_errors += phy_tmp;
3026 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3029 #ifdef CONFIG_E1000_MQ
3031 e1000_rx_schedule(void *data)
3033 struct net_device *poll_dev, *netdev = data;
3034 struct e1000_adapter *adapter = netdev->priv;
3035 int this_cpu = get_cpu();
3037 poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
3038 if (poll_dev == NULL) {
3043 if (likely(netif_rx_schedule_prep(poll_dev)))
3044 __netif_rx_schedule(poll_dev);
3046 e1000_irq_enable(adapter);
3053 * e1000_intr - Interrupt Handler
3054 * @irq: interrupt number
3055 * @data: pointer to a network interface device structure
3056 * @pt_regs: CPU registers structure
3060 e1000_intr(int irq, void *data, struct pt_regs *regs)
3062 struct net_device *netdev = data;
3063 struct e1000_adapter *adapter = netdev_priv(netdev);
3064 struct e1000_hw *hw = &adapter->hw;
3065 uint32_t icr = E1000_READ_REG(hw, ICR);
3069 return IRQ_NONE; /* Not our interrupt */
3071 if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3072 hw->get_link_status = 1;
3073 mod_timer(&adapter->watchdog_timer, jiffies);
3076 #ifdef CONFIG_E1000_NAPI
3077 atomic_inc(&adapter->irq_sem);
3078 E1000_WRITE_REG(hw, IMC, ~0);
3079 E1000_WRITE_FLUSH(hw);
3080 #ifdef CONFIG_E1000_MQ
3081 if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
3082 cpu_set(adapter->cpu_for_queue[0],
3083 adapter->rx_sched_call_data.cpumask);
3084 for (i = 1; i < adapter->num_queues; i++) {
3085 cpu_set(adapter->cpu_for_queue[i],
3086 adapter->rx_sched_call_data.cpumask);
3087 atomic_inc(&adapter->irq_sem);
3089 atomic_set(&adapter->rx_sched_call_data.count, i);
3090 smp_call_async_mask(&adapter->rx_sched_call_data);
3092 printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
3095 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3096 __netif_rx_schedule(&adapter->polling_netdev[0]);
3098 e1000_irq_enable(adapter);
3101 /* Writing IMC and IMS is needed for 82547.
3102 Due to Hub Link bus being occupied, an interrupt
3103 de-assertion message is not able to be sent.
3104 When an interrupt assertion message is generated later,
3105 two messages are re-ordered and sent out.
3106 That causes APIC to think 82547 is in de-assertion
3107 state, while 82547 is in assertion state, resulting
3108 in dead lock. Writing IMC forces 82547 into
3111 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
3112 atomic_inc(&adapter->irq_sem);
3113 E1000_WRITE_REG(hw, IMC, ~0);
3116 for(i = 0; i < E1000_MAX_INTR; i++)
3117 if(unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3118 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3121 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3122 e1000_irq_enable(adapter);
3129 #ifdef CONFIG_E1000_NAPI
3131 * e1000_clean - NAPI Rx polling callback
3132 * @adapter: board private structure
3136 e1000_clean(struct net_device *poll_dev, int *budget)
3138 struct e1000_adapter *adapter;
3139 int work_to_do = min(*budget, poll_dev->quota);
3140 int tx_cleaned, i = 0, work_done = 0;
3142 /* Must NOT use netdev_priv macro here. */
3143 adapter = poll_dev->priv;
3145 /* Keep link state information with original netdev */
3146 if (!netif_carrier_ok(adapter->netdev))
3149 while (poll_dev != &adapter->polling_netdev[i]) {
3151 if (unlikely(i == adapter->num_queues))
3155 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3156 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3157 &work_done, work_to_do);
3159 *budget -= work_done;
3160 poll_dev->quota -= work_done;
3162 /* If no Tx and not enough Rx work done, exit the polling mode */
3163 if((!tx_cleaned && (work_done == 0)) ||
3164 !netif_running(adapter->netdev)) {
3166 netif_rx_complete(poll_dev);
3167 e1000_irq_enable(adapter);
3176 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3177 * @adapter: board private structure
3181 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3182 struct e1000_tx_ring *tx_ring)
3184 struct net_device *netdev = adapter->netdev;
3185 struct e1000_tx_desc *tx_desc, *eop_desc;
3186 struct e1000_buffer *buffer_info;
3187 unsigned int i, eop;
3188 boolean_t cleaned = FALSE;
3190 i = tx_ring->next_to_clean;
3191 eop = tx_ring->buffer_info[i].next_to_watch;
3192 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3194 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3195 /* Premature writeback of Tx descriptors clear (free buffers
3196 * and unmap pci_mapping) previous_buffer_info */
3197 if (likely(tx_ring->previous_buffer_info.skb != NULL)) {
3198 e1000_unmap_and_free_tx_resource(adapter,
3199 &tx_ring->previous_buffer_info);
3202 for(cleaned = FALSE; !cleaned; ) {
3203 tx_desc = E1000_TX_DESC(*tx_ring, i);
3204 buffer_info = &tx_ring->buffer_info[i];
3205 cleaned = (i == eop);
3208 if (!(netdev->features & NETIF_F_TSO)) {
3210 e1000_unmap_and_free_tx_resource(adapter,
3215 memcpy(&tx_ring->previous_buffer_info,
3217 sizeof(struct e1000_buffer));
3218 memset(buffer_info, 0,
3219 sizeof(struct e1000_buffer));
3221 e1000_unmap_and_free_tx_resource(
3222 adapter, buffer_info);
3227 tx_desc->buffer_addr = 0;
3228 tx_desc->lower.data = 0;
3229 tx_desc->upper.data = 0;
3231 if(unlikely(++i == tx_ring->count)) i = 0;
3236 eop = tx_ring->buffer_info[i].next_to_watch;
3237 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3240 tx_ring->next_to_clean = i;
3242 spin_lock(&tx_ring->tx_lock);
3244 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
3245 netif_carrier_ok(netdev)))
3246 netif_wake_queue(netdev);
3248 spin_unlock(&tx_ring->tx_lock);
3250 if (adapter->detect_tx_hung) {
3251 /* Detect a transmit hang in hardware, this serializes the
3252 * check with the clearing of time_stamp and movement of i */
3253 adapter->detect_tx_hung = FALSE;
3254 if (tx_ring->buffer_info[i].dma &&
3255 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
3256 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3257 E1000_STATUS_TXOFF)) {
3259 /* detected Tx unit hang */
3260 i = tx_ring->next_to_clean;
3261 eop = tx_ring->buffer_info[i].next_to_watch;
3262 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3263 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3266 " next_to_use <%x>\n"
3267 " next_to_clean <%x>\n"
3268 "buffer_info[next_to_clean]\n"
3270 " time_stamp <%lx>\n"
3271 " next_to_watch <%x>\n"
3273 " next_to_watch.status <%x>\n",
3274 readl(adapter->hw.hw_addr + tx_ring->tdh),
3275 readl(adapter->hw.hw_addr + tx_ring->tdt),
3276 tx_ring->next_to_use,
3278 (unsigned long long)tx_ring->buffer_info[i].dma,
3279 tx_ring->buffer_info[i].time_stamp,
3282 eop_desc->upper.fields.status);
3283 netif_stop_queue(netdev);
3287 if (unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3288 time_after(jiffies, tx_ring->previous_buffer_info.time_stamp + HZ)))
3289 e1000_unmap_and_free_tx_resource(
3290 adapter, &tx_ring->previous_buffer_info);
3296 * e1000_rx_checksum - Receive Checksum Offload for 82543
3297 * @adapter: board private structure
3298 * @status_err: receive descriptor status and error fields
3299 * @csum: receive descriptor csum field
3300 * @sk_buff: socket buffer with received data
3304 e1000_rx_checksum(struct e1000_adapter *adapter,
3305 uint32_t status_err, uint32_t csum,
3306 struct sk_buff *skb)
3308 uint16_t status = (uint16_t)status_err;
3309 uint8_t errors = (uint8_t)(status_err >> 24);
3310 skb->ip_summed = CHECKSUM_NONE;
3312 /* 82543 or newer only */
3313 if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
3314 /* Ignore Checksum bit is set */
3315 if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
3316 /* TCP/UDP checksum error bit is set */
3317 if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
3318 /* let the stack verify checksum errors */
3319 adapter->hw_csum_err++;
3322 /* TCP/UDP Checksum has not been calculated */
3323 if(adapter->hw.mac_type <= e1000_82547_rev_2) {
3324 if(!(status & E1000_RXD_STAT_TCPCS))
3327 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3330 /* It must be a TCP or UDP packet with a valid checksum */
3331 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3332 /* TCP checksum is good */
3333 skb->ip_summed = CHECKSUM_UNNECESSARY;
3334 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3335 /* IP fragment with UDP payload */
3336 /* Hardware complements the payload checksum, so we undo it
3337 * and then put the value in host order for further stack use.
3339 csum = ntohl(csum ^ 0xFFFF);
3341 skb->ip_summed = CHECKSUM_HW;
3343 adapter->hw_csum_good++;
3347 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3348 * @adapter: board private structure
3352 #ifdef CONFIG_E1000_NAPI
3353 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3354 struct e1000_rx_ring *rx_ring,
3355 int *work_done, int work_to_do)
3357 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3358 struct e1000_rx_ring *rx_ring)
3361 struct net_device *netdev = adapter->netdev;
3362 struct pci_dev *pdev = adapter->pdev;
3363 struct e1000_rx_desc *rx_desc;
3364 struct e1000_buffer *buffer_info;
3365 struct sk_buff *skb;
3366 unsigned long flags;
3370 boolean_t cleaned = FALSE;
3372 i = rx_ring->next_to_clean;
3373 rx_desc = E1000_RX_DESC(*rx_ring, i);
3375 while(rx_desc->status & E1000_RXD_STAT_DD) {
3376 buffer_info = &rx_ring->buffer_info[i];
3377 #ifdef CONFIG_E1000_NAPI
3378 if(*work_done >= work_to_do)
3384 pci_unmap_single(pdev,
3386 buffer_info->length,
3387 PCI_DMA_FROMDEVICE);
3389 skb = buffer_info->skb;
3390 length = le16_to_cpu(rx_desc->length);
3392 if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
3393 /* All receives must fit into a single buffer */
3394 E1000_DBG("%s: Receive packet consumed multiple"
3395 " buffers\n", netdev->name);
3396 dev_kfree_skb_irq(skb);
3400 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3401 last_byte = *(skb->data + length - 1);
3402 if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
3403 rx_desc->errors, length, last_byte)) {
3404 spin_lock_irqsave(&adapter->stats_lock, flags);
3405 e1000_tbi_adjust_stats(&adapter->hw,
3408 spin_unlock_irqrestore(&adapter->stats_lock,
3412 dev_kfree_skb_irq(skb);
3418 skb_put(skb, length - ETHERNET_FCS_SIZE);
3420 /* Receive Checksum Offload */
3421 e1000_rx_checksum(adapter,
3422 (uint32_t)(rx_desc->status) |
3423 ((uint32_t)(rx_desc->errors) << 24),
3424 rx_desc->csum, skb);
3425 skb->protocol = eth_type_trans(skb, netdev);
3426 #ifdef CONFIG_E1000_NAPI
3427 if(unlikely(adapter->vlgrp &&
3428 (rx_desc->status & E1000_RXD_STAT_VP))) {
3429 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3430 le16_to_cpu(rx_desc->special) &
3431 E1000_RXD_SPC_VLAN_MASK);
3433 netif_receive_skb(skb);
3435 #else /* CONFIG_E1000_NAPI */
3436 if(unlikely(adapter->vlgrp &&
3437 (rx_desc->status & E1000_RXD_STAT_VP))) {
3438 vlan_hwaccel_rx(skb, adapter->vlgrp,
3439 le16_to_cpu(rx_desc->special) &
3440 E1000_RXD_SPC_VLAN_MASK);
3444 #endif /* CONFIG_E1000_NAPI */
3445 netdev->last_rx = jiffies;
3449 rx_desc->status = 0;
3450 buffer_info->skb = NULL;
3451 if(unlikely(++i == rx_ring->count)) i = 0;
3453 rx_desc = E1000_RX_DESC(*rx_ring, i);
3455 rx_ring->next_to_clean = i;
3456 adapter->alloc_rx_buf(adapter, rx_ring);
3462 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3463 * @adapter: board private structure
3467 #ifdef CONFIG_E1000_NAPI
3468 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3469 struct e1000_rx_ring *rx_ring,
3470 int *work_done, int work_to_do)
3472 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3473 struct e1000_rx_ring *rx_ring)
3476 union e1000_rx_desc_packet_split *rx_desc;
3477 struct net_device *netdev = adapter->netdev;
3478 struct pci_dev *pdev = adapter->pdev;
3479 struct e1000_buffer *buffer_info;
3480 struct e1000_ps_page *ps_page;
3481 struct e1000_ps_page_dma *ps_page_dma;
3482 struct sk_buff *skb;
3484 uint32_t length, staterr;
3485 boolean_t cleaned = FALSE;
3487 i = rx_ring->next_to_clean;
3488 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3489 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3491 while(staterr & E1000_RXD_STAT_DD) {
3492 buffer_info = &rx_ring->buffer_info[i];
3493 ps_page = &rx_ring->ps_page[i];
3494 ps_page_dma = &rx_ring->ps_page_dma[i];
3495 #ifdef CONFIG_E1000_NAPI
3496 if(unlikely(*work_done >= work_to_do))
3501 pci_unmap_single(pdev, buffer_info->dma,
3502 buffer_info->length,
3503 PCI_DMA_FROMDEVICE);
3505 skb = buffer_info->skb;
3507 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3508 E1000_DBG("%s: Packet Split buffers didn't pick up"
3509 " the full packet\n", netdev->name);
3510 dev_kfree_skb_irq(skb);
3514 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3515 dev_kfree_skb_irq(skb);
3519 length = le16_to_cpu(rx_desc->wb.middle.length0);
3521 if(unlikely(!length)) {
3522 E1000_DBG("%s: Last part of the packet spanning"
3523 " multiple descriptors\n", netdev->name);
3524 dev_kfree_skb_irq(skb);
3529 skb_put(skb, length);
3531 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3532 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3535 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3536 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3537 ps_page_dma->ps_page_dma[j] = 0;
3538 skb_shinfo(skb)->frags[j].page =
3539 ps_page->ps_page[j];
3540 ps_page->ps_page[j] = NULL;
3541 skb_shinfo(skb)->frags[j].page_offset = 0;
3542 skb_shinfo(skb)->frags[j].size = length;
3543 skb_shinfo(skb)->nr_frags++;
3545 skb->data_len += length;
3548 e1000_rx_checksum(adapter, staterr,
3549 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3550 skb->protocol = eth_type_trans(skb, netdev);
3552 #ifdef HAVE_RX_ZERO_COPY
3553 if(likely(rx_desc->wb.upper.header_status &
3554 E1000_RXDPS_HDRSTAT_HDRSP))
3555 skb_shinfo(skb)->zero_copy = TRUE;
3557 #ifdef CONFIG_E1000_NAPI
3558 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3559 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3560 le16_to_cpu(rx_desc->wb.middle.vlan) &
3561 E1000_RXD_SPC_VLAN_MASK);
3563 netif_receive_skb(skb);
3565 #else /* CONFIG_E1000_NAPI */
3566 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3567 vlan_hwaccel_rx(skb, adapter->vlgrp,
3568 le16_to_cpu(rx_desc->wb.middle.vlan) &
3569 E1000_RXD_SPC_VLAN_MASK);
3573 #endif /* CONFIG_E1000_NAPI */
3574 netdev->last_rx = jiffies;
3578 rx_desc->wb.middle.status_error &= ~0xFF;
3579 buffer_info->skb = NULL;
3580 if(unlikely(++i == rx_ring->count)) i = 0;
3582 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3583 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3585 rx_ring->next_to_clean = i;
3586 adapter->alloc_rx_buf(adapter, rx_ring);
3592 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3593 * @adapter: address of board private structure
3597 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3598 struct e1000_rx_ring *rx_ring)
3600 struct net_device *netdev = adapter->netdev;
3601 struct pci_dev *pdev = adapter->pdev;
3602 struct e1000_rx_desc *rx_desc;
3603 struct e1000_buffer *buffer_info;
3604 struct sk_buff *skb;
3606 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3608 i = rx_ring->next_to_use;
3609 buffer_info = &rx_ring->buffer_info[i];
3611 while(!buffer_info->skb) {
3612 skb = dev_alloc_skb(bufsz);
3614 if(unlikely(!skb)) {
3615 /* Better luck next round */
3619 /* Fix for errata 23, can't cross 64kB boundary */
3620 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3621 struct sk_buff *oldskb = skb;
3622 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3623 "at %p\n", bufsz, skb->data);
3624 /* Try again, without freeing the previous */
3625 skb = dev_alloc_skb(bufsz);
3626 /* Failed allocation, critical failure */
3628 dev_kfree_skb(oldskb);
3632 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3635 dev_kfree_skb(oldskb);
3636 break; /* while !buffer_info->skb */
3638 /* Use new allocation */
3639 dev_kfree_skb(oldskb);
3642 /* Make buffer alignment 2 beyond a 16 byte boundary
3643 * this will result in a 16 byte aligned IP header after
3644 * the 14 byte MAC header is removed
3646 skb_reserve(skb, NET_IP_ALIGN);
3650 buffer_info->skb = skb;
3651 buffer_info->length = adapter->rx_buffer_len;
3652 buffer_info->dma = pci_map_single(pdev,
3654 adapter->rx_buffer_len,
3655 PCI_DMA_FROMDEVICE);
3657 /* Fix for errata 23, can't cross 64kB boundary */
3658 if (!e1000_check_64k_bound(adapter,
3659 (void *)(unsigned long)buffer_info->dma,
3660 adapter->rx_buffer_len)) {
3661 DPRINTK(RX_ERR, ERR,
3662 "dma align check failed: %u bytes at %p\n",
3663 adapter->rx_buffer_len,
3664 (void *)(unsigned long)buffer_info->dma);
3666 buffer_info->skb = NULL;
3668 pci_unmap_single(pdev, buffer_info->dma,
3669 adapter->rx_buffer_len,
3670 PCI_DMA_FROMDEVICE);
3672 break; /* while !buffer_info->skb */
3674 rx_desc = E1000_RX_DESC(*rx_ring, i);
3675 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3677 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3678 /* Force memory writes to complete before letting h/w
3679 * know there are new descriptors to fetch. (Only
3680 * applicable for weak-ordered memory model archs,
3681 * such as IA-64). */
3683 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3686 if(unlikely(++i == rx_ring->count)) i = 0;
3687 buffer_info = &rx_ring->buffer_info[i];
3690 rx_ring->next_to_use = i;
3694 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3695 * @adapter: address of board private structure
3699 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3700 struct e1000_rx_ring *rx_ring)
3702 struct net_device *netdev = adapter->netdev;
3703 struct pci_dev *pdev = adapter->pdev;
3704 union e1000_rx_desc_packet_split *rx_desc;
3705 struct e1000_buffer *buffer_info;
3706 struct e1000_ps_page *ps_page;
3707 struct e1000_ps_page_dma *ps_page_dma;
3708 struct sk_buff *skb;
3711 i = rx_ring->next_to_use;
3712 buffer_info = &rx_ring->buffer_info[i];
3713 ps_page = &rx_ring->ps_page[i];
3714 ps_page_dma = &rx_ring->ps_page_dma[i];
3716 while(!buffer_info->skb) {
3717 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3719 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3720 if(unlikely(!ps_page->ps_page[j])) {
3721 ps_page->ps_page[j] =
3722 alloc_page(GFP_ATOMIC);
3723 if(unlikely(!ps_page->ps_page[j]))
3725 ps_page_dma->ps_page_dma[j] =
3727 ps_page->ps_page[j],
3729 PCI_DMA_FROMDEVICE);
3731 /* Refresh the desc even if buffer_addrs didn't
3732 * change because each write-back erases this info.
3734 rx_desc->read.buffer_addr[j+1] =
3735 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3738 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3743 /* Make buffer alignment 2 beyond a 16 byte boundary
3744 * this will result in a 16 byte aligned IP header after
3745 * the 14 byte MAC header is removed
3747 skb_reserve(skb, NET_IP_ALIGN);
3751 buffer_info->skb = skb;
3752 buffer_info->length = adapter->rx_ps_bsize0;
3753 buffer_info->dma = pci_map_single(pdev, skb->data,
3754 adapter->rx_ps_bsize0,
3755 PCI_DMA_FROMDEVICE);
3757 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
3759 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3760 /* Force memory writes to complete before letting h/w
3761 * know there are new descriptors to fetch. (Only
3762 * applicable for weak-ordered memory model archs,
3763 * such as IA-64). */
3765 /* Hardware increments by 16 bytes, but packet split
3766 * descriptors are 32 bytes...so we increment tail
3769 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
3772 if(unlikely(++i == rx_ring->count)) i = 0;
3773 buffer_info = &rx_ring->buffer_info[i];
3774 ps_page = &rx_ring->ps_page[i];
3775 ps_page_dma = &rx_ring->ps_page_dma[i];
3779 rx_ring->next_to_use = i;
3783 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3788 e1000_smartspeed(struct e1000_adapter *adapter)
3790 uint16_t phy_status;
3793 if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
3794 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
3797 if(adapter->smartspeed == 0) {
3798 /* If Master/Slave config fault is asserted twice,
3799 * we assume back-to-back */
3800 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3801 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3802 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3803 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3804 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3805 if(phy_ctrl & CR_1000T_MS_ENABLE) {
3806 phy_ctrl &= ~CR_1000T_MS_ENABLE;
3807 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
3809 adapter->smartspeed++;
3810 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3811 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
3813 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3814 MII_CR_RESTART_AUTO_NEG);
3815 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
3820 } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
3821 /* If still no link, perhaps using 2/3 pair cable */
3822 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3823 phy_ctrl |= CR_1000T_MS_ENABLE;
3824 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
3825 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3826 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
3827 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3828 MII_CR_RESTART_AUTO_NEG);
3829 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
3832 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3833 if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
3834 adapter->smartspeed = 0;
3845 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3851 return e1000_mii_ioctl(netdev, ifr, cmd);
3865 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3867 struct e1000_adapter *adapter = netdev_priv(netdev);
3868 struct mii_ioctl_data *data = if_mii(ifr);
3872 unsigned long flags;
3874 if(adapter->hw.media_type != e1000_media_type_copper)
3879 data->phy_id = adapter->hw.phy_addr;
3882 if(!capable(CAP_NET_ADMIN))
3884 spin_lock_irqsave(&adapter->stats_lock, flags);
3885 if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
3887 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3890 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3893 if(!capable(CAP_NET_ADMIN))
3895 if(data->reg_num & ~(0x1F))
3897 mii_reg = data->val_in;
3898 spin_lock_irqsave(&adapter->stats_lock, flags);
3899 if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
3901 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3904 if(adapter->hw.phy_type == e1000_phy_m88) {
3905 switch (data->reg_num) {
3907 if(mii_reg & MII_CR_POWER_DOWN)
3909 if(mii_reg & MII_CR_AUTO_NEG_EN) {
3910 adapter->hw.autoneg = 1;
3911 adapter->hw.autoneg_advertised = 0x2F;
3914 spddplx = SPEED_1000;
3915 else if (mii_reg & 0x2000)
3916 spddplx = SPEED_100;
3919 spddplx += (mii_reg & 0x100)
3922 retval = e1000_set_spd_dplx(adapter,
3925 spin_unlock_irqrestore(
3926 &adapter->stats_lock,
3931 if(netif_running(adapter->netdev)) {
3932 e1000_down(adapter);
3935 e1000_reset(adapter);
3937 case M88E1000_PHY_SPEC_CTRL:
3938 case M88E1000_EXT_PHY_SPEC_CTRL:
3939 if(e1000_phy_reset(&adapter->hw)) {
3940 spin_unlock_irqrestore(
3941 &adapter->stats_lock, flags);
3947 switch (data->reg_num) {
3949 if(mii_reg & MII_CR_POWER_DOWN)
3951 if(netif_running(adapter->netdev)) {
3952 e1000_down(adapter);
3955 e1000_reset(adapter);
3959 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3964 return E1000_SUCCESS;
3968 e1000_pci_set_mwi(struct e1000_hw *hw)
3970 struct e1000_adapter *adapter = hw->back;
3971 int ret_val = pci_set_mwi(adapter->pdev);
3974 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
3978 e1000_pci_clear_mwi(struct e1000_hw *hw)
3980 struct e1000_adapter *adapter = hw->back;
3982 pci_clear_mwi(adapter->pdev);
3986 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3988 struct e1000_adapter *adapter = hw->back;
3990 pci_read_config_word(adapter->pdev, reg, value);
3994 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3996 struct e1000_adapter *adapter = hw->back;
3998 pci_write_config_word(adapter->pdev, reg, *value);
4002 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4008 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4014 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4016 struct e1000_adapter *adapter = netdev_priv(netdev);
4017 uint32_t ctrl, rctl;
4019 e1000_irq_disable(adapter);
4020 adapter->vlgrp = grp;
4023 /* enable VLAN tag insert/strip */
4024 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4025 ctrl |= E1000_CTRL_VME;
4026 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4028 /* enable VLAN receive filtering */
4029 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4030 rctl |= E1000_RCTL_VFE;
4031 rctl &= ~E1000_RCTL_CFIEN;
4032 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4033 e1000_update_mng_vlan(adapter);
4035 /* disable VLAN tag insert/strip */
4036 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4037 ctrl &= ~E1000_CTRL_VME;
4038 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4040 /* disable VLAN filtering */
4041 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4042 rctl &= ~E1000_RCTL_VFE;
4043 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4044 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4045 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4046 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4050 e1000_irq_enable(adapter);
4054 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4056 struct e1000_adapter *adapter = netdev_priv(netdev);
4057 uint32_t vfta, index;
4058 if((adapter->hw.mng_cookie.status &
4059 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4060 (vid == adapter->mng_vlan_id))
4062 /* add VID to filter table */
4063 index = (vid >> 5) & 0x7F;
4064 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4065 vfta |= (1 << (vid & 0x1F));
4066 e1000_write_vfta(&adapter->hw, index, vfta);
4070 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4072 struct e1000_adapter *adapter = netdev_priv(netdev);
4073 uint32_t vfta, index;
4075 e1000_irq_disable(adapter);
4078 adapter->vlgrp->vlan_devices[vid] = NULL;
4080 e1000_irq_enable(adapter);
4082 if((adapter->hw.mng_cookie.status &
4083 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4084 (vid == adapter->mng_vlan_id))
4086 /* remove VID from filter table */
4087 index = (vid >> 5) & 0x7F;
4088 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4089 vfta &= ~(1 << (vid & 0x1F));
4090 e1000_write_vfta(&adapter->hw, index, vfta);
4094 e1000_restore_vlan(struct e1000_adapter *adapter)
4096 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4098 if(adapter->vlgrp) {
4100 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4101 if(!adapter->vlgrp->vlan_devices[vid])
4103 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4109 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4111 adapter->hw.autoneg = 0;
4113 /* Fiber NICs only allow 1000 gbps Full duplex */
4114 if((adapter->hw.media_type == e1000_media_type_fiber) &&
4115 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4116 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4121 case SPEED_10 + DUPLEX_HALF:
4122 adapter->hw.forced_speed_duplex = e1000_10_half;
4124 case SPEED_10 + DUPLEX_FULL:
4125 adapter->hw.forced_speed_duplex = e1000_10_full;
4127 case SPEED_100 + DUPLEX_HALF:
4128 adapter->hw.forced_speed_duplex = e1000_100_half;
4130 case SPEED_100 + DUPLEX_FULL:
4131 adapter->hw.forced_speed_duplex = e1000_100_full;
4133 case SPEED_1000 + DUPLEX_FULL:
4134 adapter->hw.autoneg = 1;
4135 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4137 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4139 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4146 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4148 struct net_device *netdev = pci_get_drvdata(pdev);
4149 struct e1000_adapter *adapter = netdev_priv(netdev);
4150 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
4151 uint32_t wufc = adapter->wol;
4153 netif_device_detach(netdev);
4155 if(netif_running(netdev))
4156 e1000_down(adapter);
4158 status = E1000_READ_REG(&adapter->hw, STATUS);
4159 if(status & E1000_STATUS_LU)
4160 wufc &= ~E1000_WUFC_LNKC;
4163 e1000_setup_rctl(adapter);
4164 e1000_set_multi(netdev);
4166 /* turn on all-multi mode if wake on multicast is enabled */
4167 if(adapter->wol & E1000_WUFC_MC) {
4168 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4169 rctl |= E1000_RCTL_MPE;
4170 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4173 if(adapter->hw.mac_type >= e1000_82540) {
4174 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4175 /* advertise wake from D3Cold */
4176 #define E1000_CTRL_ADVD3WUC 0x00100000
4177 /* phy power management enable */
4178 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4179 ctrl |= E1000_CTRL_ADVD3WUC |
4180 E1000_CTRL_EN_PHY_PWR_MGMT;
4181 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4184 if(adapter->hw.media_type == e1000_media_type_fiber ||
4185 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4186 /* keep the laser running in D3 */
4187 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4188 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4189 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4192 /* Allow time for pending master requests to run */
4193 e1000_disable_pciex_master(&adapter->hw);
4195 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4196 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4197 pci_enable_wake(pdev, 3, 1);
4198 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
4200 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4201 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4202 pci_enable_wake(pdev, 3, 0);
4203 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
4206 pci_save_state(pdev);
4208 if(adapter->hw.mac_type >= e1000_82540 &&
4209 adapter->hw.media_type == e1000_media_type_copper) {
4210 manc = E1000_READ_REG(&adapter->hw, MANC);
4211 if(manc & E1000_MANC_SMBUS_EN) {
4212 manc |= E1000_MANC_ARP_EN;
4213 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4214 pci_enable_wake(pdev, 3, 1);
4215 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
4219 switch(adapter->hw.mac_type) {
4222 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4223 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
4224 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
4227 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4228 E1000_WRITE_REG(&adapter->hw, SWSM,
4229 swsm & ~E1000_SWSM_DRV_LOAD);
4235 pci_disable_device(pdev);
4236 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4243 e1000_resume(struct pci_dev *pdev)
4245 struct net_device *netdev = pci_get_drvdata(pdev);
4246 struct e1000_adapter *adapter = netdev_priv(netdev);
4247 uint32_t manc, ret_val, swsm;
4250 pci_set_power_state(pdev, PCI_D0);
4251 pci_restore_state(pdev);
4252 ret_val = pci_enable_device(pdev);
4253 pci_set_master(pdev);
4255 pci_enable_wake(pdev, PCI_D3hot, 0);
4256 pci_enable_wake(pdev, PCI_D3cold, 0);
4258 e1000_reset(adapter);
4259 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4261 if(netif_running(netdev))
4264 netif_device_attach(netdev);
4266 if(adapter->hw.mac_type >= e1000_82540 &&
4267 adapter->hw.media_type == e1000_media_type_copper) {
4268 manc = E1000_READ_REG(&adapter->hw, MANC);
4269 manc &= ~(E1000_MANC_ARP_EN);
4270 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4273 switch(adapter->hw.mac_type) {
4276 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4277 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
4278 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
4281 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4282 E1000_WRITE_REG(&adapter->hw, SWSM,
4283 swsm | E1000_SWSM_DRV_LOAD);
4292 #ifdef CONFIG_NET_POLL_CONTROLLER
4294 * Polling 'interrupt' - used by things like netconsole to send skbs
4295 * without having to re-enable interrupts. It's not called while
4296 * the interrupt routine is executing.
4299 e1000_netpoll(struct net_device *netdev)
4301 struct e1000_adapter *adapter = netdev_priv(netdev);
4302 disable_irq(adapter->pdev->irq);
4303 e1000_intr(adapter->pdev->irq, netdev, NULL);
4304 e1000_clean_tx_irq(adapter);
4305 enable_irq(adapter->pdev->irq);