blob: 03294400bc90a0fb2d77a5974d59df90da3b7c31 [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);
David Howells65f27f32006-11-22 14:55:48 +0000186static void e1000_reset_task(struct work_struct *work);
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
378 * of the f/w this means that the netowrk 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)
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800419 * of the f/w this means that the netowrk 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;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800429 /* Let firmware know the driver has taken over */
430 switch (adapter->hw.mac_type) {
431 case e1000_82571:
432 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700433 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800434 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
435 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
436 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
437 break;
438 case e1000_82573:
439 swsm = E1000_READ_REG(&adapter->hw, SWSM);
440 E1000_WRITE_REG(&adapter->hw, SWSM,
441 swsm | E1000_SWSM_DRV_LOAD);
442 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700443 case e1000_ich8lan:
444 extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
445 E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
446 extcnf | E1000_EXTCNF_CTRL_SWFLAG);
447 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800448 default:
449 break;
450 }
451}
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453int
454e1000_up(struct e1000_adapter *adapter)
455{
456 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700457 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 /* hardware has been reset, we need to reload some things */
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 e1000_set_multi(netdev);
462
463 e1000_restore_vlan(adapter);
464
465 e1000_configure_tx(adapter);
466 e1000_setup_rctl(adapter);
467 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800468 /* call E1000_DESC_UNUSED which always leaves
469 * at least 1 descriptor unused to make sure
470 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800471 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800472 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800473 adapter->alloc_rx_buf(adapter, ring,
474 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800477 adapter->tx_queue_len = netdev->tx_queue_len;
478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#ifdef CONFIG_E1000_NAPI
480 netif_poll_enable(netdev);
481#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700482 e1000_irq_enable(adapter);
483
Auke Kok1314bbf2006-09-27 12:54:02 -0700484 clear_bit(__E1000_DOWN, &adapter->flags);
485
486 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 return 0;
488}
489
Auke Kok79f05bf2006-06-27 09:06:32 -0700490/**
491 * e1000_power_up_phy - restore link in case the phy was powered down
492 * @adapter: address of board private structure
493 *
494 * The phy may be powered down to save power and turn off link when the
495 * driver is unloaded and wake on lan is not enabled (among others)
496 * *** this routine MUST be followed by a call to e1000_reset ***
497 *
498 **/
499
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700500void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700501{
502 uint16_t mii_reg = 0;
503
504 /* Just clear the power down bit to wake the phy back up */
505 if (adapter->hw.media_type == e1000_media_type_copper) {
506 /* according to the manual, the phy will retain its
507 * settings across a power-down/up cycle */
508 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
509 mii_reg &= ~MII_CR_POWER_DOWN;
510 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
511 }
512}
513
514static void e1000_power_down_phy(struct e1000_adapter *adapter)
515{
Bruce Allan61c25052006-09-27 12:53:54 -0700516 /* Power down the PHY so no link is implied when interface is down *
517 * The PHY cannot be powered down if any of the following is TRUE *
Auke Kok79f05bf2006-06-27 09:06:32 -0700518 * (a) WoL is enabled
519 * (b) AMT is active
520 * (c) SoL/IDER session is active */
521 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700522 adapter->hw.media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700523 uint16_t mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700524
525 switch (adapter->hw.mac_type) {
526 case e1000_82540:
527 case e1000_82545:
528 case e1000_82545_rev_3:
529 case e1000_82546:
530 case e1000_82546_rev_3:
531 case e1000_82541:
532 case e1000_82541_rev_2:
533 case e1000_82547:
534 case e1000_82547_rev_2:
535 if (E1000_READ_REG(&adapter->hw, MANC) &
536 E1000_MANC_SMBUS_EN)
537 goto out;
538 break;
539 case e1000_82571:
540 case e1000_82572:
541 case e1000_82573:
542 case e1000_80003es2lan:
543 case e1000_ich8lan:
544 if (e1000_check_mng_mode(&adapter->hw) ||
545 e1000_check_phy_reset_block(&adapter->hw))
546 goto out;
547 break;
548 default:
549 goto out;
550 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700551 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
552 mii_reg |= MII_CR_POWER_DOWN;
553 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
554 mdelay(1);
555 }
Bruce Allan61c25052006-09-27 12:53:54 -0700556out:
557 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700558}
559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560void
561e1000_down(struct e1000_adapter *adapter)
562{
563 struct net_device *netdev = adapter->netdev;
564
Auke Kok1314bbf2006-09-27 12:54:02 -0700565 /* signal that we're down so the interrupt handler does not
566 * reschedule our watchdog timer */
567 set_bit(__E1000_DOWN, &adapter->flags);
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 del_timer_sync(&adapter->tx_fifo_stall_timer);
572 del_timer_sync(&adapter->watchdog_timer);
573 del_timer_sync(&adapter->phy_info_timer);
574
575#ifdef CONFIG_E1000_NAPI
576 netif_poll_disable(netdev);
577#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800578 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 adapter->link_speed = 0;
580 adapter->link_duplex = 0;
581 netif_carrier_off(netdev);
582 netif_stop_queue(netdev);
583
584 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400585 e1000_clean_all_tx_rings(adapter);
586 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589void
Auke Kok2db10a02006-06-27 09:06:28 -0700590e1000_reinit_locked(struct e1000_adapter *adapter)
591{
592 WARN_ON(in_interrupt());
593 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
594 msleep(1);
595 e1000_down(adapter);
596 e1000_up(adapter);
597 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
600void
601e1000_reset(struct e1000_adapter *adapter)
602{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700603 uint32_t pba, manc;
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700604#ifdef DISABLE_MULR
605 uint32_t tctl;
606#endif
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700607 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 /* Repartition Pba for greater than 9k mtu
610 * To take effect CTRL.RST is required.
611 */
612
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700613 switch (adapter->hw.mac_type) {
614 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700615 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700616 pba = E1000_PBA_30K;
617 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400618 case e1000_82571:
619 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800620 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400621 pba = E1000_PBA_38K;
622 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700623 case e1000_82573:
624 pba = E1000_PBA_12K;
625 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700626 case e1000_ich8lan:
627 pba = E1000_PBA_8K;
628 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700629 default:
630 pba = E1000_PBA_48K;
631 break;
632 }
633
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800634 if ((adapter->hw.mac_type != e1000_82573) &&
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800635 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700636 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700637
638
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800639 if (adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 adapter->tx_fifo_head = 0;
641 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
642 adapter->tx_fifo_size =
643 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
644 atomic_set(&adapter->tx_fifo_stall, 0);
645 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 E1000_WRITE_REG(&adapter->hw, PBA, pba);
648
649 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800650 /* Set the FC high water mark to 90% of the FIFO size.
651 * Required to clear last 3 LSB */
652 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700653 /* We can't use 90% on small FIFOs because the remainder
654 * would be less than 1 full frame. In this case, we size
655 * it to allow at least a full frame above the high water
656 * mark. */
657 if (pba < E1000_PBA_16K)
658 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800659
660 adapter->hw.fc_high_water = fc_high_water_mark;
661 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800662 if (adapter->hw.mac_type == e1000_80003es2lan)
663 adapter->hw.fc_pause_time = 0xFFFF;
664 else
665 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 adapter->hw.fc_send_xon = 1;
667 adapter->hw.fc = adapter->hw.original_fc;
668
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700669 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800671 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700673#ifdef DISABLE_MULR
674 /* disable Multiple Reads in Transmit Control Register for debugging */
675 tctl = E1000_READ_REG(hw, TCTL);
676 E1000_WRITE_REG(hw, TCTL, tctl & ~E1000_TCTL_MULR);
677
678#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800679 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700681 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
683 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
684
685 e1000_reset_adaptive(&adapter->hw);
686 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700687
688 if (!adapter->smart_power_down &&
689 (adapter->hw.mac_type == e1000_82571 ||
690 adapter->hw.mac_type == e1000_82572)) {
691 uint16_t phy_data = 0;
692 /* speed up time to link by disabling smart power down, ignore
693 * the return value of this function because there is nothing
694 * different we would do if it failed */
695 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
696 &phy_data);
697 phy_data &= ~IGP02E1000_PM_SPD;
698 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
699 phy_data);
700 }
701
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -0700702 if ((adapter->en_mng_pt) &&
703 (adapter->hw.mac_type >= e1000_82540) &&
704 (adapter->hw.mac_type < e1000_82571) &&
705 (adapter->hw.media_type == e1000_media_type_copper)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700706 manc = E1000_READ_REG(&adapter->hw, MANC);
707 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
708 E1000_WRITE_REG(&adapter->hw, MANC, manc);
709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710}
711
712/**
713 * e1000_probe - Device Initialization Routine
714 * @pdev: PCI device information struct
715 * @ent: entry in e1000_pci_tbl
716 *
717 * Returns 0 on success, negative on failure
718 *
719 * e1000_probe initializes an adapter identified by a pci_dev structure.
720 * The OS initialization, configuring of the adapter private structure,
721 * and a hardware reset occur.
722 **/
723
724static int __devinit
725e1000_probe(struct pci_dev *pdev,
726 const struct pci_device_id *ent)
727{
728 struct net_device *netdev;
729 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700730 unsigned long mmio_start, mmio_len;
Auke Kokcd94dd02006-06-27 09:08:22 -0700731 unsigned long flash_start, flash_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700734 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700735 int i, err, pci_using_dac;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700736 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800738 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 return err;
740
Auke Kokcd94dd02006-06-27 09:08:22 -0700741 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
742 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 pci_using_dac = 1;
744 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700745 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
746 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700748 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 }
750 pci_using_dac = 0;
751 }
752
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800753 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700754 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756 pci_set_master(pdev);
757
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700758 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700760 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 SET_MODULE_OWNER(netdev);
764 SET_NETDEV_DEV(netdev, &pdev->dev);
765
766 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700767 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 adapter->netdev = netdev;
769 adapter->pdev = pdev;
770 adapter->hw.back = adapter;
771 adapter->msg_enable = (1 << debug) - 1;
772
773 mmio_start = pci_resource_start(pdev, BAR_0);
774 mmio_len = pci_resource_len(pdev, BAR_0);
775
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700776 err = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700778 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800781 for (i = BAR_1; i <= BAR_5; i++) {
782 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800784 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 adapter->hw.io_base = pci_resource_start(pdev, i);
786 break;
787 }
788 }
789
790 netdev->open = &e1000_open;
791 netdev->stop = &e1000_close;
792 netdev->hard_start_xmit = &e1000_xmit_frame;
793 netdev->get_stats = &e1000_get_stats;
794 netdev->set_multicast_list = &e1000_set_multi;
795 netdev->set_mac_address = &e1000_set_mac;
796 netdev->change_mtu = &e1000_change_mtu;
797 netdev->do_ioctl = &e1000_ioctl;
798 e1000_set_ethtool_ops(netdev);
799 netdev->tx_timeout = &e1000_tx_timeout;
800 netdev->watchdog_timeo = 5 * HZ;
801#ifdef CONFIG_E1000_NAPI
802 netdev->poll = &e1000_clean;
803 netdev->weight = 64;
804#endif
805 netdev->vlan_rx_register = e1000_vlan_rx_register;
806 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
807 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
808#ifdef CONFIG_NET_POLL_CONTROLLER
809 netdev->poll_controller = e1000_netpoll;
810#endif
Auke Kok0eb5a342006-09-27 12:53:17 -0700811 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 netdev->mem_start = mmio_start;
814 netdev->mem_end = mmio_start + mmio_len;
815 netdev->base_addr = adapter->hw.io_base;
816
817 adapter->bd_number = cards_found;
818
819 /* setup the private structure */
820
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800821 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 goto err_sw_init;
823
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700824 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -0700825 /* Flash BAR mapping must happen after e1000_sw_init
826 * because it depends on mac_type */
827 if ((adapter->hw.mac_type == e1000_ich8lan) &&
828 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
829 flash_start = pci_resource_start(pdev, 1);
830 flash_len = pci_resource_len(pdev, 1);
831 adapter->hw.flash_address = ioremap(flash_start, flash_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700832 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -0700833 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -0700834 }
835
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700836 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700837 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
838
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800839 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 netdev->features = NETIF_F_SG |
841 NETIF_F_HW_CSUM |
842 NETIF_F_HW_VLAN_TX |
843 NETIF_F_HW_VLAN_RX |
844 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -0700845 if (adapter->hw.mac_type == e1000_ich8lan)
846 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
848
849#ifdef NETIF_F_TSO
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800850 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 (adapter->hw.mac_type != e1000_82547))
852 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700853
854#ifdef NETIF_F_TSO_IPV6
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800855 if (adapter->hw.mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700856 netdev->features |= NETIF_F_TSO_IPV6;
857#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800859 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 netdev->features |= NETIF_F_HIGHDMA;
861
Auke Kok76c224b2006-05-23 13:36:06 -0700862 netdev->features |= NETIF_F_LLTX;
863
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700864 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
865
Auke Kokcd94dd02006-06-27 09:08:22 -0700866 /* initialize eeprom parameters */
867
868 if (e1000_init_eeprom_params(&adapter->hw)) {
869 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700870 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -0700871 }
872
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800873 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 e1000_reset_hw(&adapter->hw);
877
878 /* make sure the EEPROM is good */
879
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800880 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 goto err_eeprom;
883 }
884
885 /* copy the MAC address out of the EEPROM */
886
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800887 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
889 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400890 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800892 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 goto err_eeprom;
895 }
896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 e1000_get_bus_info(&adapter->hw);
898
899 init_timer(&adapter->tx_fifo_stall_timer);
900 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
901 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
902
903 init_timer(&adapter->watchdog_timer);
904 adapter->watchdog_timer.function = &e1000_watchdog;
905 adapter->watchdog_timer.data = (unsigned long) adapter;
906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 init_timer(&adapter->phy_info_timer);
908 adapter->phy_info_timer.function = &e1000_update_phy_info;
909 adapter->phy_info_timer.data = (unsigned long) adapter;
910
David Howells65f27f32006-11-22 14:55:48 +0000911 INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 e1000_check_options(adapter);
914
915 /* Initial Wake on LAN setting
916 * If APM wake is enabled in the EEPROM,
917 * enable the ACPI Magic Packet filter
918 */
919
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800920 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 case e1000_82542_rev2_0:
922 case e1000_82542_rev2_1:
923 case e1000_82543:
924 break;
925 case e1000_82544:
926 e1000_read_eeprom(&adapter->hw,
927 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
928 eeprom_apme_mask = E1000_EEPROM_82544_APM;
929 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700930 case e1000_ich8lan:
931 e1000_read_eeprom(&adapter->hw,
932 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
933 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
934 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 case e1000_82546:
936 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500937 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800938 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800939 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 e1000_read_eeprom(&adapter->hw,
941 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
942 break;
943 }
944 /* Fall Through */
945 default:
946 e1000_read_eeprom(&adapter->hw,
947 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
948 break;
949 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800950 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700951 adapter->eeprom_wol |= E1000_WUFC_MAG;
952
953 /* now that we have the eeprom settings, apply the special cases
954 * where the eeprom may be wrong or the board simply won't support
955 * wake on lan on a particular port */
956 switch (pdev->device) {
957 case E1000_DEV_ID_82546GB_PCIE:
958 adapter->eeprom_wol = 0;
959 break;
960 case E1000_DEV_ID_82546EB_FIBER:
961 case E1000_DEV_ID_82546GB_FIBER:
962 case E1000_DEV_ID_82571EB_FIBER:
963 /* Wake events only supported on port A for dual fiber
964 * regardless of eeprom setting */
965 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
966 adapter->eeprom_wol = 0;
967 break;
968 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700969 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700970 /* if quad port adapter, disable WoL on all but port A */
971 if (global_quad_port_a != 0)
972 adapter->eeprom_wol = 0;
973 else
974 adapter->quad_port_a = 1;
975 /* Reset for multiple quad port adapters */
976 if (++global_quad_port_a == 4)
977 global_quad_port_a = 0;
978 break;
979 }
980
981 /* initialize the wol settings based on the eeprom settings */
982 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -0800984 /* print bus type/speed/width info */
985 {
986 struct e1000_hw *hw = &adapter->hw;
987 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
988 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
989 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
990 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
991 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
992 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
993 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
994 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
995 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
996 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
997 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
998 "32-bit"));
999 }
1000
1001 for (i = 0; i < 6; i++)
1002 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 /* reset the hardware with the new settings */
1005 e1000_reset(adapter);
1006
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001007 /* If the controller is 82573 and f/w is AMT, do not set
1008 * DRV_LOAD until the interface is up. For all other cases,
1009 * let the f/w know that the h/w is now under the control
1010 * of the driver. */
1011 if (adapter->hw.mac_type != e1000_82573 ||
1012 !e1000_check_mng_mode(&adapter->hw))
1013 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 strcpy(netdev->name, "eth%d");
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001016 if ((err = register_netdev(netdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 goto err_register;
1018
Auke Kok1314bbf2006-09-27 12:54:02 -07001019 /* tell the stack to leave us alone until e1000_open() is called */
1020 netif_carrier_off(netdev);
1021 netif_stop_queue(netdev);
1022
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1024
1025 cards_found++;
1026 return 0;
1027
1028err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001029 e1000_release_hw_control(adapter);
1030err_eeprom:
1031 if (!e1000_check_phy_reset_block(&adapter->hw))
1032 e1000_phy_hw_reset(&adapter->hw);
1033
Auke Kokcd94dd02006-06-27 09:08:22 -07001034 if (adapter->hw.flash_address)
1035 iounmap(adapter->hw.flash_address);
1036err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001037#ifdef CONFIG_E1000_NAPI
1038 for (i = 0; i < adapter->num_rx_queues; i++)
1039 dev_put(&adapter->polling_netdev[i]);
1040#endif
1041
1042 kfree(adapter->tx_ring);
1043 kfree(adapter->rx_ring);
1044#ifdef CONFIG_E1000_NAPI
1045 kfree(adapter->polling_netdev);
1046#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 iounmap(adapter->hw.hw_addr);
1049err_ioremap:
1050 free_netdev(netdev);
1051err_alloc_etherdev:
1052 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001053err_pci_reg:
1054err_dma:
1055 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 return err;
1057}
1058
1059/**
1060 * e1000_remove - Device Removal Routine
1061 * @pdev: PCI device information struct
1062 *
1063 * e1000_remove is called by the PCI subsystem to alert the driver
1064 * that it should release a PCI device. The could be caused by a
1065 * Hot-Plug event, or because the driver is going to be removed from
1066 * memory.
1067 **/
1068
1069static void __devexit
1070e1000_remove(struct pci_dev *pdev)
1071{
1072 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001073 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001074 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001075#ifdef CONFIG_E1000_NAPI
1076 int i;
1077#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001079 flush_scheduled_work();
1080
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07001081 if (adapter->hw.mac_type >= e1000_82540 &&
1082 adapter->hw.mac_type < e1000_82571 &&
1083 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001085 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 manc |= E1000_MANC_ARP_EN;
1087 E1000_WRITE_REG(&adapter->hw, MANC, manc);
1088 }
1089 }
1090
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001091 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1092 * would have already happened in close and is redundant. */
1093 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001094
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001096#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001097 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001098 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001099#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001101 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001102 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001104 kfree(adapter->tx_ring);
1105 kfree(adapter->rx_ring);
1106#ifdef CONFIG_E1000_NAPI
1107 kfree(adapter->polling_netdev);
1108#endif
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001111 if (adapter->hw.flash_address)
1112 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 pci_release_regions(pdev);
1114
1115 free_netdev(netdev);
1116
1117 pci_disable_device(pdev);
1118}
1119
1120/**
1121 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1122 * @adapter: board private structure to initialize
1123 *
1124 * e1000_sw_init initializes the Adapter private data structure.
1125 * Fields are initialized based on PCI device information and
1126 * OS network device settings (MTU size).
1127 **/
1128
1129static int __devinit
1130e1000_sw_init(struct e1000_adapter *adapter)
1131{
1132 struct e1000_hw *hw = &adapter->hw;
1133 struct net_device *netdev = adapter->netdev;
1134 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001135#ifdef CONFIG_E1000_NAPI
1136 int i;
1137#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
1139 /* PCI config space info */
1140
1141 hw->vendor_id = pdev->vendor;
1142 hw->device_id = pdev->device;
1143 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1144 hw->subsystem_id = pdev->subsystem_device;
1145
1146 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1147
1148 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1149
Auke Kokeb0f8052006-07-14 16:14:48 -07001150 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001151 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 hw->max_frame_size = netdev->mtu +
1153 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1154 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1155
1156 /* identify the MAC */
1157
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001158 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1160 return -EIO;
1161 }
1162
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001163 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 default:
1165 break;
1166 case e1000_82541:
1167 case e1000_82547:
1168 case e1000_82541_rev_2:
1169 case e1000_82547_rev_2:
1170 hw->phy_init_script = 1;
1171 break;
1172 }
1173
1174 e1000_set_media_type(hw);
1175
1176 hw->wait_autoneg_complete = FALSE;
1177 hw->tbi_compatibility_en = TRUE;
1178 hw->adaptive_ifs = TRUE;
1179
1180 /* Copper options */
1181
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001182 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 hw->mdix = AUTO_ALL_MODES;
1184 hw->disable_polarity_correction = FALSE;
1185 hw->master_slave = E1000_MASTER_SLAVE;
1186 }
1187
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001188 adapter->num_tx_queues = 1;
1189 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001190
1191 if (e1000_alloc_queues(adapter)) {
1192 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1193 return -ENOMEM;
1194 }
1195
1196#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001197 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001198 adapter->polling_netdev[i].priv = adapter;
1199 adapter->polling_netdev[i].poll = &e1000_clean;
1200 adapter->polling_netdev[i].weight = 64;
1201 dev_hold(&adapter->polling_netdev[i]);
1202 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1203 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001204 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001205#endif
1206
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 atomic_set(&adapter->irq_sem, 1);
1208 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Auke Kok1314bbf2006-09-27 12:54:02 -07001210 set_bit(__E1000_DOWN, &adapter->flags);
1211
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 return 0;
1213}
1214
1215/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001216 * e1000_alloc_queues - Allocate memory for all rings
1217 * @adapter: board private structure to initialize
1218 *
1219 * We allocate one ring per queue at run-time since we don't know the
1220 * number of queues at compile-time. The polling_netdev array is
1221 * intended for Multiqueue, but should work fine with a single queue.
1222 **/
1223
1224static int __devinit
1225e1000_alloc_queues(struct e1000_adapter *adapter)
1226{
1227 int size;
1228
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001229 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001230 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1231 if (!adapter->tx_ring)
1232 return -ENOMEM;
1233 memset(adapter->tx_ring, 0, size);
1234
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001235 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001236 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1237 if (!adapter->rx_ring) {
1238 kfree(adapter->tx_ring);
1239 return -ENOMEM;
1240 }
1241 memset(adapter->rx_ring, 0, size);
1242
1243#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001244 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001245 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1246 if (!adapter->polling_netdev) {
1247 kfree(adapter->tx_ring);
1248 kfree(adapter->rx_ring);
1249 return -ENOMEM;
1250 }
1251 memset(adapter->polling_netdev, 0, size);
1252#endif
1253
1254 return E1000_SUCCESS;
1255}
1256
1257/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 * e1000_open - Called when a network interface is made active
1259 * @netdev: network interface device structure
1260 *
1261 * Returns 0 on success, negative value on failure
1262 *
1263 * The open entry point is called when a network interface is made
1264 * active by the system (IFF_UP). At this point all resources needed
1265 * for transmit and receive operations are allocated, the interrupt
1266 * handler is registered with the OS, the watchdog timer is started,
1267 * and the stack is notified that the interface is ready.
1268 **/
1269
1270static int
1271e1000_open(struct net_device *netdev)
1272{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001273 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 int err;
1275
Auke Kok2db10a02006-06-27 09:06:28 -07001276 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001277 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001278 return -EBUSY;
1279
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 /* allocate transmit descriptors */
1281
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001282 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 goto err_setup_tx;
1284
1285 /* allocate receive descriptors */
1286
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);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001571 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001572 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001573 } else if (hw->mac_type == e1000_80003es2lan) {
1574 tarc = E1000_READ_REG(hw, TARC0);
1575 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001576 E1000_WRITE_REG(hw, TARC0, tarc);
1577 tarc = E1000_READ_REG(hw, TARC1);
1578 tarc |= 1;
1579 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001580 }
1581
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001582 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
1584 /* Setup Transmit Descriptor Settings for eop descriptor */
1585 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1586 E1000_TXD_CMD_IFCS;
1587
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001588 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1590 else
1591 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1592
1593 /* Cache if we're 82544 running in PCI-X because we'll
1594 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001595 if (hw->mac_type == e1000_82544 &&
1596 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001598
1599 E1000_WRITE_REG(hw, TCTL, tctl);
1600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602
1603/**
1604 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1605 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001606 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 *
1608 * Returns 0 on success, negative on failure
1609 **/
1610
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001611static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001612e1000_setup_rx_resources(struct e1000_adapter *adapter,
1613 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001616 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
1618 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001619 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001620 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001621 DPRINTK(PROBE, ERR,
1622 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 return -ENOMEM;
1624 }
1625 memset(rxdr->buffer_info, 0, size);
1626
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001627 size = sizeof(struct e1000_ps_page) * rxdr->count;
1628 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001629 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001630 vfree(rxdr->buffer_info);
1631 DPRINTK(PROBE, ERR,
1632 "Unable to allocate memory for the receive descriptor ring\n");
1633 return -ENOMEM;
1634 }
1635 memset(rxdr->ps_page, 0, size);
1636
1637 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1638 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001639 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001640 vfree(rxdr->buffer_info);
1641 kfree(rxdr->ps_page);
1642 DPRINTK(PROBE, ERR,
1643 "Unable to allocate memory for the receive descriptor ring\n");
1644 return -ENOMEM;
1645 }
1646 memset(rxdr->ps_page_dma, 0, size);
1647
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001648 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001649 desc_len = sizeof(struct e1000_rx_desc);
1650 else
1651 desc_len = sizeof(union e1000_rx_desc_packet_split);
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 /* Round up to nearest 4K */
1654
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001655 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 E1000_ROUNDUP(rxdr->size, 4096);
1657
1658 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1659
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001660 if (!rxdr->desc) {
1661 DPRINTK(PROBE, ERR,
1662 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001665 kfree(rxdr->ps_page);
1666 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 return -ENOMEM;
1668 }
1669
Malli Chilakala26483452005-04-28 19:44:46 -07001670 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1672 void *olddesc = rxdr->desc;
1673 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001674 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1675 "at %p\n", rxdr->size, rxdr->desc);
1676 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001678 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001679 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001681 DPRINTK(PROBE, ERR,
1682 "Unable to allocate memory "
1683 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 goto setup_rx_desc_die;
1685 }
1686
1687 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1688 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001689 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1690 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001692 DPRINTK(PROBE, ERR,
1693 "Unable to allocate aligned memory "
1694 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001695 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001697 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1699 }
1700 }
1701 memset(rxdr->desc, 0, rxdr->size);
1702
1703 rxdr->next_to_clean = 0;
1704 rxdr->next_to_use = 0;
1705
1706 return 0;
1707}
1708
1709/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001710 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1711 * (Descriptors) for all queues
1712 * @adapter: board private structure
1713 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001714 * Return 0 on success, negative on failure
1715 **/
1716
1717int
1718e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1719{
1720 int i, err = 0;
1721
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001722 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001723 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1724 if (err) {
1725 DPRINTK(PROBE, ERR,
1726 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001727 for (i-- ; i >= 0; i--)
1728 e1000_free_rx_resources(adapter,
1729 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001730 break;
1731 }
1732 }
1733
1734 return err;
1735}
1736
1737/**
Malli Chilakala26483452005-04-28 19:44:46 -07001738 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 * @adapter: Board private structure
1740 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001741#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1742 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743static void
1744e1000_setup_rctl(struct e1000_adapter *adapter)
1745{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001746 uint32_t rctl, rfctl;
1747 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001748#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001749 uint32_t pages = 0;
1750#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
1752 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1753
1754 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1755
1756 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1757 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1758 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1759
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001760 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 rctl |= E1000_RCTL_SBP;
1762 else
1763 rctl &= ~E1000_RCTL_SBP;
1764
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001765 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1766 rctl &= ~E1000_RCTL_LPE;
1767 else
1768 rctl |= E1000_RCTL_LPE;
1769
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001771 rctl &= ~E1000_RCTL_SZ_4096;
1772 rctl |= E1000_RCTL_BSEX;
1773 switch (adapter->rx_buffer_len) {
1774 case E1000_RXBUFFER_256:
1775 rctl |= E1000_RCTL_SZ_256;
1776 rctl &= ~E1000_RCTL_BSEX;
1777 break;
1778 case E1000_RXBUFFER_512:
1779 rctl |= E1000_RCTL_SZ_512;
1780 rctl &= ~E1000_RCTL_BSEX;
1781 break;
1782 case E1000_RXBUFFER_1024:
1783 rctl |= E1000_RCTL_SZ_1024;
1784 rctl &= ~E1000_RCTL_BSEX;
1785 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001786 case E1000_RXBUFFER_2048:
1787 default:
1788 rctl |= E1000_RCTL_SZ_2048;
1789 rctl &= ~E1000_RCTL_BSEX;
1790 break;
1791 case E1000_RXBUFFER_4096:
1792 rctl |= E1000_RCTL_SZ_4096;
1793 break;
1794 case E1000_RXBUFFER_8192:
1795 rctl |= E1000_RCTL_SZ_8192;
1796 break;
1797 case E1000_RXBUFFER_16384:
1798 rctl |= E1000_RCTL_SZ_16384;
1799 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001800 }
1801
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001802#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001803 /* 82571 and greater support packet-split where the protocol
1804 * header is placed in skb->data and the packet data is
1805 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1806 * In the case of a non-split, skb->data is linearly filled,
1807 * followed by the page buffers. Therefore, skb->data is
1808 * sized to hold the largest protocol header.
1809 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001810 /* allocations using alloc_page take too long for regular MTU
1811 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001812 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001813 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1814 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001815 adapter->rx_ps_pages = pages;
1816 else
1817 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001818#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001819 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001820 /* Configure extra packet-split registers */
1821 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1822 rfctl |= E1000_RFCTL_EXTEN;
1823 /* disable IPv6 packet split support */
1824 rfctl |= E1000_RFCTL_IPV6_DIS;
1825 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1826
Auke Kok7dfee0c2006-06-27 09:07:50 -07001827 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001828
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001829 psrctl |= adapter->rx_ps_bsize0 >>
1830 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001831
1832 switch (adapter->rx_ps_pages) {
1833 case 3:
1834 psrctl |= PAGE_SIZE <<
1835 E1000_PSRCTL_BSIZE3_SHIFT;
1836 case 2:
1837 psrctl |= PAGE_SIZE <<
1838 E1000_PSRCTL_BSIZE2_SHIFT;
1839 case 1:
1840 psrctl |= PAGE_SIZE >>
1841 E1000_PSRCTL_BSIZE1_SHIFT;
1842 break;
1843 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001844
1845 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 }
1847
1848 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1849}
1850
1851/**
1852 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1853 * @adapter: board private structure
1854 *
1855 * Configure the Rx unit of the MAC after a reset.
1856 **/
1857
1858static void
1859e1000_configure_rx(struct e1000_adapter *adapter)
1860{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001861 uint64_t rdba;
1862 struct e1000_hw *hw = &adapter->hw;
1863 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001864
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001865 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001866 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001867 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001868 sizeof(union e1000_rx_desc_packet_split);
1869 adapter->clean_rx = e1000_clean_rx_irq_ps;
1870 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1871 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001872 rdlen = adapter->rx_ring[0].count *
1873 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001874 adapter->clean_rx = e1000_clean_rx_irq;
1875 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
1878 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001879 rctl = E1000_READ_REG(hw, RCTL);
1880 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
1882 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001883 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001885 if (hw->mac_type >= e1000_82540) {
1886 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001887 if (adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001888 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 1000000000 / (adapter->itr * 256));
1890 }
1891
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001892 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001893 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001894 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07001895 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001896#ifdef CONFIG_E1000_NAPI
1897 /* Auto-Mask interrupts upon ICR read. */
1898 ctrl_ext |= E1000_CTRL_EXT_IAME;
1899#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001900 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001901 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001902 E1000_WRITE_FLUSH(hw);
1903 }
1904
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001905 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1906 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001907 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001908 case 1:
1909 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001910 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001911 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001912 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1913 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001914 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001915 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001916 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
1917 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001918 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001919 }
1920
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001922 if (hw->mac_type >= e1000_82543) {
1923 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001924 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001925 rxcsum |= E1000_RXCSUM_TUOFL;
1926
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001927 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001928 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001929 if ((hw->mac_type >= e1000_82571) &&
1930 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001931 rxcsum |= E1000_RXCSUM_IPPCSE;
1932 }
1933 } else {
1934 rxcsum &= ~E1000_RXCSUM_TUOFL;
1935 /* don't need to clear IPPCSE as it defaults to 0 */
1936 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001937 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 }
1939
1940 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001941 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942}
1943
1944/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001945 * e1000_free_tx_resources - Free Tx Resources per Queue
1946 * @adapter: board private structure
1947 * @tx_ring: Tx descriptor ring for a specific queue
1948 *
1949 * Free all transmit software resources
1950 **/
1951
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001952static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001953e1000_free_tx_resources(struct e1000_adapter *adapter,
1954 struct e1000_tx_ring *tx_ring)
1955{
1956 struct pci_dev *pdev = adapter->pdev;
1957
1958 e1000_clean_tx_ring(adapter, tx_ring);
1959
1960 vfree(tx_ring->buffer_info);
1961 tx_ring->buffer_info = NULL;
1962
1963 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1964
1965 tx_ring->desc = NULL;
1966}
1967
1968/**
1969 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 * @adapter: board private structure
1971 *
1972 * Free all transmit software resources
1973 **/
1974
1975void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001976e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001978 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001980 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001981 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982}
1983
Auke Koke619d522006-04-14 19:04:52 -07001984static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1986 struct e1000_buffer *buffer_info)
1987{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001988 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001989 pci_unmap_page(adapter->pdev,
1990 buffer_info->dma,
1991 buffer_info->length,
1992 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08001994 if (buffer_info->skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 dev_kfree_skb_any(buffer_info->skb);
Jeff Kirsher8241e352006-01-12 16:51:34 -08001996 memset(buffer_info, 0, sizeof(struct e1000_buffer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997}
1998
1999/**
2000 * e1000_clean_tx_ring - Free Tx Buffers
2001 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002002 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 **/
2004
2005static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002006e1000_clean_tx_ring(struct e1000_adapter *adapter,
2007 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 struct e1000_buffer *buffer_info;
2010 unsigned long size;
2011 unsigned int i;
2012
2013 /* Free all the Tx ring sk_buffs */
2014
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002015 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 buffer_info = &tx_ring->buffer_info[i];
2017 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2018 }
2019
2020 size = sizeof(struct e1000_buffer) * tx_ring->count;
2021 memset(tx_ring->buffer_info, 0, size);
2022
2023 /* Zero out the descriptor ring */
2024
2025 memset(tx_ring->desc, 0, tx_ring->size);
2026
2027 tx_ring->next_to_use = 0;
2028 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002029 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002031 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2032 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2033}
2034
2035/**
2036 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2037 * @adapter: board private structure
2038 **/
2039
2040static void
2041e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2042{
2043 int i;
2044
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002045 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002046 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047}
2048
2049/**
2050 * e1000_free_rx_resources - Free Rx Resources
2051 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002052 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 *
2054 * Free all receive software resources
2055 **/
2056
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002057static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002058e1000_free_rx_resources(struct e1000_adapter *adapter,
2059 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 struct pci_dev *pdev = adapter->pdev;
2062
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002063 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
2065 vfree(rx_ring->buffer_info);
2066 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002067 kfree(rx_ring->ps_page);
2068 rx_ring->ps_page = NULL;
2069 kfree(rx_ring->ps_page_dma);
2070 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
2072 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2073
2074 rx_ring->desc = NULL;
2075}
2076
2077/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002078 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002080 *
2081 * Free all receive software resources
2082 **/
2083
2084void
2085e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2086{
2087 int i;
2088
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002089 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002090 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2091}
2092
2093/**
2094 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2095 * @adapter: board private structure
2096 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 **/
2098
2099static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002100e1000_clean_rx_ring(struct e1000_adapter *adapter,
2101 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002104 struct e1000_ps_page *ps_page;
2105 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 struct pci_dev *pdev = adapter->pdev;
2107 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002108 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
2110 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002111 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002113 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 pci_unmap_single(pdev,
2115 buffer_info->dma,
2116 buffer_info->length,
2117 PCI_DMA_FROMDEVICE);
2118
2119 dev_kfree_skb(buffer_info->skb);
2120 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002121 }
2122 ps_page = &rx_ring->ps_page[i];
2123 ps_page_dma = &rx_ring->ps_page_dma[i];
2124 for (j = 0; j < adapter->rx_ps_pages; j++) {
2125 if (!ps_page->ps_page[j]) break;
2126 pci_unmap_page(pdev,
2127 ps_page_dma->ps_page_dma[j],
2128 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2129 ps_page_dma->ps_page_dma[j] = 0;
2130 put_page(ps_page->ps_page[j]);
2131 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 }
2133 }
2134
2135 size = sizeof(struct e1000_buffer) * rx_ring->count;
2136 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002137 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2138 memset(rx_ring->ps_page, 0, size);
2139 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2140 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
2142 /* Zero out the descriptor ring */
2143
2144 memset(rx_ring->desc, 0, rx_ring->size);
2145
2146 rx_ring->next_to_clean = 0;
2147 rx_ring->next_to_use = 0;
2148
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002149 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2150 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2151}
2152
2153/**
2154 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2155 * @adapter: board private structure
2156 **/
2157
2158static void
2159e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2160{
2161 int i;
2162
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002163 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002164 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165}
2166
2167/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2168 * and memory write and invalidate disabled for certain operations
2169 */
2170static void
2171e1000_enter_82542_rst(struct e1000_adapter *adapter)
2172{
2173 struct net_device *netdev = adapter->netdev;
2174 uint32_t rctl;
2175
2176 e1000_pci_clear_mwi(&adapter->hw);
2177
2178 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2179 rctl |= E1000_RCTL_RST;
2180 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2181 E1000_WRITE_FLUSH(&adapter->hw);
2182 mdelay(5);
2183
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002184 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002185 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188static void
2189e1000_leave_82542_rst(struct e1000_adapter *adapter)
2190{
2191 struct net_device *netdev = adapter->netdev;
2192 uint32_t rctl;
2193
2194 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2195 rctl &= ~E1000_RCTL_RST;
2196 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2197 E1000_WRITE_FLUSH(&adapter->hw);
2198 mdelay(5);
2199
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002200 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 e1000_pci_set_mwi(&adapter->hw);
2202
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002203 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002204 /* No need to loop, because 82542 supports only 1 queue */
2205 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002206 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002207 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 }
2209}
2210
2211/**
2212 * e1000_set_mac - Change the Ethernet Address of the NIC
2213 * @netdev: network interface device structure
2214 * @p: pointer to an address structure
2215 *
2216 * Returns 0 on success, negative on failure
2217 **/
2218
2219static int
2220e1000_set_mac(struct net_device *netdev, void *p)
2221{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002222 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 struct sockaddr *addr = p;
2224
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002225 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 return -EADDRNOTAVAIL;
2227
2228 /* 82542 2.0 needs to be in reset to write receive address registers */
2229
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002230 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 e1000_enter_82542_rst(adapter);
2232
2233 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2234 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2235
2236 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2237
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002238 /* With 82571 controllers, LAA may be overwritten (with the default)
2239 * due to controller reset from the other port. */
2240 if (adapter->hw.mac_type == e1000_82571) {
2241 /* activate the work around */
2242 adapter->hw.laa_is_present = 1;
2243
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002244 /* Hold a copy of the LAA in RAR[14] This is done so that
2245 * between the time RAR[0] gets clobbered and the time it
2246 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002247 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002248 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002249 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002250 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002251 E1000_RAR_ENTRIES - 1);
2252 }
2253
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002254 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 e1000_leave_82542_rst(adapter);
2256
2257 return 0;
2258}
2259
2260/**
2261 * e1000_set_multi - Multicast and Promiscuous mode set
2262 * @netdev: network interface device structure
2263 *
2264 * The set_multi entry point is called whenever the multicast address
2265 * list or the network interface flags are updated. This routine is
2266 * responsible for configuring the hardware for proper multicast,
2267 * promiscuous mode, and all-multi behavior.
2268 **/
2269
2270static void
2271e1000_set_multi(struct net_device *netdev)
2272{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002273 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 struct e1000_hw *hw = &adapter->hw;
2275 struct dev_mc_list *mc_ptr;
2276 uint32_t rctl;
2277 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002278 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002279 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2280 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2281 E1000_NUM_MTA_REGISTERS;
2282
2283 if (adapter->hw.mac_type == e1000_ich8lan)
2284 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002286 /* reserve RAR[14] for LAA over-write work-around */
2287 if (adapter->hw.mac_type == e1000_82571)
2288 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Malli Chilakala26483452005-04-28 19:44:46 -07002290 /* Check for Promiscuous and All Multicast modes */
2291
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 rctl = E1000_READ_REG(hw, RCTL);
2293
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002294 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002296 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 rctl |= E1000_RCTL_MPE;
2298 rctl &= ~E1000_RCTL_UPE;
2299 } else {
2300 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2301 }
2302
2303 E1000_WRITE_REG(hw, RCTL, rctl);
2304
2305 /* 82542 2.0 needs to be in reset to write receive address registers */
2306
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002307 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 e1000_enter_82542_rst(adapter);
2309
2310 /* load the first 14 multicast address into the exact filters 1-14
2311 * RAR 0 is used for the station MAC adddress
2312 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002313 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 */
2315 mc_ptr = netdev->mc_list;
2316
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002317 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002318 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2320 mc_ptr = mc_ptr->next;
2321 } else {
2322 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002323 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002325 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 }
2327 }
2328
2329 /* clear the old settings from the multicast hash table */
2330
Auke Kokcd94dd02006-06-27 09:08:22 -07002331 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002333 E1000_WRITE_FLUSH(hw);
2334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
2336 /* load any remaining addresses into the hash table */
2337
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002338 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2340 e1000_mta_set(hw, hash_value);
2341 }
2342
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002343 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
2347/* Need to wait a few seconds after link up to get diagnostic information from
2348 * the phy */
2349
2350static void
2351e1000_update_phy_info(unsigned long data)
2352{
2353 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2354 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2355}
2356
2357/**
2358 * e1000_82547_tx_fifo_stall - Timer Call-back
2359 * @data: pointer to adapter cast into an unsigned long
2360 **/
2361
2362static void
2363e1000_82547_tx_fifo_stall(unsigned long data)
2364{
2365 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2366 struct net_device *netdev = adapter->netdev;
2367 uint32_t tctl;
2368
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002369 if (atomic_read(&adapter->tx_fifo_stall)) {
2370 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 E1000_READ_REG(&adapter->hw, TDH)) &&
2372 (E1000_READ_REG(&adapter->hw, TDFT) ==
2373 E1000_READ_REG(&adapter->hw, TDFH)) &&
2374 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2375 E1000_READ_REG(&adapter->hw, TDFHS))) {
2376 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2377 E1000_WRITE_REG(&adapter->hw, TCTL,
2378 tctl & ~E1000_TCTL_EN);
2379 E1000_WRITE_REG(&adapter->hw, TDFT,
2380 adapter->tx_head_addr);
2381 E1000_WRITE_REG(&adapter->hw, TDFH,
2382 adapter->tx_head_addr);
2383 E1000_WRITE_REG(&adapter->hw, TDFTS,
2384 adapter->tx_head_addr);
2385 E1000_WRITE_REG(&adapter->hw, TDFHS,
2386 adapter->tx_head_addr);
2387 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2388 E1000_WRITE_FLUSH(&adapter->hw);
2389
2390 adapter->tx_fifo_head = 0;
2391 atomic_set(&adapter->tx_fifo_stall, 0);
2392 netif_wake_queue(netdev);
2393 } else {
2394 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2395 }
2396 }
2397}
2398
2399/**
2400 * e1000_watchdog - Timer Call-back
2401 * @data: pointer to adapter cast into an unsigned long
2402 **/
2403static void
2404e1000_watchdog(unsigned long data)
2405{
2406 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002408 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002409 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002410 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Auke Kokcd94dd02006-06-27 09:08:22 -07002412 ret_val = e1000_check_for_link(&adapter->hw);
2413 if ((ret_val == E1000_ERR_PHY) &&
2414 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2415 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2416 /* See e1000_kumeran_lock_loss_workaround() */
2417 DPRINTK(LINK, INFO,
2418 "Gigabit has been disabled, downgrading speed\n");
2419 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002420 if (adapter->hw.mac_type == e1000_82573) {
2421 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002422 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002423 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002426 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2428 link = !adapter->hw.serdes_link_down;
2429 else
2430 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2431
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002432 if (link) {
2433 if (!netif_carrier_ok(netdev)) {
Auke Kokfe7fe282006-04-14 19:04:59 -07002434 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 e1000_get_speed_and_duplex(&adapter->hw,
2436 &adapter->link_speed,
2437 &adapter->link_duplex);
2438
2439 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2440 adapter->link_speed,
2441 adapter->link_duplex == FULL_DUPLEX ?
2442 "Full Duplex" : "Half Duplex");
2443
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002444 /* tweak tx_queue_len according to speed/duplex
2445 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002446 netdev->tx_queue_len = adapter->tx_queue_len;
2447 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002448 switch (adapter->link_speed) {
2449 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002450 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002451 netdev->tx_queue_len = 10;
2452 adapter->tx_timeout_factor = 8;
2453 break;
2454 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002455 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002456 netdev->tx_queue_len = 100;
2457 /* maybe add some timeout factor ? */
2458 break;
2459 }
2460
Auke Kokfe7fe282006-04-14 19:04:59 -07002461 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002462 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002463 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002464#define SPEED_MODE_BIT (1 << 21)
2465 uint32_t tarc0;
2466 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2467 tarc0 &= ~SPEED_MODE_BIT;
2468 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2469 }
2470
2471#ifdef NETIF_F_TSO
2472 /* disable TSO for pcie and 10/100 speeds, to avoid
2473 * some hardware issues */
2474 if (!adapter->tso_force &&
2475 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002476 switch (adapter->link_speed) {
2477 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002478 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002479 DPRINTK(PROBE,INFO,
2480 "10/100 speed: disabling TSO\n");
2481 netdev->features &= ~NETIF_F_TSO;
2482 break;
2483 case SPEED_1000:
2484 netdev->features |= NETIF_F_TSO;
2485 break;
2486 default:
2487 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002488 break;
2489 }
2490 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002491#endif
2492
2493 /* enable transmits in the hardware, need to do this
2494 * after setting TARC0 */
2495 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2496 tctl |= E1000_TCTL_EN;
2497 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002498
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 netif_carrier_on(netdev);
2500 netif_wake_queue(netdev);
2501 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2502 adapter->smartspeed = 0;
2503 }
2504 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002505 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 adapter->link_speed = 0;
2507 adapter->link_duplex = 0;
2508 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2509 netif_carrier_off(netdev);
2510 netif_stop_queue(netdev);
2511 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002512
2513 /* 80003ES2LAN workaround--
2514 * For packet buffer work-around on link down event;
2515 * disable receives in the ISR and
2516 * reset device here in the watchdog
2517 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002518 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002519 /* reset device */
2520 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 }
2522
2523 e1000_smartspeed(adapter);
2524 }
2525
2526 e1000_update_stats(adapter);
2527
2528 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2529 adapter->tpt_old = adapter->stats.tpt;
2530 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2531 adapter->colc_old = adapter->stats.colc;
2532
2533 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2534 adapter->gorcl_old = adapter->stats.gorcl;
2535 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2536 adapter->gotcl_old = adapter->stats.gotcl;
2537
2538 e1000_update_adaptive(&adapter->hw);
2539
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002540 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002541 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 /* We've lost link, so the controller stops DMA,
2543 * but we've got queued Tx work that's never going
2544 * to get done, so reset controller to flush Tx.
2545 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002546 adapter->tx_timeout_count++;
2547 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 }
2549 }
2550
2551 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002552 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2554 * asymmetrical Tx or Rx gets ITR=8000; everyone
2555 * else is between 2000-8000. */
2556 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002557 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 adapter->gotcl - adapter->gorcl :
2559 adapter->gorcl - adapter->gotcl) / 10000;
2560 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2561 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2562 }
2563
2564 /* Cause software interrupt to ensure rx ring is cleaned */
2565 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2566
Malli Chilakala26483452005-04-28 19:44:46 -07002567 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 adapter->detect_tx_hung = TRUE;
2569
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002570 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002571 * reset from the other port. Set the appropriate LAA in RAR[0] */
2572 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2573 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2574
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 /* Reset the timer */
2576 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2577}
2578
2579#define E1000_TX_FLAGS_CSUM 0x00000001
2580#define E1000_TX_FLAGS_VLAN 0x00000002
2581#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002582#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2584#define E1000_TX_FLAGS_VLAN_SHIFT 16
2585
Auke Koke619d522006-04-14 19:04:52 -07002586static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002587e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2588 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589{
2590#ifdef NETIF_F_TSO
2591 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002592 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 unsigned int i;
2594 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002595 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2597 int err;
2598
Herbert Xu89114af2006-07-08 13:34:32 -07002599 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 if (skb_header_cloned(skb)) {
2601 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2602 if (err)
2603 return err;
2604 }
2605
2606 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Herbert Xu79671682006-06-22 02:40:14 -07002607 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002608 if (skb->protocol == htons(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002609 skb->nh.iph->tot_len = 0;
2610 skb->nh.iph->check = 0;
2611 skb->h.th->check =
2612 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2613 skb->nh.iph->daddr,
2614 0,
2615 IPPROTO_TCP,
2616 0);
2617 cmd_length = E1000_TXD_CMD_IP;
2618 ipcse = skb->h.raw - skb->data - 1;
2619#ifdef NETIF_F_TSO_IPV6
Auke Koke15fdd02006-08-16 11:28:45 -07002620 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002621 skb->nh.ipv6h->payload_len = 0;
2622 skb->h.th->check =
2623 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2624 &skb->nh.ipv6h->daddr,
2625 0,
2626 IPPROTO_TCP,
2627 0);
2628 ipcse = 0;
2629#endif
2630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 ipcss = skb->nh.raw - skb->data;
2632 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 tucss = skb->h.raw - skb->data;
2634 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2635 tucse = 0;
2636
2637 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002638 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002640 i = tx_ring->next_to_use;
2641 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002642 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643
2644 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2645 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2646 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2647 context_desc->upper_setup.tcp_fields.tucss = tucss;
2648 context_desc->upper_setup.tcp_fields.tucso = tucso;
2649 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2650 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2651 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2652 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2653
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002654 buffer_info->time_stamp = jiffies;
2655
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002656 if (++i == tx_ring->count) i = 0;
2657 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
Jeff Kirsher8241e352006-01-12 16:51:34 -08002659 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 }
2661#endif
2662
Jeff Kirsher8241e352006-01-12 16:51:34 -08002663 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664}
2665
Auke Koke619d522006-04-14 19:04:52 -07002666static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002667e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2668 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669{
2670 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002671 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 unsigned int i;
2673 uint8_t css;
2674
Patrick McHardy84fa7932006-08-29 16:44:56 -07002675 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 css = skb->h.raw - skb->data;
2677
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002678 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002679 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002680 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681
2682 context_desc->upper_setup.tcp_fields.tucss = css;
2683 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2684 context_desc->upper_setup.tcp_fields.tucse = 0;
2685 context_desc->tcp_seg_setup.data = 0;
2686 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2687
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002688 buffer_info->time_stamp = jiffies;
2689
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002690 if (unlikely(++i == tx_ring->count)) i = 0;
2691 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
2693 return TRUE;
2694 }
2695
2696 return FALSE;
2697}
2698
2699#define E1000_MAX_TXD_PWR 12
2700#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2701
Auke Koke619d522006-04-14 19:04:52 -07002702static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002703e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2704 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2705 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 struct e1000_buffer *buffer_info;
2708 unsigned int len = skb->len;
2709 unsigned int offset = 0, size, count = 0, i;
2710 unsigned int f;
2711 len -= skb->data_len;
2712
2713 i = tx_ring->next_to_use;
2714
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002715 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 buffer_info = &tx_ring->buffer_info[i];
2717 size = min(len, max_per_txd);
2718#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002719 /* Workaround for Controller erratum --
2720 * descriptor for non-tso packet in a linear SKB that follows a
2721 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002722 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002723 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07002724 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002725 tx_ring->last_tx_tso = 0;
2726 size -= 4;
2727 }
2728
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 /* Workaround for premature desc write-backs
2730 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002731 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 size -= 4;
2733#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002734 /* work-around for errata 10 and it applies
2735 * to all controllers in PCI-X mode
2736 * The fix is to make sure that the first descriptor of a
2737 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2738 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002739 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002740 (size > 2015) && count == 0))
2741 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002742
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 /* Workaround for potential 82544 hang in PCI-X. Avoid
2744 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002745 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2747 size > 4))
2748 size -= 4;
2749
2750 buffer_info->length = size;
2751 buffer_info->dma =
2752 pci_map_single(adapter->pdev,
2753 skb->data + offset,
2754 size,
2755 PCI_DMA_TODEVICE);
2756 buffer_info->time_stamp = jiffies;
2757
2758 len -= size;
2759 offset += size;
2760 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002761 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 }
2763
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002764 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 struct skb_frag_struct *frag;
2766
2767 frag = &skb_shinfo(skb)->frags[f];
2768 len = frag->size;
2769 offset = frag->page_offset;
2770
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002771 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 buffer_info = &tx_ring->buffer_info[i];
2773 size = min(len, max_per_txd);
2774#ifdef NETIF_F_TSO
2775 /* Workaround for premature desc write-backs
2776 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002777 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 size -= 4;
2779#endif
2780 /* Workaround for potential 82544 hang in PCI-X.
2781 * Avoid terminating buffers within evenly-aligned
2782 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002783 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2785 size > 4))
2786 size -= 4;
2787
2788 buffer_info->length = size;
2789 buffer_info->dma =
2790 pci_map_page(adapter->pdev,
2791 frag->page,
2792 offset,
2793 size,
2794 PCI_DMA_TODEVICE);
2795 buffer_info->time_stamp = jiffies;
2796
2797 len -= size;
2798 offset += size;
2799 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002800 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 }
2802 }
2803
2804 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2805 tx_ring->buffer_info[i].skb = skb;
2806 tx_ring->buffer_info[first].next_to_watch = i;
2807
2808 return count;
2809}
2810
Auke Koke619d522006-04-14 19:04:52 -07002811static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002812e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2813 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 struct e1000_tx_desc *tx_desc = NULL;
2816 struct e1000_buffer *buffer_info;
2817 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2818 unsigned int i;
2819
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002820 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2822 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002823 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2824
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002825 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002826 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 }
2828
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002829 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2831 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2832 }
2833
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002834 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 txd_lower |= E1000_TXD_CMD_VLE;
2836 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2837 }
2838
2839 i = tx_ring->next_to_use;
2840
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002841 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 buffer_info = &tx_ring->buffer_info[i];
2843 tx_desc = E1000_TX_DESC(*tx_ring, i);
2844 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2845 tx_desc->lower.data =
2846 cpu_to_le32(txd_lower | buffer_info->length);
2847 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002848 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 }
2850
2851 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2852
2853 /* Force memory writes to complete before letting h/w
2854 * know there are new descriptors to fetch. (Only
2855 * applicable for weak-ordered memory model archs,
2856 * such as IA-64). */
2857 wmb();
2858
2859 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002860 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861}
2862
2863/**
2864 * 82547 workaround to avoid controller hang in half-duplex environment.
2865 * The workaround is to avoid queuing a large packet that would span
2866 * the internal Tx FIFO ring boundary by notifying the stack to resend
2867 * the packet at a later time. This gives the Tx FIFO an opportunity to
2868 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2869 * to the beginning of the Tx FIFO.
2870 **/
2871
2872#define E1000_FIFO_HDR 0x10
2873#define E1000_82547_PAD_LEN 0x3E0
2874
Auke Koke619d522006-04-14 19:04:52 -07002875static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2877{
2878 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2879 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2880
2881 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2882
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002883 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 goto no_fifo_stall_required;
2885
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002886 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 return 1;
2888
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002889 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 atomic_set(&adapter->tx_fifo_stall, 1);
2891 return 1;
2892 }
2893
2894no_fifo_stall_required:
2895 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002896 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2898 return 0;
2899}
2900
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002901#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07002902static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002903e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2904{
2905 struct e1000_hw *hw = &adapter->hw;
2906 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002907 if (vlan_tx_tag_present(skb)) {
2908 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002909 ( adapter->hw.mng_cookie.status &
2910 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2911 return 0;
2912 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08002913 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002914 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002915 if ((htons(ETH_P_IP) == eth->h_proto)) {
2916 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002917 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002918 if (IPPROTO_UDP == ip->protocol) {
2919 struct udphdr *udp =
2920 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002921 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002922 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002923 offset = (uint8_t *)udp + 8 - skb->data;
2924 length = skb->len - offset;
2925
2926 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002927 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002928 length);
2929 }
2930 }
2931 }
2932 }
2933 return 0;
2934}
2935
Jesse Brandeburg65c79732006-09-27 12:53:48 -07002936static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
2937{
2938 struct e1000_adapter *adapter = netdev_priv(netdev);
2939 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
2940
2941 netif_stop_queue(netdev);
2942 /* Herbert's original patch had:
2943 * smp_mb__after_netif_stop_queue();
2944 * but since that doesn't exist yet, just open code it. */
2945 smp_mb();
2946
2947 /* We need to check again in a case another CPU has just
2948 * made room available. */
2949 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
2950 return -EBUSY;
2951
2952 /* A reprieve! */
2953 netif_start_queue(netdev);
2954 return 0;
2955}
2956
2957static int e1000_maybe_stop_tx(struct net_device *netdev,
2958 struct e1000_tx_ring *tx_ring, int size)
2959{
2960 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
2961 return 0;
2962 return __e1000_maybe_stop_tx(netdev, size);
2963}
2964
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2966static int
2967e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2968{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002969 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002970 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2972 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2973 unsigned int tx_flags = 0;
2974 unsigned int len = skb->len;
2975 unsigned long flags;
2976 unsigned int nr_frags = 0;
2977 unsigned int mss = 0;
2978 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07002979 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 unsigned int f;
2981 len -= skb->data_len;
2982
Jesse Brandeburg65c79732006-09-27 12:53:48 -07002983 /* This goes back to the question of how to logically map a tx queue
2984 * to a flow. Right now, performance is impacted slightly negatively
2985 * if using multiple tx queues. If the stack breaks away from a
2986 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002987 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002988
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002989 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 dev_kfree_skb_any(skb);
2991 return NETDEV_TX_OK;
2992 }
2993
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07002994 /* 82571 and newer doesn't need the workaround that limited descriptor
2995 * length to 4kB */
2996 if (adapter->hw.mac_type >= e1000_82571)
2997 max_per_txd = 8192;
2998
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999#ifdef NETIF_F_TSO
Herbert Xu79671682006-06-22 02:40:14 -07003000 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003001 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 * make sure there is enough room in the FIFO before
3003 * initiating the DMA for each buffer. The calc is:
3004 * 4 = ceil(buffer len/mss). To make sure we don't
3005 * overrun the FIFO, adjust the max buffer len if mss
3006 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003007 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003008 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 max_per_txd = min(mss << 2, max_per_txd);
3010 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003011
Jeff Kirsher9f687882006-03-02 18:20:17 -08003012 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003013 * points to just header, pull a few bytes of payload from
3014 * frags into skb->data */
3015 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08003016 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3017 switch (adapter->hw.mac_type) {
3018 unsigned int pull_size;
3019 case e1000_82571:
3020 case e1000_82572:
3021 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003022 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003023 pull_size = min((unsigned int)4, skb->data_len);
3024 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003025 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003026 "__pskb_pull_tail failed.\n");
3027 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003028 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003029 }
3030 len = skb->len - skb->data_len;
3031 break;
3032 default:
3033 /* do nothing */
3034 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003035 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003036 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 }
3038
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003039 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003040 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003042 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043#else
Patrick McHardy84fa7932006-08-29 16:44:56 -07003044 if (skb->ip_summed == CHECKSUM_PARTIAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 count++;
3046#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05003047
3048#ifdef NETIF_F_TSO
3049 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003050 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003051 count++;
3052#endif
3053
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 count += TXD_USE_COUNT(len, max_txd_pwr);
3055
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003056 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 count++;
3058
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003059 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003060 * in PCI-X mode, so add one more descriptor to the count
3061 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003062 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003063 (len > 2015)))
3064 count++;
3065
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003067 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3069 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003070 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 count += nr_frags;
3072
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003073
3074 if (adapter->hw.tx_pkt_filtering &&
3075 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003076 e1000_transfer_dhcp_info(adapter, skb);
3077
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003078 local_irq_save(flags);
3079 if (!spin_trylock(&tx_ring->tx_lock)) {
3080 /* Collision - tell upper layer to requeue */
3081 local_irq_restore(flags);
3082 return NETDEV_TX_LOCKED;
3083 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
3085 /* need: count + 2 desc gap to keep tail from touching
3086 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003087 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003088 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 return NETDEV_TX_BUSY;
3090 }
3091
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003092 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3093 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003095 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003096 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 return NETDEV_TX_BUSY;
3098 }
3099 }
3100
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003101 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 tx_flags |= E1000_TX_FLAGS_VLAN;
3103 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3104 }
3105
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003106 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003107
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003108 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 if (tso < 0) {
3110 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003111 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 return NETDEV_TX_OK;
3113 }
3114
Jeff Kirsherfd803242005-12-13 00:06:22 -05003115 if (likely(tso)) {
3116 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003118 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 tx_flags |= E1000_TX_FLAGS_CSUM;
3120
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003121 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003122 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003123 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003124 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003125 tx_flags |= E1000_TX_FLAGS_IPV4;
3126
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003127 e1000_tx_queue(adapter, tx_ring, tx_flags,
3128 e1000_tx_map(adapter, tx_ring, skb, first,
3129 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130
3131 netdev->trans_start = jiffies;
3132
3133 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003134 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003136 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 return NETDEV_TX_OK;
3138}
3139
3140/**
3141 * e1000_tx_timeout - Respond to a Tx Hang
3142 * @netdev: network interface device structure
3143 **/
3144
3145static void
3146e1000_tx_timeout(struct net_device *netdev)
3147{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003148 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149
3150 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003151 adapter->tx_timeout_count++;
3152 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153}
3154
3155static void
David Howells65f27f32006-11-22 14:55:48 +00003156e1000_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157{
David Howells65f27f32006-11-22 14:55:48 +00003158 struct e1000_adapter *adapter =
3159 container_of(work, struct e1000_adapter, reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160
Auke Kok2db10a02006-06-27 09:06:28 -07003161 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162}
3163
3164/**
3165 * e1000_get_stats - Get System Network Statistics
3166 * @netdev: network interface device structure
3167 *
3168 * Returns the address of the device statistics structure.
3169 * The statistics are actually updated from the timer callback.
3170 **/
3171
3172static struct net_device_stats *
3173e1000_get_stats(struct net_device *netdev)
3174{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003175 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003177 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 return &adapter->net_stats;
3179}
3180
3181/**
3182 * e1000_change_mtu - Change the Maximum Transfer Unit
3183 * @netdev: network interface device structure
3184 * @new_mtu: new value for maximum frame size
3185 *
3186 * Returns 0 on success, negative on failure
3187 **/
3188
3189static int
3190e1000_change_mtu(struct net_device *netdev, int new_mtu)
3191{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003192 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003194 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003196 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3197 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3198 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003199 return -EINVAL;
3200 }
3201
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003202 /* Adapter-specific max frame size limits. */
3203 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003204 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003205 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003206 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3207 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003208 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003209 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003210 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003211 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003212 /* Jumbo Frames not supported if:
3213 * - this is not an 82573L device
3214 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003215 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3216 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003217 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3218 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003219 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3220 DPRINTK(PROBE, ERR,
3221 "Jumbo Frames not supported.\n");
3222 return -EINVAL;
3223 }
3224 break;
3225 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003226 /* ERT will be enabled later to enable wire speed receives */
3227
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003228 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003229 case e1000_82571:
3230 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003231 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003232#define MAX_STD_JUMBO_FRAME_SIZE 9234
3233 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3234 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3235 return -EINVAL;
3236 }
3237 break;
3238 default:
3239 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3240 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003241 }
3242
David S. Miller87f50322006-07-31 22:39:40 -07003243 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003244 * means we reserve 2 more, this pushes us to allocate from the next
3245 * larger slab size
3246 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003247
Auke Kok9e2feac2006-04-14 19:05:18 -07003248 if (max_frame <= E1000_RXBUFFER_256)
3249 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3250 else if (max_frame <= E1000_RXBUFFER_512)
3251 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3252 else if (max_frame <= E1000_RXBUFFER_1024)
3253 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3254 else if (max_frame <= E1000_RXBUFFER_2048)
3255 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3256 else if (max_frame <= E1000_RXBUFFER_4096)
3257 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3258 else if (max_frame <= E1000_RXBUFFER_8192)
3259 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3260 else if (max_frame <= E1000_RXBUFFER_16384)
3261 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3262
3263 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003264 if (!adapter->hw.tbi_compatibility_on &&
3265 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3266 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3267 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003268
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003269 netdev->mtu = new_mtu;
3270
Auke Kok2db10a02006-06-27 09:06:28 -07003271 if (netif_running(netdev))
3272 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 adapter->hw.max_frame_size = max_frame;
3275
3276 return 0;
3277}
3278
3279/**
3280 * e1000_update_stats - Update the board statistics counters
3281 * @adapter: board private structure
3282 **/
3283
3284void
3285e1000_update_stats(struct e1000_adapter *adapter)
3286{
3287 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003288 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 unsigned long flags;
3290 uint16_t phy_tmp;
3291
3292#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3293
Linas Vepstas282f33c2006-06-08 22:19:44 -07003294 /*
3295 * Prevent stats update while adapter is being reset, or if the pci
3296 * connection is down.
3297 */
Auke Kok90267292006-06-08 09:30:24 -07003298 if (adapter->link_speed == 0)
3299 return;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003300 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3301 return;
Auke Kok90267292006-06-08 09:30:24 -07003302
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 spin_lock_irqsave(&adapter->stats_lock, flags);
3304
3305 /* these counters are modified from e1000_adjust_tbi_stats,
3306 * called from the interrupt context, so they must only
3307 * be written while holding adapter->stats_lock
3308 */
3309
3310 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3311 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3312 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3313 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3314 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3315 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3316 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003317
3318 if (adapter->hw.mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3320 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3321 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3322 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3323 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3324 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
3327 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3328 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3329 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3330 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3331 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3332 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3333 adapter->stats.dc += E1000_READ_REG(hw, DC);
3334 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3335 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3336 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3337 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3338 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3339 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3340 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3341 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3342 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3343 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3344 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3345 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3346 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3347 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3348 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3349 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3350 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3351 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3352 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003353
3354 if (adapter->hw.mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3356 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3357 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3358 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3359 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3360 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003361 }
3362
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3364 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3365
3366 /* used for adaptive IFS */
3367
3368 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3369 adapter->stats.tpt += hw->tx_packet_delta;
3370 hw->collision_delta = E1000_READ_REG(hw, COLC);
3371 adapter->stats.colc += hw->collision_delta;
3372
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003373 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3375 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3376 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3377 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3378 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3379 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3380 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003381 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003382 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3383 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003384
3385 if (adapter->hw.mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003386 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3387 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3388 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3389 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3390 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3391 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3392 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003393 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
3396 /* Fill out the OS statistics structure */
3397
3398 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 */
3429
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003430 if (hw->media_type == e1000_media_type_copper) {
3431 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3433 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3434 adapter->phy_stats.idle_errors += phy_tmp;
3435 }
3436
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003437 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 (hw->phy_type == e1000_phy_m88) &&
3439 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3440 adapter->phy_stats.receive_errors += phy_tmp;
3441 }
3442
3443 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3444}
3445
3446/**
3447 * e1000_intr - Interrupt Handler
3448 * @irq: interrupt number
3449 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 **/
3451
3452static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003453e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454{
3455 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003456 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003458 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003459#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003460 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003461#else
3462 /* Interrupt Auto-Mask...upon reading ICR,
3463 * interrupts are masked. No need for the
3464 * IMC write, but it does mean we should
3465 * account for it ASAP. */
3466 if (likely(hw->mac_type >= e1000_82571))
3467 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003468#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003470 if (unlikely(!icr)) {
3471#ifdef CONFIG_E1000_NAPI
3472 if (hw->mac_type >= e1000_82571)
3473 e1000_irq_enable(adapter);
3474#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003478 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003480 /* 80003ES2LAN workaround--
3481 * For packet buffer work-around on link down event;
3482 * disable receives here in the ISR and
3483 * reset adapter in watchdog
3484 */
3485 if (netif_carrier_ok(netdev) &&
3486 (adapter->hw.mac_type == e1000_80003es2lan)) {
3487 /* disable receives */
3488 rctl = E1000_READ_REG(hw, RCTL);
3489 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3490 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003491 /* guard against interrupt when we're going down */
3492 if (!test_bit(__E1000_DOWN, &adapter->flags))
3493 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 }
3495
3496#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003497 if (unlikely(hw->mac_type < e1000_82571)) {
3498 atomic_inc(&adapter->irq_sem);
3499 E1000_WRITE_REG(hw, IMC, ~0);
3500 E1000_WRITE_FLUSH(hw);
3501 }
Auke Kokd3d9e482006-07-14 16:14:23 -07003502 if (likely(netif_rx_schedule_prep(netdev)))
3503 __netif_rx_schedule(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003504 else
3505 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003506#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003508 * Due to Hub Link bus being occupied, an interrupt
3509 * de-assertion message is not able to be sent.
3510 * When an interrupt assertion message is generated later,
3511 * two messages are re-ordered and sent out.
3512 * That causes APIC to think 82547 is in de-assertion
3513 * state, while 82547 is in assertion state, resulting
3514 * in dead lock. Writing IMC forces 82547 into
3515 * de-assertion state.
3516 */
3517 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003519 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 }
3521
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003522 for (i = 0; i < E1000_MAX_INTR; i++)
3523 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003524 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 break;
3526
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003527 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003529
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003530#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531
3532 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
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003618
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 eop = tx_ring->buffer_info[i].next_to_watch;
3620 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003621#ifdef CONFIG_E1000_NAPI
3622#define E1000_TX_WEIGHT 64
3623 /* weight of a sort for tx, to avoid endless transmit cleanup */
3624 if (count++ == E1000_TX_WEIGHT) break;
3625#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 }
3627
3628 tx_ring->next_to_clean = i;
3629
Auke Kok77b2aad2006-04-14 19:05:25 -07003630#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003631 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3632 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3633 /* Make sure that anybody stopping the queue after this
3634 * sees the new next_to_clean.
3635 */
3636 smp_mb();
3637 if (netif_queue_stopped(netdev))
Auke Kok77b2aad2006-04-14 19:05:25 -07003638 netif_wake_queue(netdev);
Auke Kok77b2aad2006-04-14 19:05:25 -07003639 }
Malli Chilakala26483452005-04-28 19:44:46 -07003640
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003641 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003642 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 * check with the clearing of time_stamp and movement of i */
3644 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003645 if (tx_ring->buffer_info[eop].dma &&
3646 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003647 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003648 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003649 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003650
3651 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003652 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003653 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003654 " TDH <%x>\n"
3655 " TDT <%x>\n"
3656 " next_to_use <%x>\n"
3657 " next_to_clean <%x>\n"
3658 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003659 " time_stamp <%lx>\n"
3660 " next_to_watch <%x>\n"
3661 " jiffies <%lx>\n"
3662 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003663 (unsigned long)((tx_ring - adapter->tx_ring) /
3664 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003665 readl(adapter->hw.hw_addr + tx_ring->tdh),
3666 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003667 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003668 tx_ring->next_to_clean,
3669 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003670 eop,
3671 jiffies,
3672 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 return cleaned;
3677}
3678
3679/**
3680 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003681 * @adapter: board private structure
3682 * @status_err: receive descriptor status and error fields
3683 * @csum: receive descriptor csum field
3684 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 **/
3686
Auke Koke619d522006-04-14 19:04:52 -07003687static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003689 uint32_t status_err, uint32_t csum,
3690 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003692 uint16_t status = (uint16_t)status_err;
3693 uint8_t errors = (uint8_t)(status_err >> 24);
3694 skb->ip_summed = CHECKSUM_NONE;
3695
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003697 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003699 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003700 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003701 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003702 /* let the stack verify checksum errors */
3703 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 return;
3705 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003706 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003707 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3708 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003709 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003711 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003712 return;
3713 }
3714 /* It must be a TCP or UDP packet with a valid checksum */
3715 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 /* TCP checksum is good */
3717 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003718 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3719 /* IP fragment with UDP payload */
3720 /* Hardware complements the payload checksum, so we undo it
3721 * and then put the value in host order for further stack use.
3722 */
3723 csum = ntohl(csum ^ 0xFFFF);
3724 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07003725 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003727 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728}
3729
3730/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003731 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 * @adapter: board private structure
3733 **/
3734
3735static boolean_t
3736#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003737e1000_clean_rx_irq(struct e1000_adapter *adapter,
3738 struct e1000_rx_ring *rx_ring,
3739 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003741e1000_clean_rx_irq(struct e1000_adapter *adapter,
3742 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743#endif
3744{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 struct net_device *netdev = adapter->netdev;
3746 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003747 struct e1000_rx_desc *rx_desc, *next_rxd;
3748 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 unsigned long flags;
3750 uint32_t length;
3751 uint8_t last_byte;
3752 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003753 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003754 boolean_t cleaned = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755
3756 i = rx_ring->next_to_clean;
3757 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003758 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003760 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07003761 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003762 u8 status;
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 }
4002
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,
4237 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
4514
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515void
4516e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4517{
4518 outl(value, port);
4519}
4520
4521static void
4522e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4523{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004524 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 uint32_t ctrl, rctl;
4526
4527 e1000_irq_disable(adapter);
4528 adapter->vlgrp = grp;
4529
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004530 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531 /* enable VLAN tag insert/strip */
4532 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4533 ctrl |= E1000_CTRL_VME;
4534 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4535
Auke Kokcd94dd02006-06-27 09:08:22 -07004536 if (adapter->hw.mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 /* enable VLAN receive filtering */
4538 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4539 rctl |= E1000_RCTL_VFE;
4540 rctl &= ~E1000_RCTL_CFIEN;
4541 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004542 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 } else {
4545 /* disable VLAN tag insert/strip */
4546 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4547 ctrl &= ~E1000_CTRL_VME;
4548 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4549
Auke Kokcd94dd02006-06-27 09:08:22 -07004550 if (adapter->hw.mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 /* disable VLAN filtering */
4552 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4553 rctl &= ~E1000_RCTL_VFE;
4554 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004555 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004556 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4557 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4558 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 }
4561
4562 e1000_irq_enable(adapter);
4563}
4564
4565static void
4566e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4567{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004568 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004570
4571 if ((adapter->hw.mng_cookie.status &
4572 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4573 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004574 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575 /* add VID to filter table */
4576 index = (vid >> 5) & 0x7F;
4577 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4578 vfta |= (1 << (vid & 0x1F));
4579 e1000_write_vfta(&adapter->hw, index, vfta);
4580}
4581
4582static void
4583e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4584{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004585 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 uint32_t vfta, index;
4587
4588 e1000_irq_disable(adapter);
4589
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004590 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 adapter->vlgrp->vlan_devices[vid] = NULL;
4592
4593 e1000_irq_enable(adapter);
4594
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004595 if ((adapter->hw.mng_cookie.status &
4596 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004597 (vid == adapter->mng_vlan_id)) {
4598 /* release control to f/w */
4599 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004600 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004601 }
4602
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 /* remove VID from filter table */
4604 index = (vid >> 5) & 0x7F;
4605 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4606 vfta &= ~(1 << (vid & 0x1F));
4607 e1000_write_vfta(&adapter->hw, index, vfta);
4608}
4609
4610static void
4611e1000_restore_vlan(struct e1000_adapter *adapter)
4612{
4613 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4614
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004615 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004617 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4618 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 continue;
4620 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4621 }
4622 }
4623}
4624
4625int
4626e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4627{
4628 adapter->hw.autoneg = 0;
4629
Malli Chilakala69213682005-06-17 17:44:20 -07004630 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004631 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004632 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4633 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4634 return -EINVAL;
4635 }
4636
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004637 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 case SPEED_10 + DUPLEX_HALF:
4639 adapter->hw.forced_speed_duplex = e1000_10_half;
4640 break;
4641 case SPEED_10 + DUPLEX_FULL:
4642 adapter->hw.forced_speed_duplex = e1000_10_full;
4643 break;
4644 case SPEED_100 + DUPLEX_HALF:
4645 adapter->hw.forced_speed_duplex = e1000_100_half;
4646 break;
4647 case SPEED_100 + DUPLEX_FULL:
4648 adapter->hw.forced_speed_duplex = e1000_100_full;
4649 break;
4650 case SPEED_1000 + DUPLEX_FULL:
4651 adapter->hw.autoneg = 1;
4652 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4653 break;
4654 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4655 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004656 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 return -EINVAL;
4658 }
4659 return 0;
4660}
4661
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004662#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004663/* Save/restore 16 or 64 dwords of PCI config space depending on which
4664 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004665 */
4666#define PCIE_CONFIG_SPACE_LEN 256
4667#define PCI_CONFIG_SPACE_LEN 64
4668static int
4669e1000_pci_save_state(struct e1000_adapter *adapter)
4670{
4671 struct pci_dev *dev = adapter->pdev;
4672 int size;
4673 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004674
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004675 if (adapter->hw.mac_type >= e1000_82571)
4676 size = PCIE_CONFIG_SPACE_LEN;
4677 else
4678 size = PCI_CONFIG_SPACE_LEN;
4679
4680 WARN_ON(adapter->config_space != NULL);
4681
4682 adapter->config_space = kmalloc(size, GFP_KERNEL);
4683 if (!adapter->config_space) {
4684 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4685 return -ENOMEM;
4686 }
4687 for (i = 0; i < (size / 4); i++)
4688 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4689 return 0;
4690}
4691
4692static void
4693e1000_pci_restore_state(struct e1000_adapter *adapter)
4694{
4695 struct pci_dev *dev = adapter->pdev;
4696 int size;
4697 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004698
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004699 if (adapter->config_space == NULL)
4700 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004701
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004702 if (adapter->hw.mac_type >= e1000_82571)
4703 size = PCIE_CONFIG_SPACE_LEN;
4704 else
4705 size = PCI_CONFIG_SPACE_LEN;
4706 for (i = 0; i < (size / 4); i++)
4707 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4708 kfree(adapter->config_space);
4709 adapter->config_space = NULL;
4710 return;
4711}
4712#endif /* CONFIG_PM */
4713
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004715e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716{
4717 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004718 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004719 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07004721#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08004722 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07004723#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724
4725 netif_device_detach(netdev);
4726
Auke Kok2db10a02006-06-27 09:06:28 -07004727 if (netif_running(netdev)) {
4728 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07004730 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004732#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004733 /* Implement our own version of pci_save_state(pdev) because pci-
4734 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004735 retval = e1000_pci_save_state(adapter);
4736 if (retval)
4737 return retval;
4738#endif
4739
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004741 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 wufc &= ~E1000_WUFC_LNKC;
4743
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004744 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 e1000_setup_rctl(adapter);
4746 e1000_set_multi(netdev);
4747
4748 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07004749 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4751 rctl |= E1000_RCTL_MPE;
4752 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4753 }
4754
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004755 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4757 /* advertise wake from D3Cold */
4758 #define E1000_CTRL_ADVD3WUC 0x00100000
4759 /* phy power management enable */
4760 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4761 ctrl |= E1000_CTRL_ADVD3WUC |
4762 E1000_CTRL_EN_PHY_PWR_MGMT;
4763 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4764 }
4765
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004766 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4768 /* keep the laser running in D3 */
4769 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4770 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4771 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4772 }
4773
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004774 /* Allow time for pending master requests to run */
4775 e1000_disable_pciex_master(&adapter->hw);
4776
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4778 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004779 pci_enable_wake(pdev, PCI_D3hot, 1);
4780 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 } else {
4782 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4783 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07004784 pci_enable_wake(pdev, PCI_D3hot, 0);
4785 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 }
4787
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004788 if (adapter->hw.mac_type >= e1000_82540 &&
4789 adapter->hw.mac_type < e1000_82571 &&
4790 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004792 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 manc |= E1000_MANC_ARP_EN;
4794 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004795 pci_enable_wake(pdev, PCI_D3hot, 1);
4796 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 }
4798 }
4799
Auke Kokcd94dd02006-06-27 09:08:22 -07004800 if (adapter->hw.phy_type == e1000_phy_igp_3)
4801 e1000_phy_powerdown_workaround(&adapter->hw);
4802
Auke Kokedd106f2006-11-06 08:57:12 -08004803 if (netif_running(netdev))
4804 e1000_free_irq(adapter);
4805
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004806 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4807 * would have already happened in close and is redundant. */
4808 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004809
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004811
Auke Kokd0e027d2006-04-14 19:04:40 -07004812 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813
4814 return 0;
4815}
4816
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004817#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818static int
4819e1000_resume(struct pci_dev *pdev)
4820{
4821 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004822 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004823 uint32_t manc, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824
Auke Kokd0e027d2006-04-14 19:04:40 -07004825 pci_set_power_state(pdev, PCI_D0);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004826 e1000_pci_restore_state(adapter);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004827 if ((err = pci_enable_device(pdev))) {
4828 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
4829 return err;
4830 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004831 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832
Auke Kokd0e027d2006-04-14 19:04:40 -07004833 pci_enable_wake(pdev, PCI_D3hot, 0);
4834 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835
Auke Kokedd106f2006-11-06 08:57:12 -08004836 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
4837 return err;
4838
4839 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840 e1000_reset(adapter);
4841 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4842
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004843 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 e1000_up(adapter);
4845
4846 netif_device_attach(netdev);
4847
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004848 if (adapter->hw.mac_type >= e1000_82540 &&
4849 adapter->hw.mac_type < e1000_82571 &&
4850 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851 manc = E1000_READ_REG(&adapter->hw, MANC);
4852 manc &= ~(E1000_MANC_ARP_EN);
4853 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4854 }
4855
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004856 /* If the controller is 82573 and f/w is AMT, do not set
4857 * DRV_LOAD until the interface is up. For all other cases,
4858 * let the f/w know that the h/w is now under the control
4859 * of the driver. */
4860 if (adapter->hw.mac_type != e1000_82573 ||
4861 !e1000_check_mng_mode(&adapter->hw))
4862 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004863
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864 return 0;
4865}
4866#endif
Auke Kokc653e632006-05-23 13:35:57 -07004867
4868static void e1000_shutdown(struct pci_dev *pdev)
4869{
4870 e1000_suspend(pdev, PMSG_SUSPEND);
4871}
4872
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873#ifdef CONFIG_NET_POLL_CONTROLLER
4874/*
4875 * Polling 'interrupt' - used by things like netconsole to send skbs
4876 * without having to re-enable interrupts. It's not called while
4877 * the interrupt routine is executing.
4878 */
4879static void
Malli Chilakala26483452005-04-28 19:44:46 -07004880e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004882 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07004883
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01004885 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004886 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004887#ifndef CONFIG_E1000_NAPI
4888 adapter->clean_rx(adapter, adapter->rx_ring);
4889#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 enable_irq(adapter->pdev->irq);
4891}
4892#endif
4893
Auke Kok90267292006-06-08 09:30:24 -07004894/**
4895 * e1000_io_error_detected - called when PCI error is detected
4896 * @pdev: Pointer to PCI device
4897 * @state: The current pci conneection state
4898 *
4899 * This function is called after a PCI bus error affecting
4900 * this device has been detected.
4901 */
4902static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4903{
4904 struct net_device *netdev = pci_get_drvdata(pdev);
4905 struct e1000_adapter *adapter = netdev->priv;
4906
4907 netif_device_detach(netdev);
4908
4909 if (netif_running(netdev))
4910 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07004911 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07004912
4913 /* Request a slot slot reset. */
4914 return PCI_ERS_RESULT_NEED_RESET;
4915}
4916
4917/**
4918 * e1000_io_slot_reset - called after the pci bus has been reset.
4919 * @pdev: Pointer to PCI device
4920 *
4921 * Restart the card from scratch, as if from a cold-boot. Implementation
4922 * resembles the first-half of the e1000_resume routine.
4923 */
4924static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4925{
4926 struct net_device *netdev = pci_get_drvdata(pdev);
4927 struct e1000_adapter *adapter = netdev->priv;
4928
4929 if (pci_enable_device(pdev)) {
4930 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4931 return PCI_ERS_RESULT_DISCONNECT;
4932 }
4933 pci_set_master(pdev);
4934
Linas Vepstasdbf38c92006-09-27 12:54:11 -07004935 pci_enable_wake(pdev, PCI_D3hot, 0);
4936 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07004937
Auke Kok90267292006-06-08 09:30:24 -07004938 e1000_reset(adapter);
4939 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4940
4941 return PCI_ERS_RESULT_RECOVERED;
4942}
4943
4944/**
4945 * e1000_io_resume - called when traffic can start flowing again.
4946 * @pdev: Pointer to PCI device
4947 *
4948 * This callback is called when the error recovery driver tells us that
4949 * its OK to resume normal operation. Implementation resembles the
4950 * second-half of the e1000_resume routine.
4951 */
4952static void e1000_io_resume(struct pci_dev *pdev)
4953{
4954 struct net_device *netdev = pci_get_drvdata(pdev);
4955 struct e1000_adapter *adapter = netdev->priv;
4956 uint32_t manc, swsm;
4957
4958 if (netif_running(netdev)) {
4959 if (e1000_up(adapter)) {
4960 printk("e1000: can't bring device back up after reset\n");
4961 return;
4962 }
4963 }
4964
4965 netif_device_attach(netdev);
4966
4967 if (adapter->hw.mac_type >= e1000_82540 &&
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004968 adapter->hw.mac_type < e1000_82571 &&
Auke Kok90267292006-06-08 09:30:24 -07004969 adapter->hw.media_type == e1000_media_type_copper) {
4970 manc = E1000_READ_REG(&adapter->hw, MANC);
4971 manc &= ~(E1000_MANC_ARP_EN);
4972 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4973 }
4974
4975 switch (adapter->hw.mac_type) {
4976 case e1000_82573:
4977 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4978 E1000_WRITE_REG(&adapter->hw, SWSM,
4979 swsm | E1000_SWSM_DRV_LOAD);
4980 break;
4981 default:
4982 break;
4983 }
4984
4985 if (netif_running(netdev))
4986 mod_timer(&adapter->watchdog_timer, jiffies);
4987}
4988
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989/* e1000_main.c */