blob: d7df00c2dbd6ea0f97f3819878b1d815c02d6a42 [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";
Jesse Brandeburg15b2bee2009-01-27 16:41:58 -080034#define DRV_VERSION "7.3.21-k3-NAPI"
Stephen Hemmingerabec42a2007-10-29 10:46:19 -070035const char e1000_driver_version[] = DRV_VERSION;
36static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38/* e1000_pci_tbl - PCI Device ID Table
39 *
40 * Last entry must be all 0s
41 *
42 * Macro expands to...
43 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
44 */
45static struct pci_device_id e1000_pci_tbl[] = {
46 INTEL_E1000_ETHERNET_DEVICE(0x1000),
47 INTEL_E1000_ETHERNET_DEVICE(0x1001),
48 INTEL_E1000_ETHERNET_DEVICE(0x1004),
49 INTEL_E1000_ETHERNET_DEVICE(0x1008),
50 INTEL_E1000_ETHERNET_DEVICE(0x1009),
51 INTEL_E1000_ETHERNET_DEVICE(0x100C),
52 INTEL_E1000_ETHERNET_DEVICE(0x100D),
53 INTEL_E1000_ETHERNET_DEVICE(0x100E),
54 INTEL_E1000_ETHERNET_DEVICE(0x100F),
55 INTEL_E1000_ETHERNET_DEVICE(0x1010),
56 INTEL_E1000_ETHERNET_DEVICE(0x1011),
57 INTEL_E1000_ETHERNET_DEVICE(0x1012),
58 INTEL_E1000_ETHERNET_DEVICE(0x1013),
59 INTEL_E1000_ETHERNET_DEVICE(0x1014),
60 INTEL_E1000_ETHERNET_DEVICE(0x1015),
61 INTEL_E1000_ETHERNET_DEVICE(0x1016),
62 INTEL_E1000_ETHERNET_DEVICE(0x1017),
63 INTEL_E1000_ETHERNET_DEVICE(0x1018),
64 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -070065 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 INTEL_E1000_ETHERNET_DEVICE(0x101D),
67 INTEL_E1000_ETHERNET_DEVICE(0x101E),
68 INTEL_E1000_ETHERNET_DEVICE(0x1026),
69 INTEL_E1000_ETHERNET_DEVICE(0x1027),
70 INTEL_E1000_ETHERNET_DEVICE(0x1028),
71 INTEL_E1000_ETHERNET_DEVICE(0x1075),
72 INTEL_E1000_ETHERNET_DEVICE(0x1076),
73 INTEL_E1000_ETHERNET_DEVICE(0x1077),
74 INTEL_E1000_ETHERNET_DEVICE(0x1078),
75 INTEL_E1000_ETHERNET_DEVICE(0x1079),
76 INTEL_E1000_ETHERNET_DEVICE(0x107A),
77 INTEL_E1000_ETHERNET_DEVICE(0x107B),
78 INTEL_E1000_ETHERNET_DEVICE(0x107C),
79 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080080 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080081 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 /* required last entry */
83 {0,}
84};
85
86MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
87
Nicholas Nunley35574762006-09-27 12:53:34 -070088int e1000_up(struct e1000_adapter *adapter);
89void e1000_down(struct e1000_adapter *adapter);
90void e1000_reinit_locked(struct e1000_adapter *adapter);
91void e1000_reset(struct e1000_adapter *adapter);
Joe Perches406874a2008-04-03 10:06:32 -070092int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx);
Nicholas Nunley35574762006-09-27 12:53:34 -070093int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
94int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
95void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
96void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010097static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -070098 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010099static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700100 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100101static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700102 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100103static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700104 struct e1000_rx_ring *rx_ring);
105void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107static int e1000_init_module(void);
108static void e1000_exit_module(void);
109static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
110static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400111static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static int e1000_sw_init(struct e1000_adapter *adapter);
113static int e1000_open(struct net_device *netdev);
114static int e1000_close(struct net_device *netdev);
115static void e1000_configure_tx(struct e1000_adapter *adapter);
116static void e1000_configure_rx(struct e1000_adapter *adapter);
117static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400118static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
119static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
120static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
121 struct e1000_tx_ring *tx_ring);
122static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
123 struct e1000_rx_ring *rx_ring);
Patrick McHardydb0ce502007-11-13 20:54:59 -0800124static void e1000_set_rx_mode(struct net_device *netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125static void e1000_update_phy_info(unsigned long data);
126static void e1000_watchdog(unsigned long data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127static void e1000_82547_tx_fifo_stall(unsigned long data);
128static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
129static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
130static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
131static int e1000_set_mac(struct net_device *netdev, void *p);
David Howells7d12e782006-10-05 14:55:46 +0100132static irqreturn_t e1000_intr(int irq, void *data);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -0800133static irqreturn_t e1000_intr_msi(int irq, void *data);
Joe Perchesc3033b02008-03-21 11:06:25 -0700134static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
135 struct e1000_tx_ring *tx_ring);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700136static int e1000_clean(struct napi_struct *napi, int budget);
Joe Perchesc3033b02008-03-21 11:06:25 -0700137static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
138 struct e1000_rx_ring *rx_ring,
139 int *work_done, int work_to_do);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +0000140static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
141 struct e1000_rx_ring *rx_ring,
142 int *work_done, int work_to_do);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400143static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +0000144 struct e1000_rx_ring *rx_ring,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800145 int cleaned_count);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +0000146static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
148 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
150static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
151 int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
153static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
154static void e1000_tx_timeout(struct net_device *dev);
David Howells65f27f32006-11-22 14:55:48 +0000155static void e1000_reset_task(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d5232006-04-14 19:04:52 -0700157static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
158 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
Joe Perches406874a2008-04-03 10:06:32 -0700161static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
162static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static void e1000_restore_vlan(struct e1000_adapter *adapter);
164
Auke Kok6fdfef12006-06-27 09:06:36 -0700165#ifdef CONFIG_PM
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +0000166static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167static int e1000_resume(struct pci_dev *pdev);
168#endif
Auke Kokc653e632006-05-23 13:35:57 -0700169static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171#ifdef CONFIG_NET_POLL_CONTROLLER
172/* for netdump / net console */
173static void e1000_netpoll (struct net_device *netdev);
174#endif
175
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100176#define COPYBREAK_DEFAULT 256
177static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
178module_param(copybreak, uint, 0644);
179MODULE_PARM_DESC(copybreak,
180 "Maximum size of packet that is copied to a new buffer on receive");
181
Auke Kok90267292006-06-08 09:30:24 -0700182static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
183 pci_channel_state_t state);
184static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
185static void e1000_io_resume(struct pci_dev *pdev);
186
187static struct pci_error_handlers e1000_err_handler = {
188 .error_detected = e1000_io_error_detected,
189 .slot_reset = e1000_io_slot_reset,
190 .resume = e1000_io_resume,
191};
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193static struct pci_driver e1000_driver = {
194 .name = e1000_driver_name,
195 .id_table = e1000_pci_tbl,
196 .probe = e1000_probe,
197 .remove = __devexit_p(e1000_remove),
Auke Kokc4e24f02006-09-27 12:53:19 -0700198#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 /* Power Managment Hooks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 .suspend = e1000_suspend,
Auke Kokc653e632006-05-23 13:35:57 -0700201 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#endif
Auke Kok90267292006-06-08 09:30:24 -0700203 .shutdown = e1000_shutdown,
204 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205};
206
207MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
208MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
209MODULE_LICENSE("GPL");
210MODULE_VERSION(DRV_VERSION);
211
212static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
213module_param(debug, int, 0);
214MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
215
216/**
217 * e1000_init_module - Driver Registration Routine
218 *
219 * e1000_init_module is the first routine called when the driver is
220 * loaded. All it does is register with the PCI subsystem.
221 **/
222
Joe Perches64798842008-07-11 15:17:02 -0700223static int __init e1000_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
225 int ret;
226 printk(KERN_INFO "%s - version %s\n",
227 e1000_driver_string, e1000_driver_version);
228
229 printk(KERN_INFO "%s\n", e1000_copyright);
230
Jeff Garzik29917622006-08-19 17:48:59 -0400231 ret = pci_register_driver(&e1000_driver);
Jesse Brandeburg1f753862006-12-15 10:40:39 +0100232 if (copybreak != COPYBREAK_DEFAULT) {
233 if (copybreak == 0)
234 printk(KERN_INFO "e1000: copybreak disabled\n");
235 else
236 printk(KERN_INFO "e1000: copybreak enabled for "
237 "packets <= %u bytes\n", copybreak);
238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 return ret;
240}
241
242module_init(e1000_init_module);
243
244/**
245 * e1000_exit_module - Driver Exit Cleanup Routine
246 *
247 * e1000_exit_module is called just before the driver is removed
248 * from memory.
249 **/
250
Joe Perches64798842008-07-11 15:17:02 -0700251static void __exit e1000_exit_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 pci_unregister_driver(&e1000_driver);
254}
255
256module_exit(e1000_exit_module);
257
Auke Kok2db10a02006-06-27 09:06:28 -0700258static int e1000_request_irq(struct e1000_adapter *adapter)
259{
Joe Perches1dc32912008-07-11 15:17:08 -0700260 struct e1000_hw *hw = &adapter->hw;
Auke Kok2db10a02006-06-27 09:06:28 -0700261 struct net_device *netdev = adapter->netdev;
Al Viro3e188262007-12-11 19:49:39 +0000262 irq_handler_t handler = e1000_intr;
Auke Koke94bd232007-05-16 01:49:46 -0700263 int irq_flags = IRQF_SHARED;
264 int err;
Auke Kok2db10a02006-06-27 09:06:28 -0700265
Joe Perches1dc32912008-07-11 15:17:08 -0700266 if (hw->mac_type >= e1000_82571) {
Auke Koke94bd232007-05-16 01:49:46 -0700267 adapter->have_msi = !pci_enable_msi(adapter->pdev);
268 if (adapter->have_msi) {
Al Viro3e188262007-12-11 19:49:39 +0000269 handler = e1000_intr_msi;
Auke Koke94bd232007-05-16 01:49:46 -0700270 irq_flags = 0;
Auke Kok2db10a02006-06-27 09:06:28 -0700271 }
272 }
Auke Koke94bd232007-05-16 01:49:46 -0700273
274 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
275 netdev);
276 if (err) {
277 if (adapter->have_msi)
278 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700279 DPRINTK(PROBE, ERR,
280 "Unable to allocate interrupt Error: %d\n", err);
Auke Koke94bd232007-05-16 01:49:46 -0700281 }
Auke Kok2db10a02006-06-27 09:06:28 -0700282
283 return err;
284}
285
286static void e1000_free_irq(struct e1000_adapter *adapter)
287{
288 struct net_device *netdev = adapter->netdev;
289
290 free_irq(adapter->pdev->irq, netdev);
291
Auke Kok2db10a02006-06-27 09:06:28 -0700292 if (adapter->have_msi)
293 pci_disable_msi(adapter->pdev);
Auke Kok2db10a02006-06-27 09:06:28 -0700294}
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296/**
297 * e1000_irq_disable - Mask off interrupt generation on the NIC
298 * @adapter: board private structure
299 **/
300
Joe Perches64798842008-07-11 15:17:02 -0700301static void e1000_irq_disable(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Joe Perches1dc32912008-07-11 15:17:08 -0700303 struct e1000_hw *hw = &adapter->hw;
304
305 ew32(IMC, ~0);
306 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 synchronize_irq(adapter->pdev->irq);
308}
309
310/**
311 * e1000_irq_enable - Enable default interrupt generation settings
312 * @adapter: board private structure
313 **/
314
Joe Perches64798842008-07-11 15:17:02 -0700315static void e1000_irq_enable(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
Joe Perches1dc32912008-07-11 15:17:08 -0700317 struct e1000_hw *hw = &adapter->hw;
318
319 ew32(IMS, IMS_ENABLE_MASK);
320 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100322
Joe Perches64798842008-07-11 15:17:02 -0700323static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700324{
Joe Perches1dc32912008-07-11 15:17:08 -0700325 struct e1000_hw *hw = &adapter->hw;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700326 struct net_device *netdev = adapter->netdev;
Joe Perches1dc32912008-07-11 15:17:08 -0700327 u16 vid = hw->mng_cookie.vlan_id;
Joe Perches406874a2008-04-03 10:06:32 -0700328 u16 old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800329 if (adapter->vlgrp) {
Dan Aloni5c15bde2007-03-02 20:44:51 -0800330 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
Joe Perches1dc32912008-07-11 15:17:08 -0700331 if (hw->mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700332 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
333 e1000_vlan_rx_add_vid(netdev, vid);
334 adapter->mng_vlan_id = vid;
335 } else
336 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800337
Joe Perches406874a2008-04-03 10:06:32 -0700338 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800339 (vid != old_vid) &&
Dan Aloni5c15bde2007-03-02 20:44:51 -0800340 !vlan_group_get_device(adapter->vlgrp, old_vid))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700341 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800342 } else
343 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700344 }
345}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800346
347/**
348 * e1000_release_hw_control - release control of the h/w to f/w
349 * @adapter: address of board private structure
350 *
351 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
352 * For ASF and Pass Through versions of f/w this means that the
353 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800354 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700355 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800356 **/
357
Joe Perches64798842008-07-11 15:17:02 -0700358static void e1000_release_hw_control(struct e1000_adapter *adapter)
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800359{
Joe Perches406874a2008-04-03 10:06:32 -0700360 u32 ctrl_ext;
361 u32 swsm;
Joe Perches1dc32912008-07-11 15:17:08 -0700362 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800363
364 /* Let firmware taken over control of h/w */
Joe Perches1dc32912008-07-11 15:17:08 -0700365 switch (hw->mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800366 case e1000_82573:
Joe Perches1dc32912008-07-11 15:17:08 -0700367 swsm = er32(SWSM);
368 ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
Bruce Allan31d76442007-03-06 08:57:24 -0800369 break;
370 case e1000_82571:
371 case e1000_82572:
372 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700373 case e1000_ich8lan:
Joe Perches1dc32912008-07-11 15:17:08 -0700374 ctrl_ext = er32(CTRL_EXT);
375 ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700376 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800377 default:
378 break;
379 }
380}
381
382/**
383 * e1000_get_hw_control - get control of the h/w from f/w
384 * @adapter: address of board private structure
385 *
386 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700387 * For ASF and Pass Through versions of f/w this means that
388 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800389 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700390 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800391 **/
392
Joe Perches64798842008-07-11 15:17:02 -0700393static void e1000_get_hw_control(struct e1000_adapter *adapter)
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800394{
Joe Perches406874a2008-04-03 10:06:32 -0700395 u32 ctrl_ext;
396 u32 swsm;
Joe Perches1dc32912008-07-11 15:17:08 -0700397 struct e1000_hw *hw = &adapter->hw;
Auke Kok90fb5132006-11-01 08:47:30 -0800398
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800399 /* Let firmware know the driver has taken over */
Joe Perches1dc32912008-07-11 15:17:08 -0700400 switch (hw->mac_type) {
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800401 case e1000_82573:
Joe Perches1dc32912008-07-11 15:17:08 -0700402 swsm = er32(SWSM);
403 ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800404 break;
Bruce Allan31d76442007-03-06 08:57:24 -0800405 case e1000_82571:
406 case e1000_82572:
407 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700408 case e1000_ich8lan:
Joe Perches1dc32912008-07-11 15:17:08 -0700409 ctrl_ext = er32(CTRL_EXT);
410 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700411 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800412 default:
413 break;
414 }
415}
416
Joe Perches64798842008-07-11 15:17:02 -0700417static void e1000_init_manageability(struct e1000_adapter *adapter)
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500418{
Joe Perches1dc32912008-07-11 15:17:08 -0700419 struct e1000_hw *hw = &adapter->hw;
420
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500421 if (adapter->en_mng_pt) {
Joe Perches1dc32912008-07-11 15:17:08 -0700422 u32 manc = er32(MANC);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500423
424 /* disable hardware interception of ARP */
425 manc &= ~(E1000_MANC_ARP_EN);
426
427 /* enable receiving management packets to the host */
428 /* this will probably generate destination unreachable messages
429 * from the host OS, but the packets will be handled on SMBUS */
Joe Perches1dc32912008-07-11 15:17:08 -0700430 if (hw->has_manc2h) {
431 u32 manc2h = er32(MANC2H);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500432
433 manc |= E1000_MANC_EN_MNG2HOST;
434#define E1000_MNG2HOST_PORT_623 (1 << 5)
435#define E1000_MNG2HOST_PORT_664 (1 << 6)
436 manc2h |= E1000_MNG2HOST_PORT_623;
437 manc2h |= E1000_MNG2HOST_PORT_664;
Joe Perches1dc32912008-07-11 15:17:08 -0700438 ew32(MANC2H, manc2h);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500439 }
440
Joe Perches1dc32912008-07-11 15:17:08 -0700441 ew32(MANC, manc);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500442 }
443}
444
Joe Perches64798842008-07-11 15:17:02 -0700445static void e1000_release_manageability(struct e1000_adapter *adapter)
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500446{
Joe Perches1dc32912008-07-11 15:17:08 -0700447 struct e1000_hw *hw = &adapter->hw;
448
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500449 if (adapter->en_mng_pt) {
Joe Perches1dc32912008-07-11 15:17:08 -0700450 u32 manc = er32(MANC);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500451
452 /* re-enable hardware interception of ARP */
453 manc |= E1000_MANC_ARP_EN;
454
Joe Perches1dc32912008-07-11 15:17:08 -0700455 if (hw->has_manc2h)
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500456 manc &= ~E1000_MANC_EN_MNG2HOST;
457
458 /* don't explicitly have to mess with MANC2H since
459 * MANC has an enable disable that gates MANC2H */
460
Joe Perches1dc32912008-07-11 15:17:08 -0700461 ew32(MANC, manc);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500462 }
463}
464
Auke Koke0aac5a2007-03-06 08:57:21 -0800465/**
466 * e1000_configure - configure the hardware for RX and TX
467 * @adapter = private board structure
468 **/
469static void e1000_configure(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
471 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700472 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Patrick McHardydb0ce502007-11-13 20:54:59 -0800474 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 e1000_restore_vlan(adapter);
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500477 e1000_init_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 e1000_configure_tx(adapter);
480 e1000_setup_rctl(adapter);
481 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800482 /* call E1000_DESC_UNUSED which always leaves
483 * at least 1 descriptor unused to make sure
484 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800485 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800486 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800487 adapter->alloc_rx_buf(adapter, ring,
488 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800491 adapter->tx_queue_len = netdev->tx_queue_len;
Auke Koke0aac5a2007-03-06 08:57:21 -0800492}
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800493
Auke Koke0aac5a2007-03-06 08:57:21 -0800494int e1000_up(struct e1000_adapter *adapter)
495{
Joe Perches1dc32912008-07-11 15:17:08 -0700496 struct e1000_hw *hw = &adapter->hw;
497
Auke Koke0aac5a2007-03-06 08:57:21 -0800498 /* hardware has been reset, we need to reload some things */
499 e1000_configure(adapter);
Malli Chilakala5de55622005-04-28 19:39:30 -0700500
Auke Kok1314bbf2006-09-27 12:54:02 -0700501 clear_bit(__E1000_DOWN, &adapter->flags);
502
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700503 napi_enable(&adapter->napi);
Francois Romieuc3570ac2008-07-11 15:17:38 -0700504
Auke Koke0aac5a2007-03-06 08:57:21 -0800505 e1000_irq_enable(adapter);
506
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +0000507 netif_wake_queue(adapter->netdev);
508
Jesse Brandeburg79f3d392006-12-15 10:42:34 +0100509 /* fire a link change interrupt to start the watchdog */
Joe Perches1dc32912008-07-11 15:17:08 -0700510 ew32(ICS, E1000_ICS_LSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 return 0;
512}
513
Auke Kok79f05bf2006-06-27 09:06:32 -0700514/**
515 * e1000_power_up_phy - restore link in case the phy was powered down
516 * @adapter: address of board private structure
517 *
518 * The phy may be powered down to save power and turn off link when the
519 * driver is unloaded and wake on lan is not enabled (among others)
520 * *** this routine MUST be followed by a call to e1000_reset ***
521 *
522 **/
523
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700524void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700525{
Joe Perches1dc32912008-07-11 15:17:08 -0700526 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700527 u16 mii_reg = 0;
Auke Kok79f05bf2006-06-27 09:06:32 -0700528
529 /* Just clear the power down bit to wake the phy back up */
Joe Perches1dc32912008-07-11 15:17:08 -0700530 if (hw->media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700531 /* according to the manual, the phy will retain its
532 * settings across a power-down/up cycle */
Joe Perches1dc32912008-07-11 15:17:08 -0700533 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700534 mii_reg &= ~MII_CR_POWER_DOWN;
Joe Perches1dc32912008-07-11 15:17:08 -0700535 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700536 }
537}
538
539static void e1000_power_down_phy(struct e1000_adapter *adapter)
540{
Joe Perches1dc32912008-07-11 15:17:08 -0700541 struct e1000_hw *hw = &adapter->hw;
542
Bruce Allan61c25052006-09-27 12:53:54 -0700543 /* Power down the PHY so no link is implied when interface is down *
Joe Perchesc3033b02008-03-21 11:06:25 -0700544 * The PHY cannot be powered down if any of the following is true *
Auke Kok79f05bf2006-06-27 09:06:32 -0700545 * (a) WoL is enabled
546 * (b) AMT is active
547 * (c) SoL/IDER session is active */
Joe Perches1dc32912008-07-11 15:17:08 -0700548 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
549 hw->media_type == e1000_media_type_copper) {
Joe Perches406874a2008-04-03 10:06:32 -0700550 u16 mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700551
Joe Perches1dc32912008-07-11 15:17:08 -0700552 switch (hw->mac_type) {
Bruce Allan61c25052006-09-27 12:53:54 -0700553 case e1000_82540:
554 case e1000_82545:
555 case e1000_82545_rev_3:
556 case e1000_82546:
557 case e1000_82546_rev_3:
558 case e1000_82541:
559 case e1000_82541_rev_2:
560 case e1000_82547:
561 case e1000_82547_rev_2:
Joe Perches1dc32912008-07-11 15:17:08 -0700562 if (er32(MANC) & E1000_MANC_SMBUS_EN)
Bruce Allan61c25052006-09-27 12:53:54 -0700563 goto out;
564 break;
565 case e1000_82571:
566 case e1000_82572:
567 case e1000_82573:
568 case e1000_80003es2lan:
569 case e1000_ich8lan:
Joe Perches1dc32912008-07-11 15:17:08 -0700570 if (e1000_check_mng_mode(hw) ||
571 e1000_check_phy_reset_block(hw))
Bruce Allan61c25052006-09-27 12:53:54 -0700572 goto out;
573 break;
574 default:
575 goto out;
576 }
Joe Perches1dc32912008-07-11 15:17:08 -0700577 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700578 mii_reg |= MII_CR_POWER_DOWN;
Joe Perches1dc32912008-07-11 15:17:08 -0700579 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700580 mdelay(1);
581 }
Bruce Allan61c25052006-09-27 12:53:54 -0700582out:
583 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700584}
585
Joe Perches64798842008-07-11 15:17:02 -0700586void e1000_down(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Jesse Brandeburga6c42322009-03-25 21:59:22 +0000588 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 struct net_device *netdev = adapter->netdev;
Jesse Brandeburga6c42322009-03-25 21:59:22 +0000590 u32 rctl, tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Auke Kok1314bbf2006-09-27 12:54:02 -0700592 /* signal that we're down so the interrupt handler does not
593 * reschedule our watchdog timer */
594 set_bit(__E1000_DOWN, &adapter->flags);
595
Jesse Brandeburga6c42322009-03-25 21:59:22 +0000596 /* disable receives in the hardware */
597 rctl = er32(RCTL);
598 ew32(RCTL, rctl & ~E1000_RCTL_EN);
599 /* flush and sleep below */
600
601 /* can be netif_tx_disable when NETIF_F_LLTX is removed */
602 netif_stop_queue(netdev);
603
604 /* disable transmits in the hardware */
605 tctl = er32(TCTL);
606 tctl &= ~E1000_TCTL_EN;
607 ew32(TCTL, tctl);
608 /* flush both disables and wait for them to finish */
609 E1000_WRITE_FLUSH();
610 msleep(10);
611
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700612 napi_disable(&adapter->napi);
Francois Romieuc3570ac2008-07-11 15:17:38 -0700613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 del_timer_sync(&adapter->tx_fifo_stall_timer);
617 del_timer_sync(&adapter->watchdog_timer);
618 del_timer_sync(&adapter->phy_info_timer);
619
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800620 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 adapter->link_speed = 0;
622 adapter->link_duplex = 0;
623 netif_carrier_off(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400626 e1000_clean_all_tx_rings(adapter);
627 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Joe Perches64798842008-07-11 15:17:02 -0700630void e1000_reinit_locked(struct e1000_adapter *adapter)
Auke Kok2db10a02006-06-27 09:06:28 -0700631{
632 WARN_ON(in_interrupt());
633 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
634 msleep(1);
635 e1000_down(adapter);
636 e1000_up(adapter);
637 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
639
Joe Perches64798842008-07-11 15:17:02 -0700640void e1000_reset(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
Joe Perches1dc32912008-07-11 15:17:08 -0700642 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700643 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
Joe Perchesc3033b02008-03-21 11:06:25 -0700644 bool legacy_pba_adjust = false;
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000645 u16 hwm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 /* Repartition Pba for greater than 9k mtu
648 * To take effect CTRL.RST is required.
649 */
650
Joe Perches1dc32912008-07-11 15:17:08 -0700651 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100652 case e1000_82542_rev2_0:
653 case e1000_82542_rev2_1:
654 case e1000_82543:
655 case e1000_82544:
656 case e1000_82540:
657 case e1000_82541:
658 case e1000_82541_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700659 legacy_pba_adjust = true;
Bruce Allan018ea442006-12-15 10:39:45 +0100660 pba = E1000_PBA_48K;
661 break;
662 case e1000_82545:
663 case e1000_82545_rev_3:
664 case e1000_82546:
665 case e1000_82546_rev_3:
666 pba = E1000_PBA_48K;
667 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700668 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700669 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700670 legacy_pba_adjust = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700671 pba = E1000_PBA_30K;
672 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400673 case e1000_82571:
674 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800675 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400676 pba = E1000_PBA_38K;
677 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700678 case e1000_82573:
Bruce Allan018ea442006-12-15 10:39:45 +0100679 pba = E1000_PBA_20K;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700680 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700681 case e1000_ich8lan:
682 pba = E1000_PBA_8K;
Bruce Allan018ea442006-12-15 10:39:45 +0100683 case e1000_undefined:
684 case e1000_num_macs:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700685 break;
686 }
687
Joe Perchesc3033b02008-03-21 11:06:25 -0700688 if (legacy_pba_adjust) {
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000689 if (hw->max_frame_size > E1000_RXBUFFER_8192)
Bruce Allan018ea442006-12-15 10:39:45 +0100690 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700691
Joe Perches1dc32912008-07-11 15:17:08 -0700692 if (hw->mac_type == e1000_82547) {
Bruce Allan018ea442006-12-15 10:39:45 +0100693 adapter->tx_fifo_head = 0;
694 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
695 adapter->tx_fifo_size =
696 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
697 atomic_set(&adapter->tx_fifo_stall, 0);
698 }
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000699 } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
Bruce Allan018ea442006-12-15 10:39:45 +0100700 /* adjust PBA for jumbo frames */
Joe Perches1dc32912008-07-11 15:17:08 -0700701 ew32(PBA, pba);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700702
Bruce Allan018ea442006-12-15 10:39:45 +0100703 /* To maintain wire speed transmits, the Tx FIFO should be
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000704 * large enough to accommodate two full transmit packets,
Bruce Allan018ea442006-12-15 10:39:45 +0100705 * rounded up to the next 1KB and expressed in KB. Likewise,
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000706 * the Rx FIFO should be large enough to accommodate at least
Bruce Allan018ea442006-12-15 10:39:45 +0100707 * one full receive packet and is similarly rounded up and
708 * expressed in KB. */
Joe Perches1dc32912008-07-11 15:17:08 -0700709 pba = er32(PBA);
Bruce Allan018ea442006-12-15 10:39:45 +0100710 /* upper 16 bits has Tx packet buffer allocation size in KB */
711 tx_space = pba >> 16;
712 /* lower 16 bits has Rx packet buffer allocation size in KB */
713 pba &= 0xffff;
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000714 /*
715 * the tx fifo also stores 16 bytes of information about the tx
716 * but don't include ethernet FCS because hardware appends it
717 */
718 min_tx_space = (hw->max_frame_size +
719 sizeof(struct e1000_tx_desc) -
720 ETH_FCS_LEN) * 2;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700721 min_tx_space = ALIGN(min_tx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100722 min_tx_space >>= 10;
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000723 /* software strips receive CRC, so leave room for it */
724 min_rx_space = hw->max_frame_size;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700725 min_rx_space = ALIGN(min_rx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100726 min_rx_space >>= 10;
727
728 /* If current Tx allocation is less than the min Tx FIFO size,
729 * and the min Tx FIFO size is less than the current Rx FIFO
730 * allocation, take space away from current Rx allocation */
731 if (tx_space < min_tx_space &&
732 ((min_tx_space - tx_space) < pba)) {
733 pba = pba - (min_tx_space - tx_space);
734
735 /* PCI/PCIx hardware has PBA alignment constraints */
Joe Perches1dc32912008-07-11 15:17:08 -0700736 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100737 case e1000_82545 ... e1000_82546_rev_3:
738 pba &= ~(E1000_PBA_8K - 1);
739 break;
740 default:
741 break;
742 }
743
744 /* if short on rx space, rx wins and must trump tx
745 * adjustment or use Early Receive if available */
746 if (pba < min_rx_space) {
Joe Perches1dc32912008-07-11 15:17:08 -0700747 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100748 case e1000_82573:
749 /* ERT enabled in e1000_configure_rx */
750 break;
751 default:
752 pba = min_rx_space;
753 break;
754 }
755 }
756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700758
Joe Perches1dc32912008-07-11 15:17:08 -0700759 ew32(PBA, pba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000761 /*
762 * flow control settings:
763 * The high water mark must be low enough to fit one full frame
764 * (or the size used for early receive) above it in the Rx FIFO.
765 * Set it to the lower of:
766 * - 90% of the Rx FIFO size, and
767 * - the full Rx FIFO size minus the early receive size (for parts
768 * with ERT support assuming ERT set to E1000_ERT_2048), or
769 * - the full Rx FIFO size minus one full frame
770 */
771 hwm = min(((pba << 10) * 9 / 10),
772 ((pba << 10) - hw->max_frame_size));
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800773
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +0000774 hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
775 hw->fc_low_water = hw->fc_high_water - 8;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +0000776 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
Joe Perches1dc32912008-07-11 15:17:08 -0700777 hw->fc_send_xon = 1;
778 hw->fc = hw->original_fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700780 /* Allow time for pending master requests to run */
Joe Perches1dc32912008-07-11 15:17:08 -0700781 e1000_reset_hw(hw);
782 if (hw->mac_type >= e1000_82544)
783 ew32(WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700784
Joe Perches1dc32912008-07-11 15:17:08 -0700785 if (e1000_init_hw(hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700787 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100788
789 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
Joe Perches1dc32912008-07-11 15:17:08 -0700790 if (hw->mac_type >= e1000_82544 &&
791 hw->mac_type <= e1000_82547_rev_2 &&
792 hw->autoneg == 1 &&
793 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
794 u32 ctrl = er32(CTRL);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100795 /* clear phy power management bit if we are in gig only mode,
796 * which if enabled will attempt negotiation to 100Mb, which
797 * can cause a loss of link at power off or driver unload */
798 ctrl &= ~E1000_CTRL_SWDPIN3;
Joe Perches1dc32912008-07-11 15:17:08 -0700799 ew32(CTRL, ctrl);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100800 }
801
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
Joe Perches1dc32912008-07-11 15:17:08 -0700803 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Joe Perches1dc32912008-07-11 15:17:08 -0700805 e1000_reset_adaptive(hw);
806 e1000_phy_get_info(hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700807
808 if (!adapter->smart_power_down &&
Joe Perches1dc32912008-07-11 15:17:08 -0700809 (hw->mac_type == e1000_82571 ||
810 hw->mac_type == e1000_82572)) {
Joe Perches406874a2008-04-03 10:06:32 -0700811 u16 phy_data = 0;
Auke Kok9a53a202006-06-27 09:06:45 -0700812 /* speed up time to link by disabling smart power down, ignore
813 * the return value of this function because there is nothing
814 * different we would do if it failed */
Joe Perches1dc32912008-07-11 15:17:08 -0700815 e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9a53a202006-06-27 09:06:45 -0700816 &phy_data);
817 phy_data &= ~IGP02E1000_PM_SPD;
Joe Perches1dc32912008-07-11 15:17:08 -0700818 e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9a53a202006-06-27 09:06:45 -0700819 phy_data);
820 }
821
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500822 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
825/**
Auke Kok67b3c272007-12-17 13:50:23 -0800826 * Dump the eeprom for users having checksum issues
827 **/
Adrian Bunkb4ea8952008-02-01 08:21:28 -0800828static void e1000_dump_eeprom(struct e1000_adapter *adapter)
Auke Kok67b3c272007-12-17 13:50:23 -0800829{
830 struct net_device *netdev = adapter->netdev;
831 struct ethtool_eeprom eeprom;
832 const struct ethtool_ops *ops = netdev->ethtool_ops;
833 u8 *data;
834 int i;
835 u16 csum_old, csum_new = 0;
836
837 eeprom.len = ops->get_eeprom_len(netdev);
838 eeprom.offset = 0;
839
840 data = kmalloc(eeprom.len, GFP_KERNEL);
841 if (!data) {
842 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
843 " data\n");
844 return;
845 }
846
847 ops->get_eeprom(netdev, &eeprom, data);
848
849 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
850 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
851 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
852 csum_new += data[i] + (data[i + 1] << 8);
853 csum_new = EEPROM_SUM - csum_new;
854
855 printk(KERN_ERR "/*********************/\n");
856 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
857 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
858
859 printk(KERN_ERR "Offset Values\n");
860 printk(KERN_ERR "======== ======\n");
861 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
862
863 printk(KERN_ERR "Include this output when contacting your support "
864 "provider.\n");
865 printk(KERN_ERR "This is not a software error! Something bad "
866 "happened to your hardware or\n");
867 printk(KERN_ERR "EEPROM image. Ignoring this "
868 "problem could result in further problems,\n");
869 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
870 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
871 "which is invalid\n");
872 printk(KERN_ERR "and requires you to set the proper MAC "
873 "address manually before continuing\n");
874 printk(KERN_ERR "to enable this network device.\n");
875 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
876 "to your hardware vendor\n");
Jeff Kirsher63cd31f2008-07-11 15:17:33 -0700877 printk(KERN_ERR "or Intel Customer Support.\n");
Auke Kok67b3c272007-12-17 13:50:23 -0800878 printk(KERN_ERR "/*********************/\n");
879
880 kfree(data);
881}
882
883/**
Taku Izumi81250292008-07-11 15:17:44 -0700884 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
885 * @pdev: PCI device information struct
886 *
887 * Return true if an adapter needs ioport resources
888 **/
889static int e1000_is_need_ioport(struct pci_dev *pdev)
890{
891 switch (pdev->device) {
892 case E1000_DEV_ID_82540EM:
893 case E1000_DEV_ID_82540EM_LOM:
894 case E1000_DEV_ID_82540EP:
895 case E1000_DEV_ID_82540EP_LOM:
896 case E1000_DEV_ID_82540EP_LP:
897 case E1000_DEV_ID_82541EI:
898 case E1000_DEV_ID_82541EI_MOBILE:
899 case E1000_DEV_ID_82541ER:
900 case E1000_DEV_ID_82541ER_LOM:
901 case E1000_DEV_ID_82541GI:
902 case E1000_DEV_ID_82541GI_LF:
903 case E1000_DEV_ID_82541GI_MOBILE:
904 case E1000_DEV_ID_82544EI_COPPER:
905 case E1000_DEV_ID_82544EI_FIBER:
906 case E1000_DEV_ID_82544GC_COPPER:
907 case E1000_DEV_ID_82544GC_LOM:
908 case E1000_DEV_ID_82545EM_COPPER:
909 case E1000_DEV_ID_82545EM_FIBER:
910 case E1000_DEV_ID_82546EB_COPPER:
911 case E1000_DEV_ID_82546EB_FIBER:
912 case E1000_DEV_ID_82546EB_QUAD_COPPER:
913 return true;
914 default:
915 return false;
916 }
917}
918
Stephen Hemminger0e7614b2008-11-19 22:18:22 -0800919static const struct net_device_ops e1000_netdev_ops = {
920 .ndo_open = e1000_open,
921 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -0800922 .ndo_start_xmit = e1000_xmit_frame,
Stephen Hemminger0e7614b2008-11-19 22:18:22 -0800923 .ndo_get_stats = e1000_get_stats,
924 .ndo_set_rx_mode = e1000_set_rx_mode,
925 .ndo_set_mac_address = e1000_set_mac,
926 .ndo_tx_timeout = e1000_tx_timeout,
927 .ndo_change_mtu = e1000_change_mtu,
928 .ndo_do_ioctl = e1000_ioctl,
929 .ndo_validate_addr = eth_validate_addr,
930
931 .ndo_vlan_rx_register = e1000_vlan_rx_register,
932 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
933 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
934#ifdef CONFIG_NET_POLL_CONTROLLER
935 .ndo_poll_controller = e1000_netpoll,
936#endif
937};
938
Taku Izumi81250292008-07-11 15:17:44 -0700939/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 * e1000_probe - Device Initialization Routine
941 * @pdev: PCI device information struct
942 * @ent: entry in e1000_pci_tbl
943 *
944 * Returns 0 on success, negative on failure
945 *
946 * e1000_probe initializes an adapter identified by a pci_dev structure.
947 * The OS initialization, configuring of the adapter private structure,
948 * and a hardware reset occur.
949 **/
Joe Perches1dc32912008-07-11 15:17:08 -0700950static int __devinit e1000_probe(struct pci_dev *pdev,
951 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
953 struct net_device *netdev;
954 struct e1000_adapter *adapter;
Joe Perches1dc32912008-07-11 15:17:08 -0700955 struct e1000_hw *hw;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700958 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700959 int i, err, pci_using_dac;
Joe Perches406874a2008-04-03 10:06:32 -0700960 u16 eeprom_data = 0;
961 u16 eeprom_apme_mask = E1000_EEPROM_APME;
Taku Izumi81250292008-07-11 15:17:44 -0700962 int bars, need_ioport;
Joe Perches0795af52007-10-03 17:59:30 -0700963
Taku Izumi81250292008-07-11 15:17:44 -0700964 /* do not allocate ioport bars when not needed */
965 need_ioport = e1000_is_need_ioport(pdev);
966 if (need_ioport) {
967 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
968 err = pci_enable_device(pdev);
969 } else {
970 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Karsten Keil4d7155b2009-02-03 15:18:01 -0800971 err = pci_enable_device_mem(pdev);
Taku Izumi81250292008-07-11 15:17:44 -0700972 }
Joe Perchesc7be73b2008-07-11 15:17:28 -0700973 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 return err;
975
Yang Hongyang6a355282009-04-06 19:01:13 -0700976 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
977 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 pci_using_dac = 1;
979 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -0700980 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Joe Perchesc7be73b2008-07-11 15:17:28 -0700981 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -0700982 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Joe Perchesc7be73b2008-07-11 15:17:28 -0700983 if (err) {
984 E1000_ERR("No usable DMA configuration, "
985 "aborting\n");
986 goto err_dma;
987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
989 pci_using_dac = 0;
990 }
991
Taku Izumi81250292008-07-11 15:17:44 -0700992 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
Joe Perchesc7be73b2008-07-11 15:17:28 -0700993 if (err)
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700994 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 pci_set_master(pdev);
997
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700998 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001000 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 SET_NETDEV_DEV(netdev, &pdev->dev);
1004
1005 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001006 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 adapter->netdev = netdev;
1008 adapter->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 adapter->msg_enable = (1 << debug) - 1;
Taku Izumi81250292008-07-11 15:17:44 -07001010 adapter->bars = bars;
1011 adapter->need_ioport = need_ioport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Joe Perches1dc32912008-07-11 15:17:08 -07001013 hw = &adapter->hw;
1014 hw->back = adapter;
1015
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001016 err = -EIO;
Arjan van de Ven275f1652008-10-20 21:42:39 -07001017 hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
Joe Perches1dc32912008-07-11 15:17:08 -07001018 if (!hw->hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Taku Izumi81250292008-07-11 15:17:44 -07001021 if (adapter->need_ioport) {
1022 for (i = BAR_1; i <= BAR_5; i++) {
1023 if (pci_resource_len(pdev, i) == 0)
1024 continue;
1025 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1026 hw->io_base = pci_resource_start(pdev, i);
1027 break;
1028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030 }
1031
Stephen Hemminger0e7614b2008-11-19 22:18:22 -08001032 netdev->netdev_ops = &e1000_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 e1000_set_ethtool_ops(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 netdev->watchdog_timeo = 5 * HZ;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001035 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Stephen Hemminger0e7614b2008-11-19 22:18:22 -08001036
Auke Kok0eb5a342006-09-27 12:53:17 -07001037 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 adapter->bd_number = cards_found;
1040
1041 /* setup the private structure */
1042
Joe Perchesc7be73b2008-07-11 15:17:28 -07001043 err = e1000_sw_init(adapter);
1044 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 goto err_sw_init;
1046
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001047 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -07001048 /* Flash BAR mapping must happen after e1000_sw_init
1049 * because it depends on mac_type */
Joe Perches1dc32912008-07-11 15:17:08 -07001050 if ((hw->mac_type == e1000_ich8lan) &&
Auke Kokcd94dd02006-06-27 09:08:22 -07001051 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
Arjan van de Ven275f1652008-10-20 21:42:39 -07001052 hw->flash_address = pci_ioremap_bar(pdev, 1);
Joe Perches1dc32912008-07-11 15:17:08 -07001053 if (!hw->flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -07001054 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -07001055 }
1056
Joe Perches1dc32912008-07-11 15:17:08 -07001057 if (e1000_check_phy_reset_block(hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001058 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
1059
Joe Perches1dc32912008-07-11 15:17:08 -07001060 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 netdev->features = NETIF_F_SG |
1062 NETIF_F_HW_CSUM |
1063 NETIF_F_HW_VLAN_TX |
1064 NETIF_F_HW_VLAN_RX |
1065 NETIF_F_HW_VLAN_FILTER;
Joe Perches1dc32912008-07-11 15:17:08 -07001066 if (hw->mac_type == e1000_ich8lan)
Auke Kokcd94dd02006-06-27 09:08:22 -07001067 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069
Joe Perches1dc32912008-07-11 15:17:08 -07001070 if ((hw->mac_type >= e1000_82544) &&
1071 (hw->mac_type != e1000_82547))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001073
Joe Perches1dc32912008-07-11 15:17:08 -07001074 if (hw->mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -08001075 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001076 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 netdev->features |= NETIF_F_HIGHDMA;
1078
Patrick McHardy20501a62008-10-11 12:25:59 -07001079 netdev->vlan_features |= NETIF_F_TSO;
1080 netdev->vlan_features |= NETIF_F_TSO6;
1081 netdev->vlan_features |= NETIF_F_HW_CSUM;
1082 netdev->vlan_features |= NETIF_F_SG;
1083
Joe Perches1dc32912008-07-11 15:17:08 -07001084 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001085
Auke Kokcd94dd02006-06-27 09:08:22 -07001086 /* initialize eeprom parameters */
Joe Perches1dc32912008-07-11 15:17:08 -07001087 if (e1000_init_eeprom_params(hw)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001088 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001089 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001090 }
1091
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001092 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001094
Joe Perches1dc32912008-07-11 15:17:08 -07001095 e1000_reset_hw(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 /* make sure the EEPROM is good */
Joe Perches1dc32912008-07-11 15:17:08 -07001098 if (e1000_validate_eeprom_checksum(hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Auke Kok67b3c272007-12-17 13:50:23 -08001100 e1000_dump_eeprom(adapter);
1101 /*
1102 * set MAC address to all zeroes to invalidate and temporary
1103 * disable this device for the user. This blocks regular
1104 * traffic while still permitting ethtool ioctls from reaching
1105 * the hardware as well as allowing the user to run the
1106 * interface after manually setting a hw addr using
1107 * `ip set address`
1108 */
Joe Perches1dc32912008-07-11 15:17:08 -07001109 memset(hw->mac_addr, 0, netdev->addr_len);
Auke Kok67b3c272007-12-17 13:50:23 -08001110 } else {
1111 /* copy the MAC address out of the EEPROM */
Joe Perches1dc32912008-07-11 15:17:08 -07001112 if (e1000_read_mac_addr(hw))
Auke Kok67b3c272007-12-17 13:50:23 -08001113 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 }
Auke Kok67b3c272007-12-17 13:50:23 -08001115 /* don't block initalization here due to bad MAC address */
Joe Perches1dc32912008-07-11 15:17:08 -07001116 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1117 memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Auke Kok67b3c272007-12-17 13:50:23 -08001119 if (!is_valid_ether_addr(netdev->perm_addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Joe Perches1dc32912008-07-11 15:17:08 -07001122 e1000_get_bus_info(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 init_timer(&adapter->tx_fifo_stall_timer);
1125 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
Joe Perchese982f172008-07-11 15:17:18 -07001126 adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 init_timer(&adapter->watchdog_timer);
1129 adapter->watchdog_timer.function = &e1000_watchdog;
1130 adapter->watchdog_timer.data = (unsigned long) adapter;
1131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 init_timer(&adapter->phy_info_timer);
1133 adapter->phy_info_timer.function = &e1000_update_phy_info;
Joe Perchese982f172008-07-11 15:17:18 -07001134 adapter->phy_info_timer.data = (unsigned long)adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
David Howells65f27f32006-11-22 14:55:48 +00001136 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 e1000_check_options(adapter);
1139
1140 /* Initial Wake on LAN setting
1141 * If APM wake is enabled in the EEPROM,
1142 * enable the ACPI Magic Packet filter
1143 */
1144
Joe Perches1dc32912008-07-11 15:17:08 -07001145 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 case e1000_82542_rev2_0:
1147 case e1000_82542_rev2_1:
1148 case e1000_82543:
1149 break;
1150 case e1000_82544:
Joe Perches1dc32912008-07-11 15:17:08 -07001151 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1153 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1154 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001155 case e1000_ich8lan:
Joe Perches1dc32912008-07-11 15:17:08 -07001156 e1000_read_eeprom(hw,
Auke Kokcd94dd02006-06-27 09:08:22 -07001157 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1158 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1159 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 case e1000_82546:
1161 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001162 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001163 case e1000_80003es2lan:
Joe Perches1dc32912008-07-11 15:17:08 -07001164 if (er32(STATUS) & E1000_STATUS_FUNC_1){
1165 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1167 break;
1168 }
1169 /* Fall Through */
1170 default:
Joe Perches1dc32912008-07-11 15:17:08 -07001171 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1173 break;
1174 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001175 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001176 adapter->eeprom_wol |= E1000_WUFC_MAG;
1177
1178 /* now that we have the eeprom settings, apply the special cases
1179 * where the eeprom may be wrong or the board simply won't support
1180 * wake on lan on a particular port */
1181 switch (pdev->device) {
1182 case E1000_DEV_ID_82546GB_PCIE:
1183 adapter->eeprom_wol = 0;
1184 break;
1185 case E1000_DEV_ID_82546EB_FIBER:
1186 case E1000_DEV_ID_82546GB_FIBER:
1187 case E1000_DEV_ID_82571EB_FIBER:
1188 /* Wake events only supported on port A for dual fiber
1189 * regardless of eeprom setting */
Joe Perches1dc32912008-07-11 15:17:08 -07001190 if (er32(STATUS) & E1000_STATUS_FUNC_1)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001191 adapter->eeprom_wol = 0;
1192 break;
1193 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001194 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001195 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001196 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001197 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001198 /* if quad port adapter, disable WoL on all but port A */
1199 if (global_quad_port_a != 0)
1200 adapter->eeprom_wol = 0;
1201 else
1202 adapter->quad_port_a = 1;
1203 /* Reset for multiple quad port adapters */
1204 if (++global_quad_port_a == 4)
1205 global_quad_port_a = 0;
1206 break;
1207 }
1208
1209 /* initialize the wol settings based on the eeprom settings */
1210 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\de126482008-11-07 20:30:19 +00001211 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001213 /* print bus type/speed/width info */
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001214 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1215 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1216 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1217 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1218 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1219 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1220 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1221 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1222 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1223 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1224 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1225 "32-bit"));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001226
Johannes Berge1749612008-10-27 15:59:26 -07001227 printk("%pM\n", netdev->dev_addr);
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001228
Joe Perches1dc32912008-07-11 15:17:08 -07001229 if (hw->bus_type == e1000_bus_type_pci_express) {
Auke Kok14782ca2008-02-11 09:25:46 -08001230 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1231 "longer be supported by this driver in the future.\n",
1232 pdev->vendor, pdev->device);
1233 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1234 "driver instead.\n");
1235 }
1236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 /* reset the hardware with the new settings */
1238 e1000_reset(adapter);
1239
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001240 /* If the controller is 82573 and f/w is AMT, do not set
1241 * DRV_LOAD until the interface is up. For all other cases,
1242 * let the f/w know that the h/w is now under the control
1243 * of the driver. */
Joe Perches1dc32912008-07-11 15:17:08 -07001244 if (hw->mac_type != e1000_82573 ||
1245 !e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001246 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001247
Auke Kok416b5d12007-06-01 10:22:39 -07001248 strcpy(netdev->name, "eth%d");
Joe Perchesc7be73b2008-07-11 15:17:28 -07001249 err = register_netdev(netdev);
1250 if (err)
Auke Kok416b5d12007-06-01 10:22:39 -07001251 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001252
Jesse Brandeburgeb62efd2009-04-17 20:44:36 +00001253 /* carrier off reporting is important to ethtool even BEFORE open */
1254 netif_carrier_off(netdev);
1255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1257
1258 cards_found++;
1259 return 0;
1260
1261err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001262 e1000_release_hw_control(adapter);
1263err_eeprom:
Joe Perches1dc32912008-07-11 15:17:08 -07001264 if (!e1000_check_phy_reset_block(hw))
1265 e1000_phy_hw_reset(hw);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001266
Joe Perches1dc32912008-07-11 15:17:08 -07001267 if (hw->flash_address)
1268 iounmap(hw->flash_address);
Auke Kokcd94dd02006-06-27 09:08:22 -07001269err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001270 kfree(adapter->tx_ring);
1271 kfree(adapter->rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272err_sw_init:
Joe Perches1dc32912008-07-11 15:17:08 -07001273 iounmap(hw->hw_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274err_ioremap:
1275 free_netdev(netdev);
1276err_alloc_etherdev:
Taku Izumi81250292008-07-11 15:17:44 -07001277 pci_release_selected_regions(pdev, bars);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001278err_pci_reg:
1279err_dma:
1280 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 return err;
1282}
1283
1284/**
1285 * e1000_remove - Device Removal Routine
1286 * @pdev: PCI device information struct
1287 *
1288 * e1000_remove is called by the PCI subsystem to alert the driver
1289 * that it should release a PCI device. The could be caused by a
1290 * Hot-Plug event, or because the driver is going to be removed from
1291 * memory.
1292 **/
1293
Joe Perches64798842008-07-11 15:17:02 -07001294static void __devexit e1000_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
1296 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001297 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001298 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Oleg Nesterov28e53bd2007-05-09 02:34:22 -07001300 cancel_work_sync(&adapter->reset_task);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001301
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001302 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001304 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1305 * would have already happened in close and is redundant. */
1306 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001307
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001308 unregister_netdev(netdev);
1309
Joe Perches1dc32912008-07-11 15:17:08 -07001310 if (!e1000_check_phy_reset_block(hw))
1311 e1000_phy_hw_reset(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001313 kfree(adapter->tx_ring);
1314 kfree(adapter->rx_ring);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001315
Joe Perches1dc32912008-07-11 15:17:08 -07001316 iounmap(hw->hw_addr);
1317 if (hw->flash_address)
1318 iounmap(hw->flash_address);
Taku Izumi81250292008-07-11 15:17:44 -07001319 pci_release_selected_regions(pdev, adapter->bars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
1321 free_netdev(netdev);
1322
1323 pci_disable_device(pdev);
1324}
1325
1326/**
1327 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1328 * @adapter: board private structure to initialize
1329 *
1330 * e1000_sw_init initializes the Adapter private data structure.
1331 * Fields are initialized based on PCI device information and
1332 * OS network device settings (MTU size).
1333 **/
1334
Joe Perches64798842008-07-11 15:17:02 -07001335static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
1337 struct e1000_hw *hw = &adapter->hw;
1338 struct net_device *netdev = adapter->netdev;
1339 struct pci_dev *pdev = adapter->pdev;
1340
1341 /* PCI config space info */
1342
1343 hw->vendor_id = pdev->vendor;
1344 hw->device_id = pdev->device;
1345 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1346 hw->subsystem_id = pdev->subsystem_device;
Auke Kok44c10132007-06-08 15:46:36 -07001347 hw->revision_id = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
1349 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1350
Auke Kokeb0f8052006-07-14 16:14:48 -07001351 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 hw->max_frame_size = netdev->mtu +
1353 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1354 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1355
1356 /* identify the MAC */
1357
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001358 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1360 return -EIO;
1361 }
1362
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001363 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 default:
1365 break;
1366 case e1000_82541:
1367 case e1000_82547:
1368 case e1000_82541_rev_2:
1369 case e1000_82547_rev_2:
1370 hw->phy_init_script = 1;
1371 break;
1372 }
1373
1374 e1000_set_media_type(hw);
1375
Joe Perchesc3033b02008-03-21 11:06:25 -07001376 hw->wait_autoneg_complete = false;
1377 hw->tbi_compatibility_en = true;
1378 hw->adaptive_ifs = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
1380 /* Copper options */
1381
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001382 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 hw->mdix = AUTO_ALL_MODES;
Joe Perchesc3033b02008-03-21 11:06:25 -07001384 hw->disable_polarity_correction = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 hw->master_slave = E1000_MASTER_SLAVE;
1386 }
1387
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001388 adapter->num_tx_queues = 1;
1389 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001390
1391 if (e1000_alloc_queues(adapter)) {
1392 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1393 return -ENOMEM;
1394 }
1395
Herbert Xu47313052007-05-29 15:07:31 -07001396 /* Explicitly disable IRQ since the NIC can be in any state. */
Herbert Xu47313052007-05-29 15:07:31 -07001397 e1000_irq_disable(adapter);
1398
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Auke Kok1314bbf2006-09-27 12:54:02 -07001401 set_bit(__E1000_DOWN, &adapter->flags);
1402
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 return 0;
1404}
1405
1406/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001407 * e1000_alloc_queues - Allocate memory for all rings
1408 * @adapter: board private structure to initialize
1409 *
1410 * We allocate one ring per queue at run-time since we don't know the
Wang Chen3e1d7cd2008-12-03 22:07:10 -08001411 * number of queues at compile-time.
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001412 **/
1413
Joe Perches64798842008-07-11 15:17:02 -07001414static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001415{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001416 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1417 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001418 if (!adapter->tx_ring)
1419 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001420
Yan Burman1c7e5b12007-03-06 08:58:04 -08001421 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1422 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001423 if (!adapter->rx_ring) {
1424 kfree(adapter->tx_ring);
1425 return -ENOMEM;
1426 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001427
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001428 return E1000_SUCCESS;
1429}
1430
1431/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 * e1000_open - Called when a network interface is made active
1433 * @netdev: network interface device structure
1434 *
1435 * Returns 0 on success, negative value on failure
1436 *
1437 * The open entry point is called when a network interface is made
1438 * active by the system (IFF_UP). At this point all resources needed
1439 * for transmit and receive operations are allocated, the interrupt
1440 * handler is registered with the OS, the watchdog timer is started,
1441 * and the stack is notified that the interface is ready.
1442 **/
1443
Joe Perches64798842008-07-11 15:17:02 -07001444static int e1000_open(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001446 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001447 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 int err;
1449
Auke Kok2db10a02006-06-27 09:06:28 -07001450 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001451 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001452 return -EBUSY;
1453
Jesse Brandeburgeb62efd2009-04-17 20:44:36 +00001454 netif_carrier_off(netdev);
1455
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001457 err = e1000_setup_all_tx_resources(adapter);
1458 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 goto err_setup_tx;
1460
1461 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001462 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001463 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001464 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001465
Auke Kok79f05bf2006-06-27 09:06:32 -07001466 e1000_power_up_phy(adapter);
1467
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001468 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Joe Perches1dc32912008-07-11 15:17:08 -07001469 if ((hw->mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001470 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1471 e1000_update_mng_vlan(adapter);
1472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001474 /* If AMT is enabled, let the firmware know that the network
1475 * interface is now open */
Joe Perches1dc32912008-07-11 15:17:08 -07001476 if (hw->mac_type == e1000_82573 &&
1477 e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001478 e1000_get_hw_control(adapter);
1479
Auke Koke0aac5a2007-03-06 08:57:21 -08001480 /* before we allocate an interrupt, we must be ready to handle it.
1481 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1482 * as soon as we call pci_request_irq, so we have to setup our
1483 * clean_rx handler before we do so. */
1484 e1000_configure(adapter);
1485
1486 err = e1000_request_irq(adapter);
1487 if (err)
1488 goto err_req_irq;
1489
1490 /* From here on the code is the same as e1000_up() */
1491 clear_bit(__E1000_DOWN, &adapter->flags);
1492
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001493 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001494
Auke Koke0aac5a2007-03-06 08:57:21 -08001495 e1000_irq_enable(adapter);
1496
Ben Hutchings076152d2008-07-18 17:50:57 -07001497 netif_start_queue(netdev);
1498
Auke Koke0aac5a2007-03-06 08:57:21 -08001499 /* fire a link status change interrupt to start the watchdog */
Joe Perches1dc32912008-07-11 15:17:08 -07001500 ew32(ICS, E1000_ICS_LSC);
Auke Koke0aac5a2007-03-06 08:57:21 -08001501
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 return E1000_SUCCESS;
1503
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001504err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001505 e1000_release_hw_control(adapter);
1506 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001507 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001509 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510err_setup_tx:
1511 e1000_reset(adapter);
1512
1513 return err;
1514}
1515
1516/**
1517 * e1000_close - Disables a network interface
1518 * @netdev: network interface device structure
1519 *
1520 * Returns 0, this is not allowed to fail
1521 *
1522 * The close entry point is called when an interface is de-activated
1523 * by the OS. The hardware is still under the drivers control, but
1524 * needs to be disabled. A global MAC reset is issued to stop the
1525 * hardware, and all transmit and receive resources are freed.
1526 **/
1527
Joe Perches64798842008-07-11 15:17:02 -07001528static int e1000_close(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001530 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001531 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Auke Kok2db10a02006-06-27 09:06:28 -07001533 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001535 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001536 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001538 e1000_free_all_tx_resources(adapter);
1539 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Bruce Allan46665602006-09-27 12:54:08 -07001541 /* kill manageability vlan ID if supported, but not if a vlan with
1542 * the same ID is registered on the host OS (let 8021q kill it) */
Joe Perches1dc32912008-07-11 15:17:08 -07001543 if ((hw->mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001544 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1545 !(adapter->vlgrp &&
Dan Aloni5c15bde2007-03-02 20:44:51 -08001546 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001547 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1548 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001549
1550 /* If AMT is enabled, let the firmware know that the network
1551 * interface is now closed */
Joe Perches1dc32912008-07-11 15:17:08 -07001552 if (hw->mac_type == e1000_82573 &&
1553 e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001554 e1000_release_hw_control(adapter);
1555
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 return 0;
1557}
1558
1559/**
1560 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1561 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001562 * @start: address of beginning of memory
1563 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 **/
Joe Perches64798842008-07-11 15:17:02 -07001565static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1566 unsigned long len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Joe Perches1dc32912008-07-11 15:17:08 -07001568 struct e1000_hw *hw = &adapter->hw;
Joe Perchese982f172008-07-11 15:17:18 -07001569 unsigned long begin = (unsigned long)start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 unsigned long end = begin + len;
1571
Malli Chilakala26483452005-04-28 19:44:46 -07001572 /* First rev 82545 and 82546 need to not allow any memory
1573 * write location to cross 64k boundary due to errata 23 */
Joe Perches1dc32912008-07-11 15:17:08 -07001574 if (hw->mac_type == e1000_82545 ||
1575 hw->mac_type == e1000_82546) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001576 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 }
1578
Joe Perchesc3033b02008-03-21 11:06:25 -07001579 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
1581
1582/**
1583 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1584 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001585 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 *
1587 * Return 0 on success, negative on failure
1588 **/
1589
Joe Perches64798842008-07-11 15:17:02 -07001590static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1591 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 struct pci_dev *pdev = adapter->pdev;
1594 int size;
1595
1596 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001597 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001598 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001599 DPRINTK(PROBE, ERR,
1600 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 return -ENOMEM;
1602 }
1603 memset(txdr->buffer_info, 0, size);
1604
1605 /* round up to nearest 4K */
1606
1607 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001608 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001611 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001614 DPRINTK(PROBE, ERR,
1615 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 return -ENOMEM;
1617 }
1618
Malli Chilakala26483452005-04-28 19:44:46 -07001619 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1621 void *olddesc = txdr->desc;
1622 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001623 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1624 "at %p\n", txdr->size, txdr->desc);
1625 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001627 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001628 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1630 goto setup_tx_desc_die;
1631 }
1632
1633 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1634 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001635 pci_free_consistent(pdev, txdr->size, txdr->desc,
1636 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1638 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001639 "Unable to allocate aligned memory "
1640 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 vfree(txdr->buffer_info);
1642 return -ENOMEM;
1643 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001644 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1646 }
1647 }
1648 memset(txdr->desc, 0, txdr->size);
1649
1650 txdr->next_to_use = 0;
1651 txdr->next_to_clean = 0;
1652
1653 return 0;
1654}
1655
1656/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001657 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1658 * (Descriptors) for all queues
1659 * @adapter: board private structure
1660 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001661 * Return 0 on success, negative on failure
1662 **/
1663
Joe Perches64798842008-07-11 15:17:02 -07001664int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001665{
1666 int i, err = 0;
1667
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001668 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001669 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1670 if (err) {
1671 DPRINTK(PROBE, ERR,
1672 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001673 for (i-- ; i >= 0; i--)
1674 e1000_free_tx_resources(adapter,
1675 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001676 break;
1677 }
1678 }
1679
1680 return err;
1681}
1682
1683/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1685 * @adapter: board private structure
1686 *
1687 * Configure the Tx unit of the MAC after a reset.
1688 **/
1689
Joe Perches64798842008-07-11 15:17:02 -07001690static void e1000_configure_tx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Joe Perches406874a2008-04-03 10:06:32 -07001692 u64 tdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001693 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001694 u32 tdlen, tctl, tipg, tarc;
1695 u32 ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
1697 /* Setup the HW Tx Head and Tail descriptor pointers */
1698
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001699 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001700 case 1:
1701 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001702 tdba = adapter->tx_ring[0].dma;
1703 tdlen = adapter->tx_ring[0].count *
1704 sizeof(struct e1000_tx_desc);
Joe Perches1dc32912008-07-11 15:17:08 -07001705 ew32(TDLEN, tdlen);
1706 ew32(TDBAH, (tdba >> 32));
1707 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1708 ew32(TDT, 0);
1709 ew32(TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001710 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1711 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001712 break;
1713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
1715 /* Set the default values for the Tx Inter Packet Gap timer */
Joe Perches1dc32912008-07-11 15:17:08 -07001716 if (hw->mac_type <= e1000_82547_rev_2 &&
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001717 (hw->media_type == e1000_media_type_fiber ||
1718 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001719 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1720 else
1721 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1722
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001723 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 case e1000_82542_rev2_0:
1725 case e1000_82542_rev2_1:
1726 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001727 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1728 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001730 case e1000_80003es2lan:
1731 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1732 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1733 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001735 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1736 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1737 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001739 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1740 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Joe Perches1dc32912008-07-11 15:17:08 -07001741 ew32(TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
1743 /* Set the Tx Interrupt Delay register */
1744
Joe Perches1dc32912008-07-11 15:17:08 -07001745 ew32(TIDV, adapter->tx_int_delay);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001746 if (hw->mac_type >= e1000_82540)
Joe Perches1dc32912008-07-11 15:17:08 -07001747 ew32(TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
1749 /* Program the Transmit Control Register */
1750
Joe Perches1dc32912008-07-11 15:17:08 -07001751 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001753 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1755
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001756 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
Joe Perches1dc32912008-07-11 15:17:08 -07001757 tarc = er32(TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001758 /* set the speed mode bit, we'll clear it if we're not at
1759 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001760 tarc |= (1 << 21);
Joe Perches1dc32912008-07-11 15:17:08 -07001761 ew32(TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001762 } else if (hw->mac_type == e1000_80003es2lan) {
Joe Perches1dc32912008-07-11 15:17:08 -07001763 tarc = er32(TARC0);
Jeff Kirsher87041632006-03-02 18:21:24 -08001764 tarc |= 1;
Joe Perches1dc32912008-07-11 15:17:08 -07001765 ew32(TARC0, tarc);
1766 tarc = er32(TARC1);
Jeff Kirsher87041632006-03-02 18:21:24 -08001767 tarc |= 1;
Joe Perches1dc32912008-07-11 15:17:08 -07001768 ew32(TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001769 }
1770
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001771 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
1773 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001774 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1775
1776 /* only set IDE if we are delaying interrupts using the timers */
1777 if (adapter->tx_int_delay)
1778 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001780 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1782 else
1783 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1784
1785 /* Cache if we're 82544 running in PCI-X because we'll
1786 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001787 if (hw->mac_type == e1000_82544 &&
1788 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001790
Joe Perches1dc32912008-07-11 15:17:08 -07001791 ew32(TCTL, tctl);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001792
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793}
1794
1795/**
1796 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1797 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001798 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 *
1800 * Returns 0 on success, negative on failure
1801 **/
1802
Joe Perches64798842008-07-11 15:17:02 -07001803static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1804 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805{
Joe Perches1dc32912008-07-11 15:17:08 -07001806 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001808 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
1810 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001811 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001812 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001813 DPRINTK(PROBE, ERR,
1814 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 return -ENOMEM;
1816 }
1817 memset(rxdr->buffer_info, 0, size);
1818
Joe Perches1dc32912008-07-11 15:17:08 -07001819 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001820 desc_len = sizeof(struct e1000_rx_desc);
1821 else
1822 desc_len = sizeof(union e1000_rx_desc_packet_split);
1823
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 /* Round up to nearest 4K */
1825
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001826 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001827 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1830
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001831 if (!rxdr->desc) {
1832 DPRINTK(PROBE, ERR,
1833 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 vfree(rxdr->buffer_info);
1836 return -ENOMEM;
1837 }
1838
Malli Chilakala26483452005-04-28 19:44:46 -07001839 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1841 void *olddesc = rxdr->desc;
1842 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001843 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1844 "at %p\n", rxdr->size, rxdr->desc);
1845 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001847 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001848 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001850 DPRINTK(PROBE, ERR,
1851 "Unable to allocate memory "
1852 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 goto setup_rx_desc_die;
1854 }
1855
1856 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1857 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001858 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1859 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001861 DPRINTK(PROBE, ERR,
1862 "Unable to allocate aligned memory "
1863 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001864 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001866 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1868 }
1869 }
1870 memset(rxdr->desc, 0, rxdr->size);
1871
1872 rxdr->next_to_clean = 0;
1873 rxdr->next_to_use = 0;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00001874 rxdr->rx_skb_top = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
1876 return 0;
1877}
1878
1879/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001880 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1881 * (Descriptors) for all queues
1882 * @adapter: board private structure
1883 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001884 * Return 0 on success, negative on failure
1885 **/
1886
Joe Perches64798842008-07-11 15:17:02 -07001887int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001888{
1889 int i, err = 0;
1890
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001891 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001892 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1893 if (err) {
1894 DPRINTK(PROBE, ERR,
1895 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001896 for (i-- ; i >= 0; i--)
1897 e1000_free_rx_resources(adapter,
1898 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001899 break;
1900 }
1901 }
1902
1903 return err;
1904}
1905
1906/**
Malli Chilakala26483452005-04-28 19:44:46 -07001907 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 * @adapter: Board private structure
1909 **/
Joe Perches64798842008-07-11 15:17:02 -07001910static void e1000_setup_rctl(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911{
Joe Perches1dc32912008-07-11 15:17:08 -07001912 struct e1000_hw *hw = &adapter->hw;
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07001913 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
Joe Perches1dc32912008-07-11 15:17:08 -07001915 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
1917 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1918
1919 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1920 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
Joe Perches1dc32912008-07-11 15:17:08 -07001921 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Joe Perches1dc32912008-07-11 15:17:08 -07001923 if (hw->tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 rctl |= E1000_RCTL_SBP;
1925 else
1926 rctl &= ~E1000_RCTL_SBP;
1927
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001928 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1929 rctl &= ~E1000_RCTL_LPE;
1930 else
1931 rctl |= E1000_RCTL_LPE;
1932
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001934 rctl &= ~E1000_RCTL_SZ_4096;
1935 rctl |= E1000_RCTL_BSEX;
1936 switch (adapter->rx_buffer_len) {
1937 case E1000_RXBUFFER_256:
1938 rctl |= E1000_RCTL_SZ_256;
1939 rctl &= ~E1000_RCTL_BSEX;
1940 break;
1941 case E1000_RXBUFFER_512:
1942 rctl |= E1000_RCTL_SZ_512;
1943 rctl &= ~E1000_RCTL_BSEX;
1944 break;
1945 case E1000_RXBUFFER_1024:
1946 rctl |= E1000_RCTL_SZ_1024;
1947 rctl &= ~E1000_RCTL_BSEX;
1948 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001949 case E1000_RXBUFFER_2048:
1950 default:
1951 rctl |= E1000_RCTL_SZ_2048;
1952 rctl &= ~E1000_RCTL_BSEX;
1953 break;
1954 case E1000_RXBUFFER_4096:
1955 rctl |= E1000_RCTL_SZ_4096;
1956 break;
1957 case E1000_RXBUFFER_8192:
1958 rctl |= E1000_RCTL_SZ_8192;
1959 break;
1960 case E1000_RXBUFFER_16384:
1961 rctl |= E1000_RCTL_SZ_16384;
1962 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001963 }
1964
Joe Perches1dc32912008-07-11 15:17:08 -07001965 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966}
1967
1968/**
1969 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1970 * @adapter: board private structure
1971 *
1972 * Configure the Rx unit of the MAC after a reset.
1973 **/
1974
Joe Perches64798842008-07-11 15:17:02 -07001975static void e1000_configure_rx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976{
Joe Perches406874a2008-04-03 10:06:32 -07001977 u64 rdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001978 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001979 u32 rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001980
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00001981 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1982 rdlen = adapter->rx_ring[0].count *
1983 sizeof(struct e1000_rx_desc);
1984 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1985 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1986 } else {
1987 rdlen = adapter->rx_ring[0].count *
1988 sizeof(struct e1000_rx_desc);
1989 adapter->clean_rx = e1000_clean_rx_irq;
1990 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
1993 /* disable receives while setting up the descriptors */
Joe Perches1dc32912008-07-11 15:17:08 -07001994 rctl = er32(RCTL);
1995 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
1997 /* set the Receive Delay Timer Register */
Joe Perches1dc32912008-07-11 15:17:08 -07001998 ew32(RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002000 if (hw->mac_type >= e1000_82540) {
Joe Perches1dc32912008-07-11 15:17:08 -07002001 ew32(RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002002 if (adapter->itr_setting != 0)
Joe Perches1dc32912008-07-11 15:17:08 -07002003 ew32(ITR, 1000000000 / (adapter->itr * 256));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 }
2005
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002006 if (hw->mac_type >= e1000_82571) {
Joe Perches1dc32912008-07-11 15:17:08 -07002007 ctrl_ext = er32(CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002008 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002009 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002010 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002011 ctrl_ext |= E1000_CTRL_EXT_IAME;
Joe Perches1dc32912008-07-11 15:17:08 -07002012 ew32(IAM, 0xffffffff);
Joe Perches1dc32912008-07-11 15:17:08 -07002013 ew32(CTRL_EXT, ctrl_ext);
2014 E1000_WRITE_FLUSH();
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002015 }
2016
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002017 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2018 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002019 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002020 case 1:
2021 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002022 rdba = adapter->rx_ring[0].dma;
Joe Perches1dc32912008-07-11 15:17:08 -07002023 ew32(RDLEN, rdlen);
2024 ew32(RDBAH, (rdba >> 32));
2025 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
2026 ew32(RDT, 0);
2027 ew32(RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002028 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2029 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002030 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002031 }
2032
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002034 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07002035 rxcsum = er32(RXCSUM);
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07002036 if (adapter->rx_csum)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002037 rxcsum |= E1000_RXCSUM_TUOFL;
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07002038 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002039 /* don't need to clear IPPCSE as it defaults to 0 */
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07002040 rxcsum &= ~E1000_RXCSUM_TUOFL;
Joe Perches1dc32912008-07-11 15:17:08 -07002041 ew32(RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 }
2043
2044 /* Enable Receives */
Joe Perches1dc32912008-07-11 15:17:08 -07002045 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
2048/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002049 * e1000_free_tx_resources - Free Tx Resources per Queue
2050 * @adapter: board private structure
2051 * @tx_ring: Tx descriptor ring for a specific queue
2052 *
2053 * Free all transmit software resources
2054 **/
2055
Joe Perches64798842008-07-11 15:17:02 -07002056static void e1000_free_tx_resources(struct e1000_adapter *adapter,
2057 struct e1000_tx_ring *tx_ring)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002058{
2059 struct pci_dev *pdev = adapter->pdev;
2060
2061 e1000_clean_tx_ring(adapter, tx_ring);
2062
2063 vfree(tx_ring->buffer_info);
2064 tx_ring->buffer_info = NULL;
2065
2066 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2067
2068 tx_ring->desc = NULL;
2069}
2070
2071/**
2072 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 * @adapter: board private structure
2074 *
2075 * Free all transmit software resources
2076 **/
2077
Joe Perches64798842008-07-11 15:17:02 -07002078void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002080 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002082 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002083 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084}
2085
Joe Perches64798842008-07-11 15:17:02 -07002086static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2087 struct e1000_buffer *buffer_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002089 buffer_info->dma = 0;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002090 if (buffer_info->skb) {
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002091 skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
2092 DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002094 buffer_info->skb = NULL;
2095 }
Alexander Duyck37e73df2009-03-25 21:58:45 +00002096 buffer_info->time_stamp = 0;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002097 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098}
2099
2100/**
2101 * e1000_clean_tx_ring - Free Tx Buffers
2102 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002103 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 **/
2105
Joe Perches64798842008-07-11 15:17:02 -07002106static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
2107 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108{
Joe Perches1dc32912008-07-11 15:17:08 -07002109 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 struct e1000_buffer *buffer_info;
2111 unsigned long size;
2112 unsigned int i;
2113
2114 /* Free all the Tx ring sk_buffs */
2115
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002116 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 buffer_info = &tx_ring->buffer_info[i];
2118 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2119 }
2120
2121 size = sizeof(struct e1000_buffer) * tx_ring->count;
2122 memset(tx_ring->buffer_info, 0, size);
2123
2124 /* Zero out the descriptor ring */
2125
2126 memset(tx_ring->desc, 0, tx_ring->size);
2127
2128 tx_ring->next_to_use = 0;
2129 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002130 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
Joe Perches1dc32912008-07-11 15:17:08 -07002132 writel(0, hw->hw_addr + tx_ring->tdh);
2133 writel(0, hw->hw_addr + tx_ring->tdt);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002134}
2135
2136/**
2137 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2138 * @adapter: board private structure
2139 **/
2140
Joe Perches64798842008-07-11 15:17:02 -07002141static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002142{
2143 int i;
2144
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002145 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002146 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147}
2148
2149/**
2150 * e1000_free_rx_resources - Free Rx Resources
2151 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002152 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 *
2154 * Free all receive software resources
2155 **/
2156
Joe Perches64798842008-07-11 15:17:02 -07002157static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2158 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 struct pci_dev *pdev = adapter->pdev;
2161
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002162 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 vfree(rx_ring->buffer_info);
2165 rx_ring->buffer_info = NULL;
2166
2167 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2168
2169 rx_ring->desc = NULL;
2170}
2171
2172/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002173 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002175 *
2176 * Free all receive software resources
2177 **/
2178
Joe Perches64798842008-07-11 15:17:02 -07002179void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002180{
2181 int i;
2182
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002183 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002184 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2185}
2186
2187/**
2188 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2189 * @adapter: board private structure
2190 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 **/
2192
Joe Perches64798842008-07-11 15:17:02 -07002193static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2194 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195{
Joe Perches1dc32912008-07-11 15:17:08 -07002196 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 struct e1000_buffer *buffer_info;
2198 struct pci_dev *pdev = adapter->pdev;
2199 unsigned long size;
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07002200 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
2202 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002203 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00002205 if (buffer_info->dma &&
2206 adapter->clean_rx == e1000_clean_rx_irq) {
2207 pci_unmap_single(pdev, buffer_info->dma,
2208 buffer_info->length,
2209 PCI_DMA_FROMDEVICE);
2210 } else if (buffer_info->dma &&
2211 adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
2212 pci_unmap_page(pdev, buffer_info->dma,
2213 buffer_info->length,
2214 PCI_DMA_FROMDEVICE);
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00002215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00002217 buffer_info->dma = 0;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00002218 if (buffer_info->page) {
2219 put_page(buffer_info->page);
2220 buffer_info->page = NULL;
2221 }
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00002222 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 dev_kfree_skb(buffer_info->skb);
2224 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 }
2227
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00002228 /* there also may be some cached data from a chained receive */
2229 if (rx_ring->rx_skb_top) {
2230 dev_kfree_skb(rx_ring->rx_skb_top);
2231 rx_ring->rx_skb_top = NULL;
2232 }
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 size = sizeof(struct e1000_buffer) * rx_ring->count;
2235 memset(rx_ring->buffer_info, 0, size);
2236
2237 /* Zero out the descriptor ring */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 memset(rx_ring->desc, 0, rx_ring->size);
2239
2240 rx_ring->next_to_clean = 0;
2241 rx_ring->next_to_use = 0;
2242
Joe Perches1dc32912008-07-11 15:17:08 -07002243 writel(0, hw->hw_addr + rx_ring->rdh);
2244 writel(0, hw->hw_addr + rx_ring->rdt);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002245}
2246
2247/**
2248 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2249 * @adapter: board private structure
2250 **/
2251
Joe Perches64798842008-07-11 15:17:02 -07002252static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002253{
2254 int i;
2255
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002256 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002257 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258}
2259
2260/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2261 * and memory write and invalidate disabled for certain operations
2262 */
Joe Perches64798842008-07-11 15:17:02 -07002263static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264{
Joe Perches1dc32912008-07-11 15:17:08 -07002265 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002267 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Joe Perches1dc32912008-07-11 15:17:08 -07002269 e1000_pci_clear_mwi(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
Joe Perches1dc32912008-07-11 15:17:08 -07002271 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 rctl |= E1000_RCTL_RST;
Joe Perches1dc32912008-07-11 15:17:08 -07002273 ew32(RCTL, rctl);
2274 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 mdelay(5);
2276
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002277 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002278 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279}
2280
Joe Perches64798842008-07-11 15:17:02 -07002281static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282{
Joe Perches1dc32912008-07-11 15:17:08 -07002283 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002285 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
Joe Perches1dc32912008-07-11 15:17:08 -07002287 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 rctl &= ~E1000_RCTL_RST;
Joe Perches1dc32912008-07-11 15:17:08 -07002289 ew32(RCTL, rctl);
2290 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 mdelay(5);
2292
Joe Perches1dc32912008-07-11 15:17:08 -07002293 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2294 e1000_pci_set_mwi(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002296 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002297 /* No need to loop, because 82542 supports only 1 queue */
2298 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002299 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002300 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 }
2302}
2303
2304/**
2305 * e1000_set_mac - Change the Ethernet Address of the NIC
2306 * @netdev: network interface device structure
2307 * @p: pointer to an address structure
2308 *
2309 * Returns 0 on success, negative on failure
2310 **/
2311
Joe Perches64798842008-07-11 15:17:02 -07002312static int e1000_set_mac(struct net_device *netdev, void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002314 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07002315 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 struct sockaddr *addr = p;
2317
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002318 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 return -EADDRNOTAVAIL;
2320
2321 /* 82542 2.0 needs to be in reset to write receive address registers */
2322
Joe Perches1dc32912008-07-11 15:17:08 -07002323 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 e1000_enter_82542_rst(adapter);
2325
2326 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Joe Perches1dc32912008-07-11 15:17:08 -07002327 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Joe Perches1dc32912008-07-11 15:17:08 -07002329 e1000_rar_set(hw, hw->mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002331 /* With 82571 controllers, LAA may be overwritten (with the default)
2332 * due to controller reset from the other port. */
Joe Perches1dc32912008-07-11 15:17:08 -07002333 if (hw->mac_type == e1000_82571) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002334 /* activate the work around */
Joe Perches1dc32912008-07-11 15:17:08 -07002335 hw->laa_is_present = 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002336
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002337 /* Hold a copy of the LAA in RAR[14] This is done so that
2338 * between the time RAR[0] gets clobbered and the time it
2339 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002340 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002341 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002342 * RAR[14] */
Joe Perches1dc32912008-07-11 15:17:08 -07002343 e1000_rar_set(hw, hw->mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002344 E1000_RAR_ENTRIES - 1);
2345 }
2346
Joe Perches1dc32912008-07-11 15:17:08 -07002347 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 e1000_leave_82542_rst(adapter);
2349
2350 return 0;
2351}
2352
2353/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002354 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 * @netdev: network interface device structure
2356 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002357 * The set_rx_mode entry point is called whenever the unicast or multicast
2358 * address lists or the network interface flags are updated. This routine is
2359 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 * promiscuous mode, and all-multi behavior.
2361 **/
2362
Joe Perches64798842008-07-11 15:17:02 -07002363static void e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002365 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 struct e1000_hw *hw = &adapter->hw;
Jiri Pirkoccffad22009-05-22 23:22:17 +00002367 struct netdev_hw_addr *ha;
2368 bool use_uc = false;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002369 struct dev_addr_list *mc_ptr;
Joe Perches406874a2008-04-03 10:06:32 -07002370 u32 rctl;
2371 u32 hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002372 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002373 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2374 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2375 E1000_NUM_MTA_REGISTERS;
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002376 u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
2377
2378 if (!mcarray) {
2379 DPRINTK(PROBE, ERR, "memory allocation failed\n");
2380 return;
2381 }
Auke Kokcd94dd02006-06-27 09:08:22 -07002382
Joe Perches1dc32912008-07-11 15:17:08 -07002383 if (hw->mac_type == e1000_ich8lan)
Auke Kokcd94dd02006-06-27 09:08:22 -07002384 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002386 /* reserve RAR[14] for LAA over-write work-around */
Joe Perches1dc32912008-07-11 15:17:08 -07002387 if (hw->mac_type == e1000_82571)
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002388 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
Malli Chilakala26483452005-04-28 19:44:46 -07002390 /* Check for Promiscuous and All Multicast modes */
2391
Joe Perches1dc32912008-07-11 15:17:08 -07002392 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002394 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002396 rctl &= ~E1000_RCTL_VFE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002398 if (netdev->flags & IFF_ALLMULTI) {
2399 rctl |= E1000_RCTL_MPE;
2400 } else {
2401 rctl &= ~E1000_RCTL_MPE;
2402 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002403 if (adapter->hw.mac_type != e1000_ich8lan)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002404 rctl |= E1000_RCTL_VFE;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002405 }
2406
Jiri Pirko31278e72009-06-17 01:12:19 +00002407 if (netdev->uc.count > rar_entries - 1) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002408 rctl |= E1000_RCTL_UPE;
2409 } else if (!(netdev->flags & IFF_PROMISC)) {
2410 rctl &= ~E1000_RCTL_UPE;
Jiri Pirkoccffad22009-05-22 23:22:17 +00002411 use_uc = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 }
2413
Joe Perches1dc32912008-07-11 15:17:08 -07002414 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
2416 /* 82542 2.0 needs to be in reset to write receive address registers */
2417
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002418 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 e1000_enter_82542_rst(adapter);
2420
Patrick McHardydb0ce502007-11-13 20:54:59 -08002421 /* load the first 14 addresses into the exact filters 1-14. Unicast
2422 * addresses take precedence to avoid disabling unicast filtering
2423 * when possible.
2424 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 * RAR 0 is used for the station MAC adddress
2426 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002427 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 */
Jiri Pirkoccffad22009-05-22 23:22:17 +00002429 i = 1;
2430 if (use_uc)
Jiri Pirko31278e72009-06-17 01:12:19 +00002431 list_for_each_entry(ha, &netdev->uc.list, list) {
Jiri Pirkoccffad22009-05-22 23:22:17 +00002432 if (i == rar_entries)
2433 break;
2434 e1000_rar_set(hw, ha->addr, i++);
2435 }
2436
2437 WARN_ON(i == rar_entries);
2438
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 mc_ptr = netdev->mc_list;
2440
Jiri Pirkoccffad22009-05-22 23:22:17 +00002441 for (; i < rar_entries; i++) {
2442 if (mc_ptr) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002443 e1000_rar_set(hw, mc_ptr->da_addr, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 mc_ptr = mc_ptr->next;
2445 } else {
2446 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Joe Perches1dc32912008-07-11 15:17:08 -07002447 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Joe Perches1dc32912008-07-11 15:17:08 -07002449 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 }
2451 }
2452
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 /* load any remaining addresses into the hash table */
2454
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002455 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002456 u32 hash_reg, hash_bit, mta;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002457 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002458 hash_reg = (hash_value >> 5) & 0x7F;
2459 hash_bit = hash_value & 0x1F;
2460 mta = (1 << hash_bit);
2461 mcarray[hash_reg] |= mta;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 }
2463
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002464 /* write the hash table completely, write from bottom to avoid
2465 * both stupid write combining chipsets, and flushing each write */
2466 for (i = mta_reg_count - 1; i >= 0 ; i--) {
2467 /*
2468 * If we are on an 82544 has an errata where writing odd
2469 * offsets overwrites the previous even offset, but writing
2470 * backwards over the range solves the issue by always
2471 * writing the odd offset first
2472 */
2473 E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
2474 }
2475 E1000_WRITE_FLUSH();
2476
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002477 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 e1000_leave_82542_rst(adapter);
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002479
2480 kfree(mcarray);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481}
2482
2483/* Need to wait a few seconds after link up to get diagnostic information from
2484 * the phy */
2485
Joe Perches64798842008-07-11 15:17:02 -07002486static void e1000_update_phy_info(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487{
Joe Perchese982f172008-07-11 15:17:18 -07002488 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Joe Perches1dc32912008-07-11 15:17:08 -07002489 struct e1000_hw *hw = &adapter->hw;
2490 e1000_phy_get_info(hw, &adapter->phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491}
2492
2493/**
2494 * e1000_82547_tx_fifo_stall - Timer Call-back
2495 * @data: pointer to adapter cast into an unsigned long
2496 **/
2497
Joe Perches64798842008-07-11 15:17:02 -07002498static void e1000_82547_tx_fifo_stall(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499{
Joe Perchese982f172008-07-11 15:17:18 -07002500 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Joe Perches1dc32912008-07-11 15:17:08 -07002501 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002503 u32 tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002505 if (atomic_read(&adapter->tx_fifo_stall)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002506 if ((er32(TDT) == er32(TDH)) &&
2507 (er32(TDFT) == er32(TDFH)) &&
2508 (er32(TDFTS) == er32(TDFHS))) {
2509 tctl = er32(TCTL);
2510 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2511 ew32(TDFT, adapter->tx_head_addr);
2512 ew32(TDFH, adapter->tx_head_addr);
2513 ew32(TDFTS, adapter->tx_head_addr);
2514 ew32(TDFHS, adapter->tx_head_addr);
2515 ew32(TCTL, tctl);
2516 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
2518 adapter->tx_fifo_head = 0;
2519 atomic_set(&adapter->tx_fifo_stall, 0);
2520 netif_wake_queue(netdev);
2521 } else {
2522 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2523 }
2524 }
2525}
2526
2527/**
2528 * e1000_watchdog - Timer Call-back
2529 * @data: pointer to adapter cast into an unsigned long
2530 **/
Joe Perches64798842008-07-11 15:17:02 -07002531static void e1000_watchdog(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532{
Joe Perchese982f172008-07-11 15:17:18 -07002533 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Joe Perches1dc32912008-07-11 15:17:08 -07002534 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002536 struct e1000_tx_ring *txdr = adapter->tx_ring;
Joe Perches406874a2008-04-03 10:06:32 -07002537 u32 link, tctl;
2538 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Joe Perches1dc32912008-07-11 15:17:08 -07002540 ret_val = e1000_check_for_link(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07002541 if ((ret_val == E1000_ERR_PHY) &&
Joe Perches1dc32912008-07-11 15:17:08 -07002542 (hw->phy_type == e1000_phy_igp_3) &&
2543 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07002544 /* See e1000_kumeran_lock_loss_workaround() */
2545 DPRINTK(LINK, INFO,
2546 "Gigabit has been disabled, downgrading speed\n");
2547 }
Auke Kok90fb5132006-11-01 08:47:30 -08002548
Joe Perches1dc32912008-07-11 15:17:08 -07002549 if (hw->mac_type == e1000_82573) {
2550 e1000_enable_tx_pkt_filtering(hw);
2551 if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002552 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
Joe Perches1dc32912008-07-11 15:17:08 -07002555 if ((hw->media_type == e1000_media_type_internal_serdes) &&
2556 !(er32(TXCW) & E1000_TXCW_ANE))
2557 link = !hw->serdes_link_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 else
Joe Perches1dc32912008-07-11 15:17:08 -07002559 link = er32(STATUS) & E1000_STATUS_LU;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002561 if (link) {
2562 if (!netif_carrier_ok(netdev)) {
Joe Perches406874a2008-04-03 10:06:32 -07002563 u32 ctrl;
Joe Perchesc3033b02008-03-21 11:06:25 -07002564 bool txb2b = true;
Joe Perches1dc32912008-07-11 15:17:08 -07002565 e1000_get_speed_and_duplex(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 &adapter->link_speed,
2567 &adapter->link_duplex);
2568
Joe Perches1dc32912008-07-11 15:17:08 -07002569 ctrl = er32(CTRL);
Jeff Kirsherb30c4d8f2008-11-27 00:22:45 -08002570 printk(KERN_INFO "e1000: %s NIC Link is Up %d Mbps %s, "
2571 "Flow Control: %s\n",
2572 netdev->name,
2573 adapter->link_speed,
2574 adapter->link_duplex == FULL_DUPLEX ?
Auke Kok9669f532007-01-18 09:25:26 -08002575 "Full Duplex" : "Half Duplex",
2576 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2577 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2578 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2579 E1000_CTRL_TFCE) ? "TX" : "None" )));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002581 /* tweak tx_queue_len according to speed/duplex
2582 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002583 netdev->tx_queue_len = adapter->tx_queue_len;
2584 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002585 switch (adapter->link_speed) {
2586 case SPEED_10:
Joe Perchesc3033b02008-03-21 11:06:25 -07002587 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002588 netdev->tx_queue_len = 10;
2589 adapter->tx_timeout_factor = 8;
2590 break;
2591 case SPEED_100:
Joe Perchesc3033b02008-03-21 11:06:25 -07002592 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002593 netdev->tx_queue_len = 100;
2594 /* maybe add some timeout factor ? */
2595 break;
2596 }
2597
Joe Perches1dc32912008-07-11 15:17:08 -07002598 if ((hw->mac_type == e1000_82571 ||
2599 hw->mac_type == e1000_82572) &&
Joe Perchesc3033b02008-03-21 11:06:25 -07002600 !txb2b) {
Joe Perches406874a2008-04-03 10:06:32 -07002601 u32 tarc0;
Joe Perches1dc32912008-07-11 15:17:08 -07002602 tarc0 = er32(TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002603 tarc0 &= ~(1 << 21);
Joe Perches1dc32912008-07-11 15:17:08 -07002604 ew32(TARC0, tarc0);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002605 }
Auke Kok90fb5132006-11-01 08:47:30 -08002606
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002607 /* disable TSO for pcie and 10/100 speeds, to avoid
2608 * some hardware issues */
2609 if (!adapter->tso_force &&
Joe Perches1dc32912008-07-11 15:17:08 -07002610 hw->bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002611 switch (adapter->link_speed) {
2612 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002613 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002614 DPRINTK(PROBE,INFO,
2615 "10/100 speed: disabling TSO\n");
2616 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002617 netdev->features &= ~NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002618 break;
2619 case SPEED_1000:
2620 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002621 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002622 break;
2623 default:
2624 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002625 break;
2626 }
2627 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002628
2629 /* enable transmits in the hardware, need to do this
2630 * after setting TARC0 */
Joe Perches1dc32912008-07-11 15:17:08 -07002631 tctl = er32(TCTL);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002632 tctl |= E1000_TCTL_EN;
Joe Perches1dc32912008-07-11 15:17:08 -07002633 ew32(TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002634
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 netif_carrier_on(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002636 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002638 } else {
2639 /* make sure the receive unit is started */
Joe Perches1dc32912008-07-11 15:17:08 -07002640 if (hw->rx_needs_kicking) {
2641 u32 rctl = er32(RCTL);
2642 ew32(RCTL, rctl | E1000_RCTL_EN);
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 }
2645 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002646 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 adapter->link_speed = 0;
2648 adapter->link_duplex = 0;
Jeff Kirsherb30c4d8f2008-11-27 00:22:45 -08002649 printk(KERN_INFO "e1000: %s NIC Link is Down\n",
2650 netdev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 netif_carrier_off(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002652 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Jeff Kirsher87041632006-03-02 18:21:24 -08002653
2654 /* 80003ES2LAN workaround--
2655 * For packet buffer work-around on link down event;
2656 * disable receives in the ISR and
2657 * reset device here in the watchdog
2658 */
Joe Perches1dc32912008-07-11 15:17:08 -07002659 if (hw->mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002660 /* reset device */
2661 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 }
2663
2664 e1000_smartspeed(adapter);
2665 }
2666
2667 e1000_update_stats(adapter);
2668
Joe Perches1dc32912008-07-11 15:17:08 -07002669 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 adapter->tpt_old = adapter->stats.tpt;
Joe Perches1dc32912008-07-11 15:17:08 -07002671 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 adapter->colc_old = adapter->stats.colc;
2673
2674 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2675 adapter->gorcl_old = adapter->stats.gorcl;
2676 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2677 adapter->gotcl_old = adapter->stats.gotcl;
2678
Joe Perches1dc32912008-07-11 15:17:08 -07002679 e1000_update_adaptive(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002681 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002682 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 /* We've lost link, so the controller stops DMA,
2684 * but we've got queued Tx work that's never going
2685 * to get done, so reset controller to flush Tx.
2686 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002687 adapter->tx_timeout_count++;
2688 schedule_work(&adapter->reset_task);
Jesse Brandeburgc2d5ab42009-05-07 11:07:35 +00002689 /* return immediately since reset is imminent */
2690 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 }
2692 }
2693
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 /* Cause software interrupt to ensure rx ring is cleaned */
Joe Perches1dc32912008-07-11 15:17:08 -07002695 ew32(ICS, E1000_ICS_RXDMT0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
Malli Chilakala26483452005-04-28 19:44:46 -07002697 /* Force detection of hung controller every watchdog period */
Joe Perchesc3033b02008-03-21 11:06:25 -07002698 adapter->detect_tx_hung = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002700 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002701 * reset from the other port. Set the appropriate LAA in RAR[0] */
Joe Perches1dc32912008-07-11 15:17:08 -07002702 if (hw->mac_type == e1000_82571 && hw->laa_is_present)
2703 e1000_rar_set(hw, hw->mac_addr, 0);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002704
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 /* Reset the timer */
Arjan van de Ven56e13932007-03-06 02:41:48 -08002706 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707}
2708
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002709enum latency_range {
2710 lowest_latency = 0,
2711 low_latency = 1,
2712 bulk_latency = 2,
2713 latency_invalid = 255
2714};
2715
2716/**
2717 * e1000_update_itr - update the dynamic ITR value based on statistics
2718 * Stores a new ITR value based on packets and byte
2719 * counts during the last interrupt. The advantage of per interrupt
2720 * computation is faster updates and more accurate ITR for the current
2721 * traffic pattern. Constants in this function were computed
2722 * based on theoretical maximum wire speed and thresholds were set based
2723 * on testing data as well as attempting to minimize response time
2724 * while increasing bulk throughput.
2725 * this functionality is controlled by the InterruptThrottleRate module
2726 * parameter (see e1000_param.c)
2727 * @adapter: pointer to adapter
2728 * @itr_setting: current adapter->itr
2729 * @packets: the number of packets during this measurement interval
2730 * @bytes: the number of bytes during this measurement interval
2731 **/
2732static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
Joe Perches64798842008-07-11 15:17:02 -07002733 u16 itr_setting, int packets, int bytes)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002734{
2735 unsigned int retval = itr_setting;
2736 struct e1000_hw *hw = &adapter->hw;
2737
2738 if (unlikely(hw->mac_type < e1000_82540))
2739 goto update_itr_done;
2740
2741 if (packets == 0)
2742 goto update_itr_done;
2743
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002744 switch (itr_setting) {
2745 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002746 /* jumbo frames get bulk treatment*/
2747 if (bytes/packets > 8000)
2748 retval = bulk_latency;
2749 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002750 retval = low_latency;
2751 break;
2752 case low_latency: /* 50 usec aka 20000 ints/s */
2753 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002754 /* jumbo frames need bulk latency setting */
2755 if (bytes/packets > 8000)
2756 retval = bulk_latency;
2757 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002758 retval = bulk_latency;
2759 else if ((packets > 35))
2760 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002761 } else if (bytes/packets > 2000)
2762 retval = bulk_latency;
2763 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002764 retval = lowest_latency;
2765 break;
2766 case bulk_latency: /* 250 usec aka 4000 ints/s */
2767 if (bytes > 25000) {
2768 if (packets > 35)
2769 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002770 } else if (bytes < 6000) {
2771 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002772 }
2773 break;
2774 }
2775
2776update_itr_done:
2777 return retval;
2778}
2779
2780static void e1000_set_itr(struct e1000_adapter *adapter)
2781{
2782 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002783 u16 current_itr;
2784 u32 new_itr = adapter->itr;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002785
2786 if (unlikely(hw->mac_type < e1000_82540))
2787 return;
2788
2789 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2790 if (unlikely(adapter->link_speed != SPEED_1000)) {
2791 current_itr = 0;
2792 new_itr = 4000;
2793 goto set_itr_now;
2794 }
2795
2796 adapter->tx_itr = e1000_update_itr(adapter,
2797 adapter->tx_itr,
2798 adapter->total_tx_packets,
2799 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002800 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2801 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2802 adapter->tx_itr = low_latency;
2803
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002804 adapter->rx_itr = e1000_update_itr(adapter,
2805 adapter->rx_itr,
2806 adapter->total_rx_packets,
2807 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002808 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2809 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2810 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002811
2812 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2813
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002814 switch (current_itr) {
2815 /* counts and packets in update_itr are dependent on these numbers */
2816 case lowest_latency:
2817 new_itr = 70000;
2818 break;
2819 case low_latency:
2820 new_itr = 20000; /* aka hwitr = ~200 */
2821 break;
2822 case bulk_latency:
2823 new_itr = 4000;
2824 break;
2825 default:
2826 break;
2827 }
2828
2829set_itr_now:
2830 if (new_itr != adapter->itr) {
2831 /* this attempts to bias the interrupt rate towards Bulk
2832 * by adding intermediate steps when interrupt rate is
2833 * increasing */
2834 new_itr = new_itr > adapter->itr ?
2835 min(adapter->itr + (new_itr >> 2), new_itr) :
2836 new_itr;
2837 adapter->itr = new_itr;
Joe Perches1dc32912008-07-11 15:17:08 -07002838 ew32(ITR, 1000000000 / (new_itr * 256));
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002839 }
2840
2841 return;
2842}
2843
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844#define E1000_TX_FLAGS_CSUM 0x00000001
2845#define E1000_TX_FLAGS_VLAN 0x00000002
2846#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002847#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2849#define E1000_TX_FLAGS_VLAN_SHIFT 16
2850
Joe Perches64798842008-07-11 15:17:02 -07002851static int e1000_tso(struct e1000_adapter *adapter,
2852 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002855 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002857 u32 cmd_length = 0;
2858 u16 ipcse = 0, tucse, mss;
2859 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 int err;
2861
Herbert Xu89114af2006-07-08 13:34:32 -07002862 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 if (skb_header_cloned(skb)) {
2864 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2865 if (err)
2866 return err;
2867 }
2868
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002869 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002870 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002871 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002872 struct iphdr *iph = ip_hdr(skb);
2873 iph->tot_len = 0;
2874 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002875 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2876 iph->daddr, 0,
2877 IPPROTO_TCP,
2878 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002879 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002880 ipcse = skb_transport_offset(skb) - 1;
Auke Koke15fdd02006-08-16 11:28:45 -07002881 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002882 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002883 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002884 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2885 &ipv6_hdr(skb)->daddr,
2886 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002887 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002888 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002889 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002890 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002891 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002892 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 tucse = 0;
2894
2895 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002896 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002898 i = tx_ring->next_to_use;
2899 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002900 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901
2902 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2903 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2904 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2905 context_desc->upper_setup.tcp_fields.tucss = tucss;
2906 context_desc->upper_setup.tcp_fields.tucso = tucso;
2907 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2908 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2909 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2910 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2911
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002912 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002913 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002914
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002915 if (++i == tx_ring->count) i = 0;
2916 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917
Joe Perchesc3033b02008-03-21 11:06:25 -07002918 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 }
Joe Perchesc3033b02008-03-21 11:06:25 -07002920 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921}
2922
Joe Perches64798842008-07-11 15:17:02 -07002923static bool e1000_tx_csum(struct e1000_adapter *adapter,
2924 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925{
2926 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002927 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002929 u8 css;
Dave Graham3ed30672008-10-09 14:29:26 -07002930 u32 cmd_len = E1000_TXD_CMD_DEXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
Dave Graham3ed30672008-10-09 14:29:26 -07002932 if (skb->ip_summed != CHECKSUM_PARTIAL)
2933 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934
Dave Graham3ed30672008-10-09 14:29:26 -07002935 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08002936 case cpu_to_be16(ETH_P_IP):
Dave Graham3ed30672008-10-09 14:29:26 -07002937 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2938 cmd_len |= E1000_TXD_CMD_TCP;
2939 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08002940 case cpu_to_be16(ETH_P_IPV6):
Dave Graham3ed30672008-10-09 14:29:26 -07002941 /* XXX not handling all IPV6 headers */
2942 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2943 cmd_len |= E1000_TXD_CMD_TCP;
2944 break;
2945 default:
2946 if (unlikely(net_ratelimit()))
2947 DPRINTK(DRV, WARNING,
2948 "checksum_partial proto=%x!\n", skb->protocol);
2949 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 }
2951
Dave Graham3ed30672008-10-09 14:29:26 -07002952 css = skb_transport_offset(skb);
2953
2954 i = tx_ring->next_to_use;
2955 buffer_info = &tx_ring->buffer_info[i];
2956 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2957
2958 context_desc->lower_setup.ip_config = 0;
2959 context_desc->upper_setup.tcp_fields.tucss = css;
2960 context_desc->upper_setup.tcp_fields.tucso =
2961 css + skb->csum_offset;
2962 context_desc->upper_setup.tcp_fields.tucse = 0;
2963 context_desc->tcp_seg_setup.data = 0;
2964 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
2965
2966 buffer_info->time_stamp = jiffies;
2967 buffer_info->next_to_watch = i;
2968
2969 if (unlikely(++i == tx_ring->count)) i = 0;
2970 tx_ring->next_to_use = i;
2971
2972 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973}
2974
2975#define E1000_MAX_TXD_PWR 12
2976#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2977
Joe Perches64798842008-07-11 15:17:02 -07002978static int e1000_tx_map(struct e1000_adapter *adapter,
2979 struct e1000_tx_ring *tx_ring,
2980 struct sk_buff *skb, unsigned int first,
2981 unsigned int max_per_txd, unsigned int nr_frags,
2982 unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983{
Joe Perches1dc32912008-07-11 15:17:08 -07002984 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck37e73df2009-03-25 21:58:45 +00002985 struct e1000_buffer *buffer_info;
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002986 unsigned int len = skb_headlen(skb);
2987 unsigned int offset, size, count = 0, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 unsigned int f;
Alexander Duyck37e73df2009-03-25 21:58:45 +00002989 dma_addr_t *map;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
2991 i = tx_ring->next_to_use;
2992
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002993 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
2994 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
Alexander Duyck37e73df2009-03-25 21:58:45 +00002995 return 0;
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002996 }
2997
Alexander Duyck37e73df2009-03-25 21:58:45 +00002998 map = skb_shinfo(skb)->dma_maps;
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002999 offset = 0;
3000
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003001 while (len) {
Alexander Duyck37e73df2009-03-25 21:58:45 +00003002 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05003004 /* Workaround for Controller erratum --
3005 * descriptor for non-tso packet in a linear SKB that follows a
3006 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003007 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05003008 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07003009 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05003010 tx_ring->last_tx_tso = 0;
3011 size -= 4;
3012 }
3013
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 /* Workaround for premature desc write-backs
3015 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003016 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07003018 /* work-around for errata 10 and it applies
3019 * to all controllers in PCI-X mode
3020 * The fix is to make sure that the first descriptor of a
3021 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3022 */
Joe Perches1dc32912008-07-11 15:17:08 -07003023 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003024 (size > 2015) && count == 0))
3025 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003026
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 /* Workaround for potential 82544 hang in PCI-X. Avoid
3028 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003029 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3031 size > 4))
3032 size -= 4;
3033
3034 buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00003035 buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003037 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038
3039 len -= size;
3040 offset += size;
3041 count++;
Alexander Duyck37e73df2009-03-25 21:58:45 +00003042 if (len) {
3043 i++;
3044 if (unlikely(i == tx_ring->count))
3045 i = 0;
3046 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 }
3048
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003049 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 struct skb_frag_struct *frag;
3051
3052 frag = &skb_shinfo(skb)->frags[f];
3053 len = frag->size;
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08003054 offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003056 while (len) {
Alexander Duyck37e73df2009-03-25 21:58:45 +00003057 i++;
3058 if (unlikely(i == tx_ring->count))
3059 i = 0;
3060
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 buffer_info = &tx_ring->buffer_info[i];
3062 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 /* Workaround for premature desc write-backs
3064 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003065 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 /* Workaround for potential 82544 hang in PCI-X.
3068 * Avoid terminating buffers within evenly-aligned
3069 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003070 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3072 size > 4))
3073 size -= 4;
3074
3075 buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00003076 buffer_info->dma = map[f] + offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003078 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079
3080 len -= size;
3081 offset += size;
3082 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 }
3084 }
3085
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 tx_ring->buffer_info[i].skb = skb;
3087 tx_ring->buffer_info[first].next_to_watch = i;
3088
3089 return count;
3090}
3091
Joe Perches64798842008-07-11 15:17:02 -07003092static void e1000_tx_queue(struct e1000_adapter *adapter,
3093 struct e1000_tx_ring *tx_ring, int tx_flags,
3094 int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
Joe Perches1dc32912008-07-11 15:17:08 -07003096 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 struct e1000_tx_desc *tx_desc = NULL;
3098 struct e1000_buffer *buffer_info;
Joe Perches406874a2008-04-03 10:06:32 -07003099 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 unsigned int i;
3101
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003102 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3104 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003105 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3106
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003107 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003108 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 }
3110
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003111 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3113 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3114 }
3115
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003116 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 txd_lower |= E1000_TXD_CMD_VLE;
3118 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3119 }
3120
3121 i = tx_ring->next_to_use;
3122
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003123 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 buffer_info = &tx_ring->buffer_info[i];
3125 tx_desc = E1000_TX_DESC(*tx_ring, i);
3126 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3127 tx_desc->lower.data =
3128 cpu_to_le32(txd_lower | buffer_info->length);
3129 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003130 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 }
3132
3133 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3134
3135 /* Force memory writes to complete before letting h/w
3136 * know there are new descriptors to fetch. (Only
3137 * applicable for weak-ordered memory model archs,
3138 * such as IA-64). */
3139 wmb();
3140
3141 tx_ring->next_to_use = i;
Joe Perches1dc32912008-07-11 15:17:08 -07003142 writel(i, hw->hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003143 /* we need this if more than one processor can write to our tail
3144 * at a time, it syncronizes IO on IA64/Altix systems */
3145 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146}
3147
3148/**
3149 * 82547 workaround to avoid controller hang in half-duplex environment.
3150 * The workaround is to avoid queuing a large packet that would span
3151 * the internal Tx FIFO ring boundary by notifying the stack to resend
3152 * the packet at a later time. This gives the Tx FIFO an opportunity to
3153 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3154 * to the beginning of the Tx FIFO.
3155 **/
3156
3157#define E1000_FIFO_HDR 0x10
3158#define E1000_82547_PAD_LEN 0x3E0
3159
Joe Perches64798842008-07-11 15:17:02 -07003160static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3161 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162{
Joe Perches406874a2008-04-03 10:06:32 -07003163 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3164 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003166 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003168 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 goto no_fifo_stall_required;
3170
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003171 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 return 1;
3173
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003174 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 atomic_set(&adapter->tx_fifo_stall, 1);
3176 return 1;
3177 }
3178
3179no_fifo_stall_required:
3180 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003181 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3183 return 0;
3184}
3185
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003186#define MINIMUM_DHCP_PACKET_SIZE 282
Joe Perches64798842008-07-11 15:17:02 -07003187static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3188 struct sk_buff *skb)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003189{
3190 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003191 u16 length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003192 if (vlan_tx_tag_present(skb)) {
Joe Perches1dc32912008-07-11 15:17:08 -07003193 if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) &&
3194 ( hw->mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003195 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3196 return 0;
3197 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003198 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Joe Perchese982f172008-07-11 15:17:18 -07003199 struct ethhdr *eth = (struct ethhdr *)skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003200 if ((htons(ETH_P_IP) == eth->h_proto)) {
3201 const struct iphdr *ip =
Joe Perches406874a2008-04-03 10:06:32 -07003202 (struct iphdr *)((u8 *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003203 if (IPPROTO_UDP == ip->protocol) {
3204 struct udphdr *udp =
Joe Perches406874a2008-04-03 10:06:32 -07003205 (struct udphdr *)((u8 *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003206 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003207 if (ntohs(udp->dest) == 67) {
Joe Perches406874a2008-04-03 10:06:32 -07003208 offset = (u8 *)udp + 8 - skb->data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003209 length = skb->len - offset;
3210
3211 return e1000_mng_write_dhcp_info(hw,
Joe Perches406874a2008-04-03 10:06:32 -07003212 (u8 *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003213 length);
3214 }
3215 }
3216 }
3217 }
3218 return 0;
3219}
3220
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003221static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3222{
3223 struct e1000_adapter *adapter = netdev_priv(netdev);
3224 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3225
3226 netif_stop_queue(netdev);
3227 /* Herbert's original patch had:
3228 * smp_mb__after_netif_stop_queue();
3229 * but since that doesn't exist yet, just open code it. */
3230 smp_mb();
3231
3232 /* We need to check again in a case another CPU has just
3233 * made room available. */
3234 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3235 return -EBUSY;
3236
3237 /* A reprieve! */
3238 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003239 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003240 return 0;
3241}
3242
3243static int e1000_maybe_stop_tx(struct net_device *netdev,
3244 struct e1000_tx_ring *tx_ring, int size)
3245{
3246 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3247 return 0;
3248 return __e1000_maybe_stop_tx(netdev, size);
3249}
3250
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Joe Perches64798842008-07-11 15:17:02 -07003252static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003254 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07003255 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003256 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3258 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3259 unsigned int tx_flags = 0;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003260 unsigned int len = skb->len - skb->data_len;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003261 unsigned int nr_frags;
3262 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003264 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 unsigned int f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003267 /* This goes back to the question of how to logically map a tx queue
3268 * to a flow. Right now, performance is impacted slightly negatively
3269 * if using multiple tx queues. If the stack breaks away from a
3270 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003271 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003272
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003273 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 dev_kfree_skb_any(skb);
3275 return NETDEV_TX_OK;
3276 }
3277
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003278 /* 82571 and newer doesn't need the workaround that limited descriptor
3279 * length to 4kB */
Joe Perches1dc32912008-07-11 15:17:08 -07003280 if (hw->mac_type >= e1000_82571)
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003281 max_per_txd = 8192;
3282
Herbert Xu79671682006-06-22 02:40:14 -07003283 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003284 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 * make sure there is enough room in the FIFO before
3286 * initiating the DMA for each buffer. The calc is:
3287 * 4 = ceil(buffer len/mss). To make sure we don't
3288 * overrun the FIFO, adjust the max buffer len if mss
3289 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003290 if (mss) {
Joe Perches406874a2008-04-03 10:06:32 -07003291 u8 hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 max_per_txd = min(mss << 2, max_per_txd);
3293 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003294
Auke Kok90fb5132006-11-01 08:47:30 -08003295 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3296 * points to just header, pull a few bytes of payload from
3297 * frags into skb->data */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003298 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003299 if (skb->data_len && hdr_len == len) {
Joe Perches1dc32912008-07-11 15:17:08 -07003300 switch (hw->mac_type) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003301 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003302 case e1000_82544:
3303 /* Make sure we have room to chop off 4 bytes,
3304 * and that the end alignment will work out to
3305 * this hardware's requirements
3306 * NOTE: this is a TSO only workaround
3307 * if end byte alignment not correct move us
3308 * into the next dword */
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003309 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003310 break;
3311 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003312 case e1000_82571:
3313 case e1000_82572:
3314 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003315 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003316 pull_size = min((unsigned int)4, skb->data_len);
3317 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003318 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003319 "__pskb_pull_tail failed.\n");
3320 dev_kfree_skb_any(skb);
Jeff Garzik749dfc72006-03-11 13:35:31 -05003321 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003322 }
3323 len = skb->len - skb->data_len;
3324 break;
3325 default:
3326 /* do nothing */
3327 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003328 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 }
3331
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003332 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003333 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003335 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003336
Jeff Kirsherfd803242005-12-13 00:06:22 -05003337 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003338 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003339 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003340
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 count += TXD_USE_COUNT(len, max_txd_pwr);
3342
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003343 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 count++;
3345
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003346 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003347 * in PCI-X mode, so add one more descriptor to the count
3348 */
Joe Perches1dc32912008-07-11 15:17:08 -07003349 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003350 (len > 2015)))
3351 count++;
3352
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003354 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3356 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003357 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 count += nr_frags;
3359
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003360
Joe Perches1dc32912008-07-11 15:17:08 -07003361 if (hw->tx_pkt_filtering &&
3362 (hw->mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003363 e1000_transfer_dhcp_info(adapter, skb);
3364
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 /* need: count + 2 desc gap to keep tail from touching
3366 * head, otherwise try next time */
Alexander Duyck80179432009-01-21 14:42:47 -08003367 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369
Joe Perches1dc32912008-07-11 15:17:08 -07003370 if (unlikely(hw->mac_type == e1000_82547)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003371 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003373 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 return NETDEV_TX_BUSY;
3375 }
3376 }
3377
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003378 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 tx_flags |= E1000_TX_FLAGS_VLAN;
3380 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3381 }
3382
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003383 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003384
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003385 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 if (tso < 0) {
3387 dev_kfree_skb_any(skb);
3388 return NETDEV_TX_OK;
3389 }
3390
Jeff Kirsherfd803242005-12-13 00:06:22 -05003391 if (likely(tso)) {
3392 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003394 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 tx_flags |= E1000_TX_FLAGS_CSUM;
3396
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003397 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003398 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003399 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003400 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003401 tx_flags |= E1000_TX_FLAGS_IPV4;
3402
Alexander Duyck37e73df2009-03-25 21:58:45 +00003403 count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
3404 nr_frags, mss);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405
Alexander Duyck37e73df2009-03-25 21:58:45 +00003406 if (count) {
3407 e1000_tx_queue(adapter, tx_ring, tx_flags, count);
Alexander Duyck37e73df2009-03-25 21:58:45 +00003408 /* Make sure there is space in the ring for the next send. */
3409 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410
Alexander Duyck37e73df2009-03-25 21:58:45 +00003411 } else {
3412 dev_kfree_skb_any(skb);
3413 tx_ring->buffer_info[first].time_stamp = 0;
3414 tx_ring->next_to_use = first;
3415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 return NETDEV_TX_OK;
3418}
3419
3420/**
3421 * e1000_tx_timeout - Respond to a Tx Hang
3422 * @netdev: network interface device structure
3423 **/
3424
Joe Perches64798842008-07-11 15:17:02 -07003425static void e1000_tx_timeout(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003427 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428
3429 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003430 adapter->tx_timeout_count++;
3431 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432}
3433
Joe Perches64798842008-07-11 15:17:02 -07003434static void e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435{
David Howells65f27f32006-11-22 14:55:48 +00003436 struct e1000_adapter *adapter =
3437 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438
Auke Kok2db10a02006-06-27 09:06:28 -07003439 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440}
3441
3442/**
3443 * e1000_get_stats - Get System Network Statistics
3444 * @netdev: network interface device structure
3445 *
3446 * Returns the address of the device statistics structure.
3447 * The statistics are actually updated from the timer callback.
3448 **/
3449
Joe Perches64798842008-07-11 15:17:02 -07003450static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003452 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003454 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 return &adapter->net_stats;
3456}
3457
3458/**
3459 * e1000_change_mtu - Change the Maximum Transfer Unit
3460 * @netdev: network interface device structure
3461 * @new_mtu: new value for maximum frame size
3462 *
3463 * Returns 0 on success, negative on failure
3464 **/
3465
Joe Perches64798842008-07-11 15:17:02 -07003466static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003468 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07003469 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Joe Perches406874a2008-04-03 10:06:32 -07003471 u16 eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003473 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3474 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3475 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003476 return -EINVAL;
3477 }
3478
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003479 /* Adapter-specific max frame size limits. */
Joe Perches1dc32912008-07-11 15:17:08 -07003480 switch (hw->mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003481 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003482 case e1000_ich8lan:
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +00003483 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003484 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003485 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003486 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003487 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003488 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003489 /* Jumbo Frames not supported if:
3490 * - this is not an 82573L device
3491 * - ASPM is enabled in any way (0x1A bits 3:2) */
Joe Perches1dc32912008-07-11 15:17:08 -07003492 e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1,
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003493 &eeprom_data);
Joe Perches1dc32912008-07-11 15:17:08 -07003494 if ((hw->device_id != E1000_DEV_ID_82573L) ||
Bruce Allan249d71d2006-09-27 12:53:45 -07003495 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +00003496 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003497 DPRINTK(PROBE, ERR,
3498 "Jumbo Frames not supported.\n");
3499 return -EINVAL;
3500 }
3501 break;
3502 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003503 /* ERT will be enabled later to enable wire speed receives */
3504
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003505 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003506 case e1000_82571:
3507 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003508 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003509#define MAX_STD_JUMBO_FRAME_SIZE 9234
3510 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3511 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3512 return -EINVAL;
3513 }
3514 break;
3515 default:
3516 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3517 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003518 }
3519
David S. Miller87f50322006-07-31 22:39:40 -07003520 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003521 * means we reserve 2 more, this pushes us to allocate from the next
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003522 * larger slab size.
3523 * i.e. RXBUFFER_2048 --> size-4096 slab
3524 * however with the new *_jumbo_rx* routines, jumbo receives will use
3525 * fragmented skbs */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003526
Auke Kok9e2feac2006-04-14 19:05:18 -07003527 if (max_frame <= E1000_RXBUFFER_256)
3528 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3529 else if (max_frame <= E1000_RXBUFFER_512)
3530 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3531 else if (max_frame <= E1000_RXBUFFER_1024)
3532 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3533 else if (max_frame <= E1000_RXBUFFER_2048)
3534 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003535 else
3536#if (PAGE_SIZE >= E1000_RXBUFFER_16384)
Auke Kok9e2feac2006-04-14 19:05:18 -07003537 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003538#elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3539 adapter->rx_buffer_len = PAGE_SIZE;
3540#endif
Auke Kok9e2feac2006-04-14 19:05:18 -07003541
3542 /* adjust allocation if LPE protects us, and we aren't using SBP */
Joe Perches1dc32912008-07-11 15:17:08 -07003543 if (!hw->tbi_compatibility_on &&
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +00003544 ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
Auke Kok9e2feac2006-04-14 19:05:18 -07003545 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3546 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003547
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003548 netdev->mtu = new_mtu;
Joe Perches1dc32912008-07-11 15:17:08 -07003549 hw->max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003550
Auke Kok2db10a02006-06-27 09:06:28 -07003551 if (netif_running(netdev))
3552 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 return 0;
3555}
3556
3557/**
3558 * e1000_update_stats - Update the board statistics counters
3559 * @adapter: board private structure
3560 **/
3561
Joe Perches64798842008-07-11 15:17:02 -07003562void e1000_update_stats(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563{
3564 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003565 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07003567 u16 phy_tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568
3569#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3570
Linas Vepstas282f33c2006-06-08 22:19:44 -07003571 /*
3572 * Prevent stats update while adapter is being reset, or if the pci
3573 * connection is down.
3574 */
Auke Kok90267292006-06-08 09:30:24 -07003575 if (adapter->link_speed == 0)
3576 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003577 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003578 return;
Auke Kok90267292006-06-08 09:30:24 -07003579
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580 spin_lock_irqsave(&adapter->stats_lock, flags);
3581
Masatake YAMATO828d0552007-10-20 03:06:37 +02003582 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 * called from the interrupt context, so they must only
3584 * be written while holding adapter->stats_lock
3585 */
3586
Joe Perches1dc32912008-07-11 15:17:08 -07003587 adapter->stats.crcerrs += er32(CRCERRS);
3588 adapter->stats.gprc += er32(GPRC);
3589 adapter->stats.gorcl += er32(GORCL);
3590 adapter->stats.gorch += er32(GORCH);
3591 adapter->stats.bprc += er32(BPRC);
3592 adapter->stats.mprc += er32(MPRC);
3593 adapter->stats.roc += er32(ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003594
Joe Perches1dc32912008-07-11 15:17:08 -07003595 if (hw->mac_type != e1000_ich8lan) {
3596 adapter->stats.prc64 += er32(PRC64);
3597 adapter->stats.prc127 += er32(PRC127);
3598 adapter->stats.prc255 += er32(PRC255);
3599 adapter->stats.prc511 += er32(PRC511);
3600 adapter->stats.prc1023 += er32(PRC1023);
3601 adapter->stats.prc1522 += er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603
Joe Perches1dc32912008-07-11 15:17:08 -07003604 adapter->stats.symerrs += er32(SYMERRS);
3605 adapter->stats.mpc += er32(MPC);
3606 adapter->stats.scc += er32(SCC);
3607 adapter->stats.ecol += er32(ECOL);
3608 adapter->stats.mcc += er32(MCC);
3609 adapter->stats.latecol += er32(LATECOL);
3610 adapter->stats.dc += er32(DC);
3611 adapter->stats.sec += er32(SEC);
3612 adapter->stats.rlec += er32(RLEC);
3613 adapter->stats.xonrxc += er32(XONRXC);
3614 adapter->stats.xontxc += er32(XONTXC);
3615 adapter->stats.xoffrxc += er32(XOFFRXC);
3616 adapter->stats.xofftxc += er32(XOFFTXC);
3617 adapter->stats.fcruc += er32(FCRUC);
3618 adapter->stats.gptc += er32(GPTC);
3619 adapter->stats.gotcl += er32(GOTCL);
3620 adapter->stats.gotch += er32(GOTCH);
3621 adapter->stats.rnbc += er32(RNBC);
3622 adapter->stats.ruc += er32(RUC);
3623 adapter->stats.rfc += er32(RFC);
3624 adapter->stats.rjc += er32(RJC);
3625 adapter->stats.torl += er32(TORL);
3626 adapter->stats.torh += er32(TORH);
3627 adapter->stats.totl += er32(TOTL);
3628 adapter->stats.toth += er32(TOTH);
3629 adapter->stats.tpr += er32(TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003630
Joe Perches1dc32912008-07-11 15:17:08 -07003631 if (hw->mac_type != e1000_ich8lan) {
3632 adapter->stats.ptc64 += er32(PTC64);
3633 adapter->stats.ptc127 += er32(PTC127);
3634 adapter->stats.ptc255 += er32(PTC255);
3635 adapter->stats.ptc511 += er32(PTC511);
3636 adapter->stats.ptc1023 += er32(PTC1023);
3637 adapter->stats.ptc1522 += er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003638 }
3639
Joe Perches1dc32912008-07-11 15:17:08 -07003640 adapter->stats.mptc += er32(MPTC);
3641 adapter->stats.bptc += er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642
3643 /* used for adaptive IFS */
3644
Joe Perches1dc32912008-07-11 15:17:08 -07003645 hw->tx_packet_delta = er32(TPT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 adapter->stats.tpt += hw->tx_packet_delta;
Joe Perches1dc32912008-07-11 15:17:08 -07003647 hw->collision_delta = er32(COLC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 adapter->stats.colc += hw->collision_delta;
3649
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003650 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07003651 adapter->stats.algnerrc += er32(ALGNERRC);
3652 adapter->stats.rxerrc += er32(RXERRC);
3653 adapter->stats.tncrs += er32(TNCRS);
3654 adapter->stats.cexterr += er32(CEXTERR);
3655 adapter->stats.tsctc += er32(TSCTC);
3656 adapter->stats.tsctfc += er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003658 if (hw->mac_type > e1000_82547_rev_2) {
Joe Perches1dc32912008-07-11 15:17:08 -07003659 adapter->stats.iac += er32(IAC);
3660 adapter->stats.icrxoc += er32(ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003661
Joe Perches1dc32912008-07-11 15:17:08 -07003662 if (hw->mac_type != e1000_ich8lan) {
3663 adapter->stats.icrxptc += er32(ICRXPTC);
3664 adapter->stats.icrxatc += er32(ICRXATC);
3665 adapter->stats.ictxptc += er32(ICTXPTC);
3666 adapter->stats.ictxatc += er32(ICTXATC);
3667 adapter->stats.ictxqec += er32(ICTXQEC);
3668 adapter->stats.ictxqmtc += er32(ICTXQMTC);
3669 adapter->stats.icrxdmtc += er32(ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003670 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672
3673 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 adapter->net_stats.multicast = adapter->stats.mprc;
3675 adapter->net_stats.collisions = adapter->stats.colc;
3676
3677 /* Rx Errors */
3678
Jeff Kirsher87041632006-03-02 18:21:24 -08003679 /* RLEC on some newer hardware can be incorrect so build
3680 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3682 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003683 adapter->stats.ruc + adapter->stats.roc +
3684 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003685 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3686 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3688 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3690
3691 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003692 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3693 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3695 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3696 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Joe Perches1dc32912008-07-11 15:17:08 -07003697 if (hw->bad_tx_carr_stats_fd &&
Jeff Garzik167fb282006-12-15 10:41:15 -05003698 adapter->link_duplex == FULL_DUPLEX) {
3699 adapter->net_stats.tx_carrier_errors = 0;
3700 adapter->stats.tncrs = 0;
3701 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702
3703 /* Tx Dropped needs to be maintained elsewhere */
3704
3705 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003706 if (hw->media_type == e1000_media_type_copper) {
3707 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3709 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3710 adapter->phy_stats.idle_errors += phy_tmp;
3711 }
3712
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003713 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 (hw->phy_type == e1000_phy_m88) &&
3715 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3716 adapter->phy_stats.receive_errors += phy_tmp;
3717 }
3718
Jeff Garzik15e376b2006-12-15 11:16:33 -05003719 /* Management Stats */
Joe Perches1dc32912008-07-11 15:17:08 -07003720 if (hw->has_smbus) {
3721 adapter->stats.mgptc += er32(MGTPTC);
3722 adapter->stats.mgprc += er32(MGTPRC);
3723 adapter->stats.mgpdc += er32(MGTPDC);
Jeff Garzik15e376b2006-12-15 11:16:33 -05003724 }
3725
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3727}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003728
3729/**
3730 * e1000_intr_msi - Interrupt Handler
3731 * @irq: interrupt number
3732 * @data: pointer to a network interface device structure
3733 **/
3734
Joe Perches64798842008-07-11 15:17:02 -07003735static irqreturn_t e1000_intr_msi(int irq, void *data)
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003736{
3737 struct net_device *netdev = data;
3738 struct e1000_adapter *adapter = netdev_priv(netdev);
3739 struct e1000_hw *hw = &adapter->hw;
Joe Perches1dc32912008-07-11 15:17:08 -07003740 u32 icr = er32(ICR);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003741
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003742 /* in NAPI mode read ICR disables interrupts using IAM */
3743
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003744 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3745 hw->get_link_status = 1;
3746 /* 80003ES2LAN workaround-- For packet buffer work-around on
3747 * link down event; disable receives here in the ISR and reset
3748 * adapter in watchdog */
3749 if (netif_carrier_ok(netdev) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003750 (hw->mac_type == e1000_80003es2lan)) {
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003751 /* disable receives */
Joe Perches1dc32912008-07-11 15:17:08 -07003752 u32 rctl = er32(RCTL);
3753 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003754 }
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003755 /* guard against interrupt when we're going down */
3756 if (!test_bit(__E1000_DOWN, &adapter->flags))
3757 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003758 }
3759
Ben Hutchings288379f2009-01-19 16:43:59 -08003760 if (likely(napi_schedule_prep(&adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003761 adapter->total_tx_bytes = 0;
3762 adapter->total_tx_packets = 0;
3763 adapter->total_rx_bytes = 0;
3764 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08003765 __napi_schedule(&adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003766 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003767 e1000_irq_enable(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003768
3769 return IRQ_HANDLED;
3770}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771
3772/**
3773 * e1000_intr - Interrupt Handler
3774 * @irq: interrupt number
3775 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 **/
3777
Joe Perches64798842008-07-11 15:17:02 -07003778static irqreturn_t e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779{
3780 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003781 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 struct e1000_hw *hw = &adapter->hw;
Joe Perches1dc32912008-07-11 15:17:08 -07003783 u32 rctl, icr = er32(ICR);
Francois Romieuc3570ac2008-07-11 15:17:38 -07003784
Jesse Brandeburge151a602009-05-04 11:19:42 +00003785 if (unlikely((!icr) || test_bit(__E1000_DOWN, &adapter->flags)))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003786 return IRQ_NONE; /* Not our interrupt */
3787
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003788 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3789 * not set, then the adapter didn't send an interrupt */
3790 if (unlikely(hw->mac_type >= e1000_82571 &&
3791 !(icr & E1000_ICR_INT_ASSERTED)))
3792 return IRQ_NONE;
3793
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003794 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3795 * need for the IMC write */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003797 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003799 /* 80003ES2LAN workaround--
3800 * For packet buffer work-around on link down event;
3801 * disable receives here in the ISR and
3802 * reset adapter in watchdog
3803 */
3804 if (netif_carrier_ok(netdev) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003805 (hw->mac_type == e1000_80003es2lan)) {
Jeff Kirsher87041632006-03-02 18:21:24 -08003806 /* disable receives */
Joe Perches1dc32912008-07-11 15:17:08 -07003807 rctl = er32(RCTL);
3808 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher87041632006-03-02 18:21:24 -08003809 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003810 /* guard against interrupt when we're going down */
3811 if (!test_bit(__E1000_DOWN, &adapter->flags))
3812 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 }
3814
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003815 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003816 /* disable interrupts, without the synchronize_irq bit */
Joe Perches1dc32912008-07-11 15:17:08 -07003817 ew32(IMC, ~0);
3818 E1000_WRITE_FLUSH();
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003819 }
Ben Hutchings288379f2009-01-19 16:43:59 -08003820 if (likely(napi_schedule_prep(&adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003821 adapter->total_tx_bytes = 0;
3822 adapter->total_tx_packets = 0;
3823 adapter->total_rx_bytes = 0;
3824 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08003825 __napi_schedule(&adapter->napi);
Jesse Brandeburga6c42322009-03-25 21:59:22 +00003826 } else {
Auke Kok90fb5132006-11-01 08:47:30 -08003827 /* this really should not happen! if it does it is basically a
3828 * bug, but not a hard error, so enable ints and continue */
Jesse Brandeburga6c42322009-03-25 21:59:22 +00003829 if (!test_bit(__E1000_DOWN, &adapter->flags))
3830 e1000_irq_enable(adapter);
3831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 return IRQ_HANDLED;
3834}
3835
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836/**
3837 * e1000_clean - NAPI Rx polling callback
3838 * @adapter: board private structure
3839 **/
Joe Perches64798842008-07-11 15:17:02 -07003840static int e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003842 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3843 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003844 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003845
Wang Chen4cf16532008-11-12 23:38:14 -08003846 adapter = netdev_priv(poll_dev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003847
Alexander Duyck80179432009-01-21 14:42:47 -08003848 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003849
Auke Kokd3d9e482006-07-14 16:14:23 -07003850 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003851 &work_done, budget);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003852
Alexander Duyckccfb3422009-03-25 21:59:04 +00003853 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003854 work_done = budget;
3855
David S. Miller53e52c72008-01-07 21:06:12 -08003856 /* If budget not fully consumed, exit the polling mode */
3857 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003858 if (likely(adapter->itr_setting & 3))
3859 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08003860 napi_complete(napi);
Jesse Brandeburga6c42322009-03-25 21:59:22 +00003861 if (!test_bit(__E1000_DOWN, &adapter->flags))
3862 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 }
3864
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003865 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866}
3867
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868/**
3869 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3870 * @adapter: board private structure
3871 **/
Joe Perches64798842008-07-11 15:17:02 -07003872static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3873 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874{
Joe Perches1dc32912008-07-11 15:17:08 -07003875 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 struct net_device *netdev = adapter->netdev;
3877 struct e1000_tx_desc *tx_desc, *eop_desc;
3878 struct e1000_buffer *buffer_info;
3879 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003880 unsigned int count = 0;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003881 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882
3883 i = tx_ring->next_to_clean;
3884 eop = tx_ring->buffer_info[i].next_to_watch;
3885 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3886
Alexander Duyckccfb3422009-03-25 21:59:04 +00003887 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3888 (count < tx_ring->count)) {
Jesse Brandeburg843f4262009-04-16 16:59:47 +00003889 bool cleaned = false;
3890 for ( ; !cleaned; count++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 tx_desc = E1000_TX_DESC(*tx_ring, i);
3892 buffer_info = &tx_ring->buffer_info[i];
3893 cleaned = (i == eop);
3894
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003895 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003896 struct sk_buff *skb = buffer_info->skb;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003897 unsigned int segs, bytecount;
3898 segs = skb_shinfo(skb)->gso_segs ?: 1;
3899 /* multiply data chunks by size of headers */
3900 bytecount = ((segs - 1) * skb_headlen(skb)) +
3901 skb->len;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003902 total_tx_packets += segs;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003903 total_tx_bytes += bytecount;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003904 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05003905 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003906 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003908 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003910
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 eop = tx_ring->buffer_info[i].next_to_watch;
3912 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3913 }
3914
3915 tx_ring->next_to_clean = i;
3916
Auke Kok77b2aad2006-04-14 19:05:25 -07003917#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg843f4262009-04-16 16:59:47 +00003918 if (unlikely(count && netif_carrier_ok(netdev) &&
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003919 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3920 /* Make sure that anybody stopping the queue after this
3921 * sees the new next_to_clean.
3922 */
3923 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003924 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07003925 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003926 ++adapter->restart_queue;
3927 }
Auke Kok77b2aad2006-04-14 19:05:25 -07003928 }
Malli Chilakala26483452005-04-28 19:44:46 -07003929
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003930 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003931 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 * check with the clearing of time_stamp and movement of i */
Joe Perchesc3033b02008-03-21 11:06:25 -07003933 adapter->detect_tx_hung = false;
Alexander Duyckccfb3422009-03-25 21:59:04 +00003934 if (tx_ring->buffer_info[i].time_stamp &&
3935 time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003936 (adapter->tx_timeout_factor * HZ))
Joe Perches1dc32912008-07-11 15:17:08 -07003937 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003938
3939 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003940 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003941 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003942 " TDH <%x>\n"
3943 " TDT <%x>\n"
3944 " next_to_use <%x>\n"
3945 " next_to_clean <%x>\n"
3946 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003947 " time_stamp <%lx>\n"
3948 " next_to_watch <%x>\n"
3949 " jiffies <%lx>\n"
3950 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003951 (unsigned long)((tx_ring - adapter->tx_ring) /
3952 sizeof(struct e1000_tx_ring)),
Joe Perches1dc32912008-07-11 15:17:08 -07003953 readl(hw->hw_addr + tx_ring->tdh),
3954 readl(hw->hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003955 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003956 tx_ring->next_to_clean,
Alexander Duyckccfb3422009-03-25 21:59:04 +00003957 tx_ring->buffer_info[i].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003958 eop,
3959 jiffies,
3960 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003962 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003964 adapter->total_tx_bytes += total_tx_bytes;
3965 adapter->total_tx_packets += total_tx_packets;
Auke Kokef90e4e2007-11-13 20:49:15 -08003966 adapter->net_stats.tx_bytes += total_tx_bytes;
3967 adapter->net_stats.tx_packets += total_tx_packets;
Alexander Duyckccfb3422009-03-25 21:59:04 +00003968 return (count < tx_ring->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969}
3970
3971/**
3972 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003973 * @adapter: board private structure
3974 * @status_err: receive descriptor status and error fields
3975 * @csum: receive descriptor csum field
3976 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 **/
3978
Joe Perches64798842008-07-11 15:17:02 -07003979static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3980 u32 csum, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981{
Joe Perches1dc32912008-07-11 15:17:08 -07003982 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003983 u16 status = (u16)status_err;
3984 u8 errors = (u8)(status_err >> 24);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003985 skb->ip_summed = CHECKSUM_NONE;
3986
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 /* 82543 or newer only */
Joe Perches1dc32912008-07-11 15:17:08 -07003988 if (unlikely(hw->mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003990 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003991 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003992 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003993 /* let the stack verify checksum errors */
3994 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 return;
3996 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003997 /* TCP/UDP Checksum has not been calculated */
Joe Perches1dc32912008-07-11 15:17:08 -07003998 if (hw->mac_type <= e1000_82547_rev_2) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003999 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004000 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004002 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004003 return;
4004 }
4005 /* It must be a TCP or UDP packet with a valid checksum */
4006 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 /* TCP checksum is good */
4008 skb->ip_summed = CHECKSUM_UNNECESSARY;
Joe Perches1dc32912008-07-11 15:17:08 -07004009 } else if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004010 /* IP fragment with UDP payload */
4011 /* Hardware complements the payload checksum, so we undo it
4012 * and then put the value in host order for further stack use.
4013 */
Al Viro3e188262007-12-11 19:49:39 +00004014 __sum16 sum = (__force __sum16)htons(csum);
4015 skb->csum = csum_unfold(~sum);
Patrick McHardy84fa7932006-08-29 16:44:56 -07004016 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004018 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019}
4020
4021/**
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004022 * e1000_consume_page - helper function
4023 **/
4024static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
4025 u16 length)
4026{
4027 bi->page = NULL;
4028 skb->len += length;
4029 skb->data_len += length;
4030 skb->truesize += length;
4031}
4032
4033/**
4034 * e1000_receive_skb - helper function to handle rx indications
4035 * @adapter: board private structure
4036 * @status: descriptor status field as written by hardware
4037 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
4038 * @skb: pointer to sk_buff to be indicated to stack
4039 */
4040static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
4041 __le16 vlan, struct sk_buff *skb)
4042{
4043 if (unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP))) {
4044 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4045 le16_to_cpu(vlan) &
4046 E1000_RXD_SPC_VLAN_MASK);
4047 } else {
4048 netif_receive_skb(skb);
4049 }
4050}
4051
4052/**
4053 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
4054 * @adapter: board private structure
4055 * @rx_ring: ring to clean
4056 * @work_done: amount of napi work completed this call
4057 * @work_to_do: max amount of work allowed for this call to do
4058 *
4059 * the return value indicates whether actual cleaning was done, there
4060 * is no guarantee that everything was cleaned
4061 */
4062static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
4063 struct e1000_rx_ring *rx_ring,
4064 int *work_done, int work_to_do)
4065{
4066 struct e1000_hw *hw = &adapter->hw;
4067 struct net_device *netdev = adapter->netdev;
4068 struct pci_dev *pdev = adapter->pdev;
4069 struct e1000_rx_desc *rx_desc, *next_rxd;
4070 struct e1000_buffer *buffer_info, *next_buffer;
4071 unsigned long irq_flags;
4072 u32 length;
4073 unsigned int i;
4074 int cleaned_count = 0;
4075 bool cleaned = false;
4076 unsigned int total_rx_bytes=0, total_rx_packets=0;
4077
4078 i = rx_ring->next_to_clean;
4079 rx_desc = E1000_RX_DESC(*rx_ring, i);
4080 buffer_info = &rx_ring->buffer_info[i];
4081
4082 while (rx_desc->status & E1000_RXD_STAT_DD) {
4083 struct sk_buff *skb;
4084 u8 status;
4085
4086 if (*work_done >= work_to_do)
4087 break;
4088 (*work_done)++;
4089
4090 status = rx_desc->status;
4091 skb = buffer_info->skb;
4092 buffer_info->skb = NULL;
4093
4094 if (++i == rx_ring->count) i = 0;
4095 next_rxd = E1000_RX_DESC(*rx_ring, i);
4096 prefetch(next_rxd);
4097
4098 next_buffer = &rx_ring->buffer_info[i];
4099
4100 cleaned = true;
4101 cleaned_count++;
4102 pci_unmap_page(pdev, buffer_info->dma, buffer_info->length,
4103 PCI_DMA_FROMDEVICE);
4104 buffer_info->dma = 0;
4105
4106 length = le16_to_cpu(rx_desc->length);
4107
4108 /* errors is only valid for DD + EOP descriptors */
4109 if (unlikely((status & E1000_RXD_STAT_EOP) &&
4110 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
4111 u8 last_byte = *(skb->data + length - 1);
4112 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4113 last_byte)) {
4114 spin_lock_irqsave(&adapter->stats_lock,
4115 irq_flags);
4116 e1000_tbi_adjust_stats(hw, &adapter->stats,
4117 length, skb->data);
4118 spin_unlock_irqrestore(&adapter->stats_lock,
4119 irq_flags);
4120 length--;
4121 } else {
4122 /* recycle both page and skb */
4123 buffer_info->skb = skb;
4124 /* an error means any chain goes out the window
4125 * too */
4126 if (rx_ring->rx_skb_top)
4127 dev_kfree_skb(rx_ring->rx_skb_top);
4128 rx_ring->rx_skb_top = NULL;
4129 goto next_desc;
4130 }
4131 }
4132
4133#define rxtop rx_ring->rx_skb_top
4134 if (!(status & E1000_RXD_STAT_EOP)) {
4135 /* this descriptor is only the beginning (or middle) */
4136 if (!rxtop) {
4137 /* this is the beginning of a chain */
4138 rxtop = skb;
4139 skb_fill_page_desc(rxtop, 0, buffer_info->page,
4140 0, length);
4141 } else {
4142 /* this is the middle of a chain */
4143 skb_fill_page_desc(rxtop,
4144 skb_shinfo(rxtop)->nr_frags,
4145 buffer_info->page, 0, length);
4146 /* re-use the skb, only consumed the page */
4147 buffer_info->skb = skb;
4148 }
4149 e1000_consume_page(buffer_info, rxtop, length);
4150 goto next_desc;
4151 } else {
4152 if (rxtop) {
4153 /* end of the chain */
4154 skb_fill_page_desc(rxtop,
4155 skb_shinfo(rxtop)->nr_frags,
4156 buffer_info->page, 0, length);
4157 /* re-use the current skb, we only consumed the
4158 * page */
4159 buffer_info->skb = skb;
4160 skb = rxtop;
4161 rxtop = NULL;
4162 e1000_consume_page(buffer_info, skb, length);
4163 } else {
4164 /* no chain, got EOP, this buf is the packet
4165 * copybreak to save the put_page/alloc_page */
4166 if (length <= copybreak &&
4167 skb_tailroom(skb) >= length) {
4168 u8 *vaddr;
4169 vaddr = kmap_atomic(buffer_info->page,
4170 KM_SKB_DATA_SOFTIRQ);
4171 memcpy(skb_tail_pointer(skb), vaddr, length);
4172 kunmap_atomic(vaddr,
4173 KM_SKB_DATA_SOFTIRQ);
4174 /* re-use the page, so don't erase
4175 * buffer_info->page */
4176 skb_put(skb, length);
4177 } else {
4178 skb_fill_page_desc(skb, 0,
4179 buffer_info->page, 0,
4180 length);
4181 e1000_consume_page(buffer_info, skb,
4182 length);
4183 }
4184 }
4185 }
4186
4187 /* Receive Checksum Offload XXX recompute due to CRC strip? */
4188 e1000_rx_checksum(adapter,
4189 (u32)(status) |
4190 ((u32)(rx_desc->errors) << 24),
4191 le16_to_cpu(rx_desc->csum), skb);
4192
4193 pskb_trim(skb, skb->len - 4);
4194
4195 /* probably a little skewed due to removing CRC */
4196 total_rx_bytes += skb->len;
4197 total_rx_packets++;
4198
4199 /* eth type trans needs skb->data to point to something */
4200 if (!pskb_may_pull(skb, ETH_HLEN)) {
4201 DPRINTK(DRV, ERR, "pskb_may_pull failed.\n");
4202 dev_kfree_skb(skb);
4203 goto next_desc;
4204 }
4205
4206 skb->protocol = eth_type_trans(skb, netdev);
4207
4208 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4209
4210next_desc:
4211 rx_desc->status = 0;
4212
4213 /* return some buffers to hardware, one at a time is too slow */
4214 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4215 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4216 cleaned_count = 0;
4217 }
4218
4219 /* use prefetched values */
4220 rx_desc = next_rxd;
4221 buffer_info = next_buffer;
4222 }
4223 rx_ring->next_to_clean = i;
4224
4225 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4226 if (cleaned_count)
4227 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4228
4229 adapter->total_rx_packets += total_rx_packets;
4230 adapter->total_rx_bytes += total_rx_bytes;
4231 adapter->net_stats.rx_bytes += total_rx_bytes;
4232 adapter->net_stats.rx_packets += total_rx_packets;
4233 return cleaned;
4234}
4235
4236/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004237 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238 * @adapter: board private structure
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004239 * @rx_ring: ring to clean
4240 * @work_done: amount of napi work completed this call
4241 * @work_to_do: max amount of work allowed for this call to do
4242 */
Joe Perches64798842008-07-11 15:17:02 -07004243static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4244 struct e1000_rx_ring *rx_ring,
4245 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246{
Joe Perches1dc32912008-07-11 15:17:08 -07004247 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248 struct net_device *netdev = adapter->netdev;
4249 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004250 struct e1000_rx_desc *rx_desc, *next_rxd;
4251 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07004253 u32 length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004255 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004256 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004257 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258
4259 i = rx_ring->next_to_clean;
4260 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004261 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004263 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004264 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004265 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004266
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004267 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 break;
4269 (*work_done)++;
Francois Romieuc3570ac2008-07-11 15:17:38 -07004270
Jeff Kirshera292ca62006-01-12 16:51:30 -08004271 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004272 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004273 buffer_info->skb = NULL;
4274
Jeff Kirsher30320be2006-03-02 18:21:57 -08004275 prefetch(skb->data - NET_IP_ALIGN);
4276
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004277 if (++i == rx_ring->count) i = 0;
4278 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004279 prefetch(next_rxd);
4280
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004281 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004282
Joe Perchesc3033b02008-03-21 11:06:25 -07004283 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004284 cleaned_count++;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004285 pci_unmap_single(pdev, buffer_info->dma, buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286 PCI_DMA_FROMDEVICE);
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00004287 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289 length = le16_to_cpu(rx_desc->length);
Neil Hormanea30e112009-06-02 01:29:58 -07004290 /* !EOP means multiple descriptors were used to store a single
4291 * packet, also make sure the frame isn't just CRC only */
4292 if (unlikely(!(status & E1000_RXD_STAT_EOP) || (length <= 4))) {
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004293 /* All receives must fit into a single buffer */
4294 E1000_DBG("%s: Receive packet consumed multiple"
4295 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004296 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004297 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 goto next_desc;
4299 }
4300
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004301 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004302 u8 last_byte = *(skb->data + length - 1);
Joe Perches1dc32912008-07-11 15:17:08 -07004303 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4304 last_byte)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004306 e1000_tbi_adjust_stats(hw, &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 length, skb->data);
4308 spin_unlock_irqrestore(&adapter->stats_lock,
4309 flags);
4310 length--;
4311 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004312 /* recycle */
4313 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 goto next_desc;
4315 }
Auke Kok1cb58212006-04-18 12:31:04 -07004316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004318 /* adjust length to remove Ethernet CRC, this must be
4319 * done after the TBI_ACCEPT workaround above */
4320 length -= 4;
4321
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004322 /* probably a little skewed due to removing CRC */
4323 total_rx_bytes += length;
4324 total_rx_packets++;
4325
Jeff Kirshera292ca62006-01-12 16:51:30 -08004326 /* code added for copybreak, this should improve
4327 * performance for small packets with large amounts
4328 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004329 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004330 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004331 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004332 if (new_skb) {
4333 skb_reserve(new_skb, NET_IP_ALIGN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004334 skb_copy_to_linear_data_offset(new_skb,
4335 -NET_IP_ALIGN,
4336 (skb->data -
4337 NET_IP_ALIGN),
4338 (length +
4339 NET_IP_ALIGN));
Jeff Kirshera292ca62006-01-12 16:51:30 -08004340 /* save the skb in buffer_info as good */
4341 buffer_info->skb = skb;
4342 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004343 }
Auke Kok996695d2006-11-01 08:47:50 -08004344 /* else just continue with the old one */
4345 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004346 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004347 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348
4349 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004350 e1000_rx_checksum(adapter,
Joe Perches406874a2008-04-03 10:06:32 -07004351 (u32)(status) |
4352 ((u32)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004353 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004354
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 skb->protocol = eth_type_trans(skb, netdev);
Francois Romieuc3570ac2008-07-11 15:17:38 -07004356
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004357 e1000_receive_skb(adapter, status, rx_desc->special, skb);
Francois Romieuc3570ac2008-07-11 15:17:38 -07004358
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359next_desc:
4360 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004362 /* return some buffers to hardware, one at a time is too slow */
4363 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4364 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4365 cleaned_count = 0;
4366 }
4367
Jeff Kirsher30320be2006-03-02 18:21:57 -08004368 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004369 rx_desc = next_rxd;
4370 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004373
4374 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4375 if (cleaned_count)
4376 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004378 adapter->total_rx_packets += total_rx_packets;
4379 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004380 adapter->net_stats.rx_bytes += total_rx_bytes;
4381 adapter->net_stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 return cleaned;
4383}
4384
4385/**
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004386 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4387 * @adapter: address of board private structure
4388 * @rx_ring: pointer to receive ring structure
4389 * @cleaned_count: number of buffers to allocate this pass
4390 **/
4391
4392static void
4393e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
4394 struct e1000_rx_ring *rx_ring, int cleaned_count)
4395{
4396 struct net_device *netdev = adapter->netdev;
4397 struct pci_dev *pdev = adapter->pdev;
4398 struct e1000_rx_desc *rx_desc;
4399 struct e1000_buffer *buffer_info;
4400 struct sk_buff *skb;
4401 unsigned int i;
4402 unsigned int bufsz = 256 -
4403 16 /*for skb_reserve */ -
4404 NET_IP_ALIGN;
4405
4406 i = rx_ring->next_to_use;
4407 buffer_info = &rx_ring->buffer_info[i];
4408
4409 while (cleaned_count--) {
4410 skb = buffer_info->skb;
4411 if (skb) {
4412 skb_trim(skb, 0);
4413 goto check_page;
4414 }
4415
4416 skb = netdev_alloc_skb(netdev, bufsz);
4417 if (unlikely(!skb)) {
4418 /* Better luck next round */
4419 adapter->alloc_rx_buff_failed++;
4420 break;
4421 }
4422
4423 /* Fix for errata 23, can't cross 64kB boundary */
4424 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4425 struct sk_buff *oldskb = skb;
4426 DPRINTK(PROBE, ERR, "skb align check failed: %u bytes "
4427 "at %p\n", bufsz, skb->data);
4428 /* Try again, without freeing the previous */
4429 skb = netdev_alloc_skb(netdev, bufsz);
4430 /* Failed allocation, critical failure */
4431 if (!skb) {
4432 dev_kfree_skb(oldskb);
4433 adapter->alloc_rx_buff_failed++;
4434 break;
4435 }
4436
4437 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4438 /* give up */
4439 dev_kfree_skb(skb);
4440 dev_kfree_skb(oldskb);
4441 break; /* while (cleaned_count--) */
4442 }
4443
4444 /* Use new allocation */
4445 dev_kfree_skb(oldskb);
4446 }
4447 /* Make buffer alignment 2 beyond a 16 byte boundary
4448 * this will result in a 16 byte aligned IP header after
4449 * the 14 byte MAC header is removed
4450 */
4451 skb_reserve(skb, NET_IP_ALIGN);
4452
4453 buffer_info->skb = skb;
4454 buffer_info->length = adapter->rx_buffer_len;
4455check_page:
4456 /* allocate a new page if necessary */
4457 if (!buffer_info->page) {
4458 buffer_info->page = alloc_page(GFP_ATOMIC);
4459 if (unlikely(!buffer_info->page)) {
4460 adapter->alloc_rx_buff_failed++;
4461 break;
4462 }
4463 }
4464
4465 if (!buffer_info->dma)
4466 buffer_info->dma = pci_map_page(pdev,
4467 buffer_info->page, 0,
4468 buffer_info->length,
4469 PCI_DMA_FROMDEVICE);
4470
4471 rx_desc = E1000_RX_DESC(*rx_ring, i);
4472 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4473
4474 if (unlikely(++i == rx_ring->count))
4475 i = 0;
4476 buffer_info = &rx_ring->buffer_info[i];
4477 }
4478
4479 if (likely(rx_ring->next_to_use != i)) {
4480 rx_ring->next_to_use = i;
4481 if (unlikely(i-- == 0))
4482 i = (rx_ring->count - 1);
4483
4484 /* Force memory writes to complete before letting h/w
4485 * know there are new descriptors to fetch. (Only
4486 * applicable for weak-ordered memory model archs,
4487 * such as IA-64). */
4488 wmb();
4489 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4490 }
4491}
4492
4493/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004494 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 * @adapter: address of board private structure
4496 **/
4497
Joe Perches64798842008-07-11 15:17:02 -07004498static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4499 struct e1000_rx_ring *rx_ring,
4500 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501{
Joe Perches1dc32912008-07-11 15:17:08 -07004502 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 struct net_device *netdev = adapter->netdev;
4504 struct pci_dev *pdev = adapter->pdev;
4505 struct e1000_rx_desc *rx_desc;
4506 struct e1000_buffer *buffer_info;
4507 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004508 unsigned int i;
4509 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510
4511 i = rx_ring->next_to_use;
4512 buffer_info = &rx_ring->buffer_info[i];
4513
Jeff Kirshera292ca62006-01-12 16:51:30 -08004514 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004515 skb = buffer_info->skb;
4516 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004517 skb_trim(skb, 0);
4518 goto map_skb;
4519 }
4520
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004521 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004522 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004524 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 break;
4526 }
4527
Malli Chilakala26483452005-04-28 19:44:46 -07004528 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4530 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004531 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4532 "at %p\n", bufsz, skb->data);
4533 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004534 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004535 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 if (!skb) {
4537 dev_kfree_skb(oldskb);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004538 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539 break;
4540 }
Malli Chilakala26483452005-04-28 19:44:46 -07004541
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4543 /* give up */
4544 dev_kfree_skb(skb);
4545 dev_kfree_skb(oldskb);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004546 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004549
4550 /* Use new allocation */
4551 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 /* Make buffer alignment 2 beyond a 16 byte boundary
4554 * this will result in a 16 byte aligned IP header after
4555 * the 14 byte MAC header is removed
4556 */
4557 skb_reserve(skb, NET_IP_ALIGN);
4558
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 buffer_info->skb = skb;
4560 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004561map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 buffer_info->dma = pci_map_single(pdev,
4563 skb->data,
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004564 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 PCI_DMA_FROMDEVICE);
4566
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004567 /*
4568 * XXX if it was allocated cleanly it will never map to a
4569 * boundary crossing
4570 */
4571
Malli Chilakala26483452005-04-28 19:44:46 -07004572 /* Fix for errata 23, can't cross 64kB boundary */
4573 if (!e1000_check_64k_bound(adapter,
4574 (void *)(unsigned long)buffer_info->dma,
4575 adapter->rx_buffer_len)) {
4576 DPRINTK(RX_ERR, ERR,
4577 "dma align check failed: %u bytes at %p\n",
4578 adapter->rx_buffer_len,
4579 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580 dev_kfree_skb(skb);
4581 buffer_info->skb = NULL;
4582
Malli Chilakala26483452005-04-28 19:44:46 -07004583 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 adapter->rx_buffer_len,
4585 PCI_DMA_FROMDEVICE);
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00004586 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004588 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 break; /* while !buffer_info->skb */
4590 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 rx_desc = E1000_RX_DESC(*rx_ring, i);
4592 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4593
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004594 if (unlikely(++i == rx_ring->count))
4595 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 buffer_info = &rx_ring->buffer_info[i];
4597 }
4598
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004599 if (likely(rx_ring->next_to_use != i)) {
4600 rx_ring->next_to_use = i;
4601 if (unlikely(i-- == 0))
4602 i = (rx_ring->count - 1);
4603
4604 /* Force memory writes to complete before letting h/w
4605 * know there are new descriptors to fetch. (Only
4606 * applicable for weak-ordered memory model archs,
4607 * such as IA-64). */
4608 wmb();
Joe Perches1dc32912008-07-11 15:17:08 -07004609 writel(i, hw->hw_addr + rx_ring->rdt);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611}
4612
4613/**
4614 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4615 * @adapter:
4616 **/
4617
Joe Perches64798842008-07-11 15:17:02 -07004618static void e1000_smartspeed(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619{
Joe Perches1dc32912008-07-11 15:17:08 -07004620 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004621 u16 phy_status;
4622 u16 phy_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623
Joe Perches1dc32912008-07-11 15:17:08 -07004624 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4625 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 return;
4627
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004628 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 /* If Master/Slave config fault is asserted twice,
4630 * we assume back-to-back */
Joe Perches1dc32912008-07-11 15:17:08 -07004631 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004632 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Joe Perches1dc32912008-07-11 15:17:08 -07004633 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004634 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Joe Perches1dc32912008-07-11 15:17:08 -07004635 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004636 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 phy_ctrl &= ~CR_1000T_MS_ENABLE;
Joe Perches1dc32912008-07-11 15:17:08 -07004638 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 phy_ctrl);
4640 adapter->smartspeed++;
Joe Perches1dc32912008-07-11 15:17:08 -07004641 if (!e1000_phy_setup_autoneg(hw) &&
4642 !e1000_read_phy_reg(hw, PHY_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643 &phy_ctrl)) {
4644 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4645 MII_CR_RESTART_AUTO_NEG);
Joe Perches1dc32912008-07-11 15:17:08 -07004646 e1000_write_phy_reg(hw, PHY_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 phy_ctrl);
4648 }
4649 }
4650 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004651 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 /* If still no link, perhaps using 2/3 pair cable */
Joe Perches1dc32912008-07-11 15:17:08 -07004653 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 phy_ctrl |= CR_1000T_MS_ENABLE;
Joe Perches1dc32912008-07-11 15:17:08 -07004655 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4656 if (!e1000_phy_setup_autoneg(hw) &&
4657 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4659 MII_CR_RESTART_AUTO_NEG);
Joe Perches1dc32912008-07-11 15:17:08 -07004660 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661 }
4662 }
4663 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004664 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 adapter->smartspeed = 0;
4666}
4667
4668/**
4669 * e1000_ioctl -
4670 * @netdev:
4671 * @ifreq:
4672 * @cmd:
4673 **/
4674
Joe Perches64798842008-07-11 15:17:02 -07004675static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676{
4677 switch (cmd) {
4678 case SIOCGMIIPHY:
4679 case SIOCGMIIREG:
4680 case SIOCSMIIREG:
4681 return e1000_mii_ioctl(netdev, ifr, cmd);
4682 default:
4683 return -EOPNOTSUPP;
4684 }
4685}
4686
4687/**
4688 * e1000_mii_ioctl -
4689 * @netdev:
4690 * @ifreq:
4691 * @cmd:
4692 **/
4693
Joe Perches64798842008-07-11 15:17:02 -07004694static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4695 int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004697 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004698 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699 struct mii_ioctl_data *data = if_mii(ifr);
4700 int retval;
Joe Perches406874a2008-04-03 10:06:32 -07004701 u16 mii_reg;
4702 u16 spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004703 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704
Joe Perches1dc32912008-07-11 15:17:08 -07004705 if (hw->media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 return -EOPNOTSUPP;
4707
4708 switch (cmd) {
4709 case SIOCGMIIPHY:
Joe Perches1dc32912008-07-11 15:17:08 -07004710 data->phy_id = hw->phy_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 break;
4712 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004713 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004715 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004716 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004717 &data->val_out)) {
4718 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004720 }
4721 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722 break;
4723 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004724 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004726 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727 return -EFAULT;
4728 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004729 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004730 if (e1000_write_phy_reg(hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004731 mii_reg)) {
4732 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004734 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004735 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004736 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 switch (data->reg_num) {
4738 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004739 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004741 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Joe Perches1dc32912008-07-11 15:17:08 -07004742 hw->autoneg = 1;
4743 hw->autoneg_advertised = 0x2F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 } else {
4745 if (mii_reg & 0x40)
4746 spddplx = SPEED_1000;
4747 else if (mii_reg & 0x2000)
4748 spddplx = SPEED_100;
4749 else
4750 spddplx = SPEED_10;
4751 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004752 ? DUPLEX_FULL :
4753 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 retval = e1000_set_spd_dplx(adapter,
4755 spddplx);
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004756 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757 return retval;
4758 }
Auke Kok2db10a02006-06-27 09:06:28 -07004759 if (netif_running(adapter->netdev))
4760 e1000_reinit_locked(adapter);
4761 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 e1000_reset(adapter);
4763 break;
4764 case M88E1000_PHY_SPEC_CTRL:
4765 case M88E1000_EXT_PHY_SPEC_CTRL:
Joe Perches1dc32912008-07-11 15:17:08 -07004766 if (e1000_phy_reset(hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 return -EIO;
4768 break;
4769 }
4770 } else {
4771 switch (data->reg_num) {
4772 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004773 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004775 if (netif_running(adapter->netdev))
4776 e1000_reinit_locked(adapter);
4777 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 e1000_reset(adapter);
4779 break;
4780 }
4781 }
4782 break;
4783 default:
4784 return -EOPNOTSUPP;
4785 }
4786 return E1000_SUCCESS;
4787}
4788
Joe Perches64798842008-07-11 15:17:02 -07004789void e1000_pci_set_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790{
4791 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004792 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004794 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004795 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796}
4797
Joe Perches64798842008-07-11 15:17:02 -07004798void e1000_pci_clear_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799{
4800 struct e1000_adapter *adapter = hw->back;
4801
4802 pci_clear_mwi(adapter->pdev);
4803}
4804
Joe Perches64798842008-07-11 15:17:02 -07004805int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
Peter Oruba007755e2007-09-28 22:42:06 -07004806{
4807 struct e1000_adapter *adapter = hw->back;
4808 return pcix_get_mmrbc(adapter->pdev);
4809}
4810
Joe Perches64798842008-07-11 15:17:02 -07004811void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
Peter Oruba007755e2007-09-28 22:42:06 -07004812{
4813 struct e1000_adapter *adapter = hw->back;
4814 pcix_set_mmrbc(adapter->pdev, mmrbc);
4815}
4816
Joe Perches64798842008-07-11 15:17:02 -07004817s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004818{
4819 struct e1000_adapter *adapter = hw->back;
Joe Perches406874a2008-04-03 10:06:32 -07004820 u16 cap_offset;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004821
4822 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4823 if (!cap_offset)
4824 return -E1000_ERR_CONFIG;
4825
4826 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4827
4828 return E1000_SUCCESS;
4829}
4830
Joe Perches64798842008-07-11 15:17:02 -07004831void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832{
4833 outl(value, port);
4834}
4835
Joe Perches64798842008-07-11 15:17:02 -07004836static void e1000_vlan_rx_register(struct net_device *netdev,
4837 struct vlan_group *grp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004839 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004840 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004841 u32 ctrl, rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004843 if (!test_bit(__E1000_DOWN, &adapter->flags))
4844 e1000_irq_disable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 adapter->vlgrp = grp;
4846
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004847 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 /* enable VLAN tag insert/strip */
Joe Perches1dc32912008-07-11 15:17:08 -07004849 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850 ctrl |= E1000_CTRL_VME;
Joe Perches1dc32912008-07-11 15:17:08 -07004851 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852
Auke Kokcd94dd02006-06-27 09:08:22 -07004853 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004854 /* enable VLAN receive filtering */
Joe Perches1dc32912008-07-11 15:17:08 -07004855 rctl = er32(RCTL);
Auke Kok90fb5132006-11-01 08:47:30 -08004856 rctl &= ~E1000_RCTL_CFIEN;
Joe Perches1dc32912008-07-11 15:17:08 -07004857 ew32(RCTL, rctl);
Auke Kok90fb5132006-11-01 08:47:30 -08004858 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004859 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860 } else {
4861 /* disable VLAN tag insert/strip */
Joe Perches1dc32912008-07-11 15:17:08 -07004862 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 ctrl &= ~E1000_CTRL_VME;
Joe Perches1dc32912008-07-11 15:17:08 -07004864 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865
Auke Kokcd94dd02006-06-27 09:08:22 -07004866 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004867 if (adapter->mng_vlan_id !=
Joe Perches406874a2008-04-03 10:06:32 -07004868 (u16)E1000_MNG_VLAN_NONE) {
Auke Kok90fb5132006-11-01 08:47:30 -08004869 e1000_vlan_rx_kill_vid(netdev,
4870 adapter->mng_vlan_id);
4871 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4872 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004873 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 }
4875
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004876 if (!test_bit(__E1000_DOWN, &adapter->flags))
4877 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878}
4879
Joe Perches64798842008-07-11 15:17:02 -07004880static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004882 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004883 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004884 u32 vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004885
Joe Perches1dc32912008-07-11 15:17:08 -07004886 if ((hw->mng_cookie.status &
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004887 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4888 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004889 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 /* add VID to filter table */
4891 index = (vid >> 5) & 0x7F;
Joe Perches1dc32912008-07-11 15:17:08 -07004892 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893 vfta |= (1 << (vid & 0x1F));
Joe Perches1dc32912008-07-11 15:17:08 -07004894 e1000_write_vfta(hw, index, vfta);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895}
4896
Joe Perches64798842008-07-11 15:17:02 -07004897static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004899 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004900 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004901 u32 vfta, index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004903 if (!test_bit(__E1000_DOWN, &adapter->flags))
4904 e1000_irq_disable(adapter);
Dan Aloni5c15bde2007-03-02 20:44:51 -08004905 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004906 if (!test_bit(__E1000_DOWN, &adapter->flags))
4907 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908
Joe Perches1dc32912008-07-11 15:17:08 -07004909 if ((hw->mng_cookie.status &
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004910 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004911 (vid == adapter->mng_vlan_id)) {
4912 /* release control to f/w */
4913 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004914 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004915 }
4916
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 /* remove VID from filter table */
4918 index = (vid >> 5) & 0x7F;
Joe Perches1dc32912008-07-11 15:17:08 -07004919 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920 vfta &= ~(1 << (vid & 0x1F));
Joe Perches1dc32912008-07-11 15:17:08 -07004921 e1000_write_vfta(hw, index, vfta);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922}
4923
Joe Perches64798842008-07-11 15:17:02 -07004924static void e1000_restore_vlan(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925{
4926 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4927
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004928 if (adapter->vlgrp) {
Joe Perches406874a2008-04-03 10:06:32 -07004929 u16 vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004930 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08004931 if (!vlan_group_get_device(adapter->vlgrp, vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932 continue;
4933 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4934 }
4935 }
4936}
4937
Joe Perches64798842008-07-11 15:17:02 -07004938int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939{
Joe Perches1dc32912008-07-11 15:17:08 -07004940 struct e1000_hw *hw = &adapter->hw;
4941
4942 hw->autoneg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943
Malli Chilakala69213682005-06-17 17:44:20 -07004944 /* Fiber NICs only allow 1000 gbps Full duplex */
Joe Perches1dc32912008-07-11 15:17:08 -07004945 if ((hw->media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004946 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4947 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4948 return -EINVAL;
4949 }
4950
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004951 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952 case SPEED_10 + DUPLEX_HALF:
Joe Perches1dc32912008-07-11 15:17:08 -07004953 hw->forced_speed_duplex = e1000_10_half;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 break;
4955 case SPEED_10 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07004956 hw->forced_speed_duplex = e1000_10_full;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 break;
4958 case SPEED_100 + DUPLEX_HALF:
Joe Perches1dc32912008-07-11 15:17:08 -07004959 hw->forced_speed_duplex = e1000_100_half;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 break;
4961 case SPEED_100 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07004962 hw->forced_speed_duplex = e1000_100_full;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 break;
4964 case SPEED_1000 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07004965 hw->autoneg = 1;
4966 hw->autoneg_advertised = ADVERTISE_1000_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967 break;
4968 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4969 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004970 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 return -EINVAL;
4972 }
4973 return 0;
4974}
4975
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00004976static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977{
4978 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004979 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004980 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004981 u32 ctrl, ctrl_ext, rctl, status;
4982 u32 wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07004983#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08004984 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07004985#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986
4987 netif_device_detach(netdev);
4988
Auke Kok2db10a02006-06-27 09:06:28 -07004989 if (netif_running(netdev)) {
4990 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07004992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004994#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08004995 retval = pci_save_state(pdev);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004996 if (retval)
4997 return retval;
4998#endif
4999
Joe Perches1dc32912008-07-11 15:17:08 -07005000 status = er32(STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005001 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002 wufc &= ~E1000_WUFC_LNKC;
5003
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005004 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005006 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007
5008 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005009 if (wufc & E1000_WUFC_MC) {
Joe Perches1dc32912008-07-11 15:17:08 -07005010 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 rctl |= E1000_RCTL_MPE;
Joe Perches1dc32912008-07-11 15:17:08 -07005012 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 }
5014
Joe Perches1dc32912008-07-11 15:17:08 -07005015 if (hw->mac_type >= e1000_82540) {
5016 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017 /* advertise wake from D3Cold */
5018 #define E1000_CTRL_ADVD3WUC 0x00100000
5019 /* phy power management enable */
5020 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5021 ctrl |= E1000_CTRL_ADVD3WUC |
5022 E1000_CTRL_EN_PHY_PWR_MGMT;
Joe Perches1dc32912008-07-11 15:17:08 -07005023 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 }
5025
Joe Perches1dc32912008-07-11 15:17:08 -07005026 if (hw->media_type == e1000_media_type_fiber ||
5027 hw->media_type == e1000_media_type_internal_serdes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 /* keep the laser running in D3 */
Joe Perches1dc32912008-07-11 15:17:08 -07005029 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07005031 ew32(CTRL_EXT, ctrl_ext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 }
5033
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005034 /* Allow time for pending master requests to run */
Joe Perches1dc32912008-07-11 15:17:08 -07005035 e1000_disable_pciex_master(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005036
Joe Perches1dc32912008-07-11 15:17:08 -07005037 ew32(WUC, E1000_WUC_PME_EN);
5038 ew32(WUFC, wufc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07005040 ew32(WUC, 0);
5041 ew32(WUFC, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042 }
5043
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005044 e1000_release_manageability(adapter);
5045
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005046 *enable_wake = !!wufc;
5047
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005048 /* make sure adapter isn't asleep if manageability is enabled */
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005049 if (adapter->en_mng_pt)
5050 *enable_wake = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051
Joe Perches1dc32912008-07-11 15:17:08 -07005052 if (hw->phy_type == e1000_phy_igp_3)
5053 e1000_phy_powerdown_workaround(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005054
Auke Kokedd106f2006-11-06 08:57:12 -08005055 if (netif_running(netdev))
5056 e1000_free_irq(adapter);
5057
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005058 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5059 * would have already happened in close and is redundant. */
5060 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005061
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005063
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064 return 0;
5065}
5066
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005067#ifdef CONFIG_PM
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005068static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5069{
5070 int retval;
5071 bool wake;
5072
5073 retval = __e1000_shutdown(pdev, &wake);
5074 if (retval)
5075 return retval;
5076
5077 if (wake) {
5078 pci_prepare_to_sleep(pdev);
5079 } else {
5080 pci_wake_from_d3(pdev, false);
5081 pci_set_power_state(pdev, PCI_D3hot);
5082 }
5083
5084 return 0;
5085}
5086
Joe Perches64798842008-07-11 15:17:02 -07005087static int e1000_resume(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088{
5089 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005090 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005091 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07005092 u32 err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093
Auke Kokd0e027d2006-04-14 19:04:40 -07005094 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005095 pci_restore_state(pdev);
Taku Izumi81250292008-07-11 15:17:44 -07005096
5097 if (adapter->need_ioport)
5098 err = pci_enable_device(pdev);
5099 else
5100 err = pci_enable_device_mem(pdev);
Joe Perchesc7be73b2008-07-11 15:17:28 -07005101 if (err) {
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005102 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5103 return err;
5104 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005105 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106
Auke Kokd0e027d2006-04-14 19:04:40 -07005107 pci_enable_wake(pdev, PCI_D3hot, 0);
5108 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109
Joe Perchesc7be73b2008-07-11 15:17:28 -07005110 if (netif_running(netdev)) {
5111 err = e1000_request_irq(adapter);
5112 if (err)
5113 return err;
5114 }
Auke Kokedd106f2006-11-06 08:57:12 -08005115
5116 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 e1000_reset(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07005118 ew32(WUS, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005120 e1000_init_manageability(adapter);
5121
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005122 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 e1000_up(adapter);
5124
5125 netif_device_attach(netdev);
5126
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005127 /* If the controller is 82573 and f/w is AMT, do not set
5128 * DRV_LOAD until the interface is up. For all other cases,
5129 * let the f/w know that the h/w is now under the control
5130 * of the driver. */
Joe Perches1dc32912008-07-11 15:17:08 -07005131 if (hw->mac_type != e1000_82573 ||
5132 !e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005133 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005134
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135 return 0;
5136}
5137#endif
Auke Kokc653e632006-05-23 13:35:57 -07005138
5139static void e1000_shutdown(struct pci_dev *pdev)
5140{
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005141 bool wake;
5142
5143 __e1000_shutdown(pdev, &wake);
5144
5145 if (system_state == SYSTEM_POWER_OFF) {
5146 pci_wake_from_d3(pdev, wake);
5147 pci_set_power_state(pdev, PCI_D3hot);
5148 }
Auke Kokc653e632006-05-23 13:35:57 -07005149}
5150
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151#ifdef CONFIG_NET_POLL_CONTROLLER
5152/*
5153 * Polling 'interrupt' - used by things like netconsole to send skbs
5154 * without having to re-enable interrupts. It's not called while
5155 * the interrupt routine is executing.
5156 */
Joe Perches64798842008-07-11 15:17:02 -07005157static void e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005159 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005160
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005162 e1000_intr(adapter->pdev->irq, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 enable_irq(adapter->pdev->irq);
5164}
5165#endif
5166
Auke Kok90267292006-06-08 09:30:24 -07005167/**
5168 * e1000_io_error_detected - called when PCI error is detected
5169 * @pdev: Pointer to PCI device
5170 * @state: The current pci conneection state
5171 *
5172 * This function is called after a PCI bus error affecting
5173 * this device has been detected.
5174 */
Joe Perches64798842008-07-11 15:17:02 -07005175static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5176 pci_channel_state_t state)
Auke Kok90267292006-06-08 09:30:24 -07005177{
5178 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen4cf16532008-11-12 23:38:14 -08005179 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok90267292006-06-08 09:30:24 -07005180
5181 netif_device_detach(netdev);
5182
Andre Detscheab63302009-06-30 12:46:13 +00005183 if (state == pci_channel_io_perm_failure)
5184 return PCI_ERS_RESULT_DISCONNECT;
5185
Auke Kok90267292006-06-08 09:30:24 -07005186 if (netif_running(netdev))
5187 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005188 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005189
5190 /* Request a slot slot reset. */
5191 return PCI_ERS_RESULT_NEED_RESET;
5192}
5193
5194/**
5195 * e1000_io_slot_reset - called after the pci bus has been reset.
5196 * @pdev: Pointer to PCI device
5197 *
5198 * Restart the card from scratch, as if from a cold-boot. Implementation
5199 * resembles the first-half of the e1000_resume routine.
5200 */
5201static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5202{
5203 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen4cf16532008-11-12 23:38:14 -08005204 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005205 struct e1000_hw *hw = &adapter->hw;
Taku Izumi81250292008-07-11 15:17:44 -07005206 int err;
Auke Kok90267292006-06-08 09:30:24 -07005207
Taku Izumi81250292008-07-11 15:17:44 -07005208 if (adapter->need_ioport)
5209 err = pci_enable_device(pdev);
5210 else
5211 err = pci_enable_device_mem(pdev);
5212 if (err) {
Auke Kok90267292006-06-08 09:30:24 -07005213 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5214 return PCI_ERS_RESULT_DISCONNECT;
5215 }
5216 pci_set_master(pdev);
5217
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005218 pci_enable_wake(pdev, PCI_D3hot, 0);
5219 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005220
Auke Kok90267292006-06-08 09:30:24 -07005221 e1000_reset(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07005222 ew32(WUS, ~0);
Auke Kok90267292006-06-08 09:30:24 -07005223
5224 return PCI_ERS_RESULT_RECOVERED;
5225}
5226
5227/**
5228 * e1000_io_resume - called when traffic can start flowing again.
5229 * @pdev: Pointer to PCI device
5230 *
5231 * This callback is called when the error recovery driver tells us that
5232 * its OK to resume normal operation. Implementation resembles the
5233 * second-half of the e1000_resume routine.
5234 */
5235static void e1000_io_resume(struct pci_dev *pdev)
5236{
5237 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen4cf16532008-11-12 23:38:14 -08005238 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005239 struct e1000_hw *hw = &adapter->hw;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005240
5241 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005242
5243 if (netif_running(netdev)) {
5244 if (e1000_up(adapter)) {
5245 printk("e1000: can't bring device back up after reset\n");
5246 return;
5247 }
5248 }
5249
5250 netif_device_attach(netdev);
5251
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005252 /* If the controller is 82573 and f/w is AMT, do not set
5253 * DRV_LOAD until the interface is up. For all other cases,
5254 * let the f/w know that the h/w is now under the control
5255 * of the driver. */
Joe Perches1dc32912008-07-11 15:17:08 -07005256 if (hw->mac_type != e1000_82573 ||
5257 !e1000_check_mng_mode(hw))
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005258 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005259
Auke Kok90267292006-06-08 09:30:24 -07005260}
5261
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262/* e1000_main.c */