1 /*******************************************************************************
4 Copyright(c) 1999 - 2006 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 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
26 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *******************************************************************************/
32 char e1000_driver_name[] = "e1000";
33 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
34 #ifndef CONFIG_E1000_NAPI
37 #define DRIVERNAPI "-NAPI"
39 #define DRV_VERSION "7.0.38-k4"DRIVERNAPI
40 char e1000_driver_version[] = DRV_VERSION;
41 static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
43 /* e1000_pci_tbl - PCI Device ID Table
45 * Last entry must be all 0s
48 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
50 static struct pci_device_id e1000_pci_tbl[] = {
51 INTEL_E1000_ETHERNET_DEVICE(0x1000),
52 INTEL_E1000_ETHERNET_DEVICE(0x1001),
53 INTEL_E1000_ETHERNET_DEVICE(0x1004),
54 INTEL_E1000_ETHERNET_DEVICE(0x1008),
55 INTEL_E1000_ETHERNET_DEVICE(0x1009),
56 INTEL_E1000_ETHERNET_DEVICE(0x100C),
57 INTEL_E1000_ETHERNET_DEVICE(0x100D),
58 INTEL_E1000_ETHERNET_DEVICE(0x100E),
59 INTEL_E1000_ETHERNET_DEVICE(0x100F),
60 INTEL_E1000_ETHERNET_DEVICE(0x1010),
61 INTEL_E1000_ETHERNET_DEVICE(0x1011),
62 INTEL_E1000_ETHERNET_DEVICE(0x1012),
63 INTEL_E1000_ETHERNET_DEVICE(0x1013),
64 INTEL_E1000_ETHERNET_DEVICE(0x1014),
65 INTEL_E1000_ETHERNET_DEVICE(0x1015),
66 INTEL_E1000_ETHERNET_DEVICE(0x1016),
67 INTEL_E1000_ETHERNET_DEVICE(0x1017),
68 INTEL_E1000_ETHERNET_DEVICE(0x1018),
69 INTEL_E1000_ETHERNET_DEVICE(0x1019),
70 INTEL_E1000_ETHERNET_DEVICE(0x101A),
71 INTEL_E1000_ETHERNET_DEVICE(0x101D),
72 INTEL_E1000_ETHERNET_DEVICE(0x101E),
73 INTEL_E1000_ETHERNET_DEVICE(0x1026),
74 INTEL_E1000_ETHERNET_DEVICE(0x1027),
75 INTEL_E1000_ETHERNET_DEVICE(0x1028),
76 INTEL_E1000_ETHERNET_DEVICE(0x105E),
77 INTEL_E1000_ETHERNET_DEVICE(0x105F),
78 INTEL_E1000_ETHERNET_DEVICE(0x1060),
79 INTEL_E1000_ETHERNET_DEVICE(0x1075),
80 INTEL_E1000_ETHERNET_DEVICE(0x1076),
81 INTEL_E1000_ETHERNET_DEVICE(0x1077),
82 INTEL_E1000_ETHERNET_DEVICE(0x1078),
83 INTEL_E1000_ETHERNET_DEVICE(0x1079),
84 INTEL_E1000_ETHERNET_DEVICE(0x107A),
85 INTEL_E1000_ETHERNET_DEVICE(0x107B),
86 INTEL_E1000_ETHERNET_DEVICE(0x107C),
87 INTEL_E1000_ETHERNET_DEVICE(0x107D),
88 INTEL_E1000_ETHERNET_DEVICE(0x107E),
89 INTEL_E1000_ETHERNET_DEVICE(0x107F),
90 INTEL_E1000_ETHERNET_DEVICE(0x108A),
91 INTEL_E1000_ETHERNET_DEVICE(0x108B),
92 INTEL_E1000_ETHERNET_DEVICE(0x108C),
93 INTEL_E1000_ETHERNET_DEVICE(0x1096),
94 INTEL_E1000_ETHERNET_DEVICE(0x1098),
95 INTEL_E1000_ETHERNET_DEVICE(0x1099),
96 INTEL_E1000_ETHERNET_DEVICE(0x109A),
97 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
98 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
99 /* required last entry */
103 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
105 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
106 struct e1000_tx_ring *txdr);
107 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
108 struct e1000_rx_ring *rxdr);
109 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
110 struct e1000_tx_ring *tx_ring);
111 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
112 struct e1000_rx_ring *rx_ring);
114 /* Local Function Prototypes */
116 static int e1000_init_module(void);
117 static void e1000_exit_module(void);
118 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
119 static void __devexit e1000_remove(struct pci_dev *pdev);
120 static int e1000_alloc_queues(struct e1000_adapter *adapter);
121 static int e1000_sw_init(struct e1000_adapter *adapter);
122 static int e1000_open(struct net_device *netdev);
123 static int e1000_close(struct net_device *netdev);
124 static void e1000_configure_tx(struct e1000_adapter *adapter);
125 static void e1000_configure_rx(struct e1000_adapter *adapter);
126 static void e1000_setup_rctl(struct e1000_adapter *adapter);
127 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
128 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
129 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
130 struct e1000_tx_ring *tx_ring);
131 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
132 struct e1000_rx_ring *rx_ring);
133 static void e1000_set_multi(struct net_device *netdev);
134 static void e1000_update_phy_info(unsigned long data);
135 static void e1000_watchdog(unsigned long data);
136 static void e1000_watchdog_task(struct e1000_adapter *adapter);
137 static void e1000_82547_tx_fifo_stall(unsigned long data);
138 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
139 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
140 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
141 static int e1000_set_mac(struct net_device *netdev, void *p);
142 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
143 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
144 struct e1000_tx_ring *tx_ring);
145 #ifdef CONFIG_E1000_NAPI
146 static int e1000_clean(struct net_device *poll_dev, int *budget);
147 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
148 struct e1000_rx_ring *rx_ring,
149 int *work_done, int work_to_do);
150 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
151 struct e1000_rx_ring *rx_ring,
152 int *work_done, int work_to_do);
154 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
155 struct e1000_rx_ring *rx_ring);
156 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
157 struct e1000_rx_ring *rx_ring);
159 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
160 struct e1000_rx_ring *rx_ring,
162 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
163 struct e1000_rx_ring *rx_ring,
165 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
166 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
168 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
169 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
170 static void e1000_tx_timeout(struct net_device *dev);
171 static void e1000_reset_task(struct net_device *dev);
172 static void e1000_smartspeed(struct e1000_adapter *adapter);
173 static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
174 struct sk_buff *skb);
176 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
177 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
178 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
179 static void e1000_restore_vlan(struct e1000_adapter *adapter);
182 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
183 static int e1000_resume(struct pci_dev *pdev);
185 static void e1000_shutdown(struct pci_dev *pdev);
187 #ifdef CONFIG_NET_POLL_CONTROLLER
188 /* for netdump / net console */
189 static void e1000_netpoll (struct net_device *netdev);
192 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
193 pci_channel_state_t state);
194 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
195 static void e1000_io_resume(struct pci_dev *pdev);
197 static struct pci_error_handlers e1000_err_handler = {
198 .error_detected = e1000_io_error_detected,
199 .slot_reset = e1000_io_slot_reset,
200 .resume = e1000_io_resume,
203 static struct pci_driver e1000_driver = {
204 .name = e1000_driver_name,
205 .id_table = e1000_pci_tbl,
206 .probe = e1000_probe,
207 .remove = __devexit_p(e1000_remove),
208 /* Power Managment Hooks */
210 .suspend = e1000_suspend,
211 .resume = e1000_resume,
213 .shutdown = e1000_shutdown,
214 .err_handler = &e1000_err_handler
217 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
218 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
219 MODULE_LICENSE("GPL");
220 MODULE_VERSION(DRV_VERSION);
222 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
223 module_param(debug, int, 0);
224 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
227 * e1000_init_module - Driver Registration Routine
229 * e1000_init_module is the first routine called when the driver is
230 * loaded. All it does is register with the PCI subsystem.
234 e1000_init_module(void)
237 printk(KERN_INFO "%s - version %s\n",
238 e1000_driver_string, e1000_driver_version);
240 printk(KERN_INFO "%s\n", e1000_copyright);
242 ret = pci_module_init(&e1000_driver);
247 module_init(e1000_init_module);
250 * e1000_exit_module - Driver Exit Cleanup Routine
252 * e1000_exit_module is called just before the driver is removed
257 e1000_exit_module(void)
259 pci_unregister_driver(&e1000_driver);
262 module_exit(e1000_exit_module);
265 * e1000_irq_disable - Mask off interrupt generation on the NIC
266 * @adapter: board private structure
270 e1000_irq_disable(struct e1000_adapter *adapter)
272 atomic_inc(&adapter->irq_sem);
273 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
274 E1000_WRITE_FLUSH(&adapter->hw);
275 synchronize_irq(adapter->pdev->irq);
279 * e1000_irq_enable - Enable default interrupt generation settings
280 * @adapter: board private structure
284 e1000_irq_enable(struct e1000_adapter *adapter)
286 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
287 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
288 E1000_WRITE_FLUSH(&adapter->hw);
293 e1000_update_mng_vlan(struct e1000_adapter *adapter)
295 struct net_device *netdev = adapter->netdev;
296 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
297 uint16_t old_vid = adapter->mng_vlan_id;
298 if (adapter->vlgrp) {
299 if (!adapter->vlgrp->vlan_devices[vid]) {
300 if (adapter->hw.mng_cookie.status &
301 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
302 e1000_vlan_rx_add_vid(netdev, vid);
303 adapter->mng_vlan_id = vid;
305 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
307 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
309 !adapter->vlgrp->vlan_devices[old_vid])
310 e1000_vlan_rx_kill_vid(netdev, old_vid);
312 adapter->mng_vlan_id = vid;
317 * e1000_release_hw_control - release control of the h/w to f/w
318 * @adapter: address of board private structure
320 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
321 * For ASF and Pass Through versions of f/w this means that the
322 * driver is no longer loaded. For AMT version (only with 82573) i
323 * of the f/w this means that the netowrk i/f is closed.
328 e1000_release_hw_control(struct e1000_adapter *adapter)
333 /* Let firmware taken over control of h/w */
334 switch (adapter->hw.mac_type) {
337 case e1000_80003es2lan:
338 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
339 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
340 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
343 swsm = E1000_READ_REG(&adapter->hw, SWSM);
344 E1000_WRITE_REG(&adapter->hw, SWSM,
345 swsm & ~E1000_SWSM_DRV_LOAD);
352 * e1000_get_hw_control - get control of the h/w from f/w
353 * @adapter: address of board private structure
355 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
356 * For ASF and Pass Through versions of f/w this means that
357 * the driver is loaded. For AMT version (only with 82573)
358 * of the f/w this means that the netowrk i/f is open.
363 e1000_get_hw_control(struct e1000_adapter *adapter)
367 /* Let firmware know the driver has taken over */
368 switch (adapter->hw.mac_type) {
371 case e1000_80003es2lan:
372 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
373 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
374 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
377 swsm = E1000_READ_REG(&adapter->hw, SWSM);
378 E1000_WRITE_REG(&adapter->hw, SWSM,
379 swsm | E1000_SWSM_DRV_LOAD);
387 e1000_up(struct e1000_adapter *adapter)
389 struct net_device *netdev = adapter->netdev;
392 /* hardware has been reset, we need to reload some things */
394 /* Reset the PHY if it was previously powered down */
395 if (adapter->hw.media_type == e1000_media_type_copper) {
397 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
398 if (mii_reg & MII_CR_POWER_DOWN)
399 e1000_phy_hw_reset(&adapter->hw);
402 e1000_set_multi(netdev);
404 e1000_restore_vlan(adapter);
406 e1000_configure_tx(adapter);
407 e1000_setup_rctl(adapter);
408 e1000_configure_rx(adapter);
409 /* call E1000_DESC_UNUSED which always leaves
410 * at least 1 descriptor unused to make sure
411 * next_to_use != next_to_clean */
412 for (i = 0; i < adapter->num_rx_queues; i++) {
413 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
414 adapter->alloc_rx_buf(adapter, ring,
415 E1000_DESC_UNUSED(ring));
418 #ifdef CONFIG_PCI_MSI
419 if (adapter->hw.mac_type > e1000_82547_rev_2) {
420 adapter->have_msi = TRUE;
421 if ((err = pci_enable_msi(adapter->pdev))) {
423 "Unable to allocate MSI interrupt Error: %d\n", err);
424 adapter->have_msi = FALSE;
428 if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
429 SA_SHIRQ | SA_SAMPLE_RANDOM,
430 netdev->name, netdev))) {
432 "Unable to allocate interrupt Error: %d\n", err);
436 adapter->tx_queue_len = netdev->tx_queue_len;
438 mod_timer(&adapter->watchdog_timer, jiffies);
440 #ifdef CONFIG_E1000_NAPI
441 netif_poll_enable(netdev);
443 e1000_irq_enable(adapter);
449 e1000_down(struct e1000_adapter *adapter)
451 struct net_device *netdev = adapter->netdev;
452 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
453 e1000_check_mng_mode(&adapter->hw);
455 e1000_irq_disable(adapter);
457 free_irq(adapter->pdev->irq, netdev);
458 #ifdef CONFIG_PCI_MSI
459 if (adapter->hw.mac_type > e1000_82547_rev_2 &&
460 adapter->have_msi == TRUE)
461 pci_disable_msi(adapter->pdev);
463 del_timer_sync(&adapter->tx_fifo_stall_timer);
464 del_timer_sync(&adapter->watchdog_timer);
465 del_timer_sync(&adapter->phy_info_timer);
467 #ifdef CONFIG_E1000_NAPI
468 netif_poll_disable(netdev);
470 netdev->tx_queue_len = adapter->tx_queue_len;
471 adapter->link_speed = 0;
472 adapter->link_duplex = 0;
473 netif_carrier_off(netdev);
474 netif_stop_queue(netdev);
476 e1000_reset(adapter);
477 e1000_clean_all_tx_rings(adapter);
478 e1000_clean_all_rx_rings(adapter);
480 /* Power down the PHY so no link is implied when interface is down *
481 * The PHY cannot be powered down if any of the following is TRUE *
484 * (c) SoL/IDER session is active */
485 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
486 adapter->hw.media_type == e1000_media_type_copper &&
487 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
489 !e1000_check_phy_reset_block(&adapter->hw)) {
491 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
492 mii_reg |= MII_CR_POWER_DOWN;
493 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
499 e1000_reset(struct e1000_adapter *adapter)
502 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
504 /* Repartition Pba for greater than 9k mtu
505 * To take effect CTRL.RST is required.
508 switch (adapter->hw.mac_type) {
510 case e1000_82547_rev_2:
515 case e1000_80003es2lan:
526 if ((adapter->hw.mac_type != e1000_82573) &&
527 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
528 pba -= 8; /* allocate more FIFO for Tx */
531 if (adapter->hw.mac_type == e1000_82547) {
532 adapter->tx_fifo_head = 0;
533 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
534 adapter->tx_fifo_size =
535 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
536 atomic_set(&adapter->tx_fifo_stall, 0);
539 E1000_WRITE_REG(&adapter->hw, PBA, pba);
541 /* flow control settings */
542 /* Set the FC high water mark to 90% of the FIFO size.
543 * Required to clear last 3 LSB */
544 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
546 adapter->hw.fc_high_water = fc_high_water_mark;
547 adapter->hw.fc_low_water = fc_high_water_mark - 8;
548 if (adapter->hw.mac_type == e1000_80003es2lan)
549 adapter->hw.fc_pause_time = 0xFFFF;
551 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
552 adapter->hw.fc_send_xon = 1;
553 adapter->hw.fc = adapter->hw.original_fc;
555 /* Allow time for pending master requests to run */
556 e1000_reset_hw(&adapter->hw);
557 if (adapter->hw.mac_type >= e1000_82544)
558 E1000_WRITE_REG(&adapter->hw, WUC, 0);
559 if (e1000_init_hw(&adapter->hw))
560 DPRINTK(PROBE, ERR, "Hardware Error\n");
561 e1000_update_mng_vlan(adapter);
562 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
563 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
565 e1000_reset_adaptive(&adapter->hw);
566 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
567 if (adapter->en_mng_pt) {
568 manc = E1000_READ_REG(&adapter->hw, MANC);
569 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
570 E1000_WRITE_REG(&adapter->hw, MANC, manc);
575 * e1000_probe - Device Initialization Routine
576 * @pdev: PCI device information struct
577 * @ent: entry in e1000_pci_tbl
579 * Returns 0 on success, negative on failure
581 * e1000_probe initializes an adapter identified by a pci_dev structure.
582 * The OS initialization, configuring of the adapter private structure,
583 * and a hardware reset occur.
587 e1000_probe(struct pci_dev *pdev,
588 const struct pci_device_id *ent)
590 struct net_device *netdev;
591 struct e1000_adapter *adapter;
592 unsigned long mmio_start, mmio_len;
594 static int cards_found = 0;
595 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
596 int i, err, pci_using_dac;
597 uint16_t eeprom_data;
598 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
599 if ((err = pci_enable_device(pdev)))
602 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
605 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
606 E1000_ERR("No usable DMA configuration, aborting\n");
612 if ((err = pci_request_regions(pdev, e1000_driver_name)))
615 pci_set_master(pdev);
617 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
620 goto err_alloc_etherdev;
623 SET_MODULE_OWNER(netdev);
624 SET_NETDEV_DEV(netdev, &pdev->dev);
626 pci_set_drvdata(pdev, netdev);
627 adapter = netdev_priv(netdev);
628 adapter->netdev = netdev;
629 adapter->pdev = pdev;
630 adapter->hw.back = adapter;
631 adapter->msg_enable = (1 << debug) - 1;
633 mmio_start = pci_resource_start(pdev, BAR_0);
634 mmio_len = pci_resource_len(pdev, BAR_0);
636 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
637 if (!adapter->hw.hw_addr) {
642 for (i = BAR_1; i <= BAR_5; i++) {
643 if (pci_resource_len(pdev, i) == 0)
645 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
646 adapter->hw.io_base = pci_resource_start(pdev, i);
651 netdev->open = &e1000_open;
652 netdev->stop = &e1000_close;
653 netdev->hard_start_xmit = &e1000_xmit_frame;
654 netdev->get_stats = &e1000_get_stats;
655 netdev->set_multicast_list = &e1000_set_multi;
656 netdev->set_mac_address = &e1000_set_mac;
657 netdev->change_mtu = &e1000_change_mtu;
658 netdev->do_ioctl = &e1000_ioctl;
659 e1000_set_ethtool_ops(netdev);
660 netdev->tx_timeout = &e1000_tx_timeout;
661 netdev->watchdog_timeo = 5 * HZ;
662 #ifdef CONFIG_E1000_NAPI
663 netdev->poll = &e1000_clean;
666 netdev->vlan_rx_register = e1000_vlan_rx_register;
667 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
668 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
669 #ifdef CONFIG_NET_POLL_CONTROLLER
670 netdev->poll_controller = e1000_netpoll;
672 strcpy(netdev->name, pci_name(pdev));
674 netdev->mem_start = mmio_start;
675 netdev->mem_end = mmio_start + mmio_len;
676 netdev->base_addr = adapter->hw.io_base;
678 adapter->bd_number = cards_found;
680 /* setup the private structure */
682 if ((err = e1000_sw_init(adapter)))
685 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
686 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
688 /* if ksp3, indicate if it's port a being setup */
689 if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
690 e1000_ksp3_port_a == 0)
691 adapter->ksp3_port_a = 1;
693 /* Reset for multiple KP3 adapters */
694 if (e1000_ksp3_port_a == 4)
695 e1000_ksp3_port_a = 0;
697 if (adapter->hw.mac_type >= e1000_82543) {
698 netdev->features = NETIF_F_SG |
702 NETIF_F_HW_VLAN_FILTER;
706 if ((adapter->hw.mac_type >= e1000_82544) &&
707 (adapter->hw.mac_type != e1000_82547))
708 netdev->features |= NETIF_F_TSO;
710 #ifdef NETIF_F_TSO_IPV6
711 if (adapter->hw.mac_type > e1000_82547_rev_2)
712 netdev->features |= NETIF_F_TSO_IPV6;
716 netdev->features |= NETIF_F_HIGHDMA;
718 /* hard_start_xmit is safe against parallel locking */
719 netdev->features |= NETIF_F_LLTX;
721 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
723 /* before reading the EEPROM, reset the controller to
724 * put the device in a known good starting state */
726 e1000_reset_hw(&adapter->hw);
728 /* make sure the EEPROM is good */
730 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
731 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
736 /* copy the MAC address out of the EEPROM */
738 if (e1000_read_mac_addr(&adapter->hw))
739 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
740 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
741 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
743 if (!is_valid_ether_addr(netdev->perm_addr)) {
744 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
749 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
751 e1000_get_bus_info(&adapter->hw);
753 init_timer(&adapter->tx_fifo_stall_timer);
754 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
755 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
757 init_timer(&adapter->watchdog_timer);
758 adapter->watchdog_timer.function = &e1000_watchdog;
759 adapter->watchdog_timer.data = (unsigned long) adapter;
761 INIT_WORK(&adapter->watchdog_task,
762 (void (*)(void *))e1000_watchdog_task, adapter);
764 init_timer(&adapter->phy_info_timer);
765 adapter->phy_info_timer.function = &e1000_update_phy_info;
766 adapter->phy_info_timer.data = (unsigned long) adapter;
768 INIT_WORK(&adapter->reset_task,
769 (void (*)(void *))e1000_reset_task, netdev);
771 /* we're going to reset, so assume we have no link for now */
773 netif_carrier_off(netdev);
774 netif_stop_queue(netdev);
776 e1000_check_options(adapter);
778 /* Initial Wake on LAN setting
779 * If APM wake is enabled in the EEPROM,
780 * enable the ACPI Magic Packet filter
783 switch (adapter->hw.mac_type) {
784 case e1000_82542_rev2_0:
785 case e1000_82542_rev2_1:
789 e1000_read_eeprom(&adapter->hw,
790 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
791 eeprom_apme_mask = E1000_EEPROM_82544_APM;
794 case e1000_82546_rev_3:
796 case e1000_80003es2lan:
797 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
798 e1000_read_eeprom(&adapter->hw,
799 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
804 e1000_read_eeprom(&adapter->hw,
805 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
808 if (eeprom_data & eeprom_apme_mask)
809 adapter->wol |= E1000_WUFC_MAG;
811 /* print bus type/speed/width info */
813 struct e1000_hw *hw = &adapter->hw;
814 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
815 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
816 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
817 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
818 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
819 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
820 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
821 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
822 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
823 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
824 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
828 for (i = 0; i < 6; i++)
829 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
831 /* reset the hardware with the new settings */
832 e1000_reset(adapter);
834 /* If the controller is 82573 and f/w is AMT, do not set
835 * DRV_LOAD until the interface is up. For all other cases,
836 * let the f/w know that the h/w is now under the control
838 if (adapter->hw.mac_type != e1000_82573 ||
839 !e1000_check_mng_mode(&adapter->hw))
840 e1000_get_hw_control(adapter);
842 strcpy(netdev->name, "eth%d");
843 if ((err = register_netdev(netdev)))
846 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
854 iounmap(adapter->hw.hw_addr);
858 pci_release_regions(pdev);
863 * e1000_remove - Device Removal Routine
864 * @pdev: PCI device information struct
866 * e1000_remove is called by the PCI subsystem to alert the driver
867 * that it should release a PCI device. The could be caused by a
868 * Hot-Plug event, or because the driver is going to be removed from
872 static void __devexit
873 e1000_remove(struct pci_dev *pdev)
875 struct net_device *netdev = pci_get_drvdata(pdev);
876 struct e1000_adapter *adapter = netdev_priv(netdev);
878 #ifdef CONFIG_E1000_NAPI
882 flush_scheduled_work();
884 if (adapter->hw.mac_type >= e1000_82540 &&
885 adapter->hw.media_type == e1000_media_type_copper) {
886 manc = E1000_READ_REG(&adapter->hw, MANC);
887 if (manc & E1000_MANC_SMBUS_EN) {
888 manc |= E1000_MANC_ARP_EN;
889 E1000_WRITE_REG(&adapter->hw, MANC, manc);
893 /* Release control of h/w to f/w. If f/w is AMT enabled, this
894 * would have already happened in close and is redundant. */
895 e1000_release_hw_control(adapter);
897 unregister_netdev(netdev);
898 #ifdef CONFIG_E1000_NAPI
899 for (i = 0; i < adapter->num_rx_queues; i++)
900 dev_put(&adapter->polling_netdev[i]);
903 if (!e1000_check_phy_reset_block(&adapter->hw))
904 e1000_phy_hw_reset(&adapter->hw);
906 kfree(adapter->tx_ring);
907 kfree(adapter->rx_ring);
908 #ifdef CONFIG_E1000_NAPI
909 kfree(adapter->polling_netdev);
912 iounmap(adapter->hw.hw_addr);
913 pci_release_regions(pdev);
917 pci_disable_device(pdev);
921 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
922 * @adapter: board private structure to initialize
924 * e1000_sw_init initializes the Adapter private data structure.
925 * Fields are initialized based on PCI device information and
926 * OS network device settings (MTU size).
930 e1000_sw_init(struct e1000_adapter *adapter)
932 struct e1000_hw *hw = &adapter->hw;
933 struct net_device *netdev = adapter->netdev;
934 struct pci_dev *pdev = adapter->pdev;
935 #ifdef CONFIG_E1000_NAPI
939 /* PCI config space info */
941 hw->vendor_id = pdev->vendor;
942 hw->device_id = pdev->device;
943 hw->subsystem_vendor_id = pdev->subsystem_vendor;
944 hw->subsystem_id = pdev->subsystem_device;
946 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
948 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
950 adapter->rx_buffer_len = MAXIMUM_ETHERNET_FRAME_SIZE;
951 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
952 hw->max_frame_size = netdev->mtu +
953 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
954 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
956 /* identify the MAC */
958 if (e1000_set_mac_type(hw)) {
959 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
963 /* initialize eeprom parameters */
965 if (e1000_init_eeprom_params(hw)) {
966 E1000_ERR("EEPROM initialization failed\n");
970 switch (hw->mac_type) {
975 case e1000_82541_rev_2:
976 case e1000_82547_rev_2:
977 hw->phy_init_script = 1;
981 e1000_set_media_type(hw);
983 hw->wait_autoneg_complete = FALSE;
984 hw->tbi_compatibility_en = TRUE;
985 hw->adaptive_ifs = TRUE;
989 if (hw->media_type == e1000_media_type_copper) {
990 hw->mdix = AUTO_ALL_MODES;
991 hw->disable_polarity_correction = FALSE;
992 hw->master_slave = E1000_MASTER_SLAVE;
995 adapter->num_tx_queues = 1;
996 adapter->num_rx_queues = 1;
998 if (e1000_alloc_queues(adapter)) {
999 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1003 #ifdef CONFIG_E1000_NAPI
1004 for (i = 0; i < adapter->num_rx_queues; i++) {
1005 adapter->polling_netdev[i].priv = adapter;
1006 adapter->polling_netdev[i].poll = &e1000_clean;
1007 adapter->polling_netdev[i].weight = 64;
1008 dev_hold(&adapter->polling_netdev[i]);
1009 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1011 spin_lock_init(&adapter->tx_queue_lock);
1014 atomic_set(&adapter->irq_sem, 1);
1015 spin_lock_init(&adapter->stats_lock);
1021 * e1000_alloc_queues - Allocate memory for all rings
1022 * @adapter: board private structure to initialize
1024 * We allocate one ring per queue at run-time since we don't know the
1025 * number of queues at compile-time. The polling_netdev array is
1026 * intended for Multiqueue, but should work fine with a single queue.
1029 static int __devinit
1030 e1000_alloc_queues(struct e1000_adapter *adapter)
1034 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1035 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1036 if (!adapter->tx_ring)
1038 memset(adapter->tx_ring, 0, size);
1040 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1041 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1042 if (!adapter->rx_ring) {
1043 kfree(adapter->tx_ring);
1046 memset(adapter->rx_ring, 0, size);
1048 #ifdef CONFIG_E1000_NAPI
1049 size = sizeof(struct net_device) * adapter->num_rx_queues;
1050 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1051 if (!adapter->polling_netdev) {
1052 kfree(adapter->tx_ring);
1053 kfree(adapter->rx_ring);
1056 memset(adapter->polling_netdev, 0, size);
1059 return E1000_SUCCESS;
1063 * e1000_open - Called when a network interface is made active
1064 * @netdev: network interface device structure
1066 * Returns 0 on success, negative value on failure
1068 * The open entry point is called when a network interface is made
1069 * active by the system (IFF_UP). At this point all resources needed
1070 * for transmit and receive operations are allocated, the interrupt
1071 * handler is registered with the OS, the watchdog timer is started,
1072 * and the stack is notified that the interface is ready.
1076 e1000_open(struct net_device *netdev)
1078 struct e1000_adapter *adapter = netdev_priv(netdev);
1081 /* allocate transmit descriptors */
1083 if ((err = e1000_setup_all_tx_resources(adapter)))
1086 /* allocate receive descriptors */
1088 if ((err = e1000_setup_all_rx_resources(adapter)))
1091 if ((err = e1000_up(adapter)))
1093 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1094 if ((adapter->hw.mng_cookie.status &
1095 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1096 e1000_update_mng_vlan(adapter);
1099 /* If AMT is enabled, let the firmware know that the network
1100 * interface is now open */
1101 if (adapter->hw.mac_type == e1000_82573 &&
1102 e1000_check_mng_mode(&adapter->hw))
1103 e1000_get_hw_control(adapter);
1105 return E1000_SUCCESS;
1108 e1000_free_all_rx_resources(adapter);
1110 e1000_free_all_tx_resources(adapter);
1112 e1000_reset(adapter);
1118 * e1000_close - Disables a network interface
1119 * @netdev: network interface device structure
1121 * Returns 0, this is not allowed to fail
1123 * The close entry point is called when an interface is de-activated
1124 * by the OS. The hardware is still under the drivers control, but
1125 * needs to be disabled. A global MAC reset is issued to stop the
1126 * hardware, and all transmit and receive resources are freed.
1130 e1000_close(struct net_device *netdev)
1132 struct e1000_adapter *adapter = netdev_priv(netdev);
1134 e1000_down(adapter);
1136 e1000_free_all_tx_resources(adapter);
1137 e1000_free_all_rx_resources(adapter);
1139 if ((adapter->hw.mng_cookie.status &
1140 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1141 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1144 /* If AMT is enabled, let the firmware know that the network
1145 * interface is now closed */
1146 if (adapter->hw.mac_type == e1000_82573 &&
1147 e1000_check_mng_mode(&adapter->hw))
1148 e1000_release_hw_control(adapter);
1154 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1155 * @adapter: address of board private structure
1156 * @start: address of beginning of memory
1157 * @len: length of memory
1160 e1000_check_64k_bound(struct e1000_adapter *adapter,
1161 void *start, unsigned long len)
1163 unsigned long begin = (unsigned long) start;
1164 unsigned long end = begin + len;
1166 /* First rev 82545 and 82546 need to not allow any memory
1167 * write location to cross 64k boundary due to errata 23 */
1168 if (adapter->hw.mac_type == e1000_82545 ||
1169 adapter->hw.mac_type == e1000_82546) {
1170 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1177 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1178 * @adapter: board private structure
1179 * @txdr: tx descriptor ring (for a specific queue) to setup
1181 * Return 0 on success, negative on failure
1185 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1186 struct e1000_tx_ring *txdr)
1188 struct pci_dev *pdev = adapter->pdev;
1191 size = sizeof(struct e1000_buffer) * txdr->count;
1193 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1194 if (!txdr->buffer_info) {
1196 "Unable to allocate memory for the transmit descriptor ring\n");
1199 memset(txdr->buffer_info, 0, size);
1201 /* round up to nearest 4K */
1203 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1204 E1000_ROUNDUP(txdr->size, 4096);
1206 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1209 vfree(txdr->buffer_info);
1211 "Unable to allocate memory for the transmit descriptor ring\n");
1215 /* Fix for errata 23, can't cross 64kB boundary */
1216 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1217 void *olddesc = txdr->desc;
1218 dma_addr_t olddma = txdr->dma;
1219 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1220 "at %p\n", txdr->size, txdr->desc);
1221 /* Try again, without freeing the previous */
1222 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1223 /* Failed allocation, critical failure */
1225 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1226 goto setup_tx_desc_die;
1229 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1231 pci_free_consistent(pdev, txdr->size, txdr->desc,
1233 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1235 "Unable to allocate aligned memory "
1236 "for the transmit descriptor ring\n");
1237 vfree(txdr->buffer_info);
1240 /* Free old allocation, new allocation was successful */
1241 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1244 memset(txdr->desc, 0, txdr->size);
1246 txdr->next_to_use = 0;
1247 txdr->next_to_clean = 0;
1248 spin_lock_init(&txdr->tx_lock);
1254 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1255 * (Descriptors) for all queues
1256 * @adapter: board private structure
1258 * If this function returns with an error, then it's possible one or
1259 * more of the rings is populated (while the rest are not). It is the
1260 * callers duty to clean those orphaned rings.
1262 * Return 0 on success, negative on failure
1266 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1270 for (i = 0; i < adapter->num_tx_queues; i++) {
1271 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1274 "Allocation for Tx Queue %u failed\n", i);
1283 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1284 * @adapter: board private structure
1286 * Configure the Tx unit of the MAC after a reset.
1290 e1000_configure_tx(struct e1000_adapter *adapter)
1293 struct e1000_hw *hw = &adapter->hw;
1294 uint32_t tdlen, tctl, tipg, tarc;
1295 uint32_t ipgr1, ipgr2;
1297 /* Setup the HW Tx Head and Tail descriptor pointers */
1299 switch (adapter->num_tx_queues) {
1302 tdba = adapter->tx_ring[0].dma;
1303 tdlen = adapter->tx_ring[0].count *
1304 sizeof(struct e1000_tx_desc);
1305 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1306 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1307 E1000_WRITE_REG(hw, TDLEN, tdlen);
1308 E1000_WRITE_REG(hw, TDH, 0);
1309 E1000_WRITE_REG(hw, TDT, 0);
1310 adapter->tx_ring[0].tdh = E1000_TDH;
1311 adapter->tx_ring[0].tdt = E1000_TDT;
1315 /* Set the default values for the Tx Inter Packet Gap timer */
1317 if (hw->media_type == e1000_media_type_fiber ||
1318 hw->media_type == e1000_media_type_internal_serdes)
1319 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1321 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1323 switch (hw->mac_type) {
1324 case e1000_82542_rev2_0:
1325 case e1000_82542_rev2_1:
1326 tipg = DEFAULT_82542_TIPG_IPGT;
1327 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1328 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1330 case e1000_80003es2lan:
1331 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1332 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1335 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1336 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1339 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1340 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1341 E1000_WRITE_REG(hw, TIPG, tipg);
1343 /* Set the Tx Interrupt Delay register */
1345 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1346 if (hw->mac_type >= e1000_82540)
1347 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1349 /* Program the Transmit Control Register */
1351 tctl = E1000_READ_REG(hw, TCTL);
1353 tctl &= ~E1000_TCTL_CT;
1354 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1355 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1358 /* disable Multiple Reads for debugging */
1359 tctl &= ~E1000_TCTL_MULR;
1362 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1363 tarc = E1000_READ_REG(hw, TARC0);
1364 tarc |= ((1 << 25) | (1 << 21));
1365 E1000_WRITE_REG(hw, TARC0, tarc);
1366 tarc = E1000_READ_REG(hw, TARC1);
1368 if (tctl & E1000_TCTL_MULR)
1372 E1000_WRITE_REG(hw, TARC1, tarc);
1373 } else if (hw->mac_type == e1000_80003es2lan) {
1374 tarc = E1000_READ_REG(hw, TARC0);
1376 if (hw->media_type == e1000_media_type_internal_serdes)
1378 E1000_WRITE_REG(hw, TARC0, tarc);
1379 tarc = E1000_READ_REG(hw, TARC1);
1381 E1000_WRITE_REG(hw, TARC1, tarc);
1384 e1000_config_collision_dist(hw);
1386 /* Setup Transmit Descriptor Settings for eop descriptor */
1387 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1390 if (hw->mac_type < e1000_82543)
1391 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1393 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1395 /* Cache if we're 82544 running in PCI-X because we'll
1396 * need this to apply a workaround later in the send path. */
1397 if (hw->mac_type == e1000_82544 &&
1398 hw->bus_type == e1000_bus_type_pcix)
1399 adapter->pcix_82544 = 1;
1401 E1000_WRITE_REG(hw, TCTL, tctl);
1406 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1407 * @adapter: board private structure
1408 * @rxdr: rx descriptor ring (for a specific queue) to setup
1410 * Returns 0 on success, negative on failure
1414 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1415 struct e1000_rx_ring *rxdr)
1417 struct pci_dev *pdev = adapter->pdev;
1420 size = sizeof(struct e1000_buffer) * rxdr->count;
1421 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1422 if (!rxdr->buffer_info) {
1424 "Unable to allocate memory for the receive descriptor ring\n");
1427 memset(rxdr->buffer_info, 0, size);
1429 size = sizeof(struct e1000_ps_page) * rxdr->count;
1430 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1431 if (!rxdr->ps_page) {
1432 vfree(rxdr->buffer_info);
1434 "Unable to allocate memory for the receive descriptor ring\n");
1437 memset(rxdr->ps_page, 0, size);
1439 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1440 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1441 if (!rxdr->ps_page_dma) {
1442 vfree(rxdr->buffer_info);
1443 kfree(rxdr->ps_page);
1445 "Unable to allocate memory for the receive descriptor ring\n");
1448 memset(rxdr->ps_page_dma, 0, size);
1450 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1451 desc_len = sizeof(struct e1000_rx_desc);
1453 desc_len = sizeof(union e1000_rx_desc_packet_split);
1455 /* Round up to nearest 4K */
1457 rxdr->size = rxdr->count * desc_len;
1458 E1000_ROUNDUP(rxdr->size, 4096);
1460 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1464 "Unable to allocate memory for the receive descriptor ring\n");
1466 vfree(rxdr->buffer_info);
1467 kfree(rxdr->ps_page);
1468 kfree(rxdr->ps_page_dma);
1472 /* Fix for errata 23, can't cross 64kB boundary */
1473 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1474 void *olddesc = rxdr->desc;
1475 dma_addr_t olddma = rxdr->dma;
1476 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1477 "at %p\n", rxdr->size, rxdr->desc);
1478 /* Try again, without freeing the previous */
1479 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1480 /* Failed allocation, critical failure */
1482 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1484 "Unable to allocate memory "
1485 "for the receive descriptor ring\n");
1486 goto setup_rx_desc_die;
1489 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1491 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1493 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1495 "Unable to allocate aligned memory "
1496 "for the receive descriptor ring\n");
1497 goto setup_rx_desc_die;
1499 /* Free old allocation, new allocation was successful */
1500 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1503 memset(rxdr->desc, 0, rxdr->size);
1505 rxdr->next_to_clean = 0;
1506 rxdr->next_to_use = 0;
1512 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1513 * (Descriptors) for all queues
1514 * @adapter: board private structure
1516 * If this function returns with an error, then it's possible one or
1517 * more of the rings is populated (while the rest are not). It is the
1518 * callers duty to clean those orphaned rings.
1520 * Return 0 on success, negative on failure
1524 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1528 for (i = 0; i < adapter->num_rx_queues; i++) {
1529 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1532 "Allocation for Rx Queue %u failed\n", i);
1541 * e1000_setup_rctl - configure the receive control registers
1542 * @adapter: Board private structure
1544 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1545 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1547 e1000_setup_rctl(struct e1000_adapter *adapter)
1549 uint32_t rctl, rfctl;
1550 uint32_t psrctl = 0;
1551 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1555 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1557 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1559 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1560 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1561 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1563 if (adapter->hw.mac_type > e1000_82543)
1564 rctl |= E1000_RCTL_SECRC;
1566 if (adapter->hw.tbi_compatibility_on == 1)
1567 rctl |= E1000_RCTL_SBP;
1569 rctl &= ~E1000_RCTL_SBP;
1571 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1572 rctl &= ~E1000_RCTL_LPE;
1574 rctl |= E1000_RCTL_LPE;
1576 /* Setup buffer sizes */
1577 rctl &= ~E1000_RCTL_SZ_4096;
1578 rctl |= E1000_RCTL_BSEX;
1579 switch (adapter->rx_buffer_len) {
1580 case E1000_RXBUFFER_256:
1581 rctl |= E1000_RCTL_SZ_256;
1582 rctl &= ~E1000_RCTL_BSEX;
1584 case E1000_RXBUFFER_512:
1585 rctl |= E1000_RCTL_SZ_512;
1586 rctl &= ~E1000_RCTL_BSEX;
1588 case E1000_RXBUFFER_1024:
1589 rctl |= E1000_RCTL_SZ_1024;
1590 rctl &= ~E1000_RCTL_BSEX;
1592 case E1000_RXBUFFER_2048:
1594 rctl |= E1000_RCTL_SZ_2048;
1595 rctl &= ~E1000_RCTL_BSEX;
1597 case E1000_RXBUFFER_4096:
1598 rctl |= E1000_RCTL_SZ_4096;
1600 case E1000_RXBUFFER_8192:
1601 rctl |= E1000_RCTL_SZ_8192;
1603 case E1000_RXBUFFER_16384:
1604 rctl |= E1000_RCTL_SZ_16384;
1608 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1609 /* 82571 and greater support packet-split where the protocol
1610 * header is placed in skb->data and the packet data is
1611 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1612 * In the case of a non-split, skb->data is linearly filled,
1613 * followed by the page buffers. Therefore, skb->data is
1614 * sized to hold the largest protocol header.
1616 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1617 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1619 adapter->rx_ps_pages = pages;
1621 adapter->rx_ps_pages = 0;
1623 if (adapter->rx_ps_pages) {
1624 /* Configure extra packet-split registers */
1625 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1626 rfctl |= E1000_RFCTL_EXTEN;
1627 /* disable IPv6 packet split support */
1628 rfctl |= E1000_RFCTL_IPV6_DIS;
1629 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1631 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1633 psrctl |= adapter->rx_ps_bsize0 >>
1634 E1000_PSRCTL_BSIZE0_SHIFT;
1636 switch (adapter->rx_ps_pages) {
1638 psrctl |= PAGE_SIZE <<
1639 E1000_PSRCTL_BSIZE3_SHIFT;
1641 psrctl |= PAGE_SIZE <<
1642 E1000_PSRCTL_BSIZE2_SHIFT;
1644 psrctl |= PAGE_SIZE >>
1645 E1000_PSRCTL_BSIZE1_SHIFT;
1649 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1652 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1656 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1657 * @adapter: board private structure
1659 * Configure the Rx unit of the MAC after a reset.
1663 e1000_configure_rx(struct e1000_adapter *adapter)
1666 struct e1000_hw *hw = &adapter->hw;
1667 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1669 if (adapter->rx_ps_pages) {
1670 /* this is a 32 byte descriptor */
1671 rdlen = adapter->rx_ring[0].count *
1672 sizeof(union e1000_rx_desc_packet_split);
1673 adapter->clean_rx = e1000_clean_rx_irq_ps;
1674 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1676 rdlen = adapter->rx_ring[0].count *
1677 sizeof(struct e1000_rx_desc);
1678 adapter->clean_rx = e1000_clean_rx_irq;
1679 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1682 /* disable receives while setting up the descriptors */
1683 rctl = E1000_READ_REG(hw, RCTL);
1684 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1686 /* set the Receive Delay Timer Register */
1687 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1689 if (hw->mac_type >= e1000_82540) {
1690 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1691 if (adapter->itr > 1)
1692 E1000_WRITE_REG(hw, ITR,
1693 1000000000 / (adapter->itr * 256));
1696 if (hw->mac_type >= e1000_82571) {
1697 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1698 /* Reset delay timers after every interrupt */
1699 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
1700 #ifdef CONFIG_E1000_NAPI
1701 /* Auto-Mask interrupts upon ICR read. */
1702 ctrl_ext |= E1000_CTRL_EXT_IAME;
1704 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1705 E1000_WRITE_REG(hw, IAM, ~0);
1706 E1000_WRITE_FLUSH(hw);
1709 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1710 * the Base and Length of the Rx Descriptor Ring */
1711 switch (adapter->num_rx_queues) {
1714 rdba = adapter->rx_ring[0].dma;
1715 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1716 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1717 E1000_WRITE_REG(hw, RDLEN, rdlen);
1718 E1000_WRITE_REG(hw, RDH, 0);
1719 E1000_WRITE_REG(hw, RDT, 0);
1720 adapter->rx_ring[0].rdh = E1000_RDH;
1721 adapter->rx_ring[0].rdt = E1000_RDT;
1725 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1726 if (hw->mac_type >= e1000_82543) {
1727 rxcsum = E1000_READ_REG(hw, RXCSUM);
1728 if (adapter->rx_csum == TRUE) {
1729 rxcsum |= E1000_RXCSUM_TUOFL;
1731 /* Enable 82571 IPv4 payload checksum for UDP fragments
1732 * Must be used in conjunction with packet-split. */
1733 if ((hw->mac_type >= e1000_82571) &&
1734 (adapter->rx_ps_pages)) {
1735 rxcsum |= E1000_RXCSUM_IPPCSE;
1738 rxcsum &= ~E1000_RXCSUM_TUOFL;
1739 /* don't need to clear IPPCSE as it defaults to 0 */
1741 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1744 if (hw->mac_type == e1000_82573)
1745 E1000_WRITE_REG(hw, ERT, 0x0100);
1747 /* Enable Receives */
1748 E1000_WRITE_REG(hw, RCTL, rctl);
1752 * e1000_free_tx_resources - Free Tx Resources per Queue
1753 * @adapter: board private structure
1754 * @tx_ring: Tx descriptor ring for a specific queue
1756 * Free all transmit software resources
1760 e1000_free_tx_resources(struct e1000_adapter *adapter,
1761 struct e1000_tx_ring *tx_ring)
1763 struct pci_dev *pdev = adapter->pdev;
1765 e1000_clean_tx_ring(adapter, tx_ring);
1767 vfree(tx_ring->buffer_info);
1768 tx_ring->buffer_info = NULL;
1770 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1772 tx_ring->desc = NULL;
1776 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1777 * @adapter: board private structure
1779 * Free all transmit software resources
1783 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1787 for (i = 0; i < adapter->num_tx_queues; i++)
1788 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1792 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1793 struct e1000_buffer *buffer_info)
1795 if (buffer_info->dma) {
1796 pci_unmap_page(adapter->pdev,
1798 buffer_info->length,
1801 if (buffer_info->skb)
1802 dev_kfree_skb_any(buffer_info->skb);
1803 memset(buffer_info, 0, sizeof(struct e1000_buffer));
1807 * e1000_clean_tx_ring - Free Tx Buffers
1808 * @adapter: board private structure
1809 * @tx_ring: ring to be cleaned
1813 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1814 struct e1000_tx_ring *tx_ring)
1816 struct e1000_buffer *buffer_info;
1820 /* Free all the Tx ring sk_buffs */
1822 for (i = 0; i < tx_ring->count; i++) {
1823 buffer_info = &tx_ring->buffer_info[i];
1824 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1827 size = sizeof(struct e1000_buffer) * tx_ring->count;
1828 memset(tx_ring->buffer_info, 0, size);
1830 /* Zero out the descriptor ring */
1832 memset(tx_ring->desc, 0, tx_ring->size);
1834 tx_ring->next_to_use = 0;
1835 tx_ring->next_to_clean = 0;
1836 tx_ring->last_tx_tso = 0;
1838 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1839 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1843 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1844 * @adapter: board private structure
1848 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1852 for (i = 0; i < adapter->num_tx_queues; i++)
1853 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1857 * e1000_free_rx_resources - Free Rx Resources
1858 * @adapter: board private structure
1859 * @rx_ring: ring to clean the resources from
1861 * Free all receive software resources
1865 e1000_free_rx_resources(struct e1000_adapter *adapter,
1866 struct e1000_rx_ring *rx_ring)
1868 struct pci_dev *pdev = adapter->pdev;
1870 e1000_clean_rx_ring(adapter, rx_ring);
1872 vfree(rx_ring->buffer_info);
1873 rx_ring->buffer_info = NULL;
1874 kfree(rx_ring->ps_page);
1875 rx_ring->ps_page = NULL;
1876 kfree(rx_ring->ps_page_dma);
1877 rx_ring->ps_page_dma = NULL;
1879 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1881 rx_ring->desc = NULL;
1885 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1886 * @adapter: board private structure
1888 * Free all receive software resources
1892 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1896 for (i = 0; i < adapter->num_rx_queues; i++)
1897 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1901 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1902 * @adapter: board private structure
1903 * @rx_ring: ring to free buffers from
1907 e1000_clean_rx_ring(struct e1000_adapter *adapter,
1908 struct e1000_rx_ring *rx_ring)
1910 struct e1000_buffer *buffer_info;
1911 struct e1000_ps_page *ps_page;
1912 struct e1000_ps_page_dma *ps_page_dma;
1913 struct pci_dev *pdev = adapter->pdev;
1917 /* Free all the Rx ring sk_buffs */
1918 for (i = 0; i < rx_ring->count; i++) {
1919 buffer_info = &rx_ring->buffer_info[i];
1920 if (buffer_info->skb) {
1921 pci_unmap_single(pdev,
1923 buffer_info->length,
1924 PCI_DMA_FROMDEVICE);
1926 dev_kfree_skb(buffer_info->skb);
1927 buffer_info->skb = NULL;
1929 ps_page = &rx_ring->ps_page[i];
1930 ps_page_dma = &rx_ring->ps_page_dma[i];
1931 for (j = 0; j < adapter->rx_ps_pages; j++) {
1932 if (!ps_page->ps_page[j]) break;
1933 pci_unmap_page(pdev,
1934 ps_page_dma->ps_page_dma[j],
1935 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1936 ps_page_dma->ps_page_dma[j] = 0;
1937 put_page(ps_page->ps_page[j]);
1938 ps_page->ps_page[j] = NULL;
1942 size = sizeof(struct e1000_buffer) * rx_ring->count;
1943 memset(rx_ring->buffer_info, 0, size);
1944 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1945 memset(rx_ring->ps_page, 0, size);
1946 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1947 memset(rx_ring->ps_page_dma, 0, size);
1949 /* Zero out the descriptor ring */
1951 memset(rx_ring->desc, 0, rx_ring->size);
1953 rx_ring->next_to_clean = 0;
1954 rx_ring->next_to_use = 0;
1956 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1957 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1961 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1962 * @adapter: board private structure
1966 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1970 for (i = 0; i < adapter->num_rx_queues; i++)
1971 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1974 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1975 * and memory write and invalidate disabled for certain operations
1978 e1000_enter_82542_rst(struct e1000_adapter *adapter)
1980 struct net_device *netdev = adapter->netdev;
1983 e1000_pci_clear_mwi(&adapter->hw);
1985 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1986 rctl |= E1000_RCTL_RST;
1987 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1988 E1000_WRITE_FLUSH(&adapter->hw);
1991 if (netif_running(netdev))
1992 e1000_clean_all_rx_rings(adapter);
1996 e1000_leave_82542_rst(struct e1000_adapter *adapter)
1998 struct net_device *netdev = adapter->netdev;
2001 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2002 rctl &= ~E1000_RCTL_RST;
2003 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2004 E1000_WRITE_FLUSH(&adapter->hw);
2007 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2008 e1000_pci_set_mwi(&adapter->hw);
2010 if (netif_running(netdev)) {
2011 /* No need to loop, because 82542 supports only 1 queue */
2012 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2013 e1000_configure_rx(adapter);
2014 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2019 * e1000_set_mac - Change the Ethernet Address of the NIC
2020 * @netdev: network interface device structure
2021 * @p: pointer to an address structure
2023 * Returns 0 on success, negative on failure
2027 e1000_set_mac(struct net_device *netdev, void *p)
2029 struct e1000_adapter *adapter = netdev_priv(netdev);
2030 struct sockaddr *addr = p;
2032 if (!is_valid_ether_addr(addr->sa_data))
2033 return -EADDRNOTAVAIL;
2035 /* 82542 2.0 needs to be in reset to write receive address registers */
2037 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2038 e1000_enter_82542_rst(adapter);
2040 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2041 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2043 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2045 /* With 82571 controllers, LAA may be overwritten (with the default)
2046 * due to controller reset from the other port. */
2047 if (adapter->hw.mac_type == e1000_82571) {
2048 /* activate the work around */
2049 adapter->hw.laa_is_present = 1;
2051 /* Hold a copy of the LAA in RAR[14] This is done so that
2052 * between the time RAR[0] gets clobbered and the time it
2053 * gets fixed (in e1000_watchdog), the actual LAA is in one
2054 * of the RARs and no incoming packets directed to this port
2055 * are dropped. Eventaully the LAA will be in RAR[0] and
2057 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2058 E1000_RAR_ENTRIES - 1);
2061 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2062 e1000_leave_82542_rst(adapter);
2068 * e1000_set_multi - Multicast and Promiscuous mode set
2069 * @netdev: network interface device structure
2071 * The set_multi entry point is called whenever the multicast address
2072 * list or the network interface flags are updated. This routine is
2073 * responsible for configuring the hardware for proper multicast,
2074 * promiscuous mode, and all-multi behavior.
2078 e1000_set_multi(struct net_device *netdev)
2080 struct e1000_adapter *adapter = netdev_priv(netdev);
2081 struct e1000_hw *hw = &adapter->hw;
2082 struct dev_mc_list *mc_ptr;
2084 uint32_t hash_value;
2085 int i, rar_entries = E1000_RAR_ENTRIES;
2087 /* reserve RAR[14] for LAA over-write work-around */
2088 if (adapter->hw.mac_type == e1000_82571)
2091 /* Check for Promiscuous and All Multicast modes */
2093 rctl = E1000_READ_REG(hw, RCTL);
2095 if (netdev->flags & IFF_PROMISC) {
2096 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2097 } else if (netdev->flags & IFF_ALLMULTI) {
2098 rctl |= E1000_RCTL_MPE;
2099 rctl &= ~E1000_RCTL_UPE;
2101 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2104 E1000_WRITE_REG(hw, RCTL, rctl);
2106 /* 82542 2.0 needs to be in reset to write receive address registers */
2108 if (hw->mac_type == e1000_82542_rev2_0)
2109 e1000_enter_82542_rst(adapter);
2111 /* load the first 14 multicast address into the exact filters 1-14
2112 * RAR 0 is used for the station MAC adddress
2113 * if there are not 14 addresses, go ahead and clear the filters
2114 * -- with 82571 controllers only 0-13 entries are filled here
2116 mc_ptr = netdev->mc_list;
2118 for (i = 1; i < rar_entries; i++) {
2120 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2121 mc_ptr = mc_ptr->next;
2123 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2124 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2128 /* clear the old settings from the multicast hash table */
2130 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2131 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2133 /* load any remaining addresses into the hash table */
2135 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2136 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2137 e1000_mta_set(hw, hash_value);
2140 if (hw->mac_type == e1000_82542_rev2_0)
2141 e1000_leave_82542_rst(adapter);
2144 /* Need to wait a few seconds after link up to get diagnostic information from
2148 e1000_update_phy_info(unsigned long data)
2150 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2151 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2155 * e1000_82547_tx_fifo_stall - Timer Call-back
2156 * @data: pointer to adapter cast into an unsigned long
2160 e1000_82547_tx_fifo_stall(unsigned long data)
2162 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2163 struct net_device *netdev = adapter->netdev;
2166 if (atomic_read(&adapter->tx_fifo_stall)) {
2167 if ((E1000_READ_REG(&adapter->hw, TDT) ==
2168 E1000_READ_REG(&adapter->hw, TDH)) &&
2169 (E1000_READ_REG(&adapter->hw, TDFT) ==
2170 E1000_READ_REG(&adapter->hw, TDFH)) &&
2171 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2172 E1000_READ_REG(&adapter->hw, TDFHS))) {
2173 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2174 E1000_WRITE_REG(&adapter->hw, TCTL,
2175 tctl & ~E1000_TCTL_EN);
2176 E1000_WRITE_REG(&adapter->hw, TDFT,
2177 adapter->tx_head_addr);
2178 E1000_WRITE_REG(&adapter->hw, TDFH,
2179 adapter->tx_head_addr);
2180 E1000_WRITE_REG(&adapter->hw, TDFTS,
2181 adapter->tx_head_addr);
2182 E1000_WRITE_REG(&adapter->hw, TDFHS,
2183 adapter->tx_head_addr);
2184 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2185 E1000_WRITE_FLUSH(&adapter->hw);
2187 adapter->tx_fifo_head = 0;
2188 atomic_set(&adapter->tx_fifo_stall, 0);
2189 netif_wake_queue(netdev);
2191 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2197 * e1000_watchdog - Timer Call-back
2198 * @data: pointer to adapter cast into an unsigned long
2201 e1000_watchdog(unsigned long data)
2203 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2205 /* Do the rest outside of interrupt context */
2206 schedule_work(&adapter->watchdog_task);
2210 e1000_watchdog_task(struct e1000_adapter *adapter)
2212 struct net_device *netdev = adapter->netdev;
2213 struct e1000_tx_ring *txdr = adapter->tx_ring;
2214 uint32_t link, tctl;
2216 e1000_check_for_link(&adapter->hw);
2217 if (adapter->hw.mac_type == e1000_82573) {
2218 e1000_enable_tx_pkt_filtering(&adapter->hw);
2219 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2220 e1000_update_mng_vlan(adapter);
2223 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2224 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2225 link = !adapter->hw.serdes_link_down;
2227 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2230 if (!netif_carrier_ok(netdev)) {
2231 boolean_t txb2b = 1;
2232 e1000_get_speed_and_duplex(&adapter->hw,
2233 &adapter->link_speed,
2234 &adapter->link_duplex);
2236 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2237 adapter->link_speed,
2238 adapter->link_duplex == FULL_DUPLEX ?
2239 "Full Duplex" : "Half Duplex");
2241 /* tweak tx_queue_len according to speed/duplex
2242 * and adjust the timeout factor */
2243 netdev->tx_queue_len = adapter->tx_queue_len;
2244 adapter->tx_timeout_factor = 1;
2245 switch (adapter->link_speed) {
2248 netdev->tx_queue_len = 10;
2249 adapter->tx_timeout_factor = 8;
2253 netdev->tx_queue_len = 100;
2254 /* maybe add some timeout factor ? */
2258 if ((adapter->hw.mac_type == e1000_82571 ||
2259 adapter->hw.mac_type == e1000_82572) &&
2261 #define SPEED_MODE_BIT (1 << 21)
2263 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2264 tarc0 &= ~SPEED_MODE_BIT;
2265 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2269 /* disable TSO for pcie and 10/100 speeds, to avoid
2270 * some hardware issues */
2271 if (!adapter->tso_force &&
2272 adapter->hw.bus_type == e1000_bus_type_pci_express){
2273 switch (adapter->link_speed) {
2277 "10/100 speed: disabling TSO\n");
2278 netdev->features &= ~NETIF_F_TSO;
2281 netdev->features |= NETIF_F_TSO;
2290 /* enable transmits in the hardware, need to do this
2291 * after setting TARC0 */
2292 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2293 tctl |= E1000_TCTL_EN;
2294 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2296 netif_carrier_on(netdev);
2297 netif_wake_queue(netdev);
2298 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2299 adapter->smartspeed = 0;
2302 if (netif_carrier_ok(netdev)) {
2303 adapter->link_speed = 0;
2304 adapter->link_duplex = 0;
2305 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2306 netif_carrier_off(netdev);
2307 netif_stop_queue(netdev);
2308 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2310 /* 80003ES2LAN workaround--
2311 * For packet buffer work-around on link down event;
2312 * disable receives in the ISR and
2313 * reset device here in the watchdog
2315 if (adapter->hw.mac_type == e1000_80003es2lan) {
2317 schedule_work(&adapter->reset_task);
2321 e1000_smartspeed(adapter);
2324 e1000_update_stats(adapter);
2326 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2327 adapter->tpt_old = adapter->stats.tpt;
2328 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2329 adapter->colc_old = adapter->stats.colc;
2331 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2332 adapter->gorcl_old = adapter->stats.gorcl;
2333 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2334 adapter->gotcl_old = adapter->stats.gotcl;
2336 e1000_update_adaptive(&adapter->hw);
2338 if (!netif_carrier_ok(netdev)) {
2339 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2340 /* We've lost link, so the controller stops DMA,
2341 * but we've got queued Tx work that's never going
2342 * to get done, so reset controller to flush Tx.
2343 * (Do the reset outside of interrupt context). */
2344 adapter->tx_timeout_count++;
2345 schedule_work(&adapter->reset_task);
2349 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2350 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2351 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2352 * asymmetrical Tx or Rx gets ITR=8000; everyone
2353 * else is between 2000-8000. */
2354 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2355 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2356 adapter->gotcl - adapter->gorcl :
2357 adapter->gorcl - adapter->gotcl) / 10000;
2358 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2359 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2362 /* Cause software interrupt to ensure rx ring is cleaned */
2363 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2365 /* Force detection of hung controller every watchdog period */
2366 adapter->detect_tx_hung = TRUE;
2368 /* With 82571 controllers, LAA may be overwritten due to controller
2369 * reset from the other port. Set the appropriate LAA in RAR[0] */
2370 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2371 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2373 /* Reset the timer */
2374 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2377 #define E1000_TX_FLAGS_CSUM 0x00000001
2378 #define E1000_TX_FLAGS_VLAN 0x00000002
2379 #define E1000_TX_FLAGS_TSO 0x00000004
2380 #define E1000_TX_FLAGS_IPV4 0x00000008
2381 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2382 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2385 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2386 struct sk_buff *skb)
2389 struct e1000_context_desc *context_desc;
2390 struct e1000_buffer *buffer_info;
2392 uint32_t cmd_length = 0;
2393 uint16_t ipcse = 0, tucse, mss;
2394 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2397 if (skb_shinfo(skb)->tso_size) {
2398 if (skb_header_cloned(skb)) {
2399 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2404 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2405 mss = skb_shinfo(skb)->tso_size;
2406 if (skb->protocol == htons(ETH_P_IP)) {
2407 skb->nh.iph->tot_len = 0;
2408 skb->nh.iph->check = 0;
2410 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2415 cmd_length = E1000_TXD_CMD_IP;
2416 ipcse = skb->h.raw - skb->data - 1;
2417 #ifdef NETIF_F_TSO_IPV6
2418 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
2419 skb->nh.ipv6h->payload_len = 0;
2421 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2422 &skb->nh.ipv6h->daddr,
2429 ipcss = skb->nh.raw - skb->data;
2430 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2431 tucss = skb->h.raw - skb->data;
2432 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2435 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2436 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2438 i = tx_ring->next_to_use;
2439 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2440 buffer_info = &tx_ring->buffer_info[i];
2442 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2443 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2444 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2445 context_desc->upper_setup.tcp_fields.tucss = tucss;
2446 context_desc->upper_setup.tcp_fields.tucso = tucso;
2447 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2448 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2449 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2450 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2452 buffer_info->time_stamp = jiffies;
2454 if (++i == tx_ring->count) i = 0;
2455 tx_ring->next_to_use = i;
2465 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2466 struct sk_buff *skb)
2468 struct e1000_context_desc *context_desc;
2469 struct e1000_buffer *buffer_info;
2473 if (likely(skb->ip_summed == CHECKSUM_HW)) {
2474 css = skb->h.raw - skb->data;
2476 i = tx_ring->next_to_use;
2477 buffer_info = &tx_ring->buffer_info[i];
2478 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2480 context_desc->upper_setup.tcp_fields.tucss = css;
2481 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2482 context_desc->upper_setup.tcp_fields.tucse = 0;
2483 context_desc->tcp_seg_setup.data = 0;
2484 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2486 buffer_info->time_stamp = jiffies;
2488 if (unlikely(++i == tx_ring->count)) i = 0;
2489 tx_ring->next_to_use = i;
2497 #define E1000_MAX_TXD_PWR 12
2498 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2501 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2502 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2503 unsigned int nr_frags, unsigned int mss)
2505 struct e1000_buffer *buffer_info;
2506 unsigned int len = skb->len;
2507 unsigned int offset = 0, size, count = 0, i;
2509 len -= skb->data_len;
2511 i = tx_ring->next_to_use;
2514 buffer_info = &tx_ring->buffer_info[i];
2515 size = min(len, max_per_txd);
2517 /* Workaround for Controller erratum --
2518 * descriptor for non-tso packet in a linear SKB that follows a
2519 * tso gets written back prematurely before the data is fully
2520 * DMA'd to the controller */
2521 if (!skb->data_len && tx_ring->last_tx_tso &&
2522 !skb_shinfo(skb)->tso_size) {
2523 tx_ring->last_tx_tso = 0;
2527 /* Workaround for premature desc write-backs
2528 * in TSO mode. Append 4-byte sentinel desc */
2529 if (unlikely(mss && !nr_frags && size == len && size > 8))
2532 /* work-around for errata 10 and it applies
2533 * to all controllers in PCI-X mode
2534 * The fix is to make sure that the first descriptor of a
2535 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2537 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2538 (size > 2015) && count == 0))
2541 /* Workaround for potential 82544 hang in PCI-X. Avoid
2542 * terminating buffers within evenly-aligned dwords. */
2543 if (unlikely(adapter->pcix_82544 &&
2544 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2548 buffer_info->length = size;
2550 pci_map_single(adapter->pdev,
2554 buffer_info->time_stamp = jiffies;
2559 if (unlikely(++i == tx_ring->count)) i = 0;
2562 for (f = 0; f < nr_frags; f++) {
2563 struct skb_frag_struct *frag;
2565 frag = &skb_shinfo(skb)->frags[f];
2567 offset = frag->page_offset;
2570 buffer_info = &tx_ring->buffer_info[i];
2571 size = min(len, max_per_txd);
2573 /* Workaround for premature desc write-backs
2574 * in TSO mode. Append 4-byte sentinel desc */
2575 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2578 /* Workaround for potential 82544 hang in PCI-X.
2579 * Avoid terminating buffers within evenly-aligned
2581 if (unlikely(adapter->pcix_82544 &&
2582 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2586 buffer_info->length = size;
2588 pci_map_page(adapter->pdev,
2593 buffer_info->time_stamp = jiffies;
2598 if (unlikely(++i == tx_ring->count)) i = 0;
2602 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2603 tx_ring->buffer_info[i].skb = skb;
2604 tx_ring->buffer_info[first].next_to_watch = i;
2610 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2611 int tx_flags, int count)
2613 struct e1000_tx_desc *tx_desc = NULL;
2614 struct e1000_buffer *buffer_info;
2615 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2618 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2619 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2621 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2623 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2624 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2627 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2628 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2629 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2632 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2633 txd_lower |= E1000_TXD_CMD_VLE;
2634 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2637 i = tx_ring->next_to_use;
2640 buffer_info = &tx_ring->buffer_info[i];
2641 tx_desc = E1000_TX_DESC(*tx_ring, i);
2642 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2643 tx_desc->lower.data =
2644 cpu_to_le32(txd_lower | buffer_info->length);
2645 tx_desc->upper.data = cpu_to_le32(txd_upper);
2646 if (unlikely(++i == tx_ring->count)) i = 0;
2649 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2651 /* Force memory writes to complete before letting h/w
2652 * know there are new descriptors to fetch. (Only
2653 * applicable for weak-ordered memory model archs,
2654 * such as IA-64). */
2657 tx_ring->next_to_use = i;
2658 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2662 * 82547 workaround to avoid controller hang in half-duplex environment.
2663 * The workaround is to avoid queuing a large packet that would span
2664 * the internal Tx FIFO ring boundary by notifying the stack to resend
2665 * the packet at a later time. This gives the Tx FIFO an opportunity to
2666 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2667 * to the beginning of the Tx FIFO.
2670 #define E1000_FIFO_HDR 0x10
2671 #define E1000_82547_PAD_LEN 0x3E0
2674 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2676 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2677 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2679 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2681 if (adapter->link_duplex != HALF_DUPLEX)
2682 goto no_fifo_stall_required;
2684 if (atomic_read(&adapter->tx_fifo_stall))
2687 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2688 atomic_set(&adapter->tx_fifo_stall, 1);
2692 no_fifo_stall_required:
2693 adapter->tx_fifo_head += skb_fifo_len;
2694 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
2695 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2699 #define MINIMUM_DHCP_PACKET_SIZE 282
2701 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2703 struct e1000_hw *hw = &adapter->hw;
2704 uint16_t length, offset;
2705 if (vlan_tx_tag_present(skb)) {
2706 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2707 ( adapter->hw.mng_cookie.status &
2708 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2711 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
2712 struct ethhdr *eth = (struct ethhdr *) skb->data;
2713 if ((htons(ETH_P_IP) == eth->h_proto)) {
2714 const struct iphdr *ip =
2715 (struct iphdr *)((uint8_t *)skb->data+14);
2716 if (IPPROTO_UDP == ip->protocol) {
2717 struct udphdr *udp =
2718 (struct udphdr *)((uint8_t *)ip +
2720 if (ntohs(udp->dest) == 67) {
2721 offset = (uint8_t *)udp + 8 - skb->data;
2722 length = skb->len - offset;
2724 return e1000_mng_write_dhcp_info(hw,
2734 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2736 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2738 struct e1000_adapter *adapter = netdev_priv(netdev);
2739 struct e1000_tx_ring *tx_ring;
2740 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2741 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2742 unsigned int tx_flags = 0;
2743 unsigned int len = skb->len;
2744 unsigned long flags;
2745 unsigned int nr_frags = 0;
2746 unsigned int mss = 0;
2750 len -= skb->data_len;
2752 tx_ring = adapter->tx_ring;
2754 if (unlikely(skb->len <= 0)) {
2755 dev_kfree_skb_any(skb);
2756 return NETDEV_TX_OK;
2760 mss = skb_shinfo(skb)->tso_size;
2761 /* The controller does a simple calculation to
2762 * make sure there is enough room in the FIFO before
2763 * initiating the DMA for each buffer. The calc is:
2764 * 4 = ceil(buffer len/mss). To make sure we don't
2765 * overrun the FIFO, adjust the max buffer len if mss
2769 max_per_txd = min(mss << 2, max_per_txd);
2770 max_txd_pwr = fls(max_per_txd) - 1;
2772 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
2773 * points to just header, pull a few bytes of payload from
2774 * frags into skb->data */
2775 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2776 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
2777 switch (adapter->hw.mac_type) {
2778 unsigned int pull_size;
2782 pull_size = min((unsigned int)4, skb->data_len);
2783 if (!__pskb_pull_tail(skb, pull_size)) {
2785 "__pskb_pull_tail failed.\n");
2786 dev_kfree_skb_any(skb);
2787 return NETDEV_TX_OK;
2789 len = skb->len - skb->data_len;
2798 /* reserve a descriptor for the offload context */
2799 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
2803 if (skb->ip_summed == CHECKSUM_HW)
2808 /* Controller Erratum workaround */
2809 if (!skb->data_len && tx_ring->last_tx_tso &&
2810 !skb_shinfo(skb)->tso_size)
2814 count += TXD_USE_COUNT(len, max_txd_pwr);
2816 if (adapter->pcix_82544)
2819 /* work-around for errata 10 and it applies to all controllers
2820 * in PCI-X mode, so add one more descriptor to the count
2822 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2826 nr_frags = skb_shinfo(skb)->nr_frags;
2827 for (f = 0; f < nr_frags; f++)
2828 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2830 if (adapter->pcix_82544)
2834 if (adapter->hw.tx_pkt_filtering &&
2835 (adapter->hw.mac_type == e1000_82573))
2836 e1000_transfer_dhcp_info(adapter, skb);
2838 local_irq_save(flags);
2839 if (!spin_trylock(&tx_ring->tx_lock)) {
2840 /* Collision - tell upper layer to requeue */
2841 local_irq_restore(flags);
2842 return NETDEV_TX_LOCKED;
2845 /* need: count + 2 desc gap to keep tail from touching
2846 * head, otherwise try next time */
2847 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2848 netif_stop_queue(netdev);
2849 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2850 return NETDEV_TX_BUSY;
2853 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2854 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2855 netif_stop_queue(netdev);
2856 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2857 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2858 return NETDEV_TX_BUSY;
2862 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2863 tx_flags |= E1000_TX_FLAGS_VLAN;
2864 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2867 first = tx_ring->next_to_use;
2869 tso = e1000_tso(adapter, tx_ring, skb);
2871 dev_kfree_skb_any(skb);
2872 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2873 return NETDEV_TX_OK;
2877 tx_ring->last_tx_tso = 1;
2878 tx_flags |= E1000_TX_FLAGS_TSO;
2879 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
2880 tx_flags |= E1000_TX_FLAGS_CSUM;
2882 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2883 * 82571 hardware supports TSO capabilities for IPv6 as well...
2884 * no longer assume, we must. */
2885 if (likely(skb->protocol == htons(ETH_P_IP)))
2886 tx_flags |= E1000_TX_FLAGS_IPV4;
2888 e1000_tx_queue(adapter, tx_ring, tx_flags,
2889 e1000_tx_map(adapter, tx_ring, skb, first,
2890 max_per_txd, nr_frags, mss));
2892 netdev->trans_start = jiffies;
2894 /* Make sure there is space in the ring for the next send. */
2895 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
2896 netif_stop_queue(netdev);
2898 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2899 return NETDEV_TX_OK;
2903 * e1000_tx_timeout - Respond to a Tx Hang
2904 * @netdev: network interface device structure
2908 e1000_tx_timeout(struct net_device *netdev)
2910 struct e1000_adapter *adapter = netdev_priv(netdev);
2912 /* Do the reset outside of interrupt context */
2913 adapter->tx_timeout_count++;
2914 schedule_work(&adapter->reset_task);
2918 e1000_reset_task(struct net_device *netdev)
2920 struct e1000_adapter *adapter = netdev_priv(netdev);
2922 e1000_down(adapter);
2927 * e1000_get_stats - Get System Network Statistics
2928 * @netdev: network interface device structure
2930 * Returns the address of the device statistics structure.
2931 * The statistics are actually updated from the timer callback.
2934 static struct net_device_stats *
2935 e1000_get_stats(struct net_device *netdev)
2937 struct e1000_adapter *adapter = netdev_priv(netdev);
2939 /* only return the current stats */
2940 return &adapter->net_stats;
2944 * e1000_change_mtu - Change the Maximum Transfer Unit
2945 * @netdev: network interface device structure
2946 * @new_mtu: new value for maximum frame size
2948 * Returns 0 on success, negative on failure
2952 e1000_change_mtu(struct net_device *netdev, int new_mtu)
2954 struct e1000_adapter *adapter = netdev_priv(netdev);
2955 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2956 uint16_t eeprom_data = 0;
2958 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2959 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2960 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2964 /* Adapter-specific max frame size limits. */
2965 switch (adapter->hw.mac_type) {
2966 case e1000_undefined ... e1000_82542_rev2_1:
2967 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2968 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
2973 /* only enable jumbo frames if ASPM is disabled completely
2974 * this means both bits must be zero in 0x1A bits 3:2 */
2975 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
2977 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
2978 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2980 "Jumbo Frames not supported.\n");
2985 /* fall through to get support */
2988 case e1000_80003es2lan:
2989 #define MAX_STD_JUMBO_FRAME_SIZE 9234
2990 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
2991 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
2996 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3000 /* NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3001 * means we reserve 2 more, this pushes us to allocate from the next
3003 * i.e. RXBUFFER_2048 --> size-4096 slab */
3005 if (max_frame <= E1000_RXBUFFER_256)
3006 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3007 else if (max_frame <= E1000_RXBUFFER_512)
3008 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3009 else if (max_frame <= E1000_RXBUFFER_1024)
3010 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3011 else if (max_frame <= E1000_RXBUFFER_2048)
3012 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3013 else if (max_frame <= E1000_RXBUFFER_4096)
3014 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3015 else if (max_frame <= E1000_RXBUFFER_8192)
3016 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3017 else if (max_frame <= E1000_RXBUFFER_16384)
3018 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3020 /* adjust allocation if LPE protects us, and we aren't using SBP */
3021 #define MAXIMUM_ETHERNET_VLAN_SIZE 1522
3022 if (!adapter->hw.tbi_compatibility_on &&
3023 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3024 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3025 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3027 netdev->mtu = new_mtu;
3029 if (netif_running(netdev)) {
3030 e1000_down(adapter);
3034 adapter->hw.max_frame_size = max_frame;
3040 * e1000_update_stats - Update the board statistics counters
3041 * @adapter: board private structure
3045 e1000_update_stats(struct e1000_adapter *adapter)
3047 struct e1000_hw *hw = &adapter->hw;
3048 struct pci_dev *pdev = adapter->pdev;
3049 unsigned long flags;
3052 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3055 * Prevent stats update while adapter is being reset, or if the pci
3056 * connection is down.
3058 if (adapter->link_speed == 0)
3060 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3063 spin_lock_irqsave(&adapter->stats_lock, flags);
3065 /* these counters are modified from e1000_adjust_tbi_stats,
3066 * called from the interrupt context, so they must only
3067 * be written while holding adapter->stats_lock
3070 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3071 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3072 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3073 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3074 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3075 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3076 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3077 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3078 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3079 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3080 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3081 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3082 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3084 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3085 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3086 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3087 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3088 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3089 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3090 adapter->stats.dc += E1000_READ_REG(hw, DC);
3091 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3092 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3093 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3094 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3095 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3096 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3097 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3098 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3099 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3100 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3101 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3102 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3103 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3104 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3105 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3106 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3107 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3108 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3109 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3110 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3111 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3112 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3113 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3114 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3115 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3116 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3117 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3119 /* used for adaptive IFS */
3121 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3122 adapter->stats.tpt += hw->tx_packet_delta;
3123 hw->collision_delta = E1000_READ_REG(hw, COLC);
3124 adapter->stats.colc += hw->collision_delta;
3126 if (hw->mac_type >= e1000_82543) {
3127 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3128 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3129 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3130 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3131 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3132 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3134 if (hw->mac_type > e1000_82547_rev_2) {
3135 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3136 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3137 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3138 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3139 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3140 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3141 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3142 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3143 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3146 /* Fill out the OS statistics structure */
3148 adapter->net_stats.rx_packets = adapter->stats.gprc;
3149 adapter->net_stats.tx_packets = adapter->stats.gptc;
3150 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3151 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3152 adapter->net_stats.multicast = adapter->stats.mprc;
3153 adapter->net_stats.collisions = adapter->stats.colc;
3157 /* RLEC on some newer hardware can be incorrect so build
3158 * our own version based on RUC and ROC */
3159 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3160 adapter->stats.crcerrs + adapter->stats.algnerrc +
3161 adapter->stats.ruc + adapter->stats.roc +
3162 adapter->stats.cexterr;
3163 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3165 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3166 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3167 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3171 adapter->net_stats.tx_errors = adapter->stats.ecol +
3172 adapter->stats.latecol;
3173 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3174 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3175 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3177 /* Tx Dropped needs to be maintained elsewhere */
3181 if (hw->media_type == e1000_media_type_copper) {
3182 if ((adapter->link_speed == SPEED_1000) &&
3183 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3184 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3185 adapter->phy_stats.idle_errors += phy_tmp;
3188 if ((hw->mac_type <= e1000_82546) &&
3189 (hw->phy_type == e1000_phy_m88) &&
3190 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3191 adapter->phy_stats.receive_errors += phy_tmp;
3194 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3198 * e1000_intr - Interrupt Handler
3199 * @irq: interrupt number
3200 * @data: pointer to a network interface device structure
3201 * @pt_regs: CPU registers structure
3205 e1000_intr(int irq, void *data, struct pt_regs *regs)
3207 struct net_device *netdev = data;
3208 struct e1000_adapter *adapter = netdev_priv(netdev);
3209 struct e1000_hw *hw = &adapter->hw;
3210 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
3211 #ifndef CONFIG_E1000_NAPI
3214 /* Interrupt Auto-Mask...upon reading ICR,
3215 * interrupts are masked. No need for the
3216 * IMC write, but it does mean we should
3217 * account for it ASAP. */
3218 if (likely(hw->mac_type >= e1000_82571))
3219 atomic_inc(&adapter->irq_sem);
3222 if (unlikely(!icr)) {
3223 #ifdef CONFIG_E1000_NAPI
3224 if (hw->mac_type >= e1000_82571)
3225 e1000_irq_enable(adapter);
3227 return IRQ_NONE; /* Not our interrupt */
3230 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3231 hw->get_link_status = 1;
3232 /* 80003ES2LAN workaround--
3233 * For packet buffer work-around on link down event;
3234 * disable receives here in the ISR and
3235 * reset adapter in watchdog
3237 if (netif_carrier_ok(netdev) &&
3238 (adapter->hw.mac_type == e1000_80003es2lan)) {
3239 /* disable receives */
3240 rctl = E1000_READ_REG(hw, RCTL);
3241 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3243 mod_timer(&adapter->watchdog_timer, jiffies);
3246 #ifdef CONFIG_E1000_NAPI
3247 if (unlikely(hw->mac_type < e1000_82571)) {
3248 atomic_inc(&adapter->irq_sem);
3249 E1000_WRITE_REG(hw, IMC, ~0);
3250 E1000_WRITE_FLUSH(hw);
3252 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3253 __netif_rx_schedule(&adapter->polling_netdev[0]);
3255 e1000_irq_enable(adapter);
3257 /* Writing IMC and IMS is needed for 82547.
3258 * Due to Hub Link bus being occupied, an interrupt
3259 * de-assertion message is not able to be sent.
3260 * When an interrupt assertion message is generated later,
3261 * two messages are re-ordered and sent out.
3262 * That causes APIC to think 82547 is in de-assertion
3263 * state, while 82547 is in assertion state, resulting
3264 * in dead lock. Writing IMC forces 82547 into
3265 * de-assertion state.
3267 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
3268 atomic_inc(&adapter->irq_sem);
3269 E1000_WRITE_REG(hw, IMC, ~0);
3272 for (i = 0; i < E1000_MAX_INTR; i++)
3273 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3274 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3277 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3278 e1000_irq_enable(adapter);
3285 #ifdef CONFIG_E1000_NAPI
3287 * e1000_clean - NAPI Rx polling callback
3288 * @adapter: board private structure
3292 e1000_clean(struct net_device *poll_dev, int *budget)
3294 struct e1000_adapter *adapter;
3295 int work_to_do = min(*budget, poll_dev->quota);
3296 int tx_cleaned = 0, i = 0, work_done = 0;
3298 /* Must NOT use netdev_priv macro here. */
3299 adapter = poll_dev->priv;
3301 /* Keep link state information with original netdev */
3302 if (!netif_carrier_ok(adapter->netdev))
3305 while (poll_dev != &adapter->polling_netdev[i]) {
3307 BUG_ON(i == adapter->num_rx_queues);
3310 if (likely(adapter->num_tx_queues == 1)) {
3311 /* e1000_clean is called per-cpu. This lock protects
3312 * tx_ring[0] from being cleaned by multiple cpus
3313 * simultaneously. A failure obtaining the lock means
3314 * tx_ring[0] is currently being cleaned anyway. */
3315 if (spin_trylock(&adapter->tx_queue_lock)) {
3316 tx_cleaned = e1000_clean_tx_irq(adapter,
3317 &adapter->tx_ring[0]);
3318 spin_unlock(&adapter->tx_queue_lock);
3321 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3323 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3324 &work_done, work_to_do);
3326 *budget -= work_done;
3327 poll_dev->quota -= work_done;
3329 /* If no Tx and not enough Rx work done, exit the polling mode */
3330 if ((!tx_cleaned && (work_done == 0)) ||
3331 !netif_running(adapter->netdev)) {
3333 netif_rx_complete(poll_dev);
3334 e1000_irq_enable(adapter);
3343 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3344 * @adapter: board private structure
3348 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3349 struct e1000_tx_ring *tx_ring)
3351 struct net_device *netdev = adapter->netdev;
3352 struct e1000_tx_desc *tx_desc, *eop_desc;
3353 struct e1000_buffer *buffer_info;
3354 unsigned int i, eop;
3355 #ifdef CONFIG_E1000_NAPI
3356 unsigned int count = 0;
3358 boolean_t cleaned = FALSE;
3360 i = tx_ring->next_to_clean;
3361 eop = tx_ring->buffer_info[i].next_to_watch;
3362 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3364 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3365 for (cleaned = FALSE; !cleaned; ) {
3366 tx_desc = E1000_TX_DESC(*tx_ring, i);
3367 buffer_info = &tx_ring->buffer_info[i];
3368 cleaned = (i == eop);
3370 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3371 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
3373 if (unlikely(++i == tx_ring->count)) i = 0;
3377 eop = tx_ring->buffer_info[i].next_to_watch;
3378 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3379 #ifdef CONFIG_E1000_NAPI
3380 #define E1000_TX_WEIGHT 64
3381 /* weight of a sort for tx, to avoid endless transmit cleanup */
3382 if (count++ == E1000_TX_WEIGHT) break;
3386 tx_ring->next_to_clean = i;
3388 #define TX_WAKE_THRESHOLD 32
3389 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
3390 netif_carrier_ok(netdev))) {
3391 spin_lock(&tx_ring->tx_lock);
3392 if (netif_queue_stopped(netdev) &&
3393 (E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))
3394 netif_wake_queue(netdev);
3395 spin_unlock(&tx_ring->tx_lock);
3398 if (adapter->detect_tx_hung) {
3399 /* Detect a transmit hang in hardware, this serializes the
3400 * check with the clearing of time_stamp and movement of i */
3401 adapter->detect_tx_hung = FALSE;
3402 if (tx_ring->buffer_info[eop].dma &&
3403 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3404 (adapter->tx_timeout_factor * HZ))
3405 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3406 E1000_STATUS_TXOFF)) {
3408 /* detected Tx unit hang */
3409 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3413 " next_to_use <%x>\n"
3414 " next_to_clean <%x>\n"
3415 "buffer_info[next_to_clean]\n"
3416 " time_stamp <%lx>\n"
3417 " next_to_watch <%x>\n"
3419 " next_to_watch.status <%x>\n",
3420 (unsigned long)((tx_ring - adapter->tx_ring) /
3421 sizeof(struct e1000_tx_ring)),
3422 readl(adapter->hw.hw_addr + tx_ring->tdh),
3423 readl(adapter->hw.hw_addr + tx_ring->tdt),
3424 tx_ring->next_to_use,
3425 tx_ring->next_to_clean,
3426 tx_ring->buffer_info[eop].time_stamp,
3429 eop_desc->upper.fields.status);
3430 netif_stop_queue(netdev);
3437 * e1000_rx_checksum - Receive Checksum Offload for 82543
3438 * @adapter: board private structure
3439 * @status_err: receive descriptor status and error fields
3440 * @csum: receive descriptor csum field
3441 * @sk_buff: socket buffer with received data
3445 e1000_rx_checksum(struct e1000_adapter *adapter,
3446 uint32_t status_err, uint32_t csum,
3447 struct sk_buff *skb)
3449 uint16_t status = (uint16_t)status_err;
3450 uint8_t errors = (uint8_t)(status_err >> 24);
3451 skb->ip_summed = CHECKSUM_NONE;
3453 /* 82543 or newer only */
3454 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
3455 /* Ignore Checksum bit is set */
3456 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3457 /* TCP/UDP checksum error bit is set */
3458 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3459 /* let the stack verify checksum errors */
3460 adapter->hw_csum_err++;
3463 /* TCP/UDP Checksum has not been calculated */
3464 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3465 if (!(status & E1000_RXD_STAT_TCPCS))
3468 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3471 /* It must be a TCP or UDP packet with a valid checksum */
3472 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3473 /* TCP checksum is good */
3474 skb->ip_summed = CHECKSUM_UNNECESSARY;
3475 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3476 /* IP fragment with UDP payload */
3477 /* Hardware complements the payload checksum, so we undo it
3478 * and then put the value in host order for further stack use.
3480 csum = ntohl(csum ^ 0xFFFF);
3482 skb->ip_summed = CHECKSUM_HW;
3484 adapter->hw_csum_good++;
3488 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3489 * @adapter: board private structure
3493 #ifdef CONFIG_E1000_NAPI
3494 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3495 struct e1000_rx_ring *rx_ring,
3496 int *work_done, int work_to_do)
3498 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3499 struct e1000_rx_ring *rx_ring)
3502 struct net_device *netdev = adapter->netdev;
3503 struct pci_dev *pdev = adapter->pdev;
3504 struct e1000_rx_desc *rx_desc, *next_rxd;
3505 struct e1000_buffer *buffer_info, *next_buffer;
3506 unsigned long flags;
3510 int cleaned_count = 0;
3511 boolean_t cleaned = FALSE;
3513 i = rx_ring->next_to_clean;
3514 rx_desc = E1000_RX_DESC(*rx_ring, i);
3515 buffer_info = &rx_ring->buffer_info[i];
3517 while (rx_desc->status & E1000_RXD_STAT_DD) {
3518 struct sk_buff *skb;
3520 #ifdef CONFIG_E1000_NAPI
3521 if (*work_done >= work_to_do)
3525 status = rx_desc->status;
3526 skb = buffer_info->skb;
3527 buffer_info->skb = NULL;
3529 prefetch(skb->data - NET_IP_ALIGN);
3531 if (++i == rx_ring->count) i = 0;
3532 next_rxd = E1000_RX_DESC(*rx_ring, i);
3535 next_buffer = &rx_ring->buffer_info[i];
3539 pci_unmap_single(pdev,
3541 buffer_info->length,
3542 PCI_DMA_FROMDEVICE);
3544 length = le16_to_cpu(rx_desc->length);
3546 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3547 /* All receives must fit into a single buffer */
3548 E1000_DBG("%s: Receive packet consumed multiple"
3549 " buffers\n", netdev->name);
3550 dev_kfree_skb_irq(skb);
3554 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3555 last_byte = *(skb->data + length - 1);
3556 if (TBI_ACCEPT(&adapter->hw, status,
3557 rx_desc->errors, length, last_byte)) {
3558 spin_lock_irqsave(&adapter->stats_lock, flags);
3559 e1000_tbi_adjust_stats(&adapter->hw,
3562 spin_unlock_irqrestore(&adapter->stats_lock,
3567 buffer_info->skb = skb;
3572 /* code added for copybreak, this should improve
3573 * performance for small packets with large amounts
3574 * of reassembly being done in the stack */
3575 #define E1000_CB_LENGTH 256
3576 if (length < E1000_CB_LENGTH) {
3577 struct sk_buff *new_skb =
3578 dev_alloc_skb(length + NET_IP_ALIGN);
3580 skb_reserve(new_skb, NET_IP_ALIGN);
3581 new_skb->dev = netdev;
3582 memcpy(new_skb->data - NET_IP_ALIGN,
3583 skb->data - NET_IP_ALIGN,
3584 length + NET_IP_ALIGN);
3585 /* save the skb in buffer_info as good */
3586 buffer_info->skb = skb;
3588 skb_put(skb, length);
3591 skb_put(skb, length);
3593 /* end copybreak code */
3595 /* Receive Checksum Offload */
3596 e1000_rx_checksum(adapter,
3597 (uint32_t)(status) |
3598 ((uint32_t)(rx_desc->errors) << 24),
3599 le16_to_cpu(rx_desc->csum), skb);
3601 skb->protocol = eth_type_trans(skb, netdev);
3602 #ifdef CONFIG_E1000_NAPI
3603 if (unlikely(adapter->vlgrp &&
3604 (status & E1000_RXD_STAT_VP))) {
3605 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3606 le16_to_cpu(rx_desc->special) &
3607 E1000_RXD_SPC_VLAN_MASK);
3609 netif_receive_skb(skb);
3611 #else /* CONFIG_E1000_NAPI */
3612 if (unlikely(adapter->vlgrp &&
3613 (status & E1000_RXD_STAT_VP))) {
3614 vlan_hwaccel_rx(skb, adapter->vlgrp,
3615 le16_to_cpu(rx_desc->special) &
3616 E1000_RXD_SPC_VLAN_MASK);
3620 #endif /* CONFIG_E1000_NAPI */
3621 netdev->last_rx = jiffies;
3624 rx_desc->status = 0;
3626 /* return some buffers to hardware, one at a time is too slow */
3627 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3628 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3632 /* use prefetched values */
3634 buffer_info = next_buffer;
3636 rx_ring->next_to_clean = i;
3638 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3640 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3646 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3647 * @adapter: board private structure
3651 #ifdef CONFIG_E1000_NAPI
3652 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3653 struct e1000_rx_ring *rx_ring,
3654 int *work_done, int work_to_do)
3656 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3657 struct e1000_rx_ring *rx_ring)
3660 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
3661 struct net_device *netdev = adapter->netdev;
3662 struct pci_dev *pdev = adapter->pdev;
3663 struct e1000_buffer *buffer_info, *next_buffer;
3664 struct e1000_ps_page *ps_page;
3665 struct e1000_ps_page_dma *ps_page_dma;
3666 struct sk_buff *skb;
3668 uint32_t length, staterr;
3669 int cleaned_count = 0;
3670 boolean_t cleaned = FALSE;
3672 i = rx_ring->next_to_clean;
3673 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3674 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3675 buffer_info = &rx_ring->buffer_info[i];
3677 while (staterr & E1000_RXD_STAT_DD) {
3678 buffer_info = &rx_ring->buffer_info[i];
3679 ps_page = &rx_ring->ps_page[i];
3680 ps_page_dma = &rx_ring->ps_page_dma[i];
3681 #ifdef CONFIG_E1000_NAPI
3682 if (unlikely(*work_done >= work_to_do))
3686 skb = buffer_info->skb;
3688 /* in the packet split case this is header only */
3689 prefetch(skb->data - NET_IP_ALIGN);
3691 if (++i == rx_ring->count) i = 0;
3692 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
3695 next_buffer = &rx_ring->buffer_info[i];
3699 pci_unmap_single(pdev, buffer_info->dma,
3700 buffer_info->length,
3701 PCI_DMA_FROMDEVICE);
3703 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3704 E1000_DBG("%s: Packet Split buffers didn't pick up"
3705 " the full packet\n", netdev->name);
3706 dev_kfree_skb_irq(skb);
3710 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3711 dev_kfree_skb_irq(skb);
3715 length = le16_to_cpu(rx_desc->wb.middle.length0);
3717 if (unlikely(!length)) {
3718 E1000_DBG("%s: Last part of the packet spanning"
3719 " multiple descriptors\n", netdev->name);
3720 dev_kfree_skb_irq(skb);
3725 skb_put(skb, length);
3728 /* this looks ugly, but it seems compiler issues make it
3729 more efficient than reusing j */
3730 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3732 /* page alloc/put takes too long and effects small packet
3733 * throughput, so unsplit small packets and save the alloc/put*/
3734 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
3736 /* there is no documentation about how to call
3737 * kmap_atomic, so we can't hold the mapping
3739 pci_dma_sync_single_for_cpu(pdev,
3740 ps_page_dma->ps_page_dma[0],
3742 PCI_DMA_FROMDEVICE);
3743 vaddr = kmap_atomic(ps_page->ps_page[0],
3744 KM_SKB_DATA_SOFTIRQ);
3745 memcpy(skb->tail, vaddr, l1);
3746 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
3747 pci_dma_sync_single_for_device(pdev,
3748 ps_page_dma->ps_page_dma[0],
3749 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3756 for (j = 0; j < adapter->rx_ps_pages; j++) {
3757 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
3759 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3760 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3761 ps_page_dma->ps_page_dma[j] = 0;
3762 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
3764 ps_page->ps_page[j] = NULL;
3766 skb->data_len += length;
3767 skb->truesize += length;
3771 e1000_rx_checksum(adapter, staterr,
3772 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
3773 skb->protocol = eth_type_trans(skb, netdev);
3775 if (likely(rx_desc->wb.upper.header_status &
3776 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
3777 adapter->rx_hdr_split++;
3778 #ifdef CONFIG_E1000_NAPI
3779 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3780 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3781 le16_to_cpu(rx_desc->wb.middle.vlan) &
3782 E1000_RXD_SPC_VLAN_MASK);
3784 netif_receive_skb(skb);
3786 #else /* CONFIG_E1000_NAPI */
3787 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3788 vlan_hwaccel_rx(skb, adapter->vlgrp,
3789 le16_to_cpu(rx_desc->wb.middle.vlan) &
3790 E1000_RXD_SPC_VLAN_MASK);
3794 #endif /* CONFIG_E1000_NAPI */
3795 netdev->last_rx = jiffies;
3798 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
3799 buffer_info->skb = NULL;
3801 /* return some buffers to hardware, one at a time is too slow */
3802 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3803 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3807 /* use prefetched values */
3809 buffer_info = next_buffer;
3811 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3813 rx_ring->next_to_clean = i;
3815 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3817 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3823 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3824 * @adapter: address of board private structure
3828 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3829 struct e1000_rx_ring *rx_ring,
3832 struct net_device *netdev = adapter->netdev;
3833 struct pci_dev *pdev = adapter->pdev;
3834 struct e1000_rx_desc *rx_desc;
3835 struct e1000_buffer *buffer_info;
3836 struct sk_buff *skb;
3838 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3840 i = rx_ring->next_to_use;
3841 buffer_info = &rx_ring->buffer_info[i];
3843 while (cleaned_count--) {
3844 if (!(skb = buffer_info->skb))
3845 skb = dev_alloc_skb(bufsz);
3851 if (unlikely(!skb)) {
3852 /* Better luck next round */
3853 adapter->alloc_rx_buff_failed++;
3857 /* Fix for errata 23, can't cross 64kB boundary */
3858 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3859 struct sk_buff *oldskb = skb;
3860 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3861 "at %p\n", bufsz, skb->data);
3862 /* Try again, without freeing the previous */
3863 skb = dev_alloc_skb(bufsz);
3864 /* Failed allocation, critical failure */
3866 dev_kfree_skb(oldskb);
3870 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3873 dev_kfree_skb(oldskb);
3874 break; /* while !buffer_info->skb */
3876 /* Use new allocation */
3877 dev_kfree_skb(oldskb);
3880 /* Make buffer alignment 2 beyond a 16 byte boundary
3881 * this will result in a 16 byte aligned IP header after
3882 * the 14 byte MAC header is removed
3884 skb_reserve(skb, NET_IP_ALIGN);
3888 buffer_info->skb = skb;
3889 buffer_info->length = adapter->rx_buffer_len;
3891 buffer_info->dma = pci_map_single(pdev,
3893 adapter->rx_buffer_len,
3894 PCI_DMA_FROMDEVICE);
3896 /* Fix for errata 23, can't cross 64kB boundary */
3897 if (!e1000_check_64k_bound(adapter,
3898 (void *)(unsigned long)buffer_info->dma,
3899 adapter->rx_buffer_len)) {
3900 DPRINTK(RX_ERR, ERR,
3901 "dma align check failed: %u bytes at %p\n",
3902 adapter->rx_buffer_len,
3903 (void *)(unsigned long)buffer_info->dma);
3905 buffer_info->skb = NULL;
3907 pci_unmap_single(pdev, buffer_info->dma,
3908 adapter->rx_buffer_len,
3909 PCI_DMA_FROMDEVICE);
3911 break; /* while !buffer_info->skb */
3913 rx_desc = E1000_RX_DESC(*rx_ring, i);
3914 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3916 if (unlikely(++i == rx_ring->count))
3918 buffer_info = &rx_ring->buffer_info[i];
3921 if (likely(rx_ring->next_to_use != i)) {
3922 rx_ring->next_to_use = i;
3923 if (unlikely(i-- == 0))
3924 i = (rx_ring->count - 1);
3926 /* Force memory writes to complete before letting h/w
3927 * know there are new descriptors to fetch. (Only
3928 * applicable for weak-ordered memory model archs,
3929 * such as IA-64). */
3931 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3936 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3937 * @adapter: address of board private structure
3941 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3942 struct e1000_rx_ring *rx_ring,
3945 struct net_device *netdev = adapter->netdev;
3946 struct pci_dev *pdev = adapter->pdev;
3947 union e1000_rx_desc_packet_split *rx_desc;
3948 struct e1000_buffer *buffer_info;
3949 struct e1000_ps_page *ps_page;
3950 struct e1000_ps_page_dma *ps_page_dma;
3951 struct sk_buff *skb;
3954 i = rx_ring->next_to_use;
3955 buffer_info = &rx_ring->buffer_info[i];
3956 ps_page = &rx_ring->ps_page[i];
3957 ps_page_dma = &rx_ring->ps_page_dma[i];
3959 while (cleaned_count--) {
3960 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3962 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
3963 if (j < adapter->rx_ps_pages) {
3964 if (likely(!ps_page->ps_page[j])) {
3965 ps_page->ps_page[j] =
3966 alloc_page(GFP_ATOMIC);
3967 if (unlikely(!ps_page->ps_page[j])) {
3968 adapter->alloc_rx_buff_failed++;
3971 ps_page_dma->ps_page_dma[j] =
3973 ps_page->ps_page[j],
3975 PCI_DMA_FROMDEVICE);
3977 /* Refresh the desc even if buffer_addrs didn't
3978 * change because each write-back erases
3981 rx_desc->read.buffer_addr[j+1] =
3982 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3984 rx_desc->read.buffer_addr[j+1] = ~0;
3987 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3989 if (unlikely(!skb)) {
3990 adapter->alloc_rx_buff_failed++;
3994 /* Make buffer alignment 2 beyond a 16 byte boundary
3995 * this will result in a 16 byte aligned IP header after
3996 * the 14 byte MAC header is removed
3998 skb_reserve(skb, NET_IP_ALIGN);
4002 buffer_info->skb = skb;
4003 buffer_info->length = adapter->rx_ps_bsize0;
4004 buffer_info->dma = pci_map_single(pdev, skb->data,
4005 adapter->rx_ps_bsize0,
4006 PCI_DMA_FROMDEVICE);
4008 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4010 if (unlikely(++i == rx_ring->count)) i = 0;
4011 buffer_info = &rx_ring->buffer_info[i];
4012 ps_page = &rx_ring->ps_page[i];
4013 ps_page_dma = &rx_ring->ps_page_dma[i];
4017 if (likely(rx_ring->next_to_use != i)) {
4018 rx_ring->next_to_use = i;
4019 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4021 /* Force memory writes to complete before letting h/w
4022 * know there are new descriptors to fetch. (Only
4023 * applicable for weak-ordered memory model archs,
4024 * such as IA-64). */
4026 /* Hardware increments by 16 bytes, but packet split
4027 * descriptors are 32 bytes...so we increment tail
4030 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4035 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4040 e1000_smartspeed(struct e1000_adapter *adapter)
4042 uint16_t phy_status;
4045 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4046 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4049 if (adapter->smartspeed == 0) {
4050 /* If Master/Slave config fault is asserted twice,
4051 * we assume back-to-back */
4052 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4053 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4054 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4055 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4056 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4057 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4058 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4059 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4061 adapter->smartspeed++;
4062 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4063 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4065 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4066 MII_CR_RESTART_AUTO_NEG);
4067 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4072 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4073 /* If still no link, perhaps using 2/3 pair cable */
4074 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4075 phy_ctrl |= CR_1000T_MS_ENABLE;
4076 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4077 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4078 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4079 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4080 MII_CR_RESTART_AUTO_NEG);
4081 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4084 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4085 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4086 adapter->smartspeed = 0;
4097 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4103 return e1000_mii_ioctl(netdev, ifr, cmd);
4117 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4119 struct e1000_adapter *adapter = netdev_priv(netdev);
4120 struct mii_ioctl_data *data = if_mii(ifr);
4124 unsigned long flags;
4126 if (adapter->hw.media_type != e1000_media_type_copper)
4131 data->phy_id = adapter->hw.phy_addr;
4134 if (!capable(CAP_NET_ADMIN))
4136 spin_lock_irqsave(&adapter->stats_lock, flags);
4137 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4139 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4142 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4145 if (!capable(CAP_NET_ADMIN))
4147 if (data->reg_num & ~(0x1F))
4149 mii_reg = data->val_in;
4150 spin_lock_irqsave(&adapter->stats_lock, flags);
4151 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
4153 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4156 if (adapter->hw.media_type == e1000_media_type_copper) {
4157 switch (data->reg_num) {
4159 if (mii_reg & MII_CR_POWER_DOWN)
4161 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4162 adapter->hw.autoneg = 1;
4163 adapter->hw.autoneg_advertised = 0x2F;
4166 spddplx = SPEED_1000;
4167 else if (mii_reg & 0x2000)
4168 spddplx = SPEED_100;
4171 spddplx += (mii_reg & 0x100)
4174 retval = e1000_set_spd_dplx(adapter,
4177 spin_unlock_irqrestore(
4178 &adapter->stats_lock,
4183 if (netif_running(adapter->netdev)) {
4184 e1000_down(adapter);
4187 e1000_reset(adapter);
4189 case M88E1000_PHY_SPEC_CTRL:
4190 case M88E1000_EXT_PHY_SPEC_CTRL:
4191 if (e1000_phy_reset(&adapter->hw)) {
4192 spin_unlock_irqrestore(
4193 &adapter->stats_lock, flags);
4199 switch (data->reg_num) {
4201 if (mii_reg & MII_CR_POWER_DOWN)
4203 if (netif_running(adapter->netdev)) {
4204 e1000_down(adapter);
4207 e1000_reset(adapter);
4211 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4216 return E1000_SUCCESS;
4220 e1000_pci_set_mwi(struct e1000_hw *hw)
4222 struct e1000_adapter *adapter = hw->back;
4223 int ret_val = pci_set_mwi(adapter->pdev);
4226 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4230 e1000_pci_clear_mwi(struct e1000_hw *hw)
4232 struct e1000_adapter *adapter = hw->back;
4234 pci_clear_mwi(adapter->pdev);
4238 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4240 struct e1000_adapter *adapter = hw->back;
4242 pci_read_config_word(adapter->pdev, reg, value);
4246 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4248 struct e1000_adapter *adapter = hw->back;
4250 pci_write_config_word(adapter->pdev, reg, *value);
4254 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4260 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4266 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4268 struct e1000_adapter *adapter = netdev_priv(netdev);
4269 uint32_t ctrl, rctl;
4271 e1000_irq_disable(adapter);
4272 adapter->vlgrp = grp;
4275 /* enable VLAN tag insert/strip */
4276 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4277 ctrl |= E1000_CTRL_VME;
4278 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4280 /* enable VLAN receive filtering */
4281 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4282 rctl |= E1000_RCTL_VFE;
4283 rctl &= ~E1000_RCTL_CFIEN;
4284 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4285 e1000_update_mng_vlan(adapter);
4287 /* disable VLAN tag insert/strip */
4288 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4289 ctrl &= ~E1000_CTRL_VME;
4290 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4292 /* disable VLAN filtering */
4293 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4294 rctl &= ~E1000_RCTL_VFE;
4295 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4296 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4297 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4298 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4302 e1000_irq_enable(adapter);
4306 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4308 struct e1000_adapter *adapter = netdev_priv(netdev);
4309 uint32_t vfta, index;
4311 if ((adapter->hw.mng_cookie.status &
4312 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4313 (vid == adapter->mng_vlan_id))
4315 /* add VID to filter table */
4316 index = (vid >> 5) & 0x7F;
4317 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4318 vfta |= (1 << (vid & 0x1F));
4319 e1000_write_vfta(&adapter->hw, index, vfta);
4323 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4325 struct e1000_adapter *adapter = netdev_priv(netdev);
4326 uint32_t vfta, index;
4328 e1000_irq_disable(adapter);
4331 adapter->vlgrp->vlan_devices[vid] = NULL;
4333 e1000_irq_enable(adapter);
4335 if ((adapter->hw.mng_cookie.status &
4336 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4337 (vid == adapter->mng_vlan_id)) {
4338 /* release control to f/w */
4339 e1000_release_hw_control(adapter);
4343 /* remove VID from filter table */
4344 index = (vid >> 5) & 0x7F;
4345 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4346 vfta &= ~(1 << (vid & 0x1F));
4347 e1000_write_vfta(&adapter->hw, index, vfta);
4351 e1000_restore_vlan(struct e1000_adapter *adapter)
4353 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4355 if (adapter->vlgrp) {
4357 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4358 if (!adapter->vlgrp->vlan_devices[vid])
4360 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4366 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4368 adapter->hw.autoneg = 0;
4370 /* Fiber NICs only allow 1000 gbps Full duplex */
4371 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
4372 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4373 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4378 case SPEED_10 + DUPLEX_HALF:
4379 adapter->hw.forced_speed_duplex = e1000_10_half;
4381 case SPEED_10 + DUPLEX_FULL:
4382 adapter->hw.forced_speed_duplex = e1000_10_full;
4384 case SPEED_100 + DUPLEX_HALF:
4385 adapter->hw.forced_speed_duplex = e1000_100_half;
4387 case SPEED_100 + DUPLEX_FULL:
4388 adapter->hw.forced_speed_duplex = e1000_100_full;
4390 case SPEED_1000 + DUPLEX_FULL:
4391 adapter->hw.autoneg = 1;
4392 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4394 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4396 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4403 /* Save/restore 16 or 64 dwords of PCI config space depending on which
4404 * bus we're on (PCI(X) vs. PCI-E)
4406 #define PCIE_CONFIG_SPACE_LEN 256
4407 #define PCI_CONFIG_SPACE_LEN 64
4409 e1000_pci_save_state(struct e1000_adapter *adapter)
4411 struct pci_dev *dev = adapter->pdev;
4415 if (adapter->hw.mac_type >= e1000_82571)
4416 size = PCIE_CONFIG_SPACE_LEN;
4418 size = PCI_CONFIG_SPACE_LEN;
4420 WARN_ON(adapter->config_space != NULL);
4422 adapter->config_space = kmalloc(size, GFP_KERNEL);
4423 if (!adapter->config_space) {
4424 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4427 for (i = 0; i < (size / 4); i++)
4428 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4433 e1000_pci_restore_state(struct e1000_adapter *adapter)
4435 struct pci_dev *dev = adapter->pdev;
4439 if (adapter->config_space == NULL)
4442 if (adapter->hw.mac_type >= e1000_82571)
4443 size = PCIE_CONFIG_SPACE_LEN;
4445 size = PCI_CONFIG_SPACE_LEN;
4446 for (i = 0; i < (size / 4); i++)
4447 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4448 kfree(adapter->config_space);
4449 adapter->config_space = NULL;
4452 #endif /* CONFIG_PM */
4455 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4457 struct net_device *netdev = pci_get_drvdata(pdev);
4458 struct e1000_adapter *adapter = netdev_priv(netdev);
4459 uint32_t ctrl, ctrl_ext, rctl, manc, status;
4460 uint32_t wufc = adapter->wol;
4463 netif_device_detach(netdev);
4465 if (netif_running(netdev))
4466 e1000_down(adapter);
4469 /* Implement our own version of pci_save_state(pdev) because pci-
4470 * express adapters have 256-byte config spaces. */
4471 retval = e1000_pci_save_state(adapter);
4476 status = E1000_READ_REG(&adapter->hw, STATUS);
4477 if (status & E1000_STATUS_LU)
4478 wufc &= ~E1000_WUFC_LNKC;
4481 e1000_setup_rctl(adapter);
4482 e1000_set_multi(netdev);
4484 /* turn on all-multi mode if wake on multicast is enabled */
4485 if (adapter->wol & E1000_WUFC_MC) {
4486 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4487 rctl |= E1000_RCTL_MPE;
4488 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4491 if (adapter->hw.mac_type >= e1000_82540) {
4492 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4493 /* advertise wake from D3Cold */
4494 #define E1000_CTRL_ADVD3WUC 0x00100000
4495 /* phy power management enable */
4496 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4497 ctrl |= E1000_CTRL_ADVD3WUC |
4498 E1000_CTRL_EN_PHY_PWR_MGMT;
4499 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4502 if (adapter->hw.media_type == e1000_media_type_fiber ||
4503 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4504 /* keep the laser running in D3 */
4505 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4506 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4507 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4510 /* Allow time for pending master requests to run */
4511 e1000_disable_pciex_master(&adapter->hw);
4513 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4514 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4515 pci_enable_wake(pdev, PCI_D3hot, 1);
4516 pci_enable_wake(pdev, PCI_D3cold, 1);
4518 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4519 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4520 pci_enable_wake(pdev, PCI_D3hot, 0);
4521 pci_enable_wake(pdev, PCI_D3cold, 0);
4524 if (adapter->hw.mac_type >= e1000_82540 &&
4525 adapter->hw.media_type == e1000_media_type_copper) {
4526 manc = E1000_READ_REG(&adapter->hw, MANC);
4527 if (manc & E1000_MANC_SMBUS_EN) {
4528 manc |= E1000_MANC_ARP_EN;
4529 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4530 pci_enable_wake(pdev, PCI_D3hot, 1);
4531 pci_enable_wake(pdev, PCI_D3cold, 1);
4535 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4536 * would have already happened in close and is redundant. */
4537 e1000_release_hw_control(adapter);
4539 pci_disable_device(pdev);
4541 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4548 e1000_resume(struct pci_dev *pdev)
4550 struct net_device *netdev = pci_get_drvdata(pdev);
4551 struct e1000_adapter *adapter = netdev_priv(netdev);
4552 uint32_t manc, ret_val;
4554 pci_set_power_state(pdev, PCI_D0);
4555 e1000_pci_restore_state(adapter);
4556 ret_val = pci_enable_device(pdev);
4557 pci_set_master(pdev);
4559 pci_enable_wake(pdev, PCI_D3hot, 0);
4560 pci_enable_wake(pdev, PCI_D3cold, 0);
4562 e1000_reset(adapter);
4563 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4565 if (netif_running(netdev))
4568 netif_device_attach(netdev);
4570 if (adapter->hw.mac_type >= e1000_82540 &&
4571 adapter->hw.media_type == e1000_media_type_copper) {
4572 manc = E1000_READ_REG(&adapter->hw, MANC);
4573 manc &= ~(E1000_MANC_ARP_EN);
4574 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4577 /* If the controller is 82573 and f/w is AMT, do not set
4578 * DRV_LOAD until the interface is up. For all other cases,
4579 * let the f/w know that the h/w is now under the control
4581 if (adapter->hw.mac_type != e1000_82573 ||
4582 !e1000_check_mng_mode(&adapter->hw))
4583 e1000_get_hw_control(adapter);
4589 static void e1000_shutdown(struct pci_dev *pdev)
4591 e1000_suspend(pdev, PMSG_SUSPEND);
4594 #ifdef CONFIG_NET_POLL_CONTROLLER
4596 * Polling 'interrupt' - used by things like netconsole to send skbs
4597 * without having to re-enable interrupts. It's not called while
4598 * the interrupt routine is executing.
4601 e1000_netpoll(struct net_device *netdev)
4603 struct e1000_adapter *adapter = netdev_priv(netdev);
4604 disable_irq(adapter->pdev->irq);
4605 e1000_intr(adapter->pdev->irq, netdev, NULL);
4606 e1000_clean_tx_irq(adapter, adapter->tx_ring);
4607 #ifndef CONFIG_E1000_NAPI
4608 adapter->clean_rx(adapter, adapter->rx_ring);
4610 enable_irq(adapter->pdev->irq);
4615 * e1000_io_error_detected - called when PCI error is detected
4616 * @pdev: Pointer to PCI device
4617 * @state: The current pci conneection state
4619 * This function is called after a PCI bus error affecting
4620 * this device has been detected.
4622 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4624 struct net_device *netdev = pci_get_drvdata(pdev);
4625 struct e1000_adapter *adapter = netdev->priv;
4627 netif_device_detach(netdev);
4629 if (netif_running(netdev))
4630 e1000_down(adapter);
4632 /* Request a slot slot reset. */
4633 return PCI_ERS_RESULT_NEED_RESET;
4637 * e1000_io_slot_reset - called after the pci bus has been reset.
4638 * @pdev: Pointer to PCI device
4640 * Restart the card from scratch, as if from a cold-boot. Implementation
4641 * resembles the first-half of the e1000_resume routine.
4643 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4645 struct net_device *netdev = pci_get_drvdata(pdev);
4646 struct e1000_adapter *adapter = netdev->priv;
4648 if (pci_enable_device(pdev)) {
4649 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4650 return PCI_ERS_RESULT_DISCONNECT;
4652 pci_set_master(pdev);
4654 pci_enable_wake(pdev, 3, 0);
4655 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
4657 /* Perform card reset only on one instance of the card */
4658 if (PCI_FUNC (pdev->devfn) != 0)
4659 return PCI_ERS_RESULT_RECOVERED;
4661 e1000_reset(adapter);
4662 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4664 return PCI_ERS_RESULT_RECOVERED;
4668 * e1000_io_resume - called when traffic can start flowing again.
4669 * @pdev: Pointer to PCI device
4671 * This callback is called when the error recovery driver tells us that
4672 * its OK to resume normal operation. Implementation resembles the
4673 * second-half of the e1000_resume routine.
4675 static void e1000_io_resume(struct pci_dev *pdev)
4677 struct net_device *netdev = pci_get_drvdata(pdev);
4678 struct e1000_adapter *adapter = netdev->priv;
4679 uint32_t manc, swsm;
4681 if (netif_running(netdev)) {
4682 if (e1000_up(adapter)) {
4683 printk("e1000: can't bring device back up after reset\n");
4688 netif_device_attach(netdev);
4690 if (adapter->hw.mac_type >= e1000_82540 &&
4691 adapter->hw.media_type == e1000_media_type_copper) {
4692 manc = E1000_READ_REG(&adapter->hw, MANC);
4693 manc &= ~(E1000_MANC_ARP_EN);
4694 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4697 switch (adapter->hw.mac_type) {
4699 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4700 E1000_WRITE_REG(&adapter->hw, SWSM,
4701 swsm | E1000_SWSM_DRV_LOAD);
4707 if (netif_running(netdev))
4708 mod_timer(&adapter->watchdog_timer, jiffies);