1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
33 * o Accepted ethtool cleanup patch from Stephen Hemminger
35 * o applied Anton's patch to resolve tx hang in hardware
36 * o Applied Andrew Mortons patch - e1000 stops working after resume
39 char e1000_driver_name
[] = "e1000";
40 static char e1000_driver_string
[] = "Intel(R) PRO/1000 Network Driver";
41 #ifndef CONFIG_E1000_NAPI
44 #define DRIVERNAPI "-NAPI"
46 #define DRV_VERSION "6.3.9-k2"DRIVERNAPI
47 char e1000_driver_version
[] = DRV_VERSION
;
48 static char e1000_copyright
[] = "Copyright (c) 1999-2005 Intel Corporation.";
50 /* e1000_pci_tbl - PCI Device ID Table
52 * Last entry must be all 0s
55 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
57 static struct pci_device_id e1000_pci_tbl
[] = {
58 INTEL_E1000_ETHERNET_DEVICE(0x1000),
59 INTEL_E1000_ETHERNET_DEVICE(0x1001),
60 INTEL_E1000_ETHERNET_DEVICE(0x1004),
61 INTEL_E1000_ETHERNET_DEVICE(0x1008),
62 INTEL_E1000_ETHERNET_DEVICE(0x1009),
63 INTEL_E1000_ETHERNET_DEVICE(0x100C),
64 INTEL_E1000_ETHERNET_DEVICE(0x100D),
65 INTEL_E1000_ETHERNET_DEVICE(0x100E),
66 INTEL_E1000_ETHERNET_DEVICE(0x100F),
67 INTEL_E1000_ETHERNET_DEVICE(0x1010),
68 INTEL_E1000_ETHERNET_DEVICE(0x1011),
69 INTEL_E1000_ETHERNET_DEVICE(0x1012),
70 INTEL_E1000_ETHERNET_DEVICE(0x1013),
71 INTEL_E1000_ETHERNET_DEVICE(0x1014),
72 INTEL_E1000_ETHERNET_DEVICE(0x1015),
73 INTEL_E1000_ETHERNET_DEVICE(0x1016),
74 INTEL_E1000_ETHERNET_DEVICE(0x1017),
75 INTEL_E1000_ETHERNET_DEVICE(0x1018),
76 INTEL_E1000_ETHERNET_DEVICE(0x1019),
77 INTEL_E1000_ETHERNET_DEVICE(0x101A),
78 INTEL_E1000_ETHERNET_DEVICE(0x101D),
79 INTEL_E1000_ETHERNET_DEVICE(0x101E),
80 INTEL_E1000_ETHERNET_DEVICE(0x1026),
81 INTEL_E1000_ETHERNET_DEVICE(0x1027),
82 INTEL_E1000_ETHERNET_DEVICE(0x1028),
83 INTEL_E1000_ETHERNET_DEVICE(0x105E),
84 INTEL_E1000_ETHERNET_DEVICE(0x105F),
85 INTEL_E1000_ETHERNET_DEVICE(0x1060),
86 INTEL_E1000_ETHERNET_DEVICE(0x1075),
87 INTEL_E1000_ETHERNET_DEVICE(0x1076),
88 INTEL_E1000_ETHERNET_DEVICE(0x1077),
89 INTEL_E1000_ETHERNET_DEVICE(0x1078),
90 INTEL_E1000_ETHERNET_DEVICE(0x1079),
91 INTEL_E1000_ETHERNET_DEVICE(0x107A),
92 INTEL_E1000_ETHERNET_DEVICE(0x107B),
93 INTEL_E1000_ETHERNET_DEVICE(0x107C),
94 INTEL_E1000_ETHERNET_DEVICE(0x107D),
95 INTEL_E1000_ETHERNET_DEVICE(0x107E),
96 INTEL_E1000_ETHERNET_DEVICE(0x107F),
97 INTEL_E1000_ETHERNET_DEVICE(0x108A),
98 INTEL_E1000_ETHERNET_DEVICE(0x108B),
99 INTEL_E1000_ETHERNET_DEVICE(0x108C),
100 INTEL_E1000_ETHERNET_DEVICE(0x109A),
101 /* required last entry */
105 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
107 int e1000_up(struct e1000_adapter
*adapter
);
108 void e1000_down(struct e1000_adapter
*adapter
);
109 void e1000_reset(struct e1000_adapter
*adapter
);
110 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
);
111 int e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
);
112 int e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
);
113 void e1000_free_all_tx_resources(struct e1000_adapter
*adapter
);
114 void e1000_free_all_rx_resources(struct e1000_adapter
*adapter
);
115 static int e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
116 struct e1000_tx_ring
*txdr
);
117 static int e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
118 struct e1000_rx_ring
*rxdr
);
119 static void e1000_free_tx_resources(struct e1000_adapter
*adapter
,
120 struct e1000_tx_ring
*tx_ring
);
121 static void e1000_free_rx_resources(struct e1000_adapter
*adapter
,
122 struct e1000_rx_ring
*rx_ring
);
123 void e1000_update_stats(struct e1000_adapter
*adapter
);
125 /* Local Function Prototypes */
127 static int e1000_init_module(void);
128 static void e1000_exit_module(void);
129 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
130 static void __devexit
e1000_remove(struct pci_dev
*pdev
);
131 static int e1000_alloc_queues(struct e1000_adapter
*adapter
);
132 #ifdef CONFIG_E1000_MQ
133 static void e1000_setup_queue_mapping(struct e1000_adapter
*adapter
);
135 static int e1000_sw_init(struct e1000_adapter
*adapter
);
136 static int e1000_open(struct net_device
*netdev
);
137 static int e1000_close(struct net_device
*netdev
);
138 static void e1000_configure_tx(struct e1000_adapter
*adapter
);
139 static void e1000_configure_rx(struct e1000_adapter
*adapter
);
140 static void e1000_setup_rctl(struct e1000_adapter
*adapter
);
141 static void e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
);
142 static void e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
);
143 static void e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
144 struct e1000_tx_ring
*tx_ring
);
145 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
146 struct e1000_rx_ring
*rx_ring
);
147 static void e1000_set_multi(struct net_device
*netdev
);
148 static void e1000_update_phy_info(unsigned long data
);
149 static void e1000_watchdog(unsigned long data
);
150 static void e1000_watchdog_task(struct e1000_adapter
*adapter
);
151 static void e1000_82547_tx_fifo_stall(unsigned long data
);
152 static int e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
);
153 static struct net_device_stats
* e1000_get_stats(struct net_device
*netdev
);
154 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
155 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
156 static irqreturn_t
e1000_intr(int irq
, void *data
, struct pt_regs
*regs
);
157 static boolean_t
e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
158 struct e1000_tx_ring
*tx_ring
);
159 #ifdef CONFIG_E1000_NAPI
160 static int e1000_clean(struct net_device
*poll_dev
, int *budget
);
161 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
162 struct e1000_rx_ring
*rx_ring
,
163 int *work_done
, int work_to_do
);
164 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
165 struct e1000_rx_ring
*rx_ring
,
166 int *work_done
, int work_to_do
);
168 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
169 struct e1000_rx_ring
*rx_ring
);
170 static boolean_t
e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
171 struct e1000_rx_ring
*rx_ring
);
173 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
174 struct e1000_rx_ring
*rx_ring
);
175 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
176 struct e1000_rx_ring
*rx_ring
);
177 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
178 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
180 void e1000_set_ethtool_ops(struct net_device
*netdev
);
181 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
182 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
183 static void e1000_tx_timeout(struct net_device
*dev
);
184 static void e1000_tx_timeout_task(struct net_device
*dev
);
185 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
186 static inline int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
187 struct sk_buff
*skb
);
189 static void e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
);
190 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
);
191 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
);
192 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
195 static int e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
);
196 static int e1000_resume(struct pci_dev
*pdev
);
199 #ifdef CONFIG_NET_POLL_CONTROLLER
200 /* for netdump / net console */
201 static void e1000_netpoll (struct net_device
*netdev
);
204 #ifdef CONFIG_E1000_MQ
205 /* for multiple Rx queues */
206 void e1000_rx_schedule(void *data
);
209 /* Exported from other modules */
211 extern void e1000_check_options(struct e1000_adapter
*adapter
);
213 static struct pci_driver e1000_driver
= {
214 .name
= e1000_driver_name
,
215 .id_table
= e1000_pci_tbl
,
216 .probe
= e1000_probe
,
217 .remove
= __devexit_p(e1000_remove
),
218 /* Power Managment Hooks */
220 .suspend
= e1000_suspend
,
221 .resume
= e1000_resume
225 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
226 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
227 MODULE_LICENSE("GPL");
228 MODULE_VERSION(DRV_VERSION
);
230 static int debug
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
231 module_param(debug
, int, 0);
232 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
235 * e1000_init_module - Driver Registration Routine
237 * e1000_init_module is the first routine called when the driver is
238 * loaded. All it does is register with the PCI subsystem.
242 e1000_init_module(void)
245 printk(KERN_INFO
"%s - version %s\n",
246 e1000_driver_string
, e1000_driver_version
);
248 printk(KERN_INFO
"%s\n", e1000_copyright
);
250 ret
= pci_module_init(&e1000_driver
);
255 module_init(e1000_init_module
);
258 * e1000_exit_module - Driver Exit Cleanup Routine
260 * e1000_exit_module is called just before the driver is removed
265 e1000_exit_module(void)
267 pci_unregister_driver(&e1000_driver
);
270 module_exit(e1000_exit_module
);
273 * e1000_irq_disable - Mask off interrupt generation on the NIC
274 * @adapter: board private structure
278 e1000_irq_disable(struct e1000_adapter
*adapter
)
280 atomic_inc(&adapter
->irq_sem
);
281 E1000_WRITE_REG(&adapter
->hw
, IMC
, ~0);
282 E1000_WRITE_FLUSH(&adapter
->hw
);
283 synchronize_irq(adapter
->pdev
->irq
);
287 * e1000_irq_enable - Enable default interrupt generation settings
288 * @adapter: board private structure
292 e1000_irq_enable(struct e1000_adapter
*adapter
)
294 if(likely(atomic_dec_and_test(&adapter
->irq_sem
))) {
295 E1000_WRITE_REG(&adapter
->hw
, IMS
, IMS_ENABLE_MASK
);
296 E1000_WRITE_FLUSH(&adapter
->hw
);
301 e1000_update_mng_vlan(struct e1000_adapter
*adapter
)
303 struct net_device
*netdev
= adapter
->netdev
;
304 uint16_t vid
= adapter
->hw
.mng_cookie
.vlan_id
;
305 uint16_t old_vid
= adapter
->mng_vlan_id
;
307 if(!adapter
->vlgrp
->vlan_devices
[vid
]) {
308 if(adapter
->hw
.mng_cookie
.status
&
309 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) {
310 e1000_vlan_rx_add_vid(netdev
, vid
);
311 adapter
->mng_vlan_id
= vid
;
313 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
315 if((old_vid
!= (uint16_t)E1000_MNG_VLAN_NONE
) &&
317 !adapter
->vlgrp
->vlan_devices
[old_vid
])
318 e1000_vlan_rx_kill_vid(netdev
, old_vid
);
324 * e1000_release_hw_control - release control of the h/w to f/w
325 * @adapter: address of board private structure
327 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
328 * For ASF and Pass Through versions of f/w this means that the
329 * driver is no longer loaded. For AMT version (only with 82573) i
330 * of the f/w this means that the netowrk i/f is closed.
335 e1000_release_hw_control(struct e1000_adapter
*adapter
)
340 /* Let firmware taken over control of h/w */
341 switch (adapter
->hw
.mac_type
) {
344 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
345 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
346 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
349 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
350 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
351 swsm
& ~E1000_SWSM_DRV_LOAD
);
358 * e1000_get_hw_control - get control of the h/w from f/w
359 * @adapter: address of board private structure
361 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
362 * For ASF and Pass Through versions of f/w this means that
363 * the driver is loaded. For AMT version (only with 82573)
364 * of the f/w this means that the netowrk i/f is open.
369 e1000_get_hw_control(struct e1000_adapter
*adapter
)
373 /* Let firmware know the driver has taken over */
374 switch (adapter
->hw
.mac_type
) {
377 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
378 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
,
379 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
382 swsm
= E1000_READ_REG(&adapter
->hw
, SWSM
);
383 E1000_WRITE_REG(&adapter
->hw
, SWSM
,
384 swsm
| E1000_SWSM_DRV_LOAD
);
392 e1000_up(struct e1000_adapter
*adapter
)
394 struct net_device
*netdev
= adapter
->netdev
;
397 /* hardware has been reset, we need to reload some things */
399 /* Reset the PHY if it was previously powered down */
400 if(adapter
->hw
.media_type
== e1000_media_type_copper
) {
402 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
403 if(mii_reg
& MII_CR_POWER_DOWN
)
404 e1000_phy_reset(&adapter
->hw
);
407 e1000_set_multi(netdev
);
409 e1000_restore_vlan(adapter
);
411 e1000_configure_tx(adapter
);
412 e1000_setup_rctl(adapter
);
413 e1000_configure_rx(adapter
);
414 for (i
= 0; i
< adapter
->num_queues
; i
++)
415 adapter
->alloc_rx_buf(adapter
, &adapter
->rx_ring
[i
]);
417 #ifdef CONFIG_PCI_MSI
418 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
419 adapter
->have_msi
= TRUE
;
420 if((err
= pci_enable_msi(adapter
->pdev
))) {
422 "Unable to allocate MSI interrupt Error: %d\n", err
);
423 adapter
->have_msi
= FALSE
;
427 if((err
= request_irq(adapter
->pdev
->irq
, &e1000_intr
,
428 SA_SHIRQ
| SA_SAMPLE_RANDOM
,
429 netdev
->name
, netdev
))) {
431 "Unable to allocate interrupt Error: %d\n", err
);
435 mod_timer(&adapter
->watchdog_timer
, jiffies
);
437 #ifdef CONFIG_E1000_NAPI
438 netif_poll_enable(netdev
);
440 e1000_irq_enable(adapter
);
446 e1000_down(struct e1000_adapter
*adapter
)
448 struct net_device
*netdev
= adapter
->netdev
;
449 boolean_t mng_mode_enabled
= (adapter
->hw
.mac_type
>= e1000_82571
) &&
450 e1000_check_mng_mode(&adapter
->hw
);
452 e1000_irq_disable(adapter
);
453 #ifdef CONFIG_E1000_MQ
454 while (atomic_read(&adapter
->rx_sched_call_data
.count
) != 0);
456 free_irq(adapter
->pdev
->irq
, netdev
);
457 #ifdef CONFIG_PCI_MSI
458 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
&&
459 adapter
->have_msi
== TRUE
)
460 pci_disable_msi(adapter
->pdev
);
462 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
463 del_timer_sync(&adapter
->watchdog_timer
);
464 del_timer_sync(&adapter
->phy_info_timer
);
466 #ifdef CONFIG_E1000_NAPI
467 netif_poll_disable(netdev
);
469 adapter
->link_speed
= 0;
470 adapter
->link_duplex
= 0;
471 netif_carrier_off(netdev
);
472 netif_stop_queue(netdev
);
474 e1000_reset(adapter
);
475 e1000_clean_all_tx_rings(adapter
);
476 e1000_clean_all_rx_rings(adapter
);
478 /* Power down the PHY so no link is implied when interface is down *
479 * The PHY cannot be powered down if any of the following is TRUE *
482 * (c) SoL/IDER session is active */
483 if (!adapter
->wol
&& adapter
->hw
.mac_type
>= e1000_82540
&&
484 adapter
->hw
.media_type
== e1000_media_type_copper
&&
485 !(E1000_READ_REG(&adapter
->hw
, MANC
) & E1000_MANC_SMBUS_EN
) &&
487 !e1000_check_phy_reset_block(&adapter
->hw
)) {
489 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
490 mii_reg
|= MII_CR_POWER_DOWN
;
491 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
497 e1000_reset(struct e1000_adapter
*adapter
)
499 struct net_device
*netdev
= adapter
->netdev
;
501 uint16_t fc_high_water_mark
= E1000_FC_HIGH_DIFF
;
502 uint16_t fc_low_water_mark
= E1000_FC_LOW_DIFF
;
504 /* Repartition Pba for greater than 9k mtu
505 * To take effect CTRL.RST is required.
508 switch (adapter
->hw
.mac_type
) {
510 case e1000_82547_rev_2
:
525 if((adapter
->hw
.mac_type
!= e1000_82573
) &&
526 (adapter
->netdev
->mtu
> E1000_RXBUFFER_8192
)) {
527 pba
-= 8; /* allocate more FIFO for Tx */
528 /* send an XOFF when there is enough space in the
529 * Rx FIFO to hold one extra full size Rx packet
531 fc_high_water_mark
= netdev
->mtu
+ ENET_HEADER_SIZE
+
532 ETHERNET_FCS_SIZE
+ 1;
533 fc_low_water_mark
= fc_high_water_mark
+ 8;
537 if(adapter
->hw
.mac_type
== e1000_82547
) {
538 adapter
->tx_fifo_head
= 0;
539 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
540 adapter
->tx_fifo_size
=
541 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
542 atomic_set(&adapter
->tx_fifo_stall
, 0);
545 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
547 /* flow control settings */
548 adapter
->hw
.fc_high_water
= (pba
<< E1000_PBA_BYTES_SHIFT
) -
550 adapter
->hw
.fc_low_water
= (pba
<< E1000_PBA_BYTES_SHIFT
) -
552 adapter
->hw
.fc_pause_time
= E1000_FC_PAUSE_TIME
;
553 adapter
->hw
.fc_send_xon
= 1;
554 adapter
->hw
.fc
= adapter
->hw
.original_fc
;
556 /* Allow time for pending master requests to run */
557 e1000_reset_hw(&adapter
->hw
);
558 if(adapter
->hw
.mac_type
>= e1000_82544
)
559 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
560 if(e1000_init_hw(&adapter
->hw
))
561 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
562 e1000_update_mng_vlan(adapter
);
563 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
564 E1000_WRITE_REG(&adapter
->hw
, VET
, ETHERNET_IEEE_VLAN_TYPE
);
566 e1000_reset_adaptive(&adapter
->hw
);
567 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
568 if (adapter
->en_mng_pt
) {
569 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
570 manc
|= (E1000_MANC_ARP_EN
| E1000_MANC_EN_MNG2HOST
);
571 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
576 * e1000_probe - Device Initialization Routine
577 * @pdev: PCI device information struct
578 * @ent: entry in e1000_pci_tbl
580 * Returns 0 on success, negative on failure
582 * e1000_probe initializes an adapter identified by a pci_dev structure.
583 * The OS initialization, configuring of the adapter private structure,
584 * and a hardware reset occur.
588 e1000_probe(struct pci_dev
*pdev
,
589 const struct pci_device_id
*ent
)
591 struct net_device
*netdev
;
592 struct e1000_adapter
*adapter
;
593 unsigned long mmio_start
, mmio_len
;
595 static int cards_found
= 0;
596 int i
, err
, pci_using_dac
;
597 uint16_t eeprom_data
;
598 uint16_t eeprom_apme_mask
= E1000_EEPROM_APME
;
599 if((err
= pci_enable_device(pdev
)))
602 if(!(err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
))) {
605 if((err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
))) {
606 E1000_ERR("No usable DMA configuration, aborting\n");
612 if((err
= pci_request_regions(pdev
, e1000_driver_name
)))
615 pci_set_master(pdev
);
617 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
620 goto err_alloc_etherdev
;
623 SET_MODULE_OWNER(netdev
);
624 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
626 pci_set_drvdata(pdev
, netdev
);
627 adapter
= netdev_priv(netdev
);
628 adapter
->netdev
= netdev
;
629 adapter
->pdev
= pdev
;
630 adapter
->hw
.back
= adapter
;
631 adapter
->msg_enable
= (1 << debug
) - 1;
633 mmio_start
= pci_resource_start(pdev
, BAR_0
);
634 mmio_len
= pci_resource_len(pdev
, BAR_0
);
636 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
637 if(!adapter
->hw
.hw_addr
) {
642 for(i
= BAR_1
; i
<= BAR_5
; i
++) {
643 if(pci_resource_len(pdev
, i
) == 0)
645 if(pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
646 adapter
->hw
.io_base
= pci_resource_start(pdev
, i
);
651 netdev
->open
= &e1000_open
;
652 netdev
->stop
= &e1000_close
;
653 netdev
->hard_start_xmit
= &e1000_xmit_frame
;
654 netdev
->get_stats
= &e1000_get_stats
;
655 netdev
->set_multicast_list
= &e1000_set_multi
;
656 netdev
->set_mac_address
= &e1000_set_mac
;
657 netdev
->change_mtu
= &e1000_change_mtu
;
658 netdev
->do_ioctl
= &e1000_ioctl
;
659 e1000_set_ethtool_ops(netdev
);
660 netdev
->tx_timeout
= &e1000_tx_timeout
;
661 netdev
->watchdog_timeo
= 5 * HZ
;
662 #ifdef CONFIG_E1000_NAPI
663 netdev
->poll
= &e1000_clean
;
666 netdev
->vlan_rx_register
= e1000_vlan_rx_register
;
667 netdev
->vlan_rx_add_vid
= e1000_vlan_rx_add_vid
;
668 netdev
->vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
;
669 #ifdef CONFIG_NET_POLL_CONTROLLER
670 netdev
->poll_controller
= e1000_netpoll
;
672 strcpy(netdev
->name
, pci_name(pdev
));
674 netdev
->mem_start
= mmio_start
;
675 netdev
->mem_end
= mmio_start
+ mmio_len
;
676 netdev
->base_addr
= adapter
->hw
.io_base
;
678 adapter
->bd_number
= cards_found
;
680 /* setup the private structure */
682 if((err
= e1000_sw_init(adapter
)))
685 if((err
= e1000_check_phy_reset_block(&adapter
->hw
)))
686 DPRINTK(PROBE
, INFO
, "PHY reset is blocked due to SOL/IDER session.\n");
688 if(adapter
->hw
.mac_type
>= e1000_82543
) {
689 netdev
->features
= NETIF_F_SG
|
693 NETIF_F_HW_VLAN_FILTER
;
697 if((adapter
->hw
.mac_type
>= e1000_82544
) &&
698 (adapter
->hw
.mac_type
!= e1000_82547
))
699 netdev
->features
|= NETIF_F_TSO
;
701 #ifdef NETIF_F_TSO_IPV6
702 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
)
703 netdev
->features
|= NETIF_F_TSO_IPV6
;
707 netdev
->features
|= NETIF_F_HIGHDMA
;
709 /* hard_start_xmit is safe against parallel locking */
710 netdev
->features
|= NETIF_F_LLTX
;
712 adapter
->en_mng_pt
= e1000_enable_mng_pass_thru(&adapter
->hw
);
714 /* before reading the EEPROM, reset the controller to
715 * put the device in a known good starting state */
717 e1000_reset_hw(&adapter
->hw
);
719 /* make sure the EEPROM is good */
721 if(e1000_validate_eeprom_checksum(&adapter
->hw
) < 0) {
722 DPRINTK(PROBE
, ERR
, "The EEPROM Checksum Is Not Valid\n");
727 /* copy the MAC address out of the EEPROM */
729 if(e1000_read_mac_addr(&adapter
->hw
))
730 DPRINTK(PROBE
, ERR
, "EEPROM Read Error\n");
731 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
732 memcpy(netdev
->perm_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
734 if(!is_valid_ether_addr(netdev
->perm_addr
)) {
735 DPRINTK(PROBE
, ERR
, "Invalid MAC Address\n");
740 e1000_read_part_num(&adapter
->hw
, &(adapter
->part_num
));
742 e1000_get_bus_info(&adapter
->hw
);
744 init_timer(&adapter
->tx_fifo_stall_timer
);
745 adapter
->tx_fifo_stall_timer
.function
= &e1000_82547_tx_fifo_stall
;
746 adapter
->tx_fifo_stall_timer
.data
= (unsigned long) adapter
;
748 init_timer(&adapter
->watchdog_timer
);
749 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
750 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
752 INIT_WORK(&adapter
->watchdog_task
,
753 (void (*)(void *))e1000_watchdog_task
, adapter
);
755 init_timer(&adapter
->phy_info_timer
);
756 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
757 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
759 INIT_WORK(&adapter
->tx_timeout_task
,
760 (void (*)(void *))e1000_tx_timeout_task
, netdev
);
762 /* we're going to reset, so assume we have no link for now */
764 netif_carrier_off(netdev
);
765 netif_stop_queue(netdev
);
767 e1000_check_options(adapter
);
769 /* Initial Wake on LAN setting
770 * If APM wake is enabled in the EEPROM,
771 * enable the ACPI Magic Packet filter
774 switch(adapter
->hw
.mac_type
) {
775 case e1000_82542_rev2_0
:
776 case e1000_82542_rev2_1
:
780 e1000_read_eeprom(&adapter
->hw
,
781 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
782 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
785 case e1000_82546_rev_3
:
787 if((E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
)
788 && (adapter
->hw
.media_type
== e1000_media_type_copper
)) {
789 e1000_read_eeprom(&adapter
->hw
,
790 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
795 e1000_read_eeprom(&adapter
->hw
,
796 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
799 if(eeprom_data
& eeprom_apme_mask
)
800 adapter
->wol
|= E1000_WUFC_MAG
;
802 /* reset the hardware with the new settings */
803 e1000_reset(adapter
);
805 /* If the controller is 82573 and f/w is AMT, do not set
806 * DRV_LOAD until the interface is up. For all other cases,
807 * let the f/w know that the h/w is now under the control
809 if (adapter
->hw
.mac_type
!= e1000_82573
||
810 !e1000_check_mng_mode(&adapter
->hw
))
811 e1000_get_hw_control(adapter
);
813 strcpy(netdev
->name
, "eth%d");
814 if((err
= register_netdev(netdev
)))
817 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
825 iounmap(adapter
->hw
.hw_addr
);
829 pci_release_regions(pdev
);
834 * e1000_remove - Device Removal Routine
835 * @pdev: PCI device information struct
837 * e1000_remove is called by the PCI subsystem to alert the driver
838 * that it should release a PCI device. The could be caused by a
839 * Hot-Plug event, or because the driver is going to be removed from
843 static void __devexit
844 e1000_remove(struct pci_dev
*pdev
)
846 struct net_device
*netdev
= pci_get_drvdata(pdev
);
847 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
849 #ifdef CONFIG_E1000_NAPI
853 flush_scheduled_work();
855 if(adapter
->hw
.mac_type
>= e1000_82540
&&
856 adapter
->hw
.media_type
== e1000_media_type_copper
) {
857 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
858 if(manc
& E1000_MANC_SMBUS_EN
) {
859 manc
|= E1000_MANC_ARP_EN
;
860 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
864 /* Release control of h/w to f/w. If f/w is AMT enabled, this
865 * would have already happened in close and is redundant. */
866 e1000_release_hw_control(adapter
);
868 unregister_netdev(netdev
);
869 #ifdef CONFIG_E1000_NAPI
870 for (i
= 0; i
< adapter
->num_queues
; i
++)
871 __dev_put(&adapter
->polling_netdev
[i
]);
874 if(!e1000_check_phy_reset_block(&adapter
->hw
))
875 e1000_phy_hw_reset(&adapter
->hw
);
877 kfree(adapter
->tx_ring
);
878 kfree(adapter
->rx_ring
);
879 #ifdef CONFIG_E1000_NAPI
880 kfree(adapter
->polling_netdev
);
883 iounmap(adapter
->hw
.hw_addr
);
884 pci_release_regions(pdev
);
886 #ifdef CONFIG_E1000_MQ
887 free_percpu(adapter
->cpu_netdev
);
888 free_percpu(adapter
->cpu_tx_ring
);
892 pci_disable_device(pdev
);
896 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
897 * @adapter: board private structure to initialize
899 * e1000_sw_init initializes the Adapter private data structure.
900 * Fields are initialized based on PCI device information and
901 * OS network device settings (MTU size).
905 e1000_sw_init(struct e1000_adapter
*adapter
)
907 struct e1000_hw
*hw
= &adapter
->hw
;
908 struct net_device
*netdev
= adapter
->netdev
;
909 struct pci_dev
*pdev
= adapter
->pdev
;
910 #ifdef CONFIG_E1000_NAPI
914 /* PCI config space info */
916 hw
->vendor_id
= pdev
->vendor
;
917 hw
->device_id
= pdev
->device
;
918 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
919 hw
->subsystem_id
= pdev
->subsystem_device
;
921 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
923 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
925 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
926 adapter
->rx_ps_bsize0
= E1000_RXBUFFER_256
;
927 hw
->max_frame_size
= netdev
->mtu
+
928 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
929 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
931 /* identify the MAC */
933 if(e1000_set_mac_type(hw
)) {
934 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
938 /* initialize eeprom parameters */
940 if(e1000_init_eeprom_params(hw
)) {
941 E1000_ERR("EEPROM initialization failed\n");
945 switch(hw
->mac_type
) {
950 case e1000_82541_rev_2
:
951 case e1000_82547_rev_2
:
952 hw
->phy_init_script
= 1;
956 e1000_set_media_type(hw
);
958 hw
->wait_autoneg_complete
= FALSE
;
959 hw
->tbi_compatibility_en
= TRUE
;
960 hw
->adaptive_ifs
= TRUE
;
964 if(hw
->media_type
== e1000_media_type_copper
) {
965 hw
->mdix
= AUTO_ALL_MODES
;
966 hw
->disable_polarity_correction
= FALSE
;
967 hw
->master_slave
= E1000_MASTER_SLAVE
;
970 #ifdef CONFIG_E1000_MQ
971 /* Number of supported queues */
972 switch (hw
->mac_type
) {
975 adapter
->num_queues
= 2;
978 adapter
->num_queues
= 1;
981 adapter
->num_queues
= min(adapter
->num_queues
, num_online_cpus());
983 adapter
->num_queues
= 1;
986 if (e1000_alloc_queues(adapter
)) {
987 DPRINTK(PROBE
, ERR
, "Unable to allocate memory for queues\n");
991 #ifdef CONFIG_E1000_NAPI
992 for (i
= 0; i
< adapter
->num_queues
; i
++) {
993 adapter
->polling_netdev
[i
].priv
= adapter
;
994 adapter
->polling_netdev
[i
].poll
= &e1000_clean
;
995 adapter
->polling_netdev
[i
].weight
= 64;
996 dev_hold(&adapter
->polling_netdev
[i
]);
997 set_bit(__LINK_STATE_START
, &adapter
->polling_netdev
[i
].state
);
1001 #ifdef CONFIG_E1000_MQ
1002 e1000_setup_queue_mapping(adapter
);
1005 atomic_set(&adapter
->irq_sem
, 1);
1006 spin_lock_init(&adapter
->stats_lock
);
1012 * e1000_alloc_queues - Allocate memory for all rings
1013 * @adapter: board private structure to initialize
1015 * We allocate one ring per queue at run-time since we don't know the
1016 * number of queues at compile-time. The polling_netdev array is
1017 * intended for Multiqueue, but should work fine with a single queue.
1020 static int __devinit
1021 e1000_alloc_queues(struct e1000_adapter
*adapter
)
1025 size
= sizeof(struct e1000_tx_ring
) * adapter
->num_queues
;
1026 adapter
->tx_ring
= kmalloc(size
, GFP_KERNEL
);
1027 if (!adapter
->tx_ring
)
1029 memset(adapter
->tx_ring
, 0, size
);
1031 size
= sizeof(struct e1000_rx_ring
) * adapter
->num_queues
;
1032 adapter
->rx_ring
= kmalloc(size
, GFP_KERNEL
);
1033 if (!adapter
->rx_ring
) {
1034 kfree(adapter
->tx_ring
);
1037 memset(adapter
->rx_ring
, 0, size
);
1039 #ifdef CONFIG_E1000_NAPI
1040 size
= sizeof(struct net_device
) * adapter
->num_queues
;
1041 adapter
->polling_netdev
= kmalloc(size
, GFP_KERNEL
);
1042 if (!adapter
->polling_netdev
) {
1043 kfree(adapter
->tx_ring
);
1044 kfree(adapter
->rx_ring
);
1047 memset(adapter
->polling_netdev
, 0, size
);
1050 return E1000_SUCCESS
;
1053 #ifdef CONFIG_E1000_MQ
1054 static void __devinit
1055 e1000_setup_queue_mapping(struct e1000_adapter
*adapter
)
1059 adapter
->rx_sched_call_data
.func
= e1000_rx_schedule
;
1060 adapter
->rx_sched_call_data
.info
= adapter
->netdev
;
1061 cpus_clear(adapter
->rx_sched_call_data
.cpumask
);
1063 adapter
->cpu_netdev
= alloc_percpu(struct net_device
*);
1064 adapter
->cpu_tx_ring
= alloc_percpu(struct e1000_tx_ring
*);
1068 for_each_online_cpu(cpu
) {
1069 *per_cpu_ptr(adapter
->cpu_tx_ring
, cpu
) = &adapter
->tx_ring
[i
% adapter
->num_queues
];
1070 /* This is incomplete because we'd like to assign separate
1071 * physical cpus to these netdev polling structures and
1072 * avoid saturating a subset of cpus.
1074 if (i
< adapter
->num_queues
) {
1075 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = &adapter
->polling_netdev
[i
];
1076 adapter
->cpu_for_queue
[i
] = cpu
;
1078 *per_cpu_ptr(adapter
->cpu_netdev
, cpu
) = NULL
;
1082 unlock_cpu_hotplug();
1087 * e1000_open - Called when a network interface is made active
1088 * @netdev: network interface device structure
1090 * Returns 0 on success, negative value on failure
1092 * The open entry point is called when a network interface is made
1093 * active by the system (IFF_UP). At this point all resources needed
1094 * for transmit and receive operations are allocated, the interrupt
1095 * handler is registered with the OS, the watchdog timer is started,
1096 * and the stack is notified that the interface is ready.
1100 e1000_open(struct net_device
*netdev
)
1102 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1105 /* allocate transmit descriptors */
1107 if ((err
= e1000_setup_all_tx_resources(adapter
)))
1110 /* allocate receive descriptors */
1112 if ((err
= e1000_setup_all_rx_resources(adapter
)))
1115 if((err
= e1000_up(adapter
)))
1117 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
1118 if((adapter
->hw
.mng_cookie
.status
&
1119 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1120 e1000_update_mng_vlan(adapter
);
1123 /* If AMT is enabled, let the firmware know that the network
1124 * interface is now open */
1125 if (adapter
->hw
.mac_type
== e1000_82573
&&
1126 e1000_check_mng_mode(&adapter
->hw
))
1127 e1000_get_hw_control(adapter
);
1129 return E1000_SUCCESS
;
1132 e1000_free_all_rx_resources(adapter
);
1134 e1000_free_all_tx_resources(adapter
);
1136 e1000_reset(adapter
);
1142 * e1000_close - Disables a network interface
1143 * @netdev: network interface device structure
1145 * Returns 0, this is not allowed to fail
1147 * The close entry point is called when an interface is de-activated
1148 * by the OS. The hardware is still under the drivers control, but
1149 * needs to be disabled. A global MAC reset is issued to stop the
1150 * hardware, and all transmit and receive resources are freed.
1154 e1000_close(struct net_device
*netdev
)
1156 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1158 e1000_down(adapter
);
1160 e1000_free_all_tx_resources(adapter
);
1161 e1000_free_all_rx_resources(adapter
);
1163 if((adapter
->hw
.mng_cookie
.status
&
1164 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) {
1165 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1168 /* If AMT is enabled, let the firmware know that the network
1169 * interface is now closed */
1170 if (adapter
->hw
.mac_type
== e1000_82573
&&
1171 e1000_check_mng_mode(&adapter
->hw
))
1172 e1000_release_hw_control(adapter
);
1178 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1179 * @adapter: address of board private structure
1180 * @start: address of beginning of memory
1181 * @len: length of memory
1183 static inline boolean_t
1184 e1000_check_64k_bound(struct e1000_adapter
*adapter
,
1185 void *start
, unsigned long len
)
1187 unsigned long begin
= (unsigned long) start
;
1188 unsigned long end
= begin
+ len
;
1190 /* First rev 82545 and 82546 need to not allow any memory
1191 * write location to cross 64k boundary due to errata 23 */
1192 if (adapter
->hw
.mac_type
== e1000_82545
||
1193 adapter
->hw
.mac_type
== e1000_82546
) {
1194 return ((begin
^ (end
- 1)) >> 16) != 0 ? FALSE
: TRUE
;
1201 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1202 * @adapter: board private structure
1203 * @txdr: tx descriptor ring (for a specific queue) to setup
1205 * Return 0 on success, negative on failure
1209 e1000_setup_tx_resources(struct e1000_adapter
*adapter
,
1210 struct e1000_tx_ring
*txdr
)
1212 struct pci_dev
*pdev
= adapter
->pdev
;
1215 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
1217 txdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1218 if(!txdr
->buffer_info
) {
1220 "Unable to allocate memory for the transmit descriptor ring\n");
1223 memset(txdr
->buffer_info
, 0, size
);
1225 /* round up to nearest 4K */
1227 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
1228 E1000_ROUNDUP(txdr
->size
, 4096);
1230 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1233 vfree(txdr
->buffer_info
);
1235 "Unable to allocate memory for the transmit descriptor ring\n");
1239 /* Fix for errata 23, can't cross 64kB boundary */
1240 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1241 void *olddesc
= txdr
->desc
;
1242 dma_addr_t olddma
= txdr
->dma
;
1243 DPRINTK(TX_ERR
, ERR
, "txdr align check failed: %u bytes "
1244 "at %p\n", txdr
->size
, txdr
->desc
);
1245 /* Try again, without freeing the previous */
1246 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
1248 /* Failed allocation, critical failure */
1249 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1250 goto setup_tx_desc_die
;
1253 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
1255 pci_free_consistent(pdev
, txdr
->size
, txdr
->desc
,
1257 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1259 "Unable to allocate aligned memory "
1260 "for the transmit descriptor ring\n");
1261 vfree(txdr
->buffer_info
);
1264 /* Free old allocation, new allocation was successful */
1265 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
1268 memset(txdr
->desc
, 0, txdr
->size
);
1270 txdr
->next_to_use
= 0;
1271 txdr
->next_to_clean
= 0;
1272 spin_lock_init(&txdr
->tx_lock
);
1278 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1279 * (Descriptors) for all queues
1280 * @adapter: board private structure
1282 * If this function returns with an error, then it's possible one or
1283 * more of the rings is populated (while the rest are not). It is the
1284 * callers duty to clean those orphaned rings.
1286 * Return 0 on success, negative on failure
1290 e1000_setup_all_tx_resources(struct e1000_adapter
*adapter
)
1294 for (i
= 0; i
< adapter
->num_queues
; i
++) {
1295 err
= e1000_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1298 "Allocation for Tx Queue %u failed\n", i
);
1307 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1308 * @adapter: board private structure
1310 * Configure the Tx unit of the MAC after a reset.
1314 e1000_configure_tx(struct e1000_adapter
*adapter
)
1317 struct e1000_hw
*hw
= &adapter
->hw
;
1318 uint32_t tdlen
, tctl
, tipg
, tarc
;
1320 /* Setup the HW Tx Head and Tail descriptor pointers */
1322 switch (adapter
->num_queues
) {
1324 tdba
= adapter
->tx_ring
[1].dma
;
1325 tdlen
= adapter
->tx_ring
[1].count
*
1326 sizeof(struct e1000_tx_desc
);
1327 E1000_WRITE_REG(hw
, TDBAL1
, (tdba
& 0x00000000ffffffffULL
));
1328 E1000_WRITE_REG(hw
, TDBAH1
, (tdba
>> 32));
1329 E1000_WRITE_REG(hw
, TDLEN1
, tdlen
);
1330 E1000_WRITE_REG(hw
, TDH1
, 0);
1331 E1000_WRITE_REG(hw
, TDT1
, 0);
1332 adapter
->tx_ring
[1].tdh
= E1000_TDH1
;
1333 adapter
->tx_ring
[1].tdt
= E1000_TDT1
;
1337 tdba
= adapter
->tx_ring
[0].dma
;
1338 tdlen
= adapter
->tx_ring
[0].count
*
1339 sizeof(struct e1000_tx_desc
);
1340 E1000_WRITE_REG(hw
, TDBAL
, (tdba
& 0x00000000ffffffffULL
));
1341 E1000_WRITE_REG(hw
, TDBAH
, (tdba
>> 32));
1342 E1000_WRITE_REG(hw
, TDLEN
, tdlen
);
1343 E1000_WRITE_REG(hw
, TDH
, 0);
1344 E1000_WRITE_REG(hw
, TDT
, 0);
1345 adapter
->tx_ring
[0].tdh
= E1000_TDH
;
1346 adapter
->tx_ring
[0].tdt
= E1000_TDT
;
1350 /* Set the default values for the Tx Inter Packet Gap timer */
1352 switch (hw
->mac_type
) {
1353 case e1000_82542_rev2_0
:
1354 case e1000_82542_rev2_1
:
1355 tipg
= DEFAULT_82542_TIPG_IPGT
;
1356 tipg
|= DEFAULT_82542_TIPG_IPGR1
<< E1000_TIPG_IPGR1_SHIFT
;
1357 tipg
|= DEFAULT_82542_TIPG_IPGR2
<< E1000_TIPG_IPGR2_SHIFT
;
1360 if (hw
->media_type
== e1000_media_type_fiber
||
1361 hw
->media_type
== e1000_media_type_internal_serdes
)
1362 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
1364 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
1365 tipg
|= DEFAULT_82543_TIPG_IPGR1
<< E1000_TIPG_IPGR1_SHIFT
;
1366 tipg
|= DEFAULT_82543_TIPG_IPGR2
<< E1000_TIPG_IPGR2_SHIFT
;
1368 E1000_WRITE_REG(hw
, TIPG
, tipg
);
1370 /* Set the Tx Interrupt Delay register */
1372 E1000_WRITE_REG(hw
, TIDV
, adapter
->tx_int_delay
);
1373 if (hw
->mac_type
>= e1000_82540
)
1374 E1000_WRITE_REG(hw
, TADV
, adapter
->tx_abs_int_delay
);
1376 /* Program the Transmit Control Register */
1378 tctl
= E1000_READ_REG(hw
, TCTL
);
1380 tctl
&= ~E1000_TCTL_CT
;
1381 tctl
|= E1000_TCTL_EN
| E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1382 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1384 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1386 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
1387 tarc
= E1000_READ_REG(hw
, TARC0
);
1388 tarc
|= ((1 << 25) | (1 << 21));
1389 E1000_WRITE_REG(hw
, TARC0
, tarc
);
1390 tarc
= E1000_READ_REG(hw
, TARC1
);
1392 if (tctl
& E1000_TCTL_MULR
)
1396 E1000_WRITE_REG(hw
, TARC1
, tarc
);
1399 e1000_config_collision_dist(hw
);
1401 /* Setup Transmit Descriptor Settings for eop descriptor */
1402 adapter
->txd_cmd
= E1000_TXD_CMD_IDE
| E1000_TXD_CMD_EOP
|
1405 if (hw
->mac_type
< e1000_82543
)
1406 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1408 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1410 /* Cache if we're 82544 running in PCI-X because we'll
1411 * need this to apply a workaround later in the send path. */
1412 if (hw
->mac_type
== e1000_82544
&&
1413 hw
->bus_type
== e1000_bus_type_pcix
)
1414 adapter
->pcix_82544
= 1;
1418 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1419 * @adapter: board private structure
1420 * @rxdr: rx descriptor ring (for a specific queue) to setup
1422 * Returns 0 on success, negative on failure
1426 e1000_setup_rx_resources(struct e1000_adapter
*adapter
,
1427 struct e1000_rx_ring
*rxdr
)
1429 struct pci_dev
*pdev
= adapter
->pdev
;
1432 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1433 rxdr
->buffer_info
= vmalloc_node(size
, pcibus_to_node(pdev
->bus
));
1434 if (!rxdr
->buffer_info
) {
1436 "Unable to allocate memory for the receive descriptor ring\n");
1439 memset(rxdr
->buffer_info
, 0, size
);
1441 size
= sizeof(struct e1000_ps_page
) * rxdr
->count
;
1442 rxdr
->ps_page
= kmalloc(size
, GFP_KERNEL
);
1443 if(!rxdr
->ps_page
) {
1444 vfree(rxdr
->buffer_info
);
1446 "Unable to allocate memory for the receive descriptor ring\n");
1449 memset(rxdr
->ps_page
, 0, size
);
1451 size
= sizeof(struct e1000_ps_page_dma
) * rxdr
->count
;
1452 rxdr
->ps_page_dma
= kmalloc(size
, GFP_KERNEL
);
1453 if(!rxdr
->ps_page_dma
) {
1454 vfree(rxdr
->buffer_info
);
1455 kfree(rxdr
->ps_page
);
1457 "Unable to allocate memory for the receive descriptor ring\n");
1460 memset(rxdr
->ps_page_dma
, 0, size
);
1462 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
)
1463 desc_len
= sizeof(struct e1000_rx_desc
);
1465 desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1467 /* Round up to nearest 4K */
1469 rxdr
->size
= rxdr
->count
* desc_len
;
1470 E1000_ROUNDUP(rxdr
->size
, 4096);
1472 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1476 "Unable to allocate memory for the receive descriptor ring\n");
1478 vfree(rxdr
->buffer_info
);
1479 kfree(rxdr
->ps_page
);
1480 kfree(rxdr
->ps_page_dma
);
1484 /* Fix for errata 23, can't cross 64kB boundary */
1485 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1486 void *olddesc
= rxdr
->desc
;
1487 dma_addr_t olddma
= rxdr
->dma
;
1488 DPRINTK(RX_ERR
, ERR
, "rxdr align check failed: %u bytes "
1489 "at %p\n", rxdr
->size
, rxdr
->desc
);
1490 /* Try again, without freeing the previous */
1491 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1492 /* Failed allocation, critical failure */
1494 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1496 "Unable to allocate memory "
1497 "for the receive descriptor ring\n");
1498 goto setup_rx_desc_die
;
1501 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1503 pci_free_consistent(pdev
, rxdr
->size
, rxdr
->desc
,
1505 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1507 "Unable to allocate aligned memory "
1508 "for the receive descriptor ring\n");
1509 goto setup_rx_desc_die
;
1511 /* Free old allocation, new allocation was successful */
1512 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1515 memset(rxdr
->desc
, 0, rxdr
->size
);
1517 rxdr
->next_to_clean
= 0;
1518 rxdr
->next_to_use
= 0;
1524 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1525 * (Descriptors) for all queues
1526 * @adapter: board private structure
1528 * If this function returns with an error, then it's possible one or
1529 * more of the rings is populated (while the rest are not). It is the
1530 * callers duty to clean those orphaned rings.
1532 * Return 0 on success, negative on failure
1536 e1000_setup_all_rx_resources(struct e1000_adapter
*adapter
)
1540 for (i
= 0; i
< adapter
->num_queues
; i
++) {
1541 err
= e1000_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1544 "Allocation for Rx Queue %u failed\n", i
);
1553 * e1000_setup_rctl - configure the receive control registers
1554 * @adapter: Board private structure
1556 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1557 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1559 e1000_setup_rctl(struct e1000_adapter
*adapter
)
1561 uint32_t rctl
, rfctl
;
1562 uint32_t psrctl
= 0;
1563 #ifdef CONFIG_E1000_PACKET_SPLIT
1567 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1569 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1571 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1572 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1573 (adapter
->hw
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1575 if(adapter
->hw
.tbi_compatibility_on
== 1)
1576 rctl
|= E1000_RCTL_SBP
;
1578 rctl
&= ~E1000_RCTL_SBP
;
1580 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1581 rctl
&= ~E1000_RCTL_LPE
;
1583 rctl
|= E1000_RCTL_LPE
;
1585 /* Setup buffer sizes */
1586 if(adapter
->hw
.mac_type
>= e1000_82571
) {
1587 /* We can now specify buffers in 1K increments.
1588 * BSIZE and BSEX are ignored in this case. */
1589 rctl
|= adapter
->rx_buffer_len
<< 0x11;
1591 rctl
&= ~E1000_RCTL_SZ_4096
;
1592 rctl
|= E1000_RCTL_BSEX
;
1593 switch (adapter
->rx_buffer_len
) {
1594 case E1000_RXBUFFER_2048
:
1596 rctl
|= E1000_RCTL_SZ_2048
;
1597 rctl
&= ~E1000_RCTL_BSEX
;
1599 case E1000_RXBUFFER_4096
:
1600 rctl
|= E1000_RCTL_SZ_4096
;
1602 case E1000_RXBUFFER_8192
:
1603 rctl
|= E1000_RCTL_SZ_8192
;
1605 case E1000_RXBUFFER_16384
:
1606 rctl
|= E1000_RCTL_SZ_16384
;
1611 #ifdef CONFIG_E1000_PACKET_SPLIT
1612 /* 82571 and greater support packet-split where the protocol
1613 * header is placed in skb->data and the packet data is
1614 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1615 * In the case of a non-split, skb->data is linearly filled,
1616 * followed by the page buffers. Therefore, skb->data is
1617 * sized to hold the largest protocol header.
1619 pages
= PAGE_USE_COUNT(adapter
->netdev
->mtu
);
1620 if ((adapter
->hw
.mac_type
> e1000_82547_rev_2
) && (pages
<= 3) &&
1622 adapter
->rx_ps_pages
= pages
;
1624 adapter
->rx_ps_pages
= 0;
1626 if (adapter
->rx_ps_pages
) {
1627 /* Configure extra packet-split registers */
1628 rfctl
= E1000_READ_REG(&adapter
->hw
, RFCTL
);
1629 rfctl
|= E1000_RFCTL_EXTEN
;
1630 /* disable IPv6 packet split support */
1631 rfctl
|= E1000_RFCTL_IPV6_DIS
;
1632 E1000_WRITE_REG(&adapter
->hw
, RFCTL
, rfctl
);
1634 rctl
|= E1000_RCTL_DTYP_PS
| E1000_RCTL_SECRC
;
1636 psrctl
|= adapter
->rx_ps_bsize0
>>
1637 E1000_PSRCTL_BSIZE0_SHIFT
;
1639 switch (adapter
->rx_ps_pages
) {
1641 psrctl
|= PAGE_SIZE
<<
1642 E1000_PSRCTL_BSIZE3_SHIFT
;
1644 psrctl
|= PAGE_SIZE
<<
1645 E1000_PSRCTL_BSIZE2_SHIFT
;
1647 psrctl
|= PAGE_SIZE
>>
1648 E1000_PSRCTL_BSIZE1_SHIFT
;
1652 E1000_WRITE_REG(&adapter
->hw
, PSRCTL
, psrctl
);
1655 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1659 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1660 * @adapter: board private structure
1662 * Configure the Rx unit of the MAC after a reset.
1666 e1000_configure_rx(struct e1000_adapter
*adapter
)
1669 struct e1000_hw
*hw
= &adapter
->hw
;
1670 uint32_t rdlen
, rctl
, rxcsum
, ctrl_ext
;
1671 #ifdef CONFIG_E1000_MQ
1672 uint32_t reta
, mrqc
;
1676 if (adapter
->rx_ps_pages
) {
1677 rdlen
= adapter
->rx_ring
[0].count
*
1678 sizeof(union e1000_rx_desc_packet_split
);
1679 adapter
->clean_rx
= e1000_clean_rx_irq_ps
;
1680 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers_ps
;
1682 rdlen
= adapter
->rx_ring
[0].count
*
1683 sizeof(struct e1000_rx_desc
);
1684 adapter
->clean_rx
= e1000_clean_rx_irq
;
1685 adapter
->alloc_rx_buf
= e1000_alloc_rx_buffers
;
1688 /* disable receives while setting up the descriptors */
1689 rctl
= E1000_READ_REG(hw
, RCTL
);
1690 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
1692 /* set the Receive Delay Timer Register */
1693 E1000_WRITE_REG(hw
, RDTR
, adapter
->rx_int_delay
);
1695 if (hw
->mac_type
>= e1000_82540
) {
1696 E1000_WRITE_REG(hw
, RADV
, adapter
->rx_abs_int_delay
);
1697 if(adapter
->itr
> 1)
1698 E1000_WRITE_REG(hw
, ITR
,
1699 1000000000 / (adapter
->itr
* 256));
1702 if (hw
->mac_type
>= e1000_82571
) {
1703 /* Reset delay timers after every interrupt */
1704 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1705 ctrl_ext
|= E1000_CTRL_EXT_CANC
;
1706 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
1707 E1000_WRITE_FLUSH(hw
);
1710 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1711 * the Base and Length of the Rx Descriptor Ring */
1712 switch (adapter
->num_queues
) {
1713 #ifdef CONFIG_E1000_MQ
1715 rdba
= adapter
->rx_ring
[1].dma
;
1716 E1000_WRITE_REG(hw
, RDBAL1
, (rdba
& 0x00000000ffffffffULL
));
1717 E1000_WRITE_REG(hw
, RDBAH1
, (rdba
>> 32));
1718 E1000_WRITE_REG(hw
, RDLEN1
, rdlen
);
1719 E1000_WRITE_REG(hw
, RDH1
, 0);
1720 E1000_WRITE_REG(hw
, RDT1
, 0);
1721 adapter
->rx_ring
[1].rdh
= E1000_RDH1
;
1722 adapter
->rx_ring
[1].rdt
= E1000_RDT1
;
1727 rdba
= adapter
->rx_ring
[0].dma
;
1728 E1000_WRITE_REG(hw
, RDBAL
, (rdba
& 0x00000000ffffffffULL
));
1729 E1000_WRITE_REG(hw
, RDBAH
, (rdba
>> 32));
1730 E1000_WRITE_REG(hw
, RDLEN
, rdlen
);
1731 E1000_WRITE_REG(hw
, RDH
, 0);
1732 E1000_WRITE_REG(hw
, RDT
, 0);
1733 adapter
->rx_ring
[0].rdh
= E1000_RDH
;
1734 adapter
->rx_ring
[0].rdt
= E1000_RDT
;
1738 #ifdef CONFIG_E1000_MQ
1739 if (adapter
->num_queues
> 1) {
1740 uint32_t random
[10];
1742 get_random_bytes(&random
[0], 40);
1744 if (hw
->mac_type
<= e1000_82572
) {
1745 E1000_WRITE_REG(hw
, RSSIR
, 0);
1746 E1000_WRITE_REG(hw
, RSSIM
, 0);
1749 switch (adapter
->num_queues
) {
1753 mrqc
= E1000_MRQC_ENABLE_RSS_2Q
;
1757 /* Fill out redirection table */
1758 for (i
= 0; i
< 32; i
++)
1759 E1000_WRITE_REG_ARRAY(hw
, RETA
, i
, reta
);
1760 /* Fill out hash function seeds */
1761 for (i
= 0; i
< 10; i
++)
1762 E1000_WRITE_REG_ARRAY(hw
, RSSRK
, i
, random
[i
]);
1764 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4
|
1765 E1000_MRQC_RSS_FIELD_IPV4_TCP
);
1766 E1000_WRITE_REG(hw
, MRQC
, mrqc
);
1769 /* Multiqueue and packet checksumming are mutually exclusive. */
1770 if (hw
->mac_type
>= e1000_82571
) {
1771 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1772 rxcsum
|= E1000_RXCSUM_PCSD
;
1773 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1778 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1779 if (hw
->mac_type
>= e1000_82543
) {
1780 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
1781 if(adapter
->rx_csum
== TRUE
) {
1782 rxcsum
|= E1000_RXCSUM_TUOFL
;
1784 /* Enable 82571 IPv4 payload checksum for UDP fragments
1785 * Must be used in conjunction with packet-split. */
1786 if ((hw
->mac_type
>= e1000_82571
) &&
1787 (adapter
->rx_ps_pages
)) {
1788 rxcsum
|= E1000_RXCSUM_IPPCSE
;
1791 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1792 /* don't need to clear IPPCSE as it defaults to 0 */
1794 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
1796 #endif /* CONFIG_E1000_MQ */
1798 if (hw
->mac_type
== e1000_82573
)
1799 E1000_WRITE_REG(hw
, ERT
, 0x0100);
1801 /* Enable Receives */
1802 E1000_WRITE_REG(hw
, RCTL
, rctl
);
1806 * e1000_free_tx_resources - Free Tx Resources per Queue
1807 * @adapter: board private structure
1808 * @tx_ring: Tx descriptor ring for a specific queue
1810 * Free all transmit software resources
1814 e1000_free_tx_resources(struct e1000_adapter
*adapter
,
1815 struct e1000_tx_ring
*tx_ring
)
1817 struct pci_dev
*pdev
= adapter
->pdev
;
1819 e1000_clean_tx_ring(adapter
, tx_ring
);
1821 vfree(tx_ring
->buffer_info
);
1822 tx_ring
->buffer_info
= NULL
;
1824 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
1826 tx_ring
->desc
= NULL
;
1830 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1831 * @adapter: board private structure
1833 * Free all transmit software resources
1837 e1000_free_all_tx_resources(struct e1000_adapter
*adapter
)
1841 for (i
= 0; i
< adapter
->num_queues
; i
++)
1842 e1000_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1846 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
1847 struct e1000_buffer
*buffer_info
)
1849 if(buffer_info
->dma
) {
1850 pci_unmap_page(adapter
->pdev
,
1852 buffer_info
->length
,
1854 buffer_info
->dma
= 0;
1856 if(buffer_info
->skb
) {
1857 dev_kfree_skb_any(buffer_info
->skb
);
1858 buffer_info
->skb
= NULL
;
1863 * e1000_clean_tx_ring - Free Tx Buffers
1864 * @adapter: board private structure
1865 * @tx_ring: ring to be cleaned
1869 e1000_clean_tx_ring(struct e1000_adapter
*adapter
,
1870 struct e1000_tx_ring
*tx_ring
)
1872 struct e1000_buffer
*buffer_info
;
1876 /* Free all the Tx ring sk_buffs */
1878 for(i
= 0; i
< tx_ring
->count
; i
++) {
1879 buffer_info
= &tx_ring
->buffer_info
[i
];
1880 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
1883 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1884 memset(tx_ring
->buffer_info
, 0, size
);
1886 /* Zero out the descriptor ring */
1888 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1890 tx_ring
->next_to_use
= 0;
1891 tx_ring
->next_to_clean
= 0;
1892 tx_ring
->last_tx_tso
= 0;
1894 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdh
);
1895 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
1899 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1900 * @adapter: board private structure
1904 e1000_clean_all_tx_rings(struct e1000_adapter
*adapter
)
1908 for (i
= 0; i
< adapter
->num_queues
; i
++)
1909 e1000_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1913 * e1000_free_rx_resources - Free Rx Resources
1914 * @adapter: board private structure
1915 * @rx_ring: ring to clean the resources from
1917 * Free all receive software resources
1921 e1000_free_rx_resources(struct e1000_adapter
*adapter
,
1922 struct e1000_rx_ring
*rx_ring
)
1924 struct pci_dev
*pdev
= adapter
->pdev
;
1926 e1000_clean_rx_ring(adapter
, rx_ring
);
1928 vfree(rx_ring
->buffer_info
);
1929 rx_ring
->buffer_info
= NULL
;
1930 kfree(rx_ring
->ps_page
);
1931 rx_ring
->ps_page
= NULL
;
1932 kfree(rx_ring
->ps_page_dma
);
1933 rx_ring
->ps_page_dma
= NULL
;
1935 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
1937 rx_ring
->desc
= NULL
;
1941 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1942 * @adapter: board private structure
1944 * Free all receive software resources
1948 e1000_free_all_rx_resources(struct e1000_adapter
*adapter
)
1952 for (i
= 0; i
< adapter
->num_queues
; i
++)
1953 e1000_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1957 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1958 * @adapter: board private structure
1959 * @rx_ring: ring to free buffers from
1963 e1000_clean_rx_ring(struct e1000_adapter
*adapter
,
1964 struct e1000_rx_ring
*rx_ring
)
1966 struct e1000_buffer
*buffer_info
;
1967 struct e1000_ps_page
*ps_page
;
1968 struct e1000_ps_page_dma
*ps_page_dma
;
1969 struct pci_dev
*pdev
= adapter
->pdev
;
1973 /* Free all the Rx ring sk_buffs */
1975 for(i
= 0; i
< rx_ring
->count
; i
++) {
1976 buffer_info
= &rx_ring
->buffer_info
[i
];
1977 if(buffer_info
->skb
) {
1978 ps_page
= &rx_ring
->ps_page
[i
];
1979 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
1980 pci_unmap_single(pdev
,
1982 buffer_info
->length
,
1983 PCI_DMA_FROMDEVICE
);
1985 dev_kfree_skb(buffer_info
->skb
);
1986 buffer_info
->skb
= NULL
;
1988 for(j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
1989 if(!ps_page
->ps_page
[j
]) break;
1990 pci_unmap_single(pdev
,
1991 ps_page_dma
->ps_page_dma
[j
],
1992 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
1993 ps_page_dma
->ps_page_dma
[j
] = 0;
1994 put_page(ps_page
->ps_page
[j
]);
1995 ps_page
->ps_page
[j
] = NULL
;
2000 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
2001 memset(rx_ring
->buffer_info
, 0, size
);
2002 size
= sizeof(struct e1000_ps_page
) * rx_ring
->count
;
2003 memset(rx_ring
->ps_page
, 0, size
);
2004 size
= sizeof(struct e1000_ps_page_dma
) * rx_ring
->count
;
2005 memset(rx_ring
->ps_page_dma
, 0, size
);
2007 /* Zero out the descriptor ring */
2009 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2011 rx_ring
->next_to_clean
= 0;
2012 rx_ring
->next_to_use
= 0;
2014 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdh
);
2015 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
2019 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2020 * @adapter: board private structure
2024 e1000_clean_all_rx_rings(struct e1000_adapter
*adapter
)
2028 for (i
= 0; i
< adapter
->num_queues
; i
++)
2029 e1000_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2032 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2033 * and memory write and invalidate disabled for certain operations
2036 e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
2038 struct net_device
*netdev
= adapter
->netdev
;
2041 e1000_pci_clear_mwi(&adapter
->hw
);
2043 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2044 rctl
|= E1000_RCTL_RST
;
2045 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2046 E1000_WRITE_FLUSH(&adapter
->hw
);
2049 if(netif_running(netdev
))
2050 e1000_clean_all_rx_rings(adapter
);
2054 e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
2056 struct net_device
*netdev
= adapter
->netdev
;
2059 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2060 rctl
&= ~E1000_RCTL_RST
;
2061 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2062 E1000_WRITE_FLUSH(&adapter
->hw
);
2065 if(adapter
->hw
.pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
2066 e1000_pci_set_mwi(&adapter
->hw
);
2068 if(netif_running(netdev
)) {
2069 e1000_configure_rx(adapter
);
2070 e1000_alloc_rx_buffers(adapter
, &adapter
->rx_ring
[0]);
2075 * e1000_set_mac - Change the Ethernet Address of the NIC
2076 * @netdev: network interface device structure
2077 * @p: pointer to an address structure
2079 * Returns 0 on success, negative on failure
2083 e1000_set_mac(struct net_device
*netdev
, void *p
)
2085 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2086 struct sockaddr
*addr
= p
;
2088 if(!is_valid_ether_addr(addr
->sa_data
))
2089 return -EADDRNOTAVAIL
;
2091 /* 82542 2.0 needs to be in reset to write receive address registers */
2093 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2094 e1000_enter_82542_rst(adapter
);
2096 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2097 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
2099 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2101 /* With 82571 controllers, LAA may be overwritten (with the default)
2102 * due to controller reset from the other port. */
2103 if (adapter
->hw
.mac_type
== e1000_82571
) {
2104 /* activate the work around */
2105 adapter
->hw
.laa_is_present
= 1;
2107 /* Hold a copy of the LAA in RAR[14] This is done so that
2108 * between the time RAR[0] gets clobbered and the time it
2109 * gets fixed (in e1000_watchdog), the actual LAA is in one
2110 * of the RARs and no incoming packets directed to this port
2111 * are dropped. Eventaully the LAA will be in RAR[0] and
2113 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
,
2114 E1000_RAR_ENTRIES
- 1);
2117 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
2118 e1000_leave_82542_rst(adapter
);
2124 * e1000_set_multi - Multicast and Promiscuous mode set
2125 * @netdev: network interface device structure
2127 * The set_multi entry point is called whenever the multicast address
2128 * list or the network interface flags are updated. This routine is
2129 * responsible for configuring the hardware for proper multicast,
2130 * promiscuous mode, and all-multi behavior.
2134 e1000_set_multi(struct net_device
*netdev
)
2136 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2137 struct e1000_hw
*hw
= &adapter
->hw
;
2138 struct dev_mc_list
*mc_ptr
;
2140 uint32_t hash_value
;
2141 int i
, rar_entries
= E1000_RAR_ENTRIES
;
2143 /* reserve RAR[14] for LAA over-write work-around */
2144 if (adapter
->hw
.mac_type
== e1000_82571
)
2147 /* Check for Promiscuous and All Multicast modes */
2149 rctl
= E1000_READ_REG(hw
, RCTL
);
2151 if(netdev
->flags
& IFF_PROMISC
) {
2152 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2153 } else if(netdev
->flags
& IFF_ALLMULTI
) {
2154 rctl
|= E1000_RCTL_MPE
;
2155 rctl
&= ~E1000_RCTL_UPE
;
2157 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2160 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2162 /* 82542 2.0 needs to be in reset to write receive address registers */
2164 if(hw
->mac_type
== e1000_82542_rev2_0
)
2165 e1000_enter_82542_rst(adapter
);
2167 /* load the first 14 multicast address into the exact filters 1-14
2168 * RAR 0 is used for the station MAC adddress
2169 * if there are not 14 addresses, go ahead and clear the filters
2170 * -- with 82571 controllers only 0-13 entries are filled here
2172 mc_ptr
= netdev
->mc_list
;
2174 for(i
= 1; i
< rar_entries
; i
++) {
2176 e1000_rar_set(hw
, mc_ptr
->dmi_addr
, i
);
2177 mc_ptr
= mc_ptr
->next
;
2179 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
2180 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
2184 /* clear the old settings from the multicast hash table */
2186 for(i
= 0; i
< E1000_NUM_MTA_REGISTERS
; i
++)
2187 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
2189 /* load any remaining addresses into the hash table */
2191 for(; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
2192 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->dmi_addr
);
2193 e1000_mta_set(hw
, hash_value
);
2196 if(hw
->mac_type
== e1000_82542_rev2_0
)
2197 e1000_leave_82542_rst(adapter
);
2200 /* Need to wait a few seconds after link up to get diagnostic information from
2204 e1000_update_phy_info(unsigned long data
)
2206 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2207 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
2211 * e1000_82547_tx_fifo_stall - Timer Call-back
2212 * @data: pointer to adapter cast into an unsigned long
2216 e1000_82547_tx_fifo_stall(unsigned long data
)
2218 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2219 struct net_device
*netdev
= adapter
->netdev
;
2222 if(atomic_read(&adapter
->tx_fifo_stall
)) {
2223 if((E1000_READ_REG(&adapter
->hw
, TDT
) ==
2224 E1000_READ_REG(&adapter
->hw
, TDH
)) &&
2225 (E1000_READ_REG(&adapter
->hw
, TDFT
) ==
2226 E1000_READ_REG(&adapter
->hw
, TDFH
)) &&
2227 (E1000_READ_REG(&adapter
->hw
, TDFTS
) ==
2228 E1000_READ_REG(&adapter
->hw
, TDFHS
))) {
2229 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
2230 E1000_WRITE_REG(&adapter
->hw
, TCTL
,
2231 tctl
& ~E1000_TCTL_EN
);
2232 E1000_WRITE_REG(&adapter
->hw
, TDFT
,
2233 adapter
->tx_head_addr
);
2234 E1000_WRITE_REG(&adapter
->hw
, TDFH
,
2235 adapter
->tx_head_addr
);
2236 E1000_WRITE_REG(&adapter
->hw
, TDFTS
,
2237 adapter
->tx_head_addr
);
2238 E1000_WRITE_REG(&adapter
->hw
, TDFHS
,
2239 adapter
->tx_head_addr
);
2240 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
2241 E1000_WRITE_FLUSH(&adapter
->hw
);
2243 adapter
->tx_fifo_head
= 0;
2244 atomic_set(&adapter
->tx_fifo_stall
, 0);
2245 netif_wake_queue(netdev
);
2247 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
2253 * e1000_watchdog - Timer Call-back
2254 * @data: pointer to adapter cast into an unsigned long
2257 e1000_watchdog(unsigned long data
)
2259 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
2261 /* Do the rest outside of interrupt context */
2262 schedule_work(&adapter
->watchdog_task
);
2266 e1000_watchdog_task(struct e1000_adapter
*adapter
)
2268 struct net_device
*netdev
= adapter
->netdev
;
2269 struct e1000_tx_ring
*txdr
= adapter
->tx_ring
;
2272 e1000_check_for_link(&adapter
->hw
);
2273 if (adapter
->hw
.mac_type
== e1000_82573
) {
2274 e1000_enable_tx_pkt_filtering(&adapter
->hw
);
2275 if(adapter
->mng_vlan_id
!= adapter
->hw
.mng_cookie
.vlan_id
)
2276 e1000_update_mng_vlan(adapter
);
2279 if((adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) &&
2280 !(E1000_READ_REG(&adapter
->hw
, TXCW
) & E1000_TXCW_ANE
))
2281 link
= !adapter
->hw
.serdes_link_down
;
2283 link
= E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_LU
;
2286 if(!netif_carrier_ok(netdev
)) {
2287 e1000_get_speed_and_duplex(&adapter
->hw
,
2288 &adapter
->link_speed
,
2289 &adapter
->link_duplex
);
2291 DPRINTK(LINK
, INFO
, "NIC Link is Up %d Mbps %s\n",
2292 adapter
->link_speed
,
2293 adapter
->link_duplex
== FULL_DUPLEX
?
2294 "Full Duplex" : "Half Duplex");
2296 netif_carrier_on(netdev
);
2297 netif_wake_queue(netdev
);
2298 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2299 adapter
->smartspeed
= 0;
2302 if(netif_carrier_ok(netdev
)) {
2303 adapter
->link_speed
= 0;
2304 adapter
->link_duplex
= 0;
2305 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
2306 netif_carrier_off(netdev
);
2307 netif_stop_queue(netdev
);
2308 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
2311 e1000_smartspeed(adapter
);
2314 e1000_update_stats(adapter
);
2316 adapter
->hw
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2317 adapter
->tpt_old
= adapter
->stats
.tpt
;
2318 adapter
->hw
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2319 adapter
->colc_old
= adapter
->stats
.colc
;
2321 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
2322 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
2323 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
2324 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
2326 e1000_update_adaptive(&adapter
->hw
);
2328 if (adapter
->num_queues
== 1 && !netif_carrier_ok(netdev
)) {
2329 if (E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
2330 /* We've lost link, so the controller stops DMA,
2331 * but we've got queued Tx work that's never going
2332 * to get done, so reset controller to flush Tx.
2333 * (Do the reset outside of interrupt context). */
2334 schedule_work(&adapter
->tx_timeout_task
);
2338 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2339 if(adapter
->hw
.mac_type
>= e1000_82540
&& adapter
->itr
== 1) {
2340 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2341 * asymmetrical Tx or Rx gets ITR=8000; everyone
2342 * else is between 2000-8000. */
2343 uint32_t goc
= (adapter
->gotcl
+ adapter
->gorcl
) / 10000;
2344 uint32_t dif
= (adapter
->gotcl
> adapter
->gorcl
?
2345 adapter
->gotcl
- adapter
->gorcl
:
2346 adapter
->gorcl
- adapter
->gotcl
) / 10000;
2347 uint32_t itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
2348 E1000_WRITE_REG(&adapter
->hw
, ITR
, 1000000000 / (itr
* 256));
2351 /* Cause software interrupt to ensure rx ring is cleaned */
2352 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_RXDMT0
);
2354 /* Force detection of hung controller every watchdog period */
2355 adapter
->detect_tx_hung
= TRUE
;
2357 /* With 82571 controllers, LAA may be overwritten due to controller
2358 * reset from the other port. Set the appropriate LAA in RAR[0] */
2359 if (adapter
->hw
.mac_type
== e1000_82571
&& adapter
->hw
.laa_is_present
)
2360 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
2362 /* Reset the timer */
2363 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2 * HZ
);
2366 #define E1000_TX_FLAGS_CSUM 0x00000001
2367 #define E1000_TX_FLAGS_VLAN 0x00000002
2368 #define E1000_TX_FLAGS_TSO 0x00000004
2369 #define E1000_TX_FLAGS_IPV4 0x00000008
2370 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2371 #define E1000_TX_FLAGS_VLAN_SHIFT 16
2374 e1000_tso(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2375 struct sk_buff
*skb
)
2378 struct e1000_context_desc
*context_desc
;
2379 struct e1000_buffer
*buffer_info
;
2381 uint32_t cmd_length
= 0;
2382 uint16_t ipcse
= 0, tucse
, mss
;
2383 uint8_t ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
2386 if(skb_shinfo(skb
)->tso_size
) {
2387 if (skb_header_cloned(skb
)) {
2388 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2393 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2394 mss
= skb_shinfo(skb
)->tso_size
;
2395 if(skb
->protocol
== ntohs(ETH_P_IP
)) {
2396 skb
->nh
.iph
->tot_len
= 0;
2397 skb
->nh
.iph
->check
= 0;
2399 ~csum_tcpudp_magic(skb
->nh
.iph
->saddr
,
2404 cmd_length
= E1000_TXD_CMD_IP
;
2405 ipcse
= skb
->h
.raw
- skb
->data
- 1;
2406 #ifdef NETIF_F_TSO_IPV6
2407 } else if(skb
->protocol
== ntohs(ETH_P_IPV6
)) {
2408 skb
->nh
.ipv6h
->payload_len
= 0;
2410 ~csum_ipv6_magic(&skb
->nh
.ipv6h
->saddr
,
2411 &skb
->nh
.ipv6h
->daddr
,
2418 ipcss
= skb
->nh
.raw
- skb
->data
;
2419 ipcso
= (void *)&(skb
->nh
.iph
->check
) - (void *)skb
->data
;
2420 tucss
= skb
->h
.raw
- skb
->data
;
2421 tucso
= (void *)&(skb
->h
.th
->check
) - (void *)skb
->data
;
2424 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
2425 E1000_TXD_CMD_TCP
| (skb
->len
- (hdr_len
)));
2427 i
= tx_ring
->next_to_use
;
2428 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2429 buffer_info
= &tx_ring
->buffer_info
[i
];
2431 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
2432 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
2433 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
2434 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
2435 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
2436 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
2437 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
2438 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
2439 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
2441 buffer_info
->time_stamp
= jiffies
;
2443 if (++i
== tx_ring
->count
) i
= 0;
2444 tx_ring
->next_to_use
= i
;
2453 static inline boolean_t
2454 e1000_tx_csum(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2455 struct sk_buff
*skb
)
2457 struct e1000_context_desc
*context_desc
;
2458 struct e1000_buffer
*buffer_info
;
2462 if(likely(skb
->ip_summed
== CHECKSUM_HW
)) {
2463 css
= skb
->h
.raw
- skb
->data
;
2465 i
= tx_ring
->next_to_use
;
2466 buffer_info
= &tx_ring
->buffer_info
[i
];
2467 context_desc
= E1000_CONTEXT_DESC(*tx_ring
, i
);
2469 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
2470 context_desc
->upper_setup
.tcp_fields
.tucso
= css
+ skb
->csum
;
2471 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
2472 context_desc
->tcp_seg_setup
.data
= 0;
2473 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
2475 buffer_info
->time_stamp
= jiffies
;
2477 if (unlikely(++i
== tx_ring
->count
)) i
= 0;
2478 tx_ring
->next_to_use
= i
;
2486 #define E1000_MAX_TXD_PWR 12
2487 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2490 e1000_tx_map(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2491 struct sk_buff
*skb
, unsigned int first
, unsigned int max_per_txd
,
2492 unsigned int nr_frags
, unsigned int mss
)
2494 struct e1000_buffer
*buffer_info
;
2495 unsigned int len
= skb
->len
;
2496 unsigned int offset
= 0, size
, count
= 0, i
;
2498 len
-= skb
->data_len
;
2500 i
= tx_ring
->next_to_use
;
2503 buffer_info
= &tx_ring
->buffer_info
[i
];
2504 size
= min(len
, max_per_txd
);
2506 /* Workaround for Controller erratum --
2507 * descriptor for non-tso packet in a linear SKB that follows a
2508 * tso gets written back prematurely before the data is fully
2509 * DMAd to the controller */
2510 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2511 !skb_shinfo(skb
)->tso_size
) {
2512 tx_ring
->last_tx_tso
= 0;
2516 /* Workaround for premature desc write-backs
2517 * in TSO mode. Append 4-byte sentinel desc */
2518 if(unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
2521 /* work-around for errata 10 and it applies
2522 * to all controllers in PCI-X mode
2523 * The fix is to make sure that the first descriptor of a
2524 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2526 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2527 (size
> 2015) && count
== 0))
2530 /* Workaround for potential 82544 hang in PCI-X. Avoid
2531 * terminating buffers within evenly-aligned dwords. */
2532 if(unlikely(adapter
->pcix_82544
&&
2533 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
2537 buffer_info
->length
= size
;
2539 pci_map_single(adapter
->pdev
,
2543 buffer_info
->time_stamp
= jiffies
;
2548 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2551 for(f
= 0; f
< nr_frags
; f
++) {
2552 struct skb_frag_struct
*frag
;
2554 frag
= &skb_shinfo(skb
)->frags
[f
];
2556 offset
= frag
->page_offset
;
2559 buffer_info
= &tx_ring
->buffer_info
[i
];
2560 size
= min(len
, max_per_txd
);
2562 /* Workaround for premature desc write-backs
2563 * in TSO mode. Append 4-byte sentinel desc */
2564 if(unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
2567 /* Workaround for potential 82544 hang in PCI-X.
2568 * Avoid terminating buffers within evenly-aligned
2570 if(unlikely(adapter
->pcix_82544
&&
2571 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
2575 buffer_info
->length
= size
;
2577 pci_map_page(adapter
->pdev
,
2582 buffer_info
->time_stamp
= jiffies
;
2587 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2591 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
2592 tx_ring
->buffer_info
[i
].skb
= skb
;
2593 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
2599 e1000_tx_queue(struct e1000_adapter
*adapter
, struct e1000_tx_ring
*tx_ring
,
2600 int tx_flags
, int count
)
2602 struct e1000_tx_desc
*tx_desc
= NULL
;
2603 struct e1000_buffer
*buffer_info
;
2604 uint32_t txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
2607 if(likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
2608 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
2610 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2612 if(likely(tx_flags
& E1000_TX_FLAGS_IPV4
))
2613 txd_upper
|= E1000_TXD_POPTS_IXSM
<< 8;
2616 if(likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
2617 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
2618 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
2621 if(unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
2622 txd_lower
|= E1000_TXD_CMD_VLE
;
2623 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
2626 i
= tx_ring
->next_to_use
;
2629 buffer_info
= &tx_ring
->buffer_info
[i
];
2630 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
2631 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2632 tx_desc
->lower
.data
=
2633 cpu_to_le32(txd_lower
| buffer_info
->length
);
2634 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
2635 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2638 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
2640 /* Force memory writes to complete before letting h/w
2641 * know there are new descriptors to fetch. (Only
2642 * applicable for weak-ordered memory model archs,
2643 * such as IA-64). */
2646 tx_ring
->next_to_use
= i
;
2647 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tdt
);
2651 * 82547 workaround to avoid controller hang in half-duplex environment.
2652 * The workaround is to avoid queuing a large packet that would span
2653 * the internal Tx FIFO ring boundary by notifying the stack to resend
2654 * the packet at a later time. This gives the Tx FIFO an opportunity to
2655 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2656 * to the beginning of the Tx FIFO.
2659 #define E1000_FIFO_HDR 0x10
2660 #define E1000_82547_PAD_LEN 0x3E0
2663 e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2665 uint32_t fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
2666 uint32_t skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
2668 E1000_ROUNDUP(skb_fifo_len
, E1000_FIFO_HDR
);
2670 if(adapter
->link_duplex
!= HALF_DUPLEX
)
2671 goto no_fifo_stall_required
;
2673 if(atomic_read(&adapter
->tx_fifo_stall
))
2676 if(skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
2677 atomic_set(&adapter
->tx_fifo_stall
, 1);
2681 no_fifo_stall_required
:
2682 adapter
->tx_fifo_head
+= skb_fifo_len
;
2683 if(adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
2684 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
2688 #define MINIMUM_DHCP_PACKET_SIZE 282
2690 e1000_transfer_dhcp_info(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
2692 struct e1000_hw
*hw
= &adapter
->hw
;
2693 uint16_t length
, offset
;
2694 if(vlan_tx_tag_present(skb
)) {
2695 if(!((vlan_tx_tag_get(skb
) == adapter
->hw
.mng_cookie
.vlan_id
) &&
2696 ( adapter
->hw
.mng_cookie
.status
&
2697 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
)) )
2700 if ((skb
->len
> MINIMUM_DHCP_PACKET_SIZE
) && (!skb
->protocol
)) {
2701 struct ethhdr
*eth
= (struct ethhdr
*) skb
->data
;
2702 if((htons(ETH_P_IP
) == eth
->h_proto
)) {
2703 const struct iphdr
*ip
=
2704 (struct iphdr
*)((uint8_t *)skb
->data
+14);
2705 if(IPPROTO_UDP
== ip
->protocol
) {
2706 struct udphdr
*udp
=
2707 (struct udphdr
*)((uint8_t *)ip
+
2709 if(ntohs(udp
->dest
) == 67) {
2710 offset
= (uint8_t *)udp
+ 8 - skb
->data
;
2711 length
= skb
->len
- offset
;
2713 return e1000_mng_write_dhcp_info(hw
,
2723 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2725 e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2727 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2728 struct e1000_tx_ring
*tx_ring
;
2729 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
2730 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
2731 unsigned int tx_flags
= 0;
2732 unsigned int len
= skb
->len
;
2733 unsigned long flags
;
2734 unsigned int nr_frags
= 0;
2735 unsigned int mss
= 0;
2739 len
-= skb
->data_len
;
2741 #ifdef CONFIG_E1000_MQ
2742 tx_ring
= *per_cpu_ptr(adapter
->cpu_tx_ring
, smp_processor_id());
2744 tx_ring
= adapter
->tx_ring
;
2747 if (unlikely(skb
->len
<= 0)) {
2748 dev_kfree_skb_any(skb
);
2749 return NETDEV_TX_OK
;
2753 mss
= skb_shinfo(skb
)->tso_size
;
2754 /* The controller does a simple calculation to
2755 * make sure there is enough room in the FIFO before
2756 * initiating the DMA for each buffer. The calc is:
2757 * 4 = ceil(buffer len/mss). To make sure we don't
2758 * overrun the FIFO, adjust the max buffer len if mss
2762 max_per_txd
= min(mss
<< 2, max_per_txd
);
2763 max_txd_pwr
= fls(max_per_txd
) - 1;
2765 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2766 * points to just header, pull a few bytes of payload from
2767 * frags into skb->data */
2768 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
2769 if (skb
->data_len
&& (hdr_len
== (skb
->len
- skb
->data_len
)) &&
2770 (adapter
->hw
.mac_type
== e1000_82571
||
2771 adapter
->hw
.mac_type
== e1000_82572
)) {
2772 len
= skb
->len
- skb
->data_len
;
2776 if((mss
) || (skb
->ip_summed
== CHECKSUM_HW
))
2777 /* reserve a descriptor for the offload context */
2781 if(skb
->ip_summed
== CHECKSUM_HW
)
2786 /* Controller Erratum workaround */
2787 if (!skb
->data_len
&& tx_ring
->last_tx_tso
&&
2788 !skb_shinfo(skb
)->tso_size
)
2792 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
2794 if(adapter
->pcix_82544
)
2797 /* work-around for errata 10 and it applies to all controllers
2798 * in PCI-X mode, so add one more descriptor to the count
2800 if(unlikely((adapter
->hw
.bus_type
== e1000_bus_type_pcix
) &&
2804 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2805 for(f
= 0; f
< nr_frags
; f
++)
2806 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
2808 if(adapter
->pcix_82544
)
2811 unsigned int pull_size
;
2812 pull_size
= min((unsigned int)4, skb
->data_len
);
2813 if (!__pskb_pull_tail(skb
, pull_size
)) {
2814 printk(KERN_ERR
"__pskb_pull_tail failed.\n");
2815 dev_kfree_skb_any(skb
);
2819 if(adapter
->hw
.tx_pkt_filtering
&& (adapter
->hw
.mac_type
== e1000_82573
) )
2820 e1000_transfer_dhcp_info(adapter
, skb
);
2822 local_irq_save(flags
);
2823 if (!spin_trylock(&tx_ring
->tx_lock
)) {
2824 /* Collision - tell upper layer to requeue */
2825 local_irq_restore(flags
);
2826 return NETDEV_TX_LOCKED
;
2829 /* need: count + 2 desc gap to keep tail from touching
2830 * head, otherwise try next time */
2831 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < count
+ 2)) {
2832 netif_stop_queue(netdev
);
2833 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2834 return NETDEV_TX_BUSY
;
2837 if(unlikely(adapter
->hw
.mac_type
== e1000_82547
)) {
2838 if(unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
2839 netif_stop_queue(netdev
);
2840 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
);
2841 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2842 return NETDEV_TX_BUSY
;
2846 if(unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
2847 tx_flags
|= E1000_TX_FLAGS_VLAN
;
2848 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
2851 first
= tx_ring
->next_to_use
;
2853 tso
= e1000_tso(adapter
, tx_ring
, skb
);
2855 dev_kfree_skb_any(skb
);
2856 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2857 return NETDEV_TX_OK
;
2861 tx_ring
->last_tx_tso
= 1;
2862 tx_flags
|= E1000_TX_FLAGS_TSO
;
2863 } else if (likely(e1000_tx_csum(adapter
, tx_ring
, skb
)))
2864 tx_flags
|= E1000_TX_FLAGS_CSUM
;
2866 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2867 * 82571 hardware supports TSO capabilities for IPv6 as well...
2868 * no longer assume, we must. */
2869 if (likely(skb
->protocol
== ntohs(ETH_P_IP
)))
2870 tx_flags
|= E1000_TX_FLAGS_IPV4
;
2872 e1000_tx_queue(adapter
, tx_ring
, tx_flags
,
2873 e1000_tx_map(adapter
, tx_ring
, skb
, first
,
2874 max_per_txd
, nr_frags
, mss
));
2876 netdev
->trans_start
= jiffies
;
2878 /* Make sure there is space in the ring for the next send. */
2879 if (unlikely(E1000_DESC_UNUSED(tx_ring
) < MAX_SKB_FRAGS
+ 2))
2880 netif_stop_queue(netdev
);
2882 spin_unlock_irqrestore(&tx_ring
->tx_lock
, flags
);
2883 return NETDEV_TX_OK
;
2887 * e1000_tx_timeout - Respond to a Tx Hang
2888 * @netdev: network interface device structure
2892 e1000_tx_timeout(struct net_device
*netdev
)
2894 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2896 /* Do the reset outside of interrupt context */
2897 schedule_work(&adapter
->tx_timeout_task
);
2901 e1000_tx_timeout_task(struct net_device
*netdev
)
2903 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2905 adapter
->tx_timeout_count
++;
2906 e1000_down(adapter
);
2911 * e1000_get_stats - Get System Network Statistics
2912 * @netdev: network interface device structure
2914 * Returns the address of the device statistics structure.
2915 * The statistics are actually updated from the timer callback.
2918 static struct net_device_stats
*
2919 e1000_get_stats(struct net_device
*netdev
)
2921 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2923 /* only return the current stats */
2924 return &adapter
->net_stats
;
2928 * e1000_change_mtu - Change the Maximum Transfer Unit
2929 * @netdev: network interface device structure
2930 * @new_mtu: new value for maximum frame size
2932 * Returns 0 on success, negative on failure
2936 e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
2938 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2939 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
2941 if((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
2942 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
2943 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
2947 #define MAX_STD_JUMBO_FRAME_SIZE 9234
2948 /* might want this to be bigger enum check... */
2949 /* 82571 controllers limit jumbo frame size to 10500 bytes */
2950 if ((adapter
->hw
.mac_type
== e1000_82571
||
2951 adapter
->hw
.mac_type
== e1000_82572
) &&
2952 max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
2953 DPRINTK(PROBE
, ERR
, "MTU > 9216 bytes not supported "
2954 "on 82571 and 82572 controllers.\n");
2958 if(adapter
->hw
.mac_type
== e1000_82573
&&
2959 max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
) {
2960 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported "
2965 if(adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
2966 adapter
->rx_buffer_len
= max_frame
;
2967 E1000_ROUNDUP(adapter
->rx_buffer_len
, 1024);
2969 if(unlikely((adapter
->hw
.mac_type
< e1000_82543
) &&
2970 (max_frame
> MAXIMUM_ETHERNET_FRAME_SIZE
))) {
2971 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported "
2976 if(max_frame
<= E1000_RXBUFFER_2048
) {
2977 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
2978 } else if(max_frame
<= E1000_RXBUFFER_4096
) {
2979 adapter
->rx_buffer_len
= E1000_RXBUFFER_4096
;
2980 } else if(max_frame
<= E1000_RXBUFFER_8192
) {
2981 adapter
->rx_buffer_len
= E1000_RXBUFFER_8192
;
2982 } else if(max_frame
<= E1000_RXBUFFER_16384
) {
2983 adapter
->rx_buffer_len
= E1000_RXBUFFER_16384
;
2988 netdev
->mtu
= new_mtu
;
2990 if(netif_running(netdev
)) {
2991 e1000_down(adapter
);
2995 adapter
->hw
.max_frame_size
= max_frame
;
3001 * e1000_update_stats - Update the board statistics counters
3002 * @adapter: board private structure
3006 e1000_update_stats(struct e1000_adapter
*adapter
)
3008 struct e1000_hw
*hw
= &adapter
->hw
;
3009 unsigned long flags
;
3012 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3014 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3016 /* these counters are modified from e1000_adjust_tbi_stats,
3017 * called from the interrupt context, so they must only
3018 * be written while holding adapter->stats_lock
3021 adapter
->stats
.crcerrs
+= E1000_READ_REG(hw
, CRCERRS
);
3022 adapter
->stats
.gprc
+= E1000_READ_REG(hw
, GPRC
);
3023 adapter
->stats
.gorcl
+= E1000_READ_REG(hw
, GORCL
);
3024 adapter
->stats
.gorch
+= E1000_READ_REG(hw
, GORCH
);
3025 adapter
->stats
.bprc
+= E1000_READ_REG(hw
, BPRC
);
3026 adapter
->stats
.mprc
+= E1000_READ_REG(hw
, MPRC
);
3027 adapter
->stats
.roc
+= E1000_READ_REG(hw
, ROC
);
3028 adapter
->stats
.prc64
+= E1000_READ_REG(hw
, PRC64
);
3029 adapter
->stats
.prc127
+= E1000_READ_REG(hw
, PRC127
);
3030 adapter
->stats
.prc255
+= E1000_READ_REG(hw
, PRC255
);
3031 adapter
->stats
.prc511
+= E1000_READ_REG(hw
, PRC511
);
3032 adapter
->stats
.prc1023
+= E1000_READ_REG(hw
, PRC1023
);
3033 adapter
->stats
.prc1522
+= E1000_READ_REG(hw
, PRC1522
);
3035 adapter
->stats
.symerrs
+= E1000_READ_REG(hw
, SYMERRS
);
3036 adapter
->stats
.mpc
+= E1000_READ_REG(hw
, MPC
);
3037 adapter
->stats
.scc
+= E1000_READ_REG(hw
, SCC
);
3038 adapter
->stats
.ecol
+= E1000_READ_REG(hw
, ECOL
);
3039 adapter
->stats
.mcc
+= E1000_READ_REG(hw
, MCC
);
3040 adapter
->stats
.latecol
+= E1000_READ_REG(hw
, LATECOL
);
3041 adapter
->stats
.dc
+= E1000_READ_REG(hw
, DC
);
3042 adapter
->stats
.sec
+= E1000_READ_REG(hw
, SEC
);
3043 adapter
->stats
.rlec
+= E1000_READ_REG(hw
, RLEC
);
3044 adapter
->stats
.xonrxc
+= E1000_READ_REG(hw
, XONRXC
);
3045 adapter
->stats
.xontxc
+= E1000_READ_REG(hw
, XONTXC
);
3046 adapter
->stats
.xoffrxc
+= E1000_READ_REG(hw
, XOFFRXC
);
3047 adapter
->stats
.xofftxc
+= E1000_READ_REG(hw
, XOFFTXC
);
3048 adapter
->stats
.fcruc
+= E1000_READ_REG(hw
, FCRUC
);
3049 adapter
->stats
.gptc
+= E1000_READ_REG(hw
, GPTC
);
3050 adapter
->stats
.gotcl
+= E1000_READ_REG(hw
, GOTCL
);
3051 adapter
->stats
.gotch
+= E1000_READ_REG(hw
, GOTCH
);
3052 adapter
->stats
.rnbc
+= E1000_READ_REG(hw
, RNBC
);
3053 adapter
->stats
.ruc
+= E1000_READ_REG(hw
, RUC
);
3054 adapter
->stats
.rfc
+= E1000_READ_REG(hw
, RFC
);
3055 adapter
->stats
.rjc
+= E1000_READ_REG(hw
, RJC
);
3056 adapter
->stats
.torl
+= E1000_READ_REG(hw
, TORL
);
3057 adapter
->stats
.torh
+= E1000_READ_REG(hw
, TORH
);
3058 adapter
->stats
.totl
+= E1000_READ_REG(hw
, TOTL
);
3059 adapter
->stats
.toth
+= E1000_READ_REG(hw
, TOTH
);
3060 adapter
->stats
.tpr
+= E1000_READ_REG(hw
, TPR
);
3061 adapter
->stats
.ptc64
+= E1000_READ_REG(hw
, PTC64
);
3062 adapter
->stats
.ptc127
+= E1000_READ_REG(hw
, PTC127
);
3063 adapter
->stats
.ptc255
+= E1000_READ_REG(hw
, PTC255
);
3064 adapter
->stats
.ptc511
+= E1000_READ_REG(hw
, PTC511
);
3065 adapter
->stats
.ptc1023
+= E1000_READ_REG(hw
, PTC1023
);
3066 adapter
->stats
.ptc1522
+= E1000_READ_REG(hw
, PTC1522
);
3067 adapter
->stats
.mptc
+= E1000_READ_REG(hw
, MPTC
);
3068 adapter
->stats
.bptc
+= E1000_READ_REG(hw
, BPTC
);
3070 /* used for adaptive IFS */
3072 hw
->tx_packet_delta
= E1000_READ_REG(hw
, TPT
);
3073 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
3074 hw
->collision_delta
= E1000_READ_REG(hw
, COLC
);
3075 adapter
->stats
.colc
+= hw
->collision_delta
;
3077 if(hw
->mac_type
>= e1000_82543
) {
3078 adapter
->stats
.algnerrc
+= E1000_READ_REG(hw
, ALGNERRC
);
3079 adapter
->stats
.rxerrc
+= E1000_READ_REG(hw
, RXERRC
);
3080 adapter
->stats
.tncrs
+= E1000_READ_REG(hw
, TNCRS
);
3081 adapter
->stats
.cexterr
+= E1000_READ_REG(hw
, CEXTERR
);
3082 adapter
->stats
.tsctc
+= E1000_READ_REG(hw
, TSCTC
);
3083 adapter
->stats
.tsctfc
+= E1000_READ_REG(hw
, TSCTFC
);
3085 if(hw
->mac_type
> e1000_82547_rev_2
) {
3086 adapter
->stats
.iac
+= E1000_READ_REG(hw
, IAC
);
3087 adapter
->stats
.icrxoc
+= E1000_READ_REG(hw
, ICRXOC
);
3088 adapter
->stats
.icrxptc
+= E1000_READ_REG(hw
, ICRXPTC
);
3089 adapter
->stats
.icrxatc
+= E1000_READ_REG(hw
, ICRXATC
);
3090 adapter
->stats
.ictxptc
+= E1000_READ_REG(hw
, ICTXPTC
);
3091 adapter
->stats
.ictxatc
+= E1000_READ_REG(hw
, ICTXATC
);
3092 adapter
->stats
.ictxqec
+= E1000_READ_REG(hw
, ICTXQEC
);
3093 adapter
->stats
.ictxqmtc
+= E1000_READ_REG(hw
, ICTXQMTC
);
3094 adapter
->stats
.icrxdmtc
+= E1000_READ_REG(hw
, ICRXDMTC
);
3097 /* Fill out the OS statistics structure */
3099 adapter
->net_stats
.rx_packets
= adapter
->stats
.gprc
;
3100 adapter
->net_stats
.tx_packets
= adapter
->stats
.gptc
;
3101 adapter
->net_stats
.rx_bytes
= adapter
->stats
.gorcl
;
3102 adapter
->net_stats
.tx_bytes
= adapter
->stats
.gotcl
;
3103 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3104 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3108 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3109 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3110 adapter
->stats
.rlec
+ adapter
->stats
.cexterr
;
3111 adapter
->net_stats
.rx_dropped
= 0;
3112 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlec
;
3113 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3114 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3115 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3119 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3120 adapter
->stats
.latecol
;
3121 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3122 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3123 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3125 /* Tx Dropped needs to be maintained elsewhere */
3129 if(hw
->media_type
== e1000_media_type_copper
) {
3130 if((adapter
->link_speed
== SPEED_1000
) &&
3131 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3132 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3133 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3136 if((hw
->mac_type
<= e1000_82546
) &&
3137 (hw
->phy_type
== e1000_phy_m88
) &&
3138 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
3139 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
3142 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3145 #ifdef CONFIG_E1000_MQ
3147 e1000_rx_schedule(void *data
)
3149 struct net_device
*poll_dev
, *netdev
= data
;
3150 struct e1000_adapter
*adapter
= netdev
->priv
;
3151 int this_cpu
= get_cpu();
3153 poll_dev
= *per_cpu_ptr(adapter
->cpu_netdev
, this_cpu
);
3154 if (poll_dev
== NULL
) {
3159 if (likely(netif_rx_schedule_prep(poll_dev
)))
3160 __netif_rx_schedule(poll_dev
);
3162 e1000_irq_enable(adapter
);
3169 * e1000_intr - Interrupt Handler
3170 * @irq: interrupt number
3171 * @data: pointer to a network interface device structure
3172 * @pt_regs: CPU registers structure
3176 e1000_intr(int irq
, void *data
, struct pt_regs
*regs
)
3178 struct net_device
*netdev
= data
;
3179 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3180 struct e1000_hw
*hw
= &adapter
->hw
;
3181 uint32_t icr
= E1000_READ_REG(hw
, ICR
);
3182 #if defined(CONFIG_E1000_NAPI) && defined(CONFIG_E1000_MQ) || !defined(CONFIG_E1000_NAPI)
3187 return IRQ_NONE
; /* Not our interrupt */
3189 if(unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
3190 hw
->get_link_status
= 1;
3191 mod_timer(&adapter
->watchdog_timer
, jiffies
);
3194 #ifdef CONFIG_E1000_NAPI
3195 atomic_inc(&adapter
->irq_sem
);
3196 E1000_WRITE_REG(hw
, IMC
, ~0);
3197 E1000_WRITE_FLUSH(hw
);
3198 #ifdef CONFIG_E1000_MQ
3199 if (atomic_read(&adapter
->rx_sched_call_data
.count
) == 0) {
3200 cpu_set(adapter
->cpu_for_queue
[0],
3201 adapter
->rx_sched_call_data
.cpumask
);
3202 for (i
= 1; i
< adapter
->num_queues
; i
++) {
3203 cpu_set(adapter
->cpu_for_queue
[i
],
3204 adapter
->rx_sched_call_data
.cpumask
);
3205 atomic_inc(&adapter
->irq_sem
);
3207 atomic_set(&adapter
->rx_sched_call_data
.count
, i
);
3208 smp_call_async_mask(&adapter
->rx_sched_call_data
);
3210 printk("call_data.count == %u\n", atomic_read(&adapter
->rx_sched_call_data
.count
));
3212 #else /* if !CONFIG_E1000_MQ */
3213 if (likely(netif_rx_schedule_prep(&adapter
->polling_netdev
[0])))
3214 __netif_rx_schedule(&adapter
->polling_netdev
[0]);
3216 e1000_irq_enable(adapter
);
3217 #endif /* CONFIG_E1000_MQ */
3219 #else /* if !CONFIG_E1000_NAPI */
3220 /* Writing IMC and IMS is needed for 82547.
3221 Due to Hub Link bus being occupied, an interrupt
3222 de-assertion message is not able to be sent.
3223 When an interrupt assertion message is generated later,
3224 two messages are re-ordered and sent out.
3225 That causes APIC to think 82547 is in de-assertion
3226 state, while 82547 is in assertion state, resulting
3227 in dead lock. Writing IMC forces 82547 into
3230 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
){
3231 atomic_inc(&adapter
->irq_sem
);
3232 E1000_WRITE_REG(hw
, IMC
, ~0);
3235 for(i
= 0; i
< E1000_MAX_INTR
; i
++)
3236 if(unlikely(!adapter
->clean_rx(adapter
, adapter
->rx_ring
) &
3237 !e1000_clean_tx_irq(adapter
, adapter
->tx_ring
)))
3240 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
3241 e1000_irq_enable(adapter
);
3243 #endif /* CONFIG_E1000_NAPI */
3248 #ifdef CONFIG_E1000_NAPI
3250 * e1000_clean - NAPI Rx polling callback
3251 * @adapter: board private structure
3255 e1000_clean(struct net_device
*poll_dev
, int *budget
)
3257 struct e1000_adapter
*adapter
;
3258 int work_to_do
= min(*budget
, poll_dev
->quota
);
3259 int tx_cleaned
, i
= 0, work_done
= 0;
3261 /* Must NOT use netdev_priv macro here. */
3262 adapter
= poll_dev
->priv
;
3264 /* Keep link state information with original netdev */
3265 if (!netif_carrier_ok(adapter
->netdev
))
3268 while (poll_dev
!= &adapter
->polling_netdev
[i
]) {
3270 if (unlikely(i
== adapter
->num_queues
))
3274 tx_cleaned
= e1000_clean_tx_irq(adapter
, &adapter
->tx_ring
[i
]);
3275 adapter
->clean_rx(adapter
, &adapter
->rx_ring
[i
],
3276 &work_done
, work_to_do
);
3278 *budget
-= work_done
;
3279 poll_dev
->quota
-= work_done
;
3281 /* If no Tx and not enough Rx work done, exit the polling mode */
3282 if((!tx_cleaned
&& (work_done
== 0)) ||
3283 !netif_running(adapter
->netdev
)) {
3285 netif_rx_complete(poll_dev
);
3286 e1000_irq_enable(adapter
);
3295 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3296 * @adapter: board private structure
3300 e1000_clean_tx_irq(struct e1000_adapter
*adapter
,
3301 struct e1000_tx_ring
*tx_ring
)
3303 struct net_device
*netdev
= adapter
->netdev
;
3304 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
3305 struct e1000_buffer
*buffer_info
;
3306 unsigned int i
, eop
;
3307 boolean_t cleaned
= FALSE
;
3309 i
= tx_ring
->next_to_clean
;
3310 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3311 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3313 while (eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
3314 for(cleaned
= FALSE
; !cleaned
; ) {
3315 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3316 buffer_info
= &tx_ring
->buffer_info
[i
];
3317 cleaned
= (i
== eop
);
3319 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
3321 tx_desc
->buffer_addr
= 0;
3322 tx_desc
->lower
.data
= 0;
3323 tx_desc
->upper
.data
= 0;
3325 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
3328 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3329 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3332 tx_ring
->next_to_clean
= i
;
3334 spin_lock(&tx_ring
->tx_lock
);
3336 if(unlikely(cleaned
&& netif_queue_stopped(netdev
) &&
3337 netif_carrier_ok(netdev
)))
3338 netif_wake_queue(netdev
);
3340 spin_unlock(&tx_ring
->tx_lock
);
3342 if (adapter
->detect_tx_hung
) {
3343 /* Detect a transmit hang in hardware, this serializes the
3344 * check with the clearing of time_stamp and movement of i */
3345 adapter
->detect_tx_hung
= FALSE
;
3346 if (tx_ring
->buffer_info
[i
].dma
&&
3347 time_after(jiffies
, tx_ring
->buffer_info
[i
].time_stamp
+ HZ
)
3348 && !(E1000_READ_REG(&adapter
->hw
, STATUS
) &
3349 E1000_STATUS_TXOFF
)) {
3351 /* detected Tx unit hang */
3352 i
= tx_ring
->next_to_clean
;
3353 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
3354 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
3355 DPRINTK(DRV
, ERR
, "Detected Tx Unit Hang\n"
3358 " next_to_use <%x>\n"
3359 " next_to_clean <%x>\n"
3360 "buffer_info[next_to_clean]\n"
3362 " time_stamp <%lx>\n"
3363 " next_to_watch <%x>\n"
3365 " next_to_watch.status <%x>\n",
3366 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdh
),
3367 readl(adapter
->hw
.hw_addr
+ tx_ring
->tdt
),
3368 tx_ring
->next_to_use
,
3370 (unsigned long long)tx_ring
->buffer_info
[i
].dma
,
3371 tx_ring
->buffer_info
[i
].time_stamp
,
3374 eop_desc
->upper
.fields
.status
);
3375 netif_stop_queue(netdev
);
3382 * e1000_rx_checksum - Receive Checksum Offload for 82543
3383 * @adapter: board private structure
3384 * @status_err: receive descriptor status and error fields
3385 * @csum: receive descriptor csum field
3386 * @sk_buff: socket buffer with received data
3390 e1000_rx_checksum(struct e1000_adapter
*adapter
,
3391 uint32_t status_err
, uint32_t csum
,
3392 struct sk_buff
*skb
)
3394 uint16_t status
= (uint16_t)status_err
;
3395 uint8_t errors
= (uint8_t)(status_err
>> 24);
3396 skb
->ip_summed
= CHECKSUM_NONE
;
3398 /* 82543 or newer only */
3399 if(unlikely(adapter
->hw
.mac_type
< e1000_82543
)) return;
3400 /* Ignore Checksum bit is set */
3401 if(unlikely(status
& E1000_RXD_STAT_IXSM
)) return;
3402 /* TCP/UDP checksum error bit is set */
3403 if(unlikely(errors
& E1000_RXD_ERR_TCPE
)) {
3404 /* let the stack verify checksum errors */
3405 adapter
->hw_csum_err
++;
3408 /* TCP/UDP Checksum has not been calculated */
3409 if(adapter
->hw
.mac_type
<= e1000_82547_rev_2
) {
3410 if(!(status
& E1000_RXD_STAT_TCPCS
))
3413 if(!(status
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
)))
3416 /* It must be a TCP or UDP packet with a valid checksum */
3417 if (likely(status
& E1000_RXD_STAT_TCPCS
)) {
3418 /* TCP checksum is good */
3419 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3420 } else if (adapter
->hw
.mac_type
> e1000_82547_rev_2
) {
3421 /* IP fragment with UDP payload */
3422 /* Hardware complements the payload checksum, so we undo it
3423 * and then put the value in host order for further stack use.
3425 csum
= ntohl(csum
^ 0xFFFF);
3427 skb
->ip_summed
= CHECKSUM_HW
;
3429 adapter
->hw_csum_good
++;
3433 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3434 * @adapter: board private structure
3438 #ifdef CONFIG_E1000_NAPI
3439 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3440 struct e1000_rx_ring
*rx_ring
,
3441 int *work_done
, int work_to_do
)
3443 e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
3444 struct e1000_rx_ring
*rx_ring
)
3447 struct net_device
*netdev
= adapter
->netdev
;
3448 struct pci_dev
*pdev
= adapter
->pdev
;
3449 struct e1000_rx_desc
*rx_desc
;
3450 struct e1000_buffer
*buffer_info
;
3451 struct sk_buff
*skb
;
3452 unsigned long flags
;
3456 boolean_t cleaned
= FALSE
;
3458 i
= rx_ring
->next_to_clean
;
3459 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3461 while(rx_desc
->status
& E1000_RXD_STAT_DD
) {
3462 buffer_info
= &rx_ring
->buffer_info
[i
];
3463 #ifdef CONFIG_E1000_NAPI
3464 if(*work_done
>= work_to_do
)
3470 pci_unmap_single(pdev
,
3472 buffer_info
->length
,
3473 PCI_DMA_FROMDEVICE
);
3475 skb
= buffer_info
->skb
;
3476 length
= le16_to_cpu(rx_desc
->length
);
3478 if(unlikely(!(rx_desc
->status
& E1000_RXD_STAT_EOP
))) {
3479 /* All receives must fit into a single buffer */
3480 E1000_DBG("%s: Receive packet consumed multiple"
3481 " buffers\n", netdev
->name
);
3482 dev_kfree_skb_irq(skb
);
3486 if(unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
3487 last_byte
= *(skb
->data
+ length
- 1);
3488 if(TBI_ACCEPT(&adapter
->hw
, rx_desc
->status
,
3489 rx_desc
->errors
, length
, last_byte
)) {
3490 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3491 e1000_tbi_adjust_stats(&adapter
->hw
,
3494 spin_unlock_irqrestore(&adapter
->stats_lock
,
3498 dev_kfree_skb_irq(skb
);
3504 skb_put(skb
, length
- ETHERNET_FCS_SIZE
);
3506 /* Receive Checksum Offload */
3507 e1000_rx_checksum(adapter
,
3508 (uint32_t)(rx_desc
->status
) |
3509 ((uint32_t)(rx_desc
->errors
) << 24),
3510 rx_desc
->csum
, skb
);
3511 skb
->protocol
= eth_type_trans(skb
, netdev
);
3512 #ifdef CONFIG_E1000_NAPI
3513 if(unlikely(adapter
->vlgrp
&&
3514 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3515 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3516 le16_to_cpu(rx_desc
->special
) &
3517 E1000_RXD_SPC_VLAN_MASK
);
3519 netif_receive_skb(skb
);
3521 #else /* CONFIG_E1000_NAPI */
3522 if(unlikely(adapter
->vlgrp
&&
3523 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
3524 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3525 le16_to_cpu(rx_desc
->special
) &
3526 E1000_RXD_SPC_VLAN_MASK
);
3530 #endif /* CONFIG_E1000_NAPI */
3531 netdev
->last_rx
= jiffies
;
3534 rx_desc
->status
= 0;
3535 buffer_info
->skb
= NULL
;
3536 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3538 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3540 rx_ring
->next_to_clean
= i
;
3541 adapter
->alloc_rx_buf(adapter
, rx_ring
);
3547 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3548 * @adapter: board private structure
3552 #ifdef CONFIG_E1000_NAPI
3553 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3554 struct e1000_rx_ring
*rx_ring
,
3555 int *work_done
, int work_to_do
)
3557 e1000_clean_rx_irq_ps(struct e1000_adapter
*adapter
,
3558 struct e1000_rx_ring
*rx_ring
)
3561 union e1000_rx_desc_packet_split
*rx_desc
;
3562 struct net_device
*netdev
= adapter
->netdev
;
3563 struct pci_dev
*pdev
= adapter
->pdev
;
3564 struct e1000_buffer
*buffer_info
;
3565 struct e1000_ps_page
*ps_page
;
3566 struct e1000_ps_page_dma
*ps_page_dma
;
3567 struct sk_buff
*skb
;
3569 uint32_t length
, staterr
;
3570 boolean_t cleaned
= FALSE
;
3572 i
= rx_ring
->next_to_clean
;
3573 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3574 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3576 while(staterr
& E1000_RXD_STAT_DD
) {
3577 buffer_info
= &rx_ring
->buffer_info
[i
];
3578 ps_page
= &rx_ring
->ps_page
[i
];
3579 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3580 #ifdef CONFIG_E1000_NAPI
3581 if(unlikely(*work_done
>= work_to_do
))
3586 pci_unmap_single(pdev
, buffer_info
->dma
,
3587 buffer_info
->length
,
3588 PCI_DMA_FROMDEVICE
);
3590 skb
= buffer_info
->skb
;
3592 if(unlikely(!(staterr
& E1000_RXD_STAT_EOP
))) {
3593 E1000_DBG("%s: Packet Split buffers didn't pick up"
3594 " the full packet\n", netdev
->name
);
3595 dev_kfree_skb_irq(skb
);
3599 if(unlikely(staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
)) {
3600 dev_kfree_skb_irq(skb
);
3604 length
= le16_to_cpu(rx_desc
->wb
.middle
.length0
);
3606 if(unlikely(!length
)) {
3607 E1000_DBG("%s: Last part of the packet spanning"
3608 " multiple descriptors\n", netdev
->name
);
3609 dev_kfree_skb_irq(skb
);
3614 skb_put(skb
, length
);
3616 for(j
= 0; j
< adapter
->rx_ps_pages
; j
++) {
3617 if(!(length
= le16_to_cpu(rx_desc
->wb
.upper
.length
[j
])))
3620 pci_unmap_page(pdev
, ps_page_dma
->ps_page_dma
[j
],
3621 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
3622 ps_page_dma
->ps_page_dma
[j
] = 0;
3623 skb_shinfo(skb
)->frags
[j
].page
=
3624 ps_page
->ps_page
[j
];
3625 ps_page
->ps_page
[j
] = NULL
;
3626 skb_shinfo(skb
)->frags
[j
].page_offset
= 0;
3627 skb_shinfo(skb
)->frags
[j
].size
= length
;
3628 skb_shinfo(skb
)->nr_frags
++;
3630 skb
->data_len
+= length
;
3633 e1000_rx_checksum(adapter
, staterr
,
3634 rx_desc
->wb
.lower
.hi_dword
.csum_ip
.csum
, skb
);
3635 skb
->protocol
= eth_type_trans(skb
, netdev
);
3637 if(likely(rx_desc
->wb
.upper
.header_status
&
3638 E1000_RXDPS_HDRSTAT_HDRSP
)) {
3639 adapter
->rx_hdr_split
++;
3640 #ifdef HAVE_RX_ZERO_COPY
3641 skb_shinfo(skb
)->zero_copy
= TRUE
;
3644 #ifdef CONFIG_E1000_NAPI
3645 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3646 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3647 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3648 E1000_RXD_SPC_VLAN_MASK
);
3650 netif_receive_skb(skb
);
3652 #else /* CONFIG_E1000_NAPI */
3653 if(unlikely(adapter
->vlgrp
&& (staterr
& E1000_RXD_STAT_VP
))) {
3654 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
3655 le16_to_cpu(rx_desc
->wb
.middle
.vlan
) &
3656 E1000_RXD_SPC_VLAN_MASK
);
3660 #endif /* CONFIG_E1000_NAPI */
3661 netdev
->last_rx
= jiffies
;
3664 rx_desc
->wb
.middle
.status_error
&= ~0xFF;
3665 buffer_info
->skb
= NULL
;
3666 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3668 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3669 staterr
= le32_to_cpu(rx_desc
->wb
.middle
.status_error
);
3671 rx_ring
->next_to_clean
= i
;
3672 adapter
->alloc_rx_buf(adapter
, rx_ring
);
3678 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3679 * @adapter: address of board private structure
3683 e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
,
3684 struct e1000_rx_ring
*rx_ring
)
3686 struct net_device
*netdev
= adapter
->netdev
;
3687 struct pci_dev
*pdev
= adapter
->pdev
;
3688 struct e1000_rx_desc
*rx_desc
;
3689 struct e1000_buffer
*buffer_info
;
3690 struct sk_buff
*skb
;
3692 unsigned int bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
3694 i
= rx_ring
->next_to_use
;
3695 buffer_info
= &rx_ring
->buffer_info
[i
];
3697 while(!buffer_info
->skb
) {
3698 skb
= dev_alloc_skb(bufsz
);
3700 if(unlikely(!skb
)) {
3701 /* Better luck next round */
3705 /* Fix for errata 23, can't cross 64kB boundary */
3706 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3707 struct sk_buff
*oldskb
= skb
;
3708 DPRINTK(RX_ERR
, ERR
, "skb align check failed: %u bytes "
3709 "at %p\n", bufsz
, skb
->data
);
3710 /* Try again, without freeing the previous */
3711 skb
= dev_alloc_skb(bufsz
);
3712 /* Failed allocation, critical failure */
3714 dev_kfree_skb(oldskb
);
3718 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
3721 dev_kfree_skb(oldskb
);
3722 break; /* while !buffer_info->skb */
3724 /* Use new allocation */
3725 dev_kfree_skb(oldskb
);
3728 /* Make buffer alignment 2 beyond a 16 byte boundary
3729 * this will result in a 16 byte aligned IP header after
3730 * the 14 byte MAC header is removed
3732 skb_reserve(skb
, NET_IP_ALIGN
);
3736 buffer_info
->skb
= skb
;
3737 buffer_info
->length
= adapter
->rx_buffer_len
;
3738 buffer_info
->dma
= pci_map_single(pdev
,
3740 adapter
->rx_buffer_len
,
3741 PCI_DMA_FROMDEVICE
);
3743 /* Fix for errata 23, can't cross 64kB boundary */
3744 if (!e1000_check_64k_bound(adapter
,
3745 (void *)(unsigned long)buffer_info
->dma
,
3746 adapter
->rx_buffer_len
)) {
3747 DPRINTK(RX_ERR
, ERR
,
3748 "dma align check failed: %u bytes at %p\n",
3749 adapter
->rx_buffer_len
,
3750 (void *)(unsigned long)buffer_info
->dma
);
3752 buffer_info
->skb
= NULL
;
3754 pci_unmap_single(pdev
, buffer_info
->dma
,
3755 adapter
->rx_buffer_len
,
3756 PCI_DMA_FROMDEVICE
);
3758 break; /* while !buffer_info->skb */
3760 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
3761 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3763 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3764 /* Force memory writes to complete before letting h/w
3765 * know there are new descriptors to fetch. (Only
3766 * applicable for weak-ordered memory model archs,
3767 * such as IA-64). */
3769 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
3772 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3773 buffer_info
= &rx_ring
->buffer_info
[i
];
3776 rx_ring
->next_to_use
= i
;
3780 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3781 * @adapter: address of board private structure
3785 e1000_alloc_rx_buffers_ps(struct e1000_adapter
*adapter
,
3786 struct e1000_rx_ring
*rx_ring
)
3788 struct net_device
*netdev
= adapter
->netdev
;
3789 struct pci_dev
*pdev
= adapter
->pdev
;
3790 union e1000_rx_desc_packet_split
*rx_desc
;
3791 struct e1000_buffer
*buffer_info
;
3792 struct e1000_ps_page
*ps_page
;
3793 struct e1000_ps_page_dma
*ps_page_dma
;
3794 struct sk_buff
*skb
;
3797 i
= rx_ring
->next_to_use
;
3798 buffer_info
= &rx_ring
->buffer_info
[i
];
3799 ps_page
= &rx_ring
->ps_page
[i
];
3800 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3802 while(!buffer_info
->skb
) {
3803 rx_desc
= E1000_RX_DESC_PS(*rx_ring
, i
);
3805 for(j
= 0; j
< PS_PAGE_BUFFERS
; j
++) {
3806 if (j
< adapter
->rx_ps_pages
) {
3807 if (likely(!ps_page
->ps_page
[j
])) {
3808 ps_page
->ps_page
[j
] =
3809 alloc_page(GFP_ATOMIC
);
3810 if (unlikely(!ps_page
->ps_page
[j
]))
3812 ps_page_dma
->ps_page_dma
[j
] =
3814 ps_page
->ps_page
[j
],
3816 PCI_DMA_FROMDEVICE
);
3818 /* Refresh the desc even if buffer_addrs didn't
3819 * change because each write-back erases
3822 rx_desc
->read
.buffer_addr
[j
+1] =
3823 cpu_to_le64(ps_page_dma
->ps_page_dma
[j
]);
3825 rx_desc
->read
.buffer_addr
[j
+1] = ~0;
3828 skb
= dev_alloc_skb(adapter
->rx_ps_bsize0
+ NET_IP_ALIGN
);
3833 /* Make buffer alignment 2 beyond a 16 byte boundary
3834 * this will result in a 16 byte aligned IP header after
3835 * the 14 byte MAC header is removed
3837 skb_reserve(skb
, NET_IP_ALIGN
);
3841 buffer_info
->skb
= skb
;
3842 buffer_info
->length
= adapter
->rx_ps_bsize0
;
3843 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
3844 adapter
->rx_ps_bsize0
,
3845 PCI_DMA_FROMDEVICE
);
3847 rx_desc
->read
.buffer_addr
[0] = cpu_to_le64(buffer_info
->dma
);
3849 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
3850 /* Force memory writes to complete before letting h/w
3851 * know there are new descriptors to fetch. (Only
3852 * applicable for weak-ordered memory model archs,
3853 * such as IA-64). */
3855 /* Hardware increments by 16 bytes, but packet split
3856 * descriptors are 32 bytes...so we increment tail
3859 writel(i
<<1, adapter
->hw
.hw_addr
+ rx_ring
->rdt
);
3862 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
3863 buffer_info
= &rx_ring
->buffer_info
[i
];
3864 ps_page
= &rx_ring
->ps_page
[i
];
3865 ps_page_dma
= &rx_ring
->ps_page_dma
[i
];
3869 rx_ring
->next_to_use
= i
;
3873 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3878 e1000_smartspeed(struct e1000_adapter
*adapter
)
3880 uint16_t phy_status
;
3883 if((adapter
->hw
.phy_type
!= e1000_phy_igp
) || !adapter
->hw
.autoneg
||
3884 !(adapter
->hw
.autoneg_advertised
& ADVERTISE_1000_FULL
))
3887 if(adapter
->smartspeed
== 0) {
3888 /* If Master/Slave config fault is asserted twice,
3889 * we assume back-to-back */
3890 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
3891 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
3892 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
3893 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
3894 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
3895 if(phy_ctrl
& CR_1000T_MS_ENABLE
) {
3896 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
3897 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
,
3899 adapter
->smartspeed
++;
3900 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
3901 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
,
3903 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
3904 MII_CR_RESTART_AUTO_NEG
);
3905 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
,
3910 } else if(adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
3911 /* If still no link, perhaps using 2/3 pair cable */
3912 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
3913 phy_ctrl
|= CR_1000T_MS_ENABLE
;
3914 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, phy_ctrl
);
3915 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
3916 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &phy_ctrl
)) {
3917 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
3918 MII_CR_RESTART_AUTO_NEG
);
3919 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, phy_ctrl
);
3922 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3923 if(adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
3924 adapter
->smartspeed
= 0;
3935 e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
3941 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
3955 e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
3957 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
3958 struct mii_ioctl_data
*data
= if_mii(ifr
);
3962 unsigned long flags
;
3964 if(adapter
->hw
.media_type
!= e1000_media_type_copper
)
3969 data
->phy_id
= adapter
->hw
.phy_addr
;
3972 if(!capable(CAP_NET_ADMIN
))
3974 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3975 if(e1000_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
3977 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3980 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3983 if(!capable(CAP_NET_ADMIN
))
3985 if(data
->reg_num
& ~(0x1F))
3987 mii_reg
= data
->val_in
;
3988 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
3989 if(e1000_write_phy_reg(&adapter
->hw
, data
->reg_num
,
3991 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
3994 if(adapter
->hw
.phy_type
== e1000_phy_m88
) {
3995 switch (data
->reg_num
) {
3997 if(mii_reg
& MII_CR_POWER_DOWN
)
3999 if(mii_reg
& MII_CR_AUTO_NEG_EN
) {
4000 adapter
->hw
.autoneg
= 1;
4001 adapter
->hw
.autoneg_advertised
= 0x2F;
4004 spddplx
= SPEED_1000
;
4005 else if (mii_reg
& 0x2000)
4006 spddplx
= SPEED_100
;
4009 spddplx
+= (mii_reg
& 0x100)
4012 retval
= e1000_set_spd_dplx(adapter
,
4015 spin_unlock_irqrestore(
4016 &adapter
->stats_lock
,
4021 if(netif_running(adapter
->netdev
)) {
4022 e1000_down(adapter
);
4025 e1000_reset(adapter
);
4027 case M88E1000_PHY_SPEC_CTRL
:
4028 case M88E1000_EXT_PHY_SPEC_CTRL
:
4029 if(e1000_phy_reset(&adapter
->hw
)) {
4030 spin_unlock_irqrestore(
4031 &adapter
->stats_lock
, flags
);
4037 switch (data
->reg_num
) {
4039 if(mii_reg
& MII_CR_POWER_DOWN
)
4041 if(netif_running(adapter
->netdev
)) {
4042 e1000_down(adapter
);
4045 e1000_reset(adapter
);
4049 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
4054 return E1000_SUCCESS
;
4058 e1000_pci_set_mwi(struct e1000_hw
*hw
)
4060 struct e1000_adapter
*adapter
= hw
->back
;
4061 int ret_val
= pci_set_mwi(adapter
->pdev
);
4064 DPRINTK(PROBE
, ERR
, "Error in setting MWI\n");
4068 e1000_pci_clear_mwi(struct e1000_hw
*hw
)
4070 struct e1000_adapter
*adapter
= hw
->back
;
4072 pci_clear_mwi(adapter
->pdev
);
4076 e1000_read_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4078 struct e1000_adapter
*adapter
= hw
->back
;
4080 pci_read_config_word(adapter
->pdev
, reg
, value
);
4084 e1000_write_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
4086 struct e1000_adapter
*adapter
= hw
->back
;
4088 pci_write_config_word(adapter
->pdev
, reg
, *value
);
4092 e1000_io_read(struct e1000_hw
*hw
, unsigned long port
)
4098 e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, uint32_t value
)
4104 e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
4106 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4107 uint32_t ctrl
, rctl
;
4109 e1000_irq_disable(adapter
);
4110 adapter
->vlgrp
= grp
;
4113 /* enable VLAN tag insert/strip */
4114 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4115 ctrl
|= E1000_CTRL_VME
;
4116 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4118 /* enable VLAN receive filtering */
4119 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4120 rctl
|= E1000_RCTL_VFE
;
4121 rctl
&= ~E1000_RCTL_CFIEN
;
4122 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4123 e1000_update_mng_vlan(adapter
);
4125 /* disable VLAN tag insert/strip */
4126 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4127 ctrl
&= ~E1000_CTRL_VME
;
4128 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4130 /* disable VLAN filtering */
4131 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4132 rctl
&= ~E1000_RCTL_VFE
;
4133 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4134 if(adapter
->mng_vlan_id
!= (uint16_t)E1000_MNG_VLAN_NONE
) {
4135 e1000_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
4136 adapter
->mng_vlan_id
= E1000_MNG_VLAN_NONE
;
4140 e1000_irq_enable(adapter
);
4144 e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
)
4146 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4147 uint32_t vfta
, index
;
4148 if((adapter
->hw
.mng_cookie
.status
&
4149 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4150 (vid
== adapter
->mng_vlan_id
))
4152 /* add VID to filter table */
4153 index
= (vid
>> 5) & 0x7F;
4154 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4155 vfta
|= (1 << (vid
& 0x1F));
4156 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4160 e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
)
4162 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4163 uint32_t vfta
, index
;
4165 e1000_irq_disable(adapter
);
4168 adapter
->vlgrp
->vlan_devices
[vid
] = NULL
;
4170 e1000_irq_enable(adapter
);
4172 if((adapter
->hw
.mng_cookie
.status
&
4173 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT
) &&
4174 (vid
== adapter
->mng_vlan_id
))
4176 /* remove VID from filter table */
4177 index
= (vid
>> 5) & 0x7F;
4178 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
4179 vfta
&= ~(1 << (vid
& 0x1F));
4180 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
4184 e1000_restore_vlan(struct e1000_adapter
*adapter
)
4186 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
4188 if(adapter
->vlgrp
) {
4190 for(vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
4191 if(!adapter
->vlgrp
->vlan_devices
[vid
])
4193 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
4199 e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
)
4201 adapter
->hw
.autoneg
= 0;
4203 /* Fiber NICs only allow 1000 gbps Full duplex */
4204 if((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
4205 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
4206 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4211 case SPEED_10
+ DUPLEX_HALF
:
4212 adapter
->hw
.forced_speed_duplex
= e1000_10_half
;
4214 case SPEED_10
+ DUPLEX_FULL
:
4215 adapter
->hw
.forced_speed_duplex
= e1000_10_full
;
4217 case SPEED_100
+ DUPLEX_HALF
:
4218 adapter
->hw
.forced_speed_duplex
= e1000_100_half
;
4220 case SPEED_100
+ DUPLEX_FULL
:
4221 adapter
->hw
.forced_speed_duplex
= e1000_100_full
;
4223 case SPEED_1000
+ DUPLEX_FULL
:
4224 adapter
->hw
.autoneg
= 1;
4225 adapter
->hw
.autoneg_advertised
= ADVERTISE_1000_FULL
;
4227 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
4229 DPRINTK(PROBE
, ERR
, "Unsupported Speed/Duplex configuration\n");
4237 e1000_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4239 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4240 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4241 uint32_t ctrl
, ctrl_ext
, rctl
, manc
, status
;
4242 uint32_t wufc
= adapter
->wol
;
4244 netif_device_detach(netdev
);
4246 if(netif_running(netdev
))
4247 e1000_down(adapter
);
4249 status
= E1000_READ_REG(&adapter
->hw
, STATUS
);
4250 if(status
& E1000_STATUS_LU
)
4251 wufc
&= ~E1000_WUFC_LNKC
;
4254 e1000_setup_rctl(adapter
);
4255 e1000_set_multi(netdev
);
4257 /* turn on all-multi mode if wake on multicast is enabled */
4258 if(adapter
->wol
& E1000_WUFC_MC
) {
4259 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
4260 rctl
|= E1000_RCTL_MPE
;
4261 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
4264 if(adapter
->hw
.mac_type
>= e1000_82540
) {
4265 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
4266 /* advertise wake from D3Cold */
4267 #define E1000_CTRL_ADVD3WUC 0x00100000
4268 /* phy power management enable */
4269 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4270 ctrl
|= E1000_CTRL_ADVD3WUC
|
4271 E1000_CTRL_EN_PHY_PWR_MGMT
;
4272 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
4275 if(adapter
->hw
.media_type
== e1000_media_type_fiber
||
4276 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) {
4277 /* keep the laser running in D3 */
4278 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
4279 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
4280 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
, ctrl_ext
);
4283 /* Allow time for pending master requests to run */
4284 e1000_disable_pciex_master(&adapter
->hw
);
4286 E1000_WRITE_REG(&adapter
->hw
, WUC
, E1000_WUC_PME_EN
);
4287 E1000_WRITE_REG(&adapter
->hw
, WUFC
, wufc
);
4288 pci_enable_wake(pdev
, 3, 1);
4289 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
4291 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
4292 E1000_WRITE_REG(&adapter
->hw
, WUFC
, 0);
4293 pci_enable_wake(pdev
, 3, 0);
4294 pci_enable_wake(pdev
, 4, 0); /* 4 == D3 cold */
4297 pci_save_state(pdev
);
4299 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4300 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4301 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4302 if(manc
& E1000_MANC_SMBUS_EN
) {
4303 manc
|= E1000_MANC_ARP_EN
;
4304 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4305 pci_enable_wake(pdev
, 3, 1);
4306 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
4310 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4311 * would have already happened in close and is redundant. */
4312 e1000_release_hw_control(adapter
);
4314 pci_disable_device(pdev
);
4315 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4321 e1000_resume(struct pci_dev
*pdev
)
4323 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4324 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4325 uint32_t manc
, ret_val
;
4327 pci_set_power_state(pdev
, PCI_D0
);
4328 pci_restore_state(pdev
);
4329 ret_val
= pci_enable_device(pdev
);
4330 pci_set_master(pdev
);
4332 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4333 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4335 e1000_reset(adapter
);
4336 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
4338 if(netif_running(netdev
))
4341 netif_device_attach(netdev
);
4343 if(adapter
->hw
.mac_type
>= e1000_82540
&&
4344 adapter
->hw
.media_type
== e1000_media_type_copper
) {
4345 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
4346 manc
&= ~(E1000_MANC_ARP_EN
);
4347 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
4350 /* If the controller is 82573 and f/w is AMT, do not set
4351 * DRV_LOAD until the interface is up. For all other cases,
4352 * let the f/w know that the h/w is now under the control
4354 if (adapter
->hw
.mac_type
!= e1000_82573
||
4355 !e1000_check_mng_mode(&adapter
->hw
))
4356 e1000_get_hw_control(adapter
);
4361 #ifdef CONFIG_NET_POLL_CONTROLLER
4363 * Polling 'interrupt' - used by things like netconsole to send skbs
4364 * without having to re-enable interrupts. It's not called while
4365 * the interrupt routine is executing.
4368 e1000_netpoll(struct net_device
*netdev
)
4370 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
4371 disable_irq(adapter
->pdev
->irq
);
4372 e1000_intr(adapter
->pdev
->irq
, netdev
, NULL
);
4373 e1000_clean_tx_irq(adapter
, adapter
->tx_ring
);
4374 enable_irq(adapter
->pdev
->irq
);