blob: 96e44a825443ef7fb795fd42e69af75f6cdf4b57 [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 */
1583 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1584 E1000_TXD_CMD_IFCS;
1585
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001586 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1588 else
1589 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1590
1591 /* Cache if we're 82544 running in PCI-X because we'll
1592 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001593 if (hw->mac_type == e1000_82544 &&
1594 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001596
1597 E1000_WRITE_REG(hw, TCTL, tctl);
1598
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599}
1600
1601/**
1602 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1603 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001604 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 *
1606 * Returns 0 on success, negative on failure
1607 **/
1608
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001609static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001610e1000_setup_rx_resources(struct e1000_adapter *adapter,
1611 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001614 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
1616 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001617 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001618 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001619 DPRINTK(PROBE, ERR,
1620 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 return -ENOMEM;
1622 }
1623 memset(rxdr->buffer_info, 0, size);
1624
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001625 size = sizeof(struct e1000_ps_page) * rxdr->count;
1626 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001627 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001628 vfree(rxdr->buffer_info);
1629 DPRINTK(PROBE, ERR,
1630 "Unable to allocate memory for the receive descriptor ring\n");
1631 return -ENOMEM;
1632 }
1633 memset(rxdr->ps_page, 0, size);
1634
1635 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1636 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001637 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001638 vfree(rxdr->buffer_info);
1639 kfree(rxdr->ps_page);
1640 DPRINTK(PROBE, ERR,
1641 "Unable to allocate memory for the receive descriptor ring\n");
1642 return -ENOMEM;
1643 }
1644 memset(rxdr->ps_page_dma, 0, size);
1645
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001646 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001647 desc_len = sizeof(struct e1000_rx_desc);
1648 else
1649 desc_len = sizeof(union e1000_rx_desc_packet_split);
1650
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 /* Round up to nearest 4K */
1652
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001653 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 E1000_ROUNDUP(rxdr->size, 4096);
1655
1656 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1657
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001658 if (!rxdr->desc) {
1659 DPRINTK(PROBE, ERR,
1660 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001663 kfree(rxdr->ps_page);
1664 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 return -ENOMEM;
1666 }
1667
Malli Chilakala26483452005-04-28 19:44:46 -07001668 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1670 void *olddesc = rxdr->desc;
1671 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001672 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1673 "at %p\n", rxdr->size, rxdr->desc);
1674 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001676 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001677 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001679 DPRINTK(PROBE, ERR,
1680 "Unable to allocate memory "
1681 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 goto setup_rx_desc_die;
1683 }
1684
1685 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1686 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001687 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1688 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001690 DPRINTK(PROBE, ERR,
1691 "Unable to allocate aligned memory "
1692 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001693 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001695 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1697 }
1698 }
1699 memset(rxdr->desc, 0, rxdr->size);
1700
1701 rxdr->next_to_clean = 0;
1702 rxdr->next_to_use = 0;
1703
1704 return 0;
1705}
1706
1707/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001708 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1709 * (Descriptors) for all queues
1710 * @adapter: board private structure
1711 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001712 * Return 0 on success, negative on failure
1713 **/
1714
1715int
1716e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1717{
1718 int i, err = 0;
1719
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001720 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001721 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1722 if (err) {
1723 DPRINTK(PROBE, ERR,
1724 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001725 for (i-- ; i >= 0; i--)
1726 e1000_free_rx_resources(adapter,
1727 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001728 break;
1729 }
1730 }
1731
1732 return err;
1733}
1734
1735/**
Malli Chilakala26483452005-04-28 19:44:46 -07001736 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 * @adapter: Board private structure
1738 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001739#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1740 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741static void
1742e1000_setup_rctl(struct e1000_adapter *adapter)
1743{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001744 uint32_t rctl, rfctl;
1745 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001746#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001747 uint32_t pages = 0;
1748#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1751
1752 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1753
1754 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1755 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1756 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1757
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001758 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 rctl |= E1000_RCTL_SBP;
1760 else
1761 rctl &= ~E1000_RCTL_SBP;
1762
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001763 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1764 rctl &= ~E1000_RCTL_LPE;
1765 else
1766 rctl |= E1000_RCTL_LPE;
1767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001769 rctl &= ~E1000_RCTL_SZ_4096;
1770 rctl |= E1000_RCTL_BSEX;
1771 switch (adapter->rx_buffer_len) {
1772 case E1000_RXBUFFER_256:
1773 rctl |= E1000_RCTL_SZ_256;
1774 rctl &= ~E1000_RCTL_BSEX;
1775 break;
1776 case E1000_RXBUFFER_512:
1777 rctl |= E1000_RCTL_SZ_512;
1778 rctl &= ~E1000_RCTL_BSEX;
1779 break;
1780 case E1000_RXBUFFER_1024:
1781 rctl |= E1000_RCTL_SZ_1024;
1782 rctl &= ~E1000_RCTL_BSEX;
1783 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001784 case E1000_RXBUFFER_2048:
1785 default:
1786 rctl |= E1000_RCTL_SZ_2048;
1787 rctl &= ~E1000_RCTL_BSEX;
1788 break;
1789 case E1000_RXBUFFER_4096:
1790 rctl |= E1000_RCTL_SZ_4096;
1791 break;
1792 case E1000_RXBUFFER_8192:
1793 rctl |= E1000_RCTL_SZ_8192;
1794 break;
1795 case E1000_RXBUFFER_16384:
1796 rctl |= E1000_RCTL_SZ_16384;
1797 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001798 }
1799
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001800#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001801 /* 82571 and greater support packet-split where the protocol
1802 * header is placed in skb->data and the packet data is
1803 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1804 * In the case of a non-split, skb->data is linearly filled,
1805 * followed by the page buffers. Therefore, skb->data is
1806 * sized to hold the largest protocol header.
1807 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001808 /* allocations using alloc_page take too long for regular MTU
1809 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001810 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001811 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1812 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001813 adapter->rx_ps_pages = pages;
1814 else
1815 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001816#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001817 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001818 /* Configure extra packet-split registers */
1819 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1820 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08001821 /* disable packet split support for IPv6 extension headers,
1822 * because some malformed IPv6 headers can hang the RX */
1823 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1824 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1825
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001826 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1827
Auke Kok7dfee0c2006-06-27 09:07:50 -07001828 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001829
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001830 psrctl |= adapter->rx_ps_bsize0 >>
1831 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001832
1833 switch (adapter->rx_ps_pages) {
1834 case 3:
1835 psrctl |= PAGE_SIZE <<
1836 E1000_PSRCTL_BSIZE3_SHIFT;
1837 case 2:
1838 psrctl |= PAGE_SIZE <<
1839 E1000_PSRCTL_BSIZE2_SHIFT;
1840 case 1:
1841 psrctl |= PAGE_SIZE >>
1842 E1000_PSRCTL_BSIZE1_SHIFT;
1843 break;
1844 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001845
1846 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 }
1848
1849 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1850}
1851
1852/**
1853 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1854 * @adapter: board private structure
1855 *
1856 * Configure the Rx unit of the MAC after a reset.
1857 **/
1858
1859static void
1860e1000_configure_rx(struct e1000_adapter *adapter)
1861{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001862 uint64_t rdba;
1863 struct e1000_hw *hw = &adapter->hw;
1864 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001865
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001866 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001867 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001868 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001869 sizeof(union e1000_rx_desc_packet_split);
1870 adapter->clean_rx = e1000_clean_rx_irq_ps;
1871 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1872 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001873 rdlen = adapter->rx_ring[0].count *
1874 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001875 adapter->clean_rx = e1000_clean_rx_irq;
1876 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1877 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
1879 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001880 rctl = E1000_READ_REG(hw, RCTL);
1881 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
1883 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001884 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001886 if (hw->mac_type >= e1000_82540) {
1887 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001888 if (adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001889 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 1000000000 / (adapter->itr * 256));
1891 }
1892
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001893 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001894 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001895 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07001896 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001897#ifdef CONFIG_E1000_NAPI
1898 /* Auto-Mask interrupts upon ICR read. */
1899 ctrl_ext |= E1000_CTRL_EXT_IAME;
1900#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001901 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001902 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001903 E1000_WRITE_FLUSH(hw);
1904 }
1905
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001906 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1907 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001908 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001909 case 1:
1910 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001911 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001912 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001913 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1914 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001915 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001916 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001917 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
1918 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001919 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001920 }
1921
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001923 if (hw->mac_type >= e1000_82543) {
1924 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001925 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001926 rxcsum |= E1000_RXCSUM_TUOFL;
1927
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001928 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001929 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001930 if ((hw->mac_type >= e1000_82571) &&
1931 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001932 rxcsum |= E1000_RXCSUM_IPPCSE;
1933 }
1934 } else {
1935 rxcsum &= ~E1000_RXCSUM_TUOFL;
1936 /* don't need to clear IPPCSE as it defaults to 0 */
1937 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001938 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 }
1940
Auke Kok21c4d5e2006-11-01 08:47:39 -08001941 /* enable early receives on 82573, only takes effect if using > 2048
1942 * byte total frame size. for example only for jumbo frames */
1943#define E1000_ERT_2048 0x100
1944 if (hw->mac_type == e1000_82573)
1945 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
1946
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001948 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949}
1950
1951/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001952 * e1000_free_tx_resources - Free Tx Resources per Queue
1953 * @adapter: board private structure
1954 * @tx_ring: Tx descriptor ring for a specific queue
1955 *
1956 * Free all transmit software resources
1957 **/
1958
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001959static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001960e1000_free_tx_resources(struct e1000_adapter *adapter,
1961 struct e1000_tx_ring *tx_ring)
1962{
1963 struct pci_dev *pdev = adapter->pdev;
1964
1965 e1000_clean_tx_ring(adapter, tx_ring);
1966
1967 vfree(tx_ring->buffer_info);
1968 tx_ring->buffer_info = NULL;
1969
1970 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1971
1972 tx_ring->desc = NULL;
1973}
1974
1975/**
1976 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 * @adapter: board private structure
1978 *
1979 * Free all transmit software resources
1980 **/
1981
1982void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001983e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001985 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001987 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001988 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989}
1990
Auke Koke619d522006-04-14 19:04:52 -07001991static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1993 struct e1000_buffer *buffer_info)
1994{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001995 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001996 pci_unmap_page(adapter->pdev,
1997 buffer_info->dma,
1998 buffer_info->length,
1999 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002000 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002002 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002004 buffer_info->skb = NULL;
2005 }
2006 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007}
2008
2009/**
2010 * e1000_clean_tx_ring - Free Tx Buffers
2011 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002012 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 **/
2014
2015static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002016e1000_clean_tx_ring(struct e1000_adapter *adapter,
2017 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 struct e1000_buffer *buffer_info;
2020 unsigned long size;
2021 unsigned int i;
2022
2023 /* Free all the Tx ring sk_buffs */
2024
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002025 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 buffer_info = &tx_ring->buffer_info[i];
2027 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2028 }
2029
2030 size = sizeof(struct e1000_buffer) * tx_ring->count;
2031 memset(tx_ring->buffer_info, 0, size);
2032
2033 /* Zero out the descriptor ring */
2034
2035 memset(tx_ring->desc, 0, tx_ring->size);
2036
2037 tx_ring->next_to_use = 0;
2038 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002039 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002041 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2042 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2043}
2044
2045/**
2046 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2047 * @adapter: board private structure
2048 **/
2049
2050static void
2051e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2052{
2053 int i;
2054
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002055 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002056 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
2059/**
2060 * e1000_free_rx_resources - Free Rx Resources
2061 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002062 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 *
2064 * Free all receive software resources
2065 **/
2066
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002067static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002068e1000_free_rx_resources(struct e1000_adapter *adapter,
2069 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct pci_dev *pdev = adapter->pdev;
2072
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002073 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
2075 vfree(rx_ring->buffer_info);
2076 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002077 kfree(rx_ring->ps_page);
2078 rx_ring->ps_page = NULL;
2079 kfree(rx_ring->ps_page_dma);
2080 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
2082 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2083
2084 rx_ring->desc = NULL;
2085}
2086
2087/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002088 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002090 *
2091 * Free all receive software resources
2092 **/
2093
2094void
2095e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2096{
2097 int i;
2098
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002099 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002100 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2101}
2102
2103/**
2104 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2105 * @adapter: board private structure
2106 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 **/
2108
2109static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002110e1000_clean_rx_ring(struct e1000_adapter *adapter,
2111 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002114 struct e1000_ps_page *ps_page;
2115 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 struct pci_dev *pdev = adapter->pdev;
2117 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002118 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
2120 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002121 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002123 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 pci_unmap_single(pdev,
2125 buffer_info->dma,
2126 buffer_info->length,
2127 PCI_DMA_FROMDEVICE);
2128
2129 dev_kfree_skb(buffer_info->skb);
2130 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002131 }
2132 ps_page = &rx_ring->ps_page[i];
2133 ps_page_dma = &rx_ring->ps_page_dma[i];
2134 for (j = 0; j < adapter->rx_ps_pages; j++) {
2135 if (!ps_page->ps_page[j]) break;
2136 pci_unmap_page(pdev,
2137 ps_page_dma->ps_page_dma[j],
2138 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2139 ps_page_dma->ps_page_dma[j] = 0;
2140 put_page(ps_page->ps_page[j]);
2141 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 }
2143 }
2144
2145 size = sizeof(struct e1000_buffer) * rx_ring->count;
2146 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002147 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2148 memset(rx_ring->ps_page, 0, size);
2149 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2150 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
2152 /* Zero out the descriptor ring */
2153
2154 memset(rx_ring->desc, 0, rx_ring->size);
2155
2156 rx_ring->next_to_clean = 0;
2157 rx_ring->next_to_use = 0;
2158
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002159 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2160 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2161}
2162
2163/**
2164 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2165 * @adapter: board private structure
2166 **/
2167
2168static void
2169e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2170{
2171 int i;
2172
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002173 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002174 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175}
2176
2177/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2178 * and memory write and invalidate disabled for certain operations
2179 */
2180static void
2181e1000_enter_82542_rst(struct e1000_adapter *adapter)
2182{
2183 struct net_device *netdev = adapter->netdev;
2184 uint32_t rctl;
2185
2186 e1000_pci_clear_mwi(&adapter->hw);
2187
2188 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2189 rctl |= E1000_RCTL_RST;
2190 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2191 E1000_WRITE_FLUSH(&adapter->hw);
2192 mdelay(5);
2193
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002194 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002195 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196}
2197
2198static void
2199e1000_leave_82542_rst(struct e1000_adapter *adapter)
2200{
2201 struct net_device *netdev = adapter->netdev;
2202 uint32_t rctl;
2203
2204 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2205 rctl &= ~E1000_RCTL_RST;
2206 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2207 E1000_WRITE_FLUSH(&adapter->hw);
2208 mdelay(5);
2209
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002210 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 e1000_pci_set_mwi(&adapter->hw);
2212
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002213 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002214 /* No need to loop, because 82542 supports only 1 queue */
2215 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002216 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002217 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 }
2219}
2220
2221/**
2222 * e1000_set_mac - Change the Ethernet Address of the NIC
2223 * @netdev: network interface device structure
2224 * @p: pointer to an address structure
2225 *
2226 * Returns 0 on success, negative on failure
2227 **/
2228
2229static int
2230e1000_set_mac(struct net_device *netdev, void *p)
2231{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002232 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 struct sockaddr *addr = p;
2234
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002235 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 return -EADDRNOTAVAIL;
2237
2238 /* 82542 2.0 needs to be in reset to write receive address registers */
2239
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002240 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 e1000_enter_82542_rst(adapter);
2242
2243 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2244 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2245
2246 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2247
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002248 /* With 82571 controllers, LAA may be overwritten (with the default)
2249 * due to controller reset from the other port. */
2250 if (adapter->hw.mac_type == e1000_82571) {
2251 /* activate the work around */
2252 adapter->hw.laa_is_present = 1;
2253
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002254 /* Hold a copy of the LAA in RAR[14] This is done so that
2255 * between the time RAR[0] gets clobbered and the time it
2256 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002257 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002258 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002259 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002260 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002261 E1000_RAR_ENTRIES - 1);
2262 }
2263
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002264 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 e1000_leave_82542_rst(adapter);
2266
2267 return 0;
2268}
2269
2270/**
2271 * e1000_set_multi - Multicast and Promiscuous mode set
2272 * @netdev: network interface device structure
2273 *
2274 * The set_multi entry point is called whenever the multicast address
2275 * list or the network interface flags are updated. This routine is
2276 * responsible for configuring the hardware for proper multicast,
2277 * promiscuous mode, and all-multi behavior.
2278 **/
2279
2280static void
2281e1000_set_multi(struct net_device *netdev)
2282{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002283 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 struct e1000_hw *hw = &adapter->hw;
2285 struct dev_mc_list *mc_ptr;
2286 uint32_t rctl;
2287 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002288 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002289 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2290 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2291 E1000_NUM_MTA_REGISTERS;
2292
2293 if (adapter->hw.mac_type == e1000_ich8lan)
2294 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002296 /* reserve RAR[14] for LAA over-write work-around */
2297 if (adapter->hw.mac_type == e1000_82571)
2298 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
Malli Chilakala26483452005-04-28 19:44:46 -07002300 /* Check for Promiscuous and All Multicast modes */
2301
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 rctl = E1000_READ_REG(hw, RCTL);
2303
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002304 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002306 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 rctl |= E1000_RCTL_MPE;
2308 rctl &= ~E1000_RCTL_UPE;
2309 } else {
2310 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2311 }
2312
2313 E1000_WRITE_REG(hw, RCTL, rctl);
2314
2315 /* 82542 2.0 needs to be in reset to write receive address registers */
2316
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002317 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 e1000_enter_82542_rst(adapter);
2319
2320 /* load the first 14 multicast address into the exact filters 1-14
2321 * RAR 0 is used for the station MAC adddress
2322 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002323 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 */
2325 mc_ptr = netdev->mc_list;
2326
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002327 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002328 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2330 mc_ptr = mc_ptr->next;
2331 } else {
2332 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002333 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002335 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 }
2337 }
2338
2339 /* clear the old settings from the multicast hash table */
2340
Auke Kokcd94dd02006-06-27 09:08:22 -07002341 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002343 E1000_WRITE_FLUSH(hw);
2344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
2346 /* load any remaining addresses into the hash table */
2347
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002348 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2350 e1000_mta_set(hw, hash_value);
2351 }
2352
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002353 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355}
2356
2357/* Need to wait a few seconds after link up to get diagnostic information from
2358 * the phy */
2359
2360static void
2361e1000_update_phy_info(unsigned long data)
2362{
2363 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2364 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2365}
2366
2367/**
2368 * e1000_82547_tx_fifo_stall - Timer Call-back
2369 * @data: pointer to adapter cast into an unsigned long
2370 **/
2371
2372static void
2373e1000_82547_tx_fifo_stall(unsigned long data)
2374{
2375 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2376 struct net_device *netdev = adapter->netdev;
2377 uint32_t tctl;
2378
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002379 if (atomic_read(&adapter->tx_fifo_stall)) {
2380 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 E1000_READ_REG(&adapter->hw, TDH)) &&
2382 (E1000_READ_REG(&adapter->hw, TDFT) ==
2383 E1000_READ_REG(&adapter->hw, TDFH)) &&
2384 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2385 E1000_READ_REG(&adapter->hw, TDFHS))) {
2386 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2387 E1000_WRITE_REG(&adapter->hw, TCTL,
2388 tctl & ~E1000_TCTL_EN);
2389 E1000_WRITE_REG(&adapter->hw, TDFT,
2390 adapter->tx_head_addr);
2391 E1000_WRITE_REG(&adapter->hw, TDFH,
2392 adapter->tx_head_addr);
2393 E1000_WRITE_REG(&adapter->hw, TDFTS,
2394 adapter->tx_head_addr);
2395 E1000_WRITE_REG(&adapter->hw, TDFHS,
2396 adapter->tx_head_addr);
2397 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2398 E1000_WRITE_FLUSH(&adapter->hw);
2399
2400 adapter->tx_fifo_head = 0;
2401 atomic_set(&adapter->tx_fifo_stall, 0);
2402 netif_wake_queue(netdev);
2403 } else {
2404 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2405 }
2406 }
2407}
2408
2409/**
2410 * e1000_watchdog - Timer Call-back
2411 * @data: pointer to adapter cast into an unsigned long
2412 **/
2413static void
2414e1000_watchdog(unsigned long data)
2415{
2416 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002418 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002419 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002420 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
Auke Kokcd94dd02006-06-27 09:08:22 -07002422 ret_val = e1000_check_for_link(&adapter->hw);
2423 if ((ret_val == E1000_ERR_PHY) &&
2424 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2425 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2426 /* See e1000_kumeran_lock_loss_workaround() */
2427 DPRINTK(LINK, INFO,
2428 "Gigabit has been disabled, downgrading speed\n");
2429 }
Auke Kok90fb5132006-11-01 08:47:30 -08002430
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002431 if (adapter->hw.mac_type == e1000_82573) {
2432 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002433 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002434 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002437 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2439 link = !adapter->hw.serdes_link_down;
2440 else
2441 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2442
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002443 if (link) {
2444 if (!netif_carrier_ok(netdev)) {
Auke Kokfe7fe282006-04-14 19:04:59 -07002445 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 e1000_get_speed_and_duplex(&adapter->hw,
2447 &adapter->link_speed,
2448 &adapter->link_duplex);
2449
2450 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2451 adapter->link_speed,
2452 adapter->link_duplex == FULL_DUPLEX ?
2453 "Full Duplex" : "Half Duplex");
2454
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002455 /* tweak tx_queue_len according to speed/duplex
2456 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002457 netdev->tx_queue_len = adapter->tx_queue_len;
2458 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002459 switch (adapter->link_speed) {
2460 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002461 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002462 netdev->tx_queue_len = 10;
2463 adapter->tx_timeout_factor = 8;
2464 break;
2465 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002466 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002467 netdev->tx_queue_len = 100;
2468 /* maybe add some timeout factor ? */
2469 break;
2470 }
2471
Auke Kokfe7fe282006-04-14 19:04:59 -07002472 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002473 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002474 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002475 uint32_t tarc0;
2476 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002477 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002478 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2479 }
Auke Kok90fb5132006-11-01 08:47:30 -08002480
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002481#ifdef NETIF_F_TSO
2482 /* disable TSO for pcie and 10/100 speeds, to avoid
2483 * some hardware issues */
2484 if (!adapter->tso_force &&
2485 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002486 switch (adapter->link_speed) {
2487 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002488 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002489 DPRINTK(PROBE,INFO,
2490 "10/100 speed: disabling TSO\n");
2491 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002492#ifdef NETIF_F_TSO6
2493 netdev->features &= ~NETIF_F_TSO6;
2494#endif
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002495 break;
2496 case SPEED_1000:
2497 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002498#ifdef NETIF_F_TSO6
2499 netdev->features |= NETIF_F_TSO6;
2500#endif
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002501 break;
2502 default:
2503 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002504 break;
2505 }
2506 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002507#endif
2508
2509 /* enable transmits in the hardware, need to do this
2510 * after setting TARC0 */
2511 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2512 tctl |= E1000_TCTL_EN;
2513 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002514
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 netif_carrier_on(netdev);
2516 netif_wake_queue(netdev);
2517 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2518 adapter->smartspeed = 0;
2519 }
2520 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002521 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 adapter->link_speed = 0;
2523 adapter->link_duplex = 0;
2524 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2525 netif_carrier_off(netdev);
2526 netif_stop_queue(netdev);
2527 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002528
2529 /* 80003ES2LAN workaround--
2530 * For packet buffer work-around on link down event;
2531 * disable receives in the ISR and
2532 * reset device here in the watchdog
2533 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002534 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002535 /* reset device */
2536 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 }
2538
2539 e1000_smartspeed(adapter);
2540 }
2541
2542 e1000_update_stats(adapter);
2543
2544 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2545 adapter->tpt_old = adapter->stats.tpt;
2546 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2547 adapter->colc_old = adapter->stats.colc;
2548
2549 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2550 adapter->gorcl_old = adapter->stats.gorcl;
2551 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2552 adapter->gotcl_old = adapter->stats.gotcl;
2553
2554 e1000_update_adaptive(&adapter->hw);
2555
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002556 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002557 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 /* We've lost link, so the controller stops DMA,
2559 * but we've got queued Tx work that's never going
2560 * to get done, so reset controller to flush Tx.
2561 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002562 adapter->tx_timeout_count++;
2563 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 }
2565 }
2566
2567 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002568 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2570 * asymmetrical Tx or Rx gets ITR=8000; everyone
2571 * else is between 2000-8000. */
2572 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002573 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 adapter->gotcl - adapter->gorcl :
2575 adapter->gorcl - adapter->gotcl) / 10000;
2576 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2577 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2578 }
2579
2580 /* Cause software interrupt to ensure rx ring is cleaned */
2581 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2582
Malli Chilakala26483452005-04-28 19:44:46 -07002583 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 adapter->detect_tx_hung = TRUE;
2585
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002586 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002587 * reset from the other port. Set the appropriate LAA in RAR[0] */
2588 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2589 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2590
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 /* Reset the timer */
2592 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2593}
2594
2595#define E1000_TX_FLAGS_CSUM 0x00000001
2596#define E1000_TX_FLAGS_VLAN 0x00000002
2597#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002598#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2600#define E1000_TX_FLAGS_VLAN_SHIFT 16
2601
Auke Koke619d522006-04-14 19:04:52 -07002602static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002603e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2604 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605{
2606#ifdef NETIF_F_TSO
2607 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002608 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 unsigned int i;
2610 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002611 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2613 int err;
2614
Herbert Xu89114af2006-07-08 13:34:32 -07002615 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 if (skb_header_cloned(skb)) {
2617 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2618 if (err)
2619 return err;
2620 }
2621
2622 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Herbert Xu79671682006-06-22 02:40:14 -07002623 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002624 if (skb->protocol == htons(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002625 skb->nh.iph->tot_len = 0;
2626 skb->nh.iph->check = 0;
2627 skb->h.th->check =
2628 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2629 skb->nh.iph->daddr,
2630 0,
2631 IPPROTO_TCP,
2632 0);
2633 cmd_length = E1000_TXD_CMD_IP;
2634 ipcse = skb->h.raw - skb->data - 1;
Auke Kok87ca4e52006-11-01 08:47:36 -08002635#ifdef NETIF_F_TSO6
Auke Koke15fdd02006-08-16 11:28:45 -07002636 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002637 skb->nh.ipv6h->payload_len = 0;
2638 skb->h.th->check =
2639 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2640 &skb->nh.ipv6h->daddr,
2641 0,
2642 IPPROTO_TCP,
2643 0);
2644 ipcse = 0;
2645#endif
2646 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 ipcss = skb->nh.raw - skb->data;
2648 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 tucss = skb->h.raw - skb->data;
2650 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2651 tucse = 0;
2652
2653 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002654 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002656 i = tx_ring->next_to_use;
2657 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002658 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659
2660 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2661 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2662 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2663 context_desc->upper_setup.tcp_fields.tucss = tucss;
2664 context_desc->upper_setup.tcp_fields.tucso = tucso;
2665 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2666 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2667 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2668 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2669
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002670 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002671 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002672
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002673 if (++i == tx_ring->count) i = 0;
2674 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
Jeff Kirsher8241e352006-01-12 16:51:34 -08002676 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 }
2678#endif
2679
Jeff Kirsher8241e352006-01-12 16:51:34 -08002680 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681}
2682
Auke Koke619d522006-04-14 19:04:52 -07002683static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002684e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2685 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686{
2687 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002688 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 unsigned int i;
2690 uint8_t css;
2691
Patrick McHardy84fa7932006-08-29 16:44:56 -07002692 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 css = skb->h.raw - skb->data;
2694
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002695 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002696 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002697 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
2699 context_desc->upper_setup.tcp_fields.tucss = css;
2700 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2701 context_desc->upper_setup.tcp_fields.tucse = 0;
2702 context_desc->tcp_seg_setup.data = 0;
2703 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2704
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002705 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002706 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002707
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002708 if (unlikely(++i == tx_ring->count)) i = 0;
2709 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
2711 return TRUE;
2712 }
2713
2714 return FALSE;
2715}
2716
2717#define E1000_MAX_TXD_PWR 12
2718#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2719
Auke Koke619d522006-04-14 19:04:52 -07002720static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002721e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2722 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2723 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 struct e1000_buffer *buffer_info;
2726 unsigned int len = skb->len;
2727 unsigned int offset = 0, size, count = 0, i;
2728 unsigned int f;
2729 len -= skb->data_len;
2730
2731 i = tx_ring->next_to_use;
2732
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002733 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 buffer_info = &tx_ring->buffer_info[i];
2735 size = min(len, max_per_txd);
2736#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002737 /* Workaround for Controller erratum --
2738 * descriptor for non-tso packet in a linear SKB that follows a
2739 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002740 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002741 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07002742 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002743 tx_ring->last_tx_tso = 0;
2744 size -= 4;
2745 }
2746
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 /* Workaround for premature desc write-backs
2748 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002749 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 size -= 4;
2751#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002752 /* work-around for errata 10 and it applies
2753 * to all controllers in PCI-X mode
2754 * The fix is to make sure that the first descriptor of a
2755 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2756 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002757 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002758 (size > 2015) && count == 0))
2759 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002760
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 /* Workaround for potential 82544 hang in PCI-X. Avoid
2762 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002763 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2765 size > 4))
2766 size -= 4;
2767
2768 buffer_info->length = size;
2769 buffer_info->dma =
2770 pci_map_single(adapter->pdev,
2771 skb->data + offset,
2772 size,
2773 PCI_DMA_TODEVICE);
2774 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002775 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
2777 len -= size;
2778 offset += size;
2779 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002780 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 }
2782
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002783 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 struct skb_frag_struct *frag;
2785
2786 frag = &skb_shinfo(skb)->frags[f];
2787 len = frag->size;
2788 offset = frag->page_offset;
2789
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002790 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 buffer_info = &tx_ring->buffer_info[i];
2792 size = min(len, max_per_txd);
2793#ifdef NETIF_F_TSO
2794 /* Workaround for premature desc write-backs
2795 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002796 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 size -= 4;
2798#endif
2799 /* Workaround for potential 82544 hang in PCI-X.
2800 * Avoid terminating buffers within evenly-aligned
2801 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002802 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2804 size > 4))
2805 size -= 4;
2806
2807 buffer_info->length = size;
2808 buffer_info->dma =
2809 pci_map_page(adapter->pdev,
2810 frag->page,
2811 offset,
2812 size,
2813 PCI_DMA_TODEVICE);
2814 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002815 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816
2817 len -= size;
2818 offset += size;
2819 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002820 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 }
2822 }
2823
2824 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2825 tx_ring->buffer_info[i].skb = skb;
2826 tx_ring->buffer_info[first].next_to_watch = i;
2827
2828 return count;
2829}
2830
Auke Koke619d522006-04-14 19:04:52 -07002831static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002832e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2833 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 struct e1000_tx_desc *tx_desc = NULL;
2836 struct e1000_buffer *buffer_info;
2837 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2838 unsigned int i;
2839
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002840 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2842 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002843 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2844
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002845 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002846 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 }
2848
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002849 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2851 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2852 }
2853
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002854 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 txd_lower |= E1000_TXD_CMD_VLE;
2856 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2857 }
2858
2859 i = tx_ring->next_to_use;
2860
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002861 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 buffer_info = &tx_ring->buffer_info[i];
2863 tx_desc = E1000_TX_DESC(*tx_ring, i);
2864 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2865 tx_desc->lower.data =
2866 cpu_to_le32(txd_lower | buffer_info->length);
2867 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002868 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 }
2870
2871 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2872
2873 /* Force memory writes to complete before letting h/w
2874 * know there are new descriptors to fetch. (Only
2875 * applicable for weak-ordered memory model archs,
2876 * such as IA-64). */
2877 wmb();
2878
2879 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002880 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08002881 /* we need this if more than one processor can write to our tail
2882 * at a time, it syncronizes IO on IA64/Altix systems */
2883 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884}
2885
2886/**
2887 * 82547 workaround to avoid controller hang in half-duplex environment.
2888 * The workaround is to avoid queuing a large packet that would span
2889 * the internal Tx FIFO ring boundary by notifying the stack to resend
2890 * the packet at a later time. This gives the Tx FIFO an opportunity to
2891 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2892 * to the beginning of the Tx FIFO.
2893 **/
2894
2895#define E1000_FIFO_HDR 0x10
2896#define E1000_82547_PAD_LEN 0x3E0
2897
Auke Koke619d522006-04-14 19:04:52 -07002898static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2900{
2901 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2902 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2903
2904 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2905
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002906 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 goto no_fifo_stall_required;
2908
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002909 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 return 1;
2911
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002912 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 atomic_set(&adapter->tx_fifo_stall, 1);
2914 return 1;
2915 }
2916
2917no_fifo_stall_required:
2918 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002919 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2921 return 0;
2922}
2923
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002924#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07002925static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002926e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2927{
2928 struct e1000_hw *hw = &adapter->hw;
2929 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002930 if (vlan_tx_tag_present(skb)) {
2931 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002932 ( adapter->hw.mng_cookie.status &
2933 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2934 return 0;
2935 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08002936 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002937 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002938 if ((htons(ETH_P_IP) == eth->h_proto)) {
2939 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002940 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002941 if (IPPROTO_UDP == ip->protocol) {
2942 struct udphdr *udp =
2943 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002944 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002945 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002946 offset = (uint8_t *)udp + 8 - skb->data;
2947 length = skb->len - offset;
2948
2949 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002950 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002951 length);
2952 }
2953 }
2954 }
2955 }
2956 return 0;
2957}
2958
Jesse Brandeburg65c79732006-09-27 12:53:48 -07002959static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
2960{
2961 struct e1000_adapter *adapter = netdev_priv(netdev);
2962 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
2963
2964 netif_stop_queue(netdev);
2965 /* Herbert's original patch had:
2966 * smp_mb__after_netif_stop_queue();
2967 * but since that doesn't exist yet, just open code it. */
2968 smp_mb();
2969
2970 /* We need to check again in a case another CPU has just
2971 * made room available. */
2972 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
2973 return -EBUSY;
2974
2975 /* A reprieve! */
2976 netif_start_queue(netdev);
2977 return 0;
2978}
2979
2980static int e1000_maybe_stop_tx(struct net_device *netdev,
2981 struct e1000_tx_ring *tx_ring, int size)
2982{
2983 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
2984 return 0;
2985 return __e1000_maybe_stop_tx(netdev, size);
2986}
2987
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2989static int
2990e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2991{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002992 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002993 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2995 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2996 unsigned int tx_flags = 0;
2997 unsigned int len = skb->len;
2998 unsigned long flags;
2999 unsigned int nr_frags = 0;
3000 unsigned int mss = 0;
3001 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07003002 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 unsigned int f;
3004 len -= skb->data_len;
3005
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003006 /* This goes back to the question of how to logically map a tx queue
3007 * to a flow. Right now, performance is impacted slightly negatively
3008 * if using multiple tx queues. If the stack breaks away from a
3009 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003010 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003011
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003012 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 dev_kfree_skb_any(skb);
3014 return NETDEV_TX_OK;
3015 }
3016
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003017 /* 82571 and newer doesn't need the workaround that limited descriptor
3018 * length to 4kB */
3019 if (adapter->hw.mac_type >= e1000_82571)
3020 max_per_txd = 8192;
3021
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022#ifdef NETIF_F_TSO
Herbert Xu79671682006-06-22 02:40:14 -07003023 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003024 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 * make sure there is enough room in the FIFO before
3026 * initiating the DMA for each buffer. The calc is:
3027 * 4 = ceil(buffer len/mss). To make sure we don't
3028 * overrun the FIFO, adjust the max buffer len if mss
3029 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003030 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003031 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 max_per_txd = min(mss << 2, max_per_txd);
3033 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003034
Auke Kok90fb5132006-11-01 08:47:30 -08003035 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3036 * points to just header, pull a few bytes of payload from
3037 * frags into skb->data */
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003038 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08003039 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3040 switch (adapter->hw.mac_type) {
3041 unsigned int pull_size;
3042 case e1000_82571:
3043 case e1000_82572:
3044 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003045 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003046 pull_size = min((unsigned int)4, skb->data_len);
3047 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003048 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003049 "__pskb_pull_tail failed.\n");
3050 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003051 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003052 }
3053 len = skb->len - skb->data_len;
3054 break;
3055 default:
3056 /* do nothing */
3057 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003058 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003059 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 }
3061
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003062 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003063 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003065 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066#else
Patrick McHardy84fa7932006-08-29 16:44:56 -07003067 if (skb->ip_summed == CHECKSUM_PARTIAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 count++;
3069#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05003070
3071#ifdef NETIF_F_TSO
3072 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003073 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003074 count++;
3075#endif
3076
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 count += TXD_USE_COUNT(len, max_txd_pwr);
3078
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003079 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 count++;
3081
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003082 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003083 * in PCI-X mode, so add one more descriptor to the count
3084 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003085 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003086 (len > 2015)))
3087 count++;
3088
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003090 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3092 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003093 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 count += nr_frags;
3095
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003096
3097 if (adapter->hw.tx_pkt_filtering &&
3098 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003099 e1000_transfer_dhcp_info(adapter, skb);
3100
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003101 local_irq_save(flags);
3102 if (!spin_trylock(&tx_ring->tx_lock)) {
3103 /* Collision - tell upper layer to requeue */
3104 local_irq_restore(flags);
3105 return NETDEV_TX_LOCKED;
3106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107
3108 /* need: count + 2 desc gap to keep tail from touching
3109 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003110 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003111 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 return NETDEV_TX_BUSY;
3113 }
3114
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003115 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3116 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003118 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003119 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 return NETDEV_TX_BUSY;
3121 }
3122 }
3123
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003124 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 tx_flags |= E1000_TX_FLAGS_VLAN;
3126 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3127 }
3128
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003129 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003130
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003131 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 if (tso < 0) {
3133 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003134 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 return NETDEV_TX_OK;
3136 }
3137
Jeff Kirsherfd803242005-12-13 00:06:22 -05003138 if (likely(tso)) {
3139 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003141 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 tx_flags |= E1000_TX_FLAGS_CSUM;
3143
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003144 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003145 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003146 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003147 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003148 tx_flags |= E1000_TX_FLAGS_IPV4;
3149
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003150 e1000_tx_queue(adapter, tx_ring, tx_flags,
3151 e1000_tx_map(adapter, tx_ring, skb, first,
3152 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
3154 netdev->trans_start = jiffies;
3155
3156 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003157 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003159 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 return NETDEV_TX_OK;
3161}
3162
3163/**
3164 * e1000_tx_timeout - Respond to a Tx Hang
3165 * @netdev: network interface device structure
3166 **/
3167
3168static void
3169e1000_tx_timeout(struct net_device *netdev)
3170{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003171 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
3173 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003174 adapter->tx_timeout_count++;
3175 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176}
3177
3178static void
Jeff Kirsher87041632006-03-02 18:21:24 -08003179e1000_reset_task(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003181 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182
Auke Kok2db10a02006-06-27 09:06:28 -07003183 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184}
3185
3186/**
3187 * e1000_get_stats - Get System Network Statistics
3188 * @netdev: network interface device structure
3189 *
3190 * Returns the address of the device statistics structure.
3191 * The statistics are actually updated from the timer callback.
3192 **/
3193
3194static struct net_device_stats *
3195e1000_get_stats(struct net_device *netdev)
3196{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003197 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003199 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 return &adapter->net_stats;
3201}
3202
3203/**
3204 * e1000_change_mtu - Change the Maximum Transfer Unit
3205 * @netdev: network interface device structure
3206 * @new_mtu: new value for maximum frame size
3207 *
3208 * Returns 0 on success, negative on failure
3209 **/
3210
3211static int
3212e1000_change_mtu(struct net_device *netdev, int new_mtu)
3213{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003214 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003216 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003218 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3219 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3220 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003221 return -EINVAL;
3222 }
3223
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003224 /* Adapter-specific max frame size limits. */
3225 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003226 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003227 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003228 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3229 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003230 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003231 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003232 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003233 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003234 /* Jumbo Frames not supported if:
3235 * - this is not an 82573L device
3236 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003237 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3238 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003239 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3240 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003241 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3242 DPRINTK(PROBE, ERR,
3243 "Jumbo Frames not supported.\n");
3244 return -EINVAL;
3245 }
3246 break;
3247 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003248 /* ERT will be enabled later to enable wire speed receives */
3249
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003250 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003251 case e1000_82571:
3252 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003253 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003254#define MAX_STD_JUMBO_FRAME_SIZE 9234
3255 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3256 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3257 return -EINVAL;
3258 }
3259 break;
3260 default:
3261 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3262 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003263 }
3264
David S. Miller87f50322006-07-31 22:39:40 -07003265 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003266 * means we reserve 2 more, this pushes us to allocate from the next
3267 * larger slab size
3268 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003269
Auke Kok9e2feac2006-04-14 19:05:18 -07003270 if (max_frame <= E1000_RXBUFFER_256)
3271 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3272 else if (max_frame <= E1000_RXBUFFER_512)
3273 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3274 else if (max_frame <= E1000_RXBUFFER_1024)
3275 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3276 else if (max_frame <= E1000_RXBUFFER_2048)
3277 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3278 else if (max_frame <= E1000_RXBUFFER_4096)
3279 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3280 else if (max_frame <= E1000_RXBUFFER_8192)
3281 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3282 else if (max_frame <= E1000_RXBUFFER_16384)
3283 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3284
3285 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003286 if (!adapter->hw.tbi_compatibility_on &&
3287 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3288 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3289 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003290
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003291 netdev->mtu = new_mtu;
3292
Auke Kok2db10a02006-06-27 09:06:28 -07003293 if (netif_running(netdev))
3294 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 adapter->hw.max_frame_size = max_frame;
3297
3298 return 0;
3299}
3300
3301/**
3302 * e1000_update_stats - Update the board statistics counters
3303 * @adapter: board private structure
3304 **/
3305
3306void
3307e1000_update_stats(struct e1000_adapter *adapter)
3308{
3309 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003310 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 unsigned long flags;
3312 uint16_t phy_tmp;
3313
3314#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3315
Linas Vepstas282f33c2006-06-08 22:19:44 -07003316 /*
3317 * Prevent stats update while adapter is being reset, or if the pci
3318 * connection is down.
3319 */
Auke Kok90267292006-06-08 09:30:24 -07003320 if (adapter->link_speed == 0)
3321 return;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003322 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3323 return;
Auke Kok90267292006-06-08 09:30:24 -07003324
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 spin_lock_irqsave(&adapter->stats_lock, flags);
3326
3327 /* these counters are modified from e1000_adjust_tbi_stats,
3328 * called from the interrupt context, so they must only
3329 * be written while holding adapter->stats_lock
3330 */
3331
3332 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3333 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3334 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3335 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3336 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3337 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3338 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003339
3340 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003341 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3342 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3343 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3344 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3345 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3346 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
3349 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3350 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3351 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3352 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3353 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3354 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3355 adapter->stats.dc += E1000_READ_REG(hw, DC);
3356 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3357 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3358 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3359 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3360 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3361 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3362 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3363 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3364 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3365 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3366 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3367 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3368 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3369 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3370 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3371 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3372 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3373 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3374 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003375
3376 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003377 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3378 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3379 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3380 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3381 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3382 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003383 }
3384
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3386 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3387
3388 /* used for adaptive IFS */
3389
3390 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3391 adapter->stats.tpt += hw->tx_packet_delta;
3392 hw->collision_delta = E1000_READ_REG(hw, COLC);
3393 adapter->stats.colc += hw->collision_delta;
3394
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003395 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3397 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3398 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3399 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3400 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3401 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3402 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003403 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003404 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3405 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003406
3407 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003408 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3409 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3410 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3411 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3412 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3413 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3414 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003415 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417
3418 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 adapter->net_stats.rx_packets = adapter->stats.gprc;
3420 adapter->net_stats.tx_packets = adapter->stats.gptc;
3421 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3422 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3423 adapter->net_stats.multicast = adapter->stats.mprc;
3424 adapter->net_stats.collisions = adapter->stats.colc;
3425
3426 /* Rx Errors */
3427
Jeff Kirsher87041632006-03-02 18:21:24 -08003428 /* RLEC on some newer hardware can be incorrect so build
3429 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3431 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003432 adapter->stats.ruc + adapter->stats.roc +
3433 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003434 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3435 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3437 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3439
3440 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003441 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3442 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3444 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3445 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3446
3447 /* Tx Dropped needs to be maintained elsewhere */
3448
3449 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003450 if (hw->media_type == e1000_media_type_copper) {
3451 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3453 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3454 adapter->phy_stats.idle_errors += phy_tmp;
3455 }
3456
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003457 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 (hw->phy_type == e1000_phy_m88) &&
3459 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3460 adapter->phy_stats.receive_errors += phy_tmp;
3461 }
3462
3463 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3464}
3465
3466/**
3467 * e1000_intr - Interrupt Handler
3468 * @irq: interrupt number
3469 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 **/
3471
3472static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003473e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474{
3475 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003476 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003478 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003479#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003480 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003481#else
3482 /* Interrupt Auto-Mask...upon reading ICR,
3483 * interrupts are masked. No need for the
3484 * IMC write, but it does mean we should
3485 * account for it ASAP. */
3486 if (likely(hw->mac_type >= e1000_82571))
3487 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003488#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003490 if (unlikely(!icr)) {
3491#ifdef CONFIG_E1000_NAPI
3492 if (hw->mac_type >= e1000_82571)
3493 e1000_irq_enable(adapter);
3494#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003498 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003500 /* 80003ES2LAN workaround--
3501 * For packet buffer work-around on link down event;
3502 * disable receives here in the ISR and
3503 * reset adapter in watchdog
3504 */
3505 if (netif_carrier_ok(netdev) &&
3506 (adapter->hw.mac_type == e1000_80003es2lan)) {
3507 /* disable receives */
3508 rctl = E1000_READ_REG(hw, RCTL);
3509 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3510 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003511 /* guard against interrupt when we're going down */
3512 if (!test_bit(__E1000_DOWN, &adapter->flags))
3513 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 }
3515
3516#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003517 if (unlikely(hw->mac_type < e1000_82571)) {
3518 atomic_inc(&adapter->irq_sem);
3519 E1000_WRITE_REG(hw, IMC, ~0);
3520 E1000_WRITE_FLUSH(hw);
3521 }
Auke Kokd3d9e482006-07-14 16:14:23 -07003522 if (likely(netif_rx_schedule_prep(netdev)))
3523 __netif_rx_schedule(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003524 else
Auke Kok90fb5132006-11-01 08:47:30 -08003525 /* this really should not happen! if it does it is basically a
3526 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003527 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003528#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003530 * Due to Hub Link bus being occupied, an interrupt
3531 * de-assertion message is not able to be sent.
3532 * When an interrupt assertion message is generated later,
3533 * two messages are re-ordered and sent out.
3534 * That causes APIC to think 82547 is in de-assertion
3535 * state, while 82547 is in assertion state, resulting
3536 * in dead lock. Writing IMC forces 82547 into
3537 * de-assertion state.
3538 */
3539 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003541 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 }
3543
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003544 for (i = 0; i < E1000_MAX_INTR; i++)
3545 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003546 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 break;
3548
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003549 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003551
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003552#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 return IRQ_HANDLED;
3554}
3555
3556#ifdef CONFIG_E1000_NAPI
3557/**
3558 * e1000_clean - NAPI Rx polling callback
3559 * @adapter: board private structure
3560 **/
3561
3562static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003563e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003565 struct e1000_adapter *adapter;
3566 int work_to_do = min(*budget, poll_dev->quota);
Auke Kokd3d9e482006-07-14 16:14:23 -07003567 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003568
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003569 /* Must NOT use netdev_priv macro here. */
3570 adapter = poll_dev->priv;
3571
3572 /* Keep link state information with original netdev */
Auke Kokd3d9e482006-07-14 16:14:23 -07003573 if (!netif_carrier_ok(poll_dev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003574 goto quit_polling;
3575
Auke Kokd3d9e482006-07-14 16:14:23 -07003576 /* e1000_clean is called per-cpu. This lock protects
3577 * tx_ring[0] from being cleaned by multiple cpus
3578 * simultaneously. A failure obtaining the lock means
3579 * tx_ring[0] is currently being cleaned anyway. */
3580 if (spin_trylock(&adapter->tx_queue_lock)) {
3581 tx_cleaned = e1000_clean_tx_irq(adapter,
3582 &adapter->tx_ring[0]);
3583 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003584 }
3585
Auke Kokd3d9e482006-07-14 16:14:23 -07003586 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003587 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588
3589 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003590 poll_dev->quota -= work_done;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003591
Malli Chilakala2b028932005-06-17 17:46:06 -07003592 /* If no Tx and not enough Rx work done, exit the polling mode */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003593 if ((!tx_cleaned && (work_done == 0)) ||
Auke Kokd3d9e482006-07-14 16:14:23 -07003594 !netif_running(poll_dev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003595quit_polling:
3596 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 e1000_irq_enable(adapter);
3598 return 0;
3599 }
3600
3601 return 1;
3602}
3603
3604#endif
3605/**
3606 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3607 * @adapter: board private structure
3608 **/
3609
3610static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003611e1000_clean_tx_irq(struct e1000_adapter *adapter,
3612 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 struct net_device *netdev = adapter->netdev;
3615 struct e1000_tx_desc *tx_desc, *eop_desc;
3616 struct e1000_buffer *buffer_info;
3617 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003618#ifdef CONFIG_E1000_NAPI
3619 unsigned int count = 0;
3620#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 boolean_t cleaned = FALSE;
3622
3623 i = tx_ring->next_to_clean;
3624 eop = tx_ring->buffer_info[i].next_to_watch;
3625 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3626
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003627 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003628 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 tx_desc = E1000_TX_DESC(*tx_ring, i);
3630 buffer_info = &tx_ring->buffer_info[i];
3631 cleaned = (i == eop);
3632
Jeff Kirsherfd803242005-12-13 00:06:22 -05003633 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003634 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003636 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003638
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 eop = tx_ring->buffer_info[i].next_to_watch;
3640 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003641#ifdef CONFIG_E1000_NAPI
3642#define E1000_TX_WEIGHT 64
3643 /* weight of a sort for tx, to avoid endless transmit cleanup */
3644 if (count++ == E1000_TX_WEIGHT) break;
3645#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 }
3647
3648 tx_ring->next_to_clean = i;
3649
Auke Kok77b2aad2006-04-14 19:05:25 -07003650#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003651 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3652 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3653 /* Make sure that anybody stopping the queue after this
3654 * sees the new next_to_clean.
3655 */
3656 smp_mb();
3657 if (netif_queue_stopped(netdev))
Auke Kok77b2aad2006-04-14 19:05:25 -07003658 netif_wake_queue(netdev);
Auke Kok77b2aad2006-04-14 19:05:25 -07003659 }
Malli Chilakala26483452005-04-28 19:44:46 -07003660
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003661 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003662 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 * check with the clearing of time_stamp and movement of i */
3664 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003665 if (tx_ring->buffer_info[eop].dma &&
3666 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003667 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003668 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003669 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003670
3671 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003672 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003673 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003674 " TDH <%x>\n"
3675 " TDT <%x>\n"
3676 " next_to_use <%x>\n"
3677 " next_to_clean <%x>\n"
3678 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003679 " time_stamp <%lx>\n"
3680 " next_to_watch <%x>\n"
3681 " jiffies <%lx>\n"
3682 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003683 (unsigned long)((tx_ring - adapter->tx_ring) /
3684 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003685 readl(adapter->hw.hw_addr + tx_ring->tdh),
3686 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003687 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003688 tx_ring->next_to_clean,
3689 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003690 eop,
3691 jiffies,
3692 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 return cleaned;
3697}
3698
3699/**
3700 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003701 * @adapter: board private structure
3702 * @status_err: receive descriptor status and error fields
3703 * @csum: receive descriptor csum field
3704 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 **/
3706
Auke Koke619d522006-04-14 19:04:52 -07003707static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003709 uint32_t status_err, uint32_t csum,
3710 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003712 uint16_t status = (uint16_t)status_err;
3713 uint8_t errors = (uint8_t)(status_err >> 24);
3714 skb->ip_summed = CHECKSUM_NONE;
3715
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003717 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003719 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003720 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003721 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003722 /* let the stack verify checksum errors */
3723 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 return;
3725 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003726 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003727 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3728 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003729 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003731 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003732 return;
3733 }
3734 /* It must be a TCP or UDP packet with a valid checksum */
3735 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 /* TCP checksum is good */
3737 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003738 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3739 /* IP fragment with UDP payload */
3740 /* Hardware complements the payload checksum, so we undo it
3741 * and then put the value in host order for further stack use.
3742 */
3743 csum = ntohl(csum ^ 0xFFFF);
3744 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07003745 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003747 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748}
3749
3750/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003751 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 * @adapter: board private structure
3753 **/
3754
3755static boolean_t
3756#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003757e1000_clean_rx_irq(struct e1000_adapter *adapter,
3758 struct e1000_rx_ring *rx_ring,
3759 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003761e1000_clean_rx_irq(struct e1000_adapter *adapter,
3762 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763#endif
3764{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 struct net_device *netdev = adapter->netdev;
3766 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003767 struct e1000_rx_desc *rx_desc, *next_rxd;
3768 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 unsigned long flags;
3770 uint32_t length;
3771 uint8_t last_byte;
3772 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003773 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003774 boolean_t cleaned = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775
3776 i = rx_ring->next_to_clean;
3777 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003778 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003780 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07003781 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003782 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08003783
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003785 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 break;
3787 (*work_done)++;
3788#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08003789 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003790 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003791 buffer_info->skb = NULL;
3792
Jeff Kirsher30320be2006-03-02 18:21:57 -08003793 prefetch(skb->data - NET_IP_ALIGN);
3794
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003795 if (++i == rx_ring->count) i = 0;
3796 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003797 prefetch(next_rxd);
3798
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003799 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003800
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003801 cleaned = TRUE;
3802 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003803 pci_unmap_single(pdev,
3804 buffer_info->dma,
3805 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 PCI_DMA_FROMDEVICE);
3807
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 length = le16_to_cpu(rx_desc->length);
3809
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003810 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3811 /* All receives must fit into a single buffer */
3812 E1000_DBG("%s: Receive packet consumed multiple"
3813 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07003814 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07003815 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 goto next_desc;
3817 }
3818
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003819 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003821 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 rx_desc->errors, length, last_byte)) {
3823 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003824 e1000_tbi_adjust_stats(&adapter->hw,
3825 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 length, skb->data);
3827 spin_unlock_irqrestore(&adapter->stats_lock,
3828 flags);
3829 length--;
3830 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07003831 /* recycle */
3832 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 goto next_desc;
3834 }
Auke Kok1cb58212006-04-18 12:31:04 -07003835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07003837 /* adjust length to remove Ethernet CRC, this must be
3838 * done after the TBI_ACCEPT workaround above */
3839 length -= 4;
3840
Jeff Kirshera292ca62006-01-12 16:51:30 -08003841 /* code added for copybreak, this should improve
3842 * performance for small packets with large amounts
3843 * of reassembly being done in the stack */
3844#define E1000_CB_LENGTH 256
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003845 if (length < E1000_CB_LENGTH) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08003846 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07003847 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003848 if (new_skb) {
3849 skb_reserve(new_skb, NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003850 memcpy(new_skb->data - NET_IP_ALIGN,
3851 skb->data - NET_IP_ALIGN,
3852 length + NET_IP_ALIGN);
3853 /* save the skb in buffer_info as good */
3854 buffer_info->skb = skb;
3855 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003856 }
Auke Kok996695d2006-11-01 08:47:50 -08003857 /* else just continue with the old one */
3858 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08003859 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08003860 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
3862 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08003863 e1000_rx_checksum(adapter,
3864 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003865 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003866 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003867
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 skb->protocol = eth_type_trans(skb, netdev);
3869#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003870 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08003871 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003873 le16_to_cpu(rx_desc->special) &
3874 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 } else {
3876 netif_receive_skb(skb);
3877 }
3878#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003879 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003880 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 vlan_hwaccel_rx(skb, adapter->vlgrp,
3882 le16_to_cpu(rx_desc->special) &
3883 E1000_RXD_SPC_VLAN_MASK);
3884 } else {
3885 netif_rx(skb);
3886 }
3887#endif /* CONFIG_E1000_NAPI */
3888 netdev->last_rx = jiffies;
3889
3890next_desc:
3891 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003893 /* return some buffers to hardware, one at a time is too slow */
3894 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3895 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3896 cleaned_count = 0;
3897 }
3898
Jeff Kirsher30320be2006-03-02 18:21:57 -08003899 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003900 rx_desc = next_rxd;
3901 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003904
3905 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3906 if (cleaned_count)
3907 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908
3909 return cleaned;
3910}
3911
3912/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003913 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3914 * @adapter: board private structure
3915 **/
3916
3917static boolean_t
3918#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003919e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3920 struct e1000_rx_ring *rx_ring,
3921 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003922#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003923e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3924 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003925#endif
3926{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003927 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003928 struct net_device *netdev = adapter->netdev;
3929 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003930 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003931 struct e1000_ps_page *ps_page;
3932 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07003933 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003934 unsigned int i, j;
3935 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003936 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003937 boolean_t cleaned = FALSE;
3938
3939 i = rx_ring->next_to_clean;
3940 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003941 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07003942 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003943
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003944 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003945 ps_page = &rx_ring->ps_page[i];
3946 ps_page_dma = &rx_ring->ps_page_dma[i];
3947#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003948 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003949 break;
3950 (*work_done)++;
3951#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003952 skb = buffer_info->skb;
3953
Jeff Kirsher30320be2006-03-02 18:21:57 -08003954 /* in the packet split case this is header only */
3955 prefetch(skb->data - NET_IP_ALIGN);
3956
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003957 if (++i == rx_ring->count) i = 0;
3958 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003959 prefetch(next_rxd);
3960
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003961 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003962
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003963 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003964 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003965 pci_unmap_single(pdev, buffer_info->dma,
3966 buffer_info->length,
3967 PCI_DMA_FROMDEVICE);
3968
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003969 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003970 E1000_DBG("%s: Packet Split buffers didn't pick up"
3971 " the full packet\n", netdev->name);
3972 dev_kfree_skb_irq(skb);
3973 goto next_desc;
3974 }
3975
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003976 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003977 dev_kfree_skb_irq(skb);
3978 goto next_desc;
3979 }
3980
3981 length = le16_to_cpu(rx_desc->wb.middle.length0);
3982
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003983 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003984 E1000_DBG("%s: Last part of the packet spanning"
3985 " multiple descriptors\n", netdev->name);
3986 dev_kfree_skb_irq(skb);
3987 goto next_desc;
3988 }
3989
3990 /* Good Receive */
3991 skb_put(skb, length);
3992
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003993 {
3994 /* this looks ugly, but it seems compiler issues make it
3995 more efficient than reusing j */
3996 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3997
3998 /* page alloc/put takes too long and effects small packet
3999 * throughput, so unsplit small packets and save the alloc/put*/
Auke Kok9e2feac2006-04-14 19:05:18 -07004000 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004001 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07004002 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004003 * kmap_atomic, so we can't hold the mapping
4004 * very long */
4005 pci_dma_sync_single_for_cpu(pdev,
4006 ps_page_dma->ps_page_dma[0],
4007 PAGE_SIZE,
4008 PCI_DMA_FROMDEVICE);
4009 vaddr = kmap_atomic(ps_page->ps_page[0],
4010 KM_SKB_DATA_SOFTIRQ);
4011 memcpy(skb->tail, vaddr, l1);
4012 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4013 pci_dma_sync_single_for_device(pdev,
4014 ps_page_dma->ps_page_dma[0],
4015 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004016 /* remove the CRC */
4017 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004018 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004019 goto copydone;
4020 } /* if */
4021 }
Auke Kok90fb5132006-11-01 08:47:30 -08004022
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004023 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004024 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004025 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004026 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4027 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4028 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004029 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4030 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004031 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004032 skb->len += length;
4033 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004034 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004035 }
4036
Auke Kokf235a2a2006-07-14 16:14:34 -07004037 /* strip the ethernet crc, problem is we're using pages now so
4038 * this whole operation can get a little cpu intensive */
4039 pskb_trim(skb, skb->len - 4);
4040
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004041copydone:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004042 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004043 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004044 skb->protocol = eth_type_trans(skb, netdev);
4045
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004046 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004047 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004048 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004049#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004050 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004051 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004052 le16_to_cpu(rx_desc->wb.middle.vlan) &
4053 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004054 } else {
4055 netif_receive_skb(skb);
4056 }
4057#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004058 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004059 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004060 le16_to_cpu(rx_desc->wb.middle.vlan) &
4061 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004062 } else {
4063 netif_rx(skb);
4064 }
4065#endif /* CONFIG_E1000_NAPI */
4066 netdev->last_rx = jiffies;
4067
4068next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004069 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004070 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004071
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004072 /* return some buffers to hardware, one at a time is too slow */
4073 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4074 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4075 cleaned_count = 0;
4076 }
4077
Jeff Kirsher30320be2006-03-02 18:21:57 -08004078 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004079 rx_desc = next_rxd;
4080 buffer_info = next_buffer;
4081
Malli Chilakala683a38f2005-06-17 17:43:25 -07004082 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004083 }
4084 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004085
4086 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4087 if (cleaned_count)
4088 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004089
4090 return cleaned;
4091}
4092
4093/**
4094 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 * @adapter: address of board private structure
4096 **/
4097
4098static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004099e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004100 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004101 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 struct net_device *netdev = adapter->netdev;
4104 struct pci_dev *pdev = adapter->pdev;
4105 struct e1000_rx_desc *rx_desc;
4106 struct e1000_buffer *buffer_info;
4107 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004108 unsigned int i;
4109 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110
4111 i = rx_ring->next_to_use;
4112 buffer_info = &rx_ring->buffer_info[i];
4113
Jeff Kirshera292ca62006-01-12 16:51:30 -08004114 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004115 skb = buffer_info->skb;
4116 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004117 skb_trim(skb, 0);
4118 goto map_skb;
4119 }
4120
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004121 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004122 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004124 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 break;
4126 }
4127
Malli Chilakala26483452005-04-28 19:44:46 -07004128 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4130 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004131 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4132 "at %p\n", bufsz, skb->data);
4133 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004134 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004135 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 if (!skb) {
4137 dev_kfree_skb(oldskb);
4138 break;
4139 }
Malli Chilakala26483452005-04-28 19:44:46 -07004140
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4142 /* give up */
4143 dev_kfree_skb(skb);
4144 dev_kfree_skb(oldskb);
4145 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004147
4148 /* Use new allocation */
4149 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 /* Make buffer alignment 2 beyond a 16 byte boundary
4152 * this will result in a 16 byte aligned IP header after
4153 * the 14 byte MAC header is removed
4154 */
4155 skb_reserve(skb, NET_IP_ALIGN);
4156
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 buffer_info->skb = skb;
4158 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004159map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 buffer_info->dma = pci_map_single(pdev,
4161 skb->data,
4162 adapter->rx_buffer_len,
4163 PCI_DMA_FROMDEVICE);
4164
Malli Chilakala26483452005-04-28 19:44:46 -07004165 /* Fix for errata 23, can't cross 64kB boundary */
4166 if (!e1000_check_64k_bound(adapter,
4167 (void *)(unsigned long)buffer_info->dma,
4168 adapter->rx_buffer_len)) {
4169 DPRINTK(RX_ERR, ERR,
4170 "dma align check failed: %u bytes at %p\n",
4171 adapter->rx_buffer_len,
4172 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 dev_kfree_skb(skb);
4174 buffer_info->skb = NULL;
4175
Malli Chilakala26483452005-04-28 19:44:46 -07004176 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177 adapter->rx_buffer_len,
4178 PCI_DMA_FROMDEVICE);
4179
4180 break; /* while !buffer_info->skb */
4181 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 rx_desc = E1000_RX_DESC(*rx_ring, i);
4183 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4184
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004185 if (unlikely(++i == rx_ring->count))
4186 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 buffer_info = &rx_ring->buffer_info[i];
4188 }
4189
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004190 if (likely(rx_ring->next_to_use != i)) {
4191 rx_ring->next_to_use = i;
4192 if (unlikely(i-- == 0))
4193 i = (rx_ring->count - 1);
4194
4195 /* Force memory writes to complete before letting h/w
4196 * know there are new descriptors to fetch. (Only
4197 * applicable for weak-ordered memory model archs,
4198 * such as IA-64). */
4199 wmb();
4200 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202}
4203
4204/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004205 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4206 * @adapter: address of board private structure
4207 **/
4208
4209static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004210e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004211 struct e1000_rx_ring *rx_ring,
4212 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004213{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004214 struct net_device *netdev = adapter->netdev;
4215 struct pci_dev *pdev = adapter->pdev;
4216 union e1000_rx_desc_packet_split *rx_desc;
4217 struct e1000_buffer *buffer_info;
4218 struct e1000_ps_page *ps_page;
4219 struct e1000_ps_page_dma *ps_page_dma;
4220 struct sk_buff *skb;
4221 unsigned int i, j;
4222
4223 i = rx_ring->next_to_use;
4224 buffer_info = &rx_ring->buffer_info[i];
4225 ps_page = &rx_ring->ps_page[i];
4226 ps_page_dma = &rx_ring->ps_page_dma[i];
4227
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004228 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004229 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4230
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004231 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004232 if (j < adapter->rx_ps_pages) {
4233 if (likely(!ps_page->ps_page[j])) {
4234 ps_page->ps_page[j] =
4235 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004236 if (unlikely(!ps_page->ps_page[j])) {
4237 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004238 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004239 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004240 ps_page_dma->ps_page_dma[j] =
4241 pci_map_page(pdev,
4242 ps_page->ps_page[j],
4243 0, PAGE_SIZE,
4244 PCI_DMA_FROMDEVICE);
4245 }
4246 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004247 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004248 * this info.
4249 */
4250 rx_desc->read.buffer_addr[j+1] =
4251 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4252 } else
4253 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004254 }
4255
David S. Miller87f50322006-07-31 22:39:40 -07004256 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004257 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004258
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004259 if (unlikely(!skb)) {
4260 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004261 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004262 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004263
4264 /* Make buffer alignment 2 beyond a 16 byte boundary
4265 * this will result in a 16 byte aligned IP header after
4266 * the 14 byte MAC header is removed
4267 */
4268 skb_reserve(skb, NET_IP_ALIGN);
4269
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004270 buffer_info->skb = skb;
4271 buffer_info->length = adapter->rx_ps_bsize0;
4272 buffer_info->dma = pci_map_single(pdev, skb->data,
4273 adapter->rx_ps_bsize0,
4274 PCI_DMA_FROMDEVICE);
4275
4276 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4277
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004278 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004279 buffer_info = &rx_ring->buffer_info[i];
4280 ps_page = &rx_ring->ps_page[i];
4281 ps_page_dma = &rx_ring->ps_page_dma[i];
4282 }
4283
4284no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004285 if (likely(rx_ring->next_to_use != i)) {
4286 rx_ring->next_to_use = i;
4287 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4288
4289 /* Force memory writes to complete before letting h/w
4290 * know there are new descriptors to fetch. (Only
4291 * applicable for weak-ordered memory model archs,
4292 * such as IA-64). */
4293 wmb();
4294 /* Hardware increments by 16 bytes, but packet split
4295 * descriptors are 32 bytes...so we increment tail
4296 * twice as much.
4297 */
4298 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4299 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004300}
4301
4302/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4304 * @adapter:
4305 **/
4306
4307static void
4308e1000_smartspeed(struct e1000_adapter *adapter)
4309{
4310 uint16_t phy_status;
4311 uint16_t phy_ctrl;
4312
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004313 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4315 return;
4316
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004317 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 /* If Master/Slave config fault is asserted twice,
4319 * we assume back-to-back */
4320 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004321 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004323 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004325 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4327 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4328 phy_ctrl);
4329 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004330 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4332 &phy_ctrl)) {
4333 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4334 MII_CR_RESTART_AUTO_NEG);
4335 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4336 phy_ctrl);
4337 }
4338 }
4339 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004340 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341 /* If still no link, perhaps using 2/3 pair cable */
4342 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4343 phy_ctrl |= CR_1000T_MS_ENABLE;
4344 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004345 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4347 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4348 MII_CR_RESTART_AUTO_NEG);
4349 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4350 }
4351 }
4352 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004353 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 adapter->smartspeed = 0;
4355}
4356
4357/**
4358 * e1000_ioctl -
4359 * @netdev:
4360 * @ifreq:
4361 * @cmd:
4362 **/
4363
4364static int
4365e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4366{
4367 switch (cmd) {
4368 case SIOCGMIIPHY:
4369 case SIOCGMIIREG:
4370 case SIOCSMIIREG:
4371 return e1000_mii_ioctl(netdev, ifr, cmd);
4372 default:
4373 return -EOPNOTSUPP;
4374 }
4375}
4376
4377/**
4378 * e1000_mii_ioctl -
4379 * @netdev:
4380 * @ifreq:
4381 * @cmd:
4382 **/
4383
4384static int
4385e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4386{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004387 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388 struct mii_ioctl_data *data = if_mii(ifr);
4389 int retval;
4390 uint16_t mii_reg;
4391 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004392 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004394 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 return -EOPNOTSUPP;
4396
4397 switch (cmd) {
4398 case SIOCGMIIPHY:
4399 data->phy_id = adapter->hw.phy_addr;
4400 break;
4401 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004402 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004404 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004405 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004406 &data->val_out)) {
4407 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004409 }
4410 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 break;
4412 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004413 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004415 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 return -EFAULT;
4417 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004418 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004419 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004420 mii_reg)) {
4421 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004423 }
Auke Kokdc86d322006-04-18 12:30:51 -07004424 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 switch (data->reg_num) {
4426 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004427 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004429 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 adapter->hw.autoneg = 1;
4431 adapter->hw.autoneg_advertised = 0x2F;
4432 } else {
4433 if (mii_reg & 0x40)
4434 spddplx = SPEED_1000;
4435 else if (mii_reg & 0x2000)
4436 spddplx = SPEED_100;
4437 else
4438 spddplx = SPEED_10;
4439 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004440 ? DUPLEX_FULL :
4441 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 retval = e1000_set_spd_dplx(adapter,
4443 spddplx);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004444 if (retval) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004445 spin_unlock_irqrestore(
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004446 &adapter->stats_lock,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004447 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 }
Auke Kok2db10a02006-06-27 09:06:28 -07004451 if (netif_running(adapter->netdev))
4452 e1000_reinit_locked(adapter);
4453 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 e1000_reset(adapter);
4455 break;
4456 case M88E1000_PHY_SPEC_CTRL:
4457 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004458 if (e1000_phy_reset(&adapter->hw)) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004459 spin_unlock_irqrestore(
4460 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 break;
4464 }
4465 } else {
4466 switch (data->reg_num) {
4467 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004468 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004470 if (netif_running(adapter->netdev))
4471 e1000_reinit_locked(adapter);
4472 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 e1000_reset(adapter);
4474 break;
4475 }
4476 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004477 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 break;
4479 default:
4480 return -EOPNOTSUPP;
4481 }
4482 return E1000_SUCCESS;
4483}
4484
4485void
4486e1000_pci_set_mwi(struct e1000_hw *hw)
4487{
4488 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004489 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004491 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004492 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493}
4494
4495void
4496e1000_pci_clear_mwi(struct e1000_hw *hw)
4497{
4498 struct e1000_adapter *adapter = hw->back;
4499
4500 pci_clear_mwi(adapter->pdev);
4501}
4502
4503void
4504e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4505{
4506 struct e1000_adapter *adapter = hw->back;
4507
4508 pci_read_config_word(adapter->pdev, reg, value);
4509}
4510
4511void
4512e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4513{
4514 struct e1000_adapter *adapter = hw->back;
4515
4516 pci_write_config_word(adapter->pdev, reg, *value);
4517}
4518
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004519int32_t
4520e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4521{
4522 struct e1000_adapter *adapter = hw->back;
4523 uint16_t cap_offset;
4524
4525 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4526 if (!cap_offset)
4527 return -E1000_ERR_CONFIG;
4528
4529 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4530
4531 return E1000_SUCCESS;
4532}
4533
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534void
4535e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4536{
4537 outl(value, port);
4538}
4539
4540static void
4541e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4542{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004543 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 uint32_t ctrl, rctl;
4545
4546 e1000_irq_disable(adapter);
4547 adapter->vlgrp = grp;
4548
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004549 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004550 /* enable VLAN tag insert/strip */
4551 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4552 ctrl |= E1000_CTRL_VME;
4553 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4554
Auke Kokcd94dd02006-06-27 09:08:22 -07004555 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004556 /* enable VLAN receive filtering */
4557 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4558 rctl |= E1000_RCTL_VFE;
4559 rctl &= ~E1000_RCTL_CFIEN;
4560 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4561 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 } else {
4564 /* disable VLAN tag insert/strip */
4565 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4566 ctrl &= ~E1000_CTRL_VME;
4567 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4568
Auke Kokcd94dd02006-06-27 09:08:22 -07004569 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004570 /* disable VLAN filtering */
4571 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4572 rctl &= ~E1000_RCTL_VFE;
4573 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4574 if (adapter->mng_vlan_id !=
4575 (uint16_t)E1000_MNG_VLAN_NONE) {
4576 e1000_vlan_rx_kill_vid(netdev,
4577 adapter->mng_vlan_id);
4578 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4579 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 }
4582
4583 e1000_irq_enable(adapter);
4584}
4585
4586static void
4587e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4588{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004589 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004591
4592 if ((adapter->hw.mng_cookie.status &
4593 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4594 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004595 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 /* add VID to filter table */
4597 index = (vid >> 5) & 0x7F;
4598 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4599 vfta |= (1 << (vid & 0x1F));
4600 e1000_write_vfta(&adapter->hw, index, vfta);
4601}
4602
4603static void
4604e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4605{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004606 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 uint32_t vfta, index;
4608
4609 e1000_irq_disable(adapter);
4610
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004611 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612 adapter->vlgrp->vlan_devices[vid] = NULL;
4613
4614 e1000_irq_enable(adapter);
4615
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004616 if ((adapter->hw.mng_cookie.status &
4617 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004618 (vid == adapter->mng_vlan_id)) {
4619 /* release control to f/w */
4620 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004621 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004622 }
4623
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 /* remove VID from filter table */
4625 index = (vid >> 5) & 0x7F;
4626 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4627 vfta &= ~(1 << (vid & 0x1F));
4628 e1000_write_vfta(&adapter->hw, index, vfta);
4629}
4630
4631static void
4632e1000_restore_vlan(struct e1000_adapter *adapter)
4633{
4634 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4635
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004636 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004638 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4639 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 continue;
4641 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4642 }
4643 }
4644}
4645
4646int
4647e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4648{
4649 adapter->hw.autoneg = 0;
4650
Malli Chilakala69213682005-06-17 17:44:20 -07004651 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004652 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004653 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4654 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4655 return -EINVAL;
4656 }
4657
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004658 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 case SPEED_10 + DUPLEX_HALF:
4660 adapter->hw.forced_speed_duplex = e1000_10_half;
4661 break;
4662 case SPEED_10 + DUPLEX_FULL:
4663 adapter->hw.forced_speed_duplex = e1000_10_full;
4664 break;
4665 case SPEED_100 + DUPLEX_HALF:
4666 adapter->hw.forced_speed_duplex = e1000_100_half;
4667 break;
4668 case SPEED_100 + DUPLEX_FULL:
4669 adapter->hw.forced_speed_duplex = e1000_100_full;
4670 break;
4671 case SPEED_1000 + DUPLEX_FULL:
4672 adapter->hw.autoneg = 1;
4673 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4674 break;
4675 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4676 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004677 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678 return -EINVAL;
4679 }
4680 return 0;
4681}
4682
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004683#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004684/* Save/restore 16 or 64 dwords of PCI config space depending on which
4685 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004686 */
4687#define PCIE_CONFIG_SPACE_LEN 256
4688#define PCI_CONFIG_SPACE_LEN 64
4689static int
4690e1000_pci_save_state(struct e1000_adapter *adapter)
4691{
4692 struct pci_dev *dev = adapter->pdev;
4693 int size;
4694 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004695
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004696 if (adapter->hw.mac_type >= e1000_82571)
4697 size = PCIE_CONFIG_SPACE_LEN;
4698 else
4699 size = PCI_CONFIG_SPACE_LEN;
4700
4701 WARN_ON(adapter->config_space != NULL);
4702
4703 adapter->config_space = kmalloc(size, GFP_KERNEL);
4704 if (!adapter->config_space) {
4705 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4706 return -ENOMEM;
4707 }
4708 for (i = 0; i < (size / 4); i++)
4709 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4710 return 0;
4711}
4712
4713static void
4714e1000_pci_restore_state(struct e1000_adapter *adapter)
4715{
4716 struct pci_dev *dev = adapter->pdev;
4717 int size;
4718 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004719
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004720 if (adapter->config_space == NULL)
4721 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004722
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004723 if (adapter->hw.mac_type >= e1000_82571)
4724 size = PCIE_CONFIG_SPACE_LEN;
4725 else
4726 size = PCI_CONFIG_SPACE_LEN;
4727 for (i = 0; i < (size / 4); i++)
4728 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4729 kfree(adapter->config_space);
4730 adapter->config_space = NULL;
4731 return;
4732}
4733#endif /* CONFIG_PM */
4734
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004736e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737{
4738 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004739 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004740 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07004742#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08004743 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07004744#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745
4746 netif_device_detach(netdev);
4747
Auke Kok2db10a02006-06-27 09:06:28 -07004748 if (netif_running(netdev)) {
4749 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07004751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004753#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004754 /* Implement our own version of pci_save_state(pdev) because pci-
4755 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004756 retval = e1000_pci_save_state(adapter);
4757 if (retval)
4758 return retval;
4759#endif
4760
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004762 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 wufc &= ~E1000_WUFC_LNKC;
4764
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004765 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 e1000_setup_rctl(adapter);
4767 e1000_set_multi(netdev);
4768
4769 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07004770 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4772 rctl |= E1000_RCTL_MPE;
4773 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4774 }
4775
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004776 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4778 /* advertise wake from D3Cold */
4779 #define E1000_CTRL_ADVD3WUC 0x00100000
4780 /* phy power management enable */
4781 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4782 ctrl |= E1000_CTRL_ADVD3WUC |
4783 E1000_CTRL_EN_PHY_PWR_MGMT;
4784 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4785 }
4786
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004787 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4789 /* keep the laser running in D3 */
4790 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4791 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4792 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4793 }
4794
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004795 /* Allow time for pending master requests to run */
4796 e1000_disable_pciex_master(&adapter->hw);
4797
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4799 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004800 pci_enable_wake(pdev, PCI_D3hot, 1);
4801 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 } else {
4803 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4804 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07004805 pci_enable_wake(pdev, PCI_D3hot, 0);
4806 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807 }
4808
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004809 if (adapter->hw.mac_type >= e1000_82540 &&
4810 adapter->hw.mac_type < e1000_82571 &&
4811 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004813 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 manc |= E1000_MANC_ARP_EN;
4815 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004816 pci_enable_wake(pdev, PCI_D3hot, 1);
4817 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818 }
4819 }
4820
Auke Kokcd94dd02006-06-27 09:08:22 -07004821 if (adapter->hw.phy_type == e1000_phy_igp_3)
4822 e1000_phy_powerdown_workaround(&adapter->hw);
4823
Auke Kokedd106f2006-11-06 08:57:12 -08004824 if (netif_running(netdev))
4825 e1000_free_irq(adapter);
4826
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004827 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4828 * would have already happened in close and is redundant. */
4829 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004830
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004832
Auke Kokd0e027d2006-04-14 19:04:40 -07004833 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834
4835 return 0;
4836}
4837
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004838#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839static int
4840e1000_resume(struct pci_dev *pdev)
4841{
4842 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004843 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004844 uint32_t manc, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845
Auke Kokd0e027d2006-04-14 19:04:40 -07004846 pci_set_power_state(pdev, PCI_D0);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004847 e1000_pci_restore_state(adapter);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004848 if ((err = pci_enable_device(pdev))) {
4849 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
4850 return err;
4851 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004852 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853
Auke Kokd0e027d2006-04-14 19:04:40 -07004854 pci_enable_wake(pdev, PCI_D3hot, 0);
4855 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856
Auke Kokedd106f2006-11-06 08:57:12 -08004857 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
4858 return err;
4859
4860 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 e1000_reset(adapter);
4862 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4863
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004864 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 e1000_up(adapter);
4866
4867 netif_device_attach(netdev);
4868
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004869 if (adapter->hw.mac_type >= e1000_82540 &&
4870 adapter->hw.mac_type < e1000_82571 &&
4871 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872 manc = E1000_READ_REG(&adapter->hw, MANC);
4873 manc &= ~(E1000_MANC_ARP_EN);
4874 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4875 }
4876
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004877 /* If the controller is 82573 and f/w is AMT, do not set
4878 * DRV_LOAD until the interface is up. For all other cases,
4879 * let the f/w know that the h/w is now under the control
4880 * of the driver. */
4881 if (adapter->hw.mac_type != e1000_82573 ||
4882 !e1000_check_mng_mode(&adapter->hw))
4883 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004884
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 return 0;
4886}
4887#endif
Auke Kokc653e632006-05-23 13:35:57 -07004888
4889static void e1000_shutdown(struct pci_dev *pdev)
4890{
4891 e1000_suspend(pdev, PMSG_SUSPEND);
4892}
4893
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894#ifdef CONFIG_NET_POLL_CONTROLLER
4895/*
4896 * Polling 'interrupt' - used by things like netconsole to send skbs
4897 * without having to re-enable interrupts. It's not called while
4898 * the interrupt routine is executing.
4899 */
4900static void
Malli Chilakala26483452005-04-28 19:44:46 -07004901e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004903 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07004904
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01004906 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004907 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004908#ifndef CONFIG_E1000_NAPI
4909 adapter->clean_rx(adapter, adapter->rx_ring);
4910#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 enable_irq(adapter->pdev->irq);
4912}
4913#endif
4914
Auke Kok90267292006-06-08 09:30:24 -07004915/**
4916 * e1000_io_error_detected - called when PCI error is detected
4917 * @pdev: Pointer to PCI device
4918 * @state: The current pci conneection state
4919 *
4920 * This function is called after a PCI bus error affecting
4921 * this device has been detected.
4922 */
4923static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4924{
4925 struct net_device *netdev = pci_get_drvdata(pdev);
4926 struct e1000_adapter *adapter = netdev->priv;
4927
4928 netif_device_detach(netdev);
4929
4930 if (netif_running(netdev))
4931 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07004932 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07004933
4934 /* Request a slot slot reset. */
4935 return PCI_ERS_RESULT_NEED_RESET;
4936}
4937
4938/**
4939 * e1000_io_slot_reset - called after the pci bus has been reset.
4940 * @pdev: Pointer to PCI device
4941 *
4942 * Restart the card from scratch, as if from a cold-boot. Implementation
4943 * resembles the first-half of the e1000_resume routine.
4944 */
4945static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4946{
4947 struct net_device *netdev = pci_get_drvdata(pdev);
4948 struct e1000_adapter *adapter = netdev->priv;
4949
4950 if (pci_enable_device(pdev)) {
4951 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4952 return PCI_ERS_RESULT_DISCONNECT;
4953 }
4954 pci_set_master(pdev);
4955
Linas Vepstasdbf38c92006-09-27 12:54:11 -07004956 pci_enable_wake(pdev, PCI_D3hot, 0);
4957 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07004958
Auke Kok90267292006-06-08 09:30:24 -07004959 e1000_reset(adapter);
4960 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4961
4962 return PCI_ERS_RESULT_RECOVERED;
4963}
4964
4965/**
4966 * e1000_io_resume - called when traffic can start flowing again.
4967 * @pdev: Pointer to PCI device
4968 *
4969 * This callback is called when the error recovery driver tells us that
4970 * its OK to resume normal operation. Implementation resembles the
4971 * second-half of the e1000_resume routine.
4972 */
4973static void e1000_io_resume(struct pci_dev *pdev)
4974{
4975 struct net_device *netdev = pci_get_drvdata(pdev);
4976 struct e1000_adapter *adapter = netdev->priv;
4977 uint32_t manc, swsm;
4978
4979 if (netif_running(netdev)) {
4980 if (e1000_up(adapter)) {
4981 printk("e1000: can't bring device back up after reset\n");
4982 return;
4983 }
4984 }
4985
4986 netif_device_attach(netdev);
4987
4988 if (adapter->hw.mac_type >= e1000_82540 &&
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004989 adapter->hw.mac_type < e1000_82571 &&
Auke Kok90267292006-06-08 09:30:24 -07004990 adapter->hw.media_type == e1000_media_type_copper) {
4991 manc = E1000_READ_REG(&adapter->hw, MANC);
4992 manc &= ~(E1000_MANC_ARP_EN);
4993 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4994 }
4995
4996 switch (adapter->hw.mac_type) {
4997 case e1000_82573:
4998 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4999 E1000_WRITE_REG(&adapter->hw, SWSM,
5000 swsm | E1000_SWSM_DRV_LOAD);
5001 break;
5002 default:
5003 break;
5004 }
5005
5006 if (netif_running(netdev))
5007 mod_timer(&adapter->watchdog_timer, jiffies);
5008}
5009
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010/* e1000_main.c */