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 Fixed ethtool diagnostics
93 * o Enabled flow control to take default eeprom settings
94 * o Added stats_lock around e1000_read_phy_reg commands to avoid concurrent
95 * calls, one from mii_ioctl and other from within update_stats while
96 * processing MIIREG ioctl.
99 char e1000_driver_name[] = "e1000";
100 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
101 #ifndef CONFIG_E1000_NAPI
104 #define DRIVERNAPI "-NAPI"
106 #define DRV_VERSION "6.3.9-k4"DRIVERNAPI
107 char e1000_driver_version[] = DRV_VERSION;
108 static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
110 /* e1000_pci_tbl - PCI Device ID Table
112 * Last entry must be all 0s
114 * Macro expands to...
115 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
117 static struct pci_device_id e1000_pci_tbl[] = {
118 INTEL_E1000_ETHERNET_DEVICE(0x1000),
119 INTEL_E1000_ETHERNET_DEVICE(0x1001),
120 INTEL_E1000_ETHERNET_DEVICE(0x1004),
121 INTEL_E1000_ETHERNET_DEVICE(0x1008),
122 INTEL_E1000_ETHERNET_DEVICE(0x1009),
123 INTEL_E1000_ETHERNET_DEVICE(0x100C),
124 INTEL_E1000_ETHERNET_DEVICE(0x100D),
125 INTEL_E1000_ETHERNET_DEVICE(0x100E),
126 INTEL_E1000_ETHERNET_DEVICE(0x100F),
127 INTEL_E1000_ETHERNET_DEVICE(0x1010),
128 INTEL_E1000_ETHERNET_DEVICE(0x1011),
129 INTEL_E1000_ETHERNET_DEVICE(0x1012),
130 INTEL_E1000_ETHERNET_DEVICE(0x1013),
131 INTEL_E1000_ETHERNET_DEVICE(0x1014),
132 INTEL_E1000_ETHERNET_DEVICE(0x1015),
133 INTEL_E1000_ETHERNET_DEVICE(0x1016),
134 INTEL_E1000_ETHERNET_DEVICE(0x1017),
135 INTEL_E1000_ETHERNET_DEVICE(0x1018),
136 INTEL_E1000_ETHERNET_DEVICE(0x1019),
137 INTEL_E1000_ETHERNET_DEVICE(0x101A),
138 INTEL_E1000_ETHERNET_DEVICE(0x101D),
139 INTEL_E1000_ETHERNET_DEVICE(0x101E),
140 INTEL_E1000_ETHERNET_DEVICE(0x1026),
141 INTEL_E1000_ETHERNET_DEVICE(0x1027),
142 INTEL_E1000_ETHERNET_DEVICE(0x1028),
143 INTEL_E1000_ETHERNET_DEVICE(0x105E),
144 INTEL_E1000_ETHERNET_DEVICE(0x105F),
145 INTEL_E1000_ETHERNET_DEVICE(0x1060),
146 INTEL_E1000_ETHERNET_DEVICE(0x1075),
147 INTEL_E1000_ETHERNET_DEVICE(0x1076),
148 INTEL_E1000_ETHERNET_DEVICE(0x1077),
149 INTEL_E1000_ETHERNET_DEVICE(0x1078),
150 INTEL_E1000_ETHERNET_DEVICE(0x1079),
151 INTEL_E1000_ETHERNET_DEVICE(0x107A),
152 INTEL_E1000_ETHERNET_DEVICE(0x107B),
153 INTEL_E1000_ETHERNET_DEVICE(0x107C),
154 INTEL_E1000_ETHERNET_DEVICE(0x107D),
155 INTEL_E1000_ETHERNET_DEVICE(0x107E),
156 INTEL_E1000_ETHERNET_DEVICE(0x107F),
157 INTEL_E1000_ETHERNET_DEVICE(0x108A),
158 INTEL_E1000_ETHERNET_DEVICE(0x108B),
159 INTEL_E1000_ETHERNET_DEVICE(0x108C),
160 INTEL_E1000_ETHERNET_DEVICE(0x1099),
161 INTEL_E1000_ETHERNET_DEVICE(0x109A),
162 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
163 /* required last entry */
167 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
169 int e1000_up(struct e1000_adapter *adapter);
170 void e1000_down(struct e1000_adapter *adapter);
171 void e1000_reset(struct e1000_adapter *adapter);
172 int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
173 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
174 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
175 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
176 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
177 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
178 struct e1000_tx_ring *txdr);
179 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
180 struct e1000_rx_ring *rxdr);
181 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
182 struct e1000_tx_ring *tx_ring);
183 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
184 struct e1000_rx_ring *rx_ring);
185 void e1000_update_stats(struct e1000_adapter *adapter);
187 /* Local Function Prototypes */
189 static int e1000_init_module(void);
190 static void e1000_exit_module(void);
191 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
192 static void __devexit e1000_remove(struct pci_dev *pdev);
193 static int e1000_alloc_queues(struct e1000_adapter *adapter);
194 #ifdef CONFIG_E1000_MQ
195 static void e1000_setup_queue_mapping(struct e1000_adapter *adapter);
197 static int e1000_sw_init(struct e1000_adapter *adapter);
198 static int e1000_open(struct net_device *netdev);
199 static int e1000_close(struct net_device *netdev);
200 static void e1000_configure_tx(struct e1000_adapter *adapter);
201 static void e1000_configure_rx(struct e1000_adapter *adapter);
202 static void e1000_setup_rctl(struct e1000_adapter *adapter);
203 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
204 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
205 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
206 struct e1000_tx_ring *tx_ring);
207 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
208 struct e1000_rx_ring *rx_ring);
209 static void e1000_set_multi(struct net_device *netdev);
210 static void e1000_update_phy_info(unsigned long data);
211 static void e1000_watchdog(unsigned long data);
212 static void e1000_watchdog_task(struct e1000_adapter *adapter);
213 static void e1000_82547_tx_fifo_stall(unsigned long data);
214 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
215 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
216 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
217 static int e1000_set_mac(struct net_device *netdev, void *p);
218 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
219 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
220 struct e1000_tx_ring *tx_ring);
221 #ifdef CONFIG_E1000_NAPI
222 static int e1000_clean(struct net_device *poll_dev, int *budget);
223 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
224 struct e1000_rx_ring *rx_ring,
225 int *work_done, int work_to_do);
226 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
227 struct e1000_rx_ring *rx_ring,
228 int *work_done, int work_to_do);
230 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
231 struct e1000_rx_ring *rx_ring);
232 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
233 struct e1000_rx_ring *rx_ring);
235 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
236 struct e1000_rx_ring *rx_ring,
238 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
239 struct e1000_rx_ring *rx_ring,
241 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
242 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
244 void e1000_set_ethtool_ops(struct net_device *netdev);
245 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
246 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
247 static void e1000_tx_timeout(struct net_device *dev);
248 static void e1000_tx_timeout_task(struct net_device *dev);
249 static void e1000_smartspeed(struct e1000_adapter *adapter);
250 static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
251 struct sk_buff *skb);
253 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
254 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
255 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
256 static void e1000_restore_vlan(struct e1000_adapter *adapter);
259 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
260 static int e1000_resume(struct pci_dev *pdev);
263 #ifdef CONFIG_NET_POLL_CONTROLLER
264 /* for netdump / net console */
265 static void e1000_netpoll (struct net_device *netdev);
268 #ifdef CONFIG_E1000_MQ
269 /* for multiple Rx queues */
270 void e1000_rx_schedule(void *data);
273 /* Exported from other modules */
275 extern void e1000_check_options(struct e1000_adapter *adapter);
277 static struct pci_driver e1000_driver = {
278 .name = e1000_driver_name,
279 .id_table = e1000_pci_tbl,
280 .probe = e1000_probe,
281 .remove = __devexit_p(e1000_remove),
282 /* Power Managment Hooks */
284 .suspend = e1000_suspend,
285 .resume = e1000_resume
289 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
290 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
291 MODULE_LICENSE("GPL");
292 MODULE_VERSION(DRV_VERSION);
294 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
295 module_param(debug, int, 0);
296 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
299 * e1000_init_module - Driver Registration Routine
301 * e1000_init_module is the first routine called when the driver is
302 * loaded. All it does is register with the PCI subsystem.
306 e1000_init_module(void)
309 printk(KERN_INFO "%s - version %s\n",
310 e1000_driver_string, e1000_driver_version);
312 printk(KERN_INFO "%s\n", e1000_copyright);
314 ret = pci_module_init(&e1000_driver);
319 module_init(e1000_init_module);
322 * e1000_exit_module - Driver Exit Cleanup Routine
324 * e1000_exit_module is called just before the driver is removed
329 e1000_exit_module(void)
331 pci_unregister_driver(&e1000_driver);
334 module_exit(e1000_exit_module);
337 * e1000_irq_disable - Mask off interrupt generation on the NIC
338 * @adapter: board private structure
342 e1000_irq_disable(struct e1000_adapter *adapter)
344 atomic_inc(&adapter->irq_sem);
345 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
346 E1000_WRITE_FLUSH(&adapter->hw);
347 synchronize_irq(adapter->pdev->irq);
351 * e1000_irq_enable - Enable default interrupt generation settings
352 * @adapter: board private structure
356 e1000_irq_enable(struct e1000_adapter *adapter)
358 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
359 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
360 E1000_WRITE_FLUSH(&adapter->hw);
365 e1000_update_mng_vlan(struct e1000_adapter *adapter)
367 struct net_device *netdev = adapter->netdev;
368 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
369 uint16_t old_vid = adapter->mng_vlan_id;
370 if (adapter->vlgrp) {
371 if (!adapter->vlgrp->vlan_devices[vid]) {
372 if (adapter->hw.mng_cookie.status &
373 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
374 e1000_vlan_rx_add_vid(netdev, vid);
375 adapter->mng_vlan_id = vid;
377 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
379 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
381 !adapter->vlgrp->vlan_devices[old_vid])
382 e1000_vlan_rx_kill_vid(netdev, old_vid);
388 * e1000_release_hw_control - release control of the h/w to f/w
389 * @adapter: address of board private structure
391 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
392 * For ASF and Pass Through versions of f/w this means that the
393 * driver is no longer loaded. For AMT version (only with 82573) i
394 * of the f/w this means that the netowrk i/f is closed.
399 e1000_release_hw_control(struct e1000_adapter *adapter)
404 /* Let firmware taken over control of h/w */
405 switch (adapter->hw.mac_type) {
408 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
409 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
410 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
413 swsm = E1000_READ_REG(&adapter->hw, SWSM);
414 E1000_WRITE_REG(&adapter->hw, SWSM,
415 swsm & ~E1000_SWSM_DRV_LOAD);
422 * e1000_get_hw_control - get control of the h/w from f/w
423 * @adapter: address of board private structure
425 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
426 * For ASF and Pass Through versions of f/w this means that
427 * the driver is loaded. For AMT version (only with 82573)
428 * of the f/w this means that the netowrk i/f is open.
433 e1000_get_hw_control(struct e1000_adapter *adapter)
437 /* Let firmware know the driver has taken over */
438 switch (adapter->hw.mac_type) {
441 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
442 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
443 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
446 swsm = E1000_READ_REG(&adapter->hw, SWSM);
447 E1000_WRITE_REG(&adapter->hw, SWSM,
448 swsm | E1000_SWSM_DRV_LOAD);
456 e1000_up(struct e1000_adapter *adapter)
458 struct net_device *netdev = adapter->netdev;
461 /* hardware has been reset, we need to reload some things */
463 /* Reset the PHY if it was previously powered down */
464 if (adapter->hw.media_type == e1000_media_type_copper) {
466 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
467 if (mii_reg & MII_CR_POWER_DOWN)
468 e1000_phy_reset(&adapter->hw);
471 e1000_set_multi(netdev);
473 e1000_restore_vlan(adapter);
475 e1000_configure_tx(adapter);
476 e1000_setup_rctl(adapter);
477 e1000_configure_rx(adapter);
478 /* call E1000_DESC_UNUSED which always leaves
479 * at least 1 descriptor unused to make sure
480 * next_to_use != next_to_clean */
481 for (i = 0; i < adapter->num_rx_queues; i++) {
482 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
483 adapter->alloc_rx_buf(adapter, ring,
484 E1000_DESC_UNUSED(ring));
487 #ifdef CONFIG_PCI_MSI
488 if (adapter->hw.mac_type > e1000_82547_rev_2) {
489 adapter->have_msi = TRUE;
490 if ((err = pci_enable_msi(adapter->pdev))) {
492 "Unable to allocate MSI interrupt Error: %d\n", err);
493 adapter->have_msi = FALSE;
497 if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
498 SA_SHIRQ | SA_SAMPLE_RANDOM,
499 netdev->name, netdev))) {
501 "Unable to allocate interrupt Error: %d\n", err);
505 #ifdef CONFIG_E1000_MQ
506 e1000_setup_queue_mapping(adapter);
509 adapter->tx_queue_len = netdev->tx_queue_len;
511 mod_timer(&adapter->watchdog_timer, jiffies);
513 #ifdef CONFIG_E1000_NAPI
514 netif_poll_enable(netdev);
516 e1000_irq_enable(adapter);
522 e1000_down(struct e1000_adapter *adapter)
524 struct net_device *netdev = adapter->netdev;
525 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
526 e1000_check_mng_mode(&adapter->hw);
528 e1000_irq_disable(adapter);
529 #ifdef CONFIG_E1000_MQ
530 while (atomic_read(&adapter->rx_sched_call_data.count) != 0);
532 free_irq(adapter->pdev->irq, netdev);
533 #ifdef CONFIG_PCI_MSI
534 if (adapter->hw.mac_type > e1000_82547_rev_2 &&
535 adapter->have_msi == TRUE)
536 pci_disable_msi(adapter->pdev);
538 del_timer_sync(&adapter->tx_fifo_stall_timer);
539 del_timer_sync(&adapter->watchdog_timer);
540 del_timer_sync(&adapter->phy_info_timer);
542 #ifdef CONFIG_E1000_NAPI
543 netif_poll_disable(netdev);
545 netdev->tx_queue_len = adapter->tx_queue_len;
546 adapter->link_speed = 0;
547 adapter->link_duplex = 0;
548 netif_carrier_off(netdev);
549 netif_stop_queue(netdev);
551 e1000_reset(adapter);
552 e1000_clean_all_tx_rings(adapter);
553 e1000_clean_all_rx_rings(adapter);
555 /* Power down the PHY so no link is implied when interface is down *
556 * The PHY cannot be powered down if any of the following is TRUE *
559 * (c) SoL/IDER session is active */
560 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
561 adapter->hw.media_type == e1000_media_type_copper &&
562 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
564 !e1000_check_phy_reset_block(&adapter->hw)) {
566 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
567 mii_reg |= MII_CR_POWER_DOWN;
568 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
574 e1000_reset(struct e1000_adapter *adapter)
577 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
579 /* Repartition Pba for greater than 9k mtu
580 * To take effect CTRL.RST is required.
583 switch (adapter->hw.mac_type) {
585 case e1000_82547_rev_2:
600 if ((adapter->hw.mac_type != e1000_82573) &&
601 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
602 pba -= 8; /* allocate more FIFO for Tx */
605 if (adapter->hw.mac_type == e1000_82547) {
606 adapter->tx_fifo_head = 0;
607 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
608 adapter->tx_fifo_size =
609 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
610 atomic_set(&adapter->tx_fifo_stall, 0);
613 E1000_WRITE_REG(&adapter->hw, PBA, pba);
615 /* flow control settings */
616 /* Set the FC high water mark to 90% of the FIFO size.
617 * Required to clear last 3 LSB */
618 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
620 adapter->hw.fc_high_water = fc_high_water_mark;
621 adapter->hw.fc_low_water = fc_high_water_mark - 8;
622 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
623 adapter->hw.fc_send_xon = 1;
624 adapter->hw.fc = adapter->hw.original_fc;
626 /* Allow time for pending master requests to run */
627 e1000_reset_hw(&adapter->hw);
628 if (adapter->hw.mac_type >= e1000_82544)
629 E1000_WRITE_REG(&adapter->hw, WUC, 0);
630 if (e1000_init_hw(&adapter->hw))
631 DPRINTK(PROBE, ERR, "Hardware Error\n");
632 e1000_update_mng_vlan(adapter);
633 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
634 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
636 e1000_reset_adaptive(&adapter->hw);
637 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
638 if (adapter->en_mng_pt) {
639 manc = E1000_READ_REG(&adapter->hw, MANC);
640 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
641 E1000_WRITE_REG(&adapter->hw, MANC, manc);
646 * e1000_probe - Device Initialization Routine
647 * @pdev: PCI device information struct
648 * @ent: entry in e1000_pci_tbl
650 * Returns 0 on success, negative on failure
652 * e1000_probe initializes an adapter identified by a pci_dev structure.
653 * The OS initialization, configuring of the adapter private structure,
654 * and a hardware reset occur.
658 e1000_probe(struct pci_dev *pdev,
659 const struct pci_device_id *ent)
661 struct net_device *netdev;
662 struct e1000_adapter *adapter;
663 unsigned long mmio_start, mmio_len;
665 static int cards_found = 0;
666 int i, err, pci_using_dac;
667 uint16_t eeprom_data;
668 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
669 if ((err = pci_enable_device(pdev)))
672 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
675 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
676 E1000_ERR("No usable DMA configuration, aborting\n");
682 if ((err = pci_request_regions(pdev, e1000_driver_name)))
685 pci_set_master(pdev);
687 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
690 goto err_alloc_etherdev;
693 SET_MODULE_OWNER(netdev);
694 SET_NETDEV_DEV(netdev, &pdev->dev);
696 pci_set_drvdata(pdev, netdev);
697 adapter = netdev_priv(netdev);
698 adapter->netdev = netdev;
699 adapter->pdev = pdev;
700 adapter->hw.back = adapter;
701 adapter->msg_enable = (1 << debug) - 1;
703 mmio_start = pci_resource_start(pdev, BAR_0);
704 mmio_len = pci_resource_len(pdev, BAR_0);
706 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
707 if (!adapter->hw.hw_addr) {
712 for (i = BAR_1; i <= BAR_5; i++) {
713 if (pci_resource_len(pdev, i) == 0)
715 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
716 adapter->hw.io_base = pci_resource_start(pdev, i);
721 netdev->open = &e1000_open;
722 netdev->stop = &e1000_close;
723 netdev->hard_start_xmit = &e1000_xmit_frame;
724 netdev->get_stats = &e1000_get_stats;
725 netdev->set_multicast_list = &e1000_set_multi;
726 netdev->set_mac_address = &e1000_set_mac;
727 netdev->change_mtu = &e1000_change_mtu;
728 netdev->do_ioctl = &e1000_ioctl;
729 e1000_set_ethtool_ops(netdev);
730 netdev->tx_timeout = &e1000_tx_timeout;
731 netdev->watchdog_timeo = 5 * HZ;
732 #ifdef CONFIG_E1000_NAPI
733 netdev->poll = &e1000_clean;
736 netdev->vlan_rx_register = e1000_vlan_rx_register;
737 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
738 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
739 #ifdef CONFIG_NET_POLL_CONTROLLER
740 netdev->poll_controller = e1000_netpoll;
742 strcpy(netdev->name, pci_name(pdev));
744 netdev->mem_start = mmio_start;
745 netdev->mem_end = mmio_start + mmio_len;
746 netdev->base_addr = adapter->hw.io_base;
748 adapter->bd_number = cards_found;
750 /* setup the private structure */
752 if ((err = e1000_sw_init(adapter)))
755 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
756 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
758 if (adapter->hw.mac_type >= e1000_82543) {
759 netdev->features = NETIF_F_SG |
763 NETIF_F_HW_VLAN_FILTER;
767 if ((adapter->hw.mac_type >= e1000_82544) &&
768 (adapter->hw.mac_type != e1000_82547))
769 netdev->features |= NETIF_F_TSO;
771 #ifdef NETIF_F_TSO_IPV6
772 if (adapter->hw.mac_type > e1000_82547_rev_2)
773 netdev->features |= NETIF_F_TSO_IPV6;
777 netdev->features |= NETIF_F_HIGHDMA;
779 /* hard_start_xmit is safe against parallel locking */
780 netdev->features |= NETIF_F_LLTX;
782 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
784 /* before reading the EEPROM, reset the controller to
785 * put the device in a known good starting state */
787 e1000_reset_hw(&adapter->hw);
789 /* make sure the EEPROM is good */
791 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
792 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
797 /* copy the MAC address out of the EEPROM */
799 if (e1000_read_mac_addr(&adapter->hw))
800 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
801 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
802 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
804 if (!is_valid_ether_addr(netdev->perm_addr)) {
805 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
810 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
812 e1000_get_bus_info(&adapter->hw);
814 init_timer(&adapter->tx_fifo_stall_timer);
815 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
816 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
818 init_timer(&adapter->watchdog_timer);
819 adapter->watchdog_timer.function = &e1000_watchdog;
820 adapter->watchdog_timer.data = (unsigned long) adapter;
822 INIT_WORK(&adapter->watchdog_task,
823 (void (*)(void *))e1000_watchdog_task, adapter);
825 init_timer(&adapter->phy_info_timer);
826 adapter->phy_info_timer.function = &e1000_update_phy_info;
827 adapter->phy_info_timer.data = (unsigned long) adapter;
829 INIT_WORK(&adapter->tx_timeout_task,
830 (void (*)(void *))e1000_tx_timeout_task, netdev);
832 /* we're going to reset, so assume we have no link for now */
834 netif_carrier_off(netdev);
835 netif_stop_queue(netdev);
837 e1000_check_options(adapter);
839 /* Initial Wake on LAN setting
840 * If APM wake is enabled in the EEPROM,
841 * enable the ACPI Magic Packet filter
844 switch (adapter->hw.mac_type) {
845 case e1000_82542_rev2_0:
846 case e1000_82542_rev2_1:
850 e1000_read_eeprom(&adapter->hw,
851 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
852 eeprom_apme_mask = E1000_EEPROM_82544_APM;
855 case e1000_82546_rev_3:
857 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
858 e1000_read_eeprom(&adapter->hw,
859 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
864 e1000_read_eeprom(&adapter->hw,
865 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
868 if (eeprom_data & eeprom_apme_mask)
869 adapter->wol |= E1000_WUFC_MAG;
871 /* print bus type/speed/width info */
873 struct e1000_hw *hw = &adapter->hw;
874 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
875 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
876 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
877 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
878 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
879 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
880 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
881 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
882 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
883 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
884 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
888 for (i = 0; i < 6; i++)
889 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
891 /* reset the hardware with the new settings */
892 e1000_reset(adapter);
894 /* If the controller is 82573 and f/w is AMT, do not set
895 * DRV_LOAD until the interface is up. For all other cases,
896 * let the f/w know that the h/w is now under the control
898 if (adapter->hw.mac_type != e1000_82573 ||
899 !e1000_check_mng_mode(&adapter->hw))
900 e1000_get_hw_control(adapter);
902 strcpy(netdev->name, "eth%d");
903 if ((err = register_netdev(netdev)))
906 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
914 iounmap(adapter->hw.hw_addr);
918 pci_release_regions(pdev);
923 * e1000_remove - Device Removal Routine
924 * @pdev: PCI device information struct
926 * e1000_remove is called by the PCI subsystem to alert the driver
927 * that it should release a PCI device. The could be caused by a
928 * Hot-Plug event, or because the driver is going to be removed from
932 static void __devexit
933 e1000_remove(struct pci_dev *pdev)
935 struct net_device *netdev = pci_get_drvdata(pdev);
936 struct e1000_adapter *adapter = netdev_priv(netdev);
938 #ifdef CONFIG_E1000_NAPI
942 flush_scheduled_work();
944 if (adapter->hw.mac_type >= e1000_82540 &&
945 adapter->hw.media_type == e1000_media_type_copper) {
946 manc = E1000_READ_REG(&adapter->hw, MANC);
947 if (manc & E1000_MANC_SMBUS_EN) {
948 manc |= E1000_MANC_ARP_EN;
949 E1000_WRITE_REG(&adapter->hw, MANC, manc);
953 /* Release control of h/w to f/w. If f/w is AMT enabled, this
954 * would have already happened in close and is redundant. */
955 e1000_release_hw_control(adapter);
957 unregister_netdev(netdev);
958 #ifdef CONFIG_E1000_NAPI
959 for (i = 0; i < adapter->num_rx_queues; i++)
960 __dev_put(&adapter->polling_netdev[i]);
963 if (!e1000_check_phy_reset_block(&adapter->hw))
964 e1000_phy_hw_reset(&adapter->hw);
966 kfree(adapter->tx_ring);
967 kfree(adapter->rx_ring);
968 #ifdef CONFIG_E1000_NAPI
969 kfree(adapter->polling_netdev);
972 iounmap(adapter->hw.hw_addr);
973 pci_release_regions(pdev);
975 #ifdef CONFIG_E1000_MQ
976 free_percpu(adapter->cpu_netdev);
977 free_percpu(adapter->cpu_tx_ring);
981 pci_disable_device(pdev);
985 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
986 * @adapter: board private structure to initialize
988 * e1000_sw_init initializes the Adapter private data structure.
989 * Fields are initialized based on PCI device information and
990 * OS network device settings (MTU size).
994 e1000_sw_init(struct e1000_adapter *adapter)
996 struct e1000_hw *hw = &adapter->hw;
997 struct net_device *netdev = adapter->netdev;
998 struct pci_dev *pdev = adapter->pdev;
999 #ifdef CONFIG_E1000_NAPI
1003 /* PCI config space info */
1005 hw->vendor_id = pdev->vendor;
1006 hw->device_id = pdev->device;
1007 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1008 hw->subsystem_id = pdev->subsystem_device;
1010 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1012 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1014 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
1015 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
1016 hw->max_frame_size = netdev->mtu +
1017 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1018 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1020 /* identify the MAC */
1022 if (e1000_set_mac_type(hw)) {
1023 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1027 /* initialize eeprom parameters */
1029 if (e1000_init_eeprom_params(hw)) {
1030 E1000_ERR("EEPROM initialization failed\n");
1034 switch (hw->mac_type) {
1039 case e1000_82541_rev_2:
1040 case e1000_82547_rev_2:
1041 hw->phy_init_script = 1;
1045 e1000_set_media_type(hw);
1047 hw->wait_autoneg_complete = FALSE;
1048 hw->tbi_compatibility_en = TRUE;
1049 hw->adaptive_ifs = TRUE;
1051 /* Copper options */
1053 if (hw->media_type == e1000_media_type_copper) {
1054 hw->mdix = AUTO_ALL_MODES;
1055 hw->disable_polarity_correction = FALSE;
1056 hw->master_slave = E1000_MASTER_SLAVE;
1059 #ifdef CONFIG_E1000_MQ
1060 /* Number of supported queues */
1061 switch (hw->mac_type) {
1064 /* These controllers support 2 tx queues, but with a single
1065 * qdisc implementation, multiple tx queues aren't quite as
1066 * interesting. If we can find a logical way of mapping
1067 * flows to a queue, then perhaps we can up the num_tx_queue
1068 * count back to its default. Until then, we run the risk of
1069 * terrible performance due to SACK overload. */
1070 adapter->num_tx_queues = 1;
1071 adapter->num_rx_queues = 2;
1074 adapter->num_tx_queues = 1;
1075 adapter->num_rx_queues = 1;
1078 adapter->num_rx_queues = min(adapter->num_rx_queues, num_online_cpus());
1079 adapter->num_tx_queues = min(adapter->num_tx_queues, num_online_cpus());
1080 DPRINTK(DRV, INFO, "Multiqueue Enabled: Rx Queue count = %u %s\n",
1081 adapter->num_rx_queues,
1082 ((adapter->num_rx_queues == 1)
1083 ? ((num_online_cpus() > 1)
1084 ? "(due to unsupported feature in current adapter)"
1085 : "(due to unsupported system configuration)")
1087 DPRINTK(DRV, INFO, "Multiqueue Enabled: Tx Queue count = %u\n",
1088 adapter->num_tx_queues);
1090 adapter->num_tx_queues = 1;
1091 adapter->num_rx_queues = 1;
1094 if (e1000_alloc_queues(adapter)) {
1095 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1099 #ifdef CONFIG_E1000_NAPI
1100 for (i = 0; i < adapter->num_rx_queues; i++) {
1101 adapter->polling_netdev[i].priv = adapter;
1102 adapter->polling_netdev[i].poll = &e1000_clean;
1103 adapter->polling_netdev[i].weight = 64;
1104 dev_hold(&adapter->polling_netdev[i]);
1105 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1107 spin_lock_init(&adapter->tx_queue_lock);
1110 atomic_set(&adapter->irq_sem, 1);
1111 spin_lock_init(&adapter->stats_lock);
1117 * e1000_alloc_queues - Allocate memory for all rings
1118 * @adapter: board private structure to initialize
1120 * We allocate one ring per queue at run-time since we don't know the
1121 * number of queues at compile-time. The polling_netdev array is
1122 * intended for Multiqueue, but should work fine with a single queue.
1125 static int __devinit
1126 e1000_alloc_queues(struct e1000_adapter *adapter)
1130 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1131 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1132 if (!adapter->tx_ring)
1134 memset(adapter->tx_ring, 0, size);
1136 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1137 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1138 if (!adapter->rx_ring) {
1139 kfree(adapter->tx_ring);
1142 memset(adapter->rx_ring, 0, size);
1144 #ifdef CONFIG_E1000_NAPI
1145 size = sizeof(struct net_device) * adapter->num_rx_queues;
1146 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1147 if (!adapter->polling_netdev) {
1148 kfree(adapter->tx_ring);
1149 kfree(adapter->rx_ring);
1152 memset(adapter->polling_netdev, 0, size);
1155 #ifdef CONFIG_E1000_MQ
1156 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1157 adapter->rx_sched_call_data.info = adapter->netdev;
1159 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1160 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1163 return E1000_SUCCESS;
1166 #ifdef CONFIG_E1000_MQ
1167 static void __devinit
1168 e1000_setup_queue_mapping(struct e1000_adapter *adapter)
1172 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1173 adapter->rx_sched_call_data.info = adapter->netdev;
1174 cpus_clear(adapter->rx_sched_call_data.cpumask);
1176 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1177 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1181 for_each_online_cpu(cpu) {
1182 *per_cpu_ptr(adapter->cpu_tx_ring, cpu) = &adapter->tx_ring[i % adapter->num_tx_queues];
1183 /* This is incomplete because we'd like to assign separate
1184 * physical cpus to these netdev polling structures and
1185 * avoid saturating a subset of cpus.
1187 if (i < adapter->num_rx_queues) {
1188 *per_cpu_ptr(adapter->cpu_netdev, cpu) = &adapter->polling_netdev[i];
1189 adapter->rx_ring[i].cpu = cpu;
1190 cpu_set(cpu, adapter->cpumask);
1192 *per_cpu_ptr(adapter->cpu_netdev, cpu) = NULL;
1196 unlock_cpu_hotplug();
1201 * e1000_open - Called when a network interface is made active
1202 * @netdev: network interface device structure
1204 * Returns 0 on success, negative value on failure
1206 * The open entry point is called when a network interface is made
1207 * active by the system (IFF_UP). At this point all resources needed
1208 * for transmit and receive operations are allocated, the interrupt
1209 * handler is registered with the OS, the watchdog timer is started,
1210 * and the stack is notified that the interface is ready.
1214 e1000_open(struct net_device *netdev)
1216 struct e1000_adapter *adapter = netdev_priv(netdev);
1219 /* allocate transmit descriptors */
1221 if ((err = e1000_setup_all_tx_resources(adapter)))
1224 /* allocate receive descriptors */
1226 if ((err = e1000_setup_all_rx_resources(adapter)))
1229 if ((err = e1000_up(adapter)))
1231 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1232 if ((adapter->hw.mng_cookie.status &
1233 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1234 e1000_update_mng_vlan(adapter);
1237 /* If AMT is enabled, let the firmware know that the network
1238 * interface is now open */
1239 if (adapter->hw.mac_type == e1000_82573 &&
1240 e1000_check_mng_mode(&adapter->hw))
1241 e1000_get_hw_control(adapter);
1243 return E1000_SUCCESS;
1246 e1000_free_all_rx_resources(adapter);
1248 e1000_free_all_tx_resources(adapter);
1250 e1000_reset(adapter);
1256 * e1000_close - Disables a network interface
1257 * @netdev: network interface device structure
1259 * Returns 0, this is not allowed to fail
1261 * The close entry point is called when an interface is de-activated
1262 * by the OS. The hardware is still under the drivers control, but
1263 * needs to be disabled. A global MAC reset is issued to stop the
1264 * hardware, and all transmit and receive resources are freed.
1268 e1000_close(struct net_device *netdev)
1270 struct e1000_adapter *adapter = netdev_priv(netdev);
1272 e1000_down(adapter);
1274 e1000_free_all_tx_resources(adapter);
1275 e1000_free_all_rx_resources(adapter);
1277 if ((adapter->hw.mng_cookie.status &
1278 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1279 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1282 /* If AMT is enabled, let the firmware know that the network
1283 * interface is now closed */
1284 if (adapter->hw.mac_type == e1000_82573 &&
1285 e1000_check_mng_mode(&adapter->hw))
1286 e1000_release_hw_control(adapter);
1292 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1293 * @adapter: address of board private structure
1294 * @start: address of beginning of memory
1295 * @len: length of memory
1297 static inline boolean_t
1298 e1000_check_64k_bound(struct e1000_adapter *adapter,
1299 void *start, unsigned long len)
1301 unsigned long begin = (unsigned long) start;
1302 unsigned long end = begin + len;
1304 /* First rev 82545 and 82546 need to not allow any memory
1305 * write location to cross 64k boundary due to errata 23 */
1306 if (adapter->hw.mac_type == e1000_82545 ||
1307 adapter->hw.mac_type == e1000_82546) {
1308 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1315 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1316 * @adapter: board private structure
1317 * @txdr: tx descriptor ring (for a specific queue) to setup
1319 * Return 0 on success, negative on failure
1323 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1324 struct e1000_tx_ring *txdr)
1326 struct pci_dev *pdev = adapter->pdev;
1329 size = sizeof(struct e1000_buffer) * txdr->count;
1331 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1332 if (!txdr->buffer_info) {
1334 "Unable to allocate memory for the transmit descriptor ring\n");
1337 memset(txdr->buffer_info, 0, size);
1339 /* round up to nearest 4K */
1341 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1342 E1000_ROUNDUP(txdr->size, 4096);
1344 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1347 vfree(txdr->buffer_info);
1349 "Unable to allocate memory for the transmit descriptor ring\n");
1353 /* Fix for errata 23, can't cross 64kB boundary */
1354 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1355 void *olddesc = txdr->desc;
1356 dma_addr_t olddma = txdr->dma;
1357 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1358 "at %p\n", txdr->size, txdr->desc);
1359 /* Try again, without freeing the previous */
1360 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1361 /* Failed allocation, critical failure */
1363 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1364 goto setup_tx_desc_die;
1367 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1369 pci_free_consistent(pdev, txdr->size, txdr->desc,
1371 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1373 "Unable to allocate aligned memory "
1374 "for the transmit descriptor ring\n");
1375 vfree(txdr->buffer_info);
1378 /* Free old allocation, new allocation was successful */
1379 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1382 memset(txdr->desc, 0, txdr->size);
1384 txdr->next_to_use = 0;
1385 txdr->next_to_clean = 0;
1386 spin_lock_init(&txdr->tx_lock);
1392 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1393 * (Descriptors) for all queues
1394 * @adapter: board private structure
1396 * If this function returns with an error, then it's possible one or
1397 * more of the rings is populated (while the rest are not). It is the
1398 * callers duty to clean those orphaned rings.
1400 * Return 0 on success, negative on failure
1404 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1408 for (i = 0; i < adapter->num_tx_queues; i++) {
1409 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1412 "Allocation for Tx Queue %u failed\n", i);
1421 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1422 * @adapter: board private structure
1424 * Configure the Tx unit of the MAC after a reset.
1428 e1000_configure_tx(struct e1000_adapter *adapter)
1431 struct e1000_hw *hw = &adapter->hw;
1432 uint32_t tdlen, tctl, tipg, tarc;
1433 uint32_t ipgr1, ipgr2;
1435 /* Setup the HW Tx Head and Tail descriptor pointers */
1437 switch (adapter->num_tx_queues) {
1439 tdba = adapter->tx_ring[1].dma;
1440 tdlen = adapter->tx_ring[1].count *
1441 sizeof(struct e1000_tx_desc);
1442 E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
1443 E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
1444 E1000_WRITE_REG(hw, TDLEN1, tdlen);
1445 E1000_WRITE_REG(hw, TDH1, 0);
1446 E1000_WRITE_REG(hw, TDT1, 0);
1447 adapter->tx_ring[1].tdh = E1000_TDH1;
1448 adapter->tx_ring[1].tdt = E1000_TDT1;
1452 tdba = adapter->tx_ring[0].dma;
1453 tdlen = adapter->tx_ring[0].count *
1454 sizeof(struct e1000_tx_desc);
1455 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1456 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1457 E1000_WRITE_REG(hw, TDLEN, tdlen);
1458 E1000_WRITE_REG(hw, TDH, 0);
1459 E1000_WRITE_REG(hw, TDT, 0);
1460 adapter->tx_ring[0].tdh = E1000_TDH;
1461 adapter->tx_ring[0].tdt = E1000_TDT;
1465 /* Set the default values for the Tx Inter Packet Gap timer */
1467 if (hw->media_type == e1000_media_type_fiber ||
1468 hw->media_type == e1000_media_type_internal_serdes)
1469 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1471 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1473 switch (hw->mac_type) {
1474 case e1000_82542_rev2_0:
1475 case e1000_82542_rev2_1:
1476 tipg = DEFAULT_82542_TIPG_IPGT;
1477 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1478 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1481 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1482 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1485 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1486 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1487 E1000_WRITE_REG(hw, TIPG, tipg);
1489 /* Set the Tx Interrupt Delay register */
1491 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1492 if (hw->mac_type >= e1000_82540)
1493 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1495 /* Program the Transmit Control Register */
1497 tctl = E1000_READ_REG(hw, TCTL);
1499 tctl &= ~E1000_TCTL_CT;
1500 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
1501 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1503 E1000_WRITE_REG(hw, TCTL, tctl);
1505 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1506 tarc = E1000_READ_REG(hw, TARC0);
1507 tarc |= ((1 << 25) | (1 << 21));
1508 E1000_WRITE_REG(hw, TARC0, tarc);
1509 tarc = E1000_READ_REG(hw, TARC1);
1511 if (tctl & E1000_TCTL_MULR)
1515 E1000_WRITE_REG(hw, TARC1, tarc);
1518 e1000_config_collision_dist(hw);
1520 /* Setup Transmit Descriptor Settings for eop descriptor */
1521 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1524 if (hw->mac_type < e1000_82543)
1525 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1527 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1529 /* Cache if we're 82544 running in PCI-X because we'll
1530 * need this to apply a workaround later in the send path. */
1531 if (hw->mac_type == e1000_82544 &&
1532 hw->bus_type == e1000_bus_type_pcix)
1533 adapter->pcix_82544 = 1;
1537 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1538 * @adapter: board private structure
1539 * @rxdr: rx descriptor ring (for a specific queue) to setup
1541 * Returns 0 on success, negative on failure
1545 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1546 struct e1000_rx_ring *rxdr)
1548 struct pci_dev *pdev = adapter->pdev;
1551 size = sizeof(struct e1000_buffer) * rxdr->count;
1552 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1553 if (!rxdr->buffer_info) {
1555 "Unable to allocate memory for the receive descriptor ring\n");
1558 memset(rxdr->buffer_info, 0, size);
1560 size = sizeof(struct e1000_ps_page) * rxdr->count;
1561 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1562 if (!rxdr->ps_page) {
1563 vfree(rxdr->buffer_info);
1565 "Unable to allocate memory for the receive descriptor ring\n");
1568 memset(rxdr->ps_page, 0, size);
1570 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1571 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1572 if (!rxdr->ps_page_dma) {
1573 vfree(rxdr->buffer_info);
1574 kfree(rxdr->ps_page);
1576 "Unable to allocate memory for the receive descriptor ring\n");
1579 memset(rxdr->ps_page_dma, 0, size);
1581 if (adapter->hw.mac_type <= e1000_82547_rev_2)
1582 desc_len = sizeof(struct e1000_rx_desc);
1584 desc_len = sizeof(union e1000_rx_desc_packet_split);
1586 /* Round up to nearest 4K */
1588 rxdr->size = rxdr->count * desc_len;
1589 E1000_ROUNDUP(rxdr->size, 4096);
1591 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1595 "Unable to allocate memory for the receive descriptor ring\n");
1597 vfree(rxdr->buffer_info);
1598 kfree(rxdr->ps_page);
1599 kfree(rxdr->ps_page_dma);
1603 /* Fix for errata 23, can't cross 64kB boundary */
1604 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1605 void *olddesc = rxdr->desc;
1606 dma_addr_t olddma = rxdr->dma;
1607 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1608 "at %p\n", rxdr->size, rxdr->desc);
1609 /* Try again, without freeing the previous */
1610 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1611 /* Failed allocation, critical failure */
1613 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1615 "Unable to allocate memory "
1616 "for the receive descriptor ring\n");
1617 goto setup_rx_desc_die;
1620 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1622 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1624 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1626 "Unable to allocate aligned memory "
1627 "for the receive descriptor ring\n");
1628 goto setup_rx_desc_die;
1630 /* Free old allocation, new allocation was successful */
1631 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1634 memset(rxdr->desc, 0, rxdr->size);
1636 rxdr->next_to_clean = 0;
1637 rxdr->next_to_use = 0;
1643 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1644 * (Descriptors) for all queues
1645 * @adapter: board private structure
1647 * If this function returns with an error, then it's possible one or
1648 * more of the rings is populated (while the rest are not). It is the
1649 * callers duty to clean those orphaned rings.
1651 * Return 0 on success, negative on failure
1655 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1659 for (i = 0; i < adapter->num_rx_queues; i++) {
1660 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1663 "Allocation for Rx Queue %u failed\n", i);
1672 * e1000_setup_rctl - configure the receive control registers
1673 * @adapter: Board private structure
1675 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1676 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1678 e1000_setup_rctl(struct e1000_adapter *adapter)
1680 uint32_t rctl, rfctl;
1681 uint32_t psrctl = 0;
1682 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1686 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1688 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1690 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1691 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1692 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1694 if (adapter->hw.mac_type > e1000_82543)
1695 rctl |= E1000_RCTL_SECRC;
1697 if (adapter->hw.tbi_compatibility_on == 1)
1698 rctl |= E1000_RCTL_SBP;
1700 rctl &= ~E1000_RCTL_SBP;
1702 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1703 rctl &= ~E1000_RCTL_LPE;
1705 rctl |= E1000_RCTL_LPE;
1707 /* Setup buffer sizes */
1708 if (adapter->hw.mac_type >= e1000_82571) {
1709 /* We can now specify buffers in 1K increments.
1710 * BSIZE and BSEX are ignored in this case. */
1711 rctl |= adapter->rx_buffer_len << 0x11;
1713 rctl &= ~E1000_RCTL_SZ_4096;
1714 rctl |= E1000_RCTL_BSEX;
1715 switch (adapter->rx_buffer_len) {
1716 case E1000_RXBUFFER_2048:
1718 rctl |= E1000_RCTL_SZ_2048;
1719 rctl &= ~E1000_RCTL_BSEX;
1721 case E1000_RXBUFFER_4096:
1722 rctl |= E1000_RCTL_SZ_4096;
1724 case E1000_RXBUFFER_8192:
1725 rctl |= E1000_RCTL_SZ_8192;
1727 case E1000_RXBUFFER_16384:
1728 rctl |= E1000_RCTL_SZ_16384;
1733 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1734 /* 82571 and greater support packet-split where the protocol
1735 * header is placed in skb->data and the packet data is
1736 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1737 * In the case of a non-split, skb->data is linearly filled,
1738 * followed by the page buffers. Therefore, skb->data is
1739 * sized to hold the largest protocol header.
1741 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1742 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1744 adapter->rx_ps_pages = pages;
1746 adapter->rx_ps_pages = 0;
1748 if (adapter->rx_ps_pages) {
1749 /* Configure extra packet-split registers */
1750 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1751 rfctl |= E1000_RFCTL_EXTEN;
1752 /* disable IPv6 packet split support */
1753 rfctl |= E1000_RFCTL_IPV6_DIS;
1754 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1756 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1758 psrctl |= adapter->rx_ps_bsize0 >>
1759 E1000_PSRCTL_BSIZE0_SHIFT;
1761 switch (adapter->rx_ps_pages) {
1763 psrctl |= PAGE_SIZE <<
1764 E1000_PSRCTL_BSIZE3_SHIFT;
1766 psrctl |= PAGE_SIZE <<
1767 E1000_PSRCTL_BSIZE2_SHIFT;
1769 psrctl |= PAGE_SIZE >>
1770 E1000_PSRCTL_BSIZE1_SHIFT;
1774 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1777 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1781 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1782 * @adapter: board private structure
1784 * Configure the Rx unit of the MAC after a reset.
1788 e1000_configure_rx(struct e1000_adapter *adapter)
1791 struct e1000_hw *hw = &adapter->hw;
1792 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1793 #ifdef CONFIG_E1000_MQ
1794 uint32_t reta, mrqc;
1798 if (adapter->rx_ps_pages) {
1799 rdlen = adapter->rx_ring[0].count *
1800 sizeof(union e1000_rx_desc_packet_split);
1801 adapter->clean_rx = e1000_clean_rx_irq_ps;
1802 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1804 rdlen = adapter->rx_ring[0].count *
1805 sizeof(struct e1000_rx_desc);
1806 adapter->clean_rx = e1000_clean_rx_irq;
1807 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1810 /* disable receives while setting up the descriptors */
1811 rctl = E1000_READ_REG(hw, RCTL);
1812 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1814 /* set the Receive Delay Timer Register */
1815 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1817 if (hw->mac_type >= e1000_82540) {
1818 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1819 if (adapter->itr > 1)
1820 E1000_WRITE_REG(hw, ITR,
1821 1000000000 / (adapter->itr * 256));
1824 if (hw->mac_type >= e1000_82571) {
1825 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1826 /* Reset delay timers after every interrupt */
1827 ctrl_ext |= E1000_CTRL_EXT_CANC;
1828 #ifdef CONFIG_E1000_NAPI
1829 /* Auto-Mask interrupts upon ICR read. */
1830 ctrl_ext |= E1000_CTRL_EXT_IAME;
1832 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1833 E1000_WRITE_REG(hw, IAM, ~0);
1834 E1000_WRITE_FLUSH(hw);
1837 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1838 * the Base and Length of the Rx Descriptor Ring */
1839 switch (adapter->num_rx_queues) {
1840 #ifdef CONFIG_E1000_MQ
1842 rdba = adapter->rx_ring[1].dma;
1843 E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
1844 E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
1845 E1000_WRITE_REG(hw, RDLEN1, rdlen);
1846 E1000_WRITE_REG(hw, RDH1, 0);
1847 E1000_WRITE_REG(hw, RDT1, 0);
1848 adapter->rx_ring[1].rdh = E1000_RDH1;
1849 adapter->rx_ring[1].rdt = E1000_RDT1;
1854 rdba = adapter->rx_ring[0].dma;
1855 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1856 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1857 E1000_WRITE_REG(hw, RDLEN, rdlen);
1858 E1000_WRITE_REG(hw, RDH, 0);
1859 E1000_WRITE_REG(hw, RDT, 0);
1860 adapter->rx_ring[0].rdh = E1000_RDH;
1861 adapter->rx_ring[0].rdt = E1000_RDT;
1865 #ifdef CONFIG_E1000_MQ
1866 if (adapter->num_rx_queues > 1) {
1867 uint32_t random[10];
1869 get_random_bytes(&random[0], 40);
1871 if (hw->mac_type <= e1000_82572) {
1872 E1000_WRITE_REG(hw, RSSIR, 0);
1873 E1000_WRITE_REG(hw, RSSIM, 0);
1876 switch (adapter->num_rx_queues) {
1880 mrqc = E1000_MRQC_ENABLE_RSS_2Q;
1884 /* Fill out redirection table */
1885 for (i = 0; i < 32; i++)
1886 E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
1887 /* Fill out hash function seeds */
1888 for (i = 0; i < 10; i++)
1889 E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
1891 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1892 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1893 E1000_WRITE_REG(hw, MRQC, mrqc);
1896 /* Multiqueue and packet checksumming are mutually exclusive. */
1897 if (hw->mac_type >= e1000_82571) {
1898 rxcsum = E1000_READ_REG(hw, RXCSUM);
1899 rxcsum |= E1000_RXCSUM_PCSD;
1900 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1905 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1906 if (hw->mac_type >= e1000_82543) {
1907 rxcsum = E1000_READ_REG(hw, RXCSUM);
1908 if (adapter->rx_csum == TRUE) {
1909 rxcsum |= E1000_RXCSUM_TUOFL;
1911 /* Enable 82571 IPv4 payload checksum for UDP fragments
1912 * Must be used in conjunction with packet-split. */
1913 if ((hw->mac_type >= e1000_82571) &&
1914 (adapter->rx_ps_pages)) {
1915 rxcsum |= E1000_RXCSUM_IPPCSE;
1918 rxcsum &= ~E1000_RXCSUM_TUOFL;
1919 /* don't need to clear IPPCSE as it defaults to 0 */
1921 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1923 #endif /* CONFIG_E1000_MQ */
1925 if (hw->mac_type == e1000_82573)
1926 E1000_WRITE_REG(hw, ERT, 0x0100);
1928 /* Enable Receives */
1929 E1000_WRITE_REG(hw, RCTL, rctl);
1933 * e1000_free_tx_resources - Free Tx Resources per Queue
1934 * @adapter: board private structure
1935 * @tx_ring: Tx descriptor ring for a specific queue
1937 * Free all transmit software resources
1941 e1000_free_tx_resources(struct e1000_adapter *adapter,
1942 struct e1000_tx_ring *tx_ring)
1944 struct pci_dev *pdev = adapter->pdev;
1946 e1000_clean_tx_ring(adapter, tx_ring);
1948 vfree(tx_ring->buffer_info);
1949 tx_ring->buffer_info = NULL;
1951 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1953 tx_ring->desc = NULL;
1957 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1958 * @adapter: board private structure
1960 * Free all transmit software resources
1964 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1968 for (i = 0; i < adapter->num_tx_queues; i++)
1969 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1973 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1974 struct e1000_buffer *buffer_info)
1976 if (buffer_info->dma) {
1977 pci_unmap_page(adapter->pdev,
1979 buffer_info->length,
1982 if (buffer_info->skb)
1983 dev_kfree_skb_any(buffer_info->skb);
1984 memset(buffer_info, 0, sizeof(struct e1000_buffer));
1988 * e1000_clean_tx_ring - Free Tx Buffers
1989 * @adapter: board private structure
1990 * @tx_ring: ring to be cleaned
1994 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1995 struct e1000_tx_ring *tx_ring)
1997 struct e1000_buffer *buffer_info;
2001 /* Free all the Tx ring sk_buffs */
2003 for (i = 0; i < tx_ring->count; i++) {
2004 buffer_info = &tx_ring->buffer_info[i];
2005 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2008 size = sizeof(struct e1000_buffer) * tx_ring->count;
2009 memset(tx_ring->buffer_info, 0, size);
2011 /* Zero out the descriptor ring */
2013 memset(tx_ring->desc, 0, tx_ring->size);
2015 tx_ring->next_to_use = 0;
2016 tx_ring->next_to_clean = 0;
2017 tx_ring->last_tx_tso = 0;
2019 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2020 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2024 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2025 * @adapter: board private structure
2029 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2033 for (i = 0; i < adapter->num_tx_queues; i++)
2034 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2038 * e1000_free_rx_resources - Free Rx Resources
2039 * @adapter: board private structure
2040 * @rx_ring: ring to clean the resources from
2042 * Free all receive software resources
2046 e1000_free_rx_resources(struct e1000_adapter *adapter,
2047 struct e1000_rx_ring *rx_ring)
2049 struct pci_dev *pdev = adapter->pdev;
2051 e1000_clean_rx_ring(adapter, rx_ring);
2053 vfree(rx_ring->buffer_info);
2054 rx_ring->buffer_info = NULL;
2055 kfree(rx_ring->ps_page);
2056 rx_ring->ps_page = NULL;
2057 kfree(rx_ring->ps_page_dma);
2058 rx_ring->ps_page_dma = NULL;
2060 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2062 rx_ring->desc = NULL;
2066 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2067 * @adapter: board private structure
2069 * Free all receive software resources
2073 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2077 for (i = 0; i < adapter->num_rx_queues; i++)
2078 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2082 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2083 * @adapter: board private structure
2084 * @rx_ring: ring to free buffers from
2088 e1000_clean_rx_ring(struct e1000_adapter *adapter,
2089 struct e1000_rx_ring *rx_ring)
2091 struct e1000_buffer *buffer_info;
2092 struct e1000_ps_page *ps_page;
2093 struct e1000_ps_page_dma *ps_page_dma;
2094 struct pci_dev *pdev = adapter->pdev;
2098 /* Free all the Rx ring sk_buffs */
2099 for (i = 0; i < rx_ring->count; i++) {
2100 buffer_info = &rx_ring->buffer_info[i];
2101 if (buffer_info->skb) {
2102 pci_unmap_single(pdev,
2104 buffer_info->length,
2105 PCI_DMA_FROMDEVICE);
2107 dev_kfree_skb(buffer_info->skb);
2108 buffer_info->skb = NULL;
2110 ps_page = &rx_ring->ps_page[i];
2111 ps_page_dma = &rx_ring->ps_page_dma[i];
2112 for (j = 0; j < adapter->rx_ps_pages; j++) {
2113 if (!ps_page->ps_page[j]) break;
2114 pci_unmap_page(pdev,
2115 ps_page_dma->ps_page_dma[j],
2116 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2117 ps_page_dma->ps_page_dma[j] = 0;
2118 put_page(ps_page->ps_page[j]);
2119 ps_page->ps_page[j] = NULL;
2123 size = sizeof(struct e1000_buffer) * rx_ring->count;
2124 memset(rx_ring->buffer_info, 0, size);
2125 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2126 memset(rx_ring->ps_page, 0, size);
2127 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2128 memset(rx_ring->ps_page_dma, 0, size);
2130 /* Zero out the descriptor ring */
2132 memset(rx_ring->desc, 0, rx_ring->size);
2134 rx_ring->next_to_clean = 0;
2135 rx_ring->next_to_use = 0;
2137 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2138 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2142 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2143 * @adapter: board private structure
2147 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2151 for (i = 0; i < adapter->num_rx_queues; i++)
2152 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2155 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2156 * and memory write and invalidate disabled for certain operations
2159 e1000_enter_82542_rst(struct e1000_adapter *adapter)
2161 struct net_device *netdev = adapter->netdev;
2164 e1000_pci_clear_mwi(&adapter->hw);
2166 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2167 rctl |= E1000_RCTL_RST;
2168 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2169 E1000_WRITE_FLUSH(&adapter->hw);
2172 if (netif_running(netdev))
2173 e1000_clean_all_rx_rings(adapter);
2177 e1000_leave_82542_rst(struct e1000_adapter *adapter)
2179 struct net_device *netdev = adapter->netdev;
2182 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2183 rctl &= ~E1000_RCTL_RST;
2184 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2185 E1000_WRITE_FLUSH(&adapter->hw);
2188 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2189 e1000_pci_set_mwi(&adapter->hw);
2191 if (netif_running(netdev)) {
2192 /* No need to loop, because 82542 supports only 1 queue */
2193 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2194 e1000_configure_rx(adapter);
2195 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2200 * e1000_set_mac - Change the Ethernet Address of the NIC
2201 * @netdev: network interface device structure
2202 * @p: pointer to an address structure
2204 * Returns 0 on success, negative on failure
2208 e1000_set_mac(struct net_device *netdev, void *p)
2210 struct e1000_adapter *adapter = netdev_priv(netdev);
2211 struct sockaddr *addr = p;
2213 if (!is_valid_ether_addr(addr->sa_data))
2214 return -EADDRNOTAVAIL;
2216 /* 82542 2.0 needs to be in reset to write receive address registers */
2218 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2219 e1000_enter_82542_rst(adapter);
2221 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2222 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2224 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2226 /* With 82571 controllers, LAA may be overwritten (with the default)
2227 * due to controller reset from the other port. */
2228 if (adapter->hw.mac_type == e1000_82571) {
2229 /* activate the work around */
2230 adapter->hw.laa_is_present = 1;
2232 /* Hold a copy of the LAA in RAR[14] This is done so that
2233 * between the time RAR[0] gets clobbered and the time it
2234 * gets fixed (in e1000_watchdog), the actual LAA is in one
2235 * of the RARs and no incoming packets directed to this port
2236 * are dropped. Eventaully the LAA will be in RAR[0] and
2238 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2239 E1000_RAR_ENTRIES - 1);
2242 if (adapter->hw.mac_type == e1000_82542_rev2_0)
2243 e1000_leave_82542_rst(adapter);
2249 * e1000_set_multi - Multicast and Promiscuous mode set
2250 * @netdev: network interface device structure
2252 * The set_multi entry point is called whenever the multicast address
2253 * list or the network interface flags are updated. This routine is
2254 * responsible for configuring the hardware for proper multicast,
2255 * promiscuous mode, and all-multi behavior.
2259 e1000_set_multi(struct net_device *netdev)
2261 struct e1000_adapter *adapter = netdev_priv(netdev);
2262 struct e1000_hw *hw = &adapter->hw;
2263 struct dev_mc_list *mc_ptr;
2265 uint32_t hash_value;
2266 int i, rar_entries = E1000_RAR_ENTRIES;
2268 /* reserve RAR[14] for LAA over-write work-around */
2269 if (adapter->hw.mac_type == e1000_82571)
2272 /* Check for Promiscuous and All Multicast modes */
2274 rctl = E1000_READ_REG(hw, RCTL);
2276 if (netdev->flags & IFF_PROMISC) {
2277 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2278 } else if (netdev->flags & IFF_ALLMULTI) {
2279 rctl |= E1000_RCTL_MPE;
2280 rctl &= ~E1000_RCTL_UPE;
2282 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2285 E1000_WRITE_REG(hw, RCTL, rctl);
2287 /* 82542 2.0 needs to be in reset to write receive address registers */
2289 if (hw->mac_type == e1000_82542_rev2_0)
2290 e1000_enter_82542_rst(adapter);
2292 /* load the first 14 multicast address into the exact filters 1-14
2293 * RAR 0 is used for the station MAC adddress
2294 * if there are not 14 addresses, go ahead and clear the filters
2295 * -- with 82571 controllers only 0-13 entries are filled here
2297 mc_ptr = netdev->mc_list;
2299 for (i = 1; i < rar_entries; i++) {
2301 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2302 mc_ptr = mc_ptr->next;
2304 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2305 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2309 /* clear the old settings from the multicast hash table */
2311 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2312 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2314 /* load any remaining addresses into the hash table */
2316 for (; mc_ptr; mc_ptr = mc_ptr->next) {
2317 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2318 e1000_mta_set(hw, hash_value);
2321 if (hw->mac_type == e1000_82542_rev2_0)
2322 e1000_leave_82542_rst(adapter);
2325 /* Need to wait a few seconds after link up to get diagnostic information from
2329 e1000_update_phy_info(unsigned long data)
2331 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2332 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2336 * e1000_82547_tx_fifo_stall - Timer Call-back
2337 * @data: pointer to adapter cast into an unsigned long
2341 e1000_82547_tx_fifo_stall(unsigned long data)
2343 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2344 struct net_device *netdev = adapter->netdev;
2347 if (atomic_read(&adapter->tx_fifo_stall)) {
2348 if ((E1000_READ_REG(&adapter->hw, TDT) ==
2349 E1000_READ_REG(&adapter->hw, TDH)) &&
2350 (E1000_READ_REG(&adapter->hw, TDFT) ==
2351 E1000_READ_REG(&adapter->hw, TDFH)) &&
2352 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2353 E1000_READ_REG(&adapter->hw, TDFHS))) {
2354 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2355 E1000_WRITE_REG(&adapter->hw, TCTL,
2356 tctl & ~E1000_TCTL_EN);
2357 E1000_WRITE_REG(&adapter->hw, TDFT,
2358 adapter->tx_head_addr);
2359 E1000_WRITE_REG(&adapter->hw, TDFH,
2360 adapter->tx_head_addr);
2361 E1000_WRITE_REG(&adapter->hw, TDFTS,
2362 adapter->tx_head_addr);
2363 E1000_WRITE_REG(&adapter->hw, TDFHS,
2364 adapter->tx_head_addr);
2365 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2366 E1000_WRITE_FLUSH(&adapter->hw);
2368 adapter->tx_fifo_head = 0;
2369 atomic_set(&adapter->tx_fifo_stall, 0);
2370 netif_wake_queue(netdev);
2372 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2378 * e1000_watchdog - Timer Call-back
2379 * @data: pointer to adapter cast into an unsigned long
2382 e1000_watchdog(unsigned long data)
2384 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2386 /* Do the rest outside of interrupt context */
2387 schedule_work(&adapter->watchdog_task);
2391 e1000_watchdog_task(struct e1000_adapter *adapter)
2393 struct net_device *netdev = adapter->netdev;
2394 struct e1000_tx_ring *txdr = adapter->tx_ring;
2397 e1000_check_for_link(&adapter->hw);
2398 if (adapter->hw.mac_type == e1000_82573) {
2399 e1000_enable_tx_pkt_filtering(&adapter->hw);
2400 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2401 e1000_update_mng_vlan(adapter);
2404 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2405 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2406 link = !adapter->hw.serdes_link_down;
2408 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2411 if (!netif_carrier_ok(netdev)) {
2412 e1000_get_speed_and_duplex(&adapter->hw,
2413 &adapter->link_speed,
2414 &adapter->link_duplex);
2416 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2417 adapter->link_speed,
2418 adapter->link_duplex == FULL_DUPLEX ?
2419 "Full Duplex" : "Half Duplex");
2421 /* tweak tx_queue_len according to speed/duplex */
2422 netdev->tx_queue_len = adapter->tx_queue_len;
2423 adapter->tx_timeout_factor = 1;
2424 if (adapter->link_duplex == HALF_DUPLEX) {
2425 switch (adapter->link_speed) {
2427 netdev->tx_queue_len = 10;
2428 adapter->tx_timeout_factor = 8;
2431 netdev->tx_queue_len = 100;
2436 netif_carrier_on(netdev);
2437 netif_wake_queue(netdev);
2438 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2439 adapter->smartspeed = 0;
2442 if (netif_carrier_ok(netdev)) {
2443 adapter->link_speed = 0;
2444 adapter->link_duplex = 0;
2445 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2446 netif_carrier_off(netdev);
2447 netif_stop_queue(netdev);
2448 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2451 e1000_smartspeed(adapter);
2454 e1000_update_stats(adapter);
2456 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2457 adapter->tpt_old = adapter->stats.tpt;
2458 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2459 adapter->colc_old = adapter->stats.colc;
2461 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2462 adapter->gorcl_old = adapter->stats.gorcl;
2463 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2464 adapter->gotcl_old = adapter->stats.gotcl;
2466 e1000_update_adaptive(&adapter->hw);
2468 #ifdef CONFIG_E1000_MQ
2469 txdr = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2471 if (!netif_carrier_ok(netdev)) {
2472 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2473 /* We've lost link, so the controller stops DMA,
2474 * but we've got queued Tx work that's never going
2475 * to get done, so reset controller to flush Tx.
2476 * (Do the reset outside of interrupt context). */
2477 schedule_work(&adapter->tx_timeout_task);
2481 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2482 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2483 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2484 * asymmetrical Tx or Rx gets ITR=8000; everyone
2485 * else is between 2000-8000. */
2486 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2487 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2488 adapter->gotcl - adapter->gorcl :
2489 adapter->gorcl - adapter->gotcl) / 10000;
2490 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2491 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2494 /* Cause software interrupt to ensure rx ring is cleaned */
2495 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2497 /* Force detection of hung controller every watchdog period */
2498 adapter->detect_tx_hung = TRUE;
2500 /* With 82571 controllers, LAA may be overwritten due to controller
2501 * reset from the other port. Set the appropriate LAA in RAR[0] */
2502 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2503 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2505 /* Reset the timer */
2506 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2509 #define E1000_TX_FLAGS_CSUM 0x00000001
2510 #define E1000_TX_FLAGS_VLAN 0x00000002
2511 #define E1000_TX_FLAGS_TSO 0x00000004
2512 #define E1000_TX_FLAGS_IPV4 0x00000008
2513 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2514 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2517 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2518 struct sk_buff *skb)
2521 struct e1000_context_desc *context_desc;
2522 struct e1000_buffer *buffer_info;
2524 uint32_t cmd_length = 0;
2525 uint16_t ipcse = 0, tucse, mss;
2526 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2529 if (skb_shinfo(skb)->tso_size) {
2530 if (skb_header_cloned(skb)) {
2531 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2536 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2537 mss = skb_shinfo(skb)->tso_size;
2538 if (skb->protocol == ntohs(ETH_P_IP)) {
2539 skb->nh.iph->tot_len = 0;
2540 skb->nh.iph->check = 0;
2542 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2547 cmd_length = E1000_TXD_CMD_IP;
2548 ipcse = skb->h.raw - skb->data - 1;
2549 #ifdef NETIF_F_TSO_IPV6
2550 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
2551 skb->nh.ipv6h->payload_len = 0;
2553 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2554 &skb->nh.ipv6h->daddr,
2561 ipcss = skb->nh.raw - skb->data;
2562 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2563 tucss = skb->h.raw - skb->data;
2564 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2567 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2568 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2570 i = tx_ring->next_to_use;
2571 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2572 buffer_info = &tx_ring->buffer_info[i];
2574 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2575 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2576 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2577 context_desc->upper_setup.tcp_fields.tucss = tucss;
2578 context_desc->upper_setup.tcp_fields.tucso = tucso;
2579 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2580 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2581 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2582 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2584 buffer_info->time_stamp = jiffies;
2586 if (++i == tx_ring->count) i = 0;
2587 tx_ring->next_to_use = i;
2596 static inline boolean_t
2597 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2598 struct sk_buff *skb)
2600 struct e1000_context_desc *context_desc;
2601 struct e1000_buffer *buffer_info;
2605 if (likely(skb->ip_summed == CHECKSUM_HW)) {
2606 css = skb->h.raw - skb->data;
2608 i = tx_ring->next_to_use;
2609 buffer_info = &tx_ring->buffer_info[i];
2610 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2612 context_desc->upper_setup.tcp_fields.tucss = css;
2613 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2614 context_desc->upper_setup.tcp_fields.tucse = 0;
2615 context_desc->tcp_seg_setup.data = 0;
2616 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2618 buffer_info->time_stamp = jiffies;
2620 if (unlikely(++i == tx_ring->count)) i = 0;
2621 tx_ring->next_to_use = i;
2629 #define E1000_MAX_TXD_PWR 12
2630 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2633 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2634 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2635 unsigned int nr_frags, unsigned int mss)
2637 struct e1000_buffer *buffer_info;
2638 unsigned int len = skb->len;
2639 unsigned int offset = 0, size, count = 0, i;
2641 len -= skb->data_len;
2643 i = tx_ring->next_to_use;
2646 buffer_info = &tx_ring->buffer_info[i];
2647 size = min(len, max_per_txd);
2649 /* Workaround for Controller erratum --
2650 * descriptor for non-tso packet in a linear SKB that follows a
2651 * tso gets written back prematurely before the data is fully
2652 * DMAd to the controller */
2653 if (!skb->data_len && tx_ring->last_tx_tso &&
2654 !skb_shinfo(skb)->tso_size) {
2655 tx_ring->last_tx_tso = 0;
2659 /* Workaround for premature desc write-backs
2660 * in TSO mode. Append 4-byte sentinel desc */
2661 if (unlikely(mss && !nr_frags && size == len && size > 8))
2664 /* work-around for errata 10 and it applies
2665 * to all controllers in PCI-X mode
2666 * The fix is to make sure that the first descriptor of a
2667 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2669 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2670 (size > 2015) && count == 0))
2673 /* Workaround for potential 82544 hang in PCI-X. Avoid
2674 * terminating buffers within evenly-aligned dwords. */
2675 if (unlikely(adapter->pcix_82544 &&
2676 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2680 buffer_info->length = size;
2682 pci_map_single(adapter->pdev,
2686 buffer_info->time_stamp = jiffies;
2691 if (unlikely(++i == tx_ring->count)) i = 0;
2694 for (f = 0; f < nr_frags; f++) {
2695 struct skb_frag_struct *frag;
2697 frag = &skb_shinfo(skb)->frags[f];
2699 offset = frag->page_offset;
2702 buffer_info = &tx_ring->buffer_info[i];
2703 size = min(len, max_per_txd);
2705 /* Workaround for premature desc write-backs
2706 * in TSO mode. Append 4-byte sentinel desc */
2707 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2710 /* Workaround for potential 82544 hang in PCI-X.
2711 * Avoid terminating buffers within evenly-aligned
2713 if (unlikely(adapter->pcix_82544 &&
2714 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2718 buffer_info->length = size;
2720 pci_map_page(adapter->pdev,
2725 buffer_info->time_stamp = jiffies;
2730 if (unlikely(++i == tx_ring->count)) i = 0;
2734 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2735 tx_ring->buffer_info[i].skb = skb;
2736 tx_ring->buffer_info[first].next_to_watch = i;
2742 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2743 int tx_flags, int count)
2745 struct e1000_tx_desc *tx_desc = NULL;
2746 struct e1000_buffer *buffer_info;
2747 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2750 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2751 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2753 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2755 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
2756 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2759 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2760 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2761 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2764 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2765 txd_lower |= E1000_TXD_CMD_VLE;
2766 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2769 i = tx_ring->next_to_use;
2772 buffer_info = &tx_ring->buffer_info[i];
2773 tx_desc = E1000_TX_DESC(*tx_ring, i);
2774 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2775 tx_desc->lower.data =
2776 cpu_to_le32(txd_lower | buffer_info->length);
2777 tx_desc->upper.data = cpu_to_le32(txd_upper);
2778 if (unlikely(++i == tx_ring->count)) i = 0;
2781 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2783 /* Force memory writes to complete before letting h/w
2784 * know there are new descriptors to fetch. (Only
2785 * applicable for weak-ordered memory model archs,
2786 * such as IA-64). */
2789 tx_ring->next_to_use = i;
2790 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2794 * 82547 workaround to avoid controller hang in half-duplex environment.
2795 * The workaround is to avoid queuing a large packet that would span
2796 * the internal Tx FIFO ring boundary by notifying the stack to resend
2797 * the packet at a later time. This gives the Tx FIFO an opportunity to
2798 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2799 * to the beginning of the Tx FIFO.
2802 #define E1000_FIFO_HDR 0x10
2803 #define E1000_82547_PAD_LEN 0x3E0
2806 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2808 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2809 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2811 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2813 if (adapter->link_duplex != HALF_DUPLEX)
2814 goto no_fifo_stall_required;
2816 if (atomic_read(&adapter->tx_fifo_stall))
2819 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2820 atomic_set(&adapter->tx_fifo_stall, 1);
2824 no_fifo_stall_required:
2825 adapter->tx_fifo_head += skb_fifo_len;
2826 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
2827 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2831 #define MINIMUM_DHCP_PACKET_SIZE 282
2833 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2835 struct e1000_hw *hw = &adapter->hw;
2836 uint16_t length, offset;
2837 if (vlan_tx_tag_present(skb)) {
2838 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2839 ( adapter->hw.mng_cookie.status &
2840 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2843 if ((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
2844 struct ethhdr *eth = (struct ethhdr *) skb->data;
2845 if ((htons(ETH_P_IP) == eth->h_proto)) {
2846 const struct iphdr *ip =
2847 (struct iphdr *)((uint8_t *)skb->data+14);
2848 if (IPPROTO_UDP == ip->protocol) {
2849 struct udphdr *udp =
2850 (struct udphdr *)((uint8_t *)ip +
2852 if (ntohs(udp->dest) == 67) {
2853 offset = (uint8_t *)udp + 8 - skb->data;
2854 length = skb->len - offset;
2856 return e1000_mng_write_dhcp_info(hw,
2866 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2868 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2870 struct e1000_adapter *adapter = netdev_priv(netdev);
2871 struct e1000_tx_ring *tx_ring;
2872 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2873 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2874 unsigned int tx_flags = 0;
2875 unsigned int len = skb->len;
2876 unsigned long flags;
2877 unsigned int nr_frags = 0;
2878 unsigned int mss = 0;
2882 len -= skb->data_len;
2884 #ifdef CONFIG_E1000_MQ
2885 tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2887 tx_ring = adapter->tx_ring;
2890 if (unlikely(skb->len <= 0)) {
2891 dev_kfree_skb_any(skb);
2892 return NETDEV_TX_OK;
2896 mss = skb_shinfo(skb)->tso_size;
2897 /* The controller does a simple calculation to
2898 * make sure there is enough room in the FIFO before
2899 * initiating the DMA for each buffer. The calc is:
2900 * 4 = ceil(buffer len/mss). To make sure we don't
2901 * overrun the FIFO, adjust the max buffer len if mss
2905 max_per_txd = min(mss << 2, max_per_txd);
2906 max_txd_pwr = fls(max_per_txd) - 1;
2908 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2909 * points to just header, pull a few bytes of payload from
2910 * frags into skb->data */
2911 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2912 if (skb->data_len && (hdr_len == (skb->len - skb->data_len)) &&
2913 (adapter->hw.mac_type == e1000_82571 ||
2914 adapter->hw.mac_type == e1000_82572)) {
2915 unsigned int pull_size;
2916 pull_size = min((unsigned int)4, skb->data_len);
2917 if (!__pskb_pull_tail(skb, pull_size)) {
2918 printk(KERN_ERR "__pskb_pull_tail failed.\n");
2919 dev_kfree_skb_any(skb);
2920 return NETDEV_TX_OK;
2922 len = skb->len - skb->data_len;
2926 /* reserve a descriptor for the offload context */
2927 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
2931 if (skb->ip_summed == CHECKSUM_HW)
2936 /* Controller Erratum workaround */
2937 if (!skb->data_len && tx_ring->last_tx_tso &&
2938 !skb_shinfo(skb)->tso_size)
2942 count += TXD_USE_COUNT(len, max_txd_pwr);
2944 if (adapter->pcix_82544)
2947 /* work-around for errata 10 and it applies to all controllers
2948 * in PCI-X mode, so add one more descriptor to the count
2950 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2954 nr_frags = skb_shinfo(skb)->nr_frags;
2955 for (f = 0; f < nr_frags; f++)
2956 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2958 if (adapter->pcix_82544)
2961 if (adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2962 e1000_transfer_dhcp_info(adapter, skb);
2964 local_irq_save(flags);
2965 if (!spin_trylock(&tx_ring->tx_lock)) {
2966 /* Collision - tell upper layer to requeue */
2967 local_irq_restore(flags);
2968 return NETDEV_TX_LOCKED;
2971 /* need: count + 2 desc gap to keep tail from touching
2972 * head, otherwise try next time */
2973 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2974 netif_stop_queue(netdev);
2975 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2976 return NETDEV_TX_BUSY;
2979 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2980 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2981 netif_stop_queue(netdev);
2982 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2983 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2984 return NETDEV_TX_BUSY;
2988 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2989 tx_flags |= E1000_TX_FLAGS_VLAN;
2990 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2993 first = tx_ring->next_to_use;
2995 tso = e1000_tso(adapter, tx_ring, skb);
2997 dev_kfree_skb_any(skb);
2998 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2999 return NETDEV_TX_OK;
3003 tx_ring->last_tx_tso = 1;
3004 tx_flags |= E1000_TX_FLAGS_TSO;
3005 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
3006 tx_flags |= E1000_TX_FLAGS_CSUM;
3008 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3009 * 82571 hardware supports TSO capabilities for IPv6 as well...
3010 * no longer assume, we must. */
3011 if (likely(skb->protocol == ntohs(ETH_P_IP)))
3012 tx_flags |= E1000_TX_FLAGS_IPV4;
3014 e1000_tx_queue(adapter, tx_ring, tx_flags,
3015 e1000_tx_map(adapter, tx_ring, skb, first,
3016 max_per_txd, nr_frags, mss));
3018 netdev->trans_start = jiffies;
3020 /* Make sure there is space in the ring for the next send. */
3021 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
3022 netif_stop_queue(netdev);
3024 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
3025 return NETDEV_TX_OK;
3029 * e1000_tx_timeout - Respond to a Tx Hang
3030 * @netdev: network interface device structure
3034 e1000_tx_timeout(struct net_device *netdev)
3036 struct e1000_adapter *adapter = netdev_priv(netdev);
3038 /* Do the reset outside of interrupt context */
3039 schedule_work(&adapter->tx_timeout_task);
3043 e1000_tx_timeout_task(struct net_device *netdev)
3045 struct e1000_adapter *adapter = netdev_priv(netdev);
3047 adapter->tx_timeout_count++;
3048 e1000_down(adapter);
3053 * e1000_get_stats - Get System Network Statistics
3054 * @netdev: network interface device structure
3056 * Returns the address of the device statistics structure.
3057 * The statistics are actually updated from the timer callback.
3060 static struct net_device_stats *
3061 e1000_get_stats(struct net_device *netdev)
3063 struct e1000_adapter *adapter = netdev_priv(netdev);
3065 /* only return the current stats */
3066 return &adapter->net_stats;
3070 * e1000_change_mtu - Change the Maximum Transfer Unit
3071 * @netdev: network interface device structure
3072 * @new_mtu: new value for maximum frame size
3074 * Returns 0 on success, negative on failure
3078 e1000_change_mtu(struct net_device *netdev, int new_mtu)
3080 struct e1000_adapter *adapter = netdev_priv(netdev);
3081 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3083 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3084 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3085 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3089 /* Adapter-specific max frame size limits. */
3090 switch (adapter->hw.mac_type) {
3091 case e1000_82542_rev2_0:
3092 case e1000_82542_rev2_1:
3094 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3095 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3101 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3102 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3103 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3108 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3113 if (adapter->hw.mac_type > e1000_82547_rev_2) {
3114 adapter->rx_buffer_len = max_frame;
3115 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
3117 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
3118 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
3119 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
3123 if(max_frame <= E1000_RXBUFFER_2048)
3124 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3125 else if(max_frame <= E1000_RXBUFFER_4096)
3126 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3127 else if(max_frame <= E1000_RXBUFFER_8192)
3128 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3129 else if(max_frame <= E1000_RXBUFFER_16384)
3130 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3134 netdev->mtu = new_mtu;
3136 if (netif_running(netdev)) {
3137 e1000_down(adapter);
3141 adapter->hw.max_frame_size = max_frame;
3147 * e1000_update_stats - Update the board statistics counters
3148 * @adapter: board private structure
3152 e1000_update_stats(struct e1000_adapter *adapter)
3154 struct e1000_hw *hw = &adapter->hw;
3155 unsigned long flags;
3158 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3160 spin_lock_irqsave(&adapter->stats_lock, flags);
3162 /* these counters are modified from e1000_adjust_tbi_stats,
3163 * called from the interrupt context, so they must only
3164 * be written while holding adapter->stats_lock
3167 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3168 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3169 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3170 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3171 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3172 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3173 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3174 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3175 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3176 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3177 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3178 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3179 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3181 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3182 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3183 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3184 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3185 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3186 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3187 adapter->stats.dc += E1000_READ_REG(hw, DC);
3188 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3189 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3190 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3191 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3192 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3193 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3194 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3195 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3196 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3197 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3198 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3199 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3200 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3201 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3202 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3203 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3204 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3205 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3206 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3207 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3208 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3209 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3210 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3211 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3212 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3213 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3214 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3216 /* used for adaptive IFS */
3218 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3219 adapter->stats.tpt += hw->tx_packet_delta;
3220 hw->collision_delta = E1000_READ_REG(hw, COLC);
3221 adapter->stats.colc += hw->collision_delta;
3223 if (hw->mac_type >= e1000_82543) {
3224 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3225 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3226 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3227 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3228 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3229 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3231 if (hw->mac_type > e1000_82547_rev_2) {
3232 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3233 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3234 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3235 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3236 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3237 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3238 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3239 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3240 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3243 /* Fill out the OS statistics structure */
3245 adapter->net_stats.rx_packets = adapter->stats.gprc;
3246 adapter->net_stats.tx_packets = adapter->stats.gptc;
3247 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3248 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3249 adapter->net_stats.multicast = adapter->stats.mprc;
3250 adapter->net_stats.collisions = adapter->stats.colc;
3254 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3255 adapter->stats.crcerrs + adapter->stats.algnerrc +
3256 adapter->stats.rlec + adapter->stats.cexterr;
3257 adapter->net_stats.rx_dropped = 0;
3258 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3259 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3260 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3261 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3265 adapter->net_stats.tx_errors = adapter->stats.ecol +
3266 adapter->stats.latecol;
3267 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3268 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3269 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3271 /* Tx Dropped needs to be maintained elsewhere */
3275 if (hw->media_type == e1000_media_type_copper) {
3276 if ((adapter->link_speed == SPEED_1000) &&
3277 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3278 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3279 adapter->phy_stats.idle_errors += phy_tmp;
3282 if ((hw->mac_type <= e1000_82546) &&
3283 (hw->phy_type == e1000_phy_m88) &&
3284 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3285 adapter->phy_stats.receive_errors += phy_tmp;
3288 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3291 #ifdef CONFIG_E1000_MQ
3293 e1000_rx_schedule(void *data)
3295 struct net_device *poll_dev, *netdev = data;
3296 struct e1000_adapter *adapter = netdev->priv;
3297 int this_cpu = get_cpu();
3299 poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
3300 if (poll_dev == NULL) {
3305 if (likely(netif_rx_schedule_prep(poll_dev)))
3306 __netif_rx_schedule(poll_dev);
3308 e1000_irq_enable(adapter);
3315 * e1000_intr - Interrupt Handler
3316 * @irq: interrupt number
3317 * @data: pointer to a network interface device structure
3318 * @pt_regs: CPU registers structure
3322 e1000_intr(int irq, void *data, struct pt_regs *regs)
3324 struct net_device *netdev = data;
3325 struct e1000_adapter *adapter = netdev_priv(netdev);
3326 struct e1000_hw *hw = &adapter->hw;
3327 uint32_t icr = E1000_READ_REG(hw, ICR);
3328 #ifndef CONFIG_E1000_NAPI
3331 /* Interrupt Auto-Mask...upon reading ICR,
3332 * interrupts are masked. No need for the
3333 * IMC write, but it does mean we should
3334 * account for it ASAP. */
3335 if (likely(hw->mac_type >= e1000_82571))
3336 atomic_inc(&adapter->irq_sem);
3339 if (unlikely(!icr)) {
3340 #ifdef CONFIG_E1000_NAPI
3341 if (hw->mac_type >= e1000_82571)
3342 e1000_irq_enable(adapter);
3344 return IRQ_NONE; /* Not our interrupt */
3347 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3348 hw->get_link_status = 1;
3349 mod_timer(&adapter->watchdog_timer, jiffies);
3352 #ifdef CONFIG_E1000_NAPI
3353 if (unlikely(hw->mac_type < e1000_82571)) {
3354 atomic_inc(&adapter->irq_sem);
3355 E1000_WRITE_REG(hw, IMC, ~0);
3356 E1000_WRITE_FLUSH(hw);
3358 #ifdef CONFIG_E1000_MQ
3359 if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
3360 /* We must setup the cpumask once count == 0 since
3361 * each cpu bit is cleared when the work is done. */
3362 adapter->rx_sched_call_data.cpumask = adapter->cpumask;
3363 atomic_add(adapter->num_rx_queues - 1, &adapter->irq_sem);
3364 atomic_set(&adapter->rx_sched_call_data.count,
3365 adapter->num_rx_queues);
3366 smp_call_async_mask(&adapter->rx_sched_call_data);
3368 printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
3370 #else /* if !CONFIG_E1000_MQ */
3371 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3372 __netif_rx_schedule(&adapter->polling_netdev[0]);
3374 e1000_irq_enable(adapter);
3375 #endif /* CONFIG_E1000_MQ */
3377 #else /* if !CONFIG_E1000_NAPI */
3378 /* Writing IMC and IMS is needed for 82547.
3379 * Due to Hub Link bus being occupied, an interrupt
3380 * de-assertion message is not able to be sent.
3381 * When an interrupt assertion message is generated later,
3382 * two messages are re-ordered and sent out.
3383 * That causes APIC to think 82547 is in de-assertion
3384 * state, while 82547 is in assertion state, resulting
3385 * in dead lock. Writing IMC forces 82547 into
3386 * de-assertion state.
3388 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
3389 atomic_inc(&adapter->irq_sem);
3390 E1000_WRITE_REG(hw, IMC, ~0);
3393 for (i = 0; i < E1000_MAX_INTR; i++)
3394 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3395 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3398 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3399 e1000_irq_enable(adapter);
3401 #endif /* CONFIG_E1000_NAPI */
3406 #ifdef CONFIG_E1000_NAPI
3408 * e1000_clean - NAPI Rx polling callback
3409 * @adapter: board private structure
3413 e1000_clean(struct net_device *poll_dev, int *budget)
3415 struct e1000_adapter *adapter;
3416 int work_to_do = min(*budget, poll_dev->quota);
3417 int tx_cleaned = 0, i = 0, work_done = 0;
3419 /* Must NOT use netdev_priv macro here. */
3420 adapter = poll_dev->priv;
3422 /* Keep link state information with original netdev */
3423 if (!netif_carrier_ok(adapter->netdev))
3426 while (poll_dev != &adapter->polling_netdev[i]) {
3428 if (unlikely(i == adapter->num_rx_queues))
3432 if (likely(adapter->num_tx_queues == 1)) {
3433 /* e1000_clean is called per-cpu. This lock protects
3434 * tx_ring[0] from being cleaned by multiple cpus
3435 * simultaneously. A failure obtaining the lock means
3436 * tx_ring[0] is currently being cleaned anyway. */
3437 if (spin_trylock(&adapter->tx_queue_lock)) {
3438 tx_cleaned = e1000_clean_tx_irq(adapter,
3439 &adapter->tx_ring[0]);
3440 spin_unlock(&adapter->tx_queue_lock);
3443 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3445 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3446 &work_done, work_to_do);
3448 *budget -= work_done;
3449 poll_dev->quota -= work_done;
3451 /* If no Tx and not enough Rx work done, exit the polling mode */
3452 if ((!tx_cleaned && (work_done == 0)) ||
3453 !netif_running(adapter->netdev)) {
3455 netif_rx_complete(poll_dev);
3456 e1000_irq_enable(adapter);
3465 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3466 * @adapter: board private structure
3470 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3471 struct e1000_tx_ring *tx_ring)
3473 struct net_device *netdev = adapter->netdev;
3474 struct e1000_tx_desc *tx_desc, *eop_desc;
3475 struct e1000_buffer *buffer_info;
3476 unsigned int i, eop;
3477 boolean_t cleaned = FALSE;
3479 i = tx_ring->next_to_clean;
3480 eop = tx_ring->buffer_info[i].next_to_watch;
3481 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3483 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3484 for (cleaned = FALSE; !cleaned; ) {
3485 tx_desc = E1000_TX_DESC(*tx_ring, i);
3486 buffer_info = &tx_ring->buffer_info[i];
3487 cleaned = (i == eop);
3489 #ifdef CONFIG_E1000_MQ
3490 tx_ring->tx_stats.bytes += buffer_info->length;
3492 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3493 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
3495 if (unlikely(++i == tx_ring->count)) i = 0;
3498 #ifdef CONFIG_E1000_MQ
3499 tx_ring->tx_stats.packets++;
3502 eop = tx_ring->buffer_info[i].next_to_watch;
3503 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3506 tx_ring->next_to_clean = i;
3508 spin_lock(&tx_ring->tx_lock);
3510 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
3511 netif_carrier_ok(netdev)))
3512 netif_wake_queue(netdev);
3514 spin_unlock(&tx_ring->tx_lock);
3516 if (adapter->detect_tx_hung) {
3517 /* Detect a transmit hang in hardware, this serializes the
3518 * check with the clearing of time_stamp and movement of i */
3519 adapter->detect_tx_hung = FALSE;
3520 if (tx_ring->buffer_info[eop].dma &&
3521 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3522 adapter->tx_timeout_factor * HZ)
3523 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3524 E1000_STATUS_TXOFF)) {
3526 /* detected Tx unit hang */
3527 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3531 " next_to_use <%x>\n"
3532 " next_to_clean <%x>\n"
3533 "buffer_info[next_to_clean]\n"
3534 " time_stamp <%lx>\n"
3535 " next_to_watch <%x>\n"
3537 " next_to_watch.status <%x>\n",
3538 (unsigned long)((tx_ring - adapter->tx_ring) /
3539 sizeof(struct e1000_tx_ring)),
3540 readl(adapter->hw.hw_addr + tx_ring->tdh),
3541 readl(adapter->hw.hw_addr + tx_ring->tdt),
3542 tx_ring->next_to_use,
3543 tx_ring->next_to_clean,
3544 tx_ring->buffer_info[eop].time_stamp,
3547 eop_desc->upper.fields.status);
3548 netif_stop_queue(netdev);
3555 * e1000_rx_checksum - Receive Checksum Offload for 82543
3556 * @adapter: board private structure
3557 * @status_err: receive descriptor status and error fields
3558 * @csum: receive descriptor csum field
3559 * @sk_buff: socket buffer with received data
3563 e1000_rx_checksum(struct e1000_adapter *adapter,
3564 uint32_t status_err, uint32_t csum,
3565 struct sk_buff *skb)
3567 uint16_t status = (uint16_t)status_err;
3568 uint8_t errors = (uint8_t)(status_err >> 24);
3569 skb->ip_summed = CHECKSUM_NONE;
3571 /* 82543 or newer only */
3572 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
3573 /* Ignore Checksum bit is set */
3574 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
3575 /* TCP/UDP checksum error bit is set */
3576 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3577 /* let the stack verify checksum errors */
3578 adapter->hw_csum_err++;
3581 /* TCP/UDP Checksum has not been calculated */
3582 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3583 if (!(status & E1000_RXD_STAT_TCPCS))
3586 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3589 /* It must be a TCP or UDP packet with a valid checksum */
3590 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3591 /* TCP checksum is good */
3592 skb->ip_summed = CHECKSUM_UNNECESSARY;
3593 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3594 /* IP fragment with UDP payload */
3595 /* Hardware complements the payload checksum, so we undo it
3596 * and then put the value in host order for further stack use.
3598 csum = ntohl(csum ^ 0xFFFF);
3600 skb->ip_summed = CHECKSUM_HW;
3602 adapter->hw_csum_good++;
3606 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3607 * @adapter: board private structure
3611 #ifdef CONFIG_E1000_NAPI
3612 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3613 struct e1000_rx_ring *rx_ring,
3614 int *work_done, int work_to_do)
3616 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3617 struct e1000_rx_ring *rx_ring)
3620 struct net_device *netdev = adapter->netdev;
3621 struct pci_dev *pdev = adapter->pdev;
3622 struct e1000_rx_desc *rx_desc, *next_rxd;
3623 struct e1000_buffer *buffer_info, *next_buffer;
3624 unsigned long flags;
3628 int cleaned_count = 0;
3629 boolean_t cleaned = FALSE;
3631 i = rx_ring->next_to_clean;
3632 rx_desc = E1000_RX_DESC(*rx_ring, i);
3633 buffer_info = &rx_ring->buffer_info[i];
3635 while (rx_desc->status & E1000_RXD_STAT_DD) {
3636 struct sk_buff *skb, *next_skb;
3638 #ifdef CONFIG_E1000_NAPI
3639 if (*work_done >= work_to_do)
3643 status = rx_desc->status;
3644 skb = buffer_info->skb;
3645 buffer_info->skb = NULL;
3647 if (++i == rx_ring->count) i = 0;
3648 next_rxd = E1000_RX_DESC(*rx_ring, i);
3649 next_buffer = &rx_ring->buffer_info[i];
3650 next_skb = next_buffer->skb;
3654 pci_unmap_single(pdev,
3656 buffer_info->length,
3657 PCI_DMA_FROMDEVICE);
3659 length = le16_to_cpu(rx_desc->length);
3661 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3662 /* All receives must fit into a single buffer */
3663 E1000_DBG("%s: Receive packet consumed multiple"
3664 " buffers\n", netdev->name);
3665 dev_kfree_skb_irq(skb);
3669 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3670 last_byte = *(skb->data + length - 1);
3671 if (TBI_ACCEPT(&adapter->hw, status,
3672 rx_desc->errors, length, last_byte)) {
3673 spin_lock_irqsave(&adapter->stats_lock, flags);
3674 e1000_tbi_adjust_stats(&adapter->hw,
3677 spin_unlock_irqrestore(&adapter->stats_lock,
3681 dev_kfree_skb_irq(skb);
3686 /* code added for copybreak, this should improve
3687 * performance for small packets with large amounts
3688 * of reassembly being done in the stack */
3689 #define E1000_CB_LENGTH 256
3690 if (length < E1000_CB_LENGTH) {
3691 struct sk_buff *new_skb =
3692 dev_alloc_skb(length + NET_IP_ALIGN);
3694 skb_reserve(new_skb, NET_IP_ALIGN);
3695 new_skb->dev = netdev;
3696 memcpy(new_skb->data - NET_IP_ALIGN,
3697 skb->data - NET_IP_ALIGN,
3698 length + NET_IP_ALIGN);
3699 /* save the skb in buffer_info as good */
3700 buffer_info->skb = skb;
3702 skb_put(skb, length);
3705 skb_put(skb, length);
3707 /* end copybreak code */
3709 /* Receive Checksum Offload */
3710 e1000_rx_checksum(adapter,
3711 (uint32_t)(status) |
3712 ((uint32_t)(rx_desc->errors) << 24),
3713 rx_desc->csum, skb);
3715 skb->protocol = eth_type_trans(skb, netdev);
3716 #ifdef CONFIG_E1000_NAPI
3717 if (unlikely(adapter->vlgrp &&
3718 (status & E1000_RXD_STAT_VP))) {
3719 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3720 le16_to_cpu(rx_desc->special) &
3721 E1000_RXD_SPC_VLAN_MASK);
3723 netif_receive_skb(skb);
3725 #else /* CONFIG_E1000_NAPI */
3726 if (unlikely(adapter->vlgrp &&
3727 (status & E1000_RXD_STAT_VP))) {
3728 vlan_hwaccel_rx(skb, adapter->vlgrp,
3729 le16_to_cpu(rx_desc->special) &
3730 E1000_RXD_SPC_VLAN_MASK);
3734 #endif /* CONFIG_E1000_NAPI */
3735 netdev->last_rx = jiffies;
3736 #ifdef CONFIG_E1000_MQ
3737 rx_ring->rx_stats.packets++;
3738 rx_ring->rx_stats.bytes += length;
3742 rx_desc->status = 0;
3744 /* return some buffers to hardware, one at a time is too slow */
3745 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3746 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3751 buffer_info = next_buffer;
3753 rx_ring->next_to_clean = i;
3755 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3757 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3763 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3764 * @adapter: board private structure
3768 #ifdef CONFIG_E1000_NAPI
3769 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3770 struct e1000_rx_ring *rx_ring,
3771 int *work_done, int work_to_do)
3773 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3774 struct e1000_rx_ring *rx_ring)
3777 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
3778 struct net_device *netdev = adapter->netdev;
3779 struct pci_dev *pdev = adapter->pdev;
3780 struct e1000_buffer *buffer_info, *next_buffer;
3781 struct e1000_ps_page *ps_page;
3782 struct e1000_ps_page_dma *ps_page_dma;
3783 struct sk_buff *skb, *next_skb;
3785 uint32_t length, staterr;
3786 int cleaned_count = 0;
3787 boolean_t cleaned = FALSE;
3789 i = rx_ring->next_to_clean;
3790 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3791 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3792 buffer_info = &rx_ring->buffer_info[i];
3794 while (staterr & E1000_RXD_STAT_DD) {
3795 ps_page = &rx_ring->ps_page[i];
3796 ps_page_dma = &rx_ring->ps_page_dma[i];
3797 #ifdef CONFIG_E1000_NAPI
3798 if (unlikely(*work_done >= work_to_do))
3802 skb = buffer_info->skb;
3804 if (++i == rx_ring->count) i = 0;
3805 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
3806 next_buffer = &rx_ring->buffer_info[i];
3807 next_skb = next_buffer->skb;
3811 pci_unmap_single(pdev, buffer_info->dma,
3812 buffer_info->length,
3813 PCI_DMA_FROMDEVICE);
3815 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3816 E1000_DBG("%s: Packet Split buffers didn't pick up"
3817 " the full packet\n", netdev->name);
3818 dev_kfree_skb_irq(skb);
3822 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3823 dev_kfree_skb_irq(skb);
3827 length = le16_to_cpu(rx_desc->wb.middle.length0);
3829 if (unlikely(!length)) {
3830 E1000_DBG("%s: Last part of the packet spanning"
3831 " multiple descriptors\n", netdev->name);
3832 dev_kfree_skb_irq(skb);
3837 skb_put(skb, length);
3839 for (j = 0; j < adapter->rx_ps_pages; j++) {
3840 if (!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3843 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3844 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3845 ps_page_dma->ps_page_dma[j] = 0;
3846 skb_shinfo(skb)->frags[j].page =
3847 ps_page->ps_page[j];
3848 ps_page->ps_page[j] = NULL;
3849 skb_shinfo(skb)->frags[j].page_offset = 0;
3850 skb_shinfo(skb)->frags[j].size = length;
3851 skb_shinfo(skb)->nr_frags++;
3853 skb->data_len += length;
3856 e1000_rx_checksum(adapter, staterr,
3857 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3858 skb->protocol = eth_type_trans(skb, netdev);
3860 if (likely(rx_desc->wb.upper.header_status &
3861 E1000_RXDPS_HDRSTAT_HDRSP))
3862 adapter->rx_hdr_split++;
3863 #ifdef CONFIG_E1000_NAPI
3864 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3865 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3866 le16_to_cpu(rx_desc->wb.middle.vlan) &
3867 E1000_RXD_SPC_VLAN_MASK);
3869 netif_receive_skb(skb);
3871 #else /* CONFIG_E1000_NAPI */
3872 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3873 vlan_hwaccel_rx(skb, adapter->vlgrp,
3874 le16_to_cpu(rx_desc->wb.middle.vlan) &
3875 E1000_RXD_SPC_VLAN_MASK);
3879 #endif /* CONFIG_E1000_NAPI */
3880 netdev->last_rx = jiffies;
3881 #ifdef CONFIG_E1000_MQ
3882 rx_ring->rx_stats.packets++;
3883 rx_ring->rx_stats.bytes += length;
3887 rx_desc->wb.middle.status_error &= ~0xFF;
3888 buffer_info->skb = NULL;
3890 /* return some buffers to hardware, one at a time is too slow */
3891 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3892 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3897 buffer_info = next_buffer;
3899 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3901 rx_ring->next_to_clean = i;
3903 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3905 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3911 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3912 * @adapter: address of board private structure
3916 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3917 struct e1000_rx_ring *rx_ring,
3920 struct net_device *netdev = adapter->netdev;
3921 struct pci_dev *pdev = adapter->pdev;
3922 struct e1000_rx_desc *rx_desc;
3923 struct e1000_buffer *buffer_info;
3924 struct sk_buff *skb;
3926 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3928 i = rx_ring->next_to_use;
3929 buffer_info = &rx_ring->buffer_info[i];
3931 while (cleaned_count--) {
3932 if (!(skb = buffer_info->skb))
3933 skb = dev_alloc_skb(bufsz);
3940 if (unlikely(!skb)) {
3941 /* Better luck next round */
3942 adapter->alloc_rx_buff_failed++;
3946 /* Fix for errata 23, can't cross 64kB boundary */
3947 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3948 struct sk_buff *oldskb = skb;
3949 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3950 "at %p\n", bufsz, skb->data);
3951 /* Try again, without freeing the previous */
3952 skb = dev_alloc_skb(bufsz);
3953 /* Failed allocation, critical failure */
3955 dev_kfree_skb(oldskb);
3959 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3962 dev_kfree_skb(oldskb);
3963 break; /* while !buffer_info->skb */
3965 /* Use new allocation */
3966 dev_kfree_skb(oldskb);
3969 /* Make buffer alignment 2 beyond a 16 byte boundary
3970 * this will result in a 16 byte aligned IP header after
3971 * the 14 byte MAC header is removed
3973 skb_reserve(skb, NET_IP_ALIGN);
3977 buffer_info->skb = skb;
3978 buffer_info->length = adapter->rx_buffer_len;
3980 buffer_info->dma = pci_map_single(pdev,
3982 adapter->rx_buffer_len,
3983 PCI_DMA_FROMDEVICE);
3985 /* Fix for errata 23, can't cross 64kB boundary */
3986 if (!e1000_check_64k_bound(adapter,
3987 (void *)(unsigned long)buffer_info->dma,
3988 adapter->rx_buffer_len)) {
3989 DPRINTK(RX_ERR, ERR,
3990 "dma align check failed: %u bytes at %p\n",
3991 adapter->rx_buffer_len,
3992 (void *)(unsigned long)buffer_info->dma);
3994 buffer_info->skb = NULL;
3996 pci_unmap_single(pdev, buffer_info->dma,
3997 adapter->rx_buffer_len,
3998 PCI_DMA_FROMDEVICE);
4000 break; /* while !buffer_info->skb */
4002 rx_desc = E1000_RX_DESC(*rx_ring, i);
4003 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4005 if (unlikely(++i == rx_ring->count))
4007 buffer_info = &rx_ring->buffer_info[i];
4010 if (likely(rx_ring->next_to_use != i)) {
4011 rx_ring->next_to_use = i;
4012 if (unlikely(i-- == 0))
4013 i = (rx_ring->count - 1);
4015 /* Force memory writes to complete before letting h/w
4016 * know there are new descriptors to fetch. (Only
4017 * applicable for weak-ordered memory model archs,
4018 * such as IA-64). */
4020 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4025 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4026 * @adapter: address of board private structure
4030 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
4031 struct e1000_rx_ring *rx_ring,
4034 struct net_device *netdev = adapter->netdev;
4035 struct pci_dev *pdev = adapter->pdev;
4036 union e1000_rx_desc_packet_split *rx_desc;
4037 struct e1000_buffer *buffer_info;
4038 struct e1000_ps_page *ps_page;
4039 struct e1000_ps_page_dma *ps_page_dma;
4040 struct sk_buff *skb;
4043 i = rx_ring->next_to_use;
4044 buffer_info = &rx_ring->buffer_info[i];
4045 ps_page = &rx_ring->ps_page[i];
4046 ps_page_dma = &rx_ring->ps_page_dma[i];
4048 while (cleaned_count--) {
4049 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4051 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
4052 if (j < adapter->rx_ps_pages) {
4053 if (likely(!ps_page->ps_page[j])) {
4054 ps_page->ps_page[j] =
4055 alloc_page(GFP_ATOMIC);
4056 if (unlikely(!ps_page->ps_page[j])) {
4057 adapter->alloc_rx_buff_failed++;
4060 ps_page_dma->ps_page_dma[j] =
4062 ps_page->ps_page[j],
4064 PCI_DMA_FROMDEVICE);
4066 /* Refresh the desc even if buffer_addrs didn't
4067 * change because each write-back erases
4070 rx_desc->read.buffer_addr[j+1] =
4071 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4073 rx_desc->read.buffer_addr[j+1] = ~0;
4076 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4078 if (unlikely(!skb)) {
4079 adapter->alloc_rx_buff_failed++;
4083 /* Make buffer alignment 2 beyond a 16 byte boundary
4084 * this will result in a 16 byte aligned IP header after
4085 * the 14 byte MAC header is removed
4087 skb_reserve(skb, NET_IP_ALIGN);
4091 buffer_info->skb = skb;
4092 buffer_info->length = adapter->rx_ps_bsize0;
4093 buffer_info->dma = pci_map_single(pdev, skb->data,
4094 adapter->rx_ps_bsize0,
4095 PCI_DMA_FROMDEVICE);
4097 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4099 if (unlikely(++i == rx_ring->count)) i = 0;
4100 buffer_info = &rx_ring->buffer_info[i];
4101 ps_page = &rx_ring->ps_page[i];
4102 ps_page_dma = &rx_ring->ps_page_dma[i];
4106 if (likely(rx_ring->next_to_use != i)) {
4107 rx_ring->next_to_use = i;
4108 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4110 /* Force memory writes to complete before letting h/w
4111 * know there are new descriptors to fetch. (Only
4112 * applicable for weak-ordered memory model archs,
4113 * such as IA-64). */
4115 /* Hardware increments by 16 bytes, but packet split
4116 * descriptors are 32 bytes...so we increment tail
4119 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4124 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4129 e1000_smartspeed(struct e1000_adapter *adapter)
4131 uint16_t phy_status;
4134 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4135 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4138 if (adapter->smartspeed == 0) {
4139 /* If Master/Slave config fault is asserted twice,
4140 * we assume back-to-back */
4141 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4142 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4143 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4144 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4145 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4146 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4147 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4148 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4150 adapter->smartspeed++;
4151 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4152 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4154 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4155 MII_CR_RESTART_AUTO_NEG);
4156 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4161 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4162 /* If still no link, perhaps using 2/3 pair cable */
4163 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4164 phy_ctrl |= CR_1000T_MS_ENABLE;
4165 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4166 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
4167 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4168 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4169 MII_CR_RESTART_AUTO_NEG);
4170 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4173 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4174 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4175 adapter->smartspeed = 0;
4186 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4192 return e1000_mii_ioctl(netdev, ifr, cmd);
4206 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4208 struct e1000_adapter *adapter = netdev_priv(netdev);
4209 struct mii_ioctl_data *data = if_mii(ifr);
4213 unsigned long flags;
4215 if (adapter->hw.media_type != e1000_media_type_copper)
4220 data->phy_id = adapter->hw.phy_addr;
4223 if (!capable(CAP_NET_ADMIN))
4225 spin_lock_irqsave(&adapter->stats_lock, flags);
4226 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4228 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4231 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4234 if (!capable(CAP_NET_ADMIN))
4236 if (data->reg_num & ~(0x1F))
4238 mii_reg = data->val_in;
4239 spin_lock_irqsave(&adapter->stats_lock, flags);
4240 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
4242 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4245 if (adapter->hw.phy_type == e1000_phy_m88) {
4246 switch (data->reg_num) {
4248 if (mii_reg & MII_CR_POWER_DOWN)
4250 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4251 adapter->hw.autoneg = 1;
4252 adapter->hw.autoneg_advertised = 0x2F;
4255 spddplx = SPEED_1000;
4256 else if (mii_reg & 0x2000)
4257 spddplx = SPEED_100;
4260 spddplx += (mii_reg & 0x100)
4263 retval = e1000_set_spd_dplx(adapter,
4266 spin_unlock_irqrestore(
4267 &adapter->stats_lock,
4272 if (netif_running(adapter->netdev)) {
4273 e1000_down(adapter);
4276 e1000_reset(adapter);
4278 case M88E1000_PHY_SPEC_CTRL:
4279 case M88E1000_EXT_PHY_SPEC_CTRL:
4280 if (e1000_phy_reset(&adapter->hw)) {
4281 spin_unlock_irqrestore(
4282 &adapter->stats_lock, flags);
4288 switch (data->reg_num) {
4290 if (mii_reg & MII_CR_POWER_DOWN)
4292 if (netif_running(adapter->netdev)) {
4293 e1000_down(adapter);
4296 e1000_reset(adapter);
4300 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4305 return E1000_SUCCESS;
4309 e1000_pci_set_mwi(struct e1000_hw *hw)
4311 struct e1000_adapter *adapter = hw->back;
4312 int ret_val = pci_set_mwi(adapter->pdev);
4315 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4319 e1000_pci_clear_mwi(struct e1000_hw *hw)
4321 struct e1000_adapter *adapter = hw->back;
4323 pci_clear_mwi(adapter->pdev);
4327 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4329 struct e1000_adapter *adapter = hw->back;
4331 pci_read_config_word(adapter->pdev, reg, value);
4335 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4337 struct e1000_adapter *adapter = hw->back;
4339 pci_write_config_word(adapter->pdev, reg, *value);
4343 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4349 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4355 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4357 struct e1000_adapter *adapter = netdev_priv(netdev);
4358 uint32_t ctrl, rctl;
4360 e1000_irq_disable(adapter);
4361 adapter->vlgrp = grp;
4364 /* enable VLAN tag insert/strip */
4365 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4366 ctrl |= E1000_CTRL_VME;
4367 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4369 /* enable VLAN receive filtering */
4370 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4371 rctl |= E1000_RCTL_VFE;
4372 rctl &= ~E1000_RCTL_CFIEN;
4373 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4374 e1000_update_mng_vlan(adapter);
4376 /* disable 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 /* disable VLAN filtering */
4382 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4383 rctl &= ~E1000_RCTL_VFE;
4384 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4385 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4386 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4387 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4391 e1000_irq_enable(adapter);
4395 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4397 struct e1000_adapter *adapter = netdev_priv(netdev);
4398 uint32_t vfta, index;
4400 if ((adapter->hw.mng_cookie.status &
4401 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4402 (vid == adapter->mng_vlan_id))
4404 /* add VID to filter table */
4405 index = (vid >> 5) & 0x7F;
4406 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4407 vfta |= (1 << (vid & 0x1F));
4408 e1000_write_vfta(&adapter->hw, index, vfta);
4412 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4414 struct e1000_adapter *adapter = netdev_priv(netdev);
4415 uint32_t vfta, index;
4417 e1000_irq_disable(adapter);
4420 adapter->vlgrp->vlan_devices[vid] = NULL;
4422 e1000_irq_enable(adapter);
4424 if ((adapter->hw.mng_cookie.status &
4425 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4426 (vid == adapter->mng_vlan_id)) {
4427 /* release control to f/w */
4428 e1000_release_hw_control(adapter);
4432 /* remove VID from filter table */
4433 index = (vid >> 5) & 0x7F;
4434 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4435 vfta &= ~(1 << (vid & 0x1F));
4436 e1000_write_vfta(&adapter->hw, index, vfta);
4440 e1000_restore_vlan(struct e1000_adapter *adapter)
4442 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4444 if (adapter->vlgrp) {
4446 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4447 if (!adapter->vlgrp->vlan_devices[vid])
4449 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4455 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4457 adapter->hw.autoneg = 0;
4459 /* Fiber NICs only allow 1000 gbps Full duplex */
4460 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
4461 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4462 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4467 case SPEED_10 + DUPLEX_HALF:
4468 adapter->hw.forced_speed_duplex = e1000_10_half;
4470 case SPEED_10 + DUPLEX_FULL:
4471 adapter->hw.forced_speed_duplex = e1000_10_full;
4473 case SPEED_100 + DUPLEX_HALF:
4474 adapter->hw.forced_speed_duplex = e1000_100_half;
4476 case SPEED_100 + DUPLEX_FULL:
4477 adapter->hw.forced_speed_duplex = e1000_100_full;
4479 case SPEED_1000 + DUPLEX_FULL:
4480 adapter->hw.autoneg = 1;
4481 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4483 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4485 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4492 /* these functions save and restore 16 or 64 dwords (64-256 bytes) of config
4493 * space versus the 64 bytes that pci_[save|restore]_state handle
4495 #define PCIE_CONFIG_SPACE_LEN 256
4496 #define PCI_CONFIG_SPACE_LEN 64
4498 e1000_pci_save_state(struct e1000_adapter *adapter)
4500 struct pci_dev *dev = adapter->pdev;
4503 if (adapter->hw.mac_type >= e1000_82571)
4504 size = PCIE_CONFIG_SPACE_LEN;
4506 size = PCI_CONFIG_SPACE_LEN;
4508 WARN_ON(adapter->config_space != NULL);
4510 adapter->config_space = kmalloc(size, GFP_KERNEL);
4511 if (!adapter->config_space) {
4512 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4515 for (i = 0; i < (size / 4); i++)
4516 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4521 e1000_pci_restore_state(struct e1000_adapter *adapter)
4523 struct pci_dev *dev = adapter->pdev;
4526 if (adapter->config_space == NULL)
4528 if (adapter->hw.mac_type >= e1000_82571)
4529 size = PCIE_CONFIG_SPACE_LEN;
4531 size = PCI_CONFIG_SPACE_LEN;
4532 for (i = 0; i < (size / 4); i++)
4533 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4534 kfree(adapter->config_space);
4535 adapter->config_space = NULL;
4538 #endif /* CONFIG_PM */
4541 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4543 struct net_device *netdev = pci_get_drvdata(pdev);
4544 struct e1000_adapter *adapter = netdev_priv(netdev);
4545 uint32_t ctrl, ctrl_ext, rctl, manc, status;
4546 uint32_t wufc = adapter->wol;
4549 netif_device_detach(netdev);
4551 if (netif_running(netdev))
4552 e1000_down(adapter);
4555 /* implement our own version of pci_save_state(pdev) because pci
4556 * express adapters have larger 256 byte config spaces */
4557 retval = e1000_pci_save_state(adapter);
4562 status = E1000_READ_REG(&adapter->hw, STATUS);
4563 if (status & E1000_STATUS_LU)
4564 wufc &= ~E1000_WUFC_LNKC;
4567 e1000_setup_rctl(adapter);
4568 e1000_set_multi(netdev);
4570 /* turn on all-multi mode if wake on multicast is enabled */
4571 if (adapter->wol & E1000_WUFC_MC) {
4572 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4573 rctl |= E1000_RCTL_MPE;
4574 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4577 if (adapter->hw.mac_type >= e1000_82540) {
4578 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4579 /* advertise wake from D3Cold */
4580 #define E1000_CTRL_ADVD3WUC 0x00100000
4581 /* phy power management enable */
4582 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4583 ctrl |= E1000_CTRL_ADVD3WUC |
4584 E1000_CTRL_EN_PHY_PWR_MGMT;
4585 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4588 if (adapter->hw.media_type == e1000_media_type_fiber ||
4589 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4590 /* keep the laser running in D3 */
4591 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4592 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4593 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4596 /* Allow time for pending master requests to run */
4597 e1000_disable_pciex_master(&adapter->hw);
4599 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4600 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4601 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4603 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4604 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4606 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4608 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4609 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4610 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4612 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4613 retval = pci_enable_wake(pdev, PCI_D3cold, 0); /* 4 == D3 cold */
4615 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4618 if (adapter->hw.mac_type >= e1000_82540 &&
4619 adapter->hw.media_type == e1000_media_type_copper) {
4620 manc = E1000_READ_REG(&adapter->hw, MANC);
4621 if (manc & E1000_MANC_SMBUS_EN) {
4622 manc |= E1000_MANC_ARP_EN;
4623 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4624 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4626 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4627 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4629 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4633 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4634 * would have already happened in close and is redundant. */
4635 e1000_release_hw_control(adapter);
4637 pci_disable_device(pdev);
4639 retval = pci_set_power_state(pdev, pci_choose_state(pdev, state));
4641 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4648 e1000_resume(struct pci_dev *pdev)
4650 struct net_device *netdev = pci_get_drvdata(pdev);
4651 struct e1000_adapter *adapter = netdev_priv(netdev);
4653 uint32_t manc, ret_val;
4655 retval = pci_set_power_state(pdev, PCI_D0);
4657 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4658 e1000_pci_restore_state(adapter);
4659 ret_val = pci_enable_device(pdev);
4660 pci_set_master(pdev);
4662 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4664 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4665 retval = pci_enable_wake(pdev, PCI_D3cold, 0);
4667 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4669 e1000_reset(adapter);
4670 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4672 if (netif_running(netdev))
4675 netif_device_attach(netdev);
4677 if (adapter->hw.mac_type >= e1000_82540 &&
4678 adapter->hw.media_type == e1000_media_type_copper) {
4679 manc = E1000_READ_REG(&adapter->hw, MANC);
4680 manc &= ~(E1000_MANC_ARP_EN);
4681 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4684 /* If the controller is 82573 and f/w is AMT, do not set
4685 * DRV_LOAD until the interface is up. For all other cases,
4686 * let the f/w know that the h/w is now under the control
4688 if (adapter->hw.mac_type != e1000_82573 ||
4689 !e1000_check_mng_mode(&adapter->hw))
4690 e1000_get_hw_control(adapter);
4695 #ifdef CONFIG_NET_POLL_CONTROLLER
4697 * Polling 'interrupt' - used by things like netconsole to send skbs
4698 * without having to re-enable interrupts. It's not called while
4699 * the interrupt routine is executing.
4702 e1000_netpoll(struct net_device *netdev)
4704 struct e1000_adapter *adapter = netdev_priv(netdev);
4705 disable_irq(adapter->pdev->irq);
4706 e1000_intr(adapter->pdev->irq, netdev, NULL);
4707 e1000_clean_tx_irq(adapter, adapter->tx_ring);
4708 #ifndef CONFIG_E1000_NAPI
4709 adapter->clean_rx(adapter, adapter->rx_ring);
4711 enable_irq(adapter->pdev->irq);