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
, uint16_t 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 boolean_t
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 boolean_t
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 boolean_t
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 boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
184 struct e1000_rx_ring
*rx_ring
);
185 static boolean_t
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
, uint16_t vid
);
207 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t 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 atomic_inc(&adapter
->irq_sem
);
351 E1000_WRITE_REG(&adapter
->hw
, IMC
, ~0);
352 E1000_WRITE_FLUSH(&adapter
->hw
);
353 synchronize_irq(adapter
->pdev
->irq
);
357 * e1000_irq_enable - Enable default interrupt generation settings
358 * @adapter: board private structure
362 e1000_irq_enable(struct e1000_adapter
*adapter
)
364 if (likely(atomic_dec_and_test(&adapter
->irq_sem
))) {
365 E1000_WRITE_REG(&adapter
->hw
, IMS
, IMS_ENABLE_MASK
);
366 E1000_WRITE_FLUSH(&adapter
->hw
);
371 e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
373 struct net_device
*netdev
= adapter
->netdev
;
374 uint16_t vid
= adapter
->hw
.mng_cookie
.vlan_id
;
375 uint16_t old_vid
= adapter
->mng_vlan_id
;
376 if (adapter
->vlgrp
) {
377 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
378 if (adapter
->hw
.mng_cookie
.status
&
379 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
380 e1000_vlan_rx_add_vid(netdev
, vid
);
381 adapter
->mng_vlan_id
= vid
;
383 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
385 if ((old_vid
!= (uint16_t)E1000_MNG_VLAN_NONE
) &&
387 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
388 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
390 adapter
->mng_vlan_id
= vid
;
395 * e1000_release_hw_control - release control of the h/w to f/w
396 * @adapter: address of board private structure
398 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
399 * For ASF and Pass Through versions of f/w this means that the
400 * driver is no longer loaded. For AMT version (only with 82573) i
401 * of the f/w this means that the network i/f is closed.
406 e1000_release_hw_control(struct e1000_adapter
*adapter
)
411 /* Let firmware taken over control of h/w */
412 switch (adapter
->hw
.mac_type
) {
414 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
415 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
416 swsm
& ~E1000_SWSM_DRV_LOAD
);
420 case e1000_80003es2lan
:
422 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
423 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
424 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
432 * e1000_get_hw_control - get control of the h/w from f/w
433 * @adapter: address of board private structure
435 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
436 * For ASF and Pass Through versions of f/w this means that
437 * the driver is loaded. For AMT version (only with 82573)
438 * of the f/w this means that the network i/f is open.
443 e1000_get_hw_control(struct e1000_adapter
*adapter
)
448 /* Let firmware know the driver has taken over */
449 switch (adapter
->hw
.mac_type
) {
451 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
452 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
453 swsm
| E1000_SWSM_DRV_LOAD
);
457 case e1000_80003es2lan
:
459 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
460 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
461 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
469 e1000_init_manageability(struct e1000_adapter
*adapter
)
471 if (adapter
->en_mng_pt
) {
472 uint32_t manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
474 /* disable hardware interception of ARP */
475 manc
&= ~(E1000_MANC_ARP_EN
);
477 /* enable receiving management packets to the host */
478 /* this will probably generate destination unreachable messages
479 * from the host OS, but the packets will be handled on SMBUS */
480 if (adapter
->hw
.has_manc2h
) {
481 uint32_t manc2h
= E1000_READ_REG(&adapter
->hw
, MANC2H
);
483 manc
|= E1000_MANC_EN_MNG2HOST
;
484 #define E1000_MNG2HOST_PORT_623 (1 << 5)
485 #define E1000_MNG2HOST_PORT_664 (1 << 6)
486 manc2h
|= E1000_MNG2HOST_PORT_623
;
487 manc2h
|= E1000_MNG2HOST_PORT_664
;
488 E1000_WRITE_REG(&adapter
->hw
, MANC2H
, manc2h
);
491 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
496 e1000_release_manageability(struct e1000_adapter
*adapter
)
498 if (adapter
->en_mng_pt
) {
499 uint32_t manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
501 /* re-enable hardware interception of ARP */
502 manc
|= E1000_MANC_ARP_EN
;
504 if (adapter
->hw
.has_manc2h
)
505 manc
&= ~E1000_MANC_EN_MNG2HOST
;
507 /* don't explicitly have to mess with MANC2H since
508 * MANC has an enable disable that gates MANC2H */
510 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
515 * e1000_configure - configure the hardware for RX and TX
516 * @adapter = private board structure
518 static void e1000_configure(struct e1000_adapter
*adapter
)
520 struct net_device
*netdev
= adapter
->netdev
;
523 e1000_set_rx_mode(netdev
);
525 e1000_restore_vlan(adapter
);
526 e1000_init_manageability(adapter
);
528 e1000_configure_tx(adapter
);
529 e1000_setup_rctl(adapter
);
530 e1000_configure_rx(adapter
);
531 /* call E1000_DESC_UNUSED which always leaves
532 * at least 1 descriptor unused to make sure
533 * next_to_use != next_to_clean */
534 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
535 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[i
];
536 adapter
->alloc_rx_buf(adapter
, ring
,
537 E1000_DESC_UNUSED(ring
));
540 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
543 int e1000_up(struct e1000_adapter
*adapter
)
545 /* hardware has been reset, we need to reload some things */
546 e1000_configure(adapter
);
548 clear_bit(__E1000_DOWN
, &adapter
->flags
);
550 #ifdef CONFIG_E1000_NAPI
551 napi_enable(&adapter
->napi
);
553 e1000_irq_enable(adapter
);
555 /* fire a link change interrupt to start the watchdog */
556 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_LSC
);
561 * e1000_power_up_phy - restore link in case the phy was powered down
562 * @adapter: address of board private structure
564 * The phy may be powered down to save power and turn off link when the
565 * driver is unloaded and wake on lan is not enabled (among others)
566 * *** this routine MUST be followed by a call to e1000_reset ***
570 void e1000_power_up_phy(struct e1000_adapter
*adapter
)
572 uint16_t mii_reg
= 0;
574 /* Just clear the power down bit to wake the phy back up */
575 if (adapter
->hw
.media_type
== e1000_media_type_copper
) {
576 /* according to the manual, the phy will retain its
577 * settings across a power-down/up cycle */
578 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
579 mii_reg
&= ~MII_CR_POWER_DOWN
;
580 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
584 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
586 /* Power down the PHY so no link is implied when interface is down *
587 * The PHY cannot be powered down if any of the following is TRUE *
590 * (c) SoL/IDER session is active */
591 if (!adapter
->wol
&& adapter
->hw
.mac_type
>= e1000_82540
&&
592 adapter
->hw
.media_type
== e1000_media_type_copper
) {
593 uint16_t mii_reg
= 0;
595 switch (adapter
->hw
.mac_type
) {
598 case e1000_82545_rev_3
:
600 case e1000_82546_rev_3
:
602 case e1000_82541_rev_2
:
604 case e1000_82547_rev_2
:
605 if (E1000_READ_REG(&adapter
->hw
, MANC
) &
612 case e1000_80003es2lan
:
614 if (e1000_check_mng_mode(&adapter
->hw
) ||
615 e1000_check_phy_reset_block(&adapter
->hw
))
621 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
622 mii_reg
|= MII_CR_POWER_DOWN
;
623 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
631 e1000_down(struct e1000_adapter
*adapter
)
633 struct net_device
*netdev
= adapter
->netdev
;
635 /* signal that we're down so the interrupt handler does not
636 * reschedule our watchdog timer */
637 set_bit(__E1000_DOWN
, &adapter
->flags
);
639 #ifdef CONFIG_E1000_NAPI
640 napi_disable(&adapter
->napi
);
641 atomic_set(&adapter
->irq_sem
, 0);
643 e1000_irq_disable(adapter
);
645 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
646 del_timer_sync(&adapter
->watchdog_timer
);
647 del_timer_sync(&adapter
->phy_info_timer
);
649 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
650 adapter
->link_speed
= 0;
651 adapter
->link_duplex
= 0;
652 netif_carrier_off(netdev
);
653 netif_stop_queue(netdev
);
655 e1000_reset(adapter
);
656 e1000_clean_all_tx_rings(adapter
);
657 e1000_clean_all_rx_rings(adapter
);
661 e1000_reinit_locked(struct e1000_adapter
*adapter
)
663 WARN_ON(in_interrupt());
664 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->flags
))
668 clear_bit(__E1000_RESETTING
, &adapter
->flags
);
672 e1000_reset(struct e1000_adapter
*adapter
)
674 uint32_t pba
= 0, tx_space
, min_tx_space
, min_rx_space
;
675 uint16_t fc_high_water_mark
= E1000_FC_HIGH_DIFF
;
676 boolean_t legacy_pba_adjust
= FALSE
;
678 /* Repartition Pba for greater than 9k mtu
679 * To take effect CTRL.RST is required.
682 switch (adapter
->hw
.mac_type
) {
683 case e1000_82542_rev2_0
:
684 case e1000_82542_rev2_1
:
689 case e1000_82541_rev_2
:
690 legacy_pba_adjust
= TRUE
;
694 case e1000_82545_rev_3
:
696 case e1000_82546_rev_3
:
700 case e1000_82547_rev_2
:
701 legacy_pba_adjust
= TRUE
;
706 case e1000_80003es2lan
:
714 case e1000_undefined
:
719 if (legacy_pba_adjust
== TRUE
) {
720 if (adapter
->netdev
->mtu
> E1000_RXBUFFER_8192
)
721 pba
-= 8; /* allocate more FIFO for Tx */
723 if (adapter
->hw
.mac_type
== e1000_82547
) {
724 adapter
->tx_fifo_head
= 0;
725 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
726 adapter
->tx_fifo_size
=
727 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
728 atomic_set(&adapter
->tx_fifo_stall
, 0);
730 } else if (adapter
->hw
.max_frame_size
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
731 /* adjust PBA for jumbo frames */
732 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
734 /* To maintain wire speed transmits, the Tx FIFO should be
735 * large enough to accomodate two full transmit packets,
736 * rounded up to the next 1KB and expressed in KB. Likewise,
737 * the Rx FIFO should be large enough to accomodate at least
738 * one full receive packet and is similarly rounded up and
739 * expressed in KB. */
740 pba
= E1000_READ_REG(&adapter
->hw
, PBA
);
741 /* upper 16 bits has Tx packet buffer allocation size in KB */
742 tx_space
= pba
>> 16;
743 /* lower 16 bits has Rx packet buffer allocation size in KB */
745 /* don't include ethernet FCS because hardware appends/strips */
746 min_rx_space
= adapter
->netdev
->mtu
+ ENET_HEADER_SIZE
+
748 min_tx_space
= min_rx_space
;
750 min_tx_space
= ALIGN(min_tx_space
, 1024);
752 min_rx_space
= ALIGN(min_rx_space
, 1024);
755 /* If current Tx allocation is less than the min Tx FIFO size,
756 * and the min Tx FIFO size is less than the current Rx FIFO
757 * allocation, take space away from current Rx allocation */
758 if (tx_space
< min_tx_space
&&
759 ((min_tx_space
- tx_space
) < pba
)) {
760 pba
= pba
- (min_tx_space
- tx_space
);
762 /* PCI/PCIx hardware has PBA alignment constraints */
763 switch (adapter
->hw
.mac_type
) {
764 case e1000_82545
... e1000_82546_rev_3
:
765 pba
&= ~(E1000_PBA_8K
- 1);
771 /* if short on rx space, rx wins and must trump tx
772 * adjustment or use Early Receive if available */
773 if (pba
< min_rx_space
) {
774 switch (adapter
->hw
.mac_type
) {
776 /* ERT enabled in e1000_configure_rx */
786 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
788 /* flow control settings */
789 /* Set the FC high water mark to 90% of the FIFO size.
790 * Required to clear last 3 LSB */
791 fc_high_water_mark
= ((pba
* 9216)/10) & 0xFFF8;
792 /* We can't use 90% on small FIFOs because the remainder
793 * would be less than 1 full frame. In this case, we size
794 * it to allow at least a full frame above the high water
796 if (pba
< E1000_PBA_16K
)
797 fc_high_water_mark
= (pba
* 1024) - 1600;
799 adapter
->hw
.fc_high_water
= fc_high_water_mark
;
800 adapter
->hw
.fc_low_water
= fc_high_water_mark
- 8;
801 if (adapter
->hw
.mac_type
== e1000_80003es2lan
)
802 adapter
->hw
.fc_pause_time
= 0xFFFF;
804 adapter
->hw
.fc_pause_time
= E1000_FC_PAUSE_TIME
;
805 adapter
->hw
.fc_send_xon
= 1;
806 adapter
->hw
.fc
= adapter
->hw
.original_fc
;
808 /* Allow time for pending master requests to run */
809 e1000_reset_hw(&adapter
->hw
);
810 if (adapter
->hw
.mac_type
>= e1000_82544
)
811 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
813 if (e1000_init_hw(&adapter
->hw
))
814 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
815 e1000_update_mng_vlan(adapter
);
817 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
818 if (adapter
->hw
.mac_type
>= e1000_82544
&&
819 adapter
->hw
.mac_type
<= e1000_82547_rev_2
&&
820 adapter
->hw
.autoneg
== 1 &&
821 adapter
->hw
.autoneg_advertised
== ADVERTISE_1000_FULL
) {
822 uint32_t ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
823 /* clear phy power management bit if we are in gig only mode,
824 * which if enabled will attempt negotiation to 100Mb, which
825 * can cause a loss of link at power off or driver unload */
826 ctrl
&= ~E1000_CTRL_SWDPIN3
;
827 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
830 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
831 E1000_WRITE_REG(&adapter
->hw
, VET
, ETHERNET_IEEE_VLAN_TYPE
);
833 e1000_reset_adaptive(&adapter
->hw
);
834 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
836 if (!adapter
->smart_power_down
&&
837 (adapter
->hw
.mac_type
== e1000_82571
||
838 adapter
->hw
.mac_type
== e1000_82572
)) {
839 uint16_t phy_data
= 0;
840 /* speed up time to link by disabling smart power down, ignore
841 * the return value of this function because there is nothing
842 * different we would do if it failed */
843 e1000_read_phy_reg(&adapter
->hw
, IGP02E1000_PHY_POWER_MGMT
,
845 phy_data
&= ~IGP02E1000_PM_SPD
;
846 e1000_write_phy_reg(&adapter
->hw
, IGP02E1000_PHY_POWER_MGMT
,
850 e1000_release_manageability(adapter
);
854 * Dump the eeprom for users having checksum issues
856 static void e1000_dump_eeprom(struct e1000_adapter
*adapter
)
858 struct net_device
*netdev
= adapter
->netdev
;
859 struct ethtool_eeprom eeprom
;
860 const struct ethtool_ops
*ops
= netdev
->ethtool_ops
;
863 u16 csum_old
, csum_new
= 0;
865 eeprom
.len
= ops
->get_eeprom_len(netdev
);
868 data
= kmalloc(eeprom
.len
, GFP_KERNEL
);
870 printk(KERN_ERR
"Unable to allocate memory to dump EEPROM"
875 ops
->get_eeprom(netdev
, &eeprom
, data
);
877 csum_old
= (data
[EEPROM_CHECKSUM_REG
* 2]) +
878 (data
[EEPROM_CHECKSUM_REG
* 2 + 1] << 8);
879 for (i
= 0; i
< EEPROM_CHECKSUM_REG
* 2; i
+= 2)
880 csum_new
+= data
[i
] + (data
[i
+ 1] << 8);
881 csum_new
= EEPROM_SUM
- csum_new
;
883 printk(KERN_ERR
"/*********************/\n");
884 printk(KERN_ERR
"Current EEPROM Checksum : 0x%04x\n", csum_old
);
885 printk(KERN_ERR
"Calculated : 0x%04x\n", csum_new
);
887 printk(KERN_ERR
"Offset Values\n");
888 printk(KERN_ERR
"======== ======\n");
889 print_hex_dump(KERN_ERR
, "", DUMP_PREFIX_OFFSET
, 16, 1, data
, 128, 0);
891 printk(KERN_ERR
"Include this output when contacting your support "
893 printk(KERN_ERR
"This is not a software error! Something bad "
894 "happened to your hardware or\n");
895 printk(KERN_ERR
"EEPROM image. Ignoring this "
896 "problem could result in further problems,\n");
897 printk(KERN_ERR
"possibly loss of data, corruption or system hangs!\n");
898 printk(KERN_ERR
"The MAC Address will be reset to 00:00:00:00:00:00, "
899 "which is invalid\n");
900 printk(KERN_ERR
"and requires you to set the proper MAC "
901 "address manually before continuing\n");
902 printk(KERN_ERR
"to enable this network device.\n");
903 printk(KERN_ERR
"Please inspect the EEPROM dump and report the issue "
904 "to your hardware vendor\n");
905 printk(KERN_ERR
"or Intel Customer Support: linux-nics@intel.com\n");
906 printk(KERN_ERR
"/*********************/\n");
912 * e1000_probe - Device Initialization Routine
913 * @pdev: PCI device information struct
914 * @ent: entry in e1000_pci_tbl
916 * Returns 0 on success, negative on failure
918 * e1000_probe initializes an adapter identified by a pci_dev structure.
919 * The OS initialization, configuring of the adapter private structure,
920 * and a hardware reset occur.
924 e1000_probe(struct pci_dev
*pdev
,
925 const struct pci_device_id
*ent
)
927 struct net_device
*netdev
;
928 struct e1000_adapter
*adapter
;
930 static int cards_found
= 0;
931 static int global_quad_port_a
= 0; /* global ksp3 port a indication */
932 int i
, err
, pci_using_dac
;
933 uint16_t eeprom_data
= 0;
934 uint16_t eeprom_apme_mask
= E1000_EEPROM_APME
;
935 DECLARE_MAC_BUF(mac
);
937 if ((err
= pci_enable_device(pdev
)))
940 if (!(err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
)) &&
941 !(err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
))) {
944 if ((err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) &&
945 (err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
))) {
946 E1000_ERR("No usable DMA configuration, aborting\n");
952 if ((err
= pci_request_regions(pdev
, e1000_driver_name
)))
955 pci_set_master(pdev
);
958 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
960 goto err_alloc_etherdev
;
962 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
964 pci_set_drvdata(pdev
, netdev
);
965 adapter
= netdev_priv(netdev
);
966 adapter
->netdev
= netdev
;
967 adapter
->pdev
= pdev
;
968 adapter
->hw
.back
= adapter
;
969 adapter
->msg_enable
= (1 << debug
) - 1;
972 adapter
->hw
.hw_addr
= ioremap(pci_resource_start(pdev
, BAR_0
),
973 pci_resource_len(pdev
, BAR_0
));
974 if (!adapter
->hw
.hw_addr
)
977 for (i
= BAR_1
; i
<= BAR_5
; i
++) {
978 if (pci_resource_len(pdev
, i
) == 0)
980 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
981 adapter
->hw
.io_base
= pci_resource_start(pdev
, i
);
986 netdev
->open
= &e1000_open
;
987 netdev
->stop
= &e1000_close
;
988 netdev
->hard_start_xmit
= &e1000_xmit_frame
;
989 netdev
->get_stats
= &e1000_get_stats
;
990 netdev
->set_rx_mode
= &e1000_set_rx_mode
;
991 netdev
->set_mac_address
= &e1000_set_mac
;
992 netdev
->change_mtu
= &e1000_change_mtu
;
993 netdev
->do_ioctl
= &e1000_ioctl
;
994 e1000_set_ethtool_ops(netdev
);
995 netdev
->tx_timeout
= &e1000_tx_timeout
;
996 netdev
->watchdog_timeo
= 5 * HZ
;
997 #ifdef CONFIG_E1000_NAPI
998 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
1000 netdev
->vlan_rx_register
= e1000_vlan_rx_register
;
1001 netdev
->vlan_rx_add_vid
= e1000_vlan_rx_add_vid
;
1002 netdev
->vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
;
1003 #ifdef CONFIG_NET_POLL_CONTROLLER
1004 netdev
->poll_controller
= e1000_netpoll
;
1006 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
1008 adapter
->bd_number
= cards_found
;
1010 /* setup the private structure */
1012 if ((err
= e1000_sw_init(adapter
)))
1016 /* Flash BAR mapping must happen after e1000_sw_init
1017 * because it depends on mac_type */
1018 if ((adapter
->hw
.mac_type
== e1000_ich8lan
) &&
1019 (pci_resource_flags(pdev
, 1) & IORESOURCE_MEM
)) {
1020 adapter
->hw
.flash_address
=
1021 ioremap(pci_resource_start(pdev
, 1),
1022 pci_resource_len(pdev
, 1));
1023 if (!adapter
->hw
.flash_address
)
1027 if (e1000_check_phy_reset_block(&adapter
->hw
))
1028 DPRINTK(PROBE
, INFO
, "PHY reset is blocked due to SOL/IDER session.\n");
1030 if (adapter
->hw
.mac_type
>= e1000_82543
) {
1031 netdev
->features
= NETIF_F_SG
|
1033 NETIF_F_HW_VLAN_TX
|
1034 NETIF_F_HW_VLAN_RX
|
1035 NETIF_F_HW_VLAN_FILTER
;
1036 if (adapter
->hw
.mac_type
== e1000_ich8lan
)
1037 netdev
->features
&= ~NETIF_F_HW_VLAN_FILTER
;
1040 if ((adapter
->hw
.mac_type
>= e1000_82544
) &&
1041 (adapter
->hw
.mac_type
!= e1000_82547
))
1042 netdev
->features
|= NETIF_F_TSO
;
1044 if (adapter
->hw
.mac_type
> e1000_82547_rev_2
)
1045 netdev
->features
|= NETIF_F_TSO6
;
1047 netdev
->features
|= NETIF_F_HIGHDMA
;
1049 netdev
->features
|= NETIF_F_LLTX
;
1051 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(&adapter
->hw
);
1053 /* initialize eeprom parameters */
1054 if (e1000_init_eeprom_params(&adapter
->hw
)) {
1055 E1000_ERR("EEPROM initialization failed\n");
1059 /* before reading the EEPROM, reset the controller to
1060 * put the device in a known good starting state */
1062 e1000_reset_hw(&adapter
->hw
);
1064 /* make sure the EEPROM is good */
1065 if (e1000_validate_eeprom_checksum(&adapter
->hw
) < 0) {
1066 DPRINTK(PROBE
, ERR
, "The EEPROM Checksum Is Not Valid\n");
1067 e1000_dump_eeprom(adapter
);
1069 * set MAC address to all zeroes to invalidate and temporary
1070 * disable this device for the user. This blocks regular
1071 * traffic while still permitting ethtool ioctls from reaching
1072 * the hardware as well as allowing the user to run the
1073 * interface after manually setting a hw addr using
1076 memset(adapter
->hw
.mac_addr
, 0, netdev
->addr_len
);
1078 /* copy the MAC address out of the EEPROM */
1079 if (e1000_read_mac_addr(&adapter
->hw
))
1080 DPRINTK(PROBE
, ERR
, "EEPROM Read Error\n");
1082 /* don't block initalization here due to bad MAC address */
1083 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
1084 memcpy(netdev
->perm_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
1086 if (!is_valid_ether_addr(netdev
->perm_addr
))
1087 DPRINTK(PROBE
, ERR
, "Invalid MAC Address\n");
1089 e1000_get_bus_info(&adapter
->hw
);
1091 init_timer(&adapter
->tx_fifo_stall_timer
);
1092 adapter
->tx_fifo_stall_timer
.function
= &e1000_82547_tx_fifo_stall
;
1093 adapter
->tx_fifo_stall_timer
.data
= (unsigned long) adapter
;
1095 init_timer(&adapter
->watchdog_timer
);
1096 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
1097 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
1099 init_timer(&adapter
->phy_info_timer
);
1100 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
1101 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
1103 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
1105 e1000_check_options(adapter
);
1107 /* Initial Wake on LAN setting
1108 * If APM wake is enabled in the EEPROM,
1109 * enable the ACPI Magic Packet filter
1112 switch (adapter
->hw
.mac_type
) {
1113 case e1000_82542_rev2_0
:
1114 case e1000_82542_rev2_1
:
1118 e1000_read_eeprom(&adapter
->hw
,
1119 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
1120 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
1123 e1000_read_eeprom(&adapter
->hw
,
1124 EEPROM_INIT_CONTROL1_REG
, 1, &eeprom_data
);
1125 eeprom_apme_mask
= E1000_EEPROM_ICH8_APME
;
1128 case e1000_82546_rev_3
:
1130 case e1000_80003es2lan
:
1131 if (E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
){
1132 e1000_read_eeprom(&adapter
->hw
,
1133 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
1138 e1000_read_eeprom(&adapter
->hw
,
1139 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
1142 if (eeprom_data
& eeprom_apme_mask
)
1143 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
1145 /* now that we have the eeprom settings, apply the special cases
1146 * where the eeprom may be wrong or the board simply won't support
1147 * wake on lan on a particular port */
1148 switch (pdev
->device
) {
1149 case E1000_DEV_ID_82546GB_PCIE
:
1150 adapter
->eeprom_wol
= 0;
1152 case E1000_DEV_ID_82546EB_FIBER
:
1153 case E1000_DEV_ID_82546GB_FIBER
:
1154 case E1000_DEV_ID_82571EB_FIBER
:
1155 /* Wake events only supported on port A for dual fiber
1156 * regardless of eeprom setting */
1157 if (E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
)
1158 adapter
->eeprom_wol
= 0;
1160 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3
:
1161 case E1000_DEV_ID_82571EB_QUAD_COPPER
:
1162 case E1000_DEV_ID_82571EB_QUAD_FIBER
:
1163 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE
:
1164 case E1000_DEV_ID_82571PT_QUAD_COPPER
:
1165 /* if quad port adapter, disable WoL on all but port A */
1166 if (global_quad_port_a
!= 0)
1167 adapter
->eeprom_wol
= 0;
1169 adapter
->quad_port_a
= 1;
1170 /* Reset for multiple quad port adapters */
1171 if (++global_quad_port_a
== 4)
1172 global_quad_port_a
= 0;
1176 /* initialize the wol settings based on the eeprom settings */
1177 adapter
->wol
= adapter
->eeprom_wol
;
1179 /* print bus type/speed/width info */
1181 struct e1000_hw
*hw
= &adapter
->hw
;
1182 DPRINTK(PROBE
, INFO
, "(PCI%s:%s:%s) ",
1183 ((hw
->bus_type
== e1000_bus_type_pcix
) ? "-X" :
1184 (hw
->bus_type
== e1000_bus_type_pci_express
? " Express":"")),
1185 ((hw
->bus_speed
== e1000_bus_speed_2500
) ? "2.5Gb/s" :
1186 (hw
->bus_speed
== e1000_bus_speed_133
) ? "133MHz" :
1187 (hw
->bus_speed
== e1000_bus_speed_120
) ? "120MHz" :
1188 (hw
->bus_speed
== e1000_bus_speed_100
) ? "100MHz" :
1189 (hw
->bus_speed
== e1000_bus_speed_66
) ? "66MHz" : "33MHz"),
1190 ((hw
->bus_width
== e1000_bus_width_64
) ? "64-bit" :
1191 (hw
->bus_width
== e1000_bus_width_pciex_4
) ? "Width x4" :
1192 (hw
->bus_width
== e1000_bus_width_pciex_1
) ? "Width x1" :
1196 printk("%s\n", print_mac(mac
, netdev
->dev_addr
));
1198 /* reset the hardware with the new settings */
1199 e1000_reset(adapter
);
1201 /* If the controller is 82573 and f/w is AMT, do not set
1202 * DRV_LOAD until the interface is up. For all other cases,
1203 * let the f/w know that the h/w is now under the control
1205 if (adapter
->hw
.mac_type
!= e1000_82573
||
1206 !e1000_check_mng_mode(&adapter
->hw
))
1207 e1000_get_hw_control(adapter
);
1209 /* tell the stack to leave us alone until e1000_open() is called */
1210 netif_carrier_off(netdev
);
1211 netif_stop_queue(netdev
);
1213 strcpy(netdev
->name
, "eth%d");
1214 if ((err
= register_netdev(netdev
)))
1217 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
1223 e1000_release_hw_control(adapter
);
1225 if (!e1000_check_phy_reset_block(&adapter
->hw
))
1226 e1000_phy_hw_reset(&adapter
->hw
);
1228 if (adapter
->hw
.flash_address
)
1229 iounmap(adapter
->hw
.flash_address
);
1231 #ifdef CONFIG_E1000_NAPI
1232 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1233 dev_put(&adapter
->polling_netdev
[i
]);
1236 kfree(adapter
->tx_ring
);
1237 kfree(adapter
->rx_ring
);
1238 #ifdef CONFIG_E1000_NAPI
1239 kfree(adapter
->polling_netdev
);
1242 iounmap(adapter
->hw
.hw_addr
);
1244 free_netdev(netdev
);
1246 pci_release_regions(pdev
);
1249 pci_disable_device(pdev
);
1254 * e1000_remove - Device Removal Routine
1255 * @pdev: PCI device information struct
1257 * e1000_remove is called by the PCI subsystem to alert the driver
1258 * that it should release a PCI device. The could be caused by a
1259 * Hot-Plug event, or because the driver is going to be removed from
1263 static void __devexit
1264 e1000_remove(struct pci_dev
*pdev
)
1266 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1267 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1268 #ifdef CONFIG_E1000_NAPI
1272 cancel_work_sync(&adapter
->reset_task
);
1274 e1000_release_manageability(adapter
);
1276 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1277 * would have already happened in close and is redundant. */
1278 e1000_release_hw_control(adapter
);
1280 #ifdef CONFIG_E1000_NAPI
1281 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1282 dev_put(&adapter
->polling_netdev
[i
]);
1285 unregister_netdev(netdev
);
1287 if (!e1000_check_phy_reset_block(&adapter
->hw
))
1288 e1000_phy_hw_reset(&adapter
->hw
);
1290 kfree(adapter
->tx_ring
);
1291 kfree(adapter
->rx_ring
);
1292 #ifdef CONFIG_E1000_NAPI
1293 kfree(adapter
->polling_netdev
);
1296 iounmap(adapter
->hw
.hw_addr
);
1297 if (adapter
->hw
.flash_address
)
1298 iounmap(adapter
->hw
.flash_address
);
1299 pci_release_regions(pdev
);
1301 free_netdev(netdev
);
1303 pci_disable_device(pdev
);
1307 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1308 * @adapter: board private structure to initialize
1310 * e1000_sw_init initializes the Adapter private data structure.
1311 * Fields are initialized based on PCI device information and
1312 * OS network device settings (MTU size).
1315 static int __devinit
1316 e1000_sw_init(struct e1000_adapter
*adapter
)
1318 struct e1000_hw
*hw
= &adapter
->hw
;
1319 struct net_device
*netdev
= adapter
->netdev
;
1320 struct pci_dev
*pdev
= adapter
->pdev
;
1321 #ifdef CONFIG_E1000_NAPI
1325 /* PCI config space info */
1327 hw
->vendor_id
= pdev
->vendor
;
1328 hw
->device_id
= pdev
->device
;
1329 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
1330 hw
->subsystem_id
= pdev
->subsystem_device
;
1331 hw
->revision_id
= pdev
->revision
;
1333 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
1335 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1336 adapter
->rx_ps_bsize0
= E1000_RXBUFFER_128
;
1337 hw
->max_frame_size
= netdev
->mtu
+
1338 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
1339 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
1341 /* identify the MAC */
1343 if (e1000_set_mac_type(hw
)) {
1344 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
1348 switch (hw
->mac_type
) {
1353 case e1000_82541_rev_2
:
1354 case e1000_82547_rev_2
:
1355 hw
->phy_init_script
= 1;
1359 e1000_set_media_type(hw
);
1361 hw
->wait_autoneg_complete
= FALSE
;
1362 hw
->tbi_compatibility_en
= TRUE
;
1363 hw
->adaptive_ifs
= TRUE
;
1365 /* Copper options */
1367 if (hw
->media_type
== e1000_media_type_copper
) {
1368 hw
->mdix
= AUTO_ALL_MODES
;
1369 hw
->disable_polarity_correction
= FALSE
;
1370 hw
->master_slave
= E1000_MASTER_SLAVE
;
1373 adapter
->num_tx_queues
= 1;
1374 adapter
->num_rx_queues
= 1;
1376 if (e1000_alloc_queues(adapter
)) {
1377 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
1381 #ifdef CONFIG_E1000_NAPI
1382 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1383 adapter
->polling_netdev
[i
].priv
= adapter
;
1384 dev_hold(&adapter
->polling_netdev
[i
]);
1385 set_bit(__LINK_STATE_START
, &adapter
->polling_netdev
[i
].state
);
1387 spin_lock_init(&adapter
->tx_queue_lock
);
1390 /* Explicitly disable IRQ since the NIC can be in any state. */
1391 atomic_set(&adapter
->irq_sem
, 0);
1392 e1000_irq_disable(adapter
);
1394 spin_lock_init(&adapter
->stats_lock
);
1396 set_bit(__E1000_DOWN
, &adapter
->flags
);
1402 * e1000_alloc_queues - Allocate memory for all rings
1403 * @adapter: board private structure to initialize
1405 * We allocate one ring per queue at run-time since we don't know the
1406 * number of queues at compile-time. The polling_netdev array is
1407 * intended for Multiqueue, but should work fine with a single queue.
1410 static int __devinit
1411 e1000_alloc_queues(struct e1000_adapter
*adapter
)
1413 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1414 sizeof(struct e1000_tx_ring
), GFP_KERNEL
);
1415 if (!adapter
->tx_ring
)
1418 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
1419 sizeof(struct e1000_rx_ring
), GFP_KERNEL
);
1420 if (!adapter
->rx_ring
) {
1421 kfree(adapter
->tx_ring
);
1425 #ifdef CONFIG_E1000_NAPI
1426 adapter
->polling_netdev
= kcalloc(adapter
->num_rx_queues
,
1427 sizeof(struct net_device
),
1429 if (!adapter
->polling_netdev
) {
1430 kfree(adapter
->tx_ring
);
1431 kfree(adapter
->rx_ring
);
1436 return E1000_SUCCESS
;
1440 * e1000_open - Called when a network interface is made active
1441 * @netdev: network interface device structure
1443 * Returns 0 on success, negative value on failure
1445 * The open entry point is called when a network interface is made
1446 * active by the system (IFF_UP). At this point all resources needed
1447 * for transmit and receive operations are allocated, the interrupt
1448 * handler is registered with the OS, the watchdog timer is started,
1449 * and the stack is notified that the interface is ready.
1453 e1000_open(struct net_device
*netdev
)
1455 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1458 /* disallow open during test */
1459 if (test_bit(__E1000_TESTING
, &adapter
->flags
))
1462 /* allocate transmit descriptors */
1463 err
= e1000_setup_all_tx_resources(adapter
);
1467 /* allocate receive descriptors */
1468 err
= e1000_setup_all_rx_resources(adapter
);
1472 e1000_power_up_phy(adapter
);
1474 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1475 if ((adapter
->hw
.mng_cookie
.status
&
1476 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1477 e1000_update_mng_vlan(adapter
);
1480 /* If AMT is enabled, let the firmware know that the network
1481 * interface is now open */
1482 if (adapter
->hw
.mac_type
== e1000_82573
&&
1483 e1000_check_mng_mode(&adapter
->hw
))
1484 e1000_get_hw_control(adapter
);
1486 /* before we allocate an interrupt, we must be ready to handle it.
1487 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1488 * as soon as we call pci_request_irq, so we have to setup our
1489 * clean_rx handler before we do so. */
1490 e1000_configure(adapter
);
1492 err
= e1000_request_irq(adapter
);
1496 /* From here on the code is the same as e1000_up() */
1497 clear_bit(__E1000_DOWN
, &adapter
->flags
);
1499 #ifdef CONFIG_E1000_NAPI
1500 napi_enable(&adapter
->napi
);
1503 e1000_irq_enable(adapter
);
1505 /* fire a link status change interrupt to start the watchdog */
1506 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_LSC
);
1508 return E1000_SUCCESS
;
1511 e1000_release_hw_control(adapter
);
1512 e1000_power_down_phy(adapter
);
1513 e1000_free_all_rx_resources(adapter
);
1515 e1000_free_all_tx_resources(adapter
);
1517 e1000_reset(adapter
);
1523 * e1000_close - Disables a network interface
1524 * @netdev: network interface device structure
1526 * Returns 0, this is not allowed to fail
1528 * The close entry point is called when an interface is de-activated
1529 * by the OS. The hardware is still under the drivers control, but
1530 * needs to be disabled. A global MAC reset is issued to stop the
1531 * hardware, and all transmit and receive resources are freed.
1535 e1000_close(struct net_device
*netdev
)
1537 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1539 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
1540 e1000_down(adapter
);
1541 e1000_power_down_phy(adapter
);
1542 e1000_free_irq(adapter
);
1544 e1000_free_all_tx_resources(adapter
);
1545 e1000_free_all_rx_resources(adapter
);
1547 /* kill manageability vlan ID if supported, but not if a vlan with
1548 * the same ID is registered on the host OS (let 8021q kill it) */
1549 if ((adapter
->hw
.mng_cookie
.status
&
1550 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
1552 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
))) {
1553 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1556 /* If AMT is enabled, let the firmware know that the network
1557 * interface is now closed */
1558 if (adapter
->hw
.mac_type
== e1000_82573
&&
1559 e1000_check_mng_mode(&adapter
->hw
))
1560 e1000_release_hw_control(adapter
);
1566 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1567 * @adapter: address of board private structure
1568 * @start: address of beginning of memory
1569 * @len: length of memory
1572 e1000_check_64k_bound(struct e1000_adapter
*adapter
,
1573 void *start
, unsigned long len
)
1575 unsigned long begin
= (unsigned long) start
;
1576 unsigned long end
= begin
+ len
;
1578 /* First rev 82545 and 82546 need to not allow any memory
1579 * write location to cross 64k boundary due to errata 23 */
1580 if (adapter
->hw
.mac_type
== e1000_82545
||
1581 adapter
->hw
.mac_type
== e1000_82546
) {
1582 return ((begin
^ (end
- 1)) >> 16) != 0 ? FALSE
: TRUE
;
1589 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1590 * @adapter: board private structure
1591 * @txdr: tx descriptor ring (for a specific queue) to setup
1593 * Return 0 on success, negative on failure
1597 e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1598 struct e1000_tx_ring
*txdr
)
1600 struct pci_dev
*pdev
= adapter
->pdev
;
1603 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1604 txdr
->buffer_info
= vmalloc(size
);
1605 if (!txdr
->buffer_info
) {
1607 "Unable to allocate memory for the transmit descriptor ring\n");
1610 memset(txdr
->buffer_info
, 0, size
);
1612 /* round up to nearest 4K */
1614 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1615 txdr
->size
= ALIGN(txdr
->size
, 4096);
1617 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1620 vfree(txdr
->buffer_info
);
1622 "Unable to allocate memory for the transmit descriptor ring\n");
1626 /* Fix for errata 23, can't cross 64kB boundary */
1627 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1628 void *olddesc
= txdr
->desc
;
1629 dma_addr_t olddma
= txdr
->dma
;
1630 DPRINTK(TX_ERR
, ERR
, "txdr align check failed: %u bytes "
1631 "at %p\n", txdr
->size
, txdr
->desc
);
1632 /* Try again, without freeing the previous */
1633 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1634 /* Failed allocation, critical failure */
1636 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1637 goto setup_tx_desc_die
;
1640 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1642 pci_free_consistent(pdev
, txdr
->size
, txdr
->desc
,
1644 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1646 "Unable to allocate aligned memory "
1647 "for the transmit descriptor ring\n");
1648 vfree(txdr
->buffer_info
);
1651 /* Free old allocation, new allocation was successful */
1652 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1655 memset(txdr
->desc
, 0, txdr
->size
);
1657 txdr
->next_to_use
= 0;
1658 txdr
->next_to_clean
= 0;
1659 spin_lock_init(&txdr
->tx_lock
);
1665 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1666 * (Descriptors) for all queues
1667 * @adapter: board private structure
1669 * Return 0 on success, negative on failure
1673 e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1677 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1678 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1681 "Allocation for Tx Queue %u failed\n", i
);
1682 for (i
-- ; i
>= 0; i
--)
1683 e1000_free_tx_resources(adapter
,
1684 &adapter
->tx_ring
[i
]);
1693 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1694 * @adapter: board private structure
1696 * Configure the Tx unit of the MAC after a reset.
1700 e1000_configure_tx(struct e1000_adapter
*adapter
)
1703 struct e1000_hw
*hw
= &adapter
->hw
;
1704 uint32_t tdlen
, tctl
, tipg
, tarc
;
1705 uint32_t ipgr1
, ipgr2
;
1707 /* Setup the HW Tx Head and Tail descriptor pointers */
1709 switch (adapter
->num_tx_queues
) {
1712 tdba
= adapter
->tx_ring
[0].dma
;
1713 tdlen
= adapter
->tx_ring
[0].count
*
1714 sizeof(struct e1000_tx_desc
);
1715 E1000_WRITE_REG(hw
, TDLEN
, tdlen
);
1716 E1000_WRITE_REG(hw
, TDBAH
, (tdba
>> 32));
1717 E1000_WRITE_REG(hw
, TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1718 E1000_WRITE_REG(hw
, TDT
, 0);
1719 E1000_WRITE_REG(hw
, TDH
, 0);
1720 adapter
->tx_ring
[0].tdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDH
: E1000_82542_TDH
);
1721 adapter
->tx_ring
[0].tdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDT
: E1000_82542_TDT
);
1725 /* Set the default values for the Tx Inter Packet Gap timer */
1726 if (adapter
->hw
.mac_type
<= e1000_82547_rev_2
&&
1727 (hw
->media_type
== e1000_media_type_fiber
||
1728 hw
->media_type
== e1000_media_type_internal_serdes
))
1729 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1731 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1733 switch (hw
->mac_type
) {
1734 case e1000_82542_rev2_0
:
1735 case e1000_82542_rev2_1
:
1736 tipg
= DEFAULT_82542_TIPG_IPGT
;
1737 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
1738 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
1740 case e1000_80003es2lan
:
1741 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1742 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
;
1745 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1746 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
1749 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1750 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1751 E1000_WRITE_REG(hw
, TIPG
, tipg
);
1753 /* Set the Tx Interrupt Delay register */
1755 E1000_WRITE_REG(hw
, TIDV
, adapter
->tx_int_delay
);
1756 if (hw
->mac_type
>= e1000_82540
)
1757 E1000_WRITE_REG(hw
, TADV
, adapter
->tx_abs_int_delay
);
1759 /* Program the Transmit Control Register */
1761 tctl
= E1000_READ_REG(hw
, TCTL
);
1762 tctl
&= ~E1000_TCTL_CT
;
1763 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1764 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1766 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
1767 tarc
= E1000_READ_REG(hw
, TARC0
);
1768 /* set the speed mode bit, we'll clear it if we're not at
1769 * gigabit link later */
1771 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1772 } else if (hw
->mac_type
== e1000_80003es2lan
) {
1773 tarc
= E1000_READ_REG(hw
, TARC0
);
1775 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1776 tarc
= E1000_READ_REG(hw
, TARC1
);
1778 E1000_WRITE_REG(hw
, TARC1
, tarc
);
1781 e1000_config_collision_dist(hw
);
1783 /* Setup Transmit Descriptor Settings for eop descriptor */
1784 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
1786 /* only set IDE if we are delaying interrupts using the timers */
1787 if (adapter
->tx_int_delay
)
1788 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
1790 if (hw
->mac_type
< e1000_82543
)
1791 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1793 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1795 /* Cache if we're 82544 running in PCI-X because we'll
1796 * need this to apply a workaround later in the send path. */
1797 if (hw
->mac_type
== e1000_82544
&&
1798 hw
->bus_type
== e1000_bus_type_pcix
)
1799 adapter
->pcix_82544
= 1;
1801 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1806 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1807 * @adapter: board private structure
1808 * @rxdr: rx descriptor ring (for a specific queue) to setup
1810 * Returns 0 on success, negative on failure
1814 e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1815 struct e1000_rx_ring
*rxdr
)
1817 struct pci_dev
*pdev
= adapter
->pdev
;
1820 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1821 rxdr
->buffer_info
= vmalloc(size
);
1822 if (!rxdr
->buffer_info
) {
1824 "Unable to allocate memory for the receive descriptor ring\n");
1827 memset(rxdr
->buffer_info
, 0, size
);
1829 rxdr
->ps_page
= kcalloc(rxdr
->count
, sizeof(struct e1000_ps_page
),
1831 if (!rxdr
->ps_page
) {
1832 vfree(rxdr
->buffer_info
);
1834 "Unable to allocate memory for the receive descriptor ring\n");
1838 rxdr
->ps_page_dma
= kcalloc(rxdr
->count
,
1839 sizeof(struct e1000_ps_page_dma
),
1841 if (!rxdr
->ps_page_dma
) {
1842 vfree(rxdr
->buffer_info
);
1843 kfree(rxdr
->ps_page
);
1845 "Unable to allocate memory for the receive descriptor ring\n");
1849 if (adapter
->hw
.mac_type
<= e1000_82547_rev_2
)
1850 desc_len
= sizeof(struct e1000_rx_desc
);
1852 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1854 /* Round up to nearest 4K */
1856 rxdr
->size
= rxdr
->count
* desc_len
;
1857 rxdr
->size
= ALIGN(rxdr
->size
, 4096);
1859 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1863 "Unable to allocate memory for the receive descriptor ring\n");
1865 vfree(rxdr
->buffer_info
);
1866 kfree(rxdr
->ps_page
);
1867 kfree(rxdr
->ps_page_dma
);
1871 /* Fix for errata 23, can't cross 64kB boundary */
1872 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1873 void *olddesc
= rxdr
->desc
;
1874 dma_addr_t olddma
= rxdr
->dma
;
1875 DPRINTK(RX_ERR
, ERR
, "rxdr align check failed: %u bytes "
1876 "at %p\n", rxdr
->size
, rxdr
->desc
);
1877 /* Try again, without freeing the previous */
1878 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1879 /* Failed allocation, critical failure */
1881 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1883 "Unable to allocate memory "
1884 "for the receive descriptor ring\n");
1885 goto setup_rx_desc_die
;
1888 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1890 pci_free_consistent(pdev
, rxdr
->size
, rxdr
->desc
,
1892 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1894 "Unable to allocate aligned memory "
1895 "for the receive descriptor ring\n");
1896 goto setup_rx_desc_die
;
1898 /* Free old allocation, new allocation was successful */
1899 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1902 memset(rxdr
->desc
, 0, rxdr
->size
);
1904 rxdr
->next_to_clean
= 0;
1905 rxdr
->next_to_use
= 0;
1911 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1912 * (Descriptors) for all queues
1913 * @adapter: board private structure
1915 * Return 0 on success, negative on failure
1919 e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1923 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1924 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1927 "Allocation for Rx Queue %u failed\n", i
);
1928 for (i
-- ; i
>= 0; i
--)
1929 e1000_free_rx_resources(adapter
,
1930 &adapter
->rx_ring
[i
]);
1939 * e1000_setup_rctl - configure the receive control registers
1940 * @adapter: Board private structure
1942 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1943 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1945 e1000_setup_rctl(struct e1000_adapter
*adapter
)
1947 uint32_t rctl
, rfctl
;
1948 uint32_t psrctl
= 0;
1949 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1953 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1955 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1957 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1958 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1959 (adapter
->hw
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1961 if (adapter
->hw
.tbi_compatibility_on
== 1)
1962 rctl
|= E1000_RCTL_SBP
;
1964 rctl
&= ~E1000_RCTL_SBP
;
1966 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1967 rctl
&= ~E1000_RCTL_LPE
;
1969 rctl
|= E1000_RCTL_LPE
;
1971 /* Setup buffer sizes */
1972 rctl
&= ~E1000_RCTL_SZ_4096
;
1973 rctl
|= E1000_RCTL_BSEX
;
1974 switch (adapter
->rx_buffer_len
) {
1975 case E1000_RXBUFFER_256
:
1976 rctl
|= E1000_RCTL_SZ_256
;
1977 rctl
&= ~E1000_RCTL_BSEX
;
1979 case E1000_RXBUFFER_512
:
1980 rctl
|= E1000_RCTL_SZ_512
;
1981 rctl
&= ~E1000_RCTL_BSEX
;
1983 case E1000_RXBUFFER_1024
:
1984 rctl
|= E1000_RCTL_SZ_1024
;
1985 rctl
&= ~E1000_RCTL_BSEX
;
1987 case E1000_RXBUFFER_2048
:
1989 rctl
|= E1000_RCTL_SZ_2048
;
1990 rctl
&= ~E1000_RCTL_BSEX
;
1992 case E1000_RXBUFFER_4096
:
1993 rctl
|= E1000_RCTL_SZ_4096
;
1995 case E1000_RXBUFFER_8192
:
1996 rctl
|= E1000_RCTL_SZ_8192
;
1998 case E1000_RXBUFFER_16384
:
1999 rctl
|= E1000_RCTL_SZ_16384
;
2003 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
2004 /* 82571 and greater support packet-split where the protocol
2005 * header is placed in skb->data and the packet data is
2006 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2007 * In the case of a non-split, skb->data is linearly filled,
2008 * followed by the page buffers. Therefore, skb->data is
2009 * sized to hold the largest protocol header.
2011 /* allocations using alloc_page take too long for regular MTU
2012 * so only enable packet split for jumbo frames */
2013 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
2014 if ((adapter
->hw
.mac_type
>= e1000_82571
) && (pages
<= 3) &&
2015 PAGE_SIZE
<= 16384 && (rctl
& E1000_RCTL_LPE
))
2016 adapter
->rx_ps_pages
= pages
;
2018 adapter
->rx_ps_pages
= 0;
2020 if (adapter
->rx_ps_pages
) {
2021 /* Configure extra packet-split registers */
2022 rfctl
= E1000_READ_REG(&adapter
->hw
, RFCTL
);
2023 rfctl
|= E1000_RFCTL_EXTEN
;
2024 /* disable packet split support for IPv6 extension headers,
2025 * because some malformed IPv6 headers can hang the RX */
2026 rfctl
|= (E1000_RFCTL_IPV6_EX_DIS
|
2027 E1000_RFCTL_NEW_IPV6_EXT_DIS
);
2029 E1000_WRITE_REG(&adapter
->hw
, RFCTL
, rfctl
);
2031 rctl
|= E1000_RCTL_DTYP_PS
;
2033 psrctl
|= adapter
->rx_ps_bsize0
>>
2034 E1000_PSRCTL_BSIZE0_SHIFT
;
2036 switch (adapter
->rx_ps_pages
) {
2038 psrctl
|= PAGE_SIZE
<<
2039 E1000_PSRCTL_BSIZE3_SHIFT
;
2041 psrctl
|= PAGE_SIZE
<<
2042 E1000_PSRCTL_BSIZE2_SHIFT
;
2044 psrctl
|= PAGE_SIZE
>>
2045 E1000_PSRCTL_BSIZE1_SHIFT
;
2049 E1000_WRITE_REG(&adapter
->hw
, PSRCTL
, psrctl
);
2052 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2056 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2057 * @adapter: board private structure
2059 * Configure the Rx unit of the MAC after a reset.
2063 e1000_configure_rx(struct e1000_adapter
*adapter
)
2066 struct e1000_hw
*hw
= &adapter
->hw
;
2067 uint32_t rdlen
, rctl
, rxcsum
, ctrl_ext
;
2069 if (adapter
->rx_ps_pages
) {
2070 /* this is a 32 byte descriptor */
2071 rdlen
= adapter
->rx_ring
[0].count
*
2072 sizeof(union e1000_rx_desc_packet_split
);
2073 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
2074 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
2076 rdlen
= adapter
->rx_ring
[0].count
*
2077 sizeof(struct e1000_rx_desc
);
2078 adapter
->clean_rx
= e1000_clean_rx_irq
;
2079 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
2082 /* disable receives while setting up the descriptors */
2083 rctl
= E1000_READ_REG(hw
, RCTL
);
2084 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
2086 /* set the Receive Delay Timer Register */
2087 E1000_WRITE_REG(hw
, RDTR
, adapter
->rx_int_delay
);
2089 if (hw
->mac_type
>= e1000_82540
) {
2090 E1000_WRITE_REG(hw
, RADV
, adapter
->rx_abs_int_delay
);
2091 if (adapter
->itr_setting
!= 0)
2092 E1000_WRITE_REG(hw
, ITR
,
2093 1000000000 / (adapter
->itr
* 256));
2096 if (hw
->mac_type
>= e1000_82571
) {
2097 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
2098 /* Reset delay timers after every interrupt */
2099 ctrl_ext
|= E1000_CTRL_EXT_INT_TIMER_CLR
;
2100 #ifdef CONFIG_E1000_NAPI
2101 /* Auto-Mask interrupts upon ICR access */
2102 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
2103 E1000_WRITE_REG(hw
, IAM
, 0xffffffff);
2105 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
2106 E1000_WRITE_FLUSH(hw
);
2109 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2110 * the Base and Length of the Rx Descriptor Ring */
2111 switch (adapter
->num_rx_queues
) {
2114 rdba
= adapter
->rx_ring
[0].dma
;
2115 E1000_WRITE_REG(hw
, RDLEN
, rdlen
);
2116 E1000_WRITE_REG(hw
, RDBAH
, (rdba
>> 32));
2117 E1000_WRITE_REG(hw
, RDBAL
, (rdba
& 0x00000000ffffffffULL
));
2118 E1000_WRITE_REG(hw
, RDT
, 0);
2119 E1000_WRITE_REG(hw
, RDH
, 0);
2120 adapter
->rx_ring
[0].rdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDH
: E1000_82542_RDH
);
2121 adapter
->rx_ring
[0].rdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDT
: E1000_82542_RDT
);
2125 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2126 if (hw
->mac_type
>= e1000_82543
) {
2127 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
2128 if (adapter
->rx_csum
== TRUE
) {
2129 rxcsum
|= E1000_RXCSUM_TUOFL
;
2131 /* Enable 82571 IPv4 payload checksum for UDP fragments
2132 * Must be used in conjunction with packet-split. */
2133 if ((hw
->mac_type
>= e1000_82571
) &&
2134 (adapter
->rx_ps_pages
)) {
2135 rxcsum
|= E1000_RXCSUM_IPPCSE
;
2138 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
2139 /* don't need to clear IPPCSE as it defaults to 0 */
2141 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
2144 /* enable early receives on 82573, only takes effect if using > 2048
2145 * byte total frame size. for example only for jumbo frames */
2146 #define E1000_ERT_2048 0x100
2147 if (hw
->mac_type
== e1000_82573
)
2148 E1000_WRITE_REG(hw
, ERT
, E1000_ERT_2048
);
2150 /* Enable Receives */
2151 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2155 * e1000_free_tx_resources - Free Tx Resources per Queue
2156 * @adapter: board private structure
2157 * @tx_ring: Tx descriptor ring for a specific queue
2159 * Free all transmit software resources
2163 e1000_free_tx_resources(struct e1000_adapter
*adapter
,
2164 struct e1000_tx_ring
*tx_ring
)
2166 struct pci_dev
*pdev
= adapter
->pdev
;
2168 e1000_clean_tx_ring(adapter
, tx_ring
);
2170 vfree(tx_ring
->buffer_info
);
2171 tx_ring
->buffer_info
= NULL
;
2173 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
2175 tx_ring
->desc
= NULL
;
2179 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
2180 * @adapter: board private structure
2182 * Free all transmit software resources
2186 e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
2190 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2191 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
2195 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
2196 struct e1000_buffer
*buffer_info
)
2198 if (buffer_info
->dma
) {
2199 pci_unmap_page(adapter
->pdev
,
2201 buffer_info
->length
,
2203 buffer_info
->dma
= 0;
2205 if (buffer_info
->skb
) {
2206 dev_kfree_skb_any(buffer_info
->skb
);
2207 buffer_info
->skb
= NULL
;
2209 /* buffer_info must be completely set up in the transmit path */
2213 * e1000_clean_tx_ring - Free Tx Buffers
2214 * @adapter: board private structure
2215 * @tx_ring: ring to be cleaned
2219 e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
2220 struct e1000_tx_ring
*tx_ring
)
2222 struct e1000_buffer
*buffer_info
;
2226 /* Free all the Tx ring sk_buffs */
2228 for (i
= 0; i
< tx_ring
->count
; i
++) {
2229 buffer_info
= &tx_ring
->buffer_info
[i
];
2230 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
2233 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
2234 memset(tx_ring
->buffer_info
, 0, size
);
2236 /* Zero out the descriptor ring */
2238 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2240 tx_ring
->next_to_use
= 0;
2241 tx_ring
->next_to_clean
= 0;
2242 tx_ring
->last_tx_tso
= 0;
2244 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdh
);
2245 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
2249 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2250 * @adapter: board private structure
2254 e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
2258 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2259 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
2263 * e1000_free_rx_resources - Free Rx Resources
2264 * @adapter: board private structure
2265 * @rx_ring: ring to clean the resources from
2267 * Free all receive software resources
2271 e1000_free_rx_resources(struct e1000_adapter
*adapter
,
2272 struct e1000_rx_ring
*rx_ring
)
2274 struct pci_dev
*pdev
= adapter
->pdev
;
2276 e1000_clean_rx_ring(adapter
, rx_ring
);
2278 vfree(rx_ring
->buffer_info
);
2279 rx_ring
->buffer_info
= NULL
;
2280 kfree(rx_ring
->ps_page
);
2281 rx_ring
->ps_page
= NULL
;
2282 kfree(rx_ring
->ps_page_dma
);
2283 rx_ring
->ps_page_dma
= NULL
;
2285 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
2287 rx_ring
->desc
= NULL
;
2291 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2292 * @adapter: board private structure
2294 * Free all receive software resources
2298 e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
2302 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2303 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2307 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2308 * @adapter: board private structure
2309 * @rx_ring: ring to free buffers from
2313 e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
2314 struct e1000_rx_ring
*rx_ring
)
2316 struct e1000_buffer
*buffer_info
;
2317 struct e1000_ps_page
*ps_page
;
2318 struct e1000_ps_page_dma
*ps_page_dma
;
2319 struct pci_dev
*pdev
= adapter
->pdev
;
2323 /* Free all the Rx ring sk_buffs */
2324 for (i
= 0; i
< rx_ring
->count
; i
++) {
2325 buffer_info
= &rx_ring
->buffer_info
[i
];
2326 if (buffer_info
->skb
) {
2327 pci_unmap_single(pdev
,
2329 buffer_info
->length
,
2330 PCI_DMA_FROMDEVICE
);
2332 dev_kfree_skb(buffer_info
->skb
);
2333 buffer_info
->skb
= NULL
;
2335 ps_page
= &rx_ring
->ps_page
[i
];
2336 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2337 for (j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
2338 if (!ps_page
->ps_page
[j
]) break;
2339 pci_unmap_page(pdev
,
2340 ps_page_dma
->ps_page_dma
[j
],
2341 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
2342 ps_page_dma
->ps_page_dma
[j
] = 0;
2343 put_page(ps_page
->ps_page
[j
]);
2344 ps_page
->ps_page
[j
] = NULL
;
2348 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2349 memset(rx_ring
->buffer_info
, 0, size
);
2350 size
= sizeof(struct e1000_ps_page
) * rx_ring
->count
;
2351 memset(rx_ring
->ps_page
, 0, size
);
2352 size
= sizeof(struct e1000_ps_page_dma
) * rx_ring
->count
;
2353 memset(rx_ring
->ps_page_dma
, 0, size
);
2355 /* Zero out the descriptor ring */
2357 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2359 rx_ring
->next_to_clean
= 0;
2360 rx_ring
->next_to_use
= 0;
2362 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdh
);
2363 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
2367 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2368 * @adapter: board private structure
2372 e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2376 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2377 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2380 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2381 * and memory write and invalidate disabled for certain operations
2384 e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2386 struct net_device
*netdev
= adapter
->netdev
;
2389 e1000_pci_clear_mwi(&adapter
->hw
);
2391 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2392 rctl
|= E1000_RCTL_RST
;
2393 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2394 E1000_WRITE_FLUSH(&adapter
->hw
);
2397 if (netif_running(netdev
))
2398 e1000_clean_all_rx_rings(adapter
);
2402 e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2404 struct net_device
*netdev
= adapter
->netdev
;
2407 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2408 rctl
&= ~E1000_RCTL_RST
;
2409 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2410 E1000_WRITE_FLUSH(&adapter
->hw
);
2413 if (adapter
->hw
.pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2414 e1000_pci_set_mwi(&adapter
->hw
);
2416 if (netif_running(netdev
)) {
2417 /* No need to loop, because 82542 supports only 1 queue */
2418 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[0];
2419 e1000_configure_rx(adapter
);
2420 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
2425 * e1000_set_mac - Change the Ethernet Address of the NIC
2426 * @netdev: network interface device structure
2427 * @p: pointer to an address structure
2429 * Returns 0 on success, negative on failure
2433 e1000_set_mac(struct net_device
*netdev
, void *p
)
2435 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2436 struct sockaddr
*addr
= p
;
2438 if (!is_valid_ether_addr(addr
->sa_data
))
2439 return -EADDRNOTAVAIL
;
2441 /* 82542 2.0 needs to be in reset to write receive address registers */
2443 if (adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2444 e1000_enter_82542_rst(adapter
);
2446 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2447 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2449 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2451 /* With 82571 controllers, LAA may be overwritten (with the default)
2452 * due to controller reset from the other port. */
2453 if (adapter
->hw
.mac_type
== e1000_82571
) {
2454 /* activate the work around */
2455 adapter
->hw
.laa_is_present
= 1;
2457 /* Hold a copy of the LAA in RAR[14] This is done so that
2458 * between the time RAR[0] gets clobbered and the time it
2459 * gets fixed (in e1000_watchdog), the actual LAA is in one
2460 * of the RARs and no incoming packets directed to this port
2461 * are dropped. Eventaully the LAA will be in RAR[0] and
2463 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
,
2464 E1000_RAR_ENTRIES
- 1);
2467 if (adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2468 e1000_leave_82542_rst(adapter
);
2474 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2475 * @netdev: network interface device structure
2477 * The set_rx_mode entry point is called whenever the unicast or multicast
2478 * address lists or the network interface flags are updated. This routine is
2479 * responsible for configuring the hardware for proper unicast, multicast,
2480 * promiscuous mode, and all-multi behavior.
2484 e1000_set_rx_mode(struct net_device
*netdev
)
2486 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2487 struct e1000_hw
*hw
= &adapter
->hw
;
2488 struct dev_addr_list
*uc_ptr
;
2489 struct dev_addr_list
*mc_ptr
;
2491 uint32_t hash_value
;
2492 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2493 int mta_reg_count
= (hw
->mac_type
== e1000_ich8lan
) ?
2494 E1000_NUM_MTA_REGISTERS_ICH8LAN
:
2495 E1000_NUM_MTA_REGISTERS
;
2497 if (adapter
->hw
.mac_type
== e1000_ich8lan
)
2498 rar_entries
= E1000_RAR_ENTRIES_ICH8LAN
;
2500 /* reserve RAR[14] for LAA over-write work-around */
2501 if (adapter
->hw
.mac_type
== e1000_82571
)
2504 /* Check for Promiscuous and All Multicast modes */
2506 rctl
= E1000_READ_REG(hw
, RCTL
);
2508 if (netdev
->flags
& IFF_PROMISC
) {
2509 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2510 } else if (netdev
->flags
& IFF_ALLMULTI
) {
2511 rctl
|= E1000_RCTL_MPE
;
2513 rctl
&= ~E1000_RCTL_MPE
;
2517 if (netdev
->uc_count
> rar_entries
- 1) {
2518 rctl
|= E1000_RCTL_UPE
;
2519 } else if (!(netdev
->flags
& IFF_PROMISC
)) {
2520 rctl
&= ~E1000_RCTL_UPE
;
2521 uc_ptr
= netdev
->uc_list
;
2524 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2526 /* 82542 2.0 needs to be in reset to write receive address registers */
2528 if (hw
->mac_type
== e1000_82542_rev2_0
)
2529 e1000_enter_82542_rst(adapter
);
2531 /* load the first 14 addresses into the exact filters 1-14. Unicast
2532 * addresses take precedence to avoid disabling unicast filtering
2535 * RAR 0 is used for the station MAC adddress
2536 * if there are not 14 addresses, go ahead and clear the filters
2537 * -- with 82571 controllers only 0-13 entries are filled here
2539 mc_ptr
= netdev
->mc_list
;
2541 for (i
= 1; i
< rar_entries
; i
++) {
2543 e1000_rar_set(hw
, uc_ptr
->da_addr
, i
);
2544 uc_ptr
= uc_ptr
->next
;
2545 } else if (mc_ptr
) {
2546 e1000_rar_set(hw
, mc_ptr
->da_addr
, i
);
2547 mc_ptr
= mc_ptr
->next
;
2549 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2550 E1000_WRITE_FLUSH(hw
);
2551 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2552 E1000_WRITE_FLUSH(hw
);
2555 WARN_ON(uc_ptr
!= NULL
);
2557 /* clear the old settings from the multicast hash table */
2559 for (i
= 0; i
< mta_reg_count
; i
++) {
2560 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
2561 E1000_WRITE_FLUSH(hw
);
2564 /* load any remaining addresses into the hash table */
2566 for (; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
2567 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->da_addr
);
2568 e1000_mta_set(hw
, hash_value
);
2571 if (hw
->mac_type
== e1000_82542_rev2_0
)
2572 e1000_leave_82542_rst(adapter
);
2575 /* Need to wait a few seconds after link up to get diagnostic information from
2579 e1000_update_phy_info(unsigned long data
)
2581 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2582 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
2586 * e1000_82547_tx_fifo_stall - Timer Call-back
2587 * @data: pointer to adapter cast into an unsigned long
2591 e1000_82547_tx_fifo_stall(unsigned long data
)
2593 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2594 struct net_device
*netdev
= adapter
->netdev
;
2597 if (atomic_read(&adapter
->tx_fifo_stall
)) {
2598 if ((E1000_READ_REG(&adapter
->hw
, TDT
) ==
2599 E1000_READ_REG(&adapter
->hw
, TDH
)) &&
2600 (E1000_READ_REG(&adapter
->hw
, TDFT
) ==
2601 E1000_READ_REG(&adapter
->hw
, TDFH
)) &&
2602 (E1000_READ_REG(&adapter
->hw
, TDFTS
) ==
2603 E1000_READ_REG(&adapter
->hw
, TDFHS
))) {
2604 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2605 E1000_WRITE_REG(&adapter
->hw
, TCTL
,
2606 tctl
& ~E1000_TCTL_EN
);
2607 E1000_WRITE_REG(&adapter
->hw
, TDFT
,
2608 adapter
->tx_head_addr
);
2609 E1000_WRITE_REG(&adapter
->hw
, TDFH
,
2610 adapter
->tx_head_addr
);
2611 E1000_WRITE_REG(&adapter
->hw
, TDFTS
,
2612 adapter
->tx_head_addr
);
2613 E1000_WRITE_REG(&adapter
->hw
, TDFHS
,
2614 adapter
->tx_head_addr
);
2615 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2616 E1000_WRITE_FLUSH(&adapter
->hw
);
2618 adapter
->tx_fifo_head
= 0;
2619 atomic_set(&adapter
->tx_fifo_stall
, 0);
2620 netif_wake_queue(netdev
);
2622 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2628 * e1000_watchdog - Timer Call-back
2629 * @data: pointer to adapter cast into an unsigned long
2632 e1000_watchdog(unsigned long data
)
2634 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2635 struct net_device
*netdev
= adapter
->netdev
;
2636 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2637 uint32_t link
, tctl
;
2640 ret_val
= e1000_check_for_link(&adapter
->hw
);
2641 if ((ret_val
== E1000_ERR_PHY
) &&
2642 (adapter
->hw
.phy_type
== e1000_phy_igp_3
) &&
2643 (E1000_READ_REG(&adapter
->hw
, CTRL
) & E1000_PHY_CTRL_GBE_DISABLE
)) {
2644 /* See e1000_kumeran_lock_loss_workaround() */
2646 "Gigabit has been disabled, downgrading speed\n");
2649 if (adapter
->hw
.mac_type
== e1000_82573
) {
2650 e1000_enable_tx_pkt_filtering(&adapter
->hw
);
2651 if (adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
)
2652 e1000_update_mng_vlan(adapter
);
2655 if ((adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) &&
2656 !(E1000_READ_REG(&adapter
->hw
, TXCW
) & E1000_TXCW_ANE
))
2657 link
= !adapter
->hw
.serdes_link_down
;
2659 link
= E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_LU
;
2662 if (!netif_carrier_ok(netdev
)) {
2664 boolean_t txb2b
= 1;
2665 e1000_get_speed_and_duplex(&adapter
->hw
,
2666 &adapter
->link_speed
,
2667 &adapter
->link_duplex
);
2669 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
2670 DPRINTK(LINK
, INFO
, "NIC Link is Up %d Mbps %s, "
2671 "Flow Control: %s\n",
2672 adapter
->link_speed
,
2673 adapter
->link_duplex
== FULL_DUPLEX
?
2674 "Full Duplex" : "Half Duplex",
2675 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
&
2676 E1000_CTRL_RFCE
)) ? "RX/TX" : ((ctrl
&
2677 E1000_CTRL_RFCE
) ? "RX" : ((ctrl
&
2678 E1000_CTRL_TFCE
) ? "TX" : "None" )));
2680 /* tweak tx_queue_len according to speed/duplex
2681 * and adjust the timeout factor */
2682 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2683 adapter
->tx_timeout_factor
= 1;
2684 switch (adapter
->link_speed
) {
2687 netdev
->tx_queue_len
= 10;
2688 adapter
->tx_timeout_factor
= 8;
2692 netdev
->tx_queue_len
= 100;
2693 /* maybe add some timeout factor ? */
2697 if ((adapter
->hw
.mac_type
== e1000_82571
||
2698 adapter
->hw
.mac_type
== e1000_82572
) &&
2701 tarc0
= E1000_READ_REG(&adapter
->hw
, TARC0
);
2702 tarc0
&= ~(1 << 21);
2703 E1000_WRITE_REG(&adapter
->hw
, TARC0
, tarc0
);
2706 /* disable TSO for pcie and 10/100 speeds, to avoid
2707 * some hardware issues */
2708 if (!adapter
->tso_force
&&
2709 adapter
->hw
.bus_type
== e1000_bus_type_pci_express
){
2710 switch (adapter
->link_speed
) {
2714 "10/100 speed: disabling TSO\n");
2715 netdev
->features
&= ~NETIF_F_TSO
;
2716 netdev
->features
&= ~NETIF_F_TSO6
;
2719 netdev
->features
|= NETIF_F_TSO
;
2720 netdev
->features
|= NETIF_F_TSO6
;
2728 /* enable transmits in the hardware, need to do this
2729 * after setting TARC0 */
2730 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2731 tctl
|= E1000_TCTL_EN
;
2732 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2734 netif_carrier_on(netdev
);
2735 netif_wake_queue(netdev
);
2736 mod_timer(&adapter
->phy_info_timer
, round_jiffies(jiffies
+ 2 * HZ
));
2737 adapter
->smartspeed
= 0;
2739 /* make sure the receive unit is started */
2740 if (adapter
->hw
.rx_needs_kicking
) {
2741 struct e1000_hw
*hw
= &adapter
->hw
;
2742 uint32_t rctl
= E1000_READ_REG(hw
, RCTL
);
2743 E1000_WRITE_REG(hw
, RCTL
, rctl
| E1000_RCTL_EN
);
2747 if (netif_carrier_ok(netdev
)) {
2748 adapter
->link_speed
= 0;
2749 adapter
->link_duplex
= 0;
2750 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
2751 netif_carrier_off(netdev
);
2752 netif_stop_queue(netdev
);
2753 mod_timer(&adapter
->phy_info_timer
, round_jiffies(jiffies
+ 2 * HZ
));
2755 /* 80003ES2LAN workaround--
2756 * For packet buffer work-around on link down event;
2757 * disable receives in the ISR and
2758 * reset device here in the watchdog
2760 if (adapter
->hw
.mac_type
== e1000_80003es2lan
)
2762 schedule_work(&adapter
->reset_task
);
2765 e1000_smartspeed(adapter
);
2768 e1000_update_stats(adapter
);
2770 adapter
->hw
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2771 adapter
->tpt_old
= adapter
->stats
.tpt
;
2772 adapter
->hw
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2773 adapter
->colc_old
= adapter
->stats
.colc
;
2775 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2776 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2777 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2778 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2780 e1000_update_adaptive(&adapter
->hw
);
2782 if (!netif_carrier_ok(netdev
)) {
2783 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2784 /* We've lost link, so the controller stops DMA,
2785 * but we've got queued Tx work that's never going
2786 * to get done, so reset controller to flush Tx.
2787 * (Do the reset outside of interrupt context). */
2788 adapter
->tx_timeout_count
++;
2789 schedule_work(&adapter
->reset_task
);
2793 /* Cause software interrupt to ensure rx ring is cleaned */
2794 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_RXDMT0
);
2796 /* Force detection of hung controller every watchdog period */
2797 adapter
->detect_tx_hung
= TRUE
;
2799 /* With 82571 controllers, LAA may be overwritten due to controller
2800 * reset from the other port. Set the appropriate LAA in RAR[0] */
2801 if (adapter
->hw
.mac_type
== e1000_82571
&& adapter
->hw
.laa_is_present
)
2802 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2804 /* Reset the timer */
2805 mod_timer(&adapter
->watchdog_timer
, round_jiffies(jiffies
+ 2 * HZ
));
2808 enum latency_range
{
2812 latency_invalid
= 255
2816 * e1000_update_itr - update the dynamic ITR value based on statistics
2817 * Stores a new ITR value based on packets and byte
2818 * counts during the last interrupt. The advantage of per interrupt
2819 * computation is faster updates and more accurate ITR for the current
2820 * traffic pattern. Constants in this function were computed
2821 * based on theoretical maximum wire speed and thresholds were set based
2822 * on testing data as well as attempting to minimize response time
2823 * while increasing bulk throughput.
2824 * this functionality is controlled by the InterruptThrottleRate module
2825 * parameter (see e1000_param.c)
2826 * @adapter: pointer to adapter
2827 * @itr_setting: current adapter->itr
2828 * @packets: the number of packets during this measurement interval
2829 * @bytes: the number of bytes during this measurement interval
2831 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
2832 uint16_t itr_setting
,
2836 unsigned int retval
= itr_setting
;
2837 struct e1000_hw
*hw
= &adapter
->hw
;
2839 if (unlikely(hw
->mac_type
< e1000_82540
))
2840 goto update_itr_done
;
2843 goto update_itr_done
;
2845 switch (itr_setting
) {
2846 case lowest_latency
:
2847 /* jumbo frames get bulk treatment*/
2848 if (bytes
/packets
> 8000)
2849 retval
= bulk_latency
;
2850 else if ((packets
< 5) && (bytes
> 512))
2851 retval
= low_latency
;
2853 case low_latency
: /* 50 usec aka 20000 ints/s */
2854 if (bytes
> 10000) {
2855 /* jumbo frames need bulk latency setting */
2856 if (bytes
/packets
> 8000)
2857 retval
= bulk_latency
;
2858 else if ((packets
< 10) || ((bytes
/packets
) > 1200))
2859 retval
= bulk_latency
;
2860 else if ((packets
> 35))
2861 retval
= lowest_latency
;
2862 } else if (bytes
/packets
> 2000)
2863 retval
= bulk_latency
;
2864 else if (packets
<= 2 && bytes
< 512)
2865 retval
= lowest_latency
;
2867 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2868 if (bytes
> 25000) {
2870 retval
= low_latency
;
2871 } else if (bytes
< 6000) {
2872 retval
= low_latency
;
2881 static void e1000_set_itr(struct e1000_adapter
*adapter
)
2883 struct e1000_hw
*hw
= &adapter
->hw
;
2884 uint16_t current_itr
;
2885 uint32_t new_itr
= adapter
->itr
;
2887 if (unlikely(hw
->mac_type
< e1000_82540
))
2890 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2891 if (unlikely(adapter
->link_speed
!= SPEED_1000
)) {
2897 adapter
->tx_itr
= e1000_update_itr(adapter
,
2899 adapter
->total_tx_packets
,
2900 adapter
->total_tx_bytes
);
2901 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2902 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
2903 adapter
->tx_itr
= low_latency
;
2905 adapter
->rx_itr
= e1000_update_itr(adapter
,
2907 adapter
->total_rx_packets
,
2908 adapter
->total_rx_bytes
);
2909 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2910 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
2911 adapter
->rx_itr
= low_latency
;
2913 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2915 switch (current_itr
) {
2916 /* counts and packets in update_itr are dependent on these numbers */
2917 case lowest_latency
:
2921 new_itr
= 20000; /* aka hwitr = ~200 */
2931 if (new_itr
!= adapter
->itr
) {
2932 /* this attempts to bias the interrupt rate towards Bulk
2933 * by adding intermediate steps when interrupt rate is
2935 new_itr
= new_itr
> adapter
->itr
?
2936 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2938 adapter
->itr
= new_itr
;
2939 E1000_WRITE_REG(hw
, ITR
, 1000000000 / (new_itr
* 256));
2945 #define E1000_TX_FLAGS_CSUM 0x00000001
2946 #define E1000_TX_FLAGS_VLAN 0x00000002
2947 #define E1000_TX_FLAGS_TSO 0x00000004
2948 #define E1000_TX_FLAGS_IPV4 0x00000008
2949 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2950 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2953 e1000_tso(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2954 struct sk_buff
*skb
)
2956 struct e1000_context_desc
*context_desc
;
2957 struct e1000_buffer
*buffer_info
;
2959 uint32_t cmd_length
= 0;
2960 uint16_t ipcse
= 0, tucse
, mss
;
2961 uint8_t ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2964 if (skb_is_gso(skb
)) {
2965 if (skb_header_cloned(skb
)) {
2966 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2971 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2972 mss
= skb_shinfo(skb
)->gso_size
;
2973 if (skb
->protocol
== htons(ETH_P_IP
)) {
2974 struct iphdr
*iph
= ip_hdr(skb
);
2977 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2981 cmd_length
= E1000_TXD_CMD_IP
;
2982 ipcse
= skb_transport_offset(skb
) - 1;
2983 } else if (skb
->protocol
== htons(ETH_P_IPV6
)) {
2984 ipv6_hdr(skb
)->payload_len
= 0;
2985 tcp_hdr(skb
)->check
=
2986 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2987 &ipv6_hdr(skb
)->daddr
,
2991 ipcss
= skb_network_offset(skb
);
2992 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
2993 tucss
= skb_transport_offset(skb
);
2994 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
2997 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2998 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
3000 i
= tx_ring
->next_to_use
;
3001 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
3002 buffer_info
= &tx_ring
->buffer_info
[i
];
3004 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
3005 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
3006 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
3007 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
3008 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
3009 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
3010 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
3011 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
3012 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
3014 buffer_info
->time_stamp
= jiffies
;
3015 buffer_info
->next_to_watch
= i
;
3017 if (++i
== tx_ring
->count
) i
= 0;
3018 tx_ring
->next_to_use
= i
;
3026 e1000_tx_csum(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
3027 struct sk_buff
*skb
)
3029 struct e1000_context_desc
*context_desc
;
3030 struct e1000_buffer
*buffer_info
;
3034 if (likely(skb
->ip_summed
== CHECKSUM_PARTIAL
)) {
3035 css
= skb_transport_offset(skb
);
3037 i
= tx_ring
->next_to_use
;
3038 buffer_info
= &tx_ring
->buffer_info
[i
];
3039 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
3041 context_desc
->lower_setup
.ip_config
= 0;
3042 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
3043 context_desc
->upper_setup
.tcp_fields
.tucso
=
3044 css
+ skb
->csum_offset
;
3045 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
3046 context_desc
->tcp_seg_setup
.data
= 0;
3047 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
3049 buffer_info
->time_stamp
= jiffies
;
3050 buffer_info
->next_to_watch
= i
;
3052 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3053 tx_ring
->next_to_use
= i
;
3061 #define E1000_MAX_TXD_PWR 12
3062 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
3065 e1000_tx_map(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
3066 struct sk_buff
*skb
, unsigned int first
, unsigned int max_per_txd
,
3067 unsigned int nr_frags
, unsigned int mss
)
3069 struct e1000_buffer
*buffer_info
;
3070 unsigned int len
= skb
->len
;
3071 unsigned int offset
= 0, size
, count
= 0, i
;
3073 len
-= skb
->data_len
;
3075 i
= tx_ring
->next_to_use
;
3078 buffer_info
= &tx_ring
->buffer_info
[i
];
3079 size
= min(len
, max_per_txd
);
3080 /* Workaround for Controller erratum --
3081 * descriptor for non-tso packet in a linear SKB that follows a
3082 * tso gets written back prematurely before the data is fully
3083 * DMA'd to the controller */
3084 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
3086 tx_ring
->last_tx_tso
= 0;
3090 /* Workaround for premature desc write-backs
3091 * in TSO mode. Append 4-byte sentinel desc */
3092 if (unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
3094 /* work-around for errata 10 and it applies
3095 * to all controllers in PCI-X mode
3096 * The fix is to make sure that the first descriptor of a
3097 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3099 if (unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
3100 (size
> 2015) && count
== 0))
3103 /* Workaround for potential 82544 hang in PCI-X. Avoid
3104 * terminating buffers within evenly-aligned dwords. */
3105 if (unlikely(adapter
->pcix_82544
&&
3106 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
3110 buffer_info
->length
= size
;
3112 pci_map_single(adapter
->pdev
,
3116 buffer_info
->time_stamp
= jiffies
;
3117 buffer_info
->next_to_watch
= i
;
3122 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3125 for (f
= 0; f
< nr_frags
; f
++) {
3126 struct skb_frag_struct
*frag
;
3128 frag
= &skb_shinfo(skb
)->frags
[f
];
3130 offset
= frag
->page_offset
;
3133 buffer_info
= &tx_ring
->buffer_info
[i
];
3134 size
= min(len
, max_per_txd
);
3135 /* Workaround for premature desc write-backs
3136 * in TSO mode. Append 4-byte sentinel desc */
3137 if (unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
3139 /* Workaround for potential 82544 hang in PCI-X.
3140 * Avoid terminating buffers within evenly-aligned
3142 if (unlikely(adapter
->pcix_82544
&&
3143 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
3147 buffer_info
->length
= size
;
3149 pci_map_page(adapter
->pdev
,
3154 buffer_info
->time_stamp
= jiffies
;
3155 buffer_info
->next_to_watch
= i
;
3160 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3164 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
3165 tx_ring
->buffer_info
[i
].skb
= skb
;
3166 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
3172 e1000_tx_queue(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
3173 int tx_flags
, int count
)
3175 struct e1000_tx_desc
*tx_desc
= NULL
;
3176 struct e1000_buffer
*buffer_info
;
3177 uint32_t txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
3180 if (likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
3181 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
3183 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3185 if (likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
3186 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
3189 if (likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
3190 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
3191 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
3194 if (unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
3195 txd_lower
|= E1000_TXD_CMD_VLE
;
3196 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
3199 i
= tx_ring
->next_to_use
;
3202 buffer_info
= &tx_ring
->buffer_info
[i
];
3203 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3204 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3205 tx_desc
->lower
.data
=
3206 cpu_to_le32(txd_lower
| buffer_info
->length
);
3207 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
3208 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3211 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
3213 /* Force memory writes to complete before letting h/w
3214 * know there are new descriptors to fetch. (Only
3215 * applicable for weak-ordered memory model archs,
3216 * such as IA-64). */
3219 tx_ring
->next_to_use
= i
;
3220 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
3221 /* we need this if more than one processor can write to our tail
3222 * at a time, it syncronizes IO on IA64/Altix systems */
3227 * 82547 workaround to avoid controller hang in half-duplex environment.
3228 * The workaround is to avoid queuing a large packet that would span
3229 * the internal Tx FIFO ring boundary by notifying the stack to resend
3230 * the packet at a later time. This gives the Tx FIFO an opportunity to
3231 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3232 * to the beginning of the Tx FIFO.
3235 #define E1000_FIFO_HDR 0x10
3236 #define E1000_82547_PAD_LEN 0x3E0
3239 e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
3241 uint32_t fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
3242 uint32_t skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
3244 skb_fifo_len
= ALIGN(skb_fifo_len
, E1000_FIFO_HDR
);
3246 if (adapter
->link_duplex
!= HALF_DUPLEX
)
3247 goto no_fifo_stall_required
;
3249 if (atomic_read(&adapter
->tx_fifo_stall
))
3252 if (skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
3253 atomic_set(&adapter
->tx_fifo_stall
, 1);
3257 no_fifo_stall_required
:
3258 adapter
->tx_fifo_head
+= skb_fifo_len
;
3259 if (adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
3260 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
3264 #define MINIMUM_DHCP_PACKET_SIZE 282
3266 e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
3268 struct e1000_hw
*hw
= &adapter
->hw
;
3269 uint16_t length
, offset
;
3270 if (vlan_tx_tag_present(skb
)) {
3271 if (!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
3272 ( adapter
->hw
.mng_cookie
.status
&
3273 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) )
3276 if (skb
->len
> MINIMUM_DHCP_PACKET_SIZE
) {
3277 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
3278 if ((htons(ETH_P_IP
) == eth
->h_proto
)) {
3279 const struct iphdr
*ip
=
3280 (struct iphdr
*)((uint8_t *)skb
->data
+14);
3281 if (IPPROTO_UDP
== ip
->protocol
) {
3282 struct udphdr
*udp
=
3283 (struct udphdr
*)((uint8_t *)ip
+
3285 if (ntohs(udp
->dest
) == 67) {
3286 offset
= (uint8_t *)udp
+ 8 - skb
->data
;
3287 length
= skb
->len
- offset
;
3289 return e1000_mng_write_dhcp_info(hw
,
3299 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
3301 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3302 struct e1000_tx_ring
*tx_ring
= adapter
->tx_ring
;
3304 netif_stop_queue(netdev
);
3305 /* Herbert's original patch had:
3306 * smp_mb__after_netif_stop_queue();
3307 * but since that doesn't exist yet, just open code it. */
3310 /* We need to check again in a case another CPU has just
3311 * made room available. */
3312 if (likely(E1000_DESC_UNUSED(tx_ring
) < size
))
3316 netif_start_queue(netdev
);
3317 ++adapter
->restart_queue
;
3321 static int e1000_maybe_stop_tx(struct net_device
*netdev
,
3322 struct e1000_tx_ring
*tx_ring
, int size
)
3324 if (likely(E1000_DESC_UNUSED(tx_ring
) >= size
))
3326 return __e1000_maybe_stop_tx(netdev
, size
);
3329 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3331 e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
3333 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3334 struct e1000_tx_ring
*tx_ring
;
3335 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
3336 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
3337 unsigned int tx_flags
= 0;
3338 unsigned int len
= skb
->len
- skb
->data_len
;
3339 unsigned long flags
;
3340 unsigned int nr_frags
;
3346 /* This goes back to the question of how to logically map a tx queue
3347 * to a flow. Right now, performance is impacted slightly negatively
3348 * if using multiple tx queues. If the stack breaks away from a
3349 * single qdisc implementation, we can look at this again. */
3350 tx_ring
= adapter
->tx_ring
;
3352 if (unlikely(skb
->len
<= 0)) {
3353 dev_kfree_skb_any(skb
);
3354 return NETDEV_TX_OK
;
3357 /* 82571 and newer doesn't need the workaround that limited descriptor
3359 if (adapter
->hw
.mac_type
>= e1000_82571
)
3362 mss
= skb_shinfo(skb
)->gso_size
;
3363 /* The controller does a simple calculation to
3364 * make sure there is enough room in the FIFO before
3365 * initiating the DMA for each buffer. The calc is:
3366 * 4 = ceil(buffer len/mss). To make sure we don't
3367 * overrun the FIFO, adjust the max buffer len if mss
3371 max_per_txd
= min(mss
<< 2, max_per_txd
);
3372 max_txd_pwr
= fls(max_per_txd
) - 1;
3374 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3375 * points to just header, pull a few bytes of payload from
3376 * frags into skb->data */
3377 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
3378 if (skb
->data_len
&& hdr_len
== len
) {
3379 switch (adapter
->hw
.mac_type
) {
3380 unsigned int pull_size
;
3382 /* Make sure we have room to chop off 4 bytes,
3383 * and that the end alignment will work out to
3384 * this hardware's requirements
3385 * NOTE: this is a TSO only workaround
3386 * if end byte alignment not correct move us
3387 * into the next dword */
3388 if ((unsigned long)(skb_tail_pointer(skb
) - 1) & 4)
3395 pull_size
= min((unsigned int)4, skb
->data_len
);
3396 if (!__pskb_pull_tail(skb
, pull_size
)) {
3398 "__pskb_pull_tail failed.\n");
3399 dev_kfree_skb_any(skb
);
3400 return NETDEV_TX_OK
;
3402 len
= skb
->len
- skb
->data_len
;
3411 /* reserve a descriptor for the offload context */
3412 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3416 /* Controller Erratum workaround */
3417 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&& !skb_is_gso(skb
))
3420 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
3422 if (adapter
->pcix_82544
)
3425 /* work-around for errata 10 and it applies to all controllers
3426 * in PCI-X mode, so add one more descriptor to the count
3428 if (unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
3432 nr_frags
= skb_shinfo(skb
)->nr_frags
;
3433 for (f
= 0; f
< nr_frags
; f
++)
3434 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
3436 if (adapter
->pcix_82544
)
3440 if (adapter
->hw
.tx_pkt_filtering
&&
3441 (adapter
->hw
.mac_type
== e1000_82573
))
3442 e1000_transfer_dhcp_info(adapter
, skb
);
3444 if (!spin_trylock_irqsave(&tx_ring
->tx_lock
, flags
))
3445 /* Collision - tell upper layer to requeue */
3446 return NETDEV_TX_LOCKED
;
3448 /* need: count + 2 desc gap to keep tail from touching
3449 * head, otherwise try next time */
3450 if (unlikely(e1000_maybe_stop_tx(netdev
, tx_ring
, count
+ 2))) {
3451 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3452 return NETDEV_TX_BUSY
;
3455 if (unlikely(adapter
->hw
.mac_type
== e1000_82547
)) {
3456 if (unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
3457 netif_stop_queue(netdev
);
3458 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
3459 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3460 return NETDEV_TX_BUSY
;
3464 if (unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
3465 tx_flags
|= E1000_TX_FLAGS_VLAN
;
3466 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
3469 first
= tx_ring
->next_to_use
;
3471 tso
= e1000_tso(adapter
, tx_ring
, skb
);
3473 dev_kfree_skb_any(skb
);
3474 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3475 return NETDEV_TX_OK
;
3479 tx_ring
->last_tx_tso
= 1;
3480 tx_flags
|= E1000_TX_FLAGS_TSO
;
3481 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
3482 tx_flags
|= E1000_TX_FLAGS_CSUM
;
3484 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3485 * 82571 hardware supports TSO capabilities for IPv6 as well...
3486 * no longer assume, we must. */
3487 if (likely(skb
->protocol
== htons(ETH_P_IP
)))
3488 tx_flags
|= E1000_TX_FLAGS_IPV4
;
3490 e1000_tx_queue(adapter
, tx_ring
, tx_flags
,
3491 e1000_tx_map(adapter
, tx_ring
, skb
, first
,
3492 max_per_txd
, nr_frags
, mss
));
3494 netdev
->trans_start
= jiffies
;
3496 /* Make sure there is space in the ring for the next send. */
3497 e1000_maybe_stop_tx(netdev
, tx_ring
, MAX_SKB_FRAGS
+ 2);
3499 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3500 return NETDEV_TX_OK
;
3504 * e1000_tx_timeout - Respond to a Tx Hang
3505 * @netdev: network interface device structure
3509 e1000_tx_timeout(struct net_device
*netdev
)
3511 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3513 /* Do the reset outside of interrupt context */
3514 adapter
->tx_timeout_count
++;
3515 schedule_work(&adapter
->reset_task
);
3519 e1000_reset_task(struct work_struct
*work
)
3521 struct e1000_adapter
*adapter
=
3522 container_of(work
, struct e1000_adapter
, reset_task
);
3524 e1000_reinit_locked(adapter
);
3528 * e1000_get_stats - Get System Network Statistics
3529 * @netdev: network interface device structure
3531 * Returns the address of the device statistics structure.
3532 * The statistics are actually updated from the timer callback.
3535 static struct net_device_stats
*
3536 e1000_get_stats(struct net_device
*netdev
)
3538 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3540 /* only return the current stats */
3541 return &adapter
->net_stats
;
3545 * e1000_change_mtu - Change the Maximum Transfer Unit
3546 * @netdev: network interface device structure
3547 * @new_mtu: new value for maximum frame size
3549 * Returns 0 on success, negative on failure
3553 e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3555 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3556 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
3557 uint16_t eeprom_data
= 0;
3559 if ((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
3560 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3561 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
3565 /* Adapter-specific max frame size limits. */
3566 switch (adapter
->hw
.mac_type
) {
3567 case e1000_undefined
... e1000_82542_rev2_1
:
3569 if (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3570 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported.\n");
3575 /* Jumbo Frames not supported if:
3576 * - this is not an 82573L device
3577 * - ASPM is enabled in any way (0x1A bits 3:2) */
3578 e1000_read_eeprom(&adapter
->hw
, EEPROM_INIT_3GIO_3
, 1,
3580 if ((adapter
->hw
.device_id
!= E1000_DEV_ID_82573L
) ||
3581 (eeprom_data
& EEPROM_WORD1A_ASPM_MASK
)) {
3582 if (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3584 "Jumbo Frames not supported.\n");
3589 /* ERT will be enabled later to enable wire speed receives */
3591 /* fall through to get support */
3594 case e1000_80003es2lan
:
3595 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3596 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3597 DPRINTK(PROBE
, ERR
, "MTU > 9216 not supported.\n");
3602 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3606 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3607 * means we reserve 2 more, this pushes us to allocate from the next
3609 * i.e. RXBUFFER_2048 --> size-4096 slab */
3611 if (max_frame
<= E1000_RXBUFFER_256
)
3612 adapter
->rx_buffer_len
= E1000_RXBUFFER_256
;
3613 else if (max_frame
<= E1000_RXBUFFER_512
)
3614 adapter
->rx_buffer_len
= E1000_RXBUFFER_512
;
3615 else if (max_frame
<= E1000_RXBUFFER_1024
)
3616 adapter
->rx_buffer_len
= E1000_RXBUFFER_1024
;
3617 else if (max_frame
<= E1000_RXBUFFER_2048
)
3618 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3619 else if (max_frame
<= E1000_RXBUFFER_4096
)
3620 adapter
->rx_buffer_len
= E1000_RXBUFFER_4096
;
3621 else if (max_frame
<= E1000_RXBUFFER_8192
)
3622 adapter
->rx_buffer_len
= E1000_RXBUFFER_8192
;
3623 else if (max_frame
<= E1000_RXBUFFER_16384
)
3624 adapter
->rx_buffer_len
= E1000_RXBUFFER_16384
;
3626 /* adjust allocation if LPE protects us, and we aren't using SBP */
3627 if (!adapter
->hw
.tbi_compatibility_on
&&
3628 ((max_frame
== MAXIMUM_ETHERNET_FRAME_SIZE
) ||
3629 (max_frame
== MAXIMUM_ETHERNET_VLAN_SIZE
)))
3630 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3632 netdev
->mtu
= new_mtu
;
3633 adapter
->hw
.max_frame_size
= max_frame
;
3635 if (netif_running(netdev
))
3636 e1000_reinit_locked(adapter
);
3642 * e1000_update_stats - Update the board statistics counters
3643 * @adapter: board private structure
3647 e1000_update_stats(struct e1000_adapter
*adapter
)
3649 struct e1000_hw
*hw
= &adapter
->hw
;
3650 struct pci_dev
*pdev
= adapter
->pdev
;
3651 unsigned long flags
;
3654 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3657 * Prevent stats update while adapter is being reset, or if the pci
3658 * connection is down.
3660 if (adapter
->link_speed
== 0)
3662 if (pci_channel_offline(pdev
))
3665 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3667 /* these counters are modified from e1000_tbi_adjust_stats,
3668 * called from the interrupt context, so they must only
3669 * be written while holding adapter->stats_lock
3672 adapter
->stats
.crcerrs
+= E1000_READ_REG(hw
, CRCERRS
);
3673 adapter
->stats
.gprc
+= E1000_READ_REG(hw
, GPRC
);
3674 adapter
->stats
.gorcl
+= E1000_READ_REG(hw
, GORCL
);
3675 adapter
->stats
.gorch
+= E1000_READ_REG(hw
, GORCH
);
3676 adapter
->stats
.bprc
+= E1000_READ_REG(hw
, BPRC
);
3677 adapter
->stats
.mprc
+= E1000_READ_REG(hw
, MPRC
);
3678 adapter
->stats
.roc
+= E1000_READ_REG(hw
, ROC
);
3680 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
3681 adapter
->stats
.prc64
+= E1000_READ_REG(hw
, PRC64
);
3682 adapter
->stats
.prc127
+= E1000_READ_REG(hw
, PRC127
);
3683 adapter
->stats
.prc255
+= E1000_READ_REG(hw
, PRC255
);
3684 adapter
->stats
.prc511
+= E1000_READ_REG(hw
, PRC511
);
3685 adapter
->stats
.prc1023
+= E1000_READ_REG(hw
, PRC1023
);
3686 adapter
->stats
.prc1522
+= E1000_READ_REG(hw
, PRC1522
);
3689 adapter
->stats
.symerrs
+= E1000_READ_REG(hw
, SYMERRS
);
3690 adapter
->stats
.mpc
+= E1000_READ_REG(hw
, MPC
);
3691 adapter
->stats
.scc
+= E1000_READ_REG(hw
, SCC
);
3692 adapter
->stats
.ecol
+= E1000_READ_REG(hw
, ECOL
);
3693 adapter
->stats
.mcc
+= E1000_READ_REG(hw
, MCC
);
3694 adapter
->stats
.latecol
+= E1000_READ_REG(hw
, LATECOL
);
3695 adapter
->stats
.dc
+= E1000_READ_REG(hw
, DC
);
3696 adapter
->stats
.sec
+= E1000_READ_REG(hw
, SEC
);
3697 adapter
->stats
.rlec
+= E1000_READ_REG(hw
, RLEC
);
3698 adapter
->stats
.xonrxc
+= E1000_READ_REG(hw
, XONRXC
);
3699 adapter
->stats
.xontxc
+= E1000_READ_REG(hw
, XONTXC
);
3700 adapter
->stats
.xoffrxc
+= E1000_READ_REG(hw
, XOFFRXC
);
3701 adapter
->stats
.xofftxc
+= E1000_READ_REG(hw
, XOFFTXC
);
3702 adapter
->stats
.fcruc
+= E1000_READ_REG(hw
, FCRUC
);
3703 adapter
->stats
.gptc
+= E1000_READ_REG(hw
, GPTC
);
3704 adapter
->stats
.gotcl
+= E1000_READ_REG(hw
, GOTCL
);
3705 adapter
->stats
.gotch
+= E1000_READ_REG(hw
, GOTCH
);
3706 adapter
->stats
.rnbc
+= E1000_READ_REG(hw
, RNBC
);
3707 adapter
->stats
.ruc
+= E1000_READ_REG(hw
, RUC
);
3708 adapter
->stats
.rfc
+= E1000_READ_REG(hw
, RFC
);
3709 adapter
->stats
.rjc
+= E1000_READ_REG(hw
, RJC
);
3710 adapter
->stats
.torl
+= E1000_READ_REG(hw
, TORL
);
3711 adapter
->stats
.torh
+= E1000_READ_REG(hw
, TORH
);
3712 adapter
->stats
.totl
+= E1000_READ_REG(hw
, TOTL
);
3713 adapter
->stats
.toth
+= E1000_READ_REG(hw
, TOTH
);
3714 adapter
->stats
.tpr
+= E1000_READ_REG(hw
, TPR
);
3716 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
3717 adapter
->stats
.ptc64
+= E1000_READ_REG(hw
, PTC64
);
3718 adapter
->stats
.ptc127
+= E1000_READ_REG(hw
, PTC127
);
3719 adapter
->stats
.ptc255
+= E1000_READ_REG(hw
, PTC255
);
3720 adapter
->stats
.ptc511
+= E1000_READ_REG(hw
, PTC511
);
3721 adapter
->stats
.ptc1023
+= E1000_READ_REG(hw
, PTC1023
);
3722 adapter
->stats
.ptc1522
+= E1000_READ_REG(hw
, PTC1522
);
3725 adapter
->stats
.mptc
+= E1000_READ_REG(hw
, MPTC
);
3726 adapter
->stats
.bptc
+= E1000_READ_REG(hw
, BPTC
);
3728 /* used for adaptive IFS */
3730 hw
->tx_packet_delta
= E1000_READ_REG(hw
, TPT
);
3731 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3732 hw
->collision_delta
= E1000_READ_REG(hw
, COLC
);
3733 adapter
->stats
.colc
+= hw
->collision_delta
;
3735 if (hw
->mac_type
>= e1000_82543
) {
3736 adapter
->stats
.algnerrc
+= E1000_READ_REG(hw
, ALGNERRC
);
3737 adapter
->stats
.rxerrc
+= E1000_READ_REG(hw
, RXERRC
);
3738 adapter
->stats
.tncrs
+= E1000_READ_REG(hw
, TNCRS
);
3739 adapter
->stats
.cexterr
+= E1000_READ_REG(hw
, CEXTERR
);
3740 adapter
->stats
.tsctc
+= E1000_READ_REG(hw
, TSCTC
);
3741 adapter
->stats
.tsctfc
+= E1000_READ_REG(hw
, TSCTFC
);
3743 if (hw
->mac_type
> e1000_82547_rev_2
) {
3744 adapter
->stats
.iac
+= E1000_READ_REG(hw
, IAC
);
3745 adapter
->stats
.icrxoc
+= E1000_READ_REG(hw
, ICRXOC
);
3747 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
3748 adapter
->stats
.icrxptc
+= E1000_READ_REG(hw
, ICRXPTC
);
3749 adapter
->stats
.icrxatc
+= E1000_READ_REG(hw
, ICRXATC
);
3750 adapter
->stats
.ictxptc
+= E1000_READ_REG(hw
, ICTXPTC
);
3751 adapter
->stats
.ictxatc
+= E1000_READ_REG(hw
, ICTXATC
);
3752 adapter
->stats
.ictxqec
+= E1000_READ_REG(hw
, ICTXQEC
);
3753 adapter
->stats
.ictxqmtc
+= E1000_READ_REG(hw
, ICTXQMTC
);
3754 adapter
->stats
.icrxdmtc
+= E1000_READ_REG(hw
, ICRXDMTC
);
3758 /* Fill out the OS statistics structure */
3759 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3760 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3764 /* RLEC on some newer hardware can be incorrect so build
3765 * our own version based on RUC and ROC */
3766 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3767 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3768 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3769 adapter
->stats
.cexterr
;
3770 adapter
->stats
.rlerrc
= adapter
->stats
.ruc
+ adapter
->stats
.roc
;
3771 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlerrc
;
3772 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3773 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3774 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3777 adapter
->stats
.txerrc
= adapter
->stats
.ecol
+ adapter
->stats
.latecol
;
3778 adapter
->net_stats
.tx_errors
= adapter
->stats
.txerrc
;
3779 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3780 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3781 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3782 if (adapter
->hw
.bad_tx_carr_stats_fd
&&
3783 adapter
->link_duplex
== FULL_DUPLEX
) {
3784 adapter
->net_stats
.tx_carrier_errors
= 0;
3785 adapter
->stats
.tncrs
= 0;
3788 /* Tx Dropped needs to be maintained elsewhere */
3791 if (hw
->media_type
== e1000_media_type_copper
) {
3792 if ((adapter
->link_speed
== SPEED_1000
) &&
3793 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3794 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3795 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3798 if ((hw
->mac_type
<= e1000_82546
) &&
3799 (hw
->phy_type
== e1000_phy_m88
) &&
3800 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3801 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3804 /* Management Stats */
3805 if (adapter
->hw
.has_smbus
) {
3806 adapter
->stats
.mgptc
+= E1000_READ_REG(hw
, MGTPTC
);
3807 adapter
->stats
.mgprc
+= E1000_READ_REG(hw
, MGTPRC
);
3808 adapter
->stats
.mgpdc
+= E1000_READ_REG(hw
, MGTPDC
);
3811 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3815 * e1000_intr_msi - Interrupt Handler
3816 * @irq: interrupt number
3817 * @data: pointer to a network interface device structure
3821 e1000_intr_msi(int irq
, void *data
)
3823 struct net_device
*netdev
= data
;
3824 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3825 struct e1000_hw
*hw
= &adapter
->hw
;
3826 #ifndef CONFIG_E1000_NAPI
3829 uint32_t icr
= E1000_READ_REG(hw
, ICR
);
3831 #ifdef CONFIG_E1000_NAPI
3832 /* read ICR disables interrupts using IAM, so keep up with our
3833 * enable/disable accounting */
3834 atomic_inc(&adapter
->irq_sem
);
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 uint32_t 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 uint32_t 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,
3906 * interrupts are masked. No need for the
3907 * IMC write, but it does mean we should
3908 * account for it ASAP. */
3909 if (likely(hw
->mac_type
>= e1000_82571
))
3910 atomic_inc(&adapter
->irq_sem
);
3913 if (unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3914 hw
->get_link_status
= 1;
3915 /* 80003ES2LAN workaround--
3916 * For packet buffer work-around on link down event;
3917 * disable receives here in the ISR and
3918 * reset adapter in watchdog
3920 if (netif_carrier_ok(netdev
) &&
3921 (adapter
->hw
.mac_type
== e1000_80003es2lan
)) {
3922 /* disable receives */
3923 rctl
= E1000_READ_REG(hw
, RCTL
);
3924 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
3926 /* guard against interrupt when we're going down */
3927 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3928 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3931 #ifdef CONFIG_E1000_NAPI
3932 if (unlikely(hw
->mac_type
< e1000_82571
)) {
3933 /* disable interrupts, without the synchronize_irq bit */
3934 atomic_inc(&adapter
->irq_sem
);
3935 E1000_WRITE_REG(hw
, IMC
, ~0);
3936 E1000_WRITE_FLUSH(hw
);
3938 if (likely(netif_rx_schedule_prep(netdev
, &adapter
->napi
))) {
3939 adapter
->total_tx_bytes
= 0;
3940 adapter
->total_tx_packets
= 0;
3941 adapter
->total_rx_bytes
= 0;
3942 adapter
->total_rx_packets
= 0;
3943 __netif_rx_schedule(netdev
, &adapter
->napi
);
3945 /* this really should not happen! if it does it is basically a
3946 * bug, but not a hard error, so enable ints and continue */
3947 e1000_irq_enable(adapter
);
3949 /* Writing IMC and IMS is needed for 82547.
3950 * Due to Hub Link bus being occupied, an interrupt
3951 * de-assertion message is not able to be sent.
3952 * When an interrupt assertion message is generated later,
3953 * two messages are re-ordered and sent out.
3954 * That causes APIC to think 82547 is in de-assertion
3955 * state, while 82547 is in assertion state, resulting
3956 * in dead lock. Writing IMC forces 82547 into
3957 * de-assertion state.
3959 if (hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
) {
3960 atomic_inc(&adapter
->irq_sem
);
3961 E1000_WRITE_REG(hw
, IMC
, ~0);
3964 adapter
->total_tx_bytes
= 0;
3965 adapter
->total_rx_bytes
= 0;
3966 adapter
->total_tx_packets
= 0;
3967 adapter
->total_rx_packets
= 0;
3969 for (i
= 0; i
< E1000_MAX_INTR
; i
++)
3970 if (unlikely(!adapter
->clean_rx(adapter
, adapter
->rx_ring
) &
3971 !e1000_clean_tx_irq(adapter
, adapter
->tx_ring
)))
3974 if (likely(adapter
->itr_setting
& 3))
3975 e1000_set_itr(adapter
);
3977 if (hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
3978 e1000_irq_enable(adapter
);
3984 #ifdef CONFIG_E1000_NAPI
3986 * e1000_clean - NAPI Rx polling callback
3987 * @adapter: board private structure
3991 e1000_clean(struct napi_struct
*napi
, int budget
)
3993 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
, napi
);
3994 struct net_device
*poll_dev
= adapter
->netdev
;
3995 int tx_cleaned
= 0, work_done
= 0;
3997 /* Must NOT use netdev_priv macro here. */
3998 adapter
= poll_dev
->priv
;
4000 /* e1000_clean is called per-cpu. This lock protects
4001 * tx_ring[0] from being cleaned by multiple cpus
4002 * simultaneously. A failure obtaining the lock means
4003 * tx_ring[0] is currently being cleaned anyway. */
4004 if (spin_trylock(&adapter
->tx_queue_lock
)) {
4005 tx_cleaned
= e1000_clean_tx_irq(adapter
,
4006 &adapter
->tx_ring
[0]);
4007 spin_unlock(&adapter
->tx_queue_lock
);
4010 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[0],
4011 &work_done
, budget
);
4016 /* If budget not fully consumed, exit the polling mode */
4017 if (work_done
< budget
) {
4018 if (likely(adapter
->itr_setting
& 3))
4019 e1000_set_itr(adapter
);
4020 netif_rx_complete(poll_dev
, napi
);
4021 e1000_irq_enable(adapter
);
4029 * e1000_clean_tx_irq - Reclaim resources after transmit completes
4030 * @adapter: board private structure
4034 e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
4035 struct e1000_tx_ring
*tx_ring
)
4037 struct net_device
*netdev
= adapter
->netdev
;
4038 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
4039 struct e1000_buffer
*buffer_info
;
4040 unsigned int i
, eop
;
4041 #ifdef CONFIG_E1000_NAPI
4042 unsigned int count
= 0;
4044 boolean_t cleaned
= FALSE
;
4045 unsigned int total_tx_bytes
=0, total_tx_packets
=0;
4047 i
= tx_ring
->next_to_clean
;
4048 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
4049 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
4051 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
4052 for (cleaned
= FALSE
; !cleaned
; ) {
4053 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
4054 buffer_info
= &tx_ring
->buffer_info
[i
];
4055 cleaned
= (i
== eop
);
4058 struct sk_buff
*skb
= buffer_info
->skb
;
4059 unsigned int segs
, bytecount
;
4060 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
4061 /* multiply data chunks by size of headers */
4062 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
4064 total_tx_packets
+= segs
;
4065 total_tx_bytes
+= bytecount
;
4067 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
4068 tx_desc
->upper
.data
= 0;
4070 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
4073 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
4074 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
4075 #ifdef CONFIG_E1000_NAPI
4076 #define E1000_TX_WEIGHT 64
4077 /* weight of a sort for tx, to avoid endless transmit cleanup */
4078 if (count
++ == E1000_TX_WEIGHT
) break;
4082 tx_ring
->next_to_clean
= i
;
4084 #define TX_WAKE_THRESHOLD 32
4085 if (unlikely(cleaned
&& netif_carrier_ok(netdev
) &&
4086 E1000_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
)) {
4087 /* Make sure that anybody stopping the queue after this
4088 * sees the new next_to_clean.
4091 if (netif_queue_stopped(netdev
)) {
4092 netif_wake_queue(netdev
);
4093 ++adapter
->restart_queue
;
4097 if (adapter
->detect_tx_hung
) {
4098 /* Detect a transmit hang in hardware, this serializes the
4099 * check with the clearing of time_stamp and movement of i */
4100 adapter
->detect_tx_hung
= FALSE
;
4101 if (tx_ring
->buffer_info
[eop
].dma
&&
4102 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
+
4103 (adapter
->tx_timeout_factor
* HZ
))
4104 && !(E1000_READ_REG(&adapter
->hw
, STATUS
) &
4105 E1000_STATUS_TXOFF
)) {
4107 /* detected Tx unit hang */
4108 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
4112 " next_to_use <%x>\n"
4113 " next_to_clean <%x>\n"
4114 "buffer_info[next_to_clean]\n"
4115 " time_stamp <%lx>\n"
4116 " next_to_watch <%x>\n"
4118 " next_to_watch.status <%x>\n",
4119 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
4120 sizeof(struct e1000_tx_ring
)),
4121 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdh
),
4122 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdt
),
4123 tx_ring
->next_to_use
,
4124 tx_ring
->next_to_clean
,
4125 tx_ring
->buffer_info
[eop
].time_stamp
,
4128 eop_desc
->upper
.fields
.status
);
4129 netif_stop_queue(netdev
);
4132 adapter
->total_tx_bytes
+= total_tx_bytes
;
4133 adapter
->total_tx_packets
+= total_tx_packets
;
4134 adapter
->net_stats
.tx_bytes
+= total_tx_bytes
;
4135 adapter
->net_stats
.tx_packets
+= total_tx_packets
;
4140 * e1000_rx_checksum - Receive Checksum Offload for 82543
4141 * @adapter: board private structure
4142 * @status_err: receive descriptor status and error fields
4143 * @csum: receive descriptor csum field
4144 * @sk_buff: socket buffer with received data
4148 e1000_rx_checksum(struct e1000_adapter
*adapter
,
4149 uint32_t status_err
, uint32_t csum
,
4150 struct sk_buff
*skb
)
4152 uint16_t status
= (uint16_t)status_err
;
4153 uint8_t errors
= (uint8_t)(status_err
>> 24);
4154 skb
->ip_summed
= CHECKSUM_NONE
;
4156 /* 82543 or newer only */
4157 if (unlikely(adapter
->hw
.mac_type
< e1000_82543
)) return;
4158 /* Ignore Checksum bit is set */
4159 if (unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
4160 /* TCP/UDP checksum error bit is set */
4161 if (unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
4162 /* let the stack verify checksum errors */
4163 adapter
->hw_csum_err
++;
4166 /* TCP/UDP Checksum has not been calculated */
4167 if (adapter
->hw
.mac_type
<= e1000_82547_rev_2
) {
4168 if (!(status
& E1000_RXD_STAT_TCPCS
))
4171 if (!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
4174 /* It must be a TCP or UDP packet with a valid checksum */
4175 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
4176 /* TCP checksum is good */
4177 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
4178 } else if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
4179 /* IP fragment with UDP payload */
4180 /* Hardware complements the payload checksum, so we undo it
4181 * and then put the value in host order for further stack use.
4183 __sum16 sum
= (__force __sum16
)htons(csum
);
4184 skb
->csum
= csum_unfold(~sum
);
4185 skb
->ip_summed
= CHECKSUM_COMPLETE
;
4187 adapter
->hw_csum_good
++;
4191 * e1000_clean_rx_irq - Send received data up the network stack; legacy
4192 * @adapter: board private structure
4196 #ifdef CONFIG_E1000_NAPI
4197 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
4198 struct e1000_rx_ring
*rx_ring
,
4199 int *work_done
, int work_to_do
)
4201 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
4202 struct e1000_rx_ring
*rx_ring
)
4205 struct net_device
*netdev
= adapter
->netdev
;
4206 struct pci_dev
*pdev
= adapter
->pdev
;
4207 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
4208 struct e1000_buffer
*buffer_info
, *next_buffer
;
4209 unsigned long flags
;
4213 int cleaned_count
= 0;
4214 boolean_t cleaned
= FALSE
;
4215 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
4217 i
= rx_ring
->next_to_clean
;
4218 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4219 buffer_info
= &rx_ring
->buffer_info
[i
];
4221 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
4222 struct sk_buff
*skb
;
4225 #ifdef CONFIG_E1000_NAPI
4226 if (*work_done
>= work_to_do
)
4230 status
= rx_desc
->status
;
4231 skb
= buffer_info
->skb
;
4232 buffer_info
->skb
= NULL
;
4234 prefetch(skb
->data
- NET_IP_ALIGN
);
4236 if (++i
== rx_ring
->count
) i
= 0;
4237 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
4240 next_buffer
= &rx_ring
->buffer_info
[i
];
4244 pci_unmap_single(pdev
,
4246 buffer_info
->length
,
4247 PCI_DMA_FROMDEVICE
);
4249 length
= le16_to_cpu(rx_desc
->length
);
4251 if (unlikely(!(status
& E1000_RXD_STAT_EOP
))) {
4252 /* All receives must fit into a single buffer */
4253 E1000_DBG("%s: Receive packet consumed multiple"
4254 " buffers\n", netdev
->name
);
4256 buffer_info
->skb
= skb
;
4260 if (unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
4261 last_byte
= *(skb
->data
+ length
- 1);
4262 if (TBI_ACCEPT(&adapter
->hw
, status
,
4263 rx_desc
->errors
, length
, last_byte
)) {
4264 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4265 e1000_tbi_adjust_stats(&adapter
->hw
,
4268 spin_unlock_irqrestore(&adapter
->stats_lock
,
4273 buffer_info
->skb
= skb
;
4278 /* adjust length to remove Ethernet CRC, this must be
4279 * done after the TBI_ACCEPT workaround above */
4282 /* probably a little skewed due to removing CRC */
4283 total_rx_bytes
+= length
;
4286 /* code added for copybreak, this should improve
4287 * performance for small packets with large amounts
4288 * of reassembly being done in the stack */
4289 if (length
< copybreak
) {
4290 struct sk_buff
*new_skb
=
4291 netdev_alloc_skb(netdev
, length
+ NET_IP_ALIGN
);
4293 skb_reserve(new_skb
, NET_IP_ALIGN
);
4294 skb_copy_to_linear_data_offset(new_skb
,
4300 /* save the skb in buffer_info as good */
4301 buffer_info
->skb
= skb
;
4304 /* else just continue with the old one */
4306 /* end copybreak code */
4307 skb_put(skb
, length
);
4309 /* Receive Checksum Offload */
4310 e1000_rx_checksum(adapter
,
4311 (uint32_t)(status
) |
4312 ((uint32_t)(rx_desc
->errors
) << 24),
4313 le16_to_cpu(rx_desc
->csum
), skb
);
4315 skb
->protocol
= eth_type_trans(skb
, netdev
);
4316 #ifdef CONFIG_E1000_NAPI
4317 if (unlikely(adapter
->vlgrp
&&
4318 (status
& E1000_RXD_STAT_VP
))) {
4319 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
4320 le16_to_cpu(rx_desc
->special
) &
4321 E1000_RXD_SPC_VLAN_MASK
);
4323 netif_receive_skb(skb
);
4325 #else /* CONFIG_E1000_NAPI */
4326 if (unlikely(adapter
->vlgrp
&&
4327 (status
& E1000_RXD_STAT_VP
))) {
4328 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
4329 le16_to_cpu(rx_desc
->special
) &
4330 E1000_RXD_SPC_VLAN_MASK
);
4334 #endif /* CONFIG_E1000_NAPI */
4335 netdev
->last_rx
= jiffies
;
4338 rx_desc
->status
= 0;
4340 /* return some buffers to hardware, one at a time is too slow */
4341 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
4342 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4346 /* use prefetched values */
4348 buffer_info
= next_buffer
;
4350 rx_ring
->next_to_clean
= i
;
4352 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
4354 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4356 adapter
->total_rx_packets
+= total_rx_packets
;
4357 adapter
->total_rx_bytes
+= total_rx_bytes
;
4358 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
4359 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
4364 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4365 * @adapter: board private structure
4369 #ifdef CONFIG_E1000_NAPI
4370 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
4371 struct e1000_rx_ring
*rx_ring
,
4372 int *work_done
, int work_to_do
)
4374 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
4375 struct e1000_rx_ring
*rx_ring
)
4378 union e1000_rx_desc_packet_split
*rx_desc
, *next_rxd
;
4379 struct net_device
*netdev
= adapter
->netdev
;
4380 struct pci_dev
*pdev
= adapter
->pdev
;
4381 struct e1000_buffer
*buffer_info
, *next_buffer
;
4382 struct e1000_ps_page
*ps_page
;
4383 struct e1000_ps_page_dma
*ps_page_dma
;
4384 struct sk_buff
*skb
;
4386 uint32_t length
, staterr
;
4387 int cleaned_count
= 0;
4388 boolean_t cleaned
= FALSE
;
4389 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
4391 i
= rx_ring
->next_to_clean
;
4392 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
4393 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
4394 buffer_info
= &rx_ring
->buffer_info
[i
];
4396 while (staterr
& E1000_RXD_STAT_DD
) {
4397 ps_page
= &rx_ring
->ps_page
[i
];
4398 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
4399 #ifdef CONFIG_E1000_NAPI
4400 if (unlikely(*work_done
>= work_to_do
))
4404 skb
= buffer_info
->skb
;
4406 /* in the packet split case this is header only */
4407 prefetch(skb
->data
- NET_IP_ALIGN
);
4409 if (++i
== rx_ring
->count
) i
= 0;
4410 next_rxd
= E1000_RX_DESC_PS(*rx_ring
, i
);
4413 next_buffer
= &rx_ring
->buffer_info
[i
];
4417 pci_unmap_single(pdev
, buffer_info
->dma
,
4418 buffer_info
->length
,
4419 PCI_DMA_FROMDEVICE
);
4421 if (unlikely(!(staterr
& E1000_RXD_STAT_EOP
))) {
4422 E1000_DBG("%s: Packet Split buffers didn't pick up"
4423 " the full packet\n", netdev
->name
);
4424 dev_kfree_skb_irq(skb
);
4428 if (unlikely(staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
)) {
4429 dev_kfree_skb_irq(skb
);
4433 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
4435 if (unlikely(!length
)) {
4436 E1000_DBG("%s: Last part of the packet spanning"
4437 " multiple descriptors\n", netdev
->name
);
4438 dev_kfree_skb_irq(skb
);
4443 skb_put(skb
, length
);
4446 /* this looks ugly, but it seems compiler issues make it
4447 more efficient than reusing j */
4448 int l1
= le16_to_cpu(rx_desc
->wb
.upper
.length
[0]);
4450 /* page alloc/put takes too long and effects small packet
4451 * throughput, so unsplit small packets and save the alloc/put*/
4452 if (l1
&& (l1
<= copybreak
) && ((length
+ l1
) <= adapter
->rx_ps_bsize0
)) {
4454 /* there is no documentation about how to call
4455 * kmap_atomic, so we can't hold the mapping
4457 pci_dma_sync_single_for_cpu(pdev
,
4458 ps_page_dma
->ps_page_dma
[0],
4460 PCI_DMA_FROMDEVICE
);
4461 vaddr
= kmap_atomic(ps_page
->ps_page
[0],
4462 KM_SKB_DATA_SOFTIRQ
);
4463 memcpy(skb_tail_pointer(skb
), vaddr
, l1
);
4464 kunmap_atomic(vaddr
, KM_SKB_DATA_SOFTIRQ
);
4465 pci_dma_sync_single_for_device(pdev
,
4466 ps_page_dma
->ps_page_dma
[0],
4467 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
4468 /* remove the CRC */
4475 for (j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
4476 if (!(length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
])))
4478 pci_unmap_page(pdev
, ps_page_dma
->ps_page_dma
[j
],
4479 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
4480 ps_page_dma
->ps_page_dma
[j
] = 0;
4481 skb_fill_page_desc(skb
, j
, ps_page
->ps_page
[j
], 0,
4483 ps_page
->ps_page
[j
] = NULL
;
4485 skb
->data_len
+= length
;
4486 skb
->truesize
+= length
;
4489 /* strip the ethernet crc, problem is we're using pages now so
4490 * this whole operation can get a little cpu intensive */
4491 pskb_trim(skb
, skb
->len
- 4);
4494 total_rx_bytes
+= skb
->len
;
4497 e1000_rx_checksum(adapter
, staterr
,
4498 le16_to_cpu(rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
), skb
);
4499 skb
->protocol
= eth_type_trans(skb
, netdev
);
4501 if (likely(rx_desc
->wb
.upper
.header_status
&
4502 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP
)))
4503 adapter
->rx_hdr_split
++;
4504 #ifdef CONFIG_E1000_NAPI
4505 if (unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
4506 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
4507 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
4508 E1000_RXD_SPC_VLAN_MASK
);
4510 netif_receive_skb(skb
);
4512 #else /* CONFIG_E1000_NAPI */
4513 if (unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
4514 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
4515 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
4516 E1000_RXD_SPC_VLAN_MASK
);
4520 #endif /* CONFIG_E1000_NAPI */
4521 netdev
->last_rx
= jiffies
;
4524 rx_desc
->wb
.middle
.status_error
&= cpu_to_le32(~0xFF);
4525 buffer_info
->skb
= NULL
;
4527 /* return some buffers to hardware, one at a time is too slow */
4528 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
4529 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4533 /* use prefetched values */
4535 buffer_info
= next_buffer
;
4537 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
4539 rx_ring
->next_to_clean
= i
;
4541 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
4543 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4545 adapter
->total_rx_packets
+= total_rx_packets
;
4546 adapter
->total_rx_bytes
+= total_rx_bytes
;
4547 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
4548 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
4553 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4554 * @adapter: address of board private structure
4558 e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
4559 struct e1000_rx_ring
*rx_ring
,
4562 struct net_device
*netdev
= adapter
->netdev
;
4563 struct pci_dev
*pdev
= adapter
->pdev
;
4564 struct e1000_rx_desc
*rx_desc
;
4565 struct e1000_buffer
*buffer_info
;
4566 struct sk_buff
*skb
;
4568 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
4570 i
= rx_ring
->next_to_use
;
4571 buffer_info
= &rx_ring
->buffer_info
[i
];
4573 while (cleaned_count
--) {
4574 skb
= buffer_info
->skb
;
4580 skb
= netdev_alloc_skb(netdev
, bufsz
);
4581 if (unlikely(!skb
)) {
4582 /* Better luck next round */
4583 adapter
->alloc_rx_buff_failed
++;
4587 /* Fix for errata 23, can't cross 64kB boundary */
4588 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4589 struct sk_buff
*oldskb
= skb
;
4590 DPRINTK(RX_ERR
, ERR
, "skb align check failed: %u bytes "
4591 "at %p\n", bufsz
, skb
->data
);
4592 /* Try again, without freeing the previous */
4593 skb
= netdev_alloc_skb(netdev
, bufsz
);
4594 /* Failed allocation, critical failure */
4596 dev_kfree_skb(oldskb
);
4600 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4603 dev_kfree_skb(oldskb
);
4604 break; /* while !buffer_info->skb */
4607 /* Use new allocation */
4608 dev_kfree_skb(oldskb
);
4610 /* Make buffer alignment 2 beyond a 16 byte boundary
4611 * this will result in a 16 byte aligned IP header after
4612 * the 14 byte MAC header is removed
4614 skb_reserve(skb
, NET_IP_ALIGN
);
4616 buffer_info
->skb
= skb
;
4617 buffer_info
->length
= adapter
->rx_buffer_len
;
4619 buffer_info
->dma
= pci_map_single(pdev
,
4621 adapter
->rx_buffer_len
,
4622 PCI_DMA_FROMDEVICE
);
4624 /* Fix for errata 23, can't cross 64kB boundary */
4625 if (!e1000_check_64k_bound(adapter
,
4626 (void *)(unsigned long)buffer_info
->dma
,
4627 adapter
->rx_buffer_len
)) {
4628 DPRINTK(RX_ERR
, ERR
,
4629 "dma align check failed: %u bytes at %p\n",
4630 adapter
->rx_buffer_len
,
4631 (void *)(unsigned long)buffer_info
->dma
);
4633 buffer_info
->skb
= NULL
;
4635 pci_unmap_single(pdev
, buffer_info
->dma
,
4636 adapter
->rx_buffer_len
,
4637 PCI_DMA_FROMDEVICE
);
4639 break; /* while !buffer_info->skb */
4641 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4642 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4644 if (unlikely(++i
== rx_ring
->count
))
4646 buffer_info
= &rx_ring
->buffer_info
[i
];
4649 if (likely(rx_ring
->next_to_use
!= i
)) {
4650 rx_ring
->next_to_use
= i
;
4651 if (unlikely(i
-- == 0))
4652 i
= (rx_ring
->count
- 1);
4654 /* Force memory writes to complete before letting h/w
4655 * know there are new descriptors to fetch. (Only
4656 * applicable for weak-ordered memory model archs,
4657 * such as IA-64). */
4659 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4664 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4665 * @adapter: address of board private structure
4669 e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
4670 struct e1000_rx_ring
*rx_ring
,
4673 struct net_device
*netdev
= adapter
->netdev
;
4674 struct pci_dev
*pdev
= adapter
->pdev
;
4675 union e1000_rx_desc_packet_split
*rx_desc
;
4676 struct e1000_buffer
*buffer_info
;
4677 struct e1000_ps_page
*ps_page
;
4678 struct e1000_ps_page_dma
*ps_page_dma
;
4679 struct sk_buff
*skb
;
4682 i
= rx_ring
->next_to_use
;
4683 buffer_info
= &rx_ring
->buffer_info
[i
];
4684 ps_page
= &rx_ring
->ps_page
[i
];
4685 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
4687 while (cleaned_count
--) {
4688 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
4690 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
4691 if (j
< adapter
->rx_ps_pages
) {
4692 if (likely(!ps_page
->ps_page
[j
])) {
4693 ps_page
->ps_page
[j
] =
4694 alloc_page(GFP_ATOMIC
);
4695 if (unlikely(!ps_page
->ps_page
[j
])) {
4696 adapter
->alloc_rx_buff_failed
++;
4699 ps_page_dma
->ps_page_dma
[j
] =
4701 ps_page
->ps_page
[j
],
4703 PCI_DMA_FROMDEVICE
);
4705 /* Refresh the desc even if buffer_addrs didn't
4706 * change because each write-back erases
4709 rx_desc
->read
.buffer_addr
[j
+1] =
4710 cpu_to_le64(ps_page_dma
->ps_page_dma
[j
]);
4712 rx_desc
->read
.buffer_addr
[j
+1] = ~cpu_to_le64(0);
4715 skb
= netdev_alloc_skb(netdev
,
4716 adapter
->rx_ps_bsize0
+ NET_IP_ALIGN
);
4718 if (unlikely(!skb
)) {
4719 adapter
->alloc_rx_buff_failed
++;
4723 /* Make buffer alignment 2 beyond a 16 byte boundary
4724 * this will result in a 16 byte aligned IP header after
4725 * the 14 byte MAC header is removed
4727 skb_reserve(skb
, NET_IP_ALIGN
);
4729 buffer_info
->skb
= skb
;
4730 buffer_info
->length
= adapter
->rx_ps_bsize0
;
4731 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
4732 adapter
->rx_ps_bsize0
,
4733 PCI_DMA_FROMDEVICE
);
4735 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
4737 if (unlikely(++i
== rx_ring
->count
)) i
= 0;
4738 buffer_info
= &rx_ring
->buffer_info
[i
];
4739 ps_page
= &rx_ring
->ps_page
[i
];
4740 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
4744 if (likely(rx_ring
->next_to_use
!= i
)) {
4745 rx_ring
->next_to_use
= i
;
4746 if (unlikely(i
-- == 0)) i
= (rx_ring
->count
- 1);
4748 /* Force memory writes to complete before letting h/w
4749 * know there are new descriptors to fetch. (Only
4750 * applicable for weak-ordered memory model archs,
4751 * such as IA-64). */
4753 /* Hardware increments by 16 bytes, but packet split
4754 * descriptors are 32 bytes...so we increment tail
4757 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4762 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4767 e1000_smartspeed(struct e1000_adapter
*adapter
)
4769 uint16_t phy_status
;
4772 if ((adapter
->hw
.phy_type
!= e1000_phy_igp
) || !adapter
->hw
.autoneg
||
4773 !(adapter
->hw
.autoneg_advertised
& ADVERTISE_1000_FULL
))
4776 if (adapter
->smartspeed
== 0) {
4777 /* If Master/Slave config fault is asserted twice,
4778 * we assume back-to-back */
4779 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4780 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4781 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4782 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4783 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4784 if (phy_ctrl
& CR_1000T_MS_ENABLE
) {
4785 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
4786 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
,
4788 adapter
->smartspeed
++;
4789 if (!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4790 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
,
4792 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4793 MII_CR_RESTART_AUTO_NEG
);
4794 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
,
4799 } else if (adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
4800 /* If still no link, perhaps using 2/3 pair cable */
4801 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4802 phy_ctrl
|= CR_1000T_MS_ENABLE
;
4803 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, phy_ctrl
);
4804 if (!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4805 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &phy_ctrl
)) {
4806 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4807 MII_CR_RESTART_AUTO_NEG
);
4808 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, phy_ctrl
);
4811 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4812 if (adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
4813 adapter
->smartspeed
= 0;
4824 e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4830 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4844 e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4846 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4847 struct mii_ioctl_data
*data
= if_mii(ifr
);
4851 unsigned long flags
;
4853 if (adapter
->hw
.media_type
!= e1000_media_type_copper
)
4858 data
->phy_id
= adapter
->hw
.phy_addr
;
4861 if (!capable(CAP_NET_ADMIN
))
4863 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4864 if (e1000_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
4866 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4869 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4872 if (!capable(CAP_NET_ADMIN
))
4874 if (data
->reg_num
& ~(0x1F))
4876 mii_reg
= data
->val_in
;
4877 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4878 if (e1000_write_phy_reg(&adapter
->hw
, data
->reg_num
,
4880 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4883 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4884 if (adapter
->hw
.media_type
== e1000_media_type_copper
) {
4885 switch (data
->reg_num
) {
4887 if (mii_reg
& MII_CR_POWER_DOWN
)
4889 if (mii_reg
& MII_CR_AUTO_NEG_EN
) {
4890 adapter
->hw
.autoneg
= 1;
4891 adapter
->hw
.autoneg_advertised
= 0x2F;
4894 spddplx
= SPEED_1000
;
4895 else if (mii_reg
& 0x2000)
4896 spddplx
= SPEED_100
;
4899 spddplx
+= (mii_reg
& 0x100)
4902 retval
= e1000_set_spd_dplx(adapter
,
4907 if (netif_running(adapter
->netdev
))
4908 e1000_reinit_locked(adapter
);
4910 e1000_reset(adapter
);
4912 case M88E1000_PHY_SPEC_CTRL
:
4913 case M88E1000_EXT_PHY_SPEC_CTRL
:
4914 if (e1000_phy_reset(&adapter
->hw
))
4919 switch (data
->reg_num
) {
4921 if (mii_reg
& MII_CR_POWER_DOWN
)
4923 if (netif_running(adapter
->netdev
))
4924 e1000_reinit_locked(adapter
);
4926 e1000_reset(adapter
);
4934 return E1000_SUCCESS
;
4938 e1000_pci_set_mwi(struct e1000_hw
*hw
)
4940 struct e1000_adapter
*adapter
= hw
->back
;
4941 int ret_val
= pci_set_mwi(adapter
->pdev
);
4944 DPRINTK(PROBE
, ERR
, "Error in setting MWI\n");
4948 e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4950 struct e1000_adapter
*adapter
= hw
->back
;
4952 pci_clear_mwi(adapter
->pdev
);
4956 e1000_pcix_get_mmrbc(struct e1000_hw
*hw
)
4958 struct e1000_adapter
*adapter
= hw
->back
;
4959 return pcix_get_mmrbc(adapter
->pdev
);
4963 e1000_pcix_set_mmrbc(struct e1000_hw
*hw
, int mmrbc
)
4965 struct e1000_adapter
*adapter
= hw
->back
;
4966 pcix_set_mmrbc(adapter
->pdev
, mmrbc
);
4970 e1000_read_pcie_cap_reg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4972 struct e1000_adapter
*adapter
= hw
->back
;
4973 uint16_t cap_offset
;
4975 cap_offset
= pci_find_capability(adapter
->pdev
, PCI_CAP_ID_EXP
);
4977 return -E1000_ERR_CONFIG
;
4979 pci_read_config_word(adapter
->pdev
, cap_offset
+ reg
, value
);
4981 return E1000_SUCCESS
;
4985 e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, uint32_t value
)
4991 e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
4993 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4994 uint32_t ctrl
, rctl
;
4996 e1000_irq_disable(adapter
);
4997 adapter
->vlgrp
= grp
;
5000 /* enable VLAN tag insert/strip */
5001 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
5002 ctrl
|= E1000_CTRL_VME
;
5003 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
5005 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
5006 /* enable VLAN receive filtering */
5007 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
5008 rctl
|= E1000_RCTL_VFE
;
5009 rctl
&= ~E1000_RCTL_CFIEN
;
5010 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
5011 e1000_update_mng_vlan(adapter
);
5014 /* disable VLAN tag insert/strip */
5015 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
5016 ctrl
&= ~E1000_CTRL_VME
;
5017 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
5019 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
5020 /* disable VLAN filtering */
5021 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
5022 rctl
&= ~E1000_RCTL_VFE
;
5023 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
5024 if (adapter
->mng_vlan_id
!=
5025 (uint16_t)E1000_MNG_VLAN_NONE
) {
5026 e1000_vlan_rx_kill_vid(netdev
,
5027 adapter
->mng_vlan_id
);
5028 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
5033 e1000_irq_enable(adapter
);
5037 e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
)
5039 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5040 uint32_t vfta
, index
;
5042 if ((adapter
->hw
.mng_cookie
.status
&
5043 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
5044 (vid
== adapter
->mng_vlan_id
))
5046 /* add VID to filter table */
5047 index
= (vid
>> 5) & 0x7F;
5048 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
5049 vfta
|= (1 << (vid
& 0x1F));
5050 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
5054 e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
)
5056 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5057 uint32_t vfta
, index
;
5059 e1000_irq_disable(adapter
);
5060 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
5061 e1000_irq_enable(adapter
);
5063 if ((adapter
->hw
.mng_cookie
.status
&
5064 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
5065 (vid
== adapter
->mng_vlan_id
)) {
5066 /* release control to f/w */
5067 e1000_release_hw_control(adapter
);
5071 /* remove VID from filter table */
5072 index
= (vid
>> 5) & 0x7F;
5073 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
5074 vfta
&= ~(1 << (vid
& 0x1F));
5075 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
5079 e1000_restore_vlan(struct e1000_adapter
*adapter
)
5081 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
5083 if (adapter
->vlgrp
) {
5085 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
5086 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
5088 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
5094 e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
)
5096 adapter
->hw
.autoneg
= 0;
5098 /* Fiber NICs only allow 1000 gbps Full duplex */
5099 if ((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
5100 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
5101 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
5106 case SPEED_10
+ DUPLEX_HALF
:
5107 adapter
->hw
.forced_speed_duplex
= e1000_10_half
;
5109 case SPEED_10
+ DUPLEX_FULL
:
5110 adapter
->hw
.forced_speed_duplex
= e1000_10_full
;
5112 case SPEED_100
+ DUPLEX_HALF
:
5113 adapter
->hw
.forced_speed_duplex
= e1000_100_half
;
5115 case SPEED_100
+ DUPLEX_FULL
:
5116 adapter
->hw
.forced_speed_duplex
= e1000_100_full
;
5118 case SPEED_1000
+ DUPLEX_FULL
:
5119 adapter
->hw
.autoneg
= 1;
5120 adapter
->hw
.autoneg_advertised
= ADVERTISE_1000_FULL
;
5122 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
5124 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
5131 e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5133 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5134 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5135 uint32_t ctrl
, ctrl_ext
, rctl
, status
;
5136 uint32_t wufc
= adapter
->wol
;
5141 netif_device_detach(netdev
);
5143 if (netif_running(netdev
)) {
5144 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
5145 e1000_down(adapter
);
5149 retval
= pci_save_state(pdev
);
5154 status
= E1000_READ_REG(&adapter
->hw
, STATUS
);
5155 if (status
& E1000_STATUS_LU
)
5156 wufc
&= ~E1000_WUFC_LNKC
;
5159 e1000_setup_rctl(adapter
);
5160 e1000_set_rx_mode(netdev
);
5162 /* turn on all-multi mode if wake on multicast is enabled */
5163 if (wufc
& E1000_WUFC_MC
) {
5164 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
5165 rctl
|= E1000_RCTL_MPE
;
5166 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
5169 if (adapter
->hw
.mac_type
>= e1000_82540
) {
5170 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
5171 /* advertise wake from D3Cold */
5172 #define E1000_CTRL_ADVD3WUC 0x00100000
5173 /* phy power management enable */
5174 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5175 ctrl
|= E1000_CTRL_ADVD3WUC
|
5176 E1000_CTRL_EN_PHY_PWR_MGMT
;
5177 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
5180 if (adapter
->hw
.media_type
== e1000_media_type_fiber
||
5181 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) {
5182 /* keep the laser running in D3 */
5183 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
5184 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
5185 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
, ctrl_ext
);
5188 /* Allow time for pending master requests to run */
5189 e1000_disable_pciex_master(&adapter
->hw
);
5191 E1000_WRITE_REG(&adapter
->hw
, WUC
, E1000_WUC_PME_EN
);
5192 E1000_WRITE_REG(&adapter
->hw
, WUFC
, wufc
);
5193 pci_enable_wake(pdev
, PCI_D3hot
, 1);
5194 pci_enable_wake(pdev
, PCI_D3cold
, 1);
5196 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
5197 E1000_WRITE_REG(&adapter
->hw
, WUFC
, 0);
5198 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5199 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5202 e1000_release_manageability(adapter
);
5204 /* make sure adapter isn't asleep if manageability is enabled */
5205 if (adapter
->en_mng_pt
) {
5206 pci_enable_wake(pdev
, PCI_D3hot
, 1);
5207 pci_enable_wake(pdev
, PCI_D3cold
, 1);
5210 if (adapter
->hw
.phy_type
== e1000_phy_igp_3
)
5211 e1000_phy_powerdown_workaround(&adapter
->hw
);
5213 if (netif_running(netdev
))
5214 e1000_free_irq(adapter
);
5216 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5217 * would have already happened in close and is redundant. */
5218 e1000_release_hw_control(adapter
);
5220 pci_disable_device(pdev
);
5222 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
5229 e1000_resume(struct pci_dev
*pdev
)
5231 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5232 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5235 pci_set_power_state(pdev
, PCI_D0
);
5236 pci_restore_state(pdev
);
5237 if ((err
= pci_enable_device(pdev
))) {
5238 printk(KERN_ERR
"e1000: Cannot enable PCI device from suspend\n");
5241 pci_set_master(pdev
);
5243 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5244 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5246 if (netif_running(netdev
) && (err
= e1000_request_irq(adapter
)))
5249 e1000_power_up_phy(adapter
);
5250 e1000_reset(adapter
);
5251 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
5253 e1000_init_manageability(adapter
);
5255 if (netif_running(netdev
))
5258 netif_device_attach(netdev
);
5260 /* If the controller is 82573 and f/w is AMT, do not set
5261 * DRV_LOAD until the interface is up. For all other cases,
5262 * let the f/w know that the h/w is now under the control
5264 if (adapter
->hw
.mac_type
!= e1000_82573
||
5265 !e1000_check_mng_mode(&adapter
->hw
))
5266 e1000_get_hw_control(adapter
);
5272 static void e1000_shutdown(struct pci_dev
*pdev
)
5274 e1000_suspend(pdev
, PMSG_SUSPEND
);
5277 #ifdef CONFIG_NET_POLL_CONTROLLER
5279 * Polling 'interrupt' - used by things like netconsole to send skbs
5280 * without having to re-enable interrupts. It's not called while
5281 * the interrupt routine is executing.
5284 e1000_netpoll(struct net_device
*netdev
)
5286 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
5288 disable_irq(adapter
->pdev
->irq
);
5289 e1000_intr(adapter
->pdev
->irq
, netdev
);
5290 e1000_clean_tx_irq(adapter
, adapter
->tx_ring
);
5291 #ifndef CONFIG_E1000_NAPI
5292 adapter
->clean_rx(adapter
, adapter
->rx_ring
);
5294 enable_irq(adapter
->pdev
->irq
);
5299 * e1000_io_error_detected - called when PCI error is detected
5300 * @pdev: Pointer to PCI device
5301 * @state: The current pci conneection state
5303 * This function is called after a PCI bus error affecting
5304 * this device has been detected.
5306 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
5308 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5309 struct e1000_adapter
*adapter
= netdev
->priv
;
5311 netif_device_detach(netdev
);
5313 if (netif_running(netdev
))
5314 e1000_down(adapter
);
5315 pci_disable_device(pdev
);
5317 /* Request a slot slot reset. */
5318 return PCI_ERS_RESULT_NEED_RESET
;
5322 * e1000_io_slot_reset - called after the pci bus has been reset.
5323 * @pdev: Pointer to PCI device
5325 * Restart the card from scratch, as if from a cold-boot. Implementation
5326 * resembles the first-half of the e1000_resume routine.
5328 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
5330 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5331 struct e1000_adapter
*adapter
= netdev
->priv
;
5333 if (pci_enable_device(pdev
)) {
5334 printk(KERN_ERR
"e1000: Cannot re-enable PCI device after reset.\n");
5335 return PCI_ERS_RESULT_DISCONNECT
;
5337 pci_set_master(pdev
);
5339 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5340 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5342 e1000_reset(adapter
);
5343 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
5345 return PCI_ERS_RESULT_RECOVERED
;
5349 * e1000_io_resume - called when traffic can start flowing again.
5350 * @pdev: Pointer to PCI device
5352 * This callback is called when the error recovery driver tells us that
5353 * its OK to resume normal operation. Implementation resembles the
5354 * second-half of the e1000_resume routine.
5356 static void e1000_io_resume(struct pci_dev
*pdev
)
5358 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5359 struct e1000_adapter
*adapter
= netdev
->priv
;
5361 e1000_init_manageability(adapter
);
5363 if (netif_running(netdev
)) {
5364 if (e1000_up(adapter
)) {
5365 printk("e1000: can't bring device back up after reset\n");
5370 netif_device_attach(netdev
);
5372 /* If the controller is 82573 and f/w is AMT, do not set
5373 * DRV_LOAD until the interface is up. For all other cases,
5374 * let the f/w know that the h/w is now under the control
5376 if (adapter
->hw
.mac_type
!= e1000_82573
||
5377 !e1000_check_mng_mode(&adapter
->hw
))
5378 e1000_get_hw_control(adapter
);