blob: fe22ae8f0a3da7f9bd9e74df5b3fec1116fe3a81 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include "e1000.h"
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031char e1000_driver_name[] = "e1000";
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010032static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#ifndef CONFIG_E1000_NAPI
34#define DRIVERNAPI
35#else
36#define DRIVERNAPI "-NAPI"
37#endif
Auke Kokff1e55b072006-10-24 14:46:09 -070038#define DRV_VERSION "7.2.9-k4"DRIVERNAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -070039char e1000_driver_version[] = DRV_VERSION;
Auke Kok3d41e302006-04-14 19:05:31 -070040static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/* e1000_pci_tbl - PCI Device ID Table
43 *
44 * Last entry must be all 0s
45 *
46 * Macro expands to...
47 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
48 */
49static struct pci_device_id e1000_pci_tbl[] = {
50 INTEL_E1000_ETHERNET_DEVICE(0x1000),
51 INTEL_E1000_ETHERNET_DEVICE(0x1001),
52 INTEL_E1000_ETHERNET_DEVICE(0x1004),
53 INTEL_E1000_ETHERNET_DEVICE(0x1008),
54 INTEL_E1000_ETHERNET_DEVICE(0x1009),
55 INTEL_E1000_ETHERNET_DEVICE(0x100C),
56 INTEL_E1000_ETHERNET_DEVICE(0x100D),
57 INTEL_E1000_ETHERNET_DEVICE(0x100E),
58 INTEL_E1000_ETHERNET_DEVICE(0x100F),
59 INTEL_E1000_ETHERNET_DEVICE(0x1010),
60 INTEL_E1000_ETHERNET_DEVICE(0x1011),
61 INTEL_E1000_ETHERNET_DEVICE(0x1012),
62 INTEL_E1000_ETHERNET_DEVICE(0x1013),
63 INTEL_E1000_ETHERNET_DEVICE(0x1014),
64 INTEL_E1000_ETHERNET_DEVICE(0x1015),
65 INTEL_E1000_ETHERNET_DEVICE(0x1016),
66 INTEL_E1000_ETHERNET_DEVICE(0x1017),
67 INTEL_E1000_ETHERNET_DEVICE(0x1018),
68 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -070069 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 INTEL_E1000_ETHERNET_DEVICE(0x101D),
71 INTEL_E1000_ETHERNET_DEVICE(0x101E),
72 INTEL_E1000_ETHERNET_DEVICE(0x1026),
73 INTEL_E1000_ETHERNET_DEVICE(0x1027),
74 INTEL_E1000_ETHERNET_DEVICE(0x1028),
Auke Kokae2c3862006-06-27 09:08:30 -070075 INTEL_E1000_ETHERNET_DEVICE(0x1049),
76 INTEL_E1000_ETHERNET_DEVICE(0x104A),
77 INTEL_E1000_ETHERNET_DEVICE(0x104B),
78 INTEL_E1000_ETHERNET_DEVICE(0x104C),
79 INTEL_E1000_ETHERNET_DEVICE(0x104D),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040080 INTEL_E1000_ETHERNET_DEVICE(0x105E),
81 INTEL_E1000_ETHERNET_DEVICE(0x105F),
82 INTEL_E1000_ETHERNET_DEVICE(0x1060),
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 INTEL_E1000_ETHERNET_DEVICE(0x1075),
84 INTEL_E1000_ETHERNET_DEVICE(0x1076),
85 INTEL_E1000_ETHERNET_DEVICE(0x1077),
86 INTEL_E1000_ETHERNET_DEVICE(0x1078),
87 INTEL_E1000_ETHERNET_DEVICE(0x1079),
88 INTEL_E1000_ETHERNET_DEVICE(0x107A),
89 INTEL_E1000_ETHERNET_DEVICE(0x107B),
90 INTEL_E1000_ETHERNET_DEVICE(0x107C),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040091 INTEL_E1000_ETHERNET_DEVICE(0x107D),
92 INTEL_E1000_ETHERNET_DEVICE(0x107E),
93 INTEL_E1000_ETHERNET_DEVICE(0x107F),
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Malli Chilakala26483452005-04-28 19:44:46 -070095 INTEL_E1000_ETHERNET_DEVICE(0x108B),
96 INTEL_E1000_ETHERNET_DEVICE(0x108C),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -080097 INTEL_E1000_ETHERNET_DEVICE(0x1096),
98 INTEL_E1000_ETHERNET_DEVICE(0x1098),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080099 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400100 INTEL_E1000_ETHERNET_DEVICE(0x109A),
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700101 INTEL_E1000_ETHERNET_DEVICE(0x10A4),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800102 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800103 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
Auke Kokae2c3862006-06-27 09:08:30 -0700104 INTEL_E1000_ETHERNET_DEVICE(0x10BA),
105 INTEL_E1000_ETHERNET_DEVICE(0x10BB),
Auke Kokfc2307d2006-11-01 08:47:56 -0800106 INTEL_E1000_ETHERNET_DEVICE(0x10BC),
107 INTEL_E1000_ETHERNET_DEVICE(0x10C4),
108 INTEL_E1000_ETHERNET_DEVICE(0x10C5),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 /* required last entry */
110 {0,}
111};
112
113MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
114
Nicholas Nunley35574762006-09-27 12:53:34 -0700115int e1000_up(struct e1000_adapter *adapter);
116void e1000_down(struct e1000_adapter *adapter);
117void e1000_reinit_locked(struct e1000_adapter *adapter);
118void e1000_reset(struct e1000_adapter *adapter);
119int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
120int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
121int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
122void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
123void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100124static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700125 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100126static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700127 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100128static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700129 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100130static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700131 struct e1000_rx_ring *rx_ring);
132void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134static int e1000_init_module(void);
135static void e1000_exit_module(void);
136static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
137static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400138static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139static int e1000_sw_init(struct e1000_adapter *adapter);
140static int e1000_open(struct net_device *netdev);
141static int e1000_close(struct net_device *netdev);
142static void e1000_configure_tx(struct e1000_adapter *adapter);
143static void e1000_configure_rx(struct e1000_adapter *adapter);
144static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400145static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
146static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
147static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
148 struct e1000_tx_ring *tx_ring);
149static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
150 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151static void e1000_set_multi(struct net_device *netdev);
152static void e1000_update_phy_info(unsigned long data);
153static void e1000_watchdog(unsigned long data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static void e1000_82547_tx_fifo_stall(unsigned long data);
155static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
156static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
157static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
158static int e1000_set_mac(struct net_device *netdev, void *p);
David Howells7d12e782006-10-05 14:55:46 +0100159static irqreturn_t e1000_intr(int irq, void *data);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400160static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
161 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400163static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400165 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700167static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400168 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700169 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400171static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
172 struct e1000_rx_ring *rx_ring);
173static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
174 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400176static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800177 struct e1000_rx_ring *rx_ring,
178 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400179static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800180 struct e1000_rx_ring *rx_ring,
181 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
183static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
184 int cmd);
Nicholas Nunley35574762006-09-27 12:53:34 -0700185void e1000_set_ethtool_ops(struct net_device *netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
187static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
188static void e1000_tx_timeout(struct net_device *dev);
Jeff Kirsher87041632006-03-02 18:21:24 -0800189static void e1000_reset_task(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700191static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
192 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
195static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
196static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
197static void e1000_restore_vlan(struct e1000_adapter *adapter);
198
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700199static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Auke Kok6fdfef12006-06-27 09:06:36 -0700200#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201static int e1000_resume(struct pci_dev *pdev);
202#endif
Auke Kokc653e632006-05-23 13:35:57 -0700203static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205#ifdef CONFIG_NET_POLL_CONTROLLER
206/* for netdump / net console */
207static void e1000_netpoll (struct net_device *netdev);
208#endif
209
Nicholas Nunley35574762006-09-27 12:53:34 -0700210extern void e1000_check_options(struct e1000_adapter *adapter);
211
Auke Kok90267292006-06-08 09:30:24 -0700212static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
213 pci_channel_state_t state);
214static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
215static void e1000_io_resume(struct pci_dev *pdev);
216
217static struct pci_error_handlers e1000_err_handler = {
218 .error_detected = e1000_io_error_detected,
219 .slot_reset = e1000_io_slot_reset,
220 .resume = e1000_io_resume,
221};
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223static struct pci_driver e1000_driver = {
224 .name = e1000_driver_name,
225 .id_table = e1000_pci_tbl,
226 .probe = e1000_probe,
227 .remove = __devexit_p(e1000_remove),
Auke Kokc4e24f02006-09-27 12:53:19 -0700228#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 /* Power Managment Hooks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 .suspend = e1000_suspend,
Auke Kokc653e632006-05-23 13:35:57 -0700231 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#endif
Auke Kok90267292006-06-08 09:30:24 -0700233 .shutdown = e1000_shutdown,
234 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
237MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
238MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
239MODULE_LICENSE("GPL");
240MODULE_VERSION(DRV_VERSION);
241
242static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
243module_param(debug, int, 0);
244MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
245
246/**
247 * e1000_init_module - Driver Registration Routine
248 *
249 * e1000_init_module is the first routine called when the driver is
250 * loaded. All it does is register with the PCI subsystem.
251 **/
252
253static int __init
254e1000_init_module(void)
255{
256 int ret;
257 printk(KERN_INFO "%s - version %s\n",
258 e1000_driver_string, e1000_driver_version);
259
260 printk(KERN_INFO "%s\n", e1000_copyright);
261
Jeff Garzik29917622006-08-19 17:48:59 -0400262 ret = pci_register_driver(&e1000_driver);
Tony Luck8b378de2005-07-28 01:07:38 -0700263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return ret;
265}
266
267module_init(e1000_init_module);
268
269/**
270 * e1000_exit_module - Driver Exit Cleanup Routine
271 *
272 * e1000_exit_module is called just before the driver is removed
273 * from memory.
274 **/
275
276static void __exit
277e1000_exit_module(void)
278{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 pci_unregister_driver(&e1000_driver);
280}
281
282module_exit(e1000_exit_module);
283
Auke Kok2db10a02006-06-27 09:06:28 -0700284static int e1000_request_irq(struct e1000_adapter *adapter)
285{
286 struct net_device *netdev = adapter->netdev;
287 int flags, err = 0;
288
Jeff Garzikc0bc8722006-07-05 14:32:39 -0400289 flags = IRQF_SHARED;
Auke Kok2db10a02006-06-27 09:06:28 -0700290#ifdef CONFIG_PCI_MSI
291 if (adapter->hw.mac_type > e1000_82547_rev_2) {
292 adapter->have_msi = TRUE;
293 if ((err = pci_enable_msi(adapter->pdev))) {
294 DPRINTK(PROBE, ERR,
295 "Unable to allocate MSI interrupt Error: %d\n", err);
296 adapter->have_msi = FALSE;
297 }
298 }
299 if (adapter->have_msi)
Andrew Morton61ef5c02006-07-06 23:58:19 -0700300 flags &= ~IRQF_SHARED;
Auke Kok2db10a02006-06-27 09:06:28 -0700301#endif
302 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
303 netdev->name, netdev)))
304 DPRINTK(PROBE, ERR,
305 "Unable to allocate interrupt Error: %d\n", err);
306
307 return err;
308}
309
310static void e1000_free_irq(struct e1000_adapter *adapter)
311{
312 struct net_device *netdev = adapter->netdev;
313
314 free_irq(adapter->pdev->irq, netdev);
315
316#ifdef CONFIG_PCI_MSI
317 if (adapter->have_msi)
318 pci_disable_msi(adapter->pdev);
319#endif
320}
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322/**
323 * e1000_irq_disable - Mask off interrupt generation on the NIC
324 * @adapter: board private structure
325 **/
326
Auke Koke619d522006-04-14 19:04:52 -0700327static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328e1000_irq_disable(struct e1000_adapter *adapter)
329{
330 atomic_inc(&adapter->irq_sem);
331 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
332 E1000_WRITE_FLUSH(&adapter->hw);
333 synchronize_irq(adapter->pdev->irq);
334}
335
336/**
337 * e1000_irq_enable - Enable default interrupt generation settings
338 * @adapter: board private structure
339 **/
340
Auke Koke619d522006-04-14 19:04:52 -0700341static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342e1000_irq_enable(struct e1000_adapter *adapter)
343{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800344 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
346 E1000_WRITE_FLUSH(&adapter->hw);
347 }
348}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100349
350static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700351e1000_update_mng_vlan(struct e1000_adapter *adapter)
352{
353 struct net_device *netdev = adapter->netdev;
354 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
355 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800356 if (adapter->vlgrp) {
357 if (!adapter->vlgrp->vlan_devices[vid]) {
358 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700359 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
360 e1000_vlan_rx_add_vid(netdev, vid);
361 adapter->mng_vlan_id = vid;
362 } else
363 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800364
365 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
366 (vid != old_vid) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700367 !adapter->vlgrp->vlan_devices[old_vid])
368 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800369 } else
370 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700371 }
372}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800373
374/**
375 * e1000_release_hw_control - release control of the h/w to f/w
376 * @adapter: address of board private structure
377 *
378 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
379 * For ASF and Pass Through versions of f/w this means that the
380 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800381 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700382 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800383 **/
384
Auke Koke619d522006-04-14 19:04:52 -0700385static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800386e1000_release_hw_control(struct e1000_adapter *adapter)
387{
388 uint32_t ctrl_ext;
389 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700390 uint32_t extcnf;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800391
392 /* Let firmware taken over control of h/w */
393 switch (adapter->hw.mac_type) {
394 case e1000_82571:
395 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700396 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800397 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
398 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
399 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
400 break;
401 case e1000_82573:
402 swsm = E1000_READ_REG(&adapter->hw, SWSM);
403 E1000_WRITE_REG(&adapter->hw, SWSM,
404 swsm & ~E1000_SWSM_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700405 case e1000_ich8lan:
406 extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
407 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
408 extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
409 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800410 default:
411 break;
412 }
413}
414
415/**
416 * e1000_get_hw_control - get control of the h/w from f/w
417 * @adapter: address of board private structure
418 *
419 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700420 * For ASF and Pass Through versions of f/w this means that
421 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800422 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700423 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800424 **/
425
Auke Koke619d522006-04-14 19:04:52 -0700426static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800427e1000_get_hw_control(struct e1000_adapter *adapter)
428{
429 uint32_t ctrl_ext;
430 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700431 uint32_t extcnf;
Auke Kok90fb5132006-11-01 08:47:30 -0800432
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800433 /* Let firmware know the driver has taken over */
434 switch (adapter->hw.mac_type) {
435 case e1000_82571:
436 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700437 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800438 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
439 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
440 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
441 break;
442 case e1000_82573:
443 swsm = E1000_READ_REG(&adapter->hw, SWSM);
444 E1000_WRITE_REG(&adapter->hw, SWSM,
445 swsm | E1000_SWSM_DRV_LOAD);
446 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700447 case e1000_ich8lan:
448 extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
449 E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
450 extcnf | E1000_EXTCNF_CTRL_SWFLAG);
451 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800452 default:
453 break;
454 }
455}
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457int
458e1000_up(struct e1000_adapter *adapter)
459{
460 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700461 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 /* hardware has been reset, we need to reload some things */
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 e1000_set_multi(netdev);
466
467 e1000_restore_vlan(adapter);
468
469 e1000_configure_tx(adapter);
470 e1000_setup_rctl(adapter);
471 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800472 /* call E1000_DESC_UNUSED which always leaves
473 * at least 1 descriptor unused to make sure
474 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800475 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800476 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800477 adapter->alloc_rx_buf(adapter, ring,
478 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800481 adapter->tx_queue_len = netdev->tx_queue_len;
482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#ifdef CONFIG_E1000_NAPI
484 netif_poll_enable(netdev);
485#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700486 e1000_irq_enable(adapter);
487
Auke Kok1314bbf2006-09-27 12:54:02 -0700488 clear_bit(__E1000_DOWN, &adapter->flags);
489
490 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 return 0;
492}
493
Auke Kok79f05bf2006-06-27 09:06:32 -0700494/**
495 * e1000_power_up_phy - restore link in case the phy was powered down
496 * @adapter: address of board private structure
497 *
498 * The phy may be powered down to save power and turn off link when the
499 * driver is unloaded and wake on lan is not enabled (among others)
500 * *** this routine MUST be followed by a call to e1000_reset ***
501 *
502 **/
503
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700504void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700505{
506 uint16_t mii_reg = 0;
507
508 /* Just clear the power down bit to wake the phy back up */
509 if (adapter->hw.media_type == e1000_media_type_copper) {
510 /* according to the manual, the phy will retain its
511 * settings across a power-down/up cycle */
512 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
513 mii_reg &= ~MII_CR_POWER_DOWN;
514 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
515 }
516}
517
518static void e1000_power_down_phy(struct e1000_adapter *adapter)
519{
Bruce Allan61c25052006-09-27 12:53:54 -0700520 /* Power down the PHY so no link is implied when interface is down *
521 * The PHY cannot be powered down if any of the following is TRUE *
Auke Kok79f05bf2006-06-27 09:06:32 -0700522 * (a) WoL is enabled
523 * (b) AMT is active
524 * (c) SoL/IDER session is active */
525 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700526 adapter->hw.media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700527 uint16_t mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700528
529 switch (adapter->hw.mac_type) {
530 case e1000_82540:
531 case e1000_82545:
532 case e1000_82545_rev_3:
533 case e1000_82546:
534 case e1000_82546_rev_3:
535 case e1000_82541:
536 case e1000_82541_rev_2:
537 case e1000_82547:
538 case e1000_82547_rev_2:
539 if (E1000_READ_REG(&adapter->hw, MANC) &
540 E1000_MANC_SMBUS_EN)
541 goto out;
542 break;
543 case e1000_82571:
544 case e1000_82572:
545 case e1000_82573:
546 case e1000_80003es2lan:
547 case e1000_ich8lan:
548 if (e1000_check_mng_mode(&adapter->hw) ||
549 e1000_check_phy_reset_block(&adapter->hw))
550 goto out;
551 break;
552 default:
553 goto out;
554 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700555 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
556 mii_reg |= MII_CR_POWER_DOWN;
557 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
558 mdelay(1);
559 }
Bruce Allan61c25052006-09-27 12:53:54 -0700560out:
561 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700562}
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564void
565e1000_down(struct e1000_adapter *adapter)
566{
567 struct net_device *netdev = adapter->netdev;
568
Auke Kok1314bbf2006-09-27 12:54:02 -0700569 /* signal that we're down so the interrupt handler does not
570 * reschedule our watchdog timer */
571 set_bit(__E1000_DOWN, &adapter->flags);
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 del_timer_sync(&adapter->tx_fifo_stall_timer);
576 del_timer_sync(&adapter->watchdog_timer);
577 del_timer_sync(&adapter->phy_info_timer);
578
579#ifdef CONFIG_E1000_NAPI
580 netif_poll_disable(netdev);
581#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800582 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 adapter->link_speed = 0;
584 adapter->link_duplex = 0;
585 netif_carrier_off(netdev);
586 netif_stop_queue(netdev);
587
588 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400589 e1000_clean_all_tx_rings(adapter);
590 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593void
Auke Kok2db10a02006-06-27 09:06:28 -0700594e1000_reinit_locked(struct e1000_adapter *adapter)
595{
596 WARN_ON(in_interrupt());
597 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
598 msleep(1);
599 e1000_down(adapter);
600 e1000_up(adapter);
601 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
603
604void
605e1000_reset(struct e1000_adapter *adapter)
606{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700607 uint32_t pba, manc;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700608 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 /* Repartition Pba for greater than 9k mtu
611 * To take effect CTRL.RST is required.
612 */
613
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700614 switch (adapter->hw.mac_type) {
615 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700616 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700617 pba = E1000_PBA_30K;
618 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400619 case e1000_82571:
620 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800621 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400622 pba = E1000_PBA_38K;
623 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700624 case e1000_82573:
625 pba = E1000_PBA_12K;
626 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700627 case e1000_ich8lan:
628 pba = E1000_PBA_8K;
629 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700630 default:
631 pba = E1000_PBA_48K;
632 break;
633 }
634
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800635 if ((adapter->hw.mac_type != e1000_82573) &&
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800636 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700637 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700638
639
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800640 if (adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 adapter->tx_fifo_head = 0;
642 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
643 adapter->tx_fifo_size =
644 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
645 atomic_set(&adapter->tx_fifo_stall, 0);
646 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 E1000_WRITE_REG(&adapter->hw, PBA, pba);
649
650 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800651 /* Set the FC high water mark to 90% of the FIFO size.
652 * Required to clear last 3 LSB */
653 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700654 /* We can't use 90% on small FIFOs because the remainder
655 * would be less than 1 full frame. In this case, we size
656 * it to allow at least a full frame above the high water
657 * mark. */
658 if (pba < E1000_PBA_16K)
659 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800660
661 adapter->hw.fc_high_water = fc_high_water_mark;
662 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800663 if (adapter->hw.mac_type == e1000_80003es2lan)
664 adapter->hw.fc_pause_time = 0xFFFF;
665 else
666 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 adapter->hw.fc_send_xon = 1;
668 adapter->hw.fc = adapter->hw.original_fc;
669
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700670 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800672 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700674
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800675 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700677 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
679 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
680
681 e1000_reset_adaptive(&adapter->hw);
682 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700683
684 if (!adapter->smart_power_down &&
685 (adapter->hw.mac_type == e1000_82571 ||
686 adapter->hw.mac_type == e1000_82572)) {
687 uint16_t phy_data = 0;
688 /* speed up time to link by disabling smart power down, ignore
689 * the return value of this function because there is nothing
690 * different we would do if it failed */
691 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
692 &phy_data);
693 phy_data &= ~IGP02E1000_PM_SPD;
694 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
695 phy_data);
696 }
697
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -0700698 if ((adapter->en_mng_pt) &&
699 (adapter->hw.mac_type >= e1000_82540) &&
700 (adapter->hw.mac_type < e1000_82571) &&
701 (adapter->hw.media_type == e1000_media_type_copper)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700702 manc = E1000_READ_REG(&adapter->hw, MANC);
703 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
704 E1000_WRITE_REG(&adapter->hw, MANC, manc);
705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706}
707
708/**
709 * e1000_probe - Device Initialization Routine
710 * @pdev: PCI device information struct
711 * @ent: entry in e1000_pci_tbl
712 *
713 * Returns 0 on success, negative on failure
714 *
715 * e1000_probe initializes an adapter identified by a pci_dev structure.
716 * The OS initialization, configuring of the adapter private structure,
717 * and a hardware reset occur.
718 **/
719
720static int __devinit
721e1000_probe(struct pci_dev *pdev,
722 const struct pci_device_id *ent)
723{
724 struct net_device *netdev;
725 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700726 unsigned long mmio_start, mmio_len;
Auke Kokcd94dd02006-06-27 09:08:22 -0700727 unsigned long flash_start, flash_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700730 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700731 int i, err, pci_using_dac;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700732 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800734 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 return err;
736
Auke Kokcd94dd02006-06-27 09:08:22 -0700737 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
738 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 pci_using_dac = 1;
740 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700741 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
742 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700744 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 }
746 pci_using_dac = 0;
747 }
748
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800749 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700750 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 pci_set_master(pdev);
753
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700754 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700756 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 SET_MODULE_OWNER(netdev);
760 SET_NETDEV_DEV(netdev, &pdev->dev);
761
762 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700763 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 adapter->netdev = netdev;
765 adapter->pdev = pdev;
766 adapter->hw.back = adapter;
767 adapter->msg_enable = (1 << debug) - 1;
768
769 mmio_start = pci_resource_start(pdev, BAR_0);
770 mmio_len = pci_resource_len(pdev, BAR_0);
771
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700772 err = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700774 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800777 for (i = BAR_1; i <= BAR_5; i++) {
778 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800780 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 adapter->hw.io_base = pci_resource_start(pdev, i);
782 break;
783 }
784 }
785
786 netdev->open = &e1000_open;
787 netdev->stop = &e1000_close;
788 netdev->hard_start_xmit = &e1000_xmit_frame;
789 netdev->get_stats = &e1000_get_stats;
790 netdev->set_multicast_list = &e1000_set_multi;
791 netdev->set_mac_address = &e1000_set_mac;
792 netdev->change_mtu = &e1000_change_mtu;
793 netdev->do_ioctl = &e1000_ioctl;
794 e1000_set_ethtool_ops(netdev);
795 netdev->tx_timeout = &e1000_tx_timeout;
796 netdev->watchdog_timeo = 5 * HZ;
797#ifdef CONFIG_E1000_NAPI
798 netdev->poll = &e1000_clean;
799 netdev->weight = 64;
800#endif
801 netdev->vlan_rx_register = e1000_vlan_rx_register;
802 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
803 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
804#ifdef CONFIG_NET_POLL_CONTROLLER
805 netdev->poll_controller = e1000_netpoll;
806#endif
Auke Kok0eb5a342006-09-27 12:53:17 -0700807 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 netdev->mem_start = mmio_start;
810 netdev->mem_end = mmio_start + mmio_len;
811 netdev->base_addr = adapter->hw.io_base;
812
813 adapter->bd_number = cards_found;
814
815 /* setup the private structure */
816
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800817 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 goto err_sw_init;
819
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700820 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -0700821 /* Flash BAR mapping must happen after e1000_sw_init
822 * because it depends on mac_type */
823 if ((adapter->hw.mac_type == e1000_ich8lan) &&
824 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
825 flash_start = pci_resource_start(pdev, 1);
826 flash_len = pci_resource_len(pdev, 1);
827 adapter->hw.flash_address = ioremap(flash_start, flash_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700828 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -0700829 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -0700830 }
831
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700832 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700833 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
834
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800835 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 netdev->features = NETIF_F_SG |
837 NETIF_F_HW_CSUM |
838 NETIF_F_HW_VLAN_TX |
839 NETIF_F_HW_VLAN_RX |
840 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -0700841 if (adapter->hw.mac_type == e1000_ich8lan)
842 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
844
845#ifdef NETIF_F_TSO
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800846 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 (adapter->hw.mac_type != e1000_82547))
848 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700849
Auke Kok87ca4e52006-11-01 08:47:36 -0800850#ifdef NETIF_F_TSO6
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800851 if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -0800852 netdev->features |= NETIF_F_TSO6;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700853#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800855 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 netdev->features |= NETIF_F_HIGHDMA;
857
Auke Kok76c224b2006-05-23 13:36:06 -0700858 netdev->features |= NETIF_F_LLTX;
859
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700860 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
861
Auke Kokcd94dd02006-06-27 09:08:22 -0700862 /* initialize eeprom parameters */
863
864 if (e1000_init_eeprom_params(&adapter->hw)) {
865 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700866 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -0700867 }
868
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800869 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 e1000_reset_hw(&adapter->hw);
873
874 /* make sure the EEPROM is good */
875
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800876 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 goto err_eeprom;
879 }
880
881 /* copy the MAC address out of the EEPROM */
882
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800883 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
885 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400886 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800888 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 goto err_eeprom;
891 }
892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 e1000_get_bus_info(&adapter->hw);
894
895 init_timer(&adapter->tx_fifo_stall_timer);
896 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
897 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
898
899 init_timer(&adapter->watchdog_timer);
900 adapter->watchdog_timer.function = &e1000_watchdog;
901 adapter->watchdog_timer.data = (unsigned long) adapter;
902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 init_timer(&adapter->phy_info_timer);
904 adapter->phy_info_timer.function = &e1000_update_phy_info;
905 adapter->phy_info_timer.data = (unsigned long) adapter;
906
Jeff Kirsher87041632006-03-02 18:21:24 -0800907 INIT_WORK(&adapter->reset_task,
908 (void (*)(void *))e1000_reset_task, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 e1000_check_options(adapter);
911
912 /* Initial Wake on LAN setting
913 * If APM wake is enabled in the EEPROM,
914 * enable the ACPI Magic Packet filter
915 */
916
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800917 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 case e1000_82542_rev2_0:
919 case e1000_82542_rev2_1:
920 case e1000_82543:
921 break;
922 case e1000_82544:
923 e1000_read_eeprom(&adapter->hw,
924 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
925 eeprom_apme_mask = E1000_EEPROM_82544_APM;
926 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700927 case e1000_ich8lan:
928 e1000_read_eeprom(&adapter->hw,
929 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
930 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
931 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 case e1000_82546:
933 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500934 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800935 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800936 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 e1000_read_eeprom(&adapter->hw,
938 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
939 break;
940 }
941 /* Fall Through */
942 default:
943 e1000_read_eeprom(&adapter->hw,
944 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
945 break;
946 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800947 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700948 adapter->eeprom_wol |= E1000_WUFC_MAG;
949
950 /* now that we have the eeprom settings, apply the special cases
951 * where the eeprom may be wrong or the board simply won't support
952 * wake on lan on a particular port */
953 switch (pdev->device) {
954 case E1000_DEV_ID_82546GB_PCIE:
955 adapter->eeprom_wol = 0;
956 break;
957 case E1000_DEV_ID_82546EB_FIBER:
958 case E1000_DEV_ID_82546GB_FIBER:
959 case E1000_DEV_ID_82571EB_FIBER:
960 /* Wake events only supported on port A for dual fiber
961 * regardless of eeprom setting */
962 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
963 adapter->eeprom_wol = 0;
964 break;
965 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700966 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokfc2307d2006-11-01 08:47:56 -0800967 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700968 /* if quad port adapter, disable WoL on all but port A */
969 if (global_quad_port_a != 0)
970 adapter->eeprom_wol = 0;
971 else
972 adapter->quad_port_a = 1;
973 /* Reset for multiple quad port adapters */
974 if (++global_quad_port_a == 4)
975 global_quad_port_a = 0;
976 break;
977 }
978
979 /* initialize the wol settings based on the eeprom settings */
980 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -0800982 /* print bus type/speed/width info */
983 {
984 struct e1000_hw *hw = &adapter->hw;
985 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
986 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
987 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
988 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
989 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
990 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
991 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
992 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
993 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
994 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
995 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
996 "32-bit"));
997 }
998
999 for (i = 0; i < 6; i++)
1000 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
1001
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 /* reset the hardware with the new settings */
1003 e1000_reset(adapter);
1004
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001005 /* If the controller is 82573 and f/w is AMT, do not set
1006 * DRV_LOAD until the interface is up. For all other cases,
1007 * let the f/w know that the h/w is now under the control
1008 * of the driver. */
1009 if (adapter->hw.mac_type != e1000_82573 ||
1010 !e1000_check_mng_mode(&adapter->hw))
1011 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 strcpy(netdev->name, "eth%d");
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001014 if ((err = register_netdev(netdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 goto err_register;
1016
Auke Kok1314bbf2006-09-27 12:54:02 -07001017 /* tell the stack to leave us alone until e1000_open() is called */
1018 netif_carrier_off(netdev);
1019 netif_stop_queue(netdev);
1020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1022
1023 cards_found++;
1024 return 0;
1025
1026err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001027 e1000_release_hw_control(adapter);
1028err_eeprom:
1029 if (!e1000_check_phy_reset_block(&adapter->hw))
1030 e1000_phy_hw_reset(&adapter->hw);
1031
Auke Kokcd94dd02006-06-27 09:08:22 -07001032 if (adapter->hw.flash_address)
1033 iounmap(adapter->hw.flash_address);
1034err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001035#ifdef CONFIG_E1000_NAPI
1036 for (i = 0; i < adapter->num_rx_queues; i++)
1037 dev_put(&adapter->polling_netdev[i]);
1038#endif
1039
1040 kfree(adapter->tx_ring);
1041 kfree(adapter->rx_ring);
1042#ifdef CONFIG_E1000_NAPI
1043 kfree(adapter->polling_netdev);
1044#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 iounmap(adapter->hw.hw_addr);
1047err_ioremap:
1048 free_netdev(netdev);
1049err_alloc_etherdev:
1050 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001051err_pci_reg:
1052err_dma:
1053 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 return err;
1055}
1056
1057/**
1058 * e1000_remove - Device Removal Routine
1059 * @pdev: PCI device information struct
1060 *
1061 * e1000_remove is called by the PCI subsystem to alert the driver
1062 * that it should release a PCI device. The could be caused by a
1063 * Hot-Plug event, or because the driver is going to be removed from
1064 * memory.
1065 **/
1066
1067static void __devexit
1068e1000_remove(struct pci_dev *pdev)
1069{
1070 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001071 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001072 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001073#ifdef CONFIG_E1000_NAPI
1074 int i;
1075#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001077 flush_scheduled_work();
1078
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07001079 if (adapter->hw.mac_type >= e1000_82540 &&
1080 adapter->hw.mac_type < e1000_82571 &&
1081 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001083 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 manc |= E1000_MANC_ARP_EN;
1085 E1000_WRITE_REG(&adapter->hw, MANC, manc);
1086 }
1087 }
1088
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001089 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1090 * would have already happened in close and is redundant. */
1091 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001092
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001094#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001095 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001096 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001097#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001099 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001100 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001102 kfree(adapter->tx_ring);
1103 kfree(adapter->rx_ring);
1104#ifdef CONFIG_E1000_NAPI
1105 kfree(adapter->polling_netdev);
1106#endif
1107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001109 if (adapter->hw.flash_address)
1110 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 pci_release_regions(pdev);
1112
1113 free_netdev(netdev);
1114
1115 pci_disable_device(pdev);
1116}
1117
1118/**
1119 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1120 * @adapter: board private structure to initialize
1121 *
1122 * e1000_sw_init initializes the Adapter private data structure.
1123 * Fields are initialized based on PCI device information and
1124 * OS network device settings (MTU size).
1125 **/
1126
1127static int __devinit
1128e1000_sw_init(struct e1000_adapter *adapter)
1129{
1130 struct e1000_hw *hw = &adapter->hw;
1131 struct net_device *netdev = adapter->netdev;
1132 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001133#ifdef CONFIG_E1000_NAPI
1134 int i;
1135#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137 /* PCI config space info */
1138
1139 hw->vendor_id = pdev->vendor;
1140 hw->device_id = pdev->device;
1141 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1142 hw->subsystem_id = pdev->subsystem_device;
1143
1144 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1145
1146 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1147
Auke Kokeb0f8052006-07-14 16:14:48 -07001148 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001149 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 hw->max_frame_size = netdev->mtu +
1151 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1152 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1153
1154 /* identify the MAC */
1155
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001156 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1158 return -EIO;
1159 }
1160
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001161 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 default:
1163 break;
1164 case e1000_82541:
1165 case e1000_82547:
1166 case e1000_82541_rev_2:
1167 case e1000_82547_rev_2:
1168 hw->phy_init_script = 1;
1169 break;
1170 }
1171
1172 e1000_set_media_type(hw);
1173
1174 hw->wait_autoneg_complete = FALSE;
1175 hw->tbi_compatibility_en = TRUE;
1176 hw->adaptive_ifs = TRUE;
1177
1178 /* Copper options */
1179
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001180 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 hw->mdix = AUTO_ALL_MODES;
1182 hw->disable_polarity_correction = FALSE;
1183 hw->master_slave = E1000_MASTER_SLAVE;
1184 }
1185
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001186 adapter->num_tx_queues = 1;
1187 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001188
1189 if (e1000_alloc_queues(adapter)) {
1190 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1191 return -ENOMEM;
1192 }
1193
1194#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001195 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001196 adapter->polling_netdev[i].priv = adapter;
1197 adapter->polling_netdev[i].poll = &e1000_clean;
1198 adapter->polling_netdev[i].weight = 64;
1199 dev_hold(&adapter->polling_netdev[i]);
1200 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1201 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001202 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001203#endif
1204
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 atomic_set(&adapter->irq_sem, 1);
1206 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Auke Kok1314bbf2006-09-27 12:54:02 -07001208 set_bit(__E1000_DOWN, &adapter->flags);
1209
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 return 0;
1211}
1212
1213/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001214 * e1000_alloc_queues - Allocate memory for all rings
1215 * @adapter: board private structure to initialize
1216 *
1217 * We allocate one ring per queue at run-time since we don't know the
1218 * number of queues at compile-time. The polling_netdev array is
1219 * intended for Multiqueue, but should work fine with a single queue.
1220 **/
1221
1222static int __devinit
1223e1000_alloc_queues(struct e1000_adapter *adapter)
1224{
1225 int size;
1226
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001227 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001228 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1229 if (!adapter->tx_ring)
1230 return -ENOMEM;
1231 memset(adapter->tx_ring, 0, size);
1232
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001233 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001234 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1235 if (!adapter->rx_ring) {
1236 kfree(adapter->tx_ring);
1237 return -ENOMEM;
1238 }
1239 memset(adapter->rx_ring, 0, size);
1240
1241#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001242 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001243 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1244 if (!adapter->polling_netdev) {
1245 kfree(adapter->tx_ring);
1246 kfree(adapter->rx_ring);
1247 return -ENOMEM;
1248 }
1249 memset(adapter->polling_netdev, 0, size);
1250#endif
1251
1252 return E1000_SUCCESS;
1253}
1254
1255/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 * e1000_open - Called when a network interface is made active
1257 * @netdev: network interface device structure
1258 *
1259 * Returns 0 on success, negative value on failure
1260 *
1261 * The open entry point is called when a network interface is made
1262 * active by the system (IFF_UP). At this point all resources needed
1263 * for transmit and receive operations are allocated, the interrupt
1264 * handler is registered with the OS, the watchdog timer is started,
1265 * and the stack is notified that the interface is ready.
1266 **/
1267
1268static int
1269e1000_open(struct net_device *netdev)
1270{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001271 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 int err;
1273
Auke Kok2db10a02006-06-27 09:06:28 -07001274 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001275 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001276 return -EBUSY;
1277
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 /* allocate transmit descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001279 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 goto err_setup_tx;
1281
1282 /* allocate receive descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001283 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 goto err_setup_rx;
1285
Auke Kok2db10a02006-06-27 09:06:28 -07001286 err = e1000_request_irq(adapter);
1287 if (err)
Vasily Averin401a5522006-08-28 14:56:19 -07001288 goto err_req_irq;
Auke Kok2db10a02006-06-27 09:06:28 -07001289
Auke Kok79f05bf2006-06-27 09:06:32 -07001290 e1000_power_up_phy(adapter);
1291
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001292 if ((err = e1000_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001294 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001295 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001296 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1297 e1000_update_mng_vlan(adapter);
1298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001300 /* If AMT is enabled, let the firmware know that the network
1301 * interface is now open */
1302 if (adapter->hw.mac_type == e1000_82573 &&
1303 e1000_check_mng_mode(&adapter->hw))
1304 e1000_get_hw_control(adapter);
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 return E1000_SUCCESS;
1307
1308err_up:
Vasily Averin401a5522006-08-28 14:56:19 -07001309 e1000_power_down_phy(adapter);
1310 e1000_free_irq(adapter);
1311err_req_irq:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001312 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001314 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315err_setup_tx:
1316 e1000_reset(adapter);
1317
1318 return err;
1319}
1320
1321/**
1322 * e1000_close - Disables a network interface
1323 * @netdev: network interface device structure
1324 *
1325 * Returns 0, this is not allowed to fail
1326 *
1327 * The close entry point is called when an interface is de-activated
1328 * by the OS. The hardware is still under the drivers control, but
1329 * needs to be disabled. A global MAC reset is issued to stop the
1330 * hardware, and all transmit and receive resources are freed.
1331 **/
1332
1333static int
1334e1000_close(struct net_device *netdev)
1335{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001336 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Auke Kok2db10a02006-06-27 09:06:28 -07001338 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001340 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001341 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001343 e1000_free_all_tx_resources(adapter);
1344 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Bruce Allan46665602006-09-27 12:54:08 -07001346 /* kill manageability vlan ID if supported, but not if a vlan with
1347 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001348 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001349 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1350 !(adapter->vlgrp &&
1351 adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001352 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1353 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001354
1355 /* If AMT is enabled, let the firmware know that the network
1356 * interface is now closed */
1357 if (adapter->hw.mac_type == e1000_82573 &&
1358 e1000_check_mng_mode(&adapter->hw))
1359 e1000_release_hw_control(adapter);
1360
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 return 0;
1362}
1363
1364/**
1365 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1366 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001367 * @start: address of beginning of memory
1368 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 **/
Auke Koke619d522006-04-14 19:04:52 -07001370static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371e1000_check_64k_bound(struct e1000_adapter *adapter,
1372 void *start, unsigned long len)
1373{
1374 unsigned long begin = (unsigned long) start;
1375 unsigned long end = begin + len;
1376
Malli Chilakala26483452005-04-28 19:44:46 -07001377 /* First rev 82545 and 82546 need to not allow any memory
1378 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001380 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1382 }
1383
1384 return TRUE;
1385}
1386
1387/**
1388 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1389 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001390 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 *
1392 * Return 0 on success, negative on failure
1393 **/
1394
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001395static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001396e1000_setup_tx_resources(struct e1000_adapter *adapter,
1397 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 struct pci_dev *pdev = adapter->pdev;
1400 int size;
1401
1402 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001403 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001404 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001405 DPRINTK(PROBE, ERR,
1406 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 return -ENOMEM;
1408 }
1409 memset(txdr->buffer_info, 0, size);
1410
1411 /* round up to nearest 4K */
1412
1413 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1414 E1000_ROUNDUP(txdr->size, 4096);
1415
1416 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001417 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001420 DPRINTK(PROBE, ERR,
1421 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 return -ENOMEM;
1423 }
1424
Malli Chilakala26483452005-04-28 19:44:46 -07001425 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1427 void *olddesc = txdr->desc;
1428 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001429 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1430 "at %p\n", txdr->size, txdr->desc);
1431 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001433 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001434 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1436 goto setup_tx_desc_die;
1437 }
1438
1439 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1440 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001441 pci_free_consistent(pdev, txdr->size, txdr->desc,
1442 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1444 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001445 "Unable to allocate aligned memory "
1446 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 vfree(txdr->buffer_info);
1448 return -ENOMEM;
1449 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001450 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1452 }
1453 }
1454 memset(txdr->desc, 0, txdr->size);
1455
1456 txdr->next_to_use = 0;
1457 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001458 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
1460 return 0;
1461}
1462
1463/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001464 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1465 * (Descriptors) for all queues
1466 * @adapter: board private structure
1467 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001468 * Return 0 on success, negative on failure
1469 **/
1470
1471int
1472e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1473{
1474 int i, err = 0;
1475
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001476 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001477 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1478 if (err) {
1479 DPRINTK(PROBE, ERR,
1480 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001481 for (i-- ; i >= 0; i--)
1482 e1000_free_tx_resources(adapter,
1483 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001484 break;
1485 }
1486 }
1487
1488 return err;
1489}
1490
1491/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1493 * @adapter: board private structure
1494 *
1495 * Configure the Tx unit of the MAC after a reset.
1496 **/
1497
1498static void
1499e1000_configure_tx(struct e1000_adapter *adapter)
1500{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001501 uint64_t tdba;
1502 struct e1000_hw *hw = &adapter->hw;
1503 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001504 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506 /* Setup the HW Tx Head and Tail descriptor pointers */
1507
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001508 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001509 case 1:
1510 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001511 tdba = adapter->tx_ring[0].dma;
1512 tdlen = adapter->tx_ring[0].count *
1513 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001514 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001515 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1516 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001517 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001518 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001519 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1520 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001521 break;
1522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524 /* Set the default values for the Tx Inter Packet Gap timer */
1525
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001526 if (hw->media_type == e1000_media_type_fiber ||
1527 hw->media_type == e1000_media_type_internal_serdes)
1528 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1529 else
1530 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1531
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001532 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 case e1000_82542_rev2_0:
1534 case e1000_82542_rev2_1:
1535 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001536 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1537 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001539 case e1000_80003es2lan:
1540 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1541 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1542 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001544 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1545 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1546 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001548 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1549 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001550 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
1552 /* Set the Tx Interrupt Delay register */
1553
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001554 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1555 if (hw->mac_type >= e1000_82540)
1556 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 /* Program the Transmit Control Register */
1559
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001560 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001562 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1564
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001565 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1566 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001567 /* set the speed mode bit, we'll clear it if we're not at
1568 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001569 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001570 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001571 } else if (hw->mac_type == e1000_80003es2lan) {
1572 tarc = E1000_READ_REG(hw, TARC0);
1573 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001574 E1000_WRITE_REG(hw, TARC0, tarc);
1575 tarc = E1000_READ_REG(hw, TARC1);
1576 tarc |= 1;
1577 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001578 }
1579
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001580 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
1582 /* Setup Transmit Descriptor Settings for eop descriptor */
Jesse Brandeburg6a042da2006-11-01 08:48:04 -08001583 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1584
1585 /* only set IDE if we are delaying interrupts using the timers */
1586 if (adapter->tx_int_delay)
1587 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001589 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1591 else
1592 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1593
1594 /* Cache if we're 82544 running in PCI-X because we'll
1595 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001596 if (hw->mac_type == e1000_82544 &&
1597 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001599
1600 E1000_WRITE_REG(hw, TCTL, tctl);
1601
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602}
1603
1604/**
1605 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1606 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001607 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 *
1609 * Returns 0 on success, negative on failure
1610 **/
1611
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001612static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001613e1000_setup_rx_resources(struct e1000_adapter *adapter,
1614 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001617 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
1619 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001620 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001621 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001622 DPRINTK(PROBE, ERR,
1623 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 return -ENOMEM;
1625 }
1626 memset(rxdr->buffer_info, 0, size);
1627
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001628 size = sizeof(struct e1000_ps_page) * rxdr->count;
1629 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001630 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001631 vfree(rxdr->buffer_info);
1632 DPRINTK(PROBE, ERR,
1633 "Unable to allocate memory for the receive descriptor ring\n");
1634 return -ENOMEM;
1635 }
1636 memset(rxdr->ps_page, 0, size);
1637
1638 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1639 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001640 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001641 vfree(rxdr->buffer_info);
1642 kfree(rxdr->ps_page);
1643 DPRINTK(PROBE, ERR,
1644 "Unable to allocate memory for the receive descriptor ring\n");
1645 return -ENOMEM;
1646 }
1647 memset(rxdr->ps_page_dma, 0, size);
1648
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001649 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001650 desc_len = sizeof(struct e1000_rx_desc);
1651 else
1652 desc_len = sizeof(union e1000_rx_desc_packet_split);
1653
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 /* Round up to nearest 4K */
1655
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001656 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 E1000_ROUNDUP(rxdr->size, 4096);
1658
1659 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1660
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001661 if (!rxdr->desc) {
1662 DPRINTK(PROBE, ERR,
1663 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001666 kfree(rxdr->ps_page);
1667 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 return -ENOMEM;
1669 }
1670
Malli Chilakala26483452005-04-28 19:44:46 -07001671 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1673 void *olddesc = rxdr->desc;
1674 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001675 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1676 "at %p\n", rxdr->size, rxdr->desc);
1677 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001679 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001680 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001682 DPRINTK(PROBE, ERR,
1683 "Unable to allocate memory "
1684 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 goto setup_rx_desc_die;
1686 }
1687
1688 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1689 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001690 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1691 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001693 DPRINTK(PROBE, ERR,
1694 "Unable to allocate aligned memory "
1695 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001696 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001698 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1700 }
1701 }
1702 memset(rxdr->desc, 0, rxdr->size);
1703
1704 rxdr->next_to_clean = 0;
1705 rxdr->next_to_use = 0;
1706
1707 return 0;
1708}
1709
1710/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001711 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1712 * (Descriptors) for all queues
1713 * @adapter: board private structure
1714 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001715 * Return 0 on success, negative on failure
1716 **/
1717
1718int
1719e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1720{
1721 int i, err = 0;
1722
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001723 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001724 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1725 if (err) {
1726 DPRINTK(PROBE, ERR,
1727 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001728 for (i-- ; i >= 0; i--)
1729 e1000_free_rx_resources(adapter,
1730 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001731 break;
1732 }
1733 }
1734
1735 return err;
1736}
1737
1738/**
Malli Chilakala26483452005-04-28 19:44:46 -07001739 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 * @adapter: Board private structure
1741 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001742#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1743 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744static void
1745e1000_setup_rctl(struct e1000_adapter *adapter)
1746{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001747 uint32_t rctl, rfctl;
1748 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001749#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001750 uint32_t pages = 0;
1751#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1754
1755 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1756
1757 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1758 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1759 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1760
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001761 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 rctl |= E1000_RCTL_SBP;
1763 else
1764 rctl &= ~E1000_RCTL_SBP;
1765
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001766 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1767 rctl &= ~E1000_RCTL_LPE;
1768 else
1769 rctl |= E1000_RCTL_LPE;
1770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001772 rctl &= ~E1000_RCTL_SZ_4096;
1773 rctl |= E1000_RCTL_BSEX;
1774 switch (adapter->rx_buffer_len) {
1775 case E1000_RXBUFFER_256:
1776 rctl |= E1000_RCTL_SZ_256;
1777 rctl &= ~E1000_RCTL_BSEX;
1778 break;
1779 case E1000_RXBUFFER_512:
1780 rctl |= E1000_RCTL_SZ_512;
1781 rctl &= ~E1000_RCTL_BSEX;
1782 break;
1783 case E1000_RXBUFFER_1024:
1784 rctl |= E1000_RCTL_SZ_1024;
1785 rctl &= ~E1000_RCTL_BSEX;
1786 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001787 case E1000_RXBUFFER_2048:
1788 default:
1789 rctl |= E1000_RCTL_SZ_2048;
1790 rctl &= ~E1000_RCTL_BSEX;
1791 break;
1792 case E1000_RXBUFFER_4096:
1793 rctl |= E1000_RCTL_SZ_4096;
1794 break;
1795 case E1000_RXBUFFER_8192:
1796 rctl |= E1000_RCTL_SZ_8192;
1797 break;
1798 case E1000_RXBUFFER_16384:
1799 rctl |= E1000_RCTL_SZ_16384;
1800 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001801 }
1802
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001803#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001804 /* 82571 and greater support packet-split where the protocol
1805 * header is placed in skb->data and the packet data is
1806 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1807 * In the case of a non-split, skb->data is linearly filled,
1808 * followed by the page buffers. Therefore, skb->data is
1809 * sized to hold the largest protocol header.
1810 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001811 /* allocations using alloc_page take too long for regular MTU
1812 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001813 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001814 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1815 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001816 adapter->rx_ps_pages = pages;
1817 else
1818 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001819#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001820 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001821 /* Configure extra packet-split registers */
1822 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1823 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08001824 /* disable packet split support for IPv6 extension headers,
1825 * because some malformed IPv6 headers can hang the RX */
1826 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1827 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1828
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001829 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1830
Auke Kok7dfee0c2006-06-27 09:07:50 -07001831 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001832
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001833 psrctl |= adapter->rx_ps_bsize0 >>
1834 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001835
1836 switch (adapter->rx_ps_pages) {
1837 case 3:
1838 psrctl |= PAGE_SIZE <<
1839 E1000_PSRCTL_BSIZE3_SHIFT;
1840 case 2:
1841 psrctl |= PAGE_SIZE <<
1842 E1000_PSRCTL_BSIZE2_SHIFT;
1843 case 1:
1844 psrctl |= PAGE_SIZE >>
1845 E1000_PSRCTL_BSIZE1_SHIFT;
1846 break;
1847 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001848
1849 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 }
1851
1852 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1853}
1854
1855/**
1856 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1857 * @adapter: board private structure
1858 *
1859 * Configure the Rx unit of the MAC after a reset.
1860 **/
1861
1862static void
1863e1000_configure_rx(struct e1000_adapter *adapter)
1864{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001865 uint64_t rdba;
1866 struct e1000_hw *hw = &adapter->hw;
1867 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001868
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001869 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001870 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001871 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001872 sizeof(union e1000_rx_desc_packet_split);
1873 adapter->clean_rx = e1000_clean_rx_irq_ps;
1874 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1875 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001876 rdlen = adapter->rx_ring[0].count *
1877 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001878 adapter->clean_rx = e1000_clean_rx_irq;
1879 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1880 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
1882 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001883 rctl = E1000_READ_REG(hw, RCTL);
1884 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
1886 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001887 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001889 if (hw->mac_type >= e1000_82540) {
1890 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001891 if (adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001892 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 1000000000 / (adapter->itr * 256));
1894 }
1895
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001896 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001897 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001898 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07001899 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001900#ifdef CONFIG_E1000_NAPI
1901 /* Auto-Mask interrupts upon ICR read. */
1902 ctrl_ext |= E1000_CTRL_EXT_IAME;
1903#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001904 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001905 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001906 E1000_WRITE_FLUSH(hw);
1907 }
1908
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001909 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1910 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001911 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001912 case 1:
1913 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001914 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001915 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001916 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1917 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001918 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001919 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001920 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
1921 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001922 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001923 }
1924
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001926 if (hw->mac_type >= e1000_82543) {
1927 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001928 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001929 rxcsum |= E1000_RXCSUM_TUOFL;
1930
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001931 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001932 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001933 if ((hw->mac_type >= e1000_82571) &&
1934 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001935 rxcsum |= E1000_RXCSUM_IPPCSE;
1936 }
1937 } else {
1938 rxcsum &= ~E1000_RXCSUM_TUOFL;
1939 /* don't need to clear IPPCSE as it defaults to 0 */
1940 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001941 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 }
1943
Auke Kok21c4d5e2006-11-01 08:47:39 -08001944 /* enable early receives on 82573, only takes effect if using > 2048
1945 * byte total frame size. for example only for jumbo frames */
1946#define E1000_ERT_2048 0x100
1947 if (hw->mac_type == e1000_82573)
1948 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
1949
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001951 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952}
1953
1954/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001955 * e1000_free_tx_resources - Free Tx Resources per Queue
1956 * @adapter: board private structure
1957 * @tx_ring: Tx descriptor ring for a specific queue
1958 *
1959 * Free all transmit software resources
1960 **/
1961
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001962static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001963e1000_free_tx_resources(struct e1000_adapter *adapter,
1964 struct e1000_tx_ring *tx_ring)
1965{
1966 struct pci_dev *pdev = adapter->pdev;
1967
1968 e1000_clean_tx_ring(adapter, tx_ring);
1969
1970 vfree(tx_ring->buffer_info);
1971 tx_ring->buffer_info = NULL;
1972
1973 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1974
1975 tx_ring->desc = NULL;
1976}
1977
1978/**
1979 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 * @adapter: board private structure
1981 *
1982 * Free all transmit software resources
1983 **/
1984
1985void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001986e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001988 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001990 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001991 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992}
1993
Auke Koke619d522006-04-14 19:04:52 -07001994static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1996 struct e1000_buffer *buffer_info)
1997{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001998 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001999 pci_unmap_page(adapter->pdev,
2000 buffer_info->dma,
2001 buffer_info->length,
2002 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002003 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002005 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002007 buffer_info->skb = NULL;
2008 }
2009 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010}
2011
2012/**
2013 * e1000_clean_tx_ring - Free Tx Buffers
2014 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002015 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 **/
2017
2018static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002019e1000_clean_tx_ring(struct e1000_adapter *adapter,
2020 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 struct e1000_buffer *buffer_info;
2023 unsigned long size;
2024 unsigned int i;
2025
2026 /* Free all the Tx ring sk_buffs */
2027
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002028 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 buffer_info = &tx_ring->buffer_info[i];
2030 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2031 }
2032
2033 size = sizeof(struct e1000_buffer) * tx_ring->count;
2034 memset(tx_ring->buffer_info, 0, size);
2035
2036 /* Zero out the descriptor ring */
2037
2038 memset(tx_ring->desc, 0, tx_ring->size);
2039
2040 tx_ring->next_to_use = 0;
2041 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002042 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002044 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2045 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2046}
2047
2048/**
2049 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2050 * @adapter: board private structure
2051 **/
2052
2053static void
2054e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2055{
2056 int i;
2057
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002058 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002059 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
2062/**
2063 * e1000_free_rx_resources - Free Rx Resources
2064 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002065 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 *
2067 * Free all receive software resources
2068 **/
2069
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002070static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002071e1000_free_rx_resources(struct e1000_adapter *adapter,
2072 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct pci_dev *pdev = adapter->pdev;
2075
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002076 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
2078 vfree(rx_ring->buffer_info);
2079 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002080 kfree(rx_ring->ps_page);
2081 rx_ring->ps_page = NULL;
2082 kfree(rx_ring->ps_page_dma);
2083 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
2085 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2086
2087 rx_ring->desc = NULL;
2088}
2089
2090/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002091 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002093 *
2094 * Free all receive software resources
2095 **/
2096
2097void
2098e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2099{
2100 int i;
2101
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002102 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002103 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2104}
2105
2106/**
2107 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2108 * @adapter: board private structure
2109 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 **/
2111
2112static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002113e1000_clean_rx_ring(struct e1000_adapter *adapter,
2114 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002117 struct e1000_ps_page *ps_page;
2118 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 struct pci_dev *pdev = adapter->pdev;
2120 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002121 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
2123 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002124 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002126 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 pci_unmap_single(pdev,
2128 buffer_info->dma,
2129 buffer_info->length,
2130 PCI_DMA_FROMDEVICE);
2131
2132 dev_kfree_skb(buffer_info->skb);
2133 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002134 }
2135 ps_page = &rx_ring->ps_page[i];
2136 ps_page_dma = &rx_ring->ps_page_dma[i];
2137 for (j = 0; j < adapter->rx_ps_pages; j++) {
2138 if (!ps_page->ps_page[j]) break;
2139 pci_unmap_page(pdev,
2140 ps_page_dma->ps_page_dma[j],
2141 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2142 ps_page_dma->ps_page_dma[j] = 0;
2143 put_page(ps_page->ps_page[j]);
2144 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 }
2146 }
2147
2148 size = sizeof(struct e1000_buffer) * rx_ring->count;
2149 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002150 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2151 memset(rx_ring->ps_page, 0, size);
2152 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2153 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
2155 /* Zero out the descriptor ring */
2156
2157 memset(rx_ring->desc, 0, rx_ring->size);
2158
2159 rx_ring->next_to_clean = 0;
2160 rx_ring->next_to_use = 0;
2161
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002162 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2163 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2164}
2165
2166/**
2167 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2168 * @adapter: board private structure
2169 **/
2170
2171static void
2172e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2173{
2174 int i;
2175
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002176 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002177 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178}
2179
2180/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2181 * and memory write and invalidate disabled for certain operations
2182 */
2183static void
2184e1000_enter_82542_rst(struct e1000_adapter *adapter)
2185{
2186 struct net_device *netdev = adapter->netdev;
2187 uint32_t rctl;
2188
2189 e1000_pci_clear_mwi(&adapter->hw);
2190
2191 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2192 rctl |= E1000_RCTL_RST;
2193 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2194 E1000_WRITE_FLUSH(&adapter->hw);
2195 mdelay(5);
2196
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002197 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002198 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199}
2200
2201static void
2202e1000_leave_82542_rst(struct e1000_adapter *adapter)
2203{
2204 struct net_device *netdev = adapter->netdev;
2205 uint32_t rctl;
2206
2207 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2208 rctl &= ~E1000_RCTL_RST;
2209 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2210 E1000_WRITE_FLUSH(&adapter->hw);
2211 mdelay(5);
2212
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002213 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 e1000_pci_set_mwi(&adapter->hw);
2215
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002216 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002217 /* No need to loop, because 82542 supports only 1 queue */
2218 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002219 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002220 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 }
2222}
2223
2224/**
2225 * e1000_set_mac - Change the Ethernet Address of the NIC
2226 * @netdev: network interface device structure
2227 * @p: pointer to an address structure
2228 *
2229 * Returns 0 on success, negative on failure
2230 **/
2231
2232static int
2233e1000_set_mac(struct net_device *netdev, void *p)
2234{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002235 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 struct sockaddr *addr = p;
2237
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002238 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 return -EADDRNOTAVAIL;
2240
2241 /* 82542 2.0 needs to be in reset to write receive address registers */
2242
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002243 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 e1000_enter_82542_rst(adapter);
2245
2246 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2247 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2248
2249 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2250
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002251 /* With 82571 controllers, LAA may be overwritten (with the default)
2252 * due to controller reset from the other port. */
2253 if (adapter->hw.mac_type == e1000_82571) {
2254 /* activate the work around */
2255 adapter->hw.laa_is_present = 1;
2256
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002257 /* Hold a copy of the LAA in RAR[14] This is done so that
2258 * between the time RAR[0] gets clobbered and the time it
2259 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002260 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002261 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002262 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002263 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002264 E1000_RAR_ENTRIES - 1);
2265 }
2266
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002267 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 e1000_leave_82542_rst(adapter);
2269
2270 return 0;
2271}
2272
2273/**
2274 * e1000_set_multi - Multicast and Promiscuous mode set
2275 * @netdev: network interface device structure
2276 *
2277 * The set_multi entry point is called whenever the multicast address
2278 * list or the network interface flags are updated. This routine is
2279 * responsible for configuring the hardware for proper multicast,
2280 * promiscuous mode, and all-multi behavior.
2281 **/
2282
2283static void
2284e1000_set_multi(struct net_device *netdev)
2285{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002286 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 struct e1000_hw *hw = &adapter->hw;
2288 struct dev_mc_list *mc_ptr;
2289 uint32_t rctl;
2290 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002291 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002292 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2293 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2294 E1000_NUM_MTA_REGISTERS;
2295
2296 if (adapter->hw.mac_type == e1000_ich8lan)
2297 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002299 /* reserve RAR[14] for LAA over-write work-around */
2300 if (adapter->hw.mac_type == e1000_82571)
2301 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
Malli Chilakala26483452005-04-28 19:44:46 -07002303 /* Check for Promiscuous and All Multicast modes */
2304
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 rctl = E1000_READ_REG(hw, RCTL);
2306
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002307 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002309 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 rctl |= E1000_RCTL_MPE;
2311 rctl &= ~E1000_RCTL_UPE;
2312 } else {
2313 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2314 }
2315
2316 E1000_WRITE_REG(hw, RCTL, rctl);
2317
2318 /* 82542 2.0 needs to be in reset to write receive address registers */
2319
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002320 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 e1000_enter_82542_rst(adapter);
2322
2323 /* load the first 14 multicast address into the exact filters 1-14
2324 * RAR 0 is used for the station MAC adddress
2325 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002326 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 */
2328 mc_ptr = netdev->mc_list;
2329
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002330 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002331 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2333 mc_ptr = mc_ptr->next;
2334 } else {
2335 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002336 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002338 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 }
2340 }
2341
2342 /* clear the old settings from the multicast hash table */
2343
Auke Kokcd94dd02006-06-27 09:08:22 -07002344 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002346 E1000_WRITE_FLUSH(hw);
2347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348
2349 /* load any remaining addresses into the hash table */
2350
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002351 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2353 e1000_mta_set(hw, hash_value);
2354 }
2355
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002356 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358}
2359
2360/* Need to wait a few seconds after link up to get diagnostic information from
2361 * the phy */
2362
2363static void
2364e1000_update_phy_info(unsigned long data)
2365{
2366 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2367 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2368}
2369
2370/**
2371 * e1000_82547_tx_fifo_stall - Timer Call-back
2372 * @data: pointer to adapter cast into an unsigned long
2373 **/
2374
2375static void
2376e1000_82547_tx_fifo_stall(unsigned long data)
2377{
2378 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2379 struct net_device *netdev = adapter->netdev;
2380 uint32_t tctl;
2381
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002382 if (atomic_read(&adapter->tx_fifo_stall)) {
2383 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 E1000_READ_REG(&adapter->hw, TDH)) &&
2385 (E1000_READ_REG(&adapter->hw, TDFT) ==
2386 E1000_READ_REG(&adapter->hw, TDFH)) &&
2387 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2388 E1000_READ_REG(&adapter->hw, TDFHS))) {
2389 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2390 E1000_WRITE_REG(&adapter->hw, TCTL,
2391 tctl & ~E1000_TCTL_EN);
2392 E1000_WRITE_REG(&adapter->hw, TDFT,
2393 adapter->tx_head_addr);
2394 E1000_WRITE_REG(&adapter->hw, TDFH,
2395 adapter->tx_head_addr);
2396 E1000_WRITE_REG(&adapter->hw, TDFTS,
2397 adapter->tx_head_addr);
2398 E1000_WRITE_REG(&adapter->hw, TDFHS,
2399 adapter->tx_head_addr);
2400 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2401 E1000_WRITE_FLUSH(&adapter->hw);
2402
2403 adapter->tx_fifo_head = 0;
2404 atomic_set(&adapter->tx_fifo_stall, 0);
2405 netif_wake_queue(netdev);
2406 } else {
2407 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2408 }
2409 }
2410}
2411
2412/**
2413 * e1000_watchdog - Timer Call-back
2414 * @data: pointer to adapter cast into an unsigned long
2415 **/
2416static void
2417e1000_watchdog(unsigned long data)
2418{
2419 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002421 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002422 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002423 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
Auke Kokcd94dd02006-06-27 09:08:22 -07002425 ret_val = e1000_check_for_link(&adapter->hw);
2426 if ((ret_val == E1000_ERR_PHY) &&
2427 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2428 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2429 /* See e1000_kumeran_lock_loss_workaround() */
2430 DPRINTK(LINK, INFO,
2431 "Gigabit has been disabled, downgrading speed\n");
2432 }
Auke Kok90fb5132006-11-01 08:47:30 -08002433
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002434 if (adapter->hw.mac_type == e1000_82573) {
2435 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002436 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002437 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002440 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2442 link = !adapter->hw.serdes_link_down;
2443 else
2444 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2445
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002446 if (link) {
2447 if (!netif_carrier_ok(netdev)) {
Auke Kokfe7fe282006-04-14 19:04:59 -07002448 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 e1000_get_speed_and_duplex(&adapter->hw,
2450 &adapter->link_speed,
2451 &adapter->link_duplex);
2452
2453 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2454 adapter->link_speed,
2455 adapter->link_duplex == FULL_DUPLEX ?
2456 "Full Duplex" : "Half Duplex");
2457
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002458 /* tweak tx_queue_len according to speed/duplex
2459 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002460 netdev->tx_queue_len = adapter->tx_queue_len;
2461 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002462 switch (adapter->link_speed) {
2463 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002464 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002465 netdev->tx_queue_len = 10;
2466 adapter->tx_timeout_factor = 8;
2467 break;
2468 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002469 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002470 netdev->tx_queue_len = 100;
2471 /* maybe add some timeout factor ? */
2472 break;
2473 }
2474
Auke Kokfe7fe282006-04-14 19:04:59 -07002475 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002476 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002477 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002478 uint32_t tarc0;
2479 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002480 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002481 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2482 }
Auke Kok90fb5132006-11-01 08:47:30 -08002483
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002484#ifdef NETIF_F_TSO
2485 /* disable TSO for pcie and 10/100 speeds, to avoid
2486 * some hardware issues */
2487 if (!adapter->tso_force &&
2488 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002489 switch (adapter->link_speed) {
2490 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002491 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002492 DPRINTK(PROBE,INFO,
2493 "10/100 speed: disabling TSO\n");
2494 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002495#ifdef NETIF_F_TSO6
2496 netdev->features &= ~NETIF_F_TSO6;
2497#endif
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002498 break;
2499 case SPEED_1000:
2500 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002501#ifdef NETIF_F_TSO6
2502 netdev->features |= NETIF_F_TSO6;
2503#endif
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002504 break;
2505 default:
2506 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002507 break;
2508 }
2509 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002510#endif
2511
2512 /* enable transmits in the hardware, need to do this
2513 * after setting TARC0 */
2514 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2515 tctl |= E1000_TCTL_EN;
2516 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002517
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 netif_carrier_on(netdev);
2519 netif_wake_queue(netdev);
2520 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2521 adapter->smartspeed = 0;
2522 }
2523 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002524 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 adapter->link_speed = 0;
2526 adapter->link_duplex = 0;
2527 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2528 netif_carrier_off(netdev);
2529 netif_stop_queue(netdev);
2530 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002531
2532 /* 80003ES2LAN workaround--
2533 * For packet buffer work-around on link down event;
2534 * disable receives in the ISR and
2535 * reset device here in the watchdog
2536 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002537 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002538 /* reset device */
2539 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 }
2541
2542 e1000_smartspeed(adapter);
2543 }
2544
2545 e1000_update_stats(adapter);
2546
2547 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2548 adapter->tpt_old = adapter->stats.tpt;
2549 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2550 adapter->colc_old = adapter->stats.colc;
2551
2552 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2553 adapter->gorcl_old = adapter->stats.gorcl;
2554 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2555 adapter->gotcl_old = adapter->stats.gotcl;
2556
2557 e1000_update_adaptive(&adapter->hw);
2558
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002559 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002560 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 /* We've lost link, so the controller stops DMA,
2562 * but we've got queued Tx work that's never going
2563 * to get done, so reset controller to flush Tx.
2564 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002565 adapter->tx_timeout_count++;
2566 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 }
2568 }
2569
2570 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002571 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2573 * asymmetrical Tx or Rx gets ITR=8000; everyone
2574 * else is between 2000-8000. */
2575 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002576 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 adapter->gotcl - adapter->gorcl :
2578 adapter->gorcl - adapter->gotcl) / 10000;
2579 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2580 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2581 }
2582
2583 /* Cause software interrupt to ensure rx ring is cleaned */
2584 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2585
Malli Chilakala26483452005-04-28 19:44:46 -07002586 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 adapter->detect_tx_hung = TRUE;
2588
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002589 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002590 * reset from the other port. Set the appropriate LAA in RAR[0] */
2591 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2592 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2593
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 /* Reset the timer */
2595 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2596}
2597
2598#define E1000_TX_FLAGS_CSUM 0x00000001
2599#define E1000_TX_FLAGS_VLAN 0x00000002
2600#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002601#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2603#define E1000_TX_FLAGS_VLAN_SHIFT 16
2604
Auke Koke619d522006-04-14 19:04:52 -07002605static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002606e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2607 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608{
2609#ifdef NETIF_F_TSO
2610 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002611 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 unsigned int i;
2613 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002614 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2616 int err;
2617
Herbert Xu89114af2006-07-08 13:34:32 -07002618 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 if (skb_header_cloned(skb)) {
2620 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2621 if (err)
2622 return err;
2623 }
2624
2625 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Herbert Xu79671682006-06-22 02:40:14 -07002626 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002627 if (skb->protocol == htons(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002628 skb->nh.iph->tot_len = 0;
2629 skb->nh.iph->check = 0;
2630 skb->h.th->check =
2631 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2632 skb->nh.iph->daddr,
2633 0,
2634 IPPROTO_TCP,
2635 0);
2636 cmd_length = E1000_TXD_CMD_IP;
2637 ipcse = skb->h.raw - skb->data - 1;
Auke Kok87ca4e52006-11-01 08:47:36 -08002638#ifdef NETIF_F_TSO6
Auke Koke15fdd02006-08-16 11:28:45 -07002639 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002640 skb->nh.ipv6h->payload_len = 0;
2641 skb->h.th->check =
2642 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2643 &skb->nh.ipv6h->daddr,
2644 0,
2645 IPPROTO_TCP,
2646 0);
2647 ipcse = 0;
2648#endif
2649 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 ipcss = skb->nh.raw - skb->data;
2651 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 tucss = skb->h.raw - skb->data;
2653 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2654 tucse = 0;
2655
2656 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002657 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002659 i = tx_ring->next_to_use;
2660 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002661 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
2663 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2664 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2665 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2666 context_desc->upper_setup.tcp_fields.tucss = tucss;
2667 context_desc->upper_setup.tcp_fields.tucso = tucso;
2668 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2669 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2670 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2671 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2672
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002673 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002674 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002675
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002676 if (++i == tx_ring->count) i = 0;
2677 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678
Jeff Kirsher8241e352006-01-12 16:51:34 -08002679 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 }
2681#endif
2682
Jeff Kirsher8241e352006-01-12 16:51:34 -08002683 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684}
2685
Auke Koke619d522006-04-14 19:04:52 -07002686static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002687e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2688 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689{
2690 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002691 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 unsigned int i;
2693 uint8_t css;
2694
Patrick McHardy84fa7932006-08-29 16:44:56 -07002695 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 css = skb->h.raw - skb->data;
2697
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002698 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002699 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002700 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
2702 context_desc->upper_setup.tcp_fields.tucss = css;
2703 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2704 context_desc->upper_setup.tcp_fields.tucse = 0;
2705 context_desc->tcp_seg_setup.data = 0;
2706 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2707
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002708 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002709 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002710
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002711 if (unlikely(++i == tx_ring->count)) i = 0;
2712 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713
2714 return TRUE;
2715 }
2716
2717 return FALSE;
2718}
2719
2720#define E1000_MAX_TXD_PWR 12
2721#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2722
Auke Koke619d522006-04-14 19:04:52 -07002723static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002724e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2725 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2726 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 struct e1000_buffer *buffer_info;
2729 unsigned int len = skb->len;
2730 unsigned int offset = 0, size, count = 0, i;
2731 unsigned int f;
2732 len -= skb->data_len;
2733
2734 i = tx_ring->next_to_use;
2735
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002736 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 buffer_info = &tx_ring->buffer_info[i];
2738 size = min(len, max_per_txd);
2739#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002740 /* Workaround for Controller erratum --
2741 * descriptor for non-tso packet in a linear SKB that follows a
2742 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002743 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002744 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07002745 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002746 tx_ring->last_tx_tso = 0;
2747 size -= 4;
2748 }
2749
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 /* Workaround for premature desc write-backs
2751 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002752 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 size -= 4;
2754#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002755 /* work-around for errata 10 and it applies
2756 * to all controllers in PCI-X mode
2757 * The fix is to make sure that the first descriptor of a
2758 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2759 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002760 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002761 (size > 2015) && count == 0))
2762 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002763
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 /* Workaround for potential 82544 hang in PCI-X. Avoid
2765 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002766 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2768 size > 4))
2769 size -= 4;
2770
2771 buffer_info->length = size;
2772 buffer_info->dma =
2773 pci_map_single(adapter->pdev,
2774 skb->data + offset,
2775 size,
2776 PCI_DMA_TODEVICE);
2777 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002778 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779
2780 len -= size;
2781 offset += size;
2782 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002783 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 }
2785
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002786 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 struct skb_frag_struct *frag;
2788
2789 frag = &skb_shinfo(skb)->frags[f];
2790 len = frag->size;
2791 offset = frag->page_offset;
2792
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002793 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 buffer_info = &tx_ring->buffer_info[i];
2795 size = min(len, max_per_txd);
2796#ifdef NETIF_F_TSO
2797 /* Workaround for premature desc write-backs
2798 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002799 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 size -= 4;
2801#endif
2802 /* Workaround for potential 82544 hang in PCI-X.
2803 * Avoid terminating buffers within evenly-aligned
2804 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002805 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2807 size > 4))
2808 size -= 4;
2809
2810 buffer_info->length = size;
2811 buffer_info->dma =
2812 pci_map_page(adapter->pdev,
2813 frag->page,
2814 offset,
2815 size,
2816 PCI_DMA_TODEVICE);
2817 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002818 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
2820 len -= size;
2821 offset += size;
2822 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002823 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 }
2825 }
2826
2827 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2828 tx_ring->buffer_info[i].skb = skb;
2829 tx_ring->buffer_info[first].next_to_watch = i;
2830
2831 return count;
2832}
2833
Auke Koke619d522006-04-14 19:04:52 -07002834static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002835e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2836 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 struct e1000_tx_desc *tx_desc = NULL;
2839 struct e1000_buffer *buffer_info;
2840 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2841 unsigned int i;
2842
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002843 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2845 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002846 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2847
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002848 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002849 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 }
2851
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002852 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2854 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2855 }
2856
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002857 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 txd_lower |= E1000_TXD_CMD_VLE;
2859 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2860 }
2861
2862 i = tx_ring->next_to_use;
2863
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002864 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 buffer_info = &tx_ring->buffer_info[i];
2866 tx_desc = E1000_TX_DESC(*tx_ring, i);
2867 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2868 tx_desc->lower.data =
2869 cpu_to_le32(txd_lower | buffer_info->length);
2870 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002871 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 }
2873
2874 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2875
2876 /* Force memory writes to complete before letting h/w
2877 * know there are new descriptors to fetch. (Only
2878 * applicable for weak-ordered memory model archs,
2879 * such as IA-64). */
2880 wmb();
2881
2882 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002883 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08002884 /* we need this if more than one processor can write to our tail
2885 * at a time, it syncronizes IO on IA64/Altix systems */
2886 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887}
2888
2889/**
2890 * 82547 workaround to avoid controller hang in half-duplex environment.
2891 * The workaround is to avoid queuing a large packet that would span
2892 * the internal Tx FIFO ring boundary by notifying the stack to resend
2893 * the packet at a later time. This gives the Tx FIFO an opportunity to
2894 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2895 * to the beginning of the Tx FIFO.
2896 **/
2897
2898#define E1000_FIFO_HDR 0x10
2899#define E1000_82547_PAD_LEN 0x3E0
2900
Auke Koke619d522006-04-14 19:04:52 -07002901static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2903{
2904 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2905 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2906
2907 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2908
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002909 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 goto no_fifo_stall_required;
2911
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002912 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 return 1;
2914
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002915 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 atomic_set(&adapter->tx_fifo_stall, 1);
2917 return 1;
2918 }
2919
2920no_fifo_stall_required:
2921 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002922 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2924 return 0;
2925}
2926
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002927#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07002928static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002929e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2930{
2931 struct e1000_hw *hw = &adapter->hw;
2932 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002933 if (vlan_tx_tag_present(skb)) {
2934 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002935 ( adapter->hw.mng_cookie.status &
2936 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2937 return 0;
2938 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08002939 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002940 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002941 if ((htons(ETH_P_IP) == eth->h_proto)) {
2942 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002943 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002944 if (IPPROTO_UDP == ip->protocol) {
2945 struct udphdr *udp =
2946 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002947 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002948 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002949 offset = (uint8_t *)udp + 8 - skb->data;
2950 length = skb->len - offset;
2951
2952 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002953 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002954 length);
2955 }
2956 }
2957 }
2958 }
2959 return 0;
2960}
2961
Jesse Brandeburg65c79732006-09-27 12:53:48 -07002962static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
2963{
2964 struct e1000_adapter *adapter = netdev_priv(netdev);
2965 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
2966
2967 netif_stop_queue(netdev);
2968 /* Herbert's original patch had:
2969 * smp_mb__after_netif_stop_queue();
2970 * but since that doesn't exist yet, just open code it. */
2971 smp_mb();
2972
2973 /* We need to check again in a case another CPU has just
2974 * made room available. */
2975 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
2976 return -EBUSY;
2977
2978 /* A reprieve! */
2979 netif_start_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08002980 ++adapter->restart_queue;
Jesse Brandeburg65c79732006-09-27 12:53:48 -07002981 return 0;
2982}
2983
2984static int e1000_maybe_stop_tx(struct net_device *netdev,
2985 struct e1000_tx_ring *tx_ring, int size)
2986{
2987 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
2988 return 0;
2989 return __e1000_maybe_stop_tx(netdev, size);
2990}
2991
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2993static int
2994e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2995{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002996 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002997 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2999 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3000 unsigned int tx_flags = 0;
3001 unsigned int len = skb->len;
3002 unsigned long flags;
3003 unsigned int nr_frags = 0;
3004 unsigned int mss = 0;
3005 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003006 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 unsigned int f;
3008 len -= skb->data_len;
3009
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003010 /* This goes back to the question of how to logically map a tx queue
3011 * to a flow. Right now, performance is impacted slightly negatively
3012 * if using multiple tx queues. If the stack breaks away from a
3013 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003014 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003015
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003016 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 dev_kfree_skb_any(skb);
3018 return NETDEV_TX_OK;
3019 }
3020
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003021 /* 82571 and newer doesn't need the workaround that limited descriptor
3022 * length to 4kB */
3023 if (adapter->hw.mac_type >= e1000_82571)
3024 max_per_txd = 8192;
3025
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026#ifdef NETIF_F_TSO
Herbert Xu79671682006-06-22 02:40:14 -07003027 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003028 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 * make sure there is enough room in the FIFO before
3030 * initiating the DMA for each buffer. The calc is:
3031 * 4 = ceil(buffer len/mss). To make sure we don't
3032 * overrun the FIFO, adjust the max buffer len if mss
3033 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003034 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003035 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 max_per_txd = min(mss << 2, max_per_txd);
3037 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003038
Auke Kok90fb5132006-11-01 08:47:30 -08003039 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3040 * points to just header, pull a few bytes of payload from
3041 * frags into skb->data */
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003042 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08003043 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3044 switch (adapter->hw.mac_type) {
3045 unsigned int pull_size;
3046 case e1000_82571:
3047 case e1000_82572:
3048 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003049 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003050 pull_size = min((unsigned int)4, skb->data_len);
3051 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003052 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003053 "__pskb_pull_tail failed.\n");
3054 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003055 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003056 }
3057 len = skb->len - skb->data_len;
3058 break;
3059 default:
3060 /* do nothing */
3061 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003062 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003063 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 }
3065
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003066 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003067 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003069 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070#else
Patrick McHardy84fa7932006-08-29 16:44:56 -07003071 if (skb->ip_summed == CHECKSUM_PARTIAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 count++;
3073#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05003074
3075#ifdef NETIF_F_TSO
3076 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003077 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003078 count++;
3079#endif
3080
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 count += TXD_USE_COUNT(len, max_txd_pwr);
3082
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003083 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 count++;
3085
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003086 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003087 * in PCI-X mode, so add one more descriptor to the count
3088 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003089 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003090 (len > 2015)))
3091 count++;
3092
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003094 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3096 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003097 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 count += nr_frags;
3099
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003100
3101 if (adapter->hw.tx_pkt_filtering &&
3102 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003103 e1000_transfer_dhcp_info(adapter, skb);
3104
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003105 local_irq_save(flags);
3106 if (!spin_trylock(&tx_ring->tx_lock)) {
3107 /* Collision - tell upper layer to requeue */
3108 local_irq_restore(flags);
3109 return NETDEV_TX_LOCKED;
3110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111
3112 /* need: count + 2 desc gap to keep tail from touching
3113 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003114 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003115 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 return NETDEV_TX_BUSY;
3117 }
3118
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003119 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3120 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003122 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003123 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 return NETDEV_TX_BUSY;
3125 }
3126 }
3127
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003128 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 tx_flags |= E1000_TX_FLAGS_VLAN;
3130 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3131 }
3132
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003133 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003134
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003135 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 if (tso < 0) {
3137 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003138 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 return NETDEV_TX_OK;
3140 }
3141
Jeff Kirsherfd803242005-12-13 00:06:22 -05003142 if (likely(tso)) {
3143 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003145 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 tx_flags |= E1000_TX_FLAGS_CSUM;
3147
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003148 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003149 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003150 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003151 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003152 tx_flags |= E1000_TX_FLAGS_IPV4;
3153
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003154 e1000_tx_queue(adapter, tx_ring, tx_flags,
3155 e1000_tx_map(adapter, tx_ring, skb, first,
3156 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
3158 netdev->trans_start = jiffies;
3159
3160 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003161 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003163 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 return NETDEV_TX_OK;
3165}
3166
3167/**
3168 * e1000_tx_timeout - Respond to a Tx Hang
3169 * @netdev: network interface device structure
3170 **/
3171
3172static void
3173e1000_tx_timeout(struct net_device *netdev)
3174{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003175 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176
3177 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003178 adapter->tx_timeout_count++;
3179 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180}
3181
3182static void
Jeff Kirsher87041632006-03-02 18:21:24 -08003183e1000_reset_task(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003185 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186
Auke Kok2db10a02006-06-27 09:06:28 -07003187 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188}
3189
3190/**
3191 * e1000_get_stats - Get System Network Statistics
3192 * @netdev: network interface device structure
3193 *
3194 * Returns the address of the device statistics structure.
3195 * The statistics are actually updated from the timer callback.
3196 **/
3197
3198static struct net_device_stats *
3199e1000_get_stats(struct net_device *netdev)
3200{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003201 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003203 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 return &adapter->net_stats;
3205}
3206
3207/**
3208 * e1000_change_mtu - Change the Maximum Transfer Unit
3209 * @netdev: network interface device structure
3210 * @new_mtu: new value for maximum frame size
3211 *
3212 * Returns 0 on success, negative on failure
3213 **/
3214
3215static int
3216e1000_change_mtu(struct net_device *netdev, int new_mtu)
3217{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003218 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003220 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003222 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3223 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3224 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003225 return -EINVAL;
3226 }
3227
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003228 /* Adapter-specific max frame size limits. */
3229 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003230 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003231 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003232 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3233 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003234 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003235 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003236 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003237 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003238 /* Jumbo Frames not supported if:
3239 * - this is not an 82573L device
3240 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003241 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3242 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003243 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3244 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003245 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3246 DPRINTK(PROBE, ERR,
3247 "Jumbo Frames not supported.\n");
3248 return -EINVAL;
3249 }
3250 break;
3251 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003252 /* ERT will be enabled later to enable wire speed receives */
3253
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003254 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003255 case e1000_82571:
3256 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003257 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003258#define MAX_STD_JUMBO_FRAME_SIZE 9234
3259 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3260 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3261 return -EINVAL;
3262 }
3263 break;
3264 default:
3265 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3266 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003267 }
3268
David S. Miller87f50322006-07-31 22:39:40 -07003269 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003270 * means we reserve 2 more, this pushes us to allocate from the next
3271 * larger slab size
3272 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003273
Auke Kok9e2feac2006-04-14 19:05:18 -07003274 if (max_frame <= E1000_RXBUFFER_256)
3275 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3276 else if (max_frame <= E1000_RXBUFFER_512)
3277 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3278 else if (max_frame <= E1000_RXBUFFER_1024)
3279 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3280 else if (max_frame <= E1000_RXBUFFER_2048)
3281 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3282 else if (max_frame <= E1000_RXBUFFER_4096)
3283 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3284 else if (max_frame <= E1000_RXBUFFER_8192)
3285 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3286 else if (max_frame <= E1000_RXBUFFER_16384)
3287 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3288
3289 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003290 if (!adapter->hw.tbi_compatibility_on &&
3291 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3292 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3293 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003294
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003295 netdev->mtu = new_mtu;
3296
Auke Kok2db10a02006-06-27 09:06:28 -07003297 if (netif_running(netdev))
3298 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 adapter->hw.max_frame_size = max_frame;
3301
3302 return 0;
3303}
3304
3305/**
3306 * e1000_update_stats - Update the board statistics counters
3307 * @adapter: board private structure
3308 **/
3309
3310void
3311e1000_update_stats(struct e1000_adapter *adapter)
3312{
3313 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003314 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 unsigned long flags;
3316 uint16_t phy_tmp;
3317
3318#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3319
Linas Vepstas282f33c2006-06-08 22:19:44 -07003320 /*
3321 * Prevent stats update while adapter is being reset, or if the pci
3322 * connection is down.
3323 */
Auke Kok90267292006-06-08 09:30:24 -07003324 if (adapter->link_speed == 0)
3325 return;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003326 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3327 return;
Auke Kok90267292006-06-08 09:30:24 -07003328
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 spin_lock_irqsave(&adapter->stats_lock, flags);
3330
3331 /* these counters are modified from e1000_adjust_tbi_stats,
3332 * called from the interrupt context, so they must only
3333 * be written while holding adapter->stats_lock
3334 */
3335
3336 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3337 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3338 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3339 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3340 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3341 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3342 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003343
3344 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003345 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3346 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3347 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3348 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3349 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3350 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352
3353 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3354 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3355 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3356 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3357 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3358 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3359 adapter->stats.dc += E1000_READ_REG(hw, DC);
3360 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3361 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3362 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3363 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3364 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3365 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3366 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3367 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3368 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3369 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3370 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3371 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3372 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3373 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3374 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3375 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3376 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3377 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3378 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003379
3380 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003381 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3382 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3383 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3384 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3385 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3386 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003387 }
3388
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3390 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3391
3392 /* used for adaptive IFS */
3393
3394 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3395 adapter->stats.tpt += hw->tx_packet_delta;
3396 hw->collision_delta = E1000_READ_REG(hw, COLC);
3397 adapter->stats.colc += hw->collision_delta;
3398
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003399 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3401 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3402 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3403 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3404 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3405 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3406 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003407 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003408 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3409 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003410
3411 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003412 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3413 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3414 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3415 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3416 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3417 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3418 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003419 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421
3422 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 adapter->net_stats.rx_packets = adapter->stats.gprc;
3424 adapter->net_stats.tx_packets = adapter->stats.gptc;
3425 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3426 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3427 adapter->net_stats.multicast = adapter->stats.mprc;
3428 adapter->net_stats.collisions = adapter->stats.colc;
3429
3430 /* Rx Errors */
3431
Jeff Kirsher87041632006-03-02 18:21:24 -08003432 /* RLEC on some newer hardware can be incorrect so build
3433 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3435 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003436 adapter->stats.ruc + adapter->stats.roc +
3437 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003438 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3439 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3441 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3443
3444 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003445 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3446 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3448 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3449 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3450
3451 /* Tx Dropped needs to be maintained elsewhere */
3452
3453 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003454 if (hw->media_type == e1000_media_type_copper) {
3455 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3457 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3458 adapter->phy_stats.idle_errors += phy_tmp;
3459 }
3460
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003461 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 (hw->phy_type == e1000_phy_m88) &&
3463 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3464 adapter->phy_stats.receive_errors += phy_tmp;
3465 }
3466
3467 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3468}
3469
3470/**
3471 * e1000_intr - Interrupt Handler
3472 * @irq: interrupt number
3473 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 **/
3475
3476static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003477e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478{
3479 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003480 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003482 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003483#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003484 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003485#else
3486 /* Interrupt Auto-Mask...upon reading ICR,
3487 * interrupts are masked. No need for the
3488 * IMC write, but it does mean we should
3489 * account for it ASAP. */
3490 if (likely(hw->mac_type >= e1000_82571))
3491 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003492#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003494 if (unlikely(!icr)) {
3495#ifdef CONFIG_E1000_NAPI
3496 if (hw->mac_type >= e1000_82571)
3497 e1000_irq_enable(adapter);
3498#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003500 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003502 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003504 /* 80003ES2LAN workaround--
3505 * For packet buffer work-around on link down event;
3506 * disable receives here in the ISR and
3507 * reset adapter in watchdog
3508 */
3509 if (netif_carrier_ok(netdev) &&
3510 (adapter->hw.mac_type == e1000_80003es2lan)) {
3511 /* disable receives */
3512 rctl = E1000_READ_REG(hw, RCTL);
3513 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3514 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003515 /* guard against interrupt when we're going down */
3516 if (!test_bit(__E1000_DOWN, &adapter->flags))
3517 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 }
3519
3520#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003521 if (unlikely(hw->mac_type < e1000_82571)) {
3522 atomic_inc(&adapter->irq_sem);
3523 E1000_WRITE_REG(hw, IMC, ~0);
3524 E1000_WRITE_FLUSH(hw);
3525 }
Auke Kokd3d9e482006-07-14 16:14:23 -07003526 if (likely(netif_rx_schedule_prep(netdev)))
3527 __netif_rx_schedule(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003528 else
Auke Kok90fb5132006-11-01 08:47:30 -08003529 /* this really should not happen! if it does it is basically a
3530 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003531 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003532#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003534 * Due to Hub Link bus being occupied, an interrupt
3535 * de-assertion message is not able to be sent.
3536 * When an interrupt assertion message is generated later,
3537 * two messages are re-ordered and sent out.
3538 * That causes APIC to think 82547 is in de-assertion
3539 * state, while 82547 is in assertion state, resulting
3540 * in dead lock. Writing IMC forces 82547 into
3541 * de-assertion state.
3542 */
3543 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003545 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 }
3547
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003548 for (i = 0; i < E1000_MAX_INTR; i++)
3549 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003550 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 break;
3552
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003553 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003555
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003556#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 return IRQ_HANDLED;
3558}
3559
3560#ifdef CONFIG_E1000_NAPI
3561/**
3562 * e1000_clean - NAPI Rx polling callback
3563 * @adapter: board private structure
3564 **/
3565
3566static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003567e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003569 struct e1000_adapter *adapter;
3570 int work_to_do = min(*budget, poll_dev->quota);
Auke Kokd3d9e482006-07-14 16:14:23 -07003571 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003572
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003573 /* Must NOT use netdev_priv macro here. */
3574 adapter = poll_dev->priv;
3575
3576 /* Keep link state information with original netdev */
Auke Kokd3d9e482006-07-14 16:14:23 -07003577 if (!netif_carrier_ok(poll_dev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003578 goto quit_polling;
3579
Auke Kokd3d9e482006-07-14 16:14:23 -07003580 /* e1000_clean is called per-cpu. This lock protects
3581 * tx_ring[0] from being cleaned by multiple cpus
3582 * simultaneously. A failure obtaining the lock means
3583 * tx_ring[0] is currently being cleaned anyway. */
3584 if (spin_trylock(&adapter->tx_queue_lock)) {
3585 tx_cleaned = e1000_clean_tx_irq(adapter,
3586 &adapter->tx_ring[0]);
3587 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003588 }
3589
Auke Kokd3d9e482006-07-14 16:14:23 -07003590 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003591 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592
3593 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003594 poll_dev->quota -= work_done;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003595
Malli Chilakala2b028932005-06-17 17:46:06 -07003596 /* If no Tx and not enough Rx work done, exit the polling mode */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003597 if ((!tx_cleaned && (work_done == 0)) ||
Auke Kokd3d9e482006-07-14 16:14:23 -07003598 !netif_running(poll_dev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003599quit_polling:
3600 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 e1000_irq_enable(adapter);
3602 return 0;
3603 }
3604
3605 return 1;
3606}
3607
3608#endif
3609/**
3610 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3611 * @adapter: board private structure
3612 **/
3613
3614static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003615e1000_clean_tx_irq(struct e1000_adapter *adapter,
3616 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 struct net_device *netdev = adapter->netdev;
3619 struct e1000_tx_desc *tx_desc, *eop_desc;
3620 struct e1000_buffer *buffer_info;
3621 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003622#ifdef CONFIG_E1000_NAPI
3623 unsigned int count = 0;
3624#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 boolean_t cleaned = FALSE;
3626
3627 i = tx_ring->next_to_clean;
3628 eop = tx_ring->buffer_info[i].next_to_watch;
3629 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3630
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003631 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003632 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 tx_desc = E1000_TX_DESC(*tx_ring, i);
3634 buffer_info = &tx_ring->buffer_info[i];
3635 cleaned = (i == eop);
3636
Jeff Kirsherfd803242005-12-13 00:06:22 -05003637 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003638 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003640 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003642
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 eop = tx_ring->buffer_info[i].next_to_watch;
3644 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003645#ifdef CONFIG_E1000_NAPI
3646#define E1000_TX_WEIGHT 64
3647 /* weight of a sort for tx, to avoid endless transmit cleanup */
3648 if (count++ == E1000_TX_WEIGHT) break;
3649#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 }
3651
3652 tx_ring->next_to_clean = i;
3653
Auke Kok77b2aad2006-04-14 19:05:25 -07003654#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003655 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3656 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3657 /* Make sure that anybody stopping the queue after this
3658 * sees the new next_to_clean.
3659 */
3660 smp_mb();
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003661 if (netif_queue_stopped(netdev)) {
Auke Kok77b2aad2006-04-14 19:05:25 -07003662 netif_wake_queue(netdev);
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -08003663 ++adapter->restart_queue;
3664 }
Auke Kok77b2aad2006-04-14 19:05:25 -07003665 }
Malli Chilakala26483452005-04-28 19:44:46 -07003666
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003667 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003668 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 * check with the clearing of time_stamp and movement of i */
3670 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003671 if (tx_ring->buffer_info[eop].dma &&
3672 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003673 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003674 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003675 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003676
3677 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003678 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003679 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003680 " TDH <%x>\n"
3681 " TDT <%x>\n"
3682 " next_to_use <%x>\n"
3683 " next_to_clean <%x>\n"
3684 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003685 " time_stamp <%lx>\n"
3686 " next_to_watch <%x>\n"
3687 " jiffies <%lx>\n"
3688 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003689 (unsigned long)((tx_ring - adapter->tx_ring) /
3690 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003691 readl(adapter->hw.hw_addr + tx_ring->tdh),
3692 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003693 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003694 tx_ring->next_to_clean,
3695 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003696 eop,
3697 jiffies,
3698 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 return cleaned;
3703}
3704
3705/**
3706 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003707 * @adapter: board private structure
3708 * @status_err: receive descriptor status and error fields
3709 * @csum: receive descriptor csum field
3710 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 **/
3712
Auke Koke619d522006-04-14 19:04:52 -07003713static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003715 uint32_t status_err, uint32_t csum,
3716 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003718 uint16_t status = (uint16_t)status_err;
3719 uint8_t errors = (uint8_t)(status_err >> 24);
3720 skb->ip_summed = CHECKSUM_NONE;
3721
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003723 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003725 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003726 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003727 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003728 /* let the stack verify checksum errors */
3729 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 return;
3731 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003732 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003733 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3734 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003735 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003737 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003738 return;
3739 }
3740 /* It must be a TCP or UDP packet with a valid checksum */
3741 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 /* TCP checksum is good */
3743 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003744 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3745 /* IP fragment with UDP payload */
3746 /* Hardware complements the payload checksum, so we undo it
3747 * and then put the value in host order for further stack use.
3748 */
3749 csum = ntohl(csum ^ 0xFFFF);
3750 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07003751 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003753 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754}
3755
3756/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003757 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 * @adapter: board private structure
3759 **/
3760
3761static boolean_t
3762#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003763e1000_clean_rx_irq(struct e1000_adapter *adapter,
3764 struct e1000_rx_ring *rx_ring,
3765 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003767e1000_clean_rx_irq(struct e1000_adapter *adapter,
3768 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769#endif
3770{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 struct net_device *netdev = adapter->netdev;
3772 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003773 struct e1000_rx_desc *rx_desc, *next_rxd;
3774 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 unsigned long flags;
3776 uint32_t length;
3777 uint8_t last_byte;
3778 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003779 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003780 boolean_t cleaned = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781
3782 i = rx_ring->next_to_clean;
3783 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003784 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003786 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07003787 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003788 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08003789
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003791 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 break;
3793 (*work_done)++;
3794#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08003795 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003796 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003797 buffer_info->skb = NULL;
3798
Jeff Kirsher30320be2006-03-02 18:21:57 -08003799 prefetch(skb->data - NET_IP_ALIGN);
3800
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003801 if (++i == rx_ring->count) i = 0;
3802 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003803 prefetch(next_rxd);
3804
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003805 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003806
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003807 cleaned = TRUE;
3808 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003809 pci_unmap_single(pdev,
3810 buffer_info->dma,
3811 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 PCI_DMA_FROMDEVICE);
3813
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 length = le16_to_cpu(rx_desc->length);
3815
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003816 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3817 /* All receives must fit into a single buffer */
3818 E1000_DBG("%s: Receive packet consumed multiple"
3819 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07003820 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07003821 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 goto next_desc;
3823 }
3824
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003825 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003827 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 rx_desc->errors, length, last_byte)) {
3829 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003830 e1000_tbi_adjust_stats(&adapter->hw,
3831 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 length, skb->data);
3833 spin_unlock_irqrestore(&adapter->stats_lock,
3834 flags);
3835 length--;
3836 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07003837 /* recycle */
3838 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 goto next_desc;
3840 }
Auke Kok1cb58212006-04-18 12:31:04 -07003841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07003843 /* adjust length to remove Ethernet CRC, this must be
3844 * done after the TBI_ACCEPT workaround above */
3845 length -= 4;
3846
Jeff Kirshera292ca62006-01-12 16:51:30 -08003847 /* code added for copybreak, this should improve
3848 * performance for small packets with large amounts
3849 * of reassembly being done in the stack */
3850#define E1000_CB_LENGTH 256
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003851 if (length < E1000_CB_LENGTH) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08003852 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07003853 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003854 if (new_skb) {
3855 skb_reserve(new_skb, NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003856 memcpy(new_skb->data - NET_IP_ALIGN,
3857 skb->data - NET_IP_ALIGN,
3858 length + NET_IP_ALIGN);
3859 /* save the skb in buffer_info as good */
3860 buffer_info->skb = skb;
3861 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003862 }
Auke Kok996695d2006-11-01 08:47:50 -08003863 /* else just continue with the old one */
3864 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08003865 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08003866 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867
3868 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08003869 e1000_rx_checksum(adapter,
3870 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003871 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003872 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003873
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 skb->protocol = eth_type_trans(skb, netdev);
3875#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003876 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08003877 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003879 le16_to_cpu(rx_desc->special) &
3880 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 } else {
3882 netif_receive_skb(skb);
3883 }
3884#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003885 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003886 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 vlan_hwaccel_rx(skb, adapter->vlgrp,
3888 le16_to_cpu(rx_desc->special) &
3889 E1000_RXD_SPC_VLAN_MASK);
3890 } else {
3891 netif_rx(skb);
3892 }
3893#endif /* CONFIG_E1000_NAPI */
3894 netdev->last_rx = jiffies;
3895
3896next_desc:
3897 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003899 /* return some buffers to hardware, one at a time is too slow */
3900 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3901 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3902 cleaned_count = 0;
3903 }
3904
Jeff Kirsher30320be2006-03-02 18:21:57 -08003905 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003906 rx_desc = next_rxd;
3907 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003910
3911 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3912 if (cleaned_count)
3913 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914
3915 return cleaned;
3916}
3917
3918/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003919 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3920 * @adapter: board private structure
3921 **/
3922
3923static boolean_t
3924#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003925e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3926 struct e1000_rx_ring *rx_ring,
3927 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003928#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003929e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3930 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003931#endif
3932{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003933 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003934 struct net_device *netdev = adapter->netdev;
3935 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003936 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003937 struct e1000_ps_page *ps_page;
3938 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07003939 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003940 unsigned int i, j;
3941 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003942 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003943 boolean_t cleaned = FALSE;
3944
3945 i = rx_ring->next_to_clean;
3946 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003947 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07003948 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003949
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003950 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003951 ps_page = &rx_ring->ps_page[i];
3952 ps_page_dma = &rx_ring->ps_page_dma[i];
3953#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003954 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003955 break;
3956 (*work_done)++;
3957#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003958 skb = buffer_info->skb;
3959
Jeff Kirsher30320be2006-03-02 18:21:57 -08003960 /* in the packet split case this is header only */
3961 prefetch(skb->data - NET_IP_ALIGN);
3962
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003963 if (++i == rx_ring->count) i = 0;
3964 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003965 prefetch(next_rxd);
3966
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003967 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003968
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003969 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003970 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003971 pci_unmap_single(pdev, buffer_info->dma,
3972 buffer_info->length,
3973 PCI_DMA_FROMDEVICE);
3974
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003975 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003976 E1000_DBG("%s: Packet Split buffers didn't pick up"
3977 " the full packet\n", netdev->name);
3978 dev_kfree_skb_irq(skb);
3979 goto next_desc;
3980 }
3981
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003982 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003983 dev_kfree_skb_irq(skb);
3984 goto next_desc;
3985 }
3986
3987 length = le16_to_cpu(rx_desc->wb.middle.length0);
3988
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003989 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003990 E1000_DBG("%s: Last part of the packet spanning"
3991 " multiple descriptors\n", netdev->name);
3992 dev_kfree_skb_irq(skb);
3993 goto next_desc;
3994 }
3995
3996 /* Good Receive */
3997 skb_put(skb, length);
3998
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003999 {
4000 /* this looks ugly, but it seems compiler issues make it
4001 more efficient than reusing j */
4002 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
4003
4004 /* page alloc/put takes too long and effects small packet
4005 * throughput, so unsplit small packets and save the alloc/put*/
Auke Kok9e2feac2006-04-14 19:05:18 -07004006 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004007 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004008 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004009 * kmap_atomic, so we can't hold the mapping
4010 * very long */
4011 pci_dma_sync_single_for_cpu(pdev,
4012 ps_page_dma->ps_page_dma[0],
4013 PAGE_SIZE,
4014 PCI_DMA_FROMDEVICE);
4015 vaddr = kmap_atomic(ps_page->ps_page[0],
4016 KM_SKB_DATA_SOFTIRQ);
4017 memcpy(skb->tail, vaddr, l1);
4018 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4019 pci_dma_sync_single_for_device(pdev,
4020 ps_page_dma->ps_page_dma[0],
4021 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004022 /* remove the CRC */
4023 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004024 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004025 goto copydone;
4026 } /* if */
4027 }
Auke Kok90fb5132006-11-01 08:47:30 -08004028
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004029 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004030 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004031 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004032 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4033 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4034 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004035 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4036 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004037 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004038 skb->len += length;
4039 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004040 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004041 }
4042
Auke Kokf235a2a2006-07-14 16:14:34 -07004043 /* strip the ethernet crc, problem is we're using pages now so
4044 * this whole operation can get a little cpu intensive */
4045 pskb_trim(skb, skb->len - 4);
4046
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004047copydone:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004048 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004049 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004050 skb->protocol = eth_type_trans(skb, netdev);
4051
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004052 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004053 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004054 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004055#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004056 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004057 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004058 le16_to_cpu(rx_desc->wb.middle.vlan) &
4059 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004060 } else {
4061 netif_receive_skb(skb);
4062 }
4063#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004064 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004065 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004066 le16_to_cpu(rx_desc->wb.middle.vlan) &
4067 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004068 } else {
4069 netif_rx(skb);
4070 }
4071#endif /* CONFIG_E1000_NAPI */
4072 netdev->last_rx = jiffies;
4073
4074next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004075 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004076 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004077
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004078 /* return some buffers to hardware, one at a time is too slow */
4079 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4080 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4081 cleaned_count = 0;
4082 }
4083
Jeff Kirsher30320be2006-03-02 18:21:57 -08004084 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004085 rx_desc = next_rxd;
4086 buffer_info = next_buffer;
4087
Malli Chilakala683a38f2005-06-17 17:43:25 -07004088 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004089 }
4090 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004091
4092 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4093 if (cleaned_count)
4094 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004095
4096 return cleaned;
4097}
4098
4099/**
4100 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 * @adapter: address of board private structure
4102 **/
4103
4104static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004105e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004106 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004107 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 struct net_device *netdev = adapter->netdev;
4110 struct pci_dev *pdev = adapter->pdev;
4111 struct e1000_rx_desc *rx_desc;
4112 struct e1000_buffer *buffer_info;
4113 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004114 unsigned int i;
4115 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116
4117 i = rx_ring->next_to_use;
4118 buffer_info = &rx_ring->buffer_info[i];
4119
Jeff Kirshera292ca62006-01-12 16:51:30 -08004120 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004121 skb = buffer_info->skb;
4122 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004123 skb_trim(skb, 0);
4124 goto map_skb;
4125 }
4126
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004127 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004128 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004130 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 break;
4132 }
4133
Malli Chilakala26483452005-04-28 19:44:46 -07004134 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4136 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004137 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4138 "at %p\n", bufsz, skb->data);
4139 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004140 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004141 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 if (!skb) {
4143 dev_kfree_skb(oldskb);
4144 break;
4145 }
Malli Chilakala26483452005-04-28 19:44:46 -07004146
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4148 /* give up */
4149 dev_kfree_skb(skb);
4150 dev_kfree_skb(oldskb);
4151 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004153
4154 /* Use new allocation */
4155 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 /* Make buffer alignment 2 beyond a 16 byte boundary
4158 * this will result in a 16 byte aligned IP header after
4159 * the 14 byte MAC header is removed
4160 */
4161 skb_reserve(skb, NET_IP_ALIGN);
4162
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 buffer_info->skb = skb;
4164 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004165map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 buffer_info->dma = pci_map_single(pdev,
4167 skb->data,
4168 adapter->rx_buffer_len,
4169 PCI_DMA_FROMDEVICE);
4170
Malli Chilakala26483452005-04-28 19:44:46 -07004171 /* Fix for errata 23, can't cross 64kB boundary */
4172 if (!e1000_check_64k_bound(adapter,
4173 (void *)(unsigned long)buffer_info->dma,
4174 adapter->rx_buffer_len)) {
4175 DPRINTK(RX_ERR, ERR,
4176 "dma align check failed: %u bytes at %p\n",
4177 adapter->rx_buffer_len,
4178 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 dev_kfree_skb(skb);
4180 buffer_info->skb = NULL;
4181
Malli Chilakala26483452005-04-28 19:44:46 -07004182 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 adapter->rx_buffer_len,
4184 PCI_DMA_FROMDEVICE);
4185
4186 break; /* while !buffer_info->skb */
4187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188 rx_desc = E1000_RX_DESC(*rx_ring, i);
4189 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4190
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004191 if (unlikely(++i == rx_ring->count))
4192 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 buffer_info = &rx_ring->buffer_info[i];
4194 }
4195
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004196 if (likely(rx_ring->next_to_use != i)) {
4197 rx_ring->next_to_use = i;
4198 if (unlikely(i-- == 0))
4199 i = (rx_ring->count - 1);
4200
4201 /* Force memory writes to complete before letting h/w
4202 * know there are new descriptors to fetch. (Only
4203 * applicable for weak-ordered memory model archs,
4204 * such as IA-64). */
4205 wmb();
4206 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208}
4209
4210/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004211 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4212 * @adapter: address of board private structure
4213 **/
4214
4215static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004216e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004217 struct e1000_rx_ring *rx_ring,
4218 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004219{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004220 struct net_device *netdev = adapter->netdev;
4221 struct pci_dev *pdev = adapter->pdev;
4222 union e1000_rx_desc_packet_split *rx_desc;
4223 struct e1000_buffer *buffer_info;
4224 struct e1000_ps_page *ps_page;
4225 struct e1000_ps_page_dma *ps_page_dma;
4226 struct sk_buff *skb;
4227 unsigned int i, j;
4228
4229 i = rx_ring->next_to_use;
4230 buffer_info = &rx_ring->buffer_info[i];
4231 ps_page = &rx_ring->ps_page[i];
4232 ps_page_dma = &rx_ring->ps_page_dma[i];
4233
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004234 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004235 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4236
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004237 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004238 if (j < adapter->rx_ps_pages) {
4239 if (likely(!ps_page->ps_page[j])) {
4240 ps_page->ps_page[j] =
4241 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004242 if (unlikely(!ps_page->ps_page[j])) {
4243 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004244 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004245 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004246 ps_page_dma->ps_page_dma[j] =
4247 pci_map_page(pdev,
4248 ps_page->ps_page[j],
4249 0, PAGE_SIZE,
4250 PCI_DMA_FROMDEVICE);
4251 }
4252 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004253 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004254 * this info.
4255 */
4256 rx_desc->read.buffer_addr[j+1] =
4257 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4258 } else
4259 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004260 }
4261
David S. Miller87f50322006-07-31 22:39:40 -07004262 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004263 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004264
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004265 if (unlikely(!skb)) {
4266 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004267 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004268 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004269
4270 /* Make buffer alignment 2 beyond a 16 byte boundary
4271 * this will result in a 16 byte aligned IP header after
4272 * the 14 byte MAC header is removed
4273 */
4274 skb_reserve(skb, NET_IP_ALIGN);
4275
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004276 buffer_info->skb = skb;
4277 buffer_info->length = adapter->rx_ps_bsize0;
4278 buffer_info->dma = pci_map_single(pdev, skb->data,
4279 adapter->rx_ps_bsize0,
4280 PCI_DMA_FROMDEVICE);
4281
4282 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4283
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004284 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004285 buffer_info = &rx_ring->buffer_info[i];
4286 ps_page = &rx_ring->ps_page[i];
4287 ps_page_dma = &rx_ring->ps_page_dma[i];
4288 }
4289
4290no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004291 if (likely(rx_ring->next_to_use != i)) {
4292 rx_ring->next_to_use = i;
4293 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4294
4295 /* Force memory writes to complete before letting h/w
4296 * know there are new descriptors to fetch. (Only
4297 * applicable for weak-ordered memory model archs,
4298 * such as IA-64). */
4299 wmb();
4300 /* Hardware increments by 16 bytes, but packet split
4301 * descriptors are 32 bytes...so we increment tail
4302 * twice as much.
4303 */
4304 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4305 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004306}
4307
4308/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4310 * @adapter:
4311 **/
4312
4313static void
4314e1000_smartspeed(struct e1000_adapter *adapter)
4315{
4316 uint16_t phy_status;
4317 uint16_t phy_ctrl;
4318
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004319 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4321 return;
4322
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004323 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 /* If Master/Slave config fault is asserted twice,
4325 * we assume back-to-back */
4326 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004327 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004329 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004331 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4333 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4334 phy_ctrl);
4335 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004336 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4338 &phy_ctrl)) {
4339 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4340 MII_CR_RESTART_AUTO_NEG);
4341 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4342 phy_ctrl);
4343 }
4344 }
4345 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004346 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 /* If still no link, perhaps using 2/3 pair cable */
4348 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4349 phy_ctrl |= CR_1000T_MS_ENABLE;
4350 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004351 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4353 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4354 MII_CR_RESTART_AUTO_NEG);
4355 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4356 }
4357 }
4358 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004359 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 adapter->smartspeed = 0;
4361}
4362
4363/**
4364 * e1000_ioctl -
4365 * @netdev:
4366 * @ifreq:
4367 * @cmd:
4368 **/
4369
4370static int
4371e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4372{
4373 switch (cmd) {
4374 case SIOCGMIIPHY:
4375 case SIOCGMIIREG:
4376 case SIOCSMIIREG:
4377 return e1000_mii_ioctl(netdev, ifr, cmd);
4378 default:
4379 return -EOPNOTSUPP;
4380 }
4381}
4382
4383/**
4384 * e1000_mii_ioctl -
4385 * @netdev:
4386 * @ifreq:
4387 * @cmd:
4388 **/
4389
4390static int
4391e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4392{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004393 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 struct mii_ioctl_data *data = if_mii(ifr);
4395 int retval;
4396 uint16_t mii_reg;
4397 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004398 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004400 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 return -EOPNOTSUPP;
4402
4403 switch (cmd) {
4404 case SIOCGMIIPHY:
4405 data->phy_id = adapter->hw.phy_addr;
4406 break;
4407 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004408 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004410 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004411 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004412 &data->val_out)) {
4413 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004415 }
4416 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 break;
4418 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004419 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004421 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 return -EFAULT;
4423 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004424 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004425 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004426 mii_reg)) {
4427 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004429 }
Auke Kokdc86d322006-04-18 12:30:51 -07004430 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 switch (data->reg_num) {
4432 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004433 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004435 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 adapter->hw.autoneg = 1;
4437 adapter->hw.autoneg_advertised = 0x2F;
4438 } else {
4439 if (mii_reg & 0x40)
4440 spddplx = SPEED_1000;
4441 else if (mii_reg & 0x2000)
4442 spddplx = SPEED_100;
4443 else
4444 spddplx = SPEED_10;
4445 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004446 ? DUPLEX_FULL :
4447 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 retval = e1000_set_spd_dplx(adapter,
4449 spddplx);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004450 if (retval) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004451 spin_unlock_irqrestore(
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004452 &adapter->stats_lock,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004453 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456 }
Auke Kok2db10a02006-06-27 09:06:28 -07004457 if (netif_running(adapter->netdev))
4458 e1000_reinit_locked(adapter);
4459 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 e1000_reset(adapter);
4461 break;
4462 case M88E1000_PHY_SPEC_CTRL:
4463 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004464 if (e1000_phy_reset(&adapter->hw)) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004465 spin_unlock_irqrestore(
4466 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 break;
4470 }
4471 } else {
4472 switch (data->reg_num) {
4473 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004474 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004476 if (netif_running(adapter->netdev))
4477 e1000_reinit_locked(adapter);
4478 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 e1000_reset(adapter);
4480 break;
4481 }
4482 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004483 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484 break;
4485 default:
4486 return -EOPNOTSUPP;
4487 }
4488 return E1000_SUCCESS;
4489}
4490
4491void
4492e1000_pci_set_mwi(struct e1000_hw *hw)
4493{
4494 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004495 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004497 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004498 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499}
4500
4501void
4502e1000_pci_clear_mwi(struct e1000_hw *hw)
4503{
4504 struct e1000_adapter *adapter = hw->back;
4505
4506 pci_clear_mwi(adapter->pdev);
4507}
4508
4509void
4510e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4511{
4512 struct e1000_adapter *adapter = hw->back;
4513
4514 pci_read_config_word(adapter->pdev, reg, value);
4515}
4516
4517void
4518e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4519{
4520 struct e1000_adapter *adapter = hw->back;
4521
4522 pci_write_config_word(adapter->pdev, reg, *value);
4523}
4524
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004525int32_t
4526e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4527{
4528 struct e1000_adapter *adapter = hw->back;
4529 uint16_t cap_offset;
4530
4531 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4532 if (!cap_offset)
4533 return -E1000_ERR_CONFIG;
4534
4535 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4536
4537 return E1000_SUCCESS;
4538}
4539
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540void
4541e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4542{
4543 outl(value, port);
4544}
4545
4546static void
4547e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4548{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004549 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004550 uint32_t ctrl, rctl;
4551
4552 e1000_irq_disable(adapter);
4553 adapter->vlgrp = grp;
4554
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004555 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 /* enable VLAN tag insert/strip */
4557 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4558 ctrl |= E1000_CTRL_VME;
4559 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4560
Auke Kokcd94dd02006-06-27 09:08:22 -07004561 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004562 /* enable VLAN receive filtering */
4563 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4564 rctl |= E1000_RCTL_VFE;
4565 rctl &= ~E1000_RCTL_CFIEN;
4566 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4567 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569 } else {
4570 /* disable VLAN tag insert/strip */
4571 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4572 ctrl &= ~E1000_CTRL_VME;
4573 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4574
Auke Kokcd94dd02006-06-27 09:08:22 -07004575 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004576 /* disable VLAN filtering */
4577 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4578 rctl &= ~E1000_RCTL_VFE;
4579 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4580 if (adapter->mng_vlan_id !=
4581 (uint16_t)E1000_MNG_VLAN_NONE) {
4582 e1000_vlan_rx_kill_vid(netdev,
4583 adapter->mng_vlan_id);
4584 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4585 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 }
4588
4589 e1000_irq_enable(adapter);
4590}
4591
4592static void
4593e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4594{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004595 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004597
4598 if ((adapter->hw.mng_cookie.status &
4599 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4600 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004601 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602 /* add VID to filter table */
4603 index = (vid >> 5) & 0x7F;
4604 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4605 vfta |= (1 << (vid & 0x1F));
4606 e1000_write_vfta(&adapter->hw, index, vfta);
4607}
4608
4609static void
4610e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4611{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004612 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 uint32_t vfta, index;
4614
4615 e1000_irq_disable(adapter);
4616
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004617 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 adapter->vlgrp->vlan_devices[vid] = NULL;
4619
4620 e1000_irq_enable(adapter);
4621
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004622 if ((adapter->hw.mng_cookie.status &
4623 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004624 (vid == adapter->mng_vlan_id)) {
4625 /* release control to f/w */
4626 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004627 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004628 }
4629
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630 /* remove VID from filter table */
4631 index = (vid >> 5) & 0x7F;
4632 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4633 vfta &= ~(1 << (vid & 0x1F));
4634 e1000_write_vfta(&adapter->hw, index, vfta);
4635}
4636
4637static void
4638e1000_restore_vlan(struct e1000_adapter *adapter)
4639{
4640 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4641
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004642 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004644 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4645 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 continue;
4647 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4648 }
4649 }
4650}
4651
4652int
4653e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4654{
4655 adapter->hw.autoneg = 0;
4656
Malli Chilakala69213682005-06-17 17:44:20 -07004657 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004658 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004659 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4660 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4661 return -EINVAL;
4662 }
4663
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004664 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 case SPEED_10 + DUPLEX_HALF:
4666 adapter->hw.forced_speed_duplex = e1000_10_half;
4667 break;
4668 case SPEED_10 + DUPLEX_FULL:
4669 adapter->hw.forced_speed_duplex = e1000_10_full;
4670 break;
4671 case SPEED_100 + DUPLEX_HALF:
4672 adapter->hw.forced_speed_duplex = e1000_100_half;
4673 break;
4674 case SPEED_100 + DUPLEX_FULL:
4675 adapter->hw.forced_speed_duplex = e1000_100_full;
4676 break;
4677 case SPEED_1000 + DUPLEX_FULL:
4678 adapter->hw.autoneg = 1;
4679 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4680 break;
4681 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4682 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004683 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 return -EINVAL;
4685 }
4686 return 0;
4687}
4688
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004689#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004690/* Save/restore 16 or 64 dwords of PCI config space depending on which
4691 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004692 */
4693#define PCIE_CONFIG_SPACE_LEN 256
4694#define PCI_CONFIG_SPACE_LEN 64
4695static int
4696e1000_pci_save_state(struct e1000_adapter *adapter)
4697{
4698 struct pci_dev *dev = adapter->pdev;
4699 int size;
4700 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004701
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004702 if (adapter->hw.mac_type >= e1000_82571)
4703 size = PCIE_CONFIG_SPACE_LEN;
4704 else
4705 size = PCI_CONFIG_SPACE_LEN;
4706
4707 WARN_ON(adapter->config_space != NULL);
4708
4709 adapter->config_space = kmalloc(size, GFP_KERNEL);
4710 if (!adapter->config_space) {
4711 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4712 return -ENOMEM;
4713 }
4714 for (i = 0; i < (size / 4); i++)
4715 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4716 return 0;
4717}
4718
4719static void
4720e1000_pci_restore_state(struct e1000_adapter *adapter)
4721{
4722 struct pci_dev *dev = adapter->pdev;
4723 int size;
4724 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004725
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004726 if (adapter->config_space == NULL)
4727 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004728
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004729 if (adapter->hw.mac_type >= e1000_82571)
4730 size = PCIE_CONFIG_SPACE_LEN;
4731 else
4732 size = PCI_CONFIG_SPACE_LEN;
4733 for (i = 0; i < (size / 4); i++)
4734 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4735 kfree(adapter->config_space);
4736 adapter->config_space = NULL;
4737 return;
4738}
4739#endif /* CONFIG_PM */
4740
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004742e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743{
4744 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004745 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004746 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07004748#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08004749 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07004750#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751
4752 netif_device_detach(netdev);
4753
Auke Kok2db10a02006-06-27 09:06:28 -07004754 if (netif_running(netdev)) {
4755 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07004757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004759#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004760 /* Implement our own version of pci_save_state(pdev) because pci-
4761 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004762 retval = e1000_pci_save_state(adapter);
4763 if (retval)
4764 return retval;
4765#endif
4766
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004768 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 wufc &= ~E1000_WUFC_LNKC;
4770
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004771 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 e1000_setup_rctl(adapter);
4773 e1000_set_multi(netdev);
4774
4775 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07004776 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4778 rctl |= E1000_RCTL_MPE;
4779 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4780 }
4781
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004782 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4784 /* advertise wake from D3Cold */
4785 #define E1000_CTRL_ADVD3WUC 0x00100000
4786 /* phy power management enable */
4787 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4788 ctrl |= E1000_CTRL_ADVD3WUC |
4789 E1000_CTRL_EN_PHY_PWR_MGMT;
4790 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4791 }
4792
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004793 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4795 /* keep the laser running in D3 */
4796 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4797 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4798 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4799 }
4800
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004801 /* Allow time for pending master requests to run */
4802 e1000_disable_pciex_master(&adapter->hw);
4803
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4805 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004806 pci_enable_wake(pdev, PCI_D3hot, 1);
4807 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 } else {
4809 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4810 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07004811 pci_enable_wake(pdev, PCI_D3hot, 0);
4812 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 }
4814
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004815 if (adapter->hw.mac_type >= e1000_82540 &&
4816 adapter->hw.mac_type < e1000_82571 &&
4817 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004819 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 manc |= E1000_MANC_ARP_EN;
4821 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004822 pci_enable_wake(pdev, PCI_D3hot, 1);
4823 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824 }
4825 }
4826
Auke Kokcd94dd02006-06-27 09:08:22 -07004827 if (adapter->hw.phy_type == e1000_phy_igp_3)
4828 e1000_phy_powerdown_workaround(&adapter->hw);
4829
Auke Kokedd106f2006-11-06 08:57:12 -08004830 if (netif_running(netdev))
4831 e1000_free_irq(adapter);
4832
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004833 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4834 * would have already happened in close and is redundant. */
4835 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004836
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004838
Auke Kokd0e027d2006-04-14 19:04:40 -07004839 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840
4841 return 0;
4842}
4843
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004844#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845static int
4846e1000_resume(struct pci_dev *pdev)
4847{
4848 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004849 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004850 uint32_t manc, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851
Auke Kokd0e027d2006-04-14 19:04:40 -07004852 pci_set_power_state(pdev, PCI_D0);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004853 e1000_pci_restore_state(adapter);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004854 if ((err = pci_enable_device(pdev))) {
4855 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
4856 return err;
4857 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004858 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859
Auke Kokd0e027d2006-04-14 19:04:40 -07004860 pci_enable_wake(pdev, PCI_D3hot, 0);
4861 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862
Auke Kokedd106f2006-11-06 08:57:12 -08004863 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
4864 return err;
4865
4866 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 e1000_reset(adapter);
4868 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4869
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004870 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871 e1000_up(adapter);
4872
4873 netif_device_attach(netdev);
4874
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004875 if (adapter->hw.mac_type >= e1000_82540 &&
4876 adapter->hw.mac_type < e1000_82571 &&
4877 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 manc = E1000_READ_REG(&adapter->hw, MANC);
4879 manc &= ~(E1000_MANC_ARP_EN);
4880 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4881 }
4882
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004883 /* If the controller is 82573 and f/w is AMT, do not set
4884 * DRV_LOAD until the interface is up. For all other cases,
4885 * let the f/w know that the h/w is now under the control
4886 * of the driver. */
4887 if (adapter->hw.mac_type != e1000_82573 ||
4888 !e1000_check_mng_mode(&adapter->hw))
4889 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004890
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 return 0;
4892}
4893#endif
Auke Kokc653e632006-05-23 13:35:57 -07004894
4895static void e1000_shutdown(struct pci_dev *pdev)
4896{
4897 e1000_suspend(pdev, PMSG_SUSPEND);
4898}
4899
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900#ifdef CONFIG_NET_POLL_CONTROLLER
4901/*
4902 * Polling 'interrupt' - used by things like netconsole to send skbs
4903 * without having to re-enable interrupts. It's not called while
4904 * the interrupt routine is executing.
4905 */
4906static void
Malli Chilakala26483452005-04-28 19:44:46 -07004907e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004909 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07004910
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01004912 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004913 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004914#ifndef CONFIG_E1000_NAPI
4915 adapter->clean_rx(adapter, adapter->rx_ring);
4916#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 enable_irq(adapter->pdev->irq);
4918}
4919#endif
4920
Auke Kok90267292006-06-08 09:30:24 -07004921/**
4922 * e1000_io_error_detected - called when PCI error is detected
4923 * @pdev: Pointer to PCI device
4924 * @state: The current pci conneection state
4925 *
4926 * This function is called after a PCI bus error affecting
4927 * this device has been detected.
4928 */
4929static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4930{
4931 struct net_device *netdev = pci_get_drvdata(pdev);
4932 struct e1000_adapter *adapter = netdev->priv;
4933
4934 netif_device_detach(netdev);
4935
4936 if (netif_running(netdev))
4937 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07004938 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07004939
4940 /* Request a slot slot reset. */
4941 return PCI_ERS_RESULT_NEED_RESET;
4942}
4943
4944/**
4945 * e1000_io_slot_reset - called after the pci bus has been reset.
4946 * @pdev: Pointer to PCI device
4947 *
4948 * Restart the card from scratch, as if from a cold-boot. Implementation
4949 * resembles the first-half of the e1000_resume routine.
4950 */
4951static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4952{
4953 struct net_device *netdev = pci_get_drvdata(pdev);
4954 struct e1000_adapter *adapter = netdev->priv;
4955
4956 if (pci_enable_device(pdev)) {
4957 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4958 return PCI_ERS_RESULT_DISCONNECT;
4959 }
4960 pci_set_master(pdev);
4961
Linas Vepstasdbf38c92006-09-27 12:54:11 -07004962 pci_enable_wake(pdev, PCI_D3hot, 0);
4963 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07004964
Auke Kok90267292006-06-08 09:30:24 -07004965 e1000_reset(adapter);
4966 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4967
4968 return PCI_ERS_RESULT_RECOVERED;
4969}
4970
4971/**
4972 * e1000_io_resume - called when traffic can start flowing again.
4973 * @pdev: Pointer to PCI device
4974 *
4975 * This callback is called when the error recovery driver tells us that
4976 * its OK to resume normal operation. Implementation resembles the
4977 * second-half of the e1000_resume routine.
4978 */
4979static void e1000_io_resume(struct pci_dev *pdev)
4980{
4981 struct net_device *netdev = pci_get_drvdata(pdev);
4982 struct e1000_adapter *adapter = netdev->priv;
4983 uint32_t manc, swsm;
4984
4985 if (netif_running(netdev)) {
4986 if (e1000_up(adapter)) {
4987 printk("e1000: can't bring device back up after reset\n");
4988 return;
4989 }
4990 }
4991
4992 netif_device_attach(netdev);
4993
4994 if (adapter->hw.mac_type >= e1000_82540 &&
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004995 adapter->hw.mac_type < e1000_82571 &&
Auke Kok90267292006-06-08 09:30:24 -07004996 adapter->hw.media_type == e1000_media_type_copper) {
4997 manc = E1000_READ_REG(&adapter->hw, MANC);
4998 manc &= ~(E1000_MANC_ARP_EN);
4999 E1000_WRITE_REG(&adapter->hw, MANC, manc);
5000 }
5001
5002 switch (adapter->hw.mac_type) {
5003 case e1000_82573:
5004 swsm = E1000_READ_REG(&adapter->hw, SWSM);
5005 E1000_WRITE_REG(&adapter->hw, SWSM,
5006 swsm | E1000_SWSM_DRV_LOAD);
5007 break;
5008 default:
5009 break;
5010 }
5011
5012 if (netif_running(netdev))
5013 mod_timer(&adapter->watchdog_timer, jiffies);
5014}
5015
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016/* e1000_main.c */