blob: a373ccb308d8d3281298bee38c1a5dcbfcc8ca7f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
3
Auke Kok3d41e302006-04-14 19:05:31 -07004 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 The full GNU General Public License is included in this distribution in the
21 file called LICENSE.
22
23 Contact Information:
24 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070025 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27
28*******************************************************************************/
29
30#include "e1000.h"
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032char e1000_driver_name[] = "e1000";
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010033static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#ifndef CONFIG_E1000_NAPI
35#define DRIVERNAPI
36#else
37#define DRIVERNAPI "-NAPI"
38#endif
Auke Kok440c0522006-05-23 13:36:19 -070039#define DRV_VERSION "7.0.38-k4"DRIVERNAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -070040char e1000_driver_version[] = DRV_VERSION;
Auke Kok3d41e302006-04-14 19:05:31 -070041static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* e1000_pci_tbl - PCI Device ID Table
44 *
45 * Last entry must be all 0s
46 *
47 * Macro expands to...
48 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
49 */
50static struct pci_device_id e1000_pci_tbl[] = {
51 INTEL_E1000_ETHERNET_DEVICE(0x1000),
52 INTEL_E1000_ETHERNET_DEVICE(0x1001),
53 INTEL_E1000_ETHERNET_DEVICE(0x1004),
54 INTEL_E1000_ETHERNET_DEVICE(0x1008),
55 INTEL_E1000_ETHERNET_DEVICE(0x1009),
56 INTEL_E1000_ETHERNET_DEVICE(0x100C),
57 INTEL_E1000_ETHERNET_DEVICE(0x100D),
58 INTEL_E1000_ETHERNET_DEVICE(0x100E),
59 INTEL_E1000_ETHERNET_DEVICE(0x100F),
60 INTEL_E1000_ETHERNET_DEVICE(0x1010),
61 INTEL_E1000_ETHERNET_DEVICE(0x1011),
62 INTEL_E1000_ETHERNET_DEVICE(0x1012),
63 INTEL_E1000_ETHERNET_DEVICE(0x1013),
64 INTEL_E1000_ETHERNET_DEVICE(0x1014),
65 INTEL_E1000_ETHERNET_DEVICE(0x1015),
66 INTEL_E1000_ETHERNET_DEVICE(0x1016),
67 INTEL_E1000_ETHERNET_DEVICE(0x1017),
68 INTEL_E1000_ETHERNET_DEVICE(0x1018),
69 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -070070 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 INTEL_E1000_ETHERNET_DEVICE(0x101D),
72 INTEL_E1000_ETHERNET_DEVICE(0x101E),
73 INTEL_E1000_ETHERNET_DEVICE(0x1026),
74 INTEL_E1000_ETHERNET_DEVICE(0x1027),
75 INTEL_E1000_ETHERNET_DEVICE(0x1028),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040076 INTEL_E1000_ETHERNET_DEVICE(0x105E),
77 INTEL_E1000_ETHERNET_DEVICE(0x105F),
78 INTEL_E1000_ETHERNET_DEVICE(0x1060),
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 INTEL_E1000_ETHERNET_DEVICE(0x1075),
80 INTEL_E1000_ETHERNET_DEVICE(0x1076),
81 INTEL_E1000_ETHERNET_DEVICE(0x1077),
82 INTEL_E1000_ETHERNET_DEVICE(0x1078),
83 INTEL_E1000_ETHERNET_DEVICE(0x1079),
84 INTEL_E1000_ETHERNET_DEVICE(0x107A),
85 INTEL_E1000_ETHERNET_DEVICE(0x107B),
86 INTEL_E1000_ETHERNET_DEVICE(0x107C),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040087 INTEL_E1000_ETHERNET_DEVICE(0x107D),
88 INTEL_E1000_ETHERNET_DEVICE(0x107E),
89 INTEL_E1000_ETHERNET_DEVICE(0x107F),
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Malli Chilakala26483452005-04-28 19:44:46 -070091 INTEL_E1000_ETHERNET_DEVICE(0x108B),
92 INTEL_E1000_ETHERNET_DEVICE(0x108C),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -080093 INTEL_E1000_ETHERNET_DEVICE(0x1096),
94 INTEL_E1000_ETHERNET_DEVICE(0x1098),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080095 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040096 INTEL_E1000_ETHERNET_DEVICE(0x109A),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080097 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -080098 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 /* required last entry */
100 {0,}
101};
102
103MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
104
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100105static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800106 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100107static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800108 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100109static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800110 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100111static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800112 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114/* Local Function Prototypes */
115
116static int e1000_init_module(void);
117static void e1000_exit_module(void);
118static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
119static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400120static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121static int e1000_sw_init(struct e1000_adapter *adapter);
122static int e1000_open(struct net_device *netdev);
123static int e1000_close(struct net_device *netdev);
124static void e1000_configure_tx(struct e1000_adapter *adapter);
125static void e1000_configure_rx(struct e1000_adapter *adapter);
126static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400127static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
128static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
129static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
130 struct e1000_tx_ring *tx_ring);
131static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
132 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static void e1000_set_multi(struct net_device *netdev);
134static void e1000_update_phy_info(unsigned long data);
135static void e1000_watchdog(unsigned long data);
136static void e1000_watchdog_task(struct e1000_adapter *adapter);
137static void e1000_82547_tx_fifo_stall(unsigned long data);
138static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
139static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
140static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
141static int e1000_set_mac(struct net_device *netdev, void *p);
142static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400143static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
144 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400146static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400148 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700150static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400151 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700152 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400154static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
155 struct e1000_rx_ring *rx_ring);
156static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
157 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400159static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800160 struct e1000_rx_ring *rx_ring,
161 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400162static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800163 struct e1000_rx_ring *rx_ring,
164 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
166static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
167 int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
169static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
170static void e1000_tx_timeout(struct net_device *dev);
Jeff Kirsher87041632006-03-02 18:21:24 -0800171static void e1000_reset_task(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700173static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
174 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
177static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
178static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
179static void e1000_restore_vlan(struct e1000_adapter *adapter);
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#ifdef CONFIG_PM
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700182static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183static int e1000_resume(struct pci_dev *pdev);
184#endif
Auke Kokc653e632006-05-23 13:35:57 -0700185static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187#ifdef CONFIG_NET_POLL_CONTROLLER
188/* for netdump / net console */
189static void e1000_netpoll (struct net_device *netdev);
190#endif
191
Auke Kok90267292006-06-08 09:30:24 -0700192static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
193 pci_channel_state_t state);
194static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
195static void e1000_io_resume(struct pci_dev *pdev);
196
197static struct pci_error_handlers e1000_err_handler = {
198 .error_detected = e1000_io_error_detected,
199 .slot_reset = e1000_io_slot_reset,
200 .resume = e1000_io_resume,
201};
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -0400202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203static struct pci_driver e1000_driver = {
204 .name = e1000_driver_name,
205 .id_table = e1000_pci_tbl,
206 .probe = e1000_probe,
207 .remove = __devexit_p(e1000_remove),
208 /* Power Managment Hooks */
209#ifdef CONFIG_PM
210 .suspend = e1000_suspend,
Auke Kokc653e632006-05-23 13:35:57 -0700211 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#endif
Auke Kok90267292006-06-08 09:30:24 -0700213 .shutdown = e1000_shutdown,
214 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215};
216
217MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
218MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
219MODULE_LICENSE("GPL");
220MODULE_VERSION(DRV_VERSION);
221
222static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
223module_param(debug, int, 0);
224MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
225
226/**
227 * e1000_init_module - Driver Registration Routine
228 *
229 * e1000_init_module is the first routine called when the driver is
230 * loaded. All it does is register with the PCI subsystem.
231 **/
232
233static int __init
234e1000_init_module(void)
235{
236 int ret;
237 printk(KERN_INFO "%s - version %s\n",
238 e1000_driver_string, e1000_driver_version);
239
240 printk(KERN_INFO "%s\n", e1000_copyright);
241
242 ret = pci_module_init(&e1000_driver);
Tony Luck8b378de2005-07-28 01:07:38 -0700243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return ret;
245}
246
247module_init(e1000_init_module);
248
249/**
250 * e1000_exit_module - Driver Exit Cleanup Routine
251 *
252 * e1000_exit_module is called just before the driver is removed
253 * from memory.
254 **/
255
256static void __exit
257e1000_exit_module(void)
258{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 pci_unregister_driver(&e1000_driver);
260}
261
262module_exit(e1000_exit_module);
263
264/**
265 * e1000_irq_disable - Mask off interrupt generation on the NIC
266 * @adapter: board private structure
267 **/
268
Auke Koke619d522006-04-14 19:04:52 -0700269static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270e1000_irq_disable(struct e1000_adapter *adapter)
271{
272 atomic_inc(&adapter->irq_sem);
273 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
274 E1000_WRITE_FLUSH(&adapter->hw);
275 synchronize_irq(adapter->pdev->irq);
276}
277
278/**
279 * e1000_irq_enable - Enable default interrupt generation settings
280 * @adapter: board private structure
281 **/
282
Auke Koke619d522006-04-14 19:04:52 -0700283static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284e1000_irq_enable(struct e1000_adapter *adapter)
285{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800286 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
288 E1000_WRITE_FLUSH(&adapter->hw);
289 }
290}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100291
292static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700293e1000_update_mng_vlan(struct e1000_adapter *adapter)
294{
295 struct net_device *netdev = adapter->netdev;
296 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
297 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800298 if (adapter->vlgrp) {
299 if (!adapter->vlgrp->vlan_devices[vid]) {
300 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700301 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
302 e1000_vlan_rx_add_vid(netdev, vid);
303 adapter->mng_vlan_id = vid;
304 } else
305 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800306
307 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
308 (vid != old_vid) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700309 !adapter->vlgrp->vlan_devices[old_vid])
310 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800311 } else
312 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700313 }
314}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800315
316/**
317 * e1000_release_hw_control - release control of the h/w to f/w
318 * @adapter: address of board private structure
319 *
320 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
321 * For ASF and Pass Through versions of f/w this means that the
322 * driver is no longer loaded. For AMT version (only with 82573) i
323 * of the f/w this means that the netowrk i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700324 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800325 **/
326
Auke Koke619d522006-04-14 19:04:52 -0700327static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800328e1000_release_hw_control(struct e1000_adapter *adapter)
329{
330 uint32_t ctrl_ext;
331 uint32_t swsm;
332
333 /* Let firmware taken over control of h/w */
334 switch (adapter->hw.mac_type) {
335 case e1000_82571:
336 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700337 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800338 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
339 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
340 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
341 break;
342 case e1000_82573:
343 swsm = E1000_READ_REG(&adapter->hw, SWSM);
344 E1000_WRITE_REG(&adapter->hw, SWSM,
345 swsm & ~E1000_SWSM_DRV_LOAD);
346 default:
347 break;
348 }
349}
350
351/**
352 * e1000_get_hw_control - get control of the h/w from f/w
353 * @adapter: address of board private structure
354 *
355 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700356 * For ASF and Pass Through versions of f/w this means that
357 * the driver is loaded. For AMT version (only with 82573)
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800358 * of the f/w this means that the netowrk i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700359 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800360 **/
361
Auke Koke619d522006-04-14 19:04:52 -0700362static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800363e1000_get_hw_control(struct e1000_adapter *adapter)
364{
365 uint32_t ctrl_ext;
366 uint32_t swsm;
367 /* Let firmware know the driver has taken over */
368 switch (adapter->hw.mac_type) {
369 case e1000_82571:
370 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700371 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800372 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
373 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
374 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
375 break;
376 case e1000_82573:
377 swsm = E1000_READ_REG(&adapter->hw, SWSM);
378 E1000_WRITE_REG(&adapter->hw, SWSM,
379 swsm | E1000_SWSM_DRV_LOAD);
380 break;
381 default:
382 break;
383 }
384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386int
387e1000_up(struct e1000_adapter *adapter)
388{
389 struct net_device *netdev = adapter->netdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400390 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 /* hardware has been reset, we need to reload some things */
393
394 /* Reset the PHY if it was previously powered down */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800395 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 uint16_t mii_reg;
397 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800398 if (mii_reg & MII_CR_POWER_DOWN)
Auke Kok4cc15f52006-04-14 19:04:46 -0700399 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 }
401
402 e1000_set_multi(netdev);
403
404 e1000_restore_vlan(adapter);
405
406 e1000_configure_tx(adapter);
407 e1000_setup_rctl(adapter);
408 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800409 /* call E1000_DESC_UNUSED which always leaves
410 * at least 1 descriptor unused to make sure
411 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800412 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800413 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800414 adapter->alloc_rx_buf(adapter, ring,
415 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700418#ifdef CONFIG_PCI_MSI
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800419 if (adapter->hw.mac_type > e1000_82547_rev_2) {
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700420 adapter->have_msi = TRUE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800421 if ((err = pci_enable_msi(adapter->pdev))) {
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700422 DPRINTK(PROBE, ERR,
423 "Unable to allocate MSI interrupt Error: %d\n", err);
424 adapter->have_msi = FALSE;
425 }
426 }
427#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800428 if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 SA_SHIRQ | SA_SAMPLE_RANDOM,
Malli Chilakala26483452005-04-28 19:44:46 -0700430 netdev->name, netdev))) {
431 DPRINTK(PROBE, ERR,
432 "Unable to allocate interrupt Error: %d\n", err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 return err;
Malli Chilakala26483452005-04-28 19:44:46 -0700434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800436 adapter->tx_queue_len = netdev->tx_queue_len;
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 mod_timer(&adapter->watchdog_timer, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440#ifdef CONFIG_E1000_NAPI
441 netif_poll_enable(netdev);
442#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700443 e1000_irq_enable(adapter);
444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return 0;
446}
447
448void
449e1000_down(struct e1000_adapter *adapter)
450{
451 struct net_device *netdev = adapter->netdev;
Jeff Kirsher57128192006-01-12 16:50:28 -0800452 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
453 e1000_check_mng_mode(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 free_irq(adapter->pdev->irq, netdev);
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700458#ifdef CONFIG_PCI_MSI
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800459 if (adapter->hw.mac_type > e1000_82547_rev_2 &&
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700460 adapter->have_msi == TRUE)
461 pci_disable_msi(adapter->pdev);
462#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 del_timer_sync(&adapter->tx_fifo_stall_timer);
464 del_timer_sync(&adapter->watchdog_timer);
465 del_timer_sync(&adapter->phy_info_timer);
466
467#ifdef CONFIG_E1000_NAPI
468 netif_poll_disable(netdev);
469#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800470 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 adapter->link_speed = 0;
472 adapter->link_duplex = 0;
473 netif_carrier_off(netdev);
474 netif_stop_queue(netdev);
475
476 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400477 e1000_clean_all_tx_rings(adapter);
478 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Jeff Kirsher57128192006-01-12 16:50:28 -0800480 /* Power down the PHY so no link is implied when interface is down *
481 * The PHY cannot be powered down if any of the following is TRUE *
482 * (a) WoL is enabled
483 * (b) AMT is active
484 * (c) SoL/IDER session is active */
485 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700486 adapter->hw.media_type == e1000_media_type_copper &&
Jeff Kirsher57128192006-01-12 16:50:28 -0800487 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
488 !mng_mode_enabled &&
489 !e1000_check_phy_reset_block(&adapter->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 uint16_t mii_reg;
491 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
492 mii_reg |= MII_CR_POWER_DOWN;
493 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
Malli Chilakala4e48a2b2005-04-28 19:39:53 -0700494 mdelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496}
497
498void
499e1000_reset(struct e1000_adapter *adapter)
500{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700501 uint32_t pba, manc;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700502 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 /* Repartition Pba for greater than 9k mtu
505 * To take effect CTRL.RST is required.
506 */
507
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700508 switch (adapter->hw.mac_type) {
509 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700510 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700511 pba = E1000_PBA_30K;
512 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400513 case e1000_82571:
514 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800515 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400516 pba = E1000_PBA_38K;
517 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700518 case e1000_82573:
519 pba = E1000_PBA_12K;
520 break;
521 default:
522 pba = E1000_PBA_48K;
523 break;
524 }
525
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800526 if ((adapter->hw.mac_type != e1000_82573) &&
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800527 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700528 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700529
530
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800531 if (adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 adapter->tx_fifo_head = 0;
533 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
534 adapter->tx_fifo_size =
535 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
536 atomic_set(&adapter->tx_fifo_stall, 0);
537 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 E1000_WRITE_REG(&adapter->hw, PBA, pba);
540
541 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800542 /* Set the FC high water mark to 90% of the FIFO size.
543 * Required to clear last 3 LSB */
544 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
545
546 adapter->hw.fc_high_water = fc_high_water_mark;
547 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800548 if (adapter->hw.mac_type == e1000_80003es2lan)
549 adapter->hw.fc_pause_time = 0xFFFF;
550 else
551 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 adapter->hw.fc_send_xon = 1;
553 adapter->hw.fc = adapter->hw.original_fc;
554
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700555 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800557 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800559 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700561 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
563 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
564
565 e1000_reset_adaptive(&adapter->hw);
566 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700567 if (adapter->en_mng_pt) {
568 manc = E1000_READ_REG(&adapter->hw, MANC);
569 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
570 E1000_WRITE_REG(&adapter->hw, MANC, manc);
571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572}
573
574/**
575 * e1000_probe - Device Initialization Routine
576 * @pdev: PCI device information struct
577 * @ent: entry in e1000_pci_tbl
578 *
579 * Returns 0 on success, negative on failure
580 *
581 * e1000_probe initializes an adapter identified by a pci_dev structure.
582 * The OS initialization, configuring of the adapter private structure,
583 * and a hardware reset occur.
584 **/
585
586static int __devinit
587e1000_probe(struct pci_dev *pdev,
588 const struct pci_device_id *ent)
589{
590 struct net_device *netdev;
591 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700592 unsigned long mmio_start, mmio_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 static int cards_found = 0;
Jeff Kirsher84916822006-03-02 18:18:48 -0800595 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700596 int i, err, pci_using_dac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 uint16_t eeprom_data;
598 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800599 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 return err;
601
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800602 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 pci_using_dac = 1;
604 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800605 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 E1000_ERR("No usable DMA configuration, aborting\n");
607 return err;
608 }
609 pci_using_dac = 0;
610 }
611
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800612 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 return err;
614
615 pci_set_master(pdev);
616
617 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800618 if (!netdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 err = -ENOMEM;
620 goto err_alloc_etherdev;
621 }
622
623 SET_MODULE_OWNER(netdev);
624 SET_NETDEV_DEV(netdev, &pdev->dev);
625
626 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700627 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 adapter->netdev = netdev;
629 adapter->pdev = pdev;
630 adapter->hw.back = adapter;
631 adapter->msg_enable = (1 << debug) - 1;
632
633 mmio_start = pci_resource_start(pdev, BAR_0);
634 mmio_len = pci_resource_len(pdev, BAR_0);
635
636 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800637 if (!adapter->hw.hw_addr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 err = -EIO;
639 goto err_ioremap;
640 }
641
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800642 for (i = BAR_1; i <= BAR_5; i++) {
643 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800645 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 adapter->hw.io_base = pci_resource_start(pdev, i);
647 break;
648 }
649 }
650
651 netdev->open = &e1000_open;
652 netdev->stop = &e1000_close;
653 netdev->hard_start_xmit = &e1000_xmit_frame;
654 netdev->get_stats = &e1000_get_stats;
655 netdev->set_multicast_list = &e1000_set_multi;
656 netdev->set_mac_address = &e1000_set_mac;
657 netdev->change_mtu = &e1000_change_mtu;
658 netdev->do_ioctl = &e1000_ioctl;
659 e1000_set_ethtool_ops(netdev);
660 netdev->tx_timeout = &e1000_tx_timeout;
661 netdev->watchdog_timeo = 5 * HZ;
662#ifdef CONFIG_E1000_NAPI
663 netdev->poll = &e1000_clean;
664 netdev->weight = 64;
665#endif
666 netdev->vlan_rx_register = e1000_vlan_rx_register;
667 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
668 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
669#ifdef CONFIG_NET_POLL_CONTROLLER
670 netdev->poll_controller = e1000_netpoll;
671#endif
672 strcpy(netdev->name, pci_name(pdev));
673
674 netdev->mem_start = mmio_start;
675 netdev->mem_end = mmio_start + mmio_len;
676 netdev->base_addr = adapter->hw.io_base;
677
678 adapter->bd_number = cards_found;
679
680 /* setup the private structure */
681
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800682 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 goto err_sw_init;
684
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800685 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700686 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
687
Jeff Kirsher84916822006-03-02 18:18:48 -0800688 /* if ksp3, indicate if it's port a being setup */
Auke Kok76c224b2006-05-23 13:36:06 -0700689 if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
690 e1000_ksp3_port_a == 0)
Jeff Kirsher84916822006-03-02 18:18:48 -0800691 adapter->ksp3_port_a = 1;
692 e1000_ksp3_port_a++;
693 /* Reset for multiple KP3 adapters */
694 if (e1000_ksp3_port_a == 4)
695 e1000_ksp3_port_a = 0;
696
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800697 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 netdev->features = NETIF_F_SG |
699 NETIF_F_HW_CSUM |
700 NETIF_F_HW_VLAN_TX |
701 NETIF_F_HW_VLAN_RX |
702 NETIF_F_HW_VLAN_FILTER;
703 }
704
705#ifdef NETIF_F_TSO
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800706 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 (adapter->hw.mac_type != e1000_82547))
708 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700709
710#ifdef NETIF_F_TSO_IPV6
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800711 if (adapter->hw.mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700712 netdev->features |= NETIF_F_TSO_IPV6;
713#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800715 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 netdev->features |= NETIF_F_HIGHDMA;
717
Auke Kok76c224b2006-05-23 13:36:06 -0700718 /* hard_start_xmit is safe against parallel locking */
719 netdev->features |= NETIF_F_LLTX;
720
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700721 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
722
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800723 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 e1000_reset_hw(&adapter->hw);
727
728 /* make sure the EEPROM is good */
729
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800730 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
732 err = -EIO;
733 goto err_eeprom;
734 }
735
736 /* copy the MAC address out of the EEPROM */
737
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800738 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
740 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400741 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800743 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
745 err = -EIO;
746 goto err_eeprom;
747 }
748
749 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
750
751 e1000_get_bus_info(&adapter->hw);
752
753 init_timer(&adapter->tx_fifo_stall_timer);
754 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
755 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
756
757 init_timer(&adapter->watchdog_timer);
758 adapter->watchdog_timer.function = &e1000_watchdog;
759 adapter->watchdog_timer.data = (unsigned long) adapter;
760
761 INIT_WORK(&adapter->watchdog_task,
762 (void (*)(void *))e1000_watchdog_task, adapter);
763
764 init_timer(&adapter->phy_info_timer);
765 adapter->phy_info_timer.function = &e1000_update_phy_info;
766 adapter->phy_info_timer.data = (unsigned long) adapter;
767
Jeff Kirsher87041632006-03-02 18:21:24 -0800768 INIT_WORK(&adapter->reset_task,
769 (void (*)(void *))e1000_reset_task, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 /* we're going to reset, so assume we have no link for now */
772
773 netif_carrier_off(netdev);
774 netif_stop_queue(netdev);
775
776 e1000_check_options(adapter);
777
778 /* Initial Wake on LAN setting
779 * If APM wake is enabled in the EEPROM,
780 * enable the ACPI Magic Packet filter
781 */
782
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800783 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 case e1000_82542_rev2_0:
785 case e1000_82542_rev2_1:
786 case e1000_82543:
787 break;
788 case e1000_82544:
789 e1000_read_eeprom(&adapter->hw,
790 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
791 eeprom_apme_mask = E1000_EEPROM_82544_APM;
792 break;
793 case e1000_82546:
794 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500795 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800796 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800797 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 e1000_read_eeprom(&adapter->hw,
799 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
800 break;
801 }
802 /* Fall Through */
803 default:
804 e1000_read_eeprom(&adapter->hw,
805 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
806 break;
807 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800808 if (eeprom_data & eeprom_apme_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 adapter->wol |= E1000_WUFC_MAG;
810
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -0800811 /* print bus type/speed/width info */
812 {
813 struct e1000_hw *hw = &adapter->hw;
814 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
815 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
816 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
817 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
818 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
819 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
820 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
821 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
822 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
823 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
824 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
825 "32-bit"));
826 }
827
828 for (i = 0; i < 6; i++)
829 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 /* reset the hardware with the new settings */
832 e1000_reset(adapter);
833
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800834 /* If the controller is 82573 and f/w is AMT, do not set
835 * DRV_LOAD until the interface is up. For all other cases,
836 * let the f/w know that the h/w is now under the control
837 * of the driver. */
838 if (adapter->hw.mac_type != e1000_82573 ||
839 !e1000_check_mng_mode(&adapter->hw))
840 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700841
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 strcpy(netdev->name, "eth%d");
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800843 if ((err = register_netdev(netdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 goto err_register;
845
846 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
847
848 cards_found++;
849 return 0;
850
851err_register:
852err_sw_init:
853err_eeprom:
854 iounmap(adapter->hw.hw_addr);
855err_ioremap:
856 free_netdev(netdev);
857err_alloc_etherdev:
858 pci_release_regions(pdev);
859 return err;
860}
861
862/**
863 * e1000_remove - Device Removal Routine
864 * @pdev: PCI device information struct
865 *
866 * e1000_remove is called by the PCI subsystem to alert the driver
867 * that it should release a PCI device. The could be caused by a
868 * Hot-Plug event, or because the driver is going to be removed from
869 * memory.
870 **/
871
872static void __devexit
873e1000_remove(struct pci_dev *pdev)
874{
875 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700876 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800877 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400878#ifdef CONFIG_E1000_NAPI
879 int i;
880#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Jeff Garzikbe2b28e2005-10-04 07:13:43 -0400882 flush_scheduled_work();
883
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800884 if (adapter->hw.mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 adapter->hw.media_type == e1000_media_type_copper) {
886 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800887 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 manc |= E1000_MANC_ARP_EN;
889 E1000_WRITE_REG(&adapter->hw, MANC, manc);
890 }
891 }
892
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800893 /* Release control of h/w to f/w. If f/w is AMT enabled, this
894 * would have already happened in close and is redundant. */
895 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400898#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800899 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -0800900 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400901#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800903 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700904 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -0400906 kfree(adapter->tx_ring);
907 kfree(adapter->rx_ring);
908#ifdef CONFIG_E1000_NAPI
909 kfree(adapter->polling_netdev);
910#endif
911
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 iounmap(adapter->hw.hw_addr);
913 pci_release_regions(pdev);
914
915 free_netdev(netdev);
916
917 pci_disable_device(pdev);
918}
919
920/**
921 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
922 * @adapter: board private structure to initialize
923 *
924 * e1000_sw_init initializes the Adapter private data structure.
925 * Fields are initialized based on PCI device information and
926 * OS network device settings (MTU size).
927 **/
928
929static int __devinit
930e1000_sw_init(struct e1000_adapter *adapter)
931{
932 struct e1000_hw *hw = &adapter->hw;
933 struct net_device *netdev = adapter->netdev;
934 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400935#ifdef CONFIG_E1000_NAPI
936 int i;
937#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 /* PCI config space info */
940
941 hw->vendor_id = pdev->vendor;
942 hw->device_id = pdev->device;
943 hw->subsystem_vendor_id = pdev->subsystem_vendor;
944 hw->subsystem_id = pdev->subsystem_device;
945
946 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
947
948 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
949
Auke Kok9e2feac2006-04-14 19:05:18 -0700950 adapter->rx_buffer_len = MAXIMUM_ETHERNET_FRAME_SIZE;
951 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 hw->max_frame_size = netdev->mtu +
953 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
954 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
955
956 /* identify the MAC */
957
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800958 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
960 return -EIO;
961 }
962
963 /* initialize eeprom parameters */
964
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800965 if (e1000_init_eeprom_params(hw)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700966 E1000_ERR("EEPROM initialization failed\n");
967 return -EIO;
968 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800970 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 default:
972 break;
973 case e1000_82541:
974 case e1000_82547:
975 case e1000_82541_rev_2:
976 case e1000_82547_rev_2:
977 hw->phy_init_script = 1;
978 break;
979 }
980
981 e1000_set_media_type(hw);
982
983 hw->wait_autoneg_complete = FALSE;
984 hw->tbi_compatibility_en = TRUE;
985 hw->adaptive_ifs = TRUE;
986
987 /* Copper options */
988
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800989 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 hw->mdix = AUTO_ALL_MODES;
991 hw->disable_polarity_correction = FALSE;
992 hw->master_slave = E1000_MASTER_SLAVE;
993 }
994
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800995 adapter->num_tx_queues = 1;
996 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400997
998 if (e1000_alloc_queues(adapter)) {
999 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1000 return -ENOMEM;
1001 }
1002
1003#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001004 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001005 adapter->polling_netdev[i].priv = adapter;
1006 adapter->polling_netdev[i].poll = &e1000_clean;
1007 adapter->polling_netdev[i].weight = 64;
1008 dev_hold(&adapter->polling_netdev[i]);
1009 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1010 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001011 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001012#endif
1013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 atomic_set(&adapter->irq_sem, 1);
1015 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 return 0;
1018}
1019
1020/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001021 * e1000_alloc_queues - Allocate memory for all rings
1022 * @adapter: board private structure to initialize
1023 *
1024 * We allocate one ring per queue at run-time since we don't know the
1025 * number of queues at compile-time. The polling_netdev array is
1026 * intended for Multiqueue, but should work fine with a single queue.
1027 **/
1028
1029static int __devinit
1030e1000_alloc_queues(struct e1000_adapter *adapter)
1031{
1032 int size;
1033
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001034 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001035 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1036 if (!adapter->tx_ring)
1037 return -ENOMEM;
1038 memset(adapter->tx_ring, 0, size);
1039
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001040 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001041 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1042 if (!adapter->rx_ring) {
1043 kfree(adapter->tx_ring);
1044 return -ENOMEM;
1045 }
1046 memset(adapter->rx_ring, 0, size);
1047
1048#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001049 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001050 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1051 if (!adapter->polling_netdev) {
1052 kfree(adapter->tx_ring);
1053 kfree(adapter->rx_ring);
1054 return -ENOMEM;
1055 }
1056 memset(adapter->polling_netdev, 0, size);
1057#endif
1058
1059 return E1000_SUCCESS;
1060}
1061
1062/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 * e1000_open - Called when a network interface is made active
1064 * @netdev: network interface device structure
1065 *
1066 * Returns 0 on success, negative value on failure
1067 *
1068 * The open entry point is called when a network interface is made
1069 * active by the system (IFF_UP). At this point all resources needed
1070 * for transmit and receive operations are allocated, the interrupt
1071 * handler is registered with the OS, the watchdog timer is started,
1072 * and the stack is notified that the interface is ready.
1073 **/
1074
1075static int
1076e1000_open(struct net_device *netdev)
1077{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001078 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 int err;
1080
1081 /* allocate transmit descriptors */
1082
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001083 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 goto err_setup_tx;
1085
1086 /* allocate receive descriptors */
1087
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001088 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 goto err_setup_rx;
1090
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001091 if ((err = e1000_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001093 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001094 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001095 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1096 e1000_update_mng_vlan(adapter);
1097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001099 /* If AMT is enabled, let the firmware know that the network
1100 * interface is now open */
1101 if (adapter->hw.mac_type == e1000_82573 &&
1102 e1000_check_mng_mode(&adapter->hw))
1103 e1000_get_hw_control(adapter);
1104
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 return E1000_SUCCESS;
1106
1107err_up:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001108 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001110 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111err_setup_tx:
1112 e1000_reset(adapter);
1113
1114 return err;
1115}
1116
1117/**
1118 * e1000_close - Disables a network interface
1119 * @netdev: network interface device structure
1120 *
1121 * Returns 0, this is not allowed to fail
1122 *
1123 * The close entry point is called when an interface is de-activated
1124 * by the OS. The hardware is still under the drivers control, but
1125 * needs to be disabled. A global MAC reset is issued to stop the
1126 * hardware, and all transmit and receive resources are freed.
1127 **/
1128
1129static int
1130e1000_close(struct net_device *netdev)
1131{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001132 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 e1000_down(adapter);
1135
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001136 e1000_free_all_tx_resources(adapter);
1137 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001139 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001140 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1141 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1142 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001143
1144 /* If AMT is enabled, let the firmware know that the network
1145 * interface is now closed */
1146 if (adapter->hw.mac_type == e1000_82573 &&
1147 e1000_check_mng_mode(&adapter->hw))
1148 e1000_release_hw_control(adapter);
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 return 0;
1151}
1152
1153/**
1154 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1155 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001156 * @start: address of beginning of memory
1157 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 **/
Auke Koke619d522006-04-14 19:04:52 -07001159static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160e1000_check_64k_bound(struct e1000_adapter *adapter,
1161 void *start, unsigned long len)
1162{
1163 unsigned long begin = (unsigned long) start;
1164 unsigned long end = begin + len;
1165
Malli Chilakala26483452005-04-28 19:44:46 -07001166 /* First rev 82545 and 82546 need to not allow any memory
1167 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001169 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1171 }
1172
1173 return TRUE;
1174}
1175
1176/**
1177 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1178 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001179 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 *
1181 * Return 0 on success, negative on failure
1182 **/
1183
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001184static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001185e1000_setup_tx_resources(struct e1000_adapter *adapter,
1186 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 struct pci_dev *pdev = adapter->pdev;
1189 int size;
1190
1191 size = sizeof(struct e1000_buffer) * txdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001192
1193 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001194 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001195 DPRINTK(PROBE, ERR,
1196 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 return -ENOMEM;
1198 }
1199 memset(txdr->buffer_info, 0, size);
1200
1201 /* round up to nearest 4K */
1202
1203 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1204 E1000_ROUNDUP(txdr->size, 4096);
1205
1206 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001207 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001210 DPRINTK(PROBE, ERR,
1211 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 return -ENOMEM;
1213 }
1214
Malli Chilakala26483452005-04-28 19:44:46 -07001215 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1217 void *olddesc = txdr->desc;
1218 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001219 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1220 "at %p\n", txdr->size, txdr->desc);
1221 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001223 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001224 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1226 goto setup_tx_desc_die;
1227 }
1228
1229 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1230 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001231 pci_free_consistent(pdev, txdr->size, txdr->desc,
1232 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1234 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001235 "Unable to allocate aligned memory "
1236 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 vfree(txdr->buffer_info);
1238 return -ENOMEM;
1239 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001240 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1242 }
1243 }
1244 memset(txdr->desc, 0, txdr->size);
1245
1246 txdr->next_to_use = 0;
1247 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001248 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 return 0;
1251}
1252
1253/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001254 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1255 * (Descriptors) for all queues
1256 * @adapter: board private structure
1257 *
1258 * If this function returns with an error, then it's possible one or
1259 * more of the rings is populated (while the rest are not). It is the
1260 * callers duty to clean those orphaned rings.
1261 *
1262 * Return 0 on success, negative on failure
1263 **/
1264
1265int
1266e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1267{
1268 int i, err = 0;
1269
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001270 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001271 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1272 if (err) {
1273 DPRINTK(PROBE, ERR,
1274 "Allocation for Tx Queue %u failed\n", i);
1275 break;
1276 }
1277 }
1278
1279 return err;
1280}
1281
1282/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1284 * @adapter: board private structure
1285 *
1286 * Configure the Tx unit of the MAC after a reset.
1287 **/
1288
1289static void
1290e1000_configure_tx(struct e1000_adapter *adapter)
1291{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001292 uint64_t tdba;
1293 struct e1000_hw *hw = &adapter->hw;
1294 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001295 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
1297 /* Setup the HW Tx Head and Tail descriptor pointers */
1298
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001299 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001300 case 1:
1301 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001302 tdba = adapter->tx_ring[0].dma;
1303 tdlen = adapter->tx_ring[0].count *
1304 sizeof(struct e1000_tx_desc);
1305 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1306 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1307 E1000_WRITE_REG(hw, TDLEN, tdlen);
1308 E1000_WRITE_REG(hw, TDH, 0);
1309 E1000_WRITE_REG(hw, TDT, 0);
1310 adapter->tx_ring[0].tdh = E1000_TDH;
1311 adapter->tx_ring[0].tdt = E1000_TDT;
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001312 break;
1313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
1315 /* Set the default values for the Tx Inter Packet Gap timer */
1316
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001317 if (hw->media_type == e1000_media_type_fiber ||
1318 hw->media_type == e1000_media_type_internal_serdes)
1319 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1320 else
1321 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1322
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001323 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 case e1000_82542_rev2_0:
1325 case e1000_82542_rev2_1:
1326 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001327 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1328 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001330 case e1000_80003es2lan:
1331 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1332 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1333 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001335 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1336 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1337 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001339 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1340 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001341 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 /* Set the Tx Interrupt Delay register */
1344
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001345 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1346 if (hw->mac_type >= e1000_82540)
1347 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
1349 /* Program the Transmit Control Register */
1350
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001351 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001354 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1356
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001357#ifdef DISABLE_MULR
1358 /* disable Multiple Reads for debugging */
1359 tctl &= ~E1000_TCTL_MULR;
1360#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001362 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1363 tarc = E1000_READ_REG(hw, TARC0);
1364 tarc |= ((1 << 25) | (1 << 21));
1365 E1000_WRITE_REG(hw, TARC0, tarc);
1366 tarc = E1000_READ_REG(hw, TARC1);
1367 tarc |= (1 << 25);
1368 if (tctl & E1000_TCTL_MULR)
1369 tarc &= ~(1 << 28);
1370 else
1371 tarc |= (1 << 28);
1372 E1000_WRITE_REG(hw, TARC1, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001373 } else if (hw->mac_type == e1000_80003es2lan) {
1374 tarc = E1000_READ_REG(hw, TARC0);
1375 tarc |= 1;
1376 if (hw->media_type == e1000_media_type_internal_serdes)
1377 tarc |= (1 << 20);
1378 E1000_WRITE_REG(hw, TARC0, tarc);
1379 tarc = E1000_READ_REG(hw, TARC1);
1380 tarc |= 1;
1381 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001382 }
1383
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001384 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 /* Setup Transmit Descriptor Settings for eop descriptor */
1387 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1388 E1000_TXD_CMD_IFCS;
1389
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001390 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1392 else
1393 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1394
1395 /* Cache if we're 82544 running in PCI-X because we'll
1396 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001397 if (hw->mac_type == e1000_82544 &&
1398 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001400
1401 E1000_WRITE_REG(hw, TCTL, tctl);
1402
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403}
1404
1405/**
1406 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1407 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001408 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 *
1410 * Returns 0 on success, negative on failure
1411 **/
1412
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001413static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001414e1000_setup_rx_resources(struct e1000_adapter *adapter,
1415 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001418 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
1420 size = sizeof(struct e1000_buffer) * rxdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001421 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001422 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001423 DPRINTK(PROBE, ERR,
1424 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 return -ENOMEM;
1426 }
1427 memset(rxdr->buffer_info, 0, size);
1428
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001429 size = sizeof(struct e1000_ps_page) * rxdr->count;
1430 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001431 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001432 vfree(rxdr->buffer_info);
1433 DPRINTK(PROBE, ERR,
1434 "Unable to allocate memory for the receive descriptor ring\n");
1435 return -ENOMEM;
1436 }
1437 memset(rxdr->ps_page, 0, size);
1438
1439 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1440 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001441 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001442 vfree(rxdr->buffer_info);
1443 kfree(rxdr->ps_page);
1444 DPRINTK(PROBE, ERR,
1445 "Unable to allocate memory for the receive descriptor ring\n");
1446 return -ENOMEM;
1447 }
1448 memset(rxdr->ps_page_dma, 0, size);
1449
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001450 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001451 desc_len = sizeof(struct e1000_rx_desc);
1452 else
1453 desc_len = sizeof(union e1000_rx_desc_packet_split);
1454
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 /* Round up to nearest 4K */
1456
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001457 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 E1000_ROUNDUP(rxdr->size, 4096);
1459
1460 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1461
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001462 if (!rxdr->desc) {
1463 DPRINTK(PROBE, ERR,
1464 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001467 kfree(rxdr->ps_page);
1468 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 return -ENOMEM;
1470 }
1471
Malli Chilakala26483452005-04-28 19:44:46 -07001472 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1474 void *olddesc = rxdr->desc;
1475 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001476 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1477 "at %p\n", rxdr->size, rxdr->desc);
1478 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001480 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001481 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001483 DPRINTK(PROBE, ERR,
1484 "Unable to allocate memory "
1485 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 goto setup_rx_desc_die;
1487 }
1488
1489 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1490 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001491 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1492 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001494 DPRINTK(PROBE, ERR,
1495 "Unable to allocate aligned memory "
1496 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001497 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001499 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1501 }
1502 }
1503 memset(rxdr->desc, 0, rxdr->size);
1504
1505 rxdr->next_to_clean = 0;
1506 rxdr->next_to_use = 0;
1507
1508 return 0;
1509}
1510
1511/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001512 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1513 * (Descriptors) for all queues
1514 * @adapter: board private structure
1515 *
1516 * If this function returns with an error, then it's possible one or
1517 * more of the rings is populated (while the rest are not). It is the
1518 * callers duty to clean those orphaned rings.
1519 *
1520 * Return 0 on success, negative on failure
1521 **/
1522
1523int
1524e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1525{
1526 int i, err = 0;
1527
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001528 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001529 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1530 if (err) {
1531 DPRINTK(PROBE, ERR,
1532 "Allocation for Rx Queue %u failed\n", i);
1533 break;
1534 }
1535 }
1536
1537 return err;
1538}
1539
1540/**
Malli Chilakala26483452005-04-28 19:44:46 -07001541 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 * @adapter: Board private structure
1543 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001544#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1545 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546static void
1547e1000_setup_rctl(struct e1000_adapter *adapter)
1548{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001549 uint32_t rctl, rfctl;
1550 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001551#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001552 uint32_t pages = 0;
1553#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1556
1557 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1558
1559 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1560 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1561 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1562
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001563 if (adapter->hw.mac_type > e1000_82543)
1564 rctl |= E1000_RCTL_SECRC;
1565
1566 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 rctl |= E1000_RCTL_SBP;
1568 else
1569 rctl &= ~E1000_RCTL_SBP;
1570
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001571 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1572 rctl &= ~E1000_RCTL_LPE;
1573 else
1574 rctl |= E1000_RCTL_LPE;
1575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001577 rctl &= ~E1000_RCTL_SZ_4096;
1578 rctl |= E1000_RCTL_BSEX;
1579 switch (adapter->rx_buffer_len) {
1580 case E1000_RXBUFFER_256:
1581 rctl |= E1000_RCTL_SZ_256;
1582 rctl &= ~E1000_RCTL_BSEX;
1583 break;
1584 case E1000_RXBUFFER_512:
1585 rctl |= E1000_RCTL_SZ_512;
1586 rctl &= ~E1000_RCTL_BSEX;
1587 break;
1588 case E1000_RXBUFFER_1024:
1589 rctl |= E1000_RCTL_SZ_1024;
1590 rctl &= ~E1000_RCTL_BSEX;
1591 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001592 case E1000_RXBUFFER_2048:
1593 default:
1594 rctl |= E1000_RCTL_SZ_2048;
1595 rctl &= ~E1000_RCTL_BSEX;
1596 break;
1597 case E1000_RXBUFFER_4096:
1598 rctl |= E1000_RCTL_SZ_4096;
1599 break;
1600 case E1000_RXBUFFER_8192:
1601 rctl |= E1000_RCTL_SZ_8192;
1602 break;
1603 case E1000_RXBUFFER_16384:
1604 rctl |= E1000_RCTL_SZ_16384;
1605 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001606 }
1607
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001608#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001609 /* 82571 and greater support packet-split where the protocol
1610 * header is placed in skb->data and the packet data is
1611 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1612 * In the case of a non-split, skb->data is linearly filled,
1613 * followed by the page buffers. Therefore, skb->data is
1614 * sized to hold the largest protocol header.
1615 */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001616 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1617 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1618 PAGE_SIZE <= 16384)
1619 adapter->rx_ps_pages = pages;
1620 else
1621 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001622#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001623 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001624 /* Configure extra packet-split registers */
1625 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1626 rfctl |= E1000_RFCTL_EXTEN;
1627 /* disable IPv6 packet split support */
1628 rfctl |= E1000_RFCTL_IPV6_DIS;
1629 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1630
1631 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001632
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001633 psrctl |= adapter->rx_ps_bsize0 >>
1634 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001635
1636 switch (adapter->rx_ps_pages) {
1637 case 3:
1638 psrctl |= PAGE_SIZE <<
1639 E1000_PSRCTL_BSIZE3_SHIFT;
1640 case 2:
1641 psrctl |= PAGE_SIZE <<
1642 E1000_PSRCTL_BSIZE2_SHIFT;
1643 case 1:
1644 psrctl |= PAGE_SIZE >>
1645 E1000_PSRCTL_BSIZE1_SHIFT;
1646 break;
1647 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001648
1649 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 }
1651
1652 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1653}
1654
1655/**
1656 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1657 * @adapter: board private structure
1658 *
1659 * Configure the Rx unit of the MAC after a reset.
1660 **/
1661
1662static void
1663e1000_configure_rx(struct e1000_adapter *adapter)
1664{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001665 uint64_t rdba;
1666 struct e1000_hw *hw = &adapter->hw;
1667 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001668
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001669 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001670 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001671 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001672 sizeof(union e1000_rx_desc_packet_split);
1673 adapter->clean_rx = e1000_clean_rx_irq_ps;
1674 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1675 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001676 rdlen = adapter->rx_ring[0].count *
1677 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001678 adapter->clean_rx = e1000_clean_rx_irq;
1679 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
1682 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001683 rctl = E1000_READ_REG(hw, RCTL);
1684 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
1686 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001687 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001689 if (hw->mac_type >= e1000_82540) {
1690 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001691 if (adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001692 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 1000000000 / (adapter->itr * 256));
1694 }
1695
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001696 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001697 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001698 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07001699 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001700#ifdef CONFIG_E1000_NAPI
1701 /* Auto-Mask interrupts upon ICR read. */
1702 ctrl_ext |= E1000_CTRL_EXT_IAME;
1703#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001704 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001705 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001706 E1000_WRITE_FLUSH(hw);
1707 }
1708
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001709 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1710 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001711 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001712 case 1:
1713 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001714 rdba = adapter->rx_ring[0].dma;
1715 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1716 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1717 E1000_WRITE_REG(hw, RDLEN, rdlen);
1718 E1000_WRITE_REG(hw, RDH, 0);
1719 E1000_WRITE_REG(hw, RDT, 0);
1720 adapter->rx_ring[0].rdh = E1000_RDH;
1721 adapter->rx_ring[0].rdt = E1000_RDT;
1722 break;
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04001723 }
1724
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001726 if (hw->mac_type >= e1000_82543) {
1727 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001728 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001729 rxcsum |= E1000_RXCSUM_TUOFL;
1730
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001731 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001732 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001733 if ((hw->mac_type >= e1000_82571) &&
1734 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001735 rxcsum |= E1000_RXCSUM_IPPCSE;
1736 }
1737 } else {
1738 rxcsum &= ~E1000_RXCSUM_TUOFL;
1739 /* don't need to clear IPPCSE as it defaults to 0 */
1740 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001741 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 }
1743
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001744 if (hw->mac_type == e1000_82573)
1745 E1000_WRITE_REG(hw, ERT, 0x0100);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001746
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001748 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
1750
1751/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001752 * e1000_free_tx_resources - Free Tx Resources per Queue
1753 * @adapter: board private structure
1754 * @tx_ring: Tx descriptor ring for a specific queue
1755 *
1756 * Free all transmit software resources
1757 **/
1758
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001759static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001760e1000_free_tx_resources(struct e1000_adapter *adapter,
1761 struct e1000_tx_ring *tx_ring)
1762{
1763 struct pci_dev *pdev = adapter->pdev;
1764
1765 e1000_clean_tx_ring(adapter, tx_ring);
1766
1767 vfree(tx_ring->buffer_info);
1768 tx_ring->buffer_info = NULL;
1769
1770 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1771
1772 tx_ring->desc = NULL;
1773}
1774
1775/**
1776 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 * @adapter: board private structure
1778 *
1779 * Free all transmit software resources
1780 **/
1781
1782void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001783e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001785 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001787 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001788 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789}
1790
Auke Koke619d522006-04-14 19:04:52 -07001791static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1793 struct e1000_buffer *buffer_info)
1794{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001795 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001796 pci_unmap_page(adapter->pdev,
1797 buffer_info->dma,
1798 buffer_info->length,
1799 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08001801 if (buffer_info->skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 dev_kfree_skb_any(buffer_info->skb);
Jeff Kirsher8241e352006-01-12 16:51:34 -08001803 memset(buffer_info, 0, sizeof(struct e1000_buffer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804}
1805
1806/**
1807 * e1000_clean_tx_ring - Free Tx Buffers
1808 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001809 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 **/
1811
1812static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001813e1000_clean_tx_ring(struct e1000_adapter *adapter,
1814 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 struct e1000_buffer *buffer_info;
1817 unsigned long size;
1818 unsigned int i;
1819
1820 /* Free all the Tx ring sk_buffs */
1821
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001822 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 buffer_info = &tx_ring->buffer_info[i];
1824 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1825 }
1826
1827 size = sizeof(struct e1000_buffer) * tx_ring->count;
1828 memset(tx_ring->buffer_info, 0, size);
1829
1830 /* Zero out the descriptor ring */
1831
1832 memset(tx_ring->desc, 0, tx_ring->size);
1833
1834 tx_ring->next_to_use = 0;
1835 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001836 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001838 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1839 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1840}
1841
1842/**
1843 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1844 * @adapter: board private structure
1845 **/
1846
1847static void
1848e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1849{
1850 int i;
1851
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001852 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001853 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854}
1855
1856/**
1857 * e1000_free_rx_resources - Free Rx Resources
1858 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001859 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 *
1861 * Free all receive software resources
1862 **/
1863
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001864static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001865e1000_free_rx_resources(struct e1000_adapter *adapter,
1866 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 struct pci_dev *pdev = adapter->pdev;
1869
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001870 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
1872 vfree(rx_ring->buffer_info);
1873 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001874 kfree(rx_ring->ps_page);
1875 rx_ring->ps_page = NULL;
1876 kfree(rx_ring->ps_page_dma);
1877 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
1879 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1880
1881 rx_ring->desc = NULL;
1882}
1883
1884/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001885 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001887 *
1888 * Free all receive software resources
1889 **/
1890
1891void
1892e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1893{
1894 int i;
1895
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001896 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001897 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1898}
1899
1900/**
1901 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1902 * @adapter: board private structure
1903 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 **/
1905
1906static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001907e1000_clean_rx_ring(struct e1000_adapter *adapter,
1908 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001911 struct e1000_ps_page *ps_page;
1912 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 struct pci_dev *pdev = adapter->pdev;
1914 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001915 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
1917 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001918 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001920 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 pci_unmap_single(pdev,
1922 buffer_info->dma,
1923 buffer_info->length,
1924 PCI_DMA_FROMDEVICE);
1925
1926 dev_kfree_skb(buffer_info->skb);
1927 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08001928 }
1929 ps_page = &rx_ring->ps_page[i];
1930 ps_page_dma = &rx_ring->ps_page_dma[i];
1931 for (j = 0; j < adapter->rx_ps_pages; j++) {
1932 if (!ps_page->ps_page[j]) break;
1933 pci_unmap_page(pdev,
1934 ps_page_dma->ps_page_dma[j],
1935 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1936 ps_page_dma->ps_page_dma[j] = 0;
1937 put_page(ps_page->ps_page[j]);
1938 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 }
1940 }
1941
1942 size = sizeof(struct e1000_buffer) * rx_ring->count;
1943 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001944 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1945 memset(rx_ring->ps_page, 0, size);
1946 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1947 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
1949 /* Zero out the descriptor ring */
1950
1951 memset(rx_ring->desc, 0, rx_ring->size);
1952
1953 rx_ring->next_to_clean = 0;
1954 rx_ring->next_to_use = 0;
1955
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001956 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1957 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1958}
1959
1960/**
1961 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1962 * @adapter: board private structure
1963 **/
1964
1965static void
1966e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1967{
1968 int i;
1969
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001970 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001971 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972}
1973
1974/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1975 * and memory write and invalidate disabled for certain operations
1976 */
1977static void
1978e1000_enter_82542_rst(struct e1000_adapter *adapter)
1979{
1980 struct net_device *netdev = adapter->netdev;
1981 uint32_t rctl;
1982
1983 e1000_pci_clear_mwi(&adapter->hw);
1984
1985 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1986 rctl |= E1000_RCTL_RST;
1987 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1988 E1000_WRITE_FLUSH(&adapter->hw);
1989 mdelay(5);
1990
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001991 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001992 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993}
1994
1995static void
1996e1000_leave_82542_rst(struct e1000_adapter *adapter)
1997{
1998 struct net_device *netdev = adapter->netdev;
1999 uint32_t rctl;
2000
2001 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2002 rctl &= ~E1000_RCTL_RST;
2003 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2004 E1000_WRITE_FLUSH(&adapter->hw);
2005 mdelay(5);
2006
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002007 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 e1000_pci_set_mwi(&adapter->hw);
2009
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002010 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002011 /* No need to loop, because 82542 supports only 1 queue */
2012 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002013 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002014 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 }
2016}
2017
2018/**
2019 * e1000_set_mac - Change the Ethernet Address of the NIC
2020 * @netdev: network interface device structure
2021 * @p: pointer to an address structure
2022 *
2023 * Returns 0 on success, negative on failure
2024 **/
2025
2026static int
2027e1000_set_mac(struct net_device *netdev, void *p)
2028{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002029 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 struct sockaddr *addr = p;
2031
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002032 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 return -EADDRNOTAVAIL;
2034
2035 /* 82542 2.0 needs to be in reset to write receive address registers */
2036
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002037 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 e1000_enter_82542_rst(adapter);
2039
2040 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2041 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2042
2043 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2044
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002045 /* With 82571 controllers, LAA may be overwritten (with the default)
2046 * due to controller reset from the other port. */
2047 if (adapter->hw.mac_type == e1000_82571) {
2048 /* activate the work around */
2049 adapter->hw.laa_is_present = 1;
2050
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002051 /* Hold a copy of the LAA in RAR[14] This is done so that
2052 * between the time RAR[0] gets clobbered and the time it
2053 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002054 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002055 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002056 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002057 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002058 E1000_RAR_ENTRIES - 1);
2059 }
2060
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002061 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 e1000_leave_82542_rst(adapter);
2063
2064 return 0;
2065}
2066
2067/**
2068 * e1000_set_multi - Multicast and Promiscuous mode set
2069 * @netdev: network interface device structure
2070 *
2071 * The set_multi entry point is called whenever the multicast address
2072 * list or the network interface flags are updated. This routine is
2073 * responsible for configuring the hardware for proper multicast,
2074 * promiscuous mode, and all-multi behavior.
2075 **/
2076
2077static void
2078e1000_set_multi(struct net_device *netdev)
2079{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002080 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 struct e1000_hw *hw = &adapter->hw;
2082 struct dev_mc_list *mc_ptr;
2083 uint32_t rctl;
2084 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002085 int i, rar_entries = E1000_RAR_ENTRIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002087 /* reserve RAR[14] for LAA over-write work-around */
2088 if (adapter->hw.mac_type == e1000_82571)
2089 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Malli Chilakala26483452005-04-28 19:44:46 -07002091 /* Check for Promiscuous and All Multicast modes */
2092
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 rctl = E1000_READ_REG(hw, RCTL);
2094
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002095 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002097 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 rctl |= E1000_RCTL_MPE;
2099 rctl &= ~E1000_RCTL_UPE;
2100 } else {
2101 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2102 }
2103
2104 E1000_WRITE_REG(hw, RCTL, rctl);
2105
2106 /* 82542 2.0 needs to be in reset to write receive address registers */
2107
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002108 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 e1000_enter_82542_rst(adapter);
2110
2111 /* load the first 14 multicast address into the exact filters 1-14
2112 * RAR 0 is used for the station MAC adddress
2113 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002114 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 */
2116 mc_ptr = netdev->mc_list;
2117
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002118 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002119 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2121 mc_ptr = mc_ptr->next;
2122 } else {
2123 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2124 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2125 }
2126 }
2127
2128 /* clear the old settings from the multicast hash table */
2129
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002130 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2132
2133 /* load any remaining addresses into the hash table */
2134
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002135 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2137 e1000_mta_set(hw, hash_value);
2138 }
2139
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002140 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142}
2143
2144/* Need to wait a few seconds after link up to get diagnostic information from
2145 * the phy */
2146
2147static void
2148e1000_update_phy_info(unsigned long data)
2149{
2150 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2151 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2152}
2153
2154/**
2155 * e1000_82547_tx_fifo_stall - Timer Call-back
2156 * @data: pointer to adapter cast into an unsigned long
2157 **/
2158
2159static void
2160e1000_82547_tx_fifo_stall(unsigned long data)
2161{
2162 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2163 struct net_device *netdev = adapter->netdev;
2164 uint32_t tctl;
2165
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002166 if (atomic_read(&adapter->tx_fifo_stall)) {
2167 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 E1000_READ_REG(&adapter->hw, TDH)) &&
2169 (E1000_READ_REG(&adapter->hw, TDFT) ==
2170 E1000_READ_REG(&adapter->hw, TDFH)) &&
2171 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2172 E1000_READ_REG(&adapter->hw, TDFHS))) {
2173 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2174 E1000_WRITE_REG(&adapter->hw, TCTL,
2175 tctl & ~E1000_TCTL_EN);
2176 E1000_WRITE_REG(&adapter->hw, TDFT,
2177 adapter->tx_head_addr);
2178 E1000_WRITE_REG(&adapter->hw, TDFH,
2179 adapter->tx_head_addr);
2180 E1000_WRITE_REG(&adapter->hw, TDFTS,
2181 adapter->tx_head_addr);
2182 E1000_WRITE_REG(&adapter->hw, TDFHS,
2183 adapter->tx_head_addr);
2184 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2185 E1000_WRITE_FLUSH(&adapter->hw);
2186
2187 adapter->tx_fifo_head = 0;
2188 atomic_set(&adapter->tx_fifo_stall, 0);
2189 netif_wake_queue(netdev);
2190 } else {
2191 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2192 }
2193 }
2194}
2195
2196/**
2197 * e1000_watchdog - Timer Call-back
2198 * @data: pointer to adapter cast into an unsigned long
2199 **/
2200static void
2201e1000_watchdog(unsigned long data)
2202{
2203 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2204
2205 /* Do the rest outside of interrupt context */
2206 schedule_work(&adapter->watchdog_task);
2207}
2208
2209static void
2210e1000_watchdog_task(struct e1000_adapter *adapter)
2211{
2212 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002213 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002214 uint32_t link, tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
2216 e1000_check_for_link(&adapter->hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002217 if (adapter->hw.mac_type == e1000_82573) {
2218 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002219 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002220 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002223 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2225 link = !adapter->hw.serdes_link_down;
2226 else
2227 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2228
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002229 if (link) {
2230 if (!netif_carrier_ok(netdev)) {
Auke Kokfe7fe282006-04-14 19:04:59 -07002231 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 e1000_get_speed_and_duplex(&adapter->hw,
2233 &adapter->link_speed,
2234 &adapter->link_duplex);
2235
2236 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2237 adapter->link_speed,
2238 adapter->link_duplex == FULL_DUPLEX ?
2239 "Full Duplex" : "Half Duplex");
2240
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002241 /* tweak tx_queue_len according to speed/duplex
2242 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002243 netdev->tx_queue_len = adapter->tx_queue_len;
2244 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002245 switch (adapter->link_speed) {
2246 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002247 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002248 netdev->tx_queue_len = 10;
2249 adapter->tx_timeout_factor = 8;
2250 break;
2251 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002252 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002253 netdev->tx_queue_len = 100;
2254 /* maybe add some timeout factor ? */
2255 break;
2256 }
2257
Auke Kokfe7fe282006-04-14 19:04:59 -07002258 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002259 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002260 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002261#define SPEED_MODE_BIT (1 << 21)
2262 uint32_t tarc0;
2263 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2264 tarc0 &= ~SPEED_MODE_BIT;
2265 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2266 }
2267
2268#ifdef NETIF_F_TSO
2269 /* disable TSO for pcie and 10/100 speeds, to avoid
2270 * some hardware issues */
2271 if (!adapter->tso_force &&
2272 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002273 switch (adapter->link_speed) {
2274 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002275 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002276 DPRINTK(PROBE,INFO,
2277 "10/100 speed: disabling TSO\n");
2278 netdev->features &= ~NETIF_F_TSO;
2279 break;
2280 case SPEED_1000:
2281 netdev->features |= NETIF_F_TSO;
2282 break;
2283 default:
2284 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002285 break;
2286 }
2287 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002288#endif
2289
2290 /* enable transmits in the hardware, need to do this
2291 * after setting TARC0 */
2292 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2293 tctl |= E1000_TCTL_EN;
2294 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002295
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 netif_carrier_on(netdev);
2297 netif_wake_queue(netdev);
2298 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2299 adapter->smartspeed = 0;
2300 }
2301 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002302 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 adapter->link_speed = 0;
2304 adapter->link_duplex = 0;
2305 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2306 netif_carrier_off(netdev);
2307 netif_stop_queue(netdev);
2308 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002309
2310 /* 80003ES2LAN workaround--
2311 * For packet buffer work-around on link down event;
2312 * disable receives in the ISR and
2313 * reset device here in the watchdog
2314 */
2315 if (adapter->hw.mac_type == e1000_80003es2lan) {
2316 /* reset device */
2317 schedule_work(&adapter->reset_task);
2318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320
2321 e1000_smartspeed(adapter);
2322 }
2323
2324 e1000_update_stats(adapter);
2325
2326 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2327 adapter->tpt_old = adapter->stats.tpt;
2328 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2329 adapter->colc_old = adapter->stats.colc;
2330
2331 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2332 adapter->gorcl_old = adapter->stats.gorcl;
2333 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2334 adapter->gotcl_old = adapter->stats.gotcl;
2335
2336 e1000_update_adaptive(&adapter->hw);
2337
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002338 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002339 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 /* We've lost link, so the controller stops DMA,
2341 * but we've got queued Tx work that's never going
2342 * to get done, so reset controller to flush Tx.
2343 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002344 adapter->tx_timeout_count++;
2345 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 }
2347 }
2348
2349 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002350 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2352 * asymmetrical Tx or Rx gets ITR=8000; everyone
2353 * else is between 2000-8000. */
2354 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002355 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 adapter->gotcl - adapter->gorcl :
2357 adapter->gorcl - adapter->gotcl) / 10000;
2358 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2359 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2360 }
2361
2362 /* Cause software interrupt to ensure rx ring is cleaned */
2363 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2364
Malli Chilakala26483452005-04-28 19:44:46 -07002365 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 adapter->detect_tx_hung = TRUE;
2367
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002368 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002369 * reset from the other port. Set the appropriate LAA in RAR[0] */
2370 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2371 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2372
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 /* Reset the timer */
2374 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2375}
2376
2377#define E1000_TX_FLAGS_CSUM 0x00000001
2378#define E1000_TX_FLAGS_VLAN 0x00000002
2379#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002380#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2382#define E1000_TX_FLAGS_VLAN_SHIFT 16
2383
Auke Koke619d522006-04-14 19:04:52 -07002384static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002385e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2386 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387{
2388#ifdef NETIF_F_TSO
2389 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002390 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 unsigned int i;
2392 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002393 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2395 int err;
2396
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002397 if (skb_shinfo(skb)->tso_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 if (skb_header_cloned(skb)) {
2399 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2400 if (err)
2401 return err;
2402 }
2403
2404 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2405 mss = skb_shinfo(skb)->tso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002406 if (skb->protocol == htons(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002407 skb->nh.iph->tot_len = 0;
2408 skb->nh.iph->check = 0;
2409 skb->h.th->check =
2410 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2411 skb->nh.iph->daddr,
2412 0,
2413 IPPROTO_TCP,
2414 0);
2415 cmd_length = E1000_TXD_CMD_IP;
2416 ipcse = skb->h.raw - skb->data - 1;
2417#ifdef NETIF_F_TSO_IPV6
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002418 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002419 skb->nh.ipv6h->payload_len = 0;
2420 skb->h.th->check =
2421 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2422 &skb->nh.ipv6h->daddr,
2423 0,
2424 IPPROTO_TCP,
2425 0);
2426 ipcse = 0;
2427#endif
2428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 ipcss = skb->nh.raw - skb->data;
2430 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 tucss = skb->h.raw - skb->data;
2432 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2433 tucse = 0;
2434
2435 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002436 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002438 i = tx_ring->next_to_use;
2439 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002440 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
2442 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2443 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2444 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2445 context_desc->upper_setup.tcp_fields.tucss = tucss;
2446 context_desc->upper_setup.tcp_fields.tucso = tucso;
2447 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2448 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2449 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2450 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2451
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002452 buffer_info->time_stamp = jiffies;
2453
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002454 if (++i == tx_ring->count) i = 0;
2455 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Jeff Kirsher8241e352006-01-12 16:51:34 -08002457 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 }
2459#endif
2460
Jeff Kirsher8241e352006-01-12 16:51:34 -08002461 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462}
2463
Auke Koke619d522006-04-14 19:04:52 -07002464static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002465e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2466 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467{
2468 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002469 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 unsigned int i;
2471 uint8_t css;
2472
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002473 if (likely(skb->ip_summed == CHECKSUM_HW)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 css = skb->h.raw - skb->data;
2475
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002476 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002477 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002478 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
2480 context_desc->upper_setup.tcp_fields.tucss = css;
2481 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2482 context_desc->upper_setup.tcp_fields.tucse = 0;
2483 context_desc->tcp_seg_setup.data = 0;
2484 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2485
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002486 buffer_info->time_stamp = jiffies;
2487
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002488 if (unlikely(++i == tx_ring->count)) i = 0;
2489 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490
2491 return TRUE;
2492 }
2493
2494 return FALSE;
2495}
2496
2497#define E1000_MAX_TXD_PWR 12
2498#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2499
Auke Koke619d522006-04-14 19:04:52 -07002500static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002501e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2502 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2503 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 struct e1000_buffer *buffer_info;
2506 unsigned int len = skb->len;
2507 unsigned int offset = 0, size, count = 0, i;
2508 unsigned int f;
2509 len -= skb->data_len;
2510
2511 i = tx_ring->next_to_use;
2512
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002513 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 buffer_info = &tx_ring->buffer_info[i];
2515 size = min(len, max_per_txd);
2516#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002517 /* Workaround for Controller erratum --
2518 * descriptor for non-tso packet in a linear SKB that follows a
2519 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002520 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002521 if (!skb->data_len && tx_ring->last_tx_tso &&
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002522 !skb_shinfo(skb)->tso_size) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002523 tx_ring->last_tx_tso = 0;
2524 size -= 4;
2525 }
2526
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 /* Workaround for premature desc write-backs
2528 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002529 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 size -= 4;
2531#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002532 /* work-around for errata 10 and it applies
2533 * to all controllers in PCI-X mode
2534 * The fix is to make sure that the first descriptor of a
2535 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2536 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002537 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002538 (size > 2015) && count == 0))
2539 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002540
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 /* Workaround for potential 82544 hang in PCI-X. Avoid
2542 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002543 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2545 size > 4))
2546 size -= 4;
2547
2548 buffer_info->length = size;
2549 buffer_info->dma =
2550 pci_map_single(adapter->pdev,
2551 skb->data + offset,
2552 size,
2553 PCI_DMA_TODEVICE);
2554 buffer_info->time_stamp = jiffies;
2555
2556 len -= size;
2557 offset += size;
2558 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002559 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 }
2561
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002562 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 struct skb_frag_struct *frag;
2564
2565 frag = &skb_shinfo(skb)->frags[f];
2566 len = frag->size;
2567 offset = frag->page_offset;
2568
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002569 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 buffer_info = &tx_ring->buffer_info[i];
2571 size = min(len, max_per_txd);
2572#ifdef NETIF_F_TSO
2573 /* Workaround for premature desc write-backs
2574 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002575 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 size -= 4;
2577#endif
2578 /* Workaround for potential 82544 hang in PCI-X.
2579 * Avoid terminating buffers within evenly-aligned
2580 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002581 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2583 size > 4))
2584 size -= 4;
2585
2586 buffer_info->length = size;
2587 buffer_info->dma =
2588 pci_map_page(adapter->pdev,
2589 frag->page,
2590 offset,
2591 size,
2592 PCI_DMA_TODEVICE);
2593 buffer_info->time_stamp = jiffies;
2594
2595 len -= size;
2596 offset += size;
2597 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002598 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 }
2600 }
2601
2602 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2603 tx_ring->buffer_info[i].skb = skb;
2604 tx_ring->buffer_info[first].next_to_watch = i;
2605
2606 return count;
2607}
2608
Auke Koke619d522006-04-14 19:04:52 -07002609static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002610e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2611 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 struct e1000_tx_desc *tx_desc = NULL;
2614 struct e1000_buffer *buffer_info;
2615 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2616 unsigned int i;
2617
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002618 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2620 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002621 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2622
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002623 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002624 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 }
2626
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002627 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2629 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2630 }
2631
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002632 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 txd_lower |= E1000_TXD_CMD_VLE;
2634 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2635 }
2636
2637 i = tx_ring->next_to_use;
2638
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002639 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 buffer_info = &tx_ring->buffer_info[i];
2641 tx_desc = E1000_TX_DESC(*tx_ring, i);
2642 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2643 tx_desc->lower.data =
2644 cpu_to_le32(txd_lower | buffer_info->length);
2645 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002646 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 }
2648
2649 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2650
2651 /* Force memory writes to complete before letting h/w
2652 * know there are new descriptors to fetch. (Only
2653 * applicable for weak-ordered memory model archs,
2654 * such as IA-64). */
2655 wmb();
2656
2657 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002658 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659}
2660
2661/**
2662 * 82547 workaround to avoid controller hang in half-duplex environment.
2663 * The workaround is to avoid queuing a large packet that would span
2664 * the internal Tx FIFO ring boundary by notifying the stack to resend
2665 * the packet at a later time. This gives the Tx FIFO an opportunity to
2666 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2667 * to the beginning of the Tx FIFO.
2668 **/
2669
2670#define E1000_FIFO_HDR 0x10
2671#define E1000_82547_PAD_LEN 0x3E0
2672
Auke Koke619d522006-04-14 19:04:52 -07002673static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2675{
2676 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2677 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2678
2679 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2680
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002681 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 goto no_fifo_stall_required;
2683
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002684 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 return 1;
2686
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002687 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 atomic_set(&adapter->tx_fifo_stall, 1);
2689 return 1;
2690 }
2691
2692no_fifo_stall_required:
2693 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002694 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2696 return 0;
2697}
2698
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002699#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07002700static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002701e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2702{
2703 struct e1000_hw *hw = &adapter->hw;
2704 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002705 if (vlan_tx_tag_present(skb)) {
2706 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002707 ( adapter->hw.mng_cookie.status &
2708 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2709 return 0;
2710 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08002711 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002712 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002713 if ((htons(ETH_P_IP) == eth->h_proto)) {
2714 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002715 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002716 if (IPPROTO_UDP == ip->protocol) {
2717 struct udphdr *udp =
2718 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002719 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002720 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002721 offset = (uint8_t *)udp + 8 - skb->data;
2722 length = skb->len - offset;
2723
2724 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002725 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002726 length);
2727 }
2728 }
2729 }
2730 }
2731 return 0;
2732}
2733
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2735static int
2736e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2737{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002738 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002739 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2741 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2742 unsigned int tx_flags = 0;
2743 unsigned int len = skb->len;
2744 unsigned long flags;
2745 unsigned int nr_frags = 0;
2746 unsigned int mss = 0;
2747 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07002748 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 unsigned int f;
2750 len -= skb->data_len;
2751
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002752 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e42005-10-04 07:03:23 -04002753
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002754 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 dev_kfree_skb_any(skb);
2756 return NETDEV_TX_OK;
2757 }
2758
2759#ifdef NETIF_F_TSO
2760 mss = skb_shinfo(skb)->tso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07002761 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 * make sure there is enough room in the FIFO before
2763 * initiating the DMA for each buffer. The calc is:
2764 * 4 = ceil(buffer len/mss). To make sure we don't
2765 * overrun the FIFO, adjust the max buffer len if mss
2766 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002767 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002768 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 max_per_txd = min(mss << 2, max_per_txd);
2770 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002771
Jeff Kirsher9f687882006-03-02 18:20:17 -08002772 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002773 * points to just header, pull a few bytes of payload from
2774 * frags into skb->data */
2775 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08002776 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
2777 switch (adapter->hw.mac_type) {
2778 unsigned int pull_size;
2779 case e1000_82571:
2780 case e1000_82572:
2781 case e1000_82573:
2782 pull_size = min((unsigned int)4, skb->data_len);
2783 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Kok76c224b2006-05-23 13:36:06 -07002784 printk(KERN_ERR
Jeff Kirsher9f687882006-03-02 18:20:17 -08002785 "__pskb_pull_tail failed.\n");
2786 dev_kfree_skb_any(skb);
Jeff Garzik749dfc72006-03-11 13:35:31 -05002787 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08002788 }
2789 len = skb->len - skb->data_len;
2790 break;
2791 default:
2792 /* do nothing */
2793 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08002794 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 }
2797
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002798 /* reserve a descriptor for the offload context */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002799 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07002801 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802#else
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002803 if (skb->ip_summed == CHECKSUM_HW)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 count++;
2805#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05002806
2807#ifdef NETIF_F_TSO
2808 /* Controller Erratum workaround */
2809 if (!skb->data_len && tx_ring->last_tx_tso &&
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002810 !skb_shinfo(skb)->tso_size)
Jeff Kirsherfd803242005-12-13 00:06:22 -05002811 count++;
2812#endif
2813
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 count += TXD_USE_COUNT(len, max_txd_pwr);
2815
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002816 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 count++;
2818
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002819 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07002820 * in PCI-X mode, so add one more descriptor to the count
2821 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002822 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002823 (len > 2015)))
2824 count++;
2825
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002827 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2829 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002830 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 count += nr_frags;
2832
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002833
2834 if (adapter->hw.tx_pkt_filtering &&
2835 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002836 e1000_transfer_dhcp_info(adapter, skb);
2837
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002838 local_irq_save(flags);
2839 if (!spin_trylock(&tx_ring->tx_lock)) {
2840 /* Collision - tell upper layer to requeue */
2841 local_irq_restore(flags);
2842 return NETDEV_TX_LOCKED;
2843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
2845 /* need: count + 2 desc gap to keep tail from touching
2846 * head, otherwise try next time */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002847 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 netif_stop_queue(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002849 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 return NETDEV_TX_BUSY;
2851 }
2852
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002853 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2854 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 netif_stop_queue(netdev);
2856 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002857 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 return NETDEV_TX_BUSY;
2859 }
2860 }
2861
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002862 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 tx_flags |= E1000_TX_FLAGS_VLAN;
2864 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2865 }
2866
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002867 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002868
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002869 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 if (tso < 0) {
2871 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002872 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 return NETDEV_TX_OK;
2874 }
2875
Jeff Kirsherfd803242005-12-13 00:06:22 -05002876 if (likely(tso)) {
2877 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002879 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 tx_flags |= E1000_TX_FLAGS_CSUM;
2881
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002882 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002883 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002884 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07002885 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002886 tx_flags |= E1000_TX_FLAGS_IPV4;
2887
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002888 e1000_tx_queue(adapter, tx_ring, tx_flags,
2889 e1000_tx_map(adapter, tx_ring, skb, first,
2890 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891
2892 netdev->trans_start = jiffies;
2893
2894 /* Make sure there is space in the ring for the next send. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002895 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 netif_stop_queue(netdev);
2897
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002898 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 return NETDEV_TX_OK;
2900}
2901
2902/**
2903 * e1000_tx_timeout - Respond to a Tx Hang
2904 * @netdev: network interface device structure
2905 **/
2906
2907static void
2908e1000_tx_timeout(struct net_device *netdev)
2909{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002910 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911
2912 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08002913 adapter->tx_timeout_count++;
2914 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915}
2916
2917static void
Jeff Kirsher87041632006-03-02 18:21:24 -08002918e1000_reset_task(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002920 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
2922 e1000_down(adapter);
2923 e1000_up(adapter);
2924}
2925
2926/**
2927 * e1000_get_stats - Get System Network Statistics
2928 * @netdev: network interface device structure
2929 *
2930 * Returns the address of the device statistics structure.
2931 * The statistics are actually updated from the timer callback.
2932 **/
2933
2934static struct net_device_stats *
2935e1000_get_stats(struct net_device *netdev)
2936{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002937 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08002939 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 return &adapter->net_stats;
2941}
2942
2943/**
2944 * e1000_change_mtu - Change the Maximum Transfer Unit
2945 * @netdev: network interface device structure
2946 * @new_mtu: new value for maximum frame size
2947 *
2948 * Returns 0 on success, negative on failure
2949 **/
2950
2951static int
2952e1000_change_mtu(struct net_device *netdev, int new_mtu)
2953{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002954 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08002956 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002958 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2959 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2960 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002961 return -EINVAL;
2962 }
2963
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002964 /* Adapter-specific max frame size limits. */
2965 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07002966 case e1000_undefined ... e1000_82542_rev2_1:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002967 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2968 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002969 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002970 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002971 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08002972 case e1000_82573:
2973 /* only enable jumbo frames if ASPM is disabled completely
2974 * this means both bits must be zero in 0x1A bits 3:2 */
2975 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
2976 &eeprom_data);
2977 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
2978 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2979 DPRINTK(PROBE, ERR,
2980 "Jumbo Frames not supported.\n");
2981 return -EINVAL;
2982 }
2983 break;
2984 }
2985 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002986 case e1000_82571:
2987 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08002988 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002989#define MAX_STD_JUMBO_FRAME_SIZE 9234
2990 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
2991 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
2992 return -EINVAL;
2993 }
2994 break;
2995 default:
2996 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
2997 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002998 }
2999
Auke Kok9e2feac2006-04-14 19:05:18 -07003000 /* NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3001 * means we reserve 2 more, this pushes us to allocate from the next
3002 * larger slab size
3003 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003004
Auke Kok9e2feac2006-04-14 19:05:18 -07003005 if (max_frame <= E1000_RXBUFFER_256)
3006 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3007 else if (max_frame <= E1000_RXBUFFER_512)
3008 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3009 else if (max_frame <= E1000_RXBUFFER_1024)
3010 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3011 else if (max_frame <= E1000_RXBUFFER_2048)
3012 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3013 else if (max_frame <= E1000_RXBUFFER_4096)
3014 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3015 else if (max_frame <= E1000_RXBUFFER_8192)
3016 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3017 else if (max_frame <= E1000_RXBUFFER_16384)
3018 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3019
3020 /* adjust allocation if LPE protects us, and we aren't using SBP */
3021#define MAXIMUM_ETHERNET_VLAN_SIZE 1522
3022 if (!adapter->hw.tbi_compatibility_on &&
3023 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3024 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3025 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003026
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003027 netdev->mtu = new_mtu;
3028
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003029 if (netif_running(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 e1000_down(adapter);
3031 e1000_up(adapter);
3032 }
3033
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 adapter->hw.max_frame_size = max_frame;
3035
3036 return 0;
3037}
3038
3039/**
3040 * e1000_update_stats - Update the board statistics counters
3041 * @adapter: board private structure
3042 **/
3043
3044void
3045e1000_update_stats(struct e1000_adapter *adapter)
3046{
3047 struct e1000_hw *hw = &adapter->hw;
Auke Koka487a8f2006-06-09 11:29:03 -07003048 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 unsigned long flags;
3050 uint16_t phy_tmp;
3051
3052#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3053
Auke Koka487a8f2006-06-09 11:29:03 -07003054 /*
3055 * Prevent stats update while adapter is being reset, or if the pci
3056 * connection is down.
3057 */
Auke Kok90267292006-06-08 09:30:24 -07003058 if (adapter->link_speed == 0)
3059 return;
Auke Koka487a8f2006-06-09 11:29:03 -07003060 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3061 return;
Auke Kok90267292006-06-08 09:30:24 -07003062
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 spin_lock_irqsave(&adapter->stats_lock, flags);
3064
3065 /* these counters are modified from e1000_adjust_tbi_stats,
3066 * called from the interrupt context, so they must only
3067 * be written while holding adapter->stats_lock
3068 */
3069
3070 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3071 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3072 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3073 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3074 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3075 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3076 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3077 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3078 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3079 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3080 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3081 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3082 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3083
3084 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3085 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3086 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3087 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3088 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3089 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3090 adapter->stats.dc += E1000_READ_REG(hw, DC);
3091 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3092 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3093 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3094 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3095 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3096 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3097 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3098 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3099 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3100 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3101 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3102 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3103 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3104 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3105 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3106 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3107 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3108 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3109 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3110 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3111 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3112 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3113 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3114 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3115 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3116 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3117 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3118
3119 /* used for adaptive IFS */
3120
3121 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3122 adapter->stats.tpt += hw->tx_packet_delta;
3123 hw->collision_delta = E1000_READ_REG(hw, COLC);
3124 adapter->stats.colc += hw->collision_delta;
3125
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003126 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3128 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3129 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3130 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3131 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3132 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3133 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003134 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003135 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3136 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3137 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3138 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3139 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3140 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3141 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3142 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3143 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
3146 /* Fill out the OS statistics structure */
3147
3148 adapter->net_stats.rx_packets = adapter->stats.gprc;
3149 adapter->net_stats.tx_packets = adapter->stats.gptc;
3150 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3151 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3152 adapter->net_stats.multicast = adapter->stats.mprc;
3153 adapter->net_stats.collisions = adapter->stats.colc;
3154
3155 /* Rx Errors */
3156
Jeff Kirsher87041632006-03-02 18:21:24 -08003157 /* RLEC on some newer hardware can be incorrect so build
3158 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3160 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003161 adapter->stats.ruc + adapter->stats.roc +
3162 adapter->stats.cexterr;
Jeff Kirsher87041632006-03-02 18:21:24 -08003163 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3164 adapter->stats.roc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3166 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3168
3169 /* Tx Errors */
3170
3171 adapter->net_stats.tx_errors = adapter->stats.ecol +
3172 adapter->stats.latecol;
3173 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3174 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3175 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3176
3177 /* Tx Dropped needs to be maintained elsewhere */
3178
3179 /* Phy Stats */
3180
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003181 if (hw->media_type == e1000_media_type_copper) {
3182 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3184 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3185 adapter->phy_stats.idle_errors += phy_tmp;
3186 }
3187
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003188 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 (hw->phy_type == e1000_phy_m88) &&
3190 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3191 adapter->phy_stats.receive_errors += phy_tmp;
3192 }
3193
3194 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3195}
3196
3197/**
3198 * e1000_intr - Interrupt Handler
3199 * @irq: interrupt number
3200 * @data: pointer to a network interface device structure
3201 * @pt_regs: CPU registers structure
3202 **/
3203
3204static irqreturn_t
3205e1000_intr(int irq, void *data, struct pt_regs *regs)
3206{
3207 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003208 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003210 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003211#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003212 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003213#else
3214 /* Interrupt Auto-Mask...upon reading ICR,
3215 * interrupts are masked. No need for the
3216 * IMC write, but it does mean we should
3217 * account for it ASAP. */
3218 if (likely(hw->mac_type >= e1000_82571))
3219 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003220#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003222 if (unlikely(!icr)) {
3223#ifdef CONFIG_E1000_NAPI
3224 if (hw->mac_type >= e1000_82571)
3225 e1000_irq_enable(adapter);
3226#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003230 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003232 /* 80003ES2LAN workaround--
3233 * For packet buffer work-around on link down event;
3234 * disable receives here in the ISR and
3235 * reset adapter in watchdog
3236 */
3237 if (netif_carrier_ok(netdev) &&
3238 (adapter->hw.mac_type == e1000_80003es2lan)) {
3239 /* disable receives */
3240 rctl = E1000_READ_REG(hw, RCTL);
3241 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 mod_timer(&adapter->watchdog_timer, jiffies);
3244 }
3245
3246#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003247 if (unlikely(hw->mac_type < e1000_82571)) {
3248 atomic_inc(&adapter->irq_sem);
3249 E1000_WRITE_REG(hw, IMC, ~0);
3250 E1000_WRITE_FLUSH(hw);
3251 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003252 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3253 __netif_rx_schedule(&adapter->polling_netdev[0]);
3254 else
3255 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003256#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003258 * Due to Hub Link bus being occupied, an interrupt
3259 * de-assertion message is not able to be sent.
3260 * When an interrupt assertion message is generated later,
3261 * two messages are re-ordered and sent out.
3262 * That causes APIC to think 82547 is in de-assertion
3263 * state, while 82547 is in assertion state, resulting
3264 * in dead lock. Writing IMC forces 82547 into
3265 * de-assertion state.
3266 */
3267 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003269 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 }
3271
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003272 for (i = 0; i < E1000_MAX_INTR; i++)
3273 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003274 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 break;
3276
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003277 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003279
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003280#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
3282 return IRQ_HANDLED;
3283}
3284
3285#ifdef CONFIG_E1000_NAPI
3286/**
3287 * e1000_clean - NAPI Rx polling callback
3288 * @adapter: board private structure
3289 **/
3290
3291static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003292e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003294 struct e1000_adapter *adapter;
3295 int work_to_do = min(*budget, poll_dev->quota);
Jeff Kirsher38bd3b22006-01-12 16:51:37 -08003296 int tx_cleaned = 0, i = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003297
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003298 /* Must NOT use netdev_priv macro here. */
3299 adapter = poll_dev->priv;
3300
3301 /* Keep link state information with original netdev */
3302 if (!netif_carrier_ok(adapter->netdev))
3303 goto quit_polling;
3304
3305 while (poll_dev != &adapter->polling_netdev[i]) {
3306 i++;
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02003307 BUG_ON(i == adapter->num_rx_queues);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003308 }
3309
Jeff Kirsher8241e352006-01-12 16:51:34 -08003310 if (likely(adapter->num_tx_queues == 1)) {
3311 /* e1000_clean is called per-cpu. This lock protects
3312 * tx_ring[0] from being cleaned by multiple cpus
3313 * simultaneously. A failure obtaining the lock means
3314 * tx_ring[0] is currently being cleaned anyway. */
3315 if (spin_trylock(&adapter->tx_queue_lock)) {
3316 tx_cleaned = e1000_clean_tx_irq(adapter,
3317 &adapter->tx_ring[0]);
3318 spin_unlock(&adapter->tx_queue_lock);
3319 }
3320 } else
3321 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3322
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003323 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3324 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325
3326 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003327 poll_dev->quota -= work_done;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003328
Malli Chilakala2b028932005-06-17 17:46:06 -07003329 /* If no Tx and not enough Rx work done, exit the polling mode */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003330 if ((!tx_cleaned && (work_done == 0)) ||
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003331 !netif_running(adapter->netdev)) {
3332quit_polling:
3333 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 e1000_irq_enable(adapter);
3335 return 0;
3336 }
3337
3338 return 1;
3339}
3340
3341#endif
3342/**
3343 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3344 * @adapter: board private structure
3345 **/
3346
3347static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003348e1000_clean_tx_irq(struct e1000_adapter *adapter,
3349 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 struct net_device *netdev = adapter->netdev;
3352 struct e1000_tx_desc *tx_desc, *eop_desc;
3353 struct e1000_buffer *buffer_info;
3354 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003355#ifdef CONFIG_E1000_NAPI
3356 unsigned int count = 0;
3357#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 boolean_t cleaned = FALSE;
3359
3360 i = tx_ring->next_to_clean;
3361 eop = tx_ring->buffer_info[i].next_to_watch;
3362 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3363
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003364 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003365 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 tx_desc = E1000_TX_DESC(*tx_ring, i);
3367 buffer_info = &tx_ring->buffer_info[i];
3368 cleaned = (i == eop);
3369
Jeff Kirsherfd803242005-12-13 00:06:22 -05003370 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jeff Kirsher8241e352006-01-12 16:51:34 -08003371 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003373 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003375
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003376
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 eop = tx_ring->buffer_info[i].next_to_watch;
3378 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003379#ifdef CONFIG_E1000_NAPI
3380#define E1000_TX_WEIGHT 64
3381 /* weight of a sort for tx, to avoid endless transmit cleanup */
3382 if (count++ == E1000_TX_WEIGHT) break;
3383#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 }
3385
3386 tx_ring->next_to_clean = i;
3387
Auke Kok77b2aad2006-04-14 19:05:25 -07003388#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003389 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
Auke Kok77b2aad2006-04-14 19:05:25 -07003390 netif_carrier_ok(netdev))) {
3391 spin_lock(&tx_ring->tx_lock);
3392 if (netif_queue_stopped(netdev) &&
3393 (E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))
3394 netif_wake_queue(netdev);
3395 spin_unlock(&tx_ring->tx_lock);
3396 }
Malli Chilakala26483452005-04-28 19:44:46 -07003397
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003398 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003399 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 * check with the clearing of time_stamp and movement of i */
3401 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003402 if (tx_ring->buffer_info[eop].dma &&
3403 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003404 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003405 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003406 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003407
3408 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003409 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003410 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003411 " TDH <%x>\n"
3412 " TDT <%x>\n"
3413 " next_to_use <%x>\n"
3414 " next_to_clean <%x>\n"
3415 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003416 " time_stamp <%lx>\n"
3417 " next_to_watch <%x>\n"
3418 " jiffies <%lx>\n"
3419 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003420 (unsigned long)((tx_ring - adapter->tx_ring) /
3421 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003422 readl(adapter->hw.hw_addr + tx_ring->tdh),
3423 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003424 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003425 tx_ring->next_to_clean,
3426 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003427 eop,
3428 jiffies,
3429 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 return cleaned;
3434}
3435
3436/**
3437 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003438 * @adapter: board private structure
3439 * @status_err: receive descriptor status and error fields
3440 * @csum: receive descriptor csum field
3441 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 **/
3443
Auke Koke619d522006-04-14 19:04:52 -07003444static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003446 uint32_t status_err, uint32_t csum,
3447 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003449 uint16_t status = (uint16_t)status_err;
3450 uint8_t errors = (uint8_t)(status_err >> 24);
3451 skb->ip_summed = CHECKSUM_NONE;
3452
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003454 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003456 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003457 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003458 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003459 /* let the stack verify checksum errors */
3460 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 return;
3462 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003463 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003464 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3465 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003466 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003468 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003469 return;
3470 }
3471 /* It must be a TCP or UDP packet with a valid checksum */
3472 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 /* TCP checksum is good */
3474 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003475 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3476 /* IP fragment with UDP payload */
3477 /* Hardware complements the payload checksum, so we undo it
3478 * and then put the value in host order for further stack use.
3479 */
3480 csum = ntohl(csum ^ 0xFFFF);
3481 skb->csum = csum;
3482 skb->ip_summed = CHECKSUM_HW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003484 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485}
3486
3487/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003488 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 * @adapter: board private structure
3490 **/
3491
3492static boolean_t
3493#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003494e1000_clean_rx_irq(struct e1000_adapter *adapter,
3495 struct e1000_rx_ring *rx_ring,
3496 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003498e1000_clean_rx_irq(struct e1000_adapter *adapter,
3499 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500#endif
3501{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 struct net_device *netdev = adapter->netdev;
3503 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003504 struct e1000_rx_desc *rx_desc, *next_rxd;
3505 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 unsigned long flags;
3507 uint32_t length;
3508 uint8_t last_byte;
3509 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003510 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003511 boolean_t cleaned = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512
3513 i = rx_ring->next_to_clean;
3514 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003515 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003517 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07003518 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003519 u8 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003521 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 break;
3523 (*work_done)++;
3524#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08003525 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003526 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003527 buffer_info->skb = NULL;
3528
Jeff Kirsher30320be2006-03-02 18:21:57 -08003529 prefetch(skb->data - NET_IP_ALIGN);
3530
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003531 if (++i == rx_ring->count) i = 0;
3532 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003533 prefetch(next_rxd);
3534
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003535 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003536
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003537 cleaned = TRUE;
3538 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003539 pci_unmap_single(pdev,
3540 buffer_info->dma,
3541 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 PCI_DMA_FROMDEVICE);
3543
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 length = le16_to_cpu(rx_desc->length);
3545
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003546 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3547 /* All receives must fit into a single buffer */
3548 E1000_DBG("%s: Receive packet consumed multiple"
3549 " buffers\n", netdev->name);
3550 dev_kfree_skb_irq(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 goto next_desc;
3552 }
3553
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003554 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003556 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 rx_desc->errors, length, last_byte)) {
3558 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003559 e1000_tbi_adjust_stats(&adapter->hw,
3560 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 length, skb->data);
3562 spin_unlock_irqrestore(&adapter->stats_lock,
3563 flags);
3564 length--;
3565 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07003566 /* recycle */
3567 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 goto next_desc;
3569 }
Auke Kok1cb58212006-04-18 12:31:04 -07003570 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571
Jeff Kirshera292ca62006-01-12 16:51:30 -08003572 /* code added for copybreak, this should improve
3573 * performance for small packets with large amounts
3574 * of reassembly being done in the stack */
3575#define E1000_CB_LENGTH 256
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003576 if (length < E1000_CB_LENGTH) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08003577 struct sk_buff *new_skb =
3578 dev_alloc_skb(length + NET_IP_ALIGN);
3579 if (new_skb) {
3580 skb_reserve(new_skb, NET_IP_ALIGN);
3581 new_skb->dev = netdev;
3582 memcpy(new_skb->data - NET_IP_ALIGN,
3583 skb->data - NET_IP_ALIGN,
3584 length + NET_IP_ALIGN);
3585 /* save the skb in buffer_info as good */
3586 buffer_info->skb = skb;
3587 skb = new_skb;
3588 skb_put(skb, length);
3589 }
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003590 } else
3591 skb_put(skb, length);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003592
3593 /* end copybreak code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594
3595 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08003596 e1000_rx_checksum(adapter,
3597 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003598 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003599 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003600
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 skb->protocol = eth_type_trans(skb, netdev);
3602#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003603 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08003604 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003606 le16_to_cpu(rx_desc->special) &
3607 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 } else {
3609 netif_receive_skb(skb);
3610 }
3611#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003612 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003613 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 vlan_hwaccel_rx(skb, adapter->vlgrp,
3615 le16_to_cpu(rx_desc->special) &
3616 E1000_RXD_SPC_VLAN_MASK);
3617 } else {
3618 netif_rx(skb);
3619 }
3620#endif /* CONFIG_E1000_NAPI */
3621 netdev->last_rx = jiffies;
3622
3623next_desc:
3624 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003626 /* return some buffers to hardware, one at a time is too slow */
3627 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3628 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3629 cleaned_count = 0;
3630 }
3631
Jeff Kirsher30320be2006-03-02 18:21:57 -08003632 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003633 rx_desc = next_rxd;
3634 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003637
3638 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3639 if (cleaned_count)
3640 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641
3642 return cleaned;
3643}
3644
3645/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003646 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3647 * @adapter: board private structure
3648 **/
3649
3650static boolean_t
3651#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003652e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3653 struct e1000_rx_ring *rx_ring,
3654 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003655#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003656e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3657 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003658#endif
3659{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003660 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003661 struct net_device *netdev = adapter->netdev;
3662 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003663 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003664 struct e1000_ps_page *ps_page;
3665 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07003666 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003667 unsigned int i, j;
3668 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003669 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003670 boolean_t cleaned = FALSE;
3671
3672 i = rx_ring->next_to_clean;
3673 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003674 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07003675 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003676
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003677 while (staterr & E1000_RXD_STAT_DD) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08003678 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003679 ps_page = &rx_ring->ps_page[i];
3680 ps_page_dma = &rx_ring->ps_page_dma[i];
3681#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003682 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003683 break;
3684 (*work_done)++;
3685#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003686 skb = buffer_info->skb;
3687
Jeff Kirsher30320be2006-03-02 18:21:57 -08003688 /* in the packet split case this is header only */
3689 prefetch(skb->data - NET_IP_ALIGN);
3690
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003691 if (++i == rx_ring->count) i = 0;
3692 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003693 prefetch(next_rxd);
3694
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003695 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003696
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003697 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003698 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003699 pci_unmap_single(pdev, buffer_info->dma,
3700 buffer_info->length,
3701 PCI_DMA_FROMDEVICE);
3702
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003703 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003704 E1000_DBG("%s: Packet Split buffers didn't pick up"
3705 " the full packet\n", netdev->name);
3706 dev_kfree_skb_irq(skb);
3707 goto next_desc;
3708 }
3709
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003710 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003711 dev_kfree_skb_irq(skb);
3712 goto next_desc;
3713 }
3714
3715 length = le16_to_cpu(rx_desc->wb.middle.length0);
3716
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003717 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003718 E1000_DBG("%s: Last part of the packet spanning"
3719 " multiple descriptors\n", netdev->name);
3720 dev_kfree_skb_irq(skb);
3721 goto next_desc;
3722 }
3723
3724 /* Good Receive */
3725 skb_put(skb, length);
3726
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003727 {
3728 /* this looks ugly, but it seems compiler issues make it
3729 more efficient than reusing j */
3730 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3731
3732 /* page alloc/put takes too long and effects small packet
3733 * throughput, so unsplit small packets and save the alloc/put*/
Auke Kok9e2feac2006-04-14 19:05:18 -07003734 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003735 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07003736 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003737 * kmap_atomic, so we can't hold the mapping
3738 * very long */
3739 pci_dma_sync_single_for_cpu(pdev,
3740 ps_page_dma->ps_page_dma[0],
3741 PAGE_SIZE,
3742 PCI_DMA_FROMDEVICE);
3743 vaddr = kmap_atomic(ps_page->ps_page[0],
3744 KM_SKB_DATA_SOFTIRQ);
3745 memcpy(skb->tail, vaddr, l1);
3746 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
3747 pci_dma_sync_single_for_device(pdev,
3748 ps_page_dma->ps_page_dma[0],
3749 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3750 skb_put(skb, l1);
3751 length += l1;
3752 goto copydone;
3753 } /* if */
3754 }
3755
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003756 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08003757 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003758 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003759 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3760 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3761 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08003762 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
3763 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003764 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003765 skb->len += length;
3766 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07003767 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003768 }
3769
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003770copydone:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003771 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003772 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003773 skb->protocol = eth_type_trans(skb, netdev);
3774
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003775 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003776 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003777 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003778#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003779 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003780 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003781 le16_to_cpu(rx_desc->wb.middle.vlan) &
3782 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003783 } else {
3784 netif_receive_skb(skb);
3785 }
3786#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003787 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003788 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003789 le16_to_cpu(rx_desc->wb.middle.vlan) &
3790 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003791 } else {
3792 netif_rx(skb);
3793 }
3794#endif /* CONFIG_E1000_NAPI */
3795 netdev->last_rx = jiffies;
3796
3797next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003798 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003799 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003800
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003801 /* return some buffers to hardware, one at a time is too slow */
3802 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3803 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3804 cleaned_count = 0;
3805 }
3806
Jeff Kirsher30320be2006-03-02 18:21:57 -08003807 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003808 rx_desc = next_rxd;
3809 buffer_info = next_buffer;
3810
Malli Chilakala683a38f2005-06-17 17:43:25 -07003811 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003812 }
3813 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003814
3815 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3816 if (cleaned_count)
3817 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003818
3819 return cleaned;
3820}
3821
3822/**
3823 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 * @adapter: address of board private structure
3825 **/
3826
3827static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003828e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003829 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08003830 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 struct net_device *netdev = adapter->netdev;
3833 struct pci_dev *pdev = adapter->pdev;
3834 struct e1000_rx_desc *rx_desc;
3835 struct e1000_buffer *buffer_info;
3836 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003837 unsigned int i;
3838 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839
3840 i = rx_ring->next_to_use;
3841 buffer_info = &rx_ring->buffer_info[i];
3842
Jeff Kirshera292ca62006-01-12 16:51:30 -08003843 while (cleaned_count--) {
3844 if (!(skb = buffer_info->skb))
3845 skb = dev_alloc_skb(bufsz);
3846 else {
3847 skb_trim(skb, 0);
3848 goto map_skb;
3849 }
3850
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003851 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003853 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 break;
3855 }
3856
Malli Chilakala26483452005-04-28 19:44:46 -07003857 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3859 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003860 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3861 "at %p\n", bufsz, skb->data);
3862 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 skb = dev_alloc_skb(bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07003864 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 if (!skb) {
3866 dev_kfree_skb(oldskb);
3867 break;
3868 }
Malli Chilakala26483452005-04-28 19:44:46 -07003869
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3871 /* give up */
3872 dev_kfree_skb(skb);
3873 dev_kfree_skb(oldskb);
3874 break; /* while !buffer_info->skb */
3875 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07003876 /* Use new allocation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 dev_kfree_skb(oldskb);
3878 }
3879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 /* Make buffer alignment 2 beyond a 16 byte boundary
3881 * this will result in a 16 byte aligned IP header after
3882 * the 14 byte MAC header is removed
3883 */
3884 skb_reserve(skb, NET_IP_ALIGN);
3885
3886 skb->dev = netdev;
3887
3888 buffer_info->skb = skb;
3889 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003890map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 buffer_info->dma = pci_map_single(pdev,
3892 skb->data,
3893 adapter->rx_buffer_len,
3894 PCI_DMA_FROMDEVICE);
3895
Malli Chilakala26483452005-04-28 19:44:46 -07003896 /* Fix for errata 23, can't cross 64kB boundary */
3897 if (!e1000_check_64k_bound(adapter,
3898 (void *)(unsigned long)buffer_info->dma,
3899 adapter->rx_buffer_len)) {
3900 DPRINTK(RX_ERR, ERR,
3901 "dma align check failed: %u bytes at %p\n",
3902 adapter->rx_buffer_len,
3903 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 dev_kfree_skb(skb);
3905 buffer_info->skb = NULL;
3906
Malli Chilakala26483452005-04-28 19:44:46 -07003907 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 adapter->rx_buffer_len,
3909 PCI_DMA_FROMDEVICE);
3910
3911 break; /* while !buffer_info->skb */
3912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 rx_desc = E1000_RX_DESC(*rx_ring, i);
3914 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3915
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003916 if (unlikely(++i == rx_ring->count))
3917 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 buffer_info = &rx_ring->buffer_info[i];
3919 }
3920
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003921 if (likely(rx_ring->next_to_use != i)) {
3922 rx_ring->next_to_use = i;
3923 if (unlikely(i-- == 0))
3924 i = (rx_ring->count - 1);
3925
3926 /* Force memory writes to complete before letting h/w
3927 * know there are new descriptors to fetch. (Only
3928 * applicable for weak-ordered memory model archs,
3929 * such as IA-64). */
3930 wmb();
3931 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933}
3934
3935/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003936 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3937 * @adapter: address of board private structure
3938 **/
3939
3940static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003941e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003942 struct e1000_rx_ring *rx_ring,
3943 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003944{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003945 struct net_device *netdev = adapter->netdev;
3946 struct pci_dev *pdev = adapter->pdev;
3947 union e1000_rx_desc_packet_split *rx_desc;
3948 struct e1000_buffer *buffer_info;
3949 struct e1000_ps_page *ps_page;
3950 struct e1000_ps_page_dma *ps_page_dma;
3951 struct sk_buff *skb;
3952 unsigned int i, j;
3953
3954 i = rx_ring->next_to_use;
3955 buffer_info = &rx_ring->buffer_info[i];
3956 ps_page = &rx_ring->ps_page[i];
3957 ps_page_dma = &rx_ring->ps_page_dma[i];
3958
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003959 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003960 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3961
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003962 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003963 if (j < adapter->rx_ps_pages) {
3964 if (likely(!ps_page->ps_page[j])) {
3965 ps_page->ps_page[j] =
3966 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003967 if (unlikely(!ps_page->ps_page[j])) {
3968 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003969 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003970 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003971 ps_page_dma->ps_page_dma[j] =
3972 pci_map_page(pdev,
3973 ps_page->ps_page[j],
3974 0, PAGE_SIZE,
3975 PCI_DMA_FROMDEVICE);
3976 }
3977 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003978 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003979 * this info.
3980 */
3981 rx_desc->read.buffer_addr[j+1] =
3982 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3983 } else
3984 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003985 }
3986
3987 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3988
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003989 if (unlikely(!skb)) {
3990 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003991 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003992 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003993
3994 /* Make buffer alignment 2 beyond a 16 byte boundary
3995 * this will result in a 16 byte aligned IP header after
3996 * the 14 byte MAC header is removed
3997 */
3998 skb_reserve(skb, NET_IP_ALIGN);
3999
4000 skb->dev = netdev;
4001
4002 buffer_info->skb = skb;
4003 buffer_info->length = adapter->rx_ps_bsize0;
4004 buffer_info->dma = pci_map_single(pdev, skb->data,
4005 adapter->rx_ps_bsize0,
4006 PCI_DMA_FROMDEVICE);
4007
4008 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4009
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004010 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004011 buffer_info = &rx_ring->buffer_info[i];
4012 ps_page = &rx_ring->ps_page[i];
4013 ps_page_dma = &rx_ring->ps_page_dma[i];
4014 }
4015
4016no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004017 if (likely(rx_ring->next_to_use != i)) {
4018 rx_ring->next_to_use = i;
4019 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4020
4021 /* Force memory writes to complete before letting h/w
4022 * know there are new descriptors to fetch. (Only
4023 * applicable for weak-ordered memory model archs,
4024 * such as IA-64). */
4025 wmb();
4026 /* Hardware increments by 16 bytes, but packet split
4027 * descriptors are 32 bytes...so we increment tail
4028 * twice as much.
4029 */
4030 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4031 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004032}
4033
4034/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4036 * @adapter:
4037 **/
4038
4039static void
4040e1000_smartspeed(struct e1000_adapter *adapter)
4041{
4042 uint16_t phy_status;
4043 uint16_t phy_ctrl;
4044
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004045 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4047 return;
4048
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004049 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 /* If Master/Slave config fault is asserted twice,
4051 * we assume back-to-back */
4052 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004053 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004055 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004057 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4059 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4060 phy_ctrl);
4061 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004062 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4064 &phy_ctrl)) {
4065 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4066 MII_CR_RESTART_AUTO_NEG);
4067 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4068 phy_ctrl);
4069 }
4070 }
4071 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004072 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 /* If still no link, perhaps using 2/3 pair cable */
4074 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4075 phy_ctrl |= CR_1000T_MS_ENABLE;
4076 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004077 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4079 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4080 MII_CR_RESTART_AUTO_NEG);
4081 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4082 }
4083 }
4084 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004085 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 adapter->smartspeed = 0;
4087}
4088
4089/**
4090 * e1000_ioctl -
4091 * @netdev:
4092 * @ifreq:
4093 * @cmd:
4094 **/
4095
4096static int
4097e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4098{
4099 switch (cmd) {
4100 case SIOCGMIIPHY:
4101 case SIOCGMIIREG:
4102 case SIOCSMIIREG:
4103 return e1000_mii_ioctl(netdev, ifr, cmd);
4104 default:
4105 return -EOPNOTSUPP;
4106 }
4107}
4108
4109/**
4110 * e1000_mii_ioctl -
4111 * @netdev:
4112 * @ifreq:
4113 * @cmd:
4114 **/
4115
4116static int
4117e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4118{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004119 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 struct mii_ioctl_data *data = if_mii(ifr);
4121 int retval;
4122 uint16_t mii_reg;
4123 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004124 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004126 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127 return -EOPNOTSUPP;
4128
4129 switch (cmd) {
4130 case SIOCGMIIPHY:
4131 data->phy_id = adapter->hw.phy_addr;
4132 break;
4133 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004134 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004136 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004137 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004138 &data->val_out)) {
4139 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004141 }
4142 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 break;
4144 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004145 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004147 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 return -EFAULT;
4149 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004150 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004151 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004152 mii_reg)) {
4153 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004155 }
Auke Kokdc86d322006-04-18 12:30:51 -07004156 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 switch (data->reg_num) {
4158 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004159 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004161 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 adapter->hw.autoneg = 1;
4163 adapter->hw.autoneg_advertised = 0x2F;
4164 } else {
4165 if (mii_reg & 0x40)
4166 spddplx = SPEED_1000;
4167 else if (mii_reg & 0x2000)
4168 spddplx = SPEED_100;
4169 else
4170 spddplx = SPEED_10;
4171 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004172 ? DUPLEX_FULL :
4173 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 retval = e1000_set_spd_dplx(adapter,
4175 spddplx);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004176 if (retval) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004177 spin_unlock_irqrestore(
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004178 &adapter->stats_lock,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004179 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004181 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004183 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 e1000_down(adapter);
4185 e1000_up(adapter);
4186 } else
4187 e1000_reset(adapter);
4188 break;
4189 case M88E1000_PHY_SPEC_CTRL:
4190 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004191 if (e1000_phy_reset(&adapter->hw)) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004192 spin_unlock_irqrestore(
4193 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 break;
4197 }
4198 } else {
4199 switch (data->reg_num) {
4200 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004201 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004203 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204 e1000_down(adapter);
4205 e1000_up(adapter);
4206 } else
4207 e1000_reset(adapter);
4208 break;
4209 }
4210 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004211 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 break;
4213 default:
4214 return -EOPNOTSUPP;
4215 }
4216 return E1000_SUCCESS;
4217}
4218
4219void
4220e1000_pci_set_mwi(struct e1000_hw *hw)
4221{
4222 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004223 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004225 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004226 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227}
4228
4229void
4230e1000_pci_clear_mwi(struct e1000_hw *hw)
4231{
4232 struct e1000_adapter *adapter = hw->back;
4233
4234 pci_clear_mwi(adapter->pdev);
4235}
4236
4237void
4238e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4239{
4240 struct e1000_adapter *adapter = hw->back;
4241
4242 pci_read_config_word(adapter->pdev, reg, value);
4243}
4244
4245void
4246e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4247{
4248 struct e1000_adapter *adapter = hw->back;
4249
4250 pci_write_config_word(adapter->pdev, reg, *value);
4251}
4252
4253uint32_t
4254e1000_io_read(struct e1000_hw *hw, unsigned long port)
4255{
4256 return inl(port);
4257}
4258
4259void
4260e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4261{
4262 outl(value, port);
4263}
4264
4265static void
4266e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4267{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004268 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 uint32_t ctrl, rctl;
4270
4271 e1000_irq_disable(adapter);
4272 adapter->vlgrp = grp;
4273
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004274 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 /* enable VLAN tag insert/strip */
4276 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4277 ctrl |= E1000_CTRL_VME;
4278 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4279
4280 /* enable VLAN receive filtering */
4281 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4282 rctl |= E1000_RCTL_VFE;
4283 rctl &= ~E1000_RCTL_CFIEN;
4284 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004285 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286 } else {
4287 /* disable VLAN tag insert/strip */
4288 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4289 ctrl &= ~E1000_CTRL_VME;
4290 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4291
4292 /* disable VLAN filtering */
4293 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4294 rctl &= ~E1000_RCTL_VFE;
4295 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004296 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004297 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4298 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 }
4301
4302 e1000_irq_enable(adapter);
4303}
4304
4305static void
4306e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4307{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004308 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004310
4311 if ((adapter->hw.mng_cookie.status &
4312 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4313 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004314 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 /* add VID to filter table */
4316 index = (vid >> 5) & 0x7F;
4317 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4318 vfta |= (1 << (vid & 0x1F));
4319 e1000_write_vfta(&adapter->hw, index, vfta);
4320}
4321
4322static void
4323e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4324{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004325 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 uint32_t vfta, index;
4327
4328 e1000_irq_disable(adapter);
4329
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004330 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331 adapter->vlgrp->vlan_devices[vid] = NULL;
4332
4333 e1000_irq_enable(adapter);
4334
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004335 if ((adapter->hw.mng_cookie.status &
4336 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004337 (vid == adapter->mng_vlan_id)) {
4338 /* release control to f/w */
4339 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004340 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004341 }
4342
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 /* remove VID from filter table */
4344 index = (vid >> 5) & 0x7F;
4345 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4346 vfta &= ~(1 << (vid & 0x1F));
4347 e1000_write_vfta(&adapter->hw, index, vfta);
4348}
4349
4350static void
4351e1000_restore_vlan(struct e1000_adapter *adapter)
4352{
4353 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4354
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004355 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004357 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4358 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 continue;
4360 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4361 }
4362 }
4363}
4364
4365int
4366e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4367{
4368 adapter->hw.autoneg = 0;
4369
Malli Chilakala69213682005-06-17 17:44:20 -07004370 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004371 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004372 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4373 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4374 return -EINVAL;
4375 }
4376
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004377 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378 case SPEED_10 + DUPLEX_HALF:
4379 adapter->hw.forced_speed_duplex = e1000_10_half;
4380 break;
4381 case SPEED_10 + DUPLEX_FULL:
4382 adapter->hw.forced_speed_duplex = e1000_10_full;
4383 break;
4384 case SPEED_100 + DUPLEX_HALF:
4385 adapter->hw.forced_speed_duplex = e1000_100_half;
4386 break;
4387 case SPEED_100 + DUPLEX_FULL:
4388 adapter->hw.forced_speed_duplex = e1000_100_full;
4389 break;
4390 case SPEED_1000 + DUPLEX_FULL:
4391 adapter->hw.autoneg = 1;
4392 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4393 break;
4394 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4395 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004396 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 return -EINVAL;
4398 }
4399 return 0;
4400}
4401
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004402#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004403/* Save/restore 16 or 64 dwords of PCI config space depending on which
4404 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004405 */
4406#define PCIE_CONFIG_SPACE_LEN 256
4407#define PCI_CONFIG_SPACE_LEN 64
4408static int
4409e1000_pci_save_state(struct e1000_adapter *adapter)
4410{
4411 struct pci_dev *dev = adapter->pdev;
4412 int size;
4413 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004414
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004415 if (adapter->hw.mac_type >= e1000_82571)
4416 size = PCIE_CONFIG_SPACE_LEN;
4417 else
4418 size = PCI_CONFIG_SPACE_LEN;
4419
4420 WARN_ON(adapter->config_space != NULL);
4421
4422 adapter->config_space = kmalloc(size, GFP_KERNEL);
4423 if (!adapter->config_space) {
4424 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4425 return -ENOMEM;
4426 }
4427 for (i = 0; i < (size / 4); i++)
4428 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4429 return 0;
4430}
4431
4432static void
4433e1000_pci_restore_state(struct e1000_adapter *adapter)
4434{
4435 struct pci_dev *dev = adapter->pdev;
4436 int size;
4437 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004438
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004439 if (adapter->config_space == NULL)
4440 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004441
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004442 if (adapter->hw.mac_type >= e1000_82571)
4443 size = PCIE_CONFIG_SPACE_LEN;
4444 else
4445 size = PCI_CONFIG_SPACE_LEN;
4446 for (i = 0; i < (size / 4); i++)
4447 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4448 kfree(adapter->config_space);
4449 adapter->config_space = NULL;
4450 return;
4451}
4452#endif /* CONFIG_PM */
4453
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004455e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456{
4457 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004458 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004459 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 uint32_t wufc = adapter->wol;
Jeff Kirsher240b1712006-01-12 16:51:28 -08004461 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462
4463 netif_device_detach(netdev);
4464
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004465 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466 e1000_down(adapter);
4467
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004468#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004469 /* Implement our own version of pci_save_state(pdev) because pci-
4470 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004471 retval = e1000_pci_save_state(adapter);
4472 if (retval)
4473 return retval;
4474#endif
4475
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004477 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 wufc &= ~E1000_WUFC_LNKC;
4479
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004480 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 e1000_setup_rctl(adapter);
4482 e1000_set_multi(netdev);
4483
4484 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004485 if (adapter->wol & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4487 rctl |= E1000_RCTL_MPE;
4488 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4489 }
4490
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004491 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4493 /* advertise wake from D3Cold */
4494 #define E1000_CTRL_ADVD3WUC 0x00100000
4495 /* phy power management enable */
4496 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4497 ctrl |= E1000_CTRL_ADVD3WUC |
4498 E1000_CTRL_EN_PHY_PWR_MGMT;
4499 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4500 }
4501
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004502 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4504 /* keep the laser running in D3 */
4505 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4506 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4507 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4508 }
4509
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004510 /* Allow time for pending master requests to run */
4511 e1000_disable_pciex_master(&adapter->hw);
4512
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4514 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004515 pci_enable_wake(pdev, PCI_D3hot, 1);
4516 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 } else {
4518 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4519 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07004520 pci_enable_wake(pdev, PCI_D3hot, 0);
4521 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522 }
4523
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004524 if (adapter->hw.mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 adapter->hw.media_type == e1000_media_type_copper) {
4526 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004527 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 manc |= E1000_MANC_ARP_EN;
4529 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004530 pci_enable_wake(pdev, PCI_D3hot, 1);
4531 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532 }
4533 }
4534
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004535 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4536 * would have already happened in close and is redundant. */
4537 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004538
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004540
Auke Kokd0e027d2006-04-14 19:04:40 -07004541 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542
4543 return 0;
4544}
4545
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004546#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547static int
4548e1000_resume(struct pci_dev *pdev)
4549{
4550 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004551 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004552 uint32_t manc, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553
Auke Kokd0e027d2006-04-14 19:04:40 -07004554 pci_set_power_state(pdev, PCI_D0);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004555 e1000_pci_restore_state(adapter);
Malli Chilakala2b028932005-06-17 17:46:06 -07004556 ret_val = pci_enable_device(pdev);
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004557 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558
Auke Kokd0e027d2006-04-14 19:04:40 -07004559 pci_enable_wake(pdev, PCI_D3hot, 0);
4560 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561
4562 e1000_reset(adapter);
4563 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4564
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004565 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 e1000_up(adapter);
4567
4568 netif_device_attach(netdev);
4569
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004570 if (adapter->hw.mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 adapter->hw.media_type == e1000_media_type_copper) {
4572 manc = E1000_READ_REG(&adapter->hw, MANC);
4573 manc &= ~(E1000_MANC_ARP_EN);
4574 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4575 }
4576
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004577 /* If the controller is 82573 and f/w is AMT, do not set
4578 * DRV_LOAD until the interface is up. For all other cases,
4579 * let the f/w know that the h/w is now under the control
4580 * of the driver. */
4581 if (adapter->hw.mac_type != e1000_82573 ||
4582 !e1000_check_mng_mode(&adapter->hw))
4583 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004584
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 return 0;
4586}
4587#endif
Auke Kokc653e632006-05-23 13:35:57 -07004588
4589static void e1000_shutdown(struct pci_dev *pdev)
4590{
4591 e1000_suspend(pdev, PMSG_SUSPEND);
4592}
4593
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594#ifdef CONFIG_NET_POLL_CONTROLLER
4595/*
4596 * Polling 'interrupt' - used by things like netconsole to send skbs
4597 * without having to re-enable interrupts. It's not called while
4598 * the interrupt routine is executing.
4599 */
4600static void
Malli Chilakala26483452005-04-28 19:44:46 -07004601e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004603 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604 disable_irq(adapter->pdev->irq);
4605 e1000_intr(adapter->pdev->irq, netdev, NULL);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004606 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004607#ifndef CONFIG_E1000_NAPI
4608 adapter->clean_rx(adapter, adapter->rx_ring);
4609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 enable_irq(adapter->pdev->irq);
4611}
4612#endif
4613
Auke Kok90267292006-06-08 09:30:24 -07004614/**
4615 * e1000_io_error_detected - called when PCI error is detected
4616 * @pdev: Pointer to PCI device
4617 * @state: The current pci conneection state
4618 *
4619 * This function is called after a PCI bus error affecting
4620 * this device has been detected.
4621 */
4622static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4623{
4624 struct net_device *netdev = pci_get_drvdata(pdev);
4625 struct e1000_adapter *adapter = netdev->priv;
4626
4627 netif_device_detach(netdev);
4628
4629 if (netif_running(netdev))
4630 e1000_down(adapter);
4631
4632 /* Request a slot slot reset. */
4633 return PCI_ERS_RESULT_NEED_RESET;
4634}
4635
4636/**
4637 * e1000_io_slot_reset - called after the pci bus has been reset.
4638 * @pdev: Pointer to PCI device
4639 *
4640 * Restart the card from scratch, as if from a cold-boot. Implementation
4641 * resembles the first-half of the e1000_resume routine.
4642 */
4643static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4644{
4645 struct net_device *netdev = pci_get_drvdata(pdev);
4646 struct e1000_adapter *adapter = netdev->priv;
4647
4648 if (pci_enable_device(pdev)) {
4649 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4650 return PCI_ERS_RESULT_DISCONNECT;
4651 }
4652 pci_set_master(pdev);
4653
4654 pci_enable_wake(pdev, 3, 0);
4655 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
4656
4657 /* Perform card reset only on one instance of the card */
4658 if (PCI_FUNC (pdev->devfn) != 0)
4659 return PCI_ERS_RESULT_RECOVERED;
4660
4661 e1000_reset(adapter);
4662 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4663
4664 return PCI_ERS_RESULT_RECOVERED;
4665}
4666
4667/**
4668 * e1000_io_resume - called when traffic can start flowing again.
4669 * @pdev: Pointer to PCI device
4670 *
4671 * This callback is called when the error recovery driver tells us that
4672 * its OK to resume normal operation. Implementation resembles the
4673 * second-half of the e1000_resume routine.
4674 */
4675static void e1000_io_resume(struct pci_dev *pdev)
4676{
4677 struct net_device *netdev = pci_get_drvdata(pdev);
4678 struct e1000_adapter *adapter = netdev->priv;
4679 uint32_t manc, swsm;
4680
4681 if (netif_running(netdev)) {
4682 if (e1000_up(adapter)) {
4683 printk("e1000: can't bring device back up after reset\n");
4684 return;
4685 }
4686 }
4687
4688 netif_device_attach(netdev);
4689
4690 if (adapter->hw.mac_type >= e1000_82540 &&
4691 adapter->hw.media_type == e1000_media_type_copper) {
4692 manc = E1000_READ_REG(&adapter->hw, MANC);
4693 manc &= ~(E1000_MANC_ARP_EN);
4694 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4695 }
4696
4697 switch (adapter->hw.mac_type) {
4698 case e1000_82573:
4699 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4700 E1000_WRITE_REG(&adapter->hw, SWSM,
4701 swsm | E1000_SWSM_DRV_LOAD);
4702 break;
4703 default:
4704 break;
4705 }
4706
4707 if (netif_running(netdev))
4708 mod_timer(&adapter->watchdog_timer, jiffies);
4709}
4710
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711/* e1000_main.c */