1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 #include <net/ip6_checksum.h>
33 /* Intel Media SOC GbE MDIO physical base address */
34 static unsigned long ce4100_gbe_mdio_base_phy
;
35 /* Intel Media SOC GbE MDIO virtual base address */
36 void __iomem
*ce4100_gbe_mdio_base_virt
;
38 char e1000_driver_name
[] = "e1000";
39 static char e1000_driver_string
[] = "Intel(R) PRO/1000 Network Driver";
40 #define DRV_VERSION "7.3.21-k8-NAPI"
41 const char e1000_driver_version
[] = DRV_VERSION
;
42 static const char e1000_copyright
[] = "Copyright (c) 1999-2006 Intel Corporation.";
44 /* e1000_pci_tbl - PCI Device ID Table
46 * Last entry must be all 0s
49 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
51 static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl
) = {
52 INTEL_E1000_ETHERNET_DEVICE(0x1000),
53 INTEL_E1000_ETHERNET_DEVICE(0x1001),
54 INTEL_E1000_ETHERNET_DEVICE(0x1004),
55 INTEL_E1000_ETHERNET_DEVICE(0x1008),
56 INTEL_E1000_ETHERNET_DEVICE(0x1009),
57 INTEL_E1000_ETHERNET_DEVICE(0x100C),
58 INTEL_E1000_ETHERNET_DEVICE(0x100D),
59 INTEL_E1000_ETHERNET_DEVICE(0x100E),
60 INTEL_E1000_ETHERNET_DEVICE(0x100F),
61 INTEL_E1000_ETHERNET_DEVICE(0x1010),
62 INTEL_E1000_ETHERNET_DEVICE(0x1011),
63 INTEL_E1000_ETHERNET_DEVICE(0x1012),
64 INTEL_E1000_ETHERNET_DEVICE(0x1013),
65 INTEL_E1000_ETHERNET_DEVICE(0x1014),
66 INTEL_E1000_ETHERNET_DEVICE(0x1015),
67 INTEL_E1000_ETHERNET_DEVICE(0x1016),
68 INTEL_E1000_ETHERNET_DEVICE(0x1017),
69 INTEL_E1000_ETHERNET_DEVICE(0x1018),
70 INTEL_E1000_ETHERNET_DEVICE(0x1019),
71 INTEL_E1000_ETHERNET_DEVICE(0x101A),
72 INTEL_E1000_ETHERNET_DEVICE(0x101D),
73 INTEL_E1000_ETHERNET_DEVICE(0x101E),
74 INTEL_E1000_ETHERNET_DEVICE(0x1026),
75 INTEL_E1000_ETHERNET_DEVICE(0x1027),
76 INTEL_E1000_ETHERNET_DEVICE(0x1028),
77 INTEL_E1000_ETHERNET_DEVICE(0x1075),
78 INTEL_E1000_ETHERNET_DEVICE(0x1076),
79 INTEL_E1000_ETHERNET_DEVICE(0x1077),
80 INTEL_E1000_ETHERNET_DEVICE(0x1078),
81 INTEL_E1000_ETHERNET_DEVICE(0x1079),
82 INTEL_E1000_ETHERNET_DEVICE(0x107A),
83 INTEL_E1000_ETHERNET_DEVICE(0x107B),
84 INTEL_E1000_ETHERNET_DEVICE(0x107C),
85 INTEL_E1000_ETHERNET_DEVICE(0x108A),
86 INTEL_E1000_ETHERNET_DEVICE(0x1099),
87 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
88 INTEL_E1000_ETHERNET_DEVICE(0x2E6E),
89 /* required last entry */
93 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
95 int e1000_up(struct e1000_adapter
*adapter
);
96 void e1000_down(struct e1000_adapter
*adapter
);
97 void e1000_reinit_locked(struct e1000_adapter
*adapter
);
98 void e1000_reset(struct e1000_adapter
*adapter
);
99 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
);
100 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
);
101 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
);
102 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
);
103 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
104 struct e1000_tx_ring
*txdr
);
105 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
106 struct e1000_rx_ring
*rxdr
);
107 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
108 struct e1000_tx_ring
*tx_ring
);
109 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
110 struct e1000_rx_ring
*rx_ring
);
111 void e1000_update_stats(struct e1000_adapter
*adapter
);
113 static int e1000_init_module(void);
114 static void e1000_exit_module(void);
115 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
116 static void __devexit
e1000_remove(struct pci_dev
*pdev
);
117 static int e1000_alloc_queues(struct e1000_adapter
*adapter
);
118 static int e1000_sw_init(struct e1000_adapter
*adapter
);
119 static int e1000_open(struct net_device
*netdev
);
120 static int e1000_close(struct net_device
*netdev
);
121 static void e1000_configure_tx(struct e1000_adapter
*adapter
);
122 static void e1000_configure_rx(struct e1000_adapter
*adapter
);
123 static void e1000_setup_rctl(struct e1000_adapter
*adapter
);
124 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
);
125 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
);
126 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
127 struct e1000_tx_ring
*tx_ring
);
128 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
129 struct e1000_rx_ring
*rx_ring
);
130 static void e1000_set_rx_mode(struct net_device
*netdev
);
131 static void e1000_update_phy_info(unsigned long data
);
132 static void e1000_update_phy_info_task(struct work_struct
*work
);
133 static void e1000_watchdog(unsigned long data
);
134 static void e1000_82547_tx_fifo_stall(unsigned long data
);
135 static void e1000_82547_tx_fifo_stall_task(struct work_struct
*work
);
136 static netdev_tx_t
e1000_xmit_frame(struct sk_buff
*skb
,
137 struct net_device
*netdev
);
138 static struct net_device_stats
* e1000_get_stats(struct net_device
*netdev
);
139 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
140 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
141 static irqreturn_t
e1000_intr(int irq
, void *data
);
142 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
143 struct e1000_tx_ring
*tx_ring
);
144 static int e1000_clean(struct napi_struct
*napi
, int budget
);
145 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
146 struct e1000_rx_ring
*rx_ring
,
147 int *work_done
, int work_to_do
);
148 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter
*adapter
,
149 struct e1000_rx_ring
*rx_ring
,
150 int *work_done
, int work_to_do
);
151 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
152 struct e1000_rx_ring
*rx_ring
,
154 static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter
*adapter
,
155 struct e1000_rx_ring
*rx_ring
,
157 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
158 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
160 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
161 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
162 static void e1000_tx_timeout(struct net_device
*dev
);
163 static void e1000_reset_task(struct work_struct
*work
);
164 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
165 static int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
166 struct sk_buff
*skb
);
168 static void e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
);
169 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
);
170 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
);
171 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
174 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
);
175 static int e1000_resume(struct pci_dev
*pdev
);
177 static void e1000_shutdown(struct pci_dev
*pdev
);
179 #ifdef CONFIG_NET_POLL_CONTROLLER
180 /* for netdump / net console */
181 static void e1000_netpoll (struct net_device
*netdev
);
184 #define COPYBREAK_DEFAULT 256
185 static unsigned int copybreak __read_mostly
= COPYBREAK_DEFAULT
;
186 module_param(copybreak
, uint
, 0644);
187 MODULE_PARM_DESC(copybreak
,
188 "Maximum size of packet that is copied to a new buffer on receive");
190 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
191 pci_channel_state_t state
);
192 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
);
193 static void e1000_io_resume(struct pci_dev
*pdev
);
195 static struct pci_error_handlers e1000_err_handler
= {
196 .error_detected
= e1000_io_error_detected
,
197 .slot_reset
= e1000_io_slot_reset
,
198 .resume
= e1000_io_resume
,
201 static struct pci_driver e1000_driver
= {
202 .name
= e1000_driver_name
,
203 .id_table
= e1000_pci_tbl
,
204 .probe
= e1000_probe
,
205 .remove
= __devexit_p(e1000_remove
),
207 /* Power Management Hooks */
208 .suspend
= e1000_suspend
,
209 .resume
= e1000_resume
,
211 .shutdown
= e1000_shutdown
,
212 .err_handler
= &e1000_err_handler
215 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
216 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
217 MODULE_LICENSE("GPL");
218 MODULE_VERSION(DRV_VERSION
);
220 static int debug
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
221 module_param(debug
, int, 0);
222 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
225 * e1000_get_hw_dev - return device
226 * used by hardware layer to print debugging information
229 struct net_device
*e1000_get_hw_dev(struct e1000_hw
*hw
)
231 struct e1000_adapter
*adapter
= hw
->back
;
232 return adapter
->netdev
;
236 * e1000_init_module - Driver Registration Routine
238 * e1000_init_module is the first routine called when the driver is
239 * loaded. All it does is register with the PCI subsystem.
242 static int __init
e1000_init_module(void)
245 pr_info("%s - version %s\n", e1000_driver_string
, e1000_driver_version
);
247 pr_info("%s\n", e1000_copyright
);
249 ret
= pci_register_driver(&e1000_driver
);
250 if (copybreak
!= COPYBREAK_DEFAULT
) {
252 pr_info("copybreak disabled\n");
254 pr_info("copybreak enabled for "
255 "packets <= %u bytes\n", copybreak
);
260 module_init(e1000_init_module
);
263 * e1000_exit_module - Driver Exit Cleanup Routine
265 * e1000_exit_module is called just before the driver is removed
269 static void __exit
e1000_exit_module(void)
271 pci_unregister_driver(&e1000_driver
);
274 module_exit(e1000_exit_module
);
276 static int e1000_request_irq(struct e1000_adapter
*adapter
)
278 struct net_device
*netdev
= adapter
->netdev
;
279 irq_handler_t handler
= e1000_intr
;
280 int irq_flags
= IRQF_SHARED
;
283 err
= request_irq(adapter
->pdev
->irq
, handler
, irq_flags
, netdev
->name
,
286 e_err(probe
, "Unable to allocate interrupt Error: %d\n", err
);
292 static void e1000_free_irq(struct e1000_adapter
*adapter
)
294 struct net_device
*netdev
= adapter
->netdev
;
296 free_irq(adapter
->pdev
->irq
, netdev
);
300 * e1000_irq_disable - Mask off interrupt generation on the NIC
301 * @adapter: board private structure
304 static void e1000_irq_disable(struct e1000_adapter
*adapter
)
306 struct e1000_hw
*hw
= &adapter
->hw
;
310 synchronize_irq(adapter
->pdev
->irq
);
314 * e1000_irq_enable - Enable default interrupt generation settings
315 * @adapter: board private structure
318 static void e1000_irq_enable(struct e1000_adapter
*adapter
)
320 struct e1000_hw
*hw
= &adapter
->hw
;
322 ew32(IMS
, IMS_ENABLE_MASK
);
326 static void e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
328 struct e1000_hw
*hw
= &adapter
->hw
;
329 struct net_device
*netdev
= adapter
->netdev
;
330 u16 vid
= hw
->mng_cookie
.vlan_id
;
331 u16 old_vid
= adapter
->mng_vlan_id
;
332 if (adapter
->vlgrp
) {
333 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
334 if (hw
->mng_cookie
.status
&
335 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
336 e1000_vlan_rx_add_vid(netdev
, vid
);
337 adapter
->mng_vlan_id
= vid
;
339 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
341 if ((old_vid
!= (u16
)E1000_MNG_VLAN_NONE
) &&
343 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
344 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
346 adapter
->mng_vlan_id
= vid
;
350 static void e1000_init_manageability(struct e1000_adapter
*adapter
)
352 struct e1000_hw
*hw
= &adapter
->hw
;
354 if (adapter
->en_mng_pt
) {
355 u32 manc
= er32(MANC
);
357 /* disable hardware interception of ARP */
358 manc
&= ~(E1000_MANC_ARP_EN
);
364 static void e1000_release_manageability(struct e1000_adapter
*adapter
)
366 struct e1000_hw
*hw
= &adapter
->hw
;
368 if (adapter
->en_mng_pt
) {
369 u32 manc
= er32(MANC
);
371 /* re-enable hardware interception of ARP */
372 manc
|= E1000_MANC_ARP_EN
;
379 * e1000_configure - configure the hardware for RX and TX
380 * @adapter = private board structure
382 static void e1000_configure(struct e1000_adapter
*adapter
)
384 struct net_device
*netdev
= adapter
->netdev
;
387 e1000_set_rx_mode(netdev
);
389 e1000_restore_vlan(adapter
);
390 e1000_init_manageability(adapter
);
392 e1000_configure_tx(adapter
);
393 e1000_setup_rctl(adapter
);
394 e1000_configure_rx(adapter
);
395 /* call E1000_DESC_UNUSED which always leaves
396 * at least 1 descriptor unused to make sure
397 * next_to_use != next_to_clean */
398 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
399 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[i
];
400 adapter
->alloc_rx_buf(adapter
, ring
,
401 E1000_DESC_UNUSED(ring
));
405 int e1000_up(struct e1000_adapter
*adapter
)
407 struct e1000_hw
*hw
= &adapter
->hw
;
409 /* hardware has been reset, we need to reload some things */
410 e1000_configure(adapter
);
412 clear_bit(__E1000_DOWN
, &adapter
->flags
);
414 napi_enable(&adapter
->napi
);
416 e1000_irq_enable(adapter
);
418 netif_wake_queue(adapter
->netdev
);
420 /* fire a link change interrupt to start the watchdog */
421 ew32(ICS
, E1000_ICS_LSC
);
426 * e1000_power_up_phy - restore link in case the phy was powered down
427 * @adapter: address of board private structure
429 * The phy may be powered down to save power and turn off link when the
430 * driver is unloaded and wake on lan is not enabled (among others)
431 * *** this routine MUST be followed by a call to e1000_reset ***
435 void e1000_power_up_phy(struct e1000_adapter
*adapter
)
437 struct e1000_hw
*hw
= &adapter
->hw
;
440 /* Just clear the power down bit to wake the phy back up */
441 if (hw
->media_type
== e1000_media_type_copper
) {
442 /* according to the manual, the phy will retain its
443 * settings across a power-down/up cycle */
444 e1000_read_phy_reg(hw
, PHY_CTRL
, &mii_reg
);
445 mii_reg
&= ~MII_CR_POWER_DOWN
;
446 e1000_write_phy_reg(hw
, PHY_CTRL
, mii_reg
);
450 static void e1000_power_down_phy(struct e1000_adapter
*adapter
)
452 struct e1000_hw
*hw
= &adapter
->hw
;
454 /* Power down the PHY so no link is implied when interface is down *
455 * The PHY cannot be powered down if any of the following is true *
458 * (c) SoL/IDER session is active */
459 if (!adapter
->wol
&& hw
->mac_type
>= e1000_82540
&&
460 hw
->media_type
== e1000_media_type_copper
) {
463 switch (hw
->mac_type
) {
466 case e1000_82545_rev_3
:
469 case e1000_82546_rev_3
:
471 case e1000_82541_rev_2
:
473 case e1000_82547_rev_2
:
474 if (er32(MANC
) & E1000_MANC_SMBUS_EN
)
480 e1000_read_phy_reg(hw
, PHY_CTRL
, &mii_reg
);
481 mii_reg
|= MII_CR_POWER_DOWN
;
482 e1000_write_phy_reg(hw
, PHY_CTRL
, mii_reg
);
489 void e1000_down(struct e1000_adapter
*adapter
)
491 struct e1000_hw
*hw
= &adapter
->hw
;
492 struct net_device
*netdev
= adapter
->netdev
;
496 /* disable receives in the hardware */
498 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
499 /* flush and sleep below */
501 netif_tx_disable(netdev
);
503 /* disable transmits in the hardware */
505 tctl
&= ~E1000_TCTL_EN
;
507 /* flush both disables and wait for them to finish */
511 napi_disable(&adapter
->napi
);
513 e1000_irq_disable(adapter
);
516 * Setting DOWN must be after irq_disable to prevent
517 * a screaming interrupt. Setting DOWN also prevents
518 * timers and tasks from rescheduling.
520 set_bit(__E1000_DOWN
, &adapter
->flags
);
522 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
523 del_timer_sync(&adapter
->watchdog_timer
);
524 del_timer_sync(&adapter
->phy_info_timer
);
526 adapter
->link_speed
= 0;
527 adapter
->link_duplex
= 0;
528 netif_carrier_off(netdev
);
530 e1000_reset(adapter
);
531 e1000_clean_all_tx_rings(adapter
);
532 e1000_clean_all_rx_rings(adapter
);
535 static void e1000_reinit_safe(struct e1000_adapter
*adapter
)
537 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->flags
))
543 clear_bit(__E1000_RESETTING
, &adapter
->flags
);
546 void e1000_reinit_locked(struct e1000_adapter
*adapter
)
548 /* if rtnl_lock is not held the call path is bogus */
550 WARN_ON(in_interrupt());
551 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->flags
))
555 clear_bit(__E1000_RESETTING
, &adapter
->flags
);
558 void e1000_reset(struct e1000_adapter
*adapter
)
560 struct e1000_hw
*hw
= &adapter
->hw
;
561 u32 pba
= 0, tx_space
, min_tx_space
, min_rx_space
;
562 bool legacy_pba_adjust
= false;
565 /* Repartition Pba for greater than 9k mtu
566 * To take effect CTRL.RST is required.
569 switch (hw
->mac_type
) {
570 case e1000_82542_rev2_0
:
571 case e1000_82542_rev2_1
:
576 case e1000_82541_rev_2
:
577 legacy_pba_adjust
= true;
581 case e1000_82545_rev_3
:
584 case e1000_82546_rev_3
:
588 case e1000_82547_rev_2
:
589 legacy_pba_adjust
= true;
592 case e1000_undefined
:
597 if (legacy_pba_adjust
) {
598 if (hw
->max_frame_size
> E1000_RXBUFFER_8192
)
599 pba
-= 8; /* allocate more FIFO for Tx */
601 if (hw
->mac_type
== e1000_82547
) {
602 adapter
->tx_fifo_head
= 0;
603 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
604 adapter
->tx_fifo_size
=
605 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
606 atomic_set(&adapter
->tx_fifo_stall
, 0);
608 } else if (hw
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
609 /* adjust PBA for jumbo frames */
612 /* To maintain wire speed transmits, the Tx FIFO should be
613 * large enough to accommodate two full transmit packets,
614 * rounded up to the next 1KB and expressed in KB. Likewise,
615 * the Rx FIFO should be large enough to accommodate at least
616 * one full receive packet and is similarly rounded up and
617 * expressed in KB. */
619 /* upper 16 bits has Tx packet buffer allocation size in KB */
620 tx_space
= pba
>> 16;
621 /* lower 16 bits has Rx packet buffer allocation size in KB */
624 * the tx fifo also stores 16 bytes of information about the tx
625 * but don't include ethernet FCS because hardware appends it
627 min_tx_space
= (hw
->max_frame_size
+
628 sizeof(struct e1000_tx_desc
) -
630 min_tx_space
= ALIGN(min_tx_space
, 1024);
632 /* software strips receive CRC, so leave room for it */
633 min_rx_space
= hw
->max_frame_size
;
634 min_rx_space
= ALIGN(min_rx_space
, 1024);
637 /* If current Tx allocation is less than the min Tx FIFO size,
638 * and the min Tx FIFO size is less than the current Rx FIFO
639 * allocation, take space away from current Rx allocation */
640 if (tx_space
< min_tx_space
&&
641 ((min_tx_space
- tx_space
) < pba
)) {
642 pba
= pba
- (min_tx_space
- tx_space
);
644 /* PCI/PCIx hardware has PBA alignment constraints */
645 switch (hw
->mac_type
) {
646 case e1000_82545
... e1000_82546_rev_3
:
647 pba
&= ~(E1000_PBA_8K
- 1);
653 /* if short on rx space, rx wins and must trump tx
654 * adjustment or use Early Receive if available */
655 if (pba
< min_rx_space
)
663 * flow control settings:
664 * The high water mark must be low enough to fit one full frame
665 * (or the size used for early receive) above it in the Rx FIFO.
666 * Set it to the lower of:
667 * - 90% of the Rx FIFO size, and
668 * - the full Rx FIFO size minus the early receive size (for parts
669 * with ERT support assuming ERT set to E1000_ERT_2048), or
670 * - the full Rx FIFO size minus one full frame
672 hwm
= min(((pba
<< 10) * 9 / 10),
673 ((pba
<< 10) - hw
->max_frame_size
));
675 hw
->fc_high_water
= hwm
& 0xFFF8; /* 8-byte granularity */
676 hw
->fc_low_water
= hw
->fc_high_water
- 8;
677 hw
->fc_pause_time
= E1000_FC_PAUSE_TIME
;
679 hw
->fc
= hw
->original_fc
;
681 /* Allow time for pending master requests to run */
683 if (hw
->mac_type
>= e1000_82544
)
686 if (e1000_init_hw(hw
))
687 e_dev_err("Hardware Error\n");
688 e1000_update_mng_vlan(adapter
);
690 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
691 if (hw
->mac_type
>= e1000_82544
&&
693 hw
->autoneg_advertised
== ADVERTISE_1000_FULL
) {
694 u32 ctrl
= er32(CTRL
);
695 /* clear phy power management bit if we are in gig only mode,
696 * which if enabled will attempt negotiation to 100Mb, which
697 * can cause a loss of link at power off or driver unload */
698 ctrl
&= ~E1000_CTRL_SWDPIN3
;
702 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
703 ew32(VET
, ETHERNET_IEEE_VLAN_TYPE
);
705 e1000_reset_adaptive(hw
);
706 e1000_phy_get_info(hw
, &adapter
->phy_info
);
708 e1000_release_manageability(adapter
);
712 * Dump the eeprom for users having checksum issues
714 static void e1000_dump_eeprom(struct e1000_adapter
*adapter
)
716 struct net_device
*netdev
= adapter
->netdev
;
717 struct ethtool_eeprom eeprom
;
718 const struct ethtool_ops
*ops
= netdev
->ethtool_ops
;
721 u16 csum_old
, csum_new
= 0;
723 eeprom
.len
= ops
->get_eeprom_len(netdev
);
726 data
= kmalloc(eeprom
.len
, GFP_KERNEL
);
728 pr_err("Unable to allocate memory to dump EEPROM data\n");
732 ops
->get_eeprom(netdev
, &eeprom
, data
);
734 csum_old
= (data
[EEPROM_CHECKSUM_REG
* 2]) +
735 (data
[EEPROM_CHECKSUM_REG
* 2 + 1] << 8);
736 for (i
= 0; i
< EEPROM_CHECKSUM_REG
* 2; i
+= 2)
737 csum_new
+= data
[i
] + (data
[i
+ 1] << 8);
738 csum_new
= EEPROM_SUM
- csum_new
;
740 pr_err("/*********************/\n");
741 pr_err("Current EEPROM Checksum : 0x%04x\n", csum_old
);
742 pr_err("Calculated : 0x%04x\n", csum_new
);
744 pr_err("Offset Values\n");
745 pr_err("======== ======\n");
746 print_hex_dump(KERN_ERR
, "", DUMP_PREFIX_OFFSET
, 16, 1, data
, 128, 0);
748 pr_err("Include this output when contacting your support provider.\n");
749 pr_err("This is not a software error! Something bad happened to\n");
750 pr_err("your hardware or EEPROM image. Ignoring this problem could\n");
751 pr_err("result in further problems, possibly loss of data,\n");
752 pr_err("corruption or system hangs!\n");
753 pr_err("The MAC Address will be reset to 00:00:00:00:00:00,\n");
754 pr_err("which is invalid and requires you to set the proper MAC\n");
755 pr_err("address manually before continuing to enable this network\n");
756 pr_err("device. Please inspect the EEPROM dump and report the\n");
757 pr_err("issue to your hardware vendor or Intel Customer Support.\n");
758 pr_err("/*********************/\n");
764 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
765 * @pdev: PCI device information struct
767 * Return true if an adapter needs ioport resources
769 static int e1000_is_need_ioport(struct pci_dev
*pdev
)
771 switch (pdev
->device
) {
772 case E1000_DEV_ID_82540EM
:
773 case E1000_DEV_ID_82540EM_LOM
:
774 case E1000_DEV_ID_82540EP
:
775 case E1000_DEV_ID_82540EP_LOM
:
776 case E1000_DEV_ID_82540EP_LP
:
777 case E1000_DEV_ID_82541EI
:
778 case E1000_DEV_ID_82541EI_MOBILE
:
779 case E1000_DEV_ID_82541ER
:
780 case E1000_DEV_ID_82541ER_LOM
:
781 case E1000_DEV_ID_82541GI
:
782 case E1000_DEV_ID_82541GI_LF
:
783 case E1000_DEV_ID_82541GI_MOBILE
:
784 case E1000_DEV_ID_82544EI_COPPER
:
785 case E1000_DEV_ID_82544EI_FIBER
:
786 case E1000_DEV_ID_82544GC_COPPER
:
787 case E1000_DEV_ID_82544GC_LOM
:
788 case E1000_DEV_ID_82545EM_COPPER
:
789 case E1000_DEV_ID_82545EM_FIBER
:
790 case E1000_DEV_ID_82546EB_COPPER
:
791 case E1000_DEV_ID_82546EB_FIBER
:
792 case E1000_DEV_ID_82546EB_QUAD_COPPER
:
799 static const struct net_device_ops e1000_netdev_ops
= {
800 .ndo_open
= e1000_open
,
801 .ndo_stop
= e1000_close
,
802 .ndo_start_xmit
= e1000_xmit_frame
,
803 .ndo_get_stats
= e1000_get_stats
,
804 .ndo_set_rx_mode
= e1000_set_rx_mode
,
805 .ndo_set_mac_address
= e1000_set_mac
,
806 .ndo_tx_timeout
= e1000_tx_timeout
,
807 .ndo_change_mtu
= e1000_change_mtu
,
808 .ndo_do_ioctl
= e1000_ioctl
,
809 .ndo_validate_addr
= eth_validate_addr
,
811 .ndo_vlan_rx_register
= e1000_vlan_rx_register
,
812 .ndo_vlan_rx_add_vid
= e1000_vlan_rx_add_vid
,
813 .ndo_vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
,
814 #ifdef CONFIG_NET_POLL_CONTROLLER
815 .ndo_poll_controller
= e1000_netpoll
,
820 * e1000_init_hw_struct - initialize members of hw struct
821 * @adapter: board private struct
822 * @hw: structure used by e1000_hw.c
824 * Factors out initialization of the e1000_hw struct to its own function
825 * that can be called very early at init (just after struct allocation).
826 * Fields are initialized based on PCI device information and
827 * OS network device settings (MTU size).
828 * Returns negative error codes if MAC type setup fails.
830 static int e1000_init_hw_struct(struct e1000_adapter
*adapter
,
833 struct pci_dev
*pdev
= adapter
->pdev
;
835 /* PCI config space info */
836 hw
->vendor_id
= pdev
->vendor
;
837 hw
->device_id
= pdev
->device
;
838 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
839 hw
->subsystem_id
= pdev
->subsystem_device
;
840 hw
->revision_id
= pdev
->revision
;
842 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
844 hw
->max_frame_size
= adapter
->netdev
->mtu
+
845 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
846 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
848 /* identify the MAC */
849 if (e1000_set_mac_type(hw
)) {
850 e_err(probe
, "Unknown MAC Type\n");
854 switch (hw
->mac_type
) {
859 case e1000_82541_rev_2
:
860 case e1000_82547_rev_2
:
861 hw
->phy_init_script
= 1;
865 e1000_set_media_type(hw
);
866 e1000_get_bus_info(hw
);
868 hw
->wait_autoneg_complete
= false;
869 hw
->tbi_compatibility_en
= true;
870 hw
->adaptive_ifs
= true;
874 if (hw
->media_type
== e1000_media_type_copper
) {
875 hw
->mdix
= AUTO_ALL_MODES
;
876 hw
->disable_polarity_correction
= false;
877 hw
->master_slave
= E1000_MASTER_SLAVE
;
884 * e1000_probe - Device Initialization Routine
885 * @pdev: PCI device information struct
886 * @ent: entry in e1000_pci_tbl
888 * Returns 0 on success, negative on failure
890 * e1000_probe initializes an adapter identified by a pci_dev structure.
891 * The OS initialization, configuring of the adapter private structure,
892 * and a hardware reset occur.
894 static int __devinit
e1000_probe(struct pci_dev
*pdev
,
895 const struct pci_device_id
*ent
)
897 struct net_device
*netdev
;
898 struct e1000_adapter
*adapter
;
901 static int cards_found
= 0;
902 static int global_quad_port_a
= 0; /* global ksp3 port a indication */
903 int i
, err
, pci_using_dac
;
906 u16 eeprom_apme_mask
= E1000_EEPROM_APME
;
907 int bars
, need_ioport
;
909 /* do not allocate ioport bars when not needed */
910 need_ioport
= e1000_is_need_ioport(pdev
);
912 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
| IORESOURCE_IO
);
913 err
= pci_enable_device(pdev
);
915 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
916 err
= pci_enable_device_mem(pdev
);
921 err
= pci_request_selected_regions(pdev
, bars
, e1000_driver_name
);
925 pci_set_master(pdev
);
926 err
= pci_save_state(pdev
);
928 goto err_alloc_etherdev
;
931 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
933 goto err_alloc_etherdev
;
935 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
937 pci_set_drvdata(pdev
, netdev
);
938 adapter
= netdev_priv(netdev
);
939 adapter
->netdev
= netdev
;
940 adapter
->pdev
= pdev
;
941 adapter
->msg_enable
= (1 << debug
) - 1;
942 adapter
->bars
= bars
;
943 adapter
->need_ioport
= need_ioport
;
949 hw
->hw_addr
= pci_ioremap_bar(pdev
, BAR_0
);
953 if (adapter
->need_ioport
) {
954 for (i
= BAR_1
; i
<= BAR_5
; i
++) {
955 if (pci_resource_len(pdev
, i
) == 0)
957 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
958 hw
->io_base
= pci_resource_start(pdev
, i
);
964 /* make ready for any if (hw->...) below */
965 err
= e1000_init_hw_struct(adapter
, hw
);
970 * there is a workaround being applied below that limits
971 * 64-bit DMA addresses to 64-bit hardware. There are some
972 * 32-bit adapters that Tx hang when given 64-bit DMA addresses
975 if ((hw
->bus_type
== e1000_bus_type_pcix
) &&
976 !dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
978 * according to DMA-API-HOWTO, coherent calls will always
979 * succeed if the set call did
981 dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64));
984 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
986 pr_err("No usable DMA config, aborting\n");
989 dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
992 netdev
->netdev_ops
= &e1000_netdev_ops
;
993 e1000_set_ethtool_ops(netdev
);
994 netdev
->watchdog_timeo
= 5 * HZ
;
995 netif_napi_add(netdev
, &adapter
->napi
, e1000_clean
, 64);
997 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
999 adapter
->bd_number
= cards_found
;
1001 /* setup the private structure */
1003 err
= e1000_sw_init(adapter
);
1008 if (hw
->mac_type
== e1000_ce4100
) {
1009 ce4100_gbe_mdio_base_phy
= pci_resource_start(pdev
, BAR_1
);
1010 ce4100_gbe_mdio_base_virt
= ioremap(ce4100_gbe_mdio_base_phy
,
1011 pci_resource_len(pdev
, BAR_1
));
1013 if (!ce4100_gbe_mdio_base_virt
)
1014 goto err_mdio_ioremap
;
1017 if (hw
->mac_type
>= e1000_82543
) {
1018 netdev
->features
= NETIF_F_SG
|
1020 NETIF_F_HW_VLAN_TX
|
1021 NETIF_F_HW_VLAN_RX
|
1022 NETIF_F_HW_VLAN_FILTER
;
1025 if ((hw
->mac_type
>= e1000_82544
) &&
1026 (hw
->mac_type
!= e1000_82547
))
1027 netdev
->features
|= NETIF_F_TSO
;
1029 if (pci_using_dac
) {
1030 netdev
->features
|= NETIF_F_HIGHDMA
;
1031 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1034 netdev
->vlan_features
|= NETIF_F_TSO
;
1035 netdev
->vlan_features
|= NETIF_F_HW_CSUM
;
1036 netdev
->vlan_features
|= NETIF_F_SG
;
1038 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(hw
);
1040 /* initialize eeprom parameters */
1041 if (e1000_init_eeprom_params(hw
)) {
1042 e_err(probe
, "EEPROM initialization failed\n");
1046 /* before reading the EEPROM, reset the controller to
1047 * put the device in a known good starting state */
1051 /* make sure the EEPROM is good */
1052 if (e1000_validate_eeprom_checksum(hw
) < 0) {
1053 e_err(probe
, "The EEPROM Checksum Is Not Valid\n");
1054 e1000_dump_eeprom(adapter
);
1056 * set MAC address to all zeroes to invalidate and temporary
1057 * disable this device for the user. This blocks regular
1058 * traffic while still permitting ethtool ioctls from reaching
1059 * the hardware as well as allowing the user to run the
1060 * interface after manually setting a hw addr using
1063 memset(hw
->mac_addr
, 0, netdev
->addr_len
);
1065 /* copy the MAC address out of the EEPROM */
1066 if (e1000_read_mac_addr(hw
))
1067 e_err(probe
, "EEPROM Read Error\n");
1069 /* don't block initalization here due to bad MAC address */
1070 memcpy(netdev
->dev_addr
, hw
->mac_addr
, netdev
->addr_len
);
1071 memcpy(netdev
->perm_addr
, hw
->mac_addr
, netdev
->addr_len
);
1073 if (!is_valid_ether_addr(netdev
->perm_addr
))
1074 e_err(probe
, "Invalid MAC Address\n");
1076 init_timer(&adapter
->tx_fifo_stall_timer
);
1077 adapter
->tx_fifo_stall_timer
.function
= e1000_82547_tx_fifo_stall
;
1078 adapter
->tx_fifo_stall_timer
.data
= (unsigned long)adapter
;
1080 init_timer(&adapter
->watchdog_timer
);
1081 adapter
->watchdog_timer
.function
= e1000_watchdog
;
1082 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
1084 init_timer(&adapter
->phy_info_timer
);
1085 adapter
->phy_info_timer
.function
= e1000_update_phy_info
;
1086 adapter
->phy_info_timer
.data
= (unsigned long)adapter
;
1088 INIT_WORK(&adapter
->fifo_stall_task
, e1000_82547_tx_fifo_stall_task
);
1089 INIT_WORK(&adapter
->reset_task
, e1000_reset_task
);
1090 INIT_WORK(&adapter
->phy_info_task
, e1000_update_phy_info_task
);
1092 e1000_check_options(adapter
);
1094 /* Initial Wake on LAN setting
1095 * If APM wake is enabled in the EEPROM,
1096 * enable the ACPI Magic Packet filter
1099 switch (hw
->mac_type
) {
1100 case e1000_82542_rev2_0
:
1101 case e1000_82542_rev2_1
:
1105 e1000_read_eeprom(hw
,
1106 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
1107 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
1110 case e1000_82546_rev_3
:
1111 if (er32(STATUS
) & E1000_STATUS_FUNC_1
){
1112 e1000_read_eeprom(hw
,
1113 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
1118 e1000_read_eeprom(hw
,
1119 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
1122 if (eeprom_data
& eeprom_apme_mask
)
1123 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
1125 /* now that we have the eeprom settings, apply the special cases
1126 * where the eeprom may be wrong or the board simply won't support
1127 * wake on lan on a particular port */
1128 switch (pdev
->device
) {
1129 case E1000_DEV_ID_82546GB_PCIE
:
1130 adapter
->eeprom_wol
= 0;
1132 case E1000_DEV_ID_82546EB_FIBER
:
1133 case E1000_DEV_ID_82546GB_FIBER
:
1134 /* Wake events only supported on port A for dual fiber
1135 * regardless of eeprom setting */
1136 if (er32(STATUS
) & E1000_STATUS_FUNC_1
)
1137 adapter
->eeprom_wol
= 0;
1139 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3
:
1140 /* if quad port adapter, disable WoL on all but port A */
1141 if (global_quad_port_a
!= 0)
1142 adapter
->eeprom_wol
= 0;
1144 adapter
->quad_port_a
= 1;
1145 /* Reset for multiple quad port adapters */
1146 if (++global_quad_port_a
== 4)
1147 global_quad_port_a
= 0;
1151 /* initialize the wol settings based on the eeprom settings */
1152 adapter
->wol
= adapter
->eeprom_wol
;
1153 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1155 /* Auto detect PHY address */
1156 if (hw
->mac_type
== e1000_ce4100
) {
1157 for (i
= 0; i
< 32; i
++) {
1159 e1000_read_phy_reg(hw
, PHY_ID2
, &tmp
);
1160 if (tmp
== 0 || tmp
== 0xFF) {
1169 /* reset the hardware with the new settings */
1170 e1000_reset(adapter
);
1172 strcpy(netdev
->name
, "eth%d");
1173 err
= register_netdev(netdev
);
1177 /* print bus type/speed/width info */
1178 e_info(probe
, "(PCI%s:%dMHz:%d-bit) %pM\n",
1179 ((hw
->bus_type
== e1000_bus_type_pcix
) ? "-X" : ""),
1180 ((hw
->bus_speed
== e1000_bus_speed_133
) ? 133 :
1181 (hw
->bus_speed
== e1000_bus_speed_120
) ? 120 :
1182 (hw
->bus_speed
== e1000_bus_speed_100
) ? 100 :
1183 (hw
->bus_speed
== e1000_bus_speed_66
) ? 66 : 33),
1184 ((hw
->bus_width
== e1000_bus_width_64
) ? 64 : 32),
1187 /* carrier off reporting is important to ethtool even BEFORE open */
1188 netif_carrier_off(netdev
);
1190 e_info(probe
, "Intel(R) PRO/1000 Network Connection\n");
1197 e1000_phy_hw_reset(hw
);
1199 if (hw
->flash_address
)
1200 iounmap(hw
->flash_address
);
1201 kfree(adapter
->tx_ring
);
1202 kfree(adapter
->rx_ring
);
1206 iounmap(ce4100_gbe_mdio_base_virt
);
1207 iounmap(hw
->hw_addr
);
1209 free_netdev(netdev
);
1211 pci_release_selected_regions(pdev
, bars
);
1213 pci_disable_device(pdev
);
1218 * e1000_remove - Device Removal Routine
1219 * @pdev: PCI device information struct
1221 * e1000_remove is called by the PCI subsystem to alert the driver
1222 * that it should release a PCI device. The could be caused by a
1223 * Hot-Plug event, or because the driver is going to be removed from
1227 static void __devexit
e1000_remove(struct pci_dev
*pdev
)
1229 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1230 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1231 struct e1000_hw
*hw
= &adapter
->hw
;
1233 set_bit(__E1000_DOWN
, &adapter
->flags
);
1234 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
1235 del_timer_sync(&adapter
->watchdog_timer
);
1236 del_timer_sync(&adapter
->phy_info_timer
);
1238 cancel_work_sync(&adapter
->reset_task
);
1240 e1000_release_manageability(adapter
);
1242 unregister_netdev(netdev
);
1244 e1000_phy_hw_reset(hw
);
1246 kfree(adapter
->tx_ring
);
1247 kfree(adapter
->rx_ring
);
1249 iounmap(hw
->hw_addr
);
1250 if (hw
->flash_address
)
1251 iounmap(hw
->flash_address
);
1252 pci_release_selected_regions(pdev
, adapter
->bars
);
1254 free_netdev(netdev
);
1256 pci_disable_device(pdev
);
1260 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1261 * @adapter: board private structure to initialize
1263 * e1000_sw_init initializes the Adapter private data structure.
1264 * e1000_init_hw_struct MUST be called before this function
1267 static int __devinit
e1000_sw_init(struct e1000_adapter
*adapter
)
1269 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1271 adapter
->num_tx_queues
= 1;
1272 adapter
->num_rx_queues
= 1;
1274 if (e1000_alloc_queues(adapter
)) {
1275 e_err(probe
, "Unable to allocate memory for queues\n");
1279 /* Explicitly disable IRQ since the NIC can be in any state. */
1280 e1000_irq_disable(adapter
);
1282 spin_lock_init(&adapter
->stats_lock
);
1284 set_bit(__E1000_DOWN
, &adapter
->flags
);
1290 * e1000_alloc_queues - Allocate memory for all rings
1291 * @adapter: board private structure to initialize
1293 * We allocate one ring per queue at run-time since we don't know the
1294 * number of queues at compile-time.
1297 static int __devinit
e1000_alloc_queues(struct e1000_adapter
*adapter
)
1299 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1300 sizeof(struct e1000_tx_ring
), GFP_KERNEL
);
1301 if (!adapter
->tx_ring
)
1304 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
1305 sizeof(struct e1000_rx_ring
), GFP_KERNEL
);
1306 if (!adapter
->rx_ring
) {
1307 kfree(adapter
->tx_ring
);
1311 return E1000_SUCCESS
;
1315 * e1000_open - Called when a network interface is made active
1316 * @netdev: network interface device structure
1318 * Returns 0 on success, negative value on failure
1320 * The open entry point is called when a network interface is made
1321 * active by the system (IFF_UP). At this point all resources needed
1322 * for transmit and receive operations are allocated, the interrupt
1323 * handler is registered with the OS, the watchdog timer is started,
1324 * and the stack is notified that the interface is ready.
1327 static int e1000_open(struct net_device
*netdev
)
1329 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1330 struct e1000_hw
*hw
= &adapter
->hw
;
1333 /* disallow open during test */
1334 if (test_bit(__E1000_TESTING
, &adapter
->flags
))
1337 netif_carrier_off(netdev
);
1339 /* allocate transmit descriptors */
1340 err
= e1000_setup_all_tx_resources(adapter
);
1344 /* allocate receive descriptors */
1345 err
= e1000_setup_all_rx_resources(adapter
);
1349 e1000_power_up_phy(adapter
);
1351 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1352 if ((hw
->mng_cookie
.status
&
1353 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1354 e1000_update_mng_vlan(adapter
);
1357 /* before we allocate an interrupt, we must be ready to handle it.
1358 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1359 * as soon as we call pci_request_irq, so we have to setup our
1360 * clean_rx handler before we do so. */
1361 e1000_configure(adapter
);
1363 err
= e1000_request_irq(adapter
);
1367 /* From here on the code is the same as e1000_up() */
1368 clear_bit(__E1000_DOWN
, &adapter
->flags
);
1370 napi_enable(&adapter
->napi
);
1372 e1000_irq_enable(adapter
);
1374 netif_start_queue(netdev
);
1376 /* fire a link status change interrupt to start the watchdog */
1377 ew32(ICS
, E1000_ICS_LSC
);
1379 return E1000_SUCCESS
;
1382 e1000_power_down_phy(adapter
);
1383 e1000_free_all_rx_resources(adapter
);
1385 e1000_free_all_tx_resources(adapter
);
1387 e1000_reset(adapter
);
1393 * e1000_close - Disables a network interface
1394 * @netdev: network interface device structure
1396 * Returns 0, this is not allowed to fail
1398 * The close entry point is called when an interface is de-activated
1399 * by the OS. The hardware is still under the drivers control, but
1400 * needs to be disabled. A global MAC reset is issued to stop the
1401 * hardware, and all transmit and receive resources are freed.
1404 static int e1000_close(struct net_device
*netdev
)
1406 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1407 struct e1000_hw
*hw
= &adapter
->hw
;
1409 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
1410 e1000_down(adapter
);
1411 e1000_power_down_phy(adapter
);
1412 e1000_free_irq(adapter
);
1414 e1000_free_all_tx_resources(adapter
);
1415 e1000_free_all_rx_resources(adapter
);
1417 /* kill manageability vlan ID if supported, but not if a vlan with
1418 * the same ID is registered on the host OS (let 8021q kill it) */
1419 if ((hw
->mng_cookie
.status
&
1420 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
1422 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
))) {
1423 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1430 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1431 * @adapter: address of board private structure
1432 * @start: address of beginning of memory
1433 * @len: length of memory
1435 static bool e1000_check_64k_bound(struct e1000_adapter
*adapter
, void *start
,
1438 struct e1000_hw
*hw
= &adapter
->hw
;
1439 unsigned long begin
= (unsigned long)start
;
1440 unsigned long end
= begin
+ len
;
1442 /* First rev 82545 and 82546 need to not allow any memory
1443 * write location to cross 64k boundary due to errata 23 */
1444 if (hw
->mac_type
== e1000_82545
||
1445 hw
->mac_type
== e1000_ce4100
||
1446 hw
->mac_type
== e1000_82546
) {
1447 return ((begin
^ (end
- 1)) >> 16) != 0 ? false : true;
1454 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1455 * @adapter: board private structure
1456 * @txdr: tx descriptor ring (for a specific queue) to setup
1458 * Return 0 on success, negative on failure
1461 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1462 struct e1000_tx_ring
*txdr
)
1464 struct pci_dev
*pdev
= adapter
->pdev
;
1467 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1468 txdr
->buffer_info
= vzalloc(size
);
1469 if (!txdr
->buffer_info
) {
1470 e_err(probe
, "Unable to allocate memory for the Tx descriptor "
1475 /* round up to nearest 4K */
1477 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1478 txdr
->size
= ALIGN(txdr
->size
, 4096);
1480 txdr
->desc
= dma_alloc_coherent(&pdev
->dev
, txdr
->size
, &txdr
->dma
,
1484 vfree(txdr
->buffer_info
);
1485 e_err(probe
, "Unable to allocate memory for the Tx descriptor "
1490 /* Fix for errata 23, can't cross 64kB boundary */
1491 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1492 void *olddesc
= txdr
->desc
;
1493 dma_addr_t olddma
= txdr
->dma
;
1494 e_err(tx_err
, "txdr align check failed: %u bytes at %p\n",
1495 txdr
->size
, txdr
->desc
);
1496 /* Try again, without freeing the previous */
1497 txdr
->desc
= dma_alloc_coherent(&pdev
->dev
, txdr
->size
,
1498 &txdr
->dma
, GFP_KERNEL
);
1499 /* Failed allocation, critical failure */
1501 dma_free_coherent(&pdev
->dev
, txdr
->size
, olddesc
,
1503 goto setup_tx_desc_die
;
1506 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1508 dma_free_coherent(&pdev
->dev
, txdr
->size
, txdr
->desc
,
1510 dma_free_coherent(&pdev
->dev
, txdr
->size
, olddesc
,
1512 e_err(probe
, "Unable to allocate aligned memory "
1513 "for the transmit descriptor ring\n");
1514 vfree(txdr
->buffer_info
);
1517 /* Free old allocation, new allocation was successful */
1518 dma_free_coherent(&pdev
->dev
, txdr
->size
, olddesc
,
1522 memset(txdr
->desc
, 0, txdr
->size
);
1524 txdr
->next_to_use
= 0;
1525 txdr
->next_to_clean
= 0;
1531 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1532 * (Descriptors) for all queues
1533 * @adapter: board private structure
1535 * Return 0 on success, negative on failure
1538 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1542 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1543 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1545 e_err(probe
, "Allocation for Tx Queue %u failed\n", i
);
1546 for (i
-- ; i
>= 0; i
--)
1547 e1000_free_tx_resources(adapter
,
1548 &adapter
->tx_ring
[i
]);
1557 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1558 * @adapter: board private structure
1560 * Configure the Tx unit of the MAC after a reset.
1563 static void e1000_configure_tx(struct e1000_adapter
*adapter
)
1566 struct e1000_hw
*hw
= &adapter
->hw
;
1567 u32 tdlen
, tctl
, tipg
;
1570 /* Setup the HW Tx Head and Tail descriptor pointers */
1572 switch (adapter
->num_tx_queues
) {
1575 tdba
= adapter
->tx_ring
[0].dma
;
1576 tdlen
= adapter
->tx_ring
[0].count
*
1577 sizeof(struct e1000_tx_desc
);
1579 ew32(TDBAH
, (tdba
>> 32));
1580 ew32(TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1583 adapter
->tx_ring
[0].tdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDH
: E1000_82542_TDH
);
1584 adapter
->tx_ring
[0].tdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_TDT
: E1000_82542_TDT
);
1588 /* Set the default values for the Tx Inter Packet Gap timer */
1589 if ((hw
->media_type
== e1000_media_type_fiber
||
1590 hw
->media_type
== e1000_media_type_internal_serdes
))
1591 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1593 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1595 switch (hw
->mac_type
) {
1596 case e1000_82542_rev2_0
:
1597 case e1000_82542_rev2_1
:
1598 tipg
= DEFAULT_82542_TIPG_IPGT
;
1599 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
1600 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
1603 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1604 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
1607 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1608 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1611 /* Set the Tx Interrupt Delay register */
1613 ew32(TIDV
, adapter
->tx_int_delay
);
1614 if (hw
->mac_type
>= e1000_82540
)
1615 ew32(TADV
, adapter
->tx_abs_int_delay
);
1617 /* Program the Transmit Control Register */
1620 tctl
&= ~E1000_TCTL_CT
;
1621 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1622 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1624 e1000_config_collision_dist(hw
);
1626 /* Setup Transmit Descriptor Settings for eop descriptor */
1627 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
1629 /* only set IDE if we are delaying interrupts using the timers */
1630 if (adapter
->tx_int_delay
)
1631 adapter
->txd_cmd
|= E1000_TXD_CMD_IDE
;
1633 if (hw
->mac_type
< e1000_82543
)
1634 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1636 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1638 /* Cache if we're 82544 running in PCI-X because we'll
1639 * need this to apply a workaround later in the send path. */
1640 if (hw
->mac_type
== e1000_82544
&&
1641 hw
->bus_type
== e1000_bus_type_pcix
)
1642 adapter
->pcix_82544
= 1;
1649 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1650 * @adapter: board private structure
1651 * @rxdr: rx descriptor ring (for a specific queue) to setup
1653 * Returns 0 on success, negative on failure
1656 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1657 struct e1000_rx_ring
*rxdr
)
1659 struct pci_dev
*pdev
= adapter
->pdev
;
1662 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1663 rxdr
->buffer_info
= vzalloc(size
);
1664 if (!rxdr
->buffer_info
) {
1665 e_err(probe
, "Unable to allocate memory for the Rx descriptor "
1670 desc_len
= sizeof(struct e1000_rx_desc
);
1672 /* Round up to nearest 4K */
1674 rxdr
->size
= rxdr
->count
* desc_len
;
1675 rxdr
->size
= ALIGN(rxdr
->size
, 4096);
1677 rxdr
->desc
= dma_alloc_coherent(&pdev
->dev
, rxdr
->size
, &rxdr
->dma
,
1681 e_err(probe
, "Unable to allocate memory for the Rx descriptor "
1684 vfree(rxdr
->buffer_info
);
1688 /* Fix for errata 23, can't cross 64kB boundary */
1689 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1690 void *olddesc
= rxdr
->desc
;
1691 dma_addr_t olddma
= rxdr
->dma
;
1692 e_err(rx_err
, "rxdr align check failed: %u bytes at %p\n",
1693 rxdr
->size
, rxdr
->desc
);
1694 /* Try again, without freeing the previous */
1695 rxdr
->desc
= dma_alloc_coherent(&pdev
->dev
, rxdr
->size
,
1696 &rxdr
->dma
, GFP_KERNEL
);
1697 /* Failed allocation, critical failure */
1699 dma_free_coherent(&pdev
->dev
, rxdr
->size
, olddesc
,
1701 e_err(probe
, "Unable to allocate memory for the Rx "
1702 "descriptor ring\n");
1703 goto setup_rx_desc_die
;
1706 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1708 dma_free_coherent(&pdev
->dev
, rxdr
->size
, rxdr
->desc
,
1710 dma_free_coherent(&pdev
->dev
, rxdr
->size
, olddesc
,
1712 e_err(probe
, "Unable to allocate aligned memory for "
1713 "the Rx descriptor ring\n");
1714 goto setup_rx_desc_die
;
1716 /* Free old allocation, new allocation was successful */
1717 dma_free_coherent(&pdev
->dev
, rxdr
->size
, olddesc
,
1721 memset(rxdr
->desc
, 0, rxdr
->size
);
1723 rxdr
->next_to_clean
= 0;
1724 rxdr
->next_to_use
= 0;
1725 rxdr
->rx_skb_top
= NULL
;
1731 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1732 * (Descriptors) for all queues
1733 * @adapter: board private structure
1735 * Return 0 on success, negative on failure
1738 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1742 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1743 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1745 e_err(probe
, "Allocation for Rx Queue %u failed\n", i
);
1746 for (i
-- ; i
>= 0; i
--)
1747 e1000_free_rx_resources(adapter
,
1748 &adapter
->rx_ring
[i
]);
1757 * e1000_setup_rctl - configure the receive control registers
1758 * @adapter: Board private structure
1760 static void e1000_setup_rctl(struct e1000_adapter
*adapter
)
1762 struct e1000_hw
*hw
= &adapter
->hw
;
1767 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1769 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1770 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1771 (hw
->mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1773 if (hw
->tbi_compatibility_on
== 1)
1774 rctl
|= E1000_RCTL_SBP
;
1776 rctl
&= ~E1000_RCTL_SBP
;
1778 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1779 rctl
&= ~E1000_RCTL_LPE
;
1781 rctl
|= E1000_RCTL_LPE
;
1783 /* Setup buffer sizes */
1784 rctl
&= ~E1000_RCTL_SZ_4096
;
1785 rctl
|= E1000_RCTL_BSEX
;
1786 switch (adapter
->rx_buffer_len
) {
1787 case E1000_RXBUFFER_2048
:
1789 rctl
|= E1000_RCTL_SZ_2048
;
1790 rctl
&= ~E1000_RCTL_BSEX
;
1792 case E1000_RXBUFFER_4096
:
1793 rctl
|= E1000_RCTL_SZ_4096
;
1795 case E1000_RXBUFFER_8192
:
1796 rctl
|= E1000_RCTL_SZ_8192
;
1798 case E1000_RXBUFFER_16384
:
1799 rctl
|= E1000_RCTL_SZ_16384
;
1807 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1808 * @adapter: board private structure
1810 * Configure the Rx unit of the MAC after a reset.
1813 static void e1000_configure_rx(struct e1000_adapter
*adapter
)
1816 struct e1000_hw
*hw
= &adapter
->hw
;
1817 u32 rdlen
, rctl
, rxcsum
;
1819 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
1820 rdlen
= adapter
->rx_ring
[0].count
*
1821 sizeof(struct e1000_rx_desc
);
1822 adapter
->clean_rx
= e1000_clean_jumbo_rx_irq
;
1823 adapter
->alloc_rx_buf
= e1000_alloc_jumbo_rx_buffers
;
1825 rdlen
= adapter
->rx_ring
[0].count
*
1826 sizeof(struct e1000_rx_desc
);
1827 adapter
->clean_rx
= e1000_clean_rx_irq
;
1828 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1831 /* disable receives while setting up the descriptors */
1833 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1835 /* set the Receive Delay Timer Register */
1836 ew32(RDTR
, adapter
->rx_int_delay
);
1838 if (hw
->mac_type
>= e1000_82540
) {
1839 ew32(RADV
, adapter
->rx_abs_int_delay
);
1840 if (adapter
->itr_setting
!= 0)
1841 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
1844 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1845 * the Base and Length of the Rx Descriptor Ring */
1846 switch (adapter
->num_rx_queues
) {
1849 rdba
= adapter
->rx_ring
[0].dma
;
1851 ew32(RDBAH
, (rdba
>> 32));
1852 ew32(RDBAL
, (rdba
& 0x00000000ffffffffULL
));
1855 adapter
->rx_ring
[0].rdh
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDH
: E1000_82542_RDH
);
1856 adapter
->rx_ring
[0].rdt
= ((hw
->mac_type
>= e1000_82543
) ? E1000_RDT
: E1000_82542_RDT
);
1860 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1861 if (hw
->mac_type
>= e1000_82543
) {
1862 rxcsum
= er32(RXCSUM
);
1863 if (adapter
->rx_csum
)
1864 rxcsum
|= E1000_RXCSUM_TUOFL
;
1866 /* don't need to clear IPPCSE as it defaults to 0 */
1867 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1868 ew32(RXCSUM
, rxcsum
);
1871 /* Enable Receives */
1876 * e1000_free_tx_resources - Free Tx Resources per Queue
1877 * @adapter: board private structure
1878 * @tx_ring: Tx descriptor ring for a specific queue
1880 * Free all transmit software resources
1883 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
1884 struct e1000_tx_ring
*tx_ring
)
1886 struct pci_dev
*pdev
= adapter
->pdev
;
1888 e1000_clean_tx_ring(adapter
, tx_ring
);
1890 vfree(tx_ring
->buffer_info
);
1891 tx_ring
->buffer_info
= NULL
;
1893 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1896 tx_ring
->desc
= NULL
;
1900 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1901 * @adapter: board private structure
1903 * Free all transmit software resources
1906 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
1910 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1911 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1914 static void e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
1915 struct e1000_buffer
*buffer_info
)
1917 if (buffer_info
->dma
) {
1918 if (buffer_info
->mapped_as_page
)
1919 dma_unmap_page(&adapter
->pdev
->dev
, buffer_info
->dma
,
1920 buffer_info
->length
, DMA_TO_DEVICE
);
1922 dma_unmap_single(&adapter
->pdev
->dev
, buffer_info
->dma
,
1923 buffer_info
->length
,
1925 buffer_info
->dma
= 0;
1927 if (buffer_info
->skb
) {
1928 dev_kfree_skb_any(buffer_info
->skb
);
1929 buffer_info
->skb
= NULL
;
1931 buffer_info
->time_stamp
= 0;
1932 /* buffer_info must be completely set up in the transmit path */
1936 * e1000_clean_tx_ring - Free Tx Buffers
1937 * @adapter: board private structure
1938 * @tx_ring: ring to be cleaned
1941 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
1942 struct e1000_tx_ring
*tx_ring
)
1944 struct e1000_hw
*hw
= &adapter
->hw
;
1945 struct e1000_buffer
*buffer_info
;
1949 /* Free all the Tx ring sk_buffs */
1951 for (i
= 0; i
< tx_ring
->count
; i
++) {
1952 buffer_info
= &tx_ring
->buffer_info
[i
];
1953 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
1956 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1957 memset(tx_ring
->buffer_info
, 0, size
);
1959 /* Zero out the descriptor ring */
1961 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1963 tx_ring
->next_to_use
= 0;
1964 tx_ring
->next_to_clean
= 0;
1965 tx_ring
->last_tx_tso
= 0;
1967 writel(0, hw
->hw_addr
+ tx_ring
->tdh
);
1968 writel(0, hw
->hw_addr
+ tx_ring
->tdt
);
1972 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1973 * @adapter: board private structure
1976 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
1980 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1981 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1985 * e1000_free_rx_resources - Free Rx Resources
1986 * @adapter: board private structure
1987 * @rx_ring: ring to clean the resources from
1989 * Free all receive software resources
1992 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
1993 struct e1000_rx_ring
*rx_ring
)
1995 struct pci_dev
*pdev
= adapter
->pdev
;
1997 e1000_clean_rx_ring(adapter
, rx_ring
);
1999 vfree(rx_ring
->buffer_info
);
2000 rx_ring
->buffer_info
= NULL
;
2002 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
2005 rx_ring
->desc
= NULL
;
2009 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2010 * @adapter: board private structure
2012 * Free all receive software resources
2015 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
2019 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2020 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2024 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2025 * @adapter: board private structure
2026 * @rx_ring: ring to free buffers from
2029 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
2030 struct e1000_rx_ring
*rx_ring
)
2032 struct e1000_hw
*hw
= &adapter
->hw
;
2033 struct e1000_buffer
*buffer_info
;
2034 struct pci_dev
*pdev
= adapter
->pdev
;
2038 /* Free all the Rx ring sk_buffs */
2039 for (i
= 0; i
< rx_ring
->count
; i
++) {
2040 buffer_info
= &rx_ring
->buffer_info
[i
];
2041 if (buffer_info
->dma
&&
2042 adapter
->clean_rx
== e1000_clean_rx_irq
) {
2043 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
2044 buffer_info
->length
,
2046 } else if (buffer_info
->dma
&&
2047 adapter
->clean_rx
== e1000_clean_jumbo_rx_irq
) {
2048 dma_unmap_page(&pdev
->dev
, buffer_info
->dma
,
2049 buffer_info
->length
,
2053 buffer_info
->dma
= 0;
2054 if (buffer_info
->page
) {
2055 put_page(buffer_info
->page
);
2056 buffer_info
->page
= NULL
;
2058 if (buffer_info
->skb
) {
2059 dev_kfree_skb(buffer_info
->skb
);
2060 buffer_info
->skb
= NULL
;
2064 /* there also may be some cached data from a chained receive */
2065 if (rx_ring
->rx_skb_top
) {
2066 dev_kfree_skb(rx_ring
->rx_skb_top
);
2067 rx_ring
->rx_skb_top
= NULL
;
2070 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2071 memset(rx_ring
->buffer_info
, 0, size
);
2073 /* Zero out the descriptor ring */
2074 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2076 rx_ring
->next_to_clean
= 0;
2077 rx_ring
->next_to_use
= 0;
2079 writel(0, hw
->hw_addr
+ rx_ring
->rdh
);
2080 writel(0, hw
->hw_addr
+ rx_ring
->rdt
);
2084 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2085 * @adapter: board private structure
2088 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2092 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2093 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2096 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2097 * and memory write and invalidate disabled for certain operations
2099 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2101 struct e1000_hw
*hw
= &adapter
->hw
;
2102 struct net_device
*netdev
= adapter
->netdev
;
2105 e1000_pci_clear_mwi(hw
);
2108 rctl
|= E1000_RCTL_RST
;
2110 E1000_WRITE_FLUSH();
2113 if (netif_running(netdev
))
2114 e1000_clean_all_rx_rings(adapter
);
2117 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2119 struct e1000_hw
*hw
= &adapter
->hw
;
2120 struct net_device
*netdev
= adapter
->netdev
;
2124 rctl
&= ~E1000_RCTL_RST
;
2126 E1000_WRITE_FLUSH();
2129 if (hw
->pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2130 e1000_pci_set_mwi(hw
);
2132 if (netif_running(netdev
)) {
2133 /* No need to loop, because 82542 supports only 1 queue */
2134 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[0];
2135 e1000_configure_rx(adapter
);
2136 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
2141 * e1000_set_mac - Change the Ethernet Address of the NIC
2142 * @netdev: network interface device structure
2143 * @p: pointer to an address structure
2145 * Returns 0 on success, negative on failure
2148 static int e1000_set_mac(struct net_device
*netdev
, void *p
)
2150 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2151 struct e1000_hw
*hw
= &adapter
->hw
;
2152 struct sockaddr
*addr
= p
;
2154 if (!is_valid_ether_addr(addr
->sa_data
))
2155 return -EADDRNOTAVAIL
;
2157 /* 82542 2.0 needs to be in reset to write receive address registers */
2159 if (hw
->mac_type
== e1000_82542_rev2_0
)
2160 e1000_enter_82542_rst(adapter
);
2162 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2163 memcpy(hw
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2165 e1000_rar_set(hw
, hw
->mac_addr
, 0);
2167 if (hw
->mac_type
== e1000_82542_rev2_0
)
2168 e1000_leave_82542_rst(adapter
);
2174 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
2175 * @netdev: network interface device structure
2177 * The set_rx_mode entry point is called whenever the unicast or multicast
2178 * address lists or the network interface flags are updated. This routine is
2179 * responsible for configuring the hardware for proper unicast, multicast,
2180 * promiscuous mode, and all-multi behavior.
2183 static void e1000_set_rx_mode(struct net_device
*netdev
)
2185 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2186 struct e1000_hw
*hw
= &adapter
->hw
;
2187 struct netdev_hw_addr
*ha
;
2188 bool use_uc
= false;
2191 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2192 int mta_reg_count
= E1000_NUM_MTA_REGISTERS
;
2193 u32
*mcarray
= kcalloc(mta_reg_count
, sizeof(u32
), GFP_ATOMIC
);
2196 e_err(probe
, "memory allocation failed\n");
2200 /* Check for Promiscuous and All Multicast modes */
2204 if (netdev
->flags
& IFF_PROMISC
) {
2205 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2206 rctl
&= ~E1000_RCTL_VFE
;
2208 if (netdev
->flags
& IFF_ALLMULTI
)
2209 rctl
|= E1000_RCTL_MPE
;
2211 rctl
&= ~E1000_RCTL_MPE
;
2212 /* Enable VLAN filter if there is a VLAN */
2214 rctl
|= E1000_RCTL_VFE
;
2217 if (netdev_uc_count(netdev
) > rar_entries
- 1) {
2218 rctl
|= E1000_RCTL_UPE
;
2219 } else if (!(netdev
->flags
& IFF_PROMISC
)) {
2220 rctl
&= ~E1000_RCTL_UPE
;
2226 /* 82542 2.0 needs to be in reset to write receive address registers */
2228 if (hw
->mac_type
== e1000_82542_rev2_0
)
2229 e1000_enter_82542_rst(adapter
);
2231 /* load the first 14 addresses into the exact filters 1-14. Unicast
2232 * addresses take precedence to avoid disabling unicast filtering
2235 * RAR 0 is used for the station MAC address
2236 * if there are not 14 addresses, go ahead and clear the filters
2240 netdev_for_each_uc_addr(ha
, netdev
) {
2241 if (i
== rar_entries
)
2243 e1000_rar_set(hw
, ha
->addr
, i
++);
2246 netdev_for_each_mc_addr(ha
, netdev
) {
2247 if (i
== rar_entries
) {
2248 /* load any remaining addresses into the hash table */
2249 u32 hash_reg
, hash_bit
, mta
;
2250 hash_value
= e1000_hash_mc_addr(hw
, ha
->addr
);
2251 hash_reg
= (hash_value
>> 5) & 0x7F;
2252 hash_bit
= hash_value
& 0x1F;
2253 mta
= (1 << hash_bit
);
2254 mcarray
[hash_reg
] |= mta
;
2256 e1000_rar_set(hw
, ha
->addr
, i
++);
2260 for (; i
< rar_entries
; i
++) {
2261 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2262 E1000_WRITE_FLUSH();
2263 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2264 E1000_WRITE_FLUSH();
2267 /* write the hash table completely, write from bottom to avoid
2268 * both stupid write combining chipsets, and flushing each write */
2269 for (i
= mta_reg_count
- 1; i
>= 0 ; i
--) {
2271 * If we are on an 82544 has an errata where writing odd
2272 * offsets overwrites the previous even offset, but writing
2273 * backwards over the range solves the issue by always
2274 * writing the odd offset first
2276 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, mcarray
[i
]);
2278 E1000_WRITE_FLUSH();
2280 if (hw
->mac_type
== e1000_82542_rev2_0
)
2281 e1000_leave_82542_rst(adapter
);
2286 /* Need to wait a few seconds after link up to get diagnostic information from
2289 static void e1000_update_phy_info(unsigned long data
)
2291 struct e1000_adapter
*adapter
= (struct e1000_adapter
*)data
;
2292 schedule_work(&adapter
->phy_info_task
);
2295 static void e1000_update_phy_info_task(struct work_struct
*work
)
2297 struct e1000_adapter
*adapter
= container_of(work
,
2298 struct e1000_adapter
,
2300 struct e1000_hw
*hw
= &adapter
->hw
;
2303 e1000_phy_get_info(hw
, &adapter
->phy_info
);
2308 * e1000_82547_tx_fifo_stall - Timer Call-back
2309 * @data: pointer to adapter cast into an unsigned long
2311 static void e1000_82547_tx_fifo_stall(unsigned long data
)
2313 struct e1000_adapter
*adapter
= (struct e1000_adapter
*)data
;
2314 schedule_work(&adapter
->fifo_stall_task
);
2318 * e1000_82547_tx_fifo_stall_task - task to complete work
2319 * @work: work struct contained inside adapter struct
2321 static void e1000_82547_tx_fifo_stall_task(struct work_struct
*work
)
2323 struct e1000_adapter
*adapter
= container_of(work
,
2324 struct e1000_adapter
,
2326 struct e1000_hw
*hw
= &adapter
->hw
;
2327 struct net_device
*netdev
= adapter
->netdev
;
2331 if (atomic_read(&adapter
->tx_fifo_stall
)) {
2332 if ((er32(TDT
) == er32(TDH
)) &&
2333 (er32(TDFT
) == er32(TDFH
)) &&
2334 (er32(TDFTS
) == er32(TDFHS
))) {
2336 ew32(TCTL
, tctl
& ~E1000_TCTL_EN
);
2337 ew32(TDFT
, adapter
->tx_head_addr
);
2338 ew32(TDFH
, adapter
->tx_head_addr
);
2339 ew32(TDFTS
, adapter
->tx_head_addr
);
2340 ew32(TDFHS
, adapter
->tx_head_addr
);
2342 E1000_WRITE_FLUSH();
2344 adapter
->tx_fifo_head
= 0;
2345 atomic_set(&adapter
->tx_fifo_stall
, 0);
2346 netif_wake_queue(netdev
);
2347 } else if (!test_bit(__E1000_DOWN
, &adapter
->flags
)) {
2348 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2354 bool e1000_has_link(struct e1000_adapter
*adapter
)
2356 struct e1000_hw
*hw
= &adapter
->hw
;
2357 bool link_active
= false;
2359 /* get_link_status is set on LSC (link status) interrupt or
2360 * rx sequence error interrupt. get_link_status will stay
2361 * false until the e1000_check_for_link establishes link
2362 * for copper adapters ONLY
2364 switch (hw
->media_type
) {
2365 case e1000_media_type_copper
:
2366 if (hw
->get_link_status
) {
2367 e1000_check_for_link(hw
);
2368 link_active
= !hw
->get_link_status
;
2373 case e1000_media_type_fiber
:
2374 e1000_check_for_link(hw
);
2375 link_active
= !!(er32(STATUS
) & E1000_STATUS_LU
);
2377 case e1000_media_type_internal_serdes
:
2378 e1000_check_for_link(hw
);
2379 link_active
= hw
->serdes_has_link
;
2389 * e1000_watchdog - Timer Call-back
2390 * @data: pointer to adapter cast into an unsigned long
2392 static void e1000_watchdog(unsigned long data
)
2394 struct e1000_adapter
*adapter
= (struct e1000_adapter
*)data
;
2395 struct e1000_hw
*hw
= &adapter
->hw
;
2396 struct net_device
*netdev
= adapter
->netdev
;
2397 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2400 link
= e1000_has_link(adapter
);
2401 if ((netif_carrier_ok(netdev
)) && link
)
2405 if (!netif_carrier_ok(netdev
)) {
2408 /* update snapshot of PHY registers on LSC */
2409 e1000_get_speed_and_duplex(hw
,
2410 &adapter
->link_speed
,
2411 &adapter
->link_duplex
);
2414 pr_info("%s NIC Link is Up %d Mbps %s, "
2415 "Flow Control: %s\n",
2417 adapter
->link_speed
,
2418 adapter
->link_duplex
== FULL_DUPLEX
?
2419 "Full Duplex" : "Half Duplex",
2420 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
&
2421 E1000_CTRL_RFCE
)) ? "RX/TX" : ((ctrl
&
2422 E1000_CTRL_RFCE
) ? "RX" : ((ctrl
&
2423 E1000_CTRL_TFCE
) ? "TX" : "None")));
2425 /* adjust timeout factor according to speed/duplex */
2426 adapter
->tx_timeout_factor
= 1;
2427 switch (adapter
->link_speed
) {
2430 adapter
->tx_timeout_factor
= 16;
2434 /* maybe add some timeout factor ? */
2438 /* enable transmits in the hardware */
2440 tctl
|= E1000_TCTL_EN
;
2443 netif_carrier_on(netdev
);
2444 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
2445 mod_timer(&adapter
->phy_info_timer
,
2446 round_jiffies(jiffies
+ 2 * HZ
));
2447 adapter
->smartspeed
= 0;
2450 if (netif_carrier_ok(netdev
)) {
2451 adapter
->link_speed
= 0;
2452 adapter
->link_duplex
= 0;
2453 pr_info("%s NIC Link is Down\n",
2455 netif_carrier_off(netdev
);
2457 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
2458 mod_timer(&adapter
->phy_info_timer
,
2459 round_jiffies(jiffies
+ 2 * HZ
));
2462 e1000_smartspeed(adapter
);
2466 e1000_update_stats(adapter
);
2468 hw
->tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2469 adapter
->tpt_old
= adapter
->stats
.tpt
;
2470 hw
->collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2471 adapter
->colc_old
= adapter
->stats
.colc
;
2473 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2474 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2475 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2476 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2478 e1000_update_adaptive(hw
);
2480 if (!netif_carrier_ok(netdev
)) {
2481 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2482 /* We've lost link, so the controller stops DMA,
2483 * but we've got queued Tx work that's never going
2484 * to get done, so reset controller to flush Tx.
2485 * (Do the reset outside of interrupt context). */
2486 adapter
->tx_timeout_count
++;
2487 schedule_work(&adapter
->reset_task
);
2488 /* return immediately since reset is imminent */
2493 /* Simple mode for Interrupt Throttle Rate (ITR) */
2494 if (hw
->mac_type
>= e1000_82540
&& adapter
->itr_setting
== 4) {
2496 * Symmetric Tx/Rx gets a reduced ITR=2000;
2497 * Total asymmetrical Tx or Rx gets ITR=8000;
2498 * everyone else is between 2000-8000.
2500 u32 goc
= (adapter
->gotcl
+ adapter
->gorcl
) / 10000;
2501 u32 dif
= (adapter
->gotcl
> adapter
->gorcl
?
2502 adapter
->gotcl
- adapter
->gorcl
:
2503 adapter
->gorcl
- adapter
->gotcl
) / 10000;
2504 u32 itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
2506 ew32(ITR
, 1000000000 / (itr
* 256));
2509 /* Cause software interrupt to ensure rx ring is cleaned */
2510 ew32(ICS
, E1000_ICS_RXDMT0
);
2512 /* Force detection of hung controller every watchdog period */
2513 adapter
->detect_tx_hung
= true;
2515 /* Reset the timer */
2516 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
2517 mod_timer(&adapter
->watchdog_timer
,
2518 round_jiffies(jiffies
+ 2 * HZ
));
2521 enum latency_range
{
2525 latency_invalid
= 255
2529 * e1000_update_itr - update the dynamic ITR value based on statistics
2530 * @adapter: pointer to adapter
2531 * @itr_setting: current adapter->itr
2532 * @packets: the number of packets during this measurement interval
2533 * @bytes: the number of bytes during this measurement interval
2535 * Stores a new ITR value based on packets and byte
2536 * counts during the last interrupt. The advantage of per interrupt
2537 * computation is faster updates and more accurate ITR for the current
2538 * traffic pattern. Constants in this function were computed
2539 * based on theoretical maximum wire speed and thresholds were set based
2540 * on testing data as well as attempting to minimize response time
2541 * while increasing bulk throughput.
2542 * this functionality is controlled by the InterruptThrottleRate module
2543 * parameter (see e1000_param.c)
2545 static unsigned int e1000_update_itr(struct e1000_adapter
*adapter
,
2546 u16 itr_setting
, int packets
, int bytes
)
2548 unsigned int retval
= itr_setting
;
2549 struct e1000_hw
*hw
= &adapter
->hw
;
2551 if (unlikely(hw
->mac_type
< e1000_82540
))
2552 goto update_itr_done
;
2555 goto update_itr_done
;
2557 switch (itr_setting
) {
2558 case lowest_latency
:
2559 /* jumbo frames get bulk treatment*/
2560 if (bytes
/packets
> 8000)
2561 retval
= bulk_latency
;
2562 else if ((packets
< 5) && (bytes
> 512))
2563 retval
= low_latency
;
2565 case low_latency
: /* 50 usec aka 20000 ints/s */
2566 if (bytes
> 10000) {
2567 /* jumbo frames need bulk latency setting */
2568 if (bytes
/packets
> 8000)
2569 retval
= bulk_latency
;
2570 else if ((packets
< 10) || ((bytes
/packets
) > 1200))
2571 retval
= bulk_latency
;
2572 else if ((packets
> 35))
2573 retval
= lowest_latency
;
2574 } else if (bytes
/packets
> 2000)
2575 retval
= bulk_latency
;
2576 else if (packets
<= 2 && bytes
< 512)
2577 retval
= lowest_latency
;
2579 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2580 if (bytes
> 25000) {
2582 retval
= low_latency
;
2583 } else if (bytes
< 6000) {
2584 retval
= low_latency
;
2593 static void e1000_set_itr(struct e1000_adapter
*adapter
)
2595 struct e1000_hw
*hw
= &adapter
->hw
;
2597 u32 new_itr
= adapter
->itr
;
2599 if (unlikely(hw
->mac_type
< e1000_82540
))
2602 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2603 if (unlikely(adapter
->link_speed
!= SPEED_1000
)) {
2609 adapter
->tx_itr
= e1000_update_itr(adapter
,
2611 adapter
->total_tx_packets
,
2612 adapter
->total_tx_bytes
);
2613 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2614 if (adapter
->itr_setting
== 3 && adapter
->tx_itr
== lowest_latency
)
2615 adapter
->tx_itr
= low_latency
;
2617 adapter
->rx_itr
= e1000_update_itr(adapter
,
2619 adapter
->total_rx_packets
,
2620 adapter
->total_rx_bytes
);
2621 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2622 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
2623 adapter
->rx_itr
= low_latency
;
2625 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2627 switch (current_itr
) {
2628 /* counts and packets in update_itr are dependent on these numbers */
2629 case lowest_latency
:
2633 new_itr
= 20000; /* aka hwitr = ~200 */
2643 if (new_itr
!= adapter
->itr
) {
2644 /* this attempts to bias the interrupt rate towards Bulk
2645 * by adding intermediate steps when interrupt rate is
2647 new_itr
= new_itr
> adapter
->itr
?
2648 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2650 adapter
->itr
= new_itr
;
2651 ew32(ITR
, 1000000000 / (new_itr
* 256));
2655 #define E1000_TX_FLAGS_CSUM 0x00000001
2656 #define E1000_TX_FLAGS_VLAN 0x00000002
2657 #define E1000_TX_FLAGS_TSO 0x00000004
2658 #define E1000_TX_FLAGS_IPV4 0x00000008
2659 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2660 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2662 static int e1000_tso(struct e1000_adapter
*adapter
,
2663 struct e1000_tx_ring
*tx_ring
, struct sk_buff
*skb
)
2665 struct e1000_context_desc
*context_desc
;
2666 struct e1000_buffer
*buffer_info
;
2669 u16 ipcse
= 0, tucse
, mss
;
2670 u8 ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2673 if (skb_is_gso(skb
)) {
2674 if (skb_header_cloned(skb
)) {
2675 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2680 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2681 mss
= skb_shinfo(skb
)->gso_size
;
2682 if (skb
->protocol
== htons(ETH_P_IP
)) {
2683 struct iphdr
*iph
= ip_hdr(skb
);
2686 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2690 cmd_length
= E1000_TXD_CMD_IP
;
2691 ipcse
= skb_transport_offset(skb
) - 1;
2692 } else if (skb
->protocol
== htons(ETH_P_IPV6
)) {
2693 ipv6_hdr(skb
)->payload_len
= 0;
2694 tcp_hdr(skb
)->check
=
2695 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2696 &ipv6_hdr(skb
)->daddr
,
2700 ipcss
= skb_network_offset(skb
);
2701 ipcso
= (void *)&(ip_hdr(skb
)->check
) - (void *)skb
->data
;
2702 tucss
= skb_transport_offset(skb
);
2703 tucso
= (void *)&(tcp_hdr(skb
)->check
) - (void *)skb
->data
;
2706 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2707 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2709 i
= tx_ring
->next_to_use
;
2710 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2711 buffer_info
= &tx_ring
->buffer_info
[i
];
2713 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2714 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2715 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2716 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2717 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2718 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2719 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2720 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2721 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2723 buffer_info
->time_stamp
= jiffies
;
2724 buffer_info
->next_to_watch
= i
;
2726 if (++i
== tx_ring
->count
) i
= 0;
2727 tx_ring
->next_to_use
= i
;
2734 static bool e1000_tx_csum(struct e1000_adapter
*adapter
,
2735 struct e1000_tx_ring
*tx_ring
, struct sk_buff
*skb
)
2737 struct e1000_context_desc
*context_desc
;
2738 struct e1000_buffer
*buffer_info
;
2741 u32 cmd_len
= E1000_TXD_CMD_DEXT
;
2743 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
2746 switch (skb
->protocol
) {
2747 case cpu_to_be16(ETH_P_IP
):
2748 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
2749 cmd_len
|= E1000_TXD_CMD_TCP
;
2751 case cpu_to_be16(ETH_P_IPV6
):
2752 /* XXX not handling all IPV6 headers */
2753 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
2754 cmd_len
|= E1000_TXD_CMD_TCP
;
2757 if (unlikely(net_ratelimit()))
2758 e_warn(drv
, "checksum_partial proto=%x!\n",
2763 css
= skb_checksum_start_offset(skb
);
2765 i
= tx_ring
->next_to_use
;
2766 buffer_info
= &tx_ring
->buffer_info
[i
];
2767 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2769 context_desc
->lower_setup
.ip_config
= 0;
2770 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2771 context_desc
->upper_setup
.tcp_fields
.tucso
=
2772 css
+ skb
->csum_offset
;
2773 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2774 context_desc
->tcp_seg_setup
.data
= 0;
2775 context_desc
->cmd_and_length
= cpu_to_le32(cmd_len
);
2777 buffer_info
->time_stamp
= jiffies
;
2778 buffer_info
->next_to_watch
= i
;
2780 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2781 tx_ring
->next_to_use
= i
;
2786 #define E1000_MAX_TXD_PWR 12
2787 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2789 static int e1000_tx_map(struct e1000_adapter
*adapter
,
2790 struct e1000_tx_ring
*tx_ring
,
2791 struct sk_buff
*skb
, unsigned int first
,
2792 unsigned int max_per_txd
, unsigned int nr_frags
,
2795 struct e1000_hw
*hw
= &adapter
->hw
;
2796 struct pci_dev
*pdev
= adapter
->pdev
;
2797 struct e1000_buffer
*buffer_info
;
2798 unsigned int len
= skb_headlen(skb
);
2799 unsigned int offset
= 0, size
, count
= 0, i
;
2802 i
= tx_ring
->next_to_use
;
2805 buffer_info
= &tx_ring
->buffer_info
[i
];
2806 size
= min(len
, max_per_txd
);
2807 /* Workaround for Controller erratum --
2808 * descriptor for non-tso packet in a linear SKB that follows a
2809 * tso gets written back prematurely before the data is fully
2810 * DMA'd to the controller */
2811 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2813 tx_ring
->last_tx_tso
= 0;
2817 /* Workaround for premature desc write-backs
2818 * in TSO mode. Append 4-byte sentinel desc */
2819 if (unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
2821 /* work-around for errata 10 and it applies
2822 * to all controllers in PCI-X mode
2823 * The fix is to make sure that the first descriptor of a
2824 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2826 if (unlikely((hw
->bus_type
== e1000_bus_type_pcix
) &&
2827 (size
> 2015) && count
== 0))
2830 /* Workaround for potential 82544 hang in PCI-X. Avoid
2831 * terminating buffers within evenly-aligned dwords. */
2832 if (unlikely(adapter
->pcix_82544
&&
2833 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
2837 buffer_info
->length
= size
;
2838 /* set time_stamp *before* dma to help avoid a possible race */
2839 buffer_info
->time_stamp
= jiffies
;
2840 buffer_info
->mapped_as_page
= false;
2841 buffer_info
->dma
= dma_map_single(&pdev
->dev
,
2843 size
, DMA_TO_DEVICE
);
2844 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
))
2846 buffer_info
->next_to_watch
= i
;
2853 if (unlikely(i
== tx_ring
->count
))
2858 for (f
= 0; f
< nr_frags
; f
++) {
2859 struct skb_frag_struct
*frag
;
2861 frag
= &skb_shinfo(skb
)->frags
[f
];
2863 offset
= frag
->page_offset
;
2867 if (unlikely(i
== tx_ring
->count
))
2870 buffer_info
= &tx_ring
->buffer_info
[i
];
2871 size
= min(len
, max_per_txd
);
2872 /* Workaround for premature desc write-backs
2873 * in TSO mode. Append 4-byte sentinel desc */
2874 if (unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
2876 /* Workaround for potential 82544 hang in PCI-X.
2877 * Avoid terminating buffers within evenly-aligned
2879 if (unlikely(adapter
->pcix_82544
&&
2880 !((unsigned long)(page_to_phys(frag
->page
) + offset
2885 buffer_info
->length
= size
;
2886 buffer_info
->time_stamp
= jiffies
;
2887 buffer_info
->mapped_as_page
= true;
2888 buffer_info
->dma
= dma_map_page(&pdev
->dev
, frag
->page
,
2891 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
))
2893 buffer_info
->next_to_watch
= i
;
2901 tx_ring
->buffer_info
[i
].skb
= skb
;
2902 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
2907 dev_err(&pdev
->dev
, "TX DMA map failed\n");
2908 buffer_info
->dma
= 0;
2914 i
+= tx_ring
->count
;
2916 buffer_info
= &tx_ring
->buffer_info
[i
];
2917 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
2923 static void e1000_tx_queue(struct e1000_adapter
*adapter
,
2924 struct e1000_tx_ring
*tx_ring
, int tx_flags
,
2927 struct e1000_hw
*hw
= &adapter
->hw
;
2928 struct e1000_tx_desc
*tx_desc
= NULL
;
2929 struct e1000_buffer
*buffer_info
;
2930 u32 txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
2933 if (likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
2934 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
2936 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2938 if (likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
2939 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
2942 if (likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
2943 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
2944 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2947 if (unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
2948 txd_lower
|= E1000_TXD_CMD_VLE
;
2949 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
2952 i
= tx_ring
->next_to_use
;
2955 buffer_info
= &tx_ring
->buffer_info
[i
];
2956 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
2957 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2958 tx_desc
->lower
.data
=
2959 cpu_to_le32(txd_lower
| buffer_info
->length
);
2960 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
2961 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2964 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
2966 /* Force memory writes to complete before letting h/w
2967 * know there are new descriptors to fetch. (Only
2968 * applicable for weak-ordered memory model archs,
2969 * such as IA-64). */
2972 tx_ring
->next_to_use
= i
;
2973 writel(i
, hw
->hw_addr
+ tx_ring
->tdt
);
2974 /* we need this if more than one processor can write to our tail
2975 * at a time, it syncronizes IO on IA64/Altix systems */
2980 * 82547 workaround to avoid controller hang in half-duplex environment.
2981 * The workaround is to avoid queuing a large packet that would span
2982 * the internal Tx FIFO ring boundary by notifying the stack to resend
2983 * the packet at a later time. This gives the Tx FIFO an opportunity to
2984 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2985 * to the beginning of the Tx FIFO.
2988 #define E1000_FIFO_HDR 0x10
2989 #define E1000_82547_PAD_LEN 0x3E0
2991 static int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
2992 struct sk_buff
*skb
)
2994 u32 fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
2995 u32 skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
2997 skb_fifo_len
= ALIGN(skb_fifo_len
, E1000_FIFO_HDR
);
2999 if (adapter
->link_duplex
!= HALF_DUPLEX
)
3000 goto no_fifo_stall_required
;
3002 if (atomic_read(&adapter
->tx_fifo_stall
))
3005 if (skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
3006 atomic_set(&adapter
->tx_fifo_stall
, 1);
3010 no_fifo_stall_required
:
3011 adapter
->tx_fifo_head
+= skb_fifo_len
;
3012 if (adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
3013 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
3017 static int __e1000_maybe_stop_tx(struct net_device
*netdev
, int size
)
3019 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3020 struct e1000_tx_ring
*tx_ring
= adapter
->tx_ring
;
3022 netif_stop_queue(netdev
);
3023 /* Herbert's original patch had:
3024 * smp_mb__after_netif_stop_queue();
3025 * but since that doesn't exist yet, just open code it. */
3028 /* We need to check again in a case another CPU has just
3029 * made room available. */
3030 if (likely(E1000_DESC_UNUSED(tx_ring
) < size
))
3034 netif_start_queue(netdev
);
3035 ++adapter
->restart_queue
;
3039 static int e1000_maybe_stop_tx(struct net_device
*netdev
,
3040 struct e1000_tx_ring
*tx_ring
, int size
)
3042 if (likely(E1000_DESC_UNUSED(tx_ring
) >= size
))
3044 return __e1000_maybe_stop_tx(netdev
, size
);
3047 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3048 static netdev_tx_t
e1000_xmit_frame(struct sk_buff
*skb
,
3049 struct net_device
*netdev
)
3051 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3052 struct e1000_hw
*hw
= &adapter
->hw
;
3053 struct e1000_tx_ring
*tx_ring
;
3054 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
3055 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
3056 unsigned int tx_flags
= 0;
3057 unsigned int len
= skb_headlen(skb
);
3058 unsigned int nr_frags
;
3064 /* This goes back to the question of how to logically map a tx queue
3065 * to a flow. Right now, performance is impacted slightly negatively
3066 * if using multiple tx queues. If the stack breaks away from a
3067 * single qdisc implementation, we can look at this again. */
3068 tx_ring
= adapter
->tx_ring
;
3070 if (unlikely(skb
->len
<= 0)) {
3071 dev_kfree_skb_any(skb
);
3072 return NETDEV_TX_OK
;
3075 mss
= skb_shinfo(skb
)->gso_size
;
3076 /* The controller does a simple calculation to
3077 * make sure there is enough room in the FIFO before
3078 * initiating the DMA for each buffer. The calc is:
3079 * 4 = ceil(buffer len/mss). To make sure we don't
3080 * overrun the FIFO, adjust the max buffer len if mss
3084 max_per_txd
= min(mss
<< 2, max_per_txd
);
3085 max_txd_pwr
= fls(max_per_txd
) - 1;
3087 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
3088 if (skb
->data_len
&& hdr_len
== len
) {
3089 switch (hw
->mac_type
) {
3090 unsigned int pull_size
;
3092 /* Make sure we have room to chop off 4 bytes,
3093 * and that the end alignment will work out to
3094 * this hardware's requirements
3095 * NOTE: this is a TSO only workaround
3096 * if end byte alignment not correct move us
3097 * into the next dword */
3098 if ((unsigned long)(skb_tail_pointer(skb
) - 1) & 4)
3101 pull_size
= min((unsigned int)4, skb
->data_len
);
3102 if (!__pskb_pull_tail(skb
, pull_size
)) {
3103 e_err(drv
, "__pskb_pull_tail "
3105 dev_kfree_skb_any(skb
);
3106 return NETDEV_TX_OK
;
3108 len
= skb_headlen(skb
);
3117 /* reserve a descriptor for the offload context */
3118 if ((mss
) || (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3122 /* Controller Erratum workaround */
3123 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&& !skb_is_gso(skb
))
3126 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
3128 if (adapter
->pcix_82544
)
3131 /* work-around for errata 10 and it applies to all controllers
3132 * in PCI-X mode, so add one more descriptor to the count
3134 if (unlikely((hw
->bus_type
== e1000_bus_type_pcix
) &&
3138 nr_frags
= skb_shinfo(skb
)->nr_frags
;
3139 for (f
= 0; f
< nr_frags
; f
++)
3140 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
3142 if (adapter
->pcix_82544
)
3145 /* need: count + 2 desc gap to keep tail from touching
3146 * head, otherwise try next time */
3147 if (unlikely(e1000_maybe_stop_tx(netdev
, tx_ring
, count
+ 2)))
3148 return NETDEV_TX_BUSY
;
3150 if (unlikely(hw
->mac_type
== e1000_82547
)) {
3151 if (unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
3152 netif_stop_queue(netdev
);
3153 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3154 mod_timer(&adapter
->tx_fifo_stall_timer
,
3156 return NETDEV_TX_BUSY
;
3160 if (unlikely(vlan_tx_tag_present(skb
))) {
3161 tx_flags
|= E1000_TX_FLAGS_VLAN
;
3162 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
3165 first
= tx_ring
->next_to_use
;
3167 tso
= e1000_tso(adapter
, tx_ring
, skb
);
3169 dev_kfree_skb_any(skb
);
3170 return NETDEV_TX_OK
;
3174 if (likely(hw
->mac_type
!= e1000_82544
))
3175 tx_ring
->last_tx_tso
= 1;
3176 tx_flags
|= E1000_TX_FLAGS_TSO
;
3177 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
3178 tx_flags
|= E1000_TX_FLAGS_CSUM
;
3180 if (likely(skb
->protocol
== htons(ETH_P_IP
)))
3181 tx_flags
|= E1000_TX_FLAGS_IPV4
;
3183 count
= e1000_tx_map(adapter
, tx_ring
, skb
, first
, max_per_txd
,
3187 e1000_tx_queue(adapter
, tx_ring
, tx_flags
, count
);
3188 /* Make sure there is space in the ring for the next send. */
3189 e1000_maybe_stop_tx(netdev
, tx_ring
, MAX_SKB_FRAGS
+ 2);
3192 dev_kfree_skb_any(skb
);
3193 tx_ring
->buffer_info
[first
].time_stamp
= 0;
3194 tx_ring
->next_to_use
= first
;
3197 return NETDEV_TX_OK
;
3201 * e1000_tx_timeout - Respond to a Tx Hang
3202 * @netdev: network interface device structure
3205 static void e1000_tx_timeout(struct net_device
*netdev
)
3207 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3209 /* Do the reset outside of interrupt context */
3210 adapter
->tx_timeout_count
++;
3211 schedule_work(&adapter
->reset_task
);
3214 static void e1000_reset_task(struct work_struct
*work
)
3216 struct e1000_adapter
*adapter
=
3217 container_of(work
, struct e1000_adapter
, reset_task
);
3219 e1000_reinit_safe(adapter
);
3223 * e1000_get_stats - Get System Network Statistics
3224 * @netdev: network interface device structure
3226 * Returns the address of the device statistics structure.
3227 * The statistics are actually updated from the timer callback.
3230 static struct net_device_stats
*e1000_get_stats(struct net_device
*netdev
)
3232 /* only return the current stats */
3233 return &netdev
->stats
;
3237 * e1000_change_mtu - Change the Maximum Transfer Unit
3238 * @netdev: network interface device structure
3239 * @new_mtu: new value for maximum frame size
3241 * Returns 0 on success, negative on failure
3244 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3246 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3247 struct e1000_hw
*hw
= &adapter
->hw
;
3248 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
3250 if ((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
3251 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3252 e_err(probe
, "Invalid MTU setting\n");
3256 /* Adapter-specific max frame size limits. */
3257 switch (hw
->mac_type
) {
3258 case e1000_undefined
... e1000_82542_rev2_1
:
3259 if (max_frame
> (ETH_FRAME_LEN
+ ETH_FCS_LEN
)) {
3260 e_err(probe
, "Jumbo Frames not supported.\n");
3265 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3269 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->flags
))
3271 /* e1000_down has a dependency on max_frame_size */
3272 hw
->max_frame_size
= max_frame
;
3273 if (netif_running(netdev
))
3274 e1000_down(adapter
);
3276 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3277 * means we reserve 2 more, this pushes us to allocate from the next
3279 * i.e. RXBUFFER_2048 --> size-4096 slab
3280 * however with the new *_jumbo_rx* routines, jumbo receives will use
3281 * fragmented skbs */
3283 if (max_frame
<= E1000_RXBUFFER_2048
)
3284 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3286 #if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3287 adapter
->rx_buffer_len
= E1000_RXBUFFER_16384
;
3288 #elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3289 adapter
->rx_buffer_len
= PAGE_SIZE
;
3292 /* adjust allocation if LPE protects us, and we aren't using SBP */
3293 if (!hw
->tbi_compatibility_on
&&
3294 ((max_frame
== (ETH_FRAME_LEN
+ ETH_FCS_LEN
)) ||
3295 (max_frame
== MAXIMUM_ETHERNET_VLAN_SIZE
)))
3296 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3298 pr_info("%s changing MTU from %d to %d\n",
3299 netdev
->name
, netdev
->mtu
, new_mtu
);
3300 netdev
->mtu
= new_mtu
;
3302 if (netif_running(netdev
))
3305 e1000_reset(adapter
);
3307 clear_bit(__E1000_RESETTING
, &adapter
->flags
);
3313 * e1000_update_stats - Update the board statistics counters
3314 * @adapter: board private structure
3317 void e1000_update_stats(struct e1000_adapter
*adapter
)
3319 struct net_device
*netdev
= adapter
->netdev
;
3320 struct e1000_hw
*hw
= &adapter
->hw
;
3321 struct pci_dev
*pdev
= adapter
->pdev
;
3322 unsigned long flags
;
3325 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3328 * Prevent stats update while adapter is being reset, or if the pci
3329 * connection is down.
3331 if (adapter
->link_speed
== 0)
3333 if (pci_channel_offline(pdev
))
3336 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3338 /* these counters are modified from e1000_tbi_adjust_stats,
3339 * called from the interrupt context, so they must only
3340 * be written while holding adapter->stats_lock
3343 adapter
->stats
.crcerrs
+= er32(CRCERRS
);
3344 adapter
->stats
.gprc
+= er32(GPRC
);
3345 adapter
->stats
.gorcl
+= er32(GORCL
);
3346 adapter
->stats
.gorch
+= er32(GORCH
);
3347 adapter
->stats
.bprc
+= er32(BPRC
);
3348 adapter
->stats
.mprc
+= er32(MPRC
);
3349 adapter
->stats
.roc
+= er32(ROC
);
3351 adapter
->stats
.prc64
+= er32(PRC64
);
3352 adapter
->stats
.prc127
+= er32(PRC127
);
3353 adapter
->stats
.prc255
+= er32(PRC255
);
3354 adapter
->stats
.prc511
+= er32(PRC511
);
3355 adapter
->stats
.prc1023
+= er32(PRC1023
);
3356 adapter
->stats
.prc1522
+= er32(PRC1522
);
3358 adapter
->stats
.symerrs
+= er32(SYMERRS
);
3359 adapter
->stats
.mpc
+= er32(MPC
);
3360 adapter
->stats
.scc
+= er32(SCC
);
3361 adapter
->stats
.ecol
+= er32(ECOL
);
3362 adapter
->stats
.mcc
+= er32(MCC
);
3363 adapter
->stats
.latecol
+= er32(LATECOL
);
3364 adapter
->stats
.dc
+= er32(DC
);
3365 adapter
->stats
.sec
+= er32(SEC
);
3366 adapter
->stats
.rlec
+= er32(RLEC
);
3367 adapter
->stats
.xonrxc
+= er32(XONRXC
);
3368 adapter
->stats
.xontxc
+= er32(XONTXC
);
3369 adapter
->stats
.xoffrxc
+= er32(XOFFRXC
);
3370 adapter
->stats
.xofftxc
+= er32(XOFFTXC
);
3371 adapter
->stats
.fcruc
+= er32(FCRUC
);
3372 adapter
->stats
.gptc
+= er32(GPTC
);
3373 adapter
->stats
.gotcl
+= er32(GOTCL
);
3374 adapter
->stats
.gotch
+= er32(GOTCH
);
3375 adapter
->stats
.rnbc
+= er32(RNBC
);
3376 adapter
->stats
.ruc
+= er32(RUC
);
3377 adapter
->stats
.rfc
+= er32(RFC
);
3378 adapter
->stats
.rjc
+= er32(RJC
);
3379 adapter
->stats
.torl
+= er32(TORL
);
3380 adapter
->stats
.torh
+= er32(TORH
);
3381 adapter
->stats
.totl
+= er32(TOTL
);
3382 adapter
->stats
.toth
+= er32(TOTH
);
3383 adapter
->stats
.tpr
+= er32(TPR
);
3385 adapter
->stats
.ptc64
+= er32(PTC64
);
3386 adapter
->stats
.ptc127
+= er32(PTC127
);
3387 adapter
->stats
.ptc255
+= er32(PTC255
);
3388 adapter
->stats
.ptc511
+= er32(PTC511
);
3389 adapter
->stats
.ptc1023
+= er32(PTC1023
);
3390 adapter
->stats
.ptc1522
+= er32(PTC1522
);
3392 adapter
->stats
.mptc
+= er32(MPTC
);
3393 adapter
->stats
.bptc
+= er32(BPTC
);
3395 /* used for adaptive IFS */
3397 hw
->tx_packet_delta
= er32(TPT
);
3398 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3399 hw
->collision_delta
= er32(COLC
);
3400 adapter
->stats
.colc
+= hw
->collision_delta
;
3402 if (hw
->mac_type
>= e1000_82543
) {
3403 adapter
->stats
.algnerrc
+= er32(ALGNERRC
);
3404 adapter
->stats
.rxerrc
+= er32(RXERRC
);
3405 adapter
->stats
.tncrs
+= er32(TNCRS
);
3406 adapter
->stats
.cexterr
+= er32(CEXTERR
);
3407 adapter
->stats
.tsctc
+= er32(TSCTC
);
3408 adapter
->stats
.tsctfc
+= er32(TSCTFC
);
3411 /* Fill out the OS statistics structure */
3412 netdev
->stats
.multicast
= adapter
->stats
.mprc
;
3413 netdev
->stats
.collisions
= adapter
->stats
.colc
;
3417 /* RLEC on some newer hardware can be incorrect so build
3418 * our own version based on RUC and ROC */
3419 netdev
->stats
.rx_errors
= adapter
->stats
.rxerrc
+
3420 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3421 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3422 adapter
->stats
.cexterr
;
3423 adapter
->stats
.rlerrc
= adapter
->stats
.ruc
+ adapter
->stats
.roc
;
3424 netdev
->stats
.rx_length_errors
= adapter
->stats
.rlerrc
;
3425 netdev
->stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3426 netdev
->stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3427 netdev
->stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3430 adapter
->stats
.txerrc
= adapter
->stats
.ecol
+ adapter
->stats
.latecol
;
3431 netdev
->stats
.tx_errors
= adapter
->stats
.txerrc
;
3432 netdev
->stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3433 netdev
->stats
.tx_window_errors
= adapter
->stats
.latecol
;
3434 netdev
->stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3435 if (hw
->bad_tx_carr_stats_fd
&&
3436 adapter
->link_duplex
== FULL_DUPLEX
) {
3437 netdev
->stats
.tx_carrier_errors
= 0;
3438 adapter
->stats
.tncrs
= 0;
3441 /* Tx Dropped needs to be maintained elsewhere */
3444 if (hw
->media_type
== e1000_media_type_copper
) {
3445 if ((adapter
->link_speed
== SPEED_1000
) &&
3446 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3447 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3448 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3451 if ((hw
->mac_type
<= e1000_82546
) &&
3452 (hw
->phy_type
== e1000_phy_m88
) &&
3453 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3454 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3457 /* Management Stats */
3458 if (hw
->has_smbus
) {
3459 adapter
->stats
.mgptc
+= er32(MGTPTC
);
3460 adapter
->stats
.mgprc
+= er32(MGTPRC
);
3461 adapter
->stats
.mgpdc
+= er32(MGTPDC
);
3464 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3468 * e1000_intr - Interrupt Handler
3469 * @irq: interrupt number
3470 * @data: pointer to a network interface device structure
3473 static irqreturn_t
e1000_intr(int irq
, void *data
)
3475 struct net_device
*netdev
= data
;
3476 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3477 struct e1000_hw
*hw
= &adapter
->hw
;
3478 u32 icr
= er32(ICR
);
3480 if (unlikely((!icr
)))
3481 return IRQ_NONE
; /* Not our interrupt */
3484 * we might have caused the interrupt, but the above
3485 * read cleared it, and just in case the driver is
3486 * down there is nothing to do so return handled
3488 if (unlikely(test_bit(__E1000_DOWN
, &adapter
->flags
)))
3491 if (unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3492 hw
->get_link_status
= 1;
3493 /* guard against interrupt when we're going down */
3494 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3495 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3498 /* disable interrupts, without the synchronize_irq bit */
3500 E1000_WRITE_FLUSH();
3502 if (likely(napi_schedule_prep(&adapter
->napi
))) {
3503 adapter
->total_tx_bytes
= 0;
3504 adapter
->total_tx_packets
= 0;
3505 adapter
->total_rx_bytes
= 0;
3506 adapter
->total_rx_packets
= 0;
3507 __napi_schedule(&adapter
->napi
);
3509 /* this really should not happen! if it does it is basically a
3510 * bug, but not a hard error, so enable ints and continue */
3511 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3512 e1000_irq_enable(adapter
);
3519 * e1000_clean - NAPI Rx polling callback
3520 * @adapter: board private structure
3522 static int e1000_clean(struct napi_struct
*napi
, int budget
)
3524 struct e1000_adapter
*adapter
= container_of(napi
, struct e1000_adapter
, napi
);
3525 int tx_clean_complete
= 0, work_done
= 0;
3527 tx_clean_complete
= e1000_clean_tx_irq(adapter
, &adapter
->tx_ring
[0]);
3529 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[0], &work_done
, budget
);
3531 if (!tx_clean_complete
)
3534 /* If budget not fully consumed, exit the polling mode */
3535 if (work_done
< budget
) {
3536 if (likely(adapter
->itr_setting
& 3))
3537 e1000_set_itr(adapter
);
3538 napi_complete(napi
);
3539 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
3540 e1000_irq_enable(adapter
);
3547 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3548 * @adapter: board private structure
3550 static bool e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
3551 struct e1000_tx_ring
*tx_ring
)
3553 struct e1000_hw
*hw
= &adapter
->hw
;
3554 struct net_device
*netdev
= adapter
->netdev
;
3555 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
3556 struct e1000_buffer
*buffer_info
;
3557 unsigned int i
, eop
;
3558 unsigned int count
= 0;
3559 unsigned int total_tx_bytes
=0, total_tx_packets
=0;
3561 i
= tx_ring
->next_to_clean
;
3562 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3563 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3565 while ((eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) &&
3566 (count
< tx_ring
->count
)) {
3567 bool cleaned
= false;
3568 rmb(); /* read buffer_info after eop_desc */
3569 for ( ; !cleaned
; count
++) {
3570 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3571 buffer_info
= &tx_ring
->buffer_info
[i
];
3572 cleaned
= (i
== eop
);
3575 struct sk_buff
*skb
= buffer_info
->skb
;
3576 unsigned int segs
, bytecount
;
3577 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
3578 /* multiply data chunks by size of headers */
3579 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
3581 total_tx_packets
+= segs
;
3582 total_tx_bytes
+= bytecount
;
3584 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
3585 tx_desc
->upper
.data
= 0;
3587 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
3590 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3591 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3594 tx_ring
->next_to_clean
= i
;
3596 #define TX_WAKE_THRESHOLD 32
3597 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
3598 E1000_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
)) {
3599 /* Make sure that anybody stopping the queue after this
3600 * sees the new next_to_clean.
3604 if (netif_queue_stopped(netdev
) &&
3605 !(test_bit(__E1000_DOWN
, &adapter
->flags
))) {
3606 netif_wake_queue(netdev
);
3607 ++adapter
->restart_queue
;
3611 if (adapter
->detect_tx_hung
) {
3612 /* Detect a transmit hang in hardware, this serializes the
3613 * check with the clearing of time_stamp and movement of i */
3614 adapter
->detect_tx_hung
= false;
3615 if (tx_ring
->buffer_info
[eop
].time_stamp
&&
3616 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
+
3617 (adapter
->tx_timeout_factor
* HZ
)) &&
3618 !(er32(STATUS
) & E1000_STATUS_TXOFF
)) {
3620 /* detected Tx unit hang */
3621 e_err(drv
, "Detected Tx Unit Hang\n"
3625 " next_to_use <%x>\n"
3626 " next_to_clean <%x>\n"
3627 "buffer_info[next_to_clean]\n"
3628 " time_stamp <%lx>\n"
3629 " next_to_watch <%x>\n"
3631 " next_to_watch.status <%x>\n",
3632 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
3633 sizeof(struct e1000_tx_ring
)),
3634 readl(hw
->hw_addr
+ tx_ring
->tdh
),
3635 readl(hw
->hw_addr
+ tx_ring
->tdt
),
3636 tx_ring
->next_to_use
,
3637 tx_ring
->next_to_clean
,
3638 tx_ring
->buffer_info
[eop
].time_stamp
,
3641 eop_desc
->upper
.fields
.status
);
3642 netif_stop_queue(netdev
);
3645 adapter
->total_tx_bytes
+= total_tx_bytes
;
3646 adapter
->total_tx_packets
+= total_tx_packets
;
3647 netdev
->stats
.tx_bytes
+= total_tx_bytes
;
3648 netdev
->stats
.tx_packets
+= total_tx_packets
;
3649 return count
< tx_ring
->count
;
3653 * e1000_rx_checksum - Receive Checksum Offload for 82543
3654 * @adapter: board private structure
3655 * @status_err: receive descriptor status and error fields
3656 * @csum: receive descriptor csum field
3657 * @sk_buff: socket buffer with received data
3660 static void e1000_rx_checksum(struct e1000_adapter
*adapter
, u32 status_err
,
3661 u32 csum
, struct sk_buff
*skb
)
3663 struct e1000_hw
*hw
= &adapter
->hw
;
3664 u16 status
= (u16
)status_err
;
3665 u8 errors
= (u8
)(status_err
>> 24);
3667 skb_checksum_none_assert(skb
);
3669 /* 82543 or newer only */
3670 if (unlikely(hw
->mac_type
< e1000_82543
)) return;
3671 /* Ignore Checksum bit is set */
3672 if (unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
3673 /* TCP/UDP checksum error bit is set */
3674 if (unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
3675 /* let the stack verify checksum errors */
3676 adapter
->hw_csum_err
++;
3679 /* TCP/UDP Checksum has not been calculated */
3680 if (!(status
& E1000_RXD_STAT_TCPCS
))
3683 /* It must be a TCP or UDP packet with a valid checksum */
3684 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
3685 /* TCP checksum is good */
3686 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3688 adapter
->hw_csum_good
++;
3692 * e1000_consume_page - helper function
3694 static void e1000_consume_page(struct e1000_buffer
*bi
, struct sk_buff
*skb
,
3699 skb
->data_len
+= length
;
3700 skb
->truesize
+= length
;
3704 * e1000_receive_skb - helper function to handle rx indications
3705 * @adapter: board private structure
3706 * @status: descriptor status field as written by hardware
3707 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
3708 * @skb: pointer to sk_buff to be indicated to stack
3710 static void e1000_receive_skb(struct e1000_adapter
*adapter
, u8 status
,
3711 __le16 vlan
, struct sk_buff
*skb
)
3713 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
3715 if ((unlikely(adapter
->vlgrp
&& (status
& E1000_RXD_STAT_VP
))))
3716 vlan_gro_receive(&adapter
->napi
, adapter
->vlgrp
,
3717 le16_to_cpu(vlan
) & E1000_RXD_SPC_VLAN_MASK
,
3720 napi_gro_receive(&adapter
->napi
, skb
);
3724 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
3725 * @adapter: board private structure
3726 * @rx_ring: ring to clean
3727 * @work_done: amount of napi work completed this call
3728 * @work_to_do: max amount of work allowed for this call to do
3730 * the return value indicates whether actual cleaning was done, there
3731 * is no guarantee that everything was cleaned
3733 static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter
*adapter
,
3734 struct e1000_rx_ring
*rx_ring
,
3735 int *work_done
, int work_to_do
)
3737 struct e1000_hw
*hw
= &adapter
->hw
;
3738 struct net_device
*netdev
= adapter
->netdev
;
3739 struct pci_dev
*pdev
= adapter
->pdev
;
3740 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
3741 struct e1000_buffer
*buffer_info
, *next_buffer
;
3742 unsigned long irq_flags
;
3745 int cleaned_count
= 0;
3746 bool cleaned
= false;
3747 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
3749 i
= rx_ring
->next_to_clean
;
3750 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3751 buffer_info
= &rx_ring
->buffer_info
[i
];
3753 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
3754 struct sk_buff
*skb
;
3757 if (*work_done
>= work_to_do
)
3760 rmb(); /* read descriptor and rx_buffer_info after status DD */
3762 status
= rx_desc
->status
;
3763 skb
= buffer_info
->skb
;
3764 buffer_info
->skb
= NULL
;
3766 if (++i
== rx_ring
->count
) i
= 0;
3767 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
3770 next_buffer
= &rx_ring
->buffer_info
[i
];
3774 dma_unmap_page(&pdev
->dev
, buffer_info
->dma
,
3775 buffer_info
->length
, DMA_FROM_DEVICE
);
3776 buffer_info
->dma
= 0;
3778 length
= le16_to_cpu(rx_desc
->length
);
3780 /* errors is only valid for DD + EOP descriptors */
3781 if (unlikely((status
& E1000_RXD_STAT_EOP
) &&
3782 (rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
))) {
3783 u8 last_byte
= *(skb
->data
+ length
- 1);
3784 if (TBI_ACCEPT(hw
, status
, rx_desc
->errors
, length
,
3786 spin_lock_irqsave(&adapter
->stats_lock
,
3788 e1000_tbi_adjust_stats(hw
, &adapter
->stats
,
3790 spin_unlock_irqrestore(&adapter
->stats_lock
,
3794 /* recycle both page and skb */
3795 buffer_info
->skb
= skb
;
3796 /* an error means any chain goes out the window
3798 if (rx_ring
->rx_skb_top
)
3799 dev_kfree_skb(rx_ring
->rx_skb_top
);
3800 rx_ring
->rx_skb_top
= NULL
;
3805 #define rxtop rx_ring->rx_skb_top
3806 if (!(status
& E1000_RXD_STAT_EOP
)) {
3807 /* this descriptor is only the beginning (or middle) */
3809 /* this is the beginning of a chain */
3811 skb_fill_page_desc(rxtop
, 0, buffer_info
->page
,
3814 /* this is the middle of a chain */
3815 skb_fill_page_desc(rxtop
,
3816 skb_shinfo(rxtop
)->nr_frags
,
3817 buffer_info
->page
, 0, length
);
3818 /* re-use the skb, only consumed the page */
3819 buffer_info
->skb
= skb
;
3821 e1000_consume_page(buffer_info
, rxtop
, length
);
3825 /* end of the chain */
3826 skb_fill_page_desc(rxtop
,
3827 skb_shinfo(rxtop
)->nr_frags
,
3828 buffer_info
->page
, 0, length
);
3829 /* re-use the current skb, we only consumed the
3831 buffer_info
->skb
= skb
;
3834 e1000_consume_page(buffer_info
, skb
, length
);
3836 /* no chain, got EOP, this buf is the packet
3837 * copybreak to save the put_page/alloc_page */
3838 if (length
<= copybreak
&&
3839 skb_tailroom(skb
) >= length
) {
3841 vaddr
= kmap_atomic(buffer_info
->page
,
3842 KM_SKB_DATA_SOFTIRQ
);
3843 memcpy(skb_tail_pointer(skb
), vaddr
, length
);
3844 kunmap_atomic(vaddr
,
3845 KM_SKB_DATA_SOFTIRQ
);
3846 /* re-use the page, so don't erase
3847 * buffer_info->page */
3848 skb_put(skb
, length
);
3850 skb_fill_page_desc(skb
, 0,
3851 buffer_info
->page
, 0,
3853 e1000_consume_page(buffer_info
, skb
,
3859 /* Receive Checksum Offload XXX recompute due to CRC strip? */
3860 e1000_rx_checksum(adapter
,
3862 ((u32
)(rx_desc
->errors
) << 24),
3863 le16_to_cpu(rx_desc
->csum
), skb
);
3865 pskb_trim(skb
, skb
->len
- 4);
3867 /* probably a little skewed due to removing CRC */
3868 total_rx_bytes
+= skb
->len
;
3871 /* eth type trans needs skb->data to point to something */
3872 if (!pskb_may_pull(skb
, ETH_HLEN
)) {
3873 e_err(drv
, "pskb_may_pull failed.\n");
3878 e1000_receive_skb(adapter
, status
, rx_desc
->special
, skb
);
3881 rx_desc
->status
= 0;
3883 /* return some buffers to hardware, one at a time is too slow */
3884 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
3885 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3889 /* use prefetched values */
3891 buffer_info
= next_buffer
;
3893 rx_ring
->next_to_clean
= i
;
3895 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
3897 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3899 adapter
->total_rx_packets
+= total_rx_packets
;
3900 adapter
->total_rx_bytes
+= total_rx_bytes
;
3901 netdev
->stats
.rx_bytes
+= total_rx_bytes
;
3902 netdev
->stats
.rx_packets
+= total_rx_packets
;
3907 * this should improve performance for small packets with large amounts
3908 * of reassembly being done in the stack
3910 static void e1000_check_copybreak(struct net_device
*netdev
,
3911 struct e1000_buffer
*buffer_info
,
3912 u32 length
, struct sk_buff
**skb
)
3914 struct sk_buff
*new_skb
;
3916 if (length
> copybreak
)
3919 new_skb
= netdev_alloc_skb_ip_align(netdev
, length
);
3923 skb_copy_to_linear_data_offset(new_skb
, -NET_IP_ALIGN
,
3924 (*skb
)->data
- NET_IP_ALIGN
,
3925 length
+ NET_IP_ALIGN
);
3926 /* save the skb in buffer_info as good */
3927 buffer_info
->skb
= *skb
;
3932 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3933 * @adapter: board private structure
3934 * @rx_ring: ring to clean
3935 * @work_done: amount of napi work completed this call
3936 * @work_to_do: max amount of work allowed for this call to do
3938 static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3939 struct e1000_rx_ring
*rx_ring
,
3940 int *work_done
, int work_to_do
)
3942 struct e1000_hw
*hw
= &adapter
->hw
;
3943 struct net_device
*netdev
= adapter
->netdev
;
3944 struct pci_dev
*pdev
= adapter
->pdev
;
3945 struct e1000_rx_desc
*rx_desc
, *next_rxd
;
3946 struct e1000_buffer
*buffer_info
, *next_buffer
;
3947 unsigned long flags
;
3950 int cleaned_count
= 0;
3951 bool cleaned
= false;
3952 unsigned int total_rx_bytes
=0, total_rx_packets
=0;
3954 i
= rx_ring
->next_to_clean
;
3955 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3956 buffer_info
= &rx_ring
->buffer_info
[i
];
3958 while (rx_desc
->status
& E1000_RXD_STAT_DD
) {
3959 struct sk_buff
*skb
;
3962 if (*work_done
>= work_to_do
)
3965 rmb(); /* read descriptor and rx_buffer_info after status DD */
3967 status
= rx_desc
->status
;
3968 skb
= buffer_info
->skb
;
3969 buffer_info
->skb
= NULL
;
3971 prefetch(skb
->data
- NET_IP_ALIGN
);
3973 if (++i
== rx_ring
->count
) i
= 0;
3974 next_rxd
= E1000_RX_DESC(*rx_ring
, i
);
3977 next_buffer
= &rx_ring
->buffer_info
[i
];
3981 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
3982 buffer_info
->length
, DMA_FROM_DEVICE
);
3983 buffer_info
->dma
= 0;
3985 length
= le16_to_cpu(rx_desc
->length
);
3986 /* !EOP means multiple descriptors were used to store a single
3987 * packet, if thats the case we need to toss it. In fact, we
3988 * to toss every packet with the EOP bit clear and the next
3989 * frame that _does_ have the EOP bit set, as it is by
3990 * definition only a frame fragment
3992 if (unlikely(!(status
& E1000_RXD_STAT_EOP
)))
3993 adapter
->discarding
= true;
3995 if (adapter
->discarding
) {
3996 /* All receives must fit into a single buffer */
3997 e_dbg("Receive packet consumed multiple buffers\n");
3999 buffer_info
->skb
= skb
;
4000 if (status
& E1000_RXD_STAT_EOP
)
4001 adapter
->discarding
= false;
4005 if (unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
4006 u8 last_byte
= *(skb
->data
+ length
- 1);
4007 if (TBI_ACCEPT(hw
, status
, rx_desc
->errors
, length
,
4009 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4010 e1000_tbi_adjust_stats(hw
, &adapter
->stats
,
4012 spin_unlock_irqrestore(&adapter
->stats_lock
,
4017 buffer_info
->skb
= skb
;
4022 /* adjust length to remove Ethernet CRC, this must be
4023 * done after the TBI_ACCEPT workaround above */
4026 /* probably a little skewed due to removing CRC */
4027 total_rx_bytes
+= length
;
4030 e1000_check_copybreak(netdev
, buffer_info
, length
, &skb
);
4032 skb_put(skb
, length
);
4034 /* Receive Checksum Offload */
4035 e1000_rx_checksum(adapter
,
4037 ((u32
)(rx_desc
->errors
) << 24),
4038 le16_to_cpu(rx_desc
->csum
), skb
);
4040 e1000_receive_skb(adapter
, status
, rx_desc
->special
, skb
);
4043 rx_desc
->status
= 0;
4045 /* return some buffers to hardware, one at a time is too slow */
4046 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
4047 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4051 /* use prefetched values */
4053 buffer_info
= next_buffer
;
4055 rx_ring
->next_to_clean
= i
;
4057 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
4059 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
4061 adapter
->total_rx_packets
+= total_rx_packets
;
4062 adapter
->total_rx_bytes
+= total_rx_bytes
;
4063 netdev
->stats
.rx_bytes
+= total_rx_bytes
;
4064 netdev
->stats
.rx_packets
+= total_rx_packets
;
4069 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4070 * @adapter: address of board private structure
4071 * @rx_ring: pointer to receive ring structure
4072 * @cleaned_count: number of buffers to allocate this pass
4076 e1000_alloc_jumbo_rx_buffers(struct e1000_adapter
*adapter
,
4077 struct e1000_rx_ring
*rx_ring
, int cleaned_count
)
4079 struct net_device
*netdev
= adapter
->netdev
;
4080 struct pci_dev
*pdev
= adapter
->pdev
;
4081 struct e1000_rx_desc
*rx_desc
;
4082 struct e1000_buffer
*buffer_info
;
4083 struct sk_buff
*skb
;
4085 unsigned int bufsz
= 256 - 16 /*for skb_reserve */ ;
4087 i
= rx_ring
->next_to_use
;
4088 buffer_info
= &rx_ring
->buffer_info
[i
];
4090 while (cleaned_count
--) {
4091 skb
= buffer_info
->skb
;
4097 skb
= netdev_alloc_skb_ip_align(netdev
, bufsz
);
4098 if (unlikely(!skb
)) {
4099 /* Better luck next round */
4100 adapter
->alloc_rx_buff_failed
++;
4104 /* Fix for errata 23, can't cross 64kB boundary */
4105 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4106 struct sk_buff
*oldskb
= skb
;
4107 e_err(rx_err
, "skb align check failed: %u bytes at "
4108 "%p\n", bufsz
, skb
->data
);
4109 /* Try again, without freeing the previous */
4110 skb
= netdev_alloc_skb_ip_align(netdev
, bufsz
);
4111 /* Failed allocation, critical failure */
4113 dev_kfree_skb(oldskb
);
4114 adapter
->alloc_rx_buff_failed
++;
4118 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4121 dev_kfree_skb(oldskb
);
4122 break; /* while (cleaned_count--) */
4125 /* Use new allocation */
4126 dev_kfree_skb(oldskb
);
4128 buffer_info
->skb
= skb
;
4129 buffer_info
->length
= adapter
->rx_buffer_len
;
4131 /* allocate a new page if necessary */
4132 if (!buffer_info
->page
) {
4133 buffer_info
->page
= alloc_page(GFP_ATOMIC
);
4134 if (unlikely(!buffer_info
->page
)) {
4135 adapter
->alloc_rx_buff_failed
++;
4140 if (!buffer_info
->dma
) {
4141 buffer_info
->dma
= dma_map_page(&pdev
->dev
,
4142 buffer_info
->page
, 0,
4143 buffer_info
->length
,
4145 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
)) {
4146 put_page(buffer_info
->page
);
4148 buffer_info
->page
= NULL
;
4149 buffer_info
->skb
= NULL
;
4150 buffer_info
->dma
= 0;
4151 adapter
->alloc_rx_buff_failed
++;
4152 break; /* while !buffer_info->skb */
4156 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4157 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4159 if (unlikely(++i
== rx_ring
->count
))
4161 buffer_info
= &rx_ring
->buffer_info
[i
];
4164 if (likely(rx_ring
->next_to_use
!= i
)) {
4165 rx_ring
->next_to_use
= i
;
4166 if (unlikely(i
-- == 0))
4167 i
= (rx_ring
->count
- 1);
4169 /* Force memory writes to complete before letting h/w
4170 * know there are new descriptors to fetch. (Only
4171 * applicable for weak-ordered memory model archs,
4172 * such as IA-64). */
4174 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4179 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4180 * @adapter: address of board private structure
4183 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
4184 struct e1000_rx_ring
*rx_ring
,
4187 struct e1000_hw
*hw
= &adapter
->hw
;
4188 struct net_device
*netdev
= adapter
->netdev
;
4189 struct pci_dev
*pdev
= adapter
->pdev
;
4190 struct e1000_rx_desc
*rx_desc
;
4191 struct e1000_buffer
*buffer_info
;
4192 struct sk_buff
*skb
;
4194 unsigned int bufsz
= adapter
->rx_buffer_len
;
4196 i
= rx_ring
->next_to_use
;
4197 buffer_info
= &rx_ring
->buffer_info
[i
];
4199 while (cleaned_count
--) {
4200 skb
= buffer_info
->skb
;
4206 skb
= netdev_alloc_skb_ip_align(netdev
, bufsz
);
4207 if (unlikely(!skb
)) {
4208 /* Better luck next round */
4209 adapter
->alloc_rx_buff_failed
++;
4213 /* Fix for errata 23, can't cross 64kB boundary */
4214 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4215 struct sk_buff
*oldskb
= skb
;
4216 e_err(rx_err
, "skb align check failed: %u bytes at "
4217 "%p\n", bufsz
, skb
->data
);
4218 /* Try again, without freeing the previous */
4219 skb
= netdev_alloc_skb_ip_align(netdev
, bufsz
);
4220 /* Failed allocation, critical failure */
4222 dev_kfree_skb(oldskb
);
4223 adapter
->alloc_rx_buff_failed
++;
4227 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
4230 dev_kfree_skb(oldskb
);
4231 adapter
->alloc_rx_buff_failed
++;
4232 break; /* while !buffer_info->skb */
4235 /* Use new allocation */
4236 dev_kfree_skb(oldskb
);
4238 buffer_info
->skb
= skb
;
4239 buffer_info
->length
= adapter
->rx_buffer_len
;
4241 buffer_info
->dma
= dma_map_single(&pdev
->dev
,
4243 buffer_info
->length
,
4245 if (dma_mapping_error(&pdev
->dev
, buffer_info
->dma
)) {
4247 buffer_info
->skb
= NULL
;
4248 buffer_info
->dma
= 0;
4249 adapter
->alloc_rx_buff_failed
++;
4250 break; /* while !buffer_info->skb */
4254 * XXX if it was allocated cleanly it will never map to a
4258 /* Fix for errata 23, can't cross 64kB boundary */
4259 if (!e1000_check_64k_bound(adapter
,
4260 (void *)(unsigned long)buffer_info
->dma
,
4261 adapter
->rx_buffer_len
)) {
4262 e_err(rx_err
, "dma align check failed: %u bytes at "
4263 "%p\n", adapter
->rx_buffer_len
,
4264 (void *)(unsigned long)buffer_info
->dma
);
4266 buffer_info
->skb
= NULL
;
4268 dma_unmap_single(&pdev
->dev
, buffer_info
->dma
,
4269 adapter
->rx_buffer_len
,
4271 buffer_info
->dma
= 0;
4273 adapter
->alloc_rx_buff_failed
++;
4274 break; /* while !buffer_info->skb */
4276 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
4277 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
4279 if (unlikely(++i
== rx_ring
->count
))
4281 buffer_info
= &rx_ring
->buffer_info
[i
];
4284 if (likely(rx_ring
->next_to_use
!= i
)) {
4285 rx_ring
->next_to_use
= i
;
4286 if (unlikely(i
-- == 0))
4287 i
= (rx_ring
->count
- 1);
4289 /* Force memory writes to complete before letting h/w
4290 * know there are new descriptors to fetch. (Only
4291 * applicable for weak-ordered memory model archs,
4292 * such as IA-64). */
4294 writel(i
, hw
->hw_addr
+ rx_ring
->rdt
);
4299 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4303 static void e1000_smartspeed(struct e1000_adapter
*adapter
)
4305 struct e1000_hw
*hw
= &adapter
->hw
;
4309 if ((hw
->phy_type
!= e1000_phy_igp
) || !hw
->autoneg
||
4310 !(hw
->autoneg_advertised
& ADVERTISE_1000_FULL
))
4313 if (adapter
->smartspeed
== 0) {
4314 /* If Master/Slave config fault is asserted twice,
4315 * we assume back-to-back */
4316 e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_status
);
4317 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4318 e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_status
);
4319 if (!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4320 e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4321 if (phy_ctrl
& CR_1000T_MS_ENABLE
) {
4322 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
4323 e1000_write_phy_reg(hw
, PHY_1000T_CTRL
,
4325 adapter
->smartspeed
++;
4326 if (!e1000_phy_setup_autoneg(hw
) &&
4327 !e1000_read_phy_reg(hw
, PHY_CTRL
,
4329 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4330 MII_CR_RESTART_AUTO_NEG
);
4331 e1000_write_phy_reg(hw
, PHY_CTRL
,
4336 } else if (adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
4337 /* If still no link, perhaps using 2/3 pair cable */
4338 e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4339 phy_ctrl
|= CR_1000T_MS_ENABLE
;
4340 e1000_write_phy_reg(hw
, PHY_1000T_CTRL
, phy_ctrl
);
4341 if (!e1000_phy_setup_autoneg(hw
) &&
4342 !e1000_read_phy_reg(hw
, PHY_CTRL
, &phy_ctrl
)) {
4343 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4344 MII_CR_RESTART_AUTO_NEG
);
4345 e1000_write_phy_reg(hw
, PHY_CTRL
, phy_ctrl
);
4348 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4349 if (adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
4350 adapter
->smartspeed
= 0;
4360 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4366 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4379 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
4382 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4383 struct e1000_hw
*hw
= &adapter
->hw
;
4384 struct mii_ioctl_data
*data
= if_mii(ifr
);
4387 unsigned long flags
;
4389 if (hw
->media_type
!= e1000_media_type_copper
)
4394 data
->phy_id
= hw
->phy_addr
;
4397 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4398 if (e1000_read_phy_reg(hw
, data
->reg_num
& 0x1F,
4400 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4403 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4406 if (data
->reg_num
& ~(0x1F))
4408 mii_reg
= data
->val_in
;
4409 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4410 if (e1000_write_phy_reg(hw
, data
->reg_num
,
4412 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4415 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4416 if (hw
->media_type
== e1000_media_type_copper
) {
4417 switch (data
->reg_num
) {
4419 if (mii_reg
& MII_CR_POWER_DOWN
)
4421 if (mii_reg
& MII_CR_AUTO_NEG_EN
) {
4423 hw
->autoneg_advertised
= 0x2F;
4428 else if (mii_reg
& 0x2000)
4432 retval
= e1000_set_spd_dplx(
4440 if (netif_running(adapter
->netdev
))
4441 e1000_reinit_locked(adapter
);
4443 e1000_reset(adapter
);
4445 case M88E1000_PHY_SPEC_CTRL
:
4446 case M88E1000_EXT_PHY_SPEC_CTRL
:
4447 if (e1000_phy_reset(hw
))
4452 switch (data
->reg_num
) {
4454 if (mii_reg
& MII_CR_POWER_DOWN
)
4456 if (netif_running(adapter
->netdev
))
4457 e1000_reinit_locked(adapter
);
4459 e1000_reset(adapter
);
4467 return E1000_SUCCESS
;
4470 void e1000_pci_set_mwi(struct e1000_hw
*hw
)
4472 struct e1000_adapter
*adapter
= hw
->back
;
4473 int ret_val
= pci_set_mwi(adapter
->pdev
);
4476 e_err(probe
, "Error in setting MWI\n");
4479 void e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4481 struct e1000_adapter
*adapter
= hw
->back
;
4483 pci_clear_mwi(adapter
->pdev
);
4486 int e1000_pcix_get_mmrbc(struct e1000_hw
*hw
)
4488 struct e1000_adapter
*adapter
= hw
->back
;
4489 return pcix_get_mmrbc(adapter
->pdev
);
4492 void e1000_pcix_set_mmrbc(struct e1000_hw
*hw
, int mmrbc
)
4494 struct e1000_adapter
*adapter
= hw
->back
;
4495 pcix_set_mmrbc(adapter
->pdev
, mmrbc
);
4498 void e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, u32 value
)
4503 static void e1000_vlan_rx_register(struct net_device
*netdev
,
4504 struct vlan_group
*grp
)
4506 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4507 struct e1000_hw
*hw
= &adapter
->hw
;
4510 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4511 e1000_irq_disable(adapter
);
4512 adapter
->vlgrp
= grp
;
4515 /* enable VLAN tag insert/strip */
4517 ctrl
|= E1000_CTRL_VME
;
4520 /* enable VLAN receive filtering */
4522 rctl
&= ~E1000_RCTL_CFIEN
;
4523 if (!(netdev
->flags
& IFF_PROMISC
))
4524 rctl
|= E1000_RCTL_VFE
;
4526 e1000_update_mng_vlan(adapter
);
4528 /* disable VLAN tag insert/strip */
4530 ctrl
&= ~E1000_CTRL_VME
;
4533 /* disable VLAN receive filtering */
4535 rctl
&= ~E1000_RCTL_VFE
;
4538 if (adapter
->mng_vlan_id
!= (u16
)E1000_MNG_VLAN_NONE
) {
4539 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
4540 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
4544 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4545 e1000_irq_enable(adapter
);
4548 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
4550 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4551 struct e1000_hw
*hw
= &adapter
->hw
;
4554 if ((hw
->mng_cookie
.status
&
4555 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4556 (vid
== adapter
->mng_vlan_id
))
4558 /* add VID to filter table */
4559 index
= (vid
>> 5) & 0x7F;
4560 vfta
= E1000_READ_REG_ARRAY(hw
, VFTA
, index
);
4561 vfta
|= (1 << (vid
& 0x1F));
4562 e1000_write_vfta(hw
, index
, vfta
);
4565 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
4567 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4568 struct e1000_hw
*hw
= &adapter
->hw
;
4571 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4572 e1000_irq_disable(adapter
);
4573 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
4574 if (!test_bit(__E1000_DOWN
, &adapter
->flags
))
4575 e1000_irq_enable(adapter
);
4577 /* remove VID from filter table */
4578 index
= (vid
>> 5) & 0x7F;
4579 vfta
= E1000_READ_REG_ARRAY(hw
, VFTA
, index
);
4580 vfta
&= ~(1 << (vid
& 0x1F));
4581 e1000_write_vfta(hw
, index
, vfta
);
4584 static void e1000_restore_vlan(struct e1000_adapter
*adapter
)
4586 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
4588 if (adapter
->vlgrp
) {
4590 for (vid
= 0; vid
< VLAN_N_VID
; vid
++) {
4591 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
4593 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
4598 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u32 spd
, u8 dplx
)
4600 struct e1000_hw
*hw
= &adapter
->hw
;
4604 /* Make sure dplx is at most 1 bit and lsb of speed is not set
4605 * for the switch() below to work */
4606 if ((spd
& 1) || (dplx
& ~1))
4609 /* Fiber NICs only allow 1000 gbps Full duplex */
4610 if ((hw
->media_type
== e1000_media_type_fiber
) &&
4611 spd
!= SPEED_1000
&&
4612 dplx
!= DUPLEX_FULL
)
4615 switch (spd
+ dplx
) {
4616 case SPEED_10
+ DUPLEX_HALF
:
4617 hw
->forced_speed_duplex
= e1000_10_half
;
4619 case SPEED_10
+ DUPLEX_FULL
:
4620 hw
->forced_speed_duplex
= e1000_10_full
;
4622 case SPEED_100
+ DUPLEX_HALF
:
4623 hw
->forced_speed_duplex
= e1000_100_half
;
4625 case SPEED_100
+ DUPLEX_FULL
:
4626 hw
->forced_speed_duplex
= e1000_100_full
;
4628 case SPEED_1000
+ DUPLEX_FULL
:
4630 hw
->autoneg_advertised
= ADVERTISE_1000_FULL
;
4632 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
4639 e_err(probe
, "Unsupported Speed/Duplex configuration\n");
4643 static int __e1000_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
4645 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4646 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4647 struct e1000_hw
*hw
= &adapter
->hw
;
4648 u32 ctrl
, ctrl_ext
, rctl
, status
;
4649 u32 wufc
= adapter
->wol
;
4654 netif_device_detach(netdev
);
4656 if (netif_running(netdev
)) {
4657 WARN_ON(test_bit(__E1000_RESETTING
, &adapter
->flags
));
4658 e1000_down(adapter
);
4662 retval
= pci_save_state(pdev
);
4667 status
= er32(STATUS
);
4668 if (status
& E1000_STATUS_LU
)
4669 wufc
&= ~E1000_WUFC_LNKC
;
4672 e1000_setup_rctl(adapter
);
4673 e1000_set_rx_mode(netdev
);
4675 /* turn on all-multi mode if wake on multicast is enabled */
4676 if (wufc
& E1000_WUFC_MC
) {
4678 rctl
|= E1000_RCTL_MPE
;
4682 if (hw
->mac_type
>= e1000_82540
) {
4684 /* advertise wake from D3Cold */
4685 #define E1000_CTRL_ADVD3WUC 0x00100000
4686 /* phy power management enable */
4687 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4688 ctrl
|= E1000_CTRL_ADVD3WUC
|
4689 E1000_CTRL_EN_PHY_PWR_MGMT
;
4693 if (hw
->media_type
== e1000_media_type_fiber
||
4694 hw
->media_type
== e1000_media_type_internal_serdes
) {
4695 /* keep the laser running in D3 */
4696 ctrl_ext
= er32(CTRL_EXT
);
4697 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
4698 ew32(CTRL_EXT
, ctrl_ext
);
4701 ew32(WUC
, E1000_WUC_PME_EN
);
4708 e1000_release_manageability(adapter
);
4710 *enable_wake
= !!wufc
;
4712 /* make sure adapter isn't asleep if manageability is enabled */
4713 if (adapter
->en_mng_pt
)
4714 *enable_wake
= true;
4716 if (netif_running(netdev
))
4717 e1000_free_irq(adapter
);
4719 pci_disable_device(pdev
);
4725 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4730 retval
= __e1000_shutdown(pdev
, &wake
);
4735 pci_prepare_to_sleep(pdev
);
4737 pci_wake_from_d3(pdev
, false);
4738 pci_set_power_state(pdev
, PCI_D3hot
);
4744 static int e1000_resume(struct pci_dev
*pdev
)
4746 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4747 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4748 struct e1000_hw
*hw
= &adapter
->hw
;
4751 pci_set_power_state(pdev
, PCI_D0
);
4752 pci_restore_state(pdev
);
4753 pci_save_state(pdev
);
4755 if (adapter
->need_ioport
)
4756 err
= pci_enable_device(pdev
);
4758 err
= pci_enable_device_mem(pdev
);
4760 pr_err("Cannot enable PCI device from suspend\n");
4763 pci_set_master(pdev
);
4765 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4766 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4768 if (netif_running(netdev
)) {
4769 err
= e1000_request_irq(adapter
);
4774 e1000_power_up_phy(adapter
);
4775 e1000_reset(adapter
);
4778 e1000_init_manageability(adapter
);
4780 if (netif_running(netdev
))
4783 netif_device_attach(netdev
);
4789 static void e1000_shutdown(struct pci_dev
*pdev
)
4793 __e1000_shutdown(pdev
, &wake
);
4795 if (system_state
== SYSTEM_POWER_OFF
) {
4796 pci_wake_from_d3(pdev
, wake
);
4797 pci_set_power_state(pdev
, PCI_D3hot
);
4801 #ifdef CONFIG_NET_POLL_CONTROLLER
4803 * Polling 'interrupt' - used by things like netconsole to send skbs
4804 * without having to re-enable interrupts. It's not called while
4805 * the interrupt routine is executing.
4807 static void e1000_netpoll(struct net_device
*netdev
)
4809 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4811 disable_irq(adapter
->pdev
->irq
);
4812 e1000_intr(adapter
->pdev
->irq
, netdev
);
4813 enable_irq(adapter
->pdev
->irq
);
4818 * e1000_io_error_detected - called when PCI error is detected
4819 * @pdev: Pointer to PCI device
4820 * @state: The current pci connection state
4822 * This function is called after a PCI bus error affecting
4823 * this device has been detected.
4825 static pci_ers_result_t
e1000_io_error_detected(struct pci_dev
*pdev
,
4826 pci_channel_state_t state
)
4828 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4829 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4831 netif_device_detach(netdev
);
4833 if (state
== pci_channel_io_perm_failure
)
4834 return PCI_ERS_RESULT_DISCONNECT
;
4836 if (netif_running(netdev
))
4837 e1000_down(adapter
);
4838 pci_disable_device(pdev
);
4840 /* Request a slot slot reset. */
4841 return PCI_ERS_RESULT_NEED_RESET
;
4845 * e1000_io_slot_reset - called after the pci bus has been reset.
4846 * @pdev: Pointer to PCI device
4848 * Restart the card from scratch, as if from a cold-boot. Implementation
4849 * resembles the first-half of the e1000_resume routine.
4851 static pci_ers_result_t
e1000_io_slot_reset(struct pci_dev
*pdev
)
4853 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4854 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4855 struct e1000_hw
*hw
= &adapter
->hw
;
4858 if (adapter
->need_ioport
)
4859 err
= pci_enable_device(pdev
);
4861 err
= pci_enable_device_mem(pdev
);
4863 pr_err("Cannot re-enable PCI device after reset.\n");
4864 return PCI_ERS_RESULT_DISCONNECT
;
4866 pci_set_master(pdev
);
4868 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4869 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4871 e1000_reset(adapter
);
4874 return PCI_ERS_RESULT_RECOVERED
;
4878 * e1000_io_resume - called when traffic can start flowing again.
4879 * @pdev: Pointer to PCI device
4881 * This callback is called when the error recovery driver tells us that
4882 * its OK to resume normal operation. Implementation resembles the
4883 * second-half of the e1000_resume routine.
4885 static void e1000_io_resume(struct pci_dev
*pdev
)
4887 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4888 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4890 e1000_init_manageability(adapter
);
4892 if (netif_running(netdev
)) {
4893 if (e1000_up(adapter
)) {
4894 pr_info("can't bring device back up after reset\n");
4899 netif_device_attach(netdev
);