1 /*******************************************************************************
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
26 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *******************************************************************************/
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.2.7-k2"DRIVERNAPI
40 char e1000_driver_version
[] = DRV_VERSION
;
41 static 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 static struct pci_device_id e1000_pci_tbl
[] = {
51 INTEL_E1000_ETHERNET_DEVICE(0x1000),
52 INTEL_E1000_ETHERNET_DEVICE(0x1001),
53 INTEL_E1000_ETHERNET_DEVICE(0x1004),
54 INTEL_E1000_ETHERNET_DEVICE(0x1008),
55 INTEL_E1000_ETHERNET_DEVICE(0x1009),
56 INTEL_E1000_ETHERNET_DEVICE(0x100C),
57 INTEL_E1000_ETHERNET_DEVICE(0x100D),
58 INTEL_E1000_ETHERNET_DEVICE(0x100E),
59 INTEL_E1000_ETHERNET_DEVICE(0x100F),
60 INTEL_E1000_ETHERNET_DEVICE(0x1010),
61 INTEL_E1000_ETHERNET_DEVICE(0x1011),
62 INTEL_E1000_ETHERNET_DEVICE(0x1012),
63 INTEL_E1000_ETHERNET_DEVICE(0x1013),
64 INTEL_E1000_ETHERNET_DEVICE(0x1014),
65 INTEL_E1000_ETHERNET_DEVICE(0x1015),
66 INTEL_E1000_ETHERNET_DEVICE(0x1016),
67 INTEL_E1000_ETHERNET_DEVICE(0x1017),
68 INTEL_E1000_ETHERNET_DEVICE(0x1018),
69 INTEL_E1000_ETHERNET_DEVICE(0x1019),
70 INTEL_E1000_ETHERNET_DEVICE(0x101A),
71 INTEL_E1000_ETHERNET_DEVICE(0x101D),
72 INTEL_E1000_ETHERNET_DEVICE(0x101E),
73 INTEL_E1000_ETHERNET_DEVICE(0x1026),
74 INTEL_E1000_ETHERNET_DEVICE(0x1027),
75 INTEL_E1000_ETHERNET_DEVICE(0x1028),
76 INTEL_E1000_ETHERNET_DEVICE(0x1049),
77 INTEL_E1000_ETHERNET_DEVICE(0x104A),
78 INTEL_E1000_ETHERNET_DEVICE(0x104B),
79 INTEL_E1000_ETHERNET_DEVICE(0x104C),
80 INTEL_E1000_ETHERNET_DEVICE(0x104D),
81 INTEL_E1000_ETHERNET_DEVICE(0x105E),
82 INTEL_E1000_ETHERNET_DEVICE(0x105F),
83 INTEL_E1000_ETHERNET_DEVICE(0x1060),
84 INTEL_E1000_ETHERNET_DEVICE(0x1075),
85 INTEL_E1000_ETHERNET_DEVICE(0x1076),
86 INTEL_E1000_ETHERNET_DEVICE(0x1077),
87 INTEL_E1000_ETHERNET_DEVICE(0x1078),
88 INTEL_E1000_ETHERNET_DEVICE(0x1079),
89 INTEL_E1000_ETHERNET_DEVICE(0x107A),
90 INTEL_E1000_ETHERNET_DEVICE(0x107B),
91 INTEL_E1000_ETHERNET_DEVICE(0x107C),
92 INTEL_E1000_ETHERNET_DEVICE(0x107D),
93 INTEL_E1000_ETHERNET_DEVICE(0x107E),
94 INTEL_E1000_ETHERNET_DEVICE(0x107F),
95 INTEL_E1000_ETHERNET_DEVICE(0x108A),
96 INTEL_E1000_ETHERNET_DEVICE(0x108B),
97 INTEL_E1000_ETHERNET_DEVICE(0x108C),
98 INTEL_E1000_ETHERNET_DEVICE(0x1096),
99 INTEL_E1000_ETHERNET_DEVICE(0x1098),
100 INTEL_E1000_ETHERNET_DEVICE(0x1099),
101 INTEL_E1000_ETHERNET_DEVICE(0x109A),
102 INTEL_E1000_ETHERNET_DEVICE(0x10A4),
103 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
104 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
105 INTEL_E1000_ETHERNET_DEVICE(0x10BA),
106 INTEL_E1000_ETHERNET_DEVICE(0x10BB),
107 /* required last entry */
111 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
113 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
114 struct e1000_tx_ring
*txdr
);
115 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
116 struct e1000_rx_ring
*rxdr
);
117 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
118 struct e1000_tx_ring
*tx_ring
);
119 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
120 struct e1000_rx_ring
*rx_ring
);
122 /* Local Function Prototypes */
124 static int e1000_init_module(void);
125 static void e1000_exit_module(void);
126 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
127 static void __devexit
e1000_remove(struct pci_dev
*pdev
);
128 static int e1000_alloc_queues(struct e1000_adapter
*adapter
);
129 static int e1000_sw_init(struct e1000_adapter
*adapter
);
130 static int e1000_open(struct net_device
*netdev
);
131 static int e1000_close(struct net_device
*netdev
);
132 static void e1000_configure_tx(struct e1000_adapter
*adapter
);
133 static void e1000_configure_rx(struct e1000_adapter
*adapter
);
134 static void e1000_setup_rctl(struct e1000_adapter
*adapter
);
135 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
);
136 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
);
137 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
138 struct e1000_tx_ring
*tx_ring
);
139 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
140 struct e1000_rx_ring
*rx_ring
);
141 static void e1000_set_multi(struct net_device
*netdev
);
142 static void e1000_update_phy_info(unsigned long data
);
143 static void e1000_watchdog(unsigned long data
);
144 static void e1000_82547_tx_fifo_stall(unsigned long data
);
145 static int e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
);
146 static struct net_device_stats
* e1000_get_stats(struct net_device
*netdev
);
147 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
148 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
149 static irqreturn_t
e1000_intr(int irq
, void *data
, struct pt_regs
*regs
);
150 static boolean_t
e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
151 struct e1000_tx_ring
*tx_ring
);
152 #ifdef CONFIG_E1000_NAPI
153 static int e1000_clean(struct net_device
*poll_dev
, int *budget
);
154 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
155 struct e1000_rx_ring
*rx_ring
,
156 int *work_done
, int work_to_do
);
157 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
158 struct e1000_rx_ring
*rx_ring
,
159 int *work_done
, int work_to_do
);
161 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
162 struct e1000_rx_ring
*rx_ring
);
163 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
164 struct e1000_rx_ring
*rx_ring
);
166 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
167 struct e1000_rx_ring
*rx_ring
,
169 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
170 struct e1000_rx_ring
*rx_ring
,
172 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
173 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
175 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
176 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
177 static void e1000_tx_timeout(struct net_device
*dev
);
178 static void e1000_reset_task(struct net_device
*dev
);
179 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
180 static int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
181 struct sk_buff
*skb
);
183 static void e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
);
184 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
);
185 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
);
186 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
188 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
);
190 static int e1000_resume(struct pci_dev
*pdev
);
192 static void e1000_shutdown(struct pci_dev
*pdev
);
194 #ifdef CONFIG_NET_POLL_CONTROLLER
195 /* for netdump / net console */
196 static void e1000_netpoll (struct net_device
*netdev
);
199 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
200 pci_channel_state_t state
);
201 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
);
202 static void e1000_io_resume(struct pci_dev
*pdev
);
204 static struct pci_error_handlers e1000_err_handler
= {
205 .error_detected
= e1000_io_error_detected
,
206 .slot_reset
= e1000_io_slot_reset
,
207 .resume
= e1000_io_resume
,
210 static struct pci_driver e1000_driver
= {
211 .name
= e1000_driver_name
,
212 .id_table
= e1000_pci_tbl
,
213 .probe
= e1000_probe
,
214 .remove
= __devexit_p(e1000_remove
),
215 /* Power Managment Hooks */
216 .suspend
= e1000_suspend
,
218 .resume
= e1000_resume
,
220 .shutdown
= e1000_shutdown
,
221 .err_handler
= &e1000_err_handler
224 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
225 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
226 MODULE_LICENSE("GPL");
227 MODULE_VERSION(DRV_VERSION
);
229 static int debug
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
230 module_param(debug
, int, 0);
231 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
234 * e1000_init_module - Driver Registration Routine
236 * e1000_init_module is the first routine called when the driver is
237 * loaded. All it does is register with the PCI subsystem.
241 e1000_init_module(void)
244 printk(KERN_INFO
"%s - version %s\n",
245 e1000_driver_string
, e1000_driver_version
);
247 printk(KERN_INFO
"%s\n", e1000_copyright
);
249 ret
= pci_register_driver(&e1000_driver
);
254 module_init(e1000_init_module
);
257 * e1000_exit_module - Driver Exit Cleanup Routine
259 * e1000_exit_module is called just before the driver is removed
264 e1000_exit_module(void)
266 pci_unregister_driver(&e1000_driver
);
269 module_exit(e1000_exit_module
);
271 static int e1000_request_irq(struct e1000_adapter
*adapter
)
273 struct net_device
*netdev
= adapter
->netdev
;
277 #ifdef CONFIG_PCI_MSI
278 if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
279 adapter
->have_msi
= TRUE
;
280 if ((err
= pci_enable_msi(adapter
->pdev
))) {
282 "Unable to allocate MSI interrupt Error: %d\n", err
);
283 adapter
->have_msi
= FALSE
;
286 if (adapter
->have_msi
)
287 flags
&= ~IRQF_SHARED
;
289 if ((err
= request_irq(adapter
->pdev
->irq
, &e1000_intr
, flags
,
290 netdev
->name
, netdev
)))
292 "Unable to allocate interrupt Error: %d\n", err
);
297 static void e1000_free_irq(struct e1000_adapter
*adapter
)
299 struct net_device
*netdev
= adapter
->netdev
;
301 free_irq(adapter
->pdev
->irq
, netdev
);
303 #ifdef CONFIG_PCI_MSI
304 if (adapter
->have_msi
)
305 pci_disable_msi(adapter
->pdev
);
310 * e1000_irq_disable - Mask off interrupt generation on the NIC
311 * @adapter: board private structure
315 e1000_irq_disable(struct e1000_adapter
*adapter
)
317 atomic_inc(&adapter
->irq_sem
);
318 E1000_WRITE_REG(&adapter
->hw
, IMC
, ~0);
319 E1000_WRITE_FLUSH(&adapter
->hw
);
320 synchronize_irq(adapter
->pdev
->irq
);
324 * e1000_irq_enable - Enable default interrupt generation settings
325 * @adapter: board private structure
329 e1000_irq_enable(struct e1000_adapter
*adapter
)
331 if (likely(atomic_dec_and_test(&adapter
->irq_sem
))) {
332 E1000_WRITE_REG(&adapter
->hw
, IMS
, IMS_ENABLE_MASK
);
333 E1000_WRITE_FLUSH(&adapter
->hw
);
338 e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
340 struct net_device
*netdev
= adapter
->netdev
;
341 uint16_t vid
= adapter
->hw
.mng_cookie
.vlan_id
;
342 uint16_t old_vid
= adapter
->mng_vlan_id
;
343 if (adapter
->vlgrp
) {
344 if (!adapter
->vlgrp
->vlan_devices
[vid
]) {
345 if (adapter
->hw
.mng_cookie
.status
&
346 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
347 e1000_vlan_rx_add_vid(netdev
, vid
);
348 adapter
->mng_vlan_id
= vid
;
350 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
352 if ((old_vid
!= (uint16_t)E1000_MNG_VLAN_NONE
) &&
354 !adapter
->vlgrp
->vlan_devices
[old_vid
])
355 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
357 adapter
->mng_vlan_id
= vid
;
362 * e1000_release_hw_control - release control of the h/w to f/w
363 * @adapter: address of board private structure
365 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
366 * For ASF and Pass Through versions of f/w this means that the
367 * driver is no longer loaded. For AMT version (only with 82573) i
368 * of the f/w this means that the netowrk i/f is closed.
373 e1000_release_hw_control(struct e1000_adapter
*adapter
)
379 /* Let firmware taken over control of h/w */
380 switch (adapter
->hw
.mac_type
) {
383 case e1000_80003es2lan
:
384 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
385 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
386 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
389 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
390 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
391 swsm
& ~E1000_SWSM_DRV_LOAD
);
393 extcnf
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
394 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
395 extcnf
& ~E1000_CTRL_EXT_DRV_LOAD
);
403 * e1000_get_hw_control - get control of the h/w from f/w
404 * @adapter: address of board private structure
406 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
407 * For ASF and Pass Through versions of f/w this means that
408 * the driver is loaded. For AMT version (only with 82573)
409 * of the f/w this means that the netowrk i/f is open.
414 e1000_get_hw_control(struct e1000_adapter
*adapter
)
419 /* Let firmware know the driver has taken over */
420 switch (adapter
->hw
.mac_type
) {
423 case e1000_80003es2lan
:
424 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
425 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
426 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
429 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
430 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
431 swsm
| E1000_SWSM_DRV_LOAD
);
434 extcnf
= E1000_READ_REG(&adapter
->hw
, EXTCNF_CTRL
);
435 E1000_WRITE_REG(&adapter
->hw
, EXTCNF_CTRL
,
436 extcnf
| E1000_EXTCNF_CTRL_SWFLAG
);
444 e1000_up(struct e1000_adapter
*adapter
)
446 struct net_device
*netdev
= adapter
->netdev
;
449 /* hardware has been reset, we need to reload some things */
451 e1000_set_multi(netdev
);
453 e1000_restore_vlan(adapter
);
455 e1000_configure_tx(adapter
);
456 e1000_setup_rctl(adapter
);
457 e1000_configure_rx(adapter
);
458 /* call E1000_DESC_UNUSED which always leaves
459 * at least 1 descriptor unused to make sure
460 * next_to_use != next_to_clean */
461 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
462 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[i
];
463 adapter
->alloc_rx_buf(adapter
, ring
,
464 E1000_DESC_UNUSED(ring
));
467 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
469 mod_timer(&adapter
->watchdog_timer
, jiffies
);
471 #ifdef CONFIG_E1000_NAPI
472 netif_poll_enable(netdev
);
474 e1000_irq_enable(adapter
);
480 * e1000_power_up_phy - restore link in case the phy was powered down
481 * @adapter: address of board private structure
483 * The phy may be powered down to save power and turn off link when the
484 * driver is unloaded and wake on lan is not enabled (among others)
485 * *** this routine MUST be followed by a call to e1000_reset ***
489 void e1000_power_up_phy(struct e1000_adapter
*adapter
)
491 uint16_t mii_reg
= 0;
493 /* Just clear the power down bit to wake the phy back up */
494 if (adapter
->hw
.media_type
== e1000_media_type_copper
) {
495 /* according to the manual, the phy will retain its
496 * settings across a power-down/up cycle */
497 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
498 mii_reg
&= ~MII_CR_POWER_DOWN
;
499 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
503 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
505 boolean_t mng_mode_enabled
= (adapter
->hw
.mac_type
>= e1000_82571
) &&
506 e1000_check_mng_mode(&adapter
->hw
);
507 /* Power down the PHY so no link is implied when interface is down
508 * The PHY cannot be powered down if any of the following is TRUE
511 * (c) SoL/IDER session is active */
512 if (!adapter
->wol
&& adapter
->hw
.mac_type
>= e1000_82540
&&
513 adapter
->hw
.mac_type
!= e1000_ich8lan
&&
514 adapter
->hw
.media_type
== e1000_media_type_copper
&&
515 !(E1000_READ_REG(&adapter
->hw
, MANC
) & E1000_MANC_SMBUS_EN
) &&
517 !e1000_check_phy_reset_block(&adapter
->hw
)) {
518 uint16_t mii_reg
= 0;
519 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
520 mii_reg
|= MII_CR_POWER_DOWN
;
521 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
527 e1000_down(struct e1000_adapter
*adapter
)
529 struct net_device
*netdev
= adapter
->netdev
;
531 e1000_irq_disable(adapter
);
533 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
534 del_timer_sync(&adapter
->watchdog_timer
);
535 del_timer_sync(&adapter
->phy_info_timer
);
537 #ifdef CONFIG_E1000_NAPI
538 netif_poll_disable(netdev
);
540 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
541 adapter
->link_speed
= 0;
542 adapter
->link_duplex
= 0;
543 netif_carrier_off(netdev
);
544 netif_stop_queue(netdev
);
546 e1000_reset(adapter
);
547 e1000_clean_all_tx_rings(adapter
);
548 e1000_clean_all_rx_rings(adapter
);
552 e1000_reinit_locked(struct e1000_adapter
*adapter
)
554 WARN_ON(in_interrupt());
555 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->flags
))
559 clear_bit(__E1000_RESETTING
, &adapter
->flags
);
563 e1000_reset(struct e1000_adapter
*adapter
)
566 uint16_t fc_high_water_mark
= E1000_FC_HIGH_DIFF
;
568 /* Repartition Pba for greater than 9k mtu
569 * To take effect CTRL.RST is required.
572 switch (adapter
->hw
.mac_type
) {
574 case e1000_82547_rev_2
:
579 case e1000_80003es2lan
:
593 if ((adapter
->hw
.mac_type
!= e1000_82573
) &&
594 (adapter
->netdev
->mtu
> E1000_RXBUFFER_8192
))
595 pba
-= 8; /* allocate more FIFO for Tx */
598 if (adapter
->hw
.mac_type
== e1000_82547
) {
599 adapter
->tx_fifo_head
= 0;
600 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
601 adapter
->tx_fifo_size
=
602 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
603 atomic_set(&adapter
->tx_fifo_stall
, 0);
606 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
608 /* flow control settings */
609 /* Set the FC high water mark to 90% of the FIFO size.
610 * Required to clear last 3 LSB */
611 fc_high_water_mark
= ((pba
* 9216)/10) & 0xFFF8;
612 /* We can't use 90% on small FIFOs because the remainder
613 * would be less than 1 full frame. In this case, we size
614 * it to allow at least a full frame above the high water
616 if (pba
< E1000_PBA_16K
)
617 fc_high_water_mark
= (pba
* 1024) - 1600;
619 adapter
->hw
.fc_high_water
= fc_high_water_mark
;
620 adapter
->hw
.fc_low_water
= fc_high_water_mark
- 8;
621 if (adapter
->hw
.mac_type
== e1000_80003es2lan
)
622 adapter
->hw
.fc_pause_time
= 0xFFFF;
624 adapter
->hw
.fc_pause_time
= E1000_FC_PAUSE_TIME
;
625 adapter
->hw
.fc_send_xon
= 1;
626 adapter
->hw
.fc
= adapter
->hw
.original_fc
;
628 /* Allow time for pending master requests to run */
629 e1000_reset_hw(&adapter
->hw
);
630 if (adapter
->hw
.mac_type
>= e1000_82544
)
631 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
632 if (e1000_init_hw(&adapter
->hw
))
633 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
634 e1000_update_mng_vlan(adapter
);
635 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
636 E1000_WRITE_REG(&adapter
->hw
, VET
, ETHERNET_IEEE_VLAN_TYPE
);
638 e1000_reset_adaptive(&adapter
->hw
);
639 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
641 if (!adapter
->smart_power_down
&&
642 (adapter
->hw
.mac_type
== e1000_82571
||
643 adapter
->hw
.mac_type
== e1000_82572
)) {
644 uint16_t phy_data
= 0;
645 /* speed up time to link by disabling smart power down, ignore
646 * the return value of this function because there is nothing
647 * different we would do if it failed */
648 e1000_read_phy_reg(&adapter
->hw
, IGP02E1000_PHY_POWER_MGMT
,
650 phy_data
&= ~IGP02E1000_PM_SPD
;
651 e1000_write_phy_reg(&adapter
->hw
, IGP02E1000_PHY_POWER_MGMT
,
655 if (adapter
->hw
.mac_type
< e1000_ich8lan
)
656 /* FIXME: this code is duplicate and wrong for PCI Express */
657 if (adapter
->en_mng_pt
) {
658 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
659 manc
|= (E1000_MANC_ARP_EN
| E1000_MANC_EN_MNG2HOST
);
660 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
665 * e1000_probe - Device Initialization Routine
666 * @pdev: PCI device information struct
667 * @ent: entry in e1000_pci_tbl
669 * Returns 0 on success, negative on failure
671 * e1000_probe initializes an adapter identified by a pci_dev structure.
672 * The OS initialization, configuring of the adapter private structure,
673 * and a hardware reset occur.
677 e1000_probe(struct pci_dev
*pdev
,
678 const struct pci_device_id
*ent
)
680 struct net_device
*netdev
;
681 struct e1000_adapter
*adapter
;
682 unsigned long mmio_start
, mmio_len
;
683 unsigned long flash_start
, flash_len
;
685 static int cards_found
= 0;
686 static int global_quad_port_a
= 0; /* global ksp3 port a indication */
687 int i
, err
, pci_using_dac
;
688 uint16_t eeprom_data
= 0;
689 uint16_t eeprom_apme_mask
= E1000_EEPROM_APME
;
690 if ((err
= pci_enable_device(pdev
)))
693 if (!(err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
)) &&
694 !(err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
))) {
697 if ((err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) &&
698 (err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
))) {
699 E1000_ERR("No usable DMA configuration, aborting\n");
705 if ((err
= pci_request_regions(pdev
, e1000_driver_name
)))
708 pci_set_master(pdev
);
711 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
713 goto err_alloc_etherdev
;
715 SET_MODULE_OWNER(netdev
);
716 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
718 pci_set_drvdata(pdev
, netdev
);
719 adapter
= netdev_priv(netdev
);
720 adapter
->netdev
= netdev
;
721 adapter
->pdev
= pdev
;
722 adapter
->hw
.back
= adapter
;
723 adapter
->msg_enable
= (1 << debug
) - 1;
725 mmio_start
= pci_resource_start(pdev
, BAR_0
);
726 mmio_len
= pci_resource_len(pdev
, BAR_0
);
729 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
730 if (!adapter
->hw
.hw_addr
)
733 for (i
= BAR_1
; i
<= BAR_5
; i
++) {
734 if (pci_resource_len(pdev
, i
) == 0)
736 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
737 adapter
->hw
.io_base
= pci_resource_start(pdev
, i
);
742 netdev
->open
= &e1000_open
;
743 netdev
->stop
= &e1000_close
;
744 netdev
->hard_start_xmit
= &e1000_xmit_frame
;
745 netdev
->get_stats
= &e1000_get_stats
;
746 netdev
->set_multicast_list
= &e1000_set_multi
;
747 netdev
->set_mac_address
= &e1000_set_mac
;
748 netdev
->change_mtu
= &e1000_change_mtu
;
749 netdev
->do_ioctl
= &e1000_ioctl
;
750 e1000_set_ethtool_ops(netdev
);
751 netdev
->tx_timeout
= &e1000_tx_timeout
;
752 netdev
->watchdog_timeo
= 5 * HZ
;
753 #ifdef CONFIG_E1000_NAPI
754 netdev
->poll
= &e1000_clean
;
757 netdev
->vlan_rx_register
= e1000_vlan_rx_register
;
758 netdev
->vlan_rx_add_vid
= e1000_vlan_rx_add_vid
;
759 netdev
->vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
;
760 #ifdef CONFIG_NET_POLL_CONTROLLER
761 netdev
->poll_controller
= e1000_netpoll
;
763 strcpy(netdev
->name
, pci_name(pdev
));
765 netdev
->mem_start
= mmio_start
;
766 netdev
->mem_end
= mmio_start
+ mmio_len
;
767 netdev
->base_addr
= adapter
->hw
.io_base
;
769 adapter
->bd_number
= cards_found
;
771 /* setup the private structure */
773 if ((err
= e1000_sw_init(adapter
)))
777 /* Flash BAR mapping must happen after e1000_sw_init
778 * because it depends on mac_type */
779 if ((adapter
->hw
.mac_type
== e1000_ich8lan
) &&
780 (pci_resource_flags(pdev
, 1) & IORESOURCE_MEM
)) {
781 flash_start
= pci_resource_start(pdev
, 1);
782 flash_len
= pci_resource_len(pdev
, 1);
783 adapter
->hw
.flash_address
= ioremap(flash_start
, flash_len
);
784 if (!adapter
->hw
.flash_address
)
788 if (e1000_check_phy_reset_block(&adapter
->hw
))
789 DPRINTK(PROBE
, INFO
, "PHY reset is blocked due to SOL/IDER session.\n");
791 if (adapter
->hw
.mac_type
>= e1000_82543
) {
792 netdev
->features
= NETIF_F_SG
|
796 NETIF_F_HW_VLAN_FILTER
;
797 if (adapter
->hw
.mac_type
== e1000_ich8lan
)
798 netdev
->features
&= ~NETIF_F_HW_VLAN_FILTER
;
802 if ((adapter
->hw
.mac_type
>= e1000_82544
) &&
803 (adapter
->hw
.mac_type
!= e1000_82547
))
804 netdev
->features
|= NETIF_F_TSO
;
806 #ifdef NETIF_F_TSO_IPV6
807 if (adapter
->hw
.mac_type
> e1000_82547_rev_2
)
808 netdev
->features
|= NETIF_F_TSO_IPV6
;
812 netdev
->features
|= NETIF_F_HIGHDMA
;
814 netdev
->features
|= NETIF_F_LLTX
;
816 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(&adapter
->hw
);
818 /* initialize eeprom parameters */
820 if (e1000_init_eeprom_params(&adapter
->hw
)) {
821 E1000_ERR("EEPROM initialization failed\n");
825 /* before reading the EEPROM, reset the controller to
826 * put the device in a known good starting state */
828 e1000_reset_hw(&adapter
->hw
);
830 /* make sure the EEPROM is good */
832 if (e1000_validate_eeprom_checksum(&adapter
->hw
) < 0) {
833 DPRINTK(PROBE
, ERR
, "The EEPROM Checksum Is Not Valid\n");
837 /* copy the MAC address out of the EEPROM */
839 if (e1000_read_mac_addr(&adapter
->hw
))
840 DPRINTK(PROBE
, ERR
, "EEPROM Read Error\n");
841 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
842 memcpy(netdev
->perm_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
844 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
845 DPRINTK(PROBE
, ERR
, "Invalid MAC Address\n");
849 e1000_get_bus_info(&adapter
->hw
);
851 init_timer(&adapter
->tx_fifo_stall_timer
);
852 adapter
->tx_fifo_stall_timer
.function
= &e1000_82547_tx_fifo_stall
;
853 adapter
->tx_fifo_stall_timer
.data
= (unsigned long) adapter
;
855 init_timer(&adapter
->watchdog_timer
);
856 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
857 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
859 init_timer(&adapter
->phy_info_timer
);
860 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
861 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
863 INIT_WORK(&adapter
->reset_task
,
864 (void (*)(void *))e1000_reset_task
, netdev
);
866 /* we're going to reset, so assume we have no link for now */
868 netif_carrier_off(netdev
);
869 netif_stop_queue(netdev
);
871 e1000_check_options(adapter
);
873 /* Initial Wake on LAN setting
874 * If APM wake is enabled in the EEPROM,
875 * enable the ACPI Magic Packet filter
878 switch (adapter
->hw
.mac_type
) {
879 case e1000_82542_rev2_0
:
880 case e1000_82542_rev2_1
:
884 e1000_read_eeprom(&adapter
->hw
,
885 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
886 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
889 e1000_read_eeprom(&adapter
->hw
,
890 EEPROM_INIT_CONTROL1_REG
, 1, &eeprom_data
);
891 eeprom_apme_mask
= E1000_EEPROM_ICH8_APME
;
894 case e1000_82546_rev_3
:
896 case e1000_80003es2lan
:
897 if (E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
){
898 e1000_read_eeprom(&adapter
->hw
,
899 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
904 e1000_read_eeprom(&adapter
->hw
,
905 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
908 if (eeprom_data
& eeprom_apme_mask
)
909 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
911 /* now that we have the eeprom settings, apply the special cases
912 * where the eeprom may be wrong or the board simply won't support
913 * wake on lan on a particular port */
914 switch (pdev
->device
) {
915 case E1000_DEV_ID_82546GB_PCIE
:
916 adapter
->eeprom_wol
= 0;
918 case E1000_DEV_ID_82546EB_FIBER
:
919 case E1000_DEV_ID_82546GB_FIBER
:
920 case E1000_DEV_ID_82571EB_FIBER
:
921 /* Wake events only supported on port A for dual fiber
922 * regardless of eeprom setting */
923 if (E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
)
924 adapter
->eeprom_wol
= 0;
926 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3
:
927 case E1000_DEV_ID_82571EB_QUAD_COPPER
:
928 /* if quad port adapter, disable WoL on all but port A */
929 if (global_quad_port_a
!= 0)
930 adapter
->eeprom_wol
= 0;
932 adapter
->quad_port_a
= 1;
933 /* Reset for multiple quad port adapters */
934 if (++global_quad_port_a
== 4)
935 global_quad_port_a
= 0;
939 /* initialize the wol settings based on the eeprom settings */
940 adapter
->wol
= adapter
->eeprom_wol
;
942 /* print bus type/speed/width info */
944 struct e1000_hw
*hw
= &adapter
->hw
;
945 DPRINTK(PROBE
, INFO
, "(PCI%s:%s:%s) ",
946 ((hw
->bus_type
== e1000_bus_type_pcix
) ? "-X" :
947 (hw
->bus_type
== e1000_bus_type_pci_express
? " Express":"")),
948 ((hw
->bus_speed
== e1000_bus_speed_2500
) ? "2.5Gb/s" :
949 (hw
->bus_speed
== e1000_bus_speed_133
) ? "133MHz" :
950 (hw
->bus_speed
== e1000_bus_speed_120
) ? "120MHz" :
951 (hw
->bus_speed
== e1000_bus_speed_100
) ? "100MHz" :
952 (hw
->bus_speed
== e1000_bus_speed_66
) ? "66MHz" : "33MHz"),
953 ((hw
->bus_width
== e1000_bus_width_64
) ? "64-bit" :
954 (hw
->bus_width
== e1000_bus_width_pciex_4
) ? "Width x4" :
955 (hw
->bus_width
== e1000_bus_width_pciex_1
) ? "Width x1" :
959 for (i
= 0; i
< 6; i
++)
960 printk("%2.2x%c", netdev
->dev_addr
[i
], i
== 5 ? '\n' : ':');
962 /* reset the hardware with the new settings */
963 e1000_reset(adapter
);
965 /* If the controller is 82573 and f/w is AMT, do not set
966 * DRV_LOAD until the interface is up. For all other cases,
967 * let the f/w know that the h/w is now under the control
969 if (adapter
->hw
.mac_type
!= e1000_82573
||
970 !e1000_check_mng_mode(&adapter
->hw
))
971 e1000_get_hw_control(adapter
);
973 strcpy(netdev
->name
, "eth%d");
974 if ((err
= register_netdev(netdev
)))
977 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
983 e1000_release_hw_control(adapter
);
985 if (!e1000_check_phy_reset_block(&adapter
->hw
))
986 e1000_phy_hw_reset(&adapter
->hw
);
988 if (adapter
->hw
.flash_address
)
989 iounmap(adapter
->hw
.flash_address
);
991 #ifdef CONFIG_E1000_NAPI
992 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
993 dev_put(&adapter
->polling_netdev
[i
]);
996 kfree(adapter
->tx_ring
);
997 kfree(adapter
->rx_ring
);
998 #ifdef CONFIG_E1000_NAPI
999 kfree(adapter
->polling_netdev
);
1002 iounmap(adapter
->hw
.hw_addr
);
1004 free_netdev(netdev
);
1006 pci_release_regions(pdev
);
1009 pci_disable_device(pdev
);
1014 * e1000_remove - Device Removal Routine
1015 * @pdev: PCI device information struct
1017 * e1000_remove is called by the PCI subsystem to alert the driver
1018 * that it should release a PCI device. The could be caused by a
1019 * Hot-Plug event, or because the driver is going to be removed from
1023 static void __devexit
1024 e1000_remove(struct pci_dev
*pdev
)
1026 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1027 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1029 #ifdef CONFIG_E1000_NAPI
1033 flush_scheduled_work();
1035 if (adapter
->hw
.mac_type
>= e1000_82540
&&
1036 adapter
->hw
.mac_type
!= e1000_ich8lan
&&
1037 adapter
->hw
.media_type
== e1000_media_type_copper
) {
1038 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
1039 if (manc
& E1000_MANC_SMBUS_EN
) {
1040 manc
|= E1000_MANC_ARP_EN
;
1041 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
1045 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1046 * would have already happened in close and is redundant. */
1047 e1000_release_hw_control(adapter
);
1049 unregister_netdev(netdev
);
1050 #ifdef CONFIG_E1000_NAPI
1051 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1052 dev_put(&adapter
->polling_netdev
[i
]);
1055 if (!e1000_check_phy_reset_block(&adapter
->hw
))
1056 e1000_phy_hw_reset(&adapter
->hw
);
1058 kfree(adapter
->tx_ring
);
1059 kfree(adapter
->rx_ring
);
1060 #ifdef CONFIG_E1000_NAPI
1061 kfree(adapter
->polling_netdev
);
1064 iounmap(adapter
->hw
.hw_addr
);
1065 if (adapter
->hw
.flash_address
)
1066 iounmap(adapter
->hw
.flash_address
);
1067 pci_release_regions(pdev
);
1069 free_netdev(netdev
);
1071 pci_disable_device(pdev
);
1075 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1076 * @adapter: board private structure to initialize
1078 * e1000_sw_init initializes the Adapter private data structure.
1079 * Fields are initialized based on PCI device information and
1080 * OS network device settings (MTU size).
1083 static int __devinit
1084 e1000_sw_init(struct e1000_adapter
*adapter
)
1086 struct e1000_hw
*hw
= &adapter
->hw
;
1087 struct net_device
*netdev
= adapter
->netdev
;
1088 struct pci_dev
*pdev
= adapter
->pdev
;
1089 #ifdef CONFIG_E1000_NAPI
1093 /* PCI config space info */
1095 hw
->vendor_id
= pdev
->vendor
;
1096 hw
->device_id
= pdev
->device
;
1097 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
1098 hw
->subsystem_id
= pdev
->subsystem_device
;
1100 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
1102 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
1104 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1105 adapter
->rx_ps_bsize0
= E1000_RXBUFFER_128
;
1106 hw
->max_frame_size
= netdev
->mtu
+
1107 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
1108 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
1110 /* identify the MAC */
1112 if (e1000_set_mac_type(hw
)) {
1113 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
1117 switch (hw
->mac_type
) {
1122 case e1000_82541_rev_2
:
1123 case e1000_82547_rev_2
:
1124 hw
->phy_init_script
= 1;
1128 e1000_set_media_type(hw
);
1130 hw
->wait_autoneg_complete
= FALSE
;
1131 hw
->tbi_compatibility_en
= TRUE
;
1132 hw
->adaptive_ifs
= TRUE
;
1134 /* Copper options */
1136 if (hw
->media_type
== e1000_media_type_copper
) {
1137 hw
->mdix
= AUTO_ALL_MODES
;
1138 hw
->disable_polarity_correction
= FALSE
;
1139 hw
->master_slave
= E1000_MASTER_SLAVE
;
1142 adapter
->num_tx_queues
= 1;
1143 adapter
->num_rx_queues
= 1;
1145 if (e1000_alloc_queues(adapter
)) {
1146 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
1150 #ifdef CONFIG_E1000_NAPI
1151 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1152 adapter
->polling_netdev
[i
].priv
= adapter
;
1153 adapter
->polling_netdev
[i
].poll
= &e1000_clean
;
1154 adapter
->polling_netdev
[i
].weight
= 64;
1155 dev_hold(&adapter
->polling_netdev
[i
]);
1156 set_bit(__LINK_STATE_START
, &adapter
->polling_netdev
[i
].state
);
1158 spin_lock_init(&adapter
->tx_queue_lock
);
1161 atomic_set(&adapter
->irq_sem
, 1);
1162 spin_lock_init(&adapter
->stats_lock
);
1168 * e1000_alloc_queues - Allocate memory for all rings
1169 * @adapter: board private structure to initialize
1171 * We allocate one ring per queue at run-time since we don't know the
1172 * number of queues at compile-time. The polling_netdev array is
1173 * intended for Multiqueue, but should work fine with a single queue.
1176 static int __devinit
1177 e1000_alloc_queues(struct e1000_adapter
*adapter
)
1181 size
= sizeof(struct e1000_tx_ring
) * adapter
->num_tx_queues
;
1182 adapter
->tx_ring
= kmalloc(size
, GFP_KERNEL
);
1183 if (!adapter
->tx_ring
)
1185 memset(adapter
->tx_ring
, 0, size
);
1187 size
= sizeof(struct e1000_rx_ring
) * adapter
->num_rx_queues
;
1188 adapter
->rx_ring
= kmalloc(size
, GFP_KERNEL
);
1189 if (!adapter
->rx_ring
) {
1190 kfree(adapter
->tx_ring
);
1193 memset(adapter
->rx_ring
, 0, size
);
1195 #ifdef CONFIG_E1000_NAPI
1196 size
= sizeof(struct net_device
) * adapter
->num_rx_queues
;
1197 adapter
->polling_netdev
= kmalloc(size
, GFP_KERNEL
);
1198 if (!adapter
->polling_netdev
) {
1199 kfree(adapter
->tx_ring
);
1200 kfree(adapter
->rx_ring
);
1203 memset(adapter
->polling_netdev
, 0, size
);
1206 return E1000_SUCCESS
;
1210 * e1000_open - Called when a network interface is made active
1211 * @netdev: network interface device structure
1213 * Returns 0 on success, negative value on failure
1215 * The open entry point is called when a network interface is made
1216 * active by the system (IFF_UP). At this point all resources needed
1217 * for transmit and receive operations are allocated, the interrupt
1218 * handler is registered with the OS, the watchdog timer is started,
1219 * and the stack is notified that the interface is ready.
1223 e1000_open(struct net_device
*netdev
)
1225 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1228 /* disallow open during test */
1229 if (test_bit(__E1000_DRIVER_TESTING
, &adapter
->flags
))
1232 /* allocate transmit descriptors */
1234 if ((err
= e1000_setup_all_tx_resources(adapter
)))
1237 /* allocate receive descriptors */
1239 if ((err
= e1000_setup_all_rx_resources(adapter
)))
1242 err
= e1000_request_irq(adapter
);
1246 e1000_power_up_phy(adapter
);
1248 if ((err
= e1000_up(adapter
)))
1250 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1251 if ((adapter
->hw
.mng_cookie
.status
&
1252 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1253 e1000_update_mng_vlan(adapter
);
1256 /* If AMT is enabled, let the firmware know that the network
1257 * interface is now open */
1258 if (adapter
->hw
.mac_type
== e1000_82573
&&
1259 e1000_check_mng_mode(&adapter
->hw
))
1260 e1000_get_hw_control(adapter
);
1262 return E1000_SUCCESS
;
1265 e1000_power_down_phy(adapter
);
1266 e1000_free_irq(adapter
);
1268 e1000_free_all_rx_resources(adapter
);
1270 e1000_free_all_tx_resources(adapter
);
1272 e1000_reset(adapter
);
1278 * e1000_close - Disables a network interface
1279 * @netdev: network interface device structure
1281 * Returns 0, this is not allowed to fail
1283 * The close entry point is called when an interface is de-activated
1284 * by the OS. The hardware is still under the drivers control, but
1285 * needs to be disabled. A global MAC reset is issued to stop the
1286 * hardware, and all transmit and receive resources are freed.
1290 e1000_close(struct net_device
*netdev
)
1292 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1294 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
1295 e1000_down(adapter
);
1296 e1000_power_down_phy(adapter
);
1297 e1000_free_irq(adapter
);
1299 e1000_free_all_tx_resources(adapter
);
1300 e1000_free_all_rx_resources(adapter
);
1302 if ((adapter
->hw
.mng_cookie
.status
&
1303 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1304 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1307 /* If AMT is enabled, let the firmware know that the network
1308 * interface is now closed */
1309 if (adapter
->hw
.mac_type
== e1000_82573
&&
1310 e1000_check_mng_mode(&adapter
->hw
))
1311 e1000_release_hw_control(adapter
);
1317 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1318 * @adapter: address of board private structure
1319 * @start: address of beginning of memory
1320 * @len: length of memory
1323 e1000_check_64k_bound(struct e1000_adapter
*adapter
,
1324 void *start
, unsigned long len
)
1326 unsigned long begin
= (unsigned long) start
;
1327 unsigned long end
= begin
+ len
;
1329 /* First rev 82545 and 82546 need to not allow any memory
1330 * write location to cross 64k boundary due to errata 23 */
1331 if (adapter
->hw
.mac_type
== e1000_82545
||
1332 adapter
->hw
.mac_type
== e1000_82546
) {
1333 return ((begin
^ (end
- 1)) >> 16) != 0 ? FALSE
: TRUE
;
1340 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1341 * @adapter: board private structure
1342 * @txdr: tx descriptor ring (for a specific queue) to setup
1344 * Return 0 on success, negative on failure
1348 e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1349 struct e1000_tx_ring
*txdr
)
1351 struct pci_dev
*pdev
= adapter
->pdev
;
1354 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1355 txdr
->buffer_info
= vmalloc(size
);
1356 if (!txdr
->buffer_info
) {
1358 "Unable to allocate memory for the transmit descriptor ring\n");
1361 memset(txdr
->buffer_info
, 0, size
);
1363 /* round up to nearest 4K */
1365 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1366 E1000_ROUNDUP(txdr
->size
, 4096);
1368 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1371 vfree(txdr
->buffer_info
);
1373 "Unable to allocate memory for the transmit descriptor ring\n");
1377 /* Fix for errata 23, can't cross 64kB boundary */
1378 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1379 void *olddesc
= txdr
->desc
;
1380 dma_addr_t olddma
= txdr
->dma
;
1381 DPRINTK(TX_ERR
, ERR
, "txdr align check failed: %u bytes "
1382 "at %p\n", txdr
->size
, txdr
->desc
);
1383 /* Try again, without freeing the previous */
1384 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1385 /* Failed allocation, critical failure */
1387 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1388 goto setup_tx_desc_die
;
1391 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1393 pci_free_consistent(pdev
, txdr
->size
, txdr
->desc
,
1395 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1397 "Unable to allocate aligned memory "
1398 "for the transmit descriptor ring\n");
1399 vfree(txdr
->buffer_info
);
1402 /* Free old allocation, new allocation was successful */
1403 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1406 memset(txdr
->desc
, 0, txdr
->size
);
1408 txdr
->next_to_use
= 0;
1409 txdr
->next_to_clean
= 0;
1410 spin_lock_init(&txdr
->tx_lock
);
1416 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1417 * (Descriptors) for all queues
1418 * @adapter: board private structure
1420 * Return 0 on success, negative on failure
1424 e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1428 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1429 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1432 "Allocation for Tx Queue %u failed\n", i
);
1433 for (i
-- ; i
>= 0; i
--)
1434 e1000_free_tx_resources(adapter
,
1435 &adapter
->tx_ring
[i
]);
1444 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1445 * @adapter: board private structure
1447 * Configure the Tx unit of the MAC after a reset.
1451 e1000_configure_tx(struct e1000_adapter
*adapter
)
1454 struct e1000_hw
*hw
= &adapter
->hw
;
1455 uint32_t tdlen
, tctl
, tipg
, tarc
;
1456 uint32_t ipgr1
, ipgr2
;
1458 /* Setup the HW Tx Head and Tail descriptor pointers */
1460 switch (adapter
->num_tx_queues
) {
1463 tdba
= adapter
->tx_ring
[0].dma
;
1464 tdlen
= adapter
->tx_ring
[0].count
*
1465 sizeof(struct e1000_tx_desc
);
1466 E1000_WRITE_REG(hw
, TDLEN
, tdlen
);
1467 E1000_WRITE_REG(hw
, TDBAH
, (tdba
>> 32));
1468 E1000_WRITE_REG(hw
, TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1469 E1000_WRITE_REG(hw
, TDT
, 0);
1470 E1000_WRITE_REG(hw
, TDH
, 0);
1471 adapter
->tx_ring
[0].tdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDH
: E1000_82542_TDH
);
1472 adapter
->tx_ring
[0].tdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDT
: E1000_82542_TDT
);
1476 /* Set the default values for the Tx Inter Packet Gap timer */
1478 if (hw
->media_type
== e1000_media_type_fiber
||
1479 hw
->media_type
== e1000_media_type_internal_serdes
)
1480 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1482 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1484 switch (hw
->mac_type
) {
1485 case e1000_82542_rev2_0
:
1486 case e1000_82542_rev2_1
:
1487 tipg
= DEFAULT_82542_TIPG_IPGT
;
1488 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
1489 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
1491 case e1000_80003es2lan
:
1492 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1493 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
;
1496 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1497 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
1500 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1501 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1502 E1000_WRITE_REG(hw
, TIPG
, tipg
);
1504 /* Set the Tx Interrupt Delay register */
1506 E1000_WRITE_REG(hw
, TIDV
, adapter
->tx_int_delay
);
1507 if (hw
->mac_type
>= e1000_82540
)
1508 E1000_WRITE_REG(hw
, TADV
, adapter
->tx_abs_int_delay
);
1510 /* Program the Transmit Control Register */
1512 tctl
= E1000_READ_REG(hw
, TCTL
);
1514 tctl
&= ~E1000_TCTL_CT
;
1515 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1516 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1519 /* disable Multiple Reads for debugging */
1520 tctl
&= ~E1000_TCTL_MULR
;
1523 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
1524 tarc
= E1000_READ_REG(hw
, TARC0
);
1525 tarc
|= ((1 << 25) | (1 << 21));
1526 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1527 tarc
= E1000_READ_REG(hw
, TARC1
);
1529 if (tctl
& E1000_TCTL_MULR
)
1533 E1000_WRITE_REG(hw
, TARC1
, tarc
);
1534 } else if (hw
->mac_type
== e1000_80003es2lan
) {
1535 tarc
= E1000_READ_REG(hw
, TARC0
);
1537 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1538 tarc
= E1000_READ_REG(hw
, TARC1
);
1540 E1000_WRITE_REG(hw
, TARC1
, tarc
);
1543 e1000_config_collision_dist(hw
);
1545 /* Setup Transmit Descriptor Settings for eop descriptor */
1546 adapter
->txd_cmd
= E1000_TXD_CMD_IDE
| E1000_TXD_CMD_EOP
|
1549 if (hw
->mac_type
< e1000_82543
)
1550 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1552 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1554 /* Cache if we're 82544 running in PCI-X because we'll
1555 * need this to apply a workaround later in the send path. */
1556 if (hw
->mac_type
== e1000_82544
&&
1557 hw
->bus_type
== e1000_bus_type_pcix
)
1558 adapter
->pcix_82544
= 1;
1560 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1565 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1566 * @adapter: board private structure
1567 * @rxdr: rx descriptor ring (for a specific queue) to setup
1569 * Returns 0 on success, negative on failure
1573 e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1574 struct e1000_rx_ring
*rxdr
)
1576 struct pci_dev
*pdev
= adapter
->pdev
;
1579 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1580 rxdr
->buffer_info
= vmalloc(size
);
1581 if (!rxdr
->buffer_info
) {
1583 "Unable to allocate memory for the receive descriptor ring\n");
1586 memset(rxdr
->buffer_info
, 0, size
);
1588 size
= sizeof(struct e1000_ps_page
) * rxdr
->count
;
1589 rxdr
->ps_page
= kmalloc(size
, GFP_KERNEL
);
1590 if (!rxdr
->ps_page
) {
1591 vfree(rxdr
->buffer_info
);
1593 "Unable to allocate memory for the receive descriptor ring\n");
1596 memset(rxdr
->ps_page
, 0, size
);
1598 size
= sizeof(struct e1000_ps_page_dma
) * rxdr
->count
;
1599 rxdr
->ps_page_dma
= kmalloc(size
, GFP_KERNEL
);
1600 if (!rxdr
->ps_page_dma
) {
1601 vfree(rxdr
->buffer_info
);
1602 kfree(rxdr
->ps_page
);
1604 "Unable to allocate memory for the receive descriptor ring\n");
1607 memset(rxdr
->ps_page_dma
, 0, size
);
1609 if (adapter
->hw
.mac_type
<= e1000_82547_rev_2
)
1610 desc_len
= sizeof(struct e1000_rx_desc
);
1612 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1614 /* Round up to nearest 4K */
1616 rxdr
->size
= rxdr
->count
* desc_len
;
1617 E1000_ROUNDUP(rxdr
->size
, 4096);
1619 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1623 "Unable to allocate memory for the receive descriptor ring\n");
1625 vfree(rxdr
->buffer_info
);
1626 kfree(rxdr
->ps_page
);
1627 kfree(rxdr
->ps_page_dma
);
1631 /* Fix for errata 23, can't cross 64kB boundary */
1632 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1633 void *olddesc
= rxdr
->desc
;
1634 dma_addr_t olddma
= rxdr
->dma
;
1635 DPRINTK(RX_ERR
, ERR
, "rxdr align check failed: %u bytes "
1636 "at %p\n", rxdr
->size
, rxdr
->desc
);
1637 /* Try again, without freeing the previous */
1638 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1639 /* Failed allocation, critical failure */
1641 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1643 "Unable to allocate memory "
1644 "for the receive descriptor ring\n");
1645 goto setup_rx_desc_die
;
1648 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1650 pci_free_consistent(pdev
, rxdr
->size
, rxdr
->desc
,
1652 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1654 "Unable to allocate aligned memory "
1655 "for the receive descriptor ring\n");
1656 goto setup_rx_desc_die
;
1658 /* Free old allocation, new allocation was successful */
1659 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1662 memset(rxdr
->desc
, 0, rxdr
->size
);
1664 rxdr
->next_to_clean
= 0;
1665 rxdr
->next_to_use
= 0;
1671 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1672 * (Descriptors) for all queues
1673 * @adapter: board private structure
1675 * Return 0 on success, negative on failure
1679 e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1683 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1684 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1687 "Allocation for Rx Queue %u failed\n", i
);
1688 for (i
-- ; i
>= 0; i
--)
1689 e1000_free_rx_resources(adapter
,
1690 &adapter
->rx_ring
[i
]);
1699 * e1000_setup_rctl - configure the receive control registers
1700 * @adapter: Board private structure
1702 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1703 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1705 e1000_setup_rctl(struct e1000_adapter
*adapter
)
1707 uint32_t rctl
, rfctl
;
1708 uint32_t psrctl
= 0;
1709 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1713 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1715 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1717 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1718 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1719 (adapter
->hw
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1721 if (adapter
->hw
.tbi_compatibility_on
== 1)
1722 rctl
|= E1000_RCTL_SBP
;
1724 rctl
&= ~E1000_RCTL_SBP
;
1726 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1727 rctl
&= ~E1000_RCTL_LPE
;
1729 rctl
|= E1000_RCTL_LPE
;
1731 /* Setup buffer sizes */
1732 rctl
&= ~E1000_RCTL_SZ_4096
;
1733 rctl
|= E1000_RCTL_BSEX
;
1734 switch (adapter
->rx_buffer_len
) {
1735 case E1000_RXBUFFER_256
:
1736 rctl
|= E1000_RCTL_SZ_256
;
1737 rctl
&= ~E1000_RCTL_BSEX
;
1739 case E1000_RXBUFFER_512
:
1740 rctl
|= E1000_RCTL_SZ_512
;
1741 rctl
&= ~E1000_RCTL_BSEX
;
1743 case E1000_RXBUFFER_1024
:
1744 rctl
|= E1000_RCTL_SZ_1024
;
1745 rctl
&= ~E1000_RCTL_BSEX
;
1747 case E1000_RXBUFFER_2048
:
1749 rctl
|= E1000_RCTL_SZ_2048
;
1750 rctl
&= ~E1000_RCTL_BSEX
;
1752 case E1000_RXBUFFER_4096
:
1753 rctl
|= E1000_RCTL_SZ_4096
;
1755 case E1000_RXBUFFER_8192
:
1756 rctl
|= E1000_RCTL_SZ_8192
;
1758 case E1000_RXBUFFER_16384
:
1759 rctl
|= E1000_RCTL_SZ_16384
;
1763 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1764 /* 82571 and greater support packet-split where the protocol
1765 * header is placed in skb->data and the packet data is
1766 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1767 * In the case of a non-split, skb->data is linearly filled,
1768 * followed by the page buffers. Therefore, skb->data is
1769 * sized to hold the largest protocol header.
1771 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
1772 if ((adapter
->hw
.mac_type
> e1000_82547_rev_2
) && (pages
<= 3) &&
1774 adapter
->rx_ps_pages
= pages
;
1776 adapter
->rx_ps_pages
= 0;
1778 if (adapter
->rx_ps_pages
) {
1779 /* Configure extra packet-split registers */
1780 rfctl
= E1000_READ_REG(&adapter
->hw
, RFCTL
);
1781 rfctl
|= E1000_RFCTL_EXTEN
;
1782 /* disable IPv6 packet split support */
1783 rfctl
|= E1000_RFCTL_IPV6_DIS
;
1784 E1000_WRITE_REG(&adapter
->hw
, RFCTL
, rfctl
);
1786 rctl
|= E1000_RCTL_DTYP_PS
;
1788 psrctl
|= adapter
->rx_ps_bsize0
>>
1789 E1000_PSRCTL_BSIZE0_SHIFT
;
1791 switch (adapter
->rx_ps_pages
) {
1793 psrctl
|= PAGE_SIZE
<<
1794 E1000_PSRCTL_BSIZE3_SHIFT
;
1796 psrctl
|= PAGE_SIZE
<<
1797 E1000_PSRCTL_BSIZE2_SHIFT
;
1799 psrctl
|= PAGE_SIZE
>>
1800 E1000_PSRCTL_BSIZE1_SHIFT
;
1804 E1000_WRITE_REG(&adapter
->hw
, PSRCTL
, psrctl
);
1807 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1811 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1812 * @adapter: board private structure
1814 * Configure the Rx unit of the MAC after a reset.
1818 e1000_configure_rx(struct e1000_adapter
*adapter
)
1821 struct e1000_hw
*hw
= &adapter
->hw
;
1822 uint32_t rdlen
, rctl
, rxcsum
, ctrl_ext
;
1824 if (adapter
->rx_ps_pages
) {
1825 /* this is a 32 byte descriptor */
1826 rdlen
= adapter
->rx_ring
[0].count
*
1827 sizeof(union e1000_rx_desc_packet_split
);
1828 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
1829 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
1831 rdlen
= adapter
->rx_ring
[0].count
*
1832 sizeof(struct e1000_rx_desc
);
1833 adapter
->clean_rx
= e1000_clean_rx_irq
;
1834 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1837 /* disable receives while setting up the descriptors */
1838 rctl
= E1000_READ_REG(hw
, RCTL
);
1839 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
1841 /* set the Receive Delay Timer Register */
1842 E1000_WRITE_REG(hw
, RDTR
, adapter
->rx_int_delay
);
1844 if (hw
->mac_type
>= e1000_82540
) {
1845 E1000_WRITE_REG(hw
, RADV
, adapter
->rx_abs_int_delay
);
1846 if (adapter
->itr
> 1)
1847 E1000_WRITE_REG(hw
, ITR
,
1848 1000000000 / (adapter
->itr
* 256));
1851 if (hw
->mac_type
>= e1000_82571
) {
1852 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1853 /* Reset delay timers after every interrupt */
1854 ctrl_ext
|= E1000_CTRL_EXT_INT_TIMER_CLR
;
1855 #ifdef CONFIG_E1000_NAPI
1856 /* Auto-Mask interrupts upon ICR read. */
1857 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
1859 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
1860 E1000_WRITE_REG(hw
, IAM
, ~0);
1861 E1000_WRITE_FLUSH(hw
);
1864 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1865 * the Base and Length of the Rx Descriptor Ring */
1866 switch (adapter
->num_rx_queues
) {
1869 rdba
= adapter
->rx_ring
[0].dma
;
1870 E1000_WRITE_REG(hw
, RDLEN
, rdlen
);
1871 E1000_WRITE_REG(hw
, RDBAH
, (rdba
>> 32));
1872 E1000_WRITE_REG(hw
, RDBAL
, (rdba
& 0x00000000ffffffffULL
));
1873 E1000_WRITE_REG(hw
, RDT
, 0);
1874 E1000_WRITE_REG(hw
, RDH
, 0);
1875 adapter
->rx_ring
[0].rdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDH
: E1000_82542_RDH
);
1876 adapter
->rx_ring
[0].rdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDT
: E1000_82542_RDT
);
1880 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1881 if (hw
->mac_type
>= e1000_82543
) {
1882 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1883 if (adapter
->rx_csum
== TRUE
) {
1884 rxcsum
|= E1000_RXCSUM_TUOFL
;
1886 /* Enable 82571 IPv4 payload checksum for UDP fragments
1887 * Must be used in conjunction with packet-split. */
1888 if ((hw
->mac_type
>= e1000_82571
) &&
1889 (adapter
->rx_ps_pages
)) {
1890 rxcsum
|= E1000_RXCSUM_IPPCSE
;
1893 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1894 /* don't need to clear IPPCSE as it defaults to 0 */
1896 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1899 /* Enable Receives */
1900 E1000_WRITE_REG(hw
, RCTL
, rctl
);
1904 * e1000_free_tx_resources - Free Tx Resources per Queue
1905 * @adapter: board private structure
1906 * @tx_ring: Tx descriptor ring for a specific queue
1908 * Free all transmit software resources
1912 e1000_free_tx_resources(struct e1000_adapter
*adapter
,
1913 struct e1000_tx_ring
*tx_ring
)
1915 struct pci_dev
*pdev
= adapter
->pdev
;
1917 e1000_clean_tx_ring(adapter
, tx_ring
);
1919 vfree(tx_ring
->buffer_info
);
1920 tx_ring
->buffer_info
= NULL
;
1922 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
1924 tx_ring
->desc
= NULL
;
1928 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1929 * @adapter: board private structure
1931 * Free all transmit software resources
1935 e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
1939 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1940 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1944 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
1945 struct e1000_buffer
*buffer_info
)
1947 if (buffer_info
->dma
) {
1948 pci_unmap_page(adapter
->pdev
,
1950 buffer_info
->length
,
1953 if (buffer_info
->skb
)
1954 dev_kfree_skb_any(buffer_info
->skb
);
1955 memset(buffer_info
, 0, sizeof(struct e1000_buffer
));
1959 * e1000_clean_tx_ring - Free Tx Buffers
1960 * @adapter: board private structure
1961 * @tx_ring: ring to be cleaned
1965 e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
1966 struct e1000_tx_ring
*tx_ring
)
1968 struct e1000_buffer
*buffer_info
;
1972 /* Free all the Tx ring sk_buffs */
1974 for (i
= 0; i
< tx_ring
->count
; i
++) {
1975 buffer_info
= &tx_ring
->buffer_info
[i
];
1976 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
1979 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1980 memset(tx_ring
->buffer_info
, 0, size
);
1982 /* Zero out the descriptor ring */
1984 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1986 tx_ring
->next_to_use
= 0;
1987 tx_ring
->next_to_clean
= 0;
1988 tx_ring
->last_tx_tso
= 0;
1990 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdh
);
1991 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
1995 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1996 * @adapter: board private structure
2000 e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
2004 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2005 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
2009 * e1000_free_rx_resources - Free Rx Resources
2010 * @adapter: board private structure
2011 * @rx_ring: ring to clean the resources from
2013 * Free all receive software resources
2017 e1000_free_rx_resources(struct e1000_adapter
*adapter
,
2018 struct e1000_rx_ring
*rx_ring
)
2020 struct pci_dev
*pdev
= adapter
->pdev
;
2022 e1000_clean_rx_ring(adapter
, rx_ring
);
2024 vfree(rx_ring
->buffer_info
);
2025 rx_ring
->buffer_info
= NULL
;
2026 kfree(rx_ring
->ps_page
);
2027 rx_ring
->ps_page
= NULL
;
2028 kfree(rx_ring
->ps_page_dma
);
2029 rx_ring
->ps_page_dma
= NULL
;
2031 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
2033 rx_ring
->desc
= NULL
;
2037 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2038 * @adapter: board private structure
2040 * Free all receive software resources
2044 e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
2048 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2049 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2053 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2054 * @adapter: board private structure
2055 * @rx_ring: ring to free buffers from
2059 e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
2060 struct e1000_rx_ring
*rx_ring
)
2062 struct e1000_buffer
*buffer_info
;
2063 struct e1000_ps_page
*ps_page
;
2064 struct e1000_ps_page_dma
*ps_page_dma
;
2065 struct pci_dev
*pdev
= adapter
->pdev
;
2069 /* Free all the Rx ring sk_buffs */
2070 for (i
= 0; i
< rx_ring
->count
; i
++) {
2071 buffer_info
= &rx_ring
->buffer_info
[i
];
2072 if (buffer_info
->skb
) {
2073 pci_unmap_single(pdev
,
2075 buffer_info
->length
,
2076 PCI_DMA_FROMDEVICE
);
2078 dev_kfree_skb(buffer_info
->skb
);
2079 buffer_info
->skb
= NULL
;
2081 ps_page
= &rx_ring
->ps_page
[i
];
2082 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2083 for (j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
2084 if (!ps_page
->ps_page
[j
]) break;
2085 pci_unmap_page(pdev
,
2086 ps_page_dma
->ps_page_dma
[j
],
2087 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
2088 ps_page_dma
->ps_page_dma
[j
] = 0;
2089 put_page(ps_page
->ps_page
[j
]);
2090 ps_page
->ps_page
[j
] = NULL
;
2094 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2095 memset(rx_ring
->buffer_info
, 0, size
);
2096 size
= sizeof(struct e1000_ps_page
) * rx_ring
->count
;
2097 memset(rx_ring
->ps_page
, 0, size
);
2098 size
= sizeof(struct e1000_ps_page_dma
) * rx_ring
->count
;
2099 memset(rx_ring
->ps_page_dma
, 0, size
);
2101 /* Zero out the descriptor ring */
2103 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2105 rx_ring
->next_to_clean
= 0;
2106 rx_ring
->next_to_use
= 0;
2108 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdh
);
2109 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
2113 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2114 * @adapter: board private structure
2118 e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2122 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2123 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2126 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2127 * and memory write and invalidate disabled for certain operations
2130 e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2132 struct net_device
*netdev
= adapter
->netdev
;
2135 e1000_pci_clear_mwi(&adapter
->hw
);
2137 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2138 rctl
|= E1000_RCTL_RST
;
2139 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2140 E1000_WRITE_FLUSH(&adapter
->hw
);
2143 if (netif_running(netdev
))
2144 e1000_clean_all_rx_rings(adapter
);
2148 e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2150 struct net_device
*netdev
= adapter
->netdev
;
2153 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2154 rctl
&= ~E1000_RCTL_RST
;
2155 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2156 E1000_WRITE_FLUSH(&adapter
->hw
);
2159 if (adapter
->hw
.pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2160 e1000_pci_set_mwi(&adapter
->hw
);
2162 if (netif_running(netdev
)) {
2163 /* No need to loop, because 82542 supports only 1 queue */
2164 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[0];
2165 e1000_configure_rx(adapter
);
2166 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
2171 * e1000_set_mac - Change the Ethernet Address of the NIC
2172 * @netdev: network interface device structure
2173 * @p: pointer to an address structure
2175 * Returns 0 on success, negative on failure
2179 e1000_set_mac(struct net_device
*netdev
, void *p
)
2181 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2182 struct sockaddr
*addr
= p
;
2184 if (!is_valid_ether_addr(addr
->sa_data
))
2185 return -EADDRNOTAVAIL
;
2187 /* 82542 2.0 needs to be in reset to write receive address registers */
2189 if (adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2190 e1000_enter_82542_rst(adapter
);
2192 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2193 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2195 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2197 /* With 82571 controllers, LAA may be overwritten (with the default)
2198 * due to controller reset from the other port. */
2199 if (adapter
->hw
.mac_type
== e1000_82571
) {
2200 /* activate the work around */
2201 adapter
->hw
.laa_is_present
= 1;
2203 /* Hold a copy of the LAA in RAR[14] This is done so that
2204 * between the time RAR[0] gets clobbered and the time it
2205 * gets fixed (in e1000_watchdog), the actual LAA is in one
2206 * of the RARs and no incoming packets directed to this port
2207 * are dropped. Eventaully the LAA will be in RAR[0] and
2209 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
,
2210 E1000_RAR_ENTRIES
- 1);
2213 if (adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2214 e1000_leave_82542_rst(adapter
);
2220 * e1000_set_multi - Multicast and Promiscuous mode set
2221 * @netdev: network interface device structure
2223 * The set_multi entry point is called whenever the multicast address
2224 * list or the network interface flags are updated. This routine is
2225 * responsible for configuring the hardware for proper multicast,
2226 * promiscuous mode, and all-multi behavior.
2230 e1000_set_multi(struct net_device
*netdev
)
2232 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2233 struct e1000_hw
*hw
= &adapter
->hw
;
2234 struct dev_mc_list
*mc_ptr
;
2236 uint32_t hash_value
;
2237 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2238 int mta_reg_count
= (hw
->mac_type
== e1000_ich8lan
) ?
2239 E1000_NUM_MTA_REGISTERS_ICH8LAN
:
2240 E1000_NUM_MTA_REGISTERS
;
2242 if (adapter
->hw
.mac_type
== e1000_ich8lan
)
2243 rar_entries
= E1000_RAR_ENTRIES_ICH8LAN
;
2245 /* reserve RAR[14] for LAA over-write work-around */
2246 if (adapter
->hw
.mac_type
== e1000_82571
)
2249 /* Check for Promiscuous and All Multicast modes */
2251 rctl
= E1000_READ_REG(hw
, RCTL
);
2253 if (netdev
->flags
& IFF_PROMISC
) {
2254 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2255 } else if (netdev
->flags
& IFF_ALLMULTI
) {
2256 rctl
|= E1000_RCTL_MPE
;
2257 rctl
&= ~E1000_RCTL_UPE
;
2259 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2262 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2264 /* 82542 2.0 needs to be in reset to write receive address registers */
2266 if (hw
->mac_type
== e1000_82542_rev2_0
)
2267 e1000_enter_82542_rst(adapter
);
2269 /* load the first 14 multicast address into the exact filters 1-14
2270 * RAR 0 is used for the station MAC adddress
2271 * if there are not 14 addresses, go ahead and clear the filters
2272 * -- with 82571 controllers only 0-13 entries are filled here
2274 mc_ptr
= netdev
->mc_list
;
2276 for (i
= 1; i
< rar_entries
; i
++) {
2278 e1000_rar_set(hw
, mc_ptr
->dmi_addr
, i
);
2279 mc_ptr
= mc_ptr
->next
;
2281 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2282 E1000_WRITE_FLUSH(hw
);
2283 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2284 E1000_WRITE_FLUSH(hw
);
2288 /* clear the old settings from the multicast hash table */
2290 for (i
= 0; i
< mta_reg_count
; i
++) {
2291 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
2292 E1000_WRITE_FLUSH(hw
);
2295 /* load any remaining addresses into the hash table */
2297 for (; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
2298 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->dmi_addr
);
2299 e1000_mta_set(hw
, hash_value
);
2302 if (hw
->mac_type
== e1000_82542_rev2_0
)
2303 e1000_leave_82542_rst(adapter
);
2306 /* Need to wait a few seconds after link up to get diagnostic information from
2310 e1000_update_phy_info(unsigned long data
)
2312 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2313 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
2317 * e1000_82547_tx_fifo_stall - Timer Call-back
2318 * @data: pointer to adapter cast into an unsigned long
2322 e1000_82547_tx_fifo_stall(unsigned long data
)
2324 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2325 struct net_device
*netdev
= adapter
->netdev
;
2328 if (atomic_read(&adapter
->tx_fifo_stall
)) {
2329 if ((E1000_READ_REG(&adapter
->hw
, TDT
) ==
2330 E1000_READ_REG(&adapter
->hw
, TDH
)) &&
2331 (E1000_READ_REG(&adapter
->hw
, TDFT
) ==
2332 E1000_READ_REG(&adapter
->hw
, TDFH
)) &&
2333 (E1000_READ_REG(&adapter
->hw
, TDFTS
) ==
2334 E1000_READ_REG(&adapter
->hw
, TDFHS
))) {
2335 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2336 E1000_WRITE_REG(&adapter
->hw
, TCTL
,
2337 tctl
& ~E1000_TCTL_EN
);
2338 E1000_WRITE_REG(&adapter
->hw
, TDFT
,
2339 adapter
->tx_head_addr
);
2340 E1000_WRITE_REG(&adapter
->hw
, TDFH
,
2341 adapter
->tx_head_addr
);
2342 E1000_WRITE_REG(&adapter
->hw
, TDFTS
,
2343 adapter
->tx_head_addr
);
2344 E1000_WRITE_REG(&adapter
->hw
, TDFHS
,
2345 adapter
->tx_head_addr
);
2346 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2347 E1000_WRITE_FLUSH(&adapter
->hw
);
2349 adapter
->tx_fifo_head
= 0;
2350 atomic_set(&adapter
->tx_fifo_stall
, 0);
2351 netif_wake_queue(netdev
);
2353 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2359 * e1000_watchdog - Timer Call-back
2360 * @data: pointer to adapter cast into an unsigned long
2363 e1000_watchdog(unsigned long data
)
2365 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2366 struct net_device
*netdev
= adapter
->netdev
;
2367 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2368 uint32_t link
, tctl
;
2371 ret_val
= e1000_check_for_link(&adapter
->hw
);
2372 if ((ret_val
== E1000_ERR_PHY
) &&
2373 (adapter
->hw
.phy_type
== e1000_phy_igp_3
) &&
2374 (E1000_READ_REG(&adapter
->hw
, CTRL
) & E1000_PHY_CTRL_GBE_DISABLE
)) {
2375 /* See e1000_kumeran_lock_loss_workaround() */
2377 "Gigabit has been disabled, downgrading speed\n");
2379 if (adapter
->hw
.mac_type
== e1000_82573
) {
2380 e1000_enable_tx_pkt_filtering(&adapter
->hw
);
2381 if (adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
)
2382 e1000_update_mng_vlan(adapter
);
2385 if ((adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) &&
2386 !(E1000_READ_REG(&adapter
->hw
, TXCW
) & E1000_TXCW_ANE
))
2387 link
= !adapter
->hw
.serdes_link_down
;
2389 link
= E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_LU
;
2392 if (!netif_carrier_ok(netdev
)) {
2393 boolean_t txb2b
= 1;
2394 e1000_get_speed_and_duplex(&adapter
->hw
,
2395 &adapter
->link_speed
,
2396 &adapter
->link_duplex
);
2398 DPRINTK(LINK
, INFO
, "NIC Link is Up %d Mbps %s\n",
2399 adapter
->link_speed
,
2400 adapter
->link_duplex
== FULL_DUPLEX
?
2401 "Full Duplex" : "Half Duplex");
2403 /* tweak tx_queue_len according to speed/duplex
2404 * and adjust the timeout factor */
2405 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2406 adapter
->tx_timeout_factor
= 1;
2407 switch (adapter
->link_speed
) {
2410 netdev
->tx_queue_len
= 10;
2411 adapter
->tx_timeout_factor
= 8;
2415 netdev
->tx_queue_len
= 100;
2416 /* maybe add some timeout factor ? */
2420 if ((adapter
->hw
.mac_type
== e1000_82571
||
2421 adapter
->hw
.mac_type
== e1000_82572
) &&
2423 #define SPEED_MODE_BIT (1 << 21)
2425 tarc0
= E1000_READ_REG(&adapter
->hw
, TARC0
);
2426 tarc0
&= ~SPEED_MODE_BIT
;
2427 E1000_WRITE_REG(&adapter
->hw
, TARC0
, tarc0
);
2431 /* disable TSO for pcie and 10/100 speeds, to avoid
2432 * some hardware issues */
2433 if (!adapter
->tso_force
&&
2434 adapter
->hw
.bus_type
== e1000_bus_type_pci_express
){
2435 switch (adapter
->link_speed
) {
2439 "10/100 speed: disabling TSO\n");
2440 netdev
->features
&= ~NETIF_F_TSO
;
2443 netdev
->features
|= NETIF_F_TSO
;
2452 /* enable transmits in the hardware, need to do this
2453 * after setting TARC0 */
2454 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2455 tctl
|= E1000_TCTL_EN
;
2456 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2458 netif_carrier_on(netdev
);
2459 netif_wake_queue(netdev
);
2460 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2461 adapter
->smartspeed
= 0;
2464 if (netif_carrier_ok(netdev
)) {
2465 adapter
->link_speed
= 0;
2466 adapter
->link_duplex
= 0;
2467 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
2468 netif_carrier_off(netdev
);
2469 netif_stop_queue(netdev
);
2470 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2472 /* 80003ES2LAN workaround--
2473 * For packet buffer work-around on link down event;
2474 * disable receives in the ISR and
2475 * reset device here in the watchdog
2477 if (adapter
->hw
.mac_type
== e1000_80003es2lan
)
2479 schedule_work(&adapter
->reset_task
);
2482 e1000_smartspeed(adapter
);
2485 e1000_update_stats(adapter
);
2487 adapter
->hw
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2488 adapter
->tpt_old
= adapter
->stats
.tpt
;
2489 adapter
->hw
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2490 adapter
->colc_old
= adapter
->stats
.colc
;
2492 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2493 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2494 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2495 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2497 e1000_update_adaptive(&adapter
->hw
);
2499 if (!netif_carrier_ok(netdev
)) {
2500 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2501 /* We've lost link, so the controller stops DMA,
2502 * but we've got queued Tx work that's never going
2503 * to get done, so reset controller to flush Tx.
2504 * (Do the reset outside of interrupt context). */
2505 adapter
->tx_timeout_count
++;
2506 schedule_work(&adapter
->reset_task
);
2510 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2511 if (adapter
->hw
.mac_type
>= e1000_82540
&& adapter
->itr
== 1) {
2512 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2513 * asymmetrical Tx or Rx gets ITR=8000; everyone
2514 * else is between 2000-8000. */
2515 uint32_t goc
= (adapter
->gotcl
+ adapter
->gorcl
) / 10000;
2516 uint32_t dif
= (adapter
->gotcl
> adapter
->gorcl
?
2517 adapter
->gotcl
- adapter
->gorcl
:
2518 adapter
->gorcl
- adapter
->gotcl
) / 10000;
2519 uint32_t itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
2520 E1000_WRITE_REG(&adapter
->hw
, ITR
, 1000000000 / (itr
* 256));
2523 /* Cause software interrupt to ensure rx ring is cleaned */
2524 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_RXDMT0
);
2526 /* Force detection of hung controller every watchdog period */
2527 adapter
->detect_tx_hung
= TRUE
;
2529 /* With 82571 controllers, LAA may be overwritten due to controller
2530 * reset from the other port. Set the appropriate LAA in RAR[0] */
2531 if (adapter
->hw
.mac_type
== e1000_82571
&& adapter
->hw
.laa_is_present
)
2532 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2534 /* Reset the timer */
2535 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2 * HZ
);
2538 #define E1000_TX_FLAGS_CSUM 0x00000001
2539 #define E1000_TX_FLAGS_VLAN 0x00000002
2540 #define E1000_TX_FLAGS_TSO 0x00000004
2541 #define E1000_TX_FLAGS_IPV4 0x00000008
2542 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2543 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2546 e1000_tso(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2547 struct sk_buff
*skb
)
2550 struct e1000_context_desc
*context_desc
;
2551 struct e1000_buffer
*buffer_info
;
2553 uint32_t cmd_length
= 0;
2554 uint16_t ipcse
= 0, tucse
, mss
;
2555 uint8_t ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2558 if (skb_is_gso(skb
)) {
2559 if (skb_header_cloned(skb
)) {
2560 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2565 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2566 mss
= skb_shinfo(skb
)->gso_size
;
2567 if (skb
->protocol
== htons(ETH_P_IP
)) {
2568 skb
->nh
.iph
->tot_len
= 0;
2569 skb
->nh
.iph
->check
= 0;
2571 ~csum_tcpudp_magic(skb
->nh
.iph
->saddr
,
2576 cmd_length
= E1000_TXD_CMD_IP
;
2577 ipcse
= skb
->h
.raw
- skb
->data
- 1;
2578 #ifdef NETIF_F_TSO_IPV6
2579 } else if (skb
->protocol
== htons(ETH_P_IPV6
)) {
2580 skb
->nh
.ipv6h
->payload_len
= 0;
2582 ~csum_ipv6_magic(&skb
->nh
.ipv6h
->saddr
,
2583 &skb
->nh
.ipv6h
->daddr
,
2590 ipcss
= skb
->nh
.raw
- skb
->data
;
2591 ipcso
= (void *)&(skb
->nh
.iph
->check
) - (void *)skb
->data
;
2592 tucss
= skb
->h
.raw
- skb
->data
;
2593 tucso
= (void *)&(skb
->h
.th
->check
) - (void *)skb
->data
;
2596 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2597 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2599 i
= tx_ring
->next_to_use
;
2600 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2601 buffer_info
= &tx_ring
->buffer_info
[i
];
2603 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2604 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2605 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2606 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2607 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2608 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2609 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2610 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2611 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2613 buffer_info
->time_stamp
= jiffies
;
2615 if (++i
== tx_ring
->count
) i
= 0;
2616 tx_ring
->next_to_use
= i
;
2626 e1000_tx_csum(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2627 struct sk_buff
*skb
)
2629 struct e1000_context_desc
*context_desc
;
2630 struct e1000_buffer
*buffer_info
;
2634 if (likely(skb
->ip_summed
== CHECKSUM_PARTIAL
)) {
2635 css
= skb
->h
.raw
- skb
->data
;
2637 i
= tx_ring
->next_to_use
;
2638 buffer_info
= &tx_ring
->buffer_info
[i
];
2639 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2641 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2642 context_desc
->upper_setup
.tcp_fields
.tucso
= css
+ skb
->csum
;
2643 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2644 context_desc
->tcp_seg_setup
.data
= 0;
2645 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
2647 buffer_info
->time_stamp
= jiffies
;
2649 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2650 tx_ring
->next_to_use
= i
;
2658 #define E1000_MAX_TXD_PWR 12
2659 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2662 e1000_tx_map(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2663 struct sk_buff
*skb
, unsigned int first
, unsigned int max_per_txd
,
2664 unsigned int nr_frags
, unsigned int mss
)
2666 struct e1000_buffer
*buffer_info
;
2667 unsigned int len
= skb
->len
;
2668 unsigned int offset
= 0, size
, count
= 0, i
;
2670 len
-= skb
->data_len
;
2672 i
= tx_ring
->next_to_use
;
2675 buffer_info
= &tx_ring
->buffer_info
[i
];
2676 size
= min(len
, max_per_txd
);
2678 /* Workaround for Controller erratum --
2679 * descriptor for non-tso packet in a linear SKB that follows a
2680 * tso gets written back prematurely before the data is fully
2681 * DMA'd to the controller */
2682 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2684 tx_ring
->last_tx_tso
= 0;
2688 /* Workaround for premature desc write-backs
2689 * in TSO mode. Append 4-byte sentinel desc */
2690 if (unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
2693 /* work-around for errata 10 and it applies
2694 * to all controllers in PCI-X mode
2695 * The fix is to make sure that the first descriptor of a
2696 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2698 if (unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2699 (size
> 2015) && count
== 0))
2702 /* Workaround for potential 82544 hang in PCI-X. Avoid
2703 * terminating buffers within evenly-aligned dwords. */
2704 if (unlikely(adapter
->pcix_82544
&&
2705 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
2709 buffer_info
->length
= size
;
2711 pci_map_single(adapter
->pdev
,
2715 buffer_info
->time_stamp
= jiffies
;
2720 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2723 for (f
= 0; f
< nr_frags
; f
++) {
2724 struct skb_frag_struct
*frag
;
2726 frag
= &skb_shinfo(skb
)->frags
[f
];
2728 offset
= frag
->page_offset
;
2731 buffer_info
= &tx_ring
->buffer_info
[i
];
2732 size
= min(len
, max_per_txd
);
2734 /* Workaround for premature desc write-backs
2735 * in TSO mode. Append 4-byte sentinel desc */
2736 if (unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
2739 /* Workaround for potential 82544 hang in PCI-X.
2740 * Avoid terminating buffers within evenly-aligned
2742 if (unlikely(adapter
->pcix_82544
&&
2743 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
2747 buffer_info
->length
= size
;
2749 pci_map_page(adapter
->pdev
,
2754 buffer_info
->time_stamp
= jiffies
;
2759 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2763 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
2764 tx_ring
->buffer_info
[i
].skb
= skb
;
2765 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
2771 e1000_tx_queue(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2772 int tx_flags
, int count
)
2774 struct e1000_tx_desc
*tx_desc
= NULL
;
2775 struct e1000_buffer
*buffer_info
;
2776 uint32_t txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
2779 if (likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
2780 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
2782 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2784 if (likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
2785 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
2788 if (likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
2789 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
2790 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2793 if (unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
2794 txd_lower
|= E1000_TXD_CMD_VLE
;
2795 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
2798 i
= tx_ring
->next_to_use
;
2801 buffer_info
= &tx_ring
->buffer_info
[i
];
2802 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
2803 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2804 tx_desc
->lower
.data
=
2805 cpu_to_le32(txd_lower
| buffer_info
->length
);
2806 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
2807 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2810 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
2812 /* Force memory writes to complete before letting h/w
2813 * know there are new descriptors to fetch. (Only
2814 * applicable for weak-ordered memory model archs,
2815 * such as IA-64). */
2818 tx_ring
->next_to_use
= i
;
2819 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
2823 * 82547 workaround to avoid controller hang in half-duplex environment.
2824 * The workaround is to avoid queuing a large packet that would span
2825 * the internal Tx FIFO ring boundary by notifying the stack to resend
2826 * the packet at a later time. This gives the Tx FIFO an opportunity to
2827 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2828 * to the beginning of the Tx FIFO.
2831 #define E1000_FIFO_HDR 0x10
2832 #define E1000_82547_PAD_LEN 0x3E0
2835 e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2837 uint32_t fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
2838 uint32_t skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
2840 E1000_ROUNDUP(skb_fifo_len
, E1000_FIFO_HDR
);
2842 if (adapter
->link_duplex
!= HALF_DUPLEX
)
2843 goto no_fifo_stall_required
;
2845 if (atomic_read(&adapter
->tx_fifo_stall
))
2848 if (skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
2849 atomic_set(&adapter
->tx_fifo_stall
, 1);
2853 no_fifo_stall_required
:
2854 adapter
->tx_fifo_head
+= skb_fifo_len
;
2855 if (adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
2856 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
2860 #define MINIMUM_DHCP_PACKET_SIZE 282
2862 e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2864 struct e1000_hw
*hw
= &adapter
->hw
;
2865 uint16_t length
, offset
;
2866 if (vlan_tx_tag_present(skb
)) {
2867 if (!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
2868 ( adapter
->hw
.mng_cookie
.status
&
2869 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) )
2872 if (skb
->len
> MINIMUM_DHCP_PACKET_SIZE
) {
2873 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
2874 if ((htons(ETH_P_IP
) == eth
->h_proto
)) {
2875 const struct iphdr
*ip
=
2876 (struct iphdr
*)((uint8_t *)skb
->data
+14);
2877 if (IPPROTO_UDP
== ip
->protocol
) {
2878 struct udphdr
*udp
=
2879 (struct udphdr
*)((uint8_t *)ip
+
2881 if (ntohs(udp
->dest
) == 67) {
2882 offset
= (uint8_t *)udp
+ 8 - skb
->data
;
2883 length
= skb
->len
- offset
;
2885 return e1000_mng_write_dhcp_info(hw
,
2895 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2897 e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2899 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2900 struct e1000_tx_ring
*tx_ring
;
2901 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
2902 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
2903 unsigned int tx_flags
= 0;
2904 unsigned int len
= skb
->len
;
2905 unsigned long flags
;
2906 unsigned int nr_frags
= 0;
2907 unsigned int mss
= 0;
2911 len
-= skb
->data_len
;
2913 tx_ring
= adapter
->tx_ring
;
2915 if (unlikely(skb
->len
<= 0)) {
2916 dev_kfree_skb_any(skb
);
2917 return NETDEV_TX_OK
;
2921 mss
= skb_shinfo(skb
)->gso_size
;
2922 /* The controller does a simple calculation to
2923 * make sure there is enough room in the FIFO before
2924 * initiating the DMA for each buffer. The calc is:
2925 * 4 = ceil(buffer len/mss). To make sure we don't
2926 * overrun the FIFO, adjust the max buffer len if mss
2930 max_per_txd
= min(mss
<< 2, max_per_txd
);
2931 max_txd_pwr
= fls(max_per_txd
) - 1;
2933 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
2934 * points to just header, pull a few bytes of payload from
2935 * frags into skb->data */
2936 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2937 if (skb
->data_len
&& (hdr_len
== (skb
->len
- skb
->data_len
))) {
2938 switch (adapter
->hw
.mac_type
) {
2939 unsigned int pull_size
;
2944 pull_size
= min((unsigned int)4, skb
->data_len
);
2945 if (!__pskb_pull_tail(skb
, pull_size
)) {
2947 "__pskb_pull_tail failed.\n");
2948 dev_kfree_skb_any(skb
);
2949 return NETDEV_TX_OK
;
2951 len
= skb
->len
- skb
->data_len
;
2960 /* reserve a descriptor for the offload context */
2961 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
2965 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2970 /* Controller Erratum workaround */
2971 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&& !skb_is_gso(skb
))
2975 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
2977 if (adapter
->pcix_82544
)
2980 /* work-around for errata 10 and it applies to all controllers
2981 * in PCI-X mode, so add one more descriptor to the count
2983 if (unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2987 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2988 for (f
= 0; f
< nr_frags
; f
++)
2989 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
2991 if (adapter
->pcix_82544
)
2995 if (adapter
->hw
.tx_pkt_filtering
&&
2996 (adapter
->hw
.mac_type
== e1000_82573
))
2997 e1000_transfer_dhcp_info(adapter
, skb
);
2999 local_irq_save(flags
);
3000 if (!spin_trylock(&tx_ring
->tx_lock
)) {
3001 /* Collision - tell upper layer to requeue */
3002 local_irq_restore(flags
);
3003 return NETDEV_TX_LOCKED
;
3006 /* need: count + 2 desc gap to keep tail from touching
3007 * head, otherwise try next time */
3008 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < count
+ 2)) {
3009 netif_stop_queue(netdev
);
3010 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3011 return NETDEV_TX_BUSY
;
3014 if (unlikely(adapter
->hw
.mac_type
== e1000_82547
)) {
3015 if (unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
3016 netif_stop_queue(netdev
);
3017 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
);
3018 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3019 return NETDEV_TX_BUSY
;
3023 if (unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
3024 tx_flags
|= E1000_TX_FLAGS_VLAN
;
3025 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
3028 first
= tx_ring
->next_to_use
;
3030 tso
= e1000_tso(adapter
, tx_ring
, skb
);
3032 dev_kfree_skb_any(skb
);
3033 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3034 return NETDEV_TX_OK
;
3038 tx_ring
->last_tx_tso
= 1;
3039 tx_flags
|= E1000_TX_FLAGS_TSO
;
3040 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
3041 tx_flags
|= E1000_TX_FLAGS_CSUM
;
3043 /* Old method was to assume IPv4 packet by default if TSO was enabled.
3044 * 82571 hardware supports TSO capabilities for IPv6 as well...
3045 * no longer assume, we must. */
3046 if (likely(skb
->protocol
== htons(ETH_P_IP
)))
3047 tx_flags
|= E1000_TX_FLAGS_IPV4
;
3049 e1000_tx_queue(adapter
, tx_ring
, tx_flags
,
3050 e1000_tx_map(adapter
, tx_ring
, skb
, first
,
3051 max_per_txd
, nr_frags
, mss
));
3053 netdev
->trans_start
= jiffies
;
3055 /* Make sure there is space in the ring for the next send. */
3056 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < MAX_SKB_FRAGS
+ 2))
3057 netif_stop_queue(netdev
);
3059 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
3060 return NETDEV_TX_OK
;
3064 * e1000_tx_timeout - Respond to a Tx Hang
3065 * @netdev: network interface device structure
3069 e1000_tx_timeout(struct net_device
*netdev
)
3071 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3073 /* Do the reset outside of interrupt context */
3074 adapter
->tx_timeout_count
++;
3075 schedule_work(&adapter
->reset_task
);
3079 e1000_reset_task(struct net_device
*netdev
)
3081 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3083 e1000_reinit_locked(adapter
);
3087 * e1000_get_stats - Get System Network Statistics
3088 * @netdev: network interface device structure
3090 * Returns the address of the device statistics structure.
3091 * The statistics are actually updated from the timer callback.
3094 static struct net_device_stats
*
3095 e1000_get_stats(struct net_device
*netdev
)
3097 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3099 /* only return the current stats */
3100 return &adapter
->net_stats
;
3104 * e1000_change_mtu - Change the Maximum Transfer Unit
3105 * @netdev: network interface device structure
3106 * @new_mtu: new value for maximum frame size
3108 * Returns 0 on success, negative on failure
3112 e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3114 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3115 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
3116 uint16_t eeprom_data
= 0;
3118 if ((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
3119 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3120 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
3124 /* Adapter-specific max frame size limits. */
3125 switch (adapter
->hw
.mac_type
) {
3126 case e1000_undefined
... e1000_82542_rev2_1
:
3128 if (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3129 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported.\n");
3134 /* only enable jumbo frames if ASPM is disabled completely
3135 * this means both bits must be zero in 0x1A bits 3:2 */
3136 e1000_read_eeprom(&adapter
->hw
, EEPROM_INIT_3GIO_3
, 1,
3138 if (eeprom_data
& EEPROM_WORD1A_ASPM_MASK
) {
3139 if (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3141 "Jumbo Frames not supported.\n");
3146 /* fall through to get support */
3149 case e1000_80003es2lan
:
3150 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3151 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3152 DPRINTK(PROBE
, ERR
, "MTU > 9216 not supported.\n");
3157 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3161 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3162 * means we reserve 2 more, this pushes us to allocate from the next
3164 * i.e. RXBUFFER_2048 --> size-4096 slab */
3166 if (max_frame
<= E1000_RXBUFFER_256
)
3167 adapter
->rx_buffer_len
= E1000_RXBUFFER_256
;
3168 else if (max_frame
<= E1000_RXBUFFER_512
)
3169 adapter
->rx_buffer_len
= E1000_RXBUFFER_512
;
3170 else if (max_frame
<= E1000_RXBUFFER_1024
)
3171 adapter
->rx_buffer_len
= E1000_RXBUFFER_1024
;
3172 else if (max_frame
<= E1000_RXBUFFER_2048
)
3173 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3174 else if (max_frame
<= E1000_RXBUFFER_4096
)
3175 adapter
->rx_buffer_len
= E1000_RXBUFFER_4096
;
3176 else if (max_frame
<= E1000_RXBUFFER_8192
)
3177 adapter
->rx_buffer_len
= E1000_RXBUFFER_8192
;
3178 else if (max_frame
<= E1000_RXBUFFER_16384
)
3179 adapter
->rx_buffer_len
= E1000_RXBUFFER_16384
;
3181 /* adjust allocation if LPE protects us, and we aren't using SBP */
3182 if (!adapter
->hw
.tbi_compatibility_on
&&
3183 ((max_frame
== MAXIMUM_ETHERNET_FRAME_SIZE
) ||
3184 (max_frame
== MAXIMUM_ETHERNET_VLAN_SIZE
)))
3185 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3187 netdev
->mtu
= new_mtu
;
3189 if (netif_running(netdev
))
3190 e1000_reinit_locked(adapter
);
3192 adapter
->hw
.max_frame_size
= max_frame
;
3198 * e1000_update_stats - Update the board statistics counters
3199 * @adapter: board private structure
3203 e1000_update_stats(struct e1000_adapter
*adapter
)
3205 struct e1000_hw
*hw
= &adapter
->hw
;
3206 struct pci_dev
*pdev
= adapter
->pdev
;
3207 unsigned long flags
;
3210 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3213 * Prevent stats update while adapter is being reset, or if the pci
3214 * connection is down.
3216 if (adapter
->link_speed
== 0)
3218 if (pdev
->error_state
&& pdev
->error_state
!= pci_channel_io_normal
)
3221 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3223 /* these counters are modified from e1000_adjust_tbi_stats,
3224 * called from the interrupt context, so they must only
3225 * be written while holding adapter->stats_lock
3228 adapter
->stats
.crcerrs
+= E1000_READ_REG(hw
, CRCERRS
);
3229 adapter
->stats
.gprc
+= E1000_READ_REG(hw
, GPRC
);
3230 adapter
->stats
.gorcl
+= E1000_READ_REG(hw
, GORCL
);
3231 adapter
->stats
.gorch
+= E1000_READ_REG(hw
, GORCH
);
3232 adapter
->stats
.bprc
+= E1000_READ_REG(hw
, BPRC
);
3233 adapter
->stats
.mprc
+= E1000_READ_REG(hw
, MPRC
);
3234 adapter
->stats
.roc
+= E1000_READ_REG(hw
, ROC
);
3236 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
3237 adapter
->stats
.prc64
+= E1000_READ_REG(hw
, PRC64
);
3238 adapter
->stats
.prc127
+= E1000_READ_REG(hw
, PRC127
);
3239 adapter
->stats
.prc255
+= E1000_READ_REG(hw
, PRC255
);
3240 adapter
->stats
.prc511
+= E1000_READ_REG(hw
, PRC511
);
3241 adapter
->stats
.prc1023
+= E1000_READ_REG(hw
, PRC1023
);
3242 adapter
->stats
.prc1522
+= E1000_READ_REG(hw
, PRC1522
);
3245 adapter
->stats
.symerrs
+= E1000_READ_REG(hw
, SYMERRS
);
3246 adapter
->stats
.mpc
+= E1000_READ_REG(hw
, MPC
);
3247 adapter
->stats
.scc
+= E1000_READ_REG(hw
, SCC
);
3248 adapter
->stats
.ecol
+= E1000_READ_REG(hw
, ECOL
);
3249 adapter
->stats
.mcc
+= E1000_READ_REG(hw
, MCC
);
3250 adapter
->stats
.latecol
+= E1000_READ_REG(hw
, LATECOL
);
3251 adapter
->stats
.dc
+= E1000_READ_REG(hw
, DC
);
3252 adapter
->stats
.sec
+= E1000_READ_REG(hw
, SEC
);
3253 adapter
->stats
.rlec
+= E1000_READ_REG(hw
, RLEC
);
3254 adapter
->stats
.xonrxc
+= E1000_READ_REG(hw
, XONRXC
);
3255 adapter
->stats
.xontxc
+= E1000_READ_REG(hw
, XONTXC
);
3256 adapter
->stats
.xoffrxc
+= E1000_READ_REG(hw
, XOFFRXC
);
3257 adapter
->stats
.xofftxc
+= E1000_READ_REG(hw
, XOFFTXC
);
3258 adapter
->stats
.fcruc
+= E1000_READ_REG(hw
, FCRUC
);
3259 adapter
->stats
.gptc
+= E1000_READ_REG(hw
, GPTC
);
3260 adapter
->stats
.gotcl
+= E1000_READ_REG(hw
, GOTCL
);
3261 adapter
->stats
.gotch
+= E1000_READ_REG(hw
, GOTCH
);
3262 adapter
->stats
.rnbc
+= E1000_READ_REG(hw
, RNBC
);
3263 adapter
->stats
.ruc
+= E1000_READ_REG(hw
, RUC
);
3264 adapter
->stats
.rfc
+= E1000_READ_REG(hw
, RFC
);
3265 adapter
->stats
.rjc
+= E1000_READ_REG(hw
, RJC
);
3266 adapter
->stats
.torl
+= E1000_READ_REG(hw
, TORL
);
3267 adapter
->stats
.torh
+= E1000_READ_REG(hw
, TORH
);
3268 adapter
->stats
.totl
+= E1000_READ_REG(hw
, TOTL
);
3269 adapter
->stats
.toth
+= E1000_READ_REG(hw
, TOTH
);
3270 adapter
->stats
.tpr
+= E1000_READ_REG(hw
, TPR
);
3272 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
3273 adapter
->stats
.ptc64
+= E1000_READ_REG(hw
, PTC64
);
3274 adapter
->stats
.ptc127
+= E1000_READ_REG(hw
, PTC127
);
3275 adapter
->stats
.ptc255
+= E1000_READ_REG(hw
, PTC255
);
3276 adapter
->stats
.ptc511
+= E1000_READ_REG(hw
, PTC511
);
3277 adapter
->stats
.ptc1023
+= E1000_READ_REG(hw
, PTC1023
);
3278 adapter
->stats
.ptc1522
+= E1000_READ_REG(hw
, PTC1522
);
3281 adapter
->stats
.mptc
+= E1000_READ_REG(hw
, MPTC
);
3282 adapter
->stats
.bptc
+= E1000_READ_REG(hw
, BPTC
);
3284 /* used for adaptive IFS */
3286 hw
->tx_packet_delta
= E1000_READ_REG(hw
, TPT
);
3287 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3288 hw
->collision_delta
= E1000_READ_REG(hw
, COLC
);
3289 adapter
->stats
.colc
+= hw
->collision_delta
;
3291 if (hw
->mac_type
>= e1000_82543
) {
3292 adapter
->stats
.algnerrc
+= E1000_READ_REG(hw
, ALGNERRC
);
3293 adapter
->stats
.rxerrc
+= E1000_READ_REG(hw
, RXERRC
);
3294 adapter
->stats
.tncrs
+= E1000_READ_REG(hw
, TNCRS
);
3295 adapter
->stats
.cexterr
+= E1000_READ_REG(hw
, CEXTERR
);
3296 adapter
->stats
.tsctc
+= E1000_READ_REG(hw
, TSCTC
);
3297 adapter
->stats
.tsctfc
+= E1000_READ_REG(hw
, TSCTFC
);
3299 if (hw
->mac_type
> e1000_82547_rev_2
) {
3300 adapter
->stats
.iac
+= E1000_READ_REG(hw
, IAC
);
3301 adapter
->stats
.icrxoc
+= E1000_READ_REG(hw
, ICRXOC
);
3303 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
3304 adapter
->stats
.icrxptc
+= E1000_READ_REG(hw
, ICRXPTC
);
3305 adapter
->stats
.icrxatc
+= E1000_READ_REG(hw
, ICRXATC
);
3306 adapter
->stats
.ictxptc
+= E1000_READ_REG(hw
, ICTXPTC
);
3307 adapter
->stats
.ictxatc
+= E1000_READ_REG(hw
, ICTXATC
);
3308 adapter
->stats
.ictxqec
+= E1000_READ_REG(hw
, ICTXQEC
);
3309 adapter
->stats
.ictxqmtc
+= E1000_READ_REG(hw
, ICTXQMTC
);
3310 adapter
->stats
.icrxdmtc
+= E1000_READ_REG(hw
, ICRXDMTC
);
3314 /* Fill out the OS statistics structure */
3316 adapter
->net_stats
.rx_packets
= adapter
->stats
.gprc
;
3317 adapter
->net_stats
.tx_packets
= adapter
->stats
.gptc
;
3318 adapter
->net_stats
.rx_bytes
= adapter
->stats
.gorcl
;
3319 adapter
->net_stats
.tx_bytes
= adapter
->stats
.gotcl
;
3320 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3321 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3325 /* RLEC on some newer hardware can be incorrect so build
3326 * our own version based on RUC and ROC */
3327 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3328 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3329 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3330 adapter
->stats
.cexterr
;
3331 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.ruc
+
3333 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3334 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3335 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3339 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3340 adapter
->stats
.latecol
;
3341 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3342 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3343 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3345 /* Tx Dropped needs to be maintained elsewhere */
3349 if (hw
->media_type
== e1000_media_type_copper
) {
3350 if ((adapter
->link_speed
== SPEED_1000
) &&
3351 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3352 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3353 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3356 if ((hw
->mac_type
<= e1000_82546
) &&
3357 (hw
->phy_type
== e1000_phy_m88
) &&
3358 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3359 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3362 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3366 * e1000_intr - Interrupt Handler
3367 * @irq: interrupt number
3368 * @data: pointer to a network interface device structure
3369 * @pt_regs: CPU registers structure
3373 e1000_intr(int irq
, void *data
, struct pt_regs
*regs
)
3375 struct net_device
*netdev
= data
;
3376 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3377 struct e1000_hw
*hw
= &adapter
->hw
;
3378 uint32_t rctl
, icr
= E1000_READ_REG(hw
, ICR
);
3379 #ifndef CONFIG_E1000_NAPI
3382 /* Interrupt Auto-Mask...upon reading ICR,
3383 * interrupts are masked. No need for the
3384 * IMC write, but it does mean we should
3385 * account for it ASAP. */
3386 if (likely(hw
->mac_type
>= e1000_82571
))
3387 atomic_inc(&adapter
->irq_sem
);
3390 if (unlikely(!icr
)) {
3391 #ifdef CONFIG_E1000_NAPI
3392 if (hw
->mac_type
>= e1000_82571
)
3393 e1000_irq_enable(adapter
);
3395 return IRQ_NONE
; /* Not our interrupt */
3398 if (unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3399 hw
->get_link_status
= 1;
3400 /* 80003ES2LAN workaround--
3401 * For packet buffer work-around on link down event;
3402 * disable receives here in the ISR and
3403 * reset adapter in watchdog
3405 if (netif_carrier_ok(netdev
) &&
3406 (adapter
->hw
.mac_type
== e1000_80003es2lan
)) {
3407 /* disable receives */
3408 rctl
= E1000_READ_REG(hw
, RCTL
);
3409 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
3411 mod_timer(&adapter
->watchdog_timer
, jiffies
);
3414 #ifdef CONFIG_E1000_NAPI
3415 if (unlikely(hw
->mac_type
< e1000_82571
)) {
3416 atomic_inc(&adapter
->irq_sem
);
3417 E1000_WRITE_REG(hw
, IMC
, ~0);
3418 E1000_WRITE_FLUSH(hw
);
3420 if (likely(netif_rx_schedule_prep(netdev
)))
3421 __netif_rx_schedule(netdev
);
3423 e1000_irq_enable(adapter
);
3425 /* Writing IMC and IMS is needed for 82547.
3426 * Due to Hub Link bus being occupied, an interrupt
3427 * de-assertion message is not able to be sent.
3428 * When an interrupt assertion message is generated later,
3429 * two messages are re-ordered and sent out.
3430 * That causes APIC to think 82547 is in de-assertion
3431 * state, while 82547 is in assertion state, resulting
3432 * in dead lock. Writing IMC forces 82547 into
3433 * de-assertion state.
3435 if (hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
) {
3436 atomic_inc(&adapter
->irq_sem
);
3437 E1000_WRITE_REG(hw
, IMC
, ~0);
3440 for (i
= 0; i
< E1000_MAX_INTR
; i
++)
3441 if (unlikely(!adapter
->clean_rx(adapter
, adapter
->rx_ring
) &
3442 !e1000_clean_tx_irq(adapter
, adapter
->tx_ring
)))
3445 if (hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
3446 e1000_irq_enable(adapter
);
3453 #ifdef CONFIG_E1000_NAPI
3455 * e1000_clean - NAPI Rx polling callback
3456 * @adapter: board private structure
3460 e1000_clean(struct net_device
*poll_dev
, int *budget
)
3462 struct e1000_adapter
*adapter
;
3463 int work_to_do
= min(*budget
, poll_dev
->quota
);
3464 int tx_cleaned
= 0, work_done
= 0;
3466 /* Must NOT use netdev_priv macro here. */
3467 adapter
= poll_dev
->priv
;
3469 /* Keep link state information with original netdev */
3470 if (!netif_carrier_ok(poll_dev
))
3473 /* e1000_clean is called per-cpu. This lock protects
3474 * tx_ring[0] from being cleaned by multiple cpus
3475 * simultaneously. A failure obtaining the lock means
3476 * tx_ring[0] is currently being cleaned anyway. */
3477 if (spin_trylock(&adapter
->tx_queue_lock
)) {
3478 tx_cleaned
= e1000_clean_tx_irq(adapter
,
3479 &adapter
->tx_ring
[0]);
3480 spin_unlock(&adapter
->tx_queue_lock
);
3483 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[0],
3484 &work_done
, work_to_do
);
3486 *budget
-= work_done
;
3487 poll_dev
->quota
-= work_done
;
3489 /* If no Tx and not enough Rx work done, exit the polling mode */
3490 if ((!tx_cleaned
&& (work_done
== 0)) ||
3491 !netif_running(poll_dev
)) {
3493 netif_rx_complete(poll_dev
);
3494 e1000_irq_enable(adapter
);
3503 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3504 * @adapter: board private structure
3508 e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
3509 struct e1000_tx_ring
*tx_ring
)
3511 struct net_device
*netdev
= adapter
->netdev
;
3512 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
3513 struct e1000_buffer
*buffer_info
;
3514 unsigned int i
, eop
;
3515 #ifdef CONFIG_E1000_NAPI
3516 unsigned int count
= 0;
3518 boolean_t cleaned
= FALSE
;
3520 i
= tx_ring
->next_to_clean
;
3521 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3522 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3524 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
3525 for (cleaned
= FALSE
; !cleaned
; ) {
3526 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3527 buffer_info
= &tx_ring
->buffer_info
[i
];
3528 cleaned
= (i
== eop
);
3530 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
3531 memset(tx_desc
, 0, sizeof(struct e1000_tx_desc
));
3533 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3537 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3538 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3539 #ifdef CONFIG_E1000_NAPI
3540 #define E1000_TX_WEIGHT 64
3541 /* weight of a sort for tx, to avoid endless transmit cleanup */
3542 if (count
++ == E1000_TX_WEIGHT
) break;
3546 tx_ring
->next_to_clean
= i
;
3548 #define TX_WAKE_THRESHOLD 32
3549 if (unlikely(cleaned
&& netif_queue_stopped(netdev
) &&
3550 netif_carrier_ok(netdev
))) {
3551 spin_lock(&tx_ring
->tx_lock
);
3552 if (netif_queue_stopped(netdev
) &&
3553 (E1000_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
))
3554 netif_wake_queue(netdev
);
3555 spin_unlock(&tx_ring
->tx_lock
);
3558 if (adapter
->detect_tx_hung
) {
3559 /* Detect a transmit hang in hardware, this serializes the
3560 * check with the clearing of time_stamp and movement of i */
3561 adapter
->detect_tx_hung
= FALSE
;
3562 if (tx_ring
->buffer_info
[eop
].dma
&&
3563 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
+
3564 (adapter
->tx_timeout_factor
* HZ
))
3565 && !(E1000_READ_REG(&adapter
->hw
, STATUS
) &
3566 E1000_STATUS_TXOFF
)) {
3568 /* detected Tx unit hang */
3569 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
3573 " next_to_use <%x>\n"
3574 " next_to_clean <%x>\n"
3575 "buffer_info[next_to_clean]\n"
3576 " time_stamp <%lx>\n"
3577 " next_to_watch <%x>\n"
3579 " next_to_watch.status <%x>\n",
3580 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
3581 sizeof(struct e1000_tx_ring
)),
3582 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdh
),
3583 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdt
),
3584 tx_ring
->next_to_use
,
3585 tx_ring
->next_to_clean
,
3586 tx_ring
->buffer_info
[eop
].time_stamp
,
3589 eop_desc
->upper
.fields
.status
);
3590 netif_stop_queue(netdev
);
3597 * e1000_rx_checksum - Receive Checksum Offload for 82543
3598 * @adapter: board private structure
3599 * @status_err: receive descriptor status and error fields
3600 * @csum: receive descriptor csum field
3601 * @sk_buff: socket buffer with received data
3605 e1000_rx_checksum(struct e1000_adapter
*adapter
,
3606 uint32_t status_err
, uint32_t csum
,
3607 struct sk_buff
*skb
)
3609 uint16_t status
= (uint16_t)status_err
;
3610 uint8_t errors
= (uint8_t)(status_err
>> 24);
3611 skb
->ip_summed
= CHECKSUM_NONE
;
3613 /* 82543 or newer only */
3614 if (unlikely(adapter
->hw
.mac_type
< e1000_82543
)) return;
3615 /* Ignore Checksum bit is set */
3616 if (unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
3617 /* TCP/UDP checksum error bit is set */
3618 if (unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
3619 /* let the stack verify checksum errors */
3620 adapter
->hw_csum_err
++;
3623 /* TCP/UDP Checksum has not been calculated */
3624 if (adapter
->hw
.mac_type
<= e1000_82547_rev_2
) {
3625 if (!(status
& E1000_RXD_STAT_TCPCS
))
3628 if (!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
3631 /* It must be a TCP or UDP packet with a valid checksum */
3632 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
3633 /* TCP checksum is good */
3634 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3635 } else if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3636 /* IP fragment with UDP payload */
3637 /* Hardware complements the payload checksum, so we undo it
3638 * and then put the value in host order for further stack use.
3640 csum
= ntohl(csum
^ 0xFFFF);
3642 skb
->ip_summed
= CHECKSUM_COMPLETE
;
3644 adapter
->hw_csum_good
++;
3648 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3649 * @adapter: board private structure
3653 #ifdef CONFIG_E1000_NAPI
3654 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3655 struct e1000_rx_ring
*rx_ring
,
3656 int *work_done
, int work_to_do
)
3658 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3659 struct e1000_rx_ring
*rx_ring
)
3662 struct net_device
*netdev
= adapter
->netdev
;
3663 struct pci_dev
*pdev
= adapter
->pdev
;
3664 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
3665 struct e1000_buffer
*buffer_info
, *next_buffer
;
3666 unsigned long flags
;
3670 int cleaned_count
= 0;
3671 boolean_t cleaned
= FALSE
;
3673 i
= rx_ring
->next_to_clean
;
3674 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3675 buffer_info
= &rx_ring
->buffer_info
[i
];
3677 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
3678 struct sk_buff
*skb
;
3680 #ifdef CONFIG_E1000_NAPI
3681 if (*work_done
>= work_to_do
)
3685 status
= rx_desc
->status
;
3686 skb
= buffer_info
->skb
;
3687 buffer_info
->skb
= NULL
;
3689 prefetch(skb
->data
- NET_IP_ALIGN
);
3691 if (++i
== rx_ring
->count
) i
= 0;
3692 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
3695 next_buffer
= &rx_ring
->buffer_info
[i
];
3699 pci_unmap_single(pdev
,
3701 buffer_info
->length
,
3702 PCI_DMA_FROMDEVICE
);
3704 length
= le16_to_cpu(rx_desc
->length
);
3706 /* adjust length to remove Ethernet CRC */
3709 if (unlikely(!(status
& E1000_RXD_STAT_EOP
))) {
3710 /* All receives must fit into a single buffer */
3711 E1000_DBG("%s: Receive packet consumed multiple"
3712 " buffers\n", netdev
->name
);
3714 buffer_info
->skb
= skb
;
3718 if (unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
3719 last_byte
= *(skb
->data
+ length
- 1);
3720 if (TBI_ACCEPT(&adapter
->hw
, status
,
3721 rx_desc
->errors
, length
, last_byte
)) {
3722 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3723 e1000_tbi_adjust_stats(&adapter
->hw
,
3726 spin_unlock_irqrestore(&adapter
->stats_lock
,
3731 buffer_info
->skb
= skb
;
3736 /* code added for copybreak, this should improve
3737 * performance for small packets with large amounts
3738 * of reassembly being done in the stack */
3739 #define E1000_CB_LENGTH 256
3740 if (length
< E1000_CB_LENGTH
) {
3741 struct sk_buff
*new_skb
=
3742 netdev_alloc_skb(netdev
, length
+ NET_IP_ALIGN
);
3744 skb_reserve(new_skb
, NET_IP_ALIGN
);
3745 memcpy(new_skb
->data
- NET_IP_ALIGN
,
3746 skb
->data
- NET_IP_ALIGN
,
3747 length
+ NET_IP_ALIGN
);
3748 /* save the skb in buffer_info as good */
3749 buffer_info
->skb
= skb
;
3751 skb_put(skb
, length
);
3754 skb_put(skb
, length
);
3756 /* end copybreak code */
3758 /* Receive Checksum Offload */
3759 e1000_rx_checksum(adapter
,
3760 (uint32_t)(status
) |
3761 ((uint32_t)(rx_desc
->errors
) << 24),
3762 le16_to_cpu(rx_desc
->csum
), skb
);
3764 skb
->protocol
= eth_type_trans(skb
, netdev
);
3765 #ifdef CONFIG_E1000_NAPI
3766 if (unlikely(adapter
->vlgrp
&&
3767 (status
& E1000_RXD_STAT_VP
))) {
3768 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3769 le16_to_cpu(rx_desc
->special
) &
3770 E1000_RXD_SPC_VLAN_MASK
);
3772 netif_receive_skb(skb
);
3774 #else /* CONFIG_E1000_NAPI */
3775 if (unlikely(adapter
->vlgrp
&&
3776 (status
& E1000_RXD_STAT_VP
))) {
3777 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3778 le16_to_cpu(rx_desc
->special
) &
3779 E1000_RXD_SPC_VLAN_MASK
);
3783 #endif /* CONFIG_E1000_NAPI */
3784 netdev
->last_rx
= jiffies
;
3787 rx_desc
->status
= 0;
3789 /* return some buffers to hardware, one at a time is too slow */
3790 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
3791 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3795 /* use prefetched values */
3797 buffer_info
= next_buffer
;
3799 rx_ring
->next_to_clean
= i
;
3801 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
3803 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3809 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3810 * @adapter: board private structure
3814 #ifdef CONFIG_E1000_NAPI
3815 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3816 struct e1000_rx_ring
*rx_ring
,
3817 int *work_done
, int work_to_do
)
3819 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3820 struct e1000_rx_ring
*rx_ring
)
3823 union e1000_rx_desc_packet_split
*rx_desc
, *next_rxd
;
3824 struct net_device
*netdev
= adapter
->netdev
;
3825 struct pci_dev
*pdev
= adapter
->pdev
;
3826 struct e1000_buffer
*buffer_info
, *next_buffer
;
3827 struct e1000_ps_page
*ps_page
;
3828 struct e1000_ps_page_dma
*ps_page_dma
;
3829 struct sk_buff
*skb
;
3831 uint32_t length
, staterr
;
3832 int cleaned_count
= 0;
3833 boolean_t cleaned
= FALSE
;
3835 i
= rx_ring
->next_to_clean
;
3836 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3837 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3838 buffer_info
= &rx_ring
->buffer_info
[i
];
3840 while (staterr
& E1000_RXD_STAT_DD
) {
3841 ps_page
= &rx_ring
->ps_page
[i
];
3842 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3843 #ifdef CONFIG_E1000_NAPI
3844 if (unlikely(*work_done
>= work_to_do
))
3848 skb
= buffer_info
->skb
;
3850 /* in the packet split case this is header only */
3851 prefetch(skb
->data
- NET_IP_ALIGN
);
3853 if (++i
== rx_ring
->count
) i
= 0;
3854 next_rxd
= E1000_RX_DESC_PS(*rx_ring
, i
);
3857 next_buffer
= &rx_ring
->buffer_info
[i
];
3861 pci_unmap_single(pdev
, buffer_info
->dma
,
3862 buffer_info
->length
,
3863 PCI_DMA_FROMDEVICE
);
3865 if (unlikely(!(staterr
& E1000_RXD_STAT_EOP
))) {
3866 E1000_DBG("%s: Packet Split buffers didn't pick up"
3867 " the full packet\n", netdev
->name
);
3868 dev_kfree_skb_irq(skb
);
3872 if (unlikely(staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
)) {
3873 dev_kfree_skb_irq(skb
);
3877 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
3879 if (unlikely(!length
)) {
3880 E1000_DBG("%s: Last part of the packet spanning"
3881 " multiple descriptors\n", netdev
->name
);
3882 dev_kfree_skb_irq(skb
);
3887 skb_put(skb
, length
);
3890 /* this looks ugly, but it seems compiler issues make it
3891 more efficient than reusing j */
3892 int l1
= le16_to_cpu(rx_desc
->wb
.upper
.length
[0]);
3894 /* page alloc/put takes too long and effects small packet
3895 * throughput, so unsplit small packets and save the alloc/put*/
3896 if (l1
&& ((length
+ l1
) <= adapter
->rx_ps_bsize0
)) {
3898 /* there is no documentation about how to call
3899 * kmap_atomic, so we can't hold the mapping
3901 pci_dma_sync_single_for_cpu(pdev
,
3902 ps_page_dma
->ps_page_dma
[0],
3904 PCI_DMA_FROMDEVICE
);
3905 vaddr
= kmap_atomic(ps_page
->ps_page
[0],
3906 KM_SKB_DATA_SOFTIRQ
);
3907 memcpy(skb
->tail
, vaddr
, l1
);
3908 kunmap_atomic(vaddr
, KM_SKB_DATA_SOFTIRQ
);
3909 pci_dma_sync_single_for_device(pdev
,
3910 ps_page_dma
->ps_page_dma
[0],
3911 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
3912 /* remove the CRC */
3919 for (j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
3920 if (!(length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
])))
3922 pci_unmap_page(pdev
, ps_page_dma
->ps_page_dma
[j
],
3923 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
3924 ps_page_dma
->ps_page_dma
[j
] = 0;
3925 skb_fill_page_desc(skb
, j
, ps_page
->ps_page
[j
], 0,
3927 ps_page
->ps_page
[j
] = NULL
;
3929 skb
->data_len
+= length
;
3930 skb
->truesize
+= length
;
3933 /* strip the ethernet crc, problem is we're using pages now so
3934 * this whole operation can get a little cpu intensive */
3935 pskb_trim(skb
, skb
->len
- 4);
3938 e1000_rx_checksum(adapter
, staterr
,
3939 le16_to_cpu(rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
), skb
);
3940 skb
->protocol
= eth_type_trans(skb
, netdev
);
3942 if (likely(rx_desc
->wb
.upper
.header_status
&
3943 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP
)))
3944 adapter
->rx_hdr_split
++;
3945 #ifdef CONFIG_E1000_NAPI
3946 if (unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3947 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3948 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3949 E1000_RXD_SPC_VLAN_MASK
);
3951 netif_receive_skb(skb
);
3953 #else /* CONFIG_E1000_NAPI */
3954 if (unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3955 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3956 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3957 E1000_RXD_SPC_VLAN_MASK
);
3961 #endif /* CONFIG_E1000_NAPI */
3962 netdev
->last_rx
= jiffies
;
3965 rx_desc
->wb
.middle
.status_error
&= cpu_to_le32(~0xFF);
3966 buffer_info
->skb
= NULL
;
3968 /* return some buffers to hardware, one at a time is too slow */
3969 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
3970 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3974 /* use prefetched values */
3976 buffer_info
= next_buffer
;
3978 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3980 rx_ring
->next_to_clean
= i
;
3982 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
3984 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3990 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3991 * @adapter: address of board private structure
3995 e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
3996 struct e1000_rx_ring
*rx_ring
,
3999 struct net_device
*netdev
= adapter
->netdev
;
4000 struct pci_dev
*pdev
= adapter
->pdev
;
4001 struct e1000_rx_desc
*rx_desc
;
4002 struct e1000_buffer
*buffer_info
;
4003 struct sk_buff
*skb
;
4005 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
4007 i
= rx_ring
->next_to_use
;
4008 buffer_info
= &rx_ring
->buffer_info
[i
];
4010 while (cleaned_count
--) {
4011 skb
= buffer_info
->skb
;
4017 skb
= netdev_alloc_skb(netdev
, bufsz
);
4018 if (unlikely(!skb
)) {
4019 /* Better luck next round */
4020 adapter
->alloc_rx_buff_failed
++;
4024 /* Fix for errata 23, can't cross 64kB boundary */
4025 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4026 struct sk_buff
*oldskb
= skb
;
4027 DPRINTK(RX_ERR
, ERR
, "skb align check failed: %u bytes "
4028 "at %p\n", bufsz
, skb
->data
);
4029 /* Try again, without freeing the previous */
4030 skb
= netdev_alloc_skb(netdev
, bufsz
);
4031 /* Failed allocation, critical failure */
4033 dev_kfree_skb(oldskb
);
4037 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4040 dev_kfree_skb(oldskb
);
4041 break; /* while !buffer_info->skb */
4044 /* Use new allocation */
4045 dev_kfree_skb(oldskb
);
4047 /* Make buffer alignment 2 beyond a 16 byte boundary
4048 * this will result in a 16 byte aligned IP header after
4049 * the 14 byte MAC header is removed
4051 skb_reserve(skb
, NET_IP_ALIGN
);
4053 buffer_info
->skb
= skb
;
4054 buffer_info
->length
= adapter
->rx_buffer_len
;
4056 buffer_info
->dma
= pci_map_single(pdev
,
4058 adapter
->rx_buffer_len
,
4059 PCI_DMA_FROMDEVICE
);
4061 /* Fix for errata 23, can't cross 64kB boundary */
4062 if (!e1000_check_64k_bound(adapter
,
4063 (void *)(unsigned long)buffer_info
->dma
,
4064 adapter
->rx_buffer_len
)) {
4065 DPRINTK(RX_ERR
, ERR
,
4066 "dma align check failed: %u bytes at %p\n",
4067 adapter
->rx_buffer_len
,
4068 (void *)(unsigned long)buffer_info
->dma
);
4070 buffer_info
->skb
= NULL
;
4072 pci_unmap_single(pdev
, buffer_info
->dma
,
4073 adapter
->rx_buffer_len
,
4074 PCI_DMA_FROMDEVICE
);
4076 break; /* while !buffer_info->skb */
4078 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4079 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4081 if (unlikely(++i
== rx_ring
->count
))
4083 buffer_info
= &rx_ring
->buffer_info
[i
];
4086 if (likely(rx_ring
->next_to_use
!= i
)) {
4087 rx_ring
->next_to_use
= i
;
4088 if (unlikely(i
-- == 0))
4089 i
= (rx_ring
->count
- 1);
4091 /* Force memory writes to complete before letting h/w
4092 * know there are new descriptors to fetch. (Only
4093 * applicable for weak-ordered memory model archs,
4094 * such as IA-64). */
4096 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4101 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4102 * @adapter: address of board private structure
4106 e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
4107 struct e1000_rx_ring
*rx_ring
,
4110 struct net_device
*netdev
= adapter
->netdev
;
4111 struct pci_dev
*pdev
= adapter
->pdev
;
4112 union e1000_rx_desc_packet_split
*rx_desc
;
4113 struct e1000_buffer
*buffer_info
;
4114 struct e1000_ps_page
*ps_page
;
4115 struct e1000_ps_page_dma
*ps_page_dma
;
4116 struct sk_buff
*skb
;
4119 i
= rx_ring
->next_to_use
;
4120 buffer_info
= &rx_ring
->buffer_info
[i
];
4121 ps_page
= &rx_ring
->ps_page
[i
];
4122 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
4124 while (cleaned_count
--) {
4125 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
4127 for (j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
4128 if (j
< adapter
->rx_ps_pages
) {
4129 if (likely(!ps_page
->ps_page
[j
])) {
4130 ps_page
->ps_page
[j
] =
4131 alloc_page(GFP_ATOMIC
);
4132 if (unlikely(!ps_page
->ps_page
[j
])) {
4133 adapter
->alloc_rx_buff_failed
++;
4136 ps_page_dma
->ps_page_dma
[j
] =
4138 ps_page
->ps_page
[j
],
4140 PCI_DMA_FROMDEVICE
);
4142 /* Refresh the desc even if buffer_addrs didn't
4143 * change because each write-back erases
4146 rx_desc
->read
.buffer_addr
[j
+1] =
4147 cpu_to_le64(ps_page_dma
->ps_page_dma
[j
]);
4149 rx_desc
->read
.buffer_addr
[j
+1] = ~0;
4152 skb
= netdev_alloc_skb(netdev
,
4153 adapter
->rx_ps_bsize0
+ NET_IP_ALIGN
);
4155 if (unlikely(!skb
)) {
4156 adapter
->alloc_rx_buff_failed
++;
4160 /* Make buffer alignment 2 beyond a 16 byte boundary
4161 * this will result in a 16 byte aligned IP header after
4162 * the 14 byte MAC header is removed
4164 skb_reserve(skb
, NET_IP_ALIGN
);
4166 buffer_info
->skb
= skb
;
4167 buffer_info
->length
= adapter
->rx_ps_bsize0
;
4168 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
4169 adapter
->rx_ps_bsize0
,
4170 PCI_DMA_FROMDEVICE
);
4172 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
4174 if (unlikely(++i
== rx_ring
->count
)) i
= 0;
4175 buffer_info
= &rx_ring
->buffer_info
[i
];
4176 ps_page
= &rx_ring
->ps_page
[i
];
4177 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
4181 if (likely(rx_ring
->next_to_use
!= i
)) {
4182 rx_ring
->next_to_use
= i
;
4183 if (unlikely(i
-- == 0)) i
= (rx_ring
->count
- 1);
4185 /* Force memory writes to complete before letting h/w
4186 * know there are new descriptors to fetch. (Only
4187 * applicable for weak-ordered memory model archs,
4188 * such as IA-64). */
4190 /* Hardware increments by 16 bytes, but packet split
4191 * descriptors are 32 bytes...so we increment tail
4194 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4199 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4204 e1000_smartspeed(struct e1000_adapter
*adapter
)
4206 uint16_t phy_status
;
4209 if ((adapter
->hw
.phy_type
!= e1000_phy_igp
) || !adapter
->hw
.autoneg
||
4210 !(adapter
->hw
.autoneg_advertised
& ADVERTISE_1000_FULL
))
4213 if (adapter
->smartspeed
== 0) {
4214 /* If Master/Slave config fault is asserted twice,
4215 * we assume back-to-back */
4216 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4217 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4218 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4219 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4220 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4221 if (phy_ctrl
& CR_1000T_MS_ENABLE
) {
4222 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
4223 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
,
4225 adapter
->smartspeed
++;
4226 if (!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4227 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
,
4229 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4230 MII_CR_RESTART_AUTO_NEG
);
4231 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
,
4236 } else if (adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
4237 /* If still no link, perhaps using 2/3 pair cable */
4238 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4239 phy_ctrl
|= CR_1000T_MS_ENABLE
;
4240 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, phy_ctrl
);
4241 if (!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4242 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &phy_ctrl
)) {
4243 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4244 MII_CR_RESTART_AUTO_NEG
);
4245 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, phy_ctrl
);
4248 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4249 if (adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
4250 adapter
->smartspeed
= 0;
4261 e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4267 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4281 e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4283 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4284 struct mii_ioctl_data
*data
= if_mii(ifr
);
4288 unsigned long flags
;
4290 if (adapter
->hw
.media_type
!= e1000_media_type_copper
)
4295 data
->phy_id
= adapter
->hw
.phy_addr
;
4298 if (!capable(CAP_NET_ADMIN
))
4300 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4301 if (e1000_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
4303 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4306 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4309 if (!capable(CAP_NET_ADMIN
))
4311 if (data
->reg_num
& ~(0x1F))
4313 mii_reg
= data
->val_in
;
4314 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4315 if (e1000_write_phy_reg(&adapter
->hw
, data
->reg_num
,
4317 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4320 if (adapter
->hw
.media_type
== e1000_media_type_copper
) {
4321 switch (data
->reg_num
) {
4323 if (mii_reg
& MII_CR_POWER_DOWN
)
4325 if (mii_reg
& MII_CR_AUTO_NEG_EN
) {
4326 adapter
->hw
.autoneg
= 1;
4327 adapter
->hw
.autoneg_advertised
= 0x2F;
4330 spddplx
= SPEED_1000
;
4331 else if (mii_reg
& 0x2000)
4332 spddplx
= SPEED_100
;
4335 spddplx
+= (mii_reg
& 0x100)
4338 retval
= e1000_set_spd_dplx(adapter
,
4341 spin_unlock_irqrestore(
4342 &adapter
->stats_lock
,
4347 if (netif_running(adapter
->netdev
))
4348 e1000_reinit_locked(adapter
);
4350 e1000_reset(adapter
);
4352 case M88E1000_PHY_SPEC_CTRL
:
4353 case M88E1000_EXT_PHY_SPEC_CTRL
:
4354 if (e1000_phy_reset(&adapter
->hw
)) {
4355 spin_unlock_irqrestore(
4356 &adapter
->stats_lock
, flags
);
4362 switch (data
->reg_num
) {
4364 if (mii_reg
& MII_CR_POWER_DOWN
)
4366 if (netif_running(adapter
->netdev
))
4367 e1000_reinit_locked(adapter
);
4369 e1000_reset(adapter
);
4373 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4378 return E1000_SUCCESS
;
4382 e1000_pci_set_mwi(struct e1000_hw
*hw
)
4384 struct e1000_adapter
*adapter
= hw
->back
;
4385 int ret_val
= pci_set_mwi(adapter
->pdev
);
4388 DPRINTK(PROBE
, ERR
, "Error in setting MWI\n");
4392 e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4394 struct e1000_adapter
*adapter
= hw
->back
;
4396 pci_clear_mwi(adapter
->pdev
);
4400 e1000_read_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4402 struct e1000_adapter
*adapter
= hw
->back
;
4404 pci_read_config_word(adapter
->pdev
, reg
, value
);
4408 e1000_write_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4410 struct e1000_adapter
*adapter
= hw
->back
;
4412 pci_write_config_word(adapter
->pdev
, reg
, *value
);
4417 e1000_io_read(struct e1000_hw
*hw
, unsigned long port
)
4424 e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, uint32_t value
)
4430 e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
4432 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4433 uint32_t ctrl
, rctl
;
4435 e1000_irq_disable(adapter
);
4436 adapter
->vlgrp
= grp
;
4439 /* enable VLAN tag insert/strip */
4440 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4441 ctrl
|= E1000_CTRL_VME
;
4442 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4444 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
4445 /* enable VLAN receive filtering */
4446 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4447 rctl
|= E1000_RCTL_VFE
;
4448 rctl
&= ~E1000_RCTL_CFIEN
;
4449 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4450 e1000_update_mng_vlan(adapter
);
4453 /* disable VLAN tag insert/strip */
4454 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4455 ctrl
&= ~E1000_CTRL_VME
;
4456 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4458 if (adapter
->hw
.mac_type
!= e1000_ich8lan
) {
4459 /* disable VLAN filtering */
4460 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4461 rctl
&= ~E1000_RCTL_VFE
;
4462 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4463 if (adapter
->mng_vlan_id
!= (uint16_t)E1000_MNG_VLAN_NONE
) {
4464 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
4465 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
4470 e1000_irq_enable(adapter
);
4474 e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
)
4476 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4477 uint32_t vfta
, index
;
4479 if ((adapter
->hw
.mng_cookie
.status
&
4480 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4481 (vid
== adapter
->mng_vlan_id
))
4483 /* add VID to filter table */
4484 index
= (vid
>> 5) & 0x7F;
4485 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4486 vfta
|= (1 << (vid
& 0x1F));
4487 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4491 e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
)
4493 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4494 uint32_t vfta
, index
;
4496 e1000_irq_disable(adapter
);
4499 adapter
->vlgrp
->vlan_devices
[vid
] = NULL
;
4501 e1000_irq_enable(adapter
);
4503 if ((adapter
->hw
.mng_cookie
.status
&
4504 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4505 (vid
== adapter
->mng_vlan_id
)) {
4506 /* release control to f/w */
4507 e1000_release_hw_control(adapter
);
4511 /* remove VID from filter table */
4512 index
= (vid
>> 5) & 0x7F;
4513 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4514 vfta
&= ~(1 << (vid
& 0x1F));
4515 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4519 e1000_restore_vlan(struct e1000_adapter
*adapter
)
4521 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
4523 if (adapter
->vlgrp
) {
4525 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
4526 if (!adapter
->vlgrp
->vlan_devices
[vid
])
4528 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
4534 e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
)
4536 adapter
->hw
.autoneg
= 0;
4538 /* Fiber NICs only allow 1000 gbps Full duplex */
4539 if ((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
4540 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
4541 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4546 case SPEED_10
+ DUPLEX_HALF
:
4547 adapter
->hw
.forced_speed_duplex
= e1000_10_half
;
4549 case SPEED_10
+ DUPLEX_FULL
:
4550 adapter
->hw
.forced_speed_duplex
= e1000_10_full
;
4552 case SPEED_100
+ DUPLEX_HALF
:
4553 adapter
->hw
.forced_speed_duplex
= e1000_100_half
;
4555 case SPEED_100
+ DUPLEX_FULL
:
4556 adapter
->hw
.forced_speed_duplex
= e1000_100_full
;
4558 case SPEED_1000
+ DUPLEX_FULL
:
4559 adapter
->hw
.autoneg
= 1;
4560 adapter
->hw
.autoneg_advertised
= ADVERTISE_1000_FULL
;
4562 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
4564 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4571 /* Save/restore 16 or 64 dwords of PCI config space depending on which
4572 * bus we're on (PCI(X) vs. PCI-E)
4574 #define PCIE_CONFIG_SPACE_LEN 256
4575 #define PCI_CONFIG_SPACE_LEN 64
4577 e1000_pci_save_state(struct e1000_adapter
*adapter
)
4579 struct pci_dev
*dev
= adapter
->pdev
;
4583 if (adapter
->hw
.mac_type
>= e1000_82571
)
4584 size
= PCIE_CONFIG_SPACE_LEN
;
4586 size
= PCI_CONFIG_SPACE_LEN
;
4588 WARN_ON(adapter
->config_space
!= NULL
);
4590 adapter
->config_space
= kmalloc(size
, GFP_KERNEL
);
4591 if (!adapter
->config_space
) {
4592 DPRINTK(PROBE
, ERR
, "unable to allocate %d bytes\n", size
);
4595 for (i
= 0; i
< (size
/ 4); i
++)
4596 pci_read_config_dword(dev
, i
* 4, &adapter
->config_space
[i
]);
4601 e1000_pci_restore_state(struct e1000_adapter
*adapter
)
4603 struct pci_dev
*dev
= adapter
->pdev
;
4607 if (adapter
->config_space
== NULL
)
4610 if (adapter
->hw
.mac_type
>= e1000_82571
)
4611 size
= PCIE_CONFIG_SPACE_LEN
;
4613 size
= PCI_CONFIG_SPACE_LEN
;
4614 for (i
= 0; i
< (size
/ 4); i
++)
4615 pci_write_config_dword(dev
, i
* 4, adapter
->config_space
[i
]);
4616 kfree(adapter
->config_space
);
4617 adapter
->config_space
= NULL
;
4620 #endif /* CONFIG_PM */
4623 e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4625 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4626 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4627 uint32_t ctrl
, ctrl_ext
, rctl
, manc
, status
;
4628 uint32_t wufc
= adapter
->wol
;
4633 netif_device_detach(netdev
);
4635 if (netif_running(netdev
)) {
4636 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
4637 e1000_down(adapter
);
4641 /* Implement our own version of pci_save_state(pdev) because pci-
4642 * express adapters have 256-byte config spaces. */
4643 retval
= e1000_pci_save_state(adapter
);
4648 status
= E1000_READ_REG(&adapter
->hw
, STATUS
);
4649 if (status
& E1000_STATUS_LU
)
4650 wufc
&= ~E1000_WUFC_LNKC
;
4653 e1000_setup_rctl(adapter
);
4654 e1000_set_multi(netdev
);
4656 /* turn on all-multi mode if wake on multicast is enabled */
4657 if (wufc
& E1000_WUFC_MC
) {
4658 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4659 rctl
|= E1000_RCTL_MPE
;
4660 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4663 if (adapter
->hw
.mac_type
>= e1000_82540
) {
4664 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4665 /* advertise wake from D3Cold */
4666 #define E1000_CTRL_ADVD3WUC 0x00100000
4667 /* phy power management enable */
4668 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4669 ctrl
|= E1000_CTRL_ADVD3WUC
|
4670 E1000_CTRL_EN_PHY_PWR_MGMT
;
4671 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4674 if (adapter
->hw
.media_type
== e1000_media_type_fiber
||
4675 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) {
4676 /* keep the laser running in D3 */
4677 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
4678 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
4679 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
, ctrl_ext
);
4682 /* Allow time for pending master requests to run */
4683 e1000_disable_pciex_master(&adapter
->hw
);
4685 E1000_WRITE_REG(&adapter
->hw
, WUC
, E1000_WUC_PME_EN
);
4686 E1000_WRITE_REG(&adapter
->hw
, WUFC
, wufc
);
4687 pci_enable_wake(pdev
, PCI_D3hot
, 1);
4688 pci_enable_wake(pdev
, PCI_D3cold
, 1);
4690 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
4691 E1000_WRITE_REG(&adapter
->hw
, WUFC
, 0);
4692 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4693 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4696 /* FIXME: this code is incorrect for PCI Express */
4697 if (adapter
->hw
.mac_type
>= e1000_82540
&&
4698 adapter
->hw
.mac_type
!= e1000_ich8lan
&&
4699 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4700 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4701 if (manc
& E1000_MANC_SMBUS_EN
) {
4702 manc
|= E1000_MANC_ARP_EN
;
4703 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4704 pci_enable_wake(pdev
, PCI_D3hot
, 1);
4705 pci_enable_wake(pdev
, PCI_D3cold
, 1);
4709 if (adapter
->hw
.phy_type
== e1000_phy_igp_3
)
4710 e1000_phy_powerdown_workaround(&adapter
->hw
);
4712 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4713 * would have already happened in close and is redundant. */
4714 e1000_release_hw_control(adapter
);
4716 pci_disable_device(pdev
);
4718 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4725 e1000_resume(struct pci_dev
*pdev
)
4727 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4728 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4731 pci_set_power_state(pdev
, PCI_D0
);
4732 e1000_pci_restore_state(adapter
);
4733 if ((err
= pci_enable_device(pdev
))) {
4734 printk(KERN_ERR
"e1000: Cannot enable PCI device from suspend\n");
4737 pci_set_master(pdev
);
4739 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4740 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4742 e1000_reset(adapter
);
4743 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
4745 if (netif_running(netdev
))
4748 netif_device_attach(netdev
);
4750 /* FIXME: this code is incorrect for PCI Express */
4751 if (adapter
->hw
.mac_type
>= e1000_82540
&&
4752 adapter
->hw
.mac_type
!= e1000_ich8lan
&&
4753 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4754 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4755 manc
&= ~(E1000_MANC_ARP_EN
);
4756 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4759 /* If the controller is 82573 and f/w is AMT, do not set
4760 * DRV_LOAD until the interface is up. For all other cases,
4761 * let the f/w know that the h/w is now under the control
4763 if (adapter
->hw
.mac_type
!= e1000_82573
||
4764 !e1000_check_mng_mode(&adapter
->hw
))
4765 e1000_get_hw_control(adapter
);
4771 static void e1000_shutdown(struct pci_dev
*pdev
)
4773 e1000_suspend(pdev
, PMSG_SUSPEND
);
4776 #ifdef CONFIG_NET_POLL_CONTROLLER
4778 * Polling 'interrupt' - used by things like netconsole to send skbs
4779 * without having to re-enable interrupts. It's not called while
4780 * the interrupt routine is executing.
4783 e1000_netpoll(struct net_device
*netdev
)
4785 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4787 disable_irq(adapter
->pdev
->irq
);
4788 e1000_intr(adapter
->pdev
->irq
, netdev
, NULL
);
4789 e1000_clean_tx_irq(adapter
, adapter
->tx_ring
);
4790 #ifndef CONFIG_E1000_NAPI
4791 adapter
->clean_rx(adapter
, adapter
->rx_ring
);
4793 enable_irq(adapter
->pdev
->irq
);
4798 * e1000_io_error_detected - called when PCI error is detected
4799 * @pdev: Pointer to PCI device
4800 * @state: The current pci conneection state
4802 * This function is called after a PCI bus error affecting
4803 * this device has been detected.
4805 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
4807 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4808 struct e1000_adapter
*adapter
= netdev
->priv
;
4810 netif_device_detach(netdev
);
4812 if (netif_running(netdev
))
4813 e1000_down(adapter
);
4814 pci_disable_device(pdev
);
4816 /* Request a slot slot reset. */
4817 return PCI_ERS_RESULT_NEED_RESET
;
4821 * e1000_io_slot_reset - called after the pci bus has been reset.
4822 * @pdev: Pointer to PCI device
4824 * Restart the card from scratch, as if from a cold-boot. Implementation
4825 * resembles the first-half of the e1000_resume routine.
4827 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
4829 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4830 struct e1000_adapter
*adapter
= netdev
->priv
;
4832 if (pci_enable_device(pdev
)) {
4833 printk(KERN_ERR
"e1000: Cannot re-enable PCI device after reset.\n");
4834 return PCI_ERS_RESULT_DISCONNECT
;
4836 pci_set_master(pdev
);
4838 pci_enable_wake(pdev
, 3, 0);
4839 pci_enable_wake(pdev
, 4, 0); /* 4 == D3 cold */
4841 /* Perform card reset only on one instance of the card */
4842 if (PCI_FUNC (pdev
->devfn
) != 0)
4843 return PCI_ERS_RESULT_RECOVERED
;
4845 e1000_reset(adapter
);
4846 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
4848 return PCI_ERS_RESULT_RECOVERED
;
4852 * e1000_io_resume - called when traffic can start flowing again.
4853 * @pdev: Pointer to PCI device
4855 * This callback is called when the error recovery driver tells us that
4856 * its OK to resume normal operation. Implementation resembles the
4857 * second-half of the e1000_resume routine.
4859 static void e1000_io_resume(struct pci_dev
*pdev
)
4861 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4862 struct e1000_adapter
*adapter
= netdev
->priv
;
4863 uint32_t manc
, swsm
;
4865 if (netif_running(netdev
)) {
4866 if (e1000_up(adapter
)) {
4867 printk("e1000: can't bring device back up after reset\n");
4872 netif_device_attach(netdev
);
4874 if (adapter
->hw
.mac_type
>= e1000_82540
&&
4875 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4876 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4877 manc
&= ~(E1000_MANC_ARP_EN
);
4878 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4881 switch (adapter
->hw
.mac_type
) {
4883 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
4884 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
4885 swsm
| E1000_SWSM_DRV_LOAD
);
4891 if (netif_running(netdev
))
4892 mod_timer(&adapter
->watchdog_timer
, jiffies
);