blob: 9d82bbb1a8264b251738b93a9e5766a9f9055763 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include "e1000.h"
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031char e1000_driver_name[] = "e1000";
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010032static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#ifndef CONFIG_E1000_NAPI
34#define DRIVERNAPI
35#else
36#define DRIVERNAPI "-NAPI"
37#endif
Auke Kokff1e55b072006-10-24 14:46:09 -070038#define DRV_VERSION "7.2.9-k4"DRIVERNAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -070039char e1000_driver_version[] = DRV_VERSION;
Auke Kok3d41e302006-04-14 19:05:31 -070040static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/* e1000_pci_tbl - PCI Device ID Table
43 *
44 * Last entry must be all 0s
45 *
46 * Macro expands to...
47 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
48 */
49static struct pci_device_id e1000_pci_tbl[] = {
50 INTEL_E1000_ETHERNET_DEVICE(0x1000),
51 INTEL_E1000_ETHERNET_DEVICE(0x1001),
52 INTEL_E1000_ETHERNET_DEVICE(0x1004),
53 INTEL_E1000_ETHERNET_DEVICE(0x1008),
54 INTEL_E1000_ETHERNET_DEVICE(0x1009),
55 INTEL_E1000_ETHERNET_DEVICE(0x100C),
56 INTEL_E1000_ETHERNET_DEVICE(0x100D),
57 INTEL_E1000_ETHERNET_DEVICE(0x100E),
58 INTEL_E1000_ETHERNET_DEVICE(0x100F),
59 INTEL_E1000_ETHERNET_DEVICE(0x1010),
60 INTEL_E1000_ETHERNET_DEVICE(0x1011),
61 INTEL_E1000_ETHERNET_DEVICE(0x1012),
62 INTEL_E1000_ETHERNET_DEVICE(0x1013),
63 INTEL_E1000_ETHERNET_DEVICE(0x1014),
64 INTEL_E1000_ETHERNET_DEVICE(0x1015),
65 INTEL_E1000_ETHERNET_DEVICE(0x1016),
66 INTEL_E1000_ETHERNET_DEVICE(0x1017),
67 INTEL_E1000_ETHERNET_DEVICE(0x1018),
68 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -070069 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 INTEL_E1000_ETHERNET_DEVICE(0x101D),
71 INTEL_E1000_ETHERNET_DEVICE(0x101E),
72 INTEL_E1000_ETHERNET_DEVICE(0x1026),
73 INTEL_E1000_ETHERNET_DEVICE(0x1027),
74 INTEL_E1000_ETHERNET_DEVICE(0x1028),
Auke Kokae2c3862006-06-27 09:08:30 -070075 INTEL_E1000_ETHERNET_DEVICE(0x1049),
76 INTEL_E1000_ETHERNET_DEVICE(0x104A),
77 INTEL_E1000_ETHERNET_DEVICE(0x104B),
78 INTEL_E1000_ETHERNET_DEVICE(0x104C),
79 INTEL_E1000_ETHERNET_DEVICE(0x104D),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040080 INTEL_E1000_ETHERNET_DEVICE(0x105E),
81 INTEL_E1000_ETHERNET_DEVICE(0x105F),
82 INTEL_E1000_ETHERNET_DEVICE(0x1060),
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 INTEL_E1000_ETHERNET_DEVICE(0x1075),
84 INTEL_E1000_ETHERNET_DEVICE(0x1076),
85 INTEL_E1000_ETHERNET_DEVICE(0x1077),
86 INTEL_E1000_ETHERNET_DEVICE(0x1078),
87 INTEL_E1000_ETHERNET_DEVICE(0x1079),
88 INTEL_E1000_ETHERNET_DEVICE(0x107A),
89 INTEL_E1000_ETHERNET_DEVICE(0x107B),
90 INTEL_E1000_ETHERNET_DEVICE(0x107C),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040091 INTEL_E1000_ETHERNET_DEVICE(0x107D),
92 INTEL_E1000_ETHERNET_DEVICE(0x107E),
93 INTEL_E1000_ETHERNET_DEVICE(0x107F),
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Malli Chilakala26483452005-04-28 19:44:46 -070095 INTEL_E1000_ETHERNET_DEVICE(0x108B),
96 INTEL_E1000_ETHERNET_DEVICE(0x108C),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -080097 INTEL_E1000_ETHERNET_DEVICE(0x1096),
98 INTEL_E1000_ETHERNET_DEVICE(0x1098),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -080099 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400100 INTEL_E1000_ETHERNET_DEVICE(0x109A),
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700101 INTEL_E1000_ETHERNET_DEVICE(0x10A4),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800102 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800103 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
Auke Kokae2c3862006-06-27 09:08:30 -0700104 INTEL_E1000_ETHERNET_DEVICE(0x10BA),
105 INTEL_E1000_ETHERNET_DEVICE(0x10BB),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 /* required last entry */
107 {0,}
108};
109
110MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
111
Nicholas Nunley35574762006-09-27 12:53:34 -0700112int e1000_up(struct e1000_adapter *adapter);
113void e1000_down(struct e1000_adapter *adapter);
114void e1000_reinit_locked(struct e1000_adapter *adapter);
115void e1000_reset(struct e1000_adapter *adapter);
116int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
117int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
118int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
119void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
120void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100121static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700122 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100123static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700124 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100125static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700126 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100127static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Nicholas Nunley35574762006-09-27 12:53:34 -0700128 struct e1000_rx_ring *rx_ring);
129void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131static int e1000_init_module(void);
132static void e1000_exit_module(void);
133static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
134static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400135static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136static int e1000_sw_init(struct e1000_adapter *adapter);
137static int e1000_open(struct net_device *netdev);
138static int e1000_close(struct net_device *netdev);
139static void e1000_configure_tx(struct e1000_adapter *adapter);
140static void e1000_configure_rx(struct e1000_adapter *adapter);
141static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400142static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
143static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
144static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
145 struct e1000_tx_ring *tx_ring);
146static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static void e1000_set_multi(struct net_device *netdev);
149static void e1000_update_phy_info(unsigned long data);
150static void e1000_watchdog(unsigned long data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151static void e1000_82547_tx_fifo_stall(unsigned long data);
152static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
153static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
154static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
155static int e1000_set_mac(struct net_device *netdev, void *p);
David Howells7d12e782006-10-05 14:55:46 +0100156static irqreturn_t e1000_intr(int irq, void *data);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400157static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
158 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400160static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400162 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700164static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400165 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700166 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400168static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
169 struct e1000_rx_ring *rx_ring);
170static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
171 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400173static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800174 struct e1000_rx_ring *rx_ring,
175 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400176static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800177 struct e1000_rx_ring *rx_ring,
178 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
180static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
181 int cmd);
Nicholas Nunley35574762006-09-27 12:53:34 -0700182void e1000_set_ethtool_ops(struct net_device *netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
184static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
185static void e1000_tx_timeout(struct net_device *dev);
Jeff Kirsher87041632006-03-02 18:21:24 -0800186static void e1000_reset_task(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700188static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
189 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
192static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
193static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
194static void e1000_restore_vlan(struct e1000_adapter *adapter);
195
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700196static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Auke Kok6fdfef12006-06-27 09:06:36 -0700197#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198static int e1000_resume(struct pci_dev *pdev);
199#endif
Auke Kokc653e632006-05-23 13:35:57 -0700200static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202#ifdef CONFIG_NET_POLL_CONTROLLER
203/* for netdump / net console */
204static void e1000_netpoll (struct net_device *netdev);
205#endif
206
Nicholas Nunley35574762006-09-27 12:53:34 -0700207extern void e1000_check_options(struct e1000_adapter *adapter);
208
Auke Kok90267292006-06-08 09:30:24 -0700209static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
210 pci_channel_state_t state);
211static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
212static void e1000_io_resume(struct pci_dev *pdev);
213
214static struct pci_error_handlers e1000_err_handler = {
215 .error_detected = e1000_io_error_detected,
216 .slot_reset = e1000_io_slot_reset,
217 .resume = e1000_io_resume,
218};
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220static struct pci_driver e1000_driver = {
221 .name = e1000_driver_name,
222 .id_table = e1000_pci_tbl,
223 .probe = e1000_probe,
224 .remove = __devexit_p(e1000_remove),
Auke Kokc4e24f02006-09-27 12:53:19 -0700225#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 /* Power Managment Hooks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 .suspend = e1000_suspend,
Auke Kokc653e632006-05-23 13:35:57 -0700228 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#endif
Auke Kok90267292006-06-08 09:30:24 -0700230 .shutdown = e1000_shutdown,
231 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
233
234MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
235MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
236MODULE_LICENSE("GPL");
237MODULE_VERSION(DRV_VERSION);
238
239static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
240module_param(debug, int, 0);
241MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
242
243/**
244 * e1000_init_module - Driver Registration Routine
245 *
246 * e1000_init_module is the first routine called when the driver is
247 * loaded. All it does is register with the PCI subsystem.
248 **/
249
250static int __init
251e1000_init_module(void)
252{
253 int ret;
254 printk(KERN_INFO "%s - version %s\n",
255 e1000_driver_string, e1000_driver_version);
256
257 printk(KERN_INFO "%s\n", e1000_copyright);
258
Jeff Garzik29917622006-08-19 17:48:59 -0400259 ret = pci_register_driver(&e1000_driver);
Tony Luck8b378de2005-07-28 01:07:38 -0700260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return ret;
262}
263
264module_init(e1000_init_module);
265
266/**
267 * e1000_exit_module - Driver Exit Cleanup Routine
268 *
269 * e1000_exit_module is called just before the driver is removed
270 * from memory.
271 **/
272
273static void __exit
274e1000_exit_module(void)
275{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 pci_unregister_driver(&e1000_driver);
277}
278
279module_exit(e1000_exit_module);
280
Auke Kok2db10a02006-06-27 09:06:28 -0700281static int e1000_request_irq(struct e1000_adapter *adapter)
282{
283 struct net_device *netdev = adapter->netdev;
284 int flags, err = 0;
285
Jeff Garzikc0bc8722006-07-05 14:32:39 -0400286 flags = IRQF_SHARED;
Auke Kok2db10a02006-06-27 09:06:28 -0700287#ifdef CONFIG_PCI_MSI
288 if (adapter->hw.mac_type > e1000_82547_rev_2) {
289 adapter->have_msi = TRUE;
290 if ((err = pci_enable_msi(adapter->pdev))) {
291 DPRINTK(PROBE, ERR,
292 "Unable to allocate MSI interrupt Error: %d\n", err);
293 adapter->have_msi = FALSE;
294 }
295 }
296 if (adapter->have_msi)
Andrew Morton61ef5c02006-07-06 23:58:19 -0700297 flags &= ~IRQF_SHARED;
Auke Kok2db10a02006-06-27 09:06:28 -0700298#endif
299 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
300 netdev->name, netdev)))
301 DPRINTK(PROBE, ERR,
302 "Unable to allocate interrupt Error: %d\n", err);
303
304 return err;
305}
306
307static void e1000_free_irq(struct e1000_adapter *adapter)
308{
309 struct net_device *netdev = adapter->netdev;
310
311 free_irq(adapter->pdev->irq, netdev);
312
313#ifdef CONFIG_PCI_MSI
314 if (adapter->have_msi)
315 pci_disable_msi(adapter->pdev);
316#endif
317}
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319/**
320 * e1000_irq_disable - Mask off interrupt generation on the NIC
321 * @adapter: board private structure
322 **/
323
Auke Koke619d522006-04-14 19:04:52 -0700324static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325e1000_irq_disable(struct e1000_adapter *adapter)
326{
327 atomic_inc(&adapter->irq_sem);
328 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
329 E1000_WRITE_FLUSH(&adapter->hw);
330 synchronize_irq(adapter->pdev->irq);
331}
332
333/**
334 * e1000_irq_enable - Enable default interrupt generation settings
335 * @adapter: board private structure
336 **/
337
Auke Koke619d522006-04-14 19:04:52 -0700338static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339e1000_irq_enable(struct e1000_adapter *adapter)
340{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800341 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
343 E1000_WRITE_FLUSH(&adapter->hw);
344 }
345}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100346
347static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700348e1000_update_mng_vlan(struct e1000_adapter *adapter)
349{
350 struct net_device *netdev = adapter->netdev;
351 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
352 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800353 if (adapter->vlgrp) {
354 if (!adapter->vlgrp->vlan_devices[vid]) {
355 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700356 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
357 e1000_vlan_rx_add_vid(netdev, vid);
358 adapter->mng_vlan_id = vid;
359 } else
360 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800361
362 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
363 (vid != old_vid) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700364 !adapter->vlgrp->vlan_devices[old_vid])
365 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800366 } else
367 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700368 }
369}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800370
371/**
372 * e1000_release_hw_control - release control of the h/w to f/w
373 * @adapter: address of board private structure
374 *
375 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
376 * For ASF and Pass Through versions of f/w this means that the
377 * driver is no longer loaded. For AMT version (only with 82573) i
Auke Kok90fb5132006-11-01 08:47:30 -0800378 * of the f/w this means that the network i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700379 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800380 **/
381
Auke Koke619d522006-04-14 19:04:52 -0700382static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800383e1000_release_hw_control(struct e1000_adapter *adapter)
384{
385 uint32_t ctrl_ext;
386 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700387 uint32_t extcnf;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800388
389 /* Let firmware taken over control of h/w */
390 switch (adapter->hw.mac_type) {
391 case e1000_82571:
392 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700393 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800394 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
395 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
396 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
397 break;
398 case e1000_82573:
399 swsm = E1000_READ_REG(&adapter->hw, SWSM);
400 E1000_WRITE_REG(&adapter->hw, SWSM,
401 swsm & ~E1000_SWSM_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700402 case e1000_ich8lan:
403 extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
404 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
405 extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
406 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800407 default:
408 break;
409 }
410}
411
412/**
413 * e1000_get_hw_control - get control of the h/w from f/w
414 * @adapter: address of board private structure
415 *
416 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700417 * For ASF and Pass Through versions of f/w this means that
418 * the driver is loaded. For AMT version (only with 82573)
Auke Kok90fb5132006-11-01 08:47:30 -0800419 * of the f/w this means that the network i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700420 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800421 **/
422
Auke Koke619d522006-04-14 19:04:52 -0700423static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800424e1000_get_hw_control(struct e1000_adapter *adapter)
425{
426 uint32_t ctrl_ext;
427 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700428 uint32_t extcnf;
Auke Kok90fb5132006-11-01 08:47:30 -0800429
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800430 /* Let firmware know the driver has taken over */
431 switch (adapter->hw.mac_type) {
432 case e1000_82571:
433 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700434 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800435 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
436 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
437 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
438 break;
439 case e1000_82573:
440 swsm = E1000_READ_REG(&adapter->hw, SWSM);
441 E1000_WRITE_REG(&adapter->hw, SWSM,
442 swsm | E1000_SWSM_DRV_LOAD);
443 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700444 case e1000_ich8lan:
445 extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
446 E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
447 extcnf | E1000_EXTCNF_CTRL_SWFLAG);
448 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800449 default:
450 break;
451 }
452}
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454int
455e1000_up(struct e1000_adapter *adapter)
456{
457 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700458 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 /* hardware has been reset, we need to reload some things */
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 e1000_set_multi(netdev);
463
464 e1000_restore_vlan(adapter);
465
466 e1000_configure_tx(adapter);
467 e1000_setup_rctl(adapter);
468 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800469 /* call E1000_DESC_UNUSED which always leaves
470 * at least 1 descriptor unused to make sure
471 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800472 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800473 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800474 adapter->alloc_rx_buf(adapter, ring,
475 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800478 adapter->tx_queue_len = netdev->tx_queue_len;
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#ifdef CONFIG_E1000_NAPI
481 netif_poll_enable(netdev);
482#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700483 e1000_irq_enable(adapter);
484
Auke Kok1314bbf2006-09-27 12:54:02 -0700485 clear_bit(__E1000_DOWN, &adapter->flags);
486
487 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return 0;
489}
490
Auke Kok79f05bf2006-06-27 09:06:32 -0700491/**
492 * e1000_power_up_phy - restore link in case the phy was powered down
493 * @adapter: address of board private structure
494 *
495 * The phy may be powered down to save power and turn off link when the
496 * driver is unloaded and wake on lan is not enabled (among others)
497 * *** this routine MUST be followed by a call to e1000_reset ***
498 *
499 **/
500
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700501void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700502{
503 uint16_t mii_reg = 0;
504
505 /* Just clear the power down bit to wake the phy back up */
506 if (adapter->hw.media_type == e1000_media_type_copper) {
507 /* according to the manual, the phy will retain its
508 * settings across a power-down/up cycle */
509 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
510 mii_reg &= ~MII_CR_POWER_DOWN;
511 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
512 }
513}
514
515static void e1000_power_down_phy(struct e1000_adapter *adapter)
516{
Bruce Allan61c25052006-09-27 12:53:54 -0700517 /* Power down the PHY so no link is implied when interface is down *
518 * The PHY cannot be powered down if any of the following is TRUE *
Auke Kok79f05bf2006-06-27 09:06:32 -0700519 * (a) WoL is enabled
520 * (b) AMT is active
521 * (c) SoL/IDER session is active */
522 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Bruce Allan61c25052006-09-27 12:53:54 -0700523 adapter->hw.media_type == e1000_media_type_copper) {
Auke Kok79f05bf2006-06-27 09:06:32 -0700524 uint16_t mii_reg = 0;
Bruce Allan61c25052006-09-27 12:53:54 -0700525
526 switch (adapter->hw.mac_type) {
527 case e1000_82540:
528 case e1000_82545:
529 case e1000_82545_rev_3:
530 case e1000_82546:
531 case e1000_82546_rev_3:
532 case e1000_82541:
533 case e1000_82541_rev_2:
534 case e1000_82547:
535 case e1000_82547_rev_2:
536 if (E1000_READ_REG(&adapter->hw, MANC) &
537 E1000_MANC_SMBUS_EN)
538 goto out;
539 break;
540 case e1000_82571:
541 case e1000_82572:
542 case e1000_82573:
543 case e1000_80003es2lan:
544 case e1000_ich8lan:
545 if (e1000_check_mng_mode(&adapter->hw) ||
546 e1000_check_phy_reset_block(&adapter->hw))
547 goto out;
548 break;
549 default:
550 goto out;
551 }
Auke Kok79f05bf2006-06-27 09:06:32 -0700552 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
553 mii_reg |= MII_CR_POWER_DOWN;
554 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
555 mdelay(1);
556 }
Bruce Allan61c25052006-09-27 12:53:54 -0700557out:
558 return;
Auke Kok79f05bf2006-06-27 09:06:32 -0700559}
560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561void
562e1000_down(struct e1000_adapter *adapter)
563{
564 struct net_device *netdev = adapter->netdev;
565
Auke Kok1314bbf2006-09-27 12:54:02 -0700566 /* signal that we're down so the interrupt handler does not
567 * reschedule our watchdog timer */
568 set_bit(__E1000_DOWN, &adapter->flags);
569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 del_timer_sync(&adapter->tx_fifo_stall_timer);
573 del_timer_sync(&adapter->watchdog_timer);
574 del_timer_sync(&adapter->phy_info_timer);
575
576#ifdef CONFIG_E1000_NAPI
577 netif_poll_disable(netdev);
578#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800579 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 adapter->link_speed = 0;
581 adapter->link_duplex = 0;
582 netif_carrier_off(netdev);
583 netif_stop_queue(netdev);
584
585 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400586 e1000_clean_all_tx_rings(adapter);
587 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590void
Auke Kok2db10a02006-06-27 09:06:28 -0700591e1000_reinit_locked(struct e1000_adapter *adapter)
592{
593 WARN_ON(in_interrupt());
594 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
595 msleep(1);
596 e1000_down(adapter);
597 e1000_up(adapter);
598 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
601void
602e1000_reset(struct e1000_adapter *adapter)
603{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700604 uint32_t pba, manc;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700605 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 /* Repartition Pba for greater than 9k mtu
608 * To take effect CTRL.RST is required.
609 */
610
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700611 switch (adapter->hw.mac_type) {
612 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700613 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700614 pba = E1000_PBA_30K;
615 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400616 case e1000_82571:
617 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800618 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400619 pba = E1000_PBA_38K;
620 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700621 case e1000_82573:
622 pba = E1000_PBA_12K;
623 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700624 case e1000_ich8lan:
625 pba = E1000_PBA_8K;
626 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700627 default:
628 pba = E1000_PBA_48K;
629 break;
630 }
631
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800632 if ((adapter->hw.mac_type != e1000_82573) &&
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800633 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700634 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700635
636
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800637 if (adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 adapter->tx_fifo_head = 0;
639 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
640 adapter->tx_fifo_size =
641 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
642 atomic_set(&adapter->tx_fifo_stall, 0);
643 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 E1000_WRITE_REG(&adapter->hw, PBA, pba);
646
647 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800648 /* Set the FC high water mark to 90% of the FIFO size.
649 * Required to clear last 3 LSB */
650 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700651 /* We can't use 90% on small FIFOs because the remainder
652 * would be less than 1 full frame. In this case, we size
653 * it to allow at least a full frame above the high water
654 * mark. */
655 if (pba < E1000_PBA_16K)
656 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800657
658 adapter->hw.fc_high_water = fc_high_water_mark;
659 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800660 if (adapter->hw.mac_type == e1000_80003es2lan)
661 adapter->hw.fc_pause_time = 0xFFFF;
662 else
663 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 adapter->hw.fc_send_xon = 1;
665 adapter->hw.fc = adapter->hw.original_fc;
666
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700667 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800669 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700671
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800672 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700674 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
676 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
677
678 e1000_reset_adaptive(&adapter->hw);
679 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700680
681 if (!adapter->smart_power_down &&
682 (adapter->hw.mac_type == e1000_82571 ||
683 adapter->hw.mac_type == e1000_82572)) {
684 uint16_t phy_data = 0;
685 /* speed up time to link by disabling smart power down, ignore
686 * the return value of this function because there is nothing
687 * different we would do if it failed */
688 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
689 &phy_data);
690 phy_data &= ~IGP02E1000_PM_SPD;
691 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
692 phy_data);
693 }
694
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -0700695 if ((adapter->en_mng_pt) &&
696 (adapter->hw.mac_type >= e1000_82540) &&
697 (adapter->hw.mac_type < e1000_82571) &&
698 (adapter->hw.media_type == e1000_media_type_copper)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700699 manc = E1000_READ_REG(&adapter->hw, MANC);
700 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
701 E1000_WRITE_REG(&adapter->hw, MANC, manc);
702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
705/**
706 * e1000_probe - Device Initialization Routine
707 * @pdev: PCI device information struct
708 * @ent: entry in e1000_pci_tbl
709 *
710 * Returns 0 on success, negative on failure
711 *
712 * e1000_probe initializes an adapter identified by a pci_dev structure.
713 * The OS initialization, configuring of the adapter private structure,
714 * and a hardware reset occur.
715 **/
716
717static int __devinit
718e1000_probe(struct pci_dev *pdev,
719 const struct pci_device_id *ent)
720{
721 struct net_device *netdev;
722 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700723 unsigned long mmio_start, mmio_len;
Auke Kokcd94dd02006-06-27 09:08:22 -0700724 unsigned long flash_start, flash_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 static int cards_found = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700727 static int global_quad_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700728 int i, err, pci_using_dac;
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700729 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800731 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 return err;
733
Auke Kokcd94dd02006-06-27 09:08:22 -0700734 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
735 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 pci_using_dac = 1;
737 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700738 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
739 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 E1000_ERR("No usable DMA configuration, aborting\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700741 goto err_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
743 pci_using_dac = 0;
744 }
745
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800746 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700747 goto err_pci_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 pci_set_master(pdev);
750
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700751 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700753 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 goto err_alloc_etherdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756 SET_MODULE_OWNER(netdev);
757 SET_NETDEV_DEV(netdev, &pdev->dev);
758
759 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700760 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 adapter->netdev = netdev;
762 adapter->pdev = pdev;
763 adapter->hw.back = adapter;
764 adapter->msg_enable = (1 << debug) - 1;
765
766 mmio_start = pci_resource_start(pdev, BAR_0);
767 mmio_len = pci_resource_len(pdev, BAR_0);
768
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700769 err = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700771 if (!adapter->hw.hw_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 goto err_ioremap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800774 for (i = BAR_1; i <= BAR_5; i++) {
775 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800777 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 adapter->hw.io_base = pci_resource_start(pdev, i);
779 break;
780 }
781 }
782
783 netdev->open = &e1000_open;
784 netdev->stop = &e1000_close;
785 netdev->hard_start_xmit = &e1000_xmit_frame;
786 netdev->get_stats = &e1000_get_stats;
787 netdev->set_multicast_list = &e1000_set_multi;
788 netdev->set_mac_address = &e1000_set_mac;
789 netdev->change_mtu = &e1000_change_mtu;
790 netdev->do_ioctl = &e1000_ioctl;
791 e1000_set_ethtool_ops(netdev);
792 netdev->tx_timeout = &e1000_tx_timeout;
793 netdev->watchdog_timeo = 5 * HZ;
794#ifdef CONFIG_E1000_NAPI
795 netdev->poll = &e1000_clean;
796 netdev->weight = 64;
797#endif
798 netdev->vlan_rx_register = e1000_vlan_rx_register;
799 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
800 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
801#ifdef CONFIG_NET_POLL_CONTROLLER
802 netdev->poll_controller = e1000_netpoll;
803#endif
Auke Kok0eb5a342006-09-27 12:53:17 -0700804 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 netdev->mem_start = mmio_start;
807 netdev->mem_end = mmio_start + mmio_len;
808 netdev->base_addr = adapter->hw.io_base;
809
810 adapter->bd_number = cards_found;
811
812 /* setup the private structure */
813
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800814 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 goto err_sw_init;
816
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700817 err = -EIO;
Auke Kokcd94dd02006-06-27 09:08:22 -0700818 /* Flash BAR mapping must happen after e1000_sw_init
819 * because it depends on mac_type */
820 if ((adapter->hw.mac_type == e1000_ich8lan) &&
821 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
822 flash_start = pci_resource_start(pdev, 1);
823 flash_len = pci_resource_len(pdev, 1);
824 adapter->hw.flash_address = ioremap(flash_start, flash_len);
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700825 if (!adapter->hw.flash_address)
Auke Kokcd94dd02006-06-27 09:08:22 -0700826 goto err_flashmap;
Auke Kokcd94dd02006-06-27 09:08:22 -0700827 }
828
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700829 if (e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700830 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
831
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800832 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 netdev->features = NETIF_F_SG |
834 NETIF_F_HW_CSUM |
835 NETIF_F_HW_VLAN_TX |
836 NETIF_F_HW_VLAN_RX |
837 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -0700838 if (adapter->hw.mac_type == e1000_ich8lan)
839 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 }
841
842#ifdef NETIF_F_TSO
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800843 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 (adapter->hw.mac_type != e1000_82547))
845 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700846
Auke Kok87ca4e52006-11-01 08:47:36 -0800847#ifdef NETIF_F_TSO6
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800848 if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok87ca4e52006-11-01 08:47:36 -0800849 netdev->features |= NETIF_F_TSO6;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700850#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800852 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 netdev->features |= NETIF_F_HIGHDMA;
854
Auke Kok76c224b2006-05-23 13:36:06 -0700855 netdev->features |= NETIF_F_LLTX;
856
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700857 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
858
Auke Kokcd94dd02006-06-27 09:08:22 -0700859 /* initialize eeprom parameters */
860
861 if (e1000_init_eeprom_params(&adapter->hw)) {
862 E1000_ERR("EEPROM initialization failed\n");
Vasily Averin6dd62ab2006-08-28 14:56:22 -0700863 goto err_eeprom;
Auke Kokcd94dd02006-06-27 09:08:22 -0700864 }
865
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800866 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 e1000_reset_hw(&adapter->hw);
870
871 /* make sure the EEPROM is good */
872
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800873 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 goto err_eeprom;
876 }
877
878 /* copy the MAC address out of the EEPROM */
879
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800880 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
882 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400883 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800885 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 goto err_eeprom;
888 }
889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 e1000_get_bus_info(&adapter->hw);
891
892 init_timer(&adapter->tx_fifo_stall_timer);
893 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
894 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
895
896 init_timer(&adapter->watchdog_timer);
897 adapter->watchdog_timer.function = &e1000_watchdog;
898 adapter->watchdog_timer.data = (unsigned long) adapter;
899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 init_timer(&adapter->phy_info_timer);
901 adapter->phy_info_timer.function = &e1000_update_phy_info;
902 adapter->phy_info_timer.data = (unsigned long) adapter;
903
Jeff Kirsher87041632006-03-02 18:21:24 -0800904 INIT_WORK(&adapter->reset_task,
905 (void (*)(void *))e1000_reset_task, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 e1000_check_options(adapter);
908
909 /* Initial Wake on LAN setting
910 * If APM wake is enabled in the EEPROM,
911 * enable the ACPI Magic Packet filter
912 */
913
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800914 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 case e1000_82542_rev2_0:
916 case e1000_82542_rev2_1:
917 case e1000_82543:
918 break;
919 case e1000_82544:
920 e1000_read_eeprom(&adapter->hw,
921 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
922 eeprom_apme_mask = E1000_EEPROM_82544_APM;
923 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700924 case e1000_ich8lan:
925 e1000_read_eeprom(&adapter->hw,
926 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
927 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
928 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 case e1000_82546:
930 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500931 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800932 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800933 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 e1000_read_eeprom(&adapter->hw,
935 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
936 break;
937 }
938 /* Fall Through */
939 default:
940 e1000_read_eeprom(&adapter->hw,
941 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
942 break;
943 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800944 if (eeprom_data & eeprom_apme_mask)
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700945 adapter->eeprom_wol |= E1000_WUFC_MAG;
946
947 /* now that we have the eeprom settings, apply the special cases
948 * where the eeprom may be wrong or the board simply won't support
949 * wake on lan on a particular port */
950 switch (pdev->device) {
951 case E1000_DEV_ID_82546GB_PCIE:
952 adapter->eeprom_wol = 0;
953 break;
954 case E1000_DEV_ID_82546EB_FIBER:
955 case E1000_DEV_ID_82546GB_FIBER:
956 case E1000_DEV_ID_82571EB_FIBER:
957 /* Wake events only supported on port A for dual fiber
958 * regardless of eeprom setting */
959 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
960 adapter->eeprom_wol = 0;
961 break;
962 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg5881cde2006-08-31 14:27:47 -0700963 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -0700964 /* if quad port adapter, disable WoL on all but port A */
965 if (global_quad_port_a != 0)
966 adapter->eeprom_wol = 0;
967 else
968 adapter->quad_port_a = 1;
969 /* Reset for multiple quad port adapters */
970 if (++global_quad_port_a == 4)
971 global_quad_port_a = 0;
972 break;
973 }
974
975 /* initialize the wol settings based on the eeprom settings */
976 adapter->wol = adapter->eeprom_wol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -0800978 /* print bus type/speed/width info */
979 {
980 struct e1000_hw *hw = &adapter->hw;
981 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
982 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
983 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
984 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
985 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
986 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
987 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
988 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
989 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
990 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
991 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
992 "32-bit"));
993 }
994
995 for (i = 0; i < 6; i++)
996 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 /* reset the hardware with the new settings */
999 e1000_reset(adapter);
1000
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001001 /* If the controller is 82573 and f/w is AMT, do not set
1002 * DRV_LOAD until the interface is up. For all other cases,
1003 * let the f/w know that the h/w is now under the control
1004 * of the driver. */
1005 if (adapter->hw.mac_type != e1000_82573 ||
1006 !e1000_check_mng_mode(&adapter->hw))
1007 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001008
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 strcpy(netdev->name, "eth%d");
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001010 if ((err = register_netdev(netdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 goto err_register;
1012
Auke Kok1314bbf2006-09-27 12:54:02 -07001013 /* tell the stack to leave us alone until e1000_open() is called */
1014 netif_carrier_off(netdev);
1015 netif_stop_queue(netdev);
1016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
1018
1019 cards_found++;
1020 return 0;
1021
1022err_register:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001023 e1000_release_hw_control(adapter);
1024err_eeprom:
1025 if (!e1000_check_phy_reset_block(&adapter->hw))
1026 e1000_phy_hw_reset(&adapter->hw);
1027
Auke Kokcd94dd02006-06-27 09:08:22 -07001028 if (adapter->hw.flash_address)
1029 iounmap(adapter->hw.flash_address);
1030err_flashmap:
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001031#ifdef CONFIG_E1000_NAPI
1032 for (i = 0; i < adapter->num_rx_queues; i++)
1033 dev_put(&adapter->polling_netdev[i]);
1034#endif
1035
1036 kfree(adapter->tx_ring);
1037 kfree(adapter->rx_ring);
1038#ifdef CONFIG_E1000_NAPI
1039 kfree(adapter->polling_netdev);
1040#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041err_sw_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 iounmap(adapter->hw.hw_addr);
1043err_ioremap:
1044 free_netdev(netdev);
1045err_alloc_etherdev:
1046 pci_release_regions(pdev);
Vasily Averin6dd62ab2006-08-28 14:56:22 -07001047err_pci_reg:
1048err_dma:
1049 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 return err;
1051}
1052
1053/**
1054 * e1000_remove - Device Removal Routine
1055 * @pdev: PCI device information struct
1056 *
1057 * e1000_remove is called by the PCI subsystem to alert the driver
1058 * that it should release a PCI device. The could be caused by a
1059 * Hot-Plug event, or because the driver is going to be removed from
1060 * memory.
1061 **/
1062
1063static void __devexit
1064e1000_remove(struct pci_dev *pdev)
1065{
1066 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07001067 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001068 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001069#ifdef CONFIG_E1000_NAPI
1070 int i;
1071#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04001073 flush_scheduled_work();
1074
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07001075 if (adapter->hw.mac_type >= e1000_82540 &&
1076 adapter->hw.mac_type < e1000_82571 &&
1077 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001079 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 manc |= E1000_MANC_ARP_EN;
1081 E1000_WRITE_REG(&adapter->hw, MANC, manc);
1082 }
1083 }
1084
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001085 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1086 * would have already happened in close and is redundant. */
1087 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001090#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001091 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001092 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001093#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001095 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001096 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001098 kfree(adapter->tx_ring);
1099 kfree(adapter->rx_ring);
1100#ifdef CONFIG_E1000_NAPI
1101 kfree(adapter->polling_netdev);
1102#endif
1103
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001105 if (adapter->hw.flash_address)
1106 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 pci_release_regions(pdev);
1108
1109 free_netdev(netdev);
1110
1111 pci_disable_device(pdev);
1112}
1113
1114/**
1115 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1116 * @adapter: board private structure to initialize
1117 *
1118 * e1000_sw_init initializes the Adapter private data structure.
1119 * Fields are initialized based on PCI device information and
1120 * OS network device settings (MTU size).
1121 **/
1122
1123static int __devinit
1124e1000_sw_init(struct e1000_adapter *adapter)
1125{
1126 struct e1000_hw *hw = &adapter->hw;
1127 struct net_device *netdev = adapter->netdev;
1128 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001129#ifdef CONFIG_E1000_NAPI
1130 int i;
1131#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
1133 /* PCI config space info */
1134
1135 hw->vendor_id = pdev->vendor;
1136 hw->device_id = pdev->device;
1137 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1138 hw->subsystem_id = pdev->subsystem_device;
1139
1140 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1141
1142 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1143
Auke Kokeb0f8052006-07-14 16:14:48 -07001144 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001145 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 hw->max_frame_size = netdev->mtu +
1147 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1148 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1149
1150 /* identify the MAC */
1151
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001152 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1154 return -EIO;
1155 }
1156
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001157 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 default:
1159 break;
1160 case e1000_82541:
1161 case e1000_82547:
1162 case e1000_82541_rev_2:
1163 case e1000_82547_rev_2:
1164 hw->phy_init_script = 1;
1165 break;
1166 }
1167
1168 e1000_set_media_type(hw);
1169
1170 hw->wait_autoneg_complete = FALSE;
1171 hw->tbi_compatibility_en = TRUE;
1172 hw->adaptive_ifs = TRUE;
1173
1174 /* Copper options */
1175
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001176 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 hw->mdix = AUTO_ALL_MODES;
1178 hw->disable_polarity_correction = FALSE;
1179 hw->master_slave = E1000_MASTER_SLAVE;
1180 }
1181
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001182 adapter->num_tx_queues = 1;
1183 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001184
1185 if (e1000_alloc_queues(adapter)) {
1186 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1187 return -ENOMEM;
1188 }
1189
1190#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001191 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001192 adapter->polling_netdev[i].priv = adapter;
1193 adapter->polling_netdev[i].poll = &e1000_clean;
1194 adapter->polling_netdev[i].weight = 64;
1195 dev_hold(&adapter->polling_netdev[i]);
1196 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1197 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001198 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001199#endif
1200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 atomic_set(&adapter->irq_sem, 1);
1202 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Auke Kok1314bbf2006-09-27 12:54:02 -07001204 set_bit(__E1000_DOWN, &adapter->flags);
1205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 return 0;
1207}
1208
1209/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001210 * e1000_alloc_queues - Allocate memory for all rings
1211 * @adapter: board private structure to initialize
1212 *
1213 * We allocate one ring per queue at run-time since we don't know the
1214 * number of queues at compile-time. The polling_netdev array is
1215 * intended for Multiqueue, but should work fine with a single queue.
1216 **/
1217
1218static int __devinit
1219e1000_alloc_queues(struct e1000_adapter *adapter)
1220{
1221 int size;
1222
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001223 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001224 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1225 if (!adapter->tx_ring)
1226 return -ENOMEM;
1227 memset(adapter->tx_ring, 0, size);
1228
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001229 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001230 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1231 if (!adapter->rx_ring) {
1232 kfree(adapter->tx_ring);
1233 return -ENOMEM;
1234 }
1235 memset(adapter->rx_ring, 0, size);
1236
1237#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001238 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001239 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1240 if (!adapter->polling_netdev) {
1241 kfree(adapter->tx_ring);
1242 kfree(adapter->rx_ring);
1243 return -ENOMEM;
1244 }
1245 memset(adapter->polling_netdev, 0, size);
1246#endif
1247
1248 return E1000_SUCCESS;
1249}
1250
1251/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 * e1000_open - Called when a network interface is made active
1253 * @netdev: network interface device structure
1254 *
1255 * Returns 0 on success, negative value on failure
1256 *
1257 * The open entry point is called when a network interface is made
1258 * active by the system (IFF_UP). At this point all resources needed
1259 * for transmit and receive operations are allocated, the interrupt
1260 * handler is registered with the OS, the watchdog timer is started,
1261 * and the stack is notified that the interface is ready.
1262 **/
1263
1264static int
1265e1000_open(struct net_device *netdev)
1266{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001267 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 int err;
1269
Auke Kok2db10a02006-06-27 09:06:28 -07001270 /* disallow open during test */
Auke Kok1314bbf2006-09-27 12:54:02 -07001271 if (test_bit(__E1000_TESTING, &adapter->flags))
Auke Kok2db10a02006-06-27 09:06:28 -07001272 return -EBUSY;
1273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 /* allocate transmit descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001275 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 goto err_setup_tx;
1277
1278 /* allocate receive descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001279 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 goto err_setup_rx;
1281
Auke Kok2db10a02006-06-27 09:06:28 -07001282 err = e1000_request_irq(adapter);
1283 if (err)
Vasily Averin401a5522006-08-28 14:56:19 -07001284 goto err_req_irq;
Auke Kok2db10a02006-06-27 09:06:28 -07001285
Auke Kok79f05bf2006-06-27 09:06:32 -07001286 e1000_power_up_phy(adapter);
1287
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001288 if ((err = e1000_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001290 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001291 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001292 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1293 e1000_update_mng_vlan(adapter);
1294 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001296 /* If AMT is enabled, let the firmware know that the network
1297 * interface is now open */
1298 if (adapter->hw.mac_type == e1000_82573 &&
1299 e1000_check_mng_mode(&adapter->hw))
1300 e1000_get_hw_control(adapter);
1301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 return E1000_SUCCESS;
1303
1304err_up:
Vasily Averin401a5522006-08-28 14:56:19 -07001305 e1000_power_down_phy(adapter);
1306 e1000_free_irq(adapter);
1307err_req_irq:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001308 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001310 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311err_setup_tx:
1312 e1000_reset(adapter);
1313
1314 return err;
1315}
1316
1317/**
1318 * e1000_close - Disables a network interface
1319 * @netdev: network interface device structure
1320 *
1321 * Returns 0, this is not allowed to fail
1322 *
1323 * The close entry point is called when an interface is de-activated
1324 * by the OS. The hardware is still under the drivers control, but
1325 * needs to be disabled. A global MAC reset is issued to stop the
1326 * hardware, and all transmit and receive resources are freed.
1327 **/
1328
1329static int
1330e1000_close(struct net_device *netdev)
1331{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001332 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Auke Kok2db10a02006-06-27 09:06:28 -07001334 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001336 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001337 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001339 e1000_free_all_tx_resources(adapter);
1340 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Bruce Allan46665602006-09-27 12:54:08 -07001342 /* kill manageability vlan ID if supported, but not if a vlan with
1343 * the same ID is registered on the host OS (let 8021q kill it) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001344 if ((adapter->hw.mng_cookie.status &
Bruce Allan46665602006-09-27 12:54:08 -07001345 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1346 !(adapter->vlgrp &&
1347 adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001348 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1349 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001350
1351 /* If AMT is enabled, let the firmware know that the network
1352 * interface is now closed */
1353 if (adapter->hw.mac_type == e1000_82573 &&
1354 e1000_check_mng_mode(&adapter->hw))
1355 e1000_release_hw_control(adapter);
1356
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 return 0;
1358}
1359
1360/**
1361 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1362 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001363 * @start: address of beginning of memory
1364 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 **/
Auke Koke619d522006-04-14 19:04:52 -07001366static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367e1000_check_64k_bound(struct e1000_adapter *adapter,
1368 void *start, unsigned long len)
1369{
1370 unsigned long begin = (unsigned long) start;
1371 unsigned long end = begin + len;
1372
Malli Chilakala26483452005-04-28 19:44:46 -07001373 /* First rev 82545 and 82546 need to not allow any memory
1374 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001376 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1378 }
1379
1380 return TRUE;
1381}
1382
1383/**
1384 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1385 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001386 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 *
1388 * Return 0 on success, negative on failure
1389 **/
1390
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001391static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001392e1000_setup_tx_resources(struct e1000_adapter *adapter,
1393 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 struct pci_dev *pdev = adapter->pdev;
1396 int size;
1397
1398 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001399 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001400 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001401 DPRINTK(PROBE, ERR,
1402 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 return -ENOMEM;
1404 }
1405 memset(txdr->buffer_info, 0, size);
1406
1407 /* round up to nearest 4K */
1408
1409 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1410 E1000_ROUNDUP(txdr->size, 4096);
1411
1412 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001413 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001416 DPRINTK(PROBE, ERR,
1417 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 return -ENOMEM;
1419 }
1420
Malli Chilakala26483452005-04-28 19:44:46 -07001421 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1423 void *olddesc = txdr->desc;
1424 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001425 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1426 "at %p\n", txdr->size, txdr->desc);
1427 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001429 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001430 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1432 goto setup_tx_desc_die;
1433 }
1434
1435 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1436 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001437 pci_free_consistent(pdev, txdr->size, txdr->desc,
1438 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1440 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001441 "Unable to allocate aligned memory "
1442 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 vfree(txdr->buffer_info);
1444 return -ENOMEM;
1445 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001446 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1448 }
1449 }
1450 memset(txdr->desc, 0, txdr->size);
1451
1452 txdr->next_to_use = 0;
1453 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001454 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
1456 return 0;
1457}
1458
1459/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001460 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1461 * (Descriptors) for all queues
1462 * @adapter: board private structure
1463 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001464 * Return 0 on success, negative on failure
1465 **/
1466
1467int
1468e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1469{
1470 int i, err = 0;
1471
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001472 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001473 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1474 if (err) {
1475 DPRINTK(PROBE, ERR,
1476 "Allocation for Tx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001477 for (i-- ; i >= 0; i--)
1478 e1000_free_tx_resources(adapter,
1479 &adapter->tx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001480 break;
1481 }
1482 }
1483
1484 return err;
1485}
1486
1487/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1489 * @adapter: board private structure
1490 *
1491 * Configure the Tx unit of the MAC after a reset.
1492 **/
1493
1494static void
1495e1000_configure_tx(struct e1000_adapter *adapter)
1496{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001497 uint64_t tdba;
1498 struct e1000_hw *hw = &adapter->hw;
1499 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001500 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
1502 /* Setup the HW Tx Head and Tail descriptor pointers */
1503
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001504 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001505 case 1:
1506 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001507 tdba = adapter->tx_ring[0].dma;
1508 tdlen = adapter->tx_ring[0].count *
1509 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001510 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001511 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1512 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001513 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001514 E1000_WRITE_REG(hw, TDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001515 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1516 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001517 break;
1518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 /* Set the default values for the Tx Inter Packet Gap timer */
1521
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001522 if (hw->media_type == e1000_media_type_fiber ||
1523 hw->media_type == e1000_media_type_internal_serdes)
1524 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1525 else
1526 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1527
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001528 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 case e1000_82542_rev2_0:
1530 case e1000_82542_rev2_1:
1531 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001532 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1533 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001535 case e1000_80003es2lan:
1536 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1537 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1538 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001540 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1541 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1542 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001544 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1545 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001546 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
1548 /* Set the Tx Interrupt Delay register */
1549
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001550 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1551 if (hw->mac_type >= e1000_82540)
1552 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
1554 /* Program the Transmit Control Register */
1555
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001556 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001558 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1560
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001561 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1562 tarc = E1000_READ_REG(hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08001563 /* set the speed mode bit, we'll clear it if we're not at
1564 * gigabit link later */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001565 tarc |= (1 << 21);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001566 E1000_WRITE_REG(hw, TARC0, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001567 } else if (hw->mac_type == e1000_80003es2lan) {
1568 tarc = E1000_READ_REG(hw, TARC0);
1569 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001570 E1000_WRITE_REG(hw, TARC0, tarc);
1571 tarc = E1000_READ_REG(hw, TARC1);
1572 tarc |= 1;
1573 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001574 }
1575
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001576 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
1578 /* Setup Transmit Descriptor Settings for eop descriptor */
1579 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1580 E1000_TXD_CMD_IFCS;
1581
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001582 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1584 else
1585 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1586
1587 /* Cache if we're 82544 running in PCI-X because we'll
1588 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001589 if (hw->mac_type == e1000_82544 &&
1590 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001592
1593 E1000_WRITE_REG(hw, TCTL, tctl);
1594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595}
1596
1597/**
1598 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1599 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001600 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 *
1602 * Returns 0 on success, negative on failure
1603 **/
1604
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001605static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001606e1000_setup_rx_resources(struct e1000_adapter *adapter,
1607 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001610 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001613 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001614 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001615 DPRINTK(PROBE, ERR,
1616 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 return -ENOMEM;
1618 }
1619 memset(rxdr->buffer_info, 0, size);
1620
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001621 size = sizeof(struct e1000_ps_page) * rxdr->count;
1622 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001623 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001624 vfree(rxdr->buffer_info);
1625 DPRINTK(PROBE, ERR,
1626 "Unable to allocate memory for the receive descriptor ring\n");
1627 return -ENOMEM;
1628 }
1629 memset(rxdr->ps_page, 0, size);
1630
1631 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1632 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001633 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001634 vfree(rxdr->buffer_info);
1635 kfree(rxdr->ps_page);
1636 DPRINTK(PROBE, ERR,
1637 "Unable to allocate memory for the receive descriptor ring\n");
1638 return -ENOMEM;
1639 }
1640 memset(rxdr->ps_page_dma, 0, size);
1641
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001642 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001643 desc_len = sizeof(struct e1000_rx_desc);
1644 else
1645 desc_len = sizeof(union e1000_rx_desc_packet_split);
1646
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 /* Round up to nearest 4K */
1648
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001649 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 E1000_ROUNDUP(rxdr->size, 4096);
1651
1652 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1653
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001654 if (!rxdr->desc) {
1655 DPRINTK(PROBE, ERR,
1656 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001659 kfree(rxdr->ps_page);
1660 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 return -ENOMEM;
1662 }
1663
Malli Chilakala26483452005-04-28 19:44:46 -07001664 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1666 void *olddesc = rxdr->desc;
1667 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001668 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1669 "at %p\n", rxdr->size, rxdr->desc);
1670 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001672 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001673 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001675 DPRINTK(PROBE, ERR,
1676 "Unable to allocate memory "
1677 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 goto setup_rx_desc_die;
1679 }
1680
1681 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1682 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001683 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1684 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001686 DPRINTK(PROBE, ERR,
1687 "Unable to allocate aligned memory "
1688 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001689 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001691 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1693 }
1694 }
1695 memset(rxdr->desc, 0, rxdr->size);
1696
1697 rxdr->next_to_clean = 0;
1698 rxdr->next_to_use = 0;
1699
1700 return 0;
1701}
1702
1703/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001704 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1705 * (Descriptors) for all queues
1706 * @adapter: board private structure
1707 *
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001708 * Return 0 on success, negative on failure
1709 **/
1710
1711int
1712e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1713{
1714 int i, err = 0;
1715
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001716 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001717 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1718 if (err) {
1719 DPRINTK(PROBE, ERR,
1720 "Allocation for Rx Queue %u failed\n", i);
Vasily Averin3fbbc722006-08-28 14:56:24 -07001721 for (i-- ; i >= 0; i--)
1722 e1000_free_rx_resources(adapter,
1723 &adapter->rx_ring[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001724 break;
1725 }
1726 }
1727
1728 return err;
1729}
1730
1731/**
Malli Chilakala26483452005-04-28 19:44:46 -07001732 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 * @adapter: Board private structure
1734 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001735#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1736 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737static void
1738e1000_setup_rctl(struct e1000_adapter *adapter)
1739{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001740 uint32_t rctl, rfctl;
1741 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001742#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001743 uint32_t pages = 0;
1744#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
1746 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1747
1748 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1749
1750 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1751 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1752 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1753
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001754 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 rctl |= E1000_RCTL_SBP;
1756 else
1757 rctl &= ~E1000_RCTL_SBP;
1758
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001759 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1760 rctl &= ~E1000_RCTL_LPE;
1761 else
1762 rctl |= E1000_RCTL_LPE;
1763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001765 rctl &= ~E1000_RCTL_SZ_4096;
1766 rctl |= E1000_RCTL_BSEX;
1767 switch (adapter->rx_buffer_len) {
1768 case E1000_RXBUFFER_256:
1769 rctl |= E1000_RCTL_SZ_256;
1770 rctl &= ~E1000_RCTL_BSEX;
1771 break;
1772 case E1000_RXBUFFER_512:
1773 rctl |= E1000_RCTL_SZ_512;
1774 rctl &= ~E1000_RCTL_BSEX;
1775 break;
1776 case E1000_RXBUFFER_1024:
1777 rctl |= E1000_RCTL_SZ_1024;
1778 rctl &= ~E1000_RCTL_BSEX;
1779 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001780 case E1000_RXBUFFER_2048:
1781 default:
1782 rctl |= E1000_RCTL_SZ_2048;
1783 rctl &= ~E1000_RCTL_BSEX;
1784 break;
1785 case E1000_RXBUFFER_4096:
1786 rctl |= E1000_RCTL_SZ_4096;
1787 break;
1788 case E1000_RXBUFFER_8192:
1789 rctl |= E1000_RCTL_SZ_8192;
1790 break;
1791 case E1000_RXBUFFER_16384:
1792 rctl |= E1000_RCTL_SZ_16384;
1793 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001794 }
1795
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001796#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001797 /* 82571 and greater support packet-split where the protocol
1798 * header is placed in skb->data and the packet data is
1799 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1800 * In the case of a non-split, skb->data is linearly filled,
1801 * followed by the page buffers. Therefore, skb->data is
1802 * sized to hold the largest protocol header.
1803 */
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001804 /* allocations using alloc_page take too long for regular MTU
1805 * so only enable packet split for jumbo frames */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001806 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
Jesse Brandeburge64d7d02006-10-24 14:46:01 -07001807 if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
1808 PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001809 adapter->rx_ps_pages = pages;
1810 else
1811 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001812#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001813 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001814 /* Configure extra packet-split registers */
1815 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1816 rfctl |= E1000_RFCTL_EXTEN;
Auke Kok87ca4e52006-11-01 08:47:36 -08001817 /* disable packet split support for IPv6 extension headers,
1818 * because some malformed IPv6 headers can hang the RX */
1819 rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
1820 E1000_RFCTL_NEW_IPV6_EXT_DIS);
1821
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001822 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1823
Auke Kok7dfee0c2006-06-27 09:07:50 -07001824 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001825
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001826 psrctl |= adapter->rx_ps_bsize0 >>
1827 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001828
1829 switch (adapter->rx_ps_pages) {
1830 case 3:
1831 psrctl |= PAGE_SIZE <<
1832 E1000_PSRCTL_BSIZE3_SHIFT;
1833 case 2:
1834 psrctl |= PAGE_SIZE <<
1835 E1000_PSRCTL_BSIZE2_SHIFT;
1836 case 1:
1837 psrctl |= PAGE_SIZE >>
1838 E1000_PSRCTL_BSIZE1_SHIFT;
1839 break;
1840 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001841
1842 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 }
1844
1845 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1846}
1847
1848/**
1849 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1850 * @adapter: board private structure
1851 *
1852 * Configure the Rx unit of the MAC after a reset.
1853 **/
1854
1855static void
1856e1000_configure_rx(struct e1000_adapter *adapter)
1857{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001858 uint64_t rdba;
1859 struct e1000_hw *hw = &adapter->hw;
1860 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001861
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001862 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001863 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001864 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001865 sizeof(union e1000_rx_desc_packet_split);
1866 adapter->clean_rx = e1000_clean_rx_irq_ps;
1867 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1868 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001869 rdlen = adapter->rx_ring[0].count *
1870 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001871 adapter->clean_rx = e1000_clean_rx_irq;
1872 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1873 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
1875 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001876 rctl = E1000_READ_REG(hw, RCTL);
1877 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
1879 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001880 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001882 if (hw->mac_type >= e1000_82540) {
1883 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001884 if (adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001885 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 1000000000 / (adapter->itr * 256));
1887 }
1888
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001889 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001890 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001891 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07001892 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001893#ifdef CONFIG_E1000_NAPI
1894 /* Auto-Mask interrupts upon ICR read. */
1895 ctrl_ext |= E1000_CTRL_EXT_IAME;
1896#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001897 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001898 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001899 E1000_WRITE_FLUSH(hw);
1900 }
1901
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001902 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1903 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001904 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001905 case 1:
1906 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001907 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001908 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001909 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1910 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001911 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001912 E1000_WRITE_REG(hw, RDH, 0);
Auke Kok6a951692006-09-11 14:00:21 -07001913 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
1914 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001915 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001916 }
1917
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001919 if (hw->mac_type >= e1000_82543) {
1920 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001921 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001922 rxcsum |= E1000_RXCSUM_TUOFL;
1923
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001924 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001925 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001926 if ((hw->mac_type >= e1000_82571) &&
1927 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001928 rxcsum |= E1000_RXCSUM_IPPCSE;
1929 }
1930 } else {
1931 rxcsum &= ~E1000_RXCSUM_TUOFL;
1932 /* don't need to clear IPPCSE as it defaults to 0 */
1933 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001934 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 }
1936
Auke Kok21c4d5e2006-11-01 08:47:39 -08001937 /* enable early receives on 82573, only takes effect if using > 2048
1938 * byte total frame size. for example only for jumbo frames */
1939#define E1000_ERT_2048 0x100
1940 if (hw->mac_type == e1000_82573)
1941 E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
1942
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001944 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945}
1946
1947/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001948 * e1000_free_tx_resources - Free Tx Resources per Queue
1949 * @adapter: board private structure
1950 * @tx_ring: Tx descriptor ring for a specific queue
1951 *
1952 * Free all transmit software resources
1953 **/
1954
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001955static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001956e1000_free_tx_resources(struct e1000_adapter *adapter,
1957 struct e1000_tx_ring *tx_ring)
1958{
1959 struct pci_dev *pdev = adapter->pdev;
1960
1961 e1000_clean_tx_ring(adapter, tx_ring);
1962
1963 vfree(tx_ring->buffer_info);
1964 tx_ring->buffer_info = NULL;
1965
1966 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1967
1968 tx_ring->desc = NULL;
1969}
1970
1971/**
1972 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 * @adapter: board private structure
1974 *
1975 * Free all transmit software resources
1976 **/
1977
1978void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001979e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001981 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001983 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001984 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985}
1986
Auke Koke619d522006-04-14 19:04:52 -07001987static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1989 struct e1000_buffer *buffer_info)
1990{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001991 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001992 pci_unmap_page(adapter->pdev,
1993 buffer_info->dma,
1994 buffer_info->length,
1995 PCI_DMA_TODEVICE);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08001996 buffer_info->dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 }
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08001998 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 dev_kfree_skb_any(buffer_info->skb);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002000 buffer_info->skb = NULL;
2001 }
2002 /* buffer_info must be completely set up in the transmit path */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003}
2004
2005/**
2006 * e1000_clean_tx_ring - Free Tx Buffers
2007 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002008 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 **/
2010
2011static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002012e1000_clean_tx_ring(struct e1000_adapter *adapter,
2013 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 struct e1000_buffer *buffer_info;
2016 unsigned long size;
2017 unsigned int i;
2018
2019 /* Free all the Tx ring sk_buffs */
2020
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002021 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 buffer_info = &tx_ring->buffer_info[i];
2023 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2024 }
2025
2026 size = sizeof(struct e1000_buffer) * tx_ring->count;
2027 memset(tx_ring->buffer_info, 0, size);
2028
2029 /* Zero out the descriptor ring */
2030
2031 memset(tx_ring->desc, 0, tx_ring->size);
2032
2033 tx_ring->next_to_use = 0;
2034 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002035 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002037 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
2038 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
2039}
2040
2041/**
2042 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
2043 * @adapter: board private structure
2044 **/
2045
2046static void
2047e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2048{
2049 int i;
2050
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002051 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002052 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053}
2054
2055/**
2056 * e1000_free_rx_resources - Free Rx Resources
2057 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002058 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 *
2060 * Free all receive software resources
2061 **/
2062
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002063static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002064e1000_free_rx_resources(struct e1000_adapter *adapter,
2065 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 struct pci_dev *pdev = adapter->pdev;
2068
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002069 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
2071 vfree(rx_ring->buffer_info);
2072 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002073 kfree(rx_ring->ps_page);
2074 rx_ring->ps_page = NULL;
2075 kfree(rx_ring->ps_page_dma);
2076 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
2078 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2079
2080 rx_ring->desc = NULL;
2081}
2082
2083/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002084 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002086 *
2087 * Free all receive software resources
2088 **/
2089
2090void
2091e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2092{
2093 int i;
2094
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002095 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002096 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2097}
2098
2099/**
2100 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2101 * @adapter: board private structure
2102 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 **/
2104
2105static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002106e1000_clean_rx_ring(struct e1000_adapter *adapter,
2107 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002110 struct e1000_ps_page *ps_page;
2111 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 struct pci_dev *pdev = adapter->pdev;
2113 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002114 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002117 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002119 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 pci_unmap_single(pdev,
2121 buffer_info->dma,
2122 buffer_info->length,
2123 PCI_DMA_FROMDEVICE);
2124
2125 dev_kfree_skb(buffer_info->skb);
2126 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002127 }
2128 ps_page = &rx_ring->ps_page[i];
2129 ps_page_dma = &rx_ring->ps_page_dma[i];
2130 for (j = 0; j < adapter->rx_ps_pages; j++) {
2131 if (!ps_page->ps_page[j]) break;
2132 pci_unmap_page(pdev,
2133 ps_page_dma->ps_page_dma[j],
2134 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2135 ps_page_dma->ps_page_dma[j] = 0;
2136 put_page(ps_page->ps_page[j]);
2137 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 }
2139 }
2140
2141 size = sizeof(struct e1000_buffer) * rx_ring->count;
2142 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002143 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2144 memset(rx_ring->ps_page, 0, size);
2145 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2146 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
2148 /* Zero out the descriptor ring */
2149
2150 memset(rx_ring->desc, 0, rx_ring->size);
2151
2152 rx_ring->next_to_clean = 0;
2153 rx_ring->next_to_use = 0;
2154
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002155 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2156 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2157}
2158
2159/**
2160 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2161 * @adapter: board private structure
2162 **/
2163
2164static void
2165e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2166{
2167 int i;
2168
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002169 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002170 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}
2172
2173/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2174 * and memory write and invalidate disabled for certain operations
2175 */
2176static void
2177e1000_enter_82542_rst(struct e1000_adapter *adapter)
2178{
2179 struct net_device *netdev = adapter->netdev;
2180 uint32_t rctl;
2181
2182 e1000_pci_clear_mwi(&adapter->hw);
2183
2184 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2185 rctl |= E1000_RCTL_RST;
2186 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2187 E1000_WRITE_FLUSH(&adapter->hw);
2188 mdelay(5);
2189
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002190 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002191 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192}
2193
2194static void
2195e1000_leave_82542_rst(struct e1000_adapter *adapter)
2196{
2197 struct net_device *netdev = adapter->netdev;
2198 uint32_t rctl;
2199
2200 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2201 rctl &= ~E1000_RCTL_RST;
2202 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2203 E1000_WRITE_FLUSH(&adapter->hw);
2204 mdelay(5);
2205
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002206 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 e1000_pci_set_mwi(&adapter->hw);
2208
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002209 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002210 /* No need to loop, because 82542 supports only 1 queue */
2211 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002212 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002213 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 }
2215}
2216
2217/**
2218 * e1000_set_mac - Change the Ethernet Address of the NIC
2219 * @netdev: network interface device structure
2220 * @p: pointer to an address structure
2221 *
2222 * Returns 0 on success, negative on failure
2223 **/
2224
2225static int
2226e1000_set_mac(struct net_device *netdev, void *p)
2227{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002228 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 struct sockaddr *addr = p;
2230
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002231 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 return -EADDRNOTAVAIL;
2233
2234 /* 82542 2.0 needs to be in reset to write receive address registers */
2235
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002236 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 e1000_enter_82542_rst(adapter);
2238
2239 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2240 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2241
2242 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2243
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002244 /* With 82571 controllers, LAA may be overwritten (with the default)
2245 * due to controller reset from the other port. */
2246 if (adapter->hw.mac_type == e1000_82571) {
2247 /* activate the work around */
2248 adapter->hw.laa_is_present = 1;
2249
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002250 /* Hold a copy of the LAA in RAR[14] This is done so that
2251 * between the time RAR[0] gets clobbered and the time it
2252 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002253 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002254 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002255 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002256 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002257 E1000_RAR_ENTRIES - 1);
2258 }
2259
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002260 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 e1000_leave_82542_rst(adapter);
2262
2263 return 0;
2264}
2265
2266/**
2267 * e1000_set_multi - Multicast and Promiscuous mode set
2268 * @netdev: network interface device structure
2269 *
2270 * The set_multi entry point is called whenever the multicast address
2271 * list or the network interface flags are updated. This routine is
2272 * responsible for configuring the hardware for proper multicast,
2273 * promiscuous mode, and all-multi behavior.
2274 **/
2275
2276static void
2277e1000_set_multi(struct net_device *netdev)
2278{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002279 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 struct e1000_hw *hw = &adapter->hw;
2281 struct dev_mc_list *mc_ptr;
2282 uint32_t rctl;
2283 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002284 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002285 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2286 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2287 E1000_NUM_MTA_REGISTERS;
2288
2289 if (adapter->hw.mac_type == e1000_ich8lan)
2290 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002292 /* reserve RAR[14] for LAA over-write work-around */
2293 if (adapter->hw.mac_type == e1000_82571)
2294 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
Malli Chilakala26483452005-04-28 19:44:46 -07002296 /* Check for Promiscuous and All Multicast modes */
2297
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 rctl = E1000_READ_REG(hw, RCTL);
2299
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002300 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002302 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 rctl |= E1000_RCTL_MPE;
2304 rctl &= ~E1000_RCTL_UPE;
2305 } else {
2306 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2307 }
2308
2309 E1000_WRITE_REG(hw, RCTL, rctl);
2310
2311 /* 82542 2.0 needs to be in reset to write receive address registers */
2312
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002313 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 e1000_enter_82542_rst(adapter);
2315
2316 /* load the first 14 multicast address into the exact filters 1-14
2317 * RAR 0 is used for the station MAC adddress
2318 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002319 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 */
2321 mc_ptr = netdev->mc_list;
2322
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002323 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002324 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2326 mc_ptr = mc_ptr->next;
2327 } else {
2328 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002329 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002331 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 }
2333 }
2334
2335 /* clear the old settings from the multicast hash table */
2336
Auke Kokcd94dd02006-06-27 09:08:22 -07002337 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002339 E1000_WRITE_FLUSH(hw);
2340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
2342 /* load any remaining addresses into the hash table */
2343
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002344 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2346 e1000_mta_set(hw, hash_value);
2347 }
2348
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002349 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351}
2352
2353/* Need to wait a few seconds after link up to get diagnostic information from
2354 * the phy */
2355
2356static void
2357e1000_update_phy_info(unsigned long data)
2358{
2359 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2360 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2361}
2362
2363/**
2364 * e1000_82547_tx_fifo_stall - Timer Call-back
2365 * @data: pointer to adapter cast into an unsigned long
2366 **/
2367
2368static void
2369e1000_82547_tx_fifo_stall(unsigned long data)
2370{
2371 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2372 struct net_device *netdev = adapter->netdev;
2373 uint32_t tctl;
2374
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002375 if (atomic_read(&adapter->tx_fifo_stall)) {
2376 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 E1000_READ_REG(&adapter->hw, TDH)) &&
2378 (E1000_READ_REG(&adapter->hw, TDFT) ==
2379 E1000_READ_REG(&adapter->hw, TDFH)) &&
2380 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2381 E1000_READ_REG(&adapter->hw, TDFHS))) {
2382 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2383 E1000_WRITE_REG(&adapter->hw, TCTL,
2384 tctl & ~E1000_TCTL_EN);
2385 E1000_WRITE_REG(&adapter->hw, TDFT,
2386 adapter->tx_head_addr);
2387 E1000_WRITE_REG(&adapter->hw, TDFH,
2388 adapter->tx_head_addr);
2389 E1000_WRITE_REG(&adapter->hw, TDFTS,
2390 adapter->tx_head_addr);
2391 E1000_WRITE_REG(&adapter->hw, TDFHS,
2392 adapter->tx_head_addr);
2393 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2394 E1000_WRITE_FLUSH(&adapter->hw);
2395
2396 adapter->tx_fifo_head = 0;
2397 atomic_set(&adapter->tx_fifo_stall, 0);
2398 netif_wake_queue(netdev);
2399 } else {
2400 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2401 }
2402 }
2403}
2404
2405/**
2406 * e1000_watchdog - Timer Call-back
2407 * @data: pointer to adapter cast into an unsigned long
2408 **/
2409static void
2410e1000_watchdog(unsigned long data)
2411{
2412 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002414 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002415 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002416 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Auke Kokcd94dd02006-06-27 09:08:22 -07002418 ret_val = e1000_check_for_link(&adapter->hw);
2419 if ((ret_val == E1000_ERR_PHY) &&
2420 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2421 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2422 /* See e1000_kumeran_lock_loss_workaround() */
2423 DPRINTK(LINK, INFO,
2424 "Gigabit has been disabled, downgrading speed\n");
2425 }
Auke Kok90fb5132006-11-01 08:47:30 -08002426
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002427 if (adapter->hw.mac_type == e1000_82573) {
2428 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002429 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002430 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002433 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2435 link = !adapter->hw.serdes_link_down;
2436 else
2437 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2438
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002439 if (link) {
2440 if (!netif_carrier_ok(netdev)) {
Auke Kokfe7fe282006-04-14 19:04:59 -07002441 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 e1000_get_speed_and_duplex(&adapter->hw,
2443 &adapter->link_speed,
2444 &adapter->link_duplex);
2445
2446 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2447 adapter->link_speed,
2448 adapter->link_duplex == FULL_DUPLEX ?
2449 "Full Duplex" : "Half Duplex");
2450
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002451 /* tweak tx_queue_len according to speed/duplex
2452 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002453 netdev->tx_queue_len = adapter->tx_queue_len;
2454 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002455 switch (adapter->link_speed) {
2456 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002457 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002458 netdev->tx_queue_len = 10;
2459 adapter->tx_timeout_factor = 8;
2460 break;
2461 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002462 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002463 netdev->tx_queue_len = 100;
2464 /* maybe add some timeout factor ? */
2465 break;
2466 }
2467
Auke Kokfe7fe282006-04-14 19:04:59 -07002468 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002469 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002470 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002471 uint32_t tarc0;
2472 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
Auke Kok90fb5132006-11-01 08:47:30 -08002473 tarc0 &= ~(1 << 21);
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002474 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2475 }
Auke Kok90fb5132006-11-01 08:47:30 -08002476
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002477#ifdef NETIF_F_TSO
2478 /* disable TSO for pcie and 10/100 speeds, to avoid
2479 * some hardware issues */
2480 if (!adapter->tso_force &&
2481 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002482 switch (adapter->link_speed) {
2483 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002484 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002485 DPRINTK(PROBE,INFO,
2486 "10/100 speed: disabling TSO\n");
2487 netdev->features &= ~NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002488#ifdef NETIF_F_TSO6
2489 netdev->features &= ~NETIF_F_TSO6;
2490#endif
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002491 break;
2492 case SPEED_1000:
2493 netdev->features |= NETIF_F_TSO;
Auke Kok87ca4e52006-11-01 08:47:36 -08002494#ifdef NETIF_F_TSO6
2495 netdev->features |= NETIF_F_TSO6;
2496#endif
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002497 break;
2498 default:
2499 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002500 break;
2501 }
2502 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002503#endif
2504
2505 /* enable transmits in the hardware, need to do this
2506 * after setting TARC0 */
2507 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2508 tctl |= E1000_TCTL_EN;
2509 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002510
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 netif_carrier_on(netdev);
2512 netif_wake_queue(netdev);
2513 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2514 adapter->smartspeed = 0;
2515 }
2516 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002517 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 adapter->link_speed = 0;
2519 adapter->link_duplex = 0;
2520 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2521 netif_carrier_off(netdev);
2522 netif_stop_queue(netdev);
2523 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002524
2525 /* 80003ES2LAN workaround--
2526 * For packet buffer work-around on link down event;
2527 * disable receives in the ISR and
2528 * reset device here in the watchdog
2529 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002530 if (adapter->hw.mac_type == e1000_80003es2lan)
Jeff Kirsher87041632006-03-02 18:21:24 -08002531 /* reset device */
2532 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 }
2534
2535 e1000_smartspeed(adapter);
2536 }
2537
2538 e1000_update_stats(adapter);
2539
2540 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2541 adapter->tpt_old = adapter->stats.tpt;
2542 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2543 adapter->colc_old = adapter->stats.colc;
2544
2545 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2546 adapter->gorcl_old = adapter->stats.gorcl;
2547 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2548 adapter->gotcl_old = adapter->stats.gotcl;
2549
2550 e1000_update_adaptive(&adapter->hw);
2551
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002552 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002553 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 /* We've lost link, so the controller stops DMA,
2555 * but we've got queued Tx work that's never going
2556 * to get done, so reset controller to flush Tx.
2557 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002558 adapter->tx_timeout_count++;
2559 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 }
2561 }
2562
2563 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002564 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2566 * asymmetrical Tx or Rx gets ITR=8000; everyone
2567 * else is between 2000-8000. */
2568 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002569 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 adapter->gotcl - adapter->gorcl :
2571 adapter->gorcl - adapter->gotcl) / 10000;
2572 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2573 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2574 }
2575
2576 /* Cause software interrupt to ensure rx ring is cleaned */
2577 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2578
Malli Chilakala26483452005-04-28 19:44:46 -07002579 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 adapter->detect_tx_hung = TRUE;
2581
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002582 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002583 * reset from the other port. Set the appropriate LAA in RAR[0] */
2584 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2585 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2586
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 /* Reset the timer */
2588 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2589}
2590
2591#define E1000_TX_FLAGS_CSUM 0x00000001
2592#define E1000_TX_FLAGS_VLAN 0x00000002
2593#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002594#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2596#define E1000_TX_FLAGS_VLAN_SHIFT 16
2597
Auke Koke619d522006-04-14 19:04:52 -07002598static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002599e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2600 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601{
2602#ifdef NETIF_F_TSO
2603 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002604 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 unsigned int i;
2606 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002607 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2609 int err;
2610
Herbert Xu89114af2006-07-08 13:34:32 -07002611 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 if (skb_header_cloned(skb)) {
2613 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2614 if (err)
2615 return err;
2616 }
2617
2618 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Herbert Xu79671682006-06-22 02:40:14 -07002619 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002620 if (skb->protocol == htons(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002621 skb->nh.iph->tot_len = 0;
2622 skb->nh.iph->check = 0;
2623 skb->h.th->check =
2624 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2625 skb->nh.iph->daddr,
2626 0,
2627 IPPROTO_TCP,
2628 0);
2629 cmd_length = E1000_TXD_CMD_IP;
2630 ipcse = skb->h.raw - skb->data - 1;
Auke Kok87ca4e52006-11-01 08:47:36 -08002631#ifdef NETIF_F_TSO6
Auke Koke15fdd02006-08-16 11:28:45 -07002632 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002633 skb->nh.ipv6h->payload_len = 0;
2634 skb->h.th->check =
2635 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2636 &skb->nh.ipv6h->daddr,
2637 0,
2638 IPPROTO_TCP,
2639 0);
2640 ipcse = 0;
2641#endif
2642 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 ipcss = skb->nh.raw - skb->data;
2644 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 tucss = skb->h.raw - skb->data;
2646 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2647 tucse = 0;
2648
2649 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002650 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002652 i = tx_ring->next_to_use;
2653 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002654 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
2656 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2657 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2658 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2659 context_desc->upper_setup.tcp_fields.tucss = tucss;
2660 context_desc->upper_setup.tcp_fields.tucso = tucso;
2661 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2662 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2663 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2664 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2665
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002666 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002667 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002668
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002669 if (++i == tx_ring->count) i = 0;
2670 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671
Jeff Kirsher8241e352006-01-12 16:51:34 -08002672 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 }
2674#endif
2675
Jeff Kirsher8241e352006-01-12 16:51:34 -08002676 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677}
2678
Auke Koke619d522006-04-14 19:04:52 -07002679static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002680e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2681 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682{
2683 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002684 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 unsigned int i;
2686 uint8_t css;
2687
Patrick McHardy84fa7932006-08-29 16:44:56 -07002688 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 css = skb->h.raw - skb->data;
2690
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002691 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002692 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002693 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
2695 context_desc->upper_setup.tcp_fields.tucss = css;
2696 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2697 context_desc->upper_setup.tcp_fields.tucse = 0;
2698 context_desc->tcp_seg_setup.data = 0;
2699 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2700
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002701 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002702 buffer_info->next_to_watch = i;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002703
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002704 if (unlikely(++i == tx_ring->count)) i = 0;
2705 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
2707 return TRUE;
2708 }
2709
2710 return FALSE;
2711}
2712
2713#define E1000_MAX_TXD_PWR 12
2714#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2715
Auke Koke619d522006-04-14 19:04:52 -07002716static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002717e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2718 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2719 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 struct e1000_buffer *buffer_info;
2722 unsigned int len = skb->len;
2723 unsigned int offset = 0, size, count = 0, i;
2724 unsigned int f;
2725 len -= skb->data_len;
2726
2727 i = tx_ring->next_to_use;
2728
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002729 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 buffer_info = &tx_ring->buffer_info[i];
2731 size = min(len, max_per_txd);
2732#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002733 /* Workaround for Controller erratum --
2734 * descriptor for non-tso packet in a linear SKB that follows a
2735 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002736 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002737 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07002738 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002739 tx_ring->last_tx_tso = 0;
2740 size -= 4;
2741 }
2742
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 /* Workaround for premature desc write-backs
2744 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002745 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 size -= 4;
2747#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002748 /* work-around for errata 10 and it applies
2749 * to all controllers in PCI-X mode
2750 * The fix is to make sure that the first descriptor of a
2751 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2752 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002753 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002754 (size > 2015) && count == 0))
2755 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002756
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 /* Workaround for potential 82544 hang in PCI-X. Avoid
2758 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002759 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2761 size > 4))
2762 size -= 4;
2763
2764 buffer_info->length = size;
2765 buffer_info->dma =
2766 pci_map_single(adapter->pdev,
2767 skb->data + offset,
2768 size,
2769 PCI_DMA_TODEVICE);
2770 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002771 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
2773 len -= size;
2774 offset += size;
2775 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002776 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 }
2778
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002779 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 struct skb_frag_struct *frag;
2781
2782 frag = &skb_shinfo(skb)->frags[f];
2783 len = frag->size;
2784 offset = frag->page_offset;
2785
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002786 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 buffer_info = &tx_ring->buffer_info[i];
2788 size = min(len, max_per_txd);
2789#ifdef NETIF_F_TSO
2790 /* Workaround for premature desc write-backs
2791 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002792 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 size -= 4;
2794#endif
2795 /* Workaround for potential 82544 hang in PCI-X.
2796 * Avoid terminating buffers within evenly-aligned
2797 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002798 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2800 size > 4))
2801 size -= 4;
2802
2803 buffer_info->length = size;
2804 buffer_info->dma =
2805 pci_map_page(adapter->pdev,
2806 frag->page,
2807 offset,
2808 size,
2809 PCI_DMA_TODEVICE);
2810 buffer_info->time_stamp = jiffies;
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08002811 buffer_info->next_to_watch = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
2813 len -= size;
2814 offset += size;
2815 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002816 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 }
2818 }
2819
2820 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2821 tx_ring->buffer_info[i].skb = skb;
2822 tx_ring->buffer_info[first].next_to_watch = i;
2823
2824 return count;
2825}
2826
Auke Koke619d522006-04-14 19:04:52 -07002827static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002828e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2829 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 struct e1000_tx_desc *tx_desc = NULL;
2832 struct e1000_buffer *buffer_info;
2833 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2834 unsigned int i;
2835
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002836 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2838 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002839 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2840
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002841 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002842 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 }
2844
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002845 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2847 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2848 }
2849
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002850 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 txd_lower |= E1000_TXD_CMD_VLE;
2852 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2853 }
2854
2855 i = tx_ring->next_to_use;
2856
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002857 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 buffer_info = &tx_ring->buffer_info[i];
2859 tx_desc = E1000_TX_DESC(*tx_ring, i);
2860 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2861 tx_desc->lower.data =
2862 cpu_to_le32(txd_lower | buffer_info->length);
2863 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002864 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 }
2866
2867 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2868
2869 /* Force memory writes to complete before letting h/w
2870 * know there are new descriptors to fetch. (Only
2871 * applicable for weak-ordered memory model archs,
2872 * such as IA-64). */
2873 wmb();
2874
2875 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002876 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Jesse Brandeburg2ce90472006-11-01 08:47:42 -08002877 /* we need this if more than one processor can write to our tail
2878 * at a time, it syncronizes IO on IA64/Altix systems */
2879 mmiowb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880}
2881
2882/**
2883 * 82547 workaround to avoid controller hang in half-duplex environment.
2884 * The workaround is to avoid queuing a large packet that would span
2885 * the internal Tx FIFO ring boundary by notifying the stack to resend
2886 * the packet at a later time. This gives the Tx FIFO an opportunity to
2887 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2888 * to the beginning of the Tx FIFO.
2889 **/
2890
2891#define E1000_FIFO_HDR 0x10
2892#define E1000_82547_PAD_LEN 0x3E0
2893
Auke Koke619d522006-04-14 19:04:52 -07002894static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2896{
2897 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2898 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2899
2900 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2901
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002902 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 goto no_fifo_stall_required;
2904
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002905 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 return 1;
2907
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002908 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 atomic_set(&adapter->tx_fifo_stall, 1);
2910 return 1;
2911 }
2912
2913no_fifo_stall_required:
2914 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002915 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2917 return 0;
2918}
2919
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002920#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07002921static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002922e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2923{
2924 struct e1000_hw *hw = &adapter->hw;
2925 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002926 if (vlan_tx_tag_present(skb)) {
2927 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002928 ( adapter->hw.mng_cookie.status &
2929 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2930 return 0;
2931 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08002932 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002933 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002934 if ((htons(ETH_P_IP) == eth->h_proto)) {
2935 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002936 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002937 if (IPPROTO_UDP == ip->protocol) {
2938 struct udphdr *udp =
2939 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002940 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002941 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002942 offset = (uint8_t *)udp + 8 - skb->data;
2943 length = skb->len - offset;
2944
2945 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002946 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002947 length);
2948 }
2949 }
2950 }
2951 }
2952 return 0;
2953}
2954
Jesse Brandeburg65c79732006-09-27 12:53:48 -07002955static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
2956{
2957 struct e1000_adapter *adapter = netdev_priv(netdev);
2958 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
2959
2960 netif_stop_queue(netdev);
2961 /* Herbert's original patch had:
2962 * smp_mb__after_netif_stop_queue();
2963 * but since that doesn't exist yet, just open code it. */
2964 smp_mb();
2965
2966 /* We need to check again in a case another CPU has just
2967 * made room available. */
2968 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
2969 return -EBUSY;
2970
2971 /* A reprieve! */
2972 netif_start_queue(netdev);
2973 return 0;
2974}
2975
2976static int e1000_maybe_stop_tx(struct net_device *netdev,
2977 struct e1000_tx_ring *tx_ring, int size)
2978{
2979 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
2980 return 0;
2981 return __e1000_maybe_stop_tx(netdev, size);
2982}
2983
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2985static int
2986e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2987{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002988 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002989 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2991 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2992 unsigned int tx_flags = 0;
2993 unsigned int len = skb->len;
2994 unsigned long flags;
2995 unsigned int nr_frags = 0;
2996 unsigned int mss = 0;
2997 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07002998 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 unsigned int f;
3000 len -= skb->data_len;
3001
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003002 /* This goes back to the question of how to logically map a tx queue
3003 * to a flow. Right now, performance is impacted slightly negatively
3004 * if using multiple tx queues. If the stack breaks away from a
3005 * single qdisc implementation, we can look at this again. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003006 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003007
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003008 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 dev_kfree_skb_any(skb);
3010 return NETDEV_TX_OK;
3011 }
3012
Jesse Brandeburg032fe6e2006-10-24 14:46:04 -07003013 /* 82571 and newer doesn't need the workaround that limited descriptor
3014 * length to 4kB */
3015 if (adapter->hw.mac_type >= e1000_82571)
3016 max_per_txd = 8192;
3017
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018#ifdef NETIF_F_TSO
Herbert Xu79671682006-06-22 02:40:14 -07003019 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07003020 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 * make sure there is enough room in the FIFO before
3022 * initiating the DMA for each buffer. The calc is:
3023 * 4 = ceil(buffer len/mss). To make sure we don't
3024 * overrun the FIFO, adjust the max buffer len if mss
3025 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003026 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003027 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 max_per_txd = min(mss << 2, max_per_txd);
3029 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003030
Auke Kok90fb5132006-11-01 08:47:30 -08003031 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
3032 * points to just header, pull a few bytes of payload from
3033 * frags into skb->data */
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003034 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08003035 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3036 switch (adapter->hw.mac_type) {
3037 unsigned int pull_size;
3038 case e1000_82571:
3039 case e1000_82572:
3040 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07003041 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08003042 pull_size = min((unsigned int)4, skb->data_len);
3043 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07003044 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08003045 "__pskb_pull_tail failed.\n");
3046 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05003047 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08003048 }
3049 len = skb->len - skb->data_len;
3050 break;
3051 default:
3052 /* do nothing */
3053 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08003054 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003055 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 }
3057
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08003058 /* reserve a descriptor for the offload context */
Patrick McHardy84fa7932006-08-29 16:44:56 -07003059 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07003061 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062#else
Patrick McHardy84fa7932006-08-29 16:44:56 -07003063 if (skb->ip_summed == CHECKSUM_PARTIAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 count++;
3065#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05003066
3067#ifdef NETIF_F_TSO
3068 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07003069 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05003070 count++;
3071#endif
3072
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 count += TXD_USE_COUNT(len, max_txd_pwr);
3074
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003075 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 count++;
3077
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003078 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07003079 * in PCI-X mode, so add one more descriptor to the count
3080 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003081 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07003082 (len > 2015)))
3083 count++;
3084
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003086 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
3088 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003089 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 count += nr_frags;
3091
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003092
3093 if (adapter->hw.tx_pkt_filtering &&
3094 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003095 e1000_transfer_dhcp_info(adapter, skb);
3096
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003097 local_irq_save(flags);
3098 if (!spin_trylock(&tx_ring->tx_lock)) {
3099 /* Collision - tell upper layer to requeue */
3100 local_irq_restore(flags);
3101 return NETDEV_TX_LOCKED;
3102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103
3104 /* need: count + 2 desc gap to keep tail from touching
3105 * head, otherwise try next time */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003106 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003107 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 return NETDEV_TX_BUSY;
3109 }
3110
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003111 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
3112 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 netif_stop_queue(netdev);
Auke Kok1314bbf2006-09-27 12:54:02 -07003114 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003115 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 return NETDEV_TX_BUSY;
3117 }
3118 }
3119
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003120 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 tx_flags |= E1000_TX_FLAGS_VLAN;
3122 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
3123 }
3124
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003125 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003126
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003127 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 if (tso < 0) {
3129 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003130 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 return NETDEV_TX_OK;
3132 }
3133
Jeff Kirsherfd803242005-12-13 00:06:22 -05003134 if (likely(tso)) {
3135 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003137 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 tx_flags |= E1000_TX_FLAGS_CSUM;
3139
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003140 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003141 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003142 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003143 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003144 tx_flags |= E1000_TX_FLAGS_IPV4;
3145
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003146 e1000_tx_queue(adapter, tx_ring, tx_flags,
3147 e1000_tx_map(adapter, tx_ring, skb, first,
3148 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149
3150 netdev->trans_start = jiffies;
3151
3152 /* Make sure there is space in the ring for the next send. */
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003153 e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003155 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 return NETDEV_TX_OK;
3157}
3158
3159/**
3160 * e1000_tx_timeout - Respond to a Tx Hang
3161 * @netdev: network interface device structure
3162 **/
3163
3164static void
3165e1000_tx_timeout(struct net_device *netdev)
3166{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003167 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
3169 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003170 adapter->tx_timeout_count++;
3171 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172}
3173
3174static void
Jeff Kirsher87041632006-03-02 18:21:24 -08003175e1000_reset_task(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003177 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178
Auke Kok2db10a02006-06-27 09:06:28 -07003179 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180}
3181
3182/**
3183 * e1000_get_stats - Get System Network Statistics
3184 * @netdev: network interface device structure
3185 *
3186 * Returns the address of the device statistics structure.
3187 * The statistics are actually updated from the timer callback.
3188 **/
3189
3190static struct net_device_stats *
3191e1000_get_stats(struct net_device *netdev)
3192{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003193 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003195 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 return &adapter->net_stats;
3197}
3198
3199/**
3200 * e1000_change_mtu - Change the Maximum Transfer Unit
3201 * @netdev: network interface device structure
3202 * @new_mtu: new value for maximum frame size
3203 *
3204 * Returns 0 on success, negative on failure
3205 **/
3206
3207static int
3208e1000_change_mtu(struct net_device *netdev, int new_mtu)
3209{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003210 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003212 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003214 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3215 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3216 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003217 return -EINVAL;
3218 }
3219
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003220 /* Adapter-specific max frame size limits. */
3221 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003222 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003223 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003224 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3225 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003226 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003227 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003228 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003229 case e1000_82573:
Bruce Allan249d71d2006-09-27 12:53:45 -07003230 /* Jumbo Frames not supported if:
3231 * - this is not an 82573L device
3232 * - ASPM is enabled in any way (0x1A bits 3:2) */
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003233 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3234 &eeprom_data);
Bruce Allan249d71d2006-09-27 12:53:45 -07003235 if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
3236 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003237 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3238 DPRINTK(PROBE, ERR,
3239 "Jumbo Frames not supported.\n");
3240 return -EINVAL;
3241 }
3242 break;
3243 }
Bruce Allan249d71d2006-09-27 12:53:45 -07003244 /* ERT will be enabled later to enable wire speed receives */
3245
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003246 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003247 case e1000_82571:
3248 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003249 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003250#define MAX_STD_JUMBO_FRAME_SIZE 9234
3251 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3252 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3253 return -EINVAL;
3254 }
3255 break;
3256 default:
3257 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3258 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003259 }
3260
David S. Miller87f50322006-07-31 22:39:40 -07003261 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003262 * means we reserve 2 more, this pushes us to allocate from the next
3263 * larger slab size
3264 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003265
Auke Kok9e2feac2006-04-14 19:05:18 -07003266 if (max_frame <= E1000_RXBUFFER_256)
3267 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3268 else if (max_frame <= E1000_RXBUFFER_512)
3269 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3270 else if (max_frame <= E1000_RXBUFFER_1024)
3271 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3272 else if (max_frame <= E1000_RXBUFFER_2048)
3273 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3274 else if (max_frame <= E1000_RXBUFFER_4096)
3275 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3276 else if (max_frame <= E1000_RXBUFFER_8192)
3277 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3278 else if (max_frame <= E1000_RXBUFFER_16384)
3279 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3280
3281 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003282 if (!adapter->hw.tbi_compatibility_on &&
3283 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3284 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3285 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003286
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003287 netdev->mtu = new_mtu;
3288
Auke Kok2db10a02006-06-27 09:06:28 -07003289 if (netif_running(netdev))
3290 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 adapter->hw.max_frame_size = max_frame;
3293
3294 return 0;
3295}
3296
3297/**
3298 * e1000_update_stats - Update the board statistics counters
3299 * @adapter: board private structure
3300 **/
3301
3302void
3303e1000_update_stats(struct e1000_adapter *adapter)
3304{
3305 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003306 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 unsigned long flags;
3308 uint16_t phy_tmp;
3309
3310#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3311
Linas Vepstas282f33c2006-06-08 22:19:44 -07003312 /*
3313 * Prevent stats update while adapter is being reset, or if the pci
3314 * connection is down.
3315 */
Auke Kok90267292006-06-08 09:30:24 -07003316 if (adapter->link_speed == 0)
3317 return;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003318 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3319 return;
Auke Kok90267292006-06-08 09:30:24 -07003320
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 spin_lock_irqsave(&adapter->stats_lock, flags);
3322
3323 /* these counters are modified from e1000_adjust_tbi_stats,
3324 * called from the interrupt context, so they must only
3325 * be written while holding adapter->stats_lock
3326 */
3327
3328 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3329 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3330 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3331 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3332 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3333 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3334 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003335
3336 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003337 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3338 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3339 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3340 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3341 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3342 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
3345 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3346 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3347 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3348 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3349 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3350 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3351 adapter->stats.dc += E1000_READ_REG(hw, DC);
3352 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3353 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3354 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3355 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3356 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3357 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3358 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3359 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3360 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3361 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3362 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3363 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3364 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3365 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3366 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3367 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3368 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3369 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3370 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003371
3372 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003373 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3374 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3375 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3376 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3377 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3378 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003379 }
3380
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3382 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3383
3384 /* used for adaptive IFS */
3385
3386 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3387 adapter->stats.tpt += hw->tx_packet_delta;
3388 hw->collision_delta = E1000_READ_REG(hw, COLC);
3389 adapter->stats.colc += hw->collision_delta;
3390
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003391 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3393 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3394 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3395 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3396 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3397 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3398 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003399 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003400 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3401 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003402
3403 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08003404 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3405 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3406 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3407 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3408 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3409 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3410 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003411 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413
3414 /* Fill out the OS statistics structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 adapter->net_stats.rx_packets = adapter->stats.gprc;
3416 adapter->net_stats.tx_packets = adapter->stats.gptc;
3417 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3418 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3419 adapter->net_stats.multicast = adapter->stats.mprc;
3420 adapter->net_stats.collisions = adapter->stats.colc;
3421
3422 /* Rx Errors */
3423
Jeff Kirsher87041632006-03-02 18:21:24 -08003424 /* RLEC on some newer hardware can be incorrect so build
3425 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3427 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003428 adapter->stats.ruc + adapter->stats.roc +
3429 adapter->stats.cexterr;
Mitch Williams49559852006-09-27 12:53:37 -07003430 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3431 adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3433 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3435
3436 /* Tx Errors */
Mitch Williams49559852006-09-27 12:53:37 -07003437 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3438 adapter->net_stats.tx_errors = adapter->stats.txerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3440 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3441 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3442
3443 /* Tx Dropped needs to be maintained elsewhere */
3444
3445 /* Phy Stats */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003446 if (hw->media_type == e1000_media_type_copper) {
3447 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3449 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3450 adapter->phy_stats.idle_errors += phy_tmp;
3451 }
3452
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003453 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 (hw->phy_type == e1000_phy_m88) &&
3455 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3456 adapter->phy_stats.receive_errors += phy_tmp;
3457 }
3458
3459 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3460}
3461
3462/**
3463 * e1000_intr - Interrupt Handler
3464 * @irq: interrupt number
3465 * @data: pointer to a network interface device structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 **/
3467
3468static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01003469e1000_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470{
3471 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003472 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003474 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003475#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003476 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003477#else
3478 /* Interrupt Auto-Mask...upon reading ICR,
3479 * interrupts are masked. No need for the
3480 * IMC write, but it does mean we should
3481 * account for it ASAP. */
3482 if (likely(hw->mac_type >= e1000_82571))
3483 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003484#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003486 if (unlikely(!icr)) {
3487#ifdef CONFIG_E1000_NAPI
3488 if (hw->mac_type >= e1000_82571)
3489 e1000_irq_enable(adapter);
3490#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003492 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003494 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003496 /* 80003ES2LAN workaround--
3497 * For packet buffer work-around on link down event;
3498 * disable receives here in the ISR and
3499 * reset adapter in watchdog
3500 */
3501 if (netif_carrier_ok(netdev) &&
3502 (adapter->hw.mac_type == e1000_80003es2lan)) {
3503 /* disable receives */
3504 rctl = E1000_READ_REG(hw, RCTL);
3505 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3506 }
Auke Kok1314bbf2006-09-27 12:54:02 -07003507 /* guard against interrupt when we're going down */
3508 if (!test_bit(__E1000_DOWN, &adapter->flags))
3509 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 }
3511
3512#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003513 if (unlikely(hw->mac_type < e1000_82571)) {
3514 atomic_inc(&adapter->irq_sem);
3515 E1000_WRITE_REG(hw, IMC, ~0);
3516 E1000_WRITE_FLUSH(hw);
3517 }
Auke Kokd3d9e482006-07-14 16:14:23 -07003518 if (likely(netif_rx_schedule_prep(netdev)))
3519 __netif_rx_schedule(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003520 else
Auke Kok90fb5132006-11-01 08:47:30 -08003521 /* this really should not happen! if it does it is basically a
3522 * bug, but not a hard error, so enable ints and continue */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003523 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003524#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003526 * Due to Hub Link bus being occupied, an interrupt
3527 * de-assertion message is not able to be sent.
3528 * When an interrupt assertion message is generated later,
3529 * two messages are re-ordered and sent out.
3530 * That causes APIC to think 82547 is in de-assertion
3531 * state, while 82547 is in assertion state, resulting
3532 * in dead lock. Writing IMC forces 82547 into
3533 * de-assertion state.
3534 */
3535 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003537 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 }
3539
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003540 for (i = 0; i < E1000_MAX_INTR; i++)
3541 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003542 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543 break;
3544
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003545 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003547
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003548#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 return IRQ_HANDLED;
3550}
3551
3552#ifdef CONFIG_E1000_NAPI
3553/**
3554 * e1000_clean - NAPI Rx polling callback
3555 * @adapter: board private structure
3556 **/
3557
3558static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003559e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003561 struct e1000_adapter *adapter;
3562 int work_to_do = min(*budget, poll_dev->quota);
Auke Kokd3d9e482006-07-14 16:14:23 -07003563 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003564
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003565 /* Must NOT use netdev_priv macro here. */
3566 adapter = poll_dev->priv;
3567
3568 /* Keep link state information with original netdev */
Auke Kokd3d9e482006-07-14 16:14:23 -07003569 if (!netif_carrier_ok(poll_dev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003570 goto quit_polling;
3571
Auke Kokd3d9e482006-07-14 16:14:23 -07003572 /* e1000_clean is called per-cpu. This lock protects
3573 * tx_ring[0] from being cleaned by multiple cpus
3574 * simultaneously. A failure obtaining the lock means
3575 * tx_ring[0] is currently being cleaned anyway. */
3576 if (spin_trylock(&adapter->tx_queue_lock)) {
3577 tx_cleaned = e1000_clean_tx_irq(adapter,
3578 &adapter->tx_ring[0]);
3579 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003580 }
3581
Auke Kokd3d9e482006-07-14 16:14:23 -07003582 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003583 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584
3585 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003586 poll_dev->quota -= work_done;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003587
Malli Chilakala2b028932005-06-17 17:46:06 -07003588 /* If no Tx and not enough Rx work done, exit the polling mode */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003589 if ((!tx_cleaned && (work_done == 0)) ||
Auke Kokd3d9e482006-07-14 16:14:23 -07003590 !netif_running(poll_dev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003591quit_polling:
3592 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 e1000_irq_enable(adapter);
3594 return 0;
3595 }
3596
3597 return 1;
3598}
3599
3600#endif
3601/**
3602 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3603 * @adapter: board private structure
3604 **/
3605
3606static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003607e1000_clean_tx_irq(struct e1000_adapter *adapter,
3608 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 struct net_device *netdev = adapter->netdev;
3611 struct e1000_tx_desc *tx_desc, *eop_desc;
3612 struct e1000_buffer *buffer_info;
3613 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003614#ifdef CONFIG_E1000_NAPI
3615 unsigned int count = 0;
3616#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 boolean_t cleaned = FALSE;
3618
3619 i = tx_ring->next_to_clean;
3620 eop = tx_ring->buffer_info[i].next_to_watch;
3621 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3622
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003623 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003624 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 tx_desc = E1000_TX_DESC(*tx_ring, i);
3626 buffer_info = &tx_ring->buffer_info[i];
3627 cleaned = (i == eop);
3628
Jeff Kirsherfd803242005-12-13 00:06:22 -05003629 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jesse Brandeburga9ebadd2006-11-01 08:47:53 -08003630 tx_desc->upper.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003632 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003634
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 eop = tx_ring->buffer_info[i].next_to_watch;
3636 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003637#ifdef CONFIG_E1000_NAPI
3638#define E1000_TX_WEIGHT 64
3639 /* weight of a sort for tx, to avoid endless transmit cleanup */
3640 if (count++ == E1000_TX_WEIGHT) break;
3641#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 }
3643
3644 tx_ring->next_to_clean = i;
3645
Auke Kok77b2aad2006-04-14 19:05:25 -07003646#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg65c79732006-09-27 12:53:48 -07003647 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
3648 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3649 /* Make sure that anybody stopping the queue after this
3650 * sees the new next_to_clean.
3651 */
3652 smp_mb();
3653 if (netif_queue_stopped(netdev))
Auke Kok77b2aad2006-04-14 19:05:25 -07003654 netif_wake_queue(netdev);
Auke Kok77b2aad2006-04-14 19:05:25 -07003655 }
Malli Chilakala26483452005-04-28 19:44:46 -07003656
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003657 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003658 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 * check with the clearing of time_stamp and movement of i */
3660 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003661 if (tx_ring->buffer_info[eop].dma &&
3662 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003663 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003664 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003665 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003666
3667 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003668 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003669 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003670 " TDH <%x>\n"
3671 " TDT <%x>\n"
3672 " next_to_use <%x>\n"
3673 " next_to_clean <%x>\n"
3674 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003675 " time_stamp <%lx>\n"
3676 " next_to_watch <%x>\n"
3677 " jiffies <%lx>\n"
3678 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003679 (unsigned long)((tx_ring - adapter->tx_ring) /
3680 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003681 readl(adapter->hw.hw_addr + tx_ring->tdh),
3682 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003683 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003684 tx_ring->next_to_clean,
3685 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003686 eop,
3687 jiffies,
3688 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003690 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 return cleaned;
3693}
3694
3695/**
3696 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003697 * @adapter: board private structure
3698 * @status_err: receive descriptor status and error fields
3699 * @csum: receive descriptor csum field
3700 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 **/
3702
Auke Koke619d522006-04-14 19:04:52 -07003703static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003705 uint32_t status_err, uint32_t csum,
3706 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003708 uint16_t status = (uint16_t)status_err;
3709 uint8_t errors = (uint8_t)(status_err >> 24);
3710 skb->ip_summed = CHECKSUM_NONE;
3711
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003713 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003715 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003716 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003717 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003718 /* let the stack verify checksum errors */
3719 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 return;
3721 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003722 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003723 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3724 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003725 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003727 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003728 return;
3729 }
3730 /* It must be a TCP or UDP packet with a valid checksum */
3731 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 /* TCP checksum is good */
3733 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003734 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3735 /* IP fragment with UDP payload */
3736 /* Hardware complements the payload checksum, so we undo it
3737 * and then put the value in host order for further stack use.
3738 */
3739 csum = ntohl(csum ^ 0xFFFF);
3740 skb->csum = csum;
Patrick McHardy84fa7932006-08-29 16:44:56 -07003741 skb->ip_summed = CHECKSUM_COMPLETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003743 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744}
3745
3746/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003747 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 * @adapter: board private structure
3749 **/
3750
3751static boolean_t
3752#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003753e1000_clean_rx_irq(struct e1000_adapter *adapter,
3754 struct e1000_rx_ring *rx_ring,
3755 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003757e1000_clean_rx_irq(struct e1000_adapter *adapter,
3758 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759#endif
3760{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 struct net_device *netdev = adapter->netdev;
3762 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003763 struct e1000_rx_desc *rx_desc, *next_rxd;
3764 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 unsigned long flags;
3766 uint32_t length;
3767 uint8_t last_byte;
3768 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003769 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003770 boolean_t cleaned = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771
3772 i = rx_ring->next_to_clean;
3773 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003774 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003776 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07003777 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003778 u8 status;
Auke Kok90fb5132006-11-01 08:47:30 -08003779
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003781 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 break;
3783 (*work_done)++;
3784#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08003785 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003786 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003787 buffer_info->skb = NULL;
3788
Jeff Kirsher30320be2006-03-02 18:21:57 -08003789 prefetch(skb->data - NET_IP_ALIGN);
3790
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003791 if (++i == rx_ring->count) i = 0;
3792 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003793 prefetch(next_rxd);
3794
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003795 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003796
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003797 cleaned = TRUE;
3798 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003799 pci_unmap_single(pdev,
3800 buffer_info->dma,
3801 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 PCI_DMA_FROMDEVICE);
3803
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 length = le16_to_cpu(rx_desc->length);
3805
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003806 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3807 /* All receives must fit into a single buffer */
3808 E1000_DBG("%s: Receive packet consumed multiple"
3809 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07003810 /* recycle */
Auke Kok8fc897b2006-08-28 14:56:16 -07003811 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 goto next_desc;
3813 }
3814
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003815 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003817 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 rx_desc->errors, length, last_byte)) {
3819 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003820 e1000_tbi_adjust_stats(&adapter->hw,
3821 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 length, skb->data);
3823 spin_unlock_irqrestore(&adapter->stats_lock,
3824 flags);
3825 length--;
3826 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07003827 /* recycle */
3828 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 goto next_desc;
3830 }
Auke Kok1cb58212006-04-18 12:31:04 -07003831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832
Jesse Brandeburgd2a1e212006-10-24 14:46:06 -07003833 /* adjust length to remove Ethernet CRC, this must be
3834 * done after the TBI_ACCEPT workaround above */
3835 length -= 4;
3836
Jeff Kirshera292ca62006-01-12 16:51:30 -08003837 /* code added for copybreak, this should improve
3838 * performance for small packets with large amounts
3839 * of reassembly being done in the stack */
3840#define E1000_CB_LENGTH 256
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003841 if (length < E1000_CB_LENGTH) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08003842 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07003843 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003844 if (new_skb) {
3845 skb_reserve(new_skb, NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003846 memcpy(new_skb->data - NET_IP_ALIGN,
3847 skb->data - NET_IP_ALIGN,
3848 length + NET_IP_ALIGN);
3849 /* save the skb in buffer_info as good */
3850 buffer_info->skb = skb;
3851 skb = new_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003852 }
Auke Kok996695d2006-11-01 08:47:50 -08003853 /* else just continue with the old one */
3854 }
Jeff Kirshera292ca62006-01-12 16:51:30 -08003855 /* end copybreak code */
Auke Kok996695d2006-11-01 08:47:50 -08003856 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857
3858 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08003859 e1000_rx_checksum(adapter,
3860 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003861 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003862 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003863
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 skb->protocol = eth_type_trans(skb, netdev);
3865#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003866 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08003867 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003869 le16_to_cpu(rx_desc->special) &
3870 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 } else {
3872 netif_receive_skb(skb);
3873 }
3874#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003875 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003876 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 vlan_hwaccel_rx(skb, adapter->vlgrp,
3878 le16_to_cpu(rx_desc->special) &
3879 E1000_RXD_SPC_VLAN_MASK);
3880 } else {
3881 netif_rx(skb);
3882 }
3883#endif /* CONFIG_E1000_NAPI */
3884 netdev->last_rx = jiffies;
3885
3886next_desc:
3887 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003889 /* return some buffers to hardware, one at a time is too slow */
3890 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3891 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3892 cleaned_count = 0;
3893 }
3894
Jeff Kirsher30320be2006-03-02 18:21:57 -08003895 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003896 rx_desc = next_rxd;
3897 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003900
3901 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3902 if (cleaned_count)
3903 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904
3905 return cleaned;
3906}
3907
3908/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003909 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3910 * @adapter: board private structure
3911 **/
3912
3913static boolean_t
3914#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003915e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3916 struct e1000_rx_ring *rx_ring,
3917 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003918#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003919e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3920 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003921#endif
3922{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003923 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003924 struct net_device *netdev = adapter->netdev;
3925 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003926 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003927 struct e1000_ps_page *ps_page;
3928 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07003929 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003930 unsigned int i, j;
3931 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003932 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003933 boolean_t cleaned = FALSE;
3934
3935 i = rx_ring->next_to_clean;
3936 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003937 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07003938 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003939
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003940 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003941 ps_page = &rx_ring->ps_page[i];
3942 ps_page_dma = &rx_ring->ps_page_dma[i];
3943#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003944 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003945 break;
3946 (*work_done)++;
3947#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003948 skb = buffer_info->skb;
3949
Jeff Kirsher30320be2006-03-02 18:21:57 -08003950 /* in the packet split case this is header only */
3951 prefetch(skb->data - NET_IP_ALIGN);
3952
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003953 if (++i == rx_ring->count) i = 0;
3954 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003955 prefetch(next_rxd);
3956
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003957 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003958
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003959 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003960 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003961 pci_unmap_single(pdev, buffer_info->dma,
3962 buffer_info->length,
3963 PCI_DMA_FROMDEVICE);
3964
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003965 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003966 E1000_DBG("%s: Packet Split buffers didn't pick up"
3967 " the full packet\n", netdev->name);
3968 dev_kfree_skb_irq(skb);
3969 goto next_desc;
3970 }
3971
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003972 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003973 dev_kfree_skb_irq(skb);
3974 goto next_desc;
3975 }
3976
3977 length = le16_to_cpu(rx_desc->wb.middle.length0);
3978
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003979 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003980 E1000_DBG("%s: Last part of the packet spanning"
3981 " multiple descriptors\n", netdev->name);
3982 dev_kfree_skb_irq(skb);
3983 goto next_desc;
3984 }
3985
3986 /* Good Receive */
3987 skb_put(skb, length);
3988
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003989 {
3990 /* this looks ugly, but it seems compiler issues make it
3991 more efficient than reusing j */
3992 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3993
3994 /* page alloc/put takes too long and effects small packet
3995 * throughput, so unsplit small packets and save the alloc/put*/
Auke Kok9e2feac2006-04-14 19:05:18 -07003996 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003997 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07003998 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003999 * kmap_atomic, so we can't hold the mapping
4000 * very long */
4001 pci_dma_sync_single_for_cpu(pdev,
4002 ps_page_dma->ps_page_dma[0],
4003 PAGE_SIZE,
4004 PCI_DMA_FROMDEVICE);
4005 vaddr = kmap_atomic(ps_page->ps_page[0],
4006 KM_SKB_DATA_SOFTIRQ);
4007 memcpy(skb->tail, vaddr, l1);
4008 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
4009 pci_dma_sync_single_for_device(pdev,
4010 ps_page_dma->ps_page_dma[0],
4011 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07004012 /* remove the CRC */
4013 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004014 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004015 goto copydone;
4016 } /* if */
4017 }
Auke Kok90fb5132006-11-01 08:47:30 -08004018
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004019 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08004020 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004021 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004022 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
4023 PAGE_SIZE, PCI_DMA_FROMDEVICE);
4024 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08004025 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
4026 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004027 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004028 skb->len += length;
4029 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07004030 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004031 }
4032
Auke Kokf235a2a2006-07-14 16:14:34 -07004033 /* strip the ethernet crc, problem is we're using pages now so
4034 * this whole operation can get a little cpu intensive */
4035 pskb_trim(skb, skb->len - 4);
4036
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08004037copydone:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004038 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004039 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004040 skb->protocol = eth_type_trans(skb, netdev);
4041
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004042 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004043 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004044 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004045#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004046 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004047 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004048 le16_to_cpu(rx_desc->wb.middle.vlan) &
4049 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004050 } else {
4051 netif_receive_skb(skb);
4052 }
4053#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004054 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004055 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07004056 le16_to_cpu(rx_desc->wb.middle.vlan) &
4057 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004058 } else {
4059 netif_rx(skb);
4060 }
4061#endif /* CONFIG_E1000_NAPI */
4062 netdev->last_rx = jiffies;
4063
4064next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08004065 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004066 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004067
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004068 /* return some buffers to hardware, one at a time is too slow */
4069 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4070 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4071 cleaned_count = 0;
4072 }
4073
Jeff Kirsher30320be2006-03-02 18:21:57 -08004074 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08004075 rx_desc = next_rxd;
4076 buffer_info = next_buffer;
4077
Malli Chilakala683a38f2005-06-17 17:43:25 -07004078 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004079 }
4080 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004081
4082 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4083 if (cleaned_count)
4084 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004085
4086 return cleaned;
4087}
4088
4089/**
4090 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 * @adapter: address of board private structure
4092 **/
4093
4094static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004095e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004096 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08004097 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 struct net_device *netdev = adapter->netdev;
4100 struct pci_dev *pdev = adapter->pdev;
4101 struct e1000_rx_desc *rx_desc;
4102 struct e1000_buffer *buffer_info;
4103 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004104 unsigned int i;
4105 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106
4107 i = rx_ring->next_to_use;
4108 buffer_info = &rx_ring->buffer_info[i];
4109
Jeff Kirshera292ca62006-01-12 16:51:30 -08004110 while (cleaned_count--) {
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004111 skb = buffer_info->skb;
4112 if (skb) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08004113 skb_trim(skb, 0);
4114 goto map_skb;
4115 }
4116
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004117 skb = netdev_alloc_skb(netdev, bufsz);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004118 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004120 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 break;
4122 }
4123
Malli Chilakala26483452005-04-28 19:44:46 -07004124 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4126 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07004127 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
4128 "at %p\n", bufsz, skb->data);
4129 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07004130 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07004131 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 if (!skb) {
4133 dev_kfree_skb(oldskb);
4134 break;
4135 }
Malli Chilakala26483452005-04-28 19:44:46 -07004136
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4138 /* give up */
4139 dev_kfree_skb(skb);
4140 dev_kfree_skb(oldskb);
4141 break; /* while !buffer_info->skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 }
Christoph Hellwigca6f7222006-08-31 14:27:47 -07004143
4144 /* Use new allocation */
4145 dev_kfree_skb(oldskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 /* Make buffer alignment 2 beyond a 16 byte boundary
4148 * this will result in a 16 byte aligned IP header after
4149 * the 14 byte MAC header is removed
4150 */
4151 skb_reserve(skb, NET_IP_ALIGN);
4152
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 buffer_info->skb = skb;
4154 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004155map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 buffer_info->dma = pci_map_single(pdev,
4157 skb->data,
4158 adapter->rx_buffer_len,
4159 PCI_DMA_FROMDEVICE);
4160
Malli Chilakala26483452005-04-28 19:44:46 -07004161 /* Fix for errata 23, can't cross 64kB boundary */
4162 if (!e1000_check_64k_bound(adapter,
4163 (void *)(unsigned long)buffer_info->dma,
4164 adapter->rx_buffer_len)) {
4165 DPRINTK(RX_ERR, ERR,
4166 "dma align check failed: %u bytes at %p\n",
4167 adapter->rx_buffer_len,
4168 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 dev_kfree_skb(skb);
4170 buffer_info->skb = NULL;
4171
Malli Chilakala26483452005-04-28 19:44:46 -07004172 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 adapter->rx_buffer_len,
4174 PCI_DMA_FROMDEVICE);
4175
4176 break; /* while !buffer_info->skb */
4177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 rx_desc = E1000_RX_DESC(*rx_ring, i);
4179 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4180
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004181 if (unlikely(++i == rx_ring->count))
4182 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 buffer_info = &rx_ring->buffer_info[i];
4184 }
4185
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004186 if (likely(rx_ring->next_to_use != i)) {
4187 rx_ring->next_to_use = i;
4188 if (unlikely(i-- == 0))
4189 i = (rx_ring->count - 1);
4190
4191 /* Force memory writes to complete before letting h/w
4192 * know there are new descriptors to fetch. (Only
4193 * applicable for weak-ordered memory model archs,
4194 * such as IA-64). */
4195 wmb();
4196 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198}
4199
4200/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004201 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4202 * @adapter: address of board private structure
4203 **/
4204
4205static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004206e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004207 struct e1000_rx_ring *rx_ring,
4208 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004209{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004210 struct net_device *netdev = adapter->netdev;
4211 struct pci_dev *pdev = adapter->pdev;
4212 union e1000_rx_desc_packet_split *rx_desc;
4213 struct e1000_buffer *buffer_info;
4214 struct e1000_ps_page *ps_page;
4215 struct e1000_ps_page_dma *ps_page_dma;
4216 struct sk_buff *skb;
4217 unsigned int i, j;
4218
4219 i = rx_ring->next_to_use;
4220 buffer_info = &rx_ring->buffer_info[i];
4221 ps_page = &rx_ring->ps_page[i];
4222 ps_page_dma = &rx_ring->ps_page_dma[i];
4223
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004224 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004225 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4226
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004227 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004228 if (j < adapter->rx_ps_pages) {
4229 if (likely(!ps_page->ps_page[j])) {
4230 ps_page->ps_page[j] =
4231 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004232 if (unlikely(!ps_page->ps_page[j])) {
4233 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004234 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004235 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004236 ps_page_dma->ps_page_dma[j] =
4237 pci_map_page(pdev,
4238 ps_page->ps_page[j],
4239 0, PAGE_SIZE,
4240 PCI_DMA_FROMDEVICE);
4241 }
4242 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004243 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004244 * this info.
4245 */
4246 rx_desc->read.buffer_addr[j+1] =
4247 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4248 } else
4249 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004250 }
4251
David S. Miller87f50322006-07-31 22:39:40 -07004252 skb = netdev_alloc_skb(netdev,
Auke Kok90fb5132006-11-01 08:47:30 -08004253 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004254
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004255 if (unlikely(!skb)) {
4256 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004257 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004258 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004259
4260 /* Make buffer alignment 2 beyond a 16 byte boundary
4261 * this will result in a 16 byte aligned IP header after
4262 * the 14 byte MAC header is removed
4263 */
4264 skb_reserve(skb, NET_IP_ALIGN);
4265
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004266 buffer_info->skb = skb;
4267 buffer_info->length = adapter->rx_ps_bsize0;
4268 buffer_info->dma = pci_map_single(pdev, skb->data,
4269 adapter->rx_ps_bsize0,
4270 PCI_DMA_FROMDEVICE);
4271
4272 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4273
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004274 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004275 buffer_info = &rx_ring->buffer_info[i];
4276 ps_page = &rx_ring->ps_page[i];
4277 ps_page_dma = &rx_ring->ps_page_dma[i];
4278 }
4279
4280no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004281 if (likely(rx_ring->next_to_use != i)) {
4282 rx_ring->next_to_use = i;
4283 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4284
4285 /* Force memory writes to complete before letting h/w
4286 * know there are new descriptors to fetch. (Only
4287 * applicable for weak-ordered memory model archs,
4288 * such as IA-64). */
4289 wmb();
4290 /* Hardware increments by 16 bytes, but packet split
4291 * descriptors are 32 bytes...so we increment tail
4292 * twice as much.
4293 */
4294 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4295 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004296}
4297
4298/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4300 * @adapter:
4301 **/
4302
4303static void
4304e1000_smartspeed(struct e1000_adapter *adapter)
4305{
4306 uint16_t phy_status;
4307 uint16_t phy_ctrl;
4308
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004309 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4311 return;
4312
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004313 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 /* If Master/Slave config fault is asserted twice,
4315 * we assume back-to-back */
4316 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004317 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004319 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004321 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4323 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4324 phy_ctrl);
4325 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004326 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4328 &phy_ctrl)) {
4329 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4330 MII_CR_RESTART_AUTO_NEG);
4331 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4332 phy_ctrl);
4333 }
4334 }
4335 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004336 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 /* If still no link, perhaps using 2/3 pair cable */
4338 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4339 phy_ctrl |= CR_1000T_MS_ENABLE;
4340 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004341 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4343 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4344 MII_CR_RESTART_AUTO_NEG);
4345 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4346 }
4347 }
4348 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004349 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 adapter->smartspeed = 0;
4351}
4352
4353/**
4354 * e1000_ioctl -
4355 * @netdev:
4356 * @ifreq:
4357 * @cmd:
4358 **/
4359
4360static int
4361e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4362{
4363 switch (cmd) {
4364 case SIOCGMIIPHY:
4365 case SIOCGMIIREG:
4366 case SIOCSMIIREG:
4367 return e1000_mii_ioctl(netdev, ifr, cmd);
4368 default:
4369 return -EOPNOTSUPP;
4370 }
4371}
4372
4373/**
4374 * e1000_mii_ioctl -
4375 * @netdev:
4376 * @ifreq:
4377 * @cmd:
4378 **/
4379
4380static int
4381e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4382{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004383 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 struct mii_ioctl_data *data = if_mii(ifr);
4385 int retval;
4386 uint16_t mii_reg;
4387 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004388 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004390 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 return -EOPNOTSUPP;
4392
4393 switch (cmd) {
4394 case SIOCGMIIPHY:
4395 data->phy_id = adapter->hw.phy_addr;
4396 break;
4397 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004398 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004400 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004401 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004402 &data->val_out)) {
4403 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004405 }
4406 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 break;
4408 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004409 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004411 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412 return -EFAULT;
4413 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004414 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004415 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004416 mii_reg)) {
4417 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004419 }
Auke Kokdc86d322006-04-18 12:30:51 -07004420 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 switch (data->reg_num) {
4422 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004423 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004425 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 adapter->hw.autoneg = 1;
4427 adapter->hw.autoneg_advertised = 0x2F;
4428 } else {
4429 if (mii_reg & 0x40)
4430 spddplx = SPEED_1000;
4431 else if (mii_reg & 0x2000)
4432 spddplx = SPEED_100;
4433 else
4434 spddplx = SPEED_10;
4435 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004436 ? DUPLEX_FULL :
4437 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 retval = e1000_set_spd_dplx(adapter,
4439 spddplx);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004440 if (retval) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004441 spin_unlock_irqrestore(
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004442 &adapter->stats_lock,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004443 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 }
Auke Kok2db10a02006-06-27 09:06:28 -07004447 if (netif_running(adapter->netdev))
4448 e1000_reinit_locked(adapter);
4449 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 e1000_reset(adapter);
4451 break;
4452 case M88E1000_PHY_SPEC_CTRL:
4453 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004454 if (e1000_phy_reset(&adapter->hw)) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004455 spin_unlock_irqrestore(
4456 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 break;
4460 }
4461 } else {
4462 switch (data->reg_num) {
4463 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004464 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004466 if (netif_running(adapter->netdev))
4467 e1000_reinit_locked(adapter);
4468 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 e1000_reset(adapter);
4470 break;
4471 }
4472 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004473 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 break;
4475 default:
4476 return -EOPNOTSUPP;
4477 }
4478 return E1000_SUCCESS;
4479}
4480
4481void
4482e1000_pci_set_mwi(struct e1000_hw *hw)
4483{
4484 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004485 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004487 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004488 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489}
4490
4491void
4492e1000_pci_clear_mwi(struct e1000_hw *hw)
4493{
4494 struct e1000_adapter *adapter = hw->back;
4495
4496 pci_clear_mwi(adapter->pdev);
4497}
4498
4499void
4500e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4501{
4502 struct e1000_adapter *adapter = hw->back;
4503
4504 pci_read_config_word(adapter->pdev, reg, value);
4505}
4506
4507void
4508e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4509{
4510 struct e1000_adapter *adapter = hw->back;
4511
4512 pci_write_config_word(adapter->pdev, reg, *value);
4513}
4514
Jeff Kirshercaeccb62006-09-27 12:53:57 -07004515int32_t
4516e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4517{
4518 struct e1000_adapter *adapter = hw->back;
4519 uint16_t cap_offset;
4520
4521 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
4522 if (!cap_offset)
4523 return -E1000_ERR_CONFIG;
4524
4525 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
4526
4527 return E1000_SUCCESS;
4528}
4529
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530void
4531e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4532{
4533 outl(value, port);
4534}
4535
4536static void
4537e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4538{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004539 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 uint32_t ctrl, rctl;
4541
4542 e1000_irq_disable(adapter);
4543 adapter->vlgrp = grp;
4544
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004545 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546 /* enable VLAN tag insert/strip */
4547 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4548 ctrl |= E1000_CTRL_VME;
4549 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4550
Auke Kokcd94dd02006-06-27 09:08:22 -07004551 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004552 /* enable VLAN receive filtering */
4553 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4554 rctl |= E1000_RCTL_VFE;
4555 rctl &= ~E1000_RCTL_CFIEN;
4556 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4557 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 } else {
4560 /* disable VLAN tag insert/strip */
4561 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4562 ctrl &= ~E1000_CTRL_VME;
4563 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4564
Auke Kokcd94dd02006-06-27 09:08:22 -07004565 if (adapter->hw.mac_type != e1000_ich8lan) {
Auke Kok90fb5132006-11-01 08:47:30 -08004566 /* disable VLAN filtering */
4567 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4568 rctl &= ~E1000_RCTL_VFE;
4569 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4570 if (adapter->mng_vlan_id !=
4571 (uint16_t)E1000_MNG_VLAN_NONE) {
4572 e1000_vlan_rx_kill_vid(netdev,
4573 adapter->mng_vlan_id);
4574 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4575 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 }
4578
4579 e1000_irq_enable(adapter);
4580}
4581
4582static void
4583e1000_vlan_rx_add_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;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004587
4588 if ((adapter->hw.mng_cookie.status &
4589 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4590 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004591 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 /* add VID to filter table */
4593 index = (vid >> 5) & 0x7F;
4594 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4595 vfta |= (1 << (vid & 0x1F));
4596 e1000_write_vfta(&adapter->hw, index, vfta);
4597}
4598
4599static void
4600e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4601{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004602 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 uint32_t vfta, index;
4604
4605 e1000_irq_disable(adapter);
4606
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004607 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 adapter->vlgrp->vlan_devices[vid] = NULL;
4609
4610 e1000_irq_enable(adapter);
4611
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004612 if ((adapter->hw.mng_cookie.status &
4613 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004614 (vid == adapter->mng_vlan_id)) {
4615 /* release control to f/w */
4616 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004617 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004618 }
4619
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620 /* remove VID from filter table */
4621 index = (vid >> 5) & 0x7F;
4622 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4623 vfta &= ~(1 << (vid & 0x1F));
4624 e1000_write_vfta(&adapter->hw, index, vfta);
4625}
4626
4627static void
4628e1000_restore_vlan(struct e1000_adapter *adapter)
4629{
4630 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4631
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004632 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004634 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4635 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 continue;
4637 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4638 }
4639 }
4640}
4641
4642int
4643e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4644{
4645 adapter->hw.autoneg = 0;
4646
Malli Chilakala69213682005-06-17 17:44:20 -07004647 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004648 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004649 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4650 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4651 return -EINVAL;
4652 }
4653
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004654 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 case SPEED_10 + DUPLEX_HALF:
4656 adapter->hw.forced_speed_duplex = e1000_10_half;
4657 break;
4658 case SPEED_10 + DUPLEX_FULL:
4659 adapter->hw.forced_speed_duplex = e1000_10_full;
4660 break;
4661 case SPEED_100 + DUPLEX_HALF:
4662 adapter->hw.forced_speed_duplex = e1000_100_half;
4663 break;
4664 case SPEED_100 + DUPLEX_FULL:
4665 adapter->hw.forced_speed_duplex = e1000_100_full;
4666 break;
4667 case SPEED_1000 + DUPLEX_FULL:
4668 adapter->hw.autoneg = 1;
4669 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4670 break;
4671 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4672 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004673 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 return -EINVAL;
4675 }
4676 return 0;
4677}
4678
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004679#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004680/* Save/restore 16 or 64 dwords of PCI config space depending on which
4681 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004682 */
4683#define PCIE_CONFIG_SPACE_LEN 256
4684#define PCI_CONFIG_SPACE_LEN 64
4685static int
4686e1000_pci_save_state(struct e1000_adapter *adapter)
4687{
4688 struct pci_dev *dev = adapter->pdev;
4689 int size;
4690 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004691
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004692 if (adapter->hw.mac_type >= e1000_82571)
4693 size = PCIE_CONFIG_SPACE_LEN;
4694 else
4695 size = PCI_CONFIG_SPACE_LEN;
4696
4697 WARN_ON(adapter->config_space != NULL);
4698
4699 adapter->config_space = kmalloc(size, GFP_KERNEL);
4700 if (!adapter->config_space) {
4701 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4702 return -ENOMEM;
4703 }
4704 for (i = 0; i < (size / 4); i++)
4705 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4706 return 0;
4707}
4708
4709static void
4710e1000_pci_restore_state(struct e1000_adapter *adapter)
4711{
4712 struct pci_dev *dev = adapter->pdev;
4713 int size;
4714 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004715
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004716 if (adapter->config_space == NULL)
4717 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004718
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004719 if (adapter->hw.mac_type >= e1000_82571)
4720 size = PCIE_CONFIG_SPACE_LEN;
4721 else
4722 size = PCI_CONFIG_SPACE_LEN;
4723 for (i = 0; i < (size / 4); i++)
4724 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4725 kfree(adapter->config_space);
4726 adapter->config_space = NULL;
4727 return;
4728}
4729#endif /* CONFIG_PM */
4730
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004732e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733{
4734 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004735 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004736 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07004738#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08004739 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07004740#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741
4742 netif_device_detach(netdev);
4743
Auke Kok2db10a02006-06-27 09:06:28 -07004744 if (netif_running(netdev)) {
4745 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07004747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004749#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004750 /* Implement our own version of pci_save_state(pdev) because pci-
4751 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004752 retval = e1000_pci_save_state(adapter);
4753 if (retval)
4754 return retval;
4755#endif
4756
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004758 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 wufc &= ~E1000_WUFC_LNKC;
4760
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004761 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 e1000_setup_rctl(adapter);
4763 e1000_set_multi(netdev);
4764
4765 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg120cd572006-08-31 14:27:46 -07004766 if (wufc & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4768 rctl |= E1000_RCTL_MPE;
4769 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4770 }
4771
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004772 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4774 /* advertise wake from D3Cold */
4775 #define E1000_CTRL_ADVD3WUC 0x00100000
4776 /* phy power management enable */
4777 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4778 ctrl |= E1000_CTRL_ADVD3WUC |
4779 E1000_CTRL_EN_PHY_PWR_MGMT;
4780 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4781 }
4782
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004783 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4785 /* keep the laser running in D3 */
4786 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4787 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4788 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4789 }
4790
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004791 /* Allow time for pending master requests to run */
4792 e1000_disable_pciex_master(&adapter->hw);
4793
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4795 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004796 pci_enable_wake(pdev, PCI_D3hot, 1);
4797 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 } else {
4799 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4800 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07004801 pci_enable_wake(pdev, PCI_D3hot, 0);
4802 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 }
4804
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004805 if (adapter->hw.mac_type >= e1000_82540 &&
4806 adapter->hw.mac_type < e1000_82571 &&
4807 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004809 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 manc |= E1000_MANC_ARP_EN;
4811 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004812 pci_enable_wake(pdev, PCI_D3hot, 1);
4813 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 }
4815 }
4816
Auke Kokcd94dd02006-06-27 09:08:22 -07004817 if (adapter->hw.phy_type == e1000_phy_igp_3)
4818 e1000_phy_powerdown_workaround(&adapter->hw);
4819
Auke Kokedd106f2006-11-06 08:57:12 -08004820 if (netif_running(netdev))
4821 e1000_free_irq(adapter);
4822
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004823 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4824 * would have already happened in close and is redundant. */
4825 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004826
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004828
Auke Kokd0e027d2006-04-14 19:04:40 -07004829 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830
4831 return 0;
4832}
4833
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004834#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835static int
4836e1000_resume(struct pci_dev *pdev)
4837{
4838 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004839 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004840 uint32_t manc, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841
Auke Kokd0e027d2006-04-14 19:04:40 -07004842 pci_set_power_state(pdev, PCI_D0);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004843 e1000_pci_restore_state(adapter);
Auke Kok3d1dd8c2006-08-28 14:56:27 -07004844 if ((err = pci_enable_device(pdev))) {
4845 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
4846 return err;
4847 }
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004848 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849
Auke Kokd0e027d2006-04-14 19:04:40 -07004850 pci_enable_wake(pdev, PCI_D3hot, 0);
4851 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852
Auke Kokedd106f2006-11-06 08:57:12 -08004853 if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
4854 return err;
4855
4856 e1000_power_up_phy(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 e1000_reset(adapter);
4858 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4859
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004860 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 e1000_up(adapter);
4862
4863 netif_device_attach(netdev);
4864
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004865 if (adapter->hw.mac_type >= e1000_82540 &&
4866 adapter->hw.mac_type < e1000_82571 &&
4867 adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 manc = E1000_READ_REG(&adapter->hw, MANC);
4869 manc &= ~(E1000_MANC_ARP_EN);
4870 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4871 }
4872
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004873 /* If the controller is 82573 and f/w is AMT, do not set
4874 * DRV_LOAD until the interface is up. For all other cases,
4875 * let the f/w know that the h/w is now under the control
4876 * of the driver. */
4877 if (adapter->hw.mac_type != e1000_82573 ||
4878 !e1000_check_mng_mode(&adapter->hw))
4879 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004880
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 return 0;
4882}
4883#endif
Auke Kokc653e632006-05-23 13:35:57 -07004884
4885static void e1000_shutdown(struct pci_dev *pdev)
4886{
4887 e1000_suspend(pdev, PMSG_SUSPEND);
4888}
4889
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890#ifdef CONFIG_NET_POLL_CONTROLLER
4891/*
4892 * Polling 'interrupt' - used by things like netconsole to send skbs
4893 * without having to re-enable interrupts. It's not called while
4894 * the interrupt routine is executing.
4895 */
4896static void
Malli Chilakala26483452005-04-28 19:44:46 -07004897e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004899 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07004900
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 disable_irq(adapter->pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +01004902 e1000_intr(adapter->pdev->irq, netdev);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004903 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004904#ifndef CONFIG_E1000_NAPI
4905 adapter->clean_rx(adapter, adapter->rx_ring);
4906#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907 enable_irq(adapter->pdev->irq);
4908}
4909#endif
4910
Auke Kok90267292006-06-08 09:30:24 -07004911/**
4912 * e1000_io_error_detected - called when PCI error is detected
4913 * @pdev: Pointer to PCI device
4914 * @state: The current pci conneection state
4915 *
4916 * This function is called after a PCI bus error affecting
4917 * this device has been detected.
4918 */
4919static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4920{
4921 struct net_device *netdev = pci_get_drvdata(pdev);
4922 struct e1000_adapter *adapter = netdev->priv;
4923
4924 netif_device_detach(netdev);
4925
4926 if (netif_running(netdev))
4927 e1000_down(adapter);
Linas Vepstas72e8d6b2006-09-18 20:58:06 -07004928 pci_disable_device(pdev);
Auke Kok90267292006-06-08 09:30:24 -07004929
4930 /* Request a slot slot reset. */
4931 return PCI_ERS_RESULT_NEED_RESET;
4932}
4933
4934/**
4935 * e1000_io_slot_reset - called after the pci bus has been reset.
4936 * @pdev: Pointer to PCI device
4937 *
4938 * Restart the card from scratch, as if from a cold-boot. Implementation
4939 * resembles the first-half of the e1000_resume routine.
4940 */
4941static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4942{
4943 struct net_device *netdev = pci_get_drvdata(pdev);
4944 struct e1000_adapter *adapter = netdev->priv;
4945
4946 if (pci_enable_device(pdev)) {
4947 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4948 return PCI_ERS_RESULT_DISCONNECT;
4949 }
4950 pci_set_master(pdev);
4951
Linas Vepstasdbf38c92006-09-27 12:54:11 -07004952 pci_enable_wake(pdev, PCI_D3hot, 0);
4953 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok90267292006-06-08 09:30:24 -07004954
Auke Kok90267292006-06-08 09:30:24 -07004955 e1000_reset(adapter);
4956 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4957
4958 return PCI_ERS_RESULT_RECOVERED;
4959}
4960
4961/**
4962 * e1000_io_resume - called when traffic can start flowing again.
4963 * @pdev: Pointer to PCI device
4964 *
4965 * This callback is called when the error recovery driver tells us that
4966 * its OK to resume normal operation. Implementation resembles the
4967 * second-half of the e1000_resume routine.
4968 */
4969static void e1000_io_resume(struct pci_dev *pdev)
4970{
4971 struct net_device *netdev = pci_get_drvdata(pdev);
4972 struct e1000_adapter *adapter = netdev->priv;
4973 uint32_t manc, swsm;
4974
4975 if (netif_running(netdev)) {
4976 if (e1000_up(adapter)) {
4977 printk("e1000: can't bring device back up after reset\n");
4978 return;
4979 }
4980 }
4981
4982 netif_device_attach(netdev);
4983
4984 if (adapter->hw.mac_type >= e1000_82540 &&
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -07004985 adapter->hw.mac_type < e1000_82571 &&
Auke Kok90267292006-06-08 09:30:24 -07004986 adapter->hw.media_type == e1000_media_type_copper) {
4987 manc = E1000_READ_REG(&adapter->hw, MANC);
4988 manc &= ~(E1000_MANC_ARP_EN);
4989 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4990 }
4991
4992 switch (adapter->hw.mac_type) {
4993 case e1000_82573:
4994 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4995 E1000_WRITE_REG(&adapter->hw, SWSM,
4996 swsm | E1000_SWSM_DRV_LOAD);
4997 break;
4998 default:
4999 break;
5000 }
5001
5002 if (netif_running(netdev))
5003 mod_timer(&adapter->watchdog_timer, jiffies);
5004}
5005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006/* e1000_main.c */