blob: 7c5b05a82f0e7c9a27b77a9f3d943fcf3baf2931 [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 unsigned long mmio_start, mmio_len;
Auke Kokcd94dd02006-06-27 09:08:22 -0700930 unsigned long flash_start, flash_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700933 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700934 int i, err, pci_using_dac;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700935 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Joe Perches0795af52007-10-03 17:59:30 -0700937 DECLARE_MAC_BUF(mac);
938
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800939 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 return err;
941
Auke Kokcd94dd02006-06-27 09:08:22 -0700942 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
943 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 pci_using_dac = 1;
945 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700946 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
947 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700949 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 }
951 pci_using_dac = 0;
952 }
953
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800954 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700955 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 pci_set_master(pdev);
958
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700959 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700961 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 SET_NETDEV_DEV(netdev, &pdev->dev);
965
966 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700967 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 adapter->netdev = netdev;
969 adapter->pdev = pdev;
970 adapter->hw.back = adapter;
971 adapter->msg_enable = (1 << debug) - 1;
972
973 mmio_start = pci_resource_start(pdev, BAR_0);
974 mmio_len = pci_resource_len(pdev, BAR_0);
975
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700976 err = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700978 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800981 for (i = BAR_1; i <= BAR_5; i++) {
982 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800984 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 adapter->hw.io_base = pci_resource_start(pdev, i);
986 break;
987 }
988 }
989
990 netdev->open = &e1000_open;
991 netdev->stop = &e1000_close;
992 netdev->hard_start_xmit = &e1000_xmit_frame;
993 netdev->get_stats = &e1000_get_stats;
Patrick McHardydb0ce502007-11-13 20:54:59 -0800994 netdev->set_rx_mode = &e1000_set_rx_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 netdev->set_mac_address = &e1000_set_mac;
996 netdev->change_mtu = &e1000_change_mtu;
997 netdev->do_ioctl = &e1000_ioctl;
998 e1000_set_ethtool_ops(netdev);
999 netdev->tx_timeout = &e1000_tx_timeout;
1000 netdev->watchdog_timeo = 5 * HZ;
1001#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001002 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003#endif
1004 netdev->vlan_rx_register = e1000_vlan_rx_register;
1005 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
1006 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
1007#ifdef CONFIG_NET_POLL_CONTROLLER
1008 netdev->poll_controller = e1000_netpoll;
1009#endif
Auke Kok0eb5a342006-09-27 12:53:17 -07001010 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
1012 netdev->mem_start = mmio_start;
1013 netdev->mem_end = mmio_start + mmio_len;
1014 netdev->base_addr = adapter->hw.io_base;
1015
1016 adapter->bd_number = cards_found;
1017
1018 /* setup the private structure */
1019
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001020 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 goto err_sw_init;
1022
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001023 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -07001024 /* Flash BAR mapping must happen after e1000_sw_init
1025 * because it depends on mac_type */
1026 if ((adapter->hw.mac_type == e1000_ich8lan) &&
1027 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
1028 flash_start = pci_resource_start(pdev, 1);
1029 flash_len = pci_resource_len(pdev, 1);
1030 adapter->hw.flash_address = ioremap(flash_start, flash_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001031 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -07001032 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -07001033 }
1034
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001035 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001036 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
1037
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001038 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 netdev->features = NETIF_F_SG |
1040 NETIF_F_HW_CSUM |
1041 NETIF_F_HW_VLAN_TX |
1042 NETIF_F_HW_VLAN_RX |
1043 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -07001044 if (adapter->hw.mac_type == e1000_ich8lan)
1045 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 }
1047
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001048 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 (adapter->hw.mac_type != e1000_82547))
1050 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001051
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001052 if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -08001053 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001054 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 netdev->features |= NETIF_F_HIGHDMA;
1056
Auke Kok76c224b2006-05-23 13:36:06 -07001057 netdev->features |= NETIF_F_LLTX;
1058
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001059 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
1060
Auke Kokcd94dd02006-06-27 09:08:22 -07001061 /* initialize eeprom parameters */
Auke Kokcd94dd02006-06-27 09:08:22 -07001062 if (e1000_init_eeprom_params(&adapter->hw)) {
1063 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001064 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001065 }
1066
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001067 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 e1000_reset_hw(&adapter->hw);
1071
1072 /* make sure the EEPROM is good */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001073 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Auke Kok67b3c272007-12-17 13:50:23 -08001075 e1000_dump_eeprom(adapter);
1076 /*
1077 * set MAC address to all zeroes to invalidate and temporary
1078 * disable this device for the user. This blocks regular
1079 * traffic while still permitting ethtool ioctls from reaching
1080 * the hardware as well as allowing the user to run the
1081 * interface after manually setting a hw addr using
1082 * `ip set address`
1083 */
1084 memset(adapter->hw.mac_addr, 0, netdev->addr_len);
1085 } else {
1086 /* copy the MAC address out of the EEPROM */
1087 if (e1000_read_mac_addr(&adapter->hw))
1088 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 }
Auke Kok67b3c272007-12-17 13:50:23 -08001090 /* don't block initalization here due to bad MAC address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -04001092 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Auke Kok67b3c272007-12-17 13:50:23 -08001094 if (!is_valid_ether_addr(netdev->perm_addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 e1000_get_bus_info(&adapter->hw);
1098
1099 init_timer(&adapter->tx_fifo_stall_timer);
1100 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1101 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
1102
1103 init_timer(&adapter->watchdog_timer);
1104 adapter->watchdog_timer.function = &e1000_watchdog;
1105 adapter->watchdog_timer.data = (unsigned long) adapter;
1106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 init_timer(&adapter->phy_info_timer);
1108 adapter->phy_info_timer.function = &e1000_update_phy_info;
1109 adapter->phy_info_timer.data = (unsigned long) adapter;
1110
David Howells65f27f32006-11-22 14:55:48 +00001111 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 e1000_check_options(adapter);
1114
1115 /* Initial Wake on LAN setting
1116 * If APM wake is enabled in the EEPROM,
1117 * enable the ACPI Magic Packet filter
1118 */
1119
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001120 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 case e1000_82542_rev2_0:
1122 case e1000_82542_rev2_1:
1123 case e1000_82543:
1124 break;
1125 case e1000_82544:
1126 e1000_read_eeprom(&adapter->hw,
1127 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1128 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1129 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001130 case e1000_ich8lan:
1131 e1000_read_eeprom(&adapter->hw,
1132 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1133 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1134 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 case e1000_82546:
1136 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001137 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001138 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001139 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 e1000_read_eeprom(&adapter->hw,
1141 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1142 break;
1143 }
1144 /* Fall Through */
1145 default:
1146 e1000_read_eeprom(&adapter->hw,
1147 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1148 break;
1149 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001150 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001151 adapter->eeprom_wol |= E1000_WUFC_MAG;
1152
1153 /* now that we have the eeprom settings, apply the special cases
1154 * where the eeprom may be wrong or the board simply won't support
1155 * wake on lan on a particular port */
1156 switch (pdev->device) {
1157 case E1000_DEV_ID_82546GB_PCIE:
1158 adapter->eeprom_wol = 0;
1159 break;
1160 case E1000_DEV_ID_82546EB_FIBER:
1161 case E1000_DEV_ID_82546GB_FIBER:
1162 case E1000_DEV_ID_82571EB_FIBER:
1163 /* Wake events only supported on port A for dual fiber
1164 * regardless of eeprom setting */
1165 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
1166 adapter->eeprom_wol = 0;
1167 break;
1168 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001169 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001170 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001171 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001172 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001173 /* if quad port adapter, disable WoL on all but port A */
1174 if (global_quad_port_a != 0)
1175 adapter->eeprom_wol = 0;
1176 else
1177 adapter->quad_port_a = 1;
1178 /* Reset for multiple quad port adapters */
1179 if (++global_quad_port_a == 4)
1180 global_quad_port_a = 0;
1181 break;
1182 }
1183
1184 /* initialize the wol settings based on the eeprom settings */
1185 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001187 /* print bus type/speed/width info */
1188 {
1189 struct e1000_hw *hw = &adapter->hw;
1190 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1191 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1192 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1193 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1194 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1195 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1196 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1197 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1198 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1199 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1200 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1201 "32-bit"));
1202 }
1203
Joe Perches0795af52007-10-03 17:59:30 -07001204 printk("%s\n", print_mac(mac, netdev->dev_addr));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 /* reset the hardware with the new settings */
1207 e1000_reset(adapter);
1208
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001209 /* If the controller is 82573 and f/w is AMT, do not set
1210 * DRV_LOAD until the interface is up. For all other cases,
1211 * let the f/w know that the h/w is now under the control
1212 * of the driver. */
1213 if (adapter->hw.mac_type != e1000_82573 ||
1214 !e1000_check_mng_mode(&adapter->hw))
1215 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001216
Auke Kok1314bbf2006-09-27 12:54:02 -07001217 /* tell the stack to leave us alone until e1000_open() is called */
1218 netif_carrier_off(netdev);
1219 netif_stop_queue(netdev);
Auke Kok416b5d12007-06-01 10:22:39 -07001220
1221 strcpy(netdev->name, "eth%d");
1222 if ((err = register_netdev(netdev)))
1223 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001224
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1226
1227 cards_found++;
1228 return 0;
1229
1230err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001231 e1000_release_hw_control(adapter);
1232err_eeprom:
1233 if (!e1000_check_phy_reset_block(&adapter->hw))
1234 e1000_phy_hw_reset(&adapter->hw);
1235
Auke Kokcd94dd02006-06-27 09:08:22 -07001236 if (adapter->hw.flash_address)
1237 iounmap(adapter->hw.flash_address);
1238err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001239#ifdef CONFIG_E1000_NAPI
1240 for (i = 0; i < adapter->num_rx_queues; i++)
1241 dev_put(&adapter->polling_netdev[i]);
1242#endif
1243
1244 kfree(adapter->tx_ring);
1245 kfree(adapter->rx_ring);
1246#ifdef CONFIG_E1000_NAPI
1247 kfree(adapter->polling_netdev);
1248#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 iounmap(adapter->hw.hw_addr);
1251err_ioremap:
1252 free_netdev(netdev);
1253err_alloc_etherdev:
1254 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001255err_pci_reg:
1256err_dma:
1257 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 return err;
1259}
1260
1261/**
1262 * e1000_remove - Device Removal Routine
1263 * @pdev: PCI device information struct
1264 *
1265 * e1000_remove is called by the PCI subsystem to alert the driver
1266 * that it should release a PCI device. The could be caused by a
1267 * Hot-Plug event, or because the driver is going to be removed from
1268 * memory.
1269 **/
1270
1271static void __devexit
1272e1000_remove(struct pci_dev *pdev)
1273{
1274 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001275 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001276#ifdef CONFIG_E1000_NAPI
1277 int i;
1278#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Oleg Nesterov28e53bd2007-05-09 02:34:22 -07001280 cancel_work_sync(&adapter->reset_task);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001281
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001282 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001284 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1285 * would have already happened in close and is redundant. */
1286 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001287
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001288#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001289 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001290 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001291#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001293 unregister_netdev(netdev);
1294
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001295 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001296 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001298 kfree(adapter->tx_ring);
1299 kfree(adapter->rx_ring);
1300#ifdef CONFIG_E1000_NAPI
1301 kfree(adapter->polling_netdev);
1302#endif
1303
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001305 if (adapter->hw.flash_address)
1306 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 pci_release_regions(pdev);
1308
1309 free_netdev(netdev);
1310
1311 pci_disable_device(pdev);
1312}
1313
1314/**
1315 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1316 * @adapter: board private structure to initialize
1317 *
1318 * e1000_sw_init initializes the Adapter private data structure.
1319 * Fields are initialized based on PCI device information and
1320 * OS network device settings (MTU size).
1321 **/
1322
1323static int __devinit
1324e1000_sw_init(struct e1000_adapter *adapter)
1325{
1326 struct e1000_hw *hw = &adapter->hw;
1327 struct net_device *netdev = adapter->netdev;
1328 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001329#ifdef CONFIG_E1000_NAPI
1330 int i;
1331#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 /* PCI config space info */
1334
1335 hw->vendor_id = pdev->vendor;
1336 hw->device_id = pdev->device;
1337 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1338 hw->subsystem_id = pdev->subsystem_device;
Auke Kok44c10132007-06-08 15:46:36 -07001339 hw->revision_id = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
1341 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1342
Auke Kokeb0f8052006-07-14 16:14:48 -07001343 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001344 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 hw->max_frame_size = netdev->mtu +
1346 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1347 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1348
1349 /* identify the MAC */
1350
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001351 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1353 return -EIO;
1354 }
1355
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001356 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 default:
1358 break;
1359 case e1000_82541:
1360 case e1000_82547:
1361 case e1000_82541_rev_2:
1362 case e1000_82547_rev_2:
1363 hw->phy_init_script = 1;
1364 break;
1365 }
1366
1367 e1000_set_media_type(hw);
1368
1369 hw->wait_autoneg_complete = FALSE;
1370 hw->tbi_compatibility_en = TRUE;
1371 hw->adaptive_ifs = TRUE;
1372
1373 /* Copper options */
1374
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001375 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 hw->mdix = AUTO_ALL_MODES;
1377 hw->disable_polarity_correction = FALSE;
1378 hw->master_slave = E1000_MASTER_SLAVE;
1379 }
1380
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001381 adapter->num_tx_queues = 1;
1382 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001383
1384 if (e1000_alloc_queues(adapter)) {
1385 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1386 return -ENOMEM;
1387 }
1388
1389#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001390 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001391 adapter->polling_netdev[i].priv = adapter;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001392 dev_hold(&adapter->polling_netdev[i]);
1393 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1394 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001395 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001396#endif
1397
Herbert Xu47313052007-05-29 15:07:31 -07001398 /* Explicitly disable IRQ since the NIC can be in any state. */
1399 atomic_set(&adapter->irq_sem, 0);
1400 e1000_irq_disable(adapter);
1401
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Auke Kok1314bbf2006-09-27 12:54:02 -07001404 set_bit(__E1000_DOWN, &adapter->flags);
1405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 return 0;
1407}
1408
1409/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001410 * e1000_alloc_queues - Allocate memory for all rings
1411 * @adapter: board private structure to initialize
1412 *
1413 * We allocate one ring per queue at run-time since we don't know the
1414 * number of queues at compile-time. The polling_netdev array is
1415 * intended for Multiqueue, but should work fine with a single queue.
1416 **/
1417
1418static int __devinit
1419e1000_alloc_queues(struct e1000_adapter *adapter)
1420{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001421 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1422 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001423 if (!adapter->tx_ring)
1424 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001425
Yan Burman1c7e5b12007-03-06 08:58:04 -08001426 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1427 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001428 if (!adapter->rx_ring) {
1429 kfree(adapter->tx_ring);
1430 return -ENOMEM;
1431 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001432
1433#ifdef CONFIG_E1000_NAPI
Yan Burman1c7e5b12007-03-06 08:58:04 -08001434 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1435 sizeof(struct net_device),
1436 GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001437 if (!adapter->polling_netdev) {
1438 kfree(adapter->tx_ring);
1439 kfree(adapter->rx_ring);
1440 return -ENOMEM;
1441 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001442#endif
1443
1444 return E1000_SUCCESS;
1445}
1446
1447/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 * e1000_open - Called when a network interface is made active
1449 * @netdev: network interface device structure
1450 *
1451 * Returns 0 on success, negative value on failure
1452 *
1453 * The open entry point is called when a network interface is made
1454 * active by the system (IFF_UP). At this point all resources needed
1455 * for transmit and receive operations are allocated, the interrupt
1456 * handler is registered with the OS, the watchdog timer is started,
1457 * and the stack is notified that the interface is ready.
1458 **/
1459
1460static int
1461e1000_open(struct net_device *netdev)
1462{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001463 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 int err;
1465
Auke Kok2db10a02006-06-27 09:06:28 -07001466 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001467 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001468 return -EBUSY;
1469
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001471 err = e1000_setup_all_tx_resources(adapter);
1472 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 goto err_setup_tx;
1474
1475 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001476 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001477 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001478 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001479
Auke Kok79f05bf2006-06-27 09:06:32 -07001480 e1000_power_up_phy(adapter);
1481
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001482 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001483 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001484 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1485 e1000_update_mng_vlan(adapter);
1486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001488 /* If AMT is enabled, let the firmware know that the network
1489 * interface is now open */
1490 if (adapter->hw.mac_type == e1000_82573 &&
1491 e1000_check_mng_mode(&adapter->hw))
1492 e1000_get_hw_control(adapter);
1493
Auke Koke0aac5a2007-03-06 08:57:21 -08001494 /* before we allocate an interrupt, we must be ready to handle it.
1495 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1496 * as soon as we call pci_request_irq, so we have to setup our
1497 * clean_rx handler before we do so. */
1498 e1000_configure(adapter);
1499
1500 err = e1000_request_irq(adapter);
1501 if (err)
1502 goto err_req_irq;
1503
1504 /* From here on the code is the same as e1000_up() */
1505 clear_bit(__E1000_DOWN, &adapter->flags);
1506
Herbert Xu47313052007-05-29 15:07:31 -07001507#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001508 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001509#endif
1510
Auke Koke0aac5a2007-03-06 08:57:21 -08001511 e1000_irq_enable(adapter);
1512
1513 /* fire a link status change interrupt to start the watchdog */
1514 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
1515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 return E1000_SUCCESS;
1517
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001518err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001519 e1000_release_hw_control(adapter);
1520 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001521 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001523 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524err_setup_tx:
1525 e1000_reset(adapter);
1526
1527 return err;
1528}
1529
1530/**
1531 * e1000_close - Disables a network interface
1532 * @netdev: network interface device structure
1533 *
1534 * Returns 0, this is not allowed to fail
1535 *
1536 * The close entry point is called when an interface is de-activated
1537 * by the OS. The hardware is still under the drivers control, but
1538 * needs to be disabled. A global MAC reset is issued to stop the
1539 * hardware, and all transmit and receive resources are freed.
1540 **/
1541
1542static int
1543e1000_close(struct net_device *netdev)
1544{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001545 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Auke Kok2db10a02006-06-27 09:06:28 -07001547 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001549 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001550 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001552 e1000_free_all_tx_resources(adapter);
1553 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Bruce Allan46665602006-09-27 12:54:08 -07001555 /* kill manageability vlan ID if supported, but not if a vlan with
1556 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001557 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001558 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1559 !(adapter->vlgrp &&
Dan Aloni5c15bde2007-03-02 20:44:51 -08001560 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001561 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1562 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001563
1564 /* If AMT is enabled, let the firmware know that the network
1565 * interface is now closed */
1566 if (adapter->hw.mac_type == e1000_82573 &&
1567 e1000_check_mng_mode(&adapter->hw))
1568 e1000_release_hw_control(adapter);
1569
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 return 0;
1571}
1572
1573/**
1574 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1575 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001576 * @start: address of beginning of memory
1577 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 **/
Auke Koke619d522006-04-14 19:04:52 -07001579static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580e1000_check_64k_bound(struct e1000_adapter *adapter,
1581 void *start, unsigned long len)
1582{
1583 unsigned long begin = (unsigned long) start;
1584 unsigned long end = begin + len;
1585
Malli Chilakala26483452005-04-28 19:44:46 -07001586 /* First rev 82545 and 82546 need to not allow any memory
1587 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001589 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1591 }
1592
1593 return TRUE;
1594}
1595
1596/**
1597 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1598 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001599 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 *
1601 * Return 0 on success, negative on failure
1602 **/
1603
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001604static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001605e1000_setup_tx_resources(struct e1000_adapter *adapter,
1606 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 struct pci_dev *pdev = adapter->pdev;
1609 int size;
1610
1611 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001612 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001613 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001614 DPRINTK(PROBE, ERR,
1615 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 return -ENOMEM;
1617 }
1618 memset(txdr->buffer_info, 0, size);
1619
1620 /* round up to nearest 4K */
1621
1622 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001623 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001626 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001629 DPRINTK(PROBE, ERR,
1630 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 return -ENOMEM;
1632 }
1633
Malli Chilakala26483452005-04-28 19:44:46 -07001634 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1636 void *olddesc = txdr->desc;
1637 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001638 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1639 "at %p\n", txdr->size, txdr->desc);
1640 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001642 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001643 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1645 goto setup_tx_desc_die;
1646 }
1647
1648 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1649 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001650 pci_free_consistent(pdev, txdr->size, txdr->desc,
1651 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1653 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001654 "Unable to allocate aligned memory "
1655 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 vfree(txdr->buffer_info);
1657 return -ENOMEM;
1658 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001659 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1661 }
1662 }
1663 memset(txdr->desc, 0, txdr->size);
1664
1665 txdr->next_to_use = 0;
1666 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001667 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 return 0;
1670}
1671
1672/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001673 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1674 * (Descriptors) for all queues
1675 * @adapter: board private structure
1676 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001677 * Return 0 on success, negative on failure
1678 **/
1679
1680int
1681e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1682{
1683 int i, err = 0;
1684
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001685 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001686 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1687 if (err) {
1688 DPRINTK(PROBE, ERR,
1689 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001690 for (i-- ; i >= 0; i--)
1691 e1000_free_tx_resources(adapter,
1692 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001693 break;
1694 }
1695 }
1696
1697 return err;
1698}
1699
1700/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1702 * @adapter: board private structure
1703 *
1704 * Configure the Tx unit of the MAC after a reset.
1705 **/
1706
1707static void
1708e1000_configure_tx(struct e1000_adapter *adapter)
1709{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001710 uint64_t tdba;
1711 struct e1000_hw *hw = &adapter->hw;
1712 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001713 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
1715 /* Setup the HW Tx Head and Tail descriptor pointers */
1716
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001717 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001718 case 1:
1719 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001720 tdba = adapter->tx_ring[0].dma;
1721 tdlen = adapter->tx_ring[0].count *
1722 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001723 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001724 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1725 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001726 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001727 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001728 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1729 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001730 break;
1731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 /* Set the default values for the Tx Inter Packet Gap timer */
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001734 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1735 (hw->media_type == e1000_media_type_fiber ||
1736 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001737 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1738 else
1739 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1740
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001741 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 case e1000_82542_rev2_0:
1743 case e1000_82542_rev2_1:
1744 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001745 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1746 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001748 case e1000_80003es2lan:
1749 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1750 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1751 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001753 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1754 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1755 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001757 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1758 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001759 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761 /* Set the Tx Interrupt Delay register */
1762
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001763 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1764 if (hw->mac_type >= e1000_82540)
1765 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
1767 /* Program the Transmit Control Register */
1768
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001769 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001771 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1773
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001774 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1775 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001776 /* set the speed mode bit, we'll clear it if we're not at
1777 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001778 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001779 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001780 } else if (hw->mac_type == e1000_80003es2lan) {
1781 tarc = E1000_READ_REG(hw, TARC0);
1782 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001783 E1000_WRITE_REG(hw, TARC0, tarc);
1784 tarc = E1000_READ_REG(hw, TARC1);
1785 tarc |= 1;
1786 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001787 }
1788
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001789 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
1791 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001792 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1793
1794 /* only set IDE if we are delaying interrupts using the timers */
1795 if (adapter->tx_int_delay)
1796 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001798 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1800 else
1801 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1802
1803 /* Cache if we're 82544 running in PCI-X because we'll
1804 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001805 if (hw->mac_type == e1000_82544 &&
1806 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001808
1809 E1000_WRITE_REG(hw, TCTL, tctl);
1810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811}
1812
1813/**
1814 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1815 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001816 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 *
1818 * Returns 0 on success, negative on failure
1819 **/
1820
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001821static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001822e1000_setup_rx_resources(struct e1000_adapter *adapter,
1823 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001826 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
1828 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001829 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001830 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001831 DPRINTK(PROBE, ERR,
1832 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 return -ENOMEM;
1834 }
1835 memset(rxdr->buffer_info, 0, size);
1836
Yan Burman1c7e5b12007-03-06 08:58:04 -08001837 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1838 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001839 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001840 vfree(rxdr->buffer_info);
1841 DPRINTK(PROBE, ERR,
1842 "Unable to allocate memory for the receive descriptor ring\n");
1843 return -ENOMEM;
1844 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001845
Yan Burman1c7e5b12007-03-06 08:58:04 -08001846 rxdr->ps_page_dma = kcalloc(rxdr->count,
1847 sizeof(struct e1000_ps_page_dma),
1848 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001849 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001850 vfree(rxdr->buffer_info);
1851 kfree(rxdr->ps_page);
1852 DPRINTK(PROBE, ERR,
1853 "Unable to allocate memory for the receive descriptor ring\n");
1854 return -ENOMEM;
1855 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001856
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001857 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001858 desc_len = sizeof(struct e1000_rx_desc);
1859 else
1860 desc_len = sizeof(union e1000_rx_desc_packet_split);
1861
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 /* Round up to nearest 4K */
1863
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001864 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001865 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
1867 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1868
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001869 if (!rxdr->desc) {
1870 DPRINTK(PROBE, ERR,
1871 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001874 kfree(rxdr->ps_page);
1875 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 return -ENOMEM;
1877 }
1878
Malli Chilakala26483452005-04-28 19:44:46 -07001879 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1881 void *olddesc = rxdr->desc;
1882 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001883 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1884 "at %p\n", rxdr->size, rxdr->desc);
1885 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001887 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001888 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001890 DPRINTK(PROBE, ERR,
1891 "Unable to allocate memory "
1892 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 goto setup_rx_desc_die;
1894 }
1895
1896 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1897 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001898 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1899 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001901 DPRINTK(PROBE, ERR,
1902 "Unable to allocate aligned memory "
1903 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001904 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001906 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1908 }
1909 }
1910 memset(rxdr->desc, 0, rxdr->size);
1911
1912 rxdr->next_to_clean = 0;
1913 rxdr->next_to_use = 0;
1914
1915 return 0;
1916}
1917
1918/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001919 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1920 * (Descriptors) for all queues
1921 * @adapter: board private structure
1922 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001923 * Return 0 on success, negative on failure
1924 **/
1925
1926int
1927e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1928{
1929 int i, err = 0;
1930
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001931 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001932 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1933 if (err) {
1934 DPRINTK(PROBE, ERR,
1935 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001936 for (i-- ; i >= 0; i--)
1937 e1000_free_rx_resources(adapter,
1938 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001939 break;
1940 }
1941 }
1942
1943 return err;
1944}
1945
1946/**
Malli Chilakala26483452005-04-28 19:44:46 -07001947 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 * @adapter: Board private structure
1949 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001950#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1951 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952static void
1953e1000_setup_rctl(struct e1000_adapter *adapter)
1954{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001955 uint32_t rctl, rfctl;
1956 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001957#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001958 uint32_t pages = 0;
1959#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
1961 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1962
1963 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1964
1965 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1966 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1967 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1968
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001969 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 rctl |= E1000_RCTL_SBP;
1971 else
1972 rctl &= ~E1000_RCTL_SBP;
1973
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001974 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1975 rctl &= ~E1000_RCTL_LPE;
1976 else
1977 rctl |= E1000_RCTL_LPE;
1978
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001980 rctl &= ~E1000_RCTL_SZ_4096;
1981 rctl |= E1000_RCTL_BSEX;
1982 switch (adapter->rx_buffer_len) {
1983 case E1000_RXBUFFER_256:
1984 rctl |= E1000_RCTL_SZ_256;
1985 rctl &= ~E1000_RCTL_BSEX;
1986 break;
1987 case E1000_RXBUFFER_512:
1988 rctl |= E1000_RCTL_SZ_512;
1989 rctl &= ~E1000_RCTL_BSEX;
1990 break;
1991 case E1000_RXBUFFER_1024:
1992 rctl |= E1000_RCTL_SZ_1024;
1993 rctl &= ~E1000_RCTL_BSEX;
1994 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001995 case E1000_RXBUFFER_2048:
1996 default:
1997 rctl |= E1000_RCTL_SZ_2048;
1998 rctl &= ~E1000_RCTL_BSEX;
1999 break;
2000 case E1000_RXBUFFER_4096:
2001 rctl |= E1000_RCTL_SZ_4096;
2002 break;
2003 case E1000_RXBUFFER_8192:
2004 rctl |= E1000_RCTL_SZ_8192;
2005 break;
2006 case E1000_RXBUFFER_16384:
2007 rctl |= E1000_RCTL_SZ_16384;
2008 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002009 }
2010
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08002011#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002012 /* 82571 and greater support packet-split where the protocol
2013 * header is placed in skb->data and the packet data is
2014 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2015 * In the case of a non-split, skb->data is linearly filled,
2016 * followed by the page buffers. Therefore, skb->data is
2017 * sized to hold the largest protocol header.
2018 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07002019 /* allocations using alloc_page take too long for regular MTU
2020 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002021 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07002022 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
2023 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002024 adapter->rx_ps_pages = pages;
2025 else
2026 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002027#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002028 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002029 /* Configure extra packet-split registers */
2030 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
2031 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08002032 /* disable packet split support for IPv6 extension headers,
2033 * because some malformed IPv6 headers can hang the RX */
2034 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2035 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2036
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002037 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
2038
Auke Kok7dfee0c2006-06-27 09:07:50 -07002039 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002040
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002041 psrctl |= adapter->rx_ps_bsize0 >>
2042 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002043
2044 switch (adapter->rx_ps_pages) {
2045 case 3:
2046 psrctl |= PAGE_SIZE <<
2047 E1000_PSRCTL_BSIZE3_SHIFT;
2048 case 2:
2049 psrctl |= PAGE_SIZE <<
2050 E1000_PSRCTL_BSIZE2_SHIFT;
2051 case 1:
2052 psrctl |= PAGE_SIZE >>
2053 E1000_PSRCTL_BSIZE1_SHIFT;
2054 break;
2055 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002056
2057 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 }
2059
2060 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2061}
2062
2063/**
2064 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2065 * @adapter: board private structure
2066 *
2067 * Configure the Rx unit of the MAC after a reset.
2068 **/
2069
2070static void
2071e1000_configure_rx(struct e1000_adapter *adapter)
2072{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002073 uint64_t rdba;
2074 struct e1000_hw *hw = &adapter->hw;
2075 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002076
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002077 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002078 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002079 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002080 sizeof(union e1000_rx_desc_packet_split);
2081 adapter->clean_rx = e1000_clean_rx_irq_ps;
2082 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2083 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002084 rdlen = adapter->rx_ring[0].count *
2085 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002086 adapter->clean_rx = e1000_clean_rx_irq;
2087 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
2090 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002091 rctl = E1000_READ_REG(hw, RCTL);
2092 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
2094 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002095 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002097 if (hw->mac_type >= e1000_82540) {
2098 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002099 if (adapter->itr_setting != 0)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002100 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 1000000000 / (adapter->itr * 256));
2102 }
2103
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002104 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002105 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002106 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002107 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002108#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002109 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002110 ctrl_ext |= E1000_CTRL_EXT_IAME;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002111 E1000_WRITE_REG(hw, IAM, 0xffffffff);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002112#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002113 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2114 E1000_WRITE_FLUSH(hw);
2115 }
2116
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002117 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2118 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002119 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002120 case 1:
2121 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002122 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002123 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07002124 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
2125 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002126 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002127 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002128 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2129 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002130 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002131 }
2132
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002134 if (hw->mac_type >= e1000_82543) {
2135 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002136 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002137 rxcsum |= E1000_RXCSUM_TUOFL;
2138
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002139 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002140 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002141 if ((hw->mac_type >= e1000_82571) &&
2142 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002143 rxcsum |= E1000_RXCSUM_IPPCSE;
2144 }
2145 } else {
2146 rxcsum &= ~E1000_RXCSUM_TUOFL;
2147 /* don't need to clear IPPCSE as it defaults to 0 */
2148 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002149 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 }
2151
Auke Kok21c4d5e2006-11-01 08:47:39 -08002152 /* enable early receives on 82573, only takes effect if using > 2048
2153 * byte total frame size. for example only for jumbo frames */
2154#define E1000_ERT_2048 0x100
2155 if (hw->mac_type == e1000_82573)
2156 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
2157
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002159 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160}
2161
2162/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002163 * e1000_free_tx_resources - Free Tx Resources per Queue
2164 * @adapter: board private structure
2165 * @tx_ring: Tx descriptor ring for a specific queue
2166 *
2167 * Free all transmit software resources
2168 **/
2169
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002170static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002171e1000_free_tx_resources(struct e1000_adapter *adapter,
2172 struct e1000_tx_ring *tx_ring)
2173{
2174 struct pci_dev *pdev = adapter->pdev;
2175
2176 e1000_clean_tx_ring(adapter, tx_ring);
2177
2178 vfree(tx_ring->buffer_info);
2179 tx_ring->buffer_info = NULL;
2180
2181 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2182
2183 tx_ring->desc = NULL;
2184}
2185
2186/**
2187 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 * @adapter: board private structure
2189 *
2190 * Free all transmit software resources
2191 **/
2192
2193void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002194e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002196 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002198 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002199 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
Auke Koke619d522006-04-14 19:04:52 -07002202static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2204 struct e1000_buffer *buffer_info)
2205{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002206 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07002207 pci_unmap_page(adapter->pdev,
2208 buffer_info->dma,
2209 buffer_info->length,
2210 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002211 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002213 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002215 buffer_info->skb = NULL;
2216 }
2217 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218}
2219
2220/**
2221 * e1000_clean_tx_ring - Free Tx Buffers
2222 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002223 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 **/
2225
2226static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002227e1000_clean_tx_ring(struct e1000_adapter *adapter,
2228 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 struct e1000_buffer *buffer_info;
2231 unsigned long size;
2232 unsigned int i;
2233
2234 /* Free all the Tx ring sk_buffs */
2235
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002236 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 buffer_info = &tx_ring->buffer_info[i];
2238 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2239 }
2240
2241 size = sizeof(struct e1000_buffer) * tx_ring->count;
2242 memset(tx_ring->buffer_info, 0, size);
2243
2244 /* Zero out the descriptor ring */
2245
2246 memset(tx_ring->desc, 0, tx_ring->size);
2247
2248 tx_ring->next_to_use = 0;
2249 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002250 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002252 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2253 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2254}
2255
2256/**
2257 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2258 * @adapter: board private structure
2259 **/
2260
2261static void
2262e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2263{
2264 int i;
2265
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002266 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002267 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268}
2269
2270/**
2271 * e1000_free_rx_resources - Free Rx Resources
2272 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002273 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 *
2275 * Free all receive software resources
2276 **/
2277
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002278static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002279e1000_free_rx_resources(struct e1000_adapter *adapter,
2280 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 struct pci_dev *pdev = adapter->pdev;
2283
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002284 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
2286 vfree(rx_ring->buffer_info);
2287 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002288 kfree(rx_ring->ps_page);
2289 rx_ring->ps_page = NULL;
2290 kfree(rx_ring->ps_page_dma);
2291 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
2293 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2294
2295 rx_ring->desc = NULL;
2296}
2297
2298/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002299 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002301 *
2302 * Free all receive software resources
2303 **/
2304
2305void
2306e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2307{
2308 int i;
2309
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002310 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002311 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2312}
2313
2314/**
2315 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2316 * @adapter: board private structure
2317 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 **/
2319
2320static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002321e1000_clean_rx_ring(struct e1000_adapter *adapter,
2322 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002325 struct e1000_ps_page *ps_page;
2326 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 struct pci_dev *pdev = adapter->pdev;
2328 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002329 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002332 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002334 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 pci_unmap_single(pdev,
2336 buffer_info->dma,
2337 buffer_info->length,
2338 PCI_DMA_FROMDEVICE);
2339
2340 dev_kfree_skb(buffer_info->skb);
2341 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002342 }
2343 ps_page = &rx_ring->ps_page[i];
2344 ps_page_dma = &rx_ring->ps_page_dma[i];
2345 for (j = 0; j < adapter->rx_ps_pages; j++) {
2346 if (!ps_page->ps_page[j]) break;
2347 pci_unmap_page(pdev,
2348 ps_page_dma->ps_page_dma[j],
2349 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2350 ps_page_dma->ps_page_dma[j] = 0;
2351 put_page(ps_page->ps_page[j]);
2352 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 }
2354 }
2355
2356 size = sizeof(struct e1000_buffer) * rx_ring->count;
2357 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002358 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2359 memset(rx_ring->ps_page, 0, size);
2360 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2361 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
2363 /* Zero out the descriptor ring */
2364
2365 memset(rx_ring->desc, 0, rx_ring->size);
2366
2367 rx_ring->next_to_clean = 0;
2368 rx_ring->next_to_use = 0;
2369
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002370 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2371 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2372}
2373
2374/**
2375 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2376 * @adapter: board private structure
2377 **/
2378
2379static void
2380e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2381{
2382 int i;
2383
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002384 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002385 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386}
2387
2388/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2389 * and memory write and invalidate disabled for certain operations
2390 */
2391static void
2392e1000_enter_82542_rst(struct e1000_adapter *adapter)
2393{
2394 struct net_device *netdev = adapter->netdev;
2395 uint32_t rctl;
2396
2397 e1000_pci_clear_mwi(&adapter->hw);
2398
2399 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2400 rctl |= E1000_RCTL_RST;
2401 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2402 E1000_WRITE_FLUSH(&adapter->hw);
2403 mdelay(5);
2404
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002405 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002406 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407}
2408
2409static void
2410e1000_leave_82542_rst(struct e1000_adapter *adapter)
2411{
2412 struct net_device *netdev = adapter->netdev;
2413 uint32_t rctl;
2414
2415 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2416 rctl &= ~E1000_RCTL_RST;
2417 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2418 E1000_WRITE_FLUSH(&adapter->hw);
2419 mdelay(5);
2420
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002421 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 e1000_pci_set_mwi(&adapter->hw);
2423
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002424 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002425 /* No need to loop, because 82542 supports only 1 queue */
2426 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002427 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002428 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 }
2430}
2431
2432/**
2433 * e1000_set_mac - Change the Ethernet Address of the NIC
2434 * @netdev: network interface device structure
2435 * @p: pointer to an address structure
2436 *
2437 * Returns 0 on success, negative on failure
2438 **/
2439
2440static int
2441e1000_set_mac(struct net_device *netdev, void *p)
2442{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002443 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 struct sockaddr *addr = p;
2445
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002446 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 return -EADDRNOTAVAIL;
2448
2449 /* 82542 2.0 needs to be in reset to write receive address registers */
2450
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002451 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 e1000_enter_82542_rst(adapter);
2453
2454 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2455 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2456
2457 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2458
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002459 /* With 82571 controllers, LAA may be overwritten (with the default)
2460 * due to controller reset from the other port. */
2461 if (adapter->hw.mac_type == e1000_82571) {
2462 /* activate the work around */
2463 adapter->hw.laa_is_present = 1;
2464
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002465 /* Hold a copy of the LAA in RAR[14] This is done so that
2466 * between the time RAR[0] gets clobbered and the time it
2467 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002468 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002469 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002470 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002471 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002472 E1000_RAR_ENTRIES - 1);
2473 }
2474
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002475 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 e1000_leave_82542_rst(adapter);
2477
2478 return 0;
2479}
2480
2481/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002482 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 * @netdev: network interface device structure
2484 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002485 * The set_rx_mode entry point is called whenever the unicast or multicast
2486 * address lists or the network interface flags are updated. This routine is
2487 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 * promiscuous mode, and all-multi behavior.
2489 **/
2490
2491static void
Patrick McHardydb0ce502007-11-13 20:54:59 -08002492e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002494 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 struct e1000_hw *hw = &adapter->hw;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002496 struct dev_addr_list *uc_ptr;
2497 struct dev_addr_list *mc_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 uint32_t rctl;
2499 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002500 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002501 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2502 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2503 E1000_NUM_MTA_REGISTERS;
2504
2505 if (adapter->hw.mac_type == e1000_ich8lan)
2506 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002508 /* reserve RAR[14] for LAA over-write work-around */
2509 if (adapter->hw.mac_type == e1000_82571)
2510 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
Malli Chilakala26483452005-04-28 19:44:46 -07002512 /* Check for Promiscuous and All Multicast modes */
2513
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 rctl = E1000_READ_REG(hw, RCTL);
2515
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002516 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002518 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 rctl |= E1000_RCTL_MPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 } else {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002521 rctl &= ~E1000_RCTL_MPE;
2522 }
2523
2524 uc_ptr = NULL;
2525 if (netdev->uc_count > rar_entries - 1) {
2526 rctl |= E1000_RCTL_UPE;
2527 } else if (!(netdev->flags & IFF_PROMISC)) {
2528 rctl &= ~E1000_RCTL_UPE;
2529 uc_ptr = netdev->uc_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 }
2531
2532 E1000_WRITE_REG(hw, RCTL, rctl);
2533
2534 /* 82542 2.0 needs to be in reset to write receive address registers */
2535
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002536 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 e1000_enter_82542_rst(adapter);
2538
Patrick McHardydb0ce502007-11-13 20:54:59 -08002539 /* load the first 14 addresses into the exact filters 1-14. Unicast
2540 * addresses take precedence to avoid disabling unicast filtering
2541 * when possible.
2542 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 * RAR 0 is used for the station MAC adddress
2544 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002545 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 */
2547 mc_ptr = netdev->mc_list;
2548
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002549 for (i = 1; i < rar_entries; i++) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002550 if (uc_ptr) {
2551 e1000_rar_set(hw, uc_ptr->da_addr, i);
2552 uc_ptr = uc_ptr->next;
2553 } else if (mc_ptr) {
2554 e1000_rar_set(hw, mc_ptr->da_addr, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 mc_ptr = mc_ptr->next;
2556 } else {
2557 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002558 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002560 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 }
2562 }
Patrick McHardydb0ce502007-11-13 20:54:59 -08002563 WARN_ON(uc_ptr != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
2565 /* clear the old settings from the multicast hash table */
2566
Auke Kokcd94dd02006-06-27 09:08:22 -07002567 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002569 E1000_WRITE_FLUSH(hw);
2570 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571
2572 /* load any remaining addresses into the hash table */
2573
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002574 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002575 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 e1000_mta_set(hw, hash_value);
2577 }
2578
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002579 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581}
2582
2583/* Need to wait a few seconds after link up to get diagnostic information from
2584 * the phy */
2585
2586static void
2587e1000_update_phy_info(unsigned long data)
2588{
2589 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2590 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2591}
2592
2593/**
2594 * e1000_82547_tx_fifo_stall - Timer Call-back
2595 * @data: pointer to adapter cast into an unsigned long
2596 **/
2597
2598static void
2599e1000_82547_tx_fifo_stall(unsigned long data)
2600{
2601 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2602 struct net_device *netdev = adapter->netdev;
2603 uint32_t tctl;
2604
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002605 if (atomic_read(&adapter->tx_fifo_stall)) {
2606 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 E1000_READ_REG(&adapter->hw, TDH)) &&
2608 (E1000_READ_REG(&adapter->hw, TDFT) ==
2609 E1000_READ_REG(&adapter->hw, TDFH)) &&
2610 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2611 E1000_READ_REG(&adapter->hw, TDFHS))) {
2612 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2613 E1000_WRITE_REG(&adapter->hw, TCTL,
2614 tctl & ~E1000_TCTL_EN);
2615 E1000_WRITE_REG(&adapter->hw, TDFT,
2616 adapter->tx_head_addr);
2617 E1000_WRITE_REG(&adapter->hw, TDFH,
2618 adapter->tx_head_addr);
2619 E1000_WRITE_REG(&adapter->hw, TDFTS,
2620 adapter->tx_head_addr);
2621 E1000_WRITE_REG(&adapter->hw, TDFHS,
2622 adapter->tx_head_addr);
2623 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2624 E1000_WRITE_FLUSH(&adapter->hw);
2625
2626 adapter->tx_fifo_head = 0;
2627 atomic_set(&adapter->tx_fifo_stall, 0);
2628 netif_wake_queue(netdev);
2629 } else {
2630 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2631 }
2632 }
2633}
2634
2635/**
2636 * e1000_watchdog - Timer Call-back
2637 * @data: pointer to adapter cast into an unsigned long
2638 **/
2639static void
2640e1000_watchdog(unsigned long data)
2641{
2642 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002644 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002645 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002646 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Auke Kokcd94dd02006-06-27 09:08:22 -07002648 ret_val = e1000_check_for_link(&adapter->hw);
2649 if ((ret_val == E1000_ERR_PHY) &&
2650 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2651 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2652 /* See e1000_kumeran_lock_loss_workaround() */
2653 DPRINTK(LINK, INFO,
2654 "Gigabit has been disabled, downgrading speed\n");
2655 }
Auke Kok90fb5132006-11-01 08:47:30 -08002656
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002657 if (adapter->hw.mac_type == e1000_82573) {
2658 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002659 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002660 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002663 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2665 link = !adapter->hw.serdes_link_down;
2666 else
2667 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2668
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002669 if (link) {
2670 if (!netif_carrier_ok(netdev)) {
Auke Kok9669f532007-01-18 09:25:26 -08002671 uint32_t ctrl;
Auke Kokfe7fe282006-04-14 19:04:59 -07002672 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 e1000_get_speed_and_duplex(&adapter->hw,
2674 &adapter->link_speed,
2675 &adapter->link_duplex);
2676
Auke Kok9669f532007-01-18 09:25:26 -08002677 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
2678 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2679 "Flow Control: %s\n",
2680 adapter->link_speed,
2681 adapter->link_duplex == FULL_DUPLEX ?
2682 "Full Duplex" : "Half Duplex",
2683 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2684 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2685 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2686 E1000_CTRL_TFCE) ? "TX" : "None" )));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002688 /* tweak tx_queue_len according to speed/duplex
2689 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002690 netdev->tx_queue_len = adapter->tx_queue_len;
2691 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002692 switch (adapter->link_speed) {
2693 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002694 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002695 netdev->tx_queue_len = 10;
2696 adapter->tx_timeout_factor = 8;
2697 break;
2698 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002699 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002700 netdev->tx_queue_len = 100;
2701 /* maybe add some timeout factor ? */
2702 break;
2703 }
2704
Auke Kokfe7fe282006-04-14 19:04:59 -07002705 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002706 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002707 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002708 uint32_t tarc0;
2709 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002710 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002711 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2712 }
Auke Kok90fb5132006-11-01 08:47:30 -08002713
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002714 /* disable TSO for pcie and 10/100 speeds, to avoid
2715 * some hardware issues */
2716 if (!adapter->tso_force &&
2717 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002718 switch (adapter->link_speed) {
2719 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002720 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002721 DPRINTK(PROBE,INFO,
2722 "10/100 speed: disabling TSO\n");
2723 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002724 netdev->features &= ~NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002725 break;
2726 case SPEED_1000:
2727 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002728 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002729 break;
2730 default:
2731 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002732 break;
2733 }
2734 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002735
2736 /* enable transmits in the hardware, need to do this
2737 * after setting TARC0 */
2738 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2739 tctl |= E1000_TCTL_EN;
2740 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002741
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 netif_carrier_on(netdev);
2743 netif_wake_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002744 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002746 } else {
2747 /* make sure the receive unit is started */
2748 if (adapter->hw.rx_needs_kicking) {
2749 struct e1000_hw *hw = &adapter->hw;
2750 uint32_t rctl = E1000_READ_REG(hw, RCTL);
2751 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 }
2754 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002755 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 adapter->link_speed = 0;
2757 adapter->link_duplex = 0;
2758 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2759 netif_carrier_off(netdev);
2760 netif_stop_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002761 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Jeff Kirsher87041632006-03-02 18:21:24 -08002762
2763 /* 80003ES2LAN workaround--
2764 * For packet buffer work-around on link down event;
2765 * disable receives in the ISR and
2766 * reset device here in the watchdog
2767 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002768 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002769 /* reset device */
2770 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 }
2772
2773 e1000_smartspeed(adapter);
2774 }
2775
2776 e1000_update_stats(adapter);
2777
2778 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2779 adapter->tpt_old = adapter->stats.tpt;
2780 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2781 adapter->colc_old = adapter->stats.colc;
2782
2783 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2784 adapter->gorcl_old = adapter->stats.gorcl;
2785 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2786 adapter->gotcl_old = adapter->stats.gotcl;
2787
2788 e1000_update_adaptive(&adapter->hw);
2789
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002790 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002791 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 /* We've lost link, so the controller stops DMA,
2793 * but we've got queued Tx work that's never going
2794 * to get done, so reset controller to flush Tx.
2795 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002796 adapter->tx_timeout_count++;
2797 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 }
2799 }
2800
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 /* Cause software interrupt to ensure rx ring is cleaned */
2802 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2803
Malli Chilakala26483452005-04-28 19:44:46 -07002804 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 adapter->detect_tx_hung = TRUE;
2806
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002807 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002808 * reset from the other port. Set the appropriate LAA in RAR[0] */
2809 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2810 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2811
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 /* Reset the timer */
Arjan van de Ven56e13932007-03-06 02:41:48 -08002813 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814}
2815
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002816enum latency_range {
2817 lowest_latency = 0,
2818 low_latency = 1,
2819 bulk_latency = 2,
2820 latency_invalid = 255
2821};
2822
2823/**
2824 * e1000_update_itr - update the dynamic ITR value based on statistics
2825 * Stores a new ITR value based on packets and byte
2826 * counts during the last interrupt. The advantage of per interrupt
2827 * computation is faster updates and more accurate ITR for the current
2828 * traffic pattern. Constants in this function were computed
2829 * based on theoretical maximum wire speed and thresholds were set based
2830 * on testing data as well as attempting to minimize response time
2831 * while increasing bulk throughput.
2832 * this functionality is controlled by the InterruptThrottleRate module
2833 * parameter (see e1000_param.c)
2834 * @adapter: pointer to adapter
2835 * @itr_setting: current adapter->itr
2836 * @packets: the number of packets during this measurement interval
2837 * @bytes: the number of bytes during this measurement interval
2838 **/
2839static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2840 uint16_t itr_setting,
2841 int packets,
2842 int bytes)
2843{
2844 unsigned int retval = itr_setting;
2845 struct e1000_hw *hw = &adapter->hw;
2846
2847 if (unlikely(hw->mac_type < e1000_82540))
2848 goto update_itr_done;
2849
2850 if (packets == 0)
2851 goto update_itr_done;
2852
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002853 switch (itr_setting) {
2854 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002855 /* jumbo frames get bulk treatment*/
2856 if (bytes/packets > 8000)
2857 retval = bulk_latency;
2858 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002859 retval = low_latency;
2860 break;
2861 case low_latency: /* 50 usec aka 20000 ints/s */
2862 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002863 /* jumbo frames need bulk latency setting */
2864 if (bytes/packets > 8000)
2865 retval = bulk_latency;
2866 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002867 retval = bulk_latency;
2868 else if ((packets > 35))
2869 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002870 } else if (bytes/packets > 2000)
2871 retval = bulk_latency;
2872 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002873 retval = lowest_latency;
2874 break;
2875 case bulk_latency: /* 250 usec aka 4000 ints/s */
2876 if (bytes > 25000) {
2877 if (packets > 35)
2878 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002879 } else if (bytes < 6000) {
2880 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002881 }
2882 break;
2883 }
2884
2885update_itr_done:
2886 return retval;
2887}
2888
2889static void e1000_set_itr(struct e1000_adapter *adapter)
2890{
2891 struct e1000_hw *hw = &adapter->hw;
2892 uint16_t current_itr;
2893 uint32_t new_itr = adapter->itr;
2894
2895 if (unlikely(hw->mac_type < e1000_82540))
2896 return;
2897
2898 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2899 if (unlikely(adapter->link_speed != SPEED_1000)) {
2900 current_itr = 0;
2901 new_itr = 4000;
2902 goto set_itr_now;
2903 }
2904
2905 adapter->tx_itr = e1000_update_itr(adapter,
2906 adapter->tx_itr,
2907 adapter->total_tx_packets,
2908 adapter->total_tx_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->tx_itr == lowest_latency)
2911 adapter->tx_itr = low_latency;
2912
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002913 adapter->rx_itr = e1000_update_itr(adapter,
2914 adapter->rx_itr,
2915 adapter->total_rx_packets,
2916 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002917 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2918 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2919 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002920
2921 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2922
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002923 switch (current_itr) {
2924 /* counts and packets in update_itr are dependent on these numbers */
2925 case lowest_latency:
2926 new_itr = 70000;
2927 break;
2928 case low_latency:
2929 new_itr = 20000; /* aka hwitr = ~200 */
2930 break;
2931 case bulk_latency:
2932 new_itr = 4000;
2933 break;
2934 default:
2935 break;
2936 }
2937
2938set_itr_now:
2939 if (new_itr != adapter->itr) {
2940 /* this attempts to bias the interrupt rate towards Bulk
2941 * by adding intermediate steps when interrupt rate is
2942 * increasing */
2943 new_itr = new_itr > adapter->itr ?
2944 min(adapter->itr + (new_itr >> 2), new_itr) :
2945 new_itr;
2946 adapter->itr = new_itr;
2947 E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
2948 }
2949
2950 return;
2951}
2952
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953#define E1000_TX_FLAGS_CSUM 0x00000001
2954#define E1000_TX_FLAGS_VLAN 0x00000002
2955#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002956#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2958#define E1000_TX_FLAGS_VLAN_SHIFT 16
2959
Auke Koke619d522006-04-14 19:04:52 -07002960static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002961e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2962 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002965 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 unsigned int i;
2967 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002968 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2970 int err;
2971
Herbert Xu89114af2006-07-08 13:34:32 -07002972 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 if (skb_header_cloned(skb)) {
2974 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2975 if (err)
2976 return err;
2977 }
2978
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002979 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002980 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002981 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002982 struct iphdr *iph = ip_hdr(skb);
2983 iph->tot_len = 0;
2984 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002985 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2986 iph->daddr, 0,
2987 IPPROTO_TCP,
2988 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002989 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002990 ipcse = skb_transport_offset(skb) - 1;
Auke Koke15fdd02006-08-16 11:28:45 -07002991 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002992 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002993 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002994 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2995 &ipv6_hdr(skb)->daddr,
2996 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002997 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002998 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002999 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07003000 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07003001 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07003002 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 tucse = 0;
3004
3005 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003006 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003008 i = tx_ring->next_to_use;
3009 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003010 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
3012 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3013 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3014 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3015 context_desc->upper_setup.tcp_fields.tucss = tucss;
3016 context_desc->upper_setup.tcp_fields.tucso = tucso;
3017 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3018 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3019 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3020 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3021
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003022 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003023 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003024
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003025 if (++i == tx_ring->count) i = 0;
3026 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027
Jeff Kirsher8241e352006-01-12 16:51:34 -08003028 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08003030 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031}
3032
Auke Koke619d522006-04-14 19:04:52 -07003033static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003034e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3035 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036{
3037 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003038 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 unsigned int i;
3040 uint8_t css;
3041
Patrick McHardy84fa7932006-08-29 16:44:56 -07003042 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07003043 css = skb_transport_offset(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003045 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003046 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003047 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048
Bruce Allanf6c57ba2007-01-18 09:25:28 -08003049 context_desc->lower_setup.ip_config = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 context_desc->upper_setup.tcp_fields.tucss = css;
Herbert Xu628592c2007-04-23 17:06:40 -07003051 context_desc->upper_setup.tcp_fields.tucso =
3052 css + skb->csum_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 context_desc->upper_setup.tcp_fields.tucse = 0;
3054 context_desc->tcp_seg_setup.data = 0;
3055 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
3056
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003057 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003058 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003059
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003060 if (unlikely(++i == tx_ring->count)) i = 0;
3061 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
3063 return TRUE;
3064 }
3065
3066 return FALSE;
3067}
3068
3069#define E1000_MAX_TXD_PWR 12
3070#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
3071
Auke Koke619d522006-04-14 19:04:52 -07003072static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003073e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3074 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
3075 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 struct e1000_buffer *buffer_info;
3078 unsigned int len = skb->len;
3079 unsigned int offset = 0, size, count = 0, i;
3080 unsigned int f;
3081 len -= skb->data_len;
3082
3083 i = tx_ring->next_to_use;
3084
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003085 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 buffer_info = &tx_ring->buffer_info[i];
3087 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05003088 /* Workaround for Controller erratum --
3089 * descriptor for non-tso packet in a linear SKB that follows a
3090 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003091 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05003092 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07003093 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05003094 tx_ring->last_tx_tso = 0;
3095 size -= 4;
3096 }
3097
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 /* Workaround for premature desc write-backs
3099 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003100 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07003102 /* work-around for errata 10 and it applies
3103 * to all controllers in PCI-X mode
3104 * The fix is to make sure that the first descriptor of a
3105 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3106 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003107 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003108 (size > 2015) && count == 0))
3109 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003110
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 /* Workaround for potential 82544 hang in PCI-X. Avoid
3112 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003113 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3115 size > 4))
3116 size -= 4;
3117
3118 buffer_info->length = size;
3119 buffer_info->dma =
3120 pci_map_single(adapter->pdev,
3121 skb->data + offset,
3122 size,
3123 PCI_DMA_TODEVICE);
3124 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003125 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
3127 len -= size;
3128 offset += size;
3129 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003130 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 }
3132
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003133 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 struct skb_frag_struct *frag;
3135
3136 frag = &skb_shinfo(skb)->frags[f];
3137 len = frag->size;
3138 offset = frag->page_offset;
3139
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003140 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 buffer_info = &tx_ring->buffer_info[i];
3142 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 /* Workaround for premature desc write-backs
3144 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003145 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 /* Workaround for potential 82544 hang in PCI-X.
3148 * Avoid terminating buffers within evenly-aligned
3149 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003150 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3152 size > 4))
3153 size -= 4;
3154
3155 buffer_info->length = size;
3156 buffer_info->dma =
3157 pci_map_page(adapter->pdev,
3158 frag->page,
3159 offset,
3160 size,
3161 PCI_DMA_TODEVICE);
3162 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003163 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
3165 len -= size;
3166 offset += size;
3167 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003168 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 }
3170 }
3171
3172 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3173 tx_ring->buffer_info[i].skb = skb;
3174 tx_ring->buffer_info[first].next_to_watch = i;
3175
3176 return count;
3177}
3178
Auke Koke619d522006-04-14 19:04:52 -07003179static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003180e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3181 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 struct e1000_tx_desc *tx_desc = NULL;
3184 struct e1000_buffer *buffer_info;
3185 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3186 unsigned int i;
3187
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003188 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3190 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003191 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3192
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003193 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003194 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 }
3196
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003197 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3199 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3200 }
3201
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003202 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 txd_lower |= E1000_TXD_CMD_VLE;
3204 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3205 }
3206
3207 i = tx_ring->next_to_use;
3208
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003209 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 buffer_info = &tx_ring->buffer_info[i];
3211 tx_desc = E1000_TX_DESC(*tx_ring, i);
3212 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3213 tx_desc->lower.data =
3214 cpu_to_le32(txd_lower | buffer_info->length);
3215 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003216 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 }
3218
3219 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3220
3221 /* Force memory writes to complete before letting h/w
3222 * know there are new descriptors to fetch. (Only
3223 * applicable for weak-ordered memory model archs,
3224 * such as IA-64). */
3225 wmb();
3226
3227 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003228 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003229 /* we need this if more than one processor can write to our tail
3230 * at a time, it syncronizes IO on IA64/Altix systems */
3231 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232}
3233
3234/**
3235 * 82547 workaround to avoid controller hang in half-duplex environment.
3236 * The workaround is to avoid queuing a large packet that would span
3237 * the internal Tx FIFO ring boundary by notifying the stack to resend
3238 * the packet at a later time. This gives the Tx FIFO an opportunity to
3239 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3240 * to the beginning of the Tx FIFO.
3241 **/
3242
3243#define E1000_FIFO_HDR 0x10
3244#define E1000_82547_PAD_LEN 0x3E0
3245
Auke Koke619d522006-04-14 19:04:52 -07003246static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
3248{
3249 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3250 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
3251
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003252 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003254 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 goto no_fifo_stall_required;
3256
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003257 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 return 1;
3259
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003260 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 atomic_set(&adapter->tx_fifo_stall, 1);
3262 return 1;
3263 }
3264
3265no_fifo_stall_required:
3266 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003267 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3269 return 0;
3270}
3271
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003272#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07003273static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003274e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
3275{
3276 struct e1000_hw *hw = &adapter->hw;
3277 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003278 if (vlan_tx_tag_present(skb)) {
3279 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003280 ( adapter->hw.mng_cookie.status &
3281 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3282 return 0;
3283 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003284 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003285 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003286 if ((htons(ETH_P_IP) == eth->h_proto)) {
3287 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003288 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003289 if (IPPROTO_UDP == ip->protocol) {
3290 struct udphdr *udp =
3291 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003292 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003293 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003294 offset = (uint8_t *)udp + 8 - skb->data;
3295 length = skb->len - offset;
3296
3297 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003298 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003299 length);
3300 }
3301 }
3302 }
3303 }
3304 return 0;
3305}
3306
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003307static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3308{
3309 struct e1000_adapter *adapter = netdev_priv(netdev);
3310 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3311
3312 netif_stop_queue(netdev);
3313 /* Herbert's original patch had:
3314 * smp_mb__after_netif_stop_queue();
3315 * but since that doesn't exist yet, just open code it. */
3316 smp_mb();
3317
3318 /* We need to check again in a case another CPU has just
3319 * made room available. */
3320 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3321 return -EBUSY;
3322
3323 /* A reprieve! */
3324 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003325 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003326 return 0;
3327}
3328
3329static int e1000_maybe_stop_tx(struct net_device *netdev,
3330 struct e1000_tx_ring *tx_ring, int size)
3331{
3332 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3333 return 0;
3334 return __e1000_maybe_stop_tx(netdev, size);
3335}
3336
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3338static int
3339e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3340{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003341 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003342 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3344 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3345 unsigned int tx_flags = 0;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003346 unsigned int len = skb->len - skb->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 unsigned long flags;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003348 unsigned int nr_frags;
3349 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003351 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 unsigned int f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003354 /* This goes back to the question of how to logically map a tx queue
3355 * to a flow. Right now, performance is impacted slightly negatively
3356 * if using multiple tx queues. If the stack breaks away from a
3357 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003358 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003359
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003360 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 dev_kfree_skb_any(skb);
3362 return NETDEV_TX_OK;
3363 }
3364
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003365 /* 82571 and newer doesn't need the workaround that limited descriptor
3366 * length to 4kB */
3367 if (adapter->hw.mac_type >= e1000_82571)
3368 max_per_txd = 8192;
3369
Herbert Xu79671682006-06-22 02:40:14 -07003370 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003371 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 * make sure there is enough room in the FIFO before
3373 * initiating the DMA for each buffer. The calc is:
3374 * 4 = ceil(buffer len/mss). To make sure we don't
3375 * overrun the FIFO, adjust the max buffer len if mss
3376 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003377 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003378 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 max_per_txd = min(mss << 2, max_per_txd);
3380 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003381
Auke Kok90fb5132006-11-01 08:47:30 -08003382 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3383 * points to just header, pull a few bytes of payload from
3384 * frags into skb->data */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003385 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003386 if (skb->data_len && hdr_len == len) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003387 switch (adapter->hw.mac_type) {
3388 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003389 case e1000_82544:
3390 /* Make sure we have room to chop off 4 bytes,
3391 * and that the end alignment will work out to
3392 * this hardware's requirements
3393 * NOTE: this is a TSO only workaround
3394 * if end byte alignment not correct move us
3395 * into the next dword */
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003396 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003397 break;
3398 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003399 case e1000_82571:
3400 case e1000_82572:
3401 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003402 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003403 pull_size = min((unsigned int)4, skb->data_len);
3404 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003405 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003406 "__pskb_pull_tail failed.\n");
3407 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003408 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003409 }
3410 len = skb->len - skb->data_len;
3411 break;
3412 default:
3413 /* do nothing */
3414 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003415 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 }
3418
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003419 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003420 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003422 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003423
Jeff Kirsherfd803242005-12-13 00:06:22 -05003424 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003425 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003426 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003427
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 count += TXD_USE_COUNT(len, max_txd_pwr);
3429
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003430 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 count++;
3432
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003433 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003434 * in PCI-X mode, so add one more descriptor to the count
3435 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003436 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003437 (len > 2015)))
3438 count++;
3439
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003441 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3443 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003444 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 count += nr_frags;
3446
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003447
3448 if (adapter->hw.tx_pkt_filtering &&
3449 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003450 e1000_transfer_dhcp_info(adapter, skb);
3451
Mark Huthf50393f2007-03-06 08:57:26 -08003452 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003453 /* Collision - tell upper layer to requeue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003454 return NETDEV_TX_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455
3456 /* need: count + 2 desc gap to keep tail from touching
3457 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003458 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
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
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003463 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3464 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003466 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003467 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468 return NETDEV_TX_BUSY;
3469 }
3470 }
3471
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003472 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 tx_flags |= E1000_TX_FLAGS_VLAN;
3474 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3475 }
3476
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003477 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003478
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003479 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 if (tso < 0) {
3481 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003482 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 return NETDEV_TX_OK;
3484 }
3485
Jeff Kirsherfd803242005-12-13 00:06:22 -05003486 if (likely(tso)) {
3487 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003489 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 tx_flags |= E1000_TX_FLAGS_CSUM;
3491
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003492 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003493 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003494 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003495 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003496 tx_flags |= E1000_TX_FLAGS_IPV4;
3497
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003498 e1000_tx_queue(adapter, tx_ring, tx_flags,
3499 e1000_tx_map(adapter, tx_ring, skb, first,
3500 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
3502 netdev->trans_start = jiffies;
3503
3504 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003505 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003507 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 return NETDEV_TX_OK;
3509}
3510
3511/**
3512 * e1000_tx_timeout - Respond to a Tx Hang
3513 * @netdev: network interface device structure
3514 **/
3515
3516static void
3517e1000_tx_timeout(struct net_device *netdev)
3518{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003519 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520
3521 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003522 adapter->tx_timeout_count++;
3523 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524}
3525
3526static void
David Howells65f27f32006-11-22 14:55:48 +00003527e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528{
David Howells65f27f32006-11-22 14:55:48 +00003529 struct e1000_adapter *adapter =
3530 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531
Auke Kok2db10a02006-06-27 09:06:28 -07003532 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533}
3534
3535/**
3536 * e1000_get_stats - Get System Network Statistics
3537 * @netdev: network interface device structure
3538 *
3539 * Returns the address of the device statistics structure.
3540 * The statistics are actually updated from the timer callback.
3541 **/
3542
3543static struct net_device_stats *
3544e1000_get_stats(struct net_device *netdev)
3545{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003546 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003548 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 return &adapter->net_stats;
3550}
3551
3552/**
3553 * e1000_change_mtu - Change the Maximum Transfer Unit
3554 * @netdev: network interface device structure
3555 * @new_mtu: new value for maximum frame size
3556 *
3557 * Returns 0 on success, negative on failure
3558 **/
3559
3560static int
3561e1000_change_mtu(struct net_device *netdev, int new_mtu)
3562{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003563 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003565 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003567 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3568 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3569 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003570 return -EINVAL;
3571 }
3572
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003573 /* Adapter-specific max frame size limits. */
3574 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003575 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003576 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003577 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3578 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003579 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003580 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003581 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003582 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003583 /* Jumbo Frames not supported if:
3584 * - this is not an 82573L device
3585 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003586 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3587 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003588 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3589 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003590 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3591 DPRINTK(PROBE, ERR,
3592 "Jumbo Frames not supported.\n");
3593 return -EINVAL;
3594 }
3595 break;
3596 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003597 /* ERT will be enabled later to enable wire speed receives */
3598
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003599 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003600 case e1000_82571:
3601 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003602 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003603#define MAX_STD_JUMBO_FRAME_SIZE 9234
3604 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3605 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3606 return -EINVAL;
3607 }
3608 break;
3609 default:
3610 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3611 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003612 }
3613
David S. Miller87f50322006-07-31 22:39:40 -07003614 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003615 * means we reserve 2 more, this pushes us to allocate from the next
3616 * larger slab size
3617 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003618
Auke Kok9e2feac2006-04-14 19:05:18 -07003619 if (max_frame <= E1000_RXBUFFER_256)
3620 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3621 else if (max_frame <= E1000_RXBUFFER_512)
3622 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3623 else if (max_frame <= E1000_RXBUFFER_1024)
3624 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3625 else if (max_frame <= E1000_RXBUFFER_2048)
3626 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3627 else if (max_frame <= E1000_RXBUFFER_4096)
3628 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3629 else if (max_frame <= E1000_RXBUFFER_8192)
3630 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3631 else if (max_frame <= E1000_RXBUFFER_16384)
3632 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3633
3634 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003635 if (!adapter->hw.tbi_compatibility_on &&
3636 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3637 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3638 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003639
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003640 netdev->mtu = new_mtu;
Bruce Allan83cd8272006-12-15 10:36:35 +01003641 adapter->hw.max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003642
Auke Kok2db10a02006-06-27 09:06:28 -07003643 if (netif_running(netdev))
3644 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 return 0;
3647}
3648
3649/**
3650 * e1000_update_stats - Update the board statistics counters
3651 * @adapter: board private structure
3652 **/
3653
3654void
3655e1000_update_stats(struct e1000_adapter *adapter)
3656{
3657 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003658 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 unsigned long flags;
3660 uint16_t phy_tmp;
3661
3662#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3663
Linas Vepstas282f33c2006-06-08 22:19:44 -07003664 /*
3665 * Prevent stats update while adapter is being reset, or if the pci
3666 * connection is down.
3667 */
Auke Kok90267292006-06-08 09:30:24 -07003668 if (adapter->link_speed == 0)
3669 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003670 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003671 return;
Auke Kok90267292006-06-08 09:30:24 -07003672
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 spin_lock_irqsave(&adapter->stats_lock, flags);
3674
Masatake YAMATO828d0552007-10-20 03:06:37 +02003675 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 * called from the interrupt context, so they must only
3677 * be written while holding adapter->stats_lock
3678 */
3679
3680 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3681 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3682 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3683 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3684 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3685 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3686 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003687
3688 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003689 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3690 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3691 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3692 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3693 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3694 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696
3697 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3698 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3699 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3700 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3701 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3702 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3703 adapter->stats.dc += E1000_READ_REG(hw, DC);
3704 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3705 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3706 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3707 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3708 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3709 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3710 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3711 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3712 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3713 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3714 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3715 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3716 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3717 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3718 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3719 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3720 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3721 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3722 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003723
3724 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003725 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3726 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3727 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3728 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3729 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3730 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003731 }
3732
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3734 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3735
3736 /* used for adaptive IFS */
3737
3738 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3739 adapter->stats.tpt += hw->tx_packet_delta;
3740 hw->collision_delta = E1000_READ_REG(hw, COLC);
3741 adapter->stats.colc += hw->collision_delta;
3742
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003743 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3745 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3746 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3747 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3748 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3749 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3750 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003751 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003752 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3753 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003754
3755 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003756 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3757 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3758 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3759 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3760 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3761 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3762 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003763 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765
3766 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 adapter->net_stats.multicast = adapter->stats.mprc;
3768 adapter->net_stats.collisions = adapter->stats.colc;
3769
3770 /* Rx Errors */
3771
Jeff Kirsher87041632006-03-02 18:21:24 -08003772 /* RLEC on some newer hardware can be incorrect so build
3773 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3775 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003776 adapter->stats.ruc + adapter->stats.roc +
3777 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003778 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3779 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3781 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3783
3784 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003785 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3786 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3788 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3789 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Jeff Garzik167fb282006-12-15 10:41:15 -05003790 if (adapter->hw.bad_tx_carr_stats_fd &&
3791 adapter->link_duplex == FULL_DUPLEX) {
3792 adapter->net_stats.tx_carrier_errors = 0;
3793 adapter->stats.tncrs = 0;
3794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
3796 /* Tx Dropped needs to be maintained elsewhere */
3797
3798 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003799 if (hw->media_type == e1000_media_type_copper) {
3800 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3802 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3803 adapter->phy_stats.idle_errors += phy_tmp;
3804 }
3805
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003806 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 (hw->phy_type == e1000_phy_m88) &&
3808 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3809 adapter->phy_stats.receive_errors += phy_tmp;
3810 }
3811
Jeff Garzik15e376b2006-12-15 11:16:33 -05003812 /* Management Stats */
3813 if (adapter->hw.has_smbus) {
3814 adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
3815 adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
3816 adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
3817 }
3818
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3820}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003821
3822/**
3823 * e1000_intr_msi - Interrupt Handler
3824 * @irq: interrupt number
3825 * @data: pointer to a network interface device structure
3826 **/
3827
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003828static irqreturn_t
3829e1000_intr_msi(int irq, void *data)
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003830{
3831 struct net_device *netdev = data;
3832 struct e1000_adapter *adapter = netdev_priv(netdev);
3833 struct e1000_hw *hw = &adapter->hw;
3834#ifndef CONFIG_E1000_NAPI
3835 int i;
3836#endif
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003837 uint32_t icr = E1000_READ_REG(hw, ICR);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003838
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003839#ifdef CONFIG_E1000_NAPI
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003840 /* read ICR disables interrupts using IAM, so keep up with our
3841 * enable/disable accounting */
3842 atomic_inc(&adapter->irq_sem);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003843#endif
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003844 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3845 hw->get_link_status = 1;
3846 /* 80003ES2LAN workaround-- For packet buffer work-around on
3847 * link down event; disable receives here in the ISR and reset
3848 * adapter in watchdog */
3849 if (netif_carrier_ok(netdev) &&
3850 (adapter->hw.mac_type == e1000_80003es2lan)) {
3851 /* disable receives */
3852 uint32_t rctl = E1000_READ_REG(hw, RCTL);
3853 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003854 }
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003855 /* guard against interrupt when we're going down */
3856 if (!test_bit(__E1000_DOWN, &adapter->flags))
3857 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003858 }
3859
3860#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003861 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003862 adapter->total_tx_bytes = 0;
3863 adapter->total_tx_packets = 0;
3864 adapter->total_rx_bytes = 0;
3865 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003866 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003867 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003868 e1000_irq_enable(adapter);
3869#else
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003870 adapter->total_tx_bytes = 0;
3871 adapter->total_rx_bytes = 0;
3872 adapter->total_tx_packets = 0;
3873 adapter->total_rx_packets = 0;
3874
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003875 for (i = 0; i < E1000_MAX_INTR; i++)
3876 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003877 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003878 break;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003879
3880 if (likely(adapter->itr_setting & 3))
3881 e1000_set_itr(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003882#endif
3883
3884 return IRQ_HANDLED;
3885}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886
3887/**
3888 * e1000_intr - Interrupt Handler
3889 * @irq: interrupt number
3890 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 **/
3892
3893static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003894e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895{
3896 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003897 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003899 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003900#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003901 int i;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003902#endif
3903 if (unlikely(!icr))
3904 return IRQ_NONE; /* Not our interrupt */
3905
3906#ifdef CONFIG_E1000_NAPI
3907 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3908 * not set, then the adapter didn't send an interrupt */
3909 if (unlikely(hw->mac_type >= e1000_82571 &&
3910 !(icr & E1000_ICR_INT_ASSERTED)))
3911 return IRQ_NONE;
3912
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003913 /* Interrupt Auto-Mask...upon reading ICR,
3914 * interrupts are masked. No need for the
3915 * IMC write, but it does mean we should
3916 * account for it ASAP. */
3917 if (likely(hw->mac_type >= e1000_82571))
3918 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003919#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003921 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003923 /* 80003ES2LAN workaround--
3924 * For packet buffer work-around on link down event;
3925 * disable receives here in the ISR and
3926 * reset adapter in watchdog
3927 */
3928 if (netif_carrier_ok(netdev) &&
3929 (adapter->hw.mac_type == e1000_80003es2lan)) {
3930 /* disable receives */
3931 rctl = E1000_READ_REG(hw, RCTL);
3932 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3933 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003934 /* guard against interrupt when we're going down */
3935 if (!test_bit(__E1000_DOWN, &adapter->flags))
3936 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 }
3938
3939#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003940 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003941 /* disable interrupts, without the synchronize_irq bit */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003942 atomic_inc(&adapter->irq_sem);
3943 E1000_WRITE_REG(hw, IMC, ~0);
3944 E1000_WRITE_FLUSH(hw);
3945 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003946 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003947 adapter->total_tx_bytes = 0;
3948 adapter->total_tx_packets = 0;
3949 adapter->total_rx_bytes = 0;
3950 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003951 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003952 } else
Auke Kok90fb5132006-11-01 08:47:30 -08003953 /* this really should not happen! if it does it is basically a
3954 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003955 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003956#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003958 * Due to Hub Link bus being occupied, an interrupt
3959 * de-assertion message is not able to be sent.
3960 * When an interrupt assertion message is generated later,
3961 * two messages are re-ordered and sent out.
3962 * That causes APIC to think 82547 is in de-assertion
3963 * state, while 82547 is in assertion state, resulting
3964 * in dead lock. Writing IMC forces 82547 into
3965 * de-assertion state.
3966 */
3967 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003969 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 }
3971
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003972 adapter->total_tx_bytes = 0;
3973 adapter->total_rx_bytes = 0;
3974 adapter->total_tx_packets = 0;
3975 adapter->total_rx_packets = 0;
3976
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003977 for (i = 0; i < E1000_MAX_INTR; i++)
3978 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003979 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 break;
3981
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003982 if (likely(adapter->itr_setting & 3))
3983 e1000_set_itr(adapter);
3984
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003985 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003987
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003988#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 return IRQ_HANDLED;
3990}
3991
3992#ifdef CONFIG_E1000_NAPI
3993/**
3994 * e1000_clean - NAPI Rx polling callback
3995 * @adapter: board private structure
3996 **/
3997
3998static int
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003999e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004001 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
4002 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004003 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07004004
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004005 /* Must NOT use netdev_priv macro here. */
4006 adapter = poll_dev->priv;
4007
Auke Kokd3d9e482006-07-14 16:14:23 -07004008 /* e1000_clean is called per-cpu. This lock protects
4009 * tx_ring[0] from being cleaned by multiple cpus
4010 * simultaneously. A failure obtaining the lock means
4011 * tx_ring[0] is currently being cleaned anyway. */
4012 if (spin_trylock(&adapter->tx_queue_lock)) {
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004013 tx_cleaned = e1000_clean_tx_irq(adapter,
4014 &adapter->tx_ring[0]);
Auke Kokd3d9e482006-07-14 16:14:23 -07004015 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004016 }
4017
Auke Kokd3d9e482006-07-14 16:14:23 -07004018 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004019 &work_done, budget);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004020
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004021 if (tx_cleaned)
4022 work_done = budget;
4023
David S. Miller53e52c72008-01-07 21:06:12 -08004024 /* If budget not fully consumed, exit the polling mode */
4025 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004026 if (likely(adapter->itr_setting & 3))
4027 e1000_set_itr(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004028 netif_rx_complete(poll_dev, napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 }
4031
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004032 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033}
4034
4035#endif
4036/**
4037 * e1000_clean_tx_irq - Reclaim resources after transmit completes
4038 * @adapter: board private structure
4039 **/
4040
4041static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004042e1000_clean_tx_irq(struct e1000_adapter *adapter,
4043 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 struct net_device *netdev = adapter->netdev;
4046 struct e1000_tx_desc *tx_desc, *eop_desc;
4047 struct e1000_buffer *buffer_info;
4048 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004049#ifdef CONFIG_E1000_NAPI
4050 unsigned int count = 0;
4051#endif
Linus Torvalds46fcc862007-04-19 18:21:01 -07004052 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004053 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054
4055 i = tx_ring->next_to_clean;
4056 eop = tx_ring->buffer_info[i].next_to_watch;
4057 eop_desc = E1000_TX_DESC(*tx_ring, eop);
4058
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004059 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004060 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 tx_desc = E1000_TX_DESC(*tx_ring, i);
4062 buffer_info = &tx_ring->buffer_info[i];
4063 cleaned = (i == eop);
4064
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004065 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004066 struct sk_buff *skb = buffer_info->skb;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08004067 unsigned int segs, bytecount;
4068 segs = skb_shinfo(skb)->gso_segs ?: 1;
4069 /* multiply data chunks by size of headers */
4070 bytecount = ((segs - 1) * skb_headlen(skb)) +
4071 skb->len;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004072 total_tx_packets += segs;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08004073 total_tx_bytes += bytecount;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004074 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05004075 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08004076 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004078 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004080
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 eop = tx_ring->buffer_info[i].next_to_watch;
4082 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004083#ifdef CONFIG_E1000_NAPI
4084#define E1000_TX_WEIGHT 64
4085 /* weight of a sort for tx, to avoid endless transmit cleanup */
Linus Torvalds46fcc862007-04-19 18:21:01 -07004086 if (count++ == E1000_TX_WEIGHT) break;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004087#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088 }
4089
4090 tx_ring->next_to_clean = i;
4091
Auke Kok77b2aad2006-04-14 19:05:25 -07004092#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07004093 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
4094 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
4095 /* Make sure that anybody stopping the queue after this
4096 * sees the new next_to_clean.
4097 */
4098 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004099 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07004100 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004101 ++adapter->restart_queue;
4102 }
Auke Kok77b2aad2006-04-14 19:05:25 -07004103 }
Malli Chilakala26483452005-04-28 19:44:46 -07004104
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004105 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07004106 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 * check with the clearing of time_stamp and movement of i */
4108 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08004109 if (tx_ring->buffer_info[eop].dma &&
4110 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08004111 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004112 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08004113 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004114
4115 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07004116 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004117 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004118 " TDH <%x>\n"
4119 " TDT <%x>\n"
4120 " next_to_use <%x>\n"
4121 " next_to_clean <%x>\n"
4122 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004123 " time_stamp <%lx>\n"
4124 " next_to_watch <%x>\n"
4125 " jiffies <%lx>\n"
4126 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004127 (unsigned long)((tx_ring - adapter->tx_ring) /
4128 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004129 readl(adapter->hw.hw_addr + tx_ring->tdh),
4130 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004131 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08004132 tx_ring->next_to_clean,
4133 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004134 eop,
4135 jiffies,
4136 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004140 adapter->total_tx_bytes += total_tx_bytes;
4141 adapter->total_tx_packets += total_tx_packets;
Auke Kokef90e4e2007-11-13 20:49:15 -08004142 adapter->net_stats.tx_bytes += total_tx_bytes;
4143 adapter->net_stats.tx_packets += total_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144 return cleaned;
4145}
4146
4147/**
4148 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004149 * @adapter: board private structure
4150 * @status_err: receive descriptor status and error fields
4151 * @csum: receive descriptor csum field
4152 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 **/
4154
Auke Koke619d522006-04-14 19:04:52 -07004155static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004157 uint32_t status_err, uint32_t csum,
4158 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004160 uint16_t status = (uint16_t)status_err;
4161 uint8_t errors = (uint8_t)(status_err >> 24);
4162 skb->ip_summed = CHECKSUM_NONE;
4163
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004165 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004167 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004168 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004169 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004170 /* let the stack verify checksum errors */
4171 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 return;
4173 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004174 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004175 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
4176 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004177 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004179 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004180 return;
4181 }
4182 /* It must be a TCP or UDP packet with a valid checksum */
4183 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 /* TCP checksum is good */
4185 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004186 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
4187 /* IP fragment with UDP payload */
4188 /* Hardware complements the payload checksum, so we undo it
4189 * and then put the value in host order for further stack use.
4190 */
Al Viro3e188262007-12-11 19:49:39 +00004191 __sum16 sum = (__force __sum16)htons(csum);
4192 skb->csum = csum_unfold(~sum);
Patrick McHardy84fa7932006-08-29 16:44:56 -07004193 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004195 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196}
4197
4198/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004199 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 * @adapter: board private structure
4201 **/
4202
4203static boolean_t
4204#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004205e1000_clean_rx_irq(struct e1000_adapter *adapter,
4206 struct e1000_rx_ring *rx_ring,
4207 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004209e1000_clean_rx_irq(struct e1000_adapter *adapter,
4210 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211#endif
4212{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 struct net_device *netdev = adapter->netdev;
4214 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004215 struct e1000_rx_desc *rx_desc, *next_rxd;
4216 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 unsigned long flags;
4218 uint32_t length;
4219 uint8_t last_byte;
4220 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004221 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004222 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004223 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224
4225 i = rx_ring->next_to_clean;
4226 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004227 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004229 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004230 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004231 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004232
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004234 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 break;
4236 (*work_done)++;
4237#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08004238 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004239 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004240 buffer_info->skb = NULL;
4241
Jeff Kirsher30320be2006-03-02 18:21:57 -08004242 prefetch(skb->data - NET_IP_ALIGN);
4243
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004244 if (++i == rx_ring->count) i = 0;
4245 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004246 prefetch(next_rxd);
4247
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004248 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004249
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004250 cleaned = TRUE;
4251 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004252 pci_unmap_single(pdev,
4253 buffer_info->dma,
4254 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255 PCI_DMA_FROMDEVICE);
4256
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 length = le16_to_cpu(rx_desc->length);
4258
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004259 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4260 /* All receives must fit into a single buffer */
4261 E1000_DBG("%s: Receive packet consumed multiple"
4262 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004263 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004264 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265 goto next_desc;
4266 }
4267
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004268 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004270 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 rx_desc->errors, length, last_byte)) {
4272 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004273 e1000_tbi_adjust_stats(&adapter->hw,
4274 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 length, skb->data);
4276 spin_unlock_irqrestore(&adapter->stats_lock,
4277 flags);
4278 length--;
4279 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004280 /* recycle */
4281 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 goto next_desc;
4283 }
Auke Kok1cb58212006-04-18 12:31:04 -07004284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004286 /* adjust length to remove Ethernet CRC, this must be
4287 * done after the TBI_ACCEPT workaround above */
4288 length -= 4;
4289
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004290 /* probably a little skewed due to removing CRC */
4291 total_rx_bytes += length;
4292 total_rx_packets++;
4293
Jeff Kirshera292ca62006-01-12 16:51:30 -08004294 /* code added for copybreak, this should improve
4295 * performance for small packets with large amounts
4296 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004297 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004298 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004299 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004300 if (new_skb) {
4301 skb_reserve(new_skb, NET_IP_ALIGN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004302 skb_copy_to_linear_data_offset(new_skb,
4303 -NET_IP_ALIGN,
4304 (skb->data -
4305 NET_IP_ALIGN),
4306 (length +
4307 NET_IP_ALIGN));
Jeff Kirshera292ca62006-01-12 16:51:30 -08004308 /* save the skb in buffer_info as good */
4309 buffer_info->skb = skb;
4310 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004311 }
Auke Kok996695d2006-11-01 08:47:50 -08004312 /* else just continue with the old one */
4313 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004314 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004315 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316
4317 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004318 e1000_rx_checksum(adapter,
4319 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004320 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004321 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004322
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 skb->protocol = eth_type_trans(skb, netdev);
4324#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004325 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08004326 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004328 le16_to_cpu(rx_desc->special) &
4329 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 } else {
4331 netif_receive_skb(skb);
4332 }
4333#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004334 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004335 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 vlan_hwaccel_rx(skb, adapter->vlgrp,
4337 le16_to_cpu(rx_desc->special) &
4338 E1000_RXD_SPC_VLAN_MASK);
4339 } else {
4340 netif_rx(skb);
4341 }
4342#endif /* CONFIG_E1000_NAPI */
4343 netdev->last_rx = jiffies;
4344
4345next_desc:
4346 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004348 /* return some buffers to hardware, one at a time is too slow */
4349 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4350 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4351 cleaned_count = 0;
4352 }
4353
Jeff Kirsher30320be2006-03-02 18:21:57 -08004354 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004355 rx_desc = next_rxd;
4356 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004359
4360 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4361 if (cleaned_count)
4362 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004364 adapter->total_rx_packets += total_rx_packets;
4365 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004366 adapter->net_stats.rx_bytes += total_rx_bytes;
4367 adapter->net_stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 return cleaned;
4369}
4370
4371/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004372 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4373 * @adapter: board private structure
4374 **/
4375
4376static boolean_t
4377#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004378e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4379 struct e1000_rx_ring *rx_ring,
4380 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004381#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004382e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4383 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004384#endif
4385{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004386 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004387 struct net_device *netdev = adapter->netdev;
4388 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004389 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004390 struct e1000_ps_page *ps_page;
4391 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07004392 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004393 unsigned int i, j;
4394 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004395 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004396 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004397 unsigned int total_rx_bytes=0, total_rx_packets=0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004398
4399 i = rx_ring->next_to_clean;
4400 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07004401 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07004402 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004403
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004404 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004405 ps_page = &rx_ring->ps_page[i];
4406 ps_page_dma = &rx_ring->ps_page_dma[i];
4407#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004408 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004409 break;
4410 (*work_done)++;
4411#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004412 skb = buffer_info->skb;
4413
Jeff Kirsher30320be2006-03-02 18:21:57 -08004414 /* in the packet split case this is header only */
4415 prefetch(skb->data - NET_IP_ALIGN);
4416
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004417 if (++i == rx_ring->count) i = 0;
4418 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004419 prefetch(next_rxd);
4420
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004421 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004422
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004423 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004424 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004425 pci_unmap_single(pdev, buffer_info->dma,
4426 buffer_info->length,
4427 PCI_DMA_FROMDEVICE);
4428
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004429 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004430 E1000_DBG("%s: Packet Split buffers didn't pick up"
4431 " the full packet\n", netdev->name);
4432 dev_kfree_skb_irq(skb);
4433 goto next_desc;
4434 }
4435
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004436 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004437 dev_kfree_skb_irq(skb);
4438 goto next_desc;
4439 }
4440
4441 length = le16_to_cpu(rx_desc->wb.middle.length0);
4442
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004443 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004444 E1000_DBG("%s: Last part of the packet spanning"
4445 " multiple descriptors\n", netdev->name);
4446 dev_kfree_skb_irq(skb);
4447 goto next_desc;
4448 }
4449
4450 /* Good Receive */
4451 skb_put(skb, length);
4452
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004453 {
4454 /* this looks ugly, but it seems compiler issues make it
4455 more efficient than reusing j */
4456 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4457
4458 /* page alloc/put takes too long and effects small packet
4459 * throughput, so unsplit small packets and save the alloc/put*/
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004460 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004461 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004462 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004463 * kmap_atomic, so we can't hold the mapping
4464 * very long */
4465 pci_dma_sync_single_for_cpu(pdev,
4466 ps_page_dma->ps_page_dma[0],
4467 PAGE_SIZE,
4468 PCI_DMA_FROMDEVICE);
4469 vaddr = kmap_atomic(ps_page->ps_page[0],
4470 KM_SKB_DATA_SOFTIRQ);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07004471 memcpy(skb_tail_pointer(skb), vaddr, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004472 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4473 pci_dma_sync_single_for_device(pdev,
4474 ps_page_dma->ps_page_dma[0],
4475 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004476 /* remove the CRC */
4477 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004478 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004479 goto copydone;
4480 } /* if */
4481 }
Auke Kok90fb5132006-11-01 08:47:30 -08004482
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004483 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004484 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004485 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004486 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4487 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4488 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004489 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4490 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004491 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004492 skb->len += length;
4493 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004494 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004495 }
4496
Auke Kokf235a2a2006-07-14 16:14:34 -07004497 /* strip the ethernet crc, problem is we're using pages now so
4498 * this whole operation can get a little cpu intensive */
4499 pskb_trim(skb, skb->len - 4);
4500
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004501copydone:
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004502 total_rx_bytes += skb->len;
4503 total_rx_packets++;
4504
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004505 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004506 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004507 skb->protocol = eth_type_trans(skb, netdev);
4508
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004509 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004510 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004511 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004512#ifdef 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_receive_skb(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_receive_skb(skb);
4519 }
4520#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004521 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004522 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004523 le16_to_cpu(rx_desc->wb.middle.vlan) &
4524 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004525 } else {
4526 netif_rx(skb);
4527 }
4528#endif /* CONFIG_E1000_NAPI */
4529 netdev->last_rx = jiffies;
4530
4531next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004532 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004533 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004534
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004535 /* return some buffers to hardware, one at a time is too slow */
4536 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4537 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4538 cleaned_count = 0;
4539 }
4540
Jeff Kirsher30320be2006-03-02 18:21:57 -08004541 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004542 rx_desc = next_rxd;
4543 buffer_info = next_buffer;
4544
Malli Chilakala683a38f2005-06-17 17:43:25 -07004545 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004546 }
4547 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004548
4549 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4550 if (cleaned_count)
4551 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004552
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004553 adapter->total_rx_packets += total_rx_packets;
4554 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004555 adapter->net_stats.rx_bytes += total_rx_bytes;
4556 adapter->net_stats.rx_packets += total_rx_packets;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004557 return cleaned;
4558}
4559
4560/**
4561 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 * @adapter: address of board private structure
4563 **/
4564
4565static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004566e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004567 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004568 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 struct net_device *netdev = adapter->netdev;
4571 struct pci_dev *pdev = adapter->pdev;
4572 struct e1000_rx_desc *rx_desc;
4573 struct e1000_buffer *buffer_info;
4574 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004575 unsigned int i;
4576 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577
4578 i = rx_ring->next_to_use;
4579 buffer_info = &rx_ring->buffer_info[i];
4580
Jeff Kirshera292ca62006-01-12 16:51:30 -08004581 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004582 skb = buffer_info->skb;
4583 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004584 skb_trim(skb, 0);
4585 goto map_skb;
4586 }
4587
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004588 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004589 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004591 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 break;
4593 }
4594
Malli Chilakala26483452005-04-28 19:44:46 -07004595 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4597 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004598 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4599 "at %p\n", bufsz, skb->data);
4600 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004601 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004602 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 if (!skb) {
4604 dev_kfree_skb(oldskb);
4605 break;
4606 }
Malli Chilakala26483452005-04-28 19:44:46 -07004607
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4609 /* give up */
4610 dev_kfree_skb(skb);
4611 dev_kfree_skb(oldskb);
4612 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004614
4615 /* Use new allocation */
4616 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 /* Make buffer alignment 2 beyond a 16 byte boundary
4619 * this will result in a 16 byte aligned IP header after
4620 * the 14 byte MAC header is removed
4621 */
4622 skb_reserve(skb, NET_IP_ALIGN);
4623
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 buffer_info->skb = skb;
4625 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004626map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627 buffer_info->dma = pci_map_single(pdev,
4628 skb->data,
4629 adapter->rx_buffer_len,
4630 PCI_DMA_FROMDEVICE);
4631
Malli Chilakala26483452005-04-28 19:44:46 -07004632 /* Fix for errata 23, can't cross 64kB boundary */
4633 if (!e1000_check_64k_bound(adapter,
4634 (void *)(unsigned long)buffer_info->dma,
4635 adapter->rx_buffer_len)) {
4636 DPRINTK(RX_ERR, ERR,
4637 "dma align check failed: %u bytes at %p\n",
4638 adapter->rx_buffer_len,
4639 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 dev_kfree_skb(skb);
4641 buffer_info->skb = NULL;
4642
Malli Chilakala26483452005-04-28 19:44:46 -07004643 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 adapter->rx_buffer_len,
4645 PCI_DMA_FROMDEVICE);
4646
4647 break; /* while !buffer_info->skb */
4648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 rx_desc = E1000_RX_DESC(*rx_ring, i);
4650 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4651
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004652 if (unlikely(++i == rx_ring->count))
4653 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 buffer_info = &rx_ring->buffer_info[i];
4655 }
4656
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004657 if (likely(rx_ring->next_to_use != i)) {
4658 rx_ring->next_to_use = i;
4659 if (unlikely(i-- == 0))
4660 i = (rx_ring->count - 1);
4661
4662 /* Force memory writes to complete before letting h/w
4663 * know there are new descriptors to fetch. (Only
4664 * applicable for weak-ordered memory model archs,
4665 * such as IA-64). */
4666 wmb();
4667 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669}
4670
4671/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004672 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4673 * @adapter: address of board private structure
4674 **/
4675
4676static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004677e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004678 struct e1000_rx_ring *rx_ring,
4679 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004680{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004681 struct net_device *netdev = adapter->netdev;
4682 struct pci_dev *pdev = adapter->pdev;
4683 union e1000_rx_desc_packet_split *rx_desc;
4684 struct e1000_buffer *buffer_info;
4685 struct e1000_ps_page *ps_page;
4686 struct e1000_ps_page_dma *ps_page_dma;
4687 struct sk_buff *skb;
4688 unsigned int i, j;
4689
4690 i = rx_ring->next_to_use;
4691 buffer_info = &rx_ring->buffer_info[i];
4692 ps_page = &rx_ring->ps_page[i];
4693 ps_page_dma = &rx_ring->ps_page_dma[i];
4694
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004695 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004696 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4697
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004698 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004699 if (j < adapter->rx_ps_pages) {
4700 if (likely(!ps_page->ps_page[j])) {
4701 ps_page->ps_page[j] =
4702 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004703 if (unlikely(!ps_page->ps_page[j])) {
4704 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004705 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004706 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004707 ps_page_dma->ps_page_dma[j] =
4708 pci_map_page(pdev,
4709 ps_page->ps_page[j],
4710 0, PAGE_SIZE,
4711 PCI_DMA_FROMDEVICE);
4712 }
4713 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004714 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004715 * this info.
4716 */
4717 rx_desc->read.buffer_addr[j+1] =
4718 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4719 } else
Al Viro3e188262007-12-11 19:49:39 +00004720 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004721 }
4722
David S. Miller87f50322006-07-31 22:39:40 -07004723 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004724 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004725
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004726 if (unlikely(!skb)) {
4727 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004728 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004729 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004730
4731 /* Make buffer alignment 2 beyond a 16 byte boundary
4732 * this will result in a 16 byte aligned IP header after
4733 * the 14 byte MAC header is removed
4734 */
4735 skb_reserve(skb, NET_IP_ALIGN);
4736
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004737 buffer_info->skb = skb;
4738 buffer_info->length = adapter->rx_ps_bsize0;
4739 buffer_info->dma = pci_map_single(pdev, skb->data,
4740 adapter->rx_ps_bsize0,
4741 PCI_DMA_FROMDEVICE);
4742
4743 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4744
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004745 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004746 buffer_info = &rx_ring->buffer_info[i];
4747 ps_page = &rx_ring->ps_page[i];
4748 ps_page_dma = &rx_ring->ps_page_dma[i];
4749 }
4750
4751no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004752 if (likely(rx_ring->next_to_use != i)) {
4753 rx_ring->next_to_use = i;
4754 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4755
4756 /* Force memory writes to complete before letting h/w
4757 * know there are new descriptors to fetch. (Only
4758 * applicable for weak-ordered memory model archs,
4759 * such as IA-64). */
4760 wmb();
4761 /* Hardware increments by 16 bytes, but packet split
4762 * descriptors are 32 bytes...so we increment tail
4763 * twice as much.
4764 */
4765 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4766 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004767}
4768
4769/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4771 * @adapter:
4772 **/
4773
4774static void
4775e1000_smartspeed(struct e1000_adapter *adapter)
4776{
4777 uint16_t phy_status;
4778 uint16_t phy_ctrl;
4779
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004780 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4782 return;
4783
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004784 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 /* If Master/Slave config fault is asserted twice,
4786 * we assume back-to-back */
4787 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004788 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004790 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004792 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4794 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4795 phy_ctrl);
4796 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004797 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4799 &phy_ctrl)) {
4800 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4801 MII_CR_RESTART_AUTO_NEG);
4802 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4803 phy_ctrl);
4804 }
4805 }
4806 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004807 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 /* If still no link, perhaps using 2/3 pair cable */
4809 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4810 phy_ctrl |= CR_1000T_MS_ENABLE;
4811 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004812 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4814 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4815 MII_CR_RESTART_AUTO_NEG);
4816 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4817 }
4818 }
4819 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004820 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 adapter->smartspeed = 0;
4822}
4823
4824/**
4825 * e1000_ioctl -
4826 * @netdev:
4827 * @ifreq:
4828 * @cmd:
4829 **/
4830
4831static int
4832e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4833{
4834 switch (cmd) {
4835 case SIOCGMIIPHY:
4836 case SIOCGMIIREG:
4837 case SIOCSMIIREG:
4838 return e1000_mii_ioctl(netdev, ifr, cmd);
4839 default:
4840 return -EOPNOTSUPP;
4841 }
4842}
4843
4844/**
4845 * e1000_mii_ioctl -
4846 * @netdev:
4847 * @ifreq:
4848 * @cmd:
4849 **/
4850
4851static int
4852e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4853{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004854 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 struct mii_ioctl_data *data = if_mii(ifr);
4856 int retval;
4857 uint16_t mii_reg;
4858 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004859 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004861 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862 return -EOPNOTSUPP;
4863
4864 switch (cmd) {
4865 case SIOCGMIIPHY:
4866 data->phy_id = adapter->hw.phy_addr;
4867 break;
4868 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004869 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004871 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004872 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004873 &data->val_out)) {
4874 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004876 }
4877 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 break;
4879 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004880 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004882 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 return -EFAULT;
4884 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004885 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004886 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004887 mii_reg)) {
4888 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004890 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004891 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Auke Kokdc86d322006-04-18 12:30:51 -07004892 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893 switch (data->reg_num) {
4894 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004895 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004897 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 adapter->hw.autoneg = 1;
4899 adapter->hw.autoneg_advertised = 0x2F;
4900 } else {
4901 if (mii_reg & 0x40)
4902 spddplx = SPEED_1000;
4903 else if (mii_reg & 0x2000)
4904 spddplx = SPEED_100;
4905 else
4906 spddplx = SPEED_10;
4907 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004908 ? DUPLEX_FULL :
4909 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 retval = e1000_set_spd_dplx(adapter,
4911 spddplx);
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004912 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 return retval;
4914 }
Auke Kok2db10a02006-06-27 09:06:28 -07004915 if (netif_running(adapter->netdev))
4916 e1000_reinit_locked(adapter);
4917 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 e1000_reset(adapter);
4919 break;
4920 case M88E1000_PHY_SPEC_CTRL:
4921 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004922 if (e1000_phy_reset(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 return -EIO;
4924 break;
4925 }
4926 } else {
4927 switch (data->reg_num) {
4928 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004929 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004931 if (netif_running(adapter->netdev))
4932 e1000_reinit_locked(adapter);
4933 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934 e1000_reset(adapter);
4935 break;
4936 }
4937 }
4938 break;
4939 default:
4940 return -EOPNOTSUPP;
4941 }
4942 return E1000_SUCCESS;
4943}
4944
4945void
4946e1000_pci_set_mwi(struct e1000_hw *hw)
4947{
4948 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004949 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004951 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004952 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953}
4954
4955void
4956e1000_pci_clear_mwi(struct e1000_hw *hw)
4957{
4958 struct e1000_adapter *adapter = hw->back;
4959
4960 pci_clear_mwi(adapter->pdev);
4961}
4962
Peter Oruba007755e2007-09-28 22:42:06 -07004963int
4964e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4965{
4966 struct e1000_adapter *adapter = hw->back;
4967 return pcix_get_mmrbc(adapter->pdev);
4968}
4969
4970void
4971e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4972{
4973 struct e1000_adapter *adapter = hw->back;
4974 pcix_set_mmrbc(adapter->pdev, mmrbc);
4975}
4976
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004977int32_t
4978e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4979{
4980 struct e1000_adapter *adapter = hw->back;
4981 uint16_t cap_offset;
4982
4983 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4984 if (!cap_offset)
4985 return -E1000_ERR_CONFIG;
4986
4987 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4988
4989 return E1000_SUCCESS;
4990}
4991
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992void
4993e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4994{
4995 outl(value, port);
4996}
4997
4998static void
4999e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
5000{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005001 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002 uint32_t ctrl, rctl;
5003
5004 e1000_irq_disable(adapter);
5005 adapter->vlgrp = grp;
5006
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005007 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008 /* enable VLAN tag insert/strip */
5009 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5010 ctrl |= E1000_CTRL_VME;
5011 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5012
Auke Kokcd94dd02006-06-27 09:08:22 -07005013 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08005014 /* enable VLAN receive filtering */
5015 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5016 rctl |= E1000_RCTL_VFE;
5017 rctl &= ~E1000_RCTL_CFIEN;
5018 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5019 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07005020 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021 } else {
5022 /* disable VLAN tag insert/strip */
5023 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5024 ctrl &= ~E1000_CTRL_VME;
5025 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5026
Auke Kokcd94dd02006-06-27 09:08:22 -07005027 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08005028 /* disable VLAN filtering */
5029 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5030 rctl &= ~E1000_RCTL_VFE;
5031 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5032 if (adapter->mng_vlan_id !=
5033 (uint16_t)E1000_MNG_VLAN_NONE) {
5034 e1000_vlan_rx_kill_vid(netdev,
5035 adapter->mng_vlan_id);
5036 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
5037 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005038 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039 }
5040
5041 e1000_irq_enable(adapter);
5042}
5043
5044static void
5045e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
5046{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005047 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005049
5050 if ((adapter->hw.mng_cookie.status &
5051 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
5052 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005053 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054 /* add VID to filter table */
5055 index = (vid >> 5) & 0x7F;
5056 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5057 vfta |= (1 << (vid & 0x1F));
5058 e1000_write_vfta(&adapter->hw, index, vfta);
5059}
5060
5061static void
5062e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
5063{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005064 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065 uint32_t vfta, index;
5066
5067 e1000_irq_disable(adapter);
Dan Aloni5c15bde2007-03-02 20:44:51 -08005068 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 e1000_irq_enable(adapter);
5070
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005071 if ((adapter->hw.mng_cookie.status &
5072 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08005073 (vid == adapter->mng_vlan_id)) {
5074 /* release control to f/w */
5075 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005076 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08005077 }
5078
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 /* remove VID from filter table */
5080 index = (vid >> 5) & 0x7F;
5081 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5082 vfta &= ~(1 << (vid & 0x1F));
5083 e1000_write_vfta(&adapter->hw, index, vfta);
5084}
5085
5086static void
5087e1000_restore_vlan(struct e1000_adapter *adapter)
5088{
5089 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
5090
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005091 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005093 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08005094 if (!vlan_group_get_device(adapter->vlgrp, vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095 continue;
5096 e1000_vlan_rx_add_vid(adapter->netdev, vid);
5097 }
5098 }
5099}
5100
5101int
5102e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
5103{
5104 adapter->hw.autoneg = 0;
5105
Malli Chilakala69213682005-06-17 17:44:20 -07005106 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005107 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07005108 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
5109 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
5110 return -EINVAL;
5111 }
5112
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005113 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114 case SPEED_10 + DUPLEX_HALF:
5115 adapter->hw.forced_speed_duplex = e1000_10_half;
5116 break;
5117 case SPEED_10 + DUPLEX_FULL:
5118 adapter->hw.forced_speed_duplex = e1000_10_full;
5119 break;
5120 case SPEED_100 + DUPLEX_HALF:
5121 adapter->hw.forced_speed_duplex = e1000_100_half;
5122 break;
5123 case SPEED_100 + DUPLEX_FULL:
5124 adapter->hw.forced_speed_duplex = e1000_100_full;
5125 break;
5126 case SPEED_1000 + DUPLEX_FULL:
5127 adapter->hw.autoneg = 1;
5128 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
5129 break;
5130 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5131 default:
Malli Chilakala26483452005-04-28 19:44:46 -07005132 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 return -EINVAL;
5134 }
5135 return 0;
5136}
5137
5138static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07005139e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140{
5141 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005142 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005143 uint32_t ctrl, ctrl_ext, rctl, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07005145#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08005146 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07005147#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148
5149 netif_device_detach(netdev);
5150
Auke Kok2db10a02006-06-27 09:06:28 -07005151 if (netif_running(netdev)) {
5152 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07005154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005156#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005157 retval = pci_save_state(pdev);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005158 if (retval)
5159 return retval;
5160#endif
5161
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005163 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164 wufc &= ~E1000_WUFC_LNKC;
5165
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005166 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005168 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169
5170 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005171 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5173 rctl |= E1000_RCTL_MPE;
5174 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5175 }
5176
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005177 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5179 /* advertise wake from D3Cold */
5180 #define E1000_CTRL_ADVD3WUC 0x00100000
5181 /* phy power management enable */
5182 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5183 ctrl |= E1000_CTRL_ADVD3WUC |
5184 E1000_CTRL_EN_PHY_PWR_MGMT;
5185 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5186 }
5187
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005188 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005189 adapter->hw.media_type == e1000_media_type_internal_serdes) {
5190 /* keep the laser running in D3 */
5191 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
5192 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5193 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
5194 }
5195
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005196 /* Allow time for pending master requests to run */
5197 e1000_disable_pciex_master(&adapter->hw);
5198
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
5200 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07005201 pci_enable_wake(pdev, PCI_D3hot, 1);
5202 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203 } else {
5204 E1000_WRITE_REG(&adapter->hw, WUC, 0);
5205 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07005206 pci_enable_wake(pdev, PCI_D3hot, 0);
5207 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208 }
5209
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005210 e1000_release_manageability(adapter);
5211
5212 /* make sure adapter isn't asleep if manageability is enabled */
5213 if (adapter->en_mng_pt) {
5214 pci_enable_wake(pdev, PCI_D3hot, 1);
5215 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005216 }
5217
Auke Kokcd94dd02006-06-27 09:08:22 -07005218 if (adapter->hw.phy_type == e1000_phy_igp_3)
5219 e1000_phy_powerdown_workaround(&adapter->hw);
5220
Auke Kokedd106f2006-11-06 08:57:12 -08005221 if (netif_running(netdev))
5222 e1000_free_irq(adapter);
5223
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005224 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5225 * would have already happened in close and is redundant. */
5226 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005227
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005229
Auke Kokd0e027d2006-04-14 19:04:40 -07005230 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231
5232 return 0;
5233}
5234
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005235#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236static int
5237e1000_resume(struct pci_dev *pdev)
5238{
5239 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005240 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005241 uint32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242
Auke Kokd0e027d2006-04-14 19:04:40 -07005243 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005244 pci_restore_state(pdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005245 if ((err = pci_enable_device(pdev))) {
5246 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5247 return err;
5248 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005249 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250
Auke Kokd0e027d2006-04-14 19:04:40 -07005251 pci_enable_wake(pdev, PCI_D3hot, 0);
5252 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253
Auke Kokedd106f2006-11-06 08:57:12 -08005254 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
5255 return err;
5256
5257 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258 e1000_reset(adapter);
5259 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5260
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005261 e1000_init_manageability(adapter);
5262
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005263 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 e1000_up(adapter);
5265
5266 netif_device_attach(netdev);
5267
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005268 /* If the controller is 82573 and f/w is AMT, do not set
5269 * DRV_LOAD until the interface is up. For all other cases,
5270 * let the f/w know that the h/w is now under the control
5271 * of the driver. */
5272 if (adapter->hw.mac_type != e1000_82573 ||
5273 !e1000_check_mng_mode(&adapter->hw))
5274 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005275
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 return 0;
5277}
5278#endif
Auke Kokc653e632006-05-23 13:35:57 -07005279
5280static void e1000_shutdown(struct pci_dev *pdev)
5281{
5282 e1000_suspend(pdev, PMSG_SUSPEND);
5283}
5284
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285#ifdef CONFIG_NET_POLL_CONTROLLER
5286/*
5287 * Polling 'interrupt' - used by things like netconsole to send skbs
5288 * without having to re-enable interrupts. It's not called while
5289 * the interrupt routine is executing.
5290 */
5291static void
Malli Chilakala26483452005-04-28 19:44:46 -07005292e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005294 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005295
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005297 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07005298 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08005299#ifndef CONFIG_E1000_NAPI
5300 adapter->clean_rx(adapter, adapter->rx_ring);
5301#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302 enable_irq(adapter->pdev->irq);
5303}
5304#endif
5305
Auke Kok90267292006-06-08 09:30:24 -07005306/**
5307 * e1000_io_error_detected - called when PCI error is detected
5308 * @pdev: Pointer to PCI device
5309 * @state: The current pci conneection state
5310 *
5311 * This function is called after a PCI bus error affecting
5312 * this device has been detected.
5313 */
5314static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5315{
5316 struct net_device *netdev = pci_get_drvdata(pdev);
5317 struct e1000_adapter *adapter = netdev->priv;
5318
5319 netif_device_detach(netdev);
5320
5321 if (netif_running(netdev))
5322 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005323 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005324
5325 /* Request a slot slot reset. */
5326 return PCI_ERS_RESULT_NEED_RESET;
5327}
5328
5329/**
5330 * e1000_io_slot_reset - called after the pci bus has been reset.
5331 * @pdev: Pointer to PCI device
5332 *
5333 * Restart the card from scratch, as if from a cold-boot. Implementation
5334 * resembles the first-half of the e1000_resume routine.
5335 */
5336static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5337{
5338 struct net_device *netdev = pci_get_drvdata(pdev);
5339 struct e1000_adapter *adapter = netdev->priv;
5340
5341 if (pci_enable_device(pdev)) {
5342 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5343 return PCI_ERS_RESULT_DISCONNECT;
5344 }
5345 pci_set_master(pdev);
5346
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005347 pci_enable_wake(pdev, PCI_D3hot, 0);
5348 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005349
Auke Kok90267292006-06-08 09:30:24 -07005350 e1000_reset(adapter);
5351 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5352
5353 return PCI_ERS_RESULT_RECOVERED;
5354}
5355
5356/**
5357 * e1000_io_resume - called when traffic can start flowing again.
5358 * @pdev: Pointer to PCI device
5359 *
5360 * This callback is called when the error recovery driver tells us that
5361 * its OK to resume normal operation. Implementation resembles the
5362 * second-half of the e1000_resume routine.
5363 */
5364static void e1000_io_resume(struct pci_dev *pdev)
5365{
5366 struct net_device *netdev = pci_get_drvdata(pdev);
5367 struct e1000_adapter *adapter = netdev->priv;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005368
5369 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005370
5371 if (netif_running(netdev)) {
5372 if (e1000_up(adapter)) {
5373 printk("e1000: can't bring device back up after reset\n");
5374 return;
5375 }
5376 }
5377
5378 netif_device_attach(netdev);
5379
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005380 /* If the controller is 82573 and f/w is AMT, do not set
5381 * DRV_LOAD until the interface is up. For all other cases,
5382 * let the f/w know that the h/w is now under the control
5383 * of the driver. */
5384 if (adapter->hw.mac_type != e1000_82573 ||
5385 !e1000_check_mng_mode(&adapter->hw))
5386 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005387
Auke Kok90267292006-06-08 09:30:24 -07005388}
5389
Linus Torvalds1da177e2005-04-16 15:20:36 -07005390/* e1000_main.c */