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 Added another fix for the pass false carrier bit
35 * o Need to rebuild with noew version number for the pass false carrier
38 * o fixup for tso workaround to disable it for pci-x
39 * o fix mem leak on 82542
40 * o fixes for 10 Mb/s connections and incorrect stats
42 * o hardware workaround to only set "speed mode" bit for 1G link.
44 * o wake on lan support modified for device ID 10B5
45 * o fix dhcp + vlan issue not making it to the iAMT firmware
47 * o New hardware support for the Gigabit NIC embedded in the south bridge
48 * o Fixes to the recycling logic (skb->tail) from IBM LTC
50 * o incorporate fix for recycled skbs from IBM LTC
52 * o Honor eeprom setting for enabling/disabling Wake On Lan
54 * o Fix memory leak in rx ring handling for PCI Express adapters
56 * o Patch from Jesper Juhl to remove redundant NULL checks for kfree
58 * o Render logic that sets/resets DRV_LOAD as inline functions to
59 * avoid code replication. If f/w is AMT then set DRV_LOAD only when
60 * network interface is open.
61 * o Handle DRV_LOAD set/reset in cases where AMT uses VLANs.
62 * o Adjust PBA partioning for Jumbo frames using MTU size and not
65 * o Use adapter->tx_timeout_factor in Tx Hung Detect logic
66 * (e1000_clean_tx_irq)
67 * o Support for 8086:10B5 device (Quad Port)
70 char e1000_driver_name[] = "e1000";
71 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
72 #ifndef CONFIG_E1000_NAPI
75 #define DRIVERNAPI "-NAPI"
77 #define DRV_VERSION "7.0.33-k2"DRIVERNAPI
78 char e1000_driver_version[] = DRV_VERSION;
79 static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
81 /* e1000_pci_tbl - PCI Device ID Table
83 * Last entry must be all 0s
86 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
88 static struct pci_device_id e1000_pci_tbl[] = {
89 INTEL_E1000_ETHERNET_DEVICE(0x1000),
90 INTEL_E1000_ETHERNET_DEVICE(0x1001),
91 INTEL_E1000_ETHERNET_DEVICE(0x1004),
92 INTEL_E1000_ETHERNET_DEVICE(0x1008),
93 INTEL_E1000_ETHERNET_DEVICE(0x1009),
94 INTEL_E1000_ETHERNET_DEVICE(0x100C),
95 INTEL_E1000_ETHERNET_DEVICE(0x100D),
96 INTEL_E1000_ETHERNET_DEVICE(0x100E),
97 INTEL_E1000_ETHERNET_DEVICE(0x100F),
98 INTEL_E1000_ETHERNET_DEVICE(0x1010),
99 INTEL_E1000_ETHERNET_DEVICE(0x1011),
100 INTEL_E1000_ETHERNET_DEVICE(0x1012),
101 INTEL_E1000_ETHERNET_DEVICE(0x1013),
102 INTEL_E1000_ETHERNET_DEVICE(0x1014),
103 INTEL_E1000_ETHERNET_DEVICE(0x1015),
104 INTEL_E1000_ETHERNET_DEVICE(0x1016),
105 INTEL_E1000_ETHERNET_DEVICE(0x1017),
106 INTEL_E1000_ETHERNET_DEVICE(0x1018),
107 INTEL_E1000_ETHERNET_DEVICE(0x1019),
108 INTEL_E1000_ETHERNET_DEVICE(0x101A),
109 INTEL_E1000_ETHERNET_DEVICE(0x101D),
110 INTEL_E1000_ETHERNET_DEVICE(0x101E),
111 INTEL_E1000_ETHERNET_DEVICE(0x1026),
112 INTEL_E1000_ETHERNET_DEVICE(0x1027),
113 INTEL_E1000_ETHERNET_DEVICE(0x1028),
114 INTEL_E1000_ETHERNET_DEVICE(0x105E),
115 INTEL_E1000_ETHERNET_DEVICE(0x105F),
116 INTEL_E1000_ETHERNET_DEVICE(0x1060),
117 INTEL_E1000_ETHERNET_DEVICE(0x1075),
118 INTEL_E1000_ETHERNET_DEVICE(0x1076),
119 INTEL_E1000_ETHERNET_DEVICE(0x1077),
120 INTEL_E1000_ETHERNET_DEVICE(0x1078),
121 INTEL_E1000_ETHERNET_DEVICE(0x1079),
122 INTEL_E1000_ETHERNET_DEVICE(0x107A),
123 INTEL_E1000_ETHERNET_DEVICE(0x107B),
124 INTEL_E1000_ETHERNET_DEVICE(0x107C),
125 INTEL_E1000_ETHERNET_DEVICE(0x107D),
126 INTEL_E1000_ETHERNET_DEVICE(0x107E),
127 INTEL_E1000_ETHERNET_DEVICE(0x107F),
128 INTEL_E1000_ETHERNET_DEVICE(0x108A),
129 INTEL_E1000_ETHERNET_DEVICE(0x108B),
130 INTEL_E1000_ETHERNET_DEVICE(0x108C),
131 INTEL_E1000_ETHERNET_DEVICE(0x1096),
132 INTEL_E1000_ETHERNET_DEVICE(0x1098),
133 INTEL_E1000_ETHERNET_DEVICE(0x1099),
134 INTEL_E1000_ETHERNET_DEVICE(0x109A),
135 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
136 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
137 /* required last entry */
141 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
143 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
144 struct e1000_tx_ring *txdr);
145 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
146 struct e1000_rx_ring *rxdr);
147 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
148 struct e1000_tx_ring *tx_ring);
149 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
150 struct e1000_rx_ring *rx_ring);
152 /* Local Function Prototypes */
154 static int e1000_init_module(void);
155 static void e1000_exit_module(void);
156 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
157 static void __devexit e1000_remove(struct pci_dev *pdev);
158 static int e1000_alloc_queues(struct e1000_adapter *adapter);
159 static int e1000_sw_init(struct e1000_adapter *adapter);
160 static int e1000_open(struct net_device *netdev);
161 static int e1000_close(struct net_device *netdev);
162 static void e1000_configure_tx(struct e1000_adapter *adapter);
163 static void e1000_configure_rx(struct e1000_adapter *adapter);
164 static void e1000_setup_rctl(struct e1000_adapter *adapter);
165 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
166 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
167 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
168 struct e1000_tx_ring *tx_ring);
169 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
170 struct e1000_rx_ring *rx_ring);
171 static void e1000_set_multi(struct net_device *netdev);
172 static void e1000_update_phy_info(unsigned long data);
173 static void e1000_watchdog(unsigned long data);
174 static void e1000_watchdog_task(struct e1000_adapter *adapter);
175 static void e1000_82547_tx_fifo_stall(unsigned long data);
176 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
177 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
178 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
179 static int e1000_set_mac(struct net_device *netdev, void *p);
180 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
181 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
182 struct e1000_tx_ring *tx_ring);
183 #ifdef CONFIG_E1000_NAPI
184 static int e1000_clean(struct net_device *poll_dev, int *budget);
185 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
186 struct e1000_rx_ring *rx_ring,
187 int *work_done, int work_to_do);
188 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
189 struct e1000_rx_ring *rx_ring,
190 int *work_done, int work_to_do);
192 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
193 struct e1000_rx_ring *rx_ring);
194 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
195 struct e1000_rx_ring *rx_ring);
197 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
198 struct e1000_rx_ring *rx_ring,
200 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
201 struct e1000_rx_ring *rx_ring,
203 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
204 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
206 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
207 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
208 static void e1000_tx_timeout(struct net_device *dev);
209 static void e1000_reset_task(struct net_device *dev);
210 static void e1000_smartspeed(struct e1000_adapter *adapter);
211 static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
212 struct sk_buff *skb);
214 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
215 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
216 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
217 static void e1000_restore_vlan(struct e1000_adapter *adapter);
220 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
221 static int e1000_resume(struct pci_dev *pdev);
224 #ifdef CONFIG_NET_POLL_CONTROLLER
225 /* for netdump / net console */
226 static void e1000_netpoll (struct net_device *netdev);
230 static struct pci_driver e1000_driver = {
231 .name = e1000_driver_name,
232 .id_table = e1000_pci_tbl,
233 .probe = e1000_probe,
234 .remove = __devexit_p(e1000_remove),
235 /* Power Managment Hooks */
237 .suspend = e1000_suspend,
238 .resume = e1000_resume
242 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
243 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
244 MODULE_LICENSE("GPL");
245 MODULE_VERSION(DRV_VERSION);
247 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
248 module_param(debug, int, 0);
249 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
252 * e1000_init_module - Driver Registration Routine
254 * e1000_init_module is the first routine called when the driver is
255 * loaded. All it does is register with the PCI subsystem.
259 e1000_init_module(void)
262 printk(KERN_INFO "%s - version %s\n",
263 e1000_driver_string, e1000_driver_version);
265 printk(KERN_INFO "%s\n", e1000_copyright);
267 ret = pci_module_init(&e1000_driver);
272 module_init(e1000_init_module);
275 * e1000_exit_module - Driver Exit Cleanup Routine
277 * e1000_exit_module is called just before the driver is removed
282 e1000_exit_module(void)
284 pci_unregister_driver(&e1000_driver);
287 module_exit(e1000_exit_module);
290 * e1000_irq_disable - Mask off interrupt generation on the NIC
291 * @adapter: board private structure
295 e1000_irq_disable(struct e1000_adapter *adapter)
297 atomic_inc(&adapter->irq_sem);
298 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
299 E1000_WRITE_FLUSH(&adapter->hw);
300 synchronize_irq(adapter->pdev->irq);
304 * e1000_irq_enable - Enable default interrupt generation settings
305 * @adapter: board private structure
309 e1000_irq_enable(struct e1000_adapter *adapter)
311 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
312 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
313 E1000_WRITE_FLUSH(&adapter->hw);
318 e1000_update_mng_vlan(struct e1000_adapter *adapter)
320 struct net_device *netdev = adapter->netdev;
321 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
322 uint16_t old_vid = adapter->mng_vlan_id;
323 if (adapter->vlgrp) {
324 if (!adapter->vlgrp->vlan_devices[vid]) {
325 if (adapter->hw.mng_cookie.status &
326 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
327 e1000_vlan_rx_add_vid(netdev, vid);
328 adapter->mng_vlan_id = vid;
330 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
332 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
334 !adapter->vlgrp->vlan_devices[old_vid])
335 e1000_vlan_rx_kill_vid(netdev, old_vid);
337 adapter->mng_vlan_id = vid;
342 * e1000_release_hw_control - release control of the h/w to f/w
343 * @adapter: address of board private structure
345 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
346 * For ASF and Pass Through versions of f/w this means that the
347 * driver is no longer loaded. For AMT version (only with 82573) i
348 * of the f/w this means that the netowrk i/f is closed.
353 e1000_release_hw_control(struct e1000_adapter *adapter)
358 /* Let firmware taken over control of h/w */
359 switch (adapter->hw.mac_type) {
362 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
363 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
364 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
367 swsm = E1000_READ_REG(&adapter->hw, SWSM);
368 E1000_WRITE_REG(&adapter->hw, SWSM,
369 swsm & ~E1000_SWSM_DRV_LOAD);
376 * e1000_get_hw_control - get control of the h/w from f/w
377 * @adapter: address of board private structure
379 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
380 * For ASF and Pass Through versions of f/w this means that
381 * the driver is loaded. For AMT version (only with 82573)
382 * of the f/w this means that the netowrk i/f is open.
387 e1000_get_hw_control(struct e1000_adapter *adapter)
391 /* Let firmware know the driver has taken over */
392 switch (adapter->hw.mac_type) {
395 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
396 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
397 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
400 swsm = E1000_READ_REG(&adapter->hw, SWSM);
401 E1000_WRITE_REG(&adapter->hw, SWSM,
402 swsm | E1000_SWSM_DRV_LOAD);
410 e1000_up(struct e1000_adapter *adapter)
412 struct net_device *netdev = adapter->netdev;
415 /* hardware has been reset, we need to reload some things */
417 /* Reset the PHY if it was previously powered down */
418 if (adapter->hw.media_type == e1000_media_type_copper) {
420 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
421 if (mii_reg & MII_CR_POWER_DOWN)
422 e1000_phy_reset(&adapter->hw);
425 e1000_set_multi(netdev);
427 e1000_restore_vlan(adapter);
429 e1000_configure_tx(adapter);
430 e1000_setup_rctl(adapter);
431 e1000_configure_rx(adapter);
432 /* call E1000_DESC_UNUSED which always leaves
433 * at least 1 descriptor unused to make sure
434 * next_to_use != next_to_clean */
435 for (i = 0; i < adapter->num_rx_queues; i++) {
436 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
437 adapter->alloc_rx_buf(adapter, ring,
438 E1000_DESC_UNUSED(ring));
441 #ifdef CONFIG_PCI_MSI
442 if (adapter->hw.mac_type > e1000_82547_rev_2) {
443 adapter->have_msi = TRUE;
444 if ((err = pci_enable_msi(adapter->pdev))) {
446 "Unable to allocate MSI interrupt Error: %d\n", err);
447 adapter->have_msi = FALSE;
451 if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
452 SA_SHIRQ | SA_SAMPLE_RANDOM,
453 netdev->name, netdev))) {
455 "Unable to allocate interrupt Error: %d\n", err);
459 adapter->tx_queue_len = netdev->tx_queue_len;
461 mod_timer(&adapter->watchdog_timer, jiffies);
463 #ifdef CONFIG_E1000_NAPI
464 netif_poll_enable(netdev);
466 e1000_irq_enable(adapter);
472 e1000_down(struct e1000_adapter *adapter)
474 struct net_device *netdev = adapter->netdev;
475 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
476 e1000_check_mng_mode(&adapter->hw);
478 e1000_irq_disable(adapter);
480 free_irq(adapter->pdev->irq, netdev);
481 #ifdef CONFIG_PCI_MSI
482 if (adapter->hw.mac_type > e1000_82547_rev_2 &&
483 adapter->have_msi == TRUE)
484 pci_disable_msi(adapter->pdev);
486 del_timer_sync(&adapter->tx_fifo_stall_timer);
487 del_timer_sync(&adapter->watchdog_timer);
488 del_timer_sync(&adapter->phy_info_timer);
490 #ifdef CONFIG_E1000_NAPI
491 netif_poll_disable(netdev);
493 netdev->tx_queue_len = adapter->tx_queue_len;
494 adapter->link_speed = 0;
495 adapter->link_duplex = 0;
496 netif_carrier_off(netdev);
497 netif_stop_queue(netdev);
499 e1000_reset(adapter);
500 e1000_clean_all_tx_rings(adapter);
501 e1000_clean_all_rx_rings(adapter);
503 /* Power down the PHY so no link is implied when interface is down *
504 * The PHY cannot be powered down if any of the following is TRUE *
507 * (c) SoL/IDER session is active */
508 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
509 adapter->hw.media_type == e1000_media_type_copper &&
510 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
512 !e1000_check_phy_reset_block(&adapter->hw)) {
514 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
515 mii_reg |= MII_CR_POWER_DOWN;
516 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
522 e1000_reset(struct e1000_adapter *adapter)
525 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
527 /* Repartition Pba for greater than 9k mtu
528 * To take effect CTRL.RST is required.
531 switch (adapter->hw.mac_type) {
533 case e1000_82547_rev_2:
538 case e1000_80003es2lan:
549 if ((adapter->hw.mac_type != e1000_82573) &&
550 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
551 pba -= 8; /* allocate more FIFO for Tx */
554 if (adapter->hw.mac_type == e1000_82547) {
555 adapter->tx_fifo_head = 0;
556 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
557 adapter->tx_fifo_size =
558 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
559 atomic_set(&adapter->tx_fifo_stall, 0);
562 E1000_WRITE_REG(&adapter->hw, PBA, pba);
564 /* flow control settings */
565 /* Set the FC high water mark to 90% of the FIFO size.
566 * Required to clear last 3 LSB */
567 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
569 adapter->hw.fc_high_water = fc_high_water_mark;
570 adapter->hw.fc_low_water = fc_high_water_mark - 8;
571 if (adapter->hw.mac_type == e1000_80003es2lan)
572 adapter->hw.fc_pause_time = 0xFFFF;
574 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
575 adapter->hw.fc_send_xon = 1;
576 adapter->hw.fc = adapter->hw.original_fc;
578 /* Allow time for pending master requests to run */
579 e1000_reset_hw(&adapter->hw);
580 if (adapter->hw.mac_type >= e1000_82544)
581 E1000_WRITE_REG(&adapter->hw, WUC, 0);
582 if (e1000_init_hw(&adapter->hw))
583 DPRINTK(PROBE, ERR, "Hardware Error\n");
584 e1000_update_mng_vlan(adapter);
585 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
586 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
588 e1000_reset_adaptive(&adapter->hw);
589 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
590 if (adapter->en_mng_pt) {
591 manc = E1000_READ_REG(&adapter->hw, MANC);
592 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
593 E1000_WRITE_REG(&adapter->hw, MANC, manc);
598 * e1000_probe - Device Initialization Routine
599 * @pdev: PCI device information struct
600 * @ent: entry in e1000_pci_tbl
602 * Returns 0 on success, negative on failure
604 * e1000_probe initializes an adapter identified by a pci_dev structure.
605 * The OS initialization, configuring of the adapter private structure,
606 * and a hardware reset occur.
610 e1000_probe(struct pci_dev *pdev,
611 const struct pci_device_id *ent)
613 struct net_device *netdev;
614 struct e1000_adapter *adapter;
615 unsigned long mmio_start, mmio_len;
617 static int cards_found = 0;
618 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
619 int i, err, pci_using_dac;
620 uint16_t eeprom_data;
621 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
622 if ((err = pci_enable_device(pdev)))
625 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
628 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
629 E1000_ERR("No usable DMA configuration, aborting\n");
635 if ((err = pci_request_regions(pdev, e1000_driver_name)))
638 pci_set_master(pdev);
640 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
643 goto err_alloc_etherdev;
646 SET_MODULE_OWNER(netdev);
647 SET_NETDEV_DEV(netdev, &pdev->dev);
649 pci_set_drvdata(pdev, netdev);
650 adapter = netdev_priv(netdev);
651 adapter->netdev = netdev;
652 adapter->pdev = pdev;
653 adapter->hw.back = adapter;
654 adapter->msg_enable = (1 << debug) - 1;
656 mmio_start = pci_resource_start(pdev, BAR_0);
657 mmio_len = pci_resource_len(pdev, BAR_0);
659 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
660 if (!adapter->hw.hw_addr) {
665 for (i = BAR_1; i <= BAR_5; i++) {
666 if (pci_resource_len(pdev, i) == 0)
668 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
669 adapter->hw.io_base = pci_resource_start(pdev, i);
674 netdev->open = &e1000_open;
675 netdev->stop = &e1000_close;
676 netdev->hard_start_xmit = &e1000_xmit_frame;
677 netdev->get_stats = &e1000_get_stats;
678 netdev->set_multicast_list = &e1000_set_multi;
679 netdev->set_mac_address = &e1000_set_mac;
680 netdev->change_mtu = &e1000_change_mtu;
681 netdev->do_ioctl = &e1000_ioctl;
682 e1000_set_ethtool_ops(netdev);
683 netdev->tx_timeout = &e1000_tx_timeout;
684 netdev->watchdog_timeo = 5 * HZ;
685 #ifdef CONFIG_E1000_NAPI
686 netdev->poll = &e1000_clean;
689 netdev->vlan_rx_register = e1000_vlan_rx_register;
690 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
691 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
692 #ifdef CONFIG_NET_POLL_CONTROLLER
693 netdev->poll_controller = e1000_netpoll;
695 strcpy(netdev->name, pci_name(pdev));
697 netdev->mem_start = mmio_start;
698 netdev->mem_end = mmio_start + mmio_len;
699 netdev->base_addr = adapter->hw.io_base;
701 adapter->bd_number = cards_found;
703 /* setup the private structure */
705 if ((err = e1000_sw_init(adapter)))
708 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
709 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
711 /* if ksp3, indicate if it's port a being setup */
712 if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
713 e1000_ksp3_port_a == 0)
714 adapter->ksp3_port_a = 1;
716 /* Reset for multiple KP3 adapters */
717 if (e1000_ksp3_port_a == 4)
718 e1000_ksp3_port_a = 0;
720 if (adapter->hw.mac_type >= e1000_82543) {
721 netdev->features = NETIF_F_SG |
725 NETIF_F_HW_VLAN_FILTER;
729 if ((adapter->hw.mac_type >= e1000_82544) &&
730 (adapter->hw.mac_type != e1000_82547))
731 netdev->features |= NETIF_F_TSO;
733 #ifdef NETIF_F_TSO_IPV6
734 if (adapter->hw.mac_type > e1000_82547_rev_2)
735 netdev->features |= NETIF_F_TSO_IPV6;
739 netdev->features |= NETIF_F_HIGHDMA;
741 /* hard_start_xmit is safe against parallel locking */
742 netdev->features |= NETIF_F_LLTX;
744 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
746 /* before reading the EEPROM, reset the controller to
747 * put the device in a known good starting state */
749 e1000_reset_hw(&adapter->hw);
751 /* make sure the EEPROM is good */
753 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
754 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
759 /* copy the MAC address out of the EEPROM */
761 if (e1000_read_mac_addr(&adapter->hw))
762 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
763 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
764 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
766 if (!is_valid_ether_addr(netdev->perm_addr)) {
767 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
772 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
774 e1000_get_bus_info(&adapter->hw);
776 init_timer(&adapter->tx_fifo_stall_timer);
777 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
778 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
780 init_timer(&adapter->watchdog_timer);
781 adapter->watchdog_timer.function = &e1000_watchdog;
782 adapter->watchdog_timer.data = (unsigned long) adapter;
784 INIT_WORK(&adapter->watchdog_task,
785 (void (*)(void *))e1000_watchdog_task, adapter);
787 init_timer(&adapter->phy_info_timer);
788 adapter->phy_info_timer.function = &e1000_update_phy_info;
789 adapter->phy_info_timer.data = (unsigned long) adapter;
791 INIT_WORK(&adapter->reset_task,
792 (void (*)(void *))e1000_reset_task, netdev);
794 /* we're going to reset, so assume we have no link for now */
796 netif_carrier_off(netdev);
797 netif_stop_queue(netdev);
799 e1000_check_options(adapter);
801 /* Initial Wake on LAN setting
802 * If APM wake is enabled in the EEPROM,
803 * enable the ACPI Magic Packet filter
806 switch (adapter->hw.mac_type) {
807 case e1000_82542_rev2_0:
808 case e1000_82542_rev2_1:
812 e1000_read_eeprom(&adapter->hw,
813 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
814 eeprom_apme_mask = E1000_EEPROM_82544_APM;
817 case e1000_82546_rev_3:
819 case e1000_80003es2lan:
820 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
821 e1000_read_eeprom(&adapter->hw,
822 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
827 e1000_read_eeprom(&adapter->hw,
828 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
831 if (eeprom_data & eeprom_apme_mask)
832 adapter->wol |= E1000_WUFC_MAG;
834 /* print bus type/speed/width info */
836 struct e1000_hw *hw = &adapter->hw;
837 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
838 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
839 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
840 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
841 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
842 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
843 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
844 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
845 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
846 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
847 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
851 for (i = 0; i < 6; i++)
852 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
854 /* reset the hardware with the new settings */
855 e1000_reset(adapter);
857 /* If the controller is 82573 and f/w is AMT, do not set
858 * DRV_LOAD until the interface is up. For all other cases,
859 * let the f/w know that the h/w is now under the control
861 if (adapter->hw.mac_type != e1000_82573 ||
862 !e1000_check_mng_mode(&adapter->hw))
863 e1000_get_hw_control(adapter);
865 strcpy(netdev->name, "eth%d");
866 if ((err = register_netdev(netdev)))
869 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
877 iounmap(adapter->hw.hw_addr);
881 pci_release_regions(pdev);
886 * e1000_remove - Device Removal Routine
887 * @pdev: PCI device information struct
889 * e1000_remove is called by the PCI subsystem to alert the driver
890 * that it should release a PCI device. The could be caused by a
891 * Hot-Plug event, or because the driver is going to be removed from
895 static void __devexit
896 e1000_remove(struct pci_dev *pdev)
898 struct net_device *netdev = pci_get_drvdata(pdev);
899 struct e1000_adapter *adapter = netdev_priv(netdev);
901 #ifdef CONFIG_E1000_NAPI
905 flush_scheduled_work();
907 if (adapter->hw.mac_type >= e1000_82540 &&
908 adapter->hw.media_type == e1000_media_type_copper) {
909 manc = E1000_READ_REG(&adapter->hw, MANC);
910 if (manc & E1000_MANC_SMBUS_EN) {
911 manc |= E1000_MANC_ARP_EN;
912 E1000_WRITE_REG(&adapter->hw, MANC, manc);
916 /* Release control of h/w to f/w. If f/w is AMT enabled, this
917 * would have already happened in close and is redundant. */
918 e1000_release_hw_control(adapter);
920 unregister_netdev(netdev);
921 #ifdef CONFIG_E1000_NAPI
922 for (i = 0; i < adapter->num_rx_queues; i++)
923 dev_put(&adapter->polling_netdev[i]);
926 if (!e1000_check_phy_reset_block(&adapter->hw))
927 e1000_phy_hw_reset(&adapter->hw);
929 kfree(adapter->tx_ring);
930 kfree(adapter->rx_ring);
931 #ifdef CONFIG_E1000_NAPI
932 kfree(adapter->polling_netdev);
935 iounmap(adapter->hw.hw_addr);
936 pci_release_regions(pdev);
940 pci_disable_device(pdev);
944 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
945 * @adapter: board private structure to initialize
947 * e1000_sw_init initializes the Adapter private data structure.
948 * Fields are initialized based on PCI device information and
949 * OS network device settings (MTU size).
953 e1000_sw_init(struct e1000_adapter *adapter)
955 struct e1000_hw *hw = &adapter->hw;
956 struct net_device *netdev = adapter->netdev;
957 struct pci_dev *pdev = adapter->pdev;
958 #ifdef CONFIG_E1000_NAPI
962 /* PCI config space info */
964 hw->vendor_id = pdev->vendor;
965 hw->device_id = pdev->device;
966 hw->subsystem_vendor_id = pdev->subsystem_vendor;
967 hw->subsystem_id = pdev->subsystem_device;
969 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
971 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
973 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
974 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
975 hw->max_frame_size = netdev->mtu +
976 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
977 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
979 /* identify the MAC */
981 if (e1000_set_mac_type(hw)) {
982 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
986 /* initialize eeprom parameters */
988 if (e1000_init_eeprom_params(hw)) {
989 E1000_ERR("EEPROM initialization failed\n");
993 switch (hw->mac_type) {
998 case e1000_82541_rev_2:
999 case e1000_82547_rev_2:
1000 hw->phy_init_script = 1;
1004 e1000_set_media_type(hw);
1006 hw->wait_autoneg_complete = FALSE;
1007 hw->tbi_compatibility_en = TRUE;
1008 hw->adaptive_ifs = TRUE;
1010 /* Copper options */
1012 if (hw->media_type == e1000_media_type_copper) {
1013 hw->mdix = AUTO_ALL_MODES;
1014 hw->disable_polarity_correction = FALSE;
1015 hw->master_slave = E1000_MASTER_SLAVE;
1018 adapter->num_tx_queues = 1;
1019 adapter->num_rx_queues = 1;
1021 if (e1000_alloc_queues(adapter)) {
1022 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1026 #ifdef CONFIG_E1000_NAPI
1027 for (i = 0; i < adapter->num_rx_queues; i++) {
1028 adapter->polling_netdev[i].priv = adapter;
1029 adapter->polling_netdev[i].poll = &e1000_clean;
1030 adapter->polling_netdev[i].weight = 64;
1031 dev_hold(&adapter->polling_netdev[i]);
1032 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1034 spin_lock_init(&adapter->tx_queue_lock);
1037 atomic_set(&adapter->irq_sem, 1);
1038 spin_lock_init(&adapter->stats_lock);
1044 * e1000_alloc_queues - Allocate memory for all rings
1045 * @adapter: board private structure to initialize
1047 * We allocate one ring per queue at run-time since we don't know the
1048 * number of queues at compile-time. The polling_netdev array is
1049 * intended for Multiqueue, but should work fine with a single queue.
1052 static int __devinit
1053 e1000_alloc_queues(struct e1000_adapter *adapter)
1057 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1058 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1059 if (!adapter->tx_ring)
1061 memset(adapter->tx_ring, 0, size);
1063 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1064 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1065 if (!adapter->rx_ring) {
1066 kfree(adapter->tx_ring);
1069 memset(adapter->rx_ring, 0, size);
1071 #ifdef CONFIG_E1000_NAPI
1072 size = sizeof(struct net_device) * adapter->num_rx_queues;
1073 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1074 if (!adapter->polling_netdev) {
1075 kfree(adapter->tx_ring);
1076 kfree(adapter->rx_ring);
1079 memset(adapter->polling_netdev, 0, size);
1082 return E1000_SUCCESS;
1086 * e1000_open - Called when a network interface is made active
1087 * @netdev: network interface device structure
1089 * Returns 0 on success, negative value on failure
1091 * The open entry point is called when a network interface is made
1092 * active by the system (IFF_UP). At this point all resources needed
1093 * for transmit and receive operations are allocated, the interrupt
1094 * handler is registered with the OS, the watchdog timer is started,
1095 * and the stack is notified that the interface is ready.
1099 e1000_open(struct net_device *netdev)
1101 struct e1000_adapter *adapter = netdev_priv(netdev);
1104 /* allocate transmit descriptors */
1106 if ((err = e1000_setup_all_tx_resources(adapter)))
1109 /* allocate receive descriptors */
1111 if ((err = e1000_setup_all_rx_resources(adapter)))
1114 if ((err = e1000_up(adapter)))
1116 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1117 if ((adapter->hw.mng_cookie.status &
1118 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1119 e1000_update_mng_vlan(adapter);
1122 /* If AMT is enabled, let the firmware know that the network
1123 * interface is now open */
1124 if (adapter->hw.mac_type == e1000_82573 &&
1125 e1000_check_mng_mode(&adapter->hw))
1126 e1000_get_hw_control(adapter);
1128 return E1000_SUCCESS;
1131 e1000_free_all_rx_resources(adapter);
1133 e1000_free_all_tx_resources(adapter);
1135 e1000_reset(adapter);
1141 * e1000_close - Disables a network interface
1142 * @netdev: network interface device structure
1144 * Returns 0, this is not allowed to fail
1146 * The close entry point is called when an interface is de-activated
1147 * by the OS. The hardware is still under the drivers control, but
1148 * needs to be disabled. A global MAC reset is issued to stop the
1149 * hardware, and all transmit and receive resources are freed.
1153 e1000_close(struct net_device *netdev)
1155 struct e1000_adapter *adapter = netdev_priv(netdev);
1157 e1000_down(adapter);
1159 e1000_free_all_tx_resources(adapter);
1160 e1000_free_all_rx_resources(adapter);
1162 if ((adapter->hw.mng_cookie.status &
1163 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1164 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1167 /* If AMT is enabled, let the firmware know that the network
1168 * interface is now closed */
1169 if (adapter->hw.mac_type == e1000_82573 &&
1170 e1000_check_mng_mode(&adapter->hw))
1171 e1000_release_hw_control(adapter);
1177 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1178 * @adapter: address of board private structure
1179 * @start: address of beginning of memory
1180 * @len: length of memory
1182 static inline boolean_t
1183 e1000_check_64k_bound(struct e1000_adapter *adapter,
1184 void *start, unsigned long len)
1186 unsigned long begin = (unsigned long) start;
1187 unsigned long end = begin + len;
1189 /* First rev 82545 and 82546 need to not allow any memory
1190 * write location to cross 64k boundary due to errata 23 */
1191 if (adapter->hw.mac_type == e1000_82545 ||
1192 adapter->hw.mac_type == e1000_82546) {
1193 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1200 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1201 * @adapter: board private structure
1202 * @txdr: tx descriptor ring (for a specific queue) to setup
1204 * Return 0 on success, negative on failure
1208 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1209 struct e1000_tx_ring *txdr)
1211 struct pci_dev *pdev = adapter->pdev;
1214 size = sizeof(struct e1000_buffer) * txdr->count;
1216 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1217 if (!txdr->buffer_info) {
1219 "Unable to allocate memory for the transmit descriptor ring\n");
1222 memset(txdr->buffer_info, 0, size);
1224 /* round up to nearest 4K */
1226 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1227 E1000_ROUNDUP(txdr->size, 4096);
1229 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1232 vfree(txdr->buffer_info);
1234 "Unable to allocate memory for the transmit descriptor ring\n");
1238 /* Fix for errata 23, can't cross 64kB boundary */
1239 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1240 void *olddesc = txdr->desc;
1241 dma_addr_t olddma = txdr->dma;
1242 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1243 "at %p\n", txdr->size, txdr->desc);
1244 /* Try again, without freeing the previous */
1245 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1246 /* Failed allocation, critical failure */
1248 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1249 goto setup_tx_desc_die;
1252 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1254 pci_free_consistent(pdev, txdr->size, txdr->desc,
1256 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1258 "Unable to allocate aligned memory "
1259 "for the transmit descriptor ring\n");
1260 vfree(txdr->buffer_info);
1263 /* Free old allocation, new allocation was successful */
1264 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1267 memset(txdr->desc, 0, txdr->size);
1269 txdr->next_to_use = 0;
1270 txdr->next_to_clean = 0;
1271 spin_lock_init(&txdr->tx_lock);
1277 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1278 * (Descriptors) for all queues
1279 * @adapter: board private structure
1281 * If this function returns with an error, then it's possible one or
1282 * more of the rings is populated (while the rest are not). It is the
1283 * callers duty to clean those orphaned rings.
1285 * Return 0 on success, negative on failure
1289 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1293 for (i = 0; i < adapter->num_tx_queues; i++) {
1294 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1297 "Allocation for Tx Queue %u failed\n", i);
1306 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1307 * @adapter: board private structure
1309 * Configure the Tx unit of the MAC after a reset.
1313 e1000_configure_tx(struct e1000_adapter *adapter)
1316 struct e1000_hw *hw = &adapter->hw;
1317 uint32_t tdlen, tctl, tipg, tarc;
1318 uint32_t ipgr1, ipgr2;
1320 /* Setup the HW Tx Head and Tail descriptor pointers */
1322 switch (adapter->num_tx_queues) {
1325 tdba = adapter->tx_ring[0].dma;
1326 tdlen = adapter->tx_ring[0].count *
1327 sizeof(struct e1000_tx_desc);
1328 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1329 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1330 E1000_WRITE_REG(hw, TDLEN, tdlen);
1331 E1000_WRITE_REG(hw, TDH, 0);
1332 E1000_WRITE_REG(hw, TDT, 0);
1333 adapter->tx_ring[0].tdh = E1000_TDH;
1334 adapter->tx_ring[0].tdt = E1000_TDT;
1338 /* Set the default values for the Tx Inter Packet Gap timer */
1340 if (hw->media_type == e1000_media_type_fiber ||
1341 hw->media_type == e1000_media_type_internal_serdes)
1342 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1344 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1346 switch (hw->mac_type) {
1347 case e1000_82542_rev2_0:
1348 case e1000_82542_rev2_1:
1349 tipg = DEFAULT_82542_TIPG_IPGT;
1350 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1351 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1353 case e1000_80003es2lan:
1354 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1355 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1358 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1359 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1362 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1363 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1364 E1000_WRITE_REG(hw, TIPG, tipg);
1366 /* Set the Tx Interrupt Delay register */
1368 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1369 if (hw->mac_type >= e1000_82540)
1370 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1372 /* Program the Transmit Control Register */
1374 tctl = E1000_READ_REG(hw, TCTL);
1376 tctl &= ~E1000_TCTL_CT;
1377 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1378 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1381 /* disable Multiple Reads for debugging */
1382 tctl &= ~E1000_TCTL_MULR;
1385 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1386 tarc = E1000_READ_REG(hw, TARC0);
1387 tarc |= ((1 << 25) | (1 << 21));
1388 E1000_WRITE_REG(hw, TARC0, tarc);
1389 tarc = E1000_READ_REG(hw, TARC1);
1391 if (tctl & E1000_TCTL_MULR)
1395 E1000_WRITE_REG(hw, TARC1, tarc);
1396 } else if (hw->mac_type == e1000_80003es2lan) {
1397 tarc = E1000_READ_REG(hw, TARC0);
1399 if (hw->media_type == e1000_media_type_internal_serdes)
1401 E1000_WRITE_REG(hw, TARC0, tarc);
1402 tarc = E1000_READ_REG(hw, TARC1);
1404 E1000_WRITE_REG(hw, TARC1, tarc);
1407 e1000_config_collision_dist(hw);
1409 /* Setup Transmit Descriptor Settings for eop descriptor */
1410 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1413 if (hw->mac_type < e1000_82543)
1414 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1416 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1418 /* Cache if we're 82544 running in PCI-X because we'll
1419 * need this to apply a workaround later in the send path. */
1420 if (hw->mac_type == e1000_82544 &&
1421 hw->bus_type == e1000_bus_type_pcix)
1422 adapter->pcix_82544 = 1;
1424 E1000_WRITE_REG(hw, TCTL, tctl);
1429 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1430 * @adapter: board private structure
1431 * @rxdr: rx descriptor ring (for a specific queue) to setup
1433 * Returns 0 on success, negative on failure
1437 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1438 struct e1000_rx_ring *rxdr)
1440 struct pci_dev *pdev = adapter->pdev;
1443 size = sizeof(struct e1000_buffer) * rxdr->count;
1444 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1445 if (!rxdr->buffer_info) {
1447 "Unable to allocate memory for the receive descriptor ring\n");
1450 memset(rxdr->buffer_info, 0, size);
1452 size = sizeof(struct e1000_ps_page) * rxdr->count;
1453 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1454 if (!rxdr->ps_page) {
1455 vfree(rxdr->buffer_info);
1457 "Unable to allocate memory for the receive descriptor ring\n");
1460 memset(rxdr->ps_page, 0, size);
1462 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1463 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1464 if (!rxdr->ps_page_dma) {
1465 vfree(rxdr->buffer_info);
1466 kfree(rxdr->ps_page);
1468 "Unable to allocate memory for the receive descriptor ring\n");
1471 memset(rxdr->ps_page_dma, 0, size);
1473 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1474 desc_len = sizeof(struct e1000_rx_desc);
1476 desc_len = sizeof(union e1000_rx_desc_packet_split);
1478 /* Round up to nearest 4K */
1480 rxdr->size = rxdr->count * desc_len;
1481 E1000_ROUNDUP(rxdr->size, 4096);
1483 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1487 "Unable to allocate memory for the receive descriptor ring\n");
1489 vfree(rxdr->buffer_info);
1490 kfree(rxdr->ps_page);
1491 kfree(rxdr->ps_page_dma);
1495 /* Fix for errata 23, can't cross 64kB boundary */
1496 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1497 void *olddesc = rxdr->desc;
1498 dma_addr_t olddma = rxdr->dma;
1499 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1500 "at %p\n", rxdr->size, rxdr->desc);
1501 /* Try again, without freeing the previous */
1502 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1503 /* Failed allocation, critical failure */
1505 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1507 "Unable to allocate memory "
1508 "for the receive descriptor ring\n");
1509 goto setup_rx_desc_die;
1512 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1514 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1516 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1518 "Unable to allocate aligned memory "
1519 "for the receive descriptor ring\n");
1520 goto setup_rx_desc_die;
1522 /* Free old allocation, new allocation was successful */
1523 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1526 memset(rxdr->desc, 0, rxdr->size);
1528 rxdr->next_to_clean = 0;
1529 rxdr->next_to_use = 0;
1535 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1536 * (Descriptors) for all queues
1537 * @adapter: board private structure
1539 * If this function returns with an error, then it's possible one or
1540 * more of the rings is populated (while the rest are not). It is the
1541 * callers duty to clean those orphaned rings.
1543 * Return 0 on success, negative on failure
1547 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1551 for (i = 0; i < adapter->num_rx_queues; i++) {
1552 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1555 "Allocation for Rx Queue %u failed\n", i);
1564 * e1000_setup_rctl - configure the receive control registers
1565 * @adapter: Board private structure
1567 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1568 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1570 e1000_setup_rctl(struct e1000_adapter *adapter)
1572 uint32_t rctl, rfctl;
1573 uint32_t psrctl = 0;
1574 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1578 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1580 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1582 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1583 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1584 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1586 if (adapter->hw.mac_type > e1000_82543)
1587 rctl |= E1000_RCTL_SECRC;
1589 if (adapter->hw.tbi_compatibility_on == 1)
1590 rctl |= E1000_RCTL_SBP;
1592 rctl &= ~E1000_RCTL_SBP;
1594 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1595 rctl &= ~E1000_RCTL_LPE;
1597 rctl |= E1000_RCTL_LPE;
1599 /* Setup buffer sizes */
1600 if (adapter->hw.mac_type >= e1000_82571) {
1601 /* We can now specify buffers in 1K increments.
1602 * BSIZE and BSEX are ignored in this case. */
1603 rctl |= adapter->rx_buffer_len << 0x11;
1605 rctl &= ~E1000_RCTL_SZ_4096;
1606 rctl |= E1000_RCTL_BSEX;
1607 switch (adapter->rx_buffer_len) {
1608 case E1000_RXBUFFER_2048:
1610 rctl |= E1000_RCTL_SZ_2048;
1611 rctl &= ~E1000_RCTL_BSEX;
1613 case E1000_RXBUFFER_4096:
1614 rctl |= E1000_RCTL_SZ_4096;
1616 case E1000_RXBUFFER_8192:
1617 rctl |= E1000_RCTL_SZ_8192;
1619 case E1000_RXBUFFER_16384:
1620 rctl |= E1000_RCTL_SZ_16384;
1625 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1626 /* 82571 and greater support packet-split where the protocol
1627 * header is placed in skb->data and the packet data is
1628 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1629 * In the case of a non-split, skb->data is linearly filled,
1630 * followed by the page buffers. Therefore, skb->data is
1631 * sized to hold the largest protocol header.
1633 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1634 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1636 adapter->rx_ps_pages = pages;
1638 adapter->rx_ps_pages = 0;
1640 if (adapter->rx_ps_pages) {
1641 /* Configure extra packet-split registers */
1642 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1643 rfctl |= E1000_RFCTL_EXTEN;
1644 /* disable IPv6 packet split support */
1645 rfctl |= E1000_RFCTL_IPV6_DIS;
1646 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1648 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1650 psrctl |= adapter->rx_ps_bsize0 >>
1651 E1000_PSRCTL_BSIZE0_SHIFT;
1653 switch (adapter->rx_ps_pages) {
1655 psrctl |= PAGE_SIZE <<
1656 E1000_PSRCTL_BSIZE3_SHIFT;
1658 psrctl |= PAGE_SIZE <<
1659 E1000_PSRCTL_BSIZE2_SHIFT;
1661 psrctl |= PAGE_SIZE >>
1662 E1000_PSRCTL_BSIZE1_SHIFT;
1666 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1669 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1673 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1674 * @adapter: board private structure
1676 * Configure the Rx unit of the MAC after a reset.
1680 e1000_configure_rx(struct e1000_adapter *adapter)
1683 struct e1000_hw *hw = &adapter->hw;
1684 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1686 if (adapter->rx_ps_pages) {
1687 /* this is a 32 byte descriptor */
1688 rdlen = adapter->rx_ring[0].count *
1689 sizeof(union e1000_rx_desc_packet_split);
1690 adapter->clean_rx = e1000_clean_rx_irq_ps;
1691 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1693 rdlen = adapter->rx_ring[0].count *
1694 sizeof(struct e1000_rx_desc);
1695 adapter->clean_rx = e1000_clean_rx_irq;
1696 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1699 /* disable receives while setting up the descriptors */
1700 rctl = E1000_READ_REG(hw, RCTL);
1701 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1703 /* set the Receive Delay Timer Register */
1704 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1706 if (hw->mac_type >= e1000_82540) {
1707 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1708 if (adapter->itr > 1)
1709 E1000_WRITE_REG(hw, ITR,
1710 1000000000 / (adapter->itr * 256));
1713 if (hw->mac_type >= e1000_82571) {
1714 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1715 /* Reset delay timers after every interrupt */
1716 ctrl_ext |= E1000_CTRL_EXT_CANC;
1717 #ifdef CONFIG_E1000_NAPI
1718 /* Auto-Mask interrupts upon ICR read. */
1719 ctrl_ext |= E1000_CTRL_EXT_IAME;
1721 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1722 E1000_WRITE_REG(hw, IAM, ~0);
1723 E1000_WRITE_FLUSH(hw);
1726 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1727 * the Base and Length of the Rx Descriptor Ring */
1728 switch (adapter->num_rx_queues) {
1731 rdba = adapter->rx_ring[0].dma;
1732 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1733 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1734 E1000_WRITE_REG(hw, RDLEN, rdlen);
1735 E1000_WRITE_REG(hw, RDH, 0);
1736 E1000_WRITE_REG(hw, RDT, 0);
1737 adapter->rx_ring[0].rdh = E1000_RDH;
1738 adapter->rx_ring[0].rdt = E1000_RDT;
1742 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1743 if (hw->mac_type >= e1000_82543) {
1744 rxcsum = E1000_READ_REG(hw, RXCSUM);
1745 if (adapter->rx_csum == TRUE) {
1746 rxcsum |= E1000_RXCSUM_TUOFL;
1748 /* Enable 82571 IPv4 payload checksum for UDP fragments
1749 * Must be used in conjunction with packet-split. */
1750 if ((hw->mac_type >= e1000_82571) &&
1751 (adapter->rx_ps_pages)) {
1752 rxcsum |= E1000_RXCSUM_IPPCSE;
1755 rxcsum &= ~E1000_RXCSUM_TUOFL;
1756 /* don't need to clear IPPCSE as it defaults to 0 */
1758 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1761 if (hw->mac_type == e1000_82573)
1762 E1000_WRITE_REG(hw, ERT, 0x0100);
1764 /* Enable Receives */
1765 E1000_WRITE_REG(hw, RCTL, rctl);
1769 * e1000_free_tx_resources - Free Tx Resources per Queue
1770 * @adapter: board private structure
1771 * @tx_ring: Tx descriptor ring for a specific queue
1773 * Free all transmit software resources
1777 e1000_free_tx_resources(struct e1000_adapter *adapter,
1778 struct e1000_tx_ring *tx_ring)
1780 struct pci_dev *pdev = adapter->pdev;
1782 e1000_clean_tx_ring(adapter, tx_ring);
1784 vfree(tx_ring->buffer_info);
1785 tx_ring->buffer_info = NULL;
1787 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1789 tx_ring->desc = NULL;
1793 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1794 * @adapter: board private structure
1796 * Free all transmit software resources
1800 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1804 for (i = 0; i < adapter->num_tx_queues; i++)
1805 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1809 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1810 struct e1000_buffer *buffer_info)
1812 if (buffer_info->dma) {
1813 pci_unmap_page(adapter->pdev,
1815 buffer_info->length,
1818 if (buffer_info->skb)
1819 dev_kfree_skb_any(buffer_info->skb);
1820 memset(buffer_info, 0, sizeof(struct e1000_buffer));
1824 * e1000_clean_tx_ring - Free Tx Buffers
1825 * @adapter: board private structure
1826 * @tx_ring: ring to be cleaned
1830 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1831 struct e1000_tx_ring *tx_ring)
1833 struct e1000_buffer *buffer_info;
1837 /* Free all the Tx ring sk_buffs */
1839 for (i = 0; i < tx_ring->count; i++) {
1840 buffer_info = &tx_ring->buffer_info[i];
1841 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1844 size = sizeof(struct e1000_buffer) * tx_ring->count;
1845 memset(tx_ring->buffer_info, 0, size);
1847 /* Zero out the descriptor ring */
1849 memset(tx_ring->desc, 0, tx_ring->size);
1851 tx_ring->next_to_use = 0;
1852 tx_ring->next_to_clean = 0;
1853 tx_ring->last_tx_tso = 0;
1855 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1856 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1860 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1861 * @adapter: board private structure
1865 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1869 for (i = 0; i < adapter->num_tx_queues; i++)
1870 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1874 * e1000_free_rx_resources - Free Rx Resources
1875 * @adapter: board private structure
1876 * @rx_ring: ring to clean the resources from
1878 * Free all receive software resources
1882 e1000_free_rx_resources(struct e1000_adapter *adapter,
1883 struct e1000_rx_ring *rx_ring)
1885 struct pci_dev *pdev = adapter->pdev;
1887 e1000_clean_rx_ring(adapter, rx_ring);
1889 vfree(rx_ring->buffer_info);
1890 rx_ring->buffer_info = NULL;
1891 kfree(rx_ring->ps_page);
1892 rx_ring->ps_page = NULL;
1893 kfree(rx_ring->ps_page_dma);
1894 rx_ring->ps_page_dma = NULL;
1896 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1898 rx_ring->desc = NULL;
1902 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1903 * @adapter: board private structure
1905 * Free all receive software resources
1909 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1913 for (i = 0; i < adapter->num_rx_queues; i++)
1914 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1918 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1919 * @adapter: board private structure
1920 * @rx_ring: ring to free buffers from
1924 e1000_clean_rx_ring(struct e1000_adapter *adapter,
1925 struct e1000_rx_ring *rx_ring)
1927 struct e1000_buffer *buffer_info;
1928 struct e1000_ps_page *ps_page;
1929 struct e1000_ps_page_dma *ps_page_dma;
1930 struct pci_dev *pdev = adapter->pdev;
1934 /* Free all the Rx ring sk_buffs */
1935 for (i = 0; i < rx_ring->count; i++) {
1936 buffer_info = &rx_ring->buffer_info[i];
1937 if (buffer_info->skb) {
1938 pci_unmap_single(pdev,
1940 buffer_info->length,
1941 PCI_DMA_FROMDEVICE);
1943 dev_kfree_skb(buffer_info->skb);
1944 buffer_info->skb = NULL;
1946 ps_page = &rx_ring->ps_page[i];
1947 ps_page_dma = &rx_ring->ps_page_dma[i];
1948 for (j = 0; j < adapter->rx_ps_pages; j++) {
1949 if (!ps_page->ps_page[j]) break;
1950 pci_unmap_page(pdev,
1951 ps_page_dma->ps_page_dma[j],
1952 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1953 ps_page_dma->ps_page_dma[j] = 0;
1954 put_page(ps_page->ps_page[j]);
1955 ps_page->ps_page[j] = NULL;
1959 size = sizeof(struct e1000_buffer) * rx_ring->count;
1960 memset(rx_ring->buffer_info, 0, size);
1961 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1962 memset(rx_ring->ps_page, 0, size);
1963 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1964 memset(rx_ring->ps_page_dma, 0, size);
1966 /* Zero out the descriptor ring */
1968 memset(rx_ring->desc, 0, rx_ring->size);
1970 rx_ring->next_to_clean = 0;
1971 rx_ring->next_to_use = 0;
1973 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1974 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1978 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1979 * @adapter: board private structure
1983 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1987 for (i = 0; i < adapter->num_rx_queues; i++)
1988 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1991 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1992 * and memory write and invalidate disabled for certain operations
1995 e1000_enter_82542_rst(struct e1000_adapter *adapter)
1997 struct net_device *netdev = adapter->netdev;
2000 e1000_pci_clear_mwi(&adapter->hw);
2002 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2003 rctl |= E1000_RCTL_RST;
2004 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2005 E1000_WRITE_FLUSH(&adapter->hw);
2008 if (netif_running(netdev))
2009 e1000_clean_all_rx_rings(adapter);
2013 e1000_leave_82542_rst(struct e1000_adapter *adapter)
2015 struct net_device *netdev = adapter->netdev;
2018 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2019 rctl &= ~E1000_RCTL_RST;
2020 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2021 E1000_WRITE_FLUSH(&adapter->hw);
2024 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2025 e1000_pci_set_mwi(&adapter->hw);
2027 if (netif_running(netdev)) {
2028 /* No need to loop, because 82542 supports only 1 queue */
2029 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2030 e1000_configure_rx(adapter);
2031 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2036 * e1000_set_mac - Change the Ethernet Address of the NIC
2037 * @netdev: network interface device structure
2038 * @p: pointer to an address structure
2040 * Returns 0 on success, negative on failure
2044 e1000_set_mac(struct net_device *netdev, void *p)
2046 struct e1000_adapter *adapter = netdev_priv(netdev);
2047 struct sockaddr *addr = p;
2049 if (!is_valid_ether_addr(addr->sa_data))
2050 return -EADDRNOTAVAIL;
2052 /* 82542 2.0 needs to be in reset to write receive address registers */
2054 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2055 e1000_enter_82542_rst(adapter);
2057 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2058 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2060 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2062 /* With 82571 controllers, LAA may be overwritten (with the default)
2063 * due to controller reset from the other port. */
2064 if (adapter->hw.mac_type == e1000_82571) {
2065 /* activate the work around */
2066 adapter->hw.laa_is_present = 1;
2068 /* Hold a copy of the LAA in RAR[14] This is done so that
2069 * between the time RAR[0] gets clobbered and the time it
2070 * gets fixed (in e1000_watchdog), the actual LAA is in one
2071 * of the RARs and no incoming packets directed to this port
2072 * are dropped. Eventaully the LAA will be in RAR[0] and
2074 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2075 E1000_RAR_ENTRIES - 1);
2078 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2079 e1000_leave_82542_rst(adapter);
2085 * e1000_set_multi - Multicast and Promiscuous mode set
2086 * @netdev: network interface device structure
2088 * The set_multi entry point is called whenever the multicast address
2089 * list or the network interface flags are updated. This routine is
2090 * responsible for configuring the hardware for proper multicast,
2091 * promiscuous mode, and all-multi behavior.
2095 e1000_set_multi(struct net_device *netdev)
2097 struct e1000_adapter *adapter = netdev_priv(netdev);
2098 struct e1000_hw *hw = &adapter->hw;
2099 struct dev_mc_list *mc_ptr;
2101 uint32_t hash_value;
2102 int i, rar_entries = E1000_RAR_ENTRIES;
2104 /* reserve RAR[14] for LAA over-write work-around */
2105 if (adapter->hw.mac_type == e1000_82571)
2108 /* Check for Promiscuous and All Multicast modes */
2110 rctl = E1000_READ_REG(hw, RCTL);
2112 if (netdev->flags & IFF_PROMISC) {
2113 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2114 } else if (netdev->flags & IFF_ALLMULTI) {
2115 rctl |= E1000_RCTL_MPE;
2116 rctl &= ~E1000_RCTL_UPE;
2118 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2121 E1000_WRITE_REG(hw, RCTL, rctl);
2123 /* 82542 2.0 needs to be in reset to write receive address registers */
2125 if (hw->mac_type == e1000_82542_rev2_0)
2126 e1000_enter_82542_rst(adapter);
2128 /* load the first 14 multicast address into the exact filters 1-14
2129 * RAR 0 is used for the station MAC adddress
2130 * if there are not 14 addresses, go ahead and clear the filters
2131 * -- with 82571 controllers only 0-13 entries are filled here
2133 mc_ptr = netdev->mc_list;
2135 for (i = 1; i < rar_entries; i++) {
2137 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2138 mc_ptr = mc_ptr->next;
2140 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2141 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2145 /* clear the old settings from the multicast hash table */
2147 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2148 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2150 /* load any remaining addresses into the hash table */
2152 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2153 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2154 e1000_mta_set(hw, hash_value);
2157 if (hw->mac_type == e1000_82542_rev2_0)
2158 e1000_leave_82542_rst(adapter);
2161 /* Need to wait a few seconds after link up to get diagnostic information from
2165 e1000_update_phy_info(unsigned long data)
2167 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2168 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2172 * e1000_82547_tx_fifo_stall - Timer Call-back
2173 * @data: pointer to adapter cast into an unsigned long
2177 e1000_82547_tx_fifo_stall(unsigned long data)
2179 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2180 struct net_device *netdev = adapter->netdev;
2183 if (atomic_read(&adapter->tx_fifo_stall)) {
2184 if ((E1000_READ_REG(&adapter->hw, TDT) ==
2185 E1000_READ_REG(&adapter->hw, TDH)) &&
2186 (E1000_READ_REG(&adapter->hw, TDFT) ==
2187 E1000_READ_REG(&adapter->hw, TDFH)) &&
2188 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2189 E1000_READ_REG(&adapter->hw, TDFHS))) {
2190 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2191 E1000_WRITE_REG(&adapter->hw, TCTL,
2192 tctl & ~E1000_TCTL_EN);
2193 E1000_WRITE_REG(&adapter->hw, TDFT,
2194 adapter->tx_head_addr);
2195 E1000_WRITE_REG(&adapter->hw, TDFH,
2196 adapter->tx_head_addr);
2197 E1000_WRITE_REG(&adapter->hw, TDFTS,
2198 adapter->tx_head_addr);
2199 E1000_WRITE_REG(&adapter->hw, TDFHS,
2200 adapter->tx_head_addr);
2201 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2202 E1000_WRITE_FLUSH(&adapter->hw);
2204 adapter->tx_fifo_head = 0;
2205 atomic_set(&adapter->tx_fifo_stall, 0);
2206 netif_wake_queue(netdev);
2208 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2214 * e1000_watchdog - Timer Call-back
2215 * @data: pointer to adapter cast into an unsigned long
2218 e1000_watchdog(unsigned long data)
2220 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2222 /* Do the rest outside of interrupt context */
2223 schedule_work(&adapter->watchdog_task);
2227 e1000_watchdog_task(struct e1000_adapter *adapter)
2229 struct net_device *netdev = adapter->netdev;
2230 struct e1000_tx_ring *txdr = adapter->tx_ring;
2231 uint32_t link, tctl;
2233 e1000_check_for_link(&adapter->hw);
2234 if (adapter->hw.mac_type == e1000_82573) {
2235 e1000_enable_tx_pkt_filtering(&adapter->hw);
2236 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2237 e1000_update_mng_vlan(adapter);
2240 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2241 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2242 link = !adapter->hw.serdes_link_down;
2244 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2247 if (!netif_carrier_ok(netdev)) {
2248 e1000_get_speed_and_duplex(&adapter->hw,
2249 &adapter->link_speed,
2250 &adapter->link_duplex);
2252 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2253 adapter->link_speed,
2254 adapter->link_duplex == FULL_DUPLEX ?
2255 "Full Duplex" : "Half Duplex");
2257 /* tweak tx_queue_len according to speed/duplex
2258 * and adjust the timeout factor */
2259 netdev->tx_queue_len = adapter->tx_queue_len;
2260 adapter->tx_timeout_factor = 1;
2262 switch (adapter->link_speed) {
2265 netdev->tx_queue_len = 10;
2266 adapter->tx_timeout_factor = 8;
2270 netdev->tx_queue_len = 100;
2271 /* maybe add some timeout factor ? */
2275 if ((adapter->hw.mac_type == e1000_82571 ||
2276 adapter->hw.mac_type == e1000_82572) &&
2277 adapter->txb2b == 0) {
2278 #define SPEED_MODE_BIT (1 << 21)
2280 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2281 tarc0 &= ~SPEED_MODE_BIT;
2282 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2286 /* disable TSO for pcie and 10/100 speeds, to avoid
2287 * some hardware issues */
2288 if (!adapter->tso_force &&
2289 adapter->hw.bus_type == e1000_bus_type_pci_express){
2290 switch (adapter->link_speed) {
2294 "10/100 speed: disabling TSO\n");
2295 netdev->features &= ~NETIF_F_TSO;
2298 netdev->features |= NETIF_F_TSO;
2307 /* enable transmits in the hardware, need to do this
2308 * after setting TARC0 */
2309 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2310 tctl |= E1000_TCTL_EN;
2311 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2313 netif_carrier_on(netdev);
2314 netif_wake_queue(netdev);
2315 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2316 adapter->smartspeed = 0;
2319 if (netif_carrier_ok(netdev)) {
2320 adapter->link_speed = 0;
2321 adapter->link_duplex = 0;
2322 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2323 netif_carrier_off(netdev);
2324 netif_stop_queue(netdev);
2325 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2327 /* 80003ES2LAN workaround--
2328 * For packet buffer work-around on link down event;
2329 * disable receives in the ISR and
2330 * reset device here in the watchdog
2332 if (adapter->hw.mac_type == e1000_80003es2lan) {
2334 schedule_work(&adapter->reset_task);
2338 e1000_smartspeed(adapter);
2341 e1000_update_stats(adapter);
2343 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2344 adapter->tpt_old = adapter->stats.tpt;
2345 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2346 adapter->colc_old = adapter->stats.colc;
2348 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2349 adapter->gorcl_old = adapter->stats.gorcl;
2350 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2351 adapter->gotcl_old = adapter->stats.gotcl;
2353 e1000_update_adaptive(&adapter->hw);
2355 if (!netif_carrier_ok(netdev)) {
2356 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2357 /* We've lost link, so the controller stops DMA,
2358 * but we've got queued Tx work that's never going
2359 * to get done, so reset controller to flush Tx.
2360 * (Do the reset outside of interrupt context). */
2361 adapter->tx_timeout_count++;
2362 schedule_work(&adapter->reset_task);
2366 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2367 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2368 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2369 * asymmetrical Tx or Rx gets ITR=8000; everyone
2370 * else is between 2000-8000. */
2371 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2372 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2373 adapter->gotcl - adapter->gorcl :
2374 adapter->gorcl - adapter->gotcl) / 10000;
2375 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2376 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2379 /* Cause software interrupt to ensure rx ring is cleaned */
2380 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2382 /* Force detection of hung controller every watchdog period */
2383 adapter->detect_tx_hung = TRUE;
2385 /* With 82571 controllers, LAA may be overwritten due to controller
2386 * reset from the other port. Set the appropriate LAA in RAR[0] */
2387 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2388 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2390 /* Reset the timer */
2391 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2394 #define E1000_TX_FLAGS_CSUM 0x00000001
2395 #define E1000_TX_FLAGS_VLAN 0x00000002
2396 #define E1000_TX_FLAGS_TSO 0x00000004
2397 #define E1000_TX_FLAGS_IPV4 0x00000008
2398 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2399 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2402 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2403 struct sk_buff *skb)
2406 struct e1000_context_desc *context_desc;
2407 struct e1000_buffer *buffer_info;
2409 uint32_t cmd_length = 0;
2410 uint16_t ipcse = 0, tucse, mss;
2411 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2414 if (skb_shinfo(skb)->tso_size) {
2415 if (skb_header_cloned(skb)) {
2416 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2421 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2422 mss = skb_shinfo(skb)->tso_size;
2423 if (skb->protocol == ntohs(ETH_P_IP)) {
2424 skb->nh.iph->tot_len = 0;
2425 skb->nh.iph->check = 0;
2427 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2432 cmd_length = E1000_TXD_CMD_IP;
2433 ipcse = skb->h.raw - skb->data - 1;
2434 #ifdef NETIF_F_TSO_IPV6
2435 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
2436 skb->nh.ipv6h->payload_len = 0;
2438 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2439 &skb->nh.ipv6h->daddr,
2446 ipcss = skb->nh.raw - skb->data;
2447 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2448 tucss = skb->h.raw - skb->data;
2449 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2452 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2453 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2455 i = tx_ring->next_to_use;
2456 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2457 buffer_info = &tx_ring->buffer_info[i];
2459 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2460 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2461 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2462 context_desc->upper_setup.tcp_fields.tucss = tucss;
2463 context_desc->upper_setup.tcp_fields.tucso = tucso;
2464 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2465 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2466 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2467 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2469 buffer_info->time_stamp = jiffies;
2471 if (++i == tx_ring->count) i = 0;
2472 tx_ring->next_to_use = i;
2481 static inline boolean_t
2482 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2483 struct sk_buff *skb)
2485 struct e1000_context_desc *context_desc;
2486 struct e1000_buffer *buffer_info;
2490 if (likely(skb->ip_summed == CHECKSUM_HW)) {
2491 css = skb->h.raw - skb->data;
2493 i = tx_ring->next_to_use;
2494 buffer_info = &tx_ring->buffer_info[i];
2495 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2497 context_desc->upper_setup.tcp_fields.tucss = css;
2498 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2499 context_desc->upper_setup.tcp_fields.tucse = 0;
2500 context_desc->tcp_seg_setup.data = 0;
2501 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2503 buffer_info->time_stamp = jiffies;
2505 if (unlikely(++i == tx_ring->count)) i = 0;
2506 tx_ring->next_to_use = i;
2514 #define E1000_MAX_TXD_PWR 12
2515 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2518 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2519 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2520 unsigned int nr_frags, unsigned int mss)
2522 struct e1000_buffer *buffer_info;
2523 unsigned int len = skb->len;
2524 unsigned int offset = 0, size, count = 0, i;
2526 len -= skb->data_len;
2528 i = tx_ring->next_to_use;
2531 buffer_info = &tx_ring->buffer_info[i];
2532 size = min(len, max_per_txd);
2534 /* Workaround for Controller erratum --
2535 * descriptor for non-tso packet in a linear SKB that follows a
2536 * tso gets written back prematurely before the data is fully
2537 * DMA'd to the controller */
2538 if (!skb->data_len && tx_ring->last_tx_tso &&
2539 !skb_shinfo(skb)->tso_size) {
2540 tx_ring->last_tx_tso = 0;
2544 /* Workaround for premature desc write-backs
2545 * in TSO mode. Append 4-byte sentinel desc */
2546 if (unlikely(mss && !nr_frags && size == len && size > 8))
2549 /* work-around for errata 10 and it applies
2550 * to all controllers in PCI-X mode
2551 * The fix is to make sure that the first descriptor of a
2552 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2554 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2555 (size > 2015) && count == 0))
2558 /* Workaround for potential 82544 hang in PCI-X. Avoid
2559 * terminating buffers within evenly-aligned dwords. */
2560 if (unlikely(adapter->pcix_82544 &&
2561 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2565 buffer_info->length = size;
2567 pci_map_single(adapter->pdev,
2571 buffer_info->time_stamp = jiffies;
2576 if (unlikely(++i == tx_ring->count)) i = 0;
2579 for (f = 0; f < nr_frags; f++) {
2580 struct skb_frag_struct *frag;
2582 frag = &skb_shinfo(skb)->frags[f];
2584 offset = frag->page_offset;
2587 buffer_info = &tx_ring->buffer_info[i];
2588 size = min(len, max_per_txd);
2590 /* Workaround for premature desc write-backs
2591 * in TSO mode. Append 4-byte sentinel desc */
2592 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2595 /* Workaround for potential 82544 hang in PCI-X.
2596 * Avoid terminating buffers within evenly-aligned
2598 if (unlikely(adapter->pcix_82544 &&
2599 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2603 buffer_info->length = size;
2605 pci_map_page(adapter->pdev,
2610 buffer_info->time_stamp = jiffies;
2615 if (unlikely(++i == tx_ring->count)) i = 0;
2619 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2620 tx_ring->buffer_info[i].skb = skb;
2621 tx_ring->buffer_info[first].next_to_watch = i;
2627 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2628 int tx_flags, int count)
2630 struct e1000_tx_desc *tx_desc = NULL;
2631 struct e1000_buffer *buffer_info;
2632 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2635 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2636 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2638 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2640 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2641 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2644 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2645 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2646 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2649 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2650 txd_lower |= E1000_TXD_CMD_VLE;
2651 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2654 i = tx_ring->next_to_use;
2657 buffer_info = &tx_ring->buffer_info[i];
2658 tx_desc = E1000_TX_DESC(*tx_ring, i);
2659 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2660 tx_desc->lower.data =
2661 cpu_to_le32(txd_lower | buffer_info->length);
2662 tx_desc->upper.data = cpu_to_le32(txd_upper);
2663 if (unlikely(++i == tx_ring->count)) i = 0;
2666 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2668 /* Force memory writes to complete before letting h/w
2669 * know there are new descriptors to fetch. (Only
2670 * applicable for weak-ordered memory model archs,
2671 * such as IA-64). */
2674 tx_ring->next_to_use = i;
2675 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2679 * 82547 workaround to avoid controller hang in half-duplex environment.
2680 * The workaround is to avoid queuing a large packet that would span
2681 * the internal Tx FIFO ring boundary by notifying the stack to resend
2682 * the packet at a later time. This gives the Tx FIFO an opportunity to
2683 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2684 * to the beginning of the Tx FIFO.
2687 #define E1000_FIFO_HDR 0x10
2688 #define E1000_82547_PAD_LEN 0x3E0
2691 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2693 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2694 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2696 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2698 if (adapter->link_duplex != HALF_DUPLEX)
2699 goto no_fifo_stall_required;
2701 if (atomic_read(&adapter->tx_fifo_stall))
2704 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2705 atomic_set(&adapter->tx_fifo_stall, 1);
2709 no_fifo_stall_required:
2710 adapter->tx_fifo_head += skb_fifo_len;
2711 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
2712 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2716 #define MINIMUM_DHCP_PACKET_SIZE 282
2718 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2720 struct e1000_hw *hw = &adapter->hw;
2721 uint16_t length, offset;
2722 if (vlan_tx_tag_present(skb)) {
2723 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2724 ( adapter->hw.mng_cookie.status &
2725 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2728 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
2729 struct ethhdr *eth = (struct ethhdr *) skb->data;
2730 if ((htons(ETH_P_IP) == eth->h_proto)) {
2731 const struct iphdr *ip =
2732 (struct iphdr *)((uint8_t *)skb->data+14);
2733 if (IPPROTO_UDP == ip->protocol) {
2734 struct udphdr *udp =
2735 (struct udphdr *)((uint8_t *)ip +
2737 if (ntohs(udp->dest) == 67) {
2738 offset = (uint8_t *)udp + 8 - skb->data;
2739 length = skb->len - offset;
2741 return e1000_mng_write_dhcp_info(hw,
2751 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2753 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2755 struct e1000_adapter *adapter = netdev_priv(netdev);
2756 struct e1000_tx_ring *tx_ring;
2757 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2758 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2759 unsigned int tx_flags = 0;
2760 unsigned int len = skb->len;
2761 unsigned long flags;
2762 unsigned int nr_frags = 0;
2763 unsigned int mss = 0;
2767 len -= skb->data_len;
2769 tx_ring = adapter->tx_ring;
2771 if (unlikely(skb->len <= 0)) {
2772 dev_kfree_skb_any(skb);
2773 return NETDEV_TX_OK;
2777 mss = skb_shinfo(skb)->tso_size;
2778 /* The controller does a simple calculation to
2779 * make sure there is enough room in the FIFO before
2780 * initiating the DMA for each buffer. The calc is:
2781 * 4 = ceil(buffer len/mss). To make sure we don't
2782 * overrun the FIFO, adjust the max buffer len if mss
2786 max_per_txd = min(mss << 2, max_per_txd);
2787 max_txd_pwr = fls(max_per_txd) - 1;
2789 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
2790 * points to just header, pull a few bytes of payload from
2791 * frags into skb->data */
2792 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2793 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
2794 switch (adapter->hw.mac_type) {
2795 unsigned int pull_size;
2799 pull_size = min((unsigned int)4, skb->data_len);
2800 if (!__pskb_pull_tail(skb, pull_size)) {
2802 "__pskb_pull_tail failed.\n");
2803 dev_kfree_skb_any(skb);
2804 return NETDEV_TX_OK;
2806 len = skb->len - skb->data_len;
2815 /* reserve a descriptor for the offload context */
2816 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
2820 if (skb->ip_summed == CHECKSUM_HW)
2825 /* Controller Erratum workaround */
2826 if (!skb->data_len && tx_ring->last_tx_tso &&
2827 !skb_shinfo(skb)->tso_size)
2831 count += TXD_USE_COUNT(len, max_txd_pwr);
2833 if (adapter->pcix_82544)
2836 /* work-around for errata 10 and it applies to all controllers
2837 * in PCI-X mode, so add one more descriptor to the count
2839 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2843 nr_frags = skb_shinfo(skb)->nr_frags;
2844 for (f = 0; f < nr_frags; f++)
2845 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2847 if (adapter->pcix_82544)
2851 if (adapter->hw.tx_pkt_filtering &&
2852 (adapter->hw.mac_type == e1000_82573))
2853 e1000_transfer_dhcp_info(adapter, skb);
2855 local_irq_save(flags);
2856 if (!spin_trylock(&tx_ring->tx_lock)) {
2857 /* Collision - tell upper layer to requeue */
2858 local_irq_restore(flags);
2859 return NETDEV_TX_LOCKED;
2862 /* need: count + 2 desc gap to keep tail from touching
2863 * head, otherwise try next time */
2864 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2865 netif_stop_queue(netdev);
2866 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2867 return NETDEV_TX_BUSY;
2870 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2871 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2872 netif_stop_queue(netdev);
2873 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2874 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2875 return NETDEV_TX_BUSY;
2879 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2880 tx_flags |= E1000_TX_FLAGS_VLAN;
2881 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2884 first = tx_ring->next_to_use;
2886 tso = e1000_tso(adapter, tx_ring, skb);
2888 dev_kfree_skb_any(skb);
2889 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2890 return NETDEV_TX_OK;
2894 tx_ring->last_tx_tso = 1;
2895 tx_flags |= E1000_TX_FLAGS_TSO;
2896 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
2897 tx_flags |= E1000_TX_FLAGS_CSUM;
2899 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2900 * 82571 hardware supports TSO capabilities for IPv6 as well...
2901 * no longer assume, we must. */
2902 if (likely(skb->protocol == ntohs(ETH_P_IP)))
2903 tx_flags |= E1000_TX_FLAGS_IPV4;
2905 e1000_tx_queue(adapter, tx_ring, tx_flags,
2906 e1000_tx_map(adapter, tx_ring, skb, first,
2907 max_per_txd, nr_frags, mss));
2909 netdev->trans_start = jiffies;
2911 /* Make sure there is space in the ring for the next send. */
2912 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
2913 netif_stop_queue(netdev);
2915 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2916 return NETDEV_TX_OK;
2920 * e1000_tx_timeout - Respond to a Tx Hang
2921 * @netdev: network interface device structure
2925 e1000_tx_timeout(struct net_device *netdev)
2927 struct e1000_adapter *adapter = netdev_priv(netdev);
2929 /* Do the reset outside of interrupt context */
2930 adapter->tx_timeout_count++;
2931 schedule_work(&adapter->reset_task);
2935 e1000_reset_task(struct net_device *netdev)
2937 struct e1000_adapter *adapter = netdev_priv(netdev);
2939 e1000_down(adapter);
2944 * e1000_get_stats - Get System Network Statistics
2945 * @netdev: network interface device structure
2947 * Returns the address of the device statistics structure.
2948 * The statistics are actually updated from the timer callback.
2951 static struct net_device_stats *
2952 e1000_get_stats(struct net_device *netdev)
2954 struct e1000_adapter *adapter = netdev_priv(netdev);
2956 /* only return the current stats */
2957 return &adapter->net_stats;
2961 * e1000_change_mtu - Change the Maximum Transfer Unit
2962 * @netdev: network interface device structure
2963 * @new_mtu: new value for maximum frame size
2965 * Returns 0 on success, negative on failure
2969 e1000_change_mtu(struct net_device *netdev, int new_mtu)
2971 struct e1000_adapter *adapter = netdev_priv(netdev);
2972 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2973 uint16_t eeprom_data = 0;
2975 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2976 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2977 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2981 /* Adapter-specific max frame size limits. */
2982 switch (adapter->hw.mac_type) {
2983 case e1000_82542_rev2_0:
2984 case e1000_82542_rev2_1:
2985 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2986 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
2991 /* only enable jumbo frames if ASPM is disabled completely
2992 * this means both bits must be zero in 0x1A bits 3:2 */
2993 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
2995 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
2996 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2998 "Jumbo Frames not supported.\n");
3003 /* fall through to get support */
3006 case e1000_80003es2lan:
3007 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3008 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3009 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3014 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3019 if (adapter->hw.mac_type > e1000_82547_rev_2) {
3020 adapter->rx_buffer_len = max_frame;
3021 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
3023 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
3024 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
3025 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
3029 if(max_frame <= E1000_RXBUFFER_2048)
3030 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3031 else if(max_frame <= E1000_RXBUFFER_4096)
3032 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3033 else if(max_frame <= E1000_RXBUFFER_8192)
3034 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3035 else if(max_frame <= E1000_RXBUFFER_16384)
3036 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3040 netdev->mtu = new_mtu;
3042 if (netif_running(netdev)) {
3043 e1000_down(adapter);
3047 adapter->hw.max_frame_size = max_frame;
3053 * e1000_update_stats - Update the board statistics counters
3054 * @adapter: board private structure
3058 e1000_update_stats(struct e1000_adapter *adapter)
3060 struct e1000_hw *hw = &adapter->hw;
3061 unsigned long flags;
3064 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3066 spin_lock_irqsave(&adapter->stats_lock, flags);
3068 /* these counters are modified from e1000_adjust_tbi_stats,
3069 * called from the interrupt context, so they must only
3070 * be written while holding adapter->stats_lock
3073 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3074 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3075 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3076 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3077 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3078 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3079 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3080 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3081 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3082 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3083 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3084 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3085 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3087 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3088 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3089 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3090 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3091 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3092 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3093 adapter->stats.dc += E1000_READ_REG(hw, DC);
3094 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3095 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3096 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3097 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3098 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3099 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3100 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3101 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3102 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3103 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3104 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3105 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3106 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3107 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3108 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3109 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3110 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3111 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3112 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3113 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3114 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3115 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3116 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3117 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3118 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3119 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3120 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3122 /* used for adaptive IFS */
3124 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3125 adapter->stats.tpt += hw->tx_packet_delta;
3126 hw->collision_delta = E1000_READ_REG(hw, COLC);
3127 adapter->stats.colc += hw->collision_delta;
3129 if (hw->mac_type >= e1000_82543) {
3130 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3131 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3132 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3133 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3134 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3135 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3137 if (hw->mac_type > e1000_82547_rev_2) {
3138 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3139 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3140 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3141 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3142 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3143 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3144 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3145 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3146 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3149 /* Fill out the OS statistics structure */
3151 adapter->net_stats.rx_packets = adapter->stats.gprc;
3152 adapter->net_stats.tx_packets = adapter->stats.gptc;
3153 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3154 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3155 adapter->net_stats.multicast = adapter->stats.mprc;
3156 adapter->net_stats.collisions = adapter->stats.colc;
3160 /* RLEC on some newer hardware can be incorrect so build
3161 * our own version based on RUC and ROC */
3162 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3163 adapter->stats.crcerrs + adapter->stats.algnerrc +
3164 adapter->stats.ruc + adapter->stats.roc +
3165 adapter->stats.cexterr;
3166 adapter->net_stats.rx_dropped = 0;
3167 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3169 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3170 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3171 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3175 adapter->net_stats.tx_errors = adapter->stats.ecol +
3176 adapter->stats.latecol;
3177 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3178 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3179 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3181 /* Tx Dropped needs to be maintained elsewhere */
3185 if (hw->media_type == e1000_media_type_copper) {
3186 if ((adapter->link_speed == SPEED_1000) &&
3187 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3188 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3189 adapter->phy_stats.idle_errors += phy_tmp;
3192 if ((hw->mac_type <= e1000_82546) &&
3193 (hw->phy_type == e1000_phy_m88) &&
3194 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3195 adapter->phy_stats.receive_errors += phy_tmp;
3198 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3202 * e1000_intr - Interrupt Handler
3203 * @irq: interrupt number
3204 * @data: pointer to a network interface device structure
3205 * @pt_regs: CPU registers structure
3209 e1000_intr(int irq, void *data, struct pt_regs *regs)
3211 struct net_device *netdev = data;
3212 struct e1000_adapter *adapter = netdev_priv(netdev);
3213 struct e1000_hw *hw = &adapter->hw;
3214 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
3215 #ifndef CONFIG_E1000_NAPI
3218 /* Interrupt Auto-Mask...upon reading ICR,
3219 * interrupts are masked. No need for the
3220 * IMC write, but it does mean we should
3221 * account for it ASAP. */
3222 if (likely(hw->mac_type >= e1000_82571))
3223 atomic_inc(&adapter->irq_sem);
3226 if (unlikely(!icr)) {
3227 #ifdef CONFIG_E1000_NAPI
3228 if (hw->mac_type >= e1000_82571)
3229 e1000_irq_enable(adapter);
3231 return IRQ_NONE; /* Not our interrupt */
3234 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3235 hw->get_link_status = 1;
3236 /* 80003ES2LAN workaround--
3237 * For packet buffer work-around on link down event;
3238 * disable receives here in the ISR and
3239 * reset adapter in watchdog
3241 if (netif_carrier_ok(netdev) &&
3242 (adapter->hw.mac_type == e1000_80003es2lan)) {
3243 /* disable receives */
3244 rctl = E1000_READ_REG(hw, RCTL);
3245 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3247 mod_timer(&adapter->watchdog_timer, jiffies);
3250 #ifdef CONFIG_E1000_NAPI
3251 if (unlikely(hw->mac_type < e1000_82571)) {
3252 atomic_inc(&adapter->irq_sem);
3253 E1000_WRITE_REG(hw, IMC, ~0);
3254 E1000_WRITE_FLUSH(hw);
3256 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3257 __netif_rx_schedule(&adapter->polling_netdev[0]);
3259 e1000_irq_enable(adapter);
3261 /* Writing IMC and IMS is needed for 82547.
3262 * Due to Hub Link bus being occupied, an interrupt
3263 * de-assertion message is not able to be sent.
3264 * When an interrupt assertion message is generated later,
3265 * two messages are re-ordered and sent out.
3266 * That causes APIC to think 82547 is in de-assertion
3267 * state, while 82547 is in assertion state, resulting
3268 * in dead lock. Writing IMC forces 82547 into
3269 * de-assertion state.
3271 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
3272 atomic_inc(&adapter->irq_sem);
3273 E1000_WRITE_REG(hw, IMC, ~0);
3276 for (i = 0; i < E1000_MAX_INTR; i++)
3277 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3278 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3281 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3282 e1000_irq_enable(adapter);
3289 #ifdef CONFIG_E1000_NAPI
3291 * e1000_clean - NAPI Rx polling callback
3292 * @adapter: board private structure
3296 e1000_clean(struct net_device *poll_dev, int *budget)
3298 struct e1000_adapter *adapter;
3299 int work_to_do = min(*budget, poll_dev->quota);
3300 int tx_cleaned = 0, i = 0, work_done = 0;
3302 /* Must NOT use netdev_priv macro here. */
3303 adapter = poll_dev->priv;
3305 /* Keep link state information with original netdev */
3306 if (!netif_carrier_ok(adapter->netdev))
3309 while (poll_dev != &adapter->polling_netdev[i]) {
3311 if (unlikely(i == adapter->num_rx_queues))
3315 if (likely(adapter->num_tx_queues == 1)) {
3316 /* e1000_clean is called per-cpu. This lock protects
3317 * tx_ring[0] from being cleaned by multiple cpus
3318 * simultaneously. A failure obtaining the lock means
3319 * tx_ring[0] is currently being cleaned anyway. */
3320 if (spin_trylock(&adapter->tx_queue_lock)) {
3321 tx_cleaned = e1000_clean_tx_irq(adapter,
3322 &adapter->tx_ring[0]);
3323 spin_unlock(&adapter->tx_queue_lock);
3326 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3328 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3329 &work_done, work_to_do);
3331 *budget -= work_done;
3332 poll_dev->quota -= work_done;
3334 /* If no Tx and not enough Rx work done, exit the polling mode */
3335 if ((!tx_cleaned && (work_done == 0)) ||
3336 !netif_running(adapter->netdev)) {
3338 netif_rx_complete(poll_dev);
3339 e1000_irq_enable(adapter);
3348 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3349 * @adapter: board private structure
3353 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3354 struct e1000_tx_ring *tx_ring)
3356 struct net_device *netdev = adapter->netdev;
3357 struct e1000_tx_desc *tx_desc, *eop_desc;
3358 struct e1000_buffer *buffer_info;
3359 unsigned int i, eop;
3360 #ifdef CONFIG_E1000_NAPI
3361 unsigned int count = 0;
3363 boolean_t cleaned = FALSE;
3365 i = tx_ring->next_to_clean;
3366 eop = tx_ring->buffer_info[i].next_to_watch;
3367 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3369 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3370 for (cleaned = FALSE; !cleaned; ) {
3371 tx_desc = E1000_TX_DESC(*tx_ring, i);
3372 buffer_info = &tx_ring->buffer_info[i];
3373 cleaned = (i == eop);
3375 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3376 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
3378 if (unlikely(++i == tx_ring->count)) i = 0;
3382 eop = tx_ring->buffer_info[i].next_to_watch;
3383 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3384 #ifdef CONFIG_E1000_NAPI
3385 #define E1000_TX_WEIGHT 64
3386 /* weight of a sort for tx, to avoid endless transmit cleanup */
3387 if (count++ == E1000_TX_WEIGHT) break;
3391 tx_ring->next_to_clean = i;
3393 spin_lock(&tx_ring->tx_lock);
3395 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
3396 netif_carrier_ok(netdev)))
3397 netif_wake_queue(netdev);
3399 spin_unlock(&tx_ring->tx_lock);
3401 if (adapter->detect_tx_hung) {
3402 /* Detect a transmit hang in hardware, this serializes the
3403 * check with the clearing of time_stamp and movement of i */
3404 adapter->detect_tx_hung = FALSE;
3405 if (tx_ring->buffer_info[eop].dma &&
3406 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3407 (adapter->tx_timeout_factor * HZ))
3408 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3409 E1000_STATUS_TXOFF)) {
3411 /* detected Tx unit hang */
3412 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3416 " next_to_use <%x>\n"
3417 " next_to_clean <%x>\n"
3418 "buffer_info[next_to_clean]\n"
3419 " time_stamp <%lx>\n"
3420 " next_to_watch <%x>\n"
3422 " next_to_watch.status <%x>\n",
3423 (unsigned long)((tx_ring - adapter->tx_ring) /
3424 sizeof(struct e1000_tx_ring)),
3425 readl(adapter->hw.hw_addr + tx_ring->tdh),
3426 readl(adapter->hw.hw_addr + tx_ring->tdt),
3427 tx_ring->next_to_use,
3428 tx_ring->next_to_clean,
3429 tx_ring->buffer_info[eop].time_stamp,
3432 eop_desc->upper.fields.status);
3433 netif_stop_queue(netdev);
3440 * e1000_rx_checksum - Receive Checksum Offload for 82543
3441 * @adapter: board private structure
3442 * @status_err: receive descriptor status and error fields
3443 * @csum: receive descriptor csum field
3444 * @sk_buff: socket buffer with received data
3448 e1000_rx_checksum(struct e1000_adapter *adapter,
3449 uint32_t status_err, uint32_t csum,
3450 struct sk_buff *skb)
3452 uint16_t status = (uint16_t)status_err;
3453 uint8_t errors = (uint8_t)(status_err >> 24);
3454 skb->ip_summed = CHECKSUM_NONE;
3456 /* 82543 or newer only */
3457 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
3458 /* Ignore Checksum bit is set */
3459 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3460 /* TCP/UDP checksum error bit is set */
3461 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3462 /* let the stack verify checksum errors */
3463 adapter->hw_csum_err++;
3466 /* TCP/UDP Checksum has not been calculated */
3467 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3468 if (!(status & E1000_RXD_STAT_TCPCS))
3471 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3474 /* It must be a TCP or UDP packet with a valid checksum */
3475 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3476 /* TCP checksum is good */
3477 skb->ip_summed = CHECKSUM_UNNECESSARY;
3478 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3479 /* IP fragment with UDP payload */
3480 /* Hardware complements the payload checksum, so we undo it
3481 * and then put the value in host order for further stack use.
3483 csum = ntohl(csum ^ 0xFFFF);
3485 skb->ip_summed = CHECKSUM_HW;
3487 adapter->hw_csum_good++;
3491 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3492 * @adapter: board private structure
3496 #ifdef CONFIG_E1000_NAPI
3497 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3498 struct e1000_rx_ring *rx_ring,
3499 int *work_done, int work_to_do)
3501 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3502 struct e1000_rx_ring *rx_ring)
3505 struct net_device *netdev = adapter->netdev;
3506 struct pci_dev *pdev = adapter->pdev;
3507 struct e1000_rx_desc *rx_desc, *next_rxd;
3508 struct e1000_buffer *buffer_info, *next_buffer;
3509 unsigned long flags;
3513 int cleaned_count = 0;
3514 boolean_t cleaned = FALSE;
3516 i = rx_ring->next_to_clean;
3517 rx_desc = E1000_RX_DESC(*rx_ring, i);
3518 buffer_info = &rx_ring->buffer_info[i];
3520 while (rx_desc->status & E1000_RXD_STAT_DD) {
3521 struct sk_buff *skb, *next_skb;
3523 #ifdef CONFIG_E1000_NAPI
3524 if (*work_done >= work_to_do)
3528 status = rx_desc->status;
3529 skb = buffer_info->skb;
3530 buffer_info->skb = NULL;
3532 prefetch(skb->data - NET_IP_ALIGN);
3534 if (++i == rx_ring->count) i = 0;
3535 next_rxd = E1000_RX_DESC(*rx_ring, i);
3538 next_buffer = &rx_ring->buffer_info[i];
3539 next_skb = next_buffer->skb;
3540 prefetch(next_skb->data - NET_IP_ALIGN);
3544 pci_unmap_single(pdev,
3546 buffer_info->length,
3547 PCI_DMA_FROMDEVICE);
3549 length = le16_to_cpu(rx_desc->length);
3551 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3552 /* All receives must fit into a single buffer */
3553 E1000_DBG("%s: Receive packet consumed multiple"
3554 " buffers\n", netdev->name);
3555 dev_kfree_skb_irq(skb);
3559 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3560 last_byte = *(skb->data + length - 1);
3561 if (TBI_ACCEPT(&adapter->hw, status,
3562 rx_desc->errors, length, last_byte)) {
3563 spin_lock_irqsave(&adapter->stats_lock, flags);
3564 e1000_tbi_adjust_stats(&adapter->hw,
3567 spin_unlock_irqrestore(&adapter->stats_lock,
3571 dev_kfree_skb_irq(skb);
3576 /* code added for copybreak, this should improve
3577 * performance for small packets with large amounts
3578 * of reassembly being done in the stack */
3579 #define E1000_CB_LENGTH 256
3580 if (length < E1000_CB_LENGTH) {
3581 struct sk_buff *new_skb =
3582 dev_alloc_skb(length + NET_IP_ALIGN);
3584 skb_reserve(new_skb, NET_IP_ALIGN);
3585 new_skb->dev = netdev;
3586 memcpy(new_skb->data - NET_IP_ALIGN,
3587 skb->data - NET_IP_ALIGN,
3588 length + NET_IP_ALIGN);
3589 /* save the skb in buffer_info as good */
3590 buffer_info->skb = skb;
3592 skb_put(skb, length);
3595 skb_put(skb, length);
3597 /* end copybreak code */
3599 /* Receive Checksum Offload */
3600 e1000_rx_checksum(adapter,
3601 (uint32_t)(status) |
3602 ((uint32_t)(rx_desc->errors) << 24),
3603 le16_to_cpu(rx_desc->csum), skb);
3605 skb->protocol = eth_type_trans(skb, netdev);
3606 #ifdef CONFIG_E1000_NAPI
3607 if (unlikely(adapter->vlgrp &&
3608 (status & E1000_RXD_STAT_VP))) {
3609 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3610 le16_to_cpu(rx_desc->special) &
3611 E1000_RXD_SPC_VLAN_MASK);
3613 netif_receive_skb(skb);
3615 #else /* CONFIG_E1000_NAPI */
3616 if (unlikely(adapter->vlgrp &&
3617 (status & E1000_RXD_STAT_VP))) {
3618 vlan_hwaccel_rx(skb, adapter->vlgrp,
3619 le16_to_cpu(rx_desc->special) &
3620 E1000_RXD_SPC_VLAN_MASK);
3624 #endif /* CONFIG_E1000_NAPI */
3625 netdev->last_rx = jiffies;
3628 rx_desc->status = 0;
3630 /* return some buffers to hardware, one at a time is too slow */
3631 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3632 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3636 /* use prefetched values */
3638 buffer_info = next_buffer;
3640 rx_ring->next_to_clean = i;
3642 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3644 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3650 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3651 * @adapter: board private structure
3655 #ifdef CONFIG_E1000_NAPI
3656 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3657 struct e1000_rx_ring *rx_ring,
3658 int *work_done, int work_to_do)
3660 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3661 struct e1000_rx_ring *rx_ring)
3664 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
3665 struct net_device *netdev = adapter->netdev;
3666 struct pci_dev *pdev = adapter->pdev;
3667 struct e1000_buffer *buffer_info, *next_buffer;
3668 struct e1000_ps_page *ps_page;
3669 struct e1000_ps_page_dma *ps_page_dma;
3670 struct sk_buff *skb, *next_skb;
3672 uint32_t length, staterr;
3673 int cleaned_count = 0;
3674 boolean_t cleaned = FALSE;
3676 i = rx_ring->next_to_clean;
3677 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3678 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3680 while (staterr & E1000_RXD_STAT_DD) {
3681 buffer_info = &rx_ring->buffer_info[i];
3682 ps_page = &rx_ring->ps_page[i];
3683 ps_page_dma = &rx_ring->ps_page_dma[i];
3684 #ifdef CONFIG_E1000_NAPI
3685 if (unlikely(*work_done >= work_to_do))
3689 skb = buffer_info->skb;
3691 /* in the packet split case this is header only */
3692 prefetch(skb->data - NET_IP_ALIGN);
3694 if (++i == rx_ring->count) i = 0;
3695 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
3698 next_buffer = &rx_ring->buffer_info[i];
3699 next_skb = next_buffer->skb;
3700 prefetch(next_skb->data - NET_IP_ALIGN);
3704 pci_unmap_single(pdev, buffer_info->dma,
3705 buffer_info->length,
3706 PCI_DMA_FROMDEVICE);
3708 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3709 E1000_DBG("%s: Packet Split buffers didn't pick up"
3710 " the full packet\n", netdev->name);
3711 dev_kfree_skb_irq(skb);
3715 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3716 dev_kfree_skb_irq(skb);
3720 length = le16_to_cpu(rx_desc->wb.middle.length0);
3722 if (unlikely(!length)) {
3723 E1000_DBG("%s: Last part of the packet spanning"
3724 " multiple descriptors\n", netdev->name);
3725 dev_kfree_skb_irq(skb);
3730 skb_put(skb, length);
3733 /* this looks ugly, but it seems compiler issues make it
3734 more efficient than reusing j */
3735 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3737 /* page alloc/put takes too long and effects small packet
3738 * throughput, so unsplit small packets and save the alloc/put*/
3739 if (l1 && ((length + l1) < E1000_CB_LENGTH)) {
3741 /* there is no documentation about how to call
3742 * kmap_atomic, so we can't hold the mapping
3744 pci_dma_sync_single_for_cpu(pdev,
3745 ps_page_dma->ps_page_dma[0],
3747 PCI_DMA_FROMDEVICE);
3748 vaddr = kmap_atomic(ps_page->ps_page[0],
3749 KM_SKB_DATA_SOFTIRQ);
3750 memcpy(skb->tail, vaddr, l1);
3751 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
3752 pci_dma_sync_single_for_device(pdev,
3753 ps_page_dma->ps_page_dma[0],
3754 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3761 for (j = 0; j < adapter->rx_ps_pages; j++) {
3762 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
3764 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3765 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3766 ps_page_dma->ps_page_dma[j] = 0;
3767 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
3769 ps_page->ps_page[j] = NULL;
3771 skb->data_len += length;
3775 e1000_rx_checksum(adapter, staterr,
3776 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
3777 skb->protocol = eth_type_trans(skb, netdev);
3779 if (likely(rx_desc->wb.upper.header_status &
3780 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
3781 adapter->rx_hdr_split++;
3782 #ifdef CONFIG_E1000_NAPI
3783 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3784 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3785 le16_to_cpu(rx_desc->wb.middle.vlan) &
3786 E1000_RXD_SPC_VLAN_MASK);
3788 netif_receive_skb(skb);
3790 #else /* CONFIG_E1000_NAPI */
3791 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3792 vlan_hwaccel_rx(skb, adapter->vlgrp,
3793 le16_to_cpu(rx_desc->wb.middle.vlan) &
3794 E1000_RXD_SPC_VLAN_MASK);
3798 #endif /* CONFIG_E1000_NAPI */
3799 netdev->last_rx = jiffies;
3802 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
3803 buffer_info->skb = NULL;
3805 /* return some buffers to hardware, one at a time is too slow */
3806 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3807 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3811 /* use prefetched values */
3813 buffer_info = next_buffer;
3815 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3817 rx_ring->next_to_clean = i;
3819 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3821 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3827 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3828 * @adapter: address of board private structure
3832 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3833 struct e1000_rx_ring *rx_ring,
3836 struct net_device *netdev = adapter->netdev;
3837 struct pci_dev *pdev = adapter->pdev;
3838 struct e1000_rx_desc *rx_desc;
3839 struct e1000_buffer *buffer_info;
3840 struct sk_buff *skb;
3842 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3844 i = rx_ring->next_to_use;
3845 buffer_info = &rx_ring->buffer_info[i];
3847 while (cleaned_count--) {
3848 if (!(skb = buffer_info->skb))
3849 skb = dev_alloc_skb(bufsz);
3855 if (unlikely(!skb)) {
3856 /* Better luck next round */
3857 adapter->alloc_rx_buff_failed++;
3861 /* Fix for errata 23, can't cross 64kB boundary */
3862 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3863 struct sk_buff *oldskb = skb;
3864 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3865 "at %p\n", bufsz, skb->data);
3866 /* Try again, without freeing the previous */
3867 skb = dev_alloc_skb(bufsz);
3868 /* Failed allocation, critical failure */
3870 dev_kfree_skb(oldskb);
3874 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3877 dev_kfree_skb(oldskb);
3878 break; /* while !buffer_info->skb */
3880 /* Use new allocation */
3881 dev_kfree_skb(oldskb);
3884 /* Make buffer alignment 2 beyond a 16 byte boundary
3885 * this will result in a 16 byte aligned IP header after
3886 * the 14 byte MAC header is removed
3888 skb_reserve(skb, NET_IP_ALIGN);
3892 buffer_info->skb = skb;
3893 buffer_info->length = adapter->rx_buffer_len;
3895 buffer_info->dma = pci_map_single(pdev,
3897 adapter->rx_buffer_len,
3898 PCI_DMA_FROMDEVICE);
3900 /* Fix for errata 23, can't cross 64kB boundary */
3901 if (!e1000_check_64k_bound(adapter,
3902 (void *)(unsigned long)buffer_info->dma,
3903 adapter->rx_buffer_len)) {
3904 DPRINTK(RX_ERR, ERR,
3905 "dma align check failed: %u bytes at %p\n",
3906 adapter->rx_buffer_len,
3907 (void *)(unsigned long)buffer_info->dma);
3909 buffer_info->skb = NULL;
3911 pci_unmap_single(pdev, buffer_info->dma,
3912 adapter->rx_buffer_len,
3913 PCI_DMA_FROMDEVICE);
3915 break; /* while !buffer_info->skb */
3917 rx_desc = E1000_RX_DESC(*rx_ring, i);
3918 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3920 if (unlikely(++i == rx_ring->count))
3922 buffer_info = &rx_ring->buffer_info[i];
3925 if (likely(rx_ring->next_to_use != i)) {
3926 rx_ring->next_to_use = i;
3927 if (unlikely(i-- == 0))
3928 i = (rx_ring->count - 1);
3930 /* Force memory writes to complete before letting h/w
3931 * know there are new descriptors to fetch. (Only
3932 * applicable for weak-ordered memory model archs,
3933 * such as IA-64). */
3935 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3940 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3941 * @adapter: address of board private structure
3945 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3946 struct e1000_rx_ring *rx_ring,
3949 struct net_device *netdev = adapter->netdev;
3950 struct pci_dev *pdev = adapter->pdev;
3951 union e1000_rx_desc_packet_split *rx_desc;
3952 struct e1000_buffer *buffer_info;
3953 struct e1000_ps_page *ps_page;
3954 struct e1000_ps_page_dma *ps_page_dma;
3955 struct sk_buff *skb;
3958 i = rx_ring->next_to_use;
3959 buffer_info = &rx_ring->buffer_info[i];
3960 ps_page = &rx_ring->ps_page[i];
3961 ps_page_dma = &rx_ring->ps_page_dma[i];
3963 while (cleaned_count--) {
3964 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3966 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
3967 if (j < adapter->rx_ps_pages) {
3968 if (likely(!ps_page->ps_page[j])) {
3969 ps_page->ps_page[j] =
3970 alloc_page(GFP_ATOMIC);
3971 if (unlikely(!ps_page->ps_page[j])) {
3972 adapter->alloc_rx_buff_failed++;
3975 ps_page_dma->ps_page_dma[j] =
3977 ps_page->ps_page[j],
3979 PCI_DMA_FROMDEVICE);
3981 /* Refresh the desc even if buffer_addrs didn't
3982 * change because each write-back erases
3985 rx_desc->read.buffer_addr[j+1] =
3986 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3988 rx_desc->read.buffer_addr[j+1] = ~0;
3991 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3993 if (unlikely(!skb)) {
3994 adapter->alloc_rx_buff_failed++;
3998 /* Make buffer alignment 2 beyond a 16 byte boundary
3999 * this will result in a 16 byte aligned IP header after
4000 * the 14 byte MAC header is removed
4002 skb_reserve(skb, NET_IP_ALIGN);
4006 buffer_info->skb = skb;
4007 buffer_info->length = adapter->rx_ps_bsize0;
4008 buffer_info->dma = pci_map_single(pdev, skb->data,
4009 adapter->rx_ps_bsize0,
4010 PCI_DMA_FROMDEVICE);
4012 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4014 if (unlikely(++i == rx_ring->count)) i = 0;
4015 buffer_info = &rx_ring->buffer_info[i];
4016 ps_page = &rx_ring->ps_page[i];
4017 ps_page_dma = &rx_ring->ps_page_dma[i];
4021 if (likely(rx_ring->next_to_use != i)) {
4022 rx_ring->next_to_use = i;
4023 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4025 /* Force memory writes to complete before letting h/w
4026 * know there are new descriptors to fetch. (Only
4027 * applicable for weak-ordered memory model archs,
4028 * such as IA-64). */
4030 /* Hardware increments by 16 bytes, but packet split
4031 * descriptors are 32 bytes...so we increment tail
4034 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4039 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4044 e1000_smartspeed(struct e1000_adapter *adapter)
4046 uint16_t phy_status;
4049 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4050 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4053 if (adapter->smartspeed == 0) {
4054 /* If Master/Slave config fault is asserted twice,
4055 * we assume back-to-back */
4056 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4057 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4058 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4059 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4060 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4061 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4062 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4063 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4065 adapter->smartspeed++;
4066 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4067 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4069 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4070 MII_CR_RESTART_AUTO_NEG);
4071 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4076 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4077 /* If still no link, perhaps using 2/3 pair cable */
4078 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4079 phy_ctrl |= CR_1000T_MS_ENABLE;
4080 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4081 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4082 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4083 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4084 MII_CR_RESTART_AUTO_NEG);
4085 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4088 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4089 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4090 adapter->smartspeed = 0;
4101 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4107 return e1000_mii_ioctl(netdev, ifr, cmd);
4121 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4123 struct e1000_adapter *adapter = netdev_priv(netdev);
4124 struct mii_ioctl_data *data = if_mii(ifr);
4128 unsigned long flags;
4130 if (adapter->hw.media_type != e1000_media_type_copper)
4135 data->phy_id = adapter->hw.phy_addr;
4138 if (!capable(CAP_NET_ADMIN))
4140 spin_lock_irqsave(&adapter->stats_lock, flags);
4141 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4143 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4146 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4149 if (!capable(CAP_NET_ADMIN))
4151 if (data->reg_num & ~(0x1F))
4153 mii_reg = data->val_in;
4154 spin_lock_irqsave(&adapter->stats_lock, flags);
4155 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
4157 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4160 if (adapter->hw.phy_type == e1000_media_type_copper) {
4161 switch (data->reg_num) {
4163 if (mii_reg & MII_CR_POWER_DOWN)
4165 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4166 adapter->hw.autoneg = 1;
4167 adapter->hw.autoneg_advertised = 0x2F;
4170 spddplx = SPEED_1000;
4171 else if (mii_reg & 0x2000)
4172 spddplx = SPEED_100;
4175 spddplx += (mii_reg & 0x100)
4178 retval = e1000_set_spd_dplx(adapter,
4181 spin_unlock_irqrestore(
4182 &adapter->stats_lock,
4187 if (netif_running(adapter->netdev)) {
4188 e1000_down(adapter);
4191 e1000_reset(adapter);
4193 case M88E1000_PHY_SPEC_CTRL:
4194 case M88E1000_EXT_PHY_SPEC_CTRL:
4195 if (e1000_phy_reset(&adapter->hw)) {
4196 spin_unlock_irqrestore(
4197 &adapter->stats_lock, flags);
4203 switch (data->reg_num) {
4205 if (mii_reg & MII_CR_POWER_DOWN)
4207 if (netif_running(adapter->netdev)) {
4208 e1000_down(adapter);
4211 e1000_reset(adapter);
4215 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4220 return E1000_SUCCESS;
4224 e1000_pci_set_mwi(struct e1000_hw *hw)
4226 struct e1000_adapter *adapter = hw->back;
4227 int ret_val = pci_set_mwi(adapter->pdev);
4230 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4234 e1000_pci_clear_mwi(struct e1000_hw *hw)
4236 struct e1000_adapter *adapter = hw->back;
4238 pci_clear_mwi(adapter->pdev);
4242 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4244 struct e1000_adapter *adapter = hw->back;
4246 pci_read_config_word(adapter->pdev, reg, value);
4250 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4252 struct e1000_adapter *adapter = hw->back;
4254 pci_write_config_word(adapter->pdev, reg, *value);
4258 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4264 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4270 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4272 struct e1000_adapter *adapter = netdev_priv(netdev);
4273 uint32_t ctrl, rctl;
4275 e1000_irq_disable(adapter);
4276 adapter->vlgrp = grp;
4279 /* enable VLAN tag insert/strip */
4280 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4281 ctrl |= E1000_CTRL_VME;
4282 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4284 /* enable VLAN receive filtering */
4285 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4286 rctl |= E1000_RCTL_VFE;
4287 rctl &= ~E1000_RCTL_CFIEN;
4288 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4289 e1000_update_mng_vlan(adapter);
4291 /* disable VLAN tag insert/strip */
4292 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4293 ctrl &= ~E1000_CTRL_VME;
4294 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4296 /* disable VLAN filtering */
4297 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4298 rctl &= ~E1000_RCTL_VFE;
4299 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4300 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4301 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4302 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4306 e1000_irq_enable(adapter);
4310 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4312 struct e1000_adapter *adapter = netdev_priv(netdev);
4313 uint32_t vfta, index;
4315 if ((adapter->hw.mng_cookie.status &
4316 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4317 (vid == adapter->mng_vlan_id))
4319 /* add VID to filter table */
4320 index = (vid >> 5) & 0x7F;
4321 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4322 vfta |= (1 << (vid & 0x1F));
4323 e1000_write_vfta(&adapter->hw, index, vfta);
4327 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4329 struct e1000_adapter *adapter = netdev_priv(netdev);
4330 uint32_t vfta, index;
4332 e1000_irq_disable(adapter);
4335 adapter->vlgrp->vlan_devices[vid] = NULL;
4337 e1000_irq_enable(adapter);
4339 if ((adapter->hw.mng_cookie.status &
4340 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4341 (vid == adapter->mng_vlan_id)) {
4342 /* release control to f/w */
4343 e1000_release_hw_control(adapter);
4347 /* remove VID from filter table */
4348 index = (vid >> 5) & 0x7F;
4349 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4350 vfta &= ~(1 << (vid & 0x1F));
4351 e1000_write_vfta(&adapter->hw, index, vfta);
4355 e1000_restore_vlan(struct e1000_adapter *adapter)
4357 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4359 if (adapter->vlgrp) {
4361 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4362 if (!adapter->vlgrp->vlan_devices[vid])
4364 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4370 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4372 adapter->hw.autoneg = 0;
4374 /* Fiber NICs only allow 1000 gbps Full duplex */
4375 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
4376 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4377 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4382 case SPEED_10 + DUPLEX_HALF:
4383 adapter->hw.forced_speed_duplex = e1000_10_half;
4385 case SPEED_10 + DUPLEX_FULL:
4386 adapter->hw.forced_speed_duplex = e1000_10_full;
4388 case SPEED_100 + DUPLEX_HALF:
4389 adapter->hw.forced_speed_duplex = e1000_100_half;
4391 case SPEED_100 + DUPLEX_FULL:
4392 adapter->hw.forced_speed_duplex = e1000_100_full;
4394 case SPEED_1000 + DUPLEX_FULL:
4395 adapter->hw.autoneg = 1;
4396 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4398 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4400 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4407 /* Save/restore 16 or 64 dwords of PCI config space depending on which
4408 * bus we're on (PCI(X) vs. PCI-E)
4410 #define PCIE_CONFIG_SPACE_LEN 256
4411 #define PCI_CONFIG_SPACE_LEN 64
4413 e1000_pci_save_state(struct e1000_adapter *adapter)
4415 struct pci_dev *dev = adapter->pdev;
4419 if (adapter->hw.mac_type >= e1000_82571)
4420 size = PCIE_CONFIG_SPACE_LEN;
4422 size = PCI_CONFIG_SPACE_LEN;
4424 WARN_ON(adapter->config_space != NULL);
4426 adapter->config_space = kmalloc(size, GFP_KERNEL);
4427 if (!adapter->config_space) {
4428 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4431 for (i = 0; i < (size / 4); i++)
4432 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4437 e1000_pci_restore_state(struct e1000_adapter *adapter)
4439 struct pci_dev *dev = adapter->pdev;
4443 if (adapter->config_space == NULL)
4446 if (adapter->hw.mac_type >= e1000_82571)
4447 size = PCIE_CONFIG_SPACE_LEN;
4449 size = PCI_CONFIG_SPACE_LEN;
4450 for (i = 0; i < (size / 4); i++)
4451 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4452 kfree(adapter->config_space);
4453 adapter->config_space = NULL;
4456 #endif /* CONFIG_PM */
4459 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4461 struct net_device *netdev = pci_get_drvdata(pdev);
4462 struct e1000_adapter *adapter = netdev_priv(netdev);
4463 uint32_t ctrl, ctrl_ext, rctl, manc, status;
4464 uint32_t wufc = adapter->wol;
4467 netif_device_detach(netdev);
4469 if (netif_running(netdev))
4470 e1000_down(adapter);
4473 /* Implement our own version of pci_save_state(pdev) because pci-
4474 * express adapters have 256-byte config spaces. */
4475 retval = e1000_pci_save_state(adapter);
4480 status = E1000_READ_REG(&adapter->hw, STATUS);
4481 if (status & E1000_STATUS_LU)
4482 wufc &= ~E1000_WUFC_LNKC;
4485 e1000_setup_rctl(adapter);
4486 e1000_set_multi(netdev);
4488 /* turn on all-multi mode if wake on multicast is enabled */
4489 if (adapter->wol & E1000_WUFC_MC) {
4490 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4491 rctl |= E1000_RCTL_MPE;
4492 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4495 if (adapter->hw.mac_type >= e1000_82540) {
4496 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4497 /* advertise wake from D3Cold */
4498 #define E1000_CTRL_ADVD3WUC 0x00100000
4499 /* phy power management enable */
4500 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4501 ctrl |= E1000_CTRL_ADVD3WUC |
4502 E1000_CTRL_EN_PHY_PWR_MGMT;
4503 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4506 if (adapter->hw.media_type == e1000_media_type_fiber ||
4507 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4508 /* keep the laser running in D3 */
4509 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4510 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4511 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4514 /* Allow time for pending master requests to run */
4515 e1000_disable_pciex_master(&adapter->hw);
4517 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4518 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4519 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4521 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4522 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4524 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4526 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4527 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4528 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4530 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4531 retval = pci_enable_wake(pdev, PCI_D3cold, 0);
4533 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4536 if (adapter->hw.mac_type >= e1000_82540 &&
4537 adapter->hw.media_type == e1000_media_type_copper) {
4538 manc = E1000_READ_REG(&adapter->hw, MANC);
4539 if (manc & E1000_MANC_SMBUS_EN) {
4540 manc |= E1000_MANC_ARP_EN;
4541 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4542 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4544 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4545 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4548 "Error enabling D3 cold wake\n");
4552 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4553 * would have already happened in close and is redundant. */
4554 e1000_release_hw_control(adapter);
4556 pci_disable_device(pdev);
4558 retval = pci_set_power_state(pdev, pci_choose_state(pdev, state));
4560 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4567 e1000_resume(struct pci_dev *pdev)
4569 struct net_device *netdev = pci_get_drvdata(pdev);
4570 struct e1000_adapter *adapter = netdev_priv(netdev);
4572 uint32_t manc, ret_val;
4574 retval = pci_set_power_state(pdev, PCI_D0);
4576 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4577 e1000_pci_restore_state(adapter);
4578 ret_val = pci_enable_device(pdev);
4579 pci_set_master(pdev);
4581 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4583 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4584 retval = pci_enable_wake(pdev, PCI_D3cold, 0);
4586 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4588 e1000_reset(adapter);
4589 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4591 if (netif_running(netdev))
4594 netif_device_attach(netdev);
4596 if (adapter->hw.mac_type >= e1000_82540 &&
4597 adapter->hw.media_type == e1000_media_type_copper) {
4598 manc = E1000_READ_REG(&adapter->hw, MANC);
4599 manc &= ~(E1000_MANC_ARP_EN);
4600 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4603 /* If the controller is 82573 and f/w is AMT, do not set
4604 * DRV_LOAD until the interface is up. For all other cases,
4605 * let the f/w know that the h/w is now under the control
4607 if (adapter->hw.mac_type != e1000_82573 ||
4608 !e1000_check_mng_mode(&adapter->hw))
4609 e1000_get_hw_control(adapter);
4614 #ifdef CONFIG_NET_POLL_CONTROLLER
4616 * Polling 'interrupt' - used by things like netconsole to send skbs
4617 * without having to re-enable interrupts. It's not called while
4618 * the interrupt routine is executing.
4621 e1000_netpoll(struct net_device *netdev)
4623 struct e1000_adapter *adapter = netdev_priv(netdev);
4624 disable_irq(adapter->pdev->irq);
4625 e1000_intr(adapter->pdev->irq, netdev, NULL);
4626 e1000_clean_tx_irq(adapter, adapter->tx_ring);
4627 #ifndef CONFIG_E1000_NAPI
4628 adapter->clean_rx(adapter, adapter->rx_ring);
4630 enable_irq(adapter->pdev->irq);