blob: 7b1c092d921c956bc02bff661afb7000ca25d442 [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),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 /* required last entry */
107 {0,}
108};
109
110MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
111
Nicholas Nunley35574762006-09-27 12:53:34 -0700112int e1000_up(struct e1000_adapter *adapter);
113void e1000_down(struct e1000_adapter *adapter);
114void e1000_reinit_locked(struct e1000_adapter *adapter);
115void e1000_reset(struct e1000_adapter *adapter);
116int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
117int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
118int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
119void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
120void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100121static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700122 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100123static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700124 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100125static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700126 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100127static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700128 struct e1000_rx_ring *rx_ring);
129void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131static int e1000_init_module(void);
132static void e1000_exit_module(void);
133static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
134static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400135static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136static int e1000_sw_init(struct e1000_adapter *adapter);
137static int e1000_open(struct net_device *netdev);
138static int e1000_close(struct net_device *netdev);
139static void e1000_configure_tx(struct e1000_adapter *adapter);
140static void e1000_configure_rx(struct e1000_adapter *adapter);
141static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400142static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
143static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
144static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
145 struct e1000_tx_ring *tx_ring);
146static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static void e1000_set_multi(struct net_device *netdev);
149static void e1000_update_phy_info(unsigned long data);
150static void e1000_watchdog(unsigned long data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151static void e1000_82547_tx_fifo_stall(unsigned long data);
152static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
153static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
154static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
155static int e1000_set_mac(struct net_device *netdev, void *p);
David Howells7d12e782006-10-05 14:55:46 +0100156static irqreturn_t e1000_intr(int irq, void *data);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400157static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
158 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400160static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400162 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700164static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400165 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700166 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400168static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
169 struct e1000_rx_ring *rx_ring);
170static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
171 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400173static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800174 struct e1000_rx_ring *rx_ring,
175 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400176static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800177 struct e1000_rx_ring *rx_ring,
178 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
180static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
181 int cmd);
Nicholas Nunley35574762006-09-27 12:53:34 -0700182void e1000_set_ethtool_ops(struct net_device *netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
184static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
185static void e1000_tx_timeout(struct net_device *dev);
Jeff Kirsher87041632006-03-02 18:21:24 -0800186static void e1000_reset_task(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700188static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
189 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
192static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
193static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
194static void e1000_restore_vlan(struct e1000_adapter *adapter);
195
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700196static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Auke Kok6fdfef12006-06-27 09:06:36 -0700197#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198static int e1000_resume(struct pci_dev *pdev);
199#endif
Auke Kokc653e632006-05-23 13:35:57 -0700200static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202#ifdef CONFIG_NET_POLL_CONTROLLER
203/* for netdump / net console */
204static void e1000_netpoll (struct net_device *netdev);
205#endif
206
Nicholas Nunley35574762006-09-27 12:53:34 -0700207extern void e1000_check_options(struct e1000_adapter *adapter);
208
Auke Kok90267292006-06-08 09:30:24 -0700209static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
210 pci_channel_state_t state);
211static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
212static void e1000_io_resume(struct pci_dev *pdev);
213
214static struct pci_error_handlers e1000_err_handler = {
215 .error_detected = e1000_io_error_detected,
216 .slot_reset = e1000_io_slot_reset,
217 .resume = e1000_io_resume,
218};
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220static struct pci_driver e1000_driver = {
221 .name = e1000_driver_name,
222 .id_table = e1000_pci_tbl,
223 .probe = e1000_probe,
224 .remove = __devexit_p(e1000_remove),
Auke Kokc4e24f02006-09-27 12:53:19 -0700225#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 /* Power Managment Hooks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 .suspend = e1000_suspend,
Auke Kokc653e632006-05-23 13:35:57 -0700228 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#endif
Auke Kok90267292006-06-08 09:30:24 -0700230 .shutdown = e1000_shutdown,
231 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
233
234MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
235MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
236MODULE_LICENSE("GPL");
237MODULE_VERSION(DRV_VERSION);
238
239static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
240module_param(debug, int, 0);
241MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
242
243/**
244 * e1000_init_module - Driver Registration Routine
245 *
246 * e1000_init_module is the first routine called when the driver is
247 * loaded. All it does is register with the PCI subsystem.
248 **/
249
250static int __init
251e1000_init_module(void)
252{
253 int ret;
254 printk(KERN_INFO "%s - version %s\n",
255 e1000_driver_string, e1000_driver_version);
256
257 printk(KERN_INFO "%s\n", e1000_copyright);
258
Jeff Garzik29917622006-08-19 17:48:59 -0400259 ret = pci_register_driver(&e1000_driver);
Tony Luck8b378de2005-07-28 01:07:38 -0700260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return ret;
262}
263
264module_init(e1000_init_module);
265
266/**
267 * e1000_exit_module - Driver Exit Cleanup Routine
268 *
269 * e1000_exit_module is called just before the driver is removed
270 * from memory.
271 **/
272
273static void __exit
274e1000_exit_module(void)
275{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 pci_unregister_driver(&e1000_driver);
277}
278
279module_exit(e1000_exit_module);
280
Auke Kok2db10a02006-06-27 09:06:28 -0700281static int e1000_request_irq(struct e1000_adapter *adapter)
282{
283 struct net_device *netdev = adapter->netdev;
284 int flags, err = 0;
285
Jeff Garzikc0bc8722006-07-05 14:32:39 -0400286 flags = IRQF_SHARED;
Auke Kok2db10a02006-06-27 09:06:28 -0700287#ifdef CONFIG_PCI_MSI
288 if (adapter->hw.mac_type > e1000_82547_rev_2) {
289 adapter->have_msi = TRUE;
290 if ((err = pci_enable_msi(adapter->pdev))) {
291 DPRINTK(PROBE, ERR,
292 "Unable to allocate MSI interrupt Error: %d\n", err);
293 adapter->have_msi = FALSE;
294 }
295 }
296 if (adapter->have_msi)
Andrew Morton61ef5c02006-07-06 23:58:19 -0700297 flags &= ~IRQF_SHARED;
Auke Kok2db10a02006-06-27 09:06:28 -0700298#endif
299 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
300 netdev->name, netdev)))
301 DPRINTK(PROBE, ERR,
302 "Unable to allocate interrupt Error: %d\n", err);
303
304 return err;
305}
306
307static void e1000_free_irq(struct e1000_adapter *adapter)
308{
309 struct net_device *netdev = adapter->netdev;
310
311 free_irq(adapter->pdev->irq, netdev);
312
313#ifdef CONFIG_PCI_MSI
314 if (adapter->have_msi)
315 pci_disable_msi(adapter->pdev);
316#endif
317}
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319/**
320 * e1000_irq_disable - Mask off interrupt generation on the NIC
321 * @adapter: board private structure
322 **/
323
Auke Koke619d522006-04-14 19:04:52 -0700324static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325e1000_irq_disable(struct e1000_adapter *adapter)
326{
327 atomic_inc(&adapter->irq_sem);
328 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
329 E1000_WRITE_FLUSH(&adapter->hw);
330 synchronize_irq(adapter->pdev->irq);
331}
332
333/**
334 * e1000_irq_enable - Enable default interrupt generation settings
335 * @adapter: board private structure
336 **/
337
Auke Koke619d522006-04-14 19:04:52 -0700338static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339e1000_irq_enable(struct e1000_adapter *adapter)
340{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800341 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
343 E1000_WRITE_FLUSH(&adapter->hw);
344 }
345}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100346
347static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700348e1000_update_mng_vlan(struct e1000_adapter *adapter)
349{
350 struct net_device *netdev = adapter->netdev;
351 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
352 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800353 if (adapter->vlgrp) {
354 if (!adapter->vlgrp->vlan_devices[vid]) {
355 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700356 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
357 e1000_vlan_rx_add_vid(netdev, vid);
358 adapter->mng_vlan_id = vid;
359 } else
360 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800361
362 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
363 (vid != old_vid) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700364 !adapter->vlgrp->vlan_devices[old_vid])
365 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800366 } else
367 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700368 }
369}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800370
371/**
372 * e1000_release_hw_control - release control of the h/w to f/w
373 * @adapter: address of board private structure
374 *
375 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
376 * For ASF and Pass Through versions of f/w this means that the
377 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800378 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700379 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800380 **/
381
Auke Koke619d522006-04-14 19:04:52 -0700382static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800383e1000_release_hw_control(struct e1000_adapter *adapter)
384{
385 uint32_t ctrl_ext;
386 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700387 uint32_t extcnf;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800388
389 /* Let firmware taken over control of h/w */
390 switch (adapter->hw.mac_type) {
391 case e1000_82571:
392 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700393 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800394 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
395 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
396 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
397 break;
398 case e1000_82573:
399 swsm = E1000_READ_REG(&adapter->hw, SWSM);
400 E1000_WRITE_REG(&adapter->hw, SWSM,
401 swsm & ~E1000_SWSM_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700402 case e1000_ich8lan:
403 extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
404 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
405 extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
406 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800407 default:
408 break;
409 }
410}
411
412/**
413 * e1000_get_hw_control - get control of the h/w from f/w
414 * @adapter: address of board private structure
415 *
416 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700417 * For ASF and Pass Through versions of f/w this means that
418 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800419 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700420 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800421 **/
422
Auke Koke619d522006-04-14 19:04:52 -0700423static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800424e1000_get_hw_control(struct e1000_adapter *adapter)
425{
426 uint32_t ctrl_ext;
427 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700428 uint32_t extcnf;
Auke Kok90fb5132006-11-01 08:47:30 -0800429
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800430 /* Let firmware know the driver has taken over */
431 switch (adapter->hw.mac_type) {
432 case e1000_82571:
433 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700434 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800435 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
436 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
437 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
438 break;
439 case e1000_82573:
440 swsm = E1000_READ_REG(&adapter->hw, SWSM);
441 E1000_WRITE_REG(&adapter->hw, SWSM,
442 swsm | E1000_SWSM_DRV_LOAD);
443 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700444 case e1000_ich8lan:
445 extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
446 E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
447 extcnf | E1000_EXTCNF_CTRL_SWFLAG);
448 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800449 default:
450 break;
451 }
452}
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454int
455e1000_up(struct e1000_adapter *adapter)
456{
457 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700458 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 /* hardware has been reset, we need to reload some things */
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 e1000_set_multi(netdev);
463
464 e1000_restore_vlan(adapter);
465
466 e1000_configure_tx(adapter);
467 e1000_setup_rctl(adapter);
468 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800469 /* call E1000_DESC_UNUSED which always leaves
470 * at least 1 descriptor unused to make sure
471 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800472 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800473 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800474 adapter->alloc_rx_buf(adapter, ring,
475 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800478 adapter->tx_queue_len = netdev->tx_queue_len;
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#ifdef CONFIG_E1000_NAPI
481 netif_poll_enable(netdev);
482#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700483 e1000_irq_enable(adapter);
484
Auke Kok1314bbf2006-09-27 12:54:02 -0700485 clear_bit(__E1000_DOWN, &adapter->flags);
486
487 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return 0;
489}
490
Auke Kok79f05bf2006-06-27 09:06:32 -0700491/**
492 * e1000_power_up_phy - restore link in case the phy was powered down
493 * @adapter: address of board private structure
494 *
495 * The phy may be powered down to save power and turn off link when the
496 * driver is unloaded and wake on lan is not enabled (among others)
497 * *** this routine MUST be followed by a call to e1000_reset ***
498 *
499 **/
500
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700501void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700502{
503 uint16_t mii_reg = 0;
504
505 /* Just clear the power down bit to wake the phy back up */
506 if (adapter->hw.media_type == e1000_media_type_copper) {
507 /* according to the manual, the phy will retain its
508 * settings across a power-down/up cycle */
509 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
510 mii_reg &= ~MII_CR_POWER_DOWN;
511 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
512 }
513}
514
515static void e1000_power_down_phy(struct e1000_adapter *adapter)
516{
Bruce Allan61c25052006-09-27 12:53:54 -0700517 /* Power down the PHY so no link is implied when interface is down *
518 * The PHY cannot be powered down if any of the following is TRUE *
Auke Kok79f05bf2006-06-27 09:06:32 -0700519 * (a) WoL is enabled
520 * (b) AMT is active
521 * (c) SoL/IDER session is active */
522 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700523 adapter->hw.media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700524 uint16_t mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700525
526 switch (adapter->hw.mac_type) {
527 case e1000_82540:
528 case e1000_82545:
529 case e1000_82545_rev_3:
530 case e1000_82546:
531 case e1000_82546_rev_3:
532 case e1000_82541:
533 case e1000_82541_rev_2:
534 case e1000_82547:
535 case e1000_82547_rev_2:
536 if (E1000_READ_REG(&adapter->hw, MANC) &
537 E1000_MANC_SMBUS_EN)
538 goto out;
539 break;
540 case e1000_82571:
541 case e1000_82572:
542 case e1000_82573:
543 case e1000_80003es2lan:
544 case e1000_ich8lan:
545 if (e1000_check_mng_mode(&adapter->hw) ||
546 e1000_check_phy_reset_block(&adapter->hw))
547 goto out;
548 break;
549 default:
550 goto out;
551 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700552 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
553 mii_reg |= MII_CR_POWER_DOWN;
554 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
555 mdelay(1);
556 }
Bruce Allan61c25052006-09-27 12:53:54 -0700557out:
558 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700559}
560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561void
562e1000_down(struct e1000_adapter *adapter)
563{
564 struct net_device *netdev = adapter->netdev;
565
Auke Kok1314bbf2006-09-27 12:54:02 -0700566 /* signal that we're down so the interrupt handler does not
567 * reschedule our watchdog timer */
568 set_bit(__E1000_DOWN, &adapter->flags);
569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 del_timer_sync(&adapter->tx_fifo_stall_timer);
573 del_timer_sync(&adapter->watchdog_timer);
574 del_timer_sync(&adapter->phy_info_timer);
575
576#ifdef CONFIG_E1000_NAPI
577 netif_poll_disable(netdev);
578#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800579 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 adapter->link_speed = 0;
581 adapter->link_duplex = 0;
582 netif_carrier_off(netdev);
583 netif_stop_queue(netdev);
584
585 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400586 e1000_clean_all_tx_rings(adapter);
587 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590void
Auke Kok2db10a02006-06-27 09:06:28 -0700591e1000_reinit_locked(struct e1000_adapter *adapter)
592{
593 WARN_ON(in_interrupt());
594 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
595 msleep(1);
596 e1000_down(adapter);
597 e1000_up(adapter);
598 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
601void
602e1000_reset(struct e1000_adapter *adapter)
603{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700604 uint32_t pba, manc;
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700605#ifdef DISABLE_MULR
606 uint32_t tctl;
607#endif
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#ifdef DISABLE_MULR
675 /* disable Multiple Reads in Transmit Control Register for debugging */
676 tctl = E1000_READ_REG(hw, TCTL);
677 E1000_WRITE_REG(hw, TCTL, tctl & ~E1000_TCTL_MULR);
678
679#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800680 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700682 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
684 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
685
686 e1000_reset_adaptive(&adapter->hw);
687 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700688
689 if (!adapter->smart_power_down &&
690 (adapter->hw.mac_type == e1000_82571 ||
691 adapter->hw.mac_type == e1000_82572)) {
692 uint16_t phy_data = 0;
693 /* speed up time to link by disabling smart power down, ignore
694 * the return value of this function because there is nothing
695 * different we would do if it failed */
696 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
697 &phy_data);
698 phy_data &= ~IGP02E1000_PM_SPD;
699 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
700 phy_data);
701 }
702
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -0700703 if ((adapter->en_mng_pt) &&
704 (adapter->hw.mac_type >= e1000_82540) &&
705 (adapter->hw.mac_type < e1000_82571) &&
706 (adapter->hw.media_type == e1000_media_type_copper)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700707 manc = E1000_READ_REG(&adapter->hw, MANC);
708 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
709 E1000_WRITE_REG(&adapter->hw, MANC, manc);
710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
712
713/**
714 * e1000_probe - Device Initialization Routine
715 * @pdev: PCI device information struct
716 * @ent: entry in e1000_pci_tbl
717 *
718 * Returns 0 on success, negative on failure
719 *
720 * e1000_probe initializes an adapter identified by a pci_dev structure.
721 * The OS initialization, configuring of the adapter private structure,
722 * and a hardware reset occur.
723 **/
724
725static int __devinit
726e1000_probe(struct pci_dev *pdev,
727 const struct pci_device_id *ent)
728{
729 struct net_device *netdev;
730 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700731 unsigned long mmio_start, mmio_len;
Auke Kokcd94dd02006-06-27 09:08:22 -0700732 unsigned long flash_start, flash_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700735 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700736 int i, err, pci_using_dac;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700737 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800739 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 return err;
741
Auke Kokcd94dd02006-06-27 09:08:22 -0700742 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
743 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 pci_using_dac = 1;
745 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700746 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
747 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700749 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 }
751 pci_using_dac = 0;
752 }
753
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800754 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700755 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 pci_set_master(pdev);
758
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700759 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700761 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 SET_MODULE_OWNER(netdev);
765 SET_NETDEV_DEV(netdev, &pdev->dev);
766
767 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700768 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 adapter->netdev = netdev;
770 adapter->pdev = pdev;
771 adapter->hw.back = adapter;
772 adapter->msg_enable = (1 << debug) - 1;
773
774 mmio_start = pci_resource_start(pdev, BAR_0);
775 mmio_len = pci_resource_len(pdev, BAR_0);
776
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700777 err = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700779 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800782 for (i = BAR_1; i <= BAR_5; i++) {
783 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800785 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 adapter->hw.io_base = pci_resource_start(pdev, i);
787 break;
788 }
789 }
790
791 netdev->open = &e1000_open;
792 netdev->stop = &e1000_close;
793 netdev->hard_start_xmit = &e1000_xmit_frame;
794 netdev->get_stats = &e1000_get_stats;
795 netdev->set_multicast_list = &e1000_set_multi;
796 netdev->set_mac_address = &e1000_set_mac;
797 netdev->change_mtu = &e1000_change_mtu;
798 netdev->do_ioctl = &e1000_ioctl;
799 e1000_set_ethtool_ops(netdev);
800 netdev->tx_timeout = &e1000_tx_timeout;
801 netdev->watchdog_timeo = 5 * HZ;
802#ifdef CONFIG_E1000_NAPI
803 netdev->poll = &e1000_clean;
804 netdev->weight = 64;
805#endif
806 netdev->vlan_rx_register = e1000_vlan_rx_register;
807 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
808 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
809#ifdef CONFIG_NET_POLL_CONTROLLER
810 netdev->poll_controller = e1000_netpoll;
811#endif
Auke Kok0eb5a342006-09-27 12:53:17 -0700812 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 netdev->mem_start = mmio_start;
815 netdev->mem_end = mmio_start + mmio_len;
816 netdev->base_addr = adapter->hw.io_base;
817
818 adapter->bd_number = cards_found;
819
820 /* setup the private structure */
821
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800822 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 goto err_sw_init;
824
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700825 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -0700826 /* Flash BAR mapping must happen after e1000_sw_init
827 * because it depends on mac_type */
828 if ((adapter->hw.mac_type == e1000_ich8lan) &&
829 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
830 flash_start = pci_resource_start(pdev, 1);
831 flash_len = pci_resource_len(pdev, 1);
832 adapter->hw.flash_address = ioremap(flash_start, flash_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700833 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -0700834 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -0700835 }
836
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700837 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700838 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
839
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800840 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 netdev->features = NETIF_F_SG |
842 NETIF_F_HW_CSUM |
843 NETIF_F_HW_VLAN_TX |
844 NETIF_F_HW_VLAN_RX |
845 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -0700846 if (adapter->hw.mac_type == e1000_ich8lan)
847 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 }
849
850#ifdef NETIF_F_TSO
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800851 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 (adapter->hw.mac_type != e1000_82547))
853 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700854
855#ifdef NETIF_F_TSO_IPV6
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800856 if (adapter->hw.mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700857 netdev->features |= NETIF_F_TSO_IPV6;
858#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800860 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 netdev->features |= NETIF_F_HIGHDMA;
862
Auke Kok76c224b2006-05-23 13:36:06 -0700863 netdev->features |= NETIF_F_LLTX;
864
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700865 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
866
Auke Kokcd94dd02006-06-27 09:08:22 -0700867 /* initialize eeprom parameters */
868
869 if (e1000_init_eeprom_params(&adapter->hw)) {
870 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700871 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -0700872 }
873
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800874 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 e1000_reset_hw(&adapter->hw);
878
879 /* make sure the EEPROM is good */
880
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800881 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 goto err_eeprom;
884 }
885
886 /* copy the MAC address out of the EEPROM */
887
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800888 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
890 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400891 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800893 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 goto err_eeprom;
896 }
897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 e1000_get_bus_info(&adapter->hw);
899
900 init_timer(&adapter->tx_fifo_stall_timer);
901 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
902 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
903
904 init_timer(&adapter->watchdog_timer);
905 adapter->watchdog_timer.function = &e1000_watchdog;
906 adapter->watchdog_timer.data = (unsigned long) adapter;
907
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 init_timer(&adapter->phy_info_timer);
909 adapter->phy_info_timer.function = &e1000_update_phy_info;
910 adapter->phy_info_timer.data = (unsigned long) adapter;
911
Jeff Kirsher87041632006-03-02 18:21:24 -0800912 INIT_WORK(&adapter->reset_task,
913 (void (*)(void *))e1000_reset_task, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 e1000_check_options(adapter);
916
917 /* Initial Wake on LAN setting
918 * If APM wake is enabled in the EEPROM,
919 * enable the ACPI Magic Packet filter
920 */
921
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800922 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 case e1000_82542_rev2_0:
924 case e1000_82542_rev2_1:
925 case e1000_82543:
926 break;
927 case e1000_82544:
928 e1000_read_eeprom(&adapter->hw,
929 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
930 eeprom_apme_mask = E1000_EEPROM_82544_APM;
931 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700932 case e1000_ich8lan:
933 e1000_read_eeprom(&adapter->hw,
934 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
935 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
936 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 case e1000_82546:
938 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500939 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800940 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800941 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 e1000_read_eeprom(&adapter->hw,
943 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
944 break;
945 }
946 /* Fall Through */
947 default:
948 e1000_read_eeprom(&adapter->hw,
949 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
950 break;
951 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800952 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700953 adapter->eeprom_wol |= E1000_WUFC_MAG;
954
955 /* now that we have the eeprom settings, apply the special cases
956 * where the eeprom may be wrong or the board simply won't support
957 * wake on lan on a particular port */
958 switch (pdev->device) {
959 case E1000_DEV_ID_82546GB_PCIE:
960 adapter->eeprom_wol = 0;
961 break;
962 case E1000_DEV_ID_82546EB_FIBER:
963 case E1000_DEV_ID_82546GB_FIBER:
964 case E1000_DEV_ID_82571EB_FIBER:
965 /* Wake events only supported on port A for dual fiber
966 * regardless of eeprom setting */
967 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
968 adapter->eeprom_wol = 0;
969 break;
970 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700971 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700972 /* if quad port adapter, disable WoL on all but port A */
973 if (global_quad_port_a != 0)
974 adapter->eeprom_wol = 0;
975 else
976 adapter->quad_port_a = 1;
977 /* Reset for multiple quad port adapters */
978 if (++global_quad_port_a == 4)
979 global_quad_port_a = 0;
980 break;
981 }
982
983 /* initialize the wol settings based on the eeprom settings */
984 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -0800986 /* print bus type/speed/width info */
987 {
988 struct e1000_hw *hw = &adapter->hw;
989 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
990 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
991 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
992 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
993 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
994 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
995 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
996 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
997 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
998 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
999 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1000 "32-bit"));
1001 }
1002
1003 for (i = 0; i < 6; i++)
1004 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
1005
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 /* reset the hardware with the new settings */
1007 e1000_reset(adapter);
1008
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001009 /* If the controller is 82573 and f/w is AMT, do not set
1010 * DRV_LOAD until the interface is up. For all other cases,
1011 * let the f/w know that the h/w is now under the control
1012 * of the driver. */
1013 if (adapter->hw.mac_type != e1000_82573 ||
1014 !e1000_check_mng_mode(&adapter->hw))
1015 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 strcpy(netdev->name, "eth%d");
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001018 if ((err = register_netdev(netdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 goto err_register;
1020
Auke Kok1314bbf2006-09-27 12:54:02 -07001021 /* tell the stack to leave us alone until e1000_open() is called */
1022 netif_carrier_off(netdev);
1023 netif_stop_queue(netdev);
1024
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1026
1027 cards_found++;
1028 return 0;
1029
1030err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001031 e1000_release_hw_control(adapter);
1032err_eeprom:
1033 if (!e1000_check_phy_reset_block(&adapter->hw))
1034 e1000_phy_hw_reset(&adapter->hw);
1035
Auke Kokcd94dd02006-06-27 09:08:22 -07001036 if (adapter->hw.flash_address)
1037 iounmap(adapter->hw.flash_address);
1038err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001039#ifdef CONFIG_E1000_NAPI
1040 for (i = 0; i < adapter->num_rx_queues; i++)
1041 dev_put(&adapter->polling_netdev[i]);
1042#endif
1043
1044 kfree(adapter->tx_ring);
1045 kfree(adapter->rx_ring);
1046#ifdef CONFIG_E1000_NAPI
1047 kfree(adapter->polling_netdev);
1048#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 iounmap(adapter->hw.hw_addr);
1051err_ioremap:
1052 free_netdev(netdev);
1053err_alloc_etherdev:
1054 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001055err_pci_reg:
1056err_dma:
1057 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 return err;
1059}
1060
1061/**
1062 * e1000_remove - Device Removal Routine
1063 * @pdev: PCI device information struct
1064 *
1065 * e1000_remove is called by the PCI subsystem to alert the driver
1066 * that it should release a PCI device. The could be caused by a
1067 * Hot-Plug event, or because the driver is going to be removed from
1068 * memory.
1069 **/
1070
1071static void __devexit
1072e1000_remove(struct pci_dev *pdev)
1073{
1074 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001075 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001076 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001077#ifdef CONFIG_E1000_NAPI
1078 int i;
1079#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001081 flush_scheduled_work();
1082
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07001083 if (adapter->hw.mac_type >= e1000_82540 &&
1084 adapter->hw.mac_type < e1000_82571 &&
1085 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001087 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 manc |= E1000_MANC_ARP_EN;
1089 E1000_WRITE_REG(&adapter->hw, MANC, manc);
1090 }
1091 }
1092
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001093 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1094 * would have already happened in close and is redundant. */
1095 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001096
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001098#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001099 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001100 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001101#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001103 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001104 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001106 kfree(adapter->tx_ring);
1107 kfree(adapter->rx_ring);
1108#ifdef CONFIG_E1000_NAPI
1109 kfree(adapter->polling_netdev);
1110#endif
1111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001113 if (adapter->hw.flash_address)
1114 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 pci_release_regions(pdev);
1116
1117 free_netdev(netdev);
1118
1119 pci_disable_device(pdev);
1120}
1121
1122/**
1123 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1124 * @adapter: board private structure to initialize
1125 *
1126 * e1000_sw_init initializes the Adapter private data structure.
1127 * Fields are initialized based on PCI device information and
1128 * OS network device settings (MTU size).
1129 **/
1130
1131static int __devinit
1132e1000_sw_init(struct e1000_adapter *adapter)
1133{
1134 struct e1000_hw *hw = &adapter->hw;
1135 struct net_device *netdev = adapter->netdev;
1136 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001137#ifdef CONFIG_E1000_NAPI
1138 int i;
1139#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141 /* PCI config space info */
1142
1143 hw->vendor_id = pdev->vendor;
1144 hw->device_id = pdev->device;
1145 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1146 hw->subsystem_id = pdev->subsystem_device;
1147
1148 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1149
1150 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1151
Auke Kokeb0f8052006-07-14 16:14:48 -07001152 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001153 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 hw->max_frame_size = netdev->mtu +
1155 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1156 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1157
1158 /* identify the MAC */
1159
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001160 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1162 return -EIO;
1163 }
1164
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001165 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 default:
1167 break;
1168 case e1000_82541:
1169 case e1000_82547:
1170 case e1000_82541_rev_2:
1171 case e1000_82547_rev_2:
1172 hw->phy_init_script = 1;
1173 break;
1174 }
1175
1176 e1000_set_media_type(hw);
1177
1178 hw->wait_autoneg_complete = FALSE;
1179 hw->tbi_compatibility_en = TRUE;
1180 hw->adaptive_ifs = TRUE;
1181
1182 /* Copper options */
1183
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001184 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 hw->mdix = AUTO_ALL_MODES;
1186 hw->disable_polarity_correction = FALSE;
1187 hw->master_slave = E1000_MASTER_SLAVE;
1188 }
1189
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001190 adapter->num_tx_queues = 1;
1191 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001192
1193 if (e1000_alloc_queues(adapter)) {
1194 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1195 return -ENOMEM;
1196 }
1197
1198#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001199 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001200 adapter->polling_netdev[i].priv = adapter;
1201 adapter->polling_netdev[i].poll = &e1000_clean;
1202 adapter->polling_netdev[i].weight = 64;
1203 dev_hold(&adapter->polling_netdev[i]);
1204 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1205 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001206 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001207#endif
1208
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 atomic_set(&adapter->irq_sem, 1);
1210 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Auke Kok1314bbf2006-09-27 12:54:02 -07001212 set_bit(__E1000_DOWN, &adapter->flags);
1213
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 return 0;
1215}
1216
1217/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001218 * e1000_alloc_queues - Allocate memory for all rings
1219 * @adapter: board private structure to initialize
1220 *
1221 * We allocate one ring per queue at run-time since we don't know the
1222 * number of queues at compile-time. The polling_netdev array is
1223 * intended for Multiqueue, but should work fine with a single queue.
1224 **/
1225
1226static int __devinit
1227e1000_alloc_queues(struct e1000_adapter *adapter)
1228{
1229 int size;
1230
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001231 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001232 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1233 if (!adapter->tx_ring)
1234 return -ENOMEM;
1235 memset(adapter->tx_ring, 0, size);
1236
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001237 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001238 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1239 if (!adapter->rx_ring) {
1240 kfree(adapter->tx_ring);
1241 return -ENOMEM;
1242 }
1243 memset(adapter->rx_ring, 0, size);
1244
1245#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001246 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001247 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1248 if (!adapter->polling_netdev) {
1249 kfree(adapter->tx_ring);
1250 kfree(adapter->rx_ring);
1251 return -ENOMEM;
1252 }
1253 memset(adapter->polling_netdev, 0, size);
1254#endif
1255
1256 return E1000_SUCCESS;
1257}
1258
1259/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 * e1000_open - Called when a network interface is made active
1261 * @netdev: network interface device structure
1262 *
1263 * Returns 0 on success, negative value on failure
1264 *
1265 * The open entry point is called when a network interface is made
1266 * active by the system (IFF_UP). At this point all resources needed
1267 * for transmit and receive operations are allocated, the interrupt
1268 * handler is registered with the OS, the watchdog timer is started,
1269 * and the stack is notified that the interface is ready.
1270 **/
1271
1272static int
1273e1000_open(struct net_device *netdev)
1274{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001275 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 int err;
1277
Auke Kok2db10a02006-06-27 09:06:28 -07001278 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001279 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001280 return -EBUSY;
1281
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 /* allocate transmit descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001283 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 goto err_setup_tx;
1285
1286 /* allocate receive descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001287 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 goto err_setup_rx;
1289
Auke Kok2db10a02006-06-27 09:06:28 -07001290 err = e1000_request_irq(adapter);
1291 if (err)
Vasily Averin401a5522006-08-28 14:56:19 -07001292 goto err_req_irq;
Auke Kok2db10a02006-06-27 09:06:28 -07001293
Auke Kok79f05bf2006-06-27 09:06:32 -07001294 e1000_power_up_phy(adapter);
1295
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001296 if ((err = e1000_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001298 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001299 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001300 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1301 e1000_update_mng_vlan(adapter);
1302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001304 /* If AMT is enabled, let the firmware know that the network
1305 * interface is now open */
1306 if (adapter->hw.mac_type == e1000_82573 &&
1307 e1000_check_mng_mode(&adapter->hw))
1308 e1000_get_hw_control(adapter);
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 return E1000_SUCCESS;
1311
1312err_up:
Vasily Averin401a5522006-08-28 14:56:19 -07001313 e1000_power_down_phy(adapter);
1314 e1000_free_irq(adapter);
1315err_req_irq:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001316 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001318 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319err_setup_tx:
1320 e1000_reset(adapter);
1321
1322 return err;
1323}
1324
1325/**
1326 * e1000_close - Disables a network interface
1327 * @netdev: network interface device structure
1328 *
1329 * Returns 0, this is not allowed to fail
1330 *
1331 * The close entry point is called when an interface is de-activated
1332 * by the OS. The hardware is still under the drivers control, but
1333 * needs to be disabled. A global MAC reset is issued to stop the
1334 * hardware, and all transmit and receive resources are freed.
1335 **/
1336
1337static int
1338e1000_close(struct net_device *netdev)
1339{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001340 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Auke Kok2db10a02006-06-27 09:06:28 -07001342 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001344 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001345 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001347 e1000_free_all_tx_resources(adapter);
1348 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Bruce Allan46665602006-09-27 12:54:08 -07001350 /* kill manageability vlan ID if supported, but not if a vlan with
1351 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001352 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001353 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1354 !(adapter->vlgrp &&
1355 adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001356 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1357 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001358
1359 /* If AMT is enabled, let the firmware know that the network
1360 * interface is now closed */
1361 if (adapter->hw.mac_type == e1000_82573 &&
1362 e1000_check_mng_mode(&adapter->hw))
1363 e1000_release_hw_control(adapter);
1364
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 return 0;
1366}
1367
1368/**
1369 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1370 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001371 * @start: address of beginning of memory
1372 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 **/
Auke Koke619d522006-04-14 19:04:52 -07001374static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375e1000_check_64k_bound(struct e1000_adapter *adapter,
1376 void *start, unsigned long len)
1377{
1378 unsigned long begin = (unsigned long) start;
1379 unsigned long end = begin + len;
1380
Malli Chilakala26483452005-04-28 19:44:46 -07001381 /* First rev 82545 and 82546 need to not allow any memory
1382 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001384 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1386 }
1387
1388 return TRUE;
1389}
1390
1391/**
1392 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1393 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001394 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 *
1396 * Return 0 on success, negative on failure
1397 **/
1398
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001399static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001400e1000_setup_tx_resources(struct e1000_adapter *adapter,
1401 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 struct pci_dev *pdev = adapter->pdev;
1404 int size;
1405
1406 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001407 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001408 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001409 DPRINTK(PROBE, ERR,
1410 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 return -ENOMEM;
1412 }
1413 memset(txdr->buffer_info, 0, size);
1414
1415 /* round up to nearest 4K */
1416
1417 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1418 E1000_ROUNDUP(txdr->size, 4096);
1419
1420 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001421 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001424 DPRINTK(PROBE, ERR,
1425 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 return -ENOMEM;
1427 }
1428
Malli Chilakala26483452005-04-28 19:44:46 -07001429 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1431 void *olddesc = txdr->desc;
1432 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001433 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1434 "at %p\n", txdr->size, txdr->desc);
1435 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001437 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001438 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1440 goto setup_tx_desc_die;
1441 }
1442
1443 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1444 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001445 pci_free_consistent(pdev, txdr->size, txdr->desc,
1446 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1448 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001449 "Unable to allocate aligned memory "
1450 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 vfree(txdr->buffer_info);
1452 return -ENOMEM;
1453 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001454 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1456 }
1457 }
1458 memset(txdr->desc, 0, txdr->size);
1459
1460 txdr->next_to_use = 0;
1461 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001462 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464 return 0;
1465}
1466
1467/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001468 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1469 * (Descriptors) for all queues
1470 * @adapter: board private structure
1471 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001472 * Return 0 on success, negative on failure
1473 **/
1474
1475int
1476e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1477{
1478 int i, err = 0;
1479
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001480 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001481 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1482 if (err) {
1483 DPRINTK(PROBE, ERR,
1484 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001485 for (i-- ; i >= 0; i--)
1486 e1000_free_tx_resources(adapter,
1487 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001488 break;
1489 }
1490 }
1491
1492 return err;
1493}
1494
1495/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1497 * @adapter: board private structure
1498 *
1499 * Configure the Tx unit of the MAC after a reset.
1500 **/
1501
1502static void
1503e1000_configure_tx(struct e1000_adapter *adapter)
1504{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001505 uint64_t tdba;
1506 struct e1000_hw *hw = &adapter->hw;
1507 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001508 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 /* Setup the HW Tx Head and Tail descriptor pointers */
1511
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001512 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001513 case 1:
1514 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001515 tdba = adapter->tx_ring[0].dma;
1516 tdlen = adapter->tx_ring[0].count *
1517 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001518 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001519 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1520 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001521 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001522 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001523 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1524 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001525 break;
1526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528 /* Set the default values for the Tx Inter Packet Gap timer */
1529
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001530 if (hw->media_type == e1000_media_type_fiber ||
1531 hw->media_type == e1000_media_type_internal_serdes)
1532 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1533 else
1534 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1535
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001536 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 case e1000_82542_rev2_0:
1538 case e1000_82542_rev2_1:
1539 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001540 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1541 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001543 case e1000_80003es2lan:
1544 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1545 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1546 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001548 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1549 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1550 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001552 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1553 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001554 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 /* Set the Tx Interrupt Delay register */
1557
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001558 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1559 if (hw->mac_type >= e1000_82540)
1560 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
1562 /* Program the Transmit Control Register */
1563
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001564 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001566 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1568
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001569 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1570 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001571 /* set the speed mode bit, we'll clear it if we're not at
1572 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001573 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001574 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001575 } else if (hw->mac_type == e1000_80003es2lan) {
1576 tarc = E1000_READ_REG(hw, TARC0);
1577 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001578 E1000_WRITE_REG(hw, TARC0, tarc);
1579 tarc = E1000_READ_REG(hw, TARC1);
1580 tarc |= 1;
1581 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001582 }
1583
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001584 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
1586 /* Setup Transmit Descriptor Settings for eop descriptor */
1587 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1588 E1000_TXD_CMD_IFCS;
1589
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001590 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1592 else
1593 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1594
1595 /* Cache if we're 82544 running in PCI-X because we'll
1596 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001597 if (hw->mac_type == e1000_82544 &&
1598 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001600
1601 E1000_WRITE_REG(hw, TCTL, tctl);
1602
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
1605/**
1606 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1607 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001608 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 *
1610 * Returns 0 on success, negative on failure
1611 **/
1612
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001613static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001614e1000_setup_rx_resources(struct e1000_adapter *adapter,
1615 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001618 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
1620 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001621 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001622 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001623 DPRINTK(PROBE, ERR,
1624 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 return -ENOMEM;
1626 }
1627 memset(rxdr->buffer_info, 0, size);
1628
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001629 size = sizeof(struct e1000_ps_page) * rxdr->count;
1630 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001631 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001632 vfree(rxdr->buffer_info);
1633 DPRINTK(PROBE, ERR,
1634 "Unable to allocate memory for the receive descriptor ring\n");
1635 return -ENOMEM;
1636 }
1637 memset(rxdr->ps_page, 0, size);
1638
1639 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1640 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001641 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001642 vfree(rxdr->buffer_info);
1643 kfree(rxdr->ps_page);
1644 DPRINTK(PROBE, ERR,
1645 "Unable to allocate memory for the receive descriptor ring\n");
1646 return -ENOMEM;
1647 }
1648 memset(rxdr->ps_page_dma, 0, size);
1649
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001650 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001651 desc_len = sizeof(struct e1000_rx_desc);
1652 else
1653 desc_len = sizeof(union e1000_rx_desc_packet_split);
1654
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 /* Round up to nearest 4K */
1656
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001657 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 E1000_ROUNDUP(rxdr->size, 4096);
1659
1660 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1661
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001662 if (!rxdr->desc) {
1663 DPRINTK(PROBE, ERR,
1664 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001667 kfree(rxdr->ps_page);
1668 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 return -ENOMEM;
1670 }
1671
Malli Chilakala26483452005-04-28 19:44:46 -07001672 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1674 void *olddesc = rxdr->desc;
1675 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001676 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1677 "at %p\n", rxdr->size, rxdr->desc);
1678 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001680 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001681 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001683 DPRINTK(PROBE, ERR,
1684 "Unable to allocate memory "
1685 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 goto setup_rx_desc_die;
1687 }
1688
1689 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1690 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001691 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1692 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001694 DPRINTK(PROBE, ERR,
1695 "Unable to allocate aligned memory "
1696 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001697 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001699 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1701 }
1702 }
1703 memset(rxdr->desc, 0, rxdr->size);
1704
1705 rxdr->next_to_clean = 0;
1706 rxdr->next_to_use = 0;
1707
1708 return 0;
1709}
1710
1711/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001712 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1713 * (Descriptors) for all queues
1714 * @adapter: board private structure
1715 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001716 * Return 0 on success, negative on failure
1717 **/
1718
1719int
1720e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1721{
1722 int i, err = 0;
1723
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001724 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001725 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1726 if (err) {
1727 DPRINTK(PROBE, ERR,
1728 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001729 for (i-- ; i >= 0; i--)
1730 e1000_free_rx_resources(adapter,
1731 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001732 break;
1733 }
1734 }
1735
1736 return err;
1737}
1738
1739/**
Malli Chilakala26483452005-04-28 19:44:46 -07001740 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 * @adapter: Board private structure
1742 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001743#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1744 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745static void
1746e1000_setup_rctl(struct e1000_adapter *adapter)
1747{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001748 uint32_t rctl, rfctl;
1749 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001750#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001751 uint32_t pages = 0;
1752#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
1754 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1755
1756 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1757
1758 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1759 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1760 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1761
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001762 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 rctl |= E1000_RCTL_SBP;
1764 else
1765 rctl &= ~E1000_RCTL_SBP;
1766
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001767 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1768 rctl &= ~E1000_RCTL_LPE;
1769 else
1770 rctl |= E1000_RCTL_LPE;
1771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001773 rctl &= ~E1000_RCTL_SZ_4096;
1774 rctl |= E1000_RCTL_BSEX;
1775 switch (adapter->rx_buffer_len) {
1776 case E1000_RXBUFFER_256:
1777 rctl |= E1000_RCTL_SZ_256;
1778 rctl &= ~E1000_RCTL_BSEX;
1779 break;
1780 case E1000_RXBUFFER_512:
1781 rctl |= E1000_RCTL_SZ_512;
1782 rctl &= ~E1000_RCTL_BSEX;
1783 break;
1784 case E1000_RXBUFFER_1024:
1785 rctl |= E1000_RCTL_SZ_1024;
1786 rctl &= ~E1000_RCTL_BSEX;
1787 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001788 case E1000_RXBUFFER_2048:
1789 default:
1790 rctl |= E1000_RCTL_SZ_2048;
1791 rctl &= ~E1000_RCTL_BSEX;
1792 break;
1793 case E1000_RXBUFFER_4096:
1794 rctl |= E1000_RCTL_SZ_4096;
1795 break;
1796 case E1000_RXBUFFER_8192:
1797 rctl |= E1000_RCTL_SZ_8192;
1798 break;
1799 case E1000_RXBUFFER_16384:
1800 rctl |= E1000_RCTL_SZ_16384;
1801 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001802 }
1803
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001804#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001805 /* 82571 and greater support packet-split where the protocol
1806 * header is placed in skb->data and the packet data is
1807 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1808 * In the case of a non-split, skb->data is linearly filled,
1809 * followed by the page buffers. Therefore, skb->data is
1810 * sized to hold the largest protocol header.
1811 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001812 /* allocations using alloc_page take too long for regular MTU
1813 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001814 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001815 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1816 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001817 adapter->rx_ps_pages = pages;
1818 else
1819 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001820#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001821 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001822 /* Configure extra packet-split registers */
1823 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1824 rfctl |= E1000_RFCTL_EXTEN;
1825 /* disable IPv6 packet split support */
1826 rfctl |= E1000_RFCTL_IPV6_DIS;
1827 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1828
Auke Kok7dfee0c2006-06-27 09:07:50 -07001829 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001830
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001831 psrctl |= adapter->rx_ps_bsize0 >>
1832 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001833
1834 switch (adapter->rx_ps_pages) {
1835 case 3:
1836 psrctl |= PAGE_SIZE <<
1837 E1000_PSRCTL_BSIZE3_SHIFT;
1838 case 2:
1839 psrctl |= PAGE_SIZE <<
1840 E1000_PSRCTL_BSIZE2_SHIFT;
1841 case 1:
1842 psrctl |= PAGE_SIZE >>
1843 E1000_PSRCTL_BSIZE1_SHIFT;
1844 break;
1845 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001846
1847 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 }
1849
1850 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1851}
1852
1853/**
1854 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1855 * @adapter: board private structure
1856 *
1857 * Configure the Rx unit of the MAC after a reset.
1858 **/
1859
1860static void
1861e1000_configure_rx(struct e1000_adapter *adapter)
1862{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001863 uint64_t rdba;
1864 struct e1000_hw *hw = &adapter->hw;
1865 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001866
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001867 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001868 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001869 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001870 sizeof(union e1000_rx_desc_packet_split);
1871 adapter->clean_rx = e1000_clean_rx_irq_ps;
1872 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1873 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001874 rdlen = adapter->rx_ring[0].count *
1875 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001876 adapter->clean_rx = e1000_clean_rx_irq;
1877 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1878 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
1880 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001881 rctl = E1000_READ_REG(hw, RCTL);
1882 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
1884 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001885 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001887 if (hw->mac_type >= e1000_82540) {
1888 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001889 if (adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001890 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 1000000000 / (adapter->itr * 256));
1892 }
1893
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001894 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001895 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001896 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07001897 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001898#ifdef CONFIG_E1000_NAPI
1899 /* Auto-Mask interrupts upon ICR read. */
1900 ctrl_ext |= E1000_CTRL_EXT_IAME;
1901#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001902 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001903 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001904 E1000_WRITE_FLUSH(hw);
1905 }
1906
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001907 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1908 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001909 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001910 case 1:
1911 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001912 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001913 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001914 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1915 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001916 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001917 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001918 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
1919 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001920 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001921 }
1922
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001924 if (hw->mac_type >= e1000_82543) {
1925 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001926 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001927 rxcsum |= E1000_RXCSUM_TUOFL;
1928
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001929 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001930 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001931 if ((hw->mac_type >= e1000_82571) &&
1932 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001933 rxcsum |= E1000_RXCSUM_IPPCSE;
1934 }
1935 } else {
1936 rxcsum &= ~E1000_RXCSUM_TUOFL;
1937 /* don't need to clear IPPCSE as it defaults to 0 */
1938 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001939 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 }
1941
1942 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001943 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944}
1945
1946/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001947 * e1000_free_tx_resources - Free Tx Resources per Queue
1948 * @adapter: board private structure
1949 * @tx_ring: Tx descriptor ring for a specific queue
1950 *
1951 * Free all transmit software resources
1952 **/
1953
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001954static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001955e1000_free_tx_resources(struct e1000_adapter *adapter,
1956 struct e1000_tx_ring *tx_ring)
1957{
1958 struct pci_dev *pdev = adapter->pdev;
1959
1960 e1000_clean_tx_ring(adapter, tx_ring);
1961
1962 vfree(tx_ring->buffer_info);
1963 tx_ring->buffer_info = NULL;
1964
1965 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1966
1967 tx_ring->desc = NULL;
1968}
1969
1970/**
1971 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 * @adapter: board private structure
1973 *
1974 * Free all transmit software resources
1975 **/
1976
1977void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001978e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001980 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001982 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001983 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984}
1985
Auke Koke619d522006-04-14 19:04:52 -07001986static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1988 struct e1000_buffer *buffer_info)
1989{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001990 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001991 pci_unmap_page(adapter->pdev,
1992 buffer_info->dma,
1993 buffer_info->length,
1994 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08001996 if (buffer_info->skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 dev_kfree_skb_any(buffer_info->skb);
Jeff Kirsher8241e352006-01-12 16:51:34 -08001998 memset(buffer_info, 0, sizeof(struct e1000_buffer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999}
2000
2001/**
2002 * e1000_clean_tx_ring - Free Tx Buffers
2003 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002004 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 **/
2006
2007static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002008e1000_clean_tx_ring(struct e1000_adapter *adapter,
2009 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 struct e1000_buffer *buffer_info;
2012 unsigned long size;
2013 unsigned int i;
2014
2015 /* Free all the Tx ring sk_buffs */
2016
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002017 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 buffer_info = &tx_ring->buffer_info[i];
2019 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2020 }
2021
2022 size = sizeof(struct e1000_buffer) * tx_ring->count;
2023 memset(tx_ring->buffer_info, 0, size);
2024
2025 /* Zero out the descriptor ring */
2026
2027 memset(tx_ring->desc, 0, tx_ring->size);
2028
2029 tx_ring->next_to_use = 0;
2030 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002031 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002033 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2034 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2035}
2036
2037/**
2038 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2039 * @adapter: board private structure
2040 **/
2041
2042static void
2043e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2044{
2045 int i;
2046
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002047 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002048 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
2051/**
2052 * e1000_free_rx_resources - Free Rx Resources
2053 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002054 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 *
2056 * Free all receive software resources
2057 **/
2058
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002059static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002060e1000_free_rx_resources(struct e1000_adapter *adapter,
2061 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 struct pci_dev *pdev = adapter->pdev;
2064
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002065 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
2067 vfree(rx_ring->buffer_info);
2068 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002069 kfree(rx_ring->ps_page);
2070 rx_ring->ps_page = NULL;
2071 kfree(rx_ring->ps_page_dma);
2072 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
2074 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2075
2076 rx_ring->desc = NULL;
2077}
2078
2079/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002080 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002082 *
2083 * Free all receive software resources
2084 **/
2085
2086void
2087e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2088{
2089 int i;
2090
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002091 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002092 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2093}
2094
2095/**
2096 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2097 * @adapter: board private structure
2098 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 **/
2100
2101static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002102e1000_clean_rx_ring(struct e1000_adapter *adapter,
2103 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002106 struct e1000_ps_page *ps_page;
2107 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 struct pci_dev *pdev = adapter->pdev;
2109 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002110 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
2112 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002113 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002115 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 pci_unmap_single(pdev,
2117 buffer_info->dma,
2118 buffer_info->length,
2119 PCI_DMA_FROMDEVICE);
2120
2121 dev_kfree_skb(buffer_info->skb);
2122 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002123 }
2124 ps_page = &rx_ring->ps_page[i];
2125 ps_page_dma = &rx_ring->ps_page_dma[i];
2126 for (j = 0; j < adapter->rx_ps_pages; j++) {
2127 if (!ps_page->ps_page[j]) break;
2128 pci_unmap_page(pdev,
2129 ps_page_dma->ps_page_dma[j],
2130 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2131 ps_page_dma->ps_page_dma[j] = 0;
2132 put_page(ps_page->ps_page[j]);
2133 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 }
2135 }
2136
2137 size = sizeof(struct e1000_buffer) * rx_ring->count;
2138 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002139 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2140 memset(rx_ring->ps_page, 0, size);
2141 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2142 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
2144 /* Zero out the descriptor ring */
2145
2146 memset(rx_ring->desc, 0, rx_ring->size);
2147
2148 rx_ring->next_to_clean = 0;
2149 rx_ring->next_to_use = 0;
2150
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002151 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2152 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2153}
2154
2155/**
2156 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2157 * @adapter: board private structure
2158 **/
2159
2160static void
2161e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2162{
2163 int i;
2164
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002165 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002166 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167}
2168
2169/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2170 * and memory write and invalidate disabled for certain operations
2171 */
2172static void
2173e1000_enter_82542_rst(struct e1000_adapter *adapter)
2174{
2175 struct net_device *netdev = adapter->netdev;
2176 uint32_t rctl;
2177
2178 e1000_pci_clear_mwi(&adapter->hw);
2179
2180 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2181 rctl |= E1000_RCTL_RST;
2182 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2183 E1000_WRITE_FLUSH(&adapter->hw);
2184 mdelay(5);
2185
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002186 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002187 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
2190static void
2191e1000_leave_82542_rst(struct e1000_adapter *adapter)
2192{
2193 struct net_device *netdev = adapter->netdev;
2194 uint32_t rctl;
2195
2196 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2197 rctl &= ~E1000_RCTL_RST;
2198 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2199 E1000_WRITE_FLUSH(&adapter->hw);
2200 mdelay(5);
2201
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002202 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 e1000_pci_set_mwi(&adapter->hw);
2204
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002205 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002206 /* No need to loop, because 82542 supports only 1 queue */
2207 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002208 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002209 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 }
2211}
2212
2213/**
2214 * e1000_set_mac - Change the Ethernet Address of the NIC
2215 * @netdev: network interface device structure
2216 * @p: pointer to an address structure
2217 *
2218 * Returns 0 on success, negative on failure
2219 **/
2220
2221static int
2222e1000_set_mac(struct net_device *netdev, void *p)
2223{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002224 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 struct sockaddr *addr = p;
2226
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002227 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 return -EADDRNOTAVAIL;
2229
2230 /* 82542 2.0 needs to be in reset to write receive address registers */
2231
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002232 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 e1000_enter_82542_rst(adapter);
2234
2235 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2236 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2237
2238 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2239
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002240 /* With 82571 controllers, LAA may be overwritten (with the default)
2241 * due to controller reset from the other port. */
2242 if (adapter->hw.mac_type == e1000_82571) {
2243 /* activate the work around */
2244 adapter->hw.laa_is_present = 1;
2245
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002246 /* Hold a copy of the LAA in RAR[14] This is done so that
2247 * between the time RAR[0] gets clobbered and the time it
2248 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002249 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002250 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002251 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002252 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002253 E1000_RAR_ENTRIES - 1);
2254 }
2255
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002256 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 e1000_leave_82542_rst(adapter);
2258
2259 return 0;
2260}
2261
2262/**
2263 * e1000_set_multi - Multicast and Promiscuous mode set
2264 * @netdev: network interface device structure
2265 *
2266 * The set_multi entry point is called whenever the multicast address
2267 * list or the network interface flags are updated. This routine is
2268 * responsible for configuring the hardware for proper multicast,
2269 * promiscuous mode, and all-multi behavior.
2270 **/
2271
2272static void
2273e1000_set_multi(struct net_device *netdev)
2274{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002275 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 struct e1000_hw *hw = &adapter->hw;
2277 struct dev_mc_list *mc_ptr;
2278 uint32_t rctl;
2279 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002280 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002281 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2282 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2283 E1000_NUM_MTA_REGISTERS;
2284
2285 if (adapter->hw.mac_type == e1000_ich8lan)
2286 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002288 /* reserve RAR[14] for LAA over-write work-around */
2289 if (adapter->hw.mac_type == e1000_82571)
2290 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
Malli Chilakala26483452005-04-28 19:44:46 -07002292 /* Check for Promiscuous and All Multicast modes */
2293
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 rctl = E1000_READ_REG(hw, RCTL);
2295
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002296 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002298 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 rctl |= E1000_RCTL_MPE;
2300 rctl &= ~E1000_RCTL_UPE;
2301 } else {
2302 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2303 }
2304
2305 E1000_WRITE_REG(hw, RCTL, rctl);
2306
2307 /* 82542 2.0 needs to be in reset to write receive address registers */
2308
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002309 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 e1000_enter_82542_rst(adapter);
2311
2312 /* load the first 14 multicast address into the exact filters 1-14
2313 * RAR 0 is used for the station MAC adddress
2314 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002315 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 */
2317 mc_ptr = netdev->mc_list;
2318
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002319 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002320 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2322 mc_ptr = mc_ptr->next;
2323 } else {
2324 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002325 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002327 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 }
2329 }
2330
2331 /* clear the old settings from the multicast hash table */
2332
Auke Kokcd94dd02006-06-27 09:08:22 -07002333 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002335 E1000_WRITE_FLUSH(hw);
2336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
2338 /* load any remaining addresses into the hash table */
2339
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002340 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2342 e1000_mta_set(hw, hash_value);
2343 }
2344
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002345 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347}
2348
2349/* Need to wait a few seconds after link up to get diagnostic information from
2350 * the phy */
2351
2352static void
2353e1000_update_phy_info(unsigned long data)
2354{
2355 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2356 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2357}
2358
2359/**
2360 * e1000_82547_tx_fifo_stall - Timer Call-back
2361 * @data: pointer to adapter cast into an unsigned long
2362 **/
2363
2364static void
2365e1000_82547_tx_fifo_stall(unsigned long data)
2366{
2367 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2368 struct net_device *netdev = adapter->netdev;
2369 uint32_t tctl;
2370
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002371 if (atomic_read(&adapter->tx_fifo_stall)) {
2372 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 E1000_READ_REG(&adapter->hw, TDH)) &&
2374 (E1000_READ_REG(&adapter->hw, TDFT) ==
2375 E1000_READ_REG(&adapter->hw, TDFH)) &&
2376 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2377 E1000_READ_REG(&adapter->hw, TDFHS))) {
2378 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2379 E1000_WRITE_REG(&adapter->hw, TCTL,
2380 tctl & ~E1000_TCTL_EN);
2381 E1000_WRITE_REG(&adapter->hw, TDFT,
2382 adapter->tx_head_addr);
2383 E1000_WRITE_REG(&adapter->hw, TDFH,
2384 adapter->tx_head_addr);
2385 E1000_WRITE_REG(&adapter->hw, TDFTS,
2386 adapter->tx_head_addr);
2387 E1000_WRITE_REG(&adapter->hw, TDFHS,
2388 adapter->tx_head_addr);
2389 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2390 E1000_WRITE_FLUSH(&adapter->hw);
2391
2392 adapter->tx_fifo_head = 0;
2393 atomic_set(&adapter->tx_fifo_stall, 0);
2394 netif_wake_queue(netdev);
2395 } else {
2396 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2397 }
2398 }
2399}
2400
2401/**
2402 * e1000_watchdog - Timer Call-back
2403 * @data: pointer to adapter cast into an unsigned long
2404 **/
2405static void
2406e1000_watchdog(unsigned long data)
2407{
2408 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002410 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002411 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002412 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
Auke Kokcd94dd02006-06-27 09:08:22 -07002414 ret_val = e1000_check_for_link(&adapter->hw);
2415 if ((ret_val == E1000_ERR_PHY) &&
2416 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2417 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2418 /* See e1000_kumeran_lock_loss_workaround() */
2419 DPRINTK(LINK, INFO,
2420 "Gigabit has been disabled, downgrading speed\n");
2421 }
Auke Kok90fb5132006-11-01 08:47:30 -08002422
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002423 if (adapter->hw.mac_type == e1000_82573) {
2424 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002425 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002426 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002429 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2431 link = !adapter->hw.serdes_link_down;
2432 else
2433 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2434
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002435 if (link) {
2436 if (!netif_carrier_ok(netdev)) {
Auke Kokfe7fe282006-04-14 19:04:59 -07002437 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 e1000_get_speed_and_duplex(&adapter->hw,
2439 &adapter->link_speed,
2440 &adapter->link_duplex);
2441
2442 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2443 adapter->link_speed,
2444 adapter->link_duplex == FULL_DUPLEX ?
2445 "Full Duplex" : "Half Duplex");
2446
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002447 /* tweak tx_queue_len according to speed/duplex
2448 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002449 netdev->tx_queue_len = adapter->tx_queue_len;
2450 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002451 switch (adapter->link_speed) {
2452 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002453 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002454 netdev->tx_queue_len = 10;
2455 adapter->tx_timeout_factor = 8;
2456 break;
2457 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002458 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002459 netdev->tx_queue_len = 100;
2460 /* maybe add some timeout factor ? */
2461 break;
2462 }
2463
Auke Kokfe7fe282006-04-14 19:04:59 -07002464 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002465 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002466 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002467 uint32_t tarc0;
2468 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002469 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002470 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2471 }
Auke Kok90fb5132006-11-01 08:47:30 -08002472
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002473#ifdef NETIF_F_TSO
2474 /* disable TSO for pcie and 10/100 speeds, to avoid
2475 * some hardware issues */
2476 if (!adapter->tso_force &&
2477 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002478 switch (adapter->link_speed) {
2479 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002480 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002481 DPRINTK(PROBE,INFO,
2482 "10/100 speed: disabling TSO\n");
2483 netdev->features &= ~NETIF_F_TSO;
2484 break;
2485 case SPEED_1000:
2486 netdev->features |= NETIF_F_TSO;
2487 break;
2488 default:
2489 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002490 break;
2491 }
2492 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002493#endif
2494
2495 /* enable transmits in the hardware, need to do this
2496 * after setting TARC0 */
2497 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2498 tctl |= E1000_TCTL_EN;
2499 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002500
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 netif_carrier_on(netdev);
2502 netif_wake_queue(netdev);
2503 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2504 adapter->smartspeed = 0;
2505 }
2506 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002507 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 adapter->link_speed = 0;
2509 adapter->link_duplex = 0;
2510 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2511 netif_carrier_off(netdev);
2512 netif_stop_queue(netdev);
2513 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002514
2515 /* 80003ES2LAN workaround--
2516 * For packet buffer work-around on link down event;
2517 * disable receives in the ISR and
2518 * reset device here in the watchdog
2519 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002520 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002521 /* reset device */
2522 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 }
2524
2525 e1000_smartspeed(adapter);
2526 }
2527
2528 e1000_update_stats(adapter);
2529
2530 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2531 adapter->tpt_old = adapter->stats.tpt;
2532 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2533 adapter->colc_old = adapter->stats.colc;
2534
2535 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2536 adapter->gorcl_old = adapter->stats.gorcl;
2537 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2538 adapter->gotcl_old = adapter->stats.gotcl;
2539
2540 e1000_update_adaptive(&adapter->hw);
2541
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002542 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002543 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 /* We've lost link, so the controller stops DMA,
2545 * but we've got queued Tx work that's never going
2546 * to get done, so reset controller to flush Tx.
2547 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002548 adapter->tx_timeout_count++;
2549 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 }
2551 }
2552
2553 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002554 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2556 * asymmetrical Tx or Rx gets ITR=8000; everyone
2557 * else is between 2000-8000. */
2558 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002559 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 adapter->gotcl - adapter->gorcl :
2561 adapter->gorcl - adapter->gotcl) / 10000;
2562 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2563 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2564 }
2565
2566 /* Cause software interrupt to ensure rx ring is cleaned */
2567 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2568
Malli Chilakala26483452005-04-28 19:44:46 -07002569 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 adapter->detect_tx_hung = TRUE;
2571
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002572 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002573 * reset from the other port. Set the appropriate LAA in RAR[0] */
2574 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2575 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2576
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 /* Reset the timer */
2578 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2579}
2580
2581#define E1000_TX_FLAGS_CSUM 0x00000001
2582#define E1000_TX_FLAGS_VLAN 0x00000002
2583#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002584#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2586#define E1000_TX_FLAGS_VLAN_SHIFT 16
2587
Auke Koke619d522006-04-14 19:04:52 -07002588static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002589e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2590 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591{
2592#ifdef NETIF_F_TSO
2593 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002594 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 unsigned int i;
2596 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002597 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2599 int err;
2600
Herbert Xu89114af2006-07-08 13:34:32 -07002601 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 if (skb_header_cloned(skb)) {
2603 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2604 if (err)
2605 return err;
2606 }
2607
2608 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Herbert Xu79671682006-06-22 02:40:14 -07002609 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002610 if (skb->protocol == htons(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002611 skb->nh.iph->tot_len = 0;
2612 skb->nh.iph->check = 0;
2613 skb->h.th->check =
2614 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2615 skb->nh.iph->daddr,
2616 0,
2617 IPPROTO_TCP,
2618 0);
2619 cmd_length = E1000_TXD_CMD_IP;
2620 ipcse = skb->h.raw - skb->data - 1;
2621#ifdef NETIF_F_TSO_IPV6
Auke Koke15fdd02006-08-16 11:28:45 -07002622 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002623 skb->nh.ipv6h->payload_len = 0;
2624 skb->h.th->check =
2625 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2626 &skb->nh.ipv6h->daddr,
2627 0,
2628 IPPROTO_TCP,
2629 0);
2630 ipcse = 0;
2631#endif
2632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 ipcss = skb->nh.raw - skb->data;
2634 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 tucss = skb->h.raw - skb->data;
2636 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2637 tucse = 0;
2638
2639 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002640 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002642 i = tx_ring->next_to_use;
2643 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002644 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
2646 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2647 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2648 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2649 context_desc->upper_setup.tcp_fields.tucss = tucss;
2650 context_desc->upper_setup.tcp_fields.tucso = tucso;
2651 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2652 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2653 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2654 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2655
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002656 buffer_info->time_stamp = jiffies;
2657
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002658 if (++i == tx_ring->count) i = 0;
2659 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660
Jeff Kirsher8241e352006-01-12 16:51:34 -08002661 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 }
2663#endif
2664
Jeff Kirsher8241e352006-01-12 16:51:34 -08002665 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666}
2667
Auke Koke619d522006-04-14 19:04:52 -07002668static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002669e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2670 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671{
2672 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002673 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 unsigned int i;
2675 uint8_t css;
2676
Patrick McHardy84fa7932006-08-29 16:44:56 -07002677 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 css = skb->h.raw - skb->data;
2679
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002680 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002681 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002682 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
2684 context_desc->upper_setup.tcp_fields.tucss = css;
2685 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2686 context_desc->upper_setup.tcp_fields.tucse = 0;
2687 context_desc->tcp_seg_setup.data = 0;
2688 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2689
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002690 buffer_info->time_stamp = jiffies;
2691
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002692 if (unlikely(++i == tx_ring->count)) i = 0;
2693 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
2695 return TRUE;
2696 }
2697
2698 return FALSE;
2699}
2700
2701#define E1000_MAX_TXD_PWR 12
2702#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2703
Auke Koke619d522006-04-14 19:04:52 -07002704static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002705e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2706 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2707 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 struct e1000_buffer *buffer_info;
2710 unsigned int len = skb->len;
2711 unsigned int offset = 0, size, count = 0, i;
2712 unsigned int f;
2713 len -= skb->data_len;
2714
2715 i = tx_ring->next_to_use;
2716
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002717 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 buffer_info = &tx_ring->buffer_info[i];
2719 size = min(len, max_per_txd);
2720#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002721 /* Workaround for Controller erratum --
2722 * descriptor for non-tso packet in a linear SKB that follows a
2723 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002724 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002725 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07002726 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002727 tx_ring->last_tx_tso = 0;
2728 size -= 4;
2729 }
2730
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 /* Workaround for premature desc write-backs
2732 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002733 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 size -= 4;
2735#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002736 /* work-around for errata 10 and it applies
2737 * to all controllers in PCI-X mode
2738 * The fix is to make sure that the first descriptor of a
2739 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2740 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002741 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002742 (size > 2015) && count == 0))
2743 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002744
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 /* Workaround for potential 82544 hang in PCI-X. Avoid
2746 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002747 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2749 size > 4))
2750 size -= 4;
2751
2752 buffer_info->length = size;
2753 buffer_info->dma =
2754 pci_map_single(adapter->pdev,
2755 skb->data + offset,
2756 size,
2757 PCI_DMA_TODEVICE);
2758 buffer_info->time_stamp = jiffies;
2759
2760 len -= size;
2761 offset += size;
2762 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002763 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 }
2765
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002766 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 struct skb_frag_struct *frag;
2768
2769 frag = &skb_shinfo(skb)->frags[f];
2770 len = frag->size;
2771 offset = frag->page_offset;
2772
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002773 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 buffer_info = &tx_ring->buffer_info[i];
2775 size = min(len, max_per_txd);
2776#ifdef NETIF_F_TSO
2777 /* Workaround for premature desc write-backs
2778 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002779 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 size -= 4;
2781#endif
2782 /* Workaround for potential 82544 hang in PCI-X.
2783 * Avoid terminating buffers within evenly-aligned
2784 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002785 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2787 size > 4))
2788 size -= 4;
2789
2790 buffer_info->length = size;
2791 buffer_info->dma =
2792 pci_map_page(adapter->pdev,
2793 frag->page,
2794 offset,
2795 size,
2796 PCI_DMA_TODEVICE);
2797 buffer_info->time_stamp = jiffies;
2798
2799 len -= size;
2800 offset += size;
2801 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002802 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 }
2804 }
2805
2806 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2807 tx_ring->buffer_info[i].skb = skb;
2808 tx_ring->buffer_info[first].next_to_watch = i;
2809
2810 return count;
2811}
2812
Auke Koke619d522006-04-14 19:04:52 -07002813static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002814e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2815 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 struct e1000_tx_desc *tx_desc = NULL;
2818 struct e1000_buffer *buffer_info;
2819 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2820 unsigned int i;
2821
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002822 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2824 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002825 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2826
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002827 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002828 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 }
2830
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002831 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2833 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2834 }
2835
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002836 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 txd_lower |= E1000_TXD_CMD_VLE;
2838 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2839 }
2840
2841 i = tx_ring->next_to_use;
2842
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002843 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 buffer_info = &tx_ring->buffer_info[i];
2845 tx_desc = E1000_TX_DESC(*tx_ring, i);
2846 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2847 tx_desc->lower.data =
2848 cpu_to_le32(txd_lower | buffer_info->length);
2849 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002850 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 }
2852
2853 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2854
2855 /* Force memory writes to complete before letting h/w
2856 * know there are new descriptors to fetch. (Only
2857 * applicable for weak-ordered memory model archs,
2858 * such as IA-64). */
2859 wmb();
2860
2861 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002862 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863}
2864
2865/**
2866 * 82547 workaround to avoid controller hang in half-duplex environment.
2867 * The workaround is to avoid queuing a large packet that would span
2868 * the internal Tx FIFO ring boundary by notifying the stack to resend
2869 * the packet at a later time. This gives the Tx FIFO an opportunity to
2870 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2871 * to the beginning of the Tx FIFO.
2872 **/
2873
2874#define E1000_FIFO_HDR 0x10
2875#define E1000_82547_PAD_LEN 0x3E0
2876
Auke Koke619d522006-04-14 19:04:52 -07002877static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2879{
2880 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2881 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2882
2883 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2884
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002885 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 goto no_fifo_stall_required;
2887
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002888 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 return 1;
2890
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002891 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 atomic_set(&adapter->tx_fifo_stall, 1);
2893 return 1;
2894 }
2895
2896no_fifo_stall_required:
2897 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002898 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2900 return 0;
2901}
2902
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002903#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07002904static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002905e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2906{
2907 struct e1000_hw *hw = &adapter->hw;
2908 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002909 if (vlan_tx_tag_present(skb)) {
2910 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002911 ( adapter->hw.mng_cookie.status &
2912 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2913 return 0;
2914 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08002915 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002916 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002917 if ((htons(ETH_P_IP) == eth->h_proto)) {
2918 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002919 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002920 if (IPPROTO_UDP == ip->protocol) {
2921 struct udphdr *udp =
2922 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002923 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002924 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002925 offset = (uint8_t *)udp + 8 - skb->data;
2926 length = skb->len - offset;
2927
2928 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002929 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002930 length);
2931 }
2932 }
2933 }
2934 }
2935 return 0;
2936}
2937
Jesse Brandeburg65c79732006-09-27 12:53:48 -07002938static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
2939{
2940 struct e1000_adapter *adapter = netdev_priv(netdev);
2941 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
2942
2943 netif_stop_queue(netdev);
2944 /* Herbert's original patch had:
2945 * smp_mb__after_netif_stop_queue();
2946 * but since that doesn't exist yet, just open code it. */
2947 smp_mb();
2948
2949 /* We need to check again in a case another CPU has just
2950 * made room available. */
2951 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
2952 return -EBUSY;
2953
2954 /* A reprieve! */
2955 netif_start_queue(netdev);
2956 return 0;
2957}
2958
2959static int e1000_maybe_stop_tx(struct net_device *netdev,
2960 struct e1000_tx_ring *tx_ring, int size)
2961{
2962 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
2963 return 0;
2964 return __e1000_maybe_stop_tx(netdev, size);
2965}
2966
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2968static int
2969e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2970{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002971 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002972 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2974 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2975 unsigned int tx_flags = 0;
2976 unsigned int len = skb->len;
2977 unsigned long flags;
2978 unsigned int nr_frags = 0;
2979 unsigned int mss = 0;
2980 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07002981 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 unsigned int f;
2983 len -= skb->data_len;
2984
Jesse Brandeburg65c79732006-09-27 12:53:48 -07002985 /* This goes back to the question of how to logically map a tx queue
2986 * to a flow. Right now, performance is impacted slightly negatively
2987 * if using multiple tx queues. If the stack breaks away from a
2988 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002989 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002990
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002991 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 dev_kfree_skb_any(skb);
2993 return NETDEV_TX_OK;
2994 }
2995
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07002996 /* 82571 and newer doesn't need the workaround that limited descriptor
2997 * length to 4kB */
2998 if (adapter->hw.mac_type >= e1000_82571)
2999 max_per_txd = 8192;
3000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001#ifdef NETIF_F_TSO
Herbert Xu79671682006-06-22 02:40:14 -07003002 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003003 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 * make sure there is enough room in the FIFO before
3005 * initiating the DMA for each buffer. The calc is:
3006 * 4 = ceil(buffer len/mss). To make sure we don't
3007 * overrun the FIFO, adjust the max buffer len if mss
3008 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003009 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003010 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 max_per_txd = min(mss << 2, max_per_txd);
3012 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003013
Auke Kok90fb5132006-11-01 08:47:30 -08003014 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3015 * points to just header, pull a few bytes of payload from
3016 * frags into skb->data */
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003017 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08003018 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3019 switch (adapter->hw.mac_type) {
3020 unsigned int pull_size;
3021 case e1000_82571:
3022 case e1000_82572:
3023 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003024 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003025 pull_size = min((unsigned int)4, skb->data_len);
3026 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003027 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003028 "__pskb_pull_tail failed.\n");
3029 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003030 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003031 }
3032 len = skb->len - skb->data_len;
3033 break;
3034 default:
3035 /* do nothing */
3036 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003037 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003038 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 }
3040
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003041 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003042 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003044 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045#else
Patrick McHardy84fa7932006-08-29 16:44:56 -07003046 if (skb->ip_summed == CHECKSUM_PARTIAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 count++;
3048#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05003049
3050#ifdef NETIF_F_TSO
3051 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003052 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003053 count++;
3054#endif
3055
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 count += TXD_USE_COUNT(len, max_txd_pwr);
3057
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003058 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 count++;
3060
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003061 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003062 * in PCI-X mode, so add one more descriptor to the count
3063 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003064 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003065 (len > 2015)))
3066 count++;
3067
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003069 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3071 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003072 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 count += nr_frags;
3074
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003075
3076 if (adapter->hw.tx_pkt_filtering &&
3077 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003078 e1000_transfer_dhcp_info(adapter, skb);
3079
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003080 local_irq_save(flags);
3081 if (!spin_trylock(&tx_ring->tx_lock)) {
3082 /* Collision - tell upper layer to requeue */
3083 local_irq_restore(flags);
3084 return NETDEV_TX_LOCKED;
3085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086
3087 /* need: count + 2 desc gap to keep tail from touching
3088 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003089 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003090 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 return NETDEV_TX_BUSY;
3092 }
3093
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003094 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3095 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003097 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003098 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 return NETDEV_TX_BUSY;
3100 }
3101 }
3102
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003103 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 tx_flags |= E1000_TX_FLAGS_VLAN;
3105 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3106 }
3107
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003108 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003109
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003110 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 if (tso < 0) {
3112 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003113 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 return NETDEV_TX_OK;
3115 }
3116
Jeff Kirsherfd803242005-12-13 00:06:22 -05003117 if (likely(tso)) {
3118 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003120 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 tx_flags |= E1000_TX_FLAGS_CSUM;
3122
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003123 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003124 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003125 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003126 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003127 tx_flags |= E1000_TX_FLAGS_IPV4;
3128
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003129 e1000_tx_queue(adapter, tx_ring, tx_flags,
3130 e1000_tx_map(adapter, tx_ring, skb, first,
3131 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132
3133 netdev->trans_start = jiffies;
3134
3135 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003136 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003138 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 return NETDEV_TX_OK;
3140}
3141
3142/**
3143 * e1000_tx_timeout - Respond to a Tx Hang
3144 * @netdev: network interface device structure
3145 **/
3146
3147static void
3148e1000_tx_timeout(struct net_device *netdev)
3149{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003150 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
3152 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003153 adapter->tx_timeout_count++;
3154 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155}
3156
3157static void
Jeff Kirsher87041632006-03-02 18:21:24 -08003158e1000_reset_task(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003160 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
Auke Kok2db10a02006-06-27 09:06:28 -07003162 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163}
3164
3165/**
3166 * e1000_get_stats - Get System Network Statistics
3167 * @netdev: network interface device structure
3168 *
3169 * Returns the address of the device statistics structure.
3170 * The statistics are actually updated from the timer callback.
3171 **/
3172
3173static struct net_device_stats *
3174e1000_get_stats(struct net_device *netdev)
3175{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003176 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003178 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 return &adapter->net_stats;
3180}
3181
3182/**
3183 * e1000_change_mtu - Change the Maximum Transfer Unit
3184 * @netdev: network interface device structure
3185 * @new_mtu: new value for maximum frame size
3186 *
3187 * Returns 0 on success, negative on failure
3188 **/
3189
3190static int
3191e1000_change_mtu(struct net_device *netdev, int new_mtu)
3192{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003193 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003195 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003197 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3198 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3199 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003200 return -EINVAL;
3201 }
3202
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003203 /* Adapter-specific max frame size limits. */
3204 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003205 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003206 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003207 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3208 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003209 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003210 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003211 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003212 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003213 /* Jumbo Frames not supported if:
3214 * - this is not an 82573L device
3215 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003216 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3217 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003218 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3219 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003220 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3221 DPRINTK(PROBE, ERR,
3222 "Jumbo Frames not supported.\n");
3223 return -EINVAL;
3224 }
3225 break;
3226 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003227 /* ERT will be enabled later to enable wire speed receives */
3228
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003229 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003230 case e1000_82571:
3231 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003232 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003233#define MAX_STD_JUMBO_FRAME_SIZE 9234
3234 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3235 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3236 return -EINVAL;
3237 }
3238 break;
3239 default:
3240 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3241 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003242 }
3243
David S. Miller87f50322006-07-31 22:39:40 -07003244 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003245 * means we reserve 2 more, this pushes us to allocate from the next
3246 * larger slab size
3247 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003248
Auke Kok9e2feac2006-04-14 19:05:18 -07003249 if (max_frame <= E1000_RXBUFFER_256)
3250 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3251 else if (max_frame <= E1000_RXBUFFER_512)
3252 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3253 else if (max_frame <= E1000_RXBUFFER_1024)
3254 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3255 else if (max_frame <= E1000_RXBUFFER_2048)
3256 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3257 else if (max_frame <= E1000_RXBUFFER_4096)
3258 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3259 else if (max_frame <= E1000_RXBUFFER_8192)
3260 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3261 else if (max_frame <= E1000_RXBUFFER_16384)
3262 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3263
3264 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003265 if (!adapter->hw.tbi_compatibility_on &&
3266 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3267 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3268 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003269
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003270 netdev->mtu = new_mtu;
3271
Auke Kok2db10a02006-06-27 09:06:28 -07003272 if (netif_running(netdev))
3273 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 adapter->hw.max_frame_size = max_frame;
3276
3277 return 0;
3278}
3279
3280/**
3281 * e1000_update_stats - Update the board statistics counters
3282 * @adapter: board private structure
3283 **/
3284
3285void
3286e1000_update_stats(struct e1000_adapter *adapter)
3287{
3288 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003289 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 unsigned long flags;
3291 uint16_t phy_tmp;
3292
3293#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3294
Linas Vepstas282f33c2006-06-08 22:19:44 -07003295 /*
3296 * Prevent stats update while adapter is being reset, or if the pci
3297 * connection is down.
3298 */
Auke Kok90267292006-06-08 09:30:24 -07003299 if (adapter->link_speed == 0)
3300 return;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003301 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3302 return;
Auke Kok90267292006-06-08 09:30:24 -07003303
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 spin_lock_irqsave(&adapter->stats_lock, flags);
3305
3306 /* these counters are modified from e1000_adjust_tbi_stats,
3307 * called from the interrupt context, so they must only
3308 * be written while holding adapter->stats_lock
3309 */
3310
3311 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3312 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3313 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3314 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3315 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3316 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3317 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003318
3319 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003320 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3321 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3322 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3323 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3324 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3325 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327
3328 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3329 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3330 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3331 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3332 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3333 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3334 adapter->stats.dc += E1000_READ_REG(hw, DC);
3335 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3336 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3337 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3338 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3339 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3340 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3341 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3342 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3343 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3344 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3345 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3346 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3347 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3348 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3349 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3350 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3351 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3352 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3353 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003354
3355 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003356 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3357 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3358 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3359 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3360 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3361 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003362 }
3363
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3365 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3366
3367 /* used for adaptive IFS */
3368
3369 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3370 adapter->stats.tpt += hw->tx_packet_delta;
3371 hw->collision_delta = E1000_READ_REG(hw, COLC);
3372 adapter->stats.colc += hw->collision_delta;
3373
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003374 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3376 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3377 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3378 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3379 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3380 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3381 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003382 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003383 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3384 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003385
3386 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003387 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3388 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3389 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3390 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3391 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3392 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3393 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003394 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
3397 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 adapter->net_stats.rx_packets = adapter->stats.gprc;
3399 adapter->net_stats.tx_packets = adapter->stats.gptc;
3400 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3401 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3402 adapter->net_stats.multicast = adapter->stats.mprc;
3403 adapter->net_stats.collisions = adapter->stats.colc;
3404
3405 /* Rx Errors */
3406
Jeff Kirsher87041632006-03-02 18:21:24 -08003407 /* RLEC on some newer hardware can be incorrect so build
3408 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3410 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003411 adapter->stats.ruc + adapter->stats.roc +
3412 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003413 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3414 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3416 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3418
3419 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003420 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3421 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3423 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3424 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3425
3426 /* Tx Dropped needs to be maintained elsewhere */
3427
3428 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003429 if (hw->media_type == e1000_media_type_copper) {
3430 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3432 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3433 adapter->phy_stats.idle_errors += phy_tmp;
3434 }
3435
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003436 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 (hw->phy_type == e1000_phy_m88) &&
3438 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3439 adapter->phy_stats.receive_errors += phy_tmp;
3440 }
3441
3442 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3443}
3444
3445/**
3446 * e1000_intr - Interrupt Handler
3447 * @irq: interrupt number
3448 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 **/
3450
3451static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003452e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453{
3454 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003455 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003457 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003458#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003459 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003460#else
3461 /* Interrupt Auto-Mask...upon reading ICR,
3462 * interrupts are masked. No need for the
3463 * IMC write, but it does mean we should
3464 * account for it ASAP. */
3465 if (likely(hw->mac_type >= e1000_82571))
3466 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003467#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003469 if (unlikely(!icr)) {
3470#ifdef CONFIG_E1000_NAPI
3471 if (hw->mac_type >= e1000_82571)
3472 e1000_irq_enable(adapter);
3473#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003477 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003479 /* 80003ES2LAN workaround--
3480 * For packet buffer work-around on link down event;
3481 * disable receives here in the ISR and
3482 * reset adapter in watchdog
3483 */
3484 if (netif_carrier_ok(netdev) &&
3485 (adapter->hw.mac_type == e1000_80003es2lan)) {
3486 /* disable receives */
3487 rctl = E1000_READ_REG(hw, RCTL);
3488 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3489 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003490 /* guard against interrupt when we're going down */
3491 if (!test_bit(__E1000_DOWN, &adapter->flags))
3492 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 }
3494
3495#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003496 if (unlikely(hw->mac_type < e1000_82571)) {
3497 atomic_inc(&adapter->irq_sem);
3498 E1000_WRITE_REG(hw, IMC, ~0);
3499 E1000_WRITE_FLUSH(hw);
3500 }
Auke Kokd3d9e482006-07-14 16:14:23 -07003501 if (likely(netif_rx_schedule_prep(netdev)))
3502 __netif_rx_schedule(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003503 else
Auke Kok90fb5132006-11-01 08:47:30 -08003504 /* this really should not happen! if it does it is basically a
3505 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003506 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003507#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003509 * Due to Hub Link bus being occupied, an interrupt
3510 * de-assertion message is not able to be sent.
3511 * When an interrupt assertion message is generated later,
3512 * two messages are re-ordered and sent out.
3513 * That causes APIC to think 82547 is in de-assertion
3514 * state, while 82547 is in assertion state, resulting
3515 * in dead lock. Writing IMC forces 82547 into
3516 * de-assertion state.
3517 */
3518 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003520 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 }
3522
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003523 for (i = 0; i < E1000_MAX_INTR; i++)
3524 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003525 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 break;
3527
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003528 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003530
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003531#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 return IRQ_HANDLED;
3533}
3534
3535#ifdef CONFIG_E1000_NAPI
3536/**
3537 * e1000_clean - NAPI Rx polling callback
3538 * @adapter: board private structure
3539 **/
3540
3541static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003542e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003544 struct e1000_adapter *adapter;
3545 int work_to_do = min(*budget, poll_dev->quota);
Auke Kokd3d9e482006-07-14 16:14:23 -07003546 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003547
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003548 /* Must NOT use netdev_priv macro here. */
3549 adapter = poll_dev->priv;
3550
3551 /* Keep link state information with original netdev */
Auke Kokd3d9e482006-07-14 16:14:23 -07003552 if (!netif_carrier_ok(poll_dev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003553 goto quit_polling;
3554
Auke Kokd3d9e482006-07-14 16:14:23 -07003555 /* e1000_clean is called per-cpu. This lock protects
3556 * tx_ring[0] from being cleaned by multiple cpus
3557 * simultaneously. A failure obtaining the lock means
3558 * tx_ring[0] is currently being cleaned anyway. */
3559 if (spin_trylock(&adapter->tx_queue_lock)) {
3560 tx_cleaned = e1000_clean_tx_irq(adapter,
3561 &adapter->tx_ring[0]);
3562 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003563 }
3564
Auke Kokd3d9e482006-07-14 16:14:23 -07003565 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003566 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567
3568 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003569 poll_dev->quota -= work_done;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003570
Malli Chilakala2b028932005-06-17 17:46:06 -07003571 /* If no Tx and not enough Rx work done, exit the polling mode */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003572 if ((!tx_cleaned && (work_done == 0)) ||
Auke Kokd3d9e482006-07-14 16:14:23 -07003573 !netif_running(poll_dev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003574quit_polling:
3575 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 e1000_irq_enable(adapter);
3577 return 0;
3578 }
3579
3580 return 1;
3581}
3582
3583#endif
3584/**
3585 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3586 * @adapter: board private structure
3587 **/
3588
3589static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003590e1000_clean_tx_irq(struct e1000_adapter *adapter,
3591 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 struct net_device *netdev = adapter->netdev;
3594 struct e1000_tx_desc *tx_desc, *eop_desc;
3595 struct e1000_buffer *buffer_info;
3596 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003597#ifdef CONFIG_E1000_NAPI
3598 unsigned int count = 0;
3599#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 boolean_t cleaned = FALSE;
3601
3602 i = tx_ring->next_to_clean;
3603 eop = tx_ring->buffer_info[i].next_to_watch;
3604 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3605
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003606 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003607 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 tx_desc = E1000_TX_DESC(*tx_ring, i);
3609 buffer_info = &tx_ring->buffer_info[i];
3610 cleaned = (i == eop);
3611
Jeff Kirsherfd803242005-12-13 00:06:22 -05003612 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jeff Kirsher8241e352006-01-12 16:51:34 -08003613 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003615 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003617
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 eop = tx_ring->buffer_info[i].next_to_watch;
3619 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003620#ifdef CONFIG_E1000_NAPI
3621#define E1000_TX_WEIGHT 64
3622 /* weight of a sort for tx, to avoid endless transmit cleanup */
3623 if (count++ == E1000_TX_WEIGHT) break;
3624#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 }
3626
3627 tx_ring->next_to_clean = i;
3628
Auke Kok77b2aad2006-04-14 19:05:25 -07003629#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003630 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3631 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3632 /* Make sure that anybody stopping the queue after this
3633 * sees the new next_to_clean.
3634 */
3635 smp_mb();
3636 if (netif_queue_stopped(netdev))
Auke Kok77b2aad2006-04-14 19:05:25 -07003637 netif_wake_queue(netdev);
Auke Kok77b2aad2006-04-14 19:05:25 -07003638 }
Malli Chilakala26483452005-04-28 19:44:46 -07003639
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003640 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003641 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 * check with the clearing of time_stamp and movement of i */
3643 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003644 if (tx_ring->buffer_info[eop].dma &&
3645 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003646 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003647 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003648 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003649
3650 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003651 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003652 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003653 " TDH <%x>\n"
3654 " TDT <%x>\n"
3655 " next_to_use <%x>\n"
3656 " next_to_clean <%x>\n"
3657 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003658 " time_stamp <%lx>\n"
3659 " next_to_watch <%x>\n"
3660 " jiffies <%lx>\n"
3661 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003662 (unsigned long)((tx_ring - adapter->tx_ring) /
3663 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003664 readl(adapter->hw.hw_addr + tx_ring->tdh),
3665 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003666 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003667 tx_ring->next_to_clean,
3668 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003669 eop,
3670 jiffies,
3671 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 return cleaned;
3676}
3677
3678/**
3679 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003680 * @adapter: board private structure
3681 * @status_err: receive descriptor status and error fields
3682 * @csum: receive descriptor csum field
3683 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 **/
3685
Auke Koke619d522006-04-14 19:04:52 -07003686static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003688 uint32_t status_err, uint32_t csum,
3689 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003691 uint16_t status = (uint16_t)status_err;
3692 uint8_t errors = (uint8_t)(status_err >> 24);
3693 skb->ip_summed = CHECKSUM_NONE;
3694
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003696 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003698 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003699 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003700 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003701 /* let the stack verify checksum errors */
3702 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 return;
3704 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003705 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003706 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3707 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003708 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003710 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003711 return;
3712 }
3713 /* It must be a TCP or UDP packet with a valid checksum */
3714 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 /* TCP checksum is good */
3716 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003717 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3718 /* IP fragment with UDP payload */
3719 /* Hardware complements the payload checksum, so we undo it
3720 * and then put the value in host order for further stack use.
3721 */
3722 csum = ntohl(csum ^ 0xFFFF);
3723 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07003724 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003726 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727}
3728
3729/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003730 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 * @adapter: board private structure
3732 **/
3733
3734static boolean_t
3735#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003736e1000_clean_rx_irq(struct e1000_adapter *adapter,
3737 struct e1000_rx_ring *rx_ring,
3738 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003740e1000_clean_rx_irq(struct e1000_adapter *adapter,
3741 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742#endif
3743{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 struct net_device *netdev = adapter->netdev;
3745 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003746 struct e1000_rx_desc *rx_desc, *next_rxd;
3747 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 unsigned long flags;
3749 uint32_t length;
3750 uint8_t last_byte;
3751 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003752 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003753 boolean_t cleaned = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754
3755 i = rx_ring->next_to_clean;
3756 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003757 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003759 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07003760 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003761 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08003762
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003764 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 break;
3766 (*work_done)++;
3767#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08003768 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003769 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003770 buffer_info->skb = NULL;
3771
Jeff Kirsher30320be2006-03-02 18:21:57 -08003772 prefetch(skb->data - NET_IP_ALIGN);
3773
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003774 if (++i == rx_ring->count) i = 0;
3775 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003776 prefetch(next_rxd);
3777
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003778 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003779
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003780 cleaned = TRUE;
3781 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003782 pci_unmap_single(pdev,
3783 buffer_info->dma,
3784 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 PCI_DMA_FROMDEVICE);
3786
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 length = le16_to_cpu(rx_desc->length);
3788
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003789 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3790 /* All receives must fit into a single buffer */
3791 E1000_DBG("%s: Receive packet consumed multiple"
3792 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07003793 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07003794 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 goto next_desc;
3796 }
3797
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003798 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003800 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 rx_desc->errors, length, last_byte)) {
3802 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003803 e1000_tbi_adjust_stats(&adapter->hw,
3804 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 length, skb->data);
3806 spin_unlock_irqrestore(&adapter->stats_lock,
3807 flags);
3808 length--;
3809 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07003810 /* recycle */
3811 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 goto next_desc;
3813 }
Auke Kok1cb58212006-04-18 12:31:04 -07003814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07003816 /* adjust length to remove Ethernet CRC, this must be
3817 * done after the TBI_ACCEPT workaround above */
3818 length -= 4;
3819
Jeff Kirshera292ca62006-01-12 16:51:30 -08003820 /* code added for copybreak, this should improve
3821 * performance for small packets with large amounts
3822 * of reassembly being done in the stack */
3823#define E1000_CB_LENGTH 256
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003824 if (length < E1000_CB_LENGTH) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08003825 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07003826 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003827 if (new_skb) {
3828 skb_reserve(new_skb, NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003829 memcpy(new_skb->data - NET_IP_ALIGN,
3830 skb->data - NET_IP_ALIGN,
3831 length + NET_IP_ALIGN);
3832 /* save the skb in buffer_info as good */
3833 buffer_info->skb = skb;
3834 skb = new_skb;
3835 skb_put(skb, length);
3836 }
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003837 } else
3838 skb_put(skb, length);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003839
3840 /* end copybreak code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841
3842 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08003843 e1000_rx_checksum(adapter,
3844 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003845 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003846 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003847
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 skb->protocol = eth_type_trans(skb, netdev);
3849#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003850 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08003851 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003853 le16_to_cpu(rx_desc->special) &
3854 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 } else {
3856 netif_receive_skb(skb);
3857 }
3858#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003859 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003860 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 vlan_hwaccel_rx(skb, adapter->vlgrp,
3862 le16_to_cpu(rx_desc->special) &
3863 E1000_RXD_SPC_VLAN_MASK);
3864 } else {
3865 netif_rx(skb);
3866 }
3867#endif /* CONFIG_E1000_NAPI */
3868 netdev->last_rx = jiffies;
3869
3870next_desc:
3871 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003873 /* return some buffers to hardware, one at a time is too slow */
3874 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3875 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3876 cleaned_count = 0;
3877 }
3878
Jeff Kirsher30320be2006-03-02 18:21:57 -08003879 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003880 rx_desc = next_rxd;
3881 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003884
3885 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3886 if (cleaned_count)
3887 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888
3889 return cleaned;
3890}
3891
3892/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003893 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3894 * @adapter: board private structure
3895 **/
3896
3897static boolean_t
3898#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003899e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3900 struct e1000_rx_ring *rx_ring,
3901 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003902#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003903e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3904 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003905#endif
3906{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003907 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003908 struct net_device *netdev = adapter->netdev;
3909 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003910 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003911 struct e1000_ps_page *ps_page;
3912 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07003913 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003914 unsigned int i, j;
3915 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003916 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003917 boolean_t cleaned = FALSE;
3918
3919 i = rx_ring->next_to_clean;
3920 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003921 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07003922 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003923
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003924 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003925 ps_page = &rx_ring->ps_page[i];
3926 ps_page_dma = &rx_ring->ps_page_dma[i];
3927#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003928 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003929 break;
3930 (*work_done)++;
3931#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003932 skb = buffer_info->skb;
3933
Jeff Kirsher30320be2006-03-02 18:21:57 -08003934 /* in the packet split case this is header only */
3935 prefetch(skb->data - NET_IP_ALIGN);
3936
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003937 if (++i == rx_ring->count) i = 0;
3938 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003939 prefetch(next_rxd);
3940
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003941 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003942
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003943 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003944 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003945 pci_unmap_single(pdev, buffer_info->dma,
3946 buffer_info->length,
3947 PCI_DMA_FROMDEVICE);
3948
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003949 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003950 E1000_DBG("%s: Packet Split buffers didn't pick up"
3951 " the full packet\n", netdev->name);
3952 dev_kfree_skb_irq(skb);
3953 goto next_desc;
3954 }
3955
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003956 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003957 dev_kfree_skb_irq(skb);
3958 goto next_desc;
3959 }
3960
3961 length = le16_to_cpu(rx_desc->wb.middle.length0);
3962
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003963 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003964 E1000_DBG("%s: Last part of the packet spanning"
3965 " multiple descriptors\n", netdev->name);
3966 dev_kfree_skb_irq(skb);
3967 goto next_desc;
3968 }
3969
3970 /* Good Receive */
3971 skb_put(skb, length);
3972
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003973 {
3974 /* this looks ugly, but it seems compiler issues make it
3975 more efficient than reusing j */
3976 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3977
3978 /* page alloc/put takes too long and effects small packet
3979 * throughput, so unsplit small packets and save the alloc/put*/
Auke Kok9e2feac2006-04-14 19:05:18 -07003980 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003981 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07003982 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003983 * kmap_atomic, so we can't hold the mapping
3984 * very long */
3985 pci_dma_sync_single_for_cpu(pdev,
3986 ps_page_dma->ps_page_dma[0],
3987 PAGE_SIZE,
3988 PCI_DMA_FROMDEVICE);
3989 vaddr = kmap_atomic(ps_page->ps_page[0],
3990 KM_SKB_DATA_SOFTIRQ);
3991 memcpy(skb->tail, vaddr, l1);
3992 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
3993 pci_dma_sync_single_for_device(pdev,
3994 ps_page_dma->ps_page_dma[0],
3995 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07003996 /* remove the CRC */
3997 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003998 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003999 goto copydone;
4000 } /* if */
4001 }
Auke Kok90fb5132006-11-01 08:47:30 -08004002
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004003 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004004 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004005 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004006 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4007 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4008 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004009 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4010 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004011 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004012 skb->len += length;
4013 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004014 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004015 }
4016
Auke Kokf235a2a2006-07-14 16:14:34 -07004017 /* strip the ethernet crc, problem is we're using pages now so
4018 * this whole operation can get a little cpu intensive */
4019 pskb_trim(skb, skb->len - 4);
4020
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004021copydone:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004022 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004023 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004024 skb->protocol = eth_type_trans(skb, netdev);
4025
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004026 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004027 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004028 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004029#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004030 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004031 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004032 le16_to_cpu(rx_desc->wb.middle.vlan) &
4033 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004034 } else {
4035 netif_receive_skb(skb);
4036 }
4037#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004038 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004039 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004040 le16_to_cpu(rx_desc->wb.middle.vlan) &
4041 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004042 } else {
4043 netif_rx(skb);
4044 }
4045#endif /* CONFIG_E1000_NAPI */
4046 netdev->last_rx = jiffies;
4047
4048next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004049 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004050 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004051
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004052 /* return some buffers to hardware, one at a time is too slow */
4053 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4054 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4055 cleaned_count = 0;
4056 }
4057
Jeff Kirsher30320be2006-03-02 18:21:57 -08004058 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004059 rx_desc = next_rxd;
4060 buffer_info = next_buffer;
4061
Malli Chilakala683a38f2005-06-17 17:43:25 -07004062 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004063 }
4064 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004065
4066 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4067 if (cleaned_count)
4068 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004069
4070 return cleaned;
4071}
4072
4073/**
4074 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 * @adapter: address of board private structure
4076 **/
4077
4078static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004079e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004080 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004081 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 struct net_device *netdev = adapter->netdev;
4084 struct pci_dev *pdev = adapter->pdev;
4085 struct e1000_rx_desc *rx_desc;
4086 struct e1000_buffer *buffer_info;
4087 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004088 unsigned int i;
4089 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090
4091 i = rx_ring->next_to_use;
4092 buffer_info = &rx_ring->buffer_info[i];
4093
Jeff Kirshera292ca62006-01-12 16:51:30 -08004094 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004095 skb = buffer_info->skb;
4096 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004097 skb_trim(skb, 0);
4098 goto map_skb;
4099 }
4100
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004101 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004102 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004104 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105 break;
4106 }
4107
Malli Chilakala26483452005-04-28 19:44:46 -07004108 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4110 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004111 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4112 "at %p\n", bufsz, skb->data);
4113 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004114 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004115 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 if (!skb) {
4117 dev_kfree_skb(oldskb);
4118 break;
4119 }
Malli Chilakala26483452005-04-28 19:44:46 -07004120
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4122 /* give up */
4123 dev_kfree_skb(skb);
4124 dev_kfree_skb(oldskb);
4125 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004127
4128 /* Use new allocation */
4129 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 /* Make buffer alignment 2 beyond a 16 byte boundary
4132 * this will result in a 16 byte aligned IP header after
4133 * the 14 byte MAC header is removed
4134 */
4135 skb_reserve(skb, NET_IP_ALIGN);
4136
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 buffer_info->skb = skb;
4138 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004139map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 buffer_info->dma = pci_map_single(pdev,
4141 skb->data,
4142 adapter->rx_buffer_len,
4143 PCI_DMA_FROMDEVICE);
4144
Malli Chilakala26483452005-04-28 19:44:46 -07004145 /* Fix for errata 23, can't cross 64kB boundary */
4146 if (!e1000_check_64k_bound(adapter,
4147 (void *)(unsigned long)buffer_info->dma,
4148 adapter->rx_buffer_len)) {
4149 DPRINTK(RX_ERR, ERR,
4150 "dma align check failed: %u bytes at %p\n",
4151 adapter->rx_buffer_len,
4152 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 dev_kfree_skb(skb);
4154 buffer_info->skb = NULL;
4155
Malli Chilakala26483452005-04-28 19:44:46 -07004156 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 adapter->rx_buffer_len,
4158 PCI_DMA_FROMDEVICE);
4159
4160 break; /* while !buffer_info->skb */
4161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 rx_desc = E1000_RX_DESC(*rx_ring, i);
4163 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4164
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004165 if (unlikely(++i == rx_ring->count))
4166 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 buffer_info = &rx_ring->buffer_info[i];
4168 }
4169
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004170 if (likely(rx_ring->next_to_use != i)) {
4171 rx_ring->next_to_use = i;
4172 if (unlikely(i-- == 0))
4173 i = (rx_ring->count - 1);
4174
4175 /* Force memory writes to complete before letting h/w
4176 * know there are new descriptors to fetch. (Only
4177 * applicable for weak-ordered memory model archs,
4178 * such as IA-64). */
4179 wmb();
4180 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4181 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182}
4183
4184/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004185 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4186 * @adapter: address of board private structure
4187 **/
4188
4189static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004190e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004191 struct e1000_rx_ring *rx_ring,
4192 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004193{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004194 struct net_device *netdev = adapter->netdev;
4195 struct pci_dev *pdev = adapter->pdev;
4196 union e1000_rx_desc_packet_split *rx_desc;
4197 struct e1000_buffer *buffer_info;
4198 struct e1000_ps_page *ps_page;
4199 struct e1000_ps_page_dma *ps_page_dma;
4200 struct sk_buff *skb;
4201 unsigned int i, j;
4202
4203 i = rx_ring->next_to_use;
4204 buffer_info = &rx_ring->buffer_info[i];
4205 ps_page = &rx_ring->ps_page[i];
4206 ps_page_dma = &rx_ring->ps_page_dma[i];
4207
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004208 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004209 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4210
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004211 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004212 if (j < adapter->rx_ps_pages) {
4213 if (likely(!ps_page->ps_page[j])) {
4214 ps_page->ps_page[j] =
4215 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004216 if (unlikely(!ps_page->ps_page[j])) {
4217 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004218 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004219 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004220 ps_page_dma->ps_page_dma[j] =
4221 pci_map_page(pdev,
4222 ps_page->ps_page[j],
4223 0, PAGE_SIZE,
4224 PCI_DMA_FROMDEVICE);
4225 }
4226 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004227 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004228 * this info.
4229 */
4230 rx_desc->read.buffer_addr[j+1] =
4231 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4232 } else
4233 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004234 }
4235
David S. Miller87f50322006-07-31 22:39:40 -07004236 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004237 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004238
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004239 if (unlikely(!skb)) {
4240 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004241 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004242 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004243
4244 /* Make buffer alignment 2 beyond a 16 byte boundary
4245 * this will result in a 16 byte aligned IP header after
4246 * the 14 byte MAC header is removed
4247 */
4248 skb_reserve(skb, NET_IP_ALIGN);
4249
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004250 buffer_info->skb = skb;
4251 buffer_info->length = adapter->rx_ps_bsize0;
4252 buffer_info->dma = pci_map_single(pdev, skb->data,
4253 adapter->rx_ps_bsize0,
4254 PCI_DMA_FROMDEVICE);
4255
4256 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4257
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004258 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004259 buffer_info = &rx_ring->buffer_info[i];
4260 ps_page = &rx_ring->ps_page[i];
4261 ps_page_dma = &rx_ring->ps_page_dma[i];
4262 }
4263
4264no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004265 if (likely(rx_ring->next_to_use != i)) {
4266 rx_ring->next_to_use = i;
4267 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4268
4269 /* Force memory writes to complete before letting h/w
4270 * know there are new descriptors to fetch. (Only
4271 * applicable for weak-ordered memory model archs,
4272 * such as IA-64). */
4273 wmb();
4274 /* Hardware increments by 16 bytes, but packet split
4275 * descriptors are 32 bytes...so we increment tail
4276 * twice as much.
4277 */
4278 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4279 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004280}
4281
4282/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4284 * @adapter:
4285 **/
4286
4287static void
4288e1000_smartspeed(struct e1000_adapter *adapter)
4289{
4290 uint16_t phy_status;
4291 uint16_t phy_ctrl;
4292
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004293 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4295 return;
4296
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004297 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 /* If Master/Slave config fault is asserted twice,
4299 * we assume back-to-back */
4300 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004301 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004303 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004305 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4307 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4308 phy_ctrl);
4309 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004310 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4312 &phy_ctrl)) {
4313 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4314 MII_CR_RESTART_AUTO_NEG);
4315 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4316 phy_ctrl);
4317 }
4318 }
4319 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004320 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 /* If still no link, perhaps using 2/3 pair cable */
4322 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4323 phy_ctrl |= CR_1000T_MS_ENABLE;
4324 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004325 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4327 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4328 MII_CR_RESTART_AUTO_NEG);
4329 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4330 }
4331 }
4332 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004333 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 adapter->smartspeed = 0;
4335}
4336
4337/**
4338 * e1000_ioctl -
4339 * @netdev:
4340 * @ifreq:
4341 * @cmd:
4342 **/
4343
4344static int
4345e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4346{
4347 switch (cmd) {
4348 case SIOCGMIIPHY:
4349 case SIOCGMIIREG:
4350 case SIOCSMIIREG:
4351 return e1000_mii_ioctl(netdev, ifr, cmd);
4352 default:
4353 return -EOPNOTSUPP;
4354 }
4355}
4356
4357/**
4358 * e1000_mii_ioctl -
4359 * @netdev:
4360 * @ifreq:
4361 * @cmd:
4362 **/
4363
4364static int
4365e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4366{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004367 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 struct mii_ioctl_data *data = if_mii(ifr);
4369 int retval;
4370 uint16_t mii_reg;
4371 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004372 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004374 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375 return -EOPNOTSUPP;
4376
4377 switch (cmd) {
4378 case SIOCGMIIPHY:
4379 data->phy_id = adapter->hw.phy_addr;
4380 break;
4381 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004382 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004384 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004385 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004386 &data->val_out)) {
4387 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004389 }
4390 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 break;
4392 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004393 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004395 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 return -EFAULT;
4397 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004398 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004399 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004400 mii_reg)) {
4401 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004403 }
Auke Kokdc86d322006-04-18 12:30:51 -07004404 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 switch (data->reg_num) {
4406 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004407 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004409 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 adapter->hw.autoneg = 1;
4411 adapter->hw.autoneg_advertised = 0x2F;
4412 } else {
4413 if (mii_reg & 0x40)
4414 spddplx = SPEED_1000;
4415 else if (mii_reg & 0x2000)
4416 spddplx = SPEED_100;
4417 else
4418 spddplx = SPEED_10;
4419 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004420 ? DUPLEX_FULL :
4421 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 retval = e1000_set_spd_dplx(adapter,
4423 spddplx);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004424 if (retval) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004425 spin_unlock_irqrestore(
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004426 &adapter->stats_lock,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004427 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 }
Auke Kok2db10a02006-06-27 09:06:28 -07004431 if (netif_running(adapter->netdev))
4432 e1000_reinit_locked(adapter);
4433 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434 e1000_reset(adapter);
4435 break;
4436 case M88E1000_PHY_SPEC_CTRL:
4437 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004438 if (e1000_phy_reset(&adapter->hw)) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004439 spin_unlock_irqrestore(
4440 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 break;
4444 }
4445 } else {
4446 switch (data->reg_num) {
4447 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004448 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004450 if (netif_running(adapter->netdev))
4451 e1000_reinit_locked(adapter);
4452 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 e1000_reset(adapter);
4454 break;
4455 }
4456 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004457 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 break;
4459 default:
4460 return -EOPNOTSUPP;
4461 }
4462 return E1000_SUCCESS;
4463}
4464
4465void
4466e1000_pci_set_mwi(struct e1000_hw *hw)
4467{
4468 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004469 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004471 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004472 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473}
4474
4475void
4476e1000_pci_clear_mwi(struct e1000_hw *hw)
4477{
4478 struct e1000_adapter *adapter = hw->back;
4479
4480 pci_clear_mwi(adapter->pdev);
4481}
4482
4483void
4484e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4485{
4486 struct e1000_adapter *adapter = hw->back;
4487
4488 pci_read_config_word(adapter->pdev, reg, value);
4489}
4490
4491void
4492e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4493{
4494 struct e1000_adapter *adapter = hw->back;
4495
4496 pci_write_config_word(adapter->pdev, reg, *value);
4497}
4498
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004499int32_t
4500e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4501{
4502 struct e1000_adapter *adapter = hw->back;
4503 uint16_t cap_offset;
4504
4505 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4506 if (!cap_offset)
4507 return -E1000_ERR_CONFIG;
4508
4509 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4510
4511 return E1000_SUCCESS;
4512}
4513
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514void
4515e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4516{
4517 outl(value, port);
4518}
4519
4520static void
4521e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4522{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004523 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 uint32_t ctrl, rctl;
4525
4526 e1000_irq_disable(adapter);
4527 adapter->vlgrp = grp;
4528
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004529 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 /* enable VLAN tag insert/strip */
4531 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4532 ctrl |= E1000_CTRL_VME;
4533 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4534
Auke Kokcd94dd02006-06-27 09:08:22 -07004535 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004536 /* enable VLAN receive filtering */
4537 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4538 rctl |= E1000_RCTL_VFE;
4539 rctl &= ~E1000_RCTL_CFIEN;
4540 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4541 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004542 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 } else {
4544 /* disable VLAN tag insert/strip */
4545 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4546 ctrl &= ~E1000_CTRL_VME;
4547 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4548
Auke Kokcd94dd02006-06-27 09:08:22 -07004549 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004550 /* disable VLAN filtering */
4551 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4552 rctl &= ~E1000_RCTL_VFE;
4553 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4554 if (adapter->mng_vlan_id !=
4555 (uint16_t)E1000_MNG_VLAN_NONE) {
4556 e1000_vlan_rx_kill_vid(netdev,
4557 adapter->mng_vlan_id);
4558 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4559 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561 }
4562
4563 e1000_irq_enable(adapter);
4564}
4565
4566static void
4567e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4568{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004569 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004571
4572 if ((adapter->hw.mng_cookie.status &
4573 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4574 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004575 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 /* add VID to filter table */
4577 index = (vid >> 5) & 0x7F;
4578 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4579 vfta |= (1 << (vid & 0x1F));
4580 e1000_write_vfta(&adapter->hw, index, vfta);
4581}
4582
4583static void
4584e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4585{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004586 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 uint32_t vfta, index;
4588
4589 e1000_irq_disable(adapter);
4590
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004591 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 adapter->vlgrp->vlan_devices[vid] = NULL;
4593
4594 e1000_irq_enable(adapter);
4595
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004596 if ((adapter->hw.mng_cookie.status &
4597 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004598 (vid == adapter->mng_vlan_id)) {
4599 /* release control to f/w */
4600 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004601 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004602 }
4603
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604 /* remove VID from filter table */
4605 index = (vid >> 5) & 0x7F;
4606 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4607 vfta &= ~(1 << (vid & 0x1F));
4608 e1000_write_vfta(&adapter->hw, index, vfta);
4609}
4610
4611static void
4612e1000_restore_vlan(struct e1000_adapter *adapter)
4613{
4614 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4615
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004616 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004618 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4619 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620 continue;
4621 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4622 }
4623 }
4624}
4625
4626int
4627e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4628{
4629 adapter->hw.autoneg = 0;
4630
Malli Chilakala69213682005-06-17 17:44:20 -07004631 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004632 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004633 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4634 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4635 return -EINVAL;
4636 }
4637
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004638 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 case SPEED_10 + DUPLEX_HALF:
4640 adapter->hw.forced_speed_duplex = e1000_10_half;
4641 break;
4642 case SPEED_10 + DUPLEX_FULL:
4643 adapter->hw.forced_speed_duplex = e1000_10_full;
4644 break;
4645 case SPEED_100 + DUPLEX_HALF:
4646 adapter->hw.forced_speed_duplex = e1000_100_half;
4647 break;
4648 case SPEED_100 + DUPLEX_FULL:
4649 adapter->hw.forced_speed_duplex = e1000_100_full;
4650 break;
4651 case SPEED_1000 + DUPLEX_FULL:
4652 adapter->hw.autoneg = 1;
4653 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4654 break;
4655 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4656 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004657 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 return -EINVAL;
4659 }
4660 return 0;
4661}
4662
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004663#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004664/* Save/restore 16 or 64 dwords of PCI config space depending on which
4665 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004666 */
4667#define PCIE_CONFIG_SPACE_LEN 256
4668#define PCI_CONFIG_SPACE_LEN 64
4669static int
4670e1000_pci_save_state(struct e1000_adapter *adapter)
4671{
4672 struct pci_dev *dev = adapter->pdev;
4673 int size;
4674 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004675
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004676 if (adapter->hw.mac_type >= e1000_82571)
4677 size = PCIE_CONFIG_SPACE_LEN;
4678 else
4679 size = PCI_CONFIG_SPACE_LEN;
4680
4681 WARN_ON(adapter->config_space != NULL);
4682
4683 adapter->config_space = kmalloc(size, GFP_KERNEL);
4684 if (!adapter->config_space) {
4685 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4686 return -ENOMEM;
4687 }
4688 for (i = 0; i < (size / 4); i++)
4689 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4690 return 0;
4691}
4692
4693static void
4694e1000_pci_restore_state(struct e1000_adapter *adapter)
4695{
4696 struct pci_dev *dev = adapter->pdev;
4697 int size;
4698 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004699
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004700 if (adapter->config_space == NULL)
4701 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004702
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004703 if (adapter->hw.mac_type >= e1000_82571)
4704 size = PCIE_CONFIG_SPACE_LEN;
4705 else
4706 size = PCI_CONFIG_SPACE_LEN;
4707 for (i = 0; i < (size / 4); i++)
4708 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4709 kfree(adapter->config_space);
4710 adapter->config_space = NULL;
4711 return;
4712}
4713#endif /* CONFIG_PM */
4714
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004716e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717{
4718 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004719 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004720 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07004722#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08004723 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07004724#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725
4726 netif_device_detach(netdev);
4727
Auke Kok2db10a02006-06-27 09:06:28 -07004728 if (netif_running(netdev)) {
4729 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07004731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004733#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004734 /* Implement our own version of pci_save_state(pdev) because pci-
4735 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004736 retval = e1000_pci_save_state(adapter);
4737 if (retval)
4738 return retval;
4739#endif
4740
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004742 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743 wufc &= ~E1000_WUFC_LNKC;
4744
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004745 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 e1000_setup_rctl(adapter);
4747 e1000_set_multi(netdev);
4748
4749 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07004750 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4752 rctl |= E1000_RCTL_MPE;
4753 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4754 }
4755
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004756 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4758 /* advertise wake from D3Cold */
4759 #define E1000_CTRL_ADVD3WUC 0x00100000
4760 /* phy power management enable */
4761 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4762 ctrl |= E1000_CTRL_ADVD3WUC |
4763 E1000_CTRL_EN_PHY_PWR_MGMT;
4764 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4765 }
4766
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004767 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4769 /* keep the laser running in D3 */
4770 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4771 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4772 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4773 }
4774
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004775 /* Allow time for pending master requests to run */
4776 e1000_disable_pciex_master(&adapter->hw);
4777
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4779 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004780 pci_enable_wake(pdev, PCI_D3hot, 1);
4781 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 } else {
4783 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4784 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07004785 pci_enable_wake(pdev, PCI_D3hot, 0);
4786 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 }
4788
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004789 if (adapter->hw.mac_type >= e1000_82540 &&
4790 adapter->hw.mac_type < e1000_82571 &&
4791 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004793 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 manc |= E1000_MANC_ARP_EN;
4795 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004796 pci_enable_wake(pdev, PCI_D3hot, 1);
4797 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 }
4799 }
4800
Auke Kokcd94dd02006-06-27 09:08:22 -07004801 if (adapter->hw.phy_type == e1000_phy_igp_3)
4802 e1000_phy_powerdown_workaround(&adapter->hw);
4803
Auke Kokedd106f2006-11-06 08:57:12 -08004804 if (netif_running(netdev))
4805 e1000_free_irq(adapter);
4806
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004807 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4808 * would have already happened in close and is redundant. */
4809 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004810
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004812
Auke Kokd0e027d2006-04-14 19:04:40 -07004813 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814
4815 return 0;
4816}
4817
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004818#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819static int
4820e1000_resume(struct pci_dev *pdev)
4821{
4822 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004823 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004824 uint32_t manc, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825
Auke Kokd0e027d2006-04-14 19:04:40 -07004826 pci_set_power_state(pdev, PCI_D0);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004827 e1000_pci_restore_state(adapter);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004828 if ((err = pci_enable_device(pdev))) {
4829 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
4830 return err;
4831 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004832 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833
Auke Kokd0e027d2006-04-14 19:04:40 -07004834 pci_enable_wake(pdev, PCI_D3hot, 0);
4835 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836
Auke Kokedd106f2006-11-06 08:57:12 -08004837 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
4838 return err;
4839
4840 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 e1000_reset(adapter);
4842 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4843
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004844 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 e1000_up(adapter);
4846
4847 netif_device_attach(netdev);
4848
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004849 if (adapter->hw.mac_type >= e1000_82540 &&
4850 adapter->hw.mac_type < e1000_82571 &&
4851 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852 manc = E1000_READ_REG(&adapter->hw, MANC);
4853 manc &= ~(E1000_MANC_ARP_EN);
4854 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4855 }
4856
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004857 /* If the controller is 82573 and f/w is AMT, do not set
4858 * DRV_LOAD until the interface is up. For all other cases,
4859 * let the f/w know that the h/w is now under the control
4860 * of the driver. */
4861 if (adapter->hw.mac_type != e1000_82573 ||
4862 !e1000_check_mng_mode(&adapter->hw))
4863 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004864
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 return 0;
4866}
4867#endif
Auke Kokc653e632006-05-23 13:35:57 -07004868
4869static void e1000_shutdown(struct pci_dev *pdev)
4870{
4871 e1000_suspend(pdev, PMSG_SUSPEND);
4872}
4873
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874#ifdef CONFIG_NET_POLL_CONTROLLER
4875/*
4876 * Polling 'interrupt' - used by things like netconsole to send skbs
4877 * without having to re-enable interrupts. It's not called while
4878 * the interrupt routine is executing.
4879 */
4880static void
Malli Chilakala26483452005-04-28 19:44:46 -07004881e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004883 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07004884
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01004886 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004887 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004888#ifndef CONFIG_E1000_NAPI
4889 adapter->clean_rx(adapter, adapter->rx_ring);
4890#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 enable_irq(adapter->pdev->irq);
4892}
4893#endif
4894
Auke Kok90267292006-06-08 09:30:24 -07004895/**
4896 * e1000_io_error_detected - called when PCI error is detected
4897 * @pdev: Pointer to PCI device
4898 * @state: The current pci conneection state
4899 *
4900 * This function is called after a PCI bus error affecting
4901 * this device has been detected.
4902 */
4903static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4904{
4905 struct net_device *netdev = pci_get_drvdata(pdev);
4906 struct e1000_adapter *adapter = netdev->priv;
4907
4908 netif_device_detach(netdev);
4909
4910 if (netif_running(netdev))
4911 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07004912 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07004913
4914 /* Request a slot slot reset. */
4915 return PCI_ERS_RESULT_NEED_RESET;
4916}
4917
4918/**
4919 * e1000_io_slot_reset - called after the pci bus has been reset.
4920 * @pdev: Pointer to PCI device
4921 *
4922 * Restart the card from scratch, as if from a cold-boot. Implementation
4923 * resembles the first-half of the e1000_resume routine.
4924 */
4925static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4926{
4927 struct net_device *netdev = pci_get_drvdata(pdev);
4928 struct e1000_adapter *adapter = netdev->priv;
4929
4930 if (pci_enable_device(pdev)) {
4931 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4932 return PCI_ERS_RESULT_DISCONNECT;
4933 }
4934 pci_set_master(pdev);
4935
Linas Vepstasdbf38c92006-09-27 12:54:11 -07004936 pci_enable_wake(pdev, PCI_D3hot, 0);
4937 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07004938
Auke Kok90267292006-06-08 09:30:24 -07004939 e1000_reset(adapter);
4940 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4941
4942 return PCI_ERS_RESULT_RECOVERED;
4943}
4944
4945/**
4946 * e1000_io_resume - called when traffic can start flowing again.
4947 * @pdev: Pointer to PCI device
4948 *
4949 * This callback is called when the error recovery driver tells us that
4950 * its OK to resume normal operation. Implementation resembles the
4951 * second-half of the e1000_resume routine.
4952 */
4953static void e1000_io_resume(struct pci_dev *pdev)
4954{
4955 struct net_device *netdev = pci_get_drvdata(pdev);
4956 struct e1000_adapter *adapter = netdev->priv;
4957 uint32_t manc, swsm;
4958
4959 if (netif_running(netdev)) {
4960 if (e1000_up(adapter)) {
4961 printk("e1000: can't bring device back up after reset\n");
4962 return;
4963 }
4964 }
4965
4966 netif_device_attach(netdev);
4967
4968 if (adapter->hw.mac_type >= e1000_82540 &&
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004969 adapter->hw.mac_type < e1000_82571 &&
Auke Kok90267292006-06-08 09:30:24 -07004970 adapter->hw.media_type == e1000_media_type_copper) {
4971 manc = E1000_READ_REG(&adapter->hw, MANC);
4972 manc &= ~(E1000_MANC_ARP_EN);
4973 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4974 }
4975
4976 switch (adapter->hw.mac_type) {
4977 case e1000_82573:
4978 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4979 E1000_WRITE_REG(&adapter->hw, SWSM,
4980 swsm | E1000_SWSM_DRV_LOAD);
4981 break;
4982 default:
4983 break;
4984 }
4985
4986 if (netif_running(netdev))
4987 mod_timer(&adapter->watchdog_timer, jiffies);
4988}
4989
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990/* e1000_main.c */