blob: ad6da7b67e555023532134d64e6ac1efd326049f [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";
Francois Romieuc3570ac2008-07-11 15:17:38 -070034#define DRV_VERSION "7.3.20-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);
140static bool e1000_clean_rx_irq_ps(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,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800144 struct e1000_rx_ring *rx_ring,
145 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400146static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800147 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 Koke619d522006-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
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700165static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Auke Kok6fdfef12006-06-27 09:06:36 -0700166#ifdef CONFIG_PM
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 Chilakala24025e42005-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 Brandeburg79f3d392006-12-15 10:42:34 +0100507 /* fire a link change interrupt to start the watchdog */
Joe Perches1dc32912008-07-11 15:17:08 -0700508 ew32(ICS, E1000_ICS_LSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 return 0;
510}
511
Auke Kok79f05bf2006-06-27 09:06:32 -0700512/**
513 * e1000_power_up_phy - restore link in case the phy was powered down
514 * @adapter: address of board private structure
515 *
516 * The phy may be powered down to save power and turn off link when the
517 * driver is unloaded and wake on lan is not enabled (among others)
518 * *** this routine MUST be followed by a call to e1000_reset ***
519 *
520 **/
521
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700522void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700523{
Joe Perches1dc32912008-07-11 15:17:08 -0700524 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700525 u16 mii_reg = 0;
Auke Kok79f05bf2006-06-27 09:06:32 -0700526
527 /* Just clear the power down bit to wake the phy back up */
Joe Perches1dc32912008-07-11 15:17:08 -0700528 if (hw->media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700529 /* according to the manual, the phy will retain its
530 * settings across a power-down/up cycle */
Joe Perches1dc32912008-07-11 15:17:08 -0700531 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700532 mii_reg &= ~MII_CR_POWER_DOWN;
Joe Perches1dc32912008-07-11 15:17:08 -0700533 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700534 }
535}
536
537static void e1000_power_down_phy(struct e1000_adapter *adapter)
538{
Joe Perches1dc32912008-07-11 15:17:08 -0700539 struct e1000_hw *hw = &adapter->hw;
540
Bruce Allan61c25052006-09-27 12:53:54 -0700541 /* Power down the PHY so no link is implied when interface is down *
Joe Perchesc3033b02008-03-21 11:06:25 -0700542 * The PHY cannot be powered down if any of the following is true *
Auke Kok79f05bf2006-06-27 09:06:32 -0700543 * (a) WoL is enabled
544 * (b) AMT is active
545 * (c) SoL/IDER session is active */
Joe Perches1dc32912008-07-11 15:17:08 -0700546 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
547 hw->media_type == e1000_media_type_copper) {
Joe Perches406874a2008-04-03 10:06:32 -0700548 u16 mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700549
Joe Perches1dc32912008-07-11 15:17:08 -0700550 switch (hw->mac_type) {
Bruce Allan61c25052006-09-27 12:53:54 -0700551 case e1000_82540:
552 case e1000_82545:
553 case e1000_82545_rev_3:
554 case e1000_82546:
555 case e1000_82546_rev_3:
556 case e1000_82541:
557 case e1000_82541_rev_2:
558 case e1000_82547:
559 case e1000_82547_rev_2:
Joe Perches1dc32912008-07-11 15:17:08 -0700560 if (er32(MANC) & E1000_MANC_SMBUS_EN)
Bruce Allan61c25052006-09-27 12:53:54 -0700561 goto out;
562 break;
563 case e1000_82571:
564 case e1000_82572:
565 case e1000_82573:
566 case e1000_80003es2lan:
567 case e1000_ich8lan:
Joe Perches1dc32912008-07-11 15:17:08 -0700568 if (e1000_check_mng_mode(hw) ||
569 e1000_check_phy_reset_block(hw))
Bruce Allan61c25052006-09-27 12:53:54 -0700570 goto out;
571 break;
572 default:
573 goto out;
574 }
Joe Perches1dc32912008-07-11 15:17:08 -0700575 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700576 mii_reg |= MII_CR_POWER_DOWN;
Joe Perches1dc32912008-07-11 15:17:08 -0700577 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
Auke Kok79f05bf2006-06-27 09:06:32 -0700578 mdelay(1);
579 }
Bruce Allan61c25052006-09-27 12:53:54 -0700580out:
581 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700582}
583
Joe Perches64798842008-07-11 15:17:02 -0700584void e1000_down(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
586 struct net_device *netdev = adapter->netdev;
587
Auke Kok1314bbf2006-09-27 12:54:02 -0700588 /* signal that we're down so the interrupt handler does not
589 * reschedule our watchdog timer */
590 set_bit(__E1000_DOWN, &adapter->flags);
591
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700592 napi_disable(&adapter->napi);
Francois Romieuc3570ac2008-07-11 15:17:38 -0700593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 del_timer_sync(&adapter->tx_fifo_stall_timer);
597 del_timer_sync(&adapter->watchdog_timer);
598 del_timer_sync(&adapter->phy_info_timer);
599
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800600 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 adapter->link_speed = 0;
602 adapter->link_duplex = 0;
603 netif_carrier_off(netdev);
604 netif_stop_queue(netdev);
605
606 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400607 e1000_clean_all_tx_rings(adapter);
608 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Joe Perches64798842008-07-11 15:17:02 -0700611void e1000_reinit_locked(struct e1000_adapter *adapter)
Auke Kok2db10a02006-06-27 09:06:28 -0700612{
613 WARN_ON(in_interrupt());
614 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
615 msleep(1);
616 e1000_down(adapter);
617 e1000_up(adapter);
618 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
620
Joe Perches64798842008-07-11 15:17:02 -0700621void e1000_reset(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Joe Perches1dc32912008-07-11 15:17:08 -0700623 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700624 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
625 u16 fc_high_water_mark = E1000_FC_HIGH_DIFF;
Joe Perchesc3033b02008-03-21 11:06:25 -0700626 bool legacy_pba_adjust = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 /* Repartition Pba for greater than 9k mtu
629 * To take effect CTRL.RST is required.
630 */
631
Joe Perches1dc32912008-07-11 15:17:08 -0700632 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100633 case e1000_82542_rev2_0:
634 case e1000_82542_rev2_1:
635 case e1000_82543:
636 case e1000_82544:
637 case e1000_82540:
638 case e1000_82541:
639 case e1000_82541_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700640 legacy_pba_adjust = true;
Bruce Allan018ea442006-12-15 10:39:45 +0100641 pba = E1000_PBA_48K;
642 break;
643 case e1000_82545:
644 case e1000_82545_rev_3:
645 case e1000_82546:
646 case e1000_82546_rev_3:
647 pba = E1000_PBA_48K;
648 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700649 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700650 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700651 legacy_pba_adjust = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700652 pba = E1000_PBA_30K;
653 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400654 case e1000_82571:
655 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800656 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400657 pba = E1000_PBA_38K;
658 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700659 case e1000_82573:
Bruce Allan018ea442006-12-15 10:39:45 +0100660 pba = E1000_PBA_20K;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700661 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700662 case e1000_ich8lan:
663 pba = E1000_PBA_8K;
Bruce Allan018ea442006-12-15 10:39:45 +0100664 case e1000_undefined:
665 case e1000_num_macs:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700666 break;
667 }
668
Joe Perchesc3033b02008-03-21 11:06:25 -0700669 if (legacy_pba_adjust) {
Bruce Allan018ea442006-12-15 10:39:45 +0100670 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
671 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700672
Joe Perches1dc32912008-07-11 15:17:08 -0700673 if (hw->mac_type == e1000_82547) {
Bruce Allan018ea442006-12-15 10:39:45 +0100674 adapter->tx_fifo_head = 0;
675 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
676 adapter->tx_fifo_size =
677 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
678 atomic_set(&adapter->tx_fifo_stall, 0);
679 }
Joe Perches1dc32912008-07-11 15:17:08 -0700680 } else if (hw->max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
Bruce Allan018ea442006-12-15 10:39:45 +0100681 /* adjust PBA for jumbo frames */
Joe Perches1dc32912008-07-11 15:17:08 -0700682 ew32(PBA, pba);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700683
Bruce Allan018ea442006-12-15 10:39:45 +0100684 /* To maintain wire speed transmits, the Tx FIFO should be
685 * large enough to accomodate two full transmit packets,
686 * rounded up to the next 1KB and expressed in KB. Likewise,
687 * the Rx FIFO should be large enough to accomodate at least
688 * one full receive packet and is similarly rounded up and
689 * expressed in KB. */
Joe Perches1dc32912008-07-11 15:17:08 -0700690 pba = er32(PBA);
Bruce Allan018ea442006-12-15 10:39:45 +0100691 /* upper 16 bits has Tx packet buffer allocation size in KB */
692 tx_space = pba >> 16;
693 /* lower 16 bits has Rx packet buffer allocation size in KB */
694 pba &= 0xffff;
695 /* don't include ethernet FCS because hardware appends/strips */
696 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
697 VLAN_TAG_SIZE;
698 min_tx_space = min_rx_space;
699 min_tx_space *= 2;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700700 min_tx_space = ALIGN(min_tx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100701 min_tx_space >>= 10;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700702 min_rx_space = ALIGN(min_rx_space, 1024);
Bruce Allan018ea442006-12-15 10:39:45 +0100703 min_rx_space >>= 10;
704
705 /* If current Tx allocation is less than the min Tx FIFO size,
706 * and the min Tx FIFO size is less than the current Rx FIFO
707 * allocation, take space away from current Rx allocation */
708 if (tx_space < min_tx_space &&
709 ((min_tx_space - tx_space) < pba)) {
710 pba = pba - (min_tx_space - tx_space);
711
712 /* PCI/PCIx hardware has PBA alignment constraints */
Joe Perches1dc32912008-07-11 15:17:08 -0700713 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100714 case e1000_82545 ... e1000_82546_rev_3:
715 pba &= ~(E1000_PBA_8K - 1);
716 break;
717 default:
718 break;
719 }
720
721 /* if short on rx space, rx wins and must trump tx
722 * adjustment or use Early Receive if available */
723 if (pba < min_rx_space) {
Joe Perches1dc32912008-07-11 15:17:08 -0700724 switch (hw->mac_type) {
Bruce Allan018ea442006-12-15 10:39:45 +0100725 case e1000_82573:
726 /* ERT enabled in e1000_configure_rx */
727 break;
728 default:
729 pba = min_rx_space;
730 break;
731 }
732 }
733 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700735
Joe Perches1dc32912008-07-11 15:17:08 -0700736 ew32(PBA, pba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800739 /* Set the FC high water mark to 90% of the FIFO size.
740 * Required to clear last 3 LSB */
741 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700742 /* We can't use 90% on small FIFOs because the remainder
743 * would be less than 1 full frame. In this case, we size
744 * it to allow at least a full frame above the high water
745 * mark. */
746 if (pba < E1000_PBA_16K)
747 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800748
Joe Perches1dc32912008-07-11 15:17:08 -0700749 hw->fc_high_water = fc_high_water_mark;
750 hw->fc_low_water = fc_high_water_mark - 8;
751 if (hw->mac_type == e1000_80003es2lan)
752 hw->fc_pause_time = 0xFFFF;
Jeff Kirsher87041632006-03-02 18:21:24 -0800753 else
Joe Perches1dc32912008-07-11 15:17:08 -0700754 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
755 hw->fc_send_xon = 1;
756 hw->fc = hw->original_fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700758 /* Allow time for pending master requests to run */
Joe Perches1dc32912008-07-11 15:17:08 -0700759 e1000_reset_hw(hw);
760 if (hw->mac_type >= e1000_82544)
761 ew32(WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700762
Joe Perches1dc32912008-07-11 15:17:08 -0700763 if (e1000_init_hw(hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700765 e1000_update_mng_vlan(adapter);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100766
767 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
Joe Perches1dc32912008-07-11 15:17:08 -0700768 if (hw->mac_type >= e1000_82544 &&
769 hw->mac_type <= e1000_82547_rev_2 &&
770 hw->autoneg == 1 &&
771 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
772 u32 ctrl = er32(CTRL);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100773 /* clear phy power management bit if we are in gig only mode,
774 * which if enabled will attempt negotiation to 100Mb, which
775 * can cause a loss of link at power off or driver unload */
776 ctrl &= ~E1000_CTRL_SWDPIN3;
Joe Perches1dc32912008-07-11 15:17:08 -0700777 ew32(CTRL, ctrl);
Jesse Brandeburg3d5460a2006-12-15 10:33:46 +0100778 }
779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
Joe Perches1dc32912008-07-11 15:17:08 -0700781 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Joe Perches1dc32912008-07-11 15:17:08 -0700783 e1000_reset_adaptive(hw);
784 e1000_phy_get_info(hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700785
786 if (!adapter->smart_power_down &&
Joe Perches1dc32912008-07-11 15:17:08 -0700787 (hw->mac_type == e1000_82571 ||
788 hw->mac_type == e1000_82572)) {
Joe Perches406874a2008-04-03 10:06:32 -0700789 u16 phy_data = 0;
Auke Kok9a53a202006-06-27 09:06:45 -0700790 /* speed up time to link by disabling smart power down, ignore
791 * the return value of this function because there is nothing
792 * different we would do if it failed */
Joe Perches1dc32912008-07-11 15:17:08 -0700793 e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9a53a202006-06-27 09:06:45 -0700794 &phy_data);
795 phy_data &= ~IGP02E1000_PM_SPD;
Joe Perches1dc32912008-07-11 15:17:08 -0700796 e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9a53a202006-06-27 09:06:45 -0700797 phy_data);
798 }
799
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500800 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801}
802
803/**
Auke Kok67b3c272007-12-17 13:50:23 -0800804 * Dump the eeprom for users having checksum issues
805 **/
Adrian Bunkb4ea8952008-02-01 08:21:28 -0800806static void e1000_dump_eeprom(struct e1000_adapter *adapter)
Auke Kok67b3c272007-12-17 13:50:23 -0800807{
808 struct net_device *netdev = adapter->netdev;
809 struct ethtool_eeprom eeprom;
810 const struct ethtool_ops *ops = netdev->ethtool_ops;
811 u8 *data;
812 int i;
813 u16 csum_old, csum_new = 0;
814
815 eeprom.len = ops->get_eeprom_len(netdev);
816 eeprom.offset = 0;
817
818 data = kmalloc(eeprom.len, GFP_KERNEL);
819 if (!data) {
820 printk(KERN_ERR "Unable to allocate memory to dump EEPROM"
821 " data\n");
822 return;
823 }
824
825 ops->get_eeprom(netdev, &eeprom, data);
826
827 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
828 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
829 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
830 csum_new += data[i] + (data[i + 1] << 8);
831 csum_new = EEPROM_SUM - csum_new;
832
833 printk(KERN_ERR "/*********************/\n");
834 printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old);
835 printk(KERN_ERR "Calculated : 0x%04x\n", csum_new);
836
837 printk(KERN_ERR "Offset Values\n");
838 printk(KERN_ERR "======== ======\n");
839 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
840
841 printk(KERN_ERR "Include this output when contacting your support "
842 "provider.\n");
843 printk(KERN_ERR "This is not a software error! Something bad "
844 "happened to your hardware or\n");
845 printk(KERN_ERR "EEPROM image. Ignoring this "
846 "problem could result in further problems,\n");
847 printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n");
848 printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, "
849 "which is invalid\n");
850 printk(KERN_ERR "and requires you to set the proper MAC "
851 "address manually before continuing\n");
852 printk(KERN_ERR "to enable this network device.\n");
853 printk(KERN_ERR "Please inspect the EEPROM dump and report the issue "
854 "to your hardware vendor\n");
Jeff Kirsher63cd31f2008-07-11 15:17:33 -0700855 printk(KERN_ERR "or Intel Customer Support.\n");
Auke Kok67b3c272007-12-17 13:50:23 -0800856 printk(KERN_ERR "/*********************/\n");
857
858 kfree(data);
859}
860
861/**
Taku Izumi81250292008-07-11 15:17:44 -0700862 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
863 * @pdev: PCI device information struct
864 *
865 * Return true if an adapter needs ioport resources
866 **/
867static int e1000_is_need_ioport(struct pci_dev *pdev)
868{
869 switch (pdev->device) {
870 case E1000_DEV_ID_82540EM:
871 case E1000_DEV_ID_82540EM_LOM:
872 case E1000_DEV_ID_82540EP:
873 case E1000_DEV_ID_82540EP_LOM:
874 case E1000_DEV_ID_82540EP_LP:
875 case E1000_DEV_ID_82541EI:
876 case E1000_DEV_ID_82541EI_MOBILE:
877 case E1000_DEV_ID_82541ER:
878 case E1000_DEV_ID_82541ER_LOM:
879 case E1000_DEV_ID_82541GI:
880 case E1000_DEV_ID_82541GI_LF:
881 case E1000_DEV_ID_82541GI_MOBILE:
882 case E1000_DEV_ID_82544EI_COPPER:
883 case E1000_DEV_ID_82544EI_FIBER:
884 case E1000_DEV_ID_82544GC_COPPER:
885 case E1000_DEV_ID_82544GC_LOM:
886 case E1000_DEV_ID_82545EM_COPPER:
887 case E1000_DEV_ID_82545EM_FIBER:
888 case E1000_DEV_ID_82546EB_COPPER:
889 case E1000_DEV_ID_82546EB_FIBER:
890 case E1000_DEV_ID_82546EB_QUAD_COPPER:
891 return true;
892 default:
893 return false;
894 }
895}
896
897/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 * e1000_probe - Device Initialization Routine
899 * @pdev: PCI device information struct
900 * @ent: entry in e1000_pci_tbl
901 *
902 * Returns 0 on success, negative on failure
903 *
904 * e1000_probe initializes an adapter identified by a pci_dev structure.
905 * The OS initialization, configuring of the adapter private structure,
906 * and a hardware reset occur.
907 **/
Joe Perches1dc32912008-07-11 15:17:08 -0700908static int __devinit e1000_probe(struct pci_dev *pdev,
909 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
911 struct net_device *netdev;
912 struct e1000_adapter *adapter;
Joe Perches1dc32912008-07-11 15:17:08 -0700913 struct e1000_hw *hw;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700916 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700917 int i, err, pci_using_dac;
Joe Perches406874a2008-04-03 10:06:32 -0700918 u16 eeprom_data = 0;
919 u16 eeprom_apme_mask = E1000_EEPROM_APME;
Taku Izumi81250292008-07-11 15:17:44 -0700920 int bars, need_ioport;
Joe Perches0795af52007-10-03 17:59:30 -0700921 DECLARE_MAC_BUF(mac);
922
Taku Izumi81250292008-07-11 15:17:44 -0700923 /* do not allocate ioport bars when not needed */
924 need_ioport = e1000_is_need_ioport(pdev);
925 if (need_ioport) {
926 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
927 err = pci_enable_device(pdev);
928 } else {
929 bars = pci_select_bars(pdev, IORESOURCE_MEM);
930 err = pci_enable_device(pdev);
931 }
Joe Perchesc7be73b2008-07-11 15:17:28 -0700932 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 return err;
934
Joe Perchesc7be73b2008-07-11 15:17:28 -0700935 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
936 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 pci_using_dac = 1;
938 } else {
Joe Perchesc7be73b2008-07-11 15:17:28 -0700939 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
940 if (err) {
941 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
942 if (err) {
943 E1000_ERR("No usable DMA configuration, "
944 "aborting\n");
945 goto err_dma;
946 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948 pci_using_dac = 0;
949 }
950
Taku Izumi81250292008-07-11 15:17:44 -0700951 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
Joe Perchesc7be73b2008-07-11 15:17:28 -0700952 if (err)
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700953 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 pci_set_master(pdev);
956
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700957 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700959 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 SET_NETDEV_DEV(netdev, &pdev->dev);
963
964 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700965 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 adapter->netdev = netdev;
967 adapter->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 adapter->msg_enable = (1 << debug) - 1;
Taku Izumi81250292008-07-11 15:17:44 -0700969 adapter->bars = bars;
970 adapter->need_ioport = need_ioport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Joe Perches1dc32912008-07-11 15:17:08 -0700972 hw = &adapter->hw;
973 hw->back = adapter;
974
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700975 err = -EIO;
Joe Perches1dc32912008-07-11 15:17:08 -0700976 hw->hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
977 pci_resource_len(pdev, BAR_0));
978 if (!hw->hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Taku Izumi81250292008-07-11 15:17:44 -0700981 if (adapter->need_ioport) {
982 for (i = BAR_1; i <= BAR_5; i++) {
983 if (pci_resource_len(pdev, i) == 0)
984 continue;
985 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
986 hw->io_base = pci_resource_start(pdev, i);
987 break;
988 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 }
990 }
991
992 netdev->open = &e1000_open;
993 netdev->stop = &e1000_close;
994 netdev->hard_start_xmit = &e1000_xmit_frame;
995 netdev->get_stats = &e1000_get_stats;
Patrick McHardydb0ce502007-11-13 20:54:59 -0800996 netdev->set_rx_mode = &e1000_set_rx_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 netdev->set_mac_address = &e1000_set_mac;
998 netdev->change_mtu = &e1000_change_mtu;
999 netdev->do_ioctl = &e1000_ioctl;
1000 e1000_set_ethtool_ops(netdev);
1001 netdev->tx_timeout = &e1000_tx_timeout;
1002 netdev->watchdog_timeo = 5 * HZ;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001003 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 netdev->vlan_rx_register = e1000_vlan_rx_register;
1005 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
1006 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
1007#ifdef CONFIG_NET_POLL_CONTROLLER
1008 netdev->poll_controller = e1000_netpoll;
1009#endif
Auke Kok0eb5a342006-09-27 12:53:17 -07001010 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 adapter->bd_number = cards_found;
1013
1014 /* setup the private structure */
1015
Joe Perchesc7be73b2008-07-11 15:17:28 -07001016 err = e1000_sw_init(adapter);
1017 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 goto err_sw_init;
1019
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001020 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -07001021 /* Flash BAR mapping must happen after e1000_sw_init
1022 * because it depends on mac_type */
Joe Perches1dc32912008-07-11 15:17:08 -07001023 if ((hw->mac_type == e1000_ich8lan) &&
Auke Kokcd94dd02006-06-27 09:08:22 -07001024 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
Joe Perches1dc32912008-07-11 15:17:08 -07001025 hw->flash_address =
Benjamin Herrenschmidt3c34ac32007-11-16 18:37:38 +11001026 ioremap(pci_resource_start(pdev, 1),
1027 pci_resource_len(pdev, 1));
Joe Perches1dc32912008-07-11 15:17:08 -07001028 if (!hw->flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -07001029 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -07001030 }
1031
Joe Perches1dc32912008-07-11 15:17:08 -07001032 if (e1000_check_phy_reset_block(hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001033 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
1034
Joe Perches1dc32912008-07-11 15:17:08 -07001035 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 netdev->features = NETIF_F_SG |
1037 NETIF_F_HW_CSUM |
1038 NETIF_F_HW_VLAN_TX |
1039 NETIF_F_HW_VLAN_RX |
1040 NETIF_F_HW_VLAN_FILTER;
Joe Perches1dc32912008-07-11 15:17:08 -07001041 if (hw->mac_type == e1000_ich8lan)
Auke Kokcd94dd02006-06-27 09:08:22 -07001042 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 }
1044
Joe Perches1dc32912008-07-11 15:17:08 -07001045 if ((hw->mac_type >= e1000_82544) &&
1046 (hw->mac_type != e1000_82547))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001048
Joe Perches1dc32912008-07-11 15:17:08 -07001049 if (hw->mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -08001050 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001051 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 netdev->features |= NETIF_F_HIGHDMA;
1053
Auke Kok76c224b2006-05-23 13:36:06 -07001054 netdev->features |= NETIF_F_LLTX;
1055
Joe Perches1dc32912008-07-11 15:17:08 -07001056 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001057
Auke Kokcd94dd02006-06-27 09:08:22 -07001058 /* initialize eeprom parameters */
Joe Perches1dc32912008-07-11 15:17:08 -07001059 if (e1000_init_eeprom_params(hw)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001060 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001061 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -07001062 }
1063
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001064 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001066
Joe Perches1dc32912008-07-11 15:17:08 -07001067 e1000_reset_hw(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069 /* make sure the EEPROM is good */
Joe Perches1dc32912008-07-11 15:17:08 -07001070 if (e1000_validate_eeprom_checksum(hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Auke Kok67b3c272007-12-17 13:50:23 -08001072 e1000_dump_eeprom(adapter);
1073 /*
1074 * set MAC address to all zeroes to invalidate and temporary
1075 * disable this device for the user. This blocks regular
1076 * traffic while still permitting ethtool ioctls from reaching
1077 * the hardware as well as allowing the user to run the
1078 * interface after manually setting a hw addr using
1079 * `ip set address`
1080 */
Joe Perches1dc32912008-07-11 15:17:08 -07001081 memset(hw->mac_addr, 0, netdev->addr_len);
Auke Kok67b3c272007-12-17 13:50:23 -08001082 } else {
1083 /* copy the MAC address out of the EEPROM */
Joe Perches1dc32912008-07-11 15:17:08 -07001084 if (e1000_read_mac_addr(hw))
Auke Kok67b3c272007-12-17 13:50:23 -08001085 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 }
Auke Kok67b3c272007-12-17 13:50:23 -08001087 /* don't block initalization here due to bad MAC address */
Joe Perches1dc32912008-07-11 15:17:08 -07001088 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1089 memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Auke Kok67b3c272007-12-17 13:50:23 -08001091 if (!is_valid_ether_addr(netdev->perm_addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Joe Perches1dc32912008-07-11 15:17:08 -07001094 e1000_get_bus_info(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 init_timer(&adapter->tx_fifo_stall_timer);
1097 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
Joe Perchese982f172008-07-11 15:17:18 -07001098 adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 init_timer(&adapter->watchdog_timer);
1101 adapter->watchdog_timer.function = &e1000_watchdog;
1102 adapter->watchdog_timer.data = (unsigned long) adapter;
1103
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 init_timer(&adapter->phy_info_timer);
1105 adapter->phy_info_timer.function = &e1000_update_phy_info;
Joe Perchese982f172008-07-11 15:17:18 -07001106 adapter->phy_info_timer.data = (unsigned long)adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
David Howells65f27f32006-11-22 14:55:48 +00001108 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 e1000_check_options(adapter);
1111
1112 /* Initial Wake on LAN setting
1113 * If APM wake is enabled in the EEPROM,
1114 * enable the ACPI Magic Packet filter
1115 */
1116
Joe Perches1dc32912008-07-11 15:17:08 -07001117 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 case e1000_82542_rev2_0:
1119 case e1000_82542_rev2_1:
1120 case e1000_82543:
1121 break;
1122 case e1000_82544:
Joe Perches1dc32912008-07-11 15:17:08 -07001123 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1125 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1126 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07001127 case e1000_ich8lan:
Joe Perches1dc32912008-07-11 15:17:08 -07001128 e1000_read_eeprom(hw,
Auke Kokcd94dd02006-06-27 09:08:22 -07001129 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
1130 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
1131 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 case e1000_82546:
1133 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001134 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001135 case e1000_80003es2lan:
Joe Perches1dc32912008-07-11 15:17:08 -07001136 if (er32(STATUS) & E1000_STATUS_FUNC_1){
1137 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1139 break;
1140 }
1141 /* Fall Through */
1142 default:
Joe Perches1dc32912008-07-11 15:17:08 -07001143 e1000_read_eeprom(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1145 break;
1146 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001147 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001148 adapter->eeprom_wol |= E1000_WUFC_MAG;
1149
1150 /* now that we have the eeprom settings, apply the special cases
1151 * where the eeprom may be wrong or the board simply won't support
1152 * wake on lan on a particular port */
1153 switch (pdev->device) {
1154 case E1000_DEV_ID_82546GB_PCIE:
1155 adapter->eeprom_wol = 0;
1156 break;
1157 case E1000_DEV_ID_82546EB_FIBER:
1158 case E1000_DEV_ID_82546GB_FIBER:
1159 case E1000_DEV_ID_82571EB_FIBER:
1160 /* Wake events only supported on port A for dual fiber
1161 * regardless of eeprom setting */
Joe Perches1dc32912008-07-11 15:17:08 -07001162 if (er32(STATUS) & E1000_STATUS_FUNC_1)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001163 adapter->eeprom_wol = 0;
1164 break;
1165 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001166 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001167 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001168 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001169 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001170 /* if quad port adapter, disable WoL on all but port A */
1171 if (global_quad_port_a != 0)
1172 adapter->eeprom_wol = 0;
1173 else
1174 adapter->quad_port_a = 1;
1175 /* Reset for multiple quad port adapters */
1176 if (++global_quad_port_a == 4)
1177 global_quad_port_a = 0;
1178 break;
1179 }
1180
1181 /* initialize the wol settings based on the eeprom settings */
1182 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001184 /* print bus type/speed/width info */
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001185 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
1186 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1187 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1188 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1189 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1190 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1191 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1192 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1193 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1194 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1195 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1196 "32-bit"));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001197
Joe Perches0795af52007-10-03 17:59:30 -07001198 printk("%s\n", print_mac(mac, netdev->dev_addr));
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -08001199
Joe Perches1dc32912008-07-11 15:17:08 -07001200 if (hw->bus_type == e1000_bus_type_pci_express) {
Auke Kok14782ca2008-02-11 09:25:46 -08001201 DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no "
1202 "longer be supported by this driver in the future.\n",
1203 pdev->vendor, pdev->device);
1204 DPRINTK(PROBE, WARNING, "please use the \"e1000e\" "
1205 "driver instead.\n");
1206 }
1207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 /* reset the hardware with the new settings */
1209 e1000_reset(adapter);
1210
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001211 /* If the controller is 82573 and f/w is AMT, do not set
1212 * DRV_LOAD until the interface is up. For all other cases,
1213 * let the f/w know that the h/w is now under the control
1214 * of the driver. */
Joe Perches1dc32912008-07-11 15:17:08 -07001215 if (hw->mac_type != e1000_82573 ||
1216 !e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001217 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001218
Auke Kok1314bbf2006-09-27 12:54:02 -07001219 /* tell the stack to leave us alone until e1000_open() is called */
1220 netif_carrier_off(netdev);
1221 netif_stop_queue(netdev);
Auke Kok416b5d12007-06-01 10:22:39 -07001222
1223 strcpy(netdev->name, "eth%d");
Joe Perchesc7be73b2008-07-11 15:17:28 -07001224 err = register_netdev(netdev);
1225 if (err)
Auke Kok416b5d12007-06-01 10:22:39 -07001226 goto err_register;
Auke Kok1314bbf2006-09-27 12:54:02 -07001227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1229
1230 cards_found++;
1231 return 0;
1232
1233err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001234 e1000_release_hw_control(adapter);
1235err_eeprom:
Joe Perches1dc32912008-07-11 15:17:08 -07001236 if (!e1000_check_phy_reset_block(hw))
1237 e1000_phy_hw_reset(hw);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001238
Joe Perches1dc32912008-07-11 15:17:08 -07001239 if (hw->flash_address)
1240 iounmap(hw->flash_address);
Auke Kokcd94dd02006-06-27 09:08:22 -07001241err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001242 for (i = 0; i < adapter->num_rx_queues; i++)
1243 dev_put(&adapter->polling_netdev[i]);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001244
1245 kfree(adapter->tx_ring);
1246 kfree(adapter->rx_ring);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001247 kfree(adapter->polling_netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248err_sw_init:
Joe Perches1dc32912008-07-11 15:17:08 -07001249 iounmap(hw->hw_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250err_ioremap:
1251 free_netdev(netdev);
1252err_alloc_etherdev:
Taku Izumi81250292008-07-11 15:17:44 -07001253 pci_release_selected_regions(pdev, bars);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001254err_pci_reg:
1255err_dma:
1256 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 return err;
1258}
1259
1260/**
1261 * e1000_remove - Device Removal Routine
1262 * @pdev: PCI device information struct
1263 *
1264 * e1000_remove is called by the PCI subsystem to alert the driver
1265 * that it should release a PCI device. The could be caused by a
1266 * Hot-Plug event, or because the driver is going to be removed from
1267 * memory.
1268 **/
1269
Joe Perches64798842008-07-11 15:17:02 -07001270static void __devexit e1000_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
1272 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001273 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001274 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001275 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Oleg Nesterov28e53bd2007-05-09 02:34:22 -07001277 cancel_work_sync(&adapter->reset_task);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001278
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05001279 e1000_release_manageability(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001281 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1282 * would have already happened in close and is redundant. */
1283 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001284
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001285 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001286 dev_put(&adapter->polling_netdev[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001288 unregister_netdev(netdev);
1289
Joe Perches1dc32912008-07-11 15:17:08 -07001290 if (!e1000_check_phy_reset_block(hw))
1291 e1000_phy_hw_reset(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001293 kfree(adapter->tx_ring);
1294 kfree(adapter->rx_ring);
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001295 kfree(adapter->polling_netdev);
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001296
Joe Perches1dc32912008-07-11 15:17:08 -07001297 iounmap(hw->hw_addr);
1298 if (hw->flash_address)
1299 iounmap(hw->flash_address);
Taku Izumi81250292008-07-11 15:17:44 -07001300 pci_release_selected_regions(pdev, adapter->bars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
1302 free_netdev(netdev);
1303
1304 pci_disable_device(pdev);
1305}
1306
1307/**
1308 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1309 * @adapter: board private structure to initialize
1310 *
1311 * e1000_sw_init initializes the Adapter private data structure.
1312 * Fields are initialized based on PCI device information and
1313 * OS network device settings (MTU size).
1314 **/
1315
Joe Perches64798842008-07-11 15:17:02 -07001316static int __devinit e1000_sw_init(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317{
1318 struct e1000_hw *hw = &adapter->hw;
1319 struct net_device *netdev = adapter->netdev;
1320 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001321 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 /* PCI config space info */
1324
1325 hw->vendor_id = pdev->vendor;
1326 hw->device_id = pdev->device;
1327 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1328 hw->subsystem_id = pdev->subsystem_device;
Auke Kok44c10132007-06-08 15:46:36 -07001329 hw->revision_id = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1332
Auke Kokeb0f8052006-07-14 16:14:48 -07001333 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001334 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 hw->max_frame_size = netdev->mtu +
1336 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1337 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1338
1339 /* identify the MAC */
1340
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001341 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1343 return -EIO;
1344 }
1345
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001346 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 default:
1348 break;
1349 case e1000_82541:
1350 case e1000_82547:
1351 case e1000_82541_rev_2:
1352 case e1000_82547_rev_2:
1353 hw->phy_init_script = 1;
1354 break;
1355 }
1356
1357 e1000_set_media_type(hw);
1358
Joe Perchesc3033b02008-03-21 11:06:25 -07001359 hw->wait_autoneg_complete = false;
1360 hw->tbi_compatibility_en = true;
1361 hw->adaptive_ifs = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
1363 /* Copper options */
1364
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001365 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 hw->mdix = AUTO_ALL_MODES;
Joe Perchesc3033b02008-03-21 11:06:25 -07001367 hw->disable_polarity_correction = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 hw->master_slave = E1000_MASTER_SLAVE;
1369 }
1370
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001371 adapter->num_tx_queues = 1;
1372 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001373
1374 if (e1000_alloc_queues(adapter)) {
1375 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1376 return -ENOMEM;
1377 }
1378
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001379 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001380 adapter->polling_netdev[i].priv = adapter;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001381 dev_hold(&adapter->polling_netdev[i]);
1382 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1383 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001384 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001385
Herbert Xu47313052007-05-29 15:07:31 -07001386 /* Explicitly disable IRQ since the NIC can be in any state. */
Herbert Xu47313052007-05-29 15:07:31 -07001387 e1000_irq_disable(adapter);
1388
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Auke Kok1314bbf2006-09-27 12:54:02 -07001391 set_bit(__E1000_DOWN, &adapter->flags);
1392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 return 0;
1394}
1395
1396/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001397 * e1000_alloc_queues - Allocate memory for all rings
1398 * @adapter: board private structure to initialize
1399 *
1400 * We allocate one ring per queue at run-time since we don't know the
1401 * number of queues at compile-time. The polling_netdev array is
1402 * intended for Multiqueue, but should work fine with a single queue.
1403 **/
1404
Joe Perches64798842008-07-11 15:17:02 -07001405static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001406{
Yan Burman1c7e5b12007-03-06 08:58:04 -08001407 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1408 sizeof(struct e1000_tx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001409 if (!adapter->tx_ring)
1410 return -ENOMEM;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001411
Yan Burman1c7e5b12007-03-06 08:58:04 -08001412 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1413 sizeof(struct e1000_rx_ring), GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001414 if (!adapter->rx_ring) {
1415 kfree(adapter->tx_ring);
1416 return -ENOMEM;
1417 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001418
Yan Burman1c7e5b12007-03-06 08:58:04 -08001419 adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
1420 sizeof(struct net_device),
1421 GFP_KERNEL);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001422 if (!adapter->polling_netdev) {
1423 kfree(adapter->tx_ring);
1424 kfree(adapter->rx_ring);
1425 return -ENOMEM;
1426 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001427
1428 return E1000_SUCCESS;
1429}
1430
1431/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 * e1000_open - Called when a network interface is made active
1433 * @netdev: network interface device structure
1434 *
1435 * Returns 0 on success, negative value on failure
1436 *
1437 * The open entry point is called when a network interface is made
1438 * active by the system (IFF_UP). At this point all resources needed
1439 * for transmit and receive operations are allocated, the interrupt
1440 * handler is registered with the OS, the watchdog timer is started,
1441 * and the stack is notified that the interface is ready.
1442 **/
1443
Joe Perches64798842008-07-11 15:17:02 -07001444static int e1000_open(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001446 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001447 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 int err;
1449
Auke Kok2db10a02006-06-27 09:06:28 -07001450 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001451 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001452 return -EBUSY;
1453
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 /* allocate transmit descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001455 err = e1000_setup_all_tx_resources(adapter);
1456 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 goto err_setup_tx;
1458
1459 /* allocate receive descriptors */
Auke Koke0aac5a2007-03-06 08:57:21 -08001460 err = e1000_setup_all_rx_resources(adapter);
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001461 if (err)
Auke Koke0aac5a2007-03-06 08:57:21 -08001462 goto err_setup_rx;
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001463
Auke Kok79f05bf2006-06-27 09:06:32 -07001464 e1000_power_up_phy(adapter);
1465
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001466 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Joe Perches1dc32912008-07-11 15:17:08 -07001467 if ((hw->mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001468 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1469 e1000_update_mng_vlan(adapter);
1470 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001472 /* If AMT is enabled, let the firmware know that the network
1473 * interface is now open */
Joe Perches1dc32912008-07-11 15:17:08 -07001474 if (hw->mac_type == e1000_82573 &&
1475 e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001476 e1000_get_hw_control(adapter);
1477
Auke Koke0aac5a2007-03-06 08:57:21 -08001478 /* before we allocate an interrupt, we must be ready to handle it.
1479 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1480 * as soon as we call pci_request_irq, so we have to setup our
1481 * clean_rx handler before we do so. */
1482 e1000_configure(adapter);
1483
1484 err = e1000_request_irq(adapter);
1485 if (err)
1486 goto err_req_irq;
1487
1488 /* From here on the code is the same as e1000_up() */
1489 clear_bit(__E1000_DOWN, &adapter->flags);
1490
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001491 napi_enable(&adapter->napi);
Herbert Xu47313052007-05-29 15:07:31 -07001492
Auke Koke0aac5a2007-03-06 08:57:21 -08001493 e1000_irq_enable(adapter);
1494
Ben Hutchings076152d2008-07-18 17:50:57 -07001495 netif_start_queue(netdev);
1496
Auke Koke0aac5a2007-03-06 08:57:21 -08001497 /* fire a link status change interrupt to start the watchdog */
Joe Perches1dc32912008-07-11 15:17:08 -07001498 ew32(ICS, E1000_ICS_LSC);
Auke Koke0aac5a2007-03-06 08:57:21 -08001499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 return E1000_SUCCESS;
1501
Linus Torvaldsb5bf28c2007-02-21 11:21:44 -08001502err_req_irq:
Auke Koke0aac5a2007-03-06 08:57:21 -08001503 e1000_release_hw_control(adapter);
1504 e1000_power_down_phy(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001505 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001507 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508err_setup_tx:
1509 e1000_reset(adapter);
1510
1511 return err;
1512}
1513
1514/**
1515 * e1000_close - Disables a network interface
1516 * @netdev: network interface device structure
1517 *
1518 * Returns 0, this is not allowed to fail
1519 *
1520 * The close entry point is called when an interface is de-activated
1521 * by the OS. The hardware is still under the drivers control, but
1522 * needs to be disabled. A global MAC reset is issued to stop the
1523 * hardware, and all transmit and receive resources are freed.
1524 **/
1525
Joe Perches64798842008-07-11 15:17:02 -07001526static int e1000_close(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001528 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001529 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Auke Kok2db10a02006-06-27 09:06:28 -07001531 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001533 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001534 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001536 e1000_free_all_tx_resources(adapter);
1537 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Bruce Allan46665602006-09-27 12:54:08 -07001539 /* kill manageability vlan ID if supported, but not if a vlan with
1540 * the same ID is registered on the host OS (let 8021q kill it) */
Joe Perches1dc32912008-07-11 15:17:08 -07001541 if ((hw->mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001542 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1543 !(adapter->vlgrp &&
Dan Aloni5c15bde2007-03-02 20:44:51 -08001544 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001545 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1546 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001547
1548 /* If AMT is enabled, let the firmware know that the network
1549 * interface is now closed */
Joe Perches1dc32912008-07-11 15:17:08 -07001550 if (hw->mac_type == e1000_82573 &&
1551 e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001552 e1000_release_hw_control(adapter);
1553
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 return 0;
1555}
1556
1557/**
1558 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1559 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001560 * @start: address of beginning of memory
1561 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 **/
Joe Perches64798842008-07-11 15:17:02 -07001563static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1564 unsigned long len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Joe Perches1dc32912008-07-11 15:17:08 -07001566 struct e1000_hw *hw = &adapter->hw;
Joe Perchese982f172008-07-11 15:17:18 -07001567 unsigned long begin = (unsigned long)start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 unsigned long end = begin + len;
1569
Malli Chilakala26483452005-04-28 19:44:46 -07001570 /* First rev 82545 and 82546 need to not allow any memory
1571 * write location to cross 64k boundary due to errata 23 */
Joe Perches1dc32912008-07-11 15:17:08 -07001572 if (hw->mac_type == e1000_82545 ||
1573 hw->mac_type == e1000_82546) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001574 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 }
1576
Joe Perchesc3033b02008-03-21 11:06:25 -07001577 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
1580/**
1581 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1582 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001583 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 *
1585 * Return 0 on success, negative on failure
1586 **/
1587
Joe Perches64798842008-07-11 15:17:02 -07001588static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1589 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 struct pci_dev *pdev = adapter->pdev;
1592 int size;
1593
1594 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001595 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001596 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001597 DPRINTK(PROBE, ERR,
1598 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 return -ENOMEM;
1600 }
1601 memset(txdr->buffer_info, 0, size);
1602
1603 /* round up to nearest 4K */
1604
1605 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001606 txdr->size = ALIGN(txdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
1608 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001609 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001612 DPRINTK(PROBE, ERR,
1613 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 return -ENOMEM;
1615 }
1616
Malli Chilakala26483452005-04-28 19:44:46 -07001617 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1619 void *olddesc = txdr->desc;
1620 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001621 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1622 "at %p\n", txdr->size, txdr->desc);
1623 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001625 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001626 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1628 goto setup_tx_desc_die;
1629 }
1630
1631 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1632 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001633 pci_free_consistent(pdev, txdr->size, txdr->desc,
1634 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1636 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001637 "Unable to allocate aligned memory "
1638 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 vfree(txdr->buffer_info);
1640 return -ENOMEM;
1641 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001642 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1644 }
1645 }
1646 memset(txdr->desc, 0, txdr->size);
1647
1648 txdr->next_to_use = 0;
1649 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001650 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
1652 return 0;
1653}
1654
1655/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001656 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1657 * (Descriptors) for all queues
1658 * @adapter: board private structure
1659 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001660 * Return 0 on success, negative on failure
1661 **/
1662
Joe Perches64798842008-07-11 15:17:02 -07001663int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001664{
1665 int i, err = 0;
1666
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001667 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001668 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1669 if (err) {
1670 DPRINTK(PROBE, ERR,
1671 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001672 for (i-- ; i >= 0; i--)
1673 e1000_free_tx_resources(adapter,
1674 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001675 break;
1676 }
1677 }
1678
1679 return err;
1680}
1681
1682/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1684 * @adapter: board private structure
1685 *
1686 * Configure the Tx unit of the MAC after a reset.
1687 **/
1688
Joe Perches64798842008-07-11 15:17:02 -07001689static void e1000_configure_tx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690{
Joe Perches406874a2008-04-03 10:06:32 -07001691 u64 tdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001692 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001693 u32 tdlen, tctl, tipg, tarc;
1694 u32 ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
1696 /* Setup the HW Tx Head and Tail descriptor pointers */
1697
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001698 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001699 case 1:
1700 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001701 tdba = adapter->tx_ring[0].dma;
1702 tdlen = adapter->tx_ring[0].count *
1703 sizeof(struct e1000_tx_desc);
Joe Perches1dc32912008-07-11 15:17:08 -07001704 ew32(TDLEN, tdlen);
1705 ew32(TDBAH, (tdba >> 32));
1706 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1707 ew32(TDT, 0);
1708 ew32(TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001709 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1710 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001711 break;
1712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
1714 /* Set the default values for the Tx Inter Packet Gap timer */
Joe Perches1dc32912008-07-11 15:17:08 -07001715 if (hw->mac_type <= e1000_82547_rev_2 &&
Jesse Brandeburgd89b6c62006-12-15 10:38:32 +01001716 (hw->media_type == e1000_media_type_fiber ||
1717 hw->media_type == e1000_media_type_internal_serdes))
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001718 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1719 else
1720 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1721
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001722 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 case e1000_82542_rev2_0:
1724 case e1000_82542_rev2_1:
1725 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001726 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1727 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001729 case e1000_80003es2lan:
1730 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1731 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1732 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001734 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1735 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1736 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001738 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1739 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Joe Perches1dc32912008-07-11 15:17:08 -07001740 ew32(TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
1742 /* Set the Tx Interrupt Delay register */
1743
Joe Perches1dc32912008-07-11 15:17:08 -07001744 ew32(TIDV, adapter->tx_int_delay);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001745 if (hw->mac_type >= e1000_82540)
Joe Perches1dc32912008-07-11 15:17:08 -07001746 ew32(TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
1748 /* Program the Transmit Control Register */
1749
Joe Perches1dc32912008-07-11 15:17:08 -07001750 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001752 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1754
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001755 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
Joe Perches1dc32912008-07-11 15:17:08 -07001756 tarc = er32(TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001757 /* set the speed mode bit, we'll clear it if we're not at
1758 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001759 tarc |= (1 << 21);
Joe Perches1dc32912008-07-11 15:17:08 -07001760 ew32(TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001761 } else if (hw->mac_type == e1000_80003es2lan) {
Joe Perches1dc32912008-07-11 15:17:08 -07001762 tarc = er32(TARC0);
Jeff Kirsher87041632006-03-02 18:21:24 -08001763 tarc |= 1;
Joe Perches1dc32912008-07-11 15:17:08 -07001764 ew32(TARC0, tarc);
1765 tarc = er32(TARC1);
Jeff Kirsher87041632006-03-02 18:21:24 -08001766 tarc |= 1;
Joe Perches1dc32912008-07-11 15:17:08 -07001767 ew32(TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001768 }
1769
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001770 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001773 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1774
1775 /* only set IDE if we are delaying interrupts using the timers */
1776 if (adapter->tx_int_delay)
1777 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001779 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1781 else
1782 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1783
1784 /* Cache if we're 82544 running in PCI-X because we'll
1785 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001786 if (hw->mac_type == e1000_82544 &&
1787 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001789
Joe Perches1dc32912008-07-11 15:17:08 -07001790 ew32(TCTL, tctl);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001791
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792}
1793
1794/**
1795 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1796 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001797 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 *
1799 * Returns 0 on success, negative on failure
1800 **/
1801
Joe Perches64798842008-07-11 15:17:02 -07001802static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1803 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804{
Joe Perches1dc32912008-07-11 15:17:08 -07001805 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001807 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
1809 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001810 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001811 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001812 DPRINTK(PROBE, ERR,
1813 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 return -ENOMEM;
1815 }
1816 memset(rxdr->buffer_info, 0, size);
1817
Yan Burman1c7e5b12007-03-06 08:58:04 -08001818 rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
1819 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001820 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001821 vfree(rxdr->buffer_info);
1822 DPRINTK(PROBE, ERR,
1823 "Unable to allocate memory for the receive descriptor ring\n");
1824 return -ENOMEM;
1825 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001826
Yan Burman1c7e5b12007-03-06 08:58:04 -08001827 rxdr->ps_page_dma = kcalloc(rxdr->count,
1828 sizeof(struct e1000_ps_page_dma),
1829 GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001830 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001831 vfree(rxdr->buffer_info);
1832 kfree(rxdr->ps_page);
1833 DPRINTK(PROBE, ERR,
1834 "Unable to allocate memory for the receive descriptor ring\n");
1835 return -ENOMEM;
1836 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001837
Joe Perches1dc32912008-07-11 15:17:08 -07001838 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001839 desc_len = sizeof(struct e1000_rx_desc);
1840 else
1841 desc_len = sizeof(union e1000_rx_desc_packet_split);
1842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 /* Round up to nearest 4K */
1844
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001845 rxdr->size = rxdr->count * desc_len;
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001846 rxdr->size = ALIGN(rxdr->size, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1849
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001850 if (!rxdr->desc) {
1851 DPRINTK(PROBE, ERR,
1852 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001855 kfree(rxdr->ps_page);
1856 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 return -ENOMEM;
1858 }
1859
Malli Chilakala26483452005-04-28 19:44:46 -07001860 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1862 void *olddesc = rxdr->desc;
1863 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001864 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1865 "at %p\n", rxdr->size, rxdr->desc);
1866 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001868 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001869 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001871 DPRINTK(PROBE, ERR,
1872 "Unable to allocate memory "
1873 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 goto setup_rx_desc_die;
1875 }
1876
1877 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1878 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001879 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1880 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001882 DPRINTK(PROBE, ERR,
1883 "Unable to allocate aligned memory "
1884 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001885 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001887 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1889 }
1890 }
1891 memset(rxdr->desc, 0, rxdr->size);
1892
1893 rxdr->next_to_clean = 0;
1894 rxdr->next_to_use = 0;
1895
1896 return 0;
1897}
1898
1899/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001900 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1901 * (Descriptors) for all queues
1902 * @adapter: board private structure
1903 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001904 * Return 0 on success, negative on failure
1905 **/
1906
Joe Perches64798842008-07-11 15:17:02 -07001907int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001908{
1909 int i, err = 0;
1910
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001911 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001912 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1913 if (err) {
1914 DPRINTK(PROBE, ERR,
1915 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001916 for (i-- ; i >= 0; i--)
1917 e1000_free_rx_resources(adapter,
1918 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001919 break;
1920 }
1921 }
1922
1923 return err;
1924}
1925
1926/**
Malli Chilakala26483452005-04-28 19:44:46 -07001927 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 * @adapter: Board private structure
1929 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001930#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1931 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Joe Perches64798842008-07-11 15:17:02 -07001932static void e1000_setup_rctl(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933{
Joe Perches1dc32912008-07-11 15:17:08 -07001934 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001935 u32 rctl, rfctl;
1936 u32 psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001937#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Joe Perches406874a2008-04-03 10:06:32 -07001938 u32 pages = 0;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001939#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
Joe Perches1dc32912008-07-11 15:17:08 -07001941 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1944
1945 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1946 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
Joe Perches1dc32912008-07-11 15:17:08 -07001947 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
Joe Perches1dc32912008-07-11 15:17:08 -07001949 if (hw->tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 rctl |= E1000_RCTL_SBP;
1951 else
1952 rctl &= ~E1000_RCTL_SBP;
1953
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001954 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1955 rctl &= ~E1000_RCTL_LPE;
1956 else
1957 rctl |= E1000_RCTL_LPE;
1958
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001960 rctl &= ~E1000_RCTL_SZ_4096;
1961 rctl |= E1000_RCTL_BSEX;
1962 switch (adapter->rx_buffer_len) {
1963 case E1000_RXBUFFER_256:
1964 rctl |= E1000_RCTL_SZ_256;
1965 rctl &= ~E1000_RCTL_BSEX;
1966 break;
1967 case E1000_RXBUFFER_512:
1968 rctl |= E1000_RCTL_SZ_512;
1969 rctl &= ~E1000_RCTL_BSEX;
1970 break;
1971 case E1000_RXBUFFER_1024:
1972 rctl |= E1000_RCTL_SZ_1024;
1973 rctl &= ~E1000_RCTL_BSEX;
1974 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001975 case E1000_RXBUFFER_2048:
1976 default:
1977 rctl |= E1000_RCTL_SZ_2048;
1978 rctl &= ~E1000_RCTL_BSEX;
1979 break;
1980 case E1000_RXBUFFER_4096:
1981 rctl |= E1000_RCTL_SZ_4096;
1982 break;
1983 case E1000_RXBUFFER_8192:
1984 rctl |= E1000_RCTL_SZ_8192;
1985 break;
1986 case E1000_RXBUFFER_16384:
1987 rctl |= E1000_RCTL_SZ_16384;
1988 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001989 }
1990
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001991#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001992 /* 82571 and greater support packet-split where the protocol
1993 * header is placed in skb->data and the packet data is
1994 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1995 * In the case of a non-split, skb->data is linearly filled,
1996 * followed by the page buffers. Therefore, skb->data is
1997 * sized to hold the largest protocol header.
1998 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001999 /* allocations using alloc_page take too long for regular MTU
2000 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002001 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Joe Perches1dc32912008-07-11 15:17:08 -07002002 if ((hw->mac_type >= e1000_82571) && (pages <= 3) &&
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07002003 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002004 adapter->rx_ps_pages = pages;
2005 else
2006 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002007#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002008 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002009 /* Configure extra packet-split registers */
Joe Perches1dc32912008-07-11 15:17:08 -07002010 rfctl = er32(RFCTL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002011 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08002012 /* disable packet split support for IPv6 extension headers,
2013 * because some malformed IPv6 headers can hang the RX */
2014 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
2015 E1000_RFCTL_NEW_IPV6_EXT_DIS);
2016
Joe Perches1dc32912008-07-11 15:17:08 -07002017 ew32(RFCTL, rfctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002018
Auke Kok7dfee0c2006-06-27 09:07:50 -07002019 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002020
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002021 psrctl |= adapter->rx_ps_bsize0 >>
2022 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002023
2024 switch (adapter->rx_ps_pages) {
2025 case 3:
2026 psrctl |= PAGE_SIZE <<
2027 E1000_PSRCTL_BSIZE3_SHIFT;
2028 case 2:
2029 psrctl |= PAGE_SIZE <<
2030 E1000_PSRCTL_BSIZE2_SHIFT;
2031 case 1:
2032 psrctl |= PAGE_SIZE >>
2033 E1000_PSRCTL_BSIZE1_SHIFT;
2034 break;
2035 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002036
Joe Perches1dc32912008-07-11 15:17:08 -07002037 ew32(PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 }
2039
Joe Perches1dc32912008-07-11 15:17:08 -07002040 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041}
2042
2043/**
2044 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2045 * @adapter: board private structure
2046 *
2047 * Configure the Rx unit of the MAC after a reset.
2048 **/
2049
Joe Perches64798842008-07-11 15:17:02 -07002050static void e1000_configure_rx(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051{
Joe Perches406874a2008-04-03 10:06:32 -07002052 u64 rdba;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002053 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002054 u32 rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002055
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04002056 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002057 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002058 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002059 sizeof(union e1000_rx_desc_packet_split);
2060 adapter->clean_rx = e1000_clean_rx_irq_ps;
2061 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
2062 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002063 rdlen = adapter->rx_ring[0].count *
2064 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002065 adapter->clean_rx = e1000_clean_rx_irq;
2066 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
2067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
2069 /* disable receives while setting up the descriptors */
Joe Perches1dc32912008-07-11 15:17:08 -07002070 rctl = er32(RCTL);
2071 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072
2073 /* set the Receive Delay Timer Register */
Joe Perches1dc32912008-07-11 15:17:08 -07002074 ew32(RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002076 if (hw->mac_type >= e1000_82540) {
Joe Perches1dc32912008-07-11 15:17:08 -07002077 ew32(RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002078 if (adapter->itr_setting != 0)
Joe Perches1dc32912008-07-11 15:17:08 -07002079 ew32(ITR, 1000000000 / (adapter->itr * 256));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 }
2081
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002082 if (hw->mac_type >= e1000_82571) {
Joe Perches1dc32912008-07-11 15:17:08 -07002083 ctrl_ext = er32(CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002084 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07002085 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002086 /* Auto-Mask interrupts upon ICR access */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08002087 ctrl_ext |= E1000_CTRL_EXT_IAME;
Joe Perches1dc32912008-07-11 15:17:08 -07002088 ew32(IAM, 0xffffffff);
Joe Perches1dc32912008-07-11 15:17:08 -07002089 ew32(CTRL_EXT, ctrl_ext);
2090 E1000_WRITE_FLUSH();
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04002091 }
2092
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002093 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2094 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002095 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04002096 case 1:
2097 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002098 rdba = adapter->rx_ring[0].dma;
Joe Perches1dc32912008-07-11 15:17:08 -07002099 ew32(RDLEN, rdlen);
2100 ew32(RDBAH, (rdba >> 32));
2101 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
2102 ew32(RDT, 0);
2103 ew32(RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07002104 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
2105 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002106 break;
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04002107 }
2108
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002110 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07002111 rxcsum = er32(RXCSUM);
Joe Perchesc3033b02008-03-21 11:06:25 -07002112 if (adapter->rx_csum) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002113 rxcsum |= E1000_RXCSUM_TUOFL;
2114
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002115 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002116 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002117 if ((hw->mac_type >= e1000_82571) &&
2118 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002119 rxcsum |= E1000_RXCSUM_IPPCSE;
2120 }
2121 } else {
2122 rxcsum &= ~E1000_RXCSUM_TUOFL;
2123 /* don't need to clear IPPCSE as it defaults to 0 */
2124 }
Joe Perches1dc32912008-07-11 15:17:08 -07002125 ew32(RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 }
2127
Auke Kok21c4d5e2006-11-01 08:47:39 -08002128 /* enable early receives on 82573, only takes effect if using > 2048
2129 * byte total frame size. for example only for jumbo frames */
2130#define E1000_ERT_2048 0x100
2131 if (hw->mac_type == e1000_82573)
Joe Perches1dc32912008-07-11 15:17:08 -07002132 ew32(ERT, E1000_ERT_2048);
Auke Kok21c4d5e2006-11-01 08:47:39 -08002133
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 /* Enable Receives */
Joe Perches1dc32912008-07-11 15:17:08 -07002135 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136}
2137
2138/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002139 * e1000_free_tx_resources - Free Tx Resources per Queue
2140 * @adapter: board private structure
2141 * @tx_ring: Tx descriptor ring for a specific queue
2142 *
2143 * Free all transmit software resources
2144 **/
2145
Joe Perches64798842008-07-11 15:17:02 -07002146static void e1000_free_tx_resources(struct e1000_adapter *adapter,
2147 struct e1000_tx_ring *tx_ring)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002148{
2149 struct pci_dev *pdev = adapter->pdev;
2150
2151 e1000_clean_tx_ring(adapter, tx_ring);
2152
2153 vfree(tx_ring->buffer_info);
2154 tx_ring->buffer_info = NULL;
2155
2156 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2157
2158 tx_ring->desc = NULL;
2159}
2160
2161/**
2162 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 * @adapter: board private structure
2164 *
2165 * Free all transmit software resources
2166 **/
2167
Joe Perches64798842008-07-11 15:17:02 -07002168void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002170 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002172 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002173 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174}
2175
Joe Perches64798842008-07-11 15:17:02 -07002176static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
2177 struct e1000_buffer *buffer_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002179 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07002180 pci_unmap_page(adapter->pdev,
2181 buffer_info->dma,
2182 buffer_info->length,
2183 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002184 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002186 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002188 buffer_info->skb = NULL;
2189 }
2190 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191}
2192
2193/**
2194 * e1000_clean_tx_ring - Free Tx Buffers
2195 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002196 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 **/
2198
Joe Perches64798842008-07-11 15:17:02 -07002199static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
2200 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201{
Joe Perches1dc32912008-07-11 15:17:08 -07002202 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 struct e1000_buffer *buffer_info;
2204 unsigned long size;
2205 unsigned int i;
2206
2207 /* Free all the Tx ring sk_buffs */
2208
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002209 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 buffer_info = &tx_ring->buffer_info[i];
2211 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2212 }
2213
2214 size = sizeof(struct e1000_buffer) * tx_ring->count;
2215 memset(tx_ring->buffer_info, 0, size);
2216
2217 /* Zero out the descriptor ring */
2218
2219 memset(tx_ring->desc, 0, tx_ring->size);
2220
2221 tx_ring->next_to_use = 0;
2222 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002223 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
Joe Perches1dc32912008-07-11 15:17:08 -07002225 writel(0, hw->hw_addr + tx_ring->tdh);
2226 writel(0, hw->hw_addr + tx_ring->tdt);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002227}
2228
2229/**
2230 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2231 * @adapter: board private structure
2232 **/
2233
Joe Perches64798842008-07-11 15:17:02 -07002234static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002235{
2236 int i;
2237
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002238 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002239 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240}
2241
2242/**
2243 * e1000_free_rx_resources - Free Rx Resources
2244 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002245 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 *
2247 * Free all receive software resources
2248 **/
2249
Joe Perches64798842008-07-11 15:17:02 -07002250static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2251 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 struct pci_dev *pdev = adapter->pdev;
2254
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002255 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
2257 vfree(rx_ring->buffer_info);
2258 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002259 kfree(rx_ring->ps_page);
2260 rx_ring->ps_page = NULL;
2261 kfree(rx_ring->ps_page_dma);
2262 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
2264 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2265
2266 rx_ring->desc = NULL;
2267}
2268
2269/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002270 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002272 *
2273 * Free all receive software resources
2274 **/
2275
Joe Perches64798842008-07-11 15:17:02 -07002276void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002277{
2278 int i;
2279
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002280 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002281 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2282}
2283
2284/**
2285 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2286 * @adapter: board private structure
2287 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 **/
2289
Joe Perches64798842008-07-11 15:17:02 -07002290static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2291 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292{
Joe Perches1dc32912008-07-11 15:17:08 -07002293 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002295 struct e1000_ps_page *ps_page;
2296 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 struct pci_dev *pdev = adapter->pdev;
2298 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002299 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002302 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002304 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 pci_unmap_single(pdev,
2306 buffer_info->dma,
2307 buffer_info->length,
2308 PCI_DMA_FROMDEVICE);
2309
2310 dev_kfree_skb(buffer_info->skb);
2311 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002312 }
2313 ps_page = &rx_ring->ps_page[i];
2314 ps_page_dma = &rx_ring->ps_page_dma[i];
2315 for (j = 0; j < adapter->rx_ps_pages; j++) {
2316 if (!ps_page->ps_page[j]) break;
2317 pci_unmap_page(pdev,
2318 ps_page_dma->ps_page_dma[j],
2319 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2320 ps_page_dma->ps_page_dma[j] = 0;
2321 put_page(ps_page->ps_page[j]);
2322 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 }
2324 }
2325
2326 size = sizeof(struct e1000_buffer) * rx_ring->count;
2327 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002328 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2329 memset(rx_ring->ps_page, 0, size);
2330 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2331 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
2333 /* Zero out the descriptor ring */
2334
2335 memset(rx_ring->desc, 0, rx_ring->size);
2336
2337 rx_ring->next_to_clean = 0;
2338 rx_ring->next_to_use = 0;
2339
Joe Perches1dc32912008-07-11 15:17:08 -07002340 writel(0, hw->hw_addr + rx_ring->rdh);
2341 writel(0, hw->hw_addr + rx_ring->rdt);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002342}
2343
2344/**
2345 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2346 * @adapter: board private structure
2347 **/
2348
Joe Perches64798842008-07-11 15:17:02 -07002349static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002350{
2351 int i;
2352
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002353 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002354 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355}
2356
2357/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2358 * and memory write and invalidate disabled for certain operations
2359 */
Joe Perches64798842008-07-11 15:17:02 -07002360static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361{
Joe Perches1dc32912008-07-11 15:17:08 -07002362 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002364 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
Joe Perches1dc32912008-07-11 15:17:08 -07002366 e1000_pci_clear_mwi(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
Joe Perches1dc32912008-07-11 15:17:08 -07002368 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 rctl |= E1000_RCTL_RST;
Joe Perches1dc32912008-07-11 15:17:08 -07002370 ew32(RCTL, rctl);
2371 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 mdelay(5);
2373
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002374 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002375 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376}
2377
Joe Perches64798842008-07-11 15:17:02 -07002378static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379{
Joe Perches1dc32912008-07-11 15:17:08 -07002380 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002382 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383
Joe Perches1dc32912008-07-11 15:17:08 -07002384 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 rctl &= ~E1000_RCTL_RST;
Joe Perches1dc32912008-07-11 15:17:08 -07002386 ew32(RCTL, rctl);
2387 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 mdelay(5);
2389
Joe Perches1dc32912008-07-11 15:17:08 -07002390 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2391 e1000_pci_set_mwi(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002393 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002394 /* No need to loop, because 82542 supports only 1 queue */
2395 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002396 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002397 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 }
2399}
2400
2401/**
2402 * e1000_set_mac - Change the Ethernet Address of the NIC
2403 * @netdev: network interface device structure
2404 * @p: pointer to an address structure
2405 *
2406 * Returns 0 on success, negative on failure
2407 **/
2408
Joe Perches64798842008-07-11 15:17:02 -07002409static int e1000_set_mac(struct net_device *netdev, void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002411 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07002412 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 struct sockaddr *addr = p;
2414
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002415 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 return -EADDRNOTAVAIL;
2417
2418 /* 82542 2.0 needs to be in reset to write receive address registers */
2419
Joe Perches1dc32912008-07-11 15:17:08 -07002420 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 e1000_enter_82542_rst(adapter);
2422
2423 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Joe Perches1dc32912008-07-11 15:17:08 -07002424 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Joe Perches1dc32912008-07-11 15:17:08 -07002426 e1000_rar_set(hw, hw->mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002428 /* With 82571 controllers, LAA may be overwritten (with the default)
2429 * due to controller reset from the other port. */
Joe Perches1dc32912008-07-11 15:17:08 -07002430 if (hw->mac_type == e1000_82571) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002431 /* activate the work around */
Joe Perches1dc32912008-07-11 15:17:08 -07002432 hw->laa_is_present = 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002433
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002434 /* Hold a copy of the LAA in RAR[14] This is done so that
2435 * between the time RAR[0] gets clobbered and the time it
2436 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002437 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002438 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002439 * RAR[14] */
Joe Perches1dc32912008-07-11 15:17:08 -07002440 e1000_rar_set(hw, hw->mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002441 E1000_RAR_ENTRIES - 1);
2442 }
2443
Joe Perches1dc32912008-07-11 15:17:08 -07002444 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 e1000_leave_82542_rst(adapter);
2446
2447 return 0;
2448}
2449
2450/**
Patrick McHardydb0ce502007-11-13 20:54:59 -08002451 * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 * @netdev: network interface device structure
2453 *
Patrick McHardydb0ce502007-11-13 20:54:59 -08002454 * The set_rx_mode entry point is called whenever the unicast or multicast
2455 * address lists or the network interface flags are updated. This routine is
2456 * responsible for configuring the hardware for proper unicast, multicast,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 * promiscuous mode, and all-multi behavior.
2458 **/
2459
Joe Perches64798842008-07-11 15:17:02 -07002460static void e1000_set_rx_mode(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002462 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 struct e1000_hw *hw = &adapter->hw;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002464 struct dev_addr_list *uc_ptr;
2465 struct dev_addr_list *mc_ptr;
Joe Perches406874a2008-04-03 10:06:32 -07002466 u32 rctl;
2467 u32 hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002468 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002469 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2470 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2471 E1000_NUM_MTA_REGISTERS;
2472
Joe Perches1dc32912008-07-11 15:17:08 -07002473 if (hw->mac_type == e1000_ich8lan)
Auke Kokcd94dd02006-06-27 09:08:22 -07002474 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002476 /* reserve RAR[14] for LAA over-write work-around */
Joe Perches1dc32912008-07-11 15:17:08 -07002477 if (hw->mac_type == e1000_82571)
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002478 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
Malli Chilakala26483452005-04-28 19:44:46 -07002480 /* Check for Promiscuous and All Multicast modes */
2481
Joe Perches1dc32912008-07-11 15:17:08 -07002482 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002484 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002486 rctl &= ~E1000_RCTL_VFE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002488 if (netdev->flags & IFF_ALLMULTI) {
2489 rctl |= E1000_RCTL_MPE;
2490 } else {
2491 rctl &= ~E1000_RCTL_MPE;
2492 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002493 if (adapter->hw.mac_type != e1000_ich8lan)
Patrick McHardy746b9f02008-07-16 20:15:45 -07002494 rctl |= E1000_RCTL_VFE;
Patrick McHardydb0ce502007-11-13 20:54:59 -08002495 }
2496
2497 uc_ptr = NULL;
2498 if (netdev->uc_count > rar_entries - 1) {
2499 rctl |= E1000_RCTL_UPE;
2500 } else if (!(netdev->flags & IFF_PROMISC)) {
2501 rctl &= ~E1000_RCTL_UPE;
2502 uc_ptr = netdev->uc_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 }
2504
Joe Perches1dc32912008-07-11 15:17:08 -07002505 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506
2507 /* 82542 2.0 needs to be in reset to write receive address registers */
2508
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002509 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 e1000_enter_82542_rst(adapter);
2511
Patrick McHardydb0ce502007-11-13 20:54:59 -08002512 /* load the first 14 addresses into the exact filters 1-14. Unicast
2513 * addresses take precedence to avoid disabling unicast filtering
2514 * when possible.
2515 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 * RAR 0 is used for the station MAC adddress
2517 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002518 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 */
2520 mc_ptr = netdev->mc_list;
2521
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002522 for (i = 1; i < rar_entries; i++) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002523 if (uc_ptr) {
2524 e1000_rar_set(hw, uc_ptr->da_addr, i);
2525 uc_ptr = uc_ptr->next;
2526 } else if (mc_ptr) {
2527 e1000_rar_set(hw, mc_ptr->da_addr, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 mc_ptr = mc_ptr->next;
2529 } else {
2530 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Joe Perches1dc32912008-07-11 15:17:08 -07002531 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Joe Perches1dc32912008-07-11 15:17:08 -07002533 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 }
2535 }
Patrick McHardydb0ce502007-11-13 20:54:59 -08002536 WARN_ON(uc_ptr != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537
2538 /* clear the old settings from the multicast hash table */
2539
Auke Kokcd94dd02006-06-27 09:08:22 -07002540 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Joe Perches1dc32912008-07-11 15:17:08 -07002542 E1000_WRITE_FLUSH();
Auke Kok4ca213a2006-06-27 09:07:08 -07002543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
2545 /* load any remaining addresses into the hash table */
2546
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002547 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Patrick McHardydb0ce502007-11-13 20:54:59 -08002548 hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 e1000_mta_set(hw, hash_value);
2550 }
2551
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002552 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554}
2555
2556/* Need to wait a few seconds after link up to get diagnostic information from
2557 * the phy */
2558
Joe Perches64798842008-07-11 15:17:02 -07002559static void e1000_update_phy_info(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560{
Joe Perchese982f172008-07-11 15:17:18 -07002561 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Joe Perches1dc32912008-07-11 15:17:08 -07002562 struct e1000_hw *hw = &adapter->hw;
2563 e1000_phy_get_info(hw, &adapter->phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564}
2565
2566/**
2567 * e1000_82547_tx_fifo_stall - Timer Call-back
2568 * @data: pointer to adapter cast into an unsigned long
2569 **/
2570
Joe Perches64798842008-07-11 15:17:02 -07002571static void e1000_82547_tx_fifo_stall(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572{
Joe Perchese982f172008-07-11 15:17:18 -07002573 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Joe Perches1dc32912008-07-11 15:17:08 -07002574 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -07002576 u32 tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002578 if (atomic_read(&adapter->tx_fifo_stall)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002579 if ((er32(TDT) == er32(TDH)) &&
2580 (er32(TDFT) == er32(TDFH)) &&
2581 (er32(TDFTS) == er32(TDFHS))) {
2582 tctl = er32(TCTL);
2583 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2584 ew32(TDFT, adapter->tx_head_addr);
2585 ew32(TDFH, adapter->tx_head_addr);
2586 ew32(TDFTS, adapter->tx_head_addr);
2587 ew32(TDFHS, adapter->tx_head_addr);
2588 ew32(TCTL, tctl);
2589 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
2591 adapter->tx_fifo_head = 0;
2592 atomic_set(&adapter->tx_fifo_stall, 0);
2593 netif_wake_queue(netdev);
2594 } else {
2595 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2596 }
2597 }
2598}
2599
2600/**
2601 * e1000_watchdog - Timer Call-back
2602 * @data: pointer to adapter cast into an unsigned long
2603 **/
Joe Perches64798842008-07-11 15:17:02 -07002604static void e1000_watchdog(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605{
Joe Perchese982f172008-07-11 15:17:18 -07002606 struct e1000_adapter *adapter = (struct e1000_adapter *)data;
Joe Perches1dc32912008-07-11 15:17:08 -07002607 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002609 struct e1000_tx_ring *txdr = adapter->tx_ring;
Joe Perches406874a2008-04-03 10:06:32 -07002610 u32 link, tctl;
2611 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
Joe Perches1dc32912008-07-11 15:17:08 -07002613 ret_val = e1000_check_for_link(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07002614 if ((ret_val == E1000_ERR_PHY) &&
Joe Perches1dc32912008-07-11 15:17:08 -07002615 (hw->phy_type == e1000_phy_igp_3) &&
2616 (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07002617 /* See e1000_kumeran_lock_loss_workaround() */
2618 DPRINTK(LINK, INFO,
2619 "Gigabit has been disabled, downgrading speed\n");
2620 }
Auke Kok90fb5132006-11-01 08:47:30 -08002621
Joe Perches1dc32912008-07-11 15:17:08 -07002622 if (hw->mac_type == e1000_82573) {
2623 e1000_enable_tx_pkt_filtering(hw);
2624 if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002625 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
Joe Perches1dc32912008-07-11 15:17:08 -07002628 if ((hw->media_type == e1000_media_type_internal_serdes) &&
2629 !(er32(TXCW) & E1000_TXCW_ANE))
2630 link = !hw->serdes_link_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 else
Joe Perches1dc32912008-07-11 15:17:08 -07002632 link = er32(STATUS) & E1000_STATUS_LU;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002634 if (link) {
2635 if (!netif_carrier_ok(netdev)) {
Joe Perches406874a2008-04-03 10:06:32 -07002636 u32 ctrl;
Joe Perchesc3033b02008-03-21 11:06:25 -07002637 bool txb2b = true;
Joe Perches1dc32912008-07-11 15:17:08 -07002638 e1000_get_speed_and_duplex(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 &adapter->link_speed,
2640 &adapter->link_duplex);
2641
Joe Perches1dc32912008-07-11 15:17:08 -07002642 ctrl = er32(CTRL);
Auke Kok9669f532007-01-18 09:25:26 -08002643 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
2644 "Flow Control: %s\n",
2645 adapter->link_speed,
2646 adapter->link_duplex == FULL_DUPLEX ?
2647 "Full Duplex" : "Half Duplex",
2648 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2649 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2650 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2651 E1000_CTRL_TFCE) ? "TX" : "None" )));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002653 /* tweak tx_queue_len according to speed/duplex
2654 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002655 netdev->tx_queue_len = adapter->tx_queue_len;
2656 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002657 switch (adapter->link_speed) {
2658 case SPEED_10:
Joe Perchesc3033b02008-03-21 11:06:25 -07002659 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002660 netdev->tx_queue_len = 10;
2661 adapter->tx_timeout_factor = 8;
2662 break;
2663 case SPEED_100:
Joe Perchesc3033b02008-03-21 11:06:25 -07002664 txb2b = false;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002665 netdev->tx_queue_len = 100;
2666 /* maybe add some timeout factor ? */
2667 break;
2668 }
2669
Joe Perches1dc32912008-07-11 15:17:08 -07002670 if ((hw->mac_type == e1000_82571 ||
2671 hw->mac_type == e1000_82572) &&
Joe Perchesc3033b02008-03-21 11:06:25 -07002672 !txb2b) {
Joe Perches406874a2008-04-03 10:06:32 -07002673 u32 tarc0;
Joe Perches1dc32912008-07-11 15:17:08 -07002674 tarc0 = er32(TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002675 tarc0 &= ~(1 << 21);
Joe Perches1dc32912008-07-11 15:17:08 -07002676 ew32(TARC0, tarc0);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002677 }
Auke Kok90fb5132006-11-01 08:47:30 -08002678
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002679 /* disable TSO for pcie and 10/100 speeds, to avoid
2680 * some hardware issues */
2681 if (!adapter->tso_force &&
Joe Perches1dc32912008-07-11 15:17:08 -07002682 hw->bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002683 switch (adapter->link_speed) {
2684 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002685 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002686 DPRINTK(PROBE,INFO,
2687 "10/100 speed: disabling TSO\n");
2688 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002689 netdev->features &= ~NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002690 break;
2691 case SPEED_1000:
2692 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002693 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002694 break;
2695 default:
2696 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002697 break;
2698 }
2699 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002700
2701 /* enable transmits in the hardware, need to do this
2702 * after setting TARC0 */
Joe Perches1dc32912008-07-11 15:17:08 -07002703 tctl = er32(TCTL);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002704 tctl |= E1000_TCTL_EN;
Joe Perches1dc32912008-07-11 15:17:08 -07002705 ew32(TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002706
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 netif_carrier_on(netdev);
2708 netif_wake_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002709 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 adapter->smartspeed = 0;
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002711 } else {
2712 /* make sure the receive unit is started */
Joe Perches1dc32912008-07-11 15:17:08 -07002713 if (hw->rx_needs_kicking) {
2714 u32 rctl = er32(RCTL);
2715 ew32(RCTL, rctl | E1000_RCTL_EN);
Jeff Garzikbb8e3312006-12-15 11:06:17 -05002716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 }
2718 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002719 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 adapter->link_speed = 0;
2721 adapter->link_duplex = 0;
2722 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2723 netif_carrier_off(netdev);
2724 netif_stop_queue(netdev);
Arjan van de Ven56e13932007-03-06 02:41:48 -08002725 mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
Jeff Kirsher87041632006-03-02 18:21:24 -08002726
2727 /* 80003ES2LAN workaround--
2728 * For packet buffer work-around on link down event;
2729 * disable receives in the ISR and
2730 * reset device here in the watchdog
2731 */
Joe Perches1dc32912008-07-11 15:17:08 -07002732 if (hw->mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002733 /* reset device */
2734 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 }
2736
2737 e1000_smartspeed(adapter);
2738 }
2739
2740 e1000_update_stats(adapter);
2741
Joe Perches1dc32912008-07-11 15:17:08 -07002742 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 adapter->tpt_old = adapter->stats.tpt;
Joe Perches1dc32912008-07-11 15:17:08 -07002744 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 adapter->colc_old = adapter->stats.colc;
2746
2747 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2748 adapter->gorcl_old = adapter->stats.gorcl;
2749 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2750 adapter->gotcl_old = adapter->stats.gotcl;
2751
Joe Perches1dc32912008-07-11 15:17:08 -07002752 e1000_update_adaptive(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002754 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002755 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 /* We've lost link, so the controller stops DMA,
2757 * but we've got queued Tx work that's never going
2758 * to get done, so reset controller to flush Tx.
2759 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002760 adapter->tx_timeout_count++;
2761 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 }
2763 }
2764
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 /* Cause software interrupt to ensure rx ring is cleaned */
Joe Perches1dc32912008-07-11 15:17:08 -07002766 ew32(ICS, E1000_ICS_RXDMT0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
Malli Chilakala26483452005-04-28 19:44:46 -07002768 /* Force detection of hung controller every watchdog period */
Joe Perchesc3033b02008-03-21 11:06:25 -07002769 adapter->detect_tx_hung = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002771 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002772 * reset from the other port. Set the appropriate LAA in RAR[0] */
Joe Perches1dc32912008-07-11 15:17:08 -07002773 if (hw->mac_type == e1000_82571 && hw->laa_is_present)
2774 e1000_rar_set(hw, hw->mac_addr, 0);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002775
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 /* Reset the timer */
Arjan van de Ven56e13932007-03-06 02:41:48 -08002777 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778}
2779
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002780enum latency_range {
2781 lowest_latency = 0,
2782 low_latency = 1,
2783 bulk_latency = 2,
2784 latency_invalid = 255
2785};
2786
2787/**
2788 * e1000_update_itr - update the dynamic ITR value based on statistics
2789 * Stores a new ITR value based on packets and byte
2790 * counts during the last interrupt. The advantage of per interrupt
2791 * computation is faster updates and more accurate ITR for the current
2792 * traffic pattern. Constants in this function were computed
2793 * based on theoretical maximum wire speed and thresholds were set based
2794 * on testing data as well as attempting to minimize response time
2795 * while increasing bulk throughput.
2796 * this functionality is controlled by the InterruptThrottleRate module
2797 * parameter (see e1000_param.c)
2798 * @adapter: pointer to adapter
2799 * @itr_setting: current adapter->itr
2800 * @packets: the number of packets during this measurement interval
2801 * @bytes: the number of bytes during this measurement interval
2802 **/
2803static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
Joe Perches64798842008-07-11 15:17:02 -07002804 u16 itr_setting, int packets, int bytes)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002805{
2806 unsigned int retval = itr_setting;
2807 struct e1000_hw *hw = &adapter->hw;
2808
2809 if (unlikely(hw->mac_type < e1000_82540))
2810 goto update_itr_done;
2811
2812 if (packets == 0)
2813 goto update_itr_done;
2814
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002815 switch (itr_setting) {
2816 case lowest_latency:
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002817 /* jumbo frames get bulk treatment*/
2818 if (bytes/packets > 8000)
2819 retval = bulk_latency;
2820 else if ((packets < 5) && (bytes > 512))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002821 retval = low_latency;
2822 break;
2823 case low_latency: /* 50 usec aka 20000 ints/s */
2824 if (bytes > 10000) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002825 /* jumbo frames need bulk latency setting */
2826 if (bytes/packets > 8000)
2827 retval = bulk_latency;
2828 else if ((packets < 10) || ((bytes/packets) > 1200))
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002829 retval = bulk_latency;
2830 else if ((packets > 35))
2831 retval = lowest_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002832 } else if (bytes/packets > 2000)
2833 retval = bulk_latency;
2834 else if (packets <= 2 && bytes < 512)
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002835 retval = lowest_latency;
2836 break;
2837 case bulk_latency: /* 250 usec aka 4000 ints/s */
2838 if (bytes > 25000) {
2839 if (packets > 35)
2840 retval = low_latency;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002841 } else if (bytes < 6000) {
2842 retval = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002843 }
2844 break;
2845 }
2846
2847update_itr_done:
2848 return retval;
2849}
2850
2851static void e1000_set_itr(struct e1000_adapter *adapter)
2852{
2853 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07002854 u16 current_itr;
2855 u32 new_itr = adapter->itr;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002856
2857 if (unlikely(hw->mac_type < e1000_82540))
2858 return;
2859
2860 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2861 if (unlikely(adapter->link_speed != SPEED_1000)) {
2862 current_itr = 0;
2863 new_itr = 4000;
2864 goto set_itr_now;
2865 }
2866
2867 adapter->tx_itr = e1000_update_itr(adapter,
2868 adapter->tx_itr,
2869 adapter->total_tx_packets,
2870 adapter->total_tx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002871 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2872 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2873 adapter->tx_itr = low_latency;
2874
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002875 adapter->rx_itr = e1000_update_itr(adapter,
2876 adapter->rx_itr,
2877 adapter->total_rx_packets,
2878 adapter->total_rx_bytes);
Jesse Brandeburg2b653262006-12-15 10:30:44 +01002879 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2880 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2881 adapter->rx_itr = low_latency;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002882
2883 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2884
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002885 switch (current_itr) {
2886 /* counts and packets in update_itr are dependent on these numbers */
2887 case lowest_latency:
2888 new_itr = 70000;
2889 break;
2890 case low_latency:
2891 new_itr = 20000; /* aka hwitr = ~200 */
2892 break;
2893 case bulk_latency:
2894 new_itr = 4000;
2895 break;
2896 default:
2897 break;
2898 }
2899
2900set_itr_now:
2901 if (new_itr != adapter->itr) {
2902 /* this attempts to bias the interrupt rate towards Bulk
2903 * by adding intermediate steps when interrupt rate is
2904 * increasing */
2905 new_itr = new_itr > adapter->itr ?
2906 min(adapter->itr + (new_itr >> 2), new_itr) :
2907 new_itr;
2908 adapter->itr = new_itr;
Joe Perches1dc32912008-07-11 15:17:08 -07002909 ew32(ITR, 1000000000 / (new_itr * 256));
Jesse Brandeburg835bb122006-11-01 08:48:13 -08002910 }
2911
2912 return;
2913}
2914
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915#define E1000_TX_FLAGS_CSUM 0x00000001
2916#define E1000_TX_FLAGS_VLAN 0x00000002
2917#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002918#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2920#define E1000_TX_FLAGS_VLAN_SHIFT 16
2921
Joe Perches64798842008-07-11 15:17:02 -07002922static int e1000_tso(struct e1000_adapter *adapter,
2923 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002926 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07002928 u32 cmd_length = 0;
2929 u16 ipcse = 0, tucse, mss;
2930 u8 ipcss, ipcso, tucss, tucso, hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 int err;
2932
Herbert Xu89114af2006-07-08 13:34:32 -07002933 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 if (skb_header_cloned(skb)) {
2935 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2936 if (err)
2937 return err;
2938 }
2939
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07002940 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Herbert Xu79671682006-06-22 02:40:14 -07002941 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002942 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002943 struct iphdr *iph = ip_hdr(skb);
2944 iph->tot_len = 0;
2945 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002946 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2947 iph->daddr, 0,
2948 IPPROTO_TCP,
2949 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002950 cmd_length = E1000_TXD_CMD_IP;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002951 ipcse = skb_transport_offset(skb) - 1;
Auke Koke15fdd02006-08-16 11:28:45 -07002952 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002953 ipv6_hdr(skb)->payload_len = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002954 tcp_hdr(skb)->check =
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07002955 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2956 &ipv6_hdr(skb)->daddr,
2957 0, IPPROTO_TCP, 0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002958 ipcse = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002959 }
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03002960 ipcss = skb_network_offset(skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002961 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07002962 tucss = skb_transport_offset(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07002963 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 tucse = 0;
2965
2966 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002967 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002969 i = tx_ring->next_to_use;
2970 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002971 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972
2973 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2974 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2975 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2976 context_desc->upper_setup.tcp_fields.tucss = tucss;
2977 context_desc->upper_setup.tcp_fields.tucso = tucso;
2978 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2979 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2980 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2981 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2982
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002983 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002984 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002985
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002986 if (++i == tx_ring->count) i = 0;
2987 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Joe Perchesc3033b02008-03-21 11:06:25 -07002989 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 }
Joe Perchesc3033b02008-03-21 11:06:25 -07002991 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992}
2993
Joe Perches64798842008-07-11 15:17:02 -07002994static bool e1000_tx_csum(struct e1000_adapter *adapter,
2995 struct e1000_tx_ring *tx_ring, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996{
2997 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002998 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 unsigned int i;
Joe Perches406874a2008-04-03 10:06:32 -07003000 u8 css;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001
Patrick McHardy84fa7932006-08-29 16:44:56 -07003002 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07003003 css = skb_transport_offset(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003005 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003006 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003007 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008
Bruce Allanf6c57ba2007-01-18 09:25:28 -08003009 context_desc->lower_setup.ip_config = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 context_desc->upper_setup.tcp_fields.tucss = css;
Herbert Xu628592c2007-04-23 17:06:40 -07003011 context_desc->upper_setup.tcp_fields.tucso =
3012 css + skb->csum_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 context_desc->upper_setup.tcp_fields.tucse = 0;
3014 context_desc->tcp_seg_setup.data = 0;
3015 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
3016
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003017 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003018 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08003019
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003020 if (unlikely(++i == tx_ring->count)) i = 0;
3021 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
Joe Perchesc3033b02008-03-21 11:06:25 -07003023 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 }
3025
Joe Perchesc3033b02008-03-21 11:06:25 -07003026 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027}
3028
3029#define E1000_MAX_TXD_PWR 12
3030#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
3031
Joe Perches64798842008-07-11 15:17:02 -07003032static int e1000_tx_map(struct e1000_adapter *adapter,
3033 struct e1000_tx_ring *tx_ring,
3034 struct sk_buff *skb, unsigned int first,
3035 unsigned int max_per_txd, unsigned int nr_frags,
3036 unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037{
Joe Perches1dc32912008-07-11 15:17:08 -07003038 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 struct e1000_buffer *buffer_info;
3040 unsigned int len = skb->len;
3041 unsigned int offset = 0, size, count = 0, i;
3042 unsigned int f;
3043 len -= skb->data_len;
3044
3045 i = tx_ring->next_to_use;
3046
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003047 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 buffer_info = &tx_ring->buffer_info[i];
3049 size = min(len, max_per_txd);
Jeff Kirsherfd803242005-12-13 00:06:22 -05003050 /* Workaround for Controller erratum --
3051 * descriptor for non-tso packet in a linear SKB that follows a
3052 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003053 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05003054 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07003055 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05003056 tx_ring->last_tx_tso = 0;
3057 size -= 4;
3058 }
3059
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 /* Workaround for premature desc write-backs
3061 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003062 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 size -= 4;
Malli Chilakala97338bd2005-04-28 19:41:46 -07003064 /* work-around for errata 10 and it applies
3065 * to all controllers in PCI-X mode
3066 * The fix is to make sure that the first descriptor of a
3067 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
3068 */
Joe Perches1dc32912008-07-11 15:17:08 -07003069 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003070 (size > 2015) && count == 0))
3071 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003072
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 /* Workaround for potential 82544 hang in PCI-X. Avoid
3074 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003075 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
3077 size > 4))
3078 size -= 4;
3079
3080 buffer_info->length = size;
3081 buffer_info->dma =
3082 pci_map_single(adapter->pdev,
3083 skb->data + offset,
3084 size,
3085 PCI_DMA_TODEVICE);
3086 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003087 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088
3089 len -= size;
3090 offset += size;
3091 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003092 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 }
3094
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003095 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 struct skb_frag_struct *frag;
3097
3098 frag = &skb_shinfo(skb)->frags[f];
3099 len = frag->size;
3100 offset = frag->page_offset;
3101
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003102 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 buffer_info = &tx_ring->buffer_info[i];
3104 size = min(len, max_per_txd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 /* Workaround for premature desc write-backs
3106 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003107 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 size -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 /* Workaround for potential 82544 hang in PCI-X.
3110 * Avoid terminating buffers within evenly-aligned
3111 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003112 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 !((unsigned long)(frag->page+offset+size-1) & 4) &&
3114 size > 4))
3115 size -= 4;
3116
3117 buffer_info->length = size;
3118 buffer_info->dma =
3119 pci_map_page(adapter->pdev,
3120 frag->page,
3121 offset,
3122 size,
3123 PCI_DMA_TODEVICE);
3124 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003125 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
3127 len -= size;
3128 offset += size;
3129 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003130 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 }
3132 }
3133
3134 i = (i == 0) ? tx_ring->count - 1 : i - 1;
3135 tx_ring->buffer_info[i].skb = skb;
3136 tx_ring->buffer_info[first].next_to_watch = i;
3137
3138 return count;
3139}
3140
Joe Perches64798842008-07-11 15:17:02 -07003141static void e1000_tx_queue(struct e1000_adapter *adapter,
3142 struct e1000_tx_ring *tx_ring, int tx_flags,
3143 int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144{
Joe Perches1dc32912008-07-11 15:17:08 -07003145 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 struct e1000_tx_desc *tx_desc = NULL;
3147 struct e1000_buffer *buffer_info;
Joe Perches406874a2008-04-03 10:06:32 -07003148 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 unsigned int i;
3150
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003151 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3153 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003154 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3155
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003156 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003157 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 }
3159
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003160 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3162 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3163 }
3164
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003165 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 txd_lower |= E1000_TXD_CMD_VLE;
3167 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3168 }
3169
3170 i = tx_ring->next_to_use;
3171
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003172 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 buffer_info = &tx_ring->buffer_info[i];
3174 tx_desc = E1000_TX_DESC(*tx_ring, i);
3175 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3176 tx_desc->lower.data =
3177 cpu_to_le32(txd_lower | buffer_info->length);
3178 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003179 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 }
3181
3182 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3183
3184 /* Force memory writes to complete before letting h/w
3185 * know there are new descriptors to fetch. (Only
3186 * applicable for weak-ordered memory model archs,
3187 * such as IA-64). */
3188 wmb();
3189
3190 tx_ring->next_to_use = i;
Joe Perches1dc32912008-07-11 15:17:08 -07003191 writel(i, hw->hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08003192 /* we need this if more than one processor can write to our tail
3193 * at a time, it syncronizes IO on IA64/Altix systems */
3194 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195}
3196
3197/**
3198 * 82547 workaround to avoid controller hang in half-duplex environment.
3199 * The workaround is to avoid queuing a large packet that would span
3200 * the internal Tx FIFO ring boundary by notifying the stack to resend
3201 * the packet at a later time. This gives the Tx FIFO an opportunity to
3202 * flush all packets. When that occurs, we reset the Tx FIFO pointers
3203 * to the beginning of the Tx FIFO.
3204 **/
3205
3206#define E1000_FIFO_HDR 0x10
3207#define E1000_82547_PAD_LEN 0x3E0
3208
Joe Perches64798842008-07-11 15:17:02 -07003209static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3210 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211{
Joe Perches406874a2008-04-03 10:06:32 -07003212 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3213 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07003215 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003217 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 goto no_fifo_stall_required;
3219
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003220 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 return 1;
3222
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003223 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 atomic_set(&adapter->tx_fifo_stall, 1);
3225 return 1;
3226 }
3227
3228no_fifo_stall_required:
3229 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003230 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3232 return 0;
3233}
3234
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003235#define MINIMUM_DHCP_PACKET_SIZE 282
Joe Perches64798842008-07-11 15:17:02 -07003236static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
3237 struct sk_buff *skb)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003238{
3239 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07003240 u16 length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003241 if (vlan_tx_tag_present(skb)) {
Joe Perches1dc32912008-07-11 15:17:08 -07003242 if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) &&
3243 ( hw->mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003244 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
3245 return 0;
3246 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08003247 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Joe Perchese982f172008-07-11 15:17:18 -07003248 struct ethhdr *eth = (struct ethhdr *)skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003249 if ((htons(ETH_P_IP) == eth->h_proto)) {
3250 const struct iphdr *ip =
Joe Perches406874a2008-04-03 10:06:32 -07003251 (struct iphdr *)((u8 *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003252 if (IPPROTO_UDP == ip->protocol) {
3253 struct udphdr *udp =
Joe Perches406874a2008-04-03 10:06:32 -07003254 (struct udphdr *)((u8 *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003255 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003256 if (ntohs(udp->dest) == 67) {
Joe Perches406874a2008-04-03 10:06:32 -07003257 offset = (u8 *)udp + 8 - skb->data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003258 length = skb->len - offset;
3259
3260 return e1000_mng_write_dhcp_info(hw,
Joe Perches406874a2008-04-03 10:06:32 -07003261 (u8 *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003262 length);
3263 }
3264 }
3265 }
3266 }
3267 return 0;
3268}
3269
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003270static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3271{
3272 struct e1000_adapter *adapter = netdev_priv(netdev);
3273 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3274
3275 netif_stop_queue(netdev);
3276 /* Herbert's original patch had:
3277 * smp_mb__after_netif_stop_queue();
3278 * but since that doesn't exist yet, just open code it. */
3279 smp_mb();
3280
3281 /* We need to check again in a case another CPU has just
3282 * made room available. */
3283 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3284 return -EBUSY;
3285
3286 /* A reprieve! */
3287 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003288 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003289 return 0;
3290}
3291
3292static int e1000_maybe_stop_tx(struct net_device *netdev,
3293 struct e1000_tx_ring *tx_ring, int size)
3294{
3295 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3296 return 0;
3297 return __e1000_maybe_stop_tx(netdev, size);
3298}
3299
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
Joe Perches64798842008-07-11 15:17:02 -07003301static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003303 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07003304 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003305 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3307 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3308 unsigned int tx_flags = 0;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003309 unsigned int len = skb->len - skb->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 unsigned long flags;
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003311 unsigned int nr_frags;
3312 unsigned int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003314 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 unsigned int f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003317 /* This goes back to the question of how to logically map a tx queue
3318 * to a flow. Right now, performance is impacted slightly negatively
3319 * if using multiple tx queues. If the stack breaks away from a
3320 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003321 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04003322
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003323 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 dev_kfree_skb_any(skb);
3325 return NETDEV_TX_OK;
3326 }
3327
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003328 /* 82571 and newer doesn't need the workaround that limited descriptor
3329 * length to 4kB */
Joe Perches1dc32912008-07-11 15:17:08 -07003330 if (hw->mac_type >= e1000_82571)
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003331 max_per_txd = 8192;
3332
Herbert Xu79671682006-06-22 02:40:14 -07003333 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003334 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 * make sure there is enough room in the FIFO before
3336 * initiating the DMA for each buffer. The calc is:
3337 * 4 = ceil(buffer len/mss). To make sure we don't
3338 * overrun the FIFO, adjust the max buffer len if mss
3339 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003340 if (mss) {
Joe Perches406874a2008-04-03 10:06:32 -07003341 u8 hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 max_per_txd = min(mss << 2, max_per_txd);
3343 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003344
Auke Kok90fb5132006-11-01 08:47:30 -08003345 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3346 * points to just header, pull a few bytes of payload from
3347 * frags into skb->data */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07003348 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Krishna Kumar6d1e3aa2007-10-05 14:15:16 -07003349 if (skb->data_len && hdr_len == len) {
Joe Perches1dc32912008-07-11 15:17:08 -07003350 switch (hw->mac_type) {
Jeff Kirsher9f687882006-03-02 18:20:17 -08003351 unsigned int pull_size;
Herbert Xu683a2aa2006-12-16 12:04:33 +11003352 case e1000_82544:
3353 /* Make sure we have room to chop off 4 bytes,
3354 * and that the end alignment will work out to
3355 * this hardware's requirements
3356 * NOTE: this is a TSO only workaround
3357 * if end byte alignment not correct move us
3358 * into the next dword */
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003359 if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
Herbert Xu683a2aa2006-12-16 12:04:33 +11003360 break;
3361 /* fall through */
Jeff Kirsher9f687882006-03-02 18:20:17 -08003362 case e1000_82571:
3363 case e1000_82572:
3364 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003365 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003366 pull_size = min((unsigned int)4, skb->data_len);
3367 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003368 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003369 "__pskb_pull_tail failed.\n");
3370 dev_kfree_skb_any(skb);
Jeff Garzik749dfc72006-03-11 13:35:31 -05003371 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003372 }
3373 len = skb->len - skb->data_len;
3374 break;
3375 default:
3376 /* do nothing */
3377 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003378 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 }
3381
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003382 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003383 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003385 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003386
Jeff Kirsherfd803242005-12-13 00:06:22 -05003387 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003388 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003389 count++;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003390
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 count += TXD_USE_COUNT(len, max_txd_pwr);
3392
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003393 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 count++;
3395
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003396 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003397 * in PCI-X mode, so add one more descriptor to the count
3398 */
Joe Perches1dc32912008-07-11 15:17:08 -07003399 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003400 (len > 2015)))
3401 count++;
3402
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003404 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3406 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003407 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 count += nr_frags;
3409
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003410
Joe Perches1dc32912008-07-11 15:17:08 -07003411 if (hw->tx_pkt_filtering &&
3412 (hw->mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003413 e1000_transfer_dhcp_info(adapter, skb);
3414
Mark Huthf50393f2007-03-06 08:57:26 -08003415 if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003416 /* Collision - tell upper layer to requeue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003417 return NETDEV_TX_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418
3419 /* need: count + 2 desc gap to keep tail from touching
3420 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003421 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003422 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 return NETDEV_TX_BUSY;
3424 }
3425
Joe Perches1dc32912008-07-11 15:17:08 -07003426 if (unlikely(hw->mac_type == e1000_82547)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003427 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003429 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003430 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 return NETDEV_TX_BUSY;
3432 }
3433 }
3434
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003435 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 tx_flags |= E1000_TX_FLAGS_VLAN;
3437 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3438 }
3439
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003440 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003441
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003442 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 if (tso < 0) {
3444 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003445 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 return NETDEV_TX_OK;
3447 }
3448
Jeff Kirsherfd803242005-12-13 00:06:22 -05003449 if (likely(tso)) {
3450 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003452 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 tx_flags |= E1000_TX_FLAGS_CSUM;
3454
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003455 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003456 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003457 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003458 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003459 tx_flags |= E1000_TX_FLAGS_IPV4;
3460
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003461 e1000_tx_queue(adapter, tx_ring, tx_flags,
3462 e1000_tx_map(adapter, tx_ring, skb, first,
3463 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464
3465 netdev->trans_start = jiffies;
3466
3467 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003468 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003470 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 return NETDEV_TX_OK;
3472}
3473
3474/**
3475 * e1000_tx_timeout - Respond to a Tx Hang
3476 * @netdev: network interface device structure
3477 **/
3478
Joe Perches64798842008-07-11 15:17:02 -07003479static void e1000_tx_timeout(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003481 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482
3483 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003484 adapter->tx_timeout_count++;
3485 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486}
3487
Joe Perches64798842008-07-11 15:17:02 -07003488static void e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489{
David Howells65f27f32006-11-22 14:55:48 +00003490 struct e1000_adapter *adapter =
3491 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492
Auke Kok2db10a02006-06-27 09:06:28 -07003493 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494}
3495
3496/**
3497 * e1000_get_stats - Get System Network Statistics
3498 * @netdev: network interface device structure
3499 *
3500 * Returns the address of the device statistics structure.
3501 * The statistics are actually updated from the timer callback.
3502 **/
3503
Joe Perches64798842008-07-11 15:17:02 -07003504static struct net_device_stats *e1000_get_stats(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003506 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003508 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509 return &adapter->net_stats;
3510}
3511
3512/**
3513 * e1000_change_mtu - Change the Maximum Transfer Unit
3514 * @netdev: network interface device structure
3515 * @new_mtu: new value for maximum frame size
3516 *
3517 * Returns 0 on success, negative on failure
3518 **/
3519
Joe Perches64798842008-07-11 15:17:02 -07003520static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003522 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07003523 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Joe Perches406874a2008-04-03 10:06:32 -07003525 u16 eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003527 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3528 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3529 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003530 return -EINVAL;
3531 }
3532
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003533 /* Adapter-specific max frame size limits. */
Joe Perches1dc32912008-07-11 15:17:08 -07003534 switch (hw->mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003535 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003536 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003537 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3538 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003539 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003540 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003541 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003542 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003543 /* Jumbo Frames not supported if:
3544 * - this is not an 82573L device
3545 * - ASPM is enabled in any way (0x1A bits 3:2) */
Joe Perches1dc32912008-07-11 15:17:08 -07003546 e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1,
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003547 &eeprom_data);
Joe Perches1dc32912008-07-11 15:17:08 -07003548 if ((hw->device_id != E1000_DEV_ID_82573L) ||
Bruce Allan249d71d2006-09-27 12:53:45 -07003549 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003550 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3551 DPRINTK(PROBE, ERR,
3552 "Jumbo Frames not supported.\n");
3553 return -EINVAL;
3554 }
3555 break;
3556 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003557 /* ERT will be enabled later to enable wire speed receives */
3558
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003559 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003560 case e1000_82571:
3561 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003562 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003563#define MAX_STD_JUMBO_FRAME_SIZE 9234
3564 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3565 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3566 return -EINVAL;
3567 }
3568 break;
3569 default:
3570 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3571 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003572 }
3573
David S. Miller87f50322006-07-31 22:39:40 -07003574 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003575 * means we reserve 2 more, this pushes us to allocate from the next
3576 * larger slab size
3577 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003578
Auke Kok9e2feac2006-04-14 19:05:18 -07003579 if (max_frame <= E1000_RXBUFFER_256)
3580 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3581 else if (max_frame <= E1000_RXBUFFER_512)
3582 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3583 else if (max_frame <= E1000_RXBUFFER_1024)
3584 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3585 else if (max_frame <= E1000_RXBUFFER_2048)
3586 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3587 else if (max_frame <= E1000_RXBUFFER_4096)
3588 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3589 else if (max_frame <= E1000_RXBUFFER_8192)
3590 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3591 else if (max_frame <= E1000_RXBUFFER_16384)
3592 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3593
3594 /* adjust allocation if LPE protects us, and we aren't using SBP */
Joe Perches1dc32912008-07-11 15:17:08 -07003595 if (!hw->tbi_compatibility_on &&
Auke Kok9e2feac2006-04-14 19:05:18 -07003596 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3597 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3598 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003599
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003600 netdev->mtu = new_mtu;
Joe Perches1dc32912008-07-11 15:17:08 -07003601 hw->max_frame_size = max_frame;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003602
Auke Kok2db10a02006-06-27 09:06:28 -07003603 if (netif_running(netdev))
3604 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 return 0;
3607}
3608
3609/**
3610 * e1000_update_stats - Update the board statistics counters
3611 * @adapter: board private structure
3612 **/
3613
Joe Perches64798842008-07-11 15:17:02 -07003614void e1000_update_stats(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615{
3616 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003617 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07003619 u16 phy_tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620
3621#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3622
Linas Vepstas282f33c2006-06-08 22:19:44 -07003623 /*
3624 * Prevent stats update while adapter is being reset, or if the pci
3625 * connection is down.
3626 */
Auke Kok90267292006-06-08 09:30:24 -07003627 if (adapter->link_speed == 0)
3628 return;
Linas Vepstas81b19552006-12-12 18:29:15 -06003629 if (pci_channel_offline(pdev))
Linas Vepstas282f33c2006-06-08 22:19:44 -07003630 return;
Auke Kok90267292006-06-08 09:30:24 -07003631
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 spin_lock_irqsave(&adapter->stats_lock, flags);
3633
Masatake YAMATO828d0552007-10-20 03:06:37 +02003634 /* these counters are modified from e1000_tbi_adjust_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 * called from the interrupt context, so they must only
3636 * be written while holding adapter->stats_lock
3637 */
3638
Joe Perches1dc32912008-07-11 15:17:08 -07003639 adapter->stats.crcerrs += er32(CRCERRS);
3640 adapter->stats.gprc += er32(GPRC);
3641 adapter->stats.gorcl += er32(GORCL);
3642 adapter->stats.gorch += er32(GORCH);
3643 adapter->stats.bprc += er32(BPRC);
3644 adapter->stats.mprc += er32(MPRC);
3645 adapter->stats.roc += er32(ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003646
Joe Perches1dc32912008-07-11 15:17:08 -07003647 if (hw->mac_type != e1000_ich8lan) {
3648 adapter->stats.prc64 += er32(PRC64);
3649 adapter->stats.prc127 += er32(PRC127);
3650 adapter->stats.prc255 += er32(PRC255);
3651 adapter->stats.prc511 += er32(PRC511);
3652 adapter->stats.prc1023 += er32(PRC1023);
3653 adapter->stats.prc1522 += er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655
Joe Perches1dc32912008-07-11 15:17:08 -07003656 adapter->stats.symerrs += er32(SYMERRS);
3657 adapter->stats.mpc += er32(MPC);
3658 adapter->stats.scc += er32(SCC);
3659 adapter->stats.ecol += er32(ECOL);
3660 adapter->stats.mcc += er32(MCC);
3661 adapter->stats.latecol += er32(LATECOL);
3662 adapter->stats.dc += er32(DC);
3663 adapter->stats.sec += er32(SEC);
3664 adapter->stats.rlec += er32(RLEC);
3665 adapter->stats.xonrxc += er32(XONRXC);
3666 adapter->stats.xontxc += er32(XONTXC);
3667 adapter->stats.xoffrxc += er32(XOFFRXC);
3668 adapter->stats.xofftxc += er32(XOFFTXC);
3669 adapter->stats.fcruc += er32(FCRUC);
3670 adapter->stats.gptc += er32(GPTC);
3671 adapter->stats.gotcl += er32(GOTCL);
3672 adapter->stats.gotch += er32(GOTCH);
3673 adapter->stats.rnbc += er32(RNBC);
3674 adapter->stats.ruc += er32(RUC);
3675 adapter->stats.rfc += er32(RFC);
3676 adapter->stats.rjc += er32(RJC);
3677 adapter->stats.torl += er32(TORL);
3678 adapter->stats.torh += er32(TORH);
3679 adapter->stats.totl += er32(TOTL);
3680 adapter->stats.toth += er32(TOTH);
3681 adapter->stats.tpr += er32(TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003682
Joe Perches1dc32912008-07-11 15:17:08 -07003683 if (hw->mac_type != e1000_ich8lan) {
3684 adapter->stats.ptc64 += er32(PTC64);
3685 adapter->stats.ptc127 += er32(PTC127);
3686 adapter->stats.ptc255 += er32(PTC255);
3687 adapter->stats.ptc511 += er32(PTC511);
3688 adapter->stats.ptc1023 += er32(PTC1023);
3689 adapter->stats.ptc1522 += er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003690 }
3691
Joe Perches1dc32912008-07-11 15:17:08 -07003692 adapter->stats.mptc += er32(MPTC);
3693 adapter->stats.bptc += er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694
3695 /* used for adaptive IFS */
3696
Joe Perches1dc32912008-07-11 15:17:08 -07003697 hw->tx_packet_delta = er32(TPT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 adapter->stats.tpt += hw->tx_packet_delta;
Joe Perches1dc32912008-07-11 15:17:08 -07003699 hw->collision_delta = er32(COLC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 adapter->stats.colc += hw->collision_delta;
3701
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003702 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07003703 adapter->stats.algnerrc += er32(ALGNERRC);
3704 adapter->stats.rxerrc += er32(RXERRC);
3705 adapter->stats.tncrs += er32(TNCRS);
3706 adapter->stats.cexterr += er32(CEXTERR);
3707 adapter->stats.tsctc += er32(TSCTC);
3708 adapter->stats.tsctfc += er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003710 if (hw->mac_type > e1000_82547_rev_2) {
Joe Perches1dc32912008-07-11 15:17:08 -07003711 adapter->stats.iac += er32(IAC);
3712 adapter->stats.icrxoc += er32(ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003713
Joe Perches1dc32912008-07-11 15:17:08 -07003714 if (hw->mac_type != e1000_ich8lan) {
3715 adapter->stats.icrxptc += er32(ICRXPTC);
3716 adapter->stats.icrxatc += er32(ICRXATC);
3717 adapter->stats.ictxptc += er32(ICTXPTC);
3718 adapter->stats.ictxatc += er32(ICTXATC);
3719 adapter->stats.ictxqec += er32(ICTXQEC);
3720 adapter->stats.ictxqmtc += er32(ICTXQMTC);
3721 adapter->stats.icrxdmtc += er32(ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003722 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724
3725 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 adapter->net_stats.multicast = adapter->stats.mprc;
3727 adapter->net_stats.collisions = adapter->stats.colc;
3728
3729 /* Rx Errors */
3730
Jeff Kirsher87041632006-03-02 18:21:24 -08003731 /* RLEC on some newer hardware can be incorrect so build
3732 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3734 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003735 adapter->stats.ruc + adapter->stats.roc +
3736 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003737 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3738 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3740 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3742
3743 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003744 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3745 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3747 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3748 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
Joe Perches1dc32912008-07-11 15:17:08 -07003749 if (hw->bad_tx_carr_stats_fd &&
Jeff Garzik167fb282006-12-15 10:41:15 -05003750 adapter->link_duplex == FULL_DUPLEX) {
3751 adapter->net_stats.tx_carrier_errors = 0;
3752 adapter->stats.tncrs = 0;
3753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754
3755 /* Tx Dropped needs to be maintained elsewhere */
3756
3757 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003758 if (hw->media_type == e1000_media_type_copper) {
3759 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3761 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3762 adapter->phy_stats.idle_errors += phy_tmp;
3763 }
3764
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003765 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 (hw->phy_type == e1000_phy_m88) &&
3767 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3768 adapter->phy_stats.receive_errors += phy_tmp;
3769 }
3770
Jeff Garzik15e376b2006-12-15 11:16:33 -05003771 /* Management Stats */
Joe Perches1dc32912008-07-11 15:17:08 -07003772 if (hw->has_smbus) {
3773 adapter->stats.mgptc += er32(MGTPTC);
3774 adapter->stats.mgprc += er32(MGTPRC);
3775 adapter->stats.mgpdc += er32(MGTPDC);
Jeff Garzik15e376b2006-12-15 11:16:33 -05003776 }
3777
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3779}
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003780
3781/**
3782 * e1000_intr_msi - Interrupt Handler
3783 * @irq: interrupt number
3784 * @data: pointer to a network interface device structure
3785 **/
3786
Joe Perches64798842008-07-11 15:17:02 -07003787static irqreturn_t e1000_intr_msi(int irq, void *data)
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003788{
3789 struct net_device *netdev = data;
3790 struct e1000_adapter *adapter = netdev_priv(netdev);
3791 struct e1000_hw *hw = &adapter->hw;
Joe Perches1dc32912008-07-11 15:17:08 -07003792 u32 icr = er32(ICR);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003793
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003794 /* in NAPI mode read ICR disables interrupts using IAM */
3795
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003796 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3797 hw->get_link_status = 1;
3798 /* 80003ES2LAN workaround-- For packet buffer work-around on
3799 * link down event; disable receives here in the ISR and reset
3800 * adapter in watchdog */
3801 if (netif_carrier_ok(netdev) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003802 (hw->mac_type == e1000_80003es2lan)) {
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003803 /* disable receives */
Joe Perches1dc32912008-07-11 15:17:08 -07003804 u32 rctl = er32(RCTL);
3805 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003806 }
Jesse Brandeburgb5fc8f02007-01-18 09:25:21 -08003807 /* guard against interrupt when we're going down */
3808 if (!test_bit(__E1000_DOWN, &adapter->flags))
3809 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003810 }
3811
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003812 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003813 adapter->total_tx_bytes = 0;
3814 adapter->total_tx_packets = 0;
3815 adapter->total_rx_bytes = 0;
3816 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003817 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003818 } else
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003819 e1000_irq_enable(adapter);
Jesse Brandeburg9ac98282006-11-01 08:48:10 -08003820
3821 return IRQ_HANDLED;
3822}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823
3824/**
3825 * e1000_intr - Interrupt Handler
3826 * @irq: interrupt number
3827 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 **/
3829
Joe Perches64798842008-07-11 15:17:02 -07003830static irqreturn_t e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831{
3832 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003833 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 struct e1000_hw *hw = &adapter->hw;
Joe Perches1dc32912008-07-11 15:17:08 -07003835 u32 rctl, icr = er32(ICR);
Francois Romieuc3570ac2008-07-11 15:17:38 -07003836
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003837 if (unlikely(!icr))
3838 return IRQ_NONE; /* Not our interrupt */
3839
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003840 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3841 * not set, then the adapter didn't send an interrupt */
3842 if (unlikely(hw->mac_type >= e1000_82571 &&
3843 !(icr & E1000_ICR_INT_ASSERTED)))
3844 return IRQ_NONE;
3845
Jesse Brandeburg9150b762008-03-21 11:06:58 -07003846 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3847 * need for the IMC write */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003849 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003851 /* 80003ES2LAN workaround--
3852 * For packet buffer work-around on link down event;
3853 * disable receives here in the ISR and
3854 * reset adapter in watchdog
3855 */
3856 if (netif_carrier_ok(netdev) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003857 (hw->mac_type == e1000_80003es2lan)) {
Jeff Kirsher87041632006-03-02 18:21:24 -08003858 /* disable receives */
Joe Perches1dc32912008-07-11 15:17:08 -07003859 rctl = er32(RCTL);
3860 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Jeff Kirsher87041632006-03-02 18:21:24 -08003861 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003862 /* guard against interrupt when we're going down */
3863 if (!test_bit(__E1000_DOWN, &adapter->flags))
3864 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 }
3866
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003867 if (unlikely(hw->mac_type < e1000_82571)) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003868 /* disable interrupts, without the synchronize_irq bit */
Joe Perches1dc32912008-07-11 15:17:08 -07003869 ew32(IMC, ~0);
3870 E1000_WRITE_FLUSH();
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003871 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003872 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003873 adapter->total_tx_bytes = 0;
3874 adapter->total_tx_packets = 0;
3875 adapter->total_rx_bytes = 0;
3876 adapter->total_rx_packets = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003877 __netif_rx_schedule(netdev, &adapter->napi);
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003878 } else
Auke Kok90fb5132006-11-01 08:47:30 -08003879 /* this really should not happen! if it does it is basically a
3880 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003881 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 return IRQ_HANDLED;
3884}
3885
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886/**
3887 * e1000_clean - NAPI Rx polling callback
3888 * @adapter: board private structure
3889 **/
Joe Perches64798842008-07-11 15:17:02 -07003890static int e1000_clean(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003892 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3893 struct net_device *poll_dev = adapter->netdev;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003894 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003895
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003896 /* Must NOT use netdev_priv macro here. */
3897 adapter = poll_dev->priv;
3898
Auke Kokd3d9e482006-07-14 16:14:23 -07003899 /* e1000_clean is called per-cpu. This lock protects
3900 * tx_ring[0] from being cleaned by multiple cpus
3901 * simultaneously. A failure obtaining the lock means
3902 * tx_ring[0] is currently being cleaned anyway. */
3903 if (spin_trylock(&adapter->tx_queue_lock)) {
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003904 tx_cleaned = e1000_clean_tx_irq(adapter,
3905 &adapter->tx_ring[0]);
Auke Kokd3d9e482006-07-14 16:14:23 -07003906 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003907 }
3908
Auke Kokd3d9e482006-07-14 16:14:23 -07003909 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003910 &work_done, budget);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003911
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003912 if (tx_cleaned)
3913 work_done = budget;
3914
David S. Miller53e52c72008-01-07 21:06:12 -08003915 /* If budget not fully consumed, exit the polling mode */
3916 if (work_done < budget) {
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003917 if (likely(adapter->itr_setting & 3))
3918 e1000_set_itr(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003919 netif_rx_complete(poll_dev, napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 }
3922
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003923 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924}
3925
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926/**
3927 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3928 * @adapter: board private structure
3929 **/
Joe Perches64798842008-07-11 15:17:02 -07003930static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3931 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932{
Joe Perches1dc32912008-07-11 15:17:08 -07003933 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 struct net_device *netdev = adapter->netdev;
3935 struct e1000_tx_desc *tx_desc, *eop_desc;
3936 struct e1000_buffer *buffer_info;
3937 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003938 unsigned int count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07003939 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003940 unsigned int total_tx_bytes=0, total_tx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941
3942 i = tx_ring->next_to_clean;
3943 eop = tx_ring->buffer_info[i].next_to_watch;
3944 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3945
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003946 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Joe Perchesc3033b02008-03-21 11:06:25 -07003947 for (cleaned = false; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 tx_desc = E1000_TX_DESC(*tx_ring, i);
3949 buffer_info = &tx_ring->buffer_info[i];
3950 cleaned = (i == eop);
3951
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003952 if (cleaned) {
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003953 struct sk_buff *skb = buffer_info->skb;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003954 unsigned int segs, bytecount;
3955 segs = skb_shinfo(skb)->gso_segs ?: 1;
3956 /* multiply data chunks by size of headers */
3957 bytecount = ((segs - 1) * skb_headlen(skb)) +
3958 skb->len;
Jesse Brandeburg2b653262006-12-15 10:30:44 +01003959 total_tx_packets += segs;
Jesse Brandeburg7753b172007-01-18 09:25:31 -08003960 total_tx_bytes += bytecount;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08003961 }
Jeff Kirsherfd803242005-12-13 00:06:22 -05003962 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003963 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003965 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003967
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 eop = tx_ring->buffer_info[i].next_to_watch;
3969 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003970#define E1000_TX_WEIGHT 64
3971 /* weight of a sort for tx, to avoid endless transmit cleanup */
Francois Romieuc3570ac2008-07-11 15:17:38 -07003972 if (count++ == E1000_TX_WEIGHT)
3973 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 }
3975
3976 tx_ring->next_to_clean = i;
3977
Auke Kok77b2aad2006-04-14 19:05:25 -07003978#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003979 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3980 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3981 /* Make sure that anybody stopping the queue after this
3982 * sees the new next_to_clean.
3983 */
3984 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003985 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07003986 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003987 ++adapter->restart_queue;
3988 }
Auke Kok77b2aad2006-04-14 19:05:25 -07003989 }
Malli Chilakala26483452005-04-28 19:44:46 -07003990
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003991 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003992 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 * check with the clearing of time_stamp and movement of i */
Joe Perchesc3033b02008-03-21 11:06:25 -07003994 adapter->detect_tx_hung = false;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003995 if (tx_ring->buffer_info[eop].dma &&
3996 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003997 (adapter->tx_timeout_factor * HZ))
Joe Perches1dc32912008-07-11 15:17:08 -07003998 && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003999
4000 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07004001 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004002 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004003 " TDH <%x>\n"
4004 " TDT <%x>\n"
4005 " next_to_use <%x>\n"
4006 " next_to_clean <%x>\n"
4007 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004008 " time_stamp <%lx>\n"
4009 " next_to_watch <%x>\n"
4010 " jiffies <%lx>\n"
4011 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08004012 (unsigned long)((tx_ring - adapter->tx_ring) /
4013 sizeof(struct e1000_tx_ring)),
Joe Perches1dc32912008-07-11 15:17:08 -07004014 readl(hw->hw_addr + tx_ring->tdh),
4015 readl(hw->hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004016 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08004017 tx_ring->next_to_clean,
4018 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004019 eop,
4020 jiffies,
4021 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07004023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 }
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004025 adapter->total_tx_bytes += total_tx_bytes;
4026 adapter->total_tx_packets += total_tx_packets;
Auke Kokef90e4e2007-11-13 20:49:15 -08004027 adapter->net_stats.tx_bytes += total_tx_bytes;
4028 adapter->net_stats.tx_packets += total_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 return cleaned;
4030}
4031
4032/**
4033 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004034 * @adapter: board private structure
4035 * @status_err: receive descriptor status and error fields
4036 * @csum: receive descriptor csum field
4037 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 **/
4039
Joe Perches64798842008-07-11 15:17:02 -07004040static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
4041 u32 csum, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042{
Joe Perches1dc32912008-07-11 15:17:08 -07004043 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004044 u16 status = (u16)status_err;
4045 u8 errors = (u8)(status_err >> 24);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004046 skb->ip_summed = CHECKSUM_NONE;
4047
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 /* 82543 or newer only */
Joe Perches1dc32912008-07-11 15:17:08 -07004049 if (unlikely(hw->mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004051 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004052 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004053 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004054 /* let the stack verify checksum errors */
4055 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 return;
4057 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004058 /* TCP/UDP Checksum has not been calculated */
Joe Perches1dc32912008-07-11 15:17:08 -07004059 if (hw->mac_type <= e1000_82547_rev_2) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004060 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004061 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004063 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004064 return;
4065 }
4066 /* It must be a TCP or UDP packet with a valid checksum */
4067 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 /* TCP checksum is good */
4069 skb->ip_summed = CHECKSUM_UNNECESSARY;
Joe Perches1dc32912008-07-11 15:17:08 -07004070 } else if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004071 /* IP fragment with UDP payload */
4072 /* Hardware complements the payload checksum, so we undo it
4073 * and then put the value in host order for further stack use.
4074 */
Al Viro3e188262007-12-11 19:49:39 +00004075 __sum16 sum = (__force __sum16)htons(csum);
4076 skb->csum = csum_unfold(~sum);
Patrick McHardy84fa7932006-08-29 16:44:56 -07004077 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004079 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080}
4081
4082/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004083 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 * @adapter: board private structure
4085 **/
Joe Perches64798842008-07-11 15:17:02 -07004086static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4087 struct e1000_rx_ring *rx_ring,
4088 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089{
Joe Perches1dc32912008-07-11 15:17:08 -07004090 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 struct net_device *netdev = adapter->netdev;
4092 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004093 struct e1000_rx_desc *rx_desc, *next_rxd;
4094 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 unsigned long flags;
Joe Perches406874a2008-04-03 10:06:32 -07004096 u32 length;
4097 u8 last_byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004099 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004100 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004101 unsigned int total_rx_bytes=0, total_rx_packets=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102
4103 i = rx_ring->next_to_clean;
4104 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004105 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004107 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07004108 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004109 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08004110
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004111 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 break;
4113 (*work_done)++;
Francois Romieuc3570ac2008-07-11 15:17:38 -07004114
Jeff Kirshera292ca62006-01-12 16:51:30 -08004115 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004116 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004117 buffer_info->skb = NULL;
4118
Jeff Kirsher30320be2006-03-02 18:21:57 -08004119 prefetch(skb->data - NET_IP_ALIGN);
4120
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004121 if (++i == rx_ring->count) i = 0;
4122 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004123 prefetch(next_rxd);
4124
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004125 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004126
Joe Perchesc3033b02008-03-21 11:06:25 -07004127 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004128 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004129 pci_unmap_single(pdev,
4130 buffer_info->dma,
4131 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 PCI_DMA_FROMDEVICE);
4133
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 length = le16_to_cpu(rx_desc->length);
4135
Jeff Kirshera1415ee2006-02-28 20:24:07 -08004136 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
4137 /* All receives must fit into a single buffer */
4138 E1000_DBG("%s: Receive packet consumed multiple"
4139 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07004140 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07004141 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 goto next_desc;
4143 }
4144
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004145 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 last_byte = *(skb->data + length - 1);
Joe Perches1dc32912008-07-11 15:17:08 -07004147 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4148 last_byte)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004150 e1000_tbi_adjust_stats(hw, &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 length, skb->data);
4152 spin_unlock_irqrestore(&adapter->stats_lock,
4153 flags);
4154 length--;
4155 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07004156 /* recycle */
4157 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158 goto next_desc;
4159 }
Auke Kok1cb58212006-04-18 12:31:04 -07004160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07004162 /* adjust length to remove Ethernet CRC, this must be
4163 * done after the TBI_ACCEPT workaround above */
4164 length -= 4;
4165
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004166 /* probably a little skewed due to removing CRC */
4167 total_rx_bytes += length;
4168 total_rx_packets++;
4169
Jeff Kirshera292ca62006-01-12 16:51:30 -08004170 /* code added for copybreak, this should improve
4171 * performance for small packets with large amounts
4172 * of reassembly being done in the stack */
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004173 if (length < copybreak) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004174 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07004175 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08004176 if (new_skb) {
4177 skb_reserve(new_skb, NET_IP_ALIGN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004178 skb_copy_to_linear_data_offset(new_skb,
4179 -NET_IP_ALIGN,
4180 (skb->data -
4181 NET_IP_ALIGN),
4182 (length +
4183 NET_IP_ALIGN));
Jeff Kirshera292ca62006-01-12 16:51:30 -08004184 /* save the skb in buffer_info as good */
4185 buffer_info->skb = skb;
4186 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004187 }
Auke Kok996695d2006-11-01 08:47:50 -08004188 /* else just continue with the old one */
4189 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08004190 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08004191 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
4193 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08004194 e1000_rx_checksum(adapter,
Joe Perches406874a2008-04-03 10:06:32 -07004195 (u32)(status) |
4196 ((u32)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004197 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004198
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 skb->protocol = eth_type_trans(skb, netdev);
Francois Romieuc3570ac2008-07-11 15:17:38 -07004200
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004201 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08004202 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004204 le16_to_cpu(rx_desc->special));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 } else {
4206 netif_receive_skb(skb);
4207 }
Francois Romieuc3570ac2008-07-11 15:17:38 -07004208
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 netdev->last_rx = jiffies;
4210
4211next_desc:
4212 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004214 /* return some buffers to hardware, one at a time is too slow */
4215 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4216 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4217 cleaned_count = 0;
4218 }
4219
Jeff Kirsher30320be2006-03-02 18:21:57 -08004220 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004221 rx_desc = next_rxd;
4222 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004225
4226 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4227 if (cleaned_count)
4228 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004230 adapter->total_rx_packets += total_rx_packets;
4231 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004232 adapter->net_stats.rx_bytes += total_rx_bytes;
4233 adapter->net_stats.rx_packets += total_rx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 return cleaned;
4235}
4236
4237/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004238 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
4239 * @adapter: board private structure
4240 **/
4241
Joe Perches64798842008-07-11 15:17:02 -07004242static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4243 struct e1000_rx_ring *rx_ring,
4244 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004245{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004246 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004247 struct net_device *netdev = adapter->netdev;
4248 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004249 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004250 struct e1000_ps_page *ps_page;
4251 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07004252 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004253 unsigned int i, j;
Joe Perches406874a2008-04-03 10:06:32 -07004254 u32 length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004255 int cleaned_count = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004256 bool cleaned = false;
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004257 unsigned int total_rx_bytes=0, total_rx_packets=0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004258
4259 i = rx_ring->next_to_clean;
4260 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07004261 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07004262 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004263
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004264 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004265 ps_page = &rx_ring->ps_page[i];
4266 ps_page_dma = &rx_ring->ps_page_dma[i];
Francois Romieuc3570ac2008-07-11 15:17:38 -07004267
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004268 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004269 break;
4270 (*work_done)++;
Francois Romieuc3570ac2008-07-11 15:17:38 -07004271
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004272 skb = buffer_info->skb;
4273
Jeff Kirsher30320be2006-03-02 18:21:57 -08004274 /* in the packet split case this is header only */
4275 prefetch(skb->data - NET_IP_ALIGN);
4276
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004277 if (++i == rx_ring->count) i = 0;
4278 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08004279 prefetch(next_rxd);
4280
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004281 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004282
Joe Perchesc3033b02008-03-21 11:06:25 -07004283 cleaned = true;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004284 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004285 pci_unmap_single(pdev, buffer_info->dma,
4286 buffer_info->length,
4287 PCI_DMA_FROMDEVICE);
4288
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004289 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004290 E1000_DBG("%s: Packet Split buffers didn't pick up"
4291 " the full packet\n", netdev->name);
4292 dev_kfree_skb_irq(skb);
4293 goto next_desc;
4294 }
4295
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004296 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004297 dev_kfree_skb_irq(skb);
4298 goto next_desc;
4299 }
4300
4301 length = le16_to_cpu(rx_desc->wb.middle.length0);
4302
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004303 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004304 E1000_DBG("%s: Last part of the packet spanning"
4305 " multiple descriptors\n", netdev->name);
4306 dev_kfree_skb_irq(skb);
4307 goto next_desc;
4308 }
4309
4310 /* Good Receive */
4311 skb_put(skb, length);
4312
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004313 {
4314 /* this looks ugly, but it seems compiler issues make it
4315 more efficient than reusing j */
4316 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4317
4318 /* page alloc/put takes too long and effects small packet
4319 * throughput, so unsplit small packets and save the alloc/put*/
Jesse Brandeburg1f753862006-12-15 10:40:39 +01004320 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004321 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004322 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004323 * kmap_atomic, so we can't hold the mapping
4324 * very long */
4325 pci_dma_sync_single_for_cpu(pdev,
4326 ps_page_dma->ps_page_dma[0],
4327 PAGE_SIZE,
4328 PCI_DMA_FROMDEVICE);
4329 vaddr = kmap_atomic(ps_page->ps_page[0],
4330 KM_SKB_DATA_SOFTIRQ);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07004331 memcpy(skb_tail_pointer(skb), vaddr, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004332 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4333 pci_dma_sync_single_for_device(pdev,
4334 ps_page_dma->ps_page_dma[0],
4335 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004336 /* remove the CRC */
4337 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004338 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004339 goto copydone;
4340 } /* if */
4341 }
Auke Kok90fb5132006-11-01 08:47:30 -08004342
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004343 for (j = 0; j < adapter->rx_ps_pages; j++) {
Joe Perchesc7be73b2008-07-11 15:17:28 -07004344 length = le16_to_cpu(rx_desc->wb.upper.length[j]);
4345 if (!length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004346 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004347 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4348 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4349 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004350 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4351 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004352 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004353 skb->len += length;
4354 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004355 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004356 }
4357
Auke Kokf235a2a2006-07-14 16:14:34 -07004358 /* strip the ethernet crc, problem is we're using pages now so
4359 * this whole operation can get a little cpu intensive */
4360 pskb_trim(skb, skb->len - 4);
4361
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004362copydone:
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004363 total_rx_bytes += skb->len;
4364 total_rx_packets++;
4365
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004366 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004367 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004368 skb->protocol = eth_type_trans(skb, netdev);
4369
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004370 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004371 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004372 adapter->rx_hdr_split++;
Francois Romieuc3570ac2008-07-11 15:17:38 -07004373
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004374 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004375 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Patrick McHardy38b22192008-07-06 20:48:41 -07004376 le16_to_cpu(rx_desc->wb.middle.vlan));
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004377 } else {
4378 netif_receive_skb(skb);
4379 }
Francois Romieuc3570ac2008-07-11 15:17:38 -07004380
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004381 netdev->last_rx = jiffies;
4382
4383next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004384 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004385 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004386
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004387 /* return some buffers to hardware, one at a time is too slow */
4388 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4389 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4390 cleaned_count = 0;
4391 }
4392
Jeff Kirsher30320be2006-03-02 18:21:57 -08004393 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004394 rx_desc = next_rxd;
4395 buffer_info = next_buffer;
4396
Malli Chilakala683a38f2005-06-17 17:43:25 -07004397 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004398 }
4399 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004400
4401 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4402 if (cleaned_count)
4403 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004404
Jesse Brandeburg835bb122006-11-01 08:48:13 -08004405 adapter->total_rx_packets += total_rx_packets;
4406 adapter->total_rx_bytes += total_rx_bytes;
Auke Kokef90e4e2007-11-13 20:49:15 -08004407 adapter->net_stats.rx_bytes += total_rx_bytes;
4408 adapter->net_stats.rx_packets += total_rx_packets;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004409 return cleaned;
4410}
4411
4412/**
4413 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 * @adapter: address of board private structure
4415 **/
4416
Joe Perches64798842008-07-11 15:17:02 -07004417static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4418 struct e1000_rx_ring *rx_ring,
4419 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420{
Joe Perches1dc32912008-07-11 15:17:08 -07004421 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 struct net_device *netdev = adapter->netdev;
4423 struct pci_dev *pdev = adapter->pdev;
4424 struct e1000_rx_desc *rx_desc;
4425 struct e1000_buffer *buffer_info;
4426 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004427 unsigned int i;
4428 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429
4430 i = rx_ring->next_to_use;
4431 buffer_info = &rx_ring->buffer_info[i];
4432
Jeff Kirshera292ca62006-01-12 16:51:30 -08004433 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004434 skb = buffer_info->skb;
4435 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004436 skb_trim(skb, 0);
4437 goto map_skb;
4438 }
4439
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004440 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004441 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004443 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 break;
4445 }
4446
Malli Chilakala26483452005-04-28 19:44:46 -07004447 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4449 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004450 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4451 "at %p\n", bufsz, skb->data);
4452 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004453 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004454 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 if (!skb) {
4456 dev_kfree_skb(oldskb);
4457 break;
4458 }
Malli Chilakala26483452005-04-28 19:44:46 -07004459
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4461 /* give up */
4462 dev_kfree_skb(skb);
4463 dev_kfree_skb(oldskb);
4464 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004466
4467 /* Use new allocation */
4468 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 /* Make buffer alignment 2 beyond a 16 byte boundary
4471 * this will result in a 16 byte aligned IP header after
4472 * the 14 byte MAC header is removed
4473 */
4474 skb_reserve(skb, NET_IP_ALIGN);
4475
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 buffer_info->skb = skb;
4477 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004478map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 buffer_info->dma = pci_map_single(pdev,
4480 skb->data,
4481 adapter->rx_buffer_len,
4482 PCI_DMA_FROMDEVICE);
4483
Malli Chilakala26483452005-04-28 19:44:46 -07004484 /* Fix for errata 23, can't cross 64kB boundary */
4485 if (!e1000_check_64k_bound(adapter,
4486 (void *)(unsigned long)buffer_info->dma,
4487 adapter->rx_buffer_len)) {
4488 DPRINTK(RX_ERR, ERR,
4489 "dma align check failed: %u bytes at %p\n",
4490 adapter->rx_buffer_len,
4491 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492 dev_kfree_skb(skb);
4493 buffer_info->skb = NULL;
4494
Malli Chilakala26483452005-04-28 19:44:46 -07004495 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 adapter->rx_buffer_len,
4497 PCI_DMA_FROMDEVICE);
4498
4499 break; /* while !buffer_info->skb */
4500 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501 rx_desc = E1000_RX_DESC(*rx_ring, i);
4502 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4503
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004504 if (unlikely(++i == rx_ring->count))
4505 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 buffer_info = &rx_ring->buffer_info[i];
4507 }
4508
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004509 if (likely(rx_ring->next_to_use != i)) {
4510 rx_ring->next_to_use = i;
4511 if (unlikely(i-- == 0))
4512 i = (rx_ring->count - 1);
4513
4514 /* Force memory writes to complete before letting h/w
4515 * know there are new descriptors to fetch. (Only
4516 * applicable for weak-ordered memory model archs,
4517 * such as IA-64). */
4518 wmb();
Joe Perches1dc32912008-07-11 15:17:08 -07004519 writel(i, hw->hw_addr + rx_ring->rdt);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521}
4522
4523/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004524 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4525 * @adapter: address of board private structure
4526 **/
4527
Joe Perches64798842008-07-11 15:17:02 -07004528static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
4529 struct e1000_rx_ring *rx_ring,
4530 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004531{
Joe Perches1dc32912008-07-11 15:17:08 -07004532 struct e1000_hw *hw = &adapter->hw;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004533 struct net_device *netdev = adapter->netdev;
4534 struct pci_dev *pdev = adapter->pdev;
4535 union e1000_rx_desc_packet_split *rx_desc;
4536 struct e1000_buffer *buffer_info;
4537 struct e1000_ps_page *ps_page;
4538 struct e1000_ps_page_dma *ps_page_dma;
4539 struct sk_buff *skb;
4540 unsigned int i, j;
4541
4542 i = rx_ring->next_to_use;
4543 buffer_info = &rx_ring->buffer_info[i];
4544 ps_page = &rx_ring->ps_page[i];
4545 ps_page_dma = &rx_ring->ps_page_dma[i];
4546
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004547 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004548 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4549
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004550 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004551 if (j < adapter->rx_ps_pages) {
4552 if (likely(!ps_page->ps_page[j])) {
4553 ps_page->ps_page[j] =
4554 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004555 if (unlikely(!ps_page->ps_page[j])) {
4556 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004557 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004558 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004559 ps_page_dma->ps_page_dma[j] =
4560 pci_map_page(pdev,
4561 ps_page->ps_page[j],
4562 0, PAGE_SIZE,
4563 PCI_DMA_FROMDEVICE);
4564 }
4565 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004566 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004567 * this info.
4568 */
4569 rx_desc->read.buffer_addr[j+1] =
4570 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4571 } else
Al Viro3e188262007-12-11 19:49:39 +00004572 rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004573 }
4574
David S. Miller87f50322006-07-31 22:39:40 -07004575 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004576 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004577
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004578 if (unlikely(!skb)) {
4579 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004580 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004581 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004582
4583 /* Make buffer alignment 2 beyond a 16 byte boundary
4584 * this will result in a 16 byte aligned IP header after
4585 * the 14 byte MAC header is removed
4586 */
4587 skb_reserve(skb, NET_IP_ALIGN);
4588
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004589 buffer_info->skb = skb;
4590 buffer_info->length = adapter->rx_ps_bsize0;
4591 buffer_info->dma = pci_map_single(pdev, skb->data,
4592 adapter->rx_ps_bsize0,
4593 PCI_DMA_FROMDEVICE);
4594
4595 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4596
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004597 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004598 buffer_info = &rx_ring->buffer_info[i];
4599 ps_page = &rx_ring->ps_page[i];
4600 ps_page_dma = &rx_ring->ps_page_dma[i];
4601 }
4602
4603no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004604 if (likely(rx_ring->next_to_use != i)) {
4605 rx_ring->next_to_use = i;
4606 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4607
4608 /* Force memory writes to complete before letting h/w
4609 * know there are new descriptors to fetch. (Only
4610 * applicable for weak-ordered memory model archs,
4611 * such as IA-64). */
4612 wmb();
4613 /* Hardware increments by 16 bytes, but packet split
4614 * descriptors are 32 bytes...so we increment tail
4615 * twice as much.
4616 */
Joe Perches1dc32912008-07-11 15:17:08 -07004617 writel(i<<1, hw->hw_addr + rx_ring->rdt);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004618 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004619}
4620
4621/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4623 * @adapter:
4624 **/
4625
Joe Perches64798842008-07-11 15:17:02 -07004626static void e1000_smartspeed(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627{
Joe Perches1dc32912008-07-11 15:17:08 -07004628 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004629 u16 phy_status;
4630 u16 phy_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631
Joe Perches1dc32912008-07-11 15:17:08 -07004632 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4633 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 return;
4635
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004636 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 /* If Master/Slave config fault is asserted twice,
4638 * we assume back-to-back */
Joe Perches1dc32912008-07-11 15:17:08 -07004639 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004640 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Joe Perches1dc32912008-07-11 15:17:08 -07004641 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004642 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Joe Perches1dc32912008-07-11 15:17:08 -07004643 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004644 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 phy_ctrl &= ~CR_1000T_MS_ENABLE;
Joe Perches1dc32912008-07-11 15:17:08 -07004646 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 phy_ctrl);
4648 adapter->smartspeed++;
Joe Perches1dc32912008-07-11 15:17:08 -07004649 if (!e1000_phy_setup_autoneg(hw) &&
4650 !e1000_read_phy_reg(hw, PHY_CTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 &phy_ctrl)) {
4652 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,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 phy_ctrl);
4656 }
4657 }
4658 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004659 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 /* If still no link, perhaps using 2/3 pair cable */
Joe Perches1dc32912008-07-11 15:17:08 -07004661 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 phy_ctrl |= CR_1000T_MS_ENABLE;
Joe Perches1dc32912008-07-11 15:17:08 -07004663 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4664 if (!e1000_phy_setup_autoneg(hw) &&
4665 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4667 MII_CR_RESTART_AUTO_NEG);
Joe Perches1dc32912008-07-11 15:17:08 -07004668 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 }
4670 }
4671 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004672 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673 adapter->smartspeed = 0;
4674}
4675
4676/**
4677 * e1000_ioctl -
4678 * @netdev:
4679 * @ifreq:
4680 * @cmd:
4681 **/
4682
Joe Perches64798842008-07-11 15:17:02 -07004683static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684{
4685 switch (cmd) {
4686 case SIOCGMIIPHY:
4687 case SIOCGMIIREG:
4688 case SIOCSMIIREG:
4689 return e1000_mii_ioctl(netdev, ifr, cmd);
4690 default:
4691 return -EOPNOTSUPP;
4692 }
4693}
4694
4695/**
4696 * e1000_mii_ioctl -
4697 * @netdev:
4698 * @ifreq:
4699 * @cmd:
4700 **/
4701
Joe Perches64798842008-07-11 15:17:02 -07004702static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4703 int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004705 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004706 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707 struct mii_ioctl_data *data = if_mii(ifr);
4708 int retval;
Joe Perches406874a2008-04-03 10:06:32 -07004709 u16 mii_reg;
4710 u16 spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004711 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712
Joe Perches1dc32912008-07-11 15:17:08 -07004713 if (hw->media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714 return -EOPNOTSUPP;
4715
4716 switch (cmd) {
4717 case SIOCGMIIPHY:
Joe Perches1dc32912008-07-11 15:17:08 -07004718 data->phy_id = hw->phy_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 break;
4720 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004721 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722 return -EPERM;
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_read_phy_reg(hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004725 &data->val_out)) {
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 }
4729 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 break;
4731 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004732 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004734 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 return -EFAULT;
4736 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004737 spin_lock_irqsave(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004738 if (e1000_write_phy_reg(hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004739 mii_reg)) {
4740 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004742 }
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004743 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Joe Perches1dc32912008-07-11 15:17:08 -07004744 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 switch (data->reg_num) {
4746 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004747 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004749 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Joe Perches1dc32912008-07-11 15:17:08 -07004750 hw->autoneg = 1;
4751 hw->autoneg_advertised = 0x2F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 } else {
4753 if (mii_reg & 0x40)
4754 spddplx = SPEED_1000;
4755 else if (mii_reg & 0x2000)
4756 spddplx = SPEED_100;
4757 else
4758 spddplx = SPEED_10;
4759 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004760 ? DUPLEX_FULL :
4761 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 retval = e1000_set_spd_dplx(adapter,
4763 spddplx);
Jesse Brandeburgf0163ac2007-11-13 21:00:09 -08004764 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 return retval;
4766 }
Auke Kok2db10a02006-06-27 09:06:28 -07004767 if (netif_running(adapter->netdev))
4768 e1000_reinit_locked(adapter);
4769 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 e1000_reset(adapter);
4771 break;
4772 case M88E1000_PHY_SPEC_CTRL:
4773 case M88E1000_EXT_PHY_SPEC_CTRL:
Joe Perches1dc32912008-07-11 15:17:08 -07004774 if (e1000_phy_reset(hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 return -EIO;
4776 break;
4777 }
4778 } else {
4779 switch (data->reg_num) {
4780 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004781 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004783 if (netif_running(adapter->netdev))
4784 e1000_reinit_locked(adapter);
4785 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 e1000_reset(adapter);
4787 break;
4788 }
4789 }
4790 break;
4791 default:
4792 return -EOPNOTSUPP;
4793 }
4794 return E1000_SUCCESS;
4795}
4796
Joe Perches64798842008-07-11 15:17:02 -07004797void e1000_pci_set_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798{
4799 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004800 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004802 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004803 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804}
4805
Joe Perches64798842008-07-11 15:17:02 -07004806void e1000_pci_clear_mwi(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807{
4808 struct e1000_adapter *adapter = hw->back;
4809
4810 pci_clear_mwi(adapter->pdev);
4811}
4812
Joe Perches64798842008-07-11 15:17:02 -07004813int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
Peter Oruba007755e2007-09-28 22:42:06 -07004814{
4815 struct e1000_adapter *adapter = hw->back;
4816 return pcix_get_mmrbc(adapter->pdev);
4817}
4818
Joe Perches64798842008-07-11 15:17:02 -07004819void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
Peter Oruba007755e2007-09-28 22:42:06 -07004820{
4821 struct e1000_adapter *adapter = hw->back;
4822 pcix_set_mmrbc(adapter->pdev, mmrbc);
4823}
4824
Joe Perches64798842008-07-11 15:17:02 -07004825s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004826{
4827 struct e1000_adapter *adapter = hw->back;
Joe Perches406874a2008-04-03 10:06:32 -07004828 u16 cap_offset;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004829
4830 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4831 if (!cap_offset)
4832 return -E1000_ERR_CONFIG;
4833
4834 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4835
4836 return E1000_SUCCESS;
4837}
4838
Joe Perches64798842008-07-11 15:17:02 -07004839void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840{
4841 outl(value, port);
4842}
4843
Joe Perches64798842008-07-11 15:17:02 -07004844static void e1000_vlan_rx_register(struct net_device *netdev,
4845 struct vlan_group *grp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004847 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004848 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004849 u32 ctrl, rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004851 if (!test_bit(__E1000_DOWN, &adapter->flags))
4852 e1000_irq_disable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853 adapter->vlgrp = grp;
4854
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004855 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856 /* enable VLAN tag insert/strip */
Joe Perches1dc32912008-07-11 15:17:08 -07004857 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 ctrl |= E1000_CTRL_VME;
Joe Perches1dc32912008-07-11 15:17:08 -07004859 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860
Auke Kokcd94dd02006-06-27 09:08:22 -07004861 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004862 /* enable VLAN receive filtering */
Joe Perches1dc32912008-07-11 15:17:08 -07004863 rctl = er32(RCTL);
Auke Kok90fb5132006-11-01 08:47:30 -08004864 rctl &= ~E1000_RCTL_CFIEN;
Joe Perches1dc32912008-07-11 15:17:08 -07004865 ew32(RCTL, rctl);
Auke Kok90fb5132006-11-01 08:47:30 -08004866 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 } else {
4869 /* disable VLAN tag insert/strip */
Joe Perches1dc32912008-07-11 15:17:08 -07004870 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871 ctrl &= ~E1000_CTRL_VME;
Joe Perches1dc32912008-07-11 15:17:08 -07004872 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873
Auke Kokcd94dd02006-06-27 09:08:22 -07004874 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004875 if (adapter->mng_vlan_id !=
Joe Perches406874a2008-04-03 10:06:32 -07004876 (u16)E1000_MNG_VLAN_NONE) {
Auke Kok90fb5132006-11-01 08:47:30 -08004877 e1000_vlan_rx_kill_vid(netdev,
4878 adapter->mng_vlan_id);
4879 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4880 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004881 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882 }
4883
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004884 if (!test_bit(__E1000_DOWN, &adapter->flags))
4885 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886}
4887
Joe Perches64798842008-07-11 15:17:02 -07004888static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004890 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004891 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004892 u32 vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004893
Joe Perches1dc32912008-07-11 15:17:08 -07004894 if ((hw->mng_cookie.status &
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004895 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4896 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004897 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 /* add VID to filter table */
4899 index = (vid >> 5) & 0x7F;
Joe Perches1dc32912008-07-11 15:17:08 -07004900 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 vfta |= (1 << (vid & 0x1F));
Joe Perches1dc32912008-07-11 15:17:08 -07004902 e1000_write_vfta(hw, index, vfta);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903}
4904
Joe Perches64798842008-07-11 15:17:02 -07004905static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004907 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004908 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004909 u32 vfta, index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004911 if (!test_bit(__E1000_DOWN, &adapter->flags))
4912 e1000_irq_disable(adapter);
Dan Aloni5c15bde2007-03-02 20:44:51 -08004913 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Jesse Brandeburg9150b762008-03-21 11:06:58 -07004914 if (!test_bit(__E1000_DOWN, &adapter->flags))
4915 e1000_irq_enable(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916
Joe Perches1dc32912008-07-11 15:17:08 -07004917 if ((hw->mng_cookie.status &
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004918 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004919 (vid == adapter->mng_vlan_id)) {
4920 /* release control to f/w */
4921 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004922 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004923 }
4924
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925 /* remove VID from filter table */
4926 index = (vid >> 5) & 0x7F;
Joe Perches1dc32912008-07-11 15:17:08 -07004927 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928 vfta &= ~(1 << (vid & 0x1F));
Joe Perches1dc32912008-07-11 15:17:08 -07004929 e1000_write_vfta(hw, index, vfta);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930}
4931
Joe Perches64798842008-07-11 15:17:02 -07004932static void e1000_restore_vlan(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933{
4934 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4935
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004936 if (adapter->vlgrp) {
Joe Perches406874a2008-04-03 10:06:32 -07004937 u16 vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004938 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08004939 if (!vlan_group_get_device(adapter->vlgrp, vid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004940 continue;
4941 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4942 }
4943 }
4944}
4945
Joe Perches64798842008-07-11 15:17:02 -07004946int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947{
Joe Perches1dc32912008-07-11 15:17:08 -07004948 struct e1000_hw *hw = &adapter->hw;
4949
4950 hw->autoneg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951
Malli Chilakala69213682005-06-17 17:44:20 -07004952 /* Fiber NICs only allow 1000 gbps Full duplex */
Joe Perches1dc32912008-07-11 15:17:08 -07004953 if ((hw->media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004954 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4955 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4956 return -EINVAL;
4957 }
4958
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004959 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 case SPEED_10 + DUPLEX_HALF:
Joe Perches1dc32912008-07-11 15:17:08 -07004961 hw->forced_speed_duplex = e1000_10_half;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 break;
4963 case SPEED_10 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07004964 hw->forced_speed_duplex = e1000_10_full;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965 break;
4966 case SPEED_100 + DUPLEX_HALF:
Joe Perches1dc32912008-07-11 15:17:08 -07004967 hw->forced_speed_duplex = e1000_100_half;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968 break;
4969 case SPEED_100 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07004970 hw->forced_speed_duplex = e1000_100_full;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 break;
4972 case SPEED_1000 + DUPLEX_FULL:
Joe Perches1dc32912008-07-11 15:17:08 -07004973 hw->autoneg = 1;
4974 hw->autoneg_advertised = ADVERTISE_1000_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 break;
4976 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4977 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004978 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 return -EINVAL;
4980 }
4981 return 0;
4982}
4983
Joe Perches64798842008-07-11 15:17:02 -07004984static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985{
4986 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004987 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07004988 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07004989 u32 ctrl, ctrl_ext, rctl, status;
4990 u32 wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07004991#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08004992 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07004993#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994
4995 netif_device_detach(netdev);
4996
Auke Kok2db10a02006-06-27 09:06:28 -07004997 if (netif_running(netdev)) {
4998 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07005000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005002#ifdef CONFIG_PM
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005003 retval = pci_save_state(pdev);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005004 if (retval)
5005 return retval;
5006#endif
5007
Joe Perches1dc32912008-07-11 15:17:08 -07005008 status = er32(STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005009 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 wufc &= ~E1000_WUFC_LNKC;
5011
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005012 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 e1000_setup_rctl(adapter);
Patrick McHardydb0ce502007-11-13 20:54:59 -08005014 e1000_set_rx_mode(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015
5016 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07005017 if (wufc & E1000_WUFC_MC) {
Joe Perches1dc32912008-07-11 15:17:08 -07005018 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 rctl |= E1000_RCTL_MPE;
Joe Perches1dc32912008-07-11 15:17:08 -07005020 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021 }
5022
Joe Perches1dc32912008-07-11 15:17:08 -07005023 if (hw->mac_type >= e1000_82540) {
5024 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 /* advertise wake from D3Cold */
5026 #define E1000_CTRL_ADVD3WUC 0x00100000
5027 /* phy power management enable */
5028 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5029 ctrl |= E1000_CTRL_ADVD3WUC |
5030 E1000_CTRL_EN_PHY_PWR_MGMT;
Joe Perches1dc32912008-07-11 15:17:08 -07005031 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 }
5033
Joe Perches1dc32912008-07-11 15:17:08 -07005034 if (hw->media_type == e1000_media_type_fiber ||
5035 hw->media_type == e1000_media_type_internal_serdes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036 /* keep the laser running in D3 */
Joe Perches1dc32912008-07-11 15:17:08 -07005037 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07005039 ew32(CTRL_EXT, ctrl_ext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040 }
5041
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005042 /* Allow time for pending master requests to run */
Joe Perches1dc32912008-07-11 15:17:08 -07005043 e1000_disable_pciex_master(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005044
Joe Perches1dc32912008-07-11 15:17:08 -07005045 ew32(WUC, E1000_WUC_PME_EN);
5046 ew32(WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07005047 pci_enable_wake(pdev, PCI_D3hot, 1);
5048 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07005050 ew32(WUC, 0);
5051 ew32(WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07005052 pci_enable_wake(pdev, PCI_D3hot, 0);
5053 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054 }
5055
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005056 e1000_release_manageability(adapter);
5057
5058 /* make sure adapter isn't asleep if manageability is enabled */
5059 if (adapter->en_mng_pt) {
5060 pci_enable_wake(pdev, PCI_D3hot, 1);
5061 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 }
5063
Joe Perches1dc32912008-07-11 15:17:08 -07005064 if (hw->phy_type == e1000_phy_igp_3)
5065 e1000_phy_powerdown_workaround(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005066
Auke Kokedd106f2006-11-06 08:57:12 -08005067 if (netif_running(netdev))
5068 e1000_free_irq(adapter);
5069
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005070 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5071 * would have already happened in close and is redundant. */
5072 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005073
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08005075
Auke Kokd0e027d2006-04-14 19:04:40 -07005076 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077
5078 return 0;
5079}
5080
Jesse Brandeburg2f826652006-01-18 13:01:34 -08005081#ifdef CONFIG_PM
Joe Perches64798842008-07-11 15:17:02 -07005082static int e1000_resume(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083{
5084 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07005085 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07005086 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07005087 u32 err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088
Auke Kokd0e027d2006-04-14 19:04:40 -07005089 pci_set_power_state(pdev, PCI_D0);
Kok, Auke1d33e9c2007-02-16 14:39:28 -08005090 pci_restore_state(pdev);
Taku Izumi81250292008-07-11 15:17:44 -07005091
5092 if (adapter->need_ioport)
5093 err = pci_enable_device(pdev);
5094 else
5095 err = pci_enable_device_mem(pdev);
Joe Perchesc7be73b2008-07-11 15:17:28 -07005096 if (err) {
Auke Kok3d1dd8c2006-08-28 14:56:27 -07005097 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5098 return err;
5099 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07005100 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101
Auke Kokd0e027d2006-04-14 19:04:40 -07005102 pci_enable_wake(pdev, PCI_D3hot, 0);
5103 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104
Joe Perchesc7be73b2008-07-11 15:17:28 -07005105 if (netif_running(netdev)) {
5106 err = e1000_request_irq(adapter);
5107 if (err)
5108 return err;
5109 }
Auke Kokedd106f2006-11-06 08:57:12 -08005110
5111 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 e1000_reset(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07005113 ew32(WUS, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005115 e1000_init_manageability(adapter);
5116
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005117 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118 e1000_up(adapter);
5119
5120 netif_device_attach(netdev);
5121
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005122 /* If the controller is 82573 and f/w is AMT, do not set
5123 * DRV_LOAD until the interface is up. For all other cases,
5124 * let the f/w know that the h/w is now under the control
5125 * of the driver. */
Joe Perches1dc32912008-07-11 15:17:08 -07005126 if (hw->mac_type != e1000_82573 ||
5127 !e1000_check_mng_mode(hw))
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08005128 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005129
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130 return 0;
5131}
5132#endif
Auke Kokc653e632006-05-23 13:35:57 -07005133
5134static void e1000_shutdown(struct pci_dev *pdev)
5135{
5136 e1000_suspend(pdev, PMSG_SUSPEND);
5137}
5138
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139#ifdef CONFIG_NET_POLL_CONTROLLER
5140/*
5141 * Polling 'interrupt' - used by things like netconsole to send skbs
5142 * without having to re-enable interrupts. It's not called while
5143 * the interrupt routine is executing.
5144 */
Joe Perches64798842008-07-11 15:17:02 -07005145static void e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005146{
Malli Chilakala60490fe2005-06-17 17:41:45 -07005147 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07005148
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01005150 e1000_intr(adapter->pdev->irq, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151 enable_irq(adapter->pdev->irq);
5152}
5153#endif
5154
Auke Kok90267292006-06-08 09:30:24 -07005155/**
5156 * e1000_io_error_detected - called when PCI error is detected
5157 * @pdev: Pointer to PCI device
5158 * @state: The current pci conneection state
5159 *
5160 * This function is called after a PCI bus error affecting
5161 * this device has been detected.
5162 */
Joe Perches64798842008-07-11 15:17:02 -07005163static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5164 pci_channel_state_t state)
Auke Kok90267292006-06-08 09:30:24 -07005165{
5166 struct net_device *netdev = pci_get_drvdata(pdev);
5167 struct e1000_adapter *adapter = netdev->priv;
5168
5169 netif_device_detach(netdev);
5170
5171 if (netif_running(netdev))
5172 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07005173 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07005174
5175 /* Request a slot slot reset. */
5176 return PCI_ERS_RESULT_NEED_RESET;
5177}
5178
5179/**
5180 * e1000_io_slot_reset - called after the pci bus has been reset.
5181 * @pdev: Pointer to PCI device
5182 *
5183 * Restart the card from scratch, as if from a cold-boot. Implementation
5184 * resembles the first-half of the e1000_resume routine.
5185 */
5186static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5187{
5188 struct net_device *netdev = pci_get_drvdata(pdev);
5189 struct e1000_adapter *adapter = netdev->priv;
Joe Perches1dc32912008-07-11 15:17:08 -07005190 struct e1000_hw *hw = &adapter->hw;
Taku Izumi81250292008-07-11 15:17:44 -07005191 int err;
Auke Kok90267292006-06-08 09:30:24 -07005192
Taku Izumi81250292008-07-11 15:17:44 -07005193 if (adapter->need_ioport)
5194 err = pci_enable_device(pdev);
5195 else
5196 err = pci_enable_device_mem(pdev);
5197 if (err) {
Auke Kok90267292006-06-08 09:30:24 -07005198 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
5199 return PCI_ERS_RESULT_DISCONNECT;
5200 }
5201 pci_set_master(pdev);
5202
Linas Vepstasdbf38c92006-09-27 12:54:11 -07005203 pci_enable_wake(pdev, PCI_D3hot, 0);
5204 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07005205
Auke Kok90267292006-06-08 09:30:24 -07005206 e1000_reset(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07005207 ew32(WUS, ~0);
Auke Kok90267292006-06-08 09:30:24 -07005208
5209 return PCI_ERS_RESULT_RECOVERED;
5210}
5211
5212/**
5213 * e1000_io_resume - called when traffic can start flowing again.
5214 * @pdev: Pointer to PCI device
5215 *
5216 * This callback is called when the error recovery driver tells us that
5217 * its OK to resume normal operation. Implementation resembles the
5218 * second-half of the e1000_resume routine.
5219 */
5220static void e1000_io_resume(struct pci_dev *pdev)
5221{
5222 struct net_device *netdev = pci_get_drvdata(pdev);
5223 struct e1000_adapter *adapter = netdev->priv;
Joe Perches1dc32912008-07-11 15:17:08 -07005224 struct e1000_hw *hw = &adapter->hw;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005225
5226 e1000_init_manageability(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005227
5228 if (netif_running(netdev)) {
5229 if (e1000_up(adapter)) {
5230 printk("e1000: can't bring device back up after reset\n");
5231 return;
5232 }
5233 }
5234
5235 netif_device_attach(netdev);
5236
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005237 /* If the controller is 82573 and f/w is AMT, do not set
5238 * DRV_LOAD until the interface is up. For all other cases,
5239 * let the f/w know that the h/w is now under the control
5240 * of the driver. */
Joe Perches1dc32912008-07-11 15:17:08 -07005241 if (hw->mac_type != e1000_82573 ||
5242 !e1000_check_mng_mode(hw))
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05005243 e1000_get_hw_control(adapter);
Auke Kok90267292006-06-08 09:30:24 -07005244
Auke Kok90267292006-06-08 09:30:24 -07005245}
5246
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247/* e1000_main.c */