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 char e1000_driver_name
[] = "e1000";
33 static char e1000_driver_string
[] = "Intel(R) PRO/1000 Network Driver";
34 #define DRV_VERSION "7.3.21-k3-NAPI"
35 const char e1000_driver_version
[] = DRV_VERSION
;
36 static const char e1000_copyright
[] = "Copyright (c) 1999-2006 Intel Corporation.";
38 /* e1000_pci_tbl - PCI Device ID Table
40 * Last entry must be all 0s
43 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
45 static struct pci_device_id e1000_pci_tbl
[] = {
46 INTEL_E1000_ETHERNET_DEVICE(0x1000),
47 INTEL_E1000_ETHERNET_DEVICE(0x1001),
48 INTEL_E1000_ETHERNET_DEVICE(0x1004),
49 INTEL_E1000_ETHERNET_DEVICE(0x1008),
50 INTEL_E1000_ETHERNET_DEVICE(0x1009),
51 INTEL_E1000_ETHERNET_DEVICE(0x100C),
52 INTEL_E1000_ETHERNET_DEVICE(0x100D),
53 INTEL_E1000_ETHERNET_DEVICE(0x100E),
54 INTEL_E1000_ETHERNET_DEVICE(0x100F),
55 INTEL_E1000_ETHERNET_DEVICE(0x1010),
56 INTEL_E1000_ETHERNET_DEVICE(0x1011),
57 INTEL_E1000_ETHERNET_DEVICE(0x1012),
58 INTEL_E1000_ETHERNET_DEVICE(0x1013),
59 INTEL_E1000_ETHERNET_DEVICE(0x1014),
60 INTEL_E1000_ETHERNET_DEVICE(0x1015),
61 INTEL_E1000_ETHERNET_DEVICE(0x1016),
62 INTEL_E1000_ETHERNET_DEVICE(0x1017),
63 INTEL_E1000_ETHERNET_DEVICE(0x1018),
64 INTEL_E1000_ETHERNET_DEVICE(0x1019),
65 INTEL_E1000_ETHERNET_DEVICE(0x101A),
66 INTEL_E1000_ETHERNET_DEVICE(0x101D),
67 INTEL_E1000_ETHERNET_DEVICE(0x101E),
68 INTEL_E1000_ETHERNET_DEVICE(0x1026),
69 INTEL_E1000_ETHERNET_DEVICE(0x1027),
70 INTEL_E1000_ETHERNET_DEVICE(0x1028),
71 INTEL_E1000_ETHERNET_DEVICE(0x1075),
72 INTEL_E1000_ETHERNET_DEVICE(0x1076),
73 INTEL_E1000_ETHERNET_DEVICE(0x1077),
74 INTEL_E1000_ETHERNET_DEVICE(0x1078),
75 INTEL_E1000_ETHERNET_DEVICE(0x1079),
76 INTEL_E1000_ETHERNET_DEVICE(0x107A),
77 INTEL_E1000_ETHERNET_DEVICE(0x107B),
78 INTEL_E1000_ETHERNET_DEVICE(0x107C),
79 INTEL_E1000_ETHERNET_DEVICE(0x108A),
80 INTEL_E1000_ETHERNET_DEVICE(0x1099),
81 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
82 /* required last entry */
86 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
88 int e1000_up(struct e1000_adapter
*adapter
);
89 void e1000_down(struct e1000_adapter
*adapter
);
90 void e1000_reinit_locked(struct e1000_adapter
*adapter
);
91 void e1000_reset(struct e1000_adapter
*adapter
);
92 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u16 spddplx
);
93 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
);
94 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
);
95 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
);
96 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
);
97 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
98 struct e1000_tx_ring
*txdr
);
99 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
100 struct e1000_rx_ring
*rxdr
);
101 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
102 struct e1000_tx_ring
*tx_ring
);
103 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
104 struct e1000_rx_ring
*rx_ring
);
105 void e1000_update_stats(struct e1000_adapter
*adapter
);
107 static int e1000_init_module(void);
108 static void e1000_exit_module(void);
109 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
110 static void __devexit
e1000_remove(struct pci_dev
*pdev
);
111 static int e1000_alloc_queues(struct e1000_adapter
*adapter
);
112 static int e1000_sw_init(struct e1000_adapter
*adapter
);
113 static int e1000_open(struct net_device
*netdev
);
114 static int e1000_close(struct net_device
*netdev
);
115 static void e1000_configure_tx(struct e1000_adapter
*adapter
);
116 static void e1000_configure_rx(struct e1000_adapter
*adapter
);
117 static void e1000_setup_rctl(struct e1000_adapter
*adapter
);
118 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
);
119 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
);
120 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
121 struct e1000_tx_ring
*tx_ring
);
122 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
123 struct e1000_rx_ring
*rx_ring
);
124 static void e1000_set_rx_mode(struct net_device
*netdev
);
125 static void e1000_update_phy_info(unsigned long data
);
126 static void e1000_watchdog(unsigned long data
);
127 static void e1000_82547_tx_fifo_stall(unsigned long data
);
128 static netdev_tx_t
e1000_xmit_frame(struct sk_buff
*skb
,
129 struct net_device
*netdev
);
130 static struct net_device_stats
* e1000_get_stats(struct net_device
*netdev
);
131 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
132 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
133 static irqreturn_t
e1000_intr(int irq
, void *data
);
134 static irqreturn_t
e1000_intr_msi(int irq
, void *data
);
135 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
136 struct e1000_tx_ring
*tx_ring
);
137 static int e1000_clean(struct napi_struct
*napi
, int budget
);
138 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
139 struct e1000_rx_ring
*rx_ring
,
140 int *work_done
, int work_to_do
);
141 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter
*adapter
,
142 struct e1000_rx_ring
*rx_ring
,
143 int *work_done
, int work_to_do
);
144 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
145 struct e1000_rx_ring
*rx_ring
,
147 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter
*adapter
,
148 struct e1000_rx_ring
*rx_ring
,
150 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
151 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
153 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
154 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
155 static void e1000_tx_timeout(struct net_device
*dev
);
156 static void e1000_reset_task(struct work_struct
*work
);
157 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
158 static int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
159 struct sk_buff
*skb
);
161 static void e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
);
162 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
);
163 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
);
164 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
167 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
);
168 static int e1000_resume(struct pci_dev
*pdev
);
170 static void e1000_shutdown(struct pci_dev
*pdev
);
172 #ifdef CONFIG_NET_POLL_CONTROLLER
173 /* for netdump / net console */
174 static void e1000_netpoll (struct net_device
*netdev
);
177 #define COPYBREAK_DEFAULT 256
178 static unsigned int copybreak __read_mostly
= COPYBREAK_DEFAULT
;
179 module_param(copybreak
, uint
, 0644);
180 MODULE_PARM_DESC(copybreak
,
181 "Maximum size of packet that is copied to a new buffer on receive");
183 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
184 pci_channel_state_t state
);
185 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
);
186 static void e1000_io_resume(struct pci_dev
*pdev
);
188 static struct pci_error_handlers e1000_err_handler
= {
189 .error_detected
= e1000_io_error_detected
,
190 .slot_reset
= e1000_io_slot_reset
,
191 .resume
= e1000_io_resume
,
194 static struct pci_driver e1000_driver
= {
195 .name
= e1000_driver_name
,
196 .id_table
= e1000_pci_tbl
,
197 .probe
= e1000_probe
,
198 .remove
= __devexit_p(e1000_remove
),
200 /* Power Managment Hooks */
201 .suspend
= e1000_suspend
,
202 .resume
= e1000_resume
,
204 .shutdown
= e1000_shutdown
,
205 .err_handler
= &e1000_err_handler
208 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
209 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
210 MODULE_LICENSE("GPL");
211 MODULE_VERSION(DRV_VERSION
);
213 static int debug
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
214 module_param(debug
, int, 0);
215 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
218 * e1000_init_module - Driver Registration Routine
220 * e1000_init_module is the first routine called when the driver is
221 * loaded. All it does is register with the PCI subsystem.
224 static int __init
e1000_init_module(void)
227 printk(KERN_INFO
"%s - version %s\n",
228 e1000_driver_string
, e1000_driver_version
);
230 printk(KERN_INFO
"%s\n", e1000_copyright
);
232 ret
= pci_register_driver(&e1000_driver
);
233 if (copybreak
!= COPYBREAK_DEFAULT
) {
235 printk(KERN_INFO
"e1000: copybreak disabled\n");
237 printk(KERN_INFO
"e1000: copybreak enabled for "
238 "packets <= %u bytes\n", copybreak
);
243 module_init(e1000_init_module
);
246 * e1000_exit_module - Driver Exit Cleanup Routine
248 * e1000_exit_module is called just before the driver is removed
252 static void __exit
e1000_exit_module(void)
254 pci_unregister_driver(&e1000_driver
);
257 module_exit(e1000_exit_module
);
259 static int e1000_request_irq(struct e1000_adapter
*adapter
)
261 struct e1000_hw
*hw
= &adapter
->hw
;
262 struct net_device
*netdev
= adapter
->netdev
;
263 irq_handler_t handler
= e1000_intr
;
264 int irq_flags
= IRQF_SHARED
;
267 if (hw
->mac_type
>= e1000_82571
) {
268 adapter
->have_msi
= !pci_enable_msi(adapter
->pdev
);
269 if (adapter
->have_msi
) {
270 handler
= e1000_intr_msi
;
275 err
= request_irq(adapter
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
278 if (adapter
->have_msi
)
279 pci_disable_msi(adapter
->pdev
);
281 "Unable to allocate interrupt Error: %d\n", err
);
287 static void e1000_free_irq(struct e1000_adapter
*adapter
)
289 struct net_device
*netdev
= adapter
->netdev
;
291 free_irq(adapter
->pdev
->irq
, netdev
);
293 if (adapter
->have_msi
)
294 pci_disable_msi(adapter
->pdev
);
298 * e1000_irq_disable - Mask off interrupt generation on the NIC
299 * @adapter: board private structure
302 static void e1000_irq_disable(struct e1000_adapter
*adapter
)
304 struct e1000_hw
*hw
= &adapter
->hw
;
308 synchronize_irq(adapter
->pdev
->irq
);
312 * e1000_irq_enable - Enable default interrupt generation settings
313 * @adapter: board private structure
316 static void e1000_irq_enable(struct e1000_adapter
*adapter
)
318 struct e1000_hw
*hw
= &adapter
->hw
;
320 ew32(IMS
, IMS_ENABLE_MASK
);
324 static void e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
326 struct e1000_hw
*hw
= &adapter
->hw
;
327 struct net_device
*netdev
= adapter
->netdev
;
328 u16 vid
= hw
->mng_cookie
.vlan_id
;
329 u16 old_vid
= adapter
->mng_vlan_id
;
330 if (adapter
->vlgrp
) {
331 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
332 if (hw
->mng_cookie
.status
&
333 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
334 e1000_vlan_rx_add_vid(netdev
, vid
);
335 adapter
->mng_vlan_id
= vid
;
337 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
339 if ((old_vid
!= (u16
)E1000_MNG_VLAN_NONE
) &&
341 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
342 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
344 adapter
->mng_vlan_id
= vid
;
349 * e1000_release_hw_control - release control of the h/w to f/w
350 * @adapter: address of board private structure
352 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
353 * For ASF and Pass Through versions of f/w this means that the
354 * driver is no longer loaded. For AMT version (only with 82573) i
355 * of the f/w this means that the network i/f is closed.
359 static void e1000_release_hw_control(struct e1000_adapter
*adapter
)
363 struct e1000_hw
*hw
= &adapter
->hw
;
365 /* Let firmware taken over control of h/w */
366 switch (hw
->mac_type
) {
369 ew32(SWSM
, swsm
& ~E1000_SWSM_DRV_LOAD
);
373 case e1000_80003es2lan
:
375 ctrl_ext
= er32(CTRL_EXT
);
376 ew32(CTRL_EXT
, ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
384 * e1000_get_hw_control - get control of the h/w from f/w
385 * @adapter: address of board private structure
387 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
388 * For ASF and Pass Through versions of f/w this means that
389 * the driver is loaded. For AMT version (only with 82573)
390 * of the f/w this means that the network i/f is open.
394 static void e1000_get_hw_control(struct e1000_adapter
*adapter
)
398 struct e1000_hw
*hw
= &adapter
->hw
;
400 /* Let firmware know the driver has taken over */
401 switch (hw
->mac_type
) {
404 ew32(SWSM
, swsm
| E1000_SWSM_DRV_LOAD
);
408 case e1000_80003es2lan
:
410 ctrl_ext
= er32(CTRL_EXT
);
411 ew32(CTRL_EXT
, ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
418 static void e1000_init_manageability(struct e1000_adapter
*adapter
)
420 struct e1000_hw
*hw
= &adapter
->hw
;
422 if (adapter
->en_mng_pt
) {
423 u32 manc
= er32(MANC
);
425 /* disable hardware interception of ARP */
426 manc
&= ~(E1000_MANC_ARP_EN
);
428 /* enable receiving management packets to the host */
429 /* this will probably generate destination unreachable messages
430 * from the host OS, but the packets will be handled on SMBUS */
431 if (hw
->has_manc2h
) {
432 u32 manc2h
= er32(MANC2H
);
434 manc
|= E1000_MANC_EN_MNG2HOST
;
435 #define E1000_MNG2HOST_PORT_623 (1 << 5)
436 #define E1000_MNG2HOST_PORT_664 (1 << 6)
437 manc2h
|= E1000_MNG2HOST_PORT_623
;
438 manc2h
|= E1000_MNG2HOST_PORT_664
;
439 ew32(MANC2H
, manc2h
);
446 static void e1000_release_manageability(struct e1000_adapter
*adapter
)
448 struct e1000_hw
*hw
= &adapter
->hw
;
450 if (adapter
->en_mng_pt
) {
451 u32 manc
= er32(MANC
);
453 /* re-enable hardware interception of ARP */
454 manc
|= E1000_MANC_ARP_EN
;
457 manc
&= ~E1000_MANC_EN_MNG2HOST
;
459 /* don't explicitly have to mess with MANC2H since
460 * MANC has an enable disable that gates MANC2H */
467 * e1000_configure - configure the hardware for RX and TX
468 * @adapter = private board structure
470 static void e1000_configure(struct e1000_adapter
*adapter
)
472 struct net_device
*netdev
= adapter
->netdev
;
475 e1000_set_rx_mode(netdev
);
477 e1000_restore_vlan(adapter
);
478 e1000_init_manageability(adapter
);
480 e1000_configure_tx(adapter
);
481 e1000_setup_rctl(adapter
);
482 e1000_configure_rx(adapter
);
483 /* call E1000_DESC_UNUSED which always leaves
484 * at least 1 descriptor unused to make sure
485 * next_to_use != next_to_clean */
486 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
487 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[i
];
488 adapter
->alloc_rx_buf(adapter
, ring
,
489 E1000_DESC_UNUSED(ring
));
492 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
495 int e1000_up(struct e1000_adapter
*adapter
)
497 struct e1000_hw
*hw
= &adapter
->hw
;
499 /* hardware has been reset, we need to reload some things */
500 e1000_configure(adapter
);
502 clear_bit(__E1000_DOWN
, &adapter
->flags
);
504 napi_enable(&adapter
->napi
);
506 e1000_irq_enable(adapter
);
508 netif_wake_queue(adapter
->netdev
);
510 /* fire a link change interrupt to start the watchdog */
511 ew32(ICS
, E1000_ICS_LSC
);
516 * e1000_power_up_phy - restore link in case the phy was powered down
517 * @adapter: address of board private structure
519 * The phy may be powered down to save power and turn off link when the
520 * driver is unloaded and wake on lan is not enabled (among others)
521 * *** this routine MUST be followed by a call to e1000_reset ***
525 void e1000_power_up_phy(struct e1000_adapter
*adapter
)
527 struct e1000_hw
*hw
= &adapter
->hw
;
530 /* Just clear the power down bit to wake the phy back up */
531 if (hw
->media_type
== e1000_media_type_copper
) {
532 /* according to the manual, the phy will retain its
533 * settings across a power-down/up cycle */
534 e1000_read_phy_reg(hw
, PHY_CTRL
, &mii_reg
);
535 mii_reg
&= ~MII_CR_POWER_DOWN
;
536 e1000_write_phy_reg(hw
, PHY_CTRL
, mii_reg
);
540 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
542 struct e1000_hw
*hw
= &adapter
->hw
;
544 /* Power down the PHY so no link is implied when interface is down *
545 * The PHY cannot be powered down if any of the following is true *
548 * (c) SoL/IDER session is active */
549 if (!adapter
->wol
&& hw
->mac_type
>= e1000_82540
&&
550 hw
->media_type
== e1000_media_type_copper
) {
553 switch (hw
->mac_type
) {
556 case e1000_82545_rev_3
:
558 case e1000_82546_rev_3
:
560 case e1000_82541_rev_2
:
562 case e1000_82547_rev_2
:
563 if (er32(MANC
) & E1000_MANC_SMBUS_EN
)
569 case e1000_80003es2lan
:
571 if (e1000_check_mng_mode(hw
) ||
572 e1000_check_phy_reset_block(hw
))
578 e1000_read_phy_reg(hw
, PHY_CTRL
, &mii_reg
);
579 mii_reg
|= MII_CR_POWER_DOWN
;
580 e1000_write_phy_reg(hw
, PHY_CTRL
, mii_reg
);
587 void e1000_down(struct e1000_adapter
*adapter
)
589 struct e1000_hw
*hw
= &adapter
->hw
;
590 struct net_device
*netdev
= adapter
->netdev
;
593 /* signal that we're down so the interrupt handler does not
594 * reschedule our watchdog timer */
595 set_bit(__E1000_DOWN
, &adapter
->flags
);
597 /* disable receives in the hardware */
599 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
600 /* flush and sleep below */
602 /* can be netif_tx_disable when NETIF_F_LLTX is removed */
603 netif_stop_queue(netdev
);
605 /* disable transmits in the hardware */
607 tctl
&= ~E1000_TCTL_EN
;
609 /* flush both disables and wait for them to finish */
613 napi_disable(&adapter
->napi
);
615 e1000_irq_disable(adapter
);
617 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
618 del_timer_sync(&adapter
->watchdog_timer
);
619 del_timer_sync(&adapter
->phy_info_timer
);
621 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
622 adapter
->link_speed
= 0;
623 adapter
->link_duplex
= 0;
624 netif_carrier_off(netdev
);
626 e1000_reset(adapter
);
627 e1000_clean_all_tx_rings(adapter
);
628 e1000_clean_all_rx_rings(adapter
);
631 void e1000_reinit_locked(struct e1000_adapter
*adapter
)
633 WARN_ON(in_interrupt());
634 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->flags
))
638 clear_bit(__E1000_RESETTING
, &adapter
->flags
);
641 void e1000_reset(struct e1000_adapter
*adapter
)
643 struct e1000_hw
*hw
= &adapter
->hw
;
644 u32 pba
= 0, tx_space
, min_tx_space
, min_rx_space
;
645 bool legacy_pba_adjust
= false;
648 /* Repartition Pba for greater than 9k mtu
649 * To take effect CTRL.RST is required.
652 switch (hw
->mac_type
) {
653 case e1000_82542_rev2_0
:
654 case e1000_82542_rev2_1
:
659 case e1000_82541_rev_2
:
660 legacy_pba_adjust
= true;
664 case e1000_82545_rev_3
:
666 case e1000_82546_rev_3
:
670 case e1000_82547_rev_2
:
671 legacy_pba_adjust
= true;
676 case e1000_80003es2lan
:
684 case e1000_undefined
:
689 if (legacy_pba_adjust
) {
690 if (hw
->max_frame_size
> E1000_RXBUFFER_8192
)
691 pba
-= 8; /* allocate more FIFO for Tx */
693 if (hw
->mac_type
== e1000_82547
) {
694 adapter
->tx_fifo_head
= 0;
695 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
696 adapter
->tx_fifo_size
=
697 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
698 atomic_set(&adapter
->tx_fifo_stall
, 0);
700 } else if (hw
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
701 /* adjust PBA for jumbo frames */
704 /* To maintain wire speed transmits, the Tx FIFO should be
705 * large enough to accommodate two full transmit packets,
706 * rounded up to the next 1KB and expressed in KB. Likewise,
707 * the Rx FIFO should be large enough to accommodate at least
708 * one full receive packet and is similarly rounded up and
709 * expressed in KB. */
711 /* upper 16 bits has Tx packet buffer allocation size in KB */
712 tx_space
= pba
>> 16;
713 /* lower 16 bits has Rx packet buffer allocation size in KB */
716 * the tx fifo also stores 16 bytes of information about the tx
717 * but don't include ethernet FCS because hardware appends it
719 min_tx_space
= (hw
->max_frame_size
+
720 sizeof(struct e1000_tx_desc
) -
722 min_tx_space
= ALIGN(min_tx_space
, 1024);
724 /* software strips receive CRC, so leave room for it */
725 min_rx_space
= hw
->max_frame_size
;
726 min_rx_space
= ALIGN(min_rx_space
, 1024);
729 /* If current Tx allocation is less than the min Tx FIFO size,
730 * and the min Tx FIFO size is less than the current Rx FIFO
731 * allocation, take space away from current Rx allocation */
732 if (tx_space
< min_tx_space
&&
733 ((min_tx_space
- tx_space
) < pba
)) {
734 pba
= pba
- (min_tx_space
- tx_space
);
736 /* PCI/PCIx hardware has PBA alignment constraints */
737 switch (hw
->mac_type
) {
738 case e1000_82545
... e1000_82546_rev_3
:
739 pba
&= ~(E1000_PBA_8K
- 1);
745 /* if short on rx space, rx wins and must trump tx
746 * adjustment or use Early Receive if available */
747 if (pba
< min_rx_space
) {
748 switch (hw
->mac_type
) {
750 /* ERT enabled in e1000_configure_rx */
763 * flow control settings:
764 * The high water mark must be low enough to fit one full frame
765 * (or the size used for early receive) above it in the Rx FIFO.
766 * Set it to the lower of:
767 * - 90% of the Rx FIFO size, and
768 * - the full Rx FIFO size minus the early receive size (for parts
769 * with ERT support assuming ERT set to E1000_ERT_2048), or
770 * - the full Rx FIFO size minus one full frame
772 hwm
= min(((pba
<< 10) * 9 / 10),
773 ((pba
<< 10) - hw
->max_frame_size
));
775 hw
->fc_high_water
= hwm
& 0xFFF8; /* 8-byte granularity */
776 hw
->fc_low_water
= hw
->fc_high_water
- 8;
777 hw
->fc_pause_time
= E1000_FC_PAUSE_TIME
;
779 hw
->fc
= hw
->original_fc
;
781 /* Allow time for pending master requests to run */
783 if (hw
->mac_type
>= e1000_82544
)
786 if (e1000_init_hw(hw
))
787 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
788 e1000_update_mng_vlan(adapter
);
790 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
791 if (hw
->mac_type
>= e1000_82544
&&
792 hw
->mac_type
<= e1000_82547_rev_2
&&
794 hw
->autoneg_advertised
== ADVERTISE_1000_FULL
) {
795 u32 ctrl
= er32(CTRL
);
796 /* clear phy power management bit if we are in gig only mode,
797 * which if enabled will attempt negotiation to 100Mb, which
798 * can cause a loss of link at power off or driver unload */
799 ctrl
&= ~E1000_CTRL_SWDPIN3
;
803 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
804 ew32(VET
, ETHERNET_IEEE_VLAN_TYPE
);
806 e1000_reset_adaptive(hw
);
807 e1000_phy_get_info(hw
, &adapter
->phy_info
);
809 if (!adapter
->smart_power_down
&&
810 (hw
->mac_type
== e1000_82571
||
811 hw
->mac_type
== e1000_82572
)) {
813 /* speed up time to link by disabling smart power down, ignore
814 * the return value of this function because there is nothing
815 * different we would do if it failed */
816 e1000_read_phy_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
818 phy_data
&= ~IGP02E1000_PM_SPD
;
819 e1000_write_phy_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
823 e1000_release_manageability(adapter
);
827 * Dump the eeprom for users having checksum issues
829 static void e1000_dump_eeprom(struct e1000_adapter
*adapter
)
831 struct net_device
*netdev
= adapter
->netdev
;
832 struct ethtool_eeprom eeprom
;
833 const struct ethtool_ops
*ops
= netdev
->ethtool_ops
;
836 u16 csum_old
, csum_new
= 0;
838 eeprom
.len
= ops
->get_eeprom_len(netdev
);
841 data
= kmalloc(eeprom
.len
, GFP_KERNEL
);
843 printk(KERN_ERR
"Unable to allocate memory to dump EEPROM"
848 ops
->get_eeprom(netdev
, &eeprom
, data
);
850 csum_old
= (data
[EEPROM_CHECKSUM_REG
* 2]) +
851 (data
[EEPROM_CHECKSUM_REG
* 2 + 1] << 8);
852 for (i
= 0; i
< EEPROM_CHECKSUM_REG
* 2; i
+= 2)
853 csum_new
+= data
[i
] + (data
[i
+ 1] << 8);
854 csum_new
= EEPROM_SUM
- csum_new
;
856 printk(KERN_ERR
"/*********************/\n");
857 printk(KERN_ERR
"Current EEPROM Checksum : 0x%04x\n", csum_old
);
858 printk(KERN_ERR
"Calculated : 0x%04x\n", csum_new
);
860 printk(KERN_ERR
"Offset Values\n");
861 printk(KERN_ERR
"======== ======\n");
862 print_hex_dump(KERN_ERR
, "", DUMP_PREFIX_OFFSET
, 16, 1, data
, 128, 0);
864 printk(KERN_ERR
"Include this output when contacting your support "
866 printk(KERN_ERR
"This is not a software error! Something bad "
867 "happened to your hardware or\n");
868 printk(KERN_ERR
"EEPROM image. Ignoring this "
869 "problem could result in further problems,\n");
870 printk(KERN_ERR
"possibly loss of data, corruption or system hangs!\n");
871 printk(KERN_ERR
"The MAC Address will be reset to 00:00:00:00:00:00, "
872 "which is invalid\n");
873 printk(KERN_ERR
"and requires you to set the proper MAC "
874 "address manually before continuing\n");
875 printk(KERN_ERR
"to enable this network device.\n");
876 printk(KERN_ERR
"Please inspect the EEPROM dump and report the issue "
877 "to your hardware vendor\n");
878 printk(KERN_ERR
"or Intel Customer Support.\n");
879 printk(KERN_ERR
"/*********************/\n");
885 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
886 * @pdev: PCI device information struct
888 * Return true if an adapter needs ioport resources
890 static int e1000_is_need_ioport(struct pci_dev
*pdev
)
892 switch (pdev
->device
) {
893 case E1000_DEV_ID_82540EM
:
894 case E1000_DEV_ID_82540EM_LOM
:
895 case E1000_DEV_ID_82540EP
:
896 case E1000_DEV_ID_82540EP_LOM
:
897 case E1000_DEV_ID_82540EP_LP
:
898 case E1000_DEV_ID_82541EI
:
899 case E1000_DEV_ID_82541EI_MOBILE
:
900 case E1000_DEV_ID_82541ER
:
901 case E1000_DEV_ID_82541ER_LOM
:
902 case E1000_DEV_ID_82541GI
:
903 case E1000_DEV_ID_82541GI_LF
:
904 case E1000_DEV_ID_82541GI_MOBILE
:
905 case E1000_DEV_ID_82544EI_COPPER
:
906 case E1000_DEV_ID_82544EI_FIBER
:
907 case E1000_DEV_ID_82544GC_COPPER
:
908 case E1000_DEV_ID_82544GC_LOM
:
909 case E1000_DEV_ID_82545EM_COPPER
:
910 case E1000_DEV_ID_82545EM_FIBER
:
911 case E1000_DEV_ID_82546EB_COPPER
:
912 case E1000_DEV_ID_82546EB_FIBER
:
913 case E1000_DEV_ID_82546EB_QUAD_COPPER
:
920 static const struct net_device_ops e1000_netdev_ops
= {
921 .ndo_open
= e1000_open
,
922 .ndo_stop
= e1000_close
,
923 .ndo_start_xmit
= e1000_xmit_frame
,
924 .ndo_get_stats
= e1000_get_stats
,
925 .ndo_set_rx_mode
= e1000_set_rx_mode
,
926 .ndo_set_mac_address
= e1000_set_mac
,
927 .ndo_tx_timeout
= e1000_tx_timeout
,
928 .ndo_change_mtu
= e1000_change_mtu
,
929 .ndo_do_ioctl
= e1000_ioctl
,
930 .ndo_validate_addr
= eth_validate_addr
,
932 .ndo_vlan_rx_register
= e1000_vlan_rx_register
,
933 .ndo_vlan_rx_add_vid
= e1000_vlan_rx_add_vid
,
934 .ndo_vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
,
935 #ifdef CONFIG_NET_POLL_CONTROLLER
936 .ndo_poll_controller
= e1000_netpoll
,
941 * e1000_probe - Device Initialization Routine
942 * @pdev: PCI device information struct
943 * @ent: entry in e1000_pci_tbl
945 * Returns 0 on success, negative on failure
947 * e1000_probe initializes an adapter identified by a pci_dev structure.
948 * The OS initialization, configuring of the adapter private structure,
949 * and a hardware reset occur.
951 static int __devinit
e1000_probe(struct pci_dev
*pdev
,
952 const struct pci_device_id
*ent
)
954 struct net_device
*netdev
;
955 struct e1000_adapter
*adapter
;
958 static int cards_found
= 0;
959 static int global_quad_port_a
= 0; /* global ksp3 port a indication */
960 int i
, err
, pci_using_dac
;
962 u16 eeprom_apme_mask
= E1000_EEPROM_APME
;
963 int bars
, need_ioport
;
965 /* do not allocate ioport bars when not needed */
966 need_ioport
= e1000_is_need_ioport(pdev
);
968 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
969 err
= pci_enable_device(pdev
);
971 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
972 err
= pci_enable_device_mem(pdev
);
977 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
978 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
981 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
983 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
985 E1000_ERR("No usable DMA configuration, "
993 err
= pci_request_selected_regions(pdev
, bars
, e1000_driver_name
);
997 pci_set_master(pdev
);
1000 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
1002 goto err_alloc_etherdev
;
1004 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1006 pci_set_drvdata(pdev
, netdev
);
1007 adapter
= netdev_priv(netdev
);
1008 adapter
->netdev
= netdev
;
1009 adapter
->pdev
= pdev
;
1010 adapter
->msg_enable
= (1 << debug
) - 1;
1011 adapter
->bars
= bars
;
1012 adapter
->need_ioport
= need_ioport
;
1018 hw
->hw_addr
= pci_ioremap_bar(pdev
, BAR_0
);
1022 if (adapter
->need_ioport
) {
1023 for (i
= BAR_1
; i
<= BAR_5
; i
++) {
1024 if (pci_resource_len(pdev
, i
) == 0)
1026 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
1027 hw
->io_base
= pci_resource_start(pdev
, i
);
1033 netdev
->netdev_ops
= &e1000_netdev_ops
;
1034 e1000_set_ethtool_ops(netdev
);
1035 netdev
->watchdog_timeo
= 5 * HZ
;
1036 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
1038 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
1040 adapter
->bd_number
= cards_found
;
1042 /* setup the private structure */
1044 err
= e1000_sw_init(adapter
);
1049 /* Flash BAR mapping must happen after e1000_sw_init
1050 * because it depends on mac_type */
1051 if ((hw
->mac_type
== e1000_ich8lan
) &&
1052 (pci_resource_flags(pdev
, 1) & IORESOURCE_MEM
)) {
1053 hw
->flash_address
= pci_ioremap_bar(pdev
, 1);
1054 if (!hw
->flash_address
)
1058 if (e1000_check_phy_reset_block(hw
))
1059 DPRINTK(PROBE
, INFO
, "PHY reset is blocked due to SOL/IDER session.\n");
1061 if (hw
->mac_type
>= e1000_82543
) {
1062 netdev
->features
= NETIF_F_SG
|
1064 NETIF_F_HW_VLAN_TX
|
1065 NETIF_F_HW_VLAN_RX
|
1066 NETIF_F_HW_VLAN_FILTER
;
1067 if (hw
->mac_type
== e1000_ich8lan
)
1068 netdev
->features
&= ~NETIF_F_HW_VLAN_FILTER
;
1071 if ((hw
->mac_type
>= e1000_82544
) &&
1072 (hw
->mac_type
!= e1000_82547
))
1073 netdev
->features
|= NETIF_F_TSO
;
1075 if (hw
->mac_type
> e1000_82547_rev_2
)
1076 netdev
->features
|= NETIF_F_TSO6
;
1078 netdev
->features
|= NETIF_F_HIGHDMA
;
1080 netdev
->vlan_features
|= NETIF_F_TSO
;
1081 netdev
->vlan_features
|= NETIF_F_TSO6
;
1082 netdev
->vlan_features
|= NETIF_F_HW_CSUM
;
1083 netdev
->vlan_features
|= NETIF_F_SG
;
1085 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(hw
);
1087 /* initialize eeprom parameters */
1088 if (e1000_init_eeprom_params(hw
)) {
1089 E1000_ERR("EEPROM initialization failed\n");
1093 /* before reading the EEPROM, reset the controller to
1094 * put the device in a known good starting state */
1098 /* make sure the EEPROM is good */
1099 if (e1000_validate_eeprom_checksum(hw
) < 0) {
1100 DPRINTK(PROBE
, ERR
, "The EEPROM Checksum Is Not Valid\n");
1101 e1000_dump_eeprom(adapter
);
1103 * set MAC address to all zeroes to invalidate and temporary
1104 * disable this device for the user. This blocks regular
1105 * traffic while still permitting ethtool ioctls from reaching
1106 * the hardware as well as allowing the user to run the
1107 * interface after manually setting a hw addr using
1110 memset(hw
->mac_addr
, 0, netdev
->addr_len
);
1112 /* copy the MAC address out of the EEPROM */
1113 if (e1000_read_mac_addr(hw
))
1114 DPRINTK(PROBE
, ERR
, "EEPROM Read Error\n");
1116 /* don't block initalization here due to bad MAC address */
1117 memcpy(netdev
->dev_addr
, hw
->mac_addr
, netdev
->addr_len
);
1118 memcpy(netdev
->perm_addr
, hw
->mac_addr
, netdev
->addr_len
);
1120 if (!is_valid_ether_addr(netdev
->perm_addr
))
1121 DPRINTK(PROBE
, ERR
, "Invalid MAC Address\n");
1123 e1000_get_bus_info(hw
);
1125 init_timer(&adapter
->tx_fifo_stall_timer
);
1126 adapter
->tx_fifo_stall_timer
.function
= &e1000_82547_tx_fifo_stall
;
1127 adapter
->tx_fifo_stall_timer
.data
= (unsigned long)adapter
;
1129 init_timer(&adapter
->watchdog_timer
);
1130 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
1131 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
1133 init_timer(&adapter
->phy_info_timer
);
1134 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
1135 adapter
->phy_info_timer
.data
= (unsigned long)adapter
;
1137 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
1139 e1000_check_options(adapter
);
1141 /* Initial Wake on LAN setting
1142 * If APM wake is enabled in the EEPROM,
1143 * enable the ACPI Magic Packet filter
1146 switch (hw
->mac_type
) {
1147 case e1000_82542_rev2_0
:
1148 case e1000_82542_rev2_1
:
1152 e1000_read_eeprom(hw
,
1153 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
1154 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
1157 e1000_read_eeprom(hw
,
1158 EEPROM_INIT_CONTROL1_REG
, 1, &eeprom_data
);
1159 eeprom_apme_mask
= E1000_EEPROM_ICH8_APME
;
1162 case e1000_82546_rev_3
:
1164 case e1000_80003es2lan
:
1165 if (er32(STATUS
) & E1000_STATUS_FUNC_1
){
1166 e1000_read_eeprom(hw
,
1167 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
1172 e1000_read_eeprom(hw
,
1173 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
1176 if (eeprom_data
& eeprom_apme_mask
)
1177 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
1179 /* now that we have the eeprom settings, apply the special cases
1180 * where the eeprom may be wrong or the board simply won't support
1181 * wake on lan on a particular port */
1182 switch (pdev
->device
) {
1183 case E1000_DEV_ID_82546GB_PCIE
:
1184 adapter
->eeprom_wol
= 0;
1186 case E1000_DEV_ID_82546EB_FIBER
:
1187 case E1000_DEV_ID_82546GB_FIBER
:
1188 case E1000_DEV_ID_82571EB_FIBER
:
1189 /* Wake events only supported on port A for dual fiber
1190 * regardless of eeprom setting */
1191 if (er32(STATUS
) & E1000_STATUS_FUNC_1
)
1192 adapter
->eeprom_wol
= 0;
1194 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3
:
1195 case E1000_DEV_ID_82571EB_QUAD_COPPER
:
1196 case E1000_DEV_ID_82571EB_QUAD_FIBER
:
1197 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE
:
1198 case E1000_DEV_ID_82571PT_QUAD_COPPER
:
1199 /* if quad port adapter, disable WoL on all but port A */
1200 if (global_quad_port_a
!= 0)
1201 adapter
->eeprom_wol
= 0;
1203 adapter
->quad_port_a
= 1;
1204 /* Reset for multiple quad port adapters */
1205 if (++global_quad_port_a
== 4)
1206 global_quad_port_a
= 0;
1210 /* initialize the wol settings based on the eeprom settings */
1211 adapter
->wol
= adapter
->eeprom_wol
;
1212 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1214 /* print bus type/speed/width info */
1215 DPRINTK(PROBE
, INFO
, "(PCI%s:%s:%s) ",
1216 ((hw
->bus_type
== e1000_bus_type_pcix
) ? "-X" :
1217 (hw
->bus_type
== e1000_bus_type_pci_express
? " Express":"")),
1218 ((hw
->bus_speed
== e1000_bus_speed_2500
) ? "2.5Gb/s" :
1219 (hw
->bus_speed
== e1000_bus_speed_133
) ? "133MHz" :
1220 (hw
->bus_speed
== e1000_bus_speed_120
) ? "120MHz" :
1221 (hw
->bus_speed
== e1000_bus_speed_100
) ? "100MHz" :
1222 (hw
->bus_speed
== e1000_bus_speed_66
) ? "66MHz" : "33MHz"),
1223 ((hw
->bus_width
== e1000_bus_width_64
) ? "64-bit" :
1224 (hw
->bus_width
== e1000_bus_width_pciex_4
) ? "Width x4" :
1225 (hw
->bus_width
== e1000_bus_width_pciex_1
) ? "Width x1" :
1228 printk("%pM\n", netdev
->dev_addr
);
1230 if (hw
->bus_type
== e1000_bus_type_pci_express
) {
1231 DPRINTK(PROBE
, WARNING
, "This device (id %04x:%04x) will no "
1232 "longer be supported by this driver in the future.\n",
1233 pdev
->vendor
, pdev
->device
);
1234 DPRINTK(PROBE
, WARNING
, "please use the \"e1000e\" "
1235 "driver instead.\n");
1238 /* reset the hardware with the new settings */
1239 e1000_reset(adapter
);
1241 /* If the controller is 82573 and f/w is AMT, do not set
1242 * DRV_LOAD until the interface is up. For all other cases,
1243 * let the f/w know that the h/w is now under the control
1245 if (hw
->mac_type
!= e1000_82573
||
1246 !e1000_check_mng_mode(hw
))
1247 e1000_get_hw_control(adapter
);
1249 strcpy(netdev
->name
, "eth%d");
1250 err
= register_netdev(netdev
);
1254 /* carrier off reporting is important to ethtool even BEFORE open */
1255 netif_carrier_off(netdev
);
1257 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
1263 e1000_release_hw_control(adapter
);
1265 if (!e1000_check_phy_reset_block(hw
))
1266 e1000_phy_hw_reset(hw
);
1268 if (hw
->flash_address
)
1269 iounmap(hw
->flash_address
);
1271 kfree(adapter
->tx_ring
);
1272 kfree(adapter
->rx_ring
);
1274 iounmap(hw
->hw_addr
);
1276 free_netdev(netdev
);
1278 pci_release_selected_regions(pdev
, bars
);
1281 pci_disable_device(pdev
);
1286 * e1000_remove - Device Removal Routine
1287 * @pdev: PCI device information struct
1289 * e1000_remove is called by the PCI subsystem to alert the driver
1290 * that it should release a PCI device. The could be caused by a
1291 * Hot-Plug event, or because the driver is going to be removed from
1295 static void __devexit
e1000_remove(struct pci_dev
*pdev
)
1297 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1298 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1299 struct e1000_hw
*hw
= &adapter
->hw
;
1301 cancel_work_sync(&adapter
->reset_task
);
1303 e1000_release_manageability(adapter
);
1305 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1306 * would have already happened in close and is redundant. */
1307 e1000_release_hw_control(adapter
);
1309 unregister_netdev(netdev
);
1311 if (!e1000_check_phy_reset_block(hw
))
1312 e1000_phy_hw_reset(hw
);
1314 kfree(adapter
->tx_ring
);
1315 kfree(adapter
->rx_ring
);
1317 iounmap(hw
->hw_addr
);
1318 if (hw
->flash_address
)
1319 iounmap(hw
->flash_address
);
1320 pci_release_selected_regions(pdev
, adapter
->bars
);
1322 free_netdev(netdev
);
1324 pci_disable_device(pdev
);
1328 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1329 * @adapter: board private structure to initialize
1331 * e1000_sw_init initializes the Adapter private data structure.
1332 * Fields are initialized based on PCI device information and
1333 * OS network device settings (MTU size).
1336 static int __devinit
e1000_sw_init(struct e1000_adapter
*adapter
)
1338 struct e1000_hw
*hw
= &adapter
->hw
;
1339 struct net_device
*netdev
= adapter
->netdev
;
1340 struct pci_dev
*pdev
= adapter
->pdev
;
1342 /* PCI config space info */
1344 hw
->vendor_id
= pdev
->vendor
;
1345 hw
->device_id
= pdev
->device
;
1346 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
1347 hw
->subsystem_id
= pdev
->subsystem_device
;
1348 hw
->revision_id
= pdev
->revision
;
1350 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
1352 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1353 hw
->max_frame_size
= netdev
->mtu
+
1354 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
1355 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
1357 /* identify the MAC */
1359 if (e1000_set_mac_type(hw
)) {
1360 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
1364 switch (hw
->mac_type
) {
1369 case e1000_82541_rev_2
:
1370 case e1000_82547_rev_2
:
1371 hw
->phy_init_script
= 1;
1375 e1000_set_media_type(hw
);
1377 hw
->wait_autoneg_complete
= false;
1378 hw
->tbi_compatibility_en
= true;
1379 hw
->adaptive_ifs
= true;
1381 /* Copper options */
1383 if (hw
->media_type
== e1000_media_type_copper
) {
1384 hw
->mdix
= AUTO_ALL_MODES
;
1385 hw
->disable_polarity_correction
= false;
1386 hw
->master_slave
= E1000_MASTER_SLAVE
;
1389 adapter
->num_tx_queues
= 1;
1390 adapter
->num_rx_queues
= 1;
1392 if (e1000_alloc_queues(adapter
)) {
1393 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
1397 /* Explicitly disable IRQ since the NIC can be in any state. */
1398 e1000_irq_disable(adapter
);
1400 spin_lock_init(&adapter
->stats_lock
);
1402 set_bit(__E1000_DOWN
, &adapter
->flags
);
1408 * e1000_alloc_queues - Allocate memory for all rings
1409 * @adapter: board private structure to initialize
1411 * We allocate one ring per queue at run-time since we don't know the
1412 * number of queues at compile-time.
1415 static int __devinit
e1000_alloc_queues(struct e1000_adapter
*adapter
)
1417 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1418 sizeof(struct e1000_tx_ring
), GFP_KERNEL
);
1419 if (!adapter
->tx_ring
)
1422 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
1423 sizeof(struct e1000_rx_ring
), GFP_KERNEL
);
1424 if (!adapter
->rx_ring
) {
1425 kfree(adapter
->tx_ring
);
1429 return E1000_SUCCESS
;
1433 * e1000_open - Called when a network interface is made active
1434 * @netdev: network interface device structure
1436 * Returns 0 on success, negative value on failure
1438 * The open entry point is called when a network interface is made
1439 * active by the system (IFF_UP). At this point all resources needed
1440 * for transmit and receive operations are allocated, the interrupt
1441 * handler is registered with the OS, the watchdog timer is started,
1442 * and the stack is notified that the interface is ready.
1445 static int e1000_open(struct net_device
*netdev
)
1447 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1448 struct e1000_hw
*hw
= &adapter
->hw
;
1451 /* disallow open during test */
1452 if (test_bit(__E1000_TESTING
, &adapter
->flags
))
1455 netif_carrier_off(netdev
);
1457 /* allocate transmit descriptors */
1458 err
= e1000_setup_all_tx_resources(adapter
);
1462 /* allocate receive descriptors */
1463 err
= e1000_setup_all_rx_resources(adapter
);
1467 e1000_power_up_phy(adapter
);
1469 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1470 if ((hw
->mng_cookie
.status
&
1471 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1472 e1000_update_mng_vlan(adapter
);
1475 /* If AMT is enabled, let the firmware know that the network
1476 * interface is now open */
1477 if (hw
->mac_type
== e1000_82573
&&
1478 e1000_check_mng_mode(hw
))
1479 e1000_get_hw_control(adapter
);
1481 /* before we allocate an interrupt, we must be ready to handle it.
1482 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1483 * as soon as we call pci_request_irq, so we have to setup our
1484 * clean_rx handler before we do so. */
1485 e1000_configure(adapter
);
1487 err
= e1000_request_irq(adapter
);
1491 /* From here on the code is the same as e1000_up() */
1492 clear_bit(__E1000_DOWN
, &adapter
->flags
);
1494 napi_enable(&adapter
->napi
);
1496 e1000_irq_enable(adapter
);
1498 netif_start_queue(netdev
);
1500 /* fire a link status change interrupt to start the watchdog */
1501 ew32(ICS
, E1000_ICS_LSC
);
1503 return E1000_SUCCESS
;
1506 e1000_release_hw_control(adapter
);
1507 e1000_power_down_phy(adapter
);
1508 e1000_free_all_rx_resources(adapter
);
1510 e1000_free_all_tx_resources(adapter
);
1512 e1000_reset(adapter
);
1518 * e1000_close - Disables a network interface
1519 * @netdev: network interface device structure
1521 * Returns 0, this is not allowed to fail
1523 * The close entry point is called when an interface is de-activated
1524 * by the OS. The hardware is still under the drivers control, but
1525 * needs to be disabled. A global MAC reset is issued to stop the
1526 * hardware, and all transmit and receive resources are freed.
1529 static int e1000_close(struct net_device
*netdev
)
1531 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1532 struct e1000_hw
*hw
= &adapter
->hw
;
1534 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
1535 e1000_down(adapter
);
1536 e1000_power_down_phy(adapter
);
1537 e1000_free_irq(adapter
);
1539 e1000_free_all_tx_resources(adapter
);
1540 e1000_free_all_rx_resources(adapter
);
1542 /* kill manageability vlan ID if supported, but not if a vlan with
1543 * the same ID is registered on the host OS (let 8021q kill it) */
1544 if ((hw
->mng_cookie
.status
&
1545 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
1547 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
))) {
1548 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1551 /* If AMT is enabled, let the firmware know that the network
1552 * interface is now closed */
1553 if (hw
->mac_type
== e1000_82573
&&
1554 e1000_check_mng_mode(hw
))
1555 e1000_release_hw_control(adapter
);
1561 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1562 * @adapter: address of board private structure
1563 * @start: address of beginning of memory
1564 * @len: length of memory
1566 static bool e1000_check_64k_bound(struct e1000_adapter
*adapter
, void *start
,
1569 struct e1000_hw
*hw
= &adapter
->hw
;
1570 unsigned long begin
= (unsigned long)start
;
1571 unsigned long end
= begin
+ len
;
1573 /* First rev 82545 and 82546 need to not allow any memory
1574 * write location to cross 64k boundary due to errata 23 */
1575 if (hw
->mac_type
== e1000_82545
||
1576 hw
->mac_type
== e1000_82546
) {
1577 return ((begin
^ (end
- 1)) >> 16) != 0 ? false : true;
1584 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1585 * @adapter: board private structure
1586 * @txdr: tx descriptor ring (for a specific queue) to setup
1588 * Return 0 on success, negative on failure
1591 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1592 struct e1000_tx_ring
*txdr
)
1594 struct pci_dev
*pdev
= adapter
->pdev
;
1597 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1598 txdr
->buffer_info
= vmalloc(size
);
1599 if (!txdr
->buffer_info
) {
1601 "Unable to allocate memory for the transmit descriptor ring\n");
1604 memset(txdr
->buffer_info
, 0, size
);
1606 /* round up to nearest 4K */
1608 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1609 txdr
->size
= ALIGN(txdr
->size
, 4096);
1611 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1614 vfree(txdr
->buffer_info
);
1616 "Unable to allocate memory for the transmit descriptor ring\n");
1620 /* Fix for errata 23, can't cross 64kB boundary */
1621 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1622 void *olddesc
= txdr
->desc
;
1623 dma_addr_t olddma
= txdr
->dma
;
1624 DPRINTK(TX_ERR
, ERR
, "txdr align check failed: %u bytes "
1625 "at %p\n", txdr
->size
, txdr
->desc
);
1626 /* Try again, without freeing the previous */
1627 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1628 /* Failed allocation, critical failure */
1630 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1631 goto setup_tx_desc_die
;
1634 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1636 pci_free_consistent(pdev
, txdr
->size
, txdr
->desc
,
1638 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1640 "Unable to allocate aligned memory "
1641 "for the transmit descriptor ring\n");
1642 vfree(txdr
->buffer_info
);
1645 /* Free old allocation, new allocation was successful */
1646 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1649 memset(txdr
->desc
, 0, txdr
->size
);
1651 txdr
->next_to_use
= 0;
1652 txdr
->next_to_clean
= 0;
1658 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1659 * (Descriptors) for all queues
1660 * @adapter: board private structure
1662 * Return 0 on success, negative on failure
1665 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1669 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1670 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1673 "Allocation for Tx Queue %u failed\n", i
);
1674 for (i
-- ; i
>= 0; i
--)
1675 e1000_free_tx_resources(adapter
,
1676 &adapter
->tx_ring
[i
]);
1685 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1686 * @adapter: board private structure
1688 * Configure the Tx unit of the MAC after a reset.
1691 static void e1000_configure_tx(struct e1000_adapter
*adapter
)
1694 struct e1000_hw
*hw
= &adapter
->hw
;
1695 u32 tdlen
, tctl
, tipg
, tarc
;
1698 /* Setup the HW Tx Head and Tail descriptor pointers */
1700 switch (adapter
->num_tx_queues
) {
1703 tdba
= adapter
->tx_ring
[0].dma
;
1704 tdlen
= adapter
->tx_ring
[0].count
*
1705 sizeof(struct e1000_tx_desc
);
1707 ew32(TDBAH
, (tdba
>> 32));
1708 ew32(TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1711 adapter
->tx_ring
[0].tdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDH
: E1000_82542_TDH
);
1712 adapter
->tx_ring
[0].tdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDT
: E1000_82542_TDT
);
1716 /* Set the default values for the Tx Inter Packet Gap timer */
1717 if (hw
->mac_type
<= e1000_82547_rev_2
&&
1718 (hw
->media_type
== e1000_media_type_fiber
||
1719 hw
->media_type
== e1000_media_type_internal_serdes
))
1720 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1722 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1724 switch (hw
->mac_type
) {
1725 case e1000_82542_rev2_0
:
1726 case e1000_82542_rev2_1
:
1727 tipg
= DEFAULT_82542_TIPG_IPGT
;
1728 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
1729 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
1731 case e1000_80003es2lan
:
1732 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1733 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
;
1736 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1737 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
1740 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1741 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1744 /* Set the Tx Interrupt Delay register */
1746 ew32(TIDV
, adapter
->tx_int_delay
);
1747 if (hw
->mac_type
>= e1000_82540
)
1748 ew32(TADV
, adapter
->tx_abs_int_delay
);
1750 /* Program the Transmit Control Register */
1753 tctl
&= ~E1000_TCTL_CT
;
1754 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1755 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1757 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
1759 /* set the speed mode bit, we'll clear it if we're not at
1760 * gigabit link later */
1763 } else if (hw
->mac_type
== e1000_80003es2lan
) {
1772 e1000_config_collision_dist(hw
);
1774 /* Setup Transmit Descriptor Settings for eop descriptor */
1775 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
1777 /* only set IDE if we are delaying interrupts using the timers */
1778 if (adapter
->tx_int_delay
)
1779 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
1781 if (hw
->mac_type
< e1000_82543
)
1782 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1784 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1786 /* Cache if we're 82544 running in PCI-X because we'll
1787 * need this to apply a workaround later in the send path. */
1788 if (hw
->mac_type
== e1000_82544
&&
1789 hw
->bus_type
== e1000_bus_type_pcix
)
1790 adapter
->pcix_82544
= 1;
1797 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1798 * @adapter: board private structure
1799 * @rxdr: rx descriptor ring (for a specific queue) to setup
1801 * Returns 0 on success, negative on failure
1804 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1805 struct e1000_rx_ring
*rxdr
)
1807 struct e1000_hw
*hw
= &adapter
->hw
;
1808 struct pci_dev
*pdev
= adapter
->pdev
;
1811 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1812 rxdr
->buffer_info
= vmalloc(size
);
1813 if (!rxdr
->buffer_info
) {
1815 "Unable to allocate memory for the receive descriptor ring\n");
1818 memset(rxdr
->buffer_info
, 0, size
);
1820 if (hw
->mac_type
<= e1000_82547_rev_2
)
1821 desc_len
= sizeof(struct e1000_rx_desc
);
1823 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1825 /* Round up to nearest 4K */
1827 rxdr
->size
= rxdr
->count
* desc_len
;
1828 rxdr
->size
= ALIGN(rxdr
->size
, 4096);
1830 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1834 "Unable to allocate memory for the receive descriptor ring\n");
1836 vfree(rxdr
->buffer_info
);
1840 /* Fix for errata 23, can't cross 64kB boundary */
1841 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1842 void *olddesc
= rxdr
->desc
;
1843 dma_addr_t olddma
= rxdr
->dma
;
1844 DPRINTK(RX_ERR
, ERR
, "rxdr align check failed: %u bytes "
1845 "at %p\n", rxdr
->size
, rxdr
->desc
);
1846 /* Try again, without freeing the previous */
1847 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1848 /* Failed allocation, critical failure */
1850 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1852 "Unable to allocate memory "
1853 "for the receive descriptor ring\n");
1854 goto setup_rx_desc_die
;
1857 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1859 pci_free_consistent(pdev
, rxdr
->size
, rxdr
->desc
,
1861 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1863 "Unable to allocate aligned memory "
1864 "for the receive descriptor ring\n");
1865 goto setup_rx_desc_die
;
1867 /* Free old allocation, new allocation was successful */
1868 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1871 memset(rxdr
->desc
, 0, rxdr
->size
);
1873 rxdr
->next_to_clean
= 0;
1874 rxdr
->next_to_use
= 0;
1875 rxdr
->rx_skb_top
= NULL
;
1881 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1882 * (Descriptors) for all queues
1883 * @adapter: board private structure
1885 * Return 0 on success, negative on failure
1888 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1892 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1893 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1896 "Allocation for Rx Queue %u failed\n", i
);
1897 for (i
-- ; i
>= 0; i
--)
1898 e1000_free_rx_resources(adapter
,
1899 &adapter
->rx_ring
[i
]);
1908 * e1000_setup_rctl - configure the receive control registers
1909 * @adapter: Board private structure
1911 static void e1000_setup_rctl(struct e1000_adapter
*adapter
)
1913 struct e1000_hw
*hw
= &adapter
->hw
;
1918 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1920 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1921 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1922 (hw
->mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1924 if (hw
->tbi_compatibility_on
== 1)
1925 rctl
|= E1000_RCTL_SBP
;
1927 rctl
&= ~E1000_RCTL_SBP
;
1929 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1930 rctl
&= ~E1000_RCTL_LPE
;
1932 rctl
|= E1000_RCTL_LPE
;
1934 /* Setup buffer sizes */
1935 rctl
&= ~E1000_RCTL_SZ_4096
;
1936 rctl
|= E1000_RCTL_BSEX
;
1937 switch (adapter
->rx_buffer_len
) {
1938 case E1000_RXBUFFER_256
:
1939 rctl
|= E1000_RCTL_SZ_256
;
1940 rctl
&= ~E1000_RCTL_BSEX
;
1942 case E1000_RXBUFFER_512
:
1943 rctl
|= E1000_RCTL_SZ_512
;
1944 rctl
&= ~E1000_RCTL_BSEX
;
1946 case E1000_RXBUFFER_1024
:
1947 rctl
|= E1000_RCTL_SZ_1024
;
1948 rctl
&= ~E1000_RCTL_BSEX
;
1950 case E1000_RXBUFFER_2048
:
1952 rctl
|= E1000_RCTL_SZ_2048
;
1953 rctl
&= ~E1000_RCTL_BSEX
;
1955 case E1000_RXBUFFER_4096
:
1956 rctl
|= E1000_RCTL_SZ_4096
;
1958 case E1000_RXBUFFER_8192
:
1959 rctl
|= E1000_RCTL_SZ_8192
;
1961 case E1000_RXBUFFER_16384
:
1962 rctl
|= E1000_RCTL_SZ_16384
;
1970 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1971 * @adapter: board private structure
1973 * Configure the Rx unit of the MAC after a reset.
1976 static void e1000_configure_rx(struct e1000_adapter
*adapter
)
1979 struct e1000_hw
*hw
= &adapter
->hw
;
1980 u32 rdlen
, rctl
, rxcsum
, ctrl_ext
;
1982 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
1983 rdlen
= adapter
->rx_ring
[0].count
*
1984 sizeof(struct e1000_rx_desc
);
1985 adapter
->clean_rx
= e1000_clean_jumbo_rx_irq
;
1986 adapter
->alloc_rx_buf
= e1000_alloc_jumbo_rx_buffers
;
1988 rdlen
= adapter
->rx_ring
[0].count
*
1989 sizeof(struct e1000_rx_desc
);
1990 adapter
->clean_rx
= e1000_clean_rx_irq
;
1991 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1994 /* disable receives while setting up the descriptors */
1996 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1998 /* set the Receive Delay Timer Register */
1999 ew32(RDTR
, adapter
->rx_int_delay
);
2001 if (hw
->mac_type
>= e1000_82540
) {
2002 ew32(RADV
, adapter
->rx_abs_int_delay
);
2003 if (adapter
->itr_setting
!= 0)
2004 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
2007 if (hw
->mac_type
>= e1000_82571
) {
2008 ctrl_ext
= er32(CTRL_EXT
);
2009 /* Reset delay timers after every interrupt */
2010 ctrl_ext
|= E1000_CTRL_EXT_INT_TIMER_CLR
;
2011 /* Auto-Mask interrupts upon ICR access */
2012 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
2013 ew32(IAM
, 0xffffffff);
2014 ew32(CTRL_EXT
, ctrl_ext
);
2015 E1000_WRITE_FLUSH();
2018 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2019 * the Base and Length of the Rx Descriptor Ring */
2020 switch (adapter
->num_rx_queues
) {
2023 rdba
= adapter
->rx_ring
[0].dma
;
2025 ew32(RDBAH
, (rdba
>> 32));
2026 ew32(RDBAL
, (rdba
& 0x00000000ffffffffULL
));
2029 adapter
->rx_ring
[0].rdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDH
: E1000_82542_RDH
);
2030 adapter
->rx_ring
[0].rdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDT
: E1000_82542_RDT
);
2034 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2035 if (hw
->mac_type
>= e1000_82543
) {
2036 rxcsum
= er32(RXCSUM
);
2037 if (adapter
->rx_csum
)
2038 rxcsum
|= E1000_RXCSUM_TUOFL
;
2040 /* don't need to clear IPPCSE as it defaults to 0 */
2041 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
2042 ew32(RXCSUM
, rxcsum
);
2045 /* Enable Receives */
2050 * e1000_free_tx_resources - Free Tx Resources per Queue
2051 * @adapter: board private structure
2052 * @tx_ring: Tx descriptor ring for a specific queue
2054 * Free all transmit software resources
2057 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
2058 struct e1000_tx_ring
*tx_ring
)
2060 struct pci_dev
*pdev
= adapter
->pdev
;
2062 e1000_clean_tx_ring(adapter
, tx_ring
);
2064 vfree(tx_ring
->buffer_info
);
2065 tx_ring
->buffer_info
= NULL
;
2067 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
2069 tx_ring
->desc
= NULL
;
2073 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
2074 * @adapter: board private structure
2076 * Free all transmit software resources
2079 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
2083 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2084 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
2087 static void e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
2088 struct e1000_buffer
*buffer_info
)
2090 buffer_info
->dma
= 0;
2091 if (buffer_info
->skb
) {
2092 skb_dma_unmap(&adapter
->pdev
->dev
, buffer_info
->skb
,
2094 dev_kfree_skb_any(buffer_info
->skb
);
2095 buffer_info
->skb
= NULL
;
2097 buffer_info
->time_stamp
= 0;
2098 /* buffer_info must be completely set up in the transmit path */
2102 * e1000_clean_tx_ring - Free Tx Buffers
2103 * @adapter: board private structure
2104 * @tx_ring: ring to be cleaned
2107 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
2108 struct e1000_tx_ring
*tx_ring
)
2110 struct e1000_hw
*hw
= &adapter
->hw
;
2111 struct e1000_buffer
*buffer_info
;
2115 /* Free all the Tx ring sk_buffs */
2117 for (i
= 0; i
< tx_ring
->count
; i
++) {
2118 buffer_info
= &tx_ring
->buffer_info
[i
];
2119 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
2122 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
2123 memset(tx_ring
->buffer_info
, 0, size
);
2125 /* Zero out the descriptor ring */
2127 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2129 tx_ring
->next_to_use
= 0;
2130 tx_ring
->next_to_clean
= 0;
2131 tx_ring
->last_tx_tso
= 0;
2133 writel(0, hw
->hw_addr
+ tx_ring
->tdh
);
2134 writel(0, hw
->hw_addr
+ tx_ring
->tdt
);
2138 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2139 * @adapter: board private structure
2142 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
2146 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2147 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
2151 * e1000_free_rx_resources - Free Rx Resources
2152 * @adapter: board private structure
2153 * @rx_ring: ring to clean the resources from
2155 * Free all receive software resources
2158 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
2159 struct e1000_rx_ring
*rx_ring
)
2161 struct pci_dev
*pdev
= adapter
->pdev
;
2163 e1000_clean_rx_ring(adapter
, rx_ring
);
2165 vfree(rx_ring
->buffer_info
);
2166 rx_ring
->buffer_info
= NULL
;
2168 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
2170 rx_ring
->desc
= NULL
;
2174 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2175 * @adapter: board private structure
2177 * Free all receive software resources
2180 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
2184 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2185 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2189 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2190 * @adapter: board private structure
2191 * @rx_ring: ring to free buffers from
2194 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
2195 struct e1000_rx_ring
*rx_ring
)
2197 struct e1000_hw
*hw
= &adapter
->hw
;
2198 struct e1000_buffer
*buffer_info
;
2199 struct pci_dev
*pdev
= adapter
->pdev
;
2203 /* Free all the Rx ring sk_buffs */
2204 for (i
= 0; i
< rx_ring
->count
; i
++) {
2205 buffer_info
= &rx_ring
->buffer_info
[i
];
2206 if (buffer_info
->dma
&&
2207 adapter
->clean_rx
== e1000_clean_rx_irq
) {
2208 pci_unmap_single(pdev
, buffer_info
->dma
,
2209 buffer_info
->length
,
2210 PCI_DMA_FROMDEVICE
);
2211 } else if (buffer_info
->dma
&&
2212 adapter
->clean_rx
== e1000_clean_jumbo_rx_irq
) {
2213 pci_unmap_page(pdev
, buffer_info
->dma
,
2214 buffer_info
->length
,
2215 PCI_DMA_FROMDEVICE
);
2218 buffer_info
->dma
= 0;
2219 if (buffer_info
->page
) {
2220 put_page(buffer_info
->page
);
2221 buffer_info
->page
= NULL
;
2223 if (buffer_info
->skb
) {
2224 dev_kfree_skb(buffer_info
->skb
);
2225 buffer_info
->skb
= NULL
;
2229 /* there also may be some cached data from a chained receive */
2230 if (rx_ring
->rx_skb_top
) {
2231 dev_kfree_skb(rx_ring
->rx_skb_top
);
2232 rx_ring
->rx_skb_top
= NULL
;
2235 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2236 memset(rx_ring
->buffer_info
, 0, size
);
2238 /* Zero out the descriptor ring */
2239 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2241 rx_ring
->next_to_clean
= 0;
2242 rx_ring
->next_to_use
= 0;
2244 writel(0, hw
->hw_addr
+ rx_ring
->rdh
);
2245 writel(0, hw
->hw_addr
+ rx_ring
->rdt
);
2249 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2250 * @adapter: board private structure
2253 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2257 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2258 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2261 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2262 * and memory write and invalidate disabled for certain operations
2264 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2266 struct e1000_hw
*hw
= &adapter
->hw
;
2267 struct net_device
*netdev
= adapter
->netdev
;
2270 e1000_pci_clear_mwi(hw
);
2273 rctl
|= E1000_RCTL_RST
;
2275 E1000_WRITE_FLUSH();
2278 if (netif_running(netdev
))
2279 e1000_clean_all_rx_rings(adapter
);
2282 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2284 struct e1000_hw
*hw
= &adapter
->hw
;
2285 struct net_device
*netdev
= adapter
->netdev
;
2289 rctl
&= ~E1000_RCTL_RST
;
2291 E1000_WRITE_FLUSH();
2294 if (hw
->pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2295 e1000_pci_set_mwi(hw
);
2297 if (netif_running(netdev
)) {
2298 /* No need to loop, because 82542 supports only 1 queue */
2299 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[0];
2300 e1000_configure_rx(adapter
);
2301 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
2306 * e1000_set_mac - Change the Ethernet Address of the NIC
2307 * @netdev: network interface device structure
2308 * @p: pointer to an address structure
2310 * Returns 0 on success, negative on failure
2313 static int e1000_set_mac(struct net_device
*netdev
, void *p
)
2315 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2316 struct e1000_hw
*hw
= &adapter
->hw
;
2317 struct sockaddr
*addr
= p
;
2319 if (!is_valid_ether_addr(addr
->sa_data
))
2320 return -EADDRNOTAVAIL
;
2322 /* 82542 2.0 needs to be in reset to write receive address registers */
2324 if (hw
->mac_type
== e1000_82542_rev2_0
)
2325 e1000_enter_82542_rst(adapter
);
2327 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2328 memcpy(hw
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2330 e1000_rar_set(hw
, hw
->mac_addr
, 0);
2332 /* With 82571 controllers, LAA may be overwritten (with the default)
2333 * due to controller reset from the other port. */
2334 if (hw
->mac_type
== e1000_82571
) {
2335 /* activate the work around */
2336 hw
->laa_is_present
= 1;
2338 /* Hold a copy of the LAA in RAR[14] This is done so that
2339 * between the time RAR[0] gets clobbered and the time it
2340 * gets fixed (in e1000_watchdog), the actual LAA is in one
2341 * of the RARs and no incoming packets directed to this port
2342 * are dropped. Eventaully the LAA will be in RAR[0] and
2344 e1000_rar_set(hw
, hw
->mac_addr
,
2345 E1000_RAR_ENTRIES
- 1);
2348 if (hw
->mac_type
== e1000_82542_rev2_0
)
2349 e1000_leave_82542_rst(adapter
);
2355 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2356 * @netdev: network interface device structure
2358 * The set_rx_mode entry point is called whenever the unicast or multicast
2359 * address lists or the network interface flags are updated. This routine is
2360 * responsible for configuring the hardware for proper unicast, multicast,
2361 * promiscuous mode, and all-multi behavior.
2364 static void e1000_set_rx_mode(struct net_device
*netdev
)
2366 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2367 struct e1000_hw
*hw
= &adapter
->hw
;
2368 struct netdev_hw_addr
*ha
;
2369 bool use_uc
= false;
2370 struct dev_addr_list
*mc_ptr
;
2373 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2374 int mta_reg_count
= (hw
->mac_type
== e1000_ich8lan
) ?
2375 E1000_NUM_MTA_REGISTERS_ICH8LAN
:
2376 E1000_NUM_MTA_REGISTERS
;
2377 u32
*mcarray
= kcalloc(mta_reg_count
, sizeof(u32
), GFP_ATOMIC
);
2380 DPRINTK(PROBE
, ERR
, "memory allocation failed\n");
2384 if (hw
->mac_type
== e1000_ich8lan
)
2385 rar_entries
= E1000_RAR_ENTRIES_ICH8LAN
;
2387 /* reserve RAR[14] for LAA over-write work-around */
2388 if (hw
->mac_type
== e1000_82571
)
2391 /* Check for Promiscuous and All Multicast modes */
2395 if (netdev
->flags
& IFF_PROMISC
) {
2396 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2397 rctl
&= ~E1000_RCTL_VFE
;
2399 if (netdev
->flags
& IFF_ALLMULTI
) {
2400 rctl
|= E1000_RCTL_MPE
;
2402 rctl
&= ~E1000_RCTL_MPE
;
2404 if (adapter
->hw
.mac_type
!= e1000_ich8lan
)
2405 /* Enable VLAN filter if there is a VLAN */
2407 rctl
|= E1000_RCTL_VFE
;
2410 if (netdev
->uc
.count
> rar_entries
- 1) {
2411 rctl
|= E1000_RCTL_UPE
;
2412 } else if (!(netdev
->flags
& IFF_PROMISC
)) {
2413 rctl
&= ~E1000_RCTL_UPE
;
2419 /* 82542 2.0 needs to be in reset to write receive address registers */
2421 if (hw
->mac_type
== e1000_82542_rev2_0
)
2422 e1000_enter_82542_rst(adapter
);
2424 /* load the first 14 addresses into the exact filters 1-14. Unicast
2425 * addresses take precedence to avoid disabling unicast filtering
2428 * RAR 0 is used for the station MAC adddress
2429 * if there are not 14 addresses, go ahead and clear the filters
2430 * -- with 82571 controllers only 0-13 entries are filled here
2434 list_for_each_entry(ha
, &netdev
->uc
.list
, list
) {
2435 if (i
== rar_entries
)
2437 e1000_rar_set(hw
, ha
->addr
, i
++);
2440 WARN_ON(i
== rar_entries
);
2442 mc_ptr
= netdev
->mc_list
;
2444 for (; i
< rar_entries
; i
++) {
2446 e1000_rar_set(hw
, mc_ptr
->da_addr
, i
);
2447 mc_ptr
= mc_ptr
->next
;
2449 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2450 E1000_WRITE_FLUSH();
2451 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2452 E1000_WRITE_FLUSH();
2456 /* load any remaining addresses into the hash table */
2458 for (; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
2459 u32 hash_reg
, hash_bit
, mta
;
2460 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->da_addr
);
2461 hash_reg
= (hash_value
>> 5) & 0x7F;
2462 hash_bit
= hash_value
& 0x1F;
2463 mta
= (1 << hash_bit
);
2464 mcarray
[hash_reg
] |= mta
;
2467 /* write the hash table completely, write from bottom to avoid
2468 * both stupid write combining chipsets, and flushing each write */
2469 for (i
= mta_reg_count
- 1; i
>= 0 ; i
--) {
2471 * If we are on an 82544 has an errata where writing odd
2472 * offsets overwrites the previous even offset, but writing
2473 * backwards over the range solves the issue by always
2474 * writing the odd offset first
2476 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, mcarray
[i
]);
2478 E1000_WRITE_FLUSH();
2480 if (hw
->mac_type
== e1000_82542_rev2_0
)
2481 e1000_leave_82542_rst(adapter
);
2486 /* Need to wait a few seconds after link up to get diagnostic information from
2489 static void e1000_update_phy_info(unsigned long data
)
2491 struct e1000_adapter
*adapter
= (struct e1000_adapter
*)data
;
2492 struct e1000_hw
*hw
= &adapter
->hw
;
2493 e1000_phy_get_info(hw
, &adapter
->phy_info
);
2497 * e1000_82547_tx_fifo_stall - Timer Call-back
2498 * @data: pointer to adapter cast into an unsigned long
2501 static void e1000_82547_tx_fifo_stall(unsigned long data
)
2503 struct e1000_adapter
*adapter
= (struct e1000_adapter
*)data
;
2504 struct e1000_hw
*hw
= &adapter
->hw
;
2505 struct net_device
*netdev
= adapter
->netdev
;
2508 if (atomic_read(&adapter
->tx_fifo_stall
)) {
2509 if ((er32(TDT
) == er32(TDH
)) &&
2510 (er32(TDFT
) == er32(TDFH
)) &&
2511 (er32(TDFTS
) == er32(TDFHS
))) {
2513 ew32(TCTL
, tctl
& ~E1000_TCTL_EN
);
2514 ew32(TDFT
, adapter
->tx_head_addr
);
2515 ew32(TDFH
, adapter
->tx_head_addr
);
2516 ew32(TDFTS
, adapter
->tx_head_addr
);
2517 ew32(TDFHS
, adapter
->tx_head_addr
);
2519 E1000_WRITE_FLUSH();
2521 adapter
->tx_fifo_head
= 0;
2522 atomic_set(&adapter
->tx_fifo_stall
, 0);
2523 netif_wake_queue(netdev
);
2525 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2531 * e1000_watchdog - Timer Call-back
2532 * @data: pointer to adapter cast into an unsigned long
2534 static void e1000_watchdog(unsigned long data
)
2536 struct e1000_adapter
*adapter
= (struct e1000_adapter
*)data
;
2537 struct e1000_hw
*hw
= &adapter
->hw
;
2538 struct net_device
*netdev
= adapter
->netdev
;
2539 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2543 ret_val
= e1000_check_for_link(hw
);
2544 if ((ret_val
== E1000_ERR_PHY
) &&
2545 (hw
->phy_type
== e1000_phy_igp_3
) &&
2546 (er32(CTRL
) & E1000_PHY_CTRL_GBE_DISABLE
)) {
2547 /* See e1000_kumeran_lock_loss_workaround() */
2549 "Gigabit has been disabled, downgrading speed\n");
2552 if (hw
->mac_type
== e1000_82573
) {
2553 e1000_enable_tx_pkt_filtering(hw
);
2554 if (adapter
->mng_vlan_id
!= hw
->mng_cookie
.vlan_id
)
2555 e1000_update_mng_vlan(adapter
);
2558 if ((hw
->media_type
== e1000_media_type_internal_serdes
) &&
2559 !(er32(TXCW
) & E1000_TXCW_ANE
))
2560 link
= !hw
->serdes_link_down
;
2562 link
= er32(STATUS
) & E1000_STATUS_LU
;
2565 if (!netif_carrier_ok(netdev
)) {
2568 e1000_get_speed_and_duplex(hw
,
2569 &adapter
->link_speed
,
2570 &adapter
->link_duplex
);
2573 printk(KERN_INFO
"e1000: %s NIC Link is Up %d Mbps %s, "
2574 "Flow Control: %s\n",
2576 adapter
->link_speed
,
2577 adapter
->link_duplex
== FULL_DUPLEX
?
2578 "Full Duplex" : "Half Duplex",
2579 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
&
2580 E1000_CTRL_RFCE
)) ? "RX/TX" : ((ctrl
&
2581 E1000_CTRL_RFCE
) ? "RX" : ((ctrl
&
2582 E1000_CTRL_TFCE
) ? "TX" : "None" )));
2584 /* tweak tx_queue_len according to speed/duplex
2585 * and adjust the timeout factor */
2586 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2587 adapter
->tx_timeout_factor
= 1;
2588 switch (adapter
->link_speed
) {
2591 netdev
->tx_queue_len
= 10;
2592 adapter
->tx_timeout_factor
= 8;
2596 netdev
->tx_queue_len
= 100;
2597 /* maybe add some timeout factor ? */
2601 if ((hw
->mac_type
== e1000_82571
||
2602 hw
->mac_type
== e1000_82572
) &&
2605 tarc0
= er32(TARC0
);
2606 tarc0
&= ~(1 << 21);
2610 /* disable TSO for pcie and 10/100 speeds, to avoid
2611 * some hardware issues */
2612 if (!adapter
->tso_force
&&
2613 hw
->bus_type
== e1000_bus_type_pci_express
){
2614 switch (adapter
->link_speed
) {
2618 "10/100 speed: disabling TSO\n");
2619 netdev
->features
&= ~NETIF_F_TSO
;
2620 netdev
->features
&= ~NETIF_F_TSO6
;
2623 netdev
->features
|= NETIF_F_TSO
;
2624 netdev
->features
|= NETIF_F_TSO6
;
2632 /* enable transmits in the hardware, need to do this
2633 * after setting TARC0 */
2635 tctl
|= E1000_TCTL_EN
;
2638 netif_carrier_on(netdev
);
2639 mod_timer(&adapter
->phy_info_timer
, round_jiffies(jiffies
+ 2 * HZ
));
2640 adapter
->smartspeed
= 0;
2642 /* make sure the receive unit is started */
2643 if (hw
->rx_needs_kicking
) {
2644 u32 rctl
= er32(RCTL
);
2645 ew32(RCTL
, rctl
| E1000_RCTL_EN
);
2649 if (netif_carrier_ok(netdev
)) {
2650 adapter
->link_speed
= 0;
2651 adapter
->link_duplex
= 0;
2652 printk(KERN_INFO
"e1000: %s NIC Link is Down\n",
2654 netif_carrier_off(netdev
);
2655 mod_timer(&adapter
->phy_info_timer
, round_jiffies(jiffies
+ 2 * HZ
));
2657 /* 80003ES2LAN workaround--
2658 * For packet buffer work-around on link down event;
2659 * disable receives in the ISR and
2660 * reset device here in the watchdog
2662 if (hw
->mac_type
== e1000_80003es2lan
)
2664 schedule_work(&adapter
->reset_task
);
2667 e1000_smartspeed(adapter
);
2670 e1000_update_stats(adapter
);
2672 hw
->tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2673 adapter
->tpt_old
= adapter
->stats
.tpt
;
2674 hw
->collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2675 adapter
->colc_old
= adapter
->stats
.colc
;
2677 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2678 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2679 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2680 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2682 e1000_update_adaptive(hw
);
2684 if (!netif_carrier_ok(netdev
)) {
2685 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2686 /* We've lost link, so the controller stops DMA,
2687 * but we've got queued Tx work that's never going
2688 * to get done, so reset controller to flush Tx.
2689 * (Do the reset outside of interrupt context). */
2690 adapter
->tx_timeout_count
++;
2691 schedule_work(&adapter
->reset_task
);
2692 /* return immediately since reset is imminent */
2697 /* Cause software interrupt to ensure rx ring is cleaned */
2698 ew32(ICS
, E1000_ICS_RXDMT0
);
2700 /* Force detection of hung controller every watchdog period */
2701 adapter
->detect_tx_hung
= true;
2703 /* With 82571 controllers, LAA may be overwritten due to controller
2704 * reset from the other port. Set the appropriate LAA in RAR[0] */
2705 if (hw
->mac_type
== e1000_82571
&& hw
->laa_is_present
)
2706 e1000_rar_set(hw
, hw
->mac_addr
, 0);
2708 /* Reset the timer */
2709 mod_timer(&adapter
->watchdog_timer
, round_jiffies(jiffies
+ 2 * HZ
));
2712 enum latency_range
{
2716 latency_invalid
= 255
2720 * e1000_update_itr - update the dynamic ITR value based on statistics
2721 * Stores a new ITR value based on packets and byte
2722 * counts during the last interrupt. The advantage of per interrupt
2723 * computation is faster updates and more accurate ITR for the current
2724 * traffic pattern. Constants in this function were computed
2725 * based on theoretical maximum wire speed and thresholds were set based
2726 * on testing data as well as attempting to minimize response time
2727 * while increasing bulk throughput.
2728 * this functionality is controlled by the InterruptThrottleRate module
2729 * parameter (see e1000_param.c)
2730 * @adapter: pointer to adapter
2731 * @itr_setting: current adapter->itr
2732 * @packets: the number of packets during this measurement interval
2733 * @bytes: the number of bytes during this measurement interval
2735 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
2736 u16 itr_setting
, int packets
, int bytes
)
2738 unsigned int retval
= itr_setting
;
2739 struct e1000_hw
*hw
= &adapter
->hw
;
2741 if (unlikely(hw
->mac_type
< e1000_82540
))
2742 goto update_itr_done
;
2745 goto update_itr_done
;
2747 switch (itr_setting
) {
2748 case lowest_latency
:
2749 /* jumbo frames get bulk treatment*/
2750 if (bytes
/packets
> 8000)
2751 retval
= bulk_latency
;
2752 else if ((packets
< 5) && (bytes
> 512))
2753 retval
= low_latency
;
2755 case low_latency
: /* 50 usec aka 20000 ints/s */
2756 if (bytes
> 10000) {
2757 /* jumbo frames need bulk latency setting */
2758 if (bytes
/packets
> 8000)
2759 retval
= bulk_latency
;
2760 else if ((packets
< 10) || ((bytes
/packets
) > 1200))
2761 retval
= bulk_latency
;
2762 else if ((packets
> 35))
2763 retval
= lowest_latency
;
2764 } else if (bytes
/packets
> 2000)
2765 retval
= bulk_latency
;
2766 else if (packets
<= 2 && bytes
< 512)
2767 retval
= lowest_latency
;
2769 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2770 if (bytes
> 25000) {
2772 retval
= low_latency
;
2773 } else if (bytes
< 6000) {
2774 retval
= low_latency
;
2783 static void e1000_set_itr(struct e1000_adapter
*adapter
)
2785 struct e1000_hw
*hw
= &adapter
->hw
;
2787 u32 new_itr
= adapter
->itr
;
2789 if (unlikely(hw
->mac_type
< e1000_82540
))
2792 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2793 if (unlikely(adapter
->link_speed
!= SPEED_1000
)) {
2799 adapter
->tx_itr
= e1000_update_itr(adapter
,
2801 adapter
->total_tx_packets
,
2802 adapter
->total_tx_bytes
);
2803 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2804 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
2805 adapter
->tx_itr
= low_latency
;
2807 adapter
->rx_itr
= e1000_update_itr(adapter
,
2809 adapter
->total_rx_packets
,
2810 adapter
->total_rx_bytes
);
2811 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2812 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
2813 adapter
->rx_itr
= low_latency
;
2815 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2817 switch (current_itr
) {
2818 /* counts and packets in update_itr are dependent on these numbers */
2819 case lowest_latency
:
2823 new_itr
= 20000; /* aka hwitr = ~200 */
2833 if (new_itr
!= adapter
->itr
) {
2834 /* this attempts to bias the interrupt rate towards Bulk
2835 * by adding intermediate steps when interrupt rate is
2837 new_itr
= new_itr
> adapter
->itr
?
2838 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2840 adapter
->itr
= new_itr
;
2841 ew32(ITR
, 1000000000 / (new_itr
* 256));
2847 #define E1000_TX_FLAGS_CSUM 0x00000001
2848 #define E1000_TX_FLAGS_VLAN 0x00000002
2849 #define E1000_TX_FLAGS_TSO 0x00000004
2850 #define E1000_TX_FLAGS_IPV4 0x00000008
2851 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2852 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2854 static int e1000_tso(struct e1000_adapter
*adapter
,
2855 struct e1000_tx_ring
*tx_ring
, struct sk_buff
*skb
)
2857 struct e1000_context_desc
*context_desc
;
2858 struct e1000_buffer
*buffer_info
;
2861 u16 ipcse
= 0, tucse
, mss
;
2862 u8 ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2865 if (skb_is_gso(skb
)) {
2866 if (skb_header_cloned(skb
)) {
2867 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2872 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2873 mss
= skb_shinfo(skb
)->gso_size
;
2874 if (skb
->protocol
== htons(ETH_P_IP
)) {
2875 struct iphdr
*iph
= ip_hdr(skb
);
2878 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2882 cmd_length
= E1000_TXD_CMD_IP
;
2883 ipcse
= skb_transport_offset(skb
) - 1;
2884 } else if (skb
->protocol
== htons(ETH_P_IPV6
)) {
2885 ipv6_hdr(skb
)->payload_len
= 0;
2886 tcp_hdr(skb
)->check
=
2887 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2888 &ipv6_hdr(skb
)->daddr
,
2892 ipcss
= skb_network_offset(skb
);
2893 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
2894 tucss
= skb_transport_offset(skb
);
2895 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
2898 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2899 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2901 i
= tx_ring
->next_to_use
;
2902 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2903 buffer_info
= &tx_ring
->buffer_info
[i
];
2905 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2906 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2907 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2908 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2909 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2910 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2911 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2912 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2913 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2915 buffer_info
->time_stamp
= jiffies
;
2916 buffer_info
->next_to_watch
= i
;
2918 if (++i
== tx_ring
->count
) i
= 0;
2919 tx_ring
->next_to_use
= i
;
2926 static bool e1000_tx_csum(struct e1000_adapter
*adapter
,
2927 struct e1000_tx_ring
*tx_ring
, struct sk_buff
*skb
)
2929 struct e1000_context_desc
*context_desc
;
2930 struct e1000_buffer
*buffer_info
;
2933 u32 cmd_len
= E1000_TXD_CMD_DEXT
;
2935 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
2938 switch (skb
->protocol
) {
2939 case cpu_to_be16(ETH_P_IP
):
2940 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
2941 cmd_len
|= E1000_TXD_CMD_TCP
;
2943 case cpu_to_be16(ETH_P_IPV6
):
2944 /* XXX not handling all IPV6 headers */
2945 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
2946 cmd_len
|= E1000_TXD_CMD_TCP
;
2949 if (unlikely(net_ratelimit()))
2950 DPRINTK(DRV
, WARNING
,
2951 "checksum_partial proto=%x!\n", skb
->protocol
);
2955 css
= skb_transport_offset(skb
);
2957 i
= tx_ring
->next_to_use
;
2958 buffer_info
= &tx_ring
->buffer_info
[i
];
2959 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2961 context_desc
->lower_setup
.ip_config
= 0;
2962 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2963 context_desc
->upper_setup
.tcp_fields
.tucso
=
2964 css
+ skb
->csum_offset
;
2965 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2966 context_desc
->tcp_seg_setup
.data
= 0;
2967 context_desc
->cmd_and_length
= cpu_to_le32(cmd_len
);
2969 buffer_info
->time_stamp
= jiffies
;
2970 buffer_info
->next_to_watch
= i
;
2972 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2973 tx_ring
->next_to_use
= i
;
2978 #define E1000_MAX_TXD_PWR 12
2979 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2981 static int e1000_tx_map(struct e1000_adapter
*adapter
,
2982 struct e1000_tx_ring
*tx_ring
,
2983 struct sk_buff
*skb
, unsigned int first
,
2984 unsigned int max_per_txd
, unsigned int nr_frags
,
2987 struct e1000_hw
*hw
= &adapter
->hw
;
2988 struct e1000_buffer
*buffer_info
;
2989 unsigned int len
= skb_headlen(skb
);
2990 unsigned int offset
, size
, count
= 0, i
;
2994 i
= tx_ring
->next_to_use
;
2996 if (skb_dma_map(&adapter
->pdev
->dev
, skb
, DMA_TO_DEVICE
)) {
2997 dev_err(&adapter
->pdev
->dev
, "TX DMA map failed\n");
3001 map
= skb_shinfo(skb
)->dma_maps
;
3005 buffer_info
= &tx_ring
->buffer_info
[i
];
3006 size
= min(len
, max_per_txd
);
3007 /* Workaround for Controller erratum --
3008 * descriptor for non-tso packet in a linear SKB that follows a
3009 * tso gets written back prematurely before the data is fully
3010 * DMA'd to the controller */
3011 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
3013 tx_ring
->last_tx_tso
= 0;
3017 /* Workaround for premature desc write-backs
3018 * in TSO mode. Append 4-byte sentinel desc */
3019 if (unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
3021 /* work-around for errata 10 and it applies
3022 * to all controllers in PCI-X mode
3023 * The fix is to make sure that the first descriptor of a
3024 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3026 if (unlikely((hw
->bus_type
== e1000_bus_type_pcix
) &&
3027 (size
> 2015) && count
== 0))
3030 /* Workaround for potential 82544 hang in PCI-X. Avoid
3031 * terminating buffers within evenly-aligned dwords. */
3032 if (unlikely(adapter
->pcix_82544
&&
3033 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
3037 buffer_info
->length
= size
;
3038 buffer_info
->dma
= skb_shinfo(skb
)->dma_head
+ offset
;
3039 buffer_info
->time_stamp
= jiffies
;
3040 buffer_info
->next_to_watch
= i
;
3047 if (unlikely(i
== tx_ring
->count
))
3052 for (f
= 0; f
< nr_frags
; f
++) {
3053 struct skb_frag_struct
*frag
;
3055 frag
= &skb_shinfo(skb
)->frags
[f
];
3061 if (unlikely(i
== tx_ring
->count
))
3064 buffer_info
= &tx_ring
->buffer_info
[i
];
3065 size
= min(len
, max_per_txd
);
3066 /* Workaround for premature desc write-backs
3067 * in TSO mode. Append 4-byte sentinel desc */
3068 if (unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
3070 /* Workaround for potential 82544 hang in PCI-X.
3071 * Avoid terminating buffers within evenly-aligned
3073 if (unlikely(adapter
->pcix_82544
&&
3074 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
3078 buffer_info
->length
= size
;
3079 buffer_info
->dma
= map
[f
] + offset
;
3080 buffer_info
->time_stamp
= jiffies
;
3081 buffer_info
->next_to_watch
= i
;
3089 tx_ring
->buffer_info
[i
].skb
= skb
;
3090 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
3095 static void e1000_tx_queue(struct e1000_adapter
*adapter
,
3096 struct e1000_tx_ring
*tx_ring
, int tx_flags
,
3099 struct e1000_hw
*hw
= &adapter
->hw
;
3100 struct e1000_tx_desc
*tx_desc
= NULL
;
3101 struct e1000_buffer
*buffer_info
;
3102 u32 txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
3105 if (likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
3106 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
3108 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3110 if (likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
3111 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
3114 if (likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
3115 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
3116 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3119 if (unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
3120 txd_lower
|= E1000_TXD_CMD_VLE
;
3121 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
3124 i
= tx_ring
->next_to_use
;
3127 buffer_info
= &tx_ring
->buffer_info
[i
];
3128 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3129 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3130 tx_desc
->lower
.data
=
3131 cpu_to_le32(txd_lower
| buffer_info
->length
);
3132 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
3133 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3136 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
3138 /* Force memory writes to complete before letting h/w
3139 * know there are new descriptors to fetch. (Only
3140 * applicable for weak-ordered memory model archs,
3141 * such as IA-64). */
3144 tx_ring
->next_to_use
= i
;
3145 writel(i
, hw
->hw_addr
+ tx_ring
->tdt
);
3146 /* we need this if more than one processor can write to our tail
3147 * at a time, it syncronizes IO on IA64/Altix systems */
3152 * 82547 workaround to avoid controller hang in half-duplex environment.
3153 * The workaround is to avoid queuing a large packet that would span
3154 * the internal Tx FIFO ring boundary by notifying the stack to resend
3155 * the packet at a later time. This gives the Tx FIFO an opportunity to
3156 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3157 * to the beginning of the Tx FIFO.
3160 #define E1000_FIFO_HDR 0x10
3161 #define E1000_82547_PAD_LEN 0x3E0
3163 static int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
3164 struct sk_buff
*skb
)
3166 u32 fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
3167 u32 skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
3169 skb_fifo_len
= ALIGN(skb_fifo_len
, E1000_FIFO_HDR
);
3171 if (adapter
->link_duplex
!= HALF_DUPLEX
)
3172 goto no_fifo_stall_required
;
3174 if (atomic_read(&adapter
->tx_fifo_stall
))
3177 if (skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
3178 atomic_set(&adapter
->tx_fifo_stall
, 1);
3182 no_fifo_stall_required
:
3183 adapter
->tx_fifo_head
+= skb_fifo_len
;
3184 if (adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
3185 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
3189 #define MINIMUM_DHCP_PACKET_SIZE 282
3190 static int e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
,
3191 struct sk_buff
*skb
)
3193 struct e1000_hw
*hw
= &adapter
->hw
;
3195 if (vlan_tx_tag_present(skb
)) {
3196 if (!((vlan_tx_tag_get(skb
) == hw
->mng_cookie
.vlan_id
) &&
3197 ( hw
->mng_cookie
.status
&
3198 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) )
3201 if (skb
->len
> MINIMUM_DHCP_PACKET_SIZE
) {
3202 struct ethhdr
*eth
= (struct ethhdr
*)skb
->data
;
3203 if ((htons(ETH_P_IP
) == eth
->h_proto
)) {
3204 const struct iphdr
*ip
=
3205 (struct iphdr
*)((u8
*)skb
->data
+14);
3206 if (IPPROTO_UDP
== ip
->protocol
) {
3207 struct udphdr
*udp
=
3208 (struct udphdr
*)((u8
*)ip
+
3210 if (ntohs(udp
->dest
) == 67) {
3211 offset
= (u8
*)udp
+ 8 - skb
->data
;
3212 length
= skb
->len
- offset
;
3214 return e1000_mng_write_dhcp_info(hw
,
3224 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
3226 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3227 struct e1000_tx_ring
*tx_ring
= adapter
->tx_ring
;
3229 netif_stop_queue(netdev
);
3230 /* Herbert's original patch had:
3231 * smp_mb__after_netif_stop_queue();
3232 * but since that doesn't exist yet, just open code it. */
3235 /* We need to check again in a case another CPU has just
3236 * made room available. */
3237 if (likely(E1000_DESC_UNUSED(tx_ring
) < size
))
3241 netif_start_queue(netdev
);
3242 ++adapter
->restart_queue
;
3246 static int e1000_maybe_stop_tx(struct net_device
*netdev
,
3247 struct e1000_tx_ring
*tx_ring
, int size
)
3249 if (likely(E1000_DESC_UNUSED(tx_ring
) >= size
))
3251 return __e1000_maybe_stop_tx(netdev
, size
);
3254 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3255 static netdev_tx_t
e1000_xmit_frame(struct sk_buff
*skb
,
3256 struct net_device
*netdev
)
3258 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3259 struct e1000_hw
*hw
= &adapter
->hw
;
3260 struct e1000_tx_ring
*tx_ring
;
3261 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
3262 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
3263 unsigned int tx_flags
= 0;
3264 unsigned int len
= skb
->len
- skb
->data_len
;
3265 unsigned int nr_frags
;
3271 /* This goes back to the question of how to logically map a tx queue
3272 * to a flow. Right now, performance is impacted slightly negatively
3273 * if using multiple tx queues. If the stack breaks away from a
3274 * single qdisc implementation, we can look at this again. */
3275 tx_ring
= adapter
->tx_ring
;
3277 if (unlikely(skb
->len
<= 0)) {
3278 dev_kfree_skb_any(skb
);
3279 return NETDEV_TX_OK
;
3282 /* 82571 and newer doesn't need the workaround that limited descriptor
3284 if (hw
->mac_type
>= e1000_82571
)
3287 mss
= skb_shinfo(skb
)->gso_size
;
3288 /* The controller does a simple calculation to
3289 * make sure there is enough room in the FIFO before
3290 * initiating the DMA for each buffer. The calc is:
3291 * 4 = ceil(buffer len/mss). To make sure we don't
3292 * overrun the FIFO, adjust the max buffer len if mss
3296 max_per_txd
= min(mss
<< 2, max_per_txd
);
3297 max_txd_pwr
= fls(max_per_txd
) - 1;
3299 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3300 * points to just header, pull a few bytes of payload from
3301 * frags into skb->data */
3302 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
3303 if (skb
->data_len
&& hdr_len
== len
) {
3304 switch (hw
->mac_type
) {
3305 unsigned int pull_size
;
3307 /* Make sure we have room to chop off 4 bytes,
3308 * and that the end alignment will work out to
3309 * this hardware's requirements
3310 * NOTE: this is a TSO only workaround
3311 * if end byte alignment not correct move us
3312 * into the next dword */
3313 if ((unsigned long)(skb_tail_pointer(skb
) - 1) & 4)
3320 pull_size
= min((unsigned int)4, skb
->data_len
);
3321 if (!__pskb_pull_tail(skb
, pull_size
)) {
3323 "__pskb_pull_tail failed.\n");
3324 dev_kfree_skb_any(skb
);
3325 return NETDEV_TX_OK
;
3327 len
= skb
->len
- skb
->data_len
;
3336 /* reserve a descriptor for the offload context */
3337 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3341 /* Controller Erratum workaround */
3342 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&& !skb_is_gso(skb
))
3345 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
3347 if (adapter
->pcix_82544
)
3350 /* work-around for errata 10 and it applies to all controllers
3351 * in PCI-X mode, so add one more descriptor to the count
3353 if (unlikely((hw
->bus_type
== e1000_bus_type_pcix
) &&
3357 nr_frags
= skb_shinfo(skb
)->nr_frags
;
3358 for (f
= 0; f
< nr_frags
; f
++)
3359 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
3361 if (adapter
->pcix_82544
)
3365 if (hw
->tx_pkt_filtering
&&
3366 (hw
->mac_type
== e1000_82573
))
3367 e1000_transfer_dhcp_info(adapter
, skb
);
3369 /* need: count + 2 desc gap to keep tail from touching
3370 * head, otherwise try next time */
3371 if (unlikely(e1000_maybe_stop_tx(netdev
, tx_ring
, count
+ 2)))
3372 return NETDEV_TX_BUSY
;
3374 if (unlikely(hw
->mac_type
== e1000_82547
)) {
3375 if (unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
3376 netif_stop_queue(netdev
);
3377 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
3378 return NETDEV_TX_BUSY
;
3382 if (unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
3383 tx_flags
|= E1000_TX_FLAGS_VLAN
;
3384 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
3387 first
= tx_ring
->next_to_use
;
3389 tso
= e1000_tso(adapter
, tx_ring
, skb
);
3391 dev_kfree_skb_any(skb
);
3392 return NETDEV_TX_OK
;
3396 tx_ring
->last_tx_tso
= 1;
3397 tx_flags
|= E1000_TX_FLAGS_TSO
;
3398 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
3399 tx_flags
|= E1000_TX_FLAGS_CSUM
;
3401 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3402 * 82571 hardware supports TSO capabilities for IPv6 as well...
3403 * no longer assume, we must. */
3404 if (likely(skb
->protocol
== htons(ETH_P_IP
)))
3405 tx_flags
|= E1000_TX_FLAGS_IPV4
;
3407 count
= e1000_tx_map(adapter
, tx_ring
, skb
, first
, max_per_txd
,
3411 e1000_tx_queue(adapter
, tx_ring
, tx_flags
, count
);
3412 /* Make sure there is space in the ring for the next send. */
3413 e1000_maybe_stop_tx(netdev
, tx_ring
, MAX_SKB_FRAGS
+ 2);
3416 dev_kfree_skb_any(skb
);
3417 tx_ring
->buffer_info
[first
].time_stamp
= 0;
3418 tx_ring
->next_to_use
= first
;
3421 return NETDEV_TX_OK
;
3425 * e1000_tx_timeout - Respond to a Tx Hang
3426 * @netdev: network interface device structure
3429 static void e1000_tx_timeout(struct net_device
*netdev
)
3431 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3433 /* Do the reset outside of interrupt context */
3434 adapter
->tx_timeout_count
++;
3435 schedule_work(&adapter
->reset_task
);
3438 static void e1000_reset_task(struct work_struct
*work
)
3440 struct e1000_adapter
*adapter
=
3441 container_of(work
, struct e1000_adapter
, reset_task
);
3443 e1000_reinit_locked(adapter
);
3447 * e1000_get_stats - Get System Network Statistics
3448 * @netdev: network interface device structure
3450 * Returns the address of the device statistics structure.
3451 * The statistics are actually updated from the timer callback.
3454 static struct net_device_stats
*e1000_get_stats(struct net_device
*netdev
)
3456 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3458 /* only return the current stats */
3459 return &adapter
->net_stats
;
3463 * e1000_change_mtu - Change the Maximum Transfer Unit
3464 * @netdev: network interface device structure
3465 * @new_mtu: new value for maximum frame size
3467 * Returns 0 on success, negative on failure
3470 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3472 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3473 struct e1000_hw
*hw
= &adapter
->hw
;
3474 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
3475 u16 eeprom_data
= 0;
3477 if ((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
3478 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3479 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
3483 /* Adapter-specific max frame size limits. */
3484 switch (hw
->mac_type
) {
3485 case e1000_undefined
... e1000_82542_rev2_1
:
3487 if (max_frame
> (ETH_FRAME_LEN
+ ETH_FCS_LEN
)) {
3488 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported.\n");
3493 /* Jumbo Frames not supported if:
3494 * - this is not an 82573L device
3495 * - ASPM is enabled in any way (0x1A bits 3:2) */
3496 e1000_read_eeprom(hw
, EEPROM_INIT_3GIO_3
, 1,
3498 if ((hw
->device_id
!= E1000_DEV_ID_82573L
) ||
3499 (eeprom_data
& EEPROM_WORD1A_ASPM_MASK
)) {
3500 if (max_frame
> (ETH_FRAME_LEN
+ ETH_FCS_LEN
)) {
3502 "Jumbo Frames not supported.\n");
3507 /* ERT will be enabled later to enable wire speed receives */
3509 /* fall through to get support */
3512 case e1000_80003es2lan
:
3513 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3514 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3515 DPRINTK(PROBE
, ERR
, "MTU > 9216 not supported.\n");
3520 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3524 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3525 * means we reserve 2 more, this pushes us to allocate from the next
3527 * i.e. RXBUFFER_2048 --> size-4096 slab
3528 * however with the new *_jumbo_rx* routines, jumbo receives will use
3529 * fragmented skbs */
3531 if (max_frame
<= E1000_RXBUFFER_256
)
3532 adapter
->rx_buffer_len
= E1000_RXBUFFER_256
;
3533 else if (max_frame
<= E1000_RXBUFFER_512
)
3534 adapter
->rx_buffer_len
= E1000_RXBUFFER_512
;
3535 else if (max_frame
<= E1000_RXBUFFER_1024
)
3536 adapter
->rx_buffer_len
= E1000_RXBUFFER_1024
;
3537 else if (max_frame
<= E1000_RXBUFFER_2048
)
3538 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3540 #if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3541 adapter
->rx_buffer_len
= E1000_RXBUFFER_16384
;
3542 #elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3543 adapter
->rx_buffer_len
= PAGE_SIZE
;
3546 /* adjust allocation if LPE protects us, and we aren't using SBP */
3547 if (!hw
->tbi_compatibility_on
&&
3548 ((max_frame
== (ETH_FRAME_LEN
+ ETH_FCS_LEN
)) ||
3549 (max_frame
== MAXIMUM_ETHERNET_VLAN_SIZE
)))
3550 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3552 netdev
->mtu
= new_mtu
;
3553 hw
->max_frame_size
= max_frame
;
3555 if (netif_running(netdev
))
3556 e1000_reinit_locked(adapter
);
3562 * e1000_update_stats - Update the board statistics counters
3563 * @adapter: board private structure
3566 void e1000_update_stats(struct e1000_adapter
*adapter
)
3568 struct e1000_hw
*hw
= &adapter
->hw
;
3569 struct pci_dev
*pdev
= adapter
->pdev
;
3570 unsigned long flags
;
3573 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3576 * Prevent stats update while adapter is being reset, or if the pci
3577 * connection is down.
3579 if (adapter
->link_speed
== 0)
3581 if (pci_channel_offline(pdev
))
3584 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3586 /* these counters are modified from e1000_tbi_adjust_stats,
3587 * called from the interrupt context, so they must only
3588 * be written while holding adapter->stats_lock
3591 adapter
->stats
.crcerrs
+= er32(CRCERRS
);
3592 adapter
->stats
.gprc
+= er32(GPRC
);
3593 adapter
->stats
.gorcl
+= er32(GORCL
);
3594 adapter
->stats
.gorch
+= er32(GORCH
);
3595 adapter
->stats
.bprc
+= er32(BPRC
);
3596 adapter
->stats
.mprc
+= er32(MPRC
);
3597 adapter
->stats
.roc
+= er32(ROC
);
3599 if (hw
->mac_type
!= e1000_ich8lan
) {
3600 adapter
->stats
.prc64
+= er32(PRC64
);
3601 adapter
->stats
.prc127
+= er32(PRC127
);
3602 adapter
->stats
.prc255
+= er32(PRC255
);
3603 adapter
->stats
.prc511
+= er32(PRC511
);
3604 adapter
->stats
.prc1023
+= er32(PRC1023
);
3605 adapter
->stats
.prc1522
+= er32(PRC1522
);
3608 adapter
->stats
.symerrs
+= er32(SYMERRS
);
3609 adapter
->stats
.mpc
+= er32(MPC
);
3610 adapter
->stats
.scc
+= er32(SCC
);
3611 adapter
->stats
.ecol
+= er32(ECOL
);
3612 adapter
->stats
.mcc
+= er32(MCC
);
3613 adapter
->stats
.latecol
+= er32(LATECOL
);
3614 adapter
->stats
.dc
+= er32(DC
);
3615 adapter
->stats
.sec
+= er32(SEC
);
3616 adapter
->stats
.rlec
+= er32(RLEC
);
3617 adapter
->stats
.xonrxc
+= er32(XONRXC
);
3618 adapter
->stats
.xontxc
+= er32(XONTXC
);
3619 adapter
->stats
.xoffrxc
+= er32(XOFFRXC
);
3620 adapter
->stats
.xofftxc
+= er32(XOFFTXC
);
3621 adapter
->stats
.fcruc
+= er32(FCRUC
);
3622 adapter
->stats
.gptc
+= er32(GPTC
);
3623 adapter
->stats
.gotcl
+= er32(GOTCL
);
3624 adapter
->stats
.gotch
+= er32(GOTCH
);
3625 adapter
->stats
.rnbc
+= er32(RNBC
);
3626 adapter
->stats
.ruc
+= er32(RUC
);
3627 adapter
->stats
.rfc
+= er32(RFC
);
3628 adapter
->stats
.rjc
+= er32(RJC
);
3629 adapter
->stats
.torl
+= er32(TORL
);
3630 adapter
->stats
.torh
+= er32(TORH
);
3631 adapter
->stats
.totl
+= er32(TOTL
);
3632 adapter
->stats
.toth
+= er32(TOTH
);
3633 adapter
->stats
.tpr
+= er32(TPR
);
3635 if (hw
->mac_type
!= e1000_ich8lan
) {
3636 adapter
->stats
.ptc64
+= er32(PTC64
);
3637 adapter
->stats
.ptc127
+= er32(PTC127
);
3638 adapter
->stats
.ptc255
+= er32(PTC255
);
3639 adapter
->stats
.ptc511
+= er32(PTC511
);
3640 adapter
->stats
.ptc1023
+= er32(PTC1023
);
3641 adapter
->stats
.ptc1522
+= er32(PTC1522
);
3644 adapter
->stats
.mptc
+= er32(MPTC
);
3645 adapter
->stats
.bptc
+= er32(BPTC
);
3647 /* used for adaptive IFS */
3649 hw
->tx_packet_delta
= er32(TPT
);
3650 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3651 hw
->collision_delta
= er32(COLC
);
3652 adapter
->stats
.colc
+= hw
->collision_delta
;
3654 if (hw
->mac_type
>= e1000_82543
) {
3655 adapter
->stats
.algnerrc
+= er32(ALGNERRC
);
3656 adapter
->stats
.rxerrc
+= er32(RXERRC
);
3657 adapter
->stats
.tncrs
+= er32(TNCRS
);
3658 adapter
->stats
.cexterr
+= er32(CEXTERR
);
3659 adapter
->stats
.tsctc
+= er32(TSCTC
);
3660 adapter
->stats
.tsctfc
+= er32(TSCTFC
);
3662 if (hw
->mac_type
> e1000_82547_rev_2
) {
3663 adapter
->stats
.iac
+= er32(IAC
);
3664 adapter
->stats
.icrxoc
+= er32(ICRXOC
);
3666 if (hw
->mac_type
!= e1000_ich8lan
) {
3667 adapter
->stats
.icrxptc
+= er32(ICRXPTC
);
3668 adapter
->stats
.icrxatc
+= er32(ICRXATC
);
3669 adapter
->stats
.ictxptc
+= er32(ICTXPTC
);
3670 adapter
->stats
.ictxatc
+= er32(ICTXATC
);
3671 adapter
->stats
.ictxqec
+= er32(ICTXQEC
);
3672 adapter
->stats
.ictxqmtc
+= er32(ICTXQMTC
);
3673 adapter
->stats
.icrxdmtc
+= er32(ICRXDMTC
);
3677 /* Fill out the OS statistics structure */
3678 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3679 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3683 /* RLEC on some newer hardware can be incorrect so build
3684 * our own version based on RUC and ROC */
3685 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3686 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3687 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3688 adapter
->stats
.cexterr
;
3689 adapter
->stats
.rlerrc
= adapter
->stats
.ruc
+ adapter
->stats
.roc
;
3690 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlerrc
;
3691 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3692 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3693 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3696 adapter
->stats
.txerrc
= adapter
->stats
.ecol
+ adapter
->stats
.latecol
;
3697 adapter
->net_stats
.tx_errors
= adapter
->stats
.txerrc
;
3698 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3699 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3700 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3701 if (hw
->bad_tx_carr_stats_fd
&&
3702 adapter
->link_duplex
== FULL_DUPLEX
) {
3703 adapter
->net_stats
.tx_carrier_errors
= 0;
3704 adapter
->stats
.tncrs
= 0;
3707 /* Tx Dropped needs to be maintained elsewhere */
3710 if (hw
->media_type
== e1000_media_type_copper
) {
3711 if ((adapter
->link_speed
== SPEED_1000
) &&
3712 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3713 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3714 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3717 if ((hw
->mac_type
<= e1000_82546
) &&
3718 (hw
->phy_type
== e1000_phy_m88
) &&
3719 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3720 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3723 /* Management Stats */
3724 if (hw
->has_smbus
) {
3725 adapter
->stats
.mgptc
+= er32(MGTPTC
);
3726 adapter
->stats
.mgprc
+= er32(MGTPRC
);
3727 adapter
->stats
.mgpdc
+= er32(MGTPDC
);
3730 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3734 * e1000_intr_msi - Interrupt Handler
3735 * @irq: interrupt number
3736 * @data: pointer to a network interface device structure
3739 static irqreturn_t
e1000_intr_msi(int irq
, void *data
)
3741 struct net_device
*netdev
= data
;
3742 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3743 struct e1000_hw
*hw
= &adapter
->hw
;
3744 u32 icr
= er32(ICR
);
3746 /* in NAPI mode read ICR disables interrupts using IAM */
3748 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
3749 hw
->get_link_status
= 1;
3750 /* 80003ES2LAN workaround-- For packet buffer work-around on
3751 * link down event; disable receives here in the ISR and reset
3752 * adapter in watchdog */
3753 if (netif_carrier_ok(netdev
) &&
3754 (hw
->mac_type
== e1000_80003es2lan
)) {
3755 /* disable receives */
3756 u32 rctl
= er32(RCTL
);
3757 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
3759 /* guard against interrupt when we're going down */
3760 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3761 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3764 if (likely(napi_schedule_prep(&adapter
->napi
))) {
3765 adapter
->total_tx_bytes
= 0;
3766 adapter
->total_tx_packets
= 0;
3767 adapter
->total_rx_bytes
= 0;
3768 adapter
->total_rx_packets
= 0;
3769 __napi_schedule(&adapter
->napi
);
3771 e1000_irq_enable(adapter
);
3777 * e1000_intr - Interrupt Handler
3778 * @irq: interrupt number
3779 * @data: pointer to a network interface device structure
3782 static irqreturn_t
e1000_intr(int irq
, void *data
)
3784 struct net_device
*netdev
= data
;
3785 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3786 struct e1000_hw
*hw
= &adapter
->hw
;
3787 u32 rctl
, icr
= er32(ICR
);
3789 if (unlikely((!icr
) || test_bit(__E1000_DOWN
, &adapter
->flags
)))
3790 return IRQ_NONE
; /* Not our interrupt */
3792 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3793 * not set, then the adapter didn't send an interrupt */
3794 if (unlikely(hw
->mac_type
>= e1000_82571
&&
3795 !(icr
& E1000_ICR_INT_ASSERTED
)))
3798 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3799 * need for the IMC write */
3801 if (unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3802 hw
->get_link_status
= 1;
3803 /* 80003ES2LAN workaround--
3804 * For packet buffer work-around on link down event;
3805 * disable receives here in the ISR and
3806 * reset adapter in watchdog
3808 if (netif_carrier_ok(netdev
) &&
3809 (hw
->mac_type
== e1000_80003es2lan
)) {
3810 /* disable receives */
3812 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
3814 /* guard against interrupt when we're going down */
3815 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3816 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3819 if (unlikely(hw
->mac_type
< e1000_82571
)) {
3820 /* disable interrupts, without the synchronize_irq bit */
3822 E1000_WRITE_FLUSH();
3824 if (likely(napi_schedule_prep(&adapter
->napi
))) {
3825 adapter
->total_tx_bytes
= 0;
3826 adapter
->total_tx_packets
= 0;
3827 adapter
->total_rx_bytes
= 0;
3828 adapter
->total_rx_packets
= 0;
3829 __napi_schedule(&adapter
->napi
);
3831 /* this really should not happen! if it does it is basically a
3832 * bug, but not a hard error, so enable ints and continue */
3833 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3834 e1000_irq_enable(adapter
);
3841 * e1000_clean - NAPI Rx polling callback
3842 * @adapter: board private structure
3844 static int e1000_clean(struct napi_struct
*napi
, int budget
)
3846 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
, napi
);
3847 struct net_device
*poll_dev
= adapter
->netdev
;
3848 int tx_cleaned
= 0, work_done
= 0;
3850 adapter
= netdev_priv(poll_dev
);
3852 tx_cleaned
= e1000_clean_tx_irq(adapter
, &adapter
->tx_ring
[0]);
3854 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[0],
3855 &work_done
, budget
);
3860 /* If budget not fully consumed, exit the polling mode */
3861 if (work_done
< budget
) {
3862 if (likely(adapter
->itr_setting
& 3))
3863 e1000_set_itr(adapter
);
3864 napi_complete(napi
);
3865 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3866 e1000_irq_enable(adapter
);
3873 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3874 * @adapter: board private structure
3876 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
3877 struct e1000_tx_ring
*tx_ring
)
3879 struct e1000_hw
*hw
= &adapter
->hw
;
3880 struct net_device
*netdev
= adapter
->netdev
;
3881 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
3882 struct e1000_buffer
*buffer_info
;
3883 unsigned int i
, eop
;
3884 unsigned int count
= 0;
3885 unsigned int total_tx_bytes
=0, total_tx_packets
=0;
3887 i
= tx_ring
->next_to_clean
;
3888 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3889 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3891 while ((eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) &&
3892 (count
< tx_ring
->count
)) {
3893 bool cleaned
= false;
3894 for ( ; !cleaned
; count
++) {
3895 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3896 buffer_info
= &tx_ring
->buffer_info
[i
];
3897 cleaned
= (i
== eop
);
3900 struct sk_buff
*skb
= buffer_info
->skb
;
3901 unsigned int segs
, bytecount
;
3902 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
3903 /* multiply data chunks by size of headers */
3904 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
3906 total_tx_packets
+= segs
;
3907 total_tx_bytes
+= bytecount
;
3909 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
3910 tx_desc
->upper
.data
= 0;
3912 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3915 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3916 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3919 tx_ring
->next_to_clean
= i
;
3921 #define TX_WAKE_THRESHOLD 32
3922 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
3923 E1000_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
)) {
3924 /* Make sure that anybody stopping the queue after this
3925 * sees the new next_to_clean.
3928 if (netif_queue_stopped(netdev
)) {
3929 netif_wake_queue(netdev
);
3930 ++adapter
->restart_queue
;
3934 if (adapter
->detect_tx_hung
) {
3935 /* Detect a transmit hang in hardware, this serializes the
3936 * check with the clearing of time_stamp and movement of i */
3937 adapter
->detect_tx_hung
= false;
3938 if (tx_ring
->buffer_info
[i
].time_stamp
&&
3939 time_after(jiffies
, tx_ring
->buffer_info
[i
].time_stamp
+
3940 (adapter
->tx_timeout_factor
* HZ
))
3941 && !(er32(STATUS
) & E1000_STATUS_TXOFF
)) {
3943 /* detected Tx unit hang */
3944 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
3948 " next_to_use <%x>\n"
3949 " next_to_clean <%x>\n"
3950 "buffer_info[next_to_clean]\n"
3951 " time_stamp <%lx>\n"
3952 " next_to_watch <%x>\n"
3954 " next_to_watch.status <%x>\n",
3955 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
3956 sizeof(struct e1000_tx_ring
)),
3957 readl(hw
->hw_addr
+ tx_ring
->tdh
),
3958 readl(hw
->hw_addr
+ tx_ring
->tdt
),
3959 tx_ring
->next_to_use
,
3960 tx_ring
->next_to_clean
,
3961 tx_ring
->buffer_info
[i
].time_stamp
,
3964 eop_desc
->upper
.fields
.status
);
3965 netif_stop_queue(netdev
);
3968 adapter
->total_tx_bytes
+= total_tx_bytes
;
3969 adapter
->total_tx_packets
+= total_tx_packets
;
3970 adapter
->net_stats
.tx_bytes
+= total_tx_bytes
;
3971 adapter
->net_stats
.tx_packets
+= total_tx_packets
;
3972 return (count
< tx_ring
->count
);
3976 * e1000_rx_checksum - Receive Checksum Offload for 82543
3977 * @adapter: board private structure
3978 * @status_err: receive descriptor status and error fields
3979 * @csum: receive descriptor csum field
3980 * @sk_buff: socket buffer with received data
3983 static void e1000_rx_checksum(struct e1000_adapter
*adapter
, u32 status_err
,
3984 u32 csum
, struct sk_buff
*skb
)
3986 struct e1000_hw
*hw
= &adapter
->hw
;
3987 u16 status
= (u16
)status_err
;
3988 u8 errors
= (u8
)(status_err
>> 24);
3989 skb
->ip_summed
= CHECKSUM_NONE
;
3991 /* 82543 or newer only */
3992 if (unlikely(hw
->mac_type
< e1000_82543
)) return;
3993 /* Ignore Checksum bit is set */
3994 if (unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
3995 /* TCP/UDP checksum error bit is set */
3996 if (unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
3997 /* let the stack verify checksum errors */
3998 adapter
->hw_csum_err
++;
4001 /* TCP/UDP Checksum has not been calculated */
4002 if (hw
->mac_type
<= e1000_82547_rev_2
) {
4003 if (!(status
& E1000_RXD_STAT_TCPCS
))
4006 if (!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
4009 /* It must be a TCP or UDP packet with a valid checksum */
4010 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
4011 /* TCP checksum is good */
4012 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
4013 } else if (hw
->mac_type
> e1000_82547_rev_2
) {
4014 /* IP fragment with UDP payload */
4015 /* Hardware complements the payload checksum, so we undo it
4016 * and then put the value in host order for further stack use.
4018 __sum16 sum
= (__force __sum16
)htons(csum
);
4019 skb
->csum
= csum_unfold(~sum
);
4020 skb
->ip_summed
= CHECKSUM_COMPLETE
;
4022 adapter
->hw_csum_good
++;
4026 * e1000_consume_page - helper function
4028 static void e1000_consume_page(struct e1000_buffer
*bi
, struct sk_buff
*skb
,
4033 skb
->data_len
+= length
;
4034 skb
->truesize
+= length
;
4038 * e1000_receive_skb - helper function to handle rx indications
4039 * @adapter: board private structure
4040 * @status: descriptor status field as written by hardware
4041 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
4042 * @skb: pointer to sk_buff to be indicated to stack
4044 static void e1000_receive_skb(struct e1000_adapter
*adapter
, u8 status
,
4045 __le16 vlan
, struct sk_buff
*skb
)
4047 if (unlikely(adapter
->vlgrp
&& (status
& E1000_RXD_STAT_VP
))) {
4048 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
4050 E1000_RXD_SPC_VLAN_MASK
);
4052 netif_receive_skb(skb
);
4057 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
4058 * @adapter: board private structure
4059 * @rx_ring: ring to clean
4060 * @work_done: amount of napi work completed this call
4061 * @work_to_do: max amount of work allowed for this call to do
4063 * the return value indicates whether actual cleaning was done, there
4064 * is no guarantee that everything was cleaned
4066 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter
*adapter
,
4067 struct e1000_rx_ring
*rx_ring
,
4068 int *work_done
, int work_to_do
)
4070 struct e1000_hw
*hw
= &adapter
->hw
;
4071 struct net_device
*netdev
= adapter
->netdev
;
4072 struct pci_dev
*pdev
= adapter
->pdev
;
4073 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
4074 struct e1000_buffer
*buffer_info
, *next_buffer
;
4075 unsigned long irq_flags
;
4078 int cleaned_count
= 0;
4079 bool cleaned
= false;
4080 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
4082 i
= rx_ring
->next_to_clean
;
4083 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4084 buffer_info
= &rx_ring
->buffer_info
[i
];
4086 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
4087 struct sk_buff
*skb
;
4090 if (*work_done
>= work_to_do
)
4094 status
= rx_desc
->status
;
4095 skb
= buffer_info
->skb
;
4096 buffer_info
->skb
= NULL
;
4098 if (++i
== rx_ring
->count
) i
= 0;
4099 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
4102 next_buffer
= &rx_ring
->buffer_info
[i
];
4106 pci_unmap_page(pdev
, buffer_info
->dma
, buffer_info
->length
,
4107 PCI_DMA_FROMDEVICE
);
4108 buffer_info
->dma
= 0;
4110 length
= le16_to_cpu(rx_desc
->length
);
4112 /* errors is only valid for DD + EOP descriptors */
4113 if (unlikely((status
& E1000_RXD_STAT_EOP
) &&
4114 (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
))) {
4115 u8 last_byte
= *(skb
->data
+ length
- 1);
4116 if (TBI_ACCEPT(hw
, status
, rx_desc
->errors
, length
,
4118 spin_lock_irqsave(&adapter
->stats_lock
,
4120 e1000_tbi_adjust_stats(hw
, &adapter
->stats
,
4122 spin_unlock_irqrestore(&adapter
->stats_lock
,
4126 /* recycle both page and skb */
4127 buffer_info
->skb
= skb
;
4128 /* an error means any chain goes out the window
4130 if (rx_ring
->rx_skb_top
)
4131 dev_kfree_skb(rx_ring
->rx_skb_top
);
4132 rx_ring
->rx_skb_top
= NULL
;
4137 #define rxtop rx_ring->rx_skb_top
4138 if (!(status
& E1000_RXD_STAT_EOP
)) {
4139 /* this descriptor is only the beginning (or middle) */
4141 /* this is the beginning of a chain */
4143 skb_fill_page_desc(rxtop
, 0, buffer_info
->page
,
4146 /* this is the middle of a chain */
4147 skb_fill_page_desc(rxtop
,
4148 skb_shinfo(rxtop
)->nr_frags
,
4149 buffer_info
->page
, 0, length
);
4150 /* re-use the skb, only consumed the page */
4151 buffer_info
->skb
= skb
;
4153 e1000_consume_page(buffer_info
, rxtop
, length
);
4157 /* end of the chain */
4158 skb_fill_page_desc(rxtop
,
4159 skb_shinfo(rxtop
)->nr_frags
,
4160 buffer_info
->page
, 0, length
);
4161 /* re-use the current skb, we only consumed the
4163 buffer_info
->skb
= skb
;
4166 e1000_consume_page(buffer_info
, skb
, length
);
4168 /* no chain, got EOP, this buf is the packet
4169 * copybreak to save the put_page/alloc_page */
4170 if (length
<= copybreak
&&
4171 skb_tailroom(skb
) >= length
) {
4173 vaddr
= kmap_atomic(buffer_info
->page
,
4174 KM_SKB_DATA_SOFTIRQ
);
4175 memcpy(skb_tail_pointer(skb
), vaddr
, length
);
4176 kunmap_atomic(vaddr
,
4177 KM_SKB_DATA_SOFTIRQ
);
4178 /* re-use the page, so don't erase
4179 * buffer_info->page */
4180 skb_put(skb
, length
);
4182 skb_fill_page_desc(skb
, 0,
4183 buffer_info
->page
, 0,
4185 e1000_consume_page(buffer_info
, skb
,
4191 /* Receive Checksum Offload XXX recompute due to CRC strip? */
4192 e1000_rx_checksum(adapter
,
4194 ((u32
)(rx_desc
->errors
) << 24),
4195 le16_to_cpu(rx_desc
->csum
), skb
);
4197 pskb_trim(skb
, skb
->len
- 4);
4199 /* probably a little skewed due to removing CRC */
4200 total_rx_bytes
+= skb
->len
;
4203 /* eth type trans needs skb->data to point to something */
4204 if (!pskb_may_pull(skb
, ETH_HLEN
)) {
4205 DPRINTK(DRV
, ERR
, "pskb_may_pull failed.\n");
4210 skb
->protocol
= eth_type_trans(skb
, netdev
);
4212 e1000_receive_skb(adapter
, status
, rx_desc
->special
, skb
);
4215 rx_desc
->status
= 0;
4217 /* return some buffers to hardware, one at a time is too slow */
4218 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
4219 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4223 /* use prefetched values */
4225 buffer_info
= next_buffer
;
4227 rx_ring
->next_to_clean
= i
;
4229 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
4231 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4233 adapter
->total_rx_packets
+= total_rx_packets
;
4234 adapter
->total_rx_bytes
+= total_rx_bytes
;
4235 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
4236 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
4241 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4242 * @adapter: board private structure
4243 * @rx_ring: ring to clean
4244 * @work_done: amount of napi work completed this call
4245 * @work_to_do: max amount of work allowed for this call to do
4247 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
4248 struct e1000_rx_ring
*rx_ring
,
4249 int *work_done
, int work_to_do
)
4251 struct e1000_hw
*hw
= &adapter
->hw
;
4252 struct net_device
*netdev
= adapter
->netdev
;
4253 struct pci_dev
*pdev
= adapter
->pdev
;
4254 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
4255 struct e1000_buffer
*buffer_info
, *next_buffer
;
4256 unsigned long flags
;
4259 int cleaned_count
= 0;
4260 bool cleaned
= false;
4261 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
4263 i
= rx_ring
->next_to_clean
;
4264 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4265 buffer_info
= &rx_ring
->buffer_info
[i
];
4267 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
4268 struct sk_buff
*skb
;
4271 if (*work_done
>= work_to_do
)
4275 status
= rx_desc
->status
;
4276 skb
= buffer_info
->skb
;
4277 buffer_info
->skb
= NULL
;
4279 prefetch(skb
->data
- NET_IP_ALIGN
);
4281 if (++i
== rx_ring
->count
) i
= 0;
4282 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
4285 next_buffer
= &rx_ring
->buffer_info
[i
];
4289 pci_unmap_single(pdev
, buffer_info
->dma
, buffer_info
->length
,
4290 PCI_DMA_FROMDEVICE
);
4291 buffer_info
->dma
= 0;
4293 length
= le16_to_cpu(rx_desc
->length
);
4294 /* !EOP means multiple descriptors were used to store a single
4295 * packet, also make sure the frame isn't just CRC only */
4296 if (unlikely(!(status
& E1000_RXD_STAT_EOP
) || (length
<= 4))) {
4297 /* All receives must fit into a single buffer */
4298 E1000_DBG("%s: Receive packet consumed multiple"
4299 " buffers\n", netdev
->name
);
4301 buffer_info
->skb
= skb
;
4305 if (unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
4306 u8 last_byte
= *(skb
->data
+ length
- 1);
4307 if (TBI_ACCEPT(hw
, status
, rx_desc
->errors
, length
,
4309 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4310 e1000_tbi_adjust_stats(hw
, &adapter
->stats
,
4312 spin_unlock_irqrestore(&adapter
->stats_lock
,
4317 buffer_info
->skb
= skb
;
4322 /* adjust length to remove Ethernet CRC, this must be
4323 * done after the TBI_ACCEPT workaround above */
4326 /* probably a little skewed due to removing CRC */
4327 total_rx_bytes
+= length
;
4330 /* code added for copybreak, this should improve
4331 * performance for small packets with large amounts
4332 * of reassembly being done in the stack */
4333 if (length
< copybreak
) {
4334 struct sk_buff
*new_skb
=
4335 netdev_alloc_skb(netdev
, length
+ NET_IP_ALIGN
);
4337 skb_reserve(new_skb
, NET_IP_ALIGN
);
4338 skb_copy_to_linear_data_offset(new_skb
,
4344 /* save the skb in buffer_info as good */
4345 buffer_info
->skb
= skb
;
4348 /* else just continue with the old one */
4350 /* end copybreak code */
4351 skb_put(skb
, length
);
4353 /* Receive Checksum Offload */
4354 e1000_rx_checksum(adapter
,
4356 ((u32
)(rx_desc
->errors
) << 24),
4357 le16_to_cpu(rx_desc
->csum
), skb
);
4359 skb
->protocol
= eth_type_trans(skb
, netdev
);
4361 e1000_receive_skb(adapter
, status
, rx_desc
->special
, skb
);
4364 rx_desc
->status
= 0;
4366 /* return some buffers to hardware, one at a time is too slow */
4367 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
4368 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4372 /* use prefetched values */
4374 buffer_info
= next_buffer
;
4376 rx_ring
->next_to_clean
= i
;
4378 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
4380 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4382 adapter
->total_rx_packets
+= total_rx_packets
;
4383 adapter
->total_rx_bytes
+= total_rx_bytes
;
4384 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
4385 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
4390 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4391 * @adapter: address of board private structure
4392 * @rx_ring: pointer to receive ring structure
4393 * @cleaned_count: number of buffers to allocate this pass
4397 e1000_alloc_jumbo_rx_buffers(struct e1000_adapter
*adapter
,
4398 struct e1000_rx_ring
*rx_ring
, int cleaned_count
)
4400 struct net_device
*netdev
= adapter
->netdev
;
4401 struct pci_dev
*pdev
= adapter
->pdev
;
4402 struct e1000_rx_desc
*rx_desc
;
4403 struct e1000_buffer
*buffer_info
;
4404 struct sk_buff
*skb
;
4406 unsigned int bufsz
= 256 -
4407 16 /*for skb_reserve */ -
4410 i
= rx_ring
->next_to_use
;
4411 buffer_info
= &rx_ring
->buffer_info
[i
];
4413 while (cleaned_count
--) {
4414 skb
= buffer_info
->skb
;
4420 skb
= netdev_alloc_skb(netdev
, bufsz
);
4421 if (unlikely(!skb
)) {
4422 /* Better luck next round */
4423 adapter
->alloc_rx_buff_failed
++;
4427 /* Fix for errata 23, can't cross 64kB boundary */
4428 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4429 struct sk_buff
*oldskb
= skb
;
4430 DPRINTK(PROBE
, ERR
, "skb align check failed: %u bytes "
4431 "at %p\n", bufsz
, skb
->data
);
4432 /* Try again, without freeing the previous */
4433 skb
= netdev_alloc_skb(netdev
, bufsz
);
4434 /* Failed allocation, critical failure */
4436 dev_kfree_skb(oldskb
);
4437 adapter
->alloc_rx_buff_failed
++;
4441 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4444 dev_kfree_skb(oldskb
);
4445 break; /* while (cleaned_count--) */
4448 /* Use new allocation */
4449 dev_kfree_skb(oldskb
);
4451 /* Make buffer alignment 2 beyond a 16 byte boundary
4452 * this will result in a 16 byte aligned IP header after
4453 * the 14 byte MAC header is removed
4455 skb_reserve(skb
, NET_IP_ALIGN
);
4457 buffer_info
->skb
= skb
;
4458 buffer_info
->length
= adapter
->rx_buffer_len
;
4460 /* allocate a new page if necessary */
4461 if (!buffer_info
->page
) {
4462 buffer_info
->page
= alloc_page(GFP_ATOMIC
);
4463 if (unlikely(!buffer_info
->page
)) {
4464 adapter
->alloc_rx_buff_failed
++;
4469 if (!buffer_info
->dma
)
4470 buffer_info
->dma
= pci_map_page(pdev
,
4471 buffer_info
->page
, 0,
4472 buffer_info
->length
,
4473 PCI_DMA_FROMDEVICE
);
4475 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4476 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4478 if (unlikely(++i
== rx_ring
->count
))
4480 buffer_info
= &rx_ring
->buffer_info
[i
];
4483 if (likely(rx_ring
->next_to_use
!= i
)) {
4484 rx_ring
->next_to_use
= i
;
4485 if (unlikely(i
-- == 0))
4486 i
= (rx_ring
->count
- 1);
4488 /* Force memory writes to complete before letting h/w
4489 * know there are new descriptors to fetch. (Only
4490 * applicable for weak-ordered memory model archs,
4491 * such as IA-64). */
4493 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4498 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4499 * @adapter: address of board private structure
4502 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
4503 struct e1000_rx_ring
*rx_ring
,
4506 struct e1000_hw
*hw
= &adapter
->hw
;
4507 struct net_device
*netdev
= adapter
->netdev
;
4508 struct pci_dev
*pdev
= adapter
->pdev
;
4509 struct e1000_rx_desc
*rx_desc
;
4510 struct e1000_buffer
*buffer_info
;
4511 struct sk_buff
*skb
;
4513 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
4515 i
= rx_ring
->next_to_use
;
4516 buffer_info
= &rx_ring
->buffer_info
[i
];
4518 while (cleaned_count
--) {
4519 skb
= buffer_info
->skb
;
4525 skb
= netdev_alloc_skb(netdev
, bufsz
);
4526 if (unlikely(!skb
)) {
4527 /* Better luck next round */
4528 adapter
->alloc_rx_buff_failed
++;
4532 /* Fix for errata 23, can't cross 64kB boundary */
4533 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4534 struct sk_buff
*oldskb
= skb
;
4535 DPRINTK(RX_ERR
, ERR
, "skb align check failed: %u bytes "
4536 "at %p\n", bufsz
, skb
->data
);
4537 /* Try again, without freeing the previous */
4538 skb
= netdev_alloc_skb(netdev
, bufsz
);
4539 /* Failed allocation, critical failure */
4541 dev_kfree_skb(oldskb
);
4542 adapter
->alloc_rx_buff_failed
++;
4546 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4549 dev_kfree_skb(oldskb
);
4550 adapter
->alloc_rx_buff_failed
++;
4551 break; /* while !buffer_info->skb */
4554 /* Use new allocation */
4555 dev_kfree_skb(oldskb
);
4557 /* Make buffer alignment 2 beyond a 16 byte boundary
4558 * this will result in a 16 byte aligned IP header after
4559 * the 14 byte MAC header is removed
4561 skb_reserve(skb
, NET_IP_ALIGN
);
4563 buffer_info
->skb
= skb
;
4564 buffer_info
->length
= adapter
->rx_buffer_len
;
4566 buffer_info
->dma
= pci_map_single(pdev
,
4568 buffer_info
->length
,
4569 PCI_DMA_FROMDEVICE
);
4572 * XXX if it was allocated cleanly it will never map to a
4576 /* Fix for errata 23, can't cross 64kB boundary */
4577 if (!e1000_check_64k_bound(adapter
,
4578 (void *)(unsigned long)buffer_info
->dma
,
4579 adapter
->rx_buffer_len
)) {
4580 DPRINTK(RX_ERR
, ERR
,
4581 "dma align check failed: %u bytes at %p\n",
4582 adapter
->rx_buffer_len
,
4583 (void *)(unsigned long)buffer_info
->dma
);
4585 buffer_info
->skb
= NULL
;
4587 pci_unmap_single(pdev
, buffer_info
->dma
,
4588 adapter
->rx_buffer_len
,
4589 PCI_DMA_FROMDEVICE
);
4590 buffer_info
->dma
= 0;
4592 adapter
->alloc_rx_buff_failed
++;
4593 break; /* while !buffer_info->skb */
4595 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4596 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4598 if (unlikely(++i
== rx_ring
->count
))
4600 buffer_info
= &rx_ring
->buffer_info
[i
];
4603 if (likely(rx_ring
->next_to_use
!= i
)) {
4604 rx_ring
->next_to_use
= i
;
4605 if (unlikely(i
-- == 0))
4606 i
= (rx_ring
->count
- 1);
4608 /* Force memory writes to complete before letting h/w
4609 * know there are new descriptors to fetch. (Only
4610 * applicable for weak-ordered memory model archs,
4611 * such as IA-64). */
4613 writel(i
, hw
->hw_addr
+ rx_ring
->rdt
);
4618 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4622 static void e1000_smartspeed(struct e1000_adapter
*adapter
)
4624 struct e1000_hw
*hw
= &adapter
->hw
;
4628 if ((hw
->phy_type
!= e1000_phy_igp
) || !hw
->autoneg
||
4629 !(hw
->autoneg_advertised
& ADVERTISE_1000_FULL
))
4632 if (adapter
->smartspeed
== 0) {
4633 /* If Master/Slave config fault is asserted twice,
4634 * we assume back-to-back */
4635 e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_status
);
4636 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4637 e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_status
);
4638 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4639 e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4640 if (phy_ctrl
& CR_1000T_MS_ENABLE
) {
4641 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
4642 e1000_write_phy_reg(hw
, PHY_1000T_CTRL
,
4644 adapter
->smartspeed
++;
4645 if (!e1000_phy_setup_autoneg(hw
) &&
4646 !e1000_read_phy_reg(hw
, PHY_CTRL
,
4648 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4649 MII_CR_RESTART_AUTO_NEG
);
4650 e1000_write_phy_reg(hw
, PHY_CTRL
,
4655 } else if (adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
4656 /* If still no link, perhaps using 2/3 pair cable */
4657 e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4658 phy_ctrl
|= CR_1000T_MS_ENABLE
;
4659 e1000_write_phy_reg(hw
, PHY_1000T_CTRL
, phy_ctrl
);
4660 if (!e1000_phy_setup_autoneg(hw
) &&
4661 !e1000_read_phy_reg(hw
, PHY_CTRL
, &phy_ctrl
)) {
4662 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4663 MII_CR_RESTART_AUTO_NEG
);
4664 e1000_write_phy_reg(hw
, PHY_CTRL
, phy_ctrl
);
4667 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4668 if (adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
4669 adapter
->smartspeed
= 0;
4679 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4685 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4698 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
4701 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4702 struct e1000_hw
*hw
= &adapter
->hw
;
4703 struct mii_ioctl_data
*data
= if_mii(ifr
);
4707 unsigned long flags
;
4709 if (hw
->media_type
!= e1000_media_type_copper
)
4714 data
->phy_id
= hw
->phy_addr
;
4717 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4718 if (e1000_read_phy_reg(hw
, data
->reg_num
& 0x1F,
4720 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4723 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4726 if (data
->reg_num
& ~(0x1F))
4728 mii_reg
= data
->val_in
;
4729 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4730 if (e1000_write_phy_reg(hw
, data
->reg_num
,
4732 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4735 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4736 if (hw
->media_type
== e1000_media_type_copper
) {
4737 switch (data
->reg_num
) {
4739 if (mii_reg
& MII_CR_POWER_DOWN
)
4741 if (mii_reg
& MII_CR_AUTO_NEG_EN
) {
4743 hw
->autoneg_advertised
= 0x2F;
4746 spddplx
= SPEED_1000
;
4747 else if (mii_reg
& 0x2000)
4748 spddplx
= SPEED_100
;
4751 spddplx
+= (mii_reg
& 0x100)
4754 retval
= e1000_set_spd_dplx(adapter
,
4759 if (netif_running(adapter
->netdev
))
4760 e1000_reinit_locked(adapter
);
4762 e1000_reset(adapter
);
4764 case M88E1000_PHY_SPEC_CTRL
:
4765 case M88E1000_EXT_PHY_SPEC_CTRL
:
4766 if (e1000_phy_reset(hw
))
4771 switch (data
->reg_num
) {
4773 if (mii_reg
& MII_CR_POWER_DOWN
)
4775 if (netif_running(adapter
->netdev
))
4776 e1000_reinit_locked(adapter
);
4778 e1000_reset(adapter
);
4786 return E1000_SUCCESS
;
4789 void e1000_pci_set_mwi(struct e1000_hw
*hw
)
4791 struct e1000_adapter
*adapter
= hw
->back
;
4792 int ret_val
= pci_set_mwi(adapter
->pdev
);
4795 DPRINTK(PROBE
, ERR
, "Error in setting MWI\n");
4798 void e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4800 struct e1000_adapter
*adapter
= hw
->back
;
4802 pci_clear_mwi(adapter
->pdev
);
4805 int e1000_pcix_get_mmrbc(struct e1000_hw
*hw
)
4807 struct e1000_adapter
*adapter
= hw
->back
;
4808 return pcix_get_mmrbc(adapter
->pdev
);
4811 void e1000_pcix_set_mmrbc(struct e1000_hw
*hw
, int mmrbc
)
4813 struct e1000_adapter
*adapter
= hw
->back
;
4814 pcix_set_mmrbc(adapter
->pdev
, mmrbc
);
4817 s32
e1000_read_pcie_cap_reg(struct e1000_hw
*hw
, u32 reg
, u16
*value
)
4819 struct e1000_adapter
*adapter
= hw
->back
;
4822 cap_offset
= pci_find_capability(adapter
->pdev
, PCI_CAP_ID_EXP
);
4824 return -E1000_ERR_CONFIG
;
4826 pci_read_config_word(adapter
->pdev
, cap_offset
+ reg
, value
);
4828 return E1000_SUCCESS
;
4831 void e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, u32 value
)
4836 static void e1000_vlan_rx_register(struct net_device
*netdev
,
4837 struct vlan_group
*grp
)
4839 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4840 struct e1000_hw
*hw
= &adapter
->hw
;
4843 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4844 e1000_irq_disable(adapter
);
4845 adapter
->vlgrp
= grp
;
4848 /* enable VLAN tag insert/strip */
4850 ctrl
|= E1000_CTRL_VME
;
4853 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
4854 /* enable VLAN receive filtering */
4856 rctl
&= ~E1000_RCTL_CFIEN
;
4857 if (!(netdev
->flags
& IFF_PROMISC
))
4858 rctl
|= E1000_RCTL_VFE
;
4860 e1000_update_mng_vlan(adapter
);
4863 /* disable VLAN tag insert/strip */
4865 ctrl
&= ~E1000_CTRL_VME
;
4868 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
4869 /* disable VLAN receive filtering */
4871 rctl
&= ~E1000_RCTL_VFE
;
4874 if (adapter
->mng_vlan_id
!=
4875 (u16
)E1000_MNG_VLAN_NONE
) {
4876 e1000_vlan_rx_kill_vid(netdev
,
4877 adapter
->mng_vlan_id
);
4878 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
4883 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4884 e1000_irq_enable(adapter
);
4887 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
4889 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4890 struct e1000_hw
*hw
= &adapter
->hw
;
4893 if ((hw
->mng_cookie
.status
&
4894 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4895 (vid
== adapter
->mng_vlan_id
))
4897 /* add VID to filter table */
4898 index
= (vid
>> 5) & 0x7F;
4899 vfta
= E1000_READ_REG_ARRAY(hw
, VFTA
, index
);
4900 vfta
|= (1 << (vid
& 0x1F));
4901 e1000_write_vfta(hw
, index
, vfta
);
4904 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
4906 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4907 struct e1000_hw
*hw
= &adapter
->hw
;
4910 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4911 e1000_irq_disable(adapter
);
4912 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
4913 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4914 e1000_irq_enable(adapter
);
4916 if ((hw
->mng_cookie
.status
&
4917 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4918 (vid
== adapter
->mng_vlan_id
)) {
4919 /* release control to f/w */
4920 e1000_release_hw_control(adapter
);
4924 /* remove VID from filter table */
4925 index
= (vid
>> 5) & 0x7F;
4926 vfta
= E1000_READ_REG_ARRAY(hw
, VFTA
, index
);
4927 vfta
&= ~(1 << (vid
& 0x1F));
4928 e1000_write_vfta(hw
, index
, vfta
);
4931 static void e1000_restore_vlan(struct e1000_adapter
*adapter
)
4933 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
4935 if (adapter
->vlgrp
) {
4937 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
4938 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
4940 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
4945 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u16 spddplx
)
4947 struct e1000_hw
*hw
= &adapter
->hw
;
4951 /* Fiber NICs only allow 1000 gbps Full duplex */
4952 if ((hw
->media_type
== e1000_media_type_fiber
) &&
4953 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
4954 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4959 case SPEED_10
+ DUPLEX_HALF
:
4960 hw
->forced_speed_duplex
= e1000_10_half
;
4962 case SPEED_10
+ DUPLEX_FULL
:
4963 hw
->forced_speed_duplex
= e1000_10_full
;
4965 case SPEED_100
+ DUPLEX_HALF
:
4966 hw
->forced_speed_duplex
= e1000_100_half
;
4968 case SPEED_100
+ DUPLEX_FULL
:
4969 hw
->forced_speed_duplex
= e1000_100_full
;
4971 case SPEED_1000
+ DUPLEX_FULL
:
4973 hw
->autoneg_advertised
= ADVERTISE_1000_FULL
;
4975 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
4977 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4983 static int __e1000_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
4985 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4986 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4987 struct e1000_hw
*hw
= &adapter
->hw
;
4988 u32 ctrl
, ctrl_ext
, rctl
, status
;
4989 u32 wufc
= adapter
->wol
;
4994 netif_device_detach(netdev
);
4996 if (netif_running(netdev
)) {
4997 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
4998 e1000_down(adapter
);
5002 retval
= pci_save_state(pdev
);
5007 status
= er32(STATUS
);
5008 if (status
& E1000_STATUS_LU
)
5009 wufc
&= ~E1000_WUFC_LNKC
;
5012 e1000_setup_rctl(adapter
);
5013 e1000_set_rx_mode(netdev
);
5015 /* turn on all-multi mode if wake on multicast is enabled */
5016 if (wufc
& E1000_WUFC_MC
) {
5018 rctl
|= E1000_RCTL_MPE
;
5022 if (hw
->mac_type
>= e1000_82540
) {
5024 /* advertise wake from D3Cold */
5025 #define E1000_CTRL_ADVD3WUC 0x00100000
5026 /* phy power management enable */
5027 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5028 ctrl
|= E1000_CTRL_ADVD3WUC
|
5029 E1000_CTRL_EN_PHY_PWR_MGMT
;
5033 if (hw
->media_type
== e1000_media_type_fiber
||
5034 hw
->media_type
== e1000_media_type_internal_serdes
) {
5035 /* keep the laser running in D3 */
5036 ctrl_ext
= er32(CTRL_EXT
);
5037 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
5038 ew32(CTRL_EXT
, ctrl_ext
);
5041 /* Allow time for pending master requests to run */
5042 e1000_disable_pciex_master(hw
);
5044 ew32(WUC
, E1000_WUC_PME_EN
);
5051 e1000_release_manageability(adapter
);
5053 *enable_wake
= !!wufc
;
5055 /* make sure adapter isn't asleep if manageability is enabled */
5056 if (adapter
->en_mng_pt
)
5057 *enable_wake
= true;
5059 if (hw
->phy_type
== e1000_phy_igp_3
)
5060 e1000_phy_powerdown_workaround(hw
);
5062 if (netif_running(netdev
))
5063 e1000_free_irq(adapter
);
5065 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5066 * would have already happened in close and is redundant. */
5067 e1000_release_hw_control(adapter
);
5069 pci_disable_device(pdev
);
5075 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5080 retval
= __e1000_shutdown(pdev
, &wake
);
5085 pci_prepare_to_sleep(pdev
);
5087 pci_wake_from_d3(pdev
, false);
5088 pci_set_power_state(pdev
, PCI_D3hot
);
5094 static int e1000_resume(struct pci_dev
*pdev
)
5096 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5097 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5098 struct e1000_hw
*hw
= &adapter
->hw
;
5101 pci_set_power_state(pdev
, PCI_D0
);
5102 pci_restore_state(pdev
);
5104 if (adapter
->need_ioport
)
5105 err
= pci_enable_device(pdev
);
5107 err
= pci_enable_device_mem(pdev
);
5109 printk(KERN_ERR
"e1000: Cannot enable PCI device from suspend\n");
5112 pci_set_master(pdev
);
5114 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5115 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5117 if (netif_running(netdev
)) {
5118 err
= e1000_request_irq(adapter
);
5123 e1000_power_up_phy(adapter
);
5124 e1000_reset(adapter
);
5127 e1000_init_manageability(adapter
);
5129 if (netif_running(netdev
))
5132 netif_device_attach(netdev
);
5134 /* If the controller is 82573 and f/w is AMT, do not set
5135 * DRV_LOAD until the interface is up. For all other cases,
5136 * let the f/w know that the h/w is now under the control
5138 if (hw
->mac_type
!= e1000_82573
||
5139 !e1000_check_mng_mode(hw
))
5140 e1000_get_hw_control(adapter
);
5146 static void e1000_shutdown(struct pci_dev
*pdev
)
5150 __e1000_shutdown(pdev
, &wake
);
5152 if (system_state
== SYSTEM_POWER_OFF
) {
5153 pci_wake_from_d3(pdev
, wake
);
5154 pci_set_power_state(pdev
, PCI_D3hot
);
5158 #ifdef CONFIG_NET_POLL_CONTROLLER
5160 * Polling 'interrupt' - used by things like netconsole to send skbs
5161 * without having to re-enable interrupts. It's not called while
5162 * the interrupt routine is executing.
5164 static void e1000_netpoll(struct net_device
*netdev
)
5166 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5168 disable_irq(adapter
->pdev
->irq
);
5169 e1000_intr(adapter
->pdev
->irq
, netdev
);
5170 enable_irq(adapter
->pdev
->irq
);
5175 * e1000_io_error_detected - called when PCI error is detected
5176 * @pdev: Pointer to PCI device
5177 * @state: The current pci conneection state
5179 * This function is called after a PCI bus error affecting
5180 * this device has been detected.
5182 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
5183 pci_channel_state_t state
)
5185 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5186 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5188 netif_device_detach(netdev
);
5190 if (state
== pci_channel_io_perm_failure
)
5191 return PCI_ERS_RESULT_DISCONNECT
;
5193 if (netif_running(netdev
))
5194 e1000_down(adapter
);
5195 pci_disable_device(pdev
);
5197 /* Request a slot slot reset. */
5198 return PCI_ERS_RESULT_NEED_RESET
;
5202 * e1000_io_slot_reset - called after the pci bus has been reset.
5203 * @pdev: Pointer to PCI device
5205 * Restart the card from scratch, as if from a cold-boot. Implementation
5206 * resembles the first-half of the e1000_resume routine.
5208 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
5210 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5211 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5212 struct e1000_hw
*hw
= &adapter
->hw
;
5215 if (adapter
->need_ioport
)
5216 err
= pci_enable_device(pdev
);
5218 err
= pci_enable_device_mem(pdev
);
5220 printk(KERN_ERR
"e1000: Cannot re-enable PCI device after reset.\n");
5221 return PCI_ERS_RESULT_DISCONNECT
;
5223 pci_set_master(pdev
);
5225 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5226 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5228 e1000_reset(adapter
);
5231 return PCI_ERS_RESULT_RECOVERED
;
5235 * e1000_io_resume - called when traffic can start flowing again.
5236 * @pdev: Pointer to PCI device
5238 * This callback is called when the error recovery driver tells us that
5239 * its OK to resume normal operation. Implementation resembles the
5240 * second-half of the e1000_resume routine.
5242 static void e1000_io_resume(struct pci_dev
*pdev
)
5244 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5245 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5246 struct e1000_hw
*hw
= &adapter
->hw
;
5248 e1000_init_manageability(adapter
);
5250 if (netif_running(netdev
)) {
5251 if (e1000_up(adapter
)) {
5252 printk("e1000: can't bring device back up after reset\n");
5257 netif_device_attach(netdev
);
5259 /* If the controller is 82573 and f/w is AMT, do not set
5260 * DRV_LOAD until the interface is up. For all other cases,
5261 * let the f/w know that the h/w is now under the control
5263 if (hw
->mac_type
!= e1000_82573
||
5264 !e1000_check_mng_mode(hw
))
5265 e1000_get_hw_control(adapter
);