1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 #include <net/ip6_checksum.h>
32 #include <linux/prefetch.h>
33 #include <linux/bitops.h>
34 #include <linux/if_vlan.h>
36 char e1000_driver_name
[] = "e1000";
37 static char e1000_driver_string
[] = "Intel(R) PRO/1000 Network Driver";
38 #define DRV_VERSION "7.3.21-k8-NAPI"
39 const char e1000_driver_version
[] = DRV_VERSION
;
40 static const char e1000_copyright
[] = "Copyright (c) 1999-2006 Intel Corporation.";
42 /* e1000_pci_tbl - PCI Device ID Table
44 * Last entry must be all 0s
47 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
49 static const struct pci_device_id e1000_pci_tbl
[] = {
50 INTEL_E1000_ETHERNET_DEVICE(0x1000),
51 INTEL_E1000_ETHERNET_DEVICE(0x1001),
52 INTEL_E1000_ETHERNET_DEVICE(0x1004),
53 INTEL_E1000_ETHERNET_DEVICE(0x1008),
54 INTEL_E1000_ETHERNET_DEVICE(0x1009),
55 INTEL_E1000_ETHERNET_DEVICE(0x100C),
56 INTEL_E1000_ETHERNET_DEVICE(0x100D),
57 INTEL_E1000_ETHERNET_DEVICE(0x100E),
58 INTEL_E1000_ETHERNET_DEVICE(0x100F),
59 INTEL_E1000_ETHERNET_DEVICE(0x1010),
60 INTEL_E1000_ETHERNET_DEVICE(0x1011),
61 INTEL_E1000_ETHERNET_DEVICE(0x1012),
62 INTEL_E1000_ETHERNET_DEVICE(0x1013),
63 INTEL_E1000_ETHERNET_DEVICE(0x1014),
64 INTEL_E1000_ETHERNET_DEVICE(0x1015),
65 INTEL_E1000_ETHERNET_DEVICE(0x1016),
66 INTEL_E1000_ETHERNET_DEVICE(0x1017),
67 INTEL_E1000_ETHERNET_DEVICE(0x1018),
68 INTEL_E1000_ETHERNET_DEVICE(0x1019),
69 INTEL_E1000_ETHERNET_DEVICE(0x101A),
70 INTEL_E1000_ETHERNET_DEVICE(0x101D),
71 INTEL_E1000_ETHERNET_DEVICE(0x101E),
72 INTEL_E1000_ETHERNET_DEVICE(0x1026),
73 INTEL_E1000_ETHERNET_DEVICE(0x1027),
74 INTEL_E1000_ETHERNET_DEVICE(0x1028),
75 INTEL_E1000_ETHERNET_DEVICE(0x1075),
76 INTEL_E1000_ETHERNET_DEVICE(0x1076),
77 INTEL_E1000_ETHERNET_DEVICE(0x1077),
78 INTEL_E1000_ETHERNET_DEVICE(0x1078),
79 INTEL_E1000_ETHERNET_DEVICE(0x1079),
80 INTEL_E1000_ETHERNET_DEVICE(0x107A),
81 INTEL_E1000_ETHERNET_DEVICE(0x107B),
82 INTEL_E1000_ETHERNET_DEVICE(0x107C),
83 INTEL_E1000_ETHERNET_DEVICE(0x108A),
84 INTEL_E1000_ETHERNET_DEVICE(0x1099),
85 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
86 INTEL_E1000_ETHERNET_DEVICE(0x2E6E),
87 /* required last entry */
91 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
93 int e1000_up(struct e1000_adapter
*adapter
);
94 void e1000_down(struct e1000_adapter
*adapter
);
95 void e1000_reinit_locked(struct e1000_adapter
*adapter
);
96 void e1000_reset(struct e1000_adapter
*adapter
);
97 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
);
98 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
);
99 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
);
100 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
);
101 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
102 struct e1000_tx_ring
*txdr
);
103 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
104 struct e1000_rx_ring
*rxdr
);
105 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
106 struct e1000_tx_ring
*tx_ring
);
107 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
108 struct e1000_rx_ring
*rx_ring
);
109 void e1000_update_stats(struct e1000_adapter
*adapter
);
111 static int e1000_init_module(void);
112 static void e1000_exit_module(void);
113 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
114 static void e1000_remove(struct pci_dev
*pdev
);
115 static int e1000_alloc_queues(struct e1000_adapter
*adapter
);
116 static int e1000_sw_init(struct e1000_adapter
*adapter
);
117 int e1000_open(struct net_device
*netdev
);
118 int e1000_close(struct net_device
*netdev
);
119 static void e1000_configure_tx(struct e1000_adapter
*adapter
);
120 static void e1000_configure_rx(struct e1000_adapter
*adapter
);
121 static void e1000_setup_rctl(struct e1000_adapter
*adapter
);
122 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
);
123 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
);
124 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
125 struct e1000_tx_ring
*tx_ring
);
126 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
127 struct e1000_rx_ring
*rx_ring
);
128 static void e1000_set_rx_mode(struct net_device
*netdev
);
129 static void e1000_update_phy_info_task(struct work_struct
*work
);
130 static void e1000_watchdog(struct work_struct
*work
);
131 static void e1000_82547_tx_fifo_stall_task(struct work_struct
*work
);
132 static netdev_tx_t
e1000_xmit_frame(struct sk_buff
*skb
,
133 struct net_device
*netdev
);
134 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
135 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
136 static irqreturn_t
e1000_intr(int irq
, void *data
);
137 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
138 struct e1000_tx_ring
*tx_ring
);
139 static int e1000_clean(struct napi_struct
*napi
, int budget
);
140 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
141 struct e1000_rx_ring
*rx_ring
,
142 int *work_done
, int work_to_do
);
143 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter
*adapter
,
144 struct e1000_rx_ring
*rx_ring
,
145 int *work_done
, int work_to_do
);
146 static void e1000_alloc_dummy_rx_buffers(struct e1000_adapter
*adapter
,
147 struct e1000_rx_ring
*rx_ring
,
151 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
152 struct e1000_rx_ring
*rx_ring
,
154 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter
*adapter
,
155 struct e1000_rx_ring
*rx_ring
,
157 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
158 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
160 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
161 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
162 static void e1000_tx_timeout(struct net_device
*dev
);
163 static void e1000_reset_task(struct work_struct
*work
);
164 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
165 static int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
166 struct sk_buff
*skb
);
168 static bool e1000_vlan_used(struct e1000_adapter
*adapter
);
169 static void e1000_vlan_mode(struct net_device
*netdev
,
170 netdev_features_t features
);
171 static void e1000_vlan_filter_on_off(struct e1000_adapter
*adapter
,
173 static int e1000_vlan_rx_add_vid(struct net_device
*netdev
,
174 __be16 proto
, u16 vid
);
175 static int e1000_vlan_rx_kill_vid(struct net_device
*netdev
,
176 __be16 proto
, u16 vid
);
177 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
180 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
);
181 static int e1000_resume(struct pci_dev
*pdev
);
183 static void e1000_shutdown(struct pci_dev
*pdev
);
185 #ifdef CONFIG_NET_POLL_CONTROLLER
186 /* for netdump / net console */
187 static void e1000_netpoll (struct net_device
*netdev
);
190 #define COPYBREAK_DEFAULT 256
191 static unsigned int copybreak __read_mostly
= COPYBREAK_DEFAULT
;
192 module_param(copybreak
, uint
, 0644);
193 MODULE_PARM_DESC(copybreak
,
194 "Maximum size of packet that is copied to a new buffer on receive");
196 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
197 pci_channel_state_t state
);
198 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
);
199 static void e1000_io_resume(struct pci_dev
*pdev
);
201 static const struct pci_error_handlers e1000_err_handler
= {
202 .error_detected
= e1000_io_error_detected
,
203 .slot_reset
= e1000_io_slot_reset
,
204 .resume
= e1000_io_resume
,
207 static struct pci_driver e1000_driver
= {
208 .name
= e1000_driver_name
,
209 .id_table
= e1000_pci_tbl
,
210 .probe
= e1000_probe
,
211 .remove
= e1000_remove
,
213 /* Power Management Hooks */
214 .suspend
= e1000_suspend
,
215 .resume
= e1000_resume
,
217 .shutdown
= e1000_shutdown
,
218 .err_handler
= &e1000_err_handler
221 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
222 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
223 MODULE_LICENSE("GPL");
224 MODULE_VERSION(DRV_VERSION
);
226 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
227 static int debug
= -1;
228 module_param(debug
, int, 0);
229 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
232 * e1000_get_hw_dev - return device
233 * used by hardware layer to print debugging information
236 struct net_device
*e1000_get_hw_dev(struct e1000_hw
*hw
)
238 struct e1000_adapter
*adapter
= hw
->back
;
239 return adapter
->netdev
;
243 * e1000_init_module - Driver Registration Routine
245 * e1000_init_module is the first routine called when the driver is
246 * loaded. All it does is register with the PCI subsystem.
248 static int __init
e1000_init_module(void)
251 pr_info("%s - version %s\n", e1000_driver_string
, e1000_driver_version
);
253 pr_info("%s\n", e1000_copyright
);
255 ret
= pci_register_driver(&e1000_driver
);
256 if (copybreak
!= COPYBREAK_DEFAULT
) {
258 pr_info("copybreak disabled\n");
260 pr_info("copybreak enabled for "
261 "packets <= %u bytes\n", copybreak
);
266 module_init(e1000_init_module
);
269 * e1000_exit_module - Driver Exit Cleanup Routine
271 * e1000_exit_module is called just before the driver is removed
274 static void __exit
e1000_exit_module(void)
276 pci_unregister_driver(&e1000_driver
);
279 module_exit(e1000_exit_module
);
281 static int e1000_request_irq(struct e1000_adapter
*adapter
)
283 struct net_device
*netdev
= adapter
->netdev
;
284 irq_handler_t handler
= e1000_intr
;
285 int irq_flags
= IRQF_SHARED
;
288 err
= request_irq(adapter
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
291 e_err(probe
, "Unable to allocate interrupt Error: %d\n", err
);
297 static void e1000_free_irq(struct e1000_adapter
*adapter
)
299 struct net_device
*netdev
= adapter
->netdev
;
301 free_irq(adapter
->pdev
->irq
, netdev
);
305 * e1000_irq_disable - Mask off interrupt generation on the NIC
306 * @adapter: board private structure
308 static void e1000_irq_disable(struct e1000_adapter
*adapter
)
310 struct e1000_hw
*hw
= &adapter
->hw
;
314 synchronize_irq(adapter
->pdev
->irq
);
318 * e1000_irq_enable - Enable default interrupt generation settings
319 * @adapter: board private structure
321 static void e1000_irq_enable(struct e1000_adapter
*adapter
)
323 struct e1000_hw
*hw
= &adapter
->hw
;
325 ew32(IMS
, IMS_ENABLE_MASK
);
329 static void e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
331 struct e1000_hw
*hw
= &adapter
->hw
;
332 struct net_device
*netdev
= adapter
->netdev
;
333 u16 vid
= hw
->mng_cookie
.vlan_id
;
334 u16 old_vid
= adapter
->mng_vlan_id
;
336 if (!e1000_vlan_used(adapter
))
339 if (!test_bit(vid
, adapter
->active_vlans
)) {
340 if (hw
->mng_cookie
.status
&
341 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
342 e1000_vlan_rx_add_vid(netdev
, htons(ETH_P_8021Q
), vid
);
343 adapter
->mng_vlan_id
= vid
;
345 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
347 if ((old_vid
!= (u16
)E1000_MNG_VLAN_NONE
) &&
349 !test_bit(old_vid
, adapter
->active_vlans
))
350 e1000_vlan_rx_kill_vid(netdev
, htons(ETH_P_8021Q
),
353 adapter
->mng_vlan_id
= vid
;
357 static void e1000_init_manageability(struct e1000_adapter
*adapter
)
359 struct e1000_hw
*hw
= &adapter
->hw
;
361 if (adapter
->en_mng_pt
) {
362 u32 manc
= er32(MANC
);
364 /* disable hardware interception of ARP */
365 manc
&= ~(E1000_MANC_ARP_EN
);
371 static void e1000_release_manageability(struct e1000_adapter
*adapter
)
373 struct e1000_hw
*hw
= &adapter
->hw
;
375 if (adapter
->en_mng_pt
) {
376 u32 manc
= er32(MANC
);
378 /* re-enable hardware interception of ARP */
379 manc
|= E1000_MANC_ARP_EN
;
386 * e1000_configure - configure the hardware for RX and TX
387 * @adapter = private board structure
389 static void e1000_configure(struct e1000_adapter
*adapter
)
391 struct net_device
*netdev
= adapter
->netdev
;
394 e1000_set_rx_mode(netdev
);
396 e1000_restore_vlan(adapter
);
397 e1000_init_manageability(adapter
);
399 e1000_configure_tx(adapter
);
400 e1000_setup_rctl(adapter
);
401 e1000_configure_rx(adapter
);
402 /* call E1000_DESC_UNUSED which always leaves
403 * at least 1 descriptor unused to make sure
404 * next_to_use != next_to_clean
406 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
407 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[i
];
408 adapter
->alloc_rx_buf(adapter
, ring
,
409 E1000_DESC_UNUSED(ring
));
413 int e1000_up(struct e1000_adapter
*adapter
)
415 struct e1000_hw
*hw
= &adapter
->hw
;
417 /* hardware has been reset, we need to reload some things */
418 e1000_configure(adapter
);
420 clear_bit(__E1000_DOWN
, &adapter
->flags
);
422 napi_enable(&adapter
->napi
);
424 e1000_irq_enable(adapter
);
426 netif_wake_queue(adapter
->netdev
);
428 /* fire a link change interrupt to start the watchdog */
429 ew32(ICS
, E1000_ICS_LSC
);
434 * e1000_power_up_phy - restore link in case the phy was powered down
435 * @adapter: address of board private structure
437 * The phy may be powered down to save power and turn off link when the
438 * driver is unloaded and wake on lan is not enabled (among others)
439 * *** this routine MUST be followed by a call to e1000_reset ***
441 void e1000_power_up_phy(struct e1000_adapter
*adapter
)
443 struct e1000_hw
*hw
= &adapter
->hw
;
446 /* Just clear the power down bit to wake the phy back up */
447 if (hw
->media_type
== e1000_media_type_copper
) {
448 /* according to the manual, the phy will retain its
449 * settings across a power-down/up cycle
451 e1000_read_phy_reg(hw
, PHY_CTRL
, &mii_reg
);
452 mii_reg
&= ~MII_CR_POWER_DOWN
;
453 e1000_write_phy_reg(hw
, PHY_CTRL
, mii_reg
);
457 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
459 struct e1000_hw
*hw
= &adapter
->hw
;
461 /* Power down the PHY so no link is implied when interface is down *
462 * The PHY cannot be powered down if any of the following is true *
465 * (c) SoL/IDER session is active
467 if (!adapter
->wol
&& hw
->mac_type
>= e1000_82540
&&
468 hw
->media_type
== e1000_media_type_copper
) {
471 switch (hw
->mac_type
) {
474 case e1000_82545_rev_3
:
477 case e1000_82546_rev_3
:
479 case e1000_82541_rev_2
:
481 case e1000_82547_rev_2
:
482 if (er32(MANC
) & E1000_MANC_SMBUS_EN
)
488 e1000_read_phy_reg(hw
, PHY_CTRL
, &mii_reg
);
489 mii_reg
|= MII_CR_POWER_DOWN
;
490 e1000_write_phy_reg(hw
, PHY_CTRL
, mii_reg
);
497 static void e1000_down_and_stop(struct e1000_adapter
*adapter
)
499 set_bit(__E1000_DOWN
, &adapter
->flags
);
501 cancel_delayed_work_sync(&adapter
->watchdog_task
);
504 * Since the watchdog task can reschedule other tasks, we should cancel
505 * it first, otherwise we can run into the situation when a work is
506 * still running after the adapter has been turned down.
509 cancel_delayed_work_sync(&adapter
->phy_info_task
);
510 cancel_delayed_work_sync(&adapter
->fifo_stall_task
);
512 /* Only kill reset task if adapter is not resetting */
513 if (!test_bit(__E1000_RESETTING
, &adapter
->flags
))
514 cancel_work_sync(&adapter
->reset_task
);
517 void e1000_down(struct e1000_adapter
*adapter
)
519 struct e1000_hw
*hw
= &adapter
->hw
;
520 struct net_device
*netdev
= adapter
->netdev
;
523 /* disable receives in the hardware */
525 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
526 /* flush and sleep below */
528 netif_tx_disable(netdev
);
530 /* disable transmits in the hardware */
532 tctl
&= ~E1000_TCTL_EN
;
534 /* flush both disables and wait for them to finish */
538 /* Set the carrier off after transmits have been disabled in the
539 * hardware, to avoid race conditions with e1000_watchdog() (which
540 * may be running concurrently to us, checking for the carrier
541 * bit to decide whether it should enable transmits again). Such
542 * a race condition would result into transmission being disabled
543 * in the hardware until the next IFF_DOWN+IFF_UP cycle.
545 netif_carrier_off(netdev
);
547 napi_disable(&adapter
->napi
);
549 e1000_irq_disable(adapter
);
551 /* Setting DOWN must be after irq_disable to prevent
552 * a screaming interrupt. Setting DOWN also prevents
553 * tasks from rescheduling.
555 e1000_down_and_stop(adapter
);
557 adapter
->link_speed
= 0;
558 adapter
->link_duplex
= 0;
560 e1000_reset(adapter
);
561 e1000_clean_all_tx_rings(adapter
);
562 e1000_clean_all_rx_rings(adapter
);
565 void e1000_reinit_locked(struct e1000_adapter
*adapter
)
567 WARN_ON(in_interrupt());
568 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->flags
))
572 clear_bit(__E1000_RESETTING
, &adapter
->flags
);
575 void e1000_reset(struct e1000_adapter
*adapter
)
577 struct e1000_hw
*hw
= &adapter
->hw
;
578 u32 pba
= 0, tx_space
, min_tx_space
, min_rx_space
;
579 bool legacy_pba_adjust
= false;
582 /* Repartition Pba for greater than 9k mtu
583 * To take effect CTRL.RST is required.
586 switch (hw
->mac_type
) {
587 case e1000_82542_rev2_0
:
588 case e1000_82542_rev2_1
:
593 case e1000_82541_rev_2
:
594 legacy_pba_adjust
= true;
598 case e1000_82545_rev_3
:
601 case e1000_82546_rev_3
:
605 case e1000_82547_rev_2
:
606 legacy_pba_adjust
= true;
609 case e1000_undefined
:
614 if (legacy_pba_adjust
) {
615 if (hw
->max_frame_size
> E1000_RXBUFFER_8192
)
616 pba
-= 8; /* allocate more FIFO for Tx */
618 if (hw
->mac_type
== e1000_82547
) {
619 adapter
->tx_fifo_head
= 0;
620 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
621 adapter
->tx_fifo_size
=
622 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
623 atomic_set(&adapter
->tx_fifo_stall
, 0);
625 } else if (hw
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
626 /* adjust PBA for jumbo frames */
629 /* To maintain wire speed transmits, the Tx FIFO should be
630 * large enough to accommodate two full transmit packets,
631 * rounded up to the next 1KB and expressed in KB. Likewise,
632 * the Rx FIFO should be large enough to accommodate at least
633 * one full receive packet and is similarly rounded up and
637 /* upper 16 bits has Tx packet buffer allocation size in KB */
638 tx_space
= pba
>> 16;
639 /* lower 16 bits has Rx packet buffer allocation size in KB */
641 /* the Tx fifo also stores 16 bytes of information about the Tx
642 * but don't include ethernet FCS because hardware appends it
644 min_tx_space
= (hw
->max_frame_size
+
645 sizeof(struct e1000_tx_desc
) -
647 min_tx_space
= ALIGN(min_tx_space
, 1024);
649 /* software strips receive CRC, so leave room for it */
650 min_rx_space
= hw
->max_frame_size
;
651 min_rx_space
= ALIGN(min_rx_space
, 1024);
654 /* If current Tx allocation is less than the min Tx FIFO size,
655 * and the min Tx FIFO size is less than the current Rx FIFO
656 * allocation, take space away from current Rx allocation
658 if (tx_space
< min_tx_space
&&
659 ((min_tx_space
- tx_space
) < pba
)) {
660 pba
= pba
- (min_tx_space
- tx_space
);
662 /* PCI/PCIx hardware has PBA alignment constraints */
663 switch (hw
->mac_type
) {
664 case e1000_82545
... e1000_82546_rev_3
:
665 pba
&= ~(E1000_PBA_8K
- 1);
671 /* if short on Rx space, Rx wins and must trump Tx
672 * adjustment or use Early Receive if available
674 if (pba
< min_rx_space
)
681 /* flow control settings:
682 * The high water mark must be low enough to fit one full frame
683 * (or the size used for early receive) above it in the Rx FIFO.
684 * Set it to the lower of:
685 * - 90% of the Rx FIFO size, and
686 * - the full Rx FIFO size minus the early receive size (for parts
687 * with ERT support assuming ERT set to E1000_ERT_2048), or
688 * - the full Rx FIFO size minus one full frame
690 hwm
= min(((pba
<< 10) * 9 / 10),
691 ((pba
<< 10) - hw
->max_frame_size
));
693 hw
->fc_high_water
= hwm
& 0xFFF8; /* 8-byte granularity */
694 hw
->fc_low_water
= hw
->fc_high_water
- 8;
695 hw
->fc_pause_time
= E1000_FC_PAUSE_TIME
;
697 hw
->fc
= hw
->original_fc
;
699 /* Allow time for pending master requests to run */
701 if (hw
->mac_type
>= e1000_82544
)
704 if (e1000_init_hw(hw
))
705 e_dev_err("Hardware Error\n");
706 e1000_update_mng_vlan(adapter
);
708 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
709 if (hw
->mac_type
>= e1000_82544
&&
711 hw
->autoneg_advertised
== ADVERTISE_1000_FULL
) {
712 u32 ctrl
= er32(CTRL
);
713 /* clear phy power management bit if we are in gig only mode,
714 * which if enabled will attempt negotiation to 100Mb, which
715 * can cause a loss of link at power off or driver unload
717 ctrl
&= ~E1000_CTRL_SWDPIN3
;
721 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
722 ew32(VET
, ETHERNET_IEEE_VLAN_TYPE
);
724 e1000_reset_adaptive(hw
);
725 e1000_phy_get_info(hw
, &adapter
->phy_info
);
727 e1000_release_manageability(adapter
);
730 /* Dump the eeprom for users having checksum issues */
731 static void e1000_dump_eeprom(struct e1000_adapter
*adapter
)
733 struct net_device
*netdev
= adapter
->netdev
;
734 struct ethtool_eeprom eeprom
;
735 const struct ethtool_ops
*ops
= netdev
->ethtool_ops
;
738 u16 csum_old
, csum_new
= 0;
740 eeprom
.len
= ops
->get_eeprom_len(netdev
);
743 data
= kmalloc(eeprom
.len
, GFP_KERNEL
);
747 ops
->get_eeprom(netdev
, &eeprom
, data
);
749 csum_old
= (data
[EEPROM_CHECKSUM_REG
* 2]) +
750 (data
[EEPROM_CHECKSUM_REG
* 2 + 1] << 8);
751 for (i
= 0; i
< EEPROM_CHECKSUM_REG
* 2; i
+= 2)
752 csum_new
+= data
[i
] + (data
[i
+ 1] << 8);
753 csum_new
= EEPROM_SUM
- csum_new
;
755 pr_err("/*********************/\n");
756 pr_err("Current EEPROM Checksum : 0x%04x\n", csum_old
);
757 pr_err("Calculated : 0x%04x\n", csum_new
);
759 pr_err("Offset Values\n");
760 pr_err("======== ======\n");
761 print_hex_dump(KERN_ERR
, "", DUMP_PREFIX_OFFSET
, 16, 1, data
, 128, 0);
763 pr_err("Include this output when contacting your support provider.\n");
764 pr_err("This is not a software error! Something bad happened to\n");
765 pr_err("your hardware or EEPROM image. Ignoring this problem could\n");
766 pr_err("result in further problems, possibly loss of data,\n");
767 pr_err("corruption or system hangs!\n");
768 pr_err("The MAC Address will be reset to 00:00:00:00:00:00,\n");
769 pr_err("which is invalid and requires you to set the proper MAC\n");
770 pr_err("address manually before continuing to enable this network\n");
771 pr_err("device. Please inspect the EEPROM dump and report the\n");
772 pr_err("issue to your hardware vendor or Intel Customer Support.\n");
773 pr_err("/*********************/\n");
779 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
780 * @pdev: PCI device information struct
782 * Return true if an adapter needs ioport resources
784 static int e1000_is_need_ioport(struct pci_dev
*pdev
)
786 switch (pdev
->device
) {
787 case E1000_DEV_ID_82540EM
:
788 case E1000_DEV_ID_82540EM_LOM
:
789 case E1000_DEV_ID_82540EP
:
790 case E1000_DEV_ID_82540EP_LOM
:
791 case E1000_DEV_ID_82540EP_LP
:
792 case E1000_DEV_ID_82541EI
:
793 case E1000_DEV_ID_82541EI_MOBILE
:
794 case E1000_DEV_ID_82541ER
:
795 case E1000_DEV_ID_82541ER_LOM
:
796 case E1000_DEV_ID_82541GI
:
797 case E1000_DEV_ID_82541GI_LF
:
798 case E1000_DEV_ID_82541GI_MOBILE
:
799 case E1000_DEV_ID_82544EI_COPPER
:
800 case E1000_DEV_ID_82544EI_FIBER
:
801 case E1000_DEV_ID_82544GC_COPPER
:
802 case E1000_DEV_ID_82544GC_LOM
:
803 case E1000_DEV_ID_82545EM_COPPER
:
804 case E1000_DEV_ID_82545EM_FIBER
:
805 case E1000_DEV_ID_82546EB_COPPER
:
806 case E1000_DEV_ID_82546EB_FIBER
:
807 case E1000_DEV_ID_82546EB_QUAD_COPPER
:
814 static netdev_features_t
e1000_fix_features(struct net_device
*netdev
,
815 netdev_features_t features
)
817 /* Since there is no support for separate Rx/Tx vlan accel
818 * enable/disable make sure Tx flag is always in same state as Rx.
820 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
821 features
|= NETIF_F_HW_VLAN_CTAG_TX
;
823 features
&= ~NETIF_F_HW_VLAN_CTAG_TX
;
828 static int e1000_set_features(struct net_device
*netdev
,
829 netdev_features_t features
)
831 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
832 netdev_features_t changed
= features
^ netdev
->features
;
834 if (changed
& NETIF_F_HW_VLAN_CTAG_RX
)
835 e1000_vlan_mode(netdev
, features
);
837 if (!(changed
& (NETIF_F_RXCSUM
| NETIF_F_RXALL
)))
840 netdev
->features
= features
;
841 adapter
->rx_csum
= !!(features
& NETIF_F_RXCSUM
);
843 if (netif_running(netdev
))
844 e1000_reinit_locked(adapter
);
846 e1000_reset(adapter
);
851 static const struct net_device_ops e1000_netdev_ops
= {
852 .ndo_open
= e1000_open
,
853 .ndo_stop
= e1000_close
,
854 .ndo_start_xmit
= e1000_xmit_frame
,
855 .ndo_set_rx_mode
= e1000_set_rx_mode
,
856 .ndo_set_mac_address
= e1000_set_mac
,
857 .ndo_tx_timeout
= e1000_tx_timeout
,
858 .ndo_change_mtu
= e1000_change_mtu
,
859 .ndo_do_ioctl
= e1000_ioctl
,
860 .ndo_validate_addr
= eth_validate_addr
,
861 .ndo_vlan_rx_add_vid
= e1000_vlan_rx_add_vid
,
862 .ndo_vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
,
863 #ifdef CONFIG_NET_POLL_CONTROLLER
864 .ndo_poll_controller
= e1000_netpoll
,
866 .ndo_fix_features
= e1000_fix_features
,
867 .ndo_set_features
= e1000_set_features
,
871 * e1000_init_hw_struct - initialize members of hw struct
872 * @adapter: board private struct
873 * @hw: structure used by e1000_hw.c
875 * Factors out initialization of the e1000_hw struct to its own function
876 * that can be called very early at init (just after struct allocation).
877 * Fields are initialized based on PCI device information and
878 * OS network device settings (MTU size).
879 * Returns negative error codes if MAC type setup fails.
881 static int e1000_init_hw_struct(struct e1000_adapter
*adapter
,
884 struct pci_dev
*pdev
= adapter
->pdev
;
886 /* PCI config space info */
887 hw
->vendor_id
= pdev
->vendor
;
888 hw
->device_id
= pdev
->device
;
889 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
890 hw
->subsystem_id
= pdev
->subsystem_device
;
891 hw
->revision_id
= pdev
->revision
;
893 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
895 hw
->max_frame_size
= adapter
->netdev
->mtu
+
896 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
897 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
899 /* identify the MAC */
900 if (e1000_set_mac_type(hw
)) {
901 e_err(probe
, "Unknown MAC Type\n");
905 switch (hw
->mac_type
) {
910 case e1000_82541_rev_2
:
911 case e1000_82547_rev_2
:
912 hw
->phy_init_script
= 1;
916 e1000_set_media_type(hw
);
917 e1000_get_bus_info(hw
);
919 hw
->wait_autoneg_complete
= false;
920 hw
->tbi_compatibility_en
= true;
921 hw
->adaptive_ifs
= true;
925 if (hw
->media_type
== e1000_media_type_copper
) {
926 hw
->mdix
= AUTO_ALL_MODES
;
927 hw
->disable_polarity_correction
= false;
928 hw
->master_slave
= E1000_MASTER_SLAVE
;
935 * e1000_probe - Device Initialization Routine
936 * @pdev: PCI device information struct
937 * @ent: entry in e1000_pci_tbl
939 * Returns 0 on success, negative on failure
941 * e1000_probe initializes an adapter identified by a pci_dev structure.
942 * The OS initialization, configuring of the adapter private structure,
943 * and a hardware reset occur.
945 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
947 struct net_device
*netdev
;
948 struct e1000_adapter
*adapter
= NULL
;
951 static int cards_found
;
952 static int global_quad_port_a
; /* global ksp3 port a indication */
953 int i
, err
, pci_using_dac
;
956 u16 eeprom_apme_mask
= E1000_EEPROM_APME
;
957 int bars
, need_ioport
;
958 bool disable_dev
= false;
960 /* do not allocate ioport bars when not needed */
961 need_ioport
= e1000_is_need_ioport(pdev
);
963 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
964 err
= pci_enable_device(pdev
);
966 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
967 err
= pci_enable_device_mem(pdev
);
972 err
= pci_request_selected_regions(pdev
, bars
, e1000_driver_name
);
976 pci_set_master(pdev
);
977 err
= pci_save_state(pdev
);
979 goto err_alloc_etherdev
;
982 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
984 goto err_alloc_etherdev
;
986 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
988 pci_set_drvdata(pdev
, netdev
);
989 adapter
= netdev_priv(netdev
);
990 adapter
->netdev
= netdev
;
991 adapter
->pdev
= pdev
;
992 adapter
->msg_enable
= netif_msg_init(debug
, DEFAULT_MSG_ENABLE
);
993 adapter
->bars
= bars
;
994 adapter
->need_ioport
= need_ioport
;
1000 hw
->hw_addr
= pci_ioremap_bar(pdev
, BAR_0
);
1004 if (adapter
->need_ioport
) {
1005 for (i
= BAR_1
; i
<= BAR_5
; i
++) {
1006 if (pci_resource_len(pdev
, i
) == 0)
1008 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
1009 hw
->io_base
= pci_resource_start(pdev
, i
);
1015 /* make ready for any if (hw->...) below */
1016 err
= e1000_init_hw_struct(adapter
, hw
);
1020 /* there is a workaround being applied below that limits
1021 * 64-bit DMA addresses to 64-bit hardware. There are some
1022 * 32-bit adapters that Tx hang when given 64-bit DMA addresses
1025 if ((hw
->bus_type
== e1000_bus_type_pcix
) &&
1026 !dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64))) {
1029 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
1031 pr_err("No usable DMA config, aborting\n");
1036 netdev
->netdev_ops
= &e1000_netdev_ops
;
1037 e1000_set_ethtool_ops(netdev
);
1038 netdev
->watchdog_timeo
= 5 * HZ
;
1039 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
1041 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
1043 adapter
->bd_number
= cards_found
;
1045 /* setup the private structure */
1047 err
= e1000_sw_init(adapter
);
1052 if (hw
->mac_type
== e1000_ce4100
) {
1053 hw
->ce4100_gbe_mdio_base_virt
=
1054 ioremap(pci_resource_start(pdev
, BAR_1
),
1055 pci_resource_len(pdev
, BAR_1
));
1057 if (!hw
->ce4100_gbe_mdio_base_virt
)
1058 goto err_mdio_ioremap
;
1061 if (hw
->mac_type
>= e1000_82543
) {
1062 netdev
->hw_features
= NETIF_F_SG
|
1064 NETIF_F_HW_VLAN_CTAG_RX
;
1065 netdev
->features
= NETIF_F_HW_VLAN_CTAG_TX
|
1066 NETIF_F_HW_VLAN_CTAG_FILTER
;
1069 if ((hw
->mac_type
>= e1000_82544
) &&
1070 (hw
->mac_type
!= e1000_82547
))
1071 netdev
->hw_features
|= NETIF_F_TSO
;
1073 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
1075 netdev
->features
|= netdev
->hw_features
;
1076 netdev
->hw_features
|= (NETIF_F_RXCSUM
|
1080 if (pci_using_dac
) {
1081 netdev
->features
|= NETIF_F_HIGHDMA
;
1082 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1085 netdev
->vlan_features
|= (NETIF_F_TSO
|
1089 /* Do not set IFF_UNICAST_FLT for VMWare's 82545EM */
1090 if (hw
->device_id
!= E1000_DEV_ID_82545EM_COPPER
||
1091 hw
->subsystem_vendor_id
!= PCI_VENDOR_ID_VMWARE
)
1092 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
1094 /* MTU range: 46 - 16110 */
1095 netdev
->min_mtu
= ETH_ZLEN
- ETH_HLEN
;
1096 netdev
->max_mtu
= MAX_JUMBO_FRAME_SIZE
- (ETH_HLEN
+ ETH_FCS_LEN
);
1098 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(hw
);
1100 /* initialize eeprom parameters */
1101 if (e1000_init_eeprom_params(hw
)) {
1102 e_err(probe
, "EEPROM initialization failed\n");
1106 /* before reading the EEPROM, reset the controller to
1107 * put the device in a known good starting state
1112 /* make sure the EEPROM is good */
1113 if (e1000_validate_eeprom_checksum(hw
) < 0) {
1114 e_err(probe
, "The EEPROM Checksum Is Not Valid\n");
1115 e1000_dump_eeprom(adapter
);
1116 /* set MAC address to all zeroes to invalidate and temporary
1117 * disable this device for the user. This blocks regular
1118 * traffic while still permitting ethtool ioctls from reaching
1119 * the hardware as well as allowing the user to run the
1120 * interface after manually setting a hw addr using
1123 memset(hw
->mac_addr
, 0, netdev
->addr_len
);
1125 /* copy the MAC address out of the EEPROM */
1126 if (e1000_read_mac_addr(hw
))
1127 e_err(probe
, "EEPROM Read Error\n");
1129 /* don't block initialization here due to bad MAC address */
1130 memcpy(netdev
->dev_addr
, hw
->mac_addr
, netdev
->addr_len
);
1132 if (!is_valid_ether_addr(netdev
->dev_addr
))
1133 e_err(probe
, "Invalid MAC Address\n");
1136 INIT_DELAYED_WORK(&adapter
->watchdog_task
, e1000_watchdog
);
1137 INIT_DELAYED_WORK(&adapter
->fifo_stall_task
,
1138 e1000_82547_tx_fifo_stall_task
);
1139 INIT_DELAYED_WORK(&adapter
->phy_info_task
, e1000_update_phy_info_task
);
1140 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
1142 e1000_check_options(adapter
);
1144 /* Initial Wake on LAN setting
1145 * If APM wake is enabled in the EEPROM,
1146 * enable the ACPI Magic Packet filter
1149 switch (hw
->mac_type
) {
1150 case e1000_82542_rev2_0
:
1151 case e1000_82542_rev2_1
:
1155 e1000_read_eeprom(hw
,
1156 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
1157 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
1160 case e1000_82546_rev_3
:
1161 if (er32(STATUS
) & E1000_STATUS_FUNC_1
) {
1162 e1000_read_eeprom(hw
,
1163 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
1168 e1000_read_eeprom(hw
,
1169 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
1172 if (eeprom_data
& eeprom_apme_mask
)
1173 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
1175 /* now that we have the eeprom settings, apply the special cases
1176 * where the eeprom may be wrong or the board simply won't support
1177 * wake on lan on a particular port
1179 switch (pdev
->device
) {
1180 case E1000_DEV_ID_82546GB_PCIE
:
1181 adapter
->eeprom_wol
= 0;
1183 case E1000_DEV_ID_82546EB_FIBER
:
1184 case E1000_DEV_ID_82546GB_FIBER
:
1185 /* Wake events only supported on port A for dual fiber
1186 * regardless of eeprom setting
1188 if (er32(STATUS
) & E1000_STATUS_FUNC_1
)
1189 adapter
->eeprom_wol
= 0;
1191 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3
:
1192 /* if quad port adapter, disable WoL on all but port A */
1193 if (global_quad_port_a
!= 0)
1194 adapter
->eeprom_wol
= 0;
1196 adapter
->quad_port_a
= true;
1197 /* Reset for multiple quad port adapters */
1198 if (++global_quad_port_a
== 4)
1199 global_quad_port_a
= 0;
1203 /* initialize the wol settings based on the eeprom settings */
1204 adapter
->wol
= adapter
->eeprom_wol
;
1205 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1207 /* Auto detect PHY address */
1208 if (hw
->mac_type
== e1000_ce4100
) {
1209 for (i
= 0; i
< 32; i
++) {
1211 e1000_read_phy_reg(hw
, PHY_ID2
, &tmp
);
1213 if (tmp
!= 0 && tmp
!= 0xFF)
1221 /* reset the hardware with the new settings */
1222 e1000_reset(adapter
);
1224 strcpy(netdev
->name
, "eth%d");
1225 err
= register_netdev(netdev
);
1229 e1000_vlan_filter_on_off(adapter
, false);
1231 /* print bus type/speed/width info */
1232 e_info(probe
, "(PCI%s:%dMHz:%d-bit) %pM\n",
1233 ((hw
->bus_type
== e1000_bus_type_pcix
) ? "-X" : ""),
1234 ((hw
->bus_speed
== e1000_bus_speed_133
) ? 133 :
1235 (hw
->bus_speed
== e1000_bus_speed_120
) ? 120 :
1236 (hw
->bus_speed
== e1000_bus_speed_100
) ? 100 :
1237 (hw
->bus_speed
== e1000_bus_speed_66
) ? 66 : 33),
1238 ((hw
->bus_width
== e1000_bus_width_64
) ? 64 : 32),
1241 /* carrier off reporting is important to ethtool even BEFORE open */
1242 netif_carrier_off(netdev
);
1244 e_info(probe
, "Intel(R) PRO/1000 Network Connection\n");
1251 e1000_phy_hw_reset(hw
);
1253 if (hw
->flash_address
)
1254 iounmap(hw
->flash_address
);
1255 kfree(adapter
->tx_ring
);
1256 kfree(adapter
->rx_ring
);
1260 iounmap(hw
->ce4100_gbe_mdio_base_virt
);
1261 iounmap(hw
->hw_addr
);
1263 disable_dev
= !test_and_set_bit(__E1000_DISABLED
, &adapter
->flags
);
1264 free_netdev(netdev
);
1266 pci_release_selected_regions(pdev
, bars
);
1268 if (!adapter
|| disable_dev
)
1269 pci_disable_device(pdev
);
1274 * e1000_remove - Device Removal Routine
1275 * @pdev: PCI device information struct
1277 * e1000_remove is called by the PCI subsystem to alert the driver
1278 * that it should release a PCI device. That could be caused by a
1279 * Hot-Plug event, or because the driver is going to be removed from
1282 static void e1000_remove(struct pci_dev
*pdev
)
1284 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1285 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1286 struct e1000_hw
*hw
= &adapter
->hw
;
1289 e1000_down_and_stop(adapter
);
1290 e1000_release_manageability(adapter
);
1292 unregister_netdev(netdev
);
1294 e1000_phy_hw_reset(hw
);
1296 kfree(adapter
->tx_ring
);
1297 kfree(adapter
->rx_ring
);
1299 if (hw
->mac_type
== e1000_ce4100
)
1300 iounmap(hw
->ce4100_gbe_mdio_base_virt
);
1301 iounmap(hw
->hw_addr
);
1302 if (hw
->flash_address
)
1303 iounmap(hw
->flash_address
);
1304 pci_release_selected_regions(pdev
, adapter
->bars
);
1306 disable_dev
= !test_and_set_bit(__E1000_DISABLED
, &adapter
->flags
);
1307 free_netdev(netdev
);
1310 pci_disable_device(pdev
);
1314 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1315 * @adapter: board private structure to initialize
1317 * e1000_sw_init initializes the Adapter private data structure.
1318 * e1000_init_hw_struct MUST be called before this function
1320 static int e1000_sw_init(struct e1000_adapter
*adapter
)
1322 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1324 adapter
->num_tx_queues
= 1;
1325 adapter
->num_rx_queues
= 1;
1327 if (e1000_alloc_queues(adapter
)) {
1328 e_err(probe
, "Unable to allocate memory for queues\n");
1332 /* Explicitly disable IRQ since the NIC can be in any state. */
1333 e1000_irq_disable(adapter
);
1335 spin_lock_init(&adapter
->stats_lock
);
1337 set_bit(__E1000_DOWN
, &adapter
->flags
);
1343 * e1000_alloc_queues - Allocate memory for all rings
1344 * @adapter: board private structure to initialize
1346 * We allocate one ring per queue at run-time since we don't know the
1347 * number of queues at compile-time.
1349 static int e1000_alloc_queues(struct e1000_adapter
*adapter
)
1351 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1352 sizeof(struct e1000_tx_ring
), GFP_KERNEL
);
1353 if (!adapter
->tx_ring
)
1356 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
1357 sizeof(struct e1000_rx_ring
), GFP_KERNEL
);
1358 if (!adapter
->rx_ring
) {
1359 kfree(adapter
->tx_ring
);
1363 return E1000_SUCCESS
;
1367 * e1000_open - Called when a network interface is made active
1368 * @netdev: network interface device structure
1370 * Returns 0 on success, negative value on failure
1372 * The open entry point is called when a network interface is made
1373 * active by the system (IFF_UP). At this point all resources needed
1374 * for transmit and receive operations are allocated, the interrupt
1375 * handler is registered with the OS, the watchdog task is started,
1376 * and the stack is notified that the interface is ready.
1378 int e1000_open(struct net_device
*netdev
)
1380 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1381 struct e1000_hw
*hw
= &adapter
->hw
;
1384 /* disallow open during test */
1385 if (test_bit(__E1000_TESTING
, &adapter
->flags
))
1388 netif_carrier_off(netdev
);
1390 /* allocate transmit descriptors */
1391 err
= e1000_setup_all_tx_resources(adapter
);
1395 /* allocate receive descriptors */
1396 err
= e1000_setup_all_rx_resources(adapter
);
1400 e1000_power_up_phy(adapter
);
1402 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1403 if ((hw
->mng_cookie
.status
&
1404 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1405 e1000_update_mng_vlan(adapter
);
1408 /* before we allocate an interrupt, we must be ready to handle it.
1409 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1410 * as soon as we call pci_request_irq, so we have to setup our
1411 * clean_rx handler before we do so.
1413 e1000_configure(adapter
);
1415 err
= e1000_request_irq(adapter
);
1419 /* From here on the code is the same as e1000_up() */
1420 clear_bit(__E1000_DOWN
, &adapter
->flags
);
1422 napi_enable(&adapter
->napi
);
1424 e1000_irq_enable(adapter
);
1426 netif_start_queue(netdev
);
1428 /* fire a link status change interrupt to start the watchdog */
1429 ew32(ICS
, E1000_ICS_LSC
);
1431 return E1000_SUCCESS
;
1434 e1000_power_down_phy(adapter
);
1435 e1000_free_all_rx_resources(adapter
);
1437 e1000_free_all_tx_resources(adapter
);
1439 e1000_reset(adapter
);
1445 * e1000_close - Disables a network interface
1446 * @netdev: network interface device structure
1448 * Returns 0, this is not allowed to fail
1450 * The close entry point is called when an interface is de-activated
1451 * by the OS. The hardware is still under the drivers control, but
1452 * needs to be disabled. A global MAC reset is issued to stop the
1453 * hardware, and all transmit and receive resources are freed.
1455 int e1000_close(struct net_device
*netdev
)
1457 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1458 struct e1000_hw
*hw
= &adapter
->hw
;
1459 int count
= E1000_CHECK_RESET_COUNT
;
1461 while (test_bit(__E1000_RESETTING
, &adapter
->flags
) && count
--)
1462 usleep_range(10000, 20000);
1464 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
1465 e1000_down(adapter
);
1466 e1000_power_down_phy(adapter
);
1467 e1000_free_irq(adapter
);
1469 e1000_free_all_tx_resources(adapter
);
1470 e1000_free_all_rx_resources(adapter
);
1472 /* kill manageability vlan ID if supported, but not if a vlan with
1473 * the same ID is registered on the host OS (let 8021q kill it)
1475 if ((hw
->mng_cookie
.status
&
1476 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
1477 !test_bit(adapter
->mng_vlan_id
, adapter
->active_vlans
)) {
1478 e1000_vlan_rx_kill_vid(netdev
, htons(ETH_P_8021Q
),
1479 adapter
->mng_vlan_id
);
1486 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1487 * @adapter: address of board private structure
1488 * @start: address of beginning of memory
1489 * @len: length of memory
1491 static bool e1000_check_64k_bound(struct e1000_adapter
*adapter
, void *start
,
1494 struct e1000_hw
*hw
= &adapter
->hw
;
1495 unsigned long begin
= (unsigned long)start
;
1496 unsigned long end
= begin
+ len
;
1498 /* First rev 82545 and 82546 need to not allow any memory
1499 * write location to cross 64k boundary due to errata 23
1501 if (hw
->mac_type
== e1000_82545
||
1502 hw
->mac_type
== e1000_ce4100
||
1503 hw
->mac_type
== e1000_82546
) {
1504 return ((begin
^ (end
- 1)) >> 16) != 0 ? false : true;
1511 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1512 * @adapter: board private structure
1513 * @txdr: tx descriptor ring (for a specific queue) to setup
1515 * Return 0 on success, negative on failure
1517 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1518 struct e1000_tx_ring
*txdr
)
1520 struct pci_dev
*pdev
= adapter
->pdev
;
1523 size
= sizeof(struct e1000_tx_buffer
) * txdr
->count
;
1524 txdr
->buffer_info
= vzalloc(size
);
1525 if (!txdr
->buffer_info
)
1528 /* round up to nearest 4K */
1530 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1531 txdr
->size
= ALIGN(txdr
->size
, 4096);
1533 txdr
->desc
= dma_alloc_coherent(&pdev
->dev
, txdr
->size
, &txdr
->dma
,
1537 vfree(txdr
->buffer_info
);
1541 /* Fix for errata 23, can't cross 64kB boundary */
1542 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1543 void *olddesc
= txdr
->desc
;
1544 dma_addr_t olddma
= txdr
->dma
;
1545 e_err(tx_err
, "txdr align check failed: %u bytes at %p\n",
1546 txdr
->size
, txdr
->desc
);
1547 /* Try again, without freeing the previous */
1548 txdr
->desc
= dma_alloc_coherent(&pdev
->dev
, txdr
->size
,
1549 &txdr
->dma
, GFP_KERNEL
);
1550 /* Failed allocation, critical failure */
1552 dma_free_coherent(&pdev
->dev
, txdr
->size
, olddesc
,
1554 goto setup_tx_desc_die
;
1557 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1559 dma_free_coherent(&pdev
->dev
, txdr
->size
, txdr
->desc
,
1561 dma_free_coherent(&pdev
->dev
, txdr
->size
, olddesc
,
1563 e_err(probe
, "Unable to allocate aligned memory "
1564 "for the transmit descriptor ring\n");
1565 vfree(txdr
->buffer_info
);
1568 /* Free old allocation, new allocation was successful */
1569 dma_free_coherent(&pdev
->dev
, txdr
->size
, olddesc
,
1573 memset(txdr
->desc
, 0, txdr
->size
);
1575 txdr
->next_to_use
= 0;
1576 txdr
->next_to_clean
= 0;
1582 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1583 * (Descriptors) for all queues
1584 * @adapter: board private structure
1586 * Return 0 on success, negative on failure
1588 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1592 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1593 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1595 e_err(probe
, "Allocation for Tx Queue %u failed\n", i
);
1596 for (i
-- ; i
>= 0; i
--)
1597 e1000_free_tx_resources(adapter
,
1598 &adapter
->tx_ring
[i
]);
1607 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1608 * @adapter: board private structure
1610 * Configure the Tx unit of the MAC after a reset.
1612 static void e1000_configure_tx(struct e1000_adapter
*adapter
)
1615 struct e1000_hw
*hw
= &adapter
->hw
;
1616 u32 tdlen
, tctl
, tipg
;
1619 /* Setup the HW Tx Head and Tail descriptor pointers */
1621 switch (adapter
->num_tx_queues
) {
1624 tdba
= adapter
->tx_ring
[0].dma
;
1625 tdlen
= adapter
->tx_ring
[0].count
*
1626 sizeof(struct e1000_tx_desc
);
1628 ew32(TDBAH
, (tdba
>> 32));
1629 ew32(TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1632 adapter
->tx_ring
[0].tdh
= ((hw
->mac_type
>= e1000_82543
) ?
1633 E1000_TDH
: E1000_82542_TDH
);
1634 adapter
->tx_ring
[0].tdt
= ((hw
->mac_type
>= e1000_82543
) ?
1635 E1000_TDT
: E1000_82542_TDT
);
1639 /* Set the default values for the Tx Inter Packet Gap timer */
1640 if ((hw
->media_type
== e1000_media_type_fiber
||
1641 hw
->media_type
== e1000_media_type_internal_serdes
))
1642 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1644 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1646 switch (hw
->mac_type
) {
1647 case e1000_82542_rev2_0
:
1648 case e1000_82542_rev2_1
:
1649 tipg
= DEFAULT_82542_TIPG_IPGT
;
1650 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
1651 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
1654 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1655 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
1658 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1659 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1662 /* Set the Tx Interrupt Delay register */
1664 ew32(TIDV
, adapter
->tx_int_delay
);
1665 if (hw
->mac_type
>= e1000_82540
)
1666 ew32(TADV
, adapter
->tx_abs_int_delay
);
1668 /* Program the Transmit Control Register */
1671 tctl
&= ~E1000_TCTL_CT
;
1672 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1673 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1675 e1000_config_collision_dist(hw
);
1677 /* Setup Transmit Descriptor Settings for eop descriptor */
1678 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
1680 /* only set IDE if we are delaying interrupts using the timers */
1681 if (adapter
->tx_int_delay
)
1682 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
1684 if (hw
->mac_type
< e1000_82543
)
1685 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1687 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1689 /* Cache if we're 82544 running in PCI-X because we'll
1690 * need this to apply a workaround later in the send path.
1692 if (hw
->mac_type
== e1000_82544
&&
1693 hw
->bus_type
== e1000_bus_type_pcix
)
1694 adapter
->pcix_82544
= true;
1701 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1702 * @adapter: board private structure
1703 * @rxdr: rx descriptor ring (for a specific queue) to setup
1705 * Returns 0 on success, negative on failure
1707 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1708 struct e1000_rx_ring
*rxdr
)
1710 struct pci_dev
*pdev
= adapter
->pdev
;
1713 size
= sizeof(struct e1000_rx_buffer
) * rxdr
->count
;
1714 rxdr
->buffer_info
= vzalloc(size
);
1715 if (!rxdr
->buffer_info
)
1718 desc_len
= sizeof(struct e1000_rx_desc
);
1720 /* Round up to nearest 4K */
1722 rxdr
->size
= rxdr
->count
* desc_len
;
1723 rxdr
->size
= ALIGN(rxdr
->size
, 4096);
1725 rxdr
->desc
= dma_alloc_coherent(&pdev
->dev
, rxdr
->size
, &rxdr
->dma
,
1729 vfree(rxdr
->buffer_info
);
1733 /* Fix for errata 23, can't cross 64kB boundary */
1734 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1735 void *olddesc
= rxdr
->desc
;
1736 dma_addr_t olddma
= rxdr
->dma
;
1737 e_err(rx_err
, "rxdr align check failed: %u bytes at %p\n",
1738 rxdr
->size
, rxdr
->desc
);
1739 /* Try again, without freeing the previous */
1740 rxdr
->desc
= dma_alloc_coherent(&pdev
->dev
, rxdr
->size
,
1741 &rxdr
->dma
, GFP_KERNEL
);
1742 /* Failed allocation, critical failure */
1744 dma_free_coherent(&pdev
->dev
, rxdr
->size
, olddesc
,
1746 goto setup_rx_desc_die
;
1749 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1751 dma_free_coherent(&pdev
->dev
, rxdr
->size
, rxdr
->desc
,
1753 dma_free_coherent(&pdev
->dev
, rxdr
->size
, olddesc
,
1755 e_err(probe
, "Unable to allocate aligned memory for "
1756 "the Rx descriptor ring\n");
1757 goto setup_rx_desc_die
;
1759 /* Free old allocation, new allocation was successful */
1760 dma_free_coherent(&pdev
->dev
, rxdr
->size
, olddesc
,
1764 memset(rxdr
->desc
, 0, rxdr
->size
);
1766 rxdr
->next_to_clean
= 0;
1767 rxdr
->next_to_use
= 0;
1768 rxdr
->rx_skb_top
= NULL
;
1774 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1775 * (Descriptors) for all queues
1776 * @adapter: board private structure
1778 * Return 0 on success, negative on failure
1780 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1784 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1785 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1787 e_err(probe
, "Allocation for Rx Queue %u failed\n", i
);
1788 for (i
-- ; i
>= 0; i
--)
1789 e1000_free_rx_resources(adapter
,
1790 &adapter
->rx_ring
[i
]);
1799 * e1000_setup_rctl - configure the receive control registers
1800 * @adapter: Board private structure
1802 static void e1000_setup_rctl(struct e1000_adapter
*adapter
)
1804 struct e1000_hw
*hw
= &adapter
->hw
;
1809 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1811 rctl
|= E1000_RCTL_BAM
| E1000_RCTL_LBM_NO
|
1812 E1000_RCTL_RDMTS_HALF
|
1813 (hw
->mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1815 if (hw
->tbi_compatibility_on
== 1)
1816 rctl
|= E1000_RCTL_SBP
;
1818 rctl
&= ~E1000_RCTL_SBP
;
1820 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1821 rctl
&= ~E1000_RCTL_LPE
;
1823 rctl
|= E1000_RCTL_LPE
;
1825 /* Setup buffer sizes */
1826 rctl
&= ~E1000_RCTL_SZ_4096
;
1827 rctl
|= E1000_RCTL_BSEX
;
1828 switch (adapter
->rx_buffer_len
) {
1829 case E1000_RXBUFFER_2048
:
1831 rctl
|= E1000_RCTL_SZ_2048
;
1832 rctl
&= ~E1000_RCTL_BSEX
;
1834 case E1000_RXBUFFER_4096
:
1835 rctl
|= E1000_RCTL_SZ_4096
;
1837 case E1000_RXBUFFER_8192
:
1838 rctl
|= E1000_RCTL_SZ_8192
;
1840 case E1000_RXBUFFER_16384
:
1841 rctl
|= E1000_RCTL_SZ_16384
;
1845 /* This is useful for sniffing bad packets. */
1846 if (adapter
->netdev
->features
& NETIF_F_RXALL
) {
1847 /* UPE and MPE will be handled by normal PROMISC logic
1848 * in e1000e_set_rx_mode
1850 rctl
|= (E1000_RCTL_SBP
| /* Receive bad packets */
1851 E1000_RCTL_BAM
| /* RX All Bcast Pkts */
1852 E1000_RCTL_PMCF
); /* RX All MAC Ctrl Pkts */
1854 rctl
&= ~(E1000_RCTL_VFE
| /* Disable VLAN filter */
1855 E1000_RCTL_DPF
| /* Allow filtered pause */
1856 E1000_RCTL_CFIEN
); /* Dis VLAN CFIEN Filter */
1857 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
1858 * and that breaks VLANs.
1866 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1867 * @adapter: board private structure
1869 * Configure the Rx unit of the MAC after a reset.
1871 static void e1000_configure_rx(struct e1000_adapter
*adapter
)
1874 struct e1000_hw
*hw
= &adapter
->hw
;
1875 u32 rdlen
, rctl
, rxcsum
;
1877 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
1878 rdlen
= adapter
->rx_ring
[0].count
*
1879 sizeof(struct e1000_rx_desc
);
1880 adapter
->clean_rx
= e1000_clean_jumbo_rx_irq
;
1881 adapter
->alloc_rx_buf
= e1000_alloc_jumbo_rx_buffers
;
1883 rdlen
= adapter
->rx_ring
[0].count
*
1884 sizeof(struct e1000_rx_desc
);
1885 adapter
->clean_rx
= e1000_clean_rx_irq
;
1886 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1889 /* disable receives while setting up the descriptors */
1891 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1893 /* set the Receive Delay Timer Register */
1894 ew32(RDTR
, adapter
->rx_int_delay
);
1896 if (hw
->mac_type
>= e1000_82540
) {
1897 ew32(RADV
, adapter
->rx_abs_int_delay
);
1898 if (adapter
->itr_setting
!= 0)
1899 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
1902 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1903 * the Base and Length of the Rx Descriptor Ring
1905 switch (adapter
->num_rx_queues
) {
1908 rdba
= adapter
->rx_ring
[0].dma
;
1910 ew32(RDBAH
, (rdba
>> 32));
1911 ew32(RDBAL
, (rdba
& 0x00000000ffffffffULL
));
1914 adapter
->rx_ring
[0].rdh
= ((hw
->mac_type
>= e1000_82543
) ?
1915 E1000_RDH
: E1000_82542_RDH
);
1916 adapter
->rx_ring
[0].rdt
= ((hw
->mac_type
>= e1000_82543
) ?
1917 E1000_RDT
: E1000_82542_RDT
);
1921 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1922 if (hw
->mac_type
>= e1000_82543
) {
1923 rxcsum
= er32(RXCSUM
);
1924 if (adapter
->rx_csum
)
1925 rxcsum
|= E1000_RXCSUM_TUOFL
;
1927 /* don't need to clear IPPCSE as it defaults to 0 */
1928 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1929 ew32(RXCSUM
, rxcsum
);
1932 /* Enable Receives */
1933 ew32(RCTL
, rctl
| E1000_RCTL_EN
);
1937 * e1000_free_tx_resources - Free Tx Resources per Queue
1938 * @adapter: board private structure
1939 * @tx_ring: Tx descriptor ring for a specific queue
1941 * Free all transmit software resources
1943 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
1944 struct e1000_tx_ring
*tx_ring
)
1946 struct pci_dev
*pdev
= adapter
->pdev
;
1948 e1000_clean_tx_ring(adapter
, tx_ring
);
1950 vfree(tx_ring
->buffer_info
);
1951 tx_ring
->buffer_info
= NULL
;
1953 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1956 tx_ring
->desc
= NULL
;
1960 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1961 * @adapter: board private structure
1963 * Free all transmit software resources
1965 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
1969 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1970 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1974 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
1975 struct e1000_tx_buffer
*buffer_info
)
1977 if (buffer_info
->dma
) {
1978 if (buffer_info
->mapped_as_page
)
1979 dma_unmap_page(&adapter
->pdev
->dev
, buffer_info
->dma
,
1980 buffer_info
->length
, DMA_TO_DEVICE
);
1982 dma_unmap_single(&adapter
->pdev
->dev
, buffer_info
->dma
,
1983 buffer_info
->length
,
1985 buffer_info
->dma
= 0;
1987 if (buffer_info
->skb
) {
1988 dev_kfree_skb_any(buffer_info
->skb
);
1989 buffer_info
->skb
= NULL
;
1991 buffer_info
->time_stamp
= 0;
1992 /* buffer_info must be completely set up in the transmit path */
1996 * e1000_clean_tx_ring - Free Tx Buffers
1997 * @adapter: board private structure
1998 * @tx_ring: ring to be cleaned
2000 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
2001 struct e1000_tx_ring
*tx_ring
)
2003 struct e1000_hw
*hw
= &adapter
->hw
;
2004 struct e1000_tx_buffer
*buffer_info
;
2008 /* Free all the Tx ring sk_buffs */
2010 for (i
= 0; i
< tx_ring
->count
; i
++) {
2011 buffer_info
= &tx_ring
->buffer_info
[i
];
2012 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
2015 netdev_reset_queue(adapter
->netdev
);
2016 size
= sizeof(struct e1000_tx_buffer
) * tx_ring
->count
;
2017 memset(tx_ring
->buffer_info
, 0, size
);
2019 /* Zero out the descriptor ring */
2021 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2023 tx_ring
->next_to_use
= 0;
2024 tx_ring
->next_to_clean
= 0;
2025 tx_ring
->last_tx_tso
= false;
2027 writel(0, hw
->hw_addr
+ tx_ring
->tdh
);
2028 writel(0, hw
->hw_addr
+ tx_ring
->tdt
);
2032 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2033 * @adapter: board private structure
2035 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
2039 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2040 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
2044 * e1000_free_rx_resources - Free Rx Resources
2045 * @adapter: board private structure
2046 * @rx_ring: ring to clean the resources from
2048 * Free all receive software resources
2050 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
2051 struct e1000_rx_ring
*rx_ring
)
2053 struct pci_dev
*pdev
= adapter
->pdev
;
2055 e1000_clean_rx_ring(adapter
, rx_ring
);
2057 vfree(rx_ring
->buffer_info
);
2058 rx_ring
->buffer_info
= NULL
;
2060 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
2063 rx_ring
->desc
= NULL
;
2067 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2068 * @adapter: board private structure
2070 * Free all receive software resources
2072 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
2076 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2077 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2080 #define E1000_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN)
2081 static unsigned int e1000_frag_len(const struct e1000_adapter
*a
)
2083 return SKB_DATA_ALIGN(a
->rx_buffer_len
+ E1000_HEADROOM
) +
2084 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
2087 static void *e1000_alloc_frag(const struct e1000_adapter
*a
)
2089 unsigned int len
= e1000_frag_len(a
);
2090 u8
*data
= netdev_alloc_frag(len
);
2093 data
+= E1000_HEADROOM
;
2098 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2099 * @adapter: board private structure
2100 * @rx_ring: ring to free buffers from
2102 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
2103 struct e1000_rx_ring
*rx_ring
)
2105 struct e1000_hw
*hw
= &adapter
->hw
;
2106 struct e1000_rx_buffer
*buffer_info
;
2107 struct pci_dev
*pdev
= adapter
->pdev
;
2111 /* Free all the Rx netfrags */
2112 for (i
= 0; i
< rx_ring
->count
; i
++) {
2113 buffer_info
= &rx_ring
->buffer_info
[i
];
2114 if (adapter
->clean_rx
== e1000_clean_rx_irq
) {
2115 if (buffer_info
->dma
)
2116 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
2117 adapter
->rx_buffer_len
,
2119 if (buffer_info
->rxbuf
.data
) {
2120 skb_free_frag(buffer_info
->rxbuf
.data
);
2121 buffer_info
->rxbuf
.data
= NULL
;
2123 } else if (adapter
->clean_rx
== e1000_clean_jumbo_rx_irq
) {
2124 if (buffer_info
->dma
)
2125 dma_unmap_page(&pdev
->dev
, buffer_info
->dma
,
2126 adapter
->rx_buffer_len
,
2128 if (buffer_info
->rxbuf
.page
) {
2129 put_page(buffer_info
->rxbuf
.page
);
2130 buffer_info
->rxbuf
.page
= NULL
;
2134 buffer_info
->dma
= 0;
2137 /* there also may be some cached data from a chained receive */
2138 napi_free_frags(&adapter
->napi
);
2139 rx_ring
->rx_skb_top
= NULL
;
2141 size
= sizeof(struct e1000_rx_buffer
) * rx_ring
->count
;
2142 memset(rx_ring
->buffer_info
, 0, size
);
2144 /* Zero out the descriptor ring */
2145 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2147 rx_ring
->next_to_clean
= 0;
2148 rx_ring
->next_to_use
= 0;
2150 writel(0, hw
->hw_addr
+ rx_ring
->rdh
);
2151 writel(0, hw
->hw_addr
+ rx_ring
->rdt
);
2155 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2156 * @adapter: board private structure
2158 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2162 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2163 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2166 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2167 * and memory write and invalidate disabled for certain operations
2169 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2171 struct e1000_hw
*hw
= &adapter
->hw
;
2172 struct net_device
*netdev
= adapter
->netdev
;
2175 e1000_pci_clear_mwi(hw
);
2178 rctl
|= E1000_RCTL_RST
;
2180 E1000_WRITE_FLUSH();
2183 if (netif_running(netdev
))
2184 e1000_clean_all_rx_rings(adapter
);
2187 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2189 struct e1000_hw
*hw
= &adapter
->hw
;
2190 struct net_device
*netdev
= adapter
->netdev
;
2194 rctl
&= ~E1000_RCTL_RST
;
2196 E1000_WRITE_FLUSH();
2199 if (hw
->pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2200 e1000_pci_set_mwi(hw
);
2202 if (netif_running(netdev
)) {
2203 /* No need to loop, because 82542 supports only 1 queue */
2204 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[0];
2205 e1000_configure_rx(adapter
);
2206 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
2211 * e1000_set_mac - Change the Ethernet Address of the NIC
2212 * @netdev: network interface device structure
2213 * @p: pointer to an address structure
2215 * Returns 0 on success, negative on failure
2217 static int e1000_set_mac(struct net_device
*netdev
, void *p
)
2219 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2220 struct e1000_hw
*hw
= &adapter
->hw
;
2221 struct sockaddr
*addr
= p
;
2223 if (!is_valid_ether_addr(addr
->sa_data
))
2224 return -EADDRNOTAVAIL
;
2226 /* 82542 2.0 needs to be in reset to write receive address registers */
2228 if (hw
->mac_type
== e1000_82542_rev2_0
)
2229 e1000_enter_82542_rst(adapter
);
2231 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2232 memcpy(hw
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2234 e1000_rar_set(hw
, hw
->mac_addr
, 0);
2236 if (hw
->mac_type
== e1000_82542_rev2_0
)
2237 e1000_leave_82542_rst(adapter
);
2243 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2244 * @netdev: network interface device structure
2246 * The set_rx_mode entry point is called whenever the unicast or multicast
2247 * address lists or the network interface flags are updated. This routine is
2248 * responsible for configuring the hardware for proper unicast, multicast,
2249 * promiscuous mode, and all-multi behavior.
2251 static void e1000_set_rx_mode(struct net_device
*netdev
)
2253 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2254 struct e1000_hw
*hw
= &adapter
->hw
;
2255 struct netdev_hw_addr
*ha
;
2256 bool use_uc
= false;
2259 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2260 int mta_reg_count
= E1000_NUM_MTA_REGISTERS
;
2261 u32
*mcarray
= kcalloc(mta_reg_count
, sizeof(u32
), GFP_ATOMIC
);
2266 /* Check for Promiscuous and All Multicast modes */
2270 if (netdev
->flags
& IFF_PROMISC
) {
2271 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2272 rctl
&= ~E1000_RCTL_VFE
;
2274 if (netdev
->flags
& IFF_ALLMULTI
)
2275 rctl
|= E1000_RCTL_MPE
;
2277 rctl
&= ~E1000_RCTL_MPE
;
2278 /* Enable VLAN filter if there is a VLAN */
2279 if (e1000_vlan_used(adapter
))
2280 rctl
|= E1000_RCTL_VFE
;
2283 if (netdev_uc_count(netdev
) > rar_entries
- 1) {
2284 rctl
|= E1000_RCTL_UPE
;
2285 } else if (!(netdev
->flags
& IFF_PROMISC
)) {
2286 rctl
&= ~E1000_RCTL_UPE
;
2292 /* 82542 2.0 needs to be in reset to write receive address registers */
2294 if (hw
->mac_type
== e1000_82542_rev2_0
)
2295 e1000_enter_82542_rst(adapter
);
2297 /* load the first 14 addresses into the exact filters 1-14. Unicast
2298 * addresses take precedence to avoid disabling unicast filtering
2301 * RAR 0 is used for the station MAC address
2302 * if there are not 14 addresses, go ahead and clear the filters
2306 netdev_for_each_uc_addr(ha
, netdev
) {
2307 if (i
== rar_entries
)
2309 e1000_rar_set(hw
, ha
->addr
, i
++);
2312 netdev_for_each_mc_addr(ha
, netdev
) {
2313 if (i
== rar_entries
) {
2314 /* load any remaining addresses into the hash table */
2315 u32 hash_reg
, hash_bit
, mta
;
2316 hash_value
= e1000_hash_mc_addr(hw
, ha
->addr
);
2317 hash_reg
= (hash_value
>> 5) & 0x7F;
2318 hash_bit
= hash_value
& 0x1F;
2319 mta
= (1 << hash_bit
);
2320 mcarray
[hash_reg
] |= mta
;
2322 e1000_rar_set(hw
, ha
->addr
, i
++);
2326 for (; i
< rar_entries
; i
++) {
2327 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2328 E1000_WRITE_FLUSH();
2329 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2330 E1000_WRITE_FLUSH();
2333 /* write the hash table completely, write from bottom to avoid
2334 * both stupid write combining chipsets, and flushing each write
2336 for (i
= mta_reg_count
- 1; i
>= 0 ; i
--) {
2337 /* If we are on an 82544 has an errata where writing odd
2338 * offsets overwrites the previous even offset, but writing
2339 * backwards over the range solves the issue by always
2340 * writing the odd offset first
2342 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, mcarray
[i
]);
2344 E1000_WRITE_FLUSH();
2346 if (hw
->mac_type
== e1000_82542_rev2_0
)
2347 e1000_leave_82542_rst(adapter
);
2353 * e1000_update_phy_info_task - get phy info
2354 * @work: work struct contained inside adapter struct
2356 * Need to wait a few seconds after link up to get diagnostic information from
2359 static void e1000_update_phy_info_task(struct work_struct
*work
)
2361 struct e1000_adapter
*adapter
= container_of(work
,
2362 struct e1000_adapter
,
2363 phy_info_task
.work
);
2365 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
2369 * e1000_82547_tx_fifo_stall_task - task to complete work
2370 * @work: work struct contained inside adapter struct
2372 static void e1000_82547_tx_fifo_stall_task(struct work_struct
*work
)
2374 struct e1000_adapter
*adapter
= container_of(work
,
2375 struct e1000_adapter
,
2376 fifo_stall_task
.work
);
2377 struct e1000_hw
*hw
= &adapter
->hw
;
2378 struct net_device
*netdev
= adapter
->netdev
;
2381 if (atomic_read(&adapter
->tx_fifo_stall
)) {
2382 if ((er32(TDT
) == er32(TDH
)) &&
2383 (er32(TDFT
) == er32(TDFH
)) &&
2384 (er32(TDFTS
) == er32(TDFHS
))) {
2386 ew32(TCTL
, tctl
& ~E1000_TCTL_EN
);
2387 ew32(TDFT
, adapter
->tx_head_addr
);
2388 ew32(TDFH
, adapter
->tx_head_addr
);
2389 ew32(TDFTS
, adapter
->tx_head_addr
);
2390 ew32(TDFHS
, adapter
->tx_head_addr
);
2392 E1000_WRITE_FLUSH();
2394 adapter
->tx_fifo_head
= 0;
2395 atomic_set(&adapter
->tx_fifo_stall
, 0);
2396 netif_wake_queue(netdev
);
2397 } else if (!test_bit(__E1000_DOWN
, &adapter
->flags
)) {
2398 schedule_delayed_work(&adapter
->fifo_stall_task
, 1);
2403 bool e1000_has_link(struct e1000_adapter
*adapter
)
2405 struct e1000_hw
*hw
= &adapter
->hw
;
2406 bool link_active
= false;
2408 /* get_link_status is set on LSC (link status) interrupt or rx
2409 * sequence error interrupt (except on intel ce4100).
2410 * get_link_status will stay false until the
2411 * e1000_check_for_link establishes link for copper adapters
2414 switch (hw
->media_type
) {
2415 case e1000_media_type_copper
:
2416 if (hw
->mac_type
== e1000_ce4100
)
2417 hw
->get_link_status
= 1;
2418 if (hw
->get_link_status
) {
2419 e1000_check_for_link(hw
);
2420 link_active
= !hw
->get_link_status
;
2425 case e1000_media_type_fiber
:
2426 e1000_check_for_link(hw
);
2427 link_active
= !!(er32(STATUS
) & E1000_STATUS_LU
);
2429 case e1000_media_type_internal_serdes
:
2430 e1000_check_for_link(hw
);
2431 link_active
= hw
->serdes_has_link
;
2441 * e1000_watchdog - work function
2442 * @work: work struct contained inside adapter struct
2444 static void e1000_watchdog(struct work_struct
*work
)
2446 struct e1000_adapter
*adapter
= container_of(work
,
2447 struct e1000_adapter
,
2448 watchdog_task
.work
);
2449 struct e1000_hw
*hw
= &adapter
->hw
;
2450 struct net_device
*netdev
= adapter
->netdev
;
2451 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2454 link
= e1000_has_link(adapter
);
2455 if ((netif_carrier_ok(netdev
)) && link
)
2459 if (!netif_carrier_ok(netdev
)) {
2462 /* update snapshot of PHY registers on LSC */
2463 e1000_get_speed_and_duplex(hw
,
2464 &adapter
->link_speed
,
2465 &adapter
->link_duplex
);
2468 pr_info("%s NIC Link is Up %d Mbps %s, "
2469 "Flow Control: %s\n",
2471 adapter
->link_speed
,
2472 adapter
->link_duplex
== FULL_DUPLEX
?
2473 "Full Duplex" : "Half Duplex",
2474 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
&
2475 E1000_CTRL_RFCE
)) ? "RX/TX" : ((ctrl
&
2476 E1000_CTRL_RFCE
) ? "RX" : ((ctrl
&
2477 E1000_CTRL_TFCE
) ? "TX" : "None")));
2479 /* adjust timeout factor according to speed/duplex */
2480 adapter
->tx_timeout_factor
= 1;
2481 switch (adapter
->link_speed
) {
2484 adapter
->tx_timeout_factor
= 16;
2488 /* maybe add some timeout factor ? */
2492 /* enable transmits in the hardware */
2494 tctl
|= E1000_TCTL_EN
;
2497 netif_carrier_on(netdev
);
2498 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
2499 schedule_delayed_work(&adapter
->phy_info_task
,
2501 adapter
->smartspeed
= 0;
2504 if (netif_carrier_ok(netdev
)) {
2505 adapter
->link_speed
= 0;
2506 adapter
->link_duplex
= 0;
2507 pr_info("%s NIC Link is Down\n",
2509 netif_carrier_off(netdev
);
2511 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
2512 schedule_delayed_work(&adapter
->phy_info_task
,
2516 e1000_smartspeed(adapter
);
2520 e1000_update_stats(adapter
);
2522 hw
->tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2523 adapter
->tpt_old
= adapter
->stats
.tpt
;
2524 hw
->collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2525 adapter
->colc_old
= adapter
->stats
.colc
;
2527 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2528 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2529 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2530 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2532 e1000_update_adaptive(hw
);
2534 if (!netif_carrier_ok(netdev
)) {
2535 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2536 /* We've lost link, so the controller stops DMA,
2537 * but we've got queued Tx work that's never going
2538 * to get done, so reset controller to flush Tx.
2539 * (Do the reset outside of interrupt context).
2541 adapter
->tx_timeout_count
++;
2542 schedule_work(&adapter
->reset_task
);
2543 /* exit immediately since reset is imminent */
2548 /* Simple mode for Interrupt Throttle Rate (ITR) */
2549 if (hw
->mac_type
>= e1000_82540
&& adapter
->itr_setting
== 4) {
2550 /* Symmetric Tx/Rx gets a reduced ITR=2000;
2551 * Total asymmetrical Tx or Rx gets ITR=8000;
2552 * everyone else is between 2000-8000.
2554 u32 goc
= (adapter
->gotcl
+ adapter
->gorcl
) / 10000;
2555 u32 dif
= (adapter
->gotcl
> adapter
->gorcl
?
2556 adapter
->gotcl
- adapter
->gorcl
:
2557 adapter
->gorcl
- adapter
->gotcl
) / 10000;
2558 u32 itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
2560 ew32(ITR
, 1000000000 / (itr
* 256));
2563 /* Cause software interrupt to ensure rx ring is cleaned */
2564 ew32(ICS
, E1000_ICS_RXDMT0
);
2566 /* Force detection of hung controller every watchdog period */
2567 adapter
->detect_tx_hung
= true;
2569 /* Reschedule the task */
2570 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
2571 schedule_delayed_work(&adapter
->watchdog_task
, 2 * HZ
);
2574 enum latency_range
{
2578 latency_invalid
= 255
2582 * e1000_update_itr - update the dynamic ITR value based on statistics
2583 * @adapter: pointer to adapter
2584 * @itr_setting: current adapter->itr
2585 * @packets: the number of packets during this measurement interval
2586 * @bytes: the number of bytes during this measurement interval
2588 * Stores a new ITR value based on packets and byte
2589 * counts during the last interrupt. The advantage of per interrupt
2590 * computation is faster updates and more accurate ITR for the current
2591 * traffic pattern. Constants in this function were computed
2592 * based on theoretical maximum wire speed and thresholds were set based
2593 * on testing data as well as attempting to minimize response time
2594 * while increasing bulk throughput.
2595 * this functionality is controlled by the InterruptThrottleRate module
2596 * parameter (see e1000_param.c)
2598 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
2599 u16 itr_setting
, int packets
, int bytes
)
2601 unsigned int retval
= itr_setting
;
2602 struct e1000_hw
*hw
= &adapter
->hw
;
2604 if (unlikely(hw
->mac_type
< e1000_82540
))
2605 goto update_itr_done
;
2608 goto update_itr_done
;
2610 switch (itr_setting
) {
2611 case lowest_latency
:
2612 /* jumbo frames get bulk treatment*/
2613 if (bytes
/packets
> 8000)
2614 retval
= bulk_latency
;
2615 else if ((packets
< 5) && (bytes
> 512))
2616 retval
= low_latency
;
2618 case low_latency
: /* 50 usec aka 20000 ints/s */
2619 if (bytes
> 10000) {
2620 /* jumbo frames need bulk latency setting */
2621 if (bytes
/packets
> 8000)
2622 retval
= bulk_latency
;
2623 else if ((packets
< 10) || ((bytes
/packets
) > 1200))
2624 retval
= bulk_latency
;
2625 else if ((packets
> 35))
2626 retval
= lowest_latency
;
2627 } else if (bytes
/packets
> 2000)
2628 retval
= bulk_latency
;
2629 else if (packets
<= 2 && bytes
< 512)
2630 retval
= lowest_latency
;
2632 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2633 if (bytes
> 25000) {
2635 retval
= low_latency
;
2636 } else if (bytes
< 6000) {
2637 retval
= low_latency
;
2646 static void e1000_set_itr(struct e1000_adapter
*adapter
)
2648 struct e1000_hw
*hw
= &adapter
->hw
;
2650 u32 new_itr
= adapter
->itr
;
2652 if (unlikely(hw
->mac_type
< e1000_82540
))
2655 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2656 if (unlikely(adapter
->link_speed
!= SPEED_1000
)) {
2662 adapter
->tx_itr
= e1000_update_itr(adapter
, adapter
->tx_itr
,
2663 adapter
->total_tx_packets
,
2664 adapter
->total_tx_bytes
);
2665 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2666 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
2667 adapter
->tx_itr
= low_latency
;
2669 adapter
->rx_itr
= e1000_update_itr(adapter
, adapter
->rx_itr
,
2670 adapter
->total_rx_packets
,
2671 adapter
->total_rx_bytes
);
2672 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2673 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
2674 adapter
->rx_itr
= low_latency
;
2676 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2678 switch (current_itr
) {
2679 /* counts and packets in update_itr are dependent on these numbers */
2680 case lowest_latency
:
2684 new_itr
= 20000; /* aka hwitr = ~200 */
2694 if (new_itr
!= adapter
->itr
) {
2695 /* this attempts to bias the interrupt rate towards Bulk
2696 * by adding intermediate steps when interrupt rate is
2699 new_itr
= new_itr
> adapter
->itr
?
2700 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2702 adapter
->itr
= new_itr
;
2703 ew32(ITR
, 1000000000 / (new_itr
* 256));
2707 #define E1000_TX_FLAGS_CSUM 0x00000001
2708 #define E1000_TX_FLAGS_VLAN 0x00000002
2709 #define E1000_TX_FLAGS_TSO 0x00000004
2710 #define E1000_TX_FLAGS_IPV4 0x00000008
2711 #define E1000_TX_FLAGS_NO_FCS 0x00000010
2712 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2713 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2715 static int e1000_tso(struct e1000_adapter
*adapter
,
2716 struct e1000_tx_ring
*tx_ring
, struct sk_buff
*skb
,
2719 struct e1000_context_desc
*context_desc
;
2720 struct e1000_tx_buffer
*buffer_info
;
2723 u16 ipcse
= 0, tucse
, mss
;
2724 u8 ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2726 if (skb_is_gso(skb
)) {
2729 err
= skb_cow_head(skb
, 0);
2733 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2734 mss
= skb_shinfo(skb
)->gso_size
;
2735 if (protocol
== htons(ETH_P_IP
)) {
2736 struct iphdr
*iph
= ip_hdr(skb
);
2739 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2743 cmd_length
= E1000_TXD_CMD_IP
;
2744 ipcse
= skb_transport_offset(skb
) - 1;
2745 } else if (skb_is_gso_v6(skb
)) {
2746 ipv6_hdr(skb
)->payload_len
= 0;
2747 tcp_hdr(skb
)->check
=
2748 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2749 &ipv6_hdr(skb
)->daddr
,
2753 ipcss
= skb_network_offset(skb
);
2754 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
2755 tucss
= skb_transport_offset(skb
);
2756 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
2759 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2760 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2762 i
= tx_ring
->next_to_use
;
2763 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2764 buffer_info
= &tx_ring
->buffer_info
[i
];
2766 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2767 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2768 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2769 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2770 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2771 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2772 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2773 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2774 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2776 buffer_info
->time_stamp
= jiffies
;
2777 buffer_info
->next_to_watch
= i
;
2779 if (++i
== tx_ring
->count
)
2782 tx_ring
->next_to_use
= i
;
2789 static bool e1000_tx_csum(struct e1000_adapter
*adapter
,
2790 struct e1000_tx_ring
*tx_ring
, struct sk_buff
*skb
,
2793 struct e1000_context_desc
*context_desc
;
2794 struct e1000_tx_buffer
*buffer_info
;
2797 u32 cmd_len
= E1000_TXD_CMD_DEXT
;
2799 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
2803 case cpu_to_be16(ETH_P_IP
):
2804 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
2805 cmd_len
|= E1000_TXD_CMD_TCP
;
2807 case cpu_to_be16(ETH_P_IPV6
):
2808 /* XXX not handling all IPV6 headers */
2809 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
2810 cmd_len
|= E1000_TXD_CMD_TCP
;
2813 if (unlikely(net_ratelimit()))
2814 e_warn(drv
, "checksum_partial proto=%x!\n",
2819 css
= skb_checksum_start_offset(skb
);
2821 i
= tx_ring
->next_to_use
;
2822 buffer_info
= &tx_ring
->buffer_info
[i
];
2823 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2825 context_desc
->lower_setup
.ip_config
= 0;
2826 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2827 context_desc
->upper_setup
.tcp_fields
.tucso
=
2828 css
+ skb
->csum_offset
;
2829 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2830 context_desc
->tcp_seg_setup
.data
= 0;
2831 context_desc
->cmd_and_length
= cpu_to_le32(cmd_len
);
2833 buffer_info
->time_stamp
= jiffies
;
2834 buffer_info
->next_to_watch
= i
;
2836 if (unlikely(++i
== tx_ring
->count
))
2839 tx_ring
->next_to_use
= i
;
2844 #define E1000_MAX_TXD_PWR 12
2845 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2847 static int e1000_tx_map(struct e1000_adapter
*adapter
,
2848 struct e1000_tx_ring
*tx_ring
,
2849 struct sk_buff
*skb
, unsigned int first
,
2850 unsigned int max_per_txd
, unsigned int nr_frags
,
2853 struct e1000_hw
*hw
= &adapter
->hw
;
2854 struct pci_dev
*pdev
= adapter
->pdev
;
2855 struct e1000_tx_buffer
*buffer_info
;
2856 unsigned int len
= skb_headlen(skb
);
2857 unsigned int offset
= 0, size
, count
= 0, i
;
2858 unsigned int f
, bytecount
, segs
;
2860 i
= tx_ring
->next_to_use
;
2863 buffer_info
= &tx_ring
->buffer_info
[i
];
2864 size
= min(len
, max_per_txd
);
2865 /* Workaround for Controller erratum --
2866 * descriptor for non-tso packet in a linear SKB that follows a
2867 * tso gets written back prematurely before the data is fully
2868 * DMA'd to the controller
2870 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2872 tx_ring
->last_tx_tso
= false;
2876 /* Workaround for premature desc write-backs
2877 * in TSO mode. Append 4-byte sentinel desc
2879 if (unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
2881 /* work-around for errata 10 and it applies
2882 * to all controllers in PCI-X mode
2883 * The fix is to make sure that the first descriptor of a
2884 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2886 if (unlikely((hw
->bus_type
== e1000_bus_type_pcix
) &&
2887 (size
> 2015) && count
== 0))
2890 /* Workaround for potential 82544 hang in PCI-X. Avoid
2891 * terminating buffers within evenly-aligned dwords.
2893 if (unlikely(adapter
->pcix_82544
&&
2894 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
2898 buffer_info
->length
= size
;
2899 /* set time_stamp *before* dma to help avoid a possible race */
2900 buffer_info
->time_stamp
= jiffies
;
2901 buffer_info
->mapped_as_page
= false;
2902 buffer_info
->dma
= dma_map_single(&pdev
->dev
,
2904 size
, DMA_TO_DEVICE
);
2905 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
))
2907 buffer_info
->next_to_watch
= i
;
2914 if (unlikely(i
== tx_ring
->count
))
2919 for (f
= 0; f
< nr_frags
; f
++) {
2920 const struct skb_frag_struct
*frag
;
2922 frag
= &skb_shinfo(skb
)->frags
[f
];
2923 len
= skb_frag_size(frag
);
2927 unsigned long bufend
;
2929 if (unlikely(i
== tx_ring
->count
))
2932 buffer_info
= &tx_ring
->buffer_info
[i
];
2933 size
= min(len
, max_per_txd
);
2934 /* Workaround for premature desc write-backs
2935 * in TSO mode. Append 4-byte sentinel desc
2937 if (unlikely(mss
&& f
== (nr_frags
-1) &&
2938 size
== len
&& size
> 8))
2940 /* Workaround for potential 82544 hang in PCI-X.
2941 * Avoid terminating buffers within evenly-aligned
2944 bufend
= (unsigned long)
2945 page_to_phys(skb_frag_page(frag
));
2946 bufend
+= offset
+ size
- 1;
2947 if (unlikely(adapter
->pcix_82544
&&
2952 buffer_info
->length
= size
;
2953 buffer_info
->time_stamp
= jiffies
;
2954 buffer_info
->mapped_as_page
= true;
2955 buffer_info
->dma
= skb_frag_dma_map(&pdev
->dev
, frag
,
2956 offset
, size
, DMA_TO_DEVICE
);
2957 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
))
2959 buffer_info
->next_to_watch
= i
;
2967 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
2968 /* multiply data chunks by size of headers */
2969 bytecount
= ((segs
- 1) * skb_headlen(skb
)) + skb
->len
;
2971 tx_ring
->buffer_info
[i
].skb
= skb
;
2972 tx_ring
->buffer_info
[i
].segs
= segs
;
2973 tx_ring
->buffer_info
[i
].bytecount
= bytecount
;
2974 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
2979 dev_err(&pdev
->dev
, "TX DMA map failed\n");
2980 buffer_info
->dma
= 0;
2986 i
+= tx_ring
->count
;
2988 buffer_info
= &tx_ring
->buffer_info
[i
];
2989 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
2995 static void e1000_tx_queue(struct e1000_adapter
*adapter
,
2996 struct e1000_tx_ring
*tx_ring
, int tx_flags
,
2999 struct e1000_tx_desc
*tx_desc
= NULL
;
3000 struct e1000_tx_buffer
*buffer_info
;
3001 u32 txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
3004 if (likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
3005 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
3007 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3009 if (likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
3010 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
3013 if (likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
3014 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
3015 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3018 if (unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
3019 txd_lower
|= E1000_TXD_CMD_VLE
;
3020 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
3023 if (unlikely(tx_flags
& E1000_TX_FLAGS_NO_FCS
))
3024 txd_lower
&= ~(E1000_TXD_CMD_IFCS
);
3026 i
= tx_ring
->next_to_use
;
3029 buffer_info
= &tx_ring
->buffer_info
[i
];
3030 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3031 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3032 tx_desc
->lower
.data
=
3033 cpu_to_le32(txd_lower
| buffer_info
->length
);
3034 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
3035 if (unlikely(++i
== tx_ring
->count
))
3039 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
3041 /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
3042 if (unlikely(tx_flags
& E1000_TX_FLAGS_NO_FCS
))
3043 tx_desc
->lower
.data
&= ~(cpu_to_le32(E1000_TXD_CMD_IFCS
));
3045 /* Force memory writes to complete before letting h/w
3046 * know there are new descriptors to fetch. (Only
3047 * applicable for weak-ordered memory model archs,
3052 tx_ring
->next_to_use
= i
;
3055 /* 82547 workaround to avoid controller hang in half-duplex environment.
3056 * The workaround is to avoid queuing a large packet that would span
3057 * the internal Tx FIFO ring boundary by notifying the stack to resend
3058 * the packet at a later time. This gives the Tx FIFO an opportunity to
3059 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3060 * to the beginning of the Tx FIFO.
3063 #define E1000_FIFO_HDR 0x10
3064 #define E1000_82547_PAD_LEN 0x3E0
3066 static int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
3067 struct sk_buff
*skb
)
3069 u32 fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
3070 u32 skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
3072 skb_fifo_len
= ALIGN(skb_fifo_len
, E1000_FIFO_HDR
);
3074 if (adapter
->link_duplex
!= HALF_DUPLEX
)
3075 goto no_fifo_stall_required
;
3077 if (atomic_read(&adapter
->tx_fifo_stall
))
3080 if (skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
3081 atomic_set(&adapter
->tx_fifo_stall
, 1);
3085 no_fifo_stall_required
:
3086 adapter
->tx_fifo_head
+= skb_fifo_len
;
3087 if (adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
3088 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
3092 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
3094 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3095 struct e1000_tx_ring
*tx_ring
= adapter
->tx_ring
;
3097 netif_stop_queue(netdev
);
3098 /* Herbert's original patch had:
3099 * smp_mb__after_netif_stop_queue();
3100 * but since that doesn't exist yet, just open code it.
3104 /* We need to check again in a case another CPU has just
3105 * made room available.
3107 if (likely(E1000_DESC_UNUSED(tx_ring
) < size
))
3111 netif_start_queue(netdev
);
3112 ++adapter
->restart_queue
;
3116 static int e1000_maybe_stop_tx(struct net_device
*netdev
,
3117 struct e1000_tx_ring
*tx_ring
, int size
)
3119 if (likely(E1000_DESC_UNUSED(tx_ring
) >= size
))
3121 return __e1000_maybe_stop_tx(netdev
, size
);
3124 #define TXD_USE_COUNT(S, X) (((S) + ((1 << (X)) - 1)) >> (X))
3125 static netdev_tx_t
e1000_xmit_frame(struct sk_buff
*skb
,
3126 struct net_device
*netdev
)
3128 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3129 struct e1000_hw
*hw
= &adapter
->hw
;
3130 struct e1000_tx_ring
*tx_ring
;
3131 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
3132 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
3133 unsigned int tx_flags
= 0;
3134 unsigned int len
= skb_headlen(skb
);
3135 unsigned int nr_frags
;
3140 __be16 protocol
= vlan_get_protocol(skb
);
3142 /* This goes back to the question of how to logically map a Tx queue
3143 * to a flow. Right now, performance is impacted slightly negatively
3144 * if using multiple Tx queues. If the stack breaks away from a
3145 * single qdisc implementation, we can look at this again.
3147 tx_ring
= adapter
->tx_ring
;
3149 /* On PCI/PCI-X HW, if packet size is less than ETH_ZLEN,
3150 * packets may get corrupted during padding by HW.
3151 * To WA this issue, pad all small packets manually.
3153 if (eth_skb_pad(skb
))
3154 return NETDEV_TX_OK
;
3156 mss
= skb_shinfo(skb
)->gso_size
;
3157 /* The controller does a simple calculation to
3158 * make sure there is enough room in the FIFO before
3159 * initiating the DMA for each buffer. The calc is:
3160 * 4 = ceil(buffer len/mss). To make sure we don't
3161 * overrun the FIFO, adjust the max buffer len if mss
3166 max_per_txd
= min(mss
<< 2, max_per_txd
);
3167 max_txd_pwr
= fls(max_per_txd
) - 1;
3169 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
3170 if (skb
->data_len
&& hdr_len
== len
) {
3171 switch (hw
->mac_type
) {
3172 unsigned int pull_size
;
3174 /* Make sure we have room to chop off 4 bytes,
3175 * and that the end alignment will work out to
3176 * this hardware's requirements
3177 * NOTE: this is a TSO only workaround
3178 * if end byte alignment not correct move us
3179 * into the next dword
3181 if ((unsigned long)(skb_tail_pointer(skb
) - 1)
3185 pull_size
= min((unsigned int)4, skb
->data_len
);
3186 if (!__pskb_pull_tail(skb
, pull_size
)) {
3187 e_err(drv
, "__pskb_pull_tail "
3189 dev_kfree_skb_any(skb
);
3190 return NETDEV_TX_OK
;
3192 len
= skb_headlen(skb
);
3201 /* reserve a descriptor for the offload context */
3202 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3206 /* Controller Erratum workaround */
3207 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&& !skb_is_gso(skb
))
3210 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
3212 if (adapter
->pcix_82544
)
3215 /* work-around for errata 10 and it applies to all controllers
3216 * in PCI-X mode, so add one more descriptor to the count
3218 if (unlikely((hw
->bus_type
== e1000_bus_type_pcix
) &&
3222 nr_frags
= skb_shinfo(skb
)->nr_frags
;
3223 for (f
= 0; f
< nr_frags
; f
++)
3224 count
+= TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb
)->frags
[f
]),
3226 if (adapter
->pcix_82544
)
3229 /* need: count + 2 desc gap to keep tail from touching
3230 * head, otherwise try next time
3232 if (unlikely(e1000_maybe_stop_tx(netdev
, tx_ring
, count
+ 2)))
3233 return NETDEV_TX_BUSY
;
3235 if (unlikely((hw
->mac_type
== e1000_82547
) &&
3236 (e1000_82547_fifo_workaround(adapter
, skb
)))) {
3237 netif_stop_queue(netdev
);
3238 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3239 schedule_delayed_work(&adapter
->fifo_stall_task
, 1);
3240 return NETDEV_TX_BUSY
;
3243 if (skb_vlan_tag_present(skb
)) {
3244 tx_flags
|= E1000_TX_FLAGS_VLAN
;
3245 tx_flags
|= (skb_vlan_tag_get(skb
) <<
3246 E1000_TX_FLAGS_VLAN_SHIFT
);
3249 first
= tx_ring
->next_to_use
;
3251 tso
= e1000_tso(adapter
, tx_ring
, skb
, protocol
);
3253 dev_kfree_skb_any(skb
);
3254 return NETDEV_TX_OK
;
3258 if (likely(hw
->mac_type
!= e1000_82544
))
3259 tx_ring
->last_tx_tso
= true;
3260 tx_flags
|= E1000_TX_FLAGS_TSO
;
3261 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
, protocol
)))
3262 tx_flags
|= E1000_TX_FLAGS_CSUM
;
3264 if (protocol
== htons(ETH_P_IP
))
3265 tx_flags
|= E1000_TX_FLAGS_IPV4
;
3267 if (unlikely(skb
->no_fcs
))
3268 tx_flags
|= E1000_TX_FLAGS_NO_FCS
;
3270 count
= e1000_tx_map(adapter
, tx_ring
, skb
, first
, max_per_txd
,
3274 /* The descriptors needed is higher than other Intel drivers
3275 * due to a number of workarounds. The breakdown is below:
3276 * Data descriptors: MAX_SKB_FRAGS + 1
3277 * Context Descriptor: 1
3278 * Keep head from touching tail: 2
3281 int desc_needed
= MAX_SKB_FRAGS
+ 7;
3283 netdev_sent_queue(netdev
, skb
->len
);
3284 skb_tx_timestamp(skb
);
3286 e1000_tx_queue(adapter
, tx_ring
, tx_flags
, count
);
3288 /* 82544 potentially requires twice as many data descriptors
3289 * in order to guarantee buffers don't end on evenly-aligned
3292 if (adapter
->pcix_82544
)
3293 desc_needed
+= MAX_SKB_FRAGS
+ 1;
3295 /* Make sure there is space in the ring for the next send. */
3296 e1000_maybe_stop_tx(netdev
, tx_ring
, desc_needed
);
3298 if (!skb
->xmit_more
||
3299 netif_xmit_stopped(netdev_get_tx_queue(netdev
, 0))) {
3300 writel(tx_ring
->next_to_use
, hw
->hw_addr
+ tx_ring
->tdt
);
3301 /* we need this if more than one processor can write to
3302 * our tail at a time, it synchronizes IO on IA64/Altix
3308 dev_kfree_skb_any(skb
);
3309 tx_ring
->buffer_info
[first
].time_stamp
= 0;
3310 tx_ring
->next_to_use
= first
;
3313 return NETDEV_TX_OK
;
3316 #define NUM_REGS 38 /* 1 based count */
3317 static void e1000_regdump(struct e1000_adapter
*adapter
)
3319 struct e1000_hw
*hw
= &adapter
->hw
;
3321 u32
*regs_buff
= regs
;
3324 static const char * const reg_name
[] = {
3326 "RCTL", "RDLEN", "RDH", "RDT", "RDTR",
3327 "TCTL", "TDBAL", "TDBAH", "TDLEN", "TDH", "TDT",
3328 "TIDV", "TXDCTL", "TADV", "TARC0",
3329 "TDBAL1", "TDBAH1", "TDLEN1", "TDH1", "TDT1",
3331 "CTRL_EXT", "ERT", "RDBAL", "RDBAH",
3332 "TDFH", "TDFT", "TDFHS", "TDFTS", "TDFPC",
3333 "RDFH", "RDFT", "RDFHS", "RDFTS", "RDFPC"
3336 regs_buff
[0] = er32(CTRL
);
3337 regs_buff
[1] = er32(STATUS
);
3339 regs_buff
[2] = er32(RCTL
);
3340 regs_buff
[3] = er32(RDLEN
);
3341 regs_buff
[4] = er32(RDH
);
3342 regs_buff
[5] = er32(RDT
);
3343 regs_buff
[6] = er32(RDTR
);
3345 regs_buff
[7] = er32(TCTL
);
3346 regs_buff
[8] = er32(TDBAL
);
3347 regs_buff
[9] = er32(TDBAH
);
3348 regs_buff
[10] = er32(TDLEN
);
3349 regs_buff
[11] = er32(TDH
);
3350 regs_buff
[12] = er32(TDT
);
3351 regs_buff
[13] = er32(TIDV
);
3352 regs_buff
[14] = er32(TXDCTL
);
3353 regs_buff
[15] = er32(TADV
);
3354 regs_buff
[16] = er32(TARC0
);
3356 regs_buff
[17] = er32(TDBAL1
);
3357 regs_buff
[18] = er32(TDBAH1
);
3358 regs_buff
[19] = er32(TDLEN1
);
3359 regs_buff
[20] = er32(TDH1
);
3360 regs_buff
[21] = er32(TDT1
);
3361 regs_buff
[22] = er32(TXDCTL1
);
3362 regs_buff
[23] = er32(TARC1
);
3363 regs_buff
[24] = er32(CTRL_EXT
);
3364 regs_buff
[25] = er32(ERT
);
3365 regs_buff
[26] = er32(RDBAL0
);
3366 regs_buff
[27] = er32(RDBAH0
);
3367 regs_buff
[28] = er32(TDFH
);
3368 regs_buff
[29] = er32(TDFT
);
3369 regs_buff
[30] = er32(TDFHS
);
3370 regs_buff
[31] = er32(TDFTS
);
3371 regs_buff
[32] = er32(TDFPC
);
3372 regs_buff
[33] = er32(RDFH
);
3373 regs_buff
[34] = er32(RDFT
);
3374 regs_buff
[35] = er32(RDFHS
);
3375 regs_buff
[36] = er32(RDFTS
);
3376 regs_buff
[37] = er32(RDFPC
);
3378 pr_info("Register dump\n");
3379 for (i
= 0; i
< NUM_REGS
; i
++)
3380 pr_info("%-15s %08x\n", reg_name
[i
], regs_buff
[i
]);
3384 * e1000_dump: Print registers, tx ring and rx ring
3386 static void e1000_dump(struct e1000_adapter
*adapter
)
3388 /* this code doesn't handle multiple rings */
3389 struct e1000_tx_ring
*tx_ring
= adapter
->tx_ring
;
3390 struct e1000_rx_ring
*rx_ring
= adapter
->rx_ring
;
3393 if (!netif_msg_hw(adapter
))
3396 /* Print Registers */
3397 e1000_regdump(adapter
);
3400 pr_info("TX Desc ring0 dump\n");
3402 /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
3404 * Legacy Transmit Descriptor
3405 * +--------------------------------------------------------------+
3406 * 0 | Buffer Address [63:0] (Reserved on Write Back) |
3407 * +--------------------------------------------------------------+
3408 * 8 | Special | CSS | Status | CMD | CSO | Length |
3409 * +--------------------------------------------------------------+
3410 * 63 48 47 36 35 32 31 24 23 16 15 0
3412 * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
3413 * 63 48 47 40 39 32 31 16 15 8 7 0
3414 * +----------------------------------------------------------------+
3415 * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
3416 * +----------------------------------------------------------------+
3417 * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
3418 * +----------------------------------------------------------------+
3419 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
3421 * Extended Data Descriptor (DTYP=0x1)
3422 * +----------------------------------------------------------------+
3423 * 0 | Buffer Address [63:0] |
3424 * +----------------------------------------------------------------+
3425 * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
3426 * +----------------------------------------------------------------+
3427 * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
3429 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestmp bi->skb\n");
3430 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestmp bi->skb\n");
3432 if (!netif_msg_tx_done(adapter
))
3433 goto rx_ring_summary
;
3435 for (i
= 0; tx_ring
->desc
&& (i
< tx_ring
->count
); i
++) {
3436 struct e1000_tx_desc
*tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3437 struct e1000_tx_buffer
*buffer_info
= &tx_ring
->buffer_info
[i
];
3438 struct my_u
{ __le64 a
; __le64 b
; };
3439 struct my_u
*u
= (struct my_u
*)tx_desc
;
3442 if (i
== tx_ring
->next_to_use
&& i
== tx_ring
->next_to_clean
)
3444 else if (i
== tx_ring
->next_to_use
)
3446 else if (i
== tx_ring
->next_to_clean
)
3451 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p %s\n",
3452 ((le64_to_cpu(u
->b
) & (1<<20)) ? 'd' : 'c'), i
,
3453 le64_to_cpu(u
->a
), le64_to_cpu(u
->b
),
3454 (u64
)buffer_info
->dma
, buffer_info
->length
,
3455 buffer_info
->next_to_watch
,
3456 (u64
)buffer_info
->time_stamp
, buffer_info
->skb
, type
);
3461 pr_info("\nRX Desc ring dump\n");
3463 /* Legacy Receive Descriptor Format
3465 * +-----------------------------------------------------+
3466 * | Buffer Address [63:0] |
3467 * +-----------------------------------------------------+
3468 * | VLAN Tag | Errors | Status 0 | Packet csum | Length |
3469 * +-----------------------------------------------------+
3470 * 63 48 47 40 39 32 31 16 15 0
3472 pr_info("R[desc] [address 63:0 ] [vl er S cks ln] [bi->dma ] [bi->skb]\n");
3474 if (!netif_msg_rx_status(adapter
))
3477 for (i
= 0; rx_ring
->desc
&& (i
< rx_ring
->count
); i
++) {
3478 struct e1000_rx_desc
*rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3479 struct e1000_rx_buffer
*buffer_info
= &rx_ring
->buffer_info
[i
];
3480 struct my_u
{ __le64 a
; __le64 b
; };
3481 struct my_u
*u
= (struct my_u
*)rx_desc
;
3484 if (i
== rx_ring
->next_to_use
)
3486 else if (i
== rx_ring
->next_to_clean
)
3491 pr_info("R[0x%03X] %016llX %016llX %016llX %p %s\n",
3492 i
, le64_to_cpu(u
->a
), le64_to_cpu(u
->b
),
3493 (u64
)buffer_info
->dma
, buffer_info
->rxbuf
.data
, type
);
3496 /* dump the descriptor caches */
3498 pr_info("Rx descriptor cache in 64bit format\n");
3499 for (i
= 0x6000; i
<= 0x63FF ; i
+= 0x10) {
3500 pr_info("R%04X: %08X|%08X %08X|%08X\n",
3502 readl(adapter
->hw
.hw_addr
+ i
+4),
3503 readl(adapter
->hw
.hw_addr
+ i
),
3504 readl(adapter
->hw
.hw_addr
+ i
+12),
3505 readl(adapter
->hw
.hw_addr
+ i
+8));
3508 pr_info("Tx descriptor cache in 64bit format\n");
3509 for (i
= 0x7000; i
<= 0x73FF ; i
+= 0x10) {
3510 pr_info("T%04X: %08X|%08X %08X|%08X\n",
3512 readl(adapter
->hw
.hw_addr
+ i
+4),
3513 readl(adapter
->hw
.hw_addr
+ i
),
3514 readl(adapter
->hw
.hw_addr
+ i
+12),
3515 readl(adapter
->hw
.hw_addr
+ i
+8));
3522 * e1000_tx_timeout - Respond to a Tx Hang
3523 * @netdev: network interface device structure
3525 static void e1000_tx_timeout(struct net_device
*netdev
)
3527 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3529 /* Do the reset outside of interrupt context */
3530 adapter
->tx_timeout_count
++;
3531 schedule_work(&adapter
->reset_task
);
3534 static void e1000_reset_task(struct work_struct
*work
)
3536 struct e1000_adapter
*adapter
=
3537 container_of(work
, struct e1000_adapter
, reset_task
);
3539 e_err(drv
, "Reset adapter\n");
3540 e1000_reinit_locked(adapter
);
3544 * e1000_change_mtu - Change the Maximum Transfer Unit
3545 * @netdev: network interface device structure
3546 * @new_mtu: new value for maximum frame size
3548 * Returns 0 on success, negative on failure
3550 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3552 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3553 struct e1000_hw
*hw
= &adapter
->hw
;
3554 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3556 /* Adapter-specific max frame size limits. */
3557 switch (hw
->mac_type
) {
3558 case e1000_undefined
... e1000_82542_rev2_1
:
3559 if (max_frame
> (ETH_FRAME_LEN
+ ETH_FCS_LEN
)) {
3560 e_err(probe
, "Jumbo Frames not supported.\n");
3565 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3569 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->flags
))
3571 /* e1000_down has a dependency on max_frame_size */
3572 hw
->max_frame_size
= max_frame
;
3573 if (netif_running(netdev
)) {
3574 /* prevent buffers from being reallocated */
3575 adapter
->alloc_rx_buf
= e1000_alloc_dummy_rx_buffers
;
3576 e1000_down(adapter
);
3579 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3580 * means we reserve 2 more, this pushes us to allocate from the next
3582 * i.e. RXBUFFER_2048 --> size-4096 slab
3583 * however with the new *_jumbo_rx* routines, jumbo receives will use
3587 if (max_frame
<= E1000_RXBUFFER_2048
)
3588 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3590 #if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3591 adapter
->rx_buffer_len
= E1000_RXBUFFER_16384
;
3592 #elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3593 adapter
->rx_buffer_len
= PAGE_SIZE
;
3596 /* adjust allocation if LPE protects us, and we aren't using SBP */
3597 if (!hw
->tbi_compatibility_on
&&
3598 ((max_frame
== (ETH_FRAME_LEN
+ ETH_FCS_LEN
)) ||
3599 (max_frame
== MAXIMUM_ETHERNET_VLAN_SIZE
)))
3600 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3602 pr_info("%s changing MTU from %d to %d\n",
3603 netdev
->name
, netdev
->mtu
, new_mtu
);
3604 netdev
->mtu
= new_mtu
;
3606 if (netif_running(netdev
))
3609 e1000_reset(adapter
);
3611 clear_bit(__E1000_RESETTING
, &adapter
->flags
);
3617 * e1000_update_stats - Update the board statistics counters
3618 * @adapter: board private structure
3620 void e1000_update_stats(struct e1000_adapter
*adapter
)
3622 struct net_device
*netdev
= adapter
->netdev
;
3623 struct e1000_hw
*hw
= &adapter
->hw
;
3624 struct pci_dev
*pdev
= adapter
->pdev
;
3625 unsigned long flags
;
3628 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3630 /* Prevent stats update while adapter is being reset, or if the pci
3631 * connection is down.
3633 if (adapter
->link_speed
== 0)
3635 if (pci_channel_offline(pdev
))
3638 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3640 /* these counters are modified from e1000_tbi_adjust_stats,
3641 * called from the interrupt context, so they must only
3642 * be written while holding adapter->stats_lock
3645 adapter
->stats
.crcerrs
+= er32(CRCERRS
);
3646 adapter
->stats
.gprc
+= er32(GPRC
);
3647 adapter
->stats
.gorcl
+= er32(GORCL
);
3648 adapter
->stats
.gorch
+= er32(GORCH
);
3649 adapter
->stats
.bprc
+= er32(BPRC
);
3650 adapter
->stats
.mprc
+= er32(MPRC
);
3651 adapter
->stats
.roc
+= er32(ROC
);
3653 adapter
->stats
.prc64
+= er32(PRC64
);
3654 adapter
->stats
.prc127
+= er32(PRC127
);
3655 adapter
->stats
.prc255
+= er32(PRC255
);
3656 adapter
->stats
.prc511
+= er32(PRC511
);
3657 adapter
->stats
.prc1023
+= er32(PRC1023
);
3658 adapter
->stats
.prc1522
+= er32(PRC1522
);
3660 adapter
->stats
.symerrs
+= er32(SYMERRS
);
3661 adapter
->stats
.mpc
+= er32(MPC
);
3662 adapter
->stats
.scc
+= er32(SCC
);
3663 adapter
->stats
.ecol
+= er32(ECOL
);
3664 adapter
->stats
.mcc
+= er32(MCC
);
3665 adapter
->stats
.latecol
+= er32(LATECOL
);
3666 adapter
->stats
.dc
+= er32(DC
);
3667 adapter
->stats
.sec
+= er32(SEC
);
3668 adapter
->stats
.rlec
+= er32(RLEC
);
3669 adapter
->stats
.xonrxc
+= er32(XONRXC
);
3670 adapter
->stats
.xontxc
+= er32(XONTXC
);
3671 adapter
->stats
.xoffrxc
+= er32(XOFFRXC
);
3672 adapter
->stats
.xofftxc
+= er32(XOFFTXC
);
3673 adapter
->stats
.fcruc
+= er32(FCRUC
);
3674 adapter
->stats
.gptc
+= er32(GPTC
);
3675 adapter
->stats
.gotcl
+= er32(GOTCL
);
3676 adapter
->stats
.gotch
+= er32(GOTCH
);
3677 adapter
->stats
.rnbc
+= er32(RNBC
);
3678 adapter
->stats
.ruc
+= er32(RUC
);
3679 adapter
->stats
.rfc
+= er32(RFC
);
3680 adapter
->stats
.rjc
+= er32(RJC
);
3681 adapter
->stats
.torl
+= er32(TORL
);
3682 adapter
->stats
.torh
+= er32(TORH
);
3683 adapter
->stats
.totl
+= er32(TOTL
);
3684 adapter
->stats
.toth
+= er32(TOTH
);
3685 adapter
->stats
.tpr
+= er32(TPR
);
3687 adapter
->stats
.ptc64
+= er32(PTC64
);
3688 adapter
->stats
.ptc127
+= er32(PTC127
);
3689 adapter
->stats
.ptc255
+= er32(PTC255
);
3690 adapter
->stats
.ptc511
+= er32(PTC511
);
3691 adapter
->stats
.ptc1023
+= er32(PTC1023
);
3692 adapter
->stats
.ptc1522
+= er32(PTC1522
);
3694 adapter
->stats
.mptc
+= er32(MPTC
);
3695 adapter
->stats
.bptc
+= er32(BPTC
);
3697 /* used for adaptive IFS */
3699 hw
->tx_packet_delta
= er32(TPT
);
3700 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3701 hw
->collision_delta
= er32(COLC
);
3702 adapter
->stats
.colc
+= hw
->collision_delta
;
3704 if (hw
->mac_type
>= e1000_82543
) {
3705 adapter
->stats
.algnerrc
+= er32(ALGNERRC
);
3706 adapter
->stats
.rxerrc
+= er32(RXERRC
);
3707 adapter
->stats
.tncrs
+= er32(TNCRS
);
3708 adapter
->stats
.cexterr
+= er32(CEXTERR
);
3709 adapter
->stats
.tsctc
+= er32(TSCTC
);
3710 adapter
->stats
.tsctfc
+= er32(TSCTFC
);
3713 /* Fill out the OS statistics structure */
3714 netdev
->stats
.multicast
= adapter
->stats
.mprc
;
3715 netdev
->stats
.collisions
= adapter
->stats
.colc
;
3719 /* RLEC on some newer hardware can be incorrect so build
3720 * our own version based on RUC and ROC
3722 netdev
->stats
.rx_errors
= adapter
->stats
.rxerrc
+
3723 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3724 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3725 adapter
->stats
.cexterr
;
3726 adapter
->stats
.rlerrc
= adapter
->stats
.ruc
+ adapter
->stats
.roc
;
3727 netdev
->stats
.rx_length_errors
= adapter
->stats
.rlerrc
;
3728 netdev
->stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3729 netdev
->stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3730 netdev
->stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3733 adapter
->stats
.txerrc
= adapter
->stats
.ecol
+ adapter
->stats
.latecol
;
3734 netdev
->stats
.tx_errors
= adapter
->stats
.txerrc
;
3735 netdev
->stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3736 netdev
->stats
.tx_window_errors
= adapter
->stats
.latecol
;
3737 netdev
->stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3738 if (hw
->bad_tx_carr_stats_fd
&&
3739 adapter
->link_duplex
== FULL_DUPLEX
) {
3740 netdev
->stats
.tx_carrier_errors
= 0;
3741 adapter
->stats
.tncrs
= 0;
3744 /* Tx Dropped needs to be maintained elsewhere */
3747 if (hw
->media_type
== e1000_media_type_copper
) {
3748 if ((adapter
->link_speed
== SPEED_1000
) &&
3749 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3750 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3751 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3754 if ((hw
->mac_type
<= e1000_82546
) &&
3755 (hw
->phy_type
== e1000_phy_m88
) &&
3756 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3757 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3760 /* Management Stats */
3761 if (hw
->has_smbus
) {
3762 adapter
->stats
.mgptc
+= er32(MGTPTC
);
3763 adapter
->stats
.mgprc
+= er32(MGTPRC
);
3764 adapter
->stats
.mgpdc
+= er32(MGTPDC
);
3767 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3771 * e1000_intr - Interrupt Handler
3772 * @irq: interrupt number
3773 * @data: pointer to a network interface device structure
3775 static irqreturn_t
e1000_intr(int irq
, void *data
)
3777 struct net_device
*netdev
= data
;
3778 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3779 struct e1000_hw
*hw
= &adapter
->hw
;
3780 u32 icr
= er32(ICR
);
3782 if (unlikely((!icr
)))
3783 return IRQ_NONE
; /* Not our interrupt */
3785 /* we might have caused the interrupt, but the above
3786 * read cleared it, and just in case the driver is
3787 * down there is nothing to do so return handled
3789 if (unlikely(test_bit(__E1000_DOWN
, &adapter
->flags
)))
3792 if (unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3793 hw
->get_link_status
= 1;
3794 /* guard against interrupt when we're going down */
3795 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3796 schedule_delayed_work(&adapter
->watchdog_task
, 1);
3799 /* disable interrupts, without the synchronize_irq bit */
3801 E1000_WRITE_FLUSH();
3803 if (likely(napi_schedule_prep(&adapter
->napi
))) {
3804 adapter
->total_tx_bytes
= 0;
3805 adapter
->total_tx_packets
= 0;
3806 adapter
->total_rx_bytes
= 0;
3807 adapter
->total_rx_packets
= 0;
3808 __napi_schedule(&adapter
->napi
);
3810 /* this really should not happen! if it does it is basically a
3811 * bug, but not a hard error, so enable ints and continue
3813 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3814 e1000_irq_enable(adapter
);
3821 * e1000_clean - NAPI Rx polling callback
3822 * @adapter: board private structure
3824 static int e1000_clean(struct napi_struct
*napi
, int budget
)
3826 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
,
3828 int tx_clean_complete
= 0, work_done
= 0;
3830 tx_clean_complete
= e1000_clean_tx_irq(adapter
, &adapter
->tx_ring
[0]);
3832 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[0], &work_done
, budget
);
3834 if (!tx_clean_complete
)
3837 /* If budget not fully consumed, exit the polling mode */
3838 if (work_done
< budget
) {
3839 if (likely(adapter
->itr_setting
& 3))
3840 e1000_set_itr(adapter
);
3841 napi_complete_done(napi
, work_done
);
3842 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3843 e1000_irq_enable(adapter
);
3850 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3851 * @adapter: board private structure
3853 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
3854 struct e1000_tx_ring
*tx_ring
)
3856 struct e1000_hw
*hw
= &adapter
->hw
;
3857 struct net_device
*netdev
= adapter
->netdev
;
3858 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
3859 struct e1000_tx_buffer
*buffer_info
;
3860 unsigned int i
, eop
;
3861 unsigned int count
= 0;
3862 unsigned int total_tx_bytes
= 0, total_tx_packets
= 0;
3863 unsigned int bytes_compl
= 0, pkts_compl
= 0;
3865 i
= tx_ring
->next_to_clean
;
3866 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3867 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3869 while ((eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) &&
3870 (count
< tx_ring
->count
)) {
3871 bool cleaned
= false;
3872 dma_rmb(); /* read buffer_info after eop_desc */
3873 for ( ; !cleaned
; count
++) {
3874 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3875 buffer_info
= &tx_ring
->buffer_info
[i
];
3876 cleaned
= (i
== eop
);
3879 total_tx_packets
+= buffer_info
->segs
;
3880 total_tx_bytes
+= buffer_info
->bytecount
;
3881 if (buffer_info
->skb
) {
3882 bytes_compl
+= buffer_info
->skb
->len
;
3887 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
3888 tx_desc
->upper
.data
= 0;
3890 if (unlikely(++i
== tx_ring
->count
))
3894 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3895 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3898 /* Synchronize with E1000_DESC_UNUSED called from e1000_xmit_frame,
3899 * which will reuse the cleaned buffers.
3901 smp_store_release(&tx_ring
->next_to_clean
, i
);
3903 netdev_completed_queue(netdev
, pkts_compl
, bytes_compl
);
3905 #define TX_WAKE_THRESHOLD 32
3906 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
3907 E1000_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
)) {
3908 /* Make sure that anybody stopping the queue after this
3909 * sees the new next_to_clean.
3913 if (netif_queue_stopped(netdev
) &&
3914 !(test_bit(__E1000_DOWN
, &adapter
->flags
))) {
3915 netif_wake_queue(netdev
);
3916 ++adapter
->restart_queue
;
3920 if (adapter
->detect_tx_hung
) {
3921 /* Detect a transmit hang in hardware, this serializes the
3922 * check with the clearing of time_stamp and movement of i
3924 adapter
->detect_tx_hung
= false;
3925 if (tx_ring
->buffer_info
[eop
].time_stamp
&&
3926 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
+
3927 (adapter
->tx_timeout_factor
* HZ
)) &&
3928 !(er32(STATUS
) & E1000_STATUS_TXOFF
)) {
3930 /* detected Tx unit hang */
3931 e_err(drv
, "Detected Tx Unit Hang\n"
3935 " next_to_use <%x>\n"
3936 " next_to_clean <%x>\n"
3937 "buffer_info[next_to_clean]\n"
3938 " time_stamp <%lx>\n"
3939 " next_to_watch <%x>\n"
3941 " next_to_watch.status <%x>\n",
3942 (unsigned long)(tx_ring
- adapter
->tx_ring
),
3943 readl(hw
->hw_addr
+ tx_ring
->tdh
),
3944 readl(hw
->hw_addr
+ tx_ring
->tdt
),
3945 tx_ring
->next_to_use
,
3946 tx_ring
->next_to_clean
,
3947 tx_ring
->buffer_info
[eop
].time_stamp
,
3950 eop_desc
->upper
.fields
.status
);
3951 e1000_dump(adapter
);
3952 netif_stop_queue(netdev
);
3955 adapter
->total_tx_bytes
+= total_tx_bytes
;
3956 adapter
->total_tx_packets
+= total_tx_packets
;
3957 netdev
->stats
.tx_bytes
+= total_tx_bytes
;
3958 netdev
->stats
.tx_packets
+= total_tx_packets
;
3959 return count
< tx_ring
->count
;
3963 * e1000_rx_checksum - Receive Checksum Offload for 82543
3964 * @adapter: board private structure
3965 * @status_err: receive descriptor status and error fields
3966 * @csum: receive descriptor csum field
3967 * @sk_buff: socket buffer with received data
3969 static void e1000_rx_checksum(struct e1000_adapter
*adapter
, u32 status_err
,
3970 u32 csum
, struct sk_buff
*skb
)
3972 struct e1000_hw
*hw
= &adapter
->hw
;
3973 u16 status
= (u16
)status_err
;
3974 u8 errors
= (u8
)(status_err
>> 24);
3976 skb_checksum_none_assert(skb
);
3978 /* 82543 or newer only */
3979 if (unlikely(hw
->mac_type
< e1000_82543
))
3981 /* Ignore Checksum bit is set */
3982 if (unlikely(status
& E1000_RXD_STAT_IXSM
))
3984 /* TCP/UDP checksum error bit is set */
3985 if (unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
3986 /* let the stack verify checksum errors */
3987 adapter
->hw_csum_err
++;
3990 /* TCP/UDP Checksum has not been calculated */
3991 if (!(status
& E1000_RXD_STAT_TCPCS
))
3994 /* It must be a TCP or UDP packet with a valid checksum */
3995 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
3996 /* TCP checksum is good */
3997 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3999 adapter
->hw_csum_good
++;
4003 * e1000_consume_page - helper function for jumbo Rx path
4005 static void e1000_consume_page(struct e1000_rx_buffer
*bi
, struct sk_buff
*skb
,
4008 bi
->rxbuf
.page
= NULL
;
4010 skb
->data_len
+= length
;
4011 skb
->truesize
+= PAGE_SIZE
;
4015 * e1000_receive_skb - helper function to handle rx indications
4016 * @adapter: board private structure
4017 * @status: descriptor status field as written by hardware
4018 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
4019 * @skb: pointer to sk_buff to be indicated to stack
4021 static void e1000_receive_skb(struct e1000_adapter
*adapter
, u8 status
,
4022 __le16 vlan
, struct sk_buff
*skb
)
4024 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
4026 if (status
& E1000_RXD_STAT_VP
) {
4027 u16 vid
= le16_to_cpu(vlan
) & E1000_RXD_SPC_VLAN_MASK
;
4029 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), vid
);
4031 napi_gro_receive(&adapter
->napi
, skb
);
4035 * e1000_tbi_adjust_stats
4036 * @hw: Struct containing variables accessed by shared code
4037 * @frame_len: The length of the frame in question
4038 * @mac_addr: The Ethernet destination address of the frame in question
4040 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4042 static void e1000_tbi_adjust_stats(struct e1000_hw
*hw
,
4043 struct e1000_hw_stats
*stats
,
4044 u32 frame_len
, const u8
*mac_addr
)
4048 /* First adjust the frame length. */
4050 /* We need to adjust the statistics counters, since the hardware
4051 * counters overcount this packet as a CRC error and undercount
4052 * the packet as a good packet
4054 /* This packet should not be counted as a CRC error. */
4056 /* This packet does count as a Good Packet Received. */
4059 /* Adjust the Good Octets received counters */
4060 carry_bit
= 0x80000000 & stats
->gorcl
;
4061 stats
->gorcl
+= frame_len
;
4062 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4063 * Received Count) was one before the addition,
4064 * AND it is zero after, then we lost the carry out,
4065 * need to add one to Gorch (Good Octets Received Count High).
4066 * This could be simplified if all environments supported
4069 if (carry_bit
&& ((stats
->gorcl
& 0x80000000) == 0))
4071 /* Is this a broadcast or multicast? Check broadcast first,
4072 * since the test for a multicast frame will test positive on
4073 * a broadcast frame.
4075 if (is_broadcast_ether_addr(mac_addr
))
4077 else if (is_multicast_ether_addr(mac_addr
))
4080 if (frame_len
== hw
->max_frame_size
) {
4081 /* In this case, the hardware has overcounted the number of
4088 /* Adjust the bin counters when the extra byte put the frame in the
4089 * wrong bin. Remember that the frame_len was adjusted above.
4091 if (frame_len
== 64) {
4094 } else if (frame_len
== 127) {
4097 } else if (frame_len
== 255) {
4100 } else if (frame_len
== 511) {
4103 } else if (frame_len
== 1023) {
4106 } else if (frame_len
== 1522) {
4111 static bool e1000_tbi_should_accept(struct e1000_adapter
*adapter
,
4112 u8 status
, u8 errors
,
4113 u32 length
, const u8
*data
)
4115 struct e1000_hw
*hw
= &adapter
->hw
;
4116 u8 last_byte
= *(data
+ length
- 1);
4118 if (TBI_ACCEPT(hw
, status
, errors
, length
, last_byte
)) {
4119 unsigned long irq_flags
;
4121 spin_lock_irqsave(&adapter
->stats_lock
, irq_flags
);
4122 e1000_tbi_adjust_stats(hw
, &adapter
->stats
, length
, data
);
4123 spin_unlock_irqrestore(&adapter
->stats_lock
, irq_flags
);
4131 static struct sk_buff
*e1000_alloc_rx_skb(struct e1000_adapter
*adapter
,
4134 struct sk_buff
*skb
= napi_alloc_skb(&adapter
->napi
, bufsz
);
4137 adapter
->alloc_rx_buff_failed
++;
4142 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
4143 * @adapter: board private structure
4144 * @rx_ring: ring to clean
4145 * @work_done: amount of napi work completed this call
4146 * @work_to_do: max amount of work allowed for this call to do
4148 * the return value indicates whether actual cleaning was done, there
4149 * is no guarantee that everything was cleaned
4151 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter
*adapter
,
4152 struct e1000_rx_ring
*rx_ring
,
4153 int *work_done
, int work_to_do
)
4155 struct net_device
*netdev
= adapter
->netdev
;
4156 struct pci_dev
*pdev
= adapter
->pdev
;
4157 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
4158 struct e1000_rx_buffer
*buffer_info
, *next_buffer
;
4161 int cleaned_count
= 0;
4162 bool cleaned
= false;
4163 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
4165 i
= rx_ring
->next_to_clean
;
4166 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4167 buffer_info
= &rx_ring
->buffer_info
[i
];
4169 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
4170 struct sk_buff
*skb
;
4173 if (*work_done
>= work_to_do
)
4176 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
4178 status
= rx_desc
->status
;
4180 if (++i
== rx_ring
->count
)
4183 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
4186 next_buffer
= &rx_ring
->buffer_info
[i
];
4190 dma_unmap_page(&pdev
->dev
, buffer_info
->dma
,
4191 adapter
->rx_buffer_len
, DMA_FROM_DEVICE
);
4192 buffer_info
->dma
= 0;
4194 length
= le16_to_cpu(rx_desc
->length
);
4196 /* errors is only valid for DD + EOP descriptors */
4197 if (unlikely((status
& E1000_RXD_STAT_EOP
) &&
4198 (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
))) {
4199 u8
*mapped
= page_address(buffer_info
->rxbuf
.page
);
4201 if (e1000_tbi_should_accept(adapter
, status
,
4205 } else if (netdev
->features
& NETIF_F_RXALL
) {
4208 /* an error means any chain goes out the window
4211 if (rx_ring
->rx_skb_top
)
4212 dev_kfree_skb(rx_ring
->rx_skb_top
);
4213 rx_ring
->rx_skb_top
= NULL
;
4218 #define rxtop rx_ring->rx_skb_top
4220 if (!(status
& E1000_RXD_STAT_EOP
)) {
4221 /* this descriptor is only the beginning (or middle) */
4223 /* this is the beginning of a chain */
4224 rxtop
= napi_get_frags(&adapter
->napi
);
4228 skb_fill_page_desc(rxtop
, 0,
4229 buffer_info
->rxbuf
.page
,
4232 /* this is the middle of a chain */
4233 skb_fill_page_desc(rxtop
,
4234 skb_shinfo(rxtop
)->nr_frags
,
4235 buffer_info
->rxbuf
.page
, 0, length
);
4237 e1000_consume_page(buffer_info
, rxtop
, length
);
4241 /* end of the chain */
4242 skb_fill_page_desc(rxtop
,
4243 skb_shinfo(rxtop
)->nr_frags
,
4244 buffer_info
->rxbuf
.page
, 0, length
);
4247 e1000_consume_page(buffer_info
, skb
, length
);
4250 /* no chain, got EOP, this buf is the packet
4251 * copybreak to save the put_page/alloc_page
4253 p
= buffer_info
->rxbuf
.page
;
4254 if (length
<= copybreak
) {
4257 if (likely(!(netdev
->features
& NETIF_F_RXFCS
)))
4259 skb
= e1000_alloc_rx_skb(adapter
,
4264 vaddr
= kmap_atomic(p
);
4265 memcpy(skb_tail_pointer(skb
), vaddr
,
4267 kunmap_atomic(vaddr
);
4268 /* re-use the page, so don't erase
4269 * buffer_info->rxbuf.page
4271 skb_put(skb
, length
);
4272 e1000_rx_checksum(adapter
,
4273 status
| rx_desc
->errors
<< 24,
4274 le16_to_cpu(rx_desc
->csum
), skb
);
4276 total_rx_bytes
+= skb
->len
;
4279 e1000_receive_skb(adapter
, status
,
4280 rx_desc
->special
, skb
);
4283 skb
= napi_get_frags(&adapter
->napi
);
4285 adapter
->alloc_rx_buff_failed
++;
4288 skb_fill_page_desc(skb
, 0, p
, 0,
4290 e1000_consume_page(buffer_info
, skb
,
4296 /* Receive Checksum Offload XXX recompute due to CRC strip? */
4297 e1000_rx_checksum(adapter
,
4299 ((u32
)(rx_desc
->errors
) << 24),
4300 le16_to_cpu(rx_desc
->csum
), skb
);
4302 total_rx_bytes
+= (skb
->len
- 4); /* don't count FCS */
4303 if (likely(!(netdev
->features
& NETIF_F_RXFCS
)))
4304 pskb_trim(skb
, skb
->len
- 4);
4307 if (status
& E1000_RXD_STAT_VP
) {
4308 __le16 vlan
= rx_desc
->special
;
4309 u16 vid
= le16_to_cpu(vlan
) & E1000_RXD_SPC_VLAN_MASK
;
4311 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), vid
);
4314 napi_gro_frags(&adapter
->napi
);
4317 rx_desc
->status
= 0;
4319 /* return some buffers to hardware, one at a time is too slow */
4320 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
4321 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4325 /* use prefetched values */
4327 buffer_info
= next_buffer
;
4329 rx_ring
->next_to_clean
= i
;
4331 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
4333 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4335 adapter
->total_rx_packets
+= total_rx_packets
;
4336 adapter
->total_rx_bytes
+= total_rx_bytes
;
4337 netdev
->stats
.rx_bytes
+= total_rx_bytes
;
4338 netdev
->stats
.rx_packets
+= total_rx_packets
;
4342 /* this should improve performance for small packets with large amounts
4343 * of reassembly being done in the stack
4345 static struct sk_buff
*e1000_copybreak(struct e1000_adapter
*adapter
,
4346 struct e1000_rx_buffer
*buffer_info
,
4347 u32 length
, const void *data
)
4349 struct sk_buff
*skb
;
4351 if (length
> copybreak
)
4354 skb
= e1000_alloc_rx_skb(adapter
, length
);
4358 dma_sync_single_for_cpu(&adapter
->pdev
->dev
, buffer_info
->dma
,
4359 length
, DMA_FROM_DEVICE
);
4361 skb_put_data(skb
, data
, length
);
4367 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4368 * @adapter: board private structure
4369 * @rx_ring: ring to clean
4370 * @work_done: amount of napi work completed this call
4371 * @work_to_do: max amount of work allowed for this call to do
4373 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
4374 struct e1000_rx_ring
*rx_ring
,
4375 int *work_done
, int work_to_do
)
4377 struct net_device
*netdev
= adapter
->netdev
;
4378 struct pci_dev
*pdev
= adapter
->pdev
;
4379 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
4380 struct e1000_rx_buffer
*buffer_info
, *next_buffer
;
4383 int cleaned_count
= 0;
4384 bool cleaned
= false;
4385 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
4387 i
= rx_ring
->next_to_clean
;
4388 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4389 buffer_info
= &rx_ring
->buffer_info
[i
];
4391 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
4392 struct sk_buff
*skb
;
4396 if (*work_done
>= work_to_do
)
4399 dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
4401 status
= rx_desc
->status
;
4402 length
= le16_to_cpu(rx_desc
->length
);
4404 data
= buffer_info
->rxbuf
.data
;
4406 skb
= e1000_copybreak(adapter
, buffer_info
, length
, data
);
4408 unsigned int frag_len
= e1000_frag_len(adapter
);
4410 skb
= build_skb(data
- E1000_HEADROOM
, frag_len
);
4412 adapter
->alloc_rx_buff_failed
++;
4416 skb_reserve(skb
, E1000_HEADROOM
);
4417 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
4418 adapter
->rx_buffer_len
,
4420 buffer_info
->dma
= 0;
4421 buffer_info
->rxbuf
.data
= NULL
;
4424 if (++i
== rx_ring
->count
)
4427 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
4430 next_buffer
= &rx_ring
->buffer_info
[i
];
4435 /* !EOP means multiple descriptors were used to store a single
4436 * packet, if thats the case we need to toss it. In fact, we
4437 * to toss every packet with the EOP bit clear and the next
4438 * frame that _does_ have the EOP bit set, as it is by
4439 * definition only a frame fragment
4441 if (unlikely(!(status
& E1000_RXD_STAT_EOP
)))
4442 adapter
->discarding
= true;
4444 if (adapter
->discarding
) {
4445 /* All receives must fit into a single buffer */
4446 netdev_dbg(netdev
, "Receive packet consumed multiple buffers\n");
4448 if (status
& E1000_RXD_STAT_EOP
)
4449 adapter
->discarding
= false;
4453 if (unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
4454 if (e1000_tbi_should_accept(adapter
, status
,
4458 } else if (netdev
->features
& NETIF_F_RXALL
) {
4467 total_rx_bytes
+= (length
- 4); /* don't count FCS */
4470 if (likely(!(netdev
->features
& NETIF_F_RXFCS
)))
4471 /* adjust length to remove Ethernet CRC, this must be
4472 * done after the TBI_ACCEPT workaround above
4476 if (buffer_info
->rxbuf
.data
== NULL
)
4477 skb_put(skb
, length
);
4478 else /* copybreak skb */
4479 skb_trim(skb
, length
);
4481 /* Receive Checksum Offload */
4482 e1000_rx_checksum(adapter
,
4484 ((u32
)(rx_desc
->errors
) << 24),
4485 le16_to_cpu(rx_desc
->csum
), skb
);
4487 e1000_receive_skb(adapter
, status
, rx_desc
->special
, skb
);
4490 rx_desc
->status
= 0;
4492 /* return some buffers to hardware, one at a time is too slow */
4493 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
4494 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4498 /* use prefetched values */
4500 buffer_info
= next_buffer
;
4502 rx_ring
->next_to_clean
= i
;
4504 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
4506 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4508 adapter
->total_rx_packets
+= total_rx_packets
;
4509 adapter
->total_rx_bytes
+= total_rx_bytes
;
4510 netdev
->stats
.rx_bytes
+= total_rx_bytes
;
4511 netdev
->stats
.rx_packets
+= total_rx_packets
;
4516 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4517 * @adapter: address of board private structure
4518 * @rx_ring: pointer to receive ring structure
4519 * @cleaned_count: number of buffers to allocate this pass
4522 e1000_alloc_jumbo_rx_buffers(struct e1000_adapter
*adapter
,
4523 struct e1000_rx_ring
*rx_ring
, int cleaned_count
)
4525 struct pci_dev
*pdev
= adapter
->pdev
;
4526 struct e1000_rx_desc
*rx_desc
;
4527 struct e1000_rx_buffer
*buffer_info
;
4530 i
= rx_ring
->next_to_use
;
4531 buffer_info
= &rx_ring
->buffer_info
[i
];
4533 while (cleaned_count
--) {
4534 /* allocate a new page if necessary */
4535 if (!buffer_info
->rxbuf
.page
) {
4536 buffer_info
->rxbuf
.page
= alloc_page(GFP_ATOMIC
);
4537 if (unlikely(!buffer_info
->rxbuf
.page
)) {
4538 adapter
->alloc_rx_buff_failed
++;
4543 if (!buffer_info
->dma
) {
4544 buffer_info
->dma
= dma_map_page(&pdev
->dev
,
4545 buffer_info
->rxbuf
.page
, 0,
4546 adapter
->rx_buffer_len
,
4548 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
)) {
4549 put_page(buffer_info
->rxbuf
.page
);
4550 buffer_info
->rxbuf
.page
= NULL
;
4551 buffer_info
->dma
= 0;
4552 adapter
->alloc_rx_buff_failed
++;
4557 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4558 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4560 if (unlikely(++i
== rx_ring
->count
))
4562 buffer_info
= &rx_ring
->buffer_info
[i
];
4565 if (likely(rx_ring
->next_to_use
!= i
)) {
4566 rx_ring
->next_to_use
= i
;
4567 if (unlikely(i
-- == 0))
4568 i
= (rx_ring
->count
- 1);
4570 /* Force memory writes to complete before letting h/w
4571 * know there are new descriptors to fetch. (Only
4572 * applicable for weak-ordered memory model archs,
4576 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4581 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4582 * @adapter: address of board private structure
4584 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
4585 struct e1000_rx_ring
*rx_ring
,
4588 struct e1000_hw
*hw
= &adapter
->hw
;
4589 struct pci_dev
*pdev
= adapter
->pdev
;
4590 struct e1000_rx_desc
*rx_desc
;
4591 struct e1000_rx_buffer
*buffer_info
;
4593 unsigned int bufsz
= adapter
->rx_buffer_len
;
4595 i
= rx_ring
->next_to_use
;
4596 buffer_info
= &rx_ring
->buffer_info
[i
];
4598 while (cleaned_count
--) {
4601 if (buffer_info
->rxbuf
.data
)
4604 data
= e1000_alloc_frag(adapter
);
4606 /* Better luck next round */
4607 adapter
->alloc_rx_buff_failed
++;
4611 /* Fix for errata 23, can't cross 64kB boundary */
4612 if (!e1000_check_64k_bound(adapter
, data
, bufsz
)) {
4613 void *olddata
= data
;
4614 e_err(rx_err
, "skb align check failed: %u bytes at "
4615 "%p\n", bufsz
, data
);
4616 /* Try again, without freeing the previous */
4617 data
= e1000_alloc_frag(adapter
);
4618 /* Failed allocation, critical failure */
4620 skb_free_frag(olddata
);
4621 adapter
->alloc_rx_buff_failed
++;
4625 if (!e1000_check_64k_bound(adapter
, data
, bufsz
)) {
4627 skb_free_frag(data
);
4628 skb_free_frag(olddata
);
4629 adapter
->alloc_rx_buff_failed
++;
4633 /* Use new allocation */
4634 skb_free_frag(olddata
);
4636 buffer_info
->dma
= dma_map_single(&pdev
->dev
,
4638 adapter
->rx_buffer_len
,
4640 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
)) {
4641 skb_free_frag(data
);
4642 buffer_info
->dma
= 0;
4643 adapter
->alloc_rx_buff_failed
++;
4647 /* XXX if it was allocated cleanly it will never map to a
4651 /* Fix for errata 23, can't cross 64kB boundary */
4652 if (!e1000_check_64k_bound(adapter
,
4653 (void *)(unsigned long)buffer_info
->dma
,
4654 adapter
->rx_buffer_len
)) {
4655 e_err(rx_err
, "dma align check failed: %u bytes at "
4656 "%p\n", adapter
->rx_buffer_len
,
4657 (void *)(unsigned long)buffer_info
->dma
);
4659 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
4660 adapter
->rx_buffer_len
,
4663 skb_free_frag(data
);
4664 buffer_info
->rxbuf
.data
= NULL
;
4665 buffer_info
->dma
= 0;
4667 adapter
->alloc_rx_buff_failed
++;
4670 buffer_info
->rxbuf
.data
= data
;
4672 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4673 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4675 if (unlikely(++i
== rx_ring
->count
))
4677 buffer_info
= &rx_ring
->buffer_info
[i
];
4680 if (likely(rx_ring
->next_to_use
!= i
)) {
4681 rx_ring
->next_to_use
= i
;
4682 if (unlikely(i
-- == 0))
4683 i
= (rx_ring
->count
- 1);
4685 /* Force memory writes to complete before letting h/w
4686 * know there are new descriptors to fetch. (Only
4687 * applicable for weak-ordered memory model archs,
4691 writel(i
, hw
->hw_addr
+ rx_ring
->rdt
);
4696 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4699 static void e1000_smartspeed(struct e1000_adapter
*adapter
)
4701 struct e1000_hw
*hw
= &adapter
->hw
;
4705 if ((hw
->phy_type
!= e1000_phy_igp
) || !hw
->autoneg
||
4706 !(hw
->autoneg_advertised
& ADVERTISE_1000_FULL
))
4709 if (adapter
->smartspeed
== 0) {
4710 /* If Master/Slave config fault is asserted twice,
4711 * we assume back-to-back
4713 e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_status
);
4714 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
))
4716 e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_status
);
4717 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
))
4719 e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4720 if (phy_ctrl
& CR_1000T_MS_ENABLE
) {
4721 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
4722 e1000_write_phy_reg(hw
, PHY_1000T_CTRL
,
4724 adapter
->smartspeed
++;
4725 if (!e1000_phy_setup_autoneg(hw
) &&
4726 !e1000_read_phy_reg(hw
, PHY_CTRL
,
4728 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4729 MII_CR_RESTART_AUTO_NEG
);
4730 e1000_write_phy_reg(hw
, PHY_CTRL
,
4735 } else if (adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
4736 /* If still no link, perhaps using 2/3 pair cable */
4737 e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4738 phy_ctrl
|= CR_1000T_MS_ENABLE
;
4739 e1000_write_phy_reg(hw
, PHY_1000T_CTRL
, phy_ctrl
);
4740 if (!e1000_phy_setup_autoneg(hw
) &&
4741 !e1000_read_phy_reg(hw
, PHY_CTRL
, &phy_ctrl
)) {
4742 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4743 MII_CR_RESTART_AUTO_NEG
);
4744 e1000_write_phy_reg(hw
, PHY_CTRL
, phy_ctrl
);
4747 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4748 if (adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
4749 adapter
->smartspeed
= 0;
4758 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4764 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4776 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
4779 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4780 struct e1000_hw
*hw
= &adapter
->hw
;
4781 struct mii_ioctl_data
*data
= if_mii(ifr
);
4784 unsigned long flags
;
4786 if (hw
->media_type
!= e1000_media_type_copper
)
4791 data
->phy_id
= hw
->phy_addr
;
4794 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4795 if (e1000_read_phy_reg(hw
, data
->reg_num
& 0x1F,
4797 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4800 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4803 if (data
->reg_num
& ~(0x1F))
4805 mii_reg
= data
->val_in
;
4806 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4807 if (e1000_write_phy_reg(hw
, data
->reg_num
,
4809 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4812 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4813 if (hw
->media_type
== e1000_media_type_copper
) {
4814 switch (data
->reg_num
) {
4816 if (mii_reg
& MII_CR_POWER_DOWN
)
4818 if (mii_reg
& MII_CR_AUTO_NEG_EN
) {
4820 hw
->autoneg_advertised
= 0x2F;
4825 else if (mii_reg
& 0x2000)
4829 retval
= e1000_set_spd_dplx(
4837 if (netif_running(adapter
->netdev
))
4838 e1000_reinit_locked(adapter
);
4840 e1000_reset(adapter
);
4842 case M88E1000_PHY_SPEC_CTRL
:
4843 case M88E1000_EXT_PHY_SPEC_CTRL
:
4844 if (e1000_phy_reset(hw
))
4849 switch (data
->reg_num
) {
4851 if (mii_reg
& MII_CR_POWER_DOWN
)
4853 if (netif_running(adapter
->netdev
))
4854 e1000_reinit_locked(adapter
);
4856 e1000_reset(adapter
);
4864 return E1000_SUCCESS
;
4867 void e1000_pci_set_mwi(struct e1000_hw
*hw
)
4869 struct e1000_adapter
*adapter
= hw
->back
;
4870 int ret_val
= pci_set_mwi(adapter
->pdev
);
4873 e_err(probe
, "Error in setting MWI\n");
4876 void e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4878 struct e1000_adapter
*adapter
= hw
->back
;
4880 pci_clear_mwi(adapter
->pdev
);
4883 int e1000_pcix_get_mmrbc(struct e1000_hw
*hw
)
4885 struct e1000_adapter
*adapter
= hw
->back
;
4886 return pcix_get_mmrbc(adapter
->pdev
);
4889 void e1000_pcix_set_mmrbc(struct e1000_hw
*hw
, int mmrbc
)
4891 struct e1000_adapter
*adapter
= hw
->back
;
4892 pcix_set_mmrbc(adapter
->pdev
, mmrbc
);
4895 void e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, u32 value
)
4900 static bool e1000_vlan_used(struct e1000_adapter
*adapter
)
4904 for_each_set_bit(vid
, adapter
->active_vlans
, VLAN_N_VID
)
4909 static void __e1000_vlan_mode(struct e1000_adapter
*adapter
,
4910 netdev_features_t features
)
4912 struct e1000_hw
*hw
= &adapter
->hw
;
4916 if (features
& NETIF_F_HW_VLAN_CTAG_RX
) {
4917 /* enable VLAN tag insert/strip */
4918 ctrl
|= E1000_CTRL_VME
;
4920 /* disable VLAN tag insert/strip */
4921 ctrl
&= ~E1000_CTRL_VME
;
4925 static void e1000_vlan_filter_on_off(struct e1000_adapter
*adapter
,
4928 struct e1000_hw
*hw
= &adapter
->hw
;
4931 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4932 e1000_irq_disable(adapter
);
4934 __e1000_vlan_mode(adapter
, adapter
->netdev
->features
);
4936 /* enable VLAN receive filtering */
4938 rctl
&= ~E1000_RCTL_CFIEN
;
4939 if (!(adapter
->netdev
->flags
& IFF_PROMISC
))
4940 rctl
|= E1000_RCTL_VFE
;
4942 e1000_update_mng_vlan(adapter
);
4944 /* disable VLAN receive filtering */
4946 rctl
&= ~E1000_RCTL_VFE
;
4950 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4951 e1000_irq_enable(adapter
);
4954 static void e1000_vlan_mode(struct net_device
*netdev
,
4955 netdev_features_t features
)
4957 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4959 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4960 e1000_irq_disable(adapter
);
4962 __e1000_vlan_mode(adapter
, features
);
4964 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4965 e1000_irq_enable(adapter
);
4968 static int e1000_vlan_rx_add_vid(struct net_device
*netdev
,
4969 __be16 proto
, u16 vid
)
4971 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4972 struct e1000_hw
*hw
= &adapter
->hw
;
4975 if ((hw
->mng_cookie
.status
&
4976 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4977 (vid
== adapter
->mng_vlan_id
))
4980 if (!e1000_vlan_used(adapter
))
4981 e1000_vlan_filter_on_off(adapter
, true);
4983 /* add VID to filter table */
4984 index
= (vid
>> 5) & 0x7F;
4985 vfta
= E1000_READ_REG_ARRAY(hw
, VFTA
, index
);
4986 vfta
|= (1 << (vid
& 0x1F));
4987 e1000_write_vfta(hw
, index
, vfta
);
4989 set_bit(vid
, adapter
->active_vlans
);
4994 static int e1000_vlan_rx_kill_vid(struct net_device
*netdev
,
4995 __be16 proto
, u16 vid
)
4997 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4998 struct e1000_hw
*hw
= &adapter
->hw
;
5001 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
5002 e1000_irq_disable(adapter
);
5003 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
5004 e1000_irq_enable(adapter
);
5006 /* remove VID from filter table */
5007 index
= (vid
>> 5) & 0x7F;
5008 vfta
= E1000_READ_REG_ARRAY(hw
, VFTA
, index
);
5009 vfta
&= ~(1 << (vid
& 0x1F));
5010 e1000_write_vfta(hw
, index
, vfta
);
5012 clear_bit(vid
, adapter
->active_vlans
);
5014 if (!e1000_vlan_used(adapter
))
5015 e1000_vlan_filter_on_off(adapter
, false);
5020 static void e1000_restore_vlan(struct e1000_adapter
*adapter
)
5024 if (!e1000_vlan_used(adapter
))
5027 e1000_vlan_filter_on_off(adapter
, true);
5028 for_each_set_bit(vid
, adapter
->active_vlans
, VLAN_N_VID
)
5029 e1000_vlan_rx_add_vid(adapter
->netdev
, htons(ETH_P_8021Q
), vid
);
5032 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u32 spd
, u8 dplx
)
5034 struct e1000_hw
*hw
= &adapter
->hw
;
5038 /* Make sure dplx is at most 1 bit and lsb of speed is not set
5039 * for the switch() below to work
5041 if ((spd
& 1) || (dplx
& ~1))
5044 /* Fiber NICs only allow 1000 gbps Full duplex */
5045 if ((hw
->media_type
== e1000_media_type_fiber
) &&
5046 spd
!= SPEED_1000
&&
5047 dplx
!= DUPLEX_FULL
)
5050 switch (spd
+ dplx
) {
5051 case SPEED_10
+ DUPLEX_HALF
:
5052 hw
->forced_speed_duplex
= e1000_10_half
;
5054 case SPEED_10
+ DUPLEX_FULL
:
5055 hw
->forced_speed_duplex
= e1000_10_full
;
5057 case SPEED_100
+ DUPLEX_HALF
:
5058 hw
->forced_speed_duplex
= e1000_100_half
;
5060 case SPEED_100
+ DUPLEX_FULL
:
5061 hw
->forced_speed_duplex
= e1000_100_full
;
5063 case SPEED_1000
+ DUPLEX_FULL
:
5065 hw
->autoneg_advertised
= ADVERTISE_1000_FULL
;
5067 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
5072 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
5073 hw
->mdix
= AUTO_ALL_MODES
;
5078 e_err(probe
, "Unsupported Speed/Duplex configuration\n");
5082 static int __e1000_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
5084 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5085 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5086 struct e1000_hw
*hw
= &adapter
->hw
;
5087 u32 ctrl
, ctrl_ext
, rctl
, status
;
5088 u32 wufc
= adapter
->wol
;
5093 netif_device_detach(netdev
);
5095 if (netif_running(netdev
)) {
5096 int count
= E1000_CHECK_RESET_COUNT
;
5098 while (test_bit(__E1000_RESETTING
, &adapter
->flags
) && count
--)
5099 usleep_range(10000, 20000);
5101 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
5102 e1000_down(adapter
);
5106 retval
= pci_save_state(pdev
);
5111 status
= er32(STATUS
);
5112 if (status
& E1000_STATUS_LU
)
5113 wufc
&= ~E1000_WUFC_LNKC
;
5116 e1000_setup_rctl(adapter
);
5117 e1000_set_rx_mode(netdev
);
5121 /* turn on all-multi mode if wake on multicast is enabled */
5122 if (wufc
& E1000_WUFC_MC
)
5123 rctl
|= E1000_RCTL_MPE
;
5125 /* enable receives in the hardware */
5126 ew32(RCTL
, rctl
| E1000_RCTL_EN
);
5128 if (hw
->mac_type
>= e1000_82540
) {
5130 /* advertise wake from D3Cold */
5131 #define E1000_CTRL_ADVD3WUC 0x00100000
5132 /* phy power management enable */
5133 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5134 ctrl
|= E1000_CTRL_ADVD3WUC
|
5135 E1000_CTRL_EN_PHY_PWR_MGMT
;
5139 if (hw
->media_type
== e1000_media_type_fiber
||
5140 hw
->media_type
== e1000_media_type_internal_serdes
) {
5141 /* keep the laser running in D3 */
5142 ctrl_ext
= er32(CTRL_EXT
);
5143 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
5144 ew32(CTRL_EXT
, ctrl_ext
);
5147 ew32(WUC
, E1000_WUC_PME_EN
);
5154 e1000_release_manageability(adapter
);
5156 *enable_wake
= !!wufc
;
5158 /* make sure adapter isn't asleep if manageability is enabled */
5159 if (adapter
->en_mng_pt
)
5160 *enable_wake
= true;
5162 if (netif_running(netdev
))
5163 e1000_free_irq(adapter
);
5165 if (!test_and_set_bit(__E1000_DISABLED
, &adapter
->flags
))
5166 pci_disable_device(pdev
);
5172 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5177 retval
= __e1000_shutdown(pdev
, &wake
);
5182 pci_prepare_to_sleep(pdev
);
5184 pci_wake_from_d3(pdev
, false);
5185 pci_set_power_state(pdev
, PCI_D3hot
);
5191 static int e1000_resume(struct pci_dev
*pdev
)
5193 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5194 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5195 struct e1000_hw
*hw
= &adapter
->hw
;
5198 pci_set_power_state(pdev
, PCI_D0
);
5199 pci_restore_state(pdev
);
5200 pci_save_state(pdev
);
5202 if (adapter
->need_ioport
)
5203 err
= pci_enable_device(pdev
);
5205 err
= pci_enable_device_mem(pdev
);
5207 pr_err("Cannot enable PCI device from suspend\n");
5211 /* flush memory to make sure state is correct */
5212 smp_mb__before_atomic();
5213 clear_bit(__E1000_DISABLED
, &adapter
->flags
);
5214 pci_set_master(pdev
);
5216 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5217 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5219 if (netif_running(netdev
)) {
5220 err
= e1000_request_irq(adapter
);
5225 e1000_power_up_phy(adapter
);
5226 e1000_reset(adapter
);
5229 e1000_init_manageability(adapter
);
5231 if (netif_running(netdev
))
5234 netif_device_attach(netdev
);
5240 static void e1000_shutdown(struct pci_dev
*pdev
)
5244 __e1000_shutdown(pdev
, &wake
);
5246 if (system_state
== SYSTEM_POWER_OFF
) {
5247 pci_wake_from_d3(pdev
, wake
);
5248 pci_set_power_state(pdev
, PCI_D3hot
);
5252 #ifdef CONFIG_NET_POLL_CONTROLLER
5253 /* Polling 'interrupt' - used by things like netconsole to send skbs
5254 * without having to re-enable interrupts. It's not called while
5255 * the interrupt routine is executing.
5257 static void e1000_netpoll(struct net_device
*netdev
)
5259 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5261 if (disable_hardirq(adapter
->pdev
->irq
))
5262 e1000_intr(adapter
->pdev
->irq
, netdev
);
5263 enable_irq(adapter
->pdev
->irq
);
5268 * e1000_io_error_detected - called when PCI error is detected
5269 * @pdev: Pointer to PCI device
5270 * @state: The current pci connection state
5272 * This function is called after a PCI bus error affecting
5273 * this device has been detected.
5275 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
5276 pci_channel_state_t state
)
5278 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5279 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5281 netif_device_detach(netdev
);
5283 if (state
== pci_channel_io_perm_failure
)
5284 return PCI_ERS_RESULT_DISCONNECT
;
5286 if (netif_running(netdev
))
5287 e1000_down(adapter
);
5289 if (!test_and_set_bit(__E1000_DISABLED
, &adapter
->flags
))
5290 pci_disable_device(pdev
);
5292 /* Request a slot slot reset. */
5293 return PCI_ERS_RESULT_NEED_RESET
;
5297 * e1000_io_slot_reset - called after the pci bus has been reset.
5298 * @pdev: Pointer to PCI device
5300 * Restart the card from scratch, as if from a cold-boot. Implementation
5301 * resembles the first-half of the e1000_resume routine.
5303 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
5305 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5306 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5307 struct e1000_hw
*hw
= &adapter
->hw
;
5310 if (adapter
->need_ioport
)
5311 err
= pci_enable_device(pdev
);
5313 err
= pci_enable_device_mem(pdev
);
5315 pr_err("Cannot re-enable PCI device after reset.\n");
5316 return PCI_ERS_RESULT_DISCONNECT
;
5319 /* flush memory to make sure state is correct */
5320 smp_mb__before_atomic();
5321 clear_bit(__E1000_DISABLED
, &adapter
->flags
);
5322 pci_set_master(pdev
);
5324 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5325 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5327 e1000_reset(adapter
);
5330 return PCI_ERS_RESULT_RECOVERED
;
5334 * e1000_io_resume - called when traffic can start flowing again.
5335 * @pdev: Pointer to PCI device
5337 * This callback is called when the error recovery driver tells us that
5338 * its OK to resume normal operation. Implementation resembles the
5339 * second-half of the e1000_resume routine.
5341 static void e1000_io_resume(struct pci_dev
*pdev
)
5343 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5344 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5346 e1000_init_manageability(adapter
);
5348 if (netif_running(netdev
)) {
5349 if (e1000_up(adapter
)) {
5350 pr_info("can't bring device back up after reset\n");
5355 netif_device_attach(netdev
);