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);
780 #ifdef CONFIG_E1000_NAPI
784 flush_scheduled_work();
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);
1154 memset(&txdr->previous_buffer_info, 0, sizeof(struct e1000_buffer));
1156 /* round up to nearest 4K */
1158 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1159 E1000_ROUNDUP(txdr->size, 4096);
1161 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1164 vfree(txdr->buffer_info);
1166 "Unable to allocate memory for the transmit descriptor ring\n");
1170 /* Fix for errata 23, can't cross 64kB boundary */
1171 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1172 void *olddesc = txdr->desc;
1173 dma_addr_t olddma = txdr->dma;
1174 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1175 "at %p\n", txdr->size, txdr->desc);
1176 /* Try again, without freeing the previous */
1177 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1179 /* Failed allocation, critical failure */
1180 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1181 goto setup_tx_desc_die;
1184 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1186 pci_free_consistent(pdev, txdr->size, txdr->desc,
1188 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1190 "Unable to allocate aligned memory "
1191 "for the transmit descriptor ring\n");
1192 vfree(txdr->buffer_info);
1195 /* Free old allocation, new allocation was successful */
1196 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1199 memset(txdr->desc, 0, txdr->size);
1201 txdr->next_to_use = 0;
1202 txdr->next_to_clean = 0;
1203 spin_lock_init(&txdr->tx_lock);
1209 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1210 * (Descriptors) for all queues
1211 * @adapter: board private structure
1213 * If this function returns with an error, then it's possible one or
1214 * more of the rings is populated (while the rest are not). It is the
1215 * callers duty to clean those orphaned rings.
1217 * Return 0 on success, negative on failure
1221 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1225 for (i = 0; i < adapter->num_queues; i++) {
1226 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1229 "Allocation for Tx Queue %u failed\n", i);
1238 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1239 * @adapter: board private structure
1241 * Configure the Tx unit of the MAC after a reset.
1245 e1000_configure_tx(struct e1000_adapter *adapter)
1248 struct e1000_hw *hw = &adapter->hw;
1249 uint32_t tdlen, tctl, tipg, tarc;
1251 /* Setup the HW Tx Head and Tail descriptor pointers */
1253 switch (adapter->num_queues) {
1255 tdba = adapter->tx_ring[1].dma;
1256 tdlen = adapter->tx_ring[1].count *
1257 sizeof(struct e1000_tx_desc);
1258 E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
1259 E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
1260 E1000_WRITE_REG(hw, TDLEN1, tdlen);
1261 E1000_WRITE_REG(hw, TDH1, 0);
1262 E1000_WRITE_REG(hw, TDT1, 0);
1263 adapter->tx_ring[1].tdh = E1000_TDH1;
1264 adapter->tx_ring[1].tdt = E1000_TDT1;
1268 tdba = adapter->tx_ring[0].dma;
1269 tdlen = adapter->tx_ring[0].count *
1270 sizeof(struct e1000_tx_desc);
1271 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1272 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1273 E1000_WRITE_REG(hw, TDLEN, tdlen);
1274 E1000_WRITE_REG(hw, TDH, 0);
1275 E1000_WRITE_REG(hw, TDT, 0);
1276 adapter->tx_ring[0].tdh = E1000_TDH;
1277 adapter->tx_ring[0].tdt = E1000_TDT;
1281 /* Set the default values for the Tx Inter Packet Gap timer */
1283 switch (hw->mac_type) {
1284 case e1000_82542_rev2_0:
1285 case e1000_82542_rev2_1:
1286 tipg = DEFAULT_82542_TIPG_IPGT;
1287 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1288 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1291 if (hw->media_type == e1000_media_type_fiber ||
1292 hw->media_type == e1000_media_type_internal_serdes)
1293 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1295 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1296 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1297 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1299 E1000_WRITE_REG(hw, TIPG, tipg);
1301 /* Set the Tx Interrupt Delay register */
1303 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1304 if (hw->mac_type >= e1000_82540)
1305 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1307 /* Program the Transmit Control Register */
1309 tctl = E1000_READ_REG(hw, TCTL);
1311 tctl &= ~E1000_TCTL_CT;
1312 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
1313 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1315 E1000_WRITE_REG(hw, TCTL, tctl);
1317 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1318 tarc = E1000_READ_REG(hw, TARC0);
1319 tarc |= ((1 << 25) | (1 << 21));
1320 E1000_WRITE_REG(hw, TARC0, tarc);
1321 tarc = E1000_READ_REG(hw, TARC1);
1323 if (tctl & E1000_TCTL_MULR)
1327 E1000_WRITE_REG(hw, TARC1, tarc);
1330 e1000_config_collision_dist(hw);
1332 /* Setup Transmit Descriptor Settings for eop descriptor */
1333 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1336 if (hw->mac_type < e1000_82543)
1337 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1339 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1341 /* Cache if we're 82544 running in PCI-X because we'll
1342 * need this to apply a workaround later in the send path. */
1343 if (hw->mac_type == e1000_82544 &&
1344 hw->bus_type == e1000_bus_type_pcix)
1345 adapter->pcix_82544 = 1;
1349 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1350 * @adapter: board private structure
1351 * @rxdr: rx descriptor ring (for a specific queue) to setup
1353 * Returns 0 on success, negative on failure
1357 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1358 struct e1000_rx_ring *rxdr)
1360 struct pci_dev *pdev = adapter->pdev;
1363 size = sizeof(struct e1000_buffer) * rxdr->count;
1364 rxdr->buffer_info = vmalloc(size);
1365 if (!rxdr->buffer_info) {
1367 "Unable to allocate memory for the receive descriptor ring\n");
1370 memset(rxdr->buffer_info, 0, size);
1372 size = sizeof(struct e1000_ps_page) * rxdr->count;
1373 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1374 if(!rxdr->ps_page) {
1375 vfree(rxdr->buffer_info);
1377 "Unable to allocate memory for the receive descriptor ring\n");
1380 memset(rxdr->ps_page, 0, size);
1382 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1383 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1384 if(!rxdr->ps_page_dma) {
1385 vfree(rxdr->buffer_info);
1386 kfree(rxdr->ps_page);
1388 "Unable to allocate memory for the receive descriptor ring\n");
1391 memset(rxdr->ps_page_dma, 0, size);
1393 if(adapter->hw.mac_type <= e1000_82547_rev_2)
1394 desc_len = sizeof(struct e1000_rx_desc);
1396 desc_len = sizeof(union e1000_rx_desc_packet_split);
1398 /* Round up to nearest 4K */
1400 rxdr->size = rxdr->count * desc_len;
1401 E1000_ROUNDUP(rxdr->size, 4096);
1403 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1407 "Unable to allocate memory for the receive descriptor ring\n");
1409 vfree(rxdr->buffer_info);
1410 kfree(rxdr->ps_page);
1411 kfree(rxdr->ps_page_dma);
1415 /* Fix for errata 23, can't cross 64kB boundary */
1416 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1417 void *olddesc = rxdr->desc;
1418 dma_addr_t olddma = rxdr->dma;
1419 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1420 "at %p\n", rxdr->size, rxdr->desc);
1421 /* Try again, without freeing the previous */
1422 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1423 /* Failed allocation, critical failure */
1425 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1427 "Unable to allocate memory "
1428 "for the receive descriptor ring\n");
1429 goto setup_rx_desc_die;
1432 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1434 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1436 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1438 "Unable to allocate aligned memory "
1439 "for the receive descriptor ring\n");
1440 goto setup_rx_desc_die;
1442 /* Free old allocation, new allocation was successful */
1443 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1446 memset(rxdr->desc, 0, rxdr->size);
1448 rxdr->next_to_clean = 0;
1449 rxdr->next_to_use = 0;
1455 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1456 * (Descriptors) for all queues
1457 * @adapter: board private structure
1459 * If this function returns with an error, then it's possible one or
1460 * more of the rings is populated (while the rest are not). It is the
1461 * callers duty to clean those orphaned rings.
1463 * Return 0 on success, negative on failure
1467 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1471 for (i = 0; i < adapter->num_queues; i++) {
1472 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1475 "Allocation for Rx Queue %u failed\n", i);
1484 * e1000_setup_rctl - configure the receive control registers
1485 * @adapter: Board private structure
1487 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1488 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1490 e1000_setup_rctl(struct e1000_adapter *adapter)
1492 uint32_t rctl, rfctl;
1493 uint32_t psrctl = 0;
1494 #ifdef CONFIG_E1000_PACKET_SPLIT
1498 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1500 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1502 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1503 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1504 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1506 if(adapter->hw.tbi_compatibility_on == 1)
1507 rctl |= E1000_RCTL_SBP;
1509 rctl &= ~E1000_RCTL_SBP;
1511 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1512 rctl &= ~E1000_RCTL_LPE;
1514 rctl |= E1000_RCTL_LPE;
1516 /* Setup buffer sizes */
1517 if(adapter->hw.mac_type >= e1000_82571) {
1518 /* We can now specify buffers in 1K increments.
1519 * BSIZE and BSEX are ignored in this case. */
1520 rctl |= adapter->rx_buffer_len << 0x11;
1522 rctl &= ~E1000_RCTL_SZ_4096;
1523 rctl |= E1000_RCTL_BSEX;
1524 switch (adapter->rx_buffer_len) {
1525 case E1000_RXBUFFER_2048:
1527 rctl |= E1000_RCTL_SZ_2048;
1528 rctl &= ~E1000_RCTL_BSEX;
1530 case E1000_RXBUFFER_4096:
1531 rctl |= E1000_RCTL_SZ_4096;
1533 case E1000_RXBUFFER_8192:
1534 rctl |= E1000_RCTL_SZ_8192;
1536 case E1000_RXBUFFER_16384:
1537 rctl |= E1000_RCTL_SZ_16384;
1542 #ifdef CONFIG_E1000_PACKET_SPLIT
1543 /* 82571 and greater support packet-split where the protocol
1544 * header is placed in skb->data and the packet data is
1545 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1546 * In the case of a non-split, skb->data is linearly filled,
1547 * followed by the page buffers. Therefore, skb->data is
1548 * sized to hold the largest protocol header.
1550 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1551 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1553 adapter->rx_ps_pages = pages;
1555 adapter->rx_ps_pages = 0;
1557 if (adapter->rx_ps_pages) {
1558 /* Configure extra packet-split registers */
1559 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1560 rfctl |= E1000_RFCTL_EXTEN;
1561 /* disable IPv6 packet split support */
1562 rfctl |= E1000_RFCTL_IPV6_DIS;
1563 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1565 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1567 psrctl |= adapter->rx_ps_bsize0 >>
1568 E1000_PSRCTL_BSIZE0_SHIFT;
1570 switch (adapter->rx_ps_pages) {
1572 psrctl |= PAGE_SIZE <<
1573 E1000_PSRCTL_BSIZE3_SHIFT;
1575 psrctl |= PAGE_SIZE <<
1576 E1000_PSRCTL_BSIZE2_SHIFT;
1578 psrctl |= PAGE_SIZE >>
1579 E1000_PSRCTL_BSIZE1_SHIFT;
1583 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1586 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1590 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1591 * @adapter: board private structure
1593 * Configure the Rx unit of the MAC after a reset.
1597 e1000_configure_rx(struct e1000_adapter *adapter)
1600 struct e1000_hw *hw = &adapter->hw;
1601 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1602 #ifdef CONFIG_E1000_MQ
1603 uint32_t reta, mrqc;
1607 if (adapter->rx_ps_pages) {
1608 rdlen = adapter->rx_ring[0].count *
1609 sizeof(union e1000_rx_desc_packet_split);
1610 adapter->clean_rx = e1000_clean_rx_irq_ps;
1611 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1613 rdlen = adapter->rx_ring[0].count *
1614 sizeof(struct e1000_rx_desc);
1615 adapter->clean_rx = e1000_clean_rx_irq;
1616 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1619 /* disable receives while setting up the descriptors */
1620 rctl = E1000_READ_REG(hw, RCTL);
1621 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1623 /* set the Receive Delay Timer Register */
1624 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1626 if (hw->mac_type >= e1000_82540) {
1627 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1628 if(adapter->itr > 1)
1629 E1000_WRITE_REG(hw, ITR,
1630 1000000000 / (adapter->itr * 256));
1633 if (hw->mac_type >= e1000_82571) {
1634 /* Reset delay timers after every interrupt */
1635 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1636 ctrl_ext |= E1000_CTRL_EXT_CANC;
1637 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1638 E1000_WRITE_FLUSH(hw);
1641 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1642 * the Base and Length of the Rx Descriptor Ring */
1643 switch (adapter->num_queues) {
1644 #ifdef CONFIG_E1000_MQ
1646 rdba = adapter->rx_ring[1].dma;
1647 E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
1648 E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
1649 E1000_WRITE_REG(hw, RDLEN1, rdlen);
1650 E1000_WRITE_REG(hw, RDH1, 0);
1651 E1000_WRITE_REG(hw, RDT1, 0);
1652 adapter->rx_ring[1].rdh = E1000_RDH1;
1653 adapter->rx_ring[1].rdt = E1000_RDT1;
1658 rdba = adapter->rx_ring[0].dma;
1659 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1660 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1661 E1000_WRITE_REG(hw, RDLEN, rdlen);
1662 E1000_WRITE_REG(hw, RDH, 0);
1663 E1000_WRITE_REG(hw, RDT, 0);
1664 adapter->rx_ring[0].rdh = E1000_RDH;
1665 adapter->rx_ring[0].rdt = E1000_RDT;
1669 #ifdef CONFIG_E1000_MQ
1670 if (adapter->num_queues > 1) {
1671 uint32_t random[10];
1673 get_random_bytes(&random[0], 40);
1675 if (hw->mac_type <= e1000_82572) {
1676 E1000_WRITE_REG(hw, RSSIR, 0);
1677 E1000_WRITE_REG(hw, RSSIM, 0);
1680 switch (adapter->num_queues) {
1684 mrqc = E1000_MRQC_ENABLE_RSS_2Q;
1688 /* Fill out redirection table */
1689 for (i = 0; i < 32; i++)
1690 E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
1691 /* Fill out hash function seeds */
1692 for (i = 0; i < 10; i++)
1693 E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
1695 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1696 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1697 E1000_WRITE_REG(hw, MRQC, mrqc);
1700 /* Multiqueue and packet checksumming are mutually exclusive. */
1701 if (hw->mac_type >= e1000_82571) {
1702 rxcsum = E1000_READ_REG(hw, RXCSUM);
1703 rxcsum |= E1000_RXCSUM_PCSD;
1704 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1709 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1710 if (hw->mac_type >= e1000_82543) {
1711 rxcsum = E1000_READ_REG(hw, RXCSUM);
1712 if(adapter->rx_csum == TRUE) {
1713 rxcsum |= E1000_RXCSUM_TUOFL;
1715 /* Enable 82571 IPv4 payload checksum for UDP fragments
1716 * Must be used in conjunction with packet-split. */
1717 if ((hw->mac_type >= e1000_82571) &&
1718 (adapter->rx_ps_pages)) {
1719 rxcsum |= E1000_RXCSUM_IPPCSE;
1722 rxcsum &= ~E1000_RXCSUM_TUOFL;
1723 /* don't need to clear IPPCSE as it defaults to 0 */
1725 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1727 #endif /* CONFIG_E1000_MQ */
1729 if (hw->mac_type == e1000_82573)
1730 E1000_WRITE_REG(hw, ERT, 0x0100);
1732 /* Enable Receives */
1733 E1000_WRITE_REG(hw, RCTL, rctl);
1737 * e1000_free_tx_resources - Free Tx Resources per Queue
1738 * @adapter: board private structure
1739 * @tx_ring: Tx descriptor ring for a specific queue
1741 * Free all transmit software resources
1745 e1000_free_tx_resources(struct e1000_adapter *adapter,
1746 struct e1000_tx_ring *tx_ring)
1748 struct pci_dev *pdev = adapter->pdev;
1750 e1000_clean_tx_ring(adapter, tx_ring);
1752 vfree(tx_ring->buffer_info);
1753 tx_ring->buffer_info = NULL;
1755 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1757 tx_ring->desc = NULL;
1761 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1762 * @adapter: board private structure
1764 * Free all transmit software resources
1768 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1772 for (i = 0; i < adapter->num_queues; i++)
1773 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1777 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1778 struct e1000_buffer *buffer_info)
1780 if(buffer_info->dma) {
1781 pci_unmap_page(adapter->pdev,
1783 buffer_info->length,
1785 buffer_info->dma = 0;
1787 if(buffer_info->skb) {
1788 dev_kfree_skb_any(buffer_info->skb);
1789 buffer_info->skb = NULL;
1794 * e1000_clean_tx_ring - Free Tx Buffers
1795 * @adapter: board private structure
1796 * @tx_ring: ring to be cleaned
1800 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1801 struct e1000_tx_ring *tx_ring)
1803 struct e1000_buffer *buffer_info;
1807 /* Free all the Tx ring sk_buffs */
1809 if (likely(tx_ring->previous_buffer_info.skb != NULL)) {
1810 e1000_unmap_and_free_tx_resource(adapter,
1811 &tx_ring->previous_buffer_info);
1814 for(i = 0; i < tx_ring->count; i++) {
1815 buffer_info = &tx_ring->buffer_info[i];
1816 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1819 size = sizeof(struct e1000_buffer) * tx_ring->count;
1820 memset(tx_ring->buffer_info, 0, size);
1822 /* Zero out the descriptor ring */
1824 memset(tx_ring->desc, 0, tx_ring->size);
1826 tx_ring->next_to_use = 0;
1827 tx_ring->next_to_clean = 0;
1829 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1830 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1834 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1835 * @adapter: board private structure
1839 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1843 for (i = 0; i < adapter->num_queues; i++)
1844 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1848 * e1000_free_rx_resources - Free Rx Resources
1849 * @adapter: board private structure
1850 * @rx_ring: ring to clean the resources from
1852 * Free all receive software resources
1856 e1000_free_rx_resources(struct e1000_adapter *adapter,
1857 struct e1000_rx_ring *rx_ring)
1859 struct pci_dev *pdev = adapter->pdev;
1861 e1000_clean_rx_ring(adapter, rx_ring);
1863 vfree(rx_ring->buffer_info);
1864 rx_ring->buffer_info = NULL;
1865 kfree(rx_ring->ps_page);
1866 rx_ring->ps_page = NULL;
1867 kfree(rx_ring->ps_page_dma);
1868 rx_ring->ps_page_dma = NULL;
1870 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1872 rx_ring->desc = NULL;
1876 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1877 * @adapter: board private structure
1879 * Free all receive software resources
1883 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1887 for (i = 0; i < adapter->num_queues; i++)
1888 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1892 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1893 * @adapter: board private structure
1894 * @rx_ring: ring to free buffers from
1898 e1000_clean_rx_ring(struct e1000_adapter *adapter,
1899 struct e1000_rx_ring *rx_ring)
1901 struct e1000_buffer *buffer_info;
1902 struct e1000_ps_page *ps_page;
1903 struct e1000_ps_page_dma *ps_page_dma;
1904 struct pci_dev *pdev = adapter->pdev;
1908 /* Free all the Rx ring sk_buffs */
1910 for(i = 0; i < rx_ring->count; i++) {
1911 buffer_info = &rx_ring->buffer_info[i];
1912 if(buffer_info->skb) {
1913 ps_page = &rx_ring->ps_page[i];
1914 ps_page_dma = &rx_ring->ps_page_dma[i];
1915 pci_unmap_single(pdev,
1917 buffer_info->length,
1918 PCI_DMA_FROMDEVICE);
1920 dev_kfree_skb(buffer_info->skb);
1921 buffer_info->skb = NULL;
1923 for(j = 0; j < adapter->rx_ps_pages; j++) {
1924 if(!ps_page->ps_page[j]) break;
1925 pci_unmap_single(pdev,
1926 ps_page_dma->ps_page_dma[j],
1927 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1928 ps_page_dma->ps_page_dma[j] = 0;
1929 put_page(ps_page->ps_page[j]);
1930 ps_page->ps_page[j] = NULL;
1935 size = sizeof(struct e1000_buffer) * rx_ring->count;
1936 memset(rx_ring->buffer_info, 0, size);
1937 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1938 memset(rx_ring->ps_page, 0, size);
1939 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1940 memset(rx_ring->ps_page_dma, 0, size);
1942 /* Zero out the descriptor ring */
1944 memset(rx_ring->desc, 0, rx_ring->size);
1946 rx_ring->next_to_clean = 0;
1947 rx_ring->next_to_use = 0;
1949 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1950 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1954 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1955 * @adapter: board private structure
1959 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1963 for (i = 0; i < adapter->num_queues; i++)
1964 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1967 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1968 * and memory write and invalidate disabled for certain operations
1971 e1000_enter_82542_rst(struct e1000_adapter *adapter)
1973 struct net_device *netdev = adapter->netdev;
1976 e1000_pci_clear_mwi(&adapter->hw);
1978 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1979 rctl |= E1000_RCTL_RST;
1980 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1981 E1000_WRITE_FLUSH(&adapter->hw);
1984 if(netif_running(netdev))
1985 e1000_clean_all_rx_rings(adapter);
1989 e1000_leave_82542_rst(struct e1000_adapter *adapter)
1991 struct net_device *netdev = adapter->netdev;
1994 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1995 rctl &= ~E1000_RCTL_RST;
1996 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1997 E1000_WRITE_FLUSH(&adapter->hw);
2000 if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2001 e1000_pci_set_mwi(&adapter->hw);
2003 if(netif_running(netdev)) {
2004 e1000_configure_rx(adapter);
2005 e1000_alloc_rx_buffers(adapter, &adapter->rx_ring[0]);
2010 * e1000_set_mac - Change the Ethernet Address of the NIC
2011 * @netdev: network interface device structure
2012 * @p: pointer to an address structure
2014 * Returns 0 on success, negative on failure
2018 e1000_set_mac(struct net_device *netdev, void *p)
2020 struct e1000_adapter *adapter = netdev_priv(netdev);
2021 struct sockaddr *addr = p;
2023 if(!is_valid_ether_addr(addr->sa_data))
2024 return -EADDRNOTAVAIL;
2026 /* 82542 2.0 needs to be in reset to write receive address registers */
2028 if(adapter->hw.mac_type == e1000_82542_rev2_0)
2029 e1000_enter_82542_rst(adapter);
2031 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2032 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2034 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2036 /* With 82571 controllers, LAA may be overwritten (with the default)
2037 * due to controller reset from the other port. */
2038 if (adapter->hw.mac_type == e1000_82571) {
2039 /* activate the work around */
2040 adapter->hw.laa_is_present = 1;
2042 /* Hold a copy of the LAA in RAR[14] This is done so that
2043 * between the time RAR[0] gets clobbered and the time it
2044 * gets fixed (in e1000_watchdog), the actual LAA is in one
2045 * of the RARs and no incoming packets directed to this port
2046 * are dropped. Eventaully the LAA will be in RAR[0] and
2048 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2049 E1000_RAR_ENTRIES - 1);
2052 if(adapter->hw.mac_type == e1000_82542_rev2_0)
2053 e1000_leave_82542_rst(adapter);
2059 * e1000_set_multi - Multicast and Promiscuous mode set
2060 * @netdev: network interface device structure
2062 * The set_multi entry point is called whenever the multicast address
2063 * list or the network interface flags are updated. This routine is
2064 * responsible for configuring the hardware for proper multicast,
2065 * promiscuous mode, and all-multi behavior.
2069 e1000_set_multi(struct net_device *netdev)
2071 struct e1000_adapter *adapter = netdev_priv(netdev);
2072 struct e1000_hw *hw = &adapter->hw;
2073 struct dev_mc_list *mc_ptr;
2075 uint32_t hash_value;
2076 int i, rar_entries = E1000_RAR_ENTRIES;
2078 /* reserve RAR[14] for LAA over-write work-around */
2079 if (adapter->hw.mac_type == e1000_82571)
2082 /* Check for Promiscuous and All Multicast modes */
2084 rctl = E1000_READ_REG(hw, RCTL);
2086 if(netdev->flags & IFF_PROMISC) {
2087 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2088 } else if(netdev->flags & IFF_ALLMULTI) {
2089 rctl |= E1000_RCTL_MPE;
2090 rctl &= ~E1000_RCTL_UPE;
2092 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2095 E1000_WRITE_REG(hw, RCTL, rctl);
2097 /* 82542 2.0 needs to be in reset to write receive address registers */
2099 if(hw->mac_type == e1000_82542_rev2_0)
2100 e1000_enter_82542_rst(adapter);
2102 /* load the first 14 multicast address into the exact filters 1-14
2103 * RAR 0 is used for the station MAC adddress
2104 * if there are not 14 addresses, go ahead and clear the filters
2105 * -- with 82571 controllers only 0-13 entries are filled here
2107 mc_ptr = netdev->mc_list;
2109 for(i = 1; i < rar_entries; i++) {
2111 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2112 mc_ptr = mc_ptr->next;
2114 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2115 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2119 /* clear the old settings from the multicast hash table */
2121 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2122 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2124 /* load any remaining addresses into the hash table */
2126 for(; mc_ptr; mc_ptr = mc_ptr->next) {
2127 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2128 e1000_mta_set(hw, hash_value);
2131 if(hw->mac_type == e1000_82542_rev2_0)
2132 e1000_leave_82542_rst(adapter);
2135 /* Need to wait a few seconds after link up to get diagnostic information from
2139 e1000_update_phy_info(unsigned long data)
2141 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2142 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2146 * e1000_82547_tx_fifo_stall - Timer Call-back
2147 * @data: pointer to adapter cast into an unsigned long
2151 e1000_82547_tx_fifo_stall(unsigned long data)
2153 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2154 struct net_device *netdev = adapter->netdev;
2157 if(atomic_read(&adapter->tx_fifo_stall)) {
2158 if((E1000_READ_REG(&adapter->hw, TDT) ==
2159 E1000_READ_REG(&adapter->hw, TDH)) &&
2160 (E1000_READ_REG(&adapter->hw, TDFT) ==
2161 E1000_READ_REG(&adapter->hw, TDFH)) &&
2162 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2163 E1000_READ_REG(&adapter->hw, TDFHS))) {
2164 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2165 E1000_WRITE_REG(&adapter->hw, TCTL,
2166 tctl & ~E1000_TCTL_EN);
2167 E1000_WRITE_REG(&adapter->hw, TDFT,
2168 adapter->tx_head_addr);
2169 E1000_WRITE_REG(&adapter->hw, TDFH,
2170 adapter->tx_head_addr);
2171 E1000_WRITE_REG(&adapter->hw, TDFTS,
2172 adapter->tx_head_addr);
2173 E1000_WRITE_REG(&adapter->hw, TDFHS,
2174 adapter->tx_head_addr);
2175 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2176 E1000_WRITE_FLUSH(&adapter->hw);
2178 adapter->tx_fifo_head = 0;
2179 atomic_set(&adapter->tx_fifo_stall, 0);
2180 netif_wake_queue(netdev);
2182 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2188 * e1000_watchdog - Timer Call-back
2189 * @data: pointer to adapter cast into an unsigned long
2192 e1000_watchdog(unsigned long data)
2194 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2196 /* Do the rest outside of interrupt context */
2197 schedule_work(&adapter->watchdog_task);
2201 e1000_watchdog_task(struct e1000_adapter *adapter)
2203 struct net_device *netdev = adapter->netdev;
2204 struct e1000_tx_ring *txdr = &adapter->tx_ring[0];
2207 e1000_check_for_link(&adapter->hw);
2208 if (adapter->hw.mac_type == e1000_82573) {
2209 e1000_enable_tx_pkt_filtering(&adapter->hw);
2210 if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2211 e1000_update_mng_vlan(adapter);
2214 if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2215 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2216 link = !adapter->hw.serdes_link_down;
2218 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2221 if(!netif_carrier_ok(netdev)) {
2222 e1000_get_speed_and_duplex(&adapter->hw,
2223 &adapter->link_speed,
2224 &adapter->link_duplex);
2226 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2227 adapter->link_speed,
2228 adapter->link_duplex == FULL_DUPLEX ?
2229 "Full Duplex" : "Half Duplex");
2231 netif_carrier_on(netdev);
2232 netif_wake_queue(netdev);
2233 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2234 adapter->smartspeed = 0;
2237 if(netif_carrier_ok(netdev)) {
2238 adapter->link_speed = 0;
2239 adapter->link_duplex = 0;
2240 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2241 netif_carrier_off(netdev);
2242 netif_stop_queue(netdev);
2243 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2246 e1000_smartspeed(adapter);
2249 e1000_update_stats(adapter);
2251 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2252 adapter->tpt_old = adapter->stats.tpt;
2253 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2254 adapter->colc_old = adapter->stats.colc;
2256 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2257 adapter->gorcl_old = adapter->stats.gorcl;
2258 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2259 adapter->gotcl_old = adapter->stats.gotcl;
2261 e1000_update_adaptive(&adapter->hw);
2263 if (adapter->num_queues == 1 && !netif_carrier_ok(netdev)) {
2264 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2265 /* We've lost link, so the controller stops DMA,
2266 * but we've got queued Tx work that's never going
2267 * to get done, so reset controller to flush Tx.
2268 * (Do the reset outside of interrupt context). */
2269 schedule_work(&adapter->tx_timeout_task);
2273 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2274 if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2275 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2276 * asymmetrical Tx or Rx gets ITR=8000; everyone
2277 * else is between 2000-8000. */
2278 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2279 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2280 adapter->gotcl - adapter->gorcl :
2281 adapter->gorcl - adapter->gotcl) / 10000;
2282 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2283 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2286 /* Cause software interrupt to ensure rx ring is cleaned */
2287 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2289 /* Force detection of hung controller every watchdog period */
2290 adapter->detect_tx_hung = TRUE;
2292 /* With 82571 controllers, LAA may be overwritten due to controller
2293 * reset from the other port. Set the appropriate LAA in RAR[0] */
2294 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2295 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2297 /* Reset the timer */
2298 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2301 #define E1000_TX_FLAGS_CSUM 0x00000001
2302 #define E1000_TX_FLAGS_VLAN 0x00000002
2303 #define E1000_TX_FLAGS_TSO 0x00000004
2304 #define E1000_TX_FLAGS_IPV4 0x00000008
2305 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2306 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2309 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2310 struct sk_buff *skb)
2313 struct e1000_context_desc *context_desc;
2315 uint32_t cmd_length = 0;
2316 uint16_t ipcse = 0, tucse, mss;
2317 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2320 if(skb_shinfo(skb)->tso_size) {
2321 if (skb_header_cloned(skb)) {
2322 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2327 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2328 mss = skb_shinfo(skb)->tso_size;
2329 if(skb->protocol == ntohs(ETH_P_IP)) {
2330 skb->nh.iph->tot_len = 0;
2331 skb->nh.iph->check = 0;
2333 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2338 cmd_length = E1000_TXD_CMD_IP;
2339 ipcse = skb->h.raw - skb->data - 1;
2340 #ifdef NETIF_F_TSO_IPV6
2341 } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
2342 skb->nh.ipv6h->payload_len = 0;
2344 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2345 &skb->nh.ipv6h->daddr,
2352 ipcss = skb->nh.raw - skb->data;
2353 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2354 tucss = skb->h.raw - skb->data;
2355 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2358 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2359 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2361 i = tx_ring->next_to_use;
2362 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2364 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2365 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2366 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2367 context_desc->upper_setup.tcp_fields.tucss = tucss;
2368 context_desc->upper_setup.tcp_fields.tucso = tucso;
2369 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2370 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2371 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2372 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2374 if (++i == tx_ring->count) i = 0;
2375 tx_ring->next_to_use = i;
2384 static inline boolean_t
2385 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2386 struct sk_buff *skb)
2388 struct e1000_context_desc *context_desc;
2392 if(likely(skb->ip_summed == CHECKSUM_HW)) {
2393 css = skb->h.raw - skb->data;
2395 i = tx_ring->next_to_use;
2396 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2398 context_desc->upper_setup.tcp_fields.tucss = css;
2399 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2400 context_desc->upper_setup.tcp_fields.tucse = 0;
2401 context_desc->tcp_seg_setup.data = 0;
2402 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2404 if (unlikely(++i == tx_ring->count)) i = 0;
2405 tx_ring->next_to_use = i;
2413 #define E1000_MAX_TXD_PWR 12
2414 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2417 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2418 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2419 unsigned int nr_frags, unsigned int mss)
2421 struct e1000_buffer *buffer_info;
2422 unsigned int len = skb->len;
2423 unsigned int offset = 0, size, count = 0, i;
2425 len -= skb->data_len;
2427 i = tx_ring->next_to_use;
2430 buffer_info = &tx_ring->buffer_info[i];
2431 size = min(len, max_per_txd);
2433 /* Workaround for premature desc write-backs
2434 * in TSO mode. Append 4-byte sentinel desc */
2435 if(unlikely(mss && !nr_frags && size == len && size > 8))
2438 /* work-around for errata 10 and it applies
2439 * to all controllers in PCI-X mode
2440 * The fix is to make sure that the first descriptor of a
2441 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2443 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2444 (size > 2015) && count == 0))
2447 /* Workaround for potential 82544 hang in PCI-X. Avoid
2448 * terminating buffers within evenly-aligned dwords. */
2449 if(unlikely(adapter->pcix_82544 &&
2450 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2454 buffer_info->length = size;
2456 pci_map_single(adapter->pdev,
2460 buffer_info->time_stamp = jiffies;
2465 if(unlikely(++i == tx_ring->count)) i = 0;
2468 for(f = 0; f < nr_frags; f++) {
2469 struct skb_frag_struct *frag;
2471 frag = &skb_shinfo(skb)->frags[f];
2473 offset = frag->page_offset;
2476 buffer_info = &tx_ring->buffer_info[i];
2477 size = min(len, max_per_txd);
2479 /* Workaround for premature desc write-backs
2480 * in TSO mode. Append 4-byte sentinel desc */
2481 if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2484 /* Workaround for potential 82544 hang in PCI-X.
2485 * Avoid terminating buffers within evenly-aligned
2487 if(unlikely(adapter->pcix_82544 &&
2488 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2492 buffer_info->length = size;
2494 pci_map_page(adapter->pdev,
2499 buffer_info->time_stamp = jiffies;
2504 if(unlikely(++i == tx_ring->count)) i = 0;
2508 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2509 tx_ring->buffer_info[i].skb = skb;
2510 tx_ring->buffer_info[first].next_to_watch = i;
2516 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2517 int tx_flags, int count)
2519 struct e1000_tx_desc *tx_desc = NULL;
2520 struct e1000_buffer *buffer_info;
2521 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2524 if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2525 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2527 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2529 if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
2530 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2533 if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2534 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2535 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2538 if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2539 txd_lower |= E1000_TXD_CMD_VLE;
2540 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2543 i = tx_ring->next_to_use;
2546 buffer_info = &tx_ring->buffer_info[i];
2547 tx_desc = E1000_TX_DESC(*tx_ring, i);
2548 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2549 tx_desc->lower.data =
2550 cpu_to_le32(txd_lower | buffer_info->length);
2551 tx_desc->upper.data = cpu_to_le32(txd_upper);
2552 if(unlikely(++i == tx_ring->count)) i = 0;
2555 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2557 /* Force memory writes to complete before letting h/w
2558 * know there are new descriptors to fetch. (Only
2559 * applicable for weak-ordered memory model archs,
2560 * such as IA-64). */
2563 tx_ring->next_to_use = i;
2564 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2568 * 82547 workaround to avoid controller hang in half-duplex environment.
2569 * The workaround is to avoid queuing a large packet that would span
2570 * the internal Tx FIFO ring boundary by notifying the stack to resend
2571 * the packet at a later time. This gives the Tx FIFO an opportunity to
2572 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2573 * to the beginning of the Tx FIFO.
2576 #define E1000_FIFO_HDR 0x10
2577 #define E1000_82547_PAD_LEN 0x3E0
2580 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2582 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2583 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2585 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2587 if(adapter->link_duplex != HALF_DUPLEX)
2588 goto no_fifo_stall_required;
2590 if(atomic_read(&adapter->tx_fifo_stall))
2593 if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2594 atomic_set(&adapter->tx_fifo_stall, 1);
2598 no_fifo_stall_required:
2599 adapter->tx_fifo_head += skb_fifo_len;
2600 if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
2601 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2605 #define MINIMUM_DHCP_PACKET_SIZE 282
2607 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2609 struct e1000_hw *hw = &adapter->hw;
2610 uint16_t length, offset;
2611 if(vlan_tx_tag_present(skb)) {
2612 if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2613 ( adapter->hw.mng_cookie.status &
2614 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2617 if(htons(ETH_P_IP) == skb->protocol) {
2618 const struct iphdr *ip = skb->nh.iph;
2619 if(IPPROTO_UDP == ip->protocol) {
2620 struct udphdr *udp = (struct udphdr *)(skb->h.uh);
2621 if(ntohs(udp->dest) == 67) {
2622 offset = (uint8_t *)udp + 8 - skb->data;
2623 length = skb->len - offset;
2625 return e1000_mng_write_dhcp_info(hw,
2626 (uint8_t *)udp + 8, length);
2629 } else if((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
2630 struct ethhdr *eth = (struct ethhdr *) skb->data;
2631 if((htons(ETH_P_IP) == eth->h_proto)) {
2632 const struct iphdr *ip =
2633 (struct iphdr *)((uint8_t *)skb->data+14);
2634 if(IPPROTO_UDP == ip->protocol) {
2635 struct udphdr *udp =
2636 (struct udphdr *)((uint8_t *)ip +
2638 if(ntohs(udp->dest) == 67) {
2639 offset = (uint8_t *)udp + 8 - skb->data;
2640 length = skb->len - offset;
2642 return e1000_mng_write_dhcp_info(hw,
2652 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2654 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2656 struct e1000_adapter *adapter = netdev_priv(netdev);
2657 struct e1000_tx_ring *tx_ring;
2658 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2659 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2660 unsigned int tx_flags = 0;
2661 unsigned int len = skb->len;
2662 unsigned long flags;
2663 unsigned int nr_frags = 0;
2664 unsigned int mss = 0;
2668 len -= skb->data_len;
2670 #ifdef CONFIG_E1000_MQ
2671 tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2673 tx_ring = adapter->tx_ring;
2676 if (unlikely(skb->len <= 0)) {
2677 dev_kfree_skb_any(skb);
2678 return NETDEV_TX_OK;
2682 mss = skb_shinfo(skb)->tso_size;
2683 /* The controller does a simple calculation to
2684 * make sure there is enough room in the FIFO before
2685 * initiating the DMA for each buffer. The calc is:
2686 * 4 = ceil(buffer len/mss). To make sure we don't
2687 * overrun the FIFO, adjust the max buffer len if mss
2690 max_per_txd = min(mss << 2, max_per_txd);
2691 max_txd_pwr = fls(max_per_txd) - 1;
2694 if((mss) || (skb->ip_summed == CHECKSUM_HW))
2698 if(skb->ip_summed == CHECKSUM_HW)
2701 count += TXD_USE_COUNT(len, max_txd_pwr);
2703 if(adapter->pcix_82544)
2706 /* work-around for errata 10 and it applies to all controllers
2707 * in PCI-X mode, so add one more descriptor to the count
2709 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2713 nr_frags = skb_shinfo(skb)->nr_frags;
2714 for(f = 0; f < nr_frags; f++)
2715 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2717 if(adapter->pcix_82544)
2721 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2722 * points to just header, pull a few bytes of payload from
2723 * frags into skb->data */
2724 if (skb_shinfo(skb)->tso_size) {
2726 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2727 if (skb->data_len && (hdr_len < (skb->len - skb->data_len)) &&
2728 (adapter->hw.mac_type == e1000_82571 ||
2729 adapter->hw.mac_type == e1000_82572)) {
2730 unsigned int pull_size;
2731 pull_size = min((unsigned int)4, skb->data_len);
2732 if (!__pskb_pull_tail(skb, pull_size)) {
2733 printk(KERN_ERR "__pskb_pull_tail failed.\n");
2734 dev_kfree_skb_any(skb);
2741 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2742 e1000_transfer_dhcp_info(adapter, skb);
2744 local_irq_save(flags);
2745 if (!spin_trylock(&tx_ring->tx_lock)) {
2746 /* Collision - tell upper layer to requeue */
2747 local_irq_restore(flags);
2748 return NETDEV_TX_LOCKED;
2751 /* need: count + 2 desc gap to keep tail from touching
2752 * head, otherwise try next time */
2753 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2754 netif_stop_queue(netdev);
2755 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2756 return NETDEV_TX_BUSY;
2759 if(unlikely(adapter->hw.mac_type == e1000_82547)) {
2760 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2761 netif_stop_queue(netdev);
2762 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2763 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2764 return NETDEV_TX_BUSY;
2768 if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2769 tx_flags |= E1000_TX_FLAGS_VLAN;
2770 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2773 first = tx_ring->next_to_use;
2775 tso = e1000_tso(adapter, tx_ring, skb);
2777 dev_kfree_skb_any(skb);
2778 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2779 return NETDEV_TX_OK;
2783 tx_flags |= E1000_TX_FLAGS_TSO;
2784 else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
2785 tx_flags |= E1000_TX_FLAGS_CSUM;
2787 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2788 * 82571 hardware supports TSO capabilities for IPv6 as well...
2789 * no longer assume, we must. */
2790 if (likely(skb->protocol == ntohs(ETH_P_IP)))
2791 tx_flags |= E1000_TX_FLAGS_IPV4;
2793 e1000_tx_queue(adapter, tx_ring, tx_flags,
2794 e1000_tx_map(adapter, tx_ring, skb, first,
2795 max_per_txd, nr_frags, mss));
2797 netdev->trans_start = jiffies;
2799 /* Make sure there is space in the ring for the next send. */
2800 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
2801 netif_stop_queue(netdev);
2803 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2804 return NETDEV_TX_OK;
2808 * e1000_tx_timeout - Respond to a Tx Hang
2809 * @netdev: network interface device structure
2813 e1000_tx_timeout(struct net_device *netdev)
2815 struct e1000_adapter *adapter = netdev_priv(netdev);
2817 /* Do the reset outside of interrupt context */
2818 schedule_work(&adapter->tx_timeout_task);
2822 e1000_tx_timeout_task(struct net_device *netdev)
2824 struct e1000_adapter *adapter = netdev_priv(netdev);
2826 e1000_down(adapter);
2831 * e1000_get_stats - Get System Network Statistics
2832 * @netdev: network interface device structure
2834 * Returns the address of the device statistics structure.
2835 * The statistics are actually updated from the timer callback.
2838 static struct net_device_stats *
2839 e1000_get_stats(struct net_device *netdev)
2841 struct e1000_adapter *adapter = netdev_priv(netdev);
2843 e1000_update_stats(adapter);
2844 return &adapter->net_stats;
2848 * e1000_change_mtu - Change the Maximum Transfer Unit
2849 * @netdev: network interface device structure
2850 * @new_mtu: new value for maximum frame size
2852 * Returns 0 on success, negative on failure
2856 e1000_change_mtu(struct net_device *netdev, int new_mtu)
2858 struct e1000_adapter *adapter = netdev_priv(netdev);
2859 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2861 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2862 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2863 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2867 #define MAX_STD_JUMBO_FRAME_SIZE 9234
2868 /* might want this to be bigger enum check... */
2869 /* 82571 controllers limit jumbo frame size to 10500 bytes */
2870 if ((adapter->hw.mac_type == e1000_82571 ||
2871 adapter->hw.mac_type == e1000_82572) &&
2872 max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
2873 DPRINTK(PROBE, ERR, "MTU > 9216 bytes not supported "
2874 "on 82571 and 82572 controllers.\n");
2878 if(adapter->hw.mac_type == e1000_82573 &&
2879 max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2880 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2885 if(adapter->hw.mac_type > e1000_82547_rev_2) {
2886 adapter->rx_buffer_len = max_frame;
2887 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
2889 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
2890 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
2891 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2896 if(max_frame <= E1000_RXBUFFER_2048) {
2897 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
2898 } else if(max_frame <= E1000_RXBUFFER_4096) {
2899 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
2900 } else if(max_frame <= E1000_RXBUFFER_8192) {
2901 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
2902 } else if(max_frame <= E1000_RXBUFFER_16384) {
2903 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
2908 netdev->mtu = new_mtu;
2910 if(netif_running(netdev)) {
2911 e1000_down(adapter);
2915 adapter->hw.max_frame_size = max_frame;
2921 * e1000_update_stats - Update the board statistics counters
2922 * @adapter: board private structure
2926 e1000_update_stats(struct e1000_adapter *adapter)
2928 struct e1000_hw *hw = &adapter->hw;
2929 unsigned long flags;
2932 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2934 spin_lock_irqsave(&adapter->stats_lock, flags);
2936 /* these counters are modified from e1000_adjust_tbi_stats,
2937 * called from the interrupt context, so they must only
2938 * be written while holding adapter->stats_lock
2941 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
2942 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
2943 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
2944 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
2945 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
2946 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
2947 adapter->stats.roc += E1000_READ_REG(hw, ROC);
2948 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
2949 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
2950 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
2951 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
2952 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
2953 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
2955 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
2956 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
2957 adapter->stats.scc += E1000_READ_REG(hw, SCC);
2958 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
2959 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
2960 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
2961 adapter->stats.dc += E1000_READ_REG(hw, DC);
2962 adapter->stats.sec += E1000_READ_REG(hw, SEC);
2963 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
2964 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
2965 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
2966 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
2967 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
2968 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
2969 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
2970 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
2971 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
2972 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
2973 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
2974 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
2975 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
2976 adapter->stats.torl += E1000_READ_REG(hw, TORL);
2977 adapter->stats.torh += E1000_READ_REG(hw, TORH);
2978 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
2979 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
2980 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
2981 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
2982 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
2983 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
2984 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
2985 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
2986 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
2987 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
2988 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
2990 /* used for adaptive IFS */
2992 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
2993 adapter->stats.tpt += hw->tx_packet_delta;
2994 hw->collision_delta = E1000_READ_REG(hw, COLC);
2995 adapter->stats.colc += hw->collision_delta;
2997 if(hw->mac_type >= e1000_82543) {
2998 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
2999 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3000 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3001 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3002 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3003 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3005 if(hw->mac_type > e1000_82547_rev_2) {
3006 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3007 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3008 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3009 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3010 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3011 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3012 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3013 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3014 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3017 /* Fill out the OS statistics structure */
3019 adapter->net_stats.rx_packets = adapter->stats.gprc;
3020 adapter->net_stats.tx_packets = adapter->stats.gptc;
3021 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3022 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3023 adapter->net_stats.multicast = adapter->stats.mprc;
3024 adapter->net_stats.collisions = adapter->stats.colc;
3028 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3029 adapter->stats.crcerrs + adapter->stats.algnerrc +
3030 adapter->stats.rlec + adapter->stats.mpc +
3031 adapter->stats.cexterr;
3032 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3033 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3034 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3035 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
3036 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3040 adapter->net_stats.tx_errors = adapter->stats.ecol +
3041 adapter->stats.latecol;
3042 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3043 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3044 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3046 /* Tx Dropped needs to be maintained elsewhere */
3050 if(hw->media_type == e1000_media_type_copper) {
3051 if((adapter->link_speed == SPEED_1000) &&
3052 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3053 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3054 adapter->phy_stats.idle_errors += phy_tmp;
3057 if((hw->mac_type <= e1000_82546) &&
3058 (hw->phy_type == e1000_phy_m88) &&
3059 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3060 adapter->phy_stats.receive_errors += phy_tmp;
3063 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3066 #ifdef CONFIG_E1000_MQ
3068 e1000_rx_schedule(void *data)
3070 struct net_device *poll_dev, *netdev = data;
3071 struct e1000_adapter *adapter = netdev->priv;
3072 int this_cpu = get_cpu();
3074 poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
3075 if (poll_dev == NULL) {
3080 if (likely(netif_rx_schedule_prep(poll_dev)))
3081 __netif_rx_schedule(poll_dev);
3083 e1000_irq_enable(adapter);
3090 * e1000_intr - Interrupt Handler
3091 * @irq: interrupt number
3092 * @data: pointer to a network interface device structure
3093 * @pt_regs: CPU registers structure
3097 e1000_intr(int irq, void *data, struct pt_regs *regs)
3099 struct net_device *netdev = data;
3100 struct e1000_adapter *adapter = netdev_priv(netdev);
3101 struct e1000_hw *hw = &adapter->hw;
3102 uint32_t icr = E1000_READ_REG(hw, ICR);
3103 #ifdef CONFIG_E1000_MQ
3108 return IRQ_NONE; /* Not our interrupt */
3110 if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3111 hw->get_link_status = 1;
3112 mod_timer(&adapter->watchdog_timer, jiffies);
3115 #ifdef CONFIG_E1000_NAPI
3116 atomic_inc(&adapter->irq_sem);
3117 E1000_WRITE_REG(hw, IMC, ~0);
3118 E1000_WRITE_FLUSH(hw);
3119 #ifdef CONFIG_E1000_MQ
3120 if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
3121 cpu_set(adapter->cpu_for_queue[0],
3122 adapter->rx_sched_call_data.cpumask);
3123 for (i = 1; i < adapter->num_queues; i++) {
3124 cpu_set(adapter->cpu_for_queue[i],
3125 adapter->rx_sched_call_data.cpumask);
3126 atomic_inc(&adapter->irq_sem);
3128 atomic_set(&adapter->rx_sched_call_data.count, i);
3129 smp_call_async_mask(&adapter->rx_sched_call_data);
3131 printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
3133 #else /* if !CONFIG_E1000_MQ */
3134 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3135 __netif_rx_schedule(&adapter->polling_netdev[0]);
3137 e1000_irq_enable(adapter);
3138 #endif /* CONFIG_E1000_MQ */
3140 #else /* if !CONFIG_E1000_NAPI */
3141 /* Writing IMC and IMS is needed for 82547.
3142 Due to Hub Link bus being occupied, an interrupt
3143 de-assertion message is not able to be sent.
3144 When an interrupt assertion message is generated later,
3145 two messages are re-ordered and sent out.
3146 That causes APIC to think 82547 is in de-assertion
3147 state, while 82547 is in assertion state, resulting
3148 in dead lock. Writing IMC forces 82547 into
3151 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
3152 atomic_inc(&adapter->irq_sem);
3153 E1000_WRITE_REG(hw, IMC, ~0);
3156 for(i = 0; i < E1000_MAX_INTR; i++)
3157 if(unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3158 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3161 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3162 e1000_irq_enable(adapter);
3164 #endif /* CONFIG_E1000_NAPI */
3169 #ifdef CONFIG_E1000_NAPI
3171 * e1000_clean - NAPI Rx polling callback
3172 * @adapter: board private structure
3176 e1000_clean(struct net_device *poll_dev, int *budget)
3178 struct e1000_adapter *adapter;
3179 int work_to_do = min(*budget, poll_dev->quota);
3180 int tx_cleaned, i = 0, work_done = 0;
3182 /* Must NOT use netdev_priv macro here. */
3183 adapter = poll_dev->priv;
3185 /* Keep link state information with original netdev */
3186 if (!netif_carrier_ok(adapter->netdev))
3189 while (poll_dev != &adapter->polling_netdev[i]) {
3191 if (unlikely(i == adapter->num_queues))
3195 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3196 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3197 &work_done, work_to_do);
3199 *budget -= work_done;
3200 poll_dev->quota -= work_done;
3202 /* If no Tx and not enough Rx work done, exit the polling mode */
3203 if((!tx_cleaned && (work_done == 0)) ||
3204 !netif_running(adapter->netdev)) {
3206 netif_rx_complete(poll_dev);
3207 e1000_irq_enable(adapter);
3216 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3217 * @adapter: board private structure
3221 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3222 struct e1000_tx_ring *tx_ring)
3224 struct net_device *netdev = adapter->netdev;
3225 struct e1000_tx_desc *tx_desc, *eop_desc;
3226 struct e1000_buffer *buffer_info;
3227 unsigned int i, eop;
3228 boolean_t cleaned = FALSE;
3230 i = tx_ring->next_to_clean;
3231 eop = tx_ring->buffer_info[i].next_to_watch;
3232 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3234 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3235 /* Premature writeback of Tx descriptors clear (free buffers
3236 * and unmap pci_mapping) previous_buffer_info */
3237 if (likely(tx_ring->previous_buffer_info.skb != NULL)) {
3238 e1000_unmap_and_free_tx_resource(adapter,
3239 &tx_ring->previous_buffer_info);
3242 for(cleaned = FALSE; !cleaned; ) {
3243 tx_desc = E1000_TX_DESC(*tx_ring, i);
3244 buffer_info = &tx_ring->buffer_info[i];
3245 cleaned = (i == eop);
3248 if (!(netdev->features & NETIF_F_TSO)) {
3250 e1000_unmap_and_free_tx_resource(adapter,
3255 memcpy(&tx_ring->previous_buffer_info,
3257 sizeof(struct e1000_buffer));
3258 memset(buffer_info, 0,
3259 sizeof(struct e1000_buffer));
3261 e1000_unmap_and_free_tx_resource(
3262 adapter, buffer_info);
3267 tx_desc->buffer_addr = 0;
3268 tx_desc->lower.data = 0;
3269 tx_desc->upper.data = 0;
3271 if(unlikely(++i == tx_ring->count)) i = 0;
3276 eop = tx_ring->buffer_info[i].next_to_watch;
3277 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3280 tx_ring->next_to_clean = i;
3282 spin_lock(&tx_ring->tx_lock);
3284 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
3285 netif_carrier_ok(netdev)))
3286 netif_wake_queue(netdev);
3288 spin_unlock(&tx_ring->tx_lock);
3290 if (adapter->detect_tx_hung) {
3291 /* Detect a transmit hang in hardware, this serializes the
3292 * check with the clearing of time_stamp and movement of i */
3293 adapter->detect_tx_hung = FALSE;
3294 if (tx_ring->buffer_info[i].dma &&
3295 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
3296 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3297 E1000_STATUS_TXOFF)) {
3299 /* detected Tx unit hang */
3300 i = tx_ring->next_to_clean;
3301 eop = tx_ring->buffer_info[i].next_to_watch;
3302 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3303 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3306 " next_to_use <%x>\n"
3307 " next_to_clean <%x>\n"
3308 "buffer_info[next_to_clean]\n"
3310 " time_stamp <%lx>\n"
3311 " next_to_watch <%x>\n"
3313 " next_to_watch.status <%x>\n",
3314 readl(adapter->hw.hw_addr + tx_ring->tdh),
3315 readl(adapter->hw.hw_addr + tx_ring->tdt),
3316 tx_ring->next_to_use,
3318 (unsigned long long)tx_ring->buffer_info[i].dma,
3319 tx_ring->buffer_info[i].time_stamp,
3322 eop_desc->upper.fields.status);
3323 netif_stop_queue(netdev);
3327 if (unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3328 time_after(jiffies, tx_ring->previous_buffer_info.time_stamp + HZ)))
3329 e1000_unmap_and_free_tx_resource(
3330 adapter, &tx_ring->previous_buffer_info);
3336 * e1000_rx_checksum - Receive Checksum Offload for 82543
3337 * @adapter: board private structure
3338 * @status_err: receive descriptor status and error fields
3339 * @csum: receive descriptor csum field
3340 * @sk_buff: socket buffer with received data
3344 e1000_rx_checksum(struct e1000_adapter *adapter,
3345 uint32_t status_err, uint32_t csum,
3346 struct sk_buff *skb)
3348 uint16_t status = (uint16_t)status_err;
3349 uint8_t errors = (uint8_t)(status_err >> 24);
3350 skb->ip_summed = CHECKSUM_NONE;
3352 /* 82543 or newer only */
3353 if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
3354 /* Ignore Checksum bit is set */
3355 if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
3356 /* TCP/UDP checksum error bit is set */
3357 if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
3358 /* let the stack verify checksum errors */
3359 adapter->hw_csum_err++;
3362 /* TCP/UDP Checksum has not been calculated */
3363 if(adapter->hw.mac_type <= e1000_82547_rev_2) {
3364 if(!(status & E1000_RXD_STAT_TCPCS))
3367 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3370 /* It must be a TCP or UDP packet with a valid checksum */
3371 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3372 /* TCP checksum is good */
3373 skb->ip_summed = CHECKSUM_UNNECESSARY;
3374 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3375 /* IP fragment with UDP payload */
3376 /* Hardware complements the payload checksum, so we undo it
3377 * and then put the value in host order for further stack use.
3379 csum = ntohl(csum ^ 0xFFFF);
3381 skb->ip_summed = CHECKSUM_HW;
3383 adapter->hw_csum_good++;
3387 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3388 * @adapter: board private structure
3392 #ifdef CONFIG_E1000_NAPI
3393 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3394 struct e1000_rx_ring *rx_ring,
3395 int *work_done, int work_to_do)
3397 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3398 struct e1000_rx_ring *rx_ring)
3401 struct net_device *netdev = adapter->netdev;
3402 struct pci_dev *pdev = adapter->pdev;
3403 struct e1000_rx_desc *rx_desc;
3404 struct e1000_buffer *buffer_info;
3405 struct sk_buff *skb;
3406 unsigned long flags;
3410 boolean_t cleaned = FALSE;
3412 i = rx_ring->next_to_clean;
3413 rx_desc = E1000_RX_DESC(*rx_ring, i);
3415 while(rx_desc->status & E1000_RXD_STAT_DD) {
3416 buffer_info = &rx_ring->buffer_info[i];
3417 #ifdef CONFIG_E1000_NAPI
3418 if(*work_done >= work_to_do)
3424 pci_unmap_single(pdev,
3426 buffer_info->length,
3427 PCI_DMA_FROMDEVICE);
3429 skb = buffer_info->skb;
3430 length = le16_to_cpu(rx_desc->length);
3432 if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
3433 /* All receives must fit into a single buffer */
3434 E1000_DBG("%s: Receive packet consumed multiple"
3435 " buffers\n", netdev->name);
3436 dev_kfree_skb_irq(skb);
3440 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3441 last_byte = *(skb->data + length - 1);
3442 if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
3443 rx_desc->errors, length, last_byte)) {
3444 spin_lock_irqsave(&adapter->stats_lock, flags);
3445 e1000_tbi_adjust_stats(&adapter->hw,
3448 spin_unlock_irqrestore(&adapter->stats_lock,
3452 dev_kfree_skb_irq(skb);
3458 skb_put(skb, length - ETHERNET_FCS_SIZE);
3460 /* Receive Checksum Offload */
3461 e1000_rx_checksum(adapter,
3462 (uint32_t)(rx_desc->status) |
3463 ((uint32_t)(rx_desc->errors) << 24),
3464 rx_desc->csum, skb);
3465 skb->protocol = eth_type_trans(skb, netdev);
3466 #ifdef CONFIG_E1000_NAPI
3467 if(unlikely(adapter->vlgrp &&
3468 (rx_desc->status & E1000_RXD_STAT_VP))) {
3469 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3470 le16_to_cpu(rx_desc->special) &
3471 E1000_RXD_SPC_VLAN_MASK);
3473 netif_receive_skb(skb);
3475 #else /* CONFIG_E1000_NAPI */
3476 if(unlikely(adapter->vlgrp &&
3477 (rx_desc->status & E1000_RXD_STAT_VP))) {
3478 vlan_hwaccel_rx(skb, adapter->vlgrp,
3479 le16_to_cpu(rx_desc->special) &
3480 E1000_RXD_SPC_VLAN_MASK);
3484 #endif /* CONFIG_E1000_NAPI */
3485 netdev->last_rx = jiffies;
3489 rx_desc->status = 0;
3490 buffer_info->skb = NULL;
3491 if(unlikely(++i == rx_ring->count)) i = 0;
3493 rx_desc = E1000_RX_DESC(*rx_ring, i);
3495 rx_ring->next_to_clean = i;
3496 adapter->alloc_rx_buf(adapter, rx_ring);
3502 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3503 * @adapter: board private structure
3507 #ifdef CONFIG_E1000_NAPI
3508 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3509 struct e1000_rx_ring *rx_ring,
3510 int *work_done, int work_to_do)
3512 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3513 struct e1000_rx_ring *rx_ring)
3516 union e1000_rx_desc_packet_split *rx_desc;
3517 struct net_device *netdev = adapter->netdev;
3518 struct pci_dev *pdev = adapter->pdev;
3519 struct e1000_buffer *buffer_info;
3520 struct e1000_ps_page *ps_page;
3521 struct e1000_ps_page_dma *ps_page_dma;
3522 struct sk_buff *skb;
3524 uint32_t length, staterr;
3525 boolean_t cleaned = FALSE;
3527 i = rx_ring->next_to_clean;
3528 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3529 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3531 while(staterr & E1000_RXD_STAT_DD) {
3532 buffer_info = &rx_ring->buffer_info[i];
3533 ps_page = &rx_ring->ps_page[i];
3534 ps_page_dma = &rx_ring->ps_page_dma[i];
3535 #ifdef CONFIG_E1000_NAPI
3536 if(unlikely(*work_done >= work_to_do))
3541 pci_unmap_single(pdev, buffer_info->dma,
3542 buffer_info->length,
3543 PCI_DMA_FROMDEVICE);
3545 skb = buffer_info->skb;
3547 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3548 E1000_DBG("%s: Packet Split buffers didn't pick up"
3549 " the full packet\n", netdev->name);
3550 dev_kfree_skb_irq(skb);
3554 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3555 dev_kfree_skb_irq(skb);
3559 length = le16_to_cpu(rx_desc->wb.middle.length0);
3561 if(unlikely(!length)) {
3562 E1000_DBG("%s: Last part of the packet spanning"
3563 " multiple descriptors\n", netdev->name);
3564 dev_kfree_skb_irq(skb);
3569 skb_put(skb, length);
3571 for(j = 0; j < adapter->rx_ps_pages; j++) {
3572 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3575 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3576 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3577 ps_page_dma->ps_page_dma[j] = 0;
3578 skb_shinfo(skb)->frags[j].page =
3579 ps_page->ps_page[j];
3580 ps_page->ps_page[j] = NULL;
3581 skb_shinfo(skb)->frags[j].page_offset = 0;
3582 skb_shinfo(skb)->frags[j].size = length;
3583 skb_shinfo(skb)->nr_frags++;
3585 skb->data_len += length;
3588 e1000_rx_checksum(adapter, staterr,
3589 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3590 skb->protocol = eth_type_trans(skb, netdev);
3592 if(likely(rx_desc->wb.upper.header_status &
3593 E1000_RXDPS_HDRSTAT_HDRSP)) {
3594 adapter->rx_hdr_split++;
3595 #ifdef HAVE_RX_ZERO_COPY
3596 skb_shinfo(skb)->zero_copy = TRUE;
3599 #ifdef CONFIG_E1000_NAPI
3600 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3601 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3602 le16_to_cpu(rx_desc->wb.middle.vlan) &
3603 E1000_RXD_SPC_VLAN_MASK);
3605 netif_receive_skb(skb);
3607 #else /* CONFIG_E1000_NAPI */
3608 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3609 vlan_hwaccel_rx(skb, adapter->vlgrp,
3610 le16_to_cpu(rx_desc->wb.middle.vlan) &
3611 E1000_RXD_SPC_VLAN_MASK);
3615 #endif /* CONFIG_E1000_NAPI */
3616 netdev->last_rx = jiffies;
3620 rx_desc->wb.middle.status_error &= ~0xFF;
3621 buffer_info->skb = NULL;
3622 if(unlikely(++i == rx_ring->count)) i = 0;
3624 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3625 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3627 rx_ring->next_to_clean = i;
3628 adapter->alloc_rx_buf(adapter, rx_ring);
3634 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3635 * @adapter: address of board private structure
3639 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3640 struct e1000_rx_ring *rx_ring)
3642 struct net_device *netdev = adapter->netdev;
3643 struct pci_dev *pdev = adapter->pdev;
3644 struct e1000_rx_desc *rx_desc;
3645 struct e1000_buffer *buffer_info;
3646 struct sk_buff *skb;
3648 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3650 i = rx_ring->next_to_use;
3651 buffer_info = &rx_ring->buffer_info[i];
3653 while(!buffer_info->skb) {
3654 skb = dev_alloc_skb(bufsz);
3656 if(unlikely(!skb)) {
3657 /* Better luck next round */
3661 /* Fix for errata 23, can't cross 64kB boundary */
3662 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3663 struct sk_buff *oldskb = skb;
3664 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3665 "at %p\n", bufsz, skb->data);
3666 /* Try again, without freeing the previous */
3667 skb = dev_alloc_skb(bufsz);
3668 /* Failed allocation, critical failure */
3670 dev_kfree_skb(oldskb);
3674 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3677 dev_kfree_skb(oldskb);
3678 break; /* while !buffer_info->skb */
3680 /* Use new allocation */
3681 dev_kfree_skb(oldskb);
3684 /* Make buffer alignment 2 beyond a 16 byte boundary
3685 * this will result in a 16 byte aligned IP header after
3686 * the 14 byte MAC header is removed
3688 skb_reserve(skb, NET_IP_ALIGN);
3692 buffer_info->skb = skb;
3693 buffer_info->length = adapter->rx_buffer_len;
3694 buffer_info->dma = pci_map_single(pdev,
3696 adapter->rx_buffer_len,
3697 PCI_DMA_FROMDEVICE);
3699 /* Fix for errata 23, can't cross 64kB boundary */
3700 if (!e1000_check_64k_bound(adapter,
3701 (void *)(unsigned long)buffer_info->dma,
3702 adapter->rx_buffer_len)) {
3703 DPRINTK(RX_ERR, ERR,
3704 "dma align check failed: %u bytes at %p\n",
3705 adapter->rx_buffer_len,
3706 (void *)(unsigned long)buffer_info->dma);
3708 buffer_info->skb = NULL;
3710 pci_unmap_single(pdev, buffer_info->dma,
3711 adapter->rx_buffer_len,
3712 PCI_DMA_FROMDEVICE);
3714 break; /* while !buffer_info->skb */
3716 rx_desc = E1000_RX_DESC(*rx_ring, i);
3717 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3719 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3720 /* Force memory writes to complete before letting h/w
3721 * know there are new descriptors to fetch. (Only
3722 * applicable for weak-ordered memory model archs,
3723 * such as IA-64). */
3725 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3728 if(unlikely(++i == rx_ring->count)) i = 0;
3729 buffer_info = &rx_ring->buffer_info[i];
3732 rx_ring->next_to_use = i;
3736 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3737 * @adapter: address of board private structure
3741 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3742 struct e1000_rx_ring *rx_ring)
3744 struct net_device *netdev = adapter->netdev;
3745 struct pci_dev *pdev = adapter->pdev;
3746 union e1000_rx_desc_packet_split *rx_desc;
3747 struct e1000_buffer *buffer_info;
3748 struct e1000_ps_page *ps_page;
3749 struct e1000_ps_page_dma *ps_page_dma;
3750 struct sk_buff *skb;
3753 i = rx_ring->next_to_use;
3754 buffer_info = &rx_ring->buffer_info[i];
3755 ps_page = &rx_ring->ps_page[i];
3756 ps_page_dma = &rx_ring->ps_page_dma[i];
3758 while(!buffer_info->skb) {
3759 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3761 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3762 if (j < adapter->rx_ps_pages) {
3763 if (likely(!ps_page->ps_page[j])) {
3764 ps_page->ps_page[j] =
3765 alloc_page(GFP_ATOMIC);
3766 if (unlikely(!ps_page->ps_page[j]))
3768 ps_page_dma->ps_page_dma[j] =
3770 ps_page->ps_page[j],
3772 PCI_DMA_FROMDEVICE);
3774 /* Refresh the desc even if buffer_addrs didn't
3775 * change because each write-back erases
3778 rx_desc->read.buffer_addr[j+1] =
3779 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3781 rx_desc->read.buffer_addr[j+1] = ~0;
3784 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3789 /* Make buffer alignment 2 beyond a 16 byte boundary
3790 * this will result in a 16 byte aligned IP header after
3791 * the 14 byte MAC header is removed
3793 skb_reserve(skb, NET_IP_ALIGN);
3797 buffer_info->skb = skb;
3798 buffer_info->length = adapter->rx_ps_bsize0;
3799 buffer_info->dma = pci_map_single(pdev, skb->data,
3800 adapter->rx_ps_bsize0,
3801 PCI_DMA_FROMDEVICE);
3803 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
3805 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3806 /* Force memory writes to complete before letting h/w
3807 * know there are new descriptors to fetch. (Only
3808 * applicable for weak-ordered memory model archs,
3809 * such as IA-64). */
3811 /* Hardware increments by 16 bytes, but packet split
3812 * descriptors are 32 bytes...so we increment tail
3815 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
3818 if(unlikely(++i == rx_ring->count)) i = 0;
3819 buffer_info = &rx_ring->buffer_info[i];
3820 ps_page = &rx_ring->ps_page[i];
3821 ps_page_dma = &rx_ring->ps_page_dma[i];
3825 rx_ring->next_to_use = i;
3829 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3834 e1000_smartspeed(struct e1000_adapter *adapter)
3836 uint16_t phy_status;
3839 if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
3840 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
3843 if(adapter->smartspeed == 0) {
3844 /* If Master/Slave config fault is asserted twice,
3845 * we assume back-to-back */
3846 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3847 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3848 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3849 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3850 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3851 if(phy_ctrl & CR_1000T_MS_ENABLE) {
3852 phy_ctrl &= ~CR_1000T_MS_ENABLE;
3853 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
3855 adapter->smartspeed++;
3856 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3857 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
3859 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3860 MII_CR_RESTART_AUTO_NEG);
3861 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
3866 } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
3867 /* If still no link, perhaps using 2/3 pair cable */
3868 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3869 phy_ctrl |= CR_1000T_MS_ENABLE;
3870 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
3871 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3872 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
3873 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3874 MII_CR_RESTART_AUTO_NEG);
3875 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
3878 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3879 if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
3880 adapter->smartspeed = 0;
3891 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3897 return e1000_mii_ioctl(netdev, ifr, cmd);
3911 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3913 struct e1000_adapter *adapter = netdev_priv(netdev);
3914 struct mii_ioctl_data *data = if_mii(ifr);
3918 unsigned long flags;
3920 if(adapter->hw.media_type != e1000_media_type_copper)
3925 data->phy_id = adapter->hw.phy_addr;
3928 if(!capable(CAP_NET_ADMIN))
3930 spin_lock_irqsave(&adapter->stats_lock, flags);
3931 if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
3933 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3936 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3939 if(!capable(CAP_NET_ADMIN))
3941 if(data->reg_num & ~(0x1F))
3943 mii_reg = data->val_in;
3944 spin_lock_irqsave(&adapter->stats_lock, flags);
3945 if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
3947 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3950 if(adapter->hw.phy_type == e1000_phy_m88) {
3951 switch (data->reg_num) {
3953 if(mii_reg & MII_CR_POWER_DOWN)
3955 if(mii_reg & MII_CR_AUTO_NEG_EN) {
3956 adapter->hw.autoneg = 1;
3957 adapter->hw.autoneg_advertised = 0x2F;
3960 spddplx = SPEED_1000;
3961 else if (mii_reg & 0x2000)
3962 spddplx = SPEED_100;
3965 spddplx += (mii_reg & 0x100)
3968 retval = e1000_set_spd_dplx(adapter,
3971 spin_unlock_irqrestore(
3972 &adapter->stats_lock,
3977 if(netif_running(adapter->netdev)) {
3978 e1000_down(adapter);
3981 e1000_reset(adapter);
3983 case M88E1000_PHY_SPEC_CTRL:
3984 case M88E1000_EXT_PHY_SPEC_CTRL:
3985 if(e1000_phy_reset(&adapter->hw)) {
3986 spin_unlock_irqrestore(
3987 &adapter->stats_lock, flags);
3993 switch (data->reg_num) {
3995 if(mii_reg & MII_CR_POWER_DOWN)
3997 if(netif_running(adapter->netdev)) {
3998 e1000_down(adapter);
4001 e1000_reset(adapter);
4005 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4010 return E1000_SUCCESS;
4014 e1000_pci_set_mwi(struct e1000_hw *hw)
4016 struct e1000_adapter *adapter = hw->back;
4017 int ret_val = pci_set_mwi(adapter->pdev);
4020 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4024 e1000_pci_clear_mwi(struct e1000_hw *hw)
4026 struct e1000_adapter *adapter = hw->back;
4028 pci_clear_mwi(adapter->pdev);
4032 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4034 struct e1000_adapter *adapter = hw->back;
4036 pci_read_config_word(adapter->pdev, reg, value);
4040 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4042 struct e1000_adapter *adapter = hw->back;
4044 pci_write_config_word(adapter->pdev, reg, *value);
4048 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4054 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4060 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4062 struct e1000_adapter *adapter = netdev_priv(netdev);
4063 uint32_t ctrl, rctl;
4065 e1000_irq_disable(adapter);
4066 adapter->vlgrp = grp;
4069 /* enable VLAN tag insert/strip */
4070 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4071 ctrl |= E1000_CTRL_VME;
4072 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4074 /* enable VLAN receive filtering */
4075 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4076 rctl |= E1000_RCTL_VFE;
4077 rctl &= ~E1000_RCTL_CFIEN;
4078 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4079 e1000_update_mng_vlan(adapter);
4081 /* disable VLAN tag insert/strip */
4082 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4083 ctrl &= ~E1000_CTRL_VME;
4084 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4086 /* disable VLAN filtering */
4087 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4088 rctl &= ~E1000_RCTL_VFE;
4089 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4090 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4091 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4092 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4096 e1000_irq_enable(adapter);
4100 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4102 struct e1000_adapter *adapter = netdev_priv(netdev);
4103 uint32_t vfta, index;
4104 if((adapter->hw.mng_cookie.status &
4105 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4106 (vid == adapter->mng_vlan_id))
4108 /* add VID to filter table */
4109 index = (vid >> 5) & 0x7F;
4110 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4111 vfta |= (1 << (vid & 0x1F));
4112 e1000_write_vfta(&adapter->hw, index, vfta);
4116 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4118 struct e1000_adapter *adapter = netdev_priv(netdev);
4119 uint32_t vfta, index;
4121 e1000_irq_disable(adapter);
4124 adapter->vlgrp->vlan_devices[vid] = NULL;
4126 e1000_irq_enable(adapter);
4128 if((adapter->hw.mng_cookie.status &
4129 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4130 (vid == adapter->mng_vlan_id))
4132 /* remove VID from filter table */
4133 index = (vid >> 5) & 0x7F;
4134 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4135 vfta &= ~(1 << (vid & 0x1F));
4136 e1000_write_vfta(&adapter->hw, index, vfta);
4140 e1000_restore_vlan(struct e1000_adapter *adapter)
4142 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4144 if(adapter->vlgrp) {
4146 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4147 if(!adapter->vlgrp->vlan_devices[vid])
4149 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4155 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4157 adapter->hw.autoneg = 0;
4159 /* Fiber NICs only allow 1000 gbps Full duplex */
4160 if((adapter->hw.media_type == e1000_media_type_fiber) &&
4161 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4162 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4167 case SPEED_10 + DUPLEX_HALF:
4168 adapter->hw.forced_speed_duplex = e1000_10_half;
4170 case SPEED_10 + DUPLEX_FULL:
4171 adapter->hw.forced_speed_duplex = e1000_10_full;
4173 case SPEED_100 + DUPLEX_HALF:
4174 adapter->hw.forced_speed_duplex = e1000_100_half;
4176 case SPEED_100 + DUPLEX_FULL:
4177 adapter->hw.forced_speed_duplex = e1000_100_full;
4179 case SPEED_1000 + DUPLEX_FULL:
4180 adapter->hw.autoneg = 1;
4181 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4183 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4185 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4192 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4194 struct net_device *netdev = pci_get_drvdata(pdev);
4195 struct e1000_adapter *adapter = netdev_priv(netdev);
4196 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
4197 uint32_t wufc = adapter->wol;
4199 netif_device_detach(netdev);
4201 if(netif_running(netdev))
4202 e1000_down(adapter);
4204 status = E1000_READ_REG(&adapter->hw, STATUS);
4205 if(status & E1000_STATUS_LU)
4206 wufc &= ~E1000_WUFC_LNKC;
4209 e1000_setup_rctl(adapter);
4210 e1000_set_multi(netdev);
4212 /* turn on all-multi mode if wake on multicast is enabled */
4213 if(adapter->wol & E1000_WUFC_MC) {
4214 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4215 rctl |= E1000_RCTL_MPE;
4216 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4219 if(adapter->hw.mac_type >= e1000_82540) {
4220 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4221 /* advertise wake from D3Cold */
4222 #define E1000_CTRL_ADVD3WUC 0x00100000
4223 /* phy power management enable */
4224 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4225 ctrl |= E1000_CTRL_ADVD3WUC |
4226 E1000_CTRL_EN_PHY_PWR_MGMT;
4227 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4230 if(adapter->hw.media_type == e1000_media_type_fiber ||
4231 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4232 /* keep the laser running in D3 */
4233 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4234 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4235 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4238 /* Allow time for pending master requests to run */
4239 e1000_disable_pciex_master(&adapter->hw);
4241 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4242 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4243 pci_enable_wake(pdev, 3, 1);
4244 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
4246 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4247 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4248 pci_enable_wake(pdev, 3, 0);
4249 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
4252 pci_save_state(pdev);
4254 if(adapter->hw.mac_type >= e1000_82540 &&
4255 adapter->hw.media_type == e1000_media_type_copper) {
4256 manc = E1000_READ_REG(&adapter->hw, MANC);
4257 if(manc & E1000_MANC_SMBUS_EN) {
4258 manc |= E1000_MANC_ARP_EN;
4259 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4260 pci_enable_wake(pdev, 3, 1);
4261 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
4265 switch(adapter->hw.mac_type) {
4268 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4269 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
4270 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
4273 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4274 E1000_WRITE_REG(&adapter->hw, SWSM,
4275 swsm & ~E1000_SWSM_DRV_LOAD);
4281 pci_disable_device(pdev);
4282 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4289 e1000_resume(struct pci_dev *pdev)
4291 struct net_device *netdev = pci_get_drvdata(pdev);
4292 struct e1000_adapter *adapter = netdev_priv(netdev);
4293 uint32_t manc, ret_val, swsm;
4296 pci_set_power_state(pdev, PCI_D0);
4297 pci_restore_state(pdev);
4298 ret_val = pci_enable_device(pdev);
4299 pci_set_master(pdev);
4301 pci_enable_wake(pdev, PCI_D3hot, 0);
4302 pci_enable_wake(pdev, PCI_D3cold, 0);
4304 e1000_reset(adapter);
4305 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4307 if(netif_running(netdev))
4310 netif_device_attach(netdev);
4312 if(adapter->hw.mac_type >= e1000_82540 &&
4313 adapter->hw.media_type == e1000_media_type_copper) {
4314 manc = E1000_READ_REG(&adapter->hw, MANC);
4315 manc &= ~(E1000_MANC_ARP_EN);
4316 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4319 switch(adapter->hw.mac_type) {
4322 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4323 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
4324 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
4327 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4328 E1000_WRITE_REG(&adapter->hw, SWSM,
4329 swsm | E1000_SWSM_DRV_LOAD);
4338 #ifdef CONFIG_NET_POLL_CONTROLLER
4340 * Polling 'interrupt' - used by things like netconsole to send skbs
4341 * without having to re-enable interrupts. It's not called while
4342 * the interrupt routine is executing.
4345 e1000_netpoll(struct net_device *netdev)
4347 struct e1000_adapter *adapter = netdev_priv(netdev);
4348 disable_irq(adapter->pdev->irq);
4349 e1000_intr(adapter->pdev->irq, netdev, NULL);
4350 e1000_clean_tx_irq(adapter);
4351 enable_irq(adapter->pdev->irq);