blob: cf12b05cd011fcbd4db80d12273731d4c4ff9c03 [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 */
50static struct pci_device_id e1000_pci_tbl[] = {
51 INTEL_E1000_ETHERNET_DEVICE(0x1000),
52 INTEL_E1000_ETHERNET_DEVICE(0x1001),
53 INTEL_E1000_ETHERNET_DEVICE(0x1004),
54 INTEL_E1000_ETHERNET_DEVICE(0x1008),
55 INTEL_E1000_ETHERNET_DEVICE(0x1009),
56 INTEL_E1000_ETHERNET_DEVICE(0x100C),
57 INTEL_E1000_ETHERNET_DEVICE(0x100D),
58 INTEL_E1000_ETHERNET_DEVICE(0x100E),
59 INTEL_E1000_ETHERNET_DEVICE(0x100F),
60 INTEL_E1000_ETHERNET_DEVICE(0x1010),
61 INTEL_E1000_ETHERNET_DEVICE(0x1011),
62 INTEL_E1000_ETHERNET_DEVICE(0x1012),
63 INTEL_E1000_ETHERNET_DEVICE(0x1013),
64 INTEL_E1000_ETHERNET_DEVICE(0x1014),
65 INTEL_E1000_ETHERNET_DEVICE(0x1015),
66 INTEL_E1000_ETHERNET_DEVICE(0x1016),
67 INTEL_E1000_ETHERNET_DEVICE(0x1017),
68 INTEL_E1000_ETHERNET_DEVICE(0x1018),
69 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -070070 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 INTEL_E1000_ETHERNET_DEVICE(0x101D),
72 INTEL_E1000_ETHERNET_DEVICE(0x101E),
73 INTEL_E1000_ETHERNET_DEVICE(0x1026),
74 INTEL_E1000_ETHERNET_DEVICE(0x1027),
75 INTEL_E1000_ETHERNET_DEVICE(0x1028),
76 INTEL_E1000_ETHERNET_DEVICE(0x1075),
77 INTEL_E1000_ETHERNET_DEVICE(0x1076),
78 INTEL_E1000_ETHERNET_DEVICE(0x1077),
79 INTEL_E1000_ETHERNET_DEVICE(0x1078),
80 INTEL_E1000_ETHERNET_DEVICE(0x1079),
81 INTEL_E1000_ETHERNET_DEVICE(0x107A),
82 INTEL_E1000_ETHERNET_DEVICE(0x107B),
83 INTEL_E1000_ETHERNET_DEVICE(0x107C),
84 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080085 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080086 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 /* required last entry */
88 {0,}
89};
90
91MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
92
Nicholas Nunley35574762006-09-27 12:53:34 -070093int e1000_up(struct e1000_adapter *adapter);
94void e1000_down(struct e1000_adapter *adapter);
95void e1000_reinit_locked(struct e1000_adapter *adapter);
96void e1000_reset(struct e1000_adapter *adapter);
Joe Perches406874a2008-04-03 10:06:32 -070097int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx);
Nicholas Nunley35574762006-09-27 12:53:34 -070098int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
99int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
100void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
101void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100102static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700103 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100104static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700105 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100106static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700107 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100108static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700109 struct e1000_rx_ring *rx_ring);
110void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112static int e1000_init_module(void);
113static void e1000_exit_module(void);
114static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
115static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400116static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117static int e1000_sw_init(struct e1000_adapter *adapter);
118static int e1000_open(struct net_device *netdev);
119static int e1000_close(struct net_device *netdev);
120static void e1000_configure_tx(struct e1000_adapter *adapter);
121static void e1000_configure_rx(struct e1000_adapter *adapter);
122static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400123static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
124static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
125static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
126 struct e1000_tx_ring *tx_ring);
127static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
128 struct e1000_rx_ring *rx_ring);
Patrick McHardydb0ce502007-11-13 20:54:59 -0800129static void e1000_set_rx_mode(struct net_device *netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130static void e1000_update_phy_info(unsigned long data);
131static void e1000_watchdog(unsigned long data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132static void e1000_82547_tx_fifo_stall(unsigned long data);
133static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
134static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
135static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
136static int e1000_set_mac(struct net_device *netdev, void *p);
David Howells7d12e782006-10-05 14:55:46 +0100137static irqreturn_t e1000_intr(int irq, void *data);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800138static irqreturn_t e1000_intr_msi(int irq, void *data);
Joe Perchesc3033b02008-03-21 11:06:25 -0700139static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
140 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700142static int e1000_clean(struct napi_struct *napi, int budget);
Joe Perchesc3033b02008-03-21 11:06:25 -0700143static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
144 struct e1000_rx_ring *rx_ring,
145 int *work_done, int work_to_do);
146static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
148 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#else
Joe Perchesc3033b02008-03-21 11:06:25 -0700150static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
151 struct e1000_rx_ring *rx_ring);
152static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
153 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400155static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800156 struct e1000_rx_ring *rx_ring,
157 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400158static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800159 struct e1000_rx_ring *rx_ring,
160 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
162static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
163 int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
165static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
166static void e1000_tx_timeout(struct net_device *dev);
David Howells65f27f32006-11-22 14:55:48 +0000167static void e1000_reset_task(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700169static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
170 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
Joe Perches406874a2008-04-03 10:06:32 -0700173static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
174static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175static void e1000_restore_vlan(struct e1000_adapter *adapter);
176
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700177static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Auke Kok6fdfef12006-06-27 09:06:36 -0700178#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179static int e1000_resume(struct pci_dev *pdev);
180#endif
Auke Kokc653e632006-05-23 13:35:57 -0700181static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183#ifdef CONFIG_NET_POLL_CONTROLLER
184/* for netdump / net console */
185static void e1000_netpoll (struct net_device *netdev);
186#endif
187
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100188#define COPYBREAK_DEFAULT 256
189static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
190module_param(copybreak, uint, 0644);
191MODULE_PARM_DESC(copybreak,
192 "Maximum size of packet that is copied to a new buffer on receive");
193
Auke Kok90267292006-06-08 09:30:24 -0700194static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
195 pci_channel_state_t state);
196static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
197static void e1000_io_resume(struct pci_dev *pdev);
198
199static struct pci_error_handlers e1000_err_handler = {
200 .error_detected = e1000_io_error_detected,
201 .slot_reset = e1000_io_slot_reset,
202 .resume = e1000_io_resume,
203};
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -0400204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205static struct pci_driver e1000_driver = {
206 .name = e1000_driver_name,
207 .id_table = e1000_pci_tbl,
208 .probe = e1000_probe,
209 .remove = __devexit_p(e1000_remove),
Auke Kokc4e24f02006-09-27 12:53:19 -0700210#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 /* Power Managment Hooks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 .suspend = e1000_suspend,
Auke Kokc653e632006-05-23 13:35:57 -0700213 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#endif
Auke Kok90267292006-06-08 09:30:24 -0700215 .shutdown = e1000_shutdown,
216 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217};
218
219MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
220MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
221MODULE_LICENSE("GPL");
222MODULE_VERSION(DRV_VERSION);
223
224static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
225module_param(debug, int, 0);
226MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
227
228/**
229 * e1000_init_module - Driver Registration Routine
230 *
231 * e1000_init_module is the first routine called when the driver is
232 * loaded. All it does is register with the PCI subsystem.
233 **/
234
235static int __init
236e1000_init_module(void)
237{
238 int ret;
239 printk(KERN_INFO "%s - version %s\n",
240 e1000_driver_string, e1000_driver_version);
241
242 printk(KERN_INFO "%s\n", e1000_copyright);
243
Jeff Garzik29917622006-08-19 17:48:59 -0400244 ret = pci_register_driver(&e1000_driver);
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100245 if (copybreak != COPYBREAK_DEFAULT) {
246 if (copybreak == 0)
247 printk(KERN_INFO "e1000: copybreak disabled\n");
248 else
249 printk(KERN_INFO "e1000: copybreak enabled for "
250 "packets <= %u bytes\n", copybreak);
251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return ret;
253}
254
255module_init(e1000_init_module);
256
257/**
258 * e1000_exit_module - Driver Exit Cleanup Routine
259 *
260 * e1000_exit_module is called just before the driver is removed
261 * from memory.
262 **/
263
264static void __exit
265e1000_exit_module(void)
266{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 pci_unregister_driver(&e1000_driver);
268}
269
270module_exit(e1000_exit_module);
271
Auke Kok2db10a02006-06-27 09:06:28 -0700272static int e1000_request_irq(struct e1000_adapter *adapter)
273{
274 struct net_device *netdev = adapter->netdev;
Al Viro3e188262007-12-11 19:49:39 +0000275 irq_handler_t handler = e1000_intr;
Auke Koke94bd232007-05-16 01:49:46 -0700276 int irq_flags = IRQF_SHARED;
277 int err;
Auke Kok2db10a02006-06-27 09:06:28 -0700278
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800279 if (adapter->hw.mac_type >= e1000_82571) {
Auke Koke94bd232007-05-16 01:49:46 -0700280 adapter->have_msi = !pci_enable_msi(adapter->pdev);
281 if (adapter->have_msi) {
Al Viro3e188262007-12-11 19:49:39 +0000282 handler = e1000_intr_msi;
Auke Koke94bd232007-05-16 01:49:46 -0700283 irq_flags = 0;
Auke Kok2db10a02006-06-27 09:06:28 -0700284 }
285 }
Auke Koke94bd232007-05-16 01:49:46 -0700286
287 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
288 netdev);
289 if (err) {
290 if (adapter->have_msi)
291 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700292 DPRINTK(PROBE, ERR,
293 "Unable to allocate interrupt Error: %d\n", err);
Auke Koke94bd232007-05-16 01:49:46 -0700294 }
Auke Kok2db10a02006-06-27 09:06:28 -0700295
296 return err;
297}
298
299static void e1000_free_irq(struct e1000_adapter *adapter)
300{
301 struct net_device *netdev = adapter->netdev;
302
303 free_irq(adapter->pdev->irq, netdev);
304
Auke Kok2db10a02006-06-27 09:06:28 -0700305 if (adapter->have_msi)
306 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/**
310 * e1000_irq_disable - Mask off interrupt generation on the NIC
311 * @adapter: board private structure
312 **/
313
Auke Koke619d522006-04-14 19:04:52 -0700314static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315e1000_irq_disable(struct e1000_adapter *adapter)
316{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
318 E1000_WRITE_FLUSH(&adapter->hw);
319 synchronize_irq(adapter->pdev->irq);
320}
321
322/**
323 * e1000_irq_enable - Enable default interrupt generation settings
324 * @adapter: board private structure
325 **/
326
Auke Koke619d522006-04-14 19:04:52 -0700327static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328e1000_irq_enable(struct e1000_adapter *adapter)
329{
Jesse Brandeburg9150b762008-03-21 11:06:58 -0700330 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
331 E1000_WRITE_FLUSH(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100333
334static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700335e1000_update_mng_vlan(struct e1000_adapter *adapter)
336{
337 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -0700338 u16 vid = adapter->hw.mng_cookie.vlan_id;
339 u16 old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800340 if (adapter->vlgrp) {
Dan Aloni5c15bde2007-03-02 20:44:51 -0800341 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800342 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700343 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
344 e1000_vlan_rx_add_vid(netdev, vid);
345 adapter->mng_vlan_id = vid;
346 } else
347 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800348
Joe Perches406874a2008-04-03 10:06:32 -0700349 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800350 (vid != old_vid) &&
Dan Aloni5c15bde2007-03-02 20:44:51 -0800351 !vlan_group_get_device(adapter->vlgrp, old_vid))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700352 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800353 } else
354 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700355 }
356}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800357
358/**
359 * e1000_release_hw_control - release control of the h/w to f/w
360 * @adapter: address of board private structure
361 *
362 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
363 * For ASF and Pass Through versions of f/w this means that the
364 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800365 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700366 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800367 **/
368
Auke Koke619d522006-04-14 19:04:52 -0700369static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800370e1000_release_hw_control(struct e1000_adapter *adapter)
371{
Joe Perches406874a2008-04-03 10:06:32 -0700372 u32 ctrl_ext;
373 u32 swsm;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800374
375 /* Let firmware taken over control of h/w */
376 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800377 case e1000_82573:
378 swsm = E1000_READ_REG(&adapter->hw, SWSM);
379 E1000_WRITE_REG(&adapter->hw, SWSM,
380 swsm & ~E1000_SWSM_DRV_LOAD);
Bruce Allan31d76442007-03-06 08:57:24 -0800381 break;
382 case e1000_82571:
383 case e1000_82572:
384 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700385 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800386 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
Auke Kokcd94dd02006-06-27 09:08:22 -0700387 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
Bruce Allan31d76442007-03-06 08:57:24 -0800388 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700389 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800390 default:
391 break;
392 }
393}
394
395/**
396 * e1000_get_hw_control - get control of the h/w from f/w
397 * @adapter: address of board private structure
398 *
399 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700400 * For ASF and Pass Through versions of f/w this means that
401 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800402 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700403 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800404 **/
405
Auke Koke619d522006-04-14 19:04:52 -0700406static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800407e1000_get_hw_control(struct e1000_adapter *adapter)
408{
Joe Perches406874a2008-04-03 10:06:32 -0700409 u32 ctrl_ext;
410 u32 swsm;
Auke Kok90fb5132006-11-01 08:47:30 -0800411
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800412 /* Let firmware know the driver has taken over */
413 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800414 case e1000_82573:
415 swsm = E1000_READ_REG(&adapter->hw, SWSM);
416 E1000_WRITE_REG(&adapter->hw, SWSM,
417 swsm | E1000_SWSM_DRV_LOAD);
418 break;
Bruce Allan31d76442007-03-06 08:57:24 -0800419 case e1000_82571:
420 case e1000_82572:
421 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700422 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800423 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
424 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
425 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700426 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800427 default:
428 break;
429 }
430}
431
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500432static void
433e1000_init_manageability(struct e1000_adapter *adapter)
434{
435 if (adapter->en_mng_pt) {
Joe Perches406874a2008-04-03 10:06:32 -0700436 u32 manc = E1000_READ_REG(&adapter->hw, MANC);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500437
438 /* disable hardware interception of ARP */
439 manc &= ~(E1000_MANC_ARP_EN);
440
441 /* enable receiving management packets to the host */
442 /* this will probably generate destination unreachable messages
443 * from the host OS, but the packets will be handled on SMBUS */
444 if (adapter->hw.has_manc2h) {
Joe Perches406874a2008-04-03 10:06:32 -0700445 u32 manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500446
447 manc |= E1000_MANC_EN_MNG2HOST;
448#define E1000_MNG2HOST_PORT_623 (1 << 5)
449#define E1000_MNG2HOST_PORT_664 (1 << 6)
450 manc2h |= E1000_MNG2HOST_PORT_623;
451 manc2h |= E1000_MNG2HOST_PORT_664;
452 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
453 }
454
455 E1000_WRITE_REG(&adapter->hw, MANC, manc);
456 }
457}
458
459static void
460e1000_release_manageability(struct e1000_adapter *adapter)
461{
462 if (adapter->en_mng_pt) {
Joe Perches406874a2008-04-03 10:06:32 -0700463 u32 manc = E1000_READ_REG(&adapter->hw, MANC);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500464
465 /* re-enable hardware interception of ARP */
466 manc |= E1000_MANC_ARP_EN;
467
468 if (adapter->hw.has_manc2h)
469 manc &= ~E1000_MANC_EN_MNG2HOST;
470
471 /* don't explicitly have to mess with MANC2H since
472 * MANC has an enable disable that gates MANC2H */
473
474 E1000_WRITE_REG(&adapter->hw, MANC, manc);
475 }
476}
477
Auke Koke0aac5a2007-03-06 08:57:21 -0800478/**
479 * e1000_configure - configure the hardware for RX and TX
480 * @adapter = private board structure
481 **/
482static void e1000_configure(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
484 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700485 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Patrick McHardydb0ce502007-11-13 20:54:59 -0800487 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 e1000_restore_vlan(adapter);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500490 e1000_init_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 e1000_configure_tx(adapter);
493 e1000_setup_rctl(adapter);
494 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800495 /* call E1000_DESC_UNUSED which always leaves
496 * at least 1 descriptor unused to make sure
497 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800498 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800499 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800500 adapter->alloc_rx_buf(adapter, ring,
501 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800504 adapter->tx_queue_len = netdev->tx_queue_len;
Auke Koke0aac5a2007-03-06 08:57:21 -0800505}
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800506
Auke Koke0aac5a2007-03-06 08:57:21 -0800507int e1000_up(struct e1000_adapter *adapter)
508{
509 /* hardware has been reset, we need to reload some things */
510 e1000_configure(adapter);
Malli Chilakala5de55622005-04-28 19:39:30 -0700511
Auke Kok1314bbf2006-09-27 12:54:02 -0700512 clear_bit(__E1000_DOWN, &adapter->flags);
513
Auke Koke0aac5a2007-03-06 08:57:21 -0800514#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700515 napi_enable(&adapter->napi);
Auke Koke0aac5a2007-03-06 08:57:21 -0800516#endif
517 e1000_irq_enable(adapter);
518
Jesse Brandeburg79f3d392006-12-15 10:42:34 +0100519 /* fire a link change interrupt to start the watchdog */
520 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 return 0;
522}
523
Auke Kok79f05bf2006-06-27 09:06:32 -0700524/**
525 * e1000_power_up_phy - restore link in case the phy was powered down
526 * @adapter: address of board private structure
527 *
528 * The phy may be powered down to save power and turn off link when the
529 * driver is unloaded and wake on lan is not enabled (among others)
530 * *** this routine MUST be followed by a call to e1000_reset ***
531 *
532 **/
533
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700534void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700535{
Joe Perches406874a2008-04-03 10:06:32 -0700536 u16 mii_reg = 0;
Auke Kok79f05bf2006-06-27 09:06:32 -0700537
538 /* Just clear the power down bit to wake the phy back up */
539 if (adapter->hw.media_type == e1000_media_type_copper) {
540 /* according to the manual, the phy will retain its
541 * settings across a power-down/up cycle */
542 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
543 mii_reg &= ~MII_CR_POWER_DOWN;
544 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
545 }
546}
547
548static void e1000_power_down_phy(struct e1000_adapter *adapter)
549{
Bruce Allan61c25052006-09-27 12:53:54 -0700550 /* Power down the PHY so no link is implied when interface is down *
Joe Perchesc3033b02008-03-21 11:06:25 -0700551 * The PHY cannot be powered down if any of the following is true *
Auke Kok79f05bf2006-06-27 09:06:32 -0700552 * (a) WoL is enabled
553 * (b) AMT is active
554 * (c) SoL/IDER session is active */
555 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700556 adapter->hw.media_type == e1000_media_type_copper) {
Joe Perches406874a2008-04-03 10:06:32 -0700557 u16 mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700558
559 switch (adapter->hw.mac_type) {
560 case e1000_82540:
561 case e1000_82545:
562 case e1000_82545_rev_3:
563 case e1000_82546:
564 case e1000_82546_rev_3:
565 case e1000_82541:
566 case e1000_82541_rev_2:
567 case e1000_82547:
568 case e1000_82547_rev_2:
569 if (E1000_READ_REG(&adapter->hw, MANC) &
570 E1000_MANC_SMBUS_EN)
571 goto out;
572 break;
573 case e1000_82571:
574 case e1000_82572:
575 case e1000_82573:
576 case e1000_80003es2lan:
577 case e1000_ich8lan:
578 if (e1000_check_mng_mode(&adapter->hw) ||
579 e1000_check_phy_reset_block(&adapter->hw))
580 goto out;
581 break;
582 default:
583 goto out;
584 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700585 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
586 mii_reg |= MII_CR_POWER_DOWN;
587 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
588 mdelay(1);
589 }
Bruce Allan61c25052006-09-27 12:53:54 -0700590out:
591 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700592}
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594void
595e1000_down(struct e1000_adapter *adapter)
596{
597 struct net_device *netdev = adapter->netdev;
598
Auke Kok1314bbf2006-09-27 12:54:02 -0700599 /* signal that we're down so the interrupt handler does not
600 * reschedule our watchdog timer */
601 set_bit(__E1000_DOWN, &adapter->flags);
602
Auke Koke0aac5a2007-03-06 08:57:21 -0800603#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700604 napi_disable(&adapter->napi);
Auke Koke0aac5a2007-03-06 08:57:21 -0800605#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 del_timer_sync(&adapter->tx_fifo_stall_timer);
609 del_timer_sync(&adapter->watchdog_timer);
610 del_timer_sync(&adapter->phy_info_timer);
611
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800612 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 adapter->link_speed = 0;
614 adapter->link_duplex = 0;
615 netif_carrier_off(netdev);
616 netif_stop_queue(netdev);
617
618 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400619 e1000_clean_all_tx_rings(adapter);
620 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623void
Auke Kok2db10a02006-06-27 09:06:28 -0700624e1000_reinit_locked(struct e1000_adapter *adapter)
625{
626 WARN_ON(in_interrupt());
627 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
628 msleep(1);
629 e1000_down(adapter);
630 e1000_up(adapter);
631 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632}
633
634void
635e1000_reset(struct e1000_adapter *adapter)
636{
Joe Perches406874a2008-04-03 10:06:32 -0700637 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
638 u16 fc_high_water_mark = E1000_FC_HIGH_DIFF;
Joe Perchesc3033b02008-03-21 11:06:25 -0700639 bool legacy_pba_adjust = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 /* Repartition Pba for greater than 9k mtu
642 * To take effect CTRL.RST is required.
643 */
644
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700645 switch (adapter->hw.mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100646 case e1000_82542_rev2_0:
647 case e1000_82542_rev2_1:
648 case e1000_82543:
649 case e1000_82544:
650 case e1000_82540:
651 case e1000_82541:
652 case e1000_82541_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700653 legacy_pba_adjust = true;
Bruce Allan018ea442006-12-15 10:39:45 +0100654 pba = E1000_PBA_48K;
655 break;
656 case e1000_82545:
657 case e1000_82545_rev_3:
658 case e1000_82546:
659 case e1000_82546_rev_3:
660 pba = E1000_PBA_48K;
661 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700662 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700663 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700664 legacy_pba_adjust = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700665 pba = E1000_PBA_30K;
666 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400667 case e1000_82571:
668 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800669 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400670 pba = E1000_PBA_38K;
671 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700672 case e1000_82573:
Bruce Allan018ea442006-12-15 10:39:45 +0100673 pba = E1000_PBA_20K;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700674 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700675 case e1000_ich8lan:
676 pba = E1000_PBA_8K;
Bruce Allan018ea442006-12-15 10:39:45 +0100677 case e1000_undefined:
678 case e1000_num_macs:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700679 break;
680 }
681
Joe Perchesc3033b02008-03-21 11:06:25 -0700682 if (legacy_pba_adjust) {
Bruce Allan018ea442006-12-15 10:39:45 +0100683 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
684 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700685
Bruce Allan018ea442006-12-15 10:39:45 +0100686 if (adapter->hw.mac_type == e1000_82547) {
687 adapter->tx_fifo_head = 0;
688 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
689 adapter->tx_fifo_size =
690 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
691 atomic_set(&adapter->tx_fifo_stall, 0);
692 }
693 } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
694 /* adjust PBA for jumbo frames */
695 E1000_WRITE_REG(&adapter->hw, PBA, pba);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700696
Bruce Allan018ea442006-12-15 10:39:45 +0100697 /* To maintain wire speed transmits, the Tx FIFO should be
698 * large enough to accomodate two full transmit packets,
699 * rounded up to the next 1KB and expressed in KB. Likewise,
700 * the Rx FIFO should be large enough to accomodate at least
701 * one full receive packet and is similarly rounded up and
702 * expressed in KB. */
703 pba = E1000_READ_REG(&adapter->hw, PBA);
704 /* upper 16 bits has Tx packet buffer allocation size in KB */
705 tx_space = pba >> 16;
706 /* lower 16 bits has Rx packet buffer allocation size in KB */
707 pba &= 0xffff;
708 /* don't include ethernet FCS because hardware appends/strips */
709 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
710 VLAN_TAG_SIZE;
711 min_tx_space = min_rx_space;
712 min_tx_space *= 2;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700713 min_tx_space = ALIGN(min_tx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100714 min_tx_space >>= 10;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700715 min_rx_space = ALIGN(min_rx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100716 min_rx_space >>= 10;
717
718 /* If current Tx allocation is less than the min Tx FIFO size,
719 * and the min Tx FIFO size is less than the current Rx FIFO
720 * allocation, take space away from current Rx allocation */
721 if (tx_space < min_tx_space &&
722 ((min_tx_space - tx_space) < pba)) {
723 pba = pba - (min_tx_space - tx_space);
724
725 /* PCI/PCIx hardware has PBA alignment constraints */
726 switch (adapter->hw.mac_type) {
727 case e1000_82545 ... e1000_82546_rev_3:
728 pba &= ~(E1000_PBA_8K - 1);
729 break;
730 default:
731 break;
732 }
733
734 /* if short on rx space, rx wins and must trump tx
735 * adjustment or use Early Receive if available */
736 if (pba < min_rx_space) {
737 switch (adapter->hw.mac_type) {
738 case e1000_82573:
739 /* ERT enabled in e1000_configure_rx */
740 break;
741 default:
742 pba = min_rx_space;
743 break;
744 }
745 }
746 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 E1000_WRITE_REG(&adapter->hw, PBA, pba);
750
751 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800752 /* Set the FC high water mark to 90% of the FIFO size.
753 * Required to clear last 3 LSB */
754 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700755 /* We can't use 90% on small FIFOs because the remainder
756 * would be less than 1 full frame. In this case, we size
757 * it to allow at least a full frame above the high water
758 * mark. */
759 if (pba < E1000_PBA_16K)
760 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800761
762 adapter->hw.fc_high_water = fc_high_water_mark;
763 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800764 if (adapter->hw.mac_type == e1000_80003es2lan)
765 adapter->hw.fc_pause_time = 0xFFFF;
766 else
767 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 adapter->hw.fc_send_xon = 1;
769 adapter->hw.fc = adapter->hw.original_fc;
770
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700771 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800773 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700775
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800776 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700778 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100779
780 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
781 if (adapter->hw.mac_type >= e1000_82544 &&
782 adapter->hw.mac_type <= e1000_82547_rev_2 &&
783 adapter->hw.autoneg == 1 &&
784 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
Joe Perches406874a2008-04-03 10:06:32 -0700785 u32 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100786 /* clear phy power management bit if we are in gig only mode,
787 * which if enabled will attempt negotiation to 100Mb, which
788 * can cause a loss of link at power off or driver unload */
789 ctrl &= ~E1000_CTRL_SWDPIN3;
790 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
791 }
792
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
794 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
795
796 e1000_reset_adaptive(&adapter->hw);
797 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700798
799 if (!adapter->smart_power_down &&
800 (adapter->hw.mac_type == e1000_82571 ||
801 adapter->hw.mac_type == e1000_82572)) {
Joe Perches406874a2008-04-03 10:06:32 -0700802 u16 phy_data = 0;
Auke Kok9a53a202006-06-27 09:06:45 -0700803 /* speed up time to link by disabling smart power down, ignore
804 * the return value of this function because there is nothing
805 * different we would do if it failed */
806 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
807 &phy_data);
808 phy_data &= ~IGP02E1000_PM_SPD;
809 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
810 phy_data);
811 }
812
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500813 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814}
815
816/**
Auke Kok67b3c272007-12-17 13:50:23 -0800817 * Dump the eeprom for users having checksum issues
818 **/
Adrian Bunkb4ea8952008-02-01 08:21:28 -0800819static void e1000_dump_eeprom(struct e1000_adapter *adapter)
Auke Kok67b3c272007-12-17 13:50:23 -0800820{
821 struct net_device *netdev = adapter->netdev;
822 struct ethtool_eeprom eeprom;
823 const struct ethtool_ops *ops = netdev->ethtool_ops;
824 u8 *data;
825 int i;
826 u16 csum_old, csum_new = 0;
827
828 eeprom.len = ops->get_eeprom_len(netdev);
829 eeprom.offset = 0;
830
831 data = kmalloc(eeprom.len, GFP_KERNEL);
832 if (!data) {
833 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
834 " data\n");
835 return;
836 }
837
838 ops->get_eeprom(netdev, &eeprom, data);
839
840 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
841 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
842 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
843 csum_new += data[i] + (data[i + 1] << 8);
844 csum_new = EEPROM_SUM - csum_new;
845
846 printk(KERN_ERR "/*********************/\n");
847 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
848 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
849
850 printk(KERN_ERR "Offset Values\n");
851 printk(KERN_ERR "======== ======\n");
852 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
853
854 printk(KERN_ERR "Include this output when contacting your support "
855 "provider.\n");
856 printk(KERN_ERR "This is not a software error! Something bad "
857 "happened to your hardware or\n");
858 printk(KERN_ERR "EEPROM image. Ignoring this "
859 "problem could result in further problems,\n");
860 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
861 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
862 "which is invalid\n");
863 printk(KERN_ERR "and requires you to set the proper MAC "
864 "address manually before continuing\n");
865 printk(KERN_ERR "to enable this network device.\n");
866 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
867 "to your hardware vendor\n");
868 printk(KERN_ERR "or Intel Customer Support: linux-nics@intel.com\n");
869 printk(KERN_ERR "/*********************/\n");
870
871 kfree(data);
872}
873
874/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 * e1000_probe - Device Initialization Routine
876 * @pdev: PCI device information struct
877 * @ent: entry in e1000_pci_tbl
878 *
879 * Returns 0 on success, negative on failure
880 *
881 * e1000_probe initializes an adapter identified by a pci_dev structure.
882 * The OS initialization, configuring of the adapter private structure,
883 * and a hardware reset occur.
884 **/
885
886static int __devinit
887e1000_probe(struct pci_dev *pdev,
888 const struct pci_device_id *ent)
889{
890 struct net_device *netdev;
891 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700894 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700895 int i, err, pci_using_dac;
Joe Perches406874a2008-04-03 10:06:32 -0700896 u16 eeprom_data = 0;
897 u16 eeprom_apme_mask = E1000_EEPROM_APME;
Joe Perches0795af52007-10-03 17:59:30 -0700898 DECLARE_MAC_BUF(mac);
899
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800900 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 return err;
902
Auke Kokcd94dd02006-06-27 09:08:22 -0700903 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
904 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 pci_using_dac = 1;
906 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700907 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
908 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700910 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 }
912 pci_using_dac = 0;
913 }
914
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800915 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700916 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918 pci_set_master(pdev);
919
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700920 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700922 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 SET_NETDEV_DEV(netdev, &pdev->dev);
926
927 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700928 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 adapter->netdev = netdev;
930 adapter->pdev = pdev;
931 adapter->hw.back = adapter;
932 adapter->msg_enable = (1 << debug) - 1;
933
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700934 err = -EIO;
Benjamin Herrenschmidt3c34ac32007-11-16 18:37:38 +1100935 adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
936 pci_resource_len(pdev, BAR_0));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700937 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800940 for (i = BAR_1; i <= BAR_5; i++) {
941 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800943 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 adapter->hw.io_base = pci_resource_start(pdev, i);
945 break;
946 }
947 }
948
949 netdev->open = &e1000_open;
950 netdev->stop = &e1000_close;
951 netdev->hard_start_xmit = &e1000_xmit_frame;
952 netdev->get_stats = &e1000_get_stats;
Patrick McHardydb0ce502007-11-13 20:54:59 -0800953 netdev->set_rx_mode = &e1000_set_rx_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 netdev->set_mac_address = &e1000_set_mac;
955 netdev->change_mtu = &e1000_change_mtu;
956 netdev->do_ioctl = &e1000_ioctl;
957 e1000_set_ethtool_ops(netdev);
958 netdev->tx_timeout = &e1000_tx_timeout;
959 netdev->watchdog_timeo = 5 * HZ;
960#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700961 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962#endif
963 netdev->vlan_rx_register = e1000_vlan_rx_register;
964 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
965 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
966#ifdef CONFIG_NET_POLL_CONTROLLER
967 netdev->poll_controller = e1000_netpoll;
968#endif
Auke Kok0eb5a342006-09-27 12:53:17 -0700969 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 adapter->bd_number = cards_found;
972
973 /* setup the private structure */
974
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800975 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 goto err_sw_init;
977
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700978 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -0700979 /* Flash BAR mapping must happen after e1000_sw_init
980 * because it depends on mac_type */
981 if ((adapter->hw.mac_type == e1000_ich8lan) &&
982 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
Benjamin Herrenschmidt3c34ac32007-11-16 18:37:38 +1100983 adapter->hw.flash_address =
984 ioremap(pci_resource_start(pdev, 1),
985 pci_resource_len(pdev, 1));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700986 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -0700987 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -0700988 }
989
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700990 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700991 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
992
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800993 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 netdev->features = NETIF_F_SG |
995 NETIF_F_HW_CSUM |
996 NETIF_F_HW_VLAN_TX |
997 NETIF_F_HW_VLAN_RX |
998 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -0700999 if (adapter->hw.mac_type == e1000_ich8lan)
1000 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001003 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 (adapter->hw.mac_type != e1000_82547))
1005 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001006
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001007 if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -08001008 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001009 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 netdev->features |= NETIF_F_HIGHDMA;
1011
Auke Kok76c224b2006-05-23 13:36:06 -07001012 netdev->features |= NETIF_F_LLTX;
1013
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001014 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
1015
Auke Kokcd94dd02006-06-27 09:08:22 -07001016 /* initialize eeprom parameters */
Auke Kokcd94dd02006-06-27 09:08:22 -07001017 if (e1000_init_eeprom_params(&adapter->hw)) {
1018 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001019 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001020 }
1021
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001022 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001024
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 e1000_reset_hw(&adapter->hw);
1026
1027 /* make sure the EEPROM is good */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001028 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Auke Kok67b3c272007-12-17 13:50:23 -08001030 e1000_dump_eeprom(adapter);
1031 /*
1032 * set MAC address to all zeroes to invalidate and temporary
1033 * disable this device for the user. This blocks regular
1034 * traffic while still permitting ethtool ioctls from reaching
1035 * the hardware as well as allowing the user to run the
1036 * interface after manually setting a hw addr using
1037 * `ip set address`
1038 */
1039 memset(adapter->hw.mac_addr, 0, netdev->addr_len);
1040 } else {
1041 /* copy the MAC address out of the EEPROM */
1042 if (e1000_read_mac_addr(&adapter->hw))
1043 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 }
Auke Kok67b3c272007-12-17 13:50:23 -08001045 /* don't block initalization here due to bad MAC address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -04001047 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Auke Kok67b3c272007-12-17 13:50:23 -08001049 if (!is_valid_ether_addr(netdev->perm_addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 e1000_get_bus_info(&adapter->hw);
1053
1054 init_timer(&adapter->tx_fifo_stall_timer);
1055 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1056 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
1057
1058 init_timer(&adapter->watchdog_timer);
1059 adapter->watchdog_timer.function = &e1000_watchdog;
1060 adapter->watchdog_timer.data = (unsigned long) adapter;
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 init_timer(&adapter->phy_info_timer);
1063 adapter->phy_info_timer.function = &e1000_update_phy_info;
1064 adapter->phy_info_timer.data = (unsigned long) adapter;
1065
David Howells65f27f32006-11-22 14:55:48 +00001066 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 e1000_check_options(adapter);
1069
1070 /* Initial Wake on LAN setting
1071 * If APM wake is enabled in the EEPROM,
1072 * enable the ACPI Magic Packet filter
1073 */
1074
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001075 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 case e1000_82542_rev2_0:
1077 case e1000_82542_rev2_1:
1078 case e1000_82543:
1079 break;
1080 case e1000_82544:
1081 e1000_read_eeprom(&adapter->hw,
1082 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1083 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1084 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001085 case e1000_ich8lan:
1086 e1000_read_eeprom(&adapter->hw,
1087 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1088 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1089 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 case e1000_82546:
1091 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001092 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001093 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001094 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 e1000_read_eeprom(&adapter->hw,
1096 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1097 break;
1098 }
1099 /* Fall Through */
1100 default:
1101 e1000_read_eeprom(&adapter->hw,
1102 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1103 break;
1104 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001105 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001106 adapter->eeprom_wol |= E1000_WUFC_MAG;
1107
1108 /* now that we have the eeprom settings, apply the special cases
1109 * where the eeprom may be wrong or the board simply won't support
1110 * wake on lan on a particular port */
1111 switch (pdev->device) {
1112 case E1000_DEV_ID_82546GB_PCIE:
1113 adapter->eeprom_wol = 0;
1114 break;
1115 case E1000_DEV_ID_82546EB_FIBER:
1116 case E1000_DEV_ID_82546GB_FIBER:
1117 case E1000_DEV_ID_82571EB_FIBER:
1118 /* Wake events only supported on port A for dual fiber
1119 * regardless of eeprom setting */
1120 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
1121 adapter->eeprom_wol = 0;
1122 break;
1123 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001124 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001125 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001126 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001127 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001128 /* if quad port adapter, disable WoL on all but port A */
1129 if (global_quad_port_a != 0)
1130 adapter->eeprom_wol = 0;
1131 else
1132 adapter->quad_port_a = 1;
1133 /* Reset for multiple quad port adapters */
1134 if (++global_quad_port_a == 4)
1135 global_quad_port_a = 0;
1136 break;
1137 }
1138
1139 /* initialize the wol settings based on the eeprom settings */
1140 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001142 /* print bus type/speed/width info */
1143 {
1144 struct e1000_hw *hw = &adapter->hw;
1145 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1146 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1147 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1148 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1149 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1150 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1151 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1152 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1153 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1154 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1155 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1156 "32-bit"));
1157 }
1158
Joe Perches0795af52007-10-03 17:59:30 -07001159 printk("%s\n", print_mac(mac, netdev->dev_addr));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001160
Auke Kok14782ca2008-02-11 09:25:46 -08001161 if (adapter->hw.bus_type == e1000_bus_type_pci_express) {
1162 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1163 "longer be supported by this driver in the future.\n",
1164 pdev->vendor, pdev->device);
1165 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1166 "driver instead.\n");
1167 }
1168
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 /* reset the hardware with the new settings */
1170 e1000_reset(adapter);
1171
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001172 /* If the controller is 82573 and f/w is AMT, do not set
1173 * DRV_LOAD until the interface is up. For all other cases,
1174 * let the f/w know that the h/w is now under the control
1175 * of the driver. */
1176 if (adapter->hw.mac_type != e1000_82573 ||
1177 !e1000_check_mng_mode(&adapter->hw))
1178 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001179
Auke Kok1314bbf2006-09-27 12:54:02 -07001180 /* tell the stack to leave us alone until e1000_open() is called */
1181 netif_carrier_off(netdev);
1182 netif_stop_queue(netdev);
Auke Kok416b5d12007-06-01 10:22:39 -07001183
1184 strcpy(netdev->name, "eth%d");
1185 if ((err = register_netdev(netdev)))
1186 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001187
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1189
1190 cards_found++;
1191 return 0;
1192
1193err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001194 e1000_release_hw_control(adapter);
1195err_eeprom:
1196 if (!e1000_check_phy_reset_block(&adapter->hw))
1197 e1000_phy_hw_reset(&adapter->hw);
1198
Auke Kokcd94dd02006-06-27 09:08:22 -07001199 if (adapter->hw.flash_address)
1200 iounmap(adapter->hw.flash_address);
1201err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001202#ifdef CONFIG_E1000_NAPI
1203 for (i = 0; i < adapter->num_rx_queues; i++)
1204 dev_put(&adapter->polling_netdev[i]);
1205#endif
1206
1207 kfree(adapter->tx_ring);
1208 kfree(adapter->rx_ring);
1209#ifdef CONFIG_E1000_NAPI
1210 kfree(adapter->polling_netdev);
1211#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 iounmap(adapter->hw.hw_addr);
1214err_ioremap:
1215 free_netdev(netdev);
1216err_alloc_etherdev:
1217 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001218err_pci_reg:
1219err_dma:
1220 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 return err;
1222}
1223
1224/**
1225 * e1000_remove - Device Removal Routine
1226 * @pdev: PCI device information struct
1227 *
1228 * e1000_remove is called by the PCI subsystem to alert the driver
1229 * that it should release a PCI device. The could be caused by a
1230 * Hot-Plug event, or because the driver is going to be removed from
1231 * memory.
1232 **/
1233
1234static void __devexit
1235e1000_remove(struct pci_dev *pdev)
1236{
1237 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001238 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001239#ifdef CONFIG_E1000_NAPI
1240 int i;
1241#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Oleg Nesterov28e53bd2007-05-09 02:34:22 -07001243 cancel_work_sync(&adapter->reset_task);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001244
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001245 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001247 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1248 * would have already happened in close and is redundant. */
1249 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001250
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001251#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001252 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001253 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001254#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001256 unregister_netdev(netdev);
1257
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001258 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001259 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001261 kfree(adapter->tx_ring);
1262 kfree(adapter->rx_ring);
1263#ifdef CONFIG_E1000_NAPI
1264 kfree(adapter->polling_netdev);
1265#endif
1266
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001268 if (adapter->hw.flash_address)
1269 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 pci_release_regions(pdev);
1271
1272 free_netdev(netdev);
1273
1274 pci_disable_device(pdev);
1275}
1276
1277/**
1278 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1279 * @adapter: board private structure to initialize
1280 *
1281 * e1000_sw_init initializes the Adapter private data structure.
1282 * Fields are initialized based on PCI device information and
1283 * OS network device settings (MTU size).
1284 **/
1285
1286static int __devinit
1287e1000_sw_init(struct e1000_adapter *adapter)
1288{
1289 struct e1000_hw *hw = &adapter->hw;
1290 struct net_device *netdev = adapter->netdev;
1291 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001292#ifdef CONFIG_E1000_NAPI
1293 int i;
1294#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 /* PCI config space info */
1297
1298 hw->vendor_id = pdev->vendor;
1299 hw->device_id = pdev->device;
1300 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1301 hw->subsystem_id = pdev->subsystem_device;
Auke Kok44c10132007-06-08 15:46:36 -07001302 hw->revision_id = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
1304 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1305
Auke Kokeb0f8052006-07-14 16:14:48 -07001306 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001307 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 hw->max_frame_size = netdev->mtu +
1309 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1310 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1311
1312 /* identify the MAC */
1313
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001314 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1316 return -EIO;
1317 }
1318
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001319 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 default:
1321 break;
1322 case e1000_82541:
1323 case e1000_82547:
1324 case e1000_82541_rev_2:
1325 case e1000_82547_rev_2:
1326 hw->phy_init_script = 1;
1327 break;
1328 }
1329
1330 e1000_set_media_type(hw);
1331
Joe Perchesc3033b02008-03-21 11:06:25 -07001332 hw->wait_autoneg_complete = false;
1333 hw->tbi_compatibility_en = true;
1334 hw->adaptive_ifs = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
1336 /* Copper options */
1337
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001338 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 hw->mdix = AUTO_ALL_MODES;
Joe Perchesc3033b02008-03-21 11:06:25 -07001340 hw->disable_polarity_correction = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 hw->master_slave = E1000_MASTER_SLAVE;
1342 }
1343
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001344 adapter->num_tx_queues = 1;
1345 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001346
1347 if (e1000_alloc_queues(adapter)) {
1348 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1349 return -ENOMEM;
1350 }
1351
1352#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001353 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001354 adapter->polling_netdev[i].priv = adapter;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001355 dev_hold(&adapter->polling_netdev[i]);
1356 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1357 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001358 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001359#endif
1360
Herbert Xu47313052007-05-29 15:07:31 -07001361 /* Explicitly disable IRQ since the NIC can be in any state. */
Herbert Xu47313052007-05-29 15:07:31 -07001362 e1000_irq_disable(adapter);
1363
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Auke Kok1314bbf2006-09-27 12:54:02 -07001366 set_bit(__E1000_DOWN, &adapter->flags);
1367
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 return 0;
1369}
1370
1371/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001372 * e1000_alloc_queues - Allocate memory for all rings
1373 * @adapter: board private structure to initialize
1374 *
1375 * We allocate one ring per queue at run-time since we don't know the
1376 * number of queues at compile-time. The polling_netdev array is
1377 * intended for Multiqueue, but should work fine with a single queue.
1378 **/
1379
1380static int __devinit
1381e1000_alloc_queues(struct e1000_adapter *adapter)
1382{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001383 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1384 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001385 if (!adapter->tx_ring)
1386 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001387
Yan Burman1c7e5b12007-03-06 08:58:04 -08001388 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1389 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001390 if (!adapter->rx_ring) {
1391 kfree(adapter->tx_ring);
1392 return -ENOMEM;
1393 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001394
1395#ifdef CONFIG_E1000_NAPI
Yan Burman1c7e5b12007-03-06 08:58:04 -08001396 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1397 sizeof(struct net_device),
1398 GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001399 if (!adapter->polling_netdev) {
1400 kfree(adapter->tx_ring);
1401 kfree(adapter->rx_ring);
1402 return -ENOMEM;
1403 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001404#endif
1405
1406 return E1000_SUCCESS;
1407}
1408
1409/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 * e1000_open - Called when a network interface is made active
1411 * @netdev: network interface device structure
1412 *
1413 * Returns 0 on success, negative value on failure
1414 *
1415 * The open entry point is called when a network interface is made
1416 * active by the system (IFF_UP). At this point all resources needed
1417 * for transmit and receive operations are allocated, the interrupt
1418 * handler is registered with the OS, the watchdog timer is started,
1419 * and the stack is notified that the interface is ready.
1420 **/
1421
1422static int
1423e1000_open(struct net_device *netdev)
1424{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001425 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 int err;
1427
Auke Kok2db10a02006-06-27 09:06:28 -07001428 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001429 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001430 return -EBUSY;
1431
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001433 err = e1000_setup_all_tx_resources(adapter);
1434 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 goto err_setup_tx;
1436
1437 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001438 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001439 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001440 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001441
Auke Kok79f05bf2006-06-27 09:06:32 -07001442 e1000_power_up_phy(adapter);
1443
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001444 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001445 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001446 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1447 e1000_update_mng_vlan(adapter);
1448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001450 /* If AMT is enabled, let the firmware know that the network
1451 * interface is now open */
1452 if (adapter->hw.mac_type == e1000_82573 &&
1453 e1000_check_mng_mode(&adapter->hw))
1454 e1000_get_hw_control(adapter);
1455
Auke Koke0aac5a2007-03-06 08:57:21 -08001456 /* before we allocate an interrupt, we must be ready to handle it.
1457 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1458 * as soon as we call pci_request_irq, so we have to setup our
1459 * clean_rx handler before we do so. */
1460 e1000_configure(adapter);
1461
1462 err = e1000_request_irq(adapter);
1463 if (err)
1464 goto err_req_irq;
1465
1466 /* From here on the code is the same as e1000_up() */
1467 clear_bit(__E1000_DOWN, &adapter->flags);
1468
Herbert Xu47313052007-05-29 15:07:31 -07001469#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001470 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001471#endif
1472
Auke Koke0aac5a2007-03-06 08:57:21 -08001473 e1000_irq_enable(adapter);
1474
Ben Hutchings076152d2008-07-18 17:50:57 -07001475 netif_start_queue(netdev);
1476
Auke Koke0aac5a2007-03-06 08:57:21 -08001477 /* fire a link status change interrupt to start the watchdog */
1478 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
1479
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 return E1000_SUCCESS;
1481
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001482err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001483 e1000_release_hw_control(adapter);
1484 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001485 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001487 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488err_setup_tx:
1489 e1000_reset(adapter);
1490
1491 return err;
1492}
1493
1494/**
1495 * e1000_close - Disables a network interface
1496 * @netdev: network interface device structure
1497 *
1498 * Returns 0, this is not allowed to fail
1499 *
1500 * The close entry point is called when an interface is de-activated
1501 * by the OS. The hardware is still under the drivers control, but
1502 * needs to be disabled. A global MAC reset is issued to stop the
1503 * hardware, and all transmit and receive resources are freed.
1504 **/
1505
1506static int
1507e1000_close(struct net_device *netdev)
1508{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001509 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Auke Kok2db10a02006-06-27 09:06:28 -07001511 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001513 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001514 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001516 e1000_free_all_tx_resources(adapter);
1517 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Bruce Allan46665602006-09-27 12:54:08 -07001519 /* kill manageability vlan ID if supported, but not if a vlan with
1520 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001521 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001522 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1523 !(adapter->vlgrp &&
Dan Aloni5c15bde2007-03-02 20:44:51 -08001524 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001525 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1526 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001527
1528 /* If AMT is enabled, let the firmware know that the network
1529 * interface is now closed */
1530 if (adapter->hw.mac_type == e1000_82573 &&
1531 e1000_check_mng_mode(&adapter->hw))
1532 e1000_release_hw_control(adapter);
1533
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 return 0;
1535}
1536
1537/**
1538 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1539 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001540 * @start: address of beginning of memory
1541 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 **/
Joe Perchesc3033b02008-03-21 11:06:25 -07001543static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544e1000_check_64k_bound(struct e1000_adapter *adapter,
1545 void *start, unsigned long len)
1546{
1547 unsigned long begin = (unsigned long) start;
1548 unsigned long end = begin + len;
1549
Malli Chilakala26483452005-04-28 19:44:46 -07001550 /* First rev 82545 and 82546 need to not allow any memory
1551 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001553 adapter->hw.mac_type == e1000_82546) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001554 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 }
1556
Joe Perchesc3033b02008-03-21 11:06:25 -07001557 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
1560/**
1561 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1562 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001563 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 *
1565 * Return 0 on success, negative on failure
1566 **/
1567
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001568static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001569e1000_setup_tx_resources(struct e1000_adapter *adapter,
1570 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 struct pci_dev *pdev = adapter->pdev;
1573 int size;
1574
1575 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001576 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001577 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001578 DPRINTK(PROBE, ERR,
1579 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 return -ENOMEM;
1581 }
1582 memset(txdr->buffer_info, 0, size);
1583
1584 /* round up to nearest 4K */
1585
1586 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001587 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
1589 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001590 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001593 DPRINTK(PROBE, ERR,
1594 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 return -ENOMEM;
1596 }
1597
Malli Chilakala26483452005-04-28 19:44:46 -07001598 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1600 void *olddesc = txdr->desc;
1601 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001602 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1603 "at %p\n", txdr->size, txdr->desc);
1604 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001606 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001607 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1609 goto setup_tx_desc_die;
1610 }
1611
1612 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1613 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001614 pci_free_consistent(pdev, txdr->size, txdr->desc,
1615 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1617 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001618 "Unable to allocate aligned memory "
1619 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 vfree(txdr->buffer_info);
1621 return -ENOMEM;
1622 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001623 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1625 }
1626 }
1627 memset(txdr->desc, 0, txdr->size);
1628
1629 txdr->next_to_use = 0;
1630 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001631 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
1633 return 0;
1634}
1635
1636/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001637 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1638 * (Descriptors) for all queues
1639 * @adapter: board private structure
1640 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001641 * Return 0 on success, negative on failure
1642 **/
1643
1644int
1645e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1646{
1647 int i, err = 0;
1648
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001649 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001650 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1651 if (err) {
1652 DPRINTK(PROBE, ERR,
1653 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001654 for (i-- ; i >= 0; i--)
1655 e1000_free_tx_resources(adapter,
1656 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001657 break;
1658 }
1659 }
1660
1661 return err;
1662}
1663
1664/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1666 * @adapter: board private structure
1667 *
1668 * Configure the Tx unit of the MAC after a reset.
1669 **/
1670
1671static void
1672e1000_configure_tx(struct e1000_adapter *adapter)
1673{
Joe Perches406874a2008-04-03 10:06:32 -07001674 u64 tdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001675 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001676 u32 tdlen, tctl, tipg, tarc;
1677 u32 ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 /* Setup the HW Tx Head and Tail descriptor pointers */
1680
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001681 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001682 case 1:
1683 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001684 tdba = adapter->tx_ring[0].dma;
1685 tdlen = adapter->tx_ring[0].count *
1686 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001687 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001688 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1689 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001690 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001691 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001692 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1693 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001694 break;
1695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
1697 /* Set the default values for the Tx Inter Packet Gap timer */
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001698 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1699 (hw->media_type == e1000_media_type_fiber ||
1700 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001701 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1702 else
1703 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1704
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001705 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 case e1000_82542_rev2_0:
1707 case e1000_82542_rev2_1:
1708 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001709 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1710 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001712 case e1000_80003es2lan:
1713 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1714 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1715 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001717 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1718 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1719 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001721 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1722 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001723 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 /* Set the Tx Interrupt Delay register */
1726
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001727 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1728 if (hw->mac_type >= e1000_82540)
1729 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
1731 /* Program the Transmit Control Register */
1732
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001733 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001735 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1737
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001738 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1739 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001740 /* set the speed mode bit, we'll clear it if we're not at
1741 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001742 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001743 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001744 } else if (hw->mac_type == e1000_80003es2lan) {
1745 tarc = E1000_READ_REG(hw, TARC0);
1746 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001747 E1000_WRITE_REG(hw, TARC0, tarc);
1748 tarc = E1000_READ_REG(hw, TARC1);
1749 tarc |= 1;
1750 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001751 }
1752
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001753 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001756 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1757
1758 /* only set IDE if we are delaying interrupts using the timers */
1759 if (adapter->tx_int_delay)
1760 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001762 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1764 else
1765 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1766
1767 /* Cache if we're 82544 running in PCI-X because we'll
1768 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001769 if (hw->mac_type == e1000_82544 &&
1770 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001772
1773 E1000_WRITE_REG(hw, TCTL, tctl);
1774
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
1777/**
1778 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1779 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001780 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 *
1782 * Returns 0 on success, negative on failure
1783 **/
1784
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001785static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001786e1000_setup_rx_resources(struct e1000_adapter *adapter,
1787 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001790 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001793 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001794 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001795 DPRINTK(PROBE, ERR,
1796 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 return -ENOMEM;
1798 }
1799 memset(rxdr->buffer_info, 0, size);
1800
Yan Burman1c7e5b12007-03-06 08:58:04 -08001801 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1802 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001803 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001804 vfree(rxdr->buffer_info);
1805 DPRINTK(PROBE, ERR,
1806 "Unable to allocate memory for the receive descriptor ring\n");
1807 return -ENOMEM;
1808 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001809
Yan Burman1c7e5b12007-03-06 08:58:04 -08001810 rxdr->ps_page_dma = kcalloc(rxdr->count,
1811 sizeof(struct e1000_ps_page_dma),
1812 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001813 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001814 vfree(rxdr->buffer_info);
1815 kfree(rxdr->ps_page);
1816 DPRINTK(PROBE, ERR,
1817 "Unable to allocate memory for the receive descriptor ring\n");
1818 return -ENOMEM;
1819 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001820
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001821 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001822 desc_len = sizeof(struct e1000_rx_desc);
1823 else
1824 desc_len = sizeof(union e1000_rx_desc_packet_split);
1825
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 /* Round up to nearest 4K */
1827
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001828 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001829 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
1831 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1832
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001833 if (!rxdr->desc) {
1834 DPRINTK(PROBE, ERR,
1835 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001838 kfree(rxdr->ps_page);
1839 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 return -ENOMEM;
1841 }
1842
Malli Chilakala26483452005-04-28 19:44:46 -07001843 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1845 void *olddesc = rxdr->desc;
1846 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001847 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1848 "at %p\n", rxdr->size, rxdr->desc);
1849 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001851 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001852 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001854 DPRINTK(PROBE, ERR,
1855 "Unable to allocate memory "
1856 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 goto setup_rx_desc_die;
1858 }
1859
1860 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1861 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001862 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1863 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001865 DPRINTK(PROBE, ERR,
1866 "Unable to allocate aligned memory "
1867 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001868 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001870 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1872 }
1873 }
1874 memset(rxdr->desc, 0, rxdr->size);
1875
1876 rxdr->next_to_clean = 0;
1877 rxdr->next_to_use = 0;
1878
1879 return 0;
1880}
1881
1882/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001883 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1884 * (Descriptors) for all queues
1885 * @adapter: board private structure
1886 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001887 * Return 0 on success, negative on failure
1888 **/
1889
1890int
1891e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1892{
1893 int i, err = 0;
1894
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001895 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001896 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1897 if (err) {
1898 DPRINTK(PROBE, ERR,
1899 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001900 for (i-- ; i >= 0; i--)
1901 e1000_free_rx_resources(adapter,
1902 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001903 break;
1904 }
1905 }
1906
1907 return err;
1908}
1909
1910/**
Malli Chilakala26483452005-04-28 19:44:46 -07001911 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 * @adapter: Board private structure
1913 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001914#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1915 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916static void
1917e1000_setup_rctl(struct e1000_adapter *adapter)
1918{
Joe Perches406874a2008-04-03 10:06:32 -07001919 u32 rctl, rfctl;
1920 u32 psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001921#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Joe Perches406874a2008-04-03 10:06:32 -07001922 u32 pages = 0;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001923#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
1925 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1926
1927 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1928
1929 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1930 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1931 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1932
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001933 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 rctl |= E1000_RCTL_SBP;
1935 else
1936 rctl &= ~E1000_RCTL_SBP;
1937
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001938 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1939 rctl &= ~E1000_RCTL_LPE;
1940 else
1941 rctl |= E1000_RCTL_LPE;
1942
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001944 rctl &= ~E1000_RCTL_SZ_4096;
1945 rctl |= E1000_RCTL_BSEX;
1946 switch (adapter->rx_buffer_len) {
1947 case E1000_RXBUFFER_256:
1948 rctl |= E1000_RCTL_SZ_256;
1949 rctl &= ~E1000_RCTL_BSEX;
1950 break;
1951 case E1000_RXBUFFER_512:
1952 rctl |= E1000_RCTL_SZ_512;
1953 rctl &= ~E1000_RCTL_BSEX;
1954 break;
1955 case E1000_RXBUFFER_1024:
1956 rctl |= E1000_RCTL_SZ_1024;
1957 rctl &= ~E1000_RCTL_BSEX;
1958 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001959 case E1000_RXBUFFER_2048:
1960 default:
1961 rctl |= E1000_RCTL_SZ_2048;
1962 rctl &= ~E1000_RCTL_BSEX;
1963 break;
1964 case E1000_RXBUFFER_4096:
1965 rctl |= E1000_RCTL_SZ_4096;
1966 break;
1967 case E1000_RXBUFFER_8192:
1968 rctl |= E1000_RCTL_SZ_8192;
1969 break;
1970 case E1000_RXBUFFER_16384:
1971 rctl |= E1000_RCTL_SZ_16384;
1972 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001973 }
1974
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001975#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001976 /* 82571 and greater support packet-split where the protocol
1977 * header is placed in skb->data and the packet data is
1978 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1979 * In the case of a non-split, skb->data is linearly filled,
1980 * followed by the page buffers. Therefore, skb->data is
1981 * sized to hold the largest protocol header.
1982 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001983 /* allocations using alloc_page take too long for regular MTU
1984 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001985 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001986 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1987 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001988 adapter->rx_ps_pages = pages;
1989 else
1990 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001991#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001992 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001993 /* Configure extra packet-split registers */
1994 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1995 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08001996 /* disable packet split support for IPv6 extension headers,
1997 * because some malformed IPv6 headers can hang the RX */
1998 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1999 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2000
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002001 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
2002
Auke Kok7dfee0c2006-06-27 09:07:50 -07002003 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002005 psrctl |= adapter->rx_ps_bsize0 >>
2006 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002007
2008 switch (adapter->rx_ps_pages) {
2009 case 3:
2010 psrctl |= PAGE_SIZE <<
2011 E1000_PSRCTL_BSIZE3_SHIFT;
2012 case 2:
2013 psrctl |= PAGE_SIZE <<
2014 E1000_PSRCTL_BSIZE2_SHIFT;
2015 case 1:
2016 psrctl |= PAGE_SIZE >>
2017 E1000_PSRCTL_BSIZE1_SHIFT;
2018 break;
2019 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002020
2021 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 }
2023
2024 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2025}
2026
2027/**
2028 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2029 * @adapter: board private structure
2030 *
2031 * Configure the Rx unit of the MAC after a reset.
2032 **/
2033
2034static void
2035e1000_configure_rx(struct e1000_adapter *adapter)
2036{
Joe Perches406874a2008-04-03 10:06:32 -07002037 u64 rdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002038 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002039 u32 rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002040
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002041 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002042 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002043 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002044 sizeof(union e1000_rx_desc_packet_split);
2045 adapter->clean_rx = e1000_clean_rx_irq_ps;
2046 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2047 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002048 rdlen = adapter->rx_ring[0].count *
2049 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002050 adapter->clean_rx = e1000_clean_rx_irq;
2051 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2052 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
2054 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002055 rctl = E1000_READ_REG(hw, RCTL);
2056 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
2058 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002059 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002061 if (hw->mac_type >= e1000_82540) {
2062 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002063 if (adapter->itr_setting != 0)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002064 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 1000000000 / (adapter->itr * 256));
2066 }
2067
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002068 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002069 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002070 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002071 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002072#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002073 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002074 ctrl_ext |= E1000_CTRL_EXT_IAME;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002075 E1000_WRITE_REG(hw, IAM, 0xffffffff);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002076#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002077 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2078 E1000_WRITE_FLUSH(hw);
2079 }
2080
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002081 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2082 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002083 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04002084 case 1:
2085 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002086 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002087 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07002088 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
2089 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002090 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002091 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002092 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2093 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002094 break;
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04002095 }
2096
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002098 if (hw->mac_type >= e1000_82543) {
2099 rxcsum = E1000_READ_REG(hw, RXCSUM);
Joe Perchesc3033b02008-03-21 11:06:25 -07002100 if (adapter->rx_csum) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002101 rxcsum |= E1000_RXCSUM_TUOFL;
2102
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002103 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002104 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002105 if ((hw->mac_type >= e1000_82571) &&
2106 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002107 rxcsum |= E1000_RXCSUM_IPPCSE;
2108 }
2109 } else {
2110 rxcsum &= ~E1000_RXCSUM_TUOFL;
2111 /* don't need to clear IPPCSE as it defaults to 0 */
2112 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002113 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 }
2115
Auke Kok21c4d5e2006-11-01 08:47:39 -08002116 /* enable early receives on 82573, only takes effect if using > 2048
2117 * byte total frame size. for example only for jumbo frames */
2118#define E1000_ERT_2048 0x100
2119 if (hw->mac_type == e1000_82573)
2120 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
2121
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002123 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124}
2125
2126/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002127 * e1000_free_tx_resources - Free Tx Resources per Queue
2128 * @adapter: board private structure
2129 * @tx_ring: Tx descriptor ring for a specific queue
2130 *
2131 * Free all transmit software resources
2132 **/
2133
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002134static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002135e1000_free_tx_resources(struct e1000_adapter *adapter,
2136 struct e1000_tx_ring *tx_ring)
2137{
2138 struct pci_dev *pdev = adapter->pdev;
2139
2140 e1000_clean_tx_ring(adapter, tx_ring);
2141
2142 vfree(tx_ring->buffer_info);
2143 tx_ring->buffer_info = NULL;
2144
2145 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2146
2147 tx_ring->desc = NULL;
2148}
2149
2150/**
2151 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 * @adapter: board private structure
2153 *
2154 * Free all transmit software resources
2155 **/
2156
2157void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002158e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002160 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002162 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002163 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164}
2165
Auke Koke619d522006-04-14 19:04:52 -07002166static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2168 struct e1000_buffer *buffer_info)
2169{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002170 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07002171 pci_unmap_page(adapter->pdev,
2172 buffer_info->dma,
2173 buffer_info->length,
2174 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002175 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002177 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002179 buffer_info->skb = NULL;
2180 }
2181 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182}
2183
2184/**
2185 * e1000_clean_tx_ring - Free Tx Buffers
2186 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002187 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 **/
2189
2190static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002191e1000_clean_tx_ring(struct e1000_adapter *adapter,
2192 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 struct e1000_buffer *buffer_info;
2195 unsigned long size;
2196 unsigned int i;
2197
2198 /* Free all the Tx ring sk_buffs */
2199
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002200 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 buffer_info = &tx_ring->buffer_info[i];
2202 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2203 }
2204
2205 size = sizeof(struct e1000_buffer) * tx_ring->count;
2206 memset(tx_ring->buffer_info, 0, size);
2207
2208 /* Zero out the descriptor ring */
2209
2210 memset(tx_ring->desc, 0, tx_ring->size);
2211
2212 tx_ring->next_to_use = 0;
2213 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002214 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002216 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2217 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2218}
2219
2220/**
2221 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2222 * @adapter: board private structure
2223 **/
2224
2225static void
2226e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2227{
2228 int i;
2229
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002230 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002231 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232}
2233
2234/**
2235 * e1000_free_rx_resources - Free Rx Resources
2236 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002237 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 *
2239 * Free all receive software resources
2240 **/
2241
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002242static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002243e1000_free_rx_resources(struct e1000_adapter *adapter,
2244 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 struct pci_dev *pdev = adapter->pdev;
2247
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002248 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
2250 vfree(rx_ring->buffer_info);
2251 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002252 kfree(rx_ring->ps_page);
2253 rx_ring->ps_page = NULL;
2254 kfree(rx_ring->ps_page_dma);
2255 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
2257 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2258
2259 rx_ring->desc = NULL;
2260}
2261
2262/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002263 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002265 *
2266 * Free all receive software resources
2267 **/
2268
2269void
2270e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2271{
2272 int i;
2273
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002274 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002275 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2276}
2277
2278/**
2279 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2280 * @adapter: board private structure
2281 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 **/
2283
2284static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002285e1000_clean_rx_ring(struct e1000_adapter *adapter,
2286 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002289 struct e1000_ps_page *ps_page;
2290 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 struct pci_dev *pdev = adapter->pdev;
2292 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002293 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
2295 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002296 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002298 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 pci_unmap_single(pdev,
2300 buffer_info->dma,
2301 buffer_info->length,
2302 PCI_DMA_FROMDEVICE);
2303
2304 dev_kfree_skb(buffer_info->skb);
2305 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002306 }
2307 ps_page = &rx_ring->ps_page[i];
2308 ps_page_dma = &rx_ring->ps_page_dma[i];
2309 for (j = 0; j < adapter->rx_ps_pages; j++) {
2310 if (!ps_page->ps_page[j]) break;
2311 pci_unmap_page(pdev,
2312 ps_page_dma->ps_page_dma[j],
2313 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2314 ps_page_dma->ps_page_dma[j] = 0;
2315 put_page(ps_page->ps_page[j]);
2316 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 }
2318 }
2319
2320 size = sizeof(struct e1000_buffer) * rx_ring->count;
2321 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002322 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2323 memset(rx_ring->ps_page, 0, size);
2324 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2325 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
2327 /* Zero out the descriptor ring */
2328
2329 memset(rx_ring->desc, 0, rx_ring->size);
2330
2331 rx_ring->next_to_clean = 0;
2332 rx_ring->next_to_use = 0;
2333
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002334 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2335 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2336}
2337
2338/**
2339 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2340 * @adapter: board private structure
2341 **/
2342
2343static void
2344e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2345{
2346 int i;
2347
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002348 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002349 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350}
2351
2352/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2353 * and memory write and invalidate disabled for certain operations
2354 */
2355static void
2356e1000_enter_82542_rst(struct e1000_adapter *adapter)
2357{
2358 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002359 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
2361 e1000_pci_clear_mwi(&adapter->hw);
2362
2363 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2364 rctl |= E1000_RCTL_RST;
2365 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2366 E1000_WRITE_FLUSH(&adapter->hw);
2367 mdelay(5);
2368
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002369 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002370 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371}
2372
2373static void
2374e1000_leave_82542_rst(struct e1000_adapter *adapter)
2375{
2376 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002377 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378
2379 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2380 rctl &= ~E1000_RCTL_RST;
2381 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2382 E1000_WRITE_FLUSH(&adapter->hw);
2383 mdelay(5);
2384
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002385 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 e1000_pci_set_mwi(&adapter->hw);
2387
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002388 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002389 /* No need to loop, because 82542 supports only 1 queue */
2390 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002391 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002392 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 }
2394}
2395
2396/**
2397 * e1000_set_mac - Change the Ethernet Address of the NIC
2398 * @netdev: network interface device structure
2399 * @p: pointer to an address structure
2400 *
2401 * Returns 0 on success, negative on failure
2402 **/
2403
2404static int
2405e1000_set_mac(struct net_device *netdev, void *p)
2406{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002407 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 struct sockaddr *addr = p;
2409
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002410 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 return -EADDRNOTAVAIL;
2412
2413 /* 82542 2.0 needs to be in reset to write receive address registers */
2414
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002415 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 e1000_enter_82542_rst(adapter);
2417
2418 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2419 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2420
2421 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2422
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002423 /* With 82571 controllers, LAA may be overwritten (with the default)
2424 * due to controller reset from the other port. */
2425 if (adapter->hw.mac_type == e1000_82571) {
2426 /* activate the work around */
2427 adapter->hw.laa_is_present = 1;
2428
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002429 /* Hold a copy of the LAA in RAR[14] This is done so that
2430 * between the time RAR[0] gets clobbered and the time it
2431 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002432 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002433 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002434 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002435 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002436 E1000_RAR_ENTRIES - 1);
2437 }
2438
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002439 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 e1000_leave_82542_rst(adapter);
2441
2442 return 0;
2443}
2444
2445/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002446 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 * @netdev: network interface device structure
2448 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002449 * The set_rx_mode entry point is called whenever the unicast or multicast
2450 * address lists or the network interface flags are updated. This routine is
2451 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 * promiscuous mode, and all-multi behavior.
2453 **/
2454
2455static void
Patrick McHardydb0ce502007-11-13 20:54:59 -08002456e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002458 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 struct e1000_hw *hw = &adapter->hw;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002460 struct dev_addr_list *uc_ptr;
2461 struct dev_addr_list *mc_ptr;
Joe Perches406874a2008-04-03 10:06:32 -07002462 u32 rctl;
2463 u32 hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002464 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002465 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2466 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2467 E1000_NUM_MTA_REGISTERS;
2468
2469 if (adapter->hw.mac_type == e1000_ich8lan)
2470 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002472 /* reserve RAR[14] for LAA over-write work-around */
2473 if (adapter->hw.mac_type == e1000_82571)
2474 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Malli Chilakala26483452005-04-28 19:44:46 -07002476 /* Check for Promiscuous and All Multicast modes */
2477
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 rctl = E1000_READ_REG(hw, RCTL);
2479
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002480 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002482 rctl &= ~E1000_RCTL_VFE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002484 if (netdev->flags & IFF_ALLMULTI) {
2485 rctl |= E1000_RCTL_MPE;
2486 } else {
2487 rctl &= ~E1000_RCTL_MPE;
2488 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002489 if (adapter->hw.mac_type != e1000_ich8lan)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002490 rctl |= E1000_RCTL_VFE;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002491 }
2492
2493 uc_ptr = NULL;
2494 if (netdev->uc_count > rar_entries - 1) {
2495 rctl |= E1000_RCTL_UPE;
2496 } else if (!(netdev->flags & IFF_PROMISC)) {
2497 rctl &= ~E1000_RCTL_UPE;
2498 uc_ptr = netdev->uc_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 }
2500
2501 E1000_WRITE_REG(hw, RCTL, rctl);
2502
2503 /* 82542 2.0 needs to be in reset to write receive address registers */
2504
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002505 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 e1000_enter_82542_rst(adapter);
2507
Patrick McHardydb0ce502007-11-13 20:54:59 -08002508 /* load the first 14 addresses into the exact filters 1-14. Unicast
2509 * addresses take precedence to avoid disabling unicast filtering
2510 * when possible.
2511 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 * RAR 0 is used for the station MAC adddress
2513 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002514 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 */
2516 mc_ptr = netdev->mc_list;
2517
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002518 for (i = 1; i < rar_entries; i++) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002519 if (uc_ptr) {
2520 e1000_rar_set(hw, uc_ptr->da_addr, i);
2521 uc_ptr = uc_ptr->next;
2522 } else if (mc_ptr) {
2523 e1000_rar_set(hw, mc_ptr->da_addr, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 mc_ptr = mc_ptr->next;
2525 } else {
2526 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002527 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002529 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 }
2531 }
Patrick McHardydb0ce502007-11-13 20:54:59 -08002532 WARN_ON(uc_ptr != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
2534 /* clear the old settings from the multicast hash table */
2535
Auke Kokcd94dd02006-06-27 09:08:22 -07002536 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002538 E1000_WRITE_FLUSH(hw);
2539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
2541 /* load any remaining addresses into the hash table */
2542
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002543 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002544 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 e1000_mta_set(hw, hash_value);
2546 }
2547
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002548 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550}
2551
2552/* Need to wait a few seconds after link up to get diagnostic information from
2553 * the phy */
2554
2555static void
2556e1000_update_phy_info(unsigned long data)
2557{
2558 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2559 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2560}
2561
2562/**
2563 * e1000_82547_tx_fifo_stall - Timer Call-back
2564 * @data: pointer to adapter cast into an unsigned long
2565 **/
2566
2567static void
2568e1000_82547_tx_fifo_stall(unsigned long data)
2569{
2570 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2571 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002572 u32 tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002574 if (atomic_read(&adapter->tx_fifo_stall)) {
2575 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 E1000_READ_REG(&adapter->hw, TDH)) &&
2577 (E1000_READ_REG(&adapter->hw, TDFT) ==
2578 E1000_READ_REG(&adapter->hw, TDFH)) &&
2579 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2580 E1000_READ_REG(&adapter->hw, TDFHS))) {
2581 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2582 E1000_WRITE_REG(&adapter->hw, TCTL,
2583 tctl & ~E1000_TCTL_EN);
2584 E1000_WRITE_REG(&adapter->hw, TDFT,
2585 adapter->tx_head_addr);
2586 E1000_WRITE_REG(&adapter->hw, TDFH,
2587 adapter->tx_head_addr);
2588 E1000_WRITE_REG(&adapter->hw, TDFTS,
2589 adapter->tx_head_addr);
2590 E1000_WRITE_REG(&adapter->hw, TDFHS,
2591 adapter->tx_head_addr);
2592 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2593 E1000_WRITE_FLUSH(&adapter->hw);
2594
2595 adapter->tx_fifo_head = 0;
2596 atomic_set(&adapter->tx_fifo_stall, 0);
2597 netif_wake_queue(netdev);
2598 } else {
2599 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2600 }
2601 }
2602}
2603
2604/**
2605 * e1000_watchdog - Timer Call-back
2606 * @data: pointer to adapter cast into an unsigned long
2607 **/
2608static void
2609e1000_watchdog(unsigned long data)
2610{
2611 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002613 struct e1000_tx_ring *txdr = adapter->tx_ring;
Joe Perches406874a2008-04-03 10:06:32 -07002614 u32 link, tctl;
2615 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616
Auke Kokcd94dd02006-06-27 09:08:22 -07002617 ret_val = e1000_check_for_link(&adapter->hw);
2618 if ((ret_val == E1000_ERR_PHY) &&
2619 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2620 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2621 /* See e1000_kumeran_lock_loss_workaround() */
2622 DPRINTK(LINK, INFO,
2623 "Gigabit has been disabled, downgrading speed\n");
2624 }
Auke Kok90fb5132006-11-01 08:47:30 -08002625
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002626 if (adapter->hw.mac_type == e1000_82573) {
2627 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002628 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002629 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002632 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2634 link = !adapter->hw.serdes_link_down;
2635 else
2636 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2637
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002638 if (link) {
2639 if (!netif_carrier_ok(netdev)) {
Joe Perches406874a2008-04-03 10:06:32 -07002640 u32 ctrl;
Joe Perchesc3033b02008-03-21 11:06:25 -07002641 bool txb2b = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 e1000_get_speed_and_duplex(&adapter->hw,
2643 &adapter->link_speed,
2644 &adapter->link_duplex);
2645
Auke Kok9669f532007-01-18 09:25:26 -08002646 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
2647 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2648 "Flow Control: %s\n",
2649 adapter->link_speed,
2650 adapter->link_duplex == FULL_DUPLEX ?
2651 "Full Duplex" : "Half Duplex",
2652 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2653 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2654 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2655 E1000_CTRL_TFCE) ? "TX" : "None" )));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002657 /* tweak tx_queue_len according to speed/duplex
2658 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002659 netdev->tx_queue_len = adapter->tx_queue_len;
2660 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002661 switch (adapter->link_speed) {
2662 case SPEED_10:
Joe Perchesc3033b02008-03-21 11:06:25 -07002663 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002664 netdev->tx_queue_len = 10;
2665 adapter->tx_timeout_factor = 8;
2666 break;
2667 case SPEED_100:
Joe Perchesc3033b02008-03-21 11:06:25 -07002668 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002669 netdev->tx_queue_len = 100;
2670 /* maybe add some timeout factor ? */
2671 break;
2672 }
2673
Auke Kokfe7fe282006-04-14 19:04:59 -07002674 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002675 adapter->hw.mac_type == e1000_82572) &&
Joe Perchesc3033b02008-03-21 11:06:25 -07002676 !txb2b) {
Joe Perches406874a2008-04-03 10:06:32 -07002677 u32 tarc0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002678 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002679 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002680 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2681 }
Auke Kok90fb5132006-11-01 08:47:30 -08002682
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002683 /* disable TSO for pcie and 10/100 speeds, to avoid
2684 * some hardware issues */
2685 if (!adapter->tso_force &&
2686 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002687 switch (adapter->link_speed) {
2688 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002689 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002690 DPRINTK(PROBE,INFO,
2691 "10/100 speed: disabling TSO\n");
2692 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002693 netdev->features &= ~NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002694 break;
2695 case SPEED_1000:
2696 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002697 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002698 break;
2699 default:
2700 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002701 break;
2702 }
2703 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002704
2705 /* enable transmits in the hardware, need to do this
2706 * after setting TARC0 */
2707 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2708 tctl |= E1000_TCTL_EN;
2709 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002710
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 netif_carrier_on(netdev);
2712 netif_wake_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002713 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002715 } else {
2716 /* make sure the receive unit is started */
2717 if (adapter->hw.rx_needs_kicking) {
2718 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002719 u32 rctl = E1000_READ_REG(hw, RCTL);
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002720 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 }
2723 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002724 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 adapter->link_speed = 0;
2726 adapter->link_duplex = 0;
2727 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2728 netif_carrier_off(netdev);
2729 netif_stop_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002730 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Jeff Kirsher87041632006-03-02 18:21:24 -08002731
2732 /* 80003ES2LAN workaround--
2733 * For packet buffer work-around on link down event;
2734 * disable receives in the ISR and
2735 * reset device here in the watchdog
2736 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002737 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002738 /* reset device */
2739 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 }
2741
2742 e1000_smartspeed(adapter);
2743 }
2744
2745 e1000_update_stats(adapter);
2746
2747 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2748 adapter->tpt_old = adapter->stats.tpt;
2749 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2750 adapter->colc_old = adapter->stats.colc;
2751
2752 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2753 adapter->gorcl_old = adapter->stats.gorcl;
2754 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2755 adapter->gotcl_old = adapter->stats.gotcl;
2756
2757 e1000_update_adaptive(&adapter->hw);
2758
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002759 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002760 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 /* We've lost link, so the controller stops DMA,
2762 * but we've got queued Tx work that's never going
2763 * to get done, so reset controller to flush Tx.
2764 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002765 adapter->tx_timeout_count++;
2766 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 }
2768 }
2769
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 /* Cause software interrupt to ensure rx ring is cleaned */
2771 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2772
Malli Chilakala26483452005-04-28 19:44:46 -07002773 /* Force detection of hung controller every watchdog period */
Joe Perchesc3033b02008-03-21 11:06:25 -07002774 adapter->detect_tx_hung = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002776 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002777 * reset from the other port. Set the appropriate LAA in RAR[0] */
2778 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2779 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2780
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 /* Reset the timer */
Arjan van de Ven56e13932007-03-06 02:41:48 -08002782 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783}
2784
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002785enum latency_range {
2786 lowest_latency = 0,
2787 low_latency = 1,
2788 bulk_latency = 2,
2789 latency_invalid = 255
2790};
2791
2792/**
2793 * e1000_update_itr - update the dynamic ITR value based on statistics
2794 * Stores a new ITR value based on packets and byte
2795 * counts during the last interrupt. The advantage of per interrupt
2796 * computation is faster updates and more accurate ITR for the current
2797 * traffic pattern. Constants in this function were computed
2798 * based on theoretical maximum wire speed and thresholds were set based
2799 * on testing data as well as attempting to minimize response time
2800 * while increasing bulk throughput.
2801 * this functionality is controlled by the InterruptThrottleRate module
2802 * parameter (see e1000_param.c)
2803 * @adapter: pointer to adapter
2804 * @itr_setting: current adapter->itr
2805 * @packets: the number of packets during this measurement interval
2806 * @bytes: the number of bytes during this measurement interval
2807 **/
2808static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
Joe Perches406874a2008-04-03 10:06:32 -07002809 u16 itr_setting,
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002810 int packets,
2811 int bytes)
2812{
2813 unsigned int retval = itr_setting;
2814 struct e1000_hw *hw = &adapter->hw;
2815
2816 if (unlikely(hw->mac_type < e1000_82540))
2817 goto update_itr_done;
2818
2819 if (packets == 0)
2820 goto update_itr_done;
2821
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002822 switch (itr_setting) {
2823 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002824 /* jumbo frames get bulk treatment*/
2825 if (bytes/packets > 8000)
2826 retval = bulk_latency;
2827 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002828 retval = low_latency;
2829 break;
2830 case low_latency: /* 50 usec aka 20000 ints/s */
2831 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002832 /* jumbo frames need bulk latency setting */
2833 if (bytes/packets > 8000)
2834 retval = bulk_latency;
2835 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002836 retval = bulk_latency;
2837 else if ((packets > 35))
2838 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002839 } else if (bytes/packets > 2000)
2840 retval = bulk_latency;
2841 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002842 retval = lowest_latency;
2843 break;
2844 case bulk_latency: /* 250 usec aka 4000 ints/s */
2845 if (bytes > 25000) {
2846 if (packets > 35)
2847 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002848 } else if (bytes < 6000) {
2849 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002850 }
2851 break;
2852 }
2853
2854update_itr_done:
2855 return retval;
2856}
2857
2858static void e1000_set_itr(struct e1000_adapter *adapter)
2859{
2860 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002861 u16 current_itr;
2862 u32 new_itr = adapter->itr;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002863
2864 if (unlikely(hw->mac_type < e1000_82540))
2865 return;
2866
2867 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2868 if (unlikely(adapter->link_speed != SPEED_1000)) {
2869 current_itr = 0;
2870 new_itr = 4000;
2871 goto set_itr_now;
2872 }
2873
2874 adapter->tx_itr = e1000_update_itr(adapter,
2875 adapter->tx_itr,
2876 adapter->total_tx_packets,
2877 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002878 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2879 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2880 adapter->tx_itr = low_latency;
2881
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002882 adapter->rx_itr = e1000_update_itr(adapter,
2883 adapter->rx_itr,
2884 adapter->total_rx_packets,
2885 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002886 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2887 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2888 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002889
2890 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2891
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002892 switch (current_itr) {
2893 /* counts and packets in update_itr are dependent on these numbers */
2894 case lowest_latency:
2895 new_itr = 70000;
2896 break;
2897 case low_latency:
2898 new_itr = 20000; /* aka hwitr = ~200 */
2899 break;
2900 case bulk_latency:
2901 new_itr = 4000;
2902 break;
2903 default:
2904 break;
2905 }
2906
2907set_itr_now:
2908 if (new_itr != adapter->itr) {
2909 /* this attempts to bias the interrupt rate towards Bulk
2910 * by adding intermediate steps when interrupt rate is
2911 * increasing */
2912 new_itr = new_itr > adapter->itr ?
2913 min(adapter->itr + (new_itr >> 2), new_itr) :
2914 new_itr;
2915 adapter->itr = new_itr;
2916 E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
2917 }
2918
2919 return;
2920}
2921
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922#define E1000_TX_FLAGS_CSUM 0x00000001
2923#define E1000_TX_FLAGS_VLAN 0x00000002
2924#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002925#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2927#define E1000_TX_FLAGS_VLAN_SHIFT 16
2928
Auke Koke619d522006-04-14 19:04:52 -07002929static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002930e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2931 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002934 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002936 u32 cmd_length = 0;
2937 u16 ipcse = 0, tucse, mss;
2938 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 int err;
2940
Herbert Xu89114af2006-07-08 13:34:32 -07002941 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 if (skb_header_cloned(skb)) {
2943 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2944 if (err)
2945 return err;
2946 }
2947
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002948 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002949 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002950 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002951 struct iphdr *iph = ip_hdr(skb);
2952 iph->tot_len = 0;
2953 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002954 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2955 iph->daddr, 0,
2956 IPPROTO_TCP,
2957 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002958 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002959 ipcse = skb_transport_offset(skb) - 1;
Auke Koke15fdd02006-08-16 11:28:45 -07002960 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002961 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002962 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002963 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2964 &ipv6_hdr(skb)->daddr,
2965 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002966 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002967 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002968 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002969 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002970 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002971 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 tucse = 0;
2973
2974 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002975 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002977 i = tx_ring->next_to_use;
2978 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002979 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980
2981 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2982 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2983 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2984 context_desc->upper_setup.tcp_fields.tucss = tucss;
2985 context_desc->upper_setup.tcp_fields.tucso = tucso;
2986 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2987 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2988 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2989 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2990
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002991 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002992 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002993
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002994 if (++i == tx_ring->count) i = 0;
2995 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996
Joe Perchesc3033b02008-03-21 11:06:25 -07002997 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 }
Joe Perchesc3033b02008-03-21 11:06:25 -07002999 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000}
3001
Joe Perchesc3033b02008-03-21 11:06:25 -07003002static bool
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003003e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3004 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005{
3006 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003007 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07003009 u8 css;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
Patrick McHardy84fa7932006-08-29 16:44:56 -07003011 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07003012 css = skb_transport_offset(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003014 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003015 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003016 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017
Bruce Allanf6c57ba2007-01-18 09:25:28 -08003018 context_desc->lower_setup.ip_config = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 context_desc->upper_setup.tcp_fields.tucss = css;
Herbert Xu628592c2007-04-23 17:06:40 -07003020 context_desc->upper_setup.tcp_fields.tucso =
3021 css + skb->csum_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 context_desc->upper_setup.tcp_fields.tucse = 0;
3023 context_desc->tcp_seg_setup.data = 0;
3024 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
3025
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003026 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003027 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003028
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003029 if (unlikely(++i == tx_ring->count)) i = 0;
3030 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031
Joe Perchesc3033b02008-03-21 11:06:25 -07003032 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 }
3034
Joe Perchesc3033b02008-03-21 11:06:25 -07003035 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036}
3037
3038#define E1000_MAX_TXD_PWR 12
3039#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
3040
Auke Koke619d522006-04-14 19:04:52 -07003041static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003042e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3043 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
3044 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 struct e1000_buffer *buffer_info;
3047 unsigned int len = skb->len;
3048 unsigned int offset = 0, size, count = 0, i;
3049 unsigned int f;
3050 len -= skb->data_len;
3051
3052 i = tx_ring->next_to_use;
3053
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003054 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 buffer_info = &tx_ring->buffer_info[i];
3056 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05003057 /* Workaround for Controller erratum --
3058 * descriptor for non-tso packet in a linear SKB that follows a
3059 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003060 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05003061 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07003062 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05003063 tx_ring->last_tx_tso = 0;
3064 size -= 4;
3065 }
3066
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 /* Workaround for premature desc write-backs
3068 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003069 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07003071 /* work-around for errata 10 and it applies
3072 * to all controllers in PCI-X mode
3073 * The fix is to make sure that the first descriptor of a
3074 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3075 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003076 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003077 (size > 2015) && count == 0))
3078 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003079
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 /* Workaround for potential 82544 hang in PCI-X. Avoid
3081 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003082 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3084 size > 4))
3085 size -= 4;
3086
3087 buffer_info->length = size;
3088 buffer_info->dma =
3089 pci_map_single(adapter->pdev,
3090 skb->data + offset,
3091 size,
3092 PCI_DMA_TODEVICE);
3093 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003094 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095
3096 len -= size;
3097 offset += size;
3098 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003099 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 }
3101
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003102 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 struct skb_frag_struct *frag;
3104
3105 frag = &skb_shinfo(skb)->frags[f];
3106 len = frag->size;
3107 offset = frag->page_offset;
3108
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003109 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 buffer_info = &tx_ring->buffer_info[i];
3111 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 /* Workaround for premature desc write-backs
3113 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003114 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 /* Workaround for potential 82544 hang in PCI-X.
3117 * Avoid terminating buffers within evenly-aligned
3118 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003119 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3121 size > 4))
3122 size -= 4;
3123
3124 buffer_info->length = size;
3125 buffer_info->dma =
3126 pci_map_page(adapter->pdev,
3127 frag->page,
3128 offset,
3129 size,
3130 PCI_DMA_TODEVICE);
3131 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003132 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133
3134 len -= size;
3135 offset += size;
3136 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003137 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 }
3139 }
3140
3141 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3142 tx_ring->buffer_info[i].skb = skb;
3143 tx_ring->buffer_info[first].next_to_watch = i;
3144
3145 return count;
3146}
3147
Auke Koke619d522006-04-14 19:04:52 -07003148static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003149e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3150 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 struct e1000_tx_desc *tx_desc = NULL;
3153 struct e1000_buffer *buffer_info;
Joe Perches406874a2008-04-03 10:06:32 -07003154 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 unsigned int i;
3156
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003157 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3159 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003160 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3161
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003162 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003163 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 }
3165
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003166 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3168 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3169 }
3170
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003171 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 txd_lower |= E1000_TXD_CMD_VLE;
3173 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3174 }
3175
3176 i = tx_ring->next_to_use;
3177
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003178 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 buffer_info = &tx_ring->buffer_info[i];
3180 tx_desc = E1000_TX_DESC(*tx_ring, i);
3181 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3182 tx_desc->lower.data =
3183 cpu_to_le32(txd_lower | buffer_info->length);
3184 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003185 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 }
3187
3188 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3189
3190 /* Force memory writes to complete before letting h/w
3191 * know there are new descriptors to fetch. (Only
3192 * applicable for weak-ordered memory model archs,
3193 * such as IA-64). */
3194 wmb();
3195
3196 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003197 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003198 /* we need this if more than one processor can write to our tail
3199 * at a time, it syncronizes IO on IA64/Altix systems */
3200 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201}
3202
3203/**
3204 * 82547 workaround to avoid controller hang in half-duplex environment.
3205 * The workaround is to avoid queuing a large packet that would span
3206 * the internal Tx FIFO ring boundary by notifying the stack to resend
3207 * the packet at a later time. This gives the Tx FIFO an opportunity to
3208 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3209 * to the beginning of the Tx FIFO.
3210 **/
3211
3212#define E1000_FIFO_HDR 0x10
3213#define E1000_82547_PAD_LEN 0x3E0
3214
Auke Koke619d522006-04-14 19:04:52 -07003215static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
3217{
Joe Perches406874a2008-04-03 10:06:32 -07003218 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3219 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003221 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003223 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 goto no_fifo_stall_required;
3225
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003226 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 return 1;
3228
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003229 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 atomic_set(&adapter->tx_fifo_stall, 1);
3231 return 1;
3232 }
3233
3234no_fifo_stall_required:
3235 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003236 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3238 return 0;
3239}
3240
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003241#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07003242static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003243e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
3244{
3245 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003246 u16 length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003247 if (vlan_tx_tag_present(skb)) {
3248 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003249 ( adapter->hw.mng_cookie.status &
3250 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3251 return 0;
3252 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003253 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003254 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003255 if ((htons(ETH_P_IP) == eth->h_proto)) {
3256 const struct iphdr *ip =
Joe Perches406874a2008-04-03 10:06:32 -07003257 (struct iphdr *)((u8 *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003258 if (IPPROTO_UDP == ip->protocol) {
3259 struct udphdr *udp =
Joe Perches406874a2008-04-03 10:06:32 -07003260 (struct udphdr *)((u8 *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003261 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003262 if (ntohs(udp->dest) == 67) {
Joe Perches406874a2008-04-03 10:06:32 -07003263 offset = (u8 *)udp + 8 - skb->data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003264 length = skb->len - offset;
3265
3266 return e1000_mng_write_dhcp_info(hw,
Joe Perches406874a2008-04-03 10:06:32 -07003267 (u8 *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003268 length);
3269 }
3270 }
3271 }
3272 }
3273 return 0;
3274}
3275
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003276static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3277{
3278 struct e1000_adapter *adapter = netdev_priv(netdev);
3279 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3280
3281 netif_stop_queue(netdev);
3282 /* Herbert's original patch had:
3283 * smp_mb__after_netif_stop_queue();
3284 * but since that doesn't exist yet, just open code it. */
3285 smp_mb();
3286
3287 /* We need to check again in a case another CPU has just
3288 * made room available. */
3289 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3290 return -EBUSY;
3291
3292 /* A reprieve! */
3293 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003294 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003295 return 0;
3296}
3297
3298static int e1000_maybe_stop_tx(struct net_device *netdev,
3299 struct e1000_tx_ring *tx_ring, int size)
3300{
3301 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3302 return 0;
3303 return __e1000_maybe_stop_tx(netdev, size);
3304}
3305
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3307static int
3308e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3309{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003310 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003311 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3313 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3314 unsigned int tx_flags = 0;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003315 unsigned int len = skb->len - skb->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 unsigned long flags;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003317 unsigned int nr_frags;
3318 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003320 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 unsigned int f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003323 /* This goes back to the question of how to logically map a tx queue
3324 * to a flow. Right now, performance is impacted slightly negatively
3325 * if using multiple tx queues. If the stack breaks away from a
3326 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003327 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04003328
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003329 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 dev_kfree_skb_any(skb);
3331 return NETDEV_TX_OK;
3332 }
3333
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003334 /* 82571 and newer doesn't need the workaround that limited descriptor
3335 * length to 4kB */
3336 if (adapter->hw.mac_type >= e1000_82571)
3337 max_per_txd = 8192;
3338
Herbert Xu79671682006-06-22 02:40:14 -07003339 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003340 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 * make sure there is enough room in the FIFO before
3342 * initiating the DMA for each buffer. The calc is:
3343 * 4 = ceil(buffer len/mss). To make sure we don't
3344 * overrun the FIFO, adjust the max buffer len if mss
3345 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003346 if (mss) {
Joe Perches406874a2008-04-03 10:06:32 -07003347 u8 hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 max_per_txd = min(mss << 2, max_per_txd);
3349 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003350
Auke Kok90fb5132006-11-01 08:47:30 -08003351 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3352 * points to just header, pull a few bytes of payload from
3353 * frags into skb->data */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003354 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003355 if (skb->data_len && hdr_len == len) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003356 switch (adapter->hw.mac_type) {
3357 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003358 case e1000_82544:
3359 /* Make sure we have room to chop off 4 bytes,
3360 * and that the end alignment will work out to
3361 * this hardware's requirements
3362 * NOTE: this is a TSO only workaround
3363 * if end byte alignment not correct move us
3364 * into the next dword */
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003365 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003366 break;
3367 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003368 case e1000_82571:
3369 case e1000_82572:
3370 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003371 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003372 pull_size = min((unsigned int)4, skb->data_len);
3373 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003374 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003375 "__pskb_pull_tail failed.\n");
3376 dev_kfree_skb_any(skb);
Jeff Garzik749dfc72006-03-11 13:35:31 -05003377 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003378 }
3379 len = skb->len - skb->data_len;
3380 break;
3381 default:
3382 /* do nothing */
3383 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003384 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 }
3387
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003388 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003389 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003391 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003392
Jeff Kirsherfd803242005-12-13 00:06:22 -05003393 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003394 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003395 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003396
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 count += TXD_USE_COUNT(len, max_txd_pwr);
3398
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003399 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 count++;
3401
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003402 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003403 * in PCI-X mode, so add one more descriptor to the count
3404 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003405 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003406 (len > 2015)))
3407 count++;
3408
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003410 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3412 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003413 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 count += nr_frags;
3415
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003416
3417 if (adapter->hw.tx_pkt_filtering &&
3418 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003419 e1000_transfer_dhcp_info(adapter, skb);
3420
Mark Huthf50393f2007-03-06 08:57:26 -08003421 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003422 /* Collision - tell upper layer to requeue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003423 return NETDEV_TX_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424
3425 /* need: count + 2 desc gap to keep tail from touching
3426 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003427 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003428 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 return NETDEV_TX_BUSY;
3430 }
3431
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003432 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3433 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003435 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003436 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 return NETDEV_TX_BUSY;
3438 }
3439 }
3440
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003441 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 tx_flags |= E1000_TX_FLAGS_VLAN;
3443 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3444 }
3445
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003446 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003447
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003448 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 if (tso < 0) {
3450 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003451 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 return NETDEV_TX_OK;
3453 }
3454
Jeff Kirsherfd803242005-12-13 00:06:22 -05003455 if (likely(tso)) {
3456 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003458 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 tx_flags |= E1000_TX_FLAGS_CSUM;
3460
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003461 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003462 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003463 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003464 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003465 tx_flags |= E1000_TX_FLAGS_IPV4;
3466
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003467 e1000_tx_queue(adapter, tx_ring, tx_flags,
3468 e1000_tx_map(adapter, tx_ring, skb, first,
3469 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
3471 netdev->trans_start = jiffies;
3472
3473 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003474 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003476 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 return NETDEV_TX_OK;
3478}
3479
3480/**
3481 * e1000_tx_timeout - Respond to a Tx Hang
3482 * @netdev: network interface device structure
3483 **/
3484
3485static void
3486e1000_tx_timeout(struct net_device *netdev)
3487{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003488 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489
3490 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003491 adapter->tx_timeout_count++;
3492 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493}
3494
3495static void
David Howells65f27f32006-11-22 14:55:48 +00003496e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497{
David Howells65f27f32006-11-22 14:55:48 +00003498 struct e1000_adapter *adapter =
3499 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500
Auke Kok2db10a02006-06-27 09:06:28 -07003501 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502}
3503
3504/**
3505 * e1000_get_stats - Get System Network Statistics
3506 * @netdev: network interface device structure
3507 *
3508 * Returns the address of the device statistics structure.
3509 * The statistics are actually updated from the timer callback.
3510 **/
3511
3512static struct net_device_stats *
3513e1000_get_stats(struct net_device *netdev)
3514{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003515 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003517 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 return &adapter->net_stats;
3519}
3520
3521/**
3522 * e1000_change_mtu - Change the Maximum Transfer Unit
3523 * @netdev: network interface device structure
3524 * @new_mtu: new value for maximum frame size
3525 *
3526 * Returns 0 on success, negative on failure
3527 **/
3528
3529static int
3530e1000_change_mtu(struct net_device *netdev, int new_mtu)
3531{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003532 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Joe Perches406874a2008-04-03 10:06:32 -07003534 u16 eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003536 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3537 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3538 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003539 return -EINVAL;
3540 }
3541
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003542 /* Adapter-specific max frame size limits. */
3543 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003544 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003545 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003546 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3547 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003548 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003549 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003550 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003551 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003552 /* Jumbo Frames not supported if:
3553 * - this is not an 82573L device
3554 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003555 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3556 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003557 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3558 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003559 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3560 DPRINTK(PROBE, ERR,
3561 "Jumbo Frames not supported.\n");
3562 return -EINVAL;
3563 }
3564 break;
3565 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003566 /* ERT will be enabled later to enable wire speed receives */
3567
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003568 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003569 case e1000_82571:
3570 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003571 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003572#define MAX_STD_JUMBO_FRAME_SIZE 9234
3573 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3574 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3575 return -EINVAL;
3576 }
3577 break;
3578 default:
3579 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3580 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003581 }
3582
David S. Miller87f50322006-07-31 22:39:40 -07003583 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003584 * means we reserve 2 more, this pushes us to allocate from the next
3585 * larger slab size
3586 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003587
Auke Kok9e2feac2006-04-14 19:05:18 -07003588 if (max_frame <= E1000_RXBUFFER_256)
3589 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3590 else if (max_frame <= E1000_RXBUFFER_512)
3591 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3592 else if (max_frame <= E1000_RXBUFFER_1024)
3593 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3594 else if (max_frame <= E1000_RXBUFFER_2048)
3595 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3596 else if (max_frame <= E1000_RXBUFFER_4096)
3597 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3598 else if (max_frame <= E1000_RXBUFFER_8192)
3599 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3600 else if (max_frame <= E1000_RXBUFFER_16384)
3601 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3602
3603 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003604 if (!adapter->hw.tbi_compatibility_on &&
3605 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3606 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3607 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003608
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003609 netdev->mtu = new_mtu;
Bruce Allan83cd8272006-12-15 10:36:35 +01003610 adapter->hw.max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003611
Auke Kok2db10a02006-06-27 09:06:28 -07003612 if (netif_running(netdev))
3613 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 return 0;
3616}
3617
3618/**
3619 * e1000_update_stats - Update the board statistics counters
3620 * @adapter: board private structure
3621 **/
3622
3623void
3624e1000_update_stats(struct e1000_adapter *adapter)
3625{
3626 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003627 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07003629 u16 phy_tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630
3631#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3632
Linas Vepstas282f33c2006-06-08 22:19:44 -07003633 /*
3634 * Prevent stats update while adapter is being reset, or if the pci
3635 * connection is down.
3636 */
Auke Kok90267292006-06-08 09:30:24 -07003637 if (adapter->link_speed == 0)
3638 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003639 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003640 return;
Auke Kok90267292006-06-08 09:30:24 -07003641
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 spin_lock_irqsave(&adapter->stats_lock, flags);
3643
Masatake YAMATO828d0552007-10-20 03:06:37 +02003644 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 * called from the interrupt context, so they must only
3646 * be written while holding adapter->stats_lock
3647 */
3648
3649 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3650 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3651 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3652 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3653 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3654 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3655 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003656
3657 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003658 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3659 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3660 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3661 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3662 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3663 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665
3666 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3667 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3668 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3669 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3670 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3671 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3672 adapter->stats.dc += E1000_READ_REG(hw, DC);
3673 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3674 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3675 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3676 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3677 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3678 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3679 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3680 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3681 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3682 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3683 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3684 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3685 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3686 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3687 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3688 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3689 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3690 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3691 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003692
3693 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003694 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3695 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3696 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3697 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3698 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3699 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003700 }
3701
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3703 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3704
3705 /* used for adaptive IFS */
3706
3707 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3708 adapter->stats.tpt += hw->tx_packet_delta;
3709 hw->collision_delta = E1000_READ_REG(hw, COLC);
3710 adapter->stats.colc += hw->collision_delta;
3711
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003712 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3714 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3715 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3716 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3717 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3718 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3719 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003720 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003721 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3722 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003723
3724 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003725 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3726 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3727 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3728 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3729 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3730 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3731 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003732 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003733 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734
3735 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 adapter->net_stats.multicast = adapter->stats.mprc;
3737 adapter->net_stats.collisions = adapter->stats.colc;
3738
3739 /* Rx Errors */
3740
Jeff Kirsher87041632006-03-02 18:21:24 -08003741 /* RLEC on some newer hardware can be incorrect so build
3742 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3744 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003745 adapter->stats.ruc + adapter->stats.roc +
3746 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003747 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3748 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3750 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3752
3753 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003754 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3755 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3757 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3758 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Jeff Garzik167fb282006-12-15 10:41:15 -05003759 if (adapter->hw.bad_tx_carr_stats_fd &&
3760 adapter->link_duplex == FULL_DUPLEX) {
3761 adapter->net_stats.tx_carrier_errors = 0;
3762 adapter->stats.tncrs = 0;
3763 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764
3765 /* Tx Dropped needs to be maintained elsewhere */
3766
3767 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003768 if (hw->media_type == e1000_media_type_copper) {
3769 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3771 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3772 adapter->phy_stats.idle_errors += phy_tmp;
3773 }
3774
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003775 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 (hw->phy_type == e1000_phy_m88) &&
3777 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3778 adapter->phy_stats.receive_errors += phy_tmp;
3779 }
3780
Jeff Garzik15e376b2006-12-15 11:16:33 -05003781 /* Management Stats */
3782 if (adapter->hw.has_smbus) {
3783 adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
3784 adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
3785 adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
3786 }
3787
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3789}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003790
3791/**
3792 * e1000_intr_msi - Interrupt Handler
3793 * @irq: interrupt number
3794 * @data: pointer to a network interface device structure
3795 **/
3796
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003797static irqreturn_t
3798e1000_intr_msi(int irq, void *data)
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003799{
3800 struct net_device *netdev = data;
3801 struct e1000_adapter *adapter = netdev_priv(netdev);
3802 struct e1000_hw *hw = &adapter->hw;
3803#ifndef CONFIG_E1000_NAPI
3804 int i;
3805#endif
Joe Perches406874a2008-04-03 10:06:32 -07003806 u32 icr = E1000_READ_REG(hw, ICR);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003807
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003808 /* in NAPI mode read ICR disables interrupts using IAM */
3809
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003810 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3811 hw->get_link_status = 1;
3812 /* 80003ES2LAN workaround-- For packet buffer work-around on
3813 * link down event; disable receives here in the ISR and reset
3814 * adapter in watchdog */
3815 if (netif_carrier_ok(netdev) &&
3816 (adapter->hw.mac_type == e1000_80003es2lan)) {
3817 /* disable receives */
Joe Perches406874a2008-04-03 10:06:32 -07003818 u32 rctl = E1000_READ_REG(hw, RCTL);
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003819 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003820 }
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003821 /* guard against interrupt when we're going down */
3822 if (!test_bit(__E1000_DOWN, &adapter->flags))
3823 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003824 }
3825
3826#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003827 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003828 adapter->total_tx_bytes = 0;
3829 adapter->total_tx_packets = 0;
3830 adapter->total_rx_bytes = 0;
3831 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003832 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003833 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003834 e1000_irq_enable(adapter);
3835#else
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003836 adapter->total_tx_bytes = 0;
3837 adapter->total_rx_bytes = 0;
3838 adapter->total_tx_packets = 0;
3839 adapter->total_rx_packets = 0;
3840
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003841 for (i = 0; i < E1000_MAX_INTR; i++)
3842 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003843 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003844 break;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003845
3846 if (likely(adapter->itr_setting & 3))
3847 e1000_set_itr(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003848#endif
3849
3850 return IRQ_HANDLED;
3851}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852
3853/**
3854 * e1000_intr - Interrupt Handler
3855 * @irq: interrupt number
3856 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 **/
3858
3859static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003860e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861{
3862 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003863 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003865 u32 rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003866#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003867 int i;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003868#endif
3869 if (unlikely(!icr))
3870 return IRQ_NONE; /* Not our interrupt */
3871
3872#ifdef CONFIG_E1000_NAPI
3873 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3874 * not set, then the adapter didn't send an interrupt */
3875 if (unlikely(hw->mac_type >= e1000_82571 &&
3876 !(icr & E1000_ICR_INT_ASSERTED)))
3877 return IRQ_NONE;
3878
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003879 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3880 * need for the IMC write */
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003881#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003883 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003885 /* 80003ES2LAN workaround--
3886 * For packet buffer work-around on link down event;
3887 * disable receives here in the ISR and
3888 * reset adapter in watchdog
3889 */
3890 if (netif_carrier_ok(netdev) &&
3891 (adapter->hw.mac_type == e1000_80003es2lan)) {
3892 /* disable receives */
3893 rctl = E1000_READ_REG(hw, RCTL);
3894 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3895 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003896 /* guard against interrupt when we're going down */
3897 if (!test_bit(__E1000_DOWN, &adapter->flags))
3898 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 }
3900
3901#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003902 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003903 /* disable interrupts, without the synchronize_irq bit */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003904 E1000_WRITE_REG(hw, IMC, ~0);
3905 E1000_WRITE_FLUSH(hw);
3906 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003907 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003908 adapter->total_tx_bytes = 0;
3909 adapter->total_tx_packets = 0;
3910 adapter->total_rx_bytes = 0;
3911 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003912 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003913 } else
Auke Kok90fb5132006-11-01 08:47:30 -08003914 /* this really should not happen! if it does it is basically a
3915 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003916 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003917#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003919 * Due to Hub Link bus being occupied, an interrupt
3920 * de-assertion message is not able to be sent.
3921 * When an interrupt assertion message is generated later,
3922 * two messages are re-ordered and sent out.
3923 * That causes APIC to think 82547 is in de-assertion
3924 * state, while 82547 is in assertion state, resulting
3925 * in dead lock. Writing IMC forces 82547 into
3926 * de-assertion state.
3927 */
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003928 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Malli Chilakala26483452005-04-28 19:44:46 -07003929 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003931 adapter->total_tx_bytes = 0;
3932 adapter->total_rx_bytes = 0;
3933 adapter->total_tx_packets = 0;
3934 adapter->total_rx_packets = 0;
3935
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003936 for (i = 0; i < E1000_MAX_INTR; i++)
3937 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003938 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 break;
3940
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003941 if (likely(adapter->itr_setting & 3))
3942 e1000_set_itr(adapter);
3943
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003944 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003946
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003947#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 return IRQ_HANDLED;
3949}
3950
3951#ifdef CONFIG_E1000_NAPI
3952/**
3953 * e1000_clean - NAPI Rx polling callback
3954 * @adapter: board private structure
3955 **/
3956
3957static int
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003958e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003960 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3961 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003962 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003963
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003964 /* Must NOT use netdev_priv macro here. */
3965 adapter = poll_dev->priv;
3966
Auke Kokd3d9e482006-07-14 16:14:23 -07003967 /* e1000_clean is called per-cpu. This lock protects
3968 * tx_ring[0] from being cleaned by multiple cpus
3969 * simultaneously. A failure obtaining the lock means
3970 * tx_ring[0] is currently being cleaned anyway. */
3971 if (spin_trylock(&adapter->tx_queue_lock)) {
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003972 tx_cleaned = e1000_clean_tx_irq(adapter,
3973 &adapter->tx_ring[0]);
Auke Kokd3d9e482006-07-14 16:14:23 -07003974 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003975 }
3976
Auke Kokd3d9e482006-07-14 16:14:23 -07003977 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003978 &work_done, budget);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003979
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003980 if (tx_cleaned)
3981 work_done = budget;
3982
David S. Miller53e52c72008-01-07 21:06:12 -08003983 /* If budget not fully consumed, exit the polling mode */
3984 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003985 if (likely(adapter->itr_setting & 3))
3986 e1000_set_itr(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003987 netif_rx_complete(poll_dev, napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 }
3990
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003991 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992}
3993
3994#endif
3995/**
3996 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3997 * @adapter: board private structure
3998 **/
3999
Joe Perchesc3033b02008-03-21 11:06:25 -07004000static bool
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004001e1000_clean_tx_irq(struct e1000_adapter *adapter,
4002 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 struct net_device *netdev = adapter->netdev;
4005 struct e1000_tx_desc *tx_desc, *eop_desc;
4006 struct e1000_buffer *buffer_info;
4007 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004008#ifdef CONFIG_E1000_NAPI
4009 unsigned int count = 0;
4010#endif
Joe Perchesc3033b02008-03-21 11:06:25 -07004011 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004012 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013
4014 i = tx_ring->next_to_clean;
4015 eop = tx_ring->buffer_info[i].next_to_watch;
4016 eop_desc = E1000_TX_DESC(*tx_ring, eop);
4017
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004018 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Joe Perchesc3033b02008-03-21 11:06:25 -07004019 for (cleaned = false; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 tx_desc = E1000_TX_DESC(*tx_ring, i);
4021 buffer_info = &tx_ring->buffer_info[i];
4022 cleaned = (i == eop);
4023
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004024 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004025 struct sk_buff *skb = buffer_info->skb;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08004026 unsigned int segs, bytecount;
4027 segs = skb_shinfo(skb)->gso_segs ?: 1;
4028 /* multiply data chunks by size of headers */
4029 bytecount = ((segs - 1) * skb_headlen(skb)) +
4030 skb->len;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01004031 total_tx_packets += segs;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08004032 total_tx_bytes += bytecount;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004033 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05004034 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08004035 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004037 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004039
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 eop = tx_ring->buffer_info[i].next_to_watch;
4041 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004042#ifdef CONFIG_E1000_NAPI
4043#define E1000_TX_WEIGHT 64
4044 /* weight of a sort for tx, to avoid endless transmit cleanup */
Linus Torvalds46fcc862007-04-19 18:21:01 -07004045 if (count++ == E1000_TX_WEIGHT) break;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08004046#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 }
4048
4049 tx_ring->next_to_clean = i;
4050
Auke Kok77b2aad2006-04-14 19:05:25 -07004051#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07004052 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
4053 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
4054 /* Make sure that anybody stopping the queue after this
4055 * sees the new next_to_clean.
4056 */
4057 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004058 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07004059 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004060 ++adapter->restart_queue;
4061 }
Auke Kok77b2aad2006-04-14 19:05:25 -07004062 }
Malli Chilakala26483452005-04-28 19:44:46 -07004063
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004064 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07004065 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 * check with the clearing of time_stamp and movement of i */
Joe Perchesc3033b02008-03-21 11:06:25 -07004067 adapter->detect_tx_hung = false;
Jeff Kirsher392137f2006-01-12 16:50:57 -08004068 if (tx_ring->buffer_info[eop].dma &&
4069 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08004070 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004071 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08004072 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004073
4074 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07004075 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004076 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004077 " TDH <%x>\n"
4078 " TDT <%x>\n"
4079 " next_to_use <%x>\n"
4080 " next_to_clean <%x>\n"
4081 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004082 " time_stamp <%lx>\n"
4083 " next_to_watch <%x>\n"
4084 " jiffies <%lx>\n"
4085 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004086 (unsigned long)((tx_ring - adapter->tx_ring) /
4087 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004088 readl(adapter->hw.hw_addr + tx_ring->tdh),
4089 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004090 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08004091 tx_ring->next_to_clean,
4092 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004093 eop,
4094 jiffies,
4095 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004099 adapter->total_tx_bytes += total_tx_bytes;
4100 adapter->total_tx_packets += total_tx_packets;
Auke Kokef90e4e2007-11-13 20:49:15 -08004101 adapter->net_stats.tx_bytes += total_tx_bytes;
4102 adapter->net_stats.tx_packets += total_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 return cleaned;
4104}
4105
4106/**
4107 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004108 * @adapter: board private structure
4109 * @status_err: receive descriptor status and error fields
4110 * @csum: receive descriptor csum field
4111 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 **/
4113
Auke Koke619d522006-04-14 19:04:52 -07004114static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115e1000_rx_checksum(struct e1000_adapter *adapter,
Joe Perches406874a2008-04-03 10:06:32 -07004116 u32 status_err, u32 csum,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004117 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118{
Joe Perches406874a2008-04-03 10:06:32 -07004119 u16 status = (u16)status_err;
4120 u8 errors = (u8)(status_err >> 24);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004121 skb->ip_summed = CHECKSUM_NONE;
4122
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004124 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004126 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004127 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004128 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004129 /* let the stack verify checksum errors */
4130 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 return;
4132 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004133 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004134 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
4135 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004136 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004138 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004139 return;
4140 }
4141 /* It must be a TCP or UDP packet with a valid checksum */
4142 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 /* TCP checksum is good */
4144 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004145 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
4146 /* IP fragment with UDP payload */
4147 /* Hardware complements the payload checksum, so we undo it
4148 * and then put the value in host order for further stack use.
4149 */
Al Viro3e188262007-12-11 19:49:39 +00004150 __sum16 sum = (__force __sum16)htons(csum);
4151 skb->csum = csum_unfold(~sum);
Patrick McHardy84fa7932006-08-29 16:44:56 -07004152 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004154 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155}
4156
4157/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004158 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 * @adapter: board private structure
4160 **/
4161
Joe Perchesc3033b02008-03-21 11:06:25 -07004162static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004164e1000_clean_rx_irq(struct e1000_adapter *adapter,
4165 struct e1000_rx_ring *rx_ring,
4166 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004168e1000_clean_rx_irq(struct e1000_adapter *adapter,
4169 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170#endif
4171{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 struct net_device *netdev = adapter->netdev;
4173 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004174 struct e1000_rx_desc *rx_desc, *next_rxd;
4175 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07004177 u32 length;
4178 u8 last_byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004180 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004181 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004182 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183
4184 i = rx_ring->next_to_clean;
4185 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004186 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004188 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004189 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004190 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004191
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004193 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 break;
4195 (*work_done)++;
4196#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08004197 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004198 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004199 buffer_info->skb = NULL;
4200
Jeff Kirsher30320be2006-03-02 18:21:57 -08004201 prefetch(skb->data - NET_IP_ALIGN);
4202
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004203 if (++i == rx_ring->count) i = 0;
4204 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004205 prefetch(next_rxd);
4206
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004207 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004208
Joe Perchesc3033b02008-03-21 11:06:25 -07004209 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004210 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004211 pci_unmap_single(pdev,
4212 buffer_info->dma,
4213 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 PCI_DMA_FROMDEVICE);
4215
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 length = le16_to_cpu(rx_desc->length);
4217
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004218 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4219 /* All receives must fit into a single buffer */
4220 E1000_DBG("%s: Receive packet consumed multiple"
4221 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004222 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004223 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 goto next_desc;
4225 }
4226
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004227 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004229 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 rx_desc->errors, length, last_byte)) {
4231 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004232 e1000_tbi_adjust_stats(&adapter->hw,
4233 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 length, skb->data);
4235 spin_unlock_irqrestore(&adapter->stats_lock,
4236 flags);
4237 length--;
4238 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004239 /* recycle */
4240 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241 goto next_desc;
4242 }
Auke Kok1cb58212006-04-18 12:31:04 -07004243 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004245 /* adjust length to remove Ethernet CRC, this must be
4246 * done after the TBI_ACCEPT workaround above */
4247 length -= 4;
4248
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004249 /* probably a little skewed due to removing CRC */
4250 total_rx_bytes += length;
4251 total_rx_packets++;
4252
Jeff Kirshera292ca62006-01-12 16:51:30 -08004253 /* code added for copybreak, this should improve
4254 * performance for small packets with large amounts
4255 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004256 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004257 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004258 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004259 if (new_skb) {
4260 skb_reserve(new_skb, NET_IP_ALIGN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004261 skb_copy_to_linear_data_offset(new_skb,
4262 -NET_IP_ALIGN,
4263 (skb->data -
4264 NET_IP_ALIGN),
4265 (length +
4266 NET_IP_ALIGN));
Jeff Kirshera292ca62006-01-12 16:51:30 -08004267 /* save the skb in buffer_info as good */
4268 buffer_info->skb = skb;
4269 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004270 }
Auke Kok996695d2006-11-01 08:47:50 -08004271 /* else just continue with the old one */
4272 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004273 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004274 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275
4276 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004277 e1000_rx_checksum(adapter,
Joe Perches406874a2008-04-03 10:06:32 -07004278 (u32)(status) |
4279 ((u32)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004280 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004281
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 skb->protocol = eth_type_trans(skb, netdev);
4283#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004284 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08004285 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004287 le16_to_cpu(rx_desc->special));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288 } else {
4289 netif_receive_skb(skb);
4290 }
4291#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004292 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004293 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 vlan_hwaccel_rx(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004295 le16_to_cpu(rx_desc->special));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 } else {
4297 netif_rx(skb);
4298 }
4299#endif /* CONFIG_E1000_NAPI */
4300 netdev->last_rx = jiffies;
4301
4302next_desc:
4303 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004305 /* return some buffers to hardware, one at a time is too slow */
4306 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4307 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4308 cleaned_count = 0;
4309 }
4310
Jeff Kirsher30320be2006-03-02 18:21:57 -08004311 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004312 rx_desc = next_rxd;
4313 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004316
4317 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4318 if (cleaned_count)
4319 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004321 adapter->total_rx_packets += total_rx_packets;
4322 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004323 adapter->net_stats.rx_bytes += total_rx_bytes;
4324 adapter->net_stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 return cleaned;
4326}
4327
4328/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004329 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4330 * @adapter: board private structure
4331 **/
4332
Joe Perchesc3033b02008-03-21 11:06:25 -07004333static bool
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004334#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004335e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4336 struct e1000_rx_ring *rx_ring,
4337 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004338#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004339e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4340 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004341#endif
4342{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004343 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004344 struct net_device *netdev = adapter->netdev;
4345 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004346 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004347 struct e1000_ps_page *ps_page;
4348 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07004349 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004350 unsigned int i, j;
Joe Perches406874a2008-04-03 10:06:32 -07004351 u32 length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004352 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004353 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004354 unsigned int total_rx_bytes=0, total_rx_packets=0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004355
4356 i = rx_ring->next_to_clean;
4357 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07004358 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07004359 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004360
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004361 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004362 ps_page = &rx_ring->ps_page[i];
4363 ps_page_dma = &rx_ring->ps_page_dma[i];
4364#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004365 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004366 break;
4367 (*work_done)++;
4368#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004369 skb = buffer_info->skb;
4370
Jeff Kirsher30320be2006-03-02 18:21:57 -08004371 /* in the packet split case this is header only */
4372 prefetch(skb->data - NET_IP_ALIGN);
4373
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004374 if (++i == rx_ring->count) i = 0;
4375 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004376 prefetch(next_rxd);
4377
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004378 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004379
Joe Perchesc3033b02008-03-21 11:06:25 -07004380 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004381 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004382 pci_unmap_single(pdev, buffer_info->dma,
4383 buffer_info->length,
4384 PCI_DMA_FROMDEVICE);
4385
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004386 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004387 E1000_DBG("%s: Packet Split buffers didn't pick up"
4388 " the full packet\n", netdev->name);
4389 dev_kfree_skb_irq(skb);
4390 goto next_desc;
4391 }
4392
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004393 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004394 dev_kfree_skb_irq(skb);
4395 goto next_desc;
4396 }
4397
4398 length = le16_to_cpu(rx_desc->wb.middle.length0);
4399
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004400 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004401 E1000_DBG("%s: Last part of the packet spanning"
4402 " multiple descriptors\n", netdev->name);
4403 dev_kfree_skb_irq(skb);
4404 goto next_desc;
4405 }
4406
4407 /* Good Receive */
4408 skb_put(skb, length);
4409
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004410 {
4411 /* this looks ugly, but it seems compiler issues make it
4412 more efficient than reusing j */
4413 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4414
4415 /* page alloc/put takes too long and effects small packet
4416 * throughput, so unsplit small packets and save the alloc/put*/
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004417 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004418 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004419 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004420 * kmap_atomic, so we can't hold the mapping
4421 * very long */
4422 pci_dma_sync_single_for_cpu(pdev,
4423 ps_page_dma->ps_page_dma[0],
4424 PAGE_SIZE,
4425 PCI_DMA_FROMDEVICE);
4426 vaddr = kmap_atomic(ps_page->ps_page[0],
4427 KM_SKB_DATA_SOFTIRQ);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07004428 memcpy(skb_tail_pointer(skb), vaddr, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004429 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4430 pci_dma_sync_single_for_device(pdev,
4431 ps_page_dma->ps_page_dma[0],
4432 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004433 /* remove the CRC */
4434 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004435 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004436 goto copydone;
4437 } /* if */
4438 }
Auke Kok90fb5132006-11-01 08:47:30 -08004439
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004440 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004441 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004442 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004443 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4444 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4445 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004446 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4447 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004448 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004449 skb->len += length;
4450 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004451 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004452 }
4453
Auke Kokf235a2a2006-07-14 16:14:34 -07004454 /* strip the ethernet crc, problem is we're using pages now so
4455 * this whole operation can get a little cpu intensive */
4456 pskb_trim(skb, skb->len - 4);
4457
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004458copydone:
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004459 total_rx_bytes += skb->len;
4460 total_rx_packets++;
4461
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004462 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004463 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004464 skb->protocol = eth_type_trans(skb, netdev);
4465
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004466 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004467 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004468 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004469#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004470 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004471 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004472 le16_to_cpu(rx_desc->wb.middle.vlan));
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004473 } else {
4474 netif_receive_skb(skb);
4475 }
4476#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004477 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004478 vlan_hwaccel_rx(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004479 le16_to_cpu(rx_desc->wb.middle.vlan));
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004480 } else {
4481 netif_rx(skb);
4482 }
4483#endif /* CONFIG_E1000_NAPI */
4484 netdev->last_rx = jiffies;
4485
4486next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004487 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004488 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004489
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004490 /* return some buffers to hardware, one at a time is too slow */
4491 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4492 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4493 cleaned_count = 0;
4494 }
4495
Jeff Kirsher30320be2006-03-02 18:21:57 -08004496 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004497 rx_desc = next_rxd;
4498 buffer_info = next_buffer;
4499
Malli Chilakala683a38f2005-06-17 17:43:25 -07004500 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004501 }
4502 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004503
4504 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4505 if (cleaned_count)
4506 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004507
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004508 adapter->total_rx_packets += total_rx_packets;
4509 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004510 adapter->net_stats.rx_bytes += total_rx_bytes;
4511 adapter->net_stats.rx_packets += total_rx_packets;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004512 return cleaned;
4513}
4514
4515/**
4516 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 * @adapter: address of board private structure
4518 **/
4519
4520static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004521e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004522 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004523 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 struct net_device *netdev = adapter->netdev;
4526 struct pci_dev *pdev = adapter->pdev;
4527 struct e1000_rx_desc *rx_desc;
4528 struct e1000_buffer *buffer_info;
4529 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004530 unsigned int i;
4531 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532
4533 i = rx_ring->next_to_use;
4534 buffer_info = &rx_ring->buffer_info[i];
4535
Jeff Kirshera292ca62006-01-12 16:51:30 -08004536 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004537 skb = buffer_info->skb;
4538 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004539 skb_trim(skb, 0);
4540 goto map_skb;
4541 }
4542
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004543 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004544 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004546 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 break;
4548 }
4549
Malli Chilakala26483452005-04-28 19:44:46 -07004550 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4552 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004553 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4554 "at %p\n", bufsz, skb->data);
4555 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004556 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004557 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558 if (!skb) {
4559 dev_kfree_skb(oldskb);
4560 break;
4561 }
Malli Chilakala26483452005-04-28 19:44:46 -07004562
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4564 /* give up */
4565 dev_kfree_skb(skb);
4566 dev_kfree_skb(oldskb);
4567 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004569
4570 /* Use new allocation */
4571 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 /* Make buffer alignment 2 beyond a 16 byte boundary
4574 * this will result in a 16 byte aligned IP header after
4575 * the 14 byte MAC header is removed
4576 */
4577 skb_reserve(skb, NET_IP_ALIGN);
4578
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 buffer_info->skb = skb;
4580 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004581map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 buffer_info->dma = pci_map_single(pdev,
4583 skb->data,
4584 adapter->rx_buffer_len,
4585 PCI_DMA_FROMDEVICE);
4586
Malli Chilakala26483452005-04-28 19:44:46 -07004587 /* Fix for errata 23, can't cross 64kB boundary */
4588 if (!e1000_check_64k_bound(adapter,
4589 (void *)(unsigned long)buffer_info->dma,
4590 adapter->rx_buffer_len)) {
4591 DPRINTK(RX_ERR, ERR,
4592 "dma align check failed: %u bytes at %p\n",
4593 adapter->rx_buffer_len,
4594 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 dev_kfree_skb(skb);
4596 buffer_info->skb = NULL;
4597
Malli Chilakala26483452005-04-28 19:44:46 -07004598 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599 adapter->rx_buffer_len,
4600 PCI_DMA_FROMDEVICE);
4601
4602 break; /* while !buffer_info->skb */
4603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604 rx_desc = E1000_RX_DESC(*rx_ring, i);
4605 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4606
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004607 if (unlikely(++i == rx_ring->count))
4608 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609 buffer_info = &rx_ring->buffer_info[i];
4610 }
4611
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004612 if (likely(rx_ring->next_to_use != i)) {
4613 rx_ring->next_to_use = i;
4614 if (unlikely(i-- == 0))
4615 i = (rx_ring->count - 1);
4616
4617 /* Force memory writes to complete before letting h/w
4618 * know there are new descriptors to fetch. (Only
4619 * applicable for weak-ordered memory model archs,
4620 * such as IA-64). */
4621 wmb();
4622 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624}
4625
4626/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004627 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4628 * @adapter: address of board private structure
4629 **/
4630
4631static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004632e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004633 struct e1000_rx_ring *rx_ring,
4634 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004635{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004636 struct net_device *netdev = adapter->netdev;
4637 struct pci_dev *pdev = adapter->pdev;
4638 union e1000_rx_desc_packet_split *rx_desc;
4639 struct e1000_buffer *buffer_info;
4640 struct e1000_ps_page *ps_page;
4641 struct e1000_ps_page_dma *ps_page_dma;
4642 struct sk_buff *skb;
4643 unsigned int i, j;
4644
4645 i = rx_ring->next_to_use;
4646 buffer_info = &rx_ring->buffer_info[i];
4647 ps_page = &rx_ring->ps_page[i];
4648 ps_page_dma = &rx_ring->ps_page_dma[i];
4649
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004650 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004651 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4652
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004653 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004654 if (j < adapter->rx_ps_pages) {
4655 if (likely(!ps_page->ps_page[j])) {
4656 ps_page->ps_page[j] =
4657 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004658 if (unlikely(!ps_page->ps_page[j])) {
4659 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004660 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004661 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004662 ps_page_dma->ps_page_dma[j] =
4663 pci_map_page(pdev,
4664 ps_page->ps_page[j],
4665 0, PAGE_SIZE,
4666 PCI_DMA_FROMDEVICE);
4667 }
4668 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004669 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004670 * this info.
4671 */
4672 rx_desc->read.buffer_addr[j+1] =
4673 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4674 } else
Al Viro3e188262007-12-11 19:49:39 +00004675 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004676 }
4677
David S. Miller87f50322006-07-31 22:39:40 -07004678 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004679 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004680
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004681 if (unlikely(!skb)) {
4682 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004683 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004684 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004685
4686 /* Make buffer alignment 2 beyond a 16 byte boundary
4687 * this will result in a 16 byte aligned IP header after
4688 * the 14 byte MAC header is removed
4689 */
4690 skb_reserve(skb, NET_IP_ALIGN);
4691
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004692 buffer_info->skb = skb;
4693 buffer_info->length = adapter->rx_ps_bsize0;
4694 buffer_info->dma = pci_map_single(pdev, skb->data,
4695 adapter->rx_ps_bsize0,
4696 PCI_DMA_FROMDEVICE);
4697
4698 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4699
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004700 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004701 buffer_info = &rx_ring->buffer_info[i];
4702 ps_page = &rx_ring->ps_page[i];
4703 ps_page_dma = &rx_ring->ps_page_dma[i];
4704 }
4705
4706no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004707 if (likely(rx_ring->next_to_use != i)) {
4708 rx_ring->next_to_use = i;
4709 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4710
4711 /* Force memory writes to complete before letting h/w
4712 * know there are new descriptors to fetch. (Only
4713 * applicable for weak-ordered memory model archs,
4714 * such as IA-64). */
4715 wmb();
4716 /* Hardware increments by 16 bytes, but packet split
4717 * descriptors are 32 bytes...so we increment tail
4718 * twice as much.
4719 */
4720 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4721 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004722}
4723
4724/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4726 * @adapter:
4727 **/
4728
4729static void
4730e1000_smartspeed(struct e1000_adapter *adapter)
4731{
Joe Perches406874a2008-04-03 10:06:32 -07004732 u16 phy_status;
4733 u16 phy_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004735 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4737 return;
4738
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004739 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 /* If Master/Slave config fault is asserted twice,
4741 * we assume back-to-back */
4742 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004743 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004745 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004747 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4749 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4750 phy_ctrl);
4751 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004752 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4754 &phy_ctrl)) {
4755 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4756 MII_CR_RESTART_AUTO_NEG);
4757 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4758 phy_ctrl);
4759 }
4760 }
4761 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004762 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 /* If still no link, perhaps using 2/3 pair cable */
4764 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4765 phy_ctrl |= CR_1000T_MS_ENABLE;
4766 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004767 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4769 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4770 MII_CR_RESTART_AUTO_NEG);
4771 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4772 }
4773 }
4774 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004775 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776 adapter->smartspeed = 0;
4777}
4778
4779/**
4780 * e1000_ioctl -
4781 * @netdev:
4782 * @ifreq:
4783 * @cmd:
4784 **/
4785
4786static int
4787e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4788{
4789 switch (cmd) {
4790 case SIOCGMIIPHY:
4791 case SIOCGMIIREG:
4792 case SIOCSMIIREG:
4793 return e1000_mii_ioctl(netdev, ifr, cmd);
4794 default:
4795 return -EOPNOTSUPP;
4796 }
4797}
4798
4799/**
4800 * e1000_mii_ioctl -
4801 * @netdev:
4802 * @ifreq:
4803 * @cmd:
4804 **/
4805
4806static int
4807e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4808{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004809 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 struct mii_ioctl_data *data = if_mii(ifr);
4811 int retval;
Joe Perches406874a2008-04-03 10:06:32 -07004812 u16 mii_reg;
4813 u16 spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004814 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004816 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817 return -EOPNOTSUPP;
4818
4819 switch (cmd) {
4820 case SIOCGMIIPHY:
4821 data->phy_id = adapter->hw.phy_addr;
4822 break;
4823 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004824 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004826 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004827 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004828 &data->val_out)) {
4829 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004831 }
4832 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833 break;
4834 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004835 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004837 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 return -EFAULT;
4839 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004840 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004841 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004842 mii_reg)) {
4843 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004845 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004846 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Auke Kokdc86d322006-04-18 12:30:51 -07004847 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 switch (data->reg_num) {
4849 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004850 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004852 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853 adapter->hw.autoneg = 1;
4854 adapter->hw.autoneg_advertised = 0x2F;
4855 } else {
4856 if (mii_reg & 0x40)
4857 spddplx = SPEED_1000;
4858 else if (mii_reg & 0x2000)
4859 spddplx = SPEED_100;
4860 else
4861 spddplx = SPEED_10;
4862 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004863 ? DUPLEX_FULL :
4864 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 retval = e1000_set_spd_dplx(adapter,
4866 spddplx);
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004867 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 return retval;
4869 }
Auke Kok2db10a02006-06-27 09:06:28 -07004870 if (netif_running(adapter->netdev))
4871 e1000_reinit_locked(adapter);
4872 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 e1000_reset(adapter);
4874 break;
4875 case M88E1000_PHY_SPEC_CTRL:
4876 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004877 if (e1000_phy_reset(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 return -EIO;
4879 break;
4880 }
4881 } else {
4882 switch (data->reg_num) {
4883 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004884 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004886 if (netif_running(adapter->netdev))
4887 e1000_reinit_locked(adapter);
4888 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 e1000_reset(adapter);
4890 break;
4891 }
4892 }
4893 break;
4894 default:
4895 return -EOPNOTSUPP;
4896 }
4897 return E1000_SUCCESS;
4898}
4899
4900void
4901e1000_pci_set_mwi(struct e1000_hw *hw)
4902{
4903 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004904 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004906 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004907 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908}
4909
4910void
4911e1000_pci_clear_mwi(struct e1000_hw *hw)
4912{
4913 struct e1000_adapter *adapter = hw->back;
4914
4915 pci_clear_mwi(adapter->pdev);
4916}
4917
Peter Oruba007755e2007-09-28 22:42:06 -07004918int
4919e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4920{
4921 struct e1000_adapter *adapter = hw->back;
4922 return pcix_get_mmrbc(adapter->pdev);
4923}
4924
4925void
4926e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4927{
4928 struct e1000_adapter *adapter = hw->back;
4929 pcix_set_mmrbc(adapter->pdev, mmrbc);
4930}
4931
Joe Perches406874a2008-04-03 10:06:32 -07004932s32
4933e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004934{
4935 struct e1000_adapter *adapter = hw->back;
Joe Perches406874a2008-04-03 10:06:32 -07004936 u16 cap_offset;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004937
4938 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4939 if (!cap_offset)
4940 return -E1000_ERR_CONFIG;
4941
4942 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4943
4944 return E1000_SUCCESS;
4945}
4946
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947void
Joe Perches406874a2008-04-03 10:06:32 -07004948e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949{
4950 outl(value, port);
4951}
4952
4953static void
4954e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4955{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004956 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07004957 u32 ctrl, rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004959 if (!test_bit(__E1000_DOWN, &adapter->flags))
4960 e1000_irq_disable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961 adapter->vlgrp = grp;
4962
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004963 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964 /* enable VLAN tag insert/strip */
4965 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4966 ctrl |= E1000_CTRL_VME;
4967 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4968
Auke Kokcd94dd02006-06-27 09:08:22 -07004969 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004970 /* enable VLAN receive filtering */
4971 rctl = E1000_READ_REG(&adapter->hw, RCTL);
Auke Kok90fb5132006-11-01 08:47:30 -08004972 rctl &= ~E1000_RCTL_CFIEN;
4973 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4974 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004975 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 } else {
4977 /* disable VLAN tag insert/strip */
4978 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4979 ctrl &= ~E1000_CTRL_VME;
4980 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4981
Auke Kokcd94dd02006-06-27 09:08:22 -07004982 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004983 if (adapter->mng_vlan_id !=
Joe Perches406874a2008-04-03 10:06:32 -07004984 (u16)E1000_MNG_VLAN_NONE) {
Auke Kok90fb5132006-11-01 08:47:30 -08004985 e1000_vlan_rx_kill_vid(netdev,
4986 adapter->mng_vlan_id);
4987 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4988 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004989 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 }
4991
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004992 if (!test_bit(__E1000_DOWN, &adapter->flags))
4993 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994}
4995
4996static void
Joe Perches406874a2008-04-03 10:06:32 -07004997e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004999 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07005000 u32 vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005001
5002 if ((adapter->hw.mng_cookie.status &
5003 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
5004 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005005 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 /* add VID to filter table */
5007 index = (vid >> 5) & 0x7F;
5008 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5009 vfta |= (1 << (vid & 0x1F));
5010 e1000_write_vfta(&adapter->hw, index, vfta);
5011}
5012
5013static void
Joe Perches406874a2008-04-03 10:06:32 -07005014e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005016 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07005017 u32 vfta, index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018
Jesse Brandeburg9150b762008-03-21 11:06:58 -07005019 if (!test_bit(__E1000_DOWN, &adapter->flags))
5020 e1000_irq_disable(adapter);
Dan Aloni5c15bde2007-03-02 20:44:51 -08005021 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg9150b762008-03-21 11:06:58 -07005022 if (!test_bit(__E1000_DOWN, &adapter->flags))
5023 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005025 if ((adapter->hw.mng_cookie.status &
5026 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08005027 (vid == adapter->mng_vlan_id)) {
5028 /* release control to f/w */
5029 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005030 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08005031 }
5032
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033 /* remove VID from filter table */
5034 index = (vid >> 5) & 0x7F;
5035 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5036 vfta &= ~(1 << (vid & 0x1F));
5037 e1000_write_vfta(&adapter->hw, index, vfta);
5038}
5039
5040static void
5041e1000_restore_vlan(struct e1000_adapter *adapter)
5042{
5043 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
5044
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005045 if (adapter->vlgrp) {
Joe Perches406874a2008-04-03 10:06:32 -07005046 u16 vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005047 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08005048 if (!vlan_group_get_device(adapter->vlgrp, vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049 continue;
5050 e1000_vlan_rx_add_vid(adapter->netdev, vid);
5051 }
5052 }
5053}
5054
5055int
Joe Perches406874a2008-04-03 10:06:32 -07005056e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057{
5058 adapter->hw.autoneg = 0;
5059
Malli Chilakala69213682005-06-17 17:44:20 -07005060 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005061 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07005062 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
5063 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
5064 return -EINVAL;
5065 }
5066
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005067 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 case SPEED_10 + DUPLEX_HALF:
5069 adapter->hw.forced_speed_duplex = e1000_10_half;
5070 break;
5071 case SPEED_10 + DUPLEX_FULL:
5072 adapter->hw.forced_speed_duplex = e1000_10_full;
5073 break;
5074 case SPEED_100 + DUPLEX_HALF:
5075 adapter->hw.forced_speed_duplex = e1000_100_half;
5076 break;
5077 case SPEED_100 + DUPLEX_FULL:
5078 adapter->hw.forced_speed_duplex = e1000_100_full;
5079 break;
5080 case SPEED_1000 + DUPLEX_FULL:
5081 adapter->hw.autoneg = 1;
5082 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
5083 break;
5084 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5085 default:
Malli Chilakala26483452005-04-28 19:44:46 -07005086 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 return -EINVAL;
5088 }
5089 return 0;
5090}
5091
5092static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07005093e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094{
5095 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005096 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07005097 u32 ctrl, ctrl_ext, rctl, status;
5098 u32 wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07005099#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08005100 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07005101#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102
5103 netif_device_detach(netdev);
5104
Auke Kok2db10a02006-06-27 09:06:28 -07005105 if (netif_running(netdev)) {
5106 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07005108 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005110#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005111 retval = pci_save_state(pdev);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005112 if (retval)
5113 return retval;
5114#endif
5115
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005117 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118 wufc &= ~E1000_WUFC_LNKC;
5119
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005120 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005122 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123
5124 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005125 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5127 rctl |= E1000_RCTL_MPE;
5128 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5129 }
5130
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005131 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5133 /* advertise wake from D3Cold */
5134 #define E1000_CTRL_ADVD3WUC 0x00100000
5135 /* phy power management enable */
5136 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5137 ctrl |= E1000_CTRL_ADVD3WUC |
5138 E1000_CTRL_EN_PHY_PWR_MGMT;
5139 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5140 }
5141
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005142 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 adapter->hw.media_type == e1000_media_type_internal_serdes) {
5144 /* keep the laser running in D3 */
5145 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
5146 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5147 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
5148 }
5149
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005150 /* Allow time for pending master requests to run */
5151 e1000_disable_pciex_master(&adapter->hw);
5152
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
5154 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07005155 pci_enable_wake(pdev, PCI_D3hot, 1);
5156 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 } else {
5158 E1000_WRITE_REG(&adapter->hw, WUC, 0);
5159 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07005160 pci_enable_wake(pdev, PCI_D3hot, 0);
5161 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 }
5163
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005164 e1000_release_manageability(adapter);
5165
5166 /* make sure adapter isn't asleep if manageability is enabled */
5167 if (adapter->en_mng_pt) {
5168 pci_enable_wake(pdev, PCI_D3hot, 1);
5169 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 }
5171
Auke Kokcd94dd02006-06-27 09:08:22 -07005172 if (adapter->hw.phy_type == e1000_phy_igp_3)
5173 e1000_phy_powerdown_workaround(&adapter->hw);
5174
Auke Kokedd106f2006-11-06 08:57:12 -08005175 if (netif_running(netdev))
5176 e1000_free_irq(adapter);
5177
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005178 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5179 * would have already happened in close and is redundant. */
5180 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005181
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005183
Auke Kokd0e027d2006-04-14 19:04:40 -07005184 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185
5186 return 0;
5187}
5188
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005189#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190static int
5191e1000_resume(struct pci_dev *pdev)
5192{
5193 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005194 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07005195 u32 err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196
Auke Kokd0e027d2006-04-14 19:04:40 -07005197 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005198 pci_restore_state(pdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005199 if ((err = pci_enable_device(pdev))) {
5200 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5201 return err;
5202 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005203 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204
Auke Kokd0e027d2006-04-14 19:04:40 -07005205 pci_enable_wake(pdev, PCI_D3hot, 0);
5206 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207
Auke Kokedd106f2006-11-06 08:57:12 -08005208 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
5209 return err;
5210
5211 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 e1000_reset(adapter);
5213 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5214
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005215 e1000_init_manageability(adapter);
5216
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005217 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 e1000_up(adapter);
5219
5220 netif_device_attach(netdev);
5221
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005222 /* If the controller is 82573 and f/w is AMT, do not set
5223 * DRV_LOAD until the interface is up. For all other cases,
5224 * let the f/w know that the h/w is now under the control
5225 * of the driver. */
5226 if (adapter->hw.mac_type != e1000_82573 ||
5227 !e1000_check_mng_mode(&adapter->hw))
5228 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005229
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230 return 0;
5231}
5232#endif
Auke Kokc653e632006-05-23 13:35:57 -07005233
5234static void e1000_shutdown(struct pci_dev *pdev)
5235{
5236 e1000_suspend(pdev, PMSG_SUSPEND);
5237}
5238
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239#ifdef CONFIG_NET_POLL_CONTROLLER
5240/*
5241 * Polling 'interrupt' - used by things like netconsole to send skbs
5242 * without having to re-enable interrupts. It's not called while
5243 * the interrupt routine is executing.
5244 */
5245static void
Malli Chilakala26483452005-04-28 19:44:46 -07005246e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005248 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005249
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005251 e1000_intr(adapter->pdev->irq, netdev);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08005252#ifndef CONFIG_E1000_NAPI
5253 adapter->clean_rx(adapter, adapter->rx_ring);
5254#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255 enable_irq(adapter->pdev->irq);
5256}
5257#endif
5258
Auke Kok90267292006-06-08 09:30:24 -07005259/**
5260 * e1000_io_error_detected - called when PCI error is detected
5261 * @pdev: Pointer to PCI device
5262 * @state: The current pci conneection state
5263 *
5264 * This function is called after a PCI bus error affecting
5265 * this device has been detected.
5266 */
5267static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5268{
5269 struct net_device *netdev = pci_get_drvdata(pdev);
5270 struct e1000_adapter *adapter = netdev->priv;
5271
5272 netif_device_detach(netdev);
5273
5274 if (netif_running(netdev))
5275 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005276 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005277
5278 /* Request a slot slot reset. */
5279 return PCI_ERS_RESULT_NEED_RESET;
5280}
5281
5282/**
5283 * e1000_io_slot_reset - called after the pci bus has been reset.
5284 * @pdev: Pointer to PCI device
5285 *
5286 * Restart the card from scratch, as if from a cold-boot. Implementation
5287 * resembles the first-half of the e1000_resume routine.
5288 */
5289static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5290{
5291 struct net_device *netdev = pci_get_drvdata(pdev);
5292 struct e1000_adapter *adapter = netdev->priv;
5293
5294 if (pci_enable_device(pdev)) {
5295 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5296 return PCI_ERS_RESULT_DISCONNECT;
5297 }
5298 pci_set_master(pdev);
5299
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005300 pci_enable_wake(pdev, PCI_D3hot, 0);
5301 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005302
Auke Kok90267292006-06-08 09:30:24 -07005303 e1000_reset(adapter);
5304 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5305
5306 return PCI_ERS_RESULT_RECOVERED;
5307}
5308
5309/**
5310 * e1000_io_resume - called when traffic can start flowing again.
5311 * @pdev: Pointer to PCI device
5312 *
5313 * This callback is called when the error recovery driver tells us that
5314 * its OK to resume normal operation. Implementation resembles the
5315 * second-half of the e1000_resume routine.
5316 */
5317static void e1000_io_resume(struct pci_dev *pdev)
5318{
5319 struct net_device *netdev = pci_get_drvdata(pdev);
5320 struct e1000_adapter *adapter = netdev->priv;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005321
5322 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005323
5324 if (netif_running(netdev)) {
5325 if (e1000_up(adapter)) {
5326 printk("e1000: can't bring device back up after reset\n");
5327 return;
5328 }
5329 }
5330
5331 netif_device_attach(netdev);
5332
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005333 /* If the controller is 82573 and f/w is AMT, do not set
5334 * DRV_LOAD until the interface is up. For all other cases,
5335 * let the f/w know that the h/w is now under the control
5336 * of the driver. */
5337 if (adapter->hw.mac_type != e1000_82573 ||
5338 !e1000_check_mng_mode(&adapter->hw))
5339 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005340
Auke Kok90267292006-06-08 09:30:24 -07005341}
5342
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343/* e1000_main.c */