blob: 24d96c02b5094dcf5f0e971b6f3f9be4a699508e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
3
4 Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
5
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)
9 any later version.
10
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
14 more details.
15
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.
19
20 The full GNU General Public License is included in this distribution in the
21 file called LICENSE.
22
23 Contact Information:
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include "e1000.h"
30
31/* Change Log
32 * 5.3.12 6/7/04
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>
37 *
38 * 5.7.1 12/16/04
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
43 * 5.7.0 12/10/04
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
46 * 5.6.5 11/01/04
47 * - Enabling NETIF_F_SG without checksum offload is illegal -
48 John Mason <jdmason@us.ibm.com>
49 * 5.6.3 10/26/04
50 * - Remove redundant initialization - Jamal Hadi
51 * - Reset buffer_info->dma in tx resource cleanup logic
52 * 5.6.2 10/12/04
53 * - Avoid filling tx_ring completely - shemminger@osdl.org
54 * - Replace schedule_timeout() with msleep()/msleep_interruptible() -
55 * nacc@us.ibm.com
56 * - Sparse cleanup - shemminger@osdl.org
57 * - Fix tx resource cleanup logic
58 * - LLTX support - ak@suse.de and hadi@cyberus.ca
59 */
60
61char e1000_driver_name[] = "e1000";
62char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
63#ifndef CONFIG_E1000_NAPI
64#define DRIVERNAPI
65#else
66#define DRIVERNAPI "-NAPI"
67#endif
68#define DRV_VERSION "5.7.6-k2"DRIVERNAPI
69char e1000_driver_version[] = DRV_VERSION;
70char e1000_copyright[] = "Copyright (c) 1999-2004 Intel Corporation.";
71
72/* e1000_pci_tbl - PCI Device ID Table
73 *
74 * Last entry must be all 0s
75 *
76 * Macro expands to...
77 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
78 */
79static 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 */
114 {0,}
115};
116
117MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
118
119int e1000_up(struct e1000_adapter *adapter);
120void e1000_down(struct e1000_adapter *adapter);
121void e1000_reset(struct e1000_adapter *adapter);
122int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
123int e1000_setup_tx_resources(struct e1000_adapter *adapter);
124int e1000_setup_rx_resources(struct e1000_adapter *adapter);
125void e1000_free_tx_resources(struct e1000_adapter *adapter);
126void e1000_free_rx_resources(struct e1000_adapter *adapter);
127void e1000_update_stats(struct e1000_adapter *adapter);
128
129/* Local Function Prototypes */
130
131static int e1000_init_module(void);
132static void e1000_exit_module(void);
133static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
134static void __devexit e1000_remove(struct pci_dev *pdev);
135static int e1000_sw_init(struct e1000_adapter *adapter);
136static int e1000_open(struct net_device *netdev);
137static int e1000_close(struct net_device *netdev);
138static void e1000_configure_tx(struct e1000_adapter *adapter);
139static void e1000_configure_rx(struct e1000_adapter *adapter);
140static void e1000_setup_rctl(struct e1000_adapter *adapter);
141static void e1000_clean_tx_ring(struct e1000_adapter *adapter);
142static void e1000_clean_rx_ring(struct e1000_adapter *adapter);
143static void e1000_set_multi(struct net_device *netdev);
144static void e1000_update_phy_info(unsigned long data);
145static void e1000_watchdog(unsigned long data);
146static void e1000_watchdog_task(struct e1000_adapter *adapter);
147static void e1000_82547_tx_fifo_stall(unsigned long data);
148static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
149static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
150static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
151static int e1000_set_mac(struct net_device *netdev, void *p);
152static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
153static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter);
154#ifdef CONFIG_E1000_NAPI
155static int e1000_clean(struct net_device *netdev, int *budget);
156static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
157 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700158static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
159 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#else
161static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700162static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#endif
164static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700165static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
167static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
168 int cmd);
169void e1000_set_ethtool_ops(struct net_device *netdev);
170static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
171static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
172static void e1000_tx_timeout(struct net_device *dev);
173static void e1000_tx_timeout_task(struct net_device *dev);
174static void e1000_smartspeed(struct e1000_adapter *adapter);
175static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
176 struct sk_buff *skb);
177
178static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
179static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
180static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
181static void e1000_restore_vlan(struct e1000_adapter *adapter);
182
183static int e1000_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
184static int e1000_suspend(struct pci_dev *pdev, uint32_t state);
185#ifdef CONFIG_PM
186static int e1000_resume(struct pci_dev *pdev);
187#endif
188
189#ifdef CONFIG_NET_POLL_CONTROLLER
190/* for netdump / net console */
191static void e1000_netpoll (struct net_device *netdev);
192#endif
193
194struct notifier_block e1000_notifier_reboot = {
195 .notifier_call = e1000_notify_reboot,
196 .next = NULL,
197 .priority = 0
198};
199
200/* Exported from other modules */
201
202extern void e1000_check_options(struct e1000_adapter *adapter);
203
204static struct pci_driver e1000_driver = {
205 .name = e1000_driver_name,
206 .id_table = e1000_pci_tbl,
207 .probe = e1000_probe,
208 .remove = __devexit_p(e1000_remove),
209 /* Power Managment Hooks */
210#ifdef CONFIG_PM
211 .suspend = e1000_suspend,
212 .resume = e1000_resume
213#endif
214};
215
216MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
217MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
218MODULE_LICENSE("GPL");
219MODULE_VERSION(DRV_VERSION);
220
221static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
222module_param(debug, int, 0);
223MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
224
225/**
226 * e1000_init_module - Driver Registration Routine
227 *
228 * e1000_init_module is the first routine called when the driver is
229 * loaded. All it does is register with the PCI subsystem.
230 **/
231
232static int __init
233e1000_init_module(void)
234{
235 int ret;
236 printk(KERN_INFO "%s - version %s\n",
237 e1000_driver_string, e1000_driver_version);
238
239 printk(KERN_INFO "%s\n", e1000_copyright);
240
241 ret = pci_module_init(&e1000_driver);
242 if(ret >= 0) {
243 register_reboot_notifier(&e1000_notifier_reboot);
244 }
245 return ret;
246}
247
248module_init(e1000_init_module);
249
250/**
251 * e1000_exit_module - Driver Exit Cleanup Routine
252 *
253 * e1000_exit_module is called just before the driver is removed
254 * from memory.
255 **/
256
257static void __exit
258e1000_exit_module(void)
259{
260 unregister_reboot_notifier(&e1000_notifier_reboot);
261 pci_unregister_driver(&e1000_driver);
262}
263
264module_exit(e1000_exit_module);
265
266/**
267 * e1000_irq_disable - Mask off interrupt generation on the NIC
268 * @adapter: board private structure
269 **/
270
271static inline void
272e1000_irq_disable(struct e1000_adapter *adapter)
273{
274 atomic_inc(&adapter->irq_sem);
275 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
276 E1000_WRITE_FLUSH(&adapter->hw);
277 synchronize_irq(adapter->pdev->irq);
278}
279
280/**
281 * e1000_irq_enable - Enable default interrupt generation settings
282 * @adapter: board private structure
283 **/
284
285static inline void
286e1000_irq_enable(struct e1000_adapter *adapter)
287{
288 if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
289 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
290 E1000_WRITE_FLUSH(&adapter->hw);
291 }
292}
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700293void
294e1000_update_mng_vlan(struct e1000_adapter *adapter)
295{
296 struct net_device *netdev = adapter->netdev;
297 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
298 uint16_t old_vid = adapter->mng_vlan_id;
299 if(adapter->vlgrp) {
300 if(!adapter->vlgrp->vlan_devices[vid]) {
301 if(adapter->hw.mng_cookie.status &
302 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
303 e1000_vlan_rx_add_vid(netdev, vid);
304 adapter->mng_vlan_id = vid;
305 } else
306 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
307
308 if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
309 (vid != old_vid) &&
310 !adapter->vlgrp->vlan_devices[old_vid])
311 e1000_vlan_rx_kill_vid(netdev, old_vid);
312 }
313 }
314}
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316int
317e1000_up(struct e1000_adapter *adapter)
318{
319 struct net_device *netdev = adapter->netdev;
320 int err;
321
322 /* hardware has been reset, we need to reload some things */
323
324 /* Reset the PHY if it was previously powered down */
325 if(adapter->hw.media_type == e1000_media_type_copper) {
326 uint16_t mii_reg;
327 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
328 if(mii_reg & MII_CR_POWER_DOWN)
329 e1000_phy_reset(&adapter->hw);
330 }
331
332 e1000_set_multi(netdev);
333
334 e1000_restore_vlan(adapter);
335
336 e1000_configure_tx(adapter);
337 e1000_setup_rctl(adapter);
338 e1000_configure_rx(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700339 adapter->alloc_rx_buf(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700341#ifdef CONFIG_PCI_MSI
342 if(adapter->hw.mac_type > e1000_82547_rev_2) {
343 adapter->have_msi = TRUE;
344 if((err = pci_enable_msi(adapter->pdev))) {
345 DPRINTK(PROBE, ERR,
346 "Unable to allocate MSI interrupt Error: %d\n", err);
347 adapter->have_msi = FALSE;
348 }
349 }
350#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 if((err = request_irq(adapter->pdev->irq, &e1000_intr,
352 SA_SHIRQ | SA_SAMPLE_RANDOM,
353 netdev->name, netdev)))
354 return err;
355
356 mod_timer(&adapter->watchdog_timer, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358#ifdef CONFIG_E1000_NAPI
359 netif_poll_enable(netdev);
360#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700361 e1000_irq_enable(adapter);
362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 return 0;
364}
365
366void
367e1000_down(struct e1000_adapter *adapter)
368{
369 struct net_device *netdev = adapter->netdev;
370
371 e1000_irq_disable(adapter);
372 free_irq(adapter->pdev->irq, netdev);
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700373#ifdef CONFIG_PCI_MSI
374 if(adapter->hw.mac_type > e1000_82547_rev_2 &&
375 adapter->have_msi == TRUE)
376 pci_disable_msi(adapter->pdev);
377#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 del_timer_sync(&adapter->tx_fifo_stall_timer);
379 del_timer_sync(&adapter->watchdog_timer);
380 del_timer_sync(&adapter->phy_info_timer);
381
382#ifdef CONFIG_E1000_NAPI
383 netif_poll_disable(netdev);
384#endif
385 adapter->link_speed = 0;
386 adapter->link_duplex = 0;
387 netif_carrier_off(netdev);
388 netif_stop_queue(netdev);
389
390 e1000_reset(adapter);
391 e1000_clean_tx_ring(adapter);
392 e1000_clean_rx_ring(adapter);
393
394 /* If WoL is not enabled
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700395 * and management mode is not IAMT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 * Power down the PHY so no link is implied when interface is down */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700397 if(!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
398 adapter->hw.media_type == e1000_media_type_copper &&
399 !e1000_check_mng_mode(&adapter->hw) &&
400 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 uint16_t mii_reg;
402 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
403 mii_reg |= MII_CR_POWER_DOWN;
404 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
Malli Chilakala4e48a2b2005-04-28 19:39:53 -0700405 mdelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407}
408
409void
410e1000_reset(struct e1000_adapter *adapter)
411{
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700412 struct net_device *netdev = adapter->netdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700413 uint32_t pba, manc;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700414 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
415 uint16_t fc_low_water_mark = E1000_FC_LOW_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 /* Repartition Pba for greater than 9k mtu
418 * To take effect CTRL.RST is required.
419 */
420
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700421 switch (adapter->hw.mac_type) {
422 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700423 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700424 pba = E1000_PBA_30K;
425 break;
426 case e1000_82573:
427 pba = E1000_PBA_12K;
428 break;
429 default:
430 pba = E1000_PBA_48K;
431 break;
432 }
433
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700434 if((adapter->hw.mac_type != e1000_82573) &&
435 (adapter->rx_buffer_len > E1000_RXBUFFER_8192)) {
436 pba -= 8; /* allocate more FIFO for Tx */
437 /* send an XOFF when there is enough space in the
438 * Rx FIFO to hold one extra full size Rx packet
439 */
440 fc_high_water_mark = netdev->mtu + ENET_HEADER_SIZE +
441 ETHERNET_FCS_SIZE + 1;
442 fc_low_water_mark = fc_high_water_mark + 8;
443 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700444
445
446 if(adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 adapter->tx_fifo_head = 0;
448 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
449 adapter->tx_fifo_size =
450 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
451 atomic_set(&adapter->tx_fifo_stall, 0);
452 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 E1000_WRITE_REG(&adapter->hw, PBA, pba);
455
456 /* flow control settings */
457 adapter->hw.fc_high_water = (pba << E1000_PBA_BYTES_SHIFT) -
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700458 fc_high_water_mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 adapter->hw.fc_low_water = (pba << E1000_PBA_BYTES_SHIFT) -
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700460 fc_low_water_mark;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
462 adapter->hw.fc_send_xon = 1;
463 adapter->hw.fc = adapter->hw.original_fc;
464
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700465 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 e1000_reset_hw(&adapter->hw);
467 if(adapter->hw.mac_type >= e1000_82544)
468 E1000_WRITE_REG(&adapter->hw, WUC, 0);
469 if(e1000_init_hw(&adapter->hw))
470 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700471 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
473 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
474
475 e1000_reset_adaptive(&adapter->hw);
476 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700477 if (adapter->en_mng_pt) {
478 manc = E1000_READ_REG(&adapter->hw, MANC);
479 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
480 E1000_WRITE_REG(&adapter->hw, MANC, manc);
481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482}
483
484/**
485 * e1000_probe - Device Initialization Routine
486 * @pdev: PCI device information struct
487 * @ent: entry in e1000_pci_tbl
488 *
489 * Returns 0 on success, negative on failure
490 *
491 * e1000_probe initializes an adapter identified by a pci_dev structure.
492 * The OS initialization, configuring of the adapter private structure,
493 * and a hardware reset occur.
494 **/
495
496static int __devinit
497e1000_probe(struct pci_dev *pdev,
498 const struct pci_device_id *ent)
499{
500 struct net_device *netdev;
501 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700502 unsigned long mmio_start, mmio_len;
503 uint32_t swsm;
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 static int cards_found = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700506 int i, err, pci_using_dac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 uint16_t eeprom_data;
508 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if((err = pci_enable_device(pdev)))
510 return err;
511
512 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
513 pci_using_dac = 1;
514 } else {
515 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
516 E1000_ERR("No usable DMA configuration, aborting\n");
517 return err;
518 }
519 pci_using_dac = 0;
520 }
521
522 if((err = pci_request_regions(pdev, e1000_driver_name)))
523 return err;
524
525 pci_set_master(pdev);
526
527 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
528 if(!netdev) {
529 err = -ENOMEM;
530 goto err_alloc_etherdev;
531 }
532
533 SET_MODULE_OWNER(netdev);
534 SET_NETDEV_DEV(netdev, &pdev->dev);
535
536 pci_set_drvdata(pdev, netdev);
537 adapter = netdev->priv;
538 adapter->netdev = netdev;
539 adapter->pdev = pdev;
540 adapter->hw.back = adapter;
541 adapter->msg_enable = (1 << debug) - 1;
542
543 mmio_start = pci_resource_start(pdev, BAR_0);
544 mmio_len = pci_resource_len(pdev, BAR_0);
545
546 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
547 if(!adapter->hw.hw_addr) {
548 err = -EIO;
549 goto err_ioremap;
550 }
551
552 for(i = BAR_1; i <= BAR_5; i++) {
553 if(pci_resource_len(pdev, i) == 0)
554 continue;
555 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
556 adapter->hw.io_base = pci_resource_start(pdev, i);
557 break;
558 }
559 }
560
561 netdev->open = &e1000_open;
562 netdev->stop = &e1000_close;
563 netdev->hard_start_xmit = &e1000_xmit_frame;
564 netdev->get_stats = &e1000_get_stats;
565 netdev->set_multicast_list = &e1000_set_multi;
566 netdev->set_mac_address = &e1000_set_mac;
567 netdev->change_mtu = &e1000_change_mtu;
568 netdev->do_ioctl = &e1000_ioctl;
569 e1000_set_ethtool_ops(netdev);
570 netdev->tx_timeout = &e1000_tx_timeout;
571 netdev->watchdog_timeo = 5 * HZ;
572#ifdef CONFIG_E1000_NAPI
573 netdev->poll = &e1000_clean;
574 netdev->weight = 64;
575#endif
576 netdev->vlan_rx_register = e1000_vlan_rx_register;
577 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
578 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
579#ifdef CONFIG_NET_POLL_CONTROLLER
580 netdev->poll_controller = e1000_netpoll;
581#endif
582 strcpy(netdev->name, pci_name(pdev));
583
584 netdev->mem_start = mmio_start;
585 netdev->mem_end = mmio_start + mmio_len;
586 netdev->base_addr = adapter->hw.io_base;
587
588 adapter->bd_number = cards_found;
589
590 /* setup the private structure */
591
592 if((err = e1000_sw_init(adapter)))
593 goto err_sw_init;
594
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700595 if((err = e1000_check_phy_reset_block(&adapter->hw)))
596 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 if(adapter->hw.mac_type >= e1000_82543) {
599 netdev->features = NETIF_F_SG |
600 NETIF_F_HW_CSUM |
601 NETIF_F_HW_VLAN_TX |
602 NETIF_F_HW_VLAN_RX |
603 NETIF_F_HW_VLAN_FILTER;
604 }
605
606#ifdef NETIF_F_TSO
607 if((adapter->hw.mac_type >= e1000_82544) &&
608 (adapter->hw.mac_type != e1000_82547))
609 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700610
611#ifdef NETIF_F_TSO_IPV6
612 if(adapter->hw.mac_type > e1000_82547_rev_2)
613 netdev->features |= NETIF_F_TSO_IPV6;
614#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#endif
616 if(pci_using_dac)
617 netdev->features |= NETIF_F_HIGHDMA;
618
619 /* hard_start_xmit is safe against parallel locking */
620 netdev->features |= NETIF_F_LLTX;
621
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700622 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 /* before reading the EEPROM, reset the controller to
625 * put the device in a known good starting state */
626
627 e1000_reset_hw(&adapter->hw);
628
629 /* make sure the EEPROM is good */
630
631 if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
632 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
633 err = -EIO;
634 goto err_eeprom;
635 }
636
637 /* copy the MAC address out of the EEPROM */
638
639 if (e1000_read_mac_addr(&adapter->hw))
640 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
641 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
642
643 if(!is_valid_ether_addr(netdev->dev_addr)) {
644 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
645 err = -EIO;
646 goto err_eeprom;
647 }
648
649 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
650
651 e1000_get_bus_info(&adapter->hw);
652
653 init_timer(&adapter->tx_fifo_stall_timer);
654 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
655 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
656
657 init_timer(&adapter->watchdog_timer);
658 adapter->watchdog_timer.function = &e1000_watchdog;
659 adapter->watchdog_timer.data = (unsigned long) adapter;
660
661 INIT_WORK(&adapter->watchdog_task,
662 (void (*)(void *))e1000_watchdog_task, adapter);
663
664 init_timer(&adapter->phy_info_timer);
665 adapter->phy_info_timer.function = &e1000_update_phy_info;
666 adapter->phy_info_timer.data = (unsigned long) adapter;
667
668 INIT_WORK(&adapter->tx_timeout_task,
669 (void (*)(void *))e1000_tx_timeout_task, netdev);
670
671 /* we're going to reset, so assume we have no link for now */
672
673 netif_carrier_off(netdev);
674 netif_stop_queue(netdev);
675
676 e1000_check_options(adapter);
677
678 /* Initial Wake on LAN setting
679 * If APM wake is enabled in the EEPROM,
680 * enable the ACPI Magic Packet filter
681 */
682
683 switch(adapter->hw.mac_type) {
684 case e1000_82542_rev2_0:
685 case e1000_82542_rev2_1:
686 case e1000_82543:
687 break;
688 case e1000_82544:
689 e1000_read_eeprom(&adapter->hw,
690 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
691 eeprom_apme_mask = E1000_EEPROM_82544_APM;
692 break;
693 case e1000_82546:
694 case e1000_82546_rev_3:
695 if((E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
696 && (adapter->hw.media_type == e1000_media_type_copper)) {
697 e1000_read_eeprom(&adapter->hw,
698 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
699 break;
700 }
701 /* Fall Through */
702 default:
703 e1000_read_eeprom(&adapter->hw,
704 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
705 break;
706 }
707 if(eeprom_data & eeprom_apme_mask)
708 adapter->wol |= E1000_WUFC_MAG;
709
710 /* reset the hardware with the new settings */
711 e1000_reset(adapter);
712
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700713 /* Let firmware know the driver has taken over */
714 switch(adapter->hw.mac_type) {
715 case e1000_82573:
716 swsm = E1000_READ_REG(&adapter->hw, SWSM);
717 E1000_WRITE_REG(&adapter->hw, SWSM,
718 swsm | E1000_SWSM_DRV_LOAD);
719 break;
720 default:
721 break;
722 }
723
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 strcpy(netdev->name, "eth%d");
725 if((err = register_netdev(netdev)))
726 goto err_register;
727
728 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
729
730 cards_found++;
731 return 0;
732
733err_register:
734err_sw_init:
735err_eeprom:
736 iounmap(adapter->hw.hw_addr);
737err_ioremap:
738 free_netdev(netdev);
739err_alloc_etherdev:
740 pci_release_regions(pdev);
741 return err;
742}
743
744/**
745 * e1000_remove - Device Removal Routine
746 * @pdev: PCI device information struct
747 *
748 * e1000_remove is called by the PCI subsystem to alert the driver
749 * that it should release a PCI device. The could be caused by a
750 * Hot-Plug event, or because the driver is going to be removed from
751 * memory.
752 **/
753
754static void __devexit
755e1000_remove(struct pci_dev *pdev)
756{
757 struct net_device *netdev = pci_get_drvdata(pdev);
758 struct e1000_adapter *adapter = netdev->priv;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700759 uint32_t manc, swsm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 flush_scheduled_work();
762
763 if(adapter->hw.mac_type >= e1000_82540 &&
764 adapter->hw.media_type == e1000_media_type_copper) {
765 manc = E1000_READ_REG(&adapter->hw, MANC);
766 if(manc & E1000_MANC_SMBUS_EN) {
767 manc |= E1000_MANC_ARP_EN;
768 E1000_WRITE_REG(&adapter->hw, MANC, manc);
769 }
770 }
771
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700772 switch(adapter->hw.mac_type) {
773 case e1000_82573:
774 swsm = E1000_READ_REG(&adapter->hw, SWSM);
775 E1000_WRITE_REG(&adapter->hw, SWSM,
776 swsm & ~E1000_SWSM_DRV_LOAD);
777 break;
778
779 default:
780 break;
781 }
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 unregister_netdev(netdev);
784
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700785 if(!e1000_check_phy_reset_block(&adapter->hw))
786 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 iounmap(adapter->hw.hw_addr);
789 pci_release_regions(pdev);
790
791 free_netdev(netdev);
792
793 pci_disable_device(pdev);
794}
795
796/**
797 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
798 * @adapter: board private structure to initialize
799 *
800 * e1000_sw_init initializes the Adapter private data structure.
801 * Fields are initialized based on PCI device information and
802 * OS network device settings (MTU size).
803 **/
804
805static int __devinit
806e1000_sw_init(struct e1000_adapter *adapter)
807{
808 struct e1000_hw *hw = &adapter->hw;
809 struct net_device *netdev = adapter->netdev;
810 struct pci_dev *pdev = adapter->pdev;
811
812 /* PCI config space info */
813
814 hw->vendor_id = pdev->vendor;
815 hw->device_id = pdev->device;
816 hw->subsystem_vendor_id = pdev->subsystem_vendor;
817 hw->subsystem_id = pdev->subsystem_device;
818
819 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
820
821 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
822
823 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700824 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 hw->max_frame_size = netdev->mtu +
826 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
827 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
828
829 /* identify the MAC */
830
831 if(e1000_set_mac_type(hw)) {
832 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
833 return -EIO;
834 }
835
836 /* initialize eeprom parameters */
837
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700838 if(e1000_init_eeprom_params(hw)) {
839 E1000_ERR("EEPROM initialization failed\n");
840 return -EIO;
841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 switch(hw->mac_type) {
844 default:
845 break;
846 case e1000_82541:
847 case e1000_82547:
848 case e1000_82541_rev_2:
849 case e1000_82547_rev_2:
850 hw->phy_init_script = 1;
851 break;
852 }
853
854 e1000_set_media_type(hw);
855
856 hw->wait_autoneg_complete = FALSE;
857 hw->tbi_compatibility_en = TRUE;
858 hw->adaptive_ifs = TRUE;
859
860 /* Copper options */
861
862 if(hw->media_type == e1000_media_type_copper) {
863 hw->mdix = AUTO_ALL_MODES;
864 hw->disable_polarity_correction = FALSE;
865 hw->master_slave = E1000_MASTER_SLAVE;
866 }
867
868 atomic_set(&adapter->irq_sem, 1);
869 spin_lock_init(&adapter->stats_lock);
870 spin_lock_init(&adapter->tx_lock);
871
872 return 0;
873}
874
875/**
876 * e1000_open - Called when a network interface is made active
877 * @netdev: network interface device structure
878 *
879 * Returns 0 on success, negative value on failure
880 *
881 * The open entry point is called when a network interface is made
882 * active by the system (IFF_UP). At this point all resources needed
883 * for transmit and receive operations are allocated, the interrupt
884 * handler is registered with the OS, the watchdog timer is started,
885 * and the stack is notified that the interface is ready.
886 **/
887
888static int
889e1000_open(struct net_device *netdev)
890{
891 struct e1000_adapter *adapter = netdev->priv;
892 int err;
893
894 /* allocate transmit descriptors */
895
896 if((err = e1000_setup_tx_resources(adapter)))
897 goto err_setup_tx;
898
899 /* allocate receive descriptors */
900
901 if((err = e1000_setup_rx_resources(adapter)))
902 goto err_setup_rx;
903
904 if((err = e1000_up(adapter)))
905 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700906 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
907 if((adapter->hw.mng_cookie.status &
908 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
909 e1000_update_mng_vlan(adapter);
910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 return E1000_SUCCESS;
913
914err_up:
915 e1000_free_rx_resources(adapter);
916err_setup_rx:
917 e1000_free_tx_resources(adapter);
918err_setup_tx:
919 e1000_reset(adapter);
920
921 return err;
922}
923
924/**
925 * e1000_close - Disables a network interface
926 * @netdev: network interface device structure
927 *
928 * Returns 0, this is not allowed to fail
929 *
930 * The close entry point is called when an interface is de-activated
931 * by the OS. The hardware is still under the drivers control, but
932 * needs to be disabled. A global MAC reset is issued to stop the
933 * hardware, and all transmit and receive resources are freed.
934 **/
935
936static int
937e1000_close(struct net_device *netdev)
938{
939 struct e1000_adapter *adapter = netdev->priv;
940
941 e1000_down(adapter);
942
943 e1000_free_tx_resources(adapter);
944 e1000_free_rx_resources(adapter);
945
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700946 if((adapter->hw.mng_cookie.status &
947 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
948 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 return 0;
951}
952
953/**
954 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
955 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700956 * @start: address of beginning of memory
957 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 **/
959static inline boolean_t
960e1000_check_64k_bound(struct e1000_adapter *adapter,
961 void *start, unsigned long len)
962{
963 unsigned long begin = (unsigned long) start;
964 unsigned long end = begin + len;
965
966 /* first rev 82545 and 82546 need to not allow any memory
967 * write location to cross a 64k boundary due to errata 23 */
968 if (adapter->hw.mac_type == e1000_82545 ||
969 adapter->hw.mac_type == e1000_82546 ) {
970
971 /* check buffer doesn't cross 64kB */
972 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
973 }
974
975 return TRUE;
976}
977
978/**
979 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
980 * @adapter: board private structure
981 *
982 * Return 0 on success, negative on failure
983 **/
984
985int
986e1000_setup_tx_resources(struct e1000_adapter *adapter)
987{
988 struct e1000_desc_ring *txdr = &adapter->tx_ring;
989 struct pci_dev *pdev = adapter->pdev;
990 int size;
991
992 size = sizeof(struct e1000_buffer) * txdr->count;
993 txdr->buffer_info = vmalloc(size);
994 if(!txdr->buffer_info) {
995 DPRINTK(PROBE, ERR,
996 "Unable to Allocate Memory for the Transmit descriptor ring\n");
997 return -ENOMEM;
998 }
999 memset(txdr->buffer_info, 0, size);
1000
1001 /* round up to nearest 4K */
1002
1003 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1004 E1000_ROUNDUP(txdr->size, 4096);
1005
1006 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1007 if(!txdr->desc) {
1008setup_tx_desc_die:
1009 DPRINTK(PROBE, ERR,
1010 "Unable to Allocate Memory for the Transmit descriptor ring\n");
1011 vfree(txdr->buffer_info);
1012 return -ENOMEM;
1013 }
1014
1015 /* fix for errata 23, cant cross 64kB boundary */
1016 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1017 void *olddesc = txdr->desc;
1018 dma_addr_t olddma = txdr->dma;
1019 DPRINTK(TX_ERR,ERR,"txdr align check failed: %u bytes at %p\n",
1020 txdr->size, txdr->desc);
1021 /* try again, without freeing the previous */
1022 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1023 /* failed allocation, critial failure */
1024 if(!txdr->desc) {
1025 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1026 goto setup_tx_desc_die;
1027 }
1028
1029 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1030 /* give up */
1031 pci_free_consistent(pdev, txdr->size,
1032 txdr->desc, txdr->dma);
1033 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1034 DPRINTK(PROBE, ERR,
1035 "Unable to Allocate aligned Memory for the Transmit"
1036 " descriptor ring\n");
1037 vfree(txdr->buffer_info);
1038 return -ENOMEM;
1039 } else {
1040 /* free old, move on with the new one since its okay */
1041 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1042 }
1043 }
1044 memset(txdr->desc, 0, txdr->size);
1045
1046 txdr->next_to_use = 0;
1047 txdr->next_to_clean = 0;
1048
1049 return 0;
1050}
1051
1052/**
1053 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1054 * @adapter: board private structure
1055 *
1056 * Configure the Tx unit of the MAC after a reset.
1057 **/
1058
1059static void
1060e1000_configure_tx(struct e1000_adapter *adapter)
1061{
1062 uint64_t tdba = adapter->tx_ring.dma;
1063 uint32_t tdlen = adapter->tx_ring.count * sizeof(struct e1000_tx_desc);
1064 uint32_t tctl, tipg;
1065
1066 E1000_WRITE_REG(&adapter->hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1067 E1000_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32));
1068
1069 E1000_WRITE_REG(&adapter->hw, TDLEN, tdlen);
1070
1071 /* Setup the HW Tx Head and Tail descriptor pointers */
1072
1073 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1074 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1075
1076 /* Set the default values for the Tx Inter Packet Gap timer */
1077
1078 switch (adapter->hw.mac_type) {
1079 case e1000_82542_rev2_0:
1080 case e1000_82542_rev2_1:
1081 tipg = DEFAULT_82542_TIPG_IPGT;
1082 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1083 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1084 break;
1085 default:
1086 if(adapter->hw.media_type == e1000_media_type_fiber ||
1087 adapter->hw.media_type == e1000_media_type_internal_serdes)
1088 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1089 else
1090 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1091 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1092 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1093 }
1094 E1000_WRITE_REG(&adapter->hw, TIPG, tipg);
1095
1096 /* Set the Tx Interrupt Delay register */
1097
1098 E1000_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay);
1099 if(adapter->hw.mac_type >= e1000_82540)
1100 E1000_WRITE_REG(&adapter->hw, TADV, adapter->tx_abs_int_delay);
1101
1102 /* Program the Transmit Control Register */
1103
1104 tctl = E1000_READ_REG(&adapter->hw, TCTL);
1105
1106 tctl &= ~E1000_TCTL_CT;
1107 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
1108 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1109
1110 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
1111
1112 e1000_config_collision_dist(&adapter->hw);
1113
1114 /* Setup Transmit Descriptor Settings for eop descriptor */
1115 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1116 E1000_TXD_CMD_IFCS;
1117
1118 if(adapter->hw.mac_type < e1000_82543)
1119 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1120 else
1121 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1122
1123 /* Cache if we're 82544 running in PCI-X because we'll
1124 * need this to apply a workaround later in the send path. */
1125 if(adapter->hw.mac_type == e1000_82544 &&
1126 adapter->hw.bus_type == e1000_bus_type_pcix)
1127 adapter->pcix_82544 = 1;
1128}
1129
1130/**
1131 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1132 * @adapter: board private structure
1133 *
1134 * Returns 0 on success, negative on failure
1135 **/
1136
1137int
1138e1000_setup_rx_resources(struct e1000_adapter *adapter)
1139{
1140 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
1141 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001142 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 size = sizeof(struct e1000_buffer) * rxdr->count;
1145 rxdr->buffer_info = vmalloc(size);
1146 if(!rxdr->buffer_info) {
1147 DPRINTK(PROBE, ERR,
1148 "Unable to Allocate Memory for the Recieve descriptor ring\n");
1149 return -ENOMEM;
1150 }
1151 memset(rxdr->buffer_info, 0, size);
1152
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001153 size = sizeof(struct e1000_ps_page) * rxdr->count;
1154 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1155 if(!rxdr->ps_page) {
1156 vfree(rxdr->buffer_info);
1157 DPRINTK(PROBE, ERR,
1158 "Unable to allocate memory for the receive descriptor ring\n");
1159 return -ENOMEM;
1160 }
1161 memset(rxdr->ps_page, 0, size);
1162
1163 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1164 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1165 if(!rxdr->ps_page_dma) {
1166 vfree(rxdr->buffer_info);
1167 kfree(rxdr->ps_page);
1168 DPRINTK(PROBE, ERR,
1169 "Unable to allocate memory for the receive descriptor ring\n");
1170 return -ENOMEM;
1171 }
1172 memset(rxdr->ps_page_dma, 0, size);
1173
1174 if(adapter->hw.mac_type <= e1000_82547_rev_2)
1175 desc_len = sizeof(struct e1000_rx_desc);
1176 else
1177 desc_len = sizeof(union e1000_rx_desc_packet_split);
1178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 /* Round up to nearest 4K */
1180
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001181 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 E1000_ROUNDUP(rxdr->size, 4096);
1183
1184 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1185
1186 if(!rxdr->desc) {
1187setup_rx_desc_die:
1188 DPRINTK(PROBE, ERR,
1189 "Unble to Allocate Memory for the Recieve descriptor ring\n");
1190 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001191 kfree(rxdr->ps_page);
1192 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 return -ENOMEM;
1194 }
1195
1196 /* fix for errata 23, cant cross 64kB boundary */
1197 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1198 void *olddesc = rxdr->desc;
1199 dma_addr_t olddma = rxdr->dma;
1200 DPRINTK(RX_ERR,ERR,
1201 "rxdr align check failed: %u bytes at %p\n",
1202 rxdr->size, rxdr->desc);
1203 /* try again, without freeing the previous */
1204 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1205 /* failed allocation, critial failure */
1206 if(!rxdr->desc) {
1207 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1208 goto setup_rx_desc_die;
1209 }
1210
1211 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1212 /* give up */
1213 pci_free_consistent(pdev, rxdr->size,
1214 rxdr->desc, rxdr->dma);
1215 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1216 DPRINTK(PROBE, ERR,
1217 "Unable to Allocate aligned Memory for the"
1218 " Receive descriptor ring\n");
1219 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001220 kfree(rxdr->ps_page);
1221 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 return -ENOMEM;
1223 } else {
1224 /* free old, move on with the new one since its okay */
1225 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1226 }
1227 }
1228 memset(rxdr->desc, 0, rxdr->size);
1229
1230 rxdr->next_to_clean = 0;
1231 rxdr->next_to_use = 0;
1232
1233 return 0;
1234}
1235
1236/**
1237 * e1000_setup_rctl - configure the receive control register
1238 * @adapter: Board private structure
1239 **/
1240
1241static void
1242e1000_setup_rctl(struct e1000_adapter *adapter)
1243{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001244 uint32_t rctl, rfctl;
1245 uint32_t psrctl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1248
1249 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1250
1251 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1252 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1253 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1254
1255 if(adapter->hw.tbi_compatibility_on == 1)
1256 rctl |= E1000_RCTL_SBP;
1257 else
1258 rctl &= ~E1000_RCTL_SBP;
1259
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001260 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1261 rctl &= ~E1000_RCTL_LPE;
1262 else
1263 rctl |= E1000_RCTL_LPE;
1264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 /* Setup buffer sizes */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001266 if(adapter->hw.mac_type == e1000_82573) {
1267 /* We can now specify buffers in 1K increments.
1268 * BSIZE and BSEX are ignored in this case. */
1269 rctl |= adapter->rx_buffer_len << 0x11;
1270 } else {
1271 rctl &= ~E1000_RCTL_SZ_4096;
1272 rctl |= E1000_RCTL_BSEX;
1273 switch (adapter->rx_buffer_len) {
1274 case E1000_RXBUFFER_2048:
1275 default:
1276 rctl |= E1000_RCTL_SZ_2048;
1277 rctl &= ~E1000_RCTL_BSEX;
1278 break;
1279 case E1000_RXBUFFER_4096:
1280 rctl |= E1000_RCTL_SZ_4096;
1281 break;
1282 case E1000_RXBUFFER_8192:
1283 rctl |= E1000_RCTL_SZ_8192;
1284 break;
1285 case E1000_RXBUFFER_16384:
1286 rctl |= E1000_RCTL_SZ_16384;
1287 break;
1288 }
1289 }
1290
1291#ifdef CONFIG_E1000_PACKET_SPLIT
1292 /* 82571 and greater support packet-split where the protocol
1293 * header is placed in skb->data and the packet data is
1294 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1295 * In the case of a non-split, skb->data is linearly filled,
1296 * followed by the page buffers. Therefore, skb->data is
1297 * sized to hold the largest protocol header.
1298 */
1299 adapter->rx_ps = (adapter->hw.mac_type > e1000_82547_rev_2)
1300 && (adapter->netdev->mtu
1301 < ((3 * PAGE_SIZE) + adapter->rx_ps_bsize0));
1302#endif
1303 if(adapter->rx_ps) {
1304 /* Configure extra packet-split registers */
1305 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1306 rfctl |= E1000_RFCTL_EXTEN;
1307 /* disable IPv6 packet split support */
1308 rfctl |= E1000_RFCTL_IPV6_DIS;
1309 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1310
1311 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1312
1313 psrctl |= adapter->rx_ps_bsize0 >>
1314 E1000_PSRCTL_BSIZE0_SHIFT;
1315 psrctl |= PAGE_SIZE >>
1316 E1000_PSRCTL_BSIZE1_SHIFT;
1317 psrctl |= PAGE_SIZE <<
1318 E1000_PSRCTL_BSIZE2_SHIFT;
1319 psrctl |= PAGE_SIZE <<
1320 E1000_PSRCTL_BSIZE3_SHIFT;
1321
1322 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 }
1324
1325 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1326}
1327
1328/**
1329 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1330 * @adapter: board private structure
1331 *
1332 * Configure the Rx unit of the MAC after a reset.
1333 **/
1334
1335static void
1336e1000_configure_rx(struct e1000_adapter *adapter)
1337{
1338 uint64_t rdba = adapter->rx_ring.dma;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001339 uint32_t rdlen, rctl, rxcsum;
1340
1341 if(adapter->rx_ps) {
1342 rdlen = adapter->rx_ring.count *
1343 sizeof(union e1000_rx_desc_packet_split);
1344 adapter->clean_rx = e1000_clean_rx_irq_ps;
1345 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1346 } else {
1347 rdlen = adapter->rx_ring.count * sizeof(struct e1000_rx_desc);
1348 adapter->clean_rx = e1000_clean_rx_irq;
1349 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1350 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
1352 /* disable receives while setting up the descriptors */
1353 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1354 E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
1355
1356 /* set the Receive Delay Timer Register */
1357 E1000_WRITE_REG(&adapter->hw, RDTR, adapter->rx_int_delay);
1358
1359 if(adapter->hw.mac_type >= e1000_82540) {
1360 E1000_WRITE_REG(&adapter->hw, RADV, adapter->rx_abs_int_delay);
1361 if(adapter->itr > 1)
1362 E1000_WRITE_REG(&adapter->hw, ITR,
1363 1000000000 / (adapter->itr * 256));
1364 }
1365
1366 /* Setup the Base and Length of the Rx Descriptor Ring */
1367 E1000_WRITE_REG(&adapter->hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1368 E1000_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32));
1369
1370 E1000_WRITE_REG(&adapter->hw, RDLEN, rdlen);
1371
1372 /* Setup the HW Rx Head and Tail Descriptor Pointers */
1373 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1374 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1375
1376 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001377 if(adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 rxcsum = E1000_READ_REG(&adapter->hw, RXCSUM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001379 if(adapter->rx_csum == TRUE) {
1380 rxcsum |= E1000_RXCSUM_TUOFL;
1381
1382 /* Enable 82573 IPv4 payload checksum for UDP fragments
1383 * Must be used in conjunction with packet-split. */
1384 if((adapter->hw.mac_type > e1000_82547_rev_2) &&
1385 (adapter->rx_ps)) {
1386 rxcsum |= E1000_RXCSUM_IPPCSE;
1387 }
1388 } else {
1389 rxcsum &= ~E1000_RXCSUM_TUOFL;
1390 /* don't need to clear IPPCSE as it defaults to 0 */
1391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 E1000_WRITE_REG(&adapter->hw, RXCSUM, rxcsum);
1393 }
1394
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001395 if (adapter->hw.mac_type == e1000_82573)
1396 E1000_WRITE_REG(&adapter->hw, ERT, 0x0100);
1397
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 /* Enable Receives */
1399 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1400}
1401
1402/**
1403 * e1000_free_tx_resources - Free Tx Resources
1404 * @adapter: board private structure
1405 *
1406 * Free all transmit software resources
1407 **/
1408
1409void
1410e1000_free_tx_resources(struct e1000_adapter *adapter)
1411{
1412 struct pci_dev *pdev = adapter->pdev;
1413
1414 e1000_clean_tx_ring(adapter);
1415
1416 vfree(adapter->tx_ring.buffer_info);
1417 adapter->tx_ring.buffer_info = NULL;
1418
1419 pci_free_consistent(pdev, adapter->tx_ring.size,
1420 adapter->tx_ring.desc, adapter->tx_ring.dma);
1421
1422 adapter->tx_ring.desc = NULL;
1423}
1424
1425static inline void
1426e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1427 struct e1000_buffer *buffer_info)
1428{
1429 struct pci_dev *pdev = adapter->pdev;
1430
1431 if(buffer_info->dma) {
1432 pci_unmap_page(pdev,
1433 buffer_info->dma,
1434 buffer_info->length,
1435 PCI_DMA_TODEVICE);
1436 buffer_info->dma = 0;
1437 }
1438 if(buffer_info->skb) {
1439 dev_kfree_skb_any(buffer_info->skb);
1440 buffer_info->skb = NULL;
1441 }
1442}
1443
1444/**
1445 * e1000_clean_tx_ring - Free Tx Buffers
1446 * @adapter: board private structure
1447 **/
1448
1449static void
1450e1000_clean_tx_ring(struct e1000_adapter *adapter)
1451{
1452 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
1453 struct e1000_buffer *buffer_info;
1454 unsigned long size;
1455 unsigned int i;
1456
1457 /* Free all the Tx ring sk_buffs */
1458
1459 if (likely(adapter->previous_buffer_info.skb != NULL)) {
1460 e1000_unmap_and_free_tx_resource(adapter,
1461 &adapter->previous_buffer_info);
1462 }
1463
1464 for(i = 0; i < tx_ring->count; i++) {
1465 buffer_info = &tx_ring->buffer_info[i];
1466 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1467 }
1468
1469 size = sizeof(struct e1000_buffer) * tx_ring->count;
1470 memset(tx_ring->buffer_info, 0, size);
1471
1472 /* Zero out the descriptor ring */
1473
1474 memset(tx_ring->desc, 0, tx_ring->size);
1475
1476 tx_ring->next_to_use = 0;
1477 tx_ring->next_to_clean = 0;
1478
1479 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1480 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1481}
1482
1483/**
1484 * e1000_free_rx_resources - Free Rx Resources
1485 * @adapter: board private structure
1486 *
1487 * Free all receive software resources
1488 **/
1489
1490void
1491e1000_free_rx_resources(struct e1000_adapter *adapter)
1492{
1493 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
1494 struct pci_dev *pdev = adapter->pdev;
1495
1496 e1000_clean_rx_ring(adapter);
1497
1498 vfree(rx_ring->buffer_info);
1499 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001500 kfree(rx_ring->ps_page);
1501 rx_ring->ps_page = NULL;
1502 kfree(rx_ring->ps_page_dma);
1503 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1506
1507 rx_ring->desc = NULL;
1508}
1509
1510/**
1511 * e1000_clean_rx_ring - Free Rx Buffers
1512 * @adapter: board private structure
1513 **/
1514
1515static void
1516e1000_clean_rx_ring(struct e1000_adapter *adapter)
1517{
1518 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
1519 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001520 struct e1000_ps_page *ps_page;
1521 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 struct pci_dev *pdev = adapter->pdev;
1523 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001524 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 /* Free all the Rx ring sk_buffs */
1527
1528 for(i = 0; i < rx_ring->count; i++) {
1529 buffer_info = &rx_ring->buffer_info[i];
1530 if(buffer_info->skb) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001531 ps_page = &rx_ring->ps_page[i];
1532 ps_page_dma = &rx_ring->ps_page_dma[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 pci_unmap_single(pdev,
1534 buffer_info->dma,
1535 buffer_info->length,
1536 PCI_DMA_FROMDEVICE);
1537
1538 dev_kfree_skb(buffer_info->skb);
1539 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001540
1541 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
1542 if(!ps_page->ps_page[j]) break;
1543 pci_unmap_single(pdev,
1544 ps_page_dma->ps_page_dma[j],
1545 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1546 ps_page_dma->ps_page_dma[j] = 0;
1547 put_page(ps_page->ps_page[j]);
1548 ps_page->ps_page[j] = NULL;
1549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 }
1551 }
1552
1553 size = sizeof(struct e1000_buffer) * rx_ring->count;
1554 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001555 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1556 memset(rx_ring->ps_page, 0, size);
1557 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1558 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
1560 /* Zero out the descriptor ring */
1561
1562 memset(rx_ring->desc, 0, rx_ring->size);
1563
1564 rx_ring->next_to_clean = 0;
1565 rx_ring->next_to_use = 0;
1566
1567 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1568 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1569}
1570
1571/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1572 * and memory write and invalidate disabled for certain operations
1573 */
1574static void
1575e1000_enter_82542_rst(struct e1000_adapter *adapter)
1576{
1577 struct net_device *netdev = adapter->netdev;
1578 uint32_t rctl;
1579
1580 e1000_pci_clear_mwi(&adapter->hw);
1581
1582 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1583 rctl |= E1000_RCTL_RST;
1584 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1585 E1000_WRITE_FLUSH(&adapter->hw);
1586 mdelay(5);
1587
1588 if(netif_running(netdev))
1589 e1000_clean_rx_ring(adapter);
1590}
1591
1592static void
1593e1000_leave_82542_rst(struct e1000_adapter *adapter)
1594{
1595 struct net_device *netdev = adapter->netdev;
1596 uint32_t rctl;
1597
1598 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1599 rctl &= ~E1000_RCTL_RST;
1600 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1601 E1000_WRITE_FLUSH(&adapter->hw);
1602 mdelay(5);
1603
1604 if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
1605 e1000_pci_set_mwi(&adapter->hw);
1606
1607 if(netif_running(netdev)) {
1608 e1000_configure_rx(adapter);
1609 e1000_alloc_rx_buffers(adapter);
1610 }
1611}
1612
1613/**
1614 * e1000_set_mac - Change the Ethernet Address of the NIC
1615 * @netdev: network interface device structure
1616 * @p: pointer to an address structure
1617 *
1618 * Returns 0 on success, negative on failure
1619 **/
1620
1621static int
1622e1000_set_mac(struct net_device *netdev, void *p)
1623{
1624 struct e1000_adapter *adapter = netdev->priv;
1625 struct sockaddr *addr = p;
1626
1627 if(!is_valid_ether_addr(addr->sa_data))
1628 return -EADDRNOTAVAIL;
1629
1630 /* 82542 2.0 needs to be in reset to write receive address registers */
1631
1632 if(adapter->hw.mac_type == e1000_82542_rev2_0)
1633 e1000_enter_82542_rst(adapter);
1634
1635 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1636 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
1637
1638 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
1639
1640 if(adapter->hw.mac_type == e1000_82542_rev2_0)
1641 e1000_leave_82542_rst(adapter);
1642
1643 return 0;
1644}
1645
1646/**
1647 * e1000_set_multi - Multicast and Promiscuous mode set
1648 * @netdev: network interface device structure
1649 *
1650 * The set_multi entry point is called whenever the multicast address
1651 * list or the network interface flags are updated. This routine is
1652 * responsible for configuring the hardware for proper multicast,
1653 * promiscuous mode, and all-multi behavior.
1654 **/
1655
1656static void
1657e1000_set_multi(struct net_device *netdev)
1658{
1659 struct e1000_adapter *adapter = netdev->priv;
1660 struct e1000_hw *hw = &adapter->hw;
1661 struct dev_mc_list *mc_ptr;
1662 uint32_t rctl;
1663 uint32_t hash_value;
1664 int i;
1665 unsigned long flags;
1666
1667 /* Check for Promiscuous and All Multicast modes */
1668
1669 spin_lock_irqsave(&adapter->tx_lock, flags);
1670
1671 rctl = E1000_READ_REG(hw, RCTL);
1672
1673 if(netdev->flags & IFF_PROMISC) {
1674 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1675 } else if(netdev->flags & IFF_ALLMULTI) {
1676 rctl |= E1000_RCTL_MPE;
1677 rctl &= ~E1000_RCTL_UPE;
1678 } else {
1679 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
1680 }
1681
1682 E1000_WRITE_REG(hw, RCTL, rctl);
1683
1684 /* 82542 2.0 needs to be in reset to write receive address registers */
1685
1686 if(hw->mac_type == e1000_82542_rev2_0)
1687 e1000_enter_82542_rst(adapter);
1688
1689 /* load the first 14 multicast address into the exact filters 1-14
1690 * RAR 0 is used for the station MAC adddress
1691 * if there are not 14 addresses, go ahead and clear the filters
1692 */
1693 mc_ptr = netdev->mc_list;
1694
1695 for(i = 1; i < E1000_RAR_ENTRIES; i++) {
1696 if(mc_ptr) {
1697 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
1698 mc_ptr = mc_ptr->next;
1699 } else {
1700 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
1701 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
1702 }
1703 }
1704
1705 /* clear the old settings from the multicast hash table */
1706
1707 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
1708 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1709
1710 /* load any remaining addresses into the hash table */
1711
1712 for(; mc_ptr; mc_ptr = mc_ptr->next) {
1713 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
1714 e1000_mta_set(hw, hash_value);
1715 }
1716
1717 if(hw->mac_type == e1000_82542_rev2_0)
1718 e1000_leave_82542_rst(adapter);
1719
1720 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1721}
1722
1723/* Need to wait a few seconds after link up to get diagnostic information from
1724 * the phy */
1725
1726static void
1727e1000_update_phy_info(unsigned long data)
1728{
1729 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1730 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
1731}
1732
1733/**
1734 * e1000_82547_tx_fifo_stall - Timer Call-back
1735 * @data: pointer to adapter cast into an unsigned long
1736 **/
1737
1738static void
1739e1000_82547_tx_fifo_stall(unsigned long data)
1740{
1741 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1742 struct net_device *netdev = adapter->netdev;
1743 uint32_t tctl;
1744
1745 if(atomic_read(&adapter->tx_fifo_stall)) {
1746 if((E1000_READ_REG(&adapter->hw, TDT) ==
1747 E1000_READ_REG(&adapter->hw, TDH)) &&
1748 (E1000_READ_REG(&adapter->hw, TDFT) ==
1749 E1000_READ_REG(&adapter->hw, TDFH)) &&
1750 (E1000_READ_REG(&adapter->hw, TDFTS) ==
1751 E1000_READ_REG(&adapter->hw, TDFHS))) {
1752 tctl = E1000_READ_REG(&adapter->hw, TCTL);
1753 E1000_WRITE_REG(&adapter->hw, TCTL,
1754 tctl & ~E1000_TCTL_EN);
1755 E1000_WRITE_REG(&adapter->hw, TDFT,
1756 adapter->tx_head_addr);
1757 E1000_WRITE_REG(&adapter->hw, TDFH,
1758 adapter->tx_head_addr);
1759 E1000_WRITE_REG(&adapter->hw, TDFTS,
1760 adapter->tx_head_addr);
1761 E1000_WRITE_REG(&adapter->hw, TDFHS,
1762 adapter->tx_head_addr);
1763 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
1764 E1000_WRITE_FLUSH(&adapter->hw);
1765
1766 adapter->tx_fifo_head = 0;
1767 atomic_set(&adapter->tx_fifo_stall, 0);
1768 netif_wake_queue(netdev);
1769 } else {
1770 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
1771 }
1772 }
1773}
1774
1775/**
1776 * e1000_watchdog - Timer Call-back
1777 * @data: pointer to adapter cast into an unsigned long
1778 **/
1779static void
1780e1000_watchdog(unsigned long data)
1781{
1782 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1783
1784 /* Do the rest outside of interrupt context */
1785 schedule_work(&adapter->watchdog_task);
1786}
1787
1788static void
1789e1000_watchdog_task(struct e1000_adapter *adapter)
1790{
1791 struct net_device *netdev = adapter->netdev;
1792 struct e1000_desc_ring *txdr = &adapter->tx_ring;
1793 uint32_t link;
1794
1795 e1000_check_for_link(&adapter->hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001796 if (adapter->hw.mac_type == e1000_82573) {
1797 e1000_enable_tx_pkt_filtering(&adapter->hw);
1798 if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
1799 e1000_update_mng_vlan(adapter);
1800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
1802 if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
1803 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
1804 link = !adapter->hw.serdes_link_down;
1805 else
1806 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
1807
1808 if(link) {
1809 if(!netif_carrier_ok(netdev)) {
1810 e1000_get_speed_and_duplex(&adapter->hw,
1811 &adapter->link_speed,
1812 &adapter->link_duplex);
1813
1814 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
1815 adapter->link_speed,
1816 adapter->link_duplex == FULL_DUPLEX ?
1817 "Full Duplex" : "Half Duplex");
1818
1819 netif_carrier_on(netdev);
1820 netif_wake_queue(netdev);
1821 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
1822 adapter->smartspeed = 0;
1823 }
1824 } else {
1825 if(netif_carrier_ok(netdev)) {
1826 adapter->link_speed = 0;
1827 adapter->link_duplex = 0;
1828 DPRINTK(LINK, INFO, "NIC Link is Down\n");
1829 netif_carrier_off(netdev);
1830 netif_stop_queue(netdev);
1831 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
1832 }
1833
1834 e1000_smartspeed(adapter);
1835 }
1836
1837 e1000_update_stats(adapter);
1838
1839 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
1840 adapter->tpt_old = adapter->stats.tpt;
1841 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
1842 adapter->colc_old = adapter->stats.colc;
1843
1844 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
1845 adapter->gorcl_old = adapter->stats.gorcl;
1846 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
1847 adapter->gotcl_old = adapter->stats.gotcl;
1848
1849 e1000_update_adaptive(&adapter->hw);
1850
1851 if(!netif_carrier_ok(netdev)) {
1852 if(E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
1853 /* We've lost link, so the controller stops DMA,
1854 * but we've got queued Tx work that's never going
1855 * to get done, so reset controller to flush Tx.
1856 * (Do the reset outside of interrupt context). */
1857 schedule_work(&adapter->tx_timeout_task);
1858 }
1859 }
1860
1861 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
1862 if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
1863 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
1864 * asymmetrical Tx or Rx gets ITR=8000; everyone
1865 * else is between 2000-8000. */
1866 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
1867 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
1868 adapter->gotcl - adapter->gorcl :
1869 adapter->gorcl - adapter->gotcl) / 10000;
1870 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
1871 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
1872 }
1873
1874 /* Cause software interrupt to ensure rx ring is cleaned */
1875 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
1876
1877 /* Force detection of hung controller every watchdog period*/
1878 adapter->detect_tx_hung = TRUE;
1879
1880 /* Reset the timer */
1881 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1882}
1883
1884#define E1000_TX_FLAGS_CSUM 0x00000001
1885#define E1000_TX_FLAGS_VLAN 0x00000002
1886#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001887#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
1889#define E1000_TX_FLAGS_VLAN_SHIFT 16
1890
1891static inline int
1892e1000_tso(struct e1000_adapter *adapter, struct sk_buff *skb)
1893{
1894#ifdef NETIF_F_TSO
1895 struct e1000_context_desc *context_desc;
1896 unsigned int i;
1897 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001898 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
1900 int err;
1901
1902 if(skb_shinfo(skb)->tso_size) {
1903 if (skb_header_cloned(skb)) {
1904 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1905 if (err)
1906 return err;
1907 }
1908
1909 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
1910 mss = skb_shinfo(skb)->tso_size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001911 if(skb->protocol == ntohs(ETH_P_IP)) {
1912 skb->nh.iph->tot_len = 0;
1913 skb->nh.iph->check = 0;
1914 skb->h.th->check =
1915 ~csum_tcpudp_magic(skb->nh.iph->saddr,
1916 skb->nh.iph->daddr,
1917 0,
1918 IPPROTO_TCP,
1919 0);
1920 cmd_length = E1000_TXD_CMD_IP;
1921 ipcse = skb->h.raw - skb->data - 1;
1922#ifdef NETIF_F_TSO_IPV6
1923 } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
1924 skb->nh.ipv6h->payload_len = 0;
1925 skb->h.th->check =
1926 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
1927 &skb->nh.ipv6h->daddr,
1928 0,
1929 IPPROTO_TCP,
1930 0);
1931 ipcse = 0;
1932#endif
1933 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 ipcss = skb->nh.raw - skb->data;
1935 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 tucss = skb->h.raw - skb->data;
1937 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
1938 tucse = 0;
1939
1940 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001941 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943 i = adapter->tx_ring.next_to_use;
1944 context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i);
1945
1946 context_desc->lower_setup.ip_fields.ipcss = ipcss;
1947 context_desc->lower_setup.ip_fields.ipcso = ipcso;
1948 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
1949 context_desc->upper_setup.tcp_fields.tucss = tucss;
1950 context_desc->upper_setup.tcp_fields.tucso = tucso;
1951 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
1952 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
1953 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
1954 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
1955
1956 if(++i == adapter->tx_ring.count) i = 0;
1957 adapter->tx_ring.next_to_use = i;
1958
1959 return 1;
1960 }
1961#endif
1962
1963 return 0;
1964}
1965
1966static inline boolean_t
1967e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
1968{
1969 struct e1000_context_desc *context_desc;
1970 unsigned int i;
1971 uint8_t css;
1972
1973 if(likely(skb->ip_summed == CHECKSUM_HW)) {
1974 css = skb->h.raw - skb->data;
1975
1976 i = adapter->tx_ring.next_to_use;
1977 context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i);
1978
1979 context_desc->upper_setup.tcp_fields.tucss = css;
1980 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
1981 context_desc->upper_setup.tcp_fields.tucse = 0;
1982 context_desc->tcp_seg_setup.data = 0;
1983 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
1984
1985 if(unlikely(++i == adapter->tx_ring.count)) i = 0;
1986 adapter->tx_ring.next_to_use = i;
1987
1988 return TRUE;
1989 }
1990
1991 return FALSE;
1992}
1993
1994#define E1000_MAX_TXD_PWR 12
1995#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
1996
1997static inline int
1998e1000_tx_map(struct e1000_adapter *adapter, struct sk_buff *skb,
1999 unsigned int first, unsigned int max_per_txd,
2000 unsigned int nr_frags, unsigned int mss)
2001{
2002 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2003 struct e1000_buffer *buffer_info;
2004 unsigned int len = skb->len;
2005 unsigned int offset = 0, size, count = 0, i;
2006 unsigned int f;
2007 len -= skb->data_len;
2008
2009 i = tx_ring->next_to_use;
2010
2011 while(len) {
2012 buffer_info = &tx_ring->buffer_info[i];
2013 size = min(len, max_per_txd);
2014#ifdef NETIF_F_TSO
2015 /* Workaround for premature desc write-backs
2016 * in TSO mode. Append 4-byte sentinel desc */
2017 if(unlikely(mss && !nr_frags && size == len && size > 8))
2018 size -= 4;
2019#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002020 /* work-around for errata 10 and it applies
2021 * to all controllers in PCI-X mode
2022 * The fix is to make sure that the first descriptor of a
2023 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2024 */
2025 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2026 (size > 2015) && count == 0))
2027 size = 2015;
2028
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 /* Workaround for potential 82544 hang in PCI-X. Avoid
2030 * terminating buffers within evenly-aligned dwords. */
2031 if(unlikely(adapter->pcix_82544 &&
2032 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2033 size > 4))
2034 size -= 4;
2035
2036 buffer_info->length = size;
2037 buffer_info->dma =
2038 pci_map_single(adapter->pdev,
2039 skb->data + offset,
2040 size,
2041 PCI_DMA_TODEVICE);
2042 buffer_info->time_stamp = jiffies;
2043
2044 len -= size;
2045 offset += size;
2046 count++;
2047 if(unlikely(++i == tx_ring->count)) i = 0;
2048 }
2049
2050 for(f = 0; f < nr_frags; f++) {
2051 struct skb_frag_struct *frag;
2052
2053 frag = &skb_shinfo(skb)->frags[f];
2054 len = frag->size;
2055 offset = frag->page_offset;
2056
2057 while(len) {
2058 buffer_info = &tx_ring->buffer_info[i];
2059 size = min(len, max_per_txd);
2060#ifdef NETIF_F_TSO
2061 /* Workaround for premature desc write-backs
2062 * in TSO mode. Append 4-byte sentinel desc */
2063 if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2064 size -= 4;
2065#endif
2066 /* Workaround for potential 82544 hang in PCI-X.
2067 * Avoid terminating buffers within evenly-aligned
2068 * dwords. */
2069 if(unlikely(adapter->pcix_82544 &&
2070 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2071 size > 4))
2072 size -= 4;
2073
2074 buffer_info->length = size;
2075 buffer_info->dma =
2076 pci_map_page(adapter->pdev,
2077 frag->page,
2078 offset,
2079 size,
2080 PCI_DMA_TODEVICE);
2081 buffer_info->time_stamp = jiffies;
2082
2083 len -= size;
2084 offset += size;
2085 count++;
2086 if(unlikely(++i == tx_ring->count)) i = 0;
2087 }
2088 }
2089
2090 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2091 tx_ring->buffer_info[i].skb = skb;
2092 tx_ring->buffer_info[first].next_to_watch = i;
2093
2094 return count;
2095}
2096
2097static inline void
2098e1000_tx_queue(struct e1000_adapter *adapter, int count, int tx_flags)
2099{
2100 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2101 struct e1000_tx_desc *tx_desc = NULL;
2102 struct e1000_buffer *buffer_info;
2103 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2104 unsigned int i;
2105
2106 if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2107 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2108 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002109 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2110
2111 if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
2112 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 }
2114
2115 if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2116 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2117 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2118 }
2119
2120 if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2121 txd_lower |= E1000_TXD_CMD_VLE;
2122 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2123 }
2124
2125 i = tx_ring->next_to_use;
2126
2127 while(count--) {
2128 buffer_info = &tx_ring->buffer_info[i];
2129 tx_desc = E1000_TX_DESC(*tx_ring, i);
2130 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2131 tx_desc->lower.data =
2132 cpu_to_le32(txd_lower | buffer_info->length);
2133 tx_desc->upper.data = cpu_to_le32(txd_upper);
2134 if(unlikely(++i == tx_ring->count)) i = 0;
2135 }
2136
2137 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2138
2139 /* Force memory writes to complete before letting h/w
2140 * know there are new descriptors to fetch. (Only
2141 * applicable for weak-ordered memory model archs,
2142 * such as IA-64). */
2143 wmb();
2144
2145 tx_ring->next_to_use = i;
2146 E1000_WRITE_REG(&adapter->hw, TDT, i);
2147}
2148
2149/**
2150 * 82547 workaround to avoid controller hang in half-duplex environment.
2151 * The workaround is to avoid queuing a large packet that would span
2152 * the internal Tx FIFO ring boundary by notifying the stack to resend
2153 * the packet at a later time. This gives the Tx FIFO an opportunity to
2154 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2155 * to the beginning of the Tx FIFO.
2156 **/
2157
2158#define E1000_FIFO_HDR 0x10
2159#define E1000_82547_PAD_LEN 0x3E0
2160
2161static inline int
2162e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2163{
2164 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2165 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2166
2167 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2168
2169 if(adapter->link_duplex != HALF_DUPLEX)
2170 goto no_fifo_stall_required;
2171
2172 if(atomic_read(&adapter->tx_fifo_stall))
2173 return 1;
2174
2175 if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2176 atomic_set(&adapter->tx_fifo_stall, 1);
2177 return 1;
2178 }
2179
2180no_fifo_stall_required:
2181 adapter->tx_fifo_head += skb_fifo_len;
2182 if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
2183 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2184 return 0;
2185}
2186
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002187#define MINIMUM_DHCP_PACKET_SIZE 282
2188static inline int
2189e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2190{
2191 struct e1000_hw *hw = &adapter->hw;
2192 uint16_t length, offset;
2193 if(vlan_tx_tag_present(skb)) {
2194 if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2195 ( adapter->hw.mng_cookie.status &
2196 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2197 return 0;
2198 }
2199 if(htons(ETH_P_IP) == skb->protocol) {
2200 const struct iphdr *ip = skb->nh.iph;
2201 if(IPPROTO_UDP == ip->protocol) {
2202 struct udphdr *udp = (struct udphdr *)(skb->h.uh);
2203 if(ntohs(udp->dest) == 67) {
2204 offset = (uint8_t *)udp + 8 - skb->data;
2205 length = skb->len - offset;
2206
2207 return e1000_mng_write_dhcp_info(hw,
2208 (uint8_t *)udp + 8, length);
2209 }
2210 }
2211 } else if((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
2212 struct ethhdr *eth = (struct ethhdr *) skb->data;
2213 if((htons(ETH_P_IP) == eth->h_proto)) {
2214 const struct iphdr *ip =
2215 (struct iphdr *)((uint8_t *)skb->data+14);
2216 if(IPPROTO_UDP == ip->protocol) {
2217 struct udphdr *udp =
2218 (struct udphdr *)((uint8_t *)ip +
2219 (ip->ihl << 2));
2220 if(ntohs(udp->dest) == 67) {
2221 offset = (uint8_t *)udp + 8 - skb->data;
2222 length = skb->len - offset;
2223
2224 return e1000_mng_write_dhcp_info(hw,
2225 (uint8_t *)udp + 8,
2226 length);
2227 }
2228 }
2229 }
2230 }
2231 return 0;
2232}
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2235static int
2236e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2237{
2238 struct e1000_adapter *adapter = netdev->priv;
2239 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2240 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2241 unsigned int tx_flags = 0;
2242 unsigned int len = skb->len;
2243 unsigned long flags;
2244 unsigned int nr_frags = 0;
2245 unsigned int mss = 0;
2246 int count = 0;
2247 int tso;
2248 unsigned int f;
2249 len -= skb->data_len;
2250
2251 if(unlikely(skb->len <= 0)) {
2252 dev_kfree_skb_any(skb);
2253 return NETDEV_TX_OK;
2254 }
2255
2256#ifdef NETIF_F_TSO
2257 mss = skb_shinfo(skb)->tso_size;
2258 /* The controller does a simple calculation to
2259 * make sure there is enough room in the FIFO before
2260 * initiating the DMA for each buffer. The calc is:
2261 * 4 = ceil(buffer len/mss). To make sure we don't
2262 * overrun the FIFO, adjust the max buffer len if mss
2263 * drops. */
2264 if(mss) {
2265 max_per_txd = min(mss << 2, max_per_txd);
2266 max_txd_pwr = fls(max_per_txd) - 1;
2267 }
2268
2269 if((mss) || (skb->ip_summed == CHECKSUM_HW))
2270 count++;
2271 count++; /* for sentinel desc */
2272#else
2273 if(skb->ip_summed == CHECKSUM_HW)
2274 count++;
2275#endif
2276 count += TXD_USE_COUNT(len, max_txd_pwr);
2277
2278 if(adapter->pcix_82544)
2279 count++;
2280
Malli Chilakala97338bd2005-04-28 19:41:46 -07002281 /* work-around for errata 10 and it applies to all controllers
2282 * in PCI-X mode, so add one more descriptor to the count
2283 */
2284 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2285 (len > 2015)))
2286 count++;
2287
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 nr_frags = skb_shinfo(skb)->nr_frags;
2289 for(f = 0; f < nr_frags; f++)
2290 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2291 max_txd_pwr);
2292 if(adapter->pcix_82544)
2293 count += nr_frags;
2294
2295 local_irq_save(flags);
2296 if (!spin_trylock(&adapter->tx_lock)) {
2297 /* Collision - tell upper layer to requeue */
2298 local_irq_restore(flags);
2299 return NETDEV_TX_LOCKED;
2300 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002301 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2302 e1000_transfer_dhcp_info(adapter, skb);
2303
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
2305 /* need: count + 2 desc gap to keep tail from touching
2306 * head, otherwise try next time */
2307 if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < count + 2)) {
2308 netif_stop_queue(netdev);
2309 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2310 return NETDEV_TX_BUSY;
2311 }
2312
2313 if(unlikely(adapter->hw.mac_type == e1000_82547)) {
2314 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2315 netif_stop_queue(netdev);
2316 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2317 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2318 return NETDEV_TX_BUSY;
2319 }
2320 }
2321
2322 if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2323 tx_flags |= E1000_TX_FLAGS_VLAN;
2324 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2325 }
2326
2327 first = adapter->tx_ring.next_to_use;
2328
2329 tso = e1000_tso(adapter, skb);
2330 if (tso < 0) {
2331 dev_kfree_skb_any(skb);
2332 return NETDEV_TX_OK;
2333 }
2334
2335 if (likely(tso))
2336 tx_flags |= E1000_TX_FLAGS_TSO;
2337 else if(likely(e1000_tx_csum(adapter, skb)))
2338 tx_flags |= E1000_TX_FLAGS_CSUM;
2339
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002340 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2341 * 82573 hardware supports TSO capabilities for IPv6 as well...
2342 * no longer assume, we must. */
2343 if(likely(skb->protocol == ntohs(ETH_P_IP)))
2344 tx_flags |= E1000_TX_FLAGS_IPV4;
2345
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 e1000_tx_queue(adapter,
2347 e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss),
2348 tx_flags);
2349
2350 netdev->trans_start = jiffies;
2351
2352 /* Make sure there is space in the ring for the next send. */
2353 if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < MAX_SKB_FRAGS + 2))
2354 netif_stop_queue(netdev);
2355
2356 spin_unlock_irqrestore(&adapter->tx_lock, flags);
2357 return NETDEV_TX_OK;
2358}
2359
2360/**
2361 * e1000_tx_timeout - Respond to a Tx Hang
2362 * @netdev: network interface device structure
2363 **/
2364
2365static void
2366e1000_tx_timeout(struct net_device *netdev)
2367{
2368 struct e1000_adapter *adapter = netdev->priv;
2369
2370 /* Do the reset outside of interrupt context */
2371 schedule_work(&adapter->tx_timeout_task);
2372}
2373
2374static void
2375e1000_tx_timeout_task(struct net_device *netdev)
2376{
2377 struct e1000_adapter *adapter = netdev->priv;
2378
2379 e1000_down(adapter);
2380 e1000_up(adapter);
2381}
2382
2383/**
2384 * e1000_get_stats - Get System Network Statistics
2385 * @netdev: network interface device structure
2386 *
2387 * Returns the address of the device statistics structure.
2388 * The statistics are actually updated from the timer callback.
2389 **/
2390
2391static struct net_device_stats *
2392e1000_get_stats(struct net_device *netdev)
2393{
2394 struct e1000_adapter *adapter = netdev->priv;
2395
2396 e1000_update_stats(adapter);
2397 return &adapter->net_stats;
2398}
2399
2400/**
2401 * e1000_change_mtu - Change the Maximum Transfer Unit
2402 * @netdev: network interface device structure
2403 * @new_mtu: new value for maximum frame size
2404 *
2405 * Returns 0 on success, negative on failure
2406 **/
2407
2408static int
2409e1000_change_mtu(struct net_device *netdev, int new_mtu)
2410{
2411 struct e1000_adapter *adapter = netdev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2413
2414 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2415 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2416 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
2417 return -EINVAL;
2418 }
2419
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002420#define MAX_STD_JUMBO_FRAME_SIZE 9216
2421 /* might want this to be bigger enum check... */
2422 if (adapter->hw.mac_type == e1000_82573 &&
2423 max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2424 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2425 "on 82573\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 }
2428
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002429 if(adapter->hw.mac_type > e1000_82547_rev_2) {
2430 adapter->rx_buffer_len = max_frame;
2431 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
2432 } else {
2433 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
2434 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
2435 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2436 "on 82542\n");
2437 return -EINVAL;
2438
2439 } else {
2440 if(max_frame <= E1000_RXBUFFER_2048) {
2441 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
2442 } else if(max_frame <= E1000_RXBUFFER_4096) {
2443 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
2444 } else if(max_frame <= E1000_RXBUFFER_8192) {
2445 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
2446 } else if(max_frame <= E1000_RXBUFFER_16384) {
2447 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
2448 }
2449 }
2450 }
2451
2452 netdev->mtu = new_mtu;
2453
2454 if(netif_running(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 e1000_down(adapter);
2456 e1000_up(adapter);
2457 }
2458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 adapter->hw.max_frame_size = max_frame;
2460
2461 return 0;
2462}
2463
2464/**
2465 * e1000_update_stats - Update the board statistics counters
2466 * @adapter: board private structure
2467 **/
2468
2469void
2470e1000_update_stats(struct e1000_adapter *adapter)
2471{
2472 struct e1000_hw *hw = &adapter->hw;
2473 unsigned long flags;
2474 uint16_t phy_tmp;
2475
2476#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2477
2478 spin_lock_irqsave(&adapter->stats_lock, flags);
2479
2480 /* these counters are modified from e1000_adjust_tbi_stats,
2481 * called from the interrupt context, so they must only
2482 * be written while holding adapter->stats_lock
2483 */
2484
2485 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
2486 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
2487 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
2488 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
2489 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
2490 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
2491 adapter->stats.roc += E1000_READ_REG(hw, ROC);
2492 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
2493 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
2494 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
2495 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
2496 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
2497 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
2498
2499 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
2500 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
2501 adapter->stats.scc += E1000_READ_REG(hw, SCC);
2502 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
2503 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
2504 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
2505 adapter->stats.dc += E1000_READ_REG(hw, DC);
2506 adapter->stats.sec += E1000_READ_REG(hw, SEC);
2507 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
2508 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
2509 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
2510 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
2511 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
2512 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
2513 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
2514 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
2515 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
2516 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
2517 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
2518 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
2519 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
2520 adapter->stats.torl += E1000_READ_REG(hw, TORL);
2521 adapter->stats.torh += E1000_READ_REG(hw, TORH);
2522 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
2523 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
2524 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
2525 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
2526 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
2527 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
2528 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
2529 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
2530 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
2531 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
2532 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
2533
2534 /* used for adaptive IFS */
2535
2536 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
2537 adapter->stats.tpt += hw->tx_packet_delta;
2538 hw->collision_delta = E1000_READ_REG(hw, COLC);
2539 adapter->stats.colc += hw->collision_delta;
2540
2541 if(hw->mac_type >= e1000_82543) {
2542 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
2543 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
2544 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
2545 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
2546 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
2547 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
2548 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002549 if(hw->mac_type > e1000_82547_rev_2) {
2550 adapter->stats.iac += E1000_READ_REG(hw, IAC);
2551 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
2552 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
2553 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
2554 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
2555 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
2556 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
2557 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
2558 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
2559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
2561 /* Fill out the OS statistics structure */
2562
2563 adapter->net_stats.rx_packets = adapter->stats.gprc;
2564 adapter->net_stats.tx_packets = adapter->stats.gptc;
2565 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
2566 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
2567 adapter->net_stats.multicast = adapter->stats.mprc;
2568 adapter->net_stats.collisions = adapter->stats.colc;
2569
2570 /* Rx Errors */
2571
2572 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
2573 adapter->stats.crcerrs + adapter->stats.algnerrc +
Malli Chilakala6d915752005-04-28 19:41:11 -07002574 adapter->stats.rlec + adapter->stats.mpc +
2575 adapter->stats.cexterr;
2576 adapter->net_stats.rx_dropped = adapter->stats.mpc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
2578 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
2579 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
2580 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
2581 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
2582
2583 /* Tx Errors */
2584
2585 adapter->net_stats.tx_errors = adapter->stats.ecol +
2586 adapter->stats.latecol;
2587 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
2588 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
2589 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
2590
2591 /* Tx Dropped needs to be maintained elsewhere */
2592
2593 /* Phy Stats */
2594
2595 if(hw->media_type == e1000_media_type_copper) {
2596 if((adapter->link_speed == SPEED_1000) &&
2597 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
2598 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
2599 adapter->phy_stats.idle_errors += phy_tmp;
2600 }
2601
2602 if((hw->mac_type <= e1000_82546) &&
2603 (hw->phy_type == e1000_phy_m88) &&
2604 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
2605 adapter->phy_stats.receive_errors += phy_tmp;
2606 }
2607
2608 spin_unlock_irqrestore(&adapter->stats_lock, flags);
2609}
2610
2611/**
2612 * e1000_intr - Interrupt Handler
2613 * @irq: interrupt number
2614 * @data: pointer to a network interface device structure
2615 * @pt_regs: CPU registers structure
2616 **/
2617
2618static irqreturn_t
2619e1000_intr(int irq, void *data, struct pt_regs *regs)
2620{
2621 struct net_device *netdev = data;
2622 struct e1000_adapter *adapter = netdev->priv;
2623 struct e1000_hw *hw = &adapter->hw;
2624 uint32_t icr = E1000_READ_REG(hw, ICR);
2625#ifndef CONFIG_E1000_NAPI
2626 unsigned int i;
2627#endif
2628
2629 if(unlikely(!icr))
2630 return IRQ_NONE; /* Not our interrupt */
2631
2632 if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
2633 hw->get_link_status = 1;
2634 mod_timer(&adapter->watchdog_timer, jiffies);
2635 }
2636
2637#ifdef CONFIG_E1000_NAPI
2638 if(likely(netif_rx_schedule_prep(netdev))) {
2639
2640 /* Disable interrupts and register for poll. The flush
2641 of the posted write is intentionally left out.
2642 */
2643
2644 atomic_inc(&adapter->irq_sem);
2645 E1000_WRITE_REG(hw, IMC, ~0);
2646 __netif_rx_schedule(netdev);
2647 }
2648#else
2649 /* Writing IMC and IMS is needed for 82547.
2650 Due to Hub Link bus being occupied, an interrupt
2651 de-assertion message is not able to be sent.
2652 When an interrupt assertion message is generated later,
2653 two messages are re-ordered and sent out.
2654 That causes APIC to think 82547 is in de-assertion
2655 state, while 82547 is in assertion state, resulting
2656 in dead lock. Writing IMC forces 82547 into
2657 de-assertion state.
2658 */
2659 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
2660 atomic_inc(&adapter->irq_sem);
2661 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
2662 }
2663
2664 for(i = 0; i < E1000_MAX_INTR; i++)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002665 if(unlikely(!adapter->clean_rx(adapter) &
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 !e1000_clean_tx_irq(adapter)))
2667 break;
2668
2669 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
2670 e1000_irq_enable(adapter);
2671#endif
2672
2673 return IRQ_HANDLED;
2674}
2675
2676#ifdef CONFIG_E1000_NAPI
2677/**
2678 * e1000_clean - NAPI Rx polling callback
2679 * @adapter: board private structure
2680 **/
2681
2682static int
2683e1000_clean(struct net_device *netdev, int *budget)
2684{
2685 struct e1000_adapter *adapter = netdev->priv;
2686 int work_to_do = min(*budget, netdev->quota);
2687 int tx_cleaned;
2688 int work_done = 0;
2689
2690 tx_cleaned = e1000_clean_tx_irq(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002691 adapter->clean_rx(adapter, &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
2693 *budget -= work_done;
2694 netdev->quota -= work_done;
2695
Malli Chilakalaf0d11ed2005-04-28 19:43:28 -07002696 /* If no Tx and no Rx work done, exit the polling mode */
2697 if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 netif_rx_complete(netdev);
2699 e1000_irq_enable(adapter);
2700 return 0;
2701 }
2702
2703 return 1;
2704}
2705
2706#endif
2707/**
2708 * e1000_clean_tx_irq - Reclaim resources after transmit completes
2709 * @adapter: board private structure
2710 **/
2711
2712static boolean_t
2713e1000_clean_tx_irq(struct e1000_adapter *adapter)
2714{
2715 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2716 struct net_device *netdev = adapter->netdev;
2717 struct e1000_tx_desc *tx_desc, *eop_desc;
2718 struct e1000_buffer *buffer_info;
2719 unsigned int i, eop;
2720 boolean_t cleaned = FALSE;
2721
2722 i = tx_ring->next_to_clean;
2723 eop = tx_ring->buffer_info[i].next_to_watch;
2724 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2725
2726 while(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Malli Chilakala27012342005-04-28 19:40:28 -07002727 /* Premature writeback of Tx descriptors clear (free buffers
2728 * and unmap pci_mapping) previous_buffer_info */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 if (likely(adapter->previous_buffer_info.skb != NULL)) {
Malli Chilakala27012342005-04-28 19:40:28 -07002730 e1000_unmap_and_free_tx_resource(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 &adapter->previous_buffer_info);
2732 }
2733
2734 for(cleaned = FALSE; !cleaned; ) {
2735 tx_desc = E1000_TX_DESC(*tx_ring, i);
2736 buffer_info = &tx_ring->buffer_info[i];
2737 cleaned = (i == eop);
2738
Malli Chilakala27012342005-04-28 19:40:28 -07002739#ifdef NETIF_F_TSO
2740 if (!(netdev->features & NETIF_F_TSO)) {
2741#endif
2742 e1000_unmap_and_free_tx_resource(adapter,
2743 buffer_info);
2744#ifdef NETIF_F_TSO
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 } else {
Malli Chilakala27012342005-04-28 19:40:28 -07002746 if (cleaned) {
2747 memcpy(&adapter->previous_buffer_info,
2748 buffer_info,
2749 sizeof(struct e1000_buffer));
2750 memset(buffer_info, 0,
2751 sizeof(struct e1000_buffer));
2752 } else {
2753 e1000_unmap_and_free_tx_resource(
2754 adapter, buffer_info);
2755 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 }
Malli Chilakala27012342005-04-28 19:40:28 -07002757#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758
2759 tx_desc->buffer_addr = 0;
2760 tx_desc->lower.data = 0;
2761 tx_desc->upper.data = 0;
2762
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 if(unlikely(++i == tx_ring->count)) i = 0;
2764 }
2765
2766 eop = tx_ring->buffer_info[i].next_to_watch;
2767 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2768 }
2769
2770 tx_ring->next_to_clean = i;
2771
2772 spin_lock(&adapter->tx_lock);
2773
2774 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
2775 netif_carrier_ok(netdev)))
2776 netif_wake_queue(netdev);
2777
2778 spin_unlock(&adapter->tx_lock);
2779
2780 if(adapter->detect_tx_hung) {
2781 /* detect a transmit hang in hardware, this serializes the
2782 * check with the clearing of time_stamp and movement of i */
2783 adapter->detect_tx_hung = FALSE;
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07002784 if (tx_ring->buffer_info[i].dma &&
2785 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
2786 && !(E1000_READ_REG(&adapter->hw, STATUS) &
2787 E1000_STATUS_TXOFF)) {
2788
2789 /* detected Tx unit hang */
2790 i = tx_ring->next_to_clean;
2791 eop = tx_ring->buffer_info[i].next_to_watch;
2792 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2793 DPRINTK(TX_ERR, ERR, "Detected Tx Unit Hang\n"
2794 " TDH <%x>\n"
2795 " TDT <%x>\n"
2796 " next_to_use <%x>\n"
2797 " next_to_clean <%x>\n"
2798 "buffer_info[next_to_clean]\n"
2799 " dma <%llx>\n"
2800 " time_stamp <%lx>\n"
2801 " next_to_watch <%x>\n"
2802 " jiffies <%lx>\n"
2803 " next_to_watch.status <%x>\n",
2804 E1000_READ_REG(&adapter->hw, TDH),
2805 E1000_READ_REG(&adapter->hw, TDT),
2806 tx_ring->next_to_use,
2807 i,
2808 tx_ring->buffer_info[i].dma,
2809 tx_ring->buffer_info[i].time_stamp,
2810 eop,
2811 jiffies,
2812 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07002814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 }
Malli Chilakala27012342005-04-28 19:40:28 -07002816#ifdef NETIF_F_TSO
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
Malli Chilakala27012342005-04-28 19:40:28 -07002818 if( unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
2819 time_after(jiffies, adapter->previous_buffer_info.time_stamp + HZ)))
2820 e1000_unmap_and_free_tx_resource(
2821 adapter, &adapter->previous_buffer_info);
2822
2823#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 return cleaned;
2825}
2826
2827/**
2828 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002829 * @adapter: board private structure
2830 * @status_err: receive descriptor status and error fields
2831 * @csum: receive descriptor csum field
2832 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 **/
2834
2835static inline void
2836e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002837 uint32_t status_err, uint32_t csum,
2838 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002840 uint16_t status = (uint16_t)status_err;
2841 uint8_t errors = (uint8_t)(status_err >> 24);
2842 skb->ip_summed = CHECKSUM_NONE;
2843
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 /* 82543 or newer only */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002845 if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 /* Ignore Checksum bit is set */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002847 if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
2848 /* TCP/UDP checksum error bit is set */
2849 if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
2850 /* let the stack verify checksum errors */
2851 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 return;
2853 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002854 /* TCP/UDP Checksum has not been calculated */
2855 if(adapter->hw.mac_type <= e1000_82547_rev_2) {
2856 if(!(status & E1000_RXD_STAT_TCPCS))
2857 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002859 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
2860 return;
2861 }
2862 /* It must be a TCP or UDP packet with a valid checksum */
2863 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 /* TCP checksum is good */
2865 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002866 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
2867 /* IP fragment with UDP payload */
2868 /* Hardware complements the payload checksum, so we undo it
2869 * and then put the value in host order for further stack use.
2870 */
2871 csum = ntohl(csum ^ 0xFFFF);
2872 skb->csum = csum;
2873 skb->ip_summed = CHECKSUM_HW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002875 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876}
2877
2878/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002879 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 * @adapter: board private structure
2881 **/
2882
2883static boolean_t
2884#ifdef CONFIG_E1000_NAPI
2885e1000_clean_rx_irq(struct e1000_adapter *adapter, int *work_done,
2886 int work_to_do)
2887#else
2888e1000_clean_rx_irq(struct e1000_adapter *adapter)
2889#endif
2890{
2891 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
2892 struct net_device *netdev = adapter->netdev;
2893 struct pci_dev *pdev = adapter->pdev;
2894 struct e1000_rx_desc *rx_desc;
2895 struct e1000_buffer *buffer_info;
2896 struct sk_buff *skb;
2897 unsigned long flags;
2898 uint32_t length;
2899 uint8_t last_byte;
2900 unsigned int i;
2901 boolean_t cleaned = FALSE;
2902
2903 i = rx_ring->next_to_clean;
2904 rx_desc = E1000_RX_DESC(*rx_ring, i);
2905
2906 while(rx_desc->status & E1000_RXD_STAT_DD) {
2907 buffer_info = &rx_ring->buffer_info[i];
2908#ifdef CONFIG_E1000_NAPI
2909 if(*work_done >= work_to_do)
2910 break;
2911 (*work_done)++;
2912#endif
2913 cleaned = TRUE;
2914
2915 pci_unmap_single(pdev,
2916 buffer_info->dma,
2917 buffer_info->length,
2918 PCI_DMA_FROMDEVICE);
2919
2920 skb = buffer_info->skb;
2921 length = le16_to_cpu(rx_desc->length);
2922
2923 if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
2924 /* All receives must fit into a single buffer */
2925 E1000_DBG("%s: Receive packet consumed multiple"
2926 " buffers\n", netdev->name);
2927 dev_kfree_skb_irq(skb);
2928 goto next_desc;
2929 }
2930
2931 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
2932 last_byte = *(skb->data + length - 1);
2933 if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
2934 rx_desc->errors, length, last_byte)) {
2935 spin_lock_irqsave(&adapter->stats_lock, flags);
2936 e1000_tbi_adjust_stats(&adapter->hw,
2937 &adapter->stats,
2938 length, skb->data);
2939 spin_unlock_irqrestore(&adapter->stats_lock,
2940 flags);
2941 length--;
2942 } else {
2943 dev_kfree_skb_irq(skb);
2944 goto next_desc;
2945 }
2946 }
2947
2948 /* Good Receive */
2949 skb_put(skb, length - ETHERNET_FCS_SIZE);
2950
2951 /* Receive Checksum Offload */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002952 e1000_rx_checksum(adapter,
2953 (uint32_t)(rx_desc->status) |
2954 ((uint32_t)(rx_desc->errors) << 24),
2955 rx_desc->csum, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 skb->protocol = eth_type_trans(skb, netdev);
2957#ifdef CONFIG_E1000_NAPI
2958 if(unlikely(adapter->vlgrp &&
2959 (rx_desc->status & E1000_RXD_STAT_VP))) {
2960 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002961 le16_to_cpu(rx_desc->special) &
2962 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 } else {
2964 netif_receive_skb(skb);
2965 }
2966#else /* CONFIG_E1000_NAPI */
2967 if(unlikely(adapter->vlgrp &&
2968 (rx_desc->status & E1000_RXD_STAT_VP))) {
2969 vlan_hwaccel_rx(skb, adapter->vlgrp,
2970 le16_to_cpu(rx_desc->special) &
2971 E1000_RXD_SPC_VLAN_MASK);
2972 } else {
2973 netif_rx(skb);
2974 }
2975#endif /* CONFIG_E1000_NAPI */
2976 netdev->last_rx = jiffies;
2977
2978next_desc:
2979 rx_desc->status = 0;
2980 buffer_info->skb = NULL;
2981 if(unlikely(++i == rx_ring->count)) i = 0;
2982
2983 rx_desc = E1000_RX_DESC(*rx_ring, i);
2984 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 rx_ring->next_to_clean = i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002986 adapter->alloc_rx_buf(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987
2988 return cleaned;
2989}
2990
2991/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002992 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
2993 * @adapter: board private structure
2994 **/
2995
2996static boolean_t
2997#ifdef CONFIG_E1000_NAPI
2998e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, int *work_done,
2999 int work_to_do)
3000#else
3001e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
3002#endif
3003{
3004 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3005 union e1000_rx_desc_packet_split *rx_desc;
3006 struct net_device *netdev = adapter->netdev;
3007 struct pci_dev *pdev = adapter->pdev;
3008 struct e1000_buffer *buffer_info;
3009 struct e1000_ps_page *ps_page;
3010 struct e1000_ps_page_dma *ps_page_dma;
3011 struct sk_buff *skb;
3012 unsigned int i, j;
3013 uint32_t length, staterr;
3014 boolean_t cleaned = FALSE;
3015
3016 i = rx_ring->next_to_clean;
3017 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3018 staterr = rx_desc->wb.middle.status_error;
3019
3020 while(staterr & E1000_RXD_STAT_DD) {
3021 buffer_info = &rx_ring->buffer_info[i];
3022 ps_page = &rx_ring->ps_page[i];
3023 ps_page_dma = &rx_ring->ps_page_dma[i];
3024#ifdef CONFIG_E1000_NAPI
3025 if(unlikely(*work_done >= work_to_do))
3026 break;
3027 (*work_done)++;
3028#endif
3029 cleaned = TRUE;
3030 pci_unmap_single(pdev, buffer_info->dma,
3031 buffer_info->length,
3032 PCI_DMA_FROMDEVICE);
3033
3034 skb = buffer_info->skb;
3035
3036 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3037 E1000_DBG("%s: Packet Split buffers didn't pick up"
3038 " the full packet\n", netdev->name);
3039 dev_kfree_skb_irq(skb);
3040 goto next_desc;
3041 }
3042
3043 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3044 dev_kfree_skb_irq(skb);
3045 goto next_desc;
3046 }
3047
3048 length = le16_to_cpu(rx_desc->wb.middle.length0);
3049
3050 if(unlikely(!length)) {
3051 E1000_DBG("%s: Last part of the packet spanning"
3052 " multiple descriptors\n", netdev->name);
3053 dev_kfree_skb_irq(skb);
3054 goto next_desc;
3055 }
3056
3057 /* Good Receive */
3058 skb_put(skb, length);
3059
3060 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3061 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3062 break;
3063
3064 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3065 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3066 ps_page_dma->ps_page_dma[j] = 0;
3067 skb_shinfo(skb)->frags[j].page =
3068 ps_page->ps_page[j];
3069 ps_page->ps_page[j] = NULL;
3070 skb_shinfo(skb)->frags[j].page_offset = 0;
3071 skb_shinfo(skb)->frags[j].size = length;
3072 skb_shinfo(skb)->nr_frags++;
3073 skb->len += length;
3074 skb->data_len += length;
3075 }
3076
3077 e1000_rx_checksum(adapter, staterr,
3078 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3079 skb->protocol = eth_type_trans(skb, netdev);
3080
3081#ifdef HAVE_RX_ZERO_COPY
3082 if(likely(rx_desc->wb.upper.header_status &
3083 E1000_RXDPS_HDRSTAT_HDRSP))
3084 skb_shinfo(skb)->zero_copy = TRUE;
3085#endif
3086#ifdef CONFIG_E1000_NAPI
3087 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3088 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3089 le16_to_cpu(rx_desc->wb.middle.vlan &
3090 E1000_RXD_SPC_VLAN_MASK));
3091 } else {
3092 netif_receive_skb(skb);
3093 }
3094#else /* CONFIG_E1000_NAPI */
3095 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3096 vlan_hwaccel_rx(skb, adapter->vlgrp,
3097 le16_to_cpu(rx_desc->wb.middle.vlan &
3098 E1000_RXD_SPC_VLAN_MASK));
3099 } else {
3100 netif_rx(skb);
3101 }
3102#endif /* CONFIG_E1000_NAPI */
3103 netdev->last_rx = jiffies;
3104
3105next_desc:
3106 rx_desc->wb.middle.status_error &= ~0xFF;
3107 buffer_info->skb = NULL;
3108 if(unlikely(++i == rx_ring->count)) i = 0;
3109
3110 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3111 staterr = rx_desc->wb.middle.status_error;
3112 }
3113 rx_ring->next_to_clean = i;
3114 adapter->alloc_rx_buf(adapter);
3115
3116 return cleaned;
3117}
3118
3119/**
3120 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 * @adapter: address of board private structure
3122 **/
3123
3124static void
3125e1000_alloc_rx_buffers(struct e1000_adapter *adapter)
3126{
3127 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3128 struct net_device *netdev = adapter->netdev;
3129 struct pci_dev *pdev = adapter->pdev;
3130 struct e1000_rx_desc *rx_desc;
3131 struct e1000_buffer *buffer_info;
3132 struct sk_buff *skb;
3133 unsigned int i, bufsz;
3134
3135 i = rx_ring->next_to_use;
3136 buffer_info = &rx_ring->buffer_info[i];
3137
3138 while(!buffer_info->skb) {
3139 bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3140
3141 skb = dev_alloc_skb(bufsz);
3142 if(unlikely(!skb)) {
3143 /* Better luck next round */
3144 break;
3145 }
3146
3147 /* fix for errata 23, cant cross 64kB boundary */
3148 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3149 struct sk_buff *oldskb = skb;
3150 DPRINTK(RX_ERR,ERR,
3151 "skb align check failed: %u bytes at %p\n",
3152 bufsz, skb->data);
3153 /* try again, without freeing the previous */
3154 skb = dev_alloc_skb(bufsz);
3155 if (!skb) {
3156 dev_kfree_skb(oldskb);
3157 break;
3158 }
3159 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3160 /* give up */
3161 dev_kfree_skb(skb);
3162 dev_kfree_skb(oldskb);
3163 break; /* while !buffer_info->skb */
3164 } else {
3165 /* move on with the new one */
3166 dev_kfree_skb(oldskb);
3167 }
3168 }
3169
3170 /* Make buffer alignment 2 beyond a 16 byte boundary
3171 * this will result in a 16 byte aligned IP header after
3172 * the 14 byte MAC header is removed
3173 */
3174 skb_reserve(skb, NET_IP_ALIGN);
3175
3176 skb->dev = netdev;
3177
3178 buffer_info->skb = skb;
3179 buffer_info->length = adapter->rx_buffer_len;
3180 buffer_info->dma = pci_map_single(pdev,
3181 skb->data,
3182 adapter->rx_buffer_len,
3183 PCI_DMA_FROMDEVICE);
3184
3185 /* fix for errata 23, cant cross 64kB boundary */
3186 if(!e1000_check_64k_bound(adapter,
3187 (void *)(unsigned long)buffer_info->dma,
3188 adapter->rx_buffer_len)) {
3189 DPRINTK(RX_ERR,ERR,
3190 "dma align check failed: %u bytes at %ld\n",
3191 adapter->rx_buffer_len, (unsigned long)buffer_info->dma);
3192
3193 dev_kfree_skb(skb);
3194 buffer_info->skb = NULL;
3195
3196 pci_unmap_single(pdev,
3197 buffer_info->dma,
3198 adapter->rx_buffer_len,
3199 PCI_DMA_FROMDEVICE);
3200
3201 break; /* while !buffer_info->skb */
3202 }
3203
3204 rx_desc = E1000_RX_DESC(*rx_ring, i);
3205 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3206
3207 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3208 /* Force memory writes to complete before letting h/w
3209 * know there are new descriptors to fetch. (Only
3210 * applicable for weak-ordered memory model archs,
3211 * such as IA-64). */
3212 wmb();
3213
3214 E1000_WRITE_REG(&adapter->hw, RDT, i);
3215 }
3216
3217 if(unlikely(++i == rx_ring->count)) i = 0;
3218 buffer_info = &rx_ring->buffer_info[i];
3219 }
3220
3221 rx_ring->next_to_use = i;
3222}
3223
3224/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003225 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3226 * @adapter: address of board private structure
3227 **/
3228
3229static void
3230e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter)
3231{
3232 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3233 struct net_device *netdev = adapter->netdev;
3234 struct pci_dev *pdev = adapter->pdev;
3235 union e1000_rx_desc_packet_split *rx_desc;
3236 struct e1000_buffer *buffer_info;
3237 struct e1000_ps_page *ps_page;
3238 struct e1000_ps_page_dma *ps_page_dma;
3239 struct sk_buff *skb;
3240 unsigned int i, j;
3241
3242 i = rx_ring->next_to_use;
3243 buffer_info = &rx_ring->buffer_info[i];
3244 ps_page = &rx_ring->ps_page[i];
3245 ps_page_dma = &rx_ring->ps_page_dma[i];
3246
3247 while(!buffer_info->skb) {
3248 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3249
3250 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3251 if(unlikely(!ps_page->ps_page[j])) {
3252 ps_page->ps_page[j] =
3253 alloc_page(GFP_ATOMIC);
3254 if(unlikely(!ps_page->ps_page[j]))
3255 goto no_buffers;
3256 ps_page_dma->ps_page_dma[j] =
3257 pci_map_page(pdev,
3258 ps_page->ps_page[j],
3259 0, PAGE_SIZE,
3260 PCI_DMA_FROMDEVICE);
3261 }
3262 /* Refresh the desc even if buffer_addrs didn't
3263 * change because each write-back erases this info.
3264 */
3265 rx_desc->read.buffer_addr[j+1] =
3266 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3267 }
3268
3269 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3270
3271 if(unlikely(!skb))
3272 break;
3273
3274 /* Make buffer alignment 2 beyond a 16 byte boundary
3275 * this will result in a 16 byte aligned IP header after
3276 * the 14 byte MAC header is removed
3277 */
3278 skb_reserve(skb, NET_IP_ALIGN);
3279
3280 skb->dev = netdev;
3281
3282 buffer_info->skb = skb;
3283 buffer_info->length = adapter->rx_ps_bsize0;
3284 buffer_info->dma = pci_map_single(pdev, skb->data,
3285 adapter->rx_ps_bsize0,
3286 PCI_DMA_FROMDEVICE);
3287
3288 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
3289
3290 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3291 /* Force memory writes to complete before letting h/w
3292 * know there are new descriptors to fetch. (Only
3293 * applicable for weak-ordered memory model archs,
3294 * such as IA-64). */
3295 wmb();
3296 /* Hardware increments by 16 bytes, but packet split
3297 * descriptors are 32 bytes...so we increment tail
3298 * twice as much.
3299 */
3300 E1000_WRITE_REG(&adapter->hw, RDT, i<<1);
3301 }
3302
3303 if(unlikely(++i == rx_ring->count)) i = 0;
3304 buffer_info = &rx_ring->buffer_info[i];
3305 ps_page = &rx_ring->ps_page[i];
3306 ps_page_dma = &rx_ring->ps_page_dma[i];
3307 }
3308
3309no_buffers:
3310 rx_ring->next_to_use = i;
3311}
3312
3313/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3315 * @adapter:
3316 **/
3317
3318static void
3319e1000_smartspeed(struct e1000_adapter *adapter)
3320{
3321 uint16_t phy_status;
3322 uint16_t phy_ctrl;
3323
3324 if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
3325 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
3326 return;
3327
3328 if(adapter->smartspeed == 0) {
3329 /* If Master/Slave config fault is asserted twice,
3330 * we assume back-to-back */
3331 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3332 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3333 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3334 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3335 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3336 if(phy_ctrl & CR_1000T_MS_ENABLE) {
3337 phy_ctrl &= ~CR_1000T_MS_ENABLE;
3338 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
3339 phy_ctrl);
3340 adapter->smartspeed++;
3341 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3342 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
3343 &phy_ctrl)) {
3344 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3345 MII_CR_RESTART_AUTO_NEG);
3346 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
3347 phy_ctrl);
3348 }
3349 }
3350 return;
3351 } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
3352 /* If still no link, perhaps using 2/3 pair cable */
3353 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3354 phy_ctrl |= CR_1000T_MS_ENABLE;
3355 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
3356 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3357 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
3358 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3359 MII_CR_RESTART_AUTO_NEG);
3360 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
3361 }
3362 }
3363 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3364 if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
3365 adapter->smartspeed = 0;
3366}
3367
3368/**
3369 * e1000_ioctl -
3370 * @netdev:
3371 * @ifreq:
3372 * @cmd:
3373 **/
3374
3375static int
3376e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3377{
3378 switch (cmd) {
3379 case SIOCGMIIPHY:
3380 case SIOCGMIIREG:
3381 case SIOCSMIIREG:
3382 return e1000_mii_ioctl(netdev, ifr, cmd);
3383 default:
3384 return -EOPNOTSUPP;
3385 }
3386}
3387
3388/**
3389 * e1000_mii_ioctl -
3390 * @netdev:
3391 * @ifreq:
3392 * @cmd:
3393 **/
3394
3395static int
3396e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3397{
3398 struct e1000_adapter *adapter = netdev->priv;
3399 struct mii_ioctl_data *data = if_mii(ifr);
3400 int retval;
3401 uint16_t mii_reg;
3402 uint16_t spddplx;
3403
3404 if(adapter->hw.media_type != e1000_media_type_copper)
3405 return -EOPNOTSUPP;
3406
3407 switch (cmd) {
3408 case SIOCGMIIPHY:
3409 data->phy_id = adapter->hw.phy_addr;
3410 break;
3411 case SIOCGMIIREG:
3412 if (!capable(CAP_NET_ADMIN))
3413 return -EPERM;
3414 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
3415 &data->val_out))
3416 return -EIO;
3417 break;
3418 case SIOCSMIIREG:
3419 if (!capable(CAP_NET_ADMIN))
3420 return -EPERM;
3421 if (data->reg_num & ~(0x1F))
3422 return -EFAULT;
3423 mii_reg = data->val_in;
3424 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
3425 mii_reg))
3426 return -EIO;
3427 if (adapter->hw.phy_type == e1000_phy_m88) {
3428 switch (data->reg_num) {
3429 case PHY_CTRL:
3430 if(mii_reg & MII_CR_POWER_DOWN)
3431 break;
3432 if(mii_reg & MII_CR_AUTO_NEG_EN) {
3433 adapter->hw.autoneg = 1;
3434 adapter->hw.autoneg_advertised = 0x2F;
3435 } else {
3436 if (mii_reg & 0x40)
3437 spddplx = SPEED_1000;
3438 else if (mii_reg & 0x2000)
3439 spddplx = SPEED_100;
3440 else
3441 spddplx = SPEED_10;
3442 spddplx += (mii_reg & 0x100)
3443 ? FULL_DUPLEX :
3444 HALF_DUPLEX;
3445 retval = e1000_set_spd_dplx(adapter,
3446 spddplx);
3447 if(retval)
3448 return retval;
3449 }
3450 if(netif_running(adapter->netdev)) {
3451 e1000_down(adapter);
3452 e1000_up(adapter);
3453 } else
3454 e1000_reset(adapter);
3455 break;
3456 case M88E1000_PHY_SPEC_CTRL:
3457 case M88E1000_EXT_PHY_SPEC_CTRL:
3458 if (e1000_phy_reset(&adapter->hw))
3459 return -EIO;
3460 break;
3461 }
3462 } else {
3463 switch (data->reg_num) {
3464 case PHY_CTRL:
3465 if(mii_reg & MII_CR_POWER_DOWN)
3466 break;
3467 if(netif_running(adapter->netdev)) {
3468 e1000_down(adapter);
3469 e1000_up(adapter);
3470 } else
3471 e1000_reset(adapter);
3472 break;
3473 }
3474 }
3475 break;
3476 default:
3477 return -EOPNOTSUPP;
3478 }
3479 return E1000_SUCCESS;
3480}
3481
3482void
3483e1000_pci_set_mwi(struct e1000_hw *hw)
3484{
3485 struct e1000_adapter *adapter = hw->back;
3486
3487 int ret;
3488 ret = pci_set_mwi(adapter->pdev);
3489}
3490
3491void
3492e1000_pci_clear_mwi(struct e1000_hw *hw)
3493{
3494 struct e1000_adapter *adapter = hw->back;
3495
3496 pci_clear_mwi(adapter->pdev);
3497}
3498
3499void
3500e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3501{
3502 struct e1000_adapter *adapter = hw->back;
3503
3504 pci_read_config_word(adapter->pdev, reg, value);
3505}
3506
3507void
3508e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
3509{
3510 struct e1000_adapter *adapter = hw->back;
3511
3512 pci_write_config_word(adapter->pdev, reg, *value);
3513}
3514
3515uint32_t
3516e1000_io_read(struct e1000_hw *hw, unsigned long port)
3517{
3518 return inl(port);
3519}
3520
3521void
3522e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
3523{
3524 outl(value, port);
3525}
3526
3527static void
3528e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
3529{
3530 struct e1000_adapter *adapter = netdev->priv;
3531 uint32_t ctrl, rctl;
3532
3533 e1000_irq_disable(adapter);
3534 adapter->vlgrp = grp;
3535
3536 if(grp) {
3537 /* enable VLAN tag insert/strip */
3538 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3539 ctrl |= E1000_CTRL_VME;
3540 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3541
3542 /* enable VLAN receive filtering */
3543 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3544 rctl |= E1000_RCTL_VFE;
3545 rctl &= ~E1000_RCTL_CFIEN;
3546 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003547 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 } else {
3549 /* disable VLAN tag insert/strip */
3550 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3551 ctrl &= ~E1000_CTRL_VME;
3552 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3553
3554 /* disable VLAN filtering */
3555 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3556 rctl &= ~E1000_RCTL_VFE;
3557 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003558 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
3559 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
3560 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
3561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 }
3563
3564 e1000_irq_enable(adapter);
3565}
3566
3567static void
3568e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
3569{
3570 struct e1000_adapter *adapter = netdev->priv;
3571 uint32_t vfta, index;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003572 if((adapter->hw.mng_cookie.status &
3573 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
3574 (vid == adapter->mng_vlan_id))
3575 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 /* add VID to filter table */
3577 index = (vid >> 5) & 0x7F;
3578 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
3579 vfta |= (1 << (vid & 0x1F));
3580 e1000_write_vfta(&adapter->hw, index, vfta);
3581}
3582
3583static void
3584e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
3585{
3586 struct e1000_adapter *adapter = netdev->priv;
3587 uint32_t vfta, index;
3588
3589 e1000_irq_disable(adapter);
3590
3591 if(adapter->vlgrp)
3592 adapter->vlgrp->vlan_devices[vid] = NULL;
3593
3594 e1000_irq_enable(adapter);
3595
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003596 if((adapter->hw.mng_cookie.status &
3597 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
3598 (vid == adapter->mng_vlan_id))
3599 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 /* remove VID from filter table */
3601 index = (vid >> 5) & 0x7F;
3602 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
3603 vfta &= ~(1 << (vid & 0x1F));
3604 e1000_write_vfta(&adapter->hw, index, vfta);
3605}
3606
3607static void
3608e1000_restore_vlan(struct e1000_adapter *adapter)
3609{
3610 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
3611
3612 if(adapter->vlgrp) {
3613 uint16_t vid;
3614 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
3615 if(!adapter->vlgrp->vlan_devices[vid])
3616 continue;
3617 e1000_vlan_rx_add_vid(adapter->netdev, vid);
3618 }
3619 }
3620}
3621
3622int
3623e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
3624{
3625 adapter->hw.autoneg = 0;
3626
3627 switch(spddplx) {
3628 case SPEED_10 + DUPLEX_HALF:
3629 adapter->hw.forced_speed_duplex = e1000_10_half;
3630 break;
3631 case SPEED_10 + DUPLEX_FULL:
3632 adapter->hw.forced_speed_duplex = e1000_10_full;
3633 break;
3634 case SPEED_100 + DUPLEX_HALF:
3635 adapter->hw.forced_speed_duplex = e1000_100_half;
3636 break;
3637 case SPEED_100 + DUPLEX_FULL:
3638 adapter->hw.forced_speed_duplex = e1000_100_full;
3639 break;
3640 case SPEED_1000 + DUPLEX_FULL:
3641 adapter->hw.autoneg = 1;
3642 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
3643 break;
3644 case SPEED_1000 + DUPLEX_HALF: /* not supported */
3645 default:
3646 DPRINTK(PROBE, ERR,
3647 "Unsupported Speed/Duplexity configuration\n");
3648 return -EINVAL;
3649 }
3650 return 0;
3651}
3652
3653static int
3654e1000_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3655{
3656 struct pci_dev *pdev = NULL;
3657
3658 switch(event) {
3659 case SYS_DOWN:
3660 case SYS_HALT:
3661 case SYS_POWER_OFF:
3662 while((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
3663 if(pci_dev_driver(pdev) == &e1000_driver)
3664 e1000_suspend(pdev, 3);
3665 }
3666 }
3667 return NOTIFY_DONE;
3668}
3669
3670static int
3671e1000_suspend(struct pci_dev *pdev, uint32_t state)
3672{
3673 struct net_device *netdev = pci_get_drvdata(pdev);
3674 struct e1000_adapter *adapter = netdev->priv;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003675 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 uint32_t wufc = adapter->wol;
3677
3678 netif_device_detach(netdev);
3679
3680 if(netif_running(netdev))
3681 e1000_down(adapter);
3682
3683 status = E1000_READ_REG(&adapter->hw, STATUS);
3684 if(status & E1000_STATUS_LU)
3685 wufc &= ~E1000_WUFC_LNKC;
3686
3687 if(wufc) {
3688 e1000_setup_rctl(adapter);
3689 e1000_set_multi(netdev);
3690
3691 /* turn on all-multi mode if wake on multicast is enabled */
3692 if(adapter->wol & E1000_WUFC_MC) {
3693 rctl = E1000_READ_REG(&adapter->hw, RCTL);
3694 rctl |= E1000_RCTL_MPE;
3695 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
3696 }
3697
3698 if(adapter->hw.mac_type >= e1000_82540) {
3699 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
3700 /* advertise wake from D3Cold */
3701 #define E1000_CTRL_ADVD3WUC 0x00100000
3702 /* phy power management enable */
3703 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3704 ctrl |= E1000_CTRL_ADVD3WUC |
3705 E1000_CTRL_EN_PHY_PWR_MGMT;
3706 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
3707 }
3708
3709 if(adapter->hw.media_type == e1000_media_type_fiber ||
3710 adapter->hw.media_type == e1000_media_type_internal_serdes) {
3711 /* keep the laser running in D3 */
3712 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
3713 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
3714 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
3715 }
3716
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003717 /* Allow time for pending master requests to run */
3718 e1000_disable_pciex_master(&adapter->hw);
3719
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
3721 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
3722 pci_enable_wake(pdev, 3, 1);
3723 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
3724 } else {
3725 E1000_WRITE_REG(&adapter->hw, WUC, 0);
3726 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
3727 pci_enable_wake(pdev, 3, 0);
3728 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
3729 }
3730
3731 pci_save_state(pdev);
3732
3733 if(adapter->hw.mac_type >= e1000_82540 &&
3734 adapter->hw.media_type == e1000_media_type_copper) {
3735 manc = E1000_READ_REG(&adapter->hw, MANC);
3736 if(manc & E1000_MANC_SMBUS_EN) {
3737 manc |= E1000_MANC_ARP_EN;
3738 E1000_WRITE_REG(&adapter->hw, MANC, manc);
3739 pci_enable_wake(pdev, 3, 1);
3740 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
3741 }
3742 }
3743
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003744 switch(adapter->hw.mac_type) {
3745 case e1000_82573:
3746 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3747 E1000_WRITE_REG(&adapter->hw, SWSM,
3748 swsm & ~E1000_SWSM_DRV_LOAD);
3749 break;
3750 default:
3751 break;
3752 }
3753
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 pci_disable_device(pdev);
3755
3756 state = (state > 0) ? 3 : 0;
3757 pci_set_power_state(pdev, state);
3758
3759 return 0;
3760}
3761
3762#ifdef CONFIG_PM
3763static int
3764e1000_resume(struct pci_dev *pdev)
3765{
3766 struct net_device *netdev = pci_get_drvdata(pdev);
3767 struct e1000_adapter *adapter = netdev->priv;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003768 uint32_t manc, ret, swsm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769
3770 pci_set_power_state(pdev, 0);
3771 pci_restore_state(pdev);
3772 ret = pci_enable_device(pdev);
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07003773 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774
3775 pci_enable_wake(pdev, 3, 0);
3776 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
3777
3778 e1000_reset(adapter);
3779 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
3780
3781 if(netif_running(netdev))
3782 e1000_up(adapter);
3783
3784 netif_device_attach(netdev);
3785
3786 if(adapter->hw.mac_type >= e1000_82540 &&
3787 adapter->hw.media_type == e1000_media_type_copper) {
3788 manc = E1000_READ_REG(&adapter->hw, MANC);
3789 manc &= ~(E1000_MANC_ARP_EN);
3790 E1000_WRITE_REG(&adapter->hw, MANC, manc);
3791 }
3792
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003793 switch(adapter->hw.mac_type) {
3794 case e1000_82573:
3795 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3796 E1000_WRITE_REG(&adapter->hw, SWSM,
3797 swsm | E1000_SWSM_DRV_LOAD);
3798 break;
3799 default:
3800 break;
3801 }
3802
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 return 0;
3804}
3805#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806#ifdef CONFIG_NET_POLL_CONTROLLER
3807/*
3808 * Polling 'interrupt' - used by things like netconsole to send skbs
3809 * without having to re-enable interrupts. It's not called while
3810 * the interrupt routine is executing.
3811 */
3812static void
3813e1000_netpoll (struct net_device *netdev)
3814{
3815 struct e1000_adapter *adapter = netdev->priv;
3816 disable_irq(adapter->pdev->irq);
3817 e1000_intr(adapter->pdev->irq, netdev, NULL);
3818 enable_irq(adapter->pdev->irq);
3819}
3820#endif
3821
3822/* e1000_main.c */