blob: d4ee8ec34b564f7604876da854f539d00bf53c3c [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 Kok7e721572007-01-18 09:25:33 -080039#define DRV_VERSION "7.3.20-k2"DRIVERNAPI
Stephen Hemmingerabec42a2007-10-29 10:46:19 -070040const char e1000_driver_version[] = DRV_VERSION;
41static const 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 */
Linus Torvalds60e23312008-01-31 00:30:15 +110050#ifdef CONFIG_E1000E_ENABLED
51 #define PCIE(x)
52#else
53 #define PCIE(x) x,
54#endif
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056static struct pci_device_id e1000_pci_tbl[] = {
57 INTEL_E1000_ETHERNET_DEVICE(0x1000),
58 INTEL_E1000_ETHERNET_DEVICE(0x1001),
59 INTEL_E1000_ETHERNET_DEVICE(0x1004),
60 INTEL_E1000_ETHERNET_DEVICE(0x1008),
61 INTEL_E1000_ETHERNET_DEVICE(0x1009),
62 INTEL_E1000_ETHERNET_DEVICE(0x100C),
63 INTEL_E1000_ETHERNET_DEVICE(0x100D),
64 INTEL_E1000_ETHERNET_DEVICE(0x100E),
65 INTEL_E1000_ETHERNET_DEVICE(0x100F),
66 INTEL_E1000_ETHERNET_DEVICE(0x1010),
67 INTEL_E1000_ETHERNET_DEVICE(0x1011),
68 INTEL_E1000_ETHERNET_DEVICE(0x1012),
69 INTEL_E1000_ETHERNET_DEVICE(0x1013),
70 INTEL_E1000_ETHERNET_DEVICE(0x1014),
71 INTEL_E1000_ETHERNET_DEVICE(0x1015),
72 INTEL_E1000_ETHERNET_DEVICE(0x1016),
73 INTEL_E1000_ETHERNET_DEVICE(0x1017),
74 INTEL_E1000_ETHERNET_DEVICE(0x1018),
75 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -070076 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 INTEL_E1000_ETHERNET_DEVICE(0x101D),
78 INTEL_E1000_ETHERNET_DEVICE(0x101E),
79 INTEL_E1000_ETHERNET_DEVICE(0x1026),
80 INTEL_E1000_ETHERNET_DEVICE(0x1027),
81 INTEL_E1000_ETHERNET_DEVICE(0x1028),
Linus Torvalds60e23312008-01-31 00:30:15 +110082PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1049))
83PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104A))
84PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104B))
85PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104C))
86PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104D))
87PCIE( INTEL_E1000_ETHERNET_DEVICE(0x105E))
88PCIE( INTEL_E1000_ETHERNET_DEVICE(0x105F))
89PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1060))
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 INTEL_E1000_ETHERNET_DEVICE(0x1075),
91 INTEL_E1000_ETHERNET_DEVICE(0x1076),
92 INTEL_E1000_ETHERNET_DEVICE(0x1077),
93 INTEL_E1000_ETHERNET_DEVICE(0x1078),
94 INTEL_E1000_ETHERNET_DEVICE(0x1079),
95 INTEL_E1000_ETHERNET_DEVICE(0x107A),
96 INTEL_E1000_ETHERNET_DEVICE(0x107B),
97 INTEL_E1000_ETHERNET_DEVICE(0x107C),
Linus Torvalds60e23312008-01-31 00:30:15 +110098PCIE( INTEL_E1000_ETHERNET_DEVICE(0x107D))
99PCIE( INTEL_E1000_ETHERNET_DEVICE(0x107E))
100PCIE( INTEL_E1000_ETHERNET_DEVICE(0x107F))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Linus Torvalds60e23312008-01-31 00:30:15 +1100102PCIE( INTEL_E1000_ETHERNET_DEVICE(0x108B))
103PCIE( INTEL_E1000_ETHERNET_DEVICE(0x108C))
104PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1096))
105PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1098))
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800106 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Linus Torvalds60e23312008-01-31 00:30:15 +1100107PCIE( INTEL_E1000_ETHERNET_DEVICE(0x109A))
108PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10A4))
109PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10A5))
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800110 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Linus Torvalds60e23312008-01-31 00:30:15 +1100111PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10B9))
112PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10BA))
113PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10BB))
114PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10BC))
115PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10C4))
116PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10C5))
117PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10D5))
118PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10D9))
119PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10DA))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 /* required last entry */
121 {0,}
122};
123
124MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
125
Nicholas Nunley35574762006-09-27 12:53:34 -0700126int e1000_up(struct e1000_adapter *adapter);
127void e1000_down(struct e1000_adapter *adapter);
128void e1000_reinit_locked(struct e1000_adapter *adapter);
129void e1000_reset(struct e1000_adapter *adapter);
130int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
131int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
132int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
133void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
134void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100135static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700136 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100137static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700138 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100139static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700140 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100141static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700142 struct e1000_rx_ring *rx_ring);
143void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145static int e1000_init_module(void);
146static void e1000_exit_module(void);
147static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
148static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400149static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150static int e1000_sw_init(struct e1000_adapter *adapter);
151static int e1000_open(struct net_device *netdev);
152static int e1000_close(struct net_device *netdev);
153static void e1000_configure_tx(struct e1000_adapter *adapter);
154static void e1000_configure_rx(struct e1000_adapter *adapter);
155static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400156static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
157static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
158static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
159 struct e1000_tx_ring *tx_ring);
160static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
161 struct e1000_rx_ring *rx_ring);
Patrick McHardydb0ce502007-11-13 20:54:59 -0800162static void e1000_set_rx_mode(struct net_device *netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static void e1000_update_phy_info(unsigned long data);
164static void e1000_watchdog(unsigned long data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165static void e1000_82547_tx_fifo_stall(unsigned long data);
166static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
167static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
168static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
169static int e1000_set_mac(struct net_device *netdev, void *p);
David Howells7d12e782006-10-05 14:55:46 +0100170static irqreturn_t e1000_intr(int irq, void *data);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800171static irqreturn_t e1000_intr_msi(int irq, void *data);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400172static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
173 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700175static int e1000_clean(struct napi_struct *napi, int budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400177 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700179static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400180 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700181 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400183static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
184 struct e1000_rx_ring *rx_ring);
185static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
186 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400188static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800189 struct e1000_rx_ring *rx_ring,
190 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400191static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800192 struct e1000_rx_ring *rx_ring,
193 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
195static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
196 int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
198static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
199static void e1000_tx_timeout(struct net_device *dev);
David Howells65f27f32006-11-22 14:55:48 +0000200static void e1000_reset_task(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700202static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
203 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
206static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
207static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
208static void e1000_restore_vlan(struct e1000_adapter *adapter);
209
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700210static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Auke Kok6fdfef12006-06-27 09:06:36 -0700211#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212static int e1000_resume(struct pci_dev *pdev);
213#endif
Auke Kokc653e632006-05-23 13:35:57 -0700214static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216#ifdef CONFIG_NET_POLL_CONTROLLER
217/* for netdump / net console */
218static void e1000_netpoll (struct net_device *netdev);
219#endif
220
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100221#define COPYBREAK_DEFAULT 256
222static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
223module_param(copybreak, uint, 0644);
224MODULE_PARM_DESC(copybreak,
225 "Maximum size of packet that is copied to a new buffer on receive");
226
Auke Kok90267292006-06-08 09:30:24 -0700227static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
228 pci_channel_state_t state);
229static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
230static void e1000_io_resume(struct pci_dev *pdev);
231
232static struct pci_error_handlers e1000_err_handler = {
233 .error_detected = e1000_io_error_detected,
234 .slot_reset = e1000_io_slot_reset,
235 .resume = e1000_io_resume,
236};
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238static struct pci_driver e1000_driver = {
239 .name = e1000_driver_name,
240 .id_table = e1000_pci_tbl,
241 .probe = e1000_probe,
242 .remove = __devexit_p(e1000_remove),
Auke Kokc4e24f02006-09-27 12:53:19 -0700243#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 /* Power Managment Hooks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 .suspend = e1000_suspend,
Auke Kokc653e632006-05-23 13:35:57 -0700246 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247#endif
Auke Kok90267292006-06-08 09:30:24 -0700248 .shutdown = e1000_shutdown,
249 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250};
251
252MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
253MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
254MODULE_LICENSE("GPL");
255MODULE_VERSION(DRV_VERSION);
256
257static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
258module_param(debug, int, 0);
259MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
260
261/**
262 * e1000_init_module - Driver Registration Routine
263 *
264 * e1000_init_module is the first routine called when the driver is
265 * loaded. All it does is register with the PCI subsystem.
266 **/
267
268static int __init
269e1000_init_module(void)
270{
271 int ret;
272 printk(KERN_INFO "%s - version %s\n",
273 e1000_driver_string, e1000_driver_version);
274
275 printk(KERN_INFO "%s\n", e1000_copyright);
276
Jeff Garzik29917622006-08-19 17:48:59 -0400277 ret = pci_register_driver(&e1000_driver);
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100278 if (copybreak != COPYBREAK_DEFAULT) {
279 if (copybreak == 0)
280 printk(KERN_INFO "e1000: copybreak disabled\n");
281 else
282 printk(KERN_INFO "e1000: copybreak enabled for "
283 "packets <= %u bytes\n", copybreak);
284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 return ret;
286}
287
288module_init(e1000_init_module);
289
290/**
291 * e1000_exit_module - Driver Exit Cleanup Routine
292 *
293 * e1000_exit_module is called just before the driver is removed
294 * from memory.
295 **/
296
297static void __exit
298e1000_exit_module(void)
299{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 pci_unregister_driver(&e1000_driver);
301}
302
303module_exit(e1000_exit_module);
304
Auke Kok2db10a02006-06-27 09:06:28 -0700305static int e1000_request_irq(struct e1000_adapter *adapter)
306{
307 struct net_device *netdev = adapter->netdev;
Al Viro3e188262007-12-11 19:49:39 +0000308 irq_handler_t handler = e1000_intr;
Auke Koke94bd232007-05-16 01:49:46 -0700309 int irq_flags = IRQF_SHARED;
310 int err;
Auke Kok2db10a02006-06-27 09:06:28 -0700311
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800312 if (adapter->hw.mac_type >= e1000_82571) {
Auke Koke94bd232007-05-16 01:49:46 -0700313 adapter->have_msi = !pci_enable_msi(adapter->pdev);
314 if (adapter->have_msi) {
Al Viro3e188262007-12-11 19:49:39 +0000315 handler = e1000_intr_msi;
Auke Koke94bd232007-05-16 01:49:46 -0700316 irq_flags = 0;
Auke Kok2db10a02006-06-27 09:06:28 -0700317 }
318 }
Auke Koke94bd232007-05-16 01:49:46 -0700319
320 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
321 netdev);
322 if (err) {
323 if (adapter->have_msi)
324 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700325 DPRINTK(PROBE, ERR,
326 "Unable to allocate interrupt Error: %d\n", err);
Auke Koke94bd232007-05-16 01:49:46 -0700327 }
Auke Kok2db10a02006-06-27 09:06:28 -0700328
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
Auke Kok2db10a02006-06-27 09:06:28 -0700338 if (adapter->have_msi)
339 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700340}
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342/**
343 * e1000_irq_disable - Mask off interrupt generation on the NIC
344 * @adapter: board private structure
345 **/
346
Auke Koke619d522006-04-14 19:04:52 -0700347static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348e1000_irq_disable(struct e1000_adapter *adapter)
349{
350 atomic_inc(&adapter->irq_sem);
351 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
352 E1000_WRITE_FLUSH(&adapter->hw);
353 synchronize_irq(adapter->pdev->irq);
354}
355
356/**
357 * e1000_irq_enable - Enable default interrupt generation settings
358 * @adapter: board private structure
359 **/
360
Auke Koke619d522006-04-14 19:04:52 -0700361static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362e1000_irq_enable(struct e1000_adapter *adapter)
363{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800364 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
366 E1000_WRITE_FLUSH(&adapter->hw);
367 }
368}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100369
370static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700371e1000_update_mng_vlan(struct e1000_adapter *adapter)
372{
373 struct net_device *netdev = adapter->netdev;
374 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
375 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800376 if (adapter->vlgrp) {
Dan Aloni5c15bde2007-03-02 20:44:51 -0800377 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800378 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700379 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
380 e1000_vlan_rx_add_vid(netdev, vid);
381 adapter->mng_vlan_id = vid;
382 } else
383 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800384
385 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
386 (vid != old_vid) &&
Dan Aloni5c15bde2007-03-02 20:44:51 -0800387 !vlan_group_get_device(adapter->vlgrp, old_vid))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700388 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800389 } else
390 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700391 }
392}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800393
394/**
395 * e1000_release_hw_control - release control of the h/w to f/w
396 * @adapter: address of board private structure
397 *
398 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
399 * For ASF and Pass Through versions of f/w this means that the
400 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800401 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700402 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800403 **/
404
Auke Koke619d522006-04-14 19:04:52 -0700405static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800406e1000_release_hw_control(struct e1000_adapter *adapter)
407{
408 uint32_t ctrl_ext;
409 uint32_t swsm;
410
411 /* Let firmware taken over control of h/w */
412 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800413 case e1000_82573:
414 swsm = E1000_READ_REG(&adapter->hw, SWSM);
415 E1000_WRITE_REG(&adapter->hw, SWSM,
416 swsm & ~E1000_SWSM_DRV_LOAD);
Bruce Allan31d76442007-03-06 08:57:24 -0800417 break;
418 case e1000_82571:
419 case e1000_82572:
420 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700421 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800422 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
Auke Kokcd94dd02006-06-27 09:08:22 -0700423 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
Bruce Allan31d76442007-03-06 08:57:24 -0800424 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700425 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800426 default:
427 break;
428 }
429}
430
431/**
432 * e1000_get_hw_control - get control of the h/w from f/w
433 * @adapter: address of board private structure
434 *
435 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700436 * For ASF and Pass Through versions of f/w this means that
437 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800438 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700439 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800440 **/
441
Auke Koke619d522006-04-14 19:04:52 -0700442static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800443e1000_get_hw_control(struct e1000_adapter *adapter)
444{
445 uint32_t ctrl_ext;
446 uint32_t swsm;
Auke Kok90fb5132006-11-01 08:47:30 -0800447
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800448 /* Let firmware know the driver has taken over */
449 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800450 case e1000_82573:
451 swsm = E1000_READ_REG(&adapter->hw, SWSM);
452 E1000_WRITE_REG(&adapter->hw, SWSM,
453 swsm | E1000_SWSM_DRV_LOAD);
454 break;
Bruce Allan31d76442007-03-06 08:57:24 -0800455 case e1000_82571:
456 case e1000_82572:
457 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700458 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800459 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
460 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
461 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700462 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800463 default:
464 break;
465 }
466}
467
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500468static void
469e1000_init_manageability(struct e1000_adapter *adapter)
470{
471 if (adapter->en_mng_pt) {
472 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
473
474 /* disable hardware interception of ARP */
475 manc &= ~(E1000_MANC_ARP_EN);
476
477 /* enable receiving management packets to the host */
478 /* this will probably generate destination unreachable messages
479 * from the host OS, but the packets will be handled on SMBUS */
480 if (adapter->hw.has_manc2h) {
481 uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
482
483 manc |= E1000_MANC_EN_MNG2HOST;
484#define E1000_MNG2HOST_PORT_623 (1 << 5)
485#define E1000_MNG2HOST_PORT_664 (1 << 6)
486 manc2h |= E1000_MNG2HOST_PORT_623;
487 manc2h |= E1000_MNG2HOST_PORT_664;
488 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
489 }
490
491 E1000_WRITE_REG(&adapter->hw, MANC, manc);
492 }
493}
494
495static void
496e1000_release_manageability(struct e1000_adapter *adapter)
497{
498 if (adapter->en_mng_pt) {
499 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
500
501 /* re-enable hardware interception of ARP */
502 manc |= E1000_MANC_ARP_EN;
503
504 if (adapter->hw.has_manc2h)
505 manc &= ~E1000_MANC_EN_MNG2HOST;
506
507 /* don't explicitly have to mess with MANC2H since
508 * MANC has an enable disable that gates MANC2H */
509
510 E1000_WRITE_REG(&adapter->hw, MANC, manc);
511 }
512}
513
Auke Koke0aac5a2007-03-06 08:57:21 -0800514/**
515 * e1000_configure - configure the hardware for RX and TX
516 * @adapter = private board structure
517 **/
518static void e1000_configure(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
520 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700521 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Patrick McHardydb0ce502007-11-13 20:54:59 -0800523 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 e1000_restore_vlan(adapter);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500526 e1000_init_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 e1000_configure_tx(adapter);
529 e1000_setup_rctl(adapter);
530 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800531 /* call E1000_DESC_UNUSED which always leaves
532 * at least 1 descriptor unused to make sure
533 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800534 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800535 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800536 adapter->alloc_rx_buf(adapter, ring,
537 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800540 adapter->tx_queue_len = netdev->tx_queue_len;
Auke Koke0aac5a2007-03-06 08:57:21 -0800541}
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800542
Auke Koke0aac5a2007-03-06 08:57:21 -0800543int e1000_up(struct e1000_adapter *adapter)
544{
545 /* hardware has been reset, we need to reload some things */
546 e1000_configure(adapter);
Malli Chilakala5de55622005-04-28 19:39:30 -0700547
Auke Kok1314bbf2006-09-27 12:54:02 -0700548 clear_bit(__E1000_DOWN, &adapter->flags);
549
Auke Koke0aac5a2007-03-06 08:57:21 -0800550#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700551 napi_enable(&adapter->napi);
Auke Koke0aac5a2007-03-06 08:57:21 -0800552#endif
553 e1000_irq_enable(adapter);
554
Jesse Brandeburg79f3d392006-12-15 10:42:34 +0100555 /* fire a link change interrupt to start the watchdog */
556 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 return 0;
558}
559
Auke Kok79f05bf2006-06-27 09:06:32 -0700560/**
561 * e1000_power_up_phy - restore link in case the phy was powered down
562 * @adapter: address of board private structure
563 *
564 * The phy may be powered down to save power and turn off link when the
565 * driver is unloaded and wake on lan is not enabled (among others)
566 * *** this routine MUST be followed by a call to e1000_reset ***
567 *
568 **/
569
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700570void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700571{
572 uint16_t mii_reg = 0;
573
574 /* Just clear the power down bit to wake the phy back up */
575 if (adapter->hw.media_type == e1000_media_type_copper) {
576 /* according to the manual, the phy will retain its
577 * settings across a power-down/up cycle */
578 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
579 mii_reg &= ~MII_CR_POWER_DOWN;
580 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
581 }
582}
583
584static void e1000_power_down_phy(struct e1000_adapter *adapter)
585{
Bruce Allan61c25052006-09-27 12:53:54 -0700586 /* Power down the PHY so no link is implied when interface is down *
587 * The PHY cannot be powered down if any of the following is TRUE *
Auke Kok79f05bf2006-06-27 09:06:32 -0700588 * (a) WoL is enabled
589 * (b) AMT is active
590 * (c) SoL/IDER session is active */
591 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700592 adapter->hw.media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700593 uint16_t mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700594
595 switch (adapter->hw.mac_type) {
596 case e1000_82540:
597 case e1000_82545:
598 case e1000_82545_rev_3:
599 case e1000_82546:
600 case e1000_82546_rev_3:
601 case e1000_82541:
602 case e1000_82541_rev_2:
603 case e1000_82547:
604 case e1000_82547_rev_2:
605 if (E1000_READ_REG(&adapter->hw, MANC) &
606 E1000_MANC_SMBUS_EN)
607 goto out;
608 break;
609 case e1000_82571:
610 case e1000_82572:
611 case e1000_82573:
612 case e1000_80003es2lan:
613 case e1000_ich8lan:
614 if (e1000_check_mng_mode(&adapter->hw) ||
615 e1000_check_phy_reset_block(&adapter->hw))
616 goto out;
617 break;
618 default:
619 goto out;
620 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700621 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
622 mii_reg |= MII_CR_POWER_DOWN;
623 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
624 mdelay(1);
625 }
Bruce Allan61c25052006-09-27 12:53:54 -0700626out:
627 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700628}
629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630void
631e1000_down(struct e1000_adapter *adapter)
632{
633 struct net_device *netdev = adapter->netdev;
634
Auke Kok1314bbf2006-09-27 12:54:02 -0700635 /* signal that we're down so the interrupt handler does not
636 * reschedule our watchdog timer */
637 set_bit(__E1000_DOWN, &adapter->flags);
638
Auke Koke0aac5a2007-03-06 08:57:21 -0800639#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700640 napi_disable(&adapter->napi);
David S. Miller49d85c52008-01-18 04:21:39 -0800641 atomic_set(&adapter->irq_sem, 0);
Auke Koke0aac5a2007-03-06 08:57:21 -0800642#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 del_timer_sync(&adapter->tx_fifo_stall_timer);
646 del_timer_sync(&adapter->watchdog_timer);
647 del_timer_sync(&adapter->phy_info_timer);
648
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800649 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 adapter->link_speed = 0;
651 adapter->link_duplex = 0;
652 netif_carrier_off(netdev);
653 netif_stop_queue(netdev);
654
655 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400656 e1000_clean_all_tx_rings(adapter);
657 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660void
Auke Kok2db10a02006-06-27 09:06:28 -0700661e1000_reinit_locked(struct e1000_adapter *adapter)
662{
663 WARN_ON(in_interrupt());
664 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
665 msleep(1);
666 e1000_down(adapter);
667 e1000_up(adapter);
668 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
670
671void
672e1000_reset(struct e1000_adapter *adapter)
673{
Bruce Allan018ea442006-12-15 10:39:45 +0100674 uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700675 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Bruce Allan018ea442006-12-15 10:39:45 +0100676 boolean_t legacy_pba_adjust = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 /* Repartition Pba for greater than 9k mtu
679 * To take effect CTRL.RST is required.
680 */
681
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700682 switch (adapter->hw.mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100683 case e1000_82542_rev2_0:
684 case e1000_82542_rev2_1:
685 case e1000_82543:
686 case e1000_82544:
687 case e1000_82540:
688 case e1000_82541:
689 case e1000_82541_rev_2:
690 legacy_pba_adjust = TRUE;
691 pba = E1000_PBA_48K;
692 break;
693 case e1000_82545:
694 case e1000_82545_rev_3:
695 case e1000_82546:
696 case e1000_82546_rev_3:
697 pba = E1000_PBA_48K;
698 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700699 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700700 case e1000_82547_rev_2:
Bruce Allan018ea442006-12-15 10:39:45 +0100701 legacy_pba_adjust = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700702 pba = E1000_PBA_30K;
703 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400704 case e1000_82571:
705 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800706 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400707 pba = E1000_PBA_38K;
708 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700709 case e1000_82573:
Bruce Allan018ea442006-12-15 10:39:45 +0100710 pba = E1000_PBA_20K;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700711 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700712 case e1000_ich8lan:
713 pba = E1000_PBA_8K;
Bruce Allan018ea442006-12-15 10:39:45 +0100714 case e1000_undefined:
715 case e1000_num_macs:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700716 break;
717 }
718
Bruce Allan018ea442006-12-15 10:39:45 +0100719 if (legacy_pba_adjust == TRUE) {
720 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
721 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700722
Bruce Allan018ea442006-12-15 10:39:45 +0100723 if (adapter->hw.mac_type == e1000_82547) {
724 adapter->tx_fifo_head = 0;
725 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
726 adapter->tx_fifo_size =
727 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
728 atomic_set(&adapter->tx_fifo_stall, 0);
729 }
730 } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
731 /* adjust PBA for jumbo frames */
732 E1000_WRITE_REG(&adapter->hw, PBA, pba);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700733
Bruce Allan018ea442006-12-15 10:39:45 +0100734 /* To maintain wire speed transmits, the Tx FIFO should be
735 * large enough to accomodate two full transmit packets,
736 * rounded up to the next 1KB and expressed in KB. Likewise,
737 * the Rx FIFO should be large enough to accomodate at least
738 * one full receive packet and is similarly rounded up and
739 * expressed in KB. */
740 pba = E1000_READ_REG(&adapter->hw, PBA);
741 /* upper 16 bits has Tx packet buffer allocation size in KB */
742 tx_space = pba >> 16;
743 /* lower 16 bits has Rx packet buffer allocation size in KB */
744 pba &= 0xffff;
745 /* don't include ethernet FCS because hardware appends/strips */
746 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
747 VLAN_TAG_SIZE;
748 min_tx_space = min_rx_space;
749 min_tx_space *= 2;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700750 min_tx_space = ALIGN(min_tx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100751 min_tx_space >>= 10;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700752 min_rx_space = ALIGN(min_rx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100753 min_rx_space >>= 10;
754
755 /* If current Tx allocation is less than the min Tx FIFO size,
756 * and the min Tx FIFO size is less than the current Rx FIFO
757 * allocation, take space away from current Rx allocation */
758 if (tx_space < min_tx_space &&
759 ((min_tx_space - tx_space) < pba)) {
760 pba = pba - (min_tx_space - tx_space);
761
762 /* PCI/PCIx hardware has PBA alignment constraints */
763 switch (adapter->hw.mac_type) {
764 case e1000_82545 ... e1000_82546_rev_3:
765 pba &= ~(E1000_PBA_8K - 1);
766 break;
767 default:
768 break;
769 }
770
771 /* if short on rx space, rx wins and must trump tx
772 * adjustment or use Early Receive if available */
773 if (pba < min_rx_space) {
774 switch (adapter->hw.mac_type) {
775 case e1000_82573:
776 /* ERT enabled in e1000_configure_rx */
777 break;
778 default:
779 pba = min_rx_space;
780 break;
781 }
782 }
783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 E1000_WRITE_REG(&adapter->hw, PBA, pba);
787
788 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800789 /* Set the FC high water mark to 90% of the FIFO size.
790 * Required to clear last 3 LSB */
791 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700792 /* We can't use 90% on small FIFOs because the remainder
793 * would be less than 1 full frame. In this case, we size
794 * it to allow at least a full frame above the high water
795 * mark. */
796 if (pba < E1000_PBA_16K)
797 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800798
799 adapter->hw.fc_high_water = fc_high_water_mark;
800 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800801 if (adapter->hw.mac_type == e1000_80003es2lan)
802 adapter->hw.fc_pause_time = 0xFFFF;
803 else
804 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 adapter->hw.fc_send_xon = 1;
806 adapter->hw.fc = adapter->hw.original_fc;
807
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700808 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800810 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700812
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800813 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700815 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100816
817 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
818 if (adapter->hw.mac_type >= e1000_82544 &&
819 adapter->hw.mac_type <= e1000_82547_rev_2 &&
820 adapter->hw.autoneg == 1 &&
821 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
822 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
823 /* clear phy power management bit if we are in gig only mode,
824 * which if enabled will attempt negotiation to 100Mb, which
825 * can cause a loss of link at power off or driver unload */
826 ctrl &= ~E1000_CTRL_SWDPIN3;
827 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
828 }
829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
831 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
832
833 e1000_reset_adaptive(&adapter->hw);
834 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700835
836 if (!adapter->smart_power_down &&
837 (adapter->hw.mac_type == e1000_82571 ||
838 adapter->hw.mac_type == e1000_82572)) {
839 uint16_t phy_data = 0;
840 /* speed up time to link by disabling smart power down, ignore
841 * the return value of this function because there is nothing
842 * different we would do if it failed */
843 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
844 &phy_data);
845 phy_data &= ~IGP02E1000_PM_SPD;
846 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
847 phy_data);
848 }
849
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500850 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851}
852
853/**
Auke Kok67b3c272007-12-17 13:50:23 -0800854 * Dump the eeprom for users having checksum issues
855 **/
Adrian Bunkb4ea8952008-02-01 08:21:28 -0800856static void e1000_dump_eeprom(struct e1000_adapter *adapter)
Auke Kok67b3c272007-12-17 13:50:23 -0800857{
858 struct net_device *netdev = adapter->netdev;
859 struct ethtool_eeprom eeprom;
860 const struct ethtool_ops *ops = netdev->ethtool_ops;
861 u8 *data;
862 int i;
863 u16 csum_old, csum_new = 0;
864
865 eeprom.len = ops->get_eeprom_len(netdev);
866 eeprom.offset = 0;
867
868 data = kmalloc(eeprom.len, GFP_KERNEL);
869 if (!data) {
870 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
871 " data\n");
872 return;
873 }
874
875 ops->get_eeprom(netdev, &eeprom, data);
876
877 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
878 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
879 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
880 csum_new += data[i] + (data[i + 1] << 8);
881 csum_new = EEPROM_SUM - csum_new;
882
883 printk(KERN_ERR "/*********************/\n");
884 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
885 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
886
887 printk(KERN_ERR "Offset Values\n");
888 printk(KERN_ERR "======== ======\n");
889 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
890
891 printk(KERN_ERR "Include this output when contacting your support "
892 "provider.\n");
893 printk(KERN_ERR "This is not a software error! Something bad "
894 "happened to your hardware or\n");
895 printk(KERN_ERR "EEPROM image. Ignoring this "
896 "problem could result in further problems,\n");
897 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
898 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
899 "which is invalid\n");
900 printk(KERN_ERR "and requires you to set the proper MAC "
901 "address manually before continuing\n");
902 printk(KERN_ERR "to enable this network device.\n");
903 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
904 "to your hardware vendor\n");
905 printk(KERN_ERR "or Intel Customer Support: linux-nics@intel.com\n");
906 printk(KERN_ERR "/*********************/\n");
907
908 kfree(data);
909}
910
911/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 * e1000_probe - Device Initialization Routine
913 * @pdev: PCI device information struct
914 * @ent: entry in e1000_pci_tbl
915 *
916 * Returns 0 on success, negative on failure
917 *
918 * e1000_probe initializes an adapter identified by a pci_dev structure.
919 * The OS initialization, configuring of the adapter private structure,
920 * and a hardware reset occur.
921 **/
922
923static int __devinit
924e1000_probe(struct pci_dev *pdev,
925 const struct pci_device_id *ent)
926{
927 struct net_device *netdev;
928 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700931 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700932 int i, err, pci_using_dac;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700933 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Joe Perches0795af52007-10-03 17:59:30 -0700935 DECLARE_MAC_BUF(mac);
936
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800937 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 return err;
939
Auke Kokcd94dd02006-06-27 09:08:22 -0700940 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
941 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 pci_using_dac = 1;
943 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700944 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
945 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700947 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 }
949 pci_using_dac = 0;
950 }
951
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800952 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700953 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 pci_set_master(pdev);
956
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700957 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700959 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 SET_NETDEV_DEV(netdev, &pdev->dev);
963
964 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700965 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 adapter->netdev = netdev;
967 adapter->pdev = pdev;
968 adapter->hw.back = adapter;
969 adapter->msg_enable = (1 << debug) - 1;
970
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700971 err = -EIO;
Benjamin Herrenschmidt3c34ac32007-11-16 18:37:38 +1100972 adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
973 pci_resource_len(pdev, BAR_0));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700974 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800977 for (i = BAR_1; i <= BAR_5; i++) {
978 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800980 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 adapter->hw.io_base = pci_resource_start(pdev, i);
982 break;
983 }
984 }
985
986 netdev->open = &e1000_open;
987 netdev->stop = &e1000_close;
988 netdev->hard_start_xmit = &e1000_xmit_frame;
989 netdev->get_stats = &e1000_get_stats;
Patrick McHardydb0ce502007-11-13 20:54:59 -0800990 netdev->set_rx_mode = &e1000_set_rx_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 netdev->set_mac_address = &e1000_set_mac;
992 netdev->change_mtu = &e1000_change_mtu;
993 netdev->do_ioctl = &e1000_ioctl;
994 e1000_set_ethtool_ops(netdev);
995 netdev->tx_timeout = &e1000_tx_timeout;
996 netdev->watchdog_timeo = 5 * HZ;
997#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700998 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999#endif
1000 netdev->vlan_rx_register = e1000_vlan_rx_register;
1001 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
1002 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
1003#ifdef CONFIG_NET_POLL_CONTROLLER
1004 netdev->poll_controller = e1000_netpoll;
1005#endif
Auke Kok0eb5a342006-09-27 12:53:17 -07001006 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 adapter->bd_number = cards_found;
1009
1010 /* setup the private structure */
1011
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001012 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 goto err_sw_init;
1014
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001015 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -07001016 /* Flash BAR mapping must happen after e1000_sw_init
1017 * because it depends on mac_type */
1018 if ((adapter->hw.mac_type == e1000_ich8lan) &&
1019 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
Benjamin Herrenschmidt3c34ac32007-11-16 18:37:38 +11001020 adapter->hw.flash_address =
1021 ioremap(pci_resource_start(pdev, 1),
1022 pci_resource_len(pdev, 1));
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001023 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -07001024 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -07001025 }
1026
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001027 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001028 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
1029
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001030 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 netdev->features = NETIF_F_SG |
1032 NETIF_F_HW_CSUM |
1033 NETIF_F_HW_VLAN_TX |
1034 NETIF_F_HW_VLAN_RX |
1035 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -07001036 if (adapter->hw.mac_type == e1000_ich8lan)
1037 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 }
1039
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001040 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 (adapter->hw.mac_type != e1000_82547))
1042 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001043
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001044 if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -08001045 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001046 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 netdev->features |= NETIF_F_HIGHDMA;
1048
Auke Kok76c224b2006-05-23 13:36:06 -07001049 netdev->features |= NETIF_F_LLTX;
1050
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001051 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
1052
Auke Kokcd94dd02006-06-27 09:08:22 -07001053 /* initialize eeprom parameters */
Auke Kokcd94dd02006-06-27 09:08:22 -07001054 if (e1000_init_eeprom_params(&adapter->hw)) {
1055 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001056 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001057 }
1058
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001059 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 e1000_reset_hw(&adapter->hw);
1063
1064 /* make sure the EEPROM is good */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001065 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Auke Kok67b3c272007-12-17 13:50:23 -08001067 e1000_dump_eeprom(adapter);
1068 /*
1069 * set MAC address to all zeroes to invalidate and temporary
1070 * disable this device for the user. This blocks regular
1071 * traffic while still permitting ethtool ioctls from reaching
1072 * the hardware as well as allowing the user to run the
1073 * interface after manually setting a hw addr using
1074 * `ip set address`
1075 */
1076 memset(adapter->hw.mac_addr, 0, netdev->addr_len);
1077 } else {
1078 /* copy the MAC address out of the EEPROM */
1079 if (e1000_read_mac_addr(&adapter->hw))
1080 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 }
Auke Kok67b3c272007-12-17 13:50:23 -08001082 /* don't block initalization here due to bad MAC address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -04001084 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Auke Kok67b3c272007-12-17 13:50:23 -08001086 if (!is_valid_ether_addr(netdev->perm_addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 e1000_get_bus_info(&adapter->hw);
1090
1091 init_timer(&adapter->tx_fifo_stall_timer);
1092 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1093 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
1094
1095 init_timer(&adapter->watchdog_timer);
1096 adapter->watchdog_timer.function = &e1000_watchdog;
1097 adapter->watchdog_timer.data = (unsigned long) adapter;
1098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 init_timer(&adapter->phy_info_timer);
1100 adapter->phy_info_timer.function = &e1000_update_phy_info;
1101 adapter->phy_info_timer.data = (unsigned long) adapter;
1102
David Howells65f27f32006-11-22 14:55:48 +00001103 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 e1000_check_options(adapter);
1106
1107 /* Initial Wake on LAN setting
1108 * If APM wake is enabled in the EEPROM,
1109 * enable the ACPI Magic Packet filter
1110 */
1111
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001112 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 case e1000_82542_rev2_0:
1114 case e1000_82542_rev2_1:
1115 case e1000_82543:
1116 break;
1117 case e1000_82544:
1118 e1000_read_eeprom(&adapter->hw,
1119 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1120 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1121 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001122 case e1000_ich8lan:
1123 e1000_read_eeprom(&adapter->hw,
1124 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1125 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1126 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 case e1000_82546:
1128 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001129 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001130 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001131 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 e1000_read_eeprom(&adapter->hw,
1133 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1134 break;
1135 }
1136 /* Fall Through */
1137 default:
1138 e1000_read_eeprom(&adapter->hw,
1139 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1140 break;
1141 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001142 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001143 adapter->eeprom_wol |= E1000_WUFC_MAG;
1144
1145 /* now that we have the eeprom settings, apply the special cases
1146 * where the eeprom may be wrong or the board simply won't support
1147 * wake on lan on a particular port */
1148 switch (pdev->device) {
1149 case E1000_DEV_ID_82546GB_PCIE:
1150 adapter->eeprom_wol = 0;
1151 break;
1152 case E1000_DEV_ID_82546EB_FIBER:
1153 case E1000_DEV_ID_82546GB_FIBER:
1154 case E1000_DEV_ID_82571EB_FIBER:
1155 /* Wake events only supported on port A for dual fiber
1156 * regardless of eeprom setting */
1157 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
1158 adapter->eeprom_wol = 0;
1159 break;
1160 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001161 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001162 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001163 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001164 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001165 /* if quad port adapter, disable WoL on all but port A */
1166 if (global_quad_port_a != 0)
1167 adapter->eeprom_wol = 0;
1168 else
1169 adapter->quad_port_a = 1;
1170 /* Reset for multiple quad port adapters */
1171 if (++global_quad_port_a == 4)
1172 global_quad_port_a = 0;
1173 break;
1174 }
1175
1176 /* initialize the wol settings based on the eeprom settings */
1177 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001179 /* print bus type/speed/width info */
1180 {
1181 struct e1000_hw *hw = &adapter->hw;
1182 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1183 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1184 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1185 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1186 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1187 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1188 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1189 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1190 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1191 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1192 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1193 "32-bit"));
1194 }
1195
Joe Perches0795af52007-10-03 17:59:30 -07001196 printk("%s\n", print_mac(mac, netdev->dev_addr));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 /* reset the hardware with the new settings */
1199 e1000_reset(adapter);
1200
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001201 /* If the controller is 82573 and f/w is AMT, do not set
1202 * DRV_LOAD until the interface is up. For all other cases,
1203 * let the f/w know that the h/w is now under the control
1204 * of the driver. */
1205 if (adapter->hw.mac_type != e1000_82573 ||
1206 !e1000_check_mng_mode(&adapter->hw))
1207 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001208
Auke Kok1314bbf2006-09-27 12:54:02 -07001209 /* tell the stack to leave us alone until e1000_open() is called */
1210 netif_carrier_off(netdev);
1211 netif_stop_queue(netdev);
Auke Kok416b5d12007-06-01 10:22:39 -07001212
1213 strcpy(netdev->name, "eth%d");
1214 if ((err = register_netdev(netdev)))
1215 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001216
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1218
1219 cards_found++;
1220 return 0;
1221
1222err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001223 e1000_release_hw_control(adapter);
1224err_eeprom:
1225 if (!e1000_check_phy_reset_block(&adapter->hw))
1226 e1000_phy_hw_reset(&adapter->hw);
1227
Auke Kokcd94dd02006-06-27 09:08:22 -07001228 if (adapter->hw.flash_address)
1229 iounmap(adapter->hw.flash_address);
1230err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001231#ifdef CONFIG_E1000_NAPI
1232 for (i = 0; i < adapter->num_rx_queues; i++)
1233 dev_put(&adapter->polling_netdev[i]);
1234#endif
1235
1236 kfree(adapter->tx_ring);
1237 kfree(adapter->rx_ring);
1238#ifdef CONFIG_E1000_NAPI
1239 kfree(adapter->polling_netdev);
1240#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 iounmap(adapter->hw.hw_addr);
1243err_ioremap:
1244 free_netdev(netdev);
1245err_alloc_etherdev:
1246 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001247err_pci_reg:
1248err_dma:
1249 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 return err;
1251}
1252
1253/**
1254 * e1000_remove - Device Removal Routine
1255 * @pdev: PCI device information struct
1256 *
1257 * e1000_remove is called by the PCI subsystem to alert the driver
1258 * that it should release a PCI device. The could be caused by a
1259 * Hot-Plug event, or because the driver is going to be removed from
1260 * memory.
1261 **/
1262
1263static void __devexit
1264e1000_remove(struct pci_dev *pdev)
1265{
1266 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001267 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001268#ifdef CONFIG_E1000_NAPI
1269 int i;
1270#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Oleg Nesterov28e53bd2007-05-09 02:34:22 -07001272 cancel_work_sync(&adapter->reset_task);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001273
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001274 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001276 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1277 * would have already happened in close and is redundant. */
1278 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001279
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001280#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001281 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001282 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001283#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001285 unregister_netdev(netdev);
1286
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001287 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001288 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001290 kfree(adapter->tx_ring);
1291 kfree(adapter->rx_ring);
1292#ifdef CONFIG_E1000_NAPI
1293 kfree(adapter->polling_netdev);
1294#endif
1295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001297 if (adapter->hw.flash_address)
1298 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 pci_release_regions(pdev);
1300
1301 free_netdev(netdev);
1302
1303 pci_disable_device(pdev);
1304}
1305
1306/**
1307 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1308 * @adapter: board private structure to initialize
1309 *
1310 * e1000_sw_init initializes the Adapter private data structure.
1311 * Fields are initialized based on PCI device information and
1312 * OS network device settings (MTU size).
1313 **/
1314
1315static int __devinit
1316e1000_sw_init(struct e1000_adapter *adapter)
1317{
1318 struct e1000_hw *hw = &adapter->hw;
1319 struct net_device *netdev = adapter->netdev;
1320 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001321#ifdef CONFIG_E1000_NAPI
1322 int i;
1323#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 /* PCI config space info */
1326
1327 hw->vendor_id = pdev->vendor;
1328 hw->device_id = pdev->device;
1329 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1330 hw->subsystem_id = pdev->subsystem_device;
Auke Kok44c10132007-06-08 15:46:36 -07001331 hw->revision_id = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1334
Auke Kokeb0f8052006-07-14 16:14:48 -07001335 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001336 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 hw->max_frame_size = netdev->mtu +
1338 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1339 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1340
1341 /* identify the MAC */
1342
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001343 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1345 return -EIO;
1346 }
1347
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001348 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 default:
1350 break;
1351 case e1000_82541:
1352 case e1000_82547:
1353 case e1000_82541_rev_2:
1354 case e1000_82547_rev_2:
1355 hw->phy_init_script = 1;
1356 break;
1357 }
1358
1359 e1000_set_media_type(hw);
1360
1361 hw->wait_autoneg_complete = FALSE;
1362 hw->tbi_compatibility_en = TRUE;
1363 hw->adaptive_ifs = TRUE;
1364
1365 /* Copper options */
1366
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001367 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 hw->mdix = AUTO_ALL_MODES;
1369 hw->disable_polarity_correction = FALSE;
1370 hw->master_slave = E1000_MASTER_SLAVE;
1371 }
1372
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001373 adapter->num_tx_queues = 1;
1374 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001375
1376 if (e1000_alloc_queues(adapter)) {
1377 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1378 return -ENOMEM;
1379 }
1380
1381#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001382 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001383 adapter->polling_netdev[i].priv = adapter;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001384 dev_hold(&adapter->polling_netdev[i]);
1385 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1386 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001387 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001388#endif
1389
Herbert Xu47313052007-05-29 15:07:31 -07001390 /* Explicitly disable IRQ since the NIC can be in any state. */
1391 atomic_set(&adapter->irq_sem, 0);
1392 e1000_irq_disable(adapter);
1393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Auke Kok1314bbf2006-09-27 12:54:02 -07001396 set_bit(__E1000_DOWN, &adapter->flags);
1397
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 return 0;
1399}
1400
1401/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001402 * e1000_alloc_queues - Allocate memory for all rings
1403 * @adapter: board private structure to initialize
1404 *
1405 * We allocate one ring per queue at run-time since we don't know the
1406 * number of queues at compile-time. The polling_netdev array is
1407 * intended for Multiqueue, but should work fine with a single queue.
1408 **/
1409
1410static int __devinit
1411e1000_alloc_queues(struct e1000_adapter *adapter)
1412{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001413 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1414 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001415 if (!adapter->tx_ring)
1416 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001417
Yan Burman1c7e5b12007-03-06 08:58:04 -08001418 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1419 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001420 if (!adapter->rx_ring) {
1421 kfree(adapter->tx_ring);
1422 return -ENOMEM;
1423 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001424
1425#ifdef CONFIG_E1000_NAPI
Yan Burman1c7e5b12007-03-06 08:58:04 -08001426 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1427 sizeof(struct net_device),
1428 GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001429 if (!adapter->polling_netdev) {
1430 kfree(adapter->tx_ring);
1431 kfree(adapter->rx_ring);
1432 return -ENOMEM;
1433 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001434#endif
1435
1436 return E1000_SUCCESS;
1437}
1438
1439/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 * e1000_open - Called when a network interface is made active
1441 * @netdev: network interface device structure
1442 *
1443 * Returns 0 on success, negative value on failure
1444 *
1445 * The open entry point is called when a network interface is made
1446 * active by the system (IFF_UP). At this point all resources needed
1447 * for transmit and receive operations are allocated, the interrupt
1448 * handler is registered with the OS, the watchdog timer is started,
1449 * and the stack is notified that the interface is ready.
1450 **/
1451
1452static int
1453e1000_open(struct net_device *netdev)
1454{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001455 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 int err;
1457
Auke Kok2db10a02006-06-27 09:06:28 -07001458 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001459 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001460 return -EBUSY;
1461
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001463 err = e1000_setup_all_tx_resources(adapter);
1464 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 goto err_setup_tx;
1466
1467 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001468 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001469 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001470 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001471
Auke Kok79f05bf2006-06-27 09:06:32 -07001472 e1000_power_up_phy(adapter);
1473
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001474 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001475 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001476 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1477 e1000_update_mng_vlan(adapter);
1478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001480 /* If AMT is enabled, let the firmware know that the network
1481 * interface is now open */
1482 if (adapter->hw.mac_type == e1000_82573 &&
1483 e1000_check_mng_mode(&adapter->hw))
1484 e1000_get_hw_control(adapter);
1485
Auke Koke0aac5a2007-03-06 08:57:21 -08001486 /* before we allocate an interrupt, we must be ready to handle it.
1487 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1488 * as soon as we call pci_request_irq, so we have to setup our
1489 * clean_rx handler before we do so. */
1490 e1000_configure(adapter);
1491
1492 err = e1000_request_irq(adapter);
1493 if (err)
1494 goto err_req_irq;
1495
1496 /* From here on the code is the same as e1000_up() */
1497 clear_bit(__E1000_DOWN, &adapter->flags);
1498
Herbert Xu47313052007-05-29 15:07:31 -07001499#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001500 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001501#endif
1502
Auke Koke0aac5a2007-03-06 08:57:21 -08001503 e1000_irq_enable(adapter);
1504
1505 /* fire a link status change interrupt to start the watchdog */
1506 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
1507
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 return E1000_SUCCESS;
1509
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001510err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001511 e1000_release_hw_control(adapter);
1512 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001513 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001515 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516err_setup_tx:
1517 e1000_reset(adapter);
1518
1519 return err;
1520}
1521
1522/**
1523 * e1000_close - Disables a network interface
1524 * @netdev: network interface device structure
1525 *
1526 * Returns 0, this is not allowed to fail
1527 *
1528 * The close entry point is called when an interface is de-activated
1529 * by the OS. The hardware is still under the drivers control, but
1530 * needs to be disabled. A global MAC reset is issued to stop the
1531 * hardware, and all transmit and receive resources are freed.
1532 **/
1533
1534static int
1535e1000_close(struct net_device *netdev)
1536{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001537 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Auke Kok2db10a02006-06-27 09:06:28 -07001539 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001541 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001542 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001544 e1000_free_all_tx_resources(adapter);
1545 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Bruce Allan46665602006-09-27 12:54:08 -07001547 /* kill manageability vlan ID if supported, but not if a vlan with
1548 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001549 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001550 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1551 !(adapter->vlgrp &&
Dan Aloni5c15bde2007-03-02 20:44:51 -08001552 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001553 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1554 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001555
1556 /* If AMT is enabled, let the firmware know that the network
1557 * interface is now closed */
1558 if (adapter->hw.mac_type == e1000_82573 &&
1559 e1000_check_mng_mode(&adapter->hw))
1560 e1000_release_hw_control(adapter);
1561
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 return 0;
1563}
1564
1565/**
1566 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1567 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001568 * @start: address of beginning of memory
1569 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 **/
Auke Koke619d522006-04-14 19:04:52 -07001571static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572e1000_check_64k_bound(struct e1000_adapter *adapter,
1573 void *start, unsigned long len)
1574{
1575 unsigned long begin = (unsigned long) start;
1576 unsigned long end = begin + len;
1577
Malli Chilakala26483452005-04-28 19:44:46 -07001578 /* First rev 82545 and 82546 need to not allow any memory
1579 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001581 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1583 }
1584
1585 return TRUE;
1586}
1587
1588/**
1589 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1590 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001591 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 *
1593 * Return 0 on success, negative on failure
1594 **/
1595
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001596static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001597e1000_setup_tx_resources(struct e1000_adapter *adapter,
1598 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 struct pci_dev *pdev = adapter->pdev;
1601 int size;
1602
1603 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001604 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001605 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001606 DPRINTK(PROBE, ERR,
1607 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 return -ENOMEM;
1609 }
1610 memset(txdr->buffer_info, 0, size);
1611
1612 /* round up to nearest 4K */
1613
1614 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001615 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
1617 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001618 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001621 DPRINTK(PROBE, ERR,
1622 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 return -ENOMEM;
1624 }
1625
Malli Chilakala26483452005-04-28 19:44:46 -07001626 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1628 void *olddesc = txdr->desc;
1629 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001630 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1631 "at %p\n", txdr->size, txdr->desc);
1632 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001634 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001635 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1637 goto setup_tx_desc_die;
1638 }
1639
1640 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1641 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001642 pci_free_consistent(pdev, txdr->size, txdr->desc,
1643 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1645 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001646 "Unable to allocate aligned memory "
1647 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 vfree(txdr->buffer_info);
1649 return -ENOMEM;
1650 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001651 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1653 }
1654 }
1655 memset(txdr->desc, 0, txdr->size);
1656
1657 txdr->next_to_use = 0;
1658 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001659 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661 return 0;
1662}
1663
1664/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001665 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1666 * (Descriptors) for all queues
1667 * @adapter: board private structure
1668 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001669 * Return 0 on success, negative on failure
1670 **/
1671
1672int
1673e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1674{
1675 int i, err = 0;
1676
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001677 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001678 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1679 if (err) {
1680 DPRINTK(PROBE, ERR,
1681 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001682 for (i-- ; i >= 0; i--)
1683 e1000_free_tx_resources(adapter,
1684 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001685 break;
1686 }
1687 }
1688
1689 return err;
1690}
1691
1692/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1694 * @adapter: board private structure
1695 *
1696 * Configure the Tx unit of the MAC after a reset.
1697 **/
1698
1699static void
1700e1000_configure_tx(struct e1000_adapter *adapter)
1701{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001702 uint64_t tdba;
1703 struct e1000_hw *hw = &adapter->hw;
1704 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001705 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
1707 /* Setup the HW Tx Head and Tail descriptor pointers */
1708
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001709 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001710 case 1:
1711 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001712 tdba = adapter->tx_ring[0].dma;
1713 tdlen = adapter->tx_ring[0].count *
1714 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001715 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001716 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1717 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001718 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001719 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001720 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1721 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001722 break;
1723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 /* Set the default values for the Tx Inter Packet Gap timer */
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001726 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1727 (hw->media_type == e1000_media_type_fiber ||
1728 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001729 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1730 else
1731 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1732
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001733 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 case e1000_82542_rev2_0:
1735 case e1000_82542_rev2_1:
1736 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001737 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1738 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001740 case e1000_80003es2lan:
1741 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1742 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1743 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001745 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1746 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1747 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001749 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1750 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001751 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 /* Set the Tx Interrupt Delay register */
1754
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001755 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1756 if (hw->mac_type >= e1000_82540)
1757 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
1759 /* Program the Transmit Control Register */
1760
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001761 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001763 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1765
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001766 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1767 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001768 /* set the speed mode bit, we'll clear it if we're not at
1769 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001770 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001771 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001772 } else if (hw->mac_type == e1000_80003es2lan) {
1773 tarc = E1000_READ_REG(hw, TARC0);
1774 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001775 E1000_WRITE_REG(hw, TARC0, tarc);
1776 tarc = E1000_READ_REG(hw, TARC1);
1777 tarc |= 1;
1778 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001779 }
1780
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001781 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
1783 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001784 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1785
1786 /* only set IDE if we are delaying interrupts using the timers */
1787 if (adapter->tx_int_delay)
1788 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001790 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1792 else
1793 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1794
1795 /* Cache if we're 82544 running in PCI-X because we'll
1796 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001797 if (hw->mac_type == e1000_82544 &&
1798 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001800
1801 E1000_WRITE_REG(hw, TCTL, tctl);
1802
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803}
1804
1805/**
1806 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1807 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001808 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 *
1810 * Returns 0 on success, negative on failure
1811 **/
1812
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001813static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001814e1000_setup_rx_resources(struct e1000_adapter *adapter,
1815 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001818 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
1820 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001821 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001822 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001823 DPRINTK(PROBE, ERR,
1824 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 return -ENOMEM;
1826 }
1827 memset(rxdr->buffer_info, 0, size);
1828
Yan Burman1c7e5b12007-03-06 08:58:04 -08001829 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1830 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001831 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001832 vfree(rxdr->buffer_info);
1833 DPRINTK(PROBE, ERR,
1834 "Unable to allocate memory for the receive descriptor ring\n");
1835 return -ENOMEM;
1836 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001837
Yan Burman1c7e5b12007-03-06 08:58:04 -08001838 rxdr->ps_page_dma = kcalloc(rxdr->count,
1839 sizeof(struct e1000_ps_page_dma),
1840 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001841 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001842 vfree(rxdr->buffer_info);
1843 kfree(rxdr->ps_page);
1844 DPRINTK(PROBE, ERR,
1845 "Unable to allocate memory for the receive descriptor ring\n");
1846 return -ENOMEM;
1847 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001848
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001849 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001850 desc_len = sizeof(struct e1000_rx_desc);
1851 else
1852 desc_len = sizeof(union e1000_rx_desc_packet_split);
1853
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 /* Round up to nearest 4K */
1855
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001856 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001857 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
1859 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1860
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001861 if (!rxdr->desc) {
1862 DPRINTK(PROBE, ERR,
1863 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001866 kfree(rxdr->ps_page);
1867 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 return -ENOMEM;
1869 }
1870
Malli Chilakala26483452005-04-28 19:44:46 -07001871 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1873 void *olddesc = rxdr->desc;
1874 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001875 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1876 "at %p\n", rxdr->size, rxdr->desc);
1877 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001879 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001880 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001882 DPRINTK(PROBE, ERR,
1883 "Unable to allocate memory "
1884 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 goto setup_rx_desc_die;
1886 }
1887
1888 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1889 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001890 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1891 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001893 DPRINTK(PROBE, ERR,
1894 "Unable to allocate aligned memory "
1895 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001896 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001898 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1900 }
1901 }
1902 memset(rxdr->desc, 0, rxdr->size);
1903
1904 rxdr->next_to_clean = 0;
1905 rxdr->next_to_use = 0;
1906
1907 return 0;
1908}
1909
1910/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001911 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1912 * (Descriptors) for all queues
1913 * @adapter: board private structure
1914 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001915 * Return 0 on success, negative on failure
1916 **/
1917
1918int
1919e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1920{
1921 int i, err = 0;
1922
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001923 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001924 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1925 if (err) {
1926 DPRINTK(PROBE, ERR,
1927 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001928 for (i-- ; i >= 0; i--)
1929 e1000_free_rx_resources(adapter,
1930 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001931 break;
1932 }
1933 }
1934
1935 return err;
1936}
1937
1938/**
Malli Chilakala26483452005-04-28 19:44:46 -07001939 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 * @adapter: Board private structure
1941 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001942#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1943 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944static void
1945e1000_setup_rctl(struct e1000_adapter *adapter)
1946{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001947 uint32_t rctl, rfctl;
1948 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001949#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001950 uint32_t pages = 0;
1951#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
1953 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1954
1955 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1956
1957 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1958 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1959 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1960
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001961 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 rctl |= E1000_RCTL_SBP;
1963 else
1964 rctl &= ~E1000_RCTL_SBP;
1965
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001966 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1967 rctl &= ~E1000_RCTL_LPE;
1968 else
1969 rctl |= E1000_RCTL_LPE;
1970
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001972 rctl &= ~E1000_RCTL_SZ_4096;
1973 rctl |= E1000_RCTL_BSEX;
1974 switch (adapter->rx_buffer_len) {
1975 case E1000_RXBUFFER_256:
1976 rctl |= E1000_RCTL_SZ_256;
1977 rctl &= ~E1000_RCTL_BSEX;
1978 break;
1979 case E1000_RXBUFFER_512:
1980 rctl |= E1000_RCTL_SZ_512;
1981 rctl &= ~E1000_RCTL_BSEX;
1982 break;
1983 case E1000_RXBUFFER_1024:
1984 rctl |= E1000_RCTL_SZ_1024;
1985 rctl &= ~E1000_RCTL_BSEX;
1986 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001987 case E1000_RXBUFFER_2048:
1988 default:
1989 rctl |= E1000_RCTL_SZ_2048;
1990 rctl &= ~E1000_RCTL_BSEX;
1991 break;
1992 case E1000_RXBUFFER_4096:
1993 rctl |= E1000_RCTL_SZ_4096;
1994 break;
1995 case E1000_RXBUFFER_8192:
1996 rctl |= E1000_RCTL_SZ_8192;
1997 break;
1998 case E1000_RXBUFFER_16384:
1999 rctl |= E1000_RCTL_SZ_16384;
2000 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002001 }
2002
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08002003#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002004 /* 82571 and greater support packet-split where the protocol
2005 * header is placed in skb->data and the packet data is
2006 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2007 * In the case of a non-split, skb->data is linearly filled,
2008 * followed by the page buffers. Therefore, skb->data is
2009 * sized to hold the largest protocol header.
2010 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07002011 /* allocations using alloc_page take too long for regular MTU
2012 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002013 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07002014 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
2015 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002016 adapter->rx_ps_pages = pages;
2017 else
2018 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002019#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002020 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002021 /* Configure extra packet-split registers */
2022 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
2023 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08002024 /* disable packet split support for IPv6 extension headers,
2025 * because some malformed IPv6 headers can hang the RX */
2026 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2027 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2028
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002029 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
2030
Auke Kok7dfee0c2006-06-27 09:07:50 -07002031 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002032
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002033 psrctl |= adapter->rx_ps_bsize0 >>
2034 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002035
2036 switch (adapter->rx_ps_pages) {
2037 case 3:
2038 psrctl |= PAGE_SIZE <<
2039 E1000_PSRCTL_BSIZE3_SHIFT;
2040 case 2:
2041 psrctl |= PAGE_SIZE <<
2042 E1000_PSRCTL_BSIZE2_SHIFT;
2043 case 1:
2044 psrctl |= PAGE_SIZE >>
2045 E1000_PSRCTL_BSIZE1_SHIFT;
2046 break;
2047 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002048
2049 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 }
2051
2052 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2053}
2054
2055/**
2056 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2057 * @adapter: board private structure
2058 *
2059 * Configure the Rx unit of the MAC after a reset.
2060 **/
2061
2062static void
2063e1000_configure_rx(struct e1000_adapter *adapter)
2064{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002065 uint64_t rdba;
2066 struct e1000_hw *hw = &adapter->hw;
2067 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002068
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002069 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002070 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002071 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002072 sizeof(union e1000_rx_desc_packet_split);
2073 adapter->clean_rx = e1000_clean_rx_irq_ps;
2074 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2075 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002076 rdlen = adapter->rx_ring[0].count *
2077 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002078 adapter->clean_rx = e1000_clean_rx_irq;
2079 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
2082 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002083 rctl = E1000_READ_REG(hw, RCTL);
2084 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002087 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002089 if (hw->mac_type >= e1000_82540) {
2090 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002091 if (adapter->itr_setting != 0)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002092 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 1000000000 / (adapter->itr * 256));
2094 }
2095
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002096 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002097 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002098 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002099 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002100#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002101 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002102 ctrl_ext |= E1000_CTRL_EXT_IAME;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002103 E1000_WRITE_REG(hw, IAM, 0xffffffff);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002104#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002105 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2106 E1000_WRITE_FLUSH(hw);
2107 }
2108
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002109 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2110 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002111 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002112 case 1:
2113 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002114 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002115 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07002116 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
2117 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002118 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002119 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002120 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2121 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002122 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002123 }
2124
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002126 if (hw->mac_type >= e1000_82543) {
2127 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002128 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002129 rxcsum |= E1000_RXCSUM_TUOFL;
2130
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002131 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002132 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002133 if ((hw->mac_type >= e1000_82571) &&
2134 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002135 rxcsum |= E1000_RXCSUM_IPPCSE;
2136 }
2137 } else {
2138 rxcsum &= ~E1000_RXCSUM_TUOFL;
2139 /* don't need to clear IPPCSE as it defaults to 0 */
2140 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002141 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 }
2143
Auke Kok21c4d5e2006-11-01 08:47:39 -08002144 /* enable early receives on 82573, only takes effect if using > 2048
2145 * byte total frame size. for example only for jumbo frames */
2146#define E1000_ERT_2048 0x100
2147 if (hw->mac_type == e1000_82573)
2148 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
2149
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002151 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152}
2153
2154/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002155 * e1000_free_tx_resources - Free Tx Resources per Queue
2156 * @adapter: board private structure
2157 * @tx_ring: Tx descriptor ring for a specific queue
2158 *
2159 * Free all transmit software resources
2160 **/
2161
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002162static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002163e1000_free_tx_resources(struct e1000_adapter *adapter,
2164 struct e1000_tx_ring *tx_ring)
2165{
2166 struct pci_dev *pdev = adapter->pdev;
2167
2168 e1000_clean_tx_ring(adapter, tx_ring);
2169
2170 vfree(tx_ring->buffer_info);
2171 tx_ring->buffer_info = NULL;
2172
2173 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2174
2175 tx_ring->desc = NULL;
2176}
2177
2178/**
2179 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 * @adapter: board private structure
2181 *
2182 * Free all transmit software resources
2183 **/
2184
2185void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002186e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002188 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002190 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002191 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192}
2193
Auke Koke619d522006-04-14 19:04:52 -07002194static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2196 struct e1000_buffer *buffer_info)
2197{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002198 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07002199 pci_unmap_page(adapter->pdev,
2200 buffer_info->dma,
2201 buffer_info->length,
2202 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002203 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002205 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002207 buffer_info->skb = NULL;
2208 }
2209 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210}
2211
2212/**
2213 * e1000_clean_tx_ring - Free Tx Buffers
2214 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002215 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 **/
2217
2218static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002219e1000_clean_tx_ring(struct e1000_adapter *adapter,
2220 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 struct e1000_buffer *buffer_info;
2223 unsigned long size;
2224 unsigned int i;
2225
2226 /* Free all the Tx ring sk_buffs */
2227
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002228 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 buffer_info = &tx_ring->buffer_info[i];
2230 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2231 }
2232
2233 size = sizeof(struct e1000_buffer) * tx_ring->count;
2234 memset(tx_ring->buffer_info, 0, size);
2235
2236 /* Zero out the descriptor ring */
2237
2238 memset(tx_ring->desc, 0, tx_ring->size);
2239
2240 tx_ring->next_to_use = 0;
2241 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002242 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002244 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2245 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2246}
2247
2248/**
2249 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2250 * @adapter: board private structure
2251 **/
2252
2253static void
2254e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2255{
2256 int i;
2257
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002258 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002259 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260}
2261
2262/**
2263 * e1000_free_rx_resources - Free Rx Resources
2264 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002265 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 *
2267 * Free all receive software resources
2268 **/
2269
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002270static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002271e1000_free_rx_resources(struct e1000_adapter *adapter,
2272 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 struct pci_dev *pdev = adapter->pdev;
2275
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002276 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
2278 vfree(rx_ring->buffer_info);
2279 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002280 kfree(rx_ring->ps_page);
2281 rx_ring->ps_page = NULL;
2282 kfree(rx_ring->ps_page_dma);
2283 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
2285 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2286
2287 rx_ring->desc = NULL;
2288}
2289
2290/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002291 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002293 *
2294 * Free all receive software resources
2295 **/
2296
2297void
2298e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2299{
2300 int i;
2301
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002302 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002303 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2304}
2305
2306/**
2307 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2308 * @adapter: board private structure
2309 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 **/
2311
2312static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002313e1000_clean_rx_ring(struct e1000_adapter *adapter,
2314 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002317 struct e1000_ps_page *ps_page;
2318 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 struct pci_dev *pdev = adapter->pdev;
2320 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002321 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
2323 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002324 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002326 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 pci_unmap_single(pdev,
2328 buffer_info->dma,
2329 buffer_info->length,
2330 PCI_DMA_FROMDEVICE);
2331
2332 dev_kfree_skb(buffer_info->skb);
2333 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002334 }
2335 ps_page = &rx_ring->ps_page[i];
2336 ps_page_dma = &rx_ring->ps_page_dma[i];
2337 for (j = 0; j < adapter->rx_ps_pages; j++) {
2338 if (!ps_page->ps_page[j]) break;
2339 pci_unmap_page(pdev,
2340 ps_page_dma->ps_page_dma[j],
2341 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2342 ps_page_dma->ps_page_dma[j] = 0;
2343 put_page(ps_page->ps_page[j]);
2344 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 }
2346 }
2347
2348 size = sizeof(struct e1000_buffer) * rx_ring->count;
2349 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002350 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2351 memset(rx_ring->ps_page, 0, size);
2352 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2353 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
2355 /* Zero out the descriptor ring */
2356
2357 memset(rx_ring->desc, 0, rx_ring->size);
2358
2359 rx_ring->next_to_clean = 0;
2360 rx_ring->next_to_use = 0;
2361
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002362 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2363 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2364}
2365
2366/**
2367 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2368 * @adapter: board private structure
2369 **/
2370
2371static void
2372e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2373{
2374 int i;
2375
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002376 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002377 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378}
2379
2380/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2381 * and memory write and invalidate disabled for certain operations
2382 */
2383static void
2384e1000_enter_82542_rst(struct e1000_adapter *adapter)
2385{
2386 struct net_device *netdev = adapter->netdev;
2387 uint32_t rctl;
2388
2389 e1000_pci_clear_mwi(&adapter->hw);
2390
2391 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2392 rctl |= E1000_RCTL_RST;
2393 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2394 E1000_WRITE_FLUSH(&adapter->hw);
2395 mdelay(5);
2396
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002397 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002398 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399}
2400
2401static void
2402e1000_leave_82542_rst(struct e1000_adapter *adapter)
2403{
2404 struct net_device *netdev = adapter->netdev;
2405 uint32_t rctl;
2406
2407 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2408 rctl &= ~E1000_RCTL_RST;
2409 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2410 E1000_WRITE_FLUSH(&adapter->hw);
2411 mdelay(5);
2412
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002413 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 e1000_pci_set_mwi(&adapter->hw);
2415
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002416 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002417 /* No need to loop, because 82542 supports only 1 queue */
2418 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002419 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002420 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 }
2422}
2423
2424/**
2425 * e1000_set_mac - Change the Ethernet Address of the NIC
2426 * @netdev: network interface device structure
2427 * @p: pointer to an address structure
2428 *
2429 * Returns 0 on success, negative on failure
2430 **/
2431
2432static int
2433e1000_set_mac(struct net_device *netdev, void *p)
2434{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002435 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 struct sockaddr *addr = p;
2437
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002438 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 return -EADDRNOTAVAIL;
2440
2441 /* 82542 2.0 needs to be in reset to write receive address registers */
2442
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002443 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 e1000_enter_82542_rst(adapter);
2445
2446 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2447 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2448
2449 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2450
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002451 /* With 82571 controllers, LAA may be overwritten (with the default)
2452 * due to controller reset from the other port. */
2453 if (adapter->hw.mac_type == e1000_82571) {
2454 /* activate the work around */
2455 adapter->hw.laa_is_present = 1;
2456
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002457 /* Hold a copy of the LAA in RAR[14] This is done so that
2458 * between the time RAR[0] gets clobbered and the time it
2459 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002460 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002461 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002462 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002463 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002464 E1000_RAR_ENTRIES - 1);
2465 }
2466
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002467 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 e1000_leave_82542_rst(adapter);
2469
2470 return 0;
2471}
2472
2473/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002474 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 * @netdev: network interface device structure
2476 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002477 * The set_rx_mode entry point is called whenever the unicast or multicast
2478 * address lists or the network interface flags are updated. This routine is
2479 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 * promiscuous mode, and all-multi behavior.
2481 **/
2482
2483static void
Patrick McHardydb0ce502007-11-13 20:54:59 -08002484e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002486 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 struct e1000_hw *hw = &adapter->hw;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002488 struct dev_addr_list *uc_ptr;
2489 struct dev_addr_list *mc_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 uint32_t rctl;
2491 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002492 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002493 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2494 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2495 E1000_NUM_MTA_REGISTERS;
2496
2497 if (adapter->hw.mac_type == e1000_ich8lan)
2498 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002500 /* reserve RAR[14] for LAA over-write work-around */
2501 if (adapter->hw.mac_type == e1000_82571)
2502 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503
Malli Chilakala26483452005-04-28 19:44:46 -07002504 /* Check for Promiscuous and All Multicast modes */
2505
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 rctl = E1000_READ_REG(hw, RCTL);
2507
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002508 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002510 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 rctl |= E1000_RCTL_MPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 } else {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002513 rctl &= ~E1000_RCTL_MPE;
2514 }
2515
2516 uc_ptr = NULL;
2517 if (netdev->uc_count > rar_entries - 1) {
2518 rctl |= E1000_RCTL_UPE;
2519 } else if (!(netdev->flags & IFF_PROMISC)) {
2520 rctl &= ~E1000_RCTL_UPE;
2521 uc_ptr = netdev->uc_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 }
2523
2524 E1000_WRITE_REG(hw, RCTL, rctl);
2525
2526 /* 82542 2.0 needs to be in reset to write receive address registers */
2527
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002528 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 e1000_enter_82542_rst(adapter);
2530
Patrick McHardydb0ce502007-11-13 20:54:59 -08002531 /* load the first 14 addresses into the exact filters 1-14. Unicast
2532 * addresses take precedence to avoid disabling unicast filtering
2533 * when possible.
2534 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 * RAR 0 is used for the station MAC adddress
2536 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002537 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 */
2539 mc_ptr = netdev->mc_list;
2540
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002541 for (i = 1; i < rar_entries; i++) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002542 if (uc_ptr) {
2543 e1000_rar_set(hw, uc_ptr->da_addr, i);
2544 uc_ptr = uc_ptr->next;
2545 } else if (mc_ptr) {
2546 e1000_rar_set(hw, mc_ptr->da_addr, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 mc_ptr = mc_ptr->next;
2548 } else {
2549 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002550 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002552 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 }
2554 }
Patrick McHardydb0ce502007-11-13 20:54:59 -08002555 WARN_ON(uc_ptr != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556
2557 /* clear the old settings from the multicast hash table */
2558
Auke Kokcd94dd02006-06-27 09:08:22 -07002559 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002561 E1000_WRITE_FLUSH(hw);
2562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
2564 /* load any remaining addresses into the hash table */
2565
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002566 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002567 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 e1000_mta_set(hw, hash_value);
2569 }
2570
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002571 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573}
2574
2575/* Need to wait a few seconds after link up to get diagnostic information from
2576 * the phy */
2577
2578static void
2579e1000_update_phy_info(unsigned long data)
2580{
2581 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2582 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2583}
2584
2585/**
2586 * e1000_82547_tx_fifo_stall - Timer Call-back
2587 * @data: pointer to adapter cast into an unsigned long
2588 **/
2589
2590static void
2591e1000_82547_tx_fifo_stall(unsigned long data)
2592{
2593 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2594 struct net_device *netdev = adapter->netdev;
2595 uint32_t tctl;
2596
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002597 if (atomic_read(&adapter->tx_fifo_stall)) {
2598 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 E1000_READ_REG(&adapter->hw, TDH)) &&
2600 (E1000_READ_REG(&adapter->hw, TDFT) ==
2601 E1000_READ_REG(&adapter->hw, TDFH)) &&
2602 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2603 E1000_READ_REG(&adapter->hw, TDFHS))) {
2604 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2605 E1000_WRITE_REG(&adapter->hw, TCTL,
2606 tctl & ~E1000_TCTL_EN);
2607 E1000_WRITE_REG(&adapter->hw, TDFT,
2608 adapter->tx_head_addr);
2609 E1000_WRITE_REG(&adapter->hw, TDFH,
2610 adapter->tx_head_addr);
2611 E1000_WRITE_REG(&adapter->hw, TDFTS,
2612 adapter->tx_head_addr);
2613 E1000_WRITE_REG(&adapter->hw, TDFHS,
2614 adapter->tx_head_addr);
2615 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2616 E1000_WRITE_FLUSH(&adapter->hw);
2617
2618 adapter->tx_fifo_head = 0;
2619 atomic_set(&adapter->tx_fifo_stall, 0);
2620 netif_wake_queue(netdev);
2621 } else {
2622 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2623 }
2624 }
2625}
2626
2627/**
2628 * e1000_watchdog - Timer Call-back
2629 * @data: pointer to adapter cast into an unsigned long
2630 **/
2631static void
2632e1000_watchdog(unsigned long data)
2633{
2634 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002636 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002637 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002638 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
Auke Kokcd94dd02006-06-27 09:08:22 -07002640 ret_val = e1000_check_for_link(&adapter->hw);
2641 if ((ret_val == E1000_ERR_PHY) &&
2642 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2643 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2644 /* See e1000_kumeran_lock_loss_workaround() */
2645 DPRINTK(LINK, INFO,
2646 "Gigabit has been disabled, downgrading speed\n");
2647 }
Auke Kok90fb5132006-11-01 08:47:30 -08002648
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002649 if (adapter->hw.mac_type == e1000_82573) {
2650 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002651 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002652 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002655 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2657 link = !adapter->hw.serdes_link_down;
2658 else
2659 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2660
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002661 if (link) {
2662 if (!netif_carrier_ok(netdev)) {
Auke Kok9669f532007-01-18 09:25:26 -08002663 uint32_t ctrl;
Auke Kokfe7fe282006-04-14 19:04:59 -07002664 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 e1000_get_speed_and_duplex(&adapter->hw,
2666 &adapter->link_speed,
2667 &adapter->link_duplex);
2668
Auke Kok9669f532007-01-18 09:25:26 -08002669 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
2670 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2671 "Flow Control: %s\n",
2672 adapter->link_speed,
2673 adapter->link_duplex == FULL_DUPLEX ?
2674 "Full Duplex" : "Half Duplex",
2675 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2676 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2677 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2678 E1000_CTRL_TFCE) ? "TX" : "None" )));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002680 /* tweak tx_queue_len according to speed/duplex
2681 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002682 netdev->tx_queue_len = adapter->tx_queue_len;
2683 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002684 switch (adapter->link_speed) {
2685 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002686 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002687 netdev->tx_queue_len = 10;
2688 adapter->tx_timeout_factor = 8;
2689 break;
2690 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002691 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002692 netdev->tx_queue_len = 100;
2693 /* maybe add some timeout factor ? */
2694 break;
2695 }
2696
Auke Kokfe7fe282006-04-14 19:04:59 -07002697 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002698 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002699 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002700 uint32_t tarc0;
2701 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002702 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002703 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2704 }
Auke Kok90fb5132006-11-01 08:47:30 -08002705
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002706 /* disable TSO for pcie and 10/100 speeds, to avoid
2707 * some hardware issues */
2708 if (!adapter->tso_force &&
2709 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002710 switch (adapter->link_speed) {
2711 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002712 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002713 DPRINTK(PROBE,INFO,
2714 "10/100 speed: disabling TSO\n");
2715 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002716 netdev->features &= ~NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002717 break;
2718 case SPEED_1000:
2719 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002720 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002721 break;
2722 default:
2723 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002724 break;
2725 }
2726 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002727
2728 /* enable transmits in the hardware, need to do this
2729 * after setting TARC0 */
2730 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2731 tctl |= E1000_TCTL_EN;
2732 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002733
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 netif_carrier_on(netdev);
2735 netif_wake_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002736 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002738 } else {
2739 /* make sure the receive unit is started */
2740 if (adapter->hw.rx_needs_kicking) {
2741 struct e1000_hw *hw = &adapter->hw;
2742 uint32_t rctl = E1000_READ_REG(hw, RCTL);
2743 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 }
2746 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002747 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 adapter->link_speed = 0;
2749 adapter->link_duplex = 0;
2750 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2751 netif_carrier_off(netdev);
2752 netif_stop_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002753 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Jeff Kirsher87041632006-03-02 18:21:24 -08002754
2755 /* 80003ES2LAN workaround--
2756 * For packet buffer work-around on link down event;
2757 * disable receives in the ISR and
2758 * reset device here in the watchdog
2759 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002760 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002761 /* reset device */
2762 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 }
2764
2765 e1000_smartspeed(adapter);
2766 }
2767
2768 e1000_update_stats(adapter);
2769
2770 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2771 adapter->tpt_old = adapter->stats.tpt;
2772 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2773 adapter->colc_old = adapter->stats.colc;
2774
2775 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2776 adapter->gorcl_old = adapter->stats.gorcl;
2777 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2778 adapter->gotcl_old = adapter->stats.gotcl;
2779
2780 e1000_update_adaptive(&adapter->hw);
2781
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002782 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002783 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 /* We've lost link, so the controller stops DMA,
2785 * but we've got queued Tx work that's never going
2786 * to get done, so reset controller to flush Tx.
2787 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002788 adapter->tx_timeout_count++;
2789 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 }
2791 }
2792
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 /* Cause software interrupt to ensure rx ring is cleaned */
2794 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2795
Malli Chilakala26483452005-04-28 19:44:46 -07002796 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 adapter->detect_tx_hung = TRUE;
2798
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002799 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002800 * reset from the other port. Set the appropriate LAA in RAR[0] */
2801 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2802 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2803
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 /* Reset the timer */
Arjan van de Ven56e13932007-03-06 02:41:48 -08002805 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806}
2807
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002808enum latency_range {
2809 lowest_latency = 0,
2810 low_latency = 1,
2811 bulk_latency = 2,
2812 latency_invalid = 255
2813};
2814
2815/**
2816 * e1000_update_itr - update the dynamic ITR value based on statistics
2817 * Stores a new ITR value based on packets and byte
2818 * counts during the last interrupt. The advantage of per interrupt
2819 * computation is faster updates and more accurate ITR for the current
2820 * traffic pattern. Constants in this function were computed
2821 * based on theoretical maximum wire speed and thresholds were set based
2822 * on testing data as well as attempting to minimize response time
2823 * while increasing bulk throughput.
2824 * this functionality is controlled by the InterruptThrottleRate module
2825 * parameter (see e1000_param.c)
2826 * @adapter: pointer to adapter
2827 * @itr_setting: current adapter->itr
2828 * @packets: the number of packets during this measurement interval
2829 * @bytes: the number of bytes during this measurement interval
2830 **/
2831static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2832 uint16_t itr_setting,
2833 int packets,
2834 int bytes)
2835{
2836 unsigned int retval = itr_setting;
2837 struct e1000_hw *hw = &adapter->hw;
2838
2839 if (unlikely(hw->mac_type < e1000_82540))
2840 goto update_itr_done;
2841
2842 if (packets == 0)
2843 goto update_itr_done;
2844
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002845 switch (itr_setting) {
2846 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002847 /* jumbo frames get bulk treatment*/
2848 if (bytes/packets > 8000)
2849 retval = bulk_latency;
2850 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002851 retval = low_latency;
2852 break;
2853 case low_latency: /* 50 usec aka 20000 ints/s */
2854 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002855 /* jumbo frames need bulk latency setting */
2856 if (bytes/packets > 8000)
2857 retval = bulk_latency;
2858 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002859 retval = bulk_latency;
2860 else if ((packets > 35))
2861 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002862 } else if (bytes/packets > 2000)
2863 retval = bulk_latency;
2864 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002865 retval = lowest_latency;
2866 break;
2867 case bulk_latency: /* 250 usec aka 4000 ints/s */
2868 if (bytes > 25000) {
2869 if (packets > 35)
2870 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002871 } else if (bytes < 6000) {
2872 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002873 }
2874 break;
2875 }
2876
2877update_itr_done:
2878 return retval;
2879}
2880
2881static void e1000_set_itr(struct e1000_adapter *adapter)
2882{
2883 struct e1000_hw *hw = &adapter->hw;
2884 uint16_t current_itr;
2885 uint32_t new_itr = adapter->itr;
2886
2887 if (unlikely(hw->mac_type < e1000_82540))
2888 return;
2889
2890 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2891 if (unlikely(adapter->link_speed != SPEED_1000)) {
2892 current_itr = 0;
2893 new_itr = 4000;
2894 goto set_itr_now;
2895 }
2896
2897 adapter->tx_itr = e1000_update_itr(adapter,
2898 adapter->tx_itr,
2899 adapter->total_tx_packets,
2900 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002901 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2902 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2903 adapter->tx_itr = low_latency;
2904
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002905 adapter->rx_itr = e1000_update_itr(adapter,
2906 adapter->rx_itr,
2907 adapter->total_rx_packets,
2908 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002909 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2910 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2911 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002912
2913 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2914
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002915 switch (current_itr) {
2916 /* counts and packets in update_itr are dependent on these numbers */
2917 case lowest_latency:
2918 new_itr = 70000;
2919 break;
2920 case low_latency:
2921 new_itr = 20000; /* aka hwitr = ~200 */
2922 break;
2923 case bulk_latency:
2924 new_itr = 4000;
2925 break;
2926 default:
2927 break;
2928 }
2929
2930set_itr_now:
2931 if (new_itr != adapter->itr) {
2932 /* this attempts to bias the interrupt rate towards Bulk
2933 * by adding intermediate steps when interrupt rate is
2934 * increasing */
2935 new_itr = new_itr > adapter->itr ?
2936 min(adapter->itr + (new_itr >> 2), new_itr) :
2937 new_itr;
2938 adapter->itr = new_itr;
2939 E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
2940 }
2941
2942 return;
2943}
2944
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945#define E1000_TX_FLAGS_CSUM 0x00000001
2946#define E1000_TX_FLAGS_VLAN 0x00000002
2947#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002948#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2950#define E1000_TX_FLAGS_VLAN_SHIFT 16
2951
Auke Koke619d522006-04-14 19:04:52 -07002952static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002953e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2954 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002957 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 unsigned int i;
2959 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002960 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2962 int err;
2963
Herbert Xu89114af2006-07-08 13:34:32 -07002964 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 if (skb_header_cloned(skb)) {
2966 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2967 if (err)
2968 return err;
2969 }
2970
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002971 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002972 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002973 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002974 struct iphdr *iph = ip_hdr(skb);
2975 iph->tot_len = 0;
2976 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002977 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2978 iph->daddr, 0,
2979 IPPROTO_TCP,
2980 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002981 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002982 ipcse = skb_transport_offset(skb) - 1;
Auke Koke15fdd02006-08-16 11:28:45 -07002983 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002984 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002985 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002986 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2987 &ipv6_hdr(skb)->daddr,
2988 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002989 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002990 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002991 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002992 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002993 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002994 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 tucse = 0;
2996
2997 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002998 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003000 i = tx_ring->next_to_use;
3001 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003002 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003
3004 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3005 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3006 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3007 context_desc->upper_setup.tcp_fields.tucss = tucss;
3008 context_desc->upper_setup.tcp_fields.tucso = tucso;
3009 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3010 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3011 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3012 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3013
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003014 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003015 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003016
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003017 if (++i == tx_ring->count) i = 0;
3018 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019
Jeff Kirsher8241e352006-01-12 16:51:34 -08003020 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08003022 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023}
3024
Auke Koke619d522006-04-14 19:04:52 -07003025static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003026e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3027 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028{
3029 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003030 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 unsigned int i;
3032 uint8_t css;
3033
Patrick McHardy84fa7932006-08-29 16:44:56 -07003034 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07003035 css = skb_transport_offset(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003037 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003038 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003039 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040
Bruce Allanf6c57ba2007-01-18 09:25:28 -08003041 context_desc->lower_setup.ip_config = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 context_desc->upper_setup.tcp_fields.tucss = css;
Herbert Xu628592c2007-04-23 17:06:40 -07003043 context_desc->upper_setup.tcp_fields.tucso =
3044 css + skb->csum_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 context_desc->upper_setup.tcp_fields.tucse = 0;
3046 context_desc->tcp_seg_setup.data = 0;
3047 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
3048
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003049 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003050 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003051
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003052 if (unlikely(++i == tx_ring->count)) i = 0;
3053 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054
3055 return TRUE;
3056 }
3057
3058 return FALSE;
3059}
3060
3061#define E1000_MAX_TXD_PWR 12
3062#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
3063
Auke Koke619d522006-04-14 19:04:52 -07003064static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003065e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3066 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
3067 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 struct e1000_buffer *buffer_info;
3070 unsigned int len = skb->len;
3071 unsigned int offset = 0, size, count = 0, i;
3072 unsigned int f;
3073 len -= skb->data_len;
3074
3075 i = tx_ring->next_to_use;
3076
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003077 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 buffer_info = &tx_ring->buffer_info[i];
3079 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05003080 /* Workaround for Controller erratum --
3081 * descriptor for non-tso packet in a linear SKB that follows a
3082 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003083 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05003084 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07003085 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05003086 tx_ring->last_tx_tso = 0;
3087 size -= 4;
3088 }
3089
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 /* Workaround for premature desc write-backs
3091 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003092 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07003094 /* work-around for errata 10 and it applies
3095 * to all controllers in PCI-X mode
3096 * The fix is to make sure that the first descriptor of a
3097 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3098 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003099 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003100 (size > 2015) && count == 0))
3101 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003102
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 /* Workaround for potential 82544 hang in PCI-X. Avoid
3104 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003105 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3107 size > 4))
3108 size -= 4;
3109
3110 buffer_info->length = size;
3111 buffer_info->dma =
3112 pci_map_single(adapter->pdev,
3113 skb->data + offset,
3114 size,
3115 PCI_DMA_TODEVICE);
3116 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003117 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118
3119 len -= size;
3120 offset += size;
3121 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003122 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 }
3124
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003125 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 struct skb_frag_struct *frag;
3127
3128 frag = &skb_shinfo(skb)->frags[f];
3129 len = frag->size;
3130 offset = frag->page_offset;
3131
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003132 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 buffer_info = &tx_ring->buffer_info[i];
3134 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 /* Workaround for premature desc write-backs
3136 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003137 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 /* Workaround for potential 82544 hang in PCI-X.
3140 * Avoid terminating buffers within evenly-aligned
3141 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003142 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3144 size > 4))
3145 size -= 4;
3146
3147 buffer_info->length = size;
3148 buffer_info->dma =
3149 pci_map_page(adapter->pdev,
3150 frag->page,
3151 offset,
3152 size,
3153 PCI_DMA_TODEVICE);
3154 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003155 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156
3157 len -= size;
3158 offset += size;
3159 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003160 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 }
3162 }
3163
3164 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3165 tx_ring->buffer_info[i].skb = skb;
3166 tx_ring->buffer_info[first].next_to_watch = i;
3167
3168 return count;
3169}
3170
Auke Koke619d522006-04-14 19:04:52 -07003171static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003172e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3173 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 struct e1000_tx_desc *tx_desc = NULL;
3176 struct e1000_buffer *buffer_info;
3177 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3178 unsigned int i;
3179
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003180 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3182 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003183 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3184
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003185 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003186 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 }
3188
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003189 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3191 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3192 }
3193
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003194 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 txd_lower |= E1000_TXD_CMD_VLE;
3196 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3197 }
3198
3199 i = tx_ring->next_to_use;
3200
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003201 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 buffer_info = &tx_ring->buffer_info[i];
3203 tx_desc = E1000_TX_DESC(*tx_ring, i);
3204 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3205 tx_desc->lower.data =
3206 cpu_to_le32(txd_lower | buffer_info->length);
3207 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003208 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 }
3210
3211 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3212
3213 /* Force memory writes to complete before letting h/w
3214 * know there are new descriptors to fetch. (Only
3215 * applicable for weak-ordered memory model archs,
3216 * such as IA-64). */
3217 wmb();
3218
3219 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003220 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003221 /* we need this if more than one processor can write to our tail
3222 * at a time, it syncronizes IO on IA64/Altix systems */
3223 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224}
3225
3226/**
3227 * 82547 workaround to avoid controller hang in half-duplex environment.
3228 * The workaround is to avoid queuing a large packet that would span
3229 * the internal Tx FIFO ring boundary by notifying the stack to resend
3230 * the packet at a later time. This gives the Tx FIFO an opportunity to
3231 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3232 * to the beginning of the Tx FIFO.
3233 **/
3234
3235#define E1000_FIFO_HDR 0x10
3236#define E1000_82547_PAD_LEN 0x3E0
3237
Auke Koke619d522006-04-14 19:04:52 -07003238static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
3240{
3241 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3242 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
3243
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003244 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003246 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 goto no_fifo_stall_required;
3248
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003249 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 return 1;
3251
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003252 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 atomic_set(&adapter->tx_fifo_stall, 1);
3254 return 1;
3255 }
3256
3257no_fifo_stall_required:
3258 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003259 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3261 return 0;
3262}
3263
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003264#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07003265static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003266e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
3267{
3268 struct e1000_hw *hw = &adapter->hw;
3269 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003270 if (vlan_tx_tag_present(skb)) {
3271 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003272 ( adapter->hw.mng_cookie.status &
3273 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3274 return 0;
3275 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003276 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003277 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003278 if ((htons(ETH_P_IP) == eth->h_proto)) {
3279 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003280 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003281 if (IPPROTO_UDP == ip->protocol) {
3282 struct udphdr *udp =
3283 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003284 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003285 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003286 offset = (uint8_t *)udp + 8 - skb->data;
3287 length = skb->len - offset;
3288
3289 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003290 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003291 length);
3292 }
3293 }
3294 }
3295 }
3296 return 0;
3297}
3298
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003299static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3300{
3301 struct e1000_adapter *adapter = netdev_priv(netdev);
3302 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3303
3304 netif_stop_queue(netdev);
3305 /* Herbert's original patch had:
3306 * smp_mb__after_netif_stop_queue();
3307 * but since that doesn't exist yet, just open code it. */
3308 smp_mb();
3309
3310 /* We need to check again in a case another CPU has just
3311 * made room available. */
3312 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3313 return -EBUSY;
3314
3315 /* A reprieve! */
3316 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003317 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003318 return 0;
3319}
3320
3321static int e1000_maybe_stop_tx(struct net_device *netdev,
3322 struct e1000_tx_ring *tx_ring, int size)
3323{
3324 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3325 return 0;
3326 return __e1000_maybe_stop_tx(netdev, size);
3327}
3328
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3330static int
3331e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3332{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003333 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003334 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3336 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3337 unsigned int tx_flags = 0;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003338 unsigned int len = skb->len - skb->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 unsigned long flags;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003340 unsigned int nr_frags;
3341 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003343 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 unsigned int f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003346 /* This goes back to the question of how to logically map a tx queue
3347 * to a flow. Right now, performance is impacted slightly negatively
3348 * if using multiple tx queues. If the stack breaks away from a
3349 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003350 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003351
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003352 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 dev_kfree_skb_any(skb);
3354 return NETDEV_TX_OK;
3355 }
3356
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003357 /* 82571 and newer doesn't need the workaround that limited descriptor
3358 * length to 4kB */
3359 if (adapter->hw.mac_type >= e1000_82571)
3360 max_per_txd = 8192;
3361
Herbert Xu79671682006-06-22 02:40:14 -07003362 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003363 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 * make sure there is enough room in the FIFO before
3365 * initiating the DMA for each buffer. The calc is:
3366 * 4 = ceil(buffer len/mss). To make sure we don't
3367 * overrun the FIFO, adjust the max buffer len if mss
3368 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003369 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003370 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 max_per_txd = min(mss << 2, max_per_txd);
3372 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003373
Auke Kok90fb5132006-11-01 08:47:30 -08003374 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3375 * points to just header, pull a few bytes of payload from
3376 * frags into skb->data */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003377 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003378 if (skb->data_len && hdr_len == len) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003379 switch (adapter->hw.mac_type) {
3380 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003381 case e1000_82544:
3382 /* Make sure we have room to chop off 4 bytes,
3383 * and that the end alignment will work out to
3384 * this hardware's requirements
3385 * NOTE: this is a TSO only workaround
3386 * if end byte alignment not correct move us
3387 * into the next dword */
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003388 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003389 break;
3390 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003391 case e1000_82571:
3392 case e1000_82572:
3393 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003394 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003395 pull_size = min((unsigned int)4, skb->data_len);
3396 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003397 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003398 "__pskb_pull_tail failed.\n");
3399 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003400 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003401 }
3402 len = skb->len - skb->data_len;
3403 break;
3404 default:
3405 /* do nothing */
3406 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003407 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 }
3410
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003411 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003412 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003414 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003415
Jeff Kirsherfd803242005-12-13 00:06:22 -05003416 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003417 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003418 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003419
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 count += TXD_USE_COUNT(len, max_txd_pwr);
3421
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003422 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 count++;
3424
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003425 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003426 * in PCI-X mode, so add one more descriptor to the count
3427 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003428 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003429 (len > 2015)))
3430 count++;
3431
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003433 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3435 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003436 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 count += nr_frags;
3438
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003439
3440 if (adapter->hw.tx_pkt_filtering &&
3441 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003442 e1000_transfer_dhcp_info(adapter, skb);
3443
Mark Huthf50393f2007-03-06 08:57:26 -08003444 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003445 /* Collision - tell upper layer to requeue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003446 return NETDEV_TX_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447
3448 /* need: count + 2 desc gap to keep tail from touching
3449 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003450 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003451 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 return NETDEV_TX_BUSY;
3453 }
3454
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003455 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3456 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003458 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003459 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 return NETDEV_TX_BUSY;
3461 }
3462 }
3463
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003464 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 tx_flags |= E1000_TX_FLAGS_VLAN;
3466 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3467 }
3468
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003469 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003470
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003471 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 if (tso < 0) {
3473 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003474 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 return NETDEV_TX_OK;
3476 }
3477
Jeff Kirsherfd803242005-12-13 00:06:22 -05003478 if (likely(tso)) {
3479 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003481 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 tx_flags |= E1000_TX_FLAGS_CSUM;
3483
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003484 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003485 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003486 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003487 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003488 tx_flags |= E1000_TX_FLAGS_IPV4;
3489
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003490 e1000_tx_queue(adapter, tx_ring, tx_flags,
3491 e1000_tx_map(adapter, tx_ring, skb, first,
3492 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493
3494 netdev->trans_start = jiffies;
3495
3496 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003497 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003499 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 return NETDEV_TX_OK;
3501}
3502
3503/**
3504 * e1000_tx_timeout - Respond to a Tx Hang
3505 * @netdev: network interface device structure
3506 **/
3507
3508static void
3509e1000_tx_timeout(struct net_device *netdev)
3510{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003511 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512
3513 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003514 adapter->tx_timeout_count++;
3515 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516}
3517
3518static void
David Howells65f27f32006-11-22 14:55:48 +00003519e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520{
David Howells65f27f32006-11-22 14:55:48 +00003521 struct e1000_adapter *adapter =
3522 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
Auke Kok2db10a02006-06-27 09:06:28 -07003524 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525}
3526
3527/**
3528 * e1000_get_stats - Get System Network Statistics
3529 * @netdev: network interface device structure
3530 *
3531 * Returns the address of the device statistics structure.
3532 * The statistics are actually updated from the timer callback.
3533 **/
3534
3535static struct net_device_stats *
3536e1000_get_stats(struct net_device *netdev)
3537{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003538 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003540 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 return &adapter->net_stats;
3542}
3543
3544/**
3545 * e1000_change_mtu - Change the Maximum Transfer Unit
3546 * @netdev: network interface device structure
3547 * @new_mtu: new value for maximum frame size
3548 *
3549 * Returns 0 on success, negative on failure
3550 **/
3551
3552static int
3553e1000_change_mtu(struct net_device *netdev, int new_mtu)
3554{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003555 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003557 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003559 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3560 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3561 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003562 return -EINVAL;
3563 }
3564
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003565 /* Adapter-specific max frame size limits. */
3566 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003567 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003568 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003569 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3570 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003571 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003572 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003573 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003574 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003575 /* Jumbo Frames not supported if:
3576 * - this is not an 82573L device
3577 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003578 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3579 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003580 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3581 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003582 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3583 DPRINTK(PROBE, ERR,
3584 "Jumbo Frames not supported.\n");
3585 return -EINVAL;
3586 }
3587 break;
3588 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003589 /* ERT will be enabled later to enable wire speed receives */
3590
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003591 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003592 case e1000_82571:
3593 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003594 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003595#define MAX_STD_JUMBO_FRAME_SIZE 9234
3596 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3597 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3598 return -EINVAL;
3599 }
3600 break;
3601 default:
3602 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3603 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003604 }
3605
David S. Miller87f50322006-07-31 22:39:40 -07003606 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003607 * means we reserve 2 more, this pushes us to allocate from the next
3608 * larger slab size
3609 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003610
Auke Kok9e2feac2006-04-14 19:05:18 -07003611 if (max_frame <= E1000_RXBUFFER_256)
3612 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3613 else if (max_frame <= E1000_RXBUFFER_512)
3614 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3615 else if (max_frame <= E1000_RXBUFFER_1024)
3616 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3617 else if (max_frame <= E1000_RXBUFFER_2048)
3618 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3619 else if (max_frame <= E1000_RXBUFFER_4096)
3620 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3621 else if (max_frame <= E1000_RXBUFFER_8192)
3622 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3623 else if (max_frame <= E1000_RXBUFFER_16384)
3624 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3625
3626 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003627 if (!adapter->hw.tbi_compatibility_on &&
3628 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3629 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3630 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003631
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003632 netdev->mtu = new_mtu;
Bruce Allan83cd8272006-12-15 10:36:35 +01003633 adapter->hw.max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003634
Auke Kok2db10a02006-06-27 09:06:28 -07003635 if (netif_running(netdev))
3636 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 return 0;
3639}
3640
3641/**
3642 * e1000_update_stats - Update the board statistics counters
3643 * @adapter: board private structure
3644 **/
3645
3646void
3647e1000_update_stats(struct e1000_adapter *adapter)
3648{
3649 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003650 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 unsigned long flags;
3652 uint16_t phy_tmp;
3653
3654#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3655
Linas Vepstas282f33c2006-06-08 22:19:44 -07003656 /*
3657 * Prevent stats update while adapter is being reset, or if the pci
3658 * connection is down.
3659 */
Auke Kok90267292006-06-08 09:30:24 -07003660 if (adapter->link_speed == 0)
3661 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003662 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003663 return;
Auke Kok90267292006-06-08 09:30:24 -07003664
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665 spin_lock_irqsave(&adapter->stats_lock, flags);
3666
Masatake YAMATO828d0552007-10-20 03:06:37 +02003667 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 * called from the interrupt context, so they must only
3669 * be written while holding adapter->stats_lock
3670 */
3671
3672 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3673 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3674 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3675 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3676 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3677 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3678 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003679
3680 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003681 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3682 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3683 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3684 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3685 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3686 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688
3689 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3690 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3691 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3692 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3693 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3694 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3695 adapter->stats.dc += E1000_READ_REG(hw, DC);
3696 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3697 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3698 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3699 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3700 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3701 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3702 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3703 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3704 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3705 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3706 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3707 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3708 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3709 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3710 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3711 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3712 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3713 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3714 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003715
3716 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003717 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3718 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3719 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3720 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3721 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3722 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003723 }
3724
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3726 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3727
3728 /* used for adaptive IFS */
3729
3730 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3731 adapter->stats.tpt += hw->tx_packet_delta;
3732 hw->collision_delta = E1000_READ_REG(hw, COLC);
3733 adapter->stats.colc += hw->collision_delta;
3734
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003735 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3737 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3738 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3739 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3740 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3741 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3742 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003743 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003744 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3745 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003746
3747 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003748 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3749 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3750 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3751 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3752 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3753 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3754 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003755 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757
3758 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 adapter->net_stats.multicast = adapter->stats.mprc;
3760 adapter->net_stats.collisions = adapter->stats.colc;
3761
3762 /* Rx Errors */
3763
Jeff Kirsher87041632006-03-02 18:21:24 -08003764 /* RLEC on some newer hardware can be incorrect so build
3765 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3767 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003768 adapter->stats.ruc + adapter->stats.roc +
3769 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003770 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3771 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3773 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3775
3776 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003777 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3778 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3780 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3781 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Jeff Garzik167fb282006-12-15 10:41:15 -05003782 if (adapter->hw.bad_tx_carr_stats_fd &&
3783 adapter->link_duplex == FULL_DUPLEX) {
3784 adapter->net_stats.tx_carrier_errors = 0;
3785 adapter->stats.tncrs = 0;
3786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787
3788 /* Tx Dropped needs to be maintained elsewhere */
3789
3790 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003791 if (hw->media_type == e1000_media_type_copper) {
3792 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3794 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3795 adapter->phy_stats.idle_errors += phy_tmp;
3796 }
3797
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003798 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 (hw->phy_type == e1000_phy_m88) &&
3800 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3801 adapter->phy_stats.receive_errors += phy_tmp;
3802 }
3803
Jeff Garzik15e376b2006-12-15 11:16:33 -05003804 /* Management Stats */
3805 if (adapter->hw.has_smbus) {
3806 adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
3807 adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
3808 adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
3809 }
3810
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3812}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003813
3814/**
3815 * e1000_intr_msi - Interrupt Handler
3816 * @irq: interrupt number
3817 * @data: pointer to a network interface device structure
3818 **/
3819
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003820static irqreturn_t
3821e1000_intr_msi(int irq, void *data)
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003822{
3823 struct net_device *netdev = data;
3824 struct e1000_adapter *adapter = netdev_priv(netdev);
3825 struct e1000_hw *hw = &adapter->hw;
3826#ifndef CONFIG_E1000_NAPI
3827 int i;
3828#endif
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003829 uint32_t icr = E1000_READ_REG(hw, ICR);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003830
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003831#ifdef CONFIG_E1000_NAPI
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003832 /* read ICR disables interrupts using IAM, so keep up with our
3833 * enable/disable accounting */
3834 atomic_inc(&adapter->irq_sem);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003835#endif
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003836 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3837 hw->get_link_status = 1;
3838 /* 80003ES2LAN workaround-- For packet buffer work-around on
3839 * link down event; disable receives here in the ISR and reset
3840 * adapter in watchdog */
3841 if (netif_carrier_ok(netdev) &&
3842 (adapter->hw.mac_type == e1000_80003es2lan)) {
3843 /* disable receives */
3844 uint32_t rctl = E1000_READ_REG(hw, RCTL);
3845 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003846 }
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003847 /* guard against interrupt when we're going down */
3848 if (!test_bit(__E1000_DOWN, &adapter->flags))
3849 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003850 }
3851
3852#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003853 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003854 adapter->total_tx_bytes = 0;
3855 adapter->total_tx_packets = 0;
3856 adapter->total_rx_bytes = 0;
3857 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003858 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003859 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003860 e1000_irq_enable(adapter);
3861#else
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003862 adapter->total_tx_bytes = 0;
3863 adapter->total_rx_bytes = 0;
3864 adapter->total_tx_packets = 0;
3865 adapter->total_rx_packets = 0;
3866
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003867 for (i = 0; i < E1000_MAX_INTR; i++)
3868 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003869 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003870 break;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003871
3872 if (likely(adapter->itr_setting & 3))
3873 e1000_set_itr(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003874#endif
3875
3876 return IRQ_HANDLED;
3877}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878
3879/**
3880 * e1000_intr - Interrupt Handler
3881 * @irq: interrupt number
3882 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 **/
3884
3885static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003886e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887{
3888 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003889 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003891 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003892#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003893 int i;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003894#endif
3895 if (unlikely(!icr))
3896 return IRQ_NONE; /* Not our interrupt */
3897
3898#ifdef CONFIG_E1000_NAPI
3899 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3900 * not set, then the adapter didn't send an interrupt */
3901 if (unlikely(hw->mac_type >= e1000_82571 &&
3902 !(icr & E1000_ICR_INT_ASSERTED)))
3903 return IRQ_NONE;
3904
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003905 /* Interrupt Auto-Mask...upon reading ICR,
3906 * interrupts are masked. No need for the
3907 * IMC write, but it does mean we should
3908 * account for it ASAP. */
3909 if (likely(hw->mac_type >= e1000_82571))
3910 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003911#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003913 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003915 /* 80003ES2LAN workaround--
3916 * For packet buffer work-around on link down event;
3917 * disable receives here in the ISR and
3918 * reset adapter in watchdog
3919 */
3920 if (netif_carrier_ok(netdev) &&
3921 (adapter->hw.mac_type == e1000_80003es2lan)) {
3922 /* disable receives */
3923 rctl = E1000_READ_REG(hw, RCTL);
3924 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3925 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003926 /* guard against interrupt when we're going down */
3927 if (!test_bit(__E1000_DOWN, &adapter->flags))
3928 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 }
3930
3931#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003932 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003933 /* disable interrupts, without the synchronize_irq bit */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003934 atomic_inc(&adapter->irq_sem);
3935 E1000_WRITE_REG(hw, IMC, ~0);
3936 E1000_WRITE_FLUSH(hw);
3937 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003938 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003939 adapter->total_tx_bytes = 0;
3940 adapter->total_tx_packets = 0;
3941 adapter->total_rx_bytes = 0;
3942 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003943 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003944 } else
Auke Kok90fb5132006-11-01 08:47:30 -08003945 /* this really should not happen! if it does it is basically a
3946 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003947 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003948#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003950 * Due to Hub Link bus being occupied, an interrupt
3951 * de-assertion message is not able to be sent.
3952 * When an interrupt assertion message is generated later,
3953 * two messages are re-ordered and sent out.
3954 * That causes APIC to think 82547 is in de-assertion
3955 * state, while 82547 is in assertion state, resulting
3956 * in dead lock. Writing IMC forces 82547 into
3957 * de-assertion state.
3958 */
3959 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003961 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 }
3963
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003964 adapter->total_tx_bytes = 0;
3965 adapter->total_rx_bytes = 0;
3966 adapter->total_tx_packets = 0;
3967 adapter->total_rx_packets = 0;
3968
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003969 for (i = 0; i < E1000_MAX_INTR; i++)
3970 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003971 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 break;
3973
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003974 if (likely(adapter->itr_setting & 3))
3975 e1000_set_itr(adapter);
3976
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003977 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003979
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003980#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 return IRQ_HANDLED;
3982}
3983
3984#ifdef CONFIG_E1000_NAPI
3985/**
3986 * e1000_clean - NAPI Rx polling callback
3987 * @adapter: board private structure
3988 **/
3989
3990static int
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003991e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003993 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3994 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003995 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003996
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003997 /* Must NOT use netdev_priv macro here. */
3998 adapter = poll_dev->priv;
3999
Auke Kokd3d9e482006-07-14 16:14:23 -07004000 /* e1000_clean is called per-cpu. This lock protects
4001 * tx_ring[0] from being cleaned by multiple cpus
4002 * simultaneously. A failure obtaining the lock means
4003 * tx_ring[0] is currently being cleaned anyway. */
4004 if (spin_trylock(&adapter->tx_queue_lock)) {
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004005 tx_cleaned = e1000_clean_tx_irq(adapter,
4006 &adapter->tx_ring[0]);
Auke Kokd3d9e482006-07-14 16:14:23 -07004007 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004008 }
4009
Auke Kokd3d9e482006-07-14 16:14:23 -07004010 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004011 &work_done, budget);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004012
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004013 if (tx_cleaned)
4014 work_done = budget;
4015
David S. Miller53e52c72008-01-07 21:06:12 -08004016 /* If budget not fully consumed, exit the polling mode */
4017 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004018 if (likely(adapter->itr_setting & 3))
4019 e1000_set_itr(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004020 netif_rx_complete(poll_dev, napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 }
4023
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004024 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025}
4026
4027#endif
4028/**
4029 * e1000_clean_tx_irq - Reclaim resources after transmit completes
4030 * @adapter: board private structure
4031 **/
4032
4033static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004034e1000_clean_tx_irq(struct e1000_adapter *adapter,
4035 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 struct net_device *netdev = adapter->netdev;
4038 struct e1000_tx_desc *tx_desc, *eop_desc;
4039 struct e1000_buffer *buffer_info;
4040 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004041#ifdef CONFIG_E1000_NAPI
4042 unsigned int count = 0;
4043#endif
Linus Torvalds46fcc862007-04-19 18:21:01 -07004044 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004045 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046
4047 i = tx_ring->next_to_clean;
4048 eop = tx_ring->buffer_info[i].next_to_watch;
4049 eop_desc = E1000_TX_DESC(*tx_ring, eop);
4050
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004051 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004052 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 tx_desc = E1000_TX_DESC(*tx_ring, i);
4054 buffer_info = &tx_ring->buffer_info[i];
4055 cleaned = (i == eop);
4056
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004057 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004058 struct sk_buff *skb = buffer_info->skb;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08004059 unsigned int segs, bytecount;
4060 segs = skb_shinfo(skb)->gso_segs ?: 1;
4061 /* multiply data chunks by size of headers */
4062 bytecount = ((segs - 1) * skb_headlen(skb)) +
4063 skb->len;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004064 total_tx_packets += segs;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08004065 total_tx_bytes += bytecount;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004066 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05004067 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08004068 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004070 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004072
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 eop = tx_ring->buffer_info[i].next_to_watch;
4074 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004075#ifdef CONFIG_E1000_NAPI
4076#define E1000_TX_WEIGHT 64
4077 /* weight of a sort for tx, to avoid endless transmit cleanup */
Linus Torvalds46fcc862007-04-19 18:21:01 -07004078 if (count++ == E1000_TX_WEIGHT) break;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004079#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 }
4081
4082 tx_ring->next_to_clean = i;
4083
Auke Kok77b2aad2006-04-14 19:05:25 -07004084#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07004085 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
4086 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
4087 /* Make sure that anybody stopping the queue after this
4088 * sees the new next_to_clean.
4089 */
4090 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004091 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07004092 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004093 ++adapter->restart_queue;
4094 }
Auke Kok77b2aad2006-04-14 19:05:25 -07004095 }
Malli Chilakala26483452005-04-28 19:44:46 -07004096
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004097 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07004098 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 * check with the clearing of time_stamp and movement of i */
4100 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08004101 if (tx_ring->buffer_info[eop].dma &&
4102 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08004103 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004104 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08004105 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004106
4107 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07004108 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004109 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004110 " TDH <%x>\n"
4111 " TDT <%x>\n"
4112 " next_to_use <%x>\n"
4113 " next_to_clean <%x>\n"
4114 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004115 " time_stamp <%lx>\n"
4116 " next_to_watch <%x>\n"
4117 " jiffies <%lx>\n"
4118 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004119 (unsigned long)((tx_ring - adapter->tx_ring) /
4120 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004121 readl(adapter->hw.hw_addr + tx_ring->tdh),
4122 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004123 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08004124 tx_ring->next_to_clean,
4125 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004126 eop,
4127 jiffies,
4128 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004132 adapter->total_tx_bytes += total_tx_bytes;
4133 adapter->total_tx_packets += total_tx_packets;
Auke Kokef90e4e2007-11-13 20:49:15 -08004134 adapter->net_stats.tx_bytes += total_tx_bytes;
4135 adapter->net_stats.tx_packets += total_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 return cleaned;
4137}
4138
4139/**
4140 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004141 * @adapter: board private structure
4142 * @status_err: receive descriptor status and error fields
4143 * @csum: receive descriptor csum field
4144 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 **/
4146
Auke Koke619d522006-04-14 19:04:52 -07004147static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004149 uint32_t status_err, uint32_t csum,
4150 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004152 uint16_t status = (uint16_t)status_err;
4153 uint8_t errors = (uint8_t)(status_err >> 24);
4154 skb->ip_summed = CHECKSUM_NONE;
4155
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004157 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004159 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004160 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004161 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004162 /* let the stack verify checksum errors */
4163 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 return;
4165 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004166 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004167 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
4168 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004169 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004171 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004172 return;
4173 }
4174 /* It must be a TCP or UDP packet with a valid checksum */
4175 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 /* TCP checksum is good */
4177 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004178 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
4179 /* IP fragment with UDP payload */
4180 /* Hardware complements the payload checksum, so we undo it
4181 * and then put the value in host order for further stack use.
4182 */
Al Viro3e188262007-12-11 19:49:39 +00004183 __sum16 sum = (__force __sum16)htons(csum);
4184 skb->csum = csum_unfold(~sum);
Patrick McHardy84fa7932006-08-29 16:44:56 -07004185 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004187 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188}
4189
4190/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004191 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 * @adapter: board private structure
4193 **/
4194
4195static boolean_t
4196#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004197e1000_clean_rx_irq(struct e1000_adapter *adapter,
4198 struct e1000_rx_ring *rx_ring,
4199 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004201e1000_clean_rx_irq(struct e1000_adapter *adapter,
4202 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203#endif
4204{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 struct net_device *netdev = adapter->netdev;
4206 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004207 struct e1000_rx_desc *rx_desc, *next_rxd;
4208 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 unsigned long flags;
4210 uint32_t length;
4211 uint8_t last_byte;
4212 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004213 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004214 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004215 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216
4217 i = rx_ring->next_to_clean;
4218 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004219 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004221 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004222 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004223 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004224
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004226 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 break;
4228 (*work_done)++;
4229#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08004230 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004231 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004232 buffer_info->skb = NULL;
4233
Jeff Kirsher30320be2006-03-02 18:21:57 -08004234 prefetch(skb->data - NET_IP_ALIGN);
4235
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004236 if (++i == rx_ring->count) i = 0;
4237 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004238 prefetch(next_rxd);
4239
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004240 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004241
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004242 cleaned = TRUE;
4243 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004244 pci_unmap_single(pdev,
4245 buffer_info->dma,
4246 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 PCI_DMA_FROMDEVICE);
4248
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 length = le16_to_cpu(rx_desc->length);
4250
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004251 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4252 /* All receives must fit into a single buffer */
4253 E1000_DBG("%s: Receive packet consumed multiple"
4254 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004255 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004256 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 goto next_desc;
4258 }
4259
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004260 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004262 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 rx_desc->errors, length, last_byte)) {
4264 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004265 e1000_tbi_adjust_stats(&adapter->hw,
4266 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 length, skb->data);
4268 spin_unlock_irqrestore(&adapter->stats_lock,
4269 flags);
4270 length--;
4271 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004272 /* recycle */
4273 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 goto next_desc;
4275 }
Auke Kok1cb58212006-04-18 12:31:04 -07004276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004278 /* adjust length to remove Ethernet CRC, this must be
4279 * done after the TBI_ACCEPT workaround above */
4280 length -= 4;
4281
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004282 /* probably a little skewed due to removing CRC */
4283 total_rx_bytes += length;
4284 total_rx_packets++;
4285
Jeff Kirshera292ca62006-01-12 16:51:30 -08004286 /* code added for copybreak, this should improve
4287 * performance for small packets with large amounts
4288 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004289 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004290 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004291 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004292 if (new_skb) {
4293 skb_reserve(new_skb, NET_IP_ALIGN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004294 skb_copy_to_linear_data_offset(new_skb,
4295 -NET_IP_ALIGN,
4296 (skb->data -
4297 NET_IP_ALIGN),
4298 (length +
4299 NET_IP_ALIGN));
Jeff Kirshera292ca62006-01-12 16:51:30 -08004300 /* save the skb in buffer_info as good */
4301 buffer_info->skb = skb;
4302 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004303 }
Auke Kok996695d2006-11-01 08:47:50 -08004304 /* else just continue with the old one */
4305 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004306 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004307 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308
4309 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004310 e1000_rx_checksum(adapter,
4311 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004312 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004313 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004314
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 skb->protocol = eth_type_trans(skb, netdev);
4316#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004317 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08004318 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004320 le16_to_cpu(rx_desc->special) &
4321 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 } else {
4323 netif_receive_skb(skb);
4324 }
4325#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004326 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004327 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 vlan_hwaccel_rx(skb, adapter->vlgrp,
4329 le16_to_cpu(rx_desc->special) &
4330 E1000_RXD_SPC_VLAN_MASK);
4331 } else {
4332 netif_rx(skb);
4333 }
4334#endif /* CONFIG_E1000_NAPI */
4335 netdev->last_rx = jiffies;
4336
4337next_desc:
4338 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004340 /* return some buffers to hardware, one at a time is too slow */
4341 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4342 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4343 cleaned_count = 0;
4344 }
4345
Jeff Kirsher30320be2006-03-02 18:21:57 -08004346 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004347 rx_desc = next_rxd;
4348 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004351
4352 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4353 if (cleaned_count)
4354 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004356 adapter->total_rx_packets += total_rx_packets;
4357 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004358 adapter->net_stats.rx_bytes += total_rx_bytes;
4359 adapter->net_stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 return cleaned;
4361}
4362
4363/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004364 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4365 * @adapter: board private structure
4366 **/
4367
4368static boolean_t
4369#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004370e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4371 struct e1000_rx_ring *rx_ring,
4372 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004373#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004374e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4375 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004376#endif
4377{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004378 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004379 struct net_device *netdev = adapter->netdev;
4380 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004381 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004382 struct e1000_ps_page *ps_page;
4383 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07004384 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004385 unsigned int i, j;
4386 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004387 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004388 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004389 unsigned int total_rx_bytes=0, total_rx_packets=0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004390
4391 i = rx_ring->next_to_clean;
4392 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07004393 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07004394 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004395
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004396 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004397 ps_page = &rx_ring->ps_page[i];
4398 ps_page_dma = &rx_ring->ps_page_dma[i];
4399#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004400 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004401 break;
4402 (*work_done)++;
4403#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004404 skb = buffer_info->skb;
4405
Jeff Kirsher30320be2006-03-02 18:21:57 -08004406 /* in the packet split case this is header only */
4407 prefetch(skb->data - NET_IP_ALIGN);
4408
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004409 if (++i == rx_ring->count) i = 0;
4410 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004411 prefetch(next_rxd);
4412
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004413 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004414
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004415 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004416 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004417 pci_unmap_single(pdev, buffer_info->dma,
4418 buffer_info->length,
4419 PCI_DMA_FROMDEVICE);
4420
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004421 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004422 E1000_DBG("%s: Packet Split buffers didn't pick up"
4423 " the full packet\n", netdev->name);
4424 dev_kfree_skb_irq(skb);
4425 goto next_desc;
4426 }
4427
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004428 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004429 dev_kfree_skb_irq(skb);
4430 goto next_desc;
4431 }
4432
4433 length = le16_to_cpu(rx_desc->wb.middle.length0);
4434
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004435 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004436 E1000_DBG("%s: Last part of the packet spanning"
4437 " multiple descriptors\n", netdev->name);
4438 dev_kfree_skb_irq(skb);
4439 goto next_desc;
4440 }
4441
4442 /* Good Receive */
4443 skb_put(skb, length);
4444
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004445 {
4446 /* this looks ugly, but it seems compiler issues make it
4447 more efficient than reusing j */
4448 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4449
4450 /* page alloc/put takes too long and effects small packet
4451 * throughput, so unsplit small packets and save the alloc/put*/
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004452 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004453 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004454 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004455 * kmap_atomic, so we can't hold the mapping
4456 * very long */
4457 pci_dma_sync_single_for_cpu(pdev,
4458 ps_page_dma->ps_page_dma[0],
4459 PAGE_SIZE,
4460 PCI_DMA_FROMDEVICE);
4461 vaddr = kmap_atomic(ps_page->ps_page[0],
4462 KM_SKB_DATA_SOFTIRQ);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07004463 memcpy(skb_tail_pointer(skb), vaddr, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004464 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4465 pci_dma_sync_single_for_device(pdev,
4466 ps_page_dma->ps_page_dma[0],
4467 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004468 /* remove the CRC */
4469 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004470 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004471 goto copydone;
4472 } /* if */
4473 }
Auke Kok90fb5132006-11-01 08:47:30 -08004474
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004475 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004476 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004477 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004478 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4479 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4480 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004481 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4482 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004483 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004484 skb->len += length;
4485 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004486 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004487 }
4488
Auke Kokf235a2a2006-07-14 16:14:34 -07004489 /* strip the ethernet crc, problem is we're using pages now so
4490 * this whole operation can get a little cpu intensive */
4491 pskb_trim(skb, skb->len - 4);
4492
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004493copydone:
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004494 total_rx_bytes += skb->len;
4495 total_rx_packets++;
4496
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004497 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004498 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004499 skb->protocol = eth_type_trans(skb, netdev);
4500
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004501 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004502 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004503 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004504#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004505 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004506 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004507 le16_to_cpu(rx_desc->wb.middle.vlan) &
4508 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004509 } else {
4510 netif_receive_skb(skb);
4511 }
4512#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004513 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004514 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004515 le16_to_cpu(rx_desc->wb.middle.vlan) &
4516 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004517 } else {
4518 netif_rx(skb);
4519 }
4520#endif /* CONFIG_E1000_NAPI */
4521 netdev->last_rx = jiffies;
4522
4523next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004524 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004525 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004526
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004527 /* return some buffers to hardware, one at a time is too slow */
4528 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4529 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4530 cleaned_count = 0;
4531 }
4532
Jeff Kirsher30320be2006-03-02 18:21:57 -08004533 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004534 rx_desc = next_rxd;
4535 buffer_info = next_buffer;
4536
Malli Chilakala683a38f2005-06-17 17:43:25 -07004537 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004538 }
4539 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004540
4541 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4542 if (cleaned_count)
4543 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004544
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004545 adapter->total_rx_packets += total_rx_packets;
4546 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004547 adapter->net_stats.rx_bytes += total_rx_bytes;
4548 adapter->net_stats.rx_packets += total_rx_packets;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004549 return cleaned;
4550}
4551
4552/**
4553 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 * @adapter: address of board private structure
4555 **/
4556
4557static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004558e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004559 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004560 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 struct net_device *netdev = adapter->netdev;
4563 struct pci_dev *pdev = adapter->pdev;
4564 struct e1000_rx_desc *rx_desc;
4565 struct e1000_buffer *buffer_info;
4566 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004567 unsigned int i;
4568 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569
4570 i = rx_ring->next_to_use;
4571 buffer_info = &rx_ring->buffer_info[i];
4572
Jeff Kirshera292ca62006-01-12 16:51:30 -08004573 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004574 skb = buffer_info->skb;
4575 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004576 skb_trim(skb, 0);
4577 goto map_skb;
4578 }
4579
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004580 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004581 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004583 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 break;
4585 }
4586
Malli Chilakala26483452005-04-28 19:44:46 -07004587 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4589 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004590 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4591 "at %p\n", bufsz, skb->data);
4592 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004593 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004594 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 if (!skb) {
4596 dev_kfree_skb(oldskb);
4597 break;
4598 }
Malli Chilakala26483452005-04-28 19:44:46 -07004599
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4601 /* give up */
4602 dev_kfree_skb(skb);
4603 dev_kfree_skb(oldskb);
4604 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004606
4607 /* Use new allocation */
4608 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 /* Make buffer alignment 2 beyond a 16 byte boundary
4611 * this will result in a 16 byte aligned IP header after
4612 * the 14 byte MAC header is removed
4613 */
4614 skb_reserve(skb, NET_IP_ALIGN);
4615
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 buffer_info->skb = skb;
4617 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004618map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 buffer_info->dma = pci_map_single(pdev,
4620 skb->data,
4621 adapter->rx_buffer_len,
4622 PCI_DMA_FROMDEVICE);
4623
Malli Chilakala26483452005-04-28 19:44:46 -07004624 /* Fix for errata 23, can't cross 64kB boundary */
4625 if (!e1000_check_64k_bound(adapter,
4626 (void *)(unsigned long)buffer_info->dma,
4627 adapter->rx_buffer_len)) {
4628 DPRINTK(RX_ERR, ERR,
4629 "dma align check failed: %u bytes at %p\n",
4630 adapter->rx_buffer_len,
4631 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632 dev_kfree_skb(skb);
4633 buffer_info->skb = NULL;
4634
Malli Chilakala26483452005-04-28 19:44:46 -07004635 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 adapter->rx_buffer_len,
4637 PCI_DMA_FROMDEVICE);
4638
4639 break; /* while !buffer_info->skb */
4640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 rx_desc = E1000_RX_DESC(*rx_ring, i);
4642 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4643
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004644 if (unlikely(++i == rx_ring->count))
4645 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 buffer_info = &rx_ring->buffer_info[i];
4647 }
4648
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004649 if (likely(rx_ring->next_to_use != i)) {
4650 rx_ring->next_to_use = i;
4651 if (unlikely(i-- == 0))
4652 i = (rx_ring->count - 1);
4653
4654 /* Force memory writes to complete before letting h/w
4655 * know there are new descriptors to fetch. (Only
4656 * applicable for weak-ordered memory model archs,
4657 * such as IA-64). */
4658 wmb();
4659 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4660 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661}
4662
4663/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004664 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4665 * @adapter: address of board private structure
4666 **/
4667
4668static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004669e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004670 struct e1000_rx_ring *rx_ring,
4671 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004672{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004673 struct net_device *netdev = adapter->netdev;
4674 struct pci_dev *pdev = adapter->pdev;
4675 union e1000_rx_desc_packet_split *rx_desc;
4676 struct e1000_buffer *buffer_info;
4677 struct e1000_ps_page *ps_page;
4678 struct e1000_ps_page_dma *ps_page_dma;
4679 struct sk_buff *skb;
4680 unsigned int i, j;
4681
4682 i = rx_ring->next_to_use;
4683 buffer_info = &rx_ring->buffer_info[i];
4684 ps_page = &rx_ring->ps_page[i];
4685 ps_page_dma = &rx_ring->ps_page_dma[i];
4686
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004687 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004688 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4689
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004690 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004691 if (j < adapter->rx_ps_pages) {
4692 if (likely(!ps_page->ps_page[j])) {
4693 ps_page->ps_page[j] =
4694 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004695 if (unlikely(!ps_page->ps_page[j])) {
4696 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004697 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004698 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004699 ps_page_dma->ps_page_dma[j] =
4700 pci_map_page(pdev,
4701 ps_page->ps_page[j],
4702 0, PAGE_SIZE,
4703 PCI_DMA_FROMDEVICE);
4704 }
4705 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004706 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004707 * this info.
4708 */
4709 rx_desc->read.buffer_addr[j+1] =
4710 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4711 } else
Al Viro3e188262007-12-11 19:49:39 +00004712 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004713 }
4714
David S. Miller87f50322006-07-31 22:39:40 -07004715 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004716 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004717
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004718 if (unlikely(!skb)) {
4719 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004720 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004721 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004722
4723 /* Make buffer alignment 2 beyond a 16 byte boundary
4724 * this will result in a 16 byte aligned IP header after
4725 * the 14 byte MAC header is removed
4726 */
4727 skb_reserve(skb, NET_IP_ALIGN);
4728
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004729 buffer_info->skb = skb;
4730 buffer_info->length = adapter->rx_ps_bsize0;
4731 buffer_info->dma = pci_map_single(pdev, skb->data,
4732 adapter->rx_ps_bsize0,
4733 PCI_DMA_FROMDEVICE);
4734
4735 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4736
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004737 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004738 buffer_info = &rx_ring->buffer_info[i];
4739 ps_page = &rx_ring->ps_page[i];
4740 ps_page_dma = &rx_ring->ps_page_dma[i];
4741 }
4742
4743no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004744 if (likely(rx_ring->next_to_use != i)) {
4745 rx_ring->next_to_use = i;
4746 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4747
4748 /* Force memory writes to complete before letting h/w
4749 * know there are new descriptors to fetch. (Only
4750 * applicable for weak-ordered memory model archs,
4751 * such as IA-64). */
4752 wmb();
4753 /* Hardware increments by 16 bytes, but packet split
4754 * descriptors are 32 bytes...so we increment tail
4755 * twice as much.
4756 */
4757 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4758 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004759}
4760
4761/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4763 * @adapter:
4764 **/
4765
4766static void
4767e1000_smartspeed(struct e1000_adapter *adapter)
4768{
4769 uint16_t phy_status;
4770 uint16_t phy_ctrl;
4771
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004772 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4774 return;
4775
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004776 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 /* If Master/Slave config fault is asserted twice,
4778 * we assume back-to-back */
4779 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004780 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004782 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004784 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4786 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4787 phy_ctrl);
4788 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004789 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4791 &phy_ctrl)) {
4792 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4793 MII_CR_RESTART_AUTO_NEG);
4794 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4795 phy_ctrl);
4796 }
4797 }
4798 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004799 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 /* If still no link, perhaps using 2/3 pair cable */
4801 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4802 phy_ctrl |= CR_1000T_MS_ENABLE;
4803 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004804 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4806 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4807 MII_CR_RESTART_AUTO_NEG);
4808 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4809 }
4810 }
4811 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004812 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 adapter->smartspeed = 0;
4814}
4815
4816/**
4817 * e1000_ioctl -
4818 * @netdev:
4819 * @ifreq:
4820 * @cmd:
4821 **/
4822
4823static int
4824e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4825{
4826 switch (cmd) {
4827 case SIOCGMIIPHY:
4828 case SIOCGMIIREG:
4829 case SIOCSMIIREG:
4830 return e1000_mii_ioctl(netdev, ifr, cmd);
4831 default:
4832 return -EOPNOTSUPP;
4833 }
4834}
4835
4836/**
4837 * e1000_mii_ioctl -
4838 * @netdev:
4839 * @ifreq:
4840 * @cmd:
4841 **/
4842
4843static int
4844e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4845{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004846 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 struct mii_ioctl_data *data = if_mii(ifr);
4848 int retval;
4849 uint16_t mii_reg;
4850 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004851 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004853 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 return -EOPNOTSUPP;
4855
4856 switch (cmd) {
4857 case SIOCGMIIPHY:
4858 data->phy_id = adapter->hw.phy_addr;
4859 break;
4860 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004861 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004863 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004864 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004865 &data->val_out)) {
4866 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004868 }
4869 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 break;
4871 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004872 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004874 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875 return -EFAULT;
4876 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004877 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004878 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004879 mii_reg)) {
4880 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004882 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004883 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Auke Kokdc86d322006-04-18 12:30:51 -07004884 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 switch (data->reg_num) {
4886 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004887 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004889 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 adapter->hw.autoneg = 1;
4891 adapter->hw.autoneg_advertised = 0x2F;
4892 } else {
4893 if (mii_reg & 0x40)
4894 spddplx = SPEED_1000;
4895 else if (mii_reg & 0x2000)
4896 spddplx = SPEED_100;
4897 else
4898 spddplx = SPEED_10;
4899 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004900 ? DUPLEX_FULL :
4901 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 retval = e1000_set_spd_dplx(adapter,
4903 spddplx);
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004904 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 return retval;
4906 }
Auke Kok2db10a02006-06-27 09:06:28 -07004907 if (netif_running(adapter->netdev))
4908 e1000_reinit_locked(adapter);
4909 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 e1000_reset(adapter);
4911 break;
4912 case M88E1000_PHY_SPEC_CTRL:
4913 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004914 if (e1000_phy_reset(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915 return -EIO;
4916 break;
4917 }
4918 } else {
4919 switch (data->reg_num) {
4920 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004921 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004923 if (netif_running(adapter->netdev))
4924 e1000_reinit_locked(adapter);
4925 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926 e1000_reset(adapter);
4927 break;
4928 }
4929 }
4930 break;
4931 default:
4932 return -EOPNOTSUPP;
4933 }
4934 return E1000_SUCCESS;
4935}
4936
4937void
4938e1000_pci_set_mwi(struct e1000_hw *hw)
4939{
4940 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004941 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004943 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004944 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945}
4946
4947void
4948e1000_pci_clear_mwi(struct e1000_hw *hw)
4949{
4950 struct e1000_adapter *adapter = hw->back;
4951
4952 pci_clear_mwi(adapter->pdev);
4953}
4954
Peter Oruba007755e2007-09-28 22:42:06 -07004955int
4956e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4957{
4958 struct e1000_adapter *adapter = hw->back;
4959 return pcix_get_mmrbc(adapter->pdev);
4960}
4961
4962void
4963e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4964{
4965 struct e1000_adapter *adapter = hw->back;
4966 pcix_set_mmrbc(adapter->pdev, mmrbc);
4967}
4968
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004969int32_t
4970e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4971{
4972 struct e1000_adapter *adapter = hw->back;
4973 uint16_t cap_offset;
4974
4975 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4976 if (!cap_offset)
4977 return -E1000_ERR_CONFIG;
4978
4979 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4980
4981 return E1000_SUCCESS;
4982}
4983
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984void
4985e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4986{
4987 outl(value, port);
4988}
4989
4990static void
4991e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4992{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004993 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 uint32_t ctrl, rctl;
4995
4996 e1000_irq_disable(adapter);
4997 adapter->vlgrp = grp;
4998
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004999 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 /* enable VLAN tag insert/strip */
5001 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5002 ctrl |= E1000_CTRL_VME;
5003 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5004
Auke Kokcd94dd02006-06-27 09:08:22 -07005005 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08005006 /* enable VLAN receive filtering */
5007 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5008 rctl |= E1000_RCTL_VFE;
5009 rctl &= ~E1000_RCTL_CFIEN;
5010 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5011 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07005012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 } else {
5014 /* disable VLAN tag insert/strip */
5015 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5016 ctrl &= ~E1000_CTRL_VME;
5017 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5018
Auke Kokcd94dd02006-06-27 09:08:22 -07005019 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08005020 /* disable VLAN filtering */
5021 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5022 rctl &= ~E1000_RCTL_VFE;
5023 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5024 if (adapter->mng_vlan_id !=
5025 (uint16_t)E1000_MNG_VLAN_NONE) {
5026 e1000_vlan_rx_kill_vid(netdev,
5027 adapter->mng_vlan_id);
5028 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
5029 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 }
5032
5033 e1000_irq_enable(adapter);
5034}
5035
5036static void
5037e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
5038{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005039 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005041
5042 if ((adapter->hw.mng_cookie.status &
5043 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
5044 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005045 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 /* add VID to filter table */
5047 index = (vid >> 5) & 0x7F;
5048 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5049 vfta |= (1 << (vid & 0x1F));
5050 e1000_write_vfta(&adapter->hw, index, vfta);
5051}
5052
5053static void
5054e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
5055{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005056 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057 uint32_t vfta, index;
5058
5059 e1000_irq_disable(adapter);
Dan Aloni5c15bde2007-03-02 20:44:51 -08005060 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061 e1000_irq_enable(adapter);
5062
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005063 if ((adapter->hw.mng_cookie.status &
5064 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08005065 (vid == adapter->mng_vlan_id)) {
5066 /* release control to f/w */
5067 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005068 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08005069 }
5070
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 /* remove VID from filter table */
5072 index = (vid >> 5) & 0x7F;
5073 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5074 vfta &= ~(1 << (vid & 0x1F));
5075 e1000_write_vfta(&adapter->hw, index, vfta);
5076}
5077
5078static void
5079e1000_restore_vlan(struct e1000_adapter *adapter)
5080{
5081 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
5082
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005083 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005085 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08005086 if (!vlan_group_get_device(adapter->vlgrp, vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 continue;
5088 e1000_vlan_rx_add_vid(adapter->netdev, vid);
5089 }
5090 }
5091}
5092
5093int
5094e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
5095{
5096 adapter->hw.autoneg = 0;
5097
Malli Chilakala69213682005-06-17 17:44:20 -07005098 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005099 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07005100 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
5101 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
5102 return -EINVAL;
5103 }
5104
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005105 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106 case SPEED_10 + DUPLEX_HALF:
5107 adapter->hw.forced_speed_duplex = e1000_10_half;
5108 break;
5109 case SPEED_10 + DUPLEX_FULL:
5110 adapter->hw.forced_speed_duplex = e1000_10_full;
5111 break;
5112 case SPEED_100 + DUPLEX_HALF:
5113 adapter->hw.forced_speed_duplex = e1000_100_half;
5114 break;
5115 case SPEED_100 + DUPLEX_FULL:
5116 adapter->hw.forced_speed_duplex = e1000_100_full;
5117 break;
5118 case SPEED_1000 + DUPLEX_FULL:
5119 adapter->hw.autoneg = 1;
5120 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
5121 break;
5122 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5123 default:
Malli Chilakala26483452005-04-28 19:44:46 -07005124 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125 return -EINVAL;
5126 }
5127 return 0;
5128}
5129
5130static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07005131e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132{
5133 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005134 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005135 uint32_t ctrl, ctrl_ext, rctl, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07005137#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08005138 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07005139#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140
5141 netif_device_detach(netdev);
5142
Auke Kok2db10a02006-06-27 09:06:28 -07005143 if (netif_running(netdev)) {
5144 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07005146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005148#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005149 retval = pci_save_state(pdev);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005150 if (retval)
5151 return retval;
5152#endif
5153
Linus Torvalds1da177e2005-04-16 15:20:36 -07005154 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005155 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156 wufc &= ~E1000_WUFC_LNKC;
5157
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005158 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005160 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161
5162 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005163 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5165 rctl |= E1000_RCTL_MPE;
5166 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5167 }
5168
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005169 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5171 /* advertise wake from D3Cold */
5172 #define E1000_CTRL_ADVD3WUC 0x00100000
5173 /* phy power management enable */
5174 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5175 ctrl |= E1000_CTRL_ADVD3WUC |
5176 E1000_CTRL_EN_PHY_PWR_MGMT;
5177 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5178 }
5179
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005180 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181 adapter->hw.media_type == e1000_media_type_internal_serdes) {
5182 /* keep the laser running in D3 */
5183 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
5184 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5185 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
5186 }
5187
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005188 /* Allow time for pending master requests to run */
5189 e1000_disable_pciex_master(&adapter->hw);
5190
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
5192 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07005193 pci_enable_wake(pdev, PCI_D3hot, 1);
5194 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195 } else {
5196 E1000_WRITE_REG(&adapter->hw, WUC, 0);
5197 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07005198 pci_enable_wake(pdev, PCI_D3hot, 0);
5199 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200 }
5201
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005202 e1000_release_manageability(adapter);
5203
5204 /* make sure adapter isn't asleep if manageability is enabled */
5205 if (adapter->en_mng_pt) {
5206 pci_enable_wake(pdev, PCI_D3hot, 1);
5207 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208 }
5209
Auke Kokcd94dd02006-06-27 09:08:22 -07005210 if (adapter->hw.phy_type == e1000_phy_igp_3)
5211 e1000_phy_powerdown_workaround(&adapter->hw);
5212
Auke Kokedd106f2006-11-06 08:57:12 -08005213 if (netif_running(netdev))
5214 e1000_free_irq(adapter);
5215
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005216 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5217 * would have already happened in close and is redundant. */
5218 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005219
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005221
Auke Kokd0e027d2006-04-14 19:04:40 -07005222 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223
5224 return 0;
5225}
5226
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005227#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228static int
5229e1000_resume(struct pci_dev *pdev)
5230{
5231 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005232 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005233 uint32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234
Auke Kokd0e027d2006-04-14 19:04:40 -07005235 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005236 pci_restore_state(pdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005237 if ((err = pci_enable_device(pdev))) {
5238 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5239 return err;
5240 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005241 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242
Auke Kokd0e027d2006-04-14 19:04:40 -07005243 pci_enable_wake(pdev, PCI_D3hot, 0);
5244 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245
Auke Kokedd106f2006-11-06 08:57:12 -08005246 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
5247 return err;
5248
5249 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250 e1000_reset(adapter);
5251 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5252
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005253 e1000_init_manageability(adapter);
5254
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005255 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256 e1000_up(adapter);
5257
5258 netif_device_attach(netdev);
5259
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005260 /* If the controller is 82573 and f/w is AMT, do not set
5261 * DRV_LOAD until the interface is up. For all other cases,
5262 * let the f/w know that the h/w is now under the control
5263 * of the driver. */
5264 if (adapter->hw.mac_type != e1000_82573 ||
5265 !e1000_check_mng_mode(&adapter->hw))
5266 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005267
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268 return 0;
5269}
5270#endif
Auke Kokc653e632006-05-23 13:35:57 -07005271
5272static void e1000_shutdown(struct pci_dev *pdev)
5273{
5274 e1000_suspend(pdev, PMSG_SUSPEND);
5275}
5276
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277#ifdef CONFIG_NET_POLL_CONTROLLER
5278/*
5279 * Polling 'interrupt' - used by things like netconsole to send skbs
5280 * without having to re-enable interrupts. It's not called while
5281 * the interrupt routine is executing.
5282 */
5283static void
Malli Chilakala26483452005-04-28 19:44:46 -07005284e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005286 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005287
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005289 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07005290 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08005291#ifndef CONFIG_E1000_NAPI
5292 adapter->clean_rx(adapter, adapter->rx_ring);
5293#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 enable_irq(adapter->pdev->irq);
5295}
5296#endif
5297
Auke Kok90267292006-06-08 09:30:24 -07005298/**
5299 * e1000_io_error_detected - called when PCI error is detected
5300 * @pdev: Pointer to PCI device
5301 * @state: The current pci conneection state
5302 *
5303 * This function is called after a PCI bus error affecting
5304 * this device has been detected.
5305 */
5306static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5307{
5308 struct net_device *netdev = pci_get_drvdata(pdev);
5309 struct e1000_adapter *adapter = netdev->priv;
5310
5311 netif_device_detach(netdev);
5312
5313 if (netif_running(netdev))
5314 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005315 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005316
5317 /* Request a slot slot reset. */
5318 return PCI_ERS_RESULT_NEED_RESET;
5319}
5320
5321/**
5322 * e1000_io_slot_reset - called after the pci bus has been reset.
5323 * @pdev: Pointer to PCI device
5324 *
5325 * Restart the card from scratch, as if from a cold-boot. Implementation
5326 * resembles the first-half of the e1000_resume routine.
5327 */
5328static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5329{
5330 struct net_device *netdev = pci_get_drvdata(pdev);
5331 struct e1000_adapter *adapter = netdev->priv;
5332
5333 if (pci_enable_device(pdev)) {
5334 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5335 return PCI_ERS_RESULT_DISCONNECT;
5336 }
5337 pci_set_master(pdev);
5338
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005339 pci_enable_wake(pdev, PCI_D3hot, 0);
5340 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005341
Auke Kok90267292006-06-08 09:30:24 -07005342 e1000_reset(adapter);
5343 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5344
5345 return PCI_ERS_RESULT_RECOVERED;
5346}
5347
5348/**
5349 * e1000_io_resume - called when traffic can start flowing again.
5350 * @pdev: Pointer to PCI device
5351 *
5352 * This callback is called when the error recovery driver tells us that
5353 * its OK to resume normal operation. Implementation resembles the
5354 * second-half of the e1000_resume routine.
5355 */
5356static void e1000_io_resume(struct pci_dev *pdev)
5357{
5358 struct net_device *netdev = pci_get_drvdata(pdev);
5359 struct e1000_adapter *adapter = netdev->priv;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005360
5361 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005362
5363 if (netif_running(netdev)) {
5364 if (e1000_up(adapter)) {
5365 printk("e1000: can't bring device back up after reset\n");
5366 return;
5367 }
5368 }
5369
5370 netif_device_attach(netdev);
5371
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005372 /* If the controller is 82573 and f/w is AMT, do not set
5373 * DRV_LOAD until the interface is up. For all other cases,
5374 * let the f/w know that the h/w is now under the control
5375 * of the driver. */
5376 if (adapter->hw.mac_type != e1000_82573 ||
5377 !e1000_check_mng_mode(&adapter->hw))
5378 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005379
Auke Kok90267292006-06-08 09:30:24 -07005380}
5381
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382/* e1000_main.c */