blob: c99e87838f92913ce277c9a2494955551cb79f04 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
3
Malli Chilakala26483452005-04-28 19:44:46 -07004 Copyright(c) 1999 - 2005 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>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include "e1000.h"
30
31/* Change Log
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -080032 * 7.0.33 3-Feb-2006
33 * o Added another fix for the pass false carrier bit
34 * 7.0.32 24-Jan-2006
35 * o Need to rebuild with noew version number for the pass false carrier
36 * fix in e1000_hw.c
37 * 7.0.30 18-Jan-2006
38 * o fixup for tso workaround to disable it for pci-x
39 * o fix mem leak on 82542
40 * o fixes for 10 Mb/s connections and incorrect stats
41 * 7.0.28 01/06/2006
42 * o hardware workaround to only set "speed mode" bit for 1G link.
43 * 7.0.26 12/23/2005
44 * o wake on lan support modified for device ID 10B5
45 * o fix dhcp + vlan issue not making it to the iAMT firmware
46 * 7.0.24 12/9/2005
47 * o New hardware support for the Gigabit NIC embedded in the south bridge
48 * o Fixes to the recycling logic (skb->tail) from IBM LTC
Jesse Brandeburg73629bb2006-01-18 13:01:41 -080049 * 6.3.9 12/16/2005
50 * o incorporate fix for recycled skbs from IBM LTC
51 * 6.3.7 11/18/2005
52 * o Honor eeprom setting for enabling/disabling Wake On Lan
53 * 6.3.5 11/17/2005
54 * o Fix memory leak in rx ring handling for PCI Express adapters
55 * 6.3.4 11/8/05
56 * o Patch from Jesper Juhl to remove redundant NULL checks for kfree
57 * 6.3.2 9/20/05
58 * o Render logic that sets/resets DRV_LOAD as inline functions to
59 * avoid code replication. If f/w is AMT then set DRV_LOAD only when
60 * network interface is open.
61 * o Handle DRV_LOAD set/reset in cases where AMT uses VLANs.
62 * o Adjust PBA partioning for Jumbo frames using MTU size and not
63 * rx_buffer_len
64 * 6.3.1 9/19/05
65 * o Use adapter->tx_timeout_factor in Tx Hung Detect logic
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -080066 * (e1000_clean_tx_irq)
Jesse Brandeburg73629bb2006-01-18 13:01:41 -080067 * o Support for 8086:10B5 device (Quad Port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 */
69
70char e1000_driver_name[] = "e1000";
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010071static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#ifndef CONFIG_E1000_NAPI
73#define DRIVERNAPI
74#else
75#define DRIVERNAPI "-NAPI"
76#endif
Jeff Kirsherc1605eb2006-03-02 18:16:38 -080077#define DRV_VERSION "7.0.33-k2"DRIVERNAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -070078char e1000_driver_version[] = DRV_VERSION;
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010079static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/* e1000_pci_tbl - PCI Device ID Table
82 *
83 * Last entry must be all 0s
84 *
85 * Macro expands to...
86 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
87 */
88static struct pci_device_id e1000_pci_tbl[] = {
89 INTEL_E1000_ETHERNET_DEVICE(0x1000),
90 INTEL_E1000_ETHERNET_DEVICE(0x1001),
91 INTEL_E1000_ETHERNET_DEVICE(0x1004),
92 INTEL_E1000_ETHERNET_DEVICE(0x1008),
93 INTEL_E1000_ETHERNET_DEVICE(0x1009),
94 INTEL_E1000_ETHERNET_DEVICE(0x100C),
95 INTEL_E1000_ETHERNET_DEVICE(0x100D),
96 INTEL_E1000_ETHERNET_DEVICE(0x100E),
97 INTEL_E1000_ETHERNET_DEVICE(0x100F),
98 INTEL_E1000_ETHERNET_DEVICE(0x1010),
99 INTEL_E1000_ETHERNET_DEVICE(0x1011),
100 INTEL_E1000_ETHERNET_DEVICE(0x1012),
101 INTEL_E1000_ETHERNET_DEVICE(0x1013),
102 INTEL_E1000_ETHERNET_DEVICE(0x1014),
103 INTEL_E1000_ETHERNET_DEVICE(0x1015),
104 INTEL_E1000_ETHERNET_DEVICE(0x1016),
105 INTEL_E1000_ETHERNET_DEVICE(0x1017),
106 INTEL_E1000_ETHERNET_DEVICE(0x1018),
107 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -0700108 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 INTEL_E1000_ETHERNET_DEVICE(0x101D),
110 INTEL_E1000_ETHERNET_DEVICE(0x101E),
111 INTEL_E1000_ETHERNET_DEVICE(0x1026),
112 INTEL_E1000_ETHERNET_DEVICE(0x1027),
113 INTEL_E1000_ETHERNET_DEVICE(0x1028),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400114 INTEL_E1000_ETHERNET_DEVICE(0x105E),
115 INTEL_E1000_ETHERNET_DEVICE(0x105F),
116 INTEL_E1000_ETHERNET_DEVICE(0x1060),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 INTEL_E1000_ETHERNET_DEVICE(0x1075),
118 INTEL_E1000_ETHERNET_DEVICE(0x1076),
119 INTEL_E1000_ETHERNET_DEVICE(0x1077),
120 INTEL_E1000_ETHERNET_DEVICE(0x1078),
121 INTEL_E1000_ETHERNET_DEVICE(0x1079),
122 INTEL_E1000_ETHERNET_DEVICE(0x107A),
123 INTEL_E1000_ETHERNET_DEVICE(0x107B),
124 INTEL_E1000_ETHERNET_DEVICE(0x107C),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400125 INTEL_E1000_ETHERNET_DEVICE(0x107D),
126 INTEL_E1000_ETHERNET_DEVICE(0x107E),
127 INTEL_E1000_ETHERNET_DEVICE(0x107F),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Malli Chilakala26483452005-04-28 19:44:46 -0700129 INTEL_E1000_ETHERNET_DEVICE(0x108B),
130 INTEL_E1000_ETHERNET_DEVICE(0x108C),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800131 INTEL_E1000_ETHERNET_DEVICE(0x1096),
132 INTEL_E1000_ETHERNET_DEVICE(0x1098),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800133 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400134 INTEL_E1000_ETHERNET_DEVICE(0x109A),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800135 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800136 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 /* required last entry */
138 {0,}
139};
140
141MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
142
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100143static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800144 struct e1000_tx_ring *txdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100145static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800146 struct e1000_rx_ring *rxdr);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100147static void e1000_free_tx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800148 struct e1000_tx_ring *tx_ring);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100149static void e1000_free_rx_resources(struct e1000_adapter *adapter,
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -0800150 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152/* Local Function Prototypes */
153
154static int e1000_init_module(void);
155static void e1000_exit_module(void);
156static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
157static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400158static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static int e1000_sw_init(struct e1000_adapter *adapter);
160static int e1000_open(struct net_device *netdev);
161static int e1000_close(struct net_device *netdev);
162static void e1000_configure_tx(struct e1000_adapter *adapter);
163static void e1000_configure_rx(struct e1000_adapter *adapter);
164static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400165static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
166static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
167static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
168 struct e1000_tx_ring *tx_ring);
169static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
170 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171static void e1000_set_multi(struct net_device *netdev);
172static void e1000_update_phy_info(unsigned long data);
173static void e1000_watchdog(unsigned long data);
174static void e1000_watchdog_task(struct e1000_adapter *adapter);
175static void e1000_82547_tx_fifo_stall(unsigned long data);
176static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
177static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
178static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
179static int e1000_set_mac(struct net_device *netdev, void *p);
180static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400181static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
182 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400184static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400186 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700188static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400189 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700190 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400192static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
193 struct e1000_rx_ring *rx_ring);
194static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
195 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400197static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800198 struct e1000_rx_ring *rx_ring,
199 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400200static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800201 struct e1000_rx_ring *rx_ring,
202 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
204static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
205 int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
207static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
208static void e1000_tx_timeout(struct net_device *dev);
Jeff Kirsher87041632006-03-02 18:21:24 -0800209static void e1000_reset_task(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static void e1000_smartspeed(struct e1000_adapter *adapter);
211static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
212 struct sk_buff *skb);
213
214static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
215static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
216static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
217static void e1000_restore_vlan(struct e1000_adapter *adapter);
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#ifdef CONFIG_PM
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700220static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static int e1000_resume(struct pci_dev *pdev);
222#endif
223
224#ifdef CONFIG_NET_POLL_CONTROLLER
225/* for netdump / net console */
226static void e1000_netpoll (struct net_device *netdev);
227#endif
228
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static struct pci_driver e1000_driver = {
231 .name = e1000_driver_name,
232 .id_table = e1000_pci_tbl,
233 .probe = e1000_probe,
234 .remove = __devexit_p(e1000_remove),
235 /* Power Managment Hooks */
236#ifdef CONFIG_PM
237 .suspend = e1000_suspend,
238 .resume = e1000_resume
239#endif
240};
241
242MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
243MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
244MODULE_LICENSE("GPL");
245MODULE_VERSION(DRV_VERSION);
246
247static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
248module_param(debug, int, 0);
249MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
250
251/**
252 * e1000_init_module - Driver Registration Routine
253 *
254 * e1000_init_module is the first routine called when the driver is
255 * loaded. All it does is register with the PCI subsystem.
256 **/
257
258static int __init
259e1000_init_module(void)
260{
261 int ret;
262 printk(KERN_INFO "%s - version %s\n",
263 e1000_driver_string, e1000_driver_version);
264
265 printk(KERN_INFO "%s\n", e1000_copyright);
266
267 ret = pci_module_init(&e1000_driver);
Tony Luck8b378def2005-07-28 01:07:38 -0700268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 return ret;
270}
271
272module_init(e1000_init_module);
273
274/**
275 * e1000_exit_module - Driver Exit Cleanup Routine
276 *
277 * e1000_exit_module is called just before the driver is removed
278 * from memory.
279 **/
280
281static void __exit
282e1000_exit_module(void)
283{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 pci_unregister_driver(&e1000_driver);
285}
286
287module_exit(e1000_exit_module);
288
289/**
290 * e1000_irq_disable - Mask off interrupt generation on the NIC
291 * @adapter: board private structure
292 **/
293
294static inline void
295e1000_irq_disable(struct e1000_adapter *adapter)
296{
297 atomic_inc(&adapter->irq_sem);
298 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
299 E1000_WRITE_FLUSH(&adapter->hw);
300 synchronize_irq(adapter->pdev->irq);
301}
302
303/**
304 * e1000_irq_enable - Enable default interrupt generation settings
305 * @adapter: board private structure
306 **/
307
308static inline void
309e1000_irq_enable(struct e1000_adapter *adapter)
310{
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800311 if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
313 E1000_WRITE_FLUSH(&adapter->hw);
314 }
315}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100316
317static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700318e1000_update_mng_vlan(struct e1000_adapter *adapter)
319{
320 struct net_device *netdev = adapter->netdev;
321 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
322 uint16_t old_vid = adapter->mng_vlan_id;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800323 if (adapter->vlgrp) {
324 if (!adapter->vlgrp->vlan_devices[vid]) {
325 if (adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700326 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
327 e1000_vlan_rx_add_vid(netdev, vid);
328 adapter->mng_vlan_id = vid;
329 } else
330 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800331
332 if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
333 (vid != old_vid) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700334 !adapter->vlgrp->vlan_devices[old_vid])
335 e1000_vlan_rx_kill_vid(netdev, old_vid);
Jeff Kirsherc5f226f2006-03-02 18:17:55 -0800336 } else
337 adapter->mng_vlan_id = vid;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700338 }
339}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800340
341/**
342 * e1000_release_hw_control - release control of the h/w to f/w
343 * @adapter: address of board private structure
344 *
345 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
346 * For ASF and Pass Through versions of f/w this means that the
347 * driver is no longer loaded. For AMT version (only with 82573) i
348 * of the f/w this means that the netowrk i/f is closed.
349 *
350 **/
351
352static inline void
353e1000_release_hw_control(struct e1000_adapter *adapter)
354{
355 uint32_t ctrl_ext;
356 uint32_t swsm;
357
358 /* Let firmware taken over control of h/w */
359 switch (adapter->hw.mac_type) {
360 case e1000_82571:
361 case e1000_82572:
362 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
363 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
364 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
365 break;
366 case e1000_82573:
367 swsm = E1000_READ_REG(&adapter->hw, SWSM);
368 E1000_WRITE_REG(&adapter->hw, SWSM,
369 swsm & ~E1000_SWSM_DRV_LOAD);
370 default:
371 break;
372 }
373}
374
375/**
376 * e1000_get_hw_control - get control of the h/w from f/w
377 * @adapter: address of board private structure
378 *
379 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
380 * For ASF and Pass Through versions of f/w this means that
381 * the driver is loaded. For AMT version (only with 82573)
382 * of the f/w this means that the netowrk i/f is open.
383 *
384 **/
385
386static inline void
387e1000_get_hw_control(struct e1000_adapter *adapter)
388{
389 uint32_t ctrl_ext;
390 uint32_t swsm;
391 /* Let firmware know the driver has taken over */
392 switch (adapter->hw.mac_type) {
393 case e1000_82571:
394 case e1000_82572:
395 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
396 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
397 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
398 break;
399 case e1000_82573:
400 swsm = E1000_READ_REG(&adapter->hw, SWSM);
401 E1000_WRITE_REG(&adapter->hw, SWSM,
402 swsm | E1000_SWSM_DRV_LOAD);
403 break;
404 default:
405 break;
406 }
407}
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409int
410e1000_up(struct e1000_adapter *adapter)
411{
412 struct net_device *netdev = adapter->netdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400413 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 /* hardware has been reset, we need to reload some things */
416
417 /* Reset the PHY if it was previously powered down */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800418 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 uint16_t mii_reg;
420 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800421 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 e1000_phy_reset(&adapter->hw);
423 }
424
425 e1000_set_multi(netdev);
426
427 e1000_restore_vlan(adapter);
428
429 e1000_configure_tx(adapter);
430 e1000_setup_rctl(adapter);
431 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800432 /* call E1000_DESC_UNUSED which always leaves
433 * at least 1 descriptor unused to make sure
434 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800435 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800436 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800437 adapter->alloc_rx_buf(adapter, ring,
438 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700441#ifdef CONFIG_PCI_MSI
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800442 if (adapter->hw.mac_type > e1000_82547_rev_2) {
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700443 adapter->have_msi = TRUE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800444 if ((err = pci_enable_msi(adapter->pdev))) {
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700445 DPRINTK(PROBE, ERR,
446 "Unable to allocate MSI interrupt Error: %d\n", err);
447 adapter->have_msi = FALSE;
448 }
449 }
450#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800451 if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 SA_SHIRQ | SA_SAMPLE_RANDOM,
Malli Chilakala26483452005-04-28 19:44:46 -0700453 netdev->name, netdev))) {
454 DPRINTK(PROBE, ERR,
455 "Unable to allocate interrupt Error: %d\n", err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 return err;
Malli Chilakala26483452005-04-28 19:44:46 -0700457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800459 adapter->tx_queue_len = netdev->tx_queue_len;
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 mod_timer(&adapter->watchdog_timer, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463#ifdef CONFIG_E1000_NAPI
464 netif_poll_enable(netdev);
465#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700466 e1000_irq_enable(adapter);
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 return 0;
469}
470
471void
472e1000_down(struct e1000_adapter *adapter)
473{
474 struct net_device *netdev = adapter->netdev;
Jeff Kirsher57128192006-01-12 16:50:28 -0800475 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
476 e1000_check_mng_mode(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 e1000_irq_disable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -0800479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 free_irq(adapter->pdev->irq, netdev);
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700481#ifdef CONFIG_PCI_MSI
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800482 if (adapter->hw.mac_type > e1000_82547_rev_2 &&
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700483 adapter->have_msi == TRUE)
484 pci_disable_msi(adapter->pdev);
485#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 del_timer_sync(&adapter->tx_fifo_stall_timer);
487 del_timer_sync(&adapter->watchdog_timer);
488 del_timer_sync(&adapter->phy_info_timer);
489
490#ifdef CONFIG_E1000_NAPI
491 netif_poll_disable(netdev);
492#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800493 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 adapter->link_speed = 0;
495 adapter->link_duplex = 0;
496 netif_carrier_off(netdev);
497 netif_stop_queue(netdev);
498
499 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400500 e1000_clean_all_tx_rings(adapter);
501 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Jeff Kirsher57128192006-01-12 16:50:28 -0800503 /* Power down the PHY so no link is implied when interface is down *
504 * The PHY cannot be powered down if any of the following is TRUE *
505 * (a) WoL is enabled
506 * (b) AMT is active
507 * (c) SoL/IDER session is active */
508 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700509 adapter->hw.media_type == e1000_media_type_copper &&
Jeff Kirsher57128192006-01-12 16:50:28 -0800510 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
511 !mng_mode_enabled &&
512 !e1000_check_phy_reset_block(&adapter->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 uint16_t mii_reg;
514 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
515 mii_reg |= MII_CR_POWER_DOWN;
516 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
Malli Chilakala4e48a2b2005-04-28 19:39:53 -0700517 mdelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
519}
520
521void
522e1000_reset(struct e1000_adapter *adapter)
523{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700524 uint32_t pba, manc;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700525 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 /* Repartition Pba for greater than 9k mtu
528 * To take effect CTRL.RST is required.
529 */
530
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700531 switch (adapter->hw.mac_type) {
532 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700533 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700534 pba = E1000_PBA_30K;
535 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400536 case e1000_82571:
537 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800538 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400539 pba = E1000_PBA_38K;
540 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700541 case e1000_82573:
542 pba = E1000_PBA_12K;
543 break;
544 default:
545 pba = E1000_PBA_48K;
546 break;
547 }
548
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800549 if ((adapter->hw.mac_type != e1000_82573) &&
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800550 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700551 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700552
553
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800554 if (adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 adapter->tx_fifo_head = 0;
556 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
557 adapter->tx_fifo_size =
558 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
559 atomic_set(&adapter->tx_fifo_stall, 0);
560 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 E1000_WRITE_REG(&adapter->hw, PBA, pba);
563
564 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800565 /* Set the FC high water mark to 90% of the FIFO size.
566 * Required to clear last 3 LSB */
567 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
568
569 adapter->hw.fc_high_water = fc_high_water_mark;
570 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Jeff Kirsher87041632006-03-02 18:21:24 -0800571 if (adapter->hw.mac_type == e1000_80003es2lan)
572 adapter->hw.fc_pause_time = 0xFFFF;
573 else
574 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 adapter->hw.fc_send_xon = 1;
576 adapter->hw.fc = adapter->hw.original_fc;
577
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700578 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 e1000_reset_hw(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800580 if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 E1000_WRITE_REG(&adapter->hw, WUC, 0);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800582 if (e1000_init_hw(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700584 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
586 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
587
588 e1000_reset_adaptive(&adapter->hw);
589 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700590 if (adapter->en_mng_pt) {
591 manc = E1000_READ_REG(&adapter->hw, MANC);
592 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
593 E1000_WRITE_REG(&adapter->hw, MANC, manc);
594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
597/**
598 * e1000_probe - Device Initialization Routine
599 * @pdev: PCI device information struct
600 * @ent: entry in e1000_pci_tbl
601 *
602 * Returns 0 on success, negative on failure
603 *
604 * e1000_probe initializes an adapter identified by a pci_dev structure.
605 * The OS initialization, configuring of the adapter private structure,
606 * and a hardware reset occur.
607 **/
608
609static int __devinit
610e1000_probe(struct pci_dev *pdev,
611 const struct pci_device_id *ent)
612{
613 struct net_device *netdev;
614 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700615 unsigned long mmio_start, mmio_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 static int cards_found = 0;
Jeff Kirsher84916822006-03-02 18:18:48 -0800618 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700619 int i, err, pci_using_dac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 uint16_t eeprom_data;
621 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800622 if ((err = pci_enable_device(pdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 return err;
624
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800625 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 pci_using_dac = 1;
627 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800628 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 E1000_ERR("No usable DMA configuration, aborting\n");
630 return err;
631 }
632 pci_using_dac = 0;
633 }
634
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800635 if ((err = pci_request_regions(pdev, e1000_driver_name)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 return err;
637
638 pci_set_master(pdev);
639
640 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800641 if (!netdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 err = -ENOMEM;
643 goto err_alloc_etherdev;
644 }
645
646 SET_MODULE_OWNER(netdev);
647 SET_NETDEV_DEV(netdev, &pdev->dev);
648
649 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700650 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 adapter->netdev = netdev;
652 adapter->pdev = pdev;
653 adapter->hw.back = adapter;
654 adapter->msg_enable = (1 << debug) - 1;
655
656 mmio_start = pci_resource_start(pdev, BAR_0);
657 mmio_len = pci_resource_len(pdev, BAR_0);
658
659 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800660 if (!adapter->hw.hw_addr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 err = -EIO;
662 goto err_ioremap;
663 }
664
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800665 for (i = BAR_1; i <= BAR_5; i++) {
666 if (pci_resource_len(pdev, i) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 continue;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800668 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 adapter->hw.io_base = pci_resource_start(pdev, i);
670 break;
671 }
672 }
673
674 netdev->open = &e1000_open;
675 netdev->stop = &e1000_close;
676 netdev->hard_start_xmit = &e1000_xmit_frame;
677 netdev->get_stats = &e1000_get_stats;
678 netdev->set_multicast_list = &e1000_set_multi;
679 netdev->set_mac_address = &e1000_set_mac;
680 netdev->change_mtu = &e1000_change_mtu;
681 netdev->do_ioctl = &e1000_ioctl;
682 e1000_set_ethtool_ops(netdev);
683 netdev->tx_timeout = &e1000_tx_timeout;
684 netdev->watchdog_timeo = 5 * HZ;
685#ifdef CONFIG_E1000_NAPI
686 netdev->poll = &e1000_clean;
687 netdev->weight = 64;
688#endif
689 netdev->vlan_rx_register = e1000_vlan_rx_register;
690 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
691 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
692#ifdef CONFIG_NET_POLL_CONTROLLER
693 netdev->poll_controller = e1000_netpoll;
694#endif
695 strcpy(netdev->name, pci_name(pdev));
696
697 netdev->mem_start = mmio_start;
698 netdev->mem_end = mmio_start + mmio_len;
699 netdev->base_addr = adapter->hw.io_base;
700
701 adapter->bd_number = cards_found;
702
703 /* setup the private structure */
704
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800705 if ((err = e1000_sw_init(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 goto err_sw_init;
707
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800708 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700709 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
710
Jeff Kirsher84916822006-03-02 18:18:48 -0800711 /* if ksp3, indicate if it's port a being setup */
712 if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
713 e1000_ksp3_port_a == 0)
714 adapter->ksp3_port_a = 1;
715 e1000_ksp3_port_a++;
716 /* Reset for multiple KP3 adapters */
717 if (e1000_ksp3_port_a == 4)
718 e1000_ksp3_port_a = 0;
719
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800720 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 netdev->features = NETIF_F_SG |
722 NETIF_F_HW_CSUM |
723 NETIF_F_HW_VLAN_TX |
724 NETIF_F_HW_VLAN_RX |
725 NETIF_F_HW_VLAN_FILTER;
726 }
727
728#ifdef NETIF_F_TSO
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800729 if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 (adapter->hw.mac_type != e1000_82547))
731 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700732
733#ifdef NETIF_F_TSO_IPV6
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800734 if (adapter->hw.mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700735 netdev->features |= NETIF_F_TSO_IPV6;
736#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#endif
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800738 if (pci_using_dac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 netdev->features |= NETIF_F_HIGHDMA;
740
741 /* hard_start_xmit is safe against parallel locking */
742 netdev->features |= NETIF_F_LLTX;
743
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700744 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
745
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800746 /* before reading the EEPROM, reset the controller to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 * put the device in a known good starting state */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 e1000_reset_hw(&adapter->hw);
750
751 /* make sure the EEPROM is good */
752
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800753 if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
755 err = -EIO;
756 goto err_eeprom;
757 }
758
759 /* copy the MAC address out of the EEPROM */
760
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800761 if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
763 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400764 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800766 if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
768 err = -EIO;
769 goto err_eeprom;
770 }
771
772 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
773
774 e1000_get_bus_info(&adapter->hw);
775
776 init_timer(&adapter->tx_fifo_stall_timer);
777 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
778 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
779
780 init_timer(&adapter->watchdog_timer);
781 adapter->watchdog_timer.function = &e1000_watchdog;
782 adapter->watchdog_timer.data = (unsigned long) adapter;
783
784 INIT_WORK(&adapter->watchdog_task,
785 (void (*)(void *))e1000_watchdog_task, adapter);
786
787 init_timer(&adapter->phy_info_timer);
788 adapter->phy_info_timer.function = &e1000_update_phy_info;
789 adapter->phy_info_timer.data = (unsigned long) adapter;
790
Jeff Kirsher87041632006-03-02 18:21:24 -0800791 INIT_WORK(&adapter->reset_task,
792 (void (*)(void *))e1000_reset_task, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 /* we're going to reset, so assume we have no link for now */
795
796 netif_carrier_off(netdev);
797 netif_stop_queue(netdev);
798
799 e1000_check_options(adapter);
800
801 /* Initial Wake on LAN setting
802 * If APM wake is enabled in the EEPROM,
803 * enable the ACPI Magic Packet filter
804 */
805
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800806 switch (adapter->hw.mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 case e1000_82542_rev2_0:
808 case e1000_82542_rev2_1:
809 case e1000_82543:
810 break;
811 case e1000_82544:
812 e1000_read_eeprom(&adapter->hw,
813 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
814 eeprom_apme_mask = E1000_EEPROM_82544_APM;
815 break;
816 case e1000_82546:
817 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500818 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800819 case e1000_80003es2lan:
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800820 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 e1000_read_eeprom(&adapter->hw,
822 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
823 break;
824 }
825 /* Fall Through */
826 default:
827 e1000_read_eeprom(&adapter->hw,
828 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
829 break;
830 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800831 if (eeprom_data & eeprom_apme_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 adapter->wol |= E1000_WUFC_MAG;
833
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -0800834 /* print bus type/speed/width info */
835 {
836 struct e1000_hw *hw = &adapter->hw;
837 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
838 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
839 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
840 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
841 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
842 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
843 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
844 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
845 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
846 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
847 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
848 "32-bit"));
849 }
850
851 for (i = 0; i < 6; i++)
852 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 /* reset the hardware with the new settings */
855 e1000_reset(adapter);
856
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800857 /* If the controller is 82573 and f/w is AMT, do not set
858 * DRV_LOAD until the interface is up. For all other cases,
859 * let the f/w know that the h/w is now under the control
860 * of the driver. */
861 if (adapter->hw.mac_type != e1000_82573 ||
862 !e1000_check_mng_mode(&adapter->hw))
863 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 strcpy(netdev->name, "eth%d");
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800866 if ((err = register_netdev(netdev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 goto err_register;
868
869 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
870
871 cards_found++;
872 return 0;
873
874err_register:
875err_sw_init:
876err_eeprom:
877 iounmap(adapter->hw.hw_addr);
878err_ioremap:
879 free_netdev(netdev);
880err_alloc_etherdev:
881 pci_release_regions(pdev);
882 return err;
883}
884
885/**
886 * e1000_remove - Device Removal Routine
887 * @pdev: PCI device information struct
888 *
889 * e1000_remove is called by the PCI subsystem to alert the driver
890 * that it should release a PCI device. The could be caused by a
891 * Hot-Plug event, or because the driver is going to be removed from
892 * memory.
893 **/
894
895static void __devexit
896e1000_remove(struct pci_dev *pdev)
897{
898 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700899 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800900 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400901#ifdef CONFIG_E1000_NAPI
902 int i;
903#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Jeff Garzikbe2b28e2005-10-04 07:13:43 -0400905 flush_scheduled_work();
906
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800907 if (adapter->hw.mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 adapter->hw.media_type == e1000_media_type_copper) {
909 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800910 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 manc |= E1000_MANC_ARP_EN;
912 E1000_WRITE_REG(&adapter->hw, MANC, manc);
913 }
914 }
915
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800916 /* Release control of h/w to f/w. If f/w is AMT enabled, this
917 * would have already happened in close and is redundant. */
918 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400921#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800922 for (i = 0; i < adapter->num_rx_queues; i++)
Stephen Hemminger15333062006-03-20 22:32:28 -0800923 dev_put(&adapter->polling_netdev[i]);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400924#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800926 if (!e1000_check_phy_reset_block(&adapter->hw))
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700927 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400929 kfree(adapter->tx_ring);
930 kfree(adapter->rx_ring);
931#ifdef CONFIG_E1000_NAPI
932 kfree(adapter->polling_netdev);
933#endif
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 iounmap(adapter->hw.hw_addr);
936 pci_release_regions(pdev);
937
938 free_netdev(netdev);
939
940 pci_disable_device(pdev);
941}
942
943/**
944 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
945 * @adapter: board private structure to initialize
946 *
947 * e1000_sw_init initializes the Adapter private data structure.
948 * Fields are initialized based on PCI device information and
949 * OS network device settings (MTU size).
950 **/
951
952static int __devinit
953e1000_sw_init(struct e1000_adapter *adapter)
954{
955 struct e1000_hw *hw = &adapter->hw;
956 struct net_device *netdev = adapter->netdev;
957 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400958#ifdef CONFIG_E1000_NAPI
959 int i;
960#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 /* PCI config space info */
963
964 hw->vendor_id = pdev->vendor;
965 hw->device_id = pdev->device;
966 hw->subsystem_vendor_id = pdev->subsystem_vendor;
967 hw->subsystem_id = pdev->subsystem_device;
968
969 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
970
971 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
972
973 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700974 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 hw->max_frame_size = netdev->mtu +
976 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
977 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
978
979 /* identify the MAC */
980
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800981 if (e1000_set_mac_type(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
983 return -EIO;
984 }
985
986 /* initialize eeprom parameters */
987
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800988 if (e1000_init_eeprom_params(hw)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700989 E1000_ERR("EEPROM initialization failed\n");
990 return -EIO;
991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800993 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 default:
995 break;
996 case e1000_82541:
997 case e1000_82547:
998 case e1000_82541_rev_2:
999 case e1000_82547_rev_2:
1000 hw->phy_init_script = 1;
1001 break;
1002 }
1003
1004 e1000_set_media_type(hw);
1005
1006 hw->wait_autoneg_complete = FALSE;
1007 hw->tbi_compatibility_en = TRUE;
1008 hw->adaptive_ifs = TRUE;
1009
1010 /* Copper options */
1011
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001012 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 hw->mdix = AUTO_ALL_MODES;
1014 hw->disable_polarity_correction = FALSE;
1015 hw->master_slave = E1000_MASTER_SLAVE;
1016 }
1017
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001018 adapter->num_tx_queues = 1;
1019 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001020
1021 if (e1000_alloc_queues(adapter)) {
1022 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1023 return -ENOMEM;
1024 }
1025
1026#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001027 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001028 adapter->polling_netdev[i].priv = adapter;
1029 adapter->polling_netdev[i].poll = &e1000_clean;
1030 adapter->polling_netdev[i].weight = 64;
1031 dev_hold(&adapter->polling_netdev[i]);
1032 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1033 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001034 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001035#endif
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 atomic_set(&adapter->irq_sem, 1);
1038 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040 return 0;
1041}
1042
1043/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001044 * e1000_alloc_queues - Allocate memory for all rings
1045 * @adapter: board private structure to initialize
1046 *
1047 * We allocate one ring per queue at run-time since we don't know the
1048 * number of queues at compile-time. The polling_netdev array is
1049 * intended for Multiqueue, but should work fine with a single queue.
1050 **/
1051
1052static int __devinit
1053e1000_alloc_queues(struct e1000_adapter *adapter)
1054{
1055 int size;
1056
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001057 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001058 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1059 if (!adapter->tx_ring)
1060 return -ENOMEM;
1061 memset(adapter->tx_ring, 0, size);
1062
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001063 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001064 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1065 if (!adapter->rx_ring) {
1066 kfree(adapter->tx_ring);
1067 return -ENOMEM;
1068 }
1069 memset(adapter->rx_ring, 0, size);
1070
1071#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001072 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001073 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1074 if (!adapter->polling_netdev) {
1075 kfree(adapter->tx_ring);
1076 kfree(adapter->rx_ring);
1077 return -ENOMEM;
1078 }
1079 memset(adapter->polling_netdev, 0, size);
1080#endif
1081
1082 return E1000_SUCCESS;
1083}
1084
1085/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 * e1000_open - Called when a network interface is made active
1087 * @netdev: network interface device structure
1088 *
1089 * Returns 0 on success, negative value on failure
1090 *
1091 * The open entry point is called when a network interface is made
1092 * active by the system (IFF_UP). At this point all resources needed
1093 * for transmit and receive operations are allocated, the interrupt
1094 * handler is registered with the OS, the watchdog timer is started,
1095 * and the stack is notified that the interface is ready.
1096 **/
1097
1098static int
1099e1000_open(struct net_device *netdev)
1100{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001101 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 int err;
1103
1104 /* allocate transmit descriptors */
1105
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001106 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 goto err_setup_tx;
1108
1109 /* allocate receive descriptors */
1110
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001111 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 goto err_setup_rx;
1113
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001114 if ((err = e1000_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001116 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001117 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001118 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1119 e1000_update_mng_vlan(adapter);
1120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001122 /* If AMT is enabled, let the firmware know that the network
1123 * interface is now open */
1124 if (adapter->hw.mac_type == e1000_82573 &&
1125 e1000_check_mng_mode(&adapter->hw))
1126 e1000_get_hw_control(adapter);
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 return E1000_SUCCESS;
1129
1130err_up:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001131 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001133 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134err_setup_tx:
1135 e1000_reset(adapter);
1136
1137 return err;
1138}
1139
1140/**
1141 * e1000_close - Disables a network interface
1142 * @netdev: network interface device structure
1143 *
1144 * Returns 0, this is not allowed to fail
1145 *
1146 * The close entry point is called when an interface is de-activated
1147 * by the OS. The hardware is still under the drivers control, but
1148 * needs to be disabled. A global MAC reset is issued to stop the
1149 * hardware, and all transmit and receive resources are freed.
1150 **/
1151
1152static int
1153e1000_close(struct net_device *netdev)
1154{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001155 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 e1000_down(adapter);
1158
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001159 e1000_free_all_tx_resources(adapter);
1160 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001162 if ((adapter->hw.mng_cookie.status &
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001163 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1164 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1165 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001166
1167 /* If AMT is enabled, let the firmware know that the network
1168 * interface is now closed */
1169 if (adapter->hw.mac_type == e1000_82573 &&
1170 e1000_check_mng_mode(&adapter->hw))
1171 e1000_release_hw_control(adapter);
1172
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 return 0;
1174}
1175
1176/**
1177 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1178 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001179 * @start: address of beginning of memory
1180 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 **/
1182static inline boolean_t
1183e1000_check_64k_bound(struct e1000_adapter *adapter,
1184 void *start, unsigned long len)
1185{
1186 unsigned long begin = (unsigned long) start;
1187 unsigned long end = begin + len;
1188
Malli Chilakala26483452005-04-28 19:44:46 -07001189 /* First rev 82545 and 82546 need to not allow any memory
1190 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001192 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1194 }
1195
1196 return TRUE;
1197}
1198
1199/**
1200 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1201 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001202 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 *
1204 * Return 0 on success, negative on failure
1205 **/
1206
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001207static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001208e1000_setup_tx_resources(struct e1000_adapter *adapter,
1209 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 struct pci_dev *pdev = adapter->pdev;
1212 int size;
1213
1214 size = sizeof(struct e1000_buffer) * txdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001215
1216 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001217 if (!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001218 DPRINTK(PROBE, ERR,
1219 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 return -ENOMEM;
1221 }
1222 memset(txdr->buffer_info, 0, size);
1223
1224 /* round up to nearest 4K */
1225
1226 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1227 E1000_ROUNDUP(txdr->size, 4096);
1228
1229 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001230 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001233 DPRINTK(PROBE, ERR,
1234 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 return -ENOMEM;
1236 }
1237
Malli Chilakala26483452005-04-28 19:44:46 -07001238 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1240 void *olddesc = txdr->desc;
1241 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001242 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1243 "at %p\n", txdr->size, txdr->desc);
1244 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001246 /* Failed allocation, critical failure */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001247 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1249 goto setup_tx_desc_die;
1250 }
1251
1252 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1253 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001254 pci_free_consistent(pdev, txdr->size, txdr->desc,
1255 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1257 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001258 "Unable to allocate aligned memory "
1259 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 vfree(txdr->buffer_info);
1261 return -ENOMEM;
1262 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001263 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1265 }
1266 }
1267 memset(txdr->desc, 0, txdr->size);
1268
1269 txdr->next_to_use = 0;
1270 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001271 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 return 0;
1274}
1275
1276/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001277 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1278 * (Descriptors) for all queues
1279 * @adapter: board private structure
1280 *
1281 * If this function returns with an error, then it's possible one or
1282 * more of the rings is populated (while the rest are not). It is the
1283 * callers duty to clean those orphaned rings.
1284 *
1285 * Return 0 on success, negative on failure
1286 **/
1287
1288int
1289e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1290{
1291 int i, err = 0;
1292
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001293 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001294 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1295 if (err) {
1296 DPRINTK(PROBE, ERR,
1297 "Allocation for Tx Queue %u failed\n", i);
1298 break;
1299 }
1300 }
1301
1302 return err;
1303}
1304
1305/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1307 * @adapter: board private structure
1308 *
1309 * Configure the Tx unit of the MAC after a reset.
1310 **/
1311
1312static void
1313e1000_configure_tx(struct e1000_adapter *adapter)
1314{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001315 uint64_t tdba;
1316 struct e1000_hw *hw = &adapter->hw;
1317 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001318 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320 /* Setup the HW Tx Head and Tail descriptor pointers */
1321
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001322 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001323 case 1:
1324 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001325 tdba = adapter->tx_ring[0].dma;
1326 tdlen = adapter->tx_ring[0].count *
1327 sizeof(struct e1000_tx_desc);
1328 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1329 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1330 E1000_WRITE_REG(hw, TDLEN, tdlen);
1331 E1000_WRITE_REG(hw, TDH, 0);
1332 E1000_WRITE_REG(hw, TDT, 0);
1333 adapter->tx_ring[0].tdh = E1000_TDH;
1334 adapter->tx_ring[0].tdt = E1000_TDT;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001335 break;
1336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
1338 /* Set the default values for the Tx Inter Packet Gap timer */
1339
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001340 if (hw->media_type == e1000_media_type_fiber ||
1341 hw->media_type == e1000_media_type_internal_serdes)
1342 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1343 else
1344 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1345
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001346 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 case e1000_82542_rev2_0:
1348 case e1000_82542_rev2_1:
1349 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001350 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1351 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 break;
Jeff Kirsher87041632006-03-02 18:21:24 -08001353 case e1000_80003es2lan:
1354 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1355 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
1356 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001358 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1359 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1360 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001362 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1363 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001364 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
1366 /* Set the Tx Interrupt Delay register */
1367
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001368 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1369 if (hw->mac_type >= e1000_82540)
1370 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
1372 /* Program the Transmit Control Register */
1373
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001374 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 tctl &= ~E1000_TCTL_CT;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001377 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1379
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001380#ifdef DISABLE_MULR
1381 /* disable Multiple Reads for debugging */
1382 tctl &= ~E1000_TCTL_MULR;
1383#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001385 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1386 tarc = E1000_READ_REG(hw, TARC0);
1387 tarc |= ((1 << 25) | (1 << 21));
1388 E1000_WRITE_REG(hw, TARC0, tarc);
1389 tarc = E1000_READ_REG(hw, TARC1);
1390 tarc |= (1 << 25);
1391 if (tctl & E1000_TCTL_MULR)
1392 tarc &= ~(1 << 28);
1393 else
1394 tarc |= (1 << 28);
1395 E1000_WRITE_REG(hw, TARC1, tarc);
Jeff Kirsher87041632006-03-02 18:21:24 -08001396 } else if (hw->mac_type == e1000_80003es2lan) {
1397 tarc = E1000_READ_REG(hw, TARC0);
1398 tarc |= 1;
1399 if (hw->media_type == e1000_media_type_internal_serdes)
1400 tarc |= (1 << 20);
1401 E1000_WRITE_REG(hw, TARC0, tarc);
1402 tarc = E1000_READ_REG(hw, TARC1);
1403 tarc |= 1;
1404 E1000_WRITE_REG(hw, TARC1, tarc);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001405 }
1406
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001407 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
1409 /* Setup Transmit Descriptor Settings for eop descriptor */
1410 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1411 E1000_TXD_CMD_IFCS;
1412
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001413 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1415 else
1416 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1417
1418 /* Cache if we're 82544 running in PCI-X because we'll
1419 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001420 if (hw->mac_type == e1000_82544 &&
1421 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 adapter->pcix_82544 = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08001423
1424 E1000_WRITE_REG(hw, TCTL, tctl);
1425
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426}
1427
1428/**
1429 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1430 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001431 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 *
1433 * Returns 0 on success, negative on failure
1434 **/
1435
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001436static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001437e1000_setup_rx_resources(struct e1000_adapter *adapter,
1438 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001441 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
1443 size = sizeof(struct e1000_buffer) * rxdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001444 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001445 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001446 DPRINTK(PROBE, ERR,
1447 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 return -ENOMEM;
1449 }
1450 memset(rxdr->buffer_info, 0, size);
1451
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001452 size = sizeof(struct e1000_ps_page) * rxdr->count;
1453 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001454 if (!rxdr->ps_page) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001455 vfree(rxdr->buffer_info);
1456 DPRINTK(PROBE, ERR,
1457 "Unable to allocate memory for the receive descriptor ring\n");
1458 return -ENOMEM;
1459 }
1460 memset(rxdr->ps_page, 0, size);
1461
1462 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1463 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001464 if (!rxdr->ps_page_dma) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001465 vfree(rxdr->buffer_info);
1466 kfree(rxdr->ps_page);
1467 DPRINTK(PROBE, ERR,
1468 "Unable to allocate memory for the receive descriptor ring\n");
1469 return -ENOMEM;
1470 }
1471 memset(rxdr->ps_page_dma, 0, size);
1472
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001473 if (adapter->hw.mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001474 desc_len = sizeof(struct e1000_rx_desc);
1475 else
1476 desc_len = sizeof(union e1000_rx_desc_packet_split);
1477
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 /* Round up to nearest 4K */
1479
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001480 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 E1000_ROUNDUP(rxdr->size, 4096);
1482
1483 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1484
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001485 if (!rxdr->desc) {
1486 DPRINTK(PROBE, ERR,
1487 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001490 kfree(rxdr->ps_page);
1491 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 return -ENOMEM;
1493 }
1494
Malli Chilakala26483452005-04-28 19:44:46 -07001495 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1497 void *olddesc = rxdr->desc;
1498 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001499 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1500 "at %p\n", rxdr->size, rxdr->desc);
1501 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001503 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001504 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001506 DPRINTK(PROBE, ERR,
1507 "Unable to allocate memory "
1508 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 goto setup_rx_desc_die;
1510 }
1511
1512 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1513 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001514 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1515 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001517 DPRINTK(PROBE, ERR,
1518 "Unable to allocate aligned memory "
1519 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001520 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001522 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1524 }
1525 }
1526 memset(rxdr->desc, 0, rxdr->size);
1527
1528 rxdr->next_to_clean = 0;
1529 rxdr->next_to_use = 0;
1530
1531 return 0;
1532}
1533
1534/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001535 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1536 * (Descriptors) for all queues
1537 * @adapter: board private structure
1538 *
1539 * If this function returns with an error, then it's possible one or
1540 * more of the rings is populated (while the rest are not). It is the
1541 * callers duty to clean those orphaned rings.
1542 *
1543 * Return 0 on success, negative on failure
1544 **/
1545
1546int
1547e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1548{
1549 int i, err = 0;
1550
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001551 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001552 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1553 if (err) {
1554 DPRINTK(PROBE, ERR,
1555 "Allocation for Rx Queue %u failed\n", i);
1556 break;
1557 }
1558 }
1559
1560 return err;
1561}
1562
1563/**
Malli Chilakala26483452005-04-28 19:44:46 -07001564 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 * @adapter: Board private structure
1566 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001567#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1568 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569static void
1570e1000_setup_rctl(struct e1000_adapter *adapter)
1571{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001572 uint32_t rctl, rfctl;
1573 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001574#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001575 uint32_t pages = 0;
1576#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
1578 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1579
1580 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1581
1582 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1583 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1584 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1585
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001586 if (adapter->hw.mac_type > e1000_82543)
1587 rctl |= E1000_RCTL_SECRC;
1588
1589 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 rctl |= E1000_RCTL_SBP;
1591 else
1592 rctl &= ~E1000_RCTL_SBP;
1593
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001594 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1595 rctl &= ~E1000_RCTL_LPE;
1596 else
1597 rctl |= E1000_RCTL_LPE;
1598
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 /* Setup buffer sizes */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001600 if (adapter->hw.mac_type >= e1000_82571) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001601 /* We can now specify buffers in 1K increments.
1602 * BSIZE and BSEX are ignored in this case. */
1603 rctl |= adapter->rx_buffer_len << 0x11;
1604 } else {
1605 rctl &= ~E1000_RCTL_SZ_4096;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08001606 rctl |= E1000_RCTL_BSEX;
1607 switch (adapter->rx_buffer_len) {
1608 case E1000_RXBUFFER_2048:
1609 default:
1610 rctl |= E1000_RCTL_SZ_2048;
1611 rctl &= ~E1000_RCTL_BSEX;
1612 break;
1613 case E1000_RXBUFFER_4096:
1614 rctl |= E1000_RCTL_SZ_4096;
1615 break;
1616 case E1000_RXBUFFER_8192:
1617 rctl |= E1000_RCTL_SZ_8192;
1618 break;
1619 case E1000_RXBUFFER_16384:
1620 rctl |= E1000_RCTL_SZ_16384;
1621 break;
1622 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001623 }
1624
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001625#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001626 /* 82571 and greater support packet-split where the protocol
1627 * header is placed in skb->data and the packet data is
1628 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1629 * In the case of a non-split, skb->data is linearly filled,
1630 * followed by the page buffers. Therefore, skb->data is
1631 * sized to hold the largest protocol header.
1632 */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001633 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1634 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1635 PAGE_SIZE <= 16384)
1636 adapter->rx_ps_pages = pages;
1637 else
1638 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001639#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001640 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001641 /* Configure extra packet-split registers */
1642 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1643 rfctl |= E1000_RFCTL_EXTEN;
1644 /* disable IPv6 packet split support */
1645 rfctl |= E1000_RFCTL_IPV6_DIS;
1646 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1647
1648 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001649
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001650 psrctl |= adapter->rx_ps_bsize0 >>
1651 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001652
1653 switch (adapter->rx_ps_pages) {
1654 case 3:
1655 psrctl |= PAGE_SIZE <<
1656 E1000_PSRCTL_BSIZE3_SHIFT;
1657 case 2:
1658 psrctl |= PAGE_SIZE <<
1659 E1000_PSRCTL_BSIZE2_SHIFT;
1660 case 1:
1661 psrctl |= PAGE_SIZE >>
1662 E1000_PSRCTL_BSIZE1_SHIFT;
1663 break;
1664 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001665
1666 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 }
1668
1669 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1670}
1671
1672/**
1673 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1674 * @adapter: board private structure
1675 *
1676 * Configure the Rx unit of the MAC after a reset.
1677 **/
1678
1679static void
1680e1000_configure_rx(struct e1000_adapter *adapter)
1681{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001682 uint64_t rdba;
1683 struct e1000_hw *hw = &adapter->hw;
1684 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001685
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001686 if (adapter->rx_ps_pages) {
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08001687 /* this is a 32 byte descriptor */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001688 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001689 sizeof(union e1000_rx_desc_packet_split);
1690 adapter->clean_rx = e1000_clean_rx_irq_ps;
1691 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1692 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001693 rdlen = adapter->rx_ring[0].count *
1694 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001695 adapter->clean_rx = e1000_clean_rx_irq;
1696 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
1699 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001700 rctl = E1000_READ_REG(hw, RCTL);
1701 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
1703 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001704 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001706 if (hw->mac_type >= e1000_82540) {
1707 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001708 if (adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001709 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 1000000000 / (adapter->itr * 256));
1711 }
1712
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001713 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001714 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001715 /* Reset delay timers after every interrupt */
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001716 ctrl_ext |= E1000_CTRL_EXT_CANC;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001717#ifdef CONFIG_E1000_NAPI
1718 /* Auto-Mask interrupts upon ICR read. */
1719 ctrl_ext |= E1000_CTRL_EXT_IAME;
1720#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001721 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001722 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001723 E1000_WRITE_FLUSH(hw);
1724 }
1725
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001726 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1727 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001728 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001729 case 1:
1730 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001731 rdba = adapter->rx_ring[0].dma;
1732 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1733 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1734 E1000_WRITE_REG(hw, RDLEN, rdlen);
1735 E1000_WRITE_REG(hw, RDH, 0);
1736 E1000_WRITE_REG(hw, RDT, 0);
1737 adapter->rx_ring[0].rdh = E1000_RDH;
1738 adapter->rx_ring[0].rdt = E1000_RDT;
1739 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001740 }
1741
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001743 if (hw->mac_type >= e1000_82543) {
1744 rxcsum = E1000_READ_REG(hw, RXCSUM);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001745 if (adapter->rx_csum == TRUE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001746 rxcsum |= E1000_RXCSUM_TUOFL;
1747
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001748 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001749 * Must be used in conjunction with packet-split. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001750 if ((hw->mac_type >= e1000_82571) &&
1751 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001752 rxcsum |= E1000_RXCSUM_IPPCSE;
1753 }
1754 } else {
1755 rxcsum &= ~E1000_RXCSUM_TUOFL;
1756 /* don't need to clear IPPCSE as it defaults to 0 */
1757 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001758 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 }
1760
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001761 if (hw->mac_type == e1000_82573)
1762 E1000_WRITE_REG(hw, ERT, 0x0100);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001765 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766}
1767
1768/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001769 * e1000_free_tx_resources - Free Tx Resources per Queue
1770 * @adapter: board private structure
1771 * @tx_ring: Tx descriptor ring for a specific queue
1772 *
1773 * Free all transmit software resources
1774 **/
1775
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001776static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001777e1000_free_tx_resources(struct e1000_adapter *adapter,
1778 struct e1000_tx_ring *tx_ring)
1779{
1780 struct pci_dev *pdev = adapter->pdev;
1781
1782 e1000_clean_tx_ring(adapter, tx_ring);
1783
1784 vfree(tx_ring->buffer_info);
1785 tx_ring->buffer_info = NULL;
1786
1787 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1788
1789 tx_ring->desc = NULL;
1790}
1791
1792/**
1793 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 * @adapter: board private structure
1795 *
1796 * Free all transmit software resources
1797 **/
1798
1799void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001800e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001802 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001804 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001805 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
1807
1808static inline void
1809e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1810 struct e1000_buffer *buffer_info)
1811{
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001812 if (buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001813 pci_unmap_page(adapter->pdev,
1814 buffer_info->dma,
1815 buffer_info->length,
1816 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08001818 if (buffer_info->skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 dev_kfree_skb_any(buffer_info->skb);
Jeff Kirsher8241e352006-01-12 16:51:34 -08001820 memset(buffer_info, 0, sizeof(struct e1000_buffer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821}
1822
1823/**
1824 * e1000_clean_tx_ring - Free Tx Buffers
1825 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001826 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 **/
1828
1829static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001830e1000_clean_tx_ring(struct e1000_adapter *adapter,
1831 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 struct e1000_buffer *buffer_info;
1834 unsigned long size;
1835 unsigned int i;
1836
1837 /* Free all the Tx ring sk_buffs */
1838
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001839 for (i = 0; i < tx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 buffer_info = &tx_ring->buffer_info[i];
1841 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1842 }
1843
1844 size = sizeof(struct e1000_buffer) * tx_ring->count;
1845 memset(tx_ring->buffer_info, 0, size);
1846
1847 /* Zero out the descriptor ring */
1848
1849 memset(tx_ring->desc, 0, tx_ring->size);
1850
1851 tx_ring->next_to_use = 0;
1852 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001853 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001855 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1856 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1857}
1858
1859/**
1860 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1861 * @adapter: board private structure
1862 **/
1863
1864static void
1865e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1866{
1867 int i;
1868
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001869 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001870 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871}
1872
1873/**
1874 * e1000_free_rx_resources - Free Rx Resources
1875 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001876 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 *
1878 * Free all receive software resources
1879 **/
1880
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001881static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001882e1000_free_rx_resources(struct e1000_adapter *adapter,
1883 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 struct pci_dev *pdev = adapter->pdev;
1886
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001887 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
1889 vfree(rx_ring->buffer_info);
1890 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001891 kfree(rx_ring->ps_page);
1892 rx_ring->ps_page = NULL;
1893 kfree(rx_ring->ps_page_dma);
1894 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
1896 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1897
1898 rx_ring->desc = NULL;
1899}
1900
1901/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001902 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001904 *
1905 * Free all receive software resources
1906 **/
1907
1908void
1909e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1910{
1911 int i;
1912
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001913 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001914 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1915}
1916
1917/**
1918 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1919 * @adapter: board private structure
1920 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 **/
1922
1923static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001924e1000_clean_rx_ring(struct e1000_adapter *adapter,
1925 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001928 struct e1000_ps_page *ps_page;
1929 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 struct pci_dev *pdev = adapter->pdev;
1931 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001932 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933
1934 /* Free all the Rx ring sk_buffs */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001935 for (i = 0; i < rx_ring->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 buffer_info = &rx_ring->buffer_info[i];
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001937 if (buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 pci_unmap_single(pdev,
1939 buffer_info->dma,
1940 buffer_info->length,
1941 PCI_DMA_FROMDEVICE);
1942
1943 dev_kfree_skb(buffer_info->skb);
1944 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08001945 }
1946 ps_page = &rx_ring->ps_page[i];
1947 ps_page_dma = &rx_ring->ps_page_dma[i];
1948 for (j = 0; j < adapter->rx_ps_pages; j++) {
1949 if (!ps_page->ps_page[j]) break;
1950 pci_unmap_page(pdev,
1951 ps_page_dma->ps_page_dma[j],
1952 PAGE_SIZE, PCI_DMA_FROMDEVICE);
1953 ps_page_dma->ps_page_dma[j] = 0;
1954 put_page(ps_page->ps_page[j]);
1955 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 }
1957 }
1958
1959 size = sizeof(struct e1000_buffer) * rx_ring->count;
1960 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001961 size = sizeof(struct e1000_ps_page) * rx_ring->count;
1962 memset(rx_ring->ps_page, 0, size);
1963 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
1964 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
1966 /* Zero out the descriptor ring */
1967
1968 memset(rx_ring->desc, 0, rx_ring->size);
1969
1970 rx_ring->next_to_clean = 0;
1971 rx_ring->next_to_use = 0;
1972
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001973 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1974 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1975}
1976
1977/**
1978 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1979 * @adapter: board private structure
1980 **/
1981
1982static void
1983e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1984{
1985 int i;
1986
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001987 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001988 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989}
1990
1991/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
1992 * and memory write and invalidate disabled for certain operations
1993 */
1994static void
1995e1000_enter_82542_rst(struct e1000_adapter *adapter)
1996{
1997 struct net_device *netdev = adapter->netdev;
1998 uint32_t rctl;
1999
2000 e1000_pci_clear_mwi(&adapter->hw);
2001
2002 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2003 rctl |= E1000_RCTL_RST;
2004 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2005 E1000_WRITE_FLUSH(&adapter->hw);
2006 mdelay(5);
2007
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002008 if (netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002009 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010}
2011
2012static void
2013e1000_leave_82542_rst(struct e1000_adapter *adapter)
2014{
2015 struct net_device *netdev = adapter->netdev;
2016 uint32_t rctl;
2017
2018 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2019 rctl &= ~E1000_RCTL_RST;
2020 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2021 E1000_WRITE_FLUSH(&adapter->hw);
2022 mdelay(5);
2023
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002024 if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 e1000_pci_set_mwi(&adapter->hw);
2026
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002027 if (netif_running(netdev)) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002028 /* No need to loop, because 82542 supports only 1 queue */
2029 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
Jesse Brandeburg7c4d3362006-01-18 13:01:45 -08002030 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002031 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 }
2033}
2034
2035/**
2036 * e1000_set_mac - Change the Ethernet Address of the NIC
2037 * @netdev: network interface device structure
2038 * @p: pointer to an address structure
2039 *
2040 * Returns 0 on success, negative on failure
2041 **/
2042
2043static int
2044e1000_set_mac(struct net_device *netdev, void *p)
2045{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002046 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 struct sockaddr *addr = p;
2048
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002049 if (!is_valid_ether_addr(addr->sa_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 return -EADDRNOTAVAIL;
2051
2052 /* 82542 2.0 needs to be in reset to write receive address registers */
2053
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002054 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 e1000_enter_82542_rst(adapter);
2056
2057 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2058 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2059
2060 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2061
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002062 /* With 82571 controllers, LAA may be overwritten (with the default)
2063 * due to controller reset from the other port. */
2064 if (adapter->hw.mac_type == e1000_82571) {
2065 /* activate the work around */
2066 adapter->hw.laa_is_present = 1;
2067
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002068 /* Hold a copy of the LAA in RAR[14] This is done so that
2069 * between the time RAR[0] gets clobbered and the time it
2070 * gets fixed (in e1000_watchdog), the actual LAA is in one
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002071 * of the RARs and no incoming packets directed to this port
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002072 * are dropped. Eventaully the LAA will be in RAR[0] and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002073 * RAR[14] */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002074 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002075 E1000_RAR_ENTRIES - 1);
2076 }
2077
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002078 if (adapter->hw.mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 e1000_leave_82542_rst(adapter);
2080
2081 return 0;
2082}
2083
2084/**
2085 * e1000_set_multi - Multicast and Promiscuous mode set
2086 * @netdev: network interface device structure
2087 *
2088 * The set_multi entry point is called whenever the multicast address
2089 * list or the network interface flags are updated. This routine is
2090 * responsible for configuring the hardware for proper multicast,
2091 * promiscuous mode, and all-multi behavior.
2092 **/
2093
2094static void
2095e1000_set_multi(struct net_device *netdev)
2096{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002097 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct e1000_hw *hw = &adapter->hw;
2099 struct dev_mc_list *mc_ptr;
2100 uint32_t rctl;
2101 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002102 int i, rar_entries = E1000_RAR_ENTRIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002104 /* reserve RAR[14] for LAA over-write work-around */
2105 if (adapter->hw.mac_type == e1000_82571)
2106 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
Malli Chilakala26483452005-04-28 19:44:46 -07002108 /* Check for Promiscuous and All Multicast modes */
2109
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 rctl = E1000_READ_REG(hw, RCTL);
2111
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002112 if (netdev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002114 } else if (netdev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 rctl |= E1000_RCTL_MPE;
2116 rctl &= ~E1000_RCTL_UPE;
2117 } else {
2118 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2119 }
2120
2121 E1000_WRITE_REG(hw, RCTL, rctl);
2122
2123 /* 82542 2.0 needs to be in reset to write receive address registers */
2124
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002125 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 e1000_enter_82542_rst(adapter);
2127
2128 /* load the first 14 multicast address into the exact filters 1-14
2129 * RAR 0 is used for the station MAC adddress
2130 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002131 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 */
2133 mc_ptr = netdev->mc_list;
2134
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002135 for (i = 1; i < rar_entries; i++) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002136 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2138 mc_ptr = mc_ptr->next;
2139 } else {
2140 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2141 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2142 }
2143 }
2144
2145 /* clear the old settings from the multicast hash table */
2146
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002147 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2149
2150 /* load any remaining addresses into the hash table */
2151
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002152 for (; mc_ptr; mc_ptr = mc_ptr->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2154 e1000_mta_set(hw, hash_value);
2155 }
2156
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002157 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159}
2160
2161/* Need to wait a few seconds after link up to get diagnostic information from
2162 * the phy */
2163
2164static void
2165e1000_update_phy_info(unsigned long data)
2166{
2167 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2168 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2169}
2170
2171/**
2172 * e1000_82547_tx_fifo_stall - Timer Call-back
2173 * @data: pointer to adapter cast into an unsigned long
2174 **/
2175
2176static void
2177e1000_82547_tx_fifo_stall(unsigned long data)
2178{
2179 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2180 struct net_device *netdev = adapter->netdev;
2181 uint32_t tctl;
2182
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002183 if (atomic_read(&adapter->tx_fifo_stall)) {
2184 if ((E1000_READ_REG(&adapter->hw, TDT) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 E1000_READ_REG(&adapter->hw, TDH)) &&
2186 (E1000_READ_REG(&adapter->hw, TDFT) ==
2187 E1000_READ_REG(&adapter->hw, TDFH)) &&
2188 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2189 E1000_READ_REG(&adapter->hw, TDFHS))) {
2190 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2191 E1000_WRITE_REG(&adapter->hw, TCTL,
2192 tctl & ~E1000_TCTL_EN);
2193 E1000_WRITE_REG(&adapter->hw, TDFT,
2194 adapter->tx_head_addr);
2195 E1000_WRITE_REG(&adapter->hw, TDFH,
2196 adapter->tx_head_addr);
2197 E1000_WRITE_REG(&adapter->hw, TDFTS,
2198 adapter->tx_head_addr);
2199 E1000_WRITE_REG(&adapter->hw, TDFHS,
2200 adapter->tx_head_addr);
2201 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2202 E1000_WRITE_FLUSH(&adapter->hw);
2203
2204 adapter->tx_fifo_head = 0;
2205 atomic_set(&adapter->tx_fifo_stall, 0);
2206 netif_wake_queue(netdev);
2207 } else {
2208 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2209 }
2210 }
2211}
2212
2213/**
2214 * e1000_watchdog - Timer Call-back
2215 * @data: pointer to adapter cast into an unsigned long
2216 **/
2217static void
2218e1000_watchdog(unsigned long data)
2219{
2220 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2221
2222 /* Do the rest outside of interrupt context */
2223 schedule_work(&adapter->watchdog_task);
2224}
2225
2226static void
2227e1000_watchdog_task(struct e1000_adapter *adapter)
2228{
2229 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002230 struct e1000_tx_ring *txdr = adapter->tx_ring;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002231 uint32_t link, tctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 e1000_check_for_link(&adapter->hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002234 if (adapter->hw.mac_type == e1000_82573) {
2235 e1000_enable_tx_pkt_filtering(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002236 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002237 e1000_update_mng_vlan(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002240 if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2242 link = !adapter->hw.serdes_link_down;
2243 else
2244 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2245
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002246 if (link) {
2247 if (!netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 e1000_get_speed_and_duplex(&adapter->hw,
2249 &adapter->link_speed,
2250 &adapter->link_duplex);
2251
2252 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2253 adapter->link_speed,
2254 adapter->link_duplex == FULL_DUPLEX ?
2255 "Full Duplex" : "Half Duplex");
2256
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002257 /* tweak tx_queue_len according to speed/duplex
2258 * and adjust the timeout factor */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002259 netdev->tx_queue_len = adapter->tx_queue_len;
2260 adapter->tx_timeout_factor = 1;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002261 adapter->txb2b = 1;
2262 switch (adapter->link_speed) {
2263 case SPEED_10:
2264 adapter->txb2b = 0;
2265 netdev->tx_queue_len = 10;
2266 adapter->tx_timeout_factor = 8;
2267 break;
2268 case SPEED_100:
2269 adapter->txb2b = 0;
2270 netdev->tx_queue_len = 100;
2271 /* maybe add some timeout factor ? */
2272 break;
2273 }
2274
2275 if ((adapter->hw.mac_type == e1000_82571 ||
2276 adapter->hw.mac_type == e1000_82572) &&
2277 adapter->txb2b == 0) {
2278#define SPEED_MODE_BIT (1 << 21)
2279 uint32_t tarc0;
2280 tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
2281 tarc0 &= ~SPEED_MODE_BIT;
2282 E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
2283 }
2284
2285#ifdef NETIF_F_TSO
2286 /* disable TSO for pcie and 10/100 speeds, to avoid
2287 * some hardware issues */
2288 if (!adapter->tso_force &&
2289 adapter->hw.bus_type == e1000_bus_type_pci_express){
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002290 switch (adapter->link_speed) {
2291 case SPEED_10:
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002292 case SPEED_100:
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002293 DPRINTK(PROBE,INFO,
2294 "10/100 speed: disabling TSO\n");
2295 netdev->features &= ~NETIF_F_TSO;
2296 break;
2297 case SPEED_1000:
2298 netdev->features |= NETIF_F_TSO;
2299 break;
2300 default:
2301 /* oops */
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002302 break;
2303 }
2304 }
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08002305#endif
2306
2307 /* enable transmits in the hardware, need to do this
2308 * after setting TARC0 */
2309 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2310 tctl |= E1000_TCTL_EN;
2311 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002312
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 netif_carrier_on(netdev);
2314 netif_wake_queue(netdev);
2315 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2316 adapter->smartspeed = 0;
2317 }
2318 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002319 if (netif_carrier_ok(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 adapter->link_speed = 0;
2321 adapter->link_duplex = 0;
2322 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2323 netif_carrier_off(netdev);
2324 netif_stop_queue(netdev);
2325 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
Jeff Kirsher87041632006-03-02 18:21:24 -08002326
2327 /* 80003ES2LAN workaround--
2328 * For packet buffer work-around on link down event;
2329 * disable receives in the ISR and
2330 * reset device here in the watchdog
2331 */
2332 if (adapter->hw.mac_type == e1000_80003es2lan) {
2333 /* reset device */
2334 schedule_work(&adapter->reset_task);
2335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 }
2337
2338 e1000_smartspeed(adapter);
2339 }
2340
2341 e1000_update_stats(adapter);
2342
2343 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2344 adapter->tpt_old = adapter->stats.tpt;
2345 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2346 adapter->colc_old = adapter->stats.colc;
2347
2348 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2349 adapter->gorcl_old = adapter->stats.gorcl;
2350 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2351 adapter->gotcl_old = adapter->stats.gotcl;
2352
2353 e1000_update_adaptive(&adapter->hw);
2354
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002355 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002356 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 /* We've lost link, so the controller stops DMA,
2358 * but we've got queued Tx work that's never going
2359 * to get done, so reset controller to flush Tx.
2360 * (Do the reset outside of interrupt context). */
Jeff Kirsher87041632006-03-02 18:21:24 -08002361 adapter->tx_timeout_count++;
2362 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 }
2364 }
2365
2366 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002367 if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2369 * asymmetrical Tx or Rx gets ITR=8000; everyone
2370 * else is between 2000-8000. */
2371 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002372 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 adapter->gotcl - adapter->gorcl :
2374 adapter->gorcl - adapter->gotcl) / 10000;
2375 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2376 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2377 }
2378
2379 /* Cause software interrupt to ensure rx ring is cleaned */
2380 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2381
Malli Chilakala26483452005-04-28 19:44:46 -07002382 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 adapter->detect_tx_hung = TRUE;
2384
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002385 /* With 82571 controllers, LAA may be overwritten due to controller
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002386 * reset from the other port. Set the appropriate LAA in RAR[0] */
2387 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2388 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2389
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 /* Reset the timer */
2391 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2392}
2393
2394#define E1000_TX_FLAGS_CSUM 0x00000001
2395#define E1000_TX_FLAGS_VLAN 0x00000002
2396#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002397#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2399#define E1000_TX_FLAGS_VLAN_SHIFT 16
2400
2401static inline int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002402e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2403 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404{
2405#ifdef NETIF_F_TSO
2406 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002407 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 unsigned int i;
2409 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002410 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2412 int err;
2413
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002414 if (skb_shinfo(skb)->tso_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 if (skb_header_cloned(skb)) {
2416 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2417 if (err)
2418 return err;
2419 }
2420
2421 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2422 mss = skb_shinfo(skb)->tso_size;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002423 if (skb->protocol == ntohs(ETH_P_IP)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002424 skb->nh.iph->tot_len = 0;
2425 skb->nh.iph->check = 0;
2426 skb->h.th->check =
2427 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2428 skb->nh.iph->daddr,
2429 0,
2430 IPPROTO_TCP,
2431 0);
2432 cmd_length = E1000_TXD_CMD_IP;
2433 ipcse = skb->h.raw - skb->data - 1;
2434#ifdef NETIF_F_TSO_IPV6
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002435 } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002436 skb->nh.ipv6h->payload_len = 0;
2437 skb->h.th->check =
2438 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2439 &skb->nh.ipv6h->daddr,
2440 0,
2441 IPPROTO_TCP,
2442 0);
2443 ipcse = 0;
2444#endif
2445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 ipcss = skb->nh.raw - skb->data;
2447 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 tucss = skb->h.raw - skb->data;
2449 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2450 tucse = 0;
2451
2452 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002453 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002455 i = tx_ring->next_to_use;
2456 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002457 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458
2459 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2460 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2461 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2462 context_desc->upper_setup.tcp_fields.tucss = tucss;
2463 context_desc->upper_setup.tcp_fields.tucso = tucso;
2464 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2465 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2466 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2467 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2468
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002469 buffer_info->time_stamp = jiffies;
2470
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002471 if (++i == tx_ring->count) i = 0;
2472 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
Jeff Kirsher8241e352006-01-12 16:51:34 -08002474 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 }
2476#endif
2477
Jeff Kirsher8241e352006-01-12 16:51:34 -08002478 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479}
2480
2481static inline boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002482e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2483 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484{
2485 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002486 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 unsigned int i;
2488 uint8_t css;
2489
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002490 if (likely(skb->ip_summed == CHECKSUM_HW)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 css = skb->h.raw - skb->data;
2492
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002493 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002494 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002495 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
2497 context_desc->upper_setup.tcp_fields.tucss = css;
2498 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2499 context_desc->upper_setup.tcp_fields.tucse = 0;
2500 context_desc->tcp_seg_setup.data = 0;
2501 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2502
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002503 buffer_info->time_stamp = jiffies;
2504
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002505 if (unlikely(++i == tx_ring->count)) i = 0;
2506 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
2508 return TRUE;
2509 }
2510
2511 return FALSE;
2512}
2513
2514#define E1000_MAX_TXD_PWR 12
2515#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2516
2517static inline int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002518e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2519 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2520 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 struct e1000_buffer *buffer_info;
2523 unsigned int len = skb->len;
2524 unsigned int offset = 0, size, count = 0, i;
2525 unsigned int f;
2526 len -= skb->data_len;
2527
2528 i = tx_ring->next_to_use;
2529
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002530 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 buffer_info = &tx_ring->buffer_info[i];
2532 size = min(len, max_per_txd);
2533#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002534 /* Workaround for Controller erratum --
2535 * descriptor for non-tso packet in a linear SKB that follows a
2536 * tso gets written back prematurely before the data is fully
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002537 * DMA'd to the controller */
Jeff Kirsherfd803242005-12-13 00:06:22 -05002538 if (!skb->data_len && tx_ring->last_tx_tso &&
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002539 !skb_shinfo(skb)->tso_size) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05002540 tx_ring->last_tx_tso = 0;
2541 size -= 4;
2542 }
2543
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 /* Workaround for premature desc write-backs
2545 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002546 if (unlikely(mss && !nr_frags && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 size -= 4;
2548#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002549 /* work-around for errata 10 and it applies
2550 * to all controllers in PCI-X mode
2551 * The fix is to make sure that the first descriptor of a
2552 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2553 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002554 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002555 (size > 2015) && count == 0))
2556 size = 2015;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002557
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 /* Workaround for potential 82544 hang in PCI-X. Avoid
2559 * terminating buffers within evenly-aligned dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002560 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2562 size > 4))
2563 size -= 4;
2564
2565 buffer_info->length = size;
2566 buffer_info->dma =
2567 pci_map_single(adapter->pdev,
2568 skb->data + offset,
2569 size,
2570 PCI_DMA_TODEVICE);
2571 buffer_info->time_stamp = jiffies;
2572
2573 len -= size;
2574 offset += size;
2575 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002576 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 }
2578
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002579 for (f = 0; f < nr_frags; f++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 struct skb_frag_struct *frag;
2581
2582 frag = &skb_shinfo(skb)->frags[f];
2583 len = frag->size;
2584 offset = frag->page_offset;
2585
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002586 while (len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 buffer_info = &tx_ring->buffer_info[i];
2588 size = min(len, max_per_txd);
2589#ifdef NETIF_F_TSO
2590 /* Workaround for premature desc write-backs
2591 * in TSO mode. Append 4-byte sentinel desc */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002592 if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 size -= 4;
2594#endif
2595 /* Workaround for potential 82544 hang in PCI-X.
2596 * Avoid terminating buffers within evenly-aligned
2597 * dwords. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002598 if (unlikely(adapter->pcix_82544 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2600 size > 4))
2601 size -= 4;
2602
2603 buffer_info->length = size;
2604 buffer_info->dma =
2605 pci_map_page(adapter->pdev,
2606 frag->page,
2607 offset,
2608 size,
2609 PCI_DMA_TODEVICE);
2610 buffer_info->time_stamp = jiffies;
2611
2612 len -= size;
2613 offset += size;
2614 count++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002615 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 }
2617 }
2618
2619 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2620 tx_ring->buffer_info[i].skb = skb;
2621 tx_ring->buffer_info[first].next_to_watch = i;
2622
2623 return count;
2624}
2625
2626static inline void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002627e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2628 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 struct e1000_tx_desc *tx_desc = NULL;
2631 struct e1000_buffer *buffer_info;
2632 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2633 unsigned int i;
2634
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002635 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2637 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002638 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2639
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002640 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002641 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 }
2643
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002644 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2646 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2647 }
2648
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002649 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 txd_lower |= E1000_TXD_CMD_VLE;
2651 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2652 }
2653
2654 i = tx_ring->next_to_use;
2655
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002656 while (count--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 buffer_info = &tx_ring->buffer_info[i];
2658 tx_desc = E1000_TX_DESC(*tx_ring, i);
2659 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2660 tx_desc->lower.data =
2661 cpu_to_le32(txd_lower | buffer_info->length);
2662 tx_desc->upper.data = cpu_to_le32(txd_upper);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002663 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 }
2665
2666 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2667
2668 /* Force memory writes to complete before letting h/w
2669 * know there are new descriptors to fetch. (Only
2670 * applicable for weak-ordered memory model archs,
2671 * such as IA-64). */
2672 wmb();
2673
2674 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002675 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676}
2677
2678/**
2679 * 82547 workaround to avoid controller hang in half-duplex environment.
2680 * The workaround is to avoid queuing a large packet that would span
2681 * the internal Tx FIFO ring boundary by notifying the stack to resend
2682 * the packet at a later time. This gives the Tx FIFO an opportunity to
2683 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2684 * to the beginning of the Tx FIFO.
2685 **/
2686
2687#define E1000_FIFO_HDR 0x10
2688#define E1000_82547_PAD_LEN 0x3E0
2689
2690static inline int
2691e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2692{
2693 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2694 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2695
2696 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2697
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002698 if (adapter->link_duplex != HALF_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 goto no_fifo_stall_required;
2700
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002701 if (atomic_read(&adapter->tx_fifo_stall))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 return 1;
2703
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002704 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 atomic_set(&adapter->tx_fifo_stall, 1);
2706 return 1;
2707 }
2708
2709no_fifo_stall_required:
2710 adapter->tx_fifo_head += skb_fifo_len;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002711 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2713 return 0;
2714}
2715
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002716#define MINIMUM_DHCP_PACKET_SIZE 282
2717static inline int
2718e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2719{
2720 struct e1000_hw *hw = &adapter->hw;
2721 uint16_t length, offset;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002722 if (vlan_tx_tag_present(skb)) {
2723 if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002724 ( adapter->hw.mng_cookie.status &
2725 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2726 return 0;
2727 }
Jeff Kirsher20a44022006-03-02 18:18:08 -08002728 if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002729 struct ethhdr *eth = (struct ethhdr *) skb->data;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002730 if ((htons(ETH_P_IP) == eth->h_proto)) {
2731 const struct iphdr *ip =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002732 (struct iphdr *)((uint8_t *)skb->data+14);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002733 if (IPPROTO_UDP == ip->protocol) {
2734 struct udphdr *udp =
2735 (struct udphdr *)((uint8_t *)ip +
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002736 (ip->ihl << 2));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002737 if (ntohs(udp->dest) == 67) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002738 offset = (uint8_t *)udp + 8 - skb->data;
2739 length = skb->len - offset;
2740
2741 return e1000_mng_write_dhcp_info(hw,
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002742 (uint8_t *)udp + 8,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002743 length);
2744 }
2745 }
2746 }
2747 }
2748 return 0;
2749}
2750
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2752static int
2753e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2754{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002755 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002756 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2758 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2759 unsigned int tx_flags = 0;
2760 unsigned int len = skb->len;
2761 unsigned long flags;
2762 unsigned int nr_frags = 0;
2763 unsigned int mss = 0;
2764 int count = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002765 int tso;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 unsigned int f;
2767 len -= skb->data_len;
2768
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002769 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002770
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002771 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 dev_kfree_skb_any(skb);
2773 return NETDEV_TX_OK;
2774 }
2775
2776#ifdef NETIF_F_TSO
2777 mss = skb_shinfo(skb)->tso_size;
Malli Chilakala26483452005-04-28 19:44:46 -07002778 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 * make sure there is enough room in the FIFO before
2780 * initiating the DMA for each buffer. The calc is:
2781 * 4 = ceil(buffer len/mss). To make sure we don't
2782 * overrun the FIFO, adjust the max buffer len if mss
2783 * drops. */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002784 if (mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002785 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 max_per_txd = min(mss << 2, max_per_txd);
2787 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002788
Jeff Kirsher9f687882006-03-02 18:20:17 -08002789 /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002790 * points to just header, pull a few bytes of payload from
2791 * frags into skb->data */
2792 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
Jeff Kirsher9f687882006-03-02 18:20:17 -08002793 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
2794 switch (adapter->hw.mac_type) {
2795 unsigned int pull_size;
2796 case e1000_82571:
2797 case e1000_82572:
2798 case e1000_82573:
2799 pull_size = min((unsigned int)4, skb->data_len);
2800 if (!__pskb_pull_tail(skb, pull_size)) {
2801 printk(KERN_ERR
2802 "__pskb_pull_tail failed.\n");
2803 dev_kfree_skb_any(skb);
Jeff Garzik749dfc702006-03-11 13:35:31 -05002804 return NETDEV_TX_OK;
Jeff Kirsher9f687882006-03-02 18:20:17 -08002805 }
2806 len = skb->len - skb->data_len;
2807 break;
2808 default:
2809 /* do nothing */
2810 break;
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08002811 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 }
2814
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002815 /* reserve a descriptor for the offload context */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002816 if ((mss) || (skb->ip_summed == CHECKSUM_HW))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07002818 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819#else
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002820 if (skb->ip_summed == CHECKSUM_HW)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 count++;
2822#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05002823
2824#ifdef NETIF_F_TSO
2825 /* Controller Erratum workaround */
2826 if (!skb->data_len && tx_ring->last_tx_tso &&
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002827 !skb_shinfo(skb)->tso_size)
Jeff Kirsherfd803242005-12-13 00:06:22 -05002828 count++;
2829#endif
2830
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 count += TXD_USE_COUNT(len, max_txd_pwr);
2832
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002833 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 count++;
2835
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002836 /* work-around for errata 10 and it applies to all controllers
Malli Chilakala97338bd2005-04-28 19:41:46 -07002837 * in PCI-X mode, so add one more descriptor to the count
2838 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002839 if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
Malli Chilakala97338bd2005-04-28 19:41:46 -07002840 (len > 2015)))
2841 count++;
2842
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 nr_frags = skb_shinfo(skb)->nr_frags;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002844 for (f = 0; f < nr_frags; f++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2846 max_txd_pwr);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002847 if (adapter->pcix_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 count += nr_frags;
2849
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08002850
2851 if (adapter->hw.tx_pkt_filtering &&
2852 (adapter->hw.mac_type == e1000_82573))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002853 e1000_transfer_dhcp_info(adapter, skb);
2854
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002855 local_irq_save(flags);
2856 if (!spin_trylock(&tx_ring->tx_lock)) {
2857 /* Collision - tell upper layer to requeue */
2858 local_irq_restore(flags);
2859 return NETDEV_TX_LOCKED;
2860 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861
2862 /* need: count + 2 desc gap to keep tail from touching
2863 * head, otherwise try next time */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002864 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 netif_stop_queue(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002866 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 return NETDEV_TX_BUSY;
2868 }
2869
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002870 if (unlikely(adapter->hw.mac_type == e1000_82547)) {
2871 if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 netif_stop_queue(netdev);
2873 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002874 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 return NETDEV_TX_BUSY;
2876 }
2877 }
2878
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002879 if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 tx_flags |= E1000_TX_FLAGS_VLAN;
2881 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2882 }
2883
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002884 first = tx_ring->next_to_use;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002885
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002886 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 if (tso < 0) {
2888 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002889 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 return NETDEV_TX_OK;
2891 }
2892
Jeff Kirsherfd803242005-12-13 00:06:22 -05002893 if (likely(tso)) {
2894 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002896 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 tx_flags |= E1000_TX_FLAGS_CSUM;
2898
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002899 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002900 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002901 * no longer assume, we must. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002902 if (likely(skb->protocol == ntohs(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002903 tx_flags |= E1000_TX_FLAGS_IPV4;
2904
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002905 e1000_tx_queue(adapter, tx_ring, tx_flags,
2906 e1000_tx_map(adapter, tx_ring, skb, first,
2907 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
2909 netdev->trans_start = jiffies;
2910
2911 /* Make sure there is space in the ring for the next send. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002912 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 netif_stop_queue(netdev);
2914
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002915 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 return NETDEV_TX_OK;
2917}
2918
2919/**
2920 * e1000_tx_timeout - Respond to a Tx Hang
2921 * @netdev: network interface device structure
2922 **/
2923
2924static void
2925e1000_tx_timeout(struct net_device *netdev)
2926{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002927 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928
2929 /* Do the reset outside of interrupt context */
Jeff Kirsher87041632006-03-02 18:21:24 -08002930 adapter->tx_timeout_count++;
2931 schedule_work(&adapter->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932}
2933
2934static void
Jeff Kirsher87041632006-03-02 18:21:24 -08002935e1000_reset_task(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002937 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938
2939 e1000_down(adapter);
2940 e1000_up(adapter);
2941}
2942
2943/**
2944 * e1000_get_stats - Get System Network Statistics
2945 * @netdev: network interface device structure
2946 *
2947 * Returns the address of the device statistics structure.
2948 * The statistics are actually updated from the timer callback.
2949 **/
2950
2951static struct net_device_stats *
2952e1000_get_stats(struct net_device *netdev)
2953{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002954 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08002956 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 return &adapter->net_stats;
2958}
2959
2960/**
2961 * e1000_change_mtu - Change the Maximum Transfer Unit
2962 * @netdev: network interface device structure
2963 * @new_mtu: new value for maximum frame size
2964 *
2965 * Returns 0 on success, negative on failure
2966 **/
2967
2968static int
2969e1000_change_mtu(struct net_device *netdev, int new_mtu)
2970{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002971 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08002973 uint16_t eeprom_data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
Jesse Brandeburg96838a42006-01-18 13:01:39 -08002975 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2976 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2977 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002978 return -EINVAL;
2979 }
2980
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002981 /* Adapter-specific max frame size limits. */
2982 switch (adapter->hw.mac_type) {
2983 case e1000_82542_rev2_0:
2984 case e1000_82542_rev2_1:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002985 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2986 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002987 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002988 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002989 break;
Jeff Kirsher85b22eb2006-03-02 18:20:29 -08002990 case e1000_82573:
2991 /* only enable jumbo frames if ASPM is disabled completely
2992 * this means both bits must be zero in 0x1A bits 3:2 */
2993 e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
2994 &eeprom_data);
2995 if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
2996 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2997 DPRINTK(PROBE, ERR,
2998 "Jumbo Frames not supported.\n");
2999 return -EINVAL;
3000 }
3001 break;
3002 }
3003 /* fall through to get support */
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003004 case e1000_82571:
3005 case e1000_82572:
Jeff Kirsher87041632006-03-02 18:21:24 -08003006 case e1000_80003es2lan:
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003007#define MAX_STD_JUMBO_FRAME_SIZE 9234
3008 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3009 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3010 return -EINVAL;
3011 }
3012 break;
3013 default:
3014 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3015 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003016 }
3017
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003018
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003019 if (adapter->hw.mac_type > e1000_82547_rev_2) {
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003020 adapter->rx_buffer_len = max_frame;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003021 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003022 } else {
3023 if(unlikely((adapter->hw.mac_type < e1000_82543) &&
3024 (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
3025 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
3026 "on 82542\n");
3027 return -EINVAL;
3028 } else {
3029 if(max_frame <= E1000_RXBUFFER_2048)
3030 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3031 else if(max_frame <= E1000_RXBUFFER_4096)
3032 adapter->rx_buffer_len = E1000_RXBUFFER_4096;
3033 else if(max_frame <= E1000_RXBUFFER_8192)
3034 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3035 else if(max_frame <= E1000_RXBUFFER_16384)
3036 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3037 }
3038 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003039
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003040 netdev->mtu = new_mtu;
3041
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003042 if (netif_running(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 e1000_down(adapter);
3044 e1000_up(adapter);
3045 }
3046
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 adapter->hw.max_frame_size = max_frame;
3048
3049 return 0;
3050}
3051
3052/**
3053 * e1000_update_stats - Update the board statistics counters
3054 * @adapter: board private structure
3055 **/
3056
3057void
3058e1000_update_stats(struct e1000_adapter *adapter)
3059{
3060 struct e1000_hw *hw = &adapter->hw;
3061 unsigned long flags;
3062 uint16_t phy_tmp;
3063
3064#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3065
3066 spin_lock_irqsave(&adapter->stats_lock, flags);
3067
3068 /* these counters are modified from e1000_adjust_tbi_stats,
3069 * called from the interrupt context, so they must only
3070 * be written while holding adapter->stats_lock
3071 */
3072
3073 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3074 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3075 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3076 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3077 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3078 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3079 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3080 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3081 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3082 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3083 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3084 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3085 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3086
3087 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3088 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3089 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3090 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3091 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3092 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3093 adapter->stats.dc += E1000_READ_REG(hw, DC);
3094 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3095 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3096 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3097 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3098 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3099 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3100 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3101 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3102 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3103 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3104 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3105 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3106 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3107 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3108 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3109 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3110 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3111 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3112 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3113 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3114 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3115 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3116 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3117 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3118 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3119 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3120 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3121
3122 /* used for adaptive IFS */
3123
3124 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3125 adapter->stats.tpt += hw->tx_packet_delta;
3126 hw->collision_delta = E1000_READ_REG(hw, COLC);
3127 adapter->stats.colc += hw->collision_delta;
3128
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003129 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3131 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3132 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3133 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3134 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3135 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3136 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003137 if (hw->mac_type > e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003138 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3139 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3140 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3141 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3142 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3143 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3144 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3145 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3146 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
3149 /* Fill out the OS statistics structure */
3150
3151 adapter->net_stats.rx_packets = adapter->stats.gprc;
3152 adapter->net_stats.tx_packets = adapter->stats.gptc;
3153 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3154 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3155 adapter->net_stats.multicast = adapter->stats.mprc;
3156 adapter->net_stats.collisions = adapter->stats.colc;
3157
3158 /* Rx Errors */
3159
Jeff Kirsher87041632006-03-02 18:21:24 -08003160 /* RLEC on some newer hardware can be incorrect so build
3161 * our own version based on RUC and ROC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3163 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher87041632006-03-02 18:21:24 -08003164 adapter->stats.ruc + adapter->stats.roc +
3165 adapter->stats.cexterr;
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003166 adapter->net_stats.rx_dropped = 0;
Jeff Kirsher87041632006-03-02 18:21:24 -08003167 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3168 adapter->stats.roc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3170 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3172
3173 /* Tx Errors */
3174
3175 adapter->net_stats.tx_errors = adapter->stats.ecol +
3176 adapter->stats.latecol;
3177 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3178 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3179 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3180
3181 /* Tx Dropped needs to be maintained elsewhere */
3182
3183 /* Phy Stats */
3184
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003185 if (hw->media_type == e1000_media_type_copper) {
3186 if ((adapter->link_speed == SPEED_1000) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3188 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3189 adapter->phy_stats.idle_errors += phy_tmp;
3190 }
3191
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003192 if ((hw->mac_type <= e1000_82546) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 (hw->phy_type == e1000_phy_m88) &&
3194 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3195 adapter->phy_stats.receive_errors += phy_tmp;
3196 }
3197
3198 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3199}
3200
3201/**
3202 * e1000_intr - Interrupt Handler
3203 * @irq: interrupt number
3204 * @data: pointer to a network interface device structure
3205 * @pt_regs: CPU registers structure
3206 **/
3207
3208static irqreturn_t
3209e1000_intr(int irq, void *data, struct pt_regs *regs)
3210{
3211 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003212 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 struct e1000_hw *hw = &adapter->hw;
Jeff Kirsher87041632006-03-02 18:21:24 -08003214 uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003215#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003216 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003217#else
3218 /* Interrupt Auto-Mask...upon reading ICR,
3219 * interrupts are masked. No need for the
3220 * IMC write, but it does mean we should
3221 * account for it ASAP. */
3222 if (likely(hw->mac_type >= e1000_82571))
3223 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003224#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003226 if (unlikely(!icr)) {
3227#ifdef CONFIG_E1000_NAPI
3228 if (hw->mac_type >= e1000_82571)
3229 e1000_irq_enable(adapter);
3230#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003234 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 hw->get_link_status = 1;
Jeff Kirsher87041632006-03-02 18:21:24 -08003236 /* 80003ES2LAN workaround--
3237 * For packet buffer work-around on link down event;
3238 * disable receives here in the ISR and
3239 * reset adapter in watchdog
3240 */
3241 if (netif_carrier_ok(netdev) &&
3242 (adapter->hw.mac_type == e1000_80003es2lan)) {
3243 /* disable receives */
3244 rctl = E1000_READ_REG(hw, RCTL);
3245 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
3246 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 mod_timer(&adapter->watchdog_timer, jiffies);
3248 }
3249
3250#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003251 if (unlikely(hw->mac_type < e1000_82571)) {
3252 atomic_inc(&adapter->irq_sem);
3253 E1000_WRITE_REG(hw, IMC, ~0);
3254 E1000_WRITE_FLUSH(hw);
3255 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003256 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3257 __netif_rx_schedule(&adapter->polling_netdev[0]);
3258 else
3259 e1000_irq_enable(adapter);
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003260#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 /* Writing IMC and IMS is needed for 82547.
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003262 * Due to Hub Link bus being occupied, an interrupt
3263 * de-assertion message is not able to be sent.
3264 * When an interrupt assertion message is generated later,
3265 * two messages are re-ordered and sent out.
3266 * That causes APIC to think 82547 is in de-assertion
3267 * state, while 82547 is in assertion state, resulting
3268 * in dead lock. Writing IMC forces 82547 into
3269 * de-assertion state.
3270 */
3271 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003273 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 }
3275
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003276 for (i = 0; i < E1000_MAX_INTR; i++)
3277 if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003278 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 break;
3280
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003281 if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003283
Jeff Kirsherc1605eb2006-03-02 18:16:38 -08003284#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
3286 return IRQ_HANDLED;
3287}
3288
3289#ifdef CONFIG_E1000_NAPI
3290/**
3291 * e1000_clean - NAPI Rx polling callback
3292 * @adapter: board private structure
3293 **/
3294
3295static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003296e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003298 struct e1000_adapter *adapter;
3299 int work_to_do = min(*budget, poll_dev->quota);
Jeff Kirsher38bd3b22006-01-12 16:51:37 -08003300 int tx_cleaned = 0, i = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003301
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003302 /* Must NOT use netdev_priv macro here. */
3303 adapter = poll_dev->priv;
3304
3305 /* Keep link state information with original netdev */
3306 if (!netif_carrier_ok(adapter->netdev))
3307 goto quit_polling;
3308
3309 while (poll_dev != &adapter->polling_netdev[i]) {
3310 i++;
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02003311 BUG_ON(i == adapter->num_rx_queues);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003312 }
3313
Jeff Kirsher8241e352006-01-12 16:51:34 -08003314 if (likely(adapter->num_tx_queues == 1)) {
3315 /* e1000_clean is called per-cpu. This lock protects
3316 * tx_ring[0] from being cleaned by multiple cpus
3317 * simultaneously. A failure obtaining the lock means
3318 * tx_ring[0] is currently being cleaned anyway. */
3319 if (spin_trylock(&adapter->tx_queue_lock)) {
3320 tx_cleaned = e1000_clean_tx_irq(adapter,
3321 &adapter->tx_ring[0]);
3322 spin_unlock(&adapter->tx_queue_lock);
3323 }
3324 } else
3325 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3326
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003327 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3328 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329
3330 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003331 poll_dev->quota -= work_done;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003332
Malli Chilakala2b028932005-06-17 17:46:06 -07003333 /* If no Tx and not enough Rx work done, exit the polling mode */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003334 if ((!tx_cleaned && (work_done == 0)) ||
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003335 !netif_running(adapter->netdev)) {
3336quit_polling:
3337 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 e1000_irq_enable(adapter);
3339 return 0;
3340 }
3341
3342 return 1;
3343}
3344
3345#endif
3346/**
3347 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3348 * @adapter: board private structure
3349 **/
3350
3351static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003352e1000_clean_tx_irq(struct e1000_adapter *adapter,
3353 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 struct net_device *netdev = adapter->netdev;
3356 struct e1000_tx_desc *tx_desc, *eop_desc;
3357 struct e1000_buffer *buffer_info;
3358 unsigned int i, eop;
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003359#ifdef CONFIG_E1000_NAPI
3360 unsigned int count = 0;
3361#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 boolean_t cleaned = FALSE;
3363
3364 i = tx_ring->next_to_clean;
3365 eop = tx_ring->buffer_info[i].next_to_watch;
3366 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3367
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003368 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003369 for (cleaned = FALSE; !cleaned; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 tx_desc = E1000_TX_DESC(*tx_ring, i);
3371 buffer_info = &tx_ring->buffer_info[i];
3372 cleaned = (i == eop);
3373
Jeff Kirsherfd803242005-12-13 00:06:22 -05003374 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jeff Kirsher8241e352006-01-12 16:51:34 -08003375 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003377 if (unlikely(++i == tx_ring->count)) i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003379
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003380
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 eop = tx_ring->buffer_info[i].next_to_watch;
3382 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Jeff Kirsher2a1af5d2006-03-02 18:20:43 -08003383#ifdef CONFIG_E1000_NAPI
3384#define E1000_TX_WEIGHT 64
3385 /* weight of a sort for tx, to avoid endless transmit cleanup */
3386 if (count++ == E1000_TX_WEIGHT) break;
3387#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 }
3389
3390 tx_ring->next_to_clean = i;
3391
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003392 spin_lock(&tx_ring->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003394 if (unlikely(cleaned && netif_queue_stopped(netdev) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 netif_carrier_ok(netdev)))
3396 netif_wake_queue(netdev);
3397
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003398 spin_unlock(&tx_ring->tx_lock);
Malli Chilakala26483452005-04-28 19:44:46 -07003399
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003400 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003401 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 * check with the clearing of time_stamp and movement of i */
3403 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003404 if (tx_ring->buffer_info[eop].dma &&
3405 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
Jeff Kirsher7e6c9862006-03-02 18:19:30 -08003406 (adapter->tx_timeout_factor * HZ))
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003407 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003408 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003409
3410 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003411 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003412 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003413 " TDH <%x>\n"
3414 " TDT <%x>\n"
3415 " next_to_use <%x>\n"
3416 " next_to_clean <%x>\n"
3417 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003418 " time_stamp <%lx>\n"
3419 " next_to_watch <%x>\n"
3420 " jiffies <%lx>\n"
3421 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003422 (unsigned long)((tx_ring - adapter->tx_ring) /
3423 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003424 readl(adapter->hw.hw_addr + tx_ring->tdh),
3425 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003426 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003427 tx_ring->next_to_clean,
3428 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003429 eop,
3430 jiffies,
3431 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 return cleaned;
3436}
3437
3438/**
3439 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003440 * @adapter: board private structure
3441 * @status_err: receive descriptor status and error fields
3442 * @csum: receive descriptor csum field
3443 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 **/
3445
3446static inline void
3447e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003448 uint32_t status_err, uint32_t csum,
3449 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003451 uint16_t status = (uint16_t)status_err;
3452 uint8_t errors = (uint8_t)(status_err >> 24);
3453 skb->ip_summed = CHECKSUM_NONE;
3454
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 /* 82543 or newer only */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003456 if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 /* Ignore Checksum bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003458 if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003459 /* TCP/UDP checksum error bit is set */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003460 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003461 /* let the stack verify checksum errors */
3462 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 return;
3464 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003465 /* TCP/UDP Checksum has not been calculated */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003466 if (adapter->hw.mac_type <= e1000_82547_rev_2) {
3467 if (!(status & E1000_RXD_STAT_TCPCS))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003468 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 } else {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003470 if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003471 return;
3472 }
3473 /* It must be a TCP or UDP packet with a valid checksum */
3474 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 /* TCP checksum is good */
3476 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003477 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3478 /* IP fragment with UDP payload */
3479 /* Hardware complements the payload checksum, so we undo it
3480 * and then put the value in host order for further stack use.
3481 */
3482 csum = ntohl(csum ^ 0xFFFF);
3483 skb->csum = csum;
3484 skb->ip_summed = CHECKSUM_HW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003486 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487}
3488
3489/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003490 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 * @adapter: board private structure
3492 **/
3493
3494static boolean_t
3495#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003496e1000_clean_rx_irq(struct e1000_adapter *adapter,
3497 struct e1000_rx_ring *rx_ring,
3498 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003500e1000_clean_rx_irq(struct e1000_adapter *adapter,
3501 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502#endif
3503{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 struct net_device *netdev = adapter->netdev;
3505 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003506 struct e1000_rx_desc *rx_desc, *next_rxd;
3507 struct e1000_buffer *buffer_info, *next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 unsigned long flags;
3509 uint32_t length;
3510 uint8_t last_byte;
3511 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003512 int cleaned_count = 0;
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003513 boolean_t cleaned = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514
3515 i = rx_ring->next_to_clean;
3516 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003517 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003519 while (rx_desc->status & E1000_RXD_STAT_DD) {
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003520 struct sk_buff *skb, *next_skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003521 u8 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003523 if (*work_done >= work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 break;
3525 (*work_done)++;
3526#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08003527 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003528 skb = buffer_info->skb;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003529 buffer_info->skb = NULL;
3530
Jeff Kirsher30320be2006-03-02 18:21:57 -08003531 prefetch(skb->data - NET_IP_ALIGN);
3532
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003533 if (++i == rx_ring->count) i = 0;
3534 next_rxd = E1000_RX_DESC(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003535 prefetch(next_rxd);
3536
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003537 next_buffer = &rx_ring->buffer_info[i];
3538 next_skb = next_buffer->skb;
Jeff Kirsher30320be2006-03-02 18:21:57 -08003539 prefetch(next_skb->data - NET_IP_ALIGN);
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003540
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003541 cleaned = TRUE;
3542 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003543 pci_unmap_single(pdev,
3544 buffer_info->dma,
3545 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 PCI_DMA_FROMDEVICE);
3547
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 length = le16_to_cpu(rx_desc->length);
3549
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003550 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3551 /* All receives must fit into a single buffer */
3552 E1000_DBG("%s: Receive packet consumed multiple"
3553 " buffers\n", netdev->name);
3554 dev_kfree_skb_irq(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 goto next_desc;
3556 }
3557
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003558 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003560 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 rx_desc->errors, length, last_byte)) {
3562 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003563 e1000_tbi_adjust_stats(&adapter->hw,
3564 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 length, skb->data);
3566 spin_unlock_irqrestore(&adapter->stats_lock,
3567 flags);
3568 length--;
3569 } else {
3570 dev_kfree_skb_irq(skb);
3571 goto next_desc;
3572 }
3573 }
3574
Jeff Kirshera292ca62006-01-12 16:51:30 -08003575 /* code added for copybreak, this should improve
3576 * performance for small packets with large amounts
3577 * of reassembly being done in the stack */
3578#define E1000_CB_LENGTH 256
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003579 if (length < E1000_CB_LENGTH) {
Jeff Kirshera292ca62006-01-12 16:51:30 -08003580 struct sk_buff *new_skb =
3581 dev_alloc_skb(length + NET_IP_ALIGN);
3582 if (new_skb) {
3583 skb_reserve(new_skb, NET_IP_ALIGN);
3584 new_skb->dev = netdev;
3585 memcpy(new_skb->data - NET_IP_ALIGN,
3586 skb->data - NET_IP_ALIGN,
3587 length + NET_IP_ALIGN);
3588 /* save the skb in buffer_info as good */
3589 buffer_info->skb = skb;
3590 skb = new_skb;
3591 skb_put(skb, length);
3592 }
Jeff Kirshera1415ee2006-02-28 20:24:07 -08003593 } else
3594 skb_put(skb, length);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003595
3596 /* end copybreak code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597
3598 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08003599 e1000_rx_checksum(adapter,
3600 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003601 ((uint32_t)(rx_desc->errors) << 24),
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003602 le16_to_cpu(rx_desc->csum), skb);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003603
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 skb->protocol = eth_type_trans(skb, netdev);
3605#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003606 if (unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08003607 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003609 le16_to_cpu(rx_desc->special) &
3610 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 } else {
3612 netif_receive_skb(skb);
3613 }
3614#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003615 if (unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003616 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 vlan_hwaccel_rx(skb, adapter->vlgrp,
3618 le16_to_cpu(rx_desc->special) &
3619 E1000_RXD_SPC_VLAN_MASK);
3620 } else {
3621 netif_rx(skb);
3622 }
3623#endif /* CONFIG_E1000_NAPI */
3624 netdev->last_rx = jiffies;
3625
3626next_desc:
3627 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003629 /* return some buffers to hardware, one at a time is too slow */
3630 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3631 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3632 cleaned_count = 0;
3633 }
3634
Jeff Kirsher30320be2006-03-02 18:21:57 -08003635 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003636 rx_desc = next_rxd;
3637 buffer_info = next_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003640
3641 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3642 if (cleaned_count)
3643 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644
3645 return cleaned;
3646}
3647
3648/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003649 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3650 * @adapter: board private structure
3651 **/
3652
3653static boolean_t
3654#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003655e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3656 struct e1000_rx_ring *rx_ring,
3657 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003658#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003659e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3660 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003661#endif
3662{
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003663 union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003664 struct net_device *netdev = adapter->netdev;
3665 struct pci_dev *pdev = adapter->pdev;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003666 struct e1000_buffer *buffer_info, *next_buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003667 struct e1000_ps_page *ps_page;
3668 struct e1000_ps_page_dma *ps_page_dma;
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003669 struct sk_buff *skb, *next_skb;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003670 unsigned int i, j;
3671 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003672 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003673 boolean_t cleaned = FALSE;
3674
3675 i = rx_ring->next_to_clean;
3676 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003677 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003678
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003679 while (staterr & E1000_RXD_STAT_DD) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08003680 buffer_info = &rx_ring->buffer_info[i];
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003681 ps_page = &rx_ring->ps_page[i];
3682 ps_page_dma = &rx_ring->ps_page_dma[i];
3683#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003684 if (unlikely(*work_done >= work_to_do))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003685 break;
3686 (*work_done)++;
3687#endif
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003688 skb = buffer_info->skb;
3689
Jeff Kirsher30320be2006-03-02 18:21:57 -08003690 /* in the packet split case this is header only */
3691 prefetch(skb->data - NET_IP_ALIGN);
3692
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003693 if (++i == rx_ring->count) i = 0;
3694 next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
Jeff Kirsher30320be2006-03-02 18:21:57 -08003695 prefetch(next_rxd);
3696
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003697 next_buffer = &rx_ring->buffer_info[i];
3698 next_skb = next_buffer->skb;
Jeff Kirsher30320be2006-03-02 18:21:57 -08003699 prefetch(next_skb->data - NET_IP_ALIGN);
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003700
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003701 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003702 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003703 pci_unmap_single(pdev, buffer_info->dma,
3704 buffer_info->length,
3705 PCI_DMA_FROMDEVICE);
3706
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003707 if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003708 E1000_DBG("%s: Packet Split buffers didn't pick up"
3709 " the full packet\n", netdev->name);
3710 dev_kfree_skb_irq(skb);
3711 goto next_desc;
3712 }
3713
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003714 if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003715 dev_kfree_skb_irq(skb);
3716 goto next_desc;
3717 }
3718
3719 length = le16_to_cpu(rx_desc->wb.middle.length0);
3720
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003721 if (unlikely(!length)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003722 E1000_DBG("%s: Last part of the packet spanning"
3723 " multiple descriptors\n", netdev->name);
3724 dev_kfree_skb_irq(skb);
3725 goto next_desc;
3726 }
3727
3728 /* Good Receive */
3729 skb_put(skb, length);
3730
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003731 {
3732 /* this looks ugly, but it seems compiler issues make it
3733 more efficient than reusing j */
3734 int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
3735
3736 /* page alloc/put takes too long and effects small packet
3737 * throughput, so unsplit small packets and save the alloc/put*/
3738 if (l1 && ((length + l1) < E1000_CB_LENGTH)) {
3739 u8 *vaddr;
3740 /* there is no documentation about how to call
3741 * kmap_atomic, so we can't hold the mapping
3742 * very long */
3743 pci_dma_sync_single_for_cpu(pdev,
3744 ps_page_dma->ps_page_dma[0],
3745 PAGE_SIZE,
3746 PCI_DMA_FROMDEVICE);
3747 vaddr = kmap_atomic(ps_page->ps_page[0],
3748 KM_SKB_DATA_SOFTIRQ);
3749 memcpy(skb->tail, vaddr, l1);
3750 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
3751 pci_dma_sync_single_for_device(pdev,
3752 ps_page_dma->ps_page_dma[0],
3753 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3754 skb_put(skb, l1);
3755 length += l1;
3756 goto copydone;
3757 } /* if */
3758 }
3759
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003760 for (j = 0; j < adapter->rx_ps_pages; j++) {
Jeff Kirsher30320be2006-03-02 18:21:57 -08003761 if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003762 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003763 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3764 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3765 ps_page_dma->ps_page_dma[j] = 0;
Jeff Kirsher329bfd02006-03-02 18:20:02 -08003766 skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
3767 length);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003768 ps_page->ps_page[j] = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003769 skb->len += length;
3770 skb->data_len += length;
Auke Kokbcb49192006-04-25 22:50:04 -07003771 skb->truesize += length;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003772 }
3773
Jeff Kirsherdc7c6ad2006-03-02 18:21:40 -08003774copydone:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003775 e1000_rx_checksum(adapter, staterr,
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003776 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003777 skb->protocol = eth_type_trans(skb, netdev);
3778
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003779 if (likely(rx_desc->wb.upper.header_status &
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003780 cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003781 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003782#ifdef CONFIG_E1000_NAPI
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003783 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003784 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003785 le16_to_cpu(rx_desc->wb.middle.vlan) &
3786 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003787 } else {
3788 netif_receive_skb(skb);
3789 }
3790#else /* CONFIG_E1000_NAPI */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003791 if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003792 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003793 le16_to_cpu(rx_desc->wb.middle.vlan) &
3794 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003795 } else {
3796 netif_rx(skb);
3797 }
3798#endif /* CONFIG_E1000_NAPI */
3799 netdev->last_rx = jiffies;
3800
3801next_desc:
David S. Millerc3d7a3a2006-03-15 14:26:28 -08003802 rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003803 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003804
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003805 /* return some buffers to hardware, one at a time is too slow */
3806 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3807 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3808 cleaned_count = 0;
3809 }
3810
Jeff Kirsher30320be2006-03-02 18:21:57 -08003811 /* use prefetched values */
Jesse Brandeburg86c3d592006-01-18 13:01:43 -08003812 rx_desc = next_rxd;
3813 buffer_info = next_buffer;
3814
Malli Chilakala683a38f2005-06-17 17:43:25 -07003815 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003816 }
3817 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003818
3819 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3820 if (cleaned_count)
3821 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003822
3823 return cleaned;
3824}
3825
3826/**
3827 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 * @adapter: address of board private structure
3829 **/
3830
3831static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003832e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003833 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08003834 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 struct net_device *netdev = adapter->netdev;
3837 struct pci_dev *pdev = adapter->pdev;
3838 struct e1000_rx_desc *rx_desc;
3839 struct e1000_buffer *buffer_info;
3840 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003841 unsigned int i;
3842 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843
3844 i = rx_ring->next_to_use;
3845 buffer_info = &rx_ring->buffer_info[i];
3846
Jeff Kirshera292ca62006-01-12 16:51:30 -08003847 while (cleaned_count--) {
3848 if (!(skb = buffer_info->skb))
3849 skb = dev_alloc_skb(bufsz);
3850 else {
3851 skb_trim(skb, 0);
3852 goto map_skb;
3853 }
3854
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003855 if (unlikely(!skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003857 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 break;
3859 }
3860
Malli Chilakala26483452005-04-28 19:44:46 -07003861 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3863 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003864 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3865 "at %p\n", bufsz, skb->data);
3866 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 skb = dev_alloc_skb(bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07003868 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 if (!skb) {
3870 dev_kfree_skb(oldskb);
3871 break;
3872 }
Malli Chilakala26483452005-04-28 19:44:46 -07003873
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3875 /* give up */
3876 dev_kfree_skb(skb);
3877 dev_kfree_skb(oldskb);
3878 break; /* while !buffer_info->skb */
3879 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07003880 /* Use new allocation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 dev_kfree_skb(oldskb);
3882 }
3883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 /* Make buffer alignment 2 beyond a 16 byte boundary
3885 * this will result in a 16 byte aligned IP header after
3886 * the 14 byte MAC header is removed
3887 */
3888 skb_reserve(skb, NET_IP_ALIGN);
3889
3890 skb->dev = netdev;
3891
3892 buffer_info->skb = skb;
3893 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003894map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 buffer_info->dma = pci_map_single(pdev,
3896 skb->data,
3897 adapter->rx_buffer_len,
3898 PCI_DMA_FROMDEVICE);
3899
Malli Chilakala26483452005-04-28 19:44:46 -07003900 /* Fix for errata 23, can't cross 64kB boundary */
3901 if (!e1000_check_64k_bound(adapter,
3902 (void *)(unsigned long)buffer_info->dma,
3903 adapter->rx_buffer_len)) {
3904 DPRINTK(RX_ERR, ERR,
3905 "dma align check failed: %u bytes at %p\n",
3906 adapter->rx_buffer_len,
3907 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 dev_kfree_skb(skb);
3909 buffer_info->skb = NULL;
3910
Malli Chilakala26483452005-04-28 19:44:46 -07003911 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 adapter->rx_buffer_len,
3913 PCI_DMA_FROMDEVICE);
3914
3915 break; /* while !buffer_info->skb */
3916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917 rx_desc = E1000_RX_DESC(*rx_ring, i);
3918 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3919
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003920 if (unlikely(++i == rx_ring->count))
3921 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 buffer_info = &rx_ring->buffer_info[i];
3923 }
3924
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003925 if (likely(rx_ring->next_to_use != i)) {
3926 rx_ring->next_to_use = i;
3927 if (unlikely(i-- == 0))
3928 i = (rx_ring->count - 1);
3929
3930 /* Force memory writes to complete before letting h/w
3931 * know there are new descriptors to fetch. (Only
3932 * applicable for weak-ordered memory model archs,
3933 * such as IA-64). */
3934 wmb();
3935 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3936 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937}
3938
3939/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003940 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3941 * @adapter: address of board private structure
3942 **/
3943
3944static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003945e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003946 struct e1000_rx_ring *rx_ring,
3947 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003948{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003949 struct net_device *netdev = adapter->netdev;
3950 struct pci_dev *pdev = adapter->pdev;
3951 union e1000_rx_desc_packet_split *rx_desc;
3952 struct e1000_buffer *buffer_info;
3953 struct e1000_ps_page *ps_page;
3954 struct e1000_ps_page_dma *ps_page_dma;
3955 struct sk_buff *skb;
3956 unsigned int i, j;
3957
3958 i = rx_ring->next_to_use;
3959 buffer_info = &rx_ring->buffer_info[i];
3960 ps_page = &rx_ring->ps_page[i];
3961 ps_page_dma = &rx_ring->ps_page_dma[i];
3962
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003963 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003964 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3965
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003966 for (j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003967 if (j < adapter->rx_ps_pages) {
3968 if (likely(!ps_page->ps_page[j])) {
3969 ps_page->ps_page[j] =
3970 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003971 if (unlikely(!ps_page->ps_page[j])) {
3972 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003973 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003974 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003975 ps_page_dma->ps_page_dma[j] =
3976 pci_map_page(pdev,
3977 ps_page->ps_page[j],
3978 0, PAGE_SIZE,
3979 PCI_DMA_FROMDEVICE);
3980 }
3981 /* Refresh the desc even if buffer_addrs didn't
Jesse Brandeburg96838a42006-01-18 13:01:39 -08003982 * change because each write-back erases
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003983 * this info.
3984 */
3985 rx_desc->read.buffer_addr[j+1] =
3986 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3987 } else
3988 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003989 }
3990
3991 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3992
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003993 if (unlikely(!skb)) {
3994 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003995 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003996 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003997
3998 /* Make buffer alignment 2 beyond a 16 byte boundary
3999 * this will result in a 16 byte aligned IP header after
4000 * the 14 byte MAC header is removed
4001 */
4002 skb_reserve(skb, NET_IP_ALIGN);
4003
4004 skb->dev = netdev;
4005
4006 buffer_info->skb = skb;
4007 buffer_info->length = adapter->rx_ps_bsize0;
4008 buffer_info->dma = pci_map_single(pdev, skb->data,
4009 adapter->rx_ps_bsize0,
4010 PCI_DMA_FROMDEVICE);
4011
4012 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4013
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004014 if (unlikely(++i == rx_ring->count)) i = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004015 buffer_info = &rx_ring->buffer_info[i];
4016 ps_page = &rx_ring->ps_page[i];
4017 ps_page_dma = &rx_ring->ps_page_dma[i];
4018 }
4019
4020no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004021 if (likely(rx_ring->next_to_use != i)) {
4022 rx_ring->next_to_use = i;
4023 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4024
4025 /* Force memory writes to complete before letting h/w
4026 * know there are new descriptors to fetch. (Only
4027 * applicable for weak-ordered memory model archs,
4028 * such as IA-64). */
4029 wmb();
4030 /* Hardware increments by 16 bytes, but packet split
4031 * descriptors are 32 bytes...so we increment tail
4032 * twice as much.
4033 */
4034 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4035 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004036}
4037
4038/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4040 * @adapter:
4041 **/
4042
4043static void
4044e1000_smartspeed(struct e1000_adapter *adapter)
4045{
4046 uint16_t phy_status;
4047 uint16_t phy_ctrl;
4048
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004049 if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4051 return;
4052
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004053 if (adapter->smartspeed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 /* If Master/Slave config fault is asserted twice,
4055 * we assume back-to-back */
4056 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004057 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004059 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004061 if (phy_ctrl & CR_1000T_MS_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4063 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4064 phy_ctrl);
4065 adapter->smartspeed++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004066 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4068 &phy_ctrl)) {
4069 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4070 MII_CR_RESTART_AUTO_NEG);
4071 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4072 phy_ctrl);
4073 }
4074 }
4075 return;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004076 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 /* If still no link, perhaps using 2/3 pair cable */
4078 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4079 phy_ctrl |= CR_1000T_MS_ENABLE;
4080 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004081 if (!e1000_phy_setup_autoneg(&adapter->hw) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4083 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4084 MII_CR_RESTART_AUTO_NEG);
4085 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4086 }
4087 }
4088 /* Restart process after E1000_SMARTSPEED_MAX iterations */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004089 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 adapter->smartspeed = 0;
4091}
4092
4093/**
4094 * e1000_ioctl -
4095 * @netdev:
4096 * @ifreq:
4097 * @cmd:
4098 **/
4099
4100static int
4101e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4102{
4103 switch (cmd) {
4104 case SIOCGMIIPHY:
4105 case SIOCGMIIREG:
4106 case SIOCSMIIREG:
4107 return e1000_mii_ioctl(netdev, ifr, cmd);
4108 default:
4109 return -EOPNOTSUPP;
4110 }
4111}
4112
4113/**
4114 * e1000_mii_ioctl -
4115 * @netdev:
4116 * @ifreq:
4117 * @cmd:
4118 **/
4119
4120static int
4121e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4122{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004123 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 struct mii_ioctl_data *data = if_mii(ifr);
4125 int retval;
4126 uint16_t mii_reg;
4127 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004128 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004130 if (adapter->hw.media_type != e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 return -EOPNOTSUPP;
4132
4133 switch (cmd) {
4134 case SIOCGMIIPHY:
4135 data->phy_id = adapter->hw.phy_addr;
4136 break;
4137 case SIOCGMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004138 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004140 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004141 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004142 &data->val_out)) {
4143 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004145 }
4146 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 break;
4148 case SIOCSMIIREG:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004149 if (!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 return -EPERM;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004151 if (data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 return -EFAULT;
4153 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004154 spin_lock_irqsave(&adapter->stats_lock, flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004155 if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004156 mii_reg)) {
4157 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004159 }
Jeff Kirshercb764322006-03-08 17:24:12 -08004160 if (adapter->hw.phy_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 switch (data->reg_num) {
4162 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004163 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004165 if (mii_reg & MII_CR_AUTO_NEG_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 adapter->hw.autoneg = 1;
4167 adapter->hw.autoneg_advertised = 0x2F;
4168 } else {
4169 if (mii_reg & 0x40)
4170 spddplx = SPEED_1000;
4171 else if (mii_reg & 0x2000)
4172 spddplx = SPEED_100;
4173 else
4174 spddplx = SPEED_10;
4175 spddplx += (mii_reg & 0x100)
Jeff Kirshercb764322006-03-08 17:24:12 -08004176 ? DUPLEX_FULL :
4177 DUPLEX_HALF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 retval = e1000_set_spd_dplx(adapter,
4179 spddplx);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004180 if (retval) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004181 spin_unlock_irqrestore(
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004182 &adapter->stats_lock,
Malli Chilakala97876fc2005-06-17 17:40:19 -07004183 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004187 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188 e1000_down(adapter);
4189 e1000_up(adapter);
4190 } else
4191 e1000_reset(adapter);
4192 break;
4193 case M88E1000_PHY_SPEC_CTRL:
4194 case M88E1000_EXT_PHY_SPEC_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004195 if (e1000_phy_reset(&adapter->hw)) {
Malli Chilakala97876fc2005-06-17 17:40:19 -07004196 spin_unlock_irqrestore(
4197 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 break;
4201 }
4202 } else {
4203 switch (data->reg_num) {
4204 case PHY_CTRL:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004205 if (mii_reg & MII_CR_POWER_DOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 break;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004207 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 e1000_down(adapter);
4209 e1000_up(adapter);
4210 } else
4211 e1000_reset(adapter);
4212 break;
4213 }
4214 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004215 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 break;
4217 default:
4218 return -EOPNOTSUPP;
4219 }
4220 return E1000_SUCCESS;
4221}
4222
4223void
4224e1000_pci_set_mwi(struct e1000_hw *hw)
4225{
4226 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004227 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004229 if (ret_val)
Malli Chilakala26483452005-04-28 19:44:46 -07004230 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231}
4232
4233void
4234e1000_pci_clear_mwi(struct e1000_hw *hw)
4235{
4236 struct e1000_adapter *adapter = hw->back;
4237
4238 pci_clear_mwi(adapter->pdev);
4239}
4240
4241void
4242e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4243{
4244 struct e1000_adapter *adapter = hw->back;
4245
4246 pci_read_config_word(adapter->pdev, reg, value);
4247}
4248
4249void
4250e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4251{
4252 struct e1000_adapter *adapter = hw->back;
4253
4254 pci_write_config_word(adapter->pdev, reg, *value);
4255}
4256
4257uint32_t
4258e1000_io_read(struct e1000_hw *hw, unsigned long port)
4259{
4260 return inl(port);
4261}
4262
4263void
4264e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4265{
4266 outl(value, port);
4267}
4268
4269static void
4270e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4271{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004272 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 uint32_t ctrl, rctl;
4274
4275 e1000_irq_disable(adapter);
4276 adapter->vlgrp = grp;
4277
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004278 if (grp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279 /* enable VLAN tag insert/strip */
4280 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4281 ctrl |= E1000_CTRL_VME;
4282 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4283
4284 /* enable VLAN receive filtering */
4285 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4286 rctl |= E1000_RCTL_VFE;
4287 rctl &= ~E1000_RCTL_CFIEN;
4288 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004289 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290 } else {
4291 /* disable VLAN tag insert/strip */
4292 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4293 ctrl &= ~E1000_CTRL_VME;
4294 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4295
4296 /* disable VLAN filtering */
4297 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4298 rctl &= ~E1000_RCTL_VFE;
4299 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004300 if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004301 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4302 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 }
4305
4306 e1000_irq_enable(adapter);
4307}
4308
4309static void
4310e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4311{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004312 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313 uint32_t vfta, index;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004314
4315 if ((adapter->hw.mng_cookie.status &
4316 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4317 (vid == adapter->mng_vlan_id))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004318 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 /* add VID to filter table */
4320 index = (vid >> 5) & 0x7F;
4321 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4322 vfta |= (1 << (vid & 0x1F));
4323 e1000_write_vfta(&adapter->hw, index, vfta);
4324}
4325
4326static void
4327e1000_vlan_rx_kill_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;
4331
4332 e1000_irq_disable(adapter);
4333
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004334 if (adapter->vlgrp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 adapter->vlgrp->vlan_devices[vid] = NULL;
4336
4337 e1000_irq_enable(adapter);
4338
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004339 if ((adapter->hw.mng_cookie.status &
4340 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004341 (vid == adapter->mng_vlan_id)) {
4342 /* release control to f/w */
4343 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004344 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004345 }
4346
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 /* remove VID from filter table */
4348 index = (vid >> 5) & 0x7F;
4349 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4350 vfta &= ~(1 << (vid & 0x1F));
4351 e1000_write_vfta(&adapter->hw, index, vfta);
4352}
4353
4354static void
4355e1000_restore_vlan(struct e1000_adapter *adapter)
4356{
4357 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4358
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004359 if (adapter->vlgrp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 uint16_t vid;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004361 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4362 if (!adapter->vlgrp->vlan_devices[vid])
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363 continue;
4364 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4365 }
4366 }
4367}
4368
4369int
4370e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4371{
4372 adapter->hw.autoneg = 0;
4373
Malli Chilakala69213682005-06-17 17:44:20 -07004374 /* Fiber NICs only allow 1000 gbps Full duplex */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004375 if ((adapter->hw.media_type == e1000_media_type_fiber) &&
Malli Chilakala69213682005-06-17 17:44:20 -07004376 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4377 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4378 return -EINVAL;
4379 }
4380
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004381 switch (spddplx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 case SPEED_10 + DUPLEX_HALF:
4383 adapter->hw.forced_speed_duplex = e1000_10_half;
4384 break;
4385 case SPEED_10 + DUPLEX_FULL:
4386 adapter->hw.forced_speed_duplex = e1000_10_full;
4387 break;
4388 case SPEED_100 + DUPLEX_HALF:
4389 adapter->hw.forced_speed_duplex = e1000_100_half;
4390 break;
4391 case SPEED_100 + DUPLEX_FULL:
4392 adapter->hw.forced_speed_duplex = e1000_100_full;
4393 break;
4394 case SPEED_1000 + DUPLEX_FULL:
4395 adapter->hw.autoneg = 1;
4396 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4397 break;
4398 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4399 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004400 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 return -EINVAL;
4402 }
4403 return 0;
4404}
4405
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004406#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004407/* Save/restore 16 or 64 dwords of PCI config space depending on which
4408 * bus we're on (PCI(X) vs. PCI-E)
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004409 */
4410#define PCIE_CONFIG_SPACE_LEN 256
4411#define PCI_CONFIG_SPACE_LEN 64
4412static int
4413e1000_pci_save_state(struct e1000_adapter *adapter)
4414{
4415 struct pci_dev *dev = adapter->pdev;
4416 int size;
4417 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004418
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004419 if (adapter->hw.mac_type >= e1000_82571)
4420 size = PCIE_CONFIG_SPACE_LEN;
4421 else
4422 size = PCI_CONFIG_SPACE_LEN;
4423
4424 WARN_ON(adapter->config_space != NULL);
4425
4426 adapter->config_space = kmalloc(size, GFP_KERNEL);
4427 if (!adapter->config_space) {
4428 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
4429 return -ENOMEM;
4430 }
4431 for (i = 0; i < (size / 4); i++)
4432 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
4433 return 0;
4434}
4435
4436static void
4437e1000_pci_restore_state(struct e1000_adapter *adapter)
4438{
4439 struct pci_dev *dev = adapter->pdev;
4440 int size;
4441 int i;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004442
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004443 if (adapter->config_space == NULL)
4444 return;
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004445
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004446 if (adapter->hw.mac_type >= e1000_82571)
4447 size = PCIE_CONFIG_SPACE_LEN;
4448 else
4449 size = PCI_CONFIG_SPACE_LEN;
4450 for (i = 0; i < (size / 4); i++)
4451 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
4452 kfree(adapter->config_space);
4453 adapter->config_space = NULL;
4454 return;
4455}
4456#endif /* CONFIG_PM */
4457
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004459e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460{
4461 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004462 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004463 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 uint32_t wufc = adapter->wol;
Jeff Kirsher240b1712006-01-12 16:51:28 -08004465 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466
4467 netif_device_detach(netdev);
4468
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004469 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 e1000_down(adapter);
4471
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004472#ifdef CONFIG_PM
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004473 /* Implement our own version of pci_save_state(pdev) because pci-
4474 * express adapters have 256-byte config spaces. */
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004475 retval = e1000_pci_save_state(adapter);
4476 if (retval)
4477 return retval;
4478#endif
4479
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 status = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004481 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 wufc &= ~E1000_WUFC_LNKC;
4483
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004484 if (wufc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 e1000_setup_rctl(adapter);
4486 e1000_set_multi(netdev);
4487
4488 /* turn on all-multi mode if wake on multicast is enabled */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004489 if (adapter->wol & E1000_WUFC_MC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4491 rctl |= E1000_RCTL_MPE;
4492 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4493 }
4494
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004495 if (adapter->hw.mac_type >= e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4497 /* advertise wake from D3Cold */
4498 #define E1000_CTRL_ADVD3WUC 0x00100000
4499 /* phy power management enable */
4500 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4501 ctrl |= E1000_CTRL_ADVD3WUC |
4502 E1000_CTRL_EN_PHY_PWR_MGMT;
4503 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4504 }
4505
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004506 if (adapter->hw.media_type == e1000_media_type_fiber ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4508 /* keep the laser running in D3 */
4509 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4510 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4511 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4512 }
4513
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004514 /* Allow time for pending master requests to run */
4515 e1000_disable_pciex_master(&adapter->hw);
4516
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4518 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004519 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4520 if (retval)
4521 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4522 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4523 if (retval)
4524 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 } else {
4526 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4527 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004528 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4529 if (retval)
4530 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004531 retval = pci_enable_wake(pdev, PCI_D3cold, 0);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004532 if (retval)
4533 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534 }
4535
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004536 if (adapter->hw.mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 adapter->hw.media_type == e1000_media_type_copper) {
4538 manc = E1000_READ_REG(&adapter->hw, MANC);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004539 if (manc & E1000_MANC_SMBUS_EN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 manc |= E1000_MANC_ARP_EN;
4541 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004542 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4543 if (retval)
4544 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4545 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4546 if (retval)
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004547 DPRINTK(PROBE, ERR,
4548 "Error enabling D3 cold wake\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 }
4550 }
4551
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004552 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4553 * would have already happened in close and is redundant. */
4554 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004555
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004557
4558 retval = pci_set_power_state(pdev, pci_choose_state(pdev, state));
4559 if (retval)
4560 DPRINTK(PROBE, ERR, "Error in setting power state\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561
4562 return 0;
4563}
4564
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004565#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566static int
4567e1000_resume(struct pci_dev *pdev)
4568{
4569 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004570 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004571 int retval;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004572 uint32_t manc, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573
Jeff Kirsher240b1712006-01-12 16:51:28 -08004574 retval = pci_set_power_state(pdev, PCI_D0);
4575 if (retval)
4576 DPRINTK(PROBE, ERR, "Error in setting power state\n");
Jesse Brandeburg2f826652006-01-18 13:01:34 -08004577 e1000_pci_restore_state(adapter);
Malli Chilakala2b028932005-06-17 17:46:06 -07004578 ret_val = pci_enable_device(pdev);
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004579 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580
Jeff Kirsher240b1712006-01-12 16:51:28 -08004581 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4582 if (retval)
4583 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4584 retval = pci_enable_wake(pdev, PCI_D3cold, 0);
4585 if (retval)
4586 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587
4588 e1000_reset(adapter);
4589 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4590
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004591 if (netif_running(netdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 e1000_up(adapter);
4593
4594 netif_device_attach(netdev);
4595
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004596 if (adapter->hw.mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 adapter->hw.media_type == e1000_media_type_copper) {
4598 manc = E1000_READ_REG(&adapter->hw, MANC);
4599 manc &= ~(E1000_MANC_ARP_EN);
4600 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4601 }
4602
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004603 /* If the controller is 82573 and f/w is AMT, do not set
4604 * DRV_LOAD until the interface is up. For all other cases,
4605 * let the f/w know that the h/w is now under the control
4606 * of the driver. */
4607 if (adapter->hw.mac_type != e1000_82573 ||
4608 !e1000_check_mng_mode(&adapter->hw))
4609 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004610
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 return 0;
4612}
4613#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614#ifdef CONFIG_NET_POLL_CONTROLLER
4615/*
4616 * Polling 'interrupt' - used by things like netconsole to send skbs
4617 * without having to re-enable interrupts. It's not called while
4618 * the interrupt routine is executing.
4619 */
4620static void
Malli Chilakala26483452005-04-28 19:44:46 -07004621e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004623 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 disable_irq(adapter->pdev->irq);
4625 e1000_intr(adapter->pdev->irq, netdev, NULL);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004626 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004627#ifndef CONFIG_E1000_NAPI
4628 adapter->clean_rx(adapter, adapter->rx_ring);
4629#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630 enable_irq(adapter->pdev->irq);
4631}
4632#endif
4633
4634/* e1000_main.c */