1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
33 * o incorporate fix for recycled skbs from IBM LTC
35 * o Honor eeprom setting for enabling/disabling Wake On Lan
37 * o Fix memory leak in rx ring handling for PCI Express adapters
39 * o Patch from Jesper Juhl to remove redundant NULL checks for kfree
41 * o Render logic that sets/resets DRV_LOAD as inline functions to
42 * avoid code replication. If f/w is AMT then set DRV_LOAD only when
43 * network interface is open.
44 * o Handle DRV_LOAD set/reset in cases where AMT uses VLANs.
45 * o Adjust PBA partioning for Jumbo frames using MTU size and not
48 * o Use adapter->tx_timeout_factor in Tx Hung Detect logic
50 * o Support for 8086:10B5 device (Quad Port)
52 * o In AMT enabled configurations, set/reset DRV_LOAD bit on interface
55 * o Invoke e1000_check_mng_mode only for 8257x controllers since it
56 * accesses the FWSM that is not supported in other controllers
58 * o Add support for device id E1000_DEV_ID_82546GB_QUAD_COPPER
59 * o set RCTL:SECRC only for controllers newer than 82543.
60 * o When the n/w interface comes down reset DRV_LOAD bit to notify f/w.
61 * This code was moved from e1000_remove to e1000_close
63 * o Fix error in updating RDT in el1000_alloc_rx_buffers[_ps] -- one off.
64 * o Enable fc by default on 82573 controllers (do not read eeprom)
65 * o Fix rx_errors statistic not to include missed_packet_count
66 * o Fix rx_dropped statistic not to include missed_packet_count
69 * o Remove call to update statistics from the controller ib e1000_get_stats
71 * o Improved algorithm for rx buffer allocation/rdt update
72 * o Flow control watermarks relative to rx PBA size
73 * o Simplified 'Tx Hung' detect logic
75 * o Report rx buffer allocation failures and tx timeout counts in stats
77 * o Implement workaround for controller erratum -- linear non-tso packet
78 * following a TSO gets written back prematurely
80 * o Set netdev->tx_queue_len based on link speed/duplex settings.
81 * o Fix net_stats.rx_fifo_errors <p@draigBrady.com>
82 * o Do not power off PHY if SoL/IDER session is active
84 * o Fix loopback test setup/cleanup for 82571/3 controllers
85 * o Fix parsing of outgoing packets (e1000_transfer_dhcp_info) to treat
87 * o Prevent operations that will cause the PHY to be reset if SoL/IDER
88 * sessions are active and log a message
90 * o used fixed size descriptors for all MTU sizes, reduces memory load
92 * o Performance tweaks, including copybreak and prefetch
94 * o Fixed ethtool diagnostics
95 * o Enabled flow control to take default eeprom settings
96 * o Added stats_lock around e1000_read_phy_reg commands to avoid concurrent
97 * calls, one from mii_ioctl and other from within update_stats while
98 * processing MIIREG ioctl.
101 char e1000_driver_name[] = "e1000";
102 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
103 #ifndef CONFIG_E1000_NAPI
106 #define DRIVERNAPI "-NAPI"
108 #define DRV_VERSION "6.3.9-k2"DRIVERNAPI
109 char e1000_driver_version[] = DRV_VERSION;
110 static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
112 /* e1000_pci_tbl - PCI Device ID Table
114 * Last entry must be all 0s
116 * Macro expands to...
117 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
119 static struct pci_device_id e1000_pci_tbl[] = {
120 INTEL_E1000_ETHERNET_DEVICE(0x1000),
121 INTEL_E1000_ETHERNET_DEVICE(0x1001),
122 INTEL_E1000_ETHERNET_DEVICE(0x1004),
123 INTEL_E1000_ETHERNET_DEVICE(0x1008),
124 INTEL_E1000_ETHERNET_DEVICE(0x1009),
125 INTEL_E1000_ETHERNET_DEVICE(0x100C),
126 INTEL_E1000_ETHERNET_DEVICE(0x100D),
127 INTEL_E1000_ETHERNET_DEVICE(0x100E),
128 INTEL_E1000_ETHERNET_DEVICE(0x100F),
129 INTEL_E1000_ETHERNET_DEVICE(0x1010),
130 INTEL_E1000_ETHERNET_DEVICE(0x1011),
131 INTEL_E1000_ETHERNET_DEVICE(0x1012),
132 INTEL_E1000_ETHERNET_DEVICE(0x1013),
133 INTEL_E1000_ETHERNET_DEVICE(0x1014),
134 INTEL_E1000_ETHERNET_DEVICE(0x1015),
135 INTEL_E1000_ETHERNET_DEVICE(0x1016),
136 INTEL_E1000_ETHERNET_DEVICE(0x1017),
137 INTEL_E1000_ETHERNET_DEVICE(0x1018),
138 INTEL_E1000_ETHERNET_DEVICE(0x1019),
139 INTEL_E1000_ETHERNET_DEVICE(0x101A),
140 INTEL_E1000_ETHERNET_DEVICE(0x101D),
141 INTEL_E1000_ETHERNET_DEVICE(0x101E),
142 INTEL_E1000_ETHERNET_DEVICE(0x1026),
143 INTEL_E1000_ETHERNET_DEVICE(0x1027),
144 INTEL_E1000_ETHERNET_DEVICE(0x1028),
145 INTEL_E1000_ETHERNET_DEVICE(0x105E),
146 INTEL_E1000_ETHERNET_DEVICE(0x105F),
147 INTEL_E1000_ETHERNET_DEVICE(0x1060),
148 INTEL_E1000_ETHERNET_DEVICE(0x1075),
149 INTEL_E1000_ETHERNET_DEVICE(0x1076),
150 INTEL_E1000_ETHERNET_DEVICE(0x1077),
151 INTEL_E1000_ETHERNET_DEVICE(0x1078),
152 INTEL_E1000_ETHERNET_DEVICE(0x1079),
153 INTEL_E1000_ETHERNET_DEVICE(0x107A),
154 INTEL_E1000_ETHERNET_DEVICE(0x107B),
155 INTEL_E1000_ETHERNET_DEVICE(0x107C),
156 INTEL_E1000_ETHERNET_DEVICE(0x107D),
157 INTEL_E1000_ETHERNET_DEVICE(0x107E),
158 INTEL_E1000_ETHERNET_DEVICE(0x107F),
159 INTEL_E1000_ETHERNET_DEVICE(0x108A),
160 INTEL_E1000_ETHERNET_DEVICE(0x108B),
161 INTEL_E1000_ETHERNET_DEVICE(0x108C),
162 INTEL_E1000_ETHERNET_DEVICE(0x1099),
163 INTEL_E1000_ETHERNET_DEVICE(0x109A),
164 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
165 /* required last entry */
169 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
171 int e1000_up(struct e1000_adapter *adapter);
172 void e1000_down(struct e1000_adapter *adapter);
173 void e1000_reset(struct e1000_adapter *adapter);
174 int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
175 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
176 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
177 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
178 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
179 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
180 struct e1000_tx_ring *txdr);
181 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
182 struct e1000_rx_ring *rxdr);
183 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
184 struct e1000_tx_ring *tx_ring);
185 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
186 struct e1000_rx_ring *rx_ring);
187 void e1000_update_stats(struct e1000_adapter *adapter);
189 /* Local Function Prototypes */
191 static int e1000_init_module(void);
192 static void e1000_exit_module(void);
193 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
194 static void __devexit e1000_remove(struct pci_dev *pdev);
195 static int e1000_alloc_queues(struct e1000_adapter *adapter);
196 #ifdef CONFIG_E1000_MQ
197 static void e1000_setup_queue_mapping(struct e1000_adapter *adapter);
199 static int e1000_sw_init(struct e1000_adapter *adapter);
200 static int e1000_open(struct net_device *netdev);
201 static int e1000_close(struct net_device *netdev);
202 static void e1000_configure_tx(struct e1000_adapter *adapter);
203 static void e1000_configure_rx(struct e1000_adapter *adapter);
204 static void e1000_setup_rctl(struct e1000_adapter *adapter);
205 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
206 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
207 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
208 struct e1000_tx_ring *tx_ring);
209 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
210 struct e1000_rx_ring *rx_ring);
211 static void e1000_set_multi(struct net_device *netdev);
212 static void e1000_update_phy_info(unsigned long data);
213 static void e1000_watchdog(unsigned long data);
214 static void e1000_watchdog_task(struct e1000_adapter *adapter);
215 static void e1000_82547_tx_fifo_stall(unsigned long data);
216 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
217 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
218 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
219 static int e1000_set_mac(struct net_device *netdev, void *p);
220 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
221 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
222 struct e1000_tx_ring *tx_ring);
223 #ifdef CONFIG_E1000_NAPI
224 static int e1000_clean(struct net_device *poll_dev, int *budget);
225 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
226 struct e1000_rx_ring *rx_ring,
227 int *work_done, int work_to_do);
228 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
229 struct e1000_rx_ring *rx_ring,
230 int *work_done, int work_to_do);
232 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
233 struct e1000_rx_ring *rx_ring);
234 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
235 struct e1000_rx_ring *rx_ring);
237 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
238 struct e1000_rx_ring *rx_ring,
240 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
241 struct e1000_rx_ring *rx_ring,
243 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
244 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
246 void e1000_set_ethtool_ops(struct net_device *netdev);
247 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
248 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
249 static void e1000_tx_timeout(struct net_device *dev);
250 static void e1000_tx_timeout_task(struct net_device *dev);
251 static void e1000_smartspeed(struct e1000_adapter *adapter);
252 static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
253 struct sk_buff *skb);
255 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
256 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
257 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
258 static void e1000_restore_vlan(struct e1000_adapter *adapter);
261 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
262 static int e1000_resume(struct pci_dev *pdev);
265 #ifdef CONFIG_NET_POLL_CONTROLLER
266 /* for netdump / net console */
267 static void e1000_netpoll (struct net_device *netdev);
270 #ifdef CONFIG_E1000_MQ
271 /* for multiple Rx queues */
272 void e1000_rx_schedule(void *data);
275 /* Exported from other modules */
277 extern void e1000_check_options(struct e1000_adapter *adapter);
279 static struct pci_driver e1000_driver = {
280 .name = e1000_driver_name,
281 .id_table = e1000_pci_tbl,
282 .probe = e1000_probe,
283 .remove = __devexit_p(e1000_remove),
284 /* Power Managment Hooks */
286 .suspend = e1000_suspend,
287 .resume = e1000_resume
291 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
292 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
293 MODULE_LICENSE("GPL");
294 MODULE_VERSION(DRV_VERSION);
296 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
297 module_param(debug, int, 0);
298 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
301 * e1000_init_module - Driver Registration Routine
303 * e1000_init_module is the first routine called when the driver is
304 * loaded. All it does is register with the PCI subsystem.
308 e1000_init_module(void)
311 printk(KERN_INFO "%s - version %s\n",
312 e1000_driver_string, e1000_driver_version);
314 printk(KERN_INFO "%s\n", e1000_copyright);
316 ret = pci_module_init(&e1000_driver);
321 module_init(e1000_init_module);
324 * e1000_exit_module - Driver Exit Cleanup Routine
326 * e1000_exit_module is called just before the driver is removed
331 e1000_exit_module(void)
333 pci_unregister_driver(&e1000_driver);
336 module_exit(e1000_exit_module);
339 * e1000_irq_disable - Mask off interrupt generation on the NIC
340 * @adapter: board private structure
344 e1000_irq_disable(struct e1000_adapter *adapter)
346 atomic_inc(&adapter->irq_sem);
347 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
348 E1000_WRITE_FLUSH(&adapter->hw);
349 synchronize_irq(adapter->pdev->irq);
353 * e1000_irq_enable - Enable default interrupt generation settings
354 * @adapter: board private structure
358 e1000_irq_enable(struct e1000_adapter *adapter)
360 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
361 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
362 E1000_WRITE_FLUSH(&adapter->hw);
367 e1000_update_mng_vlan(struct e1000_adapter *adapter)
369 struct net_device *netdev = adapter->netdev;
370 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
371 uint16_t old_vid = adapter->mng_vlan_id;
372 if (adapter->vlgrp) {
373 if (!adapter->vlgrp->vlan_devices[vid]) {
374 if (adapter->hw.mng_cookie.status &
375 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
376 e1000_vlan_rx_add_vid(netdev, vid);
377 adapter->mng_vlan_id = vid;
379 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
381 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
383 !adapter->vlgrp->vlan_devices[old_vid])
384 e1000_vlan_rx_kill_vid(netdev, old_vid);
390 * e1000_release_hw_control - release control of the h/w to f/w
391 * @adapter: address of board private structure
393 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
394 * For ASF and Pass Through versions of f/w this means that the
395 * driver is no longer loaded. For AMT version (only with 82573) i
396 * of the f/w this means that the netowrk i/f is closed.
401 e1000_release_hw_control(struct e1000_adapter *adapter)
406 /* Let firmware taken over control of h/w */
407 switch (adapter->hw.mac_type) {
410 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
411 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
412 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
415 swsm = E1000_READ_REG(&adapter->hw, SWSM);
416 E1000_WRITE_REG(&adapter->hw, SWSM,
417 swsm & ~E1000_SWSM_DRV_LOAD);
424 * e1000_get_hw_control - get control of the h/w from f/w
425 * @adapter: address of board private structure
427 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
428 * For ASF and Pass Through versions of f/w this means that
429 * the driver is loaded. For AMT version (only with 82573)
430 * of the f/w this means that the netowrk i/f is open.
435 e1000_get_hw_control(struct e1000_adapter *adapter)
439 /* Let firmware know the driver has taken over */
440 switch (adapter->hw.mac_type) {
443 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
444 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
445 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
448 swsm = E1000_READ_REG(&adapter->hw, SWSM);
449 E1000_WRITE_REG(&adapter->hw, SWSM,
450 swsm | E1000_SWSM_DRV_LOAD);
458 e1000_up(struct e1000_adapter *adapter)
460 struct net_device *netdev = adapter->netdev;
463 /* hardware has been reset, we need to reload some things */
465 /* Reset the PHY if it was previously powered down */
466 if (adapter->hw.media_type == e1000_media_type_copper) {
468 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
469 if (mii_reg & MII_CR_POWER_DOWN)
470 e1000_phy_reset(&adapter->hw);
473 e1000_set_multi(netdev);
475 e1000_restore_vlan(adapter);
477 e1000_configure_tx(adapter);
478 e1000_setup_rctl(adapter);
479 e1000_configure_rx(adapter);
480 /* call E1000_DESC_UNUSED which always leaves
481 * at least 1 descriptor unused to make sure
482 * next_to_use != next_to_clean */
483 for (i = 0; i < adapter->num_rx_queues; i++) {
484 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
485 adapter->alloc_rx_buf(adapter, ring,
486 E1000_DESC_UNUSED(ring));
489 #ifdef CONFIG_PCI_MSI
490 if (adapter->hw.mac_type > e1000_82547_rev_2) {
491 adapter->have_msi = TRUE;
492 if ((err = pci_enable_msi(adapter->pdev))) {
494 "Unable to allocate MSI interrupt Error: %d\n", err);
495 adapter->have_msi = FALSE;
499 if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
500 SA_SHIRQ | SA_SAMPLE_RANDOM,
501 netdev->name, netdev))) {
503 "Unable to allocate interrupt Error: %d\n", err);
507 #ifdef CONFIG_E1000_MQ
508 e1000_setup_queue_mapping(adapter);
511 adapter->tx_queue_len = netdev->tx_queue_len;
513 mod_timer(&adapter->watchdog_timer, jiffies);
515 #ifdef CONFIG_E1000_NAPI
516 netif_poll_enable(netdev);
518 e1000_irq_enable(adapter);
524 e1000_down(struct e1000_adapter *adapter)
526 struct net_device *netdev = adapter->netdev;
527 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
528 e1000_check_mng_mode(&adapter->hw);
530 e1000_irq_disable(adapter);
531 #ifdef CONFIG_E1000_MQ
532 while (atomic_read(&adapter->rx_sched_call_data.count) != 0);
534 free_irq(adapter->pdev->irq, netdev);
535 #ifdef CONFIG_PCI_MSI
536 if (adapter->hw.mac_type > e1000_82547_rev_2 &&
537 adapter->have_msi == TRUE)
538 pci_disable_msi(adapter->pdev);
540 del_timer_sync(&adapter->tx_fifo_stall_timer);
541 del_timer_sync(&adapter->watchdog_timer);
542 del_timer_sync(&adapter->phy_info_timer);
544 #ifdef CONFIG_E1000_NAPI
545 netif_poll_disable(netdev);
547 netdev->tx_queue_len = adapter->tx_queue_len;
548 adapter->link_speed = 0;
549 adapter->link_duplex = 0;
550 netif_carrier_off(netdev);
551 netif_stop_queue(netdev);
553 e1000_reset(adapter);
554 e1000_clean_all_tx_rings(adapter);
555 e1000_clean_all_rx_rings(adapter);
557 /* Power down the PHY so no link is implied when interface is down *
558 * The PHY cannot be powered down if any of the following is TRUE *
561 * (c) SoL/IDER session is active */
562 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
563 adapter->hw.media_type == e1000_media_type_copper &&
564 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
566 !e1000_check_phy_reset_block(&adapter->hw)) {
568 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
569 mii_reg |= MII_CR_POWER_DOWN;
570 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
576 e1000_reset(struct e1000_adapter *adapter)
579 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
581 /* Repartition Pba for greater than 9k mtu
582 * To take effect CTRL.RST is required.
585 switch (adapter->hw.mac_type) {
587 case e1000_82547_rev_2:
602 if ((adapter->hw.mac_type != e1000_82573) &&
603 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
604 pba -= 8; /* allocate more FIFO for Tx */
607 if (adapter->hw.mac_type == e1000_82547) {
608 adapter->tx_fifo_head = 0;
609 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
610 adapter->tx_fifo_size =
611 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
612 atomic_set(&adapter->tx_fifo_stall, 0);
615 E1000_WRITE_REG(&adapter->hw, PBA, pba);
617 /* flow control settings */
618 /* Set the FC high water mark to 90% of the FIFO size.
619 * Required to clear last 3 LSB */
620 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
622 adapter->hw.fc_high_water = fc_high_water_mark;
623 adapter->hw.fc_low_water = fc_high_water_mark - 8;
624 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
625 adapter->hw.fc_send_xon = 1;
626 adapter->hw.fc = adapter->hw.original_fc;
628 /* Allow time for pending master requests to run */
629 e1000_reset_hw(&adapter->hw);
630 if (adapter->hw.mac_type >= e1000_82544)
631 E1000_WRITE_REG(&adapter->hw, WUC, 0);
632 if (e1000_init_hw(&adapter->hw))
633 DPRINTK(PROBE, ERR, "Hardware Error\n");
634 e1000_update_mng_vlan(adapter);
635 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
636 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
638 e1000_reset_adaptive(&adapter->hw);
639 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
640 if (adapter->en_mng_pt) {
641 manc = E1000_READ_REG(&adapter->hw, MANC);
642 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
643 E1000_WRITE_REG(&adapter->hw, MANC, manc);
648 * e1000_probe - Device Initialization Routine
649 * @pdev: PCI device information struct
650 * @ent: entry in e1000_pci_tbl
652 * Returns 0 on success, negative on failure
654 * e1000_probe initializes an adapter identified by a pci_dev structure.
655 * The OS initialization, configuring of the adapter private structure,
656 * and a hardware reset occur.
660 e1000_probe(struct pci_dev *pdev,
661 const struct pci_device_id *ent)
663 struct net_device *netdev;
664 struct e1000_adapter *adapter;
665 unsigned long mmio_start, mmio_len;
667 static int cards_found = 0;
668 int i, err, pci_using_dac;
669 uint16_t eeprom_data;
670 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
671 if ((err = pci_enable_device(pdev)))
674 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
677 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
678 E1000_ERR("No usable DMA configuration, aborting\n");
684 if ((err = pci_request_regions(pdev, e1000_driver_name)))
687 pci_set_master(pdev);
689 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
692 goto err_alloc_etherdev;
695 SET_MODULE_OWNER(netdev);
696 SET_NETDEV_DEV(netdev, &pdev->dev);
698 pci_set_drvdata(pdev, netdev);
699 adapter = netdev_priv(netdev);
700 adapter->netdev = netdev;
701 adapter->pdev = pdev;
702 adapter->hw.back = adapter;
703 adapter->msg_enable = (1 << debug) - 1;
705 mmio_start = pci_resource_start(pdev, BAR_0);
706 mmio_len = pci_resource_len(pdev, BAR_0);
708 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
709 if (!adapter->hw.hw_addr) {
714 for (i = BAR_1; i <= BAR_5; i++) {
715 if (pci_resource_len(pdev, i) == 0)
717 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
718 adapter->hw.io_base = pci_resource_start(pdev, i);
723 netdev->open = &e1000_open;
724 netdev->stop = &e1000_close;
725 netdev->hard_start_xmit = &e1000_xmit_frame;
726 netdev->get_stats = &e1000_get_stats;
727 netdev->set_multicast_list = &e1000_set_multi;
728 netdev->set_mac_address = &e1000_set_mac;
729 netdev->change_mtu = &e1000_change_mtu;
730 netdev->do_ioctl = &e1000_ioctl;
731 e1000_set_ethtool_ops(netdev);
732 netdev->tx_timeout = &e1000_tx_timeout;
733 netdev->watchdog_timeo = 5 * HZ;
734 #ifdef CONFIG_E1000_NAPI
735 netdev->poll = &e1000_clean;
738 netdev->vlan_rx_register = e1000_vlan_rx_register;
739 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
740 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
741 #ifdef CONFIG_NET_POLL_CONTROLLER
742 netdev->poll_controller = e1000_netpoll;
744 strcpy(netdev->name, pci_name(pdev));
746 netdev->mem_start = mmio_start;
747 netdev->mem_end = mmio_start + mmio_len;
748 netdev->base_addr = adapter->hw.io_base;
750 adapter->bd_number = cards_found;
752 /* setup the private structure */
754 if ((err = e1000_sw_init(adapter)))
757 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
758 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
760 if (adapter->hw.mac_type >= e1000_82543) {
761 netdev->features = NETIF_F_SG |
765 NETIF_F_HW_VLAN_FILTER;
769 if ((adapter->hw.mac_type >= e1000_82544) &&
770 (adapter->hw.mac_type != e1000_82547))
771 netdev->features |= NETIF_F_TSO;
773 #ifdef NETIF_F_TSO_IPV6
774 if (adapter->hw.mac_type > e1000_82547_rev_2)
775 netdev->features |= NETIF_F_TSO_IPV6;
779 netdev->features |= NETIF_F_HIGHDMA;
781 /* hard_start_xmit is safe against parallel locking */
782 netdev->features |= NETIF_F_LLTX;
784 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
786 /* before reading the EEPROM, reset the controller to
787 * put the device in a known good starting state */
789 e1000_reset_hw(&adapter->hw);
791 /* make sure the EEPROM is good */
793 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
794 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
799 /* copy the MAC address out of the EEPROM */
801 if (e1000_read_mac_addr(&adapter->hw))
802 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
803 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
804 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
806 if (!is_valid_ether_addr(netdev->perm_addr)) {
807 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
812 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
814 e1000_get_bus_info(&adapter->hw);
816 init_timer(&adapter->tx_fifo_stall_timer);
817 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
818 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
820 init_timer(&adapter->watchdog_timer);
821 adapter->watchdog_timer.function = &e1000_watchdog;
822 adapter->watchdog_timer.data = (unsigned long) adapter;
824 INIT_WORK(&adapter->watchdog_task,
825 (void (*)(void *))e1000_watchdog_task, adapter);
827 init_timer(&adapter->phy_info_timer);
828 adapter->phy_info_timer.function = &e1000_update_phy_info;
829 adapter->phy_info_timer.data = (unsigned long) adapter;
831 INIT_WORK(&adapter->tx_timeout_task,
832 (void (*)(void *))e1000_tx_timeout_task, netdev);
834 /* we're going to reset, so assume we have no link for now */
836 netif_carrier_off(netdev);
837 netif_stop_queue(netdev);
839 e1000_check_options(adapter);
841 /* Initial Wake on LAN setting
842 * If APM wake is enabled in the EEPROM,
843 * enable the ACPI Magic Packet filter
846 switch (adapter->hw.mac_type) {
847 case e1000_82542_rev2_0:
848 case e1000_82542_rev2_1:
852 e1000_read_eeprom(&adapter->hw,
853 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
854 eeprom_apme_mask = E1000_EEPROM_82544_APM;
857 case e1000_82546_rev_3:
859 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
860 e1000_read_eeprom(&adapter->hw,
861 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
866 e1000_read_eeprom(&adapter->hw,
867 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
870 if (eeprom_data & eeprom_apme_mask)
871 adapter->wol |= E1000_WUFC_MAG;
873 /* print bus type/speed/width info */
875 struct e1000_hw *hw = &adapter->hw;
876 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
877 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
878 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
879 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
880 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
881 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
882 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
883 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
884 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
885 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
886 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
890 for (i = 0; i < 6; i++)
891 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
893 /* reset the hardware with the new settings */
894 e1000_reset(adapter);
896 /* If the controller is 82573 and f/w is AMT, do not set
897 * DRV_LOAD until the interface is up. For all other cases,
898 * let the f/w know that the h/w is now under the control
900 if (adapter->hw.mac_type != e1000_82573 ||
901 !e1000_check_mng_mode(&adapter->hw))
902 e1000_get_hw_control(adapter);
904 strcpy(netdev->name, "eth%d");
905 if ((err = register_netdev(netdev)))
908 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
916 iounmap(adapter->hw.hw_addr);
920 pci_release_regions(pdev);
925 * e1000_remove - Device Removal Routine
926 * @pdev: PCI device information struct
928 * e1000_remove is called by the PCI subsystem to alert the driver
929 * that it should release a PCI device. The could be caused by a
930 * Hot-Plug event, or because the driver is going to be removed from
934 static void __devexit
935 e1000_remove(struct pci_dev *pdev)
937 struct net_device *netdev = pci_get_drvdata(pdev);
938 struct e1000_adapter *adapter = netdev_priv(netdev);
940 #ifdef CONFIG_E1000_NAPI
944 flush_scheduled_work();
946 if (adapter->hw.mac_type >= e1000_82540 &&
947 adapter->hw.media_type == e1000_media_type_copper) {
948 manc = E1000_READ_REG(&adapter->hw, MANC);
949 if (manc & E1000_MANC_SMBUS_EN) {
950 manc |= E1000_MANC_ARP_EN;
951 E1000_WRITE_REG(&adapter->hw, MANC, manc);
955 /* Release control of h/w to f/w. If f/w is AMT enabled, this
956 * would have already happened in close and is redundant. */
957 e1000_release_hw_control(adapter);
959 unregister_netdev(netdev);
960 #ifdef CONFIG_E1000_NAPI
961 for (i = 0; i < adapter->num_rx_queues; i++)
962 __dev_put(&adapter->polling_netdev[i]);
965 if (!e1000_check_phy_reset_block(&adapter->hw))
966 e1000_phy_hw_reset(&adapter->hw);
968 kfree(adapter->tx_ring);
969 kfree(adapter->rx_ring);
970 #ifdef CONFIG_E1000_NAPI
971 kfree(adapter->polling_netdev);
974 iounmap(adapter->hw.hw_addr);
975 pci_release_regions(pdev);
977 #ifdef CONFIG_E1000_MQ
978 free_percpu(adapter->cpu_netdev);
979 free_percpu(adapter->cpu_tx_ring);
983 pci_disable_device(pdev);
987 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
988 * @adapter: board private structure to initialize
990 * e1000_sw_init initializes the Adapter private data structure.
991 * Fields are initialized based on PCI device information and
992 * OS network device settings (MTU size).
996 e1000_sw_init(struct e1000_adapter *adapter)
998 struct e1000_hw *hw = &adapter->hw;
999 struct net_device *netdev = adapter->netdev;
1000 struct pci_dev *pdev = adapter->pdev;
1001 #ifdef CONFIG_E1000_NAPI
1005 /* PCI config space info */
1007 hw->vendor_id = pdev->vendor;
1008 hw->device_id = pdev->device;
1009 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1010 hw->subsystem_id = pdev->subsystem_device;
1012 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1014 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1016 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
1017 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
1018 hw->max_frame_size = netdev->mtu +
1019 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1020 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1022 /* identify the MAC */
1024 if (e1000_set_mac_type(hw)) {
1025 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1029 /* initialize eeprom parameters */
1031 if (e1000_init_eeprom_params(hw)) {
1032 E1000_ERR("EEPROM initialization failed\n");
1036 switch (hw->mac_type) {
1041 case e1000_82541_rev_2:
1042 case e1000_82547_rev_2:
1043 hw->phy_init_script = 1;
1047 e1000_set_media_type(hw);
1049 hw->wait_autoneg_complete = FALSE;
1050 hw->tbi_compatibility_en = TRUE;
1051 hw->adaptive_ifs = TRUE;
1053 /* Copper options */
1055 if (hw->media_type == e1000_media_type_copper) {
1056 hw->mdix = AUTO_ALL_MODES;
1057 hw->disable_polarity_correction = FALSE;
1058 hw->master_slave = E1000_MASTER_SLAVE;
1061 #ifdef CONFIG_E1000_MQ
1062 /* Number of supported queues */
1063 switch (hw->mac_type) {
1066 /* These controllers support 2 tx queues, but with a single
1067 * qdisc implementation, multiple tx queues aren't quite as
1068 * interesting. If we can find a logical way of mapping
1069 * flows to a queue, then perhaps we can up the num_tx_queue
1070 * count back to its default. Until then, we run the risk of
1071 * terrible performance due to SACK overload. */
1072 adapter->num_tx_queues = 1;
1073 adapter->num_rx_queues = 2;
1076 adapter->num_tx_queues = 1;
1077 adapter->num_rx_queues = 1;
1080 adapter->num_rx_queues = min(adapter->num_rx_queues, num_online_cpus());
1081 adapter->num_tx_queues = min(adapter->num_tx_queues, num_online_cpus());
1082 DPRINTK(DRV, INFO, "Multiqueue Enabled: Rx Queue count = %u %s\n",
1083 adapter->num_rx_queues,
1084 ((adapter->num_rx_queues == 1)
1085 ? ((num_online_cpus() > 1)
1086 ? "(due to unsupported feature in current adapter)"
1087 : "(due to unsupported system configuration)")
1089 DPRINTK(DRV, INFO, "Multiqueue Enabled: Tx Queue count = %u\n",
1090 adapter->num_tx_queues);
1092 adapter->num_tx_queues = 1;
1093 adapter->num_rx_queues = 1;
1096 if (e1000_alloc_queues(adapter)) {
1097 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1101 #ifdef CONFIG_E1000_NAPI
1102 for (i = 0; i < adapter->num_rx_queues; i++) {
1103 adapter->polling_netdev[i].priv = adapter;
1104 adapter->polling_netdev[i].poll = &e1000_clean;
1105 adapter->polling_netdev[i].weight = 64;
1106 dev_hold(&adapter->polling_netdev[i]);
1107 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1109 spin_lock_init(&adapter->tx_queue_lock);
1112 atomic_set(&adapter->irq_sem, 1);
1113 spin_lock_init(&adapter->stats_lock);
1119 * e1000_alloc_queues - Allocate memory for all rings
1120 * @adapter: board private structure to initialize
1122 * We allocate one ring per queue at run-time since we don't know the
1123 * number of queues at compile-time. The polling_netdev array is
1124 * intended for Multiqueue, but should work fine with a single queue.
1127 static int __devinit
1128 e1000_alloc_queues(struct e1000_adapter *adapter)
1132 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1133 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1134 if (!adapter->tx_ring)
1136 memset(adapter->tx_ring, 0, size);
1138 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1139 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1140 if (!adapter->rx_ring) {
1141 kfree(adapter->tx_ring);
1144 memset(adapter->rx_ring, 0, size);
1146 #ifdef CONFIG_E1000_NAPI
1147 size = sizeof(struct net_device) * adapter->num_rx_queues;
1148 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1149 if (!adapter->polling_netdev) {
1150 kfree(adapter->tx_ring);
1151 kfree(adapter->rx_ring);
1154 memset(adapter->polling_netdev, 0, size);
1157 #ifdef CONFIG_E1000_MQ
1158 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1159 adapter->rx_sched_call_data.info = adapter->netdev;
1161 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1162 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1165 return E1000_SUCCESS;
1168 #ifdef CONFIG_E1000_MQ
1169 static void __devinit
1170 e1000_setup_queue_mapping(struct e1000_adapter *adapter)
1174 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1175 adapter->rx_sched_call_data.info = adapter->netdev;
1176 cpus_clear(adapter->rx_sched_call_data.cpumask);
1178 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1179 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1183 for_each_online_cpu(cpu) {
1184 *per_cpu_ptr(adapter->cpu_tx_ring, cpu) = &adapter->tx_ring[i % adapter->num_tx_queues];
1185 /* This is incomplete because we'd like to assign separate
1186 * physical cpus to these netdev polling structures and
1187 * avoid saturating a subset of cpus.
1189 if (i < adapter->num_rx_queues) {
1190 *per_cpu_ptr(adapter->cpu_netdev, cpu) = &adapter->polling_netdev[i];
1191 adapter->rx_ring[i].cpu = cpu;
1192 cpu_set(cpu, adapter->cpumask);
1194 *per_cpu_ptr(adapter->cpu_netdev, cpu) = NULL;
1198 unlock_cpu_hotplug();
1203 * e1000_open - Called when a network interface is made active
1204 * @netdev: network interface device structure
1206 * Returns 0 on success, negative value on failure
1208 * The open entry point is called when a network interface is made
1209 * active by the system (IFF_UP). At this point all resources needed
1210 * for transmit and receive operations are allocated, the interrupt
1211 * handler is registered with the OS, the watchdog timer is started,
1212 * and the stack is notified that the interface is ready.
1216 e1000_open(struct net_device *netdev)
1218 struct e1000_adapter *adapter = netdev_priv(netdev);
1221 /* allocate transmit descriptors */
1223 if ((err = e1000_setup_all_tx_resources(adapter)))
1226 /* allocate receive descriptors */
1228 if ((err = e1000_setup_all_rx_resources(adapter)))
1231 if ((err = e1000_up(adapter)))
1233 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1234 if ((adapter->hw.mng_cookie.status &
1235 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1236 e1000_update_mng_vlan(adapter);
1239 /* If AMT is enabled, let the firmware know that the network
1240 * interface is now open */
1241 if (adapter->hw.mac_type == e1000_82573 &&
1242 e1000_check_mng_mode(&adapter->hw))
1243 e1000_get_hw_control(adapter);
1245 return E1000_SUCCESS;
1248 e1000_free_all_rx_resources(adapter);
1250 e1000_free_all_tx_resources(adapter);
1252 e1000_reset(adapter);
1258 * e1000_close - Disables a network interface
1259 * @netdev: network interface device structure
1261 * Returns 0, this is not allowed to fail
1263 * The close entry point is called when an interface is de-activated
1264 * by the OS. The hardware is still under the drivers control, but
1265 * needs to be disabled. A global MAC reset is issued to stop the
1266 * hardware, and all transmit and receive resources are freed.
1270 e1000_close(struct net_device *netdev)
1272 struct e1000_adapter *adapter = netdev_priv(netdev);
1274 e1000_down(adapter);
1276 e1000_free_all_tx_resources(adapter);
1277 e1000_free_all_rx_resources(adapter);
1279 if ((adapter->hw.mng_cookie.status &
1280 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1281 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1284 /* If AMT is enabled, let the firmware know that the network
1285 * interface is now closed */
1286 if (adapter->hw.mac_type == e1000_82573 &&
1287 e1000_check_mng_mode(&adapter->hw))
1288 e1000_release_hw_control(adapter);
1294 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1295 * @adapter: address of board private structure
1296 * @start: address of beginning of memory
1297 * @len: length of memory
1299 static inline boolean_t
1300 e1000_check_64k_bound(struct e1000_adapter *adapter,
1301 void *start, unsigned long len)
1303 unsigned long begin = (unsigned long) start;
1304 unsigned long end = begin + len;
1306 /* First rev 82545 and 82546 need to not allow any memory
1307 * write location to cross 64k boundary due to errata 23 */
1308 if (adapter->hw.mac_type == e1000_82545 ||
1309 adapter->hw.mac_type == e1000_82546) {
1310 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1317 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1318 * @adapter: board private structure
1319 * @txdr: tx descriptor ring (for a specific queue) to setup
1321 * Return 0 on success, negative on failure
1325 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1326 struct e1000_tx_ring *txdr)
1328 struct pci_dev *pdev = adapter->pdev;
1331 size = sizeof(struct e1000_buffer) * txdr->count;
1333 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1334 if (!txdr->buffer_info) {
1336 "Unable to allocate memory for the transmit descriptor ring\n");
1339 memset(txdr->buffer_info, 0, size);
1341 /* round up to nearest 4K */
1343 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1344 E1000_ROUNDUP(txdr->size, 4096);
1346 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1349 vfree(txdr->buffer_info);
1351 "Unable to allocate memory for the transmit descriptor ring\n");
1355 /* Fix for errata 23, can't cross 64kB boundary */
1356 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1357 void *olddesc = txdr->desc;
1358 dma_addr_t olddma = txdr->dma;
1359 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1360 "at %p\n", txdr->size, txdr->desc);
1361 /* Try again, without freeing the previous */
1362 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1363 /* Failed allocation, critical failure */
1365 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1366 goto setup_tx_desc_die;
1369 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1371 pci_free_consistent(pdev, txdr->size, txdr->desc,
1373 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1375 "Unable to allocate aligned memory "
1376 "for the transmit descriptor ring\n");
1377 vfree(txdr->buffer_info);
1380 /* Free old allocation, new allocation was successful */
1381 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1384 memset(txdr->desc, 0, txdr->size);
1386 txdr->next_to_use = 0;
1387 txdr->next_to_clean = 0;
1388 spin_lock_init(&txdr->tx_lock);
1394 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1395 * (Descriptors) for all queues
1396 * @adapter: board private structure
1398 * If this function returns with an error, then it's possible one or
1399 * more of the rings is populated (while the rest are not). It is the
1400 * callers duty to clean those orphaned rings.
1402 * Return 0 on success, negative on failure
1406 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1410 for (i = 0; i < adapter->num_tx_queues; i++) {
1411 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1414 "Allocation for Tx Queue %u failed\n", i);
1423 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1424 * @adapter: board private structure
1426 * Configure the Tx unit of the MAC after a reset.
1430 e1000_configure_tx(struct e1000_adapter *adapter)
1433 struct e1000_hw *hw = &adapter->hw;
1434 uint32_t tdlen, tctl, tipg, tarc;
1435 uint32_t ipgr1, ipgr2;
1437 /* Setup the HW Tx Head and Tail descriptor pointers */
1439 switch (adapter->num_tx_queues) {
1441 tdba = adapter->tx_ring[1].dma;
1442 tdlen = adapter->tx_ring[1].count *
1443 sizeof(struct e1000_tx_desc);
1444 E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
1445 E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
1446 E1000_WRITE_REG(hw, TDLEN1, tdlen);
1447 E1000_WRITE_REG(hw, TDH1, 0);
1448 E1000_WRITE_REG(hw, TDT1, 0);
1449 adapter->tx_ring[1].tdh = E1000_TDH1;
1450 adapter->tx_ring[1].tdt = E1000_TDT1;
1454 tdba = adapter->tx_ring[0].dma;
1455 tdlen = adapter->tx_ring[0].count *
1456 sizeof(struct e1000_tx_desc);
1457 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1458 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1459 E1000_WRITE_REG(hw, TDLEN, tdlen);
1460 E1000_WRITE_REG(hw, TDH, 0);
1461 E1000_WRITE_REG(hw, TDT, 0);
1462 adapter->tx_ring[0].tdh = E1000_TDH;
1463 adapter->tx_ring[0].tdt = E1000_TDT;
1467 /* Set the default values for the Tx Inter Packet Gap timer */
1469 if (hw->media_type == e1000_media_type_fiber ||
1470 hw->media_type == e1000_media_type_internal_serdes)
1471 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1473 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1475 switch (hw->mac_type) {
1476 case e1000_82542_rev2_0:
1477 case e1000_82542_rev2_1:
1478 tipg = DEFAULT_82542_TIPG_IPGT;
1479 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1480 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1483 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1484 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1487 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1488 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1489 E1000_WRITE_REG(hw, TIPG, tipg);
1491 /* Set the Tx Interrupt Delay register */
1493 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1494 if (hw->mac_type >= e1000_82540)
1495 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1497 /* Program the Transmit Control Register */
1499 tctl = E1000_READ_REG(hw, TCTL);
1501 tctl &= ~E1000_TCTL_CT;
1502 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
1503 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1505 E1000_WRITE_REG(hw, TCTL, tctl);
1507 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1508 tarc = E1000_READ_REG(hw, TARC0);
1509 tarc |= ((1 << 25) | (1 << 21));
1510 E1000_WRITE_REG(hw, TARC0, tarc);
1511 tarc = E1000_READ_REG(hw, TARC1);
1513 if (tctl & E1000_TCTL_MULR)
1517 E1000_WRITE_REG(hw, TARC1, tarc);
1520 e1000_config_collision_dist(hw);
1522 /* Setup Transmit Descriptor Settings for eop descriptor */
1523 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1526 if (hw->mac_type < e1000_82543)
1527 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1529 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1531 /* Cache if we're 82544 running in PCI-X because we'll
1532 * need this to apply a workaround later in the send path. */
1533 if (hw->mac_type == e1000_82544 &&
1534 hw->bus_type == e1000_bus_type_pcix)
1535 adapter->pcix_82544 = 1;
1539 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1540 * @adapter: board private structure
1541 * @rxdr: rx descriptor ring (for a specific queue) to setup
1543 * Returns 0 on success, negative on failure
1547 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1548 struct e1000_rx_ring *rxdr)
1550 struct pci_dev *pdev = adapter->pdev;
1553 size = sizeof(struct e1000_buffer) * rxdr->count;
1554 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1555 if (!rxdr->buffer_info) {
1557 "Unable to allocate memory for the receive descriptor ring\n");
1560 memset(rxdr->buffer_info, 0, size);
1562 size = sizeof(struct e1000_ps_page) * rxdr->count;
1563 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1564 if (!rxdr->ps_page) {
1565 vfree(rxdr->buffer_info);
1567 "Unable to allocate memory for the receive descriptor ring\n");
1570 memset(rxdr->ps_page, 0, size);
1572 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1573 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1574 if (!rxdr->ps_page_dma) {
1575 vfree(rxdr->buffer_info);
1576 kfree(rxdr->ps_page);
1578 "Unable to allocate memory for the receive descriptor ring\n");
1581 memset(rxdr->ps_page_dma, 0, size);
1583 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1584 desc_len = sizeof(struct e1000_rx_desc);
1586 desc_len = sizeof(union e1000_rx_desc_packet_split);
1588 /* Round up to nearest 4K */
1590 rxdr->size = rxdr->count * desc_len;
1591 E1000_ROUNDUP(rxdr->size, 4096);
1593 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1597 "Unable to allocate memory for the receive descriptor ring\n");
1599 vfree(rxdr->buffer_info);
1600 kfree(rxdr->ps_page);
1601 kfree(rxdr->ps_page_dma);
1605 /* Fix for errata 23, can't cross 64kB boundary */
1606 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1607 void *olddesc = rxdr->desc;
1608 dma_addr_t olddma = rxdr->dma;
1609 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1610 "at %p\n", rxdr->size, rxdr->desc);
1611 /* Try again, without freeing the previous */
1612 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1613 /* Failed allocation, critical failure */
1615 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1617 "Unable to allocate memory "
1618 "for the receive descriptor ring\n");
1619 goto setup_rx_desc_die;
1622 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1624 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1626 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1628 "Unable to allocate aligned memory "
1629 "for the receive descriptor ring\n");
1630 goto setup_rx_desc_die;
1632 /* Free old allocation, new allocation was successful */
1633 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1636 memset(rxdr->desc, 0, rxdr->size);
1638 rxdr->next_to_clean = 0;
1639 rxdr->next_to_use = 0;
1640 rxdr->rx_skb_top = NULL;
1641 rxdr->rx_skb_prev = NULL;
1647 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1648 * (Descriptors) for all queues
1649 * @adapter: board private structure
1651 * If this function returns with an error, then it's possible one or
1652 * more of the rings is populated (while the rest are not). It is the
1653 * callers duty to clean those orphaned rings.
1655 * Return 0 on success, negative on failure
1659 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1663 for (i = 0; i < adapter->num_rx_queues; i++) {
1664 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1667 "Allocation for Rx Queue %u failed\n", i);
1676 * e1000_setup_rctl - configure the receive control registers
1677 * @adapter: Board private structure
1679 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1680 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1682 e1000_setup_rctl(struct e1000_adapter *adapter)
1684 uint32_t rctl, rfctl;
1685 uint32_t psrctl = 0;
1686 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1690 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1692 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1694 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1695 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1696 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1698 if (adapter->hw.mac_type > e1000_82543)
1699 rctl |= E1000_RCTL_SECRC;
1701 if (adapter->hw.tbi_compatibility_on == 1)
1702 rctl |= E1000_RCTL_SBP;
1704 rctl &= ~E1000_RCTL_SBP;
1706 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1707 rctl &= ~E1000_RCTL_LPE;
1709 rctl |= E1000_RCTL_LPE;
1711 /* Setup buffer sizes */
1712 if (adapter->hw.mac_type >= e1000_82571) {
1713 /* We can now specify buffers in 1K increments.
1714 * BSIZE and BSEX are ignored in this case. */
1715 rctl |= adapter->rx_buffer_len << 0x11;
1717 rctl &= ~E1000_RCTL_SZ_4096;
1718 rctl &= ~E1000_RCTL_BSEX;
1719 rctl |= E1000_RCTL_SZ_2048;
1722 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1723 /* 82571 and greater support packet-split where the protocol
1724 * header is placed in skb->data and the packet data is
1725 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1726 * In the case of a non-split, skb->data is linearly filled,
1727 * followed by the page buffers. Therefore, skb->data is
1728 * sized to hold the largest protocol header.
1730 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1731 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1733 adapter->rx_ps_pages = pages;
1735 adapter->rx_ps_pages = 0;
1737 if (adapter->rx_ps_pages) {
1738 /* Configure extra packet-split registers */
1739 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1740 rfctl |= E1000_RFCTL_EXTEN;
1741 /* disable IPv6 packet split support */
1742 rfctl |= E1000_RFCTL_IPV6_DIS;
1743 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1745 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1747 psrctl |= adapter->rx_ps_bsize0 >>
1748 E1000_PSRCTL_BSIZE0_SHIFT;
1750 switch (adapter->rx_ps_pages) {
1752 psrctl |= PAGE_SIZE <<
1753 E1000_PSRCTL_BSIZE3_SHIFT;
1755 psrctl |= PAGE_SIZE <<
1756 E1000_PSRCTL_BSIZE2_SHIFT;
1758 psrctl |= PAGE_SIZE >>
1759 E1000_PSRCTL_BSIZE1_SHIFT;
1763 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1766 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1770 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1771 * @adapter: board private structure
1773 * Configure the Rx unit of the MAC after a reset.
1777 e1000_configure_rx(struct e1000_adapter *adapter)
1780 struct e1000_hw *hw = &adapter->hw;
1781 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1782 #ifdef CONFIG_E1000_MQ
1783 uint32_t reta, mrqc;
1787 if (adapter->rx_ps_pages) {
1788 rdlen = adapter->rx_ring[0].count *
1789 sizeof(union e1000_rx_desc_packet_split);
1790 adapter->clean_rx = e1000_clean_rx_irq_ps;
1791 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1793 rdlen = adapter->rx_ring[0].count *
1794 sizeof(struct e1000_rx_desc);
1795 adapter->clean_rx = e1000_clean_rx_irq;
1796 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1799 /* disable receives while setting up the descriptors */
1800 rctl = E1000_READ_REG(hw, RCTL);
1801 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1803 /* set the Receive Delay Timer Register */
1804 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1806 if (hw->mac_type >= e1000_82540) {
1807 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1808 if (adapter->itr > 1)
1809 E1000_WRITE_REG(hw, ITR,
1810 1000000000 / (adapter->itr * 256));
1813 if (hw->mac_type >= e1000_82571) {
1814 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1815 /* Reset delay timers after every interrupt */
1816 ctrl_ext |= E1000_CTRL_EXT_CANC;
1817 #ifdef CONFIG_E1000_NAPI
1818 /* Auto-Mask interrupts upon ICR read. */
1819 ctrl_ext |= E1000_CTRL_EXT_IAME;
1821 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1822 E1000_WRITE_REG(hw, IAM, ~0);
1823 E1000_WRITE_FLUSH(hw);
1826 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1827 * the Base and Length of the Rx Descriptor Ring */
1828 switch (adapter->num_rx_queues) {
1829 #ifdef CONFIG_E1000_MQ
1831 rdba = adapter->rx_ring[1].dma;
1832 E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
1833 E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
1834 E1000_WRITE_REG(hw, RDLEN1, rdlen);
1835 E1000_WRITE_REG(hw, RDH1, 0);
1836 E1000_WRITE_REG(hw, RDT1, 0);
1837 adapter->rx_ring[1].rdh = E1000_RDH1;
1838 adapter->rx_ring[1].rdt = E1000_RDT1;
1843 rdba = adapter->rx_ring[0].dma;
1844 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1845 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1846 E1000_WRITE_REG(hw, RDLEN, rdlen);
1847 E1000_WRITE_REG(hw, RDH, 0);
1848 E1000_WRITE_REG(hw, RDT, 0);
1849 adapter->rx_ring[0].rdh = E1000_RDH;
1850 adapter->rx_ring[0].rdt = E1000_RDT;
1854 #ifdef CONFIG_E1000_MQ
1855 if (adapter->num_rx_queues > 1) {
1856 uint32_t random[10];
1858 get_random_bytes(&random[0], 40);
1860 if (hw->mac_type <= e1000_82572) {
1861 E1000_WRITE_REG(hw, RSSIR, 0);
1862 E1000_WRITE_REG(hw, RSSIM, 0);
1865 switch (adapter->num_rx_queues) {
1869 mrqc = E1000_MRQC_ENABLE_RSS_2Q;
1873 /* Fill out redirection table */
1874 for (i = 0; i < 32; i++)
1875 E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
1876 /* Fill out hash function seeds */
1877 for (i = 0; i < 10; i++)
1878 E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
1880 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1881 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1882 E1000_WRITE_REG(hw, MRQC, mrqc);
1885 /* Multiqueue and packet checksumming are mutually exclusive. */
1886 if (hw->mac_type >= e1000_82571) {
1887 rxcsum = E1000_READ_REG(hw, RXCSUM);
1888 rxcsum |= E1000_RXCSUM_PCSD;
1889 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1894 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1895 if (hw->mac_type >= e1000_82543) {
1896 rxcsum = E1000_READ_REG(hw, RXCSUM);
1897 if (adapter->rx_csum == TRUE) {
1898 rxcsum |= E1000_RXCSUM_TUOFL;
1900 /* Enable 82571 IPv4 payload checksum for UDP fragments
1901 * Must be used in conjunction with packet-split. */
1902 if ((hw->mac_type >= e1000_82571) &&
1903 (adapter->rx_ps_pages)) {
1904 rxcsum |= E1000_RXCSUM_IPPCSE;
1907 rxcsum &= ~E1000_RXCSUM_TUOFL;
1908 /* don't need to clear IPPCSE as it defaults to 0 */
1910 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1912 #endif /* CONFIG_E1000_MQ */
1914 if (hw->mac_type == e1000_82573)
1915 E1000_WRITE_REG(hw, ERT, 0x0100);
1917 /* Enable Receives */
1918 E1000_WRITE_REG(hw, RCTL, rctl);
1922 * e1000_free_tx_resources - Free Tx Resources per Queue
1923 * @adapter: board private structure
1924 * @tx_ring: Tx descriptor ring for a specific queue
1926 * Free all transmit software resources
1930 e1000_free_tx_resources(struct e1000_adapter *adapter,
1931 struct e1000_tx_ring *tx_ring)
1933 struct pci_dev *pdev = adapter->pdev;
1935 e1000_clean_tx_ring(adapter, tx_ring);
1937 vfree(tx_ring->buffer_info);
1938 tx_ring->buffer_info = NULL;
1940 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1942 tx_ring->desc = NULL;
1946 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1947 * @adapter: board private structure
1949 * Free all transmit software resources
1953 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1957 for (i = 0; i < adapter->num_tx_queues; i++)
1958 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1962 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1963 struct e1000_buffer *buffer_info)
1965 if (buffer_info->dma) {
1966 pci_unmap_page(adapter->pdev,
1968 buffer_info->length,
1971 if (buffer_info->skb)
1972 dev_kfree_skb_any(buffer_info->skb);
1973 memset(buffer_info, 0, sizeof(struct e1000_buffer));
1977 * e1000_clean_tx_ring - Free Tx Buffers
1978 * @adapter: board private structure
1979 * @tx_ring: ring to be cleaned
1983 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1984 struct e1000_tx_ring *tx_ring)
1986 struct e1000_buffer *buffer_info;
1990 /* Free all the Tx ring sk_buffs */
1992 for (i = 0; i < tx_ring->count; i++) {
1993 buffer_info = &tx_ring->buffer_info[i];
1994 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1997 size = sizeof(struct e1000_buffer) * tx_ring->count;
1998 memset(tx_ring->buffer_info, 0, size);
2000 /* Zero out the descriptor ring */
2002 memset(tx_ring->desc, 0, tx_ring->size);
2004 tx_ring->next_to_use = 0;
2005 tx_ring->next_to_clean = 0;
2006 tx_ring->last_tx_tso = 0;
2008 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2009 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2013 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2014 * @adapter: board private structure
2018 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2022 for (i = 0; i < adapter->num_tx_queues; i++)
2023 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2027 * e1000_free_rx_resources - Free Rx Resources
2028 * @adapter: board private structure
2029 * @rx_ring: ring to clean the resources from
2031 * Free all receive software resources
2035 e1000_free_rx_resources(struct e1000_adapter *adapter,
2036 struct e1000_rx_ring *rx_ring)
2038 struct pci_dev *pdev = adapter->pdev;
2040 e1000_clean_rx_ring(adapter, rx_ring);
2042 vfree(rx_ring->buffer_info);
2043 rx_ring->buffer_info = NULL;
2044 kfree(rx_ring->ps_page);
2045 rx_ring->ps_page = NULL;
2046 kfree(rx_ring->ps_page_dma);
2047 rx_ring->ps_page_dma = NULL;
2049 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2051 rx_ring->desc = NULL;
2055 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2056 * @adapter: board private structure
2058 * Free all receive software resources
2062 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2066 for (i = 0; i < adapter->num_rx_queues; i++)
2067 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2071 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2072 * @adapter: board private structure
2073 * @rx_ring: ring to free buffers from
2077 e1000_clean_rx_ring(struct e1000_adapter *adapter,
2078 struct e1000_rx_ring *rx_ring)
2080 struct e1000_buffer *buffer_info;
2081 struct e1000_ps_page *ps_page;
2082 struct e1000_ps_page_dma *ps_page_dma;
2083 struct pci_dev *pdev = adapter->pdev;
2087 /* Free all the Rx ring sk_buffs */
2088 for (i = 0; i < rx_ring->count; i++) {
2089 buffer_info = &rx_ring->buffer_info[i];
2090 if (buffer_info->skb) {
2091 pci_unmap_single(pdev,
2093 buffer_info->length,
2094 PCI_DMA_FROMDEVICE);
2096 dev_kfree_skb(buffer_info->skb);
2097 buffer_info->skb = NULL;
2099 ps_page = &rx_ring->ps_page[i];
2100 ps_page_dma = &rx_ring->ps_page_dma[i];
2101 for (j = 0; j < adapter->rx_ps_pages; j++) {
2102 if (!ps_page->ps_page[j]) break;
2103 pci_unmap_page(pdev,
2104 ps_page_dma->ps_page_dma[j],
2105 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2106 ps_page_dma->ps_page_dma[j] = 0;
2107 put_page(ps_page->ps_page[j]);
2108 ps_page->ps_page[j] = NULL;
2112 /* there also may be some cached data in our adapter */
2113 if (rx_ring->rx_skb_top) {
2114 dev_kfree_skb(rx_ring->rx_skb_top);
2116 /* rx_skb_prev will be wiped out by rx_skb_top */
2117 rx_ring->rx_skb_top = NULL;
2118 rx_ring->rx_skb_prev = NULL;
2122 size = sizeof(struct e1000_buffer) * rx_ring->count;
2123 memset(rx_ring->buffer_info, 0, size);
2124 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2125 memset(rx_ring->ps_page, 0, size);
2126 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2127 memset(rx_ring->ps_page_dma, 0, size);
2129 /* Zero out the descriptor ring */
2131 memset(rx_ring->desc, 0, rx_ring->size);
2133 rx_ring->next_to_clean = 0;
2134 rx_ring->next_to_use = 0;
2136 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2137 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2141 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2142 * @adapter: board private structure
2146 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2150 for (i = 0; i < adapter->num_rx_queues; i++)
2151 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2154 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2155 * and memory write and invalidate disabled for certain operations
2158 e1000_enter_82542_rst(struct e1000_adapter *adapter)
2160 struct net_device *netdev = adapter->netdev;
2163 e1000_pci_clear_mwi(&adapter->hw);
2165 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2166 rctl |= E1000_RCTL_RST;
2167 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2168 E1000_WRITE_FLUSH(&adapter->hw);
2171 if (netif_running(netdev))
2172 e1000_clean_all_rx_rings(adapter);
2176 e1000_leave_82542_rst(struct e1000_adapter *adapter)
2178 struct net_device *netdev = adapter->netdev;
2181 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2182 rctl &= ~E1000_RCTL_RST;
2183 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2184 E1000_WRITE_FLUSH(&adapter->hw);
2187 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2188 e1000_pci_set_mwi(&adapter->hw);
2190 if (netif_running(netdev)) {
2191 e1000_configure_rx(adapter);
2192 /* No need to loop, because 82542 supports only 1 queue */
2193 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2194 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2199 * e1000_set_mac - Change the Ethernet Address of the NIC
2200 * @netdev: network interface device structure
2201 * @p: pointer to an address structure
2203 * Returns 0 on success, negative on failure
2207 e1000_set_mac(struct net_device *netdev, void *p)
2209 struct e1000_adapter *adapter = netdev_priv(netdev);
2210 struct sockaddr *addr = p;
2212 if (!is_valid_ether_addr(addr->sa_data))
2213 return -EADDRNOTAVAIL;
2215 /* 82542 2.0 needs to be in reset to write receive address registers */
2217 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2218 e1000_enter_82542_rst(adapter);
2220 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2221 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2223 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2225 /* With 82571 controllers, LAA may be overwritten (with the default)
2226 * due to controller reset from the other port. */
2227 if (adapter->hw.mac_type == e1000_82571) {
2228 /* activate the work around */
2229 adapter->hw.laa_is_present = 1;
2231 /* Hold a copy of the LAA in RAR[14] This is done so that
2232 * between the time RAR[0] gets clobbered and the time it
2233 * gets fixed (in e1000_watchdog), the actual LAA is in one
2234 * of the RARs and no incoming packets directed to this port
2235 * are dropped. Eventaully the LAA will be in RAR[0] and
2237 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2238 E1000_RAR_ENTRIES - 1);
2241 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2242 e1000_leave_82542_rst(adapter);
2248 * e1000_set_multi - Multicast and Promiscuous mode set
2249 * @netdev: network interface device structure
2251 * The set_multi entry point is called whenever the multicast address
2252 * list or the network interface flags are updated. This routine is
2253 * responsible for configuring the hardware for proper multicast,
2254 * promiscuous mode, and all-multi behavior.
2258 e1000_set_multi(struct net_device *netdev)
2260 struct e1000_adapter *adapter = netdev_priv(netdev);
2261 struct e1000_hw *hw = &adapter->hw;
2262 struct dev_mc_list *mc_ptr;
2264 uint32_t hash_value;
2265 int i, rar_entries = E1000_RAR_ENTRIES;
2267 /* reserve RAR[14] for LAA over-write work-around */
2268 if (adapter->hw.mac_type == e1000_82571)
2271 /* Check for Promiscuous and All Multicast modes */
2273 rctl = E1000_READ_REG(hw, RCTL);
2275 if (netdev->flags & IFF_PROMISC) {
2276 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2277 } else if (netdev->flags & IFF_ALLMULTI) {
2278 rctl |= E1000_RCTL_MPE;
2279 rctl &= ~E1000_RCTL_UPE;
2281 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2284 E1000_WRITE_REG(hw, RCTL, rctl);
2286 /* 82542 2.0 needs to be in reset to write receive address registers */
2288 if (hw->mac_type == e1000_82542_rev2_0)
2289 e1000_enter_82542_rst(adapter);
2291 /* load the first 14 multicast address into the exact filters 1-14
2292 * RAR 0 is used for the station MAC adddress
2293 * if there are not 14 addresses, go ahead and clear the filters
2294 * -- with 82571 controllers only 0-13 entries are filled here
2296 mc_ptr = netdev->mc_list;
2298 for (i = 1; i < rar_entries; i++) {
2300 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2301 mc_ptr = mc_ptr->next;
2303 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2304 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2308 /* clear the old settings from the multicast hash table */
2310 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2311 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2313 /* load any remaining addresses into the hash table */
2315 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2316 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2317 e1000_mta_set(hw, hash_value);
2320 if (hw->mac_type == e1000_82542_rev2_0)
2321 e1000_leave_82542_rst(adapter);
2324 /* Need to wait a few seconds after link up to get diagnostic information from
2328 e1000_update_phy_info(unsigned long data)
2330 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2331 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2335 * e1000_82547_tx_fifo_stall - Timer Call-back
2336 * @data: pointer to adapter cast into an unsigned long
2340 e1000_82547_tx_fifo_stall(unsigned long data)
2342 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2343 struct net_device *netdev = adapter->netdev;
2346 if (atomic_read(&adapter->tx_fifo_stall)) {
2347 if ((E1000_READ_REG(&adapter->hw, TDT) ==
2348 E1000_READ_REG(&adapter->hw, TDH)) &&
2349 (E1000_READ_REG(&adapter->hw, TDFT) ==
2350 E1000_READ_REG(&adapter->hw, TDFH)) &&
2351 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2352 E1000_READ_REG(&adapter->hw, TDFHS))) {
2353 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2354 E1000_WRITE_REG(&adapter->hw, TCTL,
2355 tctl & ~E1000_TCTL_EN);
2356 E1000_WRITE_REG(&adapter->hw, TDFT,
2357 adapter->tx_head_addr);
2358 E1000_WRITE_REG(&adapter->hw, TDFH,
2359 adapter->tx_head_addr);
2360 E1000_WRITE_REG(&adapter->hw, TDFTS,
2361 adapter->tx_head_addr);
2362 E1000_WRITE_REG(&adapter->hw, TDFHS,
2363 adapter->tx_head_addr);
2364 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2365 E1000_WRITE_FLUSH(&adapter->hw);
2367 adapter->tx_fifo_head = 0;
2368 atomic_set(&adapter->tx_fifo_stall, 0);
2369 netif_wake_queue(netdev);
2371 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2377 * e1000_watchdog - Timer Call-back
2378 * @data: pointer to adapter cast into an unsigned long
2381 e1000_watchdog(unsigned long data)
2383 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2385 /* Do the rest outside of interrupt context */
2386 schedule_work(&adapter->watchdog_task);
2390 e1000_watchdog_task(struct e1000_adapter *adapter)
2392 struct net_device *netdev = adapter->netdev;
2393 struct e1000_tx_ring *txdr = adapter->tx_ring;
2396 e1000_check_for_link(&adapter->hw);
2397 if (adapter->hw.mac_type == e1000_82573) {
2398 e1000_enable_tx_pkt_filtering(&adapter->hw);
2399 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2400 e1000_update_mng_vlan(adapter);
2403 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2404 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2405 link = !adapter->hw.serdes_link_down;
2407 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2410 if (!netif_carrier_ok(netdev)) {
2411 e1000_get_speed_and_duplex(&adapter->hw,
2412 &adapter->link_speed,
2413 &adapter->link_duplex);
2415 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2416 adapter->link_speed,
2417 adapter->link_duplex == FULL_DUPLEX ?
2418 "Full Duplex" : "Half Duplex");
2420 /* tweak tx_queue_len according to speed/duplex */
2421 netdev->tx_queue_len = adapter->tx_queue_len;
2422 adapter->tx_timeout_factor = 1;
2423 if (adapter->link_duplex == HALF_DUPLEX) {
2424 switch (adapter->link_speed) {
2426 netdev->tx_queue_len = 10;
2427 adapter->tx_timeout_factor = 8;
2430 netdev->tx_queue_len = 100;
2435 netif_carrier_on(netdev);
2436 netif_wake_queue(netdev);
2437 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2438 adapter->smartspeed = 0;
2441 if (netif_carrier_ok(netdev)) {
2442 adapter->link_speed = 0;
2443 adapter->link_duplex = 0;
2444 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2445 netif_carrier_off(netdev);
2446 netif_stop_queue(netdev);
2447 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2450 e1000_smartspeed(adapter);
2453 e1000_update_stats(adapter);
2455 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2456 adapter->tpt_old = adapter->stats.tpt;
2457 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2458 adapter->colc_old = adapter->stats.colc;
2460 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2461 adapter->gorcl_old = adapter->stats.gorcl;
2462 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2463 adapter->gotcl_old = adapter->stats.gotcl;
2465 e1000_update_adaptive(&adapter->hw);
2467 #ifdef CONFIG_E1000_MQ
2468 txdr = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2470 if (!netif_carrier_ok(netdev)) {
2471 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2472 /* We've lost link, so the controller stops DMA,
2473 * but we've got queued Tx work that's never going
2474 * to get done, so reset controller to flush Tx.
2475 * (Do the reset outside of interrupt context). */
2476 schedule_work(&adapter->tx_timeout_task);
2480 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2481 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2482 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2483 * asymmetrical Tx or Rx gets ITR=8000; everyone
2484 * else is between 2000-8000. */
2485 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2486 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2487 adapter->gotcl - adapter->gorcl :
2488 adapter->gorcl - adapter->gotcl) / 10000;
2489 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2490 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2493 /* Cause software interrupt to ensure rx ring is cleaned */
2494 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2496 /* Force detection of hung controller every watchdog period */
2497 adapter->detect_tx_hung = TRUE;
2499 /* With 82571 controllers, LAA may be overwritten due to controller
2500 * reset from the other port. Set the appropriate LAA in RAR[0] */
2501 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2502 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2504 /* Reset the timer */
2505 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2508 #define E1000_TX_FLAGS_CSUM 0x00000001
2509 #define E1000_TX_FLAGS_VLAN 0x00000002
2510 #define E1000_TX_FLAGS_TSO 0x00000004
2511 #define E1000_TX_FLAGS_IPV4 0x00000008
2512 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2513 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2516 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2517 struct sk_buff *skb)
2520 struct e1000_context_desc *context_desc;
2521 struct e1000_buffer *buffer_info;
2523 uint32_t cmd_length = 0;
2524 uint16_t ipcse = 0, tucse, mss;
2525 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2528 if (skb_shinfo(skb)->tso_size) {
2529 if (skb_header_cloned(skb)) {
2530 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2535 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2536 mss = skb_shinfo(skb)->tso_size;
2537 if (skb->protocol == ntohs(ETH_P_IP)) {
2538 skb->nh.iph->tot_len = 0;
2539 skb->nh.iph->check = 0;
2541 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2546 cmd_length = E1000_TXD_CMD_IP;
2547 ipcse = skb->h.raw - skb->data - 1;
2548 #ifdef NETIF_F_TSO_IPV6
2549 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
2550 skb->nh.ipv6h->payload_len = 0;
2552 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2553 &skb->nh.ipv6h->daddr,
2560 ipcss = skb->nh.raw - skb->data;
2561 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2562 tucss = skb->h.raw - skb->data;
2563 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2566 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2567 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2569 i = tx_ring->next_to_use;
2570 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2571 buffer_info = &tx_ring->buffer_info[i];
2573 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2574 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2575 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2576 context_desc->upper_setup.tcp_fields.tucss = tucss;
2577 context_desc->upper_setup.tcp_fields.tucso = tucso;
2578 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2579 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2580 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2581 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2583 buffer_info->time_stamp = jiffies;
2585 if (++i == tx_ring->count) i = 0;
2586 tx_ring->next_to_use = i;
2595 static inline boolean_t
2596 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2597 struct sk_buff *skb)
2599 struct e1000_context_desc *context_desc;
2600 struct e1000_buffer *buffer_info;
2604 if (likely(skb->ip_summed == CHECKSUM_HW)) {
2605 css = skb->h.raw - skb->data;
2607 i = tx_ring->next_to_use;
2608 buffer_info = &tx_ring->buffer_info[i];
2609 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2611 context_desc->upper_setup.tcp_fields.tucss = css;
2612 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2613 context_desc->upper_setup.tcp_fields.tucse = 0;
2614 context_desc->tcp_seg_setup.data = 0;
2615 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2617 buffer_info->time_stamp = jiffies;
2619 if (unlikely(++i == tx_ring->count)) i = 0;
2620 tx_ring->next_to_use = i;
2628 #define E1000_MAX_TXD_PWR 12
2629 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2632 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2633 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2634 unsigned int nr_frags, unsigned int mss)
2636 struct e1000_buffer *buffer_info;
2637 unsigned int len = skb->len;
2638 unsigned int offset = 0, size, count = 0, i;
2640 len -= skb->data_len;
2642 i = tx_ring->next_to_use;
2645 buffer_info = &tx_ring->buffer_info[i];
2646 size = min(len, max_per_txd);
2648 /* Workaround for Controller erratum --
2649 * descriptor for non-tso packet in a linear SKB that follows a
2650 * tso gets written back prematurely before the data is fully
2651 * DMAd to the controller */
2652 if (!skb->data_len && tx_ring->last_tx_tso &&
2653 !skb_shinfo(skb)->tso_size) {
2654 tx_ring->last_tx_tso = 0;
2658 /* Workaround for premature desc write-backs
2659 * in TSO mode. Append 4-byte sentinel desc */
2660 if (unlikely(mss && !nr_frags && size == len && size > 8))
2663 /* work-around for errata 10 and it applies
2664 * to all controllers in PCI-X mode
2665 * The fix is to make sure that the first descriptor of a
2666 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2668 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2669 (size > 2015) && count == 0))
2672 /* Workaround for potential 82544 hang in PCI-X. Avoid
2673 * terminating buffers within evenly-aligned dwords. */
2674 if (unlikely(adapter->pcix_82544 &&
2675 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2679 buffer_info->length = size;
2681 pci_map_single(adapter->pdev,
2685 buffer_info->time_stamp = jiffies;
2690 if (unlikely(++i == tx_ring->count)) i = 0;
2693 for (f = 0; f < nr_frags; f++) {
2694 struct skb_frag_struct *frag;
2696 frag = &skb_shinfo(skb)->frags[f];
2698 offset = frag->page_offset;
2701 buffer_info = &tx_ring->buffer_info[i];
2702 size = min(len, max_per_txd);
2704 /* Workaround for premature desc write-backs
2705 * in TSO mode. Append 4-byte sentinel desc */
2706 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2709 /* Workaround for potential 82544 hang in PCI-X.
2710 * Avoid terminating buffers within evenly-aligned
2712 if (unlikely(adapter->pcix_82544 &&
2713 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2717 buffer_info->length = size;
2719 pci_map_page(adapter->pdev,
2724 buffer_info->time_stamp = jiffies;
2729 if (unlikely(++i == tx_ring->count)) i = 0;
2733 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2734 tx_ring->buffer_info[i].skb = skb;
2735 tx_ring->buffer_info[first].next_to_watch = i;
2741 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2742 int tx_flags, int count)
2744 struct e1000_tx_desc *tx_desc = NULL;
2745 struct e1000_buffer *buffer_info;
2746 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2749 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2750 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2752 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2754 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2755 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2758 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2759 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2760 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2763 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2764 txd_lower |= E1000_TXD_CMD_VLE;
2765 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2768 i = tx_ring->next_to_use;
2771 buffer_info = &tx_ring->buffer_info[i];
2772 tx_desc = E1000_TX_DESC(*tx_ring, i);
2773 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2774 tx_desc->lower.data =
2775 cpu_to_le32(txd_lower | buffer_info->length);
2776 tx_desc->upper.data = cpu_to_le32(txd_upper);
2777 if (unlikely(++i == tx_ring->count)) i = 0;
2780 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2782 /* Force memory writes to complete before letting h/w
2783 * know there are new descriptors to fetch. (Only
2784 * applicable for weak-ordered memory model archs,
2785 * such as IA-64). */
2788 tx_ring->next_to_use = i;
2789 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2793 * 82547 workaround to avoid controller hang in half-duplex environment.
2794 * The workaround is to avoid queuing a large packet that would span
2795 * the internal Tx FIFO ring boundary by notifying the stack to resend
2796 * the packet at a later time. This gives the Tx FIFO an opportunity to
2797 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2798 * to the beginning of the Tx FIFO.
2801 #define E1000_FIFO_HDR 0x10
2802 #define E1000_82547_PAD_LEN 0x3E0
2805 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2807 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2808 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2810 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2812 if (adapter->link_duplex != HALF_DUPLEX)
2813 goto no_fifo_stall_required;
2815 if (atomic_read(&adapter->tx_fifo_stall))
2818 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2819 atomic_set(&adapter->tx_fifo_stall, 1);
2823 no_fifo_stall_required:
2824 adapter->tx_fifo_head += skb_fifo_len;
2825 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
2826 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2830 #define MINIMUM_DHCP_PACKET_SIZE 282
2832 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2834 struct e1000_hw *hw = &adapter->hw;
2835 uint16_t length, offset;
2836 if (vlan_tx_tag_present(skb)) {
2837 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2838 ( adapter->hw.mng_cookie.status &
2839 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2842 if ((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
2843 struct ethhdr *eth = (struct ethhdr *) skb->data;
2844 if ((htons(ETH_P_IP) == eth->h_proto)) {
2845 const struct iphdr *ip =
2846 (struct iphdr *)((uint8_t *)skb->data+14);
2847 if (IPPROTO_UDP == ip->protocol) {
2848 struct udphdr *udp =
2849 (struct udphdr *)((uint8_t *)ip +
2851 if (ntohs(udp->dest) == 67) {
2852 offset = (uint8_t *)udp + 8 - skb->data;
2853 length = skb->len - offset;
2855 return e1000_mng_write_dhcp_info(hw,
2865 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2867 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2869 struct e1000_adapter *adapter = netdev_priv(netdev);
2870 struct e1000_tx_ring *tx_ring;
2871 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2872 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2873 unsigned int tx_flags = 0;
2874 unsigned int len = skb->len;
2875 unsigned long flags;
2876 unsigned int nr_frags = 0;
2877 unsigned int mss = 0;
2881 len -= skb->data_len;
2883 #ifdef CONFIG_E1000_MQ
2884 tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2886 tx_ring = adapter->tx_ring;
2889 if (unlikely(skb->len <= 0)) {
2890 dev_kfree_skb_any(skb);
2891 return NETDEV_TX_OK;
2895 mss = skb_shinfo(skb)->tso_size;
2896 /* The controller does a simple calculation to
2897 * make sure there is enough room in the FIFO before
2898 * initiating the DMA for each buffer. The calc is:
2899 * 4 = ceil(buffer len/mss). To make sure we don't
2900 * overrun the FIFO, adjust the max buffer len if mss
2904 max_per_txd = min(mss << 2, max_per_txd);
2905 max_txd_pwr = fls(max_per_txd) - 1;
2907 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2908 * points to just header, pull a few bytes of payload from
2909 * frags into skb->data */
2910 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2911 if (skb->data_len && (hdr_len == (skb->len - skb->data_len)) &&
2912 (adapter->hw.mac_type == e1000_82571 ||
2913 adapter->hw.mac_type == e1000_82572)) {
2914 unsigned int pull_size;
2915 pull_size = min((unsigned int)4, skb->data_len);
2916 if (!__pskb_pull_tail(skb, pull_size)) {
2917 printk(KERN_ERR "__pskb_pull_tail failed.\n");
2918 dev_kfree_skb_any(skb);
2921 len = skb->len - skb->data_len;
2925 /* reserve a descriptor for the offload context */
2926 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
2930 if (skb->ip_summed == CHECKSUM_HW)
2935 /* Controller Erratum workaround */
2936 if (!skb->data_len && tx_ring->last_tx_tso &&
2937 !skb_shinfo(skb)->tso_size)
2941 count += TXD_USE_COUNT(len, max_txd_pwr);
2943 if (adapter->pcix_82544)
2946 /* work-around for errata 10 and it applies to all controllers
2947 * in PCI-X mode, so add one more descriptor to the count
2949 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2953 nr_frags = skb_shinfo(skb)->nr_frags;
2954 for (f = 0; f < nr_frags; f++)
2955 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2957 if (adapter->pcix_82544)
2960 if (adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2961 e1000_transfer_dhcp_info(adapter, skb);
2963 local_irq_save(flags);
2964 if (!spin_trylock(&tx_ring->tx_lock)) {
2965 /* Collision - tell upper layer to requeue */
2966 local_irq_restore(flags);
2967 return NETDEV_TX_LOCKED;
2970 /* need: count + 2 desc gap to keep tail from touching
2971 * head, otherwise try next time */
2972 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2973 netif_stop_queue(netdev);
2974 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2975 return NETDEV_TX_BUSY;
2978 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2979 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2980 netif_stop_queue(netdev);
2981 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2982 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2983 return NETDEV_TX_BUSY;
2987 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2988 tx_flags |= E1000_TX_FLAGS_VLAN;
2989 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2992 first = tx_ring->next_to_use;
2994 tso = e1000_tso(adapter, tx_ring, skb);
2996 dev_kfree_skb_any(skb);
2997 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2998 return NETDEV_TX_OK;
3002 tx_ring->last_tx_tso = 1;
3003 tx_flags |= E1000_TX_FLAGS_TSO;
3004 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3005 tx_flags |= E1000_TX_FLAGS_CSUM;
3007 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3008 * 82571 hardware supports TSO capabilities for IPv6 as well...
3009 * no longer assume, we must. */
3010 if (likely(skb->protocol == ntohs(ETH_P_IP)))
3011 tx_flags |= E1000_TX_FLAGS_IPV4;
3013 e1000_tx_queue(adapter, tx_ring, tx_flags,
3014 e1000_tx_map(adapter, tx_ring, skb, first,
3015 max_per_txd, nr_frags, mss));
3017 netdev->trans_start = jiffies;
3019 /* Make sure there is space in the ring for the next send. */
3020 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
3021 netif_stop_queue(netdev);
3023 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3024 return NETDEV_TX_OK;
3028 * e1000_tx_timeout - Respond to a Tx Hang
3029 * @netdev: network interface device structure
3033 e1000_tx_timeout(struct net_device *netdev)
3035 struct e1000_adapter *adapter = netdev_priv(netdev);
3037 /* Do the reset outside of interrupt context */
3038 schedule_work(&adapter->tx_timeout_task);
3042 e1000_tx_timeout_task(struct net_device *netdev)
3044 struct e1000_adapter *adapter = netdev_priv(netdev);
3046 adapter->tx_timeout_count++;
3047 e1000_down(adapter);
3052 * e1000_get_stats - Get System Network Statistics
3053 * @netdev: network interface device structure
3055 * Returns the address of the device statistics structure.
3056 * The statistics are actually updated from the timer callback.
3059 static struct net_device_stats *
3060 e1000_get_stats(struct net_device *netdev)
3062 struct e1000_adapter *adapter = netdev_priv(netdev);
3064 /* only return the current stats */
3065 return &adapter->net_stats;
3069 * e1000_change_mtu - Change the Maximum Transfer Unit
3070 * @netdev: network interface device structure
3071 * @new_mtu: new value for maximum frame size
3073 * Returns 0 on success, negative on failure
3077 e1000_change_mtu(struct net_device *netdev, int new_mtu)
3079 struct e1000_adapter *adapter = netdev_priv(netdev);
3080 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3082 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3083 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3084 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3088 /* Adapter-specific max frame size limits. */
3089 switch (adapter->hw.mac_type) {
3090 case e1000_82542_rev2_0:
3091 case e1000_82542_rev2_1:
3093 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3094 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3100 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3101 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3102 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3107 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3111 /* since the driver code now supports splitting a packet across
3112 * multiple descriptors, most of the fifo related limitations on
3113 * jumbo frame traffic have gone away.
3114 * simply use 2k descriptors for everything.
3116 * NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3117 * means we reserve 2 more, this pushes us to allocate from the next
3119 * i.e. RXBUFFER_2048 --> size-4096 slab */
3121 /* recent hardware supports 1KB granularity */
3122 if (adapter->hw.mac_type > e1000_82547_rev_2) {
3123 adapter->rx_buffer_len =
3124 ((max_frame < E1000_RXBUFFER_2048) ?
3125 max_frame : E1000_RXBUFFER_2048);
3126 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
3128 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3130 netdev->mtu = new_mtu;
3132 if (netif_running(netdev)) {
3133 e1000_down(adapter);
3137 adapter->hw.max_frame_size = max_frame;
3143 * e1000_update_stats - Update the board statistics counters
3144 * @adapter: board private structure
3148 e1000_update_stats(struct e1000_adapter *adapter)
3150 struct e1000_hw *hw = &adapter->hw;
3151 unsigned long flags;
3154 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3156 spin_lock_irqsave(&adapter->stats_lock, flags);
3158 /* these counters are modified from e1000_adjust_tbi_stats,
3159 * called from the interrupt context, so they must only
3160 * be written while holding adapter->stats_lock
3163 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3164 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3165 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3166 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3167 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3168 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3169 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3170 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3171 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3172 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3173 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3174 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3175 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3177 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3178 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3179 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3180 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3181 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3182 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3183 adapter->stats.dc += E1000_READ_REG(hw, DC);
3184 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3185 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3186 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3187 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3188 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3189 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3190 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3191 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3192 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3193 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3194 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3195 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3196 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3197 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3198 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3199 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3200 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3201 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3202 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3203 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3204 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3205 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3206 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3207 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3208 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3209 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3210 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3212 /* used for adaptive IFS */
3214 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3215 adapter->stats.tpt += hw->tx_packet_delta;
3216 hw->collision_delta = E1000_READ_REG(hw, COLC);
3217 adapter->stats.colc += hw->collision_delta;
3219 if (hw->mac_type >= e1000_82543) {
3220 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3221 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3222 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3223 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3224 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3225 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3227 if (hw->mac_type > e1000_82547_rev_2) {
3228 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3229 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3230 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3231 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3232 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3233 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3234 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3235 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3236 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3239 /* Fill out the OS statistics structure */
3241 adapter->net_stats.rx_packets = adapter->stats.gprc;
3242 adapter->net_stats.tx_packets = adapter->stats.gptc;
3243 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3244 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3245 adapter->net_stats.multicast = adapter->stats.mprc;
3246 adapter->net_stats.collisions = adapter->stats.colc;
3250 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3251 adapter->stats.crcerrs + adapter->stats.algnerrc +
3252 adapter->stats.rlec + adapter->stats.cexterr;
3253 adapter->net_stats.rx_dropped = 0;
3254 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3255 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3256 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3257 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3261 adapter->net_stats.tx_errors = adapter->stats.ecol +
3262 adapter->stats.latecol;
3263 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3264 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3265 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3267 /* Tx Dropped needs to be maintained elsewhere */
3271 if (hw->media_type == e1000_media_type_copper) {
3272 if ((adapter->link_speed == SPEED_1000) &&
3273 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3274 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3275 adapter->phy_stats.idle_errors += phy_tmp;
3278 if ((hw->mac_type <= e1000_82546) &&
3279 (hw->phy_type == e1000_phy_m88) &&
3280 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3281 adapter->phy_stats.receive_errors += phy_tmp;
3284 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3287 #ifdef CONFIG_E1000_MQ
3289 e1000_rx_schedule(void *data)
3291 struct net_device *poll_dev, *netdev = data;
3292 struct e1000_adapter *adapter = netdev->priv;
3293 int this_cpu = get_cpu();
3295 poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
3296 if (poll_dev == NULL) {
3301 if (likely(netif_rx_schedule_prep(poll_dev)))
3302 __netif_rx_schedule(poll_dev);
3304 e1000_irq_enable(adapter);
3311 * e1000_intr - Interrupt Handler
3312 * @irq: interrupt number
3313 * @data: pointer to a network interface device structure
3314 * @pt_regs: CPU registers structure
3318 e1000_intr(int irq, void *data, struct pt_regs *regs)
3320 struct net_device *netdev = data;
3321 struct e1000_adapter *adapter = netdev_priv(netdev);
3322 struct e1000_hw *hw = &adapter->hw;
3323 uint32_t icr = E1000_READ_REG(hw, ICR);
3324 #ifndef CONFIG_E1000_NAPI
3327 /* Interrupt Auto-Mask...upon reading ICR,
3328 * interrupts are masked. No need for the
3329 * IMC write, but it does mean we should
3330 * account for it ASAP. */
3331 if (likely(hw->mac_type >= e1000_82571))
3332 atomic_inc(&adapter->irq_sem);
3335 if (unlikely(!icr)) {
3336 #ifdef CONFIG_E1000_NAPI
3337 if (hw->mac_type >= e1000_82571)
3338 e1000_irq_enable(adapter);
3340 return IRQ_NONE; /* Not our interrupt */
3343 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3344 hw->get_link_status = 1;
3345 mod_timer(&adapter->watchdog_timer, jiffies);
3348 #ifdef CONFIG_E1000_NAPI
3349 if (unlikely(hw->mac_type < e1000_82571)) {
3350 atomic_inc(&adapter->irq_sem);
3351 E1000_WRITE_REG(hw, IMC, ~0);
3352 E1000_WRITE_FLUSH(hw);
3354 #ifdef CONFIG_E1000_MQ
3355 if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
3356 /* We must setup the cpumask once count == 0 since
3357 * each cpu bit is cleared when the work is done. */
3358 adapter->rx_sched_call_data.cpumask = adapter->cpumask;
3359 atomic_add(adapter->num_rx_queues - 1, &adapter->irq_sem);
3360 atomic_set(&adapter->rx_sched_call_data.count,
3361 adapter->num_rx_queues);
3362 smp_call_async_mask(&adapter->rx_sched_call_data);
3364 printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
3366 #else /* if !CONFIG_E1000_MQ */
3367 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3368 __netif_rx_schedule(&adapter->polling_netdev[0]);
3370 e1000_irq_enable(adapter);
3371 #endif /* CONFIG_E1000_MQ */
3373 #else /* if !CONFIG_E1000_NAPI */
3374 /* Writing IMC and IMS is needed for 82547.
3375 * Due to Hub Link bus being occupied, an interrupt
3376 * de-assertion message is not able to be sent.
3377 * When an interrupt assertion message is generated later,
3378 * two messages are re-ordered and sent out.
3379 * That causes APIC to think 82547 is in de-assertion
3380 * state, while 82547 is in assertion state, resulting
3381 * in dead lock. Writing IMC forces 82547 into
3382 * de-assertion state.
3384 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
3385 atomic_inc(&adapter->irq_sem);
3386 E1000_WRITE_REG(hw, IMC, ~0);
3389 for (i = 0; i < E1000_MAX_INTR; i++)
3390 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3391 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3394 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3395 e1000_irq_enable(adapter);
3397 #endif /* CONFIG_E1000_NAPI */
3402 #ifdef CONFIG_E1000_NAPI
3404 * e1000_clean - NAPI Rx polling callback
3405 * @adapter: board private structure
3409 e1000_clean(struct net_device *poll_dev, int *budget)
3411 struct e1000_adapter *adapter;
3412 int work_to_do = min(*budget, poll_dev->quota);
3413 int tx_cleaned = 0, i = 0, work_done = 0;
3415 /* Must NOT use netdev_priv macro here. */
3416 adapter = poll_dev->priv;
3418 /* Keep link state information with original netdev */
3419 if (!netif_carrier_ok(adapter->netdev))
3422 while (poll_dev != &adapter->polling_netdev[i]) {
3424 if (unlikely(i == adapter->num_rx_queues))
3428 if (likely(adapter->num_tx_queues == 1)) {
3429 /* e1000_clean is called per-cpu. This lock protects
3430 * tx_ring[0] from being cleaned by multiple cpus
3431 * simultaneously. A failure obtaining the lock means
3432 * tx_ring[0] is currently being cleaned anyway. */
3433 if (spin_trylock(&adapter->tx_queue_lock)) {
3434 tx_cleaned = e1000_clean_tx_irq(adapter,
3435 &adapter->tx_ring[0]);
3436 spin_unlock(&adapter->tx_queue_lock);
3439 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3441 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3442 &work_done, work_to_do);
3444 *budget -= work_done;
3445 poll_dev->quota -= work_done;
3447 /* If no Tx and not enough Rx work done, exit the polling mode */
3448 if ((!tx_cleaned && (work_done == 0)) ||
3449 !netif_running(adapter->netdev)) {
3451 netif_rx_complete(poll_dev);
3452 e1000_irq_enable(adapter);
3461 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3462 * @adapter: board private structure
3466 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3467 struct e1000_tx_ring *tx_ring)
3469 struct net_device *netdev = adapter->netdev;
3470 struct e1000_tx_desc *tx_desc, *eop_desc;
3471 struct e1000_buffer *buffer_info;
3472 unsigned int i, eop;
3473 boolean_t cleaned = FALSE;
3475 i = tx_ring->next_to_clean;
3476 eop = tx_ring->buffer_info[i].next_to_watch;
3477 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3479 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3480 for (cleaned = FALSE; !cleaned; ) {
3481 tx_desc = E1000_TX_DESC(*tx_ring, i);
3482 buffer_info = &tx_ring->buffer_info[i];
3483 cleaned = (i == eop);
3485 #ifdef CONFIG_E1000_MQ
3486 tx_ring->tx_stats.bytes += buffer_info->length;
3488 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3489 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
3491 if (unlikely(++i == tx_ring->count)) i = 0;
3494 #ifdef CONFIG_E1000_MQ
3495 tx_ring->tx_stats.packets++;
3498 eop = tx_ring->buffer_info[i].next_to_watch;
3499 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3502 tx_ring->next_to_clean = i;
3504 spin_lock(&tx_ring->tx_lock);
3506 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
3507 netif_carrier_ok(netdev)))
3508 netif_wake_queue(netdev);
3510 spin_unlock(&tx_ring->tx_lock);
3512 if (adapter->detect_tx_hung) {
3513 /* Detect a transmit hang in hardware, this serializes the
3514 * check with the clearing of time_stamp and movement of i */
3515 adapter->detect_tx_hung = FALSE;
3516 if (tx_ring->buffer_info[eop].dma &&
3517 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3518 adapter->tx_timeout_factor * HZ)
3519 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3520 E1000_STATUS_TXOFF)) {
3522 /* detected Tx unit hang */
3523 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3527 " next_to_use <%x>\n"
3528 " next_to_clean <%x>\n"
3529 "buffer_info[next_to_clean]\n"
3530 " time_stamp <%lx>\n"
3531 " next_to_watch <%x>\n"
3533 " next_to_watch.status <%x>\n",
3534 (unsigned long)((tx_ring - adapter->tx_ring) /
3535 sizeof(struct e1000_tx_ring)),
3536 readl(adapter->hw.hw_addr + tx_ring->tdh),
3537 readl(adapter->hw.hw_addr + tx_ring->tdt),
3538 tx_ring->next_to_use,
3539 tx_ring->next_to_clean,
3540 tx_ring->buffer_info[eop].time_stamp,
3543 eop_desc->upper.fields.status);
3544 netif_stop_queue(netdev);
3551 * e1000_rx_checksum - Receive Checksum Offload for 82543
3552 * @adapter: board private structure
3553 * @status_err: receive descriptor status and error fields
3554 * @csum: receive descriptor csum field
3555 * @sk_buff: socket buffer with received data
3559 e1000_rx_checksum(struct e1000_adapter *adapter,
3560 uint32_t status_err, uint32_t csum,
3561 struct sk_buff *skb)
3563 uint16_t status = (uint16_t)status_err;
3564 uint8_t errors = (uint8_t)(status_err >> 24);
3565 skb->ip_summed = CHECKSUM_NONE;
3567 /* 82543 or newer only */
3568 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
3569 /* Ignore Checksum bit is set */
3570 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3571 /* TCP/UDP checksum error bit is set */
3572 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3573 /* let the stack verify checksum errors */
3574 adapter->hw_csum_err++;
3577 /* TCP/UDP Checksum has not been calculated */
3578 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3579 if (!(status & E1000_RXD_STAT_TCPCS))
3582 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3585 /* It must be a TCP or UDP packet with a valid checksum */
3586 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3587 /* TCP checksum is good */
3588 skb->ip_summed = CHECKSUM_UNNECESSARY;
3589 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3590 /* IP fragment with UDP payload */
3591 /* Hardware complements the payload checksum, so we undo it
3592 * and then put the value in host order for further stack use.
3594 csum = ntohl(csum ^ 0xFFFF);
3596 skb->ip_summed = CHECKSUM_HW;
3598 adapter->hw_csum_good++;
3602 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3603 * @adapter: board private structure
3607 #ifdef CONFIG_E1000_NAPI
3608 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3609 struct e1000_rx_ring *rx_ring,
3610 int *work_done, int work_to_do)
3612 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3613 struct e1000_rx_ring *rx_ring)
3616 struct net_device *netdev = adapter->netdev;
3617 struct pci_dev *pdev = adapter->pdev;
3618 struct e1000_rx_desc *rx_desc;
3619 struct e1000_buffer *buffer_info;
3620 unsigned long flags;
3624 int cleaned_count = 0;
3625 boolean_t cleaned = FALSE, multi_descriptor = FALSE;
3627 i = rx_ring->next_to_clean;
3628 rx_desc = E1000_RX_DESC(*rx_ring, i);
3629 buffer_info = &rx_ring->buffer_info[i];
3631 while (rx_desc->status & E1000_RXD_STAT_DD) {
3632 struct sk_buff *skb;
3634 #ifdef CONFIG_E1000_NAPI
3635 if (*work_done >= work_to_do)
3639 status = rx_desc->status;
3640 skb = buffer_info->skb;
3643 pci_unmap_single(pdev,
3645 buffer_info->length,
3646 PCI_DMA_FROMDEVICE);
3648 length = le16_to_cpu(rx_desc->length);
3650 skb_put(skb, length);
3652 if (!(status & E1000_RXD_STAT_EOP)) {
3653 if (!rx_ring->rx_skb_top) {
3654 rx_ring->rx_skb_top = skb;
3655 rx_ring->rx_skb_top->len = length;
3656 rx_ring->rx_skb_prev = skb;
3658 if (skb_shinfo(rx_ring->rx_skb_top)->frag_list) {
3659 rx_ring->rx_skb_prev->next = skb;
3660 skb->prev = rx_ring->rx_skb_prev;
3662 skb_shinfo(rx_ring->rx_skb_top)->frag_list = skb;
3664 rx_ring->rx_skb_prev = skb;
3665 rx_ring->rx_skb_top->data_len += length;
3669 if (rx_ring->rx_skb_top) {
3670 if (skb_shinfo(rx_ring->rx_skb_top)
3672 rx_ring->rx_skb_prev->next = skb;
3673 skb->prev = rx_ring->rx_skb_prev;
3675 skb_shinfo(rx_ring->rx_skb_top)
3678 rx_ring->rx_skb_top->data_len += length;
3679 rx_ring->rx_skb_top->len +=
3680 rx_ring->rx_skb_top->data_len;
3682 skb = rx_ring->rx_skb_top;
3683 multi_descriptor = TRUE;
3684 rx_ring->rx_skb_top = NULL;
3685 rx_ring->rx_skb_prev = NULL;
3689 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3690 last_byte = *(skb->data + length - 1);
3691 if (TBI_ACCEPT(&adapter->hw, status,
3692 rx_desc->errors, length, last_byte)) {
3693 spin_lock_irqsave(&adapter->stats_lock, flags);
3694 e1000_tbi_adjust_stats(&adapter->hw,
3697 spin_unlock_irqrestore(&adapter->stats_lock,
3701 dev_kfree_skb_irq(skb);
3706 /* code added for copybreak, this should improve
3707 * performance for small packets with large amounts
3708 * of reassembly being done in the stack */
3709 #define E1000_CB_LENGTH 256
3710 if ((length < E1000_CB_LENGTH) &&
3711 !rx_ring->rx_skb_top &&
3712 /* or maybe (status & E1000_RXD_STAT_EOP) && */
3713 !multi_descriptor) {
3714 struct sk_buff *new_skb =
3715 dev_alloc_skb(length + NET_IP_ALIGN);
3717 skb_reserve(new_skb, NET_IP_ALIGN);
3718 new_skb->dev = netdev;
3719 memcpy(new_skb->data - NET_IP_ALIGN,
3720 skb->data - NET_IP_ALIGN,
3721 length + NET_IP_ALIGN);
3722 /* save the skb in buffer_info as good */
3723 buffer_info->skb = skb;
3725 skb_put(skb, length);
3729 /* end copybreak code */
3731 /* Receive Checksum Offload */
3732 e1000_rx_checksum(adapter,
3733 (uint32_t)(status) |
3734 ((uint32_t)(rx_desc->errors) << 24),
3735 rx_desc->csum, skb);
3737 skb->protocol = eth_type_trans(skb, netdev);
3738 #ifdef CONFIG_E1000_NAPI
3739 if (unlikely(adapter->vlgrp &&
3740 (status & E1000_RXD_STAT_VP))) {
3741 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3742 le16_to_cpu(rx_desc->special) &
3743 E1000_RXD_SPC_VLAN_MASK);
3745 netif_receive_skb(skb);
3747 #else /* CONFIG_E1000_NAPI */
3748 if (unlikely(adapter->vlgrp &&
3749 (status & E1000_RXD_STAT_VP))) {
3750 vlan_hwaccel_rx(skb, adapter->vlgrp,
3751 le16_to_cpu(rx_desc->special) &
3752 E1000_RXD_SPC_VLAN_MASK);
3756 #endif /* CONFIG_E1000_NAPI */
3757 netdev->last_rx = jiffies;
3758 #ifdef CONFIG_E1000_MQ
3759 rx_ring->rx_stats.packets++;
3760 rx_ring->rx_stats.bytes += length;
3764 rx_desc->status = 0;
3766 /* return some buffers to hardware, one at a time is too slow */
3767 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3768 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3773 rx_ring->next_to_clean = i;
3775 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3777 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3783 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3784 * @adapter: board private structure
3788 #ifdef CONFIG_E1000_NAPI
3789 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3790 struct e1000_rx_ring *rx_ring,
3791 int *work_done, int work_to_do)
3793 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3794 struct e1000_rx_ring *rx_ring)
3797 union e1000_rx_desc_packet_split *rx_desc;
3798 struct net_device *netdev = adapter->netdev;
3799 struct pci_dev *pdev = adapter->pdev;
3800 struct e1000_buffer *buffer_info;
3801 struct e1000_ps_page *ps_page;
3802 struct e1000_ps_page_dma *ps_page_dma;
3803 struct sk_buff *skb;
3805 uint32_t length, staterr;
3806 int cleaned_count = 0;
3807 boolean_t cleaned = FALSE;
3809 i = rx_ring->next_to_clean;
3810 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3811 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3813 while (staterr & E1000_RXD_STAT_DD) {
3814 buffer_info = &rx_ring->buffer_info[i];
3815 ps_page = &rx_ring->ps_page[i];
3816 ps_page_dma = &rx_ring->ps_page_dma[i];
3817 #ifdef CONFIG_E1000_NAPI
3818 if (unlikely(*work_done >= work_to_do))
3824 pci_unmap_single(pdev, buffer_info->dma,
3825 buffer_info->length,
3826 PCI_DMA_FROMDEVICE);
3828 skb = buffer_info->skb;
3830 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3831 E1000_DBG("%s: Packet Split buffers didn't pick up"
3832 " the full packet\n", netdev->name);
3833 dev_kfree_skb_irq(skb);
3837 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3838 dev_kfree_skb_irq(skb);
3842 length = le16_to_cpu(rx_desc->wb.middle.length0);
3844 if (unlikely(!length)) {
3845 E1000_DBG("%s: Last part of the packet spanning"
3846 " multiple descriptors\n", netdev->name);
3847 dev_kfree_skb_irq(skb);
3852 skb_put(skb, length);
3854 for (j = 0; j < adapter->rx_ps_pages; j++) {
3855 if (!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3858 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3859 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3860 ps_page_dma->ps_page_dma[j] = 0;
3861 skb_shinfo(skb)->frags[j].page =
3862 ps_page->ps_page[j];
3863 ps_page->ps_page[j] = NULL;
3864 skb_shinfo(skb)->frags[j].page_offset = 0;
3865 skb_shinfo(skb)->frags[j].size = length;
3866 skb_shinfo(skb)->nr_frags++;
3868 skb->data_len += length;
3871 e1000_rx_checksum(adapter, staterr,
3872 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3873 skb->protocol = eth_type_trans(skb, netdev);
3875 if (likely(rx_desc->wb.upper.header_status &
3876 E1000_RXDPS_HDRSTAT_HDRSP))
3877 adapter->rx_hdr_split++;
3878 #ifdef CONFIG_E1000_NAPI
3879 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3880 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3881 le16_to_cpu(rx_desc->wb.middle.vlan) &
3882 E1000_RXD_SPC_VLAN_MASK);
3884 netif_receive_skb(skb);
3886 #else /* CONFIG_E1000_NAPI */
3887 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3888 vlan_hwaccel_rx(skb, adapter->vlgrp,
3889 le16_to_cpu(rx_desc->wb.middle.vlan) &
3890 E1000_RXD_SPC_VLAN_MASK);
3894 #endif /* CONFIG_E1000_NAPI */
3895 netdev->last_rx = jiffies;
3896 #ifdef CONFIG_E1000_MQ
3897 rx_ring->rx_stats.packets++;
3898 rx_ring->rx_stats.bytes += length;
3902 rx_desc->wb.middle.status_error &= ~0xFF;
3903 buffer_info->skb = NULL;
3905 /* return some buffers to hardware, one at a time is too slow */
3906 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3907 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3911 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3913 rx_ring->next_to_clean = i;
3915 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3917 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3923 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3924 * @adapter: address of board private structure
3928 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3929 struct e1000_rx_ring *rx_ring,
3932 struct net_device *netdev = adapter->netdev;
3933 struct pci_dev *pdev = adapter->pdev;
3934 struct e1000_rx_desc *rx_desc;
3935 struct e1000_buffer *buffer_info;
3936 struct sk_buff *skb;
3938 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3940 i = rx_ring->next_to_use;
3941 buffer_info = &rx_ring->buffer_info[i];
3943 while (cleaned_count--) {
3944 if (!(skb = buffer_info->skb))
3945 skb = dev_alloc_skb(bufsz);
3952 if (unlikely(!skb)) {
3953 /* Better luck next round */
3954 adapter->alloc_rx_buff_failed++;
3958 /* Fix for errata 23, can't cross 64kB boundary */
3959 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3960 struct sk_buff *oldskb = skb;
3961 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3962 "at %p\n", bufsz, skb->data);
3963 /* Try again, without freeing the previous */
3964 skb = dev_alloc_skb(bufsz);
3965 /* Failed allocation, critical failure */
3967 dev_kfree_skb(oldskb);
3971 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3974 dev_kfree_skb(oldskb);
3975 break; /* while !buffer_info->skb */
3977 /* Use new allocation */
3978 dev_kfree_skb(oldskb);
3981 /* Make buffer alignment 2 beyond a 16 byte boundary
3982 * this will result in a 16 byte aligned IP header after
3983 * the 14 byte MAC header is removed
3985 skb_reserve(skb, NET_IP_ALIGN);
3989 buffer_info->skb = skb;
3990 buffer_info->length = adapter->rx_buffer_len;
3992 buffer_info->dma = pci_map_single(pdev,
3994 adapter->rx_buffer_len,
3995 PCI_DMA_FROMDEVICE);
3997 /* Fix for errata 23, can't cross 64kB boundary */
3998 if (!e1000_check_64k_bound(adapter,
3999 (void *)(unsigned long)buffer_info->dma,
4000 adapter->rx_buffer_len)) {
4001 DPRINTK(RX_ERR, ERR,
4002 "dma align check failed: %u bytes at %p\n",
4003 adapter->rx_buffer_len,
4004 (void *)(unsigned long)buffer_info->dma);
4006 buffer_info->skb = NULL;
4008 pci_unmap_single(pdev, buffer_info->dma,
4009 adapter->rx_buffer_len,
4010 PCI_DMA_FROMDEVICE);
4012 break; /* while !buffer_info->skb */
4014 rx_desc = E1000_RX_DESC(*rx_ring, i);
4015 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4017 if (unlikely(++i == rx_ring->count))
4019 buffer_info = &rx_ring->buffer_info[i];
4022 if (likely(rx_ring->next_to_use != i)) {
4023 rx_ring->next_to_use = i;
4024 if (unlikely(i-- == 0))
4025 i = (rx_ring->count - 1);
4027 /* Force memory writes to complete before letting h/w
4028 * know there are new descriptors to fetch. (Only
4029 * applicable for weak-ordered memory model archs,
4030 * such as IA-64). */
4032 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4037 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4038 * @adapter: address of board private structure
4042 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
4043 struct e1000_rx_ring *rx_ring,
4046 struct net_device *netdev = adapter->netdev;
4047 struct pci_dev *pdev = adapter->pdev;
4048 union e1000_rx_desc_packet_split *rx_desc;
4049 struct e1000_buffer *buffer_info;
4050 struct e1000_ps_page *ps_page;
4051 struct e1000_ps_page_dma *ps_page_dma;
4052 struct sk_buff *skb;
4055 i = rx_ring->next_to_use;
4056 buffer_info = &rx_ring->buffer_info[i];
4057 ps_page = &rx_ring->ps_page[i];
4058 ps_page_dma = &rx_ring->ps_page_dma[i];
4060 while (cleaned_count--) {
4061 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4063 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
4064 if (j < adapter->rx_ps_pages) {
4065 if (likely(!ps_page->ps_page[j])) {
4066 ps_page->ps_page[j] =
4067 alloc_page(GFP_ATOMIC);
4068 if (unlikely(!ps_page->ps_page[j])) {
4069 adapter->alloc_rx_buff_failed++;
4072 ps_page_dma->ps_page_dma[j] =
4074 ps_page->ps_page[j],
4076 PCI_DMA_FROMDEVICE);
4078 /* Refresh the desc even if buffer_addrs didn't
4079 * change because each write-back erases
4082 rx_desc->read.buffer_addr[j+1] =
4083 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4085 rx_desc->read.buffer_addr[j+1] = ~0;
4088 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4090 if (unlikely(!skb)) {
4091 adapter->alloc_rx_buff_failed++;
4095 /* Make buffer alignment 2 beyond a 16 byte boundary
4096 * this will result in a 16 byte aligned IP header after
4097 * the 14 byte MAC header is removed
4099 skb_reserve(skb, NET_IP_ALIGN);
4103 buffer_info->skb = skb;
4104 buffer_info->length = adapter->rx_ps_bsize0;
4105 buffer_info->dma = pci_map_single(pdev, skb->data,
4106 adapter->rx_ps_bsize0,
4107 PCI_DMA_FROMDEVICE);
4109 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4111 if (unlikely(++i == rx_ring->count)) i = 0;
4112 buffer_info = &rx_ring->buffer_info[i];
4113 ps_page = &rx_ring->ps_page[i];
4114 ps_page_dma = &rx_ring->ps_page_dma[i];
4118 if (likely(rx_ring->next_to_use != i)) {
4119 rx_ring->next_to_use = i;
4120 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4122 /* Force memory writes to complete before letting h/w
4123 * know there are new descriptors to fetch. (Only
4124 * applicable for weak-ordered memory model archs,
4125 * such as IA-64). */
4127 /* Hardware increments by 16 bytes, but packet split
4128 * descriptors are 32 bytes...so we increment tail
4131 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4136 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4141 e1000_smartspeed(struct e1000_adapter *adapter)
4143 uint16_t phy_status;
4146 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4147 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4150 if (adapter->smartspeed == 0) {
4151 /* If Master/Slave config fault is asserted twice,
4152 * we assume back-to-back */
4153 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4154 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4155 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4156 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4157 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4158 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4159 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4160 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4162 adapter->smartspeed++;
4163 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4164 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4166 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4167 MII_CR_RESTART_AUTO_NEG);
4168 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4173 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4174 /* If still no link, perhaps using 2/3 pair cable */
4175 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4176 phy_ctrl |= CR_1000T_MS_ENABLE;
4177 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4178 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4179 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4180 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4181 MII_CR_RESTART_AUTO_NEG);
4182 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4185 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4186 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4187 adapter->smartspeed = 0;
4198 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4204 return e1000_mii_ioctl(netdev, ifr, cmd);
4218 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4220 struct e1000_adapter *adapter = netdev_priv(netdev);
4221 struct mii_ioctl_data *data = if_mii(ifr);
4225 unsigned long flags;
4227 if (adapter->hw.media_type != e1000_media_type_copper)
4232 data->phy_id = adapter->hw.phy_addr;
4235 if (!capable(CAP_NET_ADMIN))
4237 spin_lock_irqsave(&adapter->stats_lock, flags);
4238 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4240 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4243 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4246 if (!capable(CAP_NET_ADMIN))
4248 if (data->reg_num & ~(0x1F))
4250 mii_reg = data->val_in;
4251 spin_lock_irqsave(&adapter->stats_lock, flags);
4252 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
4254 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4257 if (adapter->hw.phy_type == e1000_phy_m88) {
4258 switch (data->reg_num) {
4260 if (mii_reg & MII_CR_POWER_DOWN)
4262 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4263 adapter->hw.autoneg = 1;
4264 adapter->hw.autoneg_advertised = 0x2F;
4267 spddplx = SPEED_1000;
4268 else if (mii_reg & 0x2000)
4269 spddplx = SPEED_100;
4272 spddplx += (mii_reg & 0x100)
4275 retval = e1000_set_spd_dplx(adapter,
4278 spin_unlock_irqrestore(
4279 &adapter->stats_lock,
4284 if (netif_running(adapter->netdev)) {
4285 e1000_down(adapter);
4288 e1000_reset(adapter);
4290 case M88E1000_PHY_SPEC_CTRL:
4291 case M88E1000_EXT_PHY_SPEC_CTRL:
4292 if (e1000_phy_reset(&adapter->hw)) {
4293 spin_unlock_irqrestore(
4294 &adapter->stats_lock, flags);
4300 switch (data->reg_num) {
4302 if (mii_reg & MII_CR_POWER_DOWN)
4304 if (netif_running(adapter->netdev)) {
4305 e1000_down(adapter);
4308 e1000_reset(adapter);
4312 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4317 return E1000_SUCCESS;
4321 e1000_pci_set_mwi(struct e1000_hw *hw)
4323 struct e1000_adapter *adapter = hw->back;
4324 int ret_val = pci_set_mwi(adapter->pdev);
4327 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4331 e1000_pci_clear_mwi(struct e1000_hw *hw)
4333 struct e1000_adapter *adapter = hw->back;
4335 pci_clear_mwi(adapter->pdev);
4339 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4341 struct e1000_adapter *adapter = hw->back;
4343 pci_read_config_word(adapter->pdev, reg, value);
4347 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4349 struct e1000_adapter *adapter = hw->back;
4351 pci_write_config_word(adapter->pdev, reg, *value);
4355 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4361 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4367 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4369 struct e1000_adapter *adapter = netdev_priv(netdev);
4370 uint32_t ctrl, rctl;
4372 e1000_irq_disable(adapter);
4373 adapter->vlgrp = grp;
4376 /* enable VLAN tag insert/strip */
4377 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4378 ctrl |= E1000_CTRL_VME;
4379 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4381 /* enable VLAN receive filtering */
4382 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4383 rctl |= E1000_RCTL_VFE;
4384 rctl &= ~E1000_RCTL_CFIEN;
4385 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4386 e1000_update_mng_vlan(adapter);
4388 /* disable VLAN tag insert/strip */
4389 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4390 ctrl &= ~E1000_CTRL_VME;
4391 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4393 /* disable VLAN filtering */
4394 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4395 rctl &= ~E1000_RCTL_VFE;
4396 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4397 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4398 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4399 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4403 e1000_irq_enable(adapter);
4407 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4409 struct e1000_adapter *adapter = netdev_priv(netdev);
4410 uint32_t vfta, index;
4412 if ((adapter->hw.mng_cookie.status &
4413 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4414 (vid == adapter->mng_vlan_id))
4416 /* add VID to filter table */
4417 index = (vid >> 5) & 0x7F;
4418 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4419 vfta |= (1 << (vid & 0x1F));
4420 e1000_write_vfta(&adapter->hw, index, vfta);
4424 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4426 struct e1000_adapter *adapter = netdev_priv(netdev);
4427 uint32_t vfta, index;
4429 e1000_irq_disable(adapter);
4432 adapter->vlgrp->vlan_devices[vid] = NULL;
4434 e1000_irq_enable(adapter);
4436 if ((adapter->hw.mng_cookie.status &
4437 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4438 (vid == adapter->mng_vlan_id)) {
4439 /* release control to f/w */
4440 e1000_release_hw_control(adapter);
4444 /* remove VID from filter table */
4445 index = (vid >> 5) & 0x7F;
4446 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4447 vfta &= ~(1 << (vid & 0x1F));
4448 e1000_write_vfta(&adapter->hw, index, vfta);
4452 e1000_restore_vlan(struct e1000_adapter *adapter)
4454 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4456 if (adapter->vlgrp) {
4458 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4459 if (!adapter->vlgrp->vlan_devices[vid])
4461 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4467 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4469 adapter->hw.autoneg = 0;
4471 /* Fiber NICs only allow 1000 gbps Full duplex */
4472 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
4473 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4474 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4479 case SPEED_10 + DUPLEX_HALF:
4480 adapter->hw.forced_speed_duplex = e1000_10_half;
4482 case SPEED_10 + DUPLEX_FULL:
4483 adapter->hw.forced_speed_duplex = e1000_10_full;
4485 case SPEED_100 + DUPLEX_HALF:
4486 adapter->hw.forced_speed_duplex = e1000_100_half;
4488 case SPEED_100 + DUPLEX_FULL:
4489 adapter->hw.forced_speed_duplex = e1000_100_full;
4491 case SPEED_1000 + DUPLEX_FULL:
4492 adapter->hw.autoneg = 1;
4493 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4495 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4497 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4504 /* these functions save and restore 16 or 64 dwords (64-256 bytes) of config
4505 * space versus the 64 bytes that pci_[save|restore]_state handle
4507 #define PCIE_CONFIG_SPACE_LEN 256
4508 #define PCI_CONFIG_SPACE_LEN 64
4510 e1000_pci_save_state(struct e1000_adapter *adapter)
4512 struct pci_dev *dev = adapter->pdev;
4515 if (adapter->hw.mac_type >= e1000_82571)
4516 size = PCIE_CONFIG_SPACE_LEN;
4518 size = PCI_CONFIG_SPACE_LEN;
4520 WARN_ON(adapter->config_space != NULL);
4522 adapter->config_space = kmalloc(size, GFP_KERNEL);
4523 if (!adapter->config_space) {
4524 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4527 for (i = 0; i < (size / 4); i++)
4528 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4533 e1000_pci_restore_state(struct e1000_adapter *adapter)
4535 struct pci_dev *dev = adapter->pdev;
4538 if (adapter->config_space == NULL)
4540 if (adapter->hw.mac_type >= e1000_82571)
4541 size = PCIE_CONFIG_SPACE_LEN;
4543 size = PCI_CONFIG_SPACE_LEN;
4544 for (i = 0; i < (size / 4); i++)
4545 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4546 kfree(adapter->config_space);
4547 adapter->config_space = NULL;
4550 #endif /* CONFIG_PM */
4553 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4555 struct net_device *netdev = pci_get_drvdata(pdev);
4556 struct e1000_adapter *adapter = netdev_priv(netdev);
4557 uint32_t ctrl, ctrl_ext, rctl, manc, status;
4558 uint32_t wufc = adapter->wol;
4561 netif_device_detach(netdev);
4563 if (netif_running(netdev))
4564 e1000_down(adapter);
4567 /* implement our own version of pci_save_state(pdev) because pci
4568 * express adapters have larger 256 byte config spaces */
4569 retval = e1000_pci_save_state(adapter);
4574 status = E1000_READ_REG(&adapter->hw, STATUS);
4575 if (status & E1000_STATUS_LU)
4576 wufc &= ~E1000_WUFC_LNKC;
4579 e1000_setup_rctl(adapter);
4580 e1000_set_multi(netdev);
4582 /* turn on all-multi mode if wake on multicast is enabled */
4583 if (adapter->wol & E1000_WUFC_MC) {
4584 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4585 rctl |= E1000_RCTL_MPE;
4586 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4589 if (adapter->hw.mac_type >= e1000_82540) {
4590 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4591 /* advertise wake from D3Cold */
4592 #define E1000_CTRL_ADVD3WUC 0x00100000
4593 /* phy power management enable */
4594 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4595 ctrl |= E1000_CTRL_ADVD3WUC |
4596 E1000_CTRL_EN_PHY_PWR_MGMT;
4597 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4600 if (adapter->hw.media_type == e1000_media_type_fiber ||
4601 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4602 /* keep the laser running in D3 */
4603 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4604 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4605 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4608 /* Allow time for pending master requests to run */
4609 e1000_disable_pciex_master(&adapter->hw);
4611 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4612 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4613 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4615 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4616 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4618 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4620 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4621 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4622 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4624 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4625 retval = pci_enable_wake(pdev, PCI_D3cold, 0); /* 4 == D3 cold */
4627 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4630 if (adapter->hw.mac_type >= e1000_82540 &&
4631 adapter->hw.media_type == e1000_media_type_copper) {
4632 manc = E1000_READ_REG(&adapter->hw, MANC);
4633 if (manc & E1000_MANC_SMBUS_EN) {
4634 manc |= E1000_MANC_ARP_EN;
4635 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4636 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4638 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4639 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4641 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4645 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4646 * would have already happened in close and is redundant. */
4647 e1000_release_hw_control(adapter);
4649 pci_disable_device(pdev);
4651 retval = pci_set_power_state(pdev, pci_choose_state(pdev, state));
4653 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4660 e1000_resume(struct pci_dev *pdev)
4662 struct net_device *netdev = pci_get_drvdata(pdev);
4663 struct e1000_adapter *adapter = netdev_priv(netdev);
4665 uint32_t manc, ret_val;
4667 retval = pci_set_power_state(pdev, PCI_D0);
4669 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4670 e1000_pci_restore_state(adapter);
4671 ret_val = pci_enable_device(pdev);
4672 pci_set_master(pdev);
4674 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4676 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4677 retval = pci_enable_wake(pdev, PCI_D3cold, 0);
4679 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4681 e1000_reset(adapter);
4682 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4684 if (netif_running(netdev))
4687 netif_device_attach(netdev);
4689 if (adapter->hw.mac_type >= e1000_82540 &&
4690 adapter->hw.media_type == e1000_media_type_copper) {
4691 manc = E1000_READ_REG(&adapter->hw, MANC);
4692 manc &= ~(E1000_MANC_ARP_EN);
4693 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4696 /* If the controller is 82573 and f/w is AMT, do not set
4697 * DRV_LOAD until the interface is up. For all other cases,
4698 * let the f/w know that the h/w is now under the control
4700 if (adapter->hw.mac_type != e1000_82573 ||
4701 !e1000_check_mng_mode(&adapter->hw))
4702 e1000_get_hw_control(adapter);
4707 #ifdef CONFIG_NET_POLL_CONTROLLER
4709 * Polling 'interrupt' - used by things like netconsole to send skbs
4710 * without having to re-enable interrupts. It's not called while
4711 * the interrupt routine is executing.
4714 e1000_netpoll(struct net_device *netdev)
4716 struct e1000_adapter *adapter = netdev_priv(netdev);
4717 disable_irq(adapter->pdev->irq);
4718 e1000_intr(adapter->pdev->irq, netdev, NULL);
4719 e1000_clean_tx_irq(adapter, adapter->tx_ring);
4720 #ifndef CONFIG_E1000_NAPI
4721 adapter->clean_rx(adapter, adapter->rx_ring);
4723 enable_irq(adapter->pdev->irq);