blob: f2db9e2069e778d830638b8bc34a2bc232b59c3c [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;
644 u16 fc_high_water_mark = E1000_FC_HIGH_DIFF;
Joe Perchesc3033b02008-03-21 11:06:25 -0700645 bool legacy_pba_adjust = false;
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) {
Bruce Allan018ea442006-12-15 10:39:45 +0100689 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
690 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 }
Joe Perches1dc32912008-07-11 15:17:08 -0700699 } else if (hw->max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
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
704 * large enough to accomodate two full transmit packets,
705 * rounded up to the next 1KB and expressed in KB. Likewise,
706 * the Rx FIFO should be large enough to accomodate at least
707 * 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;
714 /* don't include ethernet FCS because hardware appends/strips */
715 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
716 VLAN_TAG_SIZE;
717 min_tx_space = min_rx_space;
718 min_tx_space *= 2;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700719 min_tx_space = ALIGN(min_tx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100720 min_tx_space >>= 10;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700721 min_rx_space = ALIGN(min_rx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100722 min_rx_space >>= 10;
723
724 /* If current Tx allocation is less than the min Tx FIFO size,
725 * and the min Tx FIFO size is less than the current Rx FIFO
726 * allocation, take space away from current Rx allocation */
727 if (tx_space < min_tx_space &&
728 ((min_tx_space - tx_space) < pba)) {
729 pba = pba - (min_tx_space - tx_space);
730
731 /* PCI/PCIx hardware has PBA alignment constraints */
Joe Perches1dc32912008-07-11 15:17:08 -0700732 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100733 case e1000_82545 ... e1000_82546_rev_3:
734 pba &= ~(E1000_PBA_8K - 1);
735 break;
736 default:
737 break;
738 }
739
740 /* if short on rx space, rx wins and must trump tx
741 * adjustment or use Early Receive if available */
742 if (pba < min_rx_space) {
Joe Perches1dc32912008-07-11 15:17:08 -0700743 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100744 case e1000_82573:
745 /* ERT enabled in e1000_configure_rx */
746 break;
747 default:
748 pba = min_rx_space;
749 break;
750 }
751 }
752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700754
Joe Perches1dc32912008-07-11 15:17:08 -0700755 ew32(PBA, pba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800758 /* Set the FC high water mark to 90% of the FIFO size.
759 * Required to clear last 3 LSB */
760 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700761 /* We can't use 90% on small FIFOs because the remainder
762 * would be less than 1 full frame. In this case, we size
763 * it to allow at least a full frame above the high water
764 * mark. */
765 if (pba < E1000_PBA_16K)
766 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800767
Joe Perches1dc32912008-07-11 15:17:08 -0700768 hw->fc_high_water = fc_high_water_mark;
769 hw->fc_low_water = fc_high_water_mark - 8;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +0000770 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
Joe Perches1dc32912008-07-11 15:17:08 -0700771 hw->fc_send_xon = 1;
772 hw->fc = hw->original_fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700774 /* Allow time for pending master requests to run */
Joe Perches1dc32912008-07-11 15:17:08 -0700775 e1000_reset_hw(hw);
776 if (hw->mac_type >= e1000_82544)
777 ew32(WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700778
Joe Perches1dc32912008-07-11 15:17:08 -0700779 if (e1000_init_hw(hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700781 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100782
783 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
Joe Perches1dc32912008-07-11 15:17:08 -0700784 if (hw->mac_type >= e1000_82544 &&
785 hw->mac_type <= e1000_82547_rev_2 &&
786 hw->autoneg == 1 &&
787 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
788 u32 ctrl = er32(CTRL);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100789 /* clear phy power management bit if we are in gig only mode,
790 * which if enabled will attempt negotiation to 100Mb, which
791 * can cause a loss of link at power off or driver unload */
792 ctrl &= ~E1000_CTRL_SWDPIN3;
Joe Perches1dc32912008-07-11 15:17:08 -0700793 ew32(CTRL, ctrl);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100794 }
795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
Joe Perches1dc32912008-07-11 15:17:08 -0700797 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Joe Perches1dc32912008-07-11 15:17:08 -0700799 e1000_reset_adaptive(hw);
800 e1000_phy_get_info(hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700801
802 if (!adapter->smart_power_down &&
Joe Perches1dc32912008-07-11 15:17:08 -0700803 (hw->mac_type == e1000_82571 ||
804 hw->mac_type == e1000_82572)) {
Joe Perches406874a2008-04-03 10:06:32 -0700805 u16 phy_data = 0;
Auke Kok9a53a202006-06-27 09:06:45 -0700806 /* speed up time to link by disabling smart power down, ignore
807 * the return value of this function because there is nothing
808 * different we would do if it failed */
Joe Perches1dc32912008-07-11 15:17:08 -0700809 e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9a53a202006-06-27 09:06:45 -0700810 &phy_data);
811 phy_data &= ~IGP02E1000_PM_SPD;
Joe Perches1dc32912008-07-11 15:17:08 -0700812 e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9a53a202006-06-27 09:06:45 -0700813 phy_data);
814 }
815
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500816 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
819/**
Auke Kok67b3c272007-12-17 13:50:23 -0800820 * Dump the eeprom for users having checksum issues
821 **/
Adrian Bunkb4ea8952008-02-01 08:21:28 -0800822static void e1000_dump_eeprom(struct e1000_adapter *adapter)
Auke Kok67b3c272007-12-17 13:50:23 -0800823{
824 struct net_device *netdev = adapter->netdev;
825 struct ethtool_eeprom eeprom;
826 const struct ethtool_ops *ops = netdev->ethtool_ops;
827 u8 *data;
828 int i;
829 u16 csum_old, csum_new = 0;
830
831 eeprom.len = ops->get_eeprom_len(netdev);
832 eeprom.offset = 0;
833
834 data = kmalloc(eeprom.len, GFP_KERNEL);
835 if (!data) {
836 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
837 " data\n");
838 return;
839 }
840
841 ops->get_eeprom(netdev, &eeprom, data);
842
843 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
844 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
845 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
846 csum_new += data[i] + (data[i + 1] << 8);
847 csum_new = EEPROM_SUM - csum_new;
848
849 printk(KERN_ERR "/*********************/\n");
850 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
851 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
852
853 printk(KERN_ERR "Offset Values\n");
854 printk(KERN_ERR "======== ======\n");
855 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
856
857 printk(KERN_ERR "Include this output when contacting your support "
858 "provider.\n");
859 printk(KERN_ERR "This is not a software error! Something bad "
860 "happened to your hardware or\n");
861 printk(KERN_ERR "EEPROM image. Ignoring this "
862 "problem could result in further problems,\n");
863 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
864 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
865 "which is invalid\n");
866 printk(KERN_ERR "and requires you to set the proper MAC "
867 "address manually before continuing\n");
868 printk(KERN_ERR "to enable this network device.\n");
869 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
870 "to your hardware vendor\n");
Jeff Kirsher63cd31f2008-07-11 15:17:33 -0700871 printk(KERN_ERR "or Intel Customer Support.\n");
Auke Kok67b3c272007-12-17 13:50:23 -0800872 printk(KERN_ERR "/*********************/\n");
873
874 kfree(data);
875}
876
877/**
Taku Izumi81250292008-07-11 15:17:44 -0700878 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
879 * @pdev: PCI device information struct
880 *
881 * Return true if an adapter needs ioport resources
882 **/
883static int e1000_is_need_ioport(struct pci_dev *pdev)
884{
885 switch (pdev->device) {
886 case E1000_DEV_ID_82540EM:
887 case E1000_DEV_ID_82540EM_LOM:
888 case E1000_DEV_ID_82540EP:
889 case E1000_DEV_ID_82540EP_LOM:
890 case E1000_DEV_ID_82540EP_LP:
891 case E1000_DEV_ID_82541EI:
892 case E1000_DEV_ID_82541EI_MOBILE:
893 case E1000_DEV_ID_82541ER:
894 case E1000_DEV_ID_82541ER_LOM:
895 case E1000_DEV_ID_82541GI:
896 case E1000_DEV_ID_82541GI_LF:
897 case E1000_DEV_ID_82541GI_MOBILE:
898 case E1000_DEV_ID_82544EI_COPPER:
899 case E1000_DEV_ID_82544EI_FIBER:
900 case E1000_DEV_ID_82544GC_COPPER:
901 case E1000_DEV_ID_82544GC_LOM:
902 case E1000_DEV_ID_82545EM_COPPER:
903 case E1000_DEV_ID_82545EM_FIBER:
904 case E1000_DEV_ID_82546EB_COPPER:
905 case E1000_DEV_ID_82546EB_FIBER:
906 case E1000_DEV_ID_82546EB_QUAD_COPPER:
907 return true;
908 default:
909 return false;
910 }
911}
912
Stephen Hemminger0e7614b2008-11-19 22:18:22 -0800913static const struct net_device_ops e1000_netdev_ops = {
914 .ndo_open = e1000_open,
915 .ndo_stop = e1000_close,
Stephen Hemminger00829822008-11-20 20:14:53 -0800916 .ndo_start_xmit = e1000_xmit_frame,
Stephen Hemminger0e7614b2008-11-19 22:18:22 -0800917 .ndo_get_stats = e1000_get_stats,
918 .ndo_set_rx_mode = e1000_set_rx_mode,
919 .ndo_set_mac_address = e1000_set_mac,
920 .ndo_tx_timeout = e1000_tx_timeout,
921 .ndo_change_mtu = e1000_change_mtu,
922 .ndo_do_ioctl = e1000_ioctl,
923 .ndo_validate_addr = eth_validate_addr,
924
925 .ndo_vlan_rx_register = e1000_vlan_rx_register,
926 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
927 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
928#ifdef CONFIG_NET_POLL_CONTROLLER
929 .ndo_poll_controller = e1000_netpoll,
930#endif
931};
932
Taku Izumi81250292008-07-11 15:17:44 -0700933/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 * e1000_probe - Device Initialization Routine
935 * @pdev: PCI device information struct
936 * @ent: entry in e1000_pci_tbl
937 *
938 * Returns 0 on success, negative on failure
939 *
940 * e1000_probe initializes an adapter identified by a pci_dev structure.
941 * The OS initialization, configuring of the adapter private structure,
942 * and a hardware reset occur.
943 **/
Joe Perches1dc32912008-07-11 15:17:08 -0700944static int __devinit e1000_probe(struct pci_dev *pdev,
945 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
947 struct net_device *netdev;
948 struct e1000_adapter *adapter;
Joe Perches1dc32912008-07-11 15:17:08 -0700949 struct e1000_hw *hw;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700952 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700953 int i, err, pci_using_dac;
Joe Perches406874a2008-04-03 10:06:32 -0700954 u16 eeprom_data = 0;
955 u16 eeprom_apme_mask = E1000_EEPROM_APME;
Taku Izumi81250292008-07-11 15:17:44 -0700956 int bars, need_ioport;
Joe Perches0795af52007-10-03 17:59:30 -0700957
Taku Izumi81250292008-07-11 15:17:44 -0700958 /* do not allocate ioport bars when not needed */
959 need_ioport = e1000_is_need_ioport(pdev);
960 if (need_ioport) {
961 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
962 err = pci_enable_device(pdev);
963 } else {
964 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Karsten Keil4d7155b2009-02-03 15:18:01 -0800965 err = pci_enable_device_mem(pdev);
Taku Izumi81250292008-07-11 15:17:44 -0700966 }
Joe Perchesc7be73b2008-07-11 15:17:28 -0700967 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 return err;
969
Yang Hongyang6a355282009-04-06 19:01:13 -0700970 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
971 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 pci_using_dac = 1;
973 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -0700974 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Joe Perchesc7be73b2008-07-11 15:17:28 -0700975 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -0700976 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Joe Perchesc7be73b2008-07-11 15:17:28 -0700977 if (err) {
978 E1000_ERR("No usable DMA configuration, "
979 "aborting\n");
980 goto err_dma;
981 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 }
983 pci_using_dac = 0;
984 }
985
Taku Izumi81250292008-07-11 15:17:44 -0700986 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
Joe Perchesc7be73b2008-07-11 15:17:28 -0700987 if (err)
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700988 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
990 pci_set_master(pdev);
991
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700992 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700994 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 SET_NETDEV_DEV(netdev, &pdev->dev);
998
999 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001000 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 adapter->netdev = netdev;
1002 adapter->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 adapter->msg_enable = (1 << debug) - 1;
Taku Izumi81250292008-07-11 15:17:44 -07001004 adapter->bars = bars;
1005 adapter->need_ioport = need_ioport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Joe Perches1dc32912008-07-11 15:17:08 -07001007 hw = &adapter->hw;
1008 hw->back = adapter;
1009
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001010 err = -EIO;
Arjan van de Ven275f1652008-10-20 21:42:39 -07001011 hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
Joe Perches1dc32912008-07-11 15:17:08 -07001012 if (!hw->hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Taku Izumi81250292008-07-11 15:17:44 -07001015 if (adapter->need_ioport) {
1016 for (i = BAR_1; i <= BAR_5; i++) {
1017 if (pci_resource_len(pdev, i) == 0)
1018 continue;
1019 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1020 hw->io_base = pci_resource_start(pdev, i);
1021 break;
1022 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024 }
1025
Stephen Hemminger0e7614b2008-11-19 22:18:22 -08001026 netdev->netdev_ops = &e1000_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 e1000_set_ethtool_ops(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 netdev->watchdog_timeo = 5 * HZ;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001029 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Stephen Hemminger0e7614b2008-11-19 22:18:22 -08001030
Auke Kok0eb5a342006-09-27 12:53:17 -07001031 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 adapter->bd_number = cards_found;
1034
1035 /* setup the private structure */
1036
Joe Perchesc7be73b2008-07-11 15:17:28 -07001037 err = e1000_sw_init(adapter);
1038 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 goto err_sw_init;
1040
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001041 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -07001042 /* Flash BAR mapping must happen after e1000_sw_init
1043 * because it depends on mac_type */
Joe Perches1dc32912008-07-11 15:17:08 -07001044 if ((hw->mac_type == e1000_ich8lan) &&
Auke Kokcd94dd02006-06-27 09:08:22 -07001045 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
Arjan van de Ven275f1652008-10-20 21:42:39 -07001046 hw->flash_address = pci_ioremap_bar(pdev, 1);
Joe Perches1dc32912008-07-11 15:17:08 -07001047 if (!hw->flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -07001048 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -07001049 }
1050
Joe Perches1dc32912008-07-11 15:17:08 -07001051 if (e1000_check_phy_reset_block(hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001052 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
1053
Joe Perches1dc32912008-07-11 15:17:08 -07001054 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 netdev->features = NETIF_F_SG |
1056 NETIF_F_HW_CSUM |
1057 NETIF_F_HW_VLAN_TX |
1058 NETIF_F_HW_VLAN_RX |
1059 NETIF_F_HW_VLAN_FILTER;
Joe Perches1dc32912008-07-11 15:17:08 -07001060 if (hw->mac_type == e1000_ich8lan)
Auke Kokcd94dd02006-06-27 09:08:22 -07001061 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063
Joe Perches1dc32912008-07-11 15:17:08 -07001064 if ((hw->mac_type >= e1000_82544) &&
1065 (hw->mac_type != e1000_82547))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001067
Joe Perches1dc32912008-07-11 15:17:08 -07001068 if (hw->mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -08001069 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001070 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 netdev->features |= NETIF_F_HIGHDMA;
1072
Patrick McHardy20501a62008-10-11 12:25:59 -07001073 netdev->vlan_features |= NETIF_F_TSO;
1074 netdev->vlan_features |= NETIF_F_TSO6;
1075 netdev->vlan_features |= NETIF_F_HW_CSUM;
1076 netdev->vlan_features |= NETIF_F_SG;
1077
Joe Perches1dc32912008-07-11 15:17:08 -07001078 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001079
Auke Kokcd94dd02006-06-27 09:08:22 -07001080 /* initialize eeprom parameters */
Joe Perches1dc32912008-07-11 15:17:08 -07001081 if (e1000_init_eeprom_params(hw)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001082 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001083 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001084 }
1085
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001086 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001088
Joe Perches1dc32912008-07-11 15:17:08 -07001089 e1000_reset_hw(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
1091 /* make sure the EEPROM is good */
Joe Perches1dc32912008-07-11 15:17:08 -07001092 if (e1000_validate_eeprom_checksum(hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Auke Kok67b3c272007-12-17 13:50:23 -08001094 e1000_dump_eeprom(adapter);
1095 /*
1096 * set MAC address to all zeroes to invalidate and temporary
1097 * disable this device for the user. This blocks regular
1098 * traffic while still permitting ethtool ioctls from reaching
1099 * the hardware as well as allowing the user to run the
1100 * interface after manually setting a hw addr using
1101 * `ip set address`
1102 */
Joe Perches1dc32912008-07-11 15:17:08 -07001103 memset(hw->mac_addr, 0, netdev->addr_len);
Auke Kok67b3c272007-12-17 13:50:23 -08001104 } else {
1105 /* copy the MAC address out of the EEPROM */
Joe Perches1dc32912008-07-11 15:17:08 -07001106 if (e1000_read_mac_addr(hw))
Auke Kok67b3c272007-12-17 13:50:23 -08001107 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 }
Auke Kok67b3c272007-12-17 13:50:23 -08001109 /* don't block initalization here due to bad MAC address */
Joe Perches1dc32912008-07-11 15:17:08 -07001110 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1111 memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Auke Kok67b3c272007-12-17 13:50:23 -08001113 if (!is_valid_ether_addr(netdev->perm_addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Joe Perches1dc32912008-07-11 15:17:08 -07001116 e1000_get_bus_info(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118 init_timer(&adapter->tx_fifo_stall_timer);
1119 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
Joe Perchese982f172008-07-11 15:17:18 -07001120 adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
1122 init_timer(&adapter->watchdog_timer);
1123 adapter->watchdog_timer.function = &e1000_watchdog;
1124 adapter->watchdog_timer.data = (unsigned long) adapter;
1125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 init_timer(&adapter->phy_info_timer);
1127 adapter->phy_info_timer.function = &e1000_update_phy_info;
Joe Perchese982f172008-07-11 15:17:18 -07001128 adapter->phy_info_timer.data = (unsigned long)adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
David Howells65f27f32006-11-22 14:55:48 +00001130 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 e1000_check_options(adapter);
1133
1134 /* Initial Wake on LAN setting
1135 * If APM wake is enabled in the EEPROM,
1136 * enable the ACPI Magic Packet filter
1137 */
1138
Joe Perches1dc32912008-07-11 15:17:08 -07001139 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 case e1000_82542_rev2_0:
1141 case e1000_82542_rev2_1:
1142 case e1000_82543:
1143 break;
1144 case e1000_82544:
Joe Perches1dc32912008-07-11 15:17:08 -07001145 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1147 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1148 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001149 case e1000_ich8lan:
Joe Perches1dc32912008-07-11 15:17:08 -07001150 e1000_read_eeprom(hw,
Auke Kokcd94dd02006-06-27 09:08:22 -07001151 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1152 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1153 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 case e1000_82546:
1155 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001156 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001157 case e1000_80003es2lan:
Joe Perches1dc32912008-07-11 15:17:08 -07001158 if (er32(STATUS) & E1000_STATUS_FUNC_1){
1159 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1161 break;
1162 }
1163 /* Fall Through */
1164 default:
Joe Perches1dc32912008-07-11 15:17:08 -07001165 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1167 break;
1168 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001169 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001170 adapter->eeprom_wol |= E1000_WUFC_MAG;
1171
1172 /* now that we have the eeprom settings, apply the special cases
1173 * where the eeprom may be wrong or the board simply won't support
1174 * wake on lan on a particular port */
1175 switch (pdev->device) {
1176 case E1000_DEV_ID_82546GB_PCIE:
1177 adapter->eeprom_wol = 0;
1178 break;
1179 case E1000_DEV_ID_82546EB_FIBER:
1180 case E1000_DEV_ID_82546GB_FIBER:
1181 case E1000_DEV_ID_82571EB_FIBER:
1182 /* Wake events only supported on port A for dual fiber
1183 * regardless of eeprom setting */
Joe Perches1dc32912008-07-11 15:17:08 -07001184 if (er32(STATUS) & E1000_STATUS_FUNC_1)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001185 adapter->eeprom_wol = 0;
1186 break;
1187 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001188 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001189 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001190 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001191 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001192 /* if quad port adapter, disable WoL on all but port A */
1193 if (global_quad_port_a != 0)
1194 adapter->eeprom_wol = 0;
1195 else
1196 adapter->quad_port_a = 1;
1197 /* Reset for multiple quad port adapters */
1198 if (++global_quad_port_a == 4)
1199 global_quad_port_a = 0;
1200 break;
1201 }
1202
1203 /* initialize the wol settings based on the eeprom settings */
1204 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\de126482008-11-07 20:30:19 +00001205 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001207 /* print bus type/speed/width info */
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001208 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1209 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1210 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1211 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1212 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1213 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1214 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1215 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1216 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1217 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1218 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1219 "32-bit"));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001220
Johannes Berge1749612008-10-27 15:59:26 -07001221 printk("%pM\n", netdev->dev_addr);
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001222
Joe Perches1dc32912008-07-11 15:17:08 -07001223 if (hw->bus_type == e1000_bus_type_pci_express) {
Auke Kok14782ca2008-02-11 09:25:46 -08001224 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1225 "longer be supported by this driver in the future.\n",
1226 pdev->vendor, pdev->device);
1227 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1228 "driver instead.\n");
1229 }
1230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 /* reset the hardware with the new settings */
1232 e1000_reset(adapter);
1233
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001234 /* If the controller is 82573 and f/w is AMT, do not set
1235 * DRV_LOAD until the interface is up. For all other cases,
1236 * let the f/w know that the h/w is now under the control
1237 * of the driver. */
Joe Perches1dc32912008-07-11 15:17:08 -07001238 if (hw->mac_type != e1000_82573 ||
1239 !e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001240 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001241
Auke Kok416b5d12007-06-01 10:22:39 -07001242 strcpy(netdev->name, "eth%d");
Joe Perchesc7be73b2008-07-11 15:17:28 -07001243 err = register_netdev(netdev);
1244 if (err)
Auke Kok416b5d12007-06-01 10:22:39 -07001245 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001246
Jesse Brandeburgeb62efd2009-04-17 20:44:36 +00001247 /* carrier off reporting is important to ethtool even BEFORE open */
1248 netif_carrier_off(netdev);
1249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1251
1252 cards_found++;
1253 return 0;
1254
1255err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001256 e1000_release_hw_control(adapter);
1257err_eeprom:
Joe Perches1dc32912008-07-11 15:17:08 -07001258 if (!e1000_check_phy_reset_block(hw))
1259 e1000_phy_hw_reset(hw);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001260
Joe Perches1dc32912008-07-11 15:17:08 -07001261 if (hw->flash_address)
1262 iounmap(hw->flash_address);
Auke Kokcd94dd02006-06-27 09:08:22 -07001263err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001264 kfree(adapter->tx_ring);
1265 kfree(adapter->rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266err_sw_init:
Joe Perches1dc32912008-07-11 15:17:08 -07001267 iounmap(hw->hw_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268err_ioremap:
1269 free_netdev(netdev);
1270err_alloc_etherdev:
Taku Izumi81250292008-07-11 15:17:44 -07001271 pci_release_selected_regions(pdev, bars);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001272err_pci_reg:
1273err_dma:
1274 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 return err;
1276}
1277
1278/**
1279 * e1000_remove - Device Removal Routine
1280 * @pdev: PCI device information struct
1281 *
1282 * e1000_remove is called by the PCI subsystem to alert the driver
1283 * that it should release a PCI device. The could be caused by a
1284 * Hot-Plug event, or because the driver is going to be removed from
1285 * memory.
1286 **/
1287
Joe Perches64798842008-07-11 15:17:02 -07001288static void __devexit e1000_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
1290 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001291 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001292 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Oleg Nesterov28e53bd2007-05-09 02:34:22 -07001294 cancel_work_sync(&adapter->reset_task);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001295
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001296 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001298 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1299 * would have already happened in close and is redundant. */
1300 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001301
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001302 unregister_netdev(netdev);
1303
Joe Perches1dc32912008-07-11 15:17:08 -07001304 if (!e1000_check_phy_reset_block(hw))
1305 e1000_phy_hw_reset(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001307 kfree(adapter->tx_ring);
1308 kfree(adapter->rx_ring);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001309
Joe Perches1dc32912008-07-11 15:17:08 -07001310 iounmap(hw->hw_addr);
1311 if (hw->flash_address)
1312 iounmap(hw->flash_address);
Taku Izumi81250292008-07-11 15:17:44 -07001313 pci_release_selected_regions(pdev, adapter->bars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
1315 free_netdev(netdev);
1316
1317 pci_disable_device(pdev);
1318}
1319
1320/**
1321 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1322 * @adapter: board private structure to initialize
1323 *
1324 * e1000_sw_init initializes the Adapter private data structure.
1325 * Fields are initialized based on PCI device information and
1326 * OS network device settings (MTU size).
1327 **/
1328
Joe Perches64798842008-07-11 15:17:02 -07001329static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330{
1331 struct e1000_hw *hw = &adapter->hw;
1332 struct net_device *netdev = adapter->netdev;
1333 struct pci_dev *pdev = adapter->pdev;
1334
1335 /* PCI config space info */
1336
1337 hw->vendor_id = pdev->vendor;
1338 hw->device_id = pdev->device;
1339 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1340 hw->subsystem_id = pdev->subsystem_device;
Auke Kok44c10132007-06-08 15:46:36 -07001341 hw->revision_id = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1344
Auke Kokeb0f8052006-07-14 16:14:48 -07001345 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 hw->max_frame_size = netdev->mtu +
1347 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1348 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1349
1350 /* identify the MAC */
1351
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001352 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1354 return -EIO;
1355 }
1356
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001357 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 default:
1359 break;
1360 case e1000_82541:
1361 case e1000_82547:
1362 case e1000_82541_rev_2:
1363 case e1000_82547_rev_2:
1364 hw->phy_init_script = 1;
1365 break;
1366 }
1367
1368 e1000_set_media_type(hw);
1369
Joe Perchesc3033b02008-03-21 11:06:25 -07001370 hw->wait_autoneg_complete = false;
1371 hw->tbi_compatibility_en = true;
1372 hw->adaptive_ifs = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
1374 /* Copper options */
1375
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001376 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 hw->mdix = AUTO_ALL_MODES;
Joe Perchesc3033b02008-03-21 11:06:25 -07001378 hw->disable_polarity_correction = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 hw->master_slave = E1000_MASTER_SLAVE;
1380 }
1381
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001382 adapter->num_tx_queues = 1;
1383 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001384
1385 if (e1000_alloc_queues(adapter)) {
1386 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1387 return -ENOMEM;
1388 }
1389
Herbert Xu47313052007-05-29 15:07:31 -07001390 /* Explicitly disable IRQ since the NIC can be in any state. */
Herbert Xu47313052007-05-29 15:07:31 -07001391 e1000_irq_disable(adapter);
1392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Auke Kok1314bbf2006-09-27 12:54:02 -07001395 set_bit(__E1000_DOWN, &adapter->flags);
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 return 0;
1398}
1399
1400/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001401 * e1000_alloc_queues - Allocate memory for all rings
1402 * @adapter: board private structure to initialize
1403 *
1404 * We allocate one ring per queue at run-time since we don't know the
Wang Chen3e1d7cd2008-12-03 22:07:10 -08001405 * number of queues at compile-time.
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001406 **/
1407
Joe Perches64798842008-07-11 15:17:02 -07001408static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001409{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001410 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1411 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001412 if (!adapter->tx_ring)
1413 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001414
Yan Burman1c7e5b12007-03-06 08:58:04 -08001415 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1416 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001417 if (!adapter->rx_ring) {
1418 kfree(adapter->tx_ring);
1419 return -ENOMEM;
1420 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001421
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001422 return E1000_SUCCESS;
1423}
1424
1425/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 * e1000_open - Called when a network interface is made active
1427 * @netdev: network interface device structure
1428 *
1429 * Returns 0 on success, negative value on failure
1430 *
1431 * The open entry point is called when a network interface is made
1432 * active by the system (IFF_UP). At this point all resources needed
1433 * for transmit and receive operations are allocated, the interrupt
1434 * handler is registered with the OS, the watchdog timer is started,
1435 * and the stack is notified that the interface is ready.
1436 **/
1437
Joe Perches64798842008-07-11 15:17:02 -07001438static int e1000_open(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001440 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001441 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 int err;
1443
Auke Kok2db10a02006-06-27 09:06:28 -07001444 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001445 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001446 return -EBUSY;
1447
Jesse Brandeburgeb62efd2009-04-17 20:44:36 +00001448 netif_carrier_off(netdev);
1449
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001451 err = e1000_setup_all_tx_resources(adapter);
1452 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 goto err_setup_tx;
1454
1455 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001456 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001457 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001458 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001459
Auke Kok79f05bf2006-06-27 09:06:32 -07001460 e1000_power_up_phy(adapter);
1461
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001462 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Joe Perches1dc32912008-07-11 15:17:08 -07001463 if ((hw->mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001464 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1465 e1000_update_mng_vlan(adapter);
1466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001468 /* If AMT is enabled, let the firmware know that the network
1469 * interface is now open */
Joe Perches1dc32912008-07-11 15:17:08 -07001470 if (hw->mac_type == e1000_82573 &&
1471 e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001472 e1000_get_hw_control(adapter);
1473
Auke Koke0aac5a2007-03-06 08:57:21 -08001474 /* before we allocate an interrupt, we must be ready to handle it.
1475 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1476 * as soon as we call pci_request_irq, so we have to setup our
1477 * clean_rx handler before we do so. */
1478 e1000_configure(adapter);
1479
1480 err = e1000_request_irq(adapter);
1481 if (err)
1482 goto err_req_irq;
1483
1484 /* From here on the code is the same as e1000_up() */
1485 clear_bit(__E1000_DOWN, &adapter->flags);
1486
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001487 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001488
Auke Koke0aac5a2007-03-06 08:57:21 -08001489 e1000_irq_enable(adapter);
1490
Ben Hutchings076152d2008-07-18 17:50:57 -07001491 netif_start_queue(netdev);
1492
Auke Koke0aac5a2007-03-06 08:57:21 -08001493 /* fire a link status change interrupt to start the watchdog */
Joe Perches1dc32912008-07-11 15:17:08 -07001494 ew32(ICS, E1000_ICS_LSC);
Auke Koke0aac5a2007-03-06 08:57:21 -08001495
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 return E1000_SUCCESS;
1497
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001498err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001499 e1000_release_hw_control(adapter);
1500 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001501 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001503 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504err_setup_tx:
1505 e1000_reset(adapter);
1506
1507 return err;
1508}
1509
1510/**
1511 * e1000_close - Disables a network interface
1512 * @netdev: network interface device structure
1513 *
1514 * Returns 0, this is not allowed to fail
1515 *
1516 * The close entry point is called when an interface is de-activated
1517 * by the OS. The hardware is still under the drivers control, but
1518 * needs to be disabled. A global MAC reset is issued to stop the
1519 * hardware, and all transmit and receive resources are freed.
1520 **/
1521
Joe Perches64798842008-07-11 15:17:02 -07001522static int e1000_close(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001524 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001525 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Auke Kok2db10a02006-06-27 09:06:28 -07001527 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001529 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001530 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001532 e1000_free_all_tx_resources(adapter);
1533 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Bruce Allan46665602006-09-27 12:54:08 -07001535 /* kill manageability vlan ID if supported, but not if a vlan with
1536 * the same ID is registered on the host OS (let 8021q kill it) */
Joe Perches1dc32912008-07-11 15:17:08 -07001537 if ((hw->mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001538 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1539 !(adapter->vlgrp &&
Dan Aloni5c15bde2007-03-02 20:44:51 -08001540 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001541 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1542 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001543
1544 /* If AMT is enabled, let the firmware know that the network
1545 * interface is now closed */
Joe Perches1dc32912008-07-11 15:17:08 -07001546 if (hw->mac_type == e1000_82573 &&
1547 e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001548 e1000_release_hw_control(adapter);
1549
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 return 0;
1551}
1552
1553/**
1554 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1555 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001556 * @start: address of beginning of memory
1557 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 **/
Joe Perches64798842008-07-11 15:17:02 -07001559static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1560 unsigned long len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Joe Perches1dc32912008-07-11 15:17:08 -07001562 struct e1000_hw *hw = &adapter->hw;
Joe Perchese982f172008-07-11 15:17:18 -07001563 unsigned long begin = (unsigned long)start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 unsigned long end = begin + len;
1565
Malli Chilakala26483452005-04-28 19:44:46 -07001566 /* First rev 82545 and 82546 need to not allow any memory
1567 * write location to cross 64k boundary due to errata 23 */
Joe Perches1dc32912008-07-11 15:17:08 -07001568 if (hw->mac_type == e1000_82545 ||
1569 hw->mac_type == e1000_82546) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001570 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 }
1572
Joe Perchesc3033b02008-03-21 11:06:25 -07001573 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574}
1575
1576/**
1577 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1578 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001579 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 *
1581 * Return 0 on success, negative on failure
1582 **/
1583
Joe Perches64798842008-07-11 15:17:02 -07001584static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1585 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 struct pci_dev *pdev = adapter->pdev;
1588 int size;
1589
1590 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001591 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001592 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001593 DPRINTK(PROBE, ERR,
1594 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 return -ENOMEM;
1596 }
1597 memset(txdr->buffer_info, 0, size);
1598
1599 /* round up to nearest 4K */
1600
1601 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001602 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
1604 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001605 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001608 DPRINTK(PROBE, ERR,
1609 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 return -ENOMEM;
1611 }
1612
Malli Chilakala26483452005-04-28 19:44:46 -07001613 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1615 void *olddesc = txdr->desc;
1616 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001617 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1618 "at %p\n", txdr->size, txdr->desc);
1619 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001621 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001622 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1624 goto setup_tx_desc_die;
1625 }
1626
1627 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1628 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001629 pci_free_consistent(pdev, txdr->size, txdr->desc,
1630 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1632 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001633 "Unable to allocate aligned memory "
1634 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 vfree(txdr->buffer_info);
1636 return -ENOMEM;
1637 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001638 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1640 }
1641 }
1642 memset(txdr->desc, 0, txdr->size);
1643
1644 txdr->next_to_use = 0;
1645 txdr->next_to_clean = 0;
1646
1647 return 0;
1648}
1649
1650/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001651 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1652 * (Descriptors) for all queues
1653 * @adapter: board private structure
1654 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001655 * Return 0 on success, negative on failure
1656 **/
1657
Joe Perches64798842008-07-11 15:17:02 -07001658int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001659{
1660 int i, err = 0;
1661
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001662 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001663 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1664 if (err) {
1665 DPRINTK(PROBE, ERR,
1666 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001667 for (i-- ; i >= 0; i--)
1668 e1000_free_tx_resources(adapter,
1669 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001670 break;
1671 }
1672 }
1673
1674 return err;
1675}
1676
1677/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1679 * @adapter: board private structure
1680 *
1681 * Configure the Tx unit of the MAC after a reset.
1682 **/
1683
Joe Perches64798842008-07-11 15:17:02 -07001684static void e1000_configure_tx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685{
Joe Perches406874a2008-04-03 10:06:32 -07001686 u64 tdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001687 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001688 u32 tdlen, tctl, tipg, tarc;
1689 u32 ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
1691 /* Setup the HW Tx Head and Tail descriptor pointers */
1692
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001693 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001694 case 1:
1695 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001696 tdba = adapter->tx_ring[0].dma;
1697 tdlen = adapter->tx_ring[0].count *
1698 sizeof(struct e1000_tx_desc);
Joe Perches1dc32912008-07-11 15:17:08 -07001699 ew32(TDLEN, tdlen);
1700 ew32(TDBAH, (tdba >> 32));
1701 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1702 ew32(TDT, 0);
1703 ew32(TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001704 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1705 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001706 break;
1707 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 /* Set the default values for the Tx Inter Packet Gap timer */
Joe Perches1dc32912008-07-11 15:17:08 -07001710 if (hw->mac_type <= e1000_82547_rev_2 &&
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001711 (hw->media_type == e1000_media_type_fiber ||
1712 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001713 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1714 else
1715 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1716
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001717 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 case e1000_82542_rev2_0:
1719 case e1000_82542_rev2_1:
1720 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001721 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1722 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001724 case e1000_80003es2lan:
1725 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1726 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1727 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001729 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1730 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1731 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001733 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1734 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Joe Perches1dc32912008-07-11 15:17:08 -07001735 ew32(TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 /* Set the Tx Interrupt Delay register */
1738
Joe Perches1dc32912008-07-11 15:17:08 -07001739 ew32(TIDV, adapter->tx_int_delay);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001740 if (hw->mac_type >= e1000_82540)
Joe Perches1dc32912008-07-11 15:17:08 -07001741 ew32(TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
1743 /* Program the Transmit Control Register */
1744
Joe Perches1dc32912008-07-11 15:17:08 -07001745 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001747 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1749
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001750 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
Joe Perches1dc32912008-07-11 15:17:08 -07001751 tarc = er32(TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001752 /* set the speed mode bit, we'll clear it if we're not at
1753 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001754 tarc |= (1 << 21);
Joe Perches1dc32912008-07-11 15:17:08 -07001755 ew32(TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001756 } else if (hw->mac_type == e1000_80003es2lan) {
Joe Perches1dc32912008-07-11 15:17:08 -07001757 tarc = er32(TARC0);
Jeff Kirsher87041632006-03-02 18:21:24 -08001758 tarc |= 1;
Joe Perches1dc32912008-07-11 15:17:08 -07001759 ew32(TARC0, tarc);
1760 tarc = er32(TARC1);
Jeff Kirsher87041632006-03-02 18:21:24 -08001761 tarc |= 1;
Joe Perches1dc32912008-07-11 15:17:08 -07001762 ew32(TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001763 }
1764
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001765 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
1767 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001768 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1769
1770 /* only set IDE if we are delaying interrupts using the timers */
1771 if (adapter->tx_int_delay)
1772 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001774 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1776 else
1777 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1778
1779 /* Cache if we're 82544 running in PCI-X because we'll
1780 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001781 if (hw->mac_type == e1000_82544 &&
1782 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001784
Joe Perches1dc32912008-07-11 15:17:08 -07001785 ew32(TCTL, tctl);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001786
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787}
1788
1789/**
1790 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1791 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001792 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 *
1794 * Returns 0 on success, negative on failure
1795 **/
1796
Joe Perches64798842008-07-11 15:17:02 -07001797static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1798 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799{
Joe Perches1dc32912008-07-11 15:17:08 -07001800 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001802 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
1804 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001805 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001806 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001807 DPRINTK(PROBE, ERR,
1808 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 return -ENOMEM;
1810 }
1811 memset(rxdr->buffer_info, 0, size);
1812
Joe Perches1dc32912008-07-11 15:17:08 -07001813 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001814 desc_len = sizeof(struct e1000_rx_desc);
1815 else
1816 desc_len = sizeof(union e1000_rx_desc_packet_split);
1817
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 /* Round up to nearest 4K */
1819
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001820 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001821 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1824
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001825 if (!rxdr->desc) {
1826 DPRINTK(PROBE, ERR,
1827 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 vfree(rxdr->buffer_info);
1830 return -ENOMEM;
1831 }
1832
Malli Chilakala26483452005-04-28 19:44:46 -07001833 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1835 void *olddesc = rxdr->desc;
1836 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001837 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1838 "at %p\n", rxdr->size, rxdr->desc);
1839 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001841 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001842 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001844 DPRINTK(PROBE, ERR,
1845 "Unable to allocate memory "
1846 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 goto setup_rx_desc_die;
1848 }
1849
1850 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1851 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001852 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1853 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001855 DPRINTK(PROBE, ERR,
1856 "Unable to allocate aligned memory "
1857 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001858 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001860 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1862 }
1863 }
1864 memset(rxdr->desc, 0, rxdr->size);
1865
1866 rxdr->next_to_clean = 0;
1867 rxdr->next_to_use = 0;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00001868 rxdr->rx_skb_top = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
1870 return 0;
1871}
1872
1873/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001874 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1875 * (Descriptors) for all queues
1876 * @adapter: board private structure
1877 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001878 * Return 0 on success, negative on failure
1879 **/
1880
Joe Perches64798842008-07-11 15:17:02 -07001881int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001882{
1883 int i, err = 0;
1884
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001885 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001886 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1887 if (err) {
1888 DPRINTK(PROBE, ERR,
1889 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001890 for (i-- ; i >= 0; i--)
1891 e1000_free_rx_resources(adapter,
1892 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001893 break;
1894 }
1895 }
1896
1897 return err;
1898}
1899
1900/**
Malli Chilakala26483452005-04-28 19:44:46 -07001901 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 * @adapter: Board private structure
1903 **/
Joe Perches64798842008-07-11 15:17:02 -07001904static void e1000_setup_rctl(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905{
Joe Perches1dc32912008-07-11 15:17:08 -07001906 struct e1000_hw *hw = &adapter->hw;
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07001907 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
Joe Perches1dc32912008-07-11 15:17:08 -07001909 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910
1911 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1912
1913 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1914 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
Joe Perches1dc32912008-07-11 15:17:08 -07001915 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
Joe Perches1dc32912008-07-11 15:17:08 -07001917 if (hw->tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 rctl |= E1000_RCTL_SBP;
1919 else
1920 rctl &= ~E1000_RCTL_SBP;
1921
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001922 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1923 rctl &= ~E1000_RCTL_LPE;
1924 else
1925 rctl |= E1000_RCTL_LPE;
1926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001928 rctl &= ~E1000_RCTL_SZ_4096;
1929 rctl |= E1000_RCTL_BSEX;
1930 switch (adapter->rx_buffer_len) {
1931 case E1000_RXBUFFER_256:
1932 rctl |= E1000_RCTL_SZ_256;
1933 rctl &= ~E1000_RCTL_BSEX;
1934 break;
1935 case E1000_RXBUFFER_512:
1936 rctl |= E1000_RCTL_SZ_512;
1937 rctl &= ~E1000_RCTL_BSEX;
1938 break;
1939 case E1000_RXBUFFER_1024:
1940 rctl |= E1000_RCTL_SZ_1024;
1941 rctl &= ~E1000_RCTL_BSEX;
1942 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001943 case E1000_RXBUFFER_2048:
1944 default:
1945 rctl |= E1000_RCTL_SZ_2048;
1946 rctl &= ~E1000_RCTL_BSEX;
1947 break;
1948 case E1000_RXBUFFER_4096:
1949 rctl |= E1000_RCTL_SZ_4096;
1950 break;
1951 case E1000_RXBUFFER_8192:
1952 rctl |= E1000_RCTL_SZ_8192;
1953 break;
1954 case E1000_RXBUFFER_16384:
1955 rctl |= E1000_RCTL_SZ_16384;
1956 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001957 }
1958
Joe Perches1dc32912008-07-11 15:17:08 -07001959 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960}
1961
1962/**
1963 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1964 * @adapter: board private structure
1965 *
1966 * Configure the Rx unit of the MAC after a reset.
1967 **/
1968
Joe Perches64798842008-07-11 15:17:02 -07001969static void e1000_configure_rx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970{
Joe Perches406874a2008-04-03 10:06:32 -07001971 u64 rdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001972 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001973 u32 rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001974
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00001975 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1976 rdlen = adapter->rx_ring[0].count *
1977 sizeof(struct e1000_rx_desc);
1978 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1979 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1980 } else {
1981 rdlen = adapter->rx_ring[0].count *
1982 sizeof(struct e1000_rx_desc);
1983 adapter->clean_rx = e1000_clean_rx_irq;
1984 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1985 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
1987 /* disable receives while setting up the descriptors */
Joe Perches1dc32912008-07-11 15:17:08 -07001988 rctl = er32(RCTL);
1989 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
1991 /* set the Receive Delay Timer Register */
Joe Perches1dc32912008-07-11 15:17:08 -07001992 ew32(RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001994 if (hw->mac_type >= e1000_82540) {
Joe Perches1dc32912008-07-11 15:17:08 -07001995 ew32(RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08001996 if (adapter->itr_setting != 0)
Joe Perches1dc32912008-07-11 15:17:08 -07001997 ew32(ITR, 1000000000 / (adapter->itr * 256));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 }
1999
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002000 if (hw->mac_type >= e1000_82571) {
Joe Perches1dc32912008-07-11 15:17:08 -07002001 ctrl_ext = er32(CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002002 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002003 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002004 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002005 ctrl_ext |= E1000_CTRL_EXT_IAME;
Joe Perches1dc32912008-07-11 15:17:08 -07002006 ew32(IAM, 0xffffffff);
Joe Perches1dc32912008-07-11 15:17:08 -07002007 ew32(CTRL_EXT, ctrl_ext);
2008 E1000_WRITE_FLUSH();
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002009 }
2010
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002011 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2012 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002013 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002014 case 1:
2015 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002016 rdba = adapter->rx_ring[0].dma;
Joe Perches1dc32912008-07-11 15:17:08 -07002017 ew32(RDLEN, rdlen);
2018 ew32(RDBAH, (rdba >> 32));
2019 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
2020 ew32(RDT, 0);
2021 ew32(RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002022 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2023 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002024 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002025 }
2026
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002028 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07002029 rxcsum = er32(RXCSUM);
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07002030 if (adapter->rx_csum)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002031 rxcsum |= E1000_RXCSUM_TUOFL;
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07002032 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002033 /* don't need to clear IPPCSE as it defaults to 0 */
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07002034 rxcsum &= ~E1000_RXCSUM_TUOFL;
Joe Perches1dc32912008-07-11 15:17:08 -07002035 ew32(RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 }
2037
2038 /* Enable Receives */
Joe Perches1dc32912008-07-11 15:17:08 -07002039 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040}
2041
2042/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002043 * e1000_free_tx_resources - Free Tx Resources per Queue
2044 * @adapter: board private structure
2045 * @tx_ring: Tx descriptor ring for a specific queue
2046 *
2047 * Free all transmit software resources
2048 **/
2049
Joe Perches64798842008-07-11 15:17:02 -07002050static void e1000_free_tx_resources(struct e1000_adapter *adapter,
2051 struct e1000_tx_ring *tx_ring)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002052{
2053 struct pci_dev *pdev = adapter->pdev;
2054
2055 e1000_clean_tx_ring(adapter, tx_ring);
2056
2057 vfree(tx_ring->buffer_info);
2058 tx_ring->buffer_info = NULL;
2059
2060 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2061
2062 tx_ring->desc = NULL;
2063}
2064
2065/**
2066 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 * @adapter: board private structure
2068 *
2069 * Free all transmit software resources
2070 **/
2071
Joe Perches64798842008-07-11 15:17:02 -07002072void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002074 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002076 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002077 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078}
2079
Joe Perches64798842008-07-11 15:17:02 -07002080static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2081 struct e1000_buffer *buffer_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082{
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002083 buffer_info->dma = 0;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002084 if (buffer_info->skb) {
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002085 skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
2086 DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002088 buffer_info->skb = NULL;
2089 }
Alexander Duyck37e73df2009-03-25 21:58:45 +00002090 buffer_info->time_stamp = 0;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002091 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092}
2093
2094/**
2095 * e1000_clean_tx_ring - Free Tx Buffers
2096 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002097 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 **/
2099
Joe Perches64798842008-07-11 15:17:02 -07002100static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
2101 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
Joe Perches1dc32912008-07-11 15:17:08 -07002103 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 struct e1000_buffer *buffer_info;
2105 unsigned long size;
2106 unsigned int i;
2107
2108 /* Free all the Tx ring sk_buffs */
2109
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002110 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 buffer_info = &tx_ring->buffer_info[i];
2112 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2113 }
2114
2115 size = sizeof(struct e1000_buffer) * tx_ring->count;
2116 memset(tx_ring->buffer_info, 0, size);
2117
2118 /* Zero out the descriptor ring */
2119
2120 memset(tx_ring->desc, 0, tx_ring->size);
2121
2122 tx_ring->next_to_use = 0;
2123 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002124 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
Joe Perches1dc32912008-07-11 15:17:08 -07002126 writel(0, hw->hw_addr + tx_ring->tdh);
2127 writel(0, hw->hw_addr + tx_ring->tdt);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002128}
2129
2130/**
2131 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2132 * @adapter: board private structure
2133 **/
2134
Joe Perches64798842008-07-11 15:17:02 -07002135static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002136{
2137 int i;
2138
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002139 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002140 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141}
2142
2143/**
2144 * e1000_free_rx_resources - Free Rx Resources
2145 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002146 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 *
2148 * Free all receive software resources
2149 **/
2150
Joe Perches64798842008-07-11 15:17:02 -07002151static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2152 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct pci_dev *pdev = adapter->pdev;
2155
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002156 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
2158 vfree(rx_ring->buffer_info);
2159 rx_ring->buffer_info = NULL;
2160
2161 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2162
2163 rx_ring->desc = NULL;
2164}
2165
2166/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002167 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002169 *
2170 * Free all receive software resources
2171 **/
2172
Joe Perches64798842008-07-11 15:17:02 -07002173void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002174{
2175 int i;
2176
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002177 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002178 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2179}
2180
2181/**
2182 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2183 * @adapter: board private structure
2184 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 **/
2186
Joe Perches64798842008-07-11 15:17:02 -07002187static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2188 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189{
Joe Perches1dc32912008-07-11 15:17:08 -07002190 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 struct e1000_buffer *buffer_info;
2192 struct pci_dev *pdev = adapter->pdev;
2193 unsigned long size;
Brandeburg, Jesse630b25c2008-09-16 13:01:28 -07002194 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002197 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00002199 if (buffer_info->dma &&
2200 adapter->clean_rx == e1000_clean_rx_irq) {
2201 pci_unmap_single(pdev, buffer_info->dma,
2202 buffer_info->length,
2203 PCI_DMA_FROMDEVICE);
2204 } else if (buffer_info->dma &&
2205 adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
2206 pci_unmap_page(pdev, buffer_info->dma,
2207 buffer_info->length,
2208 PCI_DMA_FROMDEVICE);
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00002209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00002211 buffer_info->dma = 0;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00002212 if (buffer_info->page) {
2213 put_page(buffer_info->page);
2214 buffer_info->page = NULL;
2215 }
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00002216 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 dev_kfree_skb(buffer_info->skb);
2218 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002219 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 }
2221
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00002222 /* there also may be some cached data from a chained receive */
2223 if (rx_ring->rx_skb_top) {
2224 dev_kfree_skb(rx_ring->rx_skb_top);
2225 rx_ring->rx_skb_top = NULL;
2226 }
2227
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 size = sizeof(struct e1000_buffer) * rx_ring->count;
2229 memset(rx_ring->buffer_info, 0, size);
2230
2231 /* Zero out the descriptor ring */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 memset(rx_ring->desc, 0, rx_ring->size);
2233
2234 rx_ring->next_to_clean = 0;
2235 rx_ring->next_to_use = 0;
2236
Joe Perches1dc32912008-07-11 15:17:08 -07002237 writel(0, hw->hw_addr + rx_ring->rdh);
2238 writel(0, hw->hw_addr + rx_ring->rdt);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002239}
2240
2241/**
2242 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2243 * @adapter: board private structure
2244 **/
2245
Joe Perches64798842008-07-11 15:17:02 -07002246static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002247{
2248 int i;
2249
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002250 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002251 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252}
2253
2254/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2255 * and memory write and invalidate disabled for certain operations
2256 */
Joe Perches64798842008-07-11 15:17:02 -07002257static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
Joe Perches1dc32912008-07-11 15:17:08 -07002259 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002261 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Joe Perches1dc32912008-07-11 15:17:08 -07002263 e1000_pci_clear_mwi(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
Joe Perches1dc32912008-07-11 15:17:08 -07002265 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 rctl |= E1000_RCTL_RST;
Joe Perches1dc32912008-07-11 15:17:08 -07002267 ew32(RCTL, rctl);
2268 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 mdelay(5);
2270
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002271 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002272 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
Joe Perches64798842008-07-11 15:17:02 -07002275static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276{
Joe Perches1dc32912008-07-11 15:17:08 -07002277 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002279 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Joe Perches1dc32912008-07-11 15:17:08 -07002281 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 rctl &= ~E1000_RCTL_RST;
Joe Perches1dc32912008-07-11 15:17:08 -07002283 ew32(RCTL, rctl);
2284 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 mdelay(5);
2286
Joe Perches1dc32912008-07-11 15:17:08 -07002287 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2288 e1000_pci_set_mwi(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002290 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002291 /* No need to loop, because 82542 supports only 1 queue */
2292 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002293 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002294 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 }
2296}
2297
2298/**
2299 * e1000_set_mac - Change the Ethernet Address of the NIC
2300 * @netdev: network interface device structure
2301 * @p: pointer to an address structure
2302 *
2303 * Returns 0 on success, negative on failure
2304 **/
2305
Joe Perches64798842008-07-11 15:17:02 -07002306static int e1000_set_mac(struct net_device *netdev, void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002308 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07002309 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 struct sockaddr *addr = p;
2311
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002312 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 return -EADDRNOTAVAIL;
2314
2315 /* 82542 2.0 needs to be in reset to write receive address registers */
2316
Joe Perches1dc32912008-07-11 15:17:08 -07002317 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 e1000_enter_82542_rst(adapter);
2319
2320 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Joe Perches1dc32912008-07-11 15:17:08 -07002321 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Joe Perches1dc32912008-07-11 15:17:08 -07002323 e1000_rar_set(hw, hw->mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002325 /* With 82571 controllers, LAA may be overwritten (with the default)
2326 * due to controller reset from the other port. */
Joe Perches1dc32912008-07-11 15:17:08 -07002327 if (hw->mac_type == e1000_82571) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002328 /* activate the work around */
Joe Perches1dc32912008-07-11 15:17:08 -07002329 hw->laa_is_present = 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002330
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002331 /* Hold a copy of the LAA in RAR[14] This is done so that
2332 * between the time RAR[0] gets clobbered and the time it
2333 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002334 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002335 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002336 * RAR[14] */
Joe Perches1dc32912008-07-11 15:17:08 -07002337 e1000_rar_set(hw, hw->mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002338 E1000_RAR_ENTRIES - 1);
2339 }
2340
Joe Perches1dc32912008-07-11 15:17:08 -07002341 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 e1000_leave_82542_rst(adapter);
2343
2344 return 0;
2345}
2346
2347/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002348 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 * @netdev: network interface device structure
2350 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002351 * The set_rx_mode entry point is called whenever the unicast or multicast
2352 * address lists or the network interface flags are updated. This routine is
2353 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 * promiscuous mode, and all-multi behavior.
2355 **/
2356
Joe Perches64798842008-07-11 15:17:02 -07002357static void e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002359 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 struct e1000_hw *hw = &adapter->hw;
Jiri Pirkoccffad22009-05-22 23:22:17 +00002361 struct netdev_hw_addr *ha;
2362 bool use_uc = false;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002363 struct dev_addr_list *mc_ptr;
Joe Perches406874a2008-04-03 10:06:32 -07002364 u32 rctl;
2365 u32 hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002366 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002367 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2368 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2369 E1000_NUM_MTA_REGISTERS;
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002370 u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
2371
2372 if (!mcarray) {
2373 DPRINTK(PROBE, ERR, "memory allocation failed\n");
2374 return;
2375 }
Auke Kokcd94dd02006-06-27 09:08:22 -07002376
Joe Perches1dc32912008-07-11 15:17:08 -07002377 if (hw->mac_type == e1000_ich8lan)
Auke Kokcd94dd02006-06-27 09:08:22 -07002378 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002380 /* reserve RAR[14] for LAA over-write work-around */
Joe Perches1dc32912008-07-11 15:17:08 -07002381 if (hw->mac_type == e1000_82571)
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002382 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383
Malli Chilakala26483452005-04-28 19:44:46 -07002384 /* Check for Promiscuous and All Multicast modes */
2385
Joe Perches1dc32912008-07-11 15:17:08 -07002386 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002388 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002390 rctl &= ~E1000_RCTL_VFE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002392 if (netdev->flags & IFF_ALLMULTI) {
2393 rctl |= E1000_RCTL_MPE;
2394 } else {
2395 rctl &= ~E1000_RCTL_MPE;
2396 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002397 if (adapter->hw.mac_type != e1000_ich8lan)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002398 rctl |= E1000_RCTL_VFE;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002399 }
2400
Jiri Pirko31278e72009-06-17 01:12:19 +00002401 if (netdev->uc.count > rar_entries - 1) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002402 rctl |= E1000_RCTL_UPE;
2403 } else if (!(netdev->flags & IFF_PROMISC)) {
2404 rctl &= ~E1000_RCTL_UPE;
Jiri Pirkoccffad22009-05-22 23:22:17 +00002405 use_uc = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 }
2407
Joe Perches1dc32912008-07-11 15:17:08 -07002408 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
2410 /* 82542 2.0 needs to be in reset to write receive address registers */
2411
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002412 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 e1000_enter_82542_rst(adapter);
2414
Patrick McHardydb0ce502007-11-13 20:54:59 -08002415 /* load the first 14 addresses into the exact filters 1-14. Unicast
2416 * addresses take precedence to avoid disabling unicast filtering
2417 * when possible.
2418 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 * RAR 0 is used for the station MAC adddress
2420 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002421 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 */
Jiri Pirkoccffad22009-05-22 23:22:17 +00002423 i = 1;
2424 if (use_uc)
Jiri Pirko31278e72009-06-17 01:12:19 +00002425 list_for_each_entry(ha, &netdev->uc.list, list) {
Jiri Pirkoccffad22009-05-22 23:22:17 +00002426 if (i == rar_entries)
2427 break;
2428 e1000_rar_set(hw, ha->addr, i++);
2429 }
2430
2431 WARN_ON(i == rar_entries);
2432
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 mc_ptr = netdev->mc_list;
2434
Jiri Pirkoccffad22009-05-22 23:22:17 +00002435 for (; i < rar_entries; i++) {
2436 if (mc_ptr) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002437 e1000_rar_set(hw, mc_ptr->da_addr, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 mc_ptr = mc_ptr->next;
2439 } else {
2440 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Joe Perches1dc32912008-07-11 15:17:08 -07002441 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Joe Perches1dc32912008-07-11 15:17:08 -07002443 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 }
2445 }
2446
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 /* load any remaining addresses into the hash table */
2448
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002449 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002450 u32 hash_reg, hash_bit, mta;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002451 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002452 hash_reg = (hash_value >> 5) & 0x7F;
2453 hash_bit = hash_value & 0x1F;
2454 mta = (1 << hash_bit);
2455 mcarray[hash_reg] |= mta;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 }
2457
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002458 /* write the hash table completely, write from bottom to avoid
2459 * both stupid write combining chipsets, and flushing each write */
2460 for (i = mta_reg_count - 1; i >= 0 ; i--) {
2461 /*
2462 * If we are on an 82544 has an errata where writing odd
2463 * offsets overwrites the previous even offset, but writing
2464 * backwards over the range solves the issue by always
2465 * writing the odd offset first
2466 */
2467 E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
2468 }
2469 E1000_WRITE_FLUSH();
2470
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002471 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 e1000_leave_82542_rst(adapter);
Jesse Brandeburg81c52282009-04-04 16:36:53 -07002473
2474 kfree(mcarray);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475}
2476
2477/* Need to wait a few seconds after link up to get diagnostic information from
2478 * the phy */
2479
Joe Perches64798842008-07-11 15:17:02 -07002480static void e1000_update_phy_info(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481{
Joe Perchese982f172008-07-11 15:17:18 -07002482 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Joe Perches1dc32912008-07-11 15:17:08 -07002483 struct e1000_hw *hw = &adapter->hw;
2484 e1000_phy_get_info(hw, &adapter->phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485}
2486
2487/**
2488 * e1000_82547_tx_fifo_stall - Timer Call-back
2489 * @data: pointer to adapter cast into an unsigned long
2490 **/
2491
Joe Perches64798842008-07-11 15:17:02 -07002492static void e1000_82547_tx_fifo_stall(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
Joe Perchese982f172008-07-11 15:17:18 -07002494 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Joe Perches1dc32912008-07-11 15:17:08 -07002495 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002497 u32 tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002499 if (atomic_read(&adapter->tx_fifo_stall)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002500 if ((er32(TDT) == er32(TDH)) &&
2501 (er32(TDFT) == er32(TDFH)) &&
2502 (er32(TDFTS) == er32(TDFHS))) {
2503 tctl = er32(TCTL);
2504 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2505 ew32(TDFT, adapter->tx_head_addr);
2506 ew32(TDFH, adapter->tx_head_addr);
2507 ew32(TDFTS, adapter->tx_head_addr);
2508 ew32(TDFHS, adapter->tx_head_addr);
2509 ew32(TCTL, tctl);
2510 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
2512 adapter->tx_fifo_head = 0;
2513 atomic_set(&adapter->tx_fifo_stall, 0);
2514 netif_wake_queue(netdev);
2515 } else {
2516 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2517 }
2518 }
2519}
2520
2521/**
2522 * e1000_watchdog - Timer Call-back
2523 * @data: pointer to adapter cast into an unsigned long
2524 **/
Joe Perches64798842008-07-11 15:17:02 -07002525static void e1000_watchdog(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526{
Joe Perchese982f172008-07-11 15:17:18 -07002527 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Joe Perches1dc32912008-07-11 15:17:08 -07002528 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002530 struct e1000_tx_ring *txdr = adapter->tx_ring;
Joe Perches406874a2008-04-03 10:06:32 -07002531 u32 link, tctl;
2532 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
Joe Perches1dc32912008-07-11 15:17:08 -07002534 ret_val = e1000_check_for_link(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07002535 if ((ret_val == E1000_ERR_PHY) &&
Joe Perches1dc32912008-07-11 15:17:08 -07002536 (hw->phy_type == e1000_phy_igp_3) &&
2537 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07002538 /* See e1000_kumeran_lock_loss_workaround() */
2539 DPRINTK(LINK, INFO,
2540 "Gigabit has been disabled, downgrading speed\n");
2541 }
Auke Kok90fb5132006-11-01 08:47:30 -08002542
Joe Perches1dc32912008-07-11 15:17:08 -07002543 if (hw->mac_type == e1000_82573) {
2544 e1000_enable_tx_pkt_filtering(hw);
2545 if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002546 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
Joe Perches1dc32912008-07-11 15:17:08 -07002549 if ((hw->media_type == e1000_media_type_internal_serdes) &&
2550 !(er32(TXCW) & E1000_TXCW_ANE))
2551 link = !hw->serdes_link_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 else
Joe Perches1dc32912008-07-11 15:17:08 -07002553 link = er32(STATUS) & E1000_STATUS_LU;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002555 if (link) {
2556 if (!netif_carrier_ok(netdev)) {
Joe Perches406874a2008-04-03 10:06:32 -07002557 u32 ctrl;
Joe Perchesc3033b02008-03-21 11:06:25 -07002558 bool txb2b = true;
Joe Perches1dc32912008-07-11 15:17:08 -07002559 e1000_get_speed_and_duplex(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 &adapter->link_speed,
2561 &adapter->link_duplex);
2562
Joe Perches1dc32912008-07-11 15:17:08 -07002563 ctrl = er32(CTRL);
Jeff Kirsherb30c4d8f2008-11-27 00:22:45 -08002564 printk(KERN_INFO "e1000: %s NIC Link is Up %d Mbps %s, "
2565 "Flow Control: %s\n",
2566 netdev->name,
2567 adapter->link_speed,
2568 adapter->link_duplex == FULL_DUPLEX ?
Auke Kok9669f532007-01-18 09:25:26 -08002569 "Full Duplex" : "Half Duplex",
2570 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2571 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2572 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2573 E1000_CTRL_TFCE) ? "TX" : "None" )));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002575 /* tweak tx_queue_len according to speed/duplex
2576 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002577 netdev->tx_queue_len = adapter->tx_queue_len;
2578 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002579 switch (adapter->link_speed) {
2580 case SPEED_10:
Joe Perchesc3033b02008-03-21 11:06:25 -07002581 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002582 netdev->tx_queue_len = 10;
2583 adapter->tx_timeout_factor = 8;
2584 break;
2585 case SPEED_100:
Joe Perchesc3033b02008-03-21 11:06:25 -07002586 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002587 netdev->tx_queue_len = 100;
2588 /* maybe add some timeout factor ? */
2589 break;
2590 }
2591
Joe Perches1dc32912008-07-11 15:17:08 -07002592 if ((hw->mac_type == e1000_82571 ||
2593 hw->mac_type == e1000_82572) &&
Joe Perchesc3033b02008-03-21 11:06:25 -07002594 !txb2b) {
Joe Perches406874a2008-04-03 10:06:32 -07002595 u32 tarc0;
Joe Perches1dc32912008-07-11 15:17:08 -07002596 tarc0 = er32(TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002597 tarc0 &= ~(1 << 21);
Joe Perches1dc32912008-07-11 15:17:08 -07002598 ew32(TARC0, tarc0);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002599 }
Auke Kok90fb5132006-11-01 08:47:30 -08002600
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002601 /* disable TSO for pcie and 10/100 speeds, to avoid
2602 * some hardware issues */
2603 if (!adapter->tso_force &&
Joe Perches1dc32912008-07-11 15:17:08 -07002604 hw->bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002605 switch (adapter->link_speed) {
2606 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002607 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002608 DPRINTK(PROBE,INFO,
2609 "10/100 speed: disabling TSO\n");
2610 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002611 netdev->features &= ~NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002612 break;
2613 case SPEED_1000:
2614 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002615 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002616 break;
2617 default:
2618 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002619 break;
2620 }
2621 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002622
2623 /* enable transmits in the hardware, need to do this
2624 * after setting TARC0 */
Joe Perches1dc32912008-07-11 15:17:08 -07002625 tctl = er32(TCTL);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002626 tctl |= E1000_TCTL_EN;
Joe Perches1dc32912008-07-11 15:17:08 -07002627 ew32(TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002628
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 netif_carrier_on(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002630 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002632 } else {
2633 /* make sure the receive unit is started */
Joe Perches1dc32912008-07-11 15:17:08 -07002634 if (hw->rx_needs_kicking) {
2635 u32 rctl = er32(RCTL);
2636 ew32(RCTL, rctl | E1000_RCTL_EN);
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 }
2639 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002640 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 adapter->link_speed = 0;
2642 adapter->link_duplex = 0;
Jeff Kirsherb30c4d8f2008-11-27 00:22:45 -08002643 printk(KERN_INFO "e1000: %s NIC Link is Down\n",
2644 netdev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 netif_carrier_off(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002646 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Jeff Kirsher87041632006-03-02 18:21:24 -08002647
2648 /* 80003ES2LAN workaround--
2649 * For packet buffer work-around on link down event;
2650 * disable receives in the ISR and
2651 * reset device here in the watchdog
2652 */
Joe Perches1dc32912008-07-11 15:17:08 -07002653 if (hw->mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002654 /* reset device */
2655 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 }
2657
2658 e1000_smartspeed(adapter);
2659 }
2660
2661 e1000_update_stats(adapter);
2662
Joe Perches1dc32912008-07-11 15:17:08 -07002663 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 adapter->tpt_old = adapter->stats.tpt;
Joe Perches1dc32912008-07-11 15:17:08 -07002665 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 adapter->colc_old = adapter->stats.colc;
2667
2668 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2669 adapter->gorcl_old = adapter->stats.gorcl;
2670 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2671 adapter->gotcl_old = adapter->stats.gotcl;
2672
Joe Perches1dc32912008-07-11 15:17:08 -07002673 e1000_update_adaptive(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002675 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002676 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 /* We've lost link, so the controller stops DMA,
2678 * but we've got queued Tx work that's never going
2679 * to get done, so reset controller to flush Tx.
2680 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002681 adapter->tx_timeout_count++;
2682 schedule_work(&adapter->reset_task);
Jesse Brandeburgc2d5ab42009-05-07 11:07:35 +00002683 /* return immediately since reset is imminent */
2684 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 }
2686 }
2687
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 /* Cause software interrupt to ensure rx ring is cleaned */
Joe Perches1dc32912008-07-11 15:17:08 -07002689 ew32(ICS, E1000_ICS_RXDMT0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690
Malli Chilakala26483452005-04-28 19:44:46 -07002691 /* Force detection of hung controller every watchdog period */
Joe Perchesc3033b02008-03-21 11:06:25 -07002692 adapter->detect_tx_hung = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002694 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002695 * reset from the other port. Set the appropriate LAA in RAR[0] */
Joe Perches1dc32912008-07-11 15:17:08 -07002696 if (hw->mac_type == e1000_82571 && hw->laa_is_present)
2697 e1000_rar_set(hw, hw->mac_addr, 0);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002698
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 /* Reset the timer */
Arjan van de Ven56e13932007-03-06 02:41:48 -08002700 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701}
2702
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002703enum latency_range {
2704 lowest_latency = 0,
2705 low_latency = 1,
2706 bulk_latency = 2,
2707 latency_invalid = 255
2708};
2709
2710/**
2711 * e1000_update_itr - update the dynamic ITR value based on statistics
2712 * Stores a new ITR value based on packets and byte
2713 * counts during the last interrupt. The advantage of per interrupt
2714 * computation is faster updates and more accurate ITR for the current
2715 * traffic pattern. Constants in this function were computed
2716 * based on theoretical maximum wire speed and thresholds were set based
2717 * on testing data as well as attempting to minimize response time
2718 * while increasing bulk throughput.
2719 * this functionality is controlled by the InterruptThrottleRate module
2720 * parameter (see e1000_param.c)
2721 * @adapter: pointer to adapter
2722 * @itr_setting: current adapter->itr
2723 * @packets: the number of packets during this measurement interval
2724 * @bytes: the number of bytes during this measurement interval
2725 **/
2726static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
Joe Perches64798842008-07-11 15:17:02 -07002727 u16 itr_setting, int packets, int bytes)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002728{
2729 unsigned int retval = itr_setting;
2730 struct e1000_hw *hw = &adapter->hw;
2731
2732 if (unlikely(hw->mac_type < e1000_82540))
2733 goto update_itr_done;
2734
2735 if (packets == 0)
2736 goto update_itr_done;
2737
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002738 switch (itr_setting) {
2739 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002740 /* jumbo frames get bulk treatment*/
2741 if (bytes/packets > 8000)
2742 retval = bulk_latency;
2743 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002744 retval = low_latency;
2745 break;
2746 case low_latency: /* 50 usec aka 20000 ints/s */
2747 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002748 /* jumbo frames need bulk latency setting */
2749 if (bytes/packets > 8000)
2750 retval = bulk_latency;
2751 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002752 retval = bulk_latency;
2753 else if ((packets > 35))
2754 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002755 } else if (bytes/packets > 2000)
2756 retval = bulk_latency;
2757 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002758 retval = lowest_latency;
2759 break;
2760 case bulk_latency: /* 250 usec aka 4000 ints/s */
2761 if (bytes > 25000) {
2762 if (packets > 35)
2763 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002764 } else if (bytes < 6000) {
2765 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002766 }
2767 break;
2768 }
2769
2770update_itr_done:
2771 return retval;
2772}
2773
2774static void e1000_set_itr(struct e1000_adapter *adapter)
2775{
2776 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002777 u16 current_itr;
2778 u32 new_itr = adapter->itr;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002779
2780 if (unlikely(hw->mac_type < e1000_82540))
2781 return;
2782
2783 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2784 if (unlikely(adapter->link_speed != SPEED_1000)) {
2785 current_itr = 0;
2786 new_itr = 4000;
2787 goto set_itr_now;
2788 }
2789
2790 adapter->tx_itr = e1000_update_itr(adapter,
2791 adapter->tx_itr,
2792 adapter->total_tx_packets,
2793 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002794 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2795 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2796 adapter->tx_itr = low_latency;
2797
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002798 adapter->rx_itr = e1000_update_itr(adapter,
2799 adapter->rx_itr,
2800 adapter->total_rx_packets,
2801 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002802 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2803 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2804 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002805
2806 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2807
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002808 switch (current_itr) {
2809 /* counts and packets in update_itr are dependent on these numbers */
2810 case lowest_latency:
2811 new_itr = 70000;
2812 break;
2813 case low_latency:
2814 new_itr = 20000; /* aka hwitr = ~200 */
2815 break;
2816 case bulk_latency:
2817 new_itr = 4000;
2818 break;
2819 default:
2820 break;
2821 }
2822
2823set_itr_now:
2824 if (new_itr != adapter->itr) {
2825 /* this attempts to bias the interrupt rate towards Bulk
2826 * by adding intermediate steps when interrupt rate is
2827 * increasing */
2828 new_itr = new_itr > adapter->itr ?
2829 min(adapter->itr + (new_itr >> 2), new_itr) :
2830 new_itr;
2831 adapter->itr = new_itr;
Joe Perches1dc32912008-07-11 15:17:08 -07002832 ew32(ITR, 1000000000 / (new_itr * 256));
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002833 }
2834
2835 return;
2836}
2837
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838#define E1000_TX_FLAGS_CSUM 0x00000001
2839#define E1000_TX_FLAGS_VLAN 0x00000002
2840#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002841#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2843#define E1000_TX_FLAGS_VLAN_SHIFT 16
2844
Joe Perches64798842008-07-11 15:17:02 -07002845static int e1000_tso(struct e1000_adapter *adapter,
2846 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002849 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002851 u32 cmd_length = 0;
2852 u16 ipcse = 0, tucse, mss;
2853 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 int err;
2855
Herbert Xu89114af2006-07-08 13:34:32 -07002856 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 if (skb_header_cloned(skb)) {
2858 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2859 if (err)
2860 return err;
2861 }
2862
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002863 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002864 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002865 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002866 struct iphdr *iph = ip_hdr(skb);
2867 iph->tot_len = 0;
2868 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002869 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2870 iph->daddr, 0,
2871 IPPROTO_TCP,
2872 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002873 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002874 ipcse = skb_transport_offset(skb) - 1;
Auke Koke15fdd02006-08-16 11:28:45 -07002875 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002876 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002877 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002878 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2879 &ipv6_hdr(skb)->daddr,
2880 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002881 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002882 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002883 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002884 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002885 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002886 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 tucse = 0;
2888
2889 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002890 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002892 i = tx_ring->next_to_use;
2893 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002894 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895
2896 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2897 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2898 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2899 context_desc->upper_setup.tcp_fields.tucss = tucss;
2900 context_desc->upper_setup.tcp_fields.tucso = tucso;
2901 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2902 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2903 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2904 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2905
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002906 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002907 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002908
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002909 if (++i == tx_ring->count) i = 0;
2910 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911
Joe Perchesc3033b02008-03-21 11:06:25 -07002912 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 }
Joe Perchesc3033b02008-03-21 11:06:25 -07002914 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915}
2916
Joe Perches64798842008-07-11 15:17:02 -07002917static bool e1000_tx_csum(struct e1000_adapter *adapter,
2918 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919{
2920 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002921 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002923 u8 css;
Dave Graham3ed30672008-10-09 14:29:26 -07002924 u32 cmd_len = E1000_TXD_CMD_DEXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925
Dave Graham3ed30672008-10-09 14:29:26 -07002926 if (skb->ip_summed != CHECKSUM_PARTIAL)
2927 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928
Dave Graham3ed30672008-10-09 14:29:26 -07002929 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08002930 case cpu_to_be16(ETH_P_IP):
Dave Graham3ed30672008-10-09 14:29:26 -07002931 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2932 cmd_len |= E1000_TXD_CMD_TCP;
2933 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08002934 case cpu_to_be16(ETH_P_IPV6):
Dave Graham3ed30672008-10-09 14:29:26 -07002935 /* XXX not handling all IPV6 headers */
2936 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2937 cmd_len |= E1000_TXD_CMD_TCP;
2938 break;
2939 default:
2940 if (unlikely(net_ratelimit()))
2941 DPRINTK(DRV, WARNING,
2942 "checksum_partial proto=%x!\n", skb->protocol);
2943 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 }
2945
Dave Graham3ed30672008-10-09 14:29:26 -07002946 css = skb_transport_offset(skb);
2947
2948 i = tx_ring->next_to_use;
2949 buffer_info = &tx_ring->buffer_info[i];
2950 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2951
2952 context_desc->lower_setup.ip_config = 0;
2953 context_desc->upper_setup.tcp_fields.tucss = css;
2954 context_desc->upper_setup.tcp_fields.tucso =
2955 css + skb->csum_offset;
2956 context_desc->upper_setup.tcp_fields.tucse = 0;
2957 context_desc->tcp_seg_setup.data = 0;
2958 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
2959
2960 buffer_info->time_stamp = jiffies;
2961 buffer_info->next_to_watch = i;
2962
2963 if (unlikely(++i == tx_ring->count)) i = 0;
2964 tx_ring->next_to_use = i;
2965
2966 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967}
2968
2969#define E1000_MAX_TXD_PWR 12
2970#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2971
Joe Perches64798842008-07-11 15:17:02 -07002972static int e1000_tx_map(struct e1000_adapter *adapter,
2973 struct e1000_tx_ring *tx_ring,
2974 struct sk_buff *skb, unsigned int first,
2975 unsigned int max_per_txd, unsigned int nr_frags,
2976 unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977{
Joe Perches1dc32912008-07-11 15:17:08 -07002978 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck37e73df2009-03-25 21:58:45 +00002979 struct e1000_buffer *buffer_info;
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002980 unsigned int len = skb_headlen(skb);
2981 unsigned int offset, size, count = 0, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 unsigned int f;
Alexander Duyck37e73df2009-03-25 21:58:45 +00002983 dma_addr_t *map;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984
2985 i = tx_ring->next_to_use;
2986
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002987 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
2988 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
Alexander Duyck37e73df2009-03-25 21:58:45 +00002989 return 0;
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002990 }
2991
Alexander Duyck37e73df2009-03-25 21:58:45 +00002992 map = skb_shinfo(skb)->dma_maps;
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08002993 offset = 0;
2994
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002995 while (len) {
Alexander Duyck37e73df2009-03-25 21:58:45 +00002996 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05002998 /* Workaround for Controller erratum --
2999 * descriptor for non-tso packet in a linear SKB that follows a
3000 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003001 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05003002 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07003003 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05003004 tx_ring->last_tx_tso = 0;
3005 size -= 4;
3006 }
3007
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 /* Workaround for premature desc write-backs
3009 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003010 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07003012 /* work-around for errata 10 and it applies
3013 * to all controllers in PCI-X mode
3014 * The fix is to make sure that the first descriptor of a
3015 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3016 */
Joe Perches1dc32912008-07-11 15:17:08 -07003017 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003018 (size > 2015) && count == 0))
3019 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003020
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 /* Workaround for potential 82544 hang in PCI-X. Avoid
3022 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003023 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3025 size > 4))
3026 size -= 4;
3027
3028 buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00003029 buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003031 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032
3033 len -= size;
3034 offset += size;
3035 count++;
Alexander Duyck37e73df2009-03-25 21:58:45 +00003036 if (len) {
3037 i++;
3038 if (unlikely(i == tx_ring->count))
3039 i = 0;
3040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 }
3042
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003043 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 struct skb_frag_struct *frag;
3045
3046 frag = &skb_shinfo(skb)->frags[f];
3047 len = frag->size;
Jesse Brandeburgd20b6062009-03-02 16:03:21 -08003048 offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003050 while (len) {
Alexander Duyck37e73df2009-03-25 21:58:45 +00003051 i++;
3052 if (unlikely(i == tx_ring->count))
3053 i = 0;
3054
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 buffer_info = &tx_ring->buffer_info[i];
3056 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 /* Workaround for premature desc write-backs
3058 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003059 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 /* Workaround for potential 82544 hang in PCI-X.
3062 * Avoid terminating buffers within evenly-aligned
3063 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003064 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3066 size > 4))
3067 size -= 4;
3068
3069 buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00003070 buffer_info->dma = map[f] + offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003072 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073
3074 len -= size;
3075 offset += size;
3076 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 }
3078 }
3079
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 tx_ring->buffer_info[i].skb = skb;
3081 tx_ring->buffer_info[first].next_to_watch = i;
3082
3083 return count;
3084}
3085
Joe Perches64798842008-07-11 15:17:02 -07003086static void e1000_tx_queue(struct e1000_adapter *adapter,
3087 struct e1000_tx_ring *tx_ring, int tx_flags,
3088 int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089{
Joe Perches1dc32912008-07-11 15:17:08 -07003090 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 struct e1000_tx_desc *tx_desc = NULL;
3092 struct e1000_buffer *buffer_info;
Joe Perches406874a2008-04-03 10:06:32 -07003093 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 unsigned int i;
3095
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003096 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3098 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003099 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3100
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003101 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003102 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 }
3104
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003105 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3107 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3108 }
3109
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003110 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 txd_lower |= E1000_TXD_CMD_VLE;
3112 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3113 }
3114
3115 i = tx_ring->next_to_use;
3116
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003117 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 buffer_info = &tx_ring->buffer_info[i];
3119 tx_desc = E1000_TX_DESC(*tx_ring, i);
3120 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3121 tx_desc->lower.data =
3122 cpu_to_le32(txd_lower | buffer_info->length);
3123 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003124 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 }
3126
3127 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3128
3129 /* Force memory writes to complete before letting h/w
3130 * know there are new descriptors to fetch. (Only
3131 * applicable for weak-ordered memory model archs,
3132 * such as IA-64). */
3133 wmb();
3134
3135 tx_ring->next_to_use = i;
Joe Perches1dc32912008-07-11 15:17:08 -07003136 writel(i, hw->hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003137 /* we need this if more than one processor can write to our tail
3138 * at a time, it syncronizes IO on IA64/Altix systems */
3139 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140}
3141
3142/**
3143 * 82547 workaround to avoid controller hang in half-duplex environment.
3144 * The workaround is to avoid queuing a large packet that would span
3145 * the internal Tx FIFO ring boundary by notifying the stack to resend
3146 * the packet at a later time. This gives the Tx FIFO an opportunity to
3147 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3148 * to the beginning of the Tx FIFO.
3149 **/
3150
3151#define E1000_FIFO_HDR 0x10
3152#define E1000_82547_PAD_LEN 0x3E0
3153
Joe Perches64798842008-07-11 15:17:02 -07003154static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3155 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156{
Joe Perches406874a2008-04-03 10:06:32 -07003157 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3158 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003160 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003162 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 goto no_fifo_stall_required;
3164
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003165 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 return 1;
3167
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003168 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 atomic_set(&adapter->tx_fifo_stall, 1);
3170 return 1;
3171 }
3172
3173no_fifo_stall_required:
3174 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003175 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3177 return 0;
3178}
3179
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003180#define MINIMUM_DHCP_PACKET_SIZE 282
Joe Perches64798842008-07-11 15:17:02 -07003181static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3182 struct sk_buff *skb)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003183{
3184 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003185 u16 length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003186 if (vlan_tx_tag_present(skb)) {
Joe Perches1dc32912008-07-11 15:17:08 -07003187 if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) &&
3188 ( hw->mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003189 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3190 return 0;
3191 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003192 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Joe Perchese982f172008-07-11 15:17:18 -07003193 struct ethhdr *eth = (struct ethhdr *)skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003194 if ((htons(ETH_P_IP) == eth->h_proto)) {
3195 const struct iphdr *ip =
Joe Perches406874a2008-04-03 10:06:32 -07003196 (struct iphdr *)((u8 *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003197 if (IPPROTO_UDP == ip->protocol) {
3198 struct udphdr *udp =
Joe Perches406874a2008-04-03 10:06:32 -07003199 (struct udphdr *)((u8 *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003200 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003201 if (ntohs(udp->dest) == 67) {
Joe Perches406874a2008-04-03 10:06:32 -07003202 offset = (u8 *)udp + 8 - skb->data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003203 length = skb->len - offset;
3204
3205 return e1000_mng_write_dhcp_info(hw,
Joe Perches406874a2008-04-03 10:06:32 -07003206 (u8 *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003207 length);
3208 }
3209 }
3210 }
3211 }
3212 return 0;
3213}
3214
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003215static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3216{
3217 struct e1000_adapter *adapter = netdev_priv(netdev);
3218 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3219
3220 netif_stop_queue(netdev);
3221 /* Herbert's original patch had:
3222 * smp_mb__after_netif_stop_queue();
3223 * but since that doesn't exist yet, just open code it. */
3224 smp_mb();
3225
3226 /* We need to check again in a case another CPU has just
3227 * made room available. */
3228 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3229 return -EBUSY;
3230
3231 /* A reprieve! */
3232 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003233 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003234 return 0;
3235}
3236
3237static int e1000_maybe_stop_tx(struct net_device *netdev,
3238 struct e1000_tx_ring *tx_ring, int size)
3239{
3240 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3241 return 0;
3242 return __e1000_maybe_stop_tx(netdev, size);
3243}
3244
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Joe Perches64798842008-07-11 15:17:02 -07003246static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003248 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07003249 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003250 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3252 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3253 unsigned int tx_flags = 0;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003254 unsigned int len = skb->len - skb->data_len;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003255 unsigned int nr_frags;
3256 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003258 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 unsigned int f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003261 /* This goes back to the question of how to logically map a tx queue
3262 * to a flow. Right now, performance is impacted slightly negatively
3263 * if using multiple tx queues. If the stack breaks away from a
3264 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003265 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003266
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003267 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 dev_kfree_skb_any(skb);
3269 return NETDEV_TX_OK;
3270 }
3271
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003272 /* 82571 and newer doesn't need the workaround that limited descriptor
3273 * length to 4kB */
Joe Perches1dc32912008-07-11 15:17:08 -07003274 if (hw->mac_type >= e1000_82571)
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003275 max_per_txd = 8192;
3276
Herbert Xu79671682006-06-22 02:40:14 -07003277 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003278 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 * make sure there is enough room in the FIFO before
3280 * initiating the DMA for each buffer. The calc is:
3281 * 4 = ceil(buffer len/mss). To make sure we don't
3282 * overrun the FIFO, adjust the max buffer len if mss
3283 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003284 if (mss) {
Joe Perches406874a2008-04-03 10:06:32 -07003285 u8 hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 max_per_txd = min(mss << 2, max_per_txd);
3287 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003288
Auke Kok90fb5132006-11-01 08:47:30 -08003289 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3290 * points to just header, pull a few bytes of payload from
3291 * frags into skb->data */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003292 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003293 if (skb->data_len && hdr_len == len) {
Joe Perches1dc32912008-07-11 15:17:08 -07003294 switch (hw->mac_type) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003295 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003296 case e1000_82544:
3297 /* Make sure we have room to chop off 4 bytes,
3298 * and that the end alignment will work out to
3299 * this hardware's requirements
3300 * NOTE: this is a TSO only workaround
3301 * if end byte alignment not correct move us
3302 * into the next dword */
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003303 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003304 break;
3305 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003306 case e1000_82571:
3307 case e1000_82572:
3308 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003309 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003310 pull_size = min((unsigned int)4, skb->data_len);
3311 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003312 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003313 "__pskb_pull_tail failed.\n");
3314 dev_kfree_skb_any(skb);
Jeff Garzik749dfc72006-03-11 13:35:31 -05003315 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003316 }
3317 len = skb->len - skb->data_len;
3318 break;
3319 default:
3320 /* do nothing */
3321 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003322 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 }
3325
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003326 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003327 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003329 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003330
Jeff Kirsherfd803242005-12-13 00:06:22 -05003331 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003332 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003333 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003334
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 count += TXD_USE_COUNT(len, max_txd_pwr);
3336
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003337 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 count++;
3339
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003340 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003341 * in PCI-X mode, so add one more descriptor to the count
3342 */
Joe Perches1dc32912008-07-11 15:17:08 -07003343 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003344 (len > 2015)))
3345 count++;
3346
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003348 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3350 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003351 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 count += nr_frags;
3353
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003354
Joe Perches1dc32912008-07-11 15:17:08 -07003355 if (hw->tx_pkt_filtering &&
3356 (hw->mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003357 e1000_transfer_dhcp_info(adapter, skb);
3358
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 /* need: count + 2 desc gap to keep tail from touching
3360 * head, otherwise try next time */
Alexander Duyck80179432009-01-21 14:42:47 -08003361 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363
Joe Perches1dc32912008-07-11 15:17:08 -07003364 if (unlikely(hw->mac_type == e1000_82547)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003365 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003367 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 return NETDEV_TX_BUSY;
3369 }
3370 }
3371
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003372 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 tx_flags |= E1000_TX_FLAGS_VLAN;
3374 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3375 }
3376
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003377 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003378
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003379 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 if (tso < 0) {
3381 dev_kfree_skb_any(skb);
3382 return NETDEV_TX_OK;
3383 }
3384
Jeff Kirsherfd803242005-12-13 00:06:22 -05003385 if (likely(tso)) {
3386 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003388 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 tx_flags |= E1000_TX_FLAGS_CSUM;
3390
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003391 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003392 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003393 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003394 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003395 tx_flags |= E1000_TX_FLAGS_IPV4;
3396
Alexander Duyck37e73df2009-03-25 21:58:45 +00003397 count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
3398 nr_frags, mss);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399
Alexander Duyck37e73df2009-03-25 21:58:45 +00003400 if (count) {
3401 e1000_tx_queue(adapter, tx_ring, tx_flags, count);
Alexander Duyck37e73df2009-03-25 21:58:45 +00003402 /* Make sure there is space in the ring for the next send. */
3403 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404
Alexander Duyck37e73df2009-03-25 21:58:45 +00003405 } else {
3406 dev_kfree_skb_any(skb);
3407 tx_ring->buffer_info[first].time_stamp = 0;
3408 tx_ring->next_to_use = first;
3409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 return NETDEV_TX_OK;
3412}
3413
3414/**
3415 * e1000_tx_timeout - Respond to a Tx Hang
3416 * @netdev: network interface device structure
3417 **/
3418
Joe Perches64798842008-07-11 15:17:02 -07003419static void e1000_tx_timeout(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003421 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422
3423 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003424 adapter->tx_timeout_count++;
3425 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426}
3427
Joe Perches64798842008-07-11 15:17:02 -07003428static void e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429{
David Howells65f27f32006-11-22 14:55:48 +00003430 struct e1000_adapter *adapter =
3431 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
Auke Kok2db10a02006-06-27 09:06:28 -07003433 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434}
3435
3436/**
3437 * e1000_get_stats - Get System Network Statistics
3438 * @netdev: network interface device structure
3439 *
3440 * Returns the address of the device statistics structure.
3441 * The statistics are actually updated from the timer callback.
3442 **/
3443
Joe Perches64798842008-07-11 15:17:02 -07003444static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003446 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003448 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 return &adapter->net_stats;
3450}
3451
3452/**
3453 * e1000_change_mtu - Change the Maximum Transfer Unit
3454 * @netdev: network interface device structure
3455 * @new_mtu: new value for maximum frame size
3456 *
3457 * Returns 0 on success, negative on failure
3458 **/
3459
Joe Perches64798842008-07-11 15:17:02 -07003460static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003462 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07003463 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Joe Perches406874a2008-04-03 10:06:32 -07003465 u16 eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003467 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3468 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3469 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003470 return -EINVAL;
3471 }
3472
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003473 /* Adapter-specific max frame size limits. */
Joe Perches1dc32912008-07-11 15:17:08 -07003474 switch (hw->mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003475 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003476 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003477 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3478 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003479 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003480 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003481 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003482 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003483 /* Jumbo Frames not supported if:
3484 * - this is not an 82573L device
3485 * - ASPM is enabled in any way (0x1A bits 3:2) */
Joe Perches1dc32912008-07-11 15:17:08 -07003486 e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1,
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003487 &eeprom_data);
Joe Perches1dc32912008-07-11 15:17:08 -07003488 if ((hw->device_id != E1000_DEV_ID_82573L) ||
Bruce Allan249d71d2006-09-27 12:53:45 -07003489 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003490 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3491 DPRINTK(PROBE, ERR,
3492 "Jumbo Frames not supported.\n");
3493 return -EINVAL;
3494 }
3495 break;
3496 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003497 /* ERT will be enabled later to enable wire speed receives */
3498
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003499 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003500 case e1000_82571:
3501 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003502 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003503#define MAX_STD_JUMBO_FRAME_SIZE 9234
3504 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3505 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3506 return -EINVAL;
3507 }
3508 break;
3509 default:
3510 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3511 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003512 }
3513
David S. Miller87f50322006-07-31 22:39:40 -07003514 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003515 * means we reserve 2 more, this pushes us to allocate from the next
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003516 * larger slab size.
3517 * i.e. RXBUFFER_2048 --> size-4096 slab
3518 * however with the new *_jumbo_rx* routines, jumbo receives will use
3519 * fragmented skbs */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003520
Auke Kok9e2feac2006-04-14 19:05:18 -07003521 if (max_frame <= E1000_RXBUFFER_256)
3522 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3523 else if (max_frame <= E1000_RXBUFFER_512)
3524 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3525 else if (max_frame <= E1000_RXBUFFER_1024)
3526 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3527 else if (max_frame <= E1000_RXBUFFER_2048)
3528 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003529 else
3530#if (PAGE_SIZE >= E1000_RXBUFFER_16384)
Auke Kok9e2feac2006-04-14 19:05:18 -07003531 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00003532#elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3533 adapter->rx_buffer_len = PAGE_SIZE;
3534#endif
Auke Kok9e2feac2006-04-14 19:05:18 -07003535
3536 /* adjust allocation if LPE protects us, and we aren't using SBP */
Joe Perches1dc32912008-07-11 15:17:08 -07003537 if (!hw->tbi_compatibility_on &&
Auke Kok9e2feac2006-04-14 19:05:18 -07003538 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3539 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3540 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003541
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003542 netdev->mtu = new_mtu;
Joe Perches1dc32912008-07-11 15:17:08 -07003543 hw->max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003544
Auke Kok2db10a02006-06-27 09:06:28 -07003545 if (netif_running(netdev))
3546 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 return 0;
3549}
3550
3551/**
3552 * e1000_update_stats - Update the board statistics counters
3553 * @adapter: board private structure
3554 **/
3555
Joe Perches64798842008-07-11 15:17:02 -07003556void e1000_update_stats(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557{
3558 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003559 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07003561 u16 phy_tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562
3563#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3564
Linas Vepstas282f33c2006-06-08 22:19:44 -07003565 /*
3566 * Prevent stats update while adapter is being reset, or if the pci
3567 * connection is down.
3568 */
Auke Kok90267292006-06-08 09:30:24 -07003569 if (adapter->link_speed == 0)
3570 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003571 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003572 return;
Auke Kok90267292006-06-08 09:30:24 -07003573
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 spin_lock_irqsave(&adapter->stats_lock, flags);
3575
Masatake YAMATO828d0552007-10-20 03:06:37 +02003576 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 * called from the interrupt context, so they must only
3578 * be written while holding adapter->stats_lock
3579 */
3580
Joe Perches1dc32912008-07-11 15:17:08 -07003581 adapter->stats.crcerrs += er32(CRCERRS);
3582 adapter->stats.gprc += er32(GPRC);
3583 adapter->stats.gorcl += er32(GORCL);
3584 adapter->stats.gorch += er32(GORCH);
3585 adapter->stats.bprc += er32(BPRC);
3586 adapter->stats.mprc += er32(MPRC);
3587 adapter->stats.roc += er32(ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003588
Joe Perches1dc32912008-07-11 15:17:08 -07003589 if (hw->mac_type != e1000_ich8lan) {
3590 adapter->stats.prc64 += er32(PRC64);
3591 adapter->stats.prc127 += er32(PRC127);
3592 adapter->stats.prc255 += er32(PRC255);
3593 adapter->stats.prc511 += er32(PRC511);
3594 adapter->stats.prc1023 += er32(PRC1023);
3595 adapter->stats.prc1522 += er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003596 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597
Joe Perches1dc32912008-07-11 15:17:08 -07003598 adapter->stats.symerrs += er32(SYMERRS);
3599 adapter->stats.mpc += er32(MPC);
3600 adapter->stats.scc += er32(SCC);
3601 adapter->stats.ecol += er32(ECOL);
3602 adapter->stats.mcc += er32(MCC);
3603 adapter->stats.latecol += er32(LATECOL);
3604 adapter->stats.dc += er32(DC);
3605 adapter->stats.sec += er32(SEC);
3606 adapter->stats.rlec += er32(RLEC);
3607 adapter->stats.xonrxc += er32(XONRXC);
3608 adapter->stats.xontxc += er32(XONTXC);
3609 adapter->stats.xoffrxc += er32(XOFFRXC);
3610 adapter->stats.xofftxc += er32(XOFFTXC);
3611 adapter->stats.fcruc += er32(FCRUC);
3612 adapter->stats.gptc += er32(GPTC);
3613 adapter->stats.gotcl += er32(GOTCL);
3614 adapter->stats.gotch += er32(GOTCH);
3615 adapter->stats.rnbc += er32(RNBC);
3616 adapter->stats.ruc += er32(RUC);
3617 adapter->stats.rfc += er32(RFC);
3618 adapter->stats.rjc += er32(RJC);
3619 adapter->stats.torl += er32(TORL);
3620 adapter->stats.torh += er32(TORH);
3621 adapter->stats.totl += er32(TOTL);
3622 adapter->stats.toth += er32(TOTH);
3623 adapter->stats.tpr += er32(TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003624
Joe Perches1dc32912008-07-11 15:17:08 -07003625 if (hw->mac_type != e1000_ich8lan) {
3626 adapter->stats.ptc64 += er32(PTC64);
3627 adapter->stats.ptc127 += er32(PTC127);
3628 adapter->stats.ptc255 += er32(PTC255);
3629 adapter->stats.ptc511 += er32(PTC511);
3630 adapter->stats.ptc1023 += er32(PTC1023);
3631 adapter->stats.ptc1522 += er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003632 }
3633
Joe Perches1dc32912008-07-11 15:17:08 -07003634 adapter->stats.mptc += er32(MPTC);
3635 adapter->stats.bptc += er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636
3637 /* used for adaptive IFS */
3638
Joe Perches1dc32912008-07-11 15:17:08 -07003639 hw->tx_packet_delta = er32(TPT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 adapter->stats.tpt += hw->tx_packet_delta;
Joe Perches1dc32912008-07-11 15:17:08 -07003641 hw->collision_delta = er32(COLC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 adapter->stats.colc += hw->collision_delta;
3643
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003644 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07003645 adapter->stats.algnerrc += er32(ALGNERRC);
3646 adapter->stats.rxerrc += er32(RXERRC);
3647 adapter->stats.tncrs += er32(TNCRS);
3648 adapter->stats.cexterr += er32(CEXTERR);
3649 adapter->stats.tsctc += er32(TSCTC);
3650 adapter->stats.tsctfc += er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003652 if (hw->mac_type > e1000_82547_rev_2) {
Joe Perches1dc32912008-07-11 15:17:08 -07003653 adapter->stats.iac += er32(IAC);
3654 adapter->stats.icrxoc += er32(ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003655
Joe Perches1dc32912008-07-11 15:17:08 -07003656 if (hw->mac_type != e1000_ich8lan) {
3657 adapter->stats.icrxptc += er32(ICRXPTC);
3658 adapter->stats.icrxatc += er32(ICRXATC);
3659 adapter->stats.ictxptc += er32(ICTXPTC);
3660 adapter->stats.ictxatc += er32(ICTXATC);
3661 adapter->stats.ictxqec += er32(ICTXQEC);
3662 adapter->stats.ictxqmtc += er32(ICTXQMTC);
3663 adapter->stats.icrxdmtc += er32(ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003664 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
3667 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 adapter->net_stats.multicast = adapter->stats.mprc;
3669 adapter->net_stats.collisions = adapter->stats.colc;
3670
3671 /* Rx Errors */
3672
Jeff Kirsher87041632006-03-02 18:21:24 -08003673 /* RLEC on some newer hardware can be incorrect so build
3674 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3676 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003677 adapter->stats.ruc + adapter->stats.roc +
3678 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003679 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3680 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3682 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3684
3685 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003686 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3687 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3689 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3690 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Joe Perches1dc32912008-07-11 15:17:08 -07003691 if (hw->bad_tx_carr_stats_fd &&
Jeff Garzik167fb282006-12-15 10:41:15 -05003692 adapter->link_duplex == FULL_DUPLEX) {
3693 adapter->net_stats.tx_carrier_errors = 0;
3694 adapter->stats.tncrs = 0;
3695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696
3697 /* Tx Dropped needs to be maintained elsewhere */
3698
3699 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003700 if (hw->media_type == e1000_media_type_copper) {
3701 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3703 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3704 adapter->phy_stats.idle_errors += phy_tmp;
3705 }
3706
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003707 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 (hw->phy_type == e1000_phy_m88) &&
3709 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3710 adapter->phy_stats.receive_errors += phy_tmp;
3711 }
3712
Jeff Garzik15e376b2006-12-15 11:16:33 -05003713 /* Management Stats */
Joe Perches1dc32912008-07-11 15:17:08 -07003714 if (hw->has_smbus) {
3715 adapter->stats.mgptc += er32(MGTPTC);
3716 adapter->stats.mgprc += er32(MGTPRC);
3717 adapter->stats.mgpdc += er32(MGTPDC);
Jeff Garzik15e376b2006-12-15 11:16:33 -05003718 }
3719
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3721}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003722
3723/**
3724 * e1000_intr_msi - Interrupt Handler
3725 * @irq: interrupt number
3726 * @data: pointer to a network interface device structure
3727 **/
3728
Joe Perches64798842008-07-11 15:17:02 -07003729static irqreturn_t e1000_intr_msi(int irq, void *data)
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003730{
3731 struct net_device *netdev = data;
3732 struct e1000_adapter *adapter = netdev_priv(netdev);
3733 struct e1000_hw *hw = &adapter->hw;
Joe Perches1dc32912008-07-11 15:17:08 -07003734 u32 icr = er32(ICR);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003735
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003736 /* in NAPI mode read ICR disables interrupts using IAM */
3737
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003738 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3739 hw->get_link_status = 1;
3740 /* 80003ES2LAN workaround-- For packet buffer work-around on
3741 * link down event; disable receives here in the ISR and reset
3742 * adapter in watchdog */
3743 if (netif_carrier_ok(netdev) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003744 (hw->mac_type == e1000_80003es2lan)) {
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003745 /* disable receives */
Joe Perches1dc32912008-07-11 15:17:08 -07003746 u32 rctl = er32(RCTL);
3747 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003748 }
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003749 /* guard against interrupt when we're going down */
3750 if (!test_bit(__E1000_DOWN, &adapter->flags))
3751 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003752 }
3753
Ben Hutchings288379f2009-01-19 16:43:59 -08003754 if (likely(napi_schedule_prep(&adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003755 adapter->total_tx_bytes = 0;
3756 adapter->total_tx_packets = 0;
3757 adapter->total_rx_bytes = 0;
3758 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08003759 __napi_schedule(&adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003760 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003761 e1000_irq_enable(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003762
3763 return IRQ_HANDLED;
3764}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765
3766/**
3767 * e1000_intr - Interrupt Handler
3768 * @irq: interrupt number
3769 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 **/
3771
Joe Perches64798842008-07-11 15:17:02 -07003772static irqreturn_t e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773{
3774 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003775 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 struct e1000_hw *hw = &adapter->hw;
Joe Perches1dc32912008-07-11 15:17:08 -07003777 u32 rctl, icr = er32(ICR);
Francois Romieuc3570ac2008-07-11 15:17:38 -07003778
Jesse Brandeburge151a602009-05-04 11:19:42 +00003779 if (unlikely((!icr) || test_bit(__E1000_DOWN, &adapter->flags)))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003780 return IRQ_NONE; /* Not our interrupt */
3781
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003782 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3783 * not set, then the adapter didn't send an interrupt */
3784 if (unlikely(hw->mac_type >= e1000_82571 &&
3785 !(icr & E1000_ICR_INT_ASSERTED)))
3786 return IRQ_NONE;
3787
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003788 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3789 * need for the IMC write */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003791 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003793 /* 80003ES2LAN workaround--
3794 * For packet buffer work-around on link down event;
3795 * disable receives here in the ISR and
3796 * reset adapter in watchdog
3797 */
3798 if (netif_carrier_ok(netdev) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003799 (hw->mac_type == e1000_80003es2lan)) {
Jeff Kirsher87041632006-03-02 18:21:24 -08003800 /* disable receives */
Joe Perches1dc32912008-07-11 15:17:08 -07003801 rctl = er32(RCTL);
3802 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher87041632006-03-02 18:21:24 -08003803 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003804 /* guard against interrupt when we're going down */
3805 if (!test_bit(__E1000_DOWN, &adapter->flags))
3806 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 }
3808
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003809 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003810 /* disable interrupts, without the synchronize_irq bit */
Joe Perches1dc32912008-07-11 15:17:08 -07003811 ew32(IMC, ~0);
3812 E1000_WRITE_FLUSH();
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003813 }
Ben Hutchings288379f2009-01-19 16:43:59 -08003814 if (likely(napi_schedule_prep(&adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003815 adapter->total_tx_bytes = 0;
3816 adapter->total_tx_packets = 0;
3817 adapter->total_rx_bytes = 0;
3818 adapter->total_rx_packets = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -08003819 __napi_schedule(&adapter->napi);
Jesse Brandeburga6c42322009-03-25 21:59:22 +00003820 } else {
Auke Kok90fb5132006-11-01 08:47:30 -08003821 /* this really should not happen! if it does it is basically a
3822 * bug, but not a hard error, so enable ints and continue */
Jesse Brandeburga6c42322009-03-25 21:59:22 +00003823 if (!test_bit(__E1000_DOWN, &adapter->flags))
3824 e1000_irq_enable(adapter);
3825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 return IRQ_HANDLED;
3828}
3829
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830/**
3831 * e1000_clean - NAPI Rx polling callback
3832 * @adapter: board private structure
3833 **/
Joe Perches64798842008-07-11 15:17:02 -07003834static int e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003836 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3837 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003838 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003839
Wang Chen4cf16532008-11-12 23:38:14 -08003840 adapter = netdev_priv(poll_dev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003841
Alexander Duyck80179432009-01-21 14:42:47 -08003842 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003843
Auke Kokd3d9e482006-07-14 16:14:23 -07003844 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003845 &work_done, budget);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003846
Alexander Duyckccfb3422009-03-25 21:59:04 +00003847 if (!tx_cleaned)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003848 work_done = budget;
3849
David S. Miller53e52c72008-01-07 21:06:12 -08003850 /* If budget not fully consumed, exit the polling mode */
3851 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003852 if (likely(adapter->itr_setting & 3))
3853 e1000_set_itr(adapter);
Ben Hutchings288379f2009-01-19 16:43:59 -08003854 napi_complete(napi);
Jesse Brandeburga6c42322009-03-25 21:59:22 +00003855 if (!test_bit(__E1000_DOWN, &adapter->flags))
3856 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 }
3858
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003859 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860}
3861
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862/**
3863 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3864 * @adapter: board private structure
3865 **/
Joe Perches64798842008-07-11 15:17:02 -07003866static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3867 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868{
Joe Perches1dc32912008-07-11 15:17:08 -07003869 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 struct net_device *netdev = adapter->netdev;
3871 struct e1000_tx_desc *tx_desc, *eop_desc;
3872 struct e1000_buffer *buffer_info;
3873 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003874 unsigned int count = 0;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003875 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876
3877 i = tx_ring->next_to_clean;
3878 eop = tx_ring->buffer_info[i].next_to_watch;
3879 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3880
Alexander Duyckccfb3422009-03-25 21:59:04 +00003881 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3882 (count < tx_ring->count)) {
Jesse Brandeburg843f4262009-04-16 16:59:47 +00003883 bool cleaned = false;
3884 for ( ; !cleaned; count++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 tx_desc = E1000_TX_DESC(*tx_ring, i);
3886 buffer_info = &tx_ring->buffer_info[i];
3887 cleaned = (i == eop);
3888
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003889 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003890 struct sk_buff *skb = buffer_info->skb;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003891 unsigned int segs, bytecount;
3892 segs = skb_shinfo(skb)->gso_segs ?: 1;
3893 /* multiply data chunks by size of headers */
3894 bytecount = ((segs - 1) * skb_headlen(skb)) +
3895 skb->len;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003896 total_tx_packets += segs;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003897 total_tx_bytes += bytecount;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003898 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05003899 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003900 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003902 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003904
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 eop = tx_ring->buffer_info[i].next_to_watch;
3906 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3907 }
3908
3909 tx_ring->next_to_clean = i;
3910
Auke Kok77b2aad2006-04-14 19:05:25 -07003911#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg843f4262009-04-16 16:59:47 +00003912 if (unlikely(count && netif_carrier_ok(netdev) &&
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003913 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3914 /* Make sure that anybody stopping the queue after this
3915 * sees the new next_to_clean.
3916 */
3917 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003918 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07003919 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003920 ++adapter->restart_queue;
3921 }
Auke Kok77b2aad2006-04-14 19:05:25 -07003922 }
Malli Chilakala26483452005-04-28 19:44:46 -07003923
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003924 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003925 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 * check with the clearing of time_stamp and movement of i */
Joe Perchesc3033b02008-03-21 11:06:25 -07003927 adapter->detect_tx_hung = false;
Alexander Duyckccfb3422009-03-25 21:59:04 +00003928 if (tx_ring->buffer_info[i].time_stamp &&
3929 time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003930 (adapter->tx_timeout_factor * HZ))
Joe Perches1dc32912008-07-11 15:17:08 -07003931 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003932
3933 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003934 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003935 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003936 " TDH <%x>\n"
3937 " TDT <%x>\n"
3938 " next_to_use <%x>\n"
3939 " next_to_clean <%x>\n"
3940 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003941 " time_stamp <%lx>\n"
3942 " next_to_watch <%x>\n"
3943 " jiffies <%lx>\n"
3944 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003945 (unsigned long)((tx_ring - adapter->tx_ring) /
3946 sizeof(struct e1000_tx_ring)),
Joe Perches1dc32912008-07-11 15:17:08 -07003947 readl(hw->hw_addr + tx_ring->tdh),
3948 readl(hw->hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003949 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003950 tx_ring->next_to_clean,
Alexander Duyckccfb3422009-03-25 21:59:04 +00003951 tx_ring->buffer_info[i].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003952 eop,
3953 jiffies,
3954 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003958 adapter->total_tx_bytes += total_tx_bytes;
3959 adapter->total_tx_packets += total_tx_packets;
Auke Kokef90e4e2007-11-13 20:49:15 -08003960 adapter->net_stats.tx_bytes += total_tx_bytes;
3961 adapter->net_stats.tx_packets += total_tx_packets;
Alexander Duyckccfb3422009-03-25 21:59:04 +00003962 return (count < tx_ring->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963}
3964
3965/**
3966 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003967 * @adapter: board private structure
3968 * @status_err: receive descriptor status and error fields
3969 * @csum: receive descriptor csum field
3970 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 **/
3972
Joe Perches64798842008-07-11 15:17:02 -07003973static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3974 u32 csum, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975{
Joe Perches1dc32912008-07-11 15:17:08 -07003976 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003977 u16 status = (u16)status_err;
3978 u8 errors = (u8)(status_err >> 24);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003979 skb->ip_summed = CHECKSUM_NONE;
3980
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 /* 82543 or newer only */
Joe Perches1dc32912008-07-11 15:17:08 -07003982 if (unlikely(hw->mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003984 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003985 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003986 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003987 /* let the stack verify checksum errors */
3988 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 return;
3990 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003991 /* TCP/UDP Checksum has not been calculated */
Joe Perches1dc32912008-07-11 15:17:08 -07003992 if (hw->mac_type <= e1000_82547_rev_2) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003993 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003994 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003996 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003997 return;
3998 }
3999 /* It must be a TCP or UDP packet with a valid checksum */
4000 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 /* TCP checksum is good */
4002 skb->ip_summed = CHECKSUM_UNNECESSARY;
Joe Perches1dc32912008-07-11 15:17:08 -07004003 } else if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004004 /* IP fragment with UDP payload */
4005 /* Hardware complements the payload checksum, so we undo it
4006 * and then put the value in host order for further stack use.
4007 */
Al Viro3e188262007-12-11 19:49:39 +00004008 __sum16 sum = (__force __sum16)htons(csum);
4009 skb->csum = csum_unfold(~sum);
Patrick McHardy84fa7932006-08-29 16:44:56 -07004010 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004012 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013}
4014
4015/**
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004016 * e1000_consume_page - helper function
4017 **/
4018static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
4019 u16 length)
4020{
4021 bi->page = NULL;
4022 skb->len += length;
4023 skb->data_len += length;
4024 skb->truesize += length;
4025}
4026
4027/**
4028 * e1000_receive_skb - helper function to handle rx indications
4029 * @adapter: board private structure
4030 * @status: descriptor status field as written by hardware
4031 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
4032 * @skb: pointer to sk_buff to be indicated to stack
4033 */
4034static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
4035 __le16 vlan, struct sk_buff *skb)
4036{
4037 if (unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP))) {
4038 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4039 le16_to_cpu(vlan) &
4040 E1000_RXD_SPC_VLAN_MASK);
4041 } else {
4042 netif_receive_skb(skb);
4043 }
4044}
4045
4046/**
4047 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
4048 * @adapter: board private structure
4049 * @rx_ring: ring to clean
4050 * @work_done: amount of napi work completed this call
4051 * @work_to_do: max amount of work allowed for this call to do
4052 *
4053 * the return value indicates whether actual cleaning was done, there
4054 * is no guarantee that everything was cleaned
4055 */
4056static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
4057 struct e1000_rx_ring *rx_ring,
4058 int *work_done, int work_to_do)
4059{
4060 struct e1000_hw *hw = &adapter->hw;
4061 struct net_device *netdev = adapter->netdev;
4062 struct pci_dev *pdev = adapter->pdev;
4063 struct e1000_rx_desc *rx_desc, *next_rxd;
4064 struct e1000_buffer *buffer_info, *next_buffer;
4065 unsigned long irq_flags;
4066 u32 length;
4067 unsigned int i;
4068 int cleaned_count = 0;
4069 bool cleaned = false;
4070 unsigned int total_rx_bytes=0, total_rx_packets=0;
4071
4072 i = rx_ring->next_to_clean;
4073 rx_desc = E1000_RX_DESC(*rx_ring, i);
4074 buffer_info = &rx_ring->buffer_info[i];
4075
4076 while (rx_desc->status & E1000_RXD_STAT_DD) {
4077 struct sk_buff *skb;
4078 u8 status;
4079
4080 if (*work_done >= work_to_do)
4081 break;
4082 (*work_done)++;
4083
4084 status = rx_desc->status;
4085 skb = buffer_info->skb;
4086 buffer_info->skb = NULL;
4087
4088 if (++i == rx_ring->count) i = 0;
4089 next_rxd = E1000_RX_DESC(*rx_ring, i);
4090 prefetch(next_rxd);
4091
4092 next_buffer = &rx_ring->buffer_info[i];
4093
4094 cleaned = true;
4095 cleaned_count++;
4096 pci_unmap_page(pdev, buffer_info->dma, buffer_info->length,
4097 PCI_DMA_FROMDEVICE);
4098 buffer_info->dma = 0;
4099
4100 length = le16_to_cpu(rx_desc->length);
4101
4102 /* errors is only valid for DD + EOP descriptors */
4103 if (unlikely((status & E1000_RXD_STAT_EOP) &&
4104 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
4105 u8 last_byte = *(skb->data + length - 1);
4106 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4107 last_byte)) {
4108 spin_lock_irqsave(&adapter->stats_lock,
4109 irq_flags);
4110 e1000_tbi_adjust_stats(hw, &adapter->stats,
4111 length, skb->data);
4112 spin_unlock_irqrestore(&adapter->stats_lock,
4113 irq_flags);
4114 length--;
4115 } else {
4116 /* recycle both page and skb */
4117 buffer_info->skb = skb;
4118 /* an error means any chain goes out the window
4119 * too */
4120 if (rx_ring->rx_skb_top)
4121 dev_kfree_skb(rx_ring->rx_skb_top);
4122 rx_ring->rx_skb_top = NULL;
4123 goto next_desc;
4124 }
4125 }
4126
4127#define rxtop rx_ring->rx_skb_top
4128 if (!(status & E1000_RXD_STAT_EOP)) {
4129 /* this descriptor is only the beginning (or middle) */
4130 if (!rxtop) {
4131 /* this is the beginning of a chain */
4132 rxtop = skb;
4133 skb_fill_page_desc(rxtop, 0, buffer_info->page,
4134 0, length);
4135 } else {
4136 /* this is the middle of a chain */
4137 skb_fill_page_desc(rxtop,
4138 skb_shinfo(rxtop)->nr_frags,
4139 buffer_info->page, 0, length);
4140 /* re-use the skb, only consumed the page */
4141 buffer_info->skb = skb;
4142 }
4143 e1000_consume_page(buffer_info, rxtop, length);
4144 goto next_desc;
4145 } else {
4146 if (rxtop) {
4147 /* end of the chain */
4148 skb_fill_page_desc(rxtop,
4149 skb_shinfo(rxtop)->nr_frags,
4150 buffer_info->page, 0, length);
4151 /* re-use the current skb, we only consumed the
4152 * page */
4153 buffer_info->skb = skb;
4154 skb = rxtop;
4155 rxtop = NULL;
4156 e1000_consume_page(buffer_info, skb, length);
4157 } else {
4158 /* no chain, got EOP, this buf is the packet
4159 * copybreak to save the put_page/alloc_page */
4160 if (length <= copybreak &&
4161 skb_tailroom(skb) >= length) {
4162 u8 *vaddr;
4163 vaddr = kmap_atomic(buffer_info->page,
4164 KM_SKB_DATA_SOFTIRQ);
4165 memcpy(skb_tail_pointer(skb), vaddr, length);
4166 kunmap_atomic(vaddr,
4167 KM_SKB_DATA_SOFTIRQ);
4168 /* re-use the page, so don't erase
4169 * buffer_info->page */
4170 skb_put(skb, length);
4171 } else {
4172 skb_fill_page_desc(skb, 0,
4173 buffer_info->page, 0,
4174 length);
4175 e1000_consume_page(buffer_info, skb,
4176 length);
4177 }
4178 }
4179 }
4180
4181 /* Receive Checksum Offload XXX recompute due to CRC strip? */
4182 e1000_rx_checksum(adapter,
4183 (u32)(status) |
4184 ((u32)(rx_desc->errors) << 24),
4185 le16_to_cpu(rx_desc->csum), skb);
4186
4187 pskb_trim(skb, skb->len - 4);
4188
4189 /* probably a little skewed due to removing CRC */
4190 total_rx_bytes += skb->len;
4191 total_rx_packets++;
4192
4193 /* eth type trans needs skb->data to point to something */
4194 if (!pskb_may_pull(skb, ETH_HLEN)) {
4195 DPRINTK(DRV, ERR, "pskb_may_pull failed.\n");
4196 dev_kfree_skb(skb);
4197 goto next_desc;
4198 }
4199
4200 skb->protocol = eth_type_trans(skb, netdev);
4201
4202 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4203
4204next_desc:
4205 rx_desc->status = 0;
4206
4207 /* return some buffers to hardware, one at a time is too slow */
4208 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4209 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4210 cleaned_count = 0;
4211 }
4212
4213 /* use prefetched values */
4214 rx_desc = next_rxd;
4215 buffer_info = next_buffer;
4216 }
4217 rx_ring->next_to_clean = i;
4218
4219 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4220 if (cleaned_count)
4221 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4222
4223 adapter->total_rx_packets += total_rx_packets;
4224 adapter->total_rx_bytes += total_rx_bytes;
4225 adapter->net_stats.rx_bytes += total_rx_bytes;
4226 adapter->net_stats.rx_packets += total_rx_packets;
4227 return cleaned;
4228}
4229
4230/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004231 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 * @adapter: board private structure
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004233 * @rx_ring: ring to clean
4234 * @work_done: amount of napi work completed this call
4235 * @work_to_do: max amount of work allowed for this call to do
4236 */
Joe Perches64798842008-07-11 15:17:02 -07004237static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4238 struct e1000_rx_ring *rx_ring,
4239 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240{
Joe Perches1dc32912008-07-11 15:17:08 -07004241 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242 struct net_device *netdev = adapter->netdev;
4243 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004244 struct e1000_rx_desc *rx_desc, *next_rxd;
4245 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07004247 u32 length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004249 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004250 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004251 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252
4253 i = rx_ring->next_to_clean;
4254 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004255 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004257 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004258 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004259 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004260
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004261 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 break;
4263 (*work_done)++;
Francois Romieuc3570ac2008-07-11 15:17:38 -07004264
Jeff Kirshera292ca62006-01-12 16:51:30 -08004265 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004266 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004267 buffer_info->skb = NULL;
4268
Jeff Kirsher30320be2006-03-02 18:21:57 -08004269 prefetch(skb->data - NET_IP_ALIGN);
4270
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004271 if (++i == rx_ring->count) i = 0;
4272 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004273 prefetch(next_rxd);
4274
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004275 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004276
Joe Perchesc3033b02008-03-21 11:06:25 -07004277 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004278 cleaned_count++;
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004279 pci_unmap_single(pdev, buffer_info->dma, buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 PCI_DMA_FROMDEVICE);
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00004281 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 length = le16_to_cpu(rx_desc->length);
Neil Hormanea30e112009-06-02 01:29:58 -07004284 /* !EOP means multiple descriptors were used to store a single
4285 * packet, also make sure the frame isn't just CRC only */
4286 if (unlikely(!(status & E1000_RXD_STAT_EOP) || (length <= 4))) {
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004287 /* All receives must fit into a single buffer */
4288 E1000_DBG("%s: Receive packet consumed multiple"
4289 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004290 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004291 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 goto next_desc;
4293 }
4294
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004295 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004296 u8 last_byte = *(skb->data + length - 1);
Joe Perches1dc32912008-07-11 15:17:08 -07004297 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4298 last_byte)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004300 e1000_tbi_adjust_stats(hw, &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 length, skb->data);
4302 spin_unlock_irqrestore(&adapter->stats_lock,
4303 flags);
4304 length--;
4305 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004306 /* recycle */
4307 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308 goto next_desc;
4309 }
Auke Kok1cb58212006-04-18 12:31:04 -07004310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004312 /* adjust length to remove Ethernet CRC, this must be
4313 * done after the TBI_ACCEPT workaround above */
4314 length -= 4;
4315
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004316 /* probably a little skewed due to removing CRC */
4317 total_rx_bytes += length;
4318 total_rx_packets++;
4319
Jeff Kirshera292ca62006-01-12 16:51:30 -08004320 /* code added for copybreak, this should improve
4321 * performance for small packets with large amounts
4322 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004323 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004324 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004325 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004326 if (new_skb) {
4327 skb_reserve(new_skb, NET_IP_ALIGN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004328 skb_copy_to_linear_data_offset(new_skb,
4329 -NET_IP_ALIGN,
4330 (skb->data -
4331 NET_IP_ALIGN),
4332 (length +
4333 NET_IP_ALIGN));
Jeff Kirshera292ca62006-01-12 16:51:30 -08004334 /* save the skb in buffer_info as good */
4335 buffer_info->skb = skb;
4336 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004337 }
Auke Kok996695d2006-11-01 08:47:50 -08004338 /* else just continue with the old one */
4339 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004340 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004341 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342
4343 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004344 e1000_rx_checksum(adapter,
Joe Perches406874a2008-04-03 10:06:32 -07004345 (u32)(status) |
4346 ((u32)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004347 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004348
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 skb->protocol = eth_type_trans(skb, netdev);
Francois Romieuc3570ac2008-07-11 15:17:38 -07004350
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004351 e1000_receive_skb(adapter, status, rx_desc->special, skb);
Francois Romieuc3570ac2008-07-11 15:17:38 -07004352
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353next_desc:
4354 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004356 /* return some buffers to hardware, one at a time is too slow */
4357 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4358 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4359 cleaned_count = 0;
4360 }
4361
Jeff Kirsher30320be2006-03-02 18:21:57 -08004362 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004363 rx_desc = next_rxd;
4364 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004367
4368 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4369 if (cleaned_count)
4370 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004372 adapter->total_rx_packets += total_rx_packets;
4373 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004374 adapter->net_stats.rx_bytes += total_rx_bytes;
4375 adapter->net_stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 return cleaned;
4377}
4378
4379/**
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004380 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4381 * @adapter: address of board private structure
4382 * @rx_ring: pointer to receive ring structure
4383 * @cleaned_count: number of buffers to allocate this pass
4384 **/
4385
4386static void
4387e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
4388 struct e1000_rx_ring *rx_ring, int cleaned_count)
4389{
4390 struct net_device *netdev = adapter->netdev;
4391 struct pci_dev *pdev = adapter->pdev;
4392 struct e1000_rx_desc *rx_desc;
4393 struct e1000_buffer *buffer_info;
4394 struct sk_buff *skb;
4395 unsigned int i;
4396 unsigned int bufsz = 256 -
4397 16 /*for skb_reserve */ -
4398 NET_IP_ALIGN;
4399
4400 i = rx_ring->next_to_use;
4401 buffer_info = &rx_ring->buffer_info[i];
4402
4403 while (cleaned_count--) {
4404 skb = buffer_info->skb;
4405 if (skb) {
4406 skb_trim(skb, 0);
4407 goto check_page;
4408 }
4409
4410 skb = netdev_alloc_skb(netdev, bufsz);
4411 if (unlikely(!skb)) {
4412 /* Better luck next round */
4413 adapter->alloc_rx_buff_failed++;
4414 break;
4415 }
4416
4417 /* Fix for errata 23, can't cross 64kB boundary */
4418 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4419 struct sk_buff *oldskb = skb;
4420 DPRINTK(PROBE, ERR, "skb align check failed: %u bytes "
4421 "at %p\n", bufsz, skb->data);
4422 /* Try again, without freeing the previous */
4423 skb = netdev_alloc_skb(netdev, bufsz);
4424 /* Failed allocation, critical failure */
4425 if (!skb) {
4426 dev_kfree_skb(oldskb);
4427 adapter->alloc_rx_buff_failed++;
4428 break;
4429 }
4430
4431 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4432 /* give up */
4433 dev_kfree_skb(skb);
4434 dev_kfree_skb(oldskb);
4435 break; /* while (cleaned_count--) */
4436 }
4437
4438 /* Use new allocation */
4439 dev_kfree_skb(oldskb);
4440 }
4441 /* Make buffer alignment 2 beyond a 16 byte boundary
4442 * this will result in a 16 byte aligned IP header after
4443 * the 14 byte MAC header is removed
4444 */
4445 skb_reserve(skb, NET_IP_ALIGN);
4446
4447 buffer_info->skb = skb;
4448 buffer_info->length = adapter->rx_buffer_len;
4449check_page:
4450 /* allocate a new page if necessary */
4451 if (!buffer_info->page) {
4452 buffer_info->page = alloc_page(GFP_ATOMIC);
4453 if (unlikely(!buffer_info->page)) {
4454 adapter->alloc_rx_buff_failed++;
4455 break;
4456 }
4457 }
4458
4459 if (!buffer_info->dma)
4460 buffer_info->dma = pci_map_page(pdev,
4461 buffer_info->page, 0,
4462 buffer_info->length,
4463 PCI_DMA_FROMDEVICE);
4464
4465 rx_desc = E1000_RX_DESC(*rx_ring, i);
4466 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4467
4468 if (unlikely(++i == rx_ring->count))
4469 i = 0;
4470 buffer_info = &rx_ring->buffer_info[i];
4471 }
4472
4473 if (likely(rx_ring->next_to_use != i)) {
4474 rx_ring->next_to_use = i;
4475 if (unlikely(i-- == 0))
4476 i = (rx_ring->count - 1);
4477
4478 /* Force memory writes to complete before letting h/w
4479 * know there are new descriptors to fetch. (Only
4480 * applicable for weak-ordered memory model archs,
4481 * such as IA-64). */
4482 wmb();
4483 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4484 }
4485}
4486
4487/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004488 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 * @adapter: address of board private structure
4490 **/
4491
Joe Perches64798842008-07-11 15:17:02 -07004492static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4493 struct e1000_rx_ring *rx_ring,
4494 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495{
Joe Perches1dc32912008-07-11 15:17:08 -07004496 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 struct net_device *netdev = adapter->netdev;
4498 struct pci_dev *pdev = adapter->pdev;
4499 struct e1000_rx_desc *rx_desc;
4500 struct e1000_buffer *buffer_info;
4501 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004502 unsigned int i;
4503 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504
4505 i = rx_ring->next_to_use;
4506 buffer_info = &rx_ring->buffer_info[i];
4507
Jeff Kirshera292ca62006-01-12 16:51:30 -08004508 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004509 skb = buffer_info->skb;
4510 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004511 skb_trim(skb, 0);
4512 goto map_skb;
4513 }
4514
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004515 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004516 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004518 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 break;
4520 }
4521
Malli Chilakala26483452005-04-28 19:44:46 -07004522 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4524 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004525 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4526 "at %p\n", bufsz, skb->data);
4527 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004528 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004529 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 if (!skb) {
4531 dev_kfree_skb(oldskb);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004532 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 break;
4534 }
Malli Chilakala26483452005-04-28 19:44:46 -07004535
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4537 /* give up */
4538 dev_kfree_skb(skb);
4539 dev_kfree_skb(oldskb);
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004540 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004543
4544 /* Use new allocation */
4545 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 /* Make buffer alignment 2 beyond a 16 byte boundary
4548 * this will result in a 16 byte aligned IP header after
4549 * the 14 byte MAC header is removed
4550 */
4551 skb_reserve(skb, NET_IP_ALIGN);
4552
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 buffer_info->skb = skb;
4554 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004555map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 buffer_info->dma = pci_map_single(pdev,
4557 skb->data,
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004558 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 PCI_DMA_FROMDEVICE);
4560
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004561 /*
4562 * XXX if it was allocated cleanly it will never map to a
4563 * boundary crossing
4564 */
4565
Malli Chilakala26483452005-04-28 19:44:46 -07004566 /* Fix for errata 23, can't cross 64kB boundary */
4567 if (!e1000_check_64k_bound(adapter,
4568 (void *)(unsigned long)buffer_info->dma,
4569 adapter->rx_buffer_len)) {
4570 DPRINTK(RX_ERR, ERR,
4571 "dma align check failed: %u bytes at %p\n",
4572 adapter->rx_buffer_len,
4573 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 dev_kfree_skb(skb);
4575 buffer_info->skb = NULL;
4576
Malli Chilakala26483452005-04-28 19:44:46 -07004577 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578 adapter->rx_buffer_len,
4579 PCI_DMA_FROMDEVICE);
Jesse Brandeburg679be3b2009-06-30 12:45:34 +00004580 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581
Jesse Brandeburgedbbb3c2009-07-06 10:44:39 +00004582 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583 break; /* while !buffer_info->skb */
4584 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 rx_desc = E1000_RX_DESC(*rx_ring, i);
4586 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4587
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004588 if (unlikely(++i == rx_ring->count))
4589 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 buffer_info = &rx_ring->buffer_info[i];
4591 }
4592
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004593 if (likely(rx_ring->next_to_use != i)) {
4594 rx_ring->next_to_use = i;
4595 if (unlikely(i-- == 0))
4596 i = (rx_ring->count - 1);
4597
4598 /* Force memory writes to complete before letting h/w
4599 * know there are new descriptors to fetch. (Only
4600 * applicable for weak-ordered memory model archs,
4601 * such as IA-64). */
4602 wmb();
Joe Perches1dc32912008-07-11 15:17:08 -07004603 writel(i, hw->hw_addr + rx_ring->rdt);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605}
4606
4607/**
4608 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4609 * @adapter:
4610 **/
4611
Joe Perches64798842008-07-11 15:17:02 -07004612static void e1000_smartspeed(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613{
Joe Perches1dc32912008-07-11 15:17:08 -07004614 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004615 u16 phy_status;
4616 u16 phy_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617
Joe Perches1dc32912008-07-11 15:17:08 -07004618 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4619 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620 return;
4621
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004622 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 /* If Master/Slave config fault is asserted twice,
4624 * we assume back-to-back */
Joe Perches1dc32912008-07-11 15:17:08 -07004625 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004626 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Joe Perches1dc32912008-07-11 15:17:08 -07004627 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004628 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Joe Perches1dc32912008-07-11 15:17:08 -07004629 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004630 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 phy_ctrl &= ~CR_1000T_MS_ENABLE;
Joe Perches1dc32912008-07-11 15:17:08 -07004632 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 phy_ctrl);
4634 adapter->smartspeed++;
Joe Perches1dc32912008-07-11 15:17:08 -07004635 if (!e1000_phy_setup_autoneg(hw) &&
4636 !e1000_read_phy_reg(hw, PHY_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 &phy_ctrl)) {
4638 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4639 MII_CR_RESTART_AUTO_NEG);
Joe Perches1dc32912008-07-11 15:17:08 -07004640 e1000_write_phy_reg(hw, PHY_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 phy_ctrl);
4642 }
4643 }
4644 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004645 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 /* If still no link, perhaps using 2/3 pair cable */
Joe Perches1dc32912008-07-11 15:17:08 -07004647 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648 phy_ctrl |= CR_1000T_MS_ENABLE;
Joe Perches1dc32912008-07-11 15:17:08 -07004649 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4650 if (!e1000_phy_setup_autoneg(hw) &&
4651 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4653 MII_CR_RESTART_AUTO_NEG);
Joe Perches1dc32912008-07-11 15:17:08 -07004654 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 }
4656 }
4657 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004658 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 adapter->smartspeed = 0;
4660}
4661
4662/**
4663 * e1000_ioctl -
4664 * @netdev:
4665 * @ifreq:
4666 * @cmd:
4667 **/
4668
Joe Perches64798842008-07-11 15:17:02 -07004669static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670{
4671 switch (cmd) {
4672 case SIOCGMIIPHY:
4673 case SIOCGMIIREG:
4674 case SIOCSMIIREG:
4675 return e1000_mii_ioctl(netdev, ifr, cmd);
4676 default:
4677 return -EOPNOTSUPP;
4678 }
4679}
4680
4681/**
4682 * e1000_mii_ioctl -
4683 * @netdev:
4684 * @ifreq:
4685 * @cmd:
4686 **/
4687
Joe Perches64798842008-07-11 15:17:02 -07004688static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4689 int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004691 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004692 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 struct mii_ioctl_data *data = if_mii(ifr);
4694 int retval;
Joe Perches406874a2008-04-03 10:06:32 -07004695 u16 mii_reg;
4696 u16 spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004697 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698
Joe Perches1dc32912008-07-11 15:17:08 -07004699 if (hw->media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700 return -EOPNOTSUPP;
4701
4702 switch (cmd) {
4703 case SIOCGMIIPHY:
Joe Perches1dc32912008-07-11 15:17:08 -07004704 data->phy_id = hw->phy_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705 break;
4706 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004707 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004709 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004710 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004711 &data->val_out)) {
4712 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004714 }
4715 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 break;
4717 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004718 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004720 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 return -EFAULT;
4722 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004723 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004724 if (e1000_write_phy_reg(hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004725 mii_reg)) {
4726 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004728 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004729 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004730 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 switch (data->reg_num) {
4732 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004733 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004735 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Joe Perches1dc32912008-07-11 15:17:08 -07004736 hw->autoneg = 1;
4737 hw->autoneg_advertised = 0x2F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738 } else {
4739 if (mii_reg & 0x40)
4740 spddplx = SPEED_1000;
4741 else if (mii_reg & 0x2000)
4742 spddplx = SPEED_100;
4743 else
4744 spddplx = SPEED_10;
4745 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004746 ? DUPLEX_FULL :
4747 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 retval = e1000_set_spd_dplx(adapter,
4749 spddplx);
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004750 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 return retval;
4752 }
Auke Kok2db10a02006-06-27 09:06:28 -07004753 if (netif_running(adapter->netdev))
4754 e1000_reinit_locked(adapter);
4755 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756 e1000_reset(adapter);
4757 break;
4758 case M88E1000_PHY_SPEC_CTRL:
4759 case M88E1000_EXT_PHY_SPEC_CTRL:
Joe Perches1dc32912008-07-11 15:17:08 -07004760 if (e1000_phy_reset(hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761 return -EIO;
4762 break;
4763 }
4764 } else {
4765 switch (data->reg_num) {
4766 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004767 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004769 if (netif_running(adapter->netdev))
4770 e1000_reinit_locked(adapter);
4771 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 e1000_reset(adapter);
4773 break;
4774 }
4775 }
4776 break;
4777 default:
4778 return -EOPNOTSUPP;
4779 }
4780 return E1000_SUCCESS;
4781}
4782
Joe Perches64798842008-07-11 15:17:02 -07004783void e1000_pci_set_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784{
4785 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004786 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004788 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004789 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790}
4791
Joe Perches64798842008-07-11 15:17:02 -07004792void e1000_pci_clear_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793{
4794 struct e1000_adapter *adapter = hw->back;
4795
4796 pci_clear_mwi(adapter->pdev);
4797}
4798
Joe Perches64798842008-07-11 15:17:02 -07004799int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
Peter Oruba007755e2007-09-28 22:42:06 -07004800{
4801 struct e1000_adapter *adapter = hw->back;
4802 return pcix_get_mmrbc(adapter->pdev);
4803}
4804
Joe Perches64798842008-07-11 15:17:02 -07004805void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
Peter Oruba007755e2007-09-28 22:42:06 -07004806{
4807 struct e1000_adapter *adapter = hw->back;
4808 pcix_set_mmrbc(adapter->pdev, mmrbc);
4809}
4810
Joe Perches64798842008-07-11 15:17:02 -07004811s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004812{
4813 struct e1000_adapter *adapter = hw->back;
Joe Perches406874a2008-04-03 10:06:32 -07004814 u16 cap_offset;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004815
4816 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4817 if (!cap_offset)
4818 return -E1000_ERR_CONFIG;
4819
4820 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4821
4822 return E1000_SUCCESS;
4823}
4824
Joe Perches64798842008-07-11 15:17:02 -07004825void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826{
4827 outl(value, port);
4828}
4829
Joe Perches64798842008-07-11 15:17:02 -07004830static void e1000_vlan_rx_register(struct net_device *netdev,
4831 struct vlan_group *grp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004833 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004834 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004835 u32 ctrl, rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004837 if (!test_bit(__E1000_DOWN, &adapter->flags))
4838 e1000_irq_disable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839 adapter->vlgrp = grp;
4840
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004841 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 /* enable VLAN tag insert/strip */
Joe Perches1dc32912008-07-11 15:17:08 -07004843 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 ctrl |= E1000_CTRL_VME;
Joe Perches1dc32912008-07-11 15:17:08 -07004845 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846
Auke Kokcd94dd02006-06-27 09:08:22 -07004847 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004848 /* enable VLAN receive filtering */
Joe Perches1dc32912008-07-11 15:17:08 -07004849 rctl = er32(RCTL);
Auke Kok90fb5132006-11-01 08:47:30 -08004850 rctl &= ~E1000_RCTL_CFIEN;
Joe Perches1dc32912008-07-11 15:17:08 -07004851 ew32(RCTL, rctl);
Auke Kok90fb5132006-11-01 08:47:30 -08004852 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 } else {
4855 /* disable VLAN tag insert/strip */
Joe Perches1dc32912008-07-11 15:17:08 -07004856 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 ctrl &= ~E1000_CTRL_VME;
Joe Perches1dc32912008-07-11 15:17:08 -07004858 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859
Auke Kokcd94dd02006-06-27 09:08:22 -07004860 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004861 if (adapter->mng_vlan_id !=
Joe Perches406874a2008-04-03 10:06:32 -07004862 (u16)E1000_MNG_VLAN_NONE) {
Auke Kok90fb5132006-11-01 08:47:30 -08004863 e1000_vlan_rx_kill_vid(netdev,
4864 adapter->mng_vlan_id);
4865 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4866 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 }
4869
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004870 if (!test_bit(__E1000_DOWN, &adapter->flags))
4871 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872}
4873
Joe Perches64798842008-07-11 15:17:02 -07004874static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004876 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004877 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004878 u32 vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004879
Joe Perches1dc32912008-07-11 15:17:08 -07004880 if ((hw->mng_cookie.status &
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004881 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4882 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004883 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 /* add VID to filter table */
4885 index = (vid >> 5) & 0x7F;
Joe Perches1dc32912008-07-11 15:17:08 -07004886 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 vfta |= (1 << (vid & 0x1F));
Joe Perches1dc32912008-07-11 15:17:08 -07004888 e1000_write_vfta(hw, index, vfta);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889}
4890
Joe Perches64798842008-07-11 15:17:02 -07004891static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004893 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004894 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004895 u32 vfta, index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004897 if (!test_bit(__E1000_DOWN, &adapter->flags))
4898 e1000_irq_disable(adapter);
Dan Aloni5c15bde2007-03-02 20:44:51 -08004899 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004900 if (!test_bit(__E1000_DOWN, &adapter->flags))
4901 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902
Joe Perches1dc32912008-07-11 15:17:08 -07004903 if ((hw->mng_cookie.status &
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004904 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004905 (vid == adapter->mng_vlan_id)) {
4906 /* release control to f/w */
4907 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004908 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004909 }
4910
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 /* remove VID from filter table */
4912 index = (vid >> 5) & 0x7F;
Joe Perches1dc32912008-07-11 15:17:08 -07004913 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914 vfta &= ~(1 << (vid & 0x1F));
Joe Perches1dc32912008-07-11 15:17:08 -07004915 e1000_write_vfta(hw, index, vfta);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916}
4917
Joe Perches64798842008-07-11 15:17:02 -07004918static void e1000_restore_vlan(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919{
4920 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4921
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004922 if (adapter->vlgrp) {
Joe Perches406874a2008-04-03 10:06:32 -07004923 u16 vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004924 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08004925 if (!vlan_group_get_device(adapter->vlgrp, vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926 continue;
4927 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4928 }
4929 }
4930}
4931
Joe Perches64798842008-07-11 15:17:02 -07004932int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933{
Joe Perches1dc32912008-07-11 15:17:08 -07004934 struct e1000_hw *hw = &adapter->hw;
4935
4936 hw->autoneg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937
Malli Chilakala69213682005-06-17 17:44:20 -07004938 /* Fiber NICs only allow 1000 gbps Full duplex */
Joe Perches1dc32912008-07-11 15:17:08 -07004939 if ((hw->media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004940 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4941 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4942 return -EINVAL;
4943 }
4944
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004945 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946 case SPEED_10 + DUPLEX_HALF:
Joe Perches1dc32912008-07-11 15:17:08 -07004947 hw->forced_speed_duplex = e1000_10_half;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948 break;
4949 case SPEED_10 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07004950 hw->forced_speed_duplex = e1000_10_full;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 break;
4952 case SPEED_100 + DUPLEX_HALF:
Joe Perches1dc32912008-07-11 15:17:08 -07004953 hw->forced_speed_duplex = e1000_100_half;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 break;
4955 case SPEED_100 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07004956 hw->forced_speed_duplex = e1000_100_full;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 break;
4958 case SPEED_1000 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07004959 hw->autoneg = 1;
4960 hw->autoneg_advertised = ADVERTISE_1000_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961 break;
4962 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4963 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004964 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965 return -EINVAL;
4966 }
4967 return 0;
4968}
4969
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00004970static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971{
4972 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004973 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004974 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004975 u32 ctrl, ctrl_ext, rctl, status;
4976 u32 wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07004977#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08004978 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07004979#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980
4981 netif_device_detach(netdev);
4982
Auke Kok2db10a02006-06-27 09:06:28 -07004983 if (netif_running(netdev)) {
4984 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07004986 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004988#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08004989 retval = pci_save_state(pdev);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004990 if (retval)
4991 return retval;
4992#endif
4993
Joe Perches1dc32912008-07-11 15:17:08 -07004994 status = er32(STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004995 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996 wufc &= ~E1000_WUFC_LNKC;
4997
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004998 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005000 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001
5002 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005003 if (wufc & E1000_WUFC_MC) {
Joe Perches1dc32912008-07-11 15:17:08 -07005004 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005 rctl |= E1000_RCTL_MPE;
Joe Perches1dc32912008-07-11 15:17:08 -07005006 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 }
5008
Joe Perches1dc32912008-07-11 15:17:08 -07005009 if (hw->mac_type >= e1000_82540) {
5010 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 /* advertise wake from D3Cold */
5012 #define E1000_CTRL_ADVD3WUC 0x00100000
5013 /* phy power management enable */
5014 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5015 ctrl |= E1000_CTRL_ADVD3WUC |
5016 E1000_CTRL_EN_PHY_PWR_MGMT;
Joe Perches1dc32912008-07-11 15:17:08 -07005017 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 }
5019
Joe Perches1dc32912008-07-11 15:17:08 -07005020 if (hw->media_type == e1000_media_type_fiber ||
5021 hw->media_type == e1000_media_type_internal_serdes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022 /* keep the laser running in D3 */
Joe Perches1dc32912008-07-11 15:17:08 -07005023 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07005025 ew32(CTRL_EXT, ctrl_ext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026 }
5027
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005028 /* Allow time for pending master requests to run */
Joe Perches1dc32912008-07-11 15:17:08 -07005029 e1000_disable_pciex_master(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005030
Joe Perches1dc32912008-07-11 15:17:08 -07005031 ew32(WUC, E1000_WUC_PME_EN);
5032 ew32(WUFC, wufc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07005034 ew32(WUC, 0);
5035 ew32(WUFC, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036 }
5037
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005038 e1000_release_manageability(adapter);
5039
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005040 *enable_wake = !!wufc;
5041
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005042 /* make sure adapter isn't asleep if manageability is enabled */
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005043 if (adapter->en_mng_pt)
5044 *enable_wake = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045
Joe Perches1dc32912008-07-11 15:17:08 -07005046 if (hw->phy_type == e1000_phy_igp_3)
5047 e1000_phy_powerdown_workaround(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005048
Auke Kokedd106f2006-11-06 08:57:12 -08005049 if (netif_running(netdev))
5050 e1000_free_irq(adapter);
5051
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005052 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5053 * would have already happened in close and is redundant. */
5054 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005055
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005057
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 return 0;
5059}
5060
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005061#ifdef CONFIG_PM
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005062static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5063{
5064 int retval;
5065 bool wake;
5066
5067 retval = __e1000_shutdown(pdev, &wake);
5068 if (retval)
5069 return retval;
5070
5071 if (wake) {
5072 pci_prepare_to_sleep(pdev);
5073 } else {
5074 pci_wake_from_d3(pdev, false);
5075 pci_set_power_state(pdev, PCI_D3hot);
5076 }
5077
5078 return 0;
5079}
5080
Joe Perches64798842008-07-11 15:17:02 -07005081static int e1000_resume(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082{
5083 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005084 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005085 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07005086 u32 err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087
Auke Kokd0e027d2006-04-14 19:04:40 -07005088 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005089 pci_restore_state(pdev);
Taku Izumi81250292008-07-11 15:17:44 -07005090
5091 if (adapter->need_ioport)
5092 err = pci_enable_device(pdev);
5093 else
5094 err = pci_enable_device_mem(pdev);
Joe Perchesc7be73b2008-07-11 15:17:28 -07005095 if (err) {
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005096 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5097 return err;
5098 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005099 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100
Auke Kokd0e027d2006-04-14 19:04:40 -07005101 pci_enable_wake(pdev, PCI_D3hot, 0);
5102 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103
Joe Perchesc7be73b2008-07-11 15:17:28 -07005104 if (netif_running(netdev)) {
5105 err = e1000_request_irq(adapter);
5106 if (err)
5107 return err;
5108 }
Auke Kokedd106f2006-11-06 08:57:12 -08005109
5110 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111 e1000_reset(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07005112 ew32(WUS, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005114 e1000_init_manageability(adapter);
5115
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005116 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 e1000_up(adapter);
5118
5119 netif_device_attach(netdev);
5120
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005121 /* If the controller is 82573 and f/w is AMT, do not set
5122 * DRV_LOAD until the interface is up. For all other cases,
5123 * let the f/w know that the h/w is now under the control
5124 * of the driver. */
Joe Perches1dc32912008-07-11 15:17:08 -07005125 if (hw->mac_type != e1000_82573 ||
5126 !e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005127 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005128
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129 return 0;
5130}
5131#endif
Auke Kokc653e632006-05-23 13:35:57 -07005132
5133static void e1000_shutdown(struct pci_dev *pdev)
5134{
Rafael J. Wysockib43fcd72009-04-15 17:43:24 +00005135 bool wake;
5136
5137 __e1000_shutdown(pdev, &wake);
5138
5139 if (system_state == SYSTEM_POWER_OFF) {
5140 pci_wake_from_d3(pdev, wake);
5141 pci_set_power_state(pdev, PCI_D3hot);
5142 }
Auke Kokc653e632006-05-23 13:35:57 -07005143}
5144
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145#ifdef CONFIG_NET_POLL_CONTROLLER
5146/*
5147 * Polling 'interrupt' - used by things like netconsole to send skbs
5148 * without having to re-enable interrupts. It's not called while
5149 * the interrupt routine is executing.
5150 */
Joe Perches64798842008-07-11 15:17:02 -07005151static void e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005153 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005154
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005156 e1000_intr(adapter->pdev->irq, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 enable_irq(adapter->pdev->irq);
5158}
5159#endif
5160
Auke Kok90267292006-06-08 09:30:24 -07005161/**
5162 * e1000_io_error_detected - called when PCI error is detected
5163 * @pdev: Pointer to PCI device
5164 * @state: The current pci conneection state
5165 *
5166 * This function is called after a PCI bus error affecting
5167 * this device has been detected.
5168 */
Joe Perches64798842008-07-11 15:17:02 -07005169static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5170 pci_channel_state_t state)
Auke Kok90267292006-06-08 09:30:24 -07005171{
5172 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen4cf16532008-11-12 23:38:14 -08005173 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok90267292006-06-08 09:30:24 -07005174
5175 netif_device_detach(netdev);
5176
Andre Detscheab63302009-06-30 12:46:13 +00005177 if (state == pci_channel_io_perm_failure)
5178 return PCI_ERS_RESULT_DISCONNECT;
5179
Auke Kok90267292006-06-08 09:30:24 -07005180 if (netif_running(netdev))
5181 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005182 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005183
5184 /* Request a slot slot reset. */
5185 return PCI_ERS_RESULT_NEED_RESET;
5186}
5187
5188/**
5189 * e1000_io_slot_reset - called after the pci bus has been reset.
5190 * @pdev: Pointer to PCI device
5191 *
5192 * Restart the card from scratch, as if from a cold-boot. Implementation
5193 * resembles the first-half of the e1000_resume routine.
5194 */
5195static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5196{
5197 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen4cf16532008-11-12 23:38:14 -08005198 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005199 struct e1000_hw *hw = &adapter->hw;
Taku Izumi81250292008-07-11 15:17:44 -07005200 int err;
Auke Kok90267292006-06-08 09:30:24 -07005201
Taku Izumi81250292008-07-11 15:17:44 -07005202 if (adapter->need_ioport)
5203 err = pci_enable_device(pdev);
5204 else
5205 err = pci_enable_device_mem(pdev);
5206 if (err) {
Auke Kok90267292006-06-08 09:30:24 -07005207 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5208 return PCI_ERS_RESULT_DISCONNECT;
5209 }
5210 pci_set_master(pdev);
5211
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005212 pci_enable_wake(pdev, PCI_D3hot, 0);
5213 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005214
Auke Kok90267292006-06-08 09:30:24 -07005215 e1000_reset(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07005216 ew32(WUS, ~0);
Auke Kok90267292006-06-08 09:30:24 -07005217
5218 return PCI_ERS_RESULT_RECOVERED;
5219}
5220
5221/**
5222 * e1000_io_resume - called when traffic can start flowing again.
5223 * @pdev: Pointer to PCI device
5224 *
5225 * This callback is called when the error recovery driver tells us that
5226 * its OK to resume normal operation. Implementation resembles the
5227 * second-half of the e1000_resume routine.
5228 */
5229static void e1000_io_resume(struct pci_dev *pdev)
5230{
5231 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen4cf16532008-11-12 23:38:14 -08005232 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005233 struct e1000_hw *hw = &adapter->hw;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005234
5235 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005236
5237 if (netif_running(netdev)) {
5238 if (e1000_up(adapter)) {
5239 printk("e1000: can't bring device back up after reset\n");
5240 return;
5241 }
5242 }
5243
5244 netif_device_attach(netdev);
5245
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005246 /* If the controller is 82573 and f/w is AMT, do not set
5247 * DRV_LOAD until the interface is up. For all other cases,
5248 * let the f/w know that the h/w is now under the control
5249 * of the driver. */
Joe Perches1dc32912008-07-11 15:17:08 -07005250 if (hw->mac_type != e1000_82573 ||
5251 !e1000_check_mng_mode(hw))
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005252 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005253
Auke Kok90267292006-06-08 09:30:24 -07005254}
5255
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256/* e1000_main.c */