1 /*******************************************************************************
4 Copyright(c) 1999 - 2004 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 * - kcompat NETIF_MSG for older kernels (2.4.9) <sean.p.mcdermott@intel.com>
34 * - if_mii support and associated kcompat for older kernels
35 * - More errlogging support from Jon Mason <jonmason@us.ibm.com>
36 * - Fix TSO issues on PPC64 machines -- Jon Mason <jonmason@us.ibm.com>
39 * - Resurrect 82547EI/GI related fix in e1000_intr to avoid deadlocks. This
40 * fix was removed as it caused system instability. The suspected cause of
41 * this is the called to e1000_irq_disable in e1000_intr. Inlined the
42 * required piece of e1000_irq_disable into e1000_intr - Anton Blanchard
44 * - include fix to the condition that determines when to quit NAPI - Robert Olsson
45 * - use netif_poll_{disable/enable} to synchronize between NAPI and i/f up/down
47 * - Enabling NETIF_F_SG without checksum offload is illegal -
48 John Mason <jdmason@us.ibm.com>
50 * - Remove redundant initialization - Jamal Hadi
51 * - Reset buffer_info->dma in tx resource cleanup logic
53 * - Avoid filling tx_ring completely - shemminger@osdl.org
54 * - Replace schedule_timeout() with msleep()/msleep_interruptible() -
56 * - Sparse cleanup - shemminger@osdl.org
57 * - Fix tx resource cleanup logic
58 * - LLTX support - ak@suse.de and hadi@cyberus.ca
61 char e1000_driver_name
[] = "e1000";
62 char e1000_driver_string
[] = "Intel(R) PRO/1000 Network Driver";
63 #ifndef CONFIG_E1000_NAPI
66 #define DRIVERNAPI "-NAPI"
68 #define DRV_VERSION "5.7.6-k2"DRIVERNAPI
69 char e1000_driver_version
[] = DRV_VERSION
;
70 char e1000_copyright
[] = "Copyright (c) 1999-2004 Intel Corporation.";
72 /* e1000_pci_tbl - PCI Device ID Table
74 * Last entry must be all 0s
77 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
79 static struct pci_device_id e1000_pci_tbl
[] = {
80 INTEL_E1000_ETHERNET_DEVICE(0x1000),
81 INTEL_E1000_ETHERNET_DEVICE(0x1001),
82 INTEL_E1000_ETHERNET_DEVICE(0x1004),
83 INTEL_E1000_ETHERNET_DEVICE(0x1008),
84 INTEL_E1000_ETHERNET_DEVICE(0x1009),
85 INTEL_E1000_ETHERNET_DEVICE(0x100C),
86 INTEL_E1000_ETHERNET_DEVICE(0x100D),
87 INTEL_E1000_ETHERNET_DEVICE(0x100E),
88 INTEL_E1000_ETHERNET_DEVICE(0x100F),
89 INTEL_E1000_ETHERNET_DEVICE(0x1010),
90 INTEL_E1000_ETHERNET_DEVICE(0x1011),
91 INTEL_E1000_ETHERNET_DEVICE(0x1012),
92 INTEL_E1000_ETHERNET_DEVICE(0x1013),
93 INTEL_E1000_ETHERNET_DEVICE(0x1014),
94 INTEL_E1000_ETHERNET_DEVICE(0x1015),
95 INTEL_E1000_ETHERNET_DEVICE(0x1016),
96 INTEL_E1000_ETHERNET_DEVICE(0x1017),
97 INTEL_E1000_ETHERNET_DEVICE(0x1018),
98 INTEL_E1000_ETHERNET_DEVICE(0x1019),
99 INTEL_E1000_ETHERNET_DEVICE(0x101D),
100 INTEL_E1000_ETHERNET_DEVICE(0x101E),
101 INTEL_E1000_ETHERNET_DEVICE(0x1026),
102 INTEL_E1000_ETHERNET_DEVICE(0x1027),
103 INTEL_E1000_ETHERNET_DEVICE(0x1028),
104 INTEL_E1000_ETHERNET_DEVICE(0x1075),
105 INTEL_E1000_ETHERNET_DEVICE(0x1076),
106 INTEL_E1000_ETHERNET_DEVICE(0x1077),
107 INTEL_E1000_ETHERNET_DEVICE(0x1078),
108 INTEL_E1000_ETHERNET_DEVICE(0x1079),
109 INTEL_E1000_ETHERNET_DEVICE(0x107A),
110 INTEL_E1000_ETHERNET_DEVICE(0x107B),
111 INTEL_E1000_ETHERNET_DEVICE(0x107C),
112 INTEL_E1000_ETHERNET_DEVICE(0x108A),
113 /* required last entry */
117 MODULE_DEVICE_TABLE(pci
, e1000_pci_tbl
);
119 int e1000_up(struct e1000_adapter
*adapter
);
120 void e1000_down(struct e1000_adapter
*adapter
);
121 void e1000_reset(struct e1000_adapter
*adapter
);
122 int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
);
123 int e1000_setup_tx_resources(struct e1000_adapter
*adapter
);
124 int e1000_setup_rx_resources(struct e1000_adapter
*adapter
);
125 void e1000_free_tx_resources(struct e1000_adapter
*adapter
);
126 void e1000_free_rx_resources(struct e1000_adapter
*adapter
);
127 void e1000_update_stats(struct e1000_adapter
*adapter
);
129 /* Local Function Prototypes */
131 static int e1000_init_module(void);
132 static void e1000_exit_module(void);
133 static int e1000_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
134 static void __devexit
e1000_remove(struct pci_dev
*pdev
);
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_tx_ring(struct e1000_adapter
*adapter
);
142 static void e1000_clean_rx_ring(struct e1000_adapter
*adapter
);
143 static void e1000_set_multi(struct net_device
*netdev
);
144 static void e1000_update_phy_info(unsigned long data
);
145 static void e1000_watchdog(unsigned long data
);
146 static void e1000_watchdog_task(struct e1000_adapter
*adapter
);
147 static void e1000_82547_tx_fifo_stall(unsigned long data
);
148 static int e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
);
149 static struct net_device_stats
* e1000_get_stats(struct net_device
*netdev
);
150 static int e1000_change_mtu(struct net_device
*netdev
, int new_mtu
);
151 static int e1000_set_mac(struct net_device
*netdev
, void *p
);
152 static irqreturn_t
e1000_intr(int irq
, void *data
, struct pt_regs
*regs
);
153 static boolean_t
e1000_clean_tx_irq(struct e1000_adapter
*adapter
);
154 #ifdef CONFIG_E1000_NAPI
155 static int e1000_clean(struct net_device
*netdev
, int *budget
);
156 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
,
157 int *work_done
, int work_to_do
);
159 static boolean_t
e1000_clean_rx_irq(struct e1000_adapter
*adapter
);
161 static void e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
);
162 static int e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
);
163 static int e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
,
165 void e1000_set_ethtool_ops(struct net_device
*netdev
);
166 static void e1000_enter_82542_rst(struct e1000_adapter
*adapter
);
167 static void e1000_leave_82542_rst(struct e1000_adapter
*adapter
);
168 static void e1000_tx_timeout(struct net_device
*dev
);
169 static void e1000_tx_timeout_task(struct net_device
*dev
);
170 static void e1000_smartspeed(struct e1000_adapter
*adapter
);
171 static inline int e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
,
172 struct sk_buff
*skb
);
174 static void e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
);
175 static void e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
);
176 static void e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
);
177 static void e1000_restore_vlan(struct e1000_adapter
*adapter
);
179 static int e1000_notify_reboot(struct notifier_block
*, unsigned long event
, void *ptr
);
180 static int e1000_suspend(struct pci_dev
*pdev
, uint32_t state
);
182 static int e1000_resume(struct pci_dev
*pdev
);
185 #ifdef CONFIG_NET_POLL_CONTROLLER
186 /* for netdump / net console */
187 static void e1000_netpoll (struct net_device
*netdev
);
190 struct notifier_block e1000_notifier_reboot
= {
191 .notifier_call
= e1000_notify_reboot
,
196 /* Exported from other modules */
198 extern void e1000_check_options(struct e1000_adapter
*adapter
);
200 static struct pci_driver e1000_driver
= {
201 .name
= e1000_driver_name
,
202 .id_table
= e1000_pci_tbl
,
203 .probe
= e1000_probe
,
204 .remove
= __devexit_p(e1000_remove
),
205 /* Power Managment Hooks */
207 .suspend
= e1000_suspend
,
208 .resume
= e1000_resume
212 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
213 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
214 MODULE_LICENSE("GPL");
215 MODULE_VERSION(DRV_VERSION
);
217 static int debug
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
218 module_param(debug
, int, 0);
219 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
222 * e1000_init_module - Driver Registration Routine
224 * e1000_init_module is the first routine called when the driver is
225 * loaded. All it does is register with the PCI subsystem.
229 e1000_init_module(void)
232 printk(KERN_INFO
"%s - version %s\n",
233 e1000_driver_string
, e1000_driver_version
);
235 printk(KERN_INFO
"%s\n", e1000_copyright
);
237 ret
= pci_module_init(&e1000_driver
);
239 register_reboot_notifier(&e1000_notifier_reboot
);
244 module_init(e1000_init_module
);
247 * e1000_exit_module - Driver Exit Cleanup Routine
249 * e1000_exit_module is called just before the driver is removed
254 e1000_exit_module(void)
256 unregister_reboot_notifier(&e1000_notifier_reboot
);
257 pci_unregister_driver(&e1000_driver
);
260 module_exit(e1000_exit_module
);
263 * e1000_irq_disable - Mask off interrupt generation on the NIC
264 * @adapter: board private structure
268 e1000_irq_disable(struct e1000_adapter
*adapter
)
270 atomic_inc(&adapter
->irq_sem
);
271 E1000_WRITE_REG(&adapter
->hw
, IMC
, ~0);
272 E1000_WRITE_FLUSH(&adapter
->hw
);
273 synchronize_irq(adapter
->pdev
->irq
);
277 * e1000_irq_enable - Enable default interrupt generation settings
278 * @adapter: board private structure
282 e1000_irq_enable(struct e1000_adapter
*adapter
)
284 if(likely(atomic_dec_and_test(&adapter
->irq_sem
))) {
285 E1000_WRITE_REG(&adapter
->hw
, IMS
, IMS_ENABLE_MASK
);
286 E1000_WRITE_FLUSH(&adapter
->hw
);
291 e1000_up(struct e1000_adapter
*adapter
)
293 struct net_device
*netdev
= adapter
->netdev
;
296 /* hardware has been reset, we need to reload some things */
298 /* Reset the PHY if it was previously powered down */
299 if(adapter
->hw
.media_type
== e1000_media_type_copper
) {
301 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
302 if(mii_reg
& MII_CR_POWER_DOWN
)
303 e1000_phy_reset(&adapter
->hw
);
306 e1000_set_multi(netdev
);
308 e1000_restore_vlan(adapter
);
310 e1000_configure_tx(adapter
);
311 e1000_setup_rctl(adapter
);
312 e1000_configure_rx(adapter
);
313 e1000_alloc_rx_buffers(adapter
);
315 if((err
= request_irq(adapter
->pdev
->irq
, &e1000_intr
,
316 SA_SHIRQ
| SA_SAMPLE_RANDOM
,
317 netdev
->name
, netdev
)))
320 mod_timer(&adapter
->watchdog_timer
, jiffies
);
321 e1000_irq_enable(adapter
);
323 #ifdef CONFIG_E1000_NAPI
324 netif_poll_enable(netdev
);
330 e1000_down(struct e1000_adapter
*adapter
)
332 struct net_device
*netdev
= adapter
->netdev
;
334 e1000_irq_disable(adapter
);
335 free_irq(adapter
->pdev
->irq
, netdev
);
336 del_timer_sync(&adapter
->tx_fifo_stall_timer
);
337 del_timer_sync(&adapter
->watchdog_timer
);
338 del_timer_sync(&adapter
->phy_info_timer
);
340 #ifdef CONFIG_E1000_NAPI
341 netif_poll_disable(netdev
);
343 adapter
->link_speed
= 0;
344 adapter
->link_duplex
= 0;
345 netif_carrier_off(netdev
);
346 netif_stop_queue(netdev
);
348 e1000_reset(adapter
);
349 e1000_clean_tx_ring(adapter
);
350 e1000_clean_rx_ring(adapter
);
352 /* If WoL is not enabled
353 * Power down the PHY so no link is implied when interface is down */
354 if(!adapter
->wol
&& adapter
->hw
.media_type
== e1000_media_type_copper
) {
356 e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &mii_reg
);
357 mii_reg
|= MII_CR_POWER_DOWN
;
358 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, mii_reg
);
363 e1000_reset(struct e1000_adapter
*adapter
)
367 /* Repartition Pba for greater than 9k mtu
368 * To take effect CTRL.RST is required.
371 if(adapter
->hw
.mac_type
< e1000_82547
) {
372 if(adapter
->rx_buffer_len
> E1000_RXBUFFER_8192
)
377 if(adapter
->rx_buffer_len
> E1000_RXBUFFER_8192
)
381 adapter
->tx_fifo_head
= 0;
382 adapter
->tx_head_addr
= pba
<< E1000_TX_HEAD_ADDR_SHIFT
;
383 adapter
->tx_fifo_size
=
384 (E1000_PBA_40K
- pba
) << E1000_PBA_BYTES_SHIFT
;
385 atomic_set(&adapter
->tx_fifo_stall
, 0);
387 E1000_WRITE_REG(&adapter
->hw
, PBA
, pba
);
389 /* flow control settings */
390 adapter
->hw
.fc_high_water
= (pba
<< E1000_PBA_BYTES_SHIFT
) -
392 adapter
->hw
.fc_low_water
= (pba
<< E1000_PBA_BYTES_SHIFT
) -
394 adapter
->hw
.fc_pause_time
= E1000_FC_PAUSE_TIME
;
395 adapter
->hw
.fc_send_xon
= 1;
396 adapter
->hw
.fc
= adapter
->hw
.original_fc
;
398 e1000_reset_hw(&adapter
->hw
);
399 if(adapter
->hw
.mac_type
>= e1000_82544
)
400 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
401 if(e1000_init_hw(&adapter
->hw
))
402 DPRINTK(PROBE
, ERR
, "Hardware Error\n");
404 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
405 E1000_WRITE_REG(&adapter
->hw
, VET
, ETHERNET_IEEE_VLAN_TYPE
);
407 e1000_reset_adaptive(&adapter
->hw
);
408 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
412 * e1000_probe - Device Initialization Routine
413 * @pdev: PCI device information struct
414 * @ent: entry in e1000_pci_tbl
416 * Returns 0 on success, negative on failure
418 * e1000_probe initializes an adapter identified by a pci_dev structure.
419 * The OS initialization, configuring of the adapter private structure,
420 * and a hardware reset occur.
424 e1000_probe(struct pci_dev
*pdev
,
425 const struct pci_device_id
*ent
)
427 struct net_device
*netdev
;
428 struct e1000_adapter
*adapter
;
429 static int cards_found
= 0;
430 unsigned long mmio_start
;
435 uint16_t eeprom_data
;
436 uint16_t eeprom_apme_mask
= E1000_EEPROM_APME
;
438 if((err
= pci_enable_device(pdev
)))
441 if(!(err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
))) {
444 if((err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
))) {
445 E1000_ERR("No usable DMA configuration, aborting\n");
451 if((err
= pci_request_regions(pdev
, e1000_driver_name
)))
454 pci_set_master(pdev
);
456 netdev
= alloc_etherdev(sizeof(struct e1000_adapter
));
459 goto err_alloc_etherdev
;
462 SET_MODULE_OWNER(netdev
);
463 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
465 pci_set_drvdata(pdev
, netdev
);
466 adapter
= netdev
->priv
;
467 adapter
->netdev
= netdev
;
468 adapter
->pdev
= pdev
;
469 adapter
->hw
.back
= adapter
;
470 adapter
->msg_enable
= (1 << debug
) - 1;
472 mmio_start
= pci_resource_start(pdev
, BAR_0
);
473 mmio_len
= pci_resource_len(pdev
, BAR_0
);
475 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
476 if(!adapter
->hw
.hw_addr
) {
481 for(i
= BAR_1
; i
<= BAR_5
; i
++) {
482 if(pci_resource_len(pdev
, i
) == 0)
484 if(pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
485 adapter
->hw
.io_base
= pci_resource_start(pdev
, i
);
490 netdev
->open
= &e1000_open
;
491 netdev
->stop
= &e1000_close
;
492 netdev
->hard_start_xmit
= &e1000_xmit_frame
;
493 netdev
->get_stats
= &e1000_get_stats
;
494 netdev
->set_multicast_list
= &e1000_set_multi
;
495 netdev
->set_mac_address
= &e1000_set_mac
;
496 netdev
->change_mtu
= &e1000_change_mtu
;
497 netdev
->do_ioctl
= &e1000_ioctl
;
498 e1000_set_ethtool_ops(netdev
);
499 netdev
->tx_timeout
= &e1000_tx_timeout
;
500 netdev
->watchdog_timeo
= 5 * HZ
;
501 #ifdef CONFIG_E1000_NAPI
502 netdev
->poll
= &e1000_clean
;
505 netdev
->vlan_rx_register
= e1000_vlan_rx_register
;
506 netdev
->vlan_rx_add_vid
= e1000_vlan_rx_add_vid
;
507 netdev
->vlan_rx_kill_vid
= e1000_vlan_rx_kill_vid
;
508 #ifdef CONFIG_NET_POLL_CONTROLLER
509 netdev
->poll_controller
= e1000_netpoll
;
511 strcpy(netdev
->name
, pci_name(pdev
));
513 netdev
->mem_start
= mmio_start
;
514 netdev
->mem_end
= mmio_start
+ mmio_len
;
515 netdev
->base_addr
= adapter
->hw
.io_base
;
517 adapter
->bd_number
= cards_found
;
519 /* setup the private structure */
521 if((err
= e1000_sw_init(adapter
)))
524 if(adapter
->hw
.mac_type
>= e1000_82543
) {
525 netdev
->features
= NETIF_F_SG
|
529 NETIF_F_HW_VLAN_FILTER
;
533 if((adapter
->hw
.mac_type
>= e1000_82544
) &&
534 (adapter
->hw
.mac_type
!= e1000_82547
))
535 netdev
->features
|= NETIF_F_TSO
;
538 netdev
->features
|= NETIF_F_HIGHDMA
;
540 /* hard_start_xmit is safe against parallel locking */
541 netdev
->features
|= NETIF_F_LLTX
;
543 /* before reading the EEPROM, reset the controller to
544 * put the device in a known good starting state */
546 e1000_reset_hw(&adapter
->hw
);
548 /* make sure the EEPROM is good */
550 if(e1000_validate_eeprom_checksum(&adapter
->hw
) < 0) {
551 DPRINTK(PROBE
, ERR
, "The EEPROM Checksum Is Not Valid\n");
556 /* copy the MAC address out of the EEPROM */
558 if (e1000_read_mac_addr(&adapter
->hw
))
559 DPRINTK(PROBE
, ERR
, "EEPROM Read Error\n");
560 memcpy(netdev
->dev_addr
, adapter
->hw
.mac_addr
, netdev
->addr_len
);
562 if(!is_valid_ether_addr(netdev
->dev_addr
)) {
563 DPRINTK(PROBE
, ERR
, "Invalid MAC Address\n");
568 e1000_read_part_num(&adapter
->hw
, &(adapter
->part_num
));
570 e1000_get_bus_info(&adapter
->hw
);
572 init_timer(&adapter
->tx_fifo_stall_timer
);
573 adapter
->tx_fifo_stall_timer
.function
= &e1000_82547_tx_fifo_stall
;
574 adapter
->tx_fifo_stall_timer
.data
= (unsigned long) adapter
;
576 init_timer(&adapter
->watchdog_timer
);
577 adapter
->watchdog_timer
.function
= &e1000_watchdog
;
578 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
580 INIT_WORK(&adapter
->watchdog_task
,
581 (void (*)(void *))e1000_watchdog_task
, adapter
);
583 init_timer(&adapter
->phy_info_timer
);
584 adapter
->phy_info_timer
.function
= &e1000_update_phy_info
;
585 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
587 INIT_WORK(&adapter
->tx_timeout_task
,
588 (void (*)(void *))e1000_tx_timeout_task
, netdev
);
590 /* we're going to reset, so assume we have no link for now */
592 netif_carrier_off(netdev
);
593 netif_stop_queue(netdev
);
595 e1000_check_options(adapter
);
597 /* Initial Wake on LAN setting
598 * If APM wake is enabled in the EEPROM,
599 * enable the ACPI Magic Packet filter
602 switch(adapter
->hw
.mac_type
) {
603 case e1000_82542_rev2_0
:
604 case e1000_82542_rev2_1
:
608 e1000_read_eeprom(&adapter
->hw
,
609 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
610 eeprom_apme_mask
= E1000_EEPROM_82544_APM
;
613 case e1000_82546_rev_3
:
614 if((E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_FUNC_1
)
615 && (adapter
->hw
.media_type
== e1000_media_type_copper
)) {
616 e1000_read_eeprom(&adapter
->hw
,
617 EEPROM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
622 e1000_read_eeprom(&adapter
->hw
,
623 EEPROM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
626 if(eeprom_data
& eeprom_apme_mask
)
627 adapter
->wol
|= E1000_WUFC_MAG
;
629 /* reset the hardware with the new settings */
630 e1000_reset(adapter
);
632 strcpy(netdev
->name
, "eth%d");
633 if((err
= register_netdev(netdev
)))
636 DPRINTK(PROBE
, INFO
, "Intel(R) PRO/1000 Network Connection\n");
644 iounmap(adapter
->hw
.hw_addr
);
648 pci_release_regions(pdev
);
653 * e1000_remove - Device Removal Routine
654 * @pdev: PCI device information struct
656 * e1000_remove is called by the PCI subsystem to alert the driver
657 * that it should release a PCI device. The could be caused by a
658 * Hot-Plug event, or because the driver is going to be removed from
662 static void __devexit
663 e1000_remove(struct pci_dev
*pdev
)
665 struct net_device
*netdev
= pci_get_drvdata(pdev
);
666 struct e1000_adapter
*adapter
= netdev
->priv
;
669 flush_scheduled_work();
671 if(adapter
->hw
.mac_type
>= e1000_82540
&&
672 adapter
->hw
.media_type
== e1000_media_type_copper
) {
673 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
674 if(manc
& E1000_MANC_SMBUS_EN
) {
675 manc
|= E1000_MANC_ARP_EN
;
676 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
680 unregister_netdev(netdev
);
682 e1000_phy_hw_reset(&adapter
->hw
);
684 iounmap(adapter
->hw
.hw_addr
);
685 pci_release_regions(pdev
);
689 pci_disable_device(pdev
);
693 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
694 * @adapter: board private structure to initialize
696 * e1000_sw_init initializes the Adapter private data structure.
697 * Fields are initialized based on PCI device information and
698 * OS network device settings (MTU size).
702 e1000_sw_init(struct e1000_adapter
*adapter
)
704 struct e1000_hw
*hw
= &adapter
->hw
;
705 struct net_device
*netdev
= adapter
->netdev
;
706 struct pci_dev
*pdev
= adapter
->pdev
;
708 /* PCI config space info */
710 hw
->vendor_id
= pdev
->vendor
;
711 hw
->device_id
= pdev
->device
;
712 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
713 hw
->subsystem_id
= pdev
->subsystem_device
;
715 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
717 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
719 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
720 hw
->max_frame_size
= netdev
->mtu
+
721 ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
722 hw
->min_frame_size
= MINIMUM_ETHERNET_FRAME_SIZE
;
724 /* identify the MAC */
726 if(e1000_set_mac_type(hw
)) {
727 DPRINTK(PROBE
, ERR
, "Unknown MAC Type\n");
731 /* initialize eeprom parameters */
733 e1000_init_eeprom_params(hw
);
735 switch(hw
->mac_type
) {
740 case e1000_82541_rev_2
:
741 case e1000_82547_rev_2
:
742 hw
->phy_init_script
= 1;
746 e1000_set_media_type(hw
);
748 hw
->wait_autoneg_complete
= FALSE
;
749 hw
->tbi_compatibility_en
= TRUE
;
750 hw
->adaptive_ifs
= TRUE
;
754 if(hw
->media_type
== e1000_media_type_copper
) {
755 hw
->mdix
= AUTO_ALL_MODES
;
756 hw
->disable_polarity_correction
= FALSE
;
757 hw
->master_slave
= E1000_MASTER_SLAVE
;
760 atomic_set(&adapter
->irq_sem
, 1);
761 spin_lock_init(&adapter
->stats_lock
);
762 spin_lock_init(&adapter
->tx_lock
);
768 * e1000_open - Called when a network interface is made active
769 * @netdev: network interface device structure
771 * Returns 0 on success, negative value on failure
773 * The open entry point is called when a network interface is made
774 * active by the system (IFF_UP). At this point all resources needed
775 * for transmit and receive operations are allocated, the interrupt
776 * handler is registered with the OS, the watchdog timer is started,
777 * and the stack is notified that the interface is ready.
781 e1000_open(struct net_device
*netdev
)
783 struct e1000_adapter
*adapter
= netdev
->priv
;
786 /* allocate transmit descriptors */
788 if((err
= e1000_setup_tx_resources(adapter
)))
791 /* allocate receive descriptors */
793 if((err
= e1000_setup_rx_resources(adapter
)))
796 if((err
= e1000_up(adapter
)))
799 return E1000_SUCCESS
;
802 e1000_free_rx_resources(adapter
);
804 e1000_free_tx_resources(adapter
);
806 e1000_reset(adapter
);
812 * e1000_close - Disables a network interface
813 * @netdev: network interface device structure
815 * Returns 0, this is not allowed to fail
817 * The close entry point is called when an interface is de-activated
818 * by the OS. The hardware is still under the drivers control, but
819 * needs to be disabled. A global MAC reset is issued to stop the
820 * hardware, and all transmit and receive resources are freed.
824 e1000_close(struct net_device
*netdev
)
826 struct e1000_adapter
*adapter
= netdev
->priv
;
830 e1000_free_tx_resources(adapter
);
831 e1000_free_rx_resources(adapter
);
837 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
838 * @adapter: address of board private structure
839 * @begin: address of beginning of memory
840 * @end: address of end of memory
842 static inline boolean_t
843 e1000_check_64k_bound(struct e1000_adapter
*adapter
,
844 void *start
, unsigned long len
)
846 unsigned long begin
= (unsigned long) start
;
847 unsigned long end
= begin
+ len
;
849 /* first rev 82545 and 82546 need to not allow any memory
850 * write location to cross a 64k boundary due to errata 23 */
851 if (adapter
->hw
.mac_type
== e1000_82545
||
852 adapter
->hw
.mac_type
== e1000_82546
) {
854 /* check buffer doesn't cross 64kB */
855 return ((begin
^ (end
- 1)) >> 16) != 0 ? FALSE
: TRUE
;
862 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
863 * @adapter: board private structure
865 * Return 0 on success, negative on failure
869 e1000_setup_tx_resources(struct e1000_adapter
*adapter
)
871 struct e1000_desc_ring
*txdr
= &adapter
->tx_ring
;
872 struct pci_dev
*pdev
= adapter
->pdev
;
875 size
= sizeof(struct e1000_buffer
) * txdr
->count
;
876 txdr
->buffer_info
= vmalloc(size
);
877 if(!txdr
->buffer_info
) {
879 "Unable to Allocate Memory for the Transmit descriptor ring\n");
882 memset(txdr
->buffer_info
, 0, size
);
884 /* round up to nearest 4K */
886 txdr
->size
= txdr
->count
* sizeof(struct e1000_tx_desc
);
887 E1000_ROUNDUP(txdr
->size
, 4096);
889 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
893 "Unable to Allocate Memory for the Transmit descriptor ring\n");
894 vfree(txdr
->buffer_info
);
898 /* fix for errata 23, cant cross 64kB boundary */
899 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
900 void *olddesc
= txdr
->desc
;
901 dma_addr_t olddma
= txdr
->dma
;
902 DPRINTK(TX_ERR
,ERR
,"txdr align check failed: %u bytes at %p\n",
903 txdr
->size
, txdr
->desc
);
904 /* try again, without freeing the previous */
905 txdr
->desc
= pci_alloc_consistent(pdev
, txdr
->size
, &txdr
->dma
);
906 /* failed allocation, critial failure */
908 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
909 goto setup_tx_desc_die
;
912 if (!e1000_check_64k_bound(adapter
, txdr
->desc
, txdr
->size
)) {
914 pci_free_consistent(pdev
, txdr
->size
,
915 txdr
->desc
, txdr
->dma
);
916 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
918 "Unable to Allocate aligned Memory for the Transmit"
919 " descriptor ring\n");
920 vfree(txdr
->buffer_info
);
923 /* free old, move on with the new one since its okay */
924 pci_free_consistent(pdev
, txdr
->size
, olddesc
, olddma
);
927 memset(txdr
->desc
, 0, txdr
->size
);
929 txdr
->next_to_use
= 0;
930 txdr
->next_to_clean
= 0;
936 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
937 * @adapter: board private structure
939 * Configure the Tx unit of the MAC after a reset.
943 e1000_configure_tx(struct e1000_adapter
*adapter
)
945 uint64_t tdba
= adapter
->tx_ring
.dma
;
946 uint32_t tdlen
= adapter
->tx_ring
.count
* sizeof(struct e1000_tx_desc
);
949 E1000_WRITE_REG(&adapter
->hw
, TDBAL
, (tdba
& 0x00000000ffffffffULL
));
950 E1000_WRITE_REG(&adapter
->hw
, TDBAH
, (tdba
>> 32));
952 E1000_WRITE_REG(&adapter
->hw
, TDLEN
, tdlen
);
954 /* Setup the HW Tx Head and Tail descriptor pointers */
956 E1000_WRITE_REG(&adapter
->hw
, TDH
, 0);
957 E1000_WRITE_REG(&adapter
->hw
, TDT
, 0);
959 /* Set the default values for the Tx Inter Packet Gap timer */
961 switch (adapter
->hw
.mac_type
) {
962 case e1000_82542_rev2_0
:
963 case e1000_82542_rev2_1
:
964 tipg
= DEFAULT_82542_TIPG_IPGT
;
965 tipg
|= DEFAULT_82542_TIPG_IPGR1
<< E1000_TIPG_IPGR1_SHIFT
;
966 tipg
|= DEFAULT_82542_TIPG_IPGR2
<< E1000_TIPG_IPGR2_SHIFT
;
969 if(adapter
->hw
.media_type
== e1000_media_type_fiber
||
970 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
)
971 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
973 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
974 tipg
|= DEFAULT_82543_TIPG_IPGR1
<< E1000_TIPG_IPGR1_SHIFT
;
975 tipg
|= DEFAULT_82543_TIPG_IPGR2
<< E1000_TIPG_IPGR2_SHIFT
;
977 E1000_WRITE_REG(&adapter
->hw
, TIPG
, tipg
);
979 /* Set the Tx Interrupt Delay register */
981 E1000_WRITE_REG(&adapter
->hw
, TIDV
, adapter
->tx_int_delay
);
982 if(adapter
->hw
.mac_type
>= e1000_82540
)
983 E1000_WRITE_REG(&adapter
->hw
, TADV
, adapter
->tx_abs_int_delay
);
985 /* Program the Transmit Control Register */
987 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
989 tctl
&= ~E1000_TCTL_CT
;
990 tctl
|= E1000_TCTL_EN
| E1000_TCTL_PSP
|
991 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
993 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
995 e1000_config_collision_dist(&adapter
->hw
);
997 /* Setup Transmit Descriptor Settings for eop descriptor */
998 adapter
->txd_cmd
= E1000_TXD_CMD_IDE
| E1000_TXD_CMD_EOP
|
1001 if(adapter
->hw
.mac_type
< e1000_82543
)
1002 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
1004 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
1006 /* Cache if we're 82544 running in PCI-X because we'll
1007 * need this to apply a workaround later in the send path. */
1008 if(adapter
->hw
.mac_type
== e1000_82544
&&
1009 adapter
->hw
.bus_type
== e1000_bus_type_pcix
)
1010 adapter
->pcix_82544
= 1;
1014 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1015 * @adapter: board private structure
1017 * Returns 0 on success, negative on failure
1021 e1000_setup_rx_resources(struct e1000_adapter
*adapter
)
1023 struct e1000_desc_ring
*rxdr
= &adapter
->rx_ring
;
1024 struct pci_dev
*pdev
= adapter
->pdev
;
1027 size
= sizeof(struct e1000_buffer
) * rxdr
->count
;
1028 rxdr
->buffer_info
= vmalloc(size
);
1029 if(!rxdr
->buffer_info
) {
1031 "Unable to Allocate Memory for the Recieve descriptor ring\n");
1034 memset(rxdr
->buffer_info
, 0, size
);
1036 /* Round up to nearest 4K */
1038 rxdr
->size
= rxdr
->count
* sizeof(struct e1000_rx_desc
);
1039 E1000_ROUNDUP(rxdr
->size
, 4096);
1041 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1046 "Unble to Allocate Memory for the Recieve descriptor ring\n");
1047 vfree(rxdr
->buffer_info
);
1051 /* fix for errata 23, cant cross 64kB boundary */
1052 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1053 void *olddesc
= rxdr
->desc
;
1054 dma_addr_t olddma
= rxdr
->dma
;
1056 "rxdr align check failed: %u bytes at %p\n",
1057 rxdr
->size
, rxdr
->desc
);
1058 /* try again, without freeing the previous */
1059 rxdr
->desc
= pci_alloc_consistent(pdev
, rxdr
->size
, &rxdr
->dma
);
1060 /* failed allocation, critial failure */
1062 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1063 goto setup_rx_desc_die
;
1066 if (!e1000_check_64k_bound(adapter
, rxdr
->desc
, rxdr
->size
)) {
1068 pci_free_consistent(pdev
, rxdr
->size
,
1069 rxdr
->desc
, rxdr
->dma
);
1070 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1072 "Unable to Allocate aligned Memory for the"
1073 " Receive descriptor ring\n");
1074 vfree(rxdr
->buffer_info
);
1077 /* free old, move on with the new one since its okay */
1078 pci_free_consistent(pdev
, rxdr
->size
, olddesc
, olddma
);
1081 memset(rxdr
->desc
, 0, rxdr
->size
);
1083 rxdr
->next_to_clean
= 0;
1084 rxdr
->next_to_use
= 0;
1090 * e1000_setup_rctl - configure the receive control register
1091 * @adapter: Board private structure
1095 e1000_setup_rctl(struct e1000_adapter
*adapter
)
1099 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1101 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1103 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1104 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1105 (adapter
->hw
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1107 if(adapter
->hw
.tbi_compatibility_on
== 1)
1108 rctl
|= E1000_RCTL_SBP
;
1110 rctl
&= ~E1000_RCTL_SBP
;
1112 /* Setup buffer sizes */
1113 rctl
&= ~(E1000_RCTL_SZ_4096
);
1114 rctl
|= (E1000_RCTL_BSEX
| E1000_RCTL_LPE
);
1115 switch (adapter
->rx_buffer_len
) {
1116 case E1000_RXBUFFER_2048
:
1118 rctl
|= E1000_RCTL_SZ_2048
;
1119 rctl
&= ~(E1000_RCTL_BSEX
| E1000_RCTL_LPE
);
1121 case E1000_RXBUFFER_4096
:
1122 rctl
|= E1000_RCTL_SZ_4096
;
1124 case E1000_RXBUFFER_8192
:
1125 rctl
|= E1000_RCTL_SZ_8192
;
1127 case E1000_RXBUFFER_16384
:
1128 rctl
|= E1000_RCTL_SZ_16384
;
1132 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1136 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1137 * @adapter: board private structure
1139 * Configure the Rx unit of the MAC after a reset.
1143 e1000_configure_rx(struct e1000_adapter
*adapter
)
1145 uint64_t rdba
= adapter
->rx_ring
.dma
;
1146 uint32_t rdlen
= adapter
->rx_ring
.count
* sizeof(struct e1000_rx_desc
);
1150 /* disable receives while setting up the descriptors */
1151 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1152 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
1154 /* set the Receive Delay Timer Register */
1155 E1000_WRITE_REG(&adapter
->hw
, RDTR
, adapter
->rx_int_delay
);
1157 if(adapter
->hw
.mac_type
>= e1000_82540
) {
1158 E1000_WRITE_REG(&adapter
->hw
, RADV
, adapter
->rx_abs_int_delay
);
1159 if(adapter
->itr
> 1)
1160 E1000_WRITE_REG(&adapter
->hw
, ITR
,
1161 1000000000 / (adapter
->itr
* 256));
1164 /* Setup the Base and Length of the Rx Descriptor Ring */
1165 E1000_WRITE_REG(&adapter
->hw
, RDBAL
, (rdba
& 0x00000000ffffffffULL
));
1166 E1000_WRITE_REG(&adapter
->hw
, RDBAH
, (rdba
>> 32));
1168 E1000_WRITE_REG(&adapter
->hw
, RDLEN
, rdlen
);
1170 /* Setup the HW Rx Head and Tail Descriptor Pointers */
1171 E1000_WRITE_REG(&adapter
->hw
, RDH
, 0);
1172 E1000_WRITE_REG(&adapter
->hw
, RDT
, 0);
1174 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1175 if((adapter
->hw
.mac_type
>= e1000_82543
) &&
1176 (adapter
->rx_csum
== TRUE
)) {
1177 rxcsum
= E1000_READ_REG(&adapter
->hw
, RXCSUM
);
1178 rxcsum
|= E1000_RXCSUM_TUOFL
;
1179 E1000_WRITE_REG(&adapter
->hw
, RXCSUM
, rxcsum
);
1182 /* Enable Receives */
1183 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1187 * e1000_free_tx_resources - Free Tx Resources
1188 * @adapter: board private structure
1190 * Free all transmit software resources
1194 e1000_free_tx_resources(struct e1000_adapter
*adapter
)
1196 struct pci_dev
*pdev
= adapter
->pdev
;
1198 e1000_clean_tx_ring(adapter
);
1200 vfree(adapter
->tx_ring
.buffer_info
);
1201 adapter
->tx_ring
.buffer_info
= NULL
;
1203 pci_free_consistent(pdev
, adapter
->tx_ring
.size
,
1204 adapter
->tx_ring
.desc
, adapter
->tx_ring
.dma
);
1206 adapter
->tx_ring
.desc
= NULL
;
1210 e1000_unmap_and_free_tx_resource(struct e1000_adapter
*adapter
,
1211 struct e1000_buffer
*buffer_info
)
1213 struct pci_dev
*pdev
= adapter
->pdev
;
1215 if(buffer_info
->dma
) {
1216 pci_unmap_page(pdev
,
1218 buffer_info
->length
,
1220 buffer_info
->dma
= 0;
1222 if(buffer_info
->skb
) {
1223 dev_kfree_skb_any(buffer_info
->skb
);
1224 buffer_info
->skb
= NULL
;
1229 * e1000_clean_tx_ring - Free Tx Buffers
1230 * @adapter: board private structure
1234 e1000_clean_tx_ring(struct e1000_adapter
*adapter
)
1236 struct e1000_desc_ring
*tx_ring
= &adapter
->tx_ring
;
1237 struct e1000_buffer
*buffer_info
;
1241 /* Free all the Tx ring sk_buffs */
1243 if (likely(adapter
->previous_buffer_info
.skb
!= NULL
)) {
1244 e1000_unmap_and_free_tx_resource(adapter
,
1245 &adapter
->previous_buffer_info
);
1248 for(i
= 0; i
< tx_ring
->count
; i
++) {
1249 buffer_info
= &tx_ring
->buffer_info
[i
];
1250 e1000_unmap_and_free_tx_resource(adapter
, buffer_info
);
1253 size
= sizeof(struct e1000_buffer
) * tx_ring
->count
;
1254 memset(tx_ring
->buffer_info
, 0, size
);
1256 /* Zero out the descriptor ring */
1258 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1260 tx_ring
->next_to_use
= 0;
1261 tx_ring
->next_to_clean
= 0;
1263 E1000_WRITE_REG(&adapter
->hw
, TDH
, 0);
1264 E1000_WRITE_REG(&adapter
->hw
, TDT
, 0);
1268 * e1000_free_rx_resources - Free Rx Resources
1269 * @adapter: board private structure
1271 * Free all receive software resources
1275 e1000_free_rx_resources(struct e1000_adapter
*adapter
)
1277 struct e1000_desc_ring
*rx_ring
= &adapter
->rx_ring
;
1278 struct pci_dev
*pdev
= adapter
->pdev
;
1280 e1000_clean_rx_ring(adapter
);
1282 vfree(rx_ring
->buffer_info
);
1283 rx_ring
->buffer_info
= NULL
;
1285 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
1287 rx_ring
->desc
= NULL
;
1291 * e1000_clean_rx_ring - Free Rx Buffers
1292 * @adapter: board private structure
1296 e1000_clean_rx_ring(struct e1000_adapter
*adapter
)
1298 struct e1000_desc_ring
*rx_ring
= &adapter
->rx_ring
;
1299 struct e1000_buffer
*buffer_info
;
1300 struct pci_dev
*pdev
= adapter
->pdev
;
1304 /* Free all the Rx ring sk_buffs */
1306 for(i
= 0; i
< rx_ring
->count
; i
++) {
1307 buffer_info
= &rx_ring
->buffer_info
[i
];
1308 if(buffer_info
->skb
) {
1310 pci_unmap_single(pdev
,
1312 buffer_info
->length
,
1313 PCI_DMA_FROMDEVICE
);
1315 dev_kfree_skb(buffer_info
->skb
);
1316 buffer_info
->skb
= NULL
;
1320 size
= sizeof(struct e1000_buffer
) * rx_ring
->count
;
1321 memset(rx_ring
->buffer_info
, 0, size
);
1323 /* Zero out the descriptor ring */
1325 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1327 rx_ring
->next_to_clean
= 0;
1328 rx_ring
->next_to_use
= 0;
1330 E1000_WRITE_REG(&adapter
->hw
, RDH
, 0);
1331 E1000_WRITE_REG(&adapter
->hw
, RDT
, 0);
1334 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1335 * and memory write and invalidate disabled for certain operations
1338 e1000_enter_82542_rst(struct e1000_adapter
*adapter
)
1340 struct net_device
*netdev
= adapter
->netdev
;
1343 e1000_pci_clear_mwi(&adapter
->hw
);
1345 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1346 rctl
|= E1000_RCTL_RST
;
1347 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1348 E1000_WRITE_FLUSH(&adapter
->hw
);
1351 if(netif_running(netdev
))
1352 e1000_clean_rx_ring(adapter
);
1356 e1000_leave_82542_rst(struct e1000_adapter
*adapter
)
1358 struct net_device
*netdev
= adapter
->netdev
;
1361 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
1362 rctl
&= ~E1000_RCTL_RST
;
1363 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
1364 E1000_WRITE_FLUSH(&adapter
->hw
);
1367 if(adapter
->hw
.pci_cmd_word
& PCI_COMMAND_INVALIDATE
)
1368 e1000_pci_set_mwi(&adapter
->hw
);
1370 if(netif_running(netdev
)) {
1371 e1000_configure_rx(adapter
);
1372 e1000_alloc_rx_buffers(adapter
);
1377 * e1000_set_mac - Change the Ethernet Address of the NIC
1378 * @netdev: network interface device structure
1379 * @p: pointer to an address structure
1381 * Returns 0 on success, negative on failure
1385 e1000_set_mac(struct net_device
*netdev
, void *p
)
1387 struct e1000_adapter
*adapter
= netdev
->priv
;
1388 struct sockaddr
*addr
= p
;
1390 if(!is_valid_ether_addr(addr
->sa_data
))
1391 return -EADDRNOTAVAIL
;
1393 /* 82542 2.0 needs to be in reset to write receive address registers */
1395 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
1396 e1000_enter_82542_rst(adapter
);
1398 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
1399 memcpy(adapter
->hw
.mac_addr
, addr
->sa_data
, netdev
->addr_len
);
1401 e1000_rar_set(&adapter
->hw
, adapter
->hw
.mac_addr
, 0);
1403 if(adapter
->hw
.mac_type
== e1000_82542_rev2_0
)
1404 e1000_leave_82542_rst(adapter
);
1410 * e1000_set_multi - Multicast and Promiscuous mode set
1411 * @netdev: network interface device structure
1413 * The set_multi entry point is called whenever the multicast address
1414 * list or the network interface flags are updated. This routine is
1415 * responsible for configuring the hardware for proper multicast,
1416 * promiscuous mode, and all-multi behavior.
1420 e1000_set_multi(struct net_device
*netdev
)
1422 struct e1000_adapter
*adapter
= netdev
->priv
;
1423 struct e1000_hw
*hw
= &adapter
->hw
;
1424 struct dev_mc_list
*mc_ptr
;
1426 uint32_t hash_value
;
1428 unsigned long flags
;
1430 /* Check for Promiscuous and All Multicast modes */
1432 spin_lock_irqsave(&adapter
->tx_lock
, flags
);
1434 rctl
= E1000_READ_REG(hw
, RCTL
);
1436 if(netdev
->flags
& IFF_PROMISC
) {
1437 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
1438 } else if(netdev
->flags
& IFF_ALLMULTI
) {
1439 rctl
|= E1000_RCTL_MPE
;
1440 rctl
&= ~E1000_RCTL_UPE
;
1442 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
1445 E1000_WRITE_REG(hw
, RCTL
, rctl
);
1447 /* 82542 2.0 needs to be in reset to write receive address registers */
1449 if(hw
->mac_type
== e1000_82542_rev2_0
)
1450 e1000_enter_82542_rst(adapter
);
1452 /* load the first 14 multicast address into the exact filters 1-14
1453 * RAR 0 is used for the station MAC adddress
1454 * if there are not 14 addresses, go ahead and clear the filters
1456 mc_ptr
= netdev
->mc_list
;
1458 for(i
= 1; i
< E1000_RAR_ENTRIES
; i
++) {
1460 e1000_rar_set(hw
, mc_ptr
->dmi_addr
, i
);
1461 mc_ptr
= mc_ptr
->next
;
1463 E1000_WRITE_REG_ARRAY(hw
, RA
, i
<< 1, 0);
1464 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1) + 1, 0);
1468 /* clear the old settings from the multicast hash table */
1470 for(i
= 0; i
< E1000_NUM_MTA_REGISTERS
; i
++)
1471 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
1473 /* load any remaining addresses into the hash table */
1475 for(; mc_ptr
; mc_ptr
= mc_ptr
->next
) {
1476 hash_value
= e1000_hash_mc_addr(hw
, mc_ptr
->dmi_addr
);
1477 e1000_mta_set(hw
, hash_value
);
1480 if(hw
->mac_type
== e1000_82542_rev2_0
)
1481 e1000_leave_82542_rst(adapter
);
1483 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
1486 /* Need to wait a few seconds after link up to get diagnostic information from
1490 e1000_update_phy_info(unsigned long data
)
1492 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
1493 e1000_phy_get_info(&adapter
->hw
, &adapter
->phy_info
);
1497 * e1000_82547_tx_fifo_stall - Timer Call-back
1498 * @data: pointer to adapter cast into an unsigned long
1502 e1000_82547_tx_fifo_stall(unsigned long data
)
1504 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
1505 struct net_device
*netdev
= adapter
->netdev
;
1508 if(atomic_read(&adapter
->tx_fifo_stall
)) {
1509 if((E1000_READ_REG(&adapter
->hw
, TDT
) ==
1510 E1000_READ_REG(&adapter
->hw
, TDH
)) &&
1511 (E1000_READ_REG(&adapter
->hw
, TDFT
) ==
1512 E1000_READ_REG(&adapter
->hw
, TDFH
)) &&
1513 (E1000_READ_REG(&adapter
->hw
, TDFTS
) ==
1514 E1000_READ_REG(&adapter
->hw
, TDFHS
))) {
1515 tctl
= E1000_READ_REG(&adapter
->hw
, TCTL
);
1516 E1000_WRITE_REG(&adapter
->hw
, TCTL
,
1517 tctl
& ~E1000_TCTL_EN
);
1518 E1000_WRITE_REG(&adapter
->hw
, TDFT
,
1519 adapter
->tx_head_addr
);
1520 E1000_WRITE_REG(&adapter
->hw
, TDFH
,
1521 adapter
->tx_head_addr
);
1522 E1000_WRITE_REG(&adapter
->hw
, TDFTS
,
1523 adapter
->tx_head_addr
);
1524 E1000_WRITE_REG(&adapter
->hw
, TDFHS
,
1525 adapter
->tx_head_addr
);
1526 E1000_WRITE_REG(&adapter
->hw
, TCTL
, tctl
);
1527 E1000_WRITE_FLUSH(&adapter
->hw
);
1529 adapter
->tx_fifo_head
= 0;
1530 atomic_set(&adapter
->tx_fifo_stall
, 0);
1531 netif_wake_queue(netdev
);
1533 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
+ 1);
1539 * e1000_watchdog - Timer Call-back
1540 * @data: pointer to adapter cast into an unsigned long
1543 e1000_watchdog(unsigned long data
)
1545 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
1547 /* Do the rest outside of interrupt context */
1548 schedule_work(&adapter
->watchdog_task
);
1552 e1000_watchdog_task(struct e1000_adapter
*adapter
)
1554 struct net_device
*netdev
= adapter
->netdev
;
1555 struct e1000_desc_ring
*txdr
= &adapter
->tx_ring
;
1558 e1000_check_for_link(&adapter
->hw
);
1560 if((adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) &&
1561 !(E1000_READ_REG(&adapter
->hw
, TXCW
) & E1000_TXCW_ANE
))
1562 link
= !adapter
->hw
.serdes_link_down
;
1564 link
= E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_LU
;
1567 if(!netif_carrier_ok(netdev
)) {
1568 e1000_get_speed_and_duplex(&adapter
->hw
,
1569 &adapter
->link_speed
,
1570 &adapter
->link_duplex
);
1572 DPRINTK(LINK
, INFO
, "NIC Link is Up %d Mbps %s\n",
1573 adapter
->link_speed
,
1574 adapter
->link_duplex
== FULL_DUPLEX
?
1575 "Full Duplex" : "Half Duplex");
1577 netif_carrier_on(netdev
);
1578 netif_wake_queue(netdev
);
1579 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
1580 adapter
->smartspeed
= 0;
1583 if(netif_carrier_ok(netdev
)) {
1584 adapter
->link_speed
= 0;
1585 adapter
->link_duplex
= 0;
1586 DPRINTK(LINK
, INFO
, "NIC Link is Down\n");
1587 netif_carrier_off(netdev
);
1588 netif_stop_queue(netdev
);
1589 mod_timer(&adapter
->phy_info_timer
, jiffies
+ 2 * HZ
);
1592 e1000_smartspeed(adapter
);
1595 e1000_update_stats(adapter
);
1597 adapter
->hw
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
1598 adapter
->tpt_old
= adapter
->stats
.tpt
;
1599 adapter
->hw
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
1600 adapter
->colc_old
= adapter
->stats
.colc
;
1602 adapter
->gorcl
= adapter
->stats
.gorcl
- adapter
->gorcl_old
;
1603 adapter
->gorcl_old
= adapter
->stats
.gorcl
;
1604 adapter
->gotcl
= adapter
->stats
.gotcl
- adapter
->gotcl_old
;
1605 adapter
->gotcl_old
= adapter
->stats
.gotcl
;
1607 e1000_update_adaptive(&adapter
->hw
);
1609 if(!netif_carrier_ok(netdev
)) {
1610 if(E1000_DESC_UNUSED(txdr
) + 1 < txdr
->count
) {
1611 /* We've lost link, so the controller stops DMA,
1612 * but we've got queued Tx work that's never going
1613 * to get done, so reset controller to flush Tx.
1614 * (Do the reset outside of interrupt context). */
1615 schedule_work(&adapter
->tx_timeout_task
);
1619 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
1620 if(adapter
->hw
.mac_type
>= e1000_82540
&& adapter
->itr
== 1) {
1621 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
1622 * asymmetrical Tx or Rx gets ITR=8000; everyone
1623 * else is between 2000-8000. */
1624 uint32_t goc
= (adapter
->gotcl
+ adapter
->gorcl
) / 10000;
1625 uint32_t dif
= (adapter
->gotcl
> adapter
->gorcl
?
1626 adapter
->gotcl
- adapter
->gorcl
:
1627 adapter
->gorcl
- adapter
->gotcl
) / 10000;
1628 uint32_t itr
= goc
> 0 ? (dif
* 6000 / goc
+ 2000) : 8000;
1629 E1000_WRITE_REG(&adapter
->hw
, ITR
, 1000000000 / (itr
* 256));
1632 /* Cause software interrupt to ensure rx ring is cleaned */
1633 E1000_WRITE_REG(&adapter
->hw
, ICS
, E1000_ICS_RXDMT0
);
1635 /* Force detection of hung controller every watchdog period*/
1636 adapter
->detect_tx_hung
= TRUE
;
1638 /* Reset the timer */
1639 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2 * HZ
);
1642 #define E1000_TX_FLAGS_CSUM 0x00000001
1643 #define E1000_TX_FLAGS_VLAN 0x00000002
1644 #define E1000_TX_FLAGS_TSO 0x00000004
1645 #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
1646 #define E1000_TX_FLAGS_VLAN_SHIFT 16
1649 e1000_tso(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
1652 struct e1000_context_desc
*context_desc
;
1654 uint32_t cmd_length
= 0;
1655 uint16_t ipcse
, tucse
, mss
;
1656 uint8_t ipcss
, ipcso
, tucss
, tucso
, hdr_len
;
1659 if(skb_shinfo(skb
)->tso_size
) {
1660 if (skb_header_cloned(skb
)) {
1661 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
1666 hdr_len
= ((skb
->h
.raw
- skb
->data
) + (skb
->h
.th
->doff
<< 2));
1667 mss
= skb_shinfo(skb
)->tso_size
;
1668 skb
->nh
.iph
->tot_len
= 0;
1669 skb
->nh
.iph
->check
= 0;
1670 skb
->h
.th
->check
= ~csum_tcpudp_magic(skb
->nh
.iph
->saddr
,
1675 ipcss
= skb
->nh
.raw
- skb
->data
;
1676 ipcso
= (void *)&(skb
->nh
.iph
->check
) - (void *)skb
->data
;
1677 ipcse
= skb
->h
.raw
- skb
->data
- 1;
1678 tucss
= skb
->h
.raw
- skb
->data
;
1679 tucso
= (void *)&(skb
->h
.th
->check
) - (void *)skb
->data
;
1682 cmd_length
|= (E1000_TXD_CMD_DEXT
| E1000_TXD_CMD_TSE
|
1683 E1000_TXD_CMD_IP
| E1000_TXD_CMD_TCP
|
1684 (skb
->len
- (hdr_len
)));
1686 i
= adapter
->tx_ring
.next_to_use
;
1687 context_desc
= E1000_CONTEXT_DESC(adapter
->tx_ring
, i
);
1689 context_desc
->lower_setup
.ip_fields
.ipcss
= ipcss
;
1690 context_desc
->lower_setup
.ip_fields
.ipcso
= ipcso
;
1691 context_desc
->lower_setup
.ip_fields
.ipcse
= cpu_to_le16(ipcse
);
1692 context_desc
->upper_setup
.tcp_fields
.tucss
= tucss
;
1693 context_desc
->upper_setup
.tcp_fields
.tucso
= tucso
;
1694 context_desc
->upper_setup
.tcp_fields
.tucse
= cpu_to_le16(tucse
);
1695 context_desc
->tcp_seg_setup
.fields
.mss
= cpu_to_le16(mss
);
1696 context_desc
->tcp_seg_setup
.fields
.hdr_len
= hdr_len
;
1697 context_desc
->cmd_and_length
= cpu_to_le32(cmd_length
);
1699 if(++i
== adapter
->tx_ring
.count
) i
= 0;
1700 adapter
->tx_ring
.next_to_use
= i
;
1709 static inline boolean_t
1710 e1000_tx_csum(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
1712 struct e1000_context_desc
*context_desc
;
1716 if(likely(skb
->ip_summed
== CHECKSUM_HW
)) {
1717 css
= skb
->h
.raw
- skb
->data
;
1719 i
= adapter
->tx_ring
.next_to_use
;
1720 context_desc
= E1000_CONTEXT_DESC(adapter
->tx_ring
, i
);
1722 context_desc
->upper_setup
.tcp_fields
.tucss
= css
;
1723 context_desc
->upper_setup
.tcp_fields
.tucso
= css
+ skb
->csum
;
1724 context_desc
->upper_setup
.tcp_fields
.tucse
= 0;
1725 context_desc
->tcp_seg_setup
.data
= 0;
1726 context_desc
->cmd_and_length
= cpu_to_le32(E1000_TXD_CMD_DEXT
);
1728 if(unlikely(++i
== adapter
->tx_ring
.count
)) i
= 0;
1729 adapter
->tx_ring
.next_to_use
= i
;
1737 #define E1000_MAX_TXD_PWR 12
1738 #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
1741 e1000_tx_map(struct e1000_adapter
*adapter
, struct sk_buff
*skb
,
1742 unsigned int first
, unsigned int max_per_txd
,
1743 unsigned int nr_frags
, unsigned int mss
)
1745 struct e1000_desc_ring
*tx_ring
= &adapter
->tx_ring
;
1746 struct e1000_buffer
*buffer_info
;
1747 unsigned int len
= skb
->len
;
1748 unsigned int offset
= 0, size
, count
= 0, i
;
1750 len
-= skb
->data_len
;
1752 i
= tx_ring
->next_to_use
;
1755 buffer_info
= &tx_ring
->buffer_info
[i
];
1756 size
= min(len
, max_per_txd
);
1758 /* Workaround for premature desc write-backs
1759 * in TSO mode. Append 4-byte sentinel desc */
1760 if(unlikely(mss
&& !nr_frags
&& size
== len
&& size
> 8))
1763 /* Workaround for potential 82544 hang in PCI-X. Avoid
1764 * terminating buffers within evenly-aligned dwords. */
1765 if(unlikely(adapter
->pcix_82544
&&
1766 !((unsigned long)(skb
->data
+ offset
+ size
- 1) & 4) &&
1770 buffer_info
->length
= size
;
1772 pci_map_single(adapter
->pdev
,
1776 buffer_info
->time_stamp
= jiffies
;
1781 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
1784 for(f
= 0; f
< nr_frags
; f
++) {
1785 struct skb_frag_struct
*frag
;
1787 frag
= &skb_shinfo(skb
)->frags
[f
];
1789 offset
= frag
->page_offset
;
1792 buffer_info
= &tx_ring
->buffer_info
[i
];
1793 size
= min(len
, max_per_txd
);
1795 /* Workaround for premature desc write-backs
1796 * in TSO mode. Append 4-byte sentinel desc */
1797 if(unlikely(mss
&& f
== (nr_frags
-1) && size
== len
&& size
> 8))
1800 /* Workaround for potential 82544 hang in PCI-X.
1801 * Avoid terminating buffers within evenly-aligned
1803 if(unlikely(adapter
->pcix_82544
&&
1804 !((unsigned long)(frag
->page
+offset
+size
-1) & 4) &&
1808 buffer_info
->length
= size
;
1810 pci_map_page(adapter
->pdev
,
1815 buffer_info
->time_stamp
= jiffies
;
1820 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
1824 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
1825 tx_ring
->buffer_info
[i
].skb
= skb
;
1826 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
1832 e1000_tx_queue(struct e1000_adapter
*adapter
, int count
, int tx_flags
)
1834 struct e1000_desc_ring
*tx_ring
= &adapter
->tx_ring
;
1835 struct e1000_tx_desc
*tx_desc
= NULL
;
1836 struct e1000_buffer
*buffer_info
;
1837 uint32_t txd_upper
= 0, txd_lower
= E1000_TXD_CMD_IFCS
;
1840 if(likely(tx_flags
& E1000_TX_FLAGS_TSO
)) {
1841 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
|
1843 txd_upper
|= (E1000_TXD_POPTS_IXSM
| E1000_TXD_POPTS_TXSM
) << 8;
1846 if(likely(tx_flags
& E1000_TX_FLAGS_CSUM
)) {
1847 txd_lower
|= E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
;
1848 txd_upper
|= E1000_TXD_POPTS_TXSM
<< 8;
1851 if(unlikely(tx_flags
& E1000_TX_FLAGS_VLAN
)) {
1852 txd_lower
|= E1000_TXD_CMD_VLE
;
1853 txd_upper
|= (tx_flags
& E1000_TX_FLAGS_VLAN_MASK
);
1856 i
= tx_ring
->next_to_use
;
1859 buffer_info
= &tx_ring
->buffer_info
[i
];
1860 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
1861 tx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
1862 tx_desc
->lower
.data
=
1863 cpu_to_le32(txd_lower
| buffer_info
->length
);
1864 tx_desc
->upper
.data
= cpu_to_le32(txd_upper
);
1865 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
1868 tx_desc
->lower
.data
|= cpu_to_le32(adapter
->txd_cmd
);
1870 /* Force memory writes to complete before letting h/w
1871 * know there are new descriptors to fetch. (Only
1872 * applicable for weak-ordered memory model archs,
1873 * such as IA-64). */
1876 tx_ring
->next_to_use
= i
;
1877 E1000_WRITE_REG(&adapter
->hw
, TDT
, i
);
1881 * 82547 workaround to avoid controller hang in half-duplex environment.
1882 * The workaround is to avoid queuing a large packet that would span
1883 * the internal Tx FIFO ring boundary by notifying the stack to resend
1884 * the packet at a later time. This gives the Tx FIFO an opportunity to
1885 * flush all packets. When that occurs, we reset the Tx FIFO pointers
1886 * to the beginning of the Tx FIFO.
1889 #define E1000_FIFO_HDR 0x10
1890 #define E1000_82547_PAD_LEN 0x3E0
1893 e1000_82547_fifo_workaround(struct e1000_adapter
*adapter
, struct sk_buff
*skb
)
1895 uint32_t fifo_space
= adapter
->tx_fifo_size
- adapter
->tx_fifo_head
;
1896 uint32_t skb_fifo_len
= skb
->len
+ E1000_FIFO_HDR
;
1898 E1000_ROUNDUP(skb_fifo_len
, E1000_FIFO_HDR
);
1900 if(adapter
->link_duplex
!= HALF_DUPLEX
)
1901 goto no_fifo_stall_required
;
1903 if(atomic_read(&adapter
->tx_fifo_stall
))
1906 if(skb_fifo_len
>= (E1000_82547_PAD_LEN
+ fifo_space
)) {
1907 atomic_set(&adapter
->tx_fifo_stall
, 1);
1911 no_fifo_stall_required
:
1912 adapter
->tx_fifo_head
+= skb_fifo_len
;
1913 if(adapter
->tx_fifo_head
>= adapter
->tx_fifo_size
)
1914 adapter
->tx_fifo_head
-= adapter
->tx_fifo_size
;
1918 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
1920 e1000_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1922 struct e1000_adapter
*adapter
= netdev
->priv
;
1923 unsigned int first
, max_per_txd
= E1000_MAX_DATA_PER_TXD
;
1924 unsigned int max_txd_pwr
= E1000_MAX_TXD_PWR
;
1925 unsigned int tx_flags
= 0;
1926 unsigned int len
= skb
->len
;
1927 unsigned long flags
;
1928 unsigned int nr_frags
= 0;
1929 unsigned int mss
= 0;
1933 len
-= skb
->data_len
;
1935 if(unlikely(skb
->len
<= 0)) {
1936 dev_kfree_skb_any(skb
);
1937 return NETDEV_TX_OK
;
1941 mss
= skb_shinfo(skb
)->tso_size
;
1942 /* The controller does a simple calculation to
1943 * make sure there is enough room in the FIFO before
1944 * initiating the DMA for each buffer. The calc is:
1945 * 4 = ceil(buffer len/mss). To make sure we don't
1946 * overrun the FIFO, adjust the max buffer len if mss
1949 max_per_txd
= min(mss
<< 2, max_per_txd
);
1950 max_txd_pwr
= fls(max_per_txd
) - 1;
1953 if((mss
) || (skb
->ip_summed
== CHECKSUM_HW
))
1955 count
++; /* for sentinel desc */
1957 if(skb
->ip_summed
== CHECKSUM_HW
)
1960 count
+= TXD_USE_COUNT(len
, max_txd_pwr
);
1962 if(adapter
->pcix_82544
)
1965 nr_frags
= skb_shinfo(skb
)->nr_frags
;
1966 for(f
= 0; f
< nr_frags
; f
++)
1967 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
,
1969 if(adapter
->pcix_82544
)
1972 local_irq_save(flags
);
1973 if (!spin_trylock(&adapter
->tx_lock
)) {
1974 /* Collision - tell upper layer to requeue */
1975 local_irq_restore(flags
);
1976 return NETDEV_TX_LOCKED
;
1979 /* need: count + 2 desc gap to keep tail from touching
1980 * head, otherwise try next time */
1981 if(unlikely(E1000_DESC_UNUSED(&adapter
->tx_ring
) < count
+ 2)) {
1982 netif_stop_queue(netdev
);
1983 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
1984 return NETDEV_TX_BUSY
;
1987 if(unlikely(adapter
->hw
.mac_type
== e1000_82547
)) {
1988 if(unlikely(e1000_82547_fifo_workaround(adapter
, skb
))) {
1989 netif_stop_queue(netdev
);
1990 mod_timer(&adapter
->tx_fifo_stall_timer
, jiffies
);
1991 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
1992 return NETDEV_TX_BUSY
;
1996 if(unlikely(adapter
->vlgrp
&& vlan_tx_tag_present(skb
))) {
1997 tx_flags
|= E1000_TX_FLAGS_VLAN
;
1998 tx_flags
|= (vlan_tx_tag_get(skb
) << E1000_TX_FLAGS_VLAN_SHIFT
);
2001 first
= adapter
->tx_ring
.next_to_use
;
2003 tso
= e1000_tso(adapter
, skb
);
2005 dev_kfree_skb_any(skb
);
2006 return NETDEV_TX_OK
;
2010 tx_flags
|= E1000_TX_FLAGS_TSO
;
2011 else if(likely(e1000_tx_csum(adapter
, skb
)))
2012 tx_flags
|= E1000_TX_FLAGS_CSUM
;
2014 e1000_tx_queue(adapter
,
2015 e1000_tx_map(adapter
, skb
, first
, max_per_txd
, nr_frags
, mss
),
2018 netdev
->trans_start
= jiffies
;
2020 /* Make sure there is space in the ring for the next send. */
2021 if(unlikely(E1000_DESC_UNUSED(&adapter
->tx_ring
) < MAX_SKB_FRAGS
+ 2))
2022 netif_stop_queue(netdev
);
2024 spin_unlock_irqrestore(&adapter
->tx_lock
, flags
);
2025 return NETDEV_TX_OK
;
2029 * e1000_tx_timeout - Respond to a Tx Hang
2030 * @netdev: network interface device structure
2034 e1000_tx_timeout(struct net_device
*netdev
)
2036 struct e1000_adapter
*adapter
= netdev
->priv
;
2038 /* Do the reset outside of interrupt context */
2039 schedule_work(&adapter
->tx_timeout_task
);
2043 e1000_tx_timeout_task(struct net_device
*netdev
)
2045 struct e1000_adapter
*adapter
= netdev
->priv
;
2047 e1000_down(adapter
);
2052 * e1000_get_stats - Get System Network Statistics
2053 * @netdev: network interface device structure
2055 * Returns the address of the device statistics structure.
2056 * The statistics are actually updated from the timer callback.
2059 static struct net_device_stats
*
2060 e1000_get_stats(struct net_device
*netdev
)
2062 struct e1000_adapter
*adapter
= netdev
->priv
;
2064 e1000_update_stats(adapter
);
2065 return &adapter
->net_stats
;
2069 * e1000_change_mtu - Change the Maximum Transfer Unit
2070 * @netdev: network interface device structure
2071 * @new_mtu: new value for maximum frame size
2073 * Returns 0 on success, negative on failure
2077 e1000_change_mtu(struct net_device
*netdev
, int new_mtu
)
2079 struct e1000_adapter
*adapter
= netdev
->priv
;
2080 int old_mtu
= adapter
->rx_buffer_len
;
2081 int max_frame
= new_mtu
+ ENET_HEADER_SIZE
+ ETHERNET_FCS_SIZE
;
2083 if((max_frame
< MINIMUM_ETHERNET_FRAME_SIZE
) ||
2084 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
2085 DPRINTK(PROBE
, ERR
, "Invalid MTU setting\n");
2089 if(max_frame
<= MAXIMUM_ETHERNET_FRAME_SIZE
) {
2090 adapter
->rx_buffer_len
= E1000_RXBUFFER_2048
;
2092 } else if(adapter
->hw
.mac_type
< e1000_82543
) {
2093 DPRINTK(PROBE
, ERR
, "Jumbo Frames not supported on 82542\n");
2096 } else if(max_frame
<= E1000_RXBUFFER_4096
) {
2097 adapter
->rx_buffer_len
= E1000_RXBUFFER_4096
;
2099 } else if(max_frame
<= E1000_RXBUFFER_8192
) {
2100 adapter
->rx_buffer_len
= E1000_RXBUFFER_8192
;
2103 adapter
->rx_buffer_len
= E1000_RXBUFFER_16384
;
2106 if(old_mtu
!= adapter
->rx_buffer_len
&& netif_running(netdev
)) {
2107 e1000_down(adapter
);
2111 netdev
->mtu
= new_mtu
;
2112 adapter
->hw
.max_frame_size
= max_frame
;
2118 * e1000_update_stats - Update the board statistics counters
2119 * @adapter: board private structure
2123 e1000_update_stats(struct e1000_adapter
*adapter
)
2125 struct e1000_hw
*hw
= &adapter
->hw
;
2126 unsigned long flags
;
2129 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2131 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
2133 /* these counters are modified from e1000_adjust_tbi_stats,
2134 * called from the interrupt context, so they must only
2135 * be written while holding adapter->stats_lock
2138 adapter
->stats
.crcerrs
+= E1000_READ_REG(hw
, CRCERRS
);
2139 adapter
->stats
.gprc
+= E1000_READ_REG(hw
, GPRC
);
2140 adapter
->stats
.gorcl
+= E1000_READ_REG(hw
, GORCL
);
2141 adapter
->stats
.gorch
+= E1000_READ_REG(hw
, GORCH
);
2142 adapter
->stats
.bprc
+= E1000_READ_REG(hw
, BPRC
);
2143 adapter
->stats
.mprc
+= E1000_READ_REG(hw
, MPRC
);
2144 adapter
->stats
.roc
+= E1000_READ_REG(hw
, ROC
);
2145 adapter
->stats
.prc64
+= E1000_READ_REG(hw
, PRC64
);
2146 adapter
->stats
.prc127
+= E1000_READ_REG(hw
, PRC127
);
2147 adapter
->stats
.prc255
+= E1000_READ_REG(hw
, PRC255
);
2148 adapter
->stats
.prc511
+= E1000_READ_REG(hw
, PRC511
);
2149 adapter
->stats
.prc1023
+= E1000_READ_REG(hw
, PRC1023
);
2150 adapter
->stats
.prc1522
+= E1000_READ_REG(hw
, PRC1522
);
2152 adapter
->stats
.symerrs
+= E1000_READ_REG(hw
, SYMERRS
);
2153 adapter
->stats
.mpc
+= E1000_READ_REG(hw
, MPC
);
2154 adapter
->stats
.scc
+= E1000_READ_REG(hw
, SCC
);
2155 adapter
->stats
.ecol
+= E1000_READ_REG(hw
, ECOL
);
2156 adapter
->stats
.mcc
+= E1000_READ_REG(hw
, MCC
);
2157 adapter
->stats
.latecol
+= E1000_READ_REG(hw
, LATECOL
);
2158 adapter
->stats
.dc
+= E1000_READ_REG(hw
, DC
);
2159 adapter
->stats
.sec
+= E1000_READ_REG(hw
, SEC
);
2160 adapter
->stats
.rlec
+= E1000_READ_REG(hw
, RLEC
);
2161 adapter
->stats
.xonrxc
+= E1000_READ_REG(hw
, XONRXC
);
2162 adapter
->stats
.xontxc
+= E1000_READ_REG(hw
, XONTXC
);
2163 adapter
->stats
.xoffrxc
+= E1000_READ_REG(hw
, XOFFRXC
);
2164 adapter
->stats
.xofftxc
+= E1000_READ_REG(hw
, XOFFTXC
);
2165 adapter
->stats
.fcruc
+= E1000_READ_REG(hw
, FCRUC
);
2166 adapter
->stats
.gptc
+= E1000_READ_REG(hw
, GPTC
);
2167 adapter
->stats
.gotcl
+= E1000_READ_REG(hw
, GOTCL
);
2168 adapter
->stats
.gotch
+= E1000_READ_REG(hw
, GOTCH
);
2169 adapter
->stats
.rnbc
+= E1000_READ_REG(hw
, RNBC
);
2170 adapter
->stats
.ruc
+= E1000_READ_REG(hw
, RUC
);
2171 adapter
->stats
.rfc
+= E1000_READ_REG(hw
, RFC
);
2172 adapter
->stats
.rjc
+= E1000_READ_REG(hw
, RJC
);
2173 adapter
->stats
.torl
+= E1000_READ_REG(hw
, TORL
);
2174 adapter
->stats
.torh
+= E1000_READ_REG(hw
, TORH
);
2175 adapter
->stats
.totl
+= E1000_READ_REG(hw
, TOTL
);
2176 adapter
->stats
.toth
+= E1000_READ_REG(hw
, TOTH
);
2177 adapter
->stats
.tpr
+= E1000_READ_REG(hw
, TPR
);
2178 adapter
->stats
.ptc64
+= E1000_READ_REG(hw
, PTC64
);
2179 adapter
->stats
.ptc127
+= E1000_READ_REG(hw
, PTC127
);
2180 adapter
->stats
.ptc255
+= E1000_READ_REG(hw
, PTC255
);
2181 adapter
->stats
.ptc511
+= E1000_READ_REG(hw
, PTC511
);
2182 adapter
->stats
.ptc1023
+= E1000_READ_REG(hw
, PTC1023
);
2183 adapter
->stats
.ptc1522
+= E1000_READ_REG(hw
, PTC1522
);
2184 adapter
->stats
.mptc
+= E1000_READ_REG(hw
, MPTC
);
2185 adapter
->stats
.bptc
+= E1000_READ_REG(hw
, BPTC
);
2187 /* used for adaptive IFS */
2189 hw
->tx_packet_delta
= E1000_READ_REG(hw
, TPT
);
2190 adapter
->stats
.tpt
+= hw
->tx_packet_delta
;
2191 hw
->collision_delta
= E1000_READ_REG(hw
, COLC
);
2192 adapter
->stats
.colc
+= hw
->collision_delta
;
2194 if(hw
->mac_type
>= e1000_82543
) {
2195 adapter
->stats
.algnerrc
+= E1000_READ_REG(hw
, ALGNERRC
);
2196 adapter
->stats
.rxerrc
+= E1000_READ_REG(hw
, RXERRC
);
2197 adapter
->stats
.tncrs
+= E1000_READ_REG(hw
, TNCRS
);
2198 adapter
->stats
.cexterr
+= E1000_READ_REG(hw
, CEXTERR
);
2199 adapter
->stats
.tsctc
+= E1000_READ_REG(hw
, TSCTC
);
2200 adapter
->stats
.tsctfc
+= E1000_READ_REG(hw
, TSCTFC
);
2203 /* Fill out the OS statistics structure */
2205 adapter
->net_stats
.rx_packets
= adapter
->stats
.gprc
;
2206 adapter
->net_stats
.tx_packets
= adapter
->stats
.gptc
;
2207 adapter
->net_stats
.rx_bytes
= adapter
->stats
.gorcl
;
2208 adapter
->net_stats
.tx_bytes
= adapter
->stats
.gotcl
;
2209 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
2210 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
2214 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
2215 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
2216 adapter
->stats
.rlec
+ adapter
->stats
.rnbc
+
2217 adapter
->stats
.mpc
+ adapter
->stats
.cexterr
;
2218 adapter
->net_stats
.rx_dropped
= adapter
->stats
.rnbc
;
2219 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.rlec
;
2220 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
2221 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
2222 adapter
->net_stats
.rx_fifo_errors
= adapter
->stats
.mpc
;
2223 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
2227 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
2228 adapter
->stats
.latecol
;
2229 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
2230 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
2231 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
2233 /* Tx Dropped needs to be maintained elsewhere */
2237 if(hw
->media_type
== e1000_media_type_copper
) {
2238 if((adapter
->link_speed
== SPEED_1000
) &&
2239 (!e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
2240 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
2241 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
2244 if((hw
->mac_type
<= e1000_82546
) &&
2245 (hw
->phy_type
== e1000_phy_m88
) &&
2246 !e1000_read_phy_reg(hw
, M88E1000_RX_ERR_CNTR
, &phy_tmp
))
2247 adapter
->phy_stats
.receive_errors
+= phy_tmp
;
2250 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
2254 * e1000_intr - Interrupt Handler
2255 * @irq: interrupt number
2256 * @data: pointer to a network interface device structure
2257 * @pt_regs: CPU registers structure
2261 e1000_intr(int irq
, void *data
, struct pt_regs
*regs
)
2263 struct net_device
*netdev
= data
;
2264 struct e1000_adapter
*adapter
= netdev
->priv
;
2265 struct e1000_hw
*hw
= &adapter
->hw
;
2266 uint32_t icr
= E1000_READ_REG(hw
, ICR
);
2267 #ifndef CONFIG_E1000_NAPI
2272 return IRQ_NONE
; /* Not our interrupt */
2274 if(unlikely(icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
))) {
2275 hw
->get_link_status
= 1;
2276 mod_timer(&adapter
->watchdog_timer
, jiffies
);
2279 #ifdef CONFIG_E1000_NAPI
2280 if(likely(netif_rx_schedule_prep(netdev
))) {
2282 /* Disable interrupts and register for poll. The flush
2283 of the posted write is intentionally left out.
2286 atomic_inc(&adapter
->irq_sem
);
2287 E1000_WRITE_REG(hw
, IMC
, ~0);
2288 __netif_rx_schedule(netdev
);
2291 /* Writing IMC and IMS is needed for 82547.
2292 Due to Hub Link bus being occupied, an interrupt
2293 de-assertion message is not able to be sent.
2294 When an interrupt assertion message is generated later,
2295 two messages are re-ordered and sent out.
2296 That causes APIC to think 82547 is in de-assertion
2297 state, while 82547 is in assertion state, resulting
2298 in dead lock. Writing IMC forces 82547 into
2301 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
){
2302 atomic_inc(&adapter
->irq_sem
);
2303 E1000_WRITE_REG(&adapter
->hw
, IMC
, ~0);
2306 for(i
= 0; i
< E1000_MAX_INTR
; i
++)
2307 if(unlikely(!e1000_clean_rx_irq(adapter
) &
2308 !e1000_clean_tx_irq(adapter
)))
2311 if(hw
->mac_type
== e1000_82547
|| hw
->mac_type
== e1000_82547_rev_2
)
2312 e1000_irq_enable(adapter
);
2318 #ifdef CONFIG_E1000_NAPI
2320 * e1000_clean - NAPI Rx polling callback
2321 * @adapter: board private structure
2325 e1000_clean(struct net_device
*netdev
, int *budget
)
2327 struct e1000_adapter
*adapter
= netdev
->priv
;
2328 int work_to_do
= min(*budget
, netdev
->quota
);
2332 tx_cleaned
= e1000_clean_tx_irq(adapter
);
2333 e1000_clean_rx_irq(adapter
, &work_done
, work_to_do
);
2335 *budget
-= work_done
;
2336 netdev
->quota
-= work_done
;
2338 /* if no Tx and not enough Rx work done, exit the polling mode */
2339 if((!tx_cleaned
&& (work_done
< work_to_do
)) ||
2340 !netif_running(netdev
)) {
2341 netif_rx_complete(netdev
);
2342 e1000_irq_enable(adapter
);
2351 * e1000_clean_tx_irq - Reclaim resources after transmit completes
2352 * @adapter: board private structure
2356 e1000_clean_tx_irq(struct e1000_adapter
*adapter
)
2358 struct e1000_desc_ring
*tx_ring
= &adapter
->tx_ring
;
2359 struct net_device
*netdev
= adapter
->netdev
;
2360 struct e1000_tx_desc
*tx_desc
, *eop_desc
;
2361 struct e1000_buffer
*buffer_info
;
2362 unsigned int i
, eop
;
2363 boolean_t cleaned
= FALSE
;
2365 i
= tx_ring
->next_to_clean
;
2366 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
2367 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
2369 while(eop_desc
->upper
.data
& cpu_to_le32(E1000_TXD_STAT_DD
)) {
2370 /* pre-mature writeback of Tx descriptors */
2371 /* clear (free buffers and unmap pci_mapping) */
2372 /* previous_buffer_info */
2373 if (likely(adapter
->previous_buffer_info
.skb
!= NULL
)) {
2374 e1000_unmap_and_free_tx_resource(adapter
,
2375 &adapter
->previous_buffer_info
);
2378 for(cleaned
= FALSE
; !cleaned
; ) {
2379 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
2380 buffer_info
= &tx_ring
->buffer_info
[i
];
2381 cleaned
= (i
== eop
);
2383 /* pre-mature writeback of Tx descriptors */
2384 /* save the cleaning of the this for the */
2385 /* next iteration */
2387 memcpy(&adapter
->previous_buffer_info
,
2389 sizeof(struct e1000_buffer
));
2392 sizeof(struct e1000_buffer
));
2394 e1000_unmap_and_free_tx_resource(adapter
,
2398 tx_desc
->buffer_addr
= 0;
2399 tx_desc
->lower
.data
= 0;
2400 tx_desc
->upper
.data
= 0;
2402 cleaned
= (i
== eop
);
2403 if(unlikely(++i
== tx_ring
->count
)) i
= 0;
2406 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
2407 eop_desc
= E1000_TX_DESC(*tx_ring
, eop
);
2410 tx_ring
->next_to_clean
= i
;
2412 spin_lock(&adapter
->tx_lock
);
2414 if(unlikely(cleaned
&& netif_queue_stopped(netdev
) &&
2415 netif_carrier_ok(netdev
)))
2416 netif_wake_queue(netdev
);
2418 spin_unlock(&adapter
->tx_lock
);
2420 if(adapter
->detect_tx_hung
) {
2421 /* detect a transmit hang in hardware, this serializes the
2422 * check with the clearing of time_stamp and movement of i */
2423 adapter
->detect_tx_hung
= FALSE
;
2424 if(tx_ring
->buffer_info
[i
].dma
&&
2425 time_after(jiffies
, tx_ring
->buffer_info
[i
].time_stamp
+ HZ
) &&
2426 !(E1000_READ_REG(&adapter
->hw
, STATUS
) & E1000_STATUS_TXOFF
))
2427 netif_stop_queue(netdev
);
2434 * e1000_rx_checksum - Receive Checksum Offload for 82543
2435 * @adapter: board private structure
2436 * @rx_desc: receive descriptor
2437 * @sk_buff: socket buffer with received data
2441 e1000_rx_checksum(struct e1000_adapter
*adapter
,
2442 struct e1000_rx_desc
*rx_desc
,
2443 struct sk_buff
*skb
)
2445 /* 82543 or newer only */
2446 if(unlikely((adapter
->hw
.mac_type
< e1000_82543
) ||
2447 /* Ignore Checksum bit is set */
2448 (rx_desc
->status
& E1000_RXD_STAT_IXSM
) ||
2449 /* TCP Checksum has not been calculated */
2450 (!(rx_desc
->status
& E1000_RXD_STAT_TCPCS
)))) {
2451 skb
->ip_summed
= CHECKSUM_NONE
;
2455 /* At this point we know the hardware did the TCP checksum */
2456 /* now look at the TCP checksum error bit */
2457 if(rx_desc
->errors
& E1000_RXD_ERR_TCPE
) {
2458 /* let the stack verify checksum errors */
2459 skb
->ip_summed
= CHECKSUM_NONE
;
2460 adapter
->hw_csum_err
++;
2462 /* TCP checksum is good */
2463 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2464 adapter
->hw_csum_good
++;
2469 * e1000_clean_rx_irq - Send received data up the network stack
2470 * @adapter: board private structure
2474 #ifdef CONFIG_E1000_NAPI
2475 e1000_clean_rx_irq(struct e1000_adapter
*adapter
, int *work_done
,
2478 e1000_clean_rx_irq(struct e1000_adapter
*adapter
)
2481 struct e1000_desc_ring
*rx_ring
= &adapter
->rx_ring
;
2482 struct net_device
*netdev
= adapter
->netdev
;
2483 struct pci_dev
*pdev
= adapter
->pdev
;
2484 struct e1000_rx_desc
*rx_desc
;
2485 struct e1000_buffer
*buffer_info
;
2486 struct sk_buff
*skb
;
2487 unsigned long flags
;
2491 boolean_t cleaned
= FALSE
;
2493 i
= rx_ring
->next_to_clean
;
2494 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
2496 while(rx_desc
->status
& E1000_RXD_STAT_DD
) {
2497 buffer_info
= &rx_ring
->buffer_info
[i
];
2498 #ifdef CONFIG_E1000_NAPI
2499 if(*work_done
>= work_to_do
)
2505 pci_unmap_single(pdev
,
2507 buffer_info
->length
,
2508 PCI_DMA_FROMDEVICE
);
2510 skb
= buffer_info
->skb
;
2511 length
= le16_to_cpu(rx_desc
->length
);
2513 if(unlikely(!(rx_desc
->status
& E1000_RXD_STAT_EOP
))) {
2514 /* All receives must fit into a single buffer */
2515 E1000_DBG("%s: Receive packet consumed multiple"
2516 " buffers\n", netdev
->name
);
2517 dev_kfree_skb_irq(skb
);
2521 if(unlikely(rx_desc
->errors
& E1000_RXD_ERR_FRAME_ERR_MASK
)) {
2522 last_byte
= *(skb
->data
+ length
- 1);
2523 if(TBI_ACCEPT(&adapter
->hw
, rx_desc
->status
,
2524 rx_desc
->errors
, length
, last_byte
)) {
2525 spin_lock_irqsave(&adapter
->stats_lock
, flags
);
2526 e1000_tbi_adjust_stats(&adapter
->hw
,
2529 spin_unlock_irqrestore(&adapter
->stats_lock
,
2533 dev_kfree_skb_irq(skb
);
2539 skb_put(skb
, length
- ETHERNET_FCS_SIZE
);
2541 /* Receive Checksum Offload */
2542 e1000_rx_checksum(adapter
, rx_desc
, skb
);
2544 skb
->protocol
= eth_type_trans(skb
, netdev
);
2545 #ifdef CONFIG_E1000_NAPI
2546 if(unlikely(adapter
->vlgrp
&&
2547 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
2548 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
2549 le16_to_cpu(rx_desc
->special
) &
2550 E1000_RXD_SPC_VLAN_MASK
);
2552 netif_receive_skb(skb
);
2554 #else /* CONFIG_E1000_NAPI */
2555 if(unlikely(adapter
->vlgrp
&&
2556 (rx_desc
->status
& E1000_RXD_STAT_VP
))) {
2557 vlan_hwaccel_rx(skb
, adapter
->vlgrp
,
2558 le16_to_cpu(rx_desc
->special
) &
2559 E1000_RXD_SPC_VLAN_MASK
);
2563 #endif /* CONFIG_E1000_NAPI */
2564 netdev
->last_rx
= jiffies
;
2567 rx_desc
->status
= 0;
2568 buffer_info
->skb
= NULL
;
2569 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
2571 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
2574 rx_ring
->next_to_clean
= i
;
2576 e1000_alloc_rx_buffers(adapter
);
2582 * e1000_alloc_rx_buffers - Replace used receive buffers
2583 * @adapter: address of board private structure
2587 e1000_alloc_rx_buffers(struct e1000_adapter
*adapter
)
2589 struct e1000_desc_ring
*rx_ring
= &adapter
->rx_ring
;
2590 struct net_device
*netdev
= adapter
->netdev
;
2591 struct pci_dev
*pdev
= adapter
->pdev
;
2592 struct e1000_rx_desc
*rx_desc
;
2593 struct e1000_buffer
*buffer_info
;
2594 struct sk_buff
*skb
;
2595 unsigned int i
, bufsz
;
2597 i
= rx_ring
->next_to_use
;
2598 buffer_info
= &rx_ring
->buffer_info
[i
];
2600 while(!buffer_info
->skb
) {
2601 bufsz
= adapter
->rx_buffer_len
+ NET_IP_ALIGN
;
2603 skb
= dev_alloc_skb(bufsz
);
2604 if(unlikely(!skb
)) {
2605 /* Better luck next round */
2609 /* fix for errata 23, cant cross 64kB boundary */
2610 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
2611 struct sk_buff
*oldskb
= skb
;
2613 "skb align check failed: %u bytes at %p\n",
2615 /* try again, without freeing the previous */
2616 skb
= dev_alloc_skb(bufsz
);
2618 dev_kfree_skb(oldskb
);
2621 if (!e1000_check_64k_bound(adapter
, skb
->data
, bufsz
)) {
2624 dev_kfree_skb(oldskb
);
2625 break; /* while !buffer_info->skb */
2627 /* move on with the new one */
2628 dev_kfree_skb(oldskb
);
2632 /* Make buffer alignment 2 beyond a 16 byte boundary
2633 * this will result in a 16 byte aligned IP header after
2634 * the 14 byte MAC header is removed
2636 skb_reserve(skb
, NET_IP_ALIGN
);
2640 buffer_info
->skb
= skb
;
2641 buffer_info
->length
= adapter
->rx_buffer_len
;
2642 buffer_info
->dma
= pci_map_single(pdev
,
2644 adapter
->rx_buffer_len
,
2645 PCI_DMA_FROMDEVICE
);
2647 /* fix for errata 23, cant cross 64kB boundary */
2648 if(!e1000_check_64k_bound(adapter
,
2649 (void *)(unsigned long)buffer_info
->dma
,
2650 adapter
->rx_buffer_len
)) {
2652 "dma align check failed: %u bytes at %ld\n",
2653 adapter
->rx_buffer_len
, (unsigned long)buffer_info
->dma
);
2656 buffer_info
->skb
= NULL
;
2658 pci_unmap_single(pdev
,
2660 adapter
->rx_buffer_len
,
2661 PCI_DMA_FROMDEVICE
);
2663 break; /* while !buffer_info->skb */
2666 rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
2667 rx_desc
->buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2669 if(unlikely((i
& ~(E1000_RX_BUFFER_WRITE
- 1)) == i
)) {
2670 /* Force memory writes to complete before letting h/w
2671 * know there are new descriptors to fetch. (Only
2672 * applicable for weak-ordered memory model archs,
2673 * such as IA-64). */
2676 E1000_WRITE_REG(&adapter
->hw
, RDT
, i
);
2679 if(unlikely(++i
== rx_ring
->count
)) i
= 0;
2680 buffer_info
= &rx_ring
->buffer_info
[i
];
2683 rx_ring
->next_to_use
= i
;
2687 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
2692 e1000_smartspeed(struct e1000_adapter
*adapter
)
2694 uint16_t phy_status
;
2697 if((adapter
->hw
.phy_type
!= e1000_phy_igp
) || !adapter
->hw
.autoneg
||
2698 !(adapter
->hw
.autoneg_advertised
& ADVERTISE_1000_FULL
))
2701 if(adapter
->smartspeed
== 0) {
2702 /* If Master/Slave config fault is asserted twice,
2703 * we assume back-to-back */
2704 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
2705 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
2706 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_STATUS
, &phy_status
);
2707 if(!(phy_status
& SR_1000T_MS_CONFIG_FAULT
)) return;
2708 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
2709 if(phy_ctrl
& CR_1000T_MS_ENABLE
) {
2710 phy_ctrl
&= ~CR_1000T_MS_ENABLE
;
2711 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
,
2713 adapter
->smartspeed
++;
2714 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
2715 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
,
2717 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
2718 MII_CR_RESTART_AUTO_NEG
);
2719 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
,
2724 } else if(adapter
->smartspeed
== E1000_SMARTSPEED_DOWNSHIFT
) {
2725 /* If still no link, perhaps using 2/3 pair cable */
2726 e1000_read_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, &phy_ctrl
);
2727 phy_ctrl
|= CR_1000T_MS_ENABLE
;
2728 e1000_write_phy_reg(&adapter
->hw
, PHY_1000T_CTRL
, phy_ctrl
);
2729 if(!e1000_phy_setup_autoneg(&adapter
->hw
) &&
2730 !e1000_read_phy_reg(&adapter
->hw
, PHY_CTRL
, &phy_ctrl
)) {
2731 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
|
2732 MII_CR_RESTART_AUTO_NEG
);
2733 e1000_write_phy_reg(&adapter
->hw
, PHY_CTRL
, phy_ctrl
);
2736 /* Restart process after E1000_SMARTSPEED_MAX iterations */
2737 if(adapter
->smartspeed
++ == E1000_SMARTSPEED_MAX
)
2738 adapter
->smartspeed
= 0;
2749 e1000_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
2755 return e1000_mii_ioctl(netdev
, ifr
, cmd
);
2769 e1000_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
2771 struct e1000_adapter
*adapter
= netdev
->priv
;
2772 struct mii_ioctl_data
*data
= if_mii(ifr
);
2777 if(adapter
->hw
.media_type
!= e1000_media_type_copper
)
2782 data
->phy_id
= adapter
->hw
.phy_addr
;
2785 if (!capable(CAP_NET_ADMIN
))
2787 if (e1000_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
2792 if (!capable(CAP_NET_ADMIN
))
2794 if (data
->reg_num
& ~(0x1F))
2796 mii_reg
= data
->val_in
;
2797 if (e1000_write_phy_reg(&adapter
->hw
, data
->reg_num
,
2800 if (adapter
->hw
.phy_type
== e1000_phy_m88
) {
2801 switch (data
->reg_num
) {
2803 if(mii_reg
& MII_CR_POWER_DOWN
)
2805 if(mii_reg
& MII_CR_AUTO_NEG_EN
) {
2806 adapter
->hw
.autoneg
= 1;
2807 adapter
->hw
.autoneg_advertised
= 0x2F;
2810 spddplx
= SPEED_1000
;
2811 else if (mii_reg
& 0x2000)
2812 spddplx
= SPEED_100
;
2815 spddplx
+= (mii_reg
& 0x100)
2818 retval
= e1000_set_spd_dplx(adapter
,
2823 if(netif_running(adapter
->netdev
)) {
2824 e1000_down(adapter
);
2827 e1000_reset(adapter
);
2829 case M88E1000_PHY_SPEC_CTRL
:
2830 case M88E1000_EXT_PHY_SPEC_CTRL
:
2831 if (e1000_phy_reset(&adapter
->hw
))
2836 switch (data
->reg_num
) {
2838 if(mii_reg
& MII_CR_POWER_DOWN
)
2840 if(netif_running(adapter
->netdev
)) {
2841 e1000_down(adapter
);
2844 e1000_reset(adapter
);
2852 return E1000_SUCCESS
;
2856 e1000_pci_set_mwi(struct e1000_hw
*hw
)
2858 struct e1000_adapter
*adapter
= hw
->back
;
2861 ret
= pci_set_mwi(adapter
->pdev
);
2865 e1000_pci_clear_mwi(struct e1000_hw
*hw
)
2867 struct e1000_adapter
*adapter
= hw
->back
;
2869 pci_clear_mwi(adapter
->pdev
);
2873 e1000_read_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
2875 struct e1000_adapter
*adapter
= hw
->back
;
2877 pci_read_config_word(adapter
->pdev
, reg
, value
);
2881 e1000_write_pci_cfg(struct e1000_hw
*hw
, uint32_t reg
, uint16_t *value
)
2883 struct e1000_adapter
*adapter
= hw
->back
;
2885 pci_write_config_word(adapter
->pdev
, reg
, *value
);
2889 e1000_io_read(struct e1000_hw
*hw
, unsigned long port
)
2895 e1000_io_write(struct e1000_hw
*hw
, unsigned long port
, uint32_t value
)
2901 e1000_vlan_rx_register(struct net_device
*netdev
, struct vlan_group
*grp
)
2903 struct e1000_adapter
*adapter
= netdev
->priv
;
2904 uint32_t ctrl
, rctl
;
2906 e1000_irq_disable(adapter
);
2907 adapter
->vlgrp
= grp
;
2910 /* enable VLAN tag insert/strip */
2911 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
2912 ctrl
|= E1000_CTRL_VME
;
2913 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
2915 /* enable VLAN receive filtering */
2916 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2917 rctl
|= E1000_RCTL_VFE
;
2918 rctl
&= ~E1000_RCTL_CFIEN
;
2919 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2921 /* disable VLAN tag insert/strip */
2922 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
2923 ctrl
&= ~E1000_CTRL_VME
;
2924 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
2926 /* disable VLAN filtering */
2927 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
2928 rctl
&= ~E1000_RCTL_VFE
;
2929 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
2932 e1000_irq_enable(adapter
);
2936 e1000_vlan_rx_add_vid(struct net_device
*netdev
, uint16_t vid
)
2938 struct e1000_adapter
*adapter
= netdev
->priv
;
2939 uint32_t vfta
, index
;
2941 /* add VID to filter table */
2942 index
= (vid
>> 5) & 0x7F;
2943 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
2944 vfta
|= (1 << (vid
& 0x1F));
2945 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
2949 e1000_vlan_rx_kill_vid(struct net_device
*netdev
, uint16_t vid
)
2951 struct e1000_adapter
*adapter
= netdev
->priv
;
2952 uint32_t vfta
, index
;
2954 e1000_irq_disable(adapter
);
2957 adapter
->vlgrp
->vlan_devices
[vid
] = NULL
;
2959 e1000_irq_enable(adapter
);
2961 /* remove VID from filter table */
2962 index
= (vid
>> 5) & 0x7F;
2963 vfta
= E1000_READ_REG_ARRAY(&adapter
->hw
, VFTA
, index
);
2964 vfta
&= ~(1 << (vid
& 0x1F));
2965 e1000_write_vfta(&adapter
->hw
, index
, vfta
);
2969 e1000_restore_vlan(struct e1000_adapter
*adapter
)
2971 e1000_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
2973 if(adapter
->vlgrp
) {
2975 for(vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
2976 if(!adapter
->vlgrp
->vlan_devices
[vid
])
2978 e1000_vlan_rx_add_vid(adapter
->netdev
, vid
);
2984 e1000_set_spd_dplx(struct e1000_adapter
*adapter
, uint16_t spddplx
)
2986 adapter
->hw
.autoneg
= 0;
2989 case SPEED_10
+ DUPLEX_HALF
:
2990 adapter
->hw
.forced_speed_duplex
= e1000_10_half
;
2992 case SPEED_10
+ DUPLEX_FULL
:
2993 adapter
->hw
.forced_speed_duplex
= e1000_10_full
;
2995 case SPEED_100
+ DUPLEX_HALF
:
2996 adapter
->hw
.forced_speed_duplex
= e1000_100_half
;
2998 case SPEED_100
+ DUPLEX_FULL
:
2999 adapter
->hw
.forced_speed_duplex
= e1000_100_full
;
3001 case SPEED_1000
+ DUPLEX_FULL
:
3002 adapter
->hw
.autoneg
= 1;
3003 adapter
->hw
.autoneg_advertised
= ADVERTISE_1000_FULL
;
3005 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
3008 "Unsupported Speed/Duplexity configuration\n");
3015 e1000_notify_reboot(struct notifier_block
*nb
, unsigned long event
, void *p
)
3017 struct pci_dev
*pdev
= NULL
;
3023 while((pdev
= pci_find_device(PCI_ANY_ID
, PCI_ANY_ID
, pdev
))) {
3024 if(pci_dev_driver(pdev
) == &e1000_driver
)
3025 e1000_suspend(pdev
, 3);
3032 e1000_suspend(struct pci_dev
*pdev
, uint32_t state
)
3034 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3035 struct e1000_adapter
*adapter
= netdev
->priv
;
3036 uint32_t ctrl
, ctrl_ext
, rctl
, manc
, status
;
3037 uint32_t wufc
= adapter
->wol
;
3039 netif_device_detach(netdev
);
3041 if(netif_running(netdev
))
3042 e1000_down(adapter
);
3044 status
= E1000_READ_REG(&adapter
->hw
, STATUS
);
3045 if(status
& E1000_STATUS_LU
)
3046 wufc
&= ~E1000_WUFC_LNKC
;
3049 e1000_setup_rctl(adapter
);
3050 e1000_set_multi(netdev
);
3052 /* turn on all-multi mode if wake on multicast is enabled */
3053 if(adapter
->wol
& E1000_WUFC_MC
) {
3054 rctl
= E1000_READ_REG(&adapter
->hw
, RCTL
);
3055 rctl
|= E1000_RCTL_MPE
;
3056 E1000_WRITE_REG(&adapter
->hw
, RCTL
, rctl
);
3059 if(adapter
->hw
.mac_type
>= e1000_82540
) {
3060 ctrl
= E1000_READ_REG(&adapter
->hw
, CTRL
);
3061 /* advertise wake from D3Cold */
3062 #define E1000_CTRL_ADVD3WUC 0x00100000
3063 /* phy power management enable */
3064 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3065 ctrl
|= E1000_CTRL_ADVD3WUC
|
3066 E1000_CTRL_EN_PHY_PWR_MGMT
;
3067 E1000_WRITE_REG(&adapter
->hw
, CTRL
, ctrl
);
3070 if(adapter
->hw
.media_type
== e1000_media_type_fiber
||
3071 adapter
->hw
.media_type
== e1000_media_type_internal_serdes
) {
3072 /* keep the laser running in D3 */
3073 ctrl_ext
= E1000_READ_REG(&adapter
->hw
, CTRL_EXT
);
3074 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
3075 E1000_WRITE_REG(&adapter
->hw
, CTRL_EXT
, ctrl_ext
);
3078 E1000_WRITE_REG(&adapter
->hw
, WUC
, E1000_WUC_PME_EN
);
3079 E1000_WRITE_REG(&adapter
->hw
, WUFC
, wufc
);
3080 pci_enable_wake(pdev
, 3, 1);
3081 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
3083 E1000_WRITE_REG(&adapter
->hw
, WUC
, 0);
3084 E1000_WRITE_REG(&adapter
->hw
, WUFC
, 0);
3085 pci_enable_wake(pdev
, 3, 0);
3086 pci_enable_wake(pdev
, 4, 0); /* 4 == D3 cold */
3089 pci_save_state(pdev
);
3091 if(adapter
->hw
.mac_type
>= e1000_82540
&&
3092 adapter
->hw
.media_type
== e1000_media_type_copper
) {
3093 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
3094 if(manc
& E1000_MANC_SMBUS_EN
) {
3095 manc
|= E1000_MANC_ARP_EN
;
3096 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
3097 pci_enable_wake(pdev
, 3, 1);
3098 pci_enable_wake(pdev
, 4, 1); /* 4 == D3 cold */
3102 pci_disable_device(pdev
);
3104 state
= (state
> 0) ? 3 : 0;
3105 pci_set_power_state(pdev
, state
);
3112 e1000_resume(struct pci_dev
*pdev
)
3114 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3115 struct e1000_adapter
*adapter
= netdev
->priv
;
3118 pci_set_power_state(pdev
, 0);
3119 pci_restore_state(pdev
);
3120 ret
= pci_enable_device(pdev
);
3121 if (pdev
->is_busmaster
)
3122 pci_set_master(pdev
);
3124 pci_enable_wake(pdev
, 3, 0);
3125 pci_enable_wake(pdev
, 4, 0); /* 4 == D3 cold */
3127 e1000_reset(adapter
);
3128 E1000_WRITE_REG(&adapter
->hw
, WUS
, ~0);
3130 if(netif_running(netdev
))
3133 netif_device_attach(netdev
);
3135 if(adapter
->hw
.mac_type
>= e1000_82540
&&
3136 adapter
->hw
.media_type
== e1000_media_type_copper
) {
3137 manc
= E1000_READ_REG(&adapter
->hw
, MANC
);
3138 manc
&= ~(E1000_MANC_ARP_EN
);
3139 E1000_WRITE_REG(&adapter
->hw
, MANC
, manc
);
3146 #ifdef CONFIG_NET_POLL_CONTROLLER
3148 * Polling 'interrupt' - used by things like netconsole to send skbs
3149 * without having to re-enable interrupts. It's not called while
3150 * the interrupt routine is executing.
3153 e1000_netpoll (struct net_device
*netdev
)
3155 struct e1000_adapter
*adapter
= netdev
->priv
;
3156 disable_irq(adapter
->pdev
->irq
);
3157 e1000_intr(adapter
->pdev
->irq
, netdev
, NULL
);
3158 enable_irq(adapter
->pdev
->irq
);