blob: 0cf9ff2462ba7757d677a30fa7e0562aaeed7ed9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
3
Auke Kok3d41e302006-04-14 19:05:31 -07004 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 The full GNU General Public License is included in this distribution in the
21 file called LICENSE.
22
23 Contact Information:
24 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070025 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27
28*******************************************************************************/
29
30#include "e1000.h"
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032char e1000_driver_name[] = "e1000";
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010033static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#ifndef CONFIG_E1000_NAPI
35#define DRIVERNAPI
36#else
37#define DRIVERNAPI "-NAPI"
38#endif
Auke Kokdc335d92006-08-16 13:39:09 -070039#define DRV_VERSION "7.1.9-k6"DRIVERNAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -070040char e1000_driver_version[] = DRV_VERSION;
Auke Kok3d41e302006-04-14 19:05:31 -070041static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* e1000_pci_tbl - PCI Device ID Table
44 *
45 * Last entry must be all 0s
46 *
47 * Macro expands to...
48 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
49 */
50static struct pci_device_id e1000_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 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),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800101 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800102 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
Auke Kokae2c3862006-06-27 09:08:30 -0700103 INTEL_E1000_ETHERNET_DEVICE(0x10BA),
104 INTEL_E1000_ETHERNET_DEVICE(0x10BB),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* required last entry */
106 {0,}
107};
108
109MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
110
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100111static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800112 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100113static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800114 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100115static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800116 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100117static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800118 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120/* Local Function Prototypes */
121
122static int e1000_init_module(void);
123static void e1000_exit_module(void);
124static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
125static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400126static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127static int e1000_sw_init(struct e1000_adapter *adapter);
128static int e1000_open(struct net_device *netdev);
129static int e1000_close(struct net_device *netdev);
130static void e1000_configure_tx(struct e1000_adapter *adapter);
131static void e1000_configure_rx(struct e1000_adapter *adapter);
132static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400133static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
134static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
135static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
136 struct e1000_tx_ring *tx_ring);
137static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
138 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139static void e1000_set_multi(struct net_device *netdev);
140static void e1000_update_phy_info(unsigned long data);
141static void e1000_watchdog(unsigned long data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142static void e1000_82547_tx_fifo_stall(unsigned long data);
143static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
144static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
145static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
146static int e1000_set_mac(struct net_device *netdev, void *p);
147static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400148static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
149 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400151static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400153 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700155static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400156 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700157 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400159static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
160 struct e1000_rx_ring *rx_ring);
161static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
162 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400164static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800165 struct e1000_rx_ring *rx_ring,
166 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400167static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800168 struct e1000_rx_ring *rx_ring,
169 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
171static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
172 int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
174static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
175static void e1000_tx_timeout(struct net_device *dev);
Jeff Kirsher87041632006-03-02 18:21:24 -0800176static void e1000_reset_task(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700178static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
179 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
182static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
183static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
184static void e1000_restore_vlan(struct e1000_adapter *adapter);
185
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700186static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Auke Kok6fdfef12006-06-27 09:06:36 -0700187#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188static int e1000_resume(struct pci_dev *pdev);
189#endif
Auke Kokc653e632006-05-23 13:35:57 -0700190static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192#ifdef CONFIG_NET_POLL_CONTROLLER
193/* for netdump / net console */
194static void e1000_netpoll (struct net_device *netdev);
195#endif
196
Auke Kok90267292006-06-08 09:30:24 -0700197static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
198 pci_channel_state_t state);
199static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
200static void e1000_io_resume(struct pci_dev *pdev);
201
202static struct pci_error_handlers e1000_err_handler = {
203 .error_detected = e1000_io_error_detected,
204 .slot_reset = e1000_io_slot_reset,
205 .resume = e1000_io_resume,
206};
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208static struct pci_driver e1000_driver = {
209 .name = e1000_driver_name,
210 .id_table = e1000_pci_tbl,
211 .probe = e1000_probe,
212 .remove = __devexit_p(e1000_remove),
213 /* Power Managment Hooks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .suspend = e1000_suspend,
Auke Kok6fdfef12006-06-27 09:06:36 -0700215#ifdef CONFIG_PM
Auke Kokc653e632006-05-23 13:35:57 -0700216 .resume = e1000_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217#endif
Auke Kok90267292006-06-08 09:30:24 -0700218 .shutdown = e1000_shutdown,
219 .err_handler = &e1000_err_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220};
221
222MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
223MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
224MODULE_LICENSE("GPL");
225MODULE_VERSION(DRV_VERSION);
226
227static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
228module_param(debug, int, 0);
229MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
230
231/**
232 * e1000_init_module - Driver Registration Routine
233 *
234 * e1000_init_module is the first routine called when the driver is
235 * loaded. All it does is register with the PCI subsystem.
236 **/
237
238static int __init
239e1000_init_module(void)
240{
241 int ret;
242 printk(KERN_INFO "%s - version %s\n",
243 e1000_driver_string, e1000_driver_version);
244
245 printk(KERN_INFO "%s\n", e1000_copyright);
246
Jeff Garzik29917622006-08-19 17:48:59 -0400247 ret = pci_register_driver(&e1000_driver);
Tony Luck8b378def2005-07-28 01:07:38 -0700248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 return ret;
250}
251
252module_init(e1000_init_module);
253
254/**
255 * e1000_exit_module - Driver Exit Cleanup Routine
256 *
257 * e1000_exit_module is called just before the driver is removed
258 * from memory.
259 **/
260
261static void __exit
262e1000_exit_module(void)
263{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 pci_unregister_driver(&e1000_driver);
265}
266
267module_exit(e1000_exit_module);
268
Auke Kok2db10a02006-06-27 09:06:28 -0700269static int e1000_request_irq(struct e1000_adapter *adapter)
270{
271 struct net_device *netdev = adapter->netdev;
272 int flags, err = 0;
273
Jeff Garzikc0bc8722006-07-05 14:32:39 -0400274 flags = IRQF_SHARED;
Auke Kok2db10a02006-06-27 09:06:28 -0700275#ifdef CONFIG_PCI_MSI
276 if (adapter->hw.mac_type > e1000_82547_rev_2) {
277 adapter->have_msi = TRUE;
278 if ((err = pci_enable_msi(adapter->pdev))) {
279 DPRINTK(PROBE, ERR,
280 "Unable to allocate MSI interrupt Error: %d\n", err);
281 adapter->have_msi = FALSE;
282 }
283 }
284 if (adapter->have_msi)
Andrew Morton61ef5c02006-07-06 23:58:19 -0700285 flags &= ~IRQF_SHARED;
Auke Kok2db10a02006-06-27 09:06:28 -0700286#endif
287 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
288 netdev->name, netdev)))
289 DPRINTK(PROBE, ERR,
290 "Unable to allocate interrupt Error: %d\n", err);
291
292 return err;
293}
294
295static void e1000_free_irq(struct e1000_adapter *adapter)
296{
297 struct net_device *netdev = adapter->netdev;
298
299 free_irq(adapter->pdev->irq, netdev);
300
301#ifdef CONFIG_PCI_MSI
302 if (adapter->have_msi)
303 pci_disable_msi(adapter->pdev);
304#endif
305}
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307/**
308 * e1000_irq_disable - Mask off interrupt generation on the NIC
309 * @adapter: board private structure
310 **/
311
Auke Koke619d522006-04-14 19:04:52 -0700312static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313e1000_irq_disable(struct e1000_adapter *adapter)
314{
315 atomic_inc(&adapter->irq_sem);
316 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
317 E1000_WRITE_FLUSH(&adapter->hw);
318 synchronize_irq(adapter->pdev->irq);
319}
320
321/**
322 * e1000_irq_enable - Enable default interrupt generation settings
323 * @adapter: board private structure
324 **/
325
Auke Koke619d522006-04-14 19:04:52 -0700326static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327e1000_irq_enable(struct e1000_adapter *adapter)
328{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800329 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
331 E1000_WRITE_FLUSH(&adapter->hw);
332 }
333}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100334
335static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700336e1000_update_mng_vlan(struct e1000_adapter *adapter)
337{
338 struct net_device *netdev = adapter->netdev;
339 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
340 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800341 if (adapter->vlgrp) {
342 if (!adapter->vlgrp->vlan_devices[vid]) {
343 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700344 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
345 e1000_vlan_rx_add_vid(netdev, vid);
346 adapter->mng_vlan_id = vid;
347 } else
348 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800349
350 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
351 (vid != old_vid) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700352 !adapter->vlgrp->vlan_devices[old_vid])
353 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800354 } else
355 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700356 }
357}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800358
359/**
360 * e1000_release_hw_control - release control of the h/w to f/w
361 * @adapter: address of board private structure
362 *
363 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
364 * For ASF and Pass Through versions of f/w this means that the
365 * driver is no longer loaded. For AMT version (only with 82573) i
366 * of the f/w this means that the netowrk i/f is closed.
Auke Kok76c224b2006-05-23 13:36:06 -0700367 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800368 **/
369
Auke Koke619d522006-04-14 19:04:52 -0700370static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800371e1000_release_hw_control(struct e1000_adapter *adapter)
372{
373 uint32_t ctrl_ext;
374 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700375 uint32_t extcnf;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800376
377 /* Let firmware taken over control of h/w */
378 switch (adapter->hw.mac_type) {
379 case e1000_82571:
380 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700381 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800382 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
383 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
384 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
385 break;
386 case e1000_82573:
387 swsm = E1000_READ_REG(&adapter->hw, SWSM);
388 E1000_WRITE_REG(&adapter->hw, SWSM,
389 swsm & ~E1000_SWSM_DRV_LOAD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700390 case e1000_ich8lan:
391 extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
392 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
393 extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
394 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800395 default:
396 break;
397 }
398}
399
400/**
401 * e1000_get_hw_control - get control of the h/w from f/w
402 * @adapter: address of board private structure
403 *
404 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
Auke Kok76c224b2006-05-23 13:36:06 -0700405 * For ASF and Pass Through versions of f/w this means that
406 * the driver is loaded. For AMT version (only with 82573)
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800407 * of the f/w this means that the netowrk i/f is open.
Auke Kok76c224b2006-05-23 13:36:06 -0700408 *
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800409 **/
410
Auke Koke619d522006-04-14 19:04:52 -0700411static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800412e1000_get_hw_control(struct e1000_adapter *adapter)
413{
414 uint32_t ctrl_ext;
415 uint32_t swsm;
Auke Kokcd94dd02006-06-27 09:08:22 -0700416 uint32_t extcnf;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800417 /* Let firmware know the driver has taken over */
418 switch (adapter->hw.mac_type) {
419 case e1000_82571:
420 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700421 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800422 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
423 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
424 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
425 break;
426 case e1000_82573:
427 swsm = E1000_READ_REG(&adapter->hw, SWSM);
428 E1000_WRITE_REG(&adapter->hw, SWSM,
429 swsm | E1000_SWSM_DRV_LOAD);
430 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700431 case e1000_ich8lan:
432 extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
433 E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
434 extcnf | E1000_EXTCNF_CTRL_SWFLAG);
435 break;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800436 default:
437 break;
438 }
439}
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441int
442e1000_up(struct e1000_adapter *adapter)
443{
444 struct net_device *netdev = adapter->netdev;
Auke Kok2db10a02006-06-27 09:06:28 -0700445 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 /* hardware has been reset, we need to reload some things */
448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 e1000_set_multi(netdev);
450
451 e1000_restore_vlan(adapter);
452
453 e1000_configure_tx(adapter);
454 e1000_setup_rctl(adapter);
455 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800456 /* call E1000_DESC_UNUSED which always leaves
457 * at least 1 descriptor unused to make sure
458 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800459 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800460 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800461 adapter->alloc_rx_buf(adapter, ring,
462 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800465 adapter->tx_queue_len = netdev->tx_queue_len;
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 mod_timer(&adapter->watchdog_timer, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469#ifdef CONFIG_E1000_NAPI
470 netif_poll_enable(netdev);
471#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700472 e1000_irq_enable(adapter);
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return 0;
475}
476
Auke Kok79f05bf2006-06-27 09:06:32 -0700477/**
478 * e1000_power_up_phy - restore link in case the phy was powered down
479 * @adapter: address of board private structure
480 *
481 * The phy may be powered down to save power and turn off link when the
482 * driver is unloaded and wake on lan is not enabled (among others)
483 * *** this routine MUST be followed by a call to e1000_reset ***
484 *
485 **/
486
Jesse Brandeburgd6582662006-08-16 13:31:33 -0700487void e1000_power_up_phy(struct e1000_adapter *adapter)
Auke Kok79f05bf2006-06-27 09:06:32 -0700488{
489 uint16_t mii_reg = 0;
490
491 /* Just clear the power down bit to wake the phy back up */
492 if (adapter->hw.media_type == e1000_media_type_copper) {
493 /* according to the manual, the phy will retain its
494 * settings across a power-down/up cycle */
495 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
496 mii_reg &= ~MII_CR_POWER_DOWN;
497 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
498 }
499}
500
501static void e1000_power_down_phy(struct e1000_adapter *adapter)
502{
503 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
504 e1000_check_mng_mode(&adapter->hw);
505 /* Power down the PHY so no link is implied when interface is down
506 * The PHY cannot be powered down if any of the following is TRUE
507 * (a) WoL is enabled
508 * (b) AMT is active
509 * (c) SoL/IDER session is active */
510 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Auke Kokcd94dd02006-06-27 09:08:22 -0700511 adapter->hw.mac_type != e1000_ich8lan &&
Auke Kok79f05bf2006-06-27 09:06:32 -0700512 adapter->hw.media_type == e1000_media_type_copper &&
513 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
514 !mng_mode_enabled &&
515 !e1000_check_phy_reset_block(&adapter->hw)) {
516 uint16_t mii_reg = 0;
517 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
518 mii_reg |= MII_CR_POWER_DOWN;
519 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
520 mdelay(1);
521 }
522}
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524void
525e1000_down(struct e1000_adapter *adapter)
526{
527 struct net_device *netdev = adapter->netdev;
528
529 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 del_timer_sync(&adapter->tx_fifo_stall_timer);
532 del_timer_sync(&adapter->watchdog_timer);
533 del_timer_sync(&adapter->phy_info_timer);
534
535#ifdef CONFIG_E1000_NAPI
536 netif_poll_disable(netdev);
537#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800538 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 adapter->link_speed = 0;
540 adapter->link_duplex = 0;
541 netif_carrier_off(netdev);
542 netif_stop_queue(netdev);
543
544 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400545 e1000_clean_all_tx_rings(adapter);
546 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549void
Auke Kok2db10a02006-06-27 09:06:28 -0700550e1000_reinit_locked(struct e1000_adapter *adapter)
551{
552 WARN_ON(in_interrupt());
553 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
554 msleep(1);
555 e1000_down(adapter);
556 e1000_up(adapter);
557 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
560void
561e1000_reset(struct e1000_adapter *adapter)
562{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700563 uint32_t pba, manc;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700564 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 /* Repartition Pba for greater than 9k mtu
567 * To take effect CTRL.RST is required.
568 */
569
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700570 switch (adapter->hw.mac_type) {
571 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700572 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700573 pba = E1000_PBA_30K;
574 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400575 case e1000_82571:
576 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800577 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400578 pba = E1000_PBA_38K;
579 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700580 case e1000_82573:
581 pba = E1000_PBA_12K;
582 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700583 case e1000_ich8lan:
584 pba = E1000_PBA_8K;
585 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700586 default:
587 pba = E1000_PBA_48K;
588 break;
589 }
590
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800591 if ((adapter->hw.mac_type != e1000_82573) &&
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800592 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700593 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700594
595
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800596 if (adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 adapter->tx_fifo_head = 0;
598 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
599 adapter->tx_fifo_size =
600 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
601 atomic_set(&adapter->tx_fifo_stall, 0);
602 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 E1000_WRITE_REG(&adapter->hw, PBA, pba);
605
606 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800607 /* Set the FC high water mark to 90% of the FIFO size.
608 * Required to clear last 3 LSB */
609 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
Auke Kokcd94dd02006-06-27 09:08:22 -0700610 /* We can't use 90% on small FIFOs because the remainder
611 * would be less than 1 full frame. In this case, we size
612 * it to allow at least a full frame above the high water
613 * mark. */
614 if (pba < E1000_PBA_16K)
615 fc_high_water_mark = (pba * 1024) - 1600;
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800616
617 adapter->hw.fc_high_water = fc_high_water_mark;
618 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800619 if (adapter->hw.mac_type == e1000_80003es2lan)
620 adapter->hw.fc_pause_time = 0xFFFF;
621 else
622 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 adapter->hw.fc_send_xon = 1;
624 adapter->hw.fc = adapter->hw.original_fc;
625
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700626 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800628 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800630 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700632 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
634 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
635
636 e1000_reset_adaptive(&adapter->hw);
637 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok9a53a202006-06-27 09:06:45 -0700638
639 if (!adapter->smart_power_down &&
640 (adapter->hw.mac_type == e1000_82571 ||
641 adapter->hw.mac_type == e1000_82572)) {
642 uint16_t phy_data = 0;
643 /* speed up time to link by disabling smart power down, ignore
644 * the return value of this function because there is nothing
645 * different we would do if it failed */
646 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
647 &phy_data);
648 phy_data &= ~IGP02E1000_PM_SPD;
649 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
650 phy_data);
651 }
652
Auke Kokcd94dd02006-06-27 09:08:22 -0700653 if (adapter->hw.mac_type < e1000_ich8lan)
654 /* FIXME: this code is duplicate and wrong for PCI Express */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700655 if (adapter->en_mng_pt) {
656 manc = E1000_READ_REG(&adapter->hw, MANC);
657 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
658 E1000_WRITE_REG(&adapter->hw, MANC, manc);
659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
662/**
663 * e1000_probe - Device Initialization Routine
664 * @pdev: PCI device information struct
665 * @ent: entry in e1000_pci_tbl
666 *
667 * Returns 0 on success, negative on failure
668 *
669 * e1000_probe initializes an adapter identified by a pci_dev structure.
670 * The OS initialization, configuring of the adapter private structure,
671 * and a hardware reset occur.
672 **/
673
674static int __devinit
675e1000_probe(struct pci_dev *pdev,
676 const struct pci_device_id *ent)
677{
678 struct net_device *netdev;
679 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700680 unsigned long mmio_start, mmio_len;
Auke Kokcd94dd02006-06-27 09:08:22 -0700681 unsigned long flash_start, flash_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 static int cards_found = 0;
Jeff Kirsher84916822006-03-02 18:18:48 -0800684 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700685 int i, err, pci_using_dac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 uint16_t eeprom_data;
687 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800688 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 return err;
690
Auke Kokcd94dd02006-06-27 09:08:22 -0700691 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
692 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 pci_using_dac = 1;
694 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -0700695 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
696 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 E1000_ERR("No usable DMA configuration, aborting\n");
698 return err;
699 }
700 pci_using_dac = 0;
701 }
702
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800703 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 return err;
705
706 pci_set_master(pdev);
707
708 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800709 if (!netdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 err = -ENOMEM;
711 goto err_alloc_etherdev;
712 }
713
714 SET_MODULE_OWNER(netdev);
715 SET_NETDEV_DEV(netdev, &pdev->dev);
716
717 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700718 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 adapter->netdev = netdev;
720 adapter->pdev = pdev;
721 adapter->hw.back = adapter;
722 adapter->msg_enable = (1 << debug) - 1;
723
724 mmio_start = pci_resource_start(pdev, BAR_0);
725 mmio_len = pci_resource_len(pdev, BAR_0);
726
727 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800728 if (!adapter->hw.hw_addr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 err = -EIO;
730 goto err_ioremap;
731 }
732
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800733 for (i = BAR_1; i <= BAR_5; i++) {
734 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800736 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 adapter->hw.io_base = pci_resource_start(pdev, i);
738 break;
739 }
740 }
741
742 netdev->open = &e1000_open;
743 netdev->stop = &e1000_close;
744 netdev->hard_start_xmit = &e1000_xmit_frame;
745 netdev->get_stats = &e1000_get_stats;
746 netdev->set_multicast_list = &e1000_set_multi;
747 netdev->set_mac_address = &e1000_set_mac;
748 netdev->change_mtu = &e1000_change_mtu;
749 netdev->do_ioctl = &e1000_ioctl;
750 e1000_set_ethtool_ops(netdev);
751 netdev->tx_timeout = &e1000_tx_timeout;
752 netdev->watchdog_timeo = 5 * HZ;
753#ifdef CONFIG_E1000_NAPI
754 netdev->poll = &e1000_clean;
755 netdev->weight = 64;
756#endif
757 netdev->vlan_rx_register = e1000_vlan_rx_register;
758 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
759 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
760#ifdef CONFIG_NET_POLL_CONTROLLER
761 netdev->poll_controller = e1000_netpoll;
762#endif
763 strcpy(netdev->name, pci_name(pdev));
764
765 netdev->mem_start = mmio_start;
766 netdev->mem_end = mmio_start + mmio_len;
767 netdev->base_addr = adapter->hw.io_base;
768
769 adapter->bd_number = cards_found;
770
771 /* setup the private structure */
772
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800773 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 goto err_sw_init;
775
Auke Kokcd94dd02006-06-27 09:08:22 -0700776 /* Flash BAR mapping must happen after e1000_sw_init
777 * because it depends on mac_type */
778 if ((adapter->hw.mac_type == e1000_ich8lan) &&
779 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
780 flash_start = pci_resource_start(pdev, 1);
781 flash_len = pci_resource_len(pdev, 1);
782 adapter->hw.flash_address = ioremap(flash_start, flash_len);
783 if (!adapter->hw.flash_address) {
784 err = -EIO;
785 goto err_flashmap;
786 }
787 }
788
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800789 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700790 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
791
Jeff Kirsher84916822006-03-02 18:18:48 -0800792 /* if ksp3, indicate if it's port a being setup */
Auke Kok76c224b2006-05-23 13:36:06 -0700793 if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
794 e1000_ksp3_port_a == 0)
Jeff Kirsher84916822006-03-02 18:18:48 -0800795 adapter->ksp3_port_a = 1;
796 e1000_ksp3_port_a++;
797 /* Reset for multiple KP3 adapters */
798 if (e1000_ksp3_port_a == 4)
799 e1000_ksp3_port_a = 0;
800
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800801 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 netdev->features = NETIF_F_SG |
803 NETIF_F_HW_CSUM |
804 NETIF_F_HW_VLAN_TX |
805 NETIF_F_HW_VLAN_RX |
806 NETIF_F_HW_VLAN_FILTER;
Auke Kokcd94dd02006-06-27 09:08:22 -0700807 if (adapter->hw.mac_type == e1000_ich8lan)
808 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 }
810
811#ifdef NETIF_F_TSO
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800812 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 (adapter->hw.mac_type != e1000_82547))
814 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700815
816#ifdef NETIF_F_TSO_IPV6
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800817 if (adapter->hw.mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700818 netdev->features |= NETIF_F_TSO_IPV6;
819#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800821 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 netdev->features |= NETIF_F_HIGHDMA;
823
Auke Kok76c224b2006-05-23 13:36:06 -0700824 netdev->features |= NETIF_F_LLTX;
825
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700826 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
827
Auke Kokcd94dd02006-06-27 09:08:22 -0700828 /* initialize eeprom parameters */
829
830 if (e1000_init_eeprom_params(&adapter->hw)) {
831 E1000_ERR("EEPROM initialization failed\n");
832 return -EIO;
833 }
834
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800835 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 e1000_reset_hw(&adapter->hw);
839
840 /* make sure the EEPROM is good */
841
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800842 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
844 err = -EIO;
845 goto err_eeprom;
846 }
847
848 /* copy the MAC address out of the EEPROM */
849
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800850 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
852 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400853 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800855 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
857 err = -EIO;
858 goto err_eeprom;
859 }
860
861 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
862
863 e1000_get_bus_info(&adapter->hw);
864
865 init_timer(&adapter->tx_fifo_stall_timer);
866 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
867 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
868
869 init_timer(&adapter->watchdog_timer);
870 adapter->watchdog_timer.function = &e1000_watchdog;
871 adapter->watchdog_timer.data = (unsigned long) adapter;
872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 init_timer(&adapter->phy_info_timer);
874 adapter->phy_info_timer.function = &e1000_update_phy_info;
875 adapter->phy_info_timer.data = (unsigned long) adapter;
876
Jeff Kirsher87041632006-03-02 18:21:24 -0800877 INIT_WORK(&adapter->reset_task,
878 (void (*)(void *))e1000_reset_task, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 /* we're going to reset, so assume we have no link for now */
881
882 netif_carrier_off(netdev);
883 netif_stop_queue(netdev);
884
885 e1000_check_options(adapter);
886
887 /* Initial Wake on LAN setting
888 * If APM wake is enabled in the EEPROM,
889 * enable the ACPI Magic Packet filter
890 */
891
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800892 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 case e1000_82542_rev2_0:
894 case e1000_82542_rev2_1:
895 case e1000_82543:
896 break;
897 case e1000_82544:
898 e1000_read_eeprom(&adapter->hw,
899 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
900 eeprom_apme_mask = E1000_EEPROM_82544_APM;
901 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700902 case e1000_ich8lan:
903 e1000_read_eeprom(&adapter->hw,
904 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
905 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
906 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 case e1000_82546:
908 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500909 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800910 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800911 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 e1000_read_eeprom(&adapter->hw,
913 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
914 break;
915 }
916 /* Fall Through */
917 default:
918 e1000_read_eeprom(&adapter->hw,
919 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
920 break;
921 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800922 if (eeprom_data & eeprom_apme_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 adapter->wol |= E1000_WUFC_MAG;
924
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -0800925 /* print bus type/speed/width info */
926 {
927 struct e1000_hw *hw = &adapter->hw;
928 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
929 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
930 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
931 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
932 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
933 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
934 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
935 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
936 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
937 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
938 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
939 "32-bit"));
940 }
941
942 for (i = 0; i < 6; i++)
943 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 /* reset the hardware with the new settings */
946 e1000_reset(adapter);
947
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800948 /* If the controller is 82573 and f/w is AMT, do not set
949 * DRV_LOAD until the interface is up. For all other cases,
950 * let the f/w know that the h/w is now under the control
951 * of the driver. */
952 if (adapter->hw.mac_type != e1000_82573 ||
953 !e1000_check_mng_mode(&adapter->hw))
954 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 strcpy(netdev->name, "eth%d");
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800957 if ((err = register_netdev(netdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 goto err_register;
959
960 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
961
962 cards_found++;
963 return 0;
964
965err_register:
Auke Kokcd94dd02006-06-27 09:08:22 -0700966 if (adapter->hw.flash_address)
967 iounmap(adapter->hw.flash_address);
968err_flashmap:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969err_sw_init:
970err_eeprom:
971 iounmap(adapter->hw.hw_addr);
972err_ioremap:
973 free_netdev(netdev);
974err_alloc_etherdev:
975 pci_release_regions(pdev);
976 return err;
977}
978
979/**
980 * e1000_remove - Device Removal Routine
981 * @pdev: PCI device information struct
982 *
983 * e1000_remove is called by the PCI subsystem to alert the driver
984 * that it should release a PCI device. The could be caused by a
985 * Hot-Plug event, or because the driver is going to be removed from
986 * memory.
987 **/
988
989static void __devexit
990e1000_remove(struct pci_dev *pdev)
991{
992 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700993 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800994 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400995#ifdef CONFIG_E1000_NAPI
996 int i;
997#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
Jeff Garzikbe2b28e2005-10-04 07:13:43 -0400999 flush_scheduled_work();
1000
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001001 if (adapter->hw.mac_type >= e1000_82540 &&
Auke Kokcd94dd02006-06-27 09:08:22 -07001002 adapter->hw.mac_type != e1000_ich8lan &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 adapter->hw.media_type == e1000_media_type_copper) {
1004 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001005 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 manc |= E1000_MANC_ARP_EN;
1007 E1000_WRITE_REG(&adapter->hw, MANC, manc);
1008 }
1009 }
1010
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001011 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1012 * would have already happened in close and is redundant. */
1013 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001016#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001017 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -08001018 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001019#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001021 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001022 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001024 kfree(adapter->tx_ring);
1025 kfree(adapter->rx_ring);
1026#ifdef CONFIG_E1000_NAPI
1027 kfree(adapter->polling_netdev);
1028#endif
1029
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 iounmap(adapter->hw.hw_addr);
Auke Kokcd94dd02006-06-27 09:08:22 -07001031 if (adapter->hw.flash_address)
1032 iounmap(adapter->hw.flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 pci_release_regions(pdev);
1034
1035 free_netdev(netdev);
1036
1037 pci_disable_device(pdev);
1038}
1039
1040/**
1041 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
1042 * @adapter: board private structure to initialize
1043 *
1044 * e1000_sw_init initializes the Adapter private data structure.
1045 * Fields are initialized based on PCI device information and
1046 * OS network device settings (MTU size).
1047 **/
1048
1049static int __devinit
1050e1000_sw_init(struct e1000_adapter *adapter)
1051{
1052 struct e1000_hw *hw = &adapter->hw;
1053 struct net_device *netdev = adapter->netdev;
1054 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001055#ifdef CONFIG_E1000_NAPI
1056 int i;
1057#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059 /* PCI config space info */
1060
1061 hw->vendor_id = pdev->vendor;
1062 hw->device_id = pdev->device;
1063 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1064 hw->subsystem_id = pdev->subsystem_device;
1065
1066 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1067
1068 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
1069
Auke Kokeb0f8052006-07-14 16:14:48 -07001070 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9e2feac2006-04-14 19:05:18 -07001071 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 hw->max_frame_size = netdev->mtu +
1073 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
1074 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
1075
1076 /* identify the MAC */
1077
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001078 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
1080 return -EIO;
1081 }
1082
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001083 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 default:
1085 break;
1086 case e1000_82541:
1087 case e1000_82547:
1088 case e1000_82541_rev_2:
1089 case e1000_82547_rev_2:
1090 hw->phy_init_script = 1;
1091 break;
1092 }
1093
1094 e1000_set_media_type(hw);
1095
1096 hw->wait_autoneg_complete = FALSE;
1097 hw->tbi_compatibility_en = TRUE;
1098 hw->adaptive_ifs = TRUE;
1099
1100 /* Copper options */
1101
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001102 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 hw->mdix = AUTO_ALL_MODES;
1104 hw->disable_polarity_correction = FALSE;
1105 hw->master_slave = E1000_MASTER_SLAVE;
1106 }
1107
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001108 adapter->num_tx_queues = 1;
1109 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001110
1111 if (e1000_alloc_queues(adapter)) {
1112 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1113 return -ENOMEM;
1114 }
1115
1116#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001117 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001118 adapter->polling_netdev[i].priv = adapter;
1119 adapter->polling_netdev[i].poll = &e1000_clean;
1120 adapter->polling_netdev[i].weight = 64;
1121 dev_hold(&adapter->polling_netdev[i]);
1122 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1123 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001124 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001125#endif
1126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 atomic_set(&adapter->irq_sem, 1);
1128 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 return 0;
1131}
1132
1133/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001134 * e1000_alloc_queues - Allocate memory for all rings
1135 * @adapter: board private structure to initialize
1136 *
1137 * We allocate one ring per queue at run-time since we don't know the
1138 * number of queues at compile-time. The polling_netdev array is
1139 * intended for Multiqueue, but should work fine with a single queue.
1140 **/
1141
1142static int __devinit
1143e1000_alloc_queues(struct e1000_adapter *adapter)
1144{
1145 int size;
1146
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001147 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001148 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1149 if (!adapter->tx_ring)
1150 return -ENOMEM;
1151 memset(adapter->tx_ring, 0, size);
1152
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001153 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001154 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1155 if (!adapter->rx_ring) {
1156 kfree(adapter->tx_ring);
1157 return -ENOMEM;
1158 }
1159 memset(adapter->rx_ring, 0, size);
1160
1161#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001162 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001163 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1164 if (!adapter->polling_netdev) {
1165 kfree(adapter->tx_ring);
1166 kfree(adapter->rx_ring);
1167 return -ENOMEM;
1168 }
1169 memset(adapter->polling_netdev, 0, size);
1170#endif
1171
1172 return E1000_SUCCESS;
1173}
1174
1175/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 * e1000_open - Called when a network interface is made active
1177 * @netdev: network interface device structure
1178 *
1179 * Returns 0 on success, negative value on failure
1180 *
1181 * The open entry point is called when a network interface is made
1182 * active by the system (IFF_UP). At this point all resources needed
1183 * for transmit and receive operations are allocated, the interrupt
1184 * handler is registered with the OS, the watchdog timer is started,
1185 * and the stack is notified that the interface is ready.
1186 **/
1187
1188static int
1189e1000_open(struct net_device *netdev)
1190{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001191 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 int err;
1193
Auke Kok2db10a02006-06-27 09:06:28 -07001194 /* disallow open during test */
1195 if (test_bit(__E1000_DRIVER_TESTING, &adapter->flags))
1196 return -EBUSY;
1197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 /* allocate transmit descriptors */
1199
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001200 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 goto err_setup_tx;
1202
1203 /* allocate receive descriptors */
1204
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001205 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 goto err_setup_rx;
1207
Auke Kok2db10a02006-06-27 09:06:28 -07001208 err = e1000_request_irq(adapter);
1209 if (err)
1210 goto err_up;
1211
Auke Kok79f05bf2006-06-27 09:06:32 -07001212 e1000_power_up_phy(adapter);
1213
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001214 if ((err = e1000_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001216 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001217 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001218 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1219 e1000_update_mng_vlan(adapter);
1220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001222 /* If AMT is enabled, let the firmware know that the network
1223 * interface is now open */
1224 if (adapter->hw.mac_type == e1000_82573 &&
1225 e1000_check_mng_mode(&adapter->hw))
1226 e1000_get_hw_control(adapter);
1227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 return E1000_SUCCESS;
1229
1230err_up:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001231 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001233 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234err_setup_tx:
1235 e1000_reset(adapter);
1236
1237 return err;
1238}
1239
1240/**
1241 * e1000_close - Disables a network interface
1242 * @netdev: network interface device structure
1243 *
1244 * Returns 0, this is not allowed to fail
1245 *
1246 * The close entry point is called when an interface is de-activated
1247 * by the OS. The hardware is still under the drivers control, but
1248 * needs to be disabled. A global MAC reset is issued to stop the
1249 * hardware, and all transmit and receive resources are freed.
1250 **/
1251
1252static int
1253e1000_close(struct net_device *netdev)
1254{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001255 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Auke Kok2db10a02006-06-27 09:06:28 -07001257 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 e1000_down(adapter);
Auke Kok79f05bf2006-06-27 09:06:32 -07001259 e1000_power_down_phy(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001260 e1000_free_irq(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001262 e1000_free_all_tx_resources(adapter);
1263 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001265 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001266 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1267 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1268 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001269
1270 /* If AMT is enabled, let the firmware know that the network
1271 * interface is now closed */
1272 if (adapter->hw.mac_type == e1000_82573 &&
1273 e1000_check_mng_mode(&adapter->hw))
1274 e1000_release_hw_control(adapter);
1275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 return 0;
1277}
1278
1279/**
1280 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1281 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001282 * @start: address of beginning of memory
1283 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 **/
Auke Koke619d522006-04-14 19:04:52 -07001285static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286e1000_check_64k_bound(struct e1000_adapter *adapter,
1287 void *start, unsigned long len)
1288{
1289 unsigned long begin = (unsigned long) start;
1290 unsigned long end = begin + len;
1291
Malli Chilakala26483452005-04-28 19:44:46 -07001292 /* First rev 82545 and 82546 need to not allow any memory
1293 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001295 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1297 }
1298
1299 return TRUE;
1300}
1301
1302/**
1303 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1304 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001305 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 *
1307 * Return 0 on success, negative on failure
1308 **/
1309
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001310static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001311e1000_setup_tx_resources(struct e1000_adapter *adapter,
1312 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 struct pci_dev *pdev = adapter->pdev;
1315 int size;
1316
1317 size = sizeof(struct e1000_buffer) * txdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001318 txdr->buffer_info = vmalloc(size);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001319 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001320 DPRINTK(PROBE, ERR,
1321 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 return -ENOMEM;
1323 }
1324 memset(txdr->buffer_info, 0, size);
1325
1326 /* round up to nearest 4K */
1327
1328 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1329 E1000_ROUNDUP(txdr->size, 4096);
1330
1331 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001332 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001335 DPRINTK(PROBE, ERR,
1336 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 return -ENOMEM;
1338 }
1339
Malli Chilakala26483452005-04-28 19:44:46 -07001340 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1342 void *olddesc = txdr->desc;
1343 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001344 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1345 "at %p\n", txdr->size, txdr->desc);
1346 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001348 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001349 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1351 goto setup_tx_desc_die;
1352 }
1353
1354 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1355 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001356 pci_free_consistent(pdev, txdr->size, txdr->desc,
1357 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1359 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001360 "Unable to allocate aligned memory "
1361 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 vfree(txdr->buffer_info);
1363 return -ENOMEM;
1364 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001365 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1367 }
1368 }
1369 memset(txdr->desc, 0, txdr->size);
1370
1371 txdr->next_to_use = 0;
1372 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001373 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
1375 return 0;
1376}
1377
1378/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001379 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1380 * (Descriptors) for all queues
1381 * @adapter: board private structure
1382 *
1383 * If this function returns with an error, then it's possible one or
1384 * more of the rings is populated (while the rest are not). It is the
1385 * callers duty to clean those orphaned rings.
1386 *
1387 * Return 0 on success, negative on failure
1388 **/
1389
1390int
1391e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1392{
1393 int i, err = 0;
1394
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001395 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001396 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1397 if (err) {
1398 DPRINTK(PROBE, ERR,
1399 "Allocation for Tx Queue %u failed\n", i);
1400 break;
1401 }
1402 }
1403
1404 return err;
1405}
1406
1407/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1409 * @adapter: board private structure
1410 *
1411 * Configure the Tx unit of the MAC after a reset.
1412 **/
1413
1414static void
1415e1000_configure_tx(struct e1000_adapter *adapter)
1416{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001417 uint64_t tdba;
1418 struct e1000_hw *hw = &adapter->hw;
1419 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001420 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
1422 /* Setup the HW Tx Head and Tail descriptor pointers */
1423
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001424 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001425 case 1:
1426 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001427 tdba = adapter->tx_ring[0].dma;
1428 tdlen = adapter->tx_ring[0].count *
1429 sizeof(struct e1000_tx_desc);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001430 E1000_WRITE_REG(hw, TDLEN, tdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001431 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1432 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001433 E1000_WRITE_REG(hw, TDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001434 E1000_WRITE_REG(hw, TDH, 0);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001435 adapter->tx_ring[0].tdh = E1000_TDH;
1436 adapter->tx_ring[0].tdt = E1000_TDT;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001437 break;
1438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
1440 /* Set the default values for the Tx Inter Packet Gap timer */
1441
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001442 if (hw->media_type == e1000_media_type_fiber ||
1443 hw->media_type == e1000_media_type_internal_serdes)
1444 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1445 else
1446 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1447
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001448 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 case e1000_82542_rev2_0:
1450 case e1000_82542_rev2_1:
1451 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001452 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1453 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001455 case e1000_80003es2lan:
1456 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1457 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1458 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001460 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1461 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1462 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001464 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1465 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001466 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 /* Set the Tx Interrupt Delay register */
1469
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001470 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1471 if (hw->mac_type >= e1000_82540)
1472 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 /* Program the Transmit Control Register */
1475
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001476 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001479 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1481
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001482#ifdef DISABLE_MULR
1483 /* disable Multiple Reads for debugging */
1484 tctl &= ~E1000_TCTL_MULR;
1485#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001487 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1488 tarc = E1000_READ_REG(hw, TARC0);
1489 tarc |= ((1 << 25) | (1 << 21));
1490 E1000_WRITE_REG(hw, TARC0, tarc);
1491 tarc = E1000_READ_REG(hw, TARC1);
1492 tarc |= (1 << 25);
1493 if (tctl & E1000_TCTL_MULR)
1494 tarc &= ~(1 << 28);
1495 else
1496 tarc |= (1 << 28);
1497 E1000_WRITE_REG(hw, TARC1, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001498 } else if (hw->mac_type == e1000_80003es2lan) {
1499 tarc = E1000_READ_REG(hw, TARC0);
1500 tarc |= 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08001501 E1000_WRITE_REG(hw, TARC0, tarc);
1502 tarc = E1000_READ_REG(hw, TARC1);
1503 tarc |= 1;
1504 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001505 }
1506
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001507 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509 /* Setup Transmit Descriptor Settings for eop descriptor */
1510 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1511 E1000_TXD_CMD_IFCS;
1512
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001513 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1515 else
1516 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1517
1518 /* Cache if we're 82544 running in PCI-X because we'll
1519 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001520 if (hw->mac_type == e1000_82544 &&
1521 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001523
1524 E1000_WRITE_REG(hw, TCTL, tctl);
1525
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526}
1527
1528/**
1529 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1530 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001531 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 *
1533 * Returns 0 on success, negative on failure
1534 **/
1535
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001536static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001537e1000_setup_rx_resources(struct e1000_adapter *adapter,
1538 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001541 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 size = sizeof(struct e1000_buffer) * rxdr->count;
Auke Kokcd94dd02006-06-27 09:08:22 -07001544 rxdr->buffer_info = vmalloc(size);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001545 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001546 DPRINTK(PROBE, ERR,
1547 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 return -ENOMEM;
1549 }
1550 memset(rxdr->buffer_info, 0, size);
1551
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001552 size = sizeof(struct e1000_ps_page) * rxdr->count;
1553 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001554 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001555 vfree(rxdr->buffer_info);
1556 DPRINTK(PROBE, ERR,
1557 "Unable to allocate memory for the receive descriptor ring\n");
1558 return -ENOMEM;
1559 }
1560 memset(rxdr->ps_page, 0, size);
1561
1562 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1563 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001564 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001565 vfree(rxdr->buffer_info);
1566 kfree(rxdr->ps_page);
1567 DPRINTK(PROBE, ERR,
1568 "Unable to allocate memory for the receive descriptor ring\n");
1569 return -ENOMEM;
1570 }
1571 memset(rxdr->ps_page_dma, 0, size);
1572
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001573 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001574 desc_len = sizeof(struct e1000_rx_desc);
1575 else
1576 desc_len = sizeof(union e1000_rx_desc_packet_split);
1577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 /* Round up to nearest 4K */
1579
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001580 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 E1000_ROUNDUP(rxdr->size, 4096);
1582
1583 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1584
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001585 if (!rxdr->desc) {
1586 DPRINTK(PROBE, ERR,
1587 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001590 kfree(rxdr->ps_page);
1591 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 return -ENOMEM;
1593 }
1594
Malli Chilakala26483452005-04-28 19:44:46 -07001595 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1597 void *olddesc = rxdr->desc;
1598 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001599 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1600 "at %p\n", rxdr->size, rxdr->desc);
1601 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001603 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001604 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001606 DPRINTK(PROBE, ERR,
1607 "Unable to allocate memory "
1608 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 goto setup_rx_desc_die;
1610 }
1611
1612 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1613 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001614 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1615 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001617 DPRINTK(PROBE, ERR,
1618 "Unable to allocate aligned memory "
1619 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001620 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001622 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1624 }
1625 }
1626 memset(rxdr->desc, 0, rxdr->size);
1627
1628 rxdr->next_to_clean = 0;
1629 rxdr->next_to_use = 0;
1630
1631 return 0;
1632}
1633
1634/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001635 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1636 * (Descriptors) for all queues
1637 * @adapter: board private structure
1638 *
1639 * If this function returns with an error, then it's possible one or
1640 * more of the rings is populated (while the rest are not). It is the
1641 * callers duty to clean those orphaned rings.
1642 *
1643 * Return 0 on success, negative on failure
1644 **/
1645
1646int
1647e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1648{
1649 int i, err = 0;
1650
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001651 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001652 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1653 if (err) {
1654 DPRINTK(PROBE, ERR,
1655 "Allocation for Rx Queue %u failed\n", i);
1656 break;
1657 }
1658 }
1659
1660 return err;
1661}
1662
1663/**
Malli Chilakala26483452005-04-28 19:44:46 -07001664 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 * @adapter: Board private structure
1666 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001667#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1668 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669static void
1670e1000_setup_rctl(struct e1000_adapter *adapter)
1671{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001672 uint32_t rctl, rfctl;
1673 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001674#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001675 uint32_t pages = 0;
1676#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
1678 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1679
1680 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1681
1682 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1683 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1684 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1685
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001686 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 rctl |= E1000_RCTL_SBP;
1688 else
1689 rctl &= ~E1000_RCTL_SBP;
1690
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001691 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1692 rctl &= ~E1000_RCTL_LPE;
1693 else
1694 rctl |= E1000_RCTL_LPE;
1695
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001697 rctl &= ~E1000_RCTL_SZ_4096;
1698 rctl |= E1000_RCTL_BSEX;
1699 switch (adapter->rx_buffer_len) {
1700 case E1000_RXBUFFER_256:
1701 rctl |= E1000_RCTL_SZ_256;
1702 rctl &= ~E1000_RCTL_BSEX;
1703 break;
1704 case E1000_RXBUFFER_512:
1705 rctl |= E1000_RCTL_SZ_512;
1706 rctl &= ~E1000_RCTL_BSEX;
1707 break;
1708 case E1000_RXBUFFER_1024:
1709 rctl |= E1000_RCTL_SZ_1024;
1710 rctl &= ~E1000_RCTL_BSEX;
1711 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001712 case E1000_RXBUFFER_2048:
1713 default:
1714 rctl |= E1000_RCTL_SZ_2048;
1715 rctl &= ~E1000_RCTL_BSEX;
1716 break;
1717 case E1000_RXBUFFER_4096:
1718 rctl |= E1000_RCTL_SZ_4096;
1719 break;
1720 case E1000_RXBUFFER_8192:
1721 rctl |= E1000_RCTL_SZ_8192;
1722 break;
1723 case E1000_RXBUFFER_16384:
1724 rctl |= E1000_RCTL_SZ_16384;
1725 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001726 }
1727
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001728#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001729 /* 82571 and greater support packet-split where the protocol
1730 * header is placed in skb->data and the packet data is
1731 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1732 * In the case of a non-split, skb->data is linearly filled,
1733 * followed by the page buffers. Therefore, skb->data is
1734 * sized to hold the largest protocol header.
1735 */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001736 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1737 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1738 PAGE_SIZE <= 16384)
1739 adapter->rx_ps_pages = pages;
1740 else
1741 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001742#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001743 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001744 /* Configure extra packet-split registers */
1745 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1746 rfctl |= E1000_RFCTL_EXTEN;
1747 /* disable IPv6 packet split support */
1748 rfctl |= E1000_RFCTL_IPV6_DIS;
1749 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1750
Auke Kok7dfee0c2006-06-27 09:07:50 -07001751 rctl |= E1000_RCTL_DTYP_PS;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001752
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001753 psrctl |= adapter->rx_ps_bsize0 >>
1754 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001755
1756 switch (adapter->rx_ps_pages) {
1757 case 3:
1758 psrctl |= PAGE_SIZE <<
1759 E1000_PSRCTL_BSIZE3_SHIFT;
1760 case 2:
1761 psrctl |= PAGE_SIZE <<
1762 E1000_PSRCTL_BSIZE2_SHIFT;
1763 case 1:
1764 psrctl |= PAGE_SIZE >>
1765 E1000_PSRCTL_BSIZE1_SHIFT;
1766 break;
1767 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001768
1769 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 }
1771
1772 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1773}
1774
1775/**
1776 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1777 * @adapter: board private structure
1778 *
1779 * Configure the Rx unit of the MAC after a reset.
1780 **/
1781
1782static void
1783e1000_configure_rx(struct e1000_adapter *adapter)
1784{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001785 uint64_t rdba;
1786 struct e1000_hw *hw = &adapter->hw;
1787 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001788
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001789 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001790 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001791 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001792 sizeof(union e1000_rx_desc_packet_split);
1793 adapter->clean_rx = e1000_clean_rx_irq_ps;
1794 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1795 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001796 rdlen = adapter->rx_ring[0].count *
1797 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001798 adapter->clean_rx = e1000_clean_rx_irq;
1799 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
1802 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001803 rctl = E1000_READ_REG(hw, RCTL);
1804 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
1806 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001807 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001809 if (hw->mac_type >= e1000_82540) {
1810 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001811 if (adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001812 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 1000000000 / (adapter->itr * 256));
1814 }
1815
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001816 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001817 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001818 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07001819 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001820#ifdef CONFIG_E1000_NAPI
1821 /* Auto-Mask interrupts upon ICR read. */
1822 ctrl_ext |= E1000_CTRL_EXT_IAME;
1823#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001824 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001825 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001826 E1000_WRITE_FLUSH(hw);
1827 }
1828
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001829 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1830 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001831 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001832 case 1:
1833 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001834 rdba = adapter->rx_ring[0].dma;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001835 E1000_WRITE_REG(hw, RDLEN, rdlen);
Auke Kok4ca213a2006-06-27 09:07:08 -07001836 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1837 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001838 E1000_WRITE_REG(hw, RDT, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07001839 E1000_WRITE_REG(hw, RDH, 0);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001840 adapter->rx_ring[0].rdh = E1000_RDH;
1841 adapter->rx_ring[0].rdt = E1000_RDT;
1842 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001843 }
1844
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001846 if (hw->mac_type >= e1000_82543) {
1847 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001848 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001849 rxcsum |= E1000_RXCSUM_TUOFL;
1850
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001851 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001852 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001853 if ((hw->mac_type >= e1000_82571) &&
1854 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001855 rxcsum |= E1000_RXCSUM_IPPCSE;
1856 }
1857 } else {
1858 rxcsum &= ~E1000_RXCSUM_TUOFL;
1859 /* don't need to clear IPPCSE as it defaults to 0 */
1860 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001861 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 }
1863
1864 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001865 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866}
1867
1868/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001869 * e1000_free_tx_resources - Free Tx Resources per Queue
1870 * @adapter: board private structure
1871 * @tx_ring: Tx descriptor ring for a specific queue
1872 *
1873 * Free all transmit software resources
1874 **/
1875
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001876static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001877e1000_free_tx_resources(struct e1000_adapter *adapter,
1878 struct e1000_tx_ring *tx_ring)
1879{
1880 struct pci_dev *pdev = adapter->pdev;
1881
1882 e1000_clean_tx_ring(adapter, tx_ring);
1883
1884 vfree(tx_ring->buffer_info);
1885 tx_ring->buffer_info = NULL;
1886
1887 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1888
1889 tx_ring->desc = NULL;
1890}
1891
1892/**
1893 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 * @adapter: board private structure
1895 *
1896 * Free all transmit software resources
1897 **/
1898
1899void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001900e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001902 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001904 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001905 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906}
1907
Auke Koke619d522006-04-14 19:04:52 -07001908static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1910 struct e1000_buffer *buffer_info)
1911{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001912 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001913 pci_unmap_page(adapter->pdev,
1914 buffer_info->dma,
1915 buffer_info->length,
1916 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08001918 if (buffer_info->skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 dev_kfree_skb_any(buffer_info->skb);
Jeff Kirsher8241e352006-01-12 16:51:34 -08001920 memset(buffer_info, 0, sizeof(struct e1000_buffer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921}
1922
1923/**
1924 * e1000_clean_tx_ring - Free Tx Buffers
1925 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001926 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 **/
1928
1929static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001930e1000_clean_tx_ring(struct e1000_adapter *adapter,
1931 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 struct e1000_buffer *buffer_info;
1934 unsigned long size;
1935 unsigned int i;
1936
1937 /* Free all the Tx ring sk_buffs */
1938
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001939 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 buffer_info = &tx_ring->buffer_info[i];
1941 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1942 }
1943
1944 size = sizeof(struct e1000_buffer) * tx_ring->count;
1945 memset(tx_ring->buffer_info, 0, size);
1946
1947 /* Zero out the descriptor ring */
1948
1949 memset(tx_ring->desc, 0, tx_ring->size);
1950
1951 tx_ring->next_to_use = 0;
1952 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001953 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001955 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1956 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1957}
1958
1959/**
1960 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1961 * @adapter: board private structure
1962 **/
1963
1964static void
1965e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1966{
1967 int i;
1968
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001969 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001970 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971}
1972
1973/**
1974 * e1000_free_rx_resources - Free Rx Resources
1975 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001976 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 *
1978 * Free all receive software resources
1979 **/
1980
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001981static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001982e1000_free_rx_resources(struct e1000_adapter *adapter,
1983 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 struct pci_dev *pdev = adapter->pdev;
1986
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001987 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
1989 vfree(rx_ring->buffer_info);
1990 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001991 kfree(rx_ring->ps_page);
1992 rx_ring->ps_page = NULL;
1993 kfree(rx_ring->ps_page_dma);
1994 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
1996 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1997
1998 rx_ring->desc = NULL;
1999}
2000
2001/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002002 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002004 *
2005 * Free all receive software resources
2006 **/
2007
2008void
2009e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2010{
2011 int i;
2012
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002013 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002014 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2015}
2016
2017/**
2018 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2019 * @adapter: board private structure
2020 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 **/
2022
2023static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002024e1000_clean_rx_ring(struct e1000_adapter *adapter,
2025 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002028 struct e1000_ps_page *ps_page;
2029 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 struct pci_dev *pdev = adapter->pdev;
2031 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002032 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
2034 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002035 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002037 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 pci_unmap_single(pdev,
2039 buffer_info->dma,
2040 buffer_info->length,
2041 PCI_DMA_FROMDEVICE);
2042
2043 dev_kfree_skb(buffer_info->skb);
2044 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002045 }
2046 ps_page = &rx_ring->ps_page[i];
2047 ps_page_dma = &rx_ring->ps_page_dma[i];
2048 for (j = 0; j < adapter->rx_ps_pages; j++) {
2049 if (!ps_page->ps_page[j]) break;
2050 pci_unmap_page(pdev,
2051 ps_page_dma->ps_page_dma[j],
2052 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2053 ps_page_dma->ps_page_dma[j] = 0;
2054 put_page(ps_page->ps_page[j]);
2055 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 }
2057 }
2058
2059 size = sizeof(struct e1000_buffer) * rx_ring->count;
2060 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002061 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2062 memset(rx_ring->ps_page, 0, size);
2063 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2064 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
2066 /* Zero out the descriptor ring */
2067
2068 memset(rx_ring->desc, 0, rx_ring->size);
2069
2070 rx_ring->next_to_clean = 0;
2071 rx_ring->next_to_use = 0;
2072
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002073 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2074 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2075}
2076
2077/**
2078 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2079 * @adapter: board private structure
2080 **/
2081
2082static void
2083e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2084{
2085 int i;
2086
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002087 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002088 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
2091/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2092 * and memory write and invalidate disabled for certain operations
2093 */
2094static void
2095e1000_enter_82542_rst(struct e1000_adapter *adapter)
2096{
2097 struct net_device *netdev = adapter->netdev;
2098 uint32_t rctl;
2099
2100 e1000_pci_clear_mwi(&adapter->hw);
2101
2102 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2103 rctl |= E1000_RCTL_RST;
2104 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2105 E1000_WRITE_FLUSH(&adapter->hw);
2106 mdelay(5);
2107
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002108 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002109 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110}
2111
2112static void
2113e1000_leave_82542_rst(struct e1000_adapter *adapter)
2114{
2115 struct net_device *netdev = adapter->netdev;
2116 uint32_t rctl;
2117
2118 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2119 rctl &= ~E1000_RCTL_RST;
2120 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2121 E1000_WRITE_FLUSH(&adapter->hw);
2122 mdelay(5);
2123
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002124 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 e1000_pci_set_mwi(&adapter->hw);
2126
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002127 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002128 /* No need to loop, because 82542 supports only 1 queue */
2129 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002130 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002131 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 }
2133}
2134
2135/**
2136 * e1000_set_mac - Change the Ethernet Address of the NIC
2137 * @netdev: network interface device structure
2138 * @p: pointer to an address structure
2139 *
2140 * Returns 0 on success, negative on failure
2141 **/
2142
2143static int
2144e1000_set_mac(struct net_device *netdev, void *p)
2145{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002146 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 struct sockaddr *addr = p;
2148
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002149 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 return -EADDRNOTAVAIL;
2151
2152 /* 82542 2.0 needs to be in reset to write receive address registers */
2153
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002154 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 e1000_enter_82542_rst(adapter);
2156
2157 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2158 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2159
2160 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2161
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002162 /* With 82571 controllers, LAA may be overwritten (with the default)
2163 * due to controller reset from the other port. */
2164 if (adapter->hw.mac_type == e1000_82571) {
2165 /* activate the work around */
2166 adapter->hw.laa_is_present = 1;
2167
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002168 /* Hold a copy of the LAA in RAR[14] This is done so that
2169 * between the time RAR[0] gets clobbered and the time it
2170 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002171 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002172 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002173 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002174 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002175 E1000_RAR_ENTRIES - 1);
2176 }
2177
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002178 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 e1000_leave_82542_rst(adapter);
2180
2181 return 0;
2182}
2183
2184/**
2185 * e1000_set_multi - Multicast and Promiscuous mode set
2186 * @netdev: network interface device structure
2187 *
2188 * The set_multi entry point is called whenever the multicast address
2189 * list or the network interface flags are updated. This routine is
2190 * responsible for configuring the hardware for proper multicast,
2191 * promiscuous mode, and all-multi behavior.
2192 **/
2193
2194static void
2195e1000_set_multi(struct net_device *netdev)
2196{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002197 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 struct e1000_hw *hw = &adapter->hw;
2199 struct dev_mc_list *mc_ptr;
2200 uint32_t rctl;
2201 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002202 int i, rar_entries = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -07002203 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2204 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2205 E1000_NUM_MTA_REGISTERS;
2206
2207 if (adapter->hw.mac_type == e1000_ich8lan)
2208 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002210 /* reserve RAR[14] for LAA over-write work-around */
2211 if (adapter->hw.mac_type == e1000_82571)
2212 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Malli Chilakala26483452005-04-28 19:44:46 -07002214 /* Check for Promiscuous and All Multicast modes */
2215
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 rctl = E1000_READ_REG(hw, RCTL);
2217
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002218 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002220 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 rctl |= E1000_RCTL_MPE;
2222 rctl &= ~E1000_RCTL_UPE;
2223 } else {
2224 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2225 }
2226
2227 E1000_WRITE_REG(hw, RCTL, rctl);
2228
2229 /* 82542 2.0 needs to be in reset to write receive address registers */
2230
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002231 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 e1000_enter_82542_rst(adapter);
2233
2234 /* load the first 14 multicast address into the exact filters 1-14
2235 * RAR 0 is used for the station MAC adddress
2236 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002237 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 */
2239 mc_ptr = netdev->mc_list;
2240
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002241 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002242 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2244 mc_ptr = mc_ptr->next;
2245 } else {
2246 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002247 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002249 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 }
2251 }
2252
2253 /* clear the old settings from the multicast hash table */
2254
Auke Kokcd94dd02006-06-27 09:08:22 -07002255 for (i = 0; i < mta_reg_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07002257 E1000_WRITE_FLUSH(hw);
2258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
2260 /* load any remaining addresses into the hash table */
2261
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002262 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2264 e1000_mta_set(hw, hash_value);
2265 }
2266
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002267 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269}
2270
2271/* Need to wait a few seconds after link up to get diagnostic information from
2272 * the phy */
2273
2274static void
2275e1000_update_phy_info(unsigned long data)
2276{
2277 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2278 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2279}
2280
2281/**
2282 * e1000_82547_tx_fifo_stall - Timer Call-back
2283 * @data: pointer to adapter cast into an unsigned long
2284 **/
2285
2286static void
2287e1000_82547_tx_fifo_stall(unsigned long data)
2288{
2289 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2290 struct net_device *netdev = adapter->netdev;
2291 uint32_t tctl;
2292
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002293 if (atomic_read(&adapter->tx_fifo_stall)) {
2294 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 E1000_READ_REG(&adapter->hw, TDH)) &&
2296 (E1000_READ_REG(&adapter->hw, TDFT) ==
2297 E1000_READ_REG(&adapter->hw, TDFH)) &&
2298 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2299 E1000_READ_REG(&adapter->hw, TDFHS))) {
2300 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2301 E1000_WRITE_REG(&adapter->hw, TCTL,
2302 tctl & ~E1000_TCTL_EN);
2303 E1000_WRITE_REG(&adapter->hw, TDFT,
2304 adapter->tx_head_addr);
2305 E1000_WRITE_REG(&adapter->hw, TDFH,
2306 adapter->tx_head_addr);
2307 E1000_WRITE_REG(&adapter->hw, TDFTS,
2308 adapter->tx_head_addr);
2309 E1000_WRITE_REG(&adapter->hw, TDFHS,
2310 adapter->tx_head_addr);
2311 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2312 E1000_WRITE_FLUSH(&adapter->hw);
2313
2314 adapter->tx_fifo_head = 0;
2315 atomic_set(&adapter->tx_fifo_stall, 0);
2316 netif_wake_queue(netdev);
2317 } else {
2318 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2319 }
2320 }
2321}
2322
2323/**
2324 * e1000_watchdog - Timer Call-back
2325 * @data: pointer to adapter cast into an unsigned long
2326 **/
2327static void
2328e1000_watchdog(unsigned long data)
2329{
2330 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002332 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002333 uint32_t link, tctl;
Auke Kokcd94dd02006-06-27 09:08:22 -07002334 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Auke Kokcd94dd02006-06-27 09:08:22 -07002336 ret_val = e1000_check_for_link(&adapter->hw);
2337 if ((ret_val == E1000_ERR_PHY) &&
2338 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2339 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2340 /* See e1000_kumeran_lock_loss_workaround() */
2341 DPRINTK(LINK, INFO,
2342 "Gigabit has been disabled, downgrading speed\n");
2343 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002344 if (adapter->hw.mac_type == e1000_82573) {
2345 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002346 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002347 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002350 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2352 link = !adapter->hw.serdes_link_down;
2353 else
2354 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2355
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002356 if (link) {
2357 if (!netif_carrier_ok(netdev)) {
Auke Kokfe7fe282006-04-14 19:04:59 -07002358 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 e1000_get_speed_and_duplex(&adapter->hw,
2360 &adapter->link_speed,
2361 &adapter->link_duplex);
2362
2363 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2364 adapter->link_speed,
2365 adapter->link_duplex == FULL_DUPLEX ?
2366 "Full Duplex" : "Half Duplex");
2367
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002368 /* tweak tx_queue_len according to speed/duplex
2369 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002370 netdev->tx_queue_len = adapter->tx_queue_len;
2371 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002372 switch (adapter->link_speed) {
2373 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002374 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002375 netdev->tx_queue_len = 10;
2376 adapter->tx_timeout_factor = 8;
2377 break;
2378 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002379 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002380 netdev->tx_queue_len = 100;
2381 /* maybe add some timeout factor ? */
2382 break;
2383 }
2384
Auke Kokfe7fe282006-04-14 19:04:59 -07002385 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002386 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002387 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002388#define SPEED_MODE_BIT (1 << 21)
2389 uint32_t tarc0;
2390 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2391 tarc0 &= ~SPEED_MODE_BIT;
2392 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2393 }
2394
2395#ifdef NETIF_F_TSO
2396 /* disable TSO for pcie and 10/100 speeds, to avoid
2397 * some hardware issues */
2398 if (!adapter->tso_force &&
2399 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002400 switch (adapter->link_speed) {
2401 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002402 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002403 DPRINTK(PROBE,INFO,
2404 "10/100 speed: disabling TSO\n");
2405 netdev->features &= ~NETIF_F_TSO;
2406 break;
2407 case SPEED_1000:
2408 netdev->features |= NETIF_F_TSO;
2409 break;
2410 default:
2411 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002412 break;
2413 }
2414 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002415#endif
2416
2417 /* enable transmits in the hardware, need to do this
2418 * after setting TARC0 */
2419 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2420 tctl |= E1000_TCTL_EN;
2421 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002422
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 netif_carrier_on(netdev);
2424 netif_wake_queue(netdev);
2425 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2426 adapter->smartspeed = 0;
2427 }
2428 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002429 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 adapter->link_speed = 0;
2431 adapter->link_duplex = 0;
2432 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2433 netif_carrier_off(netdev);
2434 netif_stop_queue(netdev);
2435 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002436
2437 /* 80003ES2LAN workaround--
2438 * For packet buffer work-around on link down event;
2439 * disable receives in the ISR and
2440 * reset device here in the watchdog
2441 */
2442 if (adapter->hw.mac_type == e1000_80003es2lan) {
2443 /* reset device */
2444 schedule_work(&adapter->reset_task);
2445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 }
2447
2448 e1000_smartspeed(adapter);
2449 }
2450
2451 e1000_update_stats(adapter);
2452
2453 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2454 adapter->tpt_old = adapter->stats.tpt;
2455 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2456 adapter->colc_old = adapter->stats.colc;
2457
2458 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2459 adapter->gorcl_old = adapter->stats.gorcl;
2460 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2461 adapter->gotcl_old = adapter->stats.gotcl;
2462
2463 e1000_update_adaptive(&adapter->hw);
2464
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002465 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002466 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 /* We've lost link, so the controller stops DMA,
2468 * but we've got queued Tx work that's never going
2469 * to get done, so reset controller to flush Tx.
2470 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002471 adapter->tx_timeout_count++;
2472 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 }
2474 }
2475
2476 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002477 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2479 * asymmetrical Tx or Rx gets ITR=8000; everyone
2480 * else is between 2000-8000. */
2481 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002482 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 adapter->gotcl - adapter->gorcl :
2484 adapter->gorcl - adapter->gotcl) / 10000;
2485 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2486 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2487 }
2488
2489 /* Cause software interrupt to ensure rx ring is cleaned */
2490 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2491
Malli Chilakala26483452005-04-28 19:44:46 -07002492 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 adapter->detect_tx_hung = TRUE;
2494
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002495 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002496 * reset from the other port. Set the appropriate LAA in RAR[0] */
2497 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2498 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2499
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 /* Reset the timer */
2501 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2502}
2503
2504#define E1000_TX_FLAGS_CSUM 0x00000001
2505#define E1000_TX_FLAGS_VLAN 0x00000002
2506#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002507#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2509#define E1000_TX_FLAGS_VLAN_SHIFT 16
2510
Auke Koke619d522006-04-14 19:04:52 -07002511static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002512e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2513 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
2515#ifdef NETIF_F_TSO
2516 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002517 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 unsigned int i;
2519 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002520 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2522 int err;
2523
Herbert Xu89114af2006-07-08 13:34:32 -07002524 if (skb_is_gso(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 if (skb_header_cloned(skb)) {
2526 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2527 if (err)
2528 return err;
2529 }
2530
2531 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Herbert Xu79671682006-06-22 02:40:14 -07002532 mss = skb_shinfo(skb)->gso_size;
Alexey Dobriyan60828232006-05-23 14:52:21 -07002533 if (skb->protocol == htons(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002534 skb->nh.iph->tot_len = 0;
2535 skb->nh.iph->check = 0;
2536 skb->h.th->check =
2537 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2538 skb->nh.iph->daddr,
2539 0,
2540 IPPROTO_TCP,
2541 0);
2542 cmd_length = E1000_TXD_CMD_IP;
2543 ipcse = skb->h.raw - skb->data - 1;
2544#ifdef NETIF_F_TSO_IPV6
Auke Koke15fdd02006-08-16 11:28:45 -07002545 } else if (skb->protocol == htons(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002546 skb->nh.ipv6h->payload_len = 0;
2547 skb->h.th->check =
2548 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2549 &skb->nh.ipv6h->daddr,
2550 0,
2551 IPPROTO_TCP,
2552 0);
2553 ipcse = 0;
2554#endif
2555 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 ipcss = skb->nh.raw - skb->data;
2557 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 tucss = skb->h.raw - skb->data;
2559 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2560 tucse = 0;
2561
2562 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002563 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002565 i = tx_ring->next_to_use;
2566 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002567 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
2569 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2570 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2571 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2572 context_desc->upper_setup.tcp_fields.tucss = tucss;
2573 context_desc->upper_setup.tcp_fields.tucso = tucso;
2574 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2575 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2576 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2577 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2578
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002579 buffer_info->time_stamp = jiffies;
2580
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002581 if (++i == tx_ring->count) i = 0;
2582 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Jeff Kirsher8241e352006-01-12 16:51:34 -08002584 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 }
2586#endif
2587
Jeff Kirsher8241e352006-01-12 16:51:34 -08002588 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589}
2590
Auke Koke619d522006-04-14 19:04:52 -07002591static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002592e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2593 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594{
2595 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002596 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 unsigned int i;
2598 uint8_t css;
2599
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002600 if (likely(skb->ip_summed == CHECKSUM_HW)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 css = skb->h.raw - skb->data;
2602
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002603 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002604 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002605 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606
2607 context_desc->upper_setup.tcp_fields.tucss = css;
2608 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2609 context_desc->upper_setup.tcp_fields.tucse = 0;
2610 context_desc->tcp_seg_setup.data = 0;
2611 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2612
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002613 buffer_info->time_stamp = jiffies;
2614
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002615 if (unlikely(++i == tx_ring->count)) i = 0;
2616 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
2618 return TRUE;
2619 }
2620
2621 return FALSE;
2622}
2623
2624#define E1000_MAX_TXD_PWR 12
2625#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2626
Auke Koke619d522006-04-14 19:04:52 -07002627static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002628e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2629 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2630 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 struct e1000_buffer *buffer_info;
2633 unsigned int len = skb->len;
2634 unsigned int offset = 0, size, count = 0, i;
2635 unsigned int f;
2636 len -= skb->data_len;
2637
2638 i = tx_ring->next_to_use;
2639
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002640 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 buffer_info = &tx_ring->buffer_info[i];
2642 size = min(len, max_per_txd);
2643#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002644 /* Workaround for Controller erratum --
2645 * descriptor for non-tso packet in a linear SKB that follows a
2646 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002647 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002648 if (!skb->data_len && tx_ring->last_tx_tso &&
Herbert Xu89114af2006-07-08 13:34:32 -07002649 !skb_is_gso(skb)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002650 tx_ring->last_tx_tso = 0;
2651 size -= 4;
2652 }
2653
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 /* Workaround for premature desc write-backs
2655 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002656 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 size -= 4;
2658#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002659 /* work-around for errata 10 and it applies
2660 * to all controllers in PCI-X mode
2661 * The fix is to make sure that the first descriptor of a
2662 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2663 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002664 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002665 (size > 2015) && count == 0))
2666 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002667
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 /* Workaround for potential 82544 hang in PCI-X. Avoid
2669 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002670 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2672 size > 4))
2673 size -= 4;
2674
2675 buffer_info->length = size;
2676 buffer_info->dma =
2677 pci_map_single(adapter->pdev,
2678 skb->data + offset,
2679 size,
2680 PCI_DMA_TODEVICE);
2681 buffer_info->time_stamp = jiffies;
2682
2683 len -= size;
2684 offset += size;
2685 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002686 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 }
2688
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002689 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 struct skb_frag_struct *frag;
2691
2692 frag = &skb_shinfo(skb)->frags[f];
2693 len = frag->size;
2694 offset = frag->page_offset;
2695
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002696 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 buffer_info = &tx_ring->buffer_info[i];
2698 size = min(len, max_per_txd);
2699#ifdef NETIF_F_TSO
2700 /* Workaround for premature desc write-backs
2701 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002702 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 size -= 4;
2704#endif
2705 /* Workaround for potential 82544 hang in PCI-X.
2706 * Avoid terminating buffers within evenly-aligned
2707 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002708 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2710 size > 4))
2711 size -= 4;
2712
2713 buffer_info->length = size;
2714 buffer_info->dma =
2715 pci_map_page(adapter->pdev,
2716 frag->page,
2717 offset,
2718 size,
2719 PCI_DMA_TODEVICE);
2720 buffer_info->time_stamp = jiffies;
2721
2722 len -= size;
2723 offset += size;
2724 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002725 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 }
2727 }
2728
2729 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2730 tx_ring->buffer_info[i].skb = skb;
2731 tx_ring->buffer_info[first].next_to_watch = i;
2732
2733 return count;
2734}
2735
Auke Koke619d522006-04-14 19:04:52 -07002736static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002737e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2738 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 struct e1000_tx_desc *tx_desc = NULL;
2741 struct e1000_buffer *buffer_info;
2742 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2743 unsigned int i;
2744
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002745 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2747 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002748 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2749
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002750 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002751 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 }
2753
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002754 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2756 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2757 }
2758
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002759 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 txd_lower |= E1000_TXD_CMD_VLE;
2761 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2762 }
2763
2764 i = tx_ring->next_to_use;
2765
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002766 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 buffer_info = &tx_ring->buffer_info[i];
2768 tx_desc = E1000_TX_DESC(*tx_ring, i);
2769 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2770 tx_desc->lower.data =
2771 cpu_to_le32(txd_lower | buffer_info->length);
2772 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002773 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 }
2775
2776 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2777
2778 /* Force memory writes to complete before letting h/w
2779 * know there are new descriptors to fetch. (Only
2780 * applicable for weak-ordered memory model archs,
2781 * such as IA-64). */
2782 wmb();
2783
2784 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002785 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786}
2787
2788/**
2789 * 82547 workaround to avoid controller hang in half-duplex environment.
2790 * The workaround is to avoid queuing a large packet that would span
2791 * the internal Tx FIFO ring boundary by notifying the stack to resend
2792 * the packet at a later time. This gives the Tx FIFO an opportunity to
2793 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2794 * to the beginning of the Tx FIFO.
2795 **/
2796
2797#define E1000_FIFO_HDR 0x10
2798#define E1000_82547_PAD_LEN 0x3E0
2799
Auke Koke619d522006-04-14 19:04:52 -07002800static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2802{
2803 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2804 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2805
2806 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2807
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002808 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 goto no_fifo_stall_required;
2810
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002811 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 return 1;
2813
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002814 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 atomic_set(&adapter->tx_fifo_stall, 1);
2816 return 1;
2817 }
2818
2819no_fifo_stall_required:
2820 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002821 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2823 return 0;
2824}
2825
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002826#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07002827static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002828e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2829{
2830 struct e1000_hw *hw = &adapter->hw;
2831 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002832 if (vlan_tx_tag_present(skb)) {
2833 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002834 ( adapter->hw.mng_cookie.status &
2835 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2836 return 0;
2837 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08002838 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002839 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002840 if ((htons(ETH_P_IP) == eth->h_proto)) {
2841 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002842 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002843 if (IPPROTO_UDP == ip->protocol) {
2844 struct udphdr *udp =
2845 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002846 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002847 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002848 offset = (uint8_t *)udp + 8 - skb->data;
2849 length = skb->len - offset;
2850
2851 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002852 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002853 length);
2854 }
2855 }
2856 }
2857 }
2858 return 0;
2859}
2860
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2862static int
2863e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2864{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002865 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002866 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2868 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2869 unsigned int tx_flags = 0;
2870 unsigned int len = skb->len;
2871 unsigned long flags;
2872 unsigned int nr_frags = 0;
2873 unsigned int mss = 0;
2874 int count = 0;
Auke Kok76c224b2006-05-23 13:36:06 -07002875 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 unsigned int f;
2877 len -= skb->data_len;
2878
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002879 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002880
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002881 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 dev_kfree_skb_any(skb);
2883 return NETDEV_TX_OK;
2884 }
2885
2886#ifdef NETIF_F_TSO
Herbert Xu79671682006-06-22 02:40:14 -07002887 mss = skb_shinfo(skb)->gso_size;
Auke Kok76c224b2006-05-23 13:36:06 -07002888 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 * make sure there is enough room in the FIFO before
2890 * initiating the DMA for each buffer. The calc is:
2891 * 4 = ceil(buffer len/mss). To make sure we don't
2892 * overrun the FIFO, adjust the max buffer len if mss
2893 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002894 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002895 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 max_per_txd = min(mss << 2, max_per_txd);
2897 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002898
Jeff Kirsher9f687882006-03-02 18:20:17 -08002899 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002900 * points to just header, pull a few bytes of payload from
2901 * frags into skb->data */
2902 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08002903 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
2904 switch (adapter->hw.mac_type) {
2905 unsigned int pull_size;
2906 case e1000_82571:
2907 case e1000_82572:
2908 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -07002909 case e1000_ich8lan:
Jeff Kirsher9f687882006-03-02 18:20:17 -08002910 pull_size = min((unsigned int)4, skb->data_len);
2911 if (!__pskb_pull_tail(skb, pull_size)) {
Auke Koka5eafce2006-06-27 09:06:49 -07002912 DPRINTK(DRV, ERR,
Jeff Kirsher9f687882006-03-02 18:20:17 -08002913 "__pskb_pull_tail failed.\n");
2914 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05002915 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08002916 }
2917 len = skb->len - skb->data_len;
2918 break;
2919 default:
2920 /* do nothing */
2921 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08002922 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 }
2925
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002926 /* reserve a descriptor for the offload context */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002927 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07002929 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930#else
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002931 if (skb->ip_summed == CHECKSUM_HW)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 count++;
2933#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05002934
2935#ifdef NETIF_F_TSO
2936 /* Controller Erratum workaround */
Herbert Xu89114af2006-07-08 13:34:32 -07002937 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
Jeff Kirsherfd803242005-12-13 00:06:22 -05002938 count++;
2939#endif
2940
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 count += TXD_USE_COUNT(len, max_txd_pwr);
2942
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002943 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 count++;
2945
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002946 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07002947 * in PCI-X mode, so add one more descriptor to the count
2948 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002949 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002950 (len > 2015)))
2951 count++;
2952
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002954 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2956 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002957 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 count += nr_frags;
2959
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002960
2961 if (adapter->hw.tx_pkt_filtering &&
2962 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002963 e1000_transfer_dhcp_info(adapter, skb);
2964
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002965 local_irq_save(flags);
2966 if (!spin_trylock(&tx_ring->tx_lock)) {
2967 /* Collision - tell upper layer to requeue */
2968 local_irq_restore(flags);
2969 return NETDEV_TX_LOCKED;
2970 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
2972 /* need: count + 2 desc gap to keep tail from touching
2973 * head, otherwise try next time */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002974 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 netif_stop_queue(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002976 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 return NETDEV_TX_BUSY;
2978 }
2979
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002980 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2981 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 netif_stop_queue(netdev);
2983 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002984 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 return NETDEV_TX_BUSY;
2986 }
2987 }
2988
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002989 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 tx_flags |= E1000_TX_FLAGS_VLAN;
2991 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2992 }
2993
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002994 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002995
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002996 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 if (tso < 0) {
2998 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002999 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 return NETDEV_TX_OK;
3001 }
3002
Jeff Kirsherfd803242005-12-13 00:06:22 -05003003 if (likely(tso)) {
3004 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05003006 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 tx_flags |= E1000_TX_FLAGS_CSUM;
3008
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003009 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003010 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003011 * no longer assume, we must. */
Alexey Dobriyan60828232006-05-23 14:52:21 -07003012 if (likely(skb->protocol == htons(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003013 tx_flags |= E1000_TX_FLAGS_IPV4;
3014
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003015 e1000_tx_queue(adapter, tx_ring, tx_flags,
3016 e1000_tx_map(adapter, tx_ring, skb, first,
3017 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018
3019 netdev->trans_start = jiffies;
3020
3021 /* Make sure there is space in the ring for the next send. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003022 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 netif_stop_queue(netdev);
3024
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003025 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 return NETDEV_TX_OK;
3027}
3028
3029/**
3030 * e1000_tx_timeout - Respond to a Tx Hang
3031 * @netdev: network interface device structure
3032 **/
3033
3034static void
3035e1000_tx_timeout(struct net_device *netdev)
3036{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003037 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038
3039 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08003040 adapter->tx_timeout_count++;
3041 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042}
3043
3044static void
Jeff Kirsher87041632006-03-02 18:21:24 -08003045e1000_reset_task(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003047 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048
Auke Kok2db10a02006-06-27 09:06:28 -07003049 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050}
3051
3052/**
3053 * e1000_get_stats - Get System Network Statistics
3054 * @netdev: network interface device structure
3055 *
3056 * Returns the address of the device statistics structure.
3057 * The statistics are actually updated from the timer callback.
3058 **/
3059
3060static struct net_device_stats *
3061e1000_get_stats(struct net_device *netdev)
3062{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003063 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003065 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 return &adapter->net_stats;
3067}
3068
3069/**
3070 * e1000_change_mtu - Change the Maximum Transfer Unit
3071 * @netdev: network interface device structure
3072 * @new_mtu: new value for maximum frame size
3073 *
3074 * Returns 0 on success, negative on failure
3075 **/
3076
3077static int
3078e1000_change_mtu(struct net_device *netdev, int new_mtu)
3079{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003080 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003082 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003084 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3085 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3086 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003087 return -EINVAL;
3088 }
3089
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003090 /* Adapter-specific max frame size limits. */
3091 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07003092 case e1000_undefined ... e1000_82542_rev2_1:
Auke Kokcd94dd02006-06-27 09:08:22 -07003093 case e1000_ich8lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003094 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3095 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003096 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003097 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003098 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08003099 case e1000_82573:
3100 /* only enable jumbo frames if ASPM is disabled completely
3101 * this means both bits must be zero in 0x1A bits 3:2 */
3102 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3103 &eeprom_data);
3104 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
3105 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3106 DPRINTK(PROBE, ERR,
3107 "Jumbo Frames not supported.\n");
3108 return -EINVAL;
3109 }
3110 break;
3111 }
3112 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003113 case e1000_82571:
3114 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003115 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003116#define MAX_STD_JUMBO_FRAME_SIZE 9234
3117 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3118 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3119 return -EINVAL;
3120 }
3121 break;
3122 default:
3123 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3124 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003125 }
3126
David S. Miller87f50322006-07-31 22:39:40 -07003127 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
Auke Kok9e2feac2006-04-14 19:05:18 -07003128 * means we reserve 2 more, this pushes us to allocate from the next
3129 * larger slab size
3130 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003131
Auke Kok9e2feac2006-04-14 19:05:18 -07003132 if (max_frame <= E1000_RXBUFFER_256)
3133 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3134 else if (max_frame <= E1000_RXBUFFER_512)
3135 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3136 else if (max_frame <= E1000_RXBUFFER_1024)
3137 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3138 else if (max_frame <= E1000_RXBUFFER_2048)
3139 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3140 else if (max_frame <= E1000_RXBUFFER_4096)
3141 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3142 else if (max_frame <= E1000_RXBUFFER_8192)
3143 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3144 else if (max_frame <= E1000_RXBUFFER_16384)
3145 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3146
3147 /* adjust allocation if LPE protects us, and we aren't using SBP */
Auke Kok9e2feac2006-04-14 19:05:18 -07003148 if (!adapter->hw.tbi_compatibility_on &&
3149 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3150 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3151 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003152
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003153 netdev->mtu = new_mtu;
3154
Auke Kok2db10a02006-06-27 09:06:28 -07003155 if (netif_running(netdev))
3156 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 adapter->hw.max_frame_size = max_frame;
3159
3160 return 0;
3161}
3162
3163/**
3164 * e1000_update_stats - Update the board statistics counters
3165 * @adapter: board private structure
3166 **/
3167
3168void
3169e1000_update_stats(struct e1000_adapter *adapter)
3170{
3171 struct e1000_hw *hw = &adapter->hw;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003172 struct pci_dev *pdev = adapter->pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 unsigned long flags;
3174 uint16_t phy_tmp;
3175
3176#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3177
Linas Vepstas282f33c2006-06-08 22:19:44 -07003178 /*
3179 * Prevent stats update while adapter is being reset, or if the pci
3180 * connection is down.
3181 */
Auke Kok90267292006-06-08 09:30:24 -07003182 if (adapter->link_speed == 0)
3183 return;
Linas Vepstas282f33c2006-06-08 22:19:44 -07003184 if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
3185 return;
Auke Kok90267292006-06-08 09:30:24 -07003186
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 spin_lock_irqsave(&adapter->stats_lock, flags);
3188
3189 /* these counters are modified from e1000_adjust_tbi_stats,
3190 * called from the interrupt context, so they must only
3191 * be written while holding adapter->stats_lock
3192 */
3193
3194 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3195 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3196 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3197 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3198 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3199 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3200 adapter->stats.roc += E1000_READ_REG(hw, ROC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003201
3202 if (adapter->hw.mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3204 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3205 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3206 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3207 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3208 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210
3211 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3212 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3213 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3214 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3215 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3216 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3217 adapter->stats.dc += E1000_READ_REG(hw, DC);
3218 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3219 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3220 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3221 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3222 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3223 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3224 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3225 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3226 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3227 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3228 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3229 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3230 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3231 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3232 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3233 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3234 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3235 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3236 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
Auke Kokcd94dd02006-06-27 09:08:22 -07003237
3238 if (adapter->hw.mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3240 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3241 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3242 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3243 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3244 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07003245 }
3246
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3248 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3249
3250 /* used for adaptive IFS */
3251
3252 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3253 adapter->stats.tpt += hw->tx_packet_delta;
3254 hw->collision_delta = E1000_READ_REG(hw, COLC);
3255 adapter->stats.colc += hw->collision_delta;
3256
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003257 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3259 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3260 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3261 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3262 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3263 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3264 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003265 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003266 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3267 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003268
3269 if (adapter->hw.mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003270 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3271 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3272 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3273 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3274 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3275 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3276 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
Auke Kokcd94dd02006-06-27 09:08:22 -07003277 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 /* Fill out the OS statistics structure */
3281
3282 adapter->net_stats.rx_packets = adapter->stats.gprc;
3283 adapter->net_stats.tx_packets = adapter->stats.gptc;
3284 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3285 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3286 adapter->net_stats.multicast = adapter->stats.mprc;
3287 adapter->net_stats.collisions = adapter->stats.colc;
3288
3289 /* Rx Errors */
3290
Jeff Kirsher87041632006-03-02 18:21:24 -08003291 /* RLEC on some newer hardware can be incorrect so build
3292 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3294 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003295 adapter->stats.ruc + adapter->stats.roc +
3296 adapter->stats.cexterr;
Jeff Kirsher87041632006-03-02 18:21:24 -08003297 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3298 adapter->stats.roc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3300 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3302
3303 /* Tx Errors */
3304
3305 adapter->net_stats.tx_errors = adapter->stats.ecol +
3306 adapter->stats.latecol;
3307 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3308 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3309 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3310
3311 /* Tx Dropped needs to be maintained elsewhere */
3312
3313 /* Phy Stats */
3314
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003315 if (hw->media_type == e1000_media_type_copper) {
3316 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3318 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3319 adapter->phy_stats.idle_errors += phy_tmp;
3320 }
3321
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003322 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 (hw->phy_type == e1000_phy_m88) &&
3324 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3325 adapter->phy_stats.receive_errors += phy_tmp;
3326 }
3327
3328 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3329}
3330
3331/**
3332 * e1000_intr - Interrupt Handler
3333 * @irq: interrupt number
3334 * @data: pointer to a network interface device structure
3335 * @pt_regs: CPU registers structure
3336 **/
3337
3338static irqreturn_t
3339e1000_intr(int irq, void *data, struct pt_regs *regs)
3340{
3341 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003342 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003344 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003345#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003346 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003347#else
3348 /* Interrupt Auto-Mask...upon reading ICR,
3349 * interrupts are masked. No need for the
3350 * IMC write, but it does mean we should
3351 * account for it ASAP. */
3352 if (likely(hw->mac_type >= e1000_82571))
3353 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003354#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003356 if (unlikely(!icr)) {
3357#ifdef CONFIG_E1000_NAPI
3358 if (hw->mac_type >= e1000_82571)
3359 e1000_irq_enable(adapter);
3360#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003364 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003366 /* 80003ES2LAN workaround--
3367 * For packet buffer work-around on link down event;
3368 * disable receives here in the ISR and
3369 * reset adapter in watchdog
3370 */
3371 if (netif_carrier_ok(netdev) &&
3372 (adapter->hw.mac_type == e1000_80003es2lan)) {
3373 /* disable receives */
3374 rctl = E1000_READ_REG(hw, RCTL);
3375 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 mod_timer(&adapter->watchdog_timer, jiffies);
3378 }
3379
3380#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003381 if (unlikely(hw->mac_type < e1000_82571)) {
3382 atomic_inc(&adapter->irq_sem);
3383 E1000_WRITE_REG(hw, IMC, ~0);
3384 E1000_WRITE_FLUSH(hw);
3385 }
Auke Kokd3d9e482006-07-14 16:14:23 -07003386 if (likely(netif_rx_schedule_prep(netdev)))
3387 __netif_rx_schedule(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003388 else
3389 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003390#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003392 * Due to Hub Link bus being occupied, an interrupt
3393 * de-assertion message is not able to be sent.
3394 * When an interrupt assertion message is generated later,
3395 * two messages are re-ordered and sent out.
3396 * That causes APIC to think 82547 is in de-assertion
3397 * state, while 82547 is in assertion state, resulting
3398 * in dead lock. Writing IMC forces 82547 into
3399 * de-assertion state.
3400 */
3401 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003403 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 }
3405
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003406 for (i = 0; i < E1000_MAX_INTR; i++)
3407 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003408 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 break;
3410
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003411 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003413
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003414#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
3416 return IRQ_HANDLED;
3417}
3418
3419#ifdef CONFIG_E1000_NAPI
3420/**
3421 * e1000_clean - NAPI Rx polling callback
3422 * @adapter: board private structure
3423 **/
3424
3425static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003426e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003428 struct e1000_adapter *adapter;
3429 int work_to_do = min(*budget, poll_dev->quota);
Auke Kokd3d9e482006-07-14 16:14:23 -07003430 int tx_cleaned = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003431
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003432 /* Must NOT use netdev_priv macro here. */
3433 adapter = poll_dev->priv;
3434
3435 /* Keep link state information with original netdev */
Auke Kokd3d9e482006-07-14 16:14:23 -07003436 if (!netif_carrier_ok(poll_dev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003437 goto quit_polling;
3438
Auke Kokd3d9e482006-07-14 16:14:23 -07003439 /* e1000_clean is called per-cpu. This lock protects
3440 * tx_ring[0] from being cleaned by multiple cpus
3441 * simultaneously. A failure obtaining the lock means
3442 * tx_ring[0] is currently being cleaned anyway. */
3443 if (spin_trylock(&adapter->tx_queue_lock)) {
3444 tx_cleaned = e1000_clean_tx_irq(adapter,
3445 &adapter->tx_ring[0]);
3446 spin_unlock(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003447 }
3448
Auke Kokd3d9e482006-07-14 16:14:23 -07003449 adapter->clean_rx(adapter, &adapter->rx_ring[0],
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003450 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
3452 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003453 poll_dev->quota -= work_done;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003454
Malli Chilakala2b028932005-06-17 17:46:06 -07003455 /* If no Tx and not enough Rx work done, exit the polling mode */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003456 if ((!tx_cleaned && (work_done == 0)) ||
Auke Kokd3d9e482006-07-14 16:14:23 -07003457 !netif_running(poll_dev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003458quit_polling:
3459 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 e1000_irq_enable(adapter);
3461 return 0;
3462 }
3463
3464 return 1;
3465}
3466
3467#endif
3468/**
3469 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3470 * @adapter: board private structure
3471 **/
3472
3473static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003474e1000_clean_tx_irq(struct e1000_adapter *adapter,
3475 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 struct net_device *netdev = adapter->netdev;
3478 struct e1000_tx_desc *tx_desc, *eop_desc;
3479 struct e1000_buffer *buffer_info;
3480 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003481#ifdef CONFIG_E1000_NAPI
3482 unsigned int count = 0;
3483#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 boolean_t cleaned = FALSE;
3485
3486 i = tx_ring->next_to_clean;
3487 eop = tx_ring->buffer_info[i].next_to_watch;
3488 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3489
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003490 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003491 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 tx_desc = E1000_TX_DESC(*tx_ring, i);
3493 buffer_info = &tx_ring->buffer_info[i];
3494 cleaned = (i == eop);
3495
Jeff Kirsherfd803242005-12-13 00:06:22 -05003496 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jeff Kirsher8241e352006-01-12 16:51:34 -08003497 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003499 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003501
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003502
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 eop = tx_ring->buffer_info[i].next_to_watch;
3504 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003505#ifdef CONFIG_E1000_NAPI
3506#define E1000_TX_WEIGHT 64
3507 /* weight of a sort for tx, to avoid endless transmit cleanup */
3508 if (count++ == E1000_TX_WEIGHT) break;
3509#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 }
3511
3512 tx_ring->next_to_clean = i;
3513
Auke Kok77b2aad2006-04-14 19:05:25 -07003514#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003515 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
Auke Kok77b2aad2006-04-14 19:05:25 -07003516 netif_carrier_ok(netdev))) {
3517 spin_lock(&tx_ring->tx_lock);
3518 if (netif_queue_stopped(netdev) &&
3519 (E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))
3520 netif_wake_queue(netdev);
3521 spin_unlock(&tx_ring->tx_lock);
3522 }
Malli Chilakala26483452005-04-28 19:44:46 -07003523
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003524 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003525 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 * check with the clearing of time_stamp and movement of i */
3527 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003528 if (tx_ring->buffer_info[eop].dma &&
3529 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003530 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003531 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003532 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003533
3534 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003535 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003536 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003537 " TDH <%x>\n"
3538 " TDT <%x>\n"
3539 " next_to_use <%x>\n"
3540 " next_to_clean <%x>\n"
3541 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003542 " time_stamp <%lx>\n"
3543 " next_to_watch <%x>\n"
3544 " jiffies <%lx>\n"
3545 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003546 (unsigned long)((tx_ring - adapter->tx_ring) /
3547 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003548 readl(adapter->hw.hw_addr + tx_ring->tdh),
3549 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003550 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003551 tx_ring->next_to_clean,
3552 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003553 eop,
3554 jiffies,
3555 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 return cleaned;
3560}
3561
3562/**
3563 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003564 * @adapter: board private structure
3565 * @status_err: receive descriptor status and error fields
3566 * @csum: receive descriptor csum field
3567 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 **/
3569
Auke Koke619d522006-04-14 19:04:52 -07003570static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003572 uint32_t status_err, uint32_t csum,
3573 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003575 uint16_t status = (uint16_t)status_err;
3576 uint8_t errors = (uint8_t)(status_err >> 24);
3577 skb->ip_summed = CHECKSUM_NONE;
3578
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003580 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003582 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003583 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003584 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003585 /* let the stack verify checksum errors */
3586 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 return;
3588 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003589 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003590 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3591 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003592 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003594 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003595 return;
3596 }
3597 /* It must be a TCP or UDP packet with a valid checksum */
3598 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 /* TCP checksum is good */
3600 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003601 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3602 /* IP fragment with UDP payload */
3603 /* Hardware complements the payload checksum, so we undo it
3604 * and then put the value in host order for further stack use.
3605 */
3606 csum = ntohl(csum ^ 0xFFFF);
3607 skb->csum = csum;
3608 skb->ip_summed = CHECKSUM_HW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003610 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611}
3612
3613/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003614 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 * @adapter: board private structure
3616 **/
3617
3618static boolean_t
3619#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003620e1000_clean_rx_irq(struct e1000_adapter *adapter,
3621 struct e1000_rx_ring *rx_ring,
3622 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003624e1000_clean_rx_irq(struct e1000_adapter *adapter,
3625 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626#endif
3627{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 struct net_device *netdev = adapter->netdev;
3629 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003630 struct e1000_rx_desc *rx_desc, *next_rxd;
3631 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 unsigned long flags;
3633 uint32_t length;
3634 uint8_t last_byte;
3635 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003636 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003637 boolean_t cleaned = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638
3639 i = rx_ring->next_to_clean;
3640 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003641 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003643 while (rx_desc->status & E1000_RXD_STAT_DD) {
Auke Kok24f476e2006-06-08 09:28:47 -07003644 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003645 u8 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003647 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 break;
3649 (*work_done)++;
3650#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08003651 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003652 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003653 buffer_info->skb = NULL;
3654
Jeff Kirsher30320be2006-03-02 18:21:57 -08003655 prefetch(skb->data - NET_IP_ALIGN);
3656
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003657 if (++i == rx_ring->count) i = 0;
3658 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003659 prefetch(next_rxd);
3660
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003661 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003662
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003663 cleaned = TRUE;
3664 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003665 pci_unmap_single(pdev,
3666 buffer_info->dma,
3667 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 PCI_DMA_FROMDEVICE);
3669
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 length = le16_to_cpu(rx_desc->length);
3671
Auke Kokf235a2a2006-07-14 16:14:34 -07003672 /* adjust length to remove Ethernet CRC */
3673 length -= 4;
3674
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003675 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3676 /* All receives must fit into a single buffer */
3677 E1000_DBG("%s: Receive packet consumed multiple"
3678 " buffers\n", netdev->name);
Auke Kok864c4e42006-06-27 09:06:53 -07003679 /* recycle */
3680 buffer_info-> skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 goto next_desc;
3682 }
3683
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003684 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003686 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 rx_desc->errors, length, last_byte)) {
3688 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003689 e1000_tbi_adjust_stats(&adapter->hw,
3690 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 length, skb->data);
3692 spin_unlock_irqrestore(&adapter->stats_lock,
3693 flags);
3694 length--;
3695 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07003696 /* recycle */
3697 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 goto next_desc;
3699 }
Auke Kok1cb58212006-04-18 12:31:04 -07003700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701
Jeff Kirshera292ca62006-01-12 16:51:30 -08003702 /* code added for copybreak, this should improve
3703 * performance for small packets with large amounts
3704 * of reassembly being done in the stack */
3705#define E1000_CB_LENGTH 256
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003706 if (length < E1000_CB_LENGTH) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08003707 struct sk_buff *new_skb =
David S. Miller87f50322006-07-31 22:39:40 -07003708 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003709 if (new_skb) {
3710 skb_reserve(new_skb, NET_IP_ALIGN);
3711 new_skb->dev = netdev;
3712 memcpy(new_skb->data - NET_IP_ALIGN,
3713 skb->data - NET_IP_ALIGN,
3714 length + NET_IP_ALIGN);
3715 /* save the skb in buffer_info as good */
3716 buffer_info->skb = skb;
3717 skb = new_skb;
3718 skb_put(skb, length);
3719 }
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003720 } else
3721 skb_put(skb, length);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003722
3723 /* end copybreak code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724
3725 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08003726 e1000_rx_checksum(adapter,
3727 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003728 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003729 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003730
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 skb->protocol = eth_type_trans(skb, netdev);
3732#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003733 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08003734 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003736 le16_to_cpu(rx_desc->special) &
3737 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 } else {
3739 netif_receive_skb(skb);
3740 }
3741#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003742 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003743 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 vlan_hwaccel_rx(skb, adapter->vlgrp,
3745 le16_to_cpu(rx_desc->special) &
3746 E1000_RXD_SPC_VLAN_MASK);
3747 } else {
3748 netif_rx(skb);
3749 }
3750#endif /* CONFIG_E1000_NAPI */
3751 netdev->last_rx = jiffies;
3752
3753next_desc:
3754 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003756 /* return some buffers to hardware, one at a time is too slow */
3757 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3758 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3759 cleaned_count = 0;
3760 }
3761
Jeff Kirsher30320be2006-03-02 18:21:57 -08003762 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003763 rx_desc = next_rxd;
3764 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003767
3768 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3769 if (cleaned_count)
3770 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771
3772 return cleaned;
3773}
3774
3775/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003776 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3777 * @adapter: board private structure
3778 **/
3779
3780static boolean_t
3781#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003782e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3783 struct e1000_rx_ring *rx_ring,
3784 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003785#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003786e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3787 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003788#endif
3789{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003790 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003791 struct net_device *netdev = adapter->netdev;
3792 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003793 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003794 struct e1000_ps_page *ps_page;
3795 struct e1000_ps_page_dma *ps_page_dma;
Auke Kok24f476e2006-06-08 09:28:47 -07003796 struct sk_buff *skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003797 unsigned int i, j;
3798 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003799 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003800 boolean_t cleaned = FALSE;
3801
3802 i = rx_ring->next_to_clean;
3803 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003804 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07003805 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003806
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003807 while (staterr & E1000_RXD_STAT_DD) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003808 ps_page = &rx_ring->ps_page[i];
3809 ps_page_dma = &rx_ring->ps_page_dma[i];
3810#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003811 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003812 break;
3813 (*work_done)++;
3814#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003815 skb = buffer_info->skb;
3816
Jeff Kirsher30320be2006-03-02 18:21:57 -08003817 /* in the packet split case this is header only */
3818 prefetch(skb->data - NET_IP_ALIGN);
3819
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003820 if (++i == rx_ring->count) i = 0;
3821 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003822 prefetch(next_rxd);
3823
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003824 next_buffer = &rx_ring->buffer_info[i];
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003825
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003826 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003827 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003828 pci_unmap_single(pdev, buffer_info->dma,
3829 buffer_info->length,
3830 PCI_DMA_FROMDEVICE);
3831
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003832 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003833 E1000_DBG("%s: Packet Split buffers didn't pick up"
3834 " the full packet\n", netdev->name);
3835 dev_kfree_skb_irq(skb);
3836 goto next_desc;
3837 }
3838
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003839 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003840 dev_kfree_skb_irq(skb);
3841 goto next_desc;
3842 }
3843
3844 length = le16_to_cpu(rx_desc->wb.middle.length0);
3845
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003846 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003847 E1000_DBG("%s: Last part of the packet spanning"
3848 " multiple descriptors\n", netdev->name);
3849 dev_kfree_skb_irq(skb);
3850 goto next_desc;
3851 }
3852
3853 /* Good Receive */
3854 skb_put(skb, length);
3855
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003856 {
3857 /* this looks ugly, but it seems compiler issues make it
3858 more efficient than reusing j */
3859 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3860
3861 /* page alloc/put takes too long and effects small packet
3862 * throughput, so unsplit small packets and save the alloc/put*/
Auke Kok9e2feac2006-04-14 19:05:18 -07003863 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003864 u8 *vaddr;
Auke Kok76c224b2006-05-23 13:36:06 -07003865 /* there is no documentation about how to call
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003866 * kmap_atomic, so we can't hold the mapping
3867 * very long */
3868 pci_dma_sync_single_for_cpu(pdev,
3869 ps_page_dma->ps_page_dma[0],
3870 PAGE_SIZE,
3871 PCI_DMA_FROMDEVICE);
3872 vaddr = kmap_atomic(ps_page->ps_page[0],
3873 KM_SKB_DATA_SOFTIRQ);
3874 memcpy(skb->tail, vaddr, l1);
3875 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
3876 pci_dma_sync_single_for_device(pdev,
3877 ps_page_dma->ps_page_dma[0],
3878 PAGE_SIZE, PCI_DMA_FROMDEVICE);
Auke Kokf235a2a2006-07-14 16:14:34 -07003879 /* remove the CRC */
3880 l1 -= 4;
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003881 skb_put(skb, l1);
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003882 goto copydone;
3883 } /* if */
3884 }
3885
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003886 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08003887 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003888 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003889 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3890 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3891 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08003892 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
3893 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003894 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003895 skb->len += length;
3896 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07003897 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003898 }
3899
Auke Kokf235a2a2006-07-14 16:14:34 -07003900 /* strip the ethernet crc, problem is we're using pages now so
3901 * this whole operation can get a little cpu intensive */
3902 pskb_trim(skb, skb->len - 4);
3903
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003904copydone:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003905 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003906 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003907 skb->protocol = eth_type_trans(skb, netdev);
3908
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003909 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003910 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003911 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003912#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003913 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003914 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003915 le16_to_cpu(rx_desc->wb.middle.vlan) &
3916 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003917 } else {
3918 netif_receive_skb(skb);
3919 }
3920#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003921 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003922 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003923 le16_to_cpu(rx_desc->wb.middle.vlan) &
3924 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003925 } else {
3926 netif_rx(skb);
3927 }
3928#endif /* CONFIG_E1000_NAPI */
3929 netdev->last_rx = jiffies;
3930
3931next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003932 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003933 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003934
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003935 /* return some buffers to hardware, one at a time is too slow */
3936 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3937 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3938 cleaned_count = 0;
3939 }
3940
Jeff Kirsher30320be2006-03-02 18:21:57 -08003941 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003942 rx_desc = next_rxd;
3943 buffer_info = next_buffer;
3944
Malli Chilakala683a38f2005-06-17 17:43:25 -07003945 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003946 }
3947 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003948
3949 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3950 if (cleaned_count)
3951 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003952
3953 return cleaned;
3954}
3955
3956/**
3957 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958 * @adapter: address of board private structure
3959 **/
3960
3961static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003962e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003963 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08003964 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 struct net_device *netdev = adapter->netdev;
3967 struct pci_dev *pdev = adapter->pdev;
3968 struct e1000_rx_desc *rx_desc;
3969 struct e1000_buffer *buffer_info;
3970 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003971 unsigned int i;
3972 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973
3974 i = rx_ring->next_to_use;
3975 buffer_info = &rx_ring->buffer_info[i];
3976
Jeff Kirshera292ca62006-01-12 16:51:30 -08003977 while (cleaned_count--) {
3978 if (!(skb = buffer_info->skb))
David S. Miller87f50322006-07-31 22:39:40 -07003979 skb = netdev_alloc_skb(netdev, bufsz);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003980 else {
3981 skb_trim(skb, 0);
3982 goto map_skb;
3983 }
3984
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003985 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003987 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 break;
3989 }
3990
Malli Chilakala26483452005-04-28 19:44:46 -07003991 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3993 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003994 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3995 "at %p\n", bufsz, skb->data);
3996 /* Try again, without freeing the previous */
David S. Miller87f50322006-07-31 22:39:40 -07003997 skb = netdev_alloc_skb(netdev, bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07003998 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 if (!skb) {
4000 dev_kfree_skb(oldskb);
4001 break;
4002 }
Malli Chilakala26483452005-04-28 19:44:46 -07004003
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4005 /* give up */
4006 dev_kfree_skb(skb);
4007 dev_kfree_skb(oldskb);
4008 break; /* while !buffer_info->skb */
4009 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07004010 /* Use new allocation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 dev_kfree_skb(oldskb);
4012 }
4013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 /* Make buffer alignment 2 beyond a 16 byte boundary
4015 * this will result in a 16 byte aligned IP header after
4016 * the 14 byte MAC header is removed
4017 */
4018 skb_reserve(skb, NET_IP_ALIGN);
4019
4020 skb->dev = netdev;
4021
4022 buffer_info->skb = skb;
4023 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08004024map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 buffer_info->dma = pci_map_single(pdev,
4026 skb->data,
4027 adapter->rx_buffer_len,
4028 PCI_DMA_FROMDEVICE);
4029
Malli Chilakala26483452005-04-28 19:44:46 -07004030 /* Fix for errata 23, can't cross 64kB boundary */
4031 if (!e1000_check_64k_bound(adapter,
4032 (void *)(unsigned long)buffer_info->dma,
4033 adapter->rx_buffer_len)) {
4034 DPRINTK(RX_ERR, ERR,
4035 "dma align check failed: %u bytes at %p\n",
4036 adapter->rx_buffer_len,
4037 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 dev_kfree_skb(skb);
4039 buffer_info->skb = NULL;
4040
Malli Chilakala26483452005-04-28 19:44:46 -07004041 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 adapter->rx_buffer_len,
4043 PCI_DMA_FROMDEVICE);
4044
4045 break; /* while !buffer_info->skb */
4046 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 rx_desc = E1000_RX_DESC(*rx_ring, i);
4048 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4049
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004050 if (unlikely(++i == rx_ring->count))
4051 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 buffer_info = &rx_ring->buffer_info[i];
4053 }
4054
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004055 if (likely(rx_ring->next_to_use != i)) {
4056 rx_ring->next_to_use = i;
4057 if (unlikely(i-- == 0))
4058 i = (rx_ring->count - 1);
4059
4060 /* Force memory writes to complete before letting h/w
4061 * know there are new descriptors to fetch. (Only
4062 * applicable for weak-ordered memory model archs,
4063 * such as IA-64). */
4064 wmb();
4065 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067}
4068
4069/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004070 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
4071 * @adapter: address of board private structure
4072 **/
4073
4074static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04004075e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004076 struct e1000_rx_ring *rx_ring,
4077 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004078{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004079 struct net_device *netdev = adapter->netdev;
4080 struct pci_dev *pdev = adapter->pdev;
4081 union e1000_rx_desc_packet_split *rx_desc;
4082 struct e1000_buffer *buffer_info;
4083 struct e1000_ps_page *ps_page;
4084 struct e1000_ps_page_dma *ps_page_dma;
4085 struct sk_buff *skb;
4086 unsigned int i, j;
4087
4088 i = rx_ring->next_to_use;
4089 buffer_info = &rx_ring->buffer_info[i];
4090 ps_page = &rx_ring->ps_page[i];
4091 ps_page_dma = &rx_ring->ps_page_dma[i];
4092
Jeff Kirsher72d64a42006-01-12 16:51:19 -08004093 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004094 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
4095
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004096 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004097 if (j < adapter->rx_ps_pages) {
4098 if (likely(!ps_page->ps_page[j])) {
4099 ps_page->ps_page[j] =
4100 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004101 if (unlikely(!ps_page->ps_page[j])) {
4102 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004103 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004104 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004105 ps_page_dma->ps_page_dma[j] =
4106 pci_map_page(pdev,
4107 ps_page->ps_page[j],
4108 0, PAGE_SIZE,
4109 PCI_DMA_FROMDEVICE);
4110 }
4111 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004112 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004113 * this info.
4114 */
4115 rx_desc->read.buffer_addr[j+1] =
4116 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4117 } else
4118 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004119 }
4120
David S. Miller87f50322006-07-31 22:39:40 -07004121 skb = netdev_alloc_skb(netdev,
4122 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004123
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004124 if (unlikely(!skb)) {
4125 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004126 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004127 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004128
4129 /* Make buffer alignment 2 beyond a 16 byte boundary
4130 * this will result in a 16 byte aligned IP header after
4131 * the 14 byte MAC header is removed
4132 */
4133 skb_reserve(skb, NET_IP_ALIGN);
4134
4135 skb->dev = netdev;
4136
4137 buffer_info->skb = skb;
4138 buffer_info->length = adapter->rx_ps_bsize0;
4139 buffer_info->dma = pci_map_single(pdev, skb->data,
4140 adapter->rx_ps_bsize0,
4141 PCI_DMA_FROMDEVICE);
4142
4143 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4144
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004145 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004146 buffer_info = &rx_ring->buffer_info[i];
4147 ps_page = &rx_ring->ps_page[i];
4148 ps_page_dma = &rx_ring->ps_page_dma[i];
4149 }
4150
4151no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004152 if (likely(rx_ring->next_to_use != i)) {
4153 rx_ring->next_to_use = i;
4154 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4155
4156 /* Force memory writes to complete before letting h/w
4157 * know there are new descriptors to fetch. (Only
4158 * applicable for weak-ordered memory model archs,
4159 * such as IA-64). */
4160 wmb();
4161 /* Hardware increments by 16 bytes, but packet split
4162 * descriptors are 32 bytes...so we increment tail
4163 * twice as much.
4164 */
4165 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4166 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004167}
4168
4169/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4171 * @adapter:
4172 **/
4173
4174static void
4175e1000_smartspeed(struct e1000_adapter *adapter)
4176{
4177 uint16_t phy_status;
4178 uint16_t phy_ctrl;
4179
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004180 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4182 return;
4183
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004184 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 /* If Master/Slave config fault is asserted twice,
4186 * we assume back-to-back */
4187 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004188 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004190 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004192 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4194 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4195 phy_ctrl);
4196 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004197 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4199 &phy_ctrl)) {
4200 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4201 MII_CR_RESTART_AUTO_NEG);
4202 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4203 phy_ctrl);
4204 }
4205 }
4206 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004207 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 /* If still no link, perhaps using 2/3 pair cable */
4209 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4210 phy_ctrl |= CR_1000T_MS_ENABLE;
4211 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004212 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4214 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4215 MII_CR_RESTART_AUTO_NEG);
4216 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4217 }
4218 }
4219 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004220 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 adapter->smartspeed = 0;
4222}
4223
4224/**
4225 * e1000_ioctl -
4226 * @netdev:
4227 * @ifreq:
4228 * @cmd:
4229 **/
4230
4231static int
4232e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4233{
4234 switch (cmd) {
4235 case SIOCGMIIPHY:
4236 case SIOCGMIIREG:
4237 case SIOCSMIIREG:
4238 return e1000_mii_ioctl(netdev, ifr, cmd);
4239 default:
4240 return -EOPNOTSUPP;
4241 }
4242}
4243
4244/**
4245 * e1000_mii_ioctl -
4246 * @netdev:
4247 * @ifreq:
4248 * @cmd:
4249 **/
4250
4251static int
4252e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4253{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004254 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255 struct mii_ioctl_data *data = if_mii(ifr);
4256 int retval;
4257 uint16_t mii_reg;
4258 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004259 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004261 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 return -EOPNOTSUPP;
4263
4264 switch (cmd) {
4265 case SIOCGMIIPHY:
4266 data->phy_id = adapter->hw.phy_addr;
4267 break;
4268 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004269 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004271 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004272 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004273 &data->val_out)) {
4274 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004276 }
4277 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 break;
4279 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004280 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004282 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 return -EFAULT;
4284 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004285 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004286 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004287 mii_reg)) {
4288 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004290 }
Auke Kokdc86d322006-04-18 12:30:51 -07004291 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 switch (data->reg_num) {
4293 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004294 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004296 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 adapter->hw.autoneg = 1;
4298 adapter->hw.autoneg_advertised = 0x2F;
4299 } else {
4300 if (mii_reg & 0x40)
4301 spddplx = SPEED_1000;
4302 else if (mii_reg & 0x2000)
4303 spddplx = SPEED_100;
4304 else
4305 spddplx = SPEED_10;
4306 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004307 ? DUPLEX_FULL :
4308 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 retval = e1000_set_spd_dplx(adapter,
4310 spddplx);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004311 if (retval) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004312 spin_unlock_irqrestore(
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004313 &adapter->stats_lock,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004314 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 }
Auke Kok2db10a02006-06-27 09:06:28 -07004318 if (netif_running(adapter->netdev))
4319 e1000_reinit_locked(adapter);
4320 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 e1000_reset(adapter);
4322 break;
4323 case M88E1000_PHY_SPEC_CTRL:
4324 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004325 if (e1000_phy_reset(&adapter->hw)) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004326 spin_unlock_irqrestore(
4327 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 break;
4331 }
4332 } else {
4333 switch (data->reg_num) {
4334 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004335 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 break;
Auke Kok2db10a02006-06-27 09:06:28 -07004337 if (netif_running(adapter->netdev))
4338 e1000_reinit_locked(adapter);
4339 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340 e1000_reset(adapter);
4341 break;
4342 }
4343 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004344 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 break;
4346 default:
4347 return -EOPNOTSUPP;
4348 }
4349 return E1000_SUCCESS;
4350}
4351
4352void
4353e1000_pci_set_mwi(struct e1000_hw *hw)
4354{
4355 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004356 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004358 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004359 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360}
4361
4362void
4363e1000_pci_clear_mwi(struct e1000_hw *hw)
4364{
4365 struct e1000_adapter *adapter = hw->back;
4366
4367 pci_clear_mwi(adapter->pdev);
4368}
4369
4370void
4371e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4372{
4373 struct e1000_adapter *adapter = hw->back;
4374
4375 pci_read_config_word(adapter->pdev, reg, value);
4376}
4377
4378void
4379e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4380{
4381 struct e1000_adapter *adapter = hw->back;
4382
4383 pci_write_config_word(adapter->pdev, reg, *value);
4384}
4385
Adrian Bunke4c780b2006-08-14 23:00:10 -07004386#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387uint32_t
4388e1000_io_read(struct e1000_hw *hw, unsigned long port)
4389{
4390 return inl(port);
4391}
Adrian Bunke4c780b2006-08-14 23:00:10 -07004392#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393
4394void
4395e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4396{
4397 outl(value, port);
4398}
4399
4400static void
4401e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4402{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004403 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 uint32_t ctrl, rctl;
4405
4406 e1000_irq_disable(adapter);
4407 adapter->vlgrp = grp;
4408
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004409 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 /* enable VLAN tag insert/strip */
4411 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4412 ctrl |= E1000_CTRL_VME;
4413 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4414
Auke Kokcd94dd02006-06-27 09:08:22 -07004415 if (adapter->hw.mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 /* enable VLAN receive filtering */
4417 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4418 rctl |= E1000_RCTL_VFE;
4419 rctl &= ~E1000_RCTL_CFIEN;
4420 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004421 e1000_update_mng_vlan(adapter);
Auke Kokcd94dd02006-06-27 09:08:22 -07004422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 } else {
4424 /* disable VLAN tag insert/strip */
4425 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4426 ctrl &= ~E1000_CTRL_VME;
4427 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4428
Auke Kokcd94dd02006-06-27 09:08:22 -07004429 if (adapter->hw.mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 /* disable VLAN filtering */
4431 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4432 rctl &= ~E1000_RCTL_VFE;
4433 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004434 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004435 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4436 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4437 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 }
4440
4441 e1000_irq_enable(adapter);
4442}
4443
4444static void
4445e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4446{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004447 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004449
4450 if ((adapter->hw.mng_cookie.status &
4451 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4452 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004453 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 /* add VID to filter table */
4455 index = (vid >> 5) & 0x7F;
4456 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4457 vfta |= (1 << (vid & 0x1F));
4458 e1000_write_vfta(&adapter->hw, index, vfta);
4459}
4460
4461static void
4462e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4463{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004464 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 uint32_t vfta, index;
4466
4467 e1000_irq_disable(adapter);
4468
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004469 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 adapter->vlgrp->vlan_devices[vid] = NULL;
4471
4472 e1000_irq_enable(adapter);
4473
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004474 if ((adapter->hw.mng_cookie.status &
4475 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004476 (vid == adapter->mng_vlan_id)) {
4477 /* release control to f/w */
4478 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004479 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004480 }
4481
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 /* remove VID from filter table */
4483 index = (vid >> 5) & 0x7F;
4484 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4485 vfta &= ~(1 << (vid & 0x1F));
4486 e1000_write_vfta(&adapter->hw, index, vfta);
4487}
4488
4489static void
4490e1000_restore_vlan(struct e1000_adapter *adapter)
4491{
4492 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4493
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004494 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004496 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4497 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498 continue;
4499 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4500 }
4501 }
4502}
4503
4504int
4505e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4506{
4507 adapter->hw.autoneg = 0;
4508
Malli Chilakala69213682005-06-17 17:44:20 -07004509 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004510 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004511 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4512 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4513 return -EINVAL;
4514 }
4515
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004516 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 case SPEED_10 + DUPLEX_HALF:
4518 adapter->hw.forced_speed_duplex = e1000_10_half;
4519 break;
4520 case SPEED_10 + DUPLEX_FULL:
4521 adapter->hw.forced_speed_duplex = e1000_10_full;
4522 break;
4523 case SPEED_100 + DUPLEX_HALF:
4524 adapter->hw.forced_speed_duplex = e1000_100_half;
4525 break;
4526 case SPEED_100 + DUPLEX_FULL:
4527 adapter->hw.forced_speed_duplex = e1000_100_full;
4528 break;
4529 case SPEED_1000 + DUPLEX_FULL:
4530 adapter->hw.autoneg = 1;
4531 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4532 break;
4533 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4534 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004535 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 return -EINVAL;
4537 }
4538 return 0;
4539}
4540
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004541#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004542/* Save/restore 16 or 64 dwords of PCI config space depending on which
4543 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004544 */
4545#define PCIE_CONFIG_SPACE_LEN 256
4546#define PCI_CONFIG_SPACE_LEN 64
4547static int
4548e1000_pci_save_state(struct e1000_adapter *adapter)
4549{
4550 struct pci_dev *dev = adapter->pdev;
4551 int size;
4552 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004553
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004554 if (adapter->hw.mac_type >= e1000_82571)
4555 size = PCIE_CONFIG_SPACE_LEN;
4556 else
4557 size = PCI_CONFIG_SPACE_LEN;
4558
4559 WARN_ON(adapter->config_space != NULL);
4560
4561 adapter->config_space = kmalloc(size, GFP_KERNEL);
4562 if (!adapter->config_space) {
4563 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4564 return -ENOMEM;
4565 }
4566 for (i = 0; i < (size / 4); i++)
4567 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4568 return 0;
4569}
4570
4571static void
4572e1000_pci_restore_state(struct e1000_adapter *adapter)
4573{
4574 struct pci_dev *dev = adapter->pdev;
4575 int size;
4576 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004577
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004578 if (adapter->config_space == NULL)
4579 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004580
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004581 if (adapter->hw.mac_type >= e1000_82571)
4582 size = PCIE_CONFIG_SPACE_LEN;
4583 else
4584 size = PCI_CONFIG_SPACE_LEN;
4585 for (i = 0; i < (size / 4); i++)
4586 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4587 kfree(adapter->config_space);
4588 adapter->config_space = NULL;
4589 return;
4590}
4591#endif /* CONFIG_PM */
4592
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004594e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595{
4596 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004597 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004598 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599 uint32_t wufc = adapter->wol;
Auke Kok6fdfef12006-06-27 09:06:36 -07004600#ifdef CONFIG_PM
Jeff Kirsher240b1712006-01-12 16:51:28 -08004601 int retval = 0;
Auke Kok6fdfef12006-06-27 09:06:36 -07004602#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603
4604 netif_device_detach(netdev);
4605
Auke Kok2db10a02006-06-27 09:06:28 -07004606 if (netif_running(netdev)) {
4607 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 e1000_down(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07004609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004611#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004612 /* Implement our own version of pci_save_state(pdev) because pci-
4613 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004614 retval = e1000_pci_save_state(adapter);
4615 if (retval)
4616 return retval;
4617#endif
4618
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004620 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 wufc &= ~E1000_WUFC_LNKC;
4622
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004623 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 e1000_setup_rctl(adapter);
4625 e1000_set_multi(netdev);
4626
4627 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004628 if (adapter->wol & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4630 rctl |= E1000_RCTL_MPE;
4631 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4632 }
4633
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004634 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4636 /* advertise wake from D3Cold */
4637 #define E1000_CTRL_ADVD3WUC 0x00100000
4638 /* phy power management enable */
4639 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4640 ctrl |= E1000_CTRL_ADVD3WUC |
4641 E1000_CTRL_EN_PHY_PWR_MGMT;
4642 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4643 }
4644
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004645 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4647 /* keep the laser running in D3 */
4648 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4649 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4650 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4651 }
4652
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004653 /* Allow time for pending master requests to run */
4654 e1000_disable_pciex_master(&adapter->hw);
4655
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4657 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004658 pci_enable_wake(pdev, PCI_D3hot, 1);
4659 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 } else {
4661 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4662 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07004663 pci_enable_wake(pdev, PCI_D3hot, 0);
4664 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 }
4666
Auke Kokcd94dd02006-06-27 09:08:22 -07004667 /* FIXME: this code is incorrect for PCI Express */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004668 if (adapter->hw.mac_type >= e1000_82540 &&
Auke Kokcd94dd02006-06-27 09:08:22 -07004669 adapter->hw.mac_type != e1000_ich8lan &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 adapter->hw.media_type == e1000_media_type_copper) {
4671 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004672 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673 manc |= E1000_MANC_ARP_EN;
4674 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004675 pci_enable_wake(pdev, PCI_D3hot, 1);
4676 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677 }
4678 }
4679
Auke Kokcd94dd02006-06-27 09:08:22 -07004680 if (adapter->hw.phy_type == e1000_phy_igp_3)
4681 e1000_phy_powerdown_workaround(&adapter->hw);
4682
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004683 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4684 * would have already happened in close and is redundant. */
4685 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004686
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004688
Auke Kokd0e027d2006-04-14 19:04:40 -07004689 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690
4691 return 0;
4692}
4693
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004694#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695static int
4696e1000_resume(struct pci_dev *pdev)
4697{
4698 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004699 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004700 uint32_t manc, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701
Auke Kokd0e027d2006-04-14 19:04:40 -07004702 pci_set_power_state(pdev, PCI_D0);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004703 e1000_pci_restore_state(adapter);
Malli Chilakala2b028932005-06-17 17:46:06 -07004704 ret_val = pci_enable_device(pdev);
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004705 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706
Auke Kokd0e027d2006-04-14 19:04:40 -07004707 pci_enable_wake(pdev, PCI_D3hot, 0);
4708 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709
4710 e1000_reset(adapter);
4711 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4712
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004713 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714 e1000_up(adapter);
4715
4716 netif_device_attach(netdev);
4717
Auke Kokcd94dd02006-06-27 09:08:22 -07004718 /* FIXME: this code is incorrect for PCI Express */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004719 if (adapter->hw.mac_type >= e1000_82540 &&
Auke Kokcd94dd02006-06-27 09:08:22 -07004720 adapter->hw.mac_type != e1000_ich8lan &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 adapter->hw.media_type == e1000_media_type_copper) {
4722 manc = E1000_READ_REG(&adapter->hw, MANC);
4723 manc &= ~(E1000_MANC_ARP_EN);
4724 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4725 }
4726
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004727 /* If the controller is 82573 and f/w is AMT, do not set
4728 * DRV_LOAD until the interface is up. For all other cases,
4729 * let the f/w know that the h/w is now under the control
4730 * of the driver. */
4731 if (adapter->hw.mac_type != e1000_82573 ||
4732 !e1000_check_mng_mode(&adapter->hw))
4733 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004734
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 return 0;
4736}
4737#endif
Auke Kokc653e632006-05-23 13:35:57 -07004738
4739static void e1000_shutdown(struct pci_dev *pdev)
4740{
4741 e1000_suspend(pdev, PMSG_SUSPEND);
4742}
4743
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744#ifdef CONFIG_NET_POLL_CONTROLLER
4745/*
4746 * Polling 'interrupt' - used by things like netconsole to send skbs
4747 * without having to re-enable interrupts. It's not called while
4748 * the interrupt routine is executing.
4749 */
4750static void
Malli Chilakala26483452005-04-28 19:44:46 -07004751e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004753 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokd3d9e482006-07-14 16:14:23 -07004754
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 disable_irq(adapter->pdev->irq);
4756 e1000_intr(adapter->pdev->irq, netdev, NULL);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004757 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004758#ifndef CONFIG_E1000_NAPI
4759 adapter->clean_rx(adapter, adapter->rx_ring);
4760#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761 enable_irq(adapter->pdev->irq);
4762}
4763#endif
4764
Auke Kok90267292006-06-08 09:30:24 -07004765/**
4766 * e1000_io_error_detected - called when PCI error is detected
4767 * @pdev: Pointer to PCI device
4768 * @state: The current pci conneection state
4769 *
4770 * This function is called after a PCI bus error affecting
4771 * this device has been detected.
4772 */
4773static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4774{
4775 struct net_device *netdev = pci_get_drvdata(pdev);
4776 struct e1000_adapter *adapter = netdev->priv;
4777
4778 netif_device_detach(netdev);
4779
4780 if (netif_running(netdev))
4781 e1000_down(adapter);
4782
4783 /* Request a slot slot reset. */
4784 return PCI_ERS_RESULT_NEED_RESET;
4785}
4786
4787/**
4788 * e1000_io_slot_reset - called after the pci bus has been reset.
4789 * @pdev: Pointer to PCI device
4790 *
4791 * Restart the card from scratch, as if from a cold-boot. Implementation
4792 * resembles the first-half of the e1000_resume routine.
4793 */
4794static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4795{
4796 struct net_device *netdev = pci_get_drvdata(pdev);
4797 struct e1000_adapter *adapter = netdev->priv;
4798
4799 if (pci_enable_device(pdev)) {
4800 printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
4801 return PCI_ERS_RESULT_DISCONNECT;
4802 }
4803 pci_set_master(pdev);
4804
4805 pci_enable_wake(pdev, 3, 0);
4806 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
4807
4808 /* Perform card reset only on one instance of the card */
4809 if (PCI_FUNC (pdev->devfn) != 0)
4810 return PCI_ERS_RESULT_RECOVERED;
4811
4812 e1000_reset(adapter);
4813 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4814
4815 return PCI_ERS_RESULT_RECOVERED;
4816}
4817
4818/**
4819 * e1000_io_resume - called when traffic can start flowing again.
4820 * @pdev: Pointer to PCI device
4821 *
4822 * This callback is called when the error recovery driver tells us that
4823 * its OK to resume normal operation. Implementation resembles the
4824 * second-half of the e1000_resume routine.
4825 */
4826static void e1000_io_resume(struct pci_dev *pdev)
4827{
4828 struct net_device *netdev = pci_get_drvdata(pdev);
4829 struct e1000_adapter *adapter = netdev->priv;
4830 uint32_t manc, swsm;
4831
4832 if (netif_running(netdev)) {
4833 if (e1000_up(adapter)) {
4834 printk("e1000: can't bring device back up after reset\n");
4835 return;
4836 }
4837 }
4838
4839 netif_device_attach(netdev);
4840
4841 if (adapter->hw.mac_type >= e1000_82540 &&
4842 adapter->hw.media_type == e1000_media_type_copper) {
4843 manc = E1000_READ_REG(&adapter->hw, MANC);
4844 manc &= ~(E1000_MANC_ARP_EN);
4845 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4846 }
4847
4848 switch (adapter->hw.mac_type) {
4849 case e1000_82573:
4850 swsm = E1000_READ_REG(&adapter->hw, SWSM);
4851 E1000_WRITE_REG(&adapter->hw, SWSM,
4852 swsm | E1000_SWSM_DRV_LOAD);
4853 break;
4854 default:
4855 break;
4856 }
4857
4858 if (netif_running(netdev))
4859 mod_timer(&adapter->watchdog_timer, jiffies);
4860}
4861
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862/* e1000_main.c */