blob: 2b8bced0cf64f7f95f50e860ad9d9d38a5d70683 [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
32/* Change Log
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -080033 * 7.0.33 3-Feb-2006
34 * o Added another fix for the pass false carrier bit
35 * 7.0.32 24-Jan-2006
36 * o Need to rebuild with noew version number for the pass false carrier
37 * fix in e1000_hw.c
38 * 7.0.30 18-Jan-2006
39 * o fixup for tso workaround to disable it for pci-x
40 * o fix mem leak on 82542
41 * o fixes for 10 Mb/s connections and incorrect stats
42 * 7.0.28 01/06/2006
43 * o hardware workaround to only set "speed mode" bit for 1G link.
44 * 7.0.26 12/23/2005
45 * o wake on lan support modified for device ID 10B5
46 * o fix dhcp + vlan issue not making it to the iAMT firmware
47 * 7.0.24 12/9/2005
48 * o New hardware support for the Gigabit NIC embedded in the south bridge
49 * o Fixes to the recycling logic (skb->tail) from IBM LTC
Jesse Brandeburg73629bb2006-01-18 13:01:41 -080050 * 6.3.9 12/16/2005
51 * o incorporate fix for recycled skbs from IBM LTC
52 * 6.3.7 11/18/2005
53 * o Honor eeprom setting for enabling/disabling Wake On Lan
54 * 6.3.5 11/17/2005
55 * o Fix memory leak in rx ring handling for PCI Express adapters
56 * 6.3.4 11/8/05
57 * o Patch from Jesper Juhl to remove redundant NULL checks for kfree
58 * 6.3.2 9/20/05
59 * o Render logic that sets/resets DRV_LOAD as inline functions to
60 * avoid code replication. If f/w is AMT then set DRV_LOAD only when
61 * network interface is open.
62 * o Handle DRV_LOAD set/reset in cases where AMT uses VLANs.
63 * o Adjust PBA partioning for Jumbo frames using MTU size and not
64 * rx_buffer_len
65 * 6.3.1 9/19/05
66 * o Use adapter->tx_timeout_factor in Tx Hung Detect logic
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -080067 * (e1000_clean_tx_irq)
Jesse Brandeburg73629bb2006-01-18 13:01:41 -080068 * o Support for 8086:10B5 device (Quad Port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 */
70
71char e1000_driver_name[] = "e1000";
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010072static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#ifndef CONFIG_E1000_NAPI
74#define DRIVERNAPI
75#else
76#define DRIVERNAPI "-NAPI"
77#endif
Auke Kok3d41e302006-04-14 19:05:31 -070078#define DRV_VERSION "7.0.38-k2"DRIVERNAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -070079char e1000_driver_version[] = DRV_VERSION;
Auke Kok3d41e302006-04-14 19:05:31 -070080static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/* e1000_pci_tbl - PCI Device ID Table
83 *
84 * Last entry must be all 0s
85 *
86 * Macro expands to...
87 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
88 */
89static struct pci_device_id e1000_pci_tbl[] = {
90 INTEL_E1000_ETHERNET_DEVICE(0x1000),
91 INTEL_E1000_ETHERNET_DEVICE(0x1001),
92 INTEL_E1000_ETHERNET_DEVICE(0x1004),
93 INTEL_E1000_ETHERNET_DEVICE(0x1008),
94 INTEL_E1000_ETHERNET_DEVICE(0x1009),
95 INTEL_E1000_ETHERNET_DEVICE(0x100C),
96 INTEL_E1000_ETHERNET_DEVICE(0x100D),
97 INTEL_E1000_ETHERNET_DEVICE(0x100E),
98 INTEL_E1000_ETHERNET_DEVICE(0x100F),
99 INTEL_E1000_ETHERNET_DEVICE(0x1010),
100 INTEL_E1000_ETHERNET_DEVICE(0x1011),
101 INTEL_E1000_ETHERNET_DEVICE(0x1012),
102 INTEL_E1000_ETHERNET_DEVICE(0x1013),
103 INTEL_E1000_ETHERNET_DEVICE(0x1014),
104 INTEL_E1000_ETHERNET_DEVICE(0x1015),
105 INTEL_E1000_ETHERNET_DEVICE(0x1016),
106 INTEL_E1000_ETHERNET_DEVICE(0x1017),
107 INTEL_E1000_ETHERNET_DEVICE(0x1018),
108 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -0700109 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 INTEL_E1000_ETHERNET_DEVICE(0x101D),
111 INTEL_E1000_ETHERNET_DEVICE(0x101E),
112 INTEL_E1000_ETHERNET_DEVICE(0x1026),
113 INTEL_E1000_ETHERNET_DEVICE(0x1027),
114 INTEL_E1000_ETHERNET_DEVICE(0x1028),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400115 INTEL_E1000_ETHERNET_DEVICE(0x105E),
116 INTEL_E1000_ETHERNET_DEVICE(0x105F),
117 INTEL_E1000_ETHERNET_DEVICE(0x1060),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 INTEL_E1000_ETHERNET_DEVICE(0x1075),
119 INTEL_E1000_ETHERNET_DEVICE(0x1076),
120 INTEL_E1000_ETHERNET_DEVICE(0x1077),
121 INTEL_E1000_ETHERNET_DEVICE(0x1078),
122 INTEL_E1000_ETHERNET_DEVICE(0x1079),
123 INTEL_E1000_ETHERNET_DEVICE(0x107A),
124 INTEL_E1000_ETHERNET_DEVICE(0x107B),
125 INTEL_E1000_ETHERNET_DEVICE(0x107C),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400126 INTEL_E1000_ETHERNET_DEVICE(0x107D),
127 INTEL_E1000_ETHERNET_DEVICE(0x107E),
128 INTEL_E1000_ETHERNET_DEVICE(0x107F),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Malli Chilakala26483452005-04-28 19:44:46 -0700130 INTEL_E1000_ETHERNET_DEVICE(0x108B),
131 INTEL_E1000_ETHERNET_DEVICE(0x108C),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800132 INTEL_E1000_ETHERNET_DEVICE(0x1096),
133 INTEL_E1000_ETHERNET_DEVICE(0x1098),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800134 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400135 INTEL_E1000_ETHERNET_DEVICE(0x109A),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800136 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800137 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 /* required last entry */
139 {0,}
140};
141
142MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
143
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100144static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800145 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100146static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800147 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100148static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800149 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100150static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800151 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153/* Local Function Prototypes */
154
155static int e1000_init_module(void);
156static void e1000_exit_module(void);
157static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
158static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400159static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160static int e1000_sw_init(struct e1000_adapter *adapter);
161static int e1000_open(struct net_device *netdev);
162static int e1000_close(struct net_device *netdev);
163static void e1000_configure_tx(struct e1000_adapter *adapter);
164static void e1000_configure_rx(struct e1000_adapter *adapter);
165static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400166static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
167static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
168static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
169 struct e1000_tx_ring *tx_ring);
170static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
171 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172static void e1000_set_multi(struct net_device *netdev);
173static void e1000_update_phy_info(unsigned long data);
174static void e1000_watchdog(unsigned long data);
175static void e1000_watchdog_task(struct e1000_adapter *adapter);
176static void e1000_82547_tx_fifo_stall(unsigned long data);
177static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
178static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
179static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
180static int e1000_set_mac(struct net_device *netdev, void *p);
181static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400182static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
183 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400185static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400187 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700189static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400190 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700191 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400193static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
194 struct e1000_rx_ring *rx_ring);
195static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
196 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400198static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800199 struct e1000_rx_ring *rx_ring,
200 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400201static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800202 struct e1000_rx_ring *rx_ring,
203 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
205static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
206 int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
208static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
209static void e1000_tx_timeout(struct net_device *dev);
Jeff Kirsher87041632006-03-02 18:21:24 -0800210static void e1000_reset_task(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211static void e1000_smartspeed(struct e1000_adapter *adapter);
Auke Koke619d522006-04-14 19:04:52 -0700212static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
213 struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
216static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
217static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
218static void e1000_restore_vlan(struct e1000_adapter *adapter);
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#ifdef CONFIG_PM
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700221static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222static int e1000_resume(struct pci_dev *pdev);
223#endif
224
225#ifdef CONFIG_NET_POLL_CONTROLLER
226/* for netdump / net console */
227static void e1000_netpoll (struct net_device *netdev);
228#endif
229
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231static struct pci_driver e1000_driver = {
232 .name = e1000_driver_name,
233 .id_table = e1000_pci_tbl,
234 .probe = e1000_probe,
235 .remove = __devexit_p(e1000_remove),
236 /* Power Managment Hooks */
237#ifdef CONFIG_PM
238 .suspend = e1000_suspend,
239 .resume = e1000_resume
240#endif
241};
242
243MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
244MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
245MODULE_LICENSE("GPL");
246MODULE_VERSION(DRV_VERSION);
247
248static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
249module_param(debug, int, 0);
250MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
251
252/**
253 * e1000_init_module - Driver Registration Routine
254 *
255 * e1000_init_module is the first routine called when the driver is
256 * loaded. All it does is register with the PCI subsystem.
257 **/
258
259static int __init
260e1000_init_module(void)
261{
262 int ret;
263 printk(KERN_INFO "%s - version %s\n",
264 e1000_driver_string, e1000_driver_version);
265
266 printk(KERN_INFO "%s\n", e1000_copyright);
267
268 ret = pci_module_init(&e1000_driver);
Tony Luck8b378def2005-07-28 01:07:38 -0700269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 return ret;
271}
272
273module_init(e1000_init_module);
274
275/**
276 * e1000_exit_module - Driver Exit Cleanup Routine
277 *
278 * e1000_exit_module is called just before the driver is removed
279 * from memory.
280 **/
281
282static void __exit
283e1000_exit_module(void)
284{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 pci_unregister_driver(&e1000_driver);
286}
287
288module_exit(e1000_exit_module);
289
290/**
291 * e1000_irq_disable - Mask off interrupt generation on the NIC
292 * @adapter: board private structure
293 **/
294
Auke Koke619d522006-04-14 19:04:52 -0700295static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296e1000_irq_disable(struct e1000_adapter *adapter)
297{
298 atomic_inc(&adapter->irq_sem);
299 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
300 E1000_WRITE_FLUSH(&adapter->hw);
301 synchronize_irq(adapter->pdev->irq);
302}
303
304/**
305 * e1000_irq_enable - Enable default interrupt generation settings
306 * @adapter: board private structure
307 **/
308
Auke Koke619d522006-04-14 19:04:52 -0700309static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310e1000_irq_enable(struct e1000_adapter *adapter)
311{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800312 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
314 E1000_WRITE_FLUSH(&adapter->hw);
315 }
316}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100317
318static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700319e1000_update_mng_vlan(struct e1000_adapter *adapter)
320{
321 struct net_device *netdev = adapter->netdev;
322 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
323 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800324 if (adapter->vlgrp) {
325 if (!adapter->vlgrp->vlan_devices[vid]) {
326 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700327 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
328 e1000_vlan_rx_add_vid(netdev, vid);
329 adapter->mng_vlan_id = vid;
330 } else
331 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800332
333 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
334 (vid != old_vid) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700335 !adapter->vlgrp->vlan_devices[old_vid])
336 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800337 } else
338 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700339 }
340}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800341
342/**
343 * e1000_release_hw_control - release control of the h/w to f/w
344 * @adapter: address of board private structure
345 *
346 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
347 * For ASF and Pass Through versions of f/w this means that the
348 * driver is no longer loaded. For AMT version (only with 82573) i
349 * of the f/w this means that the netowrk i/f is closed.
350 *
351 **/
352
Auke Koke619d522006-04-14 19:04:52 -0700353static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800354e1000_release_hw_control(struct e1000_adapter *adapter)
355{
356 uint32_t ctrl_ext;
357 uint32_t swsm;
358
359 /* Let firmware taken over control of h/w */
360 switch (adapter->hw.mac_type) {
361 case e1000_82571:
362 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700363 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800364 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
365 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
366 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
367 break;
368 case e1000_82573:
369 swsm = E1000_READ_REG(&adapter->hw, SWSM);
370 E1000_WRITE_REG(&adapter->hw, SWSM,
371 swsm & ~E1000_SWSM_DRV_LOAD);
372 default:
373 break;
374 }
375}
376
377/**
378 * e1000_get_hw_control - get control of the h/w from f/w
379 * @adapter: address of board private structure
380 *
381 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
382 * For ASF and Pass Through versions of f/w this means that
383 * the driver is loaded. For AMT version (only with 82573)
384 * of the f/w this means that the netowrk i/f is open.
385 *
386 **/
387
Auke Koke619d522006-04-14 19:04:52 -0700388static void
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800389e1000_get_hw_control(struct e1000_adapter *adapter)
390{
391 uint32_t ctrl_ext;
392 uint32_t swsm;
393 /* Let firmware know the driver has taken over */
394 switch (adapter->hw.mac_type) {
395 case e1000_82571:
396 case e1000_82572:
Auke Kok4cc15f52006-04-14 19:04:46 -0700397 case e1000_80003es2lan:
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800398 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
399 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
400 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
401 break;
402 case e1000_82573:
403 swsm = E1000_READ_REG(&adapter->hw, SWSM);
404 E1000_WRITE_REG(&adapter->hw, SWSM,
405 swsm | E1000_SWSM_DRV_LOAD);
406 break;
407 default:
408 break;
409 }
410}
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412int
413e1000_up(struct e1000_adapter *adapter)
414{
415 struct net_device *netdev = adapter->netdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400416 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 /* hardware has been reset, we need to reload some things */
419
420 /* Reset the PHY if it was previously powered down */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800421 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 uint16_t mii_reg;
423 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800424 if (mii_reg & MII_CR_POWER_DOWN)
Auke Kok4cc15f52006-04-14 19:04:46 -0700425 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
427
428 e1000_set_multi(netdev);
429
430 e1000_restore_vlan(adapter);
431
432 e1000_configure_tx(adapter);
433 e1000_setup_rctl(adapter);
434 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800435 /* call E1000_DESC_UNUSED which always leaves
436 * at least 1 descriptor unused to make sure
437 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800438 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800439 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800440 adapter->alloc_rx_buf(adapter, ring,
441 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700444#ifdef CONFIG_PCI_MSI
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800445 if (adapter->hw.mac_type > e1000_82547_rev_2) {
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700446 adapter->have_msi = TRUE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800447 if ((err = pci_enable_msi(adapter->pdev))) {
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700448 DPRINTK(PROBE, ERR,
449 "Unable to allocate MSI interrupt Error: %d\n", err);
450 adapter->have_msi = FALSE;
451 }
452 }
453#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800454 if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 SA_SHIRQ | SA_SAMPLE_RANDOM,
Malli Chilakala26483452005-04-28 19:44:46 -0700456 netdev->name, netdev))) {
457 DPRINTK(PROBE, ERR,
458 "Unable to allocate interrupt Error: %d\n", err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 return err;
Malli Chilakala26483452005-04-28 19:44:46 -0700460 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800462 adapter->tx_queue_len = netdev->tx_queue_len;
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 mod_timer(&adapter->watchdog_timer, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466#ifdef CONFIG_E1000_NAPI
467 netif_poll_enable(netdev);
468#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700469 e1000_irq_enable(adapter);
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return 0;
472}
473
474void
475e1000_down(struct e1000_adapter *adapter)
476{
477 struct net_device *netdev = adapter->netdev;
Jeff Kirsher57128192006-01-12 16:50:28 -0800478 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
479 e1000_check_mng_mode(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 free_irq(adapter->pdev->irq, netdev);
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700484#ifdef CONFIG_PCI_MSI
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800485 if (adapter->hw.mac_type > e1000_82547_rev_2 &&
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700486 adapter->have_msi == TRUE)
487 pci_disable_msi(adapter->pdev);
488#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 del_timer_sync(&adapter->tx_fifo_stall_timer);
490 del_timer_sync(&adapter->watchdog_timer);
491 del_timer_sync(&adapter->phy_info_timer);
492
493#ifdef CONFIG_E1000_NAPI
494 netif_poll_disable(netdev);
495#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800496 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 adapter->link_speed = 0;
498 adapter->link_duplex = 0;
499 netif_carrier_off(netdev);
500 netif_stop_queue(netdev);
501
502 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400503 e1000_clean_all_tx_rings(adapter);
504 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Jeff Kirsher57128192006-01-12 16:50:28 -0800506 /* Power down the PHY so no link is implied when interface is down *
507 * The PHY cannot be powered down if any of the following is TRUE *
508 * (a) WoL is enabled
509 * (b) AMT is active
510 * (c) SoL/IDER session is active */
511 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700512 adapter->hw.media_type == e1000_media_type_copper &&
Jeff Kirsher57128192006-01-12 16:50:28 -0800513 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
514 !mng_mode_enabled &&
515 !e1000_check_phy_reset_block(&adapter->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 uint16_t mii_reg;
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);
Malli Chilakala4e48a2b2005-04-28 19:39:53 -0700520 mdelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522}
523
524void
525e1000_reset(struct e1000_adapter *adapter)
526{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700527 uint32_t pba, manc;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700528 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 /* Repartition Pba for greater than 9k mtu
531 * To take effect CTRL.RST is required.
532 */
533
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700534 switch (adapter->hw.mac_type) {
535 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700536 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700537 pba = E1000_PBA_30K;
538 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400539 case e1000_82571:
540 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800541 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400542 pba = E1000_PBA_38K;
543 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700544 case e1000_82573:
545 pba = E1000_PBA_12K;
546 break;
547 default:
548 pba = E1000_PBA_48K;
549 break;
550 }
551
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800552 if ((adapter->hw.mac_type != e1000_82573) &&
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800553 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700554 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700555
556
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800557 if (adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 adapter->tx_fifo_head = 0;
559 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
560 adapter->tx_fifo_size =
561 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
562 atomic_set(&adapter->tx_fifo_stall, 0);
563 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 E1000_WRITE_REG(&adapter->hw, PBA, pba);
566
567 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800568 /* Set the FC high water mark to 90% of the FIFO size.
569 * Required to clear last 3 LSB */
570 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
571
572 adapter->hw.fc_high_water = fc_high_water_mark;
573 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800574 if (adapter->hw.mac_type == e1000_80003es2lan)
575 adapter->hw.fc_pause_time = 0xFFFF;
576 else
577 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 adapter->hw.fc_send_xon = 1;
579 adapter->hw.fc = adapter->hw.original_fc;
580
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700581 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800583 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800585 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700587 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
589 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
590
591 e1000_reset_adaptive(&adapter->hw);
592 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700593 if (adapter->en_mng_pt) {
594 manc = E1000_READ_REG(&adapter->hw, MANC);
595 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
596 E1000_WRITE_REG(&adapter->hw, MANC, manc);
597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
600/**
601 * e1000_probe - Device Initialization Routine
602 * @pdev: PCI device information struct
603 * @ent: entry in e1000_pci_tbl
604 *
605 * Returns 0 on success, negative on failure
606 *
607 * e1000_probe initializes an adapter identified by a pci_dev structure.
608 * The OS initialization, configuring of the adapter private structure,
609 * and a hardware reset occur.
610 **/
611
612static int __devinit
613e1000_probe(struct pci_dev *pdev,
614 const struct pci_device_id *ent)
615{
616 struct net_device *netdev;
617 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700618 unsigned long mmio_start, mmio_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 static int cards_found = 0;
Jeff Kirsher84916822006-03-02 18:18:48 -0800621 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700622 int i, err, pci_using_dac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 uint16_t eeprom_data;
624 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800625 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 return err;
627
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800628 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 pci_using_dac = 1;
630 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800631 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 E1000_ERR("No usable DMA configuration, aborting\n");
633 return err;
634 }
635 pci_using_dac = 0;
636 }
637
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800638 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return err;
640
641 pci_set_master(pdev);
642
643 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800644 if (!netdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 err = -ENOMEM;
646 goto err_alloc_etherdev;
647 }
648
649 SET_MODULE_OWNER(netdev);
650 SET_NETDEV_DEV(netdev, &pdev->dev);
651
652 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700653 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 adapter->netdev = netdev;
655 adapter->pdev = pdev;
656 adapter->hw.back = adapter;
657 adapter->msg_enable = (1 << debug) - 1;
658
659 mmio_start = pci_resource_start(pdev, BAR_0);
660 mmio_len = pci_resource_len(pdev, BAR_0);
661
662 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800663 if (!adapter->hw.hw_addr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 err = -EIO;
665 goto err_ioremap;
666 }
667
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800668 for (i = BAR_1; i <= BAR_5; i++) {
669 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800671 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 adapter->hw.io_base = pci_resource_start(pdev, i);
673 break;
674 }
675 }
676
677 netdev->open = &e1000_open;
678 netdev->stop = &e1000_close;
679 netdev->hard_start_xmit = &e1000_xmit_frame;
680 netdev->get_stats = &e1000_get_stats;
681 netdev->set_multicast_list = &e1000_set_multi;
682 netdev->set_mac_address = &e1000_set_mac;
683 netdev->change_mtu = &e1000_change_mtu;
684 netdev->do_ioctl = &e1000_ioctl;
685 e1000_set_ethtool_ops(netdev);
686 netdev->tx_timeout = &e1000_tx_timeout;
687 netdev->watchdog_timeo = 5 * HZ;
688#ifdef CONFIG_E1000_NAPI
689 netdev->poll = &e1000_clean;
690 netdev->weight = 64;
691#endif
692 netdev->vlan_rx_register = e1000_vlan_rx_register;
693 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
694 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
695#ifdef CONFIG_NET_POLL_CONTROLLER
696 netdev->poll_controller = e1000_netpoll;
697#endif
698 strcpy(netdev->name, pci_name(pdev));
699
700 netdev->mem_start = mmio_start;
701 netdev->mem_end = mmio_start + mmio_len;
702 netdev->base_addr = adapter->hw.io_base;
703
704 adapter->bd_number = cards_found;
705
706 /* setup the private structure */
707
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800708 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 goto err_sw_init;
710
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800711 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700712 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
713
Jeff Kirsher84916822006-03-02 18:18:48 -0800714 /* if ksp3, indicate if it's port a being setup */
715 if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
716 e1000_ksp3_port_a == 0)
717 adapter->ksp3_port_a = 1;
718 e1000_ksp3_port_a++;
719 /* Reset for multiple KP3 adapters */
720 if (e1000_ksp3_port_a == 4)
721 e1000_ksp3_port_a = 0;
722
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800723 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 netdev->features = NETIF_F_SG |
725 NETIF_F_HW_CSUM |
726 NETIF_F_HW_VLAN_TX |
727 NETIF_F_HW_VLAN_RX |
728 NETIF_F_HW_VLAN_FILTER;
729 }
730
731#ifdef NETIF_F_TSO
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800732 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 (adapter->hw.mac_type != e1000_82547))
734 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700735
736#ifdef NETIF_F_TSO_IPV6
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800737 if (adapter->hw.mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700738 netdev->features |= NETIF_F_TSO_IPV6;
739#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800741 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 netdev->features |= NETIF_F_HIGHDMA;
743
744 /* hard_start_xmit is safe against parallel locking */
745 netdev->features |= NETIF_F_LLTX;
746
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700747 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
748
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800749 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 e1000_reset_hw(&adapter->hw);
753
754 /* make sure the EEPROM is good */
755
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800756 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
758 err = -EIO;
759 goto err_eeprom;
760 }
761
762 /* copy the MAC address out of the EEPROM */
763
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800764 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
766 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400767 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800769 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
771 err = -EIO;
772 goto err_eeprom;
773 }
774
775 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
776
777 e1000_get_bus_info(&adapter->hw);
778
779 init_timer(&adapter->tx_fifo_stall_timer);
780 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
781 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
782
783 init_timer(&adapter->watchdog_timer);
784 adapter->watchdog_timer.function = &e1000_watchdog;
785 adapter->watchdog_timer.data = (unsigned long) adapter;
786
787 INIT_WORK(&adapter->watchdog_task,
788 (void (*)(void *))e1000_watchdog_task, adapter);
789
790 init_timer(&adapter->phy_info_timer);
791 adapter->phy_info_timer.function = &e1000_update_phy_info;
792 adapter->phy_info_timer.data = (unsigned long) adapter;
793
Jeff Kirsher87041632006-03-02 18:21:24 -0800794 INIT_WORK(&adapter->reset_task,
795 (void (*)(void *))e1000_reset_task, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 /* we're going to reset, so assume we have no link for now */
798
799 netif_carrier_off(netdev);
800 netif_stop_queue(netdev);
801
802 e1000_check_options(adapter);
803
804 /* Initial Wake on LAN setting
805 * If APM wake is enabled in the EEPROM,
806 * enable the ACPI Magic Packet filter
807 */
808
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800809 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 case e1000_82542_rev2_0:
811 case e1000_82542_rev2_1:
812 case e1000_82543:
813 break;
814 case e1000_82544:
815 e1000_read_eeprom(&adapter->hw,
816 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
817 eeprom_apme_mask = E1000_EEPROM_82544_APM;
818 break;
819 case e1000_82546:
820 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500821 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800822 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800823 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 e1000_read_eeprom(&adapter->hw,
825 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
826 break;
827 }
828 /* Fall Through */
829 default:
830 e1000_read_eeprom(&adapter->hw,
831 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
832 break;
833 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800834 if (eeprom_data & eeprom_apme_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 adapter->wol |= E1000_WUFC_MAG;
836
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -0800837 /* print bus type/speed/width info */
838 {
839 struct e1000_hw *hw = &adapter->hw;
840 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
841 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
842 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
843 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
844 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
845 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
846 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
847 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
848 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
849 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
850 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
851 "32-bit"));
852 }
853
854 for (i = 0; i < 6; i++)
855 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 /* reset the hardware with the new settings */
858 e1000_reset(adapter);
859
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800860 /* If the controller is 82573 and f/w is AMT, do not set
861 * DRV_LOAD until the interface is up. For all other cases,
862 * let the f/w know that the h/w is now under the control
863 * of the driver. */
864 if (adapter->hw.mac_type != e1000_82573 ||
865 !e1000_check_mng_mode(&adapter->hw))
866 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 strcpy(netdev->name, "eth%d");
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800869 if ((err = register_netdev(netdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 goto err_register;
871
872 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
873
874 cards_found++;
875 return 0;
876
877err_register:
878err_sw_init:
879err_eeprom:
880 iounmap(adapter->hw.hw_addr);
881err_ioremap:
882 free_netdev(netdev);
883err_alloc_etherdev:
884 pci_release_regions(pdev);
885 return err;
886}
887
888/**
889 * e1000_remove - Device Removal Routine
890 * @pdev: PCI device information struct
891 *
892 * e1000_remove is called by the PCI subsystem to alert the driver
893 * that it should release a PCI device. The could be caused by a
894 * Hot-Plug event, or because the driver is going to be removed from
895 * memory.
896 **/
897
898static void __devexit
899e1000_remove(struct pci_dev *pdev)
900{
901 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700902 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800903 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400904#ifdef CONFIG_E1000_NAPI
905 int i;
906#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Jeff Garzikbe2b28e2005-10-04 07:13:43 -0400908 flush_scheduled_work();
909
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800910 if (adapter->hw.mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 adapter->hw.media_type == e1000_media_type_copper) {
912 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800913 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 manc |= E1000_MANC_ARP_EN;
915 E1000_WRITE_REG(&adapter->hw, MANC, manc);
916 }
917 }
918
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800919 /* Release control of h/w to f/w. If f/w is AMT enabled, this
920 * would have already happened in close and is redundant. */
921 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400924#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800925 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -0800926 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400927#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800929 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700930 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400932 kfree(adapter->tx_ring);
933 kfree(adapter->rx_ring);
934#ifdef CONFIG_E1000_NAPI
935 kfree(adapter->polling_netdev);
936#endif
937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 iounmap(adapter->hw.hw_addr);
939 pci_release_regions(pdev);
940
941 free_netdev(netdev);
942
943 pci_disable_device(pdev);
944}
945
946/**
947 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
948 * @adapter: board private structure to initialize
949 *
950 * e1000_sw_init initializes the Adapter private data structure.
951 * Fields are initialized based on PCI device information and
952 * OS network device settings (MTU size).
953 **/
954
955static int __devinit
956e1000_sw_init(struct e1000_adapter *adapter)
957{
958 struct e1000_hw *hw = &adapter->hw;
959 struct net_device *netdev = adapter->netdev;
960 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400961#ifdef CONFIG_E1000_NAPI
962 int i;
963#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 /* PCI config space info */
966
967 hw->vendor_id = pdev->vendor;
968 hw->device_id = pdev->device;
969 hw->subsystem_vendor_id = pdev->subsystem_vendor;
970 hw->subsystem_id = pdev->subsystem_device;
971
972 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
973
974 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
975
Auke Kok9e2feac2006-04-14 19:05:18 -0700976 adapter->rx_buffer_len = MAXIMUM_ETHERNET_FRAME_SIZE;
977 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 hw->max_frame_size = netdev->mtu +
979 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
980 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
981
982 /* identify the MAC */
983
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800984 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
986 return -EIO;
987 }
988
989 /* initialize eeprom parameters */
990
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800991 if (e1000_init_eeprom_params(hw)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700992 E1000_ERR("EEPROM initialization failed\n");
993 return -EIO;
994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800996 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 default:
998 break;
999 case e1000_82541:
1000 case e1000_82547:
1001 case e1000_82541_rev_2:
1002 case e1000_82547_rev_2:
1003 hw->phy_init_script = 1;
1004 break;
1005 }
1006
1007 e1000_set_media_type(hw);
1008
1009 hw->wait_autoneg_complete = FALSE;
1010 hw->tbi_compatibility_en = TRUE;
1011 hw->adaptive_ifs = TRUE;
1012
1013 /* Copper options */
1014
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001015 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 hw->mdix = AUTO_ALL_MODES;
1017 hw->disable_polarity_correction = FALSE;
1018 hw->master_slave = E1000_MASTER_SLAVE;
1019 }
1020
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001021 adapter->num_tx_queues = 1;
1022 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001023
1024 if (e1000_alloc_queues(adapter)) {
1025 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1026 return -ENOMEM;
1027 }
1028
1029#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001030 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001031 adapter->polling_netdev[i].priv = adapter;
1032 adapter->polling_netdev[i].poll = &e1000_clean;
1033 adapter->polling_netdev[i].weight = 64;
1034 dev_hold(&adapter->polling_netdev[i]);
1035 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1036 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001037 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001038#endif
1039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 atomic_set(&adapter->irq_sem, 1);
1041 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 return 0;
1044}
1045
1046/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001047 * e1000_alloc_queues - Allocate memory for all rings
1048 * @adapter: board private structure to initialize
1049 *
1050 * We allocate one ring per queue at run-time since we don't know the
1051 * number of queues at compile-time. The polling_netdev array is
1052 * intended for Multiqueue, but should work fine with a single queue.
1053 **/
1054
1055static int __devinit
1056e1000_alloc_queues(struct e1000_adapter *adapter)
1057{
1058 int size;
1059
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001060 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001061 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1062 if (!adapter->tx_ring)
1063 return -ENOMEM;
1064 memset(adapter->tx_ring, 0, size);
1065
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001066 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001067 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1068 if (!adapter->rx_ring) {
1069 kfree(adapter->tx_ring);
1070 return -ENOMEM;
1071 }
1072 memset(adapter->rx_ring, 0, size);
1073
1074#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001075 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001076 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1077 if (!adapter->polling_netdev) {
1078 kfree(adapter->tx_ring);
1079 kfree(adapter->rx_ring);
1080 return -ENOMEM;
1081 }
1082 memset(adapter->polling_netdev, 0, size);
1083#endif
1084
1085 return E1000_SUCCESS;
1086}
1087
1088/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 * e1000_open - Called when a network interface is made active
1090 * @netdev: network interface device structure
1091 *
1092 * Returns 0 on success, negative value on failure
1093 *
1094 * The open entry point is called when a network interface is made
1095 * active by the system (IFF_UP). At this point all resources needed
1096 * for transmit and receive operations are allocated, the interrupt
1097 * handler is registered with the OS, the watchdog timer is started,
1098 * and the stack is notified that the interface is ready.
1099 **/
1100
1101static int
1102e1000_open(struct net_device *netdev)
1103{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001104 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 int err;
1106
1107 /* allocate transmit descriptors */
1108
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001109 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 goto err_setup_tx;
1111
1112 /* allocate receive descriptors */
1113
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001114 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 goto err_setup_rx;
1116
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001117 if ((err = e1000_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001119 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001120 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001121 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1122 e1000_update_mng_vlan(adapter);
1123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001125 /* If AMT is enabled, let the firmware know that the network
1126 * interface is now open */
1127 if (adapter->hw.mac_type == e1000_82573 &&
1128 e1000_check_mng_mode(&adapter->hw))
1129 e1000_get_hw_control(adapter);
1130
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 return E1000_SUCCESS;
1132
1133err_up:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001134 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001136 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137err_setup_tx:
1138 e1000_reset(adapter);
1139
1140 return err;
1141}
1142
1143/**
1144 * e1000_close - Disables a network interface
1145 * @netdev: network interface device structure
1146 *
1147 * Returns 0, this is not allowed to fail
1148 *
1149 * The close entry point is called when an interface is de-activated
1150 * by the OS. The hardware is still under the drivers control, but
1151 * needs to be disabled. A global MAC reset is issued to stop the
1152 * hardware, and all transmit and receive resources are freed.
1153 **/
1154
1155static int
1156e1000_close(struct net_device *netdev)
1157{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001158 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 e1000_down(adapter);
1161
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001162 e1000_free_all_tx_resources(adapter);
1163 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001165 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001166 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1167 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1168 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001169
1170 /* If AMT is enabled, let the firmware know that the network
1171 * interface is now closed */
1172 if (adapter->hw.mac_type == e1000_82573 &&
1173 e1000_check_mng_mode(&adapter->hw))
1174 e1000_release_hw_control(adapter);
1175
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 return 0;
1177}
1178
1179/**
1180 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1181 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001182 * @start: address of beginning of memory
1183 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 **/
Auke Koke619d522006-04-14 19:04:52 -07001185static boolean_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186e1000_check_64k_bound(struct e1000_adapter *adapter,
1187 void *start, unsigned long len)
1188{
1189 unsigned long begin = (unsigned long) start;
1190 unsigned long end = begin + len;
1191
Malli Chilakala26483452005-04-28 19:44:46 -07001192 /* First rev 82545 and 82546 need to not allow any memory
1193 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001195 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1197 }
1198
1199 return TRUE;
1200}
1201
1202/**
1203 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1204 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001205 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 *
1207 * Return 0 on success, negative on failure
1208 **/
1209
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001210static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001211e1000_setup_tx_resources(struct e1000_adapter *adapter,
1212 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 struct pci_dev *pdev = adapter->pdev;
1215 int size;
1216
1217 size = sizeof(struct e1000_buffer) * txdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001218
1219 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001220 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001221 DPRINTK(PROBE, ERR,
1222 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 return -ENOMEM;
1224 }
1225 memset(txdr->buffer_info, 0, size);
1226
1227 /* round up to nearest 4K */
1228
1229 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1230 E1000_ROUNDUP(txdr->size, 4096);
1231
1232 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001233 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001236 DPRINTK(PROBE, ERR,
1237 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 return -ENOMEM;
1239 }
1240
Malli Chilakala26483452005-04-28 19:44:46 -07001241 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1243 void *olddesc = txdr->desc;
1244 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001245 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1246 "at %p\n", txdr->size, txdr->desc);
1247 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001249 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001250 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1252 goto setup_tx_desc_die;
1253 }
1254
1255 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1256 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001257 pci_free_consistent(pdev, txdr->size, txdr->desc,
1258 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1260 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001261 "Unable to allocate aligned memory "
1262 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 vfree(txdr->buffer_info);
1264 return -ENOMEM;
1265 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001266 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1268 }
1269 }
1270 memset(txdr->desc, 0, txdr->size);
1271
1272 txdr->next_to_use = 0;
1273 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001274 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 return 0;
1277}
1278
1279/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001280 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1281 * (Descriptors) for all queues
1282 * @adapter: board private structure
1283 *
1284 * If this function returns with an error, then it's possible one or
1285 * more of the rings is populated (while the rest are not). It is the
1286 * callers duty to clean those orphaned rings.
1287 *
1288 * Return 0 on success, negative on failure
1289 **/
1290
1291int
1292e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1293{
1294 int i, err = 0;
1295
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001296 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001297 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1298 if (err) {
1299 DPRINTK(PROBE, ERR,
1300 "Allocation for Tx Queue %u failed\n", i);
1301 break;
1302 }
1303 }
1304
1305 return err;
1306}
1307
1308/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1310 * @adapter: board private structure
1311 *
1312 * Configure the Tx unit of the MAC after a reset.
1313 **/
1314
1315static void
1316e1000_configure_tx(struct e1000_adapter *adapter)
1317{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001318 uint64_t tdba;
1319 struct e1000_hw *hw = &adapter->hw;
1320 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001321 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 /* Setup the HW Tx Head and Tail descriptor pointers */
1324
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001325 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001326 case 1:
1327 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001328 tdba = adapter->tx_ring[0].dma;
1329 tdlen = adapter->tx_ring[0].count *
1330 sizeof(struct e1000_tx_desc);
1331 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1332 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1333 E1000_WRITE_REG(hw, TDLEN, tdlen);
1334 E1000_WRITE_REG(hw, TDH, 0);
1335 E1000_WRITE_REG(hw, TDT, 0);
1336 adapter->tx_ring[0].tdh = E1000_TDH;
1337 adapter->tx_ring[0].tdt = E1000_TDT;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001338 break;
1339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
1341 /* Set the default values for the Tx Inter Packet Gap timer */
1342
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001343 if (hw->media_type == e1000_media_type_fiber ||
1344 hw->media_type == e1000_media_type_internal_serdes)
1345 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1346 else
1347 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1348
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001349 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 case e1000_82542_rev2_0:
1351 case e1000_82542_rev2_1:
1352 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001353 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1354 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001356 case e1000_80003es2lan:
1357 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1358 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1359 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001361 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1362 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1363 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001365 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1366 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001367 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369 /* Set the Tx Interrupt Delay register */
1370
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001371 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1372 if (hw->mac_type >= e1000_82540)
1373 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
1375 /* Program the Transmit Control Register */
1376
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001377 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
1379 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001380 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1382
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001383#ifdef DISABLE_MULR
1384 /* disable Multiple Reads for debugging */
1385 tctl &= ~E1000_TCTL_MULR;
1386#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001388 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1389 tarc = E1000_READ_REG(hw, TARC0);
1390 tarc |= ((1 << 25) | (1 << 21));
1391 E1000_WRITE_REG(hw, TARC0, tarc);
1392 tarc = E1000_READ_REG(hw, TARC1);
1393 tarc |= (1 << 25);
1394 if (tctl & E1000_TCTL_MULR)
1395 tarc &= ~(1 << 28);
1396 else
1397 tarc |= (1 << 28);
1398 E1000_WRITE_REG(hw, TARC1, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001399 } else if (hw->mac_type == e1000_80003es2lan) {
1400 tarc = E1000_READ_REG(hw, TARC0);
1401 tarc |= 1;
1402 if (hw->media_type == e1000_media_type_internal_serdes)
1403 tarc |= (1 << 20);
1404 E1000_WRITE_REG(hw, TARC0, tarc);
1405 tarc = E1000_READ_REG(hw, TARC1);
1406 tarc |= 1;
1407 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001408 }
1409
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001410 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
1412 /* Setup Transmit Descriptor Settings for eop descriptor */
1413 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1414 E1000_TXD_CMD_IFCS;
1415
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001416 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1418 else
1419 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1420
1421 /* Cache if we're 82544 running in PCI-X because we'll
1422 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001423 if (hw->mac_type == e1000_82544 &&
1424 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001426
1427 E1000_WRITE_REG(hw, TCTL, tctl);
1428
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429}
1430
1431/**
1432 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1433 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001434 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 *
1436 * Returns 0 on success, negative on failure
1437 **/
1438
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001439static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001440e1000_setup_rx_resources(struct e1000_adapter *adapter,
1441 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001444 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
1446 size = sizeof(struct e1000_buffer) * rxdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001447 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001448 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001449 DPRINTK(PROBE, ERR,
1450 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 return -ENOMEM;
1452 }
1453 memset(rxdr->buffer_info, 0, size);
1454
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001455 size = sizeof(struct e1000_ps_page) * rxdr->count;
1456 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001457 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001458 vfree(rxdr->buffer_info);
1459 DPRINTK(PROBE, ERR,
1460 "Unable to allocate memory for the receive descriptor ring\n");
1461 return -ENOMEM;
1462 }
1463 memset(rxdr->ps_page, 0, size);
1464
1465 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1466 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001467 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001468 vfree(rxdr->buffer_info);
1469 kfree(rxdr->ps_page);
1470 DPRINTK(PROBE, ERR,
1471 "Unable to allocate memory for the receive descriptor ring\n");
1472 return -ENOMEM;
1473 }
1474 memset(rxdr->ps_page_dma, 0, size);
1475
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001476 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001477 desc_len = sizeof(struct e1000_rx_desc);
1478 else
1479 desc_len = sizeof(union e1000_rx_desc_packet_split);
1480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 /* Round up to nearest 4K */
1482
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001483 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 E1000_ROUNDUP(rxdr->size, 4096);
1485
1486 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1487
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001488 if (!rxdr->desc) {
1489 DPRINTK(PROBE, ERR,
1490 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001493 kfree(rxdr->ps_page);
1494 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 return -ENOMEM;
1496 }
1497
Malli Chilakala26483452005-04-28 19:44:46 -07001498 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1500 void *olddesc = rxdr->desc;
1501 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001502 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1503 "at %p\n", rxdr->size, rxdr->desc);
1504 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001506 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001507 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001509 DPRINTK(PROBE, ERR,
1510 "Unable to allocate memory "
1511 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 goto setup_rx_desc_die;
1513 }
1514
1515 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1516 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001517 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1518 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001520 DPRINTK(PROBE, ERR,
1521 "Unable to allocate aligned memory "
1522 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001523 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001525 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1527 }
1528 }
1529 memset(rxdr->desc, 0, rxdr->size);
1530
1531 rxdr->next_to_clean = 0;
1532 rxdr->next_to_use = 0;
1533
1534 return 0;
1535}
1536
1537/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001538 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1539 * (Descriptors) for all queues
1540 * @adapter: board private structure
1541 *
1542 * If this function returns with an error, then it's possible one or
1543 * more of the rings is populated (while the rest are not). It is the
1544 * callers duty to clean those orphaned rings.
1545 *
1546 * Return 0 on success, negative on failure
1547 **/
1548
1549int
1550e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1551{
1552 int i, err = 0;
1553
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001554 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001555 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1556 if (err) {
1557 DPRINTK(PROBE, ERR,
1558 "Allocation for Rx Queue %u failed\n", i);
1559 break;
1560 }
1561 }
1562
1563 return err;
1564}
1565
1566/**
Malli Chilakala26483452005-04-28 19:44:46 -07001567 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 * @adapter: Board private structure
1569 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001570#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1571 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572static void
1573e1000_setup_rctl(struct e1000_adapter *adapter)
1574{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001575 uint32_t rctl, rfctl;
1576 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001577#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001578 uint32_t pages = 0;
1579#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
1581 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1582
1583 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1584
1585 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1586 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1587 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1588
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001589 if (adapter->hw.mac_type > e1000_82543)
1590 rctl |= E1000_RCTL_SECRC;
1591
1592 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 rctl |= E1000_RCTL_SBP;
1594 else
1595 rctl &= ~E1000_RCTL_SBP;
1596
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001597 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1598 rctl &= ~E1000_RCTL_LPE;
1599 else
1600 rctl |= E1000_RCTL_LPE;
1601
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 /* Setup buffer sizes */
Auke Kok9e2feac2006-04-14 19:05:18 -07001603 rctl &= ~E1000_RCTL_SZ_4096;
1604 rctl |= E1000_RCTL_BSEX;
1605 switch (adapter->rx_buffer_len) {
1606 case E1000_RXBUFFER_256:
1607 rctl |= E1000_RCTL_SZ_256;
1608 rctl &= ~E1000_RCTL_BSEX;
1609 break;
1610 case E1000_RXBUFFER_512:
1611 rctl |= E1000_RCTL_SZ_512;
1612 rctl &= ~E1000_RCTL_BSEX;
1613 break;
1614 case E1000_RXBUFFER_1024:
1615 rctl |= E1000_RCTL_SZ_1024;
1616 rctl &= ~E1000_RCTL_BSEX;
1617 break;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001618 case E1000_RXBUFFER_2048:
1619 default:
1620 rctl |= E1000_RCTL_SZ_2048;
1621 rctl &= ~E1000_RCTL_BSEX;
1622 break;
1623 case E1000_RXBUFFER_4096:
1624 rctl |= E1000_RCTL_SZ_4096;
1625 break;
1626 case E1000_RXBUFFER_8192:
1627 rctl |= E1000_RCTL_SZ_8192;
1628 break;
1629 case E1000_RXBUFFER_16384:
1630 rctl |= E1000_RCTL_SZ_16384;
1631 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001632 }
1633
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001634#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001635 /* 82571 and greater support packet-split where the protocol
1636 * header is placed in skb->data and the packet data is
1637 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1638 * In the case of a non-split, skb->data is linearly filled,
1639 * followed by the page buffers. Therefore, skb->data is
1640 * sized to hold the largest protocol header.
1641 */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001642 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1643 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1644 PAGE_SIZE <= 16384)
1645 adapter->rx_ps_pages = pages;
1646 else
1647 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001648#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001649 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001650 /* Configure extra packet-split registers */
1651 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1652 rfctl |= E1000_RFCTL_EXTEN;
1653 /* disable IPv6 packet split support */
1654 rfctl |= E1000_RFCTL_IPV6_DIS;
1655 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1656
1657 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001658
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001659 psrctl |= adapter->rx_ps_bsize0 >>
1660 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001661
1662 switch (adapter->rx_ps_pages) {
1663 case 3:
1664 psrctl |= PAGE_SIZE <<
1665 E1000_PSRCTL_BSIZE3_SHIFT;
1666 case 2:
1667 psrctl |= PAGE_SIZE <<
1668 E1000_PSRCTL_BSIZE2_SHIFT;
1669 case 1:
1670 psrctl |= PAGE_SIZE >>
1671 E1000_PSRCTL_BSIZE1_SHIFT;
1672 break;
1673 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001674
1675 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 }
1677
1678 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1679}
1680
1681/**
1682 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1683 * @adapter: board private structure
1684 *
1685 * Configure the Rx unit of the MAC after a reset.
1686 **/
1687
1688static void
1689e1000_configure_rx(struct e1000_adapter *adapter)
1690{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001691 uint64_t rdba;
1692 struct e1000_hw *hw = &adapter->hw;
1693 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001694
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001695 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001696 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001697 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001698 sizeof(union e1000_rx_desc_packet_split);
1699 adapter->clean_rx = e1000_clean_rx_irq_ps;
1700 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1701 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001702 rdlen = adapter->rx_ring[0].count *
1703 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001704 adapter->clean_rx = e1000_clean_rx_irq;
1705 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1706 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
1708 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001709 rctl = E1000_READ_REG(hw, RCTL);
1710 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001713 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001715 if (hw->mac_type >= e1000_82540) {
1716 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001717 if (adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001718 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 1000000000 / (adapter->itr * 256));
1720 }
1721
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001722 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001723 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001724 /* Reset delay timers after every interrupt */
Auke Kok6fc7a7e2006-04-14 19:05:12 -07001725 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001726#ifdef CONFIG_E1000_NAPI
1727 /* Auto-Mask interrupts upon ICR read. */
1728 ctrl_ext |= E1000_CTRL_EXT_IAME;
1729#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001730 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001731 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001732 E1000_WRITE_FLUSH(hw);
1733 }
1734
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001735 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1736 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001737 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001738 case 1:
1739 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001740 rdba = adapter->rx_ring[0].dma;
1741 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1742 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1743 E1000_WRITE_REG(hw, RDLEN, rdlen);
1744 E1000_WRITE_REG(hw, RDH, 0);
1745 E1000_WRITE_REG(hw, RDT, 0);
1746 adapter->rx_ring[0].rdh = E1000_RDH;
1747 adapter->rx_ring[0].rdt = E1000_RDT;
1748 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001749 }
1750
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001752 if (hw->mac_type >= e1000_82543) {
1753 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001754 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001755 rxcsum |= E1000_RXCSUM_TUOFL;
1756
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001757 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001758 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001759 if ((hw->mac_type >= e1000_82571) &&
1760 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001761 rxcsum |= E1000_RXCSUM_IPPCSE;
1762 }
1763 } else {
1764 rxcsum &= ~E1000_RXCSUM_TUOFL;
1765 /* don't need to clear IPPCSE as it defaults to 0 */
1766 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001767 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 }
1769
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001770 if (hw->mac_type == e1000_82573)
1771 E1000_WRITE_REG(hw, ERT, 0x0100);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001774 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
1777/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001778 * e1000_free_tx_resources - Free Tx Resources per Queue
1779 * @adapter: board private structure
1780 * @tx_ring: Tx descriptor ring for a specific queue
1781 *
1782 * Free all transmit software resources
1783 **/
1784
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001785static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001786e1000_free_tx_resources(struct e1000_adapter *adapter,
1787 struct e1000_tx_ring *tx_ring)
1788{
1789 struct pci_dev *pdev = adapter->pdev;
1790
1791 e1000_clean_tx_ring(adapter, tx_ring);
1792
1793 vfree(tx_ring->buffer_info);
1794 tx_ring->buffer_info = NULL;
1795
1796 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1797
1798 tx_ring->desc = NULL;
1799}
1800
1801/**
1802 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 * @adapter: board private structure
1804 *
1805 * Free all transmit software resources
1806 **/
1807
1808void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001809e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001811 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001813 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001814 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815}
1816
Auke Koke619d522006-04-14 19:04:52 -07001817static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1819 struct e1000_buffer *buffer_info)
1820{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001821 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001822 pci_unmap_page(adapter->pdev,
1823 buffer_info->dma,
1824 buffer_info->length,
1825 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08001827 if (buffer_info->skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 dev_kfree_skb_any(buffer_info->skb);
Jeff Kirsher8241e352006-01-12 16:51:34 -08001829 memset(buffer_info, 0, sizeof(struct e1000_buffer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830}
1831
1832/**
1833 * e1000_clean_tx_ring - Free Tx Buffers
1834 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001835 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 **/
1837
1838static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001839e1000_clean_tx_ring(struct e1000_adapter *adapter,
1840 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 struct e1000_buffer *buffer_info;
1843 unsigned long size;
1844 unsigned int i;
1845
1846 /* Free all the Tx ring sk_buffs */
1847
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001848 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 buffer_info = &tx_ring->buffer_info[i];
1850 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1851 }
1852
1853 size = sizeof(struct e1000_buffer) * tx_ring->count;
1854 memset(tx_ring->buffer_info, 0, size);
1855
1856 /* Zero out the descriptor ring */
1857
1858 memset(tx_ring->desc, 0, tx_ring->size);
1859
1860 tx_ring->next_to_use = 0;
1861 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001862 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001864 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1865 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1866}
1867
1868/**
1869 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1870 * @adapter: board private structure
1871 **/
1872
1873static void
1874e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1875{
1876 int i;
1877
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001878 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001879 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880}
1881
1882/**
1883 * e1000_free_rx_resources - Free Rx Resources
1884 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001885 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 *
1887 * Free all receive software resources
1888 **/
1889
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001890static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001891e1000_free_rx_resources(struct e1000_adapter *adapter,
1892 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 struct pci_dev *pdev = adapter->pdev;
1895
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001896 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897
1898 vfree(rx_ring->buffer_info);
1899 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001900 kfree(rx_ring->ps_page);
1901 rx_ring->ps_page = NULL;
1902 kfree(rx_ring->ps_page_dma);
1903 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
1905 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1906
1907 rx_ring->desc = NULL;
1908}
1909
1910/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001911 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001913 *
1914 * Free all receive software resources
1915 **/
1916
1917void
1918e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1919{
1920 int i;
1921
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001922 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001923 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1924}
1925
1926/**
1927 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1928 * @adapter: board private structure
1929 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 **/
1931
1932static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001933e1000_clean_rx_ring(struct e1000_adapter *adapter,
1934 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001937 struct e1000_ps_page *ps_page;
1938 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 struct pci_dev *pdev = adapter->pdev;
1940 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001941 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001944 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001946 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 pci_unmap_single(pdev,
1948 buffer_info->dma,
1949 buffer_info->length,
1950 PCI_DMA_FROMDEVICE);
1951
1952 dev_kfree_skb(buffer_info->skb);
1953 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08001954 }
1955 ps_page = &rx_ring->ps_page[i];
1956 ps_page_dma = &rx_ring->ps_page_dma[i];
1957 for (j = 0; j < adapter->rx_ps_pages; j++) {
1958 if (!ps_page->ps_page[j]) break;
1959 pci_unmap_page(pdev,
1960 ps_page_dma->ps_page_dma[j],
1961 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1962 ps_page_dma->ps_page_dma[j] = 0;
1963 put_page(ps_page->ps_page[j]);
1964 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 }
1966 }
1967
1968 size = sizeof(struct e1000_buffer) * rx_ring->count;
1969 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001970 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1971 memset(rx_ring->ps_page, 0, size);
1972 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1973 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974
1975 /* Zero out the descriptor ring */
1976
1977 memset(rx_ring->desc, 0, rx_ring->size);
1978
1979 rx_ring->next_to_clean = 0;
1980 rx_ring->next_to_use = 0;
1981
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001982 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1983 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1984}
1985
1986/**
1987 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1988 * @adapter: board private structure
1989 **/
1990
1991static void
1992e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1993{
1994 int i;
1995
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001996 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001997 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998}
1999
2000/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2001 * and memory write and invalidate disabled for certain operations
2002 */
2003static void
2004e1000_enter_82542_rst(struct e1000_adapter *adapter)
2005{
2006 struct net_device *netdev = adapter->netdev;
2007 uint32_t rctl;
2008
2009 e1000_pci_clear_mwi(&adapter->hw);
2010
2011 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2012 rctl |= E1000_RCTL_RST;
2013 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2014 E1000_WRITE_FLUSH(&adapter->hw);
2015 mdelay(5);
2016
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002017 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002018 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019}
2020
2021static void
2022e1000_leave_82542_rst(struct e1000_adapter *adapter)
2023{
2024 struct net_device *netdev = adapter->netdev;
2025 uint32_t rctl;
2026
2027 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2028 rctl &= ~E1000_RCTL_RST;
2029 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2030 E1000_WRITE_FLUSH(&adapter->hw);
2031 mdelay(5);
2032
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002033 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 e1000_pci_set_mwi(&adapter->hw);
2035
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002036 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002037 /* No need to loop, because 82542 supports only 1 queue */
2038 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002039 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002040 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 }
2042}
2043
2044/**
2045 * e1000_set_mac - Change the Ethernet Address of the NIC
2046 * @netdev: network interface device structure
2047 * @p: pointer to an address structure
2048 *
2049 * Returns 0 on success, negative on failure
2050 **/
2051
2052static int
2053e1000_set_mac(struct net_device *netdev, void *p)
2054{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002055 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 struct sockaddr *addr = p;
2057
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002058 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 return -EADDRNOTAVAIL;
2060
2061 /* 82542 2.0 needs to be in reset to write receive address registers */
2062
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002063 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 e1000_enter_82542_rst(adapter);
2065
2066 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2067 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2068
2069 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2070
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002071 /* With 82571 controllers, LAA may be overwritten (with the default)
2072 * due to controller reset from the other port. */
2073 if (adapter->hw.mac_type == e1000_82571) {
2074 /* activate the work around */
2075 adapter->hw.laa_is_present = 1;
2076
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002077 /* Hold a copy of the LAA in RAR[14] This is done so that
2078 * between the time RAR[0] gets clobbered and the time it
2079 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002080 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002081 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002082 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002083 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002084 E1000_RAR_ENTRIES - 1);
2085 }
2086
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002087 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 e1000_leave_82542_rst(adapter);
2089
2090 return 0;
2091}
2092
2093/**
2094 * e1000_set_multi - Multicast and Promiscuous mode set
2095 * @netdev: network interface device structure
2096 *
2097 * The set_multi entry point is called whenever the multicast address
2098 * list or the network interface flags are updated. This routine is
2099 * responsible for configuring the hardware for proper multicast,
2100 * promiscuous mode, and all-multi behavior.
2101 **/
2102
2103static void
2104e1000_set_multi(struct net_device *netdev)
2105{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002106 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 struct e1000_hw *hw = &adapter->hw;
2108 struct dev_mc_list *mc_ptr;
2109 uint32_t rctl;
2110 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002111 int i, rar_entries = E1000_RAR_ENTRIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002113 /* reserve RAR[14] for LAA over-write work-around */
2114 if (adapter->hw.mac_type == e1000_82571)
2115 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
Malli Chilakala26483452005-04-28 19:44:46 -07002117 /* Check for Promiscuous and All Multicast modes */
2118
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 rctl = E1000_READ_REG(hw, RCTL);
2120
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002121 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002123 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 rctl |= E1000_RCTL_MPE;
2125 rctl &= ~E1000_RCTL_UPE;
2126 } else {
2127 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2128 }
2129
2130 E1000_WRITE_REG(hw, RCTL, rctl);
2131
2132 /* 82542 2.0 needs to be in reset to write receive address registers */
2133
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002134 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 e1000_enter_82542_rst(adapter);
2136
2137 /* load the first 14 multicast address into the exact filters 1-14
2138 * RAR 0 is used for the station MAC adddress
2139 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002140 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 */
2142 mc_ptr = netdev->mc_list;
2143
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002144 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002145 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2147 mc_ptr = mc_ptr->next;
2148 } else {
2149 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2150 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2151 }
2152 }
2153
2154 /* clear the old settings from the multicast hash table */
2155
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002156 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2158
2159 /* load any remaining addresses into the hash table */
2160
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002161 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2163 e1000_mta_set(hw, hash_value);
2164 }
2165
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002166 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168}
2169
2170/* Need to wait a few seconds after link up to get diagnostic information from
2171 * the phy */
2172
2173static void
2174e1000_update_phy_info(unsigned long data)
2175{
2176 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2177 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2178}
2179
2180/**
2181 * e1000_82547_tx_fifo_stall - Timer Call-back
2182 * @data: pointer to adapter cast into an unsigned long
2183 **/
2184
2185static void
2186e1000_82547_tx_fifo_stall(unsigned long data)
2187{
2188 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2189 struct net_device *netdev = adapter->netdev;
2190 uint32_t tctl;
2191
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002192 if (atomic_read(&adapter->tx_fifo_stall)) {
2193 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 E1000_READ_REG(&adapter->hw, TDH)) &&
2195 (E1000_READ_REG(&adapter->hw, TDFT) ==
2196 E1000_READ_REG(&adapter->hw, TDFH)) &&
2197 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2198 E1000_READ_REG(&adapter->hw, TDFHS))) {
2199 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2200 E1000_WRITE_REG(&adapter->hw, TCTL,
2201 tctl & ~E1000_TCTL_EN);
2202 E1000_WRITE_REG(&adapter->hw, TDFT,
2203 adapter->tx_head_addr);
2204 E1000_WRITE_REG(&adapter->hw, TDFH,
2205 adapter->tx_head_addr);
2206 E1000_WRITE_REG(&adapter->hw, TDFTS,
2207 adapter->tx_head_addr);
2208 E1000_WRITE_REG(&adapter->hw, TDFHS,
2209 adapter->tx_head_addr);
2210 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2211 E1000_WRITE_FLUSH(&adapter->hw);
2212
2213 adapter->tx_fifo_head = 0;
2214 atomic_set(&adapter->tx_fifo_stall, 0);
2215 netif_wake_queue(netdev);
2216 } else {
2217 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2218 }
2219 }
2220}
2221
2222/**
2223 * e1000_watchdog - Timer Call-back
2224 * @data: pointer to adapter cast into an unsigned long
2225 **/
2226static void
2227e1000_watchdog(unsigned long data)
2228{
2229 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2230
2231 /* Do the rest outside of interrupt context */
2232 schedule_work(&adapter->watchdog_task);
2233}
2234
2235static void
2236e1000_watchdog_task(struct e1000_adapter *adapter)
2237{
2238 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002239 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002240 uint32_t link, tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
2242 e1000_check_for_link(&adapter->hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002243 if (adapter->hw.mac_type == e1000_82573) {
2244 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002245 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002246 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002249 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2251 link = !adapter->hw.serdes_link_down;
2252 else
2253 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2254
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002255 if (link) {
2256 if (!netif_carrier_ok(netdev)) {
Auke Kokfe7fe282006-04-14 19:04:59 -07002257 boolean_t txb2b = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 e1000_get_speed_and_duplex(&adapter->hw,
2259 &adapter->link_speed,
2260 &adapter->link_duplex);
2261
2262 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2263 adapter->link_speed,
2264 adapter->link_duplex == FULL_DUPLEX ?
2265 "Full Duplex" : "Half Duplex");
2266
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002267 /* tweak tx_queue_len according to speed/duplex
2268 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002269 netdev->tx_queue_len = adapter->tx_queue_len;
2270 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002271 switch (adapter->link_speed) {
2272 case SPEED_10:
Auke Kokfe7fe282006-04-14 19:04:59 -07002273 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002274 netdev->tx_queue_len = 10;
2275 adapter->tx_timeout_factor = 8;
2276 break;
2277 case SPEED_100:
Auke Kokfe7fe282006-04-14 19:04:59 -07002278 txb2b = 0;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002279 netdev->tx_queue_len = 100;
2280 /* maybe add some timeout factor ? */
2281 break;
2282 }
2283
Auke Kokfe7fe282006-04-14 19:04:59 -07002284 if ((adapter->hw.mac_type == e1000_82571 ||
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002285 adapter->hw.mac_type == e1000_82572) &&
Auke Kokfe7fe282006-04-14 19:04:59 -07002286 txb2b == 0) {
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002287#define SPEED_MODE_BIT (1 << 21)
2288 uint32_t tarc0;
2289 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2290 tarc0 &= ~SPEED_MODE_BIT;
2291 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2292 }
2293
2294#ifdef NETIF_F_TSO
2295 /* disable TSO for pcie and 10/100 speeds, to avoid
2296 * some hardware issues */
2297 if (!adapter->tso_force &&
2298 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002299 switch (adapter->link_speed) {
2300 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002301 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002302 DPRINTK(PROBE,INFO,
2303 "10/100 speed: disabling TSO\n");
2304 netdev->features &= ~NETIF_F_TSO;
2305 break;
2306 case SPEED_1000:
2307 netdev->features |= NETIF_F_TSO;
2308 break;
2309 default:
2310 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002311 break;
2312 }
2313 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002314#endif
2315
2316 /* enable transmits in the hardware, need to do this
2317 * after setting TARC0 */
2318 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2319 tctl |= E1000_TCTL_EN;
2320 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002321
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 netif_carrier_on(netdev);
2323 netif_wake_queue(netdev);
2324 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2325 adapter->smartspeed = 0;
2326 }
2327 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002328 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 adapter->link_speed = 0;
2330 adapter->link_duplex = 0;
2331 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2332 netif_carrier_off(netdev);
2333 netif_stop_queue(netdev);
2334 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002335
2336 /* 80003ES2LAN workaround--
2337 * For packet buffer work-around on link down event;
2338 * disable receives in the ISR and
2339 * reset device here in the watchdog
2340 */
2341 if (adapter->hw.mac_type == e1000_80003es2lan) {
2342 /* reset device */
2343 schedule_work(&adapter->reset_task);
2344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 }
2346
2347 e1000_smartspeed(adapter);
2348 }
2349
2350 e1000_update_stats(adapter);
2351
2352 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2353 adapter->tpt_old = adapter->stats.tpt;
2354 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2355 adapter->colc_old = adapter->stats.colc;
2356
2357 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2358 adapter->gorcl_old = adapter->stats.gorcl;
2359 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2360 adapter->gotcl_old = adapter->stats.gotcl;
2361
2362 e1000_update_adaptive(&adapter->hw);
2363
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002364 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002365 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 /* We've lost link, so the controller stops DMA,
2367 * but we've got queued Tx work that's never going
2368 * to get done, so reset controller to flush Tx.
2369 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002370 adapter->tx_timeout_count++;
2371 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 }
2373 }
2374
2375 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002376 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2378 * asymmetrical Tx or Rx gets ITR=8000; everyone
2379 * else is between 2000-8000. */
2380 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002381 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 adapter->gotcl - adapter->gorcl :
2383 adapter->gorcl - adapter->gotcl) / 10000;
2384 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2385 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2386 }
2387
2388 /* Cause software interrupt to ensure rx ring is cleaned */
2389 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2390
Malli Chilakala26483452005-04-28 19:44:46 -07002391 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 adapter->detect_tx_hung = TRUE;
2393
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002394 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002395 * reset from the other port. Set the appropriate LAA in RAR[0] */
2396 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2397 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2398
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 /* Reset the timer */
2400 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2401}
2402
2403#define E1000_TX_FLAGS_CSUM 0x00000001
2404#define E1000_TX_FLAGS_VLAN 0x00000002
2405#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002406#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2408#define E1000_TX_FLAGS_VLAN_SHIFT 16
2409
Auke Koke619d522006-04-14 19:04:52 -07002410static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002411e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2412 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413{
2414#ifdef NETIF_F_TSO
2415 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002416 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 unsigned int i;
2418 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002419 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2421 int err;
2422
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002423 if (skb_shinfo(skb)->tso_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 if (skb_header_cloned(skb)) {
2425 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2426 if (err)
2427 return err;
2428 }
2429
2430 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2431 mss = skb_shinfo(skb)->tso_size;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002432 if (skb->protocol == ntohs(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002433 skb->nh.iph->tot_len = 0;
2434 skb->nh.iph->check = 0;
2435 skb->h.th->check =
2436 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2437 skb->nh.iph->daddr,
2438 0,
2439 IPPROTO_TCP,
2440 0);
2441 cmd_length = E1000_TXD_CMD_IP;
2442 ipcse = skb->h.raw - skb->data - 1;
2443#ifdef NETIF_F_TSO_IPV6
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002444 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002445 skb->nh.ipv6h->payload_len = 0;
2446 skb->h.th->check =
2447 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2448 &skb->nh.ipv6h->daddr,
2449 0,
2450 IPPROTO_TCP,
2451 0);
2452 ipcse = 0;
2453#endif
2454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 ipcss = skb->nh.raw - skb->data;
2456 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 tucss = skb->h.raw - skb->data;
2458 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2459 tucse = 0;
2460
2461 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002462 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002464 i = tx_ring->next_to_use;
2465 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002466 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
2468 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2469 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2470 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2471 context_desc->upper_setup.tcp_fields.tucss = tucss;
2472 context_desc->upper_setup.tcp_fields.tucso = tucso;
2473 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2474 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2475 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2476 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2477
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002478 buffer_info->time_stamp = jiffies;
2479
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002480 if (++i == tx_ring->count) i = 0;
2481 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482
Jeff Kirsher8241e352006-01-12 16:51:34 -08002483 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 }
2485#endif
2486
Jeff Kirsher8241e352006-01-12 16:51:34 -08002487 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488}
2489
Auke Koke619d522006-04-14 19:04:52 -07002490static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002491e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2492 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
2494 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002495 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 unsigned int i;
2497 uint8_t css;
2498
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002499 if (likely(skb->ip_summed == CHECKSUM_HW)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 css = skb->h.raw - skb->data;
2501
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002502 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002503 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002504 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505
2506 context_desc->upper_setup.tcp_fields.tucss = css;
2507 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2508 context_desc->upper_setup.tcp_fields.tucse = 0;
2509 context_desc->tcp_seg_setup.data = 0;
2510 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2511
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002512 buffer_info->time_stamp = jiffies;
2513
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002514 if (unlikely(++i == tx_ring->count)) i = 0;
2515 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516
2517 return TRUE;
2518 }
2519
2520 return FALSE;
2521}
2522
2523#define E1000_MAX_TXD_PWR 12
2524#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2525
Auke Koke619d522006-04-14 19:04:52 -07002526static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002527e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2528 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2529 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 struct e1000_buffer *buffer_info;
2532 unsigned int len = skb->len;
2533 unsigned int offset = 0, size, count = 0, i;
2534 unsigned int f;
2535 len -= skb->data_len;
2536
2537 i = tx_ring->next_to_use;
2538
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002539 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 buffer_info = &tx_ring->buffer_info[i];
2541 size = min(len, max_per_txd);
2542#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002543 /* Workaround for Controller erratum --
2544 * descriptor for non-tso packet in a linear SKB that follows a
2545 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002546 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002547 if (!skb->data_len && tx_ring->last_tx_tso &&
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002548 !skb_shinfo(skb)->tso_size) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002549 tx_ring->last_tx_tso = 0;
2550 size -= 4;
2551 }
2552
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 /* Workaround for premature desc write-backs
2554 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002555 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 size -= 4;
2557#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002558 /* work-around for errata 10 and it applies
2559 * to all controllers in PCI-X mode
2560 * The fix is to make sure that the first descriptor of a
2561 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2562 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002563 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002564 (size > 2015) && count == 0))
2565 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002566
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 /* Workaround for potential 82544 hang in PCI-X. Avoid
2568 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002569 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2571 size > 4))
2572 size -= 4;
2573
2574 buffer_info->length = size;
2575 buffer_info->dma =
2576 pci_map_single(adapter->pdev,
2577 skb->data + offset,
2578 size,
2579 PCI_DMA_TODEVICE);
2580 buffer_info->time_stamp = jiffies;
2581
2582 len -= size;
2583 offset += size;
2584 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002585 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 }
2587
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002588 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 struct skb_frag_struct *frag;
2590
2591 frag = &skb_shinfo(skb)->frags[f];
2592 len = frag->size;
2593 offset = frag->page_offset;
2594
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002595 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 buffer_info = &tx_ring->buffer_info[i];
2597 size = min(len, max_per_txd);
2598#ifdef NETIF_F_TSO
2599 /* Workaround for premature desc write-backs
2600 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002601 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 size -= 4;
2603#endif
2604 /* Workaround for potential 82544 hang in PCI-X.
2605 * Avoid terminating buffers within evenly-aligned
2606 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002607 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2609 size > 4))
2610 size -= 4;
2611
2612 buffer_info->length = size;
2613 buffer_info->dma =
2614 pci_map_page(adapter->pdev,
2615 frag->page,
2616 offset,
2617 size,
2618 PCI_DMA_TODEVICE);
2619 buffer_info->time_stamp = jiffies;
2620
2621 len -= size;
2622 offset += size;
2623 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002624 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 }
2626 }
2627
2628 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2629 tx_ring->buffer_info[i].skb = skb;
2630 tx_ring->buffer_info[first].next_to_watch = i;
2631
2632 return count;
2633}
2634
Auke Koke619d522006-04-14 19:04:52 -07002635static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002636e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2637 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 struct e1000_tx_desc *tx_desc = NULL;
2640 struct e1000_buffer *buffer_info;
2641 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2642 unsigned int i;
2643
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002644 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2646 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002647 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2648
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002649 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002650 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 }
2652
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002653 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2655 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2656 }
2657
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002658 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 txd_lower |= E1000_TXD_CMD_VLE;
2660 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2661 }
2662
2663 i = tx_ring->next_to_use;
2664
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002665 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 buffer_info = &tx_ring->buffer_info[i];
2667 tx_desc = E1000_TX_DESC(*tx_ring, i);
2668 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2669 tx_desc->lower.data =
2670 cpu_to_le32(txd_lower | buffer_info->length);
2671 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002672 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 }
2674
2675 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2676
2677 /* Force memory writes to complete before letting h/w
2678 * know there are new descriptors to fetch. (Only
2679 * applicable for weak-ordered memory model archs,
2680 * such as IA-64). */
2681 wmb();
2682
2683 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002684 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685}
2686
2687/**
2688 * 82547 workaround to avoid controller hang in half-duplex environment.
2689 * The workaround is to avoid queuing a large packet that would span
2690 * the internal Tx FIFO ring boundary by notifying the stack to resend
2691 * the packet at a later time. This gives the Tx FIFO an opportunity to
2692 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2693 * to the beginning of the Tx FIFO.
2694 **/
2695
2696#define E1000_FIFO_HDR 0x10
2697#define E1000_82547_PAD_LEN 0x3E0
2698
Auke Koke619d522006-04-14 19:04:52 -07002699static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2701{
2702 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2703 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2704
2705 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2706
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002707 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 goto no_fifo_stall_required;
2709
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002710 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 return 1;
2712
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002713 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 atomic_set(&adapter->tx_fifo_stall, 1);
2715 return 1;
2716 }
2717
2718no_fifo_stall_required:
2719 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002720 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2722 return 0;
2723}
2724
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002725#define MINIMUM_DHCP_PACKET_SIZE 282
Auke Koke619d522006-04-14 19:04:52 -07002726static int
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002727e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2728{
2729 struct e1000_hw *hw = &adapter->hw;
2730 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002731 if (vlan_tx_tag_present(skb)) {
2732 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002733 ( adapter->hw.mng_cookie.status &
2734 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2735 return 0;
2736 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08002737 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002738 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002739 if ((htons(ETH_P_IP) == eth->h_proto)) {
2740 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002741 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002742 if (IPPROTO_UDP == ip->protocol) {
2743 struct udphdr *udp =
2744 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002745 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002746 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002747 offset = (uint8_t *)udp + 8 - skb->data;
2748 length = skb->len - offset;
2749
2750 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002751 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002752 length);
2753 }
2754 }
2755 }
2756 }
2757 return 0;
2758}
2759
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2761static int
2762e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2763{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002764 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002765 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2767 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2768 unsigned int tx_flags = 0;
2769 unsigned int len = skb->len;
2770 unsigned long flags;
2771 unsigned int nr_frags = 0;
2772 unsigned int mss = 0;
2773 int count = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002774 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 unsigned int f;
2776 len -= skb->data_len;
2777
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002778 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002779
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002780 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 dev_kfree_skb_any(skb);
2782 return NETDEV_TX_OK;
2783 }
2784
2785#ifdef NETIF_F_TSO
2786 mss = skb_shinfo(skb)->tso_size;
Malli Chilakala26483452005-04-28 19:44:46 -07002787 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 * make sure there is enough room in the FIFO before
2789 * initiating the DMA for each buffer. The calc is:
2790 * 4 = ceil(buffer len/mss). To make sure we don't
2791 * overrun the FIFO, adjust the max buffer len if mss
2792 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002793 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002794 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 max_per_txd = min(mss << 2, max_per_txd);
2796 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002797
Jeff Kirsher9f687882006-03-02 18:20:17 -08002798 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002799 * points to just header, pull a few bytes of payload from
2800 * frags into skb->data */
2801 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08002802 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
2803 switch (adapter->hw.mac_type) {
2804 unsigned int pull_size;
2805 case e1000_82571:
2806 case e1000_82572:
2807 case e1000_82573:
2808 pull_size = min((unsigned int)4, skb->data_len);
2809 if (!__pskb_pull_tail(skb, pull_size)) {
2810 printk(KERN_ERR
2811 "__pskb_pull_tail failed.\n");
2812 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05002813 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08002814 }
2815 len = skb->len - skb->data_len;
2816 break;
2817 default:
2818 /* do nothing */
2819 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08002820 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 }
2823
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002824 /* reserve a descriptor for the offload context */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002825 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07002827 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828#else
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002829 if (skb->ip_summed == CHECKSUM_HW)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 count++;
2831#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05002832
2833#ifdef NETIF_F_TSO
2834 /* Controller Erratum workaround */
2835 if (!skb->data_len && tx_ring->last_tx_tso &&
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002836 !skb_shinfo(skb)->tso_size)
Jeff Kirsherfd803242005-12-13 00:06:22 -05002837 count++;
2838#endif
2839
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 count += TXD_USE_COUNT(len, max_txd_pwr);
2841
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002842 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 count++;
2844
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002845 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07002846 * in PCI-X mode, so add one more descriptor to the count
2847 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002848 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002849 (len > 2015)))
2850 count++;
2851
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002853 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2855 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002856 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 count += nr_frags;
2858
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002859
2860 if (adapter->hw.tx_pkt_filtering &&
2861 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002862 e1000_transfer_dhcp_info(adapter, skb);
2863
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002864 local_irq_save(flags);
2865 if (!spin_trylock(&tx_ring->tx_lock)) {
2866 /* Collision - tell upper layer to requeue */
2867 local_irq_restore(flags);
2868 return NETDEV_TX_LOCKED;
2869 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870
2871 /* need: count + 2 desc gap to keep tail from touching
2872 * head, otherwise try next time */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002873 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 netif_stop_queue(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002875 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 return NETDEV_TX_BUSY;
2877 }
2878
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002879 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2880 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 netif_stop_queue(netdev);
2882 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002883 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 return NETDEV_TX_BUSY;
2885 }
2886 }
2887
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002888 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 tx_flags |= E1000_TX_FLAGS_VLAN;
2890 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2891 }
2892
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002893 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002894
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002895 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 if (tso < 0) {
2897 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002898 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 return NETDEV_TX_OK;
2900 }
2901
Jeff Kirsherfd803242005-12-13 00:06:22 -05002902 if (likely(tso)) {
2903 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002905 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 tx_flags |= E1000_TX_FLAGS_CSUM;
2907
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002908 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002909 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002910 * no longer assume, we must. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002911 if (likely(skb->protocol == ntohs(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002912 tx_flags |= E1000_TX_FLAGS_IPV4;
2913
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002914 e1000_tx_queue(adapter, tx_ring, tx_flags,
2915 e1000_tx_map(adapter, tx_ring, skb, first,
2916 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917
2918 netdev->trans_start = jiffies;
2919
2920 /* Make sure there is space in the ring for the next send. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002921 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 netif_stop_queue(netdev);
2923
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002924 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 return NETDEV_TX_OK;
2926}
2927
2928/**
2929 * e1000_tx_timeout - Respond to a Tx Hang
2930 * @netdev: network interface device structure
2931 **/
2932
2933static void
2934e1000_tx_timeout(struct net_device *netdev)
2935{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002936 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937
2938 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08002939 adapter->tx_timeout_count++;
2940 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941}
2942
2943static void
Jeff Kirsher87041632006-03-02 18:21:24 -08002944e1000_reset_task(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002946 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947
2948 e1000_down(adapter);
2949 e1000_up(adapter);
2950}
2951
2952/**
2953 * e1000_get_stats - Get System Network Statistics
2954 * @netdev: network interface device structure
2955 *
2956 * Returns the address of the device statistics structure.
2957 * The statistics are actually updated from the timer callback.
2958 **/
2959
2960static struct net_device_stats *
2961e1000_get_stats(struct net_device *netdev)
2962{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002963 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08002965 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 return &adapter->net_stats;
2967}
2968
2969/**
2970 * e1000_change_mtu - Change the Maximum Transfer Unit
2971 * @netdev: network interface device structure
2972 * @new_mtu: new value for maximum frame size
2973 *
2974 * Returns 0 on success, negative on failure
2975 **/
2976
2977static int
2978e1000_change_mtu(struct net_device *netdev, int new_mtu)
2979{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002980 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08002982 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002984 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2985 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2986 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002987 return -EINVAL;
2988 }
2989
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002990 /* Adapter-specific max frame size limits. */
2991 switch (adapter->hw.mac_type) {
Auke Kok9e2feac2006-04-14 19:05:18 -07002992 case e1000_undefined ... e1000_82542_rev2_1:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002993 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2994 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002995 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002996 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002997 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08002998 case e1000_82573:
2999 /* only enable jumbo frames if ASPM is disabled completely
3000 * this means both bits must be zero in 0x1A bits 3:2 */
3001 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
3002 &eeprom_data);
3003 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
3004 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3005 DPRINTK(PROBE, ERR,
3006 "Jumbo Frames not supported.\n");
3007 return -EINVAL;
3008 }
3009 break;
3010 }
3011 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003012 case e1000_82571:
3013 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003014 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003015#define MAX_STD_JUMBO_FRAME_SIZE 9234
3016 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3017 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3018 return -EINVAL;
3019 }
3020 break;
3021 default:
3022 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3023 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003024 }
3025
Auke Kok9e2feac2006-04-14 19:05:18 -07003026 /* NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3027 * means we reserve 2 more, this pushes us to allocate from the next
3028 * larger slab size
3029 * i.e. RXBUFFER_2048 --> size-4096 slab */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003030
Auke Kok9e2feac2006-04-14 19:05:18 -07003031 if (max_frame <= E1000_RXBUFFER_256)
3032 adapter->rx_buffer_len = E1000_RXBUFFER_256;
3033 else if (max_frame <= E1000_RXBUFFER_512)
3034 adapter->rx_buffer_len = E1000_RXBUFFER_512;
3035 else if (max_frame <= E1000_RXBUFFER_1024)
3036 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3037 else if (max_frame <= E1000_RXBUFFER_2048)
3038 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3039 else if (max_frame <= E1000_RXBUFFER_4096)
3040 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3041 else if (max_frame <= E1000_RXBUFFER_8192)
3042 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3043 else if (max_frame <= E1000_RXBUFFER_16384)
3044 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3045
3046 /* adjust allocation if LPE protects us, and we aren't using SBP */
3047#define MAXIMUM_ETHERNET_VLAN_SIZE 1522
3048 if (!adapter->hw.tbi_compatibility_on &&
3049 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3050 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3051 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003052
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003053 netdev->mtu = new_mtu;
3054
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003055 if (netif_running(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 e1000_down(adapter);
3057 e1000_up(adapter);
3058 }
3059
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 adapter->hw.max_frame_size = max_frame;
3061
3062 return 0;
3063}
3064
3065/**
3066 * e1000_update_stats - Update the board statistics counters
3067 * @adapter: board private structure
3068 **/
3069
3070void
3071e1000_update_stats(struct e1000_adapter *adapter)
3072{
3073 struct e1000_hw *hw = &adapter->hw;
3074 unsigned long flags;
3075 uint16_t phy_tmp;
3076
3077#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3078
3079 spin_lock_irqsave(&adapter->stats_lock, flags);
3080
3081 /* these counters are modified from e1000_adjust_tbi_stats,
3082 * called from the interrupt context, so they must only
3083 * be written while holding adapter->stats_lock
3084 */
3085
3086 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3087 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3088 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3089 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3090 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3091 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3092 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3093 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3094 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3095 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3096 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3097 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3098 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3099
3100 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3101 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3102 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3103 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3104 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3105 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3106 adapter->stats.dc += E1000_READ_REG(hw, DC);
3107 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3108 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3109 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3110 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3111 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3112 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3113 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3114 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3115 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3116 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3117 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3118 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3119 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3120 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3121 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3122 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3123 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3124 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3125 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3126 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3127 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3128 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3129 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3130 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3131 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3132 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3133 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3134
3135 /* used for adaptive IFS */
3136
3137 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3138 adapter->stats.tpt += hw->tx_packet_delta;
3139 hw->collision_delta = E1000_READ_REG(hw, COLC);
3140 adapter->stats.colc += hw->collision_delta;
3141
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003142 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3144 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3145 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3146 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3147 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3148 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3149 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003150 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003151 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3152 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3153 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3154 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3155 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3156 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3157 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3158 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3159 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
3162 /* Fill out the OS statistics structure */
3163
3164 adapter->net_stats.rx_packets = adapter->stats.gprc;
3165 adapter->net_stats.tx_packets = adapter->stats.gptc;
3166 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3167 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3168 adapter->net_stats.multicast = adapter->stats.mprc;
3169 adapter->net_stats.collisions = adapter->stats.colc;
3170
3171 /* Rx Errors */
3172
Jeff Kirsher87041632006-03-02 18:21:24 -08003173 /* RLEC on some newer hardware can be incorrect so build
3174 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3176 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003177 adapter->stats.ruc + adapter->stats.roc +
3178 adapter->stats.cexterr;
Jeff Kirsher87041632006-03-02 18:21:24 -08003179 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3180 adapter->stats.roc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3182 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3184
3185 /* Tx Errors */
3186
3187 adapter->net_stats.tx_errors = adapter->stats.ecol +
3188 adapter->stats.latecol;
3189 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3190 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3191 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3192
3193 /* Tx Dropped needs to be maintained elsewhere */
3194
3195 /* Phy Stats */
3196
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003197 if (hw->media_type == e1000_media_type_copper) {
3198 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3200 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3201 adapter->phy_stats.idle_errors += phy_tmp;
3202 }
3203
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003204 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 (hw->phy_type == e1000_phy_m88) &&
3206 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3207 adapter->phy_stats.receive_errors += phy_tmp;
3208 }
3209
3210 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3211}
3212
3213/**
3214 * e1000_intr - Interrupt Handler
3215 * @irq: interrupt number
3216 * @data: pointer to a network interface device structure
3217 * @pt_regs: CPU registers structure
3218 **/
3219
3220static irqreturn_t
3221e1000_intr(int irq, void *data, struct pt_regs *regs)
3222{
3223 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003224 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003226 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003227#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003228 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003229#else
3230 /* Interrupt Auto-Mask...upon reading ICR,
3231 * interrupts are masked. No need for the
3232 * IMC write, but it does mean we should
3233 * account for it ASAP. */
3234 if (likely(hw->mac_type >= e1000_82571))
3235 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003236#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003238 if (unlikely(!icr)) {
3239#ifdef CONFIG_E1000_NAPI
3240 if (hw->mac_type >= e1000_82571)
3241 e1000_irq_enable(adapter);
3242#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003246 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003248 /* 80003ES2LAN workaround--
3249 * For packet buffer work-around on link down event;
3250 * disable receives here in the ISR and
3251 * reset adapter in watchdog
3252 */
3253 if (netif_carrier_ok(netdev) &&
3254 (adapter->hw.mac_type == e1000_80003es2lan)) {
3255 /* disable receives */
3256 rctl = E1000_READ_REG(hw, RCTL);
3257 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 mod_timer(&adapter->watchdog_timer, jiffies);
3260 }
3261
3262#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003263 if (unlikely(hw->mac_type < e1000_82571)) {
3264 atomic_inc(&adapter->irq_sem);
3265 E1000_WRITE_REG(hw, IMC, ~0);
3266 E1000_WRITE_FLUSH(hw);
3267 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003268 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3269 __netif_rx_schedule(&adapter->polling_netdev[0]);
3270 else
3271 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003272#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003274 * Due to Hub Link bus being occupied, an interrupt
3275 * de-assertion message is not able to be sent.
3276 * When an interrupt assertion message is generated later,
3277 * two messages are re-ordered and sent out.
3278 * That causes APIC to think 82547 is in de-assertion
3279 * state, while 82547 is in assertion state, resulting
3280 * in dead lock. Writing IMC forces 82547 into
3281 * de-assertion state.
3282 */
3283 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003285 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 }
3287
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003288 for (i = 0; i < E1000_MAX_INTR; i++)
3289 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003290 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 break;
3292
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003293 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003295
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003296#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
3298 return IRQ_HANDLED;
3299}
3300
3301#ifdef CONFIG_E1000_NAPI
3302/**
3303 * e1000_clean - NAPI Rx polling callback
3304 * @adapter: board private structure
3305 **/
3306
3307static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003308e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003310 struct e1000_adapter *adapter;
3311 int work_to_do = min(*budget, poll_dev->quota);
Jeff Kirsher38bd3b22006-01-12 16:51:37 -08003312 int tx_cleaned = 0, i = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003313
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003314 /* Must NOT use netdev_priv macro here. */
3315 adapter = poll_dev->priv;
3316
3317 /* Keep link state information with original netdev */
3318 if (!netif_carrier_ok(adapter->netdev))
3319 goto quit_polling;
3320
3321 while (poll_dev != &adapter->polling_netdev[i]) {
3322 i++;
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02003323 BUG_ON(i == adapter->num_rx_queues);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003324 }
3325
Jeff Kirsher8241e352006-01-12 16:51:34 -08003326 if (likely(adapter->num_tx_queues == 1)) {
3327 /* e1000_clean is called per-cpu. This lock protects
3328 * tx_ring[0] from being cleaned by multiple cpus
3329 * simultaneously. A failure obtaining the lock means
3330 * tx_ring[0] is currently being cleaned anyway. */
3331 if (spin_trylock(&adapter->tx_queue_lock)) {
3332 tx_cleaned = e1000_clean_tx_irq(adapter,
3333 &adapter->tx_ring[0]);
3334 spin_unlock(&adapter->tx_queue_lock);
3335 }
3336 } else
3337 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3338
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003339 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3340 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
3342 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003343 poll_dev->quota -= work_done;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003344
Malli Chilakala2b028932005-06-17 17:46:06 -07003345 /* If no Tx and not enough Rx work done, exit the polling mode */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003346 if ((!tx_cleaned && (work_done == 0)) ||
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003347 !netif_running(adapter->netdev)) {
3348quit_polling:
3349 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 e1000_irq_enable(adapter);
3351 return 0;
3352 }
3353
3354 return 1;
3355}
3356
3357#endif
3358/**
3359 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3360 * @adapter: board private structure
3361 **/
3362
3363static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003364e1000_clean_tx_irq(struct e1000_adapter *adapter,
3365 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 struct net_device *netdev = adapter->netdev;
3368 struct e1000_tx_desc *tx_desc, *eop_desc;
3369 struct e1000_buffer *buffer_info;
3370 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003371#ifdef CONFIG_E1000_NAPI
3372 unsigned int count = 0;
3373#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 boolean_t cleaned = FALSE;
3375
3376 i = tx_ring->next_to_clean;
3377 eop = tx_ring->buffer_info[i].next_to_watch;
3378 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3379
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003380 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003381 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 tx_desc = E1000_TX_DESC(*tx_ring, i);
3383 buffer_info = &tx_ring->buffer_info[i];
3384 cleaned = (i == eop);
3385
Jeff Kirsherfd803242005-12-13 00:06:22 -05003386 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jeff Kirsher8241e352006-01-12 16:51:34 -08003387 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003389 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003391
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003392
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 eop = tx_ring->buffer_info[i].next_to_watch;
3394 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003395#ifdef CONFIG_E1000_NAPI
3396#define E1000_TX_WEIGHT 64
3397 /* weight of a sort for tx, to avoid endless transmit cleanup */
3398 if (count++ == E1000_TX_WEIGHT) break;
3399#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 }
3401
3402 tx_ring->next_to_clean = i;
3403
Auke Kok77b2aad2006-04-14 19:05:25 -07003404#define TX_WAKE_THRESHOLD 32
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003405 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
Auke Kok77b2aad2006-04-14 19:05:25 -07003406 netif_carrier_ok(netdev))) {
3407 spin_lock(&tx_ring->tx_lock);
3408 if (netif_queue_stopped(netdev) &&
3409 (E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))
3410 netif_wake_queue(netdev);
3411 spin_unlock(&tx_ring->tx_lock);
3412 }
Malli Chilakala26483452005-04-28 19:44:46 -07003413
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003414 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003415 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 * check with the clearing of time_stamp and movement of i */
3417 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003418 if (tx_ring->buffer_info[eop].dma &&
3419 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003420 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003421 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003422 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003423
3424 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003425 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003426 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003427 " TDH <%x>\n"
3428 " TDT <%x>\n"
3429 " next_to_use <%x>\n"
3430 " next_to_clean <%x>\n"
3431 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003432 " time_stamp <%lx>\n"
3433 " next_to_watch <%x>\n"
3434 " jiffies <%lx>\n"
3435 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003436 (unsigned long)((tx_ring - adapter->tx_ring) /
3437 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003438 readl(adapter->hw.hw_addr + tx_ring->tdh),
3439 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003440 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003441 tx_ring->next_to_clean,
3442 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003443 eop,
3444 jiffies,
3445 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 return cleaned;
3450}
3451
3452/**
3453 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003454 * @adapter: board private structure
3455 * @status_err: receive descriptor status and error fields
3456 * @csum: receive descriptor csum field
3457 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 **/
3459
Auke Koke619d522006-04-14 19:04:52 -07003460static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003462 uint32_t status_err, uint32_t csum,
3463 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003465 uint16_t status = (uint16_t)status_err;
3466 uint8_t errors = (uint8_t)(status_err >> 24);
3467 skb->ip_summed = CHECKSUM_NONE;
3468
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003470 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003472 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003473 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003474 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003475 /* let the stack verify checksum errors */
3476 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 return;
3478 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003479 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003480 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3481 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003482 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003484 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003485 return;
3486 }
3487 /* It must be a TCP or UDP packet with a valid checksum */
3488 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 /* TCP checksum is good */
3490 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003491 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3492 /* IP fragment with UDP payload */
3493 /* Hardware complements the payload checksum, so we undo it
3494 * and then put the value in host order for further stack use.
3495 */
3496 csum = ntohl(csum ^ 0xFFFF);
3497 skb->csum = csum;
3498 skb->ip_summed = CHECKSUM_HW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003500 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501}
3502
3503/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003504 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 * @adapter: board private structure
3506 **/
3507
3508static boolean_t
3509#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003510e1000_clean_rx_irq(struct e1000_adapter *adapter,
3511 struct e1000_rx_ring *rx_ring,
3512 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003514e1000_clean_rx_irq(struct e1000_adapter *adapter,
3515 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516#endif
3517{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 struct net_device *netdev = adapter->netdev;
3519 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003520 struct e1000_rx_desc *rx_desc, *next_rxd;
3521 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 unsigned long flags;
3523 uint32_t length;
3524 uint8_t last_byte;
3525 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003526 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003527 boolean_t cleaned = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528
3529 i = rx_ring->next_to_clean;
3530 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003531 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003533 while (rx_desc->status & E1000_RXD_STAT_DD) {
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003534 struct sk_buff *skb, *next_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003535 u8 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003537 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 break;
3539 (*work_done)++;
3540#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08003541 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003542 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003543 buffer_info->skb = NULL;
3544
Jeff Kirsher30320be2006-03-02 18:21:57 -08003545 prefetch(skb->data - NET_IP_ALIGN);
3546
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003547 if (++i == rx_ring->count) i = 0;
3548 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003549 prefetch(next_rxd);
3550
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003551 next_buffer = &rx_ring->buffer_info[i];
3552 next_skb = next_buffer->skb;
Jeff Kirsher30320be2006-03-02 18:21:57 -08003553 prefetch(next_skb->data - NET_IP_ALIGN);
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003554
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003555 cleaned = TRUE;
3556 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003557 pci_unmap_single(pdev,
3558 buffer_info->dma,
3559 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 PCI_DMA_FROMDEVICE);
3561
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 length = le16_to_cpu(rx_desc->length);
3563
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003564 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3565 /* All receives must fit into a single buffer */
3566 E1000_DBG("%s: Receive packet consumed multiple"
3567 " buffers\n", netdev->name);
3568 dev_kfree_skb_irq(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 goto next_desc;
3570 }
3571
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003572 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003574 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 rx_desc->errors, length, last_byte)) {
3576 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003577 e1000_tbi_adjust_stats(&adapter->hw,
3578 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 length, skb->data);
3580 spin_unlock_irqrestore(&adapter->stats_lock,
3581 flags);
3582 length--;
3583 } else {
Auke Kok9e2feac2006-04-14 19:05:18 -07003584 /* recycle */
3585 buffer_info->skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 goto next_desc;
3587 }
Auke Kok9e2feac2006-04-14 19:05:18 -07003588 } else
3589 skb_put(skb, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590
Jeff Kirshera292ca62006-01-12 16:51:30 -08003591 /* code added for copybreak, this should improve
3592 * performance for small packets with large amounts
3593 * of reassembly being done in the stack */
3594#define E1000_CB_LENGTH 256
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003595 if (length < E1000_CB_LENGTH) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08003596 struct sk_buff *new_skb =
3597 dev_alloc_skb(length + NET_IP_ALIGN);
3598 if (new_skb) {
3599 skb_reserve(new_skb, NET_IP_ALIGN);
3600 new_skb->dev = netdev;
3601 memcpy(new_skb->data - NET_IP_ALIGN,
3602 skb->data - NET_IP_ALIGN,
3603 length + NET_IP_ALIGN);
3604 /* save the skb in buffer_info as good */
3605 buffer_info->skb = skb;
3606 skb = new_skb;
3607 skb_put(skb, length);
3608 }
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003609 } else
3610 skb_put(skb, length);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003611
3612 /* end copybreak code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613
3614 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08003615 e1000_rx_checksum(adapter,
3616 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003617 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003618 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003619
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 skb->protocol = eth_type_trans(skb, netdev);
3621#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003622 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08003623 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003625 le16_to_cpu(rx_desc->special) &
3626 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 } else {
3628 netif_receive_skb(skb);
3629 }
3630#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003631 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003632 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 vlan_hwaccel_rx(skb, adapter->vlgrp,
3634 le16_to_cpu(rx_desc->special) &
3635 E1000_RXD_SPC_VLAN_MASK);
3636 } else {
3637 netif_rx(skb);
3638 }
3639#endif /* CONFIG_E1000_NAPI */
3640 netdev->last_rx = jiffies;
3641
3642next_desc:
3643 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003645 /* return some buffers to hardware, one at a time is too slow */
3646 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3647 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3648 cleaned_count = 0;
3649 }
3650
Jeff Kirsher30320be2006-03-02 18:21:57 -08003651 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003652 rx_desc = next_rxd;
3653 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003656
3657 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3658 if (cleaned_count)
3659 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660
3661 return cleaned;
3662}
3663
3664/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003665 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3666 * @adapter: board private structure
3667 **/
3668
3669static boolean_t
3670#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003671e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3672 struct e1000_rx_ring *rx_ring,
3673 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003674#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003675e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3676 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003677#endif
3678{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003679 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003680 struct net_device *netdev = adapter->netdev;
3681 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003682 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003683 struct e1000_ps_page *ps_page;
3684 struct e1000_ps_page_dma *ps_page_dma;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003685 struct sk_buff *skb, *next_skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003686 unsigned int i, j;
3687 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003688 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003689 boolean_t cleaned = FALSE;
3690
3691 i = rx_ring->next_to_clean;
3692 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003693 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Auke Kok9e2feac2006-04-14 19:05:18 -07003694 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003695
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003696 while (staterr & E1000_RXD_STAT_DD) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08003697 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003698 ps_page = &rx_ring->ps_page[i];
3699 ps_page_dma = &rx_ring->ps_page_dma[i];
3700#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003701 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003702 break;
3703 (*work_done)++;
3704#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003705 skb = buffer_info->skb;
3706
Jeff Kirsher30320be2006-03-02 18:21:57 -08003707 /* in the packet split case this is header only */
3708 prefetch(skb->data - NET_IP_ALIGN);
3709
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003710 if (++i == rx_ring->count) i = 0;
3711 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003712 prefetch(next_rxd);
3713
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003714 next_buffer = &rx_ring->buffer_info[i];
3715 next_skb = next_buffer->skb;
Jeff Kirsher30320be2006-03-02 18:21:57 -08003716 prefetch(next_skb->data - NET_IP_ALIGN);
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003717
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003718 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003719 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003720 pci_unmap_single(pdev, buffer_info->dma,
3721 buffer_info->length,
3722 PCI_DMA_FROMDEVICE);
3723
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003724 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003725 E1000_DBG("%s: Packet Split buffers didn't pick up"
3726 " the full packet\n", netdev->name);
3727 dev_kfree_skb_irq(skb);
3728 goto next_desc;
3729 }
3730
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003731 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003732 dev_kfree_skb_irq(skb);
3733 goto next_desc;
3734 }
3735
3736 length = le16_to_cpu(rx_desc->wb.middle.length0);
3737
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003738 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003739 E1000_DBG("%s: Last part of the packet spanning"
3740 " multiple descriptors\n", netdev->name);
3741 dev_kfree_skb_irq(skb);
3742 goto next_desc;
3743 }
3744
3745 /* Good Receive */
3746 skb_put(skb, length);
3747
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003748 {
3749 /* this looks ugly, but it seems compiler issues make it
3750 more efficient than reusing j */
3751 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3752
3753 /* page alloc/put takes too long and effects small packet
3754 * throughput, so unsplit small packets and save the alloc/put*/
Auke Kok9e2feac2006-04-14 19:05:18 -07003755 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003756 u8 *vaddr;
3757 /* there is no documentation about how to call
3758 * kmap_atomic, so we can't hold the mapping
3759 * very long */
3760 pci_dma_sync_single_for_cpu(pdev,
3761 ps_page_dma->ps_page_dma[0],
3762 PAGE_SIZE,
3763 PCI_DMA_FROMDEVICE);
3764 vaddr = kmap_atomic(ps_page->ps_page[0],
3765 KM_SKB_DATA_SOFTIRQ);
3766 memcpy(skb->tail, vaddr, l1);
3767 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
3768 pci_dma_sync_single_for_device(pdev,
3769 ps_page_dma->ps_page_dma[0],
3770 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3771 skb_put(skb, l1);
3772 length += l1;
3773 goto copydone;
3774 } /* if */
3775 }
3776
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003777 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08003778 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003779 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003780 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3781 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3782 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08003783 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
3784 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003785 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003786 skb->len += length;
3787 skb->data_len += length;
Auke Kok5d51b802006-04-14 19:05:06 -07003788 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003789 }
3790
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003791copydone:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003792 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003793 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003794 skb->protocol = eth_type_trans(skb, netdev);
3795
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003796 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003797 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003798 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003799#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003800 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003801 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003802 le16_to_cpu(rx_desc->wb.middle.vlan) &
3803 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003804 } else {
3805 netif_receive_skb(skb);
3806 }
3807#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003808 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003809 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003810 le16_to_cpu(rx_desc->wb.middle.vlan) &
3811 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003812 } else {
3813 netif_rx(skb);
3814 }
3815#endif /* CONFIG_E1000_NAPI */
3816 netdev->last_rx = jiffies;
3817
3818next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003819 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003820 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003821
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003822 /* return some buffers to hardware, one at a time is too slow */
3823 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3824 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3825 cleaned_count = 0;
3826 }
3827
Jeff Kirsher30320be2006-03-02 18:21:57 -08003828 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003829 rx_desc = next_rxd;
3830 buffer_info = next_buffer;
3831
Malli Chilakala683a38f2005-06-17 17:43:25 -07003832 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003833 }
3834 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003835
3836 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3837 if (cleaned_count)
3838 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003839
3840 return cleaned;
3841}
3842
3843/**
3844 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 * @adapter: address of board private structure
3846 **/
3847
3848static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003849e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003850 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08003851 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 struct net_device *netdev = adapter->netdev;
3854 struct pci_dev *pdev = adapter->pdev;
3855 struct e1000_rx_desc *rx_desc;
3856 struct e1000_buffer *buffer_info;
3857 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003858 unsigned int i;
3859 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860
3861 i = rx_ring->next_to_use;
3862 buffer_info = &rx_ring->buffer_info[i];
3863
Jeff Kirshera292ca62006-01-12 16:51:30 -08003864 while (cleaned_count--) {
3865 if (!(skb = buffer_info->skb))
3866 skb = dev_alloc_skb(bufsz);
3867 else {
3868 skb_trim(skb, 0);
3869 goto map_skb;
3870 }
3871
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003872 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003874 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 break;
3876 }
3877
Malli Chilakala26483452005-04-28 19:44:46 -07003878 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3880 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003881 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3882 "at %p\n", bufsz, skb->data);
3883 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 skb = dev_alloc_skb(bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07003885 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 if (!skb) {
3887 dev_kfree_skb(oldskb);
3888 break;
3889 }
Malli Chilakala26483452005-04-28 19:44:46 -07003890
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3892 /* give up */
3893 dev_kfree_skb(skb);
3894 dev_kfree_skb(oldskb);
3895 break; /* while !buffer_info->skb */
3896 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07003897 /* Use new allocation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 dev_kfree_skb(oldskb);
3899 }
3900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 /* Make buffer alignment 2 beyond a 16 byte boundary
3902 * this will result in a 16 byte aligned IP header after
3903 * the 14 byte MAC header is removed
3904 */
3905 skb_reserve(skb, NET_IP_ALIGN);
3906
3907 skb->dev = netdev;
3908
3909 buffer_info->skb = skb;
3910 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003911map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 buffer_info->dma = pci_map_single(pdev,
3913 skb->data,
3914 adapter->rx_buffer_len,
3915 PCI_DMA_FROMDEVICE);
3916
Malli Chilakala26483452005-04-28 19:44:46 -07003917 /* Fix for errata 23, can't cross 64kB boundary */
3918 if (!e1000_check_64k_bound(adapter,
3919 (void *)(unsigned long)buffer_info->dma,
3920 adapter->rx_buffer_len)) {
3921 DPRINTK(RX_ERR, ERR,
3922 "dma align check failed: %u bytes at %p\n",
3923 adapter->rx_buffer_len,
3924 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 dev_kfree_skb(skb);
3926 buffer_info->skb = NULL;
3927
Malli Chilakala26483452005-04-28 19:44:46 -07003928 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 adapter->rx_buffer_len,
3930 PCI_DMA_FROMDEVICE);
3931
3932 break; /* while !buffer_info->skb */
3933 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 rx_desc = E1000_RX_DESC(*rx_ring, i);
3935 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3936
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003937 if (unlikely(++i == rx_ring->count))
3938 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 buffer_info = &rx_ring->buffer_info[i];
3940 }
3941
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003942 if (likely(rx_ring->next_to_use != i)) {
3943 rx_ring->next_to_use = i;
3944 if (unlikely(i-- == 0))
3945 i = (rx_ring->count - 1);
3946
3947 /* Force memory writes to complete before letting h/w
3948 * know there are new descriptors to fetch. (Only
3949 * applicable for weak-ordered memory model archs,
3950 * such as IA-64). */
3951 wmb();
3952 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3953 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954}
3955
3956/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003957 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3958 * @adapter: address of board private structure
3959 **/
3960
3961static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003962e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003963 struct e1000_rx_ring *rx_ring,
3964 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003965{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003966 struct net_device *netdev = adapter->netdev;
3967 struct pci_dev *pdev = adapter->pdev;
3968 union e1000_rx_desc_packet_split *rx_desc;
3969 struct e1000_buffer *buffer_info;
3970 struct e1000_ps_page *ps_page;
3971 struct e1000_ps_page_dma *ps_page_dma;
3972 struct sk_buff *skb;
3973 unsigned int i, j;
3974
3975 i = rx_ring->next_to_use;
3976 buffer_info = &rx_ring->buffer_info[i];
3977 ps_page = &rx_ring->ps_page[i];
3978 ps_page_dma = &rx_ring->ps_page_dma[i];
3979
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003980 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003981 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3982
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003983 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003984 if (j < adapter->rx_ps_pages) {
3985 if (likely(!ps_page->ps_page[j])) {
3986 ps_page->ps_page[j] =
3987 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003988 if (unlikely(!ps_page->ps_page[j])) {
3989 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003990 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003991 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003992 ps_page_dma->ps_page_dma[j] =
3993 pci_map_page(pdev,
3994 ps_page->ps_page[j],
3995 0, PAGE_SIZE,
3996 PCI_DMA_FROMDEVICE);
3997 }
3998 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003999 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004000 * this info.
4001 */
4002 rx_desc->read.buffer_addr[j+1] =
4003 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4004 } else
4005 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004006 }
4007
4008 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4009
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004010 if (unlikely(!skb)) {
4011 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004012 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004013 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004014
4015 /* Make buffer alignment 2 beyond a 16 byte boundary
4016 * this will result in a 16 byte aligned IP header after
4017 * the 14 byte MAC header is removed
4018 */
4019 skb_reserve(skb, NET_IP_ALIGN);
4020
4021 skb->dev = netdev;
4022
4023 buffer_info->skb = skb;
4024 buffer_info->length = adapter->rx_ps_bsize0;
4025 buffer_info->dma = pci_map_single(pdev, skb->data,
4026 adapter->rx_ps_bsize0,
4027 PCI_DMA_FROMDEVICE);
4028
4029 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4030
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004031 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004032 buffer_info = &rx_ring->buffer_info[i];
4033 ps_page = &rx_ring->ps_page[i];
4034 ps_page_dma = &rx_ring->ps_page_dma[i];
4035 }
4036
4037no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004038 if (likely(rx_ring->next_to_use != i)) {
4039 rx_ring->next_to_use = i;
4040 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4041
4042 /* Force memory writes to complete before letting h/w
4043 * know there are new descriptors to fetch. (Only
4044 * applicable for weak-ordered memory model archs,
4045 * such as IA-64). */
4046 wmb();
4047 /* Hardware increments by 16 bytes, but packet split
4048 * descriptors are 32 bytes...so we increment tail
4049 * twice as much.
4050 */
4051 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4052 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004053}
4054
4055/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4057 * @adapter:
4058 **/
4059
4060static void
4061e1000_smartspeed(struct e1000_adapter *adapter)
4062{
4063 uint16_t phy_status;
4064 uint16_t phy_ctrl;
4065
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004066 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4068 return;
4069
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004070 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 /* If Master/Slave config fault is asserted twice,
4072 * we assume back-to-back */
4073 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004074 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004076 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004078 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4080 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4081 phy_ctrl);
4082 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004083 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4085 &phy_ctrl)) {
4086 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4087 MII_CR_RESTART_AUTO_NEG);
4088 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4089 phy_ctrl);
4090 }
4091 }
4092 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004093 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 /* If still no link, perhaps using 2/3 pair cable */
4095 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4096 phy_ctrl |= CR_1000T_MS_ENABLE;
4097 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004098 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4100 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4101 MII_CR_RESTART_AUTO_NEG);
4102 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4103 }
4104 }
4105 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004106 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 adapter->smartspeed = 0;
4108}
4109
4110/**
4111 * e1000_ioctl -
4112 * @netdev:
4113 * @ifreq:
4114 * @cmd:
4115 **/
4116
4117static int
4118e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4119{
4120 switch (cmd) {
4121 case SIOCGMIIPHY:
4122 case SIOCGMIIREG:
4123 case SIOCSMIIREG:
4124 return e1000_mii_ioctl(netdev, ifr, cmd);
4125 default:
4126 return -EOPNOTSUPP;
4127 }
4128}
4129
4130/**
4131 * e1000_mii_ioctl -
4132 * @netdev:
4133 * @ifreq:
4134 * @cmd:
4135 **/
4136
4137static int
4138e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4139{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004140 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 struct mii_ioctl_data *data = if_mii(ifr);
4142 int retval;
4143 uint16_t mii_reg;
4144 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004145 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004147 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 return -EOPNOTSUPP;
4149
4150 switch (cmd) {
4151 case SIOCGMIIPHY:
4152 data->phy_id = adapter->hw.phy_addr;
4153 break;
4154 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004155 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004157 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004158 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004159 &data->val_out)) {
4160 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004162 }
4163 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 break;
4165 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004166 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004168 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 return -EFAULT;
4170 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004171 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004172 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004173 mii_reg)) {
4174 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004176 }
Auke Kokdc86d322006-04-18 12:30:51 -07004177 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 switch (data->reg_num) {
4179 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004180 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004182 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 adapter->hw.autoneg = 1;
4184 adapter->hw.autoneg_advertised = 0x2F;
4185 } else {
4186 if (mii_reg & 0x40)
4187 spddplx = SPEED_1000;
4188 else if (mii_reg & 0x2000)
4189 spddplx = SPEED_100;
4190 else
4191 spddplx = SPEED_10;
4192 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004193 ? DUPLEX_FULL :
4194 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 retval = e1000_set_spd_dplx(adapter,
4196 spddplx);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004197 if (retval) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004198 spin_unlock_irqrestore(
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004199 &adapter->stats_lock,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004200 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004204 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 e1000_down(adapter);
4206 e1000_up(adapter);
4207 } else
4208 e1000_reset(adapter);
4209 break;
4210 case M88E1000_PHY_SPEC_CTRL:
4211 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004212 if (e1000_phy_reset(&adapter->hw)) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004213 spin_unlock_irqrestore(
4214 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 break;
4218 }
4219 } else {
4220 switch (data->reg_num) {
4221 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004222 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004224 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 e1000_down(adapter);
4226 e1000_up(adapter);
4227 } else
4228 e1000_reset(adapter);
4229 break;
4230 }
4231 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004232 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233 break;
4234 default:
4235 return -EOPNOTSUPP;
4236 }
4237 return E1000_SUCCESS;
4238}
4239
4240void
4241e1000_pci_set_mwi(struct e1000_hw *hw)
4242{
4243 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004244 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004246 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004247 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248}
4249
4250void
4251e1000_pci_clear_mwi(struct e1000_hw *hw)
4252{
4253 struct e1000_adapter *adapter = hw->back;
4254
4255 pci_clear_mwi(adapter->pdev);
4256}
4257
4258void
4259e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4260{
4261 struct e1000_adapter *adapter = hw->back;
4262
4263 pci_read_config_word(adapter->pdev, reg, value);
4264}
4265
4266void
4267e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4268{
4269 struct e1000_adapter *adapter = hw->back;
4270
4271 pci_write_config_word(adapter->pdev, reg, *value);
4272}
4273
4274uint32_t
4275e1000_io_read(struct e1000_hw *hw, unsigned long port)
4276{
4277 return inl(port);
4278}
4279
4280void
4281e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4282{
4283 outl(value, port);
4284}
4285
4286static void
4287e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4288{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004289 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290 uint32_t ctrl, rctl;
4291
4292 e1000_irq_disable(adapter);
4293 adapter->vlgrp = grp;
4294
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004295 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 /* enable VLAN tag insert/strip */
4297 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4298 ctrl |= E1000_CTRL_VME;
4299 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4300
4301 /* enable VLAN receive filtering */
4302 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4303 rctl |= E1000_RCTL_VFE;
4304 rctl &= ~E1000_RCTL_CFIEN;
4305 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004306 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 } else {
4308 /* disable VLAN tag insert/strip */
4309 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4310 ctrl &= ~E1000_CTRL_VME;
4311 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4312
4313 /* disable VLAN filtering */
4314 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4315 rctl &= ~E1000_RCTL_VFE;
4316 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004317 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004318 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4319 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 }
4322
4323 e1000_irq_enable(adapter);
4324}
4325
4326static void
4327e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4328{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004329 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004331
4332 if ((adapter->hw.mng_cookie.status &
4333 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4334 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004335 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 /* add VID to filter table */
4337 index = (vid >> 5) & 0x7F;
4338 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4339 vfta |= (1 << (vid & 0x1F));
4340 e1000_write_vfta(&adapter->hw, index, vfta);
4341}
4342
4343static void
4344e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4345{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004346 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 uint32_t vfta, index;
4348
4349 e1000_irq_disable(adapter);
4350
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004351 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 adapter->vlgrp->vlan_devices[vid] = NULL;
4353
4354 e1000_irq_enable(adapter);
4355
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004356 if ((adapter->hw.mng_cookie.status &
4357 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004358 (vid == adapter->mng_vlan_id)) {
4359 /* release control to f/w */
4360 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004361 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004362 }
4363
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 /* remove VID from filter table */
4365 index = (vid >> 5) & 0x7F;
4366 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4367 vfta &= ~(1 << (vid & 0x1F));
4368 e1000_write_vfta(&adapter->hw, index, vfta);
4369}
4370
4371static void
4372e1000_restore_vlan(struct e1000_adapter *adapter)
4373{
4374 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4375
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004376 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004378 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4379 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 continue;
4381 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4382 }
4383 }
4384}
4385
4386int
4387e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4388{
4389 adapter->hw.autoneg = 0;
4390
Malli Chilakala69213682005-06-17 17:44:20 -07004391 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004392 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004393 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4394 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4395 return -EINVAL;
4396 }
4397
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004398 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 case SPEED_10 + DUPLEX_HALF:
4400 adapter->hw.forced_speed_duplex = e1000_10_half;
4401 break;
4402 case SPEED_10 + DUPLEX_FULL:
4403 adapter->hw.forced_speed_duplex = e1000_10_full;
4404 break;
4405 case SPEED_100 + DUPLEX_HALF:
4406 adapter->hw.forced_speed_duplex = e1000_100_half;
4407 break;
4408 case SPEED_100 + DUPLEX_FULL:
4409 adapter->hw.forced_speed_duplex = e1000_100_full;
4410 break;
4411 case SPEED_1000 + DUPLEX_FULL:
4412 adapter->hw.autoneg = 1;
4413 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4414 break;
4415 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4416 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004417 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 return -EINVAL;
4419 }
4420 return 0;
4421}
4422
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004423#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004424/* Save/restore 16 or 64 dwords of PCI config space depending on which
4425 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004426 */
4427#define PCIE_CONFIG_SPACE_LEN 256
4428#define PCI_CONFIG_SPACE_LEN 64
4429static int
4430e1000_pci_save_state(struct e1000_adapter *adapter)
4431{
4432 struct pci_dev *dev = adapter->pdev;
4433 int size;
4434 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004435
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004436 if (adapter->hw.mac_type >= e1000_82571)
4437 size = PCIE_CONFIG_SPACE_LEN;
4438 else
4439 size = PCI_CONFIG_SPACE_LEN;
4440
4441 WARN_ON(adapter->config_space != NULL);
4442
4443 adapter->config_space = kmalloc(size, GFP_KERNEL);
4444 if (!adapter->config_space) {
4445 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4446 return -ENOMEM;
4447 }
4448 for (i = 0; i < (size / 4); i++)
4449 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4450 return 0;
4451}
4452
4453static void
4454e1000_pci_restore_state(struct e1000_adapter *adapter)
4455{
4456 struct pci_dev *dev = adapter->pdev;
4457 int size;
4458 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004459
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004460 if (adapter->config_space == NULL)
4461 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004462
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004463 if (adapter->hw.mac_type >= e1000_82571)
4464 size = PCIE_CONFIG_SPACE_LEN;
4465 else
4466 size = PCI_CONFIG_SPACE_LEN;
4467 for (i = 0; i < (size / 4); i++)
4468 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4469 kfree(adapter->config_space);
4470 adapter->config_space = NULL;
4471 return;
4472}
4473#endif /* CONFIG_PM */
4474
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004476e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477{
4478 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004479 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004480 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 uint32_t wufc = adapter->wol;
Jeff Kirsher240b1712006-01-12 16:51:28 -08004482 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483
4484 netif_device_detach(netdev);
4485
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004486 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 e1000_down(adapter);
4488
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004489#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004490 /* Implement our own version of pci_save_state(pdev) because pci-
4491 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004492 retval = e1000_pci_save_state(adapter);
4493 if (retval)
4494 return retval;
4495#endif
4496
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004498 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 wufc &= ~E1000_WUFC_LNKC;
4500
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004501 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 e1000_setup_rctl(adapter);
4503 e1000_set_multi(netdev);
4504
4505 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004506 if (adapter->wol & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4508 rctl |= E1000_RCTL_MPE;
4509 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4510 }
4511
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004512 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4514 /* advertise wake from D3Cold */
4515 #define E1000_CTRL_ADVD3WUC 0x00100000
4516 /* phy power management enable */
4517 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4518 ctrl |= E1000_CTRL_ADVD3WUC |
4519 E1000_CTRL_EN_PHY_PWR_MGMT;
4520 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4521 }
4522
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004523 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4525 /* keep the laser running in D3 */
4526 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4527 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4528 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4529 }
4530
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004531 /* Allow time for pending master requests to run */
4532 e1000_disable_pciex_master(&adapter->hw);
4533
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4535 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004536 pci_enable_wake(pdev, PCI_D3hot, 1);
4537 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 } else {
4539 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4540 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Auke Kokd0e027d2006-04-14 19:04:40 -07004541 pci_enable_wake(pdev, PCI_D3hot, 0);
4542 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 }
4544
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004545 if (adapter->hw.mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546 adapter->hw.media_type == e1000_media_type_copper) {
4547 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004548 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 manc |= E1000_MANC_ARP_EN;
4550 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Auke Kokd0e027d2006-04-14 19:04:40 -07004551 pci_enable_wake(pdev, PCI_D3hot, 1);
4552 pci_enable_wake(pdev, PCI_D3cold, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 }
4554 }
4555
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004556 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4557 * would have already happened in close and is redundant. */
4558 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004559
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004561
Auke Kokd0e027d2006-04-14 19:04:40 -07004562 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563
4564 return 0;
4565}
4566
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004567#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568static int
4569e1000_resume(struct pci_dev *pdev)
4570{
4571 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004572 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004573 uint32_t manc, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574
Auke Kokd0e027d2006-04-14 19:04:40 -07004575 pci_set_power_state(pdev, PCI_D0);
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004576 e1000_pci_restore_state(adapter);
Malli Chilakala2b028932005-06-17 17:46:06 -07004577 ret_val = pci_enable_device(pdev);
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004578 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579
Auke Kokd0e027d2006-04-14 19:04:40 -07004580 pci_enable_wake(pdev, PCI_D3hot, 0);
4581 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582
4583 e1000_reset(adapter);
4584 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4585
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004586 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 e1000_up(adapter);
4588
4589 netif_device_attach(netdev);
4590
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004591 if (adapter->hw.mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 adapter->hw.media_type == e1000_media_type_copper) {
4593 manc = E1000_READ_REG(&adapter->hw, MANC);
4594 manc &= ~(E1000_MANC_ARP_EN);
4595 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4596 }
4597
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004598 /* If the controller is 82573 and f/w is AMT, do not set
4599 * DRV_LOAD until the interface is up. For all other cases,
4600 * let the f/w know that the h/w is now under the control
4601 * of the driver. */
4602 if (adapter->hw.mac_type != e1000_82573 ||
4603 !e1000_check_mng_mode(&adapter->hw))
4604 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004605
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 return 0;
4607}
4608#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609#ifdef CONFIG_NET_POLL_CONTROLLER
4610/*
4611 * Polling 'interrupt' - used by things like netconsole to send skbs
4612 * without having to re-enable interrupts. It's not called while
4613 * the interrupt routine is executing.
4614 */
4615static void
Malli Chilakala26483452005-04-28 19:44:46 -07004616e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004618 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 disable_irq(adapter->pdev->irq);
4620 e1000_intr(adapter->pdev->irq, netdev, NULL);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004621 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004622#ifndef CONFIG_E1000_NAPI
4623 adapter->clean_rx(adapter, adapter->rx_ring);
4624#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 enable_irq(adapter->pdev->irq);
4626}
4627#endif
4628
4629/* e1000_main.c */