blob: 3f40a902de649e355601b27e472d82abf67008f2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include "e1000.h"
Andrew Mortond0bb53e2006-11-14 10:35:03 -050030#include <net/ip6_checksum.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032char e1000_driver_name[] = "e1000";
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010033static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#ifndef CONFIG_E1000_NAPI
35#define DRIVERNAPI
36#else
37#define DRIVERNAPI "-NAPI"
38#endif
Auke Kok25006ac2006-11-01 08:48:15 -080039#define DRV_VERSION "7.3.15-k2"DRIVERNAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -070040char e1000_driver_version[] = DRV_VERSION;
Auke Kok3d41e302006-04-14 19:05:31 -070041static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* e1000_pci_tbl - PCI Device ID Table
44 *
45 * Last entry must be all 0s
46 *
47 * Macro expands to...
48 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
49 */
50static struct pci_device_id e1000_pci_tbl[] = {
51 INTEL_E1000_ETHERNET_DEVICE(0x1000),
52 INTEL_E1000_ETHERNET_DEVICE(0x1001),
53 INTEL_E1000_ETHERNET_DEVICE(0x1004),
54 INTEL_E1000_ETHERNET_DEVICE(0x1008),
55 INTEL_E1000_ETHERNET_DEVICE(0x1009),
56 INTEL_E1000_ETHERNET_DEVICE(0x100C),
57 INTEL_E1000_ETHERNET_DEVICE(0x100D),
58 INTEL_E1000_ETHERNET_DEVICE(0x100E),
59 INTEL_E1000_ETHERNET_DEVICE(0x100F),
60 INTEL_E1000_ETHERNET_DEVICE(0x1010),
61 INTEL_E1000_ETHERNET_DEVICE(0x1011),
62 INTEL_E1000_ETHERNET_DEVICE(0x1012),
63 INTEL_E1000_ETHERNET_DEVICE(0x1013),
64 INTEL_E1000_ETHERNET_DEVICE(0x1014),
65 INTEL_E1000_ETHERNET_DEVICE(0x1015),
66 INTEL_E1000_ETHERNET_DEVICE(0x1016),
67 INTEL_E1000_ETHERNET_DEVICE(0x1017),
68 INTEL_E1000_ETHERNET_DEVICE(0x1018),
69 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -070070 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 INTEL_E1000_ETHERNET_DEVICE(0x101D),
72 INTEL_E1000_ETHERNET_DEVICE(0x101E),
73 INTEL_E1000_ETHERNET_DEVICE(0x1026),
74 INTEL_E1000_ETHERNET_DEVICE(0x1027),
75 INTEL_E1000_ETHERNET_DEVICE(0x1028),
Auke Kokae2c3862006-06-27 09:08:30 -070076 INTEL_E1000_ETHERNET_DEVICE(0x1049),
77 INTEL_E1000_ETHERNET_DEVICE(0x104A),
78 INTEL_E1000_ETHERNET_DEVICE(0x104B),
79 INTEL_E1000_ETHERNET_DEVICE(0x104C),
80 INTEL_E1000_ETHERNET_DEVICE(0x104D),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040081 INTEL_E1000_ETHERNET_DEVICE(0x105E),
82 INTEL_E1000_ETHERNET_DEVICE(0x105F),
83 INTEL_E1000_ETHERNET_DEVICE(0x1060),
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 INTEL_E1000_ETHERNET_DEVICE(0x1075),
85 INTEL_E1000_ETHERNET_DEVICE(0x1076),
86 INTEL_E1000_ETHERNET_DEVICE(0x1077),
87 INTEL_E1000_ETHERNET_DEVICE(0x1078),
88 INTEL_E1000_ETHERNET_DEVICE(0x1079),
89 INTEL_E1000_ETHERNET_DEVICE(0x107A),
90 INTEL_E1000_ETHERNET_DEVICE(0x107B),
91 INTEL_E1000_ETHERNET_DEVICE(0x107C),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040092 INTEL_E1000_ETHERNET_DEVICE(0x107D),
93 INTEL_E1000_ETHERNET_DEVICE(0x107E),
94 INTEL_E1000_ETHERNET_DEVICE(0x107F),
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Malli Chilakala26483452005-04-28 19:44:46 -070096 INTEL_E1000_ETHERNET_DEVICE(0x108B),
97 INTEL_E1000_ETHERNET_DEVICE(0x108C),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -080098 INTEL_E1000_ETHERNET_DEVICE(0x1096),
99 INTEL_E1000_ETHERNET_DEVICE(0x1098),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800100 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400101 INTEL_E1000_ETHERNET_DEVICE(0x109A),
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700102 INTEL_E1000_ETHERNET_DEVICE(0x10A4),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800103 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800104 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
Auke Kokae2c3862006-06-27 09:08:30 -0700105 INTEL_E1000_ETHERNET_DEVICE(0x10BA),
106 INTEL_E1000_ETHERNET_DEVICE(0x10BB),
Auke Kokfc2307d2006-11-01 08:47:56 -0800107 INTEL_E1000_ETHERNET_DEVICE(0x10BC),
108 INTEL_E1000_ETHERNET_DEVICE(0x10C4),
109 INTEL_E1000_ETHERNET_DEVICE(0x10C5),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 /* required last entry */
111 {0,}
112};
113
114MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
115
Nicholas Nunley35574762006-09-27 12:53:34 -0700116int e1000_up(struct e1000_adapter *adapter);
117void e1000_down(struct e1000_adapter *adapter);
118void e1000_reinit_locked(struct e1000_adapter *adapter);
119void e1000_reset(struct e1000_adapter *adapter);
120int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
121int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
122int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
123void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
124void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100125static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700126 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100127static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700128 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100129static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700130 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100131static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700132 struct e1000_rx_ring *rx_ring);
133void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135static int e1000_init_module(void);
136static void e1000_exit_module(void);
137static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
138static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400139static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140static int e1000_sw_init(struct e1000_adapter *adapter);
141static int e1000_open(struct net_device *netdev);
142static int e1000_close(struct net_device *netdev);
143static void e1000_configure_tx(struct e1000_adapter *adapter);
144static void e1000_configure_rx(struct e1000_adapter *adapter);
145static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400146static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
147static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
148static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
149 struct e1000_tx_ring *tx_ring);
150static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
151 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152static void e1000_set_multi(struct net_device *netdev);
153static void e1000_update_phy_info(unsigned long data);
154static void e1000_watchdog(unsigned long data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155static void e1000_82547_tx_fifo_stall(unsigned long data);
156static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
157static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
158static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
159static int e1000_set_mac(struct net_device *netdev, void *p);
David Howells7d12e782006-10-05 14:55:46 +0100160static irqreturn_t e1000_intr(int irq, void *data);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800161#ifdef CONFIG_PCI_MSI
162static irqreturn_t e1000_intr_msi(int irq, void *data);
163#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400164static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
165 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400167static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400169 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700171static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400172 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700173 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400175static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
176 struct e1000_rx_ring *rx_ring);
177static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
178 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400180static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800181 struct e1000_rx_ring *rx_ring,
182 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400183static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800184 struct e1000_rx_ring *rx_ring,
185 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
187static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
188 int cmd);
Nicholas Nunley35574762006-09-27 12:53:34 -0700189void e1000_set_ethtool_ops(struct net_device *netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
191static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
192static void e1000_tx_timeout(struct net_device *dev);
David Howells65f27f32006-11-22 14:55:48 +0000193static void e1000_reset_task(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700195static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
196 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
199static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
200static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
201static void e1000_restore_vlan(struct e1000_adapter *adapter);
202
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700203static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Auke Kok6fdfef12006-06-27 09:06:36 -0700204#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205static int e1000_resume(struct pci_dev *pdev);
206#endif
Auke Kokc653e632006-05-23 13:35:57 -0700207static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209#ifdef CONFIG_NET_POLL_CONTROLLER
210/* for netdump / net console */
211static void e1000_netpoll (struct net_device *netdev);
212#endif
213
Nicholas Nunley35574762006-09-27 12:53:34 -0700214extern void e1000_check_options(struct e1000_adapter *adapter);
215
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100216#define COPYBREAK_DEFAULT 256
217static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
218module_param(copybreak, uint, 0644);
219MODULE_PARM_DESC(copybreak,
220 "Maximum size of packet that is copied to a new buffer on receive");
221
Auke Kok90267292006-06-08 09:30:24 -0700222static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
223 pci_channel_state_t state);
224static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
225static void e1000_io_resume(struct pci_dev *pdev);
226
227static struct pci_error_handlers e1000_err_handler = {
228 .error_detected = e1000_io_error_detected,
229 .slot_reset = e1000_io_slot_reset,
230 .resume = e1000_io_resume,
231};
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233static struct pci_driver e1000_driver = {
234 .name = e1000_driver_name,
235 .id_table = e1000_pci_tbl,
236 .probe = e1000_probe,
237 .remove = __devexit_p(e1000_remove),
Auke Kokc4e24f02006-09-27 12:53:19 -0700238#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 /* Power Managment Hooks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .suspend = e1000_suspend,
Auke Kokc653e632006-05-23 13:35:57 -0700241 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#endif
Auke Kok90267292006-06-08 09:30:24 -0700243 .shutdown = e1000_shutdown,
244 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245};
246
247MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
248MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
249MODULE_LICENSE("GPL");
250MODULE_VERSION(DRV_VERSION);
251
252static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
253module_param(debug, int, 0);
254MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
255
256/**
257 * e1000_init_module - Driver Registration Routine
258 *
259 * e1000_init_module is the first routine called when the driver is
260 * loaded. All it does is register with the PCI subsystem.
261 **/
262
263static int __init
264e1000_init_module(void)
265{
266 int ret;
267 printk(KERN_INFO "%s - version %s\n",
268 e1000_driver_string, e1000_driver_version);
269
270 printk(KERN_INFO "%s\n", e1000_copyright);
271
Jeff Garzik29917622006-08-19 17:48:59 -0400272 ret = pci_register_driver(&e1000_driver);
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100273 if (copybreak != COPYBREAK_DEFAULT) {
274 if (copybreak == 0)
275 printk(KERN_INFO "e1000: copybreak disabled\n");
276 else
277 printk(KERN_INFO "e1000: copybreak enabled for "
278 "packets <= %u bytes\n", copybreak);
279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 return ret;
281}
282
283module_init(e1000_init_module);
284
285/**
286 * e1000_exit_module - Driver Exit Cleanup Routine
287 *
288 * e1000_exit_module is called just before the driver is removed
289 * from memory.
290 **/
291
292static void __exit
293e1000_exit_module(void)
294{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 pci_unregister_driver(&e1000_driver);
296}
297
298module_exit(e1000_exit_module);
299
Auke Kok2db10a02006-06-27 09:06:28 -0700300static int e1000_request_irq(struct e1000_adapter *adapter)
301{
302 struct net_device *netdev = adapter->netdev;
303 int flags, err = 0;
304
Jeff Garzikc0bc8722006-07-05 14:32:39 -0400305 flags = IRQF_SHARED;
Auke Kok2db10a02006-06-27 09:06:28 -0700306#ifdef CONFIG_PCI_MSI
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800307 if (adapter->hw.mac_type >= e1000_82571) {
Auke Kok2db10a02006-06-27 09:06:28 -0700308 adapter->have_msi = TRUE;
309 if ((err = pci_enable_msi(adapter->pdev))) {
310 DPRINTK(PROBE, ERR,
311 "Unable to allocate MSI interrupt Error: %d\n", err);
312 adapter->have_msi = FALSE;
313 }
314 }
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800315 if (adapter->have_msi) {
Andrew Morton61ef5c02006-07-06 23:58:19 -0700316 flags &= ~IRQF_SHARED;
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800317 err = request_irq(adapter->pdev->irq, &e1000_intr_msi, flags,
318 netdev->name, netdev);
319 if (err)
320 DPRINTK(PROBE, ERR,
321 "Unable to allocate interrupt Error: %d\n", err);
322 } else
Auke Kok2db10a02006-06-27 09:06:28 -0700323#endif
324 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
325 netdev->name, netdev)))
326 DPRINTK(PROBE, ERR,
327 "Unable to allocate interrupt Error: %d\n", err);
328
329 return err;
330}
331
332static void e1000_free_irq(struct e1000_adapter *adapter)
333{
334 struct net_device *netdev = adapter->netdev;
335
336 free_irq(adapter->pdev->irq, netdev);
337
338#ifdef CONFIG_PCI_MSI
339 if (adapter->have_msi)
340 pci_disable_msi(adapter->pdev);
341#endif
342}
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344/**
345 * e1000_irq_disable - Mask off interrupt generation on the NIC
346 * @adapter: board private structure
347 **/
348
Auke Koke619d522006-04-14 19:04:52 -0700349static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350e1000_irq_disable(struct e1000_adapter *adapter)
351{
352 atomic_inc(&adapter->irq_sem);
353 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
354 E1000_WRITE_FLUSH(&adapter->hw);
355 synchronize_irq(adapter->pdev->irq);
356}
357
358/**
359 * e1000_irq_enable - Enable default interrupt generation settings
360 * @adapter: board private structure
361 **/
362
Auke Koke619d522006-04-14 19:04:52 -0700363static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364e1000_irq_enable(struct e1000_adapter *adapter)
365{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800366 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
368 E1000_WRITE_FLUSH(&adapter->hw);
369 }
370}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100371
372static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700373e1000_update_mng_vlan(struct e1000_adapter *adapter)
374{
375 struct net_device *netdev = adapter->netdev;
376 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
377 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800378 if (adapter->vlgrp) {
379 if (!adapter->vlgrp->vlan_devices[vid]) {
380 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700381 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
382 e1000_vlan_rx_add_vid(netdev, vid);
383 adapter->mng_vlan_id = vid;
384 } else
385 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800386
387 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
388 (vid != old_vid) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700389 !adapter->vlgrp->vlan_devices[old_vid])
390 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800391 } else
392 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700393 }
394}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800395
396/**
397 * e1000_release_hw_control - release control of the h/w to f/w
398 * @adapter: address of board private structure
399 *
400 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
401 * For ASF and Pass Through versions of f/w this means that the
402 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800403 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700404 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800405 **/
406
Auke Koke619d522006-04-14 19:04:52 -0700407static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800408e1000_release_hw_control(struct e1000_adapter *adapter)
409{
410 uint32_t ctrl_ext;
411 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700412 uint32_t extcnf;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800413
414 /* Let firmware taken over control of h/w */
415 switch (adapter->hw.mac_type) {
416 case e1000_82571:
417 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700418 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800419 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
420 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
421 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
422 break;
423 case e1000_82573:
424 swsm = E1000_READ_REG(&adapter->hw, SWSM);
425 E1000_WRITE_REG(&adapter->hw, SWSM,
426 swsm & ~E1000_SWSM_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700427 case e1000_ich8lan:
428 extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
429 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
430 extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
431 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800432 default:
433 break;
434 }
435}
436
437/**
438 * e1000_get_hw_control - get control of the h/w from f/w
439 * @adapter: address of board private structure
440 *
441 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700442 * For ASF and Pass Through versions of f/w this means that
443 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800444 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700445 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800446 **/
447
Auke Koke619d522006-04-14 19:04:52 -0700448static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800449e1000_get_hw_control(struct e1000_adapter *adapter)
450{
451 uint32_t ctrl_ext;
452 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700453 uint32_t extcnf;
Auke Kok90fb5132006-11-01 08:47:30 -0800454
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800455 /* Let firmware know the driver has taken over */
456 switch (adapter->hw.mac_type) {
457 case e1000_82571:
458 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700459 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800460 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
461 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
462 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
463 break;
464 case e1000_82573:
465 swsm = E1000_READ_REG(&adapter->hw, SWSM);
466 E1000_WRITE_REG(&adapter->hw, SWSM,
467 swsm | E1000_SWSM_DRV_LOAD);
468 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700469 case e1000_ich8lan:
470 extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
471 E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
472 extcnf | E1000_EXTCNF_CTRL_SWFLAG);
473 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800474 default:
475 break;
476 }
477}
478
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500479static void
480e1000_init_manageability(struct e1000_adapter *adapter)
481{
482 if (adapter->en_mng_pt) {
483 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
484
485 /* disable hardware interception of ARP */
486 manc &= ~(E1000_MANC_ARP_EN);
487
488 /* enable receiving management packets to the host */
489 /* this will probably generate destination unreachable messages
490 * from the host OS, but the packets will be handled on SMBUS */
491 if (adapter->hw.has_manc2h) {
492 uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
493
494 manc |= E1000_MANC_EN_MNG2HOST;
495#define E1000_MNG2HOST_PORT_623 (1 << 5)
496#define E1000_MNG2HOST_PORT_664 (1 << 6)
497 manc2h |= E1000_MNG2HOST_PORT_623;
498 manc2h |= E1000_MNG2HOST_PORT_664;
499 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
500 }
501
502 E1000_WRITE_REG(&adapter->hw, MANC, manc);
503 }
504}
505
506static void
507e1000_release_manageability(struct e1000_adapter *adapter)
508{
509 if (adapter->en_mng_pt) {
510 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
511
512 /* re-enable hardware interception of ARP */
513 manc |= E1000_MANC_ARP_EN;
514
515 if (adapter->hw.has_manc2h)
516 manc &= ~E1000_MANC_EN_MNG2HOST;
517
518 /* don't explicitly have to mess with MANC2H since
519 * MANC has an enable disable that gates MANC2H */
520
521 E1000_WRITE_REG(&adapter->hw, MANC, manc);
522 }
523}
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525int
526e1000_up(struct e1000_adapter *adapter)
527{
528 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700529 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 /* hardware has been reset, we need to reload some things */
532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 e1000_set_multi(netdev);
534
535 e1000_restore_vlan(adapter);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500536 e1000_init_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 e1000_configure_tx(adapter);
539 e1000_setup_rctl(adapter);
540 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800541 /* call E1000_DESC_UNUSED which always leaves
542 * at least 1 descriptor unused to make sure
543 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800544 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800545 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800546 adapter->alloc_rx_buf(adapter, ring,
547 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800550 adapter->tx_queue_len = netdev->tx_queue_len;
551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#ifdef CONFIG_E1000_NAPI
553 netif_poll_enable(netdev);
554#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700555 e1000_irq_enable(adapter);
556
Auke Kok1314bbf2006-09-27 12:54:02 -0700557 clear_bit(__E1000_DOWN, &adapter->flags);
558
559 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 return 0;
561}
562
Auke Kok79f05bf2006-06-27 09:06:32 -0700563/**
564 * e1000_power_up_phy - restore link in case the phy was powered down
565 * @adapter: address of board private structure
566 *
567 * The phy may be powered down to save power and turn off link when the
568 * driver is unloaded and wake on lan is not enabled (among others)
569 * *** this routine MUST be followed by a call to e1000_reset ***
570 *
571 **/
572
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700573void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700574{
575 uint16_t mii_reg = 0;
576
577 /* Just clear the power down bit to wake the phy back up */
578 if (adapter->hw.media_type == e1000_media_type_copper) {
579 /* according to the manual, the phy will retain its
580 * settings across a power-down/up cycle */
581 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
582 mii_reg &= ~MII_CR_POWER_DOWN;
583 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
584 }
585}
586
587static void e1000_power_down_phy(struct e1000_adapter *adapter)
588{
Bruce Allan61c25052006-09-27 12:53:54 -0700589 /* Power down the PHY so no link is implied when interface is down *
590 * The PHY cannot be powered down if any of the following is TRUE *
Auke Kok79f05bf2006-06-27 09:06:32 -0700591 * (a) WoL is enabled
592 * (b) AMT is active
593 * (c) SoL/IDER session is active */
594 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700595 adapter->hw.media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700596 uint16_t mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700597
598 switch (adapter->hw.mac_type) {
599 case e1000_82540:
600 case e1000_82545:
601 case e1000_82545_rev_3:
602 case e1000_82546:
603 case e1000_82546_rev_3:
604 case e1000_82541:
605 case e1000_82541_rev_2:
606 case e1000_82547:
607 case e1000_82547_rev_2:
608 if (E1000_READ_REG(&adapter->hw, MANC) &
609 E1000_MANC_SMBUS_EN)
610 goto out;
611 break;
612 case e1000_82571:
613 case e1000_82572:
614 case e1000_82573:
615 case e1000_80003es2lan:
616 case e1000_ich8lan:
617 if (e1000_check_mng_mode(&adapter->hw) ||
618 e1000_check_phy_reset_block(&adapter->hw))
619 goto out;
620 break;
621 default:
622 goto out;
623 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700624 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
625 mii_reg |= MII_CR_POWER_DOWN;
626 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
627 mdelay(1);
628 }
Bruce Allan61c25052006-09-27 12:53:54 -0700629out:
630 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700631}
632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633void
634e1000_down(struct e1000_adapter *adapter)
635{
636 struct net_device *netdev = adapter->netdev;
637
Auke Kok1314bbf2006-09-27 12:54:02 -0700638 /* signal that we're down so the interrupt handler does not
639 * reschedule our watchdog timer */
640 set_bit(__E1000_DOWN, &adapter->flags);
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 del_timer_sync(&adapter->tx_fifo_stall_timer);
645 del_timer_sync(&adapter->watchdog_timer);
646 del_timer_sync(&adapter->phy_info_timer);
647
648#ifdef CONFIG_E1000_NAPI
649 netif_poll_disable(netdev);
650#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800651 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 adapter->link_speed = 0;
653 adapter->link_duplex = 0;
654 netif_carrier_off(netdev);
655 netif_stop_queue(netdev);
656
657 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400658 e1000_clean_all_tx_rings(adapter);
659 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662void
Auke Kok2db10a02006-06-27 09:06:28 -0700663e1000_reinit_locked(struct e1000_adapter *adapter)
664{
665 WARN_ON(in_interrupt());
666 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
667 msleep(1);
668 e1000_down(adapter);
669 e1000_up(adapter);
670 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671}
672
673void
674e1000_reset(struct e1000_adapter *adapter)
675{
Bruce Allan018ea442006-12-15 10:39:45 +0100676 uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700677 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Bruce Allan018ea442006-12-15 10:39:45 +0100678 boolean_t legacy_pba_adjust = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 /* Repartition Pba for greater than 9k mtu
681 * To take effect CTRL.RST is required.
682 */
683
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700684 switch (adapter->hw.mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100685 case e1000_82542_rev2_0:
686 case e1000_82542_rev2_1:
687 case e1000_82543:
688 case e1000_82544:
689 case e1000_82540:
690 case e1000_82541:
691 case e1000_82541_rev_2:
692 legacy_pba_adjust = TRUE;
693 pba = E1000_PBA_48K;
694 break;
695 case e1000_82545:
696 case e1000_82545_rev_3:
697 case e1000_82546:
698 case e1000_82546_rev_3:
699 pba = E1000_PBA_48K;
700 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700701 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700702 case e1000_82547_rev_2:
Bruce Allan018ea442006-12-15 10:39:45 +0100703 legacy_pba_adjust = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700704 pba = E1000_PBA_30K;
705 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400706 case e1000_82571:
707 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800708 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400709 pba = E1000_PBA_38K;
710 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700711 case e1000_82573:
Bruce Allan018ea442006-12-15 10:39:45 +0100712 pba = E1000_PBA_20K;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700713 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700714 case e1000_ich8lan:
715 pba = E1000_PBA_8K;
Bruce Allan018ea442006-12-15 10:39:45 +0100716 case e1000_undefined:
717 case e1000_num_macs:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700718 break;
719 }
720
Bruce Allan018ea442006-12-15 10:39:45 +0100721 if (legacy_pba_adjust == TRUE) {
722 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
723 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700724
Bruce Allan018ea442006-12-15 10:39:45 +0100725 if (adapter->hw.mac_type == e1000_82547) {
726 adapter->tx_fifo_head = 0;
727 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
728 adapter->tx_fifo_size =
729 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
730 atomic_set(&adapter->tx_fifo_stall, 0);
731 }
732 } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
733 /* adjust PBA for jumbo frames */
734 E1000_WRITE_REG(&adapter->hw, PBA, pba);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700735
Bruce Allan018ea442006-12-15 10:39:45 +0100736 /* To maintain wire speed transmits, the Tx FIFO should be
737 * large enough to accomodate two full transmit packets,
738 * rounded up to the next 1KB and expressed in KB. Likewise,
739 * the Rx FIFO should be large enough to accomodate at least
740 * one full receive packet and is similarly rounded up and
741 * expressed in KB. */
742 pba = E1000_READ_REG(&adapter->hw, PBA);
743 /* upper 16 bits has Tx packet buffer allocation size in KB */
744 tx_space = pba >> 16;
745 /* lower 16 bits has Rx packet buffer allocation size in KB */
746 pba &= 0xffff;
747 /* don't include ethernet FCS because hardware appends/strips */
748 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
749 VLAN_TAG_SIZE;
750 min_tx_space = min_rx_space;
751 min_tx_space *= 2;
752 E1000_ROUNDUP(min_tx_space, 1024);
753 min_tx_space >>= 10;
754 E1000_ROUNDUP(min_rx_space, 1024);
755 min_rx_space >>= 10;
756
757 /* If current Tx allocation is less than the min Tx FIFO size,
758 * and the min Tx FIFO size is less than the current Rx FIFO
759 * allocation, take space away from current Rx allocation */
760 if (tx_space < min_tx_space &&
761 ((min_tx_space - tx_space) < pba)) {
762 pba = pba - (min_tx_space - tx_space);
763
764 /* PCI/PCIx hardware has PBA alignment constraints */
765 switch (adapter->hw.mac_type) {
766 case e1000_82545 ... e1000_82546_rev_3:
767 pba &= ~(E1000_PBA_8K - 1);
768 break;
769 default:
770 break;
771 }
772
773 /* if short on rx space, rx wins and must trump tx
774 * adjustment or use Early Receive if available */
775 if (pba < min_rx_space) {
776 switch (adapter->hw.mac_type) {
777 case e1000_82573:
778 /* ERT enabled in e1000_configure_rx */
779 break;
780 default:
781 pba = min_rx_space;
782 break;
783 }
784 }
785 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 E1000_WRITE_REG(&adapter->hw, PBA, pba);
789
790 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800791 /* Set the FC high water mark to 90% of the FIFO size.
792 * Required to clear last 3 LSB */
793 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700794 /* We can't use 90% on small FIFOs because the remainder
795 * would be less than 1 full frame. In this case, we size
796 * it to allow at least a full frame above the high water
797 * mark. */
798 if (pba < E1000_PBA_16K)
799 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800800
801 adapter->hw.fc_high_water = fc_high_water_mark;
802 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800803 if (adapter->hw.mac_type == e1000_80003es2lan)
804 adapter->hw.fc_pause_time = 0xFFFF;
805 else
806 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 adapter->hw.fc_send_xon = 1;
808 adapter->hw.fc = adapter->hw.original_fc;
809
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700810 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800812 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700814
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800815 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700817 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100818
819 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
820 if (adapter->hw.mac_type >= e1000_82544 &&
821 adapter->hw.mac_type <= e1000_82547_rev_2 &&
822 adapter->hw.autoneg == 1 &&
823 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
824 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
825 /* clear phy power management bit if we are in gig only mode,
826 * which if enabled will attempt negotiation to 100Mb, which
827 * can cause a loss of link at power off or driver unload */
828 ctrl &= ~E1000_CTRL_SWDPIN3;
829 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
830 }
831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
833 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
834
835 e1000_reset_adaptive(&adapter->hw);
836 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700837
838 if (!adapter->smart_power_down &&
839 (adapter->hw.mac_type == e1000_82571 ||
840 adapter->hw.mac_type == e1000_82572)) {
841 uint16_t phy_data = 0;
842 /* speed up time to link by disabling smart power down, ignore
843 * the return value of this function because there is nothing
844 * different we would do if it failed */
845 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
846 &phy_data);
847 phy_data &= ~IGP02E1000_PM_SPD;
848 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
849 phy_data);
850 }
851
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500852 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
854
855/**
856 * e1000_probe - Device Initialization Routine
857 * @pdev: PCI device information struct
858 * @ent: entry in e1000_pci_tbl
859 *
860 * Returns 0 on success, negative on failure
861 *
862 * e1000_probe initializes an adapter identified by a pci_dev structure.
863 * The OS initialization, configuring of the adapter private structure,
864 * and a hardware reset occur.
865 **/
866
867static int __devinit
868e1000_probe(struct pci_dev *pdev,
869 const struct pci_device_id *ent)
870{
871 struct net_device *netdev;
872 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700873 unsigned long mmio_start, mmio_len;
Auke Kokcd94dd02006-06-27 09:08:22 -0700874 unsigned long flash_start, flash_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700877 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700878 int i, err, pci_using_dac;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700879 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800881 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 return err;
883
Auke Kokcd94dd02006-06-27 09:08:22 -0700884 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
885 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 pci_using_dac = 1;
887 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700888 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
889 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700891 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 }
893 pci_using_dac = 0;
894 }
895
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800896 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700897 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 pci_set_master(pdev);
900
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700901 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700903 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
906 SET_MODULE_OWNER(netdev);
907 SET_NETDEV_DEV(netdev, &pdev->dev);
908
909 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700910 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 adapter->netdev = netdev;
912 adapter->pdev = pdev;
913 adapter->hw.back = adapter;
914 adapter->msg_enable = (1 << debug) - 1;
915
916 mmio_start = pci_resource_start(pdev, BAR_0);
917 mmio_len = pci_resource_len(pdev, BAR_0);
918
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700919 err = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700921 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800924 for (i = BAR_1; i <= BAR_5; i++) {
925 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800927 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 adapter->hw.io_base = pci_resource_start(pdev, i);
929 break;
930 }
931 }
932
933 netdev->open = &e1000_open;
934 netdev->stop = &e1000_close;
935 netdev->hard_start_xmit = &e1000_xmit_frame;
936 netdev->get_stats = &e1000_get_stats;
937 netdev->set_multicast_list = &e1000_set_multi;
938 netdev->set_mac_address = &e1000_set_mac;
939 netdev->change_mtu = &e1000_change_mtu;
940 netdev->do_ioctl = &e1000_ioctl;
941 e1000_set_ethtool_ops(netdev);
942 netdev->tx_timeout = &e1000_tx_timeout;
943 netdev->watchdog_timeo = 5 * HZ;
944#ifdef CONFIG_E1000_NAPI
945 netdev->poll = &e1000_clean;
946 netdev->weight = 64;
947#endif
948 netdev->vlan_rx_register = e1000_vlan_rx_register;
949 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
950 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
951#ifdef CONFIG_NET_POLL_CONTROLLER
952 netdev->poll_controller = e1000_netpoll;
953#endif
Auke Kok0eb5a342006-09-27 12:53:17 -0700954 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956 netdev->mem_start = mmio_start;
957 netdev->mem_end = mmio_start + mmio_len;
958 netdev->base_addr = adapter->hw.io_base;
959
960 adapter->bd_number = cards_found;
961
962 /* setup the private structure */
963
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800964 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 goto err_sw_init;
966
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700967 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -0700968 /* Flash BAR mapping must happen after e1000_sw_init
969 * because it depends on mac_type */
970 if ((adapter->hw.mac_type == e1000_ich8lan) &&
971 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
972 flash_start = pci_resource_start(pdev, 1);
973 flash_len = pci_resource_len(pdev, 1);
974 adapter->hw.flash_address = ioremap(flash_start, flash_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700975 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -0700976 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -0700977 }
978
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700979 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700980 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
981
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800982 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 netdev->features = NETIF_F_SG |
984 NETIF_F_HW_CSUM |
985 NETIF_F_HW_VLAN_TX |
986 NETIF_F_HW_VLAN_RX |
987 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -0700988 if (adapter->hw.mac_type == e1000_ich8lan)
989 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 }
991
992#ifdef NETIF_F_TSO
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800993 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 (adapter->hw.mac_type != e1000_82547))
995 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700996
Jesse Brandeburg72f3ab72006-12-15 10:34:46 +0100997#ifdef CONFIG_DEBUG_SLAB
998 /* 82544's work arounds do not play nicely with DEBUG SLAB */
999 if (adapter->hw.mac_type == e1000_82544)
1000 netdev->features &= ~NETIF_F_TSO;
1001#endif
1002
Auke Kok87ca4e52006-11-01 08:47:36 -08001003#ifdef NETIF_F_TSO6
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001004 if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -08001005 netdev->features |= NETIF_F_TSO6;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001006#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001008 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 netdev->features |= NETIF_F_HIGHDMA;
1010
Auke Kok76c224b2006-05-23 13:36:06 -07001011 netdev->features |= NETIF_F_LLTX;
1012
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001013 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
1014
Auke Kokcd94dd02006-06-27 09:08:22 -07001015 /* initialize eeprom parameters */
1016
1017 if (e1000_init_eeprom_params(&adapter->hw)) {
1018 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001019 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001020 }
1021
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001022 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001024
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 e1000_reset_hw(&adapter->hw);
1026
1027 /* make sure the EEPROM is good */
1028
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001029 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 goto err_eeprom;
1032 }
1033
1034 /* copy the MAC address out of the EEPROM */
1035
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001036 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
1038 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -04001039 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001041 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 goto err_eeprom;
1044 }
1045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 e1000_get_bus_info(&adapter->hw);
1047
1048 init_timer(&adapter->tx_fifo_stall_timer);
1049 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1050 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
1051
1052 init_timer(&adapter->watchdog_timer);
1053 adapter->watchdog_timer.function = &e1000_watchdog;
1054 adapter->watchdog_timer.data = (unsigned long) adapter;
1055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 init_timer(&adapter->phy_info_timer);
1057 adapter->phy_info_timer.function = &e1000_update_phy_info;
1058 adapter->phy_info_timer.data = (unsigned long) adapter;
1059
David Howells65f27f32006-11-22 14:55:48 +00001060 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 e1000_check_options(adapter);
1063
1064 /* Initial Wake on LAN setting
1065 * If APM wake is enabled in the EEPROM,
1066 * enable the ACPI Magic Packet filter
1067 */
1068
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001069 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 case e1000_82542_rev2_0:
1071 case e1000_82542_rev2_1:
1072 case e1000_82543:
1073 break;
1074 case e1000_82544:
1075 e1000_read_eeprom(&adapter->hw,
1076 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1077 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1078 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001079 case e1000_ich8lan:
1080 e1000_read_eeprom(&adapter->hw,
1081 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1082 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1083 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 case e1000_82546:
1085 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001086 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001087 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001088 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 e1000_read_eeprom(&adapter->hw,
1090 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1091 break;
1092 }
1093 /* Fall Through */
1094 default:
1095 e1000_read_eeprom(&adapter->hw,
1096 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1097 break;
1098 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001099 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001100 adapter->eeprom_wol |= E1000_WUFC_MAG;
1101
1102 /* now that we have the eeprom settings, apply the special cases
1103 * where the eeprom may be wrong or the board simply won't support
1104 * wake on lan on a particular port */
1105 switch (pdev->device) {
1106 case E1000_DEV_ID_82546GB_PCIE:
1107 adapter->eeprom_wol = 0;
1108 break;
1109 case E1000_DEV_ID_82546EB_FIBER:
1110 case E1000_DEV_ID_82546GB_FIBER:
1111 case E1000_DEV_ID_82571EB_FIBER:
1112 /* Wake events only supported on port A for dual fiber
1113 * regardless of eeprom setting */
1114 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
1115 adapter->eeprom_wol = 0;
1116 break;
1117 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001118 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001119 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001120 /* if quad port adapter, disable WoL on all but port A */
1121 if (global_quad_port_a != 0)
1122 adapter->eeprom_wol = 0;
1123 else
1124 adapter->quad_port_a = 1;
1125 /* Reset for multiple quad port adapters */
1126 if (++global_quad_port_a == 4)
1127 global_quad_port_a = 0;
1128 break;
1129 }
1130
1131 /* initialize the wol settings based on the eeprom settings */
1132 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001134 /* print bus type/speed/width info */
1135 {
1136 struct e1000_hw *hw = &adapter->hw;
1137 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1138 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1139 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1140 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1141 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1142 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1143 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1144 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1145 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1146 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1147 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1148 "32-bit"));
1149 }
1150
1151 for (i = 0; i < 6; i++)
1152 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
1153
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 /* reset the hardware with the new settings */
1155 e1000_reset(adapter);
1156
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001157 /* If the controller is 82573 and f/w is AMT, do not set
1158 * DRV_LOAD until the interface is up. For all other cases,
1159 * let the f/w know that the h/w is now under the control
1160 * of the driver. */
1161 if (adapter->hw.mac_type != e1000_82573 ||
1162 !e1000_check_mng_mode(&adapter->hw))
1163 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 strcpy(netdev->name, "eth%d");
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001166 if ((err = register_netdev(netdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 goto err_register;
1168
Auke Kok1314bbf2006-09-27 12:54:02 -07001169 /* tell the stack to leave us alone until e1000_open() is called */
1170 netif_carrier_off(netdev);
1171 netif_stop_queue(netdev);
1172
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1174
1175 cards_found++;
1176 return 0;
1177
1178err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001179 e1000_release_hw_control(adapter);
1180err_eeprom:
1181 if (!e1000_check_phy_reset_block(&adapter->hw))
1182 e1000_phy_hw_reset(&adapter->hw);
1183
Auke Kokcd94dd02006-06-27 09:08:22 -07001184 if (adapter->hw.flash_address)
1185 iounmap(adapter->hw.flash_address);
1186err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001187#ifdef CONFIG_E1000_NAPI
1188 for (i = 0; i < adapter->num_rx_queues; i++)
1189 dev_put(&adapter->polling_netdev[i]);
1190#endif
1191
1192 kfree(adapter->tx_ring);
1193 kfree(adapter->rx_ring);
1194#ifdef CONFIG_E1000_NAPI
1195 kfree(adapter->polling_netdev);
1196#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 iounmap(adapter->hw.hw_addr);
1199err_ioremap:
1200 free_netdev(netdev);
1201err_alloc_etherdev:
1202 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001203err_pci_reg:
1204err_dma:
1205 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 return err;
1207}
1208
1209/**
1210 * e1000_remove - Device Removal Routine
1211 * @pdev: PCI device information struct
1212 *
1213 * e1000_remove is called by the PCI subsystem to alert the driver
1214 * that it should release a PCI device. The could be caused by a
1215 * Hot-Plug event, or because the driver is going to be removed from
1216 * memory.
1217 **/
1218
1219static void __devexit
1220e1000_remove(struct pci_dev *pdev)
1221{
1222 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001223 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001224#ifdef CONFIG_E1000_NAPI
1225 int i;
1226#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001228 flush_scheduled_work();
1229
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001230 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001232 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1233 * would have already happened in close and is redundant. */
1234 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001235
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001237#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001238 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001239 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001240#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001242 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001243 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001245 kfree(adapter->tx_ring);
1246 kfree(adapter->rx_ring);
1247#ifdef CONFIG_E1000_NAPI
1248 kfree(adapter->polling_netdev);
1249#endif
1250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001252 if (adapter->hw.flash_address)
1253 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 pci_release_regions(pdev);
1255
1256 free_netdev(netdev);
1257
1258 pci_disable_device(pdev);
1259}
1260
1261/**
1262 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1263 * @adapter: board private structure to initialize
1264 *
1265 * e1000_sw_init initializes the Adapter private data structure.
1266 * Fields are initialized based on PCI device information and
1267 * OS network device settings (MTU size).
1268 **/
1269
1270static int __devinit
1271e1000_sw_init(struct e1000_adapter *adapter)
1272{
1273 struct e1000_hw *hw = &adapter->hw;
1274 struct net_device *netdev = adapter->netdev;
1275 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001276#ifdef CONFIG_E1000_NAPI
1277 int i;
1278#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 /* PCI config space info */
1281
1282 hw->vendor_id = pdev->vendor;
1283 hw->device_id = pdev->device;
1284 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1285 hw->subsystem_id = pdev->subsystem_device;
1286
1287 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1288
1289 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1290
Auke Kokeb0f8052006-07-14 16:14:48 -07001291 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001292 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 hw->max_frame_size = netdev->mtu +
1294 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1295 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1296
1297 /* identify the MAC */
1298
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001299 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1301 return -EIO;
1302 }
1303
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001304 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 default:
1306 break;
1307 case e1000_82541:
1308 case e1000_82547:
1309 case e1000_82541_rev_2:
1310 case e1000_82547_rev_2:
1311 hw->phy_init_script = 1;
1312 break;
1313 }
1314
1315 e1000_set_media_type(hw);
1316
1317 hw->wait_autoneg_complete = FALSE;
1318 hw->tbi_compatibility_en = TRUE;
1319 hw->adaptive_ifs = TRUE;
1320
1321 /* Copper options */
1322
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001323 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 hw->mdix = AUTO_ALL_MODES;
1325 hw->disable_polarity_correction = FALSE;
1326 hw->master_slave = E1000_MASTER_SLAVE;
1327 }
1328
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001329 adapter->num_tx_queues = 1;
1330 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001331
1332 if (e1000_alloc_queues(adapter)) {
1333 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1334 return -ENOMEM;
1335 }
1336
1337#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001338 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001339 adapter->polling_netdev[i].priv = adapter;
1340 adapter->polling_netdev[i].poll = &e1000_clean;
1341 adapter->polling_netdev[i].weight = 64;
1342 dev_hold(&adapter->polling_netdev[i]);
1343 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1344 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001345 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001346#endif
1347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 atomic_set(&adapter->irq_sem, 1);
1349 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Auke Kok1314bbf2006-09-27 12:54:02 -07001351 set_bit(__E1000_DOWN, &adapter->flags);
1352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 return 0;
1354}
1355
1356/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001357 * e1000_alloc_queues - Allocate memory for all rings
1358 * @adapter: board private structure to initialize
1359 *
1360 * We allocate one ring per queue at run-time since we don't know the
1361 * number of queues at compile-time. The polling_netdev array is
1362 * intended for Multiqueue, but should work fine with a single queue.
1363 **/
1364
1365static int __devinit
1366e1000_alloc_queues(struct e1000_adapter *adapter)
1367{
1368 int size;
1369
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001370 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001371 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1372 if (!adapter->tx_ring)
1373 return -ENOMEM;
1374 memset(adapter->tx_ring, 0, size);
1375
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001376 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001377 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1378 if (!adapter->rx_ring) {
1379 kfree(adapter->tx_ring);
1380 return -ENOMEM;
1381 }
1382 memset(adapter->rx_ring, 0, size);
1383
1384#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001385 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001386 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1387 if (!adapter->polling_netdev) {
1388 kfree(adapter->tx_ring);
1389 kfree(adapter->rx_ring);
1390 return -ENOMEM;
1391 }
1392 memset(adapter->polling_netdev, 0, size);
1393#endif
1394
1395 return E1000_SUCCESS;
1396}
1397
1398/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 * e1000_open - Called when a network interface is made active
1400 * @netdev: network interface device structure
1401 *
1402 * Returns 0 on success, negative value on failure
1403 *
1404 * The open entry point is called when a network interface is made
1405 * active by the system (IFF_UP). At this point all resources needed
1406 * for transmit and receive operations are allocated, the interrupt
1407 * handler is registered with the OS, the watchdog timer is started,
1408 * and the stack is notified that the interface is ready.
1409 **/
1410
1411static int
1412e1000_open(struct net_device *netdev)
1413{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001414 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 int err;
1416
Auke Kok2db10a02006-06-27 09:06:28 -07001417 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001418 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001419 return -EBUSY;
1420
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 /* allocate transmit descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001422 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 goto err_setup_tx;
1424
1425 /* allocate receive descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001426 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 goto err_setup_rx;
1428
Auke Kok2db10a02006-06-27 09:06:28 -07001429 err = e1000_request_irq(adapter);
1430 if (err)
Vasily Averin401a5522006-08-28 14:56:19 -07001431 goto err_req_irq;
Auke Kok2db10a02006-06-27 09:06:28 -07001432
Auke Kok79f05bf2006-06-27 09:06:32 -07001433 e1000_power_up_phy(adapter);
1434
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001435 if ((err = e1000_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001437 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001438 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001439 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1440 e1000_update_mng_vlan(adapter);
1441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001443 /* If AMT is enabled, let the firmware know that the network
1444 * interface is now open */
1445 if (adapter->hw.mac_type == e1000_82573 &&
1446 e1000_check_mng_mode(&adapter->hw))
1447 e1000_get_hw_control(adapter);
1448
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 return E1000_SUCCESS;
1450
1451err_up:
Vasily Averin401a5522006-08-28 14:56:19 -07001452 e1000_power_down_phy(adapter);
1453 e1000_free_irq(adapter);
1454err_req_irq:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001455 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001457 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458err_setup_tx:
1459 e1000_reset(adapter);
1460
1461 return err;
1462}
1463
1464/**
1465 * e1000_close - Disables a network interface
1466 * @netdev: network interface device structure
1467 *
1468 * Returns 0, this is not allowed to fail
1469 *
1470 * The close entry point is called when an interface is de-activated
1471 * by the OS. The hardware is still under the drivers control, but
1472 * needs to be disabled. A global MAC reset is issued to stop the
1473 * hardware, and all transmit and receive resources are freed.
1474 **/
1475
1476static int
1477e1000_close(struct net_device *netdev)
1478{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001479 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Auke Kok2db10a02006-06-27 09:06:28 -07001481 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001483 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001484 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001486 e1000_free_all_tx_resources(adapter);
1487 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Bruce Allan46665602006-09-27 12:54:08 -07001489 /* kill manageability vlan ID if supported, but not if a vlan with
1490 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001491 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001492 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1493 !(adapter->vlgrp &&
1494 adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001495 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1496 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001497
1498 /* If AMT is enabled, let the firmware know that the network
1499 * interface is now closed */
1500 if (adapter->hw.mac_type == e1000_82573 &&
1501 e1000_check_mng_mode(&adapter->hw))
1502 e1000_release_hw_control(adapter);
1503
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 return 0;
1505}
1506
1507/**
1508 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1509 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001510 * @start: address of beginning of memory
1511 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 **/
Auke Koke619d522006-04-14 19:04:52 -07001513static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514e1000_check_64k_bound(struct e1000_adapter *adapter,
1515 void *start, unsigned long len)
1516{
1517 unsigned long begin = (unsigned long) start;
1518 unsigned long end = begin + len;
1519
Malli Chilakala26483452005-04-28 19:44:46 -07001520 /* First rev 82545 and 82546 need to not allow any memory
1521 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001523 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1525 }
1526
1527 return TRUE;
1528}
1529
1530/**
1531 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1532 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001533 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 *
1535 * Return 0 on success, negative on failure
1536 **/
1537
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001538static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001539e1000_setup_tx_resources(struct e1000_adapter *adapter,
1540 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 struct pci_dev *pdev = adapter->pdev;
1543 int size;
1544
1545 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001546 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001547 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001548 DPRINTK(PROBE, ERR,
1549 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 return -ENOMEM;
1551 }
1552 memset(txdr->buffer_info, 0, size);
1553
1554 /* round up to nearest 4K */
1555
1556 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1557 E1000_ROUNDUP(txdr->size, 4096);
1558
1559 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001560 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001563 DPRINTK(PROBE, ERR,
1564 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 return -ENOMEM;
1566 }
1567
Malli Chilakala26483452005-04-28 19:44:46 -07001568 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1570 void *olddesc = txdr->desc;
1571 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001572 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1573 "at %p\n", txdr->size, txdr->desc);
1574 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001576 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001577 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1579 goto setup_tx_desc_die;
1580 }
1581
1582 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1583 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001584 pci_free_consistent(pdev, txdr->size, txdr->desc,
1585 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1587 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001588 "Unable to allocate aligned memory "
1589 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 vfree(txdr->buffer_info);
1591 return -ENOMEM;
1592 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001593 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1595 }
1596 }
1597 memset(txdr->desc, 0, txdr->size);
1598
1599 txdr->next_to_use = 0;
1600 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001601 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
1603 return 0;
1604}
1605
1606/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001607 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1608 * (Descriptors) for all queues
1609 * @adapter: board private structure
1610 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001611 * Return 0 on success, negative on failure
1612 **/
1613
1614int
1615e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1616{
1617 int i, err = 0;
1618
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001619 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001620 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1621 if (err) {
1622 DPRINTK(PROBE, ERR,
1623 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001624 for (i-- ; i >= 0; i--)
1625 e1000_free_tx_resources(adapter,
1626 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001627 break;
1628 }
1629 }
1630
1631 return err;
1632}
1633
1634/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1636 * @adapter: board private structure
1637 *
1638 * Configure the Tx unit of the MAC after a reset.
1639 **/
1640
1641static void
1642e1000_configure_tx(struct e1000_adapter *adapter)
1643{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001644 uint64_t tdba;
1645 struct e1000_hw *hw = &adapter->hw;
1646 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001647 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
1649 /* Setup the HW Tx Head and Tail descriptor pointers */
1650
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001651 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001652 case 1:
1653 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001654 tdba = adapter->tx_ring[0].dma;
1655 tdlen = adapter->tx_ring[0].count *
1656 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001657 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001658 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1659 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001660 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001661 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001662 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1663 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001664 break;
1665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 /* Set the default values for the Tx Inter Packet Gap timer */
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001668 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1669 (hw->media_type == e1000_media_type_fiber ||
1670 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001671 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1672 else
1673 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1674
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001675 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 case e1000_82542_rev2_0:
1677 case e1000_82542_rev2_1:
1678 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001679 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1680 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001682 case e1000_80003es2lan:
1683 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1684 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1685 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001687 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1688 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1689 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001691 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1692 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001693 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
1695 /* Set the Tx Interrupt Delay register */
1696
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001697 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1698 if (hw->mac_type >= e1000_82540)
1699 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
1701 /* Program the Transmit Control Register */
1702
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001703 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001705 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1707
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001708 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1709 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001710 /* set the speed mode bit, we'll clear it if we're not at
1711 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001712 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001713 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001714 } else if (hw->mac_type == e1000_80003es2lan) {
1715 tarc = E1000_READ_REG(hw, TARC0);
1716 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001717 E1000_WRITE_REG(hw, TARC0, tarc);
1718 tarc = E1000_READ_REG(hw, TARC1);
1719 tarc |= 1;
1720 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001721 }
1722
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001723 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001726 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1727
1728 /* only set IDE if we are delaying interrupts using the timers */
1729 if (adapter->tx_int_delay)
1730 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001732 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1734 else
1735 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1736
1737 /* Cache if we're 82544 running in PCI-X because we'll
1738 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001739 if (hw->mac_type == e1000_82544 &&
1740 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001742
1743 E1000_WRITE_REG(hw, TCTL, tctl);
1744
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745}
1746
1747/**
1748 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1749 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001750 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 *
1752 * Returns 0 on success, negative on failure
1753 **/
1754
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001755static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001756e1000_setup_rx_resources(struct e1000_adapter *adapter,
1757 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001760 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
1762 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001763 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001764 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001765 DPRINTK(PROBE, ERR,
1766 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 return -ENOMEM;
1768 }
1769 memset(rxdr->buffer_info, 0, size);
1770
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001771 size = sizeof(struct e1000_ps_page) * rxdr->count;
1772 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001773 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001774 vfree(rxdr->buffer_info);
1775 DPRINTK(PROBE, ERR,
1776 "Unable to allocate memory for the receive descriptor ring\n");
1777 return -ENOMEM;
1778 }
1779 memset(rxdr->ps_page, 0, size);
1780
1781 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1782 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001783 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001784 vfree(rxdr->buffer_info);
1785 kfree(rxdr->ps_page);
1786 DPRINTK(PROBE, ERR,
1787 "Unable to allocate memory for the receive descriptor ring\n");
1788 return -ENOMEM;
1789 }
1790 memset(rxdr->ps_page_dma, 0, size);
1791
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001792 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001793 desc_len = sizeof(struct e1000_rx_desc);
1794 else
1795 desc_len = sizeof(union e1000_rx_desc_packet_split);
1796
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 /* Round up to nearest 4K */
1798
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001799 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 E1000_ROUNDUP(rxdr->size, 4096);
1801
1802 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1803
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001804 if (!rxdr->desc) {
1805 DPRINTK(PROBE, ERR,
1806 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001809 kfree(rxdr->ps_page);
1810 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 return -ENOMEM;
1812 }
1813
Malli Chilakala26483452005-04-28 19:44:46 -07001814 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1816 void *olddesc = rxdr->desc;
1817 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001818 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1819 "at %p\n", rxdr->size, rxdr->desc);
1820 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001822 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001823 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001825 DPRINTK(PROBE, ERR,
1826 "Unable to allocate memory "
1827 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 goto setup_rx_desc_die;
1829 }
1830
1831 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1832 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001833 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1834 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001836 DPRINTK(PROBE, ERR,
1837 "Unable to allocate aligned memory "
1838 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001839 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001841 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1843 }
1844 }
1845 memset(rxdr->desc, 0, rxdr->size);
1846
1847 rxdr->next_to_clean = 0;
1848 rxdr->next_to_use = 0;
1849
1850 return 0;
1851}
1852
1853/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001854 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1855 * (Descriptors) for all queues
1856 * @adapter: board private structure
1857 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001858 * Return 0 on success, negative on failure
1859 **/
1860
1861int
1862e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1863{
1864 int i, err = 0;
1865
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001866 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001867 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1868 if (err) {
1869 DPRINTK(PROBE, ERR,
1870 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001871 for (i-- ; i >= 0; i--)
1872 e1000_free_rx_resources(adapter,
1873 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001874 break;
1875 }
1876 }
1877
1878 return err;
1879}
1880
1881/**
Malli Chilakala26483452005-04-28 19:44:46 -07001882 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 * @adapter: Board private structure
1884 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001885#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1886 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887static void
1888e1000_setup_rctl(struct e1000_adapter *adapter)
1889{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001890 uint32_t rctl, rfctl;
1891 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001892#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001893 uint32_t pages = 0;
1894#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
1896 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1897
1898 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1899
1900 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1901 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1902 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1903
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001904 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 rctl |= E1000_RCTL_SBP;
1906 else
1907 rctl &= ~E1000_RCTL_SBP;
1908
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001909 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1910 rctl &= ~E1000_RCTL_LPE;
1911 else
1912 rctl |= E1000_RCTL_LPE;
1913
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001915 rctl &= ~E1000_RCTL_SZ_4096;
1916 rctl |= E1000_RCTL_BSEX;
1917 switch (adapter->rx_buffer_len) {
1918 case E1000_RXBUFFER_256:
1919 rctl |= E1000_RCTL_SZ_256;
1920 rctl &= ~E1000_RCTL_BSEX;
1921 break;
1922 case E1000_RXBUFFER_512:
1923 rctl |= E1000_RCTL_SZ_512;
1924 rctl &= ~E1000_RCTL_BSEX;
1925 break;
1926 case E1000_RXBUFFER_1024:
1927 rctl |= E1000_RCTL_SZ_1024;
1928 rctl &= ~E1000_RCTL_BSEX;
1929 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001930 case E1000_RXBUFFER_2048:
1931 default:
1932 rctl |= E1000_RCTL_SZ_2048;
1933 rctl &= ~E1000_RCTL_BSEX;
1934 break;
1935 case E1000_RXBUFFER_4096:
1936 rctl |= E1000_RCTL_SZ_4096;
1937 break;
1938 case E1000_RXBUFFER_8192:
1939 rctl |= E1000_RCTL_SZ_8192;
1940 break;
1941 case E1000_RXBUFFER_16384:
1942 rctl |= E1000_RCTL_SZ_16384;
1943 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001944 }
1945
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001946#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001947 /* 82571 and greater support packet-split where the protocol
1948 * header is placed in skb->data and the packet data is
1949 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1950 * In the case of a non-split, skb->data is linearly filled,
1951 * followed by the page buffers. Therefore, skb->data is
1952 * sized to hold the largest protocol header.
1953 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001954 /* allocations using alloc_page take too long for regular MTU
1955 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001956 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001957 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1958 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001959 adapter->rx_ps_pages = pages;
1960 else
1961 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001962#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001963 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001964 /* Configure extra packet-split registers */
1965 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1966 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08001967 /* disable packet split support for IPv6 extension headers,
1968 * because some malformed IPv6 headers can hang the RX */
1969 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1970 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1971
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001972 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1973
Auke Kok7dfee0c2006-06-27 09:07:50 -07001974 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001975
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001976 psrctl |= adapter->rx_ps_bsize0 >>
1977 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001978
1979 switch (adapter->rx_ps_pages) {
1980 case 3:
1981 psrctl |= PAGE_SIZE <<
1982 E1000_PSRCTL_BSIZE3_SHIFT;
1983 case 2:
1984 psrctl |= PAGE_SIZE <<
1985 E1000_PSRCTL_BSIZE2_SHIFT;
1986 case 1:
1987 psrctl |= PAGE_SIZE >>
1988 E1000_PSRCTL_BSIZE1_SHIFT;
1989 break;
1990 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001991
1992 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 }
1994
1995 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1996}
1997
1998/**
1999 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2000 * @adapter: board private structure
2001 *
2002 * Configure the Rx unit of the MAC after a reset.
2003 **/
2004
2005static void
2006e1000_configure_rx(struct e1000_adapter *adapter)
2007{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002008 uint64_t rdba;
2009 struct e1000_hw *hw = &adapter->hw;
2010 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002011
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002012 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002013 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002014 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002015 sizeof(union e1000_rx_desc_packet_split);
2016 adapter->clean_rx = e1000_clean_rx_irq_ps;
2017 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2018 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002019 rdlen = adapter->rx_ring[0].count *
2020 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002021 adapter->clean_rx = e1000_clean_rx_irq;
2022 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
2025 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002026 rctl = E1000_READ_REG(hw, RCTL);
2027 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
2029 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002030 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002032 if (hw->mac_type >= e1000_82540) {
2033 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002034 if (adapter->itr_setting != 0)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002035 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 1000000000 / (adapter->itr * 256));
2037 }
2038
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002039 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002040 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002041 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002042 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002043#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002044 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002045 ctrl_ext |= E1000_CTRL_EXT_IAME;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002046 E1000_WRITE_REG(hw, IAM, 0xffffffff);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002047#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002048 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2049 E1000_WRITE_FLUSH(hw);
2050 }
2051
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002052 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2053 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002054 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002055 case 1:
2056 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002057 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002058 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07002059 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
2060 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002061 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002062 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002063 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2064 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002065 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002066 }
2067
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002069 if (hw->mac_type >= e1000_82543) {
2070 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002071 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002072 rxcsum |= E1000_RXCSUM_TUOFL;
2073
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002074 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002075 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002076 if ((hw->mac_type >= e1000_82571) &&
2077 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002078 rxcsum |= E1000_RXCSUM_IPPCSE;
2079 }
2080 } else {
2081 rxcsum &= ~E1000_RXCSUM_TUOFL;
2082 /* don't need to clear IPPCSE as it defaults to 0 */
2083 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002084 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 }
2086
Auke Kok21c4d5e2006-11-01 08:47:39 -08002087 /* enable early receives on 82573, only takes effect if using > 2048
2088 * byte total frame size. for example only for jumbo frames */
2089#define E1000_ERT_2048 0x100
2090 if (hw->mac_type == e1000_82573)
2091 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
2092
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002094 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095}
2096
2097/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002098 * e1000_free_tx_resources - Free Tx Resources per Queue
2099 * @adapter: board private structure
2100 * @tx_ring: Tx descriptor ring for a specific queue
2101 *
2102 * Free all transmit software resources
2103 **/
2104
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002105static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002106e1000_free_tx_resources(struct e1000_adapter *adapter,
2107 struct e1000_tx_ring *tx_ring)
2108{
2109 struct pci_dev *pdev = adapter->pdev;
2110
2111 e1000_clean_tx_ring(adapter, tx_ring);
2112
2113 vfree(tx_ring->buffer_info);
2114 tx_ring->buffer_info = NULL;
2115
2116 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2117
2118 tx_ring->desc = NULL;
2119}
2120
2121/**
2122 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 * @adapter: board private structure
2124 *
2125 * Free all transmit software resources
2126 **/
2127
2128void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002129e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002131 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002133 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002134 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135}
2136
Auke Koke619d522006-04-14 19:04:52 -07002137static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2139 struct e1000_buffer *buffer_info)
2140{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002141 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07002142 pci_unmap_page(adapter->pdev,
2143 buffer_info->dma,
2144 buffer_info->length,
2145 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002146 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002148 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002150 buffer_info->skb = NULL;
2151 }
2152 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153}
2154
2155/**
2156 * e1000_clean_tx_ring - Free Tx Buffers
2157 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002158 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 **/
2160
2161static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002162e1000_clean_tx_ring(struct e1000_adapter *adapter,
2163 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct e1000_buffer *buffer_info;
2166 unsigned long size;
2167 unsigned int i;
2168
2169 /* Free all the Tx ring sk_buffs */
2170
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002171 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 buffer_info = &tx_ring->buffer_info[i];
2173 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2174 }
2175
2176 size = sizeof(struct e1000_buffer) * tx_ring->count;
2177 memset(tx_ring->buffer_info, 0, size);
2178
2179 /* Zero out the descriptor ring */
2180
2181 memset(tx_ring->desc, 0, tx_ring->size);
2182
2183 tx_ring->next_to_use = 0;
2184 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002185 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002187 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2188 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2189}
2190
2191/**
2192 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2193 * @adapter: board private structure
2194 **/
2195
2196static void
2197e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2198{
2199 int i;
2200
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002201 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002202 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203}
2204
2205/**
2206 * e1000_free_rx_resources - Free Rx Resources
2207 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002208 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 *
2210 * Free all receive software resources
2211 **/
2212
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002213static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002214e1000_free_rx_resources(struct e1000_adapter *adapter,
2215 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 struct pci_dev *pdev = adapter->pdev;
2218
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002219 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
2221 vfree(rx_ring->buffer_info);
2222 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002223 kfree(rx_ring->ps_page);
2224 rx_ring->ps_page = NULL;
2225 kfree(rx_ring->ps_page_dma);
2226 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
2228 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2229
2230 rx_ring->desc = NULL;
2231}
2232
2233/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002234 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002236 *
2237 * Free all receive software resources
2238 **/
2239
2240void
2241e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2242{
2243 int i;
2244
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002245 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002246 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2247}
2248
2249/**
2250 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2251 * @adapter: board private structure
2252 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 **/
2254
2255static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002256e1000_clean_rx_ring(struct e1000_adapter *adapter,
2257 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002260 struct e1000_ps_page *ps_page;
2261 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 struct pci_dev *pdev = adapter->pdev;
2263 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002264 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265
2266 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002267 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002269 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 pci_unmap_single(pdev,
2271 buffer_info->dma,
2272 buffer_info->length,
2273 PCI_DMA_FROMDEVICE);
2274
2275 dev_kfree_skb(buffer_info->skb);
2276 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002277 }
2278 ps_page = &rx_ring->ps_page[i];
2279 ps_page_dma = &rx_ring->ps_page_dma[i];
2280 for (j = 0; j < adapter->rx_ps_pages; j++) {
2281 if (!ps_page->ps_page[j]) break;
2282 pci_unmap_page(pdev,
2283 ps_page_dma->ps_page_dma[j],
2284 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2285 ps_page_dma->ps_page_dma[j] = 0;
2286 put_page(ps_page->ps_page[j]);
2287 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 }
2289 }
2290
2291 size = sizeof(struct e1000_buffer) * rx_ring->count;
2292 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002293 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2294 memset(rx_ring->ps_page, 0, size);
2295 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2296 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
2298 /* Zero out the descriptor ring */
2299
2300 memset(rx_ring->desc, 0, rx_ring->size);
2301
2302 rx_ring->next_to_clean = 0;
2303 rx_ring->next_to_use = 0;
2304
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002305 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2306 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2307}
2308
2309/**
2310 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2311 * @adapter: board private structure
2312 **/
2313
2314static void
2315e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2316{
2317 int i;
2318
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002319 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002320 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321}
2322
2323/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2324 * and memory write and invalidate disabled for certain operations
2325 */
2326static void
2327e1000_enter_82542_rst(struct e1000_adapter *adapter)
2328{
2329 struct net_device *netdev = adapter->netdev;
2330 uint32_t rctl;
2331
2332 e1000_pci_clear_mwi(&adapter->hw);
2333
2334 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2335 rctl |= E1000_RCTL_RST;
2336 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2337 E1000_WRITE_FLUSH(&adapter->hw);
2338 mdelay(5);
2339
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002340 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002341 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342}
2343
2344static void
2345e1000_leave_82542_rst(struct e1000_adapter *adapter)
2346{
2347 struct net_device *netdev = adapter->netdev;
2348 uint32_t rctl;
2349
2350 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2351 rctl &= ~E1000_RCTL_RST;
2352 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2353 E1000_WRITE_FLUSH(&adapter->hw);
2354 mdelay(5);
2355
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002356 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 e1000_pci_set_mwi(&adapter->hw);
2358
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002359 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002360 /* No need to loop, because 82542 supports only 1 queue */
2361 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002362 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002363 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 }
2365}
2366
2367/**
2368 * e1000_set_mac - Change the Ethernet Address of the NIC
2369 * @netdev: network interface device structure
2370 * @p: pointer to an address structure
2371 *
2372 * Returns 0 on success, negative on failure
2373 **/
2374
2375static int
2376e1000_set_mac(struct net_device *netdev, void *p)
2377{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002378 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 struct sockaddr *addr = p;
2380
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002381 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 return -EADDRNOTAVAIL;
2383
2384 /* 82542 2.0 needs to be in reset to write receive address registers */
2385
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002386 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 e1000_enter_82542_rst(adapter);
2388
2389 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2390 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2391
2392 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2393
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002394 /* With 82571 controllers, LAA may be overwritten (with the default)
2395 * due to controller reset from the other port. */
2396 if (adapter->hw.mac_type == e1000_82571) {
2397 /* activate the work around */
2398 adapter->hw.laa_is_present = 1;
2399
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002400 /* Hold a copy of the LAA in RAR[14] This is done so that
2401 * between the time RAR[0] gets clobbered and the time it
2402 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002403 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002404 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002405 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002406 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002407 E1000_RAR_ENTRIES - 1);
2408 }
2409
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002410 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 e1000_leave_82542_rst(adapter);
2412
2413 return 0;
2414}
2415
2416/**
2417 * e1000_set_multi - Multicast and Promiscuous mode set
2418 * @netdev: network interface device structure
2419 *
2420 * The set_multi entry point is called whenever the multicast address
2421 * list or the network interface flags are updated. This routine is
2422 * responsible for configuring the hardware for proper multicast,
2423 * promiscuous mode, and all-multi behavior.
2424 **/
2425
2426static void
2427e1000_set_multi(struct net_device *netdev)
2428{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002429 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 struct e1000_hw *hw = &adapter->hw;
2431 struct dev_mc_list *mc_ptr;
2432 uint32_t rctl;
2433 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002434 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002435 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2436 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2437 E1000_NUM_MTA_REGISTERS;
2438
2439 if (adapter->hw.mac_type == e1000_ich8lan)
2440 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002442 /* reserve RAR[14] for LAA over-write work-around */
2443 if (adapter->hw.mac_type == e1000_82571)
2444 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Malli Chilakala26483452005-04-28 19:44:46 -07002446 /* Check for Promiscuous and All Multicast modes */
2447
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 rctl = E1000_READ_REG(hw, RCTL);
2449
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002450 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002452 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 rctl |= E1000_RCTL_MPE;
2454 rctl &= ~E1000_RCTL_UPE;
2455 } else {
2456 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2457 }
2458
2459 E1000_WRITE_REG(hw, RCTL, rctl);
2460
2461 /* 82542 2.0 needs to be in reset to write receive address registers */
2462
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002463 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 e1000_enter_82542_rst(adapter);
2465
2466 /* load the first 14 multicast address into the exact filters 1-14
2467 * RAR 0 is used for the station MAC adddress
2468 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002469 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 */
2471 mc_ptr = netdev->mc_list;
2472
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002473 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002474 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2476 mc_ptr = mc_ptr->next;
2477 } else {
2478 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002479 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002481 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 }
2483 }
2484
2485 /* clear the old settings from the multicast hash table */
2486
Auke Kokcd94dd02006-06-27 09:08:22 -07002487 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002489 E1000_WRITE_FLUSH(hw);
2490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
2492 /* load any remaining addresses into the hash table */
2493
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002494 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2496 e1000_mta_set(hw, hash_value);
2497 }
2498
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002499 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501}
2502
2503/* Need to wait a few seconds after link up to get diagnostic information from
2504 * the phy */
2505
2506static void
2507e1000_update_phy_info(unsigned long data)
2508{
2509 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2510 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2511}
2512
2513/**
2514 * e1000_82547_tx_fifo_stall - Timer Call-back
2515 * @data: pointer to adapter cast into an unsigned long
2516 **/
2517
2518static void
2519e1000_82547_tx_fifo_stall(unsigned long data)
2520{
2521 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2522 struct net_device *netdev = adapter->netdev;
2523 uint32_t tctl;
2524
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002525 if (atomic_read(&adapter->tx_fifo_stall)) {
2526 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 E1000_READ_REG(&adapter->hw, TDH)) &&
2528 (E1000_READ_REG(&adapter->hw, TDFT) ==
2529 E1000_READ_REG(&adapter->hw, TDFH)) &&
2530 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2531 E1000_READ_REG(&adapter->hw, TDFHS))) {
2532 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2533 E1000_WRITE_REG(&adapter->hw, TCTL,
2534 tctl & ~E1000_TCTL_EN);
2535 E1000_WRITE_REG(&adapter->hw, TDFT,
2536 adapter->tx_head_addr);
2537 E1000_WRITE_REG(&adapter->hw, TDFH,
2538 adapter->tx_head_addr);
2539 E1000_WRITE_REG(&adapter->hw, TDFTS,
2540 adapter->tx_head_addr);
2541 E1000_WRITE_REG(&adapter->hw, TDFHS,
2542 adapter->tx_head_addr);
2543 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2544 E1000_WRITE_FLUSH(&adapter->hw);
2545
2546 adapter->tx_fifo_head = 0;
2547 atomic_set(&adapter->tx_fifo_stall, 0);
2548 netif_wake_queue(netdev);
2549 } else {
2550 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2551 }
2552 }
2553}
2554
2555/**
2556 * e1000_watchdog - Timer Call-back
2557 * @data: pointer to adapter cast into an unsigned long
2558 **/
2559static void
2560e1000_watchdog(unsigned long data)
2561{
2562 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002564 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002565 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002566 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
Auke Kokcd94dd02006-06-27 09:08:22 -07002568 ret_val = e1000_check_for_link(&adapter->hw);
2569 if ((ret_val == E1000_ERR_PHY) &&
2570 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2571 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2572 /* See e1000_kumeran_lock_loss_workaround() */
2573 DPRINTK(LINK, INFO,
2574 "Gigabit has been disabled, downgrading speed\n");
2575 }
Auke Kok90fb5132006-11-01 08:47:30 -08002576
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002577 if (adapter->hw.mac_type == e1000_82573) {
2578 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002579 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002580 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002583 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2585 link = !adapter->hw.serdes_link_down;
2586 else
2587 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2588
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002589 if (link) {
2590 if (!netif_carrier_ok(netdev)) {
Auke Kokfe7fe282006-04-14 19:04:59 -07002591 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 e1000_get_speed_and_duplex(&adapter->hw,
2593 &adapter->link_speed,
2594 &adapter->link_duplex);
2595
2596 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2597 adapter->link_speed,
2598 adapter->link_duplex == FULL_DUPLEX ?
2599 "Full Duplex" : "Half Duplex");
2600
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002601 /* tweak tx_queue_len according to speed/duplex
2602 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002603 netdev->tx_queue_len = adapter->tx_queue_len;
2604 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002605 switch (adapter->link_speed) {
2606 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002607 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002608 netdev->tx_queue_len = 10;
2609 adapter->tx_timeout_factor = 8;
2610 break;
2611 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002612 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002613 netdev->tx_queue_len = 100;
2614 /* maybe add some timeout factor ? */
2615 break;
2616 }
2617
Auke Kokfe7fe282006-04-14 19:04:59 -07002618 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002619 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002620 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002621 uint32_t tarc0;
2622 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002623 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002624 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2625 }
Auke Kok90fb5132006-11-01 08:47:30 -08002626
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002627#ifdef NETIF_F_TSO
2628 /* disable TSO for pcie and 10/100 speeds, to avoid
2629 * some hardware issues */
2630 if (!adapter->tso_force &&
2631 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002632 switch (adapter->link_speed) {
2633 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002634 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002635 DPRINTK(PROBE,INFO,
2636 "10/100 speed: disabling TSO\n");
2637 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002638#ifdef NETIF_F_TSO6
2639 netdev->features &= ~NETIF_F_TSO6;
2640#endif
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002641 break;
2642 case SPEED_1000:
2643 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002644#ifdef NETIF_F_TSO6
2645 netdev->features |= NETIF_F_TSO6;
2646#endif
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002647 break;
2648 default:
2649 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002650 break;
2651 }
2652 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002653#endif
2654
2655 /* enable transmits in the hardware, need to do this
2656 * after setting TARC0 */
2657 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2658 tctl |= E1000_TCTL_EN;
2659 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002660
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 netif_carrier_on(netdev);
2662 netif_wake_queue(netdev);
2663 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2664 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002665 } else {
2666 /* make sure the receive unit is started */
2667 if (adapter->hw.rx_needs_kicking) {
2668 struct e1000_hw *hw = &adapter->hw;
2669 uint32_t rctl = E1000_READ_REG(hw, RCTL);
2670 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 }
2673 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002674 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 adapter->link_speed = 0;
2676 adapter->link_duplex = 0;
2677 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2678 netif_carrier_off(netdev);
2679 netif_stop_queue(netdev);
2680 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002681
2682 /* 80003ES2LAN workaround--
2683 * For packet buffer work-around on link down event;
2684 * disable receives in the ISR and
2685 * reset device here in the watchdog
2686 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002687 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002688 /* reset device */
2689 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 }
2691
2692 e1000_smartspeed(adapter);
2693 }
2694
2695 e1000_update_stats(adapter);
2696
2697 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2698 adapter->tpt_old = adapter->stats.tpt;
2699 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2700 adapter->colc_old = adapter->stats.colc;
2701
2702 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2703 adapter->gorcl_old = adapter->stats.gorcl;
2704 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2705 adapter->gotcl_old = adapter->stats.gotcl;
2706
2707 e1000_update_adaptive(&adapter->hw);
2708
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002709 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002710 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 /* We've lost link, so the controller stops DMA,
2712 * but we've got queued Tx work that's never going
2713 * to get done, so reset controller to flush Tx.
2714 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002715 adapter->tx_timeout_count++;
2716 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 }
2718 }
2719
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 /* Cause software interrupt to ensure rx ring is cleaned */
2721 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2722
Malli Chilakala26483452005-04-28 19:44:46 -07002723 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 adapter->detect_tx_hung = TRUE;
2725
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002726 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002727 * reset from the other port. Set the appropriate LAA in RAR[0] */
2728 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2729 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2730
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 /* Reset the timer */
2732 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2733}
2734
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002735enum latency_range {
2736 lowest_latency = 0,
2737 low_latency = 1,
2738 bulk_latency = 2,
2739 latency_invalid = 255
2740};
2741
2742/**
2743 * e1000_update_itr - update the dynamic ITR value based on statistics
2744 * Stores a new ITR value based on packets and byte
2745 * counts during the last interrupt. The advantage of per interrupt
2746 * computation is faster updates and more accurate ITR for the current
2747 * traffic pattern. Constants in this function were computed
2748 * based on theoretical maximum wire speed and thresholds were set based
2749 * on testing data as well as attempting to minimize response time
2750 * while increasing bulk throughput.
2751 * this functionality is controlled by the InterruptThrottleRate module
2752 * parameter (see e1000_param.c)
2753 * @adapter: pointer to adapter
2754 * @itr_setting: current adapter->itr
2755 * @packets: the number of packets during this measurement interval
2756 * @bytes: the number of bytes during this measurement interval
2757 **/
2758static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2759 uint16_t itr_setting,
2760 int packets,
2761 int bytes)
2762{
2763 unsigned int retval = itr_setting;
2764 struct e1000_hw *hw = &adapter->hw;
2765
2766 if (unlikely(hw->mac_type < e1000_82540))
2767 goto update_itr_done;
2768
2769 if (packets == 0)
2770 goto update_itr_done;
2771
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002772 switch (itr_setting) {
2773 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002774 /* jumbo frames get bulk treatment*/
2775 if (bytes/packets > 8000)
2776 retval = bulk_latency;
2777 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002778 retval = low_latency;
2779 break;
2780 case low_latency: /* 50 usec aka 20000 ints/s */
2781 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002782 /* jumbo frames need bulk latency setting */
2783 if (bytes/packets > 8000)
2784 retval = bulk_latency;
2785 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002786 retval = bulk_latency;
2787 else if ((packets > 35))
2788 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002789 } else if (bytes/packets > 2000)
2790 retval = bulk_latency;
2791 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002792 retval = lowest_latency;
2793 break;
2794 case bulk_latency: /* 250 usec aka 4000 ints/s */
2795 if (bytes > 25000) {
2796 if (packets > 35)
2797 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002798 } else if (bytes < 6000) {
2799 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002800 }
2801 break;
2802 }
2803
2804update_itr_done:
2805 return retval;
2806}
2807
2808static void e1000_set_itr(struct e1000_adapter *adapter)
2809{
2810 struct e1000_hw *hw = &adapter->hw;
2811 uint16_t current_itr;
2812 uint32_t new_itr = adapter->itr;
2813
2814 if (unlikely(hw->mac_type < e1000_82540))
2815 return;
2816
2817 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2818 if (unlikely(adapter->link_speed != SPEED_1000)) {
2819 current_itr = 0;
2820 new_itr = 4000;
2821 goto set_itr_now;
2822 }
2823
2824 adapter->tx_itr = e1000_update_itr(adapter,
2825 adapter->tx_itr,
2826 adapter->total_tx_packets,
2827 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002828 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2829 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2830 adapter->tx_itr = low_latency;
2831
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002832 adapter->rx_itr = e1000_update_itr(adapter,
2833 adapter->rx_itr,
2834 adapter->total_rx_packets,
2835 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002836 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2837 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2838 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002839
2840 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2841
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002842 switch (current_itr) {
2843 /* counts and packets in update_itr are dependent on these numbers */
2844 case lowest_latency:
2845 new_itr = 70000;
2846 break;
2847 case low_latency:
2848 new_itr = 20000; /* aka hwitr = ~200 */
2849 break;
2850 case bulk_latency:
2851 new_itr = 4000;
2852 break;
2853 default:
2854 break;
2855 }
2856
2857set_itr_now:
2858 if (new_itr != adapter->itr) {
2859 /* this attempts to bias the interrupt rate towards Bulk
2860 * by adding intermediate steps when interrupt rate is
2861 * increasing */
2862 new_itr = new_itr > adapter->itr ?
2863 min(adapter->itr + (new_itr >> 2), new_itr) :
2864 new_itr;
2865 adapter->itr = new_itr;
2866 E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
2867 }
2868
2869 return;
2870}
2871
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872#define E1000_TX_FLAGS_CSUM 0x00000001
2873#define E1000_TX_FLAGS_VLAN 0x00000002
2874#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002875#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2877#define E1000_TX_FLAGS_VLAN_SHIFT 16
2878
Auke Koke619d522006-04-14 19:04:52 -07002879static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002880e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2881 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882{
2883#ifdef NETIF_F_TSO
2884 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002885 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 unsigned int i;
2887 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002888 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2890 int err;
2891
Herbert Xu89114af2006-07-08 13:34:32 -07002892 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 if (skb_header_cloned(skb)) {
2894 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2895 if (err)
2896 return err;
2897 }
2898
2899 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Herbert Xu79671682006-06-22 02:40:14 -07002900 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002901 if (skb->protocol == htons(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002902 skb->nh.iph->tot_len = 0;
2903 skb->nh.iph->check = 0;
2904 skb->h.th->check =
2905 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2906 skb->nh.iph->daddr,
2907 0,
2908 IPPROTO_TCP,
2909 0);
2910 cmd_length = E1000_TXD_CMD_IP;
2911 ipcse = skb->h.raw - skb->data - 1;
Auke Kok87ca4e52006-11-01 08:47:36 -08002912#ifdef NETIF_F_TSO6
Auke Koke15fdd02006-08-16 11:28:45 -07002913 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002914 skb->nh.ipv6h->payload_len = 0;
2915 skb->h.th->check =
2916 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2917 &skb->nh.ipv6h->daddr,
2918 0,
2919 IPPROTO_TCP,
2920 0);
2921 ipcse = 0;
2922#endif
2923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 ipcss = skb->nh.raw - skb->data;
2925 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 tucss = skb->h.raw - skb->data;
2927 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2928 tucse = 0;
2929
2930 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002931 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002933 i = tx_ring->next_to_use;
2934 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002935 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
2937 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2938 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2939 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2940 context_desc->upper_setup.tcp_fields.tucss = tucss;
2941 context_desc->upper_setup.tcp_fields.tucso = tucso;
2942 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2943 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2944 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2945 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2946
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002947 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002948 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002949
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002950 if (++i == tx_ring->count) i = 0;
2951 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
Jeff Kirsher8241e352006-01-12 16:51:34 -08002953 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 }
2955#endif
2956
Jeff Kirsher8241e352006-01-12 16:51:34 -08002957 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958}
2959
Auke Koke619d522006-04-14 19:04:52 -07002960static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002961e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2962 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963{
2964 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002965 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 unsigned int i;
2967 uint8_t css;
2968
Patrick McHardy84fa7932006-08-29 16:44:56 -07002969 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 css = skb->h.raw - skb->data;
2971
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002972 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002973 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002974 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
2976 context_desc->upper_setup.tcp_fields.tucss = css;
Al Viroff1dcad2006-11-20 18:07:29 -08002977 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 context_desc->upper_setup.tcp_fields.tucse = 0;
2979 context_desc->tcp_seg_setup.data = 0;
2980 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2981
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002982 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002983 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002984
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002985 if (unlikely(++i == tx_ring->count)) i = 0;
2986 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987
2988 return TRUE;
2989 }
2990
2991 return FALSE;
2992}
2993
2994#define E1000_MAX_TXD_PWR 12
2995#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2996
Auke Koke619d522006-04-14 19:04:52 -07002997static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002998e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2999 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
3000 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 struct e1000_buffer *buffer_info;
3003 unsigned int len = skb->len;
3004 unsigned int offset = 0, size, count = 0, i;
3005 unsigned int f;
3006 len -= skb->data_len;
3007
3008 i = tx_ring->next_to_use;
3009
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003010 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 buffer_info = &tx_ring->buffer_info[i];
3012 size = min(len, max_per_txd);
3013#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05003014 /* Workaround for Controller erratum --
3015 * descriptor for non-tso packet in a linear SKB that follows a
3016 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003017 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05003018 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07003019 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05003020 tx_ring->last_tx_tso = 0;
3021 size -= 4;
3022 }
3023
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 /* Workaround for premature desc write-backs
3025 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003026 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 size -= 4;
3028#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07003029 /* work-around for errata 10 and it applies
3030 * to all controllers in PCI-X mode
3031 * The fix is to make sure that the first descriptor of a
3032 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3033 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003034 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003035 (size > 2015) && count == 0))
3036 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003037
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 /* Workaround for potential 82544 hang in PCI-X. Avoid
3039 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003040 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3042 size > 4))
3043 size -= 4;
3044
3045 buffer_info->length = size;
3046 buffer_info->dma =
3047 pci_map_single(adapter->pdev,
3048 skb->data + offset,
3049 size,
3050 PCI_DMA_TODEVICE);
3051 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003052 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053
3054 len -= size;
3055 offset += size;
3056 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003057 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 }
3059
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003060 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 struct skb_frag_struct *frag;
3062
3063 frag = &skb_shinfo(skb)->frags[f];
3064 len = frag->size;
3065 offset = frag->page_offset;
3066
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003067 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 buffer_info = &tx_ring->buffer_info[i];
3069 size = min(len, max_per_txd);
3070#ifdef NETIF_F_TSO
3071 /* Workaround for premature desc write-backs
3072 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003073 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 size -= 4;
3075#endif
3076 /* Workaround for potential 82544 hang in PCI-X.
3077 * Avoid terminating buffers within evenly-aligned
3078 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003079 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3081 size > 4))
3082 size -= 4;
3083
3084 buffer_info->length = size;
3085 buffer_info->dma =
3086 pci_map_page(adapter->pdev,
3087 frag->page,
3088 offset,
3089 size,
3090 PCI_DMA_TODEVICE);
3091 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003092 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093
3094 len -= size;
3095 offset += size;
3096 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003097 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 }
3099 }
3100
3101 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3102 tx_ring->buffer_info[i].skb = skb;
3103 tx_ring->buffer_info[first].next_to_watch = i;
3104
3105 return count;
3106}
3107
Auke Koke619d522006-04-14 19:04:52 -07003108static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003109e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3110 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 struct e1000_tx_desc *tx_desc = NULL;
3113 struct e1000_buffer *buffer_info;
3114 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3115 unsigned int i;
3116
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003117 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3119 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003120 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3121
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003122 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003123 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 }
3125
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003126 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3128 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3129 }
3130
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003131 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 txd_lower |= E1000_TXD_CMD_VLE;
3133 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3134 }
3135
3136 i = tx_ring->next_to_use;
3137
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003138 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 buffer_info = &tx_ring->buffer_info[i];
3140 tx_desc = E1000_TX_DESC(*tx_ring, i);
3141 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3142 tx_desc->lower.data =
3143 cpu_to_le32(txd_lower | buffer_info->length);
3144 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003145 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 }
3147
3148 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3149
3150 /* Force memory writes to complete before letting h/w
3151 * know there are new descriptors to fetch. (Only
3152 * applicable for weak-ordered memory model archs,
3153 * such as IA-64). */
3154 wmb();
3155
3156 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003157 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003158 /* we need this if more than one processor can write to our tail
3159 * at a time, it syncronizes IO on IA64/Altix systems */
3160 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161}
3162
3163/**
3164 * 82547 workaround to avoid controller hang in half-duplex environment.
3165 * The workaround is to avoid queuing a large packet that would span
3166 * the internal Tx FIFO ring boundary by notifying the stack to resend
3167 * the packet at a later time. This gives the Tx FIFO an opportunity to
3168 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3169 * to the beginning of the Tx FIFO.
3170 **/
3171
3172#define E1000_FIFO_HDR 0x10
3173#define E1000_82547_PAD_LEN 0x3E0
3174
Auke Koke619d522006-04-14 19:04:52 -07003175static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
3177{
3178 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3179 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
3180
3181 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
3182
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003183 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 goto no_fifo_stall_required;
3185
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003186 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 return 1;
3188
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003189 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 atomic_set(&adapter->tx_fifo_stall, 1);
3191 return 1;
3192 }
3193
3194no_fifo_stall_required:
3195 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003196 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3198 return 0;
3199}
3200
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003201#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07003202static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003203e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
3204{
3205 struct e1000_hw *hw = &adapter->hw;
3206 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003207 if (vlan_tx_tag_present(skb)) {
3208 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003209 ( adapter->hw.mng_cookie.status &
3210 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3211 return 0;
3212 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003213 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003214 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003215 if ((htons(ETH_P_IP) == eth->h_proto)) {
3216 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003217 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003218 if (IPPROTO_UDP == ip->protocol) {
3219 struct udphdr *udp =
3220 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003221 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003222 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003223 offset = (uint8_t *)udp + 8 - skb->data;
3224 length = skb->len - offset;
3225
3226 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003227 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003228 length);
3229 }
3230 }
3231 }
3232 }
3233 return 0;
3234}
3235
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003236static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3237{
3238 struct e1000_adapter *adapter = netdev_priv(netdev);
3239 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3240
3241 netif_stop_queue(netdev);
3242 /* Herbert's original patch had:
3243 * smp_mb__after_netif_stop_queue();
3244 * but since that doesn't exist yet, just open code it. */
3245 smp_mb();
3246
3247 /* We need to check again in a case another CPU has just
3248 * made room available. */
3249 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3250 return -EBUSY;
3251
3252 /* A reprieve! */
3253 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003254 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003255 return 0;
3256}
3257
3258static int e1000_maybe_stop_tx(struct net_device *netdev,
3259 struct e1000_tx_ring *tx_ring, int size)
3260{
3261 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3262 return 0;
3263 return __e1000_maybe_stop_tx(netdev, size);
3264}
3265
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3267static int
3268e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3269{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003270 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003271 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3273 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3274 unsigned int tx_flags = 0;
3275 unsigned int len = skb->len;
3276 unsigned long flags;
3277 unsigned int nr_frags = 0;
3278 unsigned int mss = 0;
3279 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003280 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 unsigned int f;
3282 len -= skb->data_len;
3283
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003284 /* This goes back to the question of how to logically map a tx queue
3285 * to a flow. Right now, performance is impacted slightly negatively
3286 * if using multiple tx queues. If the stack breaks away from a
3287 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003288 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003289
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003290 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 dev_kfree_skb_any(skb);
3292 return NETDEV_TX_OK;
3293 }
3294
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003295 /* 82571 and newer doesn't need the workaround that limited descriptor
3296 * length to 4kB */
3297 if (adapter->hw.mac_type >= e1000_82571)
3298 max_per_txd = 8192;
3299
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300#ifdef NETIF_F_TSO
Herbert Xu79671682006-06-22 02:40:14 -07003301 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003302 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 * make sure there is enough room in the FIFO before
3304 * initiating the DMA for each buffer. The calc is:
3305 * 4 = ceil(buffer len/mss). To make sure we don't
3306 * overrun the FIFO, adjust the max buffer len if mss
3307 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003308 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003309 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 max_per_txd = min(mss << 2, max_per_txd);
3311 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003312
Auke Kok90fb5132006-11-01 08:47:30 -08003313 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3314 * points to just header, pull a few bytes of payload from
3315 * frags into skb->data */
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003316 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08003317 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3318 switch (adapter->hw.mac_type) {
3319 unsigned int pull_size;
3320 case e1000_82571:
3321 case e1000_82572:
3322 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003323 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003324 pull_size = min((unsigned int)4, skb->data_len);
3325 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003326 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003327 "__pskb_pull_tail failed.\n");
3328 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003329 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003330 }
3331 len = skb->len - skb->data_len;
3332 break;
3333 default:
3334 /* do nothing */
3335 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003336 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 }
3339
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003340 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003341 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003343 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344#else
Patrick McHardy84fa7932006-08-29 16:44:56 -07003345 if (skb->ip_summed == CHECKSUM_PARTIAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 count++;
3347#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05003348
3349#ifdef NETIF_F_TSO
3350 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003351 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003352 count++;
3353#endif
3354
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 count += TXD_USE_COUNT(len, max_txd_pwr);
3356
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003357 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 count++;
3359
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003360 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003361 * in PCI-X mode, so add one more descriptor to the count
3362 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003363 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003364 (len > 2015)))
3365 count++;
3366
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003368 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3370 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003371 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 count += nr_frags;
3373
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003374
3375 if (adapter->hw.tx_pkt_filtering &&
3376 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003377 e1000_transfer_dhcp_info(adapter, skb);
3378
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003379 local_irq_save(flags);
3380 if (!spin_trylock(&tx_ring->tx_lock)) {
3381 /* Collision - tell upper layer to requeue */
3382 local_irq_restore(flags);
3383 return NETDEV_TX_LOCKED;
3384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385
3386 /* need: count + 2 desc gap to keep tail from touching
3387 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003388 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003389 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 return NETDEV_TX_BUSY;
3391 }
3392
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003393 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3394 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003396 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003397 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 return NETDEV_TX_BUSY;
3399 }
3400 }
3401
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003402 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 tx_flags |= E1000_TX_FLAGS_VLAN;
3404 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3405 }
3406
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003407 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003408
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003409 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 if (tso < 0) {
3411 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003412 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 return NETDEV_TX_OK;
3414 }
3415
Jeff Kirsherfd803242005-12-13 00:06:22 -05003416 if (likely(tso)) {
3417 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003419 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 tx_flags |= E1000_TX_FLAGS_CSUM;
3421
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003422 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003423 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003424 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003425 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003426 tx_flags |= E1000_TX_FLAGS_IPV4;
3427
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003428 e1000_tx_queue(adapter, tx_ring, tx_flags,
3429 e1000_tx_map(adapter, tx_ring, skb, first,
3430 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431
3432 netdev->trans_start = jiffies;
3433
3434 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003435 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003437 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 return NETDEV_TX_OK;
3439}
3440
3441/**
3442 * e1000_tx_timeout - Respond to a Tx Hang
3443 * @netdev: network interface device structure
3444 **/
3445
3446static void
3447e1000_tx_timeout(struct net_device *netdev)
3448{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003449 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450
3451 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003452 adapter->tx_timeout_count++;
3453 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454}
3455
3456static void
David Howells65f27f32006-11-22 14:55:48 +00003457e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458{
David Howells65f27f32006-11-22 14:55:48 +00003459 struct e1000_adapter *adapter =
3460 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461
Auke Kok2db10a02006-06-27 09:06:28 -07003462 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463}
3464
3465/**
3466 * e1000_get_stats - Get System Network Statistics
3467 * @netdev: network interface device structure
3468 *
3469 * Returns the address of the device statistics structure.
3470 * The statistics are actually updated from the timer callback.
3471 **/
3472
3473static struct net_device_stats *
3474e1000_get_stats(struct net_device *netdev)
3475{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003476 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003478 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 return &adapter->net_stats;
3480}
3481
3482/**
3483 * e1000_change_mtu - Change the Maximum Transfer Unit
3484 * @netdev: network interface device structure
3485 * @new_mtu: new value for maximum frame size
3486 *
3487 * Returns 0 on success, negative on failure
3488 **/
3489
3490static int
3491e1000_change_mtu(struct net_device *netdev, int new_mtu)
3492{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003493 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003495 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003497 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3498 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3499 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003500 return -EINVAL;
3501 }
3502
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003503 /* Adapter-specific max frame size limits. */
3504 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003505 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003506 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003507 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3508 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003509 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003510 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003511 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003512 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003513 /* Jumbo Frames not supported if:
3514 * - this is not an 82573L device
3515 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003516 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3517 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003518 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3519 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003520 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3521 DPRINTK(PROBE, ERR,
3522 "Jumbo Frames not supported.\n");
3523 return -EINVAL;
3524 }
3525 break;
3526 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003527 /* ERT will be enabled later to enable wire speed receives */
3528
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003529 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003530 case e1000_82571:
3531 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003532 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003533#define MAX_STD_JUMBO_FRAME_SIZE 9234
3534 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3535 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3536 return -EINVAL;
3537 }
3538 break;
3539 default:
3540 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3541 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003542 }
3543
David S. Miller87f50322006-07-31 22:39:40 -07003544 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003545 * means we reserve 2 more, this pushes us to allocate from the next
3546 * larger slab size
3547 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003548
Auke Kok9e2feac2006-04-14 19:05:18 -07003549 if (max_frame <= E1000_RXBUFFER_256)
3550 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3551 else if (max_frame <= E1000_RXBUFFER_512)
3552 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3553 else if (max_frame <= E1000_RXBUFFER_1024)
3554 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3555 else if (max_frame <= E1000_RXBUFFER_2048)
3556 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3557 else if (max_frame <= E1000_RXBUFFER_4096)
3558 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3559 else if (max_frame <= E1000_RXBUFFER_8192)
3560 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3561 else if (max_frame <= E1000_RXBUFFER_16384)
3562 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3563
3564 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003565 if (!adapter->hw.tbi_compatibility_on &&
3566 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3567 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3568 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003569
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003570 netdev->mtu = new_mtu;
Bruce Allan83cd8272006-12-15 10:36:35 +01003571 adapter->hw.max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003572
Auke Kok2db10a02006-06-27 09:06:28 -07003573 if (netif_running(netdev))
3574 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 return 0;
3577}
3578
3579/**
3580 * e1000_update_stats - Update the board statistics counters
3581 * @adapter: board private structure
3582 **/
3583
3584void
3585e1000_update_stats(struct e1000_adapter *adapter)
3586{
3587 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003588 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 unsigned long flags;
3590 uint16_t phy_tmp;
3591
3592#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3593
Linas Vepstas282f33c2006-06-08 22:19:44 -07003594 /*
3595 * Prevent stats update while adapter is being reset, or if the pci
3596 * connection is down.
3597 */
Auke Kok90267292006-06-08 09:30:24 -07003598 if (adapter->link_speed == 0)
3599 return;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003600 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3601 return;
Auke Kok90267292006-06-08 09:30:24 -07003602
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 spin_lock_irqsave(&adapter->stats_lock, flags);
3604
3605 /* these counters are modified from e1000_adjust_tbi_stats,
3606 * called from the interrupt context, so they must only
3607 * be written while holding adapter->stats_lock
3608 */
3609
3610 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3611 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3612 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3613 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3614 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3615 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3616 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003617
3618 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003619 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3620 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3621 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3622 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3623 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3624 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626
3627 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3628 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3629 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3630 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3631 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3632 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3633 adapter->stats.dc += E1000_READ_REG(hw, DC);
3634 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3635 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3636 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3637 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3638 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3639 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3640 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3641 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3642 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3643 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3644 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3645 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3646 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3647 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3648 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3649 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3650 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3651 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3652 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003653
3654 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003655 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3656 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3657 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3658 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3659 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3660 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003661 }
3662
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3664 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3665
3666 /* used for adaptive IFS */
3667
3668 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3669 adapter->stats.tpt += hw->tx_packet_delta;
3670 hw->collision_delta = E1000_READ_REG(hw, COLC);
3671 adapter->stats.colc += hw->collision_delta;
3672
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003673 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3675 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3676 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3677 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3678 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3679 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3680 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003681 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003682 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3683 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003684
3685 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003686 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3687 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3688 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3689 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3690 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3691 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3692 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003693 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695
3696 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 adapter->net_stats.rx_packets = adapter->stats.gprc;
3698 adapter->net_stats.tx_packets = adapter->stats.gptc;
3699 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3700 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3701 adapter->net_stats.multicast = adapter->stats.mprc;
3702 adapter->net_stats.collisions = adapter->stats.colc;
3703
3704 /* Rx Errors */
3705
Jeff Kirsher87041632006-03-02 18:21:24 -08003706 /* RLEC on some newer hardware can be incorrect so build
3707 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3709 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003710 adapter->stats.ruc + adapter->stats.roc +
3711 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003712 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3713 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3715 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3717
3718 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003719 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3720 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3722 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3723 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Jeff Garzik167fb282006-12-15 10:41:15 -05003724 if (adapter->hw.bad_tx_carr_stats_fd &&
3725 adapter->link_duplex == FULL_DUPLEX) {
3726 adapter->net_stats.tx_carrier_errors = 0;
3727 adapter->stats.tncrs = 0;
3728 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729
3730 /* Tx Dropped needs to be maintained elsewhere */
3731
3732 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003733 if (hw->media_type == e1000_media_type_copper) {
3734 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3736 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3737 adapter->phy_stats.idle_errors += phy_tmp;
3738 }
3739
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003740 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 (hw->phy_type == e1000_phy_m88) &&
3742 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3743 adapter->phy_stats.receive_errors += phy_tmp;
3744 }
3745
3746 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3747}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003748#ifdef CONFIG_PCI_MSI
3749
3750/**
3751 * e1000_intr_msi - Interrupt Handler
3752 * @irq: interrupt number
3753 * @data: pointer to a network interface device structure
3754 **/
3755
3756static
3757irqreturn_t e1000_intr_msi(int irq, void *data)
3758{
3759 struct net_device *netdev = data;
3760 struct e1000_adapter *adapter = netdev_priv(netdev);
3761 struct e1000_hw *hw = &adapter->hw;
3762#ifndef CONFIG_E1000_NAPI
3763 int i;
3764#endif
3765
3766 /* this code avoids the read of ICR but has to get 1000 interrupts
3767 * at every link change event before it will notice the change */
3768 if (++adapter->detect_link >= 1000) {
3769 uint32_t icr = E1000_READ_REG(hw, ICR);
3770#ifdef CONFIG_E1000_NAPI
3771 /* read ICR disables interrupts using IAM, so keep up with our
3772 * enable/disable accounting */
3773 atomic_inc(&adapter->irq_sem);
3774#endif
3775 adapter->detect_link = 0;
3776 if ((icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) &&
3777 (icr & E1000_ICR_INT_ASSERTED)) {
3778 hw->get_link_status = 1;
3779 /* 80003ES2LAN workaround--
3780 * For packet buffer work-around on link down event;
3781 * disable receives here in the ISR and
3782 * reset adapter in watchdog
3783 */
3784 if (netif_carrier_ok(netdev) &&
3785 (adapter->hw.mac_type == e1000_80003es2lan)) {
3786 /* disable receives */
3787 uint32_t rctl = E1000_READ_REG(hw, RCTL);
3788 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3789 }
3790 /* guard against interrupt when we're going down */
3791 if (!test_bit(__E1000_DOWN, &adapter->flags))
3792 mod_timer(&adapter->watchdog_timer,
3793 jiffies + 1);
3794 }
3795 } else {
3796 E1000_WRITE_REG(hw, ICR, (0xffffffff & ~(E1000_ICR_RXSEQ |
3797 E1000_ICR_LSC)));
3798 /* bummer we have to flush here, but things break otherwise as
3799 * some event appears to be lost or delayed and throughput
3800 * drops. In almost all tests this flush is un-necessary */
3801 E1000_WRITE_FLUSH(hw);
3802#ifdef CONFIG_E1000_NAPI
3803 /* Interrupt Auto-Mask (IAM)...upon writing ICR, interrupts are
3804 * masked. No need for the IMC write, but it does mean we
3805 * should account for it ASAP. */
3806 atomic_inc(&adapter->irq_sem);
3807#endif
3808 }
3809
3810#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003811 if (likely(netif_rx_schedule_prep(netdev))) {
3812 adapter->total_tx_bytes = 0;
3813 adapter->total_tx_packets = 0;
3814 adapter->total_rx_bytes = 0;
3815 adapter->total_rx_packets = 0;
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003816 __netif_rx_schedule(netdev);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003817 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003818 e1000_irq_enable(adapter);
3819#else
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003820 adapter->total_tx_bytes = 0;
3821 adapter->total_rx_bytes = 0;
3822 adapter->total_tx_packets = 0;
3823 adapter->total_rx_packets = 0;
3824
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003825 for (i = 0; i < E1000_MAX_INTR; i++)
3826 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3827 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3828 break;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003829
3830 if (likely(adapter->itr_setting & 3))
3831 e1000_set_itr(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003832#endif
3833
3834 return IRQ_HANDLED;
3835}
3836#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837
3838/**
3839 * e1000_intr - Interrupt Handler
3840 * @irq: interrupt number
3841 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 **/
3843
3844static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003845e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846{
3847 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003848 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003850 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003851#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003852 int i;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003853#endif
3854 if (unlikely(!icr))
3855 return IRQ_NONE; /* Not our interrupt */
3856
3857#ifdef CONFIG_E1000_NAPI
3858 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3859 * not set, then the adapter didn't send an interrupt */
3860 if (unlikely(hw->mac_type >= e1000_82571 &&
3861 !(icr & E1000_ICR_INT_ASSERTED)))
3862 return IRQ_NONE;
3863
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003864 /* Interrupt Auto-Mask...upon reading ICR,
3865 * interrupts are masked. No need for the
3866 * IMC write, but it does mean we should
3867 * account for it ASAP. */
3868 if (likely(hw->mac_type >= e1000_82571))
3869 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003870#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003872 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003874 /* 80003ES2LAN workaround--
3875 * For packet buffer work-around on link down event;
3876 * disable receives here in the ISR and
3877 * reset adapter in watchdog
3878 */
3879 if (netif_carrier_ok(netdev) &&
3880 (adapter->hw.mac_type == e1000_80003es2lan)) {
3881 /* disable receives */
3882 rctl = E1000_READ_REG(hw, RCTL);
3883 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3884 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003885 /* guard against interrupt when we're going down */
3886 if (!test_bit(__E1000_DOWN, &adapter->flags))
3887 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 }
3889
3890#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003891 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003892 /* disable interrupts, without the synchronize_irq bit */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003893 atomic_inc(&adapter->irq_sem);
3894 E1000_WRITE_REG(hw, IMC, ~0);
3895 E1000_WRITE_FLUSH(hw);
3896 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003897 if (likely(netif_rx_schedule_prep(netdev))) {
3898 adapter->total_tx_bytes = 0;
3899 adapter->total_tx_packets = 0;
3900 adapter->total_rx_bytes = 0;
3901 adapter->total_rx_packets = 0;
Auke Kokd3d9e482006-07-14 16:14:23 -07003902 __netif_rx_schedule(netdev);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003903 } else
Auke Kok90fb5132006-11-01 08:47:30 -08003904 /* this really should not happen! if it does it is basically a
3905 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003906 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003907#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003909 * Due to Hub Link bus being occupied, an interrupt
3910 * de-assertion message is not able to be sent.
3911 * When an interrupt assertion message is generated later,
3912 * two messages are re-ordered and sent out.
3913 * That causes APIC to think 82547 is in de-assertion
3914 * state, while 82547 is in assertion state, resulting
3915 * in dead lock. Writing IMC forces 82547 into
3916 * de-assertion state.
3917 */
3918 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003920 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 }
3922
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003923 adapter->total_tx_bytes = 0;
3924 adapter->total_rx_bytes = 0;
3925 adapter->total_tx_packets = 0;
3926 adapter->total_rx_packets = 0;
3927
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003928 for (i = 0; i < E1000_MAX_INTR; i++)
3929 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003930 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 break;
3932
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003933 if (likely(adapter->itr_setting & 3))
3934 e1000_set_itr(adapter);
3935
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003936 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003938
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003939#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 return IRQ_HANDLED;
3941}
3942
3943#ifdef CONFIG_E1000_NAPI
3944/**
3945 * e1000_clean - NAPI Rx polling callback
3946 * @adapter: board private structure
3947 **/
3948
3949static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003950e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003952 struct e1000_adapter *adapter;
3953 int work_to_do = min(*budget, poll_dev->quota);
Auke Kokd3d9e482006-07-14 16:14:23 -07003954 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003955
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003956 /* Must NOT use netdev_priv macro here. */
3957 adapter = poll_dev->priv;
3958
3959 /* Keep link state information with original netdev */
Auke Kokd3d9e482006-07-14 16:14:23 -07003960 if (!netif_carrier_ok(poll_dev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003961 goto quit_polling;
3962
Auke Kokd3d9e482006-07-14 16:14:23 -07003963 /* e1000_clean is called per-cpu. This lock protects
3964 * tx_ring[0] from being cleaned by multiple cpus
3965 * simultaneously. A failure obtaining the lock means
3966 * tx_ring[0] is currently being cleaned anyway. */
3967 if (spin_trylock(&adapter->tx_queue_lock)) {
3968 tx_cleaned = e1000_clean_tx_irq(adapter,
3969 &adapter->tx_ring[0]);
3970 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003971 }
3972
Auke Kokd3d9e482006-07-14 16:14:23 -07003973 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003974 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975
3976 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003977 poll_dev->quota -= work_done;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003978
Malli Chilakala2b028932005-06-17 17:46:06 -07003979 /* If no Tx and not enough Rx work done, exit the polling mode */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003980 if ((!tx_cleaned && (work_done == 0)) ||
Auke Kokd3d9e482006-07-14 16:14:23 -07003981 !netif_running(poll_dev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003982quit_polling:
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003983 if (likely(adapter->itr_setting & 3))
3984 e1000_set_itr(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003985 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 e1000_irq_enable(adapter);
3987 return 0;
3988 }
3989
3990 return 1;
3991}
3992
3993#endif
3994/**
3995 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3996 * @adapter: board private structure
3997 **/
3998
3999static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004000e1000_clean_tx_irq(struct e1000_adapter *adapter,
4001 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 struct net_device *netdev = adapter->netdev;
4004 struct e1000_tx_desc *tx_desc, *eop_desc;
4005 struct e1000_buffer *buffer_info;
4006 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004007#ifdef CONFIG_E1000_NAPI
4008 unsigned int count = 0;
4009#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004011 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012
4013 i = tx_ring->next_to_clean;
4014 eop = tx_ring->buffer_info[i].next_to_watch;
4015 eop_desc = E1000_TX_DESC(*tx_ring, eop);
4016
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004017 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004018 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 tx_desc = E1000_TX_DESC(*tx_ring, i);
4020 buffer_info = &tx_ring->buffer_info[i];
4021 cleaned = (i == eop);
4022
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004023 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004024 struct sk_buff *skb = buffer_info->skb;
4025 unsigned int segs = skb_shinfo(skb)->gso_segs;
4026 total_tx_packets += segs;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004027 total_tx_packets++;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004028 total_tx_bytes += skb->len;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004029 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05004030 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08004031 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004033 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004035
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 eop = tx_ring->buffer_info[i].next_to_watch;
4037 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004038#ifdef CONFIG_E1000_NAPI
4039#define E1000_TX_WEIGHT 64
4040 /* weight of a sort for tx, to avoid endless transmit cleanup */
4041 if (count++ == E1000_TX_WEIGHT) break;
4042#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 }
4044
4045 tx_ring->next_to_clean = i;
4046
Auke Kok77b2aad2006-04-14 19:05:25 -07004047#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07004048 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
4049 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
4050 /* Make sure that anybody stopping the queue after this
4051 * sees the new next_to_clean.
4052 */
4053 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004054 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07004055 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004056 ++adapter->restart_queue;
4057 }
Auke Kok77b2aad2006-04-14 19:05:25 -07004058 }
Malli Chilakala26483452005-04-28 19:44:46 -07004059
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004060 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07004061 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 * check with the clearing of time_stamp and movement of i */
4063 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08004064 if (tx_ring->buffer_info[eop].dma &&
4065 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08004066 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004067 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08004068 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004069
4070 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07004071 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004072 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004073 " TDH <%x>\n"
4074 " TDT <%x>\n"
4075 " next_to_use <%x>\n"
4076 " next_to_clean <%x>\n"
4077 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004078 " time_stamp <%lx>\n"
4079 " next_to_watch <%x>\n"
4080 " jiffies <%lx>\n"
4081 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004082 (unsigned long)((tx_ring - adapter->tx_ring) /
4083 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004084 readl(adapter->hw.hw_addr + tx_ring->tdh),
4085 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004086 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08004087 tx_ring->next_to_clean,
4088 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004089 eop,
4090 jiffies,
4091 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004095 adapter->total_tx_bytes += total_tx_bytes;
4096 adapter->total_tx_packets += total_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 return cleaned;
4098}
4099
4100/**
4101 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004102 * @adapter: board private structure
4103 * @status_err: receive descriptor status and error fields
4104 * @csum: receive descriptor csum field
4105 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 **/
4107
Auke Koke619d522006-04-14 19:04:52 -07004108static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004110 uint32_t status_err, uint32_t csum,
4111 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004113 uint16_t status = (uint16_t)status_err;
4114 uint8_t errors = (uint8_t)(status_err >> 24);
4115 skb->ip_summed = CHECKSUM_NONE;
4116
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004118 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004120 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004121 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004122 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004123 /* let the stack verify checksum errors */
4124 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 return;
4126 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004127 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004128 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
4129 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004130 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004132 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004133 return;
4134 }
4135 /* It must be a TCP or UDP packet with a valid checksum */
4136 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 /* TCP checksum is good */
4138 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004139 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
4140 /* IP fragment with UDP payload */
4141 /* Hardware complements the payload checksum, so we undo it
4142 * and then put the value in host order for further stack use.
4143 */
4144 csum = ntohl(csum ^ 0xFFFF);
4145 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07004146 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004148 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149}
4150
4151/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004152 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 * @adapter: board private structure
4154 **/
4155
4156static boolean_t
4157#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004158e1000_clean_rx_irq(struct e1000_adapter *adapter,
4159 struct e1000_rx_ring *rx_ring,
4160 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004162e1000_clean_rx_irq(struct e1000_adapter *adapter,
4163 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164#endif
4165{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 struct net_device *netdev = adapter->netdev;
4167 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004168 struct e1000_rx_desc *rx_desc, *next_rxd;
4169 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 unsigned long flags;
4171 uint32_t length;
4172 uint8_t last_byte;
4173 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004174 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004175 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004176 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177
4178 i = rx_ring->next_to_clean;
4179 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004180 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004182 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004183 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004184 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004185
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004187 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188 break;
4189 (*work_done)++;
4190#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08004191 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004192 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004193 buffer_info->skb = NULL;
4194
Jeff Kirsher30320be2006-03-02 18:21:57 -08004195 prefetch(skb->data - NET_IP_ALIGN);
4196
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004197 if (++i == rx_ring->count) i = 0;
4198 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004199 prefetch(next_rxd);
4200
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004201 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004202
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004203 cleaned = TRUE;
4204 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004205 pci_unmap_single(pdev,
4206 buffer_info->dma,
4207 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 PCI_DMA_FROMDEVICE);
4209
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 length = le16_to_cpu(rx_desc->length);
4211
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004212 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4213 /* All receives must fit into a single buffer */
4214 E1000_DBG("%s: Receive packet consumed multiple"
4215 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004216 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004217 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 goto next_desc;
4219 }
4220
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004221 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004223 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 rx_desc->errors, length, last_byte)) {
4225 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004226 e1000_tbi_adjust_stats(&adapter->hw,
4227 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 length, skb->data);
4229 spin_unlock_irqrestore(&adapter->stats_lock,
4230 flags);
4231 length--;
4232 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004233 /* recycle */
4234 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 goto next_desc;
4236 }
Auke Kok1cb58212006-04-18 12:31:04 -07004237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004239 /* adjust length to remove Ethernet CRC, this must be
4240 * done after the TBI_ACCEPT workaround above */
4241 length -= 4;
4242
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004243 /* probably a little skewed due to removing CRC */
4244 total_rx_bytes += length;
4245 total_rx_packets++;
4246
Jeff Kirshera292ca62006-01-12 16:51:30 -08004247 /* code added for copybreak, this should improve
4248 * performance for small packets with large amounts
4249 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004250 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004251 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004252 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004253 if (new_skb) {
4254 skb_reserve(new_skb, NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004255 memcpy(new_skb->data - NET_IP_ALIGN,
4256 skb->data - NET_IP_ALIGN,
4257 length + NET_IP_ALIGN);
4258 /* save the skb in buffer_info as good */
4259 buffer_info->skb = skb;
4260 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004261 }
Auke Kok996695d2006-11-01 08:47:50 -08004262 /* else just continue with the old one */
4263 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004264 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004265 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266
4267 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004268 e1000_rx_checksum(adapter,
4269 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004270 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004271 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004272
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 skb->protocol = eth_type_trans(skb, netdev);
4274#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004275 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08004276 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004278 le16_to_cpu(rx_desc->special) &
4279 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 } else {
4281 netif_receive_skb(skb);
4282 }
4283#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004284 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004285 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286 vlan_hwaccel_rx(skb, adapter->vlgrp,
4287 le16_to_cpu(rx_desc->special) &
4288 E1000_RXD_SPC_VLAN_MASK);
4289 } else {
4290 netif_rx(skb);
4291 }
4292#endif /* CONFIG_E1000_NAPI */
4293 netdev->last_rx = jiffies;
4294
4295next_desc:
4296 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004298 /* return some buffers to hardware, one at a time is too slow */
4299 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4300 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4301 cleaned_count = 0;
4302 }
4303
Jeff Kirsher30320be2006-03-02 18:21:57 -08004304 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004305 rx_desc = next_rxd;
4306 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004309
4310 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4311 if (cleaned_count)
4312 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004314 adapter->total_rx_packets += total_rx_packets;
4315 adapter->total_rx_bytes += total_rx_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 return cleaned;
4317}
4318
4319/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004320 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4321 * @adapter: board private structure
4322 **/
4323
4324static boolean_t
4325#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004326e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4327 struct e1000_rx_ring *rx_ring,
4328 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004329#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004330e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4331 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004332#endif
4333{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004334 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004335 struct net_device *netdev = adapter->netdev;
4336 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004337 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004338 struct e1000_ps_page *ps_page;
4339 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07004340 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004341 unsigned int i, j;
4342 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004343 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004344 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004345 unsigned int total_rx_bytes=0, total_rx_packets=0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004346
4347 i = rx_ring->next_to_clean;
4348 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07004349 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07004350 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004351
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004352 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004353 ps_page = &rx_ring->ps_page[i];
4354 ps_page_dma = &rx_ring->ps_page_dma[i];
4355#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004356 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004357 break;
4358 (*work_done)++;
4359#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004360 skb = buffer_info->skb;
4361
Jeff Kirsher30320be2006-03-02 18:21:57 -08004362 /* in the packet split case this is header only */
4363 prefetch(skb->data - NET_IP_ALIGN);
4364
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004365 if (++i == rx_ring->count) i = 0;
4366 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004367 prefetch(next_rxd);
4368
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004369 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004370
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004371 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004372 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004373 pci_unmap_single(pdev, buffer_info->dma,
4374 buffer_info->length,
4375 PCI_DMA_FROMDEVICE);
4376
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004377 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004378 E1000_DBG("%s: Packet Split buffers didn't pick up"
4379 " the full packet\n", netdev->name);
4380 dev_kfree_skb_irq(skb);
4381 goto next_desc;
4382 }
4383
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004384 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004385 dev_kfree_skb_irq(skb);
4386 goto next_desc;
4387 }
4388
4389 length = le16_to_cpu(rx_desc->wb.middle.length0);
4390
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004391 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004392 E1000_DBG("%s: Last part of the packet spanning"
4393 " multiple descriptors\n", netdev->name);
4394 dev_kfree_skb_irq(skb);
4395 goto next_desc;
4396 }
4397
4398 /* Good Receive */
4399 skb_put(skb, length);
4400
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004401 {
4402 /* this looks ugly, but it seems compiler issues make it
4403 more efficient than reusing j */
4404 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4405
4406 /* page alloc/put takes too long and effects small packet
4407 * throughput, so unsplit small packets and save the alloc/put*/
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004408 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004409 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004410 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004411 * kmap_atomic, so we can't hold the mapping
4412 * very long */
4413 pci_dma_sync_single_for_cpu(pdev,
4414 ps_page_dma->ps_page_dma[0],
4415 PAGE_SIZE,
4416 PCI_DMA_FROMDEVICE);
4417 vaddr = kmap_atomic(ps_page->ps_page[0],
4418 KM_SKB_DATA_SOFTIRQ);
4419 memcpy(skb->tail, vaddr, l1);
4420 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4421 pci_dma_sync_single_for_device(pdev,
4422 ps_page_dma->ps_page_dma[0],
4423 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004424 /* remove the CRC */
4425 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004426 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004427 goto copydone;
4428 } /* if */
4429 }
Auke Kok90fb5132006-11-01 08:47:30 -08004430
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004431 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004432 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004433 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004434 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4435 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4436 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004437 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4438 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004439 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004440 skb->len += length;
4441 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004442 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004443 }
4444
Auke Kokf235a2a2006-07-14 16:14:34 -07004445 /* strip the ethernet crc, problem is we're using pages now so
4446 * this whole operation can get a little cpu intensive */
4447 pskb_trim(skb, skb->len - 4);
4448
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004449copydone:
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004450 total_rx_bytes += skb->len;
4451 total_rx_packets++;
4452
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004453 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004454 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004455 skb->protocol = eth_type_trans(skb, netdev);
4456
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004457 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004458 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004459 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004460#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004461 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004462 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004463 le16_to_cpu(rx_desc->wb.middle.vlan) &
4464 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004465 } else {
4466 netif_receive_skb(skb);
4467 }
4468#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004469 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004470 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004471 le16_to_cpu(rx_desc->wb.middle.vlan) &
4472 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004473 } else {
4474 netif_rx(skb);
4475 }
4476#endif /* CONFIG_E1000_NAPI */
4477 netdev->last_rx = jiffies;
4478
4479next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004480 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004481 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004482
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004483 /* return some buffers to hardware, one at a time is too slow */
4484 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4485 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4486 cleaned_count = 0;
4487 }
4488
Jeff Kirsher30320be2006-03-02 18:21:57 -08004489 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004490 rx_desc = next_rxd;
4491 buffer_info = next_buffer;
4492
Malli Chilakala683a38f2005-06-17 17:43:25 -07004493 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004494 }
4495 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004496
4497 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4498 if (cleaned_count)
4499 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004500
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004501 adapter->total_rx_packets += total_rx_packets;
4502 adapter->total_rx_bytes += total_rx_bytes;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004503 return cleaned;
4504}
4505
4506/**
4507 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 * @adapter: address of board private structure
4509 **/
4510
4511static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004512e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004513 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004514 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 struct net_device *netdev = adapter->netdev;
4517 struct pci_dev *pdev = adapter->pdev;
4518 struct e1000_rx_desc *rx_desc;
4519 struct e1000_buffer *buffer_info;
4520 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004521 unsigned int i;
4522 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523
4524 i = rx_ring->next_to_use;
4525 buffer_info = &rx_ring->buffer_info[i];
4526
Jeff Kirshera292ca62006-01-12 16:51:30 -08004527 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004528 skb = buffer_info->skb;
4529 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004530 skb_trim(skb, 0);
4531 goto map_skb;
4532 }
4533
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004534 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004535 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004537 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 break;
4539 }
4540
Malli Chilakala26483452005-04-28 19:44:46 -07004541 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4543 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004544 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4545 "at %p\n", bufsz, skb->data);
4546 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004547 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004548 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 if (!skb) {
4550 dev_kfree_skb(oldskb);
4551 break;
4552 }
Malli Chilakala26483452005-04-28 19:44:46 -07004553
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4555 /* give up */
4556 dev_kfree_skb(skb);
4557 dev_kfree_skb(oldskb);
4558 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004560
4561 /* Use new allocation */
4562 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564 /* Make buffer alignment 2 beyond a 16 byte boundary
4565 * this will result in a 16 byte aligned IP header after
4566 * the 14 byte MAC header is removed
4567 */
4568 skb_reserve(skb, NET_IP_ALIGN);
4569
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 buffer_info->skb = skb;
4571 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004572map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 buffer_info->dma = pci_map_single(pdev,
4574 skb->data,
4575 adapter->rx_buffer_len,
4576 PCI_DMA_FROMDEVICE);
4577
Malli Chilakala26483452005-04-28 19:44:46 -07004578 /* Fix for errata 23, can't cross 64kB boundary */
4579 if (!e1000_check_64k_bound(adapter,
4580 (void *)(unsigned long)buffer_info->dma,
4581 adapter->rx_buffer_len)) {
4582 DPRINTK(RX_ERR, ERR,
4583 "dma align check failed: %u bytes at %p\n",
4584 adapter->rx_buffer_len,
4585 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 dev_kfree_skb(skb);
4587 buffer_info->skb = NULL;
4588
Malli Chilakala26483452005-04-28 19:44:46 -07004589 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 adapter->rx_buffer_len,
4591 PCI_DMA_FROMDEVICE);
4592
4593 break; /* while !buffer_info->skb */
4594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 rx_desc = E1000_RX_DESC(*rx_ring, i);
4596 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4597
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004598 if (unlikely(++i == rx_ring->count))
4599 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 buffer_info = &rx_ring->buffer_info[i];
4601 }
4602
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004603 if (likely(rx_ring->next_to_use != i)) {
4604 rx_ring->next_to_use = i;
4605 if (unlikely(i-- == 0))
4606 i = (rx_ring->count - 1);
4607
4608 /* Force memory writes to complete before letting h/w
4609 * know there are new descriptors to fetch. (Only
4610 * applicable for weak-ordered memory model archs,
4611 * such as IA-64). */
4612 wmb();
4613 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615}
4616
4617/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004618 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4619 * @adapter: address of board private structure
4620 **/
4621
4622static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004623e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004624 struct e1000_rx_ring *rx_ring,
4625 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004626{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004627 struct net_device *netdev = adapter->netdev;
4628 struct pci_dev *pdev = adapter->pdev;
4629 union e1000_rx_desc_packet_split *rx_desc;
4630 struct e1000_buffer *buffer_info;
4631 struct e1000_ps_page *ps_page;
4632 struct e1000_ps_page_dma *ps_page_dma;
4633 struct sk_buff *skb;
4634 unsigned int i, j;
4635
4636 i = rx_ring->next_to_use;
4637 buffer_info = &rx_ring->buffer_info[i];
4638 ps_page = &rx_ring->ps_page[i];
4639 ps_page_dma = &rx_ring->ps_page_dma[i];
4640
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004641 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004642 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4643
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004644 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004645 if (j < adapter->rx_ps_pages) {
4646 if (likely(!ps_page->ps_page[j])) {
4647 ps_page->ps_page[j] =
4648 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004649 if (unlikely(!ps_page->ps_page[j])) {
4650 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004651 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004652 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004653 ps_page_dma->ps_page_dma[j] =
4654 pci_map_page(pdev,
4655 ps_page->ps_page[j],
4656 0, PAGE_SIZE,
4657 PCI_DMA_FROMDEVICE);
4658 }
4659 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004660 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004661 * this info.
4662 */
4663 rx_desc->read.buffer_addr[j+1] =
4664 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4665 } else
4666 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004667 }
4668
David S. Miller87f50322006-07-31 22:39:40 -07004669 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004670 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004671
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004672 if (unlikely(!skb)) {
4673 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004674 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004675 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004676
4677 /* Make buffer alignment 2 beyond a 16 byte boundary
4678 * this will result in a 16 byte aligned IP header after
4679 * the 14 byte MAC header is removed
4680 */
4681 skb_reserve(skb, NET_IP_ALIGN);
4682
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004683 buffer_info->skb = skb;
4684 buffer_info->length = adapter->rx_ps_bsize0;
4685 buffer_info->dma = pci_map_single(pdev, skb->data,
4686 adapter->rx_ps_bsize0,
4687 PCI_DMA_FROMDEVICE);
4688
4689 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4690
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004691 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004692 buffer_info = &rx_ring->buffer_info[i];
4693 ps_page = &rx_ring->ps_page[i];
4694 ps_page_dma = &rx_ring->ps_page_dma[i];
4695 }
4696
4697no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004698 if (likely(rx_ring->next_to_use != i)) {
4699 rx_ring->next_to_use = i;
4700 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4701
4702 /* Force memory writes to complete before letting h/w
4703 * know there are new descriptors to fetch. (Only
4704 * applicable for weak-ordered memory model archs,
4705 * such as IA-64). */
4706 wmb();
4707 /* Hardware increments by 16 bytes, but packet split
4708 * descriptors are 32 bytes...so we increment tail
4709 * twice as much.
4710 */
4711 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4712 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004713}
4714
4715/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4717 * @adapter:
4718 **/
4719
4720static void
4721e1000_smartspeed(struct e1000_adapter *adapter)
4722{
4723 uint16_t phy_status;
4724 uint16_t phy_ctrl;
4725
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004726 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4728 return;
4729
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004730 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 /* If Master/Slave config fault is asserted twice,
4732 * we assume back-to-back */
4733 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004734 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004736 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004738 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4740 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4741 phy_ctrl);
4742 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004743 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4745 &phy_ctrl)) {
4746 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4747 MII_CR_RESTART_AUTO_NEG);
4748 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4749 phy_ctrl);
4750 }
4751 }
4752 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004753 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 /* If still no link, perhaps using 2/3 pair cable */
4755 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4756 phy_ctrl |= CR_1000T_MS_ENABLE;
4757 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004758 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4760 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4761 MII_CR_RESTART_AUTO_NEG);
4762 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4763 }
4764 }
4765 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004766 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 adapter->smartspeed = 0;
4768}
4769
4770/**
4771 * e1000_ioctl -
4772 * @netdev:
4773 * @ifreq:
4774 * @cmd:
4775 **/
4776
4777static int
4778e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4779{
4780 switch (cmd) {
4781 case SIOCGMIIPHY:
4782 case SIOCGMIIREG:
4783 case SIOCSMIIREG:
4784 return e1000_mii_ioctl(netdev, ifr, cmd);
4785 default:
4786 return -EOPNOTSUPP;
4787 }
4788}
4789
4790/**
4791 * e1000_mii_ioctl -
4792 * @netdev:
4793 * @ifreq:
4794 * @cmd:
4795 **/
4796
4797static int
4798e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4799{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004800 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 struct mii_ioctl_data *data = if_mii(ifr);
4802 int retval;
4803 uint16_t mii_reg;
4804 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004805 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004807 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 return -EOPNOTSUPP;
4809
4810 switch (cmd) {
4811 case SIOCGMIIPHY:
4812 data->phy_id = adapter->hw.phy_addr;
4813 break;
4814 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004815 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004817 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004818 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004819 &data->val_out)) {
4820 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004822 }
4823 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824 break;
4825 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004826 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004828 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829 return -EFAULT;
4830 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004831 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004832 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004833 mii_reg)) {
4834 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004836 }
Auke Kokdc86d322006-04-18 12:30:51 -07004837 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 switch (data->reg_num) {
4839 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004840 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004842 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843 adapter->hw.autoneg = 1;
4844 adapter->hw.autoneg_advertised = 0x2F;
4845 } else {
4846 if (mii_reg & 0x40)
4847 spddplx = SPEED_1000;
4848 else if (mii_reg & 0x2000)
4849 spddplx = SPEED_100;
4850 else
4851 spddplx = SPEED_10;
4852 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004853 ? DUPLEX_FULL :
4854 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 retval = e1000_set_spd_dplx(adapter,
4856 spddplx);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004857 if (retval) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004858 spin_unlock_irqrestore(
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004859 &adapter->stats_lock,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004860 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 }
Auke Kok2db10a02006-06-27 09:06:28 -07004864 if (netif_running(adapter->netdev))
4865 e1000_reinit_locked(adapter);
4866 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 e1000_reset(adapter);
4868 break;
4869 case M88E1000_PHY_SPEC_CTRL:
4870 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004871 if (e1000_phy_reset(&adapter->hw)) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004872 spin_unlock_irqrestore(
4873 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 break;
4877 }
4878 } else {
4879 switch (data->reg_num) {
4880 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004881 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004883 if (netif_running(adapter->netdev))
4884 e1000_reinit_locked(adapter);
4885 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886 e1000_reset(adapter);
4887 break;
4888 }
4889 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004890 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 break;
4892 default:
4893 return -EOPNOTSUPP;
4894 }
4895 return E1000_SUCCESS;
4896}
4897
4898void
4899e1000_pci_set_mwi(struct e1000_hw *hw)
4900{
4901 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004902 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004904 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004905 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906}
4907
4908void
4909e1000_pci_clear_mwi(struct e1000_hw *hw)
4910{
4911 struct e1000_adapter *adapter = hw->back;
4912
4913 pci_clear_mwi(adapter->pdev);
4914}
4915
4916void
4917e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4918{
4919 struct e1000_adapter *adapter = hw->back;
4920
4921 pci_read_config_word(adapter->pdev, reg, value);
4922}
4923
4924void
4925e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4926{
4927 struct e1000_adapter *adapter = hw->back;
4928
4929 pci_write_config_word(adapter->pdev, reg, *value);
4930}
4931
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004932int32_t
4933e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4934{
4935 struct e1000_adapter *adapter = hw->back;
4936 uint16_t cap_offset;
4937
4938 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4939 if (!cap_offset)
4940 return -E1000_ERR_CONFIG;
4941
4942 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4943
4944 return E1000_SUCCESS;
4945}
4946
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947void
4948e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4949{
4950 outl(value, port);
4951}
4952
4953static void
4954e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4955{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004956 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 uint32_t ctrl, rctl;
4958
4959 e1000_irq_disable(adapter);
4960 adapter->vlgrp = grp;
4961
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004962 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 /* enable VLAN tag insert/strip */
4964 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4965 ctrl |= E1000_CTRL_VME;
4966 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4967
Auke Kokcd94dd02006-06-27 09:08:22 -07004968 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004969 /* enable VLAN receive filtering */
4970 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4971 rctl |= E1000_RCTL_VFE;
4972 rctl &= ~E1000_RCTL_CFIEN;
4973 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4974 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004975 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 } else {
4977 /* disable VLAN tag insert/strip */
4978 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4979 ctrl &= ~E1000_CTRL_VME;
4980 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4981
Auke Kokcd94dd02006-06-27 09:08:22 -07004982 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004983 /* disable VLAN filtering */
4984 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4985 rctl &= ~E1000_RCTL_VFE;
4986 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4987 if (adapter->mng_vlan_id !=
4988 (uint16_t)E1000_MNG_VLAN_NONE) {
4989 e1000_vlan_rx_kill_vid(netdev,
4990 adapter->mng_vlan_id);
4991 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4992 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 }
4995
4996 e1000_irq_enable(adapter);
4997}
4998
4999static void
5000e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
5001{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005002 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005004
5005 if ((adapter->hw.mng_cookie.status &
5006 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
5007 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005008 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 /* add VID to filter table */
5010 index = (vid >> 5) & 0x7F;
5011 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5012 vfta |= (1 << (vid & 0x1F));
5013 e1000_write_vfta(&adapter->hw, index, vfta);
5014}
5015
5016static void
5017e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
5018{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005019 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020 uint32_t vfta, index;
5021
5022 e1000_irq_disable(adapter);
5023
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005024 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 adapter->vlgrp->vlan_devices[vid] = NULL;
5026
5027 e1000_irq_enable(adapter);
5028
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005029 if ((adapter->hw.mng_cookie.status &
5030 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08005031 (vid == adapter->mng_vlan_id)) {
5032 /* release control to f/w */
5033 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005034 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08005035 }
5036
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037 /* remove VID from filter table */
5038 index = (vid >> 5) & 0x7F;
5039 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5040 vfta &= ~(1 << (vid & 0x1F));
5041 e1000_write_vfta(&adapter->hw, index, vfta);
5042}
5043
5044static void
5045e1000_restore_vlan(struct e1000_adapter *adapter)
5046{
5047 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
5048
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005049 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005051 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
5052 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053 continue;
5054 e1000_vlan_rx_add_vid(adapter->netdev, vid);
5055 }
5056 }
5057}
5058
5059int
5060e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
5061{
5062 adapter->hw.autoneg = 0;
5063
Malli Chilakala69213682005-06-17 17:44:20 -07005064 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005065 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07005066 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
5067 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
5068 return -EINVAL;
5069 }
5070
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005071 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072 case SPEED_10 + DUPLEX_HALF:
5073 adapter->hw.forced_speed_duplex = e1000_10_half;
5074 break;
5075 case SPEED_10 + DUPLEX_FULL:
5076 adapter->hw.forced_speed_duplex = e1000_10_full;
5077 break;
5078 case SPEED_100 + DUPLEX_HALF:
5079 adapter->hw.forced_speed_duplex = e1000_100_half;
5080 break;
5081 case SPEED_100 + DUPLEX_FULL:
5082 adapter->hw.forced_speed_duplex = e1000_100_full;
5083 break;
5084 case SPEED_1000 + DUPLEX_FULL:
5085 adapter->hw.autoneg = 1;
5086 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
5087 break;
5088 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5089 default:
Malli Chilakala26483452005-04-28 19:44:46 -07005090 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 return -EINVAL;
5092 }
5093 return 0;
5094}
5095
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07005096#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08005097/* Save/restore 16 or 64 dwords of PCI config space depending on which
5098 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005099 */
5100#define PCIE_CONFIG_SPACE_LEN 256
5101#define PCI_CONFIG_SPACE_LEN 64
5102static int
5103e1000_pci_save_state(struct e1000_adapter *adapter)
5104{
5105 struct pci_dev *dev = adapter->pdev;
5106 int size;
5107 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08005108
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005109 if (adapter->hw.mac_type >= e1000_82571)
5110 size = PCIE_CONFIG_SPACE_LEN;
5111 else
5112 size = PCI_CONFIG_SPACE_LEN;
5113
5114 WARN_ON(adapter->config_space != NULL);
5115
5116 adapter->config_space = kmalloc(size, GFP_KERNEL);
5117 if (!adapter->config_space) {
5118 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
5119 return -ENOMEM;
5120 }
5121 for (i = 0; i < (size / 4); i++)
5122 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
5123 return 0;
5124}
5125
5126static void
5127e1000_pci_restore_state(struct e1000_adapter *adapter)
5128{
5129 struct pci_dev *dev = adapter->pdev;
5130 int size;
5131 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08005132
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005133 if (adapter->config_space == NULL)
5134 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08005135
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005136 if (adapter->hw.mac_type >= e1000_82571)
5137 size = PCIE_CONFIG_SPACE_LEN;
5138 else
5139 size = PCI_CONFIG_SPACE_LEN;
5140 for (i = 0; i < (size / 4); i++)
5141 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
5142 kfree(adapter->config_space);
5143 adapter->config_space = NULL;
5144 return;
5145}
5146#endif /* CONFIG_PM */
5147
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07005149e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150{
5151 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005152 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005153 uint32_t ctrl, ctrl_ext, rctl, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005154 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07005155#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08005156 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07005157#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158
5159 netif_device_detach(netdev);
5160
Auke Kok2db10a02006-06-27 09:06:28 -07005161 if (netif_running(netdev)) {
5162 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07005164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005166#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08005167 /* Implement our own version of pci_save_state(pdev) because pci-
5168 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005169 retval = e1000_pci_save_state(adapter);
5170 if (retval)
5171 return retval;
5172#endif
5173
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005175 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176 wufc &= ~E1000_WUFC_LNKC;
5177
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005178 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179 e1000_setup_rctl(adapter);
5180 e1000_set_multi(netdev);
5181
5182 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005183 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5185 rctl |= E1000_RCTL_MPE;
5186 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5187 }
5188
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005189 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5191 /* advertise wake from D3Cold */
5192 #define E1000_CTRL_ADVD3WUC 0x00100000
5193 /* phy power management enable */
5194 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5195 ctrl |= E1000_CTRL_ADVD3WUC |
5196 E1000_CTRL_EN_PHY_PWR_MGMT;
5197 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5198 }
5199
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005200 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201 adapter->hw.media_type == e1000_media_type_internal_serdes) {
5202 /* keep the laser running in D3 */
5203 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
5204 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5205 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
5206 }
5207
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005208 /* Allow time for pending master requests to run */
5209 e1000_disable_pciex_master(&adapter->hw);
5210
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
5212 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07005213 pci_enable_wake(pdev, PCI_D3hot, 1);
5214 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 } else {
5216 E1000_WRITE_REG(&adapter->hw, WUC, 0);
5217 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07005218 pci_enable_wake(pdev, PCI_D3hot, 0);
5219 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 }
5221
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005222 e1000_release_manageability(adapter);
5223
5224 /* make sure adapter isn't asleep if manageability is enabled */
5225 if (adapter->en_mng_pt) {
5226 pci_enable_wake(pdev, PCI_D3hot, 1);
5227 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 }
5229
Auke Kokcd94dd02006-06-27 09:08:22 -07005230 if (adapter->hw.phy_type == e1000_phy_igp_3)
5231 e1000_phy_powerdown_workaround(&adapter->hw);
5232
Auke Kokedd106f2006-11-06 08:57:12 -08005233 if (netif_running(netdev))
5234 e1000_free_irq(adapter);
5235
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005236 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5237 * would have already happened in close and is redundant. */
5238 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005239
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005241
Auke Kokd0e027d2006-04-14 19:04:40 -07005242 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243
5244 return 0;
5245}
5246
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005247#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248static int
5249e1000_resume(struct pci_dev *pdev)
5250{
5251 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005252 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005253 uint32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254
Auke Kokd0e027d2006-04-14 19:04:40 -07005255 pci_set_power_state(pdev, PCI_D0);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005256 e1000_pci_restore_state(adapter);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005257 if ((err = pci_enable_device(pdev))) {
5258 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5259 return err;
5260 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005261 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262
Auke Kokd0e027d2006-04-14 19:04:40 -07005263 pci_enable_wake(pdev, PCI_D3hot, 0);
5264 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265
Auke Kokedd106f2006-11-06 08:57:12 -08005266 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
5267 return err;
5268
5269 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270 e1000_reset(adapter);
5271 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5272
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005273 e1000_init_manageability(adapter);
5274
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005275 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 e1000_up(adapter);
5277
5278 netif_device_attach(netdev);
5279
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005280 /* If the controller is 82573 and f/w is AMT, do not set
5281 * DRV_LOAD until the interface is up. For all other cases,
5282 * let the f/w know that the h/w is now under the control
5283 * of the driver. */
5284 if (adapter->hw.mac_type != e1000_82573 ||
5285 !e1000_check_mng_mode(&adapter->hw))
5286 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005287
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288 return 0;
5289}
5290#endif
Auke Kokc653e632006-05-23 13:35:57 -07005291
5292static void e1000_shutdown(struct pci_dev *pdev)
5293{
5294 e1000_suspend(pdev, PMSG_SUSPEND);
5295}
5296
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297#ifdef CONFIG_NET_POLL_CONTROLLER
5298/*
5299 * Polling 'interrupt' - used by things like netconsole to send skbs
5300 * without having to re-enable interrupts. It's not called while
5301 * the interrupt routine is executing.
5302 */
5303static void
Malli Chilakala26483452005-04-28 19:44:46 -07005304e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005305{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005306 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005307
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005309 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07005310 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08005311#ifndef CONFIG_E1000_NAPI
5312 adapter->clean_rx(adapter, adapter->rx_ring);
5313#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314 enable_irq(adapter->pdev->irq);
5315}
5316#endif
5317
Auke Kok90267292006-06-08 09:30:24 -07005318/**
5319 * e1000_io_error_detected - called when PCI error is detected
5320 * @pdev: Pointer to PCI device
5321 * @state: The current pci conneection state
5322 *
5323 * This function is called after a PCI bus error affecting
5324 * this device has been detected.
5325 */
5326static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5327{
5328 struct net_device *netdev = pci_get_drvdata(pdev);
5329 struct e1000_adapter *adapter = netdev->priv;
5330
5331 netif_device_detach(netdev);
5332
5333 if (netif_running(netdev))
5334 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005335 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005336
5337 /* Request a slot slot reset. */
5338 return PCI_ERS_RESULT_NEED_RESET;
5339}
5340
5341/**
5342 * e1000_io_slot_reset - called after the pci bus has been reset.
5343 * @pdev: Pointer to PCI device
5344 *
5345 * Restart the card from scratch, as if from a cold-boot. Implementation
5346 * resembles the first-half of the e1000_resume routine.
5347 */
5348static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5349{
5350 struct net_device *netdev = pci_get_drvdata(pdev);
5351 struct e1000_adapter *adapter = netdev->priv;
5352
5353 if (pci_enable_device(pdev)) {
5354 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5355 return PCI_ERS_RESULT_DISCONNECT;
5356 }
5357 pci_set_master(pdev);
5358
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005359 pci_enable_wake(pdev, PCI_D3hot, 0);
5360 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005361
Auke Kok90267292006-06-08 09:30:24 -07005362 e1000_reset(adapter);
5363 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5364
5365 return PCI_ERS_RESULT_RECOVERED;
5366}
5367
5368/**
5369 * e1000_io_resume - called when traffic can start flowing again.
5370 * @pdev: Pointer to PCI device
5371 *
5372 * This callback is called when the error recovery driver tells us that
5373 * its OK to resume normal operation. Implementation resembles the
5374 * second-half of the e1000_resume routine.
5375 */
5376static void e1000_io_resume(struct pci_dev *pdev)
5377{
5378 struct net_device *netdev = pci_get_drvdata(pdev);
5379 struct e1000_adapter *adapter = netdev->priv;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005380
5381 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005382
5383 if (netif_running(netdev)) {
5384 if (e1000_up(adapter)) {
5385 printk("e1000: can't bring device back up after reset\n");
5386 return;
5387 }
5388 }
5389
5390 netif_device_attach(netdev);
5391
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005392 /* If the controller is 82573 and f/w is AMT, do not set
5393 * DRV_LOAD until the interface is up. For all other cases,
5394 * let the f/w know that the h/w is now under the control
5395 * of the driver. */
5396 if (adapter->hw.mac_type != e1000_82573 ||
5397 !e1000_check_mng_mode(&adapter->hw))
5398 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005399
Auke Kok90267292006-06-08 09:30:24 -07005400}
5401
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402/* e1000_main.c */