1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
33 * o Accepted ethtool cleanup patch from Stephen Hemminger
35 * o applied Anton's patch to resolve tx hang in hardware
36 * o Applied Andrew Mortons patch - e1000 stops working after resume
39 char e1000_driver_name
[] = "e1000";
40 static char e1000_driver_string
[] = "Intel(R) PRO/1000 Network Driver";
41 #ifndef CONFIG_E1000_NAPI
44 #define DRIVERNAPI "-NAPI"
46 #define DRV_VERSION "6.3.9-k2"DRIVERNAPI
47 char e1000_driver_version
[] = DRV_VERSION
;
48 static char e1000_copyright
[] = "Copyright (c) 1999-2005 Intel Corporation.";
50 /* e1000_pci_tbl - PCI Device ID Table
52 * Last entry must be all 0s
55 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
57 static struct pci_device_id e1000_pci_tbl
[] = {
58 INTEL_E1000_ETHERNET_DEVICE(0x1000),
59 INTEL_E1000_ETHERNET_DEVICE(0x1001),
60 INTEL_E1000_ETHERNET_DEVICE(0x1004),
61 INTEL_E1000_ETHERNET_DEVICE(0x1008),
62 INTEL_E1000_ETHERNET_DEVICE(0x1009),
63 INTEL_E1000_ETHERNET_DEVICE(0x100C),
64 INTEL_E1000_ETHERNET_DEVICE(0x100D),
65 INTEL_E1000_ETHERNET_DEVICE(0x100E),
66 INTEL_E1000_ETHERNET_DEVICE(0x100F),
67 INTEL_E1000_ETHERNET_DEVICE(0x1010),
68 INTEL_E1000_ETHERNET_DEVICE(0x1011),
69 INTEL_E1000_ETHERNET_DEVICE(0x1012),
70 INTEL_E1000_ETHERNET_DEVICE(0x1013),
71 INTEL_E1000_ETHERNET_DEVICE(0x1014),
72 INTEL_E1000_ETHERNET_DEVICE(0x1015),
73 INTEL_E1000_ETHERNET_DEVICE(0x1016),
74 INTEL_E1000_ETHERNET_DEVICE(0x1017),
75 INTEL_E1000_ETHERNET_DEVICE(0x1018),
76 INTEL_E1000_ETHERNET_DEVICE(0x1019),
77 INTEL_E1000_ETHERNET_DEVICE(0x101A),
78 INTEL_E1000_ETHERNET_DEVICE(0x101D),
79 INTEL_E1000_ETHERNET_DEVICE(0x101E),
80 INTEL_E1000_ETHERNET_DEVICE(0x1026),
81 INTEL_E1000_ETHERNET_DEVICE(0x1027),
82 INTEL_E1000_ETHERNET_DEVICE(0x1028),
83 INTEL_E1000_ETHERNET_DEVICE(0x105E),
84 INTEL_E1000_ETHERNET_DEVICE(0x105F),
85 INTEL_E1000_ETHERNET_DEVICE(0x1060),
86 INTEL_E1000_ETHERNET_DEVICE(0x1075),
87 INTEL_E1000_ETHERNET_DEVICE(0x1076),
88 INTEL_E1000_ETHERNET_DEVICE(0x1077),
89 INTEL_E1000_ETHERNET_DEVICE(0x1078),
90 INTEL_E1000_ETHERNET_DEVICE(0x1079),
91 INTEL_E1000_ETHERNET_DEVICE(0x107A),
92 INTEL_E1000_ETHERNET_DEVICE(0x107B),
93 INTEL_E1000_ETHERNET_DEVICE(0x107C),
94 INTEL_E1000_ETHERNET_DEVICE(0x107D),
95 INTEL_E1000_ETHERNET_DEVICE(0x107E),
96 INTEL_E1000_ETHERNET_DEVICE(0x107F),
97 INTEL_E1000_ETHERNET_DEVICE(0x108A),
98 INTEL_E1000_ETHERNET_DEVICE(0x108B),
99 INTEL_E1000_ETHERNET_DEVICE(0x108C),
100 INTEL_E1000_ETHERNET_DEVICE(0x109A),
101 /* required last entry */
105 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
107 int e1000_up(struct e1000_adapter
*adapter
);
108 void e1000_down(struct e1000_adapter
*adapter
);
109 void e1000_reset(struct e1000_adapter
*adapter
);
110 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
);
111 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
);
112 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
);
113 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
);
114 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
);
115 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
116 struct e1000_tx_ring
*txdr
);
117 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
118 struct e1000_rx_ring
*rxdr
);
119 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
120 struct e1000_tx_ring
*tx_ring
);
121 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
122 struct e1000_rx_ring
*rx_ring
);
123 void e1000_update_stats(struct e1000_adapter
*adapter
);
125 /* Local Function Prototypes */
127 static int e1000_init_module(void);
128 static void e1000_exit_module(void);
129 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
130 static void __devexit
e1000_remove(struct pci_dev
*pdev
);
131 static int e1000_alloc_queues(struct e1000_adapter
*adapter
);
132 #ifdef CONFIG_E1000_MQ
133 static void e1000_setup_queue_mapping(struct e1000_adapter
*adapter
);
135 static int e1000_sw_init(struct e1000_adapter
*adapter
);
136 static int e1000_open(struct net_device
*netdev
);
137 static int e1000_close(struct net_device
*netdev
);
138 static void e1000_configure_tx(struct e1000_adapter
*adapter
);
139 static void e1000_configure_rx(struct e1000_adapter
*adapter
);
140 static void e1000_setup_rctl(struct e1000_adapter
*adapter
);
141 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
);
142 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
);
143 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
144 struct e1000_tx_ring
*tx_ring
);
145 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
146 struct e1000_rx_ring
*rx_ring
);
147 static void e1000_set_multi(struct net_device
*netdev
);
148 static void e1000_update_phy_info(unsigned long data
);
149 static void e1000_watchdog(unsigned long data
);
150 static void e1000_watchdog_task(struct e1000_adapter
*adapter
);
151 static void e1000_82547_tx_fifo_stall(unsigned long data
);
152 static int e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
);
153 static struct net_device_stats
* e1000_get_stats(struct net_device
*netdev
);
154 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
155 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
156 static irqreturn_t
e1000_intr(int irq
, void *data
, struct pt_regs
*regs
);
157 static boolean_t
e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
158 struct e1000_tx_ring
*tx_ring
);
159 #ifdef CONFIG_E1000_NAPI
160 static int e1000_clean(struct net_device
*poll_dev
, int *budget
);
161 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
162 struct e1000_rx_ring
*rx_ring
,
163 int *work_done
, int work_to_do
);
164 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
165 struct e1000_rx_ring
*rx_ring
,
166 int *work_done
, int work_to_do
);
168 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
169 struct e1000_rx_ring
*rx_ring
);
170 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
171 struct e1000_rx_ring
*rx_ring
);
173 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
174 struct e1000_rx_ring
*rx_ring
,
176 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
177 struct e1000_rx_ring
*rx_ring
,
179 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
180 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
182 void e1000_set_ethtool_ops(struct net_device
*netdev
);
183 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
184 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
185 static void e1000_tx_timeout(struct net_device
*dev
);
186 static void e1000_tx_timeout_task(struct net_device
*dev
);
187 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
188 static inline int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
189 struct sk_buff
*skb
);
191 static void e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
);
192 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
);
193 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
);
194 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
197 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
);
198 static int e1000_resume(struct pci_dev
*pdev
);
201 #ifdef CONFIG_NET_POLL_CONTROLLER
202 /* for netdump / net console */
203 static void e1000_netpoll (struct net_device
*netdev
);
206 #ifdef CONFIG_E1000_MQ
207 /* for multiple Rx queues */
208 void e1000_rx_schedule(void *data
);
211 /* Exported from other modules */
213 extern void e1000_check_options(struct e1000_adapter
*adapter
);
215 static struct pci_driver e1000_driver
= {
216 .name
= e1000_driver_name
,
217 .id_table
= e1000_pci_tbl
,
218 .probe
= e1000_probe
,
219 .remove
= __devexit_p(e1000_remove
),
220 /* Power Managment Hooks */
222 .suspend
= e1000_suspend
,
223 .resume
= e1000_resume
227 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
228 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
229 MODULE_LICENSE("GPL");
230 MODULE_VERSION(DRV_VERSION
);
232 static int debug
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
233 module_param(debug
, int, 0);
234 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
237 * e1000_init_module - Driver Registration Routine
239 * e1000_init_module is the first routine called when the driver is
240 * loaded. All it does is register with the PCI subsystem.
244 e1000_init_module(void)
247 printk(KERN_INFO
"%s - version %s\n",
248 e1000_driver_string
, e1000_driver_version
);
250 printk(KERN_INFO
"%s\n", e1000_copyright
);
252 ret
= pci_module_init(&e1000_driver
);
257 module_init(e1000_init_module
);
260 * e1000_exit_module - Driver Exit Cleanup Routine
262 * e1000_exit_module is called just before the driver is removed
267 e1000_exit_module(void)
269 pci_unregister_driver(&e1000_driver
);
272 module_exit(e1000_exit_module
);
275 * e1000_irq_disable - Mask off interrupt generation on the NIC
276 * @adapter: board private structure
280 e1000_irq_disable(struct e1000_adapter
*adapter
)
282 atomic_inc(&adapter
->irq_sem
);
283 E1000_WRITE_REG(&adapter
->hw
, IMC
, ~0);
284 E1000_WRITE_FLUSH(&adapter
->hw
);
285 synchronize_irq(adapter
->pdev
->irq
);
289 * e1000_irq_enable - Enable default interrupt generation settings
290 * @adapter: board private structure
294 e1000_irq_enable(struct e1000_adapter
*adapter
)
296 if(likely(atomic_dec_and_test(&adapter
->irq_sem
))) {
297 E1000_WRITE_REG(&adapter
->hw
, IMS
, IMS_ENABLE_MASK
);
298 E1000_WRITE_FLUSH(&adapter
->hw
);
303 e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
305 struct net_device
*netdev
= adapter
->netdev
;
306 uint16_t vid
= adapter
->hw
.mng_cookie
.vlan_id
;
307 uint16_t old_vid
= adapter
->mng_vlan_id
;
309 if(!adapter
->vlgrp
->vlan_devices
[vid
]) {
310 if(adapter
->hw
.mng_cookie
.status
&
311 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
312 e1000_vlan_rx_add_vid(netdev
, vid
);
313 adapter
->mng_vlan_id
= vid
;
315 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
317 if((old_vid
!= (uint16_t)E1000_MNG_VLAN_NONE
) &&
319 !adapter
->vlgrp
->vlan_devices
[old_vid
])
320 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
326 * e1000_release_hw_control - release control of the h/w to f/w
327 * @adapter: address of board private structure
329 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
330 * For ASF and Pass Through versions of f/w this means that the
331 * driver is no longer loaded. For AMT version (only with 82573) i
332 * of the f/w this means that the netowrk i/f is closed.
337 e1000_release_hw_control(struct e1000_adapter
*adapter
)
342 /* Let firmware taken over control of h/w */
343 switch (adapter
->hw
.mac_type
) {
346 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
347 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
348 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
351 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
352 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
353 swsm
& ~E1000_SWSM_DRV_LOAD
);
360 * e1000_get_hw_control - get control of the h/w from f/w
361 * @adapter: address of board private structure
363 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
364 * For ASF and Pass Through versions of f/w this means that
365 * the driver is loaded. For AMT version (only with 82573)
366 * of the f/w this means that the netowrk i/f is open.
371 e1000_get_hw_control(struct e1000_adapter
*adapter
)
375 /* Let firmware know the driver has taken over */
376 switch (adapter
->hw
.mac_type
) {
379 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
380 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
381 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
384 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
385 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
386 swsm
| E1000_SWSM_DRV_LOAD
);
394 e1000_up(struct e1000_adapter
*adapter
)
396 struct net_device
*netdev
= adapter
->netdev
;
399 /* hardware has been reset, we need to reload some things */
401 /* Reset the PHY if it was previously powered down */
402 if(adapter
->hw
.media_type
== e1000_media_type_copper
) {
404 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
405 if(mii_reg
& MII_CR_POWER_DOWN
)
406 e1000_phy_reset(&adapter
->hw
);
409 e1000_set_multi(netdev
);
411 e1000_restore_vlan(adapter
);
413 e1000_configure_tx(adapter
);
414 e1000_setup_rctl(adapter
);
415 e1000_configure_rx(adapter
);
416 /* call E1000_DESC_UNUSED which always leaves
417 * at least 1 descriptor unused to make sure
418 * next_to_use != next_to_clean */
419 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
420 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[i
];
421 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
424 #ifdef CONFIG_PCI_MSI
425 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
426 adapter
->have_msi
= TRUE
;
427 if((err
= pci_enable_msi(adapter
->pdev
))) {
429 "Unable to allocate MSI interrupt Error: %d\n", err
);
430 adapter
->have_msi
= FALSE
;
434 if((err
= request_irq(adapter
->pdev
->irq
, &e1000_intr
,
435 SA_SHIRQ
| SA_SAMPLE_RANDOM
,
436 netdev
->name
, netdev
))) {
438 "Unable to allocate interrupt Error: %d\n", err
);
442 #ifdef CONFIG_E1000_MQ
443 e1000_setup_queue_mapping(adapter
);
446 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
448 mod_timer(&adapter
->watchdog_timer
, jiffies
);
450 #ifdef CONFIG_E1000_NAPI
451 netif_poll_enable(netdev
);
453 e1000_irq_enable(adapter
);
459 e1000_down(struct e1000_adapter
*adapter
)
461 struct net_device
*netdev
= adapter
->netdev
;
462 boolean_t mng_mode_enabled
= (adapter
->hw
.mac_type
>= e1000_82571
) &&
463 e1000_check_mng_mode(&adapter
->hw
);
465 e1000_irq_disable(adapter
);
466 #ifdef CONFIG_E1000_MQ
467 while (atomic_read(&adapter
->rx_sched_call_data
.count
) != 0);
469 free_irq(adapter
->pdev
->irq
, netdev
);
470 #ifdef CONFIG_PCI_MSI
471 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
&&
472 adapter
->have_msi
== TRUE
)
473 pci_disable_msi(adapter
->pdev
);
475 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
476 del_timer_sync(&adapter
->watchdog_timer
);
477 del_timer_sync(&adapter
->phy_info_timer
);
479 #ifdef CONFIG_E1000_NAPI
480 netif_poll_disable(netdev
);
482 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
483 adapter
->link_speed
= 0;
484 adapter
->link_duplex
= 0;
485 netif_carrier_off(netdev
);
486 netif_stop_queue(netdev
);
488 e1000_reset(adapter
);
489 e1000_clean_all_tx_rings(adapter
);
490 e1000_clean_all_rx_rings(adapter
);
492 /* Power down the PHY so no link is implied when interface is down *
493 * The PHY cannot be powered down if any of the following is TRUE *
496 * (c) SoL/IDER session is active */
497 if (!adapter
->wol
&& adapter
->hw
.mac_type
>= e1000_82540
&&
498 adapter
->hw
.media_type
== e1000_media_type_copper
&&
499 !(E1000_READ_REG(&adapter
->hw
, MANC
) & E1000_MANC_SMBUS_EN
) &&
501 !e1000_check_phy_reset_block(&adapter
->hw
)) {
503 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
504 mii_reg
|= MII_CR_POWER_DOWN
;
505 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
511 e1000_reset(struct e1000_adapter
*adapter
)
514 uint16_t fc_high_water_mark
= E1000_FC_HIGH_DIFF
;
516 /* Repartition Pba for greater than 9k mtu
517 * To take effect CTRL.RST is required.
520 switch (adapter
->hw
.mac_type
) {
522 case e1000_82547_rev_2
:
537 if((adapter
->hw
.mac_type
!= e1000_82573
) &&
538 (adapter
->netdev
->mtu
> E1000_RXBUFFER_8192
))
539 pba
-= 8; /* allocate more FIFO for Tx */
542 if(adapter
->hw
.mac_type
== e1000_82547
) {
543 adapter
->tx_fifo_head
= 0;
544 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
545 adapter
->tx_fifo_size
=
546 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
547 atomic_set(&adapter
->tx_fifo_stall
, 0);
550 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
552 /* flow control settings */
553 /* Set the FC high water mark to 90% of the FIFO size.
554 * Required to clear last 3 LSB */
555 fc_high_water_mark
= ((pba
* 9216)/10) & 0xFFF8;
557 adapter
->hw
.fc_high_water
= fc_high_water_mark
;
558 adapter
->hw
.fc_low_water
= fc_high_water_mark
- 8;
559 adapter
->hw
.fc_pause_time
= E1000_FC_PAUSE_TIME
;
560 adapter
->hw
.fc_send_xon
= 1;
561 adapter
->hw
.fc
= adapter
->hw
.original_fc
;
563 /* Allow time for pending master requests to run */
564 e1000_reset_hw(&adapter
->hw
);
565 if(adapter
->hw
.mac_type
>= e1000_82544
)
566 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
567 if(e1000_init_hw(&adapter
->hw
))
568 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
569 e1000_update_mng_vlan(adapter
);
570 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
571 E1000_WRITE_REG(&adapter
->hw
, VET
, ETHERNET_IEEE_VLAN_TYPE
);
573 e1000_reset_adaptive(&adapter
->hw
);
574 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
575 if (adapter
->en_mng_pt
) {
576 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
577 manc
|= (E1000_MANC_ARP_EN
| E1000_MANC_EN_MNG2HOST
);
578 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
583 * e1000_probe - Device Initialization Routine
584 * @pdev: PCI device information struct
585 * @ent: entry in e1000_pci_tbl
587 * Returns 0 on success, negative on failure
589 * e1000_probe initializes an adapter identified by a pci_dev structure.
590 * The OS initialization, configuring of the adapter private structure,
591 * and a hardware reset occur.
595 e1000_probe(struct pci_dev
*pdev
,
596 const struct pci_device_id
*ent
)
598 struct net_device
*netdev
;
599 struct e1000_adapter
*adapter
;
600 unsigned long mmio_start
, mmio_len
;
602 static int cards_found
= 0;
603 int i
, err
, pci_using_dac
;
604 uint16_t eeprom_data
;
605 uint16_t eeprom_apme_mask
= E1000_EEPROM_APME
;
606 if((err
= pci_enable_device(pdev
)))
609 if(!(err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
))) {
612 if((err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
))) {
613 E1000_ERR("No usable DMA configuration, aborting\n");
619 if((err
= pci_request_regions(pdev
, e1000_driver_name
)))
622 pci_set_master(pdev
);
624 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
627 goto err_alloc_etherdev
;
630 SET_MODULE_OWNER(netdev
);
631 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
633 pci_set_drvdata(pdev
, netdev
);
634 adapter
= netdev_priv(netdev
);
635 adapter
->netdev
= netdev
;
636 adapter
->pdev
= pdev
;
637 adapter
->hw
.back
= adapter
;
638 adapter
->msg_enable
= (1 << debug
) - 1;
640 mmio_start
= pci_resource_start(pdev
, BAR_0
);
641 mmio_len
= pci_resource_len(pdev
, BAR_0
);
643 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
644 if(!adapter
->hw
.hw_addr
) {
649 for(i
= BAR_1
; i
<= BAR_5
; i
++) {
650 if(pci_resource_len(pdev
, i
) == 0)
652 if(pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
653 adapter
->hw
.io_base
= pci_resource_start(pdev
, i
);
658 netdev
->open
= &e1000_open
;
659 netdev
->stop
= &e1000_close
;
660 netdev
->hard_start_xmit
= &e1000_xmit_frame
;
661 netdev
->get_stats
= &e1000_get_stats
;
662 netdev
->set_multicast_list
= &e1000_set_multi
;
663 netdev
->set_mac_address
= &e1000_set_mac
;
664 netdev
->change_mtu
= &e1000_change_mtu
;
665 netdev
->do_ioctl
= &e1000_ioctl
;
666 e1000_set_ethtool_ops(netdev
);
667 netdev
->tx_timeout
= &e1000_tx_timeout
;
668 netdev
->watchdog_timeo
= 5 * HZ
;
669 #ifdef CONFIG_E1000_NAPI
670 netdev
->poll
= &e1000_clean
;
673 netdev
->vlan_rx_register
= e1000_vlan_rx_register
;
674 netdev
->vlan_rx_add_vid
= e1000_vlan_rx_add_vid
;
675 netdev
->vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
;
676 #ifdef CONFIG_NET_POLL_CONTROLLER
677 netdev
->poll_controller
= e1000_netpoll
;
679 strcpy(netdev
->name
, pci_name(pdev
));
681 netdev
->mem_start
= mmio_start
;
682 netdev
->mem_end
= mmio_start
+ mmio_len
;
683 netdev
->base_addr
= adapter
->hw
.io_base
;
685 adapter
->bd_number
= cards_found
;
687 /* setup the private structure */
689 if((err
= e1000_sw_init(adapter
)))
692 if((err
= e1000_check_phy_reset_block(&adapter
->hw
)))
693 DPRINTK(PROBE
, INFO
, "PHY reset is blocked due to SOL/IDER session.\n");
695 if(adapter
->hw
.mac_type
>= e1000_82543
) {
696 netdev
->features
= NETIF_F_SG
|
700 NETIF_F_HW_VLAN_FILTER
;
704 if((adapter
->hw
.mac_type
>= e1000_82544
) &&
705 (adapter
->hw
.mac_type
!= e1000_82547
))
706 netdev
->features
|= NETIF_F_TSO
;
708 #ifdef NETIF_F_TSO_IPV6
709 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
)
710 netdev
->features
|= NETIF_F_TSO_IPV6
;
714 netdev
->features
|= NETIF_F_HIGHDMA
;
716 /* hard_start_xmit is safe against parallel locking */
717 netdev
->features
|= NETIF_F_LLTX
;
719 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(&adapter
->hw
);
721 /* before reading the EEPROM, reset the controller to
722 * put the device in a known good starting state */
724 e1000_reset_hw(&adapter
->hw
);
726 /* make sure the EEPROM is good */
728 if(e1000_validate_eeprom_checksum(&adapter
->hw
) < 0) {
729 DPRINTK(PROBE
, ERR
, "The EEPROM Checksum Is Not Valid\n");
734 /* copy the MAC address out of the EEPROM */
736 if(e1000_read_mac_addr(&adapter
->hw
))
737 DPRINTK(PROBE
, ERR
, "EEPROM Read Error\n");
738 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
739 memcpy(netdev
->perm_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
741 if(!is_valid_ether_addr(netdev
->perm_addr
)) {
742 DPRINTK(PROBE
, ERR
, "Invalid MAC Address\n");
747 e1000_read_part_num(&adapter
->hw
, &(adapter
->part_num
));
749 e1000_get_bus_info(&adapter
->hw
);
751 init_timer(&adapter
->tx_fifo_stall_timer
);
752 adapter
->tx_fifo_stall_timer
.function
= &e1000_82547_tx_fifo_stall
;
753 adapter
->tx_fifo_stall_timer
.data
= (unsigned long) adapter
;
755 init_timer(&adapter
->watchdog_timer
);
756 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
757 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
759 INIT_WORK(&adapter
->watchdog_task
,
760 (void (*)(void *))e1000_watchdog_task
, adapter
);
762 init_timer(&adapter
->phy_info_timer
);
763 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
764 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
766 INIT_WORK(&adapter
->tx_timeout_task
,
767 (void (*)(void *))e1000_tx_timeout_task
, netdev
);
769 /* we're going to reset, so assume we have no link for now */
771 netif_carrier_off(netdev
);
772 netif_stop_queue(netdev
);
774 e1000_check_options(adapter
);
776 /* Initial Wake on LAN setting
777 * If APM wake is enabled in the EEPROM,
778 * enable the ACPI Magic Packet filter
781 switch(adapter
->hw
.mac_type
) {
782 case e1000_82542_rev2_0
:
783 case e1000_82542_rev2_1
:
787 e1000_read_eeprom(&adapter
->hw
,
788 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
789 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
792 case e1000_82546_rev_3
:
794 if((E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
)
795 && (adapter
->hw
.media_type
== e1000_media_type_copper
)) {
796 e1000_read_eeprom(&adapter
->hw
,
797 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
802 e1000_read_eeprom(&adapter
->hw
,
803 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
806 if(eeprom_data
& eeprom_apme_mask
)
807 adapter
->wol
|= E1000_WUFC_MAG
;
809 /* reset the hardware with the new settings */
810 e1000_reset(adapter
);
812 /* If the controller is 82573 and f/w is AMT, do not set
813 * DRV_LOAD until the interface is up. For all other cases,
814 * let the f/w know that the h/w is now under the control
816 if (adapter
->hw
.mac_type
!= e1000_82573
||
817 !e1000_check_mng_mode(&adapter
->hw
))
818 e1000_get_hw_control(adapter
);
820 strcpy(netdev
->name
, "eth%d");
821 if((err
= register_netdev(netdev
)))
824 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
832 iounmap(adapter
->hw
.hw_addr
);
836 pci_release_regions(pdev
);
841 * e1000_remove - Device Removal Routine
842 * @pdev: PCI device information struct
844 * e1000_remove is called by the PCI subsystem to alert the driver
845 * that it should release a PCI device. The could be caused by a
846 * Hot-Plug event, or because the driver is going to be removed from
850 static void __devexit
851 e1000_remove(struct pci_dev
*pdev
)
853 struct net_device
*netdev
= pci_get_drvdata(pdev
);
854 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
856 #ifdef CONFIG_E1000_NAPI
860 flush_scheduled_work();
862 if(adapter
->hw
.mac_type
>= e1000_82540
&&
863 adapter
->hw
.media_type
== e1000_media_type_copper
) {
864 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
865 if(manc
& E1000_MANC_SMBUS_EN
) {
866 manc
|= E1000_MANC_ARP_EN
;
867 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
871 /* Release control of h/w to f/w. If f/w is AMT enabled, this
872 * would have already happened in close and is redundant. */
873 e1000_release_hw_control(adapter
);
875 unregister_netdev(netdev
);
876 #ifdef CONFIG_E1000_NAPI
877 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
878 __dev_put(&adapter
->polling_netdev
[i
]);
881 if(!e1000_check_phy_reset_block(&adapter
->hw
))
882 e1000_phy_hw_reset(&adapter
->hw
);
884 kfree(adapter
->tx_ring
);
885 kfree(adapter
->rx_ring
);
886 #ifdef CONFIG_E1000_NAPI
887 kfree(adapter
->polling_netdev
);
890 iounmap(adapter
->hw
.hw_addr
);
891 pci_release_regions(pdev
);
893 #ifdef CONFIG_E1000_MQ
894 free_percpu(adapter
->cpu_netdev
);
895 free_percpu(adapter
->cpu_tx_ring
);
899 pci_disable_device(pdev
);
903 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
904 * @adapter: board private structure to initialize
906 * e1000_sw_init initializes the Adapter private data structure.
907 * Fields are initialized based on PCI device information and
908 * OS network device settings (MTU size).
912 e1000_sw_init(struct e1000_adapter
*adapter
)
914 struct e1000_hw
*hw
= &adapter
->hw
;
915 struct net_device
*netdev
= adapter
->netdev
;
916 struct pci_dev
*pdev
= adapter
->pdev
;
917 #ifdef CONFIG_E1000_NAPI
921 /* PCI config space info */
923 hw
->vendor_id
= pdev
->vendor
;
924 hw
->device_id
= pdev
->device
;
925 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
926 hw
->subsystem_id
= pdev
->subsystem_device
;
928 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
930 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
932 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
933 adapter
->rx_ps_bsize0
= E1000_RXBUFFER_256
;
934 hw
->max_frame_size
= netdev
->mtu
+
935 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
936 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
938 /* identify the MAC */
940 if(e1000_set_mac_type(hw
)) {
941 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
945 /* initialize eeprom parameters */
947 if(e1000_init_eeprom_params(hw
)) {
948 E1000_ERR("EEPROM initialization failed\n");
952 switch(hw
->mac_type
) {
957 case e1000_82541_rev_2
:
958 case e1000_82547_rev_2
:
959 hw
->phy_init_script
= 1;
963 e1000_set_media_type(hw
);
965 hw
->wait_autoneg_complete
= FALSE
;
966 hw
->tbi_compatibility_en
= TRUE
;
967 hw
->adaptive_ifs
= TRUE
;
971 if(hw
->media_type
== e1000_media_type_copper
) {
972 hw
->mdix
= AUTO_ALL_MODES
;
973 hw
->disable_polarity_correction
= FALSE
;
974 hw
->master_slave
= E1000_MASTER_SLAVE
;
977 #ifdef CONFIG_E1000_MQ
978 /* Number of supported queues */
979 switch (hw
->mac_type
) {
982 /* These controllers support 2 tx queues, but with a single
983 * qdisc implementation, multiple tx queues aren't quite as
984 * interesting. If we can find a logical way of mapping
985 * flows to a queue, then perhaps we can up the num_tx_queue
986 * count back to its default. Until then, we run the risk of
987 * terrible performance due to SACK overload. */
988 adapter
->num_tx_queues
= 1;
989 adapter
->num_rx_queues
= 2;
992 adapter
->num_tx_queues
= 1;
993 adapter
->num_rx_queues
= 1;
996 adapter
->num_rx_queues
= min(adapter
->num_rx_queues
, num_online_cpus());
997 adapter
->num_tx_queues
= min(adapter
->num_tx_queues
, num_online_cpus());
998 DPRINTK(DRV
, INFO
, "Multiqueue Enabled: Rx Queue count = %u %s\n",
999 adapter
->num_rx_queues
,
1000 ((adapter
->num_rx_queues
== 1)
1001 ? ((num_online_cpus() > 1)
1002 ? "(due to unsupported feature in current adapter)"
1003 : "(due to unsupported system configuration)")
1005 DPRINTK(DRV
, INFO
, "Multiqueue Enabled: Tx Queue count = %u\n",
1006 adapter
->num_tx_queues
);
1008 adapter
->num_tx_queues
= 1;
1009 adapter
->num_rx_queues
= 1;
1012 if (e1000_alloc_queues(adapter
)) {
1013 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
1017 #ifdef CONFIG_E1000_NAPI
1018 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1019 adapter
->polling_netdev
[i
].priv
= adapter
;
1020 adapter
->polling_netdev
[i
].poll
= &e1000_clean
;
1021 adapter
->polling_netdev
[i
].weight
= 64;
1022 dev_hold(&adapter
->polling_netdev
[i
]);
1023 set_bit(__LINK_STATE_START
, &adapter
->polling_netdev
[i
].state
);
1025 spin_lock_init(&adapter
->tx_queue_lock
);
1028 atomic_set(&adapter
->irq_sem
, 1);
1029 spin_lock_init(&adapter
->stats_lock
);
1035 * e1000_alloc_queues - Allocate memory for all rings
1036 * @adapter: board private structure to initialize
1038 * We allocate one ring per queue at run-time since we don't know the
1039 * number of queues at compile-time. The polling_netdev array is
1040 * intended for Multiqueue, but should work fine with a single queue.
1043 static int __devinit
1044 e1000_alloc_queues(struct e1000_adapter
*adapter
)
1048 size
= sizeof(struct e1000_tx_ring
) * adapter
->num_tx_queues
;
1049 adapter
->tx_ring
= kmalloc(size
, GFP_KERNEL
);
1050 if (!adapter
->tx_ring
)
1052 memset(adapter
->tx_ring
, 0, size
);
1054 size
= sizeof(struct e1000_rx_ring
) * adapter
->num_rx_queues
;
1055 adapter
->rx_ring
= kmalloc(size
, GFP_KERNEL
);
1056 if (!adapter
->rx_ring
) {
1057 kfree(adapter
->tx_ring
);
1060 memset(adapter
->rx_ring
, 0, size
);
1062 #ifdef CONFIG_E1000_NAPI
1063 size
= sizeof(struct net_device
) * adapter
->num_rx_queues
;
1064 adapter
->polling_netdev
= kmalloc(size
, GFP_KERNEL
);
1065 if (!adapter
->polling_netdev
) {
1066 kfree(adapter
->tx_ring
);
1067 kfree(adapter
->rx_ring
);
1070 memset(adapter
->polling_netdev
, 0, size
);
1073 #ifdef CONFIG_E1000_MQ
1074 adapter
->rx_sched_call_data
.func
= e1000_rx_schedule
;
1075 adapter
->rx_sched_call_data
.info
= adapter
->netdev
;
1077 adapter
->cpu_netdev
= alloc_percpu(struct net_device
*);
1078 adapter
->cpu_tx_ring
= alloc_percpu(struct e1000_tx_ring
*);
1081 return E1000_SUCCESS
;
1084 #ifdef CONFIG_E1000_MQ
1085 static void __devinit
1086 e1000_setup_queue_mapping(struct e1000_adapter
*adapter
)
1090 adapter
->rx_sched_call_data
.func
= e1000_rx_schedule
;
1091 adapter
->rx_sched_call_data
.info
= adapter
->netdev
;
1092 cpus_clear(adapter
->rx_sched_call_data
.cpumask
);
1094 adapter
->cpu_netdev
= alloc_percpu(struct net_device
*);
1095 adapter
->cpu_tx_ring
= alloc_percpu(struct e1000_tx_ring
*);
1099 for_each_online_cpu(cpu
) {
1100 *per_cpu_ptr(adapter
->cpu_tx_ring
, cpu
) = &adapter
->tx_ring
[i
% adapter
->num_tx_queues
];
1101 /* This is incomplete because we'd like to assign separate
1102 * physical cpus to these netdev polling structures and
1103 * avoid saturating a subset of cpus.
1105 if (i
< adapter
->num_rx_queues
) {
1106 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = &adapter
->polling_netdev
[i
];
1107 adapter
->rx_ring
[i
].cpu
= cpu
;
1108 cpu_set(cpu
, adapter
->cpumask
);
1110 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = NULL
;
1114 unlock_cpu_hotplug();
1119 * e1000_open - Called when a network interface is made active
1120 * @netdev: network interface device structure
1122 * Returns 0 on success, negative value on failure
1124 * The open entry point is called when a network interface is made
1125 * active by the system (IFF_UP). At this point all resources needed
1126 * for transmit and receive operations are allocated, the interrupt
1127 * handler is registered with the OS, the watchdog timer is started,
1128 * and the stack is notified that the interface is ready.
1132 e1000_open(struct net_device
*netdev
)
1134 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1137 /* allocate transmit descriptors */
1139 if ((err
= e1000_setup_all_tx_resources(adapter
)))
1142 /* allocate receive descriptors */
1144 if ((err
= e1000_setup_all_rx_resources(adapter
)))
1147 if((err
= e1000_up(adapter
)))
1149 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1150 if((adapter
->hw
.mng_cookie
.status
&
1151 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1152 e1000_update_mng_vlan(adapter
);
1155 /* If AMT is enabled, let the firmware know that the network
1156 * interface is now open */
1157 if (adapter
->hw
.mac_type
== e1000_82573
&&
1158 e1000_check_mng_mode(&adapter
->hw
))
1159 e1000_get_hw_control(adapter
);
1161 return E1000_SUCCESS
;
1164 e1000_free_all_rx_resources(adapter
);
1166 e1000_free_all_tx_resources(adapter
);
1168 e1000_reset(adapter
);
1174 * e1000_close - Disables a network interface
1175 * @netdev: network interface device structure
1177 * Returns 0, this is not allowed to fail
1179 * The close entry point is called when an interface is de-activated
1180 * by the OS. The hardware is still under the drivers control, but
1181 * needs to be disabled. A global MAC reset is issued to stop the
1182 * hardware, and all transmit and receive resources are freed.
1186 e1000_close(struct net_device
*netdev
)
1188 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1190 e1000_down(adapter
);
1192 e1000_free_all_tx_resources(adapter
);
1193 e1000_free_all_rx_resources(adapter
);
1195 if((adapter
->hw
.mng_cookie
.status
&
1196 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1197 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1200 /* If AMT is enabled, let the firmware know that the network
1201 * interface is now closed */
1202 if (adapter
->hw
.mac_type
== e1000_82573
&&
1203 e1000_check_mng_mode(&adapter
->hw
))
1204 e1000_release_hw_control(adapter
);
1210 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1211 * @adapter: address of board private structure
1212 * @start: address of beginning of memory
1213 * @len: length of memory
1215 static inline boolean_t
1216 e1000_check_64k_bound(struct e1000_adapter
*adapter
,
1217 void *start
, unsigned long len
)
1219 unsigned long begin
= (unsigned long) start
;
1220 unsigned long end
= begin
+ len
;
1222 /* First rev 82545 and 82546 need to not allow any memory
1223 * write location to cross 64k boundary due to errata 23 */
1224 if (adapter
->hw
.mac_type
== e1000_82545
||
1225 adapter
->hw
.mac_type
== e1000_82546
) {
1226 return ((begin
^ (end
- 1)) >> 16) != 0 ? FALSE
: TRUE
;
1233 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1234 * @adapter: board private structure
1235 * @txdr: tx descriptor ring (for a specific queue) to setup
1237 * Return 0 on success, negative on failure
1241 e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1242 struct e1000_tx_ring
*txdr
)
1244 struct pci_dev
*pdev
= adapter
->pdev
;
1247 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1249 txdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1250 if(!txdr
->buffer_info
) {
1252 "Unable to allocate memory for the transmit descriptor ring\n");
1255 memset(txdr
->buffer_info
, 0, size
);
1257 /* round up to nearest 4K */
1259 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1260 E1000_ROUNDUP(txdr
->size
, 4096);
1262 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1265 vfree(txdr
->buffer_info
);
1267 "Unable to allocate memory for the transmit descriptor ring\n");
1271 /* Fix for errata 23, can't cross 64kB boundary */
1272 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1273 void *olddesc
= txdr
->desc
;
1274 dma_addr_t olddma
= txdr
->dma
;
1275 DPRINTK(TX_ERR
, ERR
, "txdr align check failed: %u bytes "
1276 "at %p\n", txdr
->size
, txdr
->desc
);
1277 /* Try again, without freeing the previous */
1278 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1280 /* Failed allocation, critical failure */
1281 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1282 goto setup_tx_desc_die
;
1285 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1287 pci_free_consistent(pdev
, txdr
->size
, txdr
->desc
,
1289 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1291 "Unable to allocate aligned memory "
1292 "for the transmit descriptor ring\n");
1293 vfree(txdr
->buffer_info
);
1296 /* Free old allocation, new allocation was successful */
1297 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1300 memset(txdr
->desc
, 0, txdr
->size
);
1302 txdr
->next_to_use
= 0;
1303 txdr
->next_to_clean
= 0;
1304 spin_lock_init(&txdr
->tx_lock
);
1310 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1311 * (Descriptors) for all queues
1312 * @adapter: board private structure
1314 * If this function returns with an error, then it's possible one or
1315 * more of the rings is populated (while the rest are not). It is the
1316 * callers duty to clean those orphaned rings.
1318 * Return 0 on success, negative on failure
1322 e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1326 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1327 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1330 "Allocation for Tx Queue %u failed\n", i
);
1339 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1340 * @adapter: board private structure
1342 * Configure the Tx unit of the MAC after a reset.
1346 e1000_configure_tx(struct e1000_adapter
*adapter
)
1349 struct e1000_hw
*hw
= &adapter
->hw
;
1350 uint32_t tdlen
, tctl
, tipg
, tarc
;
1351 uint32_t ipgr1
, ipgr2
;
1353 /* Setup the HW Tx Head and Tail descriptor pointers */
1355 switch (adapter
->num_tx_queues
) {
1357 tdba
= adapter
->tx_ring
[1].dma
;
1358 tdlen
= adapter
->tx_ring
[1].count
*
1359 sizeof(struct e1000_tx_desc
);
1360 E1000_WRITE_REG(hw
, TDBAL1
, (tdba
& 0x00000000ffffffffULL
));
1361 E1000_WRITE_REG(hw
, TDBAH1
, (tdba
>> 32));
1362 E1000_WRITE_REG(hw
, TDLEN1
, tdlen
);
1363 E1000_WRITE_REG(hw
, TDH1
, 0);
1364 E1000_WRITE_REG(hw
, TDT1
, 0);
1365 adapter
->tx_ring
[1].tdh
= E1000_TDH1
;
1366 adapter
->tx_ring
[1].tdt
= E1000_TDT1
;
1370 tdba
= adapter
->tx_ring
[0].dma
;
1371 tdlen
= adapter
->tx_ring
[0].count
*
1372 sizeof(struct e1000_tx_desc
);
1373 E1000_WRITE_REG(hw
, TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1374 E1000_WRITE_REG(hw
, TDBAH
, (tdba
>> 32));
1375 E1000_WRITE_REG(hw
, TDLEN
, tdlen
);
1376 E1000_WRITE_REG(hw
, TDH
, 0);
1377 E1000_WRITE_REG(hw
, TDT
, 0);
1378 adapter
->tx_ring
[0].tdh
= E1000_TDH
;
1379 adapter
->tx_ring
[0].tdt
= E1000_TDT
;
1383 /* Set the default values for the Tx Inter Packet Gap timer */
1385 if (hw
->media_type
== e1000_media_type_fiber
||
1386 hw
->media_type
== e1000_media_type_internal_serdes
)
1387 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1389 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1391 switch (hw
->mac_type
) {
1392 case e1000_82542_rev2_0
:
1393 case e1000_82542_rev2_1
:
1394 tipg
= DEFAULT_82542_TIPG_IPGT
;
1395 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
1396 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
1399 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
1400 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
1403 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
1404 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
1405 E1000_WRITE_REG(hw
, TIPG
, tipg
);
1407 /* Set the Tx Interrupt Delay register */
1409 E1000_WRITE_REG(hw
, TIDV
, adapter
->tx_int_delay
);
1410 if (hw
->mac_type
>= e1000_82540
)
1411 E1000_WRITE_REG(hw
, TADV
, adapter
->tx_abs_int_delay
);
1413 /* Program the Transmit Control Register */
1415 tctl
= E1000_READ_REG(hw
, TCTL
);
1417 tctl
&= ~E1000_TCTL_CT
;
1418 tctl
|= E1000_TCTL_EN
| E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1419 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1421 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1423 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
1424 tarc
= E1000_READ_REG(hw
, TARC0
);
1425 tarc
|= ((1 << 25) | (1 << 21));
1426 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1427 tarc
= E1000_READ_REG(hw
, TARC1
);
1429 if (tctl
& E1000_TCTL_MULR
)
1433 E1000_WRITE_REG(hw
, TARC1
, tarc
);
1436 e1000_config_collision_dist(hw
);
1438 /* Setup Transmit Descriptor Settings for eop descriptor */
1439 adapter
->txd_cmd
= E1000_TXD_CMD_IDE
| E1000_TXD_CMD_EOP
|
1442 if (hw
->mac_type
< e1000_82543
)
1443 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1445 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1447 /* Cache if we're 82544 running in PCI-X because we'll
1448 * need this to apply a workaround later in the send path. */
1449 if (hw
->mac_type
== e1000_82544
&&
1450 hw
->bus_type
== e1000_bus_type_pcix
)
1451 adapter
->pcix_82544
= 1;
1455 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1456 * @adapter: board private structure
1457 * @rxdr: rx descriptor ring (for a specific queue) to setup
1459 * Returns 0 on success, negative on failure
1463 e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1464 struct e1000_rx_ring
*rxdr
)
1466 struct pci_dev
*pdev
= adapter
->pdev
;
1469 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1470 rxdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1471 if (!rxdr
->buffer_info
) {
1473 "Unable to allocate memory for the receive descriptor ring\n");
1476 memset(rxdr
->buffer_info
, 0, size
);
1478 size
= sizeof(struct e1000_ps_page
) * rxdr
->count
;
1479 rxdr
->ps_page
= kmalloc(size
, GFP_KERNEL
);
1480 if(!rxdr
->ps_page
) {
1481 vfree(rxdr
->buffer_info
);
1483 "Unable to allocate memory for the receive descriptor ring\n");
1486 memset(rxdr
->ps_page
, 0, size
);
1488 size
= sizeof(struct e1000_ps_page_dma
) * rxdr
->count
;
1489 rxdr
->ps_page_dma
= kmalloc(size
, GFP_KERNEL
);
1490 if(!rxdr
->ps_page_dma
) {
1491 vfree(rxdr
->buffer_info
);
1492 kfree(rxdr
->ps_page
);
1494 "Unable to allocate memory for the receive descriptor ring\n");
1497 memset(rxdr
->ps_page_dma
, 0, size
);
1499 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
)
1500 desc_len
= sizeof(struct e1000_rx_desc
);
1502 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1504 /* Round up to nearest 4K */
1506 rxdr
->size
= rxdr
->count
* desc_len
;
1507 E1000_ROUNDUP(rxdr
->size
, 4096);
1509 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1513 "Unable to allocate memory for the receive descriptor ring\n");
1515 vfree(rxdr
->buffer_info
);
1516 kfree(rxdr
->ps_page
);
1517 kfree(rxdr
->ps_page_dma
);
1521 /* Fix for errata 23, can't cross 64kB boundary */
1522 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1523 void *olddesc
= rxdr
->desc
;
1524 dma_addr_t olddma
= rxdr
->dma
;
1525 DPRINTK(RX_ERR
, ERR
, "rxdr align check failed: %u bytes "
1526 "at %p\n", rxdr
->size
, rxdr
->desc
);
1527 /* Try again, without freeing the previous */
1528 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1529 /* Failed allocation, critical failure */
1531 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1533 "Unable to allocate memory "
1534 "for the receive descriptor ring\n");
1535 goto setup_rx_desc_die
;
1538 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1540 pci_free_consistent(pdev
, rxdr
->size
, rxdr
->desc
,
1542 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1544 "Unable to allocate aligned memory "
1545 "for the receive descriptor ring\n");
1546 goto setup_rx_desc_die
;
1548 /* Free old allocation, new allocation was successful */
1549 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1552 memset(rxdr
->desc
, 0, rxdr
->size
);
1554 rxdr
->next_to_clean
= 0;
1555 rxdr
->next_to_use
= 0;
1556 rxdr
->rx_skb_top
= NULL
;
1557 rxdr
->rx_skb_prev
= NULL
;
1563 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1564 * (Descriptors) for all queues
1565 * @adapter: board private structure
1567 * If this function returns with an error, then it's possible one or
1568 * more of the rings is populated (while the rest are not). It is the
1569 * callers duty to clean those orphaned rings.
1571 * Return 0 on success, negative on failure
1575 e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1579 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1580 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1583 "Allocation for Rx Queue %u failed\n", i
);
1592 * e1000_setup_rctl - configure the receive control registers
1593 * @adapter: Board private structure
1595 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1596 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1598 e1000_setup_rctl(struct e1000_adapter
*adapter
)
1600 uint32_t rctl
, rfctl
;
1601 uint32_t psrctl
= 0;
1602 #ifdef CONFIG_E1000_PACKET_SPLIT
1606 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1608 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1610 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1611 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1612 (adapter
->hw
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1614 if (adapter
->hw
.mac_type
> e1000_82543
)
1615 rctl
|= E1000_RCTL_SECRC
;
1617 if (adapter
->hw
.tbi_compatibility_on
== 1)
1618 rctl
|= E1000_RCTL_SBP
;
1620 rctl
&= ~E1000_RCTL_SBP
;
1622 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1623 rctl
&= ~E1000_RCTL_LPE
;
1625 rctl
|= E1000_RCTL_LPE
;
1627 /* Setup buffer sizes */
1628 if(adapter
->hw
.mac_type
>= e1000_82571
) {
1629 /* We can now specify buffers in 1K increments.
1630 * BSIZE and BSEX are ignored in this case. */
1631 rctl
|= adapter
->rx_buffer_len
<< 0x11;
1633 rctl
&= ~E1000_RCTL_SZ_4096
;
1634 rctl
|= E1000_RCTL_BSEX
;
1635 switch (adapter
->rx_buffer_len
) {
1636 case E1000_RXBUFFER_2048
:
1638 rctl
|= E1000_RCTL_SZ_2048
;
1639 rctl
&= ~E1000_RCTL_BSEX
;
1641 case E1000_RXBUFFER_4096
:
1642 rctl
|= E1000_RCTL_SZ_4096
;
1644 case E1000_RXBUFFER_8192
:
1645 rctl
|= E1000_RCTL_SZ_8192
;
1647 case E1000_RXBUFFER_16384
:
1648 rctl
|= E1000_RCTL_SZ_16384
;
1653 #ifdef CONFIG_E1000_PACKET_SPLIT
1654 /* 82571 and greater support packet-split where the protocol
1655 * header is placed in skb->data and the packet data is
1656 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1657 * In the case of a non-split, skb->data is linearly filled,
1658 * followed by the page buffers. Therefore, skb->data is
1659 * sized to hold the largest protocol header.
1661 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
1662 if ((adapter
->hw
.mac_type
> e1000_82547_rev_2
) && (pages
<= 3) &&
1664 adapter
->rx_ps_pages
= pages
;
1666 adapter
->rx_ps_pages
= 0;
1668 if (adapter
->rx_ps_pages
) {
1669 /* Configure extra packet-split registers */
1670 rfctl
= E1000_READ_REG(&adapter
->hw
, RFCTL
);
1671 rfctl
|= E1000_RFCTL_EXTEN
;
1672 /* disable IPv6 packet split support */
1673 rfctl
|= E1000_RFCTL_IPV6_DIS
;
1674 E1000_WRITE_REG(&adapter
->hw
, RFCTL
, rfctl
);
1676 rctl
|= E1000_RCTL_DTYP_PS
| E1000_RCTL_SECRC
;
1678 psrctl
|= adapter
->rx_ps_bsize0
>>
1679 E1000_PSRCTL_BSIZE0_SHIFT
;
1681 switch (adapter
->rx_ps_pages
) {
1683 psrctl
|= PAGE_SIZE
<<
1684 E1000_PSRCTL_BSIZE3_SHIFT
;
1686 psrctl
|= PAGE_SIZE
<<
1687 E1000_PSRCTL_BSIZE2_SHIFT
;
1689 psrctl
|= PAGE_SIZE
>>
1690 E1000_PSRCTL_BSIZE1_SHIFT
;
1694 E1000_WRITE_REG(&adapter
->hw
, PSRCTL
, psrctl
);
1697 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1701 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1702 * @adapter: board private structure
1704 * Configure the Rx unit of the MAC after a reset.
1708 e1000_configure_rx(struct e1000_adapter
*adapter
)
1711 struct e1000_hw
*hw
= &adapter
->hw
;
1712 uint32_t rdlen
, rctl
, rxcsum
, ctrl_ext
;
1713 #ifdef CONFIG_E1000_MQ
1714 uint32_t reta
, mrqc
;
1718 if (adapter
->rx_ps_pages
) {
1719 rdlen
= adapter
->rx_ring
[0].count
*
1720 sizeof(union e1000_rx_desc_packet_split
);
1721 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
1722 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
1724 rdlen
= adapter
->rx_ring
[0].count
*
1725 sizeof(struct e1000_rx_desc
);
1726 adapter
->clean_rx
= e1000_clean_rx_irq
;
1727 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1730 /* disable receives while setting up the descriptors */
1731 rctl
= E1000_READ_REG(hw
, RCTL
);
1732 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
1734 /* set the Receive Delay Timer Register */
1735 E1000_WRITE_REG(hw
, RDTR
, adapter
->rx_int_delay
);
1737 if (hw
->mac_type
>= e1000_82540
) {
1738 E1000_WRITE_REG(hw
, RADV
, adapter
->rx_abs_int_delay
);
1739 if(adapter
->itr
> 1)
1740 E1000_WRITE_REG(hw
, ITR
,
1741 1000000000 / (adapter
->itr
* 256));
1744 if (hw
->mac_type
>= e1000_82571
) {
1745 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1746 /* Reset delay timers after every interrupt */
1747 ctrl_ext
|= E1000_CTRL_EXT_CANC
;
1748 #ifdef CONFIG_E1000_NAPI
1749 /* Auto-Mask interrupts upon ICR read. */
1750 ctrl_ext
|= E1000_CTRL_EXT_IAME
;
1752 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
1753 E1000_WRITE_REG(hw
, IAM
, ~0);
1754 E1000_WRITE_FLUSH(hw
);
1757 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1758 * the Base and Length of the Rx Descriptor Ring */
1759 switch (adapter
->num_rx_queues
) {
1760 #ifdef CONFIG_E1000_MQ
1762 rdba
= adapter
->rx_ring
[1].dma
;
1763 E1000_WRITE_REG(hw
, RDBAL1
, (rdba
& 0x00000000ffffffffULL
));
1764 E1000_WRITE_REG(hw
, RDBAH1
, (rdba
>> 32));
1765 E1000_WRITE_REG(hw
, RDLEN1
, rdlen
);
1766 E1000_WRITE_REG(hw
, RDH1
, 0);
1767 E1000_WRITE_REG(hw
, RDT1
, 0);
1768 adapter
->rx_ring
[1].rdh
= E1000_RDH1
;
1769 adapter
->rx_ring
[1].rdt
= E1000_RDT1
;
1774 rdba
= adapter
->rx_ring
[0].dma
;
1775 E1000_WRITE_REG(hw
, RDBAL
, (rdba
& 0x00000000ffffffffULL
));
1776 E1000_WRITE_REG(hw
, RDBAH
, (rdba
>> 32));
1777 E1000_WRITE_REG(hw
, RDLEN
, rdlen
);
1778 E1000_WRITE_REG(hw
, RDH
, 0);
1779 E1000_WRITE_REG(hw
, RDT
, 0);
1780 adapter
->rx_ring
[0].rdh
= E1000_RDH
;
1781 adapter
->rx_ring
[0].rdt
= E1000_RDT
;
1785 #ifdef CONFIG_E1000_MQ
1786 if (adapter
->num_rx_queues
> 1) {
1787 uint32_t random
[10];
1789 get_random_bytes(&random
[0], 40);
1791 if (hw
->mac_type
<= e1000_82572
) {
1792 E1000_WRITE_REG(hw
, RSSIR
, 0);
1793 E1000_WRITE_REG(hw
, RSSIM
, 0);
1796 switch (adapter
->num_rx_queues
) {
1800 mrqc
= E1000_MRQC_ENABLE_RSS_2Q
;
1804 /* Fill out redirection table */
1805 for (i
= 0; i
< 32; i
++)
1806 E1000_WRITE_REG_ARRAY(hw
, RETA
, i
, reta
);
1807 /* Fill out hash function seeds */
1808 for (i
= 0; i
< 10; i
++)
1809 E1000_WRITE_REG_ARRAY(hw
, RSSRK
, i
, random
[i
]);
1811 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4
|
1812 E1000_MRQC_RSS_FIELD_IPV4_TCP
);
1813 E1000_WRITE_REG(hw
, MRQC
, mrqc
);
1816 /* Multiqueue and packet checksumming are mutually exclusive. */
1817 if (hw
->mac_type
>= e1000_82571
) {
1818 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1819 rxcsum
|= E1000_RXCSUM_PCSD
;
1820 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1825 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1826 if (hw
->mac_type
>= e1000_82543
) {
1827 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1828 if(adapter
->rx_csum
== TRUE
) {
1829 rxcsum
|= E1000_RXCSUM_TUOFL
;
1831 /* Enable 82571 IPv4 payload checksum for UDP fragments
1832 * Must be used in conjunction with packet-split. */
1833 if ((hw
->mac_type
>= e1000_82571
) &&
1834 (adapter
->rx_ps_pages
)) {
1835 rxcsum
|= E1000_RXCSUM_IPPCSE
;
1838 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1839 /* don't need to clear IPPCSE as it defaults to 0 */
1841 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1843 #endif /* CONFIG_E1000_MQ */
1845 if (hw
->mac_type
== e1000_82573
)
1846 E1000_WRITE_REG(hw
, ERT
, 0x0100);
1848 /* Enable Receives */
1849 E1000_WRITE_REG(hw
, RCTL
, rctl
);
1853 * e1000_free_tx_resources - Free Tx Resources per Queue
1854 * @adapter: board private structure
1855 * @tx_ring: Tx descriptor ring for a specific queue
1857 * Free all transmit software resources
1861 e1000_free_tx_resources(struct e1000_adapter
*adapter
,
1862 struct e1000_tx_ring
*tx_ring
)
1864 struct pci_dev
*pdev
= adapter
->pdev
;
1866 e1000_clean_tx_ring(adapter
, tx_ring
);
1868 vfree(tx_ring
->buffer_info
);
1869 tx_ring
->buffer_info
= NULL
;
1871 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
1873 tx_ring
->desc
= NULL
;
1877 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1878 * @adapter: board private structure
1880 * Free all transmit software resources
1884 e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
1888 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1889 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1893 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
1894 struct e1000_buffer
*buffer_info
)
1896 if(buffer_info
->dma
) {
1897 pci_unmap_page(adapter
->pdev
,
1899 buffer_info
->length
,
1901 buffer_info
->dma
= 0;
1903 if(buffer_info
->skb
) {
1904 dev_kfree_skb_any(buffer_info
->skb
);
1905 buffer_info
->skb
= NULL
;
1910 * e1000_clean_tx_ring - Free Tx Buffers
1911 * @adapter: board private structure
1912 * @tx_ring: ring to be cleaned
1916 e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
1917 struct e1000_tx_ring
*tx_ring
)
1919 struct e1000_buffer
*buffer_info
;
1923 /* Free all the Tx ring sk_buffs */
1925 for(i
= 0; i
< tx_ring
->count
; i
++) {
1926 buffer_info
= &tx_ring
->buffer_info
[i
];
1927 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
1930 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1931 memset(tx_ring
->buffer_info
, 0, size
);
1933 /* Zero out the descriptor ring */
1935 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1937 tx_ring
->next_to_use
= 0;
1938 tx_ring
->next_to_clean
= 0;
1939 tx_ring
->last_tx_tso
= 0;
1941 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdh
);
1942 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
1946 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1947 * @adapter: board private structure
1951 e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
1955 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1956 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1960 * e1000_free_rx_resources - Free Rx Resources
1961 * @adapter: board private structure
1962 * @rx_ring: ring to clean the resources from
1964 * Free all receive software resources
1968 e1000_free_rx_resources(struct e1000_adapter
*adapter
,
1969 struct e1000_rx_ring
*rx_ring
)
1971 struct pci_dev
*pdev
= adapter
->pdev
;
1973 e1000_clean_rx_ring(adapter
, rx_ring
);
1975 vfree(rx_ring
->buffer_info
);
1976 rx_ring
->buffer_info
= NULL
;
1977 kfree(rx_ring
->ps_page
);
1978 rx_ring
->ps_page
= NULL
;
1979 kfree(rx_ring
->ps_page_dma
);
1980 rx_ring
->ps_page_dma
= NULL
;
1982 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
1984 rx_ring
->desc
= NULL
;
1988 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1989 * @adapter: board private structure
1991 * Free all receive software resources
1995 e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
1999 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2000 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2004 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2005 * @adapter: board private structure
2006 * @rx_ring: ring to free buffers from
2010 e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
2011 struct e1000_rx_ring
*rx_ring
)
2013 struct e1000_buffer
*buffer_info
;
2014 struct e1000_ps_page
*ps_page
;
2015 struct e1000_ps_page_dma
*ps_page_dma
;
2016 struct pci_dev
*pdev
= adapter
->pdev
;
2020 /* Free all the Rx ring sk_buffs */
2022 for(i
= 0; i
< rx_ring
->count
; i
++) {
2023 buffer_info
= &rx_ring
->buffer_info
[i
];
2024 if(buffer_info
->skb
) {
2025 ps_page
= &rx_ring
->ps_page
[i
];
2026 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2027 pci_unmap_single(pdev
,
2029 buffer_info
->length
,
2030 PCI_DMA_FROMDEVICE
);
2032 dev_kfree_skb(buffer_info
->skb
);
2033 buffer_info
->skb
= NULL
;
2035 ps_page
= &rx_ring
->ps_page
[i
];
2036 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
2037 for (j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
2038 if (!ps_page
->ps_page
[j
]) break;
2039 pci_unmap_page(pdev
,
2040 ps_page_dma
->ps_page_dma
[j
],
2041 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
2042 ps_page_dma
->ps_page_dma
[j
] = 0;
2043 put_page(ps_page
->ps_page
[j
]);
2044 ps_page
->ps_page
[j
] = NULL
;
2048 /* there also may be some cached data in our adapter */
2049 if (rx_ring
->rx_skb_top
) {
2050 dev_kfree_skb(rx_ring
->rx_skb_top
);
2052 /* rx_skb_prev will be wiped out by rx_skb_top */
2053 rx_ring
->rx_skb_top
= NULL
;
2054 rx_ring
->rx_skb_prev
= NULL
;
2058 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2059 memset(rx_ring
->buffer_info
, 0, size
);
2060 size
= sizeof(struct e1000_ps_page
) * rx_ring
->count
;
2061 memset(rx_ring
->ps_page
, 0, size
);
2062 size
= sizeof(struct e1000_ps_page_dma
) * rx_ring
->count
;
2063 memset(rx_ring
->ps_page_dma
, 0, size
);
2065 /* Zero out the descriptor ring */
2067 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2069 rx_ring
->next_to_clean
= 0;
2070 rx_ring
->next_to_use
= 0;
2072 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdh
);
2073 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
2077 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2078 * @adapter: board private structure
2082 e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2086 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2087 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2090 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2091 * and memory write and invalidate disabled for certain operations
2094 e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2096 struct net_device
*netdev
= adapter
->netdev
;
2099 e1000_pci_clear_mwi(&adapter
->hw
);
2101 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2102 rctl
|= E1000_RCTL_RST
;
2103 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2104 E1000_WRITE_FLUSH(&adapter
->hw
);
2107 if(netif_running(netdev
))
2108 e1000_clean_all_rx_rings(adapter
);
2112 e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2114 struct net_device
*netdev
= adapter
->netdev
;
2117 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2118 rctl
&= ~E1000_RCTL_RST
;
2119 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2120 E1000_WRITE_FLUSH(&adapter
->hw
);
2123 if(adapter
->hw
.pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2124 e1000_pci_set_mwi(&adapter
->hw
);
2126 if(netif_running(netdev
)) {
2127 e1000_configure_rx(adapter
);
2128 /* No need to loop, because 82542 supports only 1 queue */
2129 struct e1000_rx_ring
*ring
= &adapter
->rx_ring
[0];
2130 adapter
->alloc_rx_buf(adapter
, ring
, E1000_DESC_UNUSED(ring
));
2135 * e1000_set_mac - Change the Ethernet Address of the NIC
2136 * @netdev: network interface device structure
2137 * @p: pointer to an address structure
2139 * Returns 0 on success, negative on failure
2143 e1000_set_mac(struct net_device
*netdev
, void *p
)
2145 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2146 struct sockaddr
*addr
= p
;
2148 if(!is_valid_ether_addr(addr
->sa_data
))
2149 return -EADDRNOTAVAIL
;
2151 /* 82542 2.0 needs to be in reset to write receive address registers */
2153 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2154 e1000_enter_82542_rst(adapter
);
2156 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2157 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2159 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2161 /* With 82571 controllers, LAA may be overwritten (with the default)
2162 * due to controller reset from the other port. */
2163 if (adapter
->hw
.mac_type
== e1000_82571
) {
2164 /* activate the work around */
2165 adapter
->hw
.laa_is_present
= 1;
2167 /* Hold a copy of the LAA in RAR[14] This is done so that
2168 * between the time RAR[0] gets clobbered and the time it
2169 * gets fixed (in e1000_watchdog), the actual LAA is in one
2170 * of the RARs and no incoming packets directed to this port
2171 * are dropped. Eventaully the LAA will be in RAR[0] and
2173 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
,
2174 E1000_RAR_ENTRIES
- 1);
2177 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2178 e1000_leave_82542_rst(adapter
);
2184 * e1000_set_multi - Multicast and Promiscuous mode set
2185 * @netdev: network interface device structure
2187 * The set_multi entry point is called whenever the multicast address
2188 * list or the network interface flags are updated. This routine is
2189 * responsible for configuring the hardware for proper multicast,
2190 * promiscuous mode, and all-multi behavior.
2194 e1000_set_multi(struct net_device
*netdev
)
2196 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2197 struct e1000_hw
*hw
= &adapter
->hw
;
2198 struct dev_mc_list
*mc_ptr
;
2200 uint32_t hash_value
;
2201 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2203 /* reserve RAR[14] for LAA over-write work-around */
2204 if (adapter
->hw
.mac_type
== e1000_82571
)
2207 /* Check for Promiscuous and All Multicast modes */
2209 rctl
= E1000_READ_REG(hw
, RCTL
);
2211 if(netdev
->flags
& IFF_PROMISC
) {
2212 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2213 } else if(netdev
->flags
& IFF_ALLMULTI
) {
2214 rctl
|= E1000_RCTL_MPE
;
2215 rctl
&= ~E1000_RCTL_UPE
;
2217 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2220 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2222 /* 82542 2.0 needs to be in reset to write receive address registers */
2224 if(hw
->mac_type
== e1000_82542_rev2_0
)
2225 e1000_enter_82542_rst(adapter
);
2227 /* load the first 14 multicast address into the exact filters 1-14
2228 * RAR 0 is used for the station MAC adddress
2229 * if there are not 14 addresses, go ahead and clear the filters
2230 * -- with 82571 controllers only 0-13 entries are filled here
2232 mc_ptr
= netdev
->mc_list
;
2234 for(i
= 1; i
< rar_entries
; i
++) {
2236 e1000_rar_set(hw
, mc_ptr
->dmi_addr
, i
);
2237 mc_ptr
= mc_ptr
->next
;
2239 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2240 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2244 /* clear the old settings from the multicast hash table */
2246 for(i
= 0; i
< E1000_NUM_MTA_REGISTERS
; i
++)
2247 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
2249 /* load any remaining addresses into the hash table */
2251 for(; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
2252 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->dmi_addr
);
2253 e1000_mta_set(hw
, hash_value
);
2256 if(hw
->mac_type
== e1000_82542_rev2_0
)
2257 e1000_leave_82542_rst(adapter
);
2260 /* Need to wait a few seconds after link up to get diagnostic information from
2264 e1000_update_phy_info(unsigned long data
)
2266 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2267 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
2271 * e1000_82547_tx_fifo_stall - Timer Call-back
2272 * @data: pointer to adapter cast into an unsigned long
2276 e1000_82547_tx_fifo_stall(unsigned long data
)
2278 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2279 struct net_device
*netdev
= adapter
->netdev
;
2282 if(atomic_read(&adapter
->tx_fifo_stall
)) {
2283 if((E1000_READ_REG(&adapter
->hw
, TDT
) ==
2284 E1000_READ_REG(&adapter
->hw
, TDH
)) &&
2285 (E1000_READ_REG(&adapter
->hw
, TDFT
) ==
2286 E1000_READ_REG(&adapter
->hw
, TDFH
)) &&
2287 (E1000_READ_REG(&adapter
->hw
, TDFTS
) ==
2288 E1000_READ_REG(&adapter
->hw
, TDFHS
))) {
2289 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2290 E1000_WRITE_REG(&adapter
->hw
, TCTL
,
2291 tctl
& ~E1000_TCTL_EN
);
2292 E1000_WRITE_REG(&adapter
->hw
, TDFT
,
2293 adapter
->tx_head_addr
);
2294 E1000_WRITE_REG(&adapter
->hw
, TDFH
,
2295 adapter
->tx_head_addr
);
2296 E1000_WRITE_REG(&adapter
->hw
, TDFTS
,
2297 adapter
->tx_head_addr
);
2298 E1000_WRITE_REG(&adapter
->hw
, TDFHS
,
2299 adapter
->tx_head_addr
);
2300 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2301 E1000_WRITE_FLUSH(&adapter
->hw
);
2303 adapter
->tx_fifo_head
= 0;
2304 atomic_set(&adapter
->tx_fifo_stall
, 0);
2305 netif_wake_queue(netdev
);
2307 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2313 * e1000_watchdog - Timer Call-back
2314 * @data: pointer to adapter cast into an unsigned long
2317 e1000_watchdog(unsigned long data
)
2319 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2321 /* Do the rest outside of interrupt context */
2322 schedule_work(&adapter
->watchdog_task
);
2326 e1000_watchdog_task(struct e1000_adapter
*adapter
)
2328 struct net_device
*netdev
= adapter
->netdev
;
2329 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2332 e1000_check_for_link(&adapter
->hw
);
2333 if (adapter
->hw
.mac_type
== e1000_82573
) {
2334 e1000_enable_tx_pkt_filtering(&adapter
->hw
);
2335 if(adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
)
2336 e1000_update_mng_vlan(adapter
);
2339 if((adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) &&
2340 !(E1000_READ_REG(&adapter
->hw
, TXCW
) & E1000_TXCW_ANE
))
2341 link
= !adapter
->hw
.serdes_link_down
;
2343 link
= E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_LU
;
2346 if(!netif_carrier_ok(netdev
)) {
2347 e1000_get_speed_and_duplex(&adapter
->hw
,
2348 &adapter
->link_speed
,
2349 &adapter
->link_duplex
);
2351 DPRINTK(LINK
, INFO
, "NIC Link is Up %d Mbps %s\n",
2352 adapter
->link_speed
,
2353 adapter
->link_duplex
== FULL_DUPLEX
?
2354 "Full Duplex" : "Half Duplex");
2356 /* tweak tx_queue_len according to speed/duplex */
2357 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2358 adapter
->tx_timeout_factor
= 1;
2359 if (adapter
->link_duplex
== HALF_DUPLEX
) {
2360 switch (adapter
->link_speed
) {
2362 netdev
->tx_queue_len
= 10;
2363 adapter
->tx_timeout_factor
= 8;
2366 netdev
->tx_queue_len
= 100;
2371 netif_carrier_on(netdev
);
2372 netif_wake_queue(netdev
);
2373 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2374 adapter
->smartspeed
= 0;
2377 if(netif_carrier_ok(netdev
)) {
2378 adapter
->link_speed
= 0;
2379 adapter
->link_duplex
= 0;
2380 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
2381 netif_carrier_off(netdev
);
2382 netif_stop_queue(netdev
);
2383 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2386 e1000_smartspeed(adapter
);
2389 e1000_update_stats(adapter
);
2391 adapter
->hw
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2392 adapter
->tpt_old
= adapter
->stats
.tpt
;
2393 adapter
->hw
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2394 adapter
->colc_old
= adapter
->stats
.colc
;
2396 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2397 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2398 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2399 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2401 e1000_update_adaptive(&adapter
->hw
);
2403 #ifdef CONFIG_E1000_MQ
2404 txdr
= *per_cpu_ptr(adapter
->cpu_tx_ring
, smp_processor_id());
2406 if (!netif_carrier_ok(netdev
)) {
2407 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2408 /* We've lost link, so the controller stops DMA,
2409 * but we've got queued Tx work that's never going
2410 * to get done, so reset controller to flush Tx.
2411 * (Do the reset outside of interrupt context). */
2412 schedule_work(&adapter
->tx_timeout_task
);
2416 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2417 if(adapter
->hw
.mac_type
>= e1000_82540
&& adapter
->itr
== 1) {
2418 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2419 * asymmetrical Tx or Rx gets ITR=8000; everyone
2420 * else is between 2000-8000. */
2421 uint32_t goc
= (adapter
->gotcl
+ adapter
->gorcl
) / 10000;
2422 uint32_t dif
= (adapter
->gotcl
> adapter
->gorcl
?
2423 adapter
->gotcl
- adapter
->gorcl
:
2424 adapter
->gorcl
- adapter
->gotcl
) / 10000;
2425 uint32_t itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
2426 E1000_WRITE_REG(&adapter
->hw
, ITR
, 1000000000 / (itr
* 256));
2429 /* Cause software interrupt to ensure rx ring is cleaned */
2430 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_RXDMT0
);
2432 /* Force detection of hung controller every watchdog period */
2433 adapter
->detect_tx_hung
= TRUE
;
2435 /* With 82571 controllers, LAA may be overwritten due to controller
2436 * reset from the other port. Set the appropriate LAA in RAR[0] */
2437 if (adapter
->hw
.mac_type
== e1000_82571
&& adapter
->hw
.laa_is_present
)
2438 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2440 /* Reset the timer */
2441 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2 * HZ
);
2444 #define E1000_TX_FLAGS_CSUM 0x00000001
2445 #define E1000_TX_FLAGS_VLAN 0x00000002
2446 #define E1000_TX_FLAGS_TSO 0x00000004
2447 #define E1000_TX_FLAGS_IPV4 0x00000008
2448 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2449 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2452 e1000_tso(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2453 struct sk_buff
*skb
)
2456 struct e1000_context_desc
*context_desc
;
2457 struct e1000_buffer
*buffer_info
;
2459 uint32_t cmd_length
= 0;
2460 uint16_t ipcse
= 0, tucse
, mss
;
2461 uint8_t ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2464 if(skb_shinfo(skb
)->tso_size
) {
2465 if (skb_header_cloned(skb
)) {
2466 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2471 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2472 mss
= skb_shinfo(skb
)->tso_size
;
2473 if(skb
->protocol
== ntohs(ETH_P_IP
)) {
2474 skb
->nh
.iph
->tot_len
= 0;
2475 skb
->nh
.iph
->check
= 0;
2477 ~csum_tcpudp_magic(skb
->nh
.iph
->saddr
,
2482 cmd_length
= E1000_TXD_CMD_IP
;
2483 ipcse
= skb
->h
.raw
- skb
->data
- 1;
2484 #ifdef NETIF_F_TSO_IPV6
2485 } else if(skb
->protocol
== ntohs(ETH_P_IPV6
)) {
2486 skb
->nh
.ipv6h
->payload_len
= 0;
2488 ~csum_ipv6_magic(&skb
->nh
.ipv6h
->saddr
,
2489 &skb
->nh
.ipv6h
->daddr
,
2496 ipcss
= skb
->nh
.raw
- skb
->data
;
2497 ipcso
= (void *)&(skb
->nh
.iph
->check
) - (void *)skb
->data
;
2498 tucss
= skb
->h
.raw
- skb
->data
;
2499 tucso
= (void *)&(skb
->h
.th
->check
) - (void *)skb
->data
;
2502 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2503 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2505 i
= tx_ring
->next_to_use
;
2506 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2507 buffer_info
= &tx_ring
->buffer_info
[i
];
2509 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2510 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2511 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2512 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2513 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2514 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2515 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2516 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2517 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2519 buffer_info
->time_stamp
= jiffies
;
2521 if (++i
== tx_ring
->count
) i
= 0;
2522 tx_ring
->next_to_use
= i
;
2531 static inline boolean_t
2532 e1000_tx_csum(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2533 struct sk_buff
*skb
)
2535 struct e1000_context_desc
*context_desc
;
2536 struct e1000_buffer
*buffer_info
;
2540 if(likely(skb
->ip_summed
== CHECKSUM_HW
)) {
2541 css
= skb
->h
.raw
- skb
->data
;
2543 i
= tx_ring
->next_to_use
;
2544 buffer_info
= &tx_ring
->buffer_info
[i
];
2545 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2547 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2548 context_desc
->upper_setup
.tcp_fields
.tucso
= css
+ skb
->csum
;
2549 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2550 context_desc
->tcp_seg_setup
.data
= 0;
2551 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
2553 buffer_info
->time_stamp
= jiffies
;
2555 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2556 tx_ring
->next_to_use
= i
;
2564 #define E1000_MAX_TXD_PWR 12
2565 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2568 e1000_tx_map(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2569 struct sk_buff
*skb
, unsigned int first
, unsigned int max_per_txd
,
2570 unsigned int nr_frags
, unsigned int mss
)
2572 struct e1000_buffer
*buffer_info
;
2573 unsigned int len
= skb
->len
;
2574 unsigned int offset
= 0, size
, count
= 0, i
;
2576 len
-= skb
->data_len
;
2578 i
= tx_ring
->next_to_use
;
2581 buffer_info
= &tx_ring
->buffer_info
[i
];
2582 size
= min(len
, max_per_txd
);
2584 /* Workaround for Controller erratum --
2585 * descriptor for non-tso packet in a linear SKB that follows a
2586 * tso gets written back prematurely before the data is fully
2587 * DMAd to the controller */
2588 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2589 !skb_shinfo(skb
)->tso_size
) {
2590 tx_ring
->last_tx_tso
= 0;
2594 /* Workaround for premature desc write-backs
2595 * in TSO mode. Append 4-byte sentinel desc */
2596 if(unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
2599 /* work-around for errata 10 and it applies
2600 * to all controllers in PCI-X mode
2601 * The fix is to make sure that the first descriptor of a
2602 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2604 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2605 (size
> 2015) && count
== 0))
2608 /* Workaround for potential 82544 hang in PCI-X. Avoid
2609 * terminating buffers within evenly-aligned dwords. */
2610 if(unlikely(adapter
->pcix_82544
&&
2611 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
2615 buffer_info
->length
= size
;
2617 pci_map_single(adapter
->pdev
,
2621 buffer_info
->time_stamp
= jiffies
;
2626 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2629 for(f
= 0; f
< nr_frags
; f
++) {
2630 struct skb_frag_struct
*frag
;
2632 frag
= &skb_shinfo(skb
)->frags
[f
];
2634 offset
= frag
->page_offset
;
2637 buffer_info
= &tx_ring
->buffer_info
[i
];
2638 size
= min(len
, max_per_txd
);
2640 /* Workaround for premature desc write-backs
2641 * in TSO mode. Append 4-byte sentinel desc */
2642 if(unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
2645 /* Workaround for potential 82544 hang in PCI-X.
2646 * Avoid terminating buffers within evenly-aligned
2648 if(unlikely(adapter
->pcix_82544
&&
2649 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
2653 buffer_info
->length
= size
;
2655 pci_map_page(adapter
->pdev
,
2660 buffer_info
->time_stamp
= jiffies
;
2665 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2669 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
2670 tx_ring
->buffer_info
[i
].skb
= skb
;
2671 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
2677 e1000_tx_queue(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2678 int tx_flags
, int count
)
2680 struct e1000_tx_desc
*tx_desc
= NULL
;
2681 struct e1000_buffer
*buffer_info
;
2682 uint32_t txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
2685 if(likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
2686 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
2688 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2690 if(likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
2691 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
2694 if(likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
2695 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
2696 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2699 if(unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
2700 txd_lower
|= E1000_TXD_CMD_VLE
;
2701 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
2704 i
= tx_ring
->next_to_use
;
2707 buffer_info
= &tx_ring
->buffer_info
[i
];
2708 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
2709 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2710 tx_desc
->lower
.data
=
2711 cpu_to_le32(txd_lower
| buffer_info
->length
);
2712 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
2713 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2716 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
2718 /* Force memory writes to complete before letting h/w
2719 * know there are new descriptors to fetch. (Only
2720 * applicable for weak-ordered memory model archs,
2721 * such as IA-64). */
2724 tx_ring
->next_to_use
= i
;
2725 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
2729 * 82547 workaround to avoid controller hang in half-duplex environment.
2730 * The workaround is to avoid queuing a large packet that would span
2731 * the internal Tx FIFO ring boundary by notifying the stack to resend
2732 * the packet at a later time. This gives the Tx FIFO an opportunity to
2733 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2734 * to the beginning of the Tx FIFO.
2737 #define E1000_FIFO_HDR 0x10
2738 #define E1000_82547_PAD_LEN 0x3E0
2741 e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2743 uint32_t fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
2744 uint32_t skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
2746 E1000_ROUNDUP(skb_fifo_len
, E1000_FIFO_HDR
);
2748 if(adapter
->link_duplex
!= HALF_DUPLEX
)
2749 goto no_fifo_stall_required
;
2751 if(atomic_read(&adapter
->tx_fifo_stall
))
2754 if(skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
2755 atomic_set(&adapter
->tx_fifo_stall
, 1);
2759 no_fifo_stall_required
:
2760 adapter
->tx_fifo_head
+= skb_fifo_len
;
2761 if(adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
2762 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
2766 #define MINIMUM_DHCP_PACKET_SIZE 282
2768 e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2770 struct e1000_hw
*hw
= &adapter
->hw
;
2771 uint16_t length
, offset
;
2772 if(vlan_tx_tag_present(skb
)) {
2773 if(!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
2774 ( adapter
->hw
.mng_cookie
.status
&
2775 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) )
2778 if ((skb
->len
> MINIMUM_DHCP_PACKET_SIZE
) && (!skb
->protocol
)) {
2779 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
2780 if((htons(ETH_P_IP
) == eth
->h_proto
)) {
2781 const struct iphdr
*ip
=
2782 (struct iphdr
*)((uint8_t *)skb
->data
+14);
2783 if(IPPROTO_UDP
== ip
->protocol
) {
2784 struct udphdr
*udp
=
2785 (struct udphdr
*)((uint8_t *)ip
+
2787 if(ntohs(udp
->dest
) == 67) {
2788 offset
= (uint8_t *)udp
+ 8 - skb
->data
;
2789 length
= skb
->len
- offset
;
2791 return e1000_mng_write_dhcp_info(hw
,
2801 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2803 e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2805 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2806 struct e1000_tx_ring
*tx_ring
;
2807 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
2808 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
2809 unsigned int tx_flags
= 0;
2810 unsigned int len
= skb
->len
;
2811 unsigned long flags
;
2812 unsigned int nr_frags
= 0;
2813 unsigned int mss
= 0;
2817 len
-= skb
->data_len
;
2819 #ifdef CONFIG_E1000_MQ
2820 tx_ring
= *per_cpu_ptr(adapter
->cpu_tx_ring
, smp_processor_id());
2822 tx_ring
= adapter
->tx_ring
;
2825 if (unlikely(skb
->len
<= 0)) {
2826 dev_kfree_skb_any(skb
);
2827 return NETDEV_TX_OK
;
2831 mss
= skb_shinfo(skb
)->tso_size
;
2832 /* The controller does a simple calculation to
2833 * make sure there is enough room in the FIFO before
2834 * initiating the DMA for each buffer. The calc is:
2835 * 4 = ceil(buffer len/mss). To make sure we don't
2836 * overrun the FIFO, adjust the max buffer len if mss
2840 max_per_txd
= min(mss
<< 2, max_per_txd
);
2841 max_txd_pwr
= fls(max_per_txd
) - 1;
2843 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2844 * points to just header, pull a few bytes of payload from
2845 * frags into skb->data */
2846 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2847 if (skb
->data_len
&& (hdr_len
== (skb
->len
- skb
->data_len
)) &&
2848 (adapter
->hw
.mac_type
== e1000_82571
||
2849 adapter
->hw
.mac_type
== e1000_82572
)) {
2850 unsigned int pull_size
;
2851 pull_size
= min((unsigned int)4, skb
->data_len
);
2852 if (!__pskb_pull_tail(skb
, pull_size
)) {
2853 printk(KERN_ERR
"__pskb_pull_tail failed.\n");
2854 dev_kfree_skb_any(skb
);
2857 len
= skb
->len
- skb
->data_len
;
2861 if((mss
) || (skb
->ip_summed
== CHECKSUM_HW
))
2862 /* reserve a descriptor for the offload context */
2866 if(skb
->ip_summed
== CHECKSUM_HW
)
2871 /* Controller Erratum workaround */
2872 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2873 !skb_shinfo(skb
)->tso_size
)
2877 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
2879 if(adapter
->pcix_82544
)
2882 /* work-around for errata 10 and it applies to all controllers
2883 * in PCI-X mode, so add one more descriptor to the count
2885 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2889 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2890 for(f
= 0; f
< nr_frags
; f
++)
2891 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
2893 if(adapter
->pcix_82544
)
2896 if(adapter
->hw
.tx_pkt_filtering
&& (adapter
->hw
.mac_type
== e1000_82573
) )
2897 e1000_transfer_dhcp_info(adapter
, skb
);
2899 local_irq_save(flags
);
2900 if (!spin_trylock(&tx_ring
->tx_lock
)) {
2901 /* Collision - tell upper layer to requeue */
2902 local_irq_restore(flags
);
2903 return NETDEV_TX_LOCKED
;
2906 /* need: count + 2 desc gap to keep tail from touching
2907 * head, otherwise try next time */
2908 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < count
+ 2)) {
2909 netif_stop_queue(netdev
);
2910 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2911 return NETDEV_TX_BUSY
;
2914 if(unlikely(adapter
->hw
.mac_type
== e1000_82547
)) {
2915 if(unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
2916 netif_stop_queue(netdev
);
2917 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
);
2918 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2919 return NETDEV_TX_BUSY
;
2923 if(unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
2924 tx_flags
|= E1000_TX_FLAGS_VLAN
;
2925 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
2928 first
= tx_ring
->next_to_use
;
2930 tso
= e1000_tso(adapter
, tx_ring
, skb
);
2932 dev_kfree_skb_any(skb
);
2933 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2934 return NETDEV_TX_OK
;
2938 tx_ring
->last_tx_tso
= 1;
2939 tx_flags
|= E1000_TX_FLAGS_TSO
;
2940 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
2941 tx_flags
|= E1000_TX_FLAGS_CSUM
;
2943 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2944 * 82571 hardware supports TSO capabilities for IPv6 as well...
2945 * no longer assume, we must. */
2946 if (likely(skb
->protocol
== ntohs(ETH_P_IP
)))
2947 tx_flags
|= E1000_TX_FLAGS_IPV4
;
2949 e1000_tx_queue(adapter
, tx_ring
, tx_flags
,
2950 e1000_tx_map(adapter
, tx_ring
, skb
, first
,
2951 max_per_txd
, nr_frags
, mss
));
2953 netdev
->trans_start
= jiffies
;
2955 /* Make sure there is space in the ring for the next send. */
2956 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < MAX_SKB_FRAGS
+ 2))
2957 netif_stop_queue(netdev
);
2959 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2960 return NETDEV_TX_OK
;
2964 * e1000_tx_timeout - Respond to a Tx Hang
2965 * @netdev: network interface device structure
2969 e1000_tx_timeout(struct net_device
*netdev
)
2971 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2973 /* Do the reset outside of interrupt context */
2974 schedule_work(&adapter
->tx_timeout_task
);
2978 e1000_tx_timeout_task(struct net_device
*netdev
)
2980 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2982 adapter
->tx_timeout_count
++;
2983 e1000_down(adapter
);
2988 * e1000_get_stats - Get System Network Statistics
2989 * @netdev: network interface device structure
2991 * Returns the address of the device statistics structure.
2992 * The statistics are actually updated from the timer callback.
2995 static struct net_device_stats
*
2996 e1000_get_stats(struct net_device
*netdev
)
2998 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3000 /* only return the current stats */
3001 return &adapter
->net_stats
;
3005 * e1000_change_mtu - Change the Maximum Transfer Unit
3006 * @netdev: network interface device structure
3007 * @new_mtu: new value for maximum frame size
3009 * Returns 0 on success, negative on failure
3013 e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
3015 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3016 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
3018 if((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
3019 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3020 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
3024 /* Adapter-specific max frame size limits. */
3025 switch (adapter
->hw
.mac_type
) {
3026 case e1000_82542_rev2_0
:
3027 case e1000_82542_rev2_1
:
3029 if (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
3030 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported.\n");
3036 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3037 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3038 DPRINTK(PROBE
, ERR
, "MTU > 9216 not supported.\n");
3043 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3047 /* since the driver code now supports splitting a packet across
3048 * multiple descriptors, most of the fifo related limitations on
3049 * jumbo frame traffic have gone away.
3050 * simply use 2k descriptors for everything.
3052 * NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3053 * means we reserve 2 more, this pushes us to allocate from the next
3055 * i.e. RXBUFFER_2048 --> size-4096 slab */
3057 /* recent hardware supports 1KB granularity */
3058 if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3059 adapter
->rx_buffer_len
=
3060 ((max_frame
< E1000_RXBUFFER_2048
) ?
3061 max_frame
: E1000_RXBUFFER_2048
);
3062 E1000_ROUNDUP(adapter
->rx_buffer_len
, 1024);
3064 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
3066 netdev
->mtu
= new_mtu
;
3068 if(netif_running(netdev
)) {
3069 e1000_down(adapter
);
3073 adapter
->hw
.max_frame_size
= max_frame
;
3079 * e1000_update_stats - Update the board statistics counters
3080 * @adapter: board private structure
3084 e1000_update_stats(struct e1000_adapter
*adapter
)
3086 struct e1000_hw
*hw
= &adapter
->hw
;
3087 unsigned long flags
;
3090 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3092 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3094 /* these counters are modified from e1000_adjust_tbi_stats,
3095 * called from the interrupt context, so they must only
3096 * be written while holding adapter->stats_lock
3099 adapter
->stats
.crcerrs
+= E1000_READ_REG(hw
, CRCERRS
);
3100 adapter
->stats
.gprc
+= E1000_READ_REG(hw
, GPRC
);
3101 adapter
->stats
.gorcl
+= E1000_READ_REG(hw
, GORCL
);
3102 adapter
->stats
.gorch
+= E1000_READ_REG(hw
, GORCH
);
3103 adapter
->stats
.bprc
+= E1000_READ_REG(hw
, BPRC
);
3104 adapter
->stats
.mprc
+= E1000_READ_REG(hw
, MPRC
);
3105 adapter
->stats
.roc
+= E1000_READ_REG(hw
, ROC
);
3106 adapter
->stats
.prc64
+= E1000_READ_REG(hw
, PRC64
);
3107 adapter
->stats
.prc127
+= E1000_READ_REG(hw
, PRC127
);
3108 adapter
->stats
.prc255
+= E1000_READ_REG(hw
, PRC255
);
3109 adapter
->stats
.prc511
+= E1000_READ_REG(hw
, PRC511
);
3110 adapter
->stats
.prc1023
+= E1000_READ_REG(hw
, PRC1023
);
3111 adapter
->stats
.prc1522
+= E1000_READ_REG(hw
, PRC1522
);
3113 adapter
->stats
.symerrs
+= E1000_READ_REG(hw
, SYMERRS
);
3114 adapter
->stats
.mpc
+= E1000_READ_REG(hw
, MPC
);
3115 adapter
->stats
.scc
+= E1000_READ_REG(hw
, SCC
);
3116 adapter
->stats
.ecol
+= E1000_READ_REG(hw
, ECOL
);
3117 adapter
->stats
.mcc
+= E1000_READ_REG(hw
, MCC
);
3118 adapter
->stats
.latecol
+= E1000_READ_REG(hw
, LATECOL
);
3119 adapter
->stats
.dc
+= E1000_READ_REG(hw
, DC
);
3120 adapter
->stats
.sec
+= E1000_READ_REG(hw
, SEC
);
3121 adapter
->stats
.rlec
+= E1000_READ_REG(hw
, RLEC
);
3122 adapter
->stats
.xonrxc
+= E1000_READ_REG(hw
, XONRXC
);
3123 adapter
->stats
.xontxc
+= E1000_READ_REG(hw
, XONTXC
);
3124 adapter
->stats
.xoffrxc
+= E1000_READ_REG(hw
, XOFFRXC
);
3125 adapter
->stats
.xofftxc
+= E1000_READ_REG(hw
, XOFFTXC
);
3126 adapter
->stats
.fcruc
+= E1000_READ_REG(hw
, FCRUC
);
3127 adapter
->stats
.gptc
+= E1000_READ_REG(hw
, GPTC
);
3128 adapter
->stats
.gotcl
+= E1000_READ_REG(hw
, GOTCL
);
3129 adapter
->stats
.gotch
+= E1000_READ_REG(hw
, GOTCH
);
3130 adapter
->stats
.rnbc
+= E1000_READ_REG(hw
, RNBC
);
3131 adapter
->stats
.ruc
+= E1000_READ_REG(hw
, RUC
);
3132 adapter
->stats
.rfc
+= E1000_READ_REG(hw
, RFC
);
3133 adapter
->stats
.rjc
+= E1000_READ_REG(hw
, RJC
);
3134 adapter
->stats
.torl
+= E1000_READ_REG(hw
, TORL
);
3135 adapter
->stats
.torh
+= E1000_READ_REG(hw
, TORH
);
3136 adapter
->stats
.totl
+= E1000_READ_REG(hw
, TOTL
);
3137 adapter
->stats
.toth
+= E1000_READ_REG(hw
, TOTH
);
3138 adapter
->stats
.tpr
+= E1000_READ_REG(hw
, TPR
);
3139 adapter
->stats
.ptc64
+= E1000_READ_REG(hw
, PTC64
);
3140 adapter
->stats
.ptc127
+= E1000_READ_REG(hw
, PTC127
);
3141 adapter
->stats
.ptc255
+= E1000_READ_REG(hw
, PTC255
);
3142 adapter
->stats
.ptc511
+= E1000_READ_REG(hw
, PTC511
);
3143 adapter
->stats
.ptc1023
+= E1000_READ_REG(hw
, PTC1023
);
3144 adapter
->stats
.ptc1522
+= E1000_READ_REG(hw
, PTC1522
);
3145 adapter
->stats
.mptc
+= E1000_READ_REG(hw
, MPTC
);
3146 adapter
->stats
.bptc
+= E1000_READ_REG(hw
, BPTC
);
3148 /* used for adaptive IFS */
3150 hw
->tx_packet_delta
= E1000_READ_REG(hw
, TPT
);
3151 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3152 hw
->collision_delta
= E1000_READ_REG(hw
, COLC
);
3153 adapter
->stats
.colc
+= hw
->collision_delta
;
3155 if(hw
->mac_type
>= e1000_82543
) {
3156 adapter
->stats
.algnerrc
+= E1000_READ_REG(hw
, ALGNERRC
);
3157 adapter
->stats
.rxerrc
+= E1000_READ_REG(hw
, RXERRC
);
3158 adapter
->stats
.tncrs
+= E1000_READ_REG(hw
, TNCRS
);
3159 adapter
->stats
.cexterr
+= E1000_READ_REG(hw
, CEXTERR
);
3160 adapter
->stats
.tsctc
+= E1000_READ_REG(hw
, TSCTC
);
3161 adapter
->stats
.tsctfc
+= E1000_READ_REG(hw
, TSCTFC
);
3163 if(hw
->mac_type
> e1000_82547_rev_2
) {
3164 adapter
->stats
.iac
+= E1000_READ_REG(hw
, IAC
);
3165 adapter
->stats
.icrxoc
+= E1000_READ_REG(hw
, ICRXOC
);
3166 adapter
->stats
.icrxptc
+= E1000_READ_REG(hw
, ICRXPTC
);
3167 adapter
->stats
.icrxatc
+= E1000_READ_REG(hw
, ICRXATC
);
3168 adapter
->stats
.ictxptc
+= E1000_READ_REG(hw
, ICTXPTC
);
3169 adapter
->stats
.ictxatc
+= E1000_READ_REG(hw
, ICTXATC
);
3170 adapter
->stats
.ictxqec
+= E1000_READ_REG(hw
, ICTXQEC
);
3171 adapter
->stats
.ictxqmtc
+= E1000_READ_REG(hw
, ICTXQMTC
);
3172 adapter
->stats
.icrxdmtc
+= E1000_READ_REG(hw
, ICRXDMTC
);
3175 /* Fill out the OS statistics structure */
3177 adapter
->net_stats
.rx_packets
= adapter
->stats
.gprc
;
3178 adapter
->net_stats
.tx_packets
= adapter
->stats
.gptc
;
3179 adapter
->net_stats
.rx_bytes
= adapter
->stats
.gorcl
;
3180 adapter
->net_stats
.tx_bytes
= adapter
->stats
.gotcl
;
3181 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3182 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3186 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3187 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3188 adapter
->stats
.rlec
+ adapter
->stats
.cexterr
;
3189 adapter
->net_stats
.rx_dropped
= 0;
3190 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlec
;
3191 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3192 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3193 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3197 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3198 adapter
->stats
.latecol
;
3199 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3200 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3201 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3203 /* Tx Dropped needs to be maintained elsewhere */
3207 if(hw
->media_type
== e1000_media_type_copper
) {
3208 if((adapter
->link_speed
== SPEED_1000
) &&
3209 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3210 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3211 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3214 if((hw
->mac_type
<= e1000_82546
) &&
3215 (hw
->phy_type
== e1000_phy_m88
) &&
3216 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3217 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3220 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3223 #ifdef CONFIG_E1000_MQ
3225 e1000_rx_schedule(void *data
)
3227 struct net_device
*poll_dev
, *netdev
= data
;
3228 struct e1000_adapter
*adapter
= netdev
->priv
;
3229 int this_cpu
= get_cpu();
3231 poll_dev
= *per_cpu_ptr(adapter
->cpu_netdev
, this_cpu
);
3232 if (poll_dev
== NULL
) {
3237 if (likely(netif_rx_schedule_prep(poll_dev
)))
3238 __netif_rx_schedule(poll_dev
);
3240 e1000_irq_enable(adapter
);
3247 * e1000_intr - Interrupt Handler
3248 * @irq: interrupt number
3249 * @data: pointer to a network interface device structure
3250 * @pt_regs: CPU registers structure
3254 e1000_intr(int irq
, void *data
, struct pt_regs
*regs
)
3256 struct net_device
*netdev
= data
;
3257 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3258 struct e1000_hw
*hw
= &adapter
->hw
;
3259 uint32_t icr
= E1000_READ_REG(hw
, ICR
);
3260 #ifndef CONFIG_E1000_NAPI
3263 /* Interrupt Auto-Mask...upon reading ICR,
3264 * interrupts are masked. No need for the
3265 * IMC write, but it does mean we should
3266 * account for it ASAP. */
3267 if (likely(hw
->mac_type
>= e1000_82571
))
3268 atomic_inc(&adapter
->irq_sem
);
3271 if (unlikely(!icr
)) {
3272 #ifdef CONFIG_E1000_NAPI
3273 if (hw
->mac_type
>= e1000_82571
)
3274 e1000_irq_enable(adapter
);
3276 return IRQ_NONE
; /* Not our interrupt */
3279 if(unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3280 hw
->get_link_status
= 1;
3281 mod_timer(&adapter
->watchdog_timer
, jiffies
);
3284 #ifdef CONFIG_E1000_NAPI
3285 if (unlikely(hw
->mac_type
< e1000_82571
)) {
3286 atomic_inc(&adapter
->irq_sem
);
3287 E1000_WRITE_REG(hw
, IMC
, ~0);
3288 E1000_WRITE_FLUSH(hw
);
3290 #ifdef CONFIG_E1000_MQ
3291 if (atomic_read(&adapter
->rx_sched_call_data
.count
) == 0) {
3292 /* We must setup the cpumask once count == 0 since
3293 * each cpu bit is cleared when the work is done. */
3294 adapter
->rx_sched_call_data
.cpumask
= adapter
->cpumask
;
3295 atomic_add(adapter
->num_rx_queues
- 1, &adapter
->irq_sem
);
3296 atomic_set(&adapter
->rx_sched_call_data
.count
,
3297 adapter
->num_rx_queues
);
3298 smp_call_async_mask(&adapter
->rx_sched_call_data
);
3300 printk("call_data.count == %u\n", atomic_read(&adapter
->rx_sched_call_data
.count
));
3302 #else /* if !CONFIG_E1000_MQ */
3303 if (likely(netif_rx_schedule_prep(&adapter
->polling_netdev
[0])))
3304 __netif_rx_schedule(&adapter
->polling_netdev
[0]);
3306 e1000_irq_enable(adapter
);
3307 #endif /* CONFIG_E1000_MQ */
3309 #else /* if !CONFIG_E1000_NAPI */
3310 /* Writing IMC and IMS is needed for 82547.
3311 Due to Hub Link bus being occupied, an interrupt
3312 de-assertion message is not able to be sent.
3313 When an interrupt assertion message is generated later,
3314 two messages are re-ordered and sent out.
3315 That causes APIC to think 82547 is in de-assertion
3316 state, while 82547 is in assertion state, resulting
3317 in dead lock. Writing IMC forces 82547 into
3320 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
){
3321 atomic_inc(&adapter
->irq_sem
);
3322 E1000_WRITE_REG(hw
, IMC
, ~0);
3325 for(i
= 0; i
< E1000_MAX_INTR
; i
++)
3326 if(unlikely(!adapter
->clean_rx(adapter
, adapter
->rx_ring
) &
3327 !e1000_clean_tx_irq(adapter
, adapter
->tx_ring
)))
3330 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
3331 e1000_irq_enable(adapter
);
3333 #endif /* CONFIG_E1000_NAPI */
3338 #ifdef CONFIG_E1000_NAPI
3340 * e1000_clean - NAPI Rx polling callback
3341 * @adapter: board private structure
3345 e1000_clean(struct net_device
*poll_dev
, int *budget
)
3347 struct e1000_adapter
*adapter
;
3348 int work_to_do
= min(*budget
, poll_dev
->quota
);
3349 int tx_cleaned
, i
= 0, work_done
= 0;
3351 /* Must NOT use netdev_priv macro here. */
3352 adapter
= poll_dev
->priv
;
3354 /* Keep link state information with original netdev */
3355 if (!netif_carrier_ok(adapter
->netdev
))
3358 while (poll_dev
!= &adapter
->polling_netdev
[i
]) {
3360 if (unlikely(i
== adapter
->num_rx_queues
))
3364 tx_cleaned
= e1000_clean_tx_irq(adapter
, &adapter
->tx_ring
[i
]);
3365 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[i
],
3366 &work_done
, work_to_do
);
3368 *budget
-= work_done
;
3369 poll_dev
->quota
-= work_done
;
3371 /* If no Tx and not enough Rx work done, exit the polling mode */
3372 if((!tx_cleaned
&& (work_done
== 0)) ||
3373 !netif_running(adapter
->netdev
)) {
3375 netif_rx_complete(poll_dev
);
3376 e1000_irq_enable(adapter
);
3385 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3386 * @adapter: board private structure
3390 e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
3391 struct e1000_tx_ring
*tx_ring
)
3393 struct net_device
*netdev
= adapter
->netdev
;
3394 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
3395 struct e1000_buffer
*buffer_info
;
3396 unsigned int i
, eop
;
3397 boolean_t cleaned
= FALSE
;
3399 i
= tx_ring
->next_to_clean
;
3400 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3401 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3403 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
3404 for(cleaned
= FALSE
; !cleaned
; ) {
3405 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3406 buffer_info
= &tx_ring
->buffer_info
[i
];
3407 cleaned
= (i
== eop
);
3409 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
3411 tx_desc
->buffer_addr
= 0;
3412 tx_desc
->lower
.data
= 0;
3413 tx_desc
->upper
.data
= 0;
3415 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
3418 #ifdef CONFIG_E1000_MQ
3419 tx_ring
->tx_stats
.packets
++;
3422 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3423 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3426 tx_ring
->next_to_clean
= i
;
3428 spin_lock(&tx_ring
->tx_lock
);
3430 if(unlikely(cleaned
&& netif_queue_stopped(netdev
) &&
3431 netif_carrier_ok(netdev
)))
3432 netif_wake_queue(netdev
);
3434 spin_unlock(&tx_ring
->tx_lock
);
3436 if (adapter
->detect_tx_hung
) {
3437 /* Detect a transmit hang in hardware, this serializes the
3438 * check with the clearing of time_stamp and movement of i */
3439 adapter
->detect_tx_hung
= FALSE
;
3440 if (tx_ring
->buffer_info
[eop
].dma
&&
3441 time_after(jiffies
, tx_ring
->buffer_info
[eop
].time_stamp
+
3442 adapter
->tx_timeout_factor
* HZ
)
3443 && !(E1000_READ_REG(&adapter
->hw
, STATUS
) &
3444 E1000_STATUS_TXOFF
)) {
3446 /* detected Tx unit hang */
3447 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
3451 " next_to_use <%x>\n"
3452 " next_to_clean <%x>\n"
3453 "buffer_info[next_to_clean]\n"
3454 " time_stamp <%lx>\n"
3455 " next_to_watch <%x>\n"
3457 " next_to_watch.status <%x>\n",
3458 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
3459 sizeof(struct e1000_tx_ring
)),
3460 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdh
),
3461 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdt
),
3462 tx_ring
->next_to_use
,
3463 tx_ring
->next_to_clean
,
3464 tx_ring
->buffer_info
[eop
].time_stamp
,
3467 eop_desc
->upper
.fields
.status
);
3468 netif_stop_queue(netdev
);
3475 * e1000_rx_checksum - Receive Checksum Offload for 82543
3476 * @adapter: board private structure
3477 * @status_err: receive descriptor status and error fields
3478 * @csum: receive descriptor csum field
3479 * @sk_buff: socket buffer with received data
3483 e1000_rx_checksum(struct e1000_adapter
*adapter
,
3484 uint32_t status_err
, uint32_t csum
,
3485 struct sk_buff
*skb
)
3487 uint16_t status
= (uint16_t)status_err
;
3488 uint8_t errors
= (uint8_t)(status_err
>> 24);
3489 skb
->ip_summed
= CHECKSUM_NONE
;
3491 /* 82543 or newer only */
3492 if(unlikely(adapter
->hw
.mac_type
< e1000_82543
)) return;
3493 /* Ignore Checksum bit is set */
3494 if(unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
3495 /* TCP/UDP checksum error bit is set */
3496 if(unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
3497 /* let the stack verify checksum errors */
3498 adapter
->hw_csum_err
++;
3501 /* TCP/UDP Checksum has not been calculated */
3502 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
) {
3503 if(!(status
& E1000_RXD_STAT_TCPCS
))
3506 if(!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
3509 /* It must be a TCP or UDP packet with a valid checksum */
3510 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
3511 /* TCP checksum is good */
3512 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3513 } else if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3514 /* IP fragment with UDP payload */
3515 /* Hardware complements the payload checksum, so we undo it
3516 * and then put the value in host order for further stack use.
3518 csum
= ntohl(csum
^ 0xFFFF);
3520 skb
->ip_summed
= CHECKSUM_HW
;
3522 adapter
->hw_csum_good
++;
3526 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3527 * @adapter: board private structure
3531 #ifdef CONFIG_E1000_NAPI
3532 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3533 struct e1000_rx_ring
*rx_ring
,
3534 int *work_done
, int work_to_do
)
3536 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3537 struct e1000_rx_ring
*rx_ring
)
3540 struct net_device
*netdev
= adapter
->netdev
;
3541 struct pci_dev
*pdev
= adapter
->pdev
;
3542 struct e1000_rx_desc
*rx_desc
;
3543 struct e1000_buffer
*buffer_info
;
3544 struct sk_buff
*skb
;
3545 unsigned long flags
;
3549 boolean_t cleaned
= FALSE
;
3550 int cleaned_count
= 0;
3552 i
= rx_ring
->next_to_clean
;
3553 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3555 while(rx_desc
->status
& E1000_RXD_STAT_DD
) {
3556 buffer_info
= &rx_ring
->buffer_info
[i
];
3557 #ifdef CONFIG_E1000_NAPI
3558 if(*work_done
>= work_to_do
)
3565 pci_unmap_single(pdev
, buffer_info
->dma
, buffer_info
->length
,
3566 PCI_DMA_FROMDEVICE
);
3568 skb
= buffer_info
->skb
;
3569 length
= le16_to_cpu(rx_desc
->length
);
3571 if(unlikely(!(rx_desc
->status
& E1000_RXD_STAT_EOP
))) {
3572 /* All receives must fit into a single buffer */
3573 E1000_DBG("%s: Receive packet consumed multiple"
3574 " buffers\n", netdev
->name
);
3575 dev_kfree_skb_irq(skb
);
3579 if(unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
3580 last_byte
= *(skb
->data
+ length
- 1);
3581 if(TBI_ACCEPT(&adapter
->hw
, rx_desc
->status
,
3582 rx_desc
->errors
, length
, last_byte
)) {
3583 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3584 e1000_tbi_adjust_stats(&adapter
->hw
, &adapter
->stats
,
3586 spin_unlock_irqrestore(&adapter
->stats_lock
,
3590 dev_kfree_skb_irq(skb
);
3596 skb_put(skb
, length
- ETHERNET_FCS_SIZE
);
3598 /* Receive Checksum Offload */
3599 e1000_rx_checksum(adapter
, (uint32_t)(rx_desc
->status
) |
3600 ((uint32_t)(rx_desc
->errors
) << 24),
3601 rx_desc
->csum
, skb
);
3602 skb
->protocol
= eth_type_trans(skb
, netdev
);
3603 #ifdef CONFIG_E1000_NAPI
3604 if(unlikely(adapter
->vlgrp
&&
3605 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3606 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3607 le16_to_cpu(rx_desc
->special
) &
3608 E1000_RXD_SPC_VLAN_MASK
);
3610 netif_receive_skb(skb
);
3612 #else /* CONFIG_E1000_NAPI */
3613 if(unlikely(adapter
->vlgrp
&&
3614 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3615 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3616 le16_to_cpu(rx_desc
->special
) &
3617 E1000_RXD_SPC_VLAN_MASK
);
3621 #endif /* CONFIG_E1000_NAPI */
3622 netdev
->last_rx
= jiffies
;
3623 #ifdef CONFIG_E1000_MQ
3624 rx_ring
->rx_stats
.packets
++;
3625 rx_ring
->rx_stats
.bytes
+= length
;
3629 rx_desc
->status
= 0;
3631 /* return some buffers to hardware, one at a time is too slow */
3632 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
3633 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3638 rx_ring
->next_to_clean
= i
;
3640 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
3642 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3648 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3649 * @adapter: board private structure
3653 #ifdef CONFIG_E1000_NAPI
3654 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3655 struct e1000_rx_ring
*rx_ring
,
3656 int *work_done
, int work_to_do
)
3658 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3659 struct e1000_rx_ring
*rx_ring
)
3662 union e1000_rx_desc_packet_split
*rx_desc
;
3663 struct net_device
*netdev
= adapter
->netdev
;
3664 struct pci_dev
*pdev
= adapter
->pdev
;
3665 struct e1000_buffer
*buffer_info
;
3666 struct e1000_ps_page
*ps_page
;
3667 struct e1000_ps_page_dma
*ps_page_dma
;
3668 struct sk_buff
*skb
;
3670 uint32_t length
, staterr
;
3671 int cleaned_count
= 0;
3672 boolean_t cleaned
= FALSE
;
3674 i
= rx_ring
->next_to_clean
;
3675 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3676 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3678 while(staterr
& E1000_RXD_STAT_DD
) {
3679 buffer_info
= &rx_ring
->buffer_info
[i
];
3680 ps_page
= &rx_ring
->ps_page
[i
];
3681 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3682 #ifdef CONFIG_E1000_NAPI
3683 if(unlikely(*work_done
>= work_to_do
))
3689 pci_unmap_single(pdev
, buffer_info
->dma
,
3690 buffer_info
->length
,
3691 PCI_DMA_FROMDEVICE
);
3693 skb
= buffer_info
->skb
;
3695 if(unlikely(!(staterr
& E1000_RXD_STAT_EOP
))) {
3696 E1000_DBG("%s: Packet Split buffers didn't pick up"
3697 " the full packet\n", netdev
->name
);
3698 dev_kfree_skb_irq(skb
);
3702 if(unlikely(staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
)) {
3703 dev_kfree_skb_irq(skb
);
3707 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
3709 if(unlikely(!length
)) {
3710 E1000_DBG("%s: Last part of the packet spanning"
3711 " multiple descriptors\n", netdev
->name
);
3712 dev_kfree_skb_irq(skb
);
3717 skb_put(skb
, length
);
3719 for(j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
3720 if(!(length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
])))
3723 pci_unmap_page(pdev
, ps_page_dma
->ps_page_dma
[j
],
3724 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
3725 ps_page_dma
->ps_page_dma
[j
] = 0;
3726 skb_shinfo(skb
)->frags
[j
].page
=
3727 ps_page
->ps_page
[j
];
3728 ps_page
->ps_page
[j
] = NULL
;
3729 skb_shinfo(skb
)->frags
[j
].page_offset
= 0;
3730 skb_shinfo(skb
)->frags
[j
].size
= length
;
3731 skb_shinfo(skb
)->nr_frags
++;
3733 skb
->data_len
+= length
;
3736 e1000_rx_checksum(adapter
, staterr
,
3737 rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
, skb
);
3738 skb
->protocol
= eth_type_trans(skb
, netdev
);
3740 if(likely(rx_desc
->wb
.upper
.header_status
&
3741 E1000_RXDPS_HDRSTAT_HDRSP
)) {
3742 adapter
->rx_hdr_split
++;
3743 #ifdef HAVE_RX_ZERO_COPY
3744 skb_shinfo(skb
)->zero_copy
= TRUE
;
3747 #ifdef CONFIG_E1000_NAPI
3748 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3749 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3750 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3751 E1000_RXD_SPC_VLAN_MASK
);
3753 netif_receive_skb(skb
);
3755 #else /* CONFIG_E1000_NAPI */
3756 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3757 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3758 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3759 E1000_RXD_SPC_VLAN_MASK
);
3763 #endif /* CONFIG_E1000_NAPI */
3764 netdev
->last_rx
= jiffies
;
3765 #ifdef CONFIG_E1000_MQ
3766 rx_ring
->rx_stats
.packets
++;
3767 rx_ring
->rx_stats
.bytes
+= length
;
3771 rx_desc
->wb
.middle
.status_error
&= ~0xFF;
3772 buffer_info
->skb
= NULL
;
3774 /* return some buffers to hardware, one at a time is too slow */
3775 if (unlikely(cleaned_count
>= E1000_RX_BUFFER_WRITE
)) {
3776 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3780 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3782 rx_ring
->next_to_clean
= i
;
3784 cleaned_count
= E1000_DESC_UNUSED(rx_ring
);
3786 adapter
->alloc_rx_buf(adapter
, rx_ring
, cleaned_count
);
3792 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3793 * @adapter: address of board private structure
3797 e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
3798 struct e1000_rx_ring
*rx_ring
,
3801 struct net_device
*netdev
= adapter
->netdev
;
3802 struct pci_dev
*pdev
= adapter
->pdev
;
3803 struct e1000_rx_desc
*rx_desc
;
3804 struct e1000_buffer
*buffer_info
;
3805 struct sk_buff
*skb
;
3807 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
3809 i
= rx_ring
->next_to_use
;
3810 buffer_info
= &rx_ring
->buffer_info
[i
];
3812 while(!buffer_info
->skb
) {
3813 skb
= dev_alloc_skb(bufsz
);
3815 if(unlikely(!skb
)) {
3816 /* Better luck next round */
3817 adapter
->alloc_rx_buff_failed
++;
3821 /* Fix for errata 23, can't cross 64kB boundary */
3822 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3823 struct sk_buff
*oldskb
= skb
;
3824 DPRINTK(RX_ERR
, ERR
, "skb align check failed: %u bytes "
3825 "at %p\n", bufsz
, skb
->data
);
3826 /* Try again, without freeing the previous */
3827 skb
= dev_alloc_skb(bufsz
);
3828 /* Failed allocation, critical failure */
3830 dev_kfree_skb(oldskb
);
3834 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3837 dev_kfree_skb(oldskb
);
3838 break; /* while !buffer_info->skb */
3840 /* Use new allocation */
3841 dev_kfree_skb(oldskb
);
3844 /* Make buffer alignment 2 beyond a 16 byte boundary
3845 * this will result in a 16 byte aligned IP header after
3846 * the 14 byte MAC header is removed
3848 skb_reserve(skb
, NET_IP_ALIGN
);
3852 buffer_info
->skb
= skb
;
3853 buffer_info
->length
= adapter
->rx_buffer_len
;
3854 buffer_info
->dma
= pci_map_single(pdev
,
3856 adapter
->rx_buffer_len
,
3857 PCI_DMA_FROMDEVICE
);
3859 /* Fix for errata 23, can't cross 64kB boundary */
3860 if (!e1000_check_64k_bound(adapter
,
3861 (void *)(unsigned long)buffer_info
->dma
,
3862 adapter
->rx_buffer_len
)) {
3863 DPRINTK(RX_ERR
, ERR
,
3864 "dma align check failed: %u bytes at %p\n",
3865 adapter
->rx_buffer_len
,
3866 (void *)(unsigned long)buffer_info
->dma
);
3868 buffer_info
->skb
= NULL
;
3870 pci_unmap_single(pdev
, buffer_info
->dma
,
3871 adapter
->rx_buffer_len
,
3872 PCI_DMA_FROMDEVICE
);
3874 break; /* while !buffer_info->skb */
3876 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3877 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3879 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3880 /* Force memory writes to complete before letting h/w
3881 * know there are new descriptors to fetch. (Only
3882 * applicable for weak-ordered memory model archs,
3883 * such as IA-64). */
3885 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
3888 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3889 buffer_info
= &rx_ring
->buffer_info
[i
];
3892 rx_ring
->next_to_use
= i
;
3896 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3897 * @adapter: address of board private structure
3901 e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
3902 struct e1000_rx_ring
*rx_ring
,
3905 struct net_device
*netdev
= adapter
->netdev
;
3906 struct pci_dev
*pdev
= adapter
->pdev
;
3907 union e1000_rx_desc_packet_split
*rx_desc
;
3908 struct e1000_buffer
*buffer_info
;
3909 struct e1000_ps_page
*ps_page
;
3910 struct e1000_ps_page_dma
*ps_page_dma
;
3911 struct sk_buff
*skb
;
3914 i
= rx_ring
->next_to_use
;
3915 buffer_info
= &rx_ring
->buffer_info
[i
];
3916 ps_page
= &rx_ring
->ps_page
[i
];
3917 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3919 while (cleaned_count
--) {
3920 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3922 for(j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
3923 if (j
< adapter
->rx_ps_pages
) {
3924 if (likely(!ps_page
->ps_page
[j
])) {
3925 ps_page
->ps_page
[j
] =
3926 alloc_page(GFP_ATOMIC
);
3927 if (unlikely(!ps_page
->ps_page
[j
]))
3929 ps_page_dma
->ps_page_dma
[j
] =
3931 ps_page
->ps_page
[j
],
3933 PCI_DMA_FROMDEVICE
);
3935 /* Refresh the desc even if buffer_addrs didn't
3936 * change because each write-back erases
3939 rx_desc
->read
.buffer_addr
[j
+1] =
3940 cpu_to_le64(ps_page_dma
->ps_page_dma
[j
]);
3942 rx_desc
->read
.buffer_addr
[j
+1] = ~0;
3945 skb
= dev_alloc_skb(adapter
->rx_ps_bsize0
+ NET_IP_ALIGN
);
3950 /* Make buffer alignment 2 beyond a 16 byte boundary
3951 * this will result in a 16 byte aligned IP header after
3952 * the 14 byte MAC header is removed
3954 skb_reserve(skb
, NET_IP_ALIGN
);
3958 buffer_info
->skb
= skb
;
3959 buffer_info
->length
= adapter
->rx_ps_bsize0
;
3960 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
3961 adapter
->rx_ps_bsize0
,
3962 PCI_DMA_FROMDEVICE
);
3964 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
3966 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3967 /* Force memory writes to complete before letting h/w
3968 * know there are new descriptors to fetch. (Only
3969 * applicable for weak-ordered memory model archs,
3970 * such as IA-64). */
3972 /* Hardware increments by 16 bytes, but packet split
3973 * descriptors are 32 bytes...so we increment tail
3976 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
3979 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3980 buffer_info
= &rx_ring
->buffer_info
[i
];
3981 ps_page
= &rx_ring
->ps_page
[i
];
3982 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3986 rx_ring
->next_to_use
= i
;
3990 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3995 e1000_smartspeed(struct e1000_adapter
*adapter
)
3997 uint16_t phy_status
;
4000 if((adapter
->hw
.phy_type
!= e1000_phy_igp
) || !adapter
->hw
.autoneg
||
4001 !(adapter
->hw
.autoneg_advertised
& ADVERTISE_1000_FULL
))
4004 if(adapter
->smartspeed
== 0) {
4005 /* If Master/Slave config fault is asserted twice,
4006 * we assume back-to-back */
4007 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4008 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4009 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
4010 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
4011 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4012 if(phy_ctrl
& CR_1000T_MS_ENABLE
) {
4013 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
4014 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
,
4016 adapter
->smartspeed
++;
4017 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4018 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
,
4020 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4021 MII_CR_RESTART_AUTO_NEG
);
4022 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
,
4027 } else if(adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
4028 /* If still no link, perhaps using 2/3 pair cable */
4029 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
4030 phy_ctrl
|= CR_1000T_MS_ENABLE
;
4031 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, phy_ctrl
);
4032 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
4033 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &phy_ctrl
)) {
4034 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
4035 MII_CR_RESTART_AUTO_NEG
);
4036 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, phy_ctrl
);
4039 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4040 if(adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
4041 adapter
->smartspeed
= 0;
4052 e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4058 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
4072 e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4074 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4075 struct mii_ioctl_data
*data
= if_mii(ifr
);
4079 unsigned long flags
;
4081 if(adapter
->hw
.media_type
!= e1000_media_type_copper
)
4086 data
->phy_id
= adapter
->hw
.phy_addr
;
4089 if(!capable(CAP_NET_ADMIN
))
4091 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4092 if(e1000_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
4094 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4097 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4100 if(!capable(CAP_NET_ADMIN
))
4102 if(data
->reg_num
& ~(0x1F))
4104 mii_reg
= data
->val_in
;
4105 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
4106 if(e1000_write_phy_reg(&adapter
->hw
, data
->reg_num
,
4108 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4111 if(adapter
->hw
.phy_type
== e1000_phy_m88
) {
4112 switch (data
->reg_num
) {
4114 if(mii_reg
& MII_CR_POWER_DOWN
)
4116 if(mii_reg
& MII_CR_AUTO_NEG_EN
) {
4117 adapter
->hw
.autoneg
= 1;
4118 adapter
->hw
.autoneg_advertised
= 0x2F;
4121 spddplx
= SPEED_1000
;
4122 else if (mii_reg
& 0x2000)
4123 spddplx
= SPEED_100
;
4126 spddplx
+= (mii_reg
& 0x100)
4129 retval
= e1000_set_spd_dplx(adapter
,
4132 spin_unlock_irqrestore(
4133 &adapter
->stats_lock
,
4138 if(netif_running(adapter
->netdev
)) {
4139 e1000_down(adapter
);
4142 e1000_reset(adapter
);
4144 case M88E1000_PHY_SPEC_CTRL
:
4145 case M88E1000_EXT_PHY_SPEC_CTRL
:
4146 if(e1000_phy_reset(&adapter
->hw
)) {
4147 spin_unlock_irqrestore(
4148 &adapter
->stats_lock
, flags
);
4154 switch (data
->reg_num
) {
4156 if(mii_reg
& MII_CR_POWER_DOWN
)
4158 if(netif_running(adapter
->netdev
)) {
4159 e1000_down(adapter
);
4162 e1000_reset(adapter
);
4166 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4171 return E1000_SUCCESS
;
4175 e1000_pci_set_mwi(struct e1000_hw
*hw
)
4177 struct e1000_adapter
*adapter
= hw
->back
;
4178 int ret_val
= pci_set_mwi(adapter
->pdev
);
4181 DPRINTK(PROBE
, ERR
, "Error in setting MWI\n");
4185 e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4187 struct e1000_adapter
*adapter
= hw
->back
;
4189 pci_clear_mwi(adapter
->pdev
);
4193 e1000_read_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4195 struct e1000_adapter
*adapter
= hw
->back
;
4197 pci_read_config_word(adapter
->pdev
, reg
, value
);
4201 e1000_write_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4203 struct e1000_adapter
*adapter
= hw
->back
;
4205 pci_write_config_word(adapter
->pdev
, reg
, *value
);
4209 e1000_io_read(struct e1000_hw
*hw
, unsigned long port
)
4215 e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, uint32_t value
)
4221 e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
4223 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4224 uint32_t ctrl
, rctl
;
4226 e1000_irq_disable(adapter
);
4227 adapter
->vlgrp
= grp
;
4230 /* enable VLAN tag insert/strip */
4231 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4232 ctrl
|= E1000_CTRL_VME
;
4233 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4235 /* enable VLAN receive filtering */
4236 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4237 rctl
|= E1000_RCTL_VFE
;
4238 rctl
&= ~E1000_RCTL_CFIEN
;
4239 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4240 e1000_update_mng_vlan(adapter
);
4242 /* disable VLAN tag insert/strip */
4243 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4244 ctrl
&= ~E1000_CTRL_VME
;
4245 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4247 /* disable VLAN filtering */
4248 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4249 rctl
&= ~E1000_RCTL_VFE
;
4250 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4251 if(adapter
->mng_vlan_id
!= (uint16_t)E1000_MNG_VLAN_NONE
) {
4252 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
4253 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
4257 e1000_irq_enable(adapter
);
4261 e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
)
4263 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4264 uint32_t vfta
, index
;
4265 if((adapter
->hw
.mng_cookie
.status
&
4266 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4267 (vid
== adapter
->mng_vlan_id
))
4269 /* add VID to filter table */
4270 index
= (vid
>> 5) & 0x7F;
4271 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4272 vfta
|= (1 << (vid
& 0x1F));
4273 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4277 e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
)
4279 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4280 uint32_t vfta
, index
;
4282 e1000_irq_disable(adapter
);
4285 adapter
->vlgrp
->vlan_devices
[vid
] = NULL
;
4287 e1000_irq_enable(adapter
);
4289 if((adapter
->hw
.mng_cookie
.status
&
4290 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4291 (vid
== adapter
->mng_vlan_id
)) {
4292 /* release control to f/w */
4293 e1000_release_hw_control(adapter
);
4297 /* remove VID from filter table */
4298 index
= (vid
>> 5) & 0x7F;
4299 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4300 vfta
&= ~(1 << (vid
& 0x1F));
4301 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4305 e1000_restore_vlan(struct e1000_adapter
*adapter
)
4307 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
4309 if(adapter
->vlgrp
) {
4311 for(vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
4312 if(!adapter
->vlgrp
->vlan_devices
[vid
])
4314 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
4320 e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
)
4322 adapter
->hw
.autoneg
= 0;
4324 /* Fiber NICs only allow 1000 gbps Full duplex */
4325 if((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
4326 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
4327 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4332 case SPEED_10
+ DUPLEX_HALF
:
4333 adapter
->hw
.forced_speed_duplex
= e1000_10_half
;
4335 case SPEED_10
+ DUPLEX_FULL
:
4336 adapter
->hw
.forced_speed_duplex
= e1000_10_full
;
4338 case SPEED_100
+ DUPLEX_HALF
:
4339 adapter
->hw
.forced_speed_duplex
= e1000_100_half
;
4341 case SPEED_100
+ DUPLEX_FULL
:
4342 adapter
->hw
.forced_speed_duplex
= e1000_100_full
;
4344 case SPEED_1000
+ DUPLEX_FULL
:
4345 adapter
->hw
.autoneg
= 1;
4346 adapter
->hw
.autoneg_advertised
= ADVERTISE_1000_FULL
;
4348 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
4350 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4358 e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4360 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4361 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4362 uint32_t ctrl
, ctrl_ext
, rctl
, manc
, status
;
4363 uint32_t wufc
= adapter
->wol
;
4365 netif_device_detach(netdev
);
4367 if(netif_running(netdev
))
4368 e1000_down(adapter
);
4370 status
= E1000_READ_REG(&adapter
->hw
, STATUS
);
4371 if(status
& E1000_STATUS_LU
)
4372 wufc
&= ~E1000_WUFC_LNKC
;
4375 e1000_setup_rctl(adapter
);
4376 e1000_set_multi(netdev
);
4378 /* turn on all-multi mode if wake on multicast is enabled */
4379 if(adapter
->wol
& E1000_WUFC_MC
) {
4380 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4381 rctl
|= E1000_RCTL_MPE
;
4382 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4385 if(adapter
->hw
.mac_type
>= e1000_82540
) {
4386 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4387 /* advertise wake from D3Cold */
4388 #define E1000_CTRL_ADVD3WUC 0x00100000
4389 /* phy power management enable */
4390 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4391 ctrl
|= E1000_CTRL_ADVD3WUC
|
4392 E1000_CTRL_EN_PHY_PWR_MGMT
;
4393 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4396 if(adapter
->hw
.media_type
== e1000_media_type_fiber
||
4397 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) {
4398 /* keep the laser running in D3 */
4399 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
4400 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
4401 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
, ctrl_ext
);
4404 /* Allow time for pending master requests to run */
4405 e1000_disable_pciex_master(&adapter
->hw
);
4407 E1000_WRITE_REG(&adapter
->hw
, WUC
, E1000_WUC_PME_EN
);
4408 E1000_WRITE_REG(&adapter
->hw
, WUFC
, wufc
);
4409 pci_enable_wake(pdev
, 3, 1);
4410 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
4412 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
4413 E1000_WRITE_REG(&adapter
->hw
, WUFC
, 0);
4414 pci_enable_wake(pdev
, 3, 0);
4415 pci_enable_wake(pdev
, 4, 0); /* 4 == D3 cold */
4418 pci_save_state(pdev
);
4420 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4421 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4422 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4423 if(manc
& E1000_MANC_SMBUS_EN
) {
4424 manc
|= E1000_MANC_ARP_EN
;
4425 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4426 pci_enable_wake(pdev
, 3, 1);
4427 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
4431 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4432 * would have already happened in close and is redundant. */
4433 e1000_release_hw_control(adapter
);
4435 pci_disable_device(pdev
);
4436 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4442 e1000_resume(struct pci_dev
*pdev
)
4444 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4445 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4446 uint32_t manc
, ret_val
;
4448 pci_set_power_state(pdev
, PCI_D0
);
4449 pci_restore_state(pdev
);
4450 ret_val
= pci_enable_device(pdev
);
4451 pci_set_master(pdev
);
4453 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4454 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4456 e1000_reset(adapter
);
4457 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
4459 if(netif_running(netdev
))
4462 netif_device_attach(netdev
);
4464 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4465 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4466 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4467 manc
&= ~(E1000_MANC_ARP_EN
);
4468 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4471 /* If the controller is 82573 and f/w is AMT, do not set
4472 * DRV_LOAD until the interface is up. For all other cases,
4473 * let the f/w know that the h/w is now under the control
4475 if (adapter
->hw
.mac_type
!= e1000_82573
||
4476 !e1000_check_mng_mode(&adapter
->hw
))
4477 e1000_get_hw_control(adapter
);
4482 #ifdef CONFIG_NET_POLL_CONTROLLER
4484 * Polling 'interrupt' - used by things like netconsole to send skbs
4485 * without having to re-enable interrupts. It's not called while
4486 * the interrupt routine is executing.
4489 e1000_netpoll(struct net_device
*netdev
)
4491 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4492 disable_irq(adapter
->pdev
->irq
);
4493 e1000_intr(adapter
->pdev
->irq
, netdev
, NULL
);
4494 e1000_clean_tx_irq(adapter
, adapter
->tx_ring
);
4495 #ifndef CONFIG_E1000_NAPI
4496 adapter
->clean_rx(adapter
, adapter
->rx_ring
);
4498 enable_irq(adapter
->pdev
->irq
);