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 /* reset the hardware with the new settings */
811 e1000_reset(adapter
);
813 /* If the controller is 82573 and f/w is AMT, do not set
814 * DRV_LOAD until the interface is up. For all other cases,
815 * let the f/w know that the h/w is now under the control
817 if (adapter
->hw
.mac_type
!= e1000_82573
||
818 !e1000_check_mng_mode(&adapter
->hw
))
819 e1000_get_hw_control(adapter
);
821 strcpy(netdev
->name
, "eth%d");
822 if((err
= register_netdev(netdev
)))
825 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
833 iounmap(adapter
->hw
.hw_addr
);
837 pci_release_regions(pdev
);
842 * e1000_remove - Device Removal Routine
843 * @pdev: PCI device information struct
845 * e1000_remove is called by the PCI subsystem to alert the driver
846 * that it should release a PCI device. The could be caused by a
847 * Hot-Plug event, or because the driver is going to be removed from
851 static void __devexit
852 e1000_remove(struct pci_dev
*pdev
)
854 struct net_device
*netdev
= pci_get_drvdata(pdev
);
855 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
857 #ifdef CONFIG_E1000_NAPI
861 flush_scheduled_work();
863 if(adapter
->hw
.mac_type
>= e1000_82540
&&
864 adapter
->hw
.media_type
== e1000_media_type_copper
) {
865 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
866 if(manc
& E1000_MANC_SMBUS_EN
) {
867 manc
|= E1000_MANC_ARP_EN
;
868 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
872 /* Release control of h/w to f/w. If f/w is AMT enabled, this
873 * would have already happened in close and is redundant. */
874 e1000_release_hw_control(adapter
);
876 unregister_netdev(netdev
);
877 #ifdef CONFIG_E1000_NAPI
878 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
879 __dev_put(&adapter
->polling_netdev
[i
]);
882 if(!e1000_check_phy_reset_block(&adapter
->hw
))
883 e1000_phy_hw_reset(&adapter
->hw
);
885 kfree(adapter
->tx_ring
);
886 kfree(adapter
->rx_ring
);
887 #ifdef CONFIG_E1000_NAPI
888 kfree(adapter
->polling_netdev
);
891 iounmap(adapter
->hw
.hw_addr
);
892 pci_release_regions(pdev
);
894 #ifdef CONFIG_E1000_MQ
895 free_percpu(adapter
->cpu_netdev
);
896 free_percpu(adapter
->cpu_tx_ring
);
900 pci_disable_device(pdev
);
904 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
905 * @adapter: board private structure to initialize
907 * e1000_sw_init initializes the Adapter private data structure.
908 * Fields are initialized based on PCI device information and
909 * OS network device settings (MTU size).
913 e1000_sw_init(struct e1000_adapter
*adapter
)
915 struct e1000_hw
*hw
= &adapter
->hw
;
916 struct net_device
*netdev
= adapter
->netdev
;
917 struct pci_dev
*pdev
= adapter
->pdev
;
918 #ifdef CONFIG_E1000_NAPI
922 /* PCI config space info */
924 hw
->vendor_id
= pdev
->vendor
;
925 hw
->device_id
= pdev
->device
;
926 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
927 hw
->subsystem_id
= pdev
->subsystem_device
;
929 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
931 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
933 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
934 adapter
->rx_ps_bsize0
= E1000_RXBUFFER_256
;
935 hw
->max_frame_size
= netdev
->mtu
+
936 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
937 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
939 /* identify the MAC */
941 if(e1000_set_mac_type(hw
)) {
942 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
946 /* initialize eeprom parameters */
948 if(e1000_init_eeprom_params(hw
)) {
949 E1000_ERR("EEPROM initialization failed\n");
953 switch(hw
->mac_type
) {
958 case e1000_82541_rev_2
:
959 case e1000_82547_rev_2
:
960 hw
->phy_init_script
= 1;
964 e1000_set_media_type(hw
);
966 hw
->wait_autoneg_complete
= FALSE
;
967 hw
->tbi_compatibility_en
= TRUE
;
968 hw
->adaptive_ifs
= TRUE
;
972 if(hw
->media_type
== e1000_media_type_copper
) {
973 hw
->mdix
= AUTO_ALL_MODES
;
974 hw
->disable_polarity_correction
= FALSE
;
975 hw
->master_slave
= E1000_MASTER_SLAVE
;
978 #ifdef CONFIG_E1000_MQ
979 /* Number of supported queues */
980 switch (hw
->mac_type
) {
983 /* These controllers support 2 tx queues, but with a single
984 * qdisc implementation, multiple tx queues aren't quite as
985 * interesting. If we can find a logical way of mapping
986 * flows to a queue, then perhaps we can up the num_tx_queue
987 * count back to its default. Until then, we run the risk of
988 * terrible performance due to SACK overload. */
989 adapter
->num_tx_queues
= 1;
990 adapter
->num_rx_queues
= 2;
993 adapter
->num_tx_queues
= 1;
994 adapter
->num_rx_queues
= 1;
997 adapter
->num_rx_queues
= min(adapter
->num_rx_queues
, num_online_cpus());
998 adapter
->num_tx_queues
= min(adapter
->num_tx_queues
, num_online_cpus());
999 DPRINTK(DRV
, INFO
, "Multiqueue Enabled: Rx Queue count = %u %s\n",
1000 adapter
->num_rx_queues
,
1001 ((adapter
->num_rx_queues
== 1)
1002 ? ((num_online_cpus() > 1)
1003 ? "(due to unsupported feature in current adapter)"
1004 : "(due to unsupported system configuration)")
1006 DPRINTK(DRV
, INFO
, "Multiqueue Enabled: Tx Queue count = %u\n",
1007 adapter
->num_tx_queues
);
1009 adapter
->num_tx_queues
= 1;
1010 adapter
->num_rx_queues
= 1;
1013 if (e1000_alloc_queues(adapter
)) {
1014 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
1018 #ifdef CONFIG_E1000_NAPI
1019 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1020 adapter
->polling_netdev
[i
].priv
= adapter
;
1021 adapter
->polling_netdev
[i
].poll
= &e1000_clean
;
1022 adapter
->polling_netdev
[i
].weight
= 64;
1023 dev_hold(&adapter
->polling_netdev
[i
]);
1024 set_bit(__LINK_STATE_START
, &adapter
->polling_netdev
[i
].state
);
1026 spin_lock_init(&adapter
->tx_queue_lock
);
1029 atomic_set(&adapter
->irq_sem
, 1);
1030 spin_lock_init(&adapter
->stats_lock
);
1036 * e1000_alloc_queues - Allocate memory for all rings
1037 * @adapter: board private structure to initialize
1039 * We allocate one ring per queue at run-time since we don't know the
1040 * number of queues at compile-time. The polling_netdev array is
1041 * intended for Multiqueue, but should work fine with a single queue.
1044 static int __devinit
1045 e1000_alloc_queues(struct e1000_adapter
*adapter
)
1049 size
= sizeof(struct e1000_tx_ring
) * adapter
->num_tx_queues
;
1050 adapter
->tx_ring
= kmalloc(size
, GFP_KERNEL
);
1051 if (!adapter
->tx_ring
)
1053 memset(adapter
->tx_ring
, 0, size
);
1055 size
= sizeof(struct e1000_rx_ring
) * adapter
->num_rx_queues
;
1056 adapter
->rx_ring
= kmalloc(size
, GFP_KERNEL
);
1057 if (!adapter
->rx_ring
) {
1058 kfree(adapter
->tx_ring
);
1061 memset(adapter
->rx_ring
, 0, size
);
1063 #ifdef CONFIG_E1000_NAPI
1064 size
= sizeof(struct net_device
) * adapter
->num_rx_queues
;
1065 adapter
->polling_netdev
= kmalloc(size
, GFP_KERNEL
);
1066 if (!adapter
->polling_netdev
) {
1067 kfree(adapter
->tx_ring
);
1068 kfree(adapter
->rx_ring
);
1071 memset(adapter
->polling_netdev
, 0, size
);
1074 #ifdef CONFIG_E1000_MQ
1075 adapter
->rx_sched_call_data
.func
= e1000_rx_schedule
;
1076 adapter
->rx_sched_call_data
.info
= adapter
->netdev
;
1078 adapter
->cpu_netdev
= alloc_percpu(struct net_device
*);
1079 adapter
->cpu_tx_ring
= alloc_percpu(struct e1000_tx_ring
*);
1082 return E1000_SUCCESS
;
1085 #ifdef CONFIG_E1000_MQ
1086 static void __devinit
1087 e1000_setup_queue_mapping(struct e1000_adapter
*adapter
)
1091 adapter
->rx_sched_call_data
.func
= e1000_rx_schedule
;
1092 adapter
->rx_sched_call_data
.info
= adapter
->netdev
;
1093 cpus_clear(adapter
->rx_sched_call_data
.cpumask
);
1095 adapter
->cpu_netdev
= alloc_percpu(struct net_device
*);
1096 adapter
->cpu_tx_ring
= alloc_percpu(struct e1000_tx_ring
*);
1100 for_each_online_cpu(cpu
) {
1101 *per_cpu_ptr(adapter
->cpu_tx_ring
, cpu
) = &adapter
->tx_ring
[i
% adapter
->num_tx_queues
];
1102 /* This is incomplete because we'd like to assign separate
1103 * physical cpus to these netdev polling structures and
1104 * avoid saturating a subset of cpus.
1106 if (i
< adapter
->num_rx_queues
) {
1107 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = &adapter
->polling_netdev
[i
];
1108 adapter
->rx_ring
[i
].cpu
= cpu
;
1109 cpu_set(cpu
, adapter
->cpumask
);
1111 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = NULL
;
1115 unlock_cpu_hotplug();
1120 * e1000_open - Called when a network interface is made active
1121 * @netdev: network interface device structure
1123 * Returns 0 on success, negative value on failure
1125 * The open entry point is called when a network interface is made
1126 * active by the system (IFF_UP). At this point all resources needed
1127 * for transmit and receive operations are allocated, the interrupt
1128 * handler is registered with the OS, the watchdog timer is started,
1129 * and the stack is notified that the interface is ready.
1133 e1000_open(struct net_device
*netdev
)
1135 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1138 /* allocate transmit descriptors */
1140 if ((err
= e1000_setup_all_tx_resources(adapter
)))
1143 /* allocate receive descriptors */
1145 if ((err
= e1000_setup_all_rx_resources(adapter
)))
1148 if((err
= e1000_up(adapter
)))
1150 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1151 if((adapter
->hw
.mng_cookie
.status
&
1152 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1153 e1000_update_mng_vlan(adapter
);
1156 /* If AMT is enabled, let the firmware know that the network
1157 * interface is now open */
1158 if (adapter
->hw
.mac_type
== e1000_82573
&&
1159 e1000_check_mng_mode(&adapter
->hw
))
1160 e1000_get_hw_control(adapter
);
1162 return E1000_SUCCESS
;
1165 e1000_free_all_rx_resources(adapter
);
1167 e1000_free_all_tx_resources(adapter
);
1169 e1000_reset(adapter
);
1175 * e1000_close - Disables a network interface
1176 * @netdev: network interface device structure
1178 * Returns 0, this is not allowed to fail
1180 * The close entry point is called when an interface is de-activated
1181 * by the OS. The hardware is still under the drivers control, but
1182 * needs to be disabled. A global MAC reset is issued to stop the
1183 * hardware, and all transmit and receive resources are freed.
1187 e1000_close(struct net_device
*netdev
)
1189 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1191 e1000_down(adapter
);
1193 e1000_free_all_tx_resources(adapter
);
1194 e1000_free_all_rx_resources(adapter
);
1196 if((adapter
->hw
.mng_cookie
.status
&
1197 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1198 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1201 /* If AMT is enabled, let the firmware know that the network
1202 * interface is now closed */
1203 if (adapter
->hw
.mac_type
== e1000_82573
&&
1204 e1000_check_mng_mode(&adapter
->hw
))
1205 e1000_release_hw_control(adapter
);
1211 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1212 * @adapter: address of board private structure
1213 * @start: address of beginning of memory
1214 * @len: length of memory
1216 static inline boolean_t
1217 e1000_check_64k_bound(struct e1000_adapter
*adapter
,
1218 void *start
, unsigned long len
)
1220 unsigned long begin
= (unsigned long) start
;
1221 unsigned long end
= begin
+ len
;
1223 /* First rev 82545 and 82546 need to not allow any memory
1224 * write location to cross 64k boundary due to errata 23 */
1225 if (adapter
->hw
.mac_type
== e1000_82545
||
1226 adapter
->hw
.mac_type
== e1000_82546
) {
1227 return ((begin
^ (end
- 1)) >> 16) != 0 ? FALSE
: TRUE
;
1234 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1235 * @adapter: board private structure
1236 * @txdr: tx descriptor ring (for a specific queue) to setup
1238 * Return 0 on success, negative on failure
1242 e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1243 struct e1000_tx_ring
*txdr
)
1245 struct pci_dev
*pdev
= adapter
->pdev
;
1248 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1250 txdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1251 if(!txdr
->buffer_info
) {
1253 "Unable to allocate memory for the transmit descriptor ring\n");
1256 memset(txdr
->buffer_info
, 0, size
);
1258 /* round up to nearest 4K */
1260 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1261 E1000_ROUNDUP(txdr
->size
, 4096);
1263 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1266 vfree(txdr
->buffer_info
);
1268 "Unable to allocate memory for the transmit descriptor ring\n");
1272 /* Fix for errata 23, can't cross 64kB boundary */
1273 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1274 void *olddesc
= txdr
->desc
;
1275 dma_addr_t olddma
= txdr
->dma
;
1276 DPRINTK(TX_ERR
, ERR
, "txdr align check failed: %u bytes "
1277 "at %p\n", txdr
->size
, txdr
->desc
);
1278 /* Try again, without freeing the previous */
1279 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1281 /* Failed allocation, critical failure */
1282 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1283 goto setup_tx_desc_die
;
1286 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1288 pci_free_consistent(pdev
, txdr
->size
, txdr
->desc
,
1290 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1292 "Unable to allocate aligned memory "
1293 "for the transmit descriptor ring\n");
1294 vfree(txdr
->buffer_info
);
1297 /* Free old allocation, new allocation was successful */
1298 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1301 memset(txdr
->desc
, 0, txdr
->size
);
1303 txdr
->next_to_use
= 0;
1304 txdr
->next_to_clean
= 0;
1305 spin_lock_init(&txdr
->tx_lock
);
1311 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1312 * (Descriptors) for all queues
1313 * @adapter: board private structure
1315 * If this function returns with an error, then it's possible one or
1316 * more of the rings is populated (while the rest are not). It is the
1317 * callers duty to clean those orphaned rings.
1319 * Return 0 on success, negative on failure
1323 e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1327 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1328 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1331 "Allocation for Tx Queue %u failed\n", i
);
1340 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1341 * @adapter: board private structure
1343 * Configure the Tx unit of the MAC after a reset.
1347 e1000_configure_tx(struct e1000_adapter
*adapter
)
1350 struct e1000_hw
*hw
= &adapter
->hw
;
1351 uint32_t tdlen
, tctl
, tipg
, tarc
;
1352 uint32_t ipgr1
, ipgr2
;
1354 /* Setup the HW Tx Head and Tail descriptor pointers */
1356 switch (adapter
->num_tx_queues
) {
1358 tdba
= adapter
->tx_ring
[1].dma
;
1359 tdlen
= adapter
->tx_ring
[1].count
*
1360 sizeof(struct e1000_tx_desc
);
1361 E1000_WRITE_REG(hw
, TDBAL1
, (tdba
& 0x00000000ffffffffULL
));
1362 E1000_WRITE_REG(hw
, TDBAH1
, (tdba
>> 32));
1363 E1000_WRITE_REG(hw
, TDLEN1
, tdlen
);
1364 E1000_WRITE_REG(hw
, TDH1
, 0);
1365 E1000_WRITE_REG(hw
, TDT1
, 0);
1366 adapter
->tx_ring
[1].tdh
= E1000_TDH1
;
1367 adapter
->tx_ring
[1].tdt
= E1000_TDT1
;
1371 tdba
= adapter
->tx_ring
[0].dma
;
1372 tdlen
= adapter
->tx_ring
[0].count
*
1373 sizeof(struct e1000_tx_desc
);
1374 E1000_WRITE_REG(hw
, TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1375 E1000_WRITE_REG(hw
, TDBAH
, (tdba
>> 32));
1376 E1000_WRITE_REG(hw
, TDLEN
, tdlen
);
1377 E1000_WRITE_REG(hw
, TDH
, 0);
1378 E1000_WRITE_REG(hw
, TDT
, 0);
1379 adapter
->tx_ring
[0].tdh
= E1000_TDH
;
1380 adapter
->tx_ring
[0].tdt
= E1000_TDT
;
1384 /* Set the default values for the Tx Inter Packet Gap timer */
1386 if (hw
->media_type
== e1000_media_type_fiber
||
1387 hw
->media_type
== e1000_media_type_internal_serdes
)
1388 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1390 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1392 switch (hw
->mac_type
) {
1393 case e1000_82542_rev2_0
:
1394 case e1000_82542_rev2_1
:
1395 tipg
= DEFAULT_82542_TIPG_IPGT
;
1396 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
1397 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
1400 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1401 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
1404 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1405 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1406 E1000_WRITE_REG(hw
, TIPG
, tipg
);
1408 /* Set the Tx Interrupt Delay register */
1410 E1000_WRITE_REG(hw
, TIDV
, adapter
->tx_int_delay
);
1411 if (hw
->mac_type
>= e1000_82540
)
1412 E1000_WRITE_REG(hw
, TADV
, adapter
->tx_abs_int_delay
);
1414 /* Program the Transmit Control Register */
1416 tctl
= E1000_READ_REG(hw
, TCTL
);
1418 tctl
&= ~E1000_TCTL_CT
;
1419 tctl
|= E1000_TCTL_EN
| E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1420 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1422 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1424 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
1425 tarc
= E1000_READ_REG(hw
, TARC0
);
1426 tarc
|= ((1 << 25) | (1 << 21));
1427 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1428 tarc
= E1000_READ_REG(hw
, TARC1
);
1430 if (tctl
& E1000_TCTL_MULR
)
1434 E1000_WRITE_REG(hw
, TARC1
, tarc
);
1437 e1000_config_collision_dist(hw
);
1439 /* Setup Transmit Descriptor Settings for eop descriptor */
1440 adapter
->txd_cmd
= E1000_TXD_CMD_IDE
| E1000_TXD_CMD_EOP
|
1443 if (hw
->mac_type
< e1000_82543
)
1444 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1446 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1448 /* Cache if we're 82544 running in PCI-X because we'll
1449 * need this to apply a workaround later in the send path. */
1450 if (hw
->mac_type
== e1000_82544
&&
1451 hw
->bus_type
== e1000_bus_type_pcix
)
1452 adapter
->pcix_82544
= 1;
1456 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1457 * @adapter: board private structure
1458 * @rxdr: rx descriptor ring (for a specific queue) to setup
1460 * Returns 0 on success, negative on failure
1464 e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1465 struct e1000_rx_ring
*rxdr
)
1467 struct pci_dev
*pdev
= adapter
->pdev
;
1470 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1471 rxdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1472 if (!rxdr
->buffer_info
) {
1474 "Unable to allocate memory for the receive descriptor ring\n");
1477 memset(rxdr
->buffer_info
, 0, size
);
1479 size
= sizeof(struct e1000_ps_page
) * rxdr
->count
;
1480 rxdr
->ps_page
= kmalloc(size
, GFP_KERNEL
);
1481 if(!rxdr
->ps_page
) {
1482 vfree(rxdr
->buffer_info
);
1484 "Unable to allocate memory for the receive descriptor ring\n");
1487 memset(rxdr
->ps_page
, 0, size
);
1489 size
= sizeof(struct e1000_ps_page_dma
) * rxdr
->count
;
1490 rxdr
->ps_page_dma
= kmalloc(size
, GFP_KERNEL
);
1491 if(!rxdr
->ps_page_dma
) {
1492 vfree(rxdr
->buffer_info
);
1493 kfree(rxdr
->ps_page
);
1495 "Unable to allocate memory for the receive descriptor ring\n");
1498 memset(rxdr
->ps_page_dma
, 0, size
);
1500 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
)
1501 desc_len
= sizeof(struct e1000_rx_desc
);
1503 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1505 /* Round up to nearest 4K */
1507 rxdr
->size
= rxdr
->count
* desc_len
;
1508 E1000_ROUNDUP(rxdr
->size
, 4096);
1510 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1514 "Unable to allocate memory for the receive descriptor ring\n");
1516 vfree(rxdr
->buffer_info
);
1517 kfree(rxdr
->ps_page
);
1518 kfree(rxdr
->ps_page_dma
);
1522 /* Fix for errata 23, can't cross 64kB boundary */
1523 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1524 void *olddesc
= rxdr
->desc
;
1525 dma_addr_t olddma
= rxdr
->dma
;
1526 DPRINTK(RX_ERR
, ERR
, "rxdr align check failed: %u bytes "
1527 "at %p\n", rxdr
->size
, rxdr
->desc
);
1528 /* Try again, without freeing the previous */
1529 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1530 /* Failed allocation, critical failure */
1532 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1534 "Unable to allocate memory "
1535 "for the receive descriptor ring\n");
1536 goto setup_rx_desc_die
;
1539 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1541 pci_free_consistent(pdev
, rxdr
->size
, rxdr
->desc
,
1543 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1545 "Unable to allocate aligned memory "
1546 "for the receive descriptor ring\n");
1547 goto setup_rx_desc_die
;
1549 /* Free old allocation, new allocation was successful */
1550 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1553 memset(rxdr
->desc
, 0, rxdr
->size
);
1555 rxdr
->next_to_clean
= 0;
1556 rxdr
->next_to_use
= 0;
1557 rxdr
->rx_skb_top
= NULL
;
1558 rxdr
->rx_skb_prev
= NULL
;
1564 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1565 * (Descriptors) for all queues
1566 * @adapter: board private structure
1568 * If this function returns with an error, then it's possible one or
1569 * more of the rings is populated (while the rest are not). It is the
1570 * callers duty to clean those orphaned rings.
1572 * Return 0 on success, negative on failure
1576 e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1580 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1581 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1584 "Allocation for Rx Queue %u failed\n", i
);
1593 * e1000_setup_rctl - configure the receive control registers
1594 * @adapter: Board private structure
1596 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1597 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1599 e1000_setup_rctl(struct e1000_adapter
*adapter
)
1601 uint32_t rctl
, rfctl
;
1602 uint32_t psrctl
= 0;
1603 #ifdef CONFIG_E1000_PACKET_SPLIT
1607 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1609 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1611 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1612 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1613 (adapter
->hw
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1615 if (adapter
->hw
.mac_type
> e1000_82543
)
1616 rctl
|= E1000_RCTL_SECRC
;
1618 if (adapter
->hw
.tbi_compatibility_on
== 1)
1619 rctl
|= E1000_RCTL_SBP
;
1621 rctl
&= ~E1000_RCTL_SBP
;
1623 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1624 rctl
&= ~E1000_RCTL_LPE
;
1626 rctl
|= E1000_RCTL_LPE
;
1628 /* Setup buffer sizes */
1629 if(adapter
->hw
.mac_type
>= e1000_82571
) {
1630 /* We can now specify buffers in 1K increments.
1631 * BSIZE and BSEX are ignored in this case. */
1632 rctl
|= adapter
->rx_buffer_len
<< 0x11;
1634 rctl
&= ~E1000_RCTL_SZ_4096
;
1635 rctl
|= E1000_RCTL_BSEX
;
1636 switch (adapter
->rx_buffer_len
) {
1637 case E1000_RXBUFFER_2048
:
1639 rctl
|= E1000_RCTL_SZ_2048
;
1640 rctl
&= ~E1000_RCTL_BSEX
;
1642 case E1000_RXBUFFER_4096
:
1643 rctl
|= E1000_RCTL_SZ_4096
;
1645 case E1000_RXBUFFER_8192
:
1646 rctl
|= E1000_RCTL_SZ_8192
;
1648 case E1000_RXBUFFER_16384
:
1649 rctl
|= E1000_RCTL_SZ_16384
;
1654 #ifdef CONFIG_E1000_PACKET_SPLIT
1655 /* 82571 and greater support packet-split where the protocol
1656 * header is placed in skb->data and the packet data is
1657 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1658 * In the case of a non-split, skb->data is linearly filled,
1659 * followed by the page buffers. Therefore, skb->data is
1660 * sized to hold the largest protocol header.
1662 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
1663 if ((adapter
->hw
.mac_type
> e1000_82547_rev_2
) && (pages
<= 3) &&
1665 adapter
->rx_ps_pages
= pages
;
1667 adapter
->rx_ps_pages
= 0;
1669 if (adapter
->rx_ps_pages
) {
1670 /* Configure extra packet-split registers */
1671 rfctl
= E1000_READ_REG(&adapter
->hw
, RFCTL
);
1672 rfctl
|= E1000_RFCTL_EXTEN
;
1673 /* disable IPv6 packet split support */
1674 rfctl
|= E1000_RFCTL_IPV6_DIS
;
1675 E1000_WRITE_REG(&adapter
->hw
, RFCTL
, rfctl
);
1677 rctl
|= E1000_RCTL_DTYP_PS
| E1000_RCTL_SECRC
;
1679 psrctl
|= adapter
->rx_ps_bsize0
>>
1680 E1000_PSRCTL_BSIZE0_SHIFT
;
1682 switch (adapter
->rx_ps_pages
) {
1684 psrctl
|= PAGE_SIZE
<<
1685 E1000_PSRCTL_BSIZE3_SHIFT
;
1687 psrctl
|= PAGE_SIZE
<<
1688 E1000_PSRCTL_BSIZE2_SHIFT
;
1690 psrctl
|= PAGE_SIZE
>>
1691 E1000_PSRCTL_BSIZE1_SHIFT
;
1695 E1000_WRITE_REG(&adapter
->hw
, PSRCTL
, psrctl
);
1698 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1702 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1703 * @adapter: board private structure
1705 * Configure the Rx unit of the MAC after a reset.
1709 e1000_configure_rx(struct e1000_adapter
*adapter
)
1712 struct e1000_hw
*hw
= &adapter
->hw
;
1713 uint32_t rdlen
, rctl
, rxcsum
, ctrl_ext
;
1714 #ifdef CONFIG_E1000_MQ
1715 uint32_t reta
, mrqc
;
1719 if (adapter
->rx_ps_pages
) {
1720 rdlen
= adapter
->rx_ring
[0].count
*
1721 sizeof(union e1000_rx_desc_packet_split
);
1722 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
1723 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
1725 rdlen
= adapter
->rx_ring
[0].count
*
1726 sizeof(struct e1000_rx_desc
);
1727 adapter
->clean_rx
= e1000_clean_rx_irq
;
1728 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1731 /* disable receives while setting up the descriptors */
1732 rctl
= E1000_READ_REG(hw
, RCTL
);
1733 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
1735 /* set the Receive Delay Timer Register */
1736 E1000_WRITE_REG(hw
, RDTR
, adapter
->rx_int_delay
);
1738 if (hw
->mac_type
>= e1000_82540
) {
1739 E1000_WRITE_REG(hw
, RADV
, adapter
->rx_abs_int_delay
);
1740 if(adapter
->itr
> 1)
1741 E1000_WRITE_REG(hw
, ITR
,
1742 1000000000 / (adapter
->itr
* 256));
1745 if (hw
->mac_type
>= e1000_82571
) {
1746 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1747 /* Reset delay timers after every interrupt */
1748 ctrl_ext
|= E1000_CTRL_EXT_CANC
;
1749 #ifdef CONFIG_E1000_NAPI
1750 /* Auto-Mask interrupts upon ICR read. */
1751 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
1753 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
1754 E1000_WRITE_REG(hw
, IAM
, ~0);
1755 E1000_WRITE_FLUSH(hw
);
1758 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1759 * the Base and Length of the Rx Descriptor Ring */
1760 switch (adapter
->num_rx_queues
) {
1761 #ifdef CONFIG_E1000_MQ
1763 rdba
= adapter
->rx_ring
[1].dma
;
1764 E1000_WRITE_REG(hw
, RDBAL1
, (rdba
& 0x00000000ffffffffULL
));
1765 E1000_WRITE_REG(hw
, RDBAH1
, (rdba
>> 32));
1766 E1000_WRITE_REG(hw
, RDLEN1
, rdlen
);
1767 E1000_WRITE_REG(hw
, RDH1
, 0);
1768 E1000_WRITE_REG(hw
, RDT1
, 0);
1769 adapter
->rx_ring
[1].rdh
= E1000_RDH1
;
1770 adapter
->rx_ring
[1].rdt
= E1000_RDT1
;
1775 rdba
= adapter
->rx_ring
[0].dma
;
1776 E1000_WRITE_REG(hw
, RDBAL
, (rdba
& 0x00000000ffffffffULL
));
1777 E1000_WRITE_REG(hw
, RDBAH
, (rdba
>> 32));
1778 E1000_WRITE_REG(hw
, RDLEN
, rdlen
);
1779 E1000_WRITE_REG(hw
, RDH
, 0);
1780 E1000_WRITE_REG(hw
, RDT
, 0);
1781 adapter
->rx_ring
[0].rdh
= E1000_RDH
;
1782 adapter
->rx_ring
[0].rdt
= E1000_RDT
;
1786 #ifdef CONFIG_E1000_MQ
1787 if (adapter
->num_rx_queues
> 1) {
1788 uint32_t random
[10];
1790 get_random_bytes(&random
[0], 40);
1792 if (hw
->mac_type
<= e1000_82572
) {
1793 E1000_WRITE_REG(hw
, RSSIR
, 0);
1794 E1000_WRITE_REG(hw
, RSSIM
, 0);
1797 switch (adapter
->num_rx_queues
) {
1801 mrqc
= E1000_MRQC_ENABLE_RSS_2Q
;
1805 /* Fill out redirection table */
1806 for (i
= 0; i
< 32; i
++)
1807 E1000_WRITE_REG_ARRAY(hw
, RETA
, i
, reta
);
1808 /* Fill out hash function seeds */
1809 for (i
= 0; i
< 10; i
++)
1810 E1000_WRITE_REG_ARRAY(hw
, RSSRK
, i
, random
[i
]);
1812 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4
|
1813 E1000_MRQC_RSS_FIELD_IPV4_TCP
);
1814 E1000_WRITE_REG(hw
, MRQC
, mrqc
);
1817 /* Multiqueue and packet checksumming are mutually exclusive. */
1818 if (hw
->mac_type
>= e1000_82571
) {
1819 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1820 rxcsum
|= E1000_RXCSUM_PCSD
;
1821 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1826 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1827 if (hw
->mac_type
>= e1000_82543
) {
1828 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1829 if(adapter
->rx_csum
== TRUE
) {
1830 rxcsum
|= E1000_RXCSUM_TUOFL
;
1832 /* Enable 82571 IPv4 payload checksum for UDP fragments
1833 * Must be used in conjunction with packet-split. */
1834 if ((hw
->mac_type
>= e1000_82571
) &&
1835 (adapter
->rx_ps_pages
)) {
1836 rxcsum
|= E1000_RXCSUM_IPPCSE
;
1839 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1840 /* don't need to clear IPPCSE as it defaults to 0 */
1842 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1844 #endif /* CONFIG_E1000_MQ */
1846 if (hw
->mac_type
== e1000_82573
)
1847 E1000_WRITE_REG(hw
, ERT
, 0x0100);
1849 /* Enable Receives */
1850 E1000_WRITE_REG(hw
, RCTL
, rctl
);
1854 * e1000_free_tx_resources - Free Tx Resources per Queue
1855 * @adapter: board private structure
1856 * @tx_ring: Tx descriptor ring for a specific queue
1858 * Free all transmit software resources
1862 e1000_free_tx_resources(struct e1000_adapter
*adapter
,
1863 struct e1000_tx_ring
*tx_ring
)
1865 struct pci_dev
*pdev
= adapter
->pdev
;
1867 e1000_clean_tx_ring(adapter
, tx_ring
);
1869 vfree(tx_ring
->buffer_info
);
1870 tx_ring
->buffer_info
= NULL
;
1872 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
1874 tx_ring
->desc
= NULL
;
1878 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1879 * @adapter: board private structure
1881 * Free all transmit software resources
1885 e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
1889 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1890 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1894 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
1895 struct e1000_buffer
*buffer_info
)
1897 if(buffer_info
->dma
) {
1898 pci_unmap_page(adapter
->pdev
,
1900 buffer_info
->length
,
1902 buffer_info
->dma
= 0;
1904 if(buffer_info
->skb
) {
1905 dev_kfree_skb_any(buffer_info
->skb
);
1906 buffer_info
->skb
= NULL
;
1911 * e1000_clean_tx_ring - Free Tx Buffers
1912 * @adapter: board private structure
1913 * @tx_ring: ring to be cleaned
1917 e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
1918 struct e1000_tx_ring
*tx_ring
)
1920 struct e1000_buffer
*buffer_info
;
1924 /* Free all the Tx ring sk_buffs */
1926 for(i
= 0; i
< tx_ring
->count
; i
++) {
1927 buffer_info
= &tx_ring
->buffer_info
[i
];
1928 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
1931 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1932 memset(tx_ring
->buffer_info
, 0, size
);
1934 /* Zero out the descriptor ring */
1936 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1938 tx_ring
->next_to_use
= 0;
1939 tx_ring
->next_to_clean
= 0;
1940 tx_ring
->last_tx_tso
= 0;
1942 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdh
);
1943 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
1947 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1948 * @adapter: board private structure
1952 e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
1956 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1957 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1961 * e1000_free_rx_resources - Free Rx Resources
1962 * @adapter: board private structure
1963 * @rx_ring: ring to clean the resources from
1965 * Free all receive software resources
1969 e1000_free_rx_resources(struct e1000_adapter
*adapter
,
1970 struct e1000_rx_ring
*rx_ring
)
1972 struct pci_dev
*pdev
= adapter
->pdev
;
1974 e1000_clean_rx_ring(adapter
, rx_ring
);
1976 vfree(rx_ring
->buffer_info
);
1977 rx_ring
->buffer_info
= NULL
;
1978 kfree(rx_ring
->ps_page
);
1979 rx_ring
->ps_page
= NULL
;
1980 kfree(rx_ring
->ps_page_dma
);
1981 rx_ring
->ps_page_dma
= NULL
;
1983 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
1985 rx_ring
->desc
= NULL
;
1989 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1990 * @adapter: board private structure
1992 * Free all receive software resources
1996 e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
2000 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2001 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2005 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2006 * @adapter: board private structure
2007 * @rx_ring: ring to free buffers from
2011 e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
2012 struct e1000_rx_ring
*rx_ring
)
2014 struct e1000_buffer
*buffer_info
;
2015 struct e1000_ps_page
*ps_page
;
2016 struct e1000_ps_page_dma
*ps_page_dma
;
2017 struct pci_dev
*pdev
= adapter
->pdev
;
2021 /* Free all the Rx ring sk_buffs */
2023 for(i
= 0; i
< rx_ring
->count
; i
++) {
2024 buffer_info
= &rx_ring
->buffer_info
[i
];
2025 if(buffer_info
->skb
) {
2026 ps_page
= &rx_ring
->ps_page
[i
];
2027 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2028 pci_unmap_single(pdev
,
2030 buffer_info
->length
,
2031 PCI_DMA_FROMDEVICE
);
2033 dev_kfree_skb(buffer_info
->skb
);
2034 buffer_info
->skb
= NULL
;
2036 ps_page
= &rx_ring
->ps_page
[i
];
2037 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2038 for (j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
2039 if (!ps_page
->ps_page
[j
]) break;
2040 pci_unmap_page(pdev
,
2041 ps_page_dma
->ps_page_dma
[j
],
2042 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
2043 ps_page_dma
->ps_page_dma
[j
] = 0;
2044 put_page(ps_page
->ps_page
[j
]);
2045 ps_page
->ps_page
[j
] = NULL
;
2049 /* there also may be some cached data in our adapter */
2050 if (rx_ring
->rx_skb_top
) {
2051 dev_kfree_skb(rx_ring
->rx_skb_top
);
2053 /* rx_skb_prev will be wiped out by rx_skb_top */
2054 rx_ring
->rx_skb_top
= NULL
;
2055 rx_ring
->rx_skb_prev
= NULL
;
2059 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2060 memset(rx_ring
->buffer_info
, 0, size
);
2061 size
= sizeof(struct e1000_ps_page
) * rx_ring
->count
;
2062 memset(rx_ring
->ps_page
, 0, size
);
2063 size
= sizeof(struct e1000_ps_page_dma
) * rx_ring
->count
;
2064 memset(rx_ring
->ps_page_dma
, 0, size
);
2066 /* Zero out the descriptor ring */
2068 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2070 rx_ring
->next_to_clean
= 0;
2071 rx_ring
->next_to_use
= 0;
2073 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdh
);
2074 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
2078 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2079 * @adapter: board private structure
2083 e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2087 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2088 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2091 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2092 * and memory write and invalidate disabled for certain operations
2095 e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2097 struct net_device
*netdev
= adapter
->netdev
;
2100 e1000_pci_clear_mwi(&adapter
->hw
);
2102 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2103 rctl
|= E1000_RCTL_RST
;
2104 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2105 E1000_WRITE_FLUSH(&adapter
->hw
);
2108 if(netif_running(netdev
))
2109 e1000_clean_all_rx_rings(adapter
);
2113 e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2115 struct net_device
*netdev
= adapter
->netdev
;
2118 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2119 rctl
&= ~E1000_RCTL_RST
;
2120 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2121 E1000_WRITE_FLUSH(&adapter
->hw
);
2124 if(adapter
->hw
.pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2125 e1000_pci_set_mwi(&adapter
->hw
);
2127 if(netif_running(netdev
)) {
2128 e1000_configure_rx(adapter
);
2129 /* No need to loop, because 82542 supports only 1 queue */
2130 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[0];
2131 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
2136 * e1000_set_mac - Change the Ethernet Address of the NIC
2137 * @netdev: network interface device structure
2138 * @p: pointer to an address structure
2140 * Returns 0 on success, negative on failure
2144 e1000_set_mac(struct net_device
*netdev
, void *p
)
2146 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2147 struct sockaddr
*addr
= p
;
2149 if(!is_valid_ether_addr(addr
->sa_data
))
2150 return -EADDRNOTAVAIL
;
2152 /* 82542 2.0 needs to be in reset to write receive address registers */
2154 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2155 e1000_enter_82542_rst(adapter
);
2157 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2158 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2160 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2162 /* With 82571 controllers, LAA may be overwritten (with the default)
2163 * due to controller reset from the other port. */
2164 if (adapter
->hw
.mac_type
== e1000_82571
) {
2165 /* activate the work around */
2166 adapter
->hw
.laa_is_present
= 1;
2168 /* Hold a copy of the LAA in RAR[14] This is done so that
2169 * between the time RAR[0] gets clobbered and the time it
2170 * gets fixed (in e1000_watchdog), the actual LAA is in one
2171 * of the RARs and no incoming packets directed to this port
2172 * are dropped. Eventaully the LAA will be in RAR[0] and
2174 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
,
2175 E1000_RAR_ENTRIES
- 1);
2178 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2179 e1000_leave_82542_rst(adapter
);
2185 * e1000_set_multi - Multicast and Promiscuous mode set
2186 * @netdev: network interface device structure
2188 * The set_multi entry point is called whenever the multicast address
2189 * list or the network interface flags are updated. This routine is
2190 * responsible for configuring the hardware for proper multicast,
2191 * promiscuous mode, and all-multi behavior.
2195 e1000_set_multi(struct net_device
*netdev
)
2197 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2198 struct e1000_hw
*hw
= &adapter
->hw
;
2199 struct dev_mc_list
*mc_ptr
;
2201 uint32_t hash_value
;
2202 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2204 /* reserve RAR[14] for LAA over-write work-around */
2205 if (adapter
->hw
.mac_type
== e1000_82571
)
2208 /* Check for Promiscuous and All Multicast modes */
2210 rctl
= E1000_READ_REG(hw
, RCTL
);
2212 if(netdev
->flags
& IFF_PROMISC
) {
2213 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2214 } else if(netdev
->flags
& IFF_ALLMULTI
) {
2215 rctl
|= E1000_RCTL_MPE
;
2216 rctl
&= ~E1000_RCTL_UPE
;
2218 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2221 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2223 /* 82542 2.0 needs to be in reset to write receive address registers */
2225 if(hw
->mac_type
== e1000_82542_rev2_0
)
2226 e1000_enter_82542_rst(adapter
);
2228 /* load the first 14 multicast address into the exact filters 1-14
2229 * RAR 0 is used for the station MAC adddress
2230 * if there are not 14 addresses, go ahead and clear the filters
2231 * -- with 82571 controllers only 0-13 entries are filled here
2233 mc_ptr
= netdev
->mc_list
;
2235 for(i
= 1; i
< rar_entries
; i
++) {
2237 e1000_rar_set(hw
, mc_ptr
->dmi_addr
, i
);
2238 mc_ptr
= mc_ptr
->next
;
2240 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2241 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2245 /* clear the old settings from the multicast hash table */
2247 for(i
= 0; i
< E1000_NUM_MTA_REGISTERS
; i
++)
2248 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
2250 /* load any remaining addresses into the hash table */
2252 for(; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
2253 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->dmi_addr
);
2254 e1000_mta_set(hw
, hash_value
);
2257 if(hw
->mac_type
== e1000_82542_rev2_0
)
2258 e1000_leave_82542_rst(adapter
);
2261 /* Need to wait a few seconds after link up to get diagnostic information from
2265 e1000_update_phy_info(unsigned long data
)
2267 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2268 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
2272 * e1000_82547_tx_fifo_stall - Timer Call-back
2273 * @data: pointer to adapter cast into an unsigned long
2277 e1000_82547_tx_fifo_stall(unsigned long data
)
2279 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2280 struct net_device
*netdev
= adapter
->netdev
;
2283 if(atomic_read(&adapter
->tx_fifo_stall
)) {
2284 if((E1000_READ_REG(&adapter
->hw
, TDT
) ==
2285 E1000_READ_REG(&adapter
->hw
, TDH
)) &&
2286 (E1000_READ_REG(&adapter
->hw
, TDFT
) ==
2287 E1000_READ_REG(&adapter
->hw
, TDFH
)) &&
2288 (E1000_READ_REG(&adapter
->hw
, TDFTS
) ==
2289 E1000_READ_REG(&adapter
->hw
, TDFHS
))) {
2290 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2291 E1000_WRITE_REG(&adapter
->hw
, TCTL
,
2292 tctl
& ~E1000_TCTL_EN
);
2293 E1000_WRITE_REG(&adapter
->hw
, TDFT
,
2294 adapter
->tx_head_addr
);
2295 E1000_WRITE_REG(&adapter
->hw
, TDFH
,
2296 adapter
->tx_head_addr
);
2297 E1000_WRITE_REG(&adapter
->hw
, TDFTS
,
2298 adapter
->tx_head_addr
);
2299 E1000_WRITE_REG(&adapter
->hw
, TDFHS
,
2300 adapter
->tx_head_addr
);
2301 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2302 E1000_WRITE_FLUSH(&adapter
->hw
);
2304 adapter
->tx_fifo_head
= 0;
2305 atomic_set(&adapter
->tx_fifo_stall
, 0);
2306 netif_wake_queue(netdev
);
2308 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2314 * e1000_watchdog - Timer Call-back
2315 * @data: pointer to adapter cast into an unsigned long
2318 e1000_watchdog(unsigned long data
)
2320 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2322 /* Do the rest outside of interrupt context */
2323 schedule_work(&adapter
->watchdog_task
);
2327 e1000_watchdog_task(struct e1000_adapter
*adapter
)
2329 struct net_device
*netdev
= adapter
->netdev
;
2330 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2333 e1000_check_for_link(&adapter
->hw
);
2334 if (adapter
->hw
.mac_type
== e1000_82573
) {
2335 e1000_enable_tx_pkt_filtering(&adapter
->hw
);
2336 if(adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
)
2337 e1000_update_mng_vlan(adapter
);
2340 if((adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) &&
2341 !(E1000_READ_REG(&adapter
->hw
, TXCW
) & E1000_TXCW_ANE
))
2342 link
= !adapter
->hw
.serdes_link_down
;
2344 link
= E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_LU
;
2347 if(!netif_carrier_ok(netdev
)) {
2348 e1000_get_speed_and_duplex(&adapter
->hw
,
2349 &adapter
->link_speed
,
2350 &adapter
->link_duplex
);
2352 DPRINTK(LINK
, INFO
, "NIC Link is Up %d Mbps %s\n",
2353 adapter
->link_speed
,
2354 adapter
->link_duplex
== FULL_DUPLEX
?
2355 "Full Duplex" : "Half Duplex");
2357 /* tweak tx_queue_len according to speed/duplex */
2358 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2359 adapter
->tx_timeout_factor
= 1;
2360 if (adapter
->link_duplex
== HALF_DUPLEX
) {
2361 switch (adapter
->link_speed
) {
2363 netdev
->tx_queue_len
= 10;
2364 adapter
->tx_timeout_factor
= 8;
2367 netdev
->tx_queue_len
= 100;
2372 netif_carrier_on(netdev
);
2373 netif_wake_queue(netdev
);
2374 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2375 adapter
->smartspeed
= 0;
2378 if(netif_carrier_ok(netdev
)) {
2379 adapter
->link_speed
= 0;
2380 adapter
->link_duplex
= 0;
2381 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
2382 netif_carrier_off(netdev
);
2383 netif_stop_queue(netdev
);
2384 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2387 e1000_smartspeed(adapter
);
2390 e1000_update_stats(adapter
);
2392 adapter
->hw
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2393 adapter
->tpt_old
= adapter
->stats
.tpt
;
2394 adapter
->hw
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2395 adapter
->colc_old
= adapter
->stats
.colc
;
2397 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2398 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2399 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2400 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2402 e1000_update_adaptive(&adapter
->hw
);
2404 #ifdef CONFIG_E1000_MQ
2405 txdr
= *per_cpu_ptr(adapter
->cpu_tx_ring
, smp_processor_id());
2407 if (!netif_carrier_ok(netdev
)) {
2408 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2409 /* We've lost link, so the controller stops DMA,
2410 * but we've got queued Tx work that's never going
2411 * to get done, so reset controller to flush Tx.
2412 * (Do the reset outside of interrupt context). */
2413 schedule_work(&adapter
->tx_timeout_task
);
2417 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2418 if(adapter
->hw
.mac_type
>= e1000_82540
&& adapter
->itr
== 1) {
2419 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2420 * asymmetrical Tx or Rx gets ITR=8000; everyone
2421 * else is between 2000-8000. */
2422 uint32_t goc
= (adapter
->gotcl
+ adapter
->gorcl
) / 10000;
2423 uint32_t dif
= (adapter
->gotcl
> adapter
->gorcl
?
2424 adapter
->gotcl
- adapter
->gorcl
:
2425 adapter
->gorcl
- adapter
->gotcl
) / 10000;
2426 uint32_t itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
2427 E1000_WRITE_REG(&adapter
->hw
, ITR
, 1000000000 / (itr
* 256));
2430 /* Cause software interrupt to ensure rx ring is cleaned */
2431 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_RXDMT0
);
2433 /* Force detection of hung controller every watchdog period */
2434 adapter
->detect_tx_hung
= TRUE
;
2436 /* With 82571 controllers, LAA may be overwritten due to controller
2437 * reset from the other port. Set the appropriate LAA in RAR[0] */
2438 if (adapter
->hw
.mac_type
== e1000_82571
&& adapter
->hw
.laa_is_present
)
2439 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2441 /* Reset the timer */
2442 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2 * HZ
);
2445 #define E1000_TX_FLAGS_CSUM 0x00000001
2446 #define E1000_TX_FLAGS_VLAN 0x00000002
2447 #define E1000_TX_FLAGS_TSO 0x00000004
2448 #define E1000_TX_FLAGS_IPV4 0x00000008
2449 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2450 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2453 e1000_tso(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2454 struct sk_buff
*skb
)
2457 struct e1000_context_desc
*context_desc
;
2458 struct e1000_buffer
*buffer_info
;
2460 uint32_t cmd_length
= 0;
2461 uint16_t ipcse
= 0, tucse
, mss
;
2462 uint8_t ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2465 if(skb_shinfo(skb
)->tso_size
) {
2466 if (skb_header_cloned(skb
)) {
2467 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2472 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2473 mss
= skb_shinfo(skb
)->tso_size
;
2474 if(skb
->protocol
== ntohs(ETH_P_IP
)) {
2475 skb
->nh
.iph
->tot_len
= 0;
2476 skb
->nh
.iph
->check
= 0;
2478 ~csum_tcpudp_magic(skb
->nh
.iph
->saddr
,
2483 cmd_length
= E1000_TXD_CMD_IP
;
2484 ipcse
= skb
->h
.raw
- skb
->data
- 1;
2485 #ifdef NETIF_F_TSO_IPV6
2486 } else if(skb
->protocol
== ntohs(ETH_P_IPV6
)) {
2487 skb
->nh
.ipv6h
->payload_len
= 0;
2489 ~csum_ipv6_magic(&skb
->nh
.ipv6h
->saddr
,
2490 &skb
->nh
.ipv6h
->daddr
,
2497 ipcss
= skb
->nh
.raw
- skb
->data
;
2498 ipcso
= (void *)&(skb
->nh
.iph
->check
) - (void *)skb
->data
;
2499 tucss
= skb
->h
.raw
- skb
->data
;
2500 tucso
= (void *)&(skb
->h
.th
->check
) - (void *)skb
->data
;
2503 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2504 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2506 i
= tx_ring
->next_to_use
;
2507 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2508 buffer_info
= &tx_ring
->buffer_info
[i
];
2510 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2511 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2512 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2513 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2514 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2515 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2516 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2517 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2518 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2520 buffer_info
->time_stamp
= jiffies
;
2522 if (++i
== tx_ring
->count
) i
= 0;
2523 tx_ring
->next_to_use
= i
;
2532 static inline boolean_t
2533 e1000_tx_csum(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2534 struct sk_buff
*skb
)
2536 struct e1000_context_desc
*context_desc
;
2537 struct e1000_buffer
*buffer_info
;
2541 if(likely(skb
->ip_summed
== CHECKSUM_HW
)) {
2542 css
= skb
->h
.raw
- skb
->data
;
2544 i
= tx_ring
->next_to_use
;
2545 buffer_info
= &tx_ring
->buffer_info
[i
];
2546 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2548 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2549 context_desc
->upper_setup
.tcp_fields
.tucso
= css
+ skb
->csum
;
2550 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2551 context_desc
->tcp_seg_setup
.data
= 0;
2552 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
2554 buffer_info
->time_stamp
= jiffies
;
2556 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2557 tx_ring
->next_to_use
= i
;
2565 #define E1000_MAX_TXD_PWR 12
2566 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2569 e1000_tx_map(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2570 struct sk_buff
*skb
, unsigned int first
, unsigned int max_per_txd
,
2571 unsigned int nr_frags
, unsigned int mss
)
2573 struct e1000_buffer
*buffer_info
;
2574 unsigned int len
= skb
->len
;
2575 unsigned int offset
= 0, size
, count
= 0, i
;
2577 len
-= skb
->data_len
;
2579 i
= tx_ring
->next_to_use
;
2582 buffer_info
= &tx_ring
->buffer_info
[i
];
2583 size
= min(len
, max_per_txd
);
2585 /* Workaround for Controller erratum --
2586 * descriptor for non-tso packet in a linear SKB that follows a
2587 * tso gets written back prematurely before the data is fully
2588 * DMAd to the controller */
2589 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2590 !skb_shinfo(skb
)->tso_size
) {
2591 tx_ring
->last_tx_tso
= 0;
2595 /* Workaround for premature desc write-backs
2596 * in TSO mode. Append 4-byte sentinel desc */
2597 if(unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
2600 /* work-around for errata 10 and it applies
2601 * to all controllers in PCI-X mode
2602 * The fix is to make sure that the first descriptor of a
2603 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2605 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2606 (size
> 2015) && count
== 0))
2609 /* Workaround for potential 82544 hang in PCI-X. Avoid
2610 * terminating buffers within evenly-aligned dwords. */
2611 if(unlikely(adapter
->pcix_82544
&&
2612 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
2616 buffer_info
->length
= size
;
2618 pci_map_single(adapter
->pdev
,
2622 buffer_info
->time_stamp
= jiffies
;
2627 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2630 for(f
= 0; f
< nr_frags
; f
++) {
2631 struct skb_frag_struct
*frag
;
2633 frag
= &skb_shinfo(skb
)->frags
[f
];
2635 offset
= frag
->page_offset
;
2638 buffer_info
= &tx_ring
->buffer_info
[i
];
2639 size
= min(len
, max_per_txd
);
2641 /* Workaround for premature desc write-backs
2642 * in TSO mode. Append 4-byte sentinel desc */
2643 if(unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
2646 /* Workaround for potential 82544 hang in PCI-X.
2647 * Avoid terminating buffers within evenly-aligned
2649 if(unlikely(adapter
->pcix_82544
&&
2650 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
2654 buffer_info
->length
= size
;
2656 pci_map_page(adapter
->pdev
,
2661 buffer_info
->time_stamp
= jiffies
;
2666 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2670 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
2671 tx_ring
->buffer_info
[i
].skb
= skb
;
2672 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
2678 e1000_tx_queue(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2679 int tx_flags
, int count
)
2681 struct e1000_tx_desc
*tx_desc
= NULL
;
2682 struct e1000_buffer
*buffer_info
;
2683 uint32_t txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
2686 if(likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
2687 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
2689 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2691 if(likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
2692 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
2695 if(likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
2696 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
2697 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2700 if(unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
2701 txd_lower
|= E1000_TXD_CMD_VLE
;
2702 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
2705 i
= tx_ring
->next_to_use
;
2708 buffer_info
= &tx_ring
->buffer_info
[i
];
2709 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
2710 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2711 tx_desc
->lower
.data
=
2712 cpu_to_le32(txd_lower
| buffer_info
->length
);
2713 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
2714 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2717 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
2719 /* Force memory writes to complete before letting h/w
2720 * know there are new descriptors to fetch. (Only
2721 * applicable for weak-ordered memory model archs,
2722 * such as IA-64). */
2725 tx_ring
->next_to_use
= i
;
2726 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
2730 * 82547 workaround to avoid controller hang in half-duplex environment.
2731 * The workaround is to avoid queuing a large packet that would span
2732 * the internal Tx FIFO ring boundary by notifying the stack to resend
2733 * the packet at a later time. This gives the Tx FIFO an opportunity to
2734 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2735 * to the beginning of the Tx FIFO.
2738 #define E1000_FIFO_HDR 0x10
2739 #define E1000_82547_PAD_LEN 0x3E0
2742 e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2744 uint32_t fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
2745 uint32_t skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
2747 E1000_ROUNDUP(skb_fifo_len
, E1000_FIFO_HDR
);
2749 if(adapter
->link_duplex
!= HALF_DUPLEX
)
2750 goto no_fifo_stall_required
;
2752 if(atomic_read(&adapter
->tx_fifo_stall
))
2755 if(skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
2756 atomic_set(&adapter
->tx_fifo_stall
, 1);
2760 no_fifo_stall_required
:
2761 adapter
->tx_fifo_head
+= skb_fifo_len
;
2762 if(adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
2763 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
2767 #define MINIMUM_DHCP_PACKET_SIZE 282
2769 e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2771 struct e1000_hw
*hw
= &adapter
->hw
;
2772 uint16_t length
, offset
;
2773 if(vlan_tx_tag_present(skb
)) {
2774 if(!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
2775 ( adapter
->hw
.mng_cookie
.status
&
2776 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) )
2779 if ((skb
->len
> MINIMUM_DHCP_PACKET_SIZE
) && (!skb
->protocol
)) {
2780 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
2781 if((htons(ETH_P_IP
) == eth
->h_proto
)) {
2782 const struct iphdr
*ip
=
2783 (struct iphdr
*)((uint8_t *)skb
->data
+14);
2784 if(IPPROTO_UDP
== ip
->protocol
) {
2785 struct udphdr
*udp
=
2786 (struct udphdr
*)((uint8_t *)ip
+
2788 if(ntohs(udp
->dest
) == 67) {
2789 offset
= (uint8_t *)udp
+ 8 - skb
->data
;
2790 length
= skb
->len
- offset
;
2792 return e1000_mng_write_dhcp_info(hw
,
2802 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2804 e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2806 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2807 struct e1000_tx_ring
*tx_ring
;
2808 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
2809 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
2810 unsigned int tx_flags
= 0;
2811 unsigned int len
= skb
->len
;
2812 unsigned long flags
;
2813 unsigned int nr_frags
= 0;
2814 unsigned int mss
= 0;
2818 len
-= skb
->data_len
;
2820 #ifdef CONFIG_E1000_MQ
2821 tx_ring
= *per_cpu_ptr(adapter
->cpu_tx_ring
, smp_processor_id());
2823 tx_ring
= adapter
->tx_ring
;
2826 if (unlikely(skb
->len
<= 0)) {
2827 dev_kfree_skb_any(skb
);
2828 return NETDEV_TX_OK
;
2832 mss
= skb_shinfo(skb
)->tso_size
;
2833 /* The controller does a simple calculation to
2834 * make sure there is enough room in the FIFO before
2835 * initiating the DMA for each buffer. The calc is:
2836 * 4 = ceil(buffer len/mss). To make sure we don't
2837 * overrun the FIFO, adjust the max buffer len if mss
2841 max_per_txd
= min(mss
<< 2, max_per_txd
);
2842 max_txd_pwr
= fls(max_per_txd
) - 1;
2844 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2845 * points to just header, pull a few bytes of payload from
2846 * frags into skb->data */
2847 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2848 if (skb
->data_len
&& (hdr_len
== (skb
->len
- skb
->data_len
)) &&
2849 (adapter
->hw
.mac_type
== e1000_82571
||
2850 adapter
->hw
.mac_type
== e1000_82572
)) {
2851 unsigned int pull_size
;
2852 pull_size
= min((unsigned int)4, skb
->data_len
);
2853 if (!__pskb_pull_tail(skb
, pull_size
)) {
2854 printk(KERN_ERR
"__pskb_pull_tail failed.\n");
2855 dev_kfree_skb_any(skb
);
2858 len
= skb
->len
- skb
->data_len
;
2862 if((mss
) || (skb
->ip_summed
== CHECKSUM_HW
))
2863 /* reserve a descriptor for the offload context */
2867 if(skb
->ip_summed
== CHECKSUM_HW
)
2872 /* Controller Erratum workaround */
2873 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2874 !skb_shinfo(skb
)->tso_size
)
2878 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
2880 if(adapter
->pcix_82544
)
2883 /* work-around for errata 10 and it applies to all controllers
2884 * in PCI-X mode, so add one more descriptor to the count
2886 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2890 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2891 for(f
= 0; f
< nr_frags
; f
++)
2892 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
2894 if(adapter
->pcix_82544
)
2897 if(adapter
->hw
.tx_pkt_filtering
&& (adapter
->hw
.mac_type
== e1000_82573
) )
2898 e1000_transfer_dhcp_info(adapter
, skb
);
2900 local_irq_save(flags
);
2901 if (!spin_trylock(&tx_ring
->tx_lock
)) {
2902 /* Collision - tell upper layer to requeue */
2903 local_irq_restore(flags
);
2904 return NETDEV_TX_LOCKED
;
2907 /* need: count + 2 desc gap to keep tail from touching
2908 * head, otherwise try next time */
2909 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < count
+ 2)) {
2910 netif_stop_queue(netdev
);
2911 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2912 return NETDEV_TX_BUSY
;
2915 if(unlikely(adapter
->hw
.mac_type
== e1000_82547
)) {
2916 if(unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
2917 netif_stop_queue(netdev
);
2918 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
);
2919 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2920 return NETDEV_TX_BUSY
;
2924 if(unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
2925 tx_flags
|= E1000_TX_FLAGS_VLAN
;
2926 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
2929 first
= tx_ring
->next_to_use
;
2931 tso
= e1000_tso(adapter
, tx_ring
, skb
);
2933 dev_kfree_skb_any(skb
);
2934 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2935 return NETDEV_TX_OK
;
2939 tx_ring
->last_tx_tso
= 1;
2940 tx_flags
|= E1000_TX_FLAGS_TSO
;
2941 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
2942 tx_flags
|= E1000_TX_FLAGS_CSUM
;
2944 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2945 * 82571 hardware supports TSO capabilities for IPv6 as well...
2946 * no longer assume, we must. */
2947 if (likely(skb
->protocol
== ntohs(ETH_P_IP
)))
2948 tx_flags
|= E1000_TX_FLAGS_IPV4
;
2950 e1000_tx_queue(adapter
, tx_ring
, tx_flags
,
2951 e1000_tx_map(adapter
, tx_ring
, skb
, first
,
2952 max_per_txd
, nr_frags
, mss
));
2954 netdev
->trans_start
= jiffies
;
2956 /* Make sure there is space in the ring for the next send. */
2957 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < MAX_SKB_FRAGS
+ 2))
2958 netif_stop_queue(netdev
);
2960 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2961 return NETDEV_TX_OK
;
2965 * e1000_tx_timeout - Respond to a Tx Hang
2966 * @netdev: network interface device structure
2970 e1000_tx_timeout(struct net_device
*netdev
)
2972 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2974 /* Do the reset outside of interrupt context */
2975 schedule_work(&adapter
->tx_timeout_task
);
2979 e1000_tx_timeout_task(struct net_device
*netdev
)
2981 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2983 adapter
->tx_timeout_count
++;
2984 e1000_down(adapter
);
2989 * e1000_get_stats - Get System Network Statistics
2990 * @netdev: network interface device structure
2992 * Returns the address of the device statistics structure.
2993 * The statistics are actually updated from the timer callback.
2996 static struct net_device_stats
*
2997 e1000_get_stats(struct net_device
*netdev
)
2999 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3001 /* only return the current stats */
3002 return &adapter
->net_stats
;
3006 * e1000_change_mtu - Change the Maximum Transfer Unit
3007 * @netdev: network interface device structure
3008 * @new_mtu: new value for maximum frame size
3010 * Returns 0 on success, negative on failure
3014 e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3016 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3017 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
3019 if((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
3020 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3021 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
3025 /* Adapter-specific max frame size limits. */
3026 switch (adapter
->hw
.mac_type
) {
3027 case e1000_82542_rev2_0
:
3028 case e1000_82542_rev2_1
:
3030 if (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3031 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported.\n");
3037 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3038 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3039 DPRINTK(PROBE
, ERR
, "MTU > 9216 not supported.\n");
3044 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3048 /* since the driver code now supports splitting a packet across
3049 * multiple descriptors, most of the fifo related limitations on
3050 * jumbo frame traffic have gone away.
3051 * simply use 2k descriptors for everything.
3053 * NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3054 * means we reserve 2 more, this pushes us to allocate from the next
3056 * i.e. RXBUFFER_2048 --> size-4096 slab */
3058 /* recent hardware supports 1KB granularity */
3059 if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3060 adapter
->rx_buffer_len
=
3061 ((max_frame
< E1000_RXBUFFER_2048
) ?
3062 max_frame
: E1000_RXBUFFER_2048
);
3063 E1000_ROUNDUP(adapter
->rx_buffer_len
, 1024);
3065 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3067 netdev
->mtu
= new_mtu
;
3069 if(netif_running(netdev
)) {
3070 e1000_down(adapter
);
3074 adapter
->hw
.max_frame_size
= max_frame
;
3080 * e1000_update_stats - Update the board statistics counters
3081 * @adapter: board private structure
3085 e1000_update_stats(struct e1000_adapter
*adapter
)
3087 struct e1000_hw
*hw
= &adapter
->hw
;
3088 unsigned long flags
;
3091 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3093 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3095 /* these counters are modified from e1000_adjust_tbi_stats,
3096 * called from the interrupt context, so they must only
3097 * be written while holding adapter->stats_lock
3100 adapter
->stats
.crcerrs
+= E1000_READ_REG(hw
, CRCERRS
);
3101 adapter
->stats
.gprc
+= E1000_READ_REG(hw
, GPRC
);
3102 adapter
->stats
.gorcl
+= E1000_READ_REG(hw
, GORCL
);
3103 adapter
->stats
.gorch
+= E1000_READ_REG(hw
, GORCH
);
3104 adapter
->stats
.bprc
+= E1000_READ_REG(hw
, BPRC
);
3105 adapter
->stats
.mprc
+= E1000_READ_REG(hw
, MPRC
);
3106 adapter
->stats
.roc
+= E1000_READ_REG(hw
, ROC
);
3107 adapter
->stats
.prc64
+= E1000_READ_REG(hw
, PRC64
);
3108 adapter
->stats
.prc127
+= E1000_READ_REG(hw
, PRC127
);
3109 adapter
->stats
.prc255
+= E1000_READ_REG(hw
, PRC255
);
3110 adapter
->stats
.prc511
+= E1000_READ_REG(hw
, PRC511
);
3111 adapter
->stats
.prc1023
+= E1000_READ_REG(hw
, PRC1023
);
3112 adapter
->stats
.prc1522
+= E1000_READ_REG(hw
, PRC1522
);
3114 adapter
->stats
.symerrs
+= E1000_READ_REG(hw
, SYMERRS
);
3115 adapter
->stats
.mpc
+= E1000_READ_REG(hw
, MPC
);
3116 adapter
->stats
.scc
+= E1000_READ_REG(hw
, SCC
);
3117 adapter
->stats
.ecol
+= E1000_READ_REG(hw
, ECOL
);
3118 adapter
->stats
.mcc
+= E1000_READ_REG(hw
, MCC
);
3119 adapter
->stats
.latecol
+= E1000_READ_REG(hw
, LATECOL
);
3120 adapter
->stats
.dc
+= E1000_READ_REG(hw
, DC
);
3121 adapter
->stats
.sec
+= E1000_READ_REG(hw
, SEC
);
3122 adapter
->stats
.rlec
+= E1000_READ_REG(hw
, RLEC
);
3123 adapter
->stats
.xonrxc
+= E1000_READ_REG(hw
, XONRXC
);
3124 adapter
->stats
.xontxc
+= E1000_READ_REG(hw
, XONTXC
);
3125 adapter
->stats
.xoffrxc
+= E1000_READ_REG(hw
, XOFFRXC
);
3126 adapter
->stats
.xofftxc
+= E1000_READ_REG(hw
, XOFFTXC
);
3127 adapter
->stats
.fcruc
+= E1000_READ_REG(hw
, FCRUC
);
3128 adapter
->stats
.gptc
+= E1000_READ_REG(hw
, GPTC
);
3129 adapter
->stats
.gotcl
+= E1000_READ_REG(hw
, GOTCL
);
3130 adapter
->stats
.gotch
+= E1000_READ_REG(hw
, GOTCH
);
3131 adapter
->stats
.rnbc
+= E1000_READ_REG(hw
, RNBC
);
3132 adapter
->stats
.ruc
+= E1000_READ_REG(hw
, RUC
);
3133 adapter
->stats
.rfc
+= E1000_READ_REG(hw
, RFC
);
3134 adapter
->stats
.rjc
+= E1000_READ_REG(hw
, RJC
);
3135 adapter
->stats
.torl
+= E1000_READ_REG(hw
, TORL
);
3136 adapter
->stats
.torh
+= E1000_READ_REG(hw
, TORH
);
3137 adapter
->stats
.totl
+= E1000_READ_REG(hw
, TOTL
);
3138 adapter
->stats
.toth
+= E1000_READ_REG(hw
, TOTH
);
3139 adapter
->stats
.tpr
+= E1000_READ_REG(hw
, TPR
);
3140 adapter
->stats
.ptc64
+= E1000_READ_REG(hw
, PTC64
);
3141 adapter
->stats
.ptc127
+= E1000_READ_REG(hw
, PTC127
);
3142 adapter
->stats
.ptc255
+= E1000_READ_REG(hw
, PTC255
);
3143 adapter
->stats
.ptc511
+= E1000_READ_REG(hw
, PTC511
);
3144 adapter
->stats
.ptc1023
+= E1000_READ_REG(hw
, PTC1023
);
3145 adapter
->stats
.ptc1522
+= E1000_READ_REG(hw
, PTC1522
);
3146 adapter
->stats
.mptc
+= E1000_READ_REG(hw
, MPTC
);
3147 adapter
->stats
.bptc
+= E1000_READ_REG(hw
, BPTC
);
3149 /* used for adaptive IFS */
3151 hw
->tx_packet_delta
= E1000_READ_REG(hw
, TPT
);
3152 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3153 hw
->collision_delta
= E1000_READ_REG(hw
, COLC
);
3154 adapter
->stats
.colc
+= hw
->collision_delta
;
3156 if(hw
->mac_type
>= e1000_82543
) {
3157 adapter
->stats
.algnerrc
+= E1000_READ_REG(hw
, ALGNERRC
);
3158 adapter
->stats
.rxerrc
+= E1000_READ_REG(hw
, RXERRC
);
3159 adapter
->stats
.tncrs
+= E1000_READ_REG(hw
, TNCRS
);
3160 adapter
->stats
.cexterr
+= E1000_READ_REG(hw
, CEXTERR
);
3161 adapter
->stats
.tsctc
+= E1000_READ_REG(hw
, TSCTC
);
3162 adapter
->stats
.tsctfc
+= E1000_READ_REG(hw
, TSCTFC
);
3164 if(hw
->mac_type
> e1000_82547_rev_2
) {
3165 adapter
->stats
.iac
+= E1000_READ_REG(hw
, IAC
);
3166 adapter
->stats
.icrxoc
+= E1000_READ_REG(hw
, ICRXOC
);
3167 adapter
->stats
.icrxptc
+= E1000_READ_REG(hw
, ICRXPTC
);
3168 adapter
->stats
.icrxatc
+= E1000_READ_REG(hw
, ICRXATC
);
3169 adapter
->stats
.ictxptc
+= E1000_READ_REG(hw
, ICTXPTC
);
3170 adapter
->stats
.ictxatc
+= E1000_READ_REG(hw
, ICTXATC
);
3171 adapter
->stats
.ictxqec
+= E1000_READ_REG(hw
, ICTXQEC
);
3172 adapter
->stats
.ictxqmtc
+= E1000_READ_REG(hw
, ICTXQMTC
);
3173 adapter
->stats
.icrxdmtc
+= E1000_READ_REG(hw
, ICRXDMTC
);
3176 /* Fill out the OS statistics structure */
3178 adapter
->net_stats
.rx_packets
= adapter
->stats
.gprc
;
3179 adapter
->net_stats
.tx_packets
= adapter
->stats
.gptc
;
3180 adapter
->net_stats
.rx_bytes
= adapter
->stats
.gorcl
;
3181 adapter
->net_stats
.tx_bytes
= adapter
->stats
.gotcl
;
3182 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3183 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3187 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3188 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3189 adapter
->stats
.rlec
+ adapter
->stats
.cexterr
;
3190 adapter
->net_stats
.rx_dropped
= 0;
3191 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlec
;
3192 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3193 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3194 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3198 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3199 adapter
->stats
.latecol
;
3200 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3201 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3202 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3204 /* Tx Dropped needs to be maintained elsewhere */
3208 if(hw
->media_type
== e1000_media_type_copper
) {
3209 if((adapter
->link_speed
== SPEED_1000
) &&
3210 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3211 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3212 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3215 if((hw
->mac_type
<= e1000_82546
) &&
3216 (hw
->phy_type
== e1000_phy_m88
) &&
3217 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3218 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3221 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3224 #ifdef CONFIG_E1000_MQ
3226 e1000_rx_schedule(void *data
)
3228 struct net_device
*poll_dev
, *netdev
= data
;
3229 struct e1000_adapter
*adapter
= netdev
->priv
;
3230 int this_cpu
= get_cpu();
3232 poll_dev
= *per_cpu_ptr(adapter
->cpu_netdev
, this_cpu
);
3233 if (poll_dev
== NULL
) {
3238 if (likely(netif_rx_schedule_prep(poll_dev
)))
3239 __netif_rx_schedule(poll_dev
);
3241 e1000_irq_enable(adapter
);
3248 * e1000_intr - Interrupt Handler
3249 * @irq: interrupt number
3250 * @data: pointer to a network interface device structure
3251 * @pt_regs: CPU registers structure
3255 e1000_intr(int irq
, void *data
, struct pt_regs
*regs
)
3257 struct net_device
*netdev
= data
;
3258 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3259 struct e1000_hw
*hw
= &adapter
->hw
;
3260 uint32_t icr
= E1000_READ_REG(hw
, ICR
);
3261 #ifndef CONFIG_E1000_NAPI
3264 /* Interrupt Auto-Mask...upon reading ICR,
3265 * interrupts are masked. No need for the
3266 * IMC write, but it does mean we should
3267 * account for it ASAP. */
3268 if (likely(hw
->mac_type
>= e1000_82571
))
3269 atomic_inc(&adapter
->irq_sem
);
3272 if (unlikely(!icr
)) {
3273 #ifdef CONFIG_E1000_NAPI
3274 if (hw
->mac_type
>= e1000_82571
)
3275 e1000_irq_enable(adapter
);
3277 return IRQ_NONE
; /* Not our interrupt */
3280 if(unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3281 hw
->get_link_status
= 1;
3282 mod_timer(&adapter
->watchdog_timer
, jiffies
);
3285 #ifdef CONFIG_E1000_NAPI
3286 if (unlikely(hw
->mac_type
< e1000_82571
)) {
3287 atomic_inc(&adapter
->irq_sem
);
3288 E1000_WRITE_REG(hw
, IMC
, ~0);
3289 E1000_WRITE_FLUSH(hw
);
3291 #ifdef CONFIG_E1000_MQ
3292 if (atomic_read(&adapter
->rx_sched_call_data
.count
) == 0) {
3293 /* We must setup the cpumask once count == 0 since
3294 * each cpu bit is cleared when the work is done. */
3295 adapter
->rx_sched_call_data
.cpumask
= adapter
->cpumask
;
3296 atomic_add(adapter
->num_rx_queues
- 1, &adapter
->irq_sem
);
3297 atomic_set(&adapter
->rx_sched_call_data
.count
,
3298 adapter
->num_rx_queues
);
3299 smp_call_async_mask(&adapter
->rx_sched_call_data
);
3301 printk("call_data.count == %u\n", atomic_read(&adapter
->rx_sched_call_data
.count
));
3303 #else /* if !CONFIG_E1000_MQ */
3304 if (likely(netif_rx_schedule_prep(&adapter
->polling_netdev
[0])))
3305 __netif_rx_schedule(&adapter
->polling_netdev
[0]);
3307 e1000_irq_enable(adapter
);
3308 #endif /* CONFIG_E1000_MQ */
3310 #else /* if !CONFIG_E1000_NAPI */
3311 /* Writing IMC and IMS is needed for 82547.
3312 Due to Hub Link bus being occupied, an interrupt
3313 de-assertion message is not able to be sent.
3314 When an interrupt assertion message is generated later,
3315 two messages are re-ordered and sent out.
3316 That causes APIC to think 82547 is in de-assertion
3317 state, while 82547 is in assertion state, resulting
3318 in dead lock. Writing IMC forces 82547 into
3321 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
){
3322 atomic_inc(&adapter
->irq_sem
);
3323 E1000_WRITE_REG(hw
, IMC
, ~0);
3326 for(i
= 0; i
< E1000_MAX_INTR
; i
++)
3327 if(unlikely(!adapter
->clean_rx(adapter
, adapter
->rx_ring
) &
3328 !e1000_clean_tx_irq(adapter
, adapter
->tx_ring
)))
3331 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
3332 e1000_irq_enable(adapter
);
3334 #endif /* CONFIG_E1000_NAPI */
3339 #ifdef CONFIG_E1000_NAPI
3341 * e1000_clean - NAPI Rx polling callback
3342 * @adapter: board private structure
3346 e1000_clean(struct net_device
*poll_dev
, int *budget
)
3348 struct e1000_adapter
*adapter
;
3349 int work_to_do
= min(*budget
, poll_dev
->quota
);
3350 int tx_cleaned
, i
= 0, work_done
= 0;
3352 /* Must NOT use netdev_priv macro here. */
3353 adapter
= poll_dev
->priv
;
3355 /* Keep link state information with original netdev */
3356 if (!netif_carrier_ok(adapter
->netdev
))
3359 while (poll_dev
!= &adapter
->polling_netdev
[i
]) {
3361 if (unlikely(i
== adapter
->num_rx_queues
))
3365 tx_cleaned
= e1000_clean_tx_irq(adapter
, &adapter
->tx_ring
[i
]);
3366 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[i
],
3367 &work_done
, work_to_do
);
3369 *budget
-= work_done
;
3370 poll_dev
->quota
-= work_done
;
3372 /* If no Tx and not enough Rx work done, exit the polling mode */
3373 if((!tx_cleaned
&& (work_done
== 0)) ||
3374 !netif_running(adapter
->netdev
)) {
3376 netif_rx_complete(poll_dev
);
3377 e1000_irq_enable(adapter
);
3386 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3387 * @adapter: board private structure
3391 e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
3392 struct e1000_tx_ring
*tx_ring
)
3394 struct net_device
*netdev
= adapter
->netdev
;
3395 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
3396 struct e1000_buffer
*buffer_info
;
3397 unsigned int i
, eop
;
3398 boolean_t cleaned
= FALSE
;
3400 i
= tx_ring
->next_to_clean
;
3401 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3402 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3404 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
3405 for(cleaned
= FALSE
; !cleaned
; ) {
3406 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3407 buffer_info
= &tx_ring
->buffer_info
[i
];
3408 cleaned
= (i
== eop
);
3410 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
3412 tx_desc
->buffer_addr
= 0;
3413 tx_desc
->lower
.data
= 0;
3414 tx_desc
->upper
.data
= 0;
3416 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
3419 #ifdef CONFIG_E1000_MQ
3420 tx_ring
->tx_stats
.packets
++;
3423 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3424 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3427 tx_ring
->next_to_clean
= i
;
3429 spin_lock(&tx_ring
->tx_lock
);
3431 if(unlikely(cleaned
&& netif_queue_stopped(netdev
) &&
3432 netif_carrier_ok(netdev
)))
3433 netif_wake_queue(netdev
);
3435 spin_unlock(&tx_ring
->tx_lock
);
3437 if (adapter
->detect_tx_hung
) {
3438 /* Detect a transmit hang in hardware, this serializes the
3439 * check with the clearing of time_stamp and movement of i */
3440 adapter
->detect_tx_hung
= FALSE
;
3441 if (tx_ring
->buffer_info
[eop
].dma
&&
3442 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
+
3443 adapter
->tx_timeout_factor
* HZ
)
3444 && !(E1000_READ_REG(&adapter
->hw
, STATUS
) &
3445 E1000_STATUS_TXOFF
)) {
3447 /* detected Tx unit hang */
3448 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
3452 " next_to_use <%x>\n"
3453 " next_to_clean <%x>\n"
3454 "buffer_info[next_to_clean]\n"
3455 " time_stamp <%lx>\n"
3456 " next_to_watch <%x>\n"
3458 " next_to_watch.status <%x>\n",
3459 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
3460 sizeof(struct e1000_tx_ring
)),
3461 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdh
),
3462 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdt
),
3463 tx_ring
->next_to_use
,
3464 tx_ring
->next_to_clean
,
3465 tx_ring
->buffer_info
[eop
].time_stamp
,
3468 eop_desc
->upper
.fields
.status
);
3469 netif_stop_queue(netdev
);
3476 * e1000_rx_checksum - Receive Checksum Offload for 82543
3477 * @adapter: board private structure
3478 * @status_err: receive descriptor status and error fields
3479 * @csum: receive descriptor csum field
3480 * @sk_buff: socket buffer with received data
3484 e1000_rx_checksum(struct e1000_adapter
*adapter
,
3485 uint32_t status_err
, uint32_t csum
,
3486 struct sk_buff
*skb
)
3488 uint16_t status
= (uint16_t)status_err
;
3489 uint8_t errors
= (uint8_t)(status_err
>> 24);
3490 skb
->ip_summed
= CHECKSUM_NONE
;
3492 /* 82543 or newer only */
3493 if(unlikely(adapter
->hw
.mac_type
< e1000_82543
)) return;
3494 /* Ignore Checksum bit is set */
3495 if(unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
3496 /* TCP/UDP checksum error bit is set */
3497 if(unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
3498 /* let the stack verify checksum errors */
3499 adapter
->hw_csum_err
++;
3502 /* TCP/UDP Checksum has not been calculated */
3503 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
) {
3504 if(!(status
& E1000_RXD_STAT_TCPCS
))
3507 if(!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
3510 /* It must be a TCP or UDP packet with a valid checksum */
3511 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
3512 /* TCP checksum is good */
3513 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3514 } else if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3515 /* IP fragment with UDP payload */
3516 /* Hardware complements the payload checksum, so we undo it
3517 * and then put the value in host order for further stack use.
3519 csum
= ntohl(csum
^ 0xFFFF);
3521 skb
->ip_summed
= CHECKSUM_HW
;
3523 adapter
->hw_csum_good
++;
3527 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3528 * @adapter: board private structure
3532 #ifdef CONFIG_E1000_NAPI
3533 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3534 struct e1000_rx_ring
*rx_ring
,
3535 int *work_done
, int work_to_do
)
3537 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3538 struct e1000_rx_ring
*rx_ring
)
3541 struct net_device
*netdev
= adapter
->netdev
;
3542 struct pci_dev
*pdev
= adapter
->pdev
;
3543 struct e1000_rx_desc
*rx_desc
;
3544 struct e1000_buffer
*buffer_info
;
3545 struct sk_buff
*skb
;
3546 unsigned long flags
;
3550 boolean_t cleaned
= FALSE
;
3551 int cleaned_count
= 0;
3553 i
= rx_ring
->next_to_clean
;
3554 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3556 while(rx_desc
->status
& E1000_RXD_STAT_DD
) {
3557 buffer_info
= &rx_ring
->buffer_info
[i
];
3558 #ifdef CONFIG_E1000_NAPI
3559 if(*work_done
>= work_to_do
)
3566 pci_unmap_single(pdev
, buffer_info
->dma
, buffer_info
->length
,
3567 PCI_DMA_FROMDEVICE
);
3569 skb
= buffer_info
->skb
;
3570 length
= le16_to_cpu(rx_desc
->length
);
3572 if(unlikely(!(rx_desc
->status
& E1000_RXD_STAT_EOP
))) {
3573 /* All receives must fit into a single buffer */
3574 E1000_DBG("%s: Receive packet consumed multiple"
3575 " buffers\n", netdev
->name
);
3576 dev_kfree_skb_irq(skb
);
3580 if(unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
3581 last_byte
= *(skb
->data
+ length
- 1);
3582 if(TBI_ACCEPT(&adapter
->hw
, rx_desc
->status
,
3583 rx_desc
->errors
, length
, last_byte
)) {
3584 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3585 e1000_tbi_adjust_stats(&adapter
->hw
, &adapter
->stats
,
3587 spin_unlock_irqrestore(&adapter
->stats_lock
,
3591 dev_kfree_skb_irq(skb
);
3597 skb_put(skb
, length
- ETHERNET_FCS_SIZE
);
3599 /* Receive Checksum Offload */
3600 e1000_rx_checksum(adapter
, (uint32_t)(rx_desc
->status
) |
3601 ((uint32_t)(rx_desc
->errors
) << 24),
3602 rx_desc
->csum
, skb
);
3603 skb
->protocol
= eth_type_trans(skb
, netdev
);
3604 #ifdef CONFIG_E1000_NAPI
3605 if(unlikely(adapter
->vlgrp
&&
3606 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3607 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3608 le16_to_cpu(rx_desc
->special
) &
3609 E1000_RXD_SPC_VLAN_MASK
);
3611 netif_receive_skb(skb
);
3613 #else /* CONFIG_E1000_NAPI */
3614 if(unlikely(adapter
->vlgrp
&&
3615 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3616 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3617 le16_to_cpu(rx_desc
->special
) &
3618 E1000_RXD_SPC_VLAN_MASK
);
3622 #endif /* CONFIG_E1000_NAPI */
3623 netdev
->last_rx
= jiffies
;
3624 #ifdef CONFIG_E1000_MQ
3625 rx_ring
->rx_stats
.packets
++;
3626 rx_ring
->rx_stats
.bytes
+= length
;
3630 rx_desc
->status
= 0;
3632 /* return some buffers to hardware, one at a time is too slow */
3633 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
3634 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3639 rx_ring
->next_to_clean
= i
;
3641 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
3643 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3649 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3650 * @adapter: board private structure
3654 #ifdef CONFIG_E1000_NAPI
3655 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3656 struct e1000_rx_ring
*rx_ring
,
3657 int *work_done
, int work_to_do
)
3659 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3660 struct e1000_rx_ring
*rx_ring
)
3663 union e1000_rx_desc_packet_split
*rx_desc
;
3664 struct net_device
*netdev
= adapter
->netdev
;
3665 struct pci_dev
*pdev
= adapter
->pdev
;
3666 struct e1000_buffer
*buffer_info
;
3667 struct e1000_ps_page
*ps_page
;
3668 struct e1000_ps_page_dma
*ps_page_dma
;
3669 struct sk_buff
*skb
;
3671 uint32_t length
, staterr
;
3672 int cleaned_count
= 0;
3673 boolean_t cleaned
= FALSE
;
3675 i
= rx_ring
->next_to_clean
;
3676 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3677 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3679 while(staterr
& E1000_RXD_STAT_DD
) {
3680 buffer_info
= &rx_ring
->buffer_info
[i
];
3681 ps_page
= &rx_ring
->ps_page
[i
];
3682 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3683 #ifdef CONFIG_E1000_NAPI
3684 if(unlikely(*work_done
>= work_to_do
))
3690 pci_unmap_single(pdev
, buffer_info
->dma
,
3691 buffer_info
->length
,
3692 PCI_DMA_FROMDEVICE
);
3694 skb
= buffer_info
->skb
;
3696 if(unlikely(!(staterr
& E1000_RXD_STAT_EOP
))) {
3697 E1000_DBG("%s: Packet Split buffers didn't pick up"
3698 " the full packet\n", netdev
->name
);
3699 dev_kfree_skb_irq(skb
);
3703 if(unlikely(staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
)) {
3704 dev_kfree_skb_irq(skb
);
3708 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
3710 if(unlikely(!length
)) {
3711 E1000_DBG("%s: Last part of the packet spanning"
3712 " multiple descriptors\n", netdev
->name
);
3713 dev_kfree_skb_irq(skb
);
3718 skb_put(skb
, length
);
3720 for(j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
3721 if(!(length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
])))
3724 pci_unmap_page(pdev
, ps_page_dma
->ps_page_dma
[j
],
3725 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
3726 ps_page_dma
->ps_page_dma
[j
] = 0;
3727 skb_shinfo(skb
)->frags
[j
].page
=
3728 ps_page
->ps_page
[j
];
3729 ps_page
->ps_page
[j
] = NULL
;
3730 skb_shinfo(skb
)->frags
[j
].page_offset
= 0;
3731 skb_shinfo(skb
)->frags
[j
].size
= length
;
3732 skb_shinfo(skb
)->nr_frags
++;
3734 skb
->data_len
+= length
;
3737 e1000_rx_checksum(adapter
, staterr
,
3738 rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
, skb
);
3739 skb
->protocol
= eth_type_trans(skb
, netdev
);
3741 if(likely(rx_desc
->wb
.upper
.header_status
&
3742 E1000_RXDPS_HDRSTAT_HDRSP
)) {
3743 adapter
->rx_hdr_split
++;
3744 #ifdef HAVE_RX_ZERO_COPY
3745 skb_shinfo(skb
)->zero_copy
= TRUE
;
3748 #ifdef CONFIG_E1000_NAPI
3749 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3750 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3751 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3752 E1000_RXD_SPC_VLAN_MASK
);
3754 netif_receive_skb(skb
);
3756 #else /* CONFIG_E1000_NAPI */
3757 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3758 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3759 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3760 E1000_RXD_SPC_VLAN_MASK
);
3764 #endif /* CONFIG_E1000_NAPI */
3765 netdev
->last_rx
= jiffies
;
3766 #ifdef CONFIG_E1000_MQ
3767 rx_ring
->rx_stats
.packets
++;
3768 rx_ring
->rx_stats
.bytes
+= length
;
3772 rx_desc
->wb
.middle
.status_error
&= ~0xFF;
3773 buffer_info
->skb
= NULL
;
3775 /* return some buffers to hardware, one at a time is too slow */
3776 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
3777 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3781 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3783 rx_ring
->next_to_clean
= i
;
3785 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
3787 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3793 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3794 * @adapter: address of board private structure
3798 e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
3799 struct e1000_rx_ring
*rx_ring
,
3802 struct net_device
*netdev
= adapter
->netdev
;
3803 struct pci_dev
*pdev
= adapter
->pdev
;
3804 struct e1000_rx_desc
*rx_desc
;
3805 struct e1000_buffer
*buffer_info
;
3806 struct sk_buff
*skb
;
3808 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
3810 i
= rx_ring
->next_to_use
;
3811 buffer_info
= &rx_ring
->buffer_info
[i
];
3813 while(!buffer_info
->skb
) {
3814 skb
= dev_alloc_skb(bufsz
);
3816 if(unlikely(!skb
)) {
3817 /* Better luck next round */
3818 adapter
->alloc_rx_buff_failed
++;
3822 /* Fix for errata 23, can't cross 64kB boundary */
3823 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3824 struct sk_buff
*oldskb
= skb
;
3825 DPRINTK(RX_ERR
, ERR
, "skb align check failed: %u bytes "
3826 "at %p\n", bufsz
, skb
->data
);
3827 /* Try again, without freeing the previous */
3828 skb
= dev_alloc_skb(bufsz
);
3829 /* Failed allocation, critical failure */
3831 dev_kfree_skb(oldskb
);
3835 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3838 dev_kfree_skb(oldskb
);
3839 break; /* while !buffer_info->skb */
3841 /* Use new allocation */
3842 dev_kfree_skb(oldskb
);
3845 /* Make buffer alignment 2 beyond a 16 byte boundary
3846 * this will result in a 16 byte aligned IP header after
3847 * the 14 byte MAC header is removed
3849 skb_reserve(skb
, NET_IP_ALIGN
);
3853 buffer_info
->skb
= skb
;
3854 buffer_info
->length
= adapter
->rx_buffer_len
;
3855 buffer_info
->dma
= pci_map_single(pdev
,
3857 adapter
->rx_buffer_len
,
3858 PCI_DMA_FROMDEVICE
);
3860 /* Fix for errata 23, can't cross 64kB boundary */
3861 if (!e1000_check_64k_bound(adapter
,
3862 (void *)(unsigned long)buffer_info
->dma
,
3863 adapter
->rx_buffer_len
)) {
3864 DPRINTK(RX_ERR
, ERR
,
3865 "dma align check failed: %u bytes at %p\n",
3866 adapter
->rx_buffer_len
,
3867 (void *)(unsigned long)buffer_info
->dma
);
3869 buffer_info
->skb
= NULL
;
3871 pci_unmap_single(pdev
, buffer_info
->dma
,
3872 adapter
->rx_buffer_len
,
3873 PCI_DMA_FROMDEVICE
);
3875 break; /* while !buffer_info->skb */
3877 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3878 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3880 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3881 /* Force memory writes to complete before letting h/w
3882 * know there are new descriptors to fetch. (Only
3883 * applicable for weak-ordered memory model archs,
3884 * such as IA-64). */
3886 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
3889 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3890 buffer_info
= &rx_ring
->buffer_info
[i
];
3893 rx_ring
->next_to_use
= i
;
3897 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3898 * @adapter: address of board private structure
3902 e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
3903 struct e1000_rx_ring
*rx_ring
,
3906 struct net_device
*netdev
= adapter
->netdev
;
3907 struct pci_dev
*pdev
= adapter
->pdev
;
3908 union e1000_rx_desc_packet_split
*rx_desc
;
3909 struct e1000_buffer
*buffer_info
;
3910 struct e1000_ps_page
*ps_page
;
3911 struct e1000_ps_page_dma
*ps_page_dma
;
3912 struct sk_buff
*skb
;
3915 i
= rx_ring
->next_to_use
;
3916 buffer_info
= &rx_ring
->buffer_info
[i
];
3917 ps_page
= &rx_ring
->ps_page
[i
];
3918 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3920 while (cleaned_count
--) {
3921 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3923 for(j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
3924 if (j
< adapter
->rx_ps_pages
) {
3925 if (likely(!ps_page
->ps_page
[j
])) {
3926 ps_page
->ps_page
[j
] =
3927 alloc_page(GFP_ATOMIC
);
3928 if (unlikely(!ps_page
->ps_page
[j
]))
3930 ps_page_dma
->ps_page_dma
[j
] =
3932 ps_page
->ps_page
[j
],
3934 PCI_DMA_FROMDEVICE
);
3936 /* Refresh the desc even if buffer_addrs didn't
3937 * change because each write-back erases
3940 rx_desc
->read
.buffer_addr
[j
+1] =
3941 cpu_to_le64(ps_page_dma
->ps_page_dma
[j
]);
3943 rx_desc
->read
.buffer_addr
[j
+1] = ~0;
3946 skb
= dev_alloc_skb(adapter
->rx_ps_bsize0
+ NET_IP_ALIGN
);
3951 /* Make buffer alignment 2 beyond a 16 byte boundary
3952 * this will result in a 16 byte aligned IP header after
3953 * the 14 byte MAC header is removed
3955 skb_reserve(skb
, NET_IP_ALIGN
);
3959 buffer_info
->skb
= skb
;
3960 buffer_info
->length
= adapter
->rx_ps_bsize0
;
3961 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
3962 adapter
->rx_ps_bsize0
,
3963 PCI_DMA_FROMDEVICE
);
3965 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
3967 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3968 /* Force memory writes to complete before letting h/w
3969 * know there are new descriptors to fetch. (Only
3970 * applicable for weak-ordered memory model archs,
3971 * such as IA-64). */
3973 /* Hardware increments by 16 bytes, but packet split
3974 * descriptors are 32 bytes...so we increment tail
3977 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
3980 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3981 buffer_info
= &rx_ring
->buffer_info
[i
];
3982 ps_page
= &rx_ring
->ps_page
[i
];
3983 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3987 rx_ring
->next_to_use
= i
;
3991 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3996 e1000_smartspeed(struct e1000_adapter
*adapter
)
3998 uint16_t phy_status
;
4001 if((adapter
->hw
.phy_type
!= e1000_phy_igp
) || !adapter
->hw
.autoneg
||
4002 !(adapter
->hw
.autoneg_advertised
& ADVERTISE_1000_FULL
))
4005 if(adapter
->smartspeed
== 0) {
4006 /* If Master/Slave config fault is asserted twice,
4007 * we assume back-to-back */
4008 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4009 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4010 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4011 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4012 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4013 if(phy_ctrl
& CR_1000T_MS_ENABLE
) {
4014 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
4015 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
,
4017 adapter
->smartspeed
++;
4018 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4019 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
,
4021 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4022 MII_CR_RESTART_AUTO_NEG
);
4023 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
,
4028 } else if(adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
4029 /* If still no link, perhaps using 2/3 pair cable */
4030 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4031 phy_ctrl
|= CR_1000T_MS_ENABLE
;
4032 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, phy_ctrl
);
4033 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4034 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &phy_ctrl
)) {
4035 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4036 MII_CR_RESTART_AUTO_NEG
);
4037 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, phy_ctrl
);
4040 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4041 if(adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
4042 adapter
->smartspeed
= 0;
4053 e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4059 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4073 e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4075 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4076 struct mii_ioctl_data
*data
= if_mii(ifr
);
4080 unsigned long flags
;
4082 if(adapter
->hw
.media_type
!= e1000_media_type_copper
)
4087 data
->phy_id
= adapter
->hw
.phy_addr
;
4090 if(!capable(CAP_NET_ADMIN
))
4092 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4093 if(e1000_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
4095 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4098 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4101 if(!capable(CAP_NET_ADMIN
))
4103 if(data
->reg_num
& ~(0x1F))
4105 mii_reg
= data
->val_in
;
4106 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4107 if(e1000_write_phy_reg(&adapter
->hw
, data
->reg_num
,
4109 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4112 if(adapter
->hw
.phy_type
== e1000_phy_m88
) {
4113 switch (data
->reg_num
) {
4115 if(mii_reg
& MII_CR_POWER_DOWN
)
4117 if(mii_reg
& MII_CR_AUTO_NEG_EN
) {
4118 adapter
->hw
.autoneg
= 1;
4119 adapter
->hw
.autoneg_advertised
= 0x2F;
4122 spddplx
= SPEED_1000
;
4123 else if (mii_reg
& 0x2000)
4124 spddplx
= SPEED_100
;
4127 spddplx
+= (mii_reg
& 0x100)
4130 retval
= e1000_set_spd_dplx(adapter
,
4133 spin_unlock_irqrestore(
4134 &adapter
->stats_lock
,
4139 if(netif_running(adapter
->netdev
)) {
4140 e1000_down(adapter
);
4143 e1000_reset(adapter
);
4145 case M88E1000_PHY_SPEC_CTRL
:
4146 case M88E1000_EXT_PHY_SPEC_CTRL
:
4147 if(e1000_phy_reset(&adapter
->hw
)) {
4148 spin_unlock_irqrestore(
4149 &adapter
->stats_lock
, flags
);
4155 switch (data
->reg_num
) {
4157 if(mii_reg
& MII_CR_POWER_DOWN
)
4159 if(netif_running(adapter
->netdev
)) {
4160 e1000_down(adapter
);
4163 e1000_reset(adapter
);
4167 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4172 return E1000_SUCCESS
;
4176 e1000_pci_set_mwi(struct e1000_hw
*hw
)
4178 struct e1000_adapter
*adapter
= hw
->back
;
4179 int ret_val
= pci_set_mwi(adapter
->pdev
);
4182 DPRINTK(PROBE
, ERR
, "Error in setting MWI\n");
4186 e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4188 struct e1000_adapter
*adapter
= hw
->back
;
4190 pci_clear_mwi(adapter
->pdev
);
4194 e1000_read_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4196 struct e1000_adapter
*adapter
= hw
->back
;
4198 pci_read_config_word(adapter
->pdev
, reg
, value
);
4202 e1000_write_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4204 struct e1000_adapter
*adapter
= hw
->back
;
4206 pci_write_config_word(adapter
->pdev
, reg
, *value
);
4210 e1000_io_read(struct e1000_hw
*hw
, unsigned long port
)
4216 e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, uint32_t value
)
4222 e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
4224 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4225 uint32_t ctrl
, rctl
;
4227 e1000_irq_disable(adapter
);
4228 adapter
->vlgrp
= grp
;
4231 /* enable VLAN tag insert/strip */
4232 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4233 ctrl
|= E1000_CTRL_VME
;
4234 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4236 /* enable VLAN receive filtering */
4237 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4238 rctl
|= E1000_RCTL_VFE
;
4239 rctl
&= ~E1000_RCTL_CFIEN
;
4240 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4241 e1000_update_mng_vlan(adapter
);
4243 /* disable VLAN tag insert/strip */
4244 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4245 ctrl
&= ~E1000_CTRL_VME
;
4246 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4248 /* disable VLAN filtering */
4249 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4250 rctl
&= ~E1000_RCTL_VFE
;
4251 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4252 if(adapter
->mng_vlan_id
!= (uint16_t)E1000_MNG_VLAN_NONE
) {
4253 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
4254 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
4258 e1000_irq_enable(adapter
);
4262 e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
)
4264 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4265 uint32_t vfta
, index
;
4266 if((adapter
->hw
.mng_cookie
.status
&
4267 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4268 (vid
== adapter
->mng_vlan_id
))
4270 /* add VID to filter table */
4271 index
= (vid
>> 5) & 0x7F;
4272 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4273 vfta
|= (1 << (vid
& 0x1F));
4274 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4278 e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
)
4280 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4281 uint32_t vfta
, index
;
4283 e1000_irq_disable(adapter
);
4286 adapter
->vlgrp
->vlan_devices
[vid
] = NULL
;
4288 e1000_irq_enable(adapter
);
4290 if((adapter
->hw
.mng_cookie
.status
&
4291 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4292 (vid
== adapter
->mng_vlan_id
)) {
4293 /* release control to f/w */
4294 e1000_release_hw_control(adapter
);
4298 /* remove VID from filter table */
4299 index
= (vid
>> 5) & 0x7F;
4300 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4301 vfta
&= ~(1 << (vid
& 0x1F));
4302 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4306 e1000_restore_vlan(struct e1000_adapter
*adapter
)
4308 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
4310 if(adapter
->vlgrp
) {
4312 for(vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
4313 if(!adapter
->vlgrp
->vlan_devices
[vid
])
4315 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
4321 e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
)
4323 adapter
->hw
.autoneg
= 0;
4325 /* Fiber NICs only allow 1000 gbps Full duplex */
4326 if((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
4327 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
4328 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4333 case SPEED_10
+ DUPLEX_HALF
:
4334 adapter
->hw
.forced_speed_duplex
= e1000_10_half
;
4336 case SPEED_10
+ DUPLEX_FULL
:
4337 adapter
->hw
.forced_speed_duplex
= e1000_10_full
;
4339 case SPEED_100
+ DUPLEX_HALF
:
4340 adapter
->hw
.forced_speed_duplex
= e1000_100_half
;
4342 case SPEED_100
+ DUPLEX_FULL
:
4343 adapter
->hw
.forced_speed_duplex
= e1000_100_full
;
4345 case SPEED_1000
+ DUPLEX_FULL
:
4346 adapter
->hw
.autoneg
= 1;
4347 adapter
->hw
.autoneg_advertised
= ADVERTISE_1000_FULL
;
4349 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
4351 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4359 e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4361 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4362 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4363 uint32_t ctrl
, ctrl_ext
, rctl
, manc
, status
;
4364 uint32_t wufc
= adapter
->wol
;
4366 netif_device_detach(netdev
);
4368 if(netif_running(netdev
))
4369 e1000_down(adapter
);
4371 status
= E1000_READ_REG(&adapter
->hw
, STATUS
);
4372 if(status
& E1000_STATUS_LU
)
4373 wufc
&= ~E1000_WUFC_LNKC
;
4376 e1000_setup_rctl(adapter
);
4377 e1000_set_multi(netdev
);
4379 /* turn on all-multi mode if wake on multicast is enabled */
4380 if(adapter
->wol
& E1000_WUFC_MC
) {
4381 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4382 rctl
|= E1000_RCTL_MPE
;
4383 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4386 if(adapter
->hw
.mac_type
>= e1000_82540
) {
4387 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4388 /* advertise wake from D3Cold */
4389 #define E1000_CTRL_ADVD3WUC 0x00100000
4390 /* phy power management enable */
4391 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4392 ctrl
|= E1000_CTRL_ADVD3WUC
|
4393 E1000_CTRL_EN_PHY_PWR_MGMT
;
4394 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4397 if(adapter
->hw
.media_type
== e1000_media_type_fiber
||
4398 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) {
4399 /* keep the laser running in D3 */
4400 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
4401 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
4402 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
, ctrl_ext
);
4405 /* Allow time for pending master requests to run */
4406 e1000_disable_pciex_master(&adapter
->hw
);
4408 E1000_WRITE_REG(&adapter
->hw
, WUC
, E1000_WUC_PME_EN
);
4409 E1000_WRITE_REG(&adapter
->hw
, WUFC
, wufc
);
4410 pci_enable_wake(pdev
, 3, 1);
4411 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
4413 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
4414 E1000_WRITE_REG(&adapter
->hw
, WUFC
, 0);
4415 pci_enable_wake(pdev
, 3, 0);
4416 pci_enable_wake(pdev
, 4, 0); /* 4 == D3 cold */
4419 pci_save_state(pdev
);
4421 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4422 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4423 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4424 if(manc
& E1000_MANC_SMBUS_EN
) {
4425 manc
|= E1000_MANC_ARP_EN
;
4426 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4427 pci_enable_wake(pdev
, 3, 1);
4428 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
4432 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4433 * would have already happened in close and is redundant. */
4434 e1000_release_hw_control(adapter
);
4436 pci_disable_device(pdev
);
4437 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4443 e1000_resume(struct pci_dev
*pdev
)
4445 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4446 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4447 uint32_t manc
, ret_val
;
4449 pci_set_power_state(pdev
, PCI_D0
);
4450 pci_restore_state(pdev
);
4451 ret_val
= pci_enable_device(pdev
);
4452 pci_set_master(pdev
);
4454 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4455 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4457 e1000_reset(adapter
);
4458 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
4460 if(netif_running(netdev
))
4463 netif_device_attach(netdev
);
4465 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4466 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4467 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4468 manc
&= ~(E1000_MANC_ARP_EN
);
4469 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4472 /* If the controller is 82573 and f/w is AMT, do not set
4473 * DRV_LOAD until the interface is up. For all other cases,
4474 * let the f/w know that the h/w is now under the control
4476 if (adapter
->hw
.mac_type
!= e1000_82573
||
4477 !e1000_check_mng_mode(&adapter
->hw
))
4478 e1000_get_hw_control(adapter
);
4483 #ifdef CONFIG_NET_POLL_CONTROLLER
4485 * Polling 'interrupt' - used by things like netconsole to send skbs
4486 * without having to re-enable interrupts. It's not called while
4487 * the interrupt routine is executing.
4490 e1000_netpoll(struct net_device
*netdev
)
4492 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4493 disable_irq(adapter
->pdev
->irq
);
4494 e1000_intr(adapter
->pdev
->irq
, netdev
, NULL
);
4495 e1000_clean_tx_irq(adapter
, adapter
->tx_ring
);
4496 #ifndef CONFIG_E1000_NAPI
4497 adapter
->clean_rx(adapter
, adapter
->rx_ring
);
4499 enable_irq(adapter
->pdev
->irq
);