1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
33 * o Accepted ethtool cleanup patch from Stephen Hemminger
35 * o applied Anton's patch to resolve tx hang in hardware
36 * o Applied Andrew Mortons patch - e1000 stops working after resume
39 char e1000_driver_name
[] = "e1000";
40 static char e1000_driver_string
[] = "Intel(R) PRO/1000 Network Driver";
41 #ifndef CONFIG_E1000_NAPI
44 #define DRIVERNAPI "-NAPI"
46 #define DRV_VERSION "6.3.9-k2"DRIVERNAPI
47 char e1000_driver_version
[] = DRV_VERSION
;
48 static char e1000_copyright
[] = "Copyright (c) 1999-2005 Intel Corporation.";
50 /* e1000_pci_tbl - PCI Device ID Table
52 * Last entry must be all 0s
55 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
57 static struct pci_device_id e1000_pci_tbl
[] = {
58 INTEL_E1000_ETHERNET_DEVICE(0x1000),
59 INTEL_E1000_ETHERNET_DEVICE(0x1001),
60 INTEL_E1000_ETHERNET_DEVICE(0x1004),
61 INTEL_E1000_ETHERNET_DEVICE(0x1008),
62 INTEL_E1000_ETHERNET_DEVICE(0x1009),
63 INTEL_E1000_ETHERNET_DEVICE(0x100C),
64 INTEL_E1000_ETHERNET_DEVICE(0x100D),
65 INTEL_E1000_ETHERNET_DEVICE(0x100E),
66 INTEL_E1000_ETHERNET_DEVICE(0x100F),
67 INTEL_E1000_ETHERNET_DEVICE(0x1010),
68 INTEL_E1000_ETHERNET_DEVICE(0x1011),
69 INTEL_E1000_ETHERNET_DEVICE(0x1012),
70 INTEL_E1000_ETHERNET_DEVICE(0x1013),
71 INTEL_E1000_ETHERNET_DEVICE(0x1014),
72 INTEL_E1000_ETHERNET_DEVICE(0x1015),
73 INTEL_E1000_ETHERNET_DEVICE(0x1016),
74 INTEL_E1000_ETHERNET_DEVICE(0x1017),
75 INTEL_E1000_ETHERNET_DEVICE(0x1018),
76 INTEL_E1000_ETHERNET_DEVICE(0x1019),
77 INTEL_E1000_ETHERNET_DEVICE(0x101A),
78 INTEL_E1000_ETHERNET_DEVICE(0x101D),
79 INTEL_E1000_ETHERNET_DEVICE(0x101E),
80 INTEL_E1000_ETHERNET_DEVICE(0x1026),
81 INTEL_E1000_ETHERNET_DEVICE(0x1027),
82 INTEL_E1000_ETHERNET_DEVICE(0x1028),
83 INTEL_E1000_ETHERNET_DEVICE(0x105E),
84 INTEL_E1000_ETHERNET_DEVICE(0x105F),
85 INTEL_E1000_ETHERNET_DEVICE(0x1060),
86 INTEL_E1000_ETHERNET_DEVICE(0x1075),
87 INTEL_E1000_ETHERNET_DEVICE(0x1076),
88 INTEL_E1000_ETHERNET_DEVICE(0x1077),
89 INTEL_E1000_ETHERNET_DEVICE(0x1078),
90 INTEL_E1000_ETHERNET_DEVICE(0x1079),
91 INTEL_E1000_ETHERNET_DEVICE(0x107A),
92 INTEL_E1000_ETHERNET_DEVICE(0x107B),
93 INTEL_E1000_ETHERNET_DEVICE(0x107C),
94 INTEL_E1000_ETHERNET_DEVICE(0x107D),
95 INTEL_E1000_ETHERNET_DEVICE(0x107E),
96 INTEL_E1000_ETHERNET_DEVICE(0x107F),
97 INTEL_E1000_ETHERNET_DEVICE(0x108A),
98 INTEL_E1000_ETHERNET_DEVICE(0x108B),
99 INTEL_E1000_ETHERNET_DEVICE(0x108C),
100 INTEL_E1000_ETHERNET_DEVICE(0x109A),
101 /* required last entry */
105 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
107 int e1000_up(struct e1000_adapter
*adapter
);
108 void e1000_down(struct e1000_adapter
*adapter
);
109 void e1000_reset(struct e1000_adapter
*adapter
);
110 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
);
111 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
);
112 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
);
113 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
);
114 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
);
115 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
116 struct e1000_tx_ring
*txdr
);
117 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
118 struct e1000_rx_ring
*rxdr
);
119 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
120 struct e1000_tx_ring
*tx_ring
);
121 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
122 struct e1000_rx_ring
*rx_ring
);
123 void e1000_update_stats(struct e1000_adapter
*adapter
);
125 /* Local Function Prototypes */
127 static int e1000_init_module(void);
128 static void e1000_exit_module(void);
129 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
130 static void __devexit
e1000_remove(struct pci_dev
*pdev
);
131 static int e1000_alloc_queues(struct e1000_adapter
*adapter
);
132 #ifdef CONFIG_E1000_MQ
133 static void e1000_setup_queue_mapping(struct e1000_adapter
*adapter
);
135 static int e1000_sw_init(struct e1000_adapter
*adapter
);
136 static int e1000_open(struct net_device
*netdev
);
137 static int e1000_close(struct net_device
*netdev
);
138 static void e1000_configure_tx(struct e1000_adapter
*adapter
);
139 static void e1000_configure_rx(struct e1000_adapter
*adapter
);
140 static void e1000_setup_rctl(struct e1000_adapter
*adapter
);
141 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
);
142 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
);
143 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
144 struct e1000_tx_ring
*tx_ring
);
145 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
146 struct e1000_rx_ring
*rx_ring
);
147 static void e1000_set_multi(struct net_device
*netdev
);
148 static void e1000_update_phy_info(unsigned long data
);
149 static void e1000_watchdog(unsigned long data
);
150 static void e1000_watchdog_task(struct e1000_adapter
*adapter
);
151 static void e1000_82547_tx_fifo_stall(unsigned long data
);
152 static int e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
);
153 static struct net_device_stats
* e1000_get_stats(struct net_device
*netdev
);
154 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
155 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
156 static irqreturn_t
e1000_intr(int irq
, void *data
, struct pt_regs
*regs
);
157 static boolean_t
e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
158 struct e1000_tx_ring
*tx_ring
);
159 #ifdef CONFIG_E1000_NAPI
160 static int e1000_clean(struct net_device
*poll_dev
, int *budget
);
161 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
162 struct e1000_rx_ring
*rx_ring
,
163 int *work_done
, int work_to_do
);
164 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
165 struct e1000_rx_ring
*rx_ring
,
166 int *work_done
, int work_to_do
);
168 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
169 struct e1000_rx_ring
*rx_ring
);
170 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
171 struct e1000_rx_ring
*rx_ring
);
173 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
174 struct e1000_rx_ring
*rx_ring
);
175 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
176 struct e1000_rx_ring
*rx_ring
);
177 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
178 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
180 void e1000_set_ethtool_ops(struct net_device
*netdev
);
181 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
182 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
183 static void e1000_tx_timeout(struct net_device
*dev
);
184 static void e1000_tx_timeout_task(struct net_device
*dev
);
185 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
186 static inline int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
187 struct sk_buff
*skb
);
189 static void e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
);
190 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
);
191 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
);
192 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
195 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
);
196 static int e1000_resume(struct pci_dev
*pdev
);
199 #ifdef CONFIG_NET_POLL_CONTROLLER
200 /* for netdump / net console */
201 static void e1000_netpoll (struct net_device
*netdev
);
204 #ifdef CONFIG_E1000_MQ
205 /* for multiple Rx queues */
206 void e1000_rx_schedule(void *data
);
209 /* Exported from other modules */
211 extern void e1000_check_options(struct e1000_adapter
*adapter
);
213 static struct pci_driver e1000_driver
= {
214 .name
= e1000_driver_name
,
215 .id_table
= e1000_pci_tbl
,
216 .probe
= e1000_probe
,
217 .remove
= __devexit_p(e1000_remove
),
218 /* Power Managment Hooks */
220 .suspend
= e1000_suspend
,
221 .resume
= e1000_resume
225 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
226 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
227 MODULE_LICENSE("GPL");
228 MODULE_VERSION(DRV_VERSION
);
230 static int debug
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
231 module_param(debug
, int, 0);
232 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
235 * e1000_init_module - Driver Registration Routine
237 * e1000_init_module is the first routine called when the driver is
238 * loaded. All it does is register with the PCI subsystem.
242 e1000_init_module(void)
245 printk(KERN_INFO
"%s - version %s\n",
246 e1000_driver_string
, e1000_driver_version
);
248 printk(KERN_INFO
"%s\n", e1000_copyright
);
250 ret
= pci_module_init(&e1000_driver
);
255 module_init(e1000_init_module
);
258 * e1000_exit_module - Driver Exit Cleanup Routine
260 * e1000_exit_module is called just before the driver is removed
265 e1000_exit_module(void)
267 pci_unregister_driver(&e1000_driver
);
270 module_exit(e1000_exit_module
);
273 * e1000_irq_disable - Mask off interrupt generation on the NIC
274 * @adapter: board private structure
278 e1000_irq_disable(struct e1000_adapter
*adapter
)
280 atomic_inc(&adapter
->irq_sem
);
281 E1000_WRITE_REG(&adapter
->hw
, IMC
, ~0);
282 E1000_WRITE_FLUSH(&adapter
->hw
);
283 synchronize_irq(adapter
->pdev
->irq
);
287 * e1000_irq_enable - Enable default interrupt generation settings
288 * @adapter: board private structure
292 e1000_irq_enable(struct e1000_adapter
*adapter
)
294 if(likely(atomic_dec_and_test(&adapter
->irq_sem
))) {
295 E1000_WRITE_REG(&adapter
->hw
, IMS
, IMS_ENABLE_MASK
);
296 E1000_WRITE_FLUSH(&adapter
->hw
);
301 e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
303 struct net_device
*netdev
= adapter
->netdev
;
304 uint16_t vid
= adapter
->hw
.mng_cookie
.vlan_id
;
305 uint16_t old_vid
= adapter
->mng_vlan_id
;
307 if(!adapter
->vlgrp
->vlan_devices
[vid
]) {
308 if(adapter
->hw
.mng_cookie
.status
&
309 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
310 e1000_vlan_rx_add_vid(netdev
, vid
);
311 adapter
->mng_vlan_id
= vid
;
313 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
315 if((old_vid
!= (uint16_t)E1000_MNG_VLAN_NONE
) &&
317 !adapter
->vlgrp
->vlan_devices
[old_vid
])
318 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
324 * e1000_release_hw_control - release control of the h/w to f/w
325 * @adapter: address of board private structure
327 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
328 * For ASF and Pass Through versions of f/w this means that the
329 * driver is no longer loaded. For AMT version (only with 82573) i
330 * of the f/w this means that the netowrk i/f is closed.
335 e1000_release_hw_control(struct e1000_adapter
*adapter
)
340 /* Let firmware taken over control of h/w */
341 switch (adapter
->hw
.mac_type
) {
344 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
345 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
346 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
349 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
350 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
351 swsm
& ~E1000_SWSM_DRV_LOAD
);
358 * e1000_get_hw_control - get control of the h/w from f/w
359 * @adapter: address of board private structure
361 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
362 * For ASF and Pass Through versions of f/w this means that
363 * the driver is loaded. For AMT version (only with 82573)
364 * of the f/w this means that the netowrk i/f is open.
369 e1000_get_hw_control(struct e1000_adapter
*adapter
)
373 /* Let firmware know the driver has taken over */
374 switch (adapter
->hw
.mac_type
) {
377 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
378 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
379 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
382 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
383 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
384 swsm
| E1000_SWSM_DRV_LOAD
);
392 e1000_up(struct e1000_adapter
*adapter
)
394 struct net_device
*netdev
= adapter
->netdev
;
397 /* hardware has been reset, we need to reload some things */
399 /* Reset the PHY if it was previously powered down */
400 if(adapter
->hw
.media_type
== e1000_media_type_copper
) {
402 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
403 if(mii_reg
& MII_CR_POWER_DOWN
)
404 e1000_phy_reset(&adapter
->hw
);
407 e1000_set_multi(netdev
);
409 e1000_restore_vlan(adapter
);
411 e1000_configure_tx(adapter
);
412 e1000_setup_rctl(adapter
);
413 e1000_configure_rx(adapter
);
414 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
415 adapter
->alloc_rx_buf(adapter
, &adapter
->rx_ring
[i
]);
418 #ifdef CONFIG_PCI_MSI
419 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
420 adapter
->have_msi
= TRUE
;
421 if((err
= pci_enable_msi(adapter
->pdev
))) {
423 "Unable to allocate MSI interrupt Error: %d\n", err
);
424 adapter
->have_msi
= FALSE
;
428 if((err
= request_irq(adapter
->pdev
->irq
, &e1000_intr
,
429 SA_SHIRQ
| SA_SAMPLE_RANDOM
,
430 netdev
->name
, netdev
))) {
432 "Unable to allocate interrupt Error: %d\n", err
);
436 #ifdef CONFIG_E1000_MQ
437 e1000_setup_queue_mapping(adapter
);
440 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
442 mod_timer(&adapter
->watchdog_timer
, jiffies
);
444 #ifdef CONFIG_E1000_NAPI
445 netif_poll_enable(netdev
);
447 e1000_irq_enable(adapter
);
453 e1000_down(struct e1000_adapter
*adapter
)
455 struct net_device
*netdev
= adapter
->netdev
;
456 boolean_t mng_mode_enabled
= (adapter
->hw
.mac_type
>= e1000_82571
) &&
457 e1000_check_mng_mode(&adapter
->hw
);
459 e1000_irq_disable(adapter
);
460 #ifdef CONFIG_E1000_MQ
461 while (atomic_read(&adapter
->rx_sched_call_data
.count
) != 0);
463 free_irq(adapter
->pdev
->irq
, netdev
);
464 #ifdef CONFIG_PCI_MSI
465 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
&&
466 adapter
->have_msi
== TRUE
)
467 pci_disable_msi(adapter
->pdev
);
469 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
470 del_timer_sync(&adapter
->watchdog_timer
);
471 del_timer_sync(&adapter
->phy_info_timer
);
473 #ifdef CONFIG_E1000_NAPI
474 netif_poll_disable(netdev
);
476 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
477 adapter
->link_speed
= 0;
478 adapter
->link_duplex
= 0;
479 netif_carrier_off(netdev
);
480 netif_stop_queue(netdev
);
482 e1000_reset(adapter
);
483 e1000_clean_all_tx_rings(adapter
);
484 e1000_clean_all_rx_rings(adapter
);
486 /* Power down the PHY so no link is implied when interface is down *
487 * The PHY cannot be powered down if any of the following is TRUE *
490 * (c) SoL/IDER session is active */
491 if (!adapter
->wol
&& adapter
->hw
.mac_type
>= e1000_82540
&&
492 adapter
->hw
.media_type
== e1000_media_type_copper
&&
493 !(E1000_READ_REG(&adapter
->hw
, MANC
) & E1000_MANC_SMBUS_EN
) &&
495 !e1000_check_phy_reset_block(&adapter
->hw
)) {
497 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
498 mii_reg
|= MII_CR_POWER_DOWN
;
499 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
505 e1000_reset(struct e1000_adapter
*adapter
)
508 uint16_t fc_high_water_mark
= E1000_FC_HIGH_DIFF
;
510 /* Repartition Pba for greater than 9k mtu
511 * To take effect CTRL.RST is required.
514 switch (adapter
->hw
.mac_type
) {
516 case e1000_82547_rev_2
:
531 if((adapter
->hw
.mac_type
!= e1000_82573
) &&
532 (adapter
->netdev
->mtu
> E1000_RXBUFFER_8192
))
533 pba
-= 8; /* allocate more FIFO for Tx */
536 if(adapter
->hw
.mac_type
== e1000_82547
) {
537 adapter
->tx_fifo_head
= 0;
538 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
539 adapter
->tx_fifo_size
=
540 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
541 atomic_set(&adapter
->tx_fifo_stall
, 0);
544 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
546 /* flow control settings */
547 /* Set the FC high water mark to 90% of the FIFO size.
548 * Required to clear last 3 LSB */
549 fc_high_water_mark
= ((pba
* 9216)/10) & 0xFFF8;
551 adapter
->hw
.fc_high_water
= fc_high_water_mark
;
552 adapter
->hw
.fc_low_water
= fc_high_water_mark
- 8;
553 adapter
->hw
.fc_pause_time
= E1000_FC_PAUSE_TIME
;
554 adapter
->hw
.fc_send_xon
= 1;
555 adapter
->hw
.fc
= adapter
->hw
.original_fc
;
557 /* Allow time for pending master requests to run */
558 e1000_reset_hw(&adapter
->hw
);
559 if(adapter
->hw
.mac_type
>= e1000_82544
)
560 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
561 if(e1000_init_hw(&adapter
->hw
))
562 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
563 e1000_update_mng_vlan(adapter
);
564 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
565 E1000_WRITE_REG(&adapter
->hw
, VET
, ETHERNET_IEEE_VLAN_TYPE
);
567 e1000_reset_adaptive(&adapter
->hw
);
568 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
569 if (adapter
->en_mng_pt
) {
570 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
571 manc
|= (E1000_MANC_ARP_EN
| E1000_MANC_EN_MNG2HOST
);
572 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
577 * e1000_probe - Device Initialization Routine
578 * @pdev: PCI device information struct
579 * @ent: entry in e1000_pci_tbl
581 * Returns 0 on success, negative on failure
583 * e1000_probe initializes an adapter identified by a pci_dev structure.
584 * The OS initialization, configuring of the adapter private structure,
585 * and a hardware reset occur.
589 e1000_probe(struct pci_dev
*pdev
,
590 const struct pci_device_id
*ent
)
592 struct net_device
*netdev
;
593 struct e1000_adapter
*adapter
;
594 unsigned long mmio_start
, mmio_len
;
596 static int cards_found
= 0;
597 int i
, err
, pci_using_dac
;
598 uint16_t eeprom_data
;
599 uint16_t eeprom_apme_mask
= E1000_EEPROM_APME
;
600 if((err
= pci_enable_device(pdev
)))
603 if(!(err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
))) {
606 if((err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
))) {
607 E1000_ERR("No usable DMA configuration, aborting\n");
613 if((err
= pci_request_regions(pdev
, e1000_driver_name
)))
616 pci_set_master(pdev
);
618 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
621 goto err_alloc_etherdev
;
624 SET_MODULE_OWNER(netdev
);
625 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
627 pci_set_drvdata(pdev
, netdev
);
628 adapter
= netdev_priv(netdev
);
629 adapter
->netdev
= netdev
;
630 adapter
->pdev
= pdev
;
631 adapter
->hw
.back
= adapter
;
632 adapter
->msg_enable
= (1 << debug
) - 1;
634 mmio_start
= pci_resource_start(pdev
, BAR_0
);
635 mmio_len
= pci_resource_len(pdev
, BAR_0
);
637 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
638 if(!adapter
->hw
.hw_addr
) {
643 for(i
= BAR_1
; i
<= BAR_5
; i
++) {
644 if(pci_resource_len(pdev
, i
) == 0)
646 if(pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
647 adapter
->hw
.io_base
= pci_resource_start(pdev
, i
);
652 netdev
->open
= &e1000_open
;
653 netdev
->stop
= &e1000_close
;
654 netdev
->hard_start_xmit
= &e1000_xmit_frame
;
655 netdev
->get_stats
= &e1000_get_stats
;
656 netdev
->set_multicast_list
= &e1000_set_multi
;
657 netdev
->set_mac_address
= &e1000_set_mac
;
658 netdev
->change_mtu
= &e1000_change_mtu
;
659 netdev
->do_ioctl
= &e1000_ioctl
;
660 e1000_set_ethtool_ops(netdev
);
661 netdev
->tx_timeout
= &e1000_tx_timeout
;
662 netdev
->watchdog_timeo
= 5 * HZ
;
663 #ifdef CONFIG_E1000_NAPI
664 netdev
->poll
= &e1000_clean
;
667 netdev
->vlan_rx_register
= e1000_vlan_rx_register
;
668 netdev
->vlan_rx_add_vid
= e1000_vlan_rx_add_vid
;
669 netdev
->vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
;
670 #ifdef CONFIG_NET_POLL_CONTROLLER
671 netdev
->poll_controller
= e1000_netpoll
;
673 strcpy(netdev
->name
, pci_name(pdev
));
675 netdev
->mem_start
= mmio_start
;
676 netdev
->mem_end
= mmio_start
+ mmio_len
;
677 netdev
->base_addr
= adapter
->hw
.io_base
;
679 adapter
->bd_number
= cards_found
;
681 /* setup the private structure */
683 if((err
= e1000_sw_init(adapter
)))
686 if((err
= e1000_check_phy_reset_block(&adapter
->hw
)))
687 DPRINTK(PROBE
, INFO
, "PHY reset is blocked due to SOL/IDER session.\n");
689 if(adapter
->hw
.mac_type
>= e1000_82543
) {
690 netdev
->features
= NETIF_F_SG
|
694 NETIF_F_HW_VLAN_FILTER
;
698 if((adapter
->hw
.mac_type
>= e1000_82544
) &&
699 (adapter
->hw
.mac_type
!= e1000_82547
))
700 netdev
->features
|= NETIF_F_TSO
;
702 #ifdef NETIF_F_TSO_IPV6
703 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
)
704 netdev
->features
|= NETIF_F_TSO_IPV6
;
708 netdev
->features
|= NETIF_F_HIGHDMA
;
710 /* hard_start_xmit is safe against parallel locking */
711 netdev
->features
|= NETIF_F_LLTX
;
713 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(&adapter
->hw
);
715 /* before reading the EEPROM, reset the controller to
716 * put the device in a known good starting state */
718 e1000_reset_hw(&adapter
->hw
);
720 /* make sure the EEPROM is good */
722 if(e1000_validate_eeprom_checksum(&adapter
->hw
) < 0) {
723 DPRINTK(PROBE
, ERR
, "The EEPROM Checksum Is Not Valid\n");
728 /* copy the MAC address out of the EEPROM */
730 if(e1000_read_mac_addr(&adapter
->hw
))
731 DPRINTK(PROBE
, ERR
, "EEPROM Read Error\n");
732 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
733 memcpy(netdev
->perm_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
735 if(!is_valid_ether_addr(netdev
->perm_addr
)) {
736 DPRINTK(PROBE
, ERR
, "Invalid MAC Address\n");
741 e1000_read_part_num(&adapter
->hw
, &(adapter
->part_num
));
743 e1000_get_bus_info(&adapter
->hw
);
745 init_timer(&adapter
->tx_fifo_stall_timer
);
746 adapter
->tx_fifo_stall_timer
.function
= &e1000_82547_tx_fifo_stall
;
747 adapter
->tx_fifo_stall_timer
.data
= (unsigned long) adapter
;
749 init_timer(&adapter
->watchdog_timer
);
750 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
751 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
753 INIT_WORK(&adapter
->watchdog_task
,
754 (void (*)(void *))e1000_watchdog_task
, adapter
);
756 init_timer(&adapter
->phy_info_timer
);
757 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
758 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
760 INIT_WORK(&adapter
->tx_timeout_task
,
761 (void (*)(void *))e1000_tx_timeout_task
, netdev
);
763 /* we're going to reset, so assume we have no link for now */
765 netif_carrier_off(netdev
);
766 netif_stop_queue(netdev
);
768 e1000_check_options(adapter
);
770 /* Initial Wake on LAN setting
771 * If APM wake is enabled in the EEPROM,
772 * enable the ACPI Magic Packet filter
775 switch(adapter
->hw
.mac_type
) {
776 case e1000_82542_rev2_0
:
777 case e1000_82542_rev2_1
:
781 e1000_read_eeprom(&adapter
->hw
,
782 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
783 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
786 case e1000_82546_rev_3
:
788 if((E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
)
789 && (adapter
->hw
.media_type
== e1000_media_type_copper
)) {
790 e1000_read_eeprom(&adapter
->hw
,
791 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
796 e1000_read_eeprom(&adapter
->hw
,
797 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
800 if(eeprom_data
& eeprom_apme_mask
)
801 adapter
->wol
|= E1000_WUFC_MAG
;
803 /* reset the hardware with the new settings */
804 e1000_reset(adapter
);
806 /* If the controller is 82573 and f/w is AMT, do not set
807 * DRV_LOAD until the interface is up. For all other cases,
808 * let the f/w know that the h/w is now under the control
810 if (adapter
->hw
.mac_type
!= e1000_82573
||
811 !e1000_check_mng_mode(&adapter
->hw
))
812 e1000_get_hw_control(adapter
);
814 strcpy(netdev
->name
, "eth%d");
815 if((err
= register_netdev(netdev
)))
818 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
826 iounmap(adapter
->hw
.hw_addr
);
830 pci_release_regions(pdev
);
835 * e1000_remove - Device Removal Routine
836 * @pdev: PCI device information struct
838 * e1000_remove is called by the PCI subsystem to alert the driver
839 * that it should release a PCI device. The could be caused by a
840 * Hot-Plug event, or because the driver is going to be removed from
844 static void __devexit
845 e1000_remove(struct pci_dev
*pdev
)
847 struct net_device
*netdev
= pci_get_drvdata(pdev
);
848 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
850 #ifdef CONFIG_E1000_NAPI
854 flush_scheduled_work();
856 if(adapter
->hw
.mac_type
>= e1000_82540
&&
857 adapter
->hw
.media_type
== e1000_media_type_copper
) {
858 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
859 if(manc
& E1000_MANC_SMBUS_EN
) {
860 manc
|= E1000_MANC_ARP_EN
;
861 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
865 /* Release control of h/w to f/w. If f/w is AMT enabled, this
866 * would have already happened in close and is redundant. */
867 e1000_release_hw_control(adapter
);
869 unregister_netdev(netdev
);
870 #ifdef CONFIG_E1000_NAPI
871 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
872 __dev_put(&adapter
->polling_netdev
[i
]);
875 if(!e1000_check_phy_reset_block(&adapter
->hw
))
876 e1000_phy_hw_reset(&adapter
->hw
);
878 kfree(adapter
->tx_ring
);
879 kfree(adapter
->rx_ring
);
880 #ifdef CONFIG_E1000_NAPI
881 kfree(adapter
->polling_netdev
);
884 iounmap(adapter
->hw
.hw_addr
);
885 pci_release_regions(pdev
);
887 #ifdef CONFIG_E1000_MQ
888 free_percpu(adapter
->cpu_netdev
);
889 free_percpu(adapter
->cpu_tx_ring
);
893 pci_disable_device(pdev
);
897 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
898 * @adapter: board private structure to initialize
900 * e1000_sw_init initializes the Adapter private data structure.
901 * Fields are initialized based on PCI device information and
902 * OS network device settings (MTU size).
906 e1000_sw_init(struct e1000_adapter
*adapter
)
908 struct e1000_hw
*hw
= &adapter
->hw
;
909 struct net_device
*netdev
= adapter
->netdev
;
910 struct pci_dev
*pdev
= adapter
->pdev
;
911 #ifdef CONFIG_E1000_NAPI
915 /* PCI config space info */
917 hw
->vendor_id
= pdev
->vendor
;
918 hw
->device_id
= pdev
->device
;
919 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
920 hw
->subsystem_id
= pdev
->subsystem_device
;
922 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
924 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
926 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
927 adapter
->rx_ps_bsize0
= E1000_RXBUFFER_256
;
928 hw
->max_frame_size
= netdev
->mtu
+
929 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
930 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
932 /* identify the MAC */
934 if(e1000_set_mac_type(hw
)) {
935 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
939 /* initialize eeprom parameters */
941 if(e1000_init_eeprom_params(hw
)) {
942 E1000_ERR("EEPROM initialization failed\n");
946 switch(hw
->mac_type
) {
951 case e1000_82541_rev_2
:
952 case e1000_82547_rev_2
:
953 hw
->phy_init_script
= 1;
957 e1000_set_media_type(hw
);
959 hw
->wait_autoneg_complete
= FALSE
;
960 hw
->tbi_compatibility_en
= TRUE
;
961 hw
->adaptive_ifs
= TRUE
;
965 if(hw
->media_type
== e1000_media_type_copper
) {
966 hw
->mdix
= AUTO_ALL_MODES
;
967 hw
->disable_polarity_correction
= FALSE
;
968 hw
->master_slave
= E1000_MASTER_SLAVE
;
971 #ifdef CONFIG_E1000_MQ
972 /* Number of supported queues */
973 switch (hw
->mac_type
) {
976 /* These controllers support 2 tx queues, but with a single
977 * qdisc implementation, multiple tx queues aren't quite as
978 * interesting. If we can find a logical way of mapping
979 * flows to a queue, then perhaps we can up the num_tx_queue
980 * count back to its default. Until then, we run the risk of
981 * terrible performance due to SACK overload. */
982 adapter
->num_tx_queues
= 1;
983 adapter
->num_rx_queues
= 2;
986 adapter
->num_tx_queues
= 1;
987 adapter
->num_rx_queues
= 1;
990 adapter
->num_rx_queues
= min(adapter
->num_rx_queues
, num_online_cpus());
991 adapter
->num_tx_queues
= min(adapter
->num_tx_queues
, num_online_cpus());
992 DPRINTK(DRV
, INFO
, "Multiqueue Enabled: Rx Queue count = %u %s\n",
993 adapter
->num_rx_queues
,
994 ((adapter
->num_rx_queues
== 1)
995 ? ((num_online_cpus() > 1)
996 ? "(due to unsupported feature in current adapter)"
997 : "(due to unsupported system configuration)")
999 DPRINTK(DRV
, INFO
, "Multiqueue Enabled: Tx Queue count = %u\n",
1000 adapter
->num_tx_queues
);
1002 adapter
->num_tx_queues
= 1;
1003 adapter
->num_rx_queues
= 1;
1006 if (e1000_alloc_queues(adapter
)) {
1007 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
1011 #ifdef CONFIG_E1000_NAPI
1012 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1013 adapter
->polling_netdev
[i
].priv
= adapter
;
1014 adapter
->polling_netdev
[i
].poll
= &e1000_clean
;
1015 adapter
->polling_netdev
[i
].weight
= 64;
1016 dev_hold(&adapter
->polling_netdev
[i
]);
1017 set_bit(__LINK_STATE_START
, &adapter
->polling_netdev
[i
].state
);
1019 spin_lock_init(&adapter
->tx_queue_lock
);
1022 atomic_set(&adapter
->irq_sem
, 1);
1023 spin_lock_init(&adapter
->stats_lock
);
1029 * e1000_alloc_queues - Allocate memory for all rings
1030 * @adapter: board private structure to initialize
1032 * We allocate one ring per queue at run-time since we don't know the
1033 * number of queues at compile-time. The polling_netdev array is
1034 * intended for Multiqueue, but should work fine with a single queue.
1037 static int __devinit
1038 e1000_alloc_queues(struct e1000_adapter
*adapter
)
1042 size
= sizeof(struct e1000_tx_ring
) * adapter
->num_tx_queues
;
1043 adapter
->tx_ring
= kmalloc(size
, GFP_KERNEL
);
1044 if (!adapter
->tx_ring
)
1046 memset(adapter
->tx_ring
, 0, size
);
1048 size
= sizeof(struct e1000_rx_ring
) * adapter
->num_rx_queues
;
1049 adapter
->rx_ring
= kmalloc(size
, GFP_KERNEL
);
1050 if (!adapter
->rx_ring
) {
1051 kfree(adapter
->tx_ring
);
1054 memset(adapter
->rx_ring
, 0, size
);
1056 #ifdef CONFIG_E1000_NAPI
1057 size
= sizeof(struct net_device
) * adapter
->num_rx_queues
;
1058 adapter
->polling_netdev
= kmalloc(size
, GFP_KERNEL
);
1059 if (!adapter
->polling_netdev
) {
1060 kfree(adapter
->tx_ring
);
1061 kfree(adapter
->rx_ring
);
1064 memset(adapter
->polling_netdev
, 0, size
);
1067 #ifdef CONFIG_E1000_MQ
1068 adapter
->rx_sched_call_data
.func
= e1000_rx_schedule
;
1069 adapter
->rx_sched_call_data
.info
= adapter
->netdev
;
1071 adapter
->cpu_netdev
= alloc_percpu(struct net_device
*);
1072 adapter
->cpu_tx_ring
= alloc_percpu(struct e1000_tx_ring
*);
1075 return E1000_SUCCESS
;
1078 #ifdef CONFIG_E1000_MQ
1079 static void __devinit
1080 e1000_setup_queue_mapping(struct e1000_adapter
*adapter
)
1084 adapter
->rx_sched_call_data
.func
= e1000_rx_schedule
;
1085 adapter
->rx_sched_call_data
.info
= adapter
->netdev
;
1086 cpus_clear(adapter
->rx_sched_call_data
.cpumask
);
1088 adapter
->cpu_netdev
= alloc_percpu(struct net_device
*);
1089 adapter
->cpu_tx_ring
= alloc_percpu(struct e1000_tx_ring
*);
1093 for_each_online_cpu(cpu
) {
1094 *per_cpu_ptr(adapter
->cpu_tx_ring
, cpu
) = &adapter
->tx_ring
[i
% adapter
->num_tx_queues
];
1095 /* This is incomplete because we'd like to assign separate
1096 * physical cpus to these netdev polling structures and
1097 * avoid saturating a subset of cpus.
1099 if (i
< adapter
->num_rx_queues
) {
1100 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = &adapter
->polling_netdev
[i
];
1101 adapter
->rx_ring
[i
].cpu
= cpu
;
1102 cpu_set(cpu
, adapter
->cpumask
);
1104 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = NULL
;
1108 unlock_cpu_hotplug();
1113 * e1000_open - Called when a network interface is made active
1114 * @netdev: network interface device structure
1116 * Returns 0 on success, negative value on failure
1118 * The open entry point is called when a network interface is made
1119 * active by the system (IFF_UP). At this point all resources needed
1120 * for transmit and receive operations are allocated, the interrupt
1121 * handler is registered with the OS, the watchdog timer is started,
1122 * and the stack is notified that the interface is ready.
1126 e1000_open(struct net_device
*netdev
)
1128 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1131 /* allocate transmit descriptors */
1133 if ((err
= e1000_setup_all_tx_resources(adapter
)))
1136 /* allocate receive descriptors */
1138 if ((err
= e1000_setup_all_rx_resources(adapter
)))
1141 if((err
= e1000_up(adapter
)))
1143 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1144 if((adapter
->hw
.mng_cookie
.status
&
1145 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1146 e1000_update_mng_vlan(adapter
);
1149 /* If AMT is enabled, let the firmware know that the network
1150 * interface is now open */
1151 if (adapter
->hw
.mac_type
== e1000_82573
&&
1152 e1000_check_mng_mode(&adapter
->hw
))
1153 e1000_get_hw_control(adapter
);
1155 return E1000_SUCCESS
;
1158 e1000_free_all_rx_resources(adapter
);
1160 e1000_free_all_tx_resources(adapter
);
1162 e1000_reset(adapter
);
1168 * e1000_close - Disables a network interface
1169 * @netdev: network interface device structure
1171 * Returns 0, this is not allowed to fail
1173 * The close entry point is called when an interface is de-activated
1174 * by the OS. The hardware is still under the drivers control, but
1175 * needs to be disabled. A global MAC reset is issued to stop the
1176 * hardware, and all transmit and receive resources are freed.
1180 e1000_close(struct net_device
*netdev
)
1182 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1184 e1000_down(adapter
);
1186 e1000_free_all_tx_resources(adapter
);
1187 e1000_free_all_rx_resources(adapter
);
1189 if((adapter
->hw
.mng_cookie
.status
&
1190 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1191 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1194 /* If AMT is enabled, let the firmware know that the network
1195 * interface is now closed */
1196 if (adapter
->hw
.mac_type
== e1000_82573
&&
1197 e1000_check_mng_mode(&adapter
->hw
))
1198 e1000_release_hw_control(adapter
);
1204 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1205 * @adapter: address of board private structure
1206 * @start: address of beginning of memory
1207 * @len: length of memory
1209 static inline boolean_t
1210 e1000_check_64k_bound(struct e1000_adapter
*adapter
,
1211 void *start
, unsigned long len
)
1213 unsigned long begin
= (unsigned long) start
;
1214 unsigned long end
= begin
+ len
;
1216 /* First rev 82545 and 82546 need to not allow any memory
1217 * write location to cross 64k boundary due to errata 23 */
1218 if (adapter
->hw
.mac_type
== e1000_82545
||
1219 adapter
->hw
.mac_type
== e1000_82546
) {
1220 return ((begin
^ (end
- 1)) >> 16) != 0 ? FALSE
: TRUE
;
1227 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1228 * @adapter: board private structure
1229 * @txdr: tx descriptor ring (for a specific queue) to setup
1231 * Return 0 on success, negative on failure
1235 e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1236 struct e1000_tx_ring
*txdr
)
1238 struct pci_dev
*pdev
= adapter
->pdev
;
1241 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1243 txdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1244 if(!txdr
->buffer_info
) {
1246 "Unable to allocate memory for the transmit descriptor ring\n");
1249 memset(txdr
->buffer_info
, 0, size
);
1251 /* round up to nearest 4K */
1253 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1254 E1000_ROUNDUP(txdr
->size
, 4096);
1256 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1259 vfree(txdr
->buffer_info
);
1261 "Unable to allocate memory for the transmit descriptor ring\n");
1265 /* Fix for errata 23, can't cross 64kB boundary */
1266 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1267 void *olddesc
= txdr
->desc
;
1268 dma_addr_t olddma
= txdr
->dma
;
1269 DPRINTK(TX_ERR
, ERR
, "txdr align check failed: %u bytes "
1270 "at %p\n", txdr
->size
, txdr
->desc
);
1271 /* Try again, without freeing the previous */
1272 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1274 /* Failed allocation, critical failure */
1275 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1276 goto setup_tx_desc_die
;
1279 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1281 pci_free_consistent(pdev
, txdr
->size
, txdr
->desc
,
1283 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1285 "Unable to allocate aligned memory "
1286 "for the transmit descriptor ring\n");
1287 vfree(txdr
->buffer_info
);
1290 /* Free old allocation, new allocation was successful */
1291 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1294 memset(txdr
->desc
, 0, txdr
->size
);
1296 txdr
->next_to_use
= 0;
1297 txdr
->next_to_clean
= 0;
1298 spin_lock_init(&txdr
->tx_lock
);
1304 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1305 * (Descriptors) for all queues
1306 * @adapter: board private structure
1308 * If this function returns with an error, then it's possible one or
1309 * more of the rings is populated (while the rest are not). It is the
1310 * callers duty to clean those orphaned rings.
1312 * Return 0 on success, negative on failure
1316 e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1320 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1321 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1324 "Allocation for Tx Queue %u failed\n", i
);
1333 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1334 * @adapter: board private structure
1336 * Configure the Tx unit of the MAC after a reset.
1340 e1000_configure_tx(struct e1000_adapter
*adapter
)
1343 struct e1000_hw
*hw
= &adapter
->hw
;
1344 uint32_t tdlen
, tctl
, tipg
, tarc
;
1346 /* Setup the HW Tx Head and Tail descriptor pointers */
1348 switch (adapter
->num_tx_queues
) {
1350 tdba
= adapter
->tx_ring
[1].dma
;
1351 tdlen
= adapter
->tx_ring
[1].count
*
1352 sizeof(struct e1000_tx_desc
);
1353 E1000_WRITE_REG(hw
, TDBAL1
, (tdba
& 0x00000000ffffffffULL
));
1354 E1000_WRITE_REG(hw
, TDBAH1
, (tdba
>> 32));
1355 E1000_WRITE_REG(hw
, TDLEN1
, tdlen
);
1356 E1000_WRITE_REG(hw
, TDH1
, 0);
1357 E1000_WRITE_REG(hw
, TDT1
, 0);
1358 adapter
->tx_ring
[1].tdh
= E1000_TDH1
;
1359 adapter
->tx_ring
[1].tdt
= E1000_TDT1
;
1363 tdba
= adapter
->tx_ring
[0].dma
;
1364 tdlen
= adapter
->tx_ring
[0].count
*
1365 sizeof(struct e1000_tx_desc
);
1366 E1000_WRITE_REG(hw
, TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1367 E1000_WRITE_REG(hw
, TDBAH
, (tdba
>> 32));
1368 E1000_WRITE_REG(hw
, TDLEN
, tdlen
);
1369 E1000_WRITE_REG(hw
, TDH
, 0);
1370 E1000_WRITE_REG(hw
, TDT
, 0);
1371 adapter
->tx_ring
[0].tdh
= E1000_TDH
;
1372 adapter
->tx_ring
[0].tdt
= E1000_TDT
;
1376 /* Set the default values for the Tx Inter Packet Gap timer */
1378 switch (hw
->mac_type
) {
1379 case e1000_82542_rev2_0
:
1380 case e1000_82542_rev2_1
:
1381 tipg
= DEFAULT_82542_TIPG_IPGT
;
1382 tipg
|= DEFAULT_82542_TIPG_IPGR1
<< E1000_TIPG_IPGR1_SHIFT
;
1383 tipg
|= DEFAULT_82542_TIPG_IPGR2
<< E1000_TIPG_IPGR2_SHIFT
;
1386 if (hw
->media_type
== e1000_media_type_fiber
||
1387 hw
->media_type
== e1000_media_type_internal_serdes
)
1388 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1390 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1391 tipg
|= DEFAULT_82543_TIPG_IPGR1
<< E1000_TIPG_IPGR1_SHIFT
;
1392 tipg
|= DEFAULT_82543_TIPG_IPGR2
<< E1000_TIPG_IPGR2_SHIFT
;
1394 E1000_WRITE_REG(hw
, TIPG
, tipg
);
1396 /* Set the Tx Interrupt Delay register */
1398 E1000_WRITE_REG(hw
, TIDV
, adapter
->tx_int_delay
);
1399 if (hw
->mac_type
>= e1000_82540
)
1400 E1000_WRITE_REG(hw
, TADV
, adapter
->tx_abs_int_delay
);
1402 /* Program the Transmit Control Register */
1404 tctl
= E1000_READ_REG(hw
, TCTL
);
1406 tctl
&= ~E1000_TCTL_CT
;
1407 tctl
|= E1000_TCTL_EN
| E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1408 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1410 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1412 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
1413 tarc
= E1000_READ_REG(hw
, TARC0
);
1414 tarc
|= ((1 << 25) | (1 << 21));
1415 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1416 tarc
= E1000_READ_REG(hw
, TARC1
);
1418 if (tctl
& E1000_TCTL_MULR
)
1422 E1000_WRITE_REG(hw
, TARC1
, tarc
);
1425 e1000_config_collision_dist(hw
);
1427 /* Setup Transmit Descriptor Settings for eop descriptor */
1428 adapter
->txd_cmd
= E1000_TXD_CMD_IDE
| E1000_TXD_CMD_EOP
|
1431 if (hw
->mac_type
< e1000_82543
)
1432 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1434 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1436 /* Cache if we're 82544 running in PCI-X because we'll
1437 * need this to apply a workaround later in the send path. */
1438 if (hw
->mac_type
== e1000_82544
&&
1439 hw
->bus_type
== e1000_bus_type_pcix
)
1440 adapter
->pcix_82544
= 1;
1444 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1445 * @adapter: board private structure
1446 * @rxdr: rx descriptor ring (for a specific queue) to setup
1448 * Returns 0 on success, negative on failure
1452 e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1453 struct e1000_rx_ring
*rxdr
)
1455 struct pci_dev
*pdev
= adapter
->pdev
;
1458 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1459 rxdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1460 if (!rxdr
->buffer_info
) {
1462 "Unable to allocate memory for the receive descriptor ring\n");
1465 memset(rxdr
->buffer_info
, 0, size
);
1467 size
= sizeof(struct e1000_ps_page
) * rxdr
->count
;
1468 rxdr
->ps_page
= kmalloc(size
, GFP_KERNEL
);
1469 if(!rxdr
->ps_page
) {
1470 vfree(rxdr
->buffer_info
);
1472 "Unable to allocate memory for the receive descriptor ring\n");
1475 memset(rxdr
->ps_page
, 0, size
);
1477 size
= sizeof(struct e1000_ps_page_dma
) * rxdr
->count
;
1478 rxdr
->ps_page_dma
= kmalloc(size
, GFP_KERNEL
);
1479 if(!rxdr
->ps_page_dma
) {
1480 vfree(rxdr
->buffer_info
);
1481 kfree(rxdr
->ps_page
);
1483 "Unable to allocate memory for the receive descriptor ring\n");
1486 memset(rxdr
->ps_page_dma
, 0, size
);
1488 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
)
1489 desc_len
= sizeof(struct e1000_rx_desc
);
1491 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1493 /* Round up to nearest 4K */
1495 rxdr
->size
= rxdr
->count
* desc_len
;
1496 E1000_ROUNDUP(rxdr
->size
, 4096);
1498 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1502 "Unable to allocate memory for the receive descriptor ring\n");
1504 vfree(rxdr
->buffer_info
);
1505 kfree(rxdr
->ps_page
);
1506 kfree(rxdr
->ps_page_dma
);
1510 /* Fix for errata 23, can't cross 64kB boundary */
1511 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1512 void *olddesc
= rxdr
->desc
;
1513 dma_addr_t olddma
= rxdr
->dma
;
1514 DPRINTK(RX_ERR
, ERR
, "rxdr align check failed: %u bytes "
1515 "at %p\n", rxdr
->size
, rxdr
->desc
);
1516 /* Try again, without freeing the previous */
1517 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1518 /* Failed allocation, critical failure */
1520 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1522 "Unable to allocate memory "
1523 "for the receive descriptor ring\n");
1524 goto setup_rx_desc_die
;
1527 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1529 pci_free_consistent(pdev
, rxdr
->size
, rxdr
->desc
,
1531 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1533 "Unable to allocate aligned memory "
1534 "for the receive descriptor ring\n");
1535 goto setup_rx_desc_die
;
1537 /* Free old allocation, new allocation was successful */
1538 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1541 memset(rxdr
->desc
, 0, rxdr
->size
);
1543 rxdr
->next_to_clean
= 0;
1544 rxdr
->next_to_use
= 0;
1550 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1551 * (Descriptors) for all queues
1552 * @adapter: board private structure
1554 * If this function returns with an error, then it's possible one or
1555 * more of the rings is populated (while the rest are not). It is the
1556 * callers duty to clean those orphaned rings.
1558 * Return 0 on success, negative on failure
1562 e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1566 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1567 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1570 "Allocation for Rx Queue %u failed\n", i
);
1579 * e1000_setup_rctl - configure the receive control registers
1580 * @adapter: Board private structure
1582 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1583 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1585 e1000_setup_rctl(struct e1000_adapter
*adapter
)
1587 uint32_t rctl
, rfctl
;
1588 uint32_t psrctl
= 0;
1589 #ifdef CONFIG_E1000_PACKET_SPLIT
1593 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1595 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1597 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1598 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1599 (adapter
->hw
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1601 if(adapter
->hw
.tbi_compatibility_on
== 1)
1602 rctl
|= E1000_RCTL_SBP
;
1604 rctl
&= ~E1000_RCTL_SBP
;
1606 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1607 rctl
&= ~E1000_RCTL_LPE
;
1609 rctl
|= E1000_RCTL_LPE
;
1611 /* Setup buffer sizes */
1612 if(adapter
->hw
.mac_type
>= e1000_82571
) {
1613 /* We can now specify buffers in 1K increments.
1614 * BSIZE and BSEX are ignored in this case. */
1615 rctl
|= adapter
->rx_buffer_len
<< 0x11;
1617 rctl
&= ~E1000_RCTL_SZ_4096
;
1618 rctl
|= E1000_RCTL_BSEX
;
1619 switch (adapter
->rx_buffer_len
) {
1620 case E1000_RXBUFFER_2048
:
1622 rctl
|= E1000_RCTL_SZ_2048
;
1623 rctl
&= ~E1000_RCTL_BSEX
;
1625 case E1000_RXBUFFER_4096
:
1626 rctl
|= E1000_RCTL_SZ_4096
;
1628 case E1000_RXBUFFER_8192
:
1629 rctl
|= E1000_RCTL_SZ_8192
;
1631 case E1000_RXBUFFER_16384
:
1632 rctl
|= E1000_RCTL_SZ_16384
;
1637 #ifdef CONFIG_E1000_PACKET_SPLIT
1638 /* 82571 and greater support packet-split where the protocol
1639 * header is placed in skb->data and the packet data is
1640 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1641 * In the case of a non-split, skb->data is linearly filled,
1642 * followed by the page buffers. Therefore, skb->data is
1643 * sized to hold the largest protocol header.
1645 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
1646 if ((adapter
->hw
.mac_type
> e1000_82547_rev_2
) && (pages
<= 3) &&
1648 adapter
->rx_ps_pages
= pages
;
1650 adapter
->rx_ps_pages
= 0;
1652 if (adapter
->rx_ps_pages
) {
1653 /* Configure extra packet-split registers */
1654 rfctl
= E1000_READ_REG(&adapter
->hw
, RFCTL
);
1655 rfctl
|= E1000_RFCTL_EXTEN
;
1656 /* disable IPv6 packet split support */
1657 rfctl
|= E1000_RFCTL_IPV6_DIS
;
1658 E1000_WRITE_REG(&adapter
->hw
, RFCTL
, rfctl
);
1660 rctl
|= E1000_RCTL_DTYP_PS
| E1000_RCTL_SECRC
;
1662 psrctl
|= adapter
->rx_ps_bsize0
>>
1663 E1000_PSRCTL_BSIZE0_SHIFT
;
1665 switch (adapter
->rx_ps_pages
) {
1667 psrctl
|= PAGE_SIZE
<<
1668 E1000_PSRCTL_BSIZE3_SHIFT
;
1670 psrctl
|= PAGE_SIZE
<<
1671 E1000_PSRCTL_BSIZE2_SHIFT
;
1673 psrctl
|= PAGE_SIZE
>>
1674 E1000_PSRCTL_BSIZE1_SHIFT
;
1678 E1000_WRITE_REG(&adapter
->hw
, PSRCTL
, psrctl
);
1681 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1685 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1686 * @adapter: board private structure
1688 * Configure the Rx unit of the MAC after a reset.
1692 e1000_configure_rx(struct e1000_adapter
*adapter
)
1695 struct e1000_hw
*hw
= &adapter
->hw
;
1696 uint32_t rdlen
, rctl
, rxcsum
, ctrl_ext
;
1697 #ifdef CONFIG_E1000_MQ
1698 uint32_t reta
, mrqc
;
1702 if (adapter
->rx_ps_pages
) {
1703 rdlen
= adapter
->rx_ring
[0].count
*
1704 sizeof(union e1000_rx_desc_packet_split
);
1705 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
1706 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
1708 rdlen
= adapter
->rx_ring
[0].count
*
1709 sizeof(struct e1000_rx_desc
);
1710 adapter
->clean_rx
= e1000_clean_rx_irq
;
1711 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1714 /* disable receives while setting up the descriptors */
1715 rctl
= E1000_READ_REG(hw
, RCTL
);
1716 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
1718 /* set the Receive Delay Timer Register */
1719 E1000_WRITE_REG(hw
, RDTR
, adapter
->rx_int_delay
);
1721 if (hw
->mac_type
>= e1000_82540
) {
1722 E1000_WRITE_REG(hw
, RADV
, adapter
->rx_abs_int_delay
);
1723 if(adapter
->itr
> 1)
1724 E1000_WRITE_REG(hw
, ITR
,
1725 1000000000 / (adapter
->itr
* 256));
1728 if (hw
->mac_type
>= e1000_82571
) {
1729 /* Reset delay timers after every interrupt */
1730 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1731 ctrl_ext
|= E1000_CTRL_EXT_CANC
;
1732 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
1733 E1000_WRITE_FLUSH(hw
);
1736 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1737 * the Base and Length of the Rx Descriptor Ring */
1738 switch (adapter
->num_rx_queues
) {
1739 #ifdef CONFIG_E1000_MQ
1741 rdba
= adapter
->rx_ring
[1].dma
;
1742 E1000_WRITE_REG(hw
, RDBAL1
, (rdba
& 0x00000000ffffffffULL
));
1743 E1000_WRITE_REG(hw
, RDBAH1
, (rdba
>> 32));
1744 E1000_WRITE_REG(hw
, RDLEN1
, rdlen
);
1745 E1000_WRITE_REG(hw
, RDH1
, 0);
1746 E1000_WRITE_REG(hw
, RDT1
, 0);
1747 adapter
->rx_ring
[1].rdh
= E1000_RDH1
;
1748 adapter
->rx_ring
[1].rdt
= E1000_RDT1
;
1753 rdba
= adapter
->rx_ring
[0].dma
;
1754 E1000_WRITE_REG(hw
, RDBAL
, (rdba
& 0x00000000ffffffffULL
));
1755 E1000_WRITE_REG(hw
, RDBAH
, (rdba
>> 32));
1756 E1000_WRITE_REG(hw
, RDLEN
, rdlen
);
1757 E1000_WRITE_REG(hw
, RDH
, 0);
1758 E1000_WRITE_REG(hw
, RDT
, 0);
1759 adapter
->rx_ring
[0].rdh
= E1000_RDH
;
1760 adapter
->rx_ring
[0].rdt
= E1000_RDT
;
1764 #ifdef CONFIG_E1000_MQ
1765 if (adapter
->num_rx_queues
> 1) {
1766 uint32_t random
[10];
1768 get_random_bytes(&random
[0], 40);
1770 if (hw
->mac_type
<= e1000_82572
) {
1771 E1000_WRITE_REG(hw
, RSSIR
, 0);
1772 E1000_WRITE_REG(hw
, RSSIM
, 0);
1775 switch (adapter
->num_rx_queues
) {
1779 mrqc
= E1000_MRQC_ENABLE_RSS_2Q
;
1783 /* Fill out redirection table */
1784 for (i
= 0; i
< 32; i
++)
1785 E1000_WRITE_REG_ARRAY(hw
, RETA
, i
, reta
);
1786 /* Fill out hash function seeds */
1787 for (i
= 0; i
< 10; i
++)
1788 E1000_WRITE_REG_ARRAY(hw
, RSSRK
, i
, random
[i
]);
1790 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4
|
1791 E1000_MRQC_RSS_FIELD_IPV4_TCP
);
1792 E1000_WRITE_REG(hw
, MRQC
, mrqc
);
1795 /* Multiqueue and packet checksumming are mutually exclusive. */
1796 if (hw
->mac_type
>= e1000_82571
) {
1797 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1798 rxcsum
|= E1000_RXCSUM_PCSD
;
1799 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1804 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1805 if (hw
->mac_type
>= e1000_82543
) {
1806 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1807 if(adapter
->rx_csum
== TRUE
) {
1808 rxcsum
|= E1000_RXCSUM_TUOFL
;
1810 /* Enable 82571 IPv4 payload checksum for UDP fragments
1811 * Must be used in conjunction with packet-split. */
1812 if ((hw
->mac_type
>= e1000_82571
) &&
1813 (adapter
->rx_ps_pages
)) {
1814 rxcsum
|= E1000_RXCSUM_IPPCSE
;
1817 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1818 /* don't need to clear IPPCSE as it defaults to 0 */
1820 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1822 #endif /* CONFIG_E1000_MQ */
1824 if (hw
->mac_type
== e1000_82573
)
1825 E1000_WRITE_REG(hw
, ERT
, 0x0100);
1827 /* Enable Receives */
1828 E1000_WRITE_REG(hw
, RCTL
, rctl
);
1832 * e1000_free_tx_resources - Free Tx Resources per Queue
1833 * @adapter: board private structure
1834 * @tx_ring: Tx descriptor ring for a specific queue
1836 * Free all transmit software resources
1840 e1000_free_tx_resources(struct e1000_adapter
*adapter
,
1841 struct e1000_tx_ring
*tx_ring
)
1843 struct pci_dev
*pdev
= adapter
->pdev
;
1845 e1000_clean_tx_ring(adapter
, tx_ring
);
1847 vfree(tx_ring
->buffer_info
);
1848 tx_ring
->buffer_info
= NULL
;
1850 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
1852 tx_ring
->desc
= NULL
;
1856 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1857 * @adapter: board private structure
1859 * Free all transmit software resources
1863 e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
1867 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1868 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1872 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
1873 struct e1000_buffer
*buffer_info
)
1875 if(buffer_info
->dma
) {
1876 pci_unmap_page(adapter
->pdev
,
1878 buffer_info
->length
,
1880 buffer_info
->dma
= 0;
1882 if(buffer_info
->skb
) {
1883 dev_kfree_skb_any(buffer_info
->skb
);
1884 buffer_info
->skb
= NULL
;
1889 * e1000_clean_tx_ring - Free Tx Buffers
1890 * @adapter: board private structure
1891 * @tx_ring: ring to be cleaned
1895 e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
1896 struct e1000_tx_ring
*tx_ring
)
1898 struct e1000_buffer
*buffer_info
;
1902 /* Free all the Tx ring sk_buffs */
1904 for(i
= 0; i
< tx_ring
->count
; i
++) {
1905 buffer_info
= &tx_ring
->buffer_info
[i
];
1906 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
1909 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1910 memset(tx_ring
->buffer_info
, 0, size
);
1912 /* Zero out the descriptor ring */
1914 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1916 tx_ring
->next_to_use
= 0;
1917 tx_ring
->next_to_clean
= 0;
1918 tx_ring
->last_tx_tso
= 0;
1920 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdh
);
1921 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
1925 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1926 * @adapter: board private structure
1930 e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
1934 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1935 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1939 * e1000_free_rx_resources - Free Rx Resources
1940 * @adapter: board private structure
1941 * @rx_ring: ring to clean the resources from
1943 * Free all receive software resources
1947 e1000_free_rx_resources(struct e1000_adapter
*adapter
,
1948 struct e1000_rx_ring
*rx_ring
)
1950 struct pci_dev
*pdev
= adapter
->pdev
;
1952 e1000_clean_rx_ring(adapter
, rx_ring
);
1954 vfree(rx_ring
->buffer_info
);
1955 rx_ring
->buffer_info
= NULL
;
1956 kfree(rx_ring
->ps_page
);
1957 rx_ring
->ps_page
= NULL
;
1958 kfree(rx_ring
->ps_page_dma
);
1959 rx_ring
->ps_page_dma
= NULL
;
1961 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
1963 rx_ring
->desc
= NULL
;
1967 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1968 * @adapter: board private structure
1970 * Free all receive software resources
1974 e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
1978 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1979 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1983 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1984 * @adapter: board private structure
1985 * @rx_ring: ring to free buffers from
1989 e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
1990 struct e1000_rx_ring
*rx_ring
)
1992 struct e1000_buffer
*buffer_info
;
1993 struct e1000_ps_page
*ps_page
;
1994 struct e1000_ps_page_dma
*ps_page_dma
;
1995 struct pci_dev
*pdev
= adapter
->pdev
;
1999 /* Free all the Rx ring sk_buffs */
2001 for(i
= 0; i
< rx_ring
->count
; i
++) {
2002 buffer_info
= &rx_ring
->buffer_info
[i
];
2003 if(buffer_info
->skb
) {
2004 ps_page
= &rx_ring
->ps_page
[i
];
2005 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2006 pci_unmap_single(pdev
,
2008 buffer_info
->length
,
2009 PCI_DMA_FROMDEVICE
);
2011 dev_kfree_skb(buffer_info
->skb
);
2012 buffer_info
->skb
= NULL
;
2014 for(j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
2015 if(!ps_page
->ps_page
[j
]) break;
2016 pci_unmap_single(pdev
,
2017 ps_page_dma
->ps_page_dma
[j
],
2018 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
2019 ps_page_dma
->ps_page_dma
[j
] = 0;
2020 put_page(ps_page
->ps_page
[j
]);
2021 ps_page
->ps_page
[j
] = NULL
;
2026 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2027 memset(rx_ring
->buffer_info
, 0, size
);
2028 size
= sizeof(struct e1000_ps_page
) * rx_ring
->count
;
2029 memset(rx_ring
->ps_page
, 0, size
);
2030 size
= sizeof(struct e1000_ps_page_dma
) * rx_ring
->count
;
2031 memset(rx_ring
->ps_page_dma
, 0, size
);
2033 /* Zero out the descriptor ring */
2035 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2037 rx_ring
->next_to_clean
= 0;
2038 rx_ring
->next_to_use
= 0;
2040 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdh
);
2041 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
2045 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2046 * @adapter: board private structure
2050 e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2054 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2055 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2058 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2059 * and memory write and invalidate disabled for certain operations
2062 e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2064 struct net_device
*netdev
= adapter
->netdev
;
2067 e1000_pci_clear_mwi(&adapter
->hw
);
2069 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2070 rctl
|= E1000_RCTL_RST
;
2071 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2072 E1000_WRITE_FLUSH(&adapter
->hw
);
2075 if(netif_running(netdev
))
2076 e1000_clean_all_rx_rings(adapter
);
2080 e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2082 struct net_device
*netdev
= adapter
->netdev
;
2085 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2086 rctl
&= ~E1000_RCTL_RST
;
2087 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2088 E1000_WRITE_FLUSH(&adapter
->hw
);
2091 if(adapter
->hw
.pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2092 e1000_pci_set_mwi(&adapter
->hw
);
2094 if(netif_running(netdev
)) {
2095 e1000_configure_rx(adapter
);
2096 e1000_alloc_rx_buffers(adapter
, &adapter
->rx_ring
[0]);
2101 * e1000_set_mac - Change the Ethernet Address of the NIC
2102 * @netdev: network interface device structure
2103 * @p: pointer to an address structure
2105 * Returns 0 on success, negative on failure
2109 e1000_set_mac(struct net_device
*netdev
, void *p
)
2111 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2112 struct sockaddr
*addr
= p
;
2114 if(!is_valid_ether_addr(addr
->sa_data
))
2115 return -EADDRNOTAVAIL
;
2117 /* 82542 2.0 needs to be in reset to write receive address registers */
2119 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2120 e1000_enter_82542_rst(adapter
);
2122 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2123 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2125 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2127 /* With 82571 controllers, LAA may be overwritten (with the default)
2128 * due to controller reset from the other port. */
2129 if (adapter
->hw
.mac_type
== e1000_82571
) {
2130 /* activate the work around */
2131 adapter
->hw
.laa_is_present
= 1;
2133 /* Hold a copy of the LAA in RAR[14] This is done so that
2134 * between the time RAR[0] gets clobbered and the time it
2135 * gets fixed (in e1000_watchdog), the actual LAA is in one
2136 * of the RARs and no incoming packets directed to this port
2137 * are dropped. Eventaully the LAA will be in RAR[0] and
2139 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
,
2140 E1000_RAR_ENTRIES
- 1);
2143 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2144 e1000_leave_82542_rst(adapter
);
2150 * e1000_set_multi - Multicast and Promiscuous mode set
2151 * @netdev: network interface device structure
2153 * The set_multi entry point is called whenever the multicast address
2154 * list or the network interface flags are updated. This routine is
2155 * responsible for configuring the hardware for proper multicast,
2156 * promiscuous mode, and all-multi behavior.
2160 e1000_set_multi(struct net_device
*netdev
)
2162 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2163 struct e1000_hw
*hw
= &adapter
->hw
;
2164 struct dev_mc_list
*mc_ptr
;
2166 uint32_t hash_value
;
2167 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2169 /* reserve RAR[14] for LAA over-write work-around */
2170 if (adapter
->hw
.mac_type
== e1000_82571
)
2173 /* Check for Promiscuous and All Multicast modes */
2175 rctl
= E1000_READ_REG(hw
, RCTL
);
2177 if(netdev
->flags
& IFF_PROMISC
) {
2178 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2179 } else if(netdev
->flags
& IFF_ALLMULTI
) {
2180 rctl
|= E1000_RCTL_MPE
;
2181 rctl
&= ~E1000_RCTL_UPE
;
2183 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2186 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2188 /* 82542 2.0 needs to be in reset to write receive address registers */
2190 if(hw
->mac_type
== e1000_82542_rev2_0
)
2191 e1000_enter_82542_rst(adapter
);
2193 /* load the first 14 multicast address into the exact filters 1-14
2194 * RAR 0 is used for the station MAC adddress
2195 * if there are not 14 addresses, go ahead and clear the filters
2196 * -- with 82571 controllers only 0-13 entries are filled here
2198 mc_ptr
= netdev
->mc_list
;
2200 for(i
= 1; i
< rar_entries
; i
++) {
2202 e1000_rar_set(hw
, mc_ptr
->dmi_addr
, i
);
2203 mc_ptr
= mc_ptr
->next
;
2205 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2206 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2210 /* clear the old settings from the multicast hash table */
2212 for(i
= 0; i
< E1000_NUM_MTA_REGISTERS
; i
++)
2213 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
2215 /* load any remaining addresses into the hash table */
2217 for(; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
2218 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->dmi_addr
);
2219 e1000_mta_set(hw
, hash_value
);
2222 if(hw
->mac_type
== e1000_82542_rev2_0
)
2223 e1000_leave_82542_rst(adapter
);
2226 /* Need to wait a few seconds after link up to get diagnostic information from
2230 e1000_update_phy_info(unsigned long data
)
2232 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2233 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
2237 * e1000_82547_tx_fifo_stall - Timer Call-back
2238 * @data: pointer to adapter cast into an unsigned long
2242 e1000_82547_tx_fifo_stall(unsigned long data
)
2244 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2245 struct net_device
*netdev
= adapter
->netdev
;
2248 if(atomic_read(&adapter
->tx_fifo_stall
)) {
2249 if((E1000_READ_REG(&adapter
->hw
, TDT
) ==
2250 E1000_READ_REG(&adapter
->hw
, TDH
)) &&
2251 (E1000_READ_REG(&adapter
->hw
, TDFT
) ==
2252 E1000_READ_REG(&adapter
->hw
, TDFH
)) &&
2253 (E1000_READ_REG(&adapter
->hw
, TDFTS
) ==
2254 E1000_READ_REG(&adapter
->hw
, TDFHS
))) {
2255 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2256 E1000_WRITE_REG(&adapter
->hw
, TCTL
,
2257 tctl
& ~E1000_TCTL_EN
);
2258 E1000_WRITE_REG(&adapter
->hw
, TDFT
,
2259 adapter
->tx_head_addr
);
2260 E1000_WRITE_REG(&adapter
->hw
, TDFH
,
2261 adapter
->tx_head_addr
);
2262 E1000_WRITE_REG(&adapter
->hw
, TDFTS
,
2263 adapter
->tx_head_addr
);
2264 E1000_WRITE_REG(&adapter
->hw
, TDFHS
,
2265 adapter
->tx_head_addr
);
2266 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2267 E1000_WRITE_FLUSH(&adapter
->hw
);
2269 adapter
->tx_fifo_head
= 0;
2270 atomic_set(&adapter
->tx_fifo_stall
, 0);
2271 netif_wake_queue(netdev
);
2273 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2279 * e1000_watchdog - Timer Call-back
2280 * @data: pointer to adapter cast into an unsigned long
2283 e1000_watchdog(unsigned long data
)
2285 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2287 /* Do the rest outside of interrupt context */
2288 schedule_work(&adapter
->watchdog_task
);
2292 e1000_watchdog_task(struct e1000_adapter
*adapter
)
2294 struct net_device
*netdev
= adapter
->netdev
;
2295 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2298 e1000_check_for_link(&adapter
->hw
);
2299 if (adapter
->hw
.mac_type
== e1000_82573
) {
2300 e1000_enable_tx_pkt_filtering(&adapter
->hw
);
2301 if(adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
)
2302 e1000_update_mng_vlan(adapter
);
2305 if((adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) &&
2306 !(E1000_READ_REG(&adapter
->hw
, TXCW
) & E1000_TXCW_ANE
))
2307 link
= !adapter
->hw
.serdes_link_down
;
2309 link
= E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_LU
;
2312 if(!netif_carrier_ok(netdev
)) {
2313 e1000_get_speed_and_duplex(&adapter
->hw
,
2314 &adapter
->link_speed
,
2315 &adapter
->link_duplex
);
2317 DPRINTK(LINK
, INFO
, "NIC Link is Up %d Mbps %s\n",
2318 adapter
->link_speed
,
2319 adapter
->link_duplex
== FULL_DUPLEX
?
2320 "Full Duplex" : "Half Duplex");
2322 /* tweak tx_queue_len according to speed/duplex */
2323 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2324 adapter
->tx_timeout_factor
= 1;
2325 if (adapter
->link_duplex
== HALF_DUPLEX
) {
2326 switch (adapter
->link_speed
) {
2328 netdev
->tx_queue_len
= 10;
2329 adapter
->tx_timeout_factor
= 8;
2332 netdev
->tx_queue_len
= 100;
2337 netif_carrier_on(netdev
);
2338 netif_wake_queue(netdev
);
2339 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2340 adapter
->smartspeed
= 0;
2343 if(netif_carrier_ok(netdev
)) {
2344 adapter
->link_speed
= 0;
2345 adapter
->link_duplex
= 0;
2346 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
2347 netif_carrier_off(netdev
);
2348 netif_stop_queue(netdev
);
2349 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2352 e1000_smartspeed(adapter
);
2355 e1000_update_stats(adapter
);
2357 adapter
->hw
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2358 adapter
->tpt_old
= adapter
->stats
.tpt
;
2359 adapter
->hw
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2360 adapter
->colc_old
= adapter
->stats
.colc
;
2362 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2363 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2364 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2365 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2367 e1000_update_adaptive(&adapter
->hw
);
2369 #ifdef CONFIG_E1000_MQ
2370 txdr
= *per_cpu_ptr(adapter
->cpu_tx_ring
, smp_processor_id());
2372 if (!netif_carrier_ok(netdev
)) {
2373 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2374 /* We've lost link, so the controller stops DMA,
2375 * but we've got queued Tx work that's never going
2376 * to get done, so reset controller to flush Tx.
2377 * (Do the reset outside of interrupt context). */
2378 schedule_work(&adapter
->tx_timeout_task
);
2382 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2383 if(adapter
->hw
.mac_type
>= e1000_82540
&& adapter
->itr
== 1) {
2384 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2385 * asymmetrical Tx or Rx gets ITR=8000; everyone
2386 * else is between 2000-8000. */
2387 uint32_t goc
= (adapter
->gotcl
+ adapter
->gorcl
) / 10000;
2388 uint32_t dif
= (adapter
->gotcl
> adapter
->gorcl
?
2389 adapter
->gotcl
- adapter
->gorcl
:
2390 adapter
->gorcl
- adapter
->gotcl
) / 10000;
2391 uint32_t itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
2392 E1000_WRITE_REG(&adapter
->hw
, ITR
, 1000000000 / (itr
* 256));
2395 /* Cause software interrupt to ensure rx ring is cleaned */
2396 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_RXDMT0
);
2398 /* Force detection of hung controller every watchdog period */
2399 adapter
->detect_tx_hung
= TRUE
;
2401 /* With 82571 controllers, LAA may be overwritten due to controller
2402 * reset from the other port. Set the appropriate LAA in RAR[0] */
2403 if (adapter
->hw
.mac_type
== e1000_82571
&& adapter
->hw
.laa_is_present
)
2404 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2406 /* Reset the timer */
2407 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2 * HZ
);
2410 #define E1000_TX_FLAGS_CSUM 0x00000001
2411 #define E1000_TX_FLAGS_VLAN 0x00000002
2412 #define E1000_TX_FLAGS_TSO 0x00000004
2413 #define E1000_TX_FLAGS_IPV4 0x00000008
2414 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2415 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2418 e1000_tso(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2419 struct sk_buff
*skb
)
2422 struct e1000_context_desc
*context_desc
;
2423 struct e1000_buffer
*buffer_info
;
2425 uint32_t cmd_length
= 0;
2426 uint16_t ipcse
= 0, tucse
, mss
;
2427 uint8_t ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2430 if(skb_shinfo(skb
)->tso_size
) {
2431 if (skb_header_cloned(skb
)) {
2432 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2437 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2438 mss
= skb_shinfo(skb
)->tso_size
;
2439 if(skb
->protocol
== ntohs(ETH_P_IP
)) {
2440 skb
->nh
.iph
->tot_len
= 0;
2441 skb
->nh
.iph
->check
= 0;
2443 ~csum_tcpudp_magic(skb
->nh
.iph
->saddr
,
2448 cmd_length
= E1000_TXD_CMD_IP
;
2449 ipcse
= skb
->h
.raw
- skb
->data
- 1;
2450 #ifdef NETIF_F_TSO_IPV6
2451 } else if(skb
->protocol
== ntohs(ETH_P_IPV6
)) {
2452 skb
->nh
.ipv6h
->payload_len
= 0;
2454 ~csum_ipv6_magic(&skb
->nh
.ipv6h
->saddr
,
2455 &skb
->nh
.ipv6h
->daddr
,
2462 ipcss
= skb
->nh
.raw
- skb
->data
;
2463 ipcso
= (void *)&(skb
->nh
.iph
->check
) - (void *)skb
->data
;
2464 tucss
= skb
->h
.raw
- skb
->data
;
2465 tucso
= (void *)&(skb
->h
.th
->check
) - (void *)skb
->data
;
2468 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2469 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2471 i
= tx_ring
->next_to_use
;
2472 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2473 buffer_info
= &tx_ring
->buffer_info
[i
];
2475 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2476 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2477 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2478 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2479 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2480 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2481 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2482 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2483 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2485 buffer_info
->time_stamp
= jiffies
;
2487 if (++i
== tx_ring
->count
) i
= 0;
2488 tx_ring
->next_to_use
= i
;
2497 static inline boolean_t
2498 e1000_tx_csum(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2499 struct sk_buff
*skb
)
2501 struct e1000_context_desc
*context_desc
;
2502 struct e1000_buffer
*buffer_info
;
2506 if(likely(skb
->ip_summed
== CHECKSUM_HW
)) {
2507 css
= skb
->h
.raw
- skb
->data
;
2509 i
= tx_ring
->next_to_use
;
2510 buffer_info
= &tx_ring
->buffer_info
[i
];
2511 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2513 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2514 context_desc
->upper_setup
.tcp_fields
.tucso
= css
+ skb
->csum
;
2515 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2516 context_desc
->tcp_seg_setup
.data
= 0;
2517 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
2519 buffer_info
->time_stamp
= jiffies
;
2521 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2522 tx_ring
->next_to_use
= i
;
2530 #define E1000_MAX_TXD_PWR 12
2531 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2534 e1000_tx_map(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2535 struct sk_buff
*skb
, unsigned int first
, unsigned int max_per_txd
,
2536 unsigned int nr_frags
, unsigned int mss
)
2538 struct e1000_buffer
*buffer_info
;
2539 unsigned int len
= skb
->len
;
2540 unsigned int offset
= 0, size
, count
= 0, i
;
2542 len
-= skb
->data_len
;
2544 i
= tx_ring
->next_to_use
;
2547 buffer_info
= &tx_ring
->buffer_info
[i
];
2548 size
= min(len
, max_per_txd
);
2550 /* Workaround for Controller erratum --
2551 * descriptor for non-tso packet in a linear SKB that follows a
2552 * tso gets written back prematurely before the data is fully
2553 * DMAd to the controller */
2554 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2555 !skb_shinfo(skb
)->tso_size
) {
2556 tx_ring
->last_tx_tso
= 0;
2560 /* Workaround for premature desc write-backs
2561 * in TSO mode. Append 4-byte sentinel desc */
2562 if(unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
2565 /* work-around for errata 10 and it applies
2566 * to all controllers in PCI-X mode
2567 * The fix is to make sure that the first descriptor of a
2568 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2570 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2571 (size
> 2015) && count
== 0))
2574 /* Workaround for potential 82544 hang in PCI-X. Avoid
2575 * terminating buffers within evenly-aligned dwords. */
2576 if(unlikely(adapter
->pcix_82544
&&
2577 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
2581 buffer_info
->length
= size
;
2583 pci_map_single(adapter
->pdev
,
2587 buffer_info
->time_stamp
= jiffies
;
2592 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2595 for(f
= 0; f
< nr_frags
; f
++) {
2596 struct skb_frag_struct
*frag
;
2598 frag
= &skb_shinfo(skb
)->frags
[f
];
2600 offset
= frag
->page_offset
;
2603 buffer_info
= &tx_ring
->buffer_info
[i
];
2604 size
= min(len
, max_per_txd
);
2606 /* Workaround for premature desc write-backs
2607 * in TSO mode. Append 4-byte sentinel desc */
2608 if(unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
2611 /* Workaround for potential 82544 hang in PCI-X.
2612 * Avoid terminating buffers within evenly-aligned
2614 if(unlikely(adapter
->pcix_82544
&&
2615 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
2619 buffer_info
->length
= size
;
2621 pci_map_page(adapter
->pdev
,
2626 buffer_info
->time_stamp
= jiffies
;
2631 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2635 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
2636 tx_ring
->buffer_info
[i
].skb
= skb
;
2637 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
2643 e1000_tx_queue(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2644 int tx_flags
, int count
)
2646 struct e1000_tx_desc
*tx_desc
= NULL
;
2647 struct e1000_buffer
*buffer_info
;
2648 uint32_t txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
2651 if(likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
2652 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
2654 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2656 if(likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
2657 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
2660 if(likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
2661 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
2662 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2665 if(unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
2666 txd_lower
|= E1000_TXD_CMD_VLE
;
2667 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
2670 i
= tx_ring
->next_to_use
;
2673 buffer_info
= &tx_ring
->buffer_info
[i
];
2674 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
2675 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2676 tx_desc
->lower
.data
=
2677 cpu_to_le32(txd_lower
| buffer_info
->length
);
2678 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
2679 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2682 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
2684 /* Force memory writes to complete before letting h/w
2685 * know there are new descriptors to fetch. (Only
2686 * applicable for weak-ordered memory model archs,
2687 * such as IA-64). */
2690 tx_ring
->next_to_use
= i
;
2691 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
2695 * 82547 workaround to avoid controller hang in half-duplex environment.
2696 * The workaround is to avoid queuing a large packet that would span
2697 * the internal Tx FIFO ring boundary by notifying the stack to resend
2698 * the packet at a later time. This gives the Tx FIFO an opportunity to
2699 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2700 * to the beginning of the Tx FIFO.
2703 #define E1000_FIFO_HDR 0x10
2704 #define E1000_82547_PAD_LEN 0x3E0
2707 e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2709 uint32_t fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
2710 uint32_t skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
2712 E1000_ROUNDUP(skb_fifo_len
, E1000_FIFO_HDR
);
2714 if(adapter
->link_duplex
!= HALF_DUPLEX
)
2715 goto no_fifo_stall_required
;
2717 if(atomic_read(&adapter
->tx_fifo_stall
))
2720 if(skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
2721 atomic_set(&adapter
->tx_fifo_stall
, 1);
2725 no_fifo_stall_required
:
2726 adapter
->tx_fifo_head
+= skb_fifo_len
;
2727 if(adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
2728 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
2732 #define MINIMUM_DHCP_PACKET_SIZE 282
2734 e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2736 struct e1000_hw
*hw
= &adapter
->hw
;
2737 uint16_t length
, offset
;
2738 if(vlan_tx_tag_present(skb
)) {
2739 if(!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
2740 ( adapter
->hw
.mng_cookie
.status
&
2741 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) )
2744 if ((skb
->len
> MINIMUM_DHCP_PACKET_SIZE
) && (!skb
->protocol
)) {
2745 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
2746 if((htons(ETH_P_IP
) == eth
->h_proto
)) {
2747 const struct iphdr
*ip
=
2748 (struct iphdr
*)((uint8_t *)skb
->data
+14);
2749 if(IPPROTO_UDP
== ip
->protocol
) {
2750 struct udphdr
*udp
=
2751 (struct udphdr
*)((uint8_t *)ip
+
2753 if(ntohs(udp
->dest
) == 67) {
2754 offset
= (uint8_t *)udp
+ 8 - skb
->data
;
2755 length
= skb
->len
- offset
;
2757 return e1000_mng_write_dhcp_info(hw
,
2767 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2769 e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2771 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2772 struct e1000_tx_ring
*tx_ring
;
2773 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
2774 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
2775 unsigned int tx_flags
= 0;
2776 unsigned int len
= skb
->len
;
2777 unsigned long flags
;
2778 unsigned int nr_frags
= 0;
2779 unsigned int mss
= 0;
2783 len
-= skb
->data_len
;
2785 #ifdef CONFIG_E1000_MQ
2786 tx_ring
= *per_cpu_ptr(adapter
->cpu_tx_ring
, smp_processor_id());
2788 tx_ring
= adapter
->tx_ring
;
2791 if (unlikely(skb
->len
<= 0)) {
2792 dev_kfree_skb_any(skb
);
2793 return NETDEV_TX_OK
;
2797 mss
= skb_shinfo(skb
)->tso_size
;
2798 /* The controller does a simple calculation to
2799 * make sure there is enough room in the FIFO before
2800 * initiating the DMA for each buffer. The calc is:
2801 * 4 = ceil(buffer len/mss). To make sure we don't
2802 * overrun the FIFO, adjust the max buffer len if mss
2806 max_per_txd
= min(mss
<< 2, max_per_txd
);
2807 max_txd_pwr
= fls(max_per_txd
) - 1;
2809 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2810 * points to just header, pull a few bytes of payload from
2811 * frags into skb->data */
2812 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2813 if (skb
->data_len
&& (hdr_len
== (skb
->len
- skb
->data_len
)) &&
2814 (adapter
->hw
.mac_type
== e1000_82571
||
2815 adapter
->hw
.mac_type
== e1000_82572
)) {
2816 len
= skb
->len
- skb
->data_len
;
2820 if((mss
) || (skb
->ip_summed
== CHECKSUM_HW
))
2821 /* reserve a descriptor for the offload context */
2825 if(skb
->ip_summed
== CHECKSUM_HW
)
2830 /* Controller Erratum workaround */
2831 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2832 !skb_shinfo(skb
)->tso_size
)
2836 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
2838 if(adapter
->pcix_82544
)
2841 /* work-around for errata 10 and it applies to all controllers
2842 * in PCI-X mode, so add one more descriptor to the count
2844 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2848 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2849 for(f
= 0; f
< nr_frags
; f
++)
2850 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
2852 if(adapter
->pcix_82544
)
2855 unsigned int pull_size
;
2856 pull_size
= min((unsigned int)4, skb
->data_len
);
2857 if (!__pskb_pull_tail(skb
, pull_size
)) {
2858 printk(KERN_ERR
"__pskb_pull_tail failed.\n");
2859 dev_kfree_skb_any(skb
);
2863 if(adapter
->hw
.tx_pkt_filtering
&& (adapter
->hw
.mac_type
== e1000_82573
) )
2864 e1000_transfer_dhcp_info(adapter
, skb
);
2866 local_irq_save(flags
);
2867 if (!spin_trylock(&tx_ring
->tx_lock
)) {
2868 /* Collision - tell upper layer to requeue */
2869 local_irq_restore(flags
);
2870 return NETDEV_TX_LOCKED
;
2873 /* need: count + 2 desc gap to keep tail from touching
2874 * head, otherwise try next time */
2875 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < count
+ 2)) {
2876 netif_stop_queue(netdev
);
2877 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2878 return NETDEV_TX_BUSY
;
2881 if(unlikely(adapter
->hw
.mac_type
== e1000_82547
)) {
2882 if(unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
2883 netif_stop_queue(netdev
);
2884 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
);
2885 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2886 return NETDEV_TX_BUSY
;
2890 if(unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
2891 tx_flags
|= E1000_TX_FLAGS_VLAN
;
2892 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
2895 first
= tx_ring
->next_to_use
;
2897 tso
= e1000_tso(adapter
, tx_ring
, skb
);
2899 dev_kfree_skb_any(skb
);
2900 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2901 return NETDEV_TX_OK
;
2905 tx_ring
->last_tx_tso
= 1;
2906 tx_flags
|= E1000_TX_FLAGS_TSO
;
2907 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
2908 tx_flags
|= E1000_TX_FLAGS_CSUM
;
2910 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2911 * 82571 hardware supports TSO capabilities for IPv6 as well...
2912 * no longer assume, we must. */
2913 if (likely(skb
->protocol
== ntohs(ETH_P_IP
)))
2914 tx_flags
|= E1000_TX_FLAGS_IPV4
;
2916 e1000_tx_queue(adapter
, tx_ring
, tx_flags
,
2917 e1000_tx_map(adapter
, tx_ring
, skb
, first
,
2918 max_per_txd
, nr_frags
, mss
));
2920 netdev
->trans_start
= jiffies
;
2922 /* Make sure there is space in the ring for the next send. */
2923 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < MAX_SKB_FRAGS
+ 2))
2924 netif_stop_queue(netdev
);
2926 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2927 return NETDEV_TX_OK
;
2931 * e1000_tx_timeout - Respond to a Tx Hang
2932 * @netdev: network interface device structure
2936 e1000_tx_timeout(struct net_device
*netdev
)
2938 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2940 /* Do the reset outside of interrupt context */
2941 schedule_work(&adapter
->tx_timeout_task
);
2945 e1000_tx_timeout_task(struct net_device
*netdev
)
2947 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2949 adapter
->tx_timeout_count
++;
2950 e1000_down(adapter
);
2955 * e1000_get_stats - Get System Network Statistics
2956 * @netdev: network interface device structure
2958 * Returns the address of the device statistics structure.
2959 * The statistics are actually updated from the timer callback.
2962 static struct net_device_stats
*
2963 e1000_get_stats(struct net_device
*netdev
)
2965 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2967 /* only return the current stats */
2968 return &adapter
->net_stats
;
2972 * e1000_change_mtu - Change the Maximum Transfer Unit
2973 * @netdev: network interface device structure
2974 * @new_mtu: new value for maximum frame size
2976 * Returns 0 on success, negative on failure
2980 e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
2982 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2983 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
2985 if((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
2986 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
2987 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
2991 #define MAX_STD_JUMBO_FRAME_SIZE 9234
2992 /* might want this to be bigger enum check... */
2993 /* 82571 controllers limit jumbo frame size to 10500 bytes */
2994 if ((adapter
->hw
.mac_type
== e1000_82571
||
2995 adapter
->hw
.mac_type
== e1000_82572
) &&
2996 max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
2997 DPRINTK(PROBE
, ERR
, "MTU > 9216 bytes not supported "
2998 "on 82571 and 82572 controllers.\n");
3002 if(adapter
->hw
.mac_type
== e1000_82573
&&
3003 max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3004 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported "
3009 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3010 adapter
->rx_buffer_len
= max_frame
;
3011 E1000_ROUNDUP(adapter
->rx_buffer_len
, 1024);
3013 if(unlikely((adapter
->hw
.mac_type
< e1000_82543
) &&
3014 (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
))) {
3015 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported "
3020 if(max_frame
<= E1000_RXBUFFER_2048
) {
3021 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3022 } else if(max_frame
<= E1000_RXBUFFER_4096
) {
3023 adapter
->rx_buffer_len
= E1000_RXBUFFER_4096
;
3024 } else if(max_frame
<= E1000_RXBUFFER_8192
) {
3025 adapter
->rx_buffer_len
= E1000_RXBUFFER_8192
;
3026 } else if(max_frame
<= E1000_RXBUFFER_16384
) {
3027 adapter
->rx_buffer_len
= E1000_RXBUFFER_16384
;
3032 netdev
->mtu
= new_mtu
;
3034 if(netif_running(netdev
)) {
3035 e1000_down(adapter
);
3039 adapter
->hw
.max_frame_size
= max_frame
;
3045 * e1000_update_stats - Update the board statistics counters
3046 * @adapter: board private structure
3050 e1000_update_stats(struct e1000_adapter
*adapter
)
3052 struct e1000_hw
*hw
= &adapter
->hw
;
3053 unsigned long flags
;
3056 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3058 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3060 /* these counters are modified from e1000_adjust_tbi_stats,
3061 * called from the interrupt context, so they must only
3062 * be written while holding adapter->stats_lock
3065 adapter
->stats
.crcerrs
+= E1000_READ_REG(hw
, CRCERRS
);
3066 adapter
->stats
.gprc
+= E1000_READ_REG(hw
, GPRC
);
3067 adapter
->stats
.gorcl
+= E1000_READ_REG(hw
, GORCL
);
3068 adapter
->stats
.gorch
+= E1000_READ_REG(hw
, GORCH
);
3069 adapter
->stats
.bprc
+= E1000_READ_REG(hw
, BPRC
);
3070 adapter
->stats
.mprc
+= E1000_READ_REG(hw
, MPRC
);
3071 adapter
->stats
.roc
+= E1000_READ_REG(hw
, ROC
);
3072 adapter
->stats
.prc64
+= E1000_READ_REG(hw
, PRC64
);
3073 adapter
->stats
.prc127
+= E1000_READ_REG(hw
, PRC127
);
3074 adapter
->stats
.prc255
+= E1000_READ_REG(hw
, PRC255
);
3075 adapter
->stats
.prc511
+= E1000_READ_REG(hw
, PRC511
);
3076 adapter
->stats
.prc1023
+= E1000_READ_REG(hw
, PRC1023
);
3077 adapter
->stats
.prc1522
+= E1000_READ_REG(hw
, PRC1522
);
3079 adapter
->stats
.symerrs
+= E1000_READ_REG(hw
, SYMERRS
);
3080 adapter
->stats
.mpc
+= E1000_READ_REG(hw
, MPC
);
3081 adapter
->stats
.scc
+= E1000_READ_REG(hw
, SCC
);
3082 adapter
->stats
.ecol
+= E1000_READ_REG(hw
, ECOL
);
3083 adapter
->stats
.mcc
+= E1000_READ_REG(hw
, MCC
);
3084 adapter
->stats
.latecol
+= E1000_READ_REG(hw
, LATECOL
);
3085 adapter
->stats
.dc
+= E1000_READ_REG(hw
, DC
);
3086 adapter
->stats
.sec
+= E1000_READ_REG(hw
, SEC
);
3087 adapter
->stats
.rlec
+= E1000_READ_REG(hw
, RLEC
);
3088 adapter
->stats
.xonrxc
+= E1000_READ_REG(hw
, XONRXC
);
3089 adapter
->stats
.xontxc
+= E1000_READ_REG(hw
, XONTXC
);
3090 adapter
->stats
.xoffrxc
+= E1000_READ_REG(hw
, XOFFRXC
);
3091 adapter
->stats
.xofftxc
+= E1000_READ_REG(hw
, XOFFTXC
);
3092 adapter
->stats
.fcruc
+= E1000_READ_REG(hw
, FCRUC
);
3093 adapter
->stats
.gptc
+= E1000_READ_REG(hw
, GPTC
);
3094 adapter
->stats
.gotcl
+= E1000_READ_REG(hw
, GOTCL
);
3095 adapter
->stats
.gotch
+= E1000_READ_REG(hw
, GOTCH
);
3096 adapter
->stats
.rnbc
+= E1000_READ_REG(hw
, RNBC
);
3097 adapter
->stats
.ruc
+= E1000_READ_REG(hw
, RUC
);
3098 adapter
->stats
.rfc
+= E1000_READ_REG(hw
, RFC
);
3099 adapter
->stats
.rjc
+= E1000_READ_REG(hw
, RJC
);
3100 adapter
->stats
.torl
+= E1000_READ_REG(hw
, TORL
);
3101 adapter
->stats
.torh
+= E1000_READ_REG(hw
, TORH
);
3102 adapter
->stats
.totl
+= E1000_READ_REG(hw
, TOTL
);
3103 adapter
->stats
.toth
+= E1000_READ_REG(hw
, TOTH
);
3104 adapter
->stats
.tpr
+= E1000_READ_REG(hw
, TPR
);
3105 adapter
->stats
.ptc64
+= E1000_READ_REG(hw
, PTC64
);
3106 adapter
->stats
.ptc127
+= E1000_READ_REG(hw
, PTC127
);
3107 adapter
->stats
.ptc255
+= E1000_READ_REG(hw
, PTC255
);
3108 adapter
->stats
.ptc511
+= E1000_READ_REG(hw
, PTC511
);
3109 adapter
->stats
.ptc1023
+= E1000_READ_REG(hw
, PTC1023
);
3110 adapter
->stats
.ptc1522
+= E1000_READ_REG(hw
, PTC1522
);
3111 adapter
->stats
.mptc
+= E1000_READ_REG(hw
, MPTC
);
3112 adapter
->stats
.bptc
+= E1000_READ_REG(hw
, BPTC
);
3114 /* used for adaptive IFS */
3116 hw
->tx_packet_delta
= E1000_READ_REG(hw
, TPT
);
3117 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3118 hw
->collision_delta
= E1000_READ_REG(hw
, COLC
);
3119 adapter
->stats
.colc
+= hw
->collision_delta
;
3121 if(hw
->mac_type
>= e1000_82543
) {
3122 adapter
->stats
.algnerrc
+= E1000_READ_REG(hw
, ALGNERRC
);
3123 adapter
->stats
.rxerrc
+= E1000_READ_REG(hw
, RXERRC
);
3124 adapter
->stats
.tncrs
+= E1000_READ_REG(hw
, TNCRS
);
3125 adapter
->stats
.cexterr
+= E1000_READ_REG(hw
, CEXTERR
);
3126 adapter
->stats
.tsctc
+= E1000_READ_REG(hw
, TSCTC
);
3127 adapter
->stats
.tsctfc
+= E1000_READ_REG(hw
, TSCTFC
);
3129 if(hw
->mac_type
> e1000_82547_rev_2
) {
3130 adapter
->stats
.iac
+= E1000_READ_REG(hw
, IAC
);
3131 adapter
->stats
.icrxoc
+= E1000_READ_REG(hw
, ICRXOC
);
3132 adapter
->stats
.icrxptc
+= E1000_READ_REG(hw
, ICRXPTC
);
3133 adapter
->stats
.icrxatc
+= E1000_READ_REG(hw
, ICRXATC
);
3134 adapter
->stats
.ictxptc
+= E1000_READ_REG(hw
, ICTXPTC
);
3135 adapter
->stats
.ictxatc
+= E1000_READ_REG(hw
, ICTXATC
);
3136 adapter
->stats
.ictxqec
+= E1000_READ_REG(hw
, ICTXQEC
);
3137 adapter
->stats
.ictxqmtc
+= E1000_READ_REG(hw
, ICTXQMTC
);
3138 adapter
->stats
.icrxdmtc
+= E1000_READ_REG(hw
, ICRXDMTC
);
3141 /* Fill out the OS statistics structure */
3143 adapter
->net_stats
.rx_packets
= adapter
->stats
.gprc
;
3144 adapter
->net_stats
.tx_packets
= adapter
->stats
.gptc
;
3145 adapter
->net_stats
.rx_bytes
= adapter
->stats
.gorcl
;
3146 adapter
->net_stats
.tx_bytes
= adapter
->stats
.gotcl
;
3147 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3148 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3152 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3153 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3154 adapter
->stats
.rlec
+ adapter
->stats
.cexterr
;
3155 adapter
->net_stats
.rx_dropped
= 0;
3156 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlec
;
3157 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3158 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3159 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3163 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3164 adapter
->stats
.latecol
;
3165 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3166 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3167 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3169 /* Tx Dropped needs to be maintained elsewhere */
3173 if(hw
->media_type
== e1000_media_type_copper
) {
3174 if((adapter
->link_speed
== SPEED_1000
) &&
3175 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3176 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3177 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3180 if((hw
->mac_type
<= e1000_82546
) &&
3181 (hw
->phy_type
== e1000_phy_m88
) &&
3182 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3183 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3186 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3189 #ifdef CONFIG_E1000_MQ
3191 e1000_rx_schedule(void *data
)
3193 struct net_device
*poll_dev
, *netdev
= data
;
3194 struct e1000_adapter
*adapter
= netdev
->priv
;
3195 int this_cpu
= get_cpu();
3197 poll_dev
= *per_cpu_ptr(adapter
->cpu_netdev
, this_cpu
);
3198 if (poll_dev
== NULL
) {
3203 if (likely(netif_rx_schedule_prep(poll_dev
)))
3204 __netif_rx_schedule(poll_dev
);
3206 e1000_irq_enable(adapter
);
3213 * e1000_intr - Interrupt Handler
3214 * @irq: interrupt number
3215 * @data: pointer to a network interface device structure
3216 * @pt_regs: CPU registers structure
3220 e1000_intr(int irq
, void *data
, struct pt_regs
*regs
)
3222 struct net_device
*netdev
= data
;
3223 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3224 struct e1000_hw
*hw
= &adapter
->hw
;
3225 uint32_t icr
= E1000_READ_REG(hw
, ICR
);
3226 #if defined(CONFIG_E1000_NAPI) && defined(CONFIG_E1000_MQ) || !defined(CONFIG_E1000_NAPI)
3231 return IRQ_NONE
; /* Not our interrupt */
3233 if(unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3234 hw
->get_link_status
= 1;
3235 mod_timer(&adapter
->watchdog_timer
, jiffies
);
3238 #ifdef CONFIG_E1000_NAPI
3239 atomic_inc(&adapter
->irq_sem
);
3240 E1000_WRITE_REG(hw
, IMC
, ~0);
3241 E1000_WRITE_FLUSH(hw
);
3242 #ifdef CONFIG_E1000_MQ
3243 if (atomic_read(&adapter
->rx_sched_call_data
.count
) == 0) {
3244 /* We must setup the cpumask once count == 0 since
3245 * each cpu bit is cleared when the work is done. */
3246 adapter
->rx_sched_call_data
.cpumask
= adapter
->cpumask
;
3247 atomic_add(adapter
->num_rx_queues
- 1, &adapter
->irq_sem
);
3248 atomic_set(&adapter
->rx_sched_call_data
.count
,
3249 adapter
->num_rx_queues
);
3250 smp_call_async_mask(&adapter
->rx_sched_call_data
);
3252 printk("call_data.count == %u\n", atomic_read(&adapter
->rx_sched_call_data
.count
));
3254 #else /* if !CONFIG_E1000_MQ */
3255 if (likely(netif_rx_schedule_prep(&adapter
->polling_netdev
[0])))
3256 __netif_rx_schedule(&adapter
->polling_netdev
[0]);
3258 e1000_irq_enable(adapter
);
3259 #endif /* CONFIG_E1000_MQ */
3261 #else /* if !CONFIG_E1000_NAPI */
3262 /* Writing IMC and IMS is needed for 82547.
3263 Due to Hub Link bus being occupied, an interrupt
3264 de-assertion message is not able to be sent.
3265 When an interrupt assertion message is generated later,
3266 two messages are re-ordered and sent out.
3267 That causes APIC to think 82547 is in de-assertion
3268 state, while 82547 is in assertion state, resulting
3269 in dead lock. Writing IMC forces 82547 into
3272 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
){
3273 atomic_inc(&adapter
->irq_sem
);
3274 E1000_WRITE_REG(hw
, IMC
, ~0);
3277 for(i
= 0; i
< E1000_MAX_INTR
; i
++)
3278 if(unlikely(!adapter
->clean_rx(adapter
, adapter
->rx_ring
) &
3279 !e1000_clean_tx_irq(adapter
, adapter
->tx_ring
)))
3282 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
3283 e1000_irq_enable(adapter
);
3285 #endif /* CONFIG_E1000_NAPI */
3290 #ifdef CONFIG_E1000_NAPI
3292 * e1000_clean - NAPI Rx polling callback
3293 * @adapter: board private structure
3297 e1000_clean(struct net_device
*poll_dev
, int *budget
)
3299 struct e1000_adapter
*adapter
;
3300 int work_to_do
= min(*budget
, poll_dev
->quota
);
3301 int tx_cleaned
, i
= 0, work_done
= 0;
3303 /* Must NOT use netdev_priv macro here. */
3304 adapter
= poll_dev
->priv
;
3306 /* Keep link state information with original netdev */
3307 if (!netif_carrier_ok(adapter
->netdev
))
3310 while (poll_dev
!= &adapter
->polling_netdev
[i
]) {
3312 if (unlikely(i
== adapter
->num_rx_queues
))
3316 tx_cleaned
= e1000_clean_tx_irq(adapter
, &adapter
->tx_ring
[i
]);
3317 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[i
],
3318 &work_done
, work_to_do
);
3320 *budget
-= work_done
;
3321 poll_dev
->quota
-= work_done
;
3323 /* If no Tx and not enough Rx work done, exit the polling mode */
3324 if((!tx_cleaned
&& (work_done
== 0)) ||
3325 !netif_running(adapter
->netdev
)) {
3327 netif_rx_complete(poll_dev
);
3328 e1000_irq_enable(adapter
);
3337 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3338 * @adapter: board private structure
3342 e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
3343 struct e1000_tx_ring
*tx_ring
)
3345 struct net_device
*netdev
= adapter
->netdev
;
3346 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
3347 struct e1000_buffer
*buffer_info
;
3348 unsigned int i
, eop
;
3349 boolean_t cleaned
= FALSE
;
3351 i
= tx_ring
->next_to_clean
;
3352 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3353 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3355 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
3356 for(cleaned
= FALSE
; !cleaned
; ) {
3357 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3358 buffer_info
= &tx_ring
->buffer_info
[i
];
3359 cleaned
= (i
== eop
);
3361 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
3363 tx_desc
->buffer_addr
= 0;
3364 tx_desc
->lower
.data
= 0;
3365 tx_desc
->upper
.data
= 0;
3367 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
3370 #ifdef CONFIG_E1000_MQ
3371 tx_ring
->tx_stats
.packets
++;
3374 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3375 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3378 tx_ring
->next_to_clean
= i
;
3380 spin_lock(&tx_ring
->tx_lock
);
3382 if(unlikely(cleaned
&& netif_queue_stopped(netdev
) &&
3383 netif_carrier_ok(netdev
)))
3384 netif_wake_queue(netdev
);
3386 spin_unlock(&tx_ring
->tx_lock
);
3388 if (adapter
->detect_tx_hung
) {
3389 /* Detect a transmit hang in hardware, this serializes the
3390 * check with the clearing of time_stamp and movement of i */
3391 adapter
->detect_tx_hung
= FALSE
;
3392 if (tx_ring
->buffer_info
[i
].dma
&&
3393 time_after(jiffies
, tx_ring
->buffer_info
[i
].time_stamp
+ HZ
)
3394 && !(E1000_READ_REG(&adapter
->hw
, STATUS
) &
3395 E1000_STATUS_TXOFF
)) {
3397 /* detected Tx unit hang */
3398 i
= tx_ring
->next_to_clean
;
3399 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3400 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3401 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
3405 " next_to_use <%x>\n"
3406 " next_to_clean <%x>\n"
3407 "buffer_info[next_to_clean]\n"
3409 " time_stamp <%lx>\n"
3410 " next_to_watch <%x>\n"
3412 " next_to_watch.status <%x>\n",
3413 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
3414 sizeof(struct e1000_tx_ring
)),
3415 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdh
),
3416 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdt
),
3417 tx_ring
->next_to_use
,
3419 (unsigned long long)tx_ring
->buffer_info
[i
].dma
,
3420 tx_ring
->buffer_info
[i
].time_stamp
,
3423 eop_desc
->upper
.fields
.status
);
3424 netif_stop_queue(netdev
);
3431 * e1000_rx_checksum - Receive Checksum Offload for 82543
3432 * @adapter: board private structure
3433 * @status_err: receive descriptor status and error fields
3434 * @csum: receive descriptor csum field
3435 * @sk_buff: socket buffer with received data
3439 e1000_rx_checksum(struct e1000_adapter
*adapter
,
3440 uint32_t status_err
, uint32_t csum
,
3441 struct sk_buff
*skb
)
3443 uint16_t status
= (uint16_t)status_err
;
3444 uint8_t errors
= (uint8_t)(status_err
>> 24);
3445 skb
->ip_summed
= CHECKSUM_NONE
;
3447 /* 82543 or newer only */
3448 if(unlikely(adapter
->hw
.mac_type
< e1000_82543
)) return;
3449 /* Ignore Checksum bit is set */
3450 if(unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
3451 /* TCP/UDP checksum error bit is set */
3452 if(unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
3453 /* let the stack verify checksum errors */
3454 adapter
->hw_csum_err
++;
3457 /* TCP/UDP Checksum has not been calculated */
3458 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
) {
3459 if(!(status
& E1000_RXD_STAT_TCPCS
))
3462 if(!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
3465 /* It must be a TCP or UDP packet with a valid checksum */
3466 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
3467 /* TCP checksum is good */
3468 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3469 } else if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3470 /* IP fragment with UDP payload */
3471 /* Hardware complements the payload checksum, so we undo it
3472 * and then put the value in host order for further stack use.
3474 csum
= ntohl(csum
^ 0xFFFF);
3476 skb
->ip_summed
= CHECKSUM_HW
;
3478 adapter
->hw_csum_good
++;
3482 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3483 * @adapter: board private structure
3487 #ifdef CONFIG_E1000_NAPI
3488 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3489 struct e1000_rx_ring
*rx_ring
,
3490 int *work_done
, int work_to_do
)
3492 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3493 struct e1000_rx_ring
*rx_ring
)
3496 struct net_device
*netdev
= adapter
->netdev
;
3497 struct pci_dev
*pdev
= adapter
->pdev
;
3498 struct e1000_rx_desc
*rx_desc
;
3499 struct e1000_buffer
*buffer_info
;
3500 struct sk_buff
*skb
;
3501 unsigned long flags
;
3505 boolean_t cleaned
= FALSE
;
3507 i
= rx_ring
->next_to_clean
;
3508 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3510 while(rx_desc
->status
& E1000_RXD_STAT_DD
) {
3511 buffer_info
= &rx_ring
->buffer_info
[i
];
3512 #ifdef CONFIG_E1000_NAPI
3513 if(*work_done
>= work_to_do
)
3519 pci_unmap_single(pdev
,
3521 buffer_info
->length
,
3522 PCI_DMA_FROMDEVICE
);
3524 skb
= buffer_info
->skb
;
3525 length
= le16_to_cpu(rx_desc
->length
);
3527 if(unlikely(!(rx_desc
->status
& E1000_RXD_STAT_EOP
))) {
3528 /* All receives must fit into a single buffer */
3529 E1000_DBG("%s: Receive packet consumed multiple"
3530 " buffers\n", netdev
->name
);
3531 dev_kfree_skb_irq(skb
);
3535 if(unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
3536 last_byte
= *(skb
->data
+ length
- 1);
3537 if(TBI_ACCEPT(&adapter
->hw
, rx_desc
->status
,
3538 rx_desc
->errors
, length
, last_byte
)) {
3539 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3540 e1000_tbi_adjust_stats(&adapter
->hw
,
3543 spin_unlock_irqrestore(&adapter
->stats_lock
,
3547 dev_kfree_skb_irq(skb
);
3553 skb_put(skb
, length
- ETHERNET_FCS_SIZE
);
3555 /* Receive Checksum Offload */
3556 e1000_rx_checksum(adapter
,
3557 (uint32_t)(rx_desc
->status
) |
3558 ((uint32_t)(rx_desc
->errors
) << 24),
3559 rx_desc
->csum
, skb
);
3560 skb
->protocol
= eth_type_trans(skb
, netdev
);
3561 #ifdef CONFIG_E1000_NAPI
3562 if(unlikely(adapter
->vlgrp
&&
3563 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3564 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3565 le16_to_cpu(rx_desc
->special
) &
3566 E1000_RXD_SPC_VLAN_MASK
);
3568 netif_receive_skb(skb
);
3570 #else /* CONFIG_E1000_NAPI */
3571 if(unlikely(adapter
->vlgrp
&&
3572 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3573 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3574 le16_to_cpu(rx_desc
->special
) &
3575 E1000_RXD_SPC_VLAN_MASK
);
3579 #endif /* CONFIG_E1000_NAPI */
3580 netdev
->last_rx
= jiffies
;
3581 #ifdef CONFIG_E1000_MQ
3582 rx_ring
->rx_stats
.packets
++;
3583 rx_ring
->rx_stats
.bytes
+= length
;
3587 rx_desc
->status
= 0;
3588 buffer_info
->skb
= NULL
;
3589 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3591 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3593 rx_ring
->next_to_clean
= i
;
3594 adapter
->alloc_rx_buf(adapter
, rx_ring
);
3600 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3601 * @adapter: board private structure
3605 #ifdef CONFIG_E1000_NAPI
3606 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3607 struct e1000_rx_ring
*rx_ring
,
3608 int *work_done
, int work_to_do
)
3610 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3611 struct e1000_rx_ring
*rx_ring
)
3614 union e1000_rx_desc_packet_split
*rx_desc
;
3615 struct net_device
*netdev
= adapter
->netdev
;
3616 struct pci_dev
*pdev
= adapter
->pdev
;
3617 struct e1000_buffer
*buffer_info
;
3618 struct e1000_ps_page
*ps_page
;
3619 struct e1000_ps_page_dma
*ps_page_dma
;
3620 struct sk_buff
*skb
;
3622 uint32_t length
, staterr
;
3623 boolean_t cleaned
= FALSE
;
3625 i
= rx_ring
->next_to_clean
;
3626 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3627 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3629 while(staterr
& E1000_RXD_STAT_DD
) {
3630 buffer_info
= &rx_ring
->buffer_info
[i
];
3631 ps_page
= &rx_ring
->ps_page
[i
];
3632 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3633 #ifdef CONFIG_E1000_NAPI
3634 if(unlikely(*work_done
>= work_to_do
))
3639 pci_unmap_single(pdev
, buffer_info
->dma
,
3640 buffer_info
->length
,
3641 PCI_DMA_FROMDEVICE
);
3643 skb
= buffer_info
->skb
;
3645 if(unlikely(!(staterr
& E1000_RXD_STAT_EOP
))) {
3646 E1000_DBG("%s: Packet Split buffers didn't pick up"
3647 " the full packet\n", netdev
->name
);
3648 dev_kfree_skb_irq(skb
);
3652 if(unlikely(staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
)) {
3653 dev_kfree_skb_irq(skb
);
3657 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
3659 if(unlikely(!length
)) {
3660 E1000_DBG("%s: Last part of the packet spanning"
3661 " multiple descriptors\n", netdev
->name
);
3662 dev_kfree_skb_irq(skb
);
3667 skb_put(skb
, length
);
3669 for(j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
3670 if(!(length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
])))
3673 pci_unmap_page(pdev
, ps_page_dma
->ps_page_dma
[j
],
3674 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
3675 ps_page_dma
->ps_page_dma
[j
] = 0;
3676 skb_shinfo(skb
)->frags
[j
].page
=
3677 ps_page
->ps_page
[j
];
3678 ps_page
->ps_page
[j
] = NULL
;
3679 skb_shinfo(skb
)->frags
[j
].page_offset
= 0;
3680 skb_shinfo(skb
)->frags
[j
].size
= length
;
3681 skb_shinfo(skb
)->nr_frags
++;
3683 skb
->data_len
+= length
;
3686 e1000_rx_checksum(adapter
, staterr
,
3687 rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
, skb
);
3688 skb
->protocol
= eth_type_trans(skb
, netdev
);
3690 if(likely(rx_desc
->wb
.upper
.header_status
&
3691 E1000_RXDPS_HDRSTAT_HDRSP
)) {
3692 adapter
->rx_hdr_split
++;
3693 #ifdef HAVE_RX_ZERO_COPY
3694 skb_shinfo(skb
)->zero_copy
= TRUE
;
3697 #ifdef CONFIG_E1000_NAPI
3698 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3699 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3700 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3701 E1000_RXD_SPC_VLAN_MASK
);
3703 netif_receive_skb(skb
);
3705 #else /* CONFIG_E1000_NAPI */
3706 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3707 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3708 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3709 E1000_RXD_SPC_VLAN_MASK
);
3713 #endif /* CONFIG_E1000_NAPI */
3714 netdev
->last_rx
= jiffies
;
3715 #ifdef CONFIG_E1000_MQ
3716 rx_ring
->rx_stats
.packets
++;
3717 rx_ring
->rx_stats
.bytes
+= length
;
3721 rx_desc
->wb
.middle
.status_error
&= ~0xFF;
3722 buffer_info
->skb
= NULL
;
3723 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3725 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3726 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3728 rx_ring
->next_to_clean
= i
;
3729 adapter
->alloc_rx_buf(adapter
, rx_ring
);
3735 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3736 * @adapter: address of board private structure
3740 e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
3741 struct e1000_rx_ring
*rx_ring
)
3743 struct net_device
*netdev
= adapter
->netdev
;
3744 struct pci_dev
*pdev
= adapter
->pdev
;
3745 struct e1000_rx_desc
*rx_desc
;
3746 struct e1000_buffer
*buffer_info
;
3747 struct sk_buff
*skb
;
3749 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
3751 i
= rx_ring
->next_to_use
;
3752 buffer_info
= &rx_ring
->buffer_info
[i
];
3754 while(!buffer_info
->skb
) {
3755 skb
= dev_alloc_skb(bufsz
);
3757 if(unlikely(!skb
)) {
3758 /* Better luck next round */
3762 /* Fix for errata 23, can't cross 64kB boundary */
3763 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3764 struct sk_buff
*oldskb
= skb
;
3765 DPRINTK(RX_ERR
, ERR
, "skb align check failed: %u bytes "
3766 "at %p\n", bufsz
, skb
->data
);
3767 /* Try again, without freeing the previous */
3768 skb
= dev_alloc_skb(bufsz
);
3769 /* Failed allocation, critical failure */
3771 dev_kfree_skb(oldskb
);
3775 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3778 dev_kfree_skb(oldskb
);
3779 break; /* while !buffer_info->skb */
3781 /* Use new allocation */
3782 dev_kfree_skb(oldskb
);
3785 /* Make buffer alignment 2 beyond a 16 byte boundary
3786 * this will result in a 16 byte aligned IP header after
3787 * the 14 byte MAC header is removed
3789 skb_reserve(skb
, NET_IP_ALIGN
);
3793 buffer_info
->skb
= skb
;
3794 buffer_info
->length
= adapter
->rx_buffer_len
;
3795 buffer_info
->dma
= pci_map_single(pdev
,
3797 adapter
->rx_buffer_len
,
3798 PCI_DMA_FROMDEVICE
);
3800 /* Fix for errata 23, can't cross 64kB boundary */
3801 if (!e1000_check_64k_bound(adapter
,
3802 (void *)(unsigned long)buffer_info
->dma
,
3803 adapter
->rx_buffer_len
)) {
3804 DPRINTK(RX_ERR
, ERR
,
3805 "dma align check failed: %u bytes at %p\n",
3806 adapter
->rx_buffer_len
,
3807 (void *)(unsigned long)buffer_info
->dma
);
3809 buffer_info
->skb
= NULL
;
3811 pci_unmap_single(pdev
, buffer_info
->dma
,
3812 adapter
->rx_buffer_len
,
3813 PCI_DMA_FROMDEVICE
);
3815 break; /* while !buffer_info->skb */
3817 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3818 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3820 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3821 /* Force memory writes to complete before letting h/w
3822 * know there are new descriptors to fetch. (Only
3823 * applicable for weak-ordered memory model archs,
3824 * such as IA-64). */
3826 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
3829 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3830 buffer_info
= &rx_ring
->buffer_info
[i
];
3833 rx_ring
->next_to_use
= i
;
3837 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3838 * @adapter: address of board private structure
3842 e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
3843 struct e1000_rx_ring
*rx_ring
)
3845 struct net_device
*netdev
= adapter
->netdev
;
3846 struct pci_dev
*pdev
= adapter
->pdev
;
3847 union e1000_rx_desc_packet_split
*rx_desc
;
3848 struct e1000_buffer
*buffer_info
;
3849 struct e1000_ps_page
*ps_page
;
3850 struct e1000_ps_page_dma
*ps_page_dma
;
3851 struct sk_buff
*skb
;
3854 i
= rx_ring
->next_to_use
;
3855 buffer_info
= &rx_ring
->buffer_info
[i
];
3856 ps_page
= &rx_ring
->ps_page
[i
];
3857 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3859 while(!buffer_info
->skb
) {
3860 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3862 for(j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
3863 if (j
< adapter
->rx_ps_pages
) {
3864 if (likely(!ps_page
->ps_page
[j
])) {
3865 ps_page
->ps_page
[j
] =
3866 alloc_page(GFP_ATOMIC
);
3867 if (unlikely(!ps_page
->ps_page
[j
]))
3869 ps_page_dma
->ps_page_dma
[j
] =
3871 ps_page
->ps_page
[j
],
3873 PCI_DMA_FROMDEVICE
);
3875 /* Refresh the desc even if buffer_addrs didn't
3876 * change because each write-back erases
3879 rx_desc
->read
.buffer_addr
[j
+1] =
3880 cpu_to_le64(ps_page_dma
->ps_page_dma
[j
]);
3882 rx_desc
->read
.buffer_addr
[j
+1] = ~0;
3885 skb
= dev_alloc_skb(adapter
->rx_ps_bsize0
+ NET_IP_ALIGN
);
3890 /* Make buffer alignment 2 beyond a 16 byte boundary
3891 * this will result in a 16 byte aligned IP header after
3892 * the 14 byte MAC header is removed
3894 skb_reserve(skb
, NET_IP_ALIGN
);
3898 buffer_info
->skb
= skb
;
3899 buffer_info
->length
= adapter
->rx_ps_bsize0
;
3900 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
3901 adapter
->rx_ps_bsize0
,
3902 PCI_DMA_FROMDEVICE
);
3904 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
3906 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3907 /* Force memory writes to complete before letting h/w
3908 * know there are new descriptors to fetch. (Only
3909 * applicable for weak-ordered memory model archs,
3910 * such as IA-64). */
3912 /* Hardware increments by 16 bytes, but packet split
3913 * descriptors are 32 bytes...so we increment tail
3916 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
3919 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3920 buffer_info
= &rx_ring
->buffer_info
[i
];
3921 ps_page
= &rx_ring
->ps_page
[i
];
3922 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3926 rx_ring
->next_to_use
= i
;
3930 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3935 e1000_smartspeed(struct e1000_adapter
*adapter
)
3937 uint16_t phy_status
;
3940 if((adapter
->hw
.phy_type
!= e1000_phy_igp
) || !adapter
->hw
.autoneg
||
3941 !(adapter
->hw
.autoneg_advertised
& ADVERTISE_1000_FULL
))
3944 if(adapter
->smartspeed
== 0) {
3945 /* If Master/Slave config fault is asserted twice,
3946 * we assume back-to-back */
3947 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
3948 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
3949 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
3950 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
3951 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
3952 if(phy_ctrl
& CR_1000T_MS_ENABLE
) {
3953 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
3954 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
,
3956 adapter
->smartspeed
++;
3957 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
3958 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
,
3960 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
3961 MII_CR_RESTART_AUTO_NEG
);
3962 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
,
3967 } else if(adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
3968 /* If still no link, perhaps using 2/3 pair cable */
3969 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
3970 phy_ctrl
|= CR_1000T_MS_ENABLE
;
3971 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, phy_ctrl
);
3972 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
3973 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &phy_ctrl
)) {
3974 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
3975 MII_CR_RESTART_AUTO_NEG
);
3976 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, phy_ctrl
);
3979 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3980 if(adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
3981 adapter
->smartspeed
= 0;
3992 e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
3998 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4012 e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4014 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4015 struct mii_ioctl_data
*data
= if_mii(ifr
);
4019 unsigned long flags
;
4021 if(adapter
->hw
.media_type
!= e1000_media_type_copper
)
4026 data
->phy_id
= adapter
->hw
.phy_addr
;
4029 if(!capable(CAP_NET_ADMIN
))
4031 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4032 if(e1000_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
4034 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4037 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4040 if(!capable(CAP_NET_ADMIN
))
4042 if(data
->reg_num
& ~(0x1F))
4044 mii_reg
= data
->val_in
;
4045 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4046 if(e1000_write_phy_reg(&adapter
->hw
, data
->reg_num
,
4048 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4051 if(adapter
->hw
.phy_type
== e1000_phy_m88
) {
4052 switch (data
->reg_num
) {
4054 if(mii_reg
& MII_CR_POWER_DOWN
)
4056 if(mii_reg
& MII_CR_AUTO_NEG_EN
) {
4057 adapter
->hw
.autoneg
= 1;
4058 adapter
->hw
.autoneg_advertised
= 0x2F;
4061 spddplx
= SPEED_1000
;
4062 else if (mii_reg
& 0x2000)
4063 spddplx
= SPEED_100
;
4066 spddplx
+= (mii_reg
& 0x100)
4069 retval
= e1000_set_spd_dplx(adapter
,
4072 spin_unlock_irqrestore(
4073 &adapter
->stats_lock
,
4078 if(netif_running(adapter
->netdev
)) {
4079 e1000_down(adapter
);
4082 e1000_reset(adapter
);
4084 case M88E1000_PHY_SPEC_CTRL
:
4085 case M88E1000_EXT_PHY_SPEC_CTRL
:
4086 if(e1000_phy_reset(&adapter
->hw
)) {
4087 spin_unlock_irqrestore(
4088 &adapter
->stats_lock
, flags
);
4094 switch (data
->reg_num
) {
4096 if(mii_reg
& MII_CR_POWER_DOWN
)
4098 if(netif_running(adapter
->netdev
)) {
4099 e1000_down(adapter
);
4102 e1000_reset(adapter
);
4106 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4111 return E1000_SUCCESS
;
4115 e1000_pci_set_mwi(struct e1000_hw
*hw
)
4117 struct e1000_adapter
*adapter
= hw
->back
;
4118 int ret_val
= pci_set_mwi(adapter
->pdev
);
4121 DPRINTK(PROBE
, ERR
, "Error in setting MWI\n");
4125 e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4127 struct e1000_adapter
*adapter
= hw
->back
;
4129 pci_clear_mwi(adapter
->pdev
);
4133 e1000_read_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4135 struct e1000_adapter
*adapter
= hw
->back
;
4137 pci_read_config_word(adapter
->pdev
, reg
, value
);
4141 e1000_write_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4143 struct e1000_adapter
*adapter
= hw
->back
;
4145 pci_write_config_word(adapter
->pdev
, reg
, *value
);
4149 e1000_io_read(struct e1000_hw
*hw
, unsigned long port
)
4155 e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, uint32_t value
)
4161 e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
4163 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4164 uint32_t ctrl
, rctl
;
4166 e1000_irq_disable(adapter
);
4167 adapter
->vlgrp
= grp
;
4170 /* enable VLAN tag insert/strip */
4171 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4172 ctrl
|= E1000_CTRL_VME
;
4173 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4175 /* enable VLAN receive filtering */
4176 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4177 rctl
|= E1000_RCTL_VFE
;
4178 rctl
&= ~E1000_RCTL_CFIEN
;
4179 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4180 e1000_update_mng_vlan(adapter
);
4182 /* disable VLAN tag insert/strip */
4183 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4184 ctrl
&= ~E1000_CTRL_VME
;
4185 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4187 /* disable VLAN filtering */
4188 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4189 rctl
&= ~E1000_RCTL_VFE
;
4190 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4191 if(adapter
->mng_vlan_id
!= (uint16_t)E1000_MNG_VLAN_NONE
) {
4192 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
4193 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
4197 e1000_irq_enable(adapter
);
4201 e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
)
4203 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4204 uint32_t vfta
, index
;
4205 if((adapter
->hw
.mng_cookie
.status
&
4206 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4207 (vid
== adapter
->mng_vlan_id
))
4209 /* add VID to filter table */
4210 index
= (vid
>> 5) & 0x7F;
4211 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4212 vfta
|= (1 << (vid
& 0x1F));
4213 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4217 e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
)
4219 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4220 uint32_t vfta
, index
;
4222 e1000_irq_disable(adapter
);
4225 adapter
->vlgrp
->vlan_devices
[vid
] = NULL
;
4227 e1000_irq_enable(adapter
);
4229 if((adapter
->hw
.mng_cookie
.status
&
4230 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4231 (vid
== adapter
->mng_vlan_id
))
4233 /* remove VID from filter table */
4234 index
= (vid
>> 5) & 0x7F;
4235 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4236 vfta
&= ~(1 << (vid
& 0x1F));
4237 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4241 e1000_restore_vlan(struct e1000_adapter
*adapter
)
4243 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
4245 if(adapter
->vlgrp
) {
4247 for(vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
4248 if(!adapter
->vlgrp
->vlan_devices
[vid
])
4250 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
4256 e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
)
4258 adapter
->hw
.autoneg
= 0;
4260 /* Fiber NICs only allow 1000 gbps Full duplex */
4261 if((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
4262 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
4263 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4268 case SPEED_10
+ DUPLEX_HALF
:
4269 adapter
->hw
.forced_speed_duplex
= e1000_10_half
;
4271 case SPEED_10
+ DUPLEX_FULL
:
4272 adapter
->hw
.forced_speed_duplex
= e1000_10_full
;
4274 case SPEED_100
+ DUPLEX_HALF
:
4275 adapter
->hw
.forced_speed_duplex
= e1000_100_half
;
4277 case SPEED_100
+ DUPLEX_FULL
:
4278 adapter
->hw
.forced_speed_duplex
= e1000_100_full
;
4280 case SPEED_1000
+ DUPLEX_FULL
:
4281 adapter
->hw
.autoneg
= 1;
4282 adapter
->hw
.autoneg_advertised
= ADVERTISE_1000_FULL
;
4284 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
4286 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4294 e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4296 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4297 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4298 uint32_t ctrl
, ctrl_ext
, rctl
, manc
, status
;
4299 uint32_t wufc
= adapter
->wol
;
4301 netif_device_detach(netdev
);
4303 if(netif_running(netdev
))
4304 e1000_down(adapter
);
4306 status
= E1000_READ_REG(&adapter
->hw
, STATUS
);
4307 if(status
& E1000_STATUS_LU
)
4308 wufc
&= ~E1000_WUFC_LNKC
;
4311 e1000_setup_rctl(adapter
);
4312 e1000_set_multi(netdev
);
4314 /* turn on all-multi mode if wake on multicast is enabled */
4315 if(adapter
->wol
& E1000_WUFC_MC
) {
4316 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4317 rctl
|= E1000_RCTL_MPE
;
4318 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4321 if(adapter
->hw
.mac_type
>= e1000_82540
) {
4322 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4323 /* advertise wake from D3Cold */
4324 #define E1000_CTRL_ADVD3WUC 0x00100000
4325 /* phy power management enable */
4326 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4327 ctrl
|= E1000_CTRL_ADVD3WUC
|
4328 E1000_CTRL_EN_PHY_PWR_MGMT
;
4329 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4332 if(adapter
->hw
.media_type
== e1000_media_type_fiber
||
4333 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) {
4334 /* keep the laser running in D3 */
4335 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
4336 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
4337 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
, ctrl_ext
);
4340 /* Allow time for pending master requests to run */
4341 e1000_disable_pciex_master(&adapter
->hw
);
4343 E1000_WRITE_REG(&adapter
->hw
, WUC
, E1000_WUC_PME_EN
);
4344 E1000_WRITE_REG(&adapter
->hw
, WUFC
, wufc
);
4345 pci_enable_wake(pdev
, 3, 1);
4346 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
4348 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
4349 E1000_WRITE_REG(&adapter
->hw
, WUFC
, 0);
4350 pci_enable_wake(pdev
, 3, 0);
4351 pci_enable_wake(pdev
, 4, 0); /* 4 == D3 cold */
4354 pci_save_state(pdev
);
4356 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4357 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4358 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4359 if(manc
& E1000_MANC_SMBUS_EN
) {
4360 manc
|= E1000_MANC_ARP_EN
;
4361 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4362 pci_enable_wake(pdev
, 3, 1);
4363 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
4367 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4368 * would have already happened in close and is redundant. */
4369 e1000_release_hw_control(adapter
);
4371 pci_disable_device(pdev
);
4372 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4378 e1000_resume(struct pci_dev
*pdev
)
4380 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4381 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4382 uint32_t manc
, ret_val
;
4384 pci_set_power_state(pdev
, PCI_D0
);
4385 pci_restore_state(pdev
);
4386 ret_val
= pci_enable_device(pdev
);
4387 pci_set_master(pdev
);
4389 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4390 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4392 e1000_reset(adapter
);
4393 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
4395 if(netif_running(netdev
))
4398 netif_device_attach(netdev
);
4400 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4401 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4402 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4403 manc
&= ~(E1000_MANC_ARP_EN
);
4404 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4407 /* If the controller is 82573 and f/w is AMT, do not set
4408 * DRV_LOAD until the interface is up. For all other cases,
4409 * let the f/w know that the h/w is now under the control
4411 if (adapter
->hw
.mac_type
!= e1000_82573
||
4412 !e1000_check_mng_mode(&adapter
->hw
))
4413 e1000_get_hw_control(adapter
);
4418 #ifdef CONFIG_NET_POLL_CONTROLLER
4420 * Polling 'interrupt' - used by things like netconsole to send skbs
4421 * without having to re-enable interrupts. It's not called while
4422 * the interrupt routine is executing.
4425 e1000_netpoll(struct net_device
*netdev
)
4427 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4428 disable_irq(adapter
->pdev
->irq
);
4429 e1000_intr(adapter
->pdev
->irq
, netdev
, NULL
);
4430 e1000_clean_tx_irq(adapter
, adapter
->tx_ring
);
4431 enable_irq(adapter
->pdev
->irq
);