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 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
41 #ifndef CONFIG_E1000_NAPI
44 #define DRIVERNAPI "-NAPI"
46 #define DRV_VERSION "6.3.9-k2"DRIVERNAPI
47 char e1000_driver_version[] = DRV_VERSION;
48 static 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(0x105E),
84 INTEL_E1000_ETHERNET_DEVICE(0x105F),
85 INTEL_E1000_ETHERNET_DEVICE(0x1060),
86 INTEL_E1000_ETHERNET_DEVICE(0x1075),
87 INTEL_E1000_ETHERNET_DEVICE(0x1076),
88 INTEL_E1000_ETHERNET_DEVICE(0x1077),
89 INTEL_E1000_ETHERNET_DEVICE(0x1078),
90 INTEL_E1000_ETHERNET_DEVICE(0x1079),
91 INTEL_E1000_ETHERNET_DEVICE(0x107A),
92 INTEL_E1000_ETHERNET_DEVICE(0x107B),
93 INTEL_E1000_ETHERNET_DEVICE(0x107C),
94 INTEL_E1000_ETHERNET_DEVICE(0x107D),
95 INTEL_E1000_ETHERNET_DEVICE(0x107E),
96 INTEL_E1000_ETHERNET_DEVICE(0x107F),
97 INTEL_E1000_ETHERNET_DEVICE(0x108A),
98 INTEL_E1000_ETHERNET_DEVICE(0x108B),
99 INTEL_E1000_ETHERNET_DEVICE(0x108C),
100 INTEL_E1000_ETHERNET_DEVICE(0x109A),
101 /* required last entry */
105 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
107 int e1000_up(struct e1000_adapter *adapter);
108 void e1000_down(struct e1000_adapter *adapter);
109 void e1000_reset(struct e1000_adapter *adapter);
110 int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
111 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
112 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
113 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
114 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
115 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
116 struct e1000_tx_ring *txdr);
117 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
118 struct e1000_rx_ring *rxdr);
119 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
120 struct e1000_tx_ring *tx_ring);
121 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
122 struct e1000_rx_ring *rx_ring);
123 void e1000_update_stats(struct e1000_adapter *adapter);
125 /* Local Function Prototypes */
127 static int e1000_init_module(void);
128 static void e1000_exit_module(void);
129 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
130 static void __devexit e1000_remove(struct pci_dev *pdev);
131 static int e1000_alloc_queues(struct e1000_adapter *adapter);
132 #ifdef CONFIG_E1000_MQ
133 static void e1000_setup_queue_mapping(struct e1000_adapter *adapter);
135 static int e1000_sw_init(struct e1000_adapter *adapter);
136 static int e1000_open(struct net_device *netdev);
137 static int e1000_close(struct net_device *netdev);
138 static void e1000_configure_tx(struct e1000_adapter *adapter);
139 static void e1000_configure_rx(struct e1000_adapter *adapter);
140 static void e1000_setup_rctl(struct e1000_adapter *adapter);
141 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
142 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
143 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
144 struct e1000_tx_ring *tx_ring);
145 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
146 struct e1000_rx_ring *rx_ring);
147 static void e1000_set_multi(struct net_device *netdev);
148 static void e1000_update_phy_info(unsigned long data);
149 static void e1000_watchdog(unsigned long data);
150 static void e1000_watchdog_task(struct e1000_adapter *adapter);
151 static void e1000_82547_tx_fifo_stall(unsigned long data);
152 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
153 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
154 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
155 static int e1000_set_mac(struct net_device *netdev, void *p);
156 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
157 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
158 struct e1000_tx_ring *tx_ring);
159 #ifdef CONFIG_E1000_NAPI
160 static int e1000_clean(struct net_device *poll_dev, int *budget);
161 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
162 struct e1000_rx_ring *rx_ring,
163 int *work_done, int work_to_do);
164 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
165 struct e1000_rx_ring *rx_ring,
166 int *work_done, int work_to_do);
168 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
169 struct e1000_rx_ring *rx_ring);
170 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
171 struct e1000_rx_ring *rx_ring);
173 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
174 struct e1000_rx_ring *rx_ring);
175 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
176 struct e1000_rx_ring *rx_ring);
177 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
178 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
180 void e1000_set_ethtool_ops(struct net_device *netdev);
181 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
182 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
183 static void e1000_tx_timeout(struct net_device *dev);
184 static void e1000_tx_timeout_task(struct net_device *dev);
185 static void e1000_smartspeed(struct e1000_adapter *adapter);
186 static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
187 struct sk_buff *skb);
189 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
190 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
191 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
192 static void e1000_restore_vlan(struct e1000_adapter *adapter);
195 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
196 static int e1000_resume(struct pci_dev *pdev);
199 #ifdef CONFIG_NET_POLL_CONTROLLER
200 /* for netdump / net console */
201 static void e1000_netpoll (struct net_device *netdev);
204 #ifdef CONFIG_E1000_MQ
205 /* for multiple Rx queues */
206 void e1000_rx_schedule(void *data);
209 /* Exported from other modules */
211 extern void e1000_check_options(struct e1000_adapter *adapter);
213 static struct pci_driver e1000_driver = {
214 .name = e1000_driver_name,
215 .id_table = e1000_pci_tbl,
216 .probe = e1000_probe,
217 .remove = __devexit_p(e1000_remove),
218 /* Power Managment Hooks */
220 .suspend = e1000_suspend,
221 .resume = e1000_resume
225 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
226 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
227 MODULE_LICENSE("GPL");
228 MODULE_VERSION(DRV_VERSION);
230 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
231 module_param(debug, int, 0);
232 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
235 * e1000_init_module - Driver Registration Routine
237 * e1000_init_module is the first routine called when the driver is
238 * loaded. All it does is register with the PCI subsystem.
242 e1000_init_module(void)
245 printk(KERN_INFO "%s - version %s\n",
246 e1000_driver_string, e1000_driver_version);
248 printk(KERN_INFO "%s\n", e1000_copyright);
250 ret = pci_module_init(&e1000_driver);
255 module_init(e1000_init_module);
258 * e1000_exit_module - Driver Exit Cleanup Routine
260 * e1000_exit_module is called just before the driver is removed
265 e1000_exit_module(void)
267 pci_unregister_driver(&e1000_driver);
270 module_exit(e1000_exit_module);
273 * e1000_irq_disable - Mask off interrupt generation on the NIC
274 * @adapter: board private structure
278 e1000_irq_disable(struct e1000_adapter *adapter)
280 atomic_inc(&adapter->irq_sem);
281 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
282 E1000_WRITE_FLUSH(&adapter->hw);
283 synchronize_irq(adapter->pdev->irq);
287 * e1000_irq_enable - Enable default interrupt generation settings
288 * @adapter: board private structure
292 e1000_irq_enable(struct e1000_adapter *adapter)
294 if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
295 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
296 E1000_WRITE_FLUSH(&adapter->hw);
301 e1000_update_mng_vlan(struct e1000_adapter *adapter)
303 struct net_device *netdev = adapter->netdev;
304 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
305 uint16_t old_vid = adapter->mng_vlan_id;
307 if(!adapter->vlgrp->vlan_devices[vid]) {
308 if(adapter->hw.mng_cookie.status &
309 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
310 e1000_vlan_rx_add_vid(netdev, vid);
311 adapter->mng_vlan_id = vid;
313 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
315 if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
317 !adapter->vlgrp->vlan_devices[old_vid])
318 e1000_vlan_rx_kill_vid(netdev, old_vid);
324 e1000_up(struct e1000_adapter *adapter)
326 struct net_device *netdev = adapter->netdev;
329 /* hardware has been reset, we need to reload some things */
331 /* Reset the PHY if it was previously powered down */
332 if(adapter->hw.media_type == e1000_media_type_copper) {
334 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
335 if(mii_reg & MII_CR_POWER_DOWN)
336 e1000_phy_reset(&adapter->hw);
339 e1000_set_multi(netdev);
341 e1000_restore_vlan(adapter);
343 e1000_configure_tx(adapter);
344 e1000_setup_rctl(adapter);
345 e1000_configure_rx(adapter);
346 for (i = 0; i < adapter->num_queues; i++)
347 adapter->alloc_rx_buf(adapter, &adapter->rx_ring[i]);
349 #ifdef CONFIG_PCI_MSI
350 if(adapter->hw.mac_type > e1000_82547_rev_2) {
351 adapter->have_msi = TRUE;
352 if((err = pci_enable_msi(adapter->pdev))) {
354 "Unable to allocate MSI interrupt Error: %d\n", err);
355 adapter->have_msi = FALSE;
359 if((err = request_irq(adapter->pdev->irq, &e1000_intr,
360 SA_SHIRQ | SA_SAMPLE_RANDOM,
361 netdev->name, netdev))) {
363 "Unable to allocate interrupt Error: %d\n", err);
367 mod_timer(&adapter->watchdog_timer, jiffies);
369 #ifdef CONFIG_E1000_NAPI
370 netif_poll_enable(netdev);
372 e1000_irq_enable(adapter);
378 e1000_down(struct e1000_adapter *adapter)
380 struct net_device *netdev = adapter->netdev;
382 e1000_irq_disable(adapter);
383 #ifdef CONFIG_E1000_MQ
384 while (atomic_read(&adapter->rx_sched_call_data.count) != 0);
386 free_irq(adapter->pdev->irq, netdev);
387 #ifdef CONFIG_PCI_MSI
388 if(adapter->hw.mac_type > e1000_82547_rev_2 &&
389 adapter->have_msi == TRUE)
390 pci_disable_msi(adapter->pdev);
392 del_timer_sync(&adapter->tx_fifo_stall_timer);
393 del_timer_sync(&adapter->watchdog_timer);
394 del_timer_sync(&adapter->phy_info_timer);
396 #ifdef CONFIG_E1000_NAPI
397 netif_poll_disable(netdev);
399 adapter->link_speed = 0;
400 adapter->link_duplex = 0;
401 netif_carrier_off(netdev);
402 netif_stop_queue(netdev);
404 e1000_reset(adapter);
405 e1000_clean_all_tx_rings(adapter);
406 e1000_clean_all_rx_rings(adapter);
408 /* If WoL is not enabled and management mode is not IAMT
409 * Power down the PHY so no link is implied when interface is down */
410 if(!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
411 adapter->hw.media_type == e1000_media_type_copper &&
412 !e1000_check_mng_mode(&adapter->hw) &&
413 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN)) {
415 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
416 mii_reg |= MII_CR_POWER_DOWN;
417 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
423 e1000_reset(struct e1000_adapter *adapter)
425 struct net_device *netdev = adapter->netdev;
427 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
428 uint16_t fc_low_water_mark = E1000_FC_LOW_DIFF;
430 /* Repartition Pba for greater than 9k mtu
431 * To take effect CTRL.RST is required.
434 switch (adapter->hw.mac_type) {
436 case e1000_82547_rev_2:
451 if((adapter->hw.mac_type != e1000_82573) &&
452 (adapter->netdev->mtu > E1000_RXBUFFER_8192)) {
453 pba -= 8; /* allocate more FIFO for Tx */
454 /* send an XOFF when there is enough space in the
455 * Rx FIFO to hold one extra full size Rx packet
457 fc_high_water_mark = netdev->mtu + ENET_HEADER_SIZE +
458 ETHERNET_FCS_SIZE + 1;
459 fc_low_water_mark = fc_high_water_mark + 8;
463 if(adapter->hw.mac_type == e1000_82547) {
464 adapter->tx_fifo_head = 0;
465 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
466 adapter->tx_fifo_size =
467 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
468 atomic_set(&adapter->tx_fifo_stall, 0);
471 E1000_WRITE_REG(&adapter->hw, PBA, pba);
473 /* flow control settings */
474 adapter->hw.fc_high_water = (pba << E1000_PBA_BYTES_SHIFT) -
476 adapter->hw.fc_low_water = (pba << E1000_PBA_BYTES_SHIFT) -
478 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
479 adapter->hw.fc_send_xon = 1;
480 adapter->hw.fc = adapter->hw.original_fc;
482 /* Allow time for pending master requests to run */
483 e1000_reset_hw(&adapter->hw);
484 if(adapter->hw.mac_type >= e1000_82544)
485 E1000_WRITE_REG(&adapter->hw, WUC, 0);
486 if(e1000_init_hw(&adapter->hw))
487 DPRINTK(PROBE, ERR, "Hardware Error\n");
488 e1000_update_mng_vlan(adapter);
489 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
490 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
492 e1000_reset_adaptive(&adapter->hw);
493 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
494 if (adapter->en_mng_pt) {
495 manc = E1000_READ_REG(&adapter->hw, MANC);
496 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
497 E1000_WRITE_REG(&adapter->hw, MANC, manc);
502 * e1000_probe - Device Initialization Routine
503 * @pdev: PCI device information struct
504 * @ent: entry in e1000_pci_tbl
506 * Returns 0 on success, negative on failure
508 * e1000_probe initializes an adapter identified by a pci_dev structure.
509 * The OS initialization, configuring of the adapter private structure,
510 * and a hardware reset occur.
514 e1000_probe(struct pci_dev *pdev,
515 const struct pci_device_id *ent)
517 struct net_device *netdev;
518 struct e1000_adapter *adapter;
519 unsigned long mmio_start, mmio_len;
523 static int cards_found = 0;
524 int i, err, pci_using_dac;
525 uint16_t eeprom_data;
526 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
527 if((err = pci_enable_device(pdev)))
530 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
533 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
534 E1000_ERR("No usable DMA configuration, aborting\n");
540 if((err = pci_request_regions(pdev, e1000_driver_name)))
543 pci_set_master(pdev);
545 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
548 goto err_alloc_etherdev;
551 SET_MODULE_OWNER(netdev);
552 SET_NETDEV_DEV(netdev, &pdev->dev);
554 pci_set_drvdata(pdev, netdev);
555 adapter = netdev_priv(netdev);
556 adapter->netdev = netdev;
557 adapter->pdev = pdev;
558 adapter->hw.back = adapter;
559 adapter->msg_enable = (1 << debug) - 1;
561 mmio_start = pci_resource_start(pdev, BAR_0);
562 mmio_len = pci_resource_len(pdev, BAR_0);
564 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
565 if(!adapter->hw.hw_addr) {
570 for(i = BAR_1; i <= BAR_5; i++) {
571 if(pci_resource_len(pdev, i) == 0)
573 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
574 adapter->hw.io_base = pci_resource_start(pdev, i);
579 netdev->open = &e1000_open;
580 netdev->stop = &e1000_close;
581 netdev->hard_start_xmit = &e1000_xmit_frame;
582 netdev->get_stats = &e1000_get_stats;
583 netdev->set_multicast_list = &e1000_set_multi;
584 netdev->set_mac_address = &e1000_set_mac;
585 netdev->change_mtu = &e1000_change_mtu;
586 netdev->do_ioctl = &e1000_ioctl;
587 e1000_set_ethtool_ops(netdev);
588 netdev->tx_timeout = &e1000_tx_timeout;
589 netdev->watchdog_timeo = 5 * HZ;
590 #ifdef CONFIG_E1000_NAPI
591 netdev->poll = &e1000_clean;
594 netdev->vlan_rx_register = e1000_vlan_rx_register;
595 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
596 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
597 #ifdef CONFIG_NET_POLL_CONTROLLER
598 netdev->poll_controller = e1000_netpoll;
600 strcpy(netdev->name, pci_name(pdev));
602 netdev->mem_start = mmio_start;
603 netdev->mem_end = mmio_start + mmio_len;
604 netdev->base_addr = adapter->hw.io_base;
606 adapter->bd_number = cards_found;
608 /* setup the private structure */
610 if((err = e1000_sw_init(adapter)))
613 if((err = e1000_check_phy_reset_block(&adapter->hw)))
614 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
616 if(adapter->hw.mac_type >= e1000_82543) {
617 netdev->features = NETIF_F_SG |
621 NETIF_F_HW_VLAN_FILTER;
625 if((adapter->hw.mac_type >= e1000_82544) &&
626 (adapter->hw.mac_type != e1000_82547))
627 netdev->features |= NETIF_F_TSO;
629 #ifdef NETIF_F_TSO_IPV6
630 if(adapter->hw.mac_type > e1000_82547_rev_2)
631 netdev->features |= NETIF_F_TSO_IPV6;
635 netdev->features |= NETIF_F_HIGHDMA;
637 /* hard_start_xmit is safe against parallel locking */
638 netdev->features |= NETIF_F_LLTX;
640 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
642 /* before reading the EEPROM, reset the controller to
643 * put the device in a known good starting state */
645 e1000_reset_hw(&adapter->hw);
647 /* make sure the EEPROM is good */
649 if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
650 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
655 /* copy the MAC address out of the EEPROM */
657 if(e1000_read_mac_addr(&adapter->hw))
658 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
659 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
660 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
662 if(!is_valid_ether_addr(netdev->perm_addr)) {
663 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
668 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
670 e1000_get_bus_info(&adapter->hw);
672 init_timer(&adapter->tx_fifo_stall_timer);
673 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
674 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
676 init_timer(&adapter->watchdog_timer);
677 adapter->watchdog_timer.function = &e1000_watchdog;
678 adapter->watchdog_timer.data = (unsigned long) adapter;
680 INIT_WORK(&adapter->watchdog_task,
681 (void (*)(void *))e1000_watchdog_task, adapter);
683 init_timer(&adapter->phy_info_timer);
684 adapter->phy_info_timer.function = &e1000_update_phy_info;
685 adapter->phy_info_timer.data = (unsigned long) adapter;
687 INIT_WORK(&adapter->tx_timeout_task,
688 (void (*)(void *))e1000_tx_timeout_task, netdev);
690 /* we're going to reset, so assume we have no link for now */
692 netif_carrier_off(netdev);
693 netif_stop_queue(netdev);
695 e1000_check_options(adapter);
697 /* Initial Wake on LAN setting
698 * If APM wake is enabled in the EEPROM,
699 * enable the ACPI Magic Packet filter
702 switch(adapter->hw.mac_type) {
703 case e1000_82542_rev2_0:
704 case e1000_82542_rev2_1:
708 e1000_read_eeprom(&adapter->hw,
709 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
710 eeprom_apme_mask = E1000_EEPROM_82544_APM;
713 case e1000_82546_rev_3:
715 if((E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
716 && (adapter->hw.media_type == e1000_media_type_copper)) {
717 e1000_read_eeprom(&adapter->hw,
718 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
723 e1000_read_eeprom(&adapter->hw,
724 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
727 if(eeprom_data & eeprom_apme_mask)
728 adapter->wol |= E1000_WUFC_MAG;
730 /* reset the hardware with the new settings */
731 e1000_reset(adapter);
733 /* Let firmware know the driver has taken over */
734 switch(adapter->hw.mac_type) {
737 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
738 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
739 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
742 swsm = E1000_READ_REG(&adapter->hw, SWSM);
743 E1000_WRITE_REG(&adapter->hw, SWSM,
744 swsm | E1000_SWSM_DRV_LOAD);
750 strcpy(netdev->name, "eth%d");
751 if((err = register_netdev(netdev)))
754 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
762 iounmap(adapter->hw.hw_addr);
766 pci_release_regions(pdev);
771 * e1000_remove - Device Removal Routine
772 * @pdev: PCI device information struct
774 * e1000_remove is called by the PCI subsystem to alert the driver
775 * that it should release a PCI device. The could be caused by a
776 * Hot-Plug event, or because the driver is going to be removed from
780 static void __devexit
781 e1000_remove(struct pci_dev *pdev)
783 struct net_device *netdev = pci_get_drvdata(pdev);
784 struct e1000_adapter *adapter = netdev_priv(netdev);
787 #ifdef CONFIG_E1000_NAPI
791 flush_scheduled_work();
793 if(adapter->hw.mac_type >= e1000_82540 &&
794 adapter->hw.media_type == e1000_media_type_copper) {
795 manc = E1000_READ_REG(&adapter->hw, MANC);
796 if(manc & E1000_MANC_SMBUS_EN) {
797 manc |= E1000_MANC_ARP_EN;
798 E1000_WRITE_REG(&adapter->hw, MANC, manc);
802 switch(adapter->hw.mac_type) {
805 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
806 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
807 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
810 swsm = E1000_READ_REG(&adapter->hw, SWSM);
811 E1000_WRITE_REG(&adapter->hw, SWSM,
812 swsm & ~E1000_SWSM_DRV_LOAD);
819 unregister_netdev(netdev);
820 #ifdef CONFIG_E1000_NAPI
821 for (i = 0; i < adapter->num_queues; i++)
822 __dev_put(&adapter->polling_netdev[i]);
825 if(!e1000_check_phy_reset_block(&adapter->hw))
826 e1000_phy_hw_reset(&adapter->hw);
828 kfree(adapter->tx_ring);
829 kfree(adapter->rx_ring);
830 #ifdef CONFIG_E1000_NAPI
831 kfree(adapter->polling_netdev);
834 iounmap(adapter->hw.hw_addr);
835 pci_release_regions(pdev);
837 #ifdef CONFIG_E1000_MQ
838 free_percpu(adapter->cpu_netdev);
839 free_percpu(adapter->cpu_tx_ring);
843 pci_disable_device(pdev);
847 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
848 * @adapter: board private structure to initialize
850 * e1000_sw_init initializes the Adapter private data structure.
851 * Fields are initialized based on PCI device information and
852 * OS network device settings (MTU size).
856 e1000_sw_init(struct e1000_adapter *adapter)
858 struct e1000_hw *hw = &adapter->hw;
859 struct net_device *netdev = adapter->netdev;
860 struct pci_dev *pdev = adapter->pdev;
861 #ifdef CONFIG_E1000_NAPI
865 /* PCI config space info */
867 hw->vendor_id = pdev->vendor;
868 hw->device_id = pdev->device;
869 hw->subsystem_vendor_id = pdev->subsystem_vendor;
870 hw->subsystem_id = pdev->subsystem_device;
872 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
874 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
876 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
877 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
878 hw->max_frame_size = netdev->mtu +
879 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
880 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
882 /* identify the MAC */
884 if(e1000_set_mac_type(hw)) {
885 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
889 /* initialize eeprom parameters */
891 if(e1000_init_eeprom_params(hw)) {
892 E1000_ERR("EEPROM initialization failed\n");
896 switch(hw->mac_type) {
901 case e1000_82541_rev_2:
902 case e1000_82547_rev_2:
903 hw->phy_init_script = 1;
907 e1000_set_media_type(hw);
909 hw->wait_autoneg_complete = FALSE;
910 hw->tbi_compatibility_en = TRUE;
911 hw->adaptive_ifs = TRUE;
915 if(hw->media_type == e1000_media_type_copper) {
916 hw->mdix = AUTO_ALL_MODES;
917 hw->disable_polarity_correction = FALSE;
918 hw->master_slave = E1000_MASTER_SLAVE;
921 #ifdef CONFIG_E1000_MQ
922 /* Number of supported queues */
923 switch (hw->mac_type) {
926 adapter->num_queues = 2;
929 adapter->num_queues = 1;
932 adapter->num_queues = min(adapter->num_queues, num_online_cpus());
934 adapter->num_queues = 1;
937 if (e1000_alloc_queues(adapter)) {
938 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
942 #ifdef CONFIG_E1000_NAPI
943 for (i = 0; i < adapter->num_queues; i++) {
944 adapter->polling_netdev[i].priv = adapter;
945 adapter->polling_netdev[i].poll = &e1000_clean;
946 adapter->polling_netdev[i].weight = 64;
947 dev_hold(&adapter->polling_netdev[i]);
948 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
952 #ifdef CONFIG_E1000_MQ
953 e1000_setup_queue_mapping(adapter);
956 atomic_set(&adapter->irq_sem, 1);
957 spin_lock_init(&adapter->stats_lock);
963 * e1000_alloc_queues - Allocate memory for all rings
964 * @adapter: board private structure to initialize
966 * We allocate one ring per queue at run-time since we don't know the
967 * number of queues at compile-time. The polling_netdev array is
968 * intended for Multiqueue, but should work fine with a single queue.
972 e1000_alloc_queues(struct e1000_adapter *adapter)
976 size = sizeof(struct e1000_tx_ring) * adapter->num_queues;
977 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
978 if (!adapter->tx_ring)
980 memset(adapter->tx_ring, 0, size);
982 size = sizeof(struct e1000_rx_ring) * adapter->num_queues;
983 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
984 if (!adapter->rx_ring) {
985 kfree(adapter->tx_ring);
988 memset(adapter->rx_ring, 0, size);
990 #ifdef CONFIG_E1000_NAPI
991 size = sizeof(struct net_device) * adapter->num_queues;
992 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
993 if (!adapter->polling_netdev) {
994 kfree(adapter->tx_ring);
995 kfree(adapter->rx_ring);
998 memset(adapter->polling_netdev, 0, size);
1001 return E1000_SUCCESS;
1004 #ifdef CONFIG_E1000_MQ
1005 static void __devinit
1006 e1000_setup_queue_mapping(struct e1000_adapter *adapter)
1010 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1011 adapter->rx_sched_call_data.info = adapter->netdev;
1012 cpus_clear(adapter->rx_sched_call_data.cpumask);
1014 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1015 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1019 for_each_online_cpu(cpu) {
1020 *per_cpu_ptr(adapter->cpu_tx_ring, cpu) = &adapter->tx_ring[i % adapter->num_queues];
1021 /* This is incomplete because we'd like to assign separate
1022 * physical cpus to these netdev polling structures and
1023 * avoid saturating a subset of cpus.
1025 if (i < adapter->num_queues) {
1026 *per_cpu_ptr(adapter->cpu_netdev, cpu) = &adapter->polling_netdev[i];
1027 adapter->cpu_for_queue[i] = cpu;
1029 *per_cpu_ptr(adapter->cpu_netdev, cpu) = NULL;
1033 unlock_cpu_hotplug();
1038 * e1000_open - Called when a network interface is made active
1039 * @netdev: network interface device structure
1041 * Returns 0 on success, negative value on failure
1043 * The open entry point is called when a network interface is made
1044 * active by the system (IFF_UP). At this point all resources needed
1045 * for transmit and receive operations are allocated, the interrupt
1046 * handler is registered with the OS, the watchdog timer is started,
1047 * and the stack is notified that the interface is ready.
1051 e1000_open(struct net_device *netdev)
1053 struct e1000_adapter *adapter = netdev_priv(netdev);
1056 /* allocate transmit descriptors */
1058 if ((err = e1000_setup_all_tx_resources(adapter)))
1061 /* allocate receive descriptors */
1063 if ((err = e1000_setup_all_rx_resources(adapter)))
1066 if((err = e1000_up(adapter)))
1068 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1069 if((adapter->hw.mng_cookie.status &
1070 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1071 e1000_update_mng_vlan(adapter);
1074 return E1000_SUCCESS;
1077 e1000_free_all_rx_resources(adapter);
1079 e1000_free_all_tx_resources(adapter);
1081 e1000_reset(adapter);
1087 * e1000_close - Disables a network interface
1088 * @netdev: network interface device structure
1090 * Returns 0, this is not allowed to fail
1092 * The close entry point is called when an interface is de-activated
1093 * by the OS. The hardware is still under the drivers control, but
1094 * needs to be disabled. A global MAC reset is issued to stop the
1095 * hardware, and all transmit and receive resources are freed.
1099 e1000_close(struct net_device *netdev)
1101 struct e1000_adapter *adapter = netdev_priv(netdev);
1103 e1000_down(adapter);
1105 e1000_free_all_tx_resources(adapter);
1106 e1000_free_all_rx_resources(adapter);
1108 if((adapter->hw.mng_cookie.status &
1109 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1110 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1116 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1117 * @adapter: address of board private structure
1118 * @start: address of beginning of memory
1119 * @len: length of memory
1121 static inline boolean_t
1122 e1000_check_64k_bound(struct e1000_adapter *adapter,
1123 void *start, unsigned long len)
1125 unsigned long begin = (unsigned long) start;
1126 unsigned long end = begin + len;
1128 /* First rev 82545 and 82546 need to not allow any memory
1129 * write location to cross 64k boundary due to errata 23 */
1130 if (adapter->hw.mac_type == e1000_82545 ||
1131 adapter->hw.mac_type == e1000_82546) {
1132 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1139 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1140 * @adapter: board private structure
1141 * @txdr: tx descriptor ring (for a specific queue) to setup
1143 * Return 0 on success, negative on failure
1147 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1148 struct e1000_tx_ring *txdr)
1150 struct pci_dev *pdev = adapter->pdev;
1153 size = sizeof(struct e1000_buffer) * txdr->count;
1155 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1156 if(!txdr->buffer_info) {
1158 "Unable to allocate memory for the transmit descriptor ring\n");
1161 memset(txdr->buffer_info, 0, size);
1163 /* round up to nearest 4K */
1165 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1166 E1000_ROUNDUP(txdr->size, 4096);
1168 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1171 vfree(txdr->buffer_info);
1173 "Unable to allocate memory for the transmit descriptor ring\n");
1177 /* Fix for errata 23, can't cross 64kB boundary */
1178 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1179 void *olddesc = txdr->desc;
1180 dma_addr_t olddma = txdr->dma;
1181 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1182 "at %p\n", txdr->size, txdr->desc);
1183 /* Try again, without freeing the previous */
1184 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1186 /* Failed allocation, critical failure */
1187 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1188 goto setup_tx_desc_die;
1191 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1193 pci_free_consistent(pdev, txdr->size, txdr->desc,
1195 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1197 "Unable to allocate aligned memory "
1198 "for the transmit descriptor ring\n");
1199 vfree(txdr->buffer_info);
1202 /* Free old allocation, new allocation was successful */
1203 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1206 memset(txdr->desc, 0, txdr->size);
1208 txdr->next_to_use = 0;
1209 txdr->next_to_clean = 0;
1210 spin_lock_init(&txdr->tx_lock);
1216 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1217 * (Descriptors) for all queues
1218 * @adapter: board private structure
1220 * If this function returns with an error, then it's possible one or
1221 * more of the rings is populated (while the rest are not). It is the
1222 * callers duty to clean those orphaned rings.
1224 * Return 0 on success, negative on failure
1228 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1232 for (i = 0; i < adapter->num_queues; i++) {
1233 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1236 "Allocation for Tx Queue %u failed\n", i);
1245 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1246 * @adapter: board private structure
1248 * Configure the Tx unit of the MAC after a reset.
1252 e1000_configure_tx(struct e1000_adapter *adapter)
1255 struct e1000_hw *hw = &adapter->hw;
1256 uint32_t tdlen, tctl, tipg, tarc;
1258 /* Setup the HW Tx Head and Tail descriptor pointers */
1260 switch (adapter->num_queues) {
1262 tdba = adapter->tx_ring[1].dma;
1263 tdlen = adapter->tx_ring[1].count *
1264 sizeof(struct e1000_tx_desc);
1265 E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
1266 E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
1267 E1000_WRITE_REG(hw, TDLEN1, tdlen);
1268 E1000_WRITE_REG(hw, TDH1, 0);
1269 E1000_WRITE_REG(hw, TDT1, 0);
1270 adapter->tx_ring[1].tdh = E1000_TDH1;
1271 adapter->tx_ring[1].tdt = E1000_TDT1;
1275 tdba = adapter->tx_ring[0].dma;
1276 tdlen = adapter->tx_ring[0].count *
1277 sizeof(struct e1000_tx_desc);
1278 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1279 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1280 E1000_WRITE_REG(hw, TDLEN, tdlen);
1281 E1000_WRITE_REG(hw, TDH, 0);
1282 E1000_WRITE_REG(hw, TDT, 0);
1283 adapter->tx_ring[0].tdh = E1000_TDH;
1284 adapter->tx_ring[0].tdt = E1000_TDT;
1288 /* Set the default values for the Tx Inter Packet Gap timer */
1290 switch (hw->mac_type) {
1291 case e1000_82542_rev2_0:
1292 case e1000_82542_rev2_1:
1293 tipg = DEFAULT_82542_TIPG_IPGT;
1294 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1295 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1298 if (hw->media_type == e1000_media_type_fiber ||
1299 hw->media_type == e1000_media_type_internal_serdes)
1300 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1302 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1303 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1304 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1306 E1000_WRITE_REG(hw, TIPG, tipg);
1308 /* Set the Tx Interrupt Delay register */
1310 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1311 if (hw->mac_type >= e1000_82540)
1312 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1314 /* Program the Transmit Control Register */
1316 tctl = E1000_READ_REG(hw, TCTL);
1318 tctl &= ~E1000_TCTL_CT;
1319 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
1320 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1322 E1000_WRITE_REG(hw, TCTL, tctl);
1324 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1325 tarc = E1000_READ_REG(hw, TARC0);
1326 tarc |= ((1 << 25) | (1 << 21));
1327 E1000_WRITE_REG(hw, TARC0, tarc);
1328 tarc = E1000_READ_REG(hw, TARC1);
1330 if (tctl & E1000_TCTL_MULR)
1334 E1000_WRITE_REG(hw, TARC1, tarc);
1337 e1000_config_collision_dist(hw);
1339 /* Setup Transmit Descriptor Settings for eop descriptor */
1340 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1343 if (hw->mac_type < e1000_82543)
1344 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1346 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1348 /* Cache if we're 82544 running in PCI-X because we'll
1349 * need this to apply a workaround later in the send path. */
1350 if (hw->mac_type == e1000_82544 &&
1351 hw->bus_type == e1000_bus_type_pcix)
1352 adapter->pcix_82544 = 1;
1356 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1357 * @adapter: board private structure
1358 * @rxdr: rx descriptor ring (for a specific queue) to setup
1360 * Returns 0 on success, negative on failure
1364 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1365 struct e1000_rx_ring *rxdr)
1367 struct pci_dev *pdev = adapter->pdev;
1370 size = sizeof(struct e1000_buffer) * rxdr->count;
1371 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1372 if (!rxdr->buffer_info) {
1374 "Unable to allocate memory for the receive descriptor ring\n");
1377 memset(rxdr->buffer_info, 0, size);
1379 size = sizeof(struct e1000_ps_page) * rxdr->count;
1380 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1381 if(!rxdr->ps_page) {
1382 vfree(rxdr->buffer_info);
1384 "Unable to allocate memory for the receive descriptor ring\n");
1387 memset(rxdr->ps_page, 0, size);
1389 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1390 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1391 if(!rxdr->ps_page_dma) {
1392 vfree(rxdr->buffer_info);
1393 kfree(rxdr->ps_page);
1395 "Unable to allocate memory for the receive descriptor ring\n");
1398 memset(rxdr->ps_page_dma, 0, size);
1400 if(adapter->hw.mac_type <= e1000_82547_rev_2)
1401 desc_len = sizeof(struct e1000_rx_desc);
1403 desc_len = sizeof(union e1000_rx_desc_packet_split);
1405 /* Round up to nearest 4K */
1407 rxdr->size = rxdr->count * desc_len;
1408 E1000_ROUNDUP(rxdr->size, 4096);
1410 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1414 "Unable to allocate memory for the receive descriptor ring\n");
1416 vfree(rxdr->buffer_info);
1417 kfree(rxdr->ps_page);
1418 kfree(rxdr->ps_page_dma);
1422 /* Fix for errata 23, can't cross 64kB boundary */
1423 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1424 void *olddesc = rxdr->desc;
1425 dma_addr_t olddma = rxdr->dma;
1426 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1427 "at %p\n", rxdr->size, rxdr->desc);
1428 /* Try again, without freeing the previous */
1429 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1430 /* Failed allocation, critical failure */
1432 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1434 "Unable to allocate memory "
1435 "for the receive descriptor ring\n");
1436 goto setup_rx_desc_die;
1439 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1441 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1443 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1445 "Unable to allocate aligned memory "
1446 "for the receive descriptor ring\n");
1447 goto setup_rx_desc_die;
1449 /* Free old allocation, new allocation was successful */
1450 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1453 memset(rxdr->desc, 0, rxdr->size);
1455 rxdr->next_to_clean = 0;
1456 rxdr->next_to_use = 0;
1462 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1463 * (Descriptors) for all queues
1464 * @adapter: board private structure
1466 * If this function returns with an error, then it's possible one or
1467 * more of the rings is populated (while the rest are not). It is the
1468 * callers duty to clean those orphaned rings.
1470 * Return 0 on success, negative on failure
1474 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1478 for (i = 0; i < adapter->num_queues; i++) {
1479 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1482 "Allocation for Rx Queue %u failed\n", i);
1491 * e1000_setup_rctl - configure the receive control registers
1492 * @adapter: Board private structure
1494 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1495 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1497 e1000_setup_rctl(struct e1000_adapter *adapter)
1499 uint32_t rctl, rfctl;
1500 uint32_t psrctl = 0;
1501 #ifdef CONFIG_E1000_PACKET_SPLIT
1505 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1507 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1509 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1510 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1511 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1513 if(adapter->hw.tbi_compatibility_on == 1)
1514 rctl |= E1000_RCTL_SBP;
1516 rctl &= ~E1000_RCTL_SBP;
1518 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1519 rctl &= ~E1000_RCTL_LPE;
1521 rctl |= E1000_RCTL_LPE;
1523 /* Setup buffer sizes */
1524 if(adapter->hw.mac_type >= e1000_82571) {
1525 /* We can now specify buffers in 1K increments.
1526 * BSIZE and BSEX are ignored in this case. */
1527 rctl |= adapter->rx_buffer_len << 0x11;
1529 rctl &= ~E1000_RCTL_SZ_4096;
1530 rctl |= E1000_RCTL_BSEX;
1531 switch (adapter->rx_buffer_len) {
1532 case E1000_RXBUFFER_2048:
1534 rctl |= E1000_RCTL_SZ_2048;
1535 rctl &= ~E1000_RCTL_BSEX;
1537 case E1000_RXBUFFER_4096:
1538 rctl |= E1000_RCTL_SZ_4096;
1540 case E1000_RXBUFFER_8192:
1541 rctl |= E1000_RCTL_SZ_8192;
1543 case E1000_RXBUFFER_16384:
1544 rctl |= E1000_RCTL_SZ_16384;
1549 #ifdef CONFIG_E1000_PACKET_SPLIT
1550 /* 82571 and greater support packet-split where the protocol
1551 * header is placed in skb->data and the packet data is
1552 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1553 * In the case of a non-split, skb->data is linearly filled,
1554 * followed by the page buffers. Therefore, skb->data is
1555 * sized to hold the largest protocol header.
1557 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1558 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1560 adapter->rx_ps_pages = pages;
1562 adapter->rx_ps_pages = 0;
1564 if (adapter->rx_ps_pages) {
1565 /* Configure extra packet-split registers */
1566 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1567 rfctl |= E1000_RFCTL_EXTEN;
1568 /* disable IPv6 packet split support */
1569 rfctl |= E1000_RFCTL_IPV6_DIS;
1570 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1572 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1574 psrctl |= adapter->rx_ps_bsize0 >>
1575 E1000_PSRCTL_BSIZE0_SHIFT;
1577 switch (adapter->rx_ps_pages) {
1579 psrctl |= PAGE_SIZE <<
1580 E1000_PSRCTL_BSIZE3_SHIFT;
1582 psrctl |= PAGE_SIZE <<
1583 E1000_PSRCTL_BSIZE2_SHIFT;
1585 psrctl |= PAGE_SIZE >>
1586 E1000_PSRCTL_BSIZE1_SHIFT;
1590 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1593 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1597 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1598 * @adapter: board private structure
1600 * Configure the Rx unit of the MAC after a reset.
1604 e1000_configure_rx(struct e1000_adapter *adapter)
1607 struct e1000_hw *hw = &adapter->hw;
1608 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1609 #ifdef CONFIG_E1000_MQ
1610 uint32_t reta, mrqc;
1614 if (adapter->rx_ps_pages) {
1615 rdlen = adapter->rx_ring[0].count *
1616 sizeof(union e1000_rx_desc_packet_split);
1617 adapter->clean_rx = e1000_clean_rx_irq_ps;
1618 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1620 rdlen = adapter->rx_ring[0].count *
1621 sizeof(struct e1000_rx_desc);
1622 adapter->clean_rx = e1000_clean_rx_irq;
1623 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1626 /* disable receives while setting up the descriptors */
1627 rctl = E1000_READ_REG(hw, RCTL);
1628 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1630 /* set the Receive Delay Timer Register */
1631 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1633 if (hw->mac_type >= e1000_82540) {
1634 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1635 if(adapter->itr > 1)
1636 E1000_WRITE_REG(hw, ITR,
1637 1000000000 / (adapter->itr * 256));
1640 if (hw->mac_type >= e1000_82571) {
1641 /* Reset delay timers after every interrupt */
1642 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1643 ctrl_ext |= E1000_CTRL_EXT_CANC;
1644 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1645 E1000_WRITE_FLUSH(hw);
1648 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1649 * the Base and Length of the Rx Descriptor Ring */
1650 switch (adapter->num_queues) {
1651 #ifdef CONFIG_E1000_MQ
1653 rdba = adapter->rx_ring[1].dma;
1654 E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
1655 E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
1656 E1000_WRITE_REG(hw, RDLEN1, rdlen);
1657 E1000_WRITE_REG(hw, RDH1, 0);
1658 E1000_WRITE_REG(hw, RDT1, 0);
1659 adapter->rx_ring[1].rdh = E1000_RDH1;
1660 adapter->rx_ring[1].rdt = E1000_RDT1;
1665 rdba = adapter->rx_ring[0].dma;
1666 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1667 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1668 E1000_WRITE_REG(hw, RDLEN, rdlen);
1669 E1000_WRITE_REG(hw, RDH, 0);
1670 E1000_WRITE_REG(hw, RDT, 0);
1671 adapter->rx_ring[0].rdh = E1000_RDH;
1672 adapter->rx_ring[0].rdt = E1000_RDT;
1676 #ifdef CONFIG_E1000_MQ
1677 if (adapter->num_queues > 1) {
1678 uint32_t random[10];
1680 get_random_bytes(&random[0], 40);
1682 if (hw->mac_type <= e1000_82572) {
1683 E1000_WRITE_REG(hw, RSSIR, 0);
1684 E1000_WRITE_REG(hw, RSSIM, 0);
1687 switch (adapter->num_queues) {
1691 mrqc = E1000_MRQC_ENABLE_RSS_2Q;
1695 /* Fill out redirection table */
1696 for (i = 0; i < 32; i++)
1697 E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
1698 /* Fill out hash function seeds */
1699 for (i = 0; i < 10; i++)
1700 E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
1702 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1703 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1704 E1000_WRITE_REG(hw, MRQC, mrqc);
1707 /* Multiqueue and packet checksumming are mutually exclusive. */
1708 if (hw->mac_type >= e1000_82571) {
1709 rxcsum = E1000_READ_REG(hw, RXCSUM);
1710 rxcsum |= E1000_RXCSUM_PCSD;
1711 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1716 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1717 if (hw->mac_type >= e1000_82543) {
1718 rxcsum = E1000_READ_REG(hw, RXCSUM);
1719 if(adapter->rx_csum == TRUE) {
1720 rxcsum |= E1000_RXCSUM_TUOFL;
1722 /* Enable 82571 IPv4 payload checksum for UDP fragments
1723 * Must be used in conjunction with packet-split. */
1724 if ((hw->mac_type >= e1000_82571) &&
1725 (adapter->rx_ps_pages)) {
1726 rxcsum |= E1000_RXCSUM_IPPCSE;
1729 rxcsum &= ~E1000_RXCSUM_TUOFL;
1730 /* don't need to clear IPPCSE as it defaults to 0 */
1732 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1734 #endif /* CONFIG_E1000_MQ */
1736 if (hw->mac_type == e1000_82573)
1737 E1000_WRITE_REG(hw, ERT, 0x0100);
1739 /* Enable Receives */
1740 E1000_WRITE_REG(hw, RCTL, rctl);
1744 * e1000_free_tx_resources - Free Tx Resources per Queue
1745 * @adapter: board private structure
1746 * @tx_ring: Tx descriptor ring for a specific queue
1748 * Free all transmit software resources
1752 e1000_free_tx_resources(struct e1000_adapter *adapter,
1753 struct e1000_tx_ring *tx_ring)
1755 struct pci_dev *pdev = adapter->pdev;
1757 e1000_clean_tx_ring(adapter, tx_ring);
1759 vfree(tx_ring->buffer_info);
1760 tx_ring->buffer_info = NULL;
1762 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1764 tx_ring->desc = NULL;
1768 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1769 * @adapter: board private structure
1771 * Free all transmit software resources
1775 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1779 for (i = 0; i < adapter->num_queues; i++)
1780 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1784 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1785 struct e1000_buffer *buffer_info)
1787 if(buffer_info->dma) {
1788 pci_unmap_page(adapter->pdev,
1790 buffer_info->length,
1792 buffer_info->dma = 0;
1794 if(buffer_info->skb) {
1795 dev_kfree_skb_any(buffer_info->skb);
1796 buffer_info->skb = NULL;
1801 * e1000_clean_tx_ring - Free Tx Buffers
1802 * @adapter: board private structure
1803 * @tx_ring: ring to be cleaned
1807 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1808 struct e1000_tx_ring *tx_ring)
1810 struct e1000_buffer *buffer_info;
1814 /* Free all the Tx ring sk_buffs */
1816 for(i = 0; i < tx_ring->count; i++) {
1817 buffer_info = &tx_ring->buffer_info[i];
1818 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1821 size = sizeof(struct e1000_buffer) * tx_ring->count;
1822 memset(tx_ring->buffer_info, 0, size);
1824 /* Zero out the descriptor ring */
1826 memset(tx_ring->desc, 0, tx_ring->size);
1828 tx_ring->next_to_use = 0;
1829 tx_ring->next_to_clean = 0;
1830 tx_ring->last_tx_tso = 0;
1832 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1833 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1837 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1838 * @adapter: board private structure
1842 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1846 for (i = 0; i < adapter->num_queues; i++)
1847 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1851 * e1000_free_rx_resources - Free Rx Resources
1852 * @adapter: board private structure
1853 * @rx_ring: ring to clean the resources from
1855 * Free all receive software resources
1859 e1000_free_rx_resources(struct e1000_adapter *adapter,
1860 struct e1000_rx_ring *rx_ring)
1862 struct pci_dev *pdev = adapter->pdev;
1864 e1000_clean_rx_ring(adapter, rx_ring);
1866 vfree(rx_ring->buffer_info);
1867 rx_ring->buffer_info = NULL;
1868 kfree(rx_ring->ps_page);
1869 rx_ring->ps_page = NULL;
1870 kfree(rx_ring->ps_page_dma);
1871 rx_ring->ps_page_dma = NULL;
1873 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1875 rx_ring->desc = NULL;
1879 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1880 * @adapter: board private structure
1882 * Free all receive software resources
1886 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1890 for (i = 0; i < adapter->num_queues; i++)
1891 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1895 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1896 * @adapter: board private structure
1897 * @rx_ring: ring to free buffers from
1901 e1000_clean_rx_ring(struct e1000_adapter *adapter,
1902 struct e1000_rx_ring *rx_ring)
1904 struct e1000_buffer *buffer_info;
1905 struct e1000_ps_page *ps_page;
1906 struct e1000_ps_page_dma *ps_page_dma;
1907 struct pci_dev *pdev = adapter->pdev;
1911 /* Free all the Rx ring sk_buffs */
1913 for(i = 0; i < rx_ring->count; i++) {
1914 buffer_info = &rx_ring->buffer_info[i];
1915 if(buffer_info->skb) {
1916 ps_page = &rx_ring->ps_page[i];
1917 ps_page_dma = &rx_ring->ps_page_dma[i];
1918 pci_unmap_single(pdev,
1920 buffer_info->length,
1921 PCI_DMA_FROMDEVICE);
1923 dev_kfree_skb(buffer_info->skb);
1924 buffer_info->skb = NULL;
1926 for(j = 0; j < adapter->rx_ps_pages; j++) {
1927 if(!ps_page->ps_page[j]) break;
1928 pci_unmap_single(pdev,
1929 ps_page_dma->ps_page_dma[j],
1930 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1931 ps_page_dma->ps_page_dma[j] = 0;
1932 put_page(ps_page->ps_page[j]);
1933 ps_page->ps_page[j] = NULL;
1938 size = sizeof(struct e1000_buffer) * rx_ring->count;
1939 memset(rx_ring->buffer_info, 0, size);
1940 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1941 memset(rx_ring->ps_page, 0, size);
1942 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1943 memset(rx_ring->ps_page_dma, 0, size);
1945 /* Zero out the descriptor ring */
1947 memset(rx_ring->desc, 0, rx_ring->size);
1949 rx_ring->next_to_clean = 0;
1950 rx_ring->next_to_use = 0;
1952 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1953 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1957 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1958 * @adapter: board private structure
1962 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1966 for (i = 0; i < adapter->num_queues; i++)
1967 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1970 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1971 * and memory write and invalidate disabled for certain operations
1974 e1000_enter_82542_rst(struct e1000_adapter *adapter)
1976 struct net_device *netdev = adapter->netdev;
1979 e1000_pci_clear_mwi(&adapter->hw);
1981 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1982 rctl |= E1000_RCTL_RST;
1983 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1984 E1000_WRITE_FLUSH(&adapter->hw);
1987 if(netif_running(netdev))
1988 e1000_clean_all_rx_rings(adapter);
1992 e1000_leave_82542_rst(struct e1000_adapter *adapter)
1994 struct net_device *netdev = adapter->netdev;
1997 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1998 rctl &= ~E1000_RCTL_RST;
1999 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2000 E1000_WRITE_FLUSH(&adapter->hw);
2003 if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2004 e1000_pci_set_mwi(&adapter->hw);
2006 if(netif_running(netdev)) {
2007 e1000_configure_rx(adapter);
2008 e1000_alloc_rx_buffers(adapter, &adapter->rx_ring[0]);
2013 * e1000_set_mac - Change the Ethernet Address of the NIC
2014 * @netdev: network interface device structure
2015 * @p: pointer to an address structure
2017 * Returns 0 on success, negative on failure
2021 e1000_set_mac(struct net_device *netdev, void *p)
2023 struct e1000_adapter *adapter = netdev_priv(netdev);
2024 struct sockaddr *addr = p;
2026 if(!is_valid_ether_addr(addr->sa_data))
2027 return -EADDRNOTAVAIL;
2029 /* 82542 2.0 needs to be in reset to write receive address registers */
2031 if(adapter->hw.mac_type == e1000_82542_rev2_0)
2032 e1000_enter_82542_rst(adapter);
2034 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2035 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2037 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2039 /* With 82571 controllers, LAA may be overwritten (with the default)
2040 * due to controller reset from the other port. */
2041 if (adapter->hw.mac_type == e1000_82571) {
2042 /* activate the work around */
2043 adapter->hw.laa_is_present = 1;
2045 /* Hold a copy of the LAA in RAR[14] This is done so that
2046 * between the time RAR[0] gets clobbered and the time it
2047 * gets fixed (in e1000_watchdog), the actual LAA is in one
2048 * of the RARs and no incoming packets directed to this port
2049 * are dropped. Eventaully the LAA will be in RAR[0] and
2051 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2052 E1000_RAR_ENTRIES - 1);
2055 if(adapter->hw.mac_type == e1000_82542_rev2_0)
2056 e1000_leave_82542_rst(adapter);
2062 * e1000_set_multi - Multicast and Promiscuous mode set
2063 * @netdev: network interface device structure
2065 * The set_multi entry point is called whenever the multicast address
2066 * list or the network interface flags are updated. This routine is
2067 * responsible for configuring the hardware for proper multicast,
2068 * promiscuous mode, and all-multi behavior.
2072 e1000_set_multi(struct net_device *netdev)
2074 struct e1000_adapter *adapter = netdev_priv(netdev);
2075 struct e1000_hw *hw = &adapter->hw;
2076 struct dev_mc_list *mc_ptr;
2078 uint32_t hash_value;
2079 int i, rar_entries = E1000_RAR_ENTRIES;
2081 /* reserve RAR[14] for LAA over-write work-around */
2082 if (adapter->hw.mac_type == e1000_82571)
2085 /* Check for Promiscuous and All Multicast modes */
2087 rctl = E1000_READ_REG(hw, RCTL);
2089 if(netdev->flags & IFF_PROMISC) {
2090 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2091 } else if(netdev->flags & IFF_ALLMULTI) {
2092 rctl |= E1000_RCTL_MPE;
2093 rctl &= ~E1000_RCTL_UPE;
2095 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2098 E1000_WRITE_REG(hw, RCTL, rctl);
2100 /* 82542 2.0 needs to be in reset to write receive address registers */
2102 if(hw->mac_type == e1000_82542_rev2_0)
2103 e1000_enter_82542_rst(adapter);
2105 /* load the first 14 multicast address into the exact filters 1-14
2106 * RAR 0 is used for the station MAC adddress
2107 * if there are not 14 addresses, go ahead and clear the filters
2108 * -- with 82571 controllers only 0-13 entries are filled here
2110 mc_ptr = netdev->mc_list;
2112 for(i = 1; i < rar_entries; i++) {
2114 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2115 mc_ptr = mc_ptr->next;
2117 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2118 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2122 /* clear the old settings from the multicast hash table */
2124 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2125 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2127 /* load any remaining addresses into the hash table */
2129 for(; mc_ptr; mc_ptr = mc_ptr->next) {
2130 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2131 e1000_mta_set(hw, hash_value);
2134 if(hw->mac_type == e1000_82542_rev2_0)
2135 e1000_leave_82542_rst(adapter);
2138 /* Need to wait a few seconds after link up to get diagnostic information from
2142 e1000_update_phy_info(unsigned long data)
2144 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2145 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2149 * e1000_82547_tx_fifo_stall - Timer Call-back
2150 * @data: pointer to adapter cast into an unsigned long
2154 e1000_82547_tx_fifo_stall(unsigned long data)
2156 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2157 struct net_device *netdev = adapter->netdev;
2160 if(atomic_read(&adapter->tx_fifo_stall)) {
2161 if((E1000_READ_REG(&adapter->hw, TDT) ==
2162 E1000_READ_REG(&adapter->hw, TDH)) &&
2163 (E1000_READ_REG(&adapter->hw, TDFT) ==
2164 E1000_READ_REG(&adapter->hw, TDFH)) &&
2165 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2166 E1000_READ_REG(&adapter->hw, TDFHS))) {
2167 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2168 E1000_WRITE_REG(&adapter->hw, TCTL,
2169 tctl & ~E1000_TCTL_EN);
2170 E1000_WRITE_REG(&adapter->hw, TDFT,
2171 adapter->tx_head_addr);
2172 E1000_WRITE_REG(&adapter->hw, TDFH,
2173 adapter->tx_head_addr);
2174 E1000_WRITE_REG(&adapter->hw, TDFTS,
2175 adapter->tx_head_addr);
2176 E1000_WRITE_REG(&adapter->hw, TDFHS,
2177 adapter->tx_head_addr);
2178 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2179 E1000_WRITE_FLUSH(&adapter->hw);
2181 adapter->tx_fifo_head = 0;
2182 atomic_set(&adapter->tx_fifo_stall, 0);
2183 netif_wake_queue(netdev);
2185 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2191 * e1000_watchdog - Timer Call-back
2192 * @data: pointer to adapter cast into an unsigned long
2195 e1000_watchdog(unsigned long data)
2197 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2199 /* Do the rest outside of interrupt context */
2200 schedule_work(&adapter->watchdog_task);
2204 e1000_watchdog_task(struct e1000_adapter *adapter)
2206 struct net_device *netdev = adapter->netdev;
2207 struct e1000_tx_ring *txdr = adapter->tx_ring;
2210 e1000_check_for_link(&adapter->hw);
2211 if (adapter->hw.mac_type == e1000_82573) {
2212 e1000_enable_tx_pkt_filtering(&adapter->hw);
2213 if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2214 e1000_update_mng_vlan(adapter);
2217 if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2218 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2219 link = !adapter->hw.serdes_link_down;
2221 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2224 if(!netif_carrier_ok(netdev)) {
2225 e1000_get_speed_and_duplex(&adapter->hw,
2226 &adapter->link_speed,
2227 &adapter->link_duplex);
2229 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2230 adapter->link_speed,
2231 adapter->link_duplex == FULL_DUPLEX ?
2232 "Full Duplex" : "Half Duplex");
2234 netif_carrier_on(netdev);
2235 netif_wake_queue(netdev);
2236 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2237 adapter->smartspeed = 0;
2240 if(netif_carrier_ok(netdev)) {
2241 adapter->link_speed = 0;
2242 adapter->link_duplex = 0;
2243 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2244 netif_carrier_off(netdev);
2245 netif_stop_queue(netdev);
2246 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2249 e1000_smartspeed(adapter);
2252 e1000_update_stats(adapter);
2254 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2255 adapter->tpt_old = adapter->stats.tpt;
2256 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2257 adapter->colc_old = adapter->stats.colc;
2259 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2260 adapter->gorcl_old = adapter->stats.gorcl;
2261 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2262 adapter->gotcl_old = adapter->stats.gotcl;
2264 e1000_update_adaptive(&adapter->hw);
2266 if (adapter->num_queues == 1 && !netif_carrier_ok(netdev)) {
2267 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2268 /* We've lost link, so the controller stops DMA,
2269 * but we've got queued Tx work that's never going
2270 * to get done, so reset controller to flush Tx.
2271 * (Do the reset outside of interrupt context). */
2272 schedule_work(&adapter->tx_timeout_task);
2276 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2277 if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2278 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2279 * asymmetrical Tx or Rx gets ITR=8000; everyone
2280 * else is between 2000-8000. */
2281 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2282 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2283 adapter->gotcl - adapter->gorcl :
2284 adapter->gorcl - adapter->gotcl) / 10000;
2285 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2286 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2289 /* Cause software interrupt to ensure rx ring is cleaned */
2290 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2292 /* Force detection of hung controller every watchdog period */
2293 adapter->detect_tx_hung = TRUE;
2295 /* With 82571 controllers, LAA may be overwritten due to controller
2296 * reset from the other port. Set the appropriate LAA in RAR[0] */
2297 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2298 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2300 /* Reset the timer */
2301 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2304 #define E1000_TX_FLAGS_CSUM 0x00000001
2305 #define E1000_TX_FLAGS_VLAN 0x00000002
2306 #define E1000_TX_FLAGS_TSO 0x00000004
2307 #define E1000_TX_FLAGS_IPV4 0x00000008
2308 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2309 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2312 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2313 struct sk_buff *skb)
2316 struct e1000_context_desc *context_desc;
2317 struct e1000_buffer *buffer_info;
2319 uint32_t cmd_length = 0;
2320 uint16_t ipcse = 0, tucse, mss;
2321 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2324 if(skb_shinfo(skb)->tso_size) {
2325 if (skb_header_cloned(skb)) {
2326 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2331 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2332 mss = skb_shinfo(skb)->tso_size;
2333 if(skb->protocol == ntohs(ETH_P_IP)) {
2334 skb->nh.iph->tot_len = 0;
2335 skb->nh.iph->check = 0;
2337 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2342 cmd_length = E1000_TXD_CMD_IP;
2343 ipcse = skb->h.raw - skb->data - 1;
2344 #ifdef NETIF_F_TSO_IPV6
2345 } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
2346 skb->nh.ipv6h->payload_len = 0;
2348 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2349 &skb->nh.ipv6h->daddr,
2356 ipcss = skb->nh.raw - skb->data;
2357 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2358 tucss = skb->h.raw - skb->data;
2359 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2362 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2363 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2365 i = tx_ring->next_to_use;
2366 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2367 buffer_info = &tx_ring->buffer_info[i];
2369 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2370 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2371 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2372 context_desc->upper_setup.tcp_fields.tucss = tucss;
2373 context_desc->upper_setup.tcp_fields.tucso = tucso;
2374 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2375 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2376 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2377 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2379 buffer_info->time_stamp = jiffies;
2381 if (++i == tx_ring->count) i = 0;
2382 tx_ring->next_to_use = i;
2391 static inline boolean_t
2392 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2393 struct sk_buff *skb)
2395 struct e1000_context_desc *context_desc;
2396 struct e1000_buffer *buffer_info;
2400 if(likely(skb->ip_summed == CHECKSUM_HW)) {
2401 css = skb->h.raw - skb->data;
2403 i = tx_ring->next_to_use;
2404 buffer_info = &tx_ring->buffer_info[i];
2405 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2407 context_desc->upper_setup.tcp_fields.tucss = css;
2408 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2409 context_desc->upper_setup.tcp_fields.tucse = 0;
2410 context_desc->tcp_seg_setup.data = 0;
2411 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2413 buffer_info->time_stamp = jiffies;
2415 if (unlikely(++i == tx_ring->count)) i = 0;
2416 tx_ring->next_to_use = i;
2424 #define E1000_MAX_TXD_PWR 12
2425 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2428 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2429 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2430 unsigned int nr_frags, unsigned int mss)
2432 struct e1000_buffer *buffer_info;
2433 unsigned int len = skb->len;
2434 unsigned int offset = 0, size, count = 0, i;
2436 len -= skb->data_len;
2438 i = tx_ring->next_to_use;
2441 buffer_info = &tx_ring->buffer_info[i];
2442 size = min(len, max_per_txd);
2444 /* Workaround for Controller erratum --
2445 * descriptor for non-tso packet in a linear SKB that follows a
2446 * tso gets written back prematurely before the data is fully
2447 * DMAd to the controller */
2448 if (!skb->data_len && tx_ring->last_tx_tso &&
2449 !skb_shinfo(skb)->tso_size) {
2450 tx_ring->last_tx_tso = 0;
2454 /* Workaround for premature desc write-backs
2455 * in TSO mode. Append 4-byte sentinel desc */
2456 if(unlikely(mss && !nr_frags && size == len && size > 8))
2459 /* work-around for errata 10 and it applies
2460 * to all controllers in PCI-X mode
2461 * The fix is to make sure that the first descriptor of a
2462 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2464 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2465 (size > 2015) && count == 0))
2468 /* Workaround for potential 82544 hang in PCI-X. Avoid
2469 * terminating buffers within evenly-aligned dwords. */
2470 if(unlikely(adapter->pcix_82544 &&
2471 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2475 buffer_info->length = size;
2477 pci_map_single(adapter->pdev,
2481 buffer_info->time_stamp = jiffies;
2486 if(unlikely(++i == tx_ring->count)) i = 0;
2489 for(f = 0; f < nr_frags; f++) {
2490 struct skb_frag_struct *frag;
2492 frag = &skb_shinfo(skb)->frags[f];
2494 offset = frag->page_offset;
2497 buffer_info = &tx_ring->buffer_info[i];
2498 size = min(len, max_per_txd);
2500 /* Workaround for premature desc write-backs
2501 * in TSO mode. Append 4-byte sentinel desc */
2502 if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2505 /* Workaround for potential 82544 hang in PCI-X.
2506 * Avoid terminating buffers within evenly-aligned
2508 if(unlikely(adapter->pcix_82544 &&
2509 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2513 buffer_info->length = size;
2515 pci_map_page(adapter->pdev,
2520 buffer_info->time_stamp = jiffies;
2525 if(unlikely(++i == tx_ring->count)) i = 0;
2529 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2530 tx_ring->buffer_info[i].skb = skb;
2531 tx_ring->buffer_info[first].next_to_watch = i;
2537 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2538 int tx_flags, int count)
2540 struct e1000_tx_desc *tx_desc = NULL;
2541 struct e1000_buffer *buffer_info;
2542 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2545 if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2546 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2548 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2550 if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
2551 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2554 if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2555 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2556 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2559 if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2560 txd_lower |= E1000_TXD_CMD_VLE;
2561 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2564 i = tx_ring->next_to_use;
2567 buffer_info = &tx_ring->buffer_info[i];
2568 tx_desc = E1000_TX_DESC(*tx_ring, i);
2569 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2570 tx_desc->lower.data =
2571 cpu_to_le32(txd_lower | buffer_info->length);
2572 tx_desc->upper.data = cpu_to_le32(txd_upper);
2573 if(unlikely(++i == tx_ring->count)) i = 0;
2576 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2578 /* Force memory writes to complete before letting h/w
2579 * know there are new descriptors to fetch. (Only
2580 * applicable for weak-ordered memory model archs,
2581 * such as IA-64). */
2584 tx_ring->next_to_use = i;
2585 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2589 * 82547 workaround to avoid controller hang in half-duplex environment.
2590 * The workaround is to avoid queuing a large packet that would span
2591 * the internal Tx FIFO ring boundary by notifying the stack to resend
2592 * the packet at a later time. This gives the Tx FIFO an opportunity to
2593 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2594 * to the beginning of the Tx FIFO.
2597 #define E1000_FIFO_HDR 0x10
2598 #define E1000_82547_PAD_LEN 0x3E0
2601 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2603 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2604 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2606 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2608 if(adapter->link_duplex != HALF_DUPLEX)
2609 goto no_fifo_stall_required;
2611 if(atomic_read(&adapter->tx_fifo_stall))
2614 if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2615 atomic_set(&adapter->tx_fifo_stall, 1);
2619 no_fifo_stall_required:
2620 adapter->tx_fifo_head += skb_fifo_len;
2621 if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
2622 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2626 #define MINIMUM_DHCP_PACKET_SIZE 282
2628 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2630 struct e1000_hw *hw = &adapter->hw;
2631 uint16_t length, offset;
2632 if(vlan_tx_tag_present(skb)) {
2633 if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2634 ( adapter->hw.mng_cookie.status &
2635 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2638 if ((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
2639 struct ethhdr *eth = (struct ethhdr *) skb->data;
2640 if((htons(ETH_P_IP) == eth->h_proto)) {
2641 const struct iphdr *ip =
2642 (struct iphdr *)((uint8_t *)skb->data+14);
2643 if(IPPROTO_UDP == ip->protocol) {
2644 struct udphdr *udp =
2645 (struct udphdr *)((uint8_t *)ip +
2647 if(ntohs(udp->dest) == 67) {
2648 offset = (uint8_t *)udp + 8 - skb->data;
2649 length = skb->len - offset;
2651 return e1000_mng_write_dhcp_info(hw,
2661 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2663 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2665 struct e1000_adapter *adapter = netdev_priv(netdev);
2666 struct e1000_tx_ring *tx_ring;
2667 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2668 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2669 unsigned int tx_flags = 0;
2670 unsigned int len = skb->len;
2671 unsigned long flags;
2672 unsigned int nr_frags = 0;
2673 unsigned int mss = 0;
2677 len -= skb->data_len;
2679 #ifdef CONFIG_E1000_MQ
2680 tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2682 tx_ring = adapter->tx_ring;
2685 if (unlikely(skb->len <= 0)) {
2686 dev_kfree_skb_any(skb);
2687 return NETDEV_TX_OK;
2691 mss = skb_shinfo(skb)->tso_size;
2692 /* The controller does a simple calculation to
2693 * make sure there is enough room in the FIFO before
2694 * initiating the DMA for each buffer. The calc is:
2695 * 4 = ceil(buffer len/mss). To make sure we don't
2696 * overrun the FIFO, adjust the max buffer len if mss
2700 max_per_txd = min(mss << 2, max_per_txd);
2701 max_txd_pwr = fls(max_per_txd) - 1;
2703 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2704 * points to just header, pull a few bytes of payload from
2705 * frags into skb->data */
2706 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2707 if (skb->data_len && (hdr_len == (skb->len - skb->data_len)) &&
2708 (adapter->hw.mac_type == e1000_82571 ||
2709 adapter->hw.mac_type == e1000_82572)) {
2710 len = skb->len - skb->data_len;
2714 if((mss) || (skb->ip_summed == CHECKSUM_HW))
2715 /* reserve a descriptor for the offload context */
2719 if(skb->ip_summed == CHECKSUM_HW)
2724 /* Controller Erratum workaround */
2725 if (!skb->data_len && tx_ring->last_tx_tso &&
2726 !skb_shinfo(skb)->tso_size)
2730 count += TXD_USE_COUNT(len, max_txd_pwr);
2732 if(adapter->pcix_82544)
2735 /* work-around for errata 10 and it applies to all controllers
2736 * in PCI-X mode, so add one more descriptor to the count
2738 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2742 nr_frags = skb_shinfo(skb)->nr_frags;
2743 for(f = 0; f < nr_frags; f++)
2744 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2746 if(adapter->pcix_82544)
2749 unsigned int pull_size;
2750 pull_size = min((unsigned int)4, skb->data_len);
2751 if (!__pskb_pull_tail(skb, pull_size)) {
2752 printk(KERN_ERR "__pskb_pull_tail failed.\n");
2753 dev_kfree_skb_any(skb);
2757 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2758 e1000_transfer_dhcp_info(adapter, skb);
2760 local_irq_save(flags);
2761 if (!spin_trylock(&tx_ring->tx_lock)) {
2762 /* Collision - tell upper layer to requeue */
2763 local_irq_restore(flags);
2764 return NETDEV_TX_LOCKED;
2767 /* need: count + 2 desc gap to keep tail from touching
2768 * head, otherwise try next time */
2769 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2770 netif_stop_queue(netdev);
2771 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2772 return NETDEV_TX_BUSY;
2775 if(unlikely(adapter->hw.mac_type == e1000_82547)) {
2776 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2777 netif_stop_queue(netdev);
2778 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2779 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2780 return NETDEV_TX_BUSY;
2784 if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2785 tx_flags |= E1000_TX_FLAGS_VLAN;
2786 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2789 first = tx_ring->next_to_use;
2791 tso = e1000_tso(adapter, tx_ring, skb);
2793 dev_kfree_skb_any(skb);
2794 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2795 return NETDEV_TX_OK;
2799 tx_ring->last_tx_tso = 1;
2800 tx_flags |= E1000_TX_FLAGS_TSO;
2801 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
2802 tx_flags |= E1000_TX_FLAGS_CSUM;
2804 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2805 * 82571 hardware supports TSO capabilities for IPv6 as well...
2806 * no longer assume, we must. */
2807 if (likely(skb->protocol == ntohs(ETH_P_IP)))
2808 tx_flags |= E1000_TX_FLAGS_IPV4;
2810 e1000_tx_queue(adapter, tx_ring, tx_flags,
2811 e1000_tx_map(adapter, tx_ring, skb, first,
2812 max_per_txd, nr_frags, mss));
2814 netdev->trans_start = jiffies;
2816 /* Make sure there is space in the ring for the next send. */
2817 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
2818 netif_stop_queue(netdev);
2820 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2821 return NETDEV_TX_OK;
2825 * e1000_tx_timeout - Respond to a Tx Hang
2826 * @netdev: network interface device structure
2830 e1000_tx_timeout(struct net_device *netdev)
2832 struct e1000_adapter *adapter = netdev_priv(netdev);
2834 /* Do the reset outside of interrupt context */
2835 schedule_work(&adapter->tx_timeout_task);
2839 e1000_tx_timeout_task(struct net_device *netdev)
2841 struct e1000_adapter *adapter = netdev_priv(netdev);
2843 e1000_down(adapter);
2848 * e1000_get_stats - Get System Network Statistics
2849 * @netdev: network interface device structure
2851 * Returns the address of the device statistics structure.
2852 * The statistics are actually updated from the timer callback.
2855 static struct net_device_stats *
2856 e1000_get_stats(struct net_device *netdev)
2858 struct e1000_adapter *adapter = netdev_priv(netdev);
2860 e1000_update_stats(adapter);
2861 return &adapter->net_stats;
2865 * e1000_change_mtu - Change the Maximum Transfer Unit
2866 * @netdev: network interface device structure
2867 * @new_mtu: new value for maximum frame size
2869 * Returns 0 on success, negative on failure
2873 e1000_change_mtu(struct net_device *netdev, int new_mtu)
2875 struct e1000_adapter *adapter = netdev_priv(netdev);
2876 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2878 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2879 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2880 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2884 #define MAX_STD_JUMBO_FRAME_SIZE 9234
2885 /* might want this to be bigger enum check... */
2886 /* 82571 controllers limit jumbo frame size to 10500 bytes */
2887 if ((adapter->hw.mac_type == e1000_82571 ||
2888 adapter->hw.mac_type == e1000_82572) &&
2889 max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
2890 DPRINTK(PROBE, ERR, "MTU > 9216 bytes not supported "
2891 "on 82571 and 82572 controllers.\n");
2895 if(adapter->hw.mac_type == e1000_82573 &&
2896 max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2897 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2902 if(adapter->hw.mac_type > e1000_82547_rev_2) {
2903 adapter->rx_buffer_len = max_frame;
2904 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
2906 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
2907 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
2908 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2913 if(max_frame <= E1000_RXBUFFER_2048) {
2914 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
2915 } else if(max_frame <= E1000_RXBUFFER_4096) {
2916 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
2917 } else if(max_frame <= E1000_RXBUFFER_8192) {
2918 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
2919 } else if(max_frame <= E1000_RXBUFFER_16384) {
2920 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
2925 netdev->mtu = new_mtu;
2927 if(netif_running(netdev)) {
2928 e1000_down(adapter);
2932 adapter->hw.max_frame_size = max_frame;
2938 * e1000_update_stats - Update the board statistics counters
2939 * @adapter: board private structure
2943 e1000_update_stats(struct e1000_adapter *adapter)
2945 struct e1000_hw *hw = &adapter->hw;
2946 unsigned long flags;
2949 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2951 spin_lock_irqsave(&adapter->stats_lock, flags);
2953 /* these counters are modified from e1000_adjust_tbi_stats,
2954 * called from the interrupt context, so they must only
2955 * be written while holding adapter->stats_lock
2958 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
2959 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
2960 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
2961 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
2962 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
2963 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
2964 adapter->stats.roc += E1000_READ_REG(hw, ROC);
2965 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
2966 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
2967 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
2968 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
2969 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
2970 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
2972 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
2973 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
2974 adapter->stats.scc += E1000_READ_REG(hw, SCC);
2975 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
2976 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
2977 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
2978 adapter->stats.dc += E1000_READ_REG(hw, DC);
2979 adapter->stats.sec += E1000_READ_REG(hw, SEC);
2980 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
2981 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
2982 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
2983 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
2984 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
2985 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
2986 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
2987 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
2988 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
2989 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
2990 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
2991 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
2992 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
2993 adapter->stats.torl += E1000_READ_REG(hw, TORL);
2994 adapter->stats.torh += E1000_READ_REG(hw, TORH);
2995 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
2996 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
2997 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
2998 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
2999 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3000 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3001 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3002 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3003 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3004 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3005 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3007 /* used for adaptive IFS */
3009 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3010 adapter->stats.tpt += hw->tx_packet_delta;
3011 hw->collision_delta = E1000_READ_REG(hw, COLC);
3012 adapter->stats.colc += hw->collision_delta;
3014 if(hw->mac_type >= e1000_82543) {
3015 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3016 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3017 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3018 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3019 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3020 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3022 if(hw->mac_type > e1000_82547_rev_2) {
3023 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3024 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3025 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3026 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3027 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3028 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3029 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3030 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3031 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3034 /* Fill out the OS statistics structure */
3036 adapter->net_stats.rx_packets = adapter->stats.gprc;
3037 adapter->net_stats.tx_packets = adapter->stats.gptc;
3038 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3039 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3040 adapter->net_stats.multicast = adapter->stats.mprc;
3041 adapter->net_stats.collisions = adapter->stats.colc;
3045 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3046 adapter->stats.crcerrs + adapter->stats.algnerrc +
3047 adapter->stats.rlec + adapter->stats.mpc +
3048 adapter->stats.cexterr;
3049 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3050 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3051 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3052 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
3053 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3057 adapter->net_stats.tx_errors = adapter->stats.ecol +
3058 adapter->stats.latecol;
3059 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3060 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3061 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3063 /* Tx Dropped needs to be maintained elsewhere */
3067 if(hw->media_type == e1000_media_type_copper) {
3068 if((adapter->link_speed == SPEED_1000) &&
3069 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3070 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3071 adapter->phy_stats.idle_errors += phy_tmp;
3074 if((hw->mac_type <= e1000_82546) &&
3075 (hw->phy_type == e1000_phy_m88) &&
3076 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3077 adapter->phy_stats.receive_errors += phy_tmp;
3080 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3083 #ifdef CONFIG_E1000_MQ
3085 e1000_rx_schedule(void *data)
3087 struct net_device *poll_dev, *netdev = data;
3088 struct e1000_adapter *adapter = netdev->priv;
3089 int this_cpu = get_cpu();
3091 poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
3092 if (poll_dev == NULL) {
3097 if (likely(netif_rx_schedule_prep(poll_dev)))
3098 __netif_rx_schedule(poll_dev);
3100 e1000_irq_enable(adapter);
3107 * e1000_intr - Interrupt Handler
3108 * @irq: interrupt number
3109 * @data: pointer to a network interface device structure
3110 * @pt_regs: CPU registers structure
3114 e1000_intr(int irq, void *data, struct pt_regs *regs)
3116 struct net_device *netdev = data;
3117 struct e1000_adapter *adapter = netdev_priv(netdev);
3118 struct e1000_hw *hw = &adapter->hw;
3119 uint32_t icr = E1000_READ_REG(hw, ICR);
3120 #if defined(CONFIG_E1000_NAPI) && defined(CONFIG_E1000_MQ) || !defined(CONFIG_E1000_NAPI)
3125 return IRQ_NONE; /* Not our interrupt */
3127 if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3128 hw->get_link_status = 1;
3129 mod_timer(&adapter->watchdog_timer, jiffies);
3132 #ifdef CONFIG_E1000_NAPI
3133 atomic_inc(&adapter->irq_sem);
3134 E1000_WRITE_REG(hw, IMC, ~0);
3135 E1000_WRITE_FLUSH(hw);
3136 #ifdef CONFIG_E1000_MQ
3137 if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
3138 cpu_set(adapter->cpu_for_queue[0],
3139 adapter->rx_sched_call_data.cpumask);
3140 for (i = 1; i < adapter->num_queues; i++) {
3141 cpu_set(adapter->cpu_for_queue[i],
3142 adapter->rx_sched_call_data.cpumask);
3143 atomic_inc(&adapter->irq_sem);
3145 atomic_set(&adapter->rx_sched_call_data.count, i);
3146 smp_call_async_mask(&adapter->rx_sched_call_data);
3148 printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
3150 #else /* if !CONFIG_E1000_MQ */
3151 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3152 __netif_rx_schedule(&adapter->polling_netdev[0]);
3154 e1000_irq_enable(adapter);
3155 #endif /* CONFIG_E1000_MQ */
3157 #else /* if !CONFIG_E1000_NAPI */
3158 /* Writing IMC and IMS is needed for 82547.
3159 Due to Hub Link bus being occupied, an interrupt
3160 de-assertion message is not able to be sent.
3161 When an interrupt assertion message is generated later,
3162 two messages are re-ordered and sent out.
3163 That causes APIC to think 82547 is in de-assertion
3164 state, while 82547 is in assertion state, resulting
3165 in dead lock. Writing IMC forces 82547 into
3168 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
3169 atomic_inc(&adapter->irq_sem);
3170 E1000_WRITE_REG(hw, IMC, ~0);
3173 for(i = 0; i < E1000_MAX_INTR; i++)
3174 if(unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3175 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3178 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3179 e1000_irq_enable(adapter);
3181 #endif /* CONFIG_E1000_NAPI */
3186 #ifdef CONFIG_E1000_NAPI
3188 * e1000_clean - NAPI Rx polling callback
3189 * @adapter: board private structure
3193 e1000_clean(struct net_device *poll_dev, int *budget)
3195 struct e1000_adapter *adapter;
3196 int work_to_do = min(*budget, poll_dev->quota);
3197 int tx_cleaned, i = 0, work_done = 0;
3199 /* Must NOT use netdev_priv macro here. */
3200 adapter = poll_dev->priv;
3202 /* Keep link state information with original netdev */
3203 if (!netif_carrier_ok(adapter->netdev))
3206 while (poll_dev != &adapter->polling_netdev[i]) {
3208 if (unlikely(i == adapter->num_queues))
3212 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3213 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3214 &work_done, work_to_do);
3216 *budget -= work_done;
3217 poll_dev->quota -= work_done;
3219 /* If no Tx and not enough Rx work done, exit the polling mode */
3220 if((!tx_cleaned && (work_done == 0)) ||
3221 !netif_running(adapter->netdev)) {
3223 netif_rx_complete(poll_dev);
3224 e1000_irq_enable(adapter);
3233 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3234 * @adapter: board private structure
3238 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3239 struct e1000_tx_ring *tx_ring)
3241 struct net_device *netdev = adapter->netdev;
3242 struct e1000_tx_desc *tx_desc, *eop_desc;
3243 struct e1000_buffer *buffer_info;
3244 unsigned int i, eop;
3245 boolean_t cleaned = FALSE;
3247 i = tx_ring->next_to_clean;
3248 eop = tx_ring->buffer_info[i].next_to_watch;
3249 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3251 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3252 for(cleaned = FALSE; !cleaned; ) {
3253 tx_desc = E1000_TX_DESC(*tx_ring, i);
3254 buffer_info = &tx_ring->buffer_info[i];
3255 cleaned = (i == eop);
3257 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3259 tx_desc->buffer_addr = 0;
3260 tx_desc->lower.data = 0;
3261 tx_desc->upper.data = 0;
3263 if(unlikely(++i == tx_ring->count)) i = 0;
3266 eop = tx_ring->buffer_info[i].next_to_watch;
3267 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3270 tx_ring->next_to_clean = i;
3272 spin_lock(&tx_ring->tx_lock);
3274 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
3275 netif_carrier_ok(netdev)))
3276 netif_wake_queue(netdev);
3278 spin_unlock(&tx_ring->tx_lock);
3280 if (adapter->detect_tx_hung) {
3281 /* Detect a transmit hang in hardware, this serializes the
3282 * check with the clearing of time_stamp and movement of i */
3283 adapter->detect_tx_hung = FALSE;
3284 if (tx_ring->buffer_info[i].dma &&
3285 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
3286 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3287 E1000_STATUS_TXOFF)) {
3289 /* detected Tx unit hang */
3290 i = tx_ring->next_to_clean;
3291 eop = tx_ring->buffer_info[i].next_to_watch;
3292 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3293 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3296 " next_to_use <%x>\n"
3297 " next_to_clean <%x>\n"
3298 "buffer_info[next_to_clean]\n"
3300 " time_stamp <%lx>\n"
3301 " next_to_watch <%x>\n"
3303 " next_to_watch.status <%x>\n",
3304 readl(adapter->hw.hw_addr + tx_ring->tdh),
3305 readl(adapter->hw.hw_addr + tx_ring->tdt),
3306 tx_ring->next_to_use,
3308 (unsigned long long)tx_ring->buffer_info[i].dma,
3309 tx_ring->buffer_info[i].time_stamp,
3312 eop_desc->upper.fields.status);
3313 netif_stop_queue(netdev);
3320 * e1000_rx_checksum - Receive Checksum Offload for 82543
3321 * @adapter: board private structure
3322 * @status_err: receive descriptor status and error fields
3323 * @csum: receive descriptor csum field
3324 * @sk_buff: socket buffer with received data
3328 e1000_rx_checksum(struct e1000_adapter *adapter,
3329 uint32_t status_err, uint32_t csum,
3330 struct sk_buff *skb)
3332 uint16_t status = (uint16_t)status_err;
3333 uint8_t errors = (uint8_t)(status_err >> 24);
3334 skb->ip_summed = CHECKSUM_NONE;
3336 /* 82543 or newer only */
3337 if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
3338 /* Ignore Checksum bit is set */
3339 if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
3340 /* TCP/UDP checksum error bit is set */
3341 if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
3342 /* let the stack verify checksum errors */
3343 adapter->hw_csum_err++;
3346 /* TCP/UDP Checksum has not been calculated */
3347 if(adapter->hw.mac_type <= e1000_82547_rev_2) {
3348 if(!(status & E1000_RXD_STAT_TCPCS))
3351 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3354 /* It must be a TCP or UDP packet with a valid checksum */
3355 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3356 /* TCP checksum is good */
3357 skb->ip_summed = CHECKSUM_UNNECESSARY;
3358 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3359 /* IP fragment with UDP payload */
3360 /* Hardware complements the payload checksum, so we undo it
3361 * and then put the value in host order for further stack use.
3363 csum = ntohl(csum ^ 0xFFFF);
3365 skb->ip_summed = CHECKSUM_HW;
3367 adapter->hw_csum_good++;
3371 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3372 * @adapter: board private structure
3376 #ifdef CONFIG_E1000_NAPI
3377 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3378 struct e1000_rx_ring *rx_ring,
3379 int *work_done, int work_to_do)
3381 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3382 struct e1000_rx_ring *rx_ring)
3385 struct net_device *netdev = adapter->netdev;
3386 struct pci_dev *pdev = adapter->pdev;
3387 struct e1000_rx_desc *rx_desc;
3388 struct e1000_buffer *buffer_info;
3389 struct sk_buff *skb;
3390 unsigned long flags;
3394 boolean_t cleaned = FALSE;
3396 i = rx_ring->next_to_clean;
3397 rx_desc = E1000_RX_DESC(*rx_ring, i);
3399 while(rx_desc->status & E1000_RXD_STAT_DD) {
3400 buffer_info = &rx_ring->buffer_info[i];
3401 #ifdef CONFIG_E1000_NAPI
3402 if(*work_done >= work_to_do)
3408 pci_unmap_single(pdev,
3410 buffer_info->length,
3411 PCI_DMA_FROMDEVICE);
3413 skb = buffer_info->skb;
3414 length = le16_to_cpu(rx_desc->length);
3416 if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
3417 /* All receives must fit into a single buffer */
3418 E1000_DBG("%s: Receive packet consumed multiple"
3419 " buffers\n", netdev->name);
3420 dev_kfree_skb_irq(skb);
3424 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3425 last_byte = *(skb->data + length - 1);
3426 if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
3427 rx_desc->errors, length, last_byte)) {
3428 spin_lock_irqsave(&adapter->stats_lock, flags);
3429 e1000_tbi_adjust_stats(&adapter->hw,
3432 spin_unlock_irqrestore(&adapter->stats_lock,
3436 dev_kfree_skb_irq(skb);
3442 skb_put(skb, length - ETHERNET_FCS_SIZE);
3444 /* Receive Checksum Offload */
3445 e1000_rx_checksum(adapter,
3446 (uint32_t)(rx_desc->status) |
3447 ((uint32_t)(rx_desc->errors) << 24),
3448 rx_desc->csum, skb);
3449 skb->protocol = eth_type_trans(skb, netdev);
3450 #ifdef CONFIG_E1000_NAPI
3451 if(unlikely(adapter->vlgrp &&
3452 (rx_desc->status & E1000_RXD_STAT_VP))) {
3453 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3454 le16_to_cpu(rx_desc->special) &
3455 E1000_RXD_SPC_VLAN_MASK);
3457 netif_receive_skb(skb);
3459 #else /* CONFIG_E1000_NAPI */
3460 if(unlikely(adapter->vlgrp &&
3461 (rx_desc->status & E1000_RXD_STAT_VP))) {
3462 vlan_hwaccel_rx(skb, adapter->vlgrp,
3463 le16_to_cpu(rx_desc->special) &
3464 E1000_RXD_SPC_VLAN_MASK);
3468 #endif /* CONFIG_E1000_NAPI */
3469 netdev->last_rx = jiffies;
3472 rx_desc->status = 0;
3473 buffer_info->skb = NULL;
3474 if(unlikely(++i == rx_ring->count)) i = 0;
3476 rx_desc = E1000_RX_DESC(*rx_ring, i);
3478 rx_ring->next_to_clean = i;
3479 adapter->alloc_rx_buf(adapter, rx_ring);
3485 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3486 * @adapter: board private structure
3490 #ifdef CONFIG_E1000_NAPI
3491 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3492 struct e1000_rx_ring *rx_ring,
3493 int *work_done, int work_to_do)
3495 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3496 struct e1000_rx_ring *rx_ring)
3499 union e1000_rx_desc_packet_split *rx_desc;
3500 struct net_device *netdev = adapter->netdev;
3501 struct pci_dev *pdev = adapter->pdev;
3502 struct e1000_buffer *buffer_info;
3503 struct e1000_ps_page *ps_page;
3504 struct e1000_ps_page_dma *ps_page_dma;
3505 struct sk_buff *skb;
3507 uint32_t length, staterr;
3508 boolean_t cleaned = FALSE;
3510 i = rx_ring->next_to_clean;
3511 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3512 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3514 while(staterr & E1000_RXD_STAT_DD) {
3515 buffer_info = &rx_ring->buffer_info[i];
3516 ps_page = &rx_ring->ps_page[i];
3517 ps_page_dma = &rx_ring->ps_page_dma[i];
3518 #ifdef CONFIG_E1000_NAPI
3519 if(unlikely(*work_done >= work_to_do))
3524 pci_unmap_single(pdev, buffer_info->dma,
3525 buffer_info->length,
3526 PCI_DMA_FROMDEVICE);
3528 skb = buffer_info->skb;
3530 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3531 E1000_DBG("%s: Packet Split buffers didn't pick up"
3532 " the full packet\n", netdev->name);
3533 dev_kfree_skb_irq(skb);
3537 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3538 dev_kfree_skb_irq(skb);
3542 length = le16_to_cpu(rx_desc->wb.middle.length0);
3544 if(unlikely(!length)) {
3545 E1000_DBG("%s: Last part of the packet spanning"
3546 " multiple descriptors\n", netdev->name);
3547 dev_kfree_skb_irq(skb);
3552 skb_put(skb, length);
3554 for(j = 0; j < adapter->rx_ps_pages; j++) {
3555 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3558 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3559 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3560 ps_page_dma->ps_page_dma[j] = 0;
3561 skb_shinfo(skb)->frags[j].page =
3562 ps_page->ps_page[j];
3563 ps_page->ps_page[j] = NULL;
3564 skb_shinfo(skb)->frags[j].page_offset = 0;
3565 skb_shinfo(skb)->frags[j].size = length;
3566 skb_shinfo(skb)->nr_frags++;
3568 skb->data_len += length;
3571 e1000_rx_checksum(adapter, staterr,
3572 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3573 skb->protocol = eth_type_trans(skb, netdev);
3575 if(likely(rx_desc->wb.upper.header_status &
3576 E1000_RXDPS_HDRSTAT_HDRSP)) {
3577 adapter->rx_hdr_split++;
3578 #ifdef HAVE_RX_ZERO_COPY
3579 skb_shinfo(skb)->zero_copy = TRUE;
3582 #ifdef CONFIG_E1000_NAPI
3583 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3584 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3585 le16_to_cpu(rx_desc->wb.middle.vlan) &
3586 E1000_RXD_SPC_VLAN_MASK);
3588 netif_receive_skb(skb);
3590 #else /* CONFIG_E1000_NAPI */
3591 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3592 vlan_hwaccel_rx(skb, adapter->vlgrp,
3593 le16_to_cpu(rx_desc->wb.middle.vlan) &
3594 E1000_RXD_SPC_VLAN_MASK);
3598 #endif /* CONFIG_E1000_NAPI */
3599 netdev->last_rx = jiffies;
3602 rx_desc->wb.middle.status_error &= ~0xFF;
3603 buffer_info->skb = NULL;
3604 if(unlikely(++i == rx_ring->count)) i = 0;
3606 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3607 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3609 rx_ring->next_to_clean = i;
3610 adapter->alloc_rx_buf(adapter, rx_ring);
3616 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3617 * @adapter: address of board private structure
3621 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3622 struct e1000_rx_ring *rx_ring)
3624 struct net_device *netdev = adapter->netdev;
3625 struct pci_dev *pdev = adapter->pdev;
3626 struct e1000_rx_desc *rx_desc;
3627 struct e1000_buffer *buffer_info;
3628 struct sk_buff *skb;
3630 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3632 i = rx_ring->next_to_use;
3633 buffer_info = &rx_ring->buffer_info[i];
3635 while(!buffer_info->skb) {
3636 skb = dev_alloc_skb(bufsz);
3638 if(unlikely(!skb)) {
3639 /* Better luck next round */
3643 /* Fix for errata 23, can't cross 64kB boundary */
3644 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3645 struct sk_buff *oldskb = skb;
3646 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3647 "at %p\n", bufsz, skb->data);
3648 /* Try again, without freeing the previous */
3649 skb = dev_alloc_skb(bufsz);
3650 /* Failed allocation, critical failure */
3652 dev_kfree_skb(oldskb);
3656 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3659 dev_kfree_skb(oldskb);
3660 break; /* while !buffer_info->skb */
3662 /* Use new allocation */
3663 dev_kfree_skb(oldskb);
3666 /* Make buffer alignment 2 beyond a 16 byte boundary
3667 * this will result in a 16 byte aligned IP header after
3668 * the 14 byte MAC header is removed
3670 skb_reserve(skb, NET_IP_ALIGN);
3674 buffer_info->skb = skb;
3675 buffer_info->length = adapter->rx_buffer_len;
3676 buffer_info->dma = pci_map_single(pdev,
3678 adapter->rx_buffer_len,
3679 PCI_DMA_FROMDEVICE);
3681 /* Fix for errata 23, can't cross 64kB boundary */
3682 if (!e1000_check_64k_bound(adapter,
3683 (void *)(unsigned long)buffer_info->dma,
3684 adapter->rx_buffer_len)) {
3685 DPRINTK(RX_ERR, ERR,
3686 "dma align check failed: %u bytes at %p\n",
3687 adapter->rx_buffer_len,
3688 (void *)(unsigned long)buffer_info->dma);
3690 buffer_info->skb = NULL;
3692 pci_unmap_single(pdev, buffer_info->dma,
3693 adapter->rx_buffer_len,
3694 PCI_DMA_FROMDEVICE);
3696 break; /* while !buffer_info->skb */
3698 rx_desc = E1000_RX_DESC(*rx_ring, i);
3699 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3701 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3702 /* Force memory writes to complete before letting h/w
3703 * know there are new descriptors to fetch. (Only
3704 * applicable for weak-ordered memory model archs,
3705 * such as IA-64). */
3707 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3710 if(unlikely(++i == rx_ring->count)) i = 0;
3711 buffer_info = &rx_ring->buffer_info[i];
3714 rx_ring->next_to_use = i;
3718 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3719 * @adapter: address of board private structure
3723 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3724 struct e1000_rx_ring *rx_ring)
3726 struct net_device *netdev = adapter->netdev;
3727 struct pci_dev *pdev = adapter->pdev;
3728 union e1000_rx_desc_packet_split *rx_desc;
3729 struct e1000_buffer *buffer_info;
3730 struct e1000_ps_page *ps_page;
3731 struct e1000_ps_page_dma *ps_page_dma;
3732 struct sk_buff *skb;
3735 i = rx_ring->next_to_use;
3736 buffer_info = &rx_ring->buffer_info[i];
3737 ps_page = &rx_ring->ps_page[i];
3738 ps_page_dma = &rx_ring->ps_page_dma[i];
3740 while(!buffer_info->skb) {
3741 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3743 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3744 if (j < adapter->rx_ps_pages) {
3745 if (likely(!ps_page->ps_page[j])) {
3746 ps_page->ps_page[j] =
3747 alloc_page(GFP_ATOMIC);
3748 if (unlikely(!ps_page->ps_page[j]))
3750 ps_page_dma->ps_page_dma[j] =
3752 ps_page->ps_page[j],
3754 PCI_DMA_FROMDEVICE);
3756 /* Refresh the desc even if buffer_addrs didn't
3757 * change because each write-back erases
3760 rx_desc->read.buffer_addr[j+1] =
3761 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3763 rx_desc->read.buffer_addr[j+1] = ~0;
3766 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3771 /* Make buffer alignment 2 beyond a 16 byte boundary
3772 * this will result in a 16 byte aligned IP header after
3773 * the 14 byte MAC header is removed
3775 skb_reserve(skb, NET_IP_ALIGN);
3779 buffer_info->skb = skb;
3780 buffer_info->length = adapter->rx_ps_bsize0;
3781 buffer_info->dma = pci_map_single(pdev, skb->data,
3782 adapter->rx_ps_bsize0,
3783 PCI_DMA_FROMDEVICE);
3785 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
3787 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3788 /* Force memory writes to complete before letting h/w
3789 * know there are new descriptors to fetch. (Only
3790 * applicable for weak-ordered memory model archs,
3791 * such as IA-64). */
3793 /* Hardware increments by 16 bytes, but packet split
3794 * descriptors are 32 bytes...so we increment tail
3797 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
3800 if(unlikely(++i == rx_ring->count)) i = 0;
3801 buffer_info = &rx_ring->buffer_info[i];
3802 ps_page = &rx_ring->ps_page[i];
3803 ps_page_dma = &rx_ring->ps_page_dma[i];
3807 rx_ring->next_to_use = i;
3811 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3816 e1000_smartspeed(struct e1000_adapter *adapter)
3818 uint16_t phy_status;
3821 if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
3822 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
3825 if(adapter->smartspeed == 0) {
3826 /* If Master/Slave config fault is asserted twice,
3827 * we assume back-to-back */
3828 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3829 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3830 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3831 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3832 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3833 if(phy_ctrl & CR_1000T_MS_ENABLE) {
3834 phy_ctrl &= ~CR_1000T_MS_ENABLE;
3835 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
3837 adapter->smartspeed++;
3838 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3839 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
3841 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3842 MII_CR_RESTART_AUTO_NEG);
3843 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
3848 } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
3849 /* If still no link, perhaps using 2/3 pair cable */
3850 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3851 phy_ctrl |= CR_1000T_MS_ENABLE;
3852 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
3853 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3854 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
3855 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3856 MII_CR_RESTART_AUTO_NEG);
3857 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
3860 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3861 if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
3862 adapter->smartspeed = 0;
3873 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3879 return e1000_mii_ioctl(netdev, ifr, cmd);
3893 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3895 struct e1000_adapter *adapter = netdev_priv(netdev);
3896 struct mii_ioctl_data *data = if_mii(ifr);
3900 unsigned long flags;
3902 if(adapter->hw.media_type != e1000_media_type_copper)
3907 data->phy_id = adapter->hw.phy_addr;
3910 if(!capable(CAP_NET_ADMIN))
3912 spin_lock_irqsave(&adapter->stats_lock, flags);
3913 if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
3915 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3918 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3921 if(!capable(CAP_NET_ADMIN))
3923 if(data->reg_num & ~(0x1F))
3925 mii_reg = data->val_in;
3926 spin_lock_irqsave(&adapter->stats_lock, flags);
3927 if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
3929 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3932 if(adapter->hw.phy_type == e1000_phy_m88) {
3933 switch (data->reg_num) {
3935 if(mii_reg & MII_CR_POWER_DOWN)
3937 if(mii_reg & MII_CR_AUTO_NEG_EN) {
3938 adapter->hw.autoneg = 1;
3939 adapter->hw.autoneg_advertised = 0x2F;
3942 spddplx = SPEED_1000;
3943 else if (mii_reg & 0x2000)
3944 spddplx = SPEED_100;
3947 spddplx += (mii_reg & 0x100)
3950 retval = e1000_set_spd_dplx(adapter,
3953 spin_unlock_irqrestore(
3954 &adapter->stats_lock,
3959 if(netif_running(adapter->netdev)) {
3960 e1000_down(adapter);
3963 e1000_reset(adapter);
3965 case M88E1000_PHY_SPEC_CTRL:
3966 case M88E1000_EXT_PHY_SPEC_CTRL:
3967 if(e1000_phy_reset(&adapter->hw)) {
3968 spin_unlock_irqrestore(
3969 &adapter->stats_lock, flags);
3975 switch (data->reg_num) {
3977 if(mii_reg & MII_CR_POWER_DOWN)
3979 if(netif_running(adapter->netdev)) {
3980 e1000_down(adapter);
3983 e1000_reset(adapter);
3987 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3992 return E1000_SUCCESS;
3996 e1000_pci_set_mwi(struct e1000_hw *hw)
3998 struct e1000_adapter *adapter = hw->back;
3999 int ret_val = pci_set_mwi(adapter->pdev);
4002 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4006 e1000_pci_clear_mwi(struct e1000_hw *hw)
4008 struct e1000_adapter *adapter = hw->back;
4010 pci_clear_mwi(adapter->pdev);
4014 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4016 struct e1000_adapter *adapter = hw->back;
4018 pci_read_config_word(adapter->pdev, reg, value);
4022 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4024 struct e1000_adapter *adapter = hw->back;
4026 pci_write_config_word(adapter->pdev, reg, *value);
4030 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4036 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4042 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4044 struct e1000_adapter *adapter = netdev_priv(netdev);
4045 uint32_t ctrl, rctl;
4047 e1000_irq_disable(adapter);
4048 adapter->vlgrp = grp;
4051 /* enable VLAN tag insert/strip */
4052 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4053 ctrl |= E1000_CTRL_VME;
4054 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4056 /* enable VLAN receive filtering */
4057 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4058 rctl |= E1000_RCTL_VFE;
4059 rctl &= ~E1000_RCTL_CFIEN;
4060 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4061 e1000_update_mng_vlan(adapter);
4063 /* disable VLAN tag insert/strip */
4064 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4065 ctrl &= ~E1000_CTRL_VME;
4066 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4068 /* disable VLAN filtering */
4069 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4070 rctl &= ~E1000_RCTL_VFE;
4071 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4072 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4073 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4074 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4078 e1000_irq_enable(adapter);
4082 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4084 struct e1000_adapter *adapter = netdev_priv(netdev);
4085 uint32_t vfta, index;
4086 if((adapter->hw.mng_cookie.status &
4087 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4088 (vid == adapter->mng_vlan_id))
4090 /* add VID to filter table */
4091 index = (vid >> 5) & 0x7F;
4092 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4093 vfta |= (1 << (vid & 0x1F));
4094 e1000_write_vfta(&adapter->hw, index, vfta);
4098 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4100 struct e1000_adapter *adapter = netdev_priv(netdev);
4101 uint32_t vfta, index;
4103 e1000_irq_disable(adapter);
4106 adapter->vlgrp->vlan_devices[vid] = NULL;
4108 e1000_irq_enable(adapter);
4110 if((adapter->hw.mng_cookie.status &
4111 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4112 (vid == adapter->mng_vlan_id))
4114 /* remove VID from filter table */
4115 index = (vid >> 5) & 0x7F;
4116 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4117 vfta &= ~(1 << (vid & 0x1F));
4118 e1000_write_vfta(&adapter->hw, index, vfta);
4122 e1000_restore_vlan(struct e1000_adapter *adapter)
4124 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4126 if(adapter->vlgrp) {
4128 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4129 if(!adapter->vlgrp->vlan_devices[vid])
4131 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4137 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4139 adapter->hw.autoneg = 0;
4141 /* Fiber NICs only allow 1000 gbps Full duplex */
4142 if((adapter->hw.media_type == e1000_media_type_fiber) &&
4143 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4144 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4149 case SPEED_10 + DUPLEX_HALF:
4150 adapter->hw.forced_speed_duplex = e1000_10_half;
4152 case SPEED_10 + DUPLEX_FULL:
4153 adapter->hw.forced_speed_duplex = e1000_10_full;
4155 case SPEED_100 + DUPLEX_HALF:
4156 adapter->hw.forced_speed_duplex = e1000_100_half;
4158 case SPEED_100 + DUPLEX_FULL:
4159 adapter->hw.forced_speed_duplex = e1000_100_full;
4161 case SPEED_1000 + DUPLEX_FULL:
4162 adapter->hw.autoneg = 1;
4163 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4165 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4167 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4175 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4177 struct net_device *netdev = pci_get_drvdata(pdev);
4178 struct e1000_adapter *adapter = netdev_priv(netdev);
4179 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
4180 uint32_t wufc = adapter->wol;
4182 netif_device_detach(netdev);
4184 if(netif_running(netdev))
4185 e1000_down(adapter);
4187 status = E1000_READ_REG(&adapter->hw, STATUS);
4188 if(status & E1000_STATUS_LU)
4189 wufc &= ~E1000_WUFC_LNKC;
4192 e1000_setup_rctl(adapter);
4193 e1000_set_multi(netdev);
4195 /* turn on all-multi mode if wake on multicast is enabled */
4196 if(adapter->wol & E1000_WUFC_MC) {
4197 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4198 rctl |= E1000_RCTL_MPE;
4199 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4202 if(adapter->hw.mac_type >= e1000_82540) {
4203 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4204 /* advertise wake from D3Cold */
4205 #define E1000_CTRL_ADVD3WUC 0x00100000
4206 /* phy power management enable */
4207 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4208 ctrl |= E1000_CTRL_ADVD3WUC |
4209 E1000_CTRL_EN_PHY_PWR_MGMT;
4210 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4213 if(adapter->hw.media_type == e1000_media_type_fiber ||
4214 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4215 /* keep the laser running in D3 */
4216 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4217 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4218 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4221 /* Allow time for pending master requests to run */
4222 e1000_disable_pciex_master(&adapter->hw);
4224 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4225 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4226 pci_enable_wake(pdev, 3, 1);
4227 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
4229 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4230 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4231 pci_enable_wake(pdev, 3, 0);
4232 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
4235 pci_save_state(pdev);
4237 if(adapter->hw.mac_type >= e1000_82540 &&
4238 adapter->hw.media_type == e1000_media_type_copper) {
4239 manc = E1000_READ_REG(&adapter->hw, MANC);
4240 if(manc & E1000_MANC_SMBUS_EN) {
4241 manc |= E1000_MANC_ARP_EN;
4242 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4243 pci_enable_wake(pdev, 3, 1);
4244 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
4248 switch(adapter->hw.mac_type) {
4251 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4252 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
4253 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
4256 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4257 E1000_WRITE_REG(&adapter->hw, SWSM,
4258 swsm & ~E1000_SWSM_DRV_LOAD);
4264 pci_disable_device(pdev);
4265 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4271 e1000_resume(struct pci_dev *pdev)
4273 struct net_device *netdev = pci_get_drvdata(pdev);
4274 struct e1000_adapter *adapter = netdev_priv(netdev);
4275 uint32_t manc, ret_val, swsm;
4278 pci_set_power_state(pdev, PCI_D0);
4279 pci_restore_state(pdev);
4280 ret_val = pci_enable_device(pdev);
4281 pci_set_master(pdev);
4283 pci_enable_wake(pdev, PCI_D3hot, 0);
4284 pci_enable_wake(pdev, PCI_D3cold, 0);
4286 e1000_reset(adapter);
4287 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4289 if(netif_running(netdev))
4292 netif_device_attach(netdev);
4294 if(adapter->hw.mac_type >= e1000_82540 &&
4295 adapter->hw.media_type == e1000_media_type_copper) {
4296 manc = E1000_READ_REG(&adapter->hw, MANC);
4297 manc &= ~(E1000_MANC_ARP_EN);
4298 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4301 switch(adapter->hw.mac_type) {
4304 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4305 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
4306 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
4309 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4310 E1000_WRITE_REG(&adapter->hw, SWSM,
4311 swsm | E1000_SWSM_DRV_LOAD);
4320 #ifdef CONFIG_NET_POLL_CONTROLLER
4322 * Polling 'interrupt' - used by things like netconsole to send skbs
4323 * without having to re-enable interrupts. It's not called while
4324 * the interrupt routine is executing.
4327 e1000_netpoll(struct net_device *netdev)
4329 struct e1000_adapter *adapter = netdev_priv(netdev);
4330 disable_irq(adapter->pdev->irq);
4331 e1000_intr(adapter->pdev->irq, netdev, NULL);
4332 e1000_clean_tx_irq(adapter, adapter->tx_ring);
4333 enable_irq(adapter->pdev->irq);