blob: 9a20ba39346b95b958284ce1e65d389037a579db [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 Koke619d5232006-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 Chilakala24025e4ec2005-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
Joe Perches64798842008-07-11 15:17:02 -0700235static int __init e1000_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
237 int ret;
238 printk(KERN_INFO "%s - version %s\n",
239 e1000_driver_string, e1000_driver_version);
240
241 printk(KERN_INFO "%s\n", e1000_copyright);
242
Jeff Garzik29917622006-08-19 17:48:59 -0400243 ret = pci_register_driver(&e1000_driver);
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100244 if (copybreak != COPYBREAK_DEFAULT) {
245 if (copybreak == 0)
246 printk(KERN_INFO "e1000: copybreak disabled\n");
247 else
248 printk(KERN_INFO "e1000: copybreak enabled for "
249 "packets <= %u bytes\n", copybreak);
250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return ret;
252}
253
254module_init(e1000_init_module);
255
256/**
257 * e1000_exit_module - Driver Exit Cleanup Routine
258 *
259 * e1000_exit_module is called just before the driver is removed
260 * from memory.
261 **/
262
Joe Perches64798842008-07-11 15:17:02 -0700263static void __exit e1000_exit_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 pci_unregister_driver(&e1000_driver);
266}
267
268module_exit(e1000_exit_module);
269
Auke Kok2db10a02006-06-27 09:06:28 -0700270static int e1000_request_irq(struct e1000_adapter *adapter)
271{
272 struct net_device *netdev = adapter->netdev;
Al Viro3e188262007-12-11 19:49:39 +0000273 irq_handler_t handler = e1000_intr;
Auke Koke94bd232007-05-16 01:49:46 -0700274 int irq_flags = IRQF_SHARED;
275 int err;
Auke Kok2db10a02006-06-27 09:06:28 -0700276
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800277 if (adapter->hw.mac_type >= e1000_82571) {
Auke Koke94bd232007-05-16 01:49:46 -0700278 adapter->have_msi = !pci_enable_msi(adapter->pdev);
279 if (adapter->have_msi) {
Al Viro3e188262007-12-11 19:49:39 +0000280 handler = e1000_intr_msi;
Auke Koke94bd232007-05-16 01:49:46 -0700281 irq_flags = 0;
Auke Kok2db10a02006-06-27 09:06:28 -0700282 }
283 }
Auke Koke94bd232007-05-16 01:49:46 -0700284
285 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
286 netdev);
287 if (err) {
288 if (adapter->have_msi)
289 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700290 DPRINTK(PROBE, ERR,
291 "Unable to allocate interrupt Error: %d\n", err);
Auke Koke94bd232007-05-16 01:49:46 -0700292 }
Auke Kok2db10a02006-06-27 09:06:28 -0700293
294 return err;
295}
296
297static void e1000_free_irq(struct e1000_adapter *adapter)
298{
299 struct net_device *netdev = adapter->netdev;
300
301 free_irq(adapter->pdev->irq, netdev);
302
Auke Kok2db10a02006-06-27 09:06:28 -0700303 if (adapter->have_msi)
304 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700305}
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307/**
308 * e1000_irq_disable - Mask off interrupt generation on the NIC
309 * @adapter: board private structure
310 **/
311
Joe Perches64798842008-07-11 15:17:02 -0700312static void e1000_irq_disable(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
315 E1000_WRITE_FLUSH(&adapter->hw);
316 synchronize_irq(adapter->pdev->irq);
317}
318
319/**
320 * e1000_irq_enable - Enable default interrupt generation settings
321 * @adapter: board private structure
322 **/
323
Joe Perches64798842008-07-11 15:17:02 -0700324static void e1000_irq_enable(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Jesse Brandeburg9150b762008-03-21 11:06:58 -0700326 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
327 E1000_WRITE_FLUSH(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100329
Joe Perches64798842008-07-11 15:17:02 -0700330static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700331{
332 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -0700333 u16 vid = adapter->hw.mng_cookie.vlan_id;
334 u16 old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800335 if (adapter->vlgrp) {
Dan Aloni5c15bde2007-03-02 20:44:51 -0800336 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800337 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700338 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
339 e1000_vlan_rx_add_vid(netdev, vid);
340 adapter->mng_vlan_id = vid;
341 } else
342 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800343
Joe Perches406874a2008-04-03 10:06:32 -0700344 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800345 (vid != old_vid) &&
Dan Aloni5c15bde2007-03-02 20:44:51 -0800346 !vlan_group_get_device(adapter->vlgrp, old_vid))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700347 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800348 } else
349 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700350 }
351}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800352
353/**
354 * e1000_release_hw_control - release control of the h/w to f/w
355 * @adapter: address of board private structure
356 *
357 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
358 * For ASF and Pass Through versions of f/w this means that the
359 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800360 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700361 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800362 **/
363
Joe Perches64798842008-07-11 15:17:02 -0700364static void e1000_release_hw_control(struct e1000_adapter *adapter)
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800365{
Joe Perches406874a2008-04-03 10:06:32 -0700366 u32 ctrl_ext;
367 u32 swsm;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800368
369 /* Let firmware taken over control of h/w */
370 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800371 case e1000_82573:
372 swsm = E1000_READ_REG(&adapter->hw, SWSM);
373 E1000_WRITE_REG(&adapter->hw, SWSM,
374 swsm & ~E1000_SWSM_DRV_LOAD);
Bruce Allan31d76442007-03-06 08:57:24 -0800375 break;
376 case e1000_82571:
377 case e1000_82572:
378 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700379 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800380 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
Auke Kokcd94dd02006-06-27 09:08:22 -0700381 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
Bruce Allan31d76442007-03-06 08:57:24 -0800382 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700383 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800384 default:
385 break;
386 }
387}
388
389/**
390 * e1000_get_hw_control - get control of the h/w from f/w
391 * @adapter: address of board private structure
392 *
393 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700394 * For ASF and Pass Through versions of f/w this means that
395 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800396 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700397 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800398 **/
399
Joe Perches64798842008-07-11 15:17:02 -0700400static void e1000_get_hw_control(struct e1000_adapter *adapter)
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800401{
Joe Perches406874a2008-04-03 10:06:32 -0700402 u32 ctrl_ext;
403 u32 swsm;
Auke Kok90fb5132006-11-01 08:47:30 -0800404
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800405 /* Let firmware know the driver has taken over */
406 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800407 case e1000_82573:
408 swsm = E1000_READ_REG(&adapter->hw, SWSM);
409 E1000_WRITE_REG(&adapter->hw, SWSM,
410 swsm | E1000_SWSM_DRV_LOAD);
411 break;
Bruce Allan31d76442007-03-06 08:57:24 -0800412 case e1000_82571:
413 case e1000_82572:
414 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700415 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800416 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
417 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
418 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700419 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800420 default:
421 break;
422 }
423}
424
Joe Perches64798842008-07-11 15:17:02 -0700425static void e1000_init_manageability(struct e1000_adapter *adapter)
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500426{
427 if (adapter->en_mng_pt) {
Joe Perches406874a2008-04-03 10:06:32 -0700428 u32 manc = E1000_READ_REG(&adapter->hw, MANC);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500429
430 /* disable hardware interception of ARP */
431 manc &= ~(E1000_MANC_ARP_EN);
432
433 /* enable receiving management packets to the host */
434 /* this will probably generate destination unreachable messages
435 * from the host OS, but the packets will be handled on SMBUS */
436 if (adapter->hw.has_manc2h) {
Joe Perches406874a2008-04-03 10:06:32 -0700437 u32 manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500438
439 manc |= E1000_MANC_EN_MNG2HOST;
440#define E1000_MNG2HOST_PORT_623 (1 << 5)
441#define E1000_MNG2HOST_PORT_664 (1 << 6)
442 manc2h |= E1000_MNG2HOST_PORT_623;
443 manc2h |= E1000_MNG2HOST_PORT_664;
444 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
445 }
446
447 E1000_WRITE_REG(&adapter->hw, MANC, manc);
448 }
449}
450
Joe Perches64798842008-07-11 15:17:02 -0700451static void e1000_release_manageability(struct e1000_adapter *adapter)
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500452{
453 if (adapter->en_mng_pt) {
Joe Perches406874a2008-04-03 10:06:32 -0700454 u32 manc = E1000_READ_REG(&adapter->hw, MANC);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500455
456 /* re-enable hardware interception of ARP */
457 manc |= E1000_MANC_ARP_EN;
458
459 if (adapter->hw.has_manc2h)
460 manc &= ~E1000_MANC_EN_MNG2HOST;
461
462 /* don't explicitly have to mess with MANC2H since
463 * MANC has an enable disable that gates MANC2H */
464
465 E1000_WRITE_REG(&adapter->hw, MANC, manc);
466 }
467}
468
Auke Koke0aac5a2007-03-06 08:57:21 -0800469/**
470 * e1000_configure - configure the hardware for RX and TX
471 * @adapter = private board structure
472 **/
473static void e1000_configure(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
475 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700476 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Patrick McHardydb0ce502007-11-13 20:54:59 -0800478 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 e1000_restore_vlan(adapter);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500481 e1000_init_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 e1000_configure_tx(adapter);
484 e1000_setup_rctl(adapter);
485 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800486 /* call E1000_DESC_UNUSED which always leaves
487 * at least 1 descriptor unused to make sure
488 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800489 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800490 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800491 adapter->alloc_rx_buf(adapter, ring,
492 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800495 adapter->tx_queue_len = netdev->tx_queue_len;
Auke Koke0aac5a2007-03-06 08:57:21 -0800496}
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800497
Auke Koke0aac5a2007-03-06 08:57:21 -0800498int e1000_up(struct e1000_adapter *adapter)
499{
500 /* hardware has been reset, we need to reload some things */
501 e1000_configure(adapter);
Malli Chilakala5de55622005-04-28 19:39:30 -0700502
Auke Kok1314bbf2006-09-27 12:54:02 -0700503 clear_bit(__E1000_DOWN, &adapter->flags);
504
Auke Koke0aac5a2007-03-06 08:57:21 -0800505#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700506 napi_enable(&adapter->napi);
Auke Koke0aac5a2007-03-06 08:57:21 -0800507#endif
508 e1000_irq_enable(adapter);
509
Jesse Brandeburg79f3d392006-12-15 10:42:34 +0100510 /* fire a link change interrupt to start the watchdog */
511 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 return 0;
513}
514
Auke Kok79f05bf2006-06-27 09:06:32 -0700515/**
516 * e1000_power_up_phy - restore link in case the phy was powered down
517 * @adapter: address of board private structure
518 *
519 * The phy may be powered down to save power and turn off link when the
520 * driver is unloaded and wake on lan is not enabled (among others)
521 * *** this routine MUST be followed by a call to e1000_reset ***
522 *
523 **/
524
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700525void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700526{
Joe Perches406874a2008-04-03 10:06:32 -0700527 u16 mii_reg = 0;
Auke Kok79f05bf2006-06-27 09:06:32 -0700528
529 /* Just clear the power down bit to wake the phy back up */
530 if (adapter->hw.media_type == e1000_media_type_copper) {
531 /* according to the manual, the phy will retain its
532 * settings across a power-down/up cycle */
533 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
534 mii_reg &= ~MII_CR_POWER_DOWN;
535 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
536 }
537}
538
539static void e1000_power_down_phy(struct e1000_adapter *adapter)
540{
Bruce Allan61c25052006-09-27 12:53:54 -0700541 /* Power down the PHY so no link is implied when interface is down *
Joe Perchesc3033b02008-03-21 11:06:25 -0700542 * The PHY cannot be powered down if any of the following is true *
Auke Kok79f05bf2006-06-27 09:06:32 -0700543 * (a) WoL is enabled
544 * (b) AMT is active
545 * (c) SoL/IDER session is active */
546 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700547 adapter->hw.media_type == e1000_media_type_copper) {
Joe Perches406874a2008-04-03 10:06:32 -0700548 u16 mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700549
550 switch (adapter->hw.mac_type) {
551 case e1000_82540:
552 case e1000_82545:
553 case e1000_82545_rev_3:
554 case e1000_82546:
555 case e1000_82546_rev_3:
556 case e1000_82541:
557 case e1000_82541_rev_2:
558 case e1000_82547:
559 case e1000_82547_rev_2:
560 if (E1000_READ_REG(&adapter->hw, MANC) &
561 E1000_MANC_SMBUS_EN)
562 goto out;
563 break;
564 case e1000_82571:
565 case e1000_82572:
566 case e1000_82573:
567 case e1000_80003es2lan:
568 case e1000_ich8lan:
569 if (e1000_check_mng_mode(&adapter->hw) ||
570 e1000_check_phy_reset_block(&adapter->hw))
571 goto out;
572 break;
573 default:
574 goto out;
575 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700576 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
577 mii_reg |= MII_CR_POWER_DOWN;
578 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
579 mdelay(1);
580 }
Bruce Allan61c25052006-09-27 12:53:54 -0700581out:
582 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700583}
584
Joe Perches64798842008-07-11 15:17:02 -0700585void e1000_down(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586{
587 struct net_device *netdev = adapter->netdev;
588
Auke Kok1314bbf2006-09-27 12:54:02 -0700589 /* signal that we're down so the interrupt handler does not
590 * reschedule our watchdog timer */
591 set_bit(__E1000_DOWN, &adapter->flags);
592
Auke Koke0aac5a2007-03-06 08:57:21 -0800593#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700594 napi_disable(&adapter->napi);
Auke Koke0aac5a2007-03-06 08:57:21 -0800595#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 del_timer_sync(&adapter->tx_fifo_stall_timer);
599 del_timer_sync(&adapter->watchdog_timer);
600 del_timer_sync(&adapter->phy_info_timer);
601
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800602 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 adapter->link_speed = 0;
604 adapter->link_duplex = 0;
605 netif_carrier_off(netdev);
606 netif_stop_queue(netdev);
607
608 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400609 e1000_clean_all_tx_rings(adapter);
610 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Joe Perches64798842008-07-11 15:17:02 -0700613void e1000_reinit_locked(struct e1000_adapter *adapter)
Auke Kok2db10a02006-06-27 09:06:28 -0700614{
615 WARN_ON(in_interrupt());
616 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
617 msleep(1);
618 e1000_down(adapter);
619 e1000_up(adapter);
620 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
622
Joe Perches64798842008-07-11 15:17:02 -0700623void e1000_reset(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
Joe Perches406874a2008-04-03 10:06:32 -0700625 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
626 u16 fc_high_water_mark = E1000_FC_HIGH_DIFF;
Joe Perchesc3033b02008-03-21 11:06:25 -0700627 bool legacy_pba_adjust = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 /* Repartition Pba for greater than 9k mtu
630 * To take effect CTRL.RST is required.
631 */
632
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700633 switch (adapter->hw.mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100634 case e1000_82542_rev2_0:
635 case e1000_82542_rev2_1:
636 case e1000_82543:
637 case e1000_82544:
638 case e1000_82540:
639 case e1000_82541:
640 case e1000_82541_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700641 legacy_pba_adjust = true;
Bruce Allan018ea442006-12-15 10:39:45 +0100642 pba = E1000_PBA_48K;
643 break;
644 case e1000_82545:
645 case e1000_82545_rev_3:
646 case e1000_82546:
647 case e1000_82546_rev_3:
648 pba = E1000_PBA_48K;
649 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700650 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700651 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700652 legacy_pba_adjust = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700653 pba = E1000_PBA_30K;
654 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400655 case e1000_82571:
656 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800657 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400658 pba = E1000_PBA_38K;
659 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700660 case e1000_82573:
Bruce Allan018ea442006-12-15 10:39:45 +0100661 pba = E1000_PBA_20K;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700662 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700663 case e1000_ich8lan:
664 pba = E1000_PBA_8K;
Bruce Allan018ea442006-12-15 10:39:45 +0100665 case e1000_undefined:
666 case e1000_num_macs:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700667 break;
668 }
669
Joe Perchesc3033b02008-03-21 11:06:25 -0700670 if (legacy_pba_adjust) {
Bruce Allan018ea442006-12-15 10:39:45 +0100671 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
672 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700673
Bruce Allan018ea442006-12-15 10:39:45 +0100674 if (adapter->hw.mac_type == e1000_82547) {
675 adapter->tx_fifo_head = 0;
676 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
677 adapter->tx_fifo_size =
678 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
679 atomic_set(&adapter->tx_fifo_stall, 0);
680 }
681 } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
682 /* adjust PBA for jumbo frames */
683 E1000_WRITE_REG(&adapter->hw, PBA, pba);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700684
Bruce Allan018ea442006-12-15 10:39:45 +0100685 /* To maintain wire speed transmits, the Tx FIFO should be
686 * large enough to accomodate two full transmit packets,
687 * rounded up to the next 1KB and expressed in KB. Likewise,
688 * the Rx FIFO should be large enough to accomodate at least
689 * one full receive packet and is similarly rounded up and
690 * expressed in KB. */
691 pba = E1000_READ_REG(&adapter->hw, PBA);
692 /* upper 16 bits has Tx packet buffer allocation size in KB */
693 tx_space = pba >> 16;
694 /* lower 16 bits has Rx packet buffer allocation size in KB */
695 pba &= 0xffff;
696 /* don't include ethernet FCS because hardware appends/strips */
697 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
698 VLAN_TAG_SIZE;
699 min_tx_space = min_rx_space;
700 min_tx_space *= 2;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700701 min_tx_space = ALIGN(min_tx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100702 min_tx_space >>= 10;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700703 min_rx_space = ALIGN(min_rx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100704 min_rx_space >>= 10;
705
706 /* If current Tx allocation is less than the min Tx FIFO size,
707 * and the min Tx FIFO size is less than the current Rx FIFO
708 * allocation, take space away from current Rx allocation */
709 if (tx_space < min_tx_space &&
710 ((min_tx_space - tx_space) < pba)) {
711 pba = pba - (min_tx_space - tx_space);
712
713 /* PCI/PCIx hardware has PBA alignment constraints */
714 switch (adapter->hw.mac_type) {
715 case e1000_82545 ... e1000_82546_rev_3:
716 pba &= ~(E1000_PBA_8K - 1);
717 break;
718 default:
719 break;
720 }
721
722 /* if short on rx space, rx wins and must trump tx
723 * adjustment or use Early Receive if available */
724 if (pba < min_rx_space) {
725 switch (adapter->hw.mac_type) {
726 case e1000_82573:
727 /* ERT enabled in e1000_configure_rx */
728 break;
729 default:
730 pba = min_rx_space;
731 break;
732 }
733 }
734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 E1000_WRITE_REG(&adapter->hw, PBA, pba);
738
739 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800740 /* Set the FC high water mark to 90% of the FIFO size.
741 * Required to clear last 3 LSB */
742 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700743 /* We can't use 90% on small FIFOs because the remainder
744 * would be less than 1 full frame. In this case, we size
745 * it to allow at least a full frame above the high water
746 * mark. */
747 if (pba < E1000_PBA_16K)
748 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800749
750 adapter->hw.fc_high_water = fc_high_water_mark;
751 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800752 if (adapter->hw.mac_type == e1000_80003es2lan)
753 adapter->hw.fc_pause_time = 0xFFFF;
754 else
755 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 adapter->hw.fc_send_xon = 1;
757 adapter->hw.fc = adapter->hw.original_fc;
758
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700759 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800761 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700763
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800764 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700766 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100767
768 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
769 if (adapter->hw.mac_type >= e1000_82544 &&
770 adapter->hw.mac_type <= e1000_82547_rev_2 &&
771 adapter->hw.autoneg == 1 &&
772 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
Joe Perches406874a2008-04-03 10:06:32 -0700773 u32 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100774 /* clear phy power management bit if we are in gig only mode,
775 * which if enabled will attempt negotiation to 100Mb, which
776 * can cause a loss of link at power off or driver unload */
777 ctrl &= ~E1000_CTRL_SWDPIN3;
778 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
779 }
780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
782 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
783
784 e1000_reset_adaptive(&adapter->hw);
785 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700786
787 if (!adapter->smart_power_down &&
788 (adapter->hw.mac_type == e1000_82571 ||
789 adapter->hw.mac_type == e1000_82572)) {
Joe Perches406874a2008-04-03 10:06:32 -0700790 u16 phy_data = 0;
Auke Kok9a53a202006-06-27 09:06:45 -0700791 /* speed up time to link by disabling smart power down, ignore
792 * the return value of this function because there is nothing
793 * different we would do if it failed */
794 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
795 &phy_data);
796 phy_data &= ~IGP02E1000_PM_SPD;
797 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
798 phy_data);
799 }
800
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500801 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802}
803
804/**
Auke Kok67b3c272007-12-17 13:50:23 -0800805 * Dump the eeprom for users having checksum issues
806 **/
Adrian Bunkb4ea8952008-02-01 08:21:28 -0800807static void e1000_dump_eeprom(struct e1000_adapter *adapter)
Auke Kok67b3c272007-12-17 13:50:23 -0800808{
809 struct net_device *netdev = adapter->netdev;
810 struct ethtool_eeprom eeprom;
811 const struct ethtool_ops *ops = netdev->ethtool_ops;
812 u8 *data;
813 int i;
814 u16 csum_old, csum_new = 0;
815
816 eeprom.len = ops->get_eeprom_len(netdev);
817 eeprom.offset = 0;
818
819 data = kmalloc(eeprom.len, GFP_KERNEL);
820 if (!data) {
821 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
822 " data\n");
823 return;
824 }
825
826 ops->get_eeprom(netdev, &eeprom, data);
827
828 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
829 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
830 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
831 csum_new += data[i] + (data[i + 1] << 8);
832 csum_new = EEPROM_SUM - csum_new;
833
834 printk(KERN_ERR "/*********************/\n");
835 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
836 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
837
838 printk(KERN_ERR "Offset Values\n");
839 printk(KERN_ERR "======== ======\n");
840 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
841
842 printk(KERN_ERR "Include this output when contacting your support "
843 "provider.\n");
844 printk(KERN_ERR "This is not a software error! Something bad "
845 "happened to your hardware or\n");
846 printk(KERN_ERR "EEPROM image. Ignoring this "
847 "problem could result in further problems,\n");
848 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
849 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
850 "which is invalid\n");
851 printk(KERN_ERR "and requires you to set the proper MAC "
852 "address manually before continuing\n");
853 printk(KERN_ERR "to enable this network device.\n");
854 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
855 "to your hardware vendor\n");
856 printk(KERN_ERR "or Intel Customer Support: linux-nics@intel.com\n");
857 printk(KERN_ERR "/*********************/\n");
858
859 kfree(data);
860}
861
862/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 * e1000_probe - Device Initialization Routine
864 * @pdev: PCI device information struct
865 * @ent: entry in e1000_pci_tbl
866 *
867 * Returns 0 on success, negative on failure
868 *
869 * e1000_probe initializes an adapter identified by a pci_dev structure.
870 * The OS initialization, configuring of the adapter private structure,
871 * and a hardware reset occur.
872 **/
873
874static int __devinit
875e1000_probe(struct pci_dev *pdev,
876 const struct pci_device_id *ent)
877{
878 struct net_device *netdev;
879 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700882 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700883 int i, err, pci_using_dac;
Joe Perches406874a2008-04-03 10:06:32 -0700884 u16 eeprom_data = 0;
885 u16 eeprom_apme_mask = E1000_EEPROM_APME;
Joe Perches0795af52007-10-03 17:59:30 -0700886 DECLARE_MAC_BUF(mac);
887
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800888 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 return err;
890
Auke Kokcd94dd02006-06-27 09:08:22 -0700891 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
892 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 pci_using_dac = 1;
894 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700895 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
896 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700898 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 }
900 pci_using_dac = 0;
901 }
902
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800903 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700904 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
906 pci_set_master(pdev);
907
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700908 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700910 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 SET_NETDEV_DEV(netdev, &pdev->dev);
914
915 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700916 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 adapter->netdev = netdev;
918 adapter->pdev = pdev;
919 adapter->hw.back = adapter;
920 adapter->msg_enable = (1 << debug) - 1;
921
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700922 err = -EIO;
Benjamin Herrenschmidt3c34ac32007-11-16 18:37:38 +1100923 adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
924 pci_resource_len(pdev, BAR_0));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700925 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800928 for (i = BAR_1; i <= BAR_5; i++) {
929 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800931 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 adapter->hw.io_base = pci_resource_start(pdev, i);
933 break;
934 }
935 }
936
937 netdev->open = &e1000_open;
938 netdev->stop = &e1000_close;
939 netdev->hard_start_xmit = &e1000_xmit_frame;
940 netdev->get_stats = &e1000_get_stats;
Patrick McHardydb0ce502007-11-13 20:54:59 -0800941 netdev->set_rx_mode = &e1000_set_rx_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 netdev->set_mac_address = &e1000_set_mac;
943 netdev->change_mtu = &e1000_change_mtu;
944 netdev->do_ioctl = &e1000_ioctl;
945 e1000_set_ethtool_ops(netdev);
946 netdev->tx_timeout = &e1000_tx_timeout;
947 netdev->watchdog_timeo = 5 * HZ;
948#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700949 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950#endif
951 netdev->vlan_rx_register = e1000_vlan_rx_register;
952 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
953 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
954#ifdef CONFIG_NET_POLL_CONTROLLER
955 netdev->poll_controller = e1000_netpoll;
956#endif
Auke Kok0eb5a342006-09-27 12:53:17 -0700957 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 adapter->bd_number = cards_found;
960
961 /* setup the private structure */
962
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800963 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 goto err_sw_init;
965
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700966 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -0700967 /* Flash BAR mapping must happen after e1000_sw_init
968 * because it depends on mac_type */
969 if ((adapter->hw.mac_type == e1000_ich8lan) &&
970 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
Benjamin Herrenschmidt3c34ac32007-11-16 18:37:38 +1100971 adapter->hw.flash_address =
972 ioremap(pci_resource_start(pdev, 1),
973 pci_resource_len(pdev, 1));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700974 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -0700975 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -0700976 }
977
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700978 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700979 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
980
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800981 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 netdev->features = NETIF_F_SG |
983 NETIF_F_HW_CSUM |
984 NETIF_F_HW_VLAN_TX |
985 NETIF_F_HW_VLAN_RX |
986 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -0700987 if (adapter->hw.mac_type == e1000_ich8lan)
988 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 }
990
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800991 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 (adapter->hw.mac_type != e1000_82547))
993 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700994
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800995 if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -0800996 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800997 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 netdev->features |= NETIF_F_HIGHDMA;
999
Auke Kok76c224b2006-05-23 13:36:06 -07001000 netdev->features |= NETIF_F_LLTX;
1001
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001002 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
1003
Auke Kokcd94dd02006-06-27 09:08:22 -07001004 /* initialize eeprom parameters */
Auke Kokcd94dd02006-06-27 09:08:22 -07001005 if (e1000_init_eeprom_params(&adapter->hw)) {
1006 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001007 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001008 }
1009
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001010 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 e1000_reset_hw(&adapter->hw);
1014
1015 /* make sure the EEPROM is good */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001016 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Auke Kok67b3c272007-12-17 13:50:23 -08001018 e1000_dump_eeprom(adapter);
1019 /*
1020 * set MAC address to all zeroes to invalidate and temporary
1021 * disable this device for the user. This blocks regular
1022 * traffic while still permitting ethtool ioctls from reaching
1023 * the hardware as well as allowing the user to run the
1024 * interface after manually setting a hw addr using
1025 * `ip set address`
1026 */
1027 memset(adapter->hw.mac_addr, 0, netdev->addr_len);
1028 } else {
1029 /* copy the MAC address out of the EEPROM */
1030 if (e1000_read_mac_addr(&adapter->hw))
1031 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 }
Auke Kok67b3c272007-12-17 13:50:23 -08001033 /* don't block initalization here due to bad MAC address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -04001035 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Auke Kok67b3c272007-12-17 13:50:23 -08001037 if (!is_valid_ether_addr(netdev->perm_addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 e1000_get_bus_info(&adapter->hw);
1041
1042 init_timer(&adapter->tx_fifo_stall_timer);
1043 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1044 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
1045
1046 init_timer(&adapter->watchdog_timer);
1047 adapter->watchdog_timer.function = &e1000_watchdog;
1048 adapter->watchdog_timer.data = (unsigned long) adapter;
1049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 init_timer(&adapter->phy_info_timer);
1051 adapter->phy_info_timer.function = &e1000_update_phy_info;
1052 adapter->phy_info_timer.data = (unsigned long) adapter;
1053
David Howells65f27f32006-11-22 14:55:48 +00001054 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 e1000_check_options(adapter);
1057
1058 /* Initial Wake on LAN setting
1059 * If APM wake is enabled in the EEPROM,
1060 * enable the ACPI Magic Packet filter
1061 */
1062
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001063 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 case e1000_82542_rev2_0:
1065 case e1000_82542_rev2_1:
1066 case e1000_82543:
1067 break;
1068 case e1000_82544:
1069 e1000_read_eeprom(&adapter->hw,
1070 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1071 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1072 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001073 case e1000_ich8lan:
1074 e1000_read_eeprom(&adapter->hw,
1075 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1076 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1077 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 case e1000_82546:
1079 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001080 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001081 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001082 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 e1000_read_eeprom(&adapter->hw,
1084 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1085 break;
1086 }
1087 /* Fall Through */
1088 default:
1089 e1000_read_eeprom(&adapter->hw,
1090 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1091 break;
1092 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001093 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001094 adapter->eeprom_wol |= E1000_WUFC_MAG;
1095
1096 /* now that we have the eeprom settings, apply the special cases
1097 * where the eeprom may be wrong or the board simply won't support
1098 * wake on lan on a particular port */
1099 switch (pdev->device) {
1100 case E1000_DEV_ID_82546GB_PCIE:
1101 adapter->eeprom_wol = 0;
1102 break;
1103 case E1000_DEV_ID_82546EB_FIBER:
1104 case E1000_DEV_ID_82546GB_FIBER:
1105 case E1000_DEV_ID_82571EB_FIBER:
1106 /* Wake events only supported on port A for dual fiber
1107 * regardless of eeprom setting */
1108 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
1109 adapter->eeprom_wol = 0;
1110 break;
1111 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001112 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001113 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001114 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001115 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001116 /* if quad port adapter, disable WoL on all but port A */
1117 if (global_quad_port_a != 0)
1118 adapter->eeprom_wol = 0;
1119 else
1120 adapter->quad_port_a = 1;
1121 /* Reset for multiple quad port adapters */
1122 if (++global_quad_port_a == 4)
1123 global_quad_port_a = 0;
1124 break;
1125 }
1126
1127 /* initialize the wol settings based on the eeprom settings */
1128 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001130 /* print bus type/speed/width info */
1131 {
1132 struct e1000_hw *hw = &adapter->hw;
1133 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1134 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1135 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1136 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1137 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1138 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1139 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1140 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1141 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1142 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1143 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1144 "32-bit"));
1145 }
1146
Joe Perches0795af52007-10-03 17:59:30 -07001147 printk("%s\n", print_mac(mac, netdev->dev_addr));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001148
Auke Kok14782ca2008-02-11 09:25:46 -08001149 if (adapter->hw.bus_type == e1000_bus_type_pci_express) {
1150 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1151 "longer be supported by this driver in the future.\n",
1152 pdev->vendor, pdev->device);
1153 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1154 "driver instead.\n");
1155 }
1156
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 /* reset the hardware with the new settings */
1158 e1000_reset(adapter);
1159
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001160 /* If the controller is 82573 and f/w is AMT, do not set
1161 * DRV_LOAD until the interface is up. For all other cases,
1162 * let the f/w know that the h/w is now under the control
1163 * of the driver. */
1164 if (adapter->hw.mac_type != e1000_82573 ||
1165 !e1000_check_mng_mode(&adapter->hw))
1166 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001167
Auke Kok1314bbf2006-09-27 12:54:02 -07001168 /* tell the stack to leave us alone until e1000_open() is called */
1169 netif_carrier_off(netdev);
1170 netif_stop_queue(netdev);
Auke Kok416b5d12007-06-01 10:22:39 -07001171
1172 strcpy(netdev->name, "eth%d");
1173 if ((err = register_netdev(netdev)))
1174 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001175
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1177
1178 cards_found++;
1179 return 0;
1180
1181err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001182 e1000_release_hw_control(adapter);
1183err_eeprom:
1184 if (!e1000_check_phy_reset_block(&adapter->hw))
1185 e1000_phy_hw_reset(&adapter->hw);
1186
Auke Kokcd94dd02006-06-27 09:08:22 -07001187 if (adapter->hw.flash_address)
1188 iounmap(adapter->hw.flash_address);
1189err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001190#ifdef CONFIG_E1000_NAPI
1191 for (i = 0; i < adapter->num_rx_queues; i++)
1192 dev_put(&adapter->polling_netdev[i]);
1193#endif
1194
1195 kfree(adapter->tx_ring);
1196 kfree(adapter->rx_ring);
1197#ifdef CONFIG_E1000_NAPI
1198 kfree(adapter->polling_netdev);
1199#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 iounmap(adapter->hw.hw_addr);
1202err_ioremap:
1203 free_netdev(netdev);
1204err_alloc_etherdev:
1205 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001206err_pci_reg:
1207err_dma:
1208 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 return err;
1210}
1211
1212/**
1213 * e1000_remove - Device Removal Routine
1214 * @pdev: PCI device information struct
1215 *
1216 * e1000_remove is called by the PCI subsystem to alert the driver
1217 * that it should release a PCI device. The could be caused by a
1218 * Hot-Plug event, or because the driver is going to be removed from
1219 * memory.
1220 **/
1221
Joe Perches64798842008-07-11 15:17:02 -07001222static void __devexit e1000_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
1224 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001225 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001226#ifdef CONFIG_E1000_NAPI
1227 int i;
1228#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Oleg Nesterov28e53bd2007-05-09 02:34:22 -07001230 cancel_work_sync(&adapter->reset_task);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001231
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001232 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001234 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1235 * would have already happened in close and is redundant. */
1236 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001237
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001238#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001239 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001240 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001241#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001243 unregister_netdev(netdev);
1244
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001245 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001246 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001248 kfree(adapter->tx_ring);
1249 kfree(adapter->rx_ring);
1250#ifdef CONFIG_E1000_NAPI
1251 kfree(adapter->polling_netdev);
1252#endif
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001255 if (adapter->hw.flash_address)
1256 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 pci_release_regions(pdev);
1258
1259 free_netdev(netdev);
1260
1261 pci_disable_device(pdev);
1262}
1263
1264/**
1265 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1266 * @adapter: board private structure to initialize
1267 *
1268 * e1000_sw_init initializes the Adapter private data structure.
1269 * Fields are initialized based on PCI device information and
1270 * OS network device settings (MTU size).
1271 **/
1272
Joe Perches64798842008-07-11 15:17:02 -07001273static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274{
1275 struct e1000_hw *hw = &adapter->hw;
1276 struct net_device *netdev = adapter->netdev;
1277 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001278#ifdef CONFIG_E1000_NAPI
1279 int i;
1280#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 /* PCI config space info */
1283
1284 hw->vendor_id = pdev->vendor;
1285 hw->device_id = pdev->device;
1286 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1287 hw->subsystem_id = pdev->subsystem_device;
Auke Kok44c10132007-06-08 15:46:36 -07001288 hw->revision_id = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
1290 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1291
Auke Kokeb0f8052006-07-14 16:14:48 -07001292 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001293 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 hw->max_frame_size = netdev->mtu +
1295 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1296 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1297
1298 /* identify the MAC */
1299
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001300 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1302 return -EIO;
1303 }
1304
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001305 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 default:
1307 break;
1308 case e1000_82541:
1309 case e1000_82547:
1310 case e1000_82541_rev_2:
1311 case e1000_82547_rev_2:
1312 hw->phy_init_script = 1;
1313 break;
1314 }
1315
1316 e1000_set_media_type(hw);
1317
Joe Perchesc3033b02008-03-21 11:06:25 -07001318 hw->wait_autoneg_complete = false;
1319 hw->tbi_compatibility_en = true;
1320 hw->adaptive_ifs = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 /* Copper options */
1323
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001324 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 hw->mdix = AUTO_ALL_MODES;
Joe Perchesc3033b02008-03-21 11:06:25 -07001326 hw->disable_polarity_correction = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 hw->master_slave = E1000_MASTER_SLAVE;
1328 }
1329
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001330 adapter->num_tx_queues = 1;
1331 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001332
1333 if (e1000_alloc_queues(adapter)) {
1334 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1335 return -ENOMEM;
1336 }
1337
1338#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001339 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001340 adapter->polling_netdev[i].priv = adapter;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001341 dev_hold(&adapter->polling_netdev[i]);
1342 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1343 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001344 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001345#endif
1346
Herbert Xu47313052007-05-29 15:07:31 -07001347 /* Explicitly disable IRQ since the NIC can be in any state. */
Herbert Xu47313052007-05-29 15:07:31 -07001348 e1000_irq_disable(adapter);
1349
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Auke Kok1314bbf2006-09-27 12:54:02 -07001352 set_bit(__E1000_DOWN, &adapter->flags);
1353
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 return 0;
1355}
1356
1357/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001358 * e1000_alloc_queues - Allocate memory for all rings
1359 * @adapter: board private structure to initialize
1360 *
1361 * We allocate one ring per queue at run-time since we don't know the
1362 * number of queues at compile-time. The polling_netdev array is
1363 * intended for Multiqueue, but should work fine with a single queue.
1364 **/
1365
Joe Perches64798842008-07-11 15:17:02 -07001366static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001367{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001368 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1369 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001370 if (!adapter->tx_ring)
1371 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001372
Yan Burman1c7e5b12007-03-06 08:58:04 -08001373 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1374 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001375 if (!adapter->rx_ring) {
1376 kfree(adapter->tx_ring);
1377 return -ENOMEM;
1378 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001379
1380#ifdef CONFIG_E1000_NAPI
Yan Burman1c7e5b12007-03-06 08:58:04 -08001381 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1382 sizeof(struct net_device),
1383 GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001384 if (!adapter->polling_netdev) {
1385 kfree(adapter->tx_ring);
1386 kfree(adapter->rx_ring);
1387 return -ENOMEM;
1388 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001389#endif
1390
1391 return E1000_SUCCESS;
1392}
1393
1394/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 * e1000_open - Called when a network interface is made active
1396 * @netdev: network interface device structure
1397 *
1398 * Returns 0 on success, negative value on failure
1399 *
1400 * The open entry point is called when a network interface is made
1401 * active by the system (IFF_UP). At this point all resources needed
1402 * for transmit and receive operations are allocated, the interrupt
1403 * handler is registered with the OS, the watchdog timer is started,
1404 * and the stack is notified that the interface is ready.
1405 **/
1406
Joe Perches64798842008-07-11 15:17:02 -07001407static int e1000_open(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001409 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 int err;
1411
Auke Kok2db10a02006-06-27 09:06:28 -07001412 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001413 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001414 return -EBUSY;
1415
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001417 err = e1000_setup_all_tx_resources(adapter);
1418 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 goto err_setup_tx;
1420
1421 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001422 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001423 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001424 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001425
Auke Kok79f05bf2006-06-27 09:06:32 -07001426 e1000_power_up_phy(adapter);
1427
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001428 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001429 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001430 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1431 e1000_update_mng_vlan(adapter);
1432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001434 /* If AMT is enabled, let the firmware know that the network
1435 * interface is now open */
1436 if (adapter->hw.mac_type == e1000_82573 &&
1437 e1000_check_mng_mode(&adapter->hw))
1438 e1000_get_hw_control(adapter);
1439
Auke Koke0aac5a2007-03-06 08:57:21 -08001440 /* before we allocate an interrupt, we must be ready to handle it.
1441 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1442 * as soon as we call pci_request_irq, so we have to setup our
1443 * clean_rx handler before we do so. */
1444 e1000_configure(adapter);
1445
1446 err = e1000_request_irq(adapter);
1447 if (err)
1448 goto err_req_irq;
1449
1450 /* From here on the code is the same as e1000_up() */
1451 clear_bit(__E1000_DOWN, &adapter->flags);
1452
Herbert Xu47313052007-05-29 15:07:31 -07001453#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001454 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001455#endif
1456
Auke Koke0aac5a2007-03-06 08:57:21 -08001457 e1000_irq_enable(adapter);
1458
Ben Hutchings076152d2008-07-18 17:50:57 -07001459 netif_start_queue(netdev);
1460
Auke Koke0aac5a2007-03-06 08:57:21 -08001461 /* fire a link status change interrupt to start the watchdog */
1462 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
1463
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 return E1000_SUCCESS;
1465
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001466err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001467 e1000_release_hw_control(adapter);
1468 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001469 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001471 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472err_setup_tx:
1473 e1000_reset(adapter);
1474
1475 return err;
1476}
1477
1478/**
1479 * e1000_close - Disables a network interface
1480 * @netdev: network interface device structure
1481 *
1482 * Returns 0, this is not allowed to fail
1483 *
1484 * The close entry point is called when an interface is de-activated
1485 * by the OS. The hardware is still under the drivers control, but
1486 * needs to be disabled. A global MAC reset is issued to stop the
1487 * hardware, and all transmit and receive resources are freed.
1488 **/
1489
Joe Perches64798842008-07-11 15:17:02 -07001490static int e1000_close(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001492 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
Auke Kok2db10a02006-06-27 09:06:28 -07001494 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001496 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001497 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001499 e1000_free_all_tx_resources(adapter);
1500 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Bruce Allan46665602006-09-27 12:54:08 -07001502 /* kill manageability vlan ID if supported, but not if a vlan with
1503 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001504 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001505 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1506 !(adapter->vlgrp &&
Dan Aloni5c15bde2007-03-02 20:44:51 -08001507 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001508 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1509 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001510
1511 /* If AMT is enabled, let the firmware know that the network
1512 * interface is now closed */
1513 if (adapter->hw.mac_type == e1000_82573 &&
1514 e1000_check_mng_mode(&adapter->hw))
1515 e1000_release_hw_control(adapter);
1516
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 return 0;
1518}
1519
1520/**
1521 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1522 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001523 * @start: address of beginning of memory
1524 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 **/
Joe Perches64798842008-07-11 15:17:02 -07001526static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1527 unsigned long len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
1529 unsigned long begin = (unsigned long) start;
1530 unsigned long end = begin + len;
1531
Malli Chilakala26483452005-04-28 19:44:46 -07001532 /* First rev 82545 and 82546 need to not allow any memory
1533 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001535 adapter->hw.mac_type == e1000_82546) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001536 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 }
1538
Joe Perchesc3033b02008-03-21 11:06:25 -07001539 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540}
1541
1542/**
1543 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1544 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001545 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 *
1547 * Return 0 on success, negative on failure
1548 **/
1549
Joe Perches64798842008-07-11 15:17:02 -07001550static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1551 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 struct pci_dev *pdev = adapter->pdev;
1554 int size;
1555
1556 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001557 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001558 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001559 DPRINTK(PROBE, ERR,
1560 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 return -ENOMEM;
1562 }
1563 memset(txdr->buffer_info, 0, size);
1564
1565 /* round up to nearest 4K */
1566
1567 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001568 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
1570 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001571 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001574 DPRINTK(PROBE, ERR,
1575 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 return -ENOMEM;
1577 }
1578
Malli Chilakala26483452005-04-28 19:44:46 -07001579 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1581 void *olddesc = txdr->desc;
1582 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001583 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1584 "at %p\n", txdr->size, txdr->desc);
1585 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001587 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001588 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1590 goto setup_tx_desc_die;
1591 }
1592
1593 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1594 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001595 pci_free_consistent(pdev, txdr->size, txdr->desc,
1596 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1598 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001599 "Unable to allocate aligned memory "
1600 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 vfree(txdr->buffer_info);
1602 return -ENOMEM;
1603 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001604 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1606 }
1607 }
1608 memset(txdr->desc, 0, txdr->size);
1609
1610 txdr->next_to_use = 0;
1611 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001612 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
1614 return 0;
1615}
1616
1617/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001618 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1619 * (Descriptors) for all queues
1620 * @adapter: board private structure
1621 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001622 * Return 0 on success, negative on failure
1623 **/
1624
Joe Perches64798842008-07-11 15:17:02 -07001625int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001626{
1627 int i, err = 0;
1628
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001629 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001630 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1631 if (err) {
1632 DPRINTK(PROBE, ERR,
1633 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001634 for (i-- ; i >= 0; i--)
1635 e1000_free_tx_resources(adapter,
1636 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001637 break;
1638 }
1639 }
1640
1641 return err;
1642}
1643
1644/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1646 * @adapter: board private structure
1647 *
1648 * Configure the Tx unit of the MAC after a reset.
1649 **/
1650
Joe Perches64798842008-07-11 15:17:02 -07001651static void e1000_configure_tx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
Joe Perches406874a2008-04-03 10:06:32 -07001653 u64 tdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001654 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001655 u32 tdlen, tctl, tipg, tarc;
1656 u32 ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
1658 /* Setup the HW Tx Head and Tail descriptor pointers */
1659
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001660 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001661 case 1:
1662 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001663 tdba = adapter->tx_ring[0].dma;
1664 tdlen = adapter->tx_ring[0].count *
1665 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001666 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001667 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1668 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001669 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001670 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001671 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1672 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001673 break;
1674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
1676 /* Set the default values for the Tx Inter Packet Gap timer */
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001677 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1678 (hw->media_type == e1000_media_type_fiber ||
1679 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001680 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1681 else
1682 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1683
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001684 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 case e1000_82542_rev2_0:
1686 case e1000_82542_rev2_1:
1687 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001688 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1689 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001691 case e1000_80003es2lan:
1692 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1693 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1694 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001696 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1697 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1698 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001700 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1701 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001702 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
1704 /* Set the Tx Interrupt Delay register */
1705
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001706 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1707 if (hw->mac_type >= e1000_82540)
1708 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 /* Program the Transmit Control Register */
1711
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001712 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001714 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1716
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001717 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1718 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001719 /* set the speed mode bit, we'll clear it if we're not at
1720 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001721 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001722 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001723 } else if (hw->mac_type == e1000_80003es2lan) {
1724 tarc = E1000_READ_REG(hw, TARC0);
1725 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001726 E1000_WRITE_REG(hw, TARC0, tarc);
1727 tarc = E1000_READ_REG(hw, TARC1);
1728 tarc |= 1;
1729 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001730 }
1731
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001732 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001735 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1736
1737 /* only set IDE if we are delaying interrupts using the timers */
1738 if (adapter->tx_int_delay)
1739 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001741 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1743 else
1744 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1745
1746 /* Cache if we're 82544 running in PCI-X because we'll
1747 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001748 if (hw->mac_type == e1000_82544 &&
1749 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001751
1752 E1000_WRITE_REG(hw, TCTL, tctl);
1753
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754}
1755
1756/**
1757 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1758 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001759 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 *
1761 * Returns 0 on success, negative on failure
1762 **/
1763
Joe Perches64798842008-07-11 15:17:02 -07001764static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1765 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001768 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
1770 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001771 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001772 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001773 DPRINTK(PROBE, ERR,
1774 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 return -ENOMEM;
1776 }
1777 memset(rxdr->buffer_info, 0, size);
1778
Yan Burman1c7e5b12007-03-06 08:58:04 -08001779 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1780 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001781 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001782 vfree(rxdr->buffer_info);
1783 DPRINTK(PROBE, ERR,
1784 "Unable to allocate memory for the receive descriptor ring\n");
1785 return -ENOMEM;
1786 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001787
Yan Burman1c7e5b12007-03-06 08:58:04 -08001788 rxdr->ps_page_dma = kcalloc(rxdr->count,
1789 sizeof(struct e1000_ps_page_dma),
1790 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001791 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001792 vfree(rxdr->buffer_info);
1793 kfree(rxdr->ps_page);
1794 DPRINTK(PROBE, ERR,
1795 "Unable to allocate memory for the receive descriptor ring\n");
1796 return -ENOMEM;
1797 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001798
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001799 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001800 desc_len = sizeof(struct e1000_rx_desc);
1801 else
1802 desc_len = sizeof(union e1000_rx_desc_packet_split);
1803
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 /* Round up to nearest 4K */
1805
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001806 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001807 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
1809 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1810
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001811 if (!rxdr->desc) {
1812 DPRINTK(PROBE, ERR,
1813 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001816 kfree(rxdr->ps_page);
1817 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 return -ENOMEM;
1819 }
1820
Malli Chilakala26483452005-04-28 19:44:46 -07001821 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1823 void *olddesc = rxdr->desc;
1824 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001825 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1826 "at %p\n", rxdr->size, rxdr->desc);
1827 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001829 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001830 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001832 DPRINTK(PROBE, ERR,
1833 "Unable to allocate memory "
1834 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 goto setup_rx_desc_die;
1836 }
1837
1838 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1839 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001840 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1841 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001843 DPRINTK(PROBE, ERR,
1844 "Unable to allocate aligned memory "
1845 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001846 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001848 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1850 }
1851 }
1852 memset(rxdr->desc, 0, rxdr->size);
1853
1854 rxdr->next_to_clean = 0;
1855 rxdr->next_to_use = 0;
1856
1857 return 0;
1858}
1859
1860/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001861 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1862 * (Descriptors) for all queues
1863 * @adapter: board private structure
1864 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001865 * Return 0 on success, negative on failure
1866 **/
1867
Joe Perches64798842008-07-11 15:17:02 -07001868int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001869{
1870 int i, err = 0;
1871
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001872 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001873 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1874 if (err) {
1875 DPRINTK(PROBE, ERR,
1876 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001877 for (i-- ; i >= 0; i--)
1878 e1000_free_rx_resources(adapter,
1879 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001880 break;
1881 }
1882 }
1883
1884 return err;
1885}
1886
1887/**
Malli Chilakala26483452005-04-28 19:44:46 -07001888 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 * @adapter: Board private structure
1890 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001891#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1892 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Joe Perches64798842008-07-11 15:17:02 -07001893static void e1000_setup_rctl(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894{
Joe Perches406874a2008-04-03 10:06:32 -07001895 u32 rctl, rfctl;
1896 u32 psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001897#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Joe Perches406874a2008-04-03 10:06:32 -07001898 u32 pages = 0;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001899#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
1901 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1902
1903 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1904
1905 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1906 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1907 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1908
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001909 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 rctl |= E1000_RCTL_SBP;
1911 else
1912 rctl &= ~E1000_RCTL_SBP;
1913
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001914 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1915 rctl &= ~E1000_RCTL_LPE;
1916 else
1917 rctl |= E1000_RCTL_LPE;
1918
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001920 rctl &= ~E1000_RCTL_SZ_4096;
1921 rctl |= E1000_RCTL_BSEX;
1922 switch (adapter->rx_buffer_len) {
1923 case E1000_RXBUFFER_256:
1924 rctl |= E1000_RCTL_SZ_256;
1925 rctl &= ~E1000_RCTL_BSEX;
1926 break;
1927 case E1000_RXBUFFER_512:
1928 rctl |= E1000_RCTL_SZ_512;
1929 rctl &= ~E1000_RCTL_BSEX;
1930 break;
1931 case E1000_RXBUFFER_1024:
1932 rctl |= E1000_RCTL_SZ_1024;
1933 rctl &= ~E1000_RCTL_BSEX;
1934 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001935 case E1000_RXBUFFER_2048:
1936 default:
1937 rctl |= E1000_RCTL_SZ_2048;
1938 rctl &= ~E1000_RCTL_BSEX;
1939 break;
1940 case E1000_RXBUFFER_4096:
1941 rctl |= E1000_RCTL_SZ_4096;
1942 break;
1943 case E1000_RXBUFFER_8192:
1944 rctl |= E1000_RCTL_SZ_8192;
1945 break;
1946 case E1000_RXBUFFER_16384:
1947 rctl |= E1000_RCTL_SZ_16384;
1948 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001949 }
1950
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001951#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001952 /* 82571 and greater support packet-split where the protocol
1953 * header is placed in skb->data and the packet data is
1954 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1955 * In the case of a non-split, skb->data is linearly filled,
1956 * followed by the page buffers. Therefore, skb->data is
1957 * sized to hold the largest protocol header.
1958 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001959 /* allocations using alloc_page take too long for regular MTU
1960 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001961 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001962 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1963 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001964 adapter->rx_ps_pages = pages;
1965 else
1966 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001967#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001968 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001969 /* Configure extra packet-split registers */
1970 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1971 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08001972 /* disable packet split support for IPv6 extension headers,
1973 * because some malformed IPv6 headers can hang the RX */
1974 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1975 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1976
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001977 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1978
Auke Kok7dfee0c2006-06-27 09:07:50 -07001979 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001980
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001981 psrctl |= adapter->rx_ps_bsize0 >>
1982 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001983
1984 switch (adapter->rx_ps_pages) {
1985 case 3:
1986 psrctl |= PAGE_SIZE <<
1987 E1000_PSRCTL_BSIZE3_SHIFT;
1988 case 2:
1989 psrctl |= PAGE_SIZE <<
1990 E1000_PSRCTL_BSIZE2_SHIFT;
1991 case 1:
1992 psrctl |= PAGE_SIZE >>
1993 E1000_PSRCTL_BSIZE1_SHIFT;
1994 break;
1995 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001996
1997 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 }
1999
2000 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2001}
2002
2003/**
2004 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2005 * @adapter: board private structure
2006 *
2007 * Configure the Rx unit of the MAC after a reset.
2008 **/
2009
Joe Perches64798842008-07-11 15:17:02 -07002010static void e1000_configure_rx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011{
Joe Perches406874a2008-04-03 10:06:32 -07002012 u64 rdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002013 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002014 u32 rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002015
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002016 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002017 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002018 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002019 sizeof(union e1000_rx_desc_packet_split);
2020 adapter->clean_rx = e1000_clean_rx_irq_ps;
2021 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2022 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002023 rdlen = adapter->rx_ring[0].count *
2024 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002025 adapter->clean_rx = e1000_clean_rx_irq;
2026 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2027 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
2029 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002030 rctl = E1000_READ_REG(hw, RCTL);
2031 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
2033 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002034 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002036 if (hw->mac_type >= e1000_82540) {
2037 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002038 if (adapter->itr_setting != 0)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002039 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 1000000000 / (adapter->itr * 256));
2041 }
2042
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002043 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002044 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002045 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002046 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002047#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002048 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002049 ctrl_ext |= E1000_CTRL_EXT_IAME;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002050 E1000_WRITE_REG(hw, IAM, 0xffffffff);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002051#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002052 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2053 E1000_WRITE_FLUSH(hw);
2054 }
2055
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002056 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2057 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002058 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002059 case 1:
2060 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002061 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002062 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07002063 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
2064 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002065 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002066 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002067 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2068 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002069 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002070 }
2071
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002073 if (hw->mac_type >= e1000_82543) {
2074 rxcsum = E1000_READ_REG(hw, RXCSUM);
Joe Perchesc3033b02008-03-21 11:06:25 -07002075 if (adapter->rx_csum) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002076 rxcsum |= E1000_RXCSUM_TUOFL;
2077
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002078 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002079 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002080 if ((hw->mac_type >= e1000_82571) &&
2081 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002082 rxcsum |= E1000_RXCSUM_IPPCSE;
2083 }
2084 } else {
2085 rxcsum &= ~E1000_RXCSUM_TUOFL;
2086 /* don't need to clear IPPCSE as it defaults to 0 */
2087 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002088 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 }
2090
Auke Kok21c4d5e2006-11-01 08:47:39 -08002091 /* enable early receives on 82573, only takes effect if using > 2048
2092 * byte total frame size. for example only for jumbo frames */
2093#define E1000_ERT_2048 0x100
2094 if (hw->mac_type == e1000_82573)
2095 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
2096
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002098 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099}
2100
2101/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002102 * e1000_free_tx_resources - Free Tx Resources per Queue
2103 * @adapter: board private structure
2104 * @tx_ring: Tx descriptor ring for a specific queue
2105 *
2106 * Free all transmit software resources
2107 **/
2108
Joe Perches64798842008-07-11 15:17:02 -07002109static void e1000_free_tx_resources(struct e1000_adapter *adapter,
2110 struct e1000_tx_ring *tx_ring)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002111{
2112 struct pci_dev *pdev = adapter->pdev;
2113
2114 e1000_clean_tx_ring(adapter, tx_ring);
2115
2116 vfree(tx_ring->buffer_info);
2117 tx_ring->buffer_info = NULL;
2118
2119 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2120
2121 tx_ring->desc = NULL;
2122}
2123
2124/**
2125 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 * @adapter: board private structure
2127 *
2128 * Free all transmit software resources
2129 **/
2130
Joe Perches64798842008-07-11 15:17:02 -07002131void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002133 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002135 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002136 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137}
2138
Joe Perches64798842008-07-11 15:17:02 -07002139static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2140 struct e1000_buffer *buffer_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002142 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07002143 pci_unmap_page(adapter->pdev,
2144 buffer_info->dma,
2145 buffer_info->length,
2146 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002147 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002149 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002151 buffer_info->skb = NULL;
2152 }
2153 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154}
2155
2156/**
2157 * e1000_clean_tx_ring - Free Tx Buffers
2158 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002159 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 **/
2161
Joe Perches64798842008-07-11 15:17:02 -07002162static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
2163 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct e1000_buffer *buffer_info;
2166 unsigned long size;
2167 unsigned int i;
2168
2169 /* Free all the Tx ring sk_buffs */
2170
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002171 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 buffer_info = &tx_ring->buffer_info[i];
2173 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2174 }
2175
2176 size = sizeof(struct e1000_buffer) * tx_ring->count;
2177 memset(tx_ring->buffer_info, 0, size);
2178
2179 /* Zero out the descriptor ring */
2180
2181 memset(tx_ring->desc, 0, tx_ring->size);
2182
2183 tx_ring->next_to_use = 0;
2184 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002185 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002187 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2188 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2189}
2190
2191/**
2192 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2193 * @adapter: board private structure
2194 **/
2195
Joe Perches64798842008-07-11 15:17:02 -07002196static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002197{
2198 int i;
2199
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002200 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002201 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
2204/**
2205 * e1000_free_rx_resources - Free Rx Resources
2206 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002207 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 *
2209 * Free all receive software resources
2210 **/
2211
Joe Perches64798842008-07-11 15:17:02 -07002212static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2213 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 struct pci_dev *pdev = adapter->pdev;
2216
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002217 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
2219 vfree(rx_ring->buffer_info);
2220 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002221 kfree(rx_ring->ps_page);
2222 rx_ring->ps_page = NULL;
2223 kfree(rx_ring->ps_page_dma);
2224 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
2226 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2227
2228 rx_ring->desc = NULL;
2229}
2230
2231/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002232 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002234 *
2235 * Free all receive software resources
2236 **/
2237
Joe Perches64798842008-07-11 15:17:02 -07002238void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002239{
2240 int i;
2241
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002242 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002243 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2244}
2245
2246/**
2247 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2248 * @adapter: board private structure
2249 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 **/
2251
Joe Perches64798842008-07-11 15:17:02 -07002252static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2253 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002256 struct e1000_ps_page *ps_page;
2257 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 struct pci_dev *pdev = adapter->pdev;
2259 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002260 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
2262 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002263 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002265 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 pci_unmap_single(pdev,
2267 buffer_info->dma,
2268 buffer_info->length,
2269 PCI_DMA_FROMDEVICE);
2270
2271 dev_kfree_skb(buffer_info->skb);
2272 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002273 }
2274 ps_page = &rx_ring->ps_page[i];
2275 ps_page_dma = &rx_ring->ps_page_dma[i];
2276 for (j = 0; j < adapter->rx_ps_pages; j++) {
2277 if (!ps_page->ps_page[j]) break;
2278 pci_unmap_page(pdev,
2279 ps_page_dma->ps_page_dma[j],
2280 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2281 ps_page_dma->ps_page_dma[j] = 0;
2282 put_page(ps_page->ps_page[j]);
2283 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 }
2285 }
2286
2287 size = sizeof(struct e1000_buffer) * rx_ring->count;
2288 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002289 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2290 memset(rx_ring->ps_page, 0, size);
2291 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2292 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
2294 /* Zero out the descriptor ring */
2295
2296 memset(rx_ring->desc, 0, rx_ring->size);
2297
2298 rx_ring->next_to_clean = 0;
2299 rx_ring->next_to_use = 0;
2300
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002301 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2302 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2303}
2304
2305/**
2306 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2307 * @adapter: board private structure
2308 **/
2309
Joe Perches64798842008-07-11 15:17:02 -07002310static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002311{
2312 int i;
2313
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002314 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002315 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316}
2317
2318/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2319 * and memory write and invalidate disabled for certain operations
2320 */
Joe Perches64798842008-07-11 15:17:02 -07002321static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322{
2323 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002324 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326 e1000_pci_clear_mwi(&adapter->hw);
2327
2328 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2329 rctl |= E1000_RCTL_RST;
2330 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2331 E1000_WRITE_FLUSH(&adapter->hw);
2332 mdelay(5);
2333
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002334 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002335 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336}
2337
Joe Perches64798842008-07-11 15:17:02 -07002338static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339{
2340 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002341 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
2343 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2344 rctl &= ~E1000_RCTL_RST;
2345 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2346 E1000_WRITE_FLUSH(&adapter->hw);
2347 mdelay(5);
2348
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002349 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 e1000_pci_set_mwi(&adapter->hw);
2351
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002352 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002353 /* No need to loop, because 82542 supports only 1 queue */
2354 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002355 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002356 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 }
2358}
2359
2360/**
2361 * e1000_set_mac - Change the Ethernet Address of the NIC
2362 * @netdev: network interface device structure
2363 * @p: pointer to an address structure
2364 *
2365 * Returns 0 on success, negative on failure
2366 **/
2367
Joe Perches64798842008-07-11 15:17:02 -07002368static int e1000_set_mac(struct net_device *netdev, void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002370 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 struct sockaddr *addr = p;
2372
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002373 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 return -EADDRNOTAVAIL;
2375
2376 /* 82542 2.0 needs to be in reset to write receive address registers */
2377
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002378 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 e1000_enter_82542_rst(adapter);
2380
2381 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2382 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2383
2384 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2385
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002386 /* With 82571 controllers, LAA may be overwritten (with the default)
2387 * due to controller reset from the other port. */
2388 if (adapter->hw.mac_type == e1000_82571) {
2389 /* activate the work around */
2390 adapter->hw.laa_is_present = 1;
2391
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002392 /* Hold a copy of the LAA in RAR[14] This is done so that
2393 * between the time RAR[0] gets clobbered and the time it
2394 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002395 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002396 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002397 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002398 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002399 E1000_RAR_ENTRIES - 1);
2400 }
2401
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002402 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 e1000_leave_82542_rst(adapter);
2404
2405 return 0;
2406}
2407
2408/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002409 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 * @netdev: network interface device structure
2411 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002412 * The set_rx_mode entry point is called whenever the unicast or multicast
2413 * address lists or the network interface flags are updated. This routine is
2414 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 * promiscuous mode, and all-multi behavior.
2416 **/
2417
Joe Perches64798842008-07-11 15:17:02 -07002418static void e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002420 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 struct e1000_hw *hw = &adapter->hw;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002422 struct dev_addr_list *uc_ptr;
2423 struct dev_addr_list *mc_ptr;
Joe Perches406874a2008-04-03 10:06:32 -07002424 u32 rctl;
2425 u32 hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002426 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002427 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2428 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2429 E1000_NUM_MTA_REGISTERS;
2430
2431 if (adapter->hw.mac_type == e1000_ich8lan)
2432 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002434 /* reserve RAR[14] for LAA over-write work-around */
2435 if (adapter->hw.mac_type == e1000_82571)
2436 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
Malli Chilakala26483452005-04-28 19:44:46 -07002438 /* Check for Promiscuous and All Multicast modes */
2439
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 rctl = E1000_READ_REG(hw, RCTL);
2441
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002442 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002444 rctl &= ~E1000_RCTL_VFE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002446 if (netdev->flags & IFF_ALLMULTI) {
2447 rctl |= E1000_RCTL_MPE;
2448 } else {
2449 rctl &= ~E1000_RCTL_MPE;
2450 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002451 if (adapter->hw.mac_type != e1000_ich8lan)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002452 rctl |= E1000_RCTL_VFE;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002453 }
2454
2455 uc_ptr = NULL;
2456 if (netdev->uc_count > rar_entries - 1) {
2457 rctl |= E1000_RCTL_UPE;
2458 } else if (!(netdev->flags & IFF_PROMISC)) {
2459 rctl &= ~E1000_RCTL_UPE;
2460 uc_ptr = netdev->uc_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 }
2462
2463 E1000_WRITE_REG(hw, RCTL, rctl);
2464
2465 /* 82542 2.0 needs to be in reset to write receive address registers */
2466
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002467 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 e1000_enter_82542_rst(adapter);
2469
Patrick McHardydb0ce502007-11-13 20:54:59 -08002470 /* load the first 14 addresses into the exact filters 1-14. Unicast
2471 * addresses take precedence to avoid disabling unicast filtering
2472 * when possible.
2473 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 * RAR 0 is used for the station MAC adddress
2475 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002476 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 */
2478 mc_ptr = netdev->mc_list;
2479
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002480 for (i = 1; i < rar_entries; i++) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002481 if (uc_ptr) {
2482 e1000_rar_set(hw, uc_ptr->da_addr, i);
2483 uc_ptr = uc_ptr->next;
2484 } else if (mc_ptr) {
2485 e1000_rar_set(hw, mc_ptr->da_addr, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 mc_ptr = mc_ptr->next;
2487 } else {
2488 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002489 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002491 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 }
2493 }
Patrick McHardydb0ce502007-11-13 20:54:59 -08002494 WARN_ON(uc_ptr != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
2496 /* clear the old settings from the multicast hash table */
2497
Auke Kokcd94dd02006-06-27 09:08:22 -07002498 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002500 E1000_WRITE_FLUSH(hw);
2501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
2503 /* load any remaining addresses into the hash table */
2504
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002505 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002506 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 e1000_mta_set(hw, hash_value);
2508 }
2509
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002510 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512}
2513
2514/* Need to wait a few seconds after link up to get diagnostic information from
2515 * the phy */
2516
Joe Perches64798842008-07-11 15:17:02 -07002517static void e1000_update_phy_info(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518{
2519 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2520 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2521}
2522
2523/**
2524 * e1000_82547_tx_fifo_stall - Timer Call-back
2525 * @data: pointer to adapter cast into an unsigned long
2526 **/
2527
Joe Perches64798842008-07-11 15:17:02 -07002528static void e1000_82547_tx_fifo_stall(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529{
2530 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2531 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002532 u32 tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002534 if (atomic_read(&adapter->tx_fifo_stall)) {
2535 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 E1000_READ_REG(&adapter->hw, TDH)) &&
2537 (E1000_READ_REG(&adapter->hw, TDFT) ==
2538 E1000_READ_REG(&adapter->hw, TDFH)) &&
2539 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2540 E1000_READ_REG(&adapter->hw, TDFHS))) {
2541 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2542 E1000_WRITE_REG(&adapter->hw, TCTL,
2543 tctl & ~E1000_TCTL_EN);
2544 E1000_WRITE_REG(&adapter->hw, TDFT,
2545 adapter->tx_head_addr);
2546 E1000_WRITE_REG(&adapter->hw, TDFH,
2547 adapter->tx_head_addr);
2548 E1000_WRITE_REG(&adapter->hw, TDFTS,
2549 adapter->tx_head_addr);
2550 E1000_WRITE_REG(&adapter->hw, TDFHS,
2551 adapter->tx_head_addr);
2552 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2553 E1000_WRITE_FLUSH(&adapter->hw);
2554
2555 adapter->tx_fifo_head = 0;
2556 atomic_set(&adapter->tx_fifo_stall, 0);
2557 netif_wake_queue(netdev);
2558 } else {
2559 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2560 }
2561 }
2562}
2563
2564/**
2565 * e1000_watchdog - Timer Call-back
2566 * @data: pointer to adapter cast into an unsigned long
2567 **/
Joe Perches64798842008-07-11 15:17:02 -07002568static void e1000_watchdog(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569{
2570 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002572 struct e1000_tx_ring *txdr = adapter->tx_ring;
Joe Perches406874a2008-04-03 10:06:32 -07002573 u32 link, tctl;
2574 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
Auke Kokcd94dd02006-06-27 09:08:22 -07002576 ret_val = e1000_check_for_link(&adapter->hw);
2577 if ((ret_val == E1000_ERR_PHY) &&
2578 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2579 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2580 /* See e1000_kumeran_lock_loss_workaround() */
2581 DPRINTK(LINK, INFO,
2582 "Gigabit has been disabled, downgrading speed\n");
2583 }
Auke Kok90fb5132006-11-01 08:47:30 -08002584
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002585 if (adapter->hw.mac_type == e1000_82573) {
2586 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002587 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002588 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002591 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2593 link = !adapter->hw.serdes_link_down;
2594 else
2595 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2596
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002597 if (link) {
2598 if (!netif_carrier_ok(netdev)) {
Joe Perches406874a2008-04-03 10:06:32 -07002599 u32 ctrl;
Joe Perchesc3033b02008-03-21 11:06:25 -07002600 bool txb2b = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 e1000_get_speed_and_duplex(&adapter->hw,
2602 &adapter->link_speed,
2603 &adapter->link_duplex);
2604
Auke Kok9669f532007-01-18 09:25:26 -08002605 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
2606 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2607 "Flow Control: %s\n",
2608 adapter->link_speed,
2609 adapter->link_duplex == FULL_DUPLEX ?
2610 "Full Duplex" : "Half Duplex",
2611 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2612 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2613 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2614 E1000_CTRL_TFCE) ? "TX" : "None" )));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002616 /* tweak tx_queue_len according to speed/duplex
2617 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002618 netdev->tx_queue_len = adapter->tx_queue_len;
2619 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002620 switch (adapter->link_speed) {
2621 case SPEED_10:
Joe Perchesc3033b02008-03-21 11:06:25 -07002622 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002623 netdev->tx_queue_len = 10;
2624 adapter->tx_timeout_factor = 8;
2625 break;
2626 case SPEED_100:
Joe Perchesc3033b02008-03-21 11:06:25 -07002627 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002628 netdev->tx_queue_len = 100;
2629 /* maybe add some timeout factor ? */
2630 break;
2631 }
2632
Auke Kokfe7fe282006-04-14 19:04:59 -07002633 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002634 adapter->hw.mac_type == e1000_82572) &&
Joe Perchesc3033b02008-03-21 11:06:25 -07002635 !txb2b) {
Joe Perches406874a2008-04-03 10:06:32 -07002636 u32 tarc0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002637 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002638 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002639 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2640 }
Auke Kok90fb5132006-11-01 08:47:30 -08002641
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002642 /* disable TSO for pcie and 10/100 speeds, to avoid
2643 * some hardware issues */
2644 if (!adapter->tso_force &&
2645 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002646 switch (adapter->link_speed) {
2647 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002648 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002649 DPRINTK(PROBE,INFO,
2650 "10/100 speed: disabling TSO\n");
2651 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002652 netdev->features &= ~NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002653 break;
2654 case SPEED_1000:
2655 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002656 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002657 break;
2658 default:
2659 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002660 break;
2661 }
2662 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002663
2664 /* enable transmits in the hardware, need to do this
2665 * after setting TARC0 */
2666 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2667 tctl |= E1000_TCTL_EN;
2668 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002669
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 netif_carrier_on(netdev);
2671 netif_wake_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002672 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002674 } else {
2675 /* make sure the receive unit is started */
2676 if (adapter->hw.rx_needs_kicking) {
2677 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002678 u32 rctl = E1000_READ_REG(hw, RCTL);
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002679 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 }
2682 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002683 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 adapter->link_speed = 0;
2685 adapter->link_duplex = 0;
2686 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2687 netif_carrier_off(netdev);
2688 netif_stop_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002689 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Jeff Kirsher87041632006-03-02 18:21:24 -08002690
2691 /* 80003ES2LAN workaround--
2692 * For packet buffer work-around on link down event;
2693 * disable receives in the ISR and
2694 * reset device here in the watchdog
2695 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002696 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002697 /* reset device */
2698 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 }
2700
2701 e1000_smartspeed(adapter);
2702 }
2703
2704 e1000_update_stats(adapter);
2705
2706 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2707 adapter->tpt_old = adapter->stats.tpt;
2708 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2709 adapter->colc_old = adapter->stats.colc;
2710
2711 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2712 adapter->gorcl_old = adapter->stats.gorcl;
2713 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2714 adapter->gotcl_old = adapter->stats.gotcl;
2715
2716 e1000_update_adaptive(&adapter->hw);
2717
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002718 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002719 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 /* We've lost link, so the controller stops DMA,
2721 * but we've got queued Tx work that's never going
2722 * to get done, so reset controller to flush Tx.
2723 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002724 adapter->tx_timeout_count++;
2725 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 }
2727 }
2728
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 /* Cause software interrupt to ensure rx ring is cleaned */
2730 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2731
Malli Chilakala26483452005-04-28 19:44:46 -07002732 /* Force detection of hung controller every watchdog period */
Joe Perchesc3033b02008-03-21 11:06:25 -07002733 adapter->detect_tx_hung = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002735 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002736 * reset from the other port. Set the appropriate LAA in RAR[0] */
2737 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2738 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2739
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 /* Reset the timer */
Arjan van de Ven56e13932007-03-06 02:41:48 -08002741 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742}
2743
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002744enum latency_range {
2745 lowest_latency = 0,
2746 low_latency = 1,
2747 bulk_latency = 2,
2748 latency_invalid = 255
2749};
2750
2751/**
2752 * e1000_update_itr - update the dynamic ITR value based on statistics
2753 * Stores a new ITR value based on packets and byte
2754 * counts during the last interrupt. The advantage of per interrupt
2755 * computation is faster updates and more accurate ITR for the current
2756 * traffic pattern. Constants in this function were computed
2757 * based on theoretical maximum wire speed and thresholds were set based
2758 * on testing data as well as attempting to minimize response time
2759 * while increasing bulk throughput.
2760 * this functionality is controlled by the InterruptThrottleRate module
2761 * parameter (see e1000_param.c)
2762 * @adapter: pointer to adapter
2763 * @itr_setting: current adapter->itr
2764 * @packets: the number of packets during this measurement interval
2765 * @bytes: the number of bytes during this measurement interval
2766 **/
2767static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
Joe Perches64798842008-07-11 15:17:02 -07002768 u16 itr_setting, int packets, int bytes)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002769{
2770 unsigned int retval = itr_setting;
2771 struct e1000_hw *hw = &adapter->hw;
2772
2773 if (unlikely(hw->mac_type < e1000_82540))
2774 goto update_itr_done;
2775
2776 if (packets == 0)
2777 goto update_itr_done;
2778
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002779 switch (itr_setting) {
2780 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002781 /* jumbo frames get bulk treatment*/
2782 if (bytes/packets > 8000)
2783 retval = bulk_latency;
2784 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002785 retval = low_latency;
2786 break;
2787 case low_latency: /* 50 usec aka 20000 ints/s */
2788 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002789 /* jumbo frames need bulk latency setting */
2790 if (bytes/packets > 8000)
2791 retval = bulk_latency;
2792 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002793 retval = bulk_latency;
2794 else if ((packets > 35))
2795 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002796 } else if (bytes/packets > 2000)
2797 retval = bulk_latency;
2798 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002799 retval = lowest_latency;
2800 break;
2801 case bulk_latency: /* 250 usec aka 4000 ints/s */
2802 if (bytes > 25000) {
2803 if (packets > 35)
2804 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002805 } else if (bytes < 6000) {
2806 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002807 }
2808 break;
2809 }
2810
2811update_itr_done:
2812 return retval;
2813}
2814
2815static void e1000_set_itr(struct e1000_adapter *adapter)
2816{
2817 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002818 u16 current_itr;
2819 u32 new_itr = adapter->itr;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002820
2821 if (unlikely(hw->mac_type < e1000_82540))
2822 return;
2823
2824 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2825 if (unlikely(adapter->link_speed != SPEED_1000)) {
2826 current_itr = 0;
2827 new_itr = 4000;
2828 goto set_itr_now;
2829 }
2830
2831 adapter->tx_itr = e1000_update_itr(adapter,
2832 adapter->tx_itr,
2833 adapter->total_tx_packets,
2834 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002835 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2836 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2837 adapter->tx_itr = low_latency;
2838
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002839 adapter->rx_itr = e1000_update_itr(adapter,
2840 adapter->rx_itr,
2841 adapter->total_rx_packets,
2842 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002843 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2844 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2845 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002846
2847 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2848
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002849 switch (current_itr) {
2850 /* counts and packets in update_itr are dependent on these numbers */
2851 case lowest_latency:
2852 new_itr = 70000;
2853 break;
2854 case low_latency:
2855 new_itr = 20000; /* aka hwitr = ~200 */
2856 break;
2857 case bulk_latency:
2858 new_itr = 4000;
2859 break;
2860 default:
2861 break;
2862 }
2863
2864set_itr_now:
2865 if (new_itr != adapter->itr) {
2866 /* this attempts to bias the interrupt rate towards Bulk
2867 * by adding intermediate steps when interrupt rate is
2868 * increasing */
2869 new_itr = new_itr > adapter->itr ?
2870 min(adapter->itr + (new_itr >> 2), new_itr) :
2871 new_itr;
2872 adapter->itr = new_itr;
2873 E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
2874 }
2875
2876 return;
2877}
2878
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879#define E1000_TX_FLAGS_CSUM 0x00000001
2880#define E1000_TX_FLAGS_VLAN 0x00000002
2881#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002882#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2884#define E1000_TX_FLAGS_VLAN_SHIFT 16
2885
Joe Perches64798842008-07-11 15:17:02 -07002886static int e1000_tso(struct e1000_adapter *adapter,
2887 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002890 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002892 u32 cmd_length = 0;
2893 u16 ipcse = 0, tucse, mss;
2894 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 int err;
2896
Herbert Xu89114af2006-07-08 13:34:32 -07002897 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 if (skb_header_cloned(skb)) {
2899 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2900 if (err)
2901 return err;
2902 }
2903
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002904 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002905 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002906 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002907 struct iphdr *iph = ip_hdr(skb);
2908 iph->tot_len = 0;
2909 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002910 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2911 iph->daddr, 0,
2912 IPPROTO_TCP,
2913 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002914 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002915 ipcse = skb_transport_offset(skb) - 1;
Auke Koke15fdd02006-08-16 11:28:45 -07002916 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002917 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002918 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002919 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2920 &ipv6_hdr(skb)->daddr,
2921 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002922 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002923 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002924 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002925 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002926 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002927 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 tucse = 0;
2929
2930 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002931 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002933 i = tx_ring->next_to_use;
2934 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002935 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
2937 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2938 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2939 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2940 context_desc->upper_setup.tcp_fields.tucss = tucss;
2941 context_desc->upper_setup.tcp_fields.tucso = tucso;
2942 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2943 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2944 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2945 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2946
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002947 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002948 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002949
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002950 if (++i == tx_ring->count) i = 0;
2951 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
Joe Perchesc3033b02008-03-21 11:06:25 -07002953 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 }
Joe Perchesc3033b02008-03-21 11:06:25 -07002955 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956}
2957
Joe Perches64798842008-07-11 15:17:02 -07002958static bool e1000_tx_csum(struct e1000_adapter *adapter,
2959 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960{
2961 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002962 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002964 u8 css;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965
Patrick McHardy84fa7932006-08-29 16:44:56 -07002966 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002967 css = skb_transport_offset(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002969 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002970 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002971 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972
Bruce Allanf6c57ba2007-01-18 09:25:28 -08002973 context_desc->lower_setup.ip_config = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 context_desc->upper_setup.tcp_fields.tucss = css;
Herbert Xu628592c2007-04-23 17:06:40 -07002975 context_desc->upper_setup.tcp_fields.tucso =
2976 css + skb->csum_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 context_desc->upper_setup.tcp_fields.tucse = 0;
2978 context_desc->tcp_seg_setup.data = 0;
2979 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2980
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002981 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002982 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002983
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002984 if (unlikely(++i == tx_ring->count)) i = 0;
2985 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986
Joe Perchesc3033b02008-03-21 11:06:25 -07002987 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 }
2989
Joe Perchesc3033b02008-03-21 11:06:25 -07002990 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991}
2992
2993#define E1000_MAX_TXD_PWR 12
2994#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2995
Joe Perches64798842008-07-11 15:17:02 -07002996static int e1000_tx_map(struct e1000_adapter *adapter,
2997 struct e1000_tx_ring *tx_ring,
2998 struct sk_buff *skb, unsigned int first,
2999 unsigned int max_per_txd, unsigned int nr_frags,
3000 unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 struct e1000_buffer *buffer_info;
3003 unsigned int len = skb->len;
3004 unsigned int offset = 0, size, count = 0, i;
3005 unsigned int f;
3006 len -= skb->data_len;
3007
3008 i = tx_ring->next_to_use;
3009
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003010 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 buffer_info = &tx_ring->buffer_info[i];
3012 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05003013 /* Workaround for Controller erratum --
3014 * descriptor for non-tso packet in a linear SKB that follows a
3015 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003016 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05003017 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07003018 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05003019 tx_ring->last_tx_tso = 0;
3020 size -= 4;
3021 }
3022
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 /* Workaround for premature desc write-backs
3024 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003025 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07003027 /* work-around for errata 10 and it applies
3028 * to all controllers in PCI-X mode
3029 * The fix is to make sure that the first descriptor of a
3030 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3031 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003032 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003033 (size > 2015) && count == 0))
3034 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003035
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 /* Workaround for potential 82544 hang in PCI-X. Avoid
3037 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003038 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3040 size > 4))
3041 size -= 4;
3042
3043 buffer_info->length = size;
3044 buffer_info->dma =
3045 pci_map_single(adapter->pdev,
3046 skb->data + offset,
3047 size,
3048 PCI_DMA_TODEVICE);
3049 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003050 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051
3052 len -= size;
3053 offset += size;
3054 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003055 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 }
3057
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003058 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 struct skb_frag_struct *frag;
3060
3061 frag = &skb_shinfo(skb)->frags[f];
3062 len = frag->size;
3063 offset = frag->page_offset;
3064
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003065 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 buffer_info = &tx_ring->buffer_info[i];
3067 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 /* Workaround for premature desc write-backs
3069 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003070 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 /* Workaround for potential 82544 hang in PCI-X.
3073 * Avoid terminating buffers within evenly-aligned
3074 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003075 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3077 size > 4))
3078 size -= 4;
3079
3080 buffer_info->length = size;
3081 buffer_info->dma =
3082 pci_map_page(adapter->pdev,
3083 frag->page,
3084 offset,
3085 size,
3086 PCI_DMA_TODEVICE);
3087 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003088 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
3090 len -= size;
3091 offset += size;
3092 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003093 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 }
3095 }
3096
3097 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3098 tx_ring->buffer_info[i].skb = skb;
3099 tx_ring->buffer_info[first].next_to_watch = i;
3100
3101 return count;
3102}
3103
Joe Perches64798842008-07-11 15:17:02 -07003104static void e1000_tx_queue(struct e1000_adapter *adapter,
3105 struct e1000_tx_ring *tx_ring, int tx_flags,
3106 int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 struct e1000_tx_desc *tx_desc = NULL;
3109 struct e1000_buffer *buffer_info;
Joe Perches406874a2008-04-03 10:06:32 -07003110 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 unsigned int i;
3112
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003113 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3115 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003116 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3117
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003118 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003119 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 }
3121
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003122 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3124 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3125 }
3126
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003127 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 txd_lower |= E1000_TXD_CMD_VLE;
3129 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3130 }
3131
3132 i = tx_ring->next_to_use;
3133
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003134 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 buffer_info = &tx_ring->buffer_info[i];
3136 tx_desc = E1000_TX_DESC(*tx_ring, i);
3137 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3138 tx_desc->lower.data =
3139 cpu_to_le32(txd_lower | buffer_info->length);
3140 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003141 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 }
3143
3144 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3145
3146 /* Force memory writes to complete before letting h/w
3147 * know there are new descriptors to fetch. (Only
3148 * applicable for weak-ordered memory model archs,
3149 * such as IA-64). */
3150 wmb();
3151
3152 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003153 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003154 /* we need this if more than one processor can write to our tail
3155 * at a time, it syncronizes IO on IA64/Altix systems */
3156 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157}
3158
3159/**
3160 * 82547 workaround to avoid controller hang in half-duplex environment.
3161 * The workaround is to avoid queuing a large packet that would span
3162 * the internal Tx FIFO ring boundary by notifying the stack to resend
3163 * the packet at a later time. This gives the Tx FIFO an opportunity to
3164 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3165 * to the beginning of the Tx FIFO.
3166 **/
3167
3168#define E1000_FIFO_HDR 0x10
3169#define E1000_82547_PAD_LEN 0x3E0
3170
Joe Perches64798842008-07-11 15:17:02 -07003171static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3172 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173{
Joe Perches406874a2008-04-03 10:06:32 -07003174 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3175 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003177 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003179 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 goto no_fifo_stall_required;
3181
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003182 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 return 1;
3184
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003185 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 atomic_set(&adapter->tx_fifo_stall, 1);
3187 return 1;
3188 }
3189
3190no_fifo_stall_required:
3191 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003192 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3194 return 0;
3195}
3196
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003197#define MINIMUM_DHCP_PACKET_SIZE 282
Joe Perches64798842008-07-11 15:17:02 -07003198static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3199 struct sk_buff *skb)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003200{
3201 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003202 u16 length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003203 if (vlan_tx_tag_present(skb)) {
3204 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003205 ( adapter->hw.mng_cookie.status &
3206 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3207 return 0;
3208 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003209 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003210 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003211 if ((htons(ETH_P_IP) == eth->h_proto)) {
3212 const struct iphdr *ip =
Joe Perches406874a2008-04-03 10:06:32 -07003213 (struct iphdr *)((u8 *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003214 if (IPPROTO_UDP == ip->protocol) {
3215 struct udphdr *udp =
Joe Perches406874a2008-04-03 10:06:32 -07003216 (struct udphdr *)((u8 *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003217 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003218 if (ntohs(udp->dest) == 67) {
Joe Perches406874a2008-04-03 10:06:32 -07003219 offset = (u8 *)udp + 8 - skb->data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003220 length = skb->len - offset;
3221
3222 return e1000_mng_write_dhcp_info(hw,
Joe Perches406874a2008-04-03 10:06:32 -07003223 (u8 *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003224 length);
3225 }
3226 }
3227 }
3228 }
3229 return 0;
3230}
3231
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003232static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3233{
3234 struct e1000_adapter *adapter = netdev_priv(netdev);
3235 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3236
3237 netif_stop_queue(netdev);
3238 /* Herbert's original patch had:
3239 * smp_mb__after_netif_stop_queue();
3240 * but since that doesn't exist yet, just open code it. */
3241 smp_mb();
3242
3243 /* We need to check again in a case another CPU has just
3244 * made room available. */
3245 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3246 return -EBUSY;
3247
3248 /* A reprieve! */
3249 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003250 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003251 return 0;
3252}
3253
3254static int e1000_maybe_stop_tx(struct net_device *netdev,
3255 struct e1000_tx_ring *tx_ring, int size)
3256{
3257 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3258 return 0;
3259 return __e1000_maybe_stop_tx(netdev, size);
3260}
3261
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Joe Perches64798842008-07-11 15:17:02 -07003263static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003265 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003266 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3268 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3269 unsigned int tx_flags = 0;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003270 unsigned int len = skb->len - skb->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 unsigned long flags;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003272 unsigned int nr_frags;
3273 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003275 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 unsigned int f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003278 /* This goes back to the question of how to logically map a tx queue
3279 * to a flow. Right now, performance is impacted slightly negatively
3280 * if using multiple tx queues. If the stack breaks away from a
3281 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003282 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003283
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003284 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 dev_kfree_skb_any(skb);
3286 return NETDEV_TX_OK;
3287 }
3288
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003289 /* 82571 and newer doesn't need the workaround that limited descriptor
3290 * length to 4kB */
3291 if (adapter->hw.mac_type >= e1000_82571)
3292 max_per_txd = 8192;
3293
Herbert Xu79671682006-06-22 02:40:14 -07003294 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003295 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 * make sure there is enough room in the FIFO before
3297 * initiating the DMA for each buffer. The calc is:
3298 * 4 = ceil(buffer len/mss). To make sure we don't
3299 * overrun the FIFO, adjust the max buffer len if mss
3300 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003301 if (mss) {
Joe Perches406874a2008-04-03 10:06:32 -07003302 u8 hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 max_per_txd = min(mss << 2, max_per_txd);
3304 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003305
Auke Kok90fb5132006-11-01 08:47:30 -08003306 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3307 * points to just header, pull a few bytes of payload from
3308 * frags into skb->data */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003309 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003310 if (skb->data_len && hdr_len == len) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003311 switch (adapter->hw.mac_type) {
3312 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003313 case e1000_82544:
3314 /* Make sure we have room to chop off 4 bytes,
3315 * and that the end alignment will work out to
3316 * this hardware's requirements
3317 * NOTE: this is a TSO only workaround
3318 * if end byte alignment not correct move us
3319 * into the next dword */
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003320 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003321 break;
3322 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003323 case e1000_82571:
3324 case e1000_82572:
3325 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003326 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003327 pull_size = min((unsigned int)4, skb->data_len);
3328 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003329 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003330 "__pskb_pull_tail failed.\n");
3331 dev_kfree_skb_any(skb);
Jeff Garzik749dfc72006-03-11 13:35:31 -05003332 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003333 }
3334 len = skb->len - skb->data_len;
3335 break;
3336 default:
3337 /* do nothing */
3338 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003339 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 }
3342
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003343 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003344 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003346 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003347
Jeff Kirsherfd803242005-12-13 00:06:22 -05003348 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003349 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003350 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003351
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 count += TXD_USE_COUNT(len, max_txd_pwr);
3353
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003354 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 count++;
3356
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003357 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003358 * in PCI-X mode, so add one more descriptor to the count
3359 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003360 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003361 (len > 2015)))
3362 count++;
3363
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003365 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3367 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003368 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 count += nr_frags;
3370
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003371
3372 if (adapter->hw.tx_pkt_filtering &&
3373 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003374 e1000_transfer_dhcp_info(adapter, skb);
3375
Mark Huthf50393f2007-03-06 08:57:26 -08003376 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003377 /* Collision - tell upper layer to requeue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003378 return NETDEV_TX_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
3380 /* need: count + 2 desc gap to keep tail from touching
3381 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003382 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003383 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 return NETDEV_TX_BUSY;
3385 }
3386
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003387 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3388 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003390 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003391 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 return NETDEV_TX_BUSY;
3393 }
3394 }
3395
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003396 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 tx_flags |= E1000_TX_FLAGS_VLAN;
3398 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3399 }
3400
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003401 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003402
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003403 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 if (tso < 0) {
3405 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003406 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 return NETDEV_TX_OK;
3408 }
3409
Jeff Kirsherfd803242005-12-13 00:06:22 -05003410 if (likely(tso)) {
3411 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003413 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 tx_flags |= E1000_TX_FLAGS_CSUM;
3415
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003416 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003417 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003418 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003419 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003420 tx_flags |= E1000_TX_FLAGS_IPV4;
3421
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003422 e1000_tx_queue(adapter, tx_ring, tx_flags,
3423 e1000_tx_map(adapter, tx_ring, skb, first,
3424 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425
3426 netdev->trans_start = jiffies;
3427
3428 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003429 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003431 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 return NETDEV_TX_OK;
3433}
3434
3435/**
3436 * e1000_tx_timeout - Respond to a Tx Hang
3437 * @netdev: network interface device structure
3438 **/
3439
Joe Perches64798842008-07-11 15:17:02 -07003440static void e1000_tx_timeout(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003442 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443
3444 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003445 adapter->tx_timeout_count++;
3446 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447}
3448
Joe Perches64798842008-07-11 15:17:02 -07003449static void e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450{
David Howells65f27f32006-11-22 14:55:48 +00003451 struct e1000_adapter *adapter =
3452 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
Auke Kok2db10a02006-06-27 09:06:28 -07003454 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455}
3456
3457/**
3458 * e1000_get_stats - Get System Network Statistics
3459 * @netdev: network interface device structure
3460 *
3461 * Returns the address of the device statistics structure.
3462 * The statistics are actually updated from the timer callback.
3463 **/
3464
Joe Perches64798842008-07-11 15:17:02 -07003465static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003467 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003469 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 return &adapter->net_stats;
3471}
3472
3473/**
3474 * e1000_change_mtu - Change the Maximum Transfer Unit
3475 * @netdev: network interface device structure
3476 * @new_mtu: new value for maximum frame size
3477 *
3478 * Returns 0 on success, negative on failure
3479 **/
3480
Joe Perches64798842008-07-11 15:17:02 -07003481static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003483 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Joe Perches406874a2008-04-03 10:06:32 -07003485 u16 eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003487 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3488 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3489 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003490 return -EINVAL;
3491 }
3492
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003493 /* Adapter-specific max frame size limits. */
3494 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003495 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003496 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003497 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3498 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003499 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003500 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003501 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003502 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003503 /* Jumbo Frames not supported if:
3504 * - this is not an 82573L device
3505 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003506 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3507 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003508 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3509 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003510 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3511 DPRINTK(PROBE, ERR,
3512 "Jumbo Frames not supported.\n");
3513 return -EINVAL;
3514 }
3515 break;
3516 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003517 /* ERT will be enabled later to enable wire speed receives */
3518
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003519 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003520 case e1000_82571:
3521 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003522 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003523#define MAX_STD_JUMBO_FRAME_SIZE 9234
3524 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3525 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3526 return -EINVAL;
3527 }
3528 break;
3529 default:
3530 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3531 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003532 }
3533
David S. Miller87f50322006-07-31 22:39:40 -07003534 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003535 * means we reserve 2 more, this pushes us to allocate from the next
3536 * larger slab size
3537 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003538
Auke Kok9e2feac2006-04-14 19:05:18 -07003539 if (max_frame <= E1000_RXBUFFER_256)
3540 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3541 else if (max_frame <= E1000_RXBUFFER_512)
3542 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3543 else if (max_frame <= E1000_RXBUFFER_1024)
3544 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3545 else if (max_frame <= E1000_RXBUFFER_2048)
3546 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3547 else if (max_frame <= E1000_RXBUFFER_4096)
3548 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3549 else if (max_frame <= E1000_RXBUFFER_8192)
3550 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3551 else if (max_frame <= E1000_RXBUFFER_16384)
3552 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3553
3554 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003555 if (!adapter->hw.tbi_compatibility_on &&
3556 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3557 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3558 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003559
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003560 netdev->mtu = new_mtu;
Bruce Allan83cd8272006-12-15 10:36:35 +01003561 adapter->hw.max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003562
Auke Kok2db10a02006-06-27 09:06:28 -07003563 if (netif_running(netdev))
3564 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 return 0;
3567}
3568
3569/**
3570 * e1000_update_stats - Update the board statistics counters
3571 * @adapter: board private structure
3572 **/
3573
Joe Perches64798842008-07-11 15:17:02 -07003574void e1000_update_stats(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575{
3576 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003577 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07003579 u16 phy_tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580
3581#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3582
Linas Vepstas282f33c2006-06-08 22:19:44 -07003583 /*
3584 * Prevent stats update while adapter is being reset, or if the pci
3585 * connection is down.
3586 */
Auke Kok90267292006-06-08 09:30:24 -07003587 if (adapter->link_speed == 0)
3588 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003589 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003590 return;
Auke Kok90267292006-06-08 09:30:24 -07003591
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 spin_lock_irqsave(&adapter->stats_lock, flags);
3593
Masatake YAMATO828d0552007-10-20 03:06:37 +02003594 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 * called from the interrupt context, so they must only
3596 * be written while holding adapter->stats_lock
3597 */
3598
3599 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3600 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3601 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3602 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3603 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3604 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3605 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003606
3607 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003608 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3609 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3610 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3611 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3612 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3613 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615
3616 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3617 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3618 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3619 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3620 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3621 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3622 adapter->stats.dc += E1000_READ_REG(hw, DC);
3623 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3624 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3625 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3626 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3627 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3628 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3629 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3630 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3631 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3632 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3633 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3634 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3635 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3636 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3637 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3638 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3639 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3640 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3641 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003642
3643 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003644 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3645 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3646 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3647 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3648 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3649 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003650 }
3651
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3653 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3654
3655 /* used for adaptive IFS */
3656
3657 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3658 adapter->stats.tpt += hw->tx_packet_delta;
3659 hw->collision_delta = E1000_READ_REG(hw, COLC);
3660 adapter->stats.colc += hw->collision_delta;
3661
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003662 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3664 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3665 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3666 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3667 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3668 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3669 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003670 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003671 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3672 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003673
3674 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003675 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3676 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3677 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3678 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3679 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3680 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3681 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003682 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684
3685 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 adapter->net_stats.multicast = adapter->stats.mprc;
3687 adapter->net_stats.collisions = adapter->stats.colc;
3688
3689 /* Rx Errors */
3690
Jeff Kirsher87041632006-03-02 18:21:24 -08003691 /* RLEC on some newer hardware can be incorrect so build
3692 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3694 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003695 adapter->stats.ruc + adapter->stats.roc +
3696 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003697 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3698 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3700 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3702
3703 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003704 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3705 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3707 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3708 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Jeff Garzik167fb282006-12-15 10:41:15 -05003709 if (adapter->hw.bad_tx_carr_stats_fd &&
3710 adapter->link_duplex == FULL_DUPLEX) {
3711 adapter->net_stats.tx_carrier_errors = 0;
3712 adapter->stats.tncrs = 0;
3713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714
3715 /* Tx Dropped needs to be maintained elsewhere */
3716
3717 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003718 if (hw->media_type == e1000_media_type_copper) {
3719 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3721 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3722 adapter->phy_stats.idle_errors += phy_tmp;
3723 }
3724
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003725 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 (hw->phy_type == e1000_phy_m88) &&
3727 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3728 adapter->phy_stats.receive_errors += phy_tmp;
3729 }
3730
Jeff Garzik15e376b2006-12-15 11:16:33 -05003731 /* Management Stats */
3732 if (adapter->hw.has_smbus) {
3733 adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
3734 adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
3735 adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
3736 }
3737
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3739}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003740
3741/**
3742 * e1000_intr_msi - Interrupt Handler
3743 * @irq: interrupt number
3744 * @data: pointer to a network interface device structure
3745 **/
3746
Joe Perches64798842008-07-11 15:17:02 -07003747static irqreturn_t e1000_intr_msi(int irq, void *data)
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003748{
3749 struct net_device *netdev = data;
3750 struct e1000_adapter *adapter = netdev_priv(netdev);
3751 struct e1000_hw *hw = &adapter->hw;
3752#ifndef CONFIG_E1000_NAPI
3753 int i;
3754#endif
Joe Perches406874a2008-04-03 10:06:32 -07003755 u32 icr = E1000_READ_REG(hw, ICR);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003756
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003757 /* in NAPI mode read ICR disables interrupts using IAM */
3758
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003759 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3760 hw->get_link_status = 1;
3761 /* 80003ES2LAN workaround-- For packet buffer work-around on
3762 * link down event; disable receives here in the ISR and reset
3763 * adapter in watchdog */
3764 if (netif_carrier_ok(netdev) &&
3765 (adapter->hw.mac_type == e1000_80003es2lan)) {
3766 /* disable receives */
Joe Perches406874a2008-04-03 10:06:32 -07003767 u32 rctl = E1000_READ_REG(hw, RCTL);
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003768 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003769 }
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003770 /* guard against interrupt when we're going down */
3771 if (!test_bit(__E1000_DOWN, &adapter->flags))
3772 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003773 }
3774
3775#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003776 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003777 adapter->total_tx_bytes = 0;
3778 adapter->total_tx_packets = 0;
3779 adapter->total_rx_bytes = 0;
3780 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003781 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003782 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003783 e1000_irq_enable(adapter);
3784#else
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003785 adapter->total_tx_bytes = 0;
3786 adapter->total_rx_bytes = 0;
3787 adapter->total_tx_packets = 0;
3788 adapter->total_rx_packets = 0;
3789
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003790 for (i = 0; i < E1000_MAX_INTR; i++)
3791 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003792 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003793 break;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003794
3795 if (likely(adapter->itr_setting & 3))
3796 e1000_set_itr(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003797#endif
3798
3799 return IRQ_HANDLED;
3800}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801
3802/**
3803 * e1000_intr - Interrupt Handler
3804 * @irq: interrupt number
3805 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 **/
3807
Joe Perches64798842008-07-11 15:17:02 -07003808static irqreturn_t e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809{
3810 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003811 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003813 u32 rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003814#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003815 int i;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003816#endif
3817 if (unlikely(!icr))
3818 return IRQ_NONE; /* Not our interrupt */
3819
3820#ifdef CONFIG_E1000_NAPI
3821 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3822 * not set, then the adapter didn't send an interrupt */
3823 if (unlikely(hw->mac_type >= e1000_82571 &&
3824 !(icr & E1000_ICR_INT_ASSERTED)))
3825 return IRQ_NONE;
3826
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003827 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3828 * need for the IMC write */
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003829#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003831 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003833 /* 80003ES2LAN workaround--
3834 * For packet buffer work-around on link down event;
3835 * disable receives here in the ISR and
3836 * reset adapter in watchdog
3837 */
3838 if (netif_carrier_ok(netdev) &&
3839 (adapter->hw.mac_type == e1000_80003es2lan)) {
3840 /* disable receives */
3841 rctl = E1000_READ_REG(hw, RCTL);
3842 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3843 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003844 /* guard against interrupt when we're going down */
3845 if (!test_bit(__E1000_DOWN, &adapter->flags))
3846 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 }
3848
3849#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003850 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003851 /* disable interrupts, without the synchronize_irq bit */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003852 E1000_WRITE_REG(hw, IMC, ~0);
3853 E1000_WRITE_FLUSH(hw);
3854 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003855 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003856 adapter->total_tx_bytes = 0;
3857 adapter->total_tx_packets = 0;
3858 adapter->total_rx_bytes = 0;
3859 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003860 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003861 } else
Auke Kok90fb5132006-11-01 08:47:30 -08003862 /* this really should not happen! if it does it is basically a
3863 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003864 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003865#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003867 * Due to Hub Link bus being occupied, an interrupt
3868 * de-assertion message is not able to be sent.
3869 * When an interrupt assertion message is generated later,
3870 * two messages are re-ordered and sent out.
3871 * That causes APIC to think 82547 is in de-assertion
3872 * state, while 82547 is in assertion state, resulting
3873 * in dead lock. Writing IMC forces 82547 into
3874 * de-assertion state.
3875 */
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003876 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Malli Chilakala26483452005-04-28 19:44:46 -07003877 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003879 adapter->total_tx_bytes = 0;
3880 adapter->total_rx_bytes = 0;
3881 adapter->total_tx_packets = 0;
3882 adapter->total_rx_packets = 0;
3883
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003884 for (i = 0; i < E1000_MAX_INTR; i++)
3885 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003886 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 break;
3888
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003889 if (likely(adapter->itr_setting & 3))
3890 e1000_set_itr(adapter);
3891
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003892 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003894
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003895#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 return IRQ_HANDLED;
3897}
3898
3899#ifdef CONFIG_E1000_NAPI
3900/**
3901 * e1000_clean - NAPI Rx polling callback
3902 * @adapter: board private structure
3903 **/
3904
Joe Perches64798842008-07-11 15:17:02 -07003905static int e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003907 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3908 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003909 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003910
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003911 /* Must NOT use netdev_priv macro here. */
3912 adapter = poll_dev->priv;
3913
Auke Kokd3d9e482006-07-14 16:14:23 -07003914 /* e1000_clean is called per-cpu. This lock protects
3915 * tx_ring[0] from being cleaned by multiple cpus
3916 * simultaneously. A failure obtaining the lock means
3917 * tx_ring[0] is currently being cleaned anyway. */
3918 if (spin_trylock(&adapter->tx_queue_lock)) {
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003919 tx_cleaned = e1000_clean_tx_irq(adapter,
3920 &adapter->tx_ring[0]);
Auke Kokd3d9e482006-07-14 16:14:23 -07003921 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003922 }
3923
Auke Kokd3d9e482006-07-14 16:14:23 -07003924 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003925 &work_done, budget);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003926
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003927 if (tx_cleaned)
3928 work_done = budget;
3929
David S. Miller53e52c72008-01-07 21:06:12 -08003930 /* If budget not fully consumed, exit the polling mode */
3931 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003932 if (likely(adapter->itr_setting & 3))
3933 e1000_set_itr(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003934 netif_rx_complete(poll_dev, napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 }
3937
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003938 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939}
3940
3941#endif
3942/**
3943 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3944 * @adapter: board private structure
3945 **/
3946
Joe Perches64798842008-07-11 15:17:02 -07003947static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3948 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 struct net_device *netdev = adapter->netdev;
3951 struct e1000_tx_desc *tx_desc, *eop_desc;
3952 struct e1000_buffer *buffer_info;
3953 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003954#ifdef CONFIG_E1000_NAPI
3955 unsigned int count = 0;
3956#endif
Joe Perchesc3033b02008-03-21 11:06:25 -07003957 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003958 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959
3960 i = tx_ring->next_to_clean;
3961 eop = tx_ring->buffer_info[i].next_to_watch;
3962 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3963
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003964 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Joe Perchesc3033b02008-03-21 11:06:25 -07003965 for (cleaned = false; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 tx_desc = E1000_TX_DESC(*tx_ring, i);
3967 buffer_info = &tx_ring->buffer_info[i];
3968 cleaned = (i == eop);
3969
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003970 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003971 struct sk_buff *skb = buffer_info->skb;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003972 unsigned int segs, bytecount;
3973 segs = skb_shinfo(skb)->gso_segs ?: 1;
3974 /* multiply data chunks by size of headers */
3975 bytecount = ((segs - 1) * skb_headlen(skb)) +
3976 skb->len;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003977 total_tx_packets += segs;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003978 total_tx_bytes += bytecount;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003979 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05003980 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003981 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003983 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003985
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 eop = tx_ring->buffer_info[i].next_to_watch;
3987 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003988#ifdef CONFIG_E1000_NAPI
3989#define E1000_TX_WEIGHT 64
3990 /* weight of a sort for tx, to avoid endless transmit cleanup */
Linus Torvalds46fcc862007-04-19 18:21:01 -07003991 if (count++ == E1000_TX_WEIGHT) break;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003992#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 }
3994
3995 tx_ring->next_to_clean = i;
3996
Auke Kok77b2aad2006-04-14 19:05:25 -07003997#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003998 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3999 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
4000 /* Make sure that anybody stopping the queue after this
4001 * sees the new next_to_clean.
4002 */
4003 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004004 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07004005 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004006 ++adapter->restart_queue;
4007 }
Auke Kok77b2aad2006-04-14 19:05:25 -07004008 }
Malli Chilakala26483452005-04-28 19:44:46 -07004009
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004010 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07004011 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 * check with the clearing of time_stamp and movement of i */
Joe Perchesc3033b02008-03-21 11:06:25 -07004013 adapter->detect_tx_hung = false;
Jeff Kirsher392137f2006-01-12 16:50:57 -08004014 if (tx_ring->buffer_info[eop].dma &&
4015 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08004016 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004017 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08004018 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004019
4020 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07004021 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004022 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004023 " TDH <%x>\n"
4024 " TDT <%x>\n"
4025 " next_to_use <%x>\n"
4026 " next_to_clean <%x>\n"
4027 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004028 " time_stamp <%lx>\n"
4029 " next_to_watch <%x>\n"
4030 " jiffies <%lx>\n"
4031 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004032 (unsigned long)((tx_ring - adapter->tx_ring) /
4033 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004034 readl(adapter->hw.hw_addr + tx_ring->tdh),
4035 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004036 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08004037 tx_ring->next_to_clean,
4038 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004039 eop,
4040 jiffies,
4041 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004045 adapter->total_tx_bytes += total_tx_bytes;
4046 adapter->total_tx_packets += total_tx_packets;
Auke Kokef90e4e2007-11-13 20:49:15 -08004047 adapter->net_stats.tx_bytes += total_tx_bytes;
4048 adapter->net_stats.tx_packets += total_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 return cleaned;
4050}
4051
4052/**
4053 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004054 * @adapter: board private structure
4055 * @status_err: receive descriptor status and error fields
4056 * @csum: receive descriptor csum field
4057 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 **/
4059
Joe Perches64798842008-07-11 15:17:02 -07004060static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
4061 u32 csum, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062{
Joe Perches406874a2008-04-03 10:06:32 -07004063 u16 status = (u16)status_err;
4064 u8 errors = (u8)(status_err >> 24);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004065 skb->ip_summed = CHECKSUM_NONE;
4066
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004068 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004070 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004071 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004072 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004073 /* let the stack verify checksum errors */
4074 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 return;
4076 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004077 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004078 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
4079 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004080 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004082 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004083 return;
4084 }
4085 /* It must be a TCP or UDP packet with a valid checksum */
4086 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 /* TCP checksum is good */
4088 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004089 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
4090 /* IP fragment with UDP payload */
4091 /* Hardware complements the payload checksum, so we undo it
4092 * and then put the value in host order for further stack use.
4093 */
Al Viro3e188262007-12-11 19:49:39 +00004094 __sum16 sum = (__force __sum16)htons(csum);
4095 skb->csum = csum_unfold(~sum);
Patrick McHardy84fa7932006-08-29 16:44:56 -07004096 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004098 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099}
4100
4101/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004102 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 * @adapter: board private structure
4104 **/
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105#ifdef CONFIG_E1000_NAPI
Joe Perches64798842008-07-11 15:17:02 -07004106static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4107 struct e1000_rx_ring *rx_ring,
4108 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109#else
Joe Perches64798842008-07-11 15:17:02 -07004110static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4111 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112#endif
4113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 struct net_device *netdev = adapter->netdev;
4115 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004116 struct e1000_rx_desc *rx_desc, *next_rxd;
4117 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07004119 u32 length;
4120 u8 last_byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004122 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004123 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004124 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125
4126 i = rx_ring->next_to_clean;
4127 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004128 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004130 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004131 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004132 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004133
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004135 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 break;
4137 (*work_done)++;
4138#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08004139 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004140 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004141 buffer_info->skb = NULL;
4142
Jeff Kirsher30320be2006-03-02 18:21:57 -08004143 prefetch(skb->data - NET_IP_ALIGN);
4144
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004145 if (++i == rx_ring->count) i = 0;
4146 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004147 prefetch(next_rxd);
4148
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004149 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004150
Joe Perchesc3033b02008-03-21 11:06:25 -07004151 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004152 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004153 pci_unmap_single(pdev,
4154 buffer_info->dma,
4155 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 PCI_DMA_FROMDEVICE);
4157
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158 length = le16_to_cpu(rx_desc->length);
4159
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004160 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4161 /* All receives must fit into a single buffer */
4162 E1000_DBG("%s: Receive packet consumed multiple"
4163 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004164 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004165 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 goto next_desc;
4167 }
4168
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004169 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004171 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 rx_desc->errors, length, last_byte)) {
4173 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004174 e1000_tbi_adjust_stats(&adapter->hw,
4175 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 length, skb->data);
4177 spin_unlock_irqrestore(&adapter->stats_lock,
4178 flags);
4179 length--;
4180 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004181 /* recycle */
4182 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 goto next_desc;
4184 }
Auke Kok1cb58212006-04-18 12:31:04 -07004185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004187 /* adjust length to remove Ethernet CRC, this must be
4188 * done after the TBI_ACCEPT workaround above */
4189 length -= 4;
4190
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004191 /* probably a little skewed due to removing CRC */
4192 total_rx_bytes += length;
4193 total_rx_packets++;
4194
Jeff Kirshera292ca62006-01-12 16:51:30 -08004195 /* code added for copybreak, this should improve
4196 * performance for small packets with large amounts
4197 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004198 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004199 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004200 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004201 if (new_skb) {
4202 skb_reserve(new_skb, NET_IP_ALIGN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004203 skb_copy_to_linear_data_offset(new_skb,
4204 -NET_IP_ALIGN,
4205 (skb->data -
4206 NET_IP_ALIGN),
4207 (length +
4208 NET_IP_ALIGN));
Jeff Kirshera292ca62006-01-12 16:51:30 -08004209 /* save the skb in buffer_info as good */
4210 buffer_info->skb = skb;
4211 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004212 }
Auke Kok996695d2006-11-01 08:47:50 -08004213 /* else just continue with the old one */
4214 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004215 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004216 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217
4218 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004219 e1000_rx_checksum(adapter,
Joe Perches406874a2008-04-03 10:06:32 -07004220 (u32)(status) |
4221 ((u32)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004222 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004223
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 skb->protocol = eth_type_trans(skb, netdev);
4225#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004226 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08004227 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004229 le16_to_cpu(rx_desc->special));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 } else {
4231 netif_receive_skb(skb);
4232 }
4233#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004234 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004235 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 vlan_hwaccel_rx(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004237 le16_to_cpu(rx_desc->special));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238 } else {
4239 netif_rx(skb);
4240 }
4241#endif /* CONFIG_E1000_NAPI */
4242 netdev->last_rx = jiffies;
4243
4244next_desc:
4245 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004247 /* return some buffers to hardware, one at a time is too slow */
4248 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4249 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4250 cleaned_count = 0;
4251 }
4252
Jeff Kirsher30320be2006-03-02 18:21:57 -08004253 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004254 rx_desc = next_rxd;
4255 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004258
4259 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4260 if (cleaned_count)
4261 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004263 adapter->total_rx_packets += total_rx_packets;
4264 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004265 adapter->net_stats.rx_bytes += total_rx_bytes;
4266 adapter->net_stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 return cleaned;
4268}
4269
4270/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004271 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4272 * @adapter: board private structure
4273 **/
4274
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004275#ifdef CONFIG_E1000_NAPI
Joe Perches64798842008-07-11 15:17:02 -07004276static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4277 struct e1000_rx_ring *rx_ring,
4278 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004279#else
Joe Perches64798842008-07-11 15:17:02 -07004280static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4281 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004282#endif
4283{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004284 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004285 struct net_device *netdev = adapter->netdev;
4286 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004287 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004288 struct e1000_ps_page *ps_page;
4289 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07004290 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004291 unsigned int i, j;
Joe Perches406874a2008-04-03 10:06:32 -07004292 u32 length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004293 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004294 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004295 unsigned int total_rx_bytes=0, total_rx_packets=0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004296
4297 i = rx_ring->next_to_clean;
4298 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07004299 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07004300 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004301
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004302 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004303 ps_page = &rx_ring->ps_page[i];
4304 ps_page_dma = &rx_ring->ps_page_dma[i];
4305#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004306 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004307 break;
4308 (*work_done)++;
4309#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004310 skb = buffer_info->skb;
4311
Jeff Kirsher30320be2006-03-02 18:21:57 -08004312 /* in the packet split case this is header only */
4313 prefetch(skb->data - NET_IP_ALIGN);
4314
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004315 if (++i == rx_ring->count) i = 0;
4316 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004317 prefetch(next_rxd);
4318
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004319 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004320
Joe Perchesc3033b02008-03-21 11:06:25 -07004321 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004322 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004323 pci_unmap_single(pdev, buffer_info->dma,
4324 buffer_info->length,
4325 PCI_DMA_FROMDEVICE);
4326
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004327 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004328 E1000_DBG("%s: Packet Split buffers didn't pick up"
4329 " the full packet\n", netdev->name);
4330 dev_kfree_skb_irq(skb);
4331 goto next_desc;
4332 }
4333
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004334 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004335 dev_kfree_skb_irq(skb);
4336 goto next_desc;
4337 }
4338
4339 length = le16_to_cpu(rx_desc->wb.middle.length0);
4340
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004341 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004342 E1000_DBG("%s: Last part of the packet spanning"
4343 " multiple descriptors\n", netdev->name);
4344 dev_kfree_skb_irq(skb);
4345 goto next_desc;
4346 }
4347
4348 /* Good Receive */
4349 skb_put(skb, length);
4350
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004351 {
4352 /* this looks ugly, but it seems compiler issues make it
4353 more efficient than reusing j */
4354 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4355
4356 /* page alloc/put takes too long and effects small packet
4357 * throughput, so unsplit small packets and save the alloc/put*/
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004358 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004359 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004360 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004361 * kmap_atomic, so we can't hold the mapping
4362 * very long */
4363 pci_dma_sync_single_for_cpu(pdev,
4364 ps_page_dma->ps_page_dma[0],
4365 PAGE_SIZE,
4366 PCI_DMA_FROMDEVICE);
4367 vaddr = kmap_atomic(ps_page->ps_page[0],
4368 KM_SKB_DATA_SOFTIRQ);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07004369 memcpy(skb_tail_pointer(skb), vaddr, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004370 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4371 pci_dma_sync_single_for_device(pdev,
4372 ps_page_dma->ps_page_dma[0],
4373 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004374 /* remove the CRC */
4375 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004376 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004377 goto copydone;
4378 } /* if */
4379 }
Auke Kok90fb5132006-11-01 08:47:30 -08004380
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004381 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004382 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004383 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004384 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4385 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4386 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004387 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4388 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004389 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004390 skb->len += length;
4391 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004392 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004393 }
4394
Auke Kokf235a2a2006-07-14 16:14:34 -07004395 /* strip the ethernet crc, problem is we're using pages now so
4396 * this whole operation can get a little cpu intensive */
4397 pskb_trim(skb, skb->len - 4);
4398
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004399copydone:
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004400 total_rx_bytes += skb->len;
4401 total_rx_packets++;
4402
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004403 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004404 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004405 skb->protocol = eth_type_trans(skb, netdev);
4406
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004407 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004408 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004409 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004410#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004411 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004412 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004413 le16_to_cpu(rx_desc->wb.middle.vlan));
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004414 } else {
4415 netif_receive_skb(skb);
4416 }
4417#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004418 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004419 vlan_hwaccel_rx(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004420 le16_to_cpu(rx_desc->wb.middle.vlan));
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004421 } else {
4422 netif_rx(skb);
4423 }
4424#endif /* CONFIG_E1000_NAPI */
4425 netdev->last_rx = jiffies;
4426
4427next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004428 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004429 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004430
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004431 /* return some buffers to hardware, one at a time is too slow */
4432 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4433 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4434 cleaned_count = 0;
4435 }
4436
Jeff Kirsher30320be2006-03-02 18:21:57 -08004437 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004438 rx_desc = next_rxd;
4439 buffer_info = next_buffer;
4440
Malli Chilakala683a38f2005-06-17 17:43:25 -07004441 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004442 }
4443 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004444
4445 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4446 if (cleaned_count)
4447 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004448
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004449 adapter->total_rx_packets += total_rx_packets;
4450 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004451 adapter->net_stats.rx_bytes += total_rx_bytes;
4452 adapter->net_stats.rx_packets += total_rx_packets;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004453 return cleaned;
4454}
4455
4456/**
4457 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 * @adapter: address of board private structure
4459 **/
4460
Joe Perches64798842008-07-11 15:17:02 -07004461static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4462 struct e1000_rx_ring *rx_ring,
4463 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 struct net_device *netdev = adapter->netdev;
4466 struct pci_dev *pdev = adapter->pdev;
4467 struct e1000_rx_desc *rx_desc;
4468 struct e1000_buffer *buffer_info;
4469 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004470 unsigned int i;
4471 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472
4473 i = rx_ring->next_to_use;
4474 buffer_info = &rx_ring->buffer_info[i];
4475
Jeff Kirshera292ca62006-01-12 16:51:30 -08004476 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004477 skb = buffer_info->skb;
4478 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004479 skb_trim(skb, 0);
4480 goto map_skb;
4481 }
4482
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004483 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004484 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004486 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 break;
4488 }
4489
Malli Chilakala26483452005-04-28 19:44:46 -07004490 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4492 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004493 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4494 "at %p\n", bufsz, skb->data);
4495 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004496 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004497 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498 if (!skb) {
4499 dev_kfree_skb(oldskb);
4500 break;
4501 }
Malli Chilakala26483452005-04-28 19:44:46 -07004502
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4504 /* give up */
4505 dev_kfree_skb(skb);
4506 dev_kfree_skb(oldskb);
4507 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004509
4510 /* Use new allocation */
4511 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 /* Make buffer alignment 2 beyond a 16 byte boundary
4514 * this will result in a 16 byte aligned IP header after
4515 * the 14 byte MAC header is removed
4516 */
4517 skb_reserve(skb, NET_IP_ALIGN);
4518
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 buffer_info->skb = skb;
4520 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004521map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522 buffer_info->dma = pci_map_single(pdev,
4523 skb->data,
4524 adapter->rx_buffer_len,
4525 PCI_DMA_FROMDEVICE);
4526
Malli Chilakala26483452005-04-28 19:44:46 -07004527 /* Fix for errata 23, can't cross 64kB boundary */
4528 if (!e1000_check_64k_bound(adapter,
4529 (void *)(unsigned long)buffer_info->dma,
4530 adapter->rx_buffer_len)) {
4531 DPRINTK(RX_ERR, ERR,
4532 "dma align check failed: %u bytes at %p\n",
4533 adapter->rx_buffer_len,
4534 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535 dev_kfree_skb(skb);
4536 buffer_info->skb = NULL;
4537
Malli Chilakala26483452005-04-28 19:44:46 -07004538 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539 adapter->rx_buffer_len,
4540 PCI_DMA_FROMDEVICE);
4541
4542 break; /* while !buffer_info->skb */
4543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 rx_desc = E1000_RX_DESC(*rx_ring, i);
4545 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4546
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004547 if (unlikely(++i == rx_ring->count))
4548 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 buffer_info = &rx_ring->buffer_info[i];
4550 }
4551
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004552 if (likely(rx_ring->next_to_use != i)) {
4553 rx_ring->next_to_use = i;
4554 if (unlikely(i-- == 0))
4555 i = (rx_ring->count - 1);
4556
4557 /* Force memory writes to complete before letting h/w
4558 * know there are new descriptors to fetch. (Only
4559 * applicable for weak-ordered memory model archs,
4560 * such as IA-64). */
4561 wmb();
4562 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564}
4565
4566/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004567 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4568 * @adapter: address of board private structure
4569 **/
4570
Joe Perches64798842008-07-11 15:17:02 -07004571static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
4572 struct e1000_rx_ring *rx_ring,
4573 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004574{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004575 struct net_device *netdev = adapter->netdev;
4576 struct pci_dev *pdev = adapter->pdev;
4577 union e1000_rx_desc_packet_split *rx_desc;
4578 struct e1000_buffer *buffer_info;
4579 struct e1000_ps_page *ps_page;
4580 struct e1000_ps_page_dma *ps_page_dma;
4581 struct sk_buff *skb;
4582 unsigned int i, j;
4583
4584 i = rx_ring->next_to_use;
4585 buffer_info = &rx_ring->buffer_info[i];
4586 ps_page = &rx_ring->ps_page[i];
4587 ps_page_dma = &rx_ring->ps_page_dma[i];
4588
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004589 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004590 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4591
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004592 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004593 if (j < adapter->rx_ps_pages) {
4594 if (likely(!ps_page->ps_page[j])) {
4595 ps_page->ps_page[j] =
4596 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004597 if (unlikely(!ps_page->ps_page[j])) {
4598 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004599 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004600 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004601 ps_page_dma->ps_page_dma[j] =
4602 pci_map_page(pdev,
4603 ps_page->ps_page[j],
4604 0, PAGE_SIZE,
4605 PCI_DMA_FROMDEVICE);
4606 }
4607 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004608 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004609 * this info.
4610 */
4611 rx_desc->read.buffer_addr[j+1] =
4612 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4613 } else
Al Viro3e188262007-12-11 19:49:39 +00004614 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004615 }
4616
David S. Miller87f50322006-07-31 22:39:40 -07004617 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004618 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004619
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004620 if (unlikely(!skb)) {
4621 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004622 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004623 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004624
4625 /* Make buffer alignment 2 beyond a 16 byte boundary
4626 * this will result in a 16 byte aligned IP header after
4627 * the 14 byte MAC header is removed
4628 */
4629 skb_reserve(skb, NET_IP_ALIGN);
4630
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004631 buffer_info->skb = skb;
4632 buffer_info->length = adapter->rx_ps_bsize0;
4633 buffer_info->dma = pci_map_single(pdev, skb->data,
4634 adapter->rx_ps_bsize0,
4635 PCI_DMA_FROMDEVICE);
4636
4637 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4638
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004639 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004640 buffer_info = &rx_ring->buffer_info[i];
4641 ps_page = &rx_ring->ps_page[i];
4642 ps_page_dma = &rx_ring->ps_page_dma[i];
4643 }
4644
4645no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004646 if (likely(rx_ring->next_to_use != i)) {
4647 rx_ring->next_to_use = i;
4648 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4649
4650 /* Force memory writes to complete before letting h/w
4651 * know there are new descriptors to fetch. (Only
4652 * applicable for weak-ordered memory model archs,
4653 * such as IA-64). */
4654 wmb();
4655 /* Hardware increments by 16 bytes, but packet split
4656 * descriptors are 32 bytes...so we increment tail
4657 * twice as much.
4658 */
4659 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4660 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004661}
4662
4663/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4665 * @adapter:
4666 **/
4667
Joe Perches64798842008-07-11 15:17:02 -07004668static void e1000_smartspeed(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669{
Joe Perches406874a2008-04-03 10:06:32 -07004670 u16 phy_status;
4671 u16 phy_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004673 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4675 return;
4676
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004677 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678 /* If Master/Slave config fault is asserted twice,
4679 * we assume back-to-back */
4680 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004681 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004683 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004685 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4687 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4688 phy_ctrl);
4689 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004690 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4692 &phy_ctrl)) {
4693 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4694 MII_CR_RESTART_AUTO_NEG);
4695 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4696 phy_ctrl);
4697 }
4698 }
4699 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004700 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 /* If still no link, perhaps using 2/3 pair cable */
4702 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4703 phy_ctrl |= CR_1000T_MS_ENABLE;
4704 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004705 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4707 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4708 MII_CR_RESTART_AUTO_NEG);
4709 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4710 }
4711 }
4712 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004713 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714 adapter->smartspeed = 0;
4715}
4716
4717/**
4718 * e1000_ioctl -
4719 * @netdev:
4720 * @ifreq:
4721 * @cmd:
4722 **/
4723
Joe Perches64798842008-07-11 15:17:02 -07004724static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725{
4726 switch (cmd) {
4727 case SIOCGMIIPHY:
4728 case SIOCGMIIREG:
4729 case SIOCSMIIREG:
4730 return e1000_mii_ioctl(netdev, ifr, cmd);
4731 default:
4732 return -EOPNOTSUPP;
4733 }
4734}
4735
4736/**
4737 * e1000_mii_ioctl -
4738 * @netdev:
4739 * @ifreq:
4740 * @cmd:
4741 **/
4742
Joe Perches64798842008-07-11 15:17:02 -07004743static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4744 int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004746 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 struct mii_ioctl_data *data = if_mii(ifr);
4748 int retval;
Joe Perches406874a2008-04-03 10:06:32 -07004749 u16 mii_reg;
4750 u16 spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004751 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004753 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 return -EOPNOTSUPP;
4755
4756 switch (cmd) {
4757 case SIOCGMIIPHY:
4758 data->phy_id = adapter->hw.phy_addr;
4759 break;
4760 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004761 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004763 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004764 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004765 &data->val_out)) {
4766 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004768 }
4769 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 break;
4771 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004772 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004774 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 return -EFAULT;
4776 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004777 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004778 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004779 mii_reg)) {
4780 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004782 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004783 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Auke Kokdc86d322006-04-18 12:30:51 -07004784 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 switch (data->reg_num) {
4786 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004787 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004789 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790 adapter->hw.autoneg = 1;
4791 adapter->hw.autoneg_advertised = 0x2F;
4792 } else {
4793 if (mii_reg & 0x40)
4794 spddplx = SPEED_1000;
4795 else if (mii_reg & 0x2000)
4796 spddplx = SPEED_100;
4797 else
4798 spddplx = SPEED_10;
4799 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004800 ? DUPLEX_FULL :
4801 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 retval = e1000_set_spd_dplx(adapter,
4803 spddplx);
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004804 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805 return retval;
4806 }
Auke Kok2db10a02006-06-27 09:06:28 -07004807 if (netif_running(adapter->netdev))
4808 e1000_reinit_locked(adapter);
4809 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 e1000_reset(adapter);
4811 break;
4812 case M88E1000_PHY_SPEC_CTRL:
4813 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004814 if (e1000_phy_reset(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 return -EIO;
4816 break;
4817 }
4818 } else {
4819 switch (data->reg_num) {
4820 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004821 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004823 if (netif_running(adapter->netdev))
4824 e1000_reinit_locked(adapter);
4825 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 e1000_reset(adapter);
4827 break;
4828 }
4829 }
4830 break;
4831 default:
4832 return -EOPNOTSUPP;
4833 }
4834 return E1000_SUCCESS;
4835}
4836
Joe Perches64798842008-07-11 15:17:02 -07004837void e1000_pci_set_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838{
4839 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004840 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004842 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004843 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844}
4845
Joe Perches64798842008-07-11 15:17:02 -07004846void e1000_pci_clear_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847{
4848 struct e1000_adapter *adapter = hw->back;
4849
4850 pci_clear_mwi(adapter->pdev);
4851}
4852
Joe Perches64798842008-07-11 15:17:02 -07004853int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
Peter Oruba007755e2007-09-28 22:42:06 -07004854{
4855 struct e1000_adapter *adapter = hw->back;
4856 return pcix_get_mmrbc(adapter->pdev);
4857}
4858
Joe Perches64798842008-07-11 15:17:02 -07004859void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
Peter Oruba007755e2007-09-28 22:42:06 -07004860{
4861 struct e1000_adapter *adapter = hw->back;
4862 pcix_set_mmrbc(adapter->pdev, mmrbc);
4863}
4864
Joe Perches64798842008-07-11 15:17:02 -07004865s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004866{
4867 struct e1000_adapter *adapter = hw->back;
Joe Perches406874a2008-04-03 10:06:32 -07004868 u16 cap_offset;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004869
4870 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4871 if (!cap_offset)
4872 return -E1000_ERR_CONFIG;
4873
4874 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4875
4876 return E1000_SUCCESS;
4877}
4878
Joe Perches64798842008-07-11 15:17:02 -07004879void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880{
4881 outl(value, port);
4882}
4883
Joe Perches64798842008-07-11 15:17:02 -07004884static void e1000_vlan_rx_register(struct net_device *netdev,
4885 struct vlan_group *grp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004887 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07004888 u32 ctrl, rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004890 if (!test_bit(__E1000_DOWN, &adapter->flags))
4891 e1000_irq_disable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 adapter->vlgrp = grp;
4893
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004894 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 /* enable VLAN tag insert/strip */
4896 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4897 ctrl |= E1000_CTRL_VME;
4898 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4899
Auke Kokcd94dd02006-06-27 09:08:22 -07004900 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004901 /* enable VLAN receive filtering */
4902 rctl = E1000_READ_REG(&adapter->hw, RCTL);
Auke Kok90fb5132006-11-01 08:47:30 -08004903 rctl &= ~E1000_RCTL_CFIEN;
4904 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4905 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907 } else {
4908 /* disable VLAN tag insert/strip */
4909 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4910 ctrl &= ~E1000_CTRL_VME;
4911 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4912
Auke Kokcd94dd02006-06-27 09:08:22 -07004913 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004914 if (adapter->mng_vlan_id !=
Joe Perches406874a2008-04-03 10:06:32 -07004915 (u16)E1000_MNG_VLAN_NONE) {
Auke Kok90fb5132006-11-01 08:47:30 -08004916 e1000_vlan_rx_kill_vid(netdev,
4917 adapter->mng_vlan_id);
4918 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4919 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 }
4922
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004923 if (!test_bit(__E1000_DOWN, &adapter->flags))
4924 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925}
4926
Joe Perches64798842008-07-11 15:17:02 -07004927static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004929 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07004930 u32 vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004931
4932 if ((adapter->hw.mng_cookie.status &
4933 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4934 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004935 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 /* add VID to filter table */
4937 index = (vid >> 5) & 0x7F;
4938 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4939 vfta |= (1 << (vid & 0x1F));
4940 e1000_write_vfta(&adapter->hw, index, vfta);
4941}
4942
Joe Perches64798842008-07-11 15:17:02 -07004943static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004945 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07004946 u32 vfta, index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004948 if (!test_bit(__E1000_DOWN, &adapter->flags))
4949 e1000_irq_disable(adapter);
Dan Aloni5c15bde2007-03-02 20:44:51 -08004950 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004951 if (!test_bit(__E1000_DOWN, &adapter->flags))
4952 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004954 if ((adapter->hw.mng_cookie.status &
4955 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004956 (vid == adapter->mng_vlan_id)) {
4957 /* release control to f/w */
4958 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004959 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004960 }
4961
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 /* remove VID from filter table */
4963 index = (vid >> 5) & 0x7F;
4964 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4965 vfta &= ~(1 << (vid & 0x1F));
4966 e1000_write_vfta(&adapter->hw, index, vfta);
4967}
4968
Joe Perches64798842008-07-11 15:17:02 -07004969static void e1000_restore_vlan(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970{
4971 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4972
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004973 if (adapter->vlgrp) {
Joe Perches406874a2008-04-03 10:06:32 -07004974 u16 vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004975 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08004976 if (!vlan_group_get_device(adapter->vlgrp, vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977 continue;
4978 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4979 }
4980 }
4981}
4982
Joe Perches64798842008-07-11 15:17:02 -07004983int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984{
4985 adapter->hw.autoneg = 0;
4986
Malli Chilakala69213682005-06-17 17:44:20 -07004987 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004988 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004989 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4990 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4991 return -EINVAL;
4992 }
4993
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004994 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 case SPEED_10 + DUPLEX_HALF:
4996 adapter->hw.forced_speed_duplex = e1000_10_half;
4997 break;
4998 case SPEED_10 + DUPLEX_FULL:
4999 adapter->hw.forced_speed_duplex = e1000_10_full;
5000 break;
5001 case SPEED_100 + DUPLEX_HALF:
5002 adapter->hw.forced_speed_duplex = e1000_100_half;
5003 break;
5004 case SPEED_100 + DUPLEX_FULL:
5005 adapter->hw.forced_speed_duplex = e1000_100_full;
5006 break;
5007 case SPEED_1000 + DUPLEX_FULL:
5008 adapter->hw.autoneg = 1;
5009 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
5010 break;
5011 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5012 default:
Malli Chilakala26483452005-04-28 19:44:46 -07005013 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014 return -EINVAL;
5015 }
5016 return 0;
5017}
5018
Joe Perches64798842008-07-11 15:17:02 -07005019static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020{
5021 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005022 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07005023 u32 ctrl, ctrl_ext, rctl, status;
5024 u32 wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07005025#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08005026 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07005027#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028
5029 netif_device_detach(netdev);
5030
Auke Kok2db10a02006-06-27 09:06:28 -07005031 if (netif_running(netdev)) {
5032 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07005034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005036#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005037 retval = pci_save_state(pdev);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005038 if (retval)
5039 return retval;
5040#endif
5041
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005043 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 wufc &= ~E1000_WUFC_LNKC;
5045
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005046 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005048 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049
5050 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005051 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5053 rctl |= E1000_RCTL_MPE;
5054 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5055 }
5056
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005057 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5059 /* advertise wake from D3Cold */
5060 #define E1000_CTRL_ADVD3WUC 0x00100000
5061 /* phy power management enable */
5062 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5063 ctrl |= E1000_CTRL_ADVD3WUC |
5064 E1000_CTRL_EN_PHY_PWR_MGMT;
5065 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5066 }
5067
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005068 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 adapter->hw.media_type == e1000_media_type_internal_serdes) {
5070 /* keep the laser running in D3 */
5071 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
5072 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5073 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
5074 }
5075
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005076 /* Allow time for pending master requests to run */
5077 e1000_disable_pciex_master(&adapter->hw);
5078
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
5080 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07005081 pci_enable_wake(pdev, PCI_D3hot, 1);
5082 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 } else {
5084 E1000_WRITE_REG(&adapter->hw, WUC, 0);
5085 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07005086 pci_enable_wake(pdev, PCI_D3hot, 0);
5087 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 }
5089
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005090 e1000_release_manageability(adapter);
5091
5092 /* make sure adapter isn't asleep if manageability is enabled */
5093 if (adapter->en_mng_pt) {
5094 pci_enable_wake(pdev, PCI_D3hot, 1);
5095 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096 }
5097
Auke Kokcd94dd02006-06-27 09:08:22 -07005098 if (adapter->hw.phy_type == e1000_phy_igp_3)
5099 e1000_phy_powerdown_workaround(&adapter->hw);
5100
Auke Kokedd106f2006-11-06 08:57:12 -08005101 if (netif_running(netdev))
5102 e1000_free_irq(adapter);
5103
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005104 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5105 * would have already happened in close and is redundant. */
5106 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005107
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005109
Auke Kokd0e027d2006-04-14 19:04:40 -07005110 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111
5112 return 0;
5113}
5114
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005115#ifdef CONFIG_PM
Joe Perches64798842008-07-11 15:17:02 -07005116static int e1000_resume(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117{
5118 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005119 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches406874a2008-04-03 10:06:32 -07005120 u32 err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121
Auke Kokd0e027d2006-04-14 19:04:40 -07005122 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005123 pci_restore_state(pdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005124 if ((err = pci_enable_device(pdev))) {
5125 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5126 return err;
5127 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005128 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129
Auke Kokd0e027d2006-04-14 19:04:40 -07005130 pci_enable_wake(pdev, PCI_D3hot, 0);
5131 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132
Auke Kokedd106f2006-11-06 08:57:12 -08005133 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
5134 return err;
5135
5136 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137 e1000_reset(adapter);
5138 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5139
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005140 e1000_init_manageability(adapter);
5141
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005142 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 e1000_up(adapter);
5144
5145 netif_device_attach(netdev);
5146
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005147 /* If the controller is 82573 and f/w is AMT, do not set
5148 * DRV_LOAD until the interface is up. For all other cases,
5149 * let the f/w know that the h/w is now under the control
5150 * of the driver. */
5151 if (adapter->hw.mac_type != e1000_82573 ||
5152 !e1000_check_mng_mode(&adapter->hw))
5153 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005154
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 return 0;
5156}
5157#endif
Auke Kokc653e632006-05-23 13:35:57 -07005158
5159static void e1000_shutdown(struct pci_dev *pdev)
5160{
5161 e1000_suspend(pdev, PMSG_SUSPEND);
5162}
5163
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164#ifdef CONFIG_NET_POLL_CONTROLLER
5165/*
5166 * Polling 'interrupt' - used by things like netconsole to send skbs
5167 * without having to re-enable interrupts. It's not called while
5168 * the interrupt routine is executing.
5169 */
Joe Perches64798842008-07-11 15:17:02 -07005170static void e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005172 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005173
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005175 e1000_intr(adapter->pdev->irq, netdev);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08005176#ifndef CONFIG_E1000_NAPI
5177 adapter->clean_rx(adapter, adapter->rx_ring);
5178#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179 enable_irq(adapter->pdev->irq);
5180}
5181#endif
5182
Auke Kok90267292006-06-08 09:30:24 -07005183/**
5184 * e1000_io_error_detected - called when PCI error is detected
5185 * @pdev: Pointer to PCI device
5186 * @state: The current pci conneection state
5187 *
5188 * This function is called after a PCI bus error affecting
5189 * this device has been detected.
5190 */
Joe Perches64798842008-07-11 15:17:02 -07005191static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5192 pci_channel_state_t state)
Auke Kok90267292006-06-08 09:30:24 -07005193{
5194 struct net_device *netdev = pci_get_drvdata(pdev);
5195 struct e1000_adapter *adapter = netdev->priv;
5196
5197 netif_device_detach(netdev);
5198
5199 if (netif_running(netdev))
5200 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005201 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005202
5203 /* Request a slot slot reset. */
5204 return PCI_ERS_RESULT_NEED_RESET;
5205}
5206
5207/**
5208 * e1000_io_slot_reset - called after the pci bus has been reset.
5209 * @pdev: Pointer to PCI device
5210 *
5211 * Restart the card from scratch, as if from a cold-boot. Implementation
5212 * resembles the first-half of the e1000_resume routine.
5213 */
5214static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5215{
5216 struct net_device *netdev = pci_get_drvdata(pdev);
5217 struct e1000_adapter *adapter = netdev->priv;
5218
5219 if (pci_enable_device(pdev)) {
5220 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5221 return PCI_ERS_RESULT_DISCONNECT;
5222 }
5223 pci_set_master(pdev);
5224
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005225 pci_enable_wake(pdev, PCI_D3hot, 0);
5226 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005227
Auke Kok90267292006-06-08 09:30:24 -07005228 e1000_reset(adapter);
5229 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5230
5231 return PCI_ERS_RESULT_RECOVERED;
5232}
5233
5234/**
5235 * e1000_io_resume - called when traffic can start flowing again.
5236 * @pdev: Pointer to PCI device
5237 *
5238 * This callback is called when the error recovery driver tells us that
5239 * its OK to resume normal operation. Implementation resembles the
5240 * second-half of the e1000_resume routine.
5241 */
5242static void e1000_io_resume(struct pci_dev *pdev)
5243{
5244 struct net_device *netdev = pci_get_drvdata(pdev);
5245 struct e1000_adapter *adapter = netdev->priv;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005246
5247 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005248
5249 if (netif_running(netdev)) {
5250 if (e1000_up(adapter)) {
5251 printk("e1000: can't bring device back up after reset\n");
5252 return;
5253 }
5254 }
5255
5256 netif_device_attach(netdev);
5257
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005258 /* If the controller is 82573 and f/w is AMT, do not set
5259 * DRV_LOAD until the interface is up. For all other cases,
5260 * let the f/w know that the h/w is now under the control
5261 * of the driver. */
5262 if (adapter->hw.mac_type != e1000_82573 ||
5263 !e1000_check_mng_mode(&adapter->hw))
5264 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005265
Auke Kok90267292006-06-08 09:30:24 -07005266}
5267
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268/* e1000_main.c */