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 #ifndef CONFIG_E1000_NAPI
37 #define DRIVERNAPI "-NAPI"
39 #define DRV_VERSION "7.3.20-k2"DRIVERNAPI
40 const char e1000_driver_version
[] = DRV_VERSION
;
41 static const char e1000_copyright
[] = "Copyright (c) 1999-2006 Intel Corporation.";
43 /* e1000_pci_tbl - PCI Device ID Table
45 * Last entry must be all 0s
48 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
50 #ifdef CONFIG_E1000E_ENABLED
56 static struct pci_device_id e1000_pci_tbl
[] = {
57 INTEL_E1000_ETHERNET_DEVICE(0x1000),
58 INTEL_E1000_ETHERNET_DEVICE(0x1001),
59 INTEL_E1000_ETHERNET_DEVICE(0x1004),
60 INTEL_E1000_ETHERNET_DEVICE(0x1008),
61 INTEL_E1000_ETHERNET_DEVICE(0x1009),
62 INTEL_E1000_ETHERNET_DEVICE(0x100C),
63 INTEL_E1000_ETHERNET_DEVICE(0x100D),
64 INTEL_E1000_ETHERNET_DEVICE(0x100E),
65 INTEL_E1000_ETHERNET_DEVICE(0x100F),
66 INTEL_E1000_ETHERNET_DEVICE(0x1010),
67 INTEL_E1000_ETHERNET_DEVICE(0x1011),
68 INTEL_E1000_ETHERNET_DEVICE(0x1012),
69 INTEL_E1000_ETHERNET_DEVICE(0x1013),
70 INTEL_E1000_ETHERNET_DEVICE(0x1014),
71 INTEL_E1000_ETHERNET_DEVICE(0x1015),
72 INTEL_E1000_ETHERNET_DEVICE(0x1016),
73 INTEL_E1000_ETHERNET_DEVICE(0x1017),
74 INTEL_E1000_ETHERNET_DEVICE(0x1018),
75 INTEL_E1000_ETHERNET_DEVICE(0x1019),
76 INTEL_E1000_ETHERNET_DEVICE(0x101A),
77 INTEL_E1000_ETHERNET_DEVICE(0x101D),
78 INTEL_E1000_ETHERNET_DEVICE(0x101E),
79 INTEL_E1000_ETHERNET_DEVICE(0x1026),
80 INTEL_E1000_ETHERNET_DEVICE(0x1027),
81 INTEL_E1000_ETHERNET_DEVICE(0x1028),
82 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1049))
83 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104A))
84 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104B))
85 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104C))
86 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104D))
87 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x105E))
88 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x105F))
89 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1060))
90 INTEL_E1000_ETHERNET_DEVICE(0x1075),
91 INTEL_E1000_ETHERNET_DEVICE(0x1076),
92 INTEL_E1000_ETHERNET_DEVICE(0x1077),
93 INTEL_E1000_ETHERNET_DEVICE(0x1078),
94 INTEL_E1000_ETHERNET_DEVICE(0x1079),
95 INTEL_E1000_ETHERNET_DEVICE(0x107A),
96 INTEL_E1000_ETHERNET_DEVICE(0x107B),
97 INTEL_E1000_ETHERNET_DEVICE(0x107C),
98 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x107D))
99 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x107E))
100 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x107F))
101 INTEL_E1000_ETHERNET_DEVICE(0x108A),
102 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x108B))
103 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x108C))
104 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1096))
105 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1098))
106 INTEL_E1000_ETHERNET_DEVICE(0x1099),
107 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x109A))
108 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10A4))
109 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10A5))
110 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
111 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10B9))
112 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10BA))
113 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10BB))
114 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10BC))
115 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10C4))
116 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10C5))
117 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10D5))
118 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10D9))
119 PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10DA))
120 /* required last entry */
124 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
126 int e1000_up(struct e1000_adapter
*adapter
);
127 void e1000_down(struct e1000_adapter
*adapter
);
128 void e1000_reinit_locked(struct e1000_adapter
*adapter
);
129 void e1000_reset(struct e1000_adapter
*adapter
);
130 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u16 spddplx
);
131 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
);
132 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
);
133 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
);
134 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
);
135 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
136 struct e1000_tx_ring
*txdr
);
137 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
138 struct e1000_rx_ring
*rxdr
);
139 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
140 struct e1000_tx_ring
*tx_ring
);
141 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
142 struct e1000_rx_ring
*rx_ring
);
143 void e1000_update_stats(struct e1000_adapter
*adapter
);
145 static int e1000_init_module(void);
146 static void e1000_exit_module(void);
147 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
148 static void __devexit
e1000_remove(struct pci_dev
*pdev
);
149 static int e1000_alloc_queues(struct e1000_adapter
*adapter
);
150 static int e1000_sw_init(struct e1000_adapter
*adapter
);
151 static int e1000_open(struct net_device
*netdev
);
152 static int e1000_close(struct net_device
*netdev
);
153 static void e1000_configure_tx(struct e1000_adapter
*adapter
);
154 static void e1000_configure_rx(struct e1000_adapter
*adapter
);
155 static void e1000_setup_rctl(struct e1000_adapter
*adapter
);
156 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
);
157 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
);
158 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
159 struct e1000_tx_ring
*tx_ring
);
160 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
161 struct e1000_rx_ring
*rx_ring
);
162 static void e1000_set_rx_mode(struct net_device
*netdev
);
163 static void e1000_update_phy_info(unsigned long data
);
164 static void e1000_watchdog(unsigned long data
);
165 static void e1000_82547_tx_fifo_stall(unsigned long data
);
166 static int e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
);
167 static struct net_device_stats
* e1000_get_stats(struct net_device
*netdev
);
168 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
169 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
170 static irqreturn_t
e1000_intr(int irq
, void *data
);
171 static irqreturn_t
e1000_intr_msi(int irq
, void *data
);
172 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
173 struct e1000_tx_ring
*tx_ring
);
174 #ifdef CONFIG_E1000_NAPI
175 static int e1000_clean(struct napi_struct
*napi
, int budget
);
176 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
177 struct e1000_rx_ring
*rx_ring
,
178 int *work_done
, int work_to_do
);
179 static bool e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
180 struct e1000_rx_ring
*rx_ring
,
181 int *work_done
, int work_to_do
);
183 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
184 struct e1000_rx_ring
*rx_ring
);
185 static bool e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
186 struct e1000_rx_ring
*rx_ring
);
188 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
189 struct e1000_rx_ring
*rx_ring
,
191 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
192 struct e1000_rx_ring
*rx_ring
,
194 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
195 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
197 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
198 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
199 static void e1000_tx_timeout(struct net_device
*dev
);
200 static void e1000_reset_task(struct work_struct
*work
);
201 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
202 static int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
203 struct sk_buff
*skb
);
205 static void e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
);
206 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
);
207 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
);
208 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
210 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
);
212 static int e1000_resume(struct pci_dev
*pdev
);
214 static void e1000_shutdown(struct pci_dev
*pdev
);
216 #ifdef CONFIG_NET_POLL_CONTROLLER
217 /* for netdump / net console */
218 static void e1000_netpoll (struct net_device
*netdev
);
221 #define COPYBREAK_DEFAULT 256
222 static unsigned int copybreak __read_mostly
= COPYBREAK_DEFAULT
;
223 module_param(copybreak
, uint
, 0644);
224 MODULE_PARM_DESC(copybreak
,
225 "Maximum size of packet that is copied to a new buffer on receive");
227 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
228 pci_channel_state_t state
);
229 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
);
230 static void e1000_io_resume(struct pci_dev
*pdev
);
232 static struct pci_error_handlers e1000_err_handler
= {
233 .error_detected
= e1000_io_error_detected
,
234 .slot_reset
= e1000_io_slot_reset
,
235 .resume
= e1000_io_resume
,
238 static struct pci_driver e1000_driver
= {
239 .name
= e1000_driver_name
,
240 .id_table
= e1000_pci_tbl
,
241 .probe
= e1000_probe
,
242 .remove
= __devexit_p(e1000_remove
),
244 /* Power Managment Hooks */
245 .suspend
= e1000_suspend
,
246 .resume
= e1000_resume
,
248 .shutdown
= e1000_shutdown
,
249 .err_handler
= &e1000_err_handler
252 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
253 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
254 MODULE_LICENSE("GPL");
255 MODULE_VERSION(DRV_VERSION
);
257 static int debug
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
258 module_param(debug
, int, 0);
259 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
262 * e1000_init_module - Driver Registration Routine
264 * e1000_init_module is the first routine called when the driver is
265 * loaded. All it does is register with the PCI subsystem.
269 e1000_init_module(void)
272 printk(KERN_INFO
"%s - version %s\n",
273 e1000_driver_string
, e1000_driver_version
);
275 printk(KERN_INFO
"%s\n", e1000_copyright
);
277 ret
= pci_register_driver(&e1000_driver
);
278 if (copybreak
!= COPYBREAK_DEFAULT
) {
280 printk(KERN_INFO
"e1000: copybreak disabled\n");
282 printk(KERN_INFO
"e1000: copybreak enabled for "
283 "packets <= %u bytes\n", copybreak
);
288 module_init(e1000_init_module
);
291 * e1000_exit_module - Driver Exit Cleanup Routine
293 * e1000_exit_module is called just before the driver is removed
298 e1000_exit_module(void)
300 pci_unregister_driver(&e1000_driver
);
303 module_exit(e1000_exit_module
);
305 static int e1000_request_irq(struct e1000_adapter
*adapter
)
307 struct net_device
*netdev
= adapter
->netdev
;
308 irq_handler_t handler
= e1000_intr
;
309 int irq_flags
= IRQF_SHARED
;
312 if (adapter
->hw
.mac_type
>= e1000_82571
) {
313 adapter
->have_msi
= !pci_enable_msi(adapter
->pdev
);
314 if (adapter
->have_msi
) {
315 handler
= e1000_intr_msi
;
320 err
= request_irq(adapter
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
323 if (adapter
->have_msi
)
324 pci_disable_msi(adapter
->pdev
);
326 "Unable to allocate interrupt Error: %d\n", err
);
332 static void e1000_free_irq(struct e1000_adapter
*adapter
)
334 struct net_device
*netdev
= adapter
->netdev
;
336 free_irq(adapter
->pdev
->irq
, netdev
);
338 if (adapter
->have_msi
)
339 pci_disable_msi(adapter
->pdev
);
343 * e1000_irq_disable - Mask off interrupt generation on the NIC
344 * @adapter: board private structure
348 e1000_irq_disable(struct e1000_adapter
*adapter
)
350 E1000_WRITE_REG(&adapter
->hw
, IMC
, ~0);
351 E1000_WRITE_FLUSH(&adapter
->hw
);
352 synchronize_irq(adapter
->pdev
->irq
);
356 * e1000_irq_enable - Enable default interrupt generation settings
357 * @adapter: board private structure
361 e1000_irq_enable(struct e1000_adapter
*adapter
)
363 E1000_WRITE_REG(&adapter
->hw
, IMS
, IMS_ENABLE_MASK
);
364 E1000_WRITE_FLUSH(&adapter
->hw
);
368 e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
370 struct net_device
*netdev
= adapter
->netdev
;
371 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
372 u16 old_vid
= adapter
->mng_vlan_id
;
373 if (adapter
->vlgrp
) {
374 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
375 if (adapter
->hw
.mng_cookie
.status
&
376 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
377 e1000_vlan_rx_add_vid(netdev
, vid
);
378 adapter
->mng_vlan_id
= vid
;
380 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
382 if ((old_vid
!= (u16
)E1000_MNG_VLAN_NONE
) &&
384 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
385 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
387 adapter
->mng_vlan_id
= vid
;
392 * e1000_release_hw_control - release control of the h/w to f/w
393 * @adapter: address of board private structure
395 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
396 * For ASF and Pass Through versions of f/w this means that the
397 * driver is no longer loaded. For AMT version (only with 82573) i
398 * of the f/w this means that the network i/f is closed.
403 e1000_release_hw_control(struct e1000_adapter
*adapter
)
408 /* Let firmware taken over control of h/w */
409 switch (adapter
->hw
.mac_type
) {
411 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
412 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
413 swsm
& ~E1000_SWSM_DRV_LOAD
);
417 case e1000_80003es2lan
:
419 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
420 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
421 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
429 * e1000_get_hw_control - get control of the h/w from f/w
430 * @adapter: address of board private structure
432 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
433 * For ASF and Pass Through versions of f/w this means that
434 * the driver is loaded. For AMT version (only with 82573)
435 * of the f/w this means that the network i/f is open.
440 e1000_get_hw_control(struct e1000_adapter
*adapter
)
445 /* Let firmware know the driver has taken over */
446 switch (adapter
->hw
.mac_type
) {
448 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
449 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
450 swsm
| E1000_SWSM_DRV_LOAD
);
454 case e1000_80003es2lan
:
456 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
457 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
458 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
466 e1000_init_manageability(struct e1000_adapter
*adapter
)
468 if (adapter
->en_mng_pt
) {
469 u32 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
471 /* disable hardware interception of ARP */
472 manc
&= ~(E1000_MANC_ARP_EN
);
474 /* enable receiving management packets to the host */
475 /* this will probably generate destination unreachable messages
476 * from the host OS, but the packets will be handled on SMBUS */
477 if (adapter
->hw
.has_manc2h
) {
478 u32 manc2h
= E1000_READ_REG(&adapter
->hw
, MANC2H
);
480 manc
|= E1000_MANC_EN_MNG2HOST
;
481 #define E1000_MNG2HOST_PORT_623 (1 << 5)
482 #define E1000_MNG2HOST_PORT_664 (1 << 6)
483 manc2h
|= E1000_MNG2HOST_PORT_623
;
484 manc2h
|= E1000_MNG2HOST_PORT_664
;
485 E1000_WRITE_REG(&adapter
->hw
, MANC2H
, manc2h
);
488 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
493 e1000_release_manageability(struct e1000_adapter
*adapter
)
495 if (adapter
->en_mng_pt
) {
496 u32 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
498 /* re-enable hardware interception of ARP */
499 manc
|= E1000_MANC_ARP_EN
;
501 if (adapter
->hw
.has_manc2h
)
502 manc
&= ~E1000_MANC_EN_MNG2HOST
;
504 /* don't explicitly have to mess with MANC2H since
505 * MANC has an enable disable that gates MANC2H */
507 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
512 * e1000_configure - configure the hardware for RX and TX
513 * @adapter = private board structure
515 static void e1000_configure(struct e1000_adapter
*adapter
)
517 struct net_device
*netdev
= adapter
->netdev
;
520 e1000_set_rx_mode(netdev
);
522 e1000_restore_vlan(adapter
);
523 e1000_init_manageability(adapter
);
525 e1000_configure_tx(adapter
);
526 e1000_setup_rctl(adapter
);
527 e1000_configure_rx(adapter
);
528 /* call E1000_DESC_UNUSED which always leaves
529 * at least 1 descriptor unused to make sure
530 * next_to_use != next_to_clean */
531 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
532 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[i
];
533 adapter
->alloc_rx_buf(adapter
, ring
,
534 E1000_DESC_UNUSED(ring
));
537 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
540 int e1000_up(struct e1000_adapter
*adapter
)
542 /* hardware has been reset, we need to reload some things */
543 e1000_configure(adapter
);
545 clear_bit(__E1000_DOWN
, &adapter
->flags
);
547 #ifdef CONFIG_E1000_NAPI
548 napi_enable(&adapter
->napi
);
550 e1000_irq_enable(adapter
);
552 /* fire a link change interrupt to start the watchdog */
553 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_LSC
);
558 * e1000_power_up_phy - restore link in case the phy was powered down
559 * @adapter: address of board private structure
561 * The phy may be powered down to save power and turn off link when the
562 * driver is unloaded and wake on lan is not enabled (among others)
563 * *** this routine MUST be followed by a call to e1000_reset ***
567 void e1000_power_up_phy(struct e1000_adapter
*adapter
)
571 /* Just clear the power down bit to wake the phy back up */
572 if (adapter
->hw
.media_type
== e1000_media_type_copper
) {
573 /* according to the manual, the phy will retain its
574 * settings across a power-down/up cycle */
575 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
576 mii_reg
&= ~MII_CR_POWER_DOWN
;
577 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
581 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
583 /* Power down the PHY so no link is implied when interface is down *
584 * The PHY cannot be powered down if any of the following is true *
587 * (c) SoL/IDER session is active */
588 if (!adapter
->wol
&& adapter
->hw
.mac_type
>= e1000_82540
&&
589 adapter
->hw
.media_type
== e1000_media_type_copper
) {
592 switch (adapter
->hw
.mac_type
) {
595 case e1000_82545_rev_3
:
597 case e1000_82546_rev_3
:
599 case e1000_82541_rev_2
:
601 case e1000_82547_rev_2
:
602 if (E1000_READ_REG(&adapter
->hw
, MANC
) &
609 case e1000_80003es2lan
:
611 if (e1000_check_mng_mode(&adapter
->hw
) ||
612 e1000_check_phy_reset_block(&adapter
->hw
))
618 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
619 mii_reg
|= MII_CR_POWER_DOWN
;
620 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
628 e1000_down(struct e1000_adapter
*adapter
)
630 struct net_device
*netdev
= adapter
->netdev
;
632 /* signal that we're down so the interrupt handler does not
633 * reschedule our watchdog timer */
634 set_bit(__E1000_DOWN
, &adapter
->flags
);
636 #ifdef CONFIG_E1000_NAPI
637 napi_disable(&adapter
->napi
);
639 e1000_irq_disable(adapter
);
641 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
642 del_timer_sync(&adapter
->watchdog_timer
);
643 del_timer_sync(&adapter
->phy_info_timer
);
645 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
646 adapter
->link_speed
= 0;
647 adapter
->link_duplex
= 0;
648 netif_carrier_off(netdev
);
649 netif_stop_queue(netdev
);
651 e1000_reset(adapter
);
652 e1000_clean_all_tx_rings(adapter
);
653 e1000_clean_all_rx_rings(adapter
);
657 e1000_reinit_locked(struct e1000_adapter
*adapter
)
659 WARN_ON(in_interrupt());
660 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->flags
))
664 clear_bit(__E1000_RESETTING
, &adapter
->flags
);
668 e1000_reset(struct e1000_adapter
*adapter
)
670 u32 pba
= 0, tx_space
, min_tx_space
, min_rx_space
;
671 u16 fc_high_water_mark
= E1000_FC_HIGH_DIFF
;
672 bool legacy_pba_adjust
= false;
674 /* Repartition Pba for greater than 9k mtu
675 * To take effect CTRL.RST is required.
678 switch (adapter
->hw
.mac_type
) {
679 case e1000_82542_rev2_0
:
680 case e1000_82542_rev2_1
:
685 case e1000_82541_rev_2
:
686 legacy_pba_adjust
= true;
690 case e1000_82545_rev_3
:
692 case e1000_82546_rev_3
:
696 case e1000_82547_rev_2
:
697 legacy_pba_adjust
= true;
702 case e1000_80003es2lan
:
710 case e1000_undefined
:
715 if (legacy_pba_adjust
) {
716 if (adapter
->netdev
->mtu
> E1000_RXBUFFER_8192
)
717 pba
-= 8; /* allocate more FIFO for Tx */
719 if (adapter
->hw
.mac_type
== e1000_82547
) {
720 adapter
->tx_fifo_head
= 0;
721 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
722 adapter
->tx_fifo_size
=
723 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
724 atomic_set(&adapter
->tx_fifo_stall
, 0);
726 } else if (adapter
->hw
.max_frame_size
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
727 /* adjust PBA for jumbo frames */
728 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
730 /* To maintain wire speed transmits, the Tx FIFO should be
731 * large enough to accomodate two full transmit packets,
732 * rounded up to the next 1KB and expressed in KB. Likewise,
733 * the Rx FIFO should be large enough to accomodate at least
734 * one full receive packet and is similarly rounded up and
735 * expressed in KB. */
736 pba
= E1000_READ_REG(&adapter
->hw
, PBA
);
737 /* upper 16 bits has Tx packet buffer allocation size in KB */
738 tx_space
= pba
>> 16;
739 /* lower 16 bits has Rx packet buffer allocation size in KB */
741 /* don't include ethernet FCS because hardware appends/strips */
742 min_rx_space
= adapter
->netdev
->mtu
+ ENET_HEADER_SIZE
+
744 min_tx_space
= min_rx_space
;
746 min_tx_space
= ALIGN(min_tx_space
, 1024);
748 min_rx_space
= ALIGN(min_rx_space
, 1024);
751 /* If current Tx allocation is less than the min Tx FIFO size,
752 * and the min Tx FIFO size is less than the current Rx FIFO
753 * allocation, take space away from current Rx allocation */
754 if (tx_space
< min_tx_space
&&
755 ((min_tx_space
- tx_space
) < pba
)) {
756 pba
= pba
- (min_tx_space
- tx_space
);
758 /* PCI/PCIx hardware has PBA alignment constraints */
759 switch (adapter
->hw
.mac_type
) {
760 case e1000_82545
... e1000_82546_rev_3
:
761 pba
&= ~(E1000_PBA_8K
- 1);
767 /* if short on rx space, rx wins and must trump tx
768 * adjustment or use Early Receive if available */
769 if (pba
< min_rx_space
) {
770 switch (adapter
->hw
.mac_type
) {
772 /* ERT enabled in e1000_configure_rx */
782 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
784 /* flow control settings */
785 /* Set the FC high water mark to 90% of the FIFO size.
786 * Required to clear last 3 LSB */
787 fc_high_water_mark
= ((pba
* 9216)/10) & 0xFFF8;
788 /* We can't use 90% on small FIFOs because the remainder
789 * would be less than 1 full frame. In this case, we size
790 * it to allow at least a full frame above the high water
792 if (pba
< E1000_PBA_16K
)
793 fc_high_water_mark
= (pba
* 1024) - 1600;
795 adapter
->hw
.fc_high_water
= fc_high_water_mark
;
796 adapter
->hw
.fc_low_water
= fc_high_water_mark
- 8;
797 if (adapter
->hw
.mac_type
== e1000_80003es2lan
)
798 adapter
->hw
.fc_pause_time
= 0xFFFF;
800 adapter
->hw
.fc_pause_time
= E1000_FC_PAUSE_TIME
;
801 adapter
->hw
.fc_send_xon
= 1;
802 adapter
->hw
.fc
= adapter
->hw
.original_fc
;
804 /* Allow time for pending master requests to run */
805 e1000_reset_hw(&adapter
->hw
);
806 if (adapter
->hw
.mac_type
>= e1000_82544
)
807 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
809 if (e1000_init_hw(&adapter
->hw
))
810 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
811 e1000_update_mng_vlan(adapter
);
813 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
814 if (adapter
->hw
.mac_type
>= e1000_82544
&&
815 adapter
->hw
.mac_type
<= e1000_82547_rev_2
&&
816 adapter
->hw
.autoneg
== 1 &&
817 adapter
->hw
.autoneg_advertised
== ADVERTISE_1000_FULL
) {
818 u32 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
819 /* clear phy power management bit if we are in gig only mode,
820 * which if enabled will attempt negotiation to 100Mb, which
821 * can cause a loss of link at power off or driver unload */
822 ctrl
&= ~E1000_CTRL_SWDPIN3
;
823 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
826 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
827 E1000_WRITE_REG(&adapter
->hw
, VET
, ETHERNET_IEEE_VLAN_TYPE
);
829 e1000_reset_adaptive(&adapter
->hw
);
830 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
832 if (!adapter
->smart_power_down
&&
833 (adapter
->hw
.mac_type
== e1000_82571
||
834 adapter
->hw
.mac_type
== e1000_82572
)) {
836 /* speed up time to link by disabling smart power down, ignore
837 * the return value of this function because there is nothing
838 * different we would do if it failed */
839 e1000_read_phy_reg(&adapter
->hw
, IGP02E1000_PHY_POWER_MGMT
,
841 phy_data
&= ~IGP02E1000_PM_SPD
;
842 e1000_write_phy_reg(&adapter
->hw
, IGP02E1000_PHY_POWER_MGMT
,
846 e1000_release_manageability(adapter
);
850 * Dump the eeprom for users having checksum issues
852 static void e1000_dump_eeprom(struct e1000_adapter
*adapter
)
854 struct net_device
*netdev
= adapter
->netdev
;
855 struct ethtool_eeprom eeprom
;
856 const struct ethtool_ops
*ops
= netdev
->ethtool_ops
;
859 u16 csum_old
, csum_new
= 0;
861 eeprom
.len
= ops
->get_eeprom_len(netdev
);
864 data
= kmalloc(eeprom
.len
, GFP_KERNEL
);
866 printk(KERN_ERR
"Unable to allocate memory to dump EEPROM"
871 ops
->get_eeprom(netdev
, &eeprom
, data
);
873 csum_old
= (data
[EEPROM_CHECKSUM_REG
* 2]) +
874 (data
[EEPROM_CHECKSUM_REG
* 2 + 1] << 8);
875 for (i
= 0; i
< EEPROM_CHECKSUM_REG
* 2; i
+= 2)
876 csum_new
+= data
[i
] + (data
[i
+ 1] << 8);
877 csum_new
= EEPROM_SUM
- csum_new
;
879 printk(KERN_ERR
"/*********************/\n");
880 printk(KERN_ERR
"Current EEPROM Checksum : 0x%04x\n", csum_old
);
881 printk(KERN_ERR
"Calculated : 0x%04x\n", csum_new
);
883 printk(KERN_ERR
"Offset Values\n");
884 printk(KERN_ERR
"======== ======\n");
885 print_hex_dump(KERN_ERR
, "", DUMP_PREFIX_OFFSET
, 16, 1, data
, 128, 0);
887 printk(KERN_ERR
"Include this output when contacting your support "
889 printk(KERN_ERR
"This is not a software error! Something bad "
890 "happened to your hardware or\n");
891 printk(KERN_ERR
"EEPROM image. Ignoring this "
892 "problem could result in further problems,\n");
893 printk(KERN_ERR
"possibly loss of data, corruption or system hangs!\n");
894 printk(KERN_ERR
"The MAC Address will be reset to 00:00:00:00:00:00, "
895 "which is invalid\n");
896 printk(KERN_ERR
"and requires you to set the proper MAC "
897 "address manually before continuing\n");
898 printk(KERN_ERR
"to enable this network device.\n");
899 printk(KERN_ERR
"Please inspect the EEPROM dump and report the issue "
900 "to your hardware vendor\n");
901 printk(KERN_ERR
"or Intel Customer Support: linux-nics@intel.com\n");
902 printk(KERN_ERR
"/*********************/\n");
908 * e1000_probe - Device Initialization Routine
909 * @pdev: PCI device information struct
910 * @ent: entry in e1000_pci_tbl
912 * Returns 0 on success, negative on failure
914 * e1000_probe initializes an adapter identified by a pci_dev structure.
915 * The OS initialization, configuring of the adapter private structure,
916 * and a hardware reset occur.
920 e1000_probe(struct pci_dev
*pdev
,
921 const struct pci_device_id
*ent
)
923 struct net_device
*netdev
;
924 struct e1000_adapter
*adapter
;
926 static int cards_found
= 0;
927 static int global_quad_port_a
= 0; /* global ksp3 port a indication */
928 int i
, err
, pci_using_dac
;
930 u16 eeprom_apme_mask
= E1000_EEPROM_APME
;
931 DECLARE_MAC_BUF(mac
);
933 if ((err
= pci_enable_device(pdev
)))
936 if (!(err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
)) &&
937 !(err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
))) {
940 if ((err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) &&
941 (err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
))) {
942 E1000_ERR("No usable DMA configuration, aborting\n");
948 if ((err
= pci_request_regions(pdev
, e1000_driver_name
)))
951 pci_set_master(pdev
);
954 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
956 goto err_alloc_etherdev
;
958 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
960 pci_set_drvdata(pdev
, netdev
);
961 adapter
= netdev_priv(netdev
);
962 adapter
->netdev
= netdev
;
963 adapter
->pdev
= pdev
;
964 adapter
->hw
.back
= adapter
;
965 adapter
->msg_enable
= (1 << debug
) - 1;
968 adapter
->hw
.hw_addr
= ioremap(pci_resource_start(pdev
, BAR_0
),
969 pci_resource_len(pdev
, BAR_0
));
970 if (!adapter
->hw
.hw_addr
)
973 for (i
= BAR_1
; i
<= BAR_5
; i
++) {
974 if (pci_resource_len(pdev
, i
) == 0)
976 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
977 adapter
->hw
.io_base
= pci_resource_start(pdev
, i
);
982 netdev
->open
= &e1000_open
;
983 netdev
->stop
= &e1000_close
;
984 netdev
->hard_start_xmit
= &e1000_xmit_frame
;
985 netdev
->get_stats
= &e1000_get_stats
;
986 netdev
->set_rx_mode
= &e1000_set_rx_mode
;
987 netdev
->set_mac_address
= &e1000_set_mac
;
988 netdev
->change_mtu
= &e1000_change_mtu
;
989 netdev
->do_ioctl
= &e1000_ioctl
;
990 e1000_set_ethtool_ops(netdev
);
991 netdev
->tx_timeout
= &e1000_tx_timeout
;
992 netdev
->watchdog_timeo
= 5 * HZ
;
993 #ifdef CONFIG_E1000_NAPI
994 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
996 netdev
->vlan_rx_register
= e1000_vlan_rx_register
;
997 netdev
->vlan_rx_add_vid
= e1000_vlan_rx_add_vid
;
998 netdev
->vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
;
999 #ifdef CONFIG_NET_POLL_CONTROLLER
1000 netdev
->poll_controller
= e1000_netpoll
;
1002 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
1004 adapter
->bd_number
= cards_found
;
1006 /* setup the private structure */
1008 if ((err
= e1000_sw_init(adapter
)))
1012 /* Flash BAR mapping must happen after e1000_sw_init
1013 * because it depends on mac_type */
1014 if ((adapter
->hw
.mac_type
== e1000_ich8lan
) &&
1015 (pci_resource_flags(pdev
, 1) & IORESOURCE_MEM
)) {
1016 adapter
->hw
.flash_address
=
1017 ioremap(pci_resource_start(pdev
, 1),
1018 pci_resource_len(pdev
, 1));
1019 if (!adapter
->hw
.flash_address
)
1023 if (e1000_check_phy_reset_block(&adapter
->hw
))
1024 DPRINTK(PROBE
, INFO
, "PHY reset is blocked due to SOL/IDER session.\n");
1026 if (adapter
->hw
.mac_type
>= e1000_82543
) {
1027 netdev
->features
= NETIF_F_SG
|
1029 NETIF_F_HW_VLAN_TX
|
1030 NETIF_F_HW_VLAN_RX
|
1031 NETIF_F_HW_VLAN_FILTER
;
1032 if (adapter
->hw
.mac_type
== e1000_ich8lan
)
1033 netdev
->features
&= ~NETIF_F_HW_VLAN_FILTER
;
1036 if ((adapter
->hw
.mac_type
>= e1000_82544
) &&
1037 (adapter
->hw
.mac_type
!= e1000_82547
))
1038 netdev
->features
|= NETIF_F_TSO
;
1040 if (adapter
->hw
.mac_type
> e1000_82547_rev_2
)
1041 netdev
->features
|= NETIF_F_TSO6
;
1043 netdev
->features
|= NETIF_F_HIGHDMA
;
1045 netdev
->features
|= NETIF_F_LLTX
;
1047 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(&adapter
->hw
);
1049 /* initialize eeprom parameters */
1050 if (e1000_init_eeprom_params(&adapter
->hw
)) {
1051 E1000_ERR("EEPROM initialization failed\n");
1055 /* before reading the EEPROM, reset the controller to
1056 * put the device in a known good starting state */
1058 e1000_reset_hw(&adapter
->hw
);
1060 /* make sure the EEPROM is good */
1061 if (e1000_validate_eeprom_checksum(&adapter
->hw
) < 0) {
1062 DPRINTK(PROBE
, ERR
, "The EEPROM Checksum Is Not Valid\n");
1063 e1000_dump_eeprom(adapter
);
1065 * set MAC address to all zeroes to invalidate and temporary
1066 * disable this device for the user. This blocks regular
1067 * traffic while still permitting ethtool ioctls from reaching
1068 * the hardware as well as allowing the user to run the
1069 * interface after manually setting a hw addr using
1072 memset(adapter
->hw
.mac_addr
, 0, netdev
->addr_len
);
1074 /* copy the MAC address out of the EEPROM */
1075 if (e1000_read_mac_addr(&adapter
->hw
))
1076 DPRINTK(PROBE
, ERR
, "EEPROM Read Error\n");
1078 /* don't block initalization here due to bad MAC address */
1079 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
1080 memcpy(netdev
->perm_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
1082 if (!is_valid_ether_addr(netdev
->perm_addr
))
1083 DPRINTK(PROBE
, ERR
, "Invalid MAC Address\n");
1085 e1000_get_bus_info(&adapter
->hw
);
1087 init_timer(&adapter
->tx_fifo_stall_timer
);
1088 adapter
->tx_fifo_stall_timer
.function
= &e1000_82547_tx_fifo_stall
;
1089 adapter
->tx_fifo_stall_timer
.data
= (unsigned long) adapter
;
1091 init_timer(&adapter
->watchdog_timer
);
1092 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
1093 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
1095 init_timer(&adapter
->phy_info_timer
);
1096 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
1097 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
1099 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
1101 e1000_check_options(adapter
);
1103 /* Initial Wake on LAN setting
1104 * If APM wake is enabled in the EEPROM,
1105 * enable the ACPI Magic Packet filter
1108 switch (adapter
->hw
.mac_type
) {
1109 case e1000_82542_rev2_0
:
1110 case e1000_82542_rev2_1
:
1114 e1000_read_eeprom(&adapter
->hw
,
1115 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
1116 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
1119 e1000_read_eeprom(&adapter
->hw
,
1120 EEPROM_INIT_CONTROL1_REG
, 1, &eeprom_data
);
1121 eeprom_apme_mask
= E1000_EEPROM_ICH8_APME
;
1124 case e1000_82546_rev_3
:
1126 case e1000_80003es2lan
:
1127 if (E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
){
1128 e1000_read_eeprom(&adapter
->hw
,
1129 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
1134 e1000_read_eeprom(&adapter
->hw
,
1135 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
1138 if (eeprom_data
& eeprom_apme_mask
)
1139 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
1141 /* now that we have the eeprom settings, apply the special cases
1142 * where the eeprom may be wrong or the board simply won't support
1143 * wake on lan on a particular port */
1144 switch (pdev
->device
) {
1145 case E1000_DEV_ID_82546GB_PCIE
:
1146 adapter
->eeprom_wol
= 0;
1148 case E1000_DEV_ID_82546EB_FIBER
:
1149 case E1000_DEV_ID_82546GB_FIBER
:
1150 case E1000_DEV_ID_82571EB_FIBER
:
1151 /* Wake events only supported on port A for dual fiber
1152 * regardless of eeprom setting */
1153 if (E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
)
1154 adapter
->eeprom_wol
= 0;
1156 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3
:
1157 case E1000_DEV_ID_82571EB_QUAD_COPPER
:
1158 case E1000_DEV_ID_82571EB_QUAD_FIBER
:
1159 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE
:
1160 case E1000_DEV_ID_82571PT_QUAD_COPPER
:
1161 /* if quad port adapter, disable WoL on all but port A */
1162 if (global_quad_port_a
!= 0)
1163 adapter
->eeprom_wol
= 0;
1165 adapter
->quad_port_a
= 1;
1166 /* Reset for multiple quad port adapters */
1167 if (++global_quad_port_a
== 4)
1168 global_quad_port_a
= 0;
1172 /* initialize the wol settings based on the eeprom settings */
1173 adapter
->wol
= adapter
->eeprom_wol
;
1175 /* print bus type/speed/width info */
1177 struct e1000_hw
*hw
= &adapter
->hw
;
1178 DPRINTK(PROBE
, INFO
, "(PCI%s:%s:%s) ",
1179 ((hw
->bus_type
== e1000_bus_type_pcix
) ? "-X" :
1180 (hw
->bus_type
== e1000_bus_type_pci_express
? " Express":"")),
1181 ((hw
->bus_speed
== e1000_bus_speed_2500
) ? "2.5Gb/s" :
1182 (hw
->bus_speed
== e1000_bus_speed_133
) ? "133MHz" :
1183 (hw
->bus_speed
== e1000_bus_speed_120
) ? "120MHz" :
1184 (hw
->bus_speed
== e1000_bus_speed_100
) ? "100MHz" :
1185 (hw
->bus_speed
== e1000_bus_speed_66
) ? "66MHz" : "33MHz"),
1186 ((hw
->bus_width
== e1000_bus_width_64
) ? "64-bit" :
1187 (hw
->bus_width
== e1000_bus_width_pciex_4
) ? "Width x4" :
1188 (hw
->bus_width
== e1000_bus_width_pciex_1
) ? "Width x1" :
1192 printk("%s\n", print_mac(mac
, netdev
->dev_addr
));
1194 if (adapter
->hw
.bus_type
== e1000_bus_type_pci_express
) {
1195 DPRINTK(PROBE
, WARNING
, "This device (id %04x:%04x) will no "
1196 "longer be supported by this driver in the future.\n",
1197 pdev
->vendor
, pdev
->device
);
1198 DPRINTK(PROBE
, WARNING
, "please use the \"e1000e\" "
1199 "driver instead.\n");
1202 /* reset the hardware with the new settings */
1203 e1000_reset(adapter
);
1205 /* If the controller is 82573 and f/w is AMT, do not set
1206 * DRV_LOAD until the interface is up. For all other cases,
1207 * let the f/w know that the h/w is now under the control
1209 if (adapter
->hw
.mac_type
!= e1000_82573
||
1210 !e1000_check_mng_mode(&adapter
->hw
))
1211 e1000_get_hw_control(adapter
);
1213 /* tell the stack to leave us alone until e1000_open() is called */
1214 netif_carrier_off(netdev
);
1215 netif_stop_queue(netdev
);
1217 strcpy(netdev
->name
, "eth%d");
1218 if ((err
= register_netdev(netdev
)))
1221 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
1227 e1000_release_hw_control(adapter
);
1229 if (!e1000_check_phy_reset_block(&adapter
->hw
))
1230 e1000_phy_hw_reset(&adapter
->hw
);
1232 if (adapter
->hw
.flash_address
)
1233 iounmap(adapter
->hw
.flash_address
);
1235 #ifdef CONFIG_E1000_NAPI
1236 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1237 dev_put(&adapter
->polling_netdev
[i
]);
1240 kfree(adapter
->tx_ring
);
1241 kfree(adapter
->rx_ring
);
1242 #ifdef CONFIG_E1000_NAPI
1243 kfree(adapter
->polling_netdev
);
1246 iounmap(adapter
->hw
.hw_addr
);
1248 free_netdev(netdev
);
1250 pci_release_regions(pdev
);
1253 pci_disable_device(pdev
);
1258 * e1000_remove - Device Removal Routine
1259 * @pdev: PCI device information struct
1261 * e1000_remove is called by the PCI subsystem to alert the driver
1262 * that it should release a PCI device. The could be caused by a
1263 * Hot-Plug event, or because the driver is going to be removed from
1267 static void __devexit
1268 e1000_remove(struct pci_dev
*pdev
)
1270 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1271 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1272 #ifdef CONFIG_E1000_NAPI
1276 cancel_work_sync(&adapter
->reset_task
);
1278 e1000_release_manageability(adapter
);
1280 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1281 * would have already happened in close and is redundant. */
1282 e1000_release_hw_control(adapter
);
1284 #ifdef CONFIG_E1000_NAPI
1285 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1286 dev_put(&adapter
->polling_netdev
[i
]);
1289 unregister_netdev(netdev
);
1291 if (!e1000_check_phy_reset_block(&adapter
->hw
))
1292 e1000_phy_hw_reset(&adapter
->hw
);
1294 kfree(adapter
->tx_ring
);
1295 kfree(adapter
->rx_ring
);
1296 #ifdef CONFIG_E1000_NAPI
1297 kfree(adapter
->polling_netdev
);
1300 iounmap(adapter
->hw
.hw_addr
);
1301 if (adapter
->hw
.flash_address
)
1302 iounmap(adapter
->hw
.flash_address
);
1303 pci_release_regions(pdev
);
1305 free_netdev(netdev
);
1307 pci_disable_device(pdev
);
1311 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1312 * @adapter: board private structure to initialize
1314 * e1000_sw_init initializes the Adapter private data structure.
1315 * Fields are initialized based on PCI device information and
1316 * OS network device settings (MTU size).
1319 static int __devinit
1320 e1000_sw_init(struct e1000_adapter
*adapter
)
1322 struct e1000_hw
*hw
= &adapter
->hw
;
1323 struct net_device
*netdev
= adapter
->netdev
;
1324 struct pci_dev
*pdev
= adapter
->pdev
;
1325 #ifdef CONFIG_E1000_NAPI
1329 /* PCI config space info */
1331 hw
->vendor_id
= pdev
->vendor
;
1332 hw
->device_id
= pdev
->device
;
1333 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
1334 hw
->subsystem_id
= pdev
->subsystem_device
;
1335 hw
->revision_id
= pdev
->revision
;
1337 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
1339 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1340 adapter
->rx_ps_bsize0
= E1000_RXBUFFER_128
;
1341 hw
->max_frame_size
= netdev
->mtu
+
1342 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
1343 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
1345 /* identify the MAC */
1347 if (e1000_set_mac_type(hw
)) {
1348 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
1352 switch (hw
->mac_type
) {
1357 case e1000_82541_rev_2
:
1358 case e1000_82547_rev_2
:
1359 hw
->phy_init_script
= 1;
1363 e1000_set_media_type(hw
);
1365 hw
->wait_autoneg_complete
= false;
1366 hw
->tbi_compatibility_en
= true;
1367 hw
->adaptive_ifs
= true;
1369 /* Copper options */
1371 if (hw
->media_type
== e1000_media_type_copper
) {
1372 hw
->mdix
= AUTO_ALL_MODES
;
1373 hw
->disable_polarity_correction
= false;
1374 hw
->master_slave
= E1000_MASTER_SLAVE
;
1377 adapter
->num_tx_queues
= 1;
1378 adapter
->num_rx_queues
= 1;
1380 if (e1000_alloc_queues(adapter
)) {
1381 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
1385 #ifdef CONFIG_E1000_NAPI
1386 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1387 adapter
->polling_netdev
[i
].priv
= adapter
;
1388 dev_hold(&adapter
->polling_netdev
[i
]);
1389 set_bit(__LINK_STATE_START
, &adapter
->polling_netdev
[i
].state
);
1391 spin_lock_init(&adapter
->tx_queue_lock
);
1394 /* Explicitly disable IRQ since the NIC can be in any state. */
1395 e1000_irq_disable(adapter
);
1397 spin_lock_init(&adapter
->stats_lock
);
1399 set_bit(__E1000_DOWN
, &adapter
->flags
);
1405 * e1000_alloc_queues - Allocate memory for all rings
1406 * @adapter: board private structure to initialize
1408 * We allocate one ring per queue at run-time since we don't know the
1409 * number of queues at compile-time. The polling_netdev array is
1410 * intended for Multiqueue, but should work fine with a single queue.
1413 static int __devinit
1414 e1000_alloc_queues(struct e1000_adapter
*adapter
)
1416 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1417 sizeof(struct e1000_tx_ring
), GFP_KERNEL
);
1418 if (!adapter
->tx_ring
)
1421 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
1422 sizeof(struct e1000_rx_ring
), GFP_KERNEL
);
1423 if (!adapter
->rx_ring
) {
1424 kfree(adapter
->tx_ring
);
1428 #ifdef CONFIG_E1000_NAPI
1429 adapter
->polling_netdev
= kcalloc(adapter
->num_rx_queues
,
1430 sizeof(struct net_device
),
1432 if (!adapter
->polling_netdev
) {
1433 kfree(adapter
->tx_ring
);
1434 kfree(adapter
->rx_ring
);
1439 return E1000_SUCCESS
;
1443 * e1000_open - Called when a network interface is made active
1444 * @netdev: network interface device structure
1446 * Returns 0 on success, negative value on failure
1448 * The open entry point is called when a network interface is made
1449 * active by the system (IFF_UP). At this point all resources needed
1450 * for transmit and receive operations are allocated, the interrupt
1451 * handler is registered with the OS, the watchdog timer is started,
1452 * and the stack is notified that the interface is ready.
1456 e1000_open(struct net_device
*netdev
)
1458 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1461 /* disallow open during test */
1462 if (test_bit(__E1000_TESTING
, &adapter
->flags
))
1465 /* allocate transmit descriptors */
1466 err
= e1000_setup_all_tx_resources(adapter
);
1470 /* allocate receive descriptors */
1471 err
= e1000_setup_all_rx_resources(adapter
);
1475 e1000_power_up_phy(adapter
);
1477 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1478 if ((adapter
->hw
.mng_cookie
.status
&
1479 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1480 e1000_update_mng_vlan(adapter
);
1483 /* If AMT is enabled, let the firmware know that the network
1484 * interface is now open */
1485 if (adapter
->hw
.mac_type
== e1000_82573
&&
1486 e1000_check_mng_mode(&adapter
->hw
))
1487 e1000_get_hw_control(adapter
);
1489 /* before we allocate an interrupt, we must be ready to handle it.
1490 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1491 * as soon as we call pci_request_irq, so we have to setup our
1492 * clean_rx handler before we do so. */
1493 e1000_configure(adapter
);
1495 err
= e1000_request_irq(adapter
);
1499 /* From here on the code is the same as e1000_up() */
1500 clear_bit(__E1000_DOWN
, &adapter
->flags
);
1502 #ifdef CONFIG_E1000_NAPI
1503 napi_enable(&adapter
->napi
);
1506 e1000_irq_enable(adapter
);
1508 /* fire a link status change interrupt to start the watchdog */
1509 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_LSC
);
1511 return E1000_SUCCESS
;
1514 e1000_release_hw_control(adapter
);
1515 e1000_power_down_phy(adapter
);
1516 e1000_free_all_rx_resources(adapter
);
1518 e1000_free_all_tx_resources(adapter
);
1520 e1000_reset(adapter
);
1526 * e1000_close - Disables a network interface
1527 * @netdev: network interface device structure
1529 * Returns 0, this is not allowed to fail
1531 * The close entry point is called when an interface is de-activated
1532 * by the OS. The hardware is still under the drivers control, but
1533 * needs to be disabled. A global MAC reset is issued to stop the
1534 * hardware, and all transmit and receive resources are freed.
1538 e1000_close(struct net_device
*netdev
)
1540 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1542 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
1543 e1000_down(adapter
);
1544 e1000_power_down_phy(adapter
);
1545 e1000_free_irq(adapter
);
1547 e1000_free_all_tx_resources(adapter
);
1548 e1000_free_all_rx_resources(adapter
);
1550 /* kill manageability vlan ID if supported, but not if a vlan with
1551 * the same ID is registered on the host OS (let 8021q kill it) */
1552 if ((adapter
->hw
.mng_cookie
.status
&
1553 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
1555 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
))) {
1556 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1559 /* If AMT is enabled, let the firmware know that the network
1560 * interface is now closed */
1561 if (adapter
->hw
.mac_type
== e1000_82573
&&
1562 e1000_check_mng_mode(&adapter
->hw
))
1563 e1000_release_hw_control(adapter
);
1569 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1570 * @adapter: address of board private structure
1571 * @start: address of beginning of memory
1572 * @len: length of memory
1575 e1000_check_64k_bound(struct e1000_adapter
*adapter
,
1576 void *start
, unsigned long len
)
1578 unsigned long begin
= (unsigned long) start
;
1579 unsigned long end
= begin
+ len
;
1581 /* First rev 82545 and 82546 need to not allow any memory
1582 * write location to cross 64k boundary due to errata 23 */
1583 if (adapter
->hw
.mac_type
== e1000_82545
||
1584 adapter
->hw
.mac_type
== e1000_82546
) {
1585 return ((begin
^ (end
- 1)) >> 16) != 0 ? false : true;
1592 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1593 * @adapter: board private structure
1594 * @txdr: tx descriptor ring (for a specific queue) to setup
1596 * Return 0 on success, negative on failure
1600 e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1601 struct e1000_tx_ring
*txdr
)
1603 struct pci_dev
*pdev
= adapter
->pdev
;
1606 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1607 txdr
->buffer_info
= vmalloc(size
);
1608 if (!txdr
->buffer_info
) {
1610 "Unable to allocate memory for the transmit descriptor ring\n");
1613 memset(txdr
->buffer_info
, 0, size
);
1615 /* round up to nearest 4K */
1617 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1618 txdr
->size
= ALIGN(txdr
->size
, 4096);
1620 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1623 vfree(txdr
->buffer_info
);
1625 "Unable to allocate memory for the transmit descriptor ring\n");
1629 /* Fix for errata 23, can't cross 64kB boundary */
1630 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1631 void *olddesc
= txdr
->desc
;
1632 dma_addr_t olddma
= txdr
->dma
;
1633 DPRINTK(TX_ERR
, ERR
, "txdr align check failed: %u bytes "
1634 "at %p\n", txdr
->size
, txdr
->desc
);
1635 /* Try again, without freeing the previous */
1636 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1637 /* Failed allocation, critical failure */
1639 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1640 goto setup_tx_desc_die
;
1643 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1645 pci_free_consistent(pdev
, txdr
->size
, txdr
->desc
,
1647 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1649 "Unable to allocate aligned memory "
1650 "for the transmit descriptor ring\n");
1651 vfree(txdr
->buffer_info
);
1654 /* Free old allocation, new allocation was successful */
1655 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1658 memset(txdr
->desc
, 0, txdr
->size
);
1660 txdr
->next_to_use
= 0;
1661 txdr
->next_to_clean
= 0;
1662 spin_lock_init(&txdr
->tx_lock
);
1668 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1669 * (Descriptors) for all queues
1670 * @adapter: board private structure
1672 * Return 0 on success, negative on failure
1676 e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1680 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1681 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1684 "Allocation for Tx Queue %u failed\n", i
);
1685 for (i
-- ; i
>= 0; i
--)
1686 e1000_free_tx_resources(adapter
,
1687 &adapter
->tx_ring
[i
]);
1696 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1697 * @adapter: board private structure
1699 * Configure the Tx unit of the MAC after a reset.
1703 e1000_configure_tx(struct e1000_adapter
*adapter
)
1706 struct e1000_hw
*hw
= &adapter
->hw
;
1707 u32 tdlen
, tctl
, tipg
, tarc
;
1710 /* Setup the HW Tx Head and Tail descriptor pointers */
1712 switch (adapter
->num_tx_queues
) {
1715 tdba
= adapter
->tx_ring
[0].dma
;
1716 tdlen
= adapter
->tx_ring
[0].count
*
1717 sizeof(struct e1000_tx_desc
);
1718 E1000_WRITE_REG(hw
, TDLEN
, tdlen
);
1719 E1000_WRITE_REG(hw
, TDBAH
, (tdba
>> 32));
1720 E1000_WRITE_REG(hw
, TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1721 E1000_WRITE_REG(hw
, TDT
, 0);
1722 E1000_WRITE_REG(hw
, TDH
, 0);
1723 adapter
->tx_ring
[0].tdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDH
: E1000_82542_TDH
);
1724 adapter
->tx_ring
[0].tdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDT
: E1000_82542_TDT
);
1728 /* Set the default values for the Tx Inter Packet Gap timer */
1729 if (adapter
->hw
.mac_type
<= e1000_82547_rev_2
&&
1730 (hw
->media_type
== e1000_media_type_fiber
||
1731 hw
->media_type
== e1000_media_type_internal_serdes
))
1732 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1734 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1736 switch (hw
->mac_type
) {
1737 case e1000_82542_rev2_0
:
1738 case e1000_82542_rev2_1
:
1739 tipg
= DEFAULT_82542_TIPG_IPGT
;
1740 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
1741 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
1743 case e1000_80003es2lan
:
1744 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1745 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
;
1748 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1749 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
1752 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1753 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1754 E1000_WRITE_REG(hw
, TIPG
, tipg
);
1756 /* Set the Tx Interrupt Delay register */
1758 E1000_WRITE_REG(hw
, TIDV
, adapter
->tx_int_delay
);
1759 if (hw
->mac_type
>= e1000_82540
)
1760 E1000_WRITE_REG(hw
, TADV
, adapter
->tx_abs_int_delay
);
1762 /* Program the Transmit Control Register */
1764 tctl
= E1000_READ_REG(hw
, TCTL
);
1765 tctl
&= ~E1000_TCTL_CT
;
1766 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1767 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1769 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
1770 tarc
= E1000_READ_REG(hw
, TARC0
);
1771 /* set the speed mode bit, we'll clear it if we're not at
1772 * gigabit link later */
1774 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1775 } else if (hw
->mac_type
== e1000_80003es2lan
) {
1776 tarc
= E1000_READ_REG(hw
, TARC0
);
1778 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1779 tarc
= E1000_READ_REG(hw
, TARC1
);
1781 E1000_WRITE_REG(hw
, TARC1
, tarc
);
1784 e1000_config_collision_dist(hw
);
1786 /* Setup Transmit Descriptor Settings for eop descriptor */
1787 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
1789 /* only set IDE if we are delaying interrupts using the timers */
1790 if (adapter
->tx_int_delay
)
1791 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
1793 if (hw
->mac_type
< e1000_82543
)
1794 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1796 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1798 /* Cache if we're 82544 running in PCI-X because we'll
1799 * need this to apply a workaround later in the send path. */
1800 if (hw
->mac_type
== e1000_82544
&&
1801 hw
->bus_type
== e1000_bus_type_pcix
)
1802 adapter
->pcix_82544
= 1;
1804 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1809 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1810 * @adapter: board private structure
1811 * @rxdr: rx descriptor ring (for a specific queue) to setup
1813 * Returns 0 on success, negative on failure
1817 e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1818 struct e1000_rx_ring
*rxdr
)
1820 struct pci_dev
*pdev
= adapter
->pdev
;
1823 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1824 rxdr
->buffer_info
= vmalloc(size
);
1825 if (!rxdr
->buffer_info
) {
1827 "Unable to allocate memory for the receive descriptor ring\n");
1830 memset(rxdr
->buffer_info
, 0, size
);
1832 rxdr
->ps_page
= kcalloc(rxdr
->count
, sizeof(struct e1000_ps_page
),
1834 if (!rxdr
->ps_page
) {
1835 vfree(rxdr
->buffer_info
);
1837 "Unable to allocate memory for the receive descriptor ring\n");
1841 rxdr
->ps_page_dma
= kcalloc(rxdr
->count
,
1842 sizeof(struct e1000_ps_page_dma
),
1844 if (!rxdr
->ps_page_dma
) {
1845 vfree(rxdr
->buffer_info
);
1846 kfree(rxdr
->ps_page
);
1848 "Unable to allocate memory for the receive descriptor ring\n");
1852 if (adapter
->hw
.mac_type
<= e1000_82547_rev_2
)
1853 desc_len
= sizeof(struct e1000_rx_desc
);
1855 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1857 /* Round up to nearest 4K */
1859 rxdr
->size
= rxdr
->count
* desc_len
;
1860 rxdr
->size
= ALIGN(rxdr
->size
, 4096);
1862 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1866 "Unable to allocate memory for the receive descriptor ring\n");
1868 vfree(rxdr
->buffer_info
);
1869 kfree(rxdr
->ps_page
);
1870 kfree(rxdr
->ps_page_dma
);
1874 /* Fix for errata 23, can't cross 64kB boundary */
1875 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1876 void *olddesc
= rxdr
->desc
;
1877 dma_addr_t olddma
= rxdr
->dma
;
1878 DPRINTK(RX_ERR
, ERR
, "rxdr align check failed: %u bytes "
1879 "at %p\n", rxdr
->size
, rxdr
->desc
);
1880 /* Try again, without freeing the previous */
1881 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1882 /* Failed allocation, critical failure */
1884 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1886 "Unable to allocate memory "
1887 "for the receive descriptor ring\n");
1888 goto setup_rx_desc_die
;
1891 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1893 pci_free_consistent(pdev
, rxdr
->size
, rxdr
->desc
,
1895 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1897 "Unable to allocate aligned memory "
1898 "for the receive descriptor ring\n");
1899 goto setup_rx_desc_die
;
1901 /* Free old allocation, new allocation was successful */
1902 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1905 memset(rxdr
->desc
, 0, rxdr
->size
);
1907 rxdr
->next_to_clean
= 0;
1908 rxdr
->next_to_use
= 0;
1914 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1915 * (Descriptors) for all queues
1916 * @adapter: board private structure
1918 * Return 0 on success, negative on failure
1922 e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1926 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1927 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1930 "Allocation for Rx Queue %u failed\n", i
);
1931 for (i
-- ; i
>= 0; i
--)
1932 e1000_free_rx_resources(adapter
,
1933 &adapter
->rx_ring
[i
]);
1942 * e1000_setup_rctl - configure the receive control registers
1943 * @adapter: Board private structure
1945 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1946 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1948 e1000_setup_rctl(struct e1000_adapter
*adapter
)
1952 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1956 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1958 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1960 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1961 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1962 (adapter
->hw
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1964 if (adapter
->hw
.tbi_compatibility_on
== 1)
1965 rctl
|= E1000_RCTL_SBP
;
1967 rctl
&= ~E1000_RCTL_SBP
;
1969 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1970 rctl
&= ~E1000_RCTL_LPE
;
1972 rctl
|= E1000_RCTL_LPE
;
1974 /* Setup buffer sizes */
1975 rctl
&= ~E1000_RCTL_SZ_4096
;
1976 rctl
|= E1000_RCTL_BSEX
;
1977 switch (adapter
->rx_buffer_len
) {
1978 case E1000_RXBUFFER_256
:
1979 rctl
|= E1000_RCTL_SZ_256
;
1980 rctl
&= ~E1000_RCTL_BSEX
;
1982 case E1000_RXBUFFER_512
:
1983 rctl
|= E1000_RCTL_SZ_512
;
1984 rctl
&= ~E1000_RCTL_BSEX
;
1986 case E1000_RXBUFFER_1024
:
1987 rctl
|= E1000_RCTL_SZ_1024
;
1988 rctl
&= ~E1000_RCTL_BSEX
;
1990 case E1000_RXBUFFER_2048
:
1992 rctl
|= E1000_RCTL_SZ_2048
;
1993 rctl
&= ~E1000_RCTL_BSEX
;
1995 case E1000_RXBUFFER_4096
:
1996 rctl
|= E1000_RCTL_SZ_4096
;
1998 case E1000_RXBUFFER_8192
:
1999 rctl
|= E1000_RCTL_SZ_8192
;
2001 case E1000_RXBUFFER_16384
:
2002 rctl
|= E1000_RCTL_SZ_16384
;
2006 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
2007 /* 82571 and greater support packet-split where the protocol
2008 * header is placed in skb->data and the packet data is
2009 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2010 * In the case of a non-split, skb->data is linearly filled,
2011 * followed by the page buffers. Therefore, skb->data is
2012 * sized to hold the largest protocol header.
2014 /* allocations using alloc_page take too long for regular MTU
2015 * so only enable packet split for jumbo frames */
2016 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
2017 if ((adapter
->hw
.mac_type
>= e1000_82571
) && (pages
<= 3) &&
2018 PAGE_SIZE
<= 16384 && (rctl
& E1000_RCTL_LPE
))
2019 adapter
->rx_ps_pages
= pages
;
2021 adapter
->rx_ps_pages
= 0;
2023 if (adapter
->rx_ps_pages
) {
2024 /* Configure extra packet-split registers */
2025 rfctl
= E1000_READ_REG(&adapter
->hw
, RFCTL
);
2026 rfctl
|= E1000_RFCTL_EXTEN
;
2027 /* disable packet split support for IPv6 extension headers,
2028 * because some malformed IPv6 headers can hang the RX */
2029 rfctl
|= (E1000_RFCTL_IPV6_EX_DIS
|
2030 E1000_RFCTL_NEW_IPV6_EXT_DIS
);
2032 E1000_WRITE_REG(&adapter
->hw
, RFCTL
, rfctl
);
2034 rctl
|= E1000_RCTL_DTYP_PS
;
2036 psrctl
|= adapter
->rx_ps_bsize0
>>
2037 E1000_PSRCTL_BSIZE0_SHIFT
;
2039 switch (adapter
->rx_ps_pages
) {
2041 psrctl
|= PAGE_SIZE
<<
2042 E1000_PSRCTL_BSIZE3_SHIFT
;
2044 psrctl
|= PAGE_SIZE
<<
2045 E1000_PSRCTL_BSIZE2_SHIFT
;
2047 psrctl
|= PAGE_SIZE
>>
2048 E1000_PSRCTL_BSIZE1_SHIFT
;
2052 E1000_WRITE_REG(&adapter
->hw
, PSRCTL
, psrctl
);
2055 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2059 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2060 * @adapter: board private structure
2062 * Configure the Rx unit of the MAC after a reset.
2066 e1000_configure_rx(struct e1000_adapter
*adapter
)
2069 struct e1000_hw
*hw
= &adapter
->hw
;
2070 u32 rdlen
, rctl
, rxcsum
, ctrl_ext
;
2072 if (adapter
->rx_ps_pages
) {
2073 /* this is a 32 byte descriptor */
2074 rdlen
= adapter
->rx_ring
[0].count
*
2075 sizeof(union e1000_rx_desc_packet_split
);
2076 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
2077 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
2079 rdlen
= adapter
->rx_ring
[0].count
*
2080 sizeof(struct e1000_rx_desc
);
2081 adapter
->clean_rx
= e1000_clean_rx_irq
;
2082 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
2085 /* disable receives while setting up the descriptors */
2086 rctl
= E1000_READ_REG(hw
, RCTL
);
2087 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
2089 /* set the Receive Delay Timer Register */
2090 E1000_WRITE_REG(hw
, RDTR
, adapter
->rx_int_delay
);
2092 if (hw
->mac_type
>= e1000_82540
) {
2093 E1000_WRITE_REG(hw
, RADV
, adapter
->rx_abs_int_delay
);
2094 if (adapter
->itr_setting
!= 0)
2095 E1000_WRITE_REG(hw
, ITR
,
2096 1000000000 / (adapter
->itr
* 256));
2099 if (hw
->mac_type
>= e1000_82571
) {
2100 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
2101 /* Reset delay timers after every interrupt */
2102 ctrl_ext
|= E1000_CTRL_EXT_INT_TIMER_CLR
;
2103 #ifdef CONFIG_E1000_NAPI
2104 /* Auto-Mask interrupts upon ICR access */
2105 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
2106 E1000_WRITE_REG(hw
, IAM
, 0xffffffff);
2108 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
2109 E1000_WRITE_FLUSH(hw
);
2112 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2113 * the Base and Length of the Rx Descriptor Ring */
2114 switch (adapter
->num_rx_queues
) {
2117 rdba
= adapter
->rx_ring
[0].dma
;
2118 E1000_WRITE_REG(hw
, RDLEN
, rdlen
);
2119 E1000_WRITE_REG(hw
, RDBAH
, (rdba
>> 32));
2120 E1000_WRITE_REG(hw
, RDBAL
, (rdba
& 0x00000000ffffffffULL
));
2121 E1000_WRITE_REG(hw
, RDT
, 0);
2122 E1000_WRITE_REG(hw
, RDH
, 0);
2123 adapter
->rx_ring
[0].rdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDH
: E1000_82542_RDH
);
2124 adapter
->rx_ring
[0].rdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDT
: E1000_82542_RDT
);
2128 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2129 if (hw
->mac_type
>= e1000_82543
) {
2130 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
2131 if (adapter
->rx_csum
) {
2132 rxcsum
|= E1000_RXCSUM_TUOFL
;
2134 /* Enable 82571 IPv4 payload checksum for UDP fragments
2135 * Must be used in conjunction with packet-split. */
2136 if ((hw
->mac_type
>= e1000_82571
) &&
2137 (adapter
->rx_ps_pages
)) {
2138 rxcsum
|= E1000_RXCSUM_IPPCSE
;
2141 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
2142 /* don't need to clear IPPCSE as it defaults to 0 */
2144 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
2147 /* enable early receives on 82573, only takes effect if using > 2048
2148 * byte total frame size. for example only for jumbo frames */
2149 #define E1000_ERT_2048 0x100
2150 if (hw
->mac_type
== e1000_82573
)
2151 E1000_WRITE_REG(hw
, ERT
, E1000_ERT_2048
);
2153 /* Enable Receives */
2154 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2158 * e1000_free_tx_resources - Free Tx Resources per Queue
2159 * @adapter: board private structure
2160 * @tx_ring: Tx descriptor ring for a specific queue
2162 * Free all transmit software resources
2166 e1000_free_tx_resources(struct e1000_adapter
*adapter
,
2167 struct e1000_tx_ring
*tx_ring
)
2169 struct pci_dev
*pdev
= adapter
->pdev
;
2171 e1000_clean_tx_ring(adapter
, tx_ring
);
2173 vfree(tx_ring
->buffer_info
);
2174 tx_ring
->buffer_info
= NULL
;
2176 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
2178 tx_ring
->desc
= NULL
;
2182 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
2183 * @adapter: board private structure
2185 * Free all transmit software resources
2189 e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
2193 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2194 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
2198 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
2199 struct e1000_buffer
*buffer_info
)
2201 if (buffer_info
->dma
) {
2202 pci_unmap_page(adapter
->pdev
,
2204 buffer_info
->length
,
2206 buffer_info
->dma
= 0;
2208 if (buffer_info
->skb
) {
2209 dev_kfree_skb_any(buffer_info
->skb
);
2210 buffer_info
->skb
= NULL
;
2212 /* buffer_info must be completely set up in the transmit path */
2216 * e1000_clean_tx_ring - Free Tx Buffers
2217 * @adapter: board private structure
2218 * @tx_ring: ring to be cleaned
2222 e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
2223 struct e1000_tx_ring
*tx_ring
)
2225 struct e1000_buffer
*buffer_info
;
2229 /* Free all the Tx ring sk_buffs */
2231 for (i
= 0; i
< tx_ring
->count
; i
++) {
2232 buffer_info
= &tx_ring
->buffer_info
[i
];
2233 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
2236 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
2237 memset(tx_ring
->buffer_info
, 0, size
);
2239 /* Zero out the descriptor ring */
2241 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2243 tx_ring
->next_to_use
= 0;
2244 tx_ring
->next_to_clean
= 0;
2245 tx_ring
->last_tx_tso
= 0;
2247 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdh
);
2248 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
2252 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2253 * @adapter: board private structure
2257 e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
2261 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2262 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
2266 * e1000_free_rx_resources - Free Rx Resources
2267 * @adapter: board private structure
2268 * @rx_ring: ring to clean the resources from
2270 * Free all receive software resources
2274 e1000_free_rx_resources(struct e1000_adapter
*adapter
,
2275 struct e1000_rx_ring
*rx_ring
)
2277 struct pci_dev
*pdev
= adapter
->pdev
;
2279 e1000_clean_rx_ring(adapter
, rx_ring
);
2281 vfree(rx_ring
->buffer_info
);
2282 rx_ring
->buffer_info
= NULL
;
2283 kfree(rx_ring
->ps_page
);
2284 rx_ring
->ps_page
= NULL
;
2285 kfree(rx_ring
->ps_page_dma
);
2286 rx_ring
->ps_page_dma
= NULL
;
2288 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
2290 rx_ring
->desc
= NULL
;
2294 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2295 * @adapter: board private structure
2297 * Free all receive software resources
2301 e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
2305 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2306 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2310 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2311 * @adapter: board private structure
2312 * @rx_ring: ring to free buffers from
2316 e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
2317 struct e1000_rx_ring
*rx_ring
)
2319 struct e1000_buffer
*buffer_info
;
2320 struct e1000_ps_page
*ps_page
;
2321 struct e1000_ps_page_dma
*ps_page_dma
;
2322 struct pci_dev
*pdev
= adapter
->pdev
;
2326 /* Free all the Rx ring sk_buffs */
2327 for (i
= 0; i
< rx_ring
->count
; i
++) {
2328 buffer_info
= &rx_ring
->buffer_info
[i
];
2329 if (buffer_info
->skb
) {
2330 pci_unmap_single(pdev
,
2332 buffer_info
->length
,
2333 PCI_DMA_FROMDEVICE
);
2335 dev_kfree_skb(buffer_info
->skb
);
2336 buffer_info
->skb
= NULL
;
2338 ps_page
= &rx_ring
->ps_page
[i
];
2339 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2340 for (j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
2341 if (!ps_page
->ps_page
[j
]) break;
2342 pci_unmap_page(pdev
,
2343 ps_page_dma
->ps_page_dma
[j
],
2344 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
2345 ps_page_dma
->ps_page_dma
[j
] = 0;
2346 put_page(ps_page
->ps_page
[j
]);
2347 ps_page
->ps_page
[j
] = NULL
;
2351 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2352 memset(rx_ring
->buffer_info
, 0, size
);
2353 size
= sizeof(struct e1000_ps_page
) * rx_ring
->count
;
2354 memset(rx_ring
->ps_page
, 0, size
);
2355 size
= sizeof(struct e1000_ps_page_dma
) * rx_ring
->count
;
2356 memset(rx_ring
->ps_page_dma
, 0, size
);
2358 /* Zero out the descriptor ring */
2360 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2362 rx_ring
->next_to_clean
= 0;
2363 rx_ring
->next_to_use
= 0;
2365 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdh
);
2366 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
2370 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2371 * @adapter: board private structure
2375 e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2379 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2380 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2383 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2384 * and memory write and invalidate disabled for certain operations
2387 e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2389 struct net_device
*netdev
= adapter
->netdev
;
2392 e1000_pci_clear_mwi(&adapter
->hw
);
2394 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2395 rctl
|= E1000_RCTL_RST
;
2396 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2397 E1000_WRITE_FLUSH(&adapter
->hw
);
2400 if (netif_running(netdev
))
2401 e1000_clean_all_rx_rings(adapter
);
2405 e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2407 struct net_device
*netdev
= adapter
->netdev
;
2410 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2411 rctl
&= ~E1000_RCTL_RST
;
2412 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2413 E1000_WRITE_FLUSH(&adapter
->hw
);
2416 if (adapter
->hw
.pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2417 e1000_pci_set_mwi(&adapter
->hw
);
2419 if (netif_running(netdev
)) {
2420 /* No need to loop, because 82542 supports only 1 queue */
2421 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[0];
2422 e1000_configure_rx(adapter
);
2423 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
2428 * e1000_set_mac - Change the Ethernet Address of the NIC
2429 * @netdev: network interface device structure
2430 * @p: pointer to an address structure
2432 * Returns 0 on success, negative on failure
2436 e1000_set_mac(struct net_device
*netdev
, void *p
)
2438 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2439 struct sockaddr
*addr
= p
;
2441 if (!is_valid_ether_addr(addr
->sa_data
))
2442 return -EADDRNOTAVAIL
;
2444 /* 82542 2.0 needs to be in reset to write receive address registers */
2446 if (adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2447 e1000_enter_82542_rst(adapter
);
2449 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2450 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2452 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2454 /* With 82571 controllers, LAA may be overwritten (with the default)
2455 * due to controller reset from the other port. */
2456 if (adapter
->hw
.mac_type
== e1000_82571
) {
2457 /* activate the work around */
2458 adapter
->hw
.laa_is_present
= 1;
2460 /* Hold a copy of the LAA in RAR[14] This is done so that
2461 * between the time RAR[0] gets clobbered and the time it
2462 * gets fixed (in e1000_watchdog), the actual LAA is in one
2463 * of the RARs and no incoming packets directed to this port
2464 * are dropped. Eventaully the LAA will be in RAR[0] and
2466 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
,
2467 E1000_RAR_ENTRIES
- 1);
2470 if (adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2471 e1000_leave_82542_rst(adapter
);
2477 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2478 * @netdev: network interface device structure
2480 * The set_rx_mode entry point is called whenever the unicast or multicast
2481 * address lists or the network interface flags are updated. This routine is
2482 * responsible for configuring the hardware for proper unicast, multicast,
2483 * promiscuous mode, and all-multi behavior.
2487 e1000_set_rx_mode(struct net_device
*netdev
)
2489 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2490 struct e1000_hw
*hw
= &adapter
->hw
;
2491 struct dev_addr_list
*uc_ptr
;
2492 struct dev_addr_list
*mc_ptr
;
2495 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2496 int mta_reg_count
= (hw
->mac_type
== e1000_ich8lan
) ?
2497 E1000_NUM_MTA_REGISTERS_ICH8LAN
:
2498 E1000_NUM_MTA_REGISTERS
;
2500 if (adapter
->hw
.mac_type
== e1000_ich8lan
)
2501 rar_entries
= E1000_RAR_ENTRIES_ICH8LAN
;
2503 /* reserve RAR[14] for LAA over-write work-around */
2504 if (adapter
->hw
.mac_type
== e1000_82571
)
2507 /* Check for Promiscuous and All Multicast modes */
2509 rctl
= E1000_READ_REG(hw
, RCTL
);
2511 if (netdev
->flags
& IFF_PROMISC
) {
2512 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2513 } else if (netdev
->flags
& IFF_ALLMULTI
) {
2514 rctl
|= E1000_RCTL_MPE
;
2516 rctl
&= ~E1000_RCTL_MPE
;
2520 if (netdev
->uc_count
> rar_entries
- 1) {
2521 rctl
|= E1000_RCTL_UPE
;
2522 } else if (!(netdev
->flags
& IFF_PROMISC
)) {
2523 rctl
&= ~E1000_RCTL_UPE
;
2524 uc_ptr
= netdev
->uc_list
;
2527 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2529 /* 82542 2.0 needs to be in reset to write receive address registers */
2531 if (hw
->mac_type
== e1000_82542_rev2_0
)
2532 e1000_enter_82542_rst(adapter
);
2534 /* load the first 14 addresses into the exact filters 1-14. Unicast
2535 * addresses take precedence to avoid disabling unicast filtering
2538 * RAR 0 is used for the station MAC adddress
2539 * if there are not 14 addresses, go ahead and clear the filters
2540 * -- with 82571 controllers only 0-13 entries are filled here
2542 mc_ptr
= netdev
->mc_list
;
2544 for (i
= 1; i
< rar_entries
; i
++) {
2546 e1000_rar_set(hw
, uc_ptr
->da_addr
, i
);
2547 uc_ptr
= uc_ptr
->next
;
2548 } else if (mc_ptr
) {
2549 e1000_rar_set(hw
, mc_ptr
->da_addr
, i
);
2550 mc_ptr
= mc_ptr
->next
;
2552 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2553 E1000_WRITE_FLUSH(hw
);
2554 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2555 E1000_WRITE_FLUSH(hw
);
2558 WARN_ON(uc_ptr
!= NULL
);
2560 /* clear the old settings from the multicast hash table */
2562 for (i
= 0; i
< mta_reg_count
; i
++) {
2563 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
2564 E1000_WRITE_FLUSH(hw
);
2567 /* load any remaining addresses into the hash table */
2569 for (; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
2570 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->da_addr
);
2571 e1000_mta_set(hw
, hash_value
);
2574 if (hw
->mac_type
== e1000_82542_rev2_0
)
2575 e1000_leave_82542_rst(adapter
);
2578 /* Need to wait a few seconds after link up to get diagnostic information from
2582 e1000_update_phy_info(unsigned long data
)
2584 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2585 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
2589 * e1000_82547_tx_fifo_stall - Timer Call-back
2590 * @data: pointer to adapter cast into an unsigned long
2594 e1000_82547_tx_fifo_stall(unsigned long data
)
2596 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2597 struct net_device
*netdev
= adapter
->netdev
;
2600 if (atomic_read(&adapter
->tx_fifo_stall
)) {
2601 if ((E1000_READ_REG(&adapter
->hw
, TDT
) ==
2602 E1000_READ_REG(&adapter
->hw
, TDH
)) &&
2603 (E1000_READ_REG(&adapter
->hw
, TDFT
) ==
2604 E1000_READ_REG(&adapter
->hw
, TDFH
)) &&
2605 (E1000_READ_REG(&adapter
->hw
, TDFTS
) ==
2606 E1000_READ_REG(&adapter
->hw
, TDFHS
))) {
2607 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2608 E1000_WRITE_REG(&adapter
->hw
, TCTL
,
2609 tctl
& ~E1000_TCTL_EN
);
2610 E1000_WRITE_REG(&adapter
->hw
, TDFT
,
2611 adapter
->tx_head_addr
);
2612 E1000_WRITE_REG(&adapter
->hw
, TDFH
,
2613 adapter
->tx_head_addr
);
2614 E1000_WRITE_REG(&adapter
->hw
, TDFTS
,
2615 adapter
->tx_head_addr
);
2616 E1000_WRITE_REG(&adapter
->hw
, TDFHS
,
2617 adapter
->tx_head_addr
);
2618 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2619 E1000_WRITE_FLUSH(&adapter
->hw
);
2621 adapter
->tx_fifo_head
= 0;
2622 atomic_set(&adapter
->tx_fifo_stall
, 0);
2623 netif_wake_queue(netdev
);
2625 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2631 * e1000_watchdog - Timer Call-back
2632 * @data: pointer to adapter cast into an unsigned long
2635 e1000_watchdog(unsigned long data
)
2637 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2638 struct net_device
*netdev
= adapter
->netdev
;
2639 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2643 ret_val
= e1000_check_for_link(&adapter
->hw
);
2644 if ((ret_val
== E1000_ERR_PHY
) &&
2645 (adapter
->hw
.phy_type
== e1000_phy_igp_3
) &&
2646 (E1000_READ_REG(&adapter
->hw
, CTRL
) & E1000_PHY_CTRL_GBE_DISABLE
)) {
2647 /* See e1000_kumeran_lock_loss_workaround() */
2649 "Gigabit has been disabled, downgrading speed\n");
2652 if (adapter
->hw
.mac_type
== e1000_82573
) {
2653 e1000_enable_tx_pkt_filtering(&adapter
->hw
);
2654 if (adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
)
2655 e1000_update_mng_vlan(adapter
);
2658 if ((adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) &&
2659 !(E1000_READ_REG(&adapter
->hw
, TXCW
) & E1000_TXCW_ANE
))
2660 link
= !adapter
->hw
.serdes_link_down
;
2662 link
= E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_LU
;
2665 if (!netif_carrier_ok(netdev
)) {
2668 e1000_get_speed_and_duplex(&adapter
->hw
,
2669 &adapter
->link_speed
,
2670 &adapter
->link_duplex
);
2672 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
2673 DPRINTK(LINK
, INFO
, "NIC Link is Up %d Mbps %s, "
2674 "Flow Control: %s\n",
2675 adapter
->link_speed
,
2676 adapter
->link_duplex
== FULL_DUPLEX
?
2677 "Full Duplex" : "Half Duplex",
2678 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
&
2679 E1000_CTRL_RFCE
)) ? "RX/TX" : ((ctrl
&
2680 E1000_CTRL_RFCE
) ? "RX" : ((ctrl
&
2681 E1000_CTRL_TFCE
) ? "TX" : "None" )));
2683 /* tweak tx_queue_len according to speed/duplex
2684 * and adjust the timeout factor */
2685 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2686 adapter
->tx_timeout_factor
= 1;
2687 switch (adapter
->link_speed
) {
2690 netdev
->tx_queue_len
= 10;
2691 adapter
->tx_timeout_factor
= 8;
2695 netdev
->tx_queue_len
= 100;
2696 /* maybe add some timeout factor ? */
2700 if ((adapter
->hw
.mac_type
== e1000_82571
||
2701 adapter
->hw
.mac_type
== e1000_82572
) &&
2704 tarc0
= E1000_READ_REG(&adapter
->hw
, TARC0
);
2705 tarc0
&= ~(1 << 21);
2706 E1000_WRITE_REG(&adapter
->hw
, TARC0
, tarc0
);
2709 /* disable TSO for pcie and 10/100 speeds, to avoid
2710 * some hardware issues */
2711 if (!adapter
->tso_force
&&
2712 adapter
->hw
.bus_type
== e1000_bus_type_pci_express
){
2713 switch (adapter
->link_speed
) {
2717 "10/100 speed: disabling TSO\n");
2718 netdev
->features
&= ~NETIF_F_TSO
;
2719 netdev
->features
&= ~NETIF_F_TSO6
;
2722 netdev
->features
|= NETIF_F_TSO
;
2723 netdev
->features
|= NETIF_F_TSO6
;
2731 /* enable transmits in the hardware, need to do this
2732 * after setting TARC0 */
2733 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2734 tctl
|= E1000_TCTL_EN
;
2735 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2737 netif_carrier_on(netdev
);
2738 netif_wake_queue(netdev
);
2739 mod_timer(&adapter
->phy_info_timer
, round_jiffies(jiffies
+ 2 * HZ
));
2740 adapter
->smartspeed
= 0;
2742 /* make sure the receive unit is started */
2743 if (adapter
->hw
.rx_needs_kicking
) {
2744 struct e1000_hw
*hw
= &adapter
->hw
;
2745 u32 rctl
= E1000_READ_REG(hw
, RCTL
);
2746 E1000_WRITE_REG(hw
, RCTL
, rctl
| E1000_RCTL_EN
);
2750 if (netif_carrier_ok(netdev
)) {
2751 adapter
->link_speed
= 0;
2752 adapter
->link_duplex
= 0;
2753 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
2754 netif_carrier_off(netdev
);
2755 netif_stop_queue(netdev
);
2756 mod_timer(&adapter
->phy_info_timer
, round_jiffies(jiffies
+ 2 * HZ
));
2758 /* 80003ES2LAN workaround--
2759 * For packet buffer work-around on link down event;
2760 * disable receives in the ISR and
2761 * reset device here in the watchdog
2763 if (adapter
->hw
.mac_type
== e1000_80003es2lan
)
2765 schedule_work(&adapter
->reset_task
);
2768 e1000_smartspeed(adapter
);
2771 e1000_update_stats(adapter
);
2773 adapter
->hw
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2774 adapter
->tpt_old
= adapter
->stats
.tpt
;
2775 adapter
->hw
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2776 adapter
->colc_old
= adapter
->stats
.colc
;
2778 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2779 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2780 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2781 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2783 e1000_update_adaptive(&adapter
->hw
);
2785 if (!netif_carrier_ok(netdev
)) {
2786 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2787 /* We've lost link, so the controller stops DMA,
2788 * but we've got queued Tx work that's never going
2789 * to get done, so reset controller to flush Tx.
2790 * (Do the reset outside of interrupt context). */
2791 adapter
->tx_timeout_count
++;
2792 schedule_work(&adapter
->reset_task
);
2796 /* Cause software interrupt to ensure rx ring is cleaned */
2797 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_RXDMT0
);
2799 /* Force detection of hung controller every watchdog period */
2800 adapter
->detect_tx_hung
= true;
2802 /* With 82571 controllers, LAA may be overwritten due to controller
2803 * reset from the other port. Set the appropriate LAA in RAR[0] */
2804 if (adapter
->hw
.mac_type
== e1000_82571
&& adapter
->hw
.laa_is_present
)
2805 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2807 /* Reset the timer */
2808 mod_timer(&adapter
->watchdog_timer
, round_jiffies(jiffies
+ 2 * HZ
));
2811 enum latency_range
{
2815 latency_invalid
= 255
2819 * e1000_update_itr - update the dynamic ITR value based on statistics
2820 * Stores a new ITR value based on packets and byte
2821 * counts during the last interrupt. The advantage of per interrupt
2822 * computation is faster updates and more accurate ITR for the current
2823 * traffic pattern. Constants in this function were computed
2824 * based on theoretical maximum wire speed and thresholds were set based
2825 * on testing data as well as attempting to minimize response time
2826 * while increasing bulk throughput.
2827 * this functionality is controlled by the InterruptThrottleRate module
2828 * parameter (see e1000_param.c)
2829 * @adapter: pointer to adapter
2830 * @itr_setting: current adapter->itr
2831 * @packets: the number of packets during this measurement interval
2832 * @bytes: the number of bytes during this measurement interval
2834 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
2839 unsigned int retval
= itr_setting
;
2840 struct e1000_hw
*hw
= &adapter
->hw
;
2842 if (unlikely(hw
->mac_type
< e1000_82540
))
2843 goto update_itr_done
;
2846 goto update_itr_done
;
2848 switch (itr_setting
) {
2849 case lowest_latency
:
2850 /* jumbo frames get bulk treatment*/
2851 if (bytes
/packets
> 8000)
2852 retval
= bulk_latency
;
2853 else if ((packets
< 5) && (bytes
> 512))
2854 retval
= low_latency
;
2856 case low_latency
: /* 50 usec aka 20000 ints/s */
2857 if (bytes
> 10000) {
2858 /* jumbo frames need bulk latency setting */
2859 if (bytes
/packets
> 8000)
2860 retval
= bulk_latency
;
2861 else if ((packets
< 10) || ((bytes
/packets
) > 1200))
2862 retval
= bulk_latency
;
2863 else if ((packets
> 35))
2864 retval
= lowest_latency
;
2865 } else if (bytes
/packets
> 2000)
2866 retval
= bulk_latency
;
2867 else if (packets
<= 2 && bytes
< 512)
2868 retval
= lowest_latency
;
2870 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2871 if (bytes
> 25000) {
2873 retval
= low_latency
;
2874 } else if (bytes
< 6000) {
2875 retval
= low_latency
;
2884 static void e1000_set_itr(struct e1000_adapter
*adapter
)
2886 struct e1000_hw
*hw
= &adapter
->hw
;
2888 u32 new_itr
= adapter
->itr
;
2890 if (unlikely(hw
->mac_type
< e1000_82540
))
2893 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2894 if (unlikely(adapter
->link_speed
!= SPEED_1000
)) {
2900 adapter
->tx_itr
= e1000_update_itr(adapter
,
2902 adapter
->total_tx_packets
,
2903 adapter
->total_tx_bytes
);
2904 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2905 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
2906 adapter
->tx_itr
= low_latency
;
2908 adapter
->rx_itr
= e1000_update_itr(adapter
,
2910 adapter
->total_rx_packets
,
2911 adapter
->total_rx_bytes
);
2912 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2913 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
2914 adapter
->rx_itr
= low_latency
;
2916 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2918 switch (current_itr
) {
2919 /* counts and packets in update_itr are dependent on these numbers */
2920 case lowest_latency
:
2924 new_itr
= 20000; /* aka hwitr = ~200 */
2934 if (new_itr
!= adapter
->itr
) {
2935 /* this attempts to bias the interrupt rate towards Bulk
2936 * by adding intermediate steps when interrupt rate is
2938 new_itr
= new_itr
> adapter
->itr
?
2939 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2941 adapter
->itr
= new_itr
;
2942 E1000_WRITE_REG(hw
, ITR
, 1000000000 / (new_itr
* 256));
2948 #define E1000_TX_FLAGS_CSUM 0x00000001
2949 #define E1000_TX_FLAGS_VLAN 0x00000002
2950 #define E1000_TX_FLAGS_TSO 0x00000004
2951 #define E1000_TX_FLAGS_IPV4 0x00000008
2952 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2953 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2956 e1000_tso(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2957 struct sk_buff
*skb
)
2959 struct e1000_context_desc
*context_desc
;
2960 struct e1000_buffer
*buffer_info
;
2963 u16 ipcse
= 0, tucse
, mss
;
2964 u8 ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2967 if (skb_is_gso(skb
)) {
2968 if (skb_header_cloned(skb
)) {
2969 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2974 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2975 mss
= skb_shinfo(skb
)->gso_size
;
2976 if (skb
->protocol
== htons(ETH_P_IP
)) {
2977 struct iphdr
*iph
= ip_hdr(skb
);
2980 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2984 cmd_length
= E1000_TXD_CMD_IP
;
2985 ipcse
= skb_transport_offset(skb
) - 1;
2986 } else if (skb
->protocol
== htons(ETH_P_IPV6
)) {
2987 ipv6_hdr(skb
)->payload_len
= 0;
2988 tcp_hdr(skb
)->check
=
2989 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2990 &ipv6_hdr(skb
)->daddr
,
2994 ipcss
= skb_network_offset(skb
);
2995 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
2996 tucss
= skb_transport_offset(skb
);
2997 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
3000 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
3001 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
3003 i
= tx_ring
->next_to_use
;
3004 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
3005 buffer_info
= &tx_ring
->buffer_info
[i
];
3007 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
3008 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
3009 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
3010 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
3011 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
3012 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
3013 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
3014 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
3015 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
3017 buffer_info
->time_stamp
= jiffies
;
3018 buffer_info
->next_to_watch
= i
;
3020 if (++i
== tx_ring
->count
) i
= 0;
3021 tx_ring
->next_to_use
= i
;
3029 e1000_tx_csum(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
3030 struct sk_buff
*skb
)
3032 struct e1000_context_desc
*context_desc
;
3033 struct e1000_buffer
*buffer_info
;
3037 if (likely(skb
->ip_summed
== CHECKSUM_PARTIAL
)) {
3038 css
= skb_transport_offset(skb
);
3040 i
= tx_ring
->next_to_use
;
3041 buffer_info
= &tx_ring
->buffer_info
[i
];
3042 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
3044 context_desc
->lower_setup
.ip_config
= 0;
3045 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
3046 context_desc
->upper_setup
.tcp_fields
.tucso
=
3047 css
+ skb
->csum_offset
;
3048 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
3049 context_desc
->tcp_seg_setup
.data
= 0;
3050 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
3052 buffer_info
->time_stamp
= jiffies
;
3053 buffer_info
->next_to_watch
= i
;
3055 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3056 tx_ring
->next_to_use
= i
;
3064 #define E1000_MAX_TXD_PWR 12
3065 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
3068 e1000_tx_map(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
3069 struct sk_buff
*skb
, unsigned int first
, unsigned int max_per_txd
,
3070 unsigned int nr_frags
, unsigned int mss
)
3072 struct e1000_buffer
*buffer_info
;
3073 unsigned int len
= skb
->len
;
3074 unsigned int offset
= 0, size
, count
= 0, i
;
3076 len
-= skb
->data_len
;
3078 i
= tx_ring
->next_to_use
;
3081 buffer_info
= &tx_ring
->buffer_info
[i
];
3082 size
= min(len
, max_per_txd
);
3083 /* Workaround for Controller erratum --
3084 * descriptor for non-tso packet in a linear SKB that follows a
3085 * tso gets written back prematurely before the data is fully
3086 * DMA'd to the controller */
3087 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
3089 tx_ring
->last_tx_tso
= 0;
3093 /* Workaround for premature desc write-backs
3094 * in TSO mode. Append 4-byte sentinel desc */
3095 if (unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
3097 /* work-around for errata 10 and it applies
3098 * to all controllers in PCI-X mode
3099 * The fix is to make sure that the first descriptor of a
3100 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3102 if (unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
3103 (size
> 2015) && count
== 0))
3106 /* Workaround for potential 82544 hang in PCI-X. Avoid
3107 * terminating buffers within evenly-aligned dwords. */
3108 if (unlikely(adapter
->pcix_82544
&&
3109 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
3113 buffer_info
->length
= size
;
3115 pci_map_single(adapter
->pdev
,
3119 buffer_info
->time_stamp
= jiffies
;
3120 buffer_info
->next_to_watch
= i
;
3125 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3128 for (f
= 0; f
< nr_frags
; f
++) {
3129 struct skb_frag_struct
*frag
;
3131 frag
= &skb_shinfo(skb
)->frags
[f
];
3133 offset
= frag
->page_offset
;
3136 buffer_info
= &tx_ring
->buffer_info
[i
];
3137 size
= min(len
, max_per_txd
);
3138 /* Workaround for premature desc write-backs
3139 * in TSO mode. Append 4-byte sentinel desc */
3140 if (unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
3142 /* Workaround for potential 82544 hang in PCI-X.
3143 * Avoid terminating buffers within evenly-aligned
3145 if (unlikely(adapter
->pcix_82544
&&
3146 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
3150 buffer_info
->length
= size
;
3152 pci_map_page(adapter
->pdev
,
3157 buffer_info
->time_stamp
= jiffies
;
3158 buffer_info
->next_to_watch
= i
;
3163 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3167 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
3168 tx_ring
->buffer_info
[i
].skb
= skb
;
3169 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
3175 e1000_tx_queue(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
3176 int tx_flags
, int count
)
3178 struct e1000_tx_desc
*tx_desc
= NULL
;
3179 struct e1000_buffer
*buffer_info
;
3180 u32 txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
3183 if (likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
3184 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
3186 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3188 if (likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
3189 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
3192 if (likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
3193 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
3194 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3197 if (unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
3198 txd_lower
|= E1000_TXD_CMD_VLE
;
3199 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
3202 i
= tx_ring
->next_to_use
;
3205 buffer_info
= &tx_ring
->buffer_info
[i
];
3206 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3207 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3208 tx_desc
->lower
.data
=
3209 cpu_to_le32(txd_lower
| buffer_info
->length
);
3210 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
3211 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3214 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
3216 /* Force memory writes to complete before letting h/w
3217 * know there are new descriptors to fetch. (Only
3218 * applicable for weak-ordered memory model archs,
3219 * such as IA-64). */
3222 tx_ring
->next_to_use
= i
;
3223 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
3224 /* we need this if more than one processor can write to our tail
3225 * at a time, it syncronizes IO on IA64/Altix systems */
3230 * 82547 workaround to avoid controller hang in half-duplex environment.
3231 * The workaround is to avoid queuing a large packet that would span
3232 * the internal Tx FIFO ring boundary by notifying the stack to resend
3233 * the packet at a later time. This gives the Tx FIFO an opportunity to
3234 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3235 * to the beginning of the Tx FIFO.
3238 #define E1000_FIFO_HDR 0x10
3239 #define E1000_82547_PAD_LEN 0x3E0
3242 e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
3244 u32 fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
3245 u32 skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
3247 skb_fifo_len
= ALIGN(skb_fifo_len
, E1000_FIFO_HDR
);
3249 if (adapter
->link_duplex
!= HALF_DUPLEX
)
3250 goto no_fifo_stall_required
;
3252 if (atomic_read(&adapter
->tx_fifo_stall
))
3255 if (skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
3256 atomic_set(&adapter
->tx_fifo_stall
, 1);
3260 no_fifo_stall_required
:
3261 adapter
->tx_fifo_head
+= skb_fifo_len
;
3262 if (adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
3263 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
3267 #define MINIMUM_DHCP_PACKET_SIZE 282
3269 e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
3271 struct e1000_hw
*hw
= &adapter
->hw
;
3273 if (vlan_tx_tag_present(skb
)) {
3274 if (!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
3275 ( adapter
->hw
.mng_cookie
.status
&
3276 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) )
3279 if (skb
->len
> MINIMUM_DHCP_PACKET_SIZE
) {
3280 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
3281 if ((htons(ETH_P_IP
) == eth
->h_proto
)) {
3282 const struct iphdr
*ip
=
3283 (struct iphdr
*)((u8
*)skb
->data
+14);
3284 if (IPPROTO_UDP
== ip
->protocol
) {
3285 struct udphdr
*udp
=
3286 (struct udphdr
*)((u8
*)ip
+
3288 if (ntohs(udp
->dest
) == 67) {
3289 offset
= (u8
*)udp
+ 8 - skb
->data
;
3290 length
= skb
->len
- offset
;
3292 return e1000_mng_write_dhcp_info(hw
,
3302 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
3304 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3305 struct e1000_tx_ring
*tx_ring
= adapter
->tx_ring
;
3307 netif_stop_queue(netdev
);
3308 /* Herbert's original patch had:
3309 * smp_mb__after_netif_stop_queue();
3310 * but since that doesn't exist yet, just open code it. */
3313 /* We need to check again in a case another CPU has just
3314 * made room available. */
3315 if (likely(E1000_DESC_UNUSED(tx_ring
) < size
))
3319 netif_start_queue(netdev
);
3320 ++adapter
->restart_queue
;
3324 static int e1000_maybe_stop_tx(struct net_device
*netdev
,
3325 struct e1000_tx_ring
*tx_ring
, int size
)
3327 if (likely(E1000_DESC_UNUSED(tx_ring
) >= size
))
3329 return __e1000_maybe_stop_tx(netdev
, size
);
3332 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3334 e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
3336 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3337 struct e1000_tx_ring
*tx_ring
;
3338 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
3339 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
3340 unsigned int tx_flags
= 0;
3341 unsigned int len
= skb
->len
- skb
->data_len
;
3342 unsigned long flags
;
3343 unsigned int nr_frags
;
3349 /* This goes back to the question of how to logically map a tx queue
3350 * to a flow. Right now, performance is impacted slightly negatively
3351 * if using multiple tx queues. If the stack breaks away from a
3352 * single qdisc implementation, we can look at this again. */
3353 tx_ring
= adapter
->tx_ring
;
3355 if (unlikely(skb
->len
<= 0)) {
3356 dev_kfree_skb_any(skb
);
3357 return NETDEV_TX_OK
;
3360 /* 82571 and newer doesn't need the workaround that limited descriptor
3362 if (adapter
->hw
.mac_type
>= e1000_82571
)
3365 mss
= skb_shinfo(skb
)->gso_size
;
3366 /* The controller does a simple calculation to
3367 * make sure there is enough room in the FIFO before
3368 * initiating the DMA for each buffer. The calc is:
3369 * 4 = ceil(buffer len/mss). To make sure we don't
3370 * overrun the FIFO, adjust the max buffer len if mss
3374 max_per_txd
= min(mss
<< 2, max_per_txd
);
3375 max_txd_pwr
= fls(max_per_txd
) - 1;
3377 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3378 * points to just header, pull a few bytes of payload from
3379 * frags into skb->data */
3380 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
3381 if (skb
->data_len
&& hdr_len
== len
) {
3382 switch (adapter
->hw
.mac_type
) {
3383 unsigned int pull_size
;
3385 /* Make sure we have room to chop off 4 bytes,
3386 * and that the end alignment will work out to
3387 * this hardware's requirements
3388 * NOTE: this is a TSO only workaround
3389 * if end byte alignment not correct move us
3390 * into the next dword */
3391 if ((unsigned long)(skb_tail_pointer(skb
) - 1) & 4)
3398 pull_size
= min((unsigned int)4, skb
->data_len
);
3399 if (!__pskb_pull_tail(skb
, pull_size
)) {
3401 "__pskb_pull_tail failed.\n");
3402 dev_kfree_skb_any(skb
);
3403 return NETDEV_TX_OK
;
3405 len
= skb
->len
- skb
->data_len
;
3414 /* reserve a descriptor for the offload context */
3415 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3419 /* Controller Erratum workaround */
3420 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&& !skb_is_gso(skb
))
3423 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
3425 if (adapter
->pcix_82544
)
3428 /* work-around for errata 10 and it applies to all controllers
3429 * in PCI-X mode, so add one more descriptor to the count
3431 if (unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
3435 nr_frags
= skb_shinfo(skb
)->nr_frags
;
3436 for (f
= 0; f
< nr_frags
; f
++)
3437 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
3439 if (adapter
->pcix_82544
)
3443 if (adapter
->hw
.tx_pkt_filtering
&&
3444 (adapter
->hw
.mac_type
== e1000_82573
))
3445 e1000_transfer_dhcp_info(adapter
, skb
);
3447 if (!spin_trylock_irqsave(&tx_ring
->tx_lock
, flags
))
3448 /* Collision - tell upper layer to requeue */
3449 return NETDEV_TX_LOCKED
;
3451 /* need: count + 2 desc gap to keep tail from touching
3452 * head, otherwise try next time */
3453 if (unlikely(e1000_maybe_stop_tx(netdev
, tx_ring
, count
+ 2))) {
3454 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3455 return NETDEV_TX_BUSY
;
3458 if (unlikely(adapter
->hw
.mac_type
== e1000_82547
)) {
3459 if (unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
3460 netif_stop_queue(netdev
);
3461 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
3462 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3463 return NETDEV_TX_BUSY
;
3467 if (unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
3468 tx_flags
|= E1000_TX_FLAGS_VLAN
;
3469 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
3472 first
= tx_ring
->next_to_use
;
3474 tso
= e1000_tso(adapter
, tx_ring
, skb
);
3476 dev_kfree_skb_any(skb
);
3477 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3478 return NETDEV_TX_OK
;
3482 tx_ring
->last_tx_tso
= 1;
3483 tx_flags
|= E1000_TX_FLAGS_TSO
;
3484 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
3485 tx_flags
|= E1000_TX_FLAGS_CSUM
;
3487 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3488 * 82571 hardware supports TSO capabilities for IPv6 as well...
3489 * no longer assume, we must. */
3490 if (likely(skb
->protocol
== htons(ETH_P_IP
)))
3491 tx_flags
|= E1000_TX_FLAGS_IPV4
;
3493 e1000_tx_queue(adapter
, tx_ring
, tx_flags
,
3494 e1000_tx_map(adapter
, tx_ring
, skb
, first
,
3495 max_per_txd
, nr_frags
, mss
));
3497 netdev
->trans_start
= jiffies
;
3499 /* Make sure there is space in the ring for the next send. */
3500 e1000_maybe_stop_tx(netdev
, tx_ring
, MAX_SKB_FRAGS
+ 2);
3502 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3503 return NETDEV_TX_OK
;
3507 * e1000_tx_timeout - Respond to a Tx Hang
3508 * @netdev: network interface device structure
3512 e1000_tx_timeout(struct net_device
*netdev
)
3514 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3516 /* Do the reset outside of interrupt context */
3517 adapter
->tx_timeout_count
++;
3518 schedule_work(&adapter
->reset_task
);
3522 e1000_reset_task(struct work_struct
*work
)
3524 struct e1000_adapter
*adapter
=
3525 container_of(work
, struct e1000_adapter
, reset_task
);
3527 e1000_reinit_locked(adapter
);
3531 * e1000_get_stats - Get System Network Statistics
3532 * @netdev: network interface device structure
3534 * Returns the address of the device statistics structure.
3535 * The statistics are actually updated from the timer callback.
3538 static struct net_device_stats
*
3539 e1000_get_stats(struct net_device
*netdev
)
3541 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3543 /* only return the current stats */
3544 return &adapter
->net_stats
;
3548 * e1000_change_mtu - Change the Maximum Transfer Unit
3549 * @netdev: network interface device structure
3550 * @new_mtu: new value for maximum frame size
3552 * Returns 0 on success, negative on failure
3556 e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3558 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3559 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
3560 u16 eeprom_data
= 0;
3562 if ((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
3563 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3564 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
3568 /* Adapter-specific max frame size limits. */
3569 switch (adapter
->hw
.mac_type
) {
3570 case e1000_undefined
... e1000_82542_rev2_1
:
3572 if (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3573 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported.\n");
3578 /* Jumbo Frames not supported if:
3579 * - this is not an 82573L device
3580 * - ASPM is enabled in any way (0x1A bits 3:2) */
3581 e1000_read_eeprom(&adapter
->hw
, EEPROM_INIT_3GIO_3
, 1,
3583 if ((adapter
->hw
.device_id
!= E1000_DEV_ID_82573L
) ||
3584 (eeprom_data
& EEPROM_WORD1A_ASPM_MASK
)) {
3585 if (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3587 "Jumbo Frames not supported.\n");
3592 /* ERT will be enabled later to enable wire speed receives */
3594 /* fall through to get support */
3597 case e1000_80003es2lan
:
3598 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3599 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3600 DPRINTK(PROBE
, ERR
, "MTU > 9216 not supported.\n");
3605 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3609 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3610 * means we reserve 2 more, this pushes us to allocate from the next
3612 * i.e. RXBUFFER_2048 --> size-4096 slab */
3614 if (max_frame
<= E1000_RXBUFFER_256
)
3615 adapter
->rx_buffer_len
= E1000_RXBUFFER_256
;
3616 else if (max_frame
<= E1000_RXBUFFER_512
)
3617 adapter
->rx_buffer_len
= E1000_RXBUFFER_512
;
3618 else if (max_frame
<= E1000_RXBUFFER_1024
)
3619 adapter
->rx_buffer_len
= E1000_RXBUFFER_1024
;
3620 else if (max_frame
<= E1000_RXBUFFER_2048
)
3621 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3622 else if (max_frame
<= E1000_RXBUFFER_4096
)
3623 adapter
->rx_buffer_len
= E1000_RXBUFFER_4096
;
3624 else if (max_frame
<= E1000_RXBUFFER_8192
)
3625 adapter
->rx_buffer_len
= E1000_RXBUFFER_8192
;
3626 else if (max_frame
<= E1000_RXBUFFER_16384
)
3627 adapter
->rx_buffer_len
= E1000_RXBUFFER_16384
;
3629 /* adjust allocation if LPE protects us, and we aren't using SBP */
3630 if (!adapter
->hw
.tbi_compatibility_on
&&
3631 ((max_frame
== MAXIMUM_ETHERNET_FRAME_SIZE
) ||
3632 (max_frame
== MAXIMUM_ETHERNET_VLAN_SIZE
)))
3633 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3635 netdev
->mtu
= new_mtu
;
3636 adapter
->hw
.max_frame_size
= max_frame
;
3638 if (netif_running(netdev
))
3639 e1000_reinit_locked(adapter
);
3645 * e1000_update_stats - Update the board statistics counters
3646 * @adapter: board private structure
3650 e1000_update_stats(struct e1000_adapter
*adapter
)
3652 struct e1000_hw
*hw
= &adapter
->hw
;
3653 struct pci_dev
*pdev
= adapter
->pdev
;
3654 unsigned long flags
;
3657 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3660 * Prevent stats update while adapter is being reset, or if the pci
3661 * connection is down.
3663 if (adapter
->link_speed
== 0)
3665 if (pci_channel_offline(pdev
))
3668 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3670 /* these counters are modified from e1000_tbi_adjust_stats,
3671 * called from the interrupt context, so they must only
3672 * be written while holding adapter->stats_lock
3675 adapter
->stats
.crcerrs
+= E1000_READ_REG(hw
, CRCERRS
);
3676 adapter
->stats
.gprc
+= E1000_READ_REG(hw
, GPRC
);
3677 adapter
->stats
.gorcl
+= E1000_READ_REG(hw
, GORCL
);
3678 adapter
->stats
.gorch
+= E1000_READ_REG(hw
, GORCH
);
3679 adapter
->stats
.bprc
+= E1000_READ_REG(hw
, BPRC
);
3680 adapter
->stats
.mprc
+= E1000_READ_REG(hw
, MPRC
);
3681 adapter
->stats
.roc
+= E1000_READ_REG(hw
, ROC
);
3683 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
3684 adapter
->stats
.prc64
+= E1000_READ_REG(hw
, PRC64
);
3685 adapter
->stats
.prc127
+= E1000_READ_REG(hw
, PRC127
);
3686 adapter
->stats
.prc255
+= E1000_READ_REG(hw
, PRC255
);
3687 adapter
->stats
.prc511
+= E1000_READ_REG(hw
, PRC511
);
3688 adapter
->stats
.prc1023
+= E1000_READ_REG(hw
, PRC1023
);
3689 adapter
->stats
.prc1522
+= E1000_READ_REG(hw
, PRC1522
);
3692 adapter
->stats
.symerrs
+= E1000_READ_REG(hw
, SYMERRS
);
3693 adapter
->stats
.mpc
+= E1000_READ_REG(hw
, MPC
);
3694 adapter
->stats
.scc
+= E1000_READ_REG(hw
, SCC
);
3695 adapter
->stats
.ecol
+= E1000_READ_REG(hw
, ECOL
);
3696 adapter
->stats
.mcc
+= E1000_READ_REG(hw
, MCC
);
3697 adapter
->stats
.latecol
+= E1000_READ_REG(hw
, LATECOL
);
3698 adapter
->stats
.dc
+= E1000_READ_REG(hw
, DC
);
3699 adapter
->stats
.sec
+= E1000_READ_REG(hw
, SEC
);
3700 adapter
->stats
.rlec
+= E1000_READ_REG(hw
, RLEC
);
3701 adapter
->stats
.xonrxc
+= E1000_READ_REG(hw
, XONRXC
);
3702 adapter
->stats
.xontxc
+= E1000_READ_REG(hw
, XONTXC
);
3703 adapter
->stats
.xoffrxc
+= E1000_READ_REG(hw
, XOFFRXC
);
3704 adapter
->stats
.xofftxc
+= E1000_READ_REG(hw
, XOFFTXC
);
3705 adapter
->stats
.fcruc
+= E1000_READ_REG(hw
, FCRUC
);
3706 adapter
->stats
.gptc
+= E1000_READ_REG(hw
, GPTC
);
3707 adapter
->stats
.gotcl
+= E1000_READ_REG(hw
, GOTCL
);
3708 adapter
->stats
.gotch
+= E1000_READ_REG(hw
, GOTCH
);
3709 adapter
->stats
.rnbc
+= E1000_READ_REG(hw
, RNBC
);
3710 adapter
->stats
.ruc
+= E1000_READ_REG(hw
, RUC
);
3711 adapter
->stats
.rfc
+= E1000_READ_REG(hw
, RFC
);
3712 adapter
->stats
.rjc
+= E1000_READ_REG(hw
, RJC
);
3713 adapter
->stats
.torl
+= E1000_READ_REG(hw
, TORL
);
3714 adapter
->stats
.torh
+= E1000_READ_REG(hw
, TORH
);
3715 adapter
->stats
.totl
+= E1000_READ_REG(hw
, TOTL
);
3716 adapter
->stats
.toth
+= E1000_READ_REG(hw
, TOTH
);
3717 adapter
->stats
.tpr
+= E1000_READ_REG(hw
, TPR
);
3719 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
3720 adapter
->stats
.ptc64
+= E1000_READ_REG(hw
, PTC64
);
3721 adapter
->stats
.ptc127
+= E1000_READ_REG(hw
, PTC127
);
3722 adapter
->stats
.ptc255
+= E1000_READ_REG(hw
, PTC255
);
3723 adapter
->stats
.ptc511
+= E1000_READ_REG(hw
, PTC511
);
3724 adapter
->stats
.ptc1023
+= E1000_READ_REG(hw
, PTC1023
);
3725 adapter
->stats
.ptc1522
+= E1000_READ_REG(hw
, PTC1522
);
3728 adapter
->stats
.mptc
+= E1000_READ_REG(hw
, MPTC
);
3729 adapter
->stats
.bptc
+= E1000_READ_REG(hw
, BPTC
);
3731 /* used for adaptive IFS */
3733 hw
->tx_packet_delta
= E1000_READ_REG(hw
, TPT
);
3734 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3735 hw
->collision_delta
= E1000_READ_REG(hw
, COLC
);
3736 adapter
->stats
.colc
+= hw
->collision_delta
;
3738 if (hw
->mac_type
>= e1000_82543
) {
3739 adapter
->stats
.algnerrc
+= E1000_READ_REG(hw
, ALGNERRC
);
3740 adapter
->stats
.rxerrc
+= E1000_READ_REG(hw
, RXERRC
);
3741 adapter
->stats
.tncrs
+= E1000_READ_REG(hw
, TNCRS
);
3742 adapter
->stats
.cexterr
+= E1000_READ_REG(hw
, CEXTERR
);
3743 adapter
->stats
.tsctc
+= E1000_READ_REG(hw
, TSCTC
);
3744 adapter
->stats
.tsctfc
+= E1000_READ_REG(hw
, TSCTFC
);
3746 if (hw
->mac_type
> e1000_82547_rev_2
) {
3747 adapter
->stats
.iac
+= E1000_READ_REG(hw
, IAC
);
3748 adapter
->stats
.icrxoc
+= E1000_READ_REG(hw
, ICRXOC
);
3750 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
3751 adapter
->stats
.icrxptc
+= E1000_READ_REG(hw
, ICRXPTC
);
3752 adapter
->stats
.icrxatc
+= E1000_READ_REG(hw
, ICRXATC
);
3753 adapter
->stats
.ictxptc
+= E1000_READ_REG(hw
, ICTXPTC
);
3754 adapter
->stats
.ictxatc
+= E1000_READ_REG(hw
, ICTXATC
);
3755 adapter
->stats
.ictxqec
+= E1000_READ_REG(hw
, ICTXQEC
);
3756 adapter
->stats
.ictxqmtc
+= E1000_READ_REG(hw
, ICTXQMTC
);
3757 adapter
->stats
.icrxdmtc
+= E1000_READ_REG(hw
, ICRXDMTC
);
3761 /* Fill out the OS statistics structure */
3762 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3763 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3767 /* RLEC on some newer hardware can be incorrect so build
3768 * our own version based on RUC and ROC */
3769 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3770 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3771 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3772 adapter
->stats
.cexterr
;
3773 adapter
->stats
.rlerrc
= adapter
->stats
.ruc
+ adapter
->stats
.roc
;
3774 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlerrc
;
3775 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3776 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3777 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3780 adapter
->stats
.txerrc
= adapter
->stats
.ecol
+ adapter
->stats
.latecol
;
3781 adapter
->net_stats
.tx_errors
= adapter
->stats
.txerrc
;
3782 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3783 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3784 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3785 if (adapter
->hw
.bad_tx_carr_stats_fd
&&
3786 adapter
->link_duplex
== FULL_DUPLEX
) {
3787 adapter
->net_stats
.tx_carrier_errors
= 0;
3788 adapter
->stats
.tncrs
= 0;
3791 /* Tx Dropped needs to be maintained elsewhere */
3794 if (hw
->media_type
== e1000_media_type_copper
) {
3795 if ((adapter
->link_speed
== SPEED_1000
) &&
3796 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3797 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3798 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3801 if ((hw
->mac_type
<= e1000_82546
) &&
3802 (hw
->phy_type
== e1000_phy_m88
) &&
3803 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3804 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3807 /* Management Stats */
3808 if (adapter
->hw
.has_smbus
) {
3809 adapter
->stats
.mgptc
+= E1000_READ_REG(hw
, MGTPTC
);
3810 adapter
->stats
.mgprc
+= E1000_READ_REG(hw
, MGTPRC
);
3811 adapter
->stats
.mgpdc
+= E1000_READ_REG(hw
, MGTPDC
);
3814 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3818 * e1000_intr_msi - Interrupt Handler
3819 * @irq: interrupt number
3820 * @data: pointer to a network interface device structure
3824 e1000_intr_msi(int irq
, void *data
)
3826 struct net_device
*netdev
= data
;
3827 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3828 struct e1000_hw
*hw
= &adapter
->hw
;
3829 #ifndef CONFIG_E1000_NAPI
3832 u32 icr
= E1000_READ_REG(hw
, ICR
);
3834 /* in NAPI mode read ICR disables interrupts using IAM */
3836 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
3837 hw
->get_link_status
= 1;
3838 /* 80003ES2LAN workaround-- For packet buffer work-around on
3839 * link down event; disable receives here in the ISR and reset
3840 * adapter in watchdog */
3841 if (netif_carrier_ok(netdev
) &&
3842 (adapter
->hw
.mac_type
== e1000_80003es2lan
)) {
3843 /* disable receives */
3844 u32 rctl
= E1000_READ_REG(hw
, RCTL
);
3845 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
3847 /* guard against interrupt when we're going down */
3848 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3849 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3852 #ifdef CONFIG_E1000_NAPI
3853 if (likely(netif_rx_schedule_prep(netdev
, &adapter
->napi
))) {
3854 adapter
->total_tx_bytes
= 0;
3855 adapter
->total_tx_packets
= 0;
3856 adapter
->total_rx_bytes
= 0;
3857 adapter
->total_rx_packets
= 0;
3858 __netif_rx_schedule(netdev
, &adapter
->napi
);
3860 e1000_irq_enable(adapter
);
3862 adapter
->total_tx_bytes
= 0;
3863 adapter
->total_rx_bytes
= 0;
3864 adapter
->total_tx_packets
= 0;
3865 adapter
->total_rx_packets
= 0;
3867 for (i
= 0; i
< E1000_MAX_INTR
; i
++)
3868 if (unlikely(!adapter
->clean_rx(adapter
, adapter
->rx_ring
) &
3869 !e1000_clean_tx_irq(adapter
, adapter
->tx_ring
)))
3872 if (likely(adapter
->itr_setting
& 3))
3873 e1000_set_itr(adapter
);
3880 * e1000_intr - Interrupt Handler
3881 * @irq: interrupt number
3882 * @data: pointer to a network interface device structure
3886 e1000_intr(int irq
, void *data
)
3888 struct net_device
*netdev
= data
;
3889 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3890 struct e1000_hw
*hw
= &adapter
->hw
;
3891 u32 rctl
, icr
= E1000_READ_REG(hw
, ICR
);
3892 #ifndef CONFIG_E1000_NAPI
3896 return IRQ_NONE
; /* Not our interrupt */
3898 #ifdef CONFIG_E1000_NAPI
3899 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3900 * not set, then the adapter didn't send an interrupt */
3901 if (unlikely(hw
->mac_type
>= e1000_82571
&&
3902 !(icr
& E1000_ICR_INT_ASSERTED
)))
3905 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3906 * need for the IMC write */
3909 if (unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3910 hw
->get_link_status
= 1;
3911 /* 80003ES2LAN workaround--
3912 * For packet buffer work-around on link down event;
3913 * disable receives here in the ISR and
3914 * reset adapter in watchdog
3916 if (netif_carrier_ok(netdev
) &&
3917 (adapter
->hw
.mac_type
== e1000_80003es2lan
)) {
3918 /* disable receives */
3919 rctl
= E1000_READ_REG(hw
, RCTL
);
3920 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
3922 /* guard against interrupt when we're going down */
3923 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3924 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3927 #ifdef CONFIG_E1000_NAPI
3928 if (unlikely(hw
->mac_type
< e1000_82571
)) {
3929 /* disable interrupts, without the synchronize_irq bit */
3930 E1000_WRITE_REG(hw
, IMC
, ~0);
3931 E1000_WRITE_FLUSH(hw
);
3933 if (likely(netif_rx_schedule_prep(netdev
, &adapter
->napi
))) {
3934 adapter
->total_tx_bytes
= 0;
3935 adapter
->total_tx_packets
= 0;
3936 adapter
->total_rx_bytes
= 0;
3937 adapter
->total_rx_packets
= 0;
3938 __netif_rx_schedule(netdev
, &adapter
->napi
);
3940 /* this really should not happen! if it does it is basically a
3941 * bug, but not a hard error, so enable ints and continue */
3942 e1000_irq_enable(adapter
);
3944 /* Writing IMC and IMS is needed for 82547.
3945 * Due to Hub Link bus being occupied, an interrupt
3946 * de-assertion message is not able to be sent.
3947 * When an interrupt assertion message is generated later,
3948 * two messages are re-ordered and sent out.
3949 * That causes APIC to think 82547 is in de-assertion
3950 * state, while 82547 is in assertion state, resulting
3951 * in dead lock. Writing IMC forces 82547 into
3952 * de-assertion state.
3954 if (hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
3955 E1000_WRITE_REG(hw
, IMC
, ~0);
3957 adapter
->total_tx_bytes
= 0;
3958 adapter
->total_rx_bytes
= 0;
3959 adapter
->total_tx_packets
= 0;
3960 adapter
->total_rx_packets
= 0;
3962 for (i
= 0; i
< E1000_MAX_INTR
; i
++)
3963 if (unlikely(!adapter
->clean_rx(adapter
, adapter
->rx_ring
) &
3964 !e1000_clean_tx_irq(adapter
, adapter
->tx_ring
)))
3967 if (likely(adapter
->itr_setting
& 3))
3968 e1000_set_itr(adapter
);
3970 if (hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
3971 e1000_irq_enable(adapter
);
3977 #ifdef CONFIG_E1000_NAPI
3979 * e1000_clean - NAPI Rx polling callback
3980 * @adapter: board private structure
3984 e1000_clean(struct napi_struct
*napi
, int budget
)
3986 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
, napi
);
3987 struct net_device
*poll_dev
= adapter
->netdev
;
3988 int tx_cleaned
= 0, work_done
= 0;
3990 /* Must NOT use netdev_priv macro here. */
3991 adapter
= poll_dev
->priv
;
3993 /* e1000_clean is called per-cpu. This lock protects
3994 * tx_ring[0] from being cleaned by multiple cpus
3995 * simultaneously. A failure obtaining the lock means
3996 * tx_ring[0] is currently being cleaned anyway. */
3997 if (spin_trylock(&adapter
->tx_queue_lock
)) {
3998 tx_cleaned
= e1000_clean_tx_irq(adapter
,
3999 &adapter
->tx_ring
[0]);
4000 spin_unlock(&adapter
->tx_queue_lock
);
4003 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[0],
4004 &work_done
, budget
);
4009 /* If budget not fully consumed, exit the polling mode */
4010 if (work_done
< budget
) {
4011 if (likely(adapter
->itr_setting
& 3))
4012 e1000_set_itr(adapter
);
4013 netif_rx_complete(poll_dev
, napi
);
4014 e1000_irq_enable(adapter
);
4022 * e1000_clean_tx_irq - Reclaim resources after transmit completes
4023 * @adapter: board private structure
4027 e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
4028 struct e1000_tx_ring
*tx_ring
)
4030 struct net_device
*netdev
= adapter
->netdev
;
4031 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
4032 struct e1000_buffer
*buffer_info
;
4033 unsigned int i
, eop
;
4034 #ifdef CONFIG_E1000_NAPI
4035 unsigned int count
= 0;
4037 bool cleaned
= false;
4038 unsigned int total_tx_bytes
=0, total_tx_packets
=0;
4040 i
= tx_ring
->next_to_clean
;
4041 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
4042 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
4044 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
4045 for (cleaned
= false; !cleaned
; ) {
4046 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
4047 buffer_info
= &tx_ring
->buffer_info
[i
];
4048 cleaned
= (i
== eop
);
4051 struct sk_buff
*skb
= buffer_info
->skb
;
4052 unsigned int segs
, bytecount
;
4053 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
4054 /* multiply data chunks by size of headers */
4055 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
4057 total_tx_packets
+= segs
;
4058 total_tx_bytes
+= bytecount
;
4060 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
4061 tx_desc
->upper
.data
= 0;
4063 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
4066 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
4067 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
4068 #ifdef CONFIG_E1000_NAPI
4069 #define E1000_TX_WEIGHT 64
4070 /* weight of a sort for tx, to avoid endless transmit cleanup */
4071 if (count
++ == E1000_TX_WEIGHT
) break;
4075 tx_ring
->next_to_clean
= i
;
4077 #define TX_WAKE_THRESHOLD 32
4078 if (unlikely(cleaned
&& netif_carrier_ok(netdev
) &&
4079 E1000_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
)) {
4080 /* Make sure that anybody stopping the queue after this
4081 * sees the new next_to_clean.
4084 if (netif_queue_stopped(netdev
)) {
4085 netif_wake_queue(netdev
);
4086 ++adapter
->restart_queue
;
4090 if (adapter
->detect_tx_hung
) {
4091 /* Detect a transmit hang in hardware, this serializes the
4092 * check with the clearing of time_stamp and movement of i */
4093 adapter
->detect_tx_hung
= false;
4094 if (tx_ring
->buffer_info
[eop
].dma
&&
4095 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
+
4096 (adapter
->tx_timeout_factor
* HZ
))
4097 && !(E1000_READ_REG(&adapter
->hw
, STATUS
) &
4098 E1000_STATUS_TXOFF
)) {
4100 /* detected Tx unit hang */
4101 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
4105 " next_to_use <%x>\n"
4106 " next_to_clean <%x>\n"
4107 "buffer_info[next_to_clean]\n"
4108 " time_stamp <%lx>\n"
4109 " next_to_watch <%x>\n"
4111 " next_to_watch.status <%x>\n",
4112 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
4113 sizeof(struct e1000_tx_ring
)),
4114 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdh
),
4115 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdt
),
4116 tx_ring
->next_to_use
,
4117 tx_ring
->next_to_clean
,
4118 tx_ring
->buffer_info
[eop
].time_stamp
,
4121 eop_desc
->upper
.fields
.status
);
4122 netif_stop_queue(netdev
);
4125 adapter
->total_tx_bytes
+= total_tx_bytes
;
4126 adapter
->total_tx_packets
+= total_tx_packets
;
4127 adapter
->net_stats
.tx_bytes
+= total_tx_bytes
;
4128 adapter
->net_stats
.tx_packets
+= total_tx_packets
;
4133 * e1000_rx_checksum - Receive Checksum Offload for 82543
4134 * @adapter: board private structure
4135 * @status_err: receive descriptor status and error fields
4136 * @csum: receive descriptor csum field
4137 * @sk_buff: socket buffer with received data
4141 e1000_rx_checksum(struct e1000_adapter
*adapter
,
4142 u32 status_err
, u32 csum
,
4143 struct sk_buff
*skb
)
4145 u16 status
= (u16
)status_err
;
4146 u8 errors
= (u8
)(status_err
>> 24);
4147 skb
->ip_summed
= CHECKSUM_NONE
;
4149 /* 82543 or newer only */
4150 if (unlikely(adapter
->hw
.mac_type
< e1000_82543
)) return;
4151 /* Ignore Checksum bit is set */
4152 if (unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
4153 /* TCP/UDP checksum error bit is set */
4154 if (unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
4155 /* let the stack verify checksum errors */
4156 adapter
->hw_csum_err
++;
4159 /* TCP/UDP Checksum has not been calculated */
4160 if (adapter
->hw
.mac_type
<= e1000_82547_rev_2
) {
4161 if (!(status
& E1000_RXD_STAT_TCPCS
))
4164 if (!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
4167 /* It must be a TCP or UDP packet with a valid checksum */
4168 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
4169 /* TCP checksum is good */
4170 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
4171 } else if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
4172 /* IP fragment with UDP payload */
4173 /* Hardware complements the payload checksum, so we undo it
4174 * and then put the value in host order for further stack use.
4176 __sum16 sum
= (__force __sum16
)htons(csum
);
4177 skb
->csum
= csum_unfold(~sum
);
4178 skb
->ip_summed
= CHECKSUM_COMPLETE
;
4180 adapter
->hw_csum_good
++;
4184 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4185 * @adapter: board private structure
4189 #ifdef CONFIG_E1000_NAPI
4190 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
4191 struct e1000_rx_ring
*rx_ring
,
4192 int *work_done
, int work_to_do
)
4194 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
4195 struct e1000_rx_ring
*rx_ring
)
4198 struct net_device
*netdev
= adapter
->netdev
;
4199 struct pci_dev
*pdev
= adapter
->pdev
;
4200 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
4201 struct e1000_buffer
*buffer_info
, *next_buffer
;
4202 unsigned long flags
;
4206 int cleaned_count
= 0;
4207 bool cleaned
= false;
4208 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
4210 i
= rx_ring
->next_to_clean
;
4211 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4212 buffer_info
= &rx_ring
->buffer_info
[i
];
4214 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
4215 struct sk_buff
*skb
;
4218 #ifdef CONFIG_E1000_NAPI
4219 if (*work_done
>= work_to_do
)
4223 status
= rx_desc
->status
;
4224 skb
= buffer_info
->skb
;
4225 buffer_info
->skb
= NULL
;
4227 prefetch(skb
->data
- NET_IP_ALIGN
);
4229 if (++i
== rx_ring
->count
) i
= 0;
4230 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
4233 next_buffer
= &rx_ring
->buffer_info
[i
];
4237 pci_unmap_single(pdev
,
4239 buffer_info
->length
,
4240 PCI_DMA_FROMDEVICE
);
4242 length
= le16_to_cpu(rx_desc
->length
);
4244 if (unlikely(!(status
& E1000_RXD_STAT_EOP
))) {
4245 /* All receives must fit into a single buffer */
4246 E1000_DBG("%s: Receive packet consumed multiple"
4247 " buffers\n", netdev
->name
);
4249 buffer_info
->skb
= skb
;
4253 if (unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
4254 last_byte
= *(skb
->data
+ length
- 1);
4255 if (TBI_ACCEPT(&adapter
->hw
, status
,
4256 rx_desc
->errors
, length
, last_byte
)) {
4257 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4258 e1000_tbi_adjust_stats(&adapter
->hw
,
4261 spin_unlock_irqrestore(&adapter
->stats_lock
,
4266 buffer_info
->skb
= skb
;
4271 /* adjust length to remove Ethernet CRC, this must be
4272 * done after the TBI_ACCEPT workaround above */
4275 /* probably a little skewed due to removing CRC */
4276 total_rx_bytes
+= length
;
4279 /* code added for copybreak, this should improve
4280 * performance for small packets with large amounts
4281 * of reassembly being done in the stack */
4282 if (length
< copybreak
) {
4283 struct sk_buff
*new_skb
=
4284 netdev_alloc_skb(netdev
, length
+ NET_IP_ALIGN
);
4286 skb_reserve(new_skb
, NET_IP_ALIGN
);
4287 skb_copy_to_linear_data_offset(new_skb
,
4293 /* save the skb in buffer_info as good */
4294 buffer_info
->skb
= skb
;
4297 /* else just continue with the old one */
4299 /* end copybreak code */
4300 skb_put(skb
, length
);
4302 /* Receive Checksum Offload */
4303 e1000_rx_checksum(adapter
,
4305 ((u32
)(rx_desc
->errors
) << 24),
4306 le16_to_cpu(rx_desc
->csum
), skb
);
4308 skb
->protocol
= eth_type_trans(skb
, netdev
);
4309 #ifdef CONFIG_E1000_NAPI
4310 if (unlikely(adapter
->vlgrp
&&
4311 (status
& E1000_RXD_STAT_VP
))) {
4312 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
4313 le16_to_cpu(rx_desc
->special
) &
4314 E1000_RXD_SPC_VLAN_MASK
);
4316 netif_receive_skb(skb
);
4318 #else /* CONFIG_E1000_NAPI */
4319 if (unlikely(adapter
->vlgrp
&&
4320 (status
& E1000_RXD_STAT_VP
))) {
4321 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
4322 le16_to_cpu(rx_desc
->special
) &
4323 E1000_RXD_SPC_VLAN_MASK
);
4327 #endif /* CONFIG_E1000_NAPI */
4328 netdev
->last_rx
= jiffies
;
4331 rx_desc
->status
= 0;
4333 /* return some buffers to hardware, one at a time is too slow */
4334 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
4335 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4339 /* use prefetched values */
4341 buffer_info
= next_buffer
;
4343 rx_ring
->next_to_clean
= i
;
4345 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
4347 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4349 adapter
->total_rx_packets
+= total_rx_packets
;
4350 adapter
->total_rx_bytes
+= total_rx_bytes
;
4351 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
4352 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
4357 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4358 * @adapter: board private structure
4362 #ifdef CONFIG_E1000_NAPI
4363 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
4364 struct e1000_rx_ring
*rx_ring
,
4365 int *work_done
, int work_to_do
)
4367 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
4368 struct e1000_rx_ring
*rx_ring
)
4371 union e1000_rx_desc_packet_split
*rx_desc
, *next_rxd
;
4372 struct net_device
*netdev
= adapter
->netdev
;
4373 struct pci_dev
*pdev
= adapter
->pdev
;
4374 struct e1000_buffer
*buffer_info
, *next_buffer
;
4375 struct e1000_ps_page
*ps_page
;
4376 struct e1000_ps_page_dma
*ps_page_dma
;
4377 struct sk_buff
*skb
;
4379 u32 length
, staterr
;
4380 int cleaned_count
= 0;
4381 bool cleaned
= false;
4382 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
4384 i
= rx_ring
->next_to_clean
;
4385 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
4386 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
4387 buffer_info
= &rx_ring
->buffer_info
[i
];
4389 while (staterr
& E1000_RXD_STAT_DD
) {
4390 ps_page
= &rx_ring
->ps_page
[i
];
4391 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
4392 #ifdef CONFIG_E1000_NAPI
4393 if (unlikely(*work_done
>= work_to_do
))
4397 skb
= buffer_info
->skb
;
4399 /* in the packet split case this is header only */
4400 prefetch(skb
->data
- NET_IP_ALIGN
);
4402 if (++i
== rx_ring
->count
) i
= 0;
4403 next_rxd
= E1000_RX_DESC_PS(*rx_ring
, i
);
4406 next_buffer
= &rx_ring
->buffer_info
[i
];
4410 pci_unmap_single(pdev
, buffer_info
->dma
,
4411 buffer_info
->length
,
4412 PCI_DMA_FROMDEVICE
);
4414 if (unlikely(!(staterr
& E1000_RXD_STAT_EOP
))) {
4415 E1000_DBG("%s: Packet Split buffers didn't pick up"
4416 " the full packet\n", netdev
->name
);
4417 dev_kfree_skb_irq(skb
);
4421 if (unlikely(staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
)) {
4422 dev_kfree_skb_irq(skb
);
4426 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
4428 if (unlikely(!length
)) {
4429 E1000_DBG("%s: Last part of the packet spanning"
4430 " multiple descriptors\n", netdev
->name
);
4431 dev_kfree_skb_irq(skb
);
4436 skb_put(skb
, length
);
4439 /* this looks ugly, but it seems compiler issues make it
4440 more efficient than reusing j */
4441 int l1
= le16_to_cpu(rx_desc
->wb
.upper
.length
[0]);
4443 /* page alloc/put takes too long and effects small packet
4444 * throughput, so unsplit small packets and save the alloc/put*/
4445 if (l1
&& (l1
<= copybreak
) && ((length
+ l1
) <= adapter
->rx_ps_bsize0
)) {
4447 /* there is no documentation about how to call
4448 * kmap_atomic, so we can't hold the mapping
4450 pci_dma_sync_single_for_cpu(pdev
,
4451 ps_page_dma
->ps_page_dma
[0],
4453 PCI_DMA_FROMDEVICE
);
4454 vaddr
= kmap_atomic(ps_page
->ps_page
[0],
4455 KM_SKB_DATA_SOFTIRQ
);
4456 memcpy(skb_tail_pointer(skb
), vaddr
, l1
);
4457 kunmap_atomic(vaddr
, KM_SKB_DATA_SOFTIRQ
);
4458 pci_dma_sync_single_for_device(pdev
,
4459 ps_page_dma
->ps_page_dma
[0],
4460 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
4461 /* remove the CRC */
4468 for (j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
4469 if (!(length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
])))
4471 pci_unmap_page(pdev
, ps_page_dma
->ps_page_dma
[j
],
4472 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
4473 ps_page_dma
->ps_page_dma
[j
] = 0;
4474 skb_fill_page_desc(skb
, j
, ps_page
->ps_page
[j
], 0,
4476 ps_page
->ps_page
[j
] = NULL
;
4478 skb
->data_len
+= length
;
4479 skb
->truesize
+= length
;
4482 /* strip the ethernet crc, problem is we're using pages now so
4483 * this whole operation can get a little cpu intensive */
4484 pskb_trim(skb
, skb
->len
- 4);
4487 total_rx_bytes
+= skb
->len
;
4490 e1000_rx_checksum(adapter
, staterr
,
4491 le16_to_cpu(rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
), skb
);
4492 skb
->protocol
= eth_type_trans(skb
, netdev
);
4494 if (likely(rx_desc
->wb
.upper
.header_status
&
4495 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP
)))
4496 adapter
->rx_hdr_split
++;
4497 #ifdef CONFIG_E1000_NAPI
4498 if (unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
4499 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
4500 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
4501 E1000_RXD_SPC_VLAN_MASK
);
4503 netif_receive_skb(skb
);
4505 #else /* CONFIG_E1000_NAPI */
4506 if (unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
4507 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
4508 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
4509 E1000_RXD_SPC_VLAN_MASK
);
4513 #endif /* CONFIG_E1000_NAPI */
4514 netdev
->last_rx
= jiffies
;
4517 rx_desc
->wb
.middle
.status_error
&= cpu_to_le32(~0xFF);
4518 buffer_info
->skb
= NULL
;
4520 /* return some buffers to hardware, one at a time is too slow */
4521 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
4522 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4526 /* use prefetched values */
4528 buffer_info
= next_buffer
;
4530 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
4532 rx_ring
->next_to_clean
= i
;
4534 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
4536 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4538 adapter
->total_rx_packets
+= total_rx_packets
;
4539 adapter
->total_rx_bytes
+= total_rx_bytes
;
4540 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
4541 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
4546 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4547 * @adapter: address of board private structure
4551 e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
4552 struct e1000_rx_ring
*rx_ring
,
4555 struct net_device
*netdev
= adapter
->netdev
;
4556 struct pci_dev
*pdev
= adapter
->pdev
;
4557 struct e1000_rx_desc
*rx_desc
;
4558 struct e1000_buffer
*buffer_info
;
4559 struct sk_buff
*skb
;
4561 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
4563 i
= rx_ring
->next_to_use
;
4564 buffer_info
= &rx_ring
->buffer_info
[i
];
4566 while (cleaned_count
--) {
4567 skb
= buffer_info
->skb
;
4573 skb
= netdev_alloc_skb(netdev
, bufsz
);
4574 if (unlikely(!skb
)) {
4575 /* Better luck next round */
4576 adapter
->alloc_rx_buff_failed
++;
4580 /* Fix for errata 23, can't cross 64kB boundary */
4581 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4582 struct sk_buff
*oldskb
= skb
;
4583 DPRINTK(RX_ERR
, ERR
, "skb align check failed: %u bytes "
4584 "at %p\n", bufsz
, skb
->data
);
4585 /* Try again, without freeing the previous */
4586 skb
= netdev_alloc_skb(netdev
, bufsz
);
4587 /* Failed allocation, critical failure */
4589 dev_kfree_skb(oldskb
);
4593 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4596 dev_kfree_skb(oldskb
);
4597 break; /* while !buffer_info->skb */
4600 /* Use new allocation */
4601 dev_kfree_skb(oldskb
);
4603 /* Make buffer alignment 2 beyond a 16 byte boundary
4604 * this will result in a 16 byte aligned IP header after
4605 * the 14 byte MAC header is removed
4607 skb_reserve(skb
, NET_IP_ALIGN
);
4609 buffer_info
->skb
= skb
;
4610 buffer_info
->length
= adapter
->rx_buffer_len
;
4612 buffer_info
->dma
= pci_map_single(pdev
,
4614 adapter
->rx_buffer_len
,
4615 PCI_DMA_FROMDEVICE
);
4617 /* Fix for errata 23, can't cross 64kB boundary */
4618 if (!e1000_check_64k_bound(adapter
,
4619 (void *)(unsigned long)buffer_info
->dma
,
4620 adapter
->rx_buffer_len
)) {
4621 DPRINTK(RX_ERR
, ERR
,
4622 "dma align check failed: %u bytes at %p\n",
4623 adapter
->rx_buffer_len
,
4624 (void *)(unsigned long)buffer_info
->dma
);
4626 buffer_info
->skb
= NULL
;
4628 pci_unmap_single(pdev
, buffer_info
->dma
,
4629 adapter
->rx_buffer_len
,
4630 PCI_DMA_FROMDEVICE
);
4632 break; /* while !buffer_info->skb */
4634 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4635 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4637 if (unlikely(++i
== rx_ring
->count
))
4639 buffer_info
= &rx_ring
->buffer_info
[i
];
4642 if (likely(rx_ring
->next_to_use
!= i
)) {
4643 rx_ring
->next_to_use
= i
;
4644 if (unlikely(i
-- == 0))
4645 i
= (rx_ring
->count
- 1);
4647 /* Force memory writes to complete before letting h/w
4648 * know there are new descriptors to fetch. (Only
4649 * applicable for weak-ordered memory model archs,
4650 * such as IA-64). */
4652 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4657 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4658 * @adapter: address of board private structure
4662 e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
4663 struct e1000_rx_ring
*rx_ring
,
4666 struct net_device
*netdev
= adapter
->netdev
;
4667 struct pci_dev
*pdev
= adapter
->pdev
;
4668 union e1000_rx_desc_packet_split
*rx_desc
;
4669 struct e1000_buffer
*buffer_info
;
4670 struct e1000_ps_page
*ps_page
;
4671 struct e1000_ps_page_dma
*ps_page_dma
;
4672 struct sk_buff
*skb
;
4675 i
= rx_ring
->next_to_use
;
4676 buffer_info
= &rx_ring
->buffer_info
[i
];
4677 ps_page
= &rx_ring
->ps_page
[i
];
4678 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
4680 while (cleaned_count
--) {
4681 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
4683 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
4684 if (j
< adapter
->rx_ps_pages
) {
4685 if (likely(!ps_page
->ps_page
[j
])) {
4686 ps_page
->ps_page
[j
] =
4687 alloc_page(GFP_ATOMIC
);
4688 if (unlikely(!ps_page
->ps_page
[j
])) {
4689 adapter
->alloc_rx_buff_failed
++;
4692 ps_page_dma
->ps_page_dma
[j
] =
4694 ps_page
->ps_page
[j
],
4696 PCI_DMA_FROMDEVICE
);
4698 /* Refresh the desc even if buffer_addrs didn't
4699 * change because each write-back erases
4702 rx_desc
->read
.buffer_addr
[j
+1] =
4703 cpu_to_le64(ps_page_dma
->ps_page_dma
[j
]);
4705 rx_desc
->read
.buffer_addr
[j
+1] = ~cpu_to_le64(0);
4708 skb
= netdev_alloc_skb(netdev
,
4709 adapter
->rx_ps_bsize0
+ NET_IP_ALIGN
);
4711 if (unlikely(!skb
)) {
4712 adapter
->alloc_rx_buff_failed
++;
4716 /* Make buffer alignment 2 beyond a 16 byte boundary
4717 * this will result in a 16 byte aligned IP header after
4718 * the 14 byte MAC header is removed
4720 skb_reserve(skb
, NET_IP_ALIGN
);
4722 buffer_info
->skb
= skb
;
4723 buffer_info
->length
= adapter
->rx_ps_bsize0
;
4724 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
4725 adapter
->rx_ps_bsize0
,
4726 PCI_DMA_FROMDEVICE
);
4728 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
4730 if (unlikely(++i
== rx_ring
->count
)) i
= 0;
4731 buffer_info
= &rx_ring
->buffer_info
[i
];
4732 ps_page
= &rx_ring
->ps_page
[i
];
4733 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
4737 if (likely(rx_ring
->next_to_use
!= i
)) {
4738 rx_ring
->next_to_use
= i
;
4739 if (unlikely(i
-- == 0)) i
= (rx_ring
->count
- 1);
4741 /* Force memory writes to complete before letting h/w
4742 * know there are new descriptors to fetch. (Only
4743 * applicable for weak-ordered memory model archs,
4744 * such as IA-64). */
4746 /* Hardware increments by 16 bytes, but packet split
4747 * descriptors are 32 bytes...so we increment tail
4750 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4755 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4760 e1000_smartspeed(struct e1000_adapter
*adapter
)
4765 if ((adapter
->hw
.phy_type
!= e1000_phy_igp
) || !adapter
->hw
.autoneg
||
4766 !(adapter
->hw
.autoneg_advertised
& ADVERTISE_1000_FULL
))
4769 if (adapter
->smartspeed
== 0) {
4770 /* If Master/Slave config fault is asserted twice,
4771 * we assume back-to-back */
4772 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4773 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4774 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4775 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4776 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4777 if (phy_ctrl
& CR_1000T_MS_ENABLE
) {
4778 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
4779 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
,
4781 adapter
->smartspeed
++;
4782 if (!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4783 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
,
4785 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4786 MII_CR_RESTART_AUTO_NEG
);
4787 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
,
4792 } else if (adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
4793 /* If still no link, perhaps using 2/3 pair cable */
4794 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4795 phy_ctrl
|= CR_1000T_MS_ENABLE
;
4796 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, phy_ctrl
);
4797 if (!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4798 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &phy_ctrl
)) {
4799 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4800 MII_CR_RESTART_AUTO_NEG
);
4801 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, phy_ctrl
);
4804 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4805 if (adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
4806 adapter
->smartspeed
= 0;
4817 e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4823 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4837 e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4839 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4840 struct mii_ioctl_data
*data
= if_mii(ifr
);
4844 unsigned long flags
;
4846 if (adapter
->hw
.media_type
!= e1000_media_type_copper
)
4851 data
->phy_id
= adapter
->hw
.phy_addr
;
4854 if (!capable(CAP_NET_ADMIN
))
4856 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4857 if (e1000_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
4859 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4862 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4865 if (!capable(CAP_NET_ADMIN
))
4867 if (data
->reg_num
& ~(0x1F))
4869 mii_reg
= data
->val_in
;
4870 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4871 if (e1000_write_phy_reg(&adapter
->hw
, data
->reg_num
,
4873 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4876 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4877 if (adapter
->hw
.media_type
== e1000_media_type_copper
) {
4878 switch (data
->reg_num
) {
4880 if (mii_reg
& MII_CR_POWER_DOWN
)
4882 if (mii_reg
& MII_CR_AUTO_NEG_EN
) {
4883 adapter
->hw
.autoneg
= 1;
4884 adapter
->hw
.autoneg_advertised
= 0x2F;
4887 spddplx
= SPEED_1000
;
4888 else if (mii_reg
& 0x2000)
4889 spddplx
= SPEED_100
;
4892 spddplx
+= (mii_reg
& 0x100)
4895 retval
= e1000_set_spd_dplx(adapter
,
4900 if (netif_running(adapter
->netdev
))
4901 e1000_reinit_locked(adapter
);
4903 e1000_reset(adapter
);
4905 case M88E1000_PHY_SPEC_CTRL
:
4906 case M88E1000_EXT_PHY_SPEC_CTRL
:
4907 if (e1000_phy_reset(&adapter
->hw
))
4912 switch (data
->reg_num
) {
4914 if (mii_reg
& MII_CR_POWER_DOWN
)
4916 if (netif_running(adapter
->netdev
))
4917 e1000_reinit_locked(adapter
);
4919 e1000_reset(adapter
);
4927 return E1000_SUCCESS
;
4931 e1000_pci_set_mwi(struct e1000_hw
*hw
)
4933 struct e1000_adapter
*adapter
= hw
->back
;
4934 int ret_val
= pci_set_mwi(adapter
->pdev
);
4937 DPRINTK(PROBE
, ERR
, "Error in setting MWI\n");
4941 e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4943 struct e1000_adapter
*adapter
= hw
->back
;
4945 pci_clear_mwi(adapter
->pdev
);
4949 e1000_pcix_get_mmrbc(struct e1000_hw
*hw
)
4951 struct e1000_adapter
*adapter
= hw
->back
;
4952 return pcix_get_mmrbc(adapter
->pdev
);
4956 e1000_pcix_set_mmrbc(struct e1000_hw
*hw
, int mmrbc
)
4958 struct e1000_adapter
*adapter
= hw
->back
;
4959 pcix_set_mmrbc(adapter
->pdev
, mmrbc
);
4963 e1000_read_pcie_cap_reg(struct e1000_hw
*hw
, u32 reg
, u16
*value
)
4965 struct e1000_adapter
*adapter
= hw
->back
;
4968 cap_offset
= pci_find_capability(adapter
->pdev
, PCI_CAP_ID_EXP
);
4970 return -E1000_ERR_CONFIG
;
4972 pci_read_config_word(adapter
->pdev
, cap_offset
+ reg
, value
);
4974 return E1000_SUCCESS
;
4978 e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, u32 value
)
4984 e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
4986 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4989 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4990 e1000_irq_disable(adapter
);
4991 adapter
->vlgrp
= grp
;
4994 /* enable VLAN tag insert/strip */
4995 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4996 ctrl
|= E1000_CTRL_VME
;
4997 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4999 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
5000 /* enable VLAN receive filtering */
5001 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
5002 rctl
|= E1000_RCTL_VFE
;
5003 rctl
&= ~E1000_RCTL_CFIEN
;
5004 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
5005 e1000_update_mng_vlan(adapter
);
5008 /* disable VLAN tag insert/strip */
5009 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
5010 ctrl
&= ~E1000_CTRL_VME
;
5011 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
5013 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
5014 /* disable VLAN filtering */
5015 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
5016 rctl
&= ~E1000_RCTL_VFE
;
5017 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
5018 if (adapter
->mng_vlan_id
!=
5019 (u16
)E1000_MNG_VLAN_NONE
) {
5020 e1000_vlan_rx_kill_vid(netdev
,
5021 adapter
->mng_vlan_id
);
5022 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
5027 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
5028 e1000_irq_enable(adapter
);
5032 e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
5034 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5037 if ((adapter
->hw
.mng_cookie
.status
&
5038 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
5039 (vid
== adapter
->mng_vlan_id
))
5041 /* add VID to filter table */
5042 index
= (vid
>> 5) & 0x7F;
5043 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
5044 vfta
|= (1 << (vid
& 0x1F));
5045 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
5049 e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
5051 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5054 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
5055 e1000_irq_disable(adapter
);
5056 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
5057 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
5058 e1000_irq_enable(adapter
);
5060 if ((adapter
->hw
.mng_cookie
.status
&
5061 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
5062 (vid
== adapter
->mng_vlan_id
)) {
5063 /* release control to f/w */
5064 e1000_release_hw_control(adapter
);
5068 /* remove VID from filter table */
5069 index
= (vid
>> 5) & 0x7F;
5070 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
5071 vfta
&= ~(1 << (vid
& 0x1F));
5072 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
5076 e1000_restore_vlan(struct e1000_adapter
*adapter
)
5078 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
5080 if (adapter
->vlgrp
) {
5082 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
5083 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
5085 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
5091 e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u16 spddplx
)
5093 adapter
->hw
.autoneg
= 0;
5095 /* Fiber NICs only allow 1000 gbps Full duplex */
5096 if ((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
5097 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
5098 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
5103 case SPEED_10
+ DUPLEX_HALF
:
5104 adapter
->hw
.forced_speed_duplex
= e1000_10_half
;
5106 case SPEED_10
+ DUPLEX_FULL
:
5107 adapter
->hw
.forced_speed_duplex
= e1000_10_full
;
5109 case SPEED_100
+ DUPLEX_HALF
:
5110 adapter
->hw
.forced_speed_duplex
= e1000_100_half
;
5112 case SPEED_100
+ DUPLEX_FULL
:
5113 adapter
->hw
.forced_speed_duplex
= e1000_100_full
;
5115 case SPEED_1000
+ DUPLEX_FULL
:
5116 adapter
->hw
.autoneg
= 1;
5117 adapter
->hw
.autoneg_advertised
= ADVERTISE_1000_FULL
;
5119 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
5121 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
5128 e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5130 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5131 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5132 u32 ctrl
, ctrl_ext
, rctl
, status
;
5133 u32 wufc
= adapter
->wol
;
5138 netif_device_detach(netdev
);
5140 if (netif_running(netdev
)) {
5141 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
5142 e1000_down(adapter
);
5146 retval
= pci_save_state(pdev
);
5151 status
= E1000_READ_REG(&adapter
->hw
, STATUS
);
5152 if (status
& E1000_STATUS_LU
)
5153 wufc
&= ~E1000_WUFC_LNKC
;
5156 e1000_setup_rctl(adapter
);
5157 e1000_set_rx_mode(netdev
);
5159 /* turn on all-multi mode if wake on multicast is enabled */
5160 if (wufc
& E1000_WUFC_MC
) {
5161 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
5162 rctl
|= E1000_RCTL_MPE
;
5163 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
5166 if (adapter
->hw
.mac_type
>= e1000_82540
) {
5167 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
5168 /* advertise wake from D3Cold */
5169 #define E1000_CTRL_ADVD3WUC 0x00100000
5170 /* phy power management enable */
5171 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5172 ctrl
|= E1000_CTRL_ADVD3WUC
|
5173 E1000_CTRL_EN_PHY_PWR_MGMT
;
5174 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
5177 if (adapter
->hw
.media_type
== e1000_media_type_fiber
||
5178 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) {
5179 /* keep the laser running in D3 */
5180 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
5181 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
5182 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
, ctrl_ext
);
5185 /* Allow time for pending master requests to run */
5186 e1000_disable_pciex_master(&adapter
->hw
);
5188 E1000_WRITE_REG(&adapter
->hw
, WUC
, E1000_WUC_PME_EN
);
5189 E1000_WRITE_REG(&adapter
->hw
, WUFC
, wufc
);
5190 pci_enable_wake(pdev
, PCI_D3hot
, 1);
5191 pci_enable_wake(pdev
, PCI_D3cold
, 1);
5193 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
5194 E1000_WRITE_REG(&adapter
->hw
, WUFC
, 0);
5195 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5196 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5199 e1000_release_manageability(adapter
);
5201 /* make sure adapter isn't asleep if manageability is enabled */
5202 if (adapter
->en_mng_pt
) {
5203 pci_enable_wake(pdev
, PCI_D3hot
, 1);
5204 pci_enable_wake(pdev
, PCI_D3cold
, 1);
5207 if (adapter
->hw
.phy_type
== e1000_phy_igp_3
)
5208 e1000_phy_powerdown_workaround(&adapter
->hw
);
5210 if (netif_running(netdev
))
5211 e1000_free_irq(adapter
);
5213 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5214 * would have already happened in close and is redundant. */
5215 e1000_release_hw_control(adapter
);
5217 pci_disable_device(pdev
);
5219 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
5226 e1000_resume(struct pci_dev
*pdev
)
5228 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5229 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5232 pci_set_power_state(pdev
, PCI_D0
);
5233 pci_restore_state(pdev
);
5234 if ((err
= pci_enable_device(pdev
))) {
5235 printk(KERN_ERR
"e1000: Cannot enable PCI device from suspend\n");
5238 pci_set_master(pdev
);
5240 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5241 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5243 if (netif_running(netdev
) && (err
= e1000_request_irq(adapter
)))
5246 e1000_power_up_phy(adapter
);
5247 e1000_reset(adapter
);
5248 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
5250 e1000_init_manageability(adapter
);
5252 if (netif_running(netdev
))
5255 netif_device_attach(netdev
);
5257 /* If the controller is 82573 and f/w is AMT, do not set
5258 * DRV_LOAD until the interface is up. For all other cases,
5259 * let the f/w know that the h/w is now under the control
5261 if (adapter
->hw
.mac_type
!= e1000_82573
||
5262 !e1000_check_mng_mode(&adapter
->hw
))
5263 e1000_get_hw_control(adapter
);
5269 static void e1000_shutdown(struct pci_dev
*pdev
)
5271 e1000_suspend(pdev
, PMSG_SUSPEND
);
5274 #ifdef CONFIG_NET_POLL_CONTROLLER
5276 * Polling 'interrupt' - used by things like netconsole to send skbs
5277 * without having to re-enable interrupts. It's not called while
5278 * the interrupt routine is executing.
5281 e1000_netpoll(struct net_device
*netdev
)
5283 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5285 disable_irq(adapter
->pdev
->irq
);
5286 e1000_intr(adapter
->pdev
->irq
, netdev
);
5287 e1000_clean_tx_irq(adapter
, adapter
->tx_ring
);
5288 #ifndef CONFIG_E1000_NAPI
5289 adapter
->clean_rx(adapter
, adapter
->rx_ring
);
5291 enable_irq(adapter
->pdev
->irq
);
5296 * e1000_io_error_detected - called when PCI error is detected
5297 * @pdev: Pointer to PCI device
5298 * @state: The current pci conneection state
5300 * This function is called after a PCI bus error affecting
5301 * this device has been detected.
5303 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
5305 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5306 struct e1000_adapter
*adapter
= netdev
->priv
;
5308 netif_device_detach(netdev
);
5310 if (netif_running(netdev
))
5311 e1000_down(adapter
);
5312 pci_disable_device(pdev
);
5314 /* Request a slot slot reset. */
5315 return PCI_ERS_RESULT_NEED_RESET
;
5319 * e1000_io_slot_reset - called after the pci bus has been reset.
5320 * @pdev: Pointer to PCI device
5322 * Restart the card from scratch, as if from a cold-boot. Implementation
5323 * resembles the first-half of the e1000_resume routine.
5325 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
5327 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5328 struct e1000_adapter
*adapter
= netdev
->priv
;
5330 if (pci_enable_device(pdev
)) {
5331 printk(KERN_ERR
"e1000: Cannot re-enable PCI device after reset.\n");
5332 return PCI_ERS_RESULT_DISCONNECT
;
5334 pci_set_master(pdev
);
5336 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5337 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5339 e1000_reset(adapter
);
5340 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
5342 return PCI_ERS_RESULT_RECOVERED
;
5346 * e1000_io_resume - called when traffic can start flowing again.
5347 * @pdev: Pointer to PCI device
5349 * This callback is called when the error recovery driver tells us that
5350 * its OK to resume normal operation. Implementation resembles the
5351 * second-half of the e1000_resume routine.
5353 static void e1000_io_resume(struct pci_dev
*pdev
)
5355 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5356 struct e1000_adapter
*adapter
= netdev
->priv
;
5358 e1000_init_manageability(adapter
);
5360 if (netif_running(netdev
)) {
5361 if (e1000_up(adapter
)) {
5362 printk("e1000: can't bring device back up after reset\n");
5367 netif_device_attach(netdev
);
5369 /* If the controller is 82573 and f/w is AMT, do not set
5370 * DRV_LOAD until the interface is up. For all other cases,
5371 * let the f/w know that the h/w is now under the control
5373 if (adapter
->hw
.mac_type
!= e1000_82573
||
5374 !e1000_check_mng_mode(&adapter
->hw
))
5375 e1000_get_hw_control(adapter
);