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(0x1099),
101 INTEL_E1000_ETHERNET_DEVICE(0x109A),
102 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
103 /* required last entry */
107 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
109 int e1000_up(struct e1000_adapter
*adapter
);
110 void e1000_down(struct e1000_adapter
*adapter
);
111 void e1000_reset(struct e1000_adapter
*adapter
);
112 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
);
113 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
);
114 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
);
115 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
);
116 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
);
117 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
118 struct e1000_tx_ring
*txdr
);
119 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
120 struct e1000_rx_ring
*rxdr
);
121 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
122 struct e1000_tx_ring
*tx_ring
);
123 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
124 struct e1000_rx_ring
*rx_ring
);
125 void e1000_update_stats(struct e1000_adapter
*adapter
);
127 /* Local Function Prototypes */
129 static int e1000_init_module(void);
130 static void e1000_exit_module(void);
131 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
132 static void __devexit
e1000_remove(struct pci_dev
*pdev
);
133 static int e1000_alloc_queues(struct e1000_adapter
*adapter
);
134 #ifdef CONFIG_E1000_MQ
135 static void e1000_setup_queue_mapping(struct e1000_adapter
*adapter
);
137 static int e1000_sw_init(struct e1000_adapter
*adapter
);
138 static int e1000_open(struct net_device
*netdev
);
139 static int e1000_close(struct net_device
*netdev
);
140 static void e1000_configure_tx(struct e1000_adapter
*adapter
);
141 static void e1000_configure_rx(struct e1000_adapter
*adapter
);
142 static void e1000_setup_rctl(struct e1000_adapter
*adapter
);
143 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
);
144 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
);
145 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
146 struct e1000_tx_ring
*tx_ring
);
147 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
148 struct e1000_rx_ring
*rx_ring
);
149 static void e1000_set_multi(struct net_device
*netdev
);
150 static void e1000_update_phy_info(unsigned long data
);
151 static void e1000_watchdog(unsigned long data
);
152 static void e1000_watchdog_task(struct e1000_adapter
*adapter
);
153 static void e1000_82547_tx_fifo_stall(unsigned long data
);
154 static int e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
);
155 static struct net_device_stats
* e1000_get_stats(struct net_device
*netdev
);
156 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
157 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
158 static irqreturn_t
e1000_intr(int irq
, void *data
, struct pt_regs
*regs
);
159 static boolean_t
e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
160 struct e1000_tx_ring
*tx_ring
);
161 #ifdef CONFIG_E1000_NAPI
162 static int e1000_clean(struct net_device
*poll_dev
, int *budget
);
163 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
164 struct e1000_rx_ring
*rx_ring
,
165 int *work_done
, int work_to_do
);
166 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
167 struct e1000_rx_ring
*rx_ring
,
168 int *work_done
, int work_to_do
);
170 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
171 struct e1000_rx_ring
*rx_ring
);
172 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
173 struct e1000_rx_ring
*rx_ring
);
175 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
176 struct e1000_rx_ring
*rx_ring
,
178 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
179 struct e1000_rx_ring
*rx_ring
,
181 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
182 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
184 void e1000_set_ethtool_ops(struct net_device
*netdev
);
185 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
186 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
187 static void e1000_tx_timeout(struct net_device
*dev
);
188 static void e1000_tx_timeout_task(struct net_device
*dev
);
189 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
190 static inline int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
191 struct sk_buff
*skb
);
193 static void e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
);
194 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
);
195 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
);
196 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
199 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
);
200 static int e1000_resume(struct pci_dev
*pdev
);
203 #ifdef CONFIG_NET_POLL_CONTROLLER
204 /* for netdump / net console */
205 static void e1000_netpoll (struct net_device
*netdev
);
208 #ifdef CONFIG_E1000_MQ
209 /* for multiple Rx queues */
210 void e1000_rx_schedule(void *data
);
213 /* Exported from other modules */
215 extern void e1000_check_options(struct e1000_adapter
*adapter
);
217 static struct pci_driver e1000_driver
= {
218 .name
= e1000_driver_name
,
219 .id_table
= e1000_pci_tbl
,
220 .probe
= e1000_probe
,
221 .remove
= __devexit_p(e1000_remove
),
222 /* Power Managment Hooks */
224 .suspend
= e1000_suspend
,
225 .resume
= e1000_resume
229 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
230 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
231 MODULE_LICENSE("GPL");
232 MODULE_VERSION(DRV_VERSION
);
234 static int debug
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
235 module_param(debug
, int, 0);
236 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
239 * e1000_init_module - Driver Registration Routine
241 * e1000_init_module is the first routine called when the driver is
242 * loaded. All it does is register with the PCI subsystem.
246 e1000_init_module(void)
249 printk(KERN_INFO
"%s - version %s\n",
250 e1000_driver_string
, e1000_driver_version
);
252 printk(KERN_INFO
"%s\n", e1000_copyright
);
254 ret
= pci_module_init(&e1000_driver
);
259 module_init(e1000_init_module
);
262 * e1000_exit_module - Driver Exit Cleanup Routine
264 * e1000_exit_module is called just before the driver is removed
269 e1000_exit_module(void)
271 pci_unregister_driver(&e1000_driver
);
274 module_exit(e1000_exit_module
);
277 * e1000_irq_disable - Mask off interrupt generation on the NIC
278 * @adapter: board private structure
282 e1000_irq_disable(struct e1000_adapter
*adapter
)
284 atomic_inc(&adapter
->irq_sem
);
285 E1000_WRITE_REG(&adapter
->hw
, IMC
, ~0);
286 E1000_WRITE_FLUSH(&adapter
->hw
);
287 synchronize_irq(adapter
->pdev
->irq
);
291 * e1000_irq_enable - Enable default interrupt generation settings
292 * @adapter: board private structure
296 e1000_irq_enable(struct e1000_adapter
*adapter
)
298 if(likely(atomic_dec_and_test(&adapter
->irq_sem
))) {
299 E1000_WRITE_REG(&adapter
->hw
, IMS
, IMS_ENABLE_MASK
);
300 E1000_WRITE_FLUSH(&adapter
->hw
);
305 e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
307 struct net_device
*netdev
= adapter
->netdev
;
308 uint16_t vid
= adapter
->hw
.mng_cookie
.vlan_id
;
309 uint16_t old_vid
= adapter
->mng_vlan_id
;
311 if(!adapter
->vlgrp
->vlan_devices
[vid
]) {
312 if(adapter
->hw
.mng_cookie
.status
&
313 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
314 e1000_vlan_rx_add_vid(netdev
, vid
);
315 adapter
->mng_vlan_id
= vid
;
317 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
319 if((old_vid
!= (uint16_t)E1000_MNG_VLAN_NONE
) &&
321 !adapter
->vlgrp
->vlan_devices
[old_vid
])
322 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
328 * e1000_release_hw_control - release control of the h/w to f/w
329 * @adapter: address of board private structure
331 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
332 * For ASF and Pass Through versions of f/w this means that the
333 * driver is no longer loaded. For AMT version (only with 82573) i
334 * of the f/w this means that the netowrk i/f is closed.
339 e1000_release_hw_control(struct e1000_adapter
*adapter
)
344 /* Let firmware taken over control of h/w */
345 switch (adapter
->hw
.mac_type
) {
348 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
349 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
350 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
353 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
354 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
355 swsm
& ~E1000_SWSM_DRV_LOAD
);
362 * e1000_get_hw_control - get control of the h/w from f/w
363 * @adapter: address of board private structure
365 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
366 * For ASF and Pass Through versions of f/w this means that
367 * the driver is loaded. For AMT version (only with 82573)
368 * of the f/w this means that the netowrk i/f is open.
373 e1000_get_hw_control(struct e1000_adapter
*adapter
)
377 /* Let firmware know the driver has taken over */
378 switch (adapter
->hw
.mac_type
) {
381 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
382 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
383 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
386 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
387 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
388 swsm
| E1000_SWSM_DRV_LOAD
);
396 e1000_up(struct e1000_adapter
*adapter
)
398 struct net_device
*netdev
= adapter
->netdev
;
401 /* hardware has been reset, we need to reload some things */
403 /* Reset the PHY if it was previously powered down */
404 if(adapter
->hw
.media_type
== e1000_media_type_copper
) {
406 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
407 if(mii_reg
& MII_CR_POWER_DOWN
)
408 e1000_phy_reset(&adapter
->hw
);
411 e1000_set_multi(netdev
);
413 e1000_restore_vlan(adapter
);
415 e1000_configure_tx(adapter
);
416 e1000_setup_rctl(adapter
);
417 e1000_configure_rx(adapter
);
418 /* call E1000_DESC_UNUSED which always leaves
419 * at least 1 descriptor unused to make sure
420 * next_to_use != next_to_clean */
421 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
422 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[i
];
423 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
426 #ifdef CONFIG_PCI_MSI
427 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
428 adapter
->have_msi
= TRUE
;
429 if((err
= pci_enable_msi(adapter
->pdev
))) {
431 "Unable to allocate MSI interrupt Error: %d\n", err
);
432 adapter
->have_msi
= FALSE
;
436 if((err
= request_irq(adapter
->pdev
->irq
, &e1000_intr
,
437 SA_SHIRQ
| SA_SAMPLE_RANDOM
,
438 netdev
->name
, netdev
))) {
440 "Unable to allocate interrupt Error: %d\n", err
);
444 #ifdef CONFIG_E1000_MQ
445 e1000_setup_queue_mapping(adapter
);
448 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
450 mod_timer(&adapter
->watchdog_timer
, jiffies
);
452 #ifdef CONFIG_E1000_NAPI
453 netif_poll_enable(netdev
);
455 e1000_irq_enable(adapter
);
461 e1000_down(struct e1000_adapter
*adapter
)
463 struct net_device
*netdev
= adapter
->netdev
;
464 boolean_t mng_mode_enabled
= (adapter
->hw
.mac_type
>= e1000_82571
) &&
465 e1000_check_mng_mode(&adapter
->hw
);
467 e1000_irq_disable(adapter
);
468 #ifdef CONFIG_E1000_MQ
469 while (atomic_read(&adapter
->rx_sched_call_data
.count
) != 0);
471 free_irq(adapter
->pdev
->irq
, netdev
);
472 #ifdef CONFIG_PCI_MSI
473 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
&&
474 adapter
->have_msi
== TRUE
)
475 pci_disable_msi(adapter
->pdev
);
477 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
478 del_timer_sync(&adapter
->watchdog_timer
);
479 del_timer_sync(&adapter
->phy_info_timer
);
481 #ifdef CONFIG_E1000_NAPI
482 netif_poll_disable(netdev
);
484 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
485 adapter
->link_speed
= 0;
486 adapter
->link_duplex
= 0;
487 netif_carrier_off(netdev
);
488 netif_stop_queue(netdev
);
490 e1000_reset(adapter
);
491 e1000_clean_all_tx_rings(adapter
);
492 e1000_clean_all_rx_rings(adapter
);
494 /* Power down the PHY so no link is implied when interface is down *
495 * The PHY cannot be powered down if any of the following is TRUE *
498 * (c) SoL/IDER session is active */
499 if (!adapter
->wol
&& adapter
->hw
.mac_type
>= e1000_82540
&&
500 adapter
->hw
.media_type
== e1000_media_type_copper
&&
501 !(E1000_READ_REG(&adapter
->hw
, MANC
) & E1000_MANC_SMBUS_EN
) &&
503 !e1000_check_phy_reset_block(&adapter
->hw
)) {
505 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
506 mii_reg
|= MII_CR_POWER_DOWN
;
507 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
513 e1000_reset(struct e1000_adapter
*adapter
)
516 uint16_t fc_high_water_mark
= E1000_FC_HIGH_DIFF
;
518 /* Repartition Pba for greater than 9k mtu
519 * To take effect CTRL.RST is required.
522 switch (adapter
->hw
.mac_type
) {
524 case e1000_82547_rev_2
:
539 if((adapter
->hw
.mac_type
!= e1000_82573
) &&
540 (adapter
->netdev
->mtu
> E1000_RXBUFFER_8192
))
541 pba
-= 8; /* allocate more FIFO for Tx */
544 if(adapter
->hw
.mac_type
== e1000_82547
) {
545 adapter
->tx_fifo_head
= 0;
546 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
547 adapter
->tx_fifo_size
=
548 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
549 atomic_set(&adapter
->tx_fifo_stall
, 0);
552 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
554 /* flow control settings */
555 /* Set the FC high water mark to 90% of the FIFO size.
556 * Required to clear last 3 LSB */
557 fc_high_water_mark
= ((pba
* 9216)/10) & 0xFFF8;
559 adapter
->hw
.fc_high_water
= fc_high_water_mark
;
560 adapter
->hw
.fc_low_water
= fc_high_water_mark
- 8;
561 adapter
->hw
.fc_pause_time
= E1000_FC_PAUSE_TIME
;
562 adapter
->hw
.fc_send_xon
= 1;
563 adapter
->hw
.fc
= adapter
->hw
.original_fc
;
565 /* Allow time for pending master requests to run */
566 e1000_reset_hw(&adapter
->hw
);
567 if(adapter
->hw
.mac_type
>= e1000_82544
)
568 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
569 if(e1000_init_hw(&adapter
->hw
))
570 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
571 e1000_update_mng_vlan(adapter
);
572 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
573 E1000_WRITE_REG(&adapter
->hw
, VET
, ETHERNET_IEEE_VLAN_TYPE
);
575 e1000_reset_adaptive(&adapter
->hw
);
576 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
577 if (adapter
->en_mng_pt
) {
578 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
579 manc
|= (E1000_MANC_ARP_EN
| E1000_MANC_EN_MNG2HOST
);
580 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
585 * e1000_probe - Device Initialization Routine
586 * @pdev: PCI device information struct
587 * @ent: entry in e1000_pci_tbl
589 * Returns 0 on success, negative on failure
591 * e1000_probe initializes an adapter identified by a pci_dev structure.
592 * The OS initialization, configuring of the adapter private structure,
593 * and a hardware reset occur.
597 e1000_probe(struct pci_dev
*pdev
,
598 const struct pci_device_id
*ent
)
600 struct net_device
*netdev
;
601 struct e1000_adapter
*adapter
;
602 unsigned long mmio_start
, mmio_len
;
604 static int cards_found
= 0;
605 int i
, err
, pci_using_dac
;
606 uint16_t eeprom_data
;
607 uint16_t eeprom_apme_mask
= E1000_EEPROM_APME
;
608 if((err
= pci_enable_device(pdev
)))
611 if(!(err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
))) {
614 if((err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
))) {
615 E1000_ERR("No usable DMA configuration, aborting\n");
621 if((err
= pci_request_regions(pdev
, e1000_driver_name
)))
624 pci_set_master(pdev
);
626 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
629 goto err_alloc_etherdev
;
632 SET_MODULE_OWNER(netdev
);
633 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
635 pci_set_drvdata(pdev
, netdev
);
636 adapter
= netdev_priv(netdev
);
637 adapter
->netdev
= netdev
;
638 adapter
->pdev
= pdev
;
639 adapter
->hw
.back
= adapter
;
640 adapter
->msg_enable
= (1 << debug
) - 1;
642 mmio_start
= pci_resource_start(pdev
, BAR_0
);
643 mmio_len
= pci_resource_len(pdev
, BAR_0
);
645 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
646 if(!adapter
->hw
.hw_addr
) {
651 for(i
= BAR_1
; i
<= BAR_5
; i
++) {
652 if(pci_resource_len(pdev
, i
) == 0)
654 if(pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
655 adapter
->hw
.io_base
= pci_resource_start(pdev
, i
);
660 netdev
->open
= &e1000_open
;
661 netdev
->stop
= &e1000_close
;
662 netdev
->hard_start_xmit
= &e1000_xmit_frame
;
663 netdev
->get_stats
= &e1000_get_stats
;
664 netdev
->set_multicast_list
= &e1000_set_multi
;
665 netdev
->set_mac_address
= &e1000_set_mac
;
666 netdev
->change_mtu
= &e1000_change_mtu
;
667 netdev
->do_ioctl
= &e1000_ioctl
;
668 e1000_set_ethtool_ops(netdev
);
669 netdev
->tx_timeout
= &e1000_tx_timeout
;
670 netdev
->watchdog_timeo
= 5 * HZ
;
671 #ifdef CONFIG_E1000_NAPI
672 netdev
->poll
= &e1000_clean
;
675 netdev
->vlan_rx_register
= e1000_vlan_rx_register
;
676 netdev
->vlan_rx_add_vid
= e1000_vlan_rx_add_vid
;
677 netdev
->vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
;
678 #ifdef CONFIG_NET_POLL_CONTROLLER
679 netdev
->poll_controller
= e1000_netpoll
;
681 strcpy(netdev
->name
, pci_name(pdev
));
683 netdev
->mem_start
= mmio_start
;
684 netdev
->mem_end
= mmio_start
+ mmio_len
;
685 netdev
->base_addr
= adapter
->hw
.io_base
;
687 adapter
->bd_number
= cards_found
;
689 /* setup the private structure */
691 if((err
= e1000_sw_init(adapter
)))
694 if((err
= e1000_check_phy_reset_block(&adapter
->hw
)))
695 DPRINTK(PROBE
, INFO
, "PHY reset is blocked due to SOL/IDER session.\n");
697 if(adapter
->hw
.mac_type
>= e1000_82543
) {
698 netdev
->features
= NETIF_F_SG
|
702 NETIF_F_HW_VLAN_FILTER
;
706 if((adapter
->hw
.mac_type
>= e1000_82544
) &&
707 (adapter
->hw
.mac_type
!= e1000_82547
))
708 netdev
->features
|= NETIF_F_TSO
;
710 #ifdef NETIF_F_TSO_IPV6
711 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
)
712 netdev
->features
|= NETIF_F_TSO_IPV6
;
716 netdev
->features
|= NETIF_F_HIGHDMA
;
718 /* hard_start_xmit is safe against parallel locking */
719 netdev
->features
|= NETIF_F_LLTX
;
721 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(&adapter
->hw
);
723 /* before reading the EEPROM, reset the controller to
724 * put the device in a known good starting state */
726 e1000_reset_hw(&adapter
->hw
);
728 /* make sure the EEPROM is good */
730 if(e1000_validate_eeprom_checksum(&adapter
->hw
) < 0) {
731 DPRINTK(PROBE
, ERR
, "The EEPROM Checksum Is Not Valid\n");
736 /* copy the MAC address out of the EEPROM */
738 if(e1000_read_mac_addr(&adapter
->hw
))
739 DPRINTK(PROBE
, ERR
, "EEPROM Read Error\n");
740 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
741 memcpy(netdev
->perm_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
743 if(!is_valid_ether_addr(netdev
->perm_addr
)) {
744 DPRINTK(PROBE
, ERR
, "Invalid MAC Address\n");
749 e1000_read_part_num(&adapter
->hw
, &(adapter
->part_num
));
751 e1000_get_bus_info(&adapter
->hw
);
753 init_timer(&adapter
->tx_fifo_stall_timer
);
754 adapter
->tx_fifo_stall_timer
.function
= &e1000_82547_tx_fifo_stall
;
755 adapter
->tx_fifo_stall_timer
.data
= (unsigned long) adapter
;
757 init_timer(&adapter
->watchdog_timer
);
758 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
759 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
761 INIT_WORK(&adapter
->watchdog_task
,
762 (void (*)(void *))e1000_watchdog_task
, adapter
);
764 init_timer(&adapter
->phy_info_timer
);
765 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
766 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
768 INIT_WORK(&adapter
->tx_timeout_task
,
769 (void (*)(void *))e1000_tx_timeout_task
, netdev
);
771 /* we're going to reset, so assume we have no link for now */
773 netif_carrier_off(netdev
);
774 netif_stop_queue(netdev
);
776 e1000_check_options(adapter
);
778 /* Initial Wake on LAN setting
779 * If APM wake is enabled in the EEPROM,
780 * enable the ACPI Magic Packet filter
783 switch(adapter
->hw
.mac_type
) {
784 case e1000_82542_rev2_0
:
785 case e1000_82542_rev2_1
:
789 e1000_read_eeprom(&adapter
->hw
,
790 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
791 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
794 case e1000_82546_rev_3
:
796 if(E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
){
797 e1000_read_eeprom(&adapter
->hw
,
798 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
803 e1000_read_eeprom(&adapter
->hw
,
804 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
807 if(eeprom_data
& eeprom_apme_mask
)
808 adapter
->wol
|= E1000_WUFC_MAG
;
810 /* print bus type/speed/width info */
812 struct e1000_hw
*hw
= &adapter
->hw
;
813 DPRINTK(PROBE
, INFO
, "(PCI%s:%s:%s) ",
814 ((hw
->bus_type
== e1000_bus_type_pcix
) ? "-X" :
815 (hw
->bus_type
== e1000_bus_type_pci_express
? " Express":"")),
816 ((hw
->bus_speed
== e1000_bus_speed_2500
) ? "2.5Gb/s" :
817 (hw
->bus_speed
== e1000_bus_speed_133
) ? "133MHz" :
818 (hw
->bus_speed
== e1000_bus_speed_120
) ? "120MHz" :
819 (hw
->bus_speed
== e1000_bus_speed_100
) ? "100MHz" :
820 (hw
->bus_speed
== e1000_bus_speed_66
) ? "66MHz" : "33MHz"),
821 ((hw
->bus_width
== e1000_bus_width_64
) ? "64-bit" :
822 (hw
->bus_width
== e1000_bus_width_pciex_4
) ? "Width x4" :
823 (hw
->bus_width
== e1000_bus_width_pciex_1
) ? "Width x1" :
827 for (i
= 0; i
< 6; i
++)
828 printk("%2.2x%c", netdev
->dev_addr
[i
], i
== 5 ? '\n' : ':');
830 /* reset the hardware with the new settings */
831 e1000_reset(adapter
);
833 /* If the controller is 82573 and f/w is AMT, do not set
834 * DRV_LOAD until the interface is up. For all other cases,
835 * let the f/w know that the h/w is now under the control
837 if (adapter
->hw
.mac_type
!= e1000_82573
||
838 !e1000_check_mng_mode(&adapter
->hw
))
839 e1000_get_hw_control(adapter
);
841 strcpy(netdev
->name
, "eth%d");
842 if((err
= register_netdev(netdev
)))
845 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
853 iounmap(adapter
->hw
.hw_addr
);
857 pci_release_regions(pdev
);
862 * e1000_remove - Device Removal Routine
863 * @pdev: PCI device information struct
865 * e1000_remove is called by the PCI subsystem to alert the driver
866 * that it should release a PCI device. The could be caused by a
867 * Hot-Plug event, or because the driver is going to be removed from
871 static void __devexit
872 e1000_remove(struct pci_dev
*pdev
)
874 struct net_device
*netdev
= pci_get_drvdata(pdev
);
875 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
877 #ifdef CONFIG_E1000_NAPI
881 flush_scheduled_work();
883 if(adapter
->hw
.mac_type
>= e1000_82540
&&
884 adapter
->hw
.media_type
== e1000_media_type_copper
) {
885 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
886 if(manc
& E1000_MANC_SMBUS_EN
) {
887 manc
|= E1000_MANC_ARP_EN
;
888 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
892 /* Release control of h/w to f/w. If f/w is AMT enabled, this
893 * would have already happened in close and is redundant. */
894 e1000_release_hw_control(adapter
);
896 unregister_netdev(netdev
);
897 #ifdef CONFIG_E1000_NAPI
898 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
899 __dev_put(&adapter
->polling_netdev
[i
]);
902 if(!e1000_check_phy_reset_block(&adapter
->hw
))
903 e1000_phy_hw_reset(&adapter
->hw
);
905 kfree(adapter
->tx_ring
);
906 kfree(adapter
->rx_ring
);
907 #ifdef CONFIG_E1000_NAPI
908 kfree(adapter
->polling_netdev
);
911 iounmap(adapter
->hw
.hw_addr
);
912 pci_release_regions(pdev
);
914 #ifdef CONFIG_E1000_MQ
915 free_percpu(adapter
->cpu_netdev
);
916 free_percpu(adapter
->cpu_tx_ring
);
920 pci_disable_device(pdev
);
924 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
925 * @adapter: board private structure to initialize
927 * e1000_sw_init initializes the Adapter private data structure.
928 * Fields are initialized based on PCI device information and
929 * OS network device settings (MTU size).
933 e1000_sw_init(struct e1000_adapter
*adapter
)
935 struct e1000_hw
*hw
= &adapter
->hw
;
936 struct net_device
*netdev
= adapter
->netdev
;
937 struct pci_dev
*pdev
= adapter
->pdev
;
938 #ifdef CONFIG_E1000_NAPI
942 /* PCI config space info */
944 hw
->vendor_id
= pdev
->vendor
;
945 hw
->device_id
= pdev
->device
;
946 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
947 hw
->subsystem_id
= pdev
->subsystem_device
;
949 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
951 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
953 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
954 adapter
->rx_ps_bsize0
= E1000_RXBUFFER_256
;
955 hw
->max_frame_size
= netdev
->mtu
+
956 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
957 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
959 /* identify the MAC */
961 if(e1000_set_mac_type(hw
)) {
962 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
966 /* initialize eeprom parameters */
968 if(e1000_init_eeprom_params(hw
)) {
969 E1000_ERR("EEPROM initialization failed\n");
973 switch(hw
->mac_type
) {
978 case e1000_82541_rev_2
:
979 case e1000_82547_rev_2
:
980 hw
->phy_init_script
= 1;
984 e1000_set_media_type(hw
);
986 hw
->wait_autoneg_complete
= FALSE
;
987 hw
->tbi_compatibility_en
= TRUE
;
988 hw
->adaptive_ifs
= TRUE
;
992 if(hw
->media_type
== e1000_media_type_copper
) {
993 hw
->mdix
= AUTO_ALL_MODES
;
994 hw
->disable_polarity_correction
= FALSE
;
995 hw
->master_slave
= E1000_MASTER_SLAVE
;
998 #ifdef CONFIG_E1000_MQ
999 /* Number of supported queues */
1000 switch (hw
->mac_type
) {
1003 /* These controllers support 2 tx queues, but with a single
1004 * qdisc implementation, multiple tx queues aren't quite as
1005 * interesting. If we can find a logical way of mapping
1006 * flows to a queue, then perhaps we can up the num_tx_queue
1007 * count back to its default. Until then, we run the risk of
1008 * terrible performance due to SACK overload. */
1009 adapter
->num_tx_queues
= 1;
1010 adapter
->num_rx_queues
= 2;
1013 adapter
->num_tx_queues
= 1;
1014 adapter
->num_rx_queues
= 1;
1017 adapter
->num_rx_queues
= min(adapter
->num_rx_queues
, num_online_cpus());
1018 adapter
->num_tx_queues
= min(adapter
->num_tx_queues
, num_online_cpus());
1019 DPRINTK(DRV
, INFO
, "Multiqueue Enabled: Rx Queue count = %u %s\n",
1020 adapter
->num_rx_queues
,
1021 ((adapter
->num_rx_queues
== 1)
1022 ? ((num_online_cpus() > 1)
1023 ? "(due to unsupported feature in current adapter)"
1024 : "(due to unsupported system configuration)")
1026 DPRINTK(DRV
, INFO
, "Multiqueue Enabled: Tx Queue count = %u\n",
1027 adapter
->num_tx_queues
);
1029 adapter
->num_tx_queues
= 1;
1030 adapter
->num_rx_queues
= 1;
1033 if (e1000_alloc_queues(adapter
)) {
1034 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
1038 #ifdef CONFIG_E1000_NAPI
1039 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1040 adapter
->polling_netdev
[i
].priv
= adapter
;
1041 adapter
->polling_netdev
[i
].poll
= &e1000_clean
;
1042 adapter
->polling_netdev
[i
].weight
= 64;
1043 dev_hold(&adapter
->polling_netdev
[i
]);
1044 set_bit(__LINK_STATE_START
, &adapter
->polling_netdev
[i
].state
);
1046 spin_lock_init(&adapter
->tx_queue_lock
);
1049 atomic_set(&adapter
->irq_sem
, 1);
1050 spin_lock_init(&adapter
->stats_lock
);
1056 * e1000_alloc_queues - Allocate memory for all rings
1057 * @adapter: board private structure to initialize
1059 * We allocate one ring per queue at run-time since we don't know the
1060 * number of queues at compile-time. The polling_netdev array is
1061 * intended for Multiqueue, but should work fine with a single queue.
1064 static int __devinit
1065 e1000_alloc_queues(struct e1000_adapter
*adapter
)
1069 size
= sizeof(struct e1000_tx_ring
) * adapter
->num_tx_queues
;
1070 adapter
->tx_ring
= kmalloc(size
, GFP_KERNEL
);
1071 if (!adapter
->tx_ring
)
1073 memset(adapter
->tx_ring
, 0, size
);
1075 size
= sizeof(struct e1000_rx_ring
) * adapter
->num_rx_queues
;
1076 adapter
->rx_ring
= kmalloc(size
, GFP_KERNEL
);
1077 if (!adapter
->rx_ring
) {
1078 kfree(adapter
->tx_ring
);
1081 memset(adapter
->rx_ring
, 0, size
);
1083 #ifdef CONFIG_E1000_NAPI
1084 size
= sizeof(struct net_device
) * adapter
->num_rx_queues
;
1085 adapter
->polling_netdev
= kmalloc(size
, GFP_KERNEL
);
1086 if (!adapter
->polling_netdev
) {
1087 kfree(adapter
->tx_ring
);
1088 kfree(adapter
->rx_ring
);
1091 memset(adapter
->polling_netdev
, 0, size
);
1094 #ifdef CONFIG_E1000_MQ
1095 adapter
->rx_sched_call_data
.func
= e1000_rx_schedule
;
1096 adapter
->rx_sched_call_data
.info
= adapter
->netdev
;
1098 adapter
->cpu_netdev
= alloc_percpu(struct net_device
*);
1099 adapter
->cpu_tx_ring
= alloc_percpu(struct e1000_tx_ring
*);
1102 return E1000_SUCCESS
;
1105 #ifdef CONFIG_E1000_MQ
1106 static void __devinit
1107 e1000_setup_queue_mapping(struct e1000_adapter
*adapter
)
1111 adapter
->rx_sched_call_data
.func
= e1000_rx_schedule
;
1112 adapter
->rx_sched_call_data
.info
= adapter
->netdev
;
1113 cpus_clear(adapter
->rx_sched_call_data
.cpumask
);
1115 adapter
->cpu_netdev
= alloc_percpu(struct net_device
*);
1116 adapter
->cpu_tx_ring
= alloc_percpu(struct e1000_tx_ring
*);
1120 for_each_online_cpu(cpu
) {
1121 *per_cpu_ptr(adapter
->cpu_tx_ring
, cpu
) = &adapter
->tx_ring
[i
% adapter
->num_tx_queues
];
1122 /* This is incomplete because we'd like to assign separate
1123 * physical cpus to these netdev polling structures and
1124 * avoid saturating a subset of cpus.
1126 if (i
< adapter
->num_rx_queues
) {
1127 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = &adapter
->polling_netdev
[i
];
1128 adapter
->rx_ring
[i
].cpu
= cpu
;
1129 cpu_set(cpu
, adapter
->cpumask
);
1131 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = NULL
;
1135 unlock_cpu_hotplug();
1140 * e1000_open - Called when a network interface is made active
1141 * @netdev: network interface device structure
1143 * Returns 0 on success, negative value on failure
1145 * The open entry point is called when a network interface is made
1146 * active by the system (IFF_UP). At this point all resources needed
1147 * for transmit and receive operations are allocated, the interrupt
1148 * handler is registered with the OS, the watchdog timer is started,
1149 * and the stack is notified that the interface is ready.
1153 e1000_open(struct net_device
*netdev
)
1155 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1158 /* allocate transmit descriptors */
1160 if ((err
= e1000_setup_all_tx_resources(adapter
)))
1163 /* allocate receive descriptors */
1165 if ((err
= e1000_setup_all_rx_resources(adapter
)))
1168 if((err
= e1000_up(adapter
)))
1170 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1171 if((adapter
->hw
.mng_cookie
.status
&
1172 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1173 e1000_update_mng_vlan(adapter
);
1176 /* If AMT is enabled, let the firmware know that the network
1177 * interface is now open */
1178 if (adapter
->hw
.mac_type
== e1000_82573
&&
1179 e1000_check_mng_mode(&adapter
->hw
))
1180 e1000_get_hw_control(adapter
);
1182 return E1000_SUCCESS
;
1185 e1000_free_all_rx_resources(adapter
);
1187 e1000_free_all_tx_resources(adapter
);
1189 e1000_reset(adapter
);
1195 * e1000_close - Disables a network interface
1196 * @netdev: network interface device structure
1198 * Returns 0, this is not allowed to fail
1200 * The close entry point is called when an interface is de-activated
1201 * by the OS. The hardware is still under the drivers control, but
1202 * needs to be disabled. A global MAC reset is issued to stop the
1203 * hardware, and all transmit and receive resources are freed.
1207 e1000_close(struct net_device
*netdev
)
1209 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1211 e1000_down(adapter
);
1213 e1000_free_all_tx_resources(adapter
);
1214 e1000_free_all_rx_resources(adapter
);
1216 if((adapter
->hw
.mng_cookie
.status
&
1217 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1218 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1221 /* If AMT is enabled, let the firmware know that the network
1222 * interface is now closed */
1223 if (adapter
->hw
.mac_type
== e1000_82573
&&
1224 e1000_check_mng_mode(&adapter
->hw
))
1225 e1000_release_hw_control(adapter
);
1231 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1232 * @adapter: address of board private structure
1233 * @start: address of beginning of memory
1234 * @len: length of memory
1236 static inline boolean_t
1237 e1000_check_64k_bound(struct e1000_adapter
*adapter
,
1238 void *start
, unsigned long len
)
1240 unsigned long begin
= (unsigned long) start
;
1241 unsigned long end
= begin
+ len
;
1243 /* First rev 82545 and 82546 need to not allow any memory
1244 * write location to cross 64k boundary due to errata 23 */
1245 if (adapter
->hw
.mac_type
== e1000_82545
||
1246 adapter
->hw
.mac_type
== e1000_82546
) {
1247 return ((begin
^ (end
- 1)) >> 16) != 0 ? FALSE
: TRUE
;
1254 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1255 * @adapter: board private structure
1256 * @txdr: tx descriptor ring (for a specific queue) to setup
1258 * Return 0 on success, negative on failure
1262 e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1263 struct e1000_tx_ring
*txdr
)
1265 struct pci_dev
*pdev
= adapter
->pdev
;
1268 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1270 txdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1271 if(!txdr
->buffer_info
) {
1273 "Unable to allocate memory for the transmit descriptor ring\n");
1276 memset(txdr
->buffer_info
, 0, size
);
1278 /* round up to nearest 4K */
1280 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1281 E1000_ROUNDUP(txdr
->size
, 4096);
1283 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1286 vfree(txdr
->buffer_info
);
1288 "Unable to allocate memory for the transmit descriptor ring\n");
1292 /* Fix for errata 23, can't cross 64kB boundary */
1293 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1294 void *olddesc
= txdr
->desc
;
1295 dma_addr_t olddma
= txdr
->dma
;
1296 DPRINTK(TX_ERR
, ERR
, "txdr align check failed: %u bytes "
1297 "at %p\n", txdr
->size
, txdr
->desc
);
1298 /* Try again, without freeing the previous */
1299 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1301 /* Failed allocation, critical failure */
1302 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1303 goto setup_tx_desc_die
;
1306 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1308 pci_free_consistent(pdev
, txdr
->size
, txdr
->desc
,
1310 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1312 "Unable to allocate aligned memory "
1313 "for the transmit descriptor ring\n");
1314 vfree(txdr
->buffer_info
);
1317 /* Free old allocation, new allocation was successful */
1318 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1321 memset(txdr
->desc
, 0, txdr
->size
);
1323 txdr
->next_to_use
= 0;
1324 txdr
->next_to_clean
= 0;
1325 spin_lock_init(&txdr
->tx_lock
);
1331 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1332 * (Descriptors) for all queues
1333 * @adapter: board private structure
1335 * If this function returns with an error, then it's possible one or
1336 * more of the rings is populated (while the rest are not). It is the
1337 * callers duty to clean those orphaned rings.
1339 * Return 0 on success, negative on failure
1343 e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1347 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1348 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1351 "Allocation for Tx Queue %u failed\n", i
);
1360 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1361 * @adapter: board private structure
1363 * Configure the Tx unit of the MAC after a reset.
1367 e1000_configure_tx(struct e1000_adapter
*adapter
)
1370 struct e1000_hw
*hw
= &adapter
->hw
;
1371 uint32_t tdlen
, tctl
, tipg
, tarc
;
1372 uint32_t ipgr1
, ipgr2
;
1374 /* Setup the HW Tx Head and Tail descriptor pointers */
1376 switch (adapter
->num_tx_queues
) {
1378 tdba
= adapter
->tx_ring
[1].dma
;
1379 tdlen
= adapter
->tx_ring
[1].count
*
1380 sizeof(struct e1000_tx_desc
);
1381 E1000_WRITE_REG(hw
, TDBAL1
, (tdba
& 0x00000000ffffffffULL
));
1382 E1000_WRITE_REG(hw
, TDBAH1
, (tdba
>> 32));
1383 E1000_WRITE_REG(hw
, TDLEN1
, tdlen
);
1384 E1000_WRITE_REG(hw
, TDH1
, 0);
1385 E1000_WRITE_REG(hw
, TDT1
, 0);
1386 adapter
->tx_ring
[1].tdh
= E1000_TDH1
;
1387 adapter
->tx_ring
[1].tdt
= E1000_TDT1
;
1391 tdba
= adapter
->tx_ring
[0].dma
;
1392 tdlen
= adapter
->tx_ring
[0].count
*
1393 sizeof(struct e1000_tx_desc
);
1394 E1000_WRITE_REG(hw
, TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1395 E1000_WRITE_REG(hw
, TDBAH
, (tdba
>> 32));
1396 E1000_WRITE_REG(hw
, TDLEN
, tdlen
);
1397 E1000_WRITE_REG(hw
, TDH
, 0);
1398 E1000_WRITE_REG(hw
, TDT
, 0);
1399 adapter
->tx_ring
[0].tdh
= E1000_TDH
;
1400 adapter
->tx_ring
[0].tdt
= E1000_TDT
;
1404 /* Set the default values for the Tx Inter Packet Gap timer */
1406 if (hw
->media_type
== e1000_media_type_fiber
||
1407 hw
->media_type
== e1000_media_type_internal_serdes
)
1408 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1410 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1412 switch (hw
->mac_type
) {
1413 case e1000_82542_rev2_0
:
1414 case e1000_82542_rev2_1
:
1415 tipg
= DEFAULT_82542_TIPG_IPGT
;
1416 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
1417 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
1420 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1421 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
1424 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1425 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1426 E1000_WRITE_REG(hw
, TIPG
, tipg
);
1428 /* Set the Tx Interrupt Delay register */
1430 E1000_WRITE_REG(hw
, TIDV
, adapter
->tx_int_delay
);
1431 if (hw
->mac_type
>= e1000_82540
)
1432 E1000_WRITE_REG(hw
, TADV
, adapter
->tx_abs_int_delay
);
1434 /* Program the Transmit Control Register */
1436 tctl
= E1000_READ_REG(hw
, TCTL
);
1438 tctl
&= ~E1000_TCTL_CT
;
1439 tctl
|= E1000_TCTL_EN
| E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1440 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1442 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1444 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
1445 tarc
= E1000_READ_REG(hw
, TARC0
);
1446 tarc
|= ((1 << 25) | (1 << 21));
1447 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1448 tarc
= E1000_READ_REG(hw
, TARC1
);
1450 if (tctl
& E1000_TCTL_MULR
)
1454 E1000_WRITE_REG(hw
, TARC1
, tarc
);
1457 e1000_config_collision_dist(hw
);
1459 /* Setup Transmit Descriptor Settings for eop descriptor */
1460 adapter
->txd_cmd
= E1000_TXD_CMD_IDE
| E1000_TXD_CMD_EOP
|
1463 if (hw
->mac_type
< e1000_82543
)
1464 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1466 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1468 /* Cache if we're 82544 running in PCI-X because we'll
1469 * need this to apply a workaround later in the send path. */
1470 if (hw
->mac_type
== e1000_82544
&&
1471 hw
->bus_type
== e1000_bus_type_pcix
)
1472 adapter
->pcix_82544
= 1;
1476 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1477 * @adapter: board private structure
1478 * @rxdr: rx descriptor ring (for a specific queue) to setup
1480 * Returns 0 on success, negative on failure
1484 e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1485 struct e1000_rx_ring
*rxdr
)
1487 struct pci_dev
*pdev
= adapter
->pdev
;
1490 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1491 rxdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1492 if (!rxdr
->buffer_info
) {
1494 "Unable to allocate memory for the receive descriptor ring\n");
1497 memset(rxdr
->buffer_info
, 0, size
);
1499 size
= sizeof(struct e1000_ps_page
) * rxdr
->count
;
1500 rxdr
->ps_page
= kmalloc(size
, GFP_KERNEL
);
1501 if(!rxdr
->ps_page
) {
1502 vfree(rxdr
->buffer_info
);
1504 "Unable to allocate memory for the receive descriptor ring\n");
1507 memset(rxdr
->ps_page
, 0, size
);
1509 size
= sizeof(struct e1000_ps_page_dma
) * rxdr
->count
;
1510 rxdr
->ps_page_dma
= kmalloc(size
, GFP_KERNEL
);
1511 if(!rxdr
->ps_page_dma
) {
1512 vfree(rxdr
->buffer_info
);
1513 kfree(rxdr
->ps_page
);
1515 "Unable to allocate memory for the receive descriptor ring\n");
1518 memset(rxdr
->ps_page_dma
, 0, size
);
1520 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
)
1521 desc_len
= sizeof(struct e1000_rx_desc
);
1523 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1525 /* Round up to nearest 4K */
1527 rxdr
->size
= rxdr
->count
* desc_len
;
1528 E1000_ROUNDUP(rxdr
->size
, 4096);
1530 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1534 "Unable to allocate memory for the receive descriptor ring\n");
1536 vfree(rxdr
->buffer_info
);
1537 kfree(rxdr
->ps_page
);
1538 kfree(rxdr
->ps_page_dma
);
1542 /* Fix for errata 23, can't cross 64kB boundary */
1543 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1544 void *olddesc
= rxdr
->desc
;
1545 dma_addr_t olddma
= rxdr
->dma
;
1546 DPRINTK(RX_ERR
, ERR
, "rxdr align check failed: %u bytes "
1547 "at %p\n", rxdr
->size
, rxdr
->desc
);
1548 /* Try again, without freeing the previous */
1549 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1550 /* Failed allocation, critical failure */
1552 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1554 "Unable to allocate memory "
1555 "for the receive descriptor ring\n");
1556 goto setup_rx_desc_die
;
1559 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1561 pci_free_consistent(pdev
, rxdr
->size
, rxdr
->desc
,
1563 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1565 "Unable to allocate aligned memory "
1566 "for the receive descriptor ring\n");
1567 goto setup_rx_desc_die
;
1569 /* Free old allocation, new allocation was successful */
1570 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1573 memset(rxdr
->desc
, 0, rxdr
->size
);
1575 rxdr
->next_to_clean
= 0;
1576 rxdr
->next_to_use
= 0;
1577 rxdr
->rx_skb_top
= NULL
;
1578 rxdr
->rx_skb_prev
= NULL
;
1584 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1585 * (Descriptors) for all queues
1586 * @adapter: board private structure
1588 * If this function returns with an error, then it's possible one or
1589 * more of the rings is populated (while the rest are not). It is the
1590 * callers duty to clean those orphaned rings.
1592 * Return 0 on success, negative on failure
1596 e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1600 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1601 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1604 "Allocation for Rx Queue %u failed\n", i
);
1613 * e1000_setup_rctl - configure the receive control registers
1614 * @adapter: Board private structure
1616 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1617 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1619 e1000_setup_rctl(struct e1000_adapter
*adapter
)
1621 uint32_t rctl
, rfctl
;
1622 uint32_t psrctl
= 0;
1623 #ifdef CONFIG_E1000_PACKET_SPLIT
1627 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1629 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1631 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1632 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1633 (adapter
->hw
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1635 if (adapter
->hw
.mac_type
> e1000_82543
)
1636 rctl
|= E1000_RCTL_SECRC
;
1638 if (adapter
->hw
.tbi_compatibility_on
== 1)
1639 rctl
|= E1000_RCTL_SBP
;
1641 rctl
&= ~E1000_RCTL_SBP
;
1643 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1644 rctl
&= ~E1000_RCTL_LPE
;
1646 rctl
|= E1000_RCTL_LPE
;
1648 /* Setup buffer sizes */
1649 if(adapter
->hw
.mac_type
>= e1000_82571
) {
1650 /* We can now specify buffers in 1K increments.
1651 * BSIZE and BSEX are ignored in this case. */
1652 rctl
|= adapter
->rx_buffer_len
<< 0x11;
1654 rctl
&= ~E1000_RCTL_SZ_4096
;
1655 rctl
|= E1000_RCTL_BSEX
;
1656 switch (adapter
->rx_buffer_len
) {
1657 case E1000_RXBUFFER_2048
:
1659 rctl
|= E1000_RCTL_SZ_2048
;
1660 rctl
&= ~E1000_RCTL_BSEX
;
1662 case E1000_RXBUFFER_4096
:
1663 rctl
|= E1000_RCTL_SZ_4096
;
1665 case E1000_RXBUFFER_8192
:
1666 rctl
|= E1000_RCTL_SZ_8192
;
1668 case E1000_RXBUFFER_16384
:
1669 rctl
|= E1000_RCTL_SZ_16384
;
1674 #ifdef CONFIG_E1000_PACKET_SPLIT
1675 /* 82571 and greater support packet-split where the protocol
1676 * header is placed in skb->data and the packet data is
1677 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1678 * In the case of a non-split, skb->data is linearly filled,
1679 * followed by the page buffers. Therefore, skb->data is
1680 * sized to hold the largest protocol header.
1682 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
1683 if ((adapter
->hw
.mac_type
> e1000_82547_rev_2
) && (pages
<= 3) &&
1685 adapter
->rx_ps_pages
= pages
;
1687 adapter
->rx_ps_pages
= 0;
1689 if (adapter
->rx_ps_pages
) {
1690 /* Configure extra packet-split registers */
1691 rfctl
= E1000_READ_REG(&adapter
->hw
, RFCTL
);
1692 rfctl
|= E1000_RFCTL_EXTEN
;
1693 /* disable IPv6 packet split support */
1694 rfctl
|= E1000_RFCTL_IPV6_DIS
;
1695 E1000_WRITE_REG(&adapter
->hw
, RFCTL
, rfctl
);
1697 rctl
|= E1000_RCTL_DTYP_PS
| E1000_RCTL_SECRC
;
1699 psrctl
|= adapter
->rx_ps_bsize0
>>
1700 E1000_PSRCTL_BSIZE0_SHIFT
;
1702 switch (adapter
->rx_ps_pages
) {
1704 psrctl
|= PAGE_SIZE
<<
1705 E1000_PSRCTL_BSIZE3_SHIFT
;
1707 psrctl
|= PAGE_SIZE
<<
1708 E1000_PSRCTL_BSIZE2_SHIFT
;
1710 psrctl
|= PAGE_SIZE
>>
1711 E1000_PSRCTL_BSIZE1_SHIFT
;
1715 E1000_WRITE_REG(&adapter
->hw
, PSRCTL
, psrctl
);
1718 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1722 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1723 * @adapter: board private structure
1725 * Configure the Rx unit of the MAC after a reset.
1729 e1000_configure_rx(struct e1000_adapter
*adapter
)
1732 struct e1000_hw
*hw
= &adapter
->hw
;
1733 uint32_t rdlen
, rctl
, rxcsum
, ctrl_ext
;
1734 #ifdef CONFIG_E1000_MQ
1735 uint32_t reta
, mrqc
;
1739 if (adapter
->rx_ps_pages
) {
1740 rdlen
= adapter
->rx_ring
[0].count
*
1741 sizeof(union e1000_rx_desc_packet_split
);
1742 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
1743 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
1745 rdlen
= adapter
->rx_ring
[0].count
*
1746 sizeof(struct e1000_rx_desc
);
1747 adapter
->clean_rx
= e1000_clean_rx_irq
;
1748 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1751 /* disable receives while setting up the descriptors */
1752 rctl
= E1000_READ_REG(hw
, RCTL
);
1753 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
1755 /* set the Receive Delay Timer Register */
1756 E1000_WRITE_REG(hw
, RDTR
, adapter
->rx_int_delay
);
1758 if (hw
->mac_type
>= e1000_82540
) {
1759 E1000_WRITE_REG(hw
, RADV
, adapter
->rx_abs_int_delay
);
1760 if(adapter
->itr
> 1)
1761 E1000_WRITE_REG(hw
, ITR
,
1762 1000000000 / (adapter
->itr
* 256));
1765 if (hw
->mac_type
>= e1000_82571
) {
1766 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1767 /* Reset delay timers after every interrupt */
1768 ctrl_ext
|= E1000_CTRL_EXT_CANC
;
1769 #ifdef CONFIG_E1000_NAPI
1770 /* Auto-Mask interrupts upon ICR read. */
1771 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
1773 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
1774 E1000_WRITE_REG(hw
, IAM
, ~0);
1775 E1000_WRITE_FLUSH(hw
);
1778 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1779 * the Base and Length of the Rx Descriptor Ring */
1780 switch (adapter
->num_rx_queues
) {
1781 #ifdef CONFIG_E1000_MQ
1783 rdba
= adapter
->rx_ring
[1].dma
;
1784 E1000_WRITE_REG(hw
, RDBAL1
, (rdba
& 0x00000000ffffffffULL
));
1785 E1000_WRITE_REG(hw
, RDBAH1
, (rdba
>> 32));
1786 E1000_WRITE_REG(hw
, RDLEN1
, rdlen
);
1787 E1000_WRITE_REG(hw
, RDH1
, 0);
1788 E1000_WRITE_REG(hw
, RDT1
, 0);
1789 adapter
->rx_ring
[1].rdh
= E1000_RDH1
;
1790 adapter
->rx_ring
[1].rdt
= E1000_RDT1
;
1795 rdba
= adapter
->rx_ring
[0].dma
;
1796 E1000_WRITE_REG(hw
, RDBAL
, (rdba
& 0x00000000ffffffffULL
));
1797 E1000_WRITE_REG(hw
, RDBAH
, (rdba
>> 32));
1798 E1000_WRITE_REG(hw
, RDLEN
, rdlen
);
1799 E1000_WRITE_REG(hw
, RDH
, 0);
1800 E1000_WRITE_REG(hw
, RDT
, 0);
1801 adapter
->rx_ring
[0].rdh
= E1000_RDH
;
1802 adapter
->rx_ring
[0].rdt
= E1000_RDT
;
1806 #ifdef CONFIG_E1000_MQ
1807 if (adapter
->num_rx_queues
> 1) {
1808 uint32_t random
[10];
1810 get_random_bytes(&random
[0], 40);
1812 if (hw
->mac_type
<= e1000_82572
) {
1813 E1000_WRITE_REG(hw
, RSSIR
, 0);
1814 E1000_WRITE_REG(hw
, RSSIM
, 0);
1817 switch (adapter
->num_rx_queues
) {
1821 mrqc
= E1000_MRQC_ENABLE_RSS_2Q
;
1825 /* Fill out redirection table */
1826 for (i
= 0; i
< 32; i
++)
1827 E1000_WRITE_REG_ARRAY(hw
, RETA
, i
, reta
);
1828 /* Fill out hash function seeds */
1829 for (i
= 0; i
< 10; i
++)
1830 E1000_WRITE_REG_ARRAY(hw
, RSSRK
, i
, random
[i
]);
1832 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4
|
1833 E1000_MRQC_RSS_FIELD_IPV4_TCP
);
1834 E1000_WRITE_REG(hw
, MRQC
, mrqc
);
1837 /* Multiqueue and packet checksumming are mutually exclusive. */
1838 if (hw
->mac_type
>= e1000_82571
) {
1839 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1840 rxcsum
|= E1000_RXCSUM_PCSD
;
1841 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1846 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1847 if (hw
->mac_type
>= e1000_82543
) {
1848 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1849 if(adapter
->rx_csum
== TRUE
) {
1850 rxcsum
|= E1000_RXCSUM_TUOFL
;
1852 /* Enable 82571 IPv4 payload checksum for UDP fragments
1853 * Must be used in conjunction with packet-split. */
1854 if ((hw
->mac_type
>= e1000_82571
) &&
1855 (adapter
->rx_ps_pages
)) {
1856 rxcsum
|= E1000_RXCSUM_IPPCSE
;
1859 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1860 /* don't need to clear IPPCSE as it defaults to 0 */
1862 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1864 #endif /* CONFIG_E1000_MQ */
1866 if (hw
->mac_type
== e1000_82573
)
1867 E1000_WRITE_REG(hw
, ERT
, 0x0100);
1869 /* Enable Receives */
1870 E1000_WRITE_REG(hw
, RCTL
, rctl
);
1874 * e1000_free_tx_resources - Free Tx Resources per Queue
1875 * @adapter: board private structure
1876 * @tx_ring: Tx descriptor ring for a specific queue
1878 * Free all transmit software resources
1882 e1000_free_tx_resources(struct e1000_adapter
*adapter
,
1883 struct e1000_tx_ring
*tx_ring
)
1885 struct pci_dev
*pdev
= adapter
->pdev
;
1887 e1000_clean_tx_ring(adapter
, tx_ring
);
1889 vfree(tx_ring
->buffer_info
);
1890 tx_ring
->buffer_info
= NULL
;
1892 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
1894 tx_ring
->desc
= NULL
;
1898 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1899 * @adapter: board private structure
1901 * Free all transmit software resources
1905 e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
1909 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1910 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1914 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
1915 struct e1000_buffer
*buffer_info
)
1917 if(buffer_info
->dma
) {
1918 pci_unmap_page(adapter
->pdev
,
1920 buffer_info
->length
,
1922 buffer_info
->dma
= 0;
1924 if(buffer_info
->skb
) {
1925 dev_kfree_skb_any(buffer_info
->skb
);
1926 buffer_info
->skb
= NULL
;
1931 * e1000_clean_tx_ring - Free Tx Buffers
1932 * @adapter: board private structure
1933 * @tx_ring: ring to be cleaned
1937 e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
1938 struct e1000_tx_ring
*tx_ring
)
1940 struct e1000_buffer
*buffer_info
;
1944 /* Free all the Tx ring sk_buffs */
1946 for(i
= 0; i
< tx_ring
->count
; i
++) {
1947 buffer_info
= &tx_ring
->buffer_info
[i
];
1948 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
1951 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1952 memset(tx_ring
->buffer_info
, 0, size
);
1954 /* Zero out the descriptor ring */
1956 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1958 tx_ring
->next_to_use
= 0;
1959 tx_ring
->next_to_clean
= 0;
1960 tx_ring
->last_tx_tso
= 0;
1962 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdh
);
1963 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
1967 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1968 * @adapter: board private structure
1972 e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
1976 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1977 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1981 * e1000_free_rx_resources - Free Rx Resources
1982 * @adapter: board private structure
1983 * @rx_ring: ring to clean the resources from
1985 * Free all receive software resources
1989 e1000_free_rx_resources(struct e1000_adapter
*adapter
,
1990 struct e1000_rx_ring
*rx_ring
)
1992 struct pci_dev
*pdev
= adapter
->pdev
;
1994 e1000_clean_rx_ring(adapter
, rx_ring
);
1996 vfree(rx_ring
->buffer_info
);
1997 rx_ring
->buffer_info
= NULL
;
1998 kfree(rx_ring
->ps_page
);
1999 rx_ring
->ps_page
= NULL
;
2000 kfree(rx_ring
->ps_page_dma
);
2001 rx_ring
->ps_page_dma
= NULL
;
2003 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
2005 rx_ring
->desc
= NULL
;
2009 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2010 * @adapter: board private structure
2012 * Free all receive software resources
2016 e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
2020 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2021 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2025 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2026 * @adapter: board private structure
2027 * @rx_ring: ring to free buffers from
2031 e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
2032 struct e1000_rx_ring
*rx_ring
)
2034 struct e1000_buffer
*buffer_info
;
2035 struct e1000_ps_page
*ps_page
;
2036 struct e1000_ps_page_dma
*ps_page_dma
;
2037 struct pci_dev
*pdev
= adapter
->pdev
;
2041 /* Free all the Rx ring sk_buffs */
2043 for(i
= 0; i
< rx_ring
->count
; i
++) {
2044 buffer_info
= &rx_ring
->buffer_info
[i
];
2045 if(buffer_info
->skb
) {
2046 ps_page
= &rx_ring
->ps_page
[i
];
2047 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2048 pci_unmap_single(pdev
,
2050 buffer_info
->length
,
2051 PCI_DMA_FROMDEVICE
);
2053 dev_kfree_skb(buffer_info
->skb
);
2054 buffer_info
->skb
= NULL
;
2056 ps_page
= &rx_ring
->ps_page
[i
];
2057 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2058 for (j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
2059 if (!ps_page
->ps_page
[j
]) break;
2060 pci_unmap_page(pdev
,
2061 ps_page_dma
->ps_page_dma
[j
],
2062 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
2063 ps_page_dma
->ps_page_dma
[j
] = 0;
2064 put_page(ps_page
->ps_page
[j
]);
2065 ps_page
->ps_page
[j
] = NULL
;
2069 /* there also may be some cached data in our adapter */
2070 if (rx_ring
->rx_skb_top
) {
2071 dev_kfree_skb(rx_ring
->rx_skb_top
);
2073 /* rx_skb_prev will be wiped out by rx_skb_top */
2074 rx_ring
->rx_skb_top
= NULL
;
2075 rx_ring
->rx_skb_prev
= NULL
;
2079 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2080 memset(rx_ring
->buffer_info
, 0, size
);
2081 size
= sizeof(struct e1000_ps_page
) * rx_ring
->count
;
2082 memset(rx_ring
->ps_page
, 0, size
);
2083 size
= sizeof(struct e1000_ps_page_dma
) * rx_ring
->count
;
2084 memset(rx_ring
->ps_page_dma
, 0, size
);
2086 /* Zero out the descriptor ring */
2088 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2090 rx_ring
->next_to_clean
= 0;
2091 rx_ring
->next_to_use
= 0;
2093 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdh
);
2094 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
2098 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2099 * @adapter: board private structure
2103 e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2107 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2108 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2111 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2112 * and memory write and invalidate disabled for certain operations
2115 e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2117 struct net_device
*netdev
= adapter
->netdev
;
2120 e1000_pci_clear_mwi(&adapter
->hw
);
2122 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2123 rctl
|= E1000_RCTL_RST
;
2124 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2125 E1000_WRITE_FLUSH(&adapter
->hw
);
2128 if(netif_running(netdev
))
2129 e1000_clean_all_rx_rings(adapter
);
2133 e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2135 struct net_device
*netdev
= adapter
->netdev
;
2138 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2139 rctl
&= ~E1000_RCTL_RST
;
2140 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2141 E1000_WRITE_FLUSH(&adapter
->hw
);
2144 if(adapter
->hw
.pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2145 e1000_pci_set_mwi(&adapter
->hw
);
2147 if(netif_running(netdev
)) {
2148 e1000_configure_rx(adapter
);
2149 /* No need to loop, because 82542 supports only 1 queue */
2150 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[0];
2151 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
2156 * e1000_set_mac - Change the Ethernet Address of the NIC
2157 * @netdev: network interface device structure
2158 * @p: pointer to an address structure
2160 * Returns 0 on success, negative on failure
2164 e1000_set_mac(struct net_device
*netdev
, void *p
)
2166 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2167 struct sockaddr
*addr
= p
;
2169 if(!is_valid_ether_addr(addr
->sa_data
))
2170 return -EADDRNOTAVAIL
;
2172 /* 82542 2.0 needs to be in reset to write receive address registers */
2174 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2175 e1000_enter_82542_rst(adapter
);
2177 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2178 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2180 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2182 /* With 82571 controllers, LAA may be overwritten (with the default)
2183 * due to controller reset from the other port. */
2184 if (adapter
->hw
.mac_type
== e1000_82571
) {
2185 /* activate the work around */
2186 adapter
->hw
.laa_is_present
= 1;
2188 /* Hold a copy of the LAA in RAR[14] This is done so that
2189 * between the time RAR[0] gets clobbered and the time it
2190 * gets fixed (in e1000_watchdog), the actual LAA is in one
2191 * of the RARs and no incoming packets directed to this port
2192 * are dropped. Eventaully the LAA will be in RAR[0] and
2194 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
,
2195 E1000_RAR_ENTRIES
- 1);
2198 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2199 e1000_leave_82542_rst(adapter
);
2205 * e1000_set_multi - Multicast and Promiscuous mode set
2206 * @netdev: network interface device structure
2208 * The set_multi entry point is called whenever the multicast address
2209 * list or the network interface flags are updated. This routine is
2210 * responsible for configuring the hardware for proper multicast,
2211 * promiscuous mode, and all-multi behavior.
2215 e1000_set_multi(struct net_device
*netdev
)
2217 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2218 struct e1000_hw
*hw
= &adapter
->hw
;
2219 struct dev_mc_list
*mc_ptr
;
2221 uint32_t hash_value
;
2222 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2224 /* reserve RAR[14] for LAA over-write work-around */
2225 if (adapter
->hw
.mac_type
== e1000_82571
)
2228 /* Check for Promiscuous and All Multicast modes */
2230 rctl
= E1000_READ_REG(hw
, RCTL
);
2232 if(netdev
->flags
& IFF_PROMISC
) {
2233 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2234 } else if(netdev
->flags
& IFF_ALLMULTI
) {
2235 rctl
|= E1000_RCTL_MPE
;
2236 rctl
&= ~E1000_RCTL_UPE
;
2238 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2241 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2243 /* 82542 2.0 needs to be in reset to write receive address registers */
2245 if(hw
->mac_type
== e1000_82542_rev2_0
)
2246 e1000_enter_82542_rst(adapter
);
2248 /* load the first 14 multicast address into the exact filters 1-14
2249 * RAR 0 is used for the station MAC adddress
2250 * if there are not 14 addresses, go ahead and clear the filters
2251 * -- with 82571 controllers only 0-13 entries are filled here
2253 mc_ptr
= netdev
->mc_list
;
2255 for(i
= 1; i
< rar_entries
; i
++) {
2257 e1000_rar_set(hw
, mc_ptr
->dmi_addr
, i
);
2258 mc_ptr
= mc_ptr
->next
;
2260 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2261 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2265 /* clear the old settings from the multicast hash table */
2267 for(i
= 0; i
< E1000_NUM_MTA_REGISTERS
; i
++)
2268 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
2270 /* load any remaining addresses into the hash table */
2272 for(; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
2273 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->dmi_addr
);
2274 e1000_mta_set(hw
, hash_value
);
2277 if(hw
->mac_type
== e1000_82542_rev2_0
)
2278 e1000_leave_82542_rst(adapter
);
2281 /* Need to wait a few seconds after link up to get diagnostic information from
2285 e1000_update_phy_info(unsigned long data
)
2287 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2288 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
2292 * e1000_82547_tx_fifo_stall - Timer Call-back
2293 * @data: pointer to adapter cast into an unsigned long
2297 e1000_82547_tx_fifo_stall(unsigned long data
)
2299 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2300 struct net_device
*netdev
= adapter
->netdev
;
2303 if(atomic_read(&adapter
->tx_fifo_stall
)) {
2304 if((E1000_READ_REG(&adapter
->hw
, TDT
) ==
2305 E1000_READ_REG(&adapter
->hw
, TDH
)) &&
2306 (E1000_READ_REG(&adapter
->hw
, TDFT
) ==
2307 E1000_READ_REG(&adapter
->hw
, TDFH
)) &&
2308 (E1000_READ_REG(&adapter
->hw
, TDFTS
) ==
2309 E1000_READ_REG(&adapter
->hw
, TDFHS
))) {
2310 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2311 E1000_WRITE_REG(&adapter
->hw
, TCTL
,
2312 tctl
& ~E1000_TCTL_EN
);
2313 E1000_WRITE_REG(&adapter
->hw
, TDFT
,
2314 adapter
->tx_head_addr
);
2315 E1000_WRITE_REG(&adapter
->hw
, TDFH
,
2316 adapter
->tx_head_addr
);
2317 E1000_WRITE_REG(&adapter
->hw
, TDFTS
,
2318 adapter
->tx_head_addr
);
2319 E1000_WRITE_REG(&adapter
->hw
, TDFHS
,
2320 adapter
->tx_head_addr
);
2321 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2322 E1000_WRITE_FLUSH(&adapter
->hw
);
2324 adapter
->tx_fifo_head
= 0;
2325 atomic_set(&adapter
->tx_fifo_stall
, 0);
2326 netif_wake_queue(netdev
);
2328 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2334 * e1000_watchdog - Timer Call-back
2335 * @data: pointer to adapter cast into an unsigned long
2338 e1000_watchdog(unsigned long data
)
2340 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2342 /* Do the rest outside of interrupt context */
2343 schedule_work(&adapter
->watchdog_task
);
2347 e1000_watchdog_task(struct e1000_adapter
*adapter
)
2349 struct net_device
*netdev
= adapter
->netdev
;
2350 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2353 e1000_check_for_link(&adapter
->hw
);
2354 if (adapter
->hw
.mac_type
== e1000_82573
) {
2355 e1000_enable_tx_pkt_filtering(&adapter
->hw
);
2356 if(adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
)
2357 e1000_update_mng_vlan(adapter
);
2360 if((adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) &&
2361 !(E1000_READ_REG(&adapter
->hw
, TXCW
) & E1000_TXCW_ANE
))
2362 link
= !adapter
->hw
.serdes_link_down
;
2364 link
= E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_LU
;
2367 if(!netif_carrier_ok(netdev
)) {
2368 e1000_get_speed_and_duplex(&adapter
->hw
,
2369 &adapter
->link_speed
,
2370 &adapter
->link_duplex
);
2372 DPRINTK(LINK
, INFO
, "NIC Link is Up %d Mbps %s\n",
2373 adapter
->link_speed
,
2374 adapter
->link_duplex
== FULL_DUPLEX
?
2375 "Full Duplex" : "Half Duplex");
2377 /* tweak tx_queue_len according to speed/duplex */
2378 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2379 adapter
->tx_timeout_factor
= 1;
2380 if (adapter
->link_duplex
== HALF_DUPLEX
) {
2381 switch (adapter
->link_speed
) {
2383 netdev
->tx_queue_len
= 10;
2384 adapter
->tx_timeout_factor
= 8;
2387 netdev
->tx_queue_len
= 100;
2392 netif_carrier_on(netdev
);
2393 netif_wake_queue(netdev
);
2394 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2395 adapter
->smartspeed
= 0;
2398 if(netif_carrier_ok(netdev
)) {
2399 adapter
->link_speed
= 0;
2400 adapter
->link_duplex
= 0;
2401 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
2402 netif_carrier_off(netdev
);
2403 netif_stop_queue(netdev
);
2404 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2407 e1000_smartspeed(adapter
);
2410 e1000_update_stats(adapter
);
2412 adapter
->hw
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2413 adapter
->tpt_old
= adapter
->stats
.tpt
;
2414 adapter
->hw
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2415 adapter
->colc_old
= adapter
->stats
.colc
;
2417 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2418 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2419 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2420 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2422 e1000_update_adaptive(&adapter
->hw
);
2424 #ifdef CONFIG_E1000_MQ
2425 txdr
= *per_cpu_ptr(adapter
->cpu_tx_ring
, smp_processor_id());
2427 if (!netif_carrier_ok(netdev
)) {
2428 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2429 /* We've lost link, so the controller stops DMA,
2430 * but we've got queued Tx work that's never going
2431 * to get done, so reset controller to flush Tx.
2432 * (Do the reset outside of interrupt context). */
2433 schedule_work(&adapter
->tx_timeout_task
);
2437 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2438 if(adapter
->hw
.mac_type
>= e1000_82540
&& adapter
->itr
== 1) {
2439 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2440 * asymmetrical Tx or Rx gets ITR=8000; everyone
2441 * else is between 2000-8000. */
2442 uint32_t goc
= (adapter
->gotcl
+ adapter
->gorcl
) / 10000;
2443 uint32_t dif
= (adapter
->gotcl
> adapter
->gorcl
?
2444 adapter
->gotcl
- adapter
->gorcl
:
2445 adapter
->gorcl
- adapter
->gotcl
) / 10000;
2446 uint32_t itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
2447 E1000_WRITE_REG(&adapter
->hw
, ITR
, 1000000000 / (itr
* 256));
2450 /* Cause software interrupt to ensure rx ring is cleaned */
2451 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_RXDMT0
);
2453 /* Force detection of hung controller every watchdog period */
2454 adapter
->detect_tx_hung
= TRUE
;
2456 /* With 82571 controllers, LAA may be overwritten due to controller
2457 * reset from the other port. Set the appropriate LAA in RAR[0] */
2458 if (adapter
->hw
.mac_type
== e1000_82571
&& adapter
->hw
.laa_is_present
)
2459 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2461 /* Reset the timer */
2462 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2 * HZ
);
2465 #define E1000_TX_FLAGS_CSUM 0x00000001
2466 #define E1000_TX_FLAGS_VLAN 0x00000002
2467 #define E1000_TX_FLAGS_TSO 0x00000004
2468 #define E1000_TX_FLAGS_IPV4 0x00000008
2469 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2470 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2473 e1000_tso(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2474 struct sk_buff
*skb
)
2477 struct e1000_context_desc
*context_desc
;
2478 struct e1000_buffer
*buffer_info
;
2480 uint32_t cmd_length
= 0;
2481 uint16_t ipcse
= 0, tucse
, mss
;
2482 uint8_t ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2485 if(skb_shinfo(skb
)->tso_size
) {
2486 if (skb_header_cloned(skb
)) {
2487 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2492 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2493 mss
= skb_shinfo(skb
)->tso_size
;
2494 if(skb
->protocol
== ntohs(ETH_P_IP
)) {
2495 skb
->nh
.iph
->tot_len
= 0;
2496 skb
->nh
.iph
->check
= 0;
2498 ~csum_tcpudp_magic(skb
->nh
.iph
->saddr
,
2503 cmd_length
= E1000_TXD_CMD_IP
;
2504 ipcse
= skb
->h
.raw
- skb
->data
- 1;
2505 #ifdef NETIF_F_TSO_IPV6
2506 } else if(skb
->protocol
== ntohs(ETH_P_IPV6
)) {
2507 skb
->nh
.ipv6h
->payload_len
= 0;
2509 ~csum_ipv6_magic(&skb
->nh
.ipv6h
->saddr
,
2510 &skb
->nh
.ipv6h
->daddr
,
2517 ipcss
= skb
->nh
.raw
- skb
->data
;
2518 ipcso
= (void *)&(skb
->nh
.iph
->check
) - (void *)skb
->data
;
2519 tucss
= skb
->h
.raw
- skb
->data
;
2520 tucso
= (void *)&(skb
->h
.th
->check
) - (void *)skb
->data
;
2523 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2524 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2526 i
= tx_ring
->next_to_use
;
2527 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2528 buffer_info
= &tx_ring
->buffer_info
[i
];
2530 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2531 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2532 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2533 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2534 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2535 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2536 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2537 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2538 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2540 buffer_info
->time_stamp
= jiffies
;
2542 if (++i
== tx_ring
->count
) i
= 0;
2543 tx_ring
->next_to_use
= i
;
2552 static inline boolean_t
2553 e1000_tx_csum(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2554 struct sk_buff
*skb
)
2556 struct e1000_context_desc
*context_desc
;
2557 struct e1000_buffer
*buffer_info
;
2561 if(likely(skb
->ip_summed
== CHECKSUM_HW
)) {
2562 css
= skb
->h
.raw
- skb
->data
;
2564 i
= tx_ring
->next_to_use
;
2565 buffer_info
= &tx_ring
->buffer_info
[i
];
2566 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2568 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2569 context_desc
->upper_setup
.tcp_fields
.tucso
= css
+ skb
->csum
;
2570 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2571 context_desc
->tcp_seg_setup
.data
= 0;
2572 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
2574 buffer_info
->time_stamp
= jiffies
;
2576 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2577 tx_ring
->next_to_use
= i
;
2585 #define E1000_MAX_TXD_PWR 12
2586 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2589 e1000_tx_map(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2590 struct sk_buff
*skb
, unsigned int first
, unsigned int max_per_txd
,
2591 unsigned int nr_frags
, unsigned int mss
)
2593 struct e1000_buffer
*buffer_info
;
2594 unsigned int len
= skb
->len
;
2595 unsigned int offset
= 0, size
, count
= 0, i
;
2597 len
-= skb
->data_len
;
2599 i
= tx_ring
->next_to_use
;
2602 buffer_info
= &tx_ring
->buffer_info
[i
];
2603 size
= min(len
, max_per_txd
);
2605 /* Workaround for Controller erratum --
2606 * descriptor for non-tso packet in a linear SKB that follows a
2607 * tso gets written back prematurely before the data is fully
2608 * DMAd to the controller */
2609 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2610 !skb_shinfo(skb
)->tso_size
) {
2611 tx_ring
->last_tx_tso
= 0;
2615 /* Workaround for premature desc write-backs
2616 * in TSO mode. Append 4-byte sentinel desc */
2617 if(unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
2620 /* work-around for errata 10 and it applies
2621 * to all controllers in PCI-X mode
2622 * The fix is to make sure that the first descriptor of a
2623 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2625 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2626 (size
> 2015) && count
== 0))
2629 /* Workaround for potential 82544 hang in PCI-X. Avoid
2630 * terminating buffers within evenly-aligned dwords. */
2631 if(unlikely(adapter
->pcix_82544
&&
2632 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
2636 buffer_info
->length
= size
;
2638 pci_map_single(adapter
->pdev
,
2642 buffer_info
->time_stamp
= jiffies
;
2647 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2650 for(f
= 0; f
< nr_frags
; f
++) {
2651 struct skb_frag_struct
*frag
;
2653 frag
= &skb_shinfo(skb
)->frags
[f
];
2655 offset
= frag
->page_offset
;
2658 buffer_info
= &tx_ring
->buffer_info
[i
];
2659 size
= min(len
, max_per_txd
);
2661 /* Workaround for premature desc write-backs
2662 * in TSO mode. Append 4-byte sentinel desc */
2663 if(unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
2666 /* Workaround for potential 82544 hang in PCI-X.
2667 * Avoid terminating buffers within evenly-aligned
2669 if(unlikely(adapter
->pcix_82544
&&
2670 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
2674 buffer_info
->length
= size
;
2676 pci_map_page(adapter
->pdev
,
2681 buffer_info
->time_stamp
= jiffies
;
2686 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2690 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
2691 tx_ring
->buffer_info
[i
].skb
= skb
;
2692 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
2698 e1000_tx_queue(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2699 int tx_flags
, int count
)
2701 struct e1000_tx_desc
*tx_desc
= NULL
;
2702 struct e1000_buffer
*buffer_info
;
2703 uint32_t txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
2706 if(likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
2707 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
2709 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2711 if(likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
2712 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
2715 if(likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
2716 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
2717 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2720 if(unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
2721 txd_lower
|= E1000_TXD_CMD_VLE
;
2722 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
2725 i
= tx_ring
->next_to_use
;
2728 buffer_info
= &tx_ring
->buffer_info
[i
];
2729 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
2730 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2731 tx_desc
->lower
.data
=
2732 cpu_to_le32(txd_lower
| buffer_info
->length
);
2733 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
2734 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2737 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
2739 /* Force memory writes to complete before letting h/w
2740 * know there are new descriptors to fetch. (Only
2741 * applicable for weak-ordered memory model archs,
2742 * such as IA-64). */
2745 tx_ring
->next_to_use
= i
;
2746 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
2750 * 82547 workaround to avoid controller hang in half-duplex environment.
2751 * The workaround is to avoid queuing a large packet that would span
2752 * the internal Tx FIFO ring boundary by notifying the stack to resend
2753 * the packet at a later time. This gives the Tx FIFO an opportunity to
2754 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2755 * to the beginning of the Tx FIFO.
2758 #define E1000_FIFO_HDR 0x10
2759 #define E1000_82547_PAD_LEN 0x3E0
2762 e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2764 uint32_t fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
2765 uint32_t skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
2767 E1000_ROUNDUP(skb_fifo_len
, E1000_FIFO_HDR
);
2769 if(adapter
->link_duplex
!= HALF_DUPLEX
)
2770 goto no_fifo_stall_required
;
2772 if(atomic_read(&adapter
->tx_fifo_stall
))
2775 if(skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
2776 atomic_set(&adapter
->tx_fifo_stall
, 1);
2780 no_fifo_stall_required
:
2781 adapter
->tx_fifo_head
+= skb_fifo_len
;
2782 if(adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
2783 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
2787 #define MINIMUM_DHCP_PACKET_SIZE 282
2789 e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2791 struct e1000_hw
*hw
= &adapter
->hw
;
2792 uint16_t length
, offset
;
2793 if(vlan_tx_tag_present(skb
)) {
2794 if(!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
2795 ( adapter
->hw
.mng_cookie
.status
&
2796 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) )
2799 if ((skb
->len
> MINIMUM_DHCP_PACKET_SIZE
) && (!skb
->protocol
)) {
2800 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
2801 if((htons(ETH_P_IP
) == eth
->h_proto
)) {
2802 const struct iphdr
*ip
=
2803 (struct iphdr
*)((uint8_t *)skb
->data
+14);
2804 if(IPPROTO_UDP
== ip
->protocol
) {
2805 struct udphdr
*udp
=
2806 (struct udphdr
*)((uint8_t *)ip
+
2808 if(ntohs(udp
->dest
) == 67) {
2809 offset
= (uint8_t *)udp
+ 8 - skb
->data
;
2810 length
= skb
->len
- offset
;
2812 return e1000_mng_write_dhcp_info(hw
,
2822 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2824 e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2826 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2827 struct e1000_tx_ring
*tx_ring
;
2828 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
2829 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
2830 unsigned int tx_flags
= 0;
2831 unsigned int len
= skb
->len
;
2832 unsigned long flags
;
2833 unsigned int nr_frags
= 0;
2834 unsigned int mss
= 0;
2838 len
-= skb
->data_len
;
2840 #ifdef CONFIG_E1000_MQ
2841 tx_ring
= *per_cpu_ptr(adapter
->cpu_tx_ring
, smp_processor_id());
2843 tx_ring
= adapter
->tx_ring
;
2846 if (unlikely(skb
->len
<= 0)) {
2847 dev_kfree_skb_any(skb
);
2848 return NETDEV_TX_OK
;
2852 mss
= skb_shinfo(skb
)->tso_size
;
2853 /* The controller does a simple calculation to
2854 * make sure there is enough room in the FIFO before
2855 * initiating the DMA for each buffer. The calc is:
2856 * 4 = ceil(buffer len/mss). To make sure we don't
2857 * overrun the FIFO, adjust the max buffer len if mss
2861 max_per_txd
= min(mss
<< 2, max_per_txd
);
2862 max_txd_pwr
= fls(max_per_txd
) - 1;
2864 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2865 * points to just header, pull a few bytes of payload from
2866 * frags into skb->data */
2867 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2868 if (skb
->data_len
&& (hdr_len
== (skb
->len
- skb
->data_len
)) &&
2869 (adapter
->hw
.mac_type
== e1000_82571
||
2870 adapter
->hw
.mac_type
== e1000_82572
)) {
2871 unsigned int pull_size
;
2872 pull_size
= min((unsigned int)4, skb
->data_len
);
2873 if (!__pskb_pull_tail(skb
, pull_size
)) {
2874 printk(KERN_ERR
"__pskb_pull_tail failed.\n");
2875 dev_kfree_skb_any(skb
);
2878 len
= skb
->len
- skb
->data_len
;
2882 if((mss
) || (skb
->ip_summed
== CHECKSUM_HW
))
2883 /* reserve a descriptor for the offload context */
2887 if(skb
->ip_summed
== CHECKSUM_HW
)
2892 /* Controller Erratum workaround */
2893 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2894 !skb_shinfo(skb
)->tso_size
)
2898 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
2900 if(adapter
->pcix_82544
)
2903 /* work-around for errata 10 and it applies to all controllers
2904 * in PCI-X mode, so add one more descriptor to the count
2906 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2910 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2911 for(f
= 0; f
< nr_frags
; f
++)
2912 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
2914 if(adapter
->pcix_82544
)
2917 if(adapter
->hw
.tx_pkt_filtering
&& (adapter
->hw
.mac_type
== e1000_82573
) )
2918 e1000_transfer_dhcp_info(adapter
, skb
);
2920 local_irq_save(flags
);
2921 if (!spin_trylock(&tx_ring
->tx_lock
)) {
2922 /* Collision - tell upper layer to requeue */
2923 local_irq_restore(flags
);
2924 return NETDEV_TX_LOCKED
;
2927 /* need: count + 2 desc gap to keep tail from touching
2928 * head, otherwise try next time */
2929 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < count
+ 2)) {
2930 netif_stop_queue(netdev
);
2931 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2932 return NETDEV_TX_BUSY
;
2935 if(unlikely(adapter
->hw
.mac_type
== e1000_82547
)) {
2936 if(unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
2937 netif_stop_queue(netdev
);
2938 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
);
2939 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2940 return NETDEV_TX_BUSY
;
2944 if(unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
2945 tx_flags
|= E1000_TX_FLAGS_VLAN
;
2946 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
2949 first
= tx_ring
->next_to_use
;
2951 tso
= e1000_tso(adapter
, tx_ring
, skb
);
2953 dev_kfree_skb_any(skb
);
2954 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2955 return NETDEV_TX_OK
;
2959 tx_ring
->last_tx_tso
= 1;
2960 tx_flags
|= E1000_TX_FLAGS_TSO
;
2961 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
2962 tx_flags
|= E1000_TX_FLAGS_CSUM
;
2964 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2965 * 82571 hardware supports TSO capabilities for IPv6 as well...
2966 * no longer assume, we must. */
2967 if (likely(skb
->protocol
== ntohs(ETH_P_IP
)))
2968 tx_flags
|= E1000_TX_FLAGS_IPV4
;
2970 e1000_tx_queue(adapter
, tx_ring
, tx_flags
,
2971 e1000_tx_map(adapter
, tx_ring
, skb
, first
,
2972 max_per_txd
, nr_frags
, mss
));
2974 netdev
->trans_start
= jiffies
;
2976 /* Make sure there is space in the ring for the next send. */
2977 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < MAX_SKB_FRAGS
+ 2))
2978 netif_stop_queue(netdev
);
2980 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2981 return NETDEV_TX_OK
;
2985 * e1000_tx_timeout - Respond to a Tx Hang
2986 * @netdev: network interface device structure
2990 e1000_tx_timeout(struct net_device
*netdev
)
2992 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2994 /* Do the reset outside of interrupt context */
2995 schedule_work(&adapter
->tx_timeout_task
);
2999 e1000_tx_timeout_task(struct net_device
*netdev
)
3001 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3003 adapter
->tx_timeout_count
++;
3004 e1000_down(adapter
);
3009 * e1000_get_stats - Get System Network Statistics
3010 * @netdev: network interface device structure
3012 * Returns the address of the device statistics structure.
3013 * The statistics are actually updated from the timer callback.
3016 static struct net_device_stats
*
3017 e1000_get_stats(struct net_device
*netdev
)
3019 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3021 /* only return the current stats */
3022 return &adapter
->net_stats
;
3026 * e1000_change_mtu - Change the Maximum Transfer Unit
3027 * @netdev: network interface device structure
3028 * @new_mtu: new value for maximum frame size
3030 * Returns 0 on success, negative on failure
3034 e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3036 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3037 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
3039 if((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
3040 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3041 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
3045 /* Adapter-specific max frame size limits. */
3046 switch (adapter
->hw
.mac_type
) {
3047 case e1000_82542_rev2_0
:
3048 case e1000_82542_rev2_1
:
3050 if (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3051 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported.\n");
3057 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3058 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3059 DPRINTK(PROBE
, ERR
, "MTU > 9216 not supported.\n");
3064 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3068 /* since the driver code now supports splitting a packet across
3069 * multiple descriptors, most of the fifo related limitations on
3070 * jumbo frame traffic have gone away.
3071 * simply use 2k descriptors for everything.
3073 * NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3074 * means we reserve 2 more, this pushes us to allocate from the next
3076 * i.e. RXBUFFER_2048 --> size-4096 slab */
3078 /* recent hardware supports 1KB granularity */
3079 if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3080 adapter
->rx_buffer_len
=
3081 ((max_frame
< E1000_RXBUFFER_2048
) ?
3082 max_frame
: E1000_RXBUFFER_2048
);
3083 E1000_ROUNDUP(adapter
->rx_buffer_len
, 1024);
3085 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3087 netdev
->mtu
= new_mtu
;
3089 if(netif_running(netdev
)) {
3090 e1000_down(adapter
);
3094 adapter
->hw
.max_frame_size
= max_frame
;
3100 * e1000_update_stats - Update the board statistics counters
3101 * @adapter: board private structure
3105 e1000_update_stats(struct e1000_adapter
*adapter
)
3107 struct e1000_hw
*hw
= &adapter
->hw
;
3108 unsigned long flags
;
3111 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3113 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3115 /* these counters are modified from e1000_adjust_tbi_stats,
3116 * called from the interrupt context, so they must only
3117 * be written while holding adapter->stats_lock
3120 adapter
->stats
.crcerrs
+= E1000_READ_REG(hw
, CRCERRS
);
3121 adapter
->stats
.gprc
+= E1000_READ_REG(hw
, GPRC
);
3122 adapter
->stats
.gorcl
+= E1000_READ_REG(hw
, GORCL
);
3123 adapter
->stats
.gorch
+= E1000_READ_REG(hw
, GORCH
);
3124 adapter
->stats
.bprc
+= E1000_READ_REG(hw
, BPRC
);
3125 adapter
->stats
.mprc
+= E1000_READ_REG(hw
, MPRC
);
3126 adapter
->stats
.roc
+= E1000_READ_REG(hw
, ROC
);
3127 adapter
->stats
.prc64
+= E1000_READ_REG(hw
, PRC64
);
3128 adapter
->stats
.prc127
+= E1000_READ_REG(hw
, PRC127
);
3129 adapter
->stats
.prc255
+= E1000_READ_REG(hw
, PRC255
);
3130 adapter
->stats
.prc511
+= E1000_READ_REG(hw
, PRC511
);
3131 adapter
->stats
.prc1023
+= E1000_READ_REG(hw
, PRC1023
);
3132 adapter
->stats
.prc1522
+= E1000_READ_REG(hw
, PRC1522
);
3134 adapter
->stats
.symerrs
+= E1000_READ_REG(hw
, SYMERRS
);
3135 adapter
->stats
.mpc
+= E1000_READ_REG(hw
, MPC
);
3136 adapter
->stats
.scc
+= E1000_READ_REG(hw
, SCC
);
3137 adapter
->stats
.ecol
+= E1000_READ_REG(hw
, ECOL
);
3138 adapter
->stats
.mcc
+= E1000_READ_REG(hw
, MCC
);
3139 adapter
->stats
.latecol
+= E1000_READ_REG(hw
, LATECOL
);
3140 adapter
->stats
.dc
+= E1000_READ_REG(hw
, DC
);
3141 adapter
->stats
.sec
+= E1000_READ_REG(hw
, SEC
);
3142 adapter
->stats
.rlec
+= E1000_READ_REG(hw
, RLEC
);
3143 adapter
->stats
.xonrxc
+= E1000_READ_REG(hw
, XONRXC
);
3144 adapter
->stats
.xontxc
+= E1000_READ_REG(hw
, XONTXC
);
3145 adapter
->stats
.xoffrxc
+= E1000_READ_REG(hw
, XOFFRXC
);
3146 adapter
->stats
.xofftxc
+= E1000_READ_REG(hw
, XOFFTXC
);
3147 adapter
->stats
.fcruc
+= E1000_READ_REG(hw
, FCRUC
);
3148 adapter
->stats
.gptc
+= E1000_READ_REG(hw
, GPTC
);
3149 adapter
->stats
.gotcl
+= E1000_READ_REG(hw
, GOTCL
);
3150 adapter
->stats
.gotch
+= E1000_READ_REG(hw
, GOTCH
);
3151 adapter
->stats
.rnbc
+= E1000_READ_REG(hw
, RNBC
);
3152 adapter
->stats
.ruc
+= E1000_READ_REG(hw
, RUC
);
3153 adapter
->stats
.rfc
+= E1000_READ_REG(hw
, RFC
);
3154 adapter
->stats
.rjc
+= E1000_READ_REG(hw
, RJC
);
3155 adapter
->stats
.torl
+= E1000_READ_REG(hw
, TORL
);
3156 adapter
->stats
.torh
+= E1000_READ_REG(hw
, TORH
);
3157 adapter
->stats
.totl
+= E1000_READ_REG(hw
, TOTL
);
3158 adapter
->stats
.toth
+= E1000_READ_REG(hw
, TOTH
);
3159 adapter
->stats
.tpr
+= E1000_READ_REG(hw
, TPR
);
3160 adapter
->stats
.ptc64
+= E1000_READ_REG(hw
, PTC64
);
3161 adapter
->stats
.ptc127
+= E1000_READ_REG(hw
, PTC127
);
3162 adapter
->stats
.ptc255
+= E1000_READ_REG(hw
, PTC255
);
3163 adapter
->stats
.ptc511
+= E1000_READ_REG(hw
, PTC511
);
3164 adapter
->stats
.ptc1023
+= E1000_READ_REG(hw
, PTC1023
);
3165 adapter
->stats
.ptc1522
+= E1000_READ_REG(hw
, PTC1522
);
3166 adapter
->stats
.mptc
+= E1000_READ_REG(hw
, MPTC
);
3167 adapter
->stats
.bptc
+= E1000_READ_REG(hw
, BPTC
);
3169 /* used for adaptive IFS */
3171 hw
->tx_packet_delta
= E1000_READ_REG(hw
, TPT
);
3172 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3173 hw
->collision_delta
= E1000_READ_REG(hw
, COLC
);
3174 adapter
->stats
.colc
+= hw
->collision_delta
;
3176 if(hw
->mac_type
>= e1000_82543
) {
3177 adapter
->stats
.algnerrc
+= E1000_READ_REG(hw
, ALGNERRC
);
3178 adapter
->stats
.rxerrc
+= E1000_READ_REG(hw
, RXERRC
);
3179 adapter
->stats
.tncrs
+= E1000_READ_REG(hw
, TNCRS
);
3180 adapter
->stats
.cexterr
+= E1000_READ_REG(hw
, CEXTERR
);
3181 adapter
->stats
.tsctc
+= E1000_READ_REG(hw
, TSCTC
);
3182 adapter
->stats
.tsctfc
+= E1000_READ_REG(hw
, TSCTFC
);
3184 if(hw
->mac_type
> e1000_82547_rev_2
) {
3185 adapter
->stats
.iac
+= E1000_READ_REG(hw
, IAC
);
3186 adapter
->stats
.icrxoc
+= E1000_READ_REG(hw
, ICRXOC
);
3187 adapter
->stats
.icrxptc
+= E1000_READ_REG(hw
, ICRXPTC
);
3188 adapter
->stats
.icrxatc
+= E1000_READ_REG(hw
, ICRXATC
);
3189 adapter
->stats
.ictxptc
+= E1000_READ_REG(hw
, ICTXPTC
);
3190 adapter
->stats
.ictxatc
+= E1000_READ_REG(hw
, ICTXATC
);
3191 adapter
->stats
.ictxqec
+= E1000_READ_REG(hw
, ICTXQEC
);
3192 adapter
->stats
.ictxqmtc
+= E1000_READ_REG(hw
, ICTXQMTC
);
3193 adapter
->stats
.icrxdmtc
+= E1000_READ_REG(hw
, ICRXDMTC
);
3196 /* Fill out the OS statistics structure */
3198 adapter
->net_stats
.rx_packets
= adapter
->stats
.gprc
;
3199 adapter
->net_stats
.tx_packets
= adapter
->stats
.gptc
;
3200 adapter
->net_stats
.rx_bytes
= adapter
->stats
.gorcl
;
3201 adapter
->net_stats
.tx_bytes
= adapter
->stats
.gotcl
;
3202 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3203 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3207 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3208 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3209 adapter
->stats
.rlec
+ adapter
->stats
.cexterr
;
3210 adapter
->net_stats
.rx_dropped
= 0;
3211 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlec
;
3212 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3213 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3214 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3218 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3219 adapter
->stats
.latecol
;
3220 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3221 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3222 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3224 /* Tx Dropped needs to be maintained elsewhere */
3228 if(hw
->media_type
== e1000_media_type_copper
) {
3229 if((adapter
->link_speed
== SPEED_1000
) &&
3230 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3231 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3232 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3235 if((hw
->mac_type
<= e1000_82546
) &&
3236 (hw
->phy_type
== e1000_phy_m88
) &&
3237 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3238 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3241 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3244 #ifdef CONFIG_E1000_MQ
3246 e1000_rx_schedule(void *data
)
3248 struct net_device
*poll_dev
, *netdev
= data
;
3249 struct e1000_adapter
*adapter
= netdev
->priv
;
3250 int this_cpu
= get_cpu();
3252 poll_dev
= *per_cpu_ptr(adapter
->cpu_netdev
, this_cpu
);
3253 if (poll_dev
== NULL
) {
3258 if (likely(netif_rx_schedule_prep(poll_dev
)))
3259 __netif_rx_schedule(poll_dev
);
3261 e1000_irq_enable(adapter
);
3268 * e1000_intr - Interrupt Handler
3269 * @irq: interrupt number
3270 * @data: pointer to a network interface device structure
3271 * @pt_regs: CPU registers structure
3275 e1000_intr(int irq
, void *data
, struct pt_regs
*regs
)
3277 struct net_device
*netdev
= data
;
3278 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3279 struct e1000_hw
*hw
= &adapter
->hw
;
3280 uint32_t icr
= E1000_READ_REG(hw
, ICR
);
3281 #ifndef CONFIG_E1000_NAPI
3284 /* Interrupt Auto-Mask...upon reading ICR,
3285 * interrupts are masked. No need for the
3286 * IMC write, but it does mean we should
3287 * account for it ASAP. */
3288 if (likely(hw
->mac_type
>= e1000_82571
))
3289 atomic_inc(&adapter
->irq_sem
);
3292 if (unlikely(!icr
)) {
3293 #ifdef CONFIG_E1000_NAPI
3294 if (hw
->mac_type
>= e1000_82571
)
3295 e1000_irq_enable(adapter
);
3297 return IRQ_NONE
; /* Not our interrupt */
3300 if(unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3301 hw
->get_link_status
= 1;
3302 mod_timer(&adapter
->watchdog_timer
, jiffies
);
3305 #ifdef CONFIG_E1000_NAPI
3306 if (unlikely(hw
->mac_type
< e1000_82571
)) {
3307 atomic_inc(&adapter
->irq_sem
);
3308 E1000_WRITE_REG(hw
, IMC
, ~0);
3309 E1000_WRITE_FLUSH(hw
);
3311 #ifdef CONFIG_E1000_MQ
3312 if (atomic_read(&adapter
->rx_sched_call_data
.count
) == 0) {
3313 /* We must setup the cpumask once count == 0 since
3314 * each cpu bit is cleared when the work is done. */
3315 adapter
->rx_sched_call_data
.cpumask
= adapter
->cpumask
;
3316 atomic_add(adapter
->num_rx_queues
- 1, &adapter
->irq_sem
);
3317 atomic_set(&adapter
->rx_sched_call_data
.count
,
3318 adapter
->num_rx_queues
);
3319 smp_call_async_mask(&adapter
->rx_sched_call_data
);
3321 printk("call_data.count == %u\n", atomic_read(&adapter
->rx_sched_call_data
.count
));
3323 #else /* if !CONFIG_E1000_MQ */
3324 if (likely(netif_rx_schedule_prep(&adapter
->polling_netdev
[0])))
3325 __netif_rx_schedule(&adapter
->polling_netdev
[0]);
3327 e1000_irq_enable(adapter
);
3328 #endif /* CONFIG_E1000_MQ */
3330 #else /* if !CONFIG_E1000_NAPI */
3331 /* Writing IMC and IMS is needed for 82547.
3332 Due to Hub Link bus being occupied, an interrupt
3333 de-assertion message is not able to be sent.
3334 When an interrupt assertion message is generated later,
3335 two messages are re-ordered and sent out.
3336 That causes APIC to think 82547 is in de-assertion
3337 state, while 82547 is in assertion state, resulting
3338 in dead lock. Writing IMC forces 82547 into
3341 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
){
3342 atomic_inc(&adapter
->irq_sem
);
3343 E1000_WRITE_REG(hw
, IMC
, ~0);
3346 for(i
= 0; i
< E1000_MAX_INTR
; i
++)
3347 if(unlikely(!adapter
->clean_rx(adapter
, adapter
->rx_ring
) &
3348 !e1000_clean_tx_irq(adapter
, adapter
->tx_ring
)))
3351 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
3352 e1000_irq_enable(adapter
);
3354 #endif /* CONFIG_E1000_NAPI */
3359 #ifdef CONFIG_E1000_NAPI
3361 * e1000_clean - NAPI Rx polling callback
3362 * @adapter: board private structure
3366 e1000_clean(struct net_device
*poll_dev
, int *budget
)
3368 struct e1000_adapter
*adapter
;
3369 int work_to_do
= min(*budget
, poll_dev
->quota
);
3370 int tx_cleaned
, i
= 0, work_done
= 0;
3372 /* Must NOT use netdev_priv macro here. */
3373 adapter
= poll_dev
->priv
;
3375 /* Keep link state information with original netdev */
3376 if (!netif_carrier_ok(adapter
->netdev
))
3379 while (poll_dev
!= &adapter
->polling_netdev
[i
]) {
3381 if (unlikely(i
== adapter
->num_rx_queues
))
3385 tx_cleaned
= e1000_clean_tx_irq(adapter
, &adapter
->tx_ring
[i
]);
3386 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[i
],
3387 &work_done
, work_to_do
);
3389 *budget
-= work_done
;
3390 poll_dev
->quota
-= work_done
;
3392 /* If no Tx and not enough Rx work done, exit the polling mode */
3393 if((!tx_cleaned
&& (work_done
== 0)) ||
3394 !netif_running(adapter
->netdev
)) {
3396 netif_rx_complete(poll_dev
);
3397 e1000_irq_enable(adapter
);
3406 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3407 * @adapter: board private structure
3411 e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
3412 struct e1000_tx_ring
*tx_ring
)
3414 struct net_device
*netdev
= adapter
->netdev
;
3415 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
3416 struct e1000_buffer
*buffer_info
;
3417 unsigned int i
, eop
;
3418 boolean_t cleaned
= FALSE
;
3420 i
= tx_ring
->next_to_clean
;
3421 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3422 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3424 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
3425 for(cleaned
= FALSE
; !cleaned
; ) {
3426 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3427 buffer_info
= &tx_ring
->buffer_info
[i
];
3428 cleaned
= (i
== eop
);
3430 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
3432 tx_desc
->buffer_addr
= 0;
3433 tx_desc
->lower
.data
= 0;
3434 tx_desc
->upper
.data
= 0;
3436 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
3439 #ifdef CONFIG_E1000_MQ
3440 tx_ring
->tx_stats
.packets
++;
3443 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3444 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3447 tx_ring
->next_to_clean
= i
;
3449 spin_lock(&tx_ring
->tx_lock
);
3451 if(unlikely(cleaned
&& netif_queue_stopped(netdev
) &&
3452 netif_carrier_ok(netdev
)))
3453 netif_wake_queue(netdev
);
3455 spin_unlock(&tx_ring
->tx_lock
);
3457 if (adapter
->detect_tx_hung
) {
3458 /* Detect a transmit hang in hardware, this serializes the
3459 * check with the clearing of time_stamp and movement of i */
3460 adapter
->detect_tx_hung
= FALSE
;
3461 if (tx_ring
->buffer_info
[eop
].dma
&&
3462 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
+
3463 adapter
->tx_timeout_factor
* HZ
)
3464 && !(E1000_READ_REG(&adapter
->hw
, STATUS
) &
3465 E1000_STATUS_TXOFF
)) {
3467 /* detected Tx unit hang */
3468 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
3472 " next_to_use <%x>\n"
3473 " next_to_clean <%x>\n"
3474 "buffer_info[next_to_clean]\n"
3475 " time_stamp <%lx>\n"
3476 " next_to_watch <%x>\n"
3478 " next_to_watch.status <%x>\n",
3479 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
3480 sizeof(struct e1000_tx_ring
)),
3481 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdh
),
3482 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdt
),
3483 tx_ring
->next_to_use
,
3484 tx_ring
->next_to_clean
,
3485 tx_ring
->buffer_info
[eop
].time_stamp
,
3488 eop_desc
->upper
.fields
.status
);
3489 netif_stop_queue(netdev
);
3496 * e1000_rx_checksum - Receive Checksum Offload for 82543
3497 * @adapter: board private structure
3498 * @status_err: receive descriptor status and error fields
3499 * @csum: receive descriptor csum field
3500 * @sk_buff: socket buffer with received data
3504 e1000_rx_checksum(struct e1000_adapter
*adapter
,
3505 uint32_t status_err
, uint32_t csum
,
3506 struct sk_buff
*skb
)
3508 uint16_t status
= (uint16_t)status_err
;
3509 uint8_t errors
= (uint8_t)(status_err
>> 24);
3510 skb
->ip_summed
= CHECKSUM_NONE
;
3512 /* 82543 or newer only */
3513 if(unlikely(adapter
->hw
.mac_type
< e1000_82543
)) return;
3514 /* Ignore Checksum bit is set */
3515 if(unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
3516 /* TCP/UDP checksum error bit is set */
3517 if(unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
3518 /* let the stack verify checksum errors */
3519 adapter
->hw_csum_err
++;
3522 /* TCP/UDP Checksum has not been calculated */
3523 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
) {
3524 if(!(status
& E1000_RXD_STAT_TCPCS
))
3527 if(!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
3530 /* It must be a TCP or UDP packet with a valid checksum */
3531 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
3532 /* TCP checksum is good */
3533 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3534 } else if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3535 /* IP fragment with UDP payload */
3536 /* Hardware complements the payload checksum, so we undo it
3537 * and then put the value in host order for further stack use.
3539 csum
= ntohl(csum
^ 0xFFFF);
3541 skb
->ip_summed
= CHECKSUM_HW
;
3543 adapter
->hw_csum_good
++;
3547 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3548 * @adapter: board private structure
3552 #ifdef CONFIG_E1000_NAPI
3553 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3554 struct e1000_rx_ring
*rx_ring
,
3555 int *work_done
, int work_to_do
)
3557 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3558 struct e1000_rx_ring
*rx_ring
)
3561 struct net_device
*netdev
= adapter
->netdev
;
3562 struct pci_dev
*pdev
= adapter
->pdev
;
3563 struct e1000_rx_desc
*rx_desc
;
3564 struct e1000_buffer
*buffer_info
;
3565 struct sk_buff
*skb
;
3566 unsigned long flags
;
3570 boolean_t cleaned
= FALSE
;
3571 int cleaned_count
= 0;
3573 i
= rx_ring
->next_to_clean
;
3574 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3576 while(rx_desc
->status
& E1000_RXD_STAT_DD
) {
3577 buffer_info
= &rx_ring
->buffer_info
[i
];
3578 #ifdef CONFIG_E1000_NAPI
3579 if(*work_done
>= work_to_do
)
3586 pci_unmap_single(pdev
, buffer_info
->dma
, buffer_info
->length
,
3587 PCI_DMA_FROMDEVICE
);
3589 skb
= buffer_info
->skb
;
3590 length
= le16_to_cpu(rx_desc
->length
);
3592 if(unlikely(!(rx_desc
->status
& E1000_RXD_STAT_EOP
))) {
3593 /* All receives must fit into a single buffer */
3594 E1000_DBG("%s: Receive packet consumed multiple"
3595 " buffers\n", netdev
->name
);
3596 dev_kfree_skb_irq(skb
);
3600 if(unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
3601 last_byte
= *(skb
->data
+ length
- 1);
3602 if(TBI_ACCEPT(&adapter
->hw
, rx_desc
->status
,
3603 rx_desc
->errors
, length
, last_byte
)) {
3604 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3605 e1000_tbi_adjust_stats(&adapter
->hw
, &adapter
->stats
,
3607 spin_unlock_irqrestore(&adapter
->stats_lock
,
3611 dev_kfree_skb_irq(skb
);
3617 skb_put(skb
, length
- ETHERNET_FCS_SIZE
);
3619 /* Receive Checksum Offload */
3620 e1000_rx_checksum(adapter
, (uint32_t)(rx_desc
->status
) |
3621 ((uint32_t)(rx_desc
->errors
) << 24),
3622 rx_desc
->csum
, skb
);
3623 skb
->protocol
= eth_type_trans(skb
, netdev
);
3624 #ifdef CONFIG_E1000_NAPI
3625 if(unlikely(adapter
->vlgrp
&&
3626 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3627 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3628 le16_to_cpu(rx_desc
->special
) &
3629 E1000_RXD_SPC_VLAN_MASK
);
3631 netif_receive_skb(skb
);
3633 #else /* CONFIG_E1000_NAPI */
3634 if(unlikely(adapter
->vlgrp
&&
3635 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3636 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3637 le16_to_cpu(rx_desc
->special
) &
3638 E1000_RXD_SPC_VLAN_MASK
);
3642 #endif /* CONFIG_E1000_NAPI */
3643 netdev
->last_rx
= jiffies
;
3644 #ifdef CONFIG_E1000_MQ
3645 rx_ring
->rx_stats
.packets
++;
3646 rx_ring
->rx_stats
.bytes
+= length
;
3650 rx_desc
->status
= 0;
3652 /* return some buffers to hardware, one at a time is too slow */
3653 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
3654 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3659 rx_ring
->next_to_clean
= i
;
3661 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
3663 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3669 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3670 * @adapter: board private structure
3674 #ifdef CONFIG_E1000_NAPI
3675 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3676 struct e1000_rx_ring
*rx_ring
,
3677 int *work_done
, int work_to_do
)
3679 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3680 struct e1000_rx_ring
*rx_ring
)
3683 union e1000_rx_desc_packet_split
*rx_desc
;
3684 struct net_device
*netdev
= adapter
->netdev
;
3685 struct pci_dev
*pdev
= adapter
->pdev
;
3686 struct e1000_buffer
*buffer_info
;
3687 struct e1000_ps_page
*ps_page
;
3688 struct e1000_ps_page_dma
*ps_page_dma
;
3689 struct sk_buff
*skb
;
3691 uint32_t length
, staterr
;
3692 int cleaned_count
= 0;
3693 boolean_t cleaned
= FALSE
;
3695 i
= rx_ring
->next_to_clean
;
3696 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3697 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3699 while(staterr
& E1000_RXD_STAT_DD
) {
3700 buffer_info
= &rx_ring
->buffer_info
[i
];
3701 ps_page
= &rx_ring
->ps_page
[i
];
3702 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3703 #ifdef CONFIG_E1000_NAPI
3704 if(unlikely(*work_done
>= work_to_do
))
3710 pci_unmap_single(pdev
, buffer_info
->dma
,
3711 buffer_info
->length
,
3712 PCI_DMA_FROMDEVICE
);
3714 skb
= buffer_info
->skb
;
3716 if(unlikely(!(staterr
& E1000_RXD_STAT_EOP
))) {
3717 E1000_DBG("%s: Packet Split buffers didn't pick up"
3718 " the full packet\n", netdev
->name
);
3719 dev_kfree_skb_irq(skb
);
3723 if(unlikely(staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
)) {
3724 dev_kfree_skb_irq(skb
);
3728 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
3730 if(unlikely(!length
)) {
3731 E1000_DBG("%s: Last part of the packet spanning"
3732 " multiple descriptors\n", netdev
->name
);
3733 dev_kfree_skb_irq(skb
);
3738 skb_put(skb
, length
);
3740 for(j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
3741 if(!(length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
])))
3744 pci_unmap_page(pdev
, ps_page_dma
->ps_page_dma
[j
],
3745 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
3746 ps_page_dma
->ps_page_dma
[j
] = 0;
3747 skb_shinfo(skb
)->frags
[j
].page
=
3748 ps_page
->ps_page
[j
];
3749 ps_page
->ps_page
[j
] = NULL
;
3750 skb_shinfo(skb
)->frags
[j
].page_offset
= 0;
3751 skb_shinfo(skb
)->frags
[j
].size
= length
;
3752 skb_shinfo(skb
)->nr_frags
++;
3754 skb
->data_len
+= length
;
3757 e1000_rx_checksum(adapter
, staterr
,
3758 rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
, skb
);
3759 skb
->protocol
= eth_type_trans(skb
, netdev
);
3761 if(likely(rx_desc
->wb
.upper
.header_status
&
3762 E1000_RXDPS_HDRSTAT_HDRSP
)) {
3763 adapter
->rx_hdr_split
++;
3764 #ifdef HAVE_RX_ZERO_COPY
3765 skb_shinfo(skb
)->zero_copy
= TRUE
;
3768 #ifdef CONFIG_E1000_NAPI
3769 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3770 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3771 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3772 E1000_RXD_SPC_VLAN_MASK
);
3774 netif_receive_skb(skb
);
3776 #else /* CONFIG_E1000_NAPI */
3777 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3778 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3779 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3780 E1000_RXD_SPC_VLAN_MASK
);
3784 #endif /* CONFIG_E1000_NAPI */
3785 netdev
->last_rx
= jiffies
;
3786 #ifdef CONFIG_E1000_MQ
3787 rx_ring
->rx_stats
.packets
++;
3788 rx_ring
->rx_stats
.bytes
+= length
;
3792 rx_desc
->wb
.middle
.status_error
&= ~0xFF;
3793 buffer_info
->skb
= NULL
;
3795 /* return some buffers to hardware, one at a time is too slow */
3796 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
3797 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3801 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3803 rx_ring
->next_to_clean
= i
;
3805 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
3807 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3813 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3814 * @adapter: address of board private structure
3818 e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
3819 struct e1000_rx_ring
*rx_ring
,
3822 struct net_device
*netdev
= adapter
->netdev
;
3823 struct pci_dev
*pdev
= adapter
->pdev
;
3824 struct e1000_rx_desc
*rx_desc
;
3825 struct e1000_buffer
*buffer_info
;
3826 struct sk_buff
*skb
;
3828 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
3830 i
= rx_ring
->next_to_use
;
3831 buffer_info
= &rx_ring
->buffer_info
[i
];
3833 while(!buffer_info
->skb
) {
3834 skb
= dev_alloc_skb(bufsz
);
3836 if(unlikely(!skb
)) {
3837 /* Better luck next round */
3838 adapter
->alloc_rx_buff_failed
++;
3842 /* Fix for errata 23, can't cross 64kB boundary */
3843 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3844 struct sk_buff
*oldskb
= skb
;
3845 DPRINTK(RX_ERR
, ERR
, "skb align check failed: %u bytes "
3846 "at %p\n", bufsz
, skb
->data
);
3847 /* Try again, without freeing the previous */
3848 skb
= dev_alloc_skb(bufsz
);
3849 /* Failed allocation, critical failure */
3851 dev_kfree_skb(oldskb
);
3855 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3858 dev_kfree_skb(oldskb
);
3859 break; /* while !buffer_info->skb */
3861 /* Use new allocation */
3862 dev_kfree_skb(oldskb
);
3865 /* Make buffer alignment 2 beyond a 16 byte boundary
3866 * this will result in a 16 byte aligned IP header after
3867 * the 14 byte MAC header is removed
3869 skb_reserve(skb
, NET_IP_ALIGN
);
3873 buffer_info
->skb
= skb
;
3874 buffer_info
->length
= adapter
->rx_buffer_len
;
3875 buffer_info
->dma
= pci_map_single(pdev
,
3877 adapter
->rx_buffer_len
,
3878 PCI_DMA_FROMDEVICE
);
3880 /* Fix for errata 23, can't cross 64kB boundary */
3881 if (!e1000_check_64k_bound(adapter
,
3882 (void *)(unsigned long)buffer_info
->dma
,
3883 adapter
->rx_buffer_len
)) {
3884 DPRINTK(RX_ERR
, ERR
,
3885 "dma align check failed: %u bytes at %p\n",
3886 adapter
->rx_buffer_len
,
3887 (void *)(unsigned long)buffer_info
->dma
);
3889 buffer_info
->skb
= NULL
;
3891 pci_unmap_single(pdev
, buffer_info
->dma
,
3892 adapter
->rx_buffer_len
,
3893 PCI_DMA_FROMDEVICE
);
3895 break; /* while !buffer_info->skb */
3897 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3898 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3900 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3901 /* Force memory writes to complete before letting h/w
3902 * know there are new descriptors to fetch. (Only
3903 * applicable for weak-ordered memory model archs,
3904 * such as IA-64). */
3906 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
3909 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3910 buffer_info
= &rx_ring
->buffer_info
[i
];
3913 rx_ring
->next_to_use
= i
;
3917 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3918 * @adapter: address of board private structure
3922 e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
3923 struct e1000_rx_ring
*rx_ring
,
3926 struct net_device
*netdev
= adapter
->netdev
;
3927 struct pci_dev
*pdev
= adapter
->pdev
;
3928 union e1000_rx_desc_packet_split
*rx_desc
;
3929 struct e1000_buffer
*buffer_info
;
3930 struct e1000_ps_page
*ps_page
;
3931 struct e1000_ps_page_dma
*ps_page_dma
;
3932 struct sk_buff
*skb
;
3935 i
= rx_ring
->next_to_use
;
3936 buffer_info
= &rx_ring
->buffer_info
[i
];
3937 ps_page
= &rx_ring
->ps_page
[i
];
3938 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3940 while (cleaned_count
--) {
3941 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3943 for(j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
3944 if (j
< adapter
->rx_ps_pages
) {
3945 if (likely(!ps_page
->ps_page
[j
])) {
3946 ps_page
->ps_page
[j
] =
3947 alloc_page(GFP_ATOMIC
);
3948 if (unlikely(!ps_page
->ps_page
[j
]))
3950 ps_page_dma
->ps_page_dma
[j
] =
3952 ps_page
->ps_page
[j
],
3954 PCI_DMA_FROMDEVICE
);
3956 /* Refresh the desc even if buffer_addrs didn't
3957 * change because each write-back erases
3960 rx_desc
->read
.buffer_addr
[j
+1] =
3961 cpu_to_le64(ps_page_dma
->ps_page_dma
[j
]);
3963 rx_desc
->read
.buffer_addr
[j
+1] = ~0;
3966 skb
= dev_alloc_skb(adapter
->rx_ps_bsize0
+ NET_IP_ALIGN
);
3971 /* Make buffer alignment 2 beyond a 16 byte boundary
3972 * this will result in a 16 byte aligned IP header after
3973 * the 14 byte MAC header is removed
3975 skb_reserve(skb
, NET_IP_ALIGN
);
3979 buffer_info
->skb
= skb
;
3980 buffer_info
->length
= adapter
->rx_ps_bsize0
;
3981 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
3982 adapter
->rx_ps_bsize0
,
3983 PCI_DMA_FROMDEVICE
);
3985 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
3987 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3988 /* Force memory writes to complete before letting h/w
3989 * know there are new descriptors to fetch. (Only
3990 * applicable for weak-ordered memory model archs,
3991 * such as IA-64). */
3993 /* Hardware increments by 16 bytes, but packet split
3994 * descriptors are 32 bytes...so we increment tail
3997 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
4000 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
4001 buffer_info
= &rx_ring
->buffer_info
[i
];
4002 ps_page
= &rx_ring
->ps_page
[i
];
4003 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
4007 rx_ring
->next_to_use
= i
;
4011 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4016 e1000_smartspeed(struct e1000_adapter
*adapter
)
4018 uint16_t phy_status
;
4021 if((adapter
->hw
.phy_type
!= e1000_phy_igp
) || !adapter
->hw
.autoneg
||
4022 !(adapter
->hw
.autoneg_advertised
& ADVERTISE_1000_FULL
))
4025 if(adapter
->smartspeed
== 0) {
4026 /* If Master/Slave config fault is asserted twice,
4027 * we assume back-to-back */
4028 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4029 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4030 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4031 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4032 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4033 if(phy_ctrl
& CR_1000T_MS_ENABLE
) {
4034 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
4035 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
,
4037 adapter
->smartspeed
++;
4038 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4039 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
,
4041 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4042 MII_CR_RESTART_AUTO_NEG
);
4043 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
,
4048 } else if(adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
4049 /* If still no link, perhaps using 2/3 pair cable */
4050 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4051 phy_ctrl
|= CR_1000T_MS_ENABLE
;
4052 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, phy_ctrl
);
4053 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4054 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &phy_ctrl
)) {
4055 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4056 MII_CR_RESTART_AUTO_NEG
);
4057 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, phy_ctrl
);
4060 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4061 if(adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
4062 adapter
->smartspeed
= 0;
4073 e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4079 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4093 e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4095 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4096 struct mii_ioctl_data
*data
= if_mii(ifr
);
4100 unsigned long flags
;
4102 if(adapter
->hw
.media_type
!= e1000_media_type_copper
)
4107 data
->phy_id
= adapter
->hw
.phy_addr
;
4110 if(!capable(CAP_NET_ADMIN
))
4112 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4113 if(e1000_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
4115 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4118 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4121 if(!capable(CAP_NET_ADMIN
))
4123 if(data
->reg_num
& ~(0x1F))
4125 mii_reg
= data
->val_in
;
4126 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4127 if(e1000_write_phy_reg(&adapter
->hw
, data
->reg_num
,
4129 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4132 if(adapter
->hw
.phy_type
== e1000_phy_m88
) {
4133 switch (data
->reg_num
) {
4135 if(mii_reg
& MII_CR_POWER_DOWN
)
4137 if(mii_reg
& MII_CR_AUTO_NEG_EN
) {
4138 adapter
->hw
.autoneg
= 1;
4139 adapter
->hw
.autoneg_advertised
= 0x2F;
4142 spddplx
= SPEED_1000
;
4143 else if (mii_reg
& 0x2000)
4144 spddplx
= SPEED_100
;
4147 spddplx
+= (mii_reg
& 0x100)
4150 retval
= e1000_set_spd_dplx(adapter
,
4153 spin_unlock_irqrestore(
4154 &adapter
->stats_lock
,
4159 if(netif_running(adapter
->netdev
)) {
4160 e1000_down(adapter
);
4163 e1000_reset(adapter
);
4165 case M88E1000_PHY_SPEC_CTRL
:
4166 case M88E1000_EXT_PHY_SPEC_CTRL
:
4167 if(e1000_phy_reset(&adapter
->hw
)) {
4168 spin_unlock_irqrestore(
4169 &adapter
->stats_lock
, flags
);
4175 switch (data
->reg_num
) {
4177 if(mii_reg
& MII_CR_POWER_DOWN
)
4179 if(netif_running(adapter
->netdev
)) {
4180 e1000_down(adapter
);
4183 e1000_reset(adapter
);
4187 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4192 return E1000_SUCCESS
;
4196 e1000_pci_set_mwi(struct e1000_hw
*hw
)
4198 struct e1000_adapter
*adapter
= hw
->back
;
4199 int ret_val
= pci_set_mwi(adapter
->pdev
);
4202 DPRINTK(PROBE
, ERR
, "Error in setting MWI\n");
4206 e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4208 struct e1000_adapter
*adapter
= hw
->back
;
4210 pci_clear_mwi(adapter
->pdev
);
4214 e1000_read_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4216 struct e1000_adapter
*adapter
= hw
->back
;
4218 pci_read_config_word(adapter
->pdev
, reg
, value
);
4222 e1000_write_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4224 struct e1000_adapter
*adapter
= hw
->back
;
4226 pci_write_config_word(adapter
->pdev
, reg
, *value
);
4230 e1000_io_read(struct e1000_hw
*hw
, unsigned long port
)
4236 e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, uint32_t value
)
4242 e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
4244 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4245 uint32_t ctrl
, rctl
;
4247 e1000_irq_disable(adapter
);
4248 adapter
->vlgrp
= grp
;
4251 /* enable VLAN tag insert/strip */
4252 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4253 ctrl
|= E1000_CTRL_VME
;
4254 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4256 /* enable VLAN receive filtering */
4257 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4258 rctl
|= E1000_RCTL_VFE
;
4259 rctl
&= ~E1000_RCTL_CFIEN
;
4260 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4261 e1000_update_mng_vlan(adapter
);
4263 /* disable VLAN tag insert/strip */
4264 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4265 ctrl
&= ~E1000_CTRL_VME
;
4266 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4268 /* disable VLAN filtering */
4269 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4270 rctl
&= ~E1000_RCTL_VFE
;
4271 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4272 if(adapter
->mng_vlan_id
!= (uint16_t)E1000_MNG_VLAN_NONE
) {
4273 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
4274 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
4278 e1000_irq_enable(adapter
);
4282 e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
)
4284 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4285 uint32_t vfta
, index
;
4286 if((adapter
->hw
.mng_cookie
.status
&
4287 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4288 (vid
== adapter
->mng_vlan_id
))
4290 /* add VID to filter table */
4291 index
= (vid
>> 5) & 0x7F;
4292 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4293 vfta
|= (1 << (vid
& 0x1F));
4294 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4298 e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
)
4300 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4301 uint32_t vfta
, index
;
4303 e1000_irq_disable(adapter
);
4306 adapter
->vlgrp
->vlan_devices
[vid
] = NULL
;
4308 e1000_irq_enable(adapter
);
4310 if((adapter
->hw
.mng_cookie
.status
&
4311 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4312 (vid
== adapter
->mng_vlan_id
)) {
4313 /* release control to f/w */
4314 e1000_release_hw_control(adapter
);
4318 /* remove VID from filter table */
4319 index
= (vid
>> 5) & 0x7F;
4320 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4321 vfta
&= ~(1 << (vid
& 0x1F));
4322 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4326 e1000_restore_vlan(struct e1000_adapter
*adapter
)
4328 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
4330 if(adapter
->vlgrp
) {
4332 for(vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
4333 if(!adapter
->vlgrp
->vlan_devices
[vid
])
4335 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
4341 e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
)
4343 adapter
->hw
.autoneg
= 0;
4345 /* Fiber NICs only allow 1000 gbps Full duplex */
4346 if((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
4347 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
4348 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4353 case SPEED_10
+ DUPLEX_HALF
:
4354 adapter
->hw
.forced_speed_duplex
= e1000_10_half
;
4356 case SPEED_10
+ DUPLEX_FULL
:
4357 adapter
->hw
.forced_speed_duplex
= e1000_10_full
;
4359 case SPEED_100
+ DUPLEX_HALF
:
4360 adapter
->hw
.forced_speed_duplex
= e1000_100_half
;
4362 case SPEED_100
+ DUPLEX_FULL
:
4363 adapter
->hw
.forced_speed_duplex
= e1000_100_full
;
4365 case SPEED_1000
+ DUPLEX_FULL
:
4366 adapter
->hw
.autoneg
= 1;
4367 adapter
->hw
.autoneg_advertised
= ADVERTISE_1000_FULL
;
4369 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
4371 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4379 e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4381 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4382 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4383 uint32_t ctrl
, ctrl_ext
, rctl
, manc
, status
;
4384 uint32_t wufc
= adapter
->wol
;
4387 netif_device_detach(netdev
);
4389 if(netif_running(netdev
))
4390 e1000_down(adapter
);
4392 status
= E1000_READ_REG(&adapter
->hw
, STATUS
);
4393 if(status
& E1000_STATUS_LU
)
4394 wufc
&= ~E1000_WUFC_LNKC
;
4397 e1000_setup_rctl(adapter
);
4398 e1000_set_multi(netdev
);
4400 /* turn on all-multi mode if wake on multicast is enabled */
4401 if(adapter
->wol
& E1000_WUFC_MC
) {
4402 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4403 rctl
|= E1000_RCTL_MPE
;
4404 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4407 if(adapter
->hw
.mac_type
>= e1000_82540
) {
4408 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4409 /* advertise wake from D3Cold */
4410 #define E1000_CTRL_ADVD3WUC 0x00100000
4411 /* phy power management enable */
4412 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4413 ctrl
|= E1000_CTRL_ADVD3WUC
|
4414 E1000_CTRL_EN_PHY_PWR_MGMT
;
4415 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4418 if(adapter
->hw
.media_type
== e1000_media_type_fiber
||
4419 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) {
4420 /* keep the laser running in D3 */
4421 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
4422 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
4423 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
, ctrl_ext
);
4426 /* Allow time for pending master requests to run */
4427 e1000_disable_pciex_master(&adapter
->hw
);
4429 E1000_WRITE_REG(&adapter
->hw
, WUC
, E1000_WUC_PME_EN
);
4430 E1000_WRITE_REG(&adapter
->hw
, WUFC
, wufc
);
4431 retval
= pci_enable_wake(pdev
, PCI_D3hot
, 1);
4433 DPRINTK(PROBE
, ERR
, "Error enabling D3 wake\n");
4434 retval
= pci_enable_wake(pdev
, PCI_D3cold
, 1);
4436 DPRINTK(PROBE
, ERR
, "Error enabling D3 cold wake\n");
4438 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
4439 E1000_WRITE_REG(&adapter
->hw
, WUFC
, 0);
4440 retval
= pci_enable_wake(pdev
, PCI_D3hot
, 0);
4442 DPRINTK(PROBE
, ERR
, "Error enabling D3 wake\n");
4443 retval
= pci_enable_wake(pdev
, PCI_D3cold
, 0); /* 4 == D3 cold */
4445 DPRINTK(PROBE
, ERR
, "Error enabling D3 cold wake\n");
4448 pci_save_state(pdev
);
4450 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4451 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4452 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4453 if(manc
& E1000_MANC_SMBUS_EN
) {
4454 manc
|= E1000_MANC_ARP_EN
;
4455 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4456 retval
= pci_enable_wake(pdev
, PCI_D3hot
, 1);
4458 DPRINTK(PROBE
, ERR
, "Error enabling D3 wake\n");
4459 retval
= pci_enable_wake(pdev
, PCI_D3cold
, 1);
4461 DPRINTK(PROBE
, ERR
, "Error enabling D3 cold wake\n");
4465 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4466 * would have already happened in close and is redundant. */
4467 e1000_release_hw_control(adapter
);
4469 pci_disable_device(pdev
);
4471 retval
= pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4473 DPRINTK(PROBE
, ERR
, "Error in setting power state\n");
4479 e1000_resume(struct pci_dev
*pdev
)
4481 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4482 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4484 uint32_t manc
, ret_val
;
4486 retval
= pci_set_power_state(pdev
, PCI_D0
);
4488 DPRINTK(PROBE
, ERR
, "Error in setting power state\n");
4489 ret_val
= pci_enable_device(pdev
);
4490 pci_set_master(pdev
);
4492 retval
= pci_enable_wake(pdev
, PCI_D3hot
, 0);
4494 DPRINTK(PROBE
, ERR
, "Error enabling D3 wake\n");
4495 retval
= pci_enable_wake(pdev
, PCI_D3cold
, 0);
4497 DPRINTK(PROBE
, ERR
, "Error enabling D3 cold wake\n");
4499 e1000_reset(adapter
);
4500 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
4502 if(netif_running(netdev
))
4505 netif_device_attach(netdev
);
4507 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4508 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4509 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4510 manc
&= ~(E1000_MANC_ARP_EN
);
4511 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4514 /* If the controller is 82573 and f/w is AMT, do not set
4515 * DRV_LOAD until the interface is up. For all other cases,
4516 * let the f/w know that the h/w is now under the control
4518 if (adapter
->hw
.mac_type
!= e1000_82573
||
4519 !e1000_check_mng_mode(&adapter
->hw
))
4520 e1000_get_hw_control(adapter
);
4525 #ifdef CONFIG_NET_POLL_CONTROLLER
4527 * Polling 'interrupt' - used by things like netconsole to send skbs
4528 * without having to re-enable interrupts. It's not called while
4529 * the interrupt routine is executing.
4532 e1000_netpoll(struct net_device
*netdev
)
4534 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4535 disable_irq(adapter
->pdev
->irq
);
4536 e1000_intr(adapter
->pdev
->irq
, netdev
, NULL
);
4537 e1000_clean_tx_irq(adapter
, adapter
->tx_ring
);
4538 #ifndef CONFIG_E1000_NAPI
4539 adapter
->clean_rx(adapter
, adapter
->rx_ring
);
4541 enable_irq(adapter
->pdev
->irq
);