blob: 757d02f443a500a03790e1782729fef0f20cc8ee [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);
Joe Perchesc3033b02008-03-21 11:06:25 -0700172static bool 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);
Joe Perchesc3033b02008-03-21 11:06:25 -0700176static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
177 struct e1000_rx_ring *rx_ring,
178 int *work_done, int work_to_do);
179static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
180 struct e1000_rx_ring *rx_ring,
181 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#else
Joe Perchesc3033b02008-03-21 11:06:25 -0700183static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
184 struct e1000_rx_ring *rx_ring);
185static bool 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{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
351 E1000_WRITE_FLUSH(&adapter->hw);
352 synchronize_irq(adapter->pdev->irq);
353}
354
355/**
356 * e1000_irq_enable - Enable default interrupt generation settings
357 * @adapter: board private structure
358 **/
359
Auke Koke619d522006-04-14 19:04:52 -0700360static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361e1000_irq_enable(struct e1000_adapter *adapter)
362{
Jesse Brandeburg9150b762008-03-21 11:06:58 -0700363 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
364 E1000_WRITE_FLUSH(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100366
367static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700368e1000_update_mng_vlan(struct e1000_adapter *adapter)
369{
370 struct net_device *netdev = adapter->netdev;
371 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
372 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800373 if (adapter->vlgrp) {
Dan Aloni5c15bde2007-03-02 20:44:51 -0800374 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800375 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700376 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
377 e1000_vlan_rx_add_vid(netdev, vid);
378 adapter->mng_vlan_id = vid;
379 } else
380 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800381
382 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
383 (vid != old_vid) &&
Dan Aloni5c15bde2007-03-02 20:44:51 -0800384 !vlan_group_get_device(adapter->vlgrp, old_vid))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700385 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800386 } else
387 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700388 }
389}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800390
391/**
392 * e1000_release_hw_control - release control of the h/w to f/w
393 * @adapter: address of board private structure
394 *
395 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
396 * For ASF and Pass Through versions of f/w this means that the
397 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800398 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700399 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800400 **/
401
Auke Koke619d522006-04-14 19:04:52 -0700402static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800403e1000_release_hw_control(struct e1000_adapter *adapter)
404{
405 uint32_t ctrl_ext;
406 uint32_t swsm;
407
408 /* Let firmware taken over control of h/w */
409 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800410 case e1000_82573:
411 swsm = E1000_READ_REG(&adapter->hw, SWSM);
412 E1000_WRITE_REG(&adapter->hw, SWSM,
413 swsm & ~E1000_SWSM_DRV_LOAD);
Bruce Allan31d76442007-03-06 08:57:24 -0800414 break;
415 case e1000_82571:
416 case e1000_82572:
417 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700418 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800419 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
Auke Kokcd94dd02006-06-27 09:08:22 -0700420 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
Bruce Allan31d76442007-03-06 08:57:24 -0800421 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700422 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800423 default:
424 break;
425 }
426}
427
428/**
429 * e1000_get_hw_control - get control of the h/w from f/w
430 * @adapter: address of board private structure
431 *
432 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700433 * For ASF and Pass Through versions of f/w this means that
434 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800435 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700436 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800437 **/
438
Auke Koke619d522006-04-14 19:04:52 -0700439static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800440e1000_get_hw_control(struct e1000_adapter *adapter)
441{
442 uint32_t ctrl_ext;
443 uint32_t swsm;
Auke Kok90fb5132006-11-01 08:47:30 -0800444
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800445 /* Let firmware know the driver has taken over */
446 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800447 case e1000_82573:
448 swsm = E1000_READ_REG(&adapter->hw, SWSM);
449 E1000_WRITE_REG(&adapter->hw, SWSM,
450 swsm | E1000_SWSM_DRV_LOAD);
451 break;
Bruce Allan31d76442007-03-06 08:57:24 -0800452 case e1000_82571:
453 case e1000_82572:
454 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700455 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800456 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
457 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
458 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700459 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800460 default:
461 break;
462 }
463}
464
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500465static void
466e1000_init_manageability(struct e1000_adapter *adapter)
467{
468 if (adapter->en_mng_pt) {
469 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
470
471 /* disable hardware interception of ARP */
472 manc &= ~(E1000_MANC_ARP_EN);
473
474 /* enable receiving management packets to the host */
475 /* this will probably generate destination unreachable messages
476 * from the host OS, but the packets will be handled on SMBUS */
477 if (adapter->hw.has_manc2h) {
478 uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
479
480 manc |= E1000_MANC_EN_MNG2HOST;
481#define E1000_MNG2HOST_PORT_623 (1 << 5)
482#define E1000_MNG2HOST_PORT_664 (1 << 6)
483 manc2h |= E1000_MNG2HOST_PORT_623;
484 manc2h |= E1000_MNG2HOST_PORT_664;
485 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
486 }
487
488 E1000_WRITE_REG(&adapter->hw, MANC, manc);
489 }
490}
491
492static void
493e1000_release_manageability(struct e1000_adapter *adapter)
494{
495 if (adapter->en_mng_pt) {
496 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
497
498 /* re-enable hardware interception of ARP */
499 manc |= E1000_MANC_ARP_EN;
500
501 if (adapter->hw.has_manc2h)
502 manc &= ~E1000_MANC_EN_MNG2HOST;
503
504 /* don't explicitly have to mess with MANC2H since
505 * MANC has an enable disable that gates MANC2H */
506
507 E1000_WRITE_REG(&adapter->hw, MANC, manc);
508 }
509}
510
Auke Koke0aac5a2007-03-06 08:57:21 -0800511/**
512 * e1000_configure - configure the hardware for RX and TX
513 * @adapter = private board structure
514 **/
515static void e1000_configure(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
517 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700518 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Patrick McHardydb0ce502007-11-13 20:54:59 -0800520 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 e1000_restore_vlan(adapter);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500523 e1000_init_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 e1000_configure_tx(adapter);
526 e1000_setup_rctl(adapter);
527 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800528 /* call E1000_DESC_UNUSED which always leaves
529 * at least 1 descriptor unused to make sure
530 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800531 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800532 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800533 adapter->alloc_rx_buf(adapter, ring,
534 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800537 adapter->tx_queue_len = netdev->tx_queue_len;
Auke Koke0aac5a2007-03-06 08:57:21 -0800538}
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800539
Auke Koke0aac5a2007-03-06 08:57:21 -0800540int e1000_up(struct e1000_adapter *adapter)
541{
542 /* hardware has been reset, we need to reload some things */
543 e1000_configure(adapter);
Malli Chilakala5de55622005-04-28 19:39:30 -0700544
Auke Kok1314bbf2006-09-27 12:54:02 -0700545 clear_bit(__E1000_DOWN, &adapter->flags);
546
Auke Koke0aac5a2007-03-06 08:57:21 -0800547#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700548 napi_enable(&adapter->napi);
Auke Koke0aac5a2007-03-06 08:57:21 -0800549#endif
550 e1000_irq_enable(adapter);
551
Jesse Brandeburg79f3d392006-12-15 10:42:34 +0100552 /* fire a link change interrupt to start the watchdog */
553 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 return 0;
555}
556
Auke Kok79f05bf2006-06-27 09:06:32 -0700557/**
558 * e1000_power_up_phy - restore link in case the phy was powered down
559 * @adapter: address of board private structure
560 *
561 * The phy may be powered down to save power and turn off link when the
562 * driver is unloaded and wake on lan is not enabled (among others)
563 * *** this routine MUST be followed by a call to e1000_reset ***
564 *
565 **/
566
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700567void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700568{
569 uint16_t mii_reg = 0;
570
571 /* Just clear the power down bit to wake the phy back up */
572 if (adapter->hw.media_type == e1000_media_type_copper) {
573 /* according to the manual, the phy will retain its
574 * settings across a power-down/up cycle */
575 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
576 mii_reg &= ~MII_CR_POWER_DOWN;
577 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
578 }
579}
580
581static void e1000_power_down_phy(struct e1000_adapter *adapter)
582{
Bruce Allan61c25052006-09-27 12:53:54 -0700583 /* Power down the PHY so no link is implied when interface is down *
Joe Perchesc3033b02008-03-21 11:06:25 -0700584 * The PHY cannot be powered down if any of the following is true *
Auke Kok79f05bf2006-06-27 09:06:32 -0700585 * (a) WoL is enabled
586 * (b) AMT is active
587 * (c) SoL/IDER session is active */
588 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700589 adapter->hw.media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700590 uint16_t mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700591
592 switch (adapter->hw.mac_type) {
593 case e1000_82540:
594 case e1000_82545:
595 case e1000_82545_rev_3:
596 case e1000_82546:
597 case e1000_82546_rev_3:
598 case e1000_82541:
599 case e1000_82541_rev_2:
600 case e1000_82547:
601 case e1000_82547_rev_2:
602 if (E1000_READ_REG(&adapter->hw, MANC) &
603 E1000_MANC_SMBUS_EN)
604 goto out;
605 break;
606 case e1000_82571:
607 case e1000_82572:
608 case e1000_82573:
609 case e1000_80003es2lan:
610 case e1000_ich8lan:
611 if (e1000_check_mng_mode(&adapter->hw) ||
612 e1000_check_phy_reset_block(&adapter->hw))
613 goto out;
614 break;
615 default:
616 goto out;
617 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700618 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
619 mii_reg |= MII_CR_POWER_DOWN;
620 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
621 mdelay(1);
622 }
Bruce Allan61c25052006-09-27 12:53:54 -0700623out:
624 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700625}
626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627void
628e1000_down(struct e1000_adapter *adapter)
629{
630 struct net_device *netdev = adapter->netdev;
631
Auke Kok1314bbf2006-09-27 12:54:02 -0700632 /* signal that we're down so the interrupt handler does not
633 * reschedule our watchdog timer */
634 set_bit(__E1000_DOWN, &adapter->flags);
635
Auke Koke0aac5a2007-03-06 08:57:21 -0800636#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700637 napi_disable(&adapter->napi);
Auke Koke0aac5a2007-03-06 08:57:21 -0800638#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 del_timer_sync(&adapter->tx_fifo_stall_timer);
642 del_timer_sync(&adapter->watchdog_timer);
643 del_timer_sync(&adapter->phy_info_timer);
644
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800645 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 adapter->link_speed = 0;
647 adapter->link_duplex = 0;
648 netif_carrier_off(netdev);
649 netif_stop_queue(netdev);
650
651 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400652 e1000_clean_all_tx_rings(adapter);
653 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656void
Auke Kok2db10a02006-06-27 09:06:28 -0700657e1000_reinit_locked(struct e1000_adapter *adapter)
658{
659 WARN_ON(in_interrupt());
660 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
661 msleep(1);
662 e1000_down(adapter);
663 e1000_up(adapter);
664 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
666
667void
668e1000_reset(struct e1000_adapter *adapter)
669{
Bruce Allan018ea442006-12-15 10:39:45 +0100670 uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700671 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Joe Perchesc3033b02008-03-21 11:06:25 -0700672 bool legacy_pba_adjust = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 /* Repartition Pba for greater than 9k mtu
675 * To take effect CTRL.RST is required.
676 */
677
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700678 switch (adapter->hw.mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100679 case e1000_82542_rev2_0:
680 case e1000_82542_rev2_1:
681 case e1000_82543:
682 case e1000_82544:
683 case e1000_82540:
684 case e1000_82541:
685 case e1000_82541_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700686 legacy_pba_adjust = true;
Bruce Allan018ea442006-12-15 10:39:45 +0100687 pba = E1000_PBA_48K;
688 break;
689 case e1000_82545:
690 case e1000_82545_rev_3:
691 case e1000_82546:
692 case e1000_82546_rev_3:
693 pba = E1000_PBA_48K;
694 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700695 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700696 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700697 legacy_pba_adjust = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700698 pba = E1000_PBA_30K;
699 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400700 case e1000_82571:
701 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800702 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400703 pba = E1000_PBA_38K;
704 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700705 case e1000_82573:
Bruce Allan018ea442006-12-15 10:39:45 +0100706 pba = E1000_PBA_20K;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700707 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700708 case e1000_ich8lan:
709 pba = E1000_PBA_8K;
Bruce Allan018ea442006-12-15 10:39:45 +0100710 case e1000_undefined:
711 case e1000_num_macs:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700712 break;
713 }
714
Joe Perchesc3033b02008-03-21 11:06:25 -0700715 if (legacy_pba_adjust) {
Bruce Allan018ea442006-12-15 10:39:45 +0100716 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
717 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700718
Bruce Allan018ea442006-12-15 10:39:45 +0100719 if (adapter->hw.mac_type == e1000_82547) {
720 adapter->tx_fifo_head = 0;
721 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
722 adapter->tx_fifo_size =
723 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
724 atomic_set(&adapter->tx_fifo_stall, 0);
725 }
726 } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
727 /* adjust PBA for jumbo frames */
728 E1000_WRITE_REG(&adapter->hw, PBA, pba);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700729
Bruce Allan018ea442006-12-15 10:39:45 +0100730 /* To maintain wire speed transmits, the Tx FIFO should be
731 * large enough to accomodate two full transmit packets,
732 * rounded up to the next 1KB and expressed in KB. Likewise,
733 * the Rx FIFO should be large enough to accomodate at least
734 * one full receive packet and is similarly rounded up and
735 * expressed in KB. */
736 pba = E1000_READ_REG(&adapter->hw, PBA);
737 /* upper 16 bits has Tx packet buffer allocation size in KB */
738 tx_space = pba >> 16;
739 /* lower 16 bits has Rx packet buffer allocation size in KB */
740 pba &= 0xffff;
741 /* don't include ethernet FCS because hardware appends/strips */
742 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
743 VLAN_TAG_SIZE;
744 min_tx_space = min_rx_space;
745 min_tx_space *= 2;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700746 min_tx_space = ALIGN(min_tx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100747 min_tx_space >>= 10;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700748 min_rx_space = ALIGN(min_rx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100749 min_rx_space >>= 10;
750
751 /* If current Tx allocation is less than the min Tx FIFO size,
752 * and the min Tx FIFO size is less than the current Rx FIFO
753 * allocation, take space away from current Rx allocation */
754 if (tx_space < min_tx_space &&
755 ((min_tx_space - tx_space) < pba)) {
756 pba = pba - (min_tx_space - tx_space);
757
758 /* PCI/PCIx hardware has PBA alignment constraints */
759 switch (adapter->hw.mac_type) {
760 case e1000_82545 ... e1000_82546_rev_3:
761 pba &= ~(E1000_PBA_8K - 1);
762 break;
763 default:
764 break;
765 }
766
767 /* if short on rx space, rx wins and must trump tx
768 * adjustment or use Early Receive if available */
769 if (pba < min_rx_space) {
770 switch (adapter->hw.mac_type) {
771 case e1000_82573:
772 /* ERT enabled in e1000_configure_rx */
773 break;
774 default:
775 pba = min_rx_space;
776 break;
777 }
778 }
779 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 E1000_WRITE_REG(&adapter->hw, PBA, pba);
783
784 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800785 /* Set the FC high water mark to 90% of the FIFO size.
786 * Required to clear last 3 LSB */
787 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700788 /* We can't use 90% on small FIFOs because the remainder
789 * would be less than 1 full frame. In this case, we size
790 * it to allow at least a full frame above the high water
791 * mark. */
792 if (pba < E1000_PBA_16K)
793 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800794
795 adapter->hw.fc_high_water = fc_high_water_mark;
796 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800797 if (adapter->hw.mac_type == e1000_80003es2lan)
798 adapter->hw.fc_pause_time = 0xFFFF;
799 else
800 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 adapter->hw.fc_send_xon = 1;
802 adapter->hw.fc = adapter->hw.original_fc;
803
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700804 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800806 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700808
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800809 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700811 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100812
813 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
814 if (adapter->hw.mac_type >= e1000_82544 &&
815 adapter->hw.mac_type <= e1000_82547_rev_2 &&
816 adapter->hw.autoneg == 1 &&
817 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
818 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
819 /* clear phy power management bit if we are in gig only mode,
820 * which if enabled will attempt negotiation to 100Mb, which
821 * can cause a loss of link at power off or driver unload */
822 ctrl &= ~E1000_CTRL_SWDPIN3;
823 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
824 }
825
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
827 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
828
829 e1000_reset_adaptive(&adapter->hw);
830 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700831
832 if (!adapter->smart_power_down &&
833 (adapter->hw.mac_type == e1000_82571 ||
834 adapter->hw.mac_type == e1000_82572)) {
835 uint16_t phy_data = 0;
836 /* speed up time to link by disabling smart power down, ignore
837 * the return value of this function because there is nothing
838 * different we would do if it failed */
839 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
840 &phy_data);
841 phy_data &= ~IGP02E1000_PM_SPD;
842 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
843 phy_data);
844 }
845
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500846 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
849/**
Auke Kok67b3c272007-12-17 13:50:23 -0800850 * Dump the eeprom for users having checksum issues
851 **/
Adrian Bunkb4ea8952008-02-01 08:21:28 -0800852static void e1000_dump_eeprom(struct e1000_adapter *adapter)
Auke Kok67b3c272007-12-17 13:50:23 -0800853{
854 struct net_device *netdev = adapter->netdev;
855 struct ethtool_eeprom eeprom;
856 const struct ethtool_ops *ops = netdev->ethtool_ops;
857 u8 *data;
858 int i;
859 u16 csum_old, csum_new = 0;
860
861 eeprom.len = ops->get_eeprom_len(netdev);
862 eeprom.offset = 0;
863
864 data = kmalloc(eeprom.len, GFP_KERNEL);
865 if (!data) {
866 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
867 " data\n");
868 return;
869 }
870
871 ops->get_eeprom(netdev, &eeprom, data);
872
873 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
874 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
875 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
876 csum_new += data[i] + (data[i + 1] << 8);
877 csum_new = EEPROM_SUM - csum_new;
878
879 printk(KERN_ERR "/*********************/\n");
880 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
881 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
882
883 printk(KERN_ERR "Offset Values\n");
884 printk(KERN_ERR "======== ======\n");
885 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
886
887 printk(KERN_ERR "Include this output when contacting your support "
888 "provider.\n");
889 printk(KERN_ERR "This is not a software error! Something bad "
890 "happened to your hardware or\n");
891 printk(KERN_ERR "EEPROM image. Ignoring this "
892 "problem could result in further problems,\n");
893 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
894 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
895 "which is invalid\n");
896 printk(KERN_ERR "and requires you to set the proper MAC "
897 "address manually before continuing\n");
898 printk(KERN_ERR "to enable this network device.\n");
899 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
900 "to your hardware vendor\n");
901 printk(KERN_ERR "or Intel Customer Support: linux-nics@intel.com\n");
902 printk(KERN_ERR "/*********************/\n");
903
904 kfree(data);
905}
906
907/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 * e1000_probe - Device Initialization Routine
909 * @pdev: PCI device information struct
910 * @ent: entry in e1000_pci_tbl
911 *
912 * Returns 0 on success, negative on failure
913 *
914 * e1000_probe initializes an adapter identified by a pci_dev structure.
915 * The OS initialization, configuring of the adapter private structure,
916 * and a hardware reset occur.
917 **/
918
919static int __devinit
920e1000_probe(struct pci_dev *pdev,
921 const struct pci_device_id *ent)
922{
923 struct net_device *netdev;
924 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700927 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700928 int i, err, pci_using_dac;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700929 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Joe Perches0795af52007-10-03 17:59:30 -0700931 DECLARE_MAC_BUF(mac);
932
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800933 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 return err;
935
Auke Kokcd94dd02006-06-27 09:08:22 -0700936 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
937 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 pci_using_dac = 1;
939 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700940 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
941 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700943 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 }
945 pci_using_dac = 0;
946 }
947
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800948 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700949 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 pci_set_master(pdev);
952
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700953 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700955 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 SET_NETDEV_DEV(netdev, &pdev->dev);
959
960 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700961 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 adapter->netdev = netdev;
963 adapter->pdev = pdev;
964 adapter->hw.back = adapter;
965 adapter->msg_enable = (1 << debug) - 1;
966
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700967 err = -EIO;
Benjamin Herrenschmidt3c34ac32007-11-16 18:37:38 +1100968 adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
969 pci_resource_len(pdev, BAR_0));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700970 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800973 for (i = BAR_1; i <= BAR_5; i++) {
974 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800976 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 adapter->hw.io_base = pci_resource_start(pdev, i);
978 break;
979 }
980 }
981
982 netdev->open = &e1000_open;
983 netdev->stop = &e1000_close;
984 netdev->hard_start_xmit = &e1000_xmit_frame;
985 netdev->get_stats = &e1000_get_stats;
Patrick McHardydb0ce502007-11-13 20:54:59 -0800986 netdev->set_rx_mode = &e1000_set_rx_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 netdev->set_mac_address = &e1000_set_mac;
988 netdev->change_mtu = &e1000_change_mtu;
989 netdev->do_ioctl = &e1000_ioctl;
990 e1000_set_ethtool_ops(netdev);
991 netdev->tx_timeout = &e1000_tx_timeout;
992 netdev->watchdog_timeo = 5 * HZ;
993#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700994 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995#endif
996 netdev->vlan_rx_register = e1000_vlan_rx_register;
997 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
998 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
999#ifdef CONFIG_NET_POLL_CONTROLLER
1000 netdev->poll_controller = e1000_netpoll;
1001#endif
Auke Kok0eb5a342006-09-27 12:53:17 -07001002 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 adapter->bd_number = cards_found;
1005
1006 /* setup the private structure */
1007
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001008 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 goto err_sw_init;
1010
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001011 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -07001012 /* Flash BAR mapping must happen after e1000_sw_init
1013 * because it depends on mac_type */
1014 if ((adapter->hw.mac_type == e1000_ich8lan) &&
1015 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
Benjamin Herrenschmidt3c34ac32007-11-16 18:37:38 +11001016 adapter->hw.flash_address =
1017 ioremap(pci_resource_start(pdev, 1),
1018 pci_resource_len(pdev, 1));
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001019 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -07001020 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -07001021 }
1022
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001023 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001024 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
1025
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001026 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 netdev->features = NETIF_F_SG |
1028 NETIF_F_HW_CSUM |
1029 NETIF_F_HW_VLAN_TX |
1030 NETIF_F_HW_VLAN_RX |
1031 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -07001032 if (adapter->hw.mac_type == e1000_ich8lan)
1033 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
1035
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001036 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 (adapter->hw.mac_type != e1000_82547))
1038 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001039
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001040 if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -08001041 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001042 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 netdev->features |= NETIF_F_HIGHDMA;
1044
Auke Kok76c224b2006-05-23 13:36:06 -07001045 netdev->features |= NETIF_F_LLTX;
1046
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001047 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
1048
Auke Kokcd94dd02006-06-27 09:08:22 -07001049 /* initialize eeprom parameters */
Auke Kokcd94dd02006-06-27 09:08:22 -07001050 if (e1000_init_eeprom_params(&adapter->hw)) {
1051 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001052 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001053 }
1054
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001055 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 e1000_reset_hw(&adapter->hw);
1059
1060 /* make sure the EEPROM is good */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001061 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Auke Kok67b3c272007-12-17 13:50:23 -08001063 e1000_dump_eeprom(adapter);
1064 /*
1065 * set MAC address to all zeroes to invalidate and temporary
1066 * disable this device for the user. This blocks regular
1067 * traffic while still permitting ethtool ioctls from reaching
1068 * the hardware as well as allowing the user to run the
1069 * interface after manually setting a hw addr using
1070 * `ip set address`
1071 */
1072 memset(adapter->hw.mac_addr, 0, netdev->addr_len);
1073 } else {
1074 /* copy the MAC address out of the EEPROM */
1075 if (e1000_read_mac_addr(&adapter->hw))
1076 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 }
Auke Kok67b3c272007-12-17 13:50:23 -08001078 /* don't block initalization here due to bad MAC address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -04001080 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Auke Kok67b3c272007-12-17 13:50:23 -08001082 if (!is_valid_ether_addr(netdev->perm_addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 e1000_get_bus_info(&adapter->hw);
1086
1087 init_timer(&adapter->tx_fifo_stall_timer);
1088 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1089 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
1090
1091 init_timer(&adapter->watchdog_timer);
1092 adapter->watchdog_timer.function = &e1000_watchdog;
1093 adapter->watchdog_timer.data = (unsigned long) adapter;
1094
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 init_timer(&adapter->phy_info_timer);
1096 adapter->phy_info_timer.function = &e1000_update_phy_info;
1097 adapter->phy_info_timer.data = (unsigned long) adapter;
1098
David Howells65f27f32006-11-22 14:55:48 +00001099 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 e1000_check_options(adapter);
1102
1103 /* Initial Wake on LAN setting
1104 * If APM wake is enabled in the EEPROM,
1105 * enable the ACPI Magic Packet filter
1106 */
1107
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001108 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 case e1000_82542_rev2_0:
1110 case e1000_82542_rev2_1:
1111 case e1000_82543:
1112 break;
1113 case e1000_82544:
1114 e1000_read_eeprom(&adapter->hw,
1115 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1116 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1117 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001118 case e1000_ich8lan:
1119 e1000_read_eeprom(&adapter->hw,
1120 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1121 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1122 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 case e1000_82546:
1124 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001125 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001126 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001127 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 e1000_read_eeprom(&adapter->hw,
1129 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1130 break;
1131 }
1132 /* Fall Through */
1133 default:
1134 e1000_read_eeprom(&adapter->hw,
1135 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1136 break;
1137 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001138 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001139 adapter->eeprom_wol |= E1000_WUFC_MAG;
1140
1141 /* now that we have the eeprom settings, apply the special cases
1142 * where the eeprom may be wrong or the board simply won't support
1143 * wake on lan on a particular port */
1144 switch (pdev->device) {
1145 case E1000_DEV_ID_82546GB_PCIE:
1146 adapter->eeprom_wol = 0;
1147 break;
1148 case E1000_DEV_ID_82546EB_FIBER:
1149 case E1000_DEV_ID_82546GB_FIBER:
1150 case E1000_DEV_ID_82571EB_FIBER:
1151 /* Wake events only supported on port A for dual fiber
1152 * regardless of eeprom setting */
1153 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
1154 adapter->eeprom_wol = 0;
1155 break;
1156 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001157 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001158 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001159 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001160 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001161 /* if quad port adapter, disable WoL on all but port A */
1162 if (global_quad_port_a != 0)
1163 adapter->eeprom_wol = 0;
1164 else
1165 adapter->quad_port_a = 1;
1166 /* Reset for multiple quad port adapters */
1167 if (++global_quad_port_a == 4)
1168 global_quad_port_a = 0;
1169 break;
1170 }
1171
1172 /* initialize the wol settings based on the eeprom settings */
1173 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001175 /* print bus type/speed/width info */
1176 {
1177 struct e1000_hw *hw = &adapter->hw;
1178 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1179 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1180 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1181 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1182 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1183 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1184 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1185 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1186 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1187 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1188 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1189 "32-bit"));
1190 }
1191
Joe Perches0795af52007-10-03 17:59:30 -07001192 printk("%s\n", print_mac(mac, netdev->dev_addr));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001193
Auke Kok14782ca2008-02-11 09:25:46 -08001194 if (adapter->hw.bus_type == e1000_bus_type_pci_express) {
1195 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1196 "longer be supported by this driver in the future.\n",
1197 pdev->vendor, pdev->device);
1198 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1199 "driver instead.\n");
1200 }
1201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 /* reset the hardware with the new settings */
1203 e1000_reset(adapter);
1204
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001205 /* If the controller is 82573 and f/w is AMT, do not set
1206 * DRV_LOAD until the interface is up. For all other cases,
1207 * let the f/w know that the h/w is now under the control
1208 * of the driver. */
1209 if (adapter->hw.mac_type != e1000_82573 ||
1210 !e1000_check_mng_mode(&adapter->hw))
1211 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001212
Auke Kok1314bbf2006-09-27 12:54:02 -07001213 /* tell the stack to leave us alone until e1000_open() is called */
1214 netif_carrier_off(netdev);
1215 netif_stop_queue(netdev);
Auke Kok416b5d12007-06-01 10:22:39 -07001216
1217 strcpy(netdev->name, "eth%d");
1218 if ((err = register_netdev(netdev)))
1219 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001220
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1222
1223 cards_found++;
1224 return 0;
1225
1226err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001227 e1000_release_hw_control(adapter);
1228err_eeprom:
1229 if (!e1000_check_phy_reset_block(&adapter->hw))
1230 e1000_phy_hw_reset(&adapter->hw);
1231
Auke Kokcd94dd02006-06-27 09:08:22 -07001232 if (adapter->hw.flash_address)
1233 iounmap(adapter->hw.flash_address);
1234err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001235#ifdef CONFIG_E1000_NAPI
1236 for (i = 0; i < adapter->num_rx_queues; i++)
1237 dev_put(&adapter->polling_netdev[i]);
1238#endif
1239
1240 kfree(adapter->tx_ring);
1241 kfree(adapter->rx_ring);
1242#ifdef CONFIG_E1000_NAPI
1243 kfree(adapter->polling_netdev);
1244#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 iounmap(adapter->hw.hw_addr);
1247err_ioremap:
1248 free_netdev(netdev);
1249err_alloc_etherdev:
1250 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001251err_pci_reg:
1252err_dma:
1253 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 return err;
1255}
1256
1257/**
1258 * e1000_remove - Device Removal Routine
1259 * @pdev: PCI device information struct
1260 *
1261 * e1000_remove is called by the PCI subsystem to alert the driver
1262 * that it should release a PCI device. The could be caused by a
1263 * Hot-Plug event, or because the driver is going to be removed from
1264 * memory.
1265 **/
1266
1267static void __devexit
1268e1000_remove(struct pci_dev *pdev)
1269{
1270 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001271 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001272#ifdef CONFIG_E1000_NAPI
1273 int i;
1274#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Oleg Nesterov28e53bd2007-05-09 02:34:22 -07001276 cancel_work_sync(&adapter->reset_task);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001277
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001278 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001280 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1281 * would have already happened in close and is redundant. */
1282 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001283
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001284#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001285 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001286 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001287#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001289 unregister_netdev(netdev);
1290
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001291 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001292 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001294 kfree(adapter->tx_ring);
1295 kfree(adapter->rx_ring);
1296#ifdef CONFIG_E1000_NAPI
1297 kfree(adapter->polling_netdev);
1298#endif
1299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001301 if (adapter->hw.flash_address)
1302 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 pci_release_regions(pdev);
1304
1305 free_netdev(netdev);
1306
1307 pci_disable_device(pdev);
1308}
1309
1310/**
1311 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1312 * @adapter: board private structure to initialize
1313 *
1314 * e1000_sw_init initializes the Adapter private data structure.
1315 * Fields are initialized based on PCI device information and
1316 * OS network device settings (MTU size).
1317 **/
1318
1319static int __devinit
1320e1000_sw_init(struct e1000_adapter *adapter)
1321{
1322 struct e1000_hw *hw = &adapter->hw;
1323 struct net_device *netdev = adapter->netdev;
1324 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001325#ifdef CONFIG_E1000_NAPI
1326 int i;
1327#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
1329 /* PCI config space info */
1330
1331 hw->vendor_id = pdev->vendor;
1332 hw->device_id = pdev->device;
1333 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1334 hw->subsystem_id = pdev->subsystem_device;
Auke Kok44c10132007-06-08 15:46:36 -07001335 hw->revision_id = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
1337 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1338
Auke Kokeb0f8052006-07-14 16:14:48 -07001339 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001340 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 hw->max_frame_size = netdev->mtu +
1342 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1343 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1344
1345 /* identify the MAC */
1346
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001347 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1349 return -EIO;
1350 }
1351
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001352 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 default:
1354 break;
1355 case e1000_82541:
1356 case e1000_82547:
1357 case e1000_82541_rev_2:
1358 case e1000_82547_rev_2:
1359 hw->phy_init_script = 1;
1360 break;
1361 }
1362
1363 e1000_set_media_type(hw);
1364
Joe Perchesc3033b02008-03-21 11:06:25 -07001365 hw->wait_autoneg_complete = false;
1366 hw->tbi_compatibility_en = true;
1367 hw->adaptive_ifs = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369 /* Copper options */
1370
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001371 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 hw->mdix = AUTO_ALL_MODES;
Joe Perchesc3033b02008-03-21 11:06:25 -07001373 hw->disable_polarity_correction = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 hw->master_slave = E1000_MASTER_SLAVE;
1375 }
1376
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001377 adapter->num_tx_queues = 1;
1378 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001379
1380 if (e1000_alloc_queues(adapter)) {
1381 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1382 return -ENOMEM;
1383 }
1384
1385#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001386 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001387 adapter->polling_netdev[i].priv = adapter;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001388 dev_hold(&adapter->polling_netdev[i]);
1389 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1390 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001391 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001392#endif
1393
Herbert Xu47313052007-05-29 15:07:31 -07001394 /* Explicitly disable IRQ since the NIC can be in any state. */
Herbert Xu47313052007-05-29 15:07:31 -07001395 e1000_irq_disable(adapter);
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Auke Kok1314bbf2006-09-27 12:54:02 -07001399 set_bit(__E1000_DOWN, &adapter->flags);
1400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 return 0;
1402}
1403
1404/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001405 * e1000_alloc_queues - Allocate memory for all rings
1406 * @adapter: board private structure to initialize
1407 *
1408 * We allocate one ring per queue at run-time since we don't know the
1409 * number of queues at compile-time. The polling_netdev array is
1410 * intended for Multiqueue, but should work fine with a single queue.
1411 **/
1412
1413static int __devinit
1414e1000_alloc_queues(struct e1000_adapter *adapter)
1415{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001416 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1417 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001418 if (!adapter->tx_ring)
1419 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001420
Yan Burman1c7e5b12007-03-06 08:58:04 -08001421 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1422 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001423 if (!adapter->rx_ring) {
1424 kfree(adapter->tx_ring);
1425 return -ENOMEM;
1426 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001427
1428#ifdef CONFIG_E1000_NAPI
Yan Burman1c7e5b12007-03-06 08:58:04 -08001429 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1430 sizeof(struct net_device),
1431 GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001432 if (!adapter->polling_netdev) {
1433 kfree(adapter->tx_ring);
1434 kfree(adapter->rx_ring);
1435 return -ENOMEM;
1436 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001437#endif
1438
1439 return E1000_SUCCESS;
1440}
1441
1442/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 * e1000_open - Called when a network interface is made active
1444 * @netdev: network interface device structure
1445 *
1446 * Returns 0 on success, negative value on failure
1447 *
1448 * The open entry point is called when a network interface is made
1449 * active by the system (IFF_UP). At this point all resources needed
1450 * for transmit and receive operations are allocated, the interrupt
1451 * handler is registered with the OS, the watchdog timer is started,
1452 * and the stack is notified that the interface is ready.
1453 **/
1454
1455static int
1456e1000_open(struct net_device *netdev)
1457{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001458 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 int err;
1460
Auke Kok2db10a02006-06-27 09:06:28 -07001461 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001462 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001463 return -EBUSY;
1464
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001466 err = e1000_setup_all_tx_resources(adapter);
1467 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 goto err_setup_tx;
1469
1470 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001471 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001472 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001473 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001474
Auke Kok79f05bf2006-06-27 09:06:32 -07001475 e1000_power_up_phy(adapter);
1476
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001477 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001478 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001479 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1480 e1000_update_mng_vlan(adapter);
1481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001483 /* If AMT is enabled, let the firmware know that the network
1484 * interface is now open */
1485 if (adapter->hw.mac_type == e1000_82573 &&
1486 e1000_check_mng_mode(&adapter->hw))
1487 e1000_get_hw_control(adapter);
1488
Auke Koke0aac5a2007-03-06 08:57:21 -08001489 /* before we allocate an interrupt, we must be ready to handle it.
1490 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1491 * as soon as we call pci_request_irq, so we have to setup our
1492 * clean_rx handler before we do so. */
1493 e1000_configure(adapter);
1494
1495 err = e1000_request_irq(adapter);
1496 if (err)
1497 goto err_req_irq;
1498
1499 /* From here on the code is the same as e1000_up() */
1500 clear_bit(__E1000_DOWN, &adapter->flags);
1501
Herbert Xu47313052007-05-29 15:07:31 -07001502#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001503 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001504#endif
1505
Auke Koke0aac5a2007-03-06 08:57:21 -08001506 e1000_irq_enable(adapter);
1507
1508 /* fire a link status change interrupt to start the watchdog */
1509 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
1510
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 return E1000_SUCCESS;
1512
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001513err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001514 e1000_release_hw_control(adapter);
1515 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001516 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001518 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519err_setup_tx:
1520 e1000_reset(adapter);
1521
1522 return err;
1523}
1524
1525/**
1526 * e1000_close - Disables a network interface
1527 * @netdev: network interface device structure
1528 *
1529 * Returns 0, this is not allowed to fail
1530 *
1531 * The close entry point is called when an interface is de-activated
1532 * by the OS. The hardware is still under the drivers control, but
1533 * needs to be disabled. A global MAC reset is issued to stop the
1534 * hardware, and all transmit and receive resources are freed.
1535 **/
1536
1537static int
1538e1000_close(struct net_device *netdev)
1539{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001540 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Auke Kok2db10a02006-06-27 09:06:28 -07001542 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001544 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001545 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001547 e1000_free_all_tx_resources(adapter);
1548 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Bruce Allan46665602006-09-27 12:54:08 -07001550 /* kill manageability vlan ID if supported, but not if a vlan with
1551 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001552 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001553 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1554 !(adapter->vlgrp &&
Dan Aloni5c15bde2007-03-02 20:44:51 -08001555 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001556 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1557 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001558
1559 /* If AMT is enabled, let the firmware know that the network
1560 * interface is now closed */
1561 if (adapter->hw.mac_type == e1000_82573 &&
1562 e1000_check_mng_mode(&adapter->hw))
1563 e1000_release_hw_control(adapter);
1564
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 return 0;
1566}
1567
1568/**
1569 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1570 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001571 * @start: address of beginning of memory
1572 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 **/
Joe Perchesc3033b02008-03-21 11:06:25 -07001574static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575e1000_check_64k_bound(struct e1000_adapter *adapter,
1576 void *start, unsigned long len)
1577{
1578 unsigned long begin = (unsigned long) start;
1579 unsigned long end = begin + len;
1580
Malli Chilakala26483452005-04-28 19:44:46 -07001581 /* First rev 82545 and 82546 need to not allow any memory
1582 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001584 adapter->hw.mac_type == e1000_82546) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001585 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 }
1587
Joe Perchesc3033b02008-03-21 11:06:25 -07001588 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589}
1590
1591/**
1592 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1593 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001594 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 *
1596 * Return 0 on success, negative on failure
1597 **/
1598
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001599static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001600e1000_setup_tx_resources(struct e1000_adapter *adapter,
1601 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 struct pci_dev *pdev = adapter->pdev;
1604 int size;
1605
1606 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001607 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001608 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001609 DPRINTK(PROBE, ERR,
1610 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 return -ENOMEM;
1612 }
1613 memset(txdr->buffer_info, 0, size);
1614
1615 /* round up to nearest 4K */
1616
1617 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001618 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
1620 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001621 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001624 DPRINTK(PROBE, ERR,
1625 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 return -ENOMEM;
1627 }
1628
Malli Chilakala26483452005-04-28 19:44:46 -07001629 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1631 void *olddesc = txdr->desc;
1632 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001633 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1634 "at %p\n", txdr->size, txdr->desc);
1635 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001637 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001638 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1640 goto setup_tx_desc_die;
1641 }
1642
1643 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1644 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001645 pci_free_consistent(pdev, txdr->size, txdr->desc,
1646 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1648 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001649 "Unable to allocate aligned memory "
1650 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 vfree(txdr->buffer_info);
1652 return -ENOMEM;
1653 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001654 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1656 }
1657 }
1658 memset(txdr->desc, 0, txdr->size);
1659
1660 txdr->next_to_use = 0;
1661 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001662 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
1664 return 0;
1665}
1666
1667/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001668 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1669 * (Descriptors) for all queues
1670 * @adapter: board private structure
1671 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001672 * Return 0 on success, negative on failure
1673 **/
1674
1675int
1676e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1677{
1678 int i, err = 0;
1679
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001680 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001681 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1682 if (err) {
1683 DPRINTK(PROBE, ERR,
1684 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001685 for (i-- ; i >= 0; i--)
1686 e1000_free_tx_resources(adapter,
1687 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001688 break;
1689 }
1690 }
1691
1692 return err;
1693}
1694
1695/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1697 * @adapter: board private structure
1698 *
1699 * Configure the Tx unit of the MAC after a reset.
1700 **/
1701
1702static void
1703e1000_configure_tx(struct e1000_adapter *adapter)
1704{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001705 uint64_t tdba;
1706 struct e1000_hw *hw = &adapter->hw;
1707 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001708 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 /* Setup the HW Tx Head and Tail descriptor pointers */
1711
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001712 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001713 case 1:
1714 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001715 tdba = adapter->tx_ring[0].dma;
1716 tdlen = adapter->tx_ring[0].count *
1717 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001718 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001719 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1720 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001721 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001722 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001723 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1724 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001725 break;
1726 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
1728 /* Set the default values for the Tx Inter Packet Gap timer */
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001729 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1730 (hw->media_type == e1000_media_type_fiber ||
1731 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001732 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1733 else
1734 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1735
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001736 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 case e1000_82542_rev2_0:
1738 case e1000_82542_rev2_1:
1739 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001740 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1741 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001743 case e1000_80003es2lan:
1744 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1745 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1746 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001748 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1749 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1750 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001752 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1753 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001754 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756 /* Set the Tx Interrupt Delay register */
1757
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001758 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1759 if (hw->mac_type >= e1000_82540)
1760 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
1762 /* Program the Transmit Control Register */
1763
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001764 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001766 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1768
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001769 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1770 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001771 /* set the speed mode bit, we'll clear it if we're not at
1772 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001773 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001774 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001775 } else if (hw->mac_type == e1000_80003es2lan) {
1776 tarc = E1000_READ_REG(hw, TARC0);
1777 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001778 E1000_WRITE_REG(hw, TARC0, tarc);
1779 tarc = E1000_READ_REG(hw, TARC1);
1780 tarc |= 1;
1781 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001782 }
1783
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001784 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
1786 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001787 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1788
1789 /* only set IDE if we are delaying interrupts using the timers */
1790 if (adapter->tx_int_delay)
1791 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001793 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1795 else
1796 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1797
1798 /* Cache if we're 82544 running in PCI-X because we'll
1799 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001800 if (hw->mac_type == e1000_82544 &&
1801 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001803
1804 E1000_WRITE_REG(hw, TCTL, tctl);
1805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
1807
1808/**
1809 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1810 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001811 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 *
1813 * Returns 0 on success, negative on failure
1814 **/
1815
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001816static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001817e1000_setup_rx_resources(struct e1000_adapter *adapter,
1818 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001821 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001824 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001825 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001826 DPRINTK(PROBE, ERR,
1827 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 return -ENOMEM;
1829 }
1830 memset(rxdr->buffer_info, 0, size);
1831
Yan Burman1c7e5b12007-03-06 08:58:04 -08001832 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1833 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001834 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001835 vfree(rxdr->buffer_info);
1836 DPRINTK(PROBE, ERR,
1837 "Unable to allocate memory for the receive descriptor ring\n");
1838 return -ENOMEM;
1839 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001840
Yan Burman1c7e5b12007-03-06 08:58:04 -08001841 rxdr->ps_page_dma = kcalloc(rxdr->count,
1842 sizeof(struct e1000_ps_page_dma),
1843 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001844 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001845 vfree(rxdr->buffer_info);
1846 kfree(rxdr->ps_page);
1847 DPRINTK(PROBE, ERR,
1848 "Unable to allocate memory for the receive descriptor ring\n");
1849 return -ENOMEM;
1850 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001851
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001852 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001853 desc_len = sizeof(struct e1000_rx_desc);
1854 else
1855 desc_len = sizeof(union e1000_rx_desc_packet_split);
1856
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 /* Round up to nearest 4K */
1858
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001859 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001860 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
1862 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1863
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001864 if (!rxdr->desc) {
1865 DPRINTK(PROBE, ERR,
1866 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001869 kfree(rxdr->ps_page);
1870 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 return -ENOMEM;
1872 }
1873
Malli Chilakala26483452005-04-28 19:44:46 -07001874 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1876 void *olddesc = rxdr->desc;
1877 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001878 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1879 "at %p\n", rxdr->size, rxdr->desc);
1880 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001882 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001883 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001885 DPRINTK(PROBE, ERR,
1886 "Unable to allocate memory "
1887 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 goto setup_rx_desc_die;
1889 }
1890
1891 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1892 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001893 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1894 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001896 DPRINTK(PROBE, ERR,
1897 "Unable to allocate aligned memory "
1898 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001899 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001901 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1903 }
1904 }
1905 memset(rxdr->desc, 0, rxdr->size);
1906
1907 rxdr->next_to_clean = 0;
1908 rxdr->next_to_use = 0;
1909
1910 return 0;
1911}
1912
1913/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001914 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1915 * (Descriptors) for all queues
1916 * @adapter: board private structure
1917 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001918 * Return 0 on success, negative on failure
1919 **/
1920
1921int
1922e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1923{
1924 int i, err = 0;
1925
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001926 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001927 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1928 if (err) {
1929 DPRINTK(PROBE, ERR,
1930 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001931 for (i-- ; i >= 0; i--)
1932 e1000_free_rx_resources(adapter,
1933 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001934 break;
1935 }
1936 }
1937
1938 return err;
1939}
1940
1941/**
Malli Chilakala26483452005-04-28 19:44:46 -07001942 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 * @adapter: Board private structure
1944 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001945#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1946 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947static void
1948e1000_setup_rctl(struct e1000_adapter *adapter)
1949{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001950 uint32_t rctl, rfctl;
1951 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001952#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001953 uint32_t pages = 0;
1954#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
1956 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1957
1958 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1959
1960 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1961 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1962 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1963
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001964 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 rctl |= E1000_RCTL_SBP;
1966 else
1967 rctl &= ~E1000_RCTL_SBP;
1968
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001969 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1970 rctl &= ~E1000_RCTL_LPE;
1971 else
1972 rctl |= E1000_RCTL_LPE;
1973
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001975 rctl &= ~E1000_RCTL_SZ_4096;
1976 rctl |= E1000_RCTL_BSEX;
1977 switch (adapter->rx_buffer_len) {
1978 case E1000_RXBUFFER_256:
1979 rctl |= E1000_RCTL_SZ_256;
1980 rctl &= ~E1000_RCTL_BSEX;
1981 break;
1982 case E1000_RXBUFFER_512:
1983 rctl |= E1000_RCTL_SZ_512;
1984 rctl &= ~E1000_RCTL_BSEX;
1985 break;
1986 case E1000_RXBUFFER_1024:
1987 rctl |= E1000_RCTL_SZ_1024;
1988 rctl &= ~E1000_RCTL_BSEX;
1989 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001990 case E1000_RXBUFFER_2048:
1991 default:
1992 rctl |= E1000_RCTL_SZ_2048;
1993 rctl &= ~E1000_RCTL_BSEX;
1994 break;
1995 case E1000_RXBUFFER_4096:
1996 rctl |= E1000_RCTL_SZ_4096;
1997 break;
1998 case E1000_RXBUFFER_8192:
1999 rctl |= E1000_RCTL_SZ_8192;
2000 break;
2001 case E1000_RXBUFFER_16384:
2002 rctl |= E1000_RCTL_SZ_16384;
2003 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002004 }
2005
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08002006#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002007 /* 82571 and greater support packet-split where the protocol
2008 * header is placed in skb->data and the packet data is
2009 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2010 * In the case of a non-split, skb->data is linearly filled,
2011 * followed by the page buffers. Therefore, skb->data is
2012 * sized to hold the largest protocol header.
2013 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07002014 /* allocations using alloc_page take too long for regular MTU
2015 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002016 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07002017 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
2018 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002019 adapter->rx_ps_pages = pages;
2020 else
2021 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002022#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002023 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002024 /* Configure extra packet-split registers */
2025 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
2026 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08002027 /* disable packet split support for IPv6 extension headers,
2028 * because some malformed IPv6 headers can hang the RX */
2029 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2030 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2031
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002032 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
2033
Auke Kok7dfee0c2006-06-27 09:07:50 -07002034 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002035
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002036 psrctl |= adapter->rx_ps_bsize0 >>
2037 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002038
2039 switch (adapter->rx_ps_pages) {
2040 case 3:
2041 psrctl |= PAGE_SIZE <<
2042 E1000_PSRCTL_BSIZE3_SHIFT;
2043 case 2:
2044 psrctl |= PAGE_SIZE <<
2045 E1000_PSRCTL_BSIZE2_SHIFT;
2046 case 1:
2047 psrctl |= PAGE_SIZE >>
2048 E1000_PSRCTL_BSIZE1_SHIFT;
2049 break;
2050 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002051
2052 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 }
2054
2055 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2056}
2057
2058/**
2059 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2060 * @adapter: board private structure
2061 *
2062 * Configure the Rx unit of the MAC after a reset.
2063 **/
2064
2065static void
2066e1000_configure_rx(struct e1000_adapter *adapter)
2067{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002068 uint64_t rdba;
2069 struct e1000_hw *hw = &adapter->hw;
2070 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002071
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002072 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002073 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002074 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002075 sizeof(union e1000_rx_desc_packet_split);
2076 adapter->clean_rx = e1000_clean_rx_irq_ps;
2077 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2078 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002079 rdlen = adapter->rx_ring[0].count *
2080 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002081 adapter->clean_rx = e1000_clean_rx_irq;
2082 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2083 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
2085 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002086 rctl = E1000_READ_REG(hw, RCTL);
2087 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
2089 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002090 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002092 if (hw->mac_type >= e1000_82540) {
2093 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002094 if (adapter->itr_setting != 0)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002095 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 1000000000 / (adapter->itr * 256));
2097 }
2098
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002099 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002100 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002101 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002102 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002103#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002104 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002105 ctrl_ext |= E1000_CTRL_EXT_IAME;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002106 E1000_WRITE_REG(hw, IAM, 0xffffffff);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002107#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002108 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2109 E1000_WRITE_FLUSH(hw);
2110 }
2111
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002112 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2113 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002114 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002115 case 1:
2116 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002117 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002118 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07002119 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
2120 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002121 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002122 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002123 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2124 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002125 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002126 }
2127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002129 if (hw->mac_type >= e1000_82543) {
2130 rxcsum = E1000_READ_REG(hw, RXCSUM);
Joe Perchesc3033b02008-03-21 11:06:25 -07002131 if (adapter->rx_csum) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002132 rxcsum |= E1000_RXCSUM_TUOFL;
2133
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002134 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002135 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002136 if ((hw->mac_type >= e1000_82571) &&
2137 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002138 rxcsum |= E1000_RXCSUM_IPPCSE;
2139 }
2140 } else {
2141 rxcsum &= ~E1000_RXCSUM_TUOFL;
2142 /* don't need to clear IPPCSE as it defaults to 0 */
2143 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002144 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 }
2146
Auke Kok21c4d5e2006-11-01 08:47:39 -08002147 /* enable early receives on 82573, only takes effect if using > 2048
2148 * byte total frame size. for example only for jumbo frames */
2149#define E1000_ERT_2048 0x100
2150 if (hw->mac_type == e1000_82573)
2151 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
2152
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002154 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155}
2156
2157/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002158 * e1000_free_tx_resources - Free Tx Resources per Queue
2159 * @adapter: board private structure
2160 * @tx_ring: Tx descriptor ring for a specific queue
2161 *
2162 * Free all transmit software resources
2163 **/
2164
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002165static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002166e1000_free_tx_resources(struct e1000_adapter *adapter,
2167 struct e1000_tx_ring *tx_ring)
2168{
2169 struct pci_dev *pdev = adapter->pdev;
2170
2171 e1000_clean_tx_ring(adapter, tx_ring);
2172
2173 vfree(tx_ring->buffer_info);
2174 tx_ring->buffer_info = NULL;
2175
2176 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2177
2178 tx_ring->desc = NULL;
2179}
2180
2181/**
2182 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 * @adapter: board private structure
2184 *
2185 * Free all transmit software resources
2186 **/
2187
2188void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002189e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002191 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002193 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002194 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
Auke Koke619d522006-04-14 19:04:52 -07002197static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2199 struct e1000_buffer *buffer_info)
2200{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002201 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07002202 pci_unmap_page(adapter->pdev,
2203 buffer_info->dma,
2204 buffer_info->length,
2205 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002206 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002208 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002210 buffer_info->skb = NULL;
2211 }
2212 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213}
2214
2215/**
2216 * e1000_clean_tx_ring - Free Tx Buffers
2217 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002218 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 **/
2220
2221static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002222e1000_clean_tx_ring(struct e1000_adapter *adapter,
2223 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 struct e1000_buffer *buffer_info;
2226 unsigned long size;
2227 unsigned int i;
2228
2229 /* Free all the Tx ring sk_buffs */
2230
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002231 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 buffer_info = &tx_ring->buffer_info[i];
2233 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2234 }
2235
2236 size = sizeof(struct e1000_buffer) * tx_ring->count;
2237 memset(tx_ring->buffer_info, 0, size);
2238
2239 /* Zero out the descriptor ring */
2240
2241 memset(tx_ring->desc, 0, tx_ring->size);
2242
2243 tx_ring->next_to_use = 0;
2244 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002245 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002247 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2248 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2249}
2250
2251/**
2252 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2253 * @adapter: board private structure
2254 **/
2255
2256static void
2257e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2258{
2259 int i;
2260
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002261 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002262 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263}
2264
2265/**
2266 * e1000_free_rx_resources - Free Rx Resources
2267 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002268 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 *
2270 * Free all receive software resources
2271 **/
2272
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002273static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002274e1000_free_rx_resources(struct e1000_adapter *adapter,
2275 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 struct pci_dev *pdev = adapter->pdev;
2278
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002279 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
2281 vfree(rx_ring->buffer_info);
2282 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002283 kfree(rx_ring->ps_page);
2284 rx_ring->ps_page = NULL;
2285 kfree(rx_ring->ps_page_dma);
2286 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
2288 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2289
2290 rx_ring->desc = NULL;
2291}
2292
2293/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002294 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002296 *
2297 * Free all receive software resources
2298 **/
2299
2300void
2301e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2302{
2303 int i;
2304
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002305 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002306 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2307}
2308
2309/**
2310 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2311 * @adapter: board private structure
2312 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 **/
2314
2315static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002316e1000_clean_rx_ring(struct e1000_adapter *adapter,
2317 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002320 struct e1000_ps_page *ps_page;
2321 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 struct pci_dev *pdev = adapter->pdev;
2323 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002324 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002327 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002329 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 pci_unmap_single(pdev,
2331 buffer_info->dma,
2332 buffer_info->length,
2333 PCI_DMA_FROMDEVICE);
2334
2335 dev_kfree_skb(buffer_info->skb);
2336 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002337 }
2338 ps_page = &rx_ring->ps_page[i];
2339 ps_page_dma = &rx_ring->ps_page_dma[i];
2340 for (j = 0; j < adapter->rx_ps_pages; j++) {
2341 if (!ps_page->ps_page[j]) break;
2342 pci_unmap_page(pdev,
2343 ps_page_dma->ps_page_dma[j],
2344 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2345 ps_page_dma->ps_page_dma[j] = 0;
2346 put_page(ps_page->ps_page[j]);
2347 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 }
2349 }
2350
2351 size = sizeof(struct e1000_buffer) * rx_ring->count;
2352 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002353 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2354 memset(rx_ring->ps_page, 0, size);
2355 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2356 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
2358 /* Zero out the descriptor ring */
2359
2360 memset(rx_ring->desc, 0, rx_ring->size);
2361
2362 rx_ring->next_to_clean = 0;
2363 rx_ring->next_to_use = 0;
2364
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002365 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2366 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2367}
2368
2369/**
2370 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2371 * @adapter: board private structure
2372 **/
2373
2374static void
2375e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2376{
2377 int i;
2378
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002379 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002380 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381}
2382
2383/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2384 * and memory write and invalidate disabled for certain operations
2385 */
2386static void
2387e1000_enter_82542_rst(struct e1000_adapter *adapter)
2388{
2389 struct net_device *netdev = adapter->netdev;
2390 uint32_t rctl;
2391
2392 e1000_pci_clear_mwi(&adapter->hw);
2393
2394 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2395 rctl |= E1000_RCTL_RST;
2396 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2397 E1000_WRITE_FLUSH(&adapter->hw);
2398 mdelay(5);
2399
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002400 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002401 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402}
2403
2404static void
2405e1000_leave_82542_rst(struct e1000_adapter *adapter)
2406{
2407 struct net_device *netdev = adapter->netdev;
2408 uint32_t rctl;
2409
2410 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2411 rctl &= ~E1000_RCTL_RST;
2412 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2413 E1000_WRITE_FLUSH(&adapter->hw);
2414 mdelay(5);
2415
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002416 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 e1000_pci_set_mwi(&adapter->hw);
2418
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002419 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002420 /* No need to loop, because 82542 supports only 1 queue */
2421 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002422 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002423 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 }
2425}
2426
2427/**
2428 * e1000_set_mac - Change the Ethernet Address of the NIC
2429 * @netdev: network interface device structure
2430 * @p: pointer to an address structure
2431 *
2432 * Returns 0 on success, negative on failure
2433 **/
2434
2435static int
2436e1000_set_mac(struct net_device *netdev, void *p)
2437{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002438 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 struct sockaddr *addr = p;
2440
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002441 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 return -EADDRNOTAVAIL;
2443
2444 /* 82542 2.0 needs to be in reset to write receive address registers */
2445
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002446 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 e1000_enter_82542_rst(adapter);
2448
2449 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2450 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2451
2452 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2453
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002454 /* With 82571 controllers, LAA may be overwritten (with the default)
2455 * due to controller reset from the other port. */
2456 if (adapter->hw.mac_type == e1000_82571) {
2457 /* activate the work around */
2458 adapter->hw.laa_is_present = 1;
2459
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002460 /* Hold a copy of the LAA in RAR[14] This is done so that
2461 * between the time RAR[0] gets clobbered and the time it
2462 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002463 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002464 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002465 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002466 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002467 E1000_RAR_ENTRIES - 1);
2468 }
2469
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002470 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 e1000_leave_82542_rst(adapter);
2472
2473 return 0;
2474}
2475
2476/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002477 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 * @netdev: network interface device structure
2479 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002480 * The set_rx_mode entry point is called whenever the unicast or multicast
2481 * address lists or the network interface flags are updated. This routine is
2482 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 * promiscuous mode, and all-multi behavior.
2484 **/
2485
2486static void
Patrick McHardydb0ce502007-11-13 20:54:59 -08002487e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002489 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 struct e1000_hw *hw = &adapter->hw;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002491 struct dev_addr_list *uc_ptr;
2492 struct dev_addr_list *mc_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 uint32_t rctl;
2494 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002495 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002496 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2497 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2498 E1000_NUM_MTA_REGISTERS;
2499
2500 if (adapter->hw.mac_type == e1000_ich8lan)
2501 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002503 /* reserve RAR[14] for LAA over-write work-around */
2504 if (adapter->hw.mac_type == e1000_82571)
2505 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506
Malli Chilakala26483452005-04-28 19:44:46 -07002507 /* Check for Promiscuous and All Multicast modes */
2508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 rctl = E1000_READ_REG(hw, RCTL);
2510
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002511 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002513 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 rctl |= E1000_RCTL_MPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 } else {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002516 rctl &= ~E1000_RCTL_MPE;
2517 }
2518
2519 uc_ptr = NULL;
2520 if (netdev->uc_count > rar_entries - 1) {
2521 rctl |= E1000_RCTL_UPE;
2522 } else if (!(netdev->flags & IFF_PROMISC)) {
2523 rctl &= ~E1000_RCTL_UPE;
2524 uc_ptr = netdev->uc_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 }
2526
2527 E1000_WRITE_REG(hw, RCTL, rctl);
2528
2529 /* 82542 2.0 needs to be in reset to write receive address registers */
2530
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002531 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 e1000_enter_82542_rst(adapter);
2533
Patrick McHardydb0ce502007-11-13 20:54:59 -08002534 /* load the first 14 addresses into the exact filters 1-14. Unicast
2535 * addresses take precedence to avoid disabling unicast filtering
2536 * when possible.
2537 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 * RAR 0 is used for the station MAC adddress
2539 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002540 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 */
2542 mc_ptr = netdev->mc_list;
2543
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002544 for (i = 1; i < rar_entries; i++) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002545 if (uc_ptr) {
2546 e1000_rar_set(hw, uc_ptr->da_addr, i);
2547 uc_ptr = uc_ptr->next;
2548 } else if (mc_ptr) {
2549 e1000_rar_set(hw, mc_ptr->da_addr, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 mc_ptr = mc_ptr->next;
2551 } else {
2552 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002553 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002555 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 }
2557 }
Patrick McHardydb0ce502007-11-13 20:54:59 -08002558 WARN_ON(uc_ptr != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
2560 /* clear the old settings from the multicast hash table */
2561
Auke Kokcd94dd02006-06-27 09:08:22 -07002562 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002564 E1000_WRITE_FLUSH(hw);
2565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
2567 /* load any remaining addresses into the hash table */
2568
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002569 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002570 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 e1000_mta_set(hw, hash_value);
2572 }
2573
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002574 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
2578/* Need to wait a few seconds after link up to get diagnostic information from
2579 * the phy */
2580
2581static void
2582e1000_update_phy_info(unsigned long data)
2583{
2584 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2585 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2586}
2587
2588/**
2589 * e1000_82547_tx_fifo_stall - Timer Call-back
2590 * @data: pointer to adapter cast into an unsigned long
2591 **/
2592
2593static void
2594e1000_82547_tx_fifo_stall(unsigned long data)
2595{
2596 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2597 struct net_device *netdev = adapter->netdev;
2598 uint32_t tctl;
2599
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002600 if (atomic_read(&adapter->tx_fifo_stall)) {
2601 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 E1000_READ_REG(&adapter->hw, TDH)) &&
2603 (E1000_READ_REG(&adapter->hw, TDFT) ==
2604 E1000_READ_REG(&adapter->hw, TDFH)) &&
2605 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2606 E1000_READ_REG(&adapter->hw, TDFHS))) {
2607 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2608 E1000_WRITE_REG(&adapter->hw, TCTL,
2609 tctl & ~E1000_TCTL_EN);
2610 E1000_WRITE_REG(&adapter->hw, TDFT,
2611 adapter->tx_head_addr);
2612 E1000_WRITE_REG(&adapter->hw, TDFH,
2613 adapter->tx_head_addr);
2614 E1000_WRITE_REG(&adapter->hw, TDFTS,
2615 adapter->tx_head_addr);
2616 E1000_WRITE_REG(&adapter->hw, TDFHS,
2617 adapter->tx_head_addr);
2618 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2619 E1000_WRITE_FLUSH(&adapter->hw);
2620
2621 adapter->tx_fifo_head = 0;
2622 atomic_set(&adapter->tx_fifo_stall, 0);
2623 netif_wake_queue(netdev);
2624 } else {
2625 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2626 }
2627 }
2628}
2629
2630/**
2631 * e1000_watchdog - Timer Call-back
2632 * @data: pointer to adapter cast into an unsigned long
2633 **/
2634static void
2635e1000_watchdog(unsigned long data)
2636{
2637 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002639 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002640 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002641 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
Auke Kokcd94dd02006-06-27 09:08:22 -07002643 ret_val = e1000_check_for_link(&adapter->hw);
2644 if ((ret_val == E1000_ERR_PHY) &&
2645 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2646 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2647 /* See e1000_kumeran_lock_loss_workaround() */
2648 DPRINTK(LINK, INFO,
2649 "Gigabit has been disabled, downgrading speed\n");
2650 }
Auke Kok90fb5132006-11-01 08:47:30 -08002651
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002652 if (adapter->hw.mac_type == e1000_82573) {
2653 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002654 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002655 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002658 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2660 link = !adapter->hw.serdes_link_down;
2661 else
2662 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2663
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002664 if (link) {
2665 if (!netif_carrier_ok(netdev)) {
Auke Kok9669f532007-01-18 09:25:26 -08002666 uint32_t ctrl;
Joe Perchesc3033b02008-03-21 11:06:25 -07002667 bool txb2b = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 e1000_get_speed_and_duplex(&adapter->hw,
2669 &adapter->link_speed,
2670 &adapter->link_duplex);
2671
Auke Kok9669f532007-01-18 09:25:26 -08002672 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
2673 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2674 "Flow Control: %s\n",
2675 adapter->link_speed,
2676 adapter->link_duplex == FULL_DUPLEX ?
2677 "Full Duplex" : "Half Duplex",
2678 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2679 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2680 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2681 E1000_CTRL_TFCE) ? "TX" : "None" )));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002683 /* tweak tx_queue_len according to speed/duplex
2684 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002685 netdev->tx_queue_len = adapter->tx_queue_len;
2686 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002687 switch (adapter->link_speed) {
2688 case SPEED_10:
Joe Perchesc3033b02008-03-21 11:06:25 -07002689 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002690 netdev->tx_queue_len = 10;
2691 adapter->tx_timeout_factor = 8;
2692 break;
2693 case SPEED_100:
Joe Perchesc3033b02008-03-21 11:06:25 -07002694 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002695 netdev->tx_queue_len = 100;
2696 /* maybe add some timeout factor ? */
2697 break;
2698 }
2699
Auke Kokfe7fe282006-04-14 19:04:59 -07002700 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002701 adapter->hw.mac_type == e1000_82572) &&
Joe Perchesc3033b02008-03-21 11:06:25 -07002702 !txb2b) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002703 uint32_t tarc0;
2704 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002705 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002706 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2707 }
Auke Kok90fb5132006-11-01 08:47:30 -08002708
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002709 /* disable TSO for pcie and 10/100 speeds, to avoid
2710 * some hardware issues */
2711 if (!adapter->tso_force &&
2712 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002713 switch (adapter->link_speed) {
2714 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002715 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002716 DPRINTK(PROBE,INFO,
2717 "10/100 speed: disabling TSO\n");
2718 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002719 netdev->features &= ~NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002720 break;
2721 case SPEED_1000:
2722 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002723 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002724 break;
2725 default:
2726 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002727 break;
2728 }
2729 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002730
2731 /* enable transmits in the hardware, need to do this
2732 * after setting TARC0 */
2733 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2734 tctl |= E1000_TCTL_EN;
2735 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002736
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 netif_carrier_on(netdev);
2738 netif_wake_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002739 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002741 } else {
2742 /* make sure the receive unit is started */
2743 if (adapter->hw.rx_needs_kicking) {
2744 struct e1000_hw *hw = &adapter->hw;
2745 uint32_t rctl = E1000_READ_REG(hw, RCTL);
2746 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 }
2749 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002750 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 adapter->link_speed = 0;
2752 adapter->link_duplex = 0;
2753 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2754 netif_carrier_off(netdev);
2755 netif_stop_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002756 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Jeff Kirsher87041632006-03-02 18:21:24 -08002757
2758 /* 80003ES2LAN workaround--
2759 * For packet buffer work-around on link down event;
2760 * disable receives in the ISR and
2761 * reset device here in the watchdog
2762 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002763 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002764 /* reset device */
2765 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 }
2767
2768 e1000_smartspeed(adapter);
2769 }
2770
2771 e1000_update_stats(adapter);
2772
2773 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2774 adapter->tpt_old = adapter->stats.tpt;
2775 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2776 adapter->colc_old = adapter->stats.colc;
2777
2778 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2779 adapter->gorcl_old = adapter->stats.gorcl;
2780 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2781 adapter->gotcl_old = adapter->stats.gotcl;
2782
2783 e1000_update_adaptive(&adapter->hw);
2784
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002785 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002786 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 /* We've lost link, so the controller stops DMA,
2788 * but we've got queued Tx work that's never going
2789 * to get done, so reset controller to flush Tx.
2790 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002791 adapter->tx_timeout_count++;
2792 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 }
2794 }
2795
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 /* Cause software interrupt to ensure rx ring is cleaned */
2797 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2798
Malli Chilakala26483452005-04-28 19:44:46 -07002799 /* Force detection of hung controller every watchdog period */
Joe Perchesc3033b02008-03-21 11:06:25 -07002800 adapter->detect_tx_hung = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002802 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002803 * reset from the other port. Set the appropriate LAA in RAR[0] */
2804 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2805 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2806
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 /* Reset the timer */
Arjan van de Ven56e13932007-03-06 02:41:48 -08002808 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809}
2810
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002811enum latency_range {
2812 lowest_latency = 0,
2813 low_latency = 1,
2814 bulk_latency = 2,
2815 latency_invalid = 255
2816};
2817
2818/**
2819 * e1000_update_itr - update the dynamic ITR value based on statistics
2820 * Stores a new ITR value based on packets and byte
2821 * counts during the last interrupt. The advantage of per interrupt
2822 * computation is faster updates and more accurate ITR for the current
2823 * traffic pattern. Constants in this function were computed
2824 * based on theoretical maximum wire speed and thresholds were set based
2825 * on testing data as well as attempting to minimize response time
2826 * while increasing bulk throughput.
2827 * this functionality is controlled by the InterruptThrottleRate module
2828 * parameter (see e1000_param.c)
2829 * @adapter: pointer to adapter
2830 * @itr_setting: current adapter->itr
2831 * @packets: the number of packets during this measurement interval
2832 * @bytes: the number of bytes during this measurement interval
2833 **/
2834static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2835 uint16_t itr_setting,
2836 int packets,
2837 int bytes)
2838{
2839 unsigned int retval = itr_setting;
2840 struct e1000_hw *hw = &adapter->hw;
2841
2842 if (unlikely(hw->mac_type < e1000_82540))
2843 goto update_itr_done;
2844
2845 if (packets == 0)
2846 goto update_itr_done;
2847
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002848 switch (itr_setting) {
2849 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002850 /* jumbo frames get bulk treatment*/
2851 if (bytes/packets > 8000)
2852 retval = bulk_latency;
2853 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002854 retval = low_latency;
2855 break;
2856 case low_latency: /* 50 usec aka 20000 ints/s */
2857 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002858 /* jumbo frames need bulk latency setting */
2859 if (bytes/packets > 8000)
2860 retval = bulk_latency;
2861 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002862 retval = bulk_latency;
2863 else if ((packets > 35))
2864 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002865 } else if (bytes/packets > 2000)
2866 retval = bulk_latency;
2867 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002868 retval = lowest_latency;
2869 break;
2870 case bulk_latency: /* 250 usec aka 4000 ints/s */
2871 if (bytes > 25000) {
2872 if (packets > 35)
2873 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002874 } else if (bytes < 6000) {
2875 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002876 }
2877 break;
2878 }
2879
2880update_itr_done:
2881 return retval;
2882}
2883
2884static void e1000_set_itr(struct e1000_adapter *adapter)
2885{
2886 struct e1000_hw *hw = &adapter->hw;
2887 uint16_t current_itr;
2888 uint32_t new_itr = adapter->itr;
2889
2890 if (unlikely(hw->mac_type < e1000_82540))
2891 return;
2892
2893 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2894 if (unlikely(adapter->link_speed != SPEED_1000)) {
2895 current_itr = 0;
2896 new_itr = 4000;
2897 goto set_itr_now;
2898 }
2899
2900 adapter->tx_itr = e1000_update_itr(adapter,
2901 adapter->tx_itr,
2902 adapter->total_tx_packets,
2903 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002904 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2905 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2906 adapter->tx_itr = low_latency;
2907
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002908 adapter->rx_itr = e1000_update_itr(adapter,
2909 adapter->rx_itr,
2910 adapter->total_rx_packets,
2911 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002912 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2913 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2914 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002915
2916 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2917
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002918 switch (current_itr) {
2919 /* counts and packets in update_itr are dependent on these numbers */
2920 case lowest_latency:
2921 new_itr = 70000;
2922 break;
2923 case low_latency:
2924 new_itr = 20000; /* aka hwitr = ~200 */
2925 break;
2926 case bulk_latency:
2927 new_itr = 4000;
2928 break;
2929 default:
2930 break;
2931 }
2932
2933set_itr_now:
2934 if (new_itr != adapter->itr) {
2935 /* this attempts to bias the interrupt rate towards Bulk
2936 * by adding intermediate steps when interrupt rate is
2937 * increasing */
2938 new_itr = new_itr > adapter->itr ?
2939 min(adapter->itr + (new_itr >> 2), new_itr) :
2940 new_itr;
2941 adapter->itr = new_itr;
2942 E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
2943 }
2944
2945 return;
2946}
2947
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948#define E1000_TX_FLAGS_CSUM 0x00000001
2949#define E1000_TX_FLAGS_VLAN 0x00000002
2950#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002951#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2953#define E1000_TX_FLAGS_VLAN_SHIFT 16
2954
Auke Koke619d522006-04-14 19:04:52 -07002955static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002956e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2957 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002960 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 unsigned int i;
2962 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002963 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2965 int err;
2966
Herbert Xu89114af2006-07-08 13:34:32 -07002967 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 if (skb_header_cloned(skb)) {
2969 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2970 if (err)
2971 return err;
2972 }
2973
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002974 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002975 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002976 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002977 struct iphdr *iph = ip_hdr(skb);
2978 iph->tot_len = 0;
2979 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002980 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2981 iph->daddr, 0,
2982 IPPROTO_TCP,
2983 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002984 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002985 ipcse = skb_transport_offset(skb) - 1;
Auke Koke15fdd02006-08-16 11:28:45 -07002986 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002987 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002988 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002989 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2990 &ipv6_hdr(skb)->daddr,
2991 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002992 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002993 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002994 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002995 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002996 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002997 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 tucse = 0;
2999
3000 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003001 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003003 i = tx_ring->next_to_use;
3004 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003005 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006
3007 context_desc->lower_setup.ip_fields.ipcss = ipcss;
3008 context_desc->lower_setup.ip_fields.ipcso = ipcso;
3009 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
3010 context_desc->upper_setup.tcp_fields.tucss = tucss;
3011 context_desc->upper_setup.tcp_fields.tucso = tucso;
3012 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
3013 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
3014 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
3015 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
3016
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003017 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003018 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003019
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003020 if (++i == tx_ring->count) i = 0;
3021 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
Joe Perchesc3033b02008-03-21 11:06:25 -07003023 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 }
Joe Perchesc3033b02008-03-21 11:06:25 -07003025 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026}
3027
Joe Perchesc3033b02008-03-21 11:06:25 -07003028static bool
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003029e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3030 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031{
3032 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003033 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 unsigned int i;
3035 uint8_t css;
3036
Patrick McHardy84fa7932006-08-29 16:44:56 -07003037 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07003038 css = skb_transport_offset(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003040 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003041 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003042 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Bruce Allanf6c57ba2007-01-18 09:25:28 -08003044 context_desc->lower_setup.ip_config = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 context_desc->upper_setup.tcp_fields.tucss = css;
Herbert Xu628592c2007-04-23 17:06:40 -07003046 context_desc->upper_setup.tcp_fields.tucso =
3047 css + skb->csum_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 context_desc->upper_setup.tcp_fields.tucse = 0;
3049 context_desc->tcp_seg_setup.data = 0;
3050 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
3051
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003052 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003053 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003054
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003055 if (unlikely(++i == tx_ring->count)) i = 0;
3056 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
Joe Perchesc3033b02008-03-21 11:06:25 -07003058 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 }
3060
Joe Perchesc3033b02008-03-21 11:06:25 -07003061 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062}
3063
3064#define E1000_MAX_TXD_PWR 12
3065#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
3066
Auke Koke619d522006-04-14 19:04:52 -07003067static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003068e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3069 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
3070 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 struct e1000_buffer *buffer_info;
3073 unsigned int len = skb->len;
3074 unsigned int offset = 0, size, count = 0, i;
3075 unsigned int f;
3076 len -= skb->data_len;
3077
3078 i = tx_ring->next_to_use;
3079
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003080 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 buffer_info = &tx_ring->buffer_info[i];
3082 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05003083 /* Workaround for Controller erratum --
3084 * descriptor for non-tso packet in a linear SKB that follows a
3085 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003086 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05003087 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07003088 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05003089 tx_ring->last_tx_tso = 0;
3090 size -= 4;
3091 }
3092
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 /* Workaround for premature desc write-backs
3094 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003095 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07003097 /* work-around for errata 10 and it applies
3098 * to all controllers in PCI-X mode
3099 * The fix is to make sure that the first descriptor of a
3100 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3101 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003102 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003103 (size > 2015) && count == 0))
3104 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003105
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 /* Workaround for potential 82544 hang in PCI-X. Avoid
3107 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003108 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3110 size > 4))
3111 size -= 4;
3112
3113 buffer_info->length = size;
3114 buffer_info->dma =
3115 pci_map_single(adapter->pdev,
3116 skb->data + offset,
3117 size,
3118 PCI_DMA_TODEVICE);
3119 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003120 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121
3122 len -= size;
3123 offset += size;
3124 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003125 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 }
3127
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003128 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 struct skb_frag_struct *frag;
3130
3131 frag = &skb_shinfo(skb)->frags[f];
3132 len = frag->size;
3133 offset = frag->page_offset;
3134
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003135 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 buffer_info = &tx_ring->buffer_info[i];
3137 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 /* Workaround for premature desc write-backs
3139 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003140 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 /* Workaround for potential 82544 hang in PCI-X.
3143 * Avoid terminating buffers within evenly-aligned
3144 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003145 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3147 size > 4))
3148 size -= 4;
3149
3150 buffer_info->length = size;
3151 buffer_info->dma =
3152 pci_map_page(adapter->pdev,
3153 frag->page,
3154 offset,
3155 size,
3156 PCI_DMA_TODEVICE);
3157 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003158 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
3160 len -= size;
3161 offset += size;
3162 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003163 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 }
3165 }
3166
3167 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3168 tx_ring->buffer_info[i].skb = skb;
3169 tx_ring->buffer_info[first].next_to_watch = i;
3170
3171 return count;
3172}
3173
Auke Koke619d522006-04-14 19:04:52 -07003174static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003175e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3176 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 struct e1000_tx_desc *tx_desc = NULL;
3179 struct e1000_buffer *buffer_info;
3180 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3181 unsigned int i;
3182
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003183 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3185 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003186 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3187
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003188 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003189 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 }
3191
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003192 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3194 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3195 }
3196
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003197 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 txd_lower |= E1000_TXD_CMD_VLE;
3199 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3200 }
3201
3202 i = tx_ring->next_to_use;
3203
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003204 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 buffer_info = &tx_ring->buffer_info[i];
3206 tx_desc = E1000_TX_DESC(*tx_ring, i);
3207 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3208 tx_desc->lower.data =
3209 cpu_to_le32(txd_lower | buffer_info->length);
3210 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003211 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 }
3213
3214 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3215
3216 /* Force memory writes to complete before letting h/w
3217 * know there are new descriptors to fetch. (Only
3218 * applicable for weak-ordered memory model archs,
3219 * such as IA-64). */
3220 wmb();
3221
3222 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003223 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003224 /* we need this if more than one processor can write to our tail
3225 * at a time, it syncronizes IO on IA64/Altix systems */
3226 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227}
3228
3229/**
3230 * 82547 workaround to avoid controller hang in half-duplex environment.
3231 * The workaround is to avoid queuing a large packet that would span
3232 * the internal Tx FIFO ring boundary by notifying the stack to resend
3233 * the packet at a later time. This gives the Tx FIFO an opportunity to
3234 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3235 * to the beginning of the Tx FIFO.
3236 **/
3237
3238#define E1000_FIFO_HDR 0x10
3239#define E1000_82547_PAD_LEN 0x3E0
3240
Auke Koke619d522006-04-14 19:04:52 -07003241static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
3243{
3244 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3245 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
3246
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003247 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003249 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 goto no_fifo_stall_required;
3251
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003252 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 return 1;
3254
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003255 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 atomic_set(&adapter->tx_fifo_stall, 1);
3257 return 1;
3258 }
3259
3260no_fifo_stall_required:
3261 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003262 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3264 return 0;
3265}
3266
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003267#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07003268static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003269e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
3270{
3271 struct e1000_hw *hw = &adapter->hw;
3272 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003273 if (vlan_tx_tag_present(skb)) {
3274 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003275 ( adapter->hw.mng_cookie.status &
3276 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3277 return 0;
3278 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003279 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003280 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003281 if ((htons(ETH_P_IP) == eth->h_proto)) {
3282 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003283 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003284 if (IPPROTO_UDP == ip->protocol) {
3285 struct udphdr *udp =
3286 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003287 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003288 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003289 offset = (uint8_t *)udp + 8 - skb->data;
3290 length = skb->len - offset;
3291
3292 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003293 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003294 length);
3295 }
3296 }
3297 }
3298 }
3299 return 0;
3300}
3301
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003302static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3303{
3304 struct e1000_adapter *adapter = netdev_priv(netdev);
3305 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3306
3307 netif_stop_queue(netdev);
3308 /* Herbert's original patch had:
3309 * smp_mb__after_netif_stop_queue();
3310 * but since that doesn't exist yet, just open code it. */
3311 smp_mb();
3312
3313 /* We need to check again in a case another CPU has just
3314 * made room available. */
3315 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3316 return -EBUSY;
3317
3318 /* A reprieve! */
3319 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003320 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003321 return 0;
3322}
3323
3324static int e1000_maybe_stop_tx(struct net_device *netdev,
3325 struct e1000_tx_ring *tx_ring, int size)
3326{
3327 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3328 return 0;
3329 return __e1000_maybe_stop_tx(netdev, size);
3330}
3331
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3333static int
3334e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3335{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003336 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003337 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3339 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3340 unsigned int tx_flags = 0;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003341 unsigned int len = skb->len - skb->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 unsigned long flags;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003343 unsigned int nr_frags;
3344 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003346 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 unsigned int f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003349 /* This goes back to the question of how to logically map a tx queue
3350 * to a flow. Right now, performance is impacted slightly negatively
3351 * if using multiple tx queues. If the stack breaks away from a
3352 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003353 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003354
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003355 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 dev_kfree_skb_any(skb);
3357 return NETDEV_TX_OK;
3358 }
3359
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003360 /* 82571 and newer doesn't need the workaround that limited descriptor
3361 * length to 4kB */
3362 if (adapter->hw.mac_type >= e1000_82571)
3363 max_per_txd = 8192;
3364
Herbert Xu79671682006-06-22 02:40:14 -07003365 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003366 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 * make sure there is enough room in the FIFO before
3368 * initiating the DMA for each buffer. The calc is:
3369 * 4 = ceil(buffer len/mss). To make sure we don't
3370 * overrun the FIFO, adjust the max buffer len if mss
3371 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003372 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003373 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 max_per_txd = min(mss << 2, max_per_txd);
3375 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003376
Auke Kok90fb5132006-11-01 08:47:30 -08003377 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3378 * points to just header, pull a few bytes of payload from
3379 * frags into skb->data */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003380 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003381 if (skb->data_len && hdr_len == len) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003382 switch (adapter->hw.mac_type) {
3383 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003384 case e1000_82544:
3385 /* Make sure we have room to chop off 4 bytes,
3386 * and that the end alignment will work out to
3387 * this hardware's requirements
3388 * NOTE: this is a TSO only workaround
3389 * if end byte alignment not correct move us
3390 * into the next dword */
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003391 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003392 break;
3393 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003394 case e1000_82571:
3395 case e1000_82572:
3396 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003397 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003398 pull_size = min((unsigned int)4, skb->data_len);
3399 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003400 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003401 "__pskb_pull_tail failed.\n");
3402 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003403 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003404 }
3405 len = skb->len - skb->data_len;
3406 break;
3407 default:
3408 /* do nothing */
3409 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003410 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 }
3413
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003414 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003415 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003417 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003418
Jeff Kirsherfd803242005-12-13 00:06:22 -05003419 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003420 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003421 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003422
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 count += TXD_USE_COUNT(len, max_txd_pwr);
3424
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003425 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 count++;
3427
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003428 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003429 * in PCI-X mode, so add one more descriptor to the count
3430 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003431 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003432 (len > 2015)))
3433 count++;
3434
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003436 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3438 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003439 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 count += nr_frags;
3441
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003442
3443 if (adapter->hw.tx_pkt_filtering &&
3444 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003445 e1000_transfer_dhcp_info(adapter, skb);
3446
Mark Huthf50393f2007-03-06 08:57:26 -08003447 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003448 /* Collision - tell upper layer to requeue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003449 return NETDEV_TX_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450
3451 /* need: count + 2 desc gap to keep tail from touching
3452 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003453 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003454 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 return NETDEV_TX_BUSY;
3456 }
3457
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003458 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3459 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003461 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003462 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 return NETDEV_TX_BUSY;
3464 }
3465 }
3466
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003467 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468 tx_flags |= E1000_TX_FLAGS_VLAN;
3469 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3470 }
3471
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003472 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003473
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003474 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 if (tso < 0) {
3476 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003477 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 return NETDEV_TX_OK;
3479 }
3480
Jeff Kirsherfd803242005-12-13 00:06:22 -05003481 if (likely(tso)) {
3482 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003484 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 tx_flags |= E1000_TX_FLAGS_CSUM;
3486
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003487 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003488 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003489 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003490 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003491 tx_flags |= E1000_TX_FLAGS_IPV4;
3492
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003493 e1000_tx_queue(adapter, tx_ring, tx_flags,
3494 e1000_tx_map(adapter, tx_ring, skb, first,
3495 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496
3497 netdev->trans_start = jiffies;
3498
3499 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003500 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003502 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 return NETDEV_TX_OK;
3504}
3505
3506/**
3507 * e1000_tx_timeout - Respond to a Tx Hang
3508 * @netdev: network interface device structure
3509 **/
3510
3511static void
3512e1000_tx_timeout(struct net_device *netdev)
3513{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003514 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515
3516 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003517 adapter->tx_timeout_count++;
3518 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519}
3520
3521static void
David Howells65f27f32006-11-22 14:55:48 +00003522e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523{
David Howells65f27f32006-11-22 14:55:48 +00003524 struct e1000_adapter *adapter =
3525 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526
Auke Kok2db10a02006-06-27 09:06:28 -07003527 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528}
3529
3530/**
3531 * e1000_get_stats - Get System Network Statistics
3532 * @netdev: network interface device structure
3533 *
3534 * Returns the address of the device statistics structure.
3535 * The statistics are actually updated from the timer callback.
3536 **/
3537
3538static struct net_device_stats *
3539e1000_get_stats(struct net_device *netdev)
3540{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003541 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003543 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 return &adapter->net_stats;
3545}
3546
3547/**
3548 * e1000_change_mtu - Change the Maximum Transfer Unit
3549 * @netdev: network interface device structure
3550 * @new_mtu: new value for maximum frame size
3551 *
3552 * Returns 0 on success, negative on failure
3553 **/
3554
3555static int
3556e1000_change_mtu(struct net_device *netdev, int new_mtu)
3557{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003558 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003560 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003562 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3563 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3564 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003565 return -EINVAL;
3566 }
3567
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003568 /* Adapter-specific max frame size limits. */
3569 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003570 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003571 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003572 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3573 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003574 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003575 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003576 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003577 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003578 /* Jumbo Frames not supported if:
3579 * - this is not an 82573L device
3580 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003581 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3582 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003583 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3584 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003585 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3586 DPRINTK(PROBE, ERR,
3587 "Jumbo Frames not supported.\n");
3588 return -EINVAL;
3589 }
3590 break;
3591 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003592 /* ERT will be enabled later to enable wire speed receives */
3593
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003594 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003595 case e1000_82571:
3596 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003597 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003598#define MAX_STD_JUMBO_FRAME_SIZE 9234
3599 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3600 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3601 return -EINVAL;
3602 }
3603 break;
3604 default:
3605 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3606 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003607 }
3608
David S. Miller87f50322006-07-31 22:39:40 -07003609 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003610 * means we reserve 2 more, this pushes us to allocate from the next
3611 * larger slab size
3612 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003613
Auke Kok9e2feac2006-04-14 19:05:18 -07003614 if (max_frame <= E1000_RXBUFFER_256)
3615 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3616 else if (max_frame <= E1000_RXBUFFER_512)
3617 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3618 else if (max_frame <= E1000_RXBUFFER_1024)
3619 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3620 else if (max_frame <= E1000_RXBUFFER_2048)
3621 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3622 else if (max_frame <= E1000_RXBUFFER_4096)
3623 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3624 else if (max_frame <= E1000_RXBUFFER_8192)
3625 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3626 else if (max_frame <= E1000_RXBUFFER_16384)
3627 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3628
3629 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003630 if (!adapter->hw.tbi_compatibility_on &&
3631 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3632 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3633 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003634
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003635 netdev->mtu = new_mtu;
Bruce Allan83cd8272006-12-15 10:36:35 +01003636 adapter->hw.max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003637
Auke Kok2db10a02006-06-27 09:06:28 -07003638 if (netif_running(netdev))
3639 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 return 0;
3642}
3643
3644/**
3645 * e1000_update_stats - Update the board statistics counters
3646 * @adapter: board private structure
3647 **/
3648
3649void
3650e1000_update_stats(struct e1000_adapter *adapter)
3651{
3652 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003653 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 unsigned long flags;
3655 uint16_t phy_tmp;
3656
3657#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3658
Linas Vepstas282f33c2006-06-08 22:19:44 -07003659 /*
3660 * Prevent stats update while adapter is being reset, or if the pci
3661 * connection is down.
3662 */
Auke Kok90267292006-06-08 09:30:24 -07003663 if (adapter->link_speed == 0)
3664 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003665 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003666 return;
Auke Kok90267292006-06-08 09:30:24 -07003667
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 spin_lock_irqsave(&adapter->stats_lock, flags);
3669
Masatake YAMATO828d0552007-10-20 03:06:37 +02003670 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 * called from the interrupt context, so they must only
3672 * be written while holding adapter->stats_lock
3673 */
3674
3675 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3676 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3677 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3678 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3679 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3680 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3681 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003682
3683 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003684 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3685 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3686 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3687 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3688 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3689 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003690 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691
3692 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3693 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3694 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3695 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3696 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3697 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3698 adapter->stats.dc += E1000_READ_REG(hw, DC);
3699 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3700 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3701 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3702 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3703 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3704 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3705 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3706 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3707 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3708 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3709 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3710 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3711 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3712 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3713 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3714 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3715 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3716 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3717 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003718
3719 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003720 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3721 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3722 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3723 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3724 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3725 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003726 }
3727
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3729 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3730
3731 /* used for adaptive IFS */
3732
3733 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3734 adapter->stats.tpt += hw->tx_packet_delta;
3735 hw->collision_delta = E1000_READ_REG(hw, COLC);
3736 adapter->stats.colc += hw->collision_delta;
3737
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003738 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3740 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3741 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3742 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3743 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3744 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3745 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003746 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003747 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3748 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003749
3750 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003751 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3752 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3753 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3754 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3755 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3756 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3757 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003758 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760
3761 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 adapter->net_stats.multicast = adapter->stats.mprc;
3763 adapter->net_stats.collisions = adapter->stats.colc;
3764
3765 /* Rx Errors */
3766
Jeff Kirsher87041632006-03-02 18:21:24 -08003767 /* RLEC on some newer hardware can be incorrect so build
3768 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3770 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003771 adapter->stats.ruc + adapter->stats.roc +
3772 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003773 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3774 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3776 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3778
3779 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003780 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3781 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3783 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3784 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Jeff Garzik167fb282006-12-15 10:41:15 -05003785 if (adapter->hw.bad_tx_carr_stats_fd &&
3786 adapter->link_duplex == FULL_DUPLEX) {
3787 adapter->net_stats.tx_carrier_errors = 0;
3788 adapter->stats.tncrs = 0;
3789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790
3791 /* Tx Dropped needs to be maintained elsewhere */
3792
3793 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003794 if (hw->media_type == e1000_media_type_copper) {
3795 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3797 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3798 adapter->phy_stats.idle_errors += phy_tmp;
3799 }
3800
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003801 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 (hw->phy_type == e1000_phy_m88) &&
3803 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3804 adapter->phy_stats.receive_errors += phy_tmp;
3805 }
3806
Jeff Garzik15e376b2006-12-15 11:16:33 -05003807 /* Management Stats */
3808 if (adapter->hw.has_smbus) {
3809 adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
3810 adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
3811 adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
3812 }
3813
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3815}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003816
3817/**
3818 * e1000_intr_msi - Interrupt Handler
3819 * @irq: interrupt number
3820 * @data: pointer to a network interface device structure
3821 **/
3822
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003823static irqreturn_t
3824e1000_intr_msi(int irq, void *data)
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003825{
3826 struct net_device *netdev = data;
3827 struct e1000_adapter *adapter = netdev_priv(netdev);
3828 struct e1000_hw *hw = &adapter->hw;
3829#ifndef CONFIG_E1000_NAPI
3830 int i;
3831#endif
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003832 uint32_t icr = E1000_READ_REG(hw, ICR);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003833
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003834 /* in NAPI mode read ICR disables interrupts using IAM */
3835
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003836 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3837 hw->get_link_status = 1;
3838 /* 80003ES2LAN workaround-- For packet buffer work-around on
3839 * link down event; disable receives here in the ISR and reset
3840 * adapter in watchdog */
3841 if (netif_carrier_ok(netdev) &&
3842 (adapter->hw.mac_type == e1000_80003es2lan)) {
3843 /* disable receives */
3844 uint32_t rctl = E1000_READ_REG(hw, RCTL);
3845 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003846 }
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003847 /* guard against interrupt when we're going down */
3848 if (!test_bit(__E1000_DOWN, &adapter->flags))
3849 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003850 }
3851
3852#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003853 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003854 adapter->total_tx_bytes = 0;
3855 adapter->total_tx_packets = 0;
3856 adapter->total_rx_bytes = 0;
3857 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003858 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003859 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003860 e1000_irq_enable(adapter);
3861#else
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003862 adapter->total_tx_bytes = 0;
3863 adapter->total_rx_bytes = 0;
3864 adapter->total_tx_packets = 0;
3865 adapter->total_rx_packets = 0;
3866
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003867 for (i = 0; i < E1000_MAX_INTR; i++)
3868 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003869 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003870 break;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003871
3872 if (likely(adapter->itr_setting & 3))
3873 e1000_set_itr(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003874#endif
3875
3876 return IRQ_HANDLED;
3877}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878
3879/**
3880 * e1000_intr - Interrupt Handler
3881 * @irq: interrupt number
3882 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 **/
3884
3885static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003886e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887{
3888 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003889 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003891 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003892#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003893 int i;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003894#endif
3895 if (unlikely(!icr))
3896 return IRQ_NONE; /* Not our interrupt */
3897
3898#ifdef CONFIG_E1000_NAPI
3899 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3900 * not set, then the adapter didn't send an interrupt */
3901 if (unlikely(hw->mac_type >= e1000_82571 &&
3902 !(icr & E1000_ICR_INT_ASSERTED)))
3903 return IRQ_NONE;
3904
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003905 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3906 * need for the IMC write */
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003907#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003909 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003911 /* 80003ES2LAN workaround--
3912 * For packet buffer work-around on link down event;
3913 * disable receives here in the ISR and
3914 * reset adapter in watchdog
3915 */
3916 if (netif_carrier_ok(netdev) &&
3917 (adapter->hw.mac_type == e1000_80003es2lan)) {
3918 /* disable receives */
3919 rctl = E1000_READ_REG(hw, RCTL);
3920 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3921 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003922 /* guard against interrupt when we're going down */
3923 if (!test_bit(__E1000_DOWN, &adapter->flags))
3924 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 }
3926
3927#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003928 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003929 /* disable interrupts, without the synchronize_irq bit */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003930 E1000_WRITE_REG(hw, IMC, ~0);
3931 E1000_WRITE_FLUSH(hw);
3932 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003933 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003934 adapter->total_tx_bytes = 0;
3935 adapter->total_tx_packets = 0;
3936 adapter->total_rx_bytes = 0;
3937 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003938 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003939 } else
Auke Kok90fb5132006-11-01 08:47:30 -08003940 /* this really should not happen! if it does it is basically a
3941 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003942 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003943#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003945 * Due to Hub Link bus being occupied, an interrupt
3946 * de-assertion message is not able to be sent.
3947 * When an interrupt assertion message is generated later,
3948 * two messages are re-ordered and sent out.
3949 * That causes APIC to think 82547 is in de-assertion
3950 * state, while 82547 is in assertion state, resulting
3951 * in dead lock. Writing IMC forces 82547 into
3952 * de-assertion state.
3953 */
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003954 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Malli Chilakala26483452005-04-28 19:44:46 -07003955 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003957 adapter->total_tx_bytes = 0;
3958 adapter->total_rx_bytes = 0;
3959 adapter->total_tx_packets = 0;
3960 adapter->total_rx_packets = 0;
3961
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003962 for (i = 0; i < E1000_MAX_INTR; i++)
3963 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003964 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 break;
3966
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003967 if (likely(adapter->itr_setting & 3))
3968 e1000_set_itr(adapter);
3969
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003970 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003972
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003973#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 return IRQ_HANDLED;
3975}
3976
3977#ifdef CONFIG_E1000_NAPI
3978/**
3979 * e1000_clean - NAPI Rx polling callback
3980 * @adapter: board private structure
3981 **/
3982
3983static int
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003984e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003986 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3987 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003988 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003989
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003990 /* Must NOT use netdev_priv macro here. */
3991 adapter = poll_dev->priv;
3992
Auke Kokd3d9e482006-07-14 16:14:23 -07003993 /* e1000_clean is called per-cpu. This lock protects
3994 * tx_ring[0] from being cleaned by multiple cpus
3995 * simultaneously. A failure obtaining the lock means
3996 * tx_ring[0] is currently being cleaned anyway. */
3997 if (spin_trylock(&adapter->tx_queue_lock)) {
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003998 tx_cleaned = e1000_clean_tx_irq(adapter,
3999 &adapter->tx_ring[0]);
Auke Kokd3d9e482006-07-14 16:14:23 -07004000 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004001 }
4002
Auke Kokd3d9e482006-07-14 16:14:23 -07004003 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004004 &work_done, budget);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004005
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004006 if (tx_cleaned)
4007 work_done = budget;
4008
David S. Miller53e52c72008-01-07 21:06:12 -08004009 /* If budget not fully consumed, exit the polling mode */
4010 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004011 if (likely(adapter->itr_setting & 3))
4012 e1000_set_itr(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004013 netif_rx_complete(poll_dev, napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 }
4016
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004017 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018}
4019
4020#endif
4021/**
4022 * e1000_clean_tx_irq - Reclaim resources after transmit completes
4023 * @adapter: board private structure
4024 **/
4025
Joe Perchesc3033b02008-03-21 11:06:25 -07004026static bool
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004027e1000_clean_tx_irq(struct e1000_adapter *adapter,
4028 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 struct net_device *netdev = adapter->netdev;
4031 struct e1000_tx_desc *tx_desc, *eop_desc;
4032 struct e1000_buffer *buffer_info;
4033 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004034#ifdef CONFIG_E1000_NAPI
4035 unsigned int count = 0;
4036#endif
Joe Perchesc3033b02008-03-21 11:06:25 -07004037 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004038 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039
4040 i = tx_ring->next_to_clean;
4041 eop = tx_ring->buffer_info[i].next_to_watch;
4042 eop_desc = E1000_TX_DESC(*tx_ring, eop);
4043
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004044 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Joe Perchesc3033b02008-03-21 11:06:25 -07004045 for (cleaned = false; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 tx_desc = E1000_TX_DESC(*tx_ring, i);
4047 buffer_info = &tx_ring->buffer_info[i];
4048 cleaned = (i == eop);
4049
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004050 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004051 struct sk_buff *skb = buffer_info->skb;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08004052 unsigned int segs, bytecount;
4053 segs = skb_shinfo(skb)->gso_segs ?: 1;
4054 /* multiply data chunks by size of headers */
4055 bytecount = ((segs - 1) * skb_headlen(skb)) +
4056 skb->len;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004057 total_tx_packets += segs;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08004058 total_tx_bytes += bytecount;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004059 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05004060 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08004061 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004063 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004065
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 eop = tx_ring->buffer_info[i].next_to_watch;
4067 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004068#ifdef CONFIG_E1000_NAPI
4069#define E1000_TX_WEIGHT 64
4070 /* weight of a sort for tx, to avoid endless transmit cleanup */
Linus Torvalds46fcc862007-04-19 18:21:01 -07004071 if (count++ == E1000_TX_WEIGHT) break;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004072#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 }
4074
4075 tx_ring->next_to_clean = i;
4076
Auke Kok77b2aad2006-04-14 19:05:25 -07004077#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07004078 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
4079 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
4080 /* Make sure that anybody stopping the queue after this
4081 * sees the new next_to_clean.
4082 */
4083 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004084 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07004085 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004086 ++adapter->restart_queue;
4087 }
Auke Kok77b2aad2006-04-14 19:05:25 -07004088 }
Malli Chilakala26483452005-04-28 19:44:46 -07004089
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004090 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07004091 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 * check with the clearing of time_stamp and movement of i */
Joe Perchesc3033b02008-03-21 11:06:25 -07004093 adapter->detect_tx_hung = false;
Jeff Kirsher392137f2006-01-12 16:50:57 -08004094 if (tx_ring->buffer_info[eop].dma &&
4095 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08004096 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004097 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08004098 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004099
4100 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07004101 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004102 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004103 " TDH <%x>\n"
4104 " TDT <%x>\n"
4105 " next_to_use <%x>\n"
4106 " next_to_clean <%x>\n"
4107 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004108 " time_stamp <%lx>\n"
4109 " next_to_watch <%x>\n"
4110 " jiffies <%lx>\n"
4111 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004112 (unsigned long)((tx_ring - adapter->tx_ring) /
4113 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004114 readl(adapter->hw.hw_addr + tx_ring->tdh),
4115 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004116 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08004117 tx_ring->next_to_clean,
4118 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004119 eop,
4120 jiffies,
4121 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004125 adapter->total_tx_bytes += total_tx_bytes;
4126 adapter->total_tx_packets += total_tx_packets;
Auke Kokef90e4e2007-11-13 20:49:15 -08004127 adapter->net_stats.tx_bytes += total_tx_bytes;
4128 adapter->net_stats.tx_packets += total_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 return cleaned;
4130}
4131
4132/**
4133 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004134 * @adapter: board private structure
4135 * @status_err: receive descriptor status and error fields
4136 * @csum: receive descriptor csum field
4137 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 **/
4139
Auke Koke619d522006-04-14 19:04:52 -07004140static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004142 uint32_t status_err, uint32_t csum,
4143 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004145 uint16_t status = (uint16_t)status_err;
4146 uint8_t errors = (uint8_t)(status_err >> 24);
4147 skb->ip_summed = CHECKSUM_NONE;
4148
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004150 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004152 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004153 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004154 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004155 /* let the stack verify checksum errors */
4156 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 return;
4158 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004159 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004160 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
4161 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004162 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004164 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004165 return;
4166 }
4167 /* It must be a TCP or UDP packet with a valid checksum */
4168 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 /* TCP checksum is good */
4170 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004171 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
4172 /* IP fragment with UDP payload */
4173 /* Hardware complements the payload checksum, so we undo it
4174 * and then put the value in host order for further stack use.
4175 */
Al Viro3e188262007-12-11 19:49:39 +00004176 __sum16 sum = (__force __sum16)htons(csum);
4177 skb->csum = csum_unfold(~sum);
Patrick McHardy84fa7932006-08-29 16:44:56 -07004178 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004180 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181}
4182
4183/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004184 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 * @adapter: board private structure
4186 **/
4187
Joe Perchesc3033b02008-03-21 11:06:25 -07004188static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004190e1000_clean_rx_irq(struct e1000_adapter *adapter,
4191 struct e1000_rx_ring *rx_ring,
4192 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004194e1000_clean_rx_irq(struct e1000_adapter *adapter,
4195 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196#endif
4197{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 struct net_device *netdev = adapter->netdev;
4199 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004200 struct e1000_rx_desc *rx_desc, *next_rxd;
4201 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 unsigned long flags;
4203 uint32_t length;
4204 uint8_t last_byte;
4205 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004206 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004207 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004208 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209
4210 i = rx_ring->next_to_clean;
4211 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004212 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004214 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004215 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004216 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004217
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004219 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 break;
4221 (*work_done)++;
4222#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08004223 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004224 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004225 buffer_info->skb = NULL;
4226
Jeff Kirsher30320be2006-03-02 18:21:57 -08004227 prefetch(skb->data - NET_IP_ALIGN);
4228
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004229 if (++i == rx_ring->count) i = 0;
4230 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004231 prefetch(next_rxd);
4232
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004233 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004234
Joe Perchesc3033b02008-03-21 11:06:25 -07004235 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004236 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004237 pci_unmap_single(pdev,
4238 buffer_info->dma,
4239 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 PCI_DMA_FROMDEVICE);
4241
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242 length = le16_to_cpu(rx_desc->length);
4243
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004244 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4245 /* All receives must fit into a single buffer */
4246 E1000_DBG("%s: Receive packet consumed multiple"
4247 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004248 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004249 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 goto next_desc;
4251 }
4252
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004253 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004255 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 rx_desc->errors, length, last_byte)) {
4257 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004258 e1000_tbi_adjust_stats(&adapter->hw,
4259 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260 length, skb->data);
4261 spin_unlock_irqrestore(&adapter->stats_lock,
4262 flags);
4263 length--;
4264 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004265 /* recycle */
4266 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 goto next_desc;
4268 }
Auke Kok1cb58212006-04-18 12:31:04 -07004269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004271 /* adjust length to remove Ethernet CRC, this must be
4272 * done after the TBI_ACCEPT workaround above */
4273 length -= 4;
4274
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004275 /* probably a little skewed due to removing CRC */
4276 total_rx_bytes += length;
4277 total_rx_packets++;
4278
Jeff Kirshera292ca62006-01-12 16:51:30 -08004279 /* code added for copybreak, this should improve
4280 * performance for small packets with large amounts
4281 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004282 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004283 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004284 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004285 if (new_skb) {
4286 skb_reserve(new_skb, NET_IP_ALIGN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004287 skb_copy_to_linear_data_offset(new_skb,
4288 -NET_IP_ALIGN,
4289 (skb->data -
4290 NET_IP_ALIGN),
4291 (length +
4292 NET_IP_ALIGN));
Jeff Kirshera292ca62006-01-12 16:51:30 -08004293 /* save the skb in buffer_info as good */
4294 buffer_info->skb = skb;
4295 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004296 }
Auke Kok996695d2006-11-01 08:47:50 -08004297 /* else just continue with the old one */
4298 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004299 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004300 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301
4302 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004303 e1000_rx_checksum(adapter,
4304 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004305 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004306 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004307
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308 skb->protocol = eth_type_trans(skb, netdev);
4309#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004310 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08004311 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004313 le16_to_cpu(rx_desc->special) &
4314 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 } else {
4316 netif_receive_skb(skb);
4317 }
4318#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004319 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004320 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 vlan_hwaccel_rx(skb, adapter->vlgrp,
4322 le16_to_cpu(rx_desc->special) &
4323 E1000_RXD_SPC_VLAN_MASK);
4324 } else {
4325 netif_rx(skb);
4326 }
4327#endif /* CONFIG_E1000_NAPI */
4328 netdev->last_rx = jiffies;
4329
4330next_desc:
4331 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004333 /* return some buffers to hardware, one at a time is too slow */
4334 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4335 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4336 cleaned_count = 0;
4337 }
4338
Jeff Kirsher30320be2006-03-02 18:21:57 -08004339 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004340 rx_desc = next_rxd;
4341 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004344
4345 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4346 if (cleaned_count)
4347 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004349 adapter->total_rx_packets += total_rx_packets;
4350 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004351 adapter->net_stats.rx_bytes += total_rx_bytes;
4352 adapter->net_stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 return cleaned;
4354}
4355
4356/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004357 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4358 * @adapter: board private structure
4359 **/
4360
Joe Perchesc3033b02008-03-21 11:06:25 -07004361static bool
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004362#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004363e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4364 struct e1000_rx_ring *rx_ring,
4365 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004366#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004367e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4368 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004369#endif
4370{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004371 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004372 struct net_device *netdev = adapter->netdev;
4373 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004374 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004375 struct e1000_ps_page *ps_page;
4376 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07004377 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004378 unsigned int i, j;
4379 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004380 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004381 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004382 unsigned int total_rx_bytes=0, total_rx_packets=0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004383
4384 i = rx_ring->next_to_clean;
4385 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07004386 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07004387 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004388
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004389 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004390 ps_page = &rx_ring->ps_page[i];
4391 ps_page_dma = &rx_ring->ps_page_dma[i];
4392#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004393 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004394 break;
4395 (*work_done)++;
4396#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004397 skb = buffer_info->skb;
4398
Jeff Kirsher30320be2006-03-02 18:21:57 -08004399 /* in the packet split case this is header only */
4400 prefetch(skb->data - NET_IP_ALIGN);
4401
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004402 if (++i == rx_ring->count) i = 0;
4403 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004404 prefetch(next_rxd);
4405
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004406 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004407
Joe Perchesc3033b02008-03-21 11:06:25 -07004408 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004409 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004410 pci_unmap_single(pdev, buffer_info->dma,
4411 buffer_info->length,
4412 PCI_DMA_FROMDEVICE);
4413
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004414 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004415 E1000_DBG("%s: Packet Split buffers didn't pick up"
4416 " the full packet\n", netdev->name);
4417 dev_kfree_skb_irq(skb);
4418 goto next_desc;
4419 }
4420
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004421 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004422 dev_kfree_skb_irq(skb);
4423 goto next_desc;
4424 }
4425
4426 length = le16_to_cpu(rx_desc->wb.middle.length0);
4427
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004428 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004429 E1000_DBG("%s: Last part of the packet spanning"
4430 " multiple descriptors\n", netdev->name);
4431 dev_kfree_skb_irq(skb);
4432 goto next_desc;
4433 }
4434
4435 /* Good Receive */
4436 skb_put(skb, length);
4437
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004438 {
4439 /* this looks ugly, but it seems compiler issues make it
4440 more efficient than reusing j */
4441 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4442
4443 /* page alloc/put takes too long and effects small packet
4444 * throughput, so unsplit small packets and save the alloc/put*/
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004445 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004446 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004447 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004448 * kmap_atomic, so we can't hold the mapping
4449 * very long */
4450 pci_dma_sync_single_for_cpu(pdev,
4451 ps_page_dma->ps_page_dma[0],
4452 PAGE_SIZE,
4453 PCI_DMA_FROMDEVICE);
4454 vaddr = kmap_atomic(ps_page->ps_page[0],
4455 KM_SKB_DATA_SOFTIRQ);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07004456 memcpy(skb_tail_pointer(skb), vaddr, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004457 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4458 pci_dma_sync_single_for_device(pdev,
4459 ps_page_dma->ps_page_dma[0],
4460 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004461 /* remove the CRC */
4462 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004463 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004464 goto copydone;
4465 } /* if */
4466 }
Auke Kok90fb5132006-11-01 08:47:30 -08004467
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004468 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004469 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004470 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004471 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4472 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4473 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004474 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4475 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004476 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004477 skb->len += length;
4478 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004479 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004480 }
4481
Auke Kokf235a2a2006-07-14 16:14:34 -07004482 /* strip the ethernet crc, problem is we're using pages now so
4483 * this whole operation can get a little cpu intensive */
4484 pskb_trim(skb, skb->len - 4);
4485
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004486copydone:
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004487 total_rx_bytes += skb->len;
4488 total_rx_packets++;
4489
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004490 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004491 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004492 skb->protocol = eth_type_trans(skb, netdev);
4493
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004494 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004495 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004496 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004497#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004498 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004499 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004500 le16_to_cpu(rx_desc->wb.middle.vlan) &
4501 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004502 } else {
4503 netif_receive_skb(skb);
4504 }
4505#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004506 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004507 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004508 le16_to_cpu(rx_desc->wb.middle.vlan) &
4509 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004510 } else {
4511 netif_rx(skb);
4512 }
4513#endif /* CONFIG_E1000_NAPI */
4514 netdev->last_rx = jiffies;
4515
4516next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004517 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004518 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004519
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004520 /* return some buffers to hardware, one at a time is too slow */
4521 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4522 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4523 cleaned_count = 0;
4524 }
4525
Jeff Kirsher30320be2006-03-02 18:21:57 -08004526 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004527 rx_desc = next_rxd;
4528 buffer_info = next_buffer;
4529
Malli Chilakala683a38f2005-06-17 17:43:25 -07004530 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004531 }
4532 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004533
4534 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4535 if (cleaned_count)
4536 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004537
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004538 adapter->total_rx_packets += total_rx_packets;
4539 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004540 adapter->net_stats.rx_bytes += total_rx_bytes;
4541 adapter->net_stats.rx_packets += total_rx_packets;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004542 return cleaned;
4543}
4544
4545/**
4546 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 * @adapter: address of board private structure
4548 **/
4549
4550static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004551e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004552 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004553 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555 struct net_device *netdev = adapter->netdev;
4556 struct pci_dev *pdev = adapter->pdev;
4557 struct e1000_rx_desc *rx_desc;
4558 struct e1000_buffer *buffer_info;
4559 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004560 unsigned int i;
4561 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562
4563 i = rx_ring->next_to_use;
4564 buffer_info = &rx_ring->buffer_info[i];
4565
Jeff Kirshera292ca62006-01-12 16:51:30 -08004566 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004567 skb = buffer_info->skb;
4568 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004569 skb_trim(skb, 0);
4570 goto map_skb;
4571 }
4572
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004573 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004574 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004576 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 break;
4578 }
4579
Malli Chilakala26483452005-04-28 19:44:46 -07004580 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4582 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004583 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4584 "at %p\n", bufsz, skb->data);
4585 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004586 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004587 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588 if (!skb) {
4589 dev_kfree_skb(oldskb);
4590 break;
4591 }
Malli Chilakala26483452005-04-28 19:44:46 -07004592
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4594 /* give up */
4595 dev_kfree_skb(skb);
4596 dev_kfree_skb(oldskb);
4597 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004599
4600 /* Use new allocation */
4601 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 /* Make buffer alignment 2 beyond a 16 byte boundary
4604 * this will result in a 16 byte aligned IP header after
4605 * the 14 byte MAC header is removed
4606 */
4607 skb_reserve(skb, NET_IP_ALIGN);
4608
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609 buffer_info->skb = skb;
4610 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004611map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612 buffer_info->dma = pci_map_single(pdev,
4613 skb->data,
4614 adapter->rx_buffer_len,
4615 PCI_DMA_FROMDEVICE);
4616
Malli Chilakala26483452005-04-28 19:44:46 -07004617 /* Fix for errata 23, can't cross 64kB boundary */
4618 if (!e1000_check_64k_bound(adapter,
4619 (void *)(unsigned long)buffer_info->dma,
4620 adapter->rx_buffer_len)) {
4621 DPRINTK(RX_ERR, ERR,
4622 "dma align check failed: %u bytes at %p\n",
4623 adapter->rx_buffer_len,
4624 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 dev_kfree_skb(skb);
4626 buffer_info->skb = NULL;
4627
Malli Chilakala26483452005-04-28 19:44:46 -07004628 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 adapter->rx_buffer_len,
4630 PCI_DMA_FROMDEVICE);
4631
4632 break; /* while !buffer_info->skb */
4633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 rx_desc = E1000_RX_DESC(*rx_ring, i);
4635 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4636
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004637 if (unlikely(++i == rx_ring->count))
4638 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 buffer_info = &rx_ring->buffer_info[i];
4640 }
4641
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004642 if (likely(rx_ring->next_to_use != i)) {
4643 rx_ring->next_to_use = i;
4644 if (unlikely(i-- == 0))
4645 i = (rx_ring->count - 1);
4646
4647 /* Force memory writes to complete before letting h/w
4648 * know there are new descriptors to fetch. (Only
4649 * applicable for weak-ordered memory model archs,
4650 * such as IA-64). */
4651 wmb();
4652 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654}
4655
4656/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004657 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4658 * @adapter: address of board private structure
4659 **/
4660
4661static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004662e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004663 struct e1000_rx_ring *rx_ring,
4664 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004665{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004666 struct net_device *netdev = adapter->netdev;
4667 struct pci_dev *pdev = adapter->pdev;
4668 union e1000_rx_desc_packet_split *rx_desc;
4669 struct e1000_buffer *buffer_info;
4670 struct e1000_ps_page *ps_page;
4671 struct e1000_ps_page_dma *ps_page_dma;
4672 struct sk_buff *skb;
4673 unsigned int i, j;
4674
4675 i = rx_ring->next_to_use;
4676 buffer_info = &rx_ring->buffer_info[i];
4677 ps_page = &rx_ring->ps_page[i];
4678 ps_page_dma = &rx_ring->ps_page_dma[i];
4679
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004680 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004681 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4682
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004683 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004684 if (j < adapter->rx_ps_pages) {
4685 if (likely(!ps_page->ps_page[j])) {
4686 ps_page->ps_page[j] =
4687 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004688 if (unlikely(!ps_page->ps_page[j])) {
4689 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004690 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004691 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004692 ps_page_dma->ps_page_dma[j] =
4693 pci_map_page(pdev,
4694 ps_page->ps_page[j],
4695 0, PAGE_SIZE,
4696 PCI_DMA_FROMDEVICE);
4697 }
4698 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004699 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004700 * this info.
4701 */
4702 rx_desc->read.buffer_addr[j+1] =
4703 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4704 } else
Al Viro3e188262007-12-11 19:49:39 +00004705 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004706 }
4707
David S. Miller87f50322006-07-31 22:39:40 -07004708 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004709 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004710
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004711 if (unlikely(!skb)) {
4712 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004713 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004714 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004715
4716 /* Make buffer alignment 2 beyond a 16 byte boundary
4717 * this will result in a 16 byte aligned IP header after
4718 * the 14 byte MAC header is removed
4719 */
4720 skb_reserve(skb, NET_IP_ALIGN);
4721
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004722 buffer_info->skb = skb;
4723 buffer_info->length = adapter->rx_ps_bsize0;
4724 buffer_info->dma = pci_map_single(pdev, skb->data,
4725 adapter->rx_ps_bsize0,
4726 PCI_DMA_FROMDEVICE);
4727
4728 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4729
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004730 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004731 buffer_info = &rx_ring->buffer_info[i];
4732 ps_page = &rx_ring->ps_page[i];
4733 ps_page_dma = &rx_ring->ps_page_dma[i];
4734 }
4735
4736no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004737 if (likely(rx_ring->next_to_use != i)) {
4738 rx_ring->next_to_use = i;
4739 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4740
4741 /* Force memory writes to complete before letting h/w
4742 * know there are new descriptors to fetch. (Only
4743 * applicable for weak-ordered memory model archs,
4744 * such as IA-64). */
4745 wmb();
4746 /* Hardware increments by 16 bytes, but packet split
4747 * descriptors are 32 bytes...so we increment tail
4748 * twice as much.
4749 */
4750 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4751 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004752}
4753
4754/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4756 * @adapter:
4757 **/
4758
4759static void
4760e1000_smartspeed(struct e1000_adapter *adapter)
4761{
4762 uint16_t phy_status;
4763 uint16_t phy_ctrl;
4764
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004765 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4767 return;
4768
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004769 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 /* If Master/Slave config fault is asserted twice,
4771 * we assume back-to-back */
4772 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004773 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004775 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004777 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4779 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4780 phy_ctrl);
4781 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004782 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4784 &phy_ctrl)) {
4785 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4786 MII_CR_RESTART_AUTO_NEG);
4787 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4788 phy_ctrl);
4789 }
4790 }
4791 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004792 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 /* If still no link, perhaps using 2/3 pair cable */
4794 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4795 phy_ctrl |= CR_1000T_MS_ENABLE;
4796 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
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, &phy_ctrl)) {
4799 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4800 MII_CR_RESTART_AUTO_NEG);
4801 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4802 }
4803 }
4804 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004805 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806 adapter->smartspeed = 0;
4807}
4808
4809/**
4810 * e1000_ioctl -
4811 * @netdev:
4812 * @ifreq:
4813 * @cmd:
4814 **/
4815
4816static int
4817e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4818{
4819 switch (cmd) {
4820 case SIOCGMIIPHY:
4821 case SIOCGMIIREG:
4822 case SIOCSMIIREG:
4823 return e1000_mii_ioctl(netdev, ifr, cmd);
4824 default:
4825 return -EOPNOTSUPP;
4826 }
4827}
4828
4829/**
4830 * e1000_mii_ioctl -
4831 * @netdev:
4832 * @ifreq:
4833 * @cmd:
4834 **/
4835
4836static int
4837e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4838{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004839 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840 struct mii_ioctl_data *data = if_mii(ifr);
4841 int retval;
4842 uint16_t mii_reg;
4843 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004844 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004846 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 return -EOPNOTSUPP;
4848
4849 switch (cmd) {
4850 case SIOCGMIIPHY:
4851 data->phy_id = adapter->hw.phy_addr;
4852 break;
4853 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004854 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004856 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004857 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004858 &data->val_out)) {
4859 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004861 }
4862 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 break;
4864 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004865 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004867 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 return -EFAULT;
4869 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004870 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004871 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004872 mii_reg)) {
4873 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004875 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004876 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Auke Kokdc86d322006-04-18 12:30:51 -07004877 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 switch (data->reg_num) {
4879 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004880 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004882 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 adapter->hw.autoneg = 1;
4884 adapter->hw.autoneg_advertised = 0x2F;
4885 } else {
4886 if (mii_reg & 0x40)
4887 spddplx = SPEED_1000;
4888 else if (mii_reg & 0x2000)
4889 spddplx = SPEED_100;
4890 else
4891 spddplx = SPEED_10;
4892 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004893 ? DUPLEX_FULL :
4894 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 retval = e1000_set_spd_dplx(adapter,
4896 spddplx);
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004897 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 return retval;
4899 }
Auke Kok2db10a02006-06-27 09:06:28 -07004900 if (netif_running(adapter->netdev))
4901 e1000_reinit_locked(adapter);
4902 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903 e1000_reset(adapter);
4904 break;
4905 case M88E1000_PHY_SPEC_CTRL:
4906 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004907 if (e1000_phy_reset(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 return -EIO;
4909 break;
4910 }
4911 } else {
4912 switch (data->reg_num) {
4913 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004914 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004916 if (netif_running(adapter->netdev))
4917 e1000_reinit_locked(adapter);
4918 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919 e1000_reset(adapter);
4920 break;
4921 }
4922 }
4923 break;
4924 default:
4925 return -EOPNOTSUPP;
4926 }
4927 return E1000_SUCCESS;
4928}
4929
4930void
4931e1000_pci_set_mwi(struct e1000_hw *hw)
4932{
4933 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004934 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004936 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004937 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938}
4939
4940void
4941e1000_pci_clear_mwi(struct e1000_hw *hw)
4942{
4943 struct e1000_adapter *adapter = hw->back;
4944
4945 pci_clear_mwi(adapter->pdev);
4946}
4947
Peter Oruba007755e2007-09-28 22:42:06 -07004948int
4949e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4950{
4951 struct e1000_adapter *adapter = hw->back;
4952 return pcix_get_mmrbc(adapter->pdev);
4953}
4954
4955void
4956e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4957{
4958 struct e1000_adapter *adapter = hw->back;
4959 pcix_set_mmrbc(adapter->pdev, mmrbc);
4960}
4961
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004962int32_t
4963e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4964{
4965 struct e1000_adapter *adapter = hw->back;
4966 uint16_t cap_offset;
4967
4968 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4969 if (!cap_offset)
4970 return -E1000_ERR_CONFIG;
4971
4972 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4973
4974 return E1000_SUCCESS;
4975}
4976
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977void
4978e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4979{
4980 outl(value, port);
4981}
4982
4983static void
4984e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4985{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004986 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 uint32_t ctrl, rctl;
4988
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004989 if (!test_bit(__E1000_DOWN, &adapter->flags))
4990 e1000_irq_disable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991 adapter->vlgrp = grp;
4992
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004993 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 /* enable VLAN tag insert/strip */
4995 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4996 ctrl |= E1000_CTRL_VME;
4997 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4998
Auke Kokcd94dd02006-06-27 09:08:22 -07004999 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08005000 /* enable VLAN receive filtering */
5001 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5002 rctl |= E1000_RCTL_VFE;
5003 rctl &= ~E1000_RCTL_CFIEN;
5004 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5005 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07005006 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 } else {
5008 /* disable 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 /* disable VLAN filtering */
5015 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5016 rctl &= ~E1000_RCTL_VFE;
5017 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5018 if (adapter->mng_vlan_id !=
5019 (uint16_t)E1000_MNG_VLAN_NONE) {
5020 e1000_vlan_rx_kill_vid(netdev,
5021 adapter->mng_vlan_id);
5022 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
5023 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 }
5026
Jesse Brandeburg9150b762008-03-21 11:06:58 -07005027 if (!test_bit(__E1000_DOWN, &adapter->flags))
5028 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029}
5030
5031static void
5032e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
5033{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005034 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005036
5037 if ((adapter->hw.mng_cookie.status &
5038 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
5039 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005040 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041 /* add VID to filter table */
5042 index = (vid >> 5) & 0x7F;
5043 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5044 vfta |= (1 << (vid & 0x1F));
5045 e1000_write_vfta(&adapter->hw, index, vfta);
5046}
5047
5048static void
5049e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
5050{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005051 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052 uint32_t vfta, index;
5053
Jesse Brandeburg9150b762008-03-21 11:06:58 -07005054 if (!test_bit(__E1000_DOWN, &adapter->flags))
5055 e1000_irq_disable(adapter);
Dan Aloni5c15bde2007-03-02 20:44:51 -08005056 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg9150b762008-03-21 11:06:58 -07005057 if (!test_bit(__E1000_DOWN, &adapter->flags))
5058 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005060 if ((adapter->hw.mng_cookie.status &
5061 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08005062 (vid == adapter->mng_vlan_id)) {
5063 /* release control to f/w */
5064 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005065 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08005066 }
5067
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 /* remove VID from filter table */
5069 index = (vid >> 5) & 0x7F;
5070 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5071 vfta &= ~(1 << (vid & 0x1F));
5072 e1000_write_vfta(&adapter->hw, index, vfta);
5073}
5074
5075static void
5076e1000_restore_vlan(struct e1000_adapter *adapter)
5077{
5078 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
5079
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005080 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005082 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08005083 if (!vlan_group_get_device(adapter->vlgrp, vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 continue;
5085 e1000_vlan_rx_add_vid(adapter->netdev, vid);
5086 }
5087 }
5088}
5089
5090int
5091e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
5092{
5093 adapter->hw.autoneg = 0;
5094
Malli Chilakala69213682005-06-17 17:44:20 -07005095 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005096 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07005097 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
5098 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
5099 return -EINVAL;
5100 }
5101
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005102 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103 case SPEED_10 + DUPLEX_HALF:
5104 adapter->hw.forced_speed_duplex = e1000_10_half;
5105 break;
5106 case SPEED_10 + DUPLEX_FULL:
5107 adapter->hw.forced_speed_duplex = e1000_10_full;
5108 break;
5109 case SPEED_100 + DUPLEX_HALF:
5110 adapter->hw.forced_speed_duplex = e1000_100_half;
5111 break;
5112 case SPEED_100 + DUPLEX_FULL:
5113 adapter->hw.forced_speed_duplex = e1000_100_full;
5114 break;
5115 case SPEED_1000 + DUPLEX_FULL:
5116 adapter->hw.autoneg = 1;
5117 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
5118 break;
5119 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5120 default:
Malli Chilakala26483452005-04-28 19:44:46 -07005121 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 return -EINVAL;
5123 }
5124 return 0;
5125}
5126
5127static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07005128e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129{
5130 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005131 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005132 uint32_t ctrl, ctrl_ext, rctl, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07005134#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08005135 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07005136#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137
5138 netif_device_detach(netdev);
5139
Auke Kok2db10a02006-06-27 09:06:28 -07005140 if (netif_running(netdev)) {
5141 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07005143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005145#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005146 retval = pci_save_state(pdev);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005147 if (retval)
5148 return retval;
5149#endif
5150
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005152 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153 wufc &= ~E1000_WUFC_LNKC;
5154
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005155 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005157 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158
5159 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005160 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5162 rctl |= E1000_RCTL_MPE;
5163 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5164 }
5165
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005166 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5168 /* advertise wake from D3Cold */
5169 #define E1000_CTRL_ADVD3WUC 0x00100000
5170 /* phy power management enable */
5171 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5172 ctrl |= E1000_CTRL_ADVD3WUC |
5173 E1000_CTRL_EN_PHY_PWR_MGMT;
5174 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5175 }
5176
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005177 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178 adapter->hw.media_type == e1000_media_type_internal_serdes) {
5179 /* keep the laser running in D3 */
5180 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
5181 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5182 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
5183 }
5184
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005185 /* Allow time for pending master requests to run */
5186 e1000_disable_pciex_master(&adapter->hw);
5187
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
5189 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07005190 pci_enable_wake(pdev, PCI_D3hot, 1);
5191 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192 } else {
5193 E1000_WRITE_REG(&adapter->hw, WUC, 0);
5194 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07005195 pci_enable_wake(pdev, PCI_D3hot, 0);
5196 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197 }
5198
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005199 e1000_release_manageability(adapter);
5200
5201 /* make sure adapter isn't asleep if manageability is enabled */
5202 if (adapter->en_mng_pt) {
5203 pci_enable_wake(pdev, PCI_D3hot, 1);
5204 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205 }
5206
Auke Kokcd94dd02006-06-27 09:08:22 -07005207 if (adapter->hw.phy_type == e1000_phy_igp_3)
5208 e1000_phy_powerdown_workaround(&adapter->hw);
5209
Auke Kokedd106f2006-11-06 08:57:12 -08005210 if (netif_running(netdev))
5211 e1000_free_irq(adapter);
5212
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005213 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5214 * would have already happened in close and is redundant. */
5215 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005216
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005218
Auke Kokd0e027d2006-04-14 19:04:40 -07005219 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220
5221 return 0;
5222}
5223
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005224#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225static int
5226e1000_resume(struct pci_dev *pdev)
5227{
5228 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005229 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005230 uint32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231
Auke Kokd0e027d2006-04-14 19:04:40 -07005232 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005233 pci_restore_state(pdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005234 if ((err = pci_enable_device(pdev))) {
5235 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5236 return err;
5237 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005238 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239
Auke Kokd0e027d2006-04-14 19:04:40 -07005240 pci_enable_wake(pdev, PCI_D3hot, 0);
5241 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242
Auke Kokedd106f2006-11-06 08:57:12 -08005243 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
5244 return err;
5245
5246 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247 e1000_reset(adapter);
5248 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5249
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005250 e1000_init_manageability(adapter);
5251
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005252 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253 e1000_up(adapter);
5254
5255 netif_device_attach(netdev);
5256
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005257 /* If the controller is 82573 and f/w is AMT, do not set
5258 * DRV_LOAD until the interface is up. For all other cases,
5259 * let the f/w know that the h/w is now under the control
5260 * of the driver. */
5261 if (adapter->hw.mac_type != e1000_82573 ||
5262 !e1000_check_mng_mode(&adapter->hw))
5263 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005264
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265 return 0;
5266}
5267#endif
Auke Kokc653e632006-05-23 13:35:57 -07005268
5269static void e1000_shutdown(struct pci_dev *pdev)
5270{
5271 e1000_suspend(pdev, PMSG_SUSPEND);
5272}
5273
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274#ifdef CONFIG_NET_POLL_CONTROLLER
5275/*
5276 * Polling 'interrupt' - used by things like netconsole to send skbs
5277 * without having to re-enable interrupts. It's not called while
5278 * the interrupt routine is executing.
5279 */
5280static void
Malli Chilakala26483452005-04-28 19:44:46 -07005281e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005283 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005284
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005286 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07005287 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08005288#ifndef CONFIG_E1000_NAPI
5289 adapter->clean_rx(adapter, adapter->rx_ring);
5290#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291 enable_irq(adapter->pdev->irq);
5292}
5293#endif
5294
Auke Kok90267292006-06-08 09:30:24 -07005295/**
5296 * e1000_io_error_detected - called when PCI error is detected
5297 * @pdev: Pointer to PCI device
5298 * @state: The current pci conneection state
5299 *
5300 * This function is called after a PCI bus error affecting
5301 * this device has been detected.
5302 */
5303static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5304{
5305 struct net_device *netdev = pci_get_drvdata(pdev);
5306 struct e1000_adapter *adapter = netdev->priv;
5307
5308 netif_device_detach(netdev);
5309
5310 if (netif_running(netdev))
5311 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005312 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005313
5314 /* Request a slot slot reset. */
5315 return PCI_ERS_RESULT_NEED_RESET;
5316}
5317
5318/**
5319 * e1000_io_slot_reset - called after the pci bus has been reset.
5320 * @pdev: Pointer to PCI device
5321 *
5322 * Restart the card from scratch, as if from a cold-boot. Implementation
5323 * resembles the first-half of the e1000_resume routine.
5324 */
5325static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5326{
5327 struct net_device *netdev = pci_get_drvdata(pdev);
5328 struct e1000_adapter *adapter = netdev->priv;
5329
5330 if (pci_enable_device(pdev)) {
5331 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5332 return PCI_ERS_RESULT_DISCONNECT;
5333 }
5334 pci_set_master(pdev);
5335
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005336 pci_enable_wake(pdev, PCI_D3hot, 0);
5337 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005338
Auke Kok90267292006-06-08 09:30:24 -07005339 e1000_reset(adapter);
5340 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5341
5342 return PCI_ERS_RESULT_RECOVERED;
5343}
5344
5345/**
5346 * e1000_io_resume - called when traffic can start flowing again.
5347 * @pdev: Pointer to PCI device
5348 *
5349 * This callback is called when the error recovery driver tells us that
5350 * its OK to resume normal operation. Implementation resembles the
5351 * second-half of the e1000_resume routine.
5352 */
5353static void e1000_io_resume(struct pci_dev *pdev)
5354{
5355 struct net_device *netdev = pci_get_drvdata(pdev);
5356 struct e1000_adapter *adapter = netdev->priv;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005357
5358 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005359
5360 if (netif_running(netdev)) {
5361 if (e1000_up(adapter)) {
5362 printk("e1000: can't bring device back up after reset\n");
5363 return;
5364 }
5365 }
5366
5367 netif_device_attach(netdev);
5368
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005369 /* If the controller is 82573 and f/w is AMT, do not set
5370 * DRV_LOAD until the interface is up. For all other cases,
5371 * let the f/w know that the h/w is now under the control
5372 * of the driver. */
5373 if (adapter->hw.mac_type != e1000_82573 ||
5374 !e1000_check_mng_mode(&adapter->hw))
5375 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005376
Auke Kok90267292006-06-08 09:30:24 -07005377}
5378
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379/* e1000_main.c */