blob: d3665bc9bd4099121594c260220c92907283a4ad [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);
97int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
98int 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);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400139static boolean_t 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400144 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700146static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400147 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700148 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400150static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
151 struct e1000_rx_ring *rx_ring);
152static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
153 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400155static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800156 struct e1000_rx_ring *rx_ring,
157 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400158static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800159 struct e1000_rx_ring *rx_ring,
160 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
162static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
163 int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
165static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
166static void e1000_tx_timeout(struct net_device *dev);
David Howells65f27f32006-11-22 14:55:48 +0000167static void e1000_reset_task(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700169static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
170 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
173static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
174static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
175static 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
235static int __init
236e1000_init_module(void)
237{
238 int ret;
239 printk(KERN_INFO "%s - version %s\n",
240 e1000_driver_string, e1000_driver_version);
241
242 printk(KERN_INFO "%s\n", e1000_copyright);
243
Jeff Garzik29917622006-08-19 17:48:59 -0400244 ret = pci_register_driver(&e1000_driver);
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100245 if (copybreak != COPYBREAK_DEFAULT) {
246 if (copybreak == 0)
247 printk(KERN_INFO "e1000: copybreak disabled\n");
248 else
249 printk(KERN_INFO "e1000: copybreak enabled for "
250 "packets <= %u bytes\n", copybreak);
251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return ret;
253}
254
255module_init(e1000_init_module);
256
257/**
258 * e1000_exit_module - Driver Exit Cleanup Routine
259 *
260 * e1000_exit_module is called just before the driver is removed
261 * from memory.
262 **/
263
264static void __exit
265e1000_exit_module(void)
266{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 pci_unregister_driver(&e1000_driver);
268}
269
270module_exit(e1000_exit_module);
271
Auke Kok2db10a02006-06-27 09:06:28 -0700272static int e1000_request_irq(struct e1000_adapter *adapter)
273{
274 struct net_device *netdev = adapter->netdev;
Al Viro3e188262007-12-11 19:49:39 +0000275 irq_handler_t handler = e1000_intr;
Auke Koke94bd232007-05-16 01:49:46 -0700276 int irq_flags = IRQF_SHARED;
277 int err;
Auke Kok2db10a02006-06-27 09:06:28 -0700278
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800279 if (adapter->hw.mac_type >= e1000_82571) {
Auke Koke94bd232007-05-16 01:49:46 -0700280 adapter->have_msi = !pci_enable_msi(adapter->pdev);
281 if (adapter->have_msi) {
Al Viro3e188262007-12-11 19:49:39 +0000282 handler = e1000_intr_msi;
Auke Koke94bd232007-05-16 01:49:46 -0700283 irq_flags = 0;
Auke Kok2db10a02006-06-27 09:06:28 -0700284 }
285 }
Auke Koke94bd232007-05-16 01:49:46 -0700286
287 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
288 netdev);
289 if (err) {
290 if (adapter->have_msi)
291 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700292 DPRINTK(PROBE, ERR,
293 "Unable to allocate interrupt Error: %d\n", err);
Auke Koke94bd232007-05-16 01:49:46 -0700294 }
Auke Kok2db10a02006-06-27 09:06:28 -0700295
296 return err;
297}
298
299static void e1000_free_irq(struct e1000_adapter *adapter)
300{
301 struct net_device *netdev = adapter->netdev;
302
303 free_irq(adapter->pdev->irq, netdev);
304
Auke Kok2db10a02006-06-27 09:06:28 -0700305 if (adapter->have_msi)
306 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/**
310 * e1000_irq_disable - Mask off interrupt generation on the NIC
311 * @adapter: board private structure
312 **/
313
Auke Koke619d522006-04-14 19:04:52 -0700314static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315e1000_irq_disable(struct e1000_adapter *adapter)
316{
317 atomic_inc(&adapter->irq_sem);
318 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
319 E1000_WRITE_FLUSH(&adapter->hw);
320 synchronize_irq(adapter->pdev->irq);
321}
322
323/**
324 * e1000_irq_enable - Enable default interrupt generation settings
325 * @adapter: board private structure
326 **/
327
Auke Koke619d522006-04-14 19:04:52 -0700328static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329e1000_irq_enable(struct e1000_adapter *adapter)
330{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800331 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
333 E1000_WRITE_FLUSH(&adapter->hw);
334 }
335}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100336
337static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700338e1000_update_mng_vlan(struct e1000_adapter *adapter)
339{
340 struct net_device *netdev = adapter->netdev;
341 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
342 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800343 if (adapter->vlgrp) {
Dan Aloni5c15bde2007-03-02 20:44:51 -0800344 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800345 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700346 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
347 e1000_vlan_rx_add_vid(netdev, vid);
348 adapter->mng_vlan_id = vid;
349 } else
350 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800351
352 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
353 (vid != old_vid) &&
Dan Aloni5c15bde2007-03-02 20:44:51 -0800354 !vlan_group_get_device(adapter->vlgrp, old_vid))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700355 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800356 } else
357 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700358 }
359}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800360
361/**
362 * e1000_release_hw_control - release control of the h/w to f/w
363 * @adapter: address of board private structure
364 *
365 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
366 * For ASF and Pass Through versions of f/w this means that the
367 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800368 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700369 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800370 **/
371
Auke Koke619d522006-04-14 19:04:52 -0700372static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800373e1000_release_hw_control(struct e1000_adapter *adapter)
374{
375 uint32_t ctrl_ext;
376 uint32_t swsm;
377
378 /* Let firmware taken over control of h/w */
379 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800380 case e1000_82573:
381 swsm = E1000_READ_REG(&adapter->hw, SWSM);
382 E1000_WRITE_REG(&adapter->hw, SWSM,
383 swsm & ~E1000_SWSM_DRV_LOAD);
Bruce Allan31d76442007-03-06 08:57:24 -0800384 break;
385 case e1000_82571:
386 case e1000_82572:
387 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700388 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800389 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
Auke Kokcd94dd02006-06-27 09:08:22 -0700390 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
Bruce Allan31d76442007-03-06 08:57:24 -0800391 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700392 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800393 default:
394 break;
395 }
396}
397
398/**
399 * e1000_get_hw_control - get control of the h/w from f/w
400 * @adapter: address of board private structure
401 *
402 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700403 * For ASF and Pass Through versions of f/w this means that
404 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800405 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700406 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800407 **/
408
Auke Koke619d522006-04-14 19:04:52 -0700409static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800410e1000_get_hw_control(struct e1000_adapter *adapter)
411{
412 uint32_t ctrl_ext;
413 uint32_t swsm;
Auke Kok90fb5132006-11-01 08:47:30 -0800414
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800415 /* Let firmware know the driver has taken over */
416 switch (adapter->hw.mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800417 case e1000_82573:
418 swsm = E1000_READ_REG(&adapter->hw, SWSM);
419 E1000_WRITE_REG(&adapter->hw, SWSM,
420 swsm | E1000_SWSM_DRV_LOAD);
421 break;
Bruce Allan31d76442007-03-06 08:57:24 -0800422 case e1000_82571:
423 case e1000_82572:
424 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700425 case e1000_ich8lan:
Bruce Allan31d76442007-03-06 08:57:24 -0800426 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
427 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
428 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700429 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800430 default:
431 break;
432 }
433}
434
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500435static void
436e1000_init_manageability(struct e1000_adapter *adapter)
437{
438 if (adapter->en_mng_pt) {
439 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
440
441 /* disable hardware interception of ARP */
442 manc &= ~(E1000_MANC_ARP_EN);
443
444 /* enable receiving management packets to the host */
445 /* this will probably generate destination unreachable messages
446 * from the host OS, but the packets will be handled on SMBUS */
447 if (adapter->hw.has_manc2h) {
448 uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
449
450 manc |= E1000_MANC_EN_MNG2HOST;
451#define E1000_MNG2HOST_PORT_623 (1 << 5)
452#define E1000_MNG2HOST_PORT_664 (1 << 6)
453 manc2h |= E1000_MNG2HOST_PORT_623;
454 manc2h |= E1000_MNG2HOST_PORT_664;
455 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
456 }
457
458 E1000_WRITE_REG(&adapter->hw, MANC, manc);
459 }
460}
461
462static void
463e1000_release_manageability(struct e1000_adapter *adapter)
464{
465 if (adapter->en_mng_pt) {
466 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
467
468 /* re-enable hardware interception of ARP */
469 manc |= E1000_MANC_ARP_EN;
470
471 if (adapter->hw.has_manc2h)
472 manc &= ~E1000_MANC_EN_MNG2HOST;
473
474 /* don't explicitly have to mess with MANC2H since
475 * MANC has an enable disable that gates MANC2H */
476
477 E1000_WRITE_REG(&adapter->hw, MANC, manc);
478 }
479}
480
Auke Koke0aac5a2007-03-06 08:57:21 -0800481/**
482 * e1000_configure - configure the hardware for RX and TX
483 * @adapter = private board structure
484 **/
485static void e1000_configure(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
487 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700488 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Patrick McHardydb0ce502007-11-13 20:54:59 -0800490 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 e1000_restore_vlan(adapter);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500493 e1000_init_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 e1000_configure_tx(adapter);
496 e1000_setup_rctl(adapter);
497 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800498 /* call E1000_DESC_UNUSED which always leaves
499 * at least 1 descriptor unused to make sure
500 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800501 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800502 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800503 adapter->alloc_rx_buf(adapter, ring,
504 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800505 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800507 adapter->tx_queue_len = netdev->tx_queue_len;
Auke Koke0aac5a2007-03-06 08:57:21 -0800508}
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800509
Auke Koke0aac5a2007-03-06 08:57:21 -0800510int e1000_up(struct e1000_adapter *adapter)
511{
512 /* hardware has been reset, we need to reload some things */
513 e1000_configure(adapter);
Malli Chilakala5de55622005-04-28 19:39:30 -0700514
Auke Kok1314bbf2006-09-27 12:54:02 -0700515 clear_bit(__E1000_DOWN, &adapter->flags);
516
Auke Koke0aac5a2007-03-06 08:57:21 -0800517#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700518 napi_enable(&adapter->napi);
Auke Koke0aac5a2007-03-06 08:57:21 -0800519#endif
520 e1000_irq_enable(adapter);
521
Jesse Brandeburg79f3d392006-12-15 10:42:34 +0100522 /* fire a link change interrupt to start the watchdog */
523 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 return 0;
525}
526
Auke Kok79f05bf2006-06-27 09:06:32 -0700527/**
528 * e1000_power_up_phy - restore link in case the phy was powered down
529 * @adapter: address of board private structure
530 *
531 * The phy may be powered down to save power and turn off link when the
532 * driver is unloaded and wake on lan is not enabled (among others)
533 * *** this routine MUST be followed by a call to e1000_reset ***
534 *
535 **/
536
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700537void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700538{
539 uint16_t mii_reg = 0;
540
541 /* Just clear the power down bit to wake the phy back up */
542 if (adapter->hw.media_type == e1000_media_type_copper) {
543 /* according to the manual, the phy will retain its
544 * settings across a power-down/up cycle */
545 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
546 mii_reg &= ~MII_CR_POWER_DOWN;
547 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
548 }
549}
550
551static void e1000_power_down_phy(struct e1000_adapter *adapter)
552{
Bruce Allan61c25052006-09-27 12:53:54 -0700553 /* Power down the PHY so no link is implied when interface is down *
554 * The PHY cannot be powered down if any of the following is TRUE *
Auke Kok79f05bf2006-06-27 09:06:32 -0700555 * (a) WoL is enabled
556 * (b) AMT is active
557 * (c) SoL/IDER session is active */
558 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700559 adapter->hw.media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700560 uint16_t mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700561
562 switch (adapter->hw.mac_type) {
563 case e1000_82540:
564 case e1000_82545:
565 case e1000_82545_rev_3:
566 case e1000_82546:
567 case e1000_82546_rev_3:
568 case e1000_82541:
569 case e1000_82541_rev_2:
570 case e1000_82547:
571 case e1000_82547_rev_2:
572 if (E1000_READ_REG(&adapter->hw, MANC) &
573 E1000_MANC_SMBUS_EN)
574 goto out;
575 break;
576 case e1000_82571:
577 case e1000_82572:
578 case e1000_82573:
579 case e1000_80003es2lan:
580 case e1000_ich8lan:
581 if (e1000_check_mng_mode(&adapter->hw) ||
582 e1000_check_phy_reset_block(&adapter->hw))
583 goto out;
584 break;
585 default:
586 goto out;
587 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700588 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
589 mii_reg |= MII_CR_POWER_DOWN;
590 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
591 mdelay(1);
592 }
Bruce Allan61c25052006-09-27 12:53:54 -0700593out:
594 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700595}
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597void
598e1000_down(struct e1000_adapter *adapter)
599{
600 struct net_device *netdev = adapter->netdev;
601
Auke Kok1314bbf2006-09-27 12:54:02 -0700602 /* signal that we're down so the interrupt handler does not
603 * reschedule our watchdog timer */
604 set_bit(__E1000_DOWN, &adapter->flags);
605
Auke Koke0aac5a2007-03-06 08:57:21 -0800606#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700607 napi_disable(&adapter->napi);
David S. Miller49d85c52008-01-18 04:21:39 -0800608 atomic_set(&adapter->irq_sem, 0);
Auke Koke0aac5a2007-03-06 08:57:21 -0800609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 del_timer_sync(&adapter->tx_fifo_stall_timer);
613 del_timer_sync(&adapter->watchdog_timer);
614 del_timer_sync(&adapter->phy_info_timer);
615
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800616 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 adapter->link_speed = 0;
618 adapter->link_duplex = 0;
619 netif_carrier_off(netdev);
620 netif_stop_queue(netdev);
621
622 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400623 e1000_clean_all_tx_rings(adapter);
624 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627void
Auke Kok2db10a02006-06-27 09:06:28 -0700628e1000_reinit_locked(struct e1000_adapter *adapter)
629{
630 WARN_ON(in_interrupt());
631 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
632 msleep(1);
633 e1000_down(adapter);
634 e1000_up(adapter);
635 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636}
637
638void
639e1000_reset(struct e1000_adapter *adapter)
640{
Bruce Allan018ea442006-12-15 10:39:45 +0100641 uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700642 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Bruce Allan018ea442006-12-15 10:39:45 +0100643 boolean_t legacy_pba_adjust = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 /* Repartition Pba for greater than 9k mtu
646 * To take effect CTRL.RST is required.
647 */
648
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700649 switch (adapter->hw.mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100650 case e1000_82542_rev2_0:
651 case e1000_82542_rev2_1:
652 case e1000_82543:
653 case e1000_82544:
654 case e1000_82540:
655 case e1000_82541:
656 case e1000_82541_rev_2:
657 legacy_pba_adjust = TRUE;
658 pba = E1000_PBA_48K;
659 break;
660 case e1000_82545:
661 case e1000_82545_rev_3:
662 case e1000_82546:
663 case e1000_82546_rev_3:
664 pba = E1000_PBA_48K;
665 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700666 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700667 case e1000_82547_rev_2:
Bruce Allan018ea442006-12-15 10:39:45 +0100668 legacy_pba_adjust = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700669 pba = E1000_PBA_30K;
670 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400671 case e1000_82571:
672 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800673 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400674 pba = E1000_PBA_38K;
675 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700676 case e1000_82573:
Bruce Allan018ea442006-12-15 10:39:45 +0100677 pba = E1000_PBA_20K;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700678 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700679 case e1000_ich8lan:
680 pba = E1000_PBA_8K;
Bruce Allan018ea442006-12-15 10:39:45 +0100681 case e1000_undefined:
682 case e1000_num_macs:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700683 break;
684 }
685
Bruce Allan018ea442006-12-15 10:39:45 +0100686 if (legacy_pba_adjust == TRUE) {
687 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
688 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700689
Bruce Allan018ea442006-12-15 10:39:45 +0100690 if (adapter->hw.mac_type == e1000_82547) {
691 adapter->tx_fifo_head = 0;
692 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
693 adapter->tx_fifo_size =
694 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
695 atomic_set(&adapter->tx_fifo_stall, 0);
696 }
697 } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
698 /* adjust PBA for jumbo frames */
699 E1000_WRITE_REG(&adapter->hw, PBA, pba);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700700
Bruce Allan018ea442006-12-15 10:39:45 +0100701 /* To maintain wire speed transmits, the Tx FIFO should be
702 * large enough to accomodate two full transmit packets,
703 * rounded up to the next 1KB and expressed in KB. Likewise,
704 * the Rx FIFO should be large enough to accomodate at least
705 * one full receive packet and is similarly rounded up and
706 * expressed in KB. */
707 pba = E1000_READ_REG(&adapter->hw, PBA);
708 /* upper 16 bits has Tx packet buffer allocation size in KB */
709 tx_space = pba >> 16;
710 /* lower 16 bits has Rx packet buffer allocation size in KB */
711 pba &= 0xffff;
712 /* don't include ethernet FCS because hardware appends/strips */
713 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
714 VLAN_TAG_SIZE;
715 min_tx_space = min_rx_space;
716 min_tx_space *= 2;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700717 min_tx_space = ALIGN(min_tx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100718 min_tx_space >>= 10;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700719 min_rx_space = ALIGN(min_rx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100720 min_rx_space >>= 10;
721
722 /* If current Tx allocation is less than the min Tx FIFO size,
723 * and the min Tx FIFO size is less than the current Rx FIFO
724 * allocation, take space away from current Rx allocation */
725 if (tx_space < min_tx_space &&
726 ((min_tx_space - tx_space) < pba)) {
727 pba = pba - (min_tx_space - tx_space);
728
729 /* PCI/PCIx hardware has PBA alignment constraints */
730 switch (adapter->hw.mac_type) {
731 case e1000_82545 ... e1000_82546_rev_3:
732 pba &= ~(E1000_PBA_8K - 1);
733 break;
734 default:
735 break;
736 }
737
738 /* if short on rx space, rx wins and must trump tx
739 * adjustment or use Early Receive if available */
740 if (pba < min_rx_space) {
741 switch (adapter->hw.mac_type) {
742 case e1000_82573:
743 /* ERT enabled in e1000_configure_rx */
744 break;
745 default:
746 pba = min_rx_space;
747 break;
748 }
749 }
750 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 E1000_WRITE_REG(&adapter->hw, PBA, pba);
754
755 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800756 /* Set the FC high water mark to 90% of the FIFO size.
757 * Required to clear last 3 LSB */
758 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700759 /* We can't use 90% on small FIFOs because the remainder
760 * would be less than 1 full frame. In this case, we size
761 * it to allow at least a full frame above the high water
762 * mark. */
763 if (pba < E1000_PBA_16K)
764 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800765
766 adapter->hw.fc_high_water = fc_high_water_mark;
767 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800768 if (adapter->hw.mac_type == e1000_80003es2lan)
769 adapter->hw.fc_pause_time = 0xFFFF;
770 else
771 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 adapter->hw.fc_send_xon = 1;
773 adapter->hw.fc = adapter->hw.original_fc;
774
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700775 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800777 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700779
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800780 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700782 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100783
784 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
785 if (adapter->hw.mac_type >= e1000_82544 &&
786 adapter->hw.mac_type <= e1000_82547_rev_2 &&
787 adapter->hw.autoneg == 1 &&
788 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
789 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
790 /* clear phy power management bit if we are in gig only mode,
791 * which if enabled will attempt negotiation to 100Mb, which
792 * can cause a loss of link at power off or driver unload */
793 ctrl &= ~E1000_CTRL_SWDPIN3;
794 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
795 }
796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
798 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
799
800 e1000_reset_adaptive(&adapter->hw);
801 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700802
803 if (!adapter->smart_power_down &&
804 (adapter->hw.mac_type == e1000_82571 ||
805 adapter->hw.mac_type == e1000_82572)) {
806 uint16_t phy_data = 0;
807 /* speed up time to link by disabling smart power down, ignore
808 * the return value of this function because there is nothing
809 * different we would do if it failed */
810 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
811 &phy_data);
812 phy_data &= ~IGP02E1000_PM_SPD;
813 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
814 phy_data);
815 }
816
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500817 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
820/**
821 * e1000_probe - Device Initialization Routine
822 * @pdev: PCI device information struct
823 * @ent: entry in e1000_pci_tbl
824 *
825 * Returns 0 on success, negative on failure
826 *
827 * e1000_probe initializes an adapter identified by a pci_dev structure.
828 * The OS initialization, configuring of the adapter private structure,
829 * and a hardware reset occur.
830 **/
831
832static int __devinit
833e1000_probe(struct pci_dev *pdev,
834 const struct pci_device_id *ent)
835{
836 struct net_device *netdev;
837 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700838 unsigned long mmio_start, mmio_len;
Auke Kokcd94dd02006-06-27 09:08:22 -0700839 unsigned long flash_start, flash_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700842 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700843 int i, err, pci_using_dac;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700844 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Joe Perches0795af52007-10-03 17:59:30 -0700846 DECLARE_MAC_BUF(mac);
847
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800848 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 return err;
850
Auke Kokcd94dd02006-06-27 09:08:22 -0700851 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
852 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 pci_using_dac = 1;
854 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700855 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
856 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700858 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 }
860 pci_using_dac = 0;
861 }
862
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800863 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700864 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 pci_set_master(pdev);
867
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700868 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700870 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 SET_NETDEV_DEV(netdev, &pdev->dev);
874
875 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700876 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 adapter->netdev = netdev;
878 adapter->pdev = pdev;
879 adapter->hw.back = adapter;
880 adapter->msg_enable = (1 << debug) - 1;
881
882 mmio_start = pci_resource_start(pdev, BAR_0);
883 mmio_len = pci_resource_len(pdev, BAR_0);
884
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700885 err = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700887 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800890 for (i = BAR_1; i <= BAR_5; i++) {
891 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800893 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 adapter->hw.io_base = pci_resource_start(pdev, i);
895 break;
896 }
897 }
898
899 netdev->open = &e1000_open;
900 netdev->stop = &e1000_close;
901 netdev->hard_start_xmit = &e1000_xmit_frame;
902 netdev->get_stats = &e1000_get_stats;
Patrick McHardydb0ce502007-11-13 20:54:59 -0800903 netdev->set_rx_mode = &e1000_set_rx_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 netdev->set_mac_address = &e1000_set_mac;
905 netdev->change_mtu = &e1000_change_mtu;
906 netdev->do_ioctl = &e1000_ioctl;
907 e1000_set_ethtool_ops(netdev);
908 netdev->tx_timeout = &e1000_tx_timeout;
909 netdev->watchdog_timeo = 5 * HZ;
910#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700911 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912#endif
913 netdev->vlan_rx_register = e1000_vlan_rx_register;
914 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
915 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
916#ifdef CONFIG_NET_POLL_CONTROLLER
917 netdev->poll_controller = e1000_netpoll;
918#endif
Auke Kok0eb5a342006-09-27 12:53:17 -0700919 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 netdev->mem_start = mmio_start;
922 netdev->mem_end = mmio_start + mmio_len;
923 netdev->base_addr = adapter->hw.io_base;
924
925 adapter->bd_number = cards_found;
926
927 /* setup the private structure */
928
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800929 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 goto err_sw_init;
931
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700932 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -0700933 /* Flash BAR mapping must happen after e1000_sw_init
934 * because it depends on mac_type */
935 if ((adapter->hw.mac_type == e1000_ich8lan) &&
936 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
937 flash_start = pci_resource_start(pdev, 1);
938 flash_len = pci_resource_len(pdev, 1);
939 adapter->hw.flash_address = ioremap(flash_start, flash_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700940 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -0700941 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -0700942 }
943
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700944 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700945 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
946
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800947 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 netdev->features = NETIF_F_SG |
949 NETIF_F_HW_CSUM |
950 NETIF_F_HW_VLAN_TX |
951 NETIF_F_HW_VLAN_RX |
952 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -0700953 if (adapter->hw.mac_type == e1000_ich8lan)
954 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 }
956
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800957 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 (adapter->hw.mac_type != e1000_82547))
959 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700960
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800961 if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -0800962 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800963 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 netdev->features |= NETIF_F_HIGHDMA;
965
Auke Kok76c224b2006-05-23 13:36:06 -0700966 netdev->features |= NETIF_F_LLTX;
967
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700968 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
969
Auke Kokcd94dd02006-06-27 09:08:22 -0700970 /* initialize eeprom parameters */
971
972 if (e1000_init_eeprom_params(&adapter->hw)) {
973 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700974 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -0700975 }
976
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800977 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 e1000_reset_hw(&adapter->hw);
981
982 /* make sure the EEPROM is good */
983
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800984 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 goto err_eeprom;
987 }
988
989 /* copy the MAC address out of the EEPROM */
990
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800991 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
993 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400994 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800996 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 goto err_eeprom;
999 }
1000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 e1000_get_bus_info(&adapter->hw);
1002
1003 init_timer(&adapter->tx_fifo_stall_timer);
1004 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
1005 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
1006
1007 init_timer(&adapter->watchdog_timer);
1008 adapter->watchdog_timer.function = &e1000_watchdog;
1009 adapter->watchdog_timer.data = (unsigned long) adapter;
1010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 init_timer(&adapter->phy_info_timer);
1012 adapter->phy_info_timer.function = &e1000_update_phy_info;
1013 adapter->phy_info_timer.data = (unsigned long) adapter;
1014
David Howells65f27f32006-11-22 14:55:48 +00001015 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 e1000_check_options(adapter);
1018
1019 /* Initial Wake on LAN setting
1020 * If APM wake is enabled in the EEPROM,
1021 * enable the ACPI Magic Packet filter
1022 */
1023
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001024 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 case e1000_82542_rev2_0:
1026 case e1000_82542_rev2_1:
1027 case e1000_82543:
1028 break;
1029 case e1000_82544:
1030 e1000_read_eeprom(&adapter->hw,
1031 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1032 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1033 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001034 case e1000_ich8lan:
1035 e1000_read_eeprom(&adapter->hw,
1036 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1037 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1038 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 case e1000_82546:
1040 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001041 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001042 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001043 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 e1000_read_eeprom(&adapter->hw,
1045 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1046 break;
1047 }
1048 /* Fall Through */
1049 default:
1050 e1000_read_eeprom(&adapter->hw,
1051 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1052 break;
1053 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001054 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001055 adapter->eeprom_wol |= E1000_WUFC_MAG;
1056
1057 /* now that we have the eeprom settings, apply the special cases
1058 * where the eeprom may be wrong or the board simply won't support
1059 * wake on lan on a particular port */
1060 switch (pdev->device) {
1061 case E1000_DEV_ID_82546GB_PCIE:
1062 adapter->eeprom_wol = 0;
1063 break;
1064 case E1000_DEV_ID_82546EB_FIBER:
1065 case E1000_DEV_ID_82546GB_FIBER:
1066 case E1000_DEV_ID_82571EB_FIBER:
1067 /* Wake events only supported on port A for dual fiber
1068 * regardless of eeprom setting */
1069 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
1070 adapter->eeprom_wol = 0;
1071 break;
1072 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001073 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001074 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001075 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001076 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001077 /* if quad port adapter, disable WoL on all but port A */
1078 if (global_quad_port_a != 0)
1079 adapter->eeprom_wol = 0;
1080 else
1081 adapter->quad_port_a = 1;
1082 /* Reset for multiple quad port adapters */
1083 if (++global_quad_port_a == 4)
1084 global_quad_port_a = 0;
1085 break;
1086 }
1087
1088 /* initialize the wol settings based on the eeprom settings */
1089 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001091 /* print bus type/speed/width info */
1092 {
1093 struct e1000_hw *hw = &adapter->hw;
1094 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1095 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1096 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1097 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1098 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1099 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1100 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1101 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1102 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1103 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1104 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1105 "32-bit"));
1106 }
1107
Joe Perches0795af52007-10-03 17:59:30 -07001108 printk("%s\n", print_mac(mac, netdev->dev_addr));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 /* reset the hardware with the new settings */
1111 e1000_reset(adapter);
1112
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001113 /* If the controller is 82573 and f/w is AMT, do not set
1114 * DRV_LOAD until the interface is up. For all other cases,
1115 * let the f/w know that the h/w is now under the control
1116 * of the driver. */
1117 if (adapter->hw.mac_type != e1000_82573 ||
1118 !e1000_check_mng_mode(&adapter->hw))
1119 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001120
Auke Kok1314bbf2006-09-27 12:54:02 -07001121 /* tell the stack to leave us alone until e1000_open() is called */
1122 netif_carrier_off(netdev);
1123 netif_stop_queue(netdev);
Auke Kok416b5d12007-06-01 10:22:39 -07001124
1125 strcpy(netdev->name, "eth%d");
1126 if ((err = register_netdev(netdev)))
1127 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1130
1131 cards_found++;
1132 return 0;
1133
1134err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001135 e1000_release_hw_control(adapter);
1136err_eeprom:
1137 if (!e1000_check_phy_reset_block(&adapter->hw))
1138 e1000_phy_hw_reset(&adapter->hw);
1139
Auke Kokcd94dd02006-06-27 09:08:22 -07001140 if (adapter->hw.flash_address)
1141 iounmap(adapter->hw.flash_address);
1142err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001143#ifdef CONFIG_E1000_NAPI
1144 for (i = 0; i < adapter->num_rx_queues; i++)
1145 dev_put(&adapter->polling_netdev[i]);
1146#endif
1147
1148 kfree(adapter->tx_ring);
1149 kfree(adapter->rx_ring);
1150#ifdef CONFIG_E1000_NAPI
1151 kfree(adapter->polling_netdev);
1152#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 iounmap(adapter->hw.hw_addr);
1155err_ioremap:
1156 free_netdev(netdev);
1157err_alloc_etherdev:
1158 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001159err_pci_reg:
1160err_dma:
1161 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 return err;
1163}
1164
1165/**
1166 * e1000_remove - Device Removal Routine
1167 * @pdev: PCI device information struct
1168 *
1169 * e1000_remove is called by the PCI subsystem to alert the driver
1170 * that it should release a PCI device. The could be caused by a
1171 * Hot-Plug event, or because the driver is going to be removed from
1172 * memory.
1173 **/
1174
1175static void __devexit
1176e1000_remove(struct pci_dev *pdev)
1177{
1178 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001179 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001180#ifdef CONFIG_E1000_NAPI
1181 int i;
1182#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Oleg Nesterov28e53bd2007-05-09 02:34:22 -07001184 cancel_work_sync(&adapter->reset_task);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001185
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001186 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001188 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1189 * would have already happened in close and is redundant. */
1190 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001191
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001192#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001193 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001194 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001195#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001197 unregister_netdev(netdev);
1198
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001199 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001200 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001202 kfree(adapter->tx_ring);
1203 kfree(adapter->rx_ring);
1204#ifdef CONFIG_E1000_NAPI
1205 kfree(adapter->polling_netdev);
1206#endif
1207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001209 if (adapter->hw.flash_address)
1210 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 pci_release_regions(pdev);
1212
1213 free_netdev(netdev);
1214
1215 pci_disable_device(pdev);
1216}
1217
1218/**
1219 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1220 * @adapter: board private structure to initialize
1221 *
1222 * e1000_sw_init initializes the Adapter private data structure.
1223 * Fields are initialized based on PCI device information and
1224 * OS network device settings (MTU size).
1225 **/
1226
1227static int __devinit
1228e1000_sw_init(struct e1000_adapter *adapter)
1229{
1230 struct e1000_hw *hw = &adapter->hw;
1231 struct net_device *netdev = adapter->netdev;
1232 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001233#ifdef CONFIG_E1000_NAPI
1234 int i;
1235#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
1237 /* PCI config space info */
1238
1239 hw->vendor_id = pdev->vendor;
1240 hw->device_id = pdev->device;
1241 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1242 hw->subsystem_id = pdev->subsystem_device;
Auke Kok44c10132007-06-08 15:46:36 -07001243 hw->revision_id = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
1245 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1246
Auke Kokeb0f8052006-07-14 16:14:48 -07001247 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001248 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 hw->max_frame_size = netdev->mtu +
1250 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1251 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1252
1253 /* identify the MAC */
1254
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001255 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1257 return -EIO;
1258 }
1259
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001260 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 default:
1262 break;
1263 case e1000_82541:
1264 case e1000_82547:
1265 case e1000_82541_rev_2:
1266 case e1000_82547_rev_2:
1267 hw->phy_init_script = 1;
1268 break;
1269 }
1270
1271 e1000_set_media_type(hw);
1272
1273 hw->wait_autoneg_complete = FALSE;
1274 hw->tbi_compatibility_en = TRUE;
1275 hw->adaptive_ifs = TRUE;
1276
1277 /* Copper options */
1278
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001279 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 hw->mdix = AUTO_ALL_MODES;
1281 hw->disable_polarity_correction = FALSE;
1282 hw->master_slave = E1000_MASTER_SLAVE;
1283 }
1284
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001285 adapter->num_tx_queues = 1;
1286 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001287
1288 if (e1000_alloc_queues(adapter)) {
1289 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1290 return -ENOMEM;
1291 }
1292
1293#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001294 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001295 adapter->polling_netdev[i].priv = adapter;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001296 dev_hold(&adapter->polling_netdev[i]);
1297 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1298 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001299 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001300#endif
1301
Herbert Xu47313052007-05-29 15:07:31 -07001302 /* Explicitly disable IRQ since the NIC can be in any state. */
1303 atomic_set(&adapter->irq_sem, 0);
1304 e1000_irq_disable(adapter);
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Auke Kok1314bbf2006-09-27 12:54:02 -07001308 set_bit(__E1000_DOWN, &adapter->flags);
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 return 0;
1311}
1312
1313/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001314 * e1000_alloc_queues - Allocate memory for all rings
1315 * @adapter: board private structure to initialize
1316 *
1317 * We allocate one ring per queue at run-time since we don't know the
1318 * number of queues at compile-time. The polling_netdev array is
1319 * intended for Multiqueue, but should work fine with a single queue.
1320 **/
1321
1322static int __devinit
1323e1000_alloc_queues(struct e1000_adapter *adapter)
1324{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001325 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1326 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001327 if (!adapter->tx_ring)
1328 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001329
Yan Burman1c7e5b12007-03-06 08:58:04 -08001330 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1331 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001332 if (!adapter->rx_ring) {
1333 kfree(adapter->tx_ring);
1334 return -ENOMEM;
1335 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001336
1337#ifdef CONFIG_E1000_NAPI
Yan Burman1c7e5b12007-03-06 08:58:04 -08001338 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1339 sizeof(struct net_device),
1340 GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001341 if (!adapter->polling_netdev) {
1342 kfree(adapter->tx_ring);
1343 kfree(adapter->rx_ring);
1344 return -ENOMEM;
1345 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001346#endif
1347
1348 return E1000_SUCCESS;
1349}
1350
1351/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 * e1000_open - Called when a network interface is made active
1353 * @netdev: network interface device structure
1354 *
1355 * Returns 0 on success, negative value on failure
1356 *
1357 * The open entry point is called when a network interface is made
1358 * active by the system (IFF_UP). At this point all resources needed
1359 * for transmit and receive operations are allocated, the interrupt
1360 * handler is registered with the OS, the watchdog timer is started,
1361 * and the stack is notified that the interface is ready.
1362 **/
1363
1364static int
1365e1000_open(struct net_device *netdev)
1366{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001367 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 int err;
1369
Auke Kok2db10a02006-06-27 09:06:28 -07001370 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001371 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001372 return -EBUSY;
1373
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001375 err = e1000_setup_all_tx_resources(adapter);
1376 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 goto err_setup_tx;
1378
1379 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001380 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001381 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001382 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001383
Auke Kok79f05bf2006-06-27 09:06:32 -07001384 e1000_power_up_phy(adapter);
1385
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001386 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001387 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001388 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1389 e1000_update_mng_vlan(adapter);
1390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001392 /* If AMT is enabled, let the firmware know that the network
1393 * interface is now open */
1394 if (adapter->hw.mac_type == e1000_82573 &&
1395 e1000_check_mng_mode(&adapter->hw))
1396 e1000_get_hw_control(adapter);
1397
Auke Koke0aac5a2007-03-06 08:57:21 -08001398 /* before we allocate an interrupt, we must be ready to handle it.
1399 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1400 * as soon as we call pci_request_irq, so we have to setup our
1401 * clean_rx handler before we do so. */
1402 e1000_configure(adapter);
1403
1404 err = e1000_request_irq(adapter);
1405 if (err)
1406 goto err_req_irq;
1407
1408 /* From here on the code is the same as e1000_up() */
1409 clear_bit(__E1000_DOWN, &adapter->flags);
1410
Herbert Xu47313052007-05-29 15:07:31 -07001411#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001412 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001413#endif
1414
Auke Koke0aac5a2007-03-06 08:57:21 -08001415 e1000_irq_enable(adapter);
1416
1417 /* fire a link status change interrupt to start the watchdog */
1418 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
1419
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 return E1000_SUCCESS;
1421
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001422err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001423 e1000_release_hw_control(adapter);
1424 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001425 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001427 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428err_setup_tx:
1429 e1000_reset(adapter);
1430
1431 return err;
1432}
1433
1434/**
1435 * e1000_close - Disables a network interface
1436 * @netdev: network interface device structure
1437 *
1438 * Returns 0, this is not allowed to fail
1439 *
1440 * The close entry point is called when an interface is de-activated
1441 * by the OS. The hardware is still under the drivers control, but
1442 * needs to be disabled. A global MAC reset is issued to stop the
1443 * hardware, and all transmit and receive resources are freed.
1444 **/
1445
1446static int
1447e1000_close(struct net_device *netdev)
1448{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001449 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Auke Kok2db10a02006-06-27 09:06:28 -07001451 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001453 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001454 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001456 e1000_free_all_tx_resources(adapter);
1457 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Bruce Allan46665602006-09-27 12:54:08 -07001459 /* kill manageability vlan ID if supported, but not if a vlan with
1460 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001461 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001462 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1463 !(adapter->vlgrp &&
Dan Aloni5c15bde2007-03-02 20:44:51 -08001464 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001465 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1466 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001467
1468 /* If AMT is enabled, let the firmware know that the network
1469 * interface is now closed */
1470 if (adapter->hw.mac_type == e1000_82573 &&
1471 e1000_check_mng_mode(&adapter->hw))
1472 e1000_release_hw_control(adapter);
1473
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 return 0;
1475}
1476
1477/**
1478 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1479 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001480 * @start: address of beginning of memory
1481 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 **/
Auke Koke619d522006-04-14 19:04:52 -07001483static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484e1000_check_64k_bound(struct e1000_adapter *adapter,
1485 void *start, unsigned long len)
1486{
1487 unsigned long begin = (unsigned long) start;
1488 unsigned long end = begin + len;
1489
Malli Chilakala26483452005-04-28 19:44:46 -07001490 /* First rev 82545 and 82546 need to not allow any memory
1491 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001493 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1495 }
1496
1497 return TRUE;
1498}
1499
1500/**
1501 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1502 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001503 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 *
1505 * Return 0 on success, negative on failure
1506 **/
1507
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001508static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001509e1000_setup_tx_resources(struct e1000_adapter *adapter,
1510 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 struct pci_dev *pdev = adapter->pdev;
1513 int size;
1514
1515 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001516 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001517 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001518 DPRINTK(PROBE, ERR,
1519 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 return -ENOMEM;
1521 }
1522 memset(txdr->buffer_info, 0, size);
1523
1524 /* round up to nearest 4K */
1525
1526 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001527 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001530 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001533 DPRINTK(PROBE, ERR,
1534 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 return -ENOMEM;
1536 }
1537
Malli Chilakala26483452005-04-28 19:44:46 -07001538 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1540 void *olddesc = txdr->desc;
1541 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001542 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1543 "at %p\n", txdr->size, txdr->desc);
1544 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001546 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001547 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1549 goto setup_tx_desc_die;
1550 }
1551
1552 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1553 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001554 pci_free_consistent(pdev, txdr->size, txdr->desc,
1555 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1557 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001558 "Unable to allocate aligned memory "
1559 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 vfree(txdr->buffer_info);
1561 return -ENOMEM;
1562 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001563 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1565 }
1566 }
1567 memset(txdr->desc, 0, txdr->size);
1568
1569 txdr->next_to_use = 0;
1570 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001571 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573 return 0;
1574}
1575
1576/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001577 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1578 * (Descriptors) for all queues
1579 * @adapter: board private structure
1580 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001581 * Return 0 on success, negative on failure
1582 **/
1583
1584int
1585e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1586{
1587 int i, err = 0;
1588
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001589 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001590 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1591 if (err) {
1592 DPRINTK(PROBE, ERR,
1593 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001594 for (i-- ; i >= 0; i--)
1595 e1000_free_tx_resources(adapter,
1596 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001597 break;
1598 }
1599 }
1600
1601 return err;
1602}
1603
1604/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1606 * @adapter: board private structure
1607 *
1608 * Configure the Tx unit of the MAC after a reset.
1609 **/
1610
1611static void
1612e1000_configure_tx(struct e1000_adapter *adapter)
1613{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001614 uint64_t tdba;
1615 struct e1000_hw *hw = &adapter->hw;
1616 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001617 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
1619 /* Setup the HW Tx Head and Tail descriptor pointers */
1620
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001621 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001622 case 1:
1623 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001624 tdba = adapter->tx_ring[0].dma;
1625 tdlen = adapter->tx_ring[0].count *
1626 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001627 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001628 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1629 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001630 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001631 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001632 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1633 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001634 break;
1635 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
1637 /* Set the default values for the Tx Inter Packet Gap timer */
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001638 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1639 (hw->media_type == e1000_media_type_fiber ||
1640 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001641 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1642 else
1643 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1644
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001645 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 case e1000_82542_rev2_0:
1647 case e1000_82542_rev2_1:
1648 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001649 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1650 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001652 case e1000_80003es2lan:
1653 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1654 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1655 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001657 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1658 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1659 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001661 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1662 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001663 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
1665 /* Set the Tx Interrupt Delay register */
1666
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001667 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1668 if (hw->mac_type >= e1000_82540)
1669 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 /* Program the Transmit Control Register */
1672
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001673 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001675 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1677
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001678 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1679 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001680 /* set the speed mode bit, we'll clear it if we're not at
1681 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001682 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001683 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001684 } else if (hw->mac_type == e1000_80003es2lan) {
1685 tarc = E1000_READ_REG(hw, TARC0);
1686 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001687 E1000_WRITE_REG(hw, TARC0, tarc);
1688 tarc = E1000_READ_REG(hw, TARC1);
1689 tarc |= 1;
1690 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001691 }
1692
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001693 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
1695 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001696 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1697
1698 /* only set IDE if we are delaying interrupts using the timers */
1699 if (adapter->tx_int_delay)
1700 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001702 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1704 else
1705 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1706
1707 /* Cache if we're 82544 running in PCI-X because we'll
1708 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001709 if (hw->mac_type == e1000_82544 &&
1710 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001712
1713 E1000_WRITE_REG(hw, TCTL, tctl);
1714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715}
1716
1717/**
1718 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1719 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001720 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 *
1722 * Returns 0 on success, negative on failure
1723 **/
1724
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001725static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001726e1000_setup_rx_resources(struct e1000_adapter *adapter,
1727 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001730 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
1732 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001733 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001734 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001735 DPRINTK(PROBE, ERR,
1736 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 return -ENOMEM;
1738 }
1739 memset(rxdr->buffer_info, 0, size);
1740
Yan Burman1c7e5b12007-03-06 08:58:04 -08001741 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1742 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001743 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001744 vfree(rxdr->buffer_info);
1745 DPRINTK(PROBE, ERR,
1746 "Unable to allocate memory for the receive descriptor ring\n");
1747 return -ENOMEM;
1748 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001749
Yan Burman1c7e5b12007-03-06 08:58:04 -08001750 rxdr->ps_page_dma = kcalloc(rxdr->count,
1751 sizeof(struct e1000_ps_page_dma),
1752 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001753 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001754 vfree(rxdr->buffer_info);
1755 kfree(rxdr->ps_page);
1756 DPRINTK(PROBE, ERR,
1757 "Unable to allocate memory for the receive descriptor ring\n");
1758 return -ENOMEM;
1759 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001760
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001761 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001762 desc_len = sizeof(struct e1000_rx_desc);
1763 else
1764 desc_len = sizeof(union e1000_rx_desc_packet_split);
1765
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 /* Round up to nearest 4K */
1767
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001768 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001769 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
1771 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1772
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001773 if (!rxdr->desc) {
1774 DPRINTK(PROBE, ERR,
1775 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001778 kfree(rxdr->ps_page);
1779 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 return -ENOMEM;
1781 }
1782
Malli Chilakala26483452005-04-28 19:44:46 -07001783 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1785 void *olddesc = rxdr->desc;
1786 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001787 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1788 "at %p\n", rxdr->size, rxdr->desc);
1789 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001791 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001792 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001794 DPRINTK(PROBE, ERR,
1795 "Unable to allocate memory "
1796 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 goto setup_rx_desc_die;
1798 }
1799
1800 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1801 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001802 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1803 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001805 DPRINTK(PROBE, ERR,
1806 "Unable to allocate aligned memory "
1807 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001808 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001810 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1812 }
1813 }
1814 memset(rxdr->desc, 0, rxdr->size);
1815
1816 rxdr->next_to_clean = 0;
1817 rxdr->next_to_use = 0;
1818
1819 return 0;
1820}
1821
1822/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001823 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1824 * (Descriptors) for all queues
1825 * @adapter: board private structure
1826 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001827 * Return 0 on success, negative on failure
1828 **/
1829
1830int
1831e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1832{
1833 int i, err = 0;
1834
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001835 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001836 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1837 if (err) {
1838 DPRINTK(PROBE, ERR,
1839 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001840 for (i-- ; i >= 0; i--)
1841 e1000_free_rx_resources(adapter,
1842 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001843 break;
1844 }
1845 }
1846
1847 return err;
1848}
1849
1850/**
Malli Chilakala26483452005-04-28 19:44:46 -07001851 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 * @adapter: Board private structure
1853 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001854#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1855 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856static void
1857e1000_setup_rctl(struct e1000_adapter *adapter)
1858{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001859 uint32_t rctl, rfctl;
1860 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001861#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001862 uint32_t pages = 0;
1863#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1866
1867 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1868
1869 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1870 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1871 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1872
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001873 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 rctl |= E1000_RCTL_SBP;
1875 else
1876 rctl &= ~E1000_RCTL_SBP;
1877
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001878 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1879 rctl &= ~E1000_RCTL_LPE;
1880 else
1881 rctl |= E1000_RCTL_LPE;
1882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001884 rctl &= ~E1000_RCTL_SZ_4096;
1885 rctl |= E1000_RCTL_BSEX;
1886 switch (adapter->rx_buffer_len) {
1887 case E1000_RXBUFFER_256:
1888 rctl |= E1000_RCTL_SZ_256;
1889 rctl &= ~E1000_RCTL_BSEX;
1890 break;
1891 case E1000_RXBUFFER_512:
1892 rctl |= E1000_RCTL_SZ_512;
1893 rctl &= ~E1000_RCTL_BSEX;
1894 break;
1895 case E1000_RXBUFFER_1024:
1896 rctl |= E1000_RCTL_SZ_1024;
1897 rctl &= ~E1000_RCTL_BSEX;
1898 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001899 case E1000_RXBUFFER_2048:
1900 default:
1901 rctl |= E1000_RCTL_SZ_2048;
1902 rctl &= ~E1000_RCTL_BSEX;
1903 break;
1904 case E1000_RXBUFFER_4096:
1905 rctl |= E1000_RCTL_SZ_4096;
1906 break;
1907 case E1000_RXBUFFER_8192:
1908 rctl |= E1000_RCTL_SZ_8192;
1909 break;
1910 case E1000_RXBUFFER_16384:
1911 rctl |= E1000_RCTL_SZ_16384;
1912 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001913 }
1914
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001915#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001916 /* 82571 and greater support packet-split where the protocol
1917 * header is placed in skb->data and the packet data is
1918 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1919 * In the case of a non-split, skb->data is linearly filled,
1920 * followed by the page buffers. Therefore, skb->data is
1921 * sized to hold the largest protocol header.
1922 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001923 /* allocations using alloc_page take too long for regular MTU
1924 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001925 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001926 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1927 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001928 adapter->rx_ps_pages = pages;
1929 else
1930 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001931#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001932 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001933 /* Configure extra packet-split registers */
1934 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1935 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08001936 /* disable packet split support for IPv6 extension headers,
1937 * because some malformed IPv6 headers can hang the RX */
1938 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1939 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1940
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001941 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1942
Auke Kok7dfee0c2006-06-27 09:07:50 -07001943 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001944
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001945 psrctl |= adapter->rx_ps_bsize0 >>
1946 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001947
1948 switch (adapter->rx_ps_pages) {
1949 case 3:
1950 psrctl |= PAGE_SIZE <<
1951 E1000_PSRCTL_BSIZE3_SHIFT;
1952 case 2:
1953 psrctl |= PAGE_SIZE <<
1954 E1000_PSRCTL_BSIZE2_SHIFT;
1955 case 1:
1956 psrctl |= PAGE_SIZE >>
1957 E1000_PSRCTL_BSIZE1_SHIFT;
1958 break;
1959 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001960
1961 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 }
1963
1964 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1965}
1966
1967/**
1968 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1969 * @adapter: board private structure
1970 *
1971 * Configure the Rx unit of the MAC after a reset.
1972 **/
1973
1974static void
1975e1000_configure_rx(struct e1000_adapter *adapter)
1976{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001977 uint64_t rdba;
1978 struct e1000_hw *hw = &adapter->hw;
1979 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001980
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001981 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001982 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001983 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001984 sizeof(union e1000_rx_desc_packet_split);
1985 adapter->clean_rx = e1000_clean_rx_irq_ps;
1986 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1987 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001988 rdlen = adapter->rx_ring[0].count *
1989 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001990 adapter->clean_rx = e1000_clean_rx_irq;
1991 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
1994 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001995 rctl = E1000_READ_REG(hw, RCTL);
1996 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
1998 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001999 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002001 if (hw->mac_type >= e1000_82540) {
2002 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002003 if (adapter->itr_setting != 0)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002004 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 1000000000 / (adapter->itr * 256));
2006 }
2007
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002008 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002009 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002010 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002011 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002012#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002013 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002014 ctrl_ext |= E1000_CTRL_EXT_IAME;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002015 E1000_WRITE_REG(hw, IAM, 0xffffffff);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002016#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002017 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2018 E1000_WRITE_FLUSH(hw);
2019 }
2020
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002021 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2022 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002023 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002024 case 1:
2025 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002026 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002027 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07002028 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
2029 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002030 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002031 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002032 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2033 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002034 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002035 }
2036
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002038 if (hw->mac_type >= e1000_82543) {
2039 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002040 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002041 rxcsum |= E1000_RXCSUM_TUOFL;
2042
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002043 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002044 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002045 if ((hw->mac_type >= e1000_82571) &&
2046 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002047 rxcsum |= E1000_RXCSUM_IPPCSE;
2048 }
2049 } else {
2050 rxcsum &= ~E1000_RXCSUM_TUOFL;
2051 /* don't need to clear IPPCSE as it defaults to 0 */
2052 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002053 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 }
2055
Auke Kok21c4d5e2006-11-01 08:47:39 -08002056 /* enable early receives on 82573, only takes effect if using > 2048
2057 * byte total frame size. for example only for jumbo frames */
2058#define E1000_ERT_2048 0x100
2059 if (hw->mac_type == e1000_82573)
2060 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
2061
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002063 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064}
2065
2066/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002067 * e1000_free_tx_resources - Free Tx Resources per Queue
2068 * @adapter: board private structure
2069 * @tx_ring: Tx descriptor ring for a specific queue
2070 *
2071 * Free all transmit software resources
2072 **/
2073
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002074static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002075e1000_free_tx_resources(struct e1000_adapter *adapter,
2076 struct e1000_tx_ring *tx_ring)
2077{
2078 struct pci_dev *pdev = adapter->pdev;
2079
2080 e1000_clean_tx_ring(adapter, tx_ring);
2081
2082 vfree(tx_ring->buffer_info);
2083 tx_ring->buffer_info = NULL;
2084
2085 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2086
2087 tx_ring->desc = NULL;
2088}
2089
2090/**
2091 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 * @adapter: board private structure
2093 *
2094 * Free all transmit software resources
2095 **/
2096
2097void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002098e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002100 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002102 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002103 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104}
2105
Auke Koke619d522006-04-14 19:04:52 -07002106static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2108 struct e1000_buffer *buffer_info)
2109{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002110 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07002111 pci_unmap_page(adapter->pdev,
2112 buffer_info->dma,
2113 buffer_info->length,
2114 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002115 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002117 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002119 buffer_info->skb = NULL;
2120 }
2121 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122}
2123
2124/**
2125 * e1000_clean_tx_ring - Free Tx Buffers
2126 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002127 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 **/
2129
2130static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002131e1000_clean_tx_ring(struct e1000_adapter *adapter,
2132 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 struct e1000_buffer *buffer_info;
2135 unsigned long size;
2136 unsigned int i;
2137
2138 /* Free all the Tx ring sk_buffs */
2139
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002140 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 buffer_info = &tx_ring->buffer_info[i];
2142 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2143 }
2144
2145 size = sizeof(struct e1000_buffer) * tx_ring->count;
2146 memset(tx_ring->buffer_info, 0, size);
2147
2148 /* Zero out the descriptor ring */
2149
2150 memset(tx_ring->desc, 0, tx_ring->size);
2151
2152 tx_ring->next_to_use = 0;
2153 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002154 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002156 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2157 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2158}
2159
2160/**
2161 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2162 * @adapter: board private structure
2163 **/
2164
2165static void
2166e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2167{
2168 int i;
2169
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002170 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002171 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172}
2173
2174/**
2175 * e1000_free_rx_resources - Free Rx Resources
2176 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002177 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 *
2179 * Free all receive software resources
2180 **/
2181
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002182static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002183e1000_free_rx_resources(struct e1000_adapter *adapter,
2184 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 struct pci_dev *pdev = adapter->pdev;
2187
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002188 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
2190 vfree(rx_ring->buffer_info);
2191 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002192 kfree(rx_ring->ps_page);
2193 rx_ring->ps_page = NULL;
2194 kfree(rx_ring->ps_page_dma);
2195 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
2197 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2198
2199 rx_ring->desc = NULL;
2200}
2201
2202/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002203 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002205 *
2206 * Free all receive software resources
2207 **/
2208
2209void
2210e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2211{
2212 int i;
2213
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002214 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002215 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2216}
2217
2218/**
2219 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2220 * @adapter: board private structure
2221 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 **/
2223
2224static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002225e1000_clean_rx_ring(struct e1000_adapter *adapter,
2226 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002229 struct e1000_ps_page *ps_page;
2230 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 struct pci_dev *pdev = adapter->pdev;
2232 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002233 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
2235 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002236 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002238 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 pci_unmap_single(pdev,
2240 buffer_info->dma,
2241 buffer_info->length,
2242 PCI_DMA_FROMDEVICE);
2243
2244 dev_kfree_skb(buffer_info->skb);
2245 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002246 }
2247 ps_page = &rx_ring->ps_page[i];
2248 ps_page_dma = &rx_ring->ps_page_dma[i];
2249 for (j = 0; j < adapter->rx_ps_pages; j++) {
2250 if (!ps_page->ps_page[j]) break;
2251 pci_unmap_page(pdev,
2252 ps_page_dma->ps_page_dma[j],
2253 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2254 ps_page_dma->ps_page_dma[j] = 0;
2255 put_page(ps_page->ps_page[j]);
2256 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 }
2258 }
2259
2260 size = sizeof(struct e1000_buffer) * rx_ring->count;
2261 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002262 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2263 memset(rx_ring->ps_page, 0, size);
2264 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2265 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
2267 /* Zero out the descriptor ring */
2268
2269 memset(rx_ring->desc, 0, rx_ring->size);
2270
2271 rx_ring->next_to_clean = 0;
2272 rx_ring->next_to_use = 0;
2273
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002274 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2275 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2276}
2277
2278/**
2279 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2280 * @adapter: board private structure
2281 **/
2282
2283static void
2284e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2285{
2286 int i;
2287
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002288 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002289 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290}
2291
2292/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2293 * and memory write and invalidate disabled for certain operations
2294 */
2295static void
2296e1000_enter_82542_rst(struct e1000_adapter *adapter)
2297{
2298 struct net_device *netdev = adapter->netdev;
2299 uint32_t rctl;
2300
2301 e1000_pci_clear_mwi(&adapter->hw);
2302
2303 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2304 rctl |= E1000_RCTL_RST;
2305 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2306 E1000_WRITE_FLUSH(&adapter->hw);
2307 mdelay(5);
2308
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002309 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002310 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311}
2312
2313static void
2314e1000_leave_82542_rst(struct e1000_adapter *adapter)
2315{
2316 struct net_device *netdev = adapter->netdev;
2317 uint32_t rctl;
2318
2319 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2320 rctl &= ~E1000_RCTL_RST;
2321 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2322 E1000_WRITE_FLUSH(&adapter->hw);
2323 mdelay(5);
2324
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002325 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 e1000_pci_set_mwi(&adapter->hw);
2327
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002328 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002329 /* No need to loop, because 82542 supports only 1 queue */
2330 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002331 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002332 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 }
2334}
2335
2336/**
2337 * e1000_set_mac - Change the Ethernet Address of the NIC
2338 * @netdev: network interface device structure
2339 * @p: pointer to an address structure
2340 *
2341 * Returns 0 on success, negative on failure
2342 **/
2343
2344static int
2345e1000_set_mac(struct net_device *netdev, void *p)
2346{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002347 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 struct sockaddr *addr = p;
2349
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002350 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 return -EADDRNOTAVAIL;
2352
2353 /* 82542 2.0 needs to be in reset to write receive address registers */
2354
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002355 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 e1000_enter_82542_rst(adapter);
2357
2358 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2359 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2360
2361 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2362
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002363 /* With 82571 controllers, LAA may be overwritten (with the default)
2364 * due to controller reset from the other port. */
2365 if (adapter->hw.mac_type == e1000_82571) {
2366 /* activate the work around */
2367 adapter->hw.laa_is_present = 1;
2368
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002369 /* Hold a copy of the LAA in RAR[14] This is done so that
2370 * between the time RAR[0] gets clobbered and the time it
2371 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002372 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002373 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002374 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002375 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002376 E1000_RAR_ENTRIES - 1);
2377 }
2378
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002379 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 e1000_leave_82542_rst(adapter);
2381
2382 return 0;
2383}
2384
2385/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002386 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 * @netdev: network interface device structure
2388 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002389 * The set_rx_mode entry point is called whenever the unicast or multicast
2390 * address lists or the network interface flags are updated. This routine is
2391 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 * promiscuous mode, and all-multi behavior.
2393 **/
2394
2395static void
Patrick McHardydb0ce502007-11-13 20:54:59 -08002396e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002398 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 struct e1000_hw *hw = &adapter->hw;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002400 struct dev_addr_list *uc_ptr;
2401 struct dev_addr_list *mc_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 uint32_t rctl;
2403 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002404 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002405 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2406 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2407 E1000_NUM_MTA_REGISTERS;
2408
2409 if (adapter->hw.mac_type == e1000_ich8lan)
2410 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002412 /* reserve RAR[14] for LAA over-write work-around */
2413 if (adapter->hw.mac_type == e1000_82571)
2414 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
Malli Chilakala26483452005-04-28 19:44:46 -07002416 /* Check for Promiscuous and All Multicast modes */
2417
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 rctl = E1000_READ_REG(hw, RCTL);
2419
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002420 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002422 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 rctl |= E1000_RCTL_MPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 } else {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002425 rctl &= ~E1000_RCTL_MPE;
2426 }
2427
2428 uc_ptr = NULL;
2429 if (netdev->uc_count > rar_entries - 1) {
2430 rctl |= E1000_RCTL_UPE;
2431 } else if (!(netdev->flags & IFF_PROMISC)) {
2432 rctl &= ~E1000_RCTL_UPE;
2433 uc_ptr = netdev->uc_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 }
2435
2436 E1000_WRITE_REG(hw, RCTL, rctl);
2437
2438 /* 82542 2.0 needs to be in reset to write receive address registers */
2439
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002440 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 e1000_enter_82542_rst(adapter);
2442
Patrick McHardydb0ce502007-11-13 20:54:59 -08002443 /* load the first 14 addresses into the exact filters 1-14. Unicast
2444 * addresses take precedence to avoid disabling unicast filtering
2445 * when possible.
2446 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 * RAR 0 is used for the station MAC adddress
2448 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002449 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 */
2451 mc_ptr = netdev->mc_list;
2452
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002453 for (i = 1; i < rar_entries; i++) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002454 if (uc_ptr) {
2455 e1000_rar_set(hw, uc_ptr->da_addr, i);
2456 uc_ptr = uc_ptr->next;
2457 } else if (mc_ptr) {
2458 e1000_rar_set(hw, mc_ptr->da_addr, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 mc_ptr = mc_ptr->next;
2460 } else {
2461 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002462 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002464 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 }
2466 }
Patrick McHardydb0ce502007-11-13 20:54:59 -08002467 WARN_ON(uc_ptr != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
2469 /* clear the old settings from the multicast hash table */
2470
Auke Kokcd94dd02006-06-27 09:08:22 -07002471 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002473 E1000_WRITE_FLUSH(hw);
2474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
2476 /* load any remaining addresses into the hash table */
2477
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002478 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002479 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 e1000_mta_set(hw, hash_value);
2481 }
2482
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002483 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485}
2486
2487/* Need to wait a few seconds after link up to get diagnostic information from
2488 * the phy */
2489
2490static void
2491e1000_update_phy_info(unsigned long data)
2492{
2493 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2494 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2495}
2496
2497/**
2498 * e1000_82547_tx_fifo_stall - Timer Call-back
2499 * @data: pointer to adapter cast into an unsigned long
2500 **/
2501
2502static void
2503e1000_82547_tx_fifo_stall(unsigned long data)
2504{
2505 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2506 struct net_device *netdev = adapter->netdev;
2507 uint32_t tctl;
2508
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002509 if (atomic_read(&adapter->tx_fifo_stall)) {
2510 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 E1000_READ_REG(&adapter->hw, TDH)) &&
2512 (E1000_READ_REG(&adapter->hw, TDFT) ==
2513 E1000_READ_REG(&adapter->hw, TDFH)) &&
2514 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2515 E1000_READ_REG(&adapter->hw, TDFHS))) {
2516 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2517 E1000_WRITE_REG(&adapter->hw, TCTL,
2518 tctl & ~E1000_TCTL_EN);
2519 E1000_WRITE_REG(&adapter->hw, TDFT,
2520 adapter->tx_head_addr);
2521 E1000_WRITE_REG(&adapter->hw, TDFH,
2522 adapter->tx_head_addr);
2523 E1000_WRITE_REG(&adapter->hw, TDFTS,
2524 adapter->tx_head_addr);
2525 E1000_WRITE_REG(&adapter->hw, TDFHS,
2526 adapter->tx_head_addr);
2527 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2528 E1000_WRITE_FLUSH(&adapter->hw);
2529
2530 adapter->tx_fifo_head = 0;
2531 atomic_set(&adapter->tx_fifo_stall, 0);
2532 netif_wake_queue(netdev);
2533 } else {
2534 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2535 }
2536 }
2537}
2538
2539/**
2540 * e1000_watchdog - Timer Call-back
2541 * @data: pointer to adapter cast into an unsigned long
2542 **/
2543static void
2544e1000_watchdog(unsigned long data)
2545{
2546 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002548 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002549 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002550 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551
Auke Kokcd94dd02006-06-27 09:08:22 -07002552 ret_val = e1000_check_for_link(&adapter->hw);
2553 if ((ret_val == E1000_ERR_PHY) &&
2554 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2555 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2556 /* See e1000_kumeran_lock_loss_workaround() */
2557 DPRINTK(LINK, INFO,
2558 "Gigabit has been disabled, downgrading speed\n");
2559 }
Auke Kok90fb5132006-11-01 08:47:30 -08002560
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002561 if (adapter->hw.mac_type == e1000_82573) {
2562 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002563 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002564 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002567 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2569 link = !adapter->hw.serdes_link_down;
2570 else
2571 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2572
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002573 if (link) {
2574 if (!netif_carrier_ok(netdev)) {
Auke Kok9669f532007-01-18 09:25:26 -08002575 uint32_t ctrl;
Auke Kokfe7fe282006-04-14 19:04:59 -07002576 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 e1000_get_speed_and_duplex(&adapter->hw,
2578 &adapter->link_speed,
2579 &adapter->link_duplex);
2580
Auke Kok9669f532007-01-18 09:25:26 -08002581 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
2582 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2583 "Flow Control: %s\n",
2584 adapter->link_speed,
2585 adapter->link_duplex == FULL_DUPLEX ?
2586 "Full Duplex" : "Half Duplex",
2587 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2588 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2589 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2590 E1000_CTRL_TFCE) ? "TX" : "None" )));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002592 /* tweak tx_queue_len according to speed/duplex
2593 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002594 netdev->tx_queue_len = adapter->tx_queue_len;
2595 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002596 switch (adapter->link_speed) {
2597 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002598 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002599 netdev->tx_queue_len = 10;
2600 adapter->tx_timeout_factor = 8;
2601 break;
2602 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002603 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002604 netdev->tx_queue_len = 100;
2605 /* maybe add some timeout factor ? */
2606 break;
2607 }
2608
Auke Kokfe7fe282006-04-14 19:04:59 -07002609 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002610 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002611 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002612 uint32_t tarc0;
2613 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002614 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002615 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2616 }
Auke Kok90fb5132006-11-01 08:47:30 -08002617
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002618 /* disable TSO for pcie and 10/100 speeds, to avoid
2619 * some hardware issues */
2620 if (!adapter->tso_force &&
2621 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002622 switch (adapter->link_speed) {
2623 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002624 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002625 DPRINTK(PROBE,INFO,
2626 "10/100 speed: disabling TSO\n");
2627 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002628 netdev->features &= ~NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002629 break;
2630 case SPEED_1000:
2631 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002632 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002633 break;
2634 default:
2635 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002636 break;
2637 }
2638 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002639
2640 /* enable transmits in the hardware, need to do this
2641 * after setting TARC0 */
2642 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2643 tctl |= E1000_TCTL_EN;
2644 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002645
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 netif_carrier_on(netdev);
2647 netif_wake_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002648 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002650 } else {
2651 /* make sure the receive unit is started */
2652 if (adapter->hw.rx_needs_kicking) {
2653 struct e1000_hw *hw = &adapter->hw;
2654 uint32_t rctl = E1000_READ_REG(hw, RCTL);
2655 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 }
2658 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002659 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 adapter->link_speed = 0;
2661 adapter->link_duplex = 0;
2662 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2663 netif_carrier_off(netdev);
2664 netif_stop_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002665 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Jeff Kirsher87041632006-03-02 18:21:24 -08002666
2667 /* 80003ES2LAN workaround--
2668 * For packet buffer work-around on link down event;
2669 * disable receives in the ISR and
2670 * reset device here in the watchdog
2671 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002672 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002673 /* reset device */
2674 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 }
2676
2677 e1000_smartspeed(adapter);
2678 }
2679
2680 e1000_update_stats(adapter);
2681
2682 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2683 adapter->tpt_old = adapter->stats.tpt;
2684 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2685 adapter->colc_old = adapter->stats.colc;
2686
2687 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2688 adapter->gorcl_old = adapter->stats.gorcl;
2689 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2690 adapter->gotcl_old = adapter->stats.gotcl;
2691
2692 e1000_update_adaptive(&adapter->hw);
2693
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002694 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002695 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 /* We've lost link, so the controller stops DMA,
2697 * but we've got queued Tx work that's never going
2698 * to get done, so reset controller to flush Tx.
2699 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002700 adapter->tx_timeout_count++;
2701 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 }
2703 }
2704
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 /* Cause software interrupt to ensure rx ring is cleaned */
2706 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2707
Malli Chilakala26483452005-04-28 19:44:46 -07002708 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 adapter->detect_tx_hung = TRUE;
2710
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002711 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002712 * reset from the other port. Set the appropriate LAA in RAR[0] */
2713 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2714 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2715
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 /* Reset the timer */
Arjan van de Ven56e13932007-03-06 02:41:48 -08002717 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718}
2719
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002720enum latency_range {
2721 lowest_latency = 0,
2722 low_latency = 1,
2723 bulk_latency = 2,
2724 latency_invalid = 255
2725};
2726
2727/**
2728 * e1000_update_itr - update the dynamic ITR value based on statistics
2729 * Stores a new ITR value based on packets and byte
2730 * counts during the last interrupt. The advantage of per interrupt
2731 * computation is faster updates and more accurate ITR for the current
2732 * traffic pattern. Constants in this function were computed
2733 * based on theoretical maximum wire speed and thresholds were set based
2734 * on testing data as well as attempting to minimize response time
2735 * while increasing bulk throughput.
2736 * this functionality is controlled by the InterruptThrottleRate module
2737 * parameter (see e1000_param.c)
2738 * @adapter: pointer to adapter
2739 * @itr_setting: current adapter->itr
2740 * @packets: the number of packets during this measurement interval
2741 * @bytes: the number of bytes during this measurement interval
2742 **/
2743static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2744 uint16_t itr_setting,
2745 int packets,
2746 int bytes)
2747{
2748 unsigned int retval = itr_setting;
2749 struct e1000_hw *hw = &adapter->hw;
2750
2751 if (unlikely(hw->mac_type < e1000_82540))
2752 goto update_itr_done;
2753
2754 if (packets == 0)
2755 goto update_itr_done;
2756
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002757 switch (itr_setting) {
2758 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002759 /* jumbo frames get bulk treatment*/
2760 if (bytes/packets > 8000)
2761 retval = bulk_latency;
2762 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002763 retval = low_latency;
2764 break;
2765 case low_latency: /* 50 usec aka 20000 ints/s */
2766 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002767 /* jumbo frames need bulk latency setting */
2768 if (bytes/packets > 8000)
2769 retval = bulk_latency;
2770 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002771 retval = bulk_latency;
2772 else if ((packets > 35))
2773 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002774 } else if (bytes/packets > 2000)
2775 retval = bulk_latency;
2776 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002777 retval = lowest_latency;
2778 break;
2779 case bulk_latency: /* 250 usec aka 4000 ints/s */
2780 if (bytes > 25000) {
2781 if (packets > 35)
2782 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002783 } else if (bytes < 6000) {
2784 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002785 }
2786 break;
2787 }
2788
2789update_itr_done:
2790 return retval;
2791}
2792
2793static void e1000_set_itr(struct e1000_adapter *adapter)
2794{
2795 struct e1000_hw *hw = &adapter->hw;
2796 uint16_t current_itr;
2797 uint32_t new_itr = adapter->itr;
2798
2799 if (unlikely(hw->mac_type < e1000_82540))
2800 return;
2801
2802 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2803 if (unlikely(adapter->link_speed != SPEED_1000)) {
2804 current_itr = 0;
2805 new_itr = 4000;
2806 goto set_itr_now;
2807 }
2808
2809 adapter->tx_itr = e1000_update_itr(adapter,
2810 adapter->tx_itr,
2811 adapter->total_tx_packets,
2812 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002813 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2814 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2815 adapter->tx_itr = low_latency;
2816
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002817 adapter->rx_itr = e1000_update_itr(adapter,
2818 adapter->rx_itr,
2819 adapter->total_rx_packets,
2820 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002821 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2822 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2823 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002824
2825 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2826
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002827 switch (current_itr) {
2828 /* counts and packets in update_itr are dependent on these numbers */
2829 case lowest_latency:
2830 new_itr = 70000;
2831 break;
2832 case low_latency:
2833 new_itr = 20000; /* aka hwitr = ~200 */
2834 break;
2835 case bulk_latency:
2836 new_itr = 4000;
2837 break;
2838 default:
2839 break;
2840 }
2841
2842set_itr_now:
2843 if (new_itr != adapter->itr) {
2844 /* this attempts to bias the interrupt rate towards Bulk
2845 * by adding intermediate steps when interrupt rate is
2846 * increasing */
2847 new_itr = new_itr > adapter->itr ?
2848 min(adapter->itr + (new_itr >> 2), new_itr) :
2849 new_itr;
2850 adapter->itr = new_itr;
2851 E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
2852 }
2853
2854 return;
2855}
2856
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857#define E1000_TX_FLAGS_CSUM 0x00000001
2858#define E1000_TX_FLAGS_VLAN 0x00000002
2859#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002860#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2862#define E1000_TX_FLAGS_VLAN_SHIFT 16
2863
Auke Koke619d522006-04-14 19:04:52 -07002864static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002865e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2866 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002869 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 unsigned int i;
2871 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002872 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2874 int err;
2875
Herbert Xu89114af2006-07-08 13:34:32 -07002876 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 if (skb_header_cloned(skb)) {
2878 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2879 if (err)
2880 return err;
2881 }
2882
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002883 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002884 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002885 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002886 struct iphdr *iph = ip_hdr(skb);
2887 iph->tot_len = 0;
2888 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002889 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2890 iph->daddr, 0,
2891 IPPROTO_TCP,
2892 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002893 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002894 ipcse = skb_transport_offset(skb) - 1;
Auke Koke15fdd02006-08-16 11:28:45 -07002895 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002896 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002897 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002898 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2899 &ipv6_hdr(skb)->daddr,
2900 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002901 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002902 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002903 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002904 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002905 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002906 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 tucse = 0;
2908
2909 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002910 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002912 i = tx_ring->next_to_use;
2913 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002914 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
2916 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2917 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2918 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2919 context_desc->upper_setup.tcp_fields.tucss = tucss;
2920 context_desc->upper_setup.tcp_fields.tucso = tucso;
2921 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2922 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2923 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2924 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2925
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002926 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002927 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002928
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002929 if (++i == tx_ring->count) i = 0;
2930 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
Jeff Kirsher8241e352006-01-12 16:51:34 -08002932 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08002934 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935}
2936
Auke Koke619d522006-04-14 19:04:52 -07002937static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002938e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2939 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940{
2941 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002942 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 unsigned int i;
2944 uint8_t css;
2945
Patrick McHardy84fa7932006-08-29 16:44:56 -07002946 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002947 css = skb_transport_offset(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002949 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002950 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002951 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
Bruce Allanf6c57ba2007-01-18 09:25:28 -08002953 context_desc->lower_setup.ip_config = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 context_desc->upper_setup.tcp_fields.tucss = css;
Herbert Xu628592c2007-04-23 17:06:40 -07002955 context_desc->upper_setup.tcp_fields.tucso =
2956 css + skb->csum_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 context_desc->upper_setup.tcp_fields.tucse = 0;
2958 context_desc->tcp_seg_setup.data = 0;
2959 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2960
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002961 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002962 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002963
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002964 if (unlikely(++i == tx_ring->count)) i = 0;
2965 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966
2967 return TRUE;
2968 }
2969
2970 return FALSE;
2971}
2972
2973#define E1000_MAX_TXD_PWR 12
2974#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2975
Auke Koke619d522006-04-14 19:04:52 -07002976static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002977e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2978 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2979 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 struct e1000_buffer *buffer_info;
2982 unsigned int len = skb->len;
2983 unsigned int offset = 0, size, count = 0, i;
2984 unsigned int f;
2985 len -= skb->data_len;
2986
2987 i = tx_ring->next_to_use;
2988
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002989 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 buffer_info = &tx_ring->buffer_info[i];
2991 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05002992 /* Workaround for Controller erratum --
2993 * descriptor for non-tso packet in a linear SKB that follows a
2994 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002995 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002996 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07002997 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002998 tx_ring->last_tx_tso = 0;
2999 size -= 4;
3000 }
3001
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 /* Workaround for premature desc write-backs
3003 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003004 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07003006 /* work-around for errata 10 and it applies
3007 * to all controllers in PCI-X mode
3008 * The fix is to make sure that the first descriptor of a
3009 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3010 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003011 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003012 (size > 2015) && count == 0))
3013 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003014
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 /* Workaround for potential 82544 hang in PCI-X. Avoid
3016 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003017 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3019 size > 4))
3020 size -= 4;
3021
3022 buffer_info->length = size;
3023 buffer_info->dma =
3024 pci_map_single(adapter->pdev,
3025 skb->data + offset,
3026 size,
3027 PCI_DMA_TODEVICE);
3028 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003029 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030
3031 len -= size;
3032 offset += size;
3033 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003034 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 }
3036
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003037 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 struct skb_frag_struct *frag;
3039
3040 frag = &skb_shinfo(skb)->frags[f];
3041 len = frag->size;
3042 offset = frag->page_offset;
3043
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003044 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 buffer_info = &tx_ring->buffer_info[i];
3046 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 /* Workaround for premature desc write-backs
3048 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003049 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 /* Workaround for potential 82544 hang in PCI-X.
3052 * Avoid terminating buffers within evenly-aligned
3053 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003054 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3056 size > 4))
3057 size -= 4;
3058
3059 buffer_info->length = size;
3060 buffer_info->dma =
3061 pci_map_page(adapter->pdev,
3062 frag->page,
3063 offset,
3064 size,
3065 PCI_DMA_TODEVICE);
3066 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003067 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068
3069 len -= size;
3070 offset += size;
3071 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003072 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 }
3074 }
3075
3076 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3077 tx_ring->buffer_info[i].skb = skb;
3078 tx_ring->buffer_info[first].next_to_watch = i;
3079
3080 return count;
3081}
3082
Auke Koke619d522006-04-14 19:04:52 -07003083static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003084e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
3085 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 struct e1000_tx_desc *tx_desc = NULL;
3088 struct e1000_buffer *buffer_info;
3089 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
3090 unsigned int i;
3091
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003092 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3094 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003095 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3096
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003097 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003098 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 }
3100
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003101 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3103 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3104 }
3105
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003106 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 txd_lower |= E1000_TXD_CMD_VLE;
3108 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3109 }
3110
3111 i = tx_ring->next_to_use;
3112
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003113 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 buffer_info = &tx_ring->buffer_info[i];
3115 tx_desc = E1000_TX_DESC(*tx_ring, i);
3116 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3117 tx_desc->lower.data =
3118 cpu_to_le32(txd_lower | buffer_info->length);
3119 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003120 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 }
3122
3123 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3124
3125 /* Force memory writes to complete before letting h/w
3126 * know there are new descriptors to fetch. (Only
3127 * applicable for weak-ordered memory model archs,
3128 * such as IA-64). */
3129 wmb();
3130
3131 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003132 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003133 /* we need this if more than one processor can write to our tail
3134 * at a time, it syncronizes IO on IA64/Altix systems */
3135 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136}
3137
3138/**
3139 * 82547 workaround to avoid controller hang in half-duplex environment.
3140 * The workaround is to avoid queuing a large packet that would span
3141 * the internal Tx FIFO ring boundary by notifying the stack to resend
3142 * the packet at a later time. This gives the Tx FIFO an opportunity to
3143 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3144 * to the beginning of the Tx FIFO.
3145 **/
3146
3147#define E1000_FIFO_HDR 0x10
3148#define E1000_82547_PAD_LEN 0x3E0
3149
Auke Koke619d522006-04-14 19:04:52 -07003150static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
3152{
3153 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3154 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
3155
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003156 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003158 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 goto no_fifo_stall_required;
3160
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003161 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 return 1;
3163
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003164 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 atomic_set(&adapter->tx_fifo_stall, 1);
3166 return 1;
3167 }
3168
3169no_fifo_stall_required:
3170 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003171 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3173 return 0;
3174}
3175
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003176#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07003177static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003178e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
3179{
3180 struct e1000_hw *hw = &adapter->hw;
3181 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003182 if (vlan_tx_tag_present(skb)) {
3183 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003184 ( adapter->hw.mng_cookie.status &
3185 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3186 return 0;
3187 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003188 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003189 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003190 if ((htons(ETH_P_IP) == eth->h_proto)) {
3191 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003192 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003193 if (IPPROTO_UDP == ip->protocol) {
3194 struct udphdr *udp =
3195 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003196 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003197 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003198 offset = (uint8_t *)udp + 8 - skb->data;
3199 length = skb->len - offset;
3200
3201 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003202 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003203 length);
3204 }
3205 }
3206 }
3207 }
3208 return 0;
3209}
3210
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003211static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3212{
3213 struct e1000_adapter *adapter = netdev_priv(netdev);
3214 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3215
3216 netif_stop_queue(netdev);
3217 /* Herbert's original patch had:
3218 * smp_mb__after_netif_stop_queue();
3219 * but since that doesn't exist yet, just open code it. */
3220 smp_mb();
3221
3222 /* We need to check again in a case another CPU has just
3223 * made room available. */
3224 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3225 return -EBUSY;
3226
3227 /* A reprieve! */
3228 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003229 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003230 return 0;
3231}
3232
3233static int e1000_maybe_stop_tx(struct net_device *netdev,
3234 struct e1000_tx_ring *tx_ring, int size)
3235{
3236 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3237 return 0;
3238 return __e1000_maybe_stop_tx(netdev, size);
3239}
3240
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
3242static int
3243e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3244{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003245 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003246 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3248 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3249 unsigned int tx_flags = 0;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003250 unsigned int len = skb->len - skb->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 unsigned long flags;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003252 unsigned int nr_frags;
3253 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003255 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 unsigned int f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003258 /* This goes back to the question of how to logically map a tx queue
3259 * to a flow. Right now, performance is impacted slightly negatively
3260 * if using multiple tx queues. If the stack breaks away from a
3261 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003262 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003263
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003264 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 dev_kfree_skb_any(skb);
3266 return NETDEV_TX_OK;
3267 }
3268
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003269 /* 82571 and newer doesn't need the workaround that limited descriptor
3270 * length to 4kB */
3271 if (adapter->hw.mac_type >= e1000_82571)
3272 max_per_txd = 8192;
3273
Herbert Xu79671682006-06-22 02:40:14 -07003274 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003275 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 * make sure there is enough room in the FIFO before
3277 * initiating the DMA for each buffer. The calc is:
3278 * 4 = ceil(buffer len/mss). To make sure we don't
3279 * overrun the FIFO, adjust the max buffer len if mss
3280 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003281 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003282 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 max_per_txd = min(mss << 2, max_per_txd);
3284 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003285
Auke Kok90fb5132006-11-01 08:47:30 -08003286 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3287 * points to just header, pull a few bytes of payload from
3288 * frags into skb->data */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003289 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003290 if (skb->data_len && hdr_len == len) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003291 switch (adapter->hw.mac_type) {
3292 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003293 case e1000_82544:
3294 /* Make sure we have room to chop off 4 bytes,
3295 * and that the end alignment will work out to
3296 * this hardware's requirements
3297 * NOTE: this is a TSO only workaround
3298 * if end byte alignment not correct move us
3299 * into the next dword */
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003300 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003301 break;
3302 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003303 case e1000_82571:
3304 case e1000_82572:
3305 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003306 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003307 pull_size = min((unsigned int)4, skb->data_len);
3308 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003309 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003310 "__pskb_pull_tail failed.\n");
3311 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003312 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003313 }
3314 len = skb->len - skb->data_len;
3315 break;
3316 default:
3317 /* do nothing */
3318 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003319 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 }
3322
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003323 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003324 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003326 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003327
Jeff Kirsherfd803242005-12-13 00:06:22 -05003328 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003329 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003330 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003331
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 count += TXD_USE_COUNT(len, max_txd_pwr);
3333
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003334 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 count++;
3336
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003337 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003338 * in PCI-X mode, so add one more descriptor to the count
3339 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003340 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003341 (len > 2015)))
3342 count++;
3343
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003345 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3347 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003348 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 count += nr_frags;
3350
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003351
3352 if (adapter->hw.tx_pkt_filtering &&
3353 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003354 e1000_transfer_dhcp_info(adapter, skb);
3355
Mark Huthf50393f2007-03-06 08:57:26 -08003356 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003357 /* Collision - tell upper layer to requeue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003358 return NETDEV_TX_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359
3360 /* need: count + 2 desc gap to keep tail from touching
3361 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003362 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003363 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 return NETDEV_TX_BUSY;
3365 }
3366
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003367 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3368 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003370 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003371 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 return NETDEV_TX_BUSY;
3373 }
3374 }
3375
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003376 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 tx_flags |= E1000_TX_FLAGS_VLAN;
3378 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3379 }
3380
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003381 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003382
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003383 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 if (tso < 0) {
3385 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003386 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 return NETDEV_TX_OK;
3388 }
3389
Jeff Kirsherfd803242005-12-13 00:06:22 -05003390 if (likely(tso)) {
3391 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003393 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 tx_flags |= E1000_TX_FLAGS_CSUM;
3395
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003396 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003397 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003398 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003399 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003400 tx_flags |= E1000_TX_FLAGS_IPV4;
3401
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003402 e1000_tx_queue(adapter, tx_ring, tx_flags,
3403 e1000_tx_map(adapter, tx_ring, skb, first,
3404 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405
3406 netdev->trans_start = jiffies;
3407
3408 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003409 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003411 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 return NETDEV_TX_OK;
3413}
3414
3415/**
3416 * e1000_tx_timeout - Respond to a Tx Hang
3417 * @netdev: network interface device structure
3418 **/
3419
3420static void
3421e1000_tx_timeout(struct net_device *netdev)
3422{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003423 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424
3425 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003426 adapter->tx_timeout_count++;
3427 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428}
3429
3430static void
David Howells65f27f32006-11-22 14:55:48 +00003431e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432{
David Howells65f27f32006-11-22 14:55:48 +00003433 struct e1000_adapter *adapter =
3434 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435
Auke Kok2db10a02006-06-27 09:06:28 -07003436 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437}
3438
3439/**
3440 * e1000_get_stats - Get System Network Statistics
3441 * @netdev: network interface device structure
3442 *
3443 * Returns the address of the device statistics structure.
3444 * The statistics are actually updated from the timer callback.
3445 **/
3446
3447static struct net_device_stats *
3448e1000_get_stats(struct net_device *netdev)
3449{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003450 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003452 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 return &adapter->net_stats;
3454}
3455
3456/**
3457 * e1000_change_mtu - Change the Maximum Transfer Unit
3458 * @netdev: network interface device structure
3459 * @new_mtu: new value for maximum frame size
3460 *
3461 * Returns 0 on success, negative on failure
3462 **/
3463
3464static int
3465e1000_change_mtu(struct net_device *netdev, int new_mtu)
3466{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003467 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003469 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003471 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3472 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3473 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003474 return -EINVAL;
3475 }
3476
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003477 /* Adapter-specific max frame size limits. */
3478 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003479 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003480 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003481 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3482 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003483 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003484 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003485 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003486 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003487 /* Jumbo Frames not supported if:
3488 * - this is not an 82573L device
3489 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003490 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3491 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003492 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3493 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003494 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3495 DPRINTK(PROBE, ERR,
3496 "Jumbo Frames not supported.\n");
3497 return -EINVAL;
3498 }
3499 break;
3500 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003501 /* ERT will be enabled later to enable wire speed receives */
3502
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003503 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003504 case e1000_82571:
3505 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003506 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003507#define MAX_STD_JUMBO_FRAME_SIZE 9234
3508 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3509 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3510 return -EINVAL;
3511 }
3512 break;
3513 default:
3514 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3515 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003516 }
3517
David S. Miller87f50322006-07-31 22:39:40 -07003518 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003519 * means we reserve 2 more, this pushes us to allocate from the next
3520 * larger slab size
3521 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003522
Auke Kok9e2feac2006-04-14 19:05:18 -07003523 if (max_frame <= E1000_RXBUFFER_256)
3524 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3525 else if (max_frame <= E1000_RXBUFFER_512)
3526 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3527 else if (max_frame <= E1000_RXBUFFER_1024)
3528 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3529 else if (max_frame <= E1000_RXBUFFER_2048)
3530 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3531 else if (max_frame <= E1000_RXBUFFER_4096)
3532 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3533 else if (max_frame <= E1000_RXBUFFER_8192)
3534 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3535 else if (max_frame <= E1000_RXBUFFER_16384)
3536 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3537
3538 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003539 if (!adapter->hw.tbi_compatibility_on &&
3540 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3541 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3542 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003544 netdev->mtu = new_mtu;
Bruce Allan83cd8272006-12-15 10:36:35 +01003545 adapter->hw.max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003546
Auke Kok2db10a02006-06-27 09:06:28 -07003547 if (netif_running(netdev))
3548 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 return 0;
3551}
3552
3553/**
3554 * e1000_update_stats - Update the board statistics counters
3555 * @adapter: board private structure
3556 **/
3557
3558void
3559e1000_update_stats(struct e1000_adapter *adapter)
3560{
3561 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003562 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 unsigned long flags;
3564 uint16_t phy_tmp;
3565
3566#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3567
Linas Vepstas282f33c2006-06-08 22:19:44 -07003568 /*
3569 * Prevent stats update while adapter is being reset, or if the pci
3570 * connection is down.
3571 */
Auke Kok90267292006-06-08 09:30:24 -07003572 if (adapter->link_speed == 0)
3573 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003574 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003575 return;
Auke Kok90267292006-06-08 09:30:24 -07003576
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 spin_lock_irqsave(&adapter->stats_lock, flags);
3578
Masatake YAMATO828d0552007-10-20 03:06:37 +02003579 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580 * called from the interrupt context, so they must only
3581 * be written while holding adapter->stats_lock
3582 */
3583
3584 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3585 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3586 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3587 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3588 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3589 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3590 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003591
3592 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003593 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3594 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3595 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3596 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3597 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3598 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600
3601 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3602 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3603 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3604 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3605 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3606 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3607 adapter->stats.dc += E1000_READ_REG(hw, DC);
3608 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3609 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3610 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3611 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3612 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3613 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3614 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3615 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3616 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3617 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3618 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3619 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3620 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3621 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3622 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3623 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3624 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3625 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3626 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003627
3628 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003629 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3630 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3631 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3632 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3633 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3634 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003635 }
3636
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3638 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3639
3640 /* used for adaptive IFS */
3641
3642 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3643 adapter->stats.tpt += hw->tx_packet_delta;
3644 hw->collision_delta = E1000_READ_REG(hw, COLC);
3645 adapter->stats.colc += hw->collision_delta;
3646
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003647 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3649 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3650 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3651 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3652 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3653 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3654 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003655 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003656 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3657 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003658
3659 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003660 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3661 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3662 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3663 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3664 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3665 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3666 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003667 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669
3670 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 adapter->net_stats.multicast = adapter->stats.mprc;
3672 adapter->net_stats.collisions = adapter->stats.colc;
3673
3674 /* Rx Errors */
3675
Jeff Kirsher87041632006-03-02 18:21:24 -08003676 /* RLEC on some newer hardware can be incorrect so build
3677 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3679 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003680 adapter->stats.ruc + adapter->stats.roc +
3681 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003682 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3683 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3685 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3687
3688 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003689 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3690 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3692 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3693 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Jeff Garzik167fb282006-12-15 10:41:15 -05003694 if (adapter->hw.bad_tx_carr_stats_fd &&
3695 adapter->link_duplex == FULL_DUPLEX) {
3696 adapter->net_stats.tx_carrier_errors = 0;
3697 adapter->stats.tncrs = 0;
3698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699
3700 /* Tx Dropped needs to be maintained elsewhere */
3701
3702 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003703 if (hw->media_type == e1000_media_type_copper) {
3704 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3706 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3707 adapter->phy_stats.idle_errors += phy_tmp;
3708 }
3709
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003710 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 (hw->phy_type == e1000_phy_m88) &&
3712 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3713 adapter->phy_stats.receive_errors += phy_tmp;
3714 }
3715
Jeff Garzik15e376b2006-12-15 11:16:33 -05003716 /* Management Stats */
3717 if (adapter->hw.has_smbus) {
3718 adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
3719 adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
3720 adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
3721 }
3722
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3724}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003725
3726/**
3727 * e1000_intr_msi - Interrupt Handler
3728 * @irq: interrupt number
3729 * @data: pointer to a network interface device structure
3730 **/
3731
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003732static irqreturn_t
3733e1000_intr_msi(int irq, void *data)
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003734{
3735 struct net_device *netdev = data;
3736 struct e1000_adapter *adapter = netdev_priv(netdev);
3737 struct e1000_hw *hw = &adapter->hw;
3738#ifndef CONFIG_E1000_NAPI
3739 int i;
3740#endif
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003741 uint32_t icr = E1000_READ_REG(hw, ICR);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003742
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003743#ifdef CONFIG_E1000_NAPI
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003744 /* read ICR disables interrupts using IAM, so keep up with our
3745 * enable/disable accounting */
3746 atomic_inc(&adapter->irq_sem);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003747#endif
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003748 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3749 hw->get_link_status = 1;
3750 /* 80003ES2LAN workaround-- For packet buffer work-around on
3751 * link down event; disable receives here in the ISR and reset
3752 * adapter in watchdog */
3753 if (netif_carrier_ok(netdev) &&
3754 (adapter->hw.mac_type == e1000_80003es2lan)) {
3755 /* disable receives */
3756 uint32_t rctl = E1000_READ_REG(hw, RCTL);
3757 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003758 }
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003759 /* guard against interrupt when we're going down */
3760 if (!test_bit(__E1000_DOWN, &adapter->flags))
3761 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003762 }
3763
3764#ifdef CONFIG_E1000_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003765 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003766 adapter->total_tx_bytes = 0;
3767 adapter->total_tx_packets = 0;
3768 adapter->total_rx_bytes = 0;
3769 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003770 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003771 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003772 e1000_irq_enable(adapter);
3773#else
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003774 adapter->total_tx_bytes = 0;
3775 adapter->total_rx_bytes = 0;
3776 adapter->total_tx_packets = 0;
3777 adapter->total_rx_packets = 0;
3778
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003779 for (i = 0; i < E1000_MAX_INTR; i++)
3780 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003781 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003782 break;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003783
3784 if (likely(adapter->itr_setting & 3))
3785 e1000_set_itr(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003786#endif
3787
3788 return IRQ_HANDLED;
3789}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790
3791/**
3792 * e1000_intr - Interrupt Handler
3793 * @irq: interrupt number
3794 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 **/
3796
3797static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003798e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799{
3800 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003801 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003803 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003804#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003805 int i;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003806#endif
3807 if (unlikely(!icr))
3808 return IRQ_NONE; /* Not our interrupt */
3809
3810#ifdef CONFIG_E1000_NAPI
3811 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3812 * not set, then the adapter didn't send an interrupt */
3813 if (unlikely(hw->mac_type >= e1000_82571 &&
3814 !(icr & E1000_ICR_INT_ASSERTED)))
3815 return IRQ_NONE;
3816
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003817 /* Interrupt Auto-Mask...upon reading ICR,
3818 * interrupts are masked. No need for the
3819 * IMC write, but it does mean we should
3820 * account for it ASAP. */
3821 if (likely(hw->mac_type >= e1000_82571))
3822 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003823#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003825 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003827 /* 80003ES2LAN workaround--
3828 * For packet buffer work-around on link down event;
3829 * disable receives here in the ISR and
3830 * reset adapter in watchdog
3831 */
3832 if (netif_carrier_ok(netdev) &&
3833 (adapter->hw.mac_type == e1000_80003es2lan)) {
3834 /* disable receives */
3835 rctl = E1000_READ_REG(hw, RCTL);
3836 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3837 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003838 /* guard against interrupt when we're going down */
3839 if (!test_bit(__E1000_DOWN, &adapter->flags))
3840 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 }
3842
3843#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003844 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003845 /* disable interrupts, without the synchronize_irq bit */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003846 atomic_inc(&adapter->irq_sem);
3847 E1000_WRITE_REG(hw, IMC, ~0);
3848 E1000_WRITE_FLUSH(hw);
3849 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003850 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003851 adapter->total_tx_bytes = 0;
3852 adapter->total_tx_packets = 0;
3853 adapter->total_rx_bytes = 0;
3854 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003855 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003856 } else
Auke Kok90fb5132006-11-01 08:47:30 -08003857 /* this really should not happen! if it does it is basically a
3858 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003859 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003860#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003862 * Due to Hub Link bus being occupied, an interrupt
3863 * de-assertion message is not able to be sent.
3864 * When an interrupt assertion message is generated later,
3865 * two messages are re-ordered and sent out.
3866 * That causes APIC to think 82547 is in de-assertion
3867 * state, while 82547 is in assertion state, resulting
3868 * in dead lock. Writing IMC forces 82547 into
3869 * de-assertion state.
3870 */
3871 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003873 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 }
3875
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003876 adapter->total_tx_bytes = 0;
3877 adapter->total_rx_bytes = 0;
3878 adapter->total_tx_packets = 0;
3879 adapter->total_rx_packets = 0;
3880
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003881 for (i = 0; i < E1000_MAX_INTR; i++)
3882 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Linus Torvalds46fcc862007-04-19 18:21:01 -07003883 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 break;
3885
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003886 if (likely(adapter->itr_setting & 3))
3887 e1000_set_itr(adapter);
3888
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003889 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003891
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003892#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 return IRQ_HANDLED;
3894}
3895
3896#ifdef CONFIG_E1000_NAPI
3897/**
3898 * e1000_clean - NAPI Rx polling callback
3899 * @adapter: board private structure
3900 **/
3901
3902static int
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003903e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003905 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3906 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003907 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003908
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003909 /* Must NOT use netdev_priv macro here. */
3910 adapter = poll_dev->priv;
3911
Auke Kokd3d9e482006-07-14 16:14:23 -07003912 /* e1000_clean is called per-cpu. This lock protects
3913 * tx_ring[0] from being cleaned by multiple cpus
3914 * simultaneously. A failure obtaining the lock means
3915 * tx_ring[0] is currently being cleaned anyway. */
3916 if (spin_trylock(&adapter->tx_queue_lock)) {
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003917 tx_cleaned = e1000_clean_tx_irq(adapter,
3918 &adapter->tx_ring[0]);
Auke Kokd3d9e482006-07-14 16:14:23 -07003919 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003920 }
3921
Auke Kokd3d9e482006-07-14 16:14:23 -07003922 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003923 &work_done, budget);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003924
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003925 if (tx_cleaned)
3926 work_done = budget;
3927
David S. Miller53e52c72008-01-07 21:06:12 -08003928 /* If budget not fully consumed, exit the polling mode */
3929 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003930 if (likely(adapter->itr_setting & 3))
3931 e1000_set_itr(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003932 netif_rx_complete(poll_dev, napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 }
3935
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003936 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937}
3938
3939#endif
3940/**
3941 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3942 * @adapter: board private structure
3943 **/
3944
3945static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003946e1000_clean_tx_irq(struct e1000_adapter *adapter,
3947 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 struct net_device *netdev = adapter->netdev;
3950 struct e1000_tx_desc *tx_desc, *eop_desc;
3951 struct e1000_buffer *buffer_info;
3952 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003953#ifdef CONFIG_E1000_NAPI
3954 unsigned int count = 0;
3955#endif
Linus Torvalds46fcc862007-04-19 18:21:01 -07003956 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003957 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958
3959 i = tx_ring->next_to_clean;
3960 eop = tx_ring->buffer_info[i].next_to_watch;
3961 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3962
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003963 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003964 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 tx_desc = E1000_TX_DESC(*tx_ring, i);
3966 buffer_info = &tx_ring->buffer_info[i];
3967 cleaned = (i == eop);
3968
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003969 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003970 struct sk_buff *skb = buffer_info->skb;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003971 unsigned int segs, bytecount;
3972 segs = skb_shinfo(skb)->gso_segs ?: 1;
3973 /* multiply data chunks by size of headers */
3974 bytecount = ((segs - 1) * skb_headlen(skb)) +
3975 skb->len;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003976 total_tx_packets += segs;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003977 total_tx_bytes += bytecount;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003978 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05003979 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003980 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003982 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003984
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 eop = tx_ring->buffer_info[i].next_to_watch;
3986 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003987#ifdef CONFIG_E1000_NAPI
3988#define E1000_TX_WEIGHT 64
3989 /* weight of a sort for tx, to avoid endless transmit cleanup */
Linus Torvalds46fcc862007-04-19 18:21:01 -07003990 if (count++ == E1000_TX_WEIGHT) break;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003991#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 }
3993
3994 tx_ring->next_to_clean = i;
3995
Auke Kok77b2aad2006-04-14 19:05:25 -07003996#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003997 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3998 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3999 /* Make sure that anybody stopping the queue after this
4000 * sees the new next_to_clean.
4001 */
4002 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004003 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07004004 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08004005 ++adapter->restart_queue;
4006 }
Auke Kok77b2aad2006-04-14 19:05:25 -07004007 }
Malli Chilakala26483452005-04-28 19:44:46 -07004008
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004009 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07004010 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 * check with the clearing of time_stamp and movement of i */
4012 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08004013 if (tx_ring->buffer_info[eop].dma &&
4014 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08004015 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004016 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08004017 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004018
4019 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07004020 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004021 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004022 " TDH <%x>\n"
4023 " TDT <%x>\n"
4024 " next_to_use <%x>\n"
4025 " next_to_clean <%x>\n"
4026 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004027 " time_stamp <%lx>\n"
4028 " next_to_watch <%x>\n"
4029 " jiffies <%lx>\n"
4030 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004031 (unsigned long)((tx_ring - adapter->tx_ring) /
4032 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004033 readl(adapter->hw.hw_addr + tx_ring->tdh),
4034 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004035 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08004036 tx_ring->next_to_clean,
4037 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004038 eop,
4039 jiffies,
4040 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004042 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004044 adapter->total_tx_bytes += total_tx_bytes;
4045 adapter->total_tx_packets += total_tx_packets;
Auke Kokef90e4e2007-11-13 20:49:15 -08004046 adapter->net_stats.tx_bytes += total_tx_bytes;
4047 adapter->net_stats.tx_packets += total_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 return cleaned;
4049}
4050
4051/**
4052 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004053 * @adapter: board private structure
4054 * @status_err: receive descriptor status and error fields
4055 * @csum: receive descriptor csum field
4056 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 **/
4058
Auke Koke619d522006-04-14 19:04:52 -07004059static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004061 uint32_t status_err, uint32_t csum,
4062 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004064 uint16_t status = (uint16_t)status_err;
4065 uint8_t errors = (uint8_t)(status_err >> 24);
4066 skb->ip_summed = CHECKSUM_NONE;
4067
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004069 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004071 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004072 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004073 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004074 /* let the stack verify checksum errors */
4075 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 return;
4077 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004078 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004079 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
4080 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004081 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004083 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004084 return;
4085 }
4086 /* It must be a TCP or UDP packet with a valid checksum */
4087 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088 /* TCP checksum is good */
4089 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004090 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
4091 /* IP fragment with UDP payload */
4092 /* Hardware complements the payload checksum, so we undo it
4093 * and then put the value in host order for further stack use.
4094 */
Al Viro3e188262007-12-11 19:49:39 +00004095 __sum16 sum = (__force __sum16)htons(csum);
4096 skb->csum = csum_unfold(~sum);
Patrick McHardy84fa7932006-08-29 16:44:56 -07004097 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004099 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100}
4101
4102/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004103 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 * @adapter: board private structure
4105 **/
4106
4107static boolean_t
4108#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004109e1000_clean_rx_irq(struct e1000_adapter *adapter,
4110 struct e1000_rx_ring *rx_ring,
4111 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004113e1000_clean_rx_irq(struct e1000_adapter *adapter,
4114 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115#endif
4116{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 struct net_device *netdev = adapter->netdev;
4118 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004119 struct e1000_rx_desc *rx_desc, *next_rxd;
4120 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 unsigned long flags;
4122 uint32_t length;
4123 uint8_t last_byte;
4124 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004125 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004126 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004127 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128
4129 i = rx_ring->next_to_clean;
4130 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004131 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004133 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004134 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004135 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004136
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004138 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 break;
4140 (*work_done)++;
4141#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08004142 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004143 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004144 buffer_info->skb = NULL;
4145
Jeff Kirsher30320be2006-03-02 18:21:57 -08004146 prefetch(skb->data - NET_IP_ALIGN);
4147
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004148 if (++i == rx_ring->count) i = 0;
4149 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004150 prefetch(next_rxd);
4151
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004152 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004153
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004154 cleaned = TRUE;
4155 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004156 pci_unmap_single(pdev,
4157 buffer_info->dma,
4158 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 PCI_DMA_FROMDEVICE);
4160
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 length = le16_to_cpu(rx_desc->length);
4162
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004163 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4164 /* All receives must fit into a single buffer */
4165 E1000_DBG("%s: Receive packet consumed multiple"
4166 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004167 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004168 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 goto next_desc;
4170 }
4171
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004172 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004174 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 rx_desc->errors, length, last_byte)) {
4176 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004177 e1000_tbi_adjust_stats(&adapter->hw,
4178 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 length, skb->data);
4180 spin_unlock_irqrestore(&adapter->stats_lock,
4181 flags);
4182 length--;
4183 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004184 /* recycle */
4185 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 goto next_desc;
4187 }
Auke Kok1cb58212006-04-18 12:31:04 -07004188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004190 /* adjust length to remove Ethernet CRC, this must be
4191 * done after the TBI_ACCEPT workaround above */
4192 length -= 4;
4193
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004194 /* probably a little skewed due to removing CRC */
4195 total_rx_bytes += length;
4196 total_rx_packets++;
4197
Jeff Kirshera292ca62006-01-12 16:51:30 -08004198 /* code added for copybreak, this should improve
4199 * performance for small packets with large amounts
4200 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004201 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004202 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004203 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004204 if (new_skb) {
4205 skb_reserve(new_skb, NET_IP_ALIGN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004206 skb_copy_to_linear_data_offset(new_skb,
4207 -NET_IP_ALIGN,
4208 (skb->data -
4209 NET_IP_ALIGN),
4210 (length +
4211 NET_IP_ALIGN));
Jeff Kirshera292ca62006-01-12 16:51:30 -08004212 /* save the skb in buffer_info as good */
4213 buffer_info->skb = skb;
4214 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004215 }
Auke Kok996695d2006-11-01 08:47:50 -08004216 /* else just continue with the old one */
4217 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004218 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004219 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220
4221 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004222 e1000_rx_checksum(adapter,
4223 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004224 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004225 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004226
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 skb->protocol = eth_type_trans(skb, netdev);
4228#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004229 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08004230 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004232 le16_to_cpu(rx_desc->special) &
4233 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 } else {
4235 netif_receive_skb(skb);
4236 }
4237#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004238 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004239 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 vlan_hwaccel_rx(skb, adapter->vlgrp,
4241 le16_to_cpu(rx_desc->special) &
4242 E1000_RXD_SPC_VLAN_MASK);
4243 } else {
4244 netif_rx(skb);
4245 }
4246#endif /* CONFIG_E1000_NAPI */
4247 netdev->last_rx = jiffies;
4248
4249next_desc:
4250 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004252 /* return some buffers to hardware, one at a time is too slow */
4253 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4254 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4255 cleaned_count = 0;
4256 }
4257
Jeff Kirsher30320be2006-03-02 18:21:57 -08004258 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004259 rx_desc = next_rxd;
4260 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004263
4264 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4265 if (cleaned_count)
4266 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004268 adapter->total_rx_packets += total_rx_packets;
4269 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004270 adapter->net_stats.rx_bytes += total_rx_bytes;
4271 adapter->net_stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 return cleaned;
4273}
4274
4275/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004276 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4277 * @adapter: board private structure
4278 **/
4279
4280static boolean_t
4281#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004282e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4283 struct e1000_rx_ring *rx_ring,
4284 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004285#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004286e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4287 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004288#endif
4289{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004290 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004291 struct net_device *netdev = adapter->netdev;
4292 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004293 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004294 struct e1000_ps_page *ps_page;
4295 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07004296 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004297 unsigned int i, j;
4298 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004299 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004300 boolean_t cleaned = FALSE;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004301 unsigned int total_rx_bytes=0, total_rx_packets=0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004302
4303 i = rx_ring->next_to_clean;
4304 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07004305 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07004306 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004307
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004308 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004309 ps_page = &rx_ring->ps_page[i];
4310 ps_page_dma = &rx_ring->ps_page_dma[i];
4311#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004312 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004313 break;
4314 (*work_done)++;
4315#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004316 skb = buffer_info->skb;
4317
Jeff Kirsher30320be2006-03-02 18:21:57 -08004318 /* in the packet split case this is header only */
4319 prefetch(skb->data - NET_IP_ALIGN);
4320
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004321 if (++i == rx_ring->count) i = 0;
4322 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004323 prefetch(next_rxd);
4324
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004325 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004326
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004327 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004328 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004329 pci_unmap_single(pdev, buffer_info->dma,
4330 buffer_info->length,
4331 PCI_DMA_FROMDEVICE);
4332
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004333 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004334 E1000_DBG("%s: Packet Split buffers didn't pick up"
4335 " the full packet\n", netdev->name);
4336 dev_kfree_skb_irq(skb);
4337 goto next_desc;
4338 }
4339
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004340 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004341 dev_kfree_skb_irq(skb);
4342 goto next_desc;
4343 }
4344
4345 length = le16_to_cpu(rx_desc->wb.middle.length0);
4346
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004347 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004348 E1000_DBG("%s: Last part of the packet spanning"
4349 " multiple descriptors\n", netdev->name);
4350 dev_kfree_skb_irq(skb);
4351 goto next_desc;
4352 }
4353
4354 /* Good Receive */
4355 skb_put(skb, length);
4356
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004357 {
4358 /* this looks ugly, but it seems compiler issues make it
4359 more efficient than reusing j */
4360 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4361
4362 /* page alloc/put takes too long and effects small packet
4363 * throughput, so unsplit small packets and save the alloc/put*/
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004364 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004365 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004366 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004367 * kmap_atomic, so we can't hold the mapping
4368 * very long */
4369 pci_dma_sync_single_for_cpu(pdev,
4370 ps_page_dma->ps_page_dma[0],
4371 PAGE_SIZE,
4372 PCI_DMA_FROMDEVICE);
4373 vaddr = kmap_atomic(ps_page->ps_page[0],
4374 KM_SKB_DATA_SOFTIRQ);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07004375 memcpy(skb_tail_pointer(skb), vaddr, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004376 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4377 pci_dma_sync_single_for_device(pdev,
4378 ps_page_dma->ps_page_dma[0],
4379 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004380 /* remove the CRC */
4381 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004382 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004383 goto copydone;
4384 } /* if */
4385 }
Auke Kok90fb5132006-11-01 08:47:30 -08004386
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004387 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004388 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004389 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004390 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4391 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4392 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004393 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4394 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004395 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004396 skb->len += length;
4397 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004398 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004399 }
4400
Auke Kokf235a2a2006-07-14 16:14:34 -07004401 /* strip the ethernet crc, problem is we're using pages now so
4402 * this whole operation can get a little cpu intensive */
4403 pskb_trim(skb, skb->len - 4);
4404
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004405copydone:
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004406 total_rx_bytes += skb->len;
4407 total_rx_packets++;
4408
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004409 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004410 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004411 skb->protocol = eth_type_trans(skb, netdev);
4412
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004413 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004414 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004415 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004416#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004417 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004418 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004419 le16_to_cpu(rx_desc->wb.middle.vlan) &
4420 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004421 } else {
4422 netif_receive_skb(skb);
4423 }
4424#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004425 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004426 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004427 le16_to_cpu(rx_desc->wb.middle.vlan) &
4428 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004429 } else {
4430 netif_rx(skb);
4431 }
4432#endif /* CONFIG_E1000_NAPI */
4433 netdev->last_rx = jiffies;
4434
4435next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004436 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004437 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004438
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004439 /* return some buffers to hardware, one at a time is too slow */
4440 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4441 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4442 cleaned_count = 0;
4443 }
4444
Jeff Kirsher30320be2006-03-02 18:21:57 -08004445 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004446 rx_desc = next_rxd;
4447 buffer_info = next_buffer;
4448
Malli Chilakala683a38f2005-06-17 17:43:25 -07004449 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004450 }
4451 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004452
4453 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4454 if (cleaned_count)
4455 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004456
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004457 adapter->total_rx_packets += total_rx_packets;
4458 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004459 adapter->net_stats.rx_bytes += total_rx_bytes;
4460 adapter->net_stats.rx_packets += total_rx_packets;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004461 return cleaned;
4462}
4463
4464/**
4465 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466 * @adapter: address of board private structure
4467 **/
4468
4469static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004470e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004471 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004472 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 struct net_device *netdev = adapter->netdev;
4475 struct pci_dev *pdev = adapter->pdev;
4476 struct e1000_rx_desc *rx_desc;
4477 struct e1000_buffer *buffer_info;
4478 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004479 unsigned int i;
4480 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481
4482 i = rx_ring->next_to_use;
4483 buffer_info = &rx_ring->buffer_info[i];
4484
Jeff Kirshera292ca62006-01-12 16:51:30 -08004485 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004486 skb = buffer_info->skb;
4487 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004488 skb_trim(skb, 0);
4489 goto map_skb;
4490 }
4491
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004492 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004493 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004495 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 break;
4497 }
4498
Malli Chilakala26483452005-04-28 19:44:46 -07004499 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4501 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004502 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4503 "at %p\n", bufsz, skb->data);
4504 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004505 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004506 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 if (!skb) {
4508 dev_kfree_skb(oldskb);
4509 break;
4510 }
Malli Chilakala26483452005-04-28 19:44:46 -07004511
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4513 /* give up */
4514 dev_kfree_skb(skb);
4515 dev_kfree_skb(oldskb);
4516 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004518
4519 /* Use new allocation */
4520 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522 /* Make buffer alignment 2 beyond a 16 byte boundary
4523 * this will result in a 16 byte aligned IP header after
4524 * the 14 byte MAC header is removed
4525 */
4526 skb_reserve(skb, NET_IP_ALIGN);
4527
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 buffer_info->skb = skb;
4529 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004530map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531 buffer_info->dma = pci_map_single(pdev,
4532 skb->data,
4533 adapter->rx_buffer_len,
4534 PCI_DMA_FROMDEVICE);
4535
Malli Chilakala26483452005-04-28 19:44:46 -07004536 /* Fix for errata 23, can't cross 64kB boundary */
4537 if (!e1000_check_64k_bound(adapter,
4538 (void *)(unsigned long)buffer_info->dma,
4539 adapter->rx_buffer_len)) {
4540 DPRINTK(RX_ERR, ERR,
4541 "dma align check failed: %u bytes at %p\n",
4542 adapter->rx_buffer_len,
4543 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 dev_kfree_skb(skb);
4545 buffer_info->skb = NULL;
4546
Malli Chilakala26483452005-04-28 19:44:46 -07004547 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 adapter->rx_buffer_len,
4549 PCI_DMA_FROMDEVICE);
4550
4551 break; /* while !buffer_info->skb */
4552 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 rx_desc = E1000_RX_DESC(*rx_ring, i);
4554 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4555
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004556 if (unlikely(++i == rx_ring->count))
4557 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558 buffer_info = &rx_ring->buffer_info[i];
4559 }
4560
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004561 if (likely(rx_ring->next_to_use != i)) {
4562 rx_ring->next_to_use = i;
4563 if (unlikely(i-- == 0))
4564 i = (rx_ring->count - 1);
4565
4566 /* Force memory writes to complete before letting h/w
4567 * know there are new descriptors to fetch. (Only
4568 * applicable for weak-ordered memory model archs,
4569 * such as IA-64). */
4570 wmb();
4571 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573}
4574
4575/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004576 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4577 * @adapter: address of board private structure
4578 **/
4579
4580static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004581e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004582 struct e1000_rx_ring *rx_ring,
4583 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004584{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004585 struct net_device *netdev = adapter->netdev;
4586 struct pci_dev *pdev = adapter->pdev;
4587 union e1000_rx_desc_packet_split *rx_desc;
4588 struct e1000_buffer *buffer_info;
4589 struct e1000_ps_page *ps_page;
4590 struct e1000_ps_page_dma *ps_page_dma;
4591 struct sk_buff *skb;
4592 unsigned int i, j;
4593
4594 i = rx_ring->next_to_use;
4595 buffer_info = &rx_ring->buffer_info[i];
4596 ps_page = &rx_ring->ps_page[i];
4597 ps_page_dma = &rx_ring->ps_page_dma[i];
4598
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004599 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004600 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4601
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004602 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004603 if (j < adapter->rx_ps_pages) {
4604 if (likely(!ps_page->ps_page[j])) {
4605 ps_page->ps_page[j] =
4606 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004607 if (unlikely(!ps_page->ps_page[j])) {
4608 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004609 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004610 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004611 ps_page_dma->ps_page_dma[j] =
4612 pci_map_page(pdev,
4613 ps_page->ps_page[j],
4614 0, PAGE_SIZE,
4615 PCI_DMA_FROMDEVICE);
4616 }
4617 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004618 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004619 * this info.
4620 */
4621 rx_desc->read.buffer_addr[j+1] =
4622 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4623 } else
Al Viro3e188262007-12-11 19:49:39 +00004624 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004625 }
4626
David S. Miller87f50322006-07-31 22:39:40 -07004627 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004628 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004629
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004630 if (unlikely(!skb)) {
4631 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004632 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004633 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004634
4635 /* Make buffer alignment 2 beyond a 16 byte boundary
4636 * this will result in a 16 byte aligned IP header after
4637 * the 14 byte MAC header is removed
4638 */
4639 skb_reserve(skb, NET_IP_ALIGN);
4640
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004641 buffer_info->skb = skb;
4642 buffer_info->length = adapter->rx_ps_bsize0;
4643 buffer_info->dma = pci_map_single(pdev, skb->data,
4644 adapter->rx_ps_bsize0,
4645 PCI_DMA_FROMDEVICE);
4646
4647 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4648
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004649 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004650 buffer_info = &rx_ring->buffer_info[i];
4651 ps_page = &rx_ring->ps_page[i];
4652 ps_page_dma = &rx_ring->ps_page_dma[i];
4653 }
4654
4655no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004656 if (likely(rx_ring->next_to_use != i)) {
4657 rx_ring->next_to_use = i;
4658 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4659
4660 /* Force memory writes to complete before letting h/w
4661 * know there are new descriptors to fetch. (Only
4662 * applicable for weak-ordered memory model archs,
4663 * such as IA-64). */
4664 wmb();
4665 /* Hardware increments by 16 bytes, but packet split
4666 * descriptors are 32 bytes...so we increment tail
4667 * twice as much.
4668 */
4669 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4670 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004671}
4672
4673/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4675 * @adapter:
4676 **/
4677
4678static void
4679e1000_smartspeed(struct e1000_adapter *adapter)
4680{
4681 uint16_t phy_status;
4682 uint16_t phy_ctrl;
4683
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004684 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4686 return;
4687
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004688 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689 /* If Master/Slave config fault is asserted twice,
4690 * we assume back-to-back */
4691 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004692 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004694 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004696 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4698 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4699 phy_ctrl);
4700 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004701 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4703 &phy_ctrl)) {
4704 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4705 MII_CR_RESTART_AUTO_NEG);
4706 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4707 phy_ctrl);
4708 }
4709 }
4710 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004711 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 /* If still no link, perhaps using 2/3 pair cable */
4713 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4714 phy_ctrl |= CR_1000T_MS_ENABLE;
4715 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004716 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4718 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4719 MII_CR_RESTART_AUTO_NEG);
4720 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4721 }
4722 }
4723 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004724 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725 adapter->smartspeed = 0;
4726}
4727
4728/**
4729 * e1000_ioctl -
4730 * @netdev:
4731 * @ifreq:
4732 * @cmd:
4733 **/
4734
4735static int
4736e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4737{
4738 switch (cmd) {
4739 case SIOCGMIIPHY:
4740 case SIOCGMIIREG:
4741 case SIOCSMIIREG:
4742 return e1000_mii_ioctl(netdev, ifr, cmd);
4743 default:
4744 return -EOPNOTSUPP;
4745 }
4746}
4747
4748/**
4749 * e1000_mii_ioctl -
4750 * @netdev:
4751 * @ifreq:
4752 * @cmd:
4753 **/
4754
4755static int
4756e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4757{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004758 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 struct mii_ioctl_data *data = if_mii(ifr);
4760 int retval;
4761 uint16_t mii_reg;
4762 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004763 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004765 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 return -EOPNOTSUPP;
4767
4768 switch (cmd) {
4769 case SIOCGMIIPHY:
4770 data->phy_id = adapter->hw.phy_addr;
4771 break;
4772 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004773 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004775 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004776 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004777 &data->val_out)) {
4778 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004780 }
4781 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 break;
4783 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004784 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004786 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 return -EFAULT;
4788 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004789 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004790 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004791 mii_reg)) {
4792 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004794 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004795 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Auke Kokdc86d322006-04-18 12:30:51 -07004796 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 switch (data->reg_num) {
4798 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004799 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004801 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 adapter->hw.autoneg = 1;
4803 adapter->hw.autoneg_advertised = 0x2F;
4804 } else {
4805 if (mii_reg & 0x40)
4806 spddplx = SPEED_1000;
4807 else if (mii_reg & 0x2000)
4808 spddplx = SPEED_100;
4809 else
4810 spddplx = SPEED_10;
4811 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004812 ? DUPLEX_FULL :
4813 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 retval = e1000_set_spd_dplx(adapter,
4815 spddplx);
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004816 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817 return retval;
4818 }
Auke Kok2db10a02006-06-27 09:06:28 -07004819 if (netif_running(adapter->netdev))
4820 e1000_reinit_locked(adapter);
4821 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 e1000_reset(adapter);
4823 break;
4824 case M88E1000_PHY_SPEC_CTRL:
4825 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004826 if (e1000_phy_reset(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 return -EIO;
4828 break;
4829 }
4830 } else {
4831 switch (data->reg_num) {
4832 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004833 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004835 if (netif_running(adapter->netdev))
4836 e1000_reinit_locked(adapter);
4837 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 e1000_reset(adapter);
4839 break;
4840 }
4841 }
4842 break;
4843 default:
4844 return -EOPNOTSUPP;
4845 }
4846 return E1000_SUCCESS;
4847}
4848
4849void
4850e1000_pci_set_mwi(struct e1000_hw *hw)
4851{
4852 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004853 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004855 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004856 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857}
4858
4859void
4860e1000_pci_clear_mwi(struct e1000_hw *hw)
4861{
4862 struct e1000_adapter *adapter = hw->back;
4863
4864 pci_clear_mwi(adapter->pdev);
4865}
4866
4867void
4868e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4869{
4870 struct e1000_adapter *adapter = hw->back;
4871
4872 pci_read_config_word(adapter->pdev, reg, value);
4873}
4874
4875void
4876e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4877{
4878 struct e1000_adapter *adapter = hw->back;
4879
4880 pci_write_config_word(adapter->pdev, reg, *value);
4881}
4882
Peter Oruba007755e2007-09-28 22:42:06 -07004883int
4884e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4885{
4886 struct e1000_adapter *adapter = hw->back;
4887 return pcix_get_mmrbc(adapter->pdev);
4888}
4889
4890void
4891e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4892{
4893 struct e1000_adapter *adapter = hw->back;
4894 pcix_set_mmrbc(adapter->pdev, mmrbc);
4895}
4896
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004897int32_t
4898e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4899{
4900 struct e1000_adapter *adapter = hw->back;
4901 uint16_t cap_offset;
4902
4903 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4904 if (!cap_offset)
4905 return -E1000_ERR_CONFIG;
4906
4907 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4908
4909 return E1000_SUCCESS;
4910}
4911
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912void
4913e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4914{
4915 outl(value, port);
4916}
4917
4918static void
4919e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4920{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004921 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 uint32_t ctrl, rctl;
4923
4924 e1000_irq_disable(adapter);
4925 adapter->vlgrp = grp;
4926
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004927 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928 /* enable VLAN tag insert/strip */
4929 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4930 ctrl |= E1000_CTRL_VME;
4931 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4932
Auke Kokcd94dd02006-06-27 09:08:22 -07004933 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004934 /* enable VLAN receive filtering */
4935 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4936 rctl |= E1000_RCTL_VFE;
4937 rctl &= ~E1000_RCTL_CFIEN;
4938 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4939 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 } else {
4942 /* disable VLAN tag insert/strip */
4943 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4944 ctrl &= ~E1000_CTRL_VME;
4945 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4946
Auke Kokcd94dd02006-06-27 09:08:22 -07004947 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004948 /* disable VLAN filtering */
4949 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4950 rctl &= ~E1000_RCTL_VFE;
4951 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4952 if (adapter->mng_vlan_id !=
4953 (uint16_t)E1000_MNG_VLAN_NONE) {
4954 e1000_vlan_rx_kill_vid(netdev,
4955 adapter->mng_vlan_id);
4956 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4957 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004958 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959 }
4960
4961 e1000_irq_enable(adapter);
4962}
4963
4964static void
4965e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4966{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004967 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004969
4970 if ((adapter->hw.mng_cookie.status &
4971 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4972 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004973 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974 /* add VID to filter table */
4975 index = (vid >> 5) & 0x7F;
4976 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4977 vfta |= (1 << (vid & 0x1F));
4978 e1000_write_vfta(&adapter->hw, index, vfta);
4979}
4980
4981static void
4982e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4983{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004984 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 uint32_t vfta, index;
4986
4987 e1000_irq_disable(adapter);
Dan Aloni5c15bde2007-03-02 20:44:51 -08004988 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 e1000_irq_enable(adapter);
4990
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004991 if ((adapter->hw.mng_cookie.status &
4992 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004993 (vid == adapter->mng_vlan_id)) {
4994 /* release control to f/w */
4995 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004996 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004997 }
4998
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 /* remove VID from filter table */
5000 index = (vid >> 5) & 0x7F;
5001 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
5002 vfta &= ~(1 << (vid & 0x1F));
5003 e1000_write_vfta(&adapter->hw, index, vfta);
5004}
5005
5006static void
5007e1000_restore_vlan(struct e1000_adapter *adapter)
5008{
5009 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
5010
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005011 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005013 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08005014 if (!vlan_group_get_device(adapter->vlgrp, vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015 continue;
5016 e1000_vlan_rx_add_vid(adapter->netdev, vid);
5017 }
5018 }
5019}
5020
5021int
5022e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
5023{
5024 adapter->hw.autoneg = 0;
5025
Malli Chilakala69213682005-06-17 17:44:20 -07005026 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005027 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07005028 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
5029 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
5030 return -EINVAL;
5031 }
5032
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005033 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 case SPEED_10 + DUPLEX_HALF:
5035 adapter->hw.forced_speed_duplex = e1000_10_half;
5036 break;
5037 case SPEED_10 + DUPLEX_FULL:
5038 adapter->hw.forced_speed_duplex = e1000_10_full;
5039 break;
5040 case SPEED_100 + DUPLEX_HALF:
5041 adapter->hw.forced_speed_duplex = e1000_100_half;
5042 break;
5043 case SPEED_100 + DUPLEX_FULL:
5044 adapter->hw.forced_speed_duplex = e1000_100_full;
5045 break;
5046 case SPEED_1000 + DUPLEX_FULL:
5047 adapter->hw.autoneg = 1;
5048 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
5049 break;
5050 case SPEED_1000 + DUPLEX_HALF: /* not supported */
5051 default:
Malli Chilakala26483452005-04-28 19:44:46 -07005052 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053 return -EINVAL;
5054 }
5055 return 0;
5056}
5057
5058static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07005059e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005060{
5061 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005062 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005063 uint32_t ctrl, ctrl_ext, rctl, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07005065#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08005066 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07005067#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068
5069 netif_device_detach(netdev);
5070
Auke Kok2db10a02006-06-27 09:06:28 -07005071 if (netif_running(netdev)) {
5072 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07005074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005076#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005077 retval = pci_save_state(pdev);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005078 if (retval)
5079 return retval;
5080#endif
5081
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005083 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 wufc &= ~E1000_WUFC_LNKC;
5085
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005086 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005088 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089
5090 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005091 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092 rctl = E1000_READ_REG(&adapter->hw, RCTL);
5093 rctl |= E1000_RCTL_MPE;
5094 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
5095 }
5096
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005097 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
5099 /* advertise wake from D3Cold */
5100 #define E1000_CTRL_ADVD3WUC 0x00100000
5101 /* phy power management enable */
5102 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5103 ctrl |= E1000_CTRL_ADVD3WUC |
5104 E1000_CTRL_EN_PHY_PWR_MGMT;
5105 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
5106 }
5107
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005108 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 adapter->hw.media_type == e1000_media_type_internal_serdes) {
5110 /* keep the laser running in D3 */
5111 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
5112 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5113 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
5114 }
5115
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005116 /* Allow time for pending master requests to run */
5117 e1000_disable_pciex_master(&adapter->hw);
5118
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
5120 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07005121 pci_enable_wake(pdev, PCI_D3hot, 1);
5122 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 } else {
5124 E1000_WRITE_REG(&adapter->hw, WUC, 0);
5125 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07005126 pci_enable_wake(pdev, PCI_D3hot, 0);
5127 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 }
5129
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005130 e1000_release_manageability(adapter);
5131
5132 /* make sure adapter isn't asleep if manageability is enabled */
5133 if (adapter->en_mng_pt) {
5134 pci_enable_wake(pdev, PCI_D3hot, 1);
5135 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 }
5137
Auke Kokcd94dd02006-06-27 09:08:22 -07005138 if (adapter->hw.phy_type == e1000_phy_igp_3)
5139 e1000_phy_powerdown_workaround(&adapter->hw);
5140
Auke Kokedd106f2006-11-06 08:57:12 -08005141 if (netif_running(netdev))
5142 e1000_free_irq(adapter);
5143
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005144 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5145 * would have already happened in close and is redundant. */
5146 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005147
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005149
Auke Kokd0e027d2006-04-14 19:04:40 -07005150 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151
5152 return 0;
5153}
5154
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005155#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156static int
5157e1000_resume(struct pci_dev *pdev)
5158{
5159 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005160 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005161 uint32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162
Auke Kokd0e027d2006-04-14 19:04:40 -07005163 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005164 pci_restore_state(pdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005165 if ((err = pci_enable_device(pdev))) {
5166 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5167 return err;
5168 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005169 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170
Auke Kokd0e027d2006-04-14 19:04:40 -07005171 pci_enable_wake(pdev, PCI_D3hot, 0);
5172 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173
Auke Kokedd106f2006-11-06 08:57:12 -08005174 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
5175 return err;
5176
5177 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178 e1000_reset(adapter);
5179 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5180
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005181 e1000_init_manageability(adapter);
5182
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005183 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184 e1000_up(adapter);
5185
5186 netif_device_attach(netdev);
5187
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005188 /* If the controller is 82573 and f/w is AMT, do not set
5189 * DRV_LOAD until the interface is up. For all other cases,
5190 * let the f/w know that the h/w is now under the control
5191 * of the driver. */
5192 if (adapter->hw.mac_type != e1000_82573 ||
5193 !e1000_check_mng_mode(&adapter->hw))
5194 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005195
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196 return 0;
5197}
5198#endif
Auke Kokc653e632006-05-23 13:35:57 -07005199
5200static void e1000_shutdown(struct pci_dev *pdev)
5201{
5202 e1000_suspend(pdev, PMSG_SUSPEND);
5203}
5204
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205#ifdef CONFIG_NET_POLL_CONTROLLER
5206/*
5207 * Polling 'interrupt' - used by things like netconsole to send skbs
5208 * without having to re-enable interrupts. It's not called while
5209 * the interrupt routine is executing.
5210 */
5211static void
Malli Chilakala26483452005-04-28 19:44:46 -07005212e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005213{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005214 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005215
Linus Torvalds1da177e2005-04-16 15:20:36 -07005216 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005217 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07005218 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08005219#ifndef CONFIG_E1000_NAPI
5220 adapter->clean_rx(adapter, adapter->rx_ring);
5221#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222 enable_irq(adapter->pdev->irq);
5223}
5224#endif
5225
Auke Kok90267292006-06-08 09:30:24 -07005226/**
5227 * e1000_io_error_detected - called when PCI error is detected
5228 * @pdev: Pointer to PCI device
5229 * @state: The current pci conneection state
5230 *
5231 * This function is called after a PCI bus error affecting
5232 * this device has been detected.
5233 */
5234static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5235{
5236 struct net_device *netdev = pci_get_drvdata(pdev);
5237 struct e1000_adapter *adapter = netdev->priv;
5238
5239 netif_device_detach(netdev);
5240
5241 if (netif_running(netdev))
5242 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005243 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005244
5245 /* Request a slot slot reset. */
5246 return PCI_ERS_RESULT_NEED_RESET;
5247}
5248
5249/**
5250 * e1000_io_slot_reset - called after the pci bus has been reset.
5251 * @pdev: Pointer to PCI device
5252 *
5253 * Restart the card from scratch, as if from a cold-boot. Implementation
5254 * resembles the first-half of the e1000_resume routine.
5255 */
5256static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5257{
5258 struct net_device *netdev = pci_get_drvdata(pdev);
5259 struct e1000_adapter *adapter = netdev->priv;
5260
5261 if (pci_enable_device(pdev)) {
5262 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5263 return PCI_ERS_RESULT_DISCONNECT;
5264 }
5265 pci_set_master(pdev);
5266
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005267 pci_enable_wake(pdev, PCI_D3hot, 0);
5268 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005269
Auke Kok90267292006-06-08 09:30:24 -07005270 e1000_reset(adapter);
5271 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5272
5273 return PCI_ERS_RESULT_RECOVERED;
5274}
5275
5276/**
5277 * e1000_io_resume - called when traffic can start flowing again.
5278 * @pdev: Pointer to PCI device
5279 *
5280 * This callback is called when the error recovery driver tells us that
5281 * its OK to resume normal operation. Implementation resembles the
5282 * second-half of the e1000_resume routine.
5283 */
5284static void e1000_io_resume(struct pci_dev *pdev)
5285{
5286 struct net_device *netdev = pci_get_drvdata(pdev);
5287 struct e1000_adapter *adapter = netdev->priv;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005288
5289 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005290
5291 if (netif_running(netdev)) {
5292 if (e1000_up(adapter)) {
5293 printk("e1000: can't bring device back up after reset\n");
5294 return;
5295 }
5296 }
5297
5298 netif_device_attach(netdev);
5299
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005300 /* If the controller is 82573 and f/w is AMT, do not set
5301 * DRV_LOAD until the interface is up. For all other cases,
5302 * let the f/w know that the h/w is now under the control
5303 * of the driver. */
5304 if (adapter->hw.mac_type != e1000_82573 ||
5305 !e1000_check_mng_mode(&adapter->hw))
5306 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005307
Auke Kok90267292006-06-08 09:30:24 -07005308}
5309
Linus Torvalds1da177e2005-04-16 15:20:36 -07005310/* e1000_main.c */