blob: 41f44a3ded9a34ad026df5da4696cd2be7ed850f [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
Malli Chilakala2b028932005-06-17 17:46:06 -070032 * 6.0.58 4/20/05
33 * o Accepted ethtool cleanup patch from Stephen Hemminger
Malli Chilakala26483452005-04-28 19:44:46 -070034 * 6.0.44+ 2/15/05
35 * o applied Anton's patch to resolve tx hang in hardware
36 * o Applied Andrew Mortons patch - e1000 stops working after resume
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 */
38
39char e1000_driver_name[] = "e1000";
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010040static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#ifndef CONFIG_E1000_NAPI
42#define DRIVERNAPI
43#else
44#define DRIVERNAPI "-NAPI"
45#endif
Jeff Kirsher4ee9c022006-01-12 16:50:18 -080046#define DRV_VERSION "6.3.9-k2"DRIVERNAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -070047char e1000_driver_version[] = DRV_VERSION;
Adrian Bunk3ad2cc62005-10-30 16:53:34 +010048static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50/* e1000_pci_tbl - PCI Device ID Table
51 *
52 * Last entry must be all 0s
53 *
54 * Macro expands to...
55 * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
56 */
57static struct pci_device_id e1000_pci_tbl[] = {
58 INTEL_E1000_ETHERNET_DEVICE(0x1000),
59 INTEL_E1000_ETHERNET_DEVICE(0x1001),
60 INTEL_E1000_ETHERNET_DEVICE(0x1004),
61 INTEL_E1000_ETHERNET_DEVICE(0x1008),
62 INTEL_E1000_ETHERNET_DEVICE(0x1009),
63 INTEL_E1000_ETHERNET_DEVICE(0x100C),
64 INTEL_E1000_ETHERNET_DEVICE(0x100D),
65 INTEL_E1000_ETHERNET_DEVICE(0x100E),
66 INTEL_E1000_ETHERNET_DEVICE(0x100F),
67 INTEL_E1000_ETHERNET_DEVICE(0x1010),
68 INTEL_E1000_ETHERNET_DEVICE(0x1011),
69 INTEL_E1000_ETHERNET_DEVICE(0x1012),
70 INTEL_E1000_ETHERNET_DEVICE(0x1013),
71 INTEL_E1000_ETHERNET_DEVICE(0x1014),
72 INTEL_E1000_ETHERNET_DEVICE(0x1015),
73 INTEL_E1000_ETHERNET_DEVICE(0x1016),
74 INTEL_E1000_ETHERNET_DEVICE(0x1017),
75 INTEL_E1000_ETHERNET_DEVICE(0x1018),
76 INTEL_E1000_ETHERNET_DEVICE(0x1019),
Malli Chilakala26483452005-04-28 19:44:46 -070077 INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 INTEL_E1000_ETHERNET_DEVICE(0x101D),
79 INTEL_E1000_ETHERNET_DEVICE(0x101E),
80 INTEL_E1000_ETHERNET_DEVICE(0x1026),
81 INTEL_E1000_ETHERNET_DEVICE(0x1027),
82 INTEL_E1000_ETHERNET_DEVICE(0x1028),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040083 INTEL_E1000_ETHERNET_DEVICE(0x105E),
84 INTEL_E1000_ETHERNET_DEVICE(0x105F),
85 INTEL_E1000_ETHERNET_DEVICE(0x1060),
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 INTEL_E1000_ETHERNET_DEVICE(0x1075),
87 INTEL_E1000_ETHERNET_DEVICE(0x1076),
88 INTEL_E1000_ETHERNET_DEVICE(0x1077),
89 INTEL_E1000_ETHERNET_DEVICE(0x1078),
90 INTEL_E1000_ETHERNET_DEVICE(0x1079),
91 INTEL_E1000_ETHERNET_DEVICE(0x107A),
92 INTEL_E1000_ETHERNET_DEVICE(0x107B),
93 INTEL_E1000_ETHERNET_DEVICE(0x107C),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -040094 INTEL_E1000_ETHERNET_DEVICE(0x107D),
95 INTEL_E1000_ETHERNET_DEVICE(0x107E),
96 INTEL_E1000_ETHERNET_DEVICE(0x107F),
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 INTEL_E1000_ETHERNET_DEVICE(0x108A),
Malli Chilakala26483452005-04-28 19:44:46 -070098 INTEL_E1000_ETHERNET_DEVICE(0x108B),
99 INTEL_E1000_ETHERNET_DEVICE(0x108C),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400100 INTEL_E1000_ETHERNET_DEVICE(0x109A),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 /* required last entry */
102 {0,}
103};
104
105MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
106
107int e1000_up(struct e1000_adapter *adapter);
108void e1000_down(struct e1000_adapter *adapter);
109void e1000_reset(struct e1000_adapter *adapter);
110int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400111int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
112int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
113void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
114void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100115static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
116 struct e1000_tx_ring *txdr);
117static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
118 struct e1000_rx_ring *rxdr);
119static void e1000_free_tx_resources(struct e1000_adapter *adapter,
120 struct e1000_tx_ring *tx_ring);
121static void e1000_free_rx_resources(struct e1000_adapter *adapter,
122 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123void e1000_update_stats(struct e1000_adapter *adapter);
124
125/* Local Function Prototypes */
126
127static int e1000_init_module(void);
128static void e1000_exit_module(void);
129static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
130static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400131static int e1000_alloc_queues(struct e1000_adapter *adapter);
132#ifdef CONFIG_E1000_MQ
133static void e1000_setup_queue_mapping(struct e1000_adapter *adapter);
134#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135static int e1000_sw_init(struct e1000_adapter *adapter);
136static int e1000_open(struct net_device *netdev);
137static int e1000_close(struct net_device *netdev);
138static void e1000_configure_tx(struct e1000_adapter *adapter);
139static void e1000_configure_rx(struct e1000_adapter *adapter);
140static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400141static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
142static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
143static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
144 struct e1000_tx_ring *tx_ring);
145static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
146 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147static void e1000_set_multi(struct net_device *netdev);
148static void e1000_update_phy_info(unsigned long data);
149static void e1000_watchdog(unsigned long data);
150static void e1000_watchdog_task(struct e1000_adapter *adapter);
151static void e1000_82547_tx_fifo_stall(unsigned long data);
152static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
153static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
154static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
155static int e1000_set_mac(struct net_device *netdev, void *p);
156static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400157static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
158 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400160static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400162 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700164static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400165 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700166 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400168static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
169 struct e1000_rx_ring *rx_ring);
170static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
171 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400173static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
174 struct e1000_rx_ring *rx_ring);
175static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
176 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
178static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
179 int cmd);
180void e1000_set_ethtool_ops(struct net_device *netdev);
181static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
182static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
183static void e1000_tx_timeout(struct net_device *dev);
184static void e1000_tx_timeout_task(struct net_device *dev);
185static void e1000_smartspeed(struct e1000_adapter *adapter);
186static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
187 struct sk_buff *skb);
188
189static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
190static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
191static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
192static void e1000_restore_vlan(struct e1000_adapter *adapter);
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194#ifdef CONFIG_PM
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700195static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196static int e1000_resume(struct pci_dev *pdev);
197#endif
198
199#ifdef CONFIG_NET_POLL_CONTROLLER
200/* for netdump / net console */
201static void e1000_netpoll (struct net_device *netdev);
202#endif
203
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400204#ifdef CONFIG_E1000_MQ
205/* for multiple Rx queues */
206void e1000_rx_schedule(void *data);
207#endif
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/* Exported from other modules */
210
211extern void e1000_check_options(struct e1000_adapter *adapter);
212
213static struct pci_driver e1000_driver = {
214 .name = e1000_driver_name,
215 .id_table = e1000_pci_tbl,
216 .probe = e1000_probe,
217 .remove = __devexit_p(e1000_remove),
218 /* Power Managment Hooks */
219#ifdef CONFIG_PM
220 .suspend = e1000_suspend,
221 .resume = e1000_resume
222#endif
223};
224
225MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
226MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
227MODULE_LICENSE("GPL");
228MODULE_VERSION(DRV_VERSION);
229
230static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
231module_param(debug, int, 0);
232MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
233
234/**
235 * e1000_init_module - Driver Registration Routine
236 *
237 * e1000_init_module is the first routine called when the driver is
238 * loaded. All it does is register with the PCI subsystem.
239 **/
240
241static int __init
242e1000_init_module(void)
243{
244 int ret;
245 printk(KERN_INFO "%s - version %s\n",
246 e1000_driver_string, e1000_driver_version);
247
248 printk(KERN_INFO "%s\n", e1000_copyright);
249
250 ret = pci_module_init(&e1000_driver);
Tony Luck8b378de2005-07-28 01:07:38 -0700251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return ret;
253}
254
255module_init(e1000_init_module);
256
257/**
258 * e1000_exit_module - Driver Exit Cleanup Routine
259 *
260 * e1000_exit_module is called just before the driver is removed
261 * from memory.
262 **/
263
264static void __exit
265e1000_exit_module(void)
266{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 pci_unregister_driver(&e1000_driver);
268}
269
270module_exit(e1000_exit_module);
271
272/**
273 * e1000_irq_disable - Mask off interrupt generation on the NIC
274 * @adapter: board private structure
275 **/
276
277static inline void
278e1000_irq_disable(struct e1000_adapter *adapter)
279{
280 atomic_inc(&adapter->irq_sem);
281 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
282 E1000_WRITE_FLUSH(&adapter->hw);
283 synchronize_irq(adapter->pdev->irq);
284}
285
286/**
287 * e1000_irq_enable - Enable default interrupt generation settings
288 * @adapter: board private structure
289 **/
290
291static inline void
292e1000_irq_enable(struct e1000_adapter *adapter)
293{
294 if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
295 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
296 E1000_WRITE_FLUSH(&adapter->hw);
297 }
298}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100299
300static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700301e1000_update_mng_vlan(struct e1000_adapter *adapter)
302{
303 struct net_device *netdev = adapter->netdev;
304 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
305 uint16_t old_vid = adapter->mng_vlan_id;
306 if(adapter->vlgrp) {
307 if(!adapter->vlgrp->vlan_devices[vid]) {
308 if(adapter->hw.mng_cookie.status &
309 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
310 e1000_vlan_rx_add_vid(netdev, vid);
311 adapter->mng_vlan_id = vid;
312 } else
313 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
314
315 if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
316 (vid != old_vid) &&
317 !adapter->vlgrp->vlan_devices[old_vid])
318 e1000_vlan_rx_kill_vid(netdev, old_vid);
319 }
320 }
321}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800322
323/**
324 * e1000_release_hw_control - release control of the h/w to f/w
325 * @adapter: address of board private structure
326 *
327 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
328 * For ASF and Pass Through versions of f/w this means that the
329 * driver is no longer loaded. For AMT version (only with 82573) i
330 * of the f/w this means that the netowrk i/f is closed.
331 *
332 **/
333
334static inline void
335e1000_release_hw_control(struct e1000_adapter *adapter)
336{
337 uint32_t ctrl_ext;
338 uint32_t swsm;
339
340 /* Let firmware taken over control of h/w */
341 switch (adapter->hw.mac_type) {
342 case e1000_82571:
343 case e1000_82572:
344 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
345 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
346 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
347 break;
348 case e1000_82573:
349 swsm = E1000_READ_REG(&adapter->hw, SWSM);
350 E1000_WRITE_REG(&adapter->hw, SWSM,
351 swsm & ~E1000_SWSM_DRV_LOAD);
352 default:
353 break;
354 }
355}
356
357/**
358 * e1000_get_hw_control - get control of the h/w from f/w
359 * @adapter: address of board private structure
360 *
361 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
362 * For ASF and Pass Through versions of f/w this means that
363 * the driver is loaded. For AMT version (only with 82573)
364 * of the f/w this means that the netowrk i/f is open.
365 *
366 **/
367
368static inline void
369e1000_get_hw_control(struct e1000_adapter *adapter)
370{
371 uint32_t ctrl_ext;
372 uint32_t swsm;
373 /* Let firmware know the driver has taken over */
374 switch (adapter->hw.mac_type) {
375 case e1000_82571:
376 case e1000_82572:
377 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
378 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
379 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
380 break;
381 case e1000_82573:
382 swsm = E1000_READ_REG(&adapter->hw, SWSM);
383 E1000_WRITE_REG(&adapter->hw, SWSM,
384 swsm | E1000_SWSM_DRV_LOAD);
385 break;
386 default:
387 break;
388 }
389}
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391int
392e1000_up(struct e1000_adapter *adapter)
393{
394 struct net_device *netdev = adapter->netdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400395 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 /* hardware has been reset, we need to reload some things */
398
399 /* Reset the PHY if it was previously powered down */
400 if(adapter->hw.media_type == e1000_media_type_copper) {
401 uint16_t mii_reg;
402 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
403 if(mii_reg & MII_CR_POWER_DOWN)
404 e1000_phy_reset(&adapter->hw);
405 }
406
407 e1000_set_multi(netdev);
408
409 e1000_restore_vlan(adapter);
410
411 e1000_configure_tx(adapter);
412 e1000_setup_rctl(adapter);
413 e1000_configure_rx(adapter);
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800414 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400415 adapter->alloc_rx_buf(adapter, &adapter->rx_ring[i]);
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700418#ifdef CONFIG_PCI_MSI
419 if(adapter->hw.mac_type > e1000_82547_rev_2) {
420 adapter->have_msi = TRUE;
421 if((err = pci_enable_msi(adapter->pdev))) {
422 DPRINTK(PROBE, ERR,
423 "Unable to allocate MSI interrupt Error: %d\n", err);
424 adapter->have_msi = FALSE;
425 }
426 }
427#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 if((err = request_irq(adapter->pdev->irq, &e1000_intr,
429 SA_SHIRQ | SA_SAMPLE_RANDOM,
Malli Chilakala26483452005-04-28 19:44:46 -0700430 netdev->name, netdev))) {
431 DPRINTK(PROBE, ERR,
432 "Unable to allocate interrupt Error: %d\n", err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 return err;
Malli Chilakala26483452005-04-28 19:44:46 -0700434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800436#ifdef CONFIG_E1000_MQ
437 e1000_setup_queue_mapping(adapter);
438#endif
439
440 adapter->tx_queue_len = netdev->tx_queue_len;
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 mod_timer(&adapter->watchdog_timer, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444#ifdef CONFIG_E1000_NAPI
445 netif_poll_enable(netdev);
446#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700447 e1000_irq_enable(adapter);
448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 return 0;
450}
451
452void
453e1000_down(struct e1000_adapter *adapter)
454{
455 struct net_device *netdev = adapter->netdev;
Jeff Kirsher57128192006-01-12 16:50:28 -0800456 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
457 e1000_check_mng_mode(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 e1000_irq_disable(adapter);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400460#ifdef CONFIG_E1000_MQ
461 while (atomic_read(&adapter->rx_sched_call_data.count) != 0);
462#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 free_irq(adapter->pdev->irq, netdev);
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700464#ifdef CONFIG_PCI_MSI
465 if(adapter->hw.mac_type > e1000_82547_rev_2 &&
466 adapter->have_msi == TRUE)
467 pci_disable_msi(adapter->pdev);
468#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 del_timer_sync(&adapter->tx_fifo_stall_timer);
470 del_timer_sync(&adapter->watchdog_timer);
471 del_timer_sync(&adapter->phy_info_timer);
472
473#ifdef CONFIG_E1000_NAPI
474 netif_poll_disable(netdev);
475#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800476 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 adapter->link_speed = 0;
478 adapter->link_duplex = 0;
479 netif_carrier_off(netdev);
480 netif_stop_queue(netdev);
481
482 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400483 e1000_clean_all_tx_rings(adapter);
484 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Jeff Kirsher57128192006-01-12 16:50:28 -0800486 /* Power down the PHY so no link is implied when interface is down *
487 * The PHY cannot be powered down if any of the following is TRUE *
488 * (a) WoL is enabled
489 * (b) AMT is active
490 * (c) SoL/IDER session is active */
491 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700492 adapter->hw.media_type == e1000_media_type_copper &&
Jeff Kirsher57128192006-01-12 16:50:28 -0800493 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
494 !mng_mode_enabled &&
495 !e1000_check_phy_reset_block(&adapter->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 uint16_t mii_reg;
497 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
498 mii_reg |= MII_CR_POWER_DOWN;
499 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
Malli Chilakala4e48a2b2005-04-28 19:39:53 -0700500 mdelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502}
503
504void
505e1000_reset(struct e1000_adapter *adapter)
506{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700507 uint32_t pba, manc;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700508 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 /* Repartition Pba for greater than 9k mtu
511 * To take effect CTRL.RST is required.
512 */
513
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700514 switch (adapter->hw.mac_type) {
515 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700516 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700517 pba = E1000_PBA_30K;
518 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400519 case e1000_82571:
520 case e1000_82572:
521 pba = E1000_PBA_38K;
522 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700523 case e1000_82573:
524 pba = E1000_PBA_12K;
525 break;
526 default:
527 pba = E1000_PBA_48K;
528 break;
529 }
530
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700531 if((adapter->hw.mac_type != e1000_82573) &&
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800532 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700533 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700534
535
536 if(adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 adapter->tx_fifo_head = 0;
538 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
539 adapter->tx_fifo_size =
540 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
541 atomic_set(&adapter->tx_fifo_stall, 0);
542 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 E1000_WRITE_REG(&adapter->hw, PBA, pba);
545
546 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800547 /* Set the FC high water mark to 90% of the FIFO size.
548 * Required to clear last 3 LSB */
549 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
550
551 adapter->hw.fc_high_water = fc_high_water_mark;
552 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
554 adapter->hw.fc_send_xon = 1;
555 adapter->hw.fc = adapter->hw.original_fc;
556
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700557 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 e1000_reset_hw(&adapter->hw);
559 if(adapter->hw.mac_type >= e1000_82544)
560 E1000_WRITE_REG(&adapter->hw, WUC, 0);
561 if(e1000_init_hw(&adapter->hw))
562 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700563 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
565 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
566
567 e1000_reset_adaptive(&adapter->hw);
568 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700569 if (adapter->en_mng_pt) {
570 manc = E1000_READ_REG(&adapter->hw, MANC);
571 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
572 E1000_WRITE_REG(&adapter->hw, MANC, manc);
573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
576/**
577 * e1000_probe - Device Initialization Routine
578 * @pdev: PCI device information struct
579 * @ent: entry in e1000_pci_tbl
580 *
581 * Returns 0 on success, negative on failure
582 *
583 * e1000_probe initializes an adapter identified by a pci_dev structure.
584 * The OS initialization, configuring of the adapter private structure,
585 * and a hardware reset occur.
586 **/
587
588static int __devinit
589e1000_probe(struct pci_dev *pdev,
590 const struct pci_device_id *ent)
591{
592 struct net_device *netdev;
593 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700594 unsigned long mmio_start, mmio_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 static int cards_found = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700597 int i, err, pci_using_dac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 uint16_t eeprom_data;
599 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 if((err = pci_enable_device(pdev)))
601 return err;
602
603 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
604 pci_using_dac = 1;
605 } else {
606 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
607 E1000_ERR("No usable DMA configuration, aborting\n");
608 return err;
609 }
610 pci_using_dac = 0;
611 }
612
613 if((err = pci_request_regions(pdev, e1000_driver_name)))
614 return err;
615
616 pci_set_master(pdev);
617
618 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
619 if(!netdev) {
620 err = -ENOMEM;
621 goto err_alloc_etherdev;
622 }
623
624 SET_MODULE_OWNER(netdev);
625 SET_NETDEV_DEV(netdev, &pdev->dev);
626
627 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700628 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 adapter->netdev = netdev;
630 adapter->pdev = pdev;
631 adapter->hw.back = adapter;
632 adapter->msg_enable = (1 << debug) - 1;
633
634 mmio_start = pci_resource_start(pdev, BAR_0);
635 mmio_len = pci_resource_len(pdev, BAR_0);
636
637 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
638 if(!adapter->hw.hw_addr) {
639 err = -EIO;
640 goto err_ioremap;
641 }
642
643 for(i = BAR_1; i <= BAR_5; i++) {
644 if(pci_resource_len(pdev, i) == 0)
645 continue;
646 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
647 adapter->hw.io_base = pci_resource_start(pdev, i);
648 break;
649 }
650 }
651
652 netdev->open = &e1000_open;
653 netdev->stop = &e1000_close;
654 netdev->hard_start_xmit = &e1000_xmit_frame;
655 netdev->get_stats = &e1000_get_stats;
656 netdev->set_multicast_list = &e1000_set_multi;
657 netdev->set_mac_address = &e1000_set_mac;
658 netdev->change_mtu = &e1000_change_mtu;
659 netdev->do_ioctl = &e1000_ioctl;
660 e1000_set_ethtool_ops(netdev);
661 netdev->tx_timeout = &e1000_tx_timeout;
662 netdev->watchdog_timeo = 5 * HZ;
663#ifdef CONFIG_E1000_NAPI
664 netdev->poll = &e1000_clean;
665 netdev->weight = 64;
666#endif
667 netdev->vlan_rx_register = e1000_vlan_rx_register;
668 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
669 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
670#ifdef CONFIG_NET_POLL_CONTROLLER
671 netdev->poll_controller = e1000_netpoll;
672#endif
673 strcpy(netdev->name, pci_name(pdev));
674
675 netdev->mem_start = mmio_start;
676 netdev->mem_end = mmio_start + mmio_len;
677 netdev->base_addr = adapter->hw.io_base;
678
679 adapter->bd_number = cards_found;
680
681 /* setup the private structure */
682
683 if((err = e1000_sw_init(adapter)))
684 goto err_sw_init;
685
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700686 if((err = e1000_check_phy_reset_block(&adapter->hw)))
687 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 if(adapter->hw.mac_type >= e1000_82543) {
690 netdev->features = NETIF_F_SG |
691 NETIF_F_HW_CSUM |
692 NETIF_F_HW_VLAN_TX |
693 NETIF_F_HW_VLAN_RX |
694 NETIF_F_HW_VLAN_FILTER;
695 }
696
697#ifdef NETIF_F_TSO
698 if((adapter->hw.mac_type >= e1000_82544) &&
699 (adapter->hw.mac_type != e1000_82547))
700 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700701
702#ifdef NETIF_F_TSO_IPV6
703 if(adapter->hw.mac_type > e1000_82547_rev_2)
704 netdev->features |= NETIF_F_TSO_IPV6;
705#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706#endif
707 if(pci_using_dac)
708 netdev->features |= NETIF_F_HIGHDMA;
709
710 /* hard_start_xmit is safe against parallel locking */
711 netdev->features |= NETIF_F_LLTX;
712
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700713 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 /* before reading the EEPROM, reset the controller to
716 * put the device in a known good starting state */
717
718 e1000_reset_hw(&adapter->hw);
719
720 /* make sure the EEPROM is good */
721
722 if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
723 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
724 err = -EIO;
725 goto err_eeprom;
726 }
727
728 /* copy the MAC address out of the EEPROM */
729
Malli Chilakala26483452005-04-28 19:44:46 -0700730 if(e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
732 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400733 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
John W. Linville9beb0ac2005-09-12 10:48:55 -0400735 if(!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
737 err = -EIO;
738 goto err_eeprom;
739 }
740
741 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
742
743 e1000_get_bus_info(&adapter->hw);
744
745 init_timer(&adapter->tx_fifo_stall_timer);
746 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
747 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
748
749 init_timer(&adapter->watchdog_timer);
750 adapter->watchdog_timer.function = &e1000_watchdog;
751 adapter->watchdog_timer.data = (unsigned long) adapter;
752
753 INIT_WORK(&adapter->watchdog_task,
754 (void (*)(void *))e1000_watchdog_task, adapter);
755
756 init_timer(&adapter->phy_info_timer);
757 adapter->phy_info_timer.function = &e1000_update_phy_info;
758 adapter->phy_info_timer.data = (unsigned long) adapter;
759
760 INIT_WORK(&adapter->tx_timeout_task,
761 (void (*)(void *))e1000_tx_timeout_task, netdev);
762
763 /* we're going to reset, so assume we have no link for now */
764
765 netif_carrier_off(netdev);
766 netif_stop_queue(netdev);
767
768 e1000_check_options(adapter);
769
770 /* Initial Wake on LAN setting
771 * If APM wake is enabled in the EEPROM,
772 * enable the ACPI Magic Packet filter
773 */
774
775 switch(adapter->hw.mac_type) {
776 case e1000_82542_rev2_0:
777 case e1000_82542_rev2_1:
778 case e1000_82543:
779 break;
780 case e1000_82544:
781 e1000_read_eeprom(&adapter->hw,
782 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
783 eeprom_apme_mask = E1000_EEPROM_82544_APM;
784 break;
785 case e1000_82546:
786 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500787 case e1000_82571:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 if((E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
789 && (adapter->hw.media_type == e1000_media_type_copper)) {
790 e1000_read_eeprom(&adapter->hw,
791 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
792 break;
793 }
794 /* Fall Through */
795 default:
796 e1000_read_eeprom(&adapter->hw,
797 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
798 break;
799 }
800 if(eeprom_data & eeprom_apme_mask)
801 adapter->wol |= E1000_WUFC_MAG;
802
803 /* reset the hardware with the new settings */
804 e1000_reset(adapter);
805
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800806 /* If the controller is 82573 and f/w is AMT, do not set
807 * DRV_LOAD until the interface is up. For all other cases,
808 * let the f/w know that the h/w is now under the control
809 * of the driver. */
810 if (adapter->hw.mac_type != e1000_82573 ||
811 !e1000_check_mng_mode(&adapter->hw))
812 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 strcpy(netdev->name, "eth%d");
815 if((err = register_netdev(netdev)))
816 goto err_register;
817
818 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
819
820 cards_found++;
821 return 0;
822
823err_register:
824err_sw_init:
825err_eeprom:
826 iounmap(adapter->hw.hw_addr);
827err_ioremap:
828 free_netdev(netdev);
829err_alloc_etherdev:
830 pci_release_regions(pdev);
831 return err;
832}
833
834/**
835 * e1000_remove - Device Removal Routine
836 * @pdev: PCI device information struct
837 *
838 * e1000_remove is called by the PCI subsystem to alert the driver
839 * that it should release a PCI device. The could be caused by a
840 * Hot-Plug event, or because the driver is going to be removed from
841 * memory.
842 **/
843
844static void __devexit
845e1000_remove(struct pci_dev *pdev)
846{
847 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700848 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800849 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400850#ifdef CONFIG_E1000_NAPI
851 int i;
852#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Jeff Garzikbe2b28e2005-10-04 07:13:43 -0400854 flush_scheduled_work();
855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 if(adapter->hw.mac_type >= e1000_82540 &&
857 adapter->hw.media_type == e1000_media_type_copper) {
858 manc = E1000_READ_REG(&adapter->hw, MANC);
859 if(manc & E1000_MANC_SMBUS_EN) {
860 manc |= E1000_MANC_ARP_EN;
861 E1000_WRITE_REG(&adapter->hw, MANC, manc);
862 }
863 }
864
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800865 /* Release control of h/w to f/w. If f/w is AMT enabled, this
866 * would have already happened in close and is redundant. */
867 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400870#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800871 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400872 __dev_put(&adapter->polling_netdev[i]);
873#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700875 if(!e1000_check_phy_reset_block(&adapter->hw))
876 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400878 kfree(adapter->tx_ring);
879 kfree(adapter->rx_ring);
880#ifdef CONFIG_E1000_NAPI
881 kfree(adapter->polling_netdev);
882#endif
883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 iounmap(adapter->hw.hw_addr);
885 pci_release_regions(pdev);
886
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400887#ifdef CONFIG_E1000_MQ
888 free_percpu(adapter->cpu_netdev);
889 free_percpu(adapter->cpu_tx_ring);
890#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 free_netdev(netdev);
892
893 pci_disable_device(pdev);
894}
895
896/**
897 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
898 * @adapter: board private structure to initialize
899 *
900 * e1000_sw_init initializes the Adapter private data structure.
901 * Fields are initialized based on PCI device information and
902 * OS network device settings (MTU size).
903 **/
904
905static int __devinit
906e1000_sw_init(struct e1000_adapter *adapter)
907{
908 struct e1000_hw *hw = &adapter->hw;
909 struct net_device *netdev = adapter->netdev;
910 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400911#ifdef CONFIG_E1000_NAPI
912 int i;
913#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 /* PCI config space info */
916
917 hw->vendor_id = pdev->vendor;
918 hw->device_id = pdev->device;
919 hw->subsystem_vendor_id = pdev->subsystem_vendor;
920 hw->subsystem_id = pdev->subsystem_device;
921
922 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
923
924 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
925
926 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700927 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 hw->max_frame_size = netdev->mtu +
929 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
930 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
931
932 /* identify the MAC */
933
934 if(e1000_set_mac_type(hw)) {
935 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
936 return -EIO;
937 }
938
939 /* initialize eeprom parameters */
940
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700941 if(e1000_init_eeprom_params(hw)) {
942 E1000_ERR("EEPROM initialization failed\n");
943 return -EIO;
944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 switch(hw->mac_type) {
947 default:
948 break;
949 case e1000_82541:
950 case e1000_82547:
951 case e1000_82541_rev_2:
952 case e1000_82547_rev_2:
953 hw->phy_init_script = 1;
954 break;
955 }
956
957 e1000_set_media_type(hw);
958
959 hw->wait_autoneg_complete = FALSE;
960 hw->tbi_compatibility_en = TRUE;
961 hw->adaptive_ifs = TRUE;
962
963 /* Copper options */
964
965 if(hw->media_type == e1000_media_type_copper) {
966 hw->mdix = AUTO_ALL_MODES;
967 hw->disable_polarity_correction = FALSE;
968 hw->master_slave = E1000_MASTER_SLAVE;
969 }
970
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400971#ifdef CONFIG_E1000_MQ
972 /* Number of supported queues */
973 switch (hw->mac_type) {
974 case e1000_82571:
975 case e1000_82572:
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800976 /* These controllers support 2 tx queues, but with a single
977 * qdisc implementation, multiple tx queues aren't quite as
978 * interesting. If we can find a logical way of mapping
979 * flows to a queue, then perhaps we can up the num_tx_queue
980 * count back to its default. Until then, we run the risk of
981 * terrible performance due to SACK overload. */
982 adapter->num_tx_queues = 1;
983 adapter->num_rx_queues = 2;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400984 break;
985 default:
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800986 adapter->num_tx_queues = 1;
987 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400988 break;
989 }
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800990 adapter->num_rx_queues = min(adapter->num_rx_queues, num_online_cpus());
991 adapter->num_tx_queues = min(adapter->num_tx_queues, num_online_cpus());
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800992 DPRINTK(DRV, INFO, "Multiqueue Enabled: Rx Queue count = %u %s\n",
993 adapter->num_rx_queues,
994 ((adapter->num_rx_queues == 1)
995 ? ((num_online_cpus() > 1)
996 ? "(due to unsupported feature in current adapter)"
997 : "(due to unsupported system configuration)")
998 : ""));
999 DPRINTK(DRV, INFO, "Multiqueue Enabled: Tx Queue count = %u\n",
1000 adapter->num_tx_queues);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001001#else
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001002 adapter->num_tx_queues = 1;
1003 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001004#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001005
1006 if (e1000_alloc_queues(adapter)) {
1007 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1008 return -ENOMEM;
1009 }
1010
1011#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001012 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001013 adapter->polling_netdev[i].priv = adapter;
1014 adapter->polling_netdev[i].poll = &e1000_clean;
1015 adapter->polling_netdev[i].weight = 64;
1016 dev_hold(&adapter->polling_netdev[i]);
1017 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1018 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001019 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001020#endif
1021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 atomic_set(&adapter->irq_sem, 1);
1023 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025 return 0;
1026}
1027
1028/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001029 * e1000_alloc_queues - Allocate memory for all rings
1030 * @adapter: board private structure to initialize
1031 *
1032 * We allocate one ring per queue at run-time since we don't know the
1033 * number of queues at compile-time. The polling_netdev array is
1034 * intended for Multiqueue, but should work fine with a single queue.
1035 **/
1036
1037static int __devinit
1038e1000_alloc_queues(struct e1000_adapter *adapter)
1039{
1040 int size;
1041
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001042 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001043 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1044 if (!adapter->tx_ring)
1045 return -ENOMEM;
1046 memset(adapter->tx_ring, 0, size);
1047
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001048 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001049 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1050 if (!adapter->rx_ring) {
1051 kfree(adapter->tx_ring);
1052 return -ENOMEM;
1053 }
1054 memset(adapter->rx_ring, 0, size);
1055
1056#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001057 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001058 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1059 if (!adapter->polling_netdev) {
1060 kfree(adapter->tx_ring);
1061 kfree(adapter->rx_ring);
1062 return -ENOMEM;
1063 }
1064 memset(adapter->polling_netdev, 0, size);
1065#endif
1066
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001067#ifdef CONFIG_E1000_MQ
1068 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1069 adapter->rx_sched_call_data.info = adapter->netdev;
1070
1071 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1072 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1073#endif
1074
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001075 return E1000_SUCCESS;
1076}
1077
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001078#ifdef CONFIG_E1000_MQ
1079static void __devinit
1080e1000_setup_queue_mapping(struct e1000_adapter *adapter)
1081{
1082 int i, cpu;
1083
1084 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1085 adapter->rx_sched_call_data.info = adapter->netdev;
1086 cpus_clear(adapter->rx_sched_call_data.cpumask);
1087
1088 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1089 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1090
1091 lock_cpu_hotplug();
1092 i = 0;
1093 for_each_online_cpu(cpu) {
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001094 *per_cpu_ptr(adapter->cpu_tx_ring, cpu) = &adapter->tx_ring[i % adapter->num_tx_queues];
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001095 /* This is incomplete because we'd like to assign separate
1096 * physical cpus to these netdev polling structures and
1097 * avoid saturating a subset of cpus.
1098 */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001099 if (i < adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001100 *per_cpu_ptr(adapter->cpu_netdev, cpu) = &adapter->polling_netdev[i];
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001101 adapter->rx_ring[i].cpu = cpu;
1102 cpu_set(cpu, adapter->cpumask);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001103 } else
1104 *per_cpu_ptr(adapter->cpu_netdev, cpu) = NULL;
1105
1106 i++;
1107 }
1108 unlock_cpu_hotplug();
1109}
1110#endif
1111
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001112/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 * e1000_open - Called when a network interface is made active
1114 * @netdev: network interface device structure
1115 *
1116 * Returns 0 on success, negative value on failure
1117 *
1118 * The open entry point is called when a network interface is made
1119 * active by the system (IFF_UP). At this point all resources needed
1120 * for transmit and receive operations are allocated, the interrupt
1121 * handler is registered with the OS, the watchdog timer is started,
1122 * and the stack is notified that the interface is ready.
1123 **/
1124
1125static int
1126e1000_open(struct net_device *netdev)
1127{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001128 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 int err;
1130
1131 /* allocate transmit descriptors */
1132
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001133 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 goto err_setup_tx;
1135
1136 /* allocate receive descriptors */
1137
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001138 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 goto err_setup_rx;
1140
1141 if((err = e1000_up(adapter)))
1142 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001143 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1144 if((adapter->hw.mng_cookie.status &
1145 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1146 e1000_update_mng_vlan(adapter);
1147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001149 /* If AMT is enabled, let the firmware know that the network
1150 * interface is now open */
1151 if (adapter->hw.mac_type == e1000_82573 &&
1152 e1000_check_mng_mode(&adapter->hw))
1153 e1000_get_hw_control(adapter);
1154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 return E1000_SUCCESS;
1156
1157err_up:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001158 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001160 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161err_setup_tx:
1162 e1000_reset(adapter);
1163
1164 return err;
1165}
1166
1167/**
1168 * e1000_close - Disables a network interface
1169 * @netdev: network interface device structure
1170 *
1171 * Returns 0, this is not allowed to fail
1172 *
1173 * The close entry point is called when an interface is de-activated
1174 * by the OS. The hardware is still under the drivers control, but
1175 * needs to be disabled. A global MAC reset is issued to stop the
1176 * hardware, and all transmit and receive resources are freed.
1177 **/
1178
1179static int
1180e1000_close(struct net_device *netdev)
1181{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001182 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184 e1000_down(adapter);
1185
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001186 e1000_free_all_tx_resources(adapter);
1187 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001189 if((adapter->hw.mng_cookie.status &
1190 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1191 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1192 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001193
1194 /* If AMT is enabled, let the firmware know that the network
1195 * interface is now closed */
1196 if (adapter->hw.mac_type == e1000_82573 &&
1197 e1000_check_mng_mode(&adapter->hw))
1198 e1000_release_hw_control(adapter);
1199
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 return 0;
1201}
1202
1203/**
1204 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1205 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001206 * @start: address of beginning of memory
1207 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 **/
1209static inline boolean_t
1210e1000_check_64k_bound(struct e1000_adapter *adapter,
1211 void *start, unsigned long len)
1212{
1213 unsigned long begin = (unsigned long) start;
1214 unsigned long end = begin + len;
1215
Malli Chilakala26483452005-04-28 19:44:46 -07001216 /* First rev 82545 and 82546 need to not allow any memory
1217 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001219 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1221 }
1222
1223 return TRUE;
1224}
1225
1226/**
1227 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1228 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001229 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 *
1231 * Return 0 on success, negative on failure
1232 **/
1233
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001234static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001235e1000_setup_tx_resources(struct e1000_adapter *adapter,
1236 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 struct pci_dev *pdev = adapter->pdev;
1239 int size;
1240
1241 size = sizeof(struct e1000_buffer) * txdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001242
1243 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 if(!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001245 DPRINTK(PROBE, ERR,
1246 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 return -ENOMEM;
1248 }
1249 memset(txdr->buffer_info, 0, size);
1250
1251 /* round up to nearest 4K */
1252
1253 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1254 E1000_ROUNDUP(txdr->size, 4096);
1255
1256 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1257 if(!txdr->desc) {
1258setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001260 DPRINTK(PROBE, ERR,
1261 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 return -ENOMEM;
1263 }
1264
Malli Chilakala26483452005-04-28 19:44:46 -07001265 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1267 void *olddesc = txdr->desc;
1268 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001269 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1270 "at %p\n", txdr->size, txdr->desc);
1271 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 if(!txdr->desc) {
Malli Chilakala26483452005-04-28 19:44:46 -07001274 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1276 goto setup_tx_desc_die;
1277 }
1278
1279 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1280 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001281 pci_free_consistent(pdev, txdr->size, txdr->desc,
1282 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1284 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001285 "Unable to allocate aligned memory "
1286 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 vfree(txdr->buffer_info);
1288 return -ENOMEM;
1289 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001290 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1292 }
1293 }
1294 memset(txdr->desc, 0, txdr->size);
1295
1296 txdr->next_to_use = 0;
1297 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001298 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
1300 return 0;
1301}
1302
1303/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001304 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1305 * (Descriptors) for all queues
1306 * @adapter: board private structure
1307 *
1308 * If this function returns with an error, then it's possible one or
1309 * more of the rings is populated (while the rest are not). It is the
1310 * callers duty to clean those orphaned rings.
1311 *
1312 * Return 0 on success, negative on failure
1313 **/
1314
1315int
1316e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1317{
1318 int i, err = 0;
1319
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001320 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001321 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1322 if (err) {
1323 DPRINTK(PROBE, ERR,
1324 "Allocation for Tx Queue %u failed\n", i);
1325 break;
1326 }
1327 }
1328
1329 return err;
1330}
1331
1332/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1334 * @adapter: board private structure
1335 *
1336 * Configure the Tx unit of the MAC after a reset.
1337 **/
1338
1339static void
1340e1000_configure_tx(struct e1000_adapter *adapter)
1341{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001342 uint64_t tdba;
1343 struct e1000_hw *hw = &adapter->hw;
1344 uint32_t tdlen, tctl, tipg, tarc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
1346 /* Setup the HW Tx Head and Tail descriptor pointers */
1347
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001348 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001349 case 2:
1350 tdba = adapter->tx_ring[1].dma;
1351 tdlen = adapter->tx_ring[1].count *
1352 sizeof(struct e1000_tx_desc);
1353 E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
1354 E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
1355 E1000_WRITE_REG(hw, TDLEN1, tdlen);
1356 E1000_WRITE_REG(hw, TDH1, 0);
1357 E1000_WRITE_REG(hw, TDT1, 0);
1358 adapter->tx_ring[1].tdh = E1000_TDH1;
1359 adapter->tx_ring[1].tdt = E1000_TDT1;
1360 /* Fall Through */
1361 case 1:
1362 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001363 tdba = adapter->tx_ring[0].dma;
1364 tdlen = adapter->tx_ring[0].count *
1365 sizeof(struct e1000_tx_desc);
1366 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1367 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1368 E1000_WRITE_REG(hw, TDLEN, tdlen);
1369 E1000_WRITE_REG(hw, TDH, 0);
1370 E1000_WRITE_REG(hw, TDT, 0);
1371 adapter->tx_ring[0].tdh = E1000_TDH;
1372 adapter->tx_ring[0].tdt = E1000_TDT;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001373 break;
1374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 /* Set the default values for the Tx Inter Packet Gap timer */
1377
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001378 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 case e1000_82542_rev2_0:
1380 case e1000_82542_rev2_1:
1381 tipg = DEFAULT_82542_TIPG_IPGT;
1382 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1383 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1384 break;
1385 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001386 if (hw->media_type == e1000_media_type_fiber ||
1387 hw->media_type == e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1389 else
1390 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1391 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1392 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1393 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001394 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
1396 /* Set the Tx Interrupt Delay register */
1397
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001398 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1399 if (hw->mac_type >= e1000_82540)
1400 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
1402 /* Program the Transmit Control Register */
1403
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001404 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
1406 tctl &= ~E1000_TCTL_CT;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001407 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1409
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001410 E1000_WRITE_REG(hw, TCTL, tctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001412 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1413 tarc = E1000_READ_REG(hw, TARC0);
1414 tarc |= ((1 << 25) | (1 << 21));
1415 E1000_WRITE_REG(hw, TARC0, tarc);
1416 tarc = E1000_READ_REG(hw, TARC1);
1417 tarc |= (1 << 25);
1418 if (tctl & E1000_TCTL_MULR)
1419 tarc &= ~(1 << 28);
1420 else
1421 tarc |= (1 << 28);
1422 E1000_WRITE_REG(hw, TARC1, tarc);
1423 }
1424
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001425 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 /* Setup Transmit Descriptor Settings for eop descriptor */
1428 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1429 E1000_TXD_CMD_IFCS;
1430
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001431 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1433 else
1434 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1435
1436 /* Cache if we're 82544 running in PCI-X because we'll
1437 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001438 if (hw->mac_type == e1000_82544 &&
1439 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 adapter->pcix_82544 = 1;
1441}
1442
1443/**
1444 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1445 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001446 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 *
1448 * Returns 0 on success, negative on failure
1449 **/
1450
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001451static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001452e1000_setup_rx_resources(struct e1000_adapter *adapter,
1453 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001456 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
1458 size = sizeof(struct e1000_buffer) * rxdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001459 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001460 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001461 DPRINTK(PROBE, ERR,
1462 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 return -ENOMEM;
1464 }
1465 memset(rxdr->buffer_info, 0, size);
1466
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001467 size = sizeof(struct e1000_ps_page) * rxdr->count;
1468 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1469 if(!rxdr->ps_page) {
1470 vfree(rxdr->buffer_info);
1471 DPRINTK(PROBE, ERR,
1472 "Unable to allocate memory for the receive descriptor ring\n");
1473 return -ENOMEM;
1474 }
1475 memset(rxdr->ps_page, 0, size);
1476
1477 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1478 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1479 if(!rxdr->ps_page_dma) {
1480 vfree(rxdr->buffer_info);
1481 kfree(rxdr->ps_page);
1482 DPRINTK(PROBE, ERR,
1483 "Unable to allocate memory for the receive descriptor ring\n");
1484 return -ENOMEM;
1485 }
1486 memset(rxdr->ps_page_dma, 0, size);
1487
1488 if(adapter->hw.mac_type <= e1000_82547_rev_2)
1489 desc_len = sizeof(struct e1000_rx_desc);
1490 else
1491 desc_len = sizeof(union e1000_rx_desc_packet_split);
1492
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 /* Round up to nearest 4K */
1494
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001495 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 E1000_ROUNDUP(rxdr->size, 4096);
1497
1498 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1499
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001500 if (!rxdr->desc) {
1501 DPRINTK(PROBE, ERR,
1502 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001505 kfree(rxdr->ps_page);
1506 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 return -ENOMEM;
1508 }
1509
Malli Chilakala26483452005-04-28 19:44:46 -07001510 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1512 void *olddesc = rxdr->desc;
1513 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001514 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1515 "at %p\n", rxdr->size, rxdr->desc);
1516 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001518 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001519 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001521 DPRINTK(PROBE, ERR,
1522 "Unable to allocate memory "
1523 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 goto setup_rx_desc_die;
1525 }
1526
1527 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1528 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001529 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1530 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001532 DPRINTK(PROBE, ERR,
1533 "Unable to allocate aligned memory "
1534 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001535 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001537 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1539 }
1540 }
1541 memset(rxdr->desc, 0, rxdr->size);
1542
1543 rxdr->next_to_clean = 0;
1544 rxdr->next_to_use = 0;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08001545 rxdr->rx_skb_top = NULL;
1546 rxdr->rx_skb_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
1548 return 0;
1549}
1550
1551/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001552 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1553 * (Descriptors) for all queues
1554 * @adapter: board private structure
1555 *
1556 * If this function returns with an error, then it's possible one or
1557 * more of the rings is populated (while the rest are not). It is the
1558 * callers duty to clean those orphaned rings.
1559 *
1560 * Return 0 on success, negative on failure
1561 **/
1562
1563int
1564e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1565{
1566 int i, err = 0;
1567
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001568 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001569 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1570 if (err) {
1571 DPRINTK(PROBE, ERR,
1572 "Allocation for Rx Queue %u failed\n", i);
1573 break;
1574 }
1575 }
1576
1577 return err;
1578}
1579
1580/**
Malli Chilakala26483452005-04-28 19:44:46 -07001581 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 * @adapter: Board private structure
1583 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001584#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1585 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586static void
1587e1000_setup_rctl(struct e1000_adapter *adapter)
1588{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001589 uint32_t rctl, rfctl;
1590 uint32_t psrctl = 0;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001591#ifdef CONFIG_E1000_PACKET_SPLIT
1592 uint32_t pages = 0;
1593#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
1595 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1596
1597 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1598
1599 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1600 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1601 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1602
1603 if(adapter->hw.tbi_compatibility_on == 1)
1604 rctl |= E1000_RCTL_SBP;
1605 else
1606 rctl &= ~E1000_RCTL_SBP;
1607
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001608 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1609 rctl &= ~E1000_RCTL_LPE;
1610 else
1611 rctl |= E1000_RCTL_LPE;
1612
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 /* Setup buffer sizes */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001614 if(adapter->hw.mac_type >= e1000_82571) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001615 /* We can now specify buffers in 1K increments.
1616 * BSIZE and BSEX are ignored in this case. */
1617 rctl |= adapter->rx_buffer_len << 0x11;
1618 } else {
1619 rctl &= ~E1000_RCTL_SZ_4096;
1620 rctl |= E1000_RCTL_BSEX;
1621 switch (adapter->rx_buffer_len) {
1622 case E1000_RXBUFFER_2048:
1623 default:
1624 rctl |= E1000_RCTL_SZ_2048;
1625 rctl &= ~E1000_RCTL_BSEX;
1626 break;
1627 case E1000_RXBUFFER_4096:
1628 rctl |= E1000_RCTL_SZ_4096;
1629 break;
1630 case E1000_RXBUFFER_8192:
1631 rctl |= E1000_RCTL_SZ_8192;
1632 break;
1633 case E1000_RXBUFFER_16384:
1634 rctl |= E1000_RCTL_SZ_16384;
1635 break;
1636 }
1637 }
1638
1639#ifdef CONFIG_E1000_PACKET_SPLIT
1640 /* 82571 and greater support packet-split where the protocol
1641 * header is placed in skb->data and the packet data is
1642 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1643 * In the case of a non-split, skb->data is linearly filled,
1644 * followed by the page buffers. Therefore, skb->data is
1645 * sized to hold the largest protocol header.
1646 */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001647 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1648 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1649 PAGE_SIZE <= 16384)
1650 adapter->rx_ps_pages = pages;
1651 else
1652 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001653#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001654 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001655 /* Configure extra packet-split registers */
1656 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1657 rfctl |= E1000_RFCTL_EXTEN;
1658 /* disable IPv6 packet split support */
1659 rfctl |= E1000_RFCTL_IPV6_DIS;
1660 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1661
1662 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1663
1664 psrctl |= adapter->rx_ps_bsize0 >>
1665 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001666
1667 switch (adapter->rx_ps_pages) {
1668 case 3:
1669 psrctl |= PAGE_SIZE <<
1670 E1000_PSRCTL_BSIZE3_SHIFT;
1671 case 2:
1672 psrctl |= PAGE_SIZE <<
1673 E1000_PSRCTL_BSIZE2_SHIFT;
1674 case 1:
1675 psrctl |= PAGE_SIZE >>
1676 E1000_PSRCTL_BSIZE1_SHIFT;
1677 break;
1678 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001679
1680 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 }
1682
1683 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1684}
1685
1686/**
1687 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1688 * @adapter: board private structure
1689 *
1690 * Configure the Rx unit of the MAC after a reset.
1691 **/
1692
1693static void
1694e1000_configure_rx(struct e1000_adapter *adapter)
1695{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001696 uint64_t rdba;
1697 struct e1000_hw *hw = &adapter->hw;
1698 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1699#ifdef CONFIG_E1000_MQ
1700 uint32_t reta, mrqc;
1701 int i;
1702#endif
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001703
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001704 if (adapter->rx_ps_pages) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001705 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001706 sizeof(union e1000_rx_desc_packet_split);
1707 adapter->clean_rx = e1000_clean_rx_irq_ps;
1708 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1709 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001710 rdlen = adapter->rx_ring[0].count *
1711 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001712 adapter->clean_rx = e1000_clean_rx_irq;
1713 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
1716 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001717 rctl = E1000_READ_REG(hw, RCTL);
1718 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
1720 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001721 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001723 if (hw->mac_type >= e1000_82540) {
1724 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 if(adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001726 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 1000000000 / (adapter->itr * 256));
1728 }
1729
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001730 if (hw->mac_type >= e1000_82571) {
1731 /* Reset delay timers after every interrupt */
1732 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1733 ctrl_ext |= E1000_CTRL_EXT_CANC;
1734 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1735 E1000_WRITE_FLUSH(hw);
1736 }
1737
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001738 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1739 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001740 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001741#ifdef CONFIG_E1000_MQ
1742 case 2:
1743 rdba = adapter->rx_ring[1].dma;
1744 E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
1745 E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
1746 E1000_WRITE_REG(hw, RDLEN1, rdlen);
1747 E1000_WRITE_REG(hw, RDH1, 0);
1748 E1000_WRITE_REG(hw, RDT1, 0);
1749 adapter->rx_ring[1].rdh = E1000_RDH1;
1750 adapter->rx_ring[1].rdt = E1000_RDT1;
1751 /* Fall Through */
1752#endif
1753 case 1:
1754 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001755 rdba = adapter->rx_ring[0].dma;
1756 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1757 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1758 E1000_WRITE_REG(hw, RDLEN, rdlen);
1759 E1000_WRITE_REG(hw, RDH, 0);
1760 E1000_WRITE_REG(hw, RDT, 0);
1761 adapter->rx_ring[0].rdh = E1000_RDH;
1762 adapter->rx_ring[0].rdt = E1000_RDT;
1763 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001764 }
1765
1766#ifdef CONFIG_E1000_MQ
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001767 if (adapter->num_rx_queues > 1) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001768 uint32_t random[10];
1769
1770 get_random_bytes(&random[0], 40);
1771
1772 if (hw->mac_type <= e1000_82572) {
1773 E1000_WRITE_REG(hw, RSSIR, 0);
1774 E1000_WRITE_REG(hw, RSSIM, 0);
1775 }
1776
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001777 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001778 case 2:
1779 default:
1780 reta = 0x00800080;
1781 mrqc = E1000_MRQC_ENABLE_RSS_2Q;
1782 break;
1783 }
1784
1785 /* Fill out redirection table */
1786 for (i = 0; i < 32; i++)
1787 E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
1788 /* Fill out hash function seeds */
1789 for (i = 0; i < 10; i++)
1790 E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
1791
1792 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1793 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1794 E1000_WRITE_REG(hw, MRQC, mrqc);
1795 }
1796
1797 /* Multiqueue and packet checksumming are mutually exclusive. */
1798 if (hw->mac_type >= e1000_82571) {
1799 rxcsum = E1000_READ_REG(hw, RXCSUM);
1800 rxcsum |= E1000_RXCSUM_PCSD;
1801 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1802 }
1803
1804#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
1806 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001807 if (hw->mac_type >= e1000_82543) {
1808 rxcsum = E1000_READ_REG(hw, RXCSUM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001809 if(adapter->rx_csum == TRUE) {
1810 rxcsum |= E1000_RXCSUM_TUOFL;
1811
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001812 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001813 * Must be used in conjunction with packet-split. */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001814 if ((hw->mac_type >= e1000_82571) &&
1815 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001816 rxcsum |= E1000_RXCSUM_IPPCSE;
1817 }
1818 } else {
1819 rxcsum &= ~E1000_RXCSUM_TUOFL;
1820 /* don't need to clear IPPCSE as it defaults to 0 */
1821 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001822 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 }
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001824#endif /* CONFIG_E1000_MQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001826 if (hw->mac_type == e1000_82573)
1827 E1000_WRITE_REG(hw, ERT, 0x0100);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001828
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001830 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831}
1832
1833/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001834 * e1000_free_tx_resources - Free Tx Resources per Queue
1835 * @adapter: board private structure
1836 * @tx_ring: Tx descriptor ring for a specific queue
1837 *
1838 * Free all transmit software resources
1839 **/
1840
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001841static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001842e1000_free_tx_resources(struct e1000_adapter *adapter,
1843 struct e1000_tx_ring *tx_ring)
1844{
1845 struct pci_dev *pdev = adapter->pdev;
1846
1847 e1000_clean_tx_ring(adapter, tx_ring);
1848
1849 vfree(tx_ring->buffer_info);
1850 tx_ring->buffer_info = NULL;
1851
1852 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1853
1854 tx_ring->desc = NULL;
1855}
1856
1857/**
1858 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 * @adapter: board private structure
1860 *
1861 * Free all transmit software resources
1862 **/
1863
1864void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001865e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001867 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
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_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871}
1872
1873static inline void
1874e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1875 struct e1000_buffer *buffer_info)
1876{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 if(buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001878 pci_unmap_page(adapter->pdev,
1879 buffer_info->dma,
1880 buffer_info->length,
1881 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 buffer_info->dma = 0;
1883 }
1884 if(buffer_info->skb) {
1885 dev_kfree_skb_any(buffer_info->skb);
1886 buffer_info->skb = NULL;
1887 }
1888}
1889
1890/**
1891 * e1000_clean_tx_ring - Free Tx Buffers
1892 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001893 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 **/
1895
1896static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001897e1000_clean_tx_ring(struct e1000_adapter *adapter,
1898 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 struct e1000_buffer *buffer_info;
1901 unsigned long size;
1902 unsigned int i;
1903
1904 /* Free all the Tx ring sk_buffs */
1905
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 for(i = 0; i < tx_ring->count; i++) {
1907 buffer_info = &tx_ring->buffer_info[i];
1908 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1909 }
1910
1911 size = sizeof(struct e1000_buffer) * tx_ring->count;
1912 memset(tx_ring->buffer_info, 0, size);
1913
1914 /* Zero out the descriptor ring */
1915
1916 memset(tx_ring->desc, 0, tx_ring->size);
1917
1918 tx_ring->next_to_use = 0;
1919 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001920 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001922 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1923 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1924}
1925
1926/**
1927 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1928 * @adapter: board private structure
1929 **/
1930
1931static void
1932e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1933{
1934 int i;
1935
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001936 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001937 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938}
1939
1940/**
1941 * e1000_free_rx_resources - Free Rx Resources
1942 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001943 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 *
1945 * Free all receive software resources
1946 **/
1947
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001948static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001949e1000_free_rx_resources(struct e1000_adapter *adapter,
1950 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 struct pci_dev *pdev = adapter->pdev;
1953
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001954 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
1956 vfree(rx_ring->buffer_info);
1957 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001958 kfree(rx_ring->ps_page);
1959 rx_ring->ps_page = NULL;
1960 kfree(rx_ring->ps_page_dma);
1961 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
1963 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1964
1965 rx_ring->desc = NULL;
1966}
1967
1968/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001969 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001971 *
1972 * Free all receive software resources
1973 **/
1974
1975void
1976e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1977{
1978 int i;
1979
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001980 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001981 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1982}
1983
1984/**
1985 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1986 * @adapter: board private structure
1987 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 **/
1989
1990static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001991e1000_clean_rx_ring(struct e1000_adapter *adapter,
1992 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001995 struct e1000_ps_page *ps_page;
1996 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 struct pci_dev *pdev = adapter->pdev;
1998 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001999 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
2001 /* Free all the Rx ring sk_buffs */
2002
2003 for(i = 0; i < rx_ring->count; i++) {
2004 buffer_info = &rx_ring->buffer_info[i];
2005 if(buffer_info->skb) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002006 ps_page = &rx_ring->ps_page[i];
2007 ps_page_dma = &rx_ring->ps_page_dma[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 pci_unmap_single(pdev,
2009 buffer_info->dma,
2010 buffer_info->length,
2011 PCI_DMA_FROMDEVICE);
2012
2013 dev_kfree_skb(buffer_info->skb);
2014 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002015 }
2016 ps_page = &rx_ring->ps_page[i];
2017 ps_page_dma = &rx_ring->ps_page_dma[i];
2018 for (j = 0; j < adapter->rx_ps_pages; j++) {
2019 if (!ps_page->ps_page[j]) break;
2020 pci_unmap_page(pdev,
2021 ps_page_dma->ps_page_dma[j],
2022 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2023 ps_page_dma->ps_page_dma[j] = 0;
2024 put_page(ps_page->ps_page[j]);
2025 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 }
2027 }
2028
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002029 /* there also may be some cached data in our adapter */
2030 if (rx_ring->rx_skb_top) {
2031 dev_kfree_skb(rx_ring->rx_skb_top);
2032
2033 /* rx_skb_prev will be wiped out by rx_skb_top */
2034 rx_ring->rx_skb_top = NULL;
2035 rx_ring->rx_skb_prev = NULL;
2036 }
2037
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 size = sizeof(struct e1000_buffer) * rx_ring->count;
2040 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002041 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2042 memset(rx_ring->ps_page, 0, size);
2043 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2044 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046 /* Zero out the descriptor ring */
2047
2048 memset(rx_ring->desc, 0, rx_ring->size);
2049
2050 rx_ring->next_to_clean = 0;
2051 rx_ring->next_to_use = 0;
2052
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002053 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2054 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2055}
2056
2057/**
2058 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2059 * @adapter: board private structure
2060 **/
2061
2062static void
2063e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2064{
2065 int i;
2066
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002067 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002068 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069}
2070
2071/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2072 * and memory write and invalidate disabled for certain operations
2073 */
2074static void
2075e1000_enter_82542_rst(struct e1000_adapter *adapter)
2076{
2077 struct net_device *netdev = adapter->netdev;
2078 uint32_t rctl;
2079
2080 e1000_pci_clear_mwi(&adapter->hw);
2081
2082 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2083 rctl |= E1000_RCTL_RST;
2084 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2085 E1000_WRITE_FLUSH(&adapter->hw);
2086 mdelay(5);
2087
2088 if(netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002089 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090}
2091
2092static void
2093e1000_leave_82542_rst(struct e1000_adapter *adapter)
2094{
2095 struct net_device *netdev = adapter->netdev;
2096 uint32_t rctl;
2097
2098 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2099 rctl &= ~E1000_RCTL_RST;
2100 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2101 E1000_WRITE_FLUSH(&adapter->hw);
2102 mdelay(5);
2103
2104 if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2105 e1000_pci_set_mwi(&adapter->hw);
2106
2107 if(netif_running(netdev)) {
2108 e1000_configure_rx(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002109 e1000_alloc_rx_buffers(adapter, &adapter->rx_ring[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 }
2111}
2112
2113/**
2114 * e1000_set_mac - Change the Ethernet Address of the NIC
2115 * @netdev: network interface device structure
2116 * @p: pointer to an address structure
2117 *
2118 * Returns 0 on success, negative on failure
2119 **/
2120
2121static int
2122e1000_set_mac(struct net_device *netdev, void *p)
2123{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002124 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 struct sockaddr *addr = p;
2126
2127 if(!is_valid_ether_addr(addr->sa_data))
2128 return -EADDRNOTAVAIL;
2129
2130 /* 82542 2.0 needs to be in reset to write receive address registers */
2131
2132 if(adapter->hw.mac_type == e1000_82542_rev2_0)
2133 e1000_enter_82542_rst(adapter);
2134
2135 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2136 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2137
2138 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2139
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002140 /* With 82571 controllers, LAA may be overwritten (with the default)
2141 * due to controller reset from the other port. */
2142 if (adapter->hw.mac_type == e1000_82571) {
2143 /* activate the work around */
2144 adapter->hw.laa_is_present = 1;
2145
2146 /* Hold a copy of the LAA in RAR[14] This is done so that
2147 * between the time RAR[0] gets clobbered and the time it
2148 * gets fixed (in e1000_watchdog), the actual LAA is in one
2149 * of the RARs and no incoming packets directed to this port
2150 * are dropped. Eventaully the LAA will be in RAR[0] and
2151 * RAR[14] */
2152 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2153 E1000_RAR_ENTRIES - 1);
2154 }
2155
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 if(adapter->hw.mac_type == e1000_82542_rev2_0)
2157 e1000_leave_82542_rst(adapter);
2158
2159 return 0;
2160}
2161
2162/**
2163 * e1000_set_multi - Multicast and Promiscuous mode set
2164 * @netdev: network interface device structure
2165 *
2166 * The set_multi entry point is called whenever the multicast address
2167 * list or the network interface flags are updated. This routine is
2168 * responsible for configuring the hardware for proper multicast,
2169 * promiscuous mode, and all-multi behavior.
2170 **/
2171
2172static void
2173e1000_set_multi(struct net_device *netdev)
2174{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002175 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 struct e1000_hw *hw = &adapter->hw;
2177 struct dev_mc_list *mc_ptr;
2178 uint32_t rctl;
2179 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002180 int i, rar_entries = E1000_RAR_ENTRIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002182 /* reserve RAR[14] for LAA over-write work-around */
2183 if (adapter->hw.mac_type == e1000_82571)
2184 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
Malli Chilakala26483452005-04-28 19:44:46 -07002186 /* Check for Promiscuous and All Multicast modes */
2187
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 rctl = E1000_READ_REG(hw, RCTL);
2189
2190 if(netdev->flags & IFF_PROMISC) {
2191 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2192 } else if(netdev->flags & IFF_ALLMULTI) {
2193 rctl |= E1000_RCTL_MPE;
2194 rctl &= ~E1000_RCTL_UPE;
2195 } else {
2196 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2197 }
2198
2199 E1000_WRITE_REG(hw, RCTL, rctl);
2200
2201 /* 82542 2.0 needs to be in reset to write receive address registers */
2202
2203 if(hw->mac_type == e1000_82542_rev2_0)
2204 e1000_enter_82542_rst(adapter);
2205
2206 /* load the first 14 multicast address into the exact filters 1-14
2207 * RAR 0 is used for the station MAC adddress
2208 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002209 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 */
2211 mc_ptr = netdev->mc_list;
2212
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002213 for(i = 1; i < rar_entries; i++) {
2214 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2216 mc_ptr = mc_ptr->next;
2217 } else {
2218 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2219 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2220 }
2221 }
2222
2223 /* clear the old settings from the multicast hash table */
2224
2225 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2226 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2227
2228 /* load any remaining addresses into the hash table */
2229
2230 for(; mc_ptr; mc_ptr = mc_ptr->next) {
2231 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2232 e1000_mta_set(hw, hash_value);
2233 }
2234
2235 if(hw->mac_type == e1000_82542_rev2_0)
2236 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237}
2238
2239/* Need to wait a few seconds after link up to get diagnostic information from
2240 * the phy */
2241
2242static void
2243e1000_update_phy_info(unsigned long data)
2244{
2245 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2246 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2247}
2248
2249/**
2250 * e1000_82547_tx_fifo_stall - Timer Call-back
2251 * @data: pointer to adapter cast into an unsigned long
2252 **/
2253
2254static void
2255e1000_82547_tx_fifo_stall(unsigned long data)
2256{
2257 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2258 struct net_device *netdev = adapter->netdev;
2259 uint32_t tctl;
2260
2261 if(atomic_read(&adapter->tx_fifo_stall)) {
2262 if((E1000_READ_REG(&adapter->hw, TDT) ==
2263 E1000_READ_REG(&adapter->hw, TDH)) &&
2264 (E1000_READ_REG(&adapter->hw, TDFT) ==
2265 E1000_READ_REG(&adapter->hw, TDFH)) &&
2266 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2267 E1000_READ_REG(&adapter->hw, TDFHS))) {
2268 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2269 E1000_WRITE_REG(&adapter->hw, TCTL,
2270 tctl & ~E1000_TCTL_EN);
2271 E1000_WRITE_REG(&adapter->hw, TDFT,
2272 adapter->tx_head_addr);
2273 E1000_WRITE_REG(&adapter->hw, TDFH,
2274 adapter->tx_head_addr);
2275 E1000_WRITE_REG(&adapter->hw, TDFTS,
2276 adapter->tx_head_addr);
2277 E1000_WRITE_REG(&adapter->hw, TDFHS,
2278 adapter->tx_head_addr);
2279 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2280 E1000_WRITE_FLUSH(&adapter->hw);
2281
2282 adapter->tx_fifo_head = 0;
2283 atomic_set(&adapter->tx_fifo_stall, 0);
2284 netif_wake_queue(netdev);
2285 } else {
2286 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2287 }
2288 }
2289}
2290
2291/**
2292 * e1000_watchdog - Timer Call-back
2293 * @data: pointer to adapter cast into an unsigned long
2294 **/
2295static void
2296e1000_watchdog(unsigned long data)
2297{
2298 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2299
2300 /* Do the rest outside of interrupt context */
2301 schedule_work(&adapter->watchdog_task);
2302}
2303
2304static void
2305e1000_watchdog_task(struct e1000_adapter *adapter)
2306{
2307 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002308 struct e1000_tx_ring *txdr = adapter->tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 uint32_t link;
2310
2311 e1000_check_for_link(&adapter->hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002312 if (adapter->hw.mac_type == e1000_82573) {
2313 e1000_enable_tx_pkt_filtering(&adapter->hw);
2314 if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2315 e1000_update_mng_vlan(adapter);
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
2318 if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2319 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2320 link = !adapter->hw.serdes_link_down;
2321 else
2322 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2323
2324 if(link) {
2325 if(!netif_carrier_ok(netdev)) {
2326 e1000_get_speed_and_duplex(&adapter->hw,
2327 &adapter->link_speed,
2328 &adapter->link_duplex);
2329
2330 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2331 adapter->link_speed,
2332 adapter->link_duplex == FULL_DUPLEX ?
2333 "Full Duplex" : "Half Duplex");
2334
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002335 /* tweak tx_queue_len according to speed/duplex */
2336 netdev->tx_queue_len = adapter->tx_queue_len;
2337 adapter->tx_timeout_factor = 1;
2338 if (adapter->link_duplex == HALF_DUPLEX) {
2339 switch (adapter->link_speed) {
2340 case SPEED_10:
2341 netdev->tx_queue_len = 10;
2342 adapter->tx_timeout_factor = 8;
2343 break;
2344 case SPEED_100:
2345 netdev->tx_queue_len = 100;
2346 break;
2347 }
2348 }
2349
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 netif_carrier_on(netdev);
2351 netif_wake_queue(netdev);
2352 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2353 adapter->smartspeed = 0;
2354 }
2355 } else {
2356 if(netif_carrier_ok(netdev)) {
2357 adapter->link_speed = 0;
2358 adapter->link_duplex = 0;
2359 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2360 netif_carrier_off(netdev);
2361 netif_stop_queue(netdev);
2362 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2363 }
2364
2365 e1000_smartspeed(adapter);
2366 }
2367
2368 e1000_update_stats(adapter);
2369
2370 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2371 adapter->tpt_old = adapter->stats.tpt;
2372 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2373 adapter->colc_old = adapter->stats.colc;
2374
2375 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2376 adapter->gorcl_old = adapter->stats.gorcl;
2377 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2378 adapter->gotcl_old = adapter->stats.gotcl;
2379
2380 e1000_update_adaptive(&adapter->hw);
2381
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002382#ifdef CONFIG_E1000_MQ
2383 txdr = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2384#endif
2385 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002386 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 /* We've lost link, so the controller stops DMA,
2388 * but we've got queued Tx work that's never going
2389 * to get done, so reset controller to flush Tx.
2390 * (Do the reset outside of interrupt context). */
2391 schedule_work(&adapter->tx_timeout_task);
2392 }
2393 }
2394
2395 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2396 if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2397 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2398 * asymmetrical Tx or Rx gets ITR=8000; everyone
2399 * else is between 2000-8000. */
2400 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2401 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2402 adapter->gotcl - adapter->gorcl :
2403 adapter->gorcl - adapter->gotcl) / 10000;
2404 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2405 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2406 }
2407
2408 /* Cause software interrupt to ensure rx ring is cleaned */
2409 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2410
Malli Chilakala26483452005-04-28 19:44:46 -07002411 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 adapter->detect_tx_hung = TRUE;
2413
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002414 /* With 82571 controllers, LAA may be overwritten due to controller
2415 * reset from the other port. Set the appropriate LAA in RAR[0] */
2416 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2417 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 /* Reset the timer */
2420 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2421}
2422
2423#define E1000_TX_FLAGS_CSUM 0x00000001
2424#define E1000_TX_FLAGS_VLAN 0x00000002
2425#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002426#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2428#define E1000_TX_FLAGS_VLAN_SHIFT 16
2429
2430static inline int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002431e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2432 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433{
2434#ifdef NETIF_F_TSO
2435 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002436 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 unsigned int i;
2438 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002439 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2441 int err;
2442
2443 if(skb_shinfo(skb)->tso_size) {
2444 if (skb_header_cloned(skb)) {
2445 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2446 if (err)
2447 return err;
2448 }
2449
2450 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2451 mss = skb_shinfo(skb)->tso_size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002452 if(skb->protocol == ntohs(ETH_P_IP)) {
2453 skb->nh.iph->tot_len = 0;
2454 skb->nh.iph->check = 0;
2455 skb->h.th->check =
2456 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2457 skb->nh.iph->daddr,
2458 0,
2459 IPPROTO_TCP,
2460 0);
2461 cmd_length = E1000_TXD_CMD_IP;
2462 ipcse = skb->h.raw - skb->data - 1;
2463#ifdef NETIF_F_TSO_IPV6
2464 } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
2465 skb->nh.ipv6h->payload_len = 0;
2466 skb->h.th->check =
2467 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2468 &skb->nh.ipv6h->daddr,
2469 0,
2470 IPPROTO_TCP,
2471 0);
2472 ipcse = 0;
2473#endif
2474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 ipcss = skb->nh.raw - skb->data;
2476 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 tucss = skb->h.raw - skb->data;
2478 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2479 tucse = 0;
2480
2481 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002482 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002484 i = tx_ring->next_to_use;
2485 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002486 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
2488 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2489 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2490 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2491 context_desc->upper_setup.tcp_fields.tucss = tucss;
2492 context_desc->upper_setup.tcp_fields.tucso = tucso;
2493 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2494 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2495 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2496 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2497
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002498 buffer_info->time_stamp = jiffies;
2499
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002500 if (++i == tx_ring->count) i = 0;
2501 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
2503 return 1;
2504 }
2505#endif
2506
2507 return 0;
2508}
2509
2510static inline boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002511e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2512 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
2514 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002515 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 unsigned int i;
2517 uint8_t css;
2518
2519 if(likely(skb->ip_summed == CHECKSUM_HW)) {
2520 css = skb->h.raw - skb->data;
2521
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002522 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002523 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002524 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
2526 context_desc->upper_setup.tcp_fields.tucss = css;
2527 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2528 context_desc->upper_setup.tcp_fields.tucse = 0;
2529 context_desc->tcp_seg_setup.data = 0;
2530 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2531
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002532 buffer_info->time_stamp = jiffies;
2533
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002534 if (unlikely(++i == tx_ring->count)) i = 0;
2535 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
2537 return TRUE;
2538 }
2539
2540 return FALSE;
2541}
2542
2543#define E1000_MAX_TXD_PWR 12
2544#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2545
2546static inline int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002547e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2548 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2549 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 struct e1000_buffer *buffer_info;
2552 unsigned int len = skb->len;
2553 unsigned int offset = 0, size, count = 0, i;
2554 unsigned int f;
2555 len -= skb->data_len;
2556
2557 i = tx_ring->next_to_use;
2558
2559 while(len) {
2560 buffer_info = &tx_ring->buffer_info[i];
2561 size = min(len, max_per_txd);
2562#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002563 /* Workaround for Controller erratum --
2564 * descriptor for non-tso packet in a linear SKB that follows a
2565 * tso gets written back prematurely before the data is fully
2566 * DMAd to the controller */
2567 if (!skb->data_len && tx_ring->last_tx_tso &&
2568 !skb_shinfo(skb)->tso_size) {
2569 tx_ring->last_tx_tso = 0;
2570 size -= 4;
2571 }
2572
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 /* Workaround for premature desc write-backs
2574 * in TSO mode. Append 4-byte sentinel desc */
2575 if(unlikely(mss && !nr_frags && size == len && size > 8))
2576 size -= 4;
2577#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002578 /* work-around for errata 10 and it applies
2579 * to all controllers in PCI-X mode
2580 * The fix is to make sure that the first descriptor of a
2581 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2582 */
2583 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2584 (size > 2015) && count == 0))
2585 size = 2015;
2586
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 /* Workaround for potential 82544 hang in PCI-X. Avoid
2588 * terminating buffers within evenly-aligned dwords. */
2589 if(unlikely(adapter->pcix_82544 &&
2590 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2591 size > 4))
2592 size -= 4;
2593
2594 buffer_info->length = size;
2595 buffer_info->dma =
2596 pci_map_single(adapter->pdev,
2597 skb->data + offset,
2598 size,
2599 PCI_DMA_TODEVICE);
2600 buffer_info->time_stamp = jiffies;
2601
2602 len -= size;
2603 offset += size;
2604 count++;
2605 if(unlikely(++i == tx_ring->count)) i = 0;
2606 }
2607
2608 for(f = 0; f < nr_frags; f++) {
2609 struct skb_frag_struct *frag;
2610
2611 frag = &skb_shinfo(skb)->frags[f];
2612 len = frag->size;
2613 offset = frag->page_offset;
2614
2615 while(len) {
2616 buffer_info = &tx_ring->buffer_info[i];
2617 size = min(len, max_per_txd);
2618#ifdef NETIF_F_TSO
2619 /* Workaround for premature desc write-backs
2620 * in TSO mode. Append 4-byte sentinel desc */
2621 if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2622 size -= 4;
2623#endif
2624 /* Workaround for potential 82544 hang in PCI-X.
2625 * Avoid terminating buffers within evenly-aligned
2626 * dwords. */
2627 if(unlikely(adapter->pcix_82544 &&
2628 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2629 size > 4))
2630 size -= 4;
2631
2632 buffer_info->length = size;
2633 buffer_info->dma =
2634 pci_map_page(adapter->pdev,
2635 frag->page,
2636 offset,
2637 size,
2638 PCI_DMA_TODEVICE);
2639 buffer_info->time_stamp = jiffies;
2640
2641 len -= size;
2642 offset += size;
2643 count++;
2644 if(unlikely(++i == tx_ring->count)) i = 0;
2645 }
2646 }
2647
2648 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2649 tx_ring->buffer_info[i].skb = skb;
2650 tx_ring->buffer_info[first].next_to_watch = i;
2651
2652 return count;
2653}
2654
2655static inline void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002656e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2657 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 struct e1000_tx_desc *tx_desc = NULL;
2660 struct e1000_buffer *buffer_info;
2661 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2662 unsigned int i;
2663
2664 if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2665 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2666 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002667 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2668
2669 if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
2670 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 }
2672
2673 if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2674 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2675 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2676 }
2677
2678 if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2679 txd_lower |= E1000_TXD_CMD_VLE;
2680 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2681 }
2682
2683 i = tx_ring->next_to_use;
2684
2685 while(count--) {
2686 buffer_info = &tx_ring->buffer_info[i];
2687 tx_desc = E1000_TX_DESC(*tx_ring, i);
2688 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2689 tx_desc->lower.data =
2690 cpu_to_le32(txd_lower | buffer_info->length);
2691 tx_desc->upper.data = cpu_to_le32(txd_upper);
2692 if(unlikely(++i == tx_ring->count)) i = 0;
2693 }
2694
2695 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2696
2697 /* Force memory writes to complete before letting h/w
2698 * know there are new descriptors to fetch. (Only
2699 * applicable for weak-ordered memory model archs,
2700 * such as IA-64). */
2701 wmb();
2702
2703 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002704 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705}
2706
2707/**
2708 * 82547 workaround to avoid controller hang in half-duplex environment.
2709 * The workaround is to avoid queuing a large packet that would span
2710 * the internal Tx FIFO ring boundary by notifying the stack to resend
2711 * the packet at a later time. This gives the Tx FIFO an opportunity to
2712 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2713 * to the beginning of the Tx FIFO.
2714 **/
2715
2716#define E1000_FIFO_HDR 0x10
2717#define E1000_82547_PAD_LEN 0x3E0
2718
2719static inline int
2720e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2721{
2722 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2723 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2724
2725 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2726
2727 if(adapter->link_duplex != HALF_DUPLEX)
2728 goto no_fifo_stall_required;
2729
2730 if(atomic_read(&adapter->tx_fifo_stall))
2731 return 1;
2732
2733 if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2734 atomic_set(&adapter->tx_fifo_stall, 1);
2735 return 1;
2736 }
2737
2738no_fifo_stall_required:
2739 adapter->tx_fifo_head += skb_fifo_len;
2740 if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
2741 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2742 return 0;
2743}
2744
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002745#define MINIMUM_DHCP_PACKET_SIZE 282
2746static inline int
2747e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2748{
2749 struct e1000_hw *hw = &adapter->hw;
2750 uint16_t length, offset;
2751 if(vlan_tx_tag_present(skb)) {
2752 if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2753 ( adapter->hw.mng_cookie.status &
2754 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2755 return 0;
2756 }
Jesse Brandeburga174fd82005-11-29 19:23:59 -08002757 if ((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002758 struct ethhdr *eth = (struct ethhdr *) skb->data;
2759 if((htons(ETH_P_IP) == eth->h_proto)) {
2760 const struct iphdr *ip =
2761 (struct iphdr *)((uint8_t *)skb->data+14);
2762 if(IPPROTO_UDP == ip->protocol) {
2763 struct udphdr *udp =
2764 (struct udphdr *)((uint8_t *)ip +
2765 (ip->ihl << 2));
2766 if(ntohs(udp->dest) == 67) {
2767 offset = (uint8_t *)udp + 8 - skb->data;
2768 length = skb->len - offset;
2769
2770 return e1000_mng_write_dhcp_info(hw,
2771 (uint8_t *)udp + 8,
2772 length);
2773 }
2774 }
2775 }
2776 }
2777 return 0;
2778}
2779
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2781static int
2782e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2783{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002784 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002785 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2787 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2788 unsigned int tx_flags = 0;
2789 unsigned int len = skb->len;
2790 unsigned long flags;
2791 unsigned int nr_frags = 0;
2792 unsigned int mss = 0;
2793 int count = 0;
2794 int tso;
2795 unsigned int f;
2796 len -= skb->data_len;
2797
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002798#ifdef CONFIG_E1000_MQ
2799 tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2800#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002801 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002802#endif
2803
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002804 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 dev_kfree_skb_any(skb);
2806 return NETDEV_TX_OK;
2807 }
2808
2809#ifdef NETIF_F_TSO
2810 mss = skb_shinfo(skb)->tso_size;
Malli Chilakala26483452005-04-28 19:44:46 -07002811 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 * make sure there is enough room in the FIFO before
2813 * initiating the DMA for each buffer. The calc is:
2814 * 4 = ceil(buffer len/mss). To make sure we don't
2815 * overrun the FIFO, adjust the max buffer len if mss
2816 * drops. */
2817 if(mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002818 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 max_per_txd = min(mss << 2, max_per_txd);
2820 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002821
2822 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2823 * points to just header, pull a few bytes of payload from
2824 * frags into skb->data */
2825 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2826 if (skb->data_len && (hdr_len == (skb->len - skb->data_len)) &&
2827 (adapter->hw.mac_type == e1000_82571 ||
2828 adapter->hw.mac_type == e1000_82572)) {
2829 len = skb->len - skb->data_len;
2830 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 }
2832
2833 if((mss) || (skb->ip_summed == CHECKSUM_HW))
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002834 /* reserve a descriptor for the offload context */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07002836 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837#else
2838 if(skb->ip_summed == CHECKSUM_HW)
2839 count++;
2840#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05002841
2842#ifdef NETIF_F_TSO
2843 /* Controller Erratum workaround */
2844 if (!skb->data_len && tx_ring->last_tx_tso &&
2845 !skb_shinfo(skb)->tso_size)
2846 count++;
2847#endif
2848
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 count += TXD_USE_COUNT(len, max_txd_pwr);
2850
2851 if(adapter->pcix_82544)
2852 count++;
2853
Malli Chilakala97338bd2005-04-28 19:41:46 -07002854 /* work-around for errata 10 and it applies to all controllers
2855 * in PCI-X mode, so add one more descriptor to the count
2856 */
2857 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2858 (len > 2015)))
2859 count++;
2860
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 nr_frags = skb_shinfo(skb)->nr_frags;
2862 for(f = 0; f < nr_frags; f++)
2863 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2864 max_txd_pwr);
2865 if(adapter->pcix_82544)
2866 count += nr_frags;
2867
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002868 unsigned int pull_size;
2869 pull_size = min((unsigned int)4, skb->data_len);
2870 if (!__pskb_pull_tail(skb, pull_size)) {
2871 printk(KERN_ERR "__pskb_pull_tail failed.\n");
2872 dev_kfree_skb_any(skb);
2873 return -EFAULT;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002874 }
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002875
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002876 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2877 e1000_transfer_dhcp_info(adapter, skb);
2878
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002879 local_irq_save(flags);
2880 if (!spin_trylock(&tx_ring->tx_lock)) {
2881 /* Collision - tell upper layer to requeue */
2882 local_irq_restore(flags);
2883 return NETDEV_TX_LOCKED;
2884 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
2886 /* need: count + 2 desc gap to keep tail from touching
2887 * head, otherwise try next time */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002888 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 netif_stop_queue(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002890 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 return NETDEV_TX_BUSY;
2892 }
2893
2894 if(unlikely(adapter->hw.mac_type == e1000_82547)) {
2895 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2896 netif_stop_queue(netdev);
2897 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002898 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 return NETDEV_TX_BUSY;
2900 }
2901 }
2902
2903 if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2904 tx_flags |= E1000_TX_FLAGS_VLAN;
2905 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2906 }
2907
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002908 first = tx_ring->next_to_use;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002910 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 if (tso < 0) {
2912 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002913 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 return NETDEV_TX_OK;
2915 }
2916
Jeff Kirsherfd803242005-12-13 00:06:22 -05002917 if (likely(tso)) {
2918 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002920 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 tx_flags |= E1000_TX_FLAGS_CSUM;
2922
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002923 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002924 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002925 * no longer assume, we must. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002926 if (likely(skb->protocol == ntohs(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002927 tx_flags |= E1000_TX_FLAGS_IPV4;
2928
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002929 e1000_tx_queue(adapter, tx_ring, tx_flags,
2930 e1000_tx_map(adapter, tx_ring, skb, first,
2931 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
2933 netdev->trans_start = jiffies;
2934
2935 /* Make sure there is space in the ring for the next send. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002936 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 netif_stop_queue(netdev);
2938
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002939 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 return NETDEV_TX_OK;
2941}
2942
2943/**
2944 * e1000_tx_timeout - Respond to a Tx Hang
2945 * @netdev: network interface device structure
2946 **/
2947
2948static void
2949e1000_tx_timeout(struct net_device *netdev)
2950{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002951 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
2953 /* Do the reset outside of interrupt context */
2954 schedule_work(&adapter->tx_timeout_task);
2955}
2956
2957static void
2958e1000_tx_timeout_task(struct net_device *netdev)
2959{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002960 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08002962 adapter->tx_timeout_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 e1000_down(adapter);
2964 e1000_up(adapter);
2965}
2966
2967/**
2968 * e1000_get_stats - Get System Network Statistics
2969 * @netdev: network interface device structure
2970 *
2971 * Returns the address of the device statistics structure.
2972 * The statistics are actually updated from the timer callback.
2973 **/
2974
2975static struct net_device_stats *
2976e1000_get_stats(struct net_device *netdev)
2977{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002978 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08002980 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 return &adapter->net_stats;
2982}
2983
2984/**
2985 * e1000_change_mtu - Change the Maximum Transfer Unit
2986 * @netdev: network interface device structure
2987 * @new_mtu: new value for maximum frame size
2988 *
2989 * Returns 0 on success, negative on failure
2990 **/
2991
2992static int
2993e1000_change_mtu(struct net_device *netdev, int new_mtu)
2994{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002995 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2997
2998 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
2999 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3000 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003001 return -EINVAL;
3002 }
3003
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003004 /* Adapter-specific max frame size limits. */
3005 switch (adapter->hw.mac_type) {
3006 case e1000_82542_rev2_0:
3007 case e1000_82542_rev2_1:
3008 case e1000_82573:
3009 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3010 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003011 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003012 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003013 break;
3014 case e1000_82571:
3015 case e1000_82572:
3016#define MAX_STD_JUMBO_FRAME_SIZE 9234
3017 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3018 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3019 return -EINVAL;
3020 }
3021 break;
3022 default:
3023 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3024 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003025 }
3026
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003027 /* since the driver code now supports splitting a packet across
3028 * multiple descriptors, most of the fifo related limitations on
3029 * jumbo frame traffic have gone away.
3030 * simply use 2k descriptors for everything.
3031 *
3032 * NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3033 * means we reserve 2 more, this pushes us to allocate from the next
3034 * larger slab size
3035 * i.e. RXBUFFER_2048 --> size-4096 slab */
3036
3037 /* recent hardware supports 1KB granularity */
3038 if (adapter->hw.mac_type > e1000_82547_rev_2) {
3039 adapter->rx_buffer_len =
3040 ((max_frame < E1000_RXBUFFER_2048) ?
3041 max_frame : E1000_RXBUFFER_2048);
3042 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
3043 } else
3044 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3045
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003046 netdev->mtu = new_mtu;
3047
3048 if(netif_running(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 e1000_down(adapter);
3050 e1000_up(adapter);
3051 }
3052
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 adapter->hw.max_frame_size = max_frame;
3054
3055 return 0;
3056}
3057
3058/**
3059 * e1000_update_stats - Update the board statistics counters
3060 * @adapter: board private structure
3061 **/
3062
3063void
3064e1000_update_stats(struct e1000_adapter *adapter)
3065{
3066 struct e1000_hw *hw = &adapter->hw;
3067 unsigned long flags;
3068 uint16_t phy_tmp;
3069
3070#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3071
3072 spin_lock_irqsave(&adapter->stats_lock, flags);
3073
3074 /* these counters are modified from e1000_adjust_tbi_stats,
3075 * called from the interrupt context, so they must only
3076 * be written while holding adapter->stats_lock
3077 */
3078
3079 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3080 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3081 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3082 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3083 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3084 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3085 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3086 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3087 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3088 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3089 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3090 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3091 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3092
3093 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3094 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3095 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3096 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3097 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3098 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3099 adapter->stats.dc += E1000_READ_REG(hw, DC);
3100 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3101 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3102 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3103 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3104 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3105 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3106 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3107 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3108 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3109 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3110 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3111 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3112 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3113 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3114 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3115 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3116 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3117 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3118 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3119 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3120 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3121 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3122 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3123 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3124 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3125 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3126 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3127
3128 /* used for adaptive IFS */
3129
3130 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3131 adapter->stats.tpt += hw->tx_packet_delta;
3132 hw->collision_delta = E1000_READ_REG(hw, COLC);
3133 adapter->stats.colc += hw->collision_delta;
3134
3135 if(hw->mac_type >= e1000_82543) {
3136 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3137 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3138 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3139 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3140 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3141 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3142 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003143 if(hw->mac_type > e1000_82547_rev_2) {
3144 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3145 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3146 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3147 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3148 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3149 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3150 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3151 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3152 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154
3155 /* Fill out the OS statistics structure */
3156
3157 adapter->net_stats.rx_packets = adapter->stats.gprc;
3158 adapter->net_stats.tx_packets = adapter->stats.gptc;
3159 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3160 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3161 adapter->net_stats.multicast = adapter->stats.mprc;
3162 adapter->net_stats.collisions = adapter->stats.colc;
3163
3164 /* Rx Errors */
3165
3166 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3167 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003168 adapter->stats.rlec + adapter->stats.cexterr;
3169 adapter->net_stats.rx_dropped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3171 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3172 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3174
3175 /* Tx Errors */
3176
3177 adapter->net_stats.tx_errors = adapter->stats.ecol +
3178 adapter->stats.latecol;
3179 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3180 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3181 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3182
3183 /* Tx Dropped needs to be maintained elsewhere */
3184
3185 /* Phy Stats */
3186
3187 if(hw->media_type == e1000_media_type_copper) {
3188 if((adapter->link_speed == SPEED_1000) &&
3189 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3190 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3191 adapter->phy_stats.idle_errors += phy_tmp;
3192 }
3193
3194 if((hw->mac_type <= e1000_82546) &&
3195 (hw->phy_type == e1000_phy_m88) &&
3196 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3197 adapter->phy_stats.receive_errors += phy_tmp;
3198 }
3199
3200 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3201}
3202
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003203#ifdef CONFIG_E1000_MQ
3204void
3205e1000_rx_schedule(void *data)
3206{
3207 struct net_device *poll_dev, *netdev = data;
3208 struct e1000_adapter *adapter = netdev->priv;
3209 int this_cpu = get_cpu();
3210
3211 poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
3212 if (poll_dev == NULL) {
3213 put_cpu();
3214 return;
3215 }
3216
3217 if (likely(netif_rx_schedule_prep(poll_dev)))
3218 __netif_rx_schedule(poll_dev);
3219 else
3220 e1000_irq_enable(adapter);
3221
3222 put_cpu();
3223}
3224#endif
3225
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226/**
3227 * e1000_intr - Interrupt Handler
3228 * @irq: interrupt number
3229 * @data: pointer to a network interface device structure
3230 * @pt_regs: CPU registers structure
3231 **/
3232
3233static irqreturn_t
3234e1000_intr(int irq, void *data, struct pt_regs *regs)
3235{
3236 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003237 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 struct e1000_hw *hw = &adapter->hw;
3239 uint32_t icr = E1000_READ_REG(hw, ICR);
Andrew Morton166d8232005-10-16 13:32:14 -07003240#if defined(CONFIG_E1000_NAPI) && defined(CONFIG_E1000_MQ) || !defined(CONFIG_E1000_NAPI)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003241 int i;
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003242#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
3244 if(unlikely(!icr))
3245 return IRQ_NONE; /* Not our interrupt */
3246
3247 if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3248 hw->get_link_status = 1;
3249 mod_timer(&adapter->watchdog_timer, jiffies);
3250 }
3251
3252#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003253 atomic_inc(&adapter->irq_sem);
3254 E1000_WRITE_REG(hw, IMC, ~0);
3255 E1000_WRITE_FLUSH(hw);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003256#ifdef CONFIG_E1000_MQ
3257 if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
Jeff Kirsherf56799e2006-01-12 16:50:39 -08003258 /* We must setup the cpumask once count == 0 since
3259 * each cpu bit is cleared when the work is done. */
3260 adapter->rx_sched_call_data.cpumask = adapter->cpumask;
3261 atomic_add(adapter->num_rx_queues - 1, &adapter->irq_sem);
3262 atomic_set(&adapter->rx_sched_call_data.count,
3263 adapter->num_rx_queues);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003264 smp_call_async_mask(&adapter->rx_sched_call_data);
3265 } else {
3266 printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 }
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003268#else /* if !CONFIG_E1000_MQ */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003269 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3270 __netif_rx_schedule(&adapter->polling_netdev[0]);
3271 else
3272 e1000_irq_enable(adapter);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003273#endif /* CONFIG_E1000_MQ */
3274
3275#else /* if !CONFIG_E1000_NAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 /* Writing IMC and IMS is needed for 82547.
3277 Due to Hub Link bus being occupied, an interrupt
3278 de-assertion message is not able to be sent.
3279 When an interrupt assertion message is generated later,
3280 two messages are re-ordered and sent out.
3281 That causes APIC to think 82547 is in de-assertion
3282 state, while 82547 is in assertion state, resulting
3283 in dead lock. Writing IMC forces 82547 into
3284 de-assertion state.
3285 */
3286 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
3287 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003288 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 }
3290
3291 for(i = 0; i < E1000_MAX_INTR; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003292 if(unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3293 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 break;
3295
3296 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3297 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003298
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003299#endif /* CONFIG_E1000_NAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300
3301 return IRQ_HANDLED;
3302}
3303
3304#ifdef CONFIG_E1000_NAPI
3305/**
3306 * e1000_clean - NAPI Rx polling callback
3307 * @adapter: board private structure
3308 **/
3309
3310static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003311e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003313 struct e1000_adapter *adapter;
3314 int work_to_do = min(*budget, poll_dev->quota);
3315 int tx_cleaned, i = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003316
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003317 /* Must NOT use netdev_priv macro here. */
3318 adapter = poll_dev->priv;
3319
3320 /* Keep link state information with original netdev */
3321 if (!netif_carrier_ok(adapter->netdev))
3322 goto quit_polling;
3323
3324 while (poll_dev != &adapter->polling_netdev[i]) {
3325 i++;
Jeff Kirsherf56799e2006-01-12 16:50:39 -08003326 if (unlikely(i == adapter->num_rx_queues))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003327 BUG();
3328 }
3329
3330 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3331 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3332 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
3334 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003335 poll_dev->quota -= work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336
Malli Chilakala2b028932005-06-17 17:46:06 -07003337 /* If no Tx and not enough Rx work done, exit the polling mode */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003338 if((!tx_cleaned && (work_done == 0)) ||
3339 !netif_running(adapter->netdev)) {
3340quit_polling:
3341 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 e1000_irq_enable(adapter);
3343 return 0;
3344 }
3345
3346 return 1;
3347}
3348
3349#endif
3350/**
3351 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3352 * @adapter: board private structure
3353 **/
3354
3355static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003356e1000_clean_tx_irq(struct e1000_adapter *adapter,
3357 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 struct net_device *netdev = adapter->netdev;
3360 struct e1000_tx_desc *tx_desc, *eop_desc;
3361 struct e1000_buffer *buffer_info;
3362 unsigned int i, eop;
3363 boolean_t cleaned = FALSE;
3364
3365 i = tx_ring->next_to_clean;
3366 eop = tx_ring->buffer_info[i].next_to_watch;
3367 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3368
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003369 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 for(cleaned = FALSE; !cleaned; ) {
3371 tx_desc = E1000_TX_DESC(*tx_ring, i);
3372 buffer_info = &tx_ring->buffer_info[i];
3373 cleaned = (i == eop);
3374
Jeff Kirsherfd803242005-12-13 00:06:22 -05003375 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376
3377 tx_desc->buffer_addr = 0;
3378 tx_desc->lower.data = 0;
3379 tx_desc->upper.data = 0;
3380
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 if(unlikely(++i == tx_ring->count)) i = 0;
3382 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003383
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003384#ifdef CONFIG_E1000_MQ
3385 tx_ring->tx_stats.packets++;
3386#endif
3387
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 eop = tx_ring->buffer_info[i].next_to_watch;
3389 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3390 }
3391
3392 tx_ring->next_to_clean = i;
3393
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003394 spin_lock(&tx_ring->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
3396 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
3397 netif_carrier_ok(netdev)))
3398 netif_wake_queue(netdev);
3399
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003400 spin_unlock(&tx_ring->tx_lock);
Malli Chilakala26483452005-04-28 19:44:46 -07003401
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003402 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003403 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 * check with the clearing of time_stamp and movement of i */
3405 adapter->detect_tx_hung = FALSE;
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003406 if (tx_ring->buffer_info[i].dma &&
3407 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
3408 && !(E1000_READ_REG(&adapter->hw, STATUS) &
3409 E1000_STATUS_TXOFF)) {
3410
3411 /* detected Tx unit hang */
3412 i = tx_ring->next_to_clean;
3413 eop = tx_ring->buffer_info[i].next_to_watch;
3414 eop_desc = E1000_TX_DESC(*tx_ring, eop);
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003415 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003416 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003417 " TDH <%x>\n"
3418 " TDT <%x>\n"
3419 " next_to_use <%x>\n"
3420 " next_to_clean <%x>\n"
3421 "buffer_info[next_to_clean]\n"
Andrew Mortonb4ee21f2005-07-27 01:14:44 -07003422 " dma <%llx>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003423 " time_stamp <%lx>\n"
3424 " next_to_watch <%x>\n"
3425 " jiffies <%lx>\n"
3426 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003427 (unsigned long)((tx_ring - adapter->tx_ring) /
3428 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003429 readl(adapter->hw.hw_addr + tx_ring->tdh),
3430 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003431 tx_ring->next_to_use,
3432 i,
Andrew Mortonb4ee21f2005-07-27 01:14:44 -07003433 (unsigned long long)tx_ring->buffer_info[i].dma,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003434 tx_ring->buffer_info[i].time_stamp,
3435 eop,
3436 jiffies,
3437 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 return cleaned;
3442}
3443
3444/**
3445 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003446 * @adapter: board private structure
3447 * @status_err: receive descriptor status and error fields
3448 * @csum: receive descriptor csum field
3449 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 **/
3451
3452static inline void
3453e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003454 uint32_t status_err, uint32_t csum,
3455 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003457 uint16_t status = (uint16_t)status_err;
3458 uint8_t errors = (uint8_t)(status_err >> 24);
3459 skb->ip_summed = CHECKSUM_NONE;
3460
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 /* 82543 or newer only */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003462 if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 /* Ignore Checksum bit is set */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003464 if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
3465 /* TCP/UDP checksum error bit is set */
3466 if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
3467 /* let the stack verify checksum errors */
3468 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 return;
3470 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003471 /* TCP/UDP Checksum has not been calculated */
3472 if(adapter->hw.mac_type <= e1000_82547_rev_2) {
3473 if(!(status & E1000_RXD_STAT_TCPCS))
3474 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003476 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3477 return;
3478 }
3479 /* It must be a TCP or UDP packet with a valid checksum */
3480 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 /* TCP checksum is good */
3482 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003483 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3484 /* IP fragment with UDP payload */
3485 /* Hardware complements the payload checksum, so we undo it
3486 * and then put the value in host order for further stack use.
3487 */
3488 csum = ntohl(csum ^ 0xFFFF);
3489 skb->csum = csum;
3490 skb->ip_summed = CHECKSUM_HW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003492 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493}
3494
3495/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003496 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 * @adapter: board private structure
3498 **/
3499
3500static boolean_t
3501#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003502e1000_clean_rx_irq(struct e1000_adapter *adapter,
3503 struct e1000_rx_ring *rx_ring,
3504 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003506e1000_clean_rx_irq(struct e1000_adapter *adapter,
3507 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508#endif
3509{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 struct net_device *netdev = adapter->netdev;
3511 struct pci_dev *pdev = adapter->pdev;
3512 struct e1000_rx_desc *rx_desc;
3513 struct e1000_buffer *buffer_info;
3514 struct sk_buff *skb;
3515 unsigned long flags;
3516 uint32_t length;
3517 uint8_t last_byte;
3518 unsigned int i;
3519 boolean_t cleaned = FALSE;
3520
3521 i = rx_ring->next_to_clean;
3522 rx_desc = E1000_RX_DESC(*rx_ring, i);
3523
3524 while(rx_desc->status & E1000_RXD_STAT_DD) {
3525 buffer_info = &rx_ring->buffer_info[i];
3526#ifdef CONFIG_E1000_NAPI
3527 if(*work_done >= work_to_do)
3528 break;
3529 (*work_done)++;
3530#endif
3531 cleaned = TRUE;
3532
3533 pci_unmap_single(pdev,
3534 buffer_info->dma,
3535 buffer_info->length,
3536 PCI_DMA_FROMDEVICE);
3537
3538 skb = buffer_info->skb;
3539 length = le16_to_cpu(rx_desc->length);
3540
3541 if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
3542 /* All receives must fit into a single buffer */
3543 E1000_DBG("%s: Receive packet consumed multiple"
Malli Chilakala26483452005-04-28 19:44:46 -07003544 " buffers\n", netdev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 dev_kfree_skb_irq(skb);
3546 goto next_desc;
3547 }
3548
3549 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3550 last_byte = *(skb->data + length - 1);
3551 if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
3552 rx_desc->errors, length, last_byte)) {
3553 spin_lock_irqsave(&adapter->stats_lock, flags);
3554 e1000_tbi_adjust_stats(&adapter->hw,
3555 &adapter->stats,
3556 length, skb->data);
3557 spin_unlock_irqrestore(&adapter->stats_lock,
3558 flags);
3559 length--;
3560 } else {
3561 dev_kfree_skb_irq(skb);
3562 goto next_desc;
3563 }
3564 }
3565
3566 /* Good Receive */
3567 skb_put(skb, length - ETHERNET_FCS_SIZE);
3568
3569 /* Receive Checksum Offload */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003570 e1000_rx_checksum(adapter,
3571 (uint32_t)(rx_desc->status) |
3572 ((uint32_t)(rx_desc->errors) << 24),
3573 rx_desc->csum, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 skb->protocol = eth_type_trans(skb, netdev);
3575#ifdef CONFIG_E1000_NAPI
3576 if(unlikely(adapter->vlgrp &&
3577 (rx_desc->status & E1000_RXD_STAT_VP))) {
3578 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003579 le16_to_cpu(rx_desc->special) &
3580 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 } else {
3582 netif_receive_skb(skb);
3583 }
3584#else /* CONFIG_E1000_NAPI */
3585 if(unlikely(adapter->vlgrp &&
3586 (rx_desc->status & E1000_RXD_STAT_VP))) {
3587 vlan_hwaccel_rx(skb, adapter->vlgrp,
3588 le16_to_cpu(rx_desc->special) &
3589 E1000_RXD_SPC_VLAN_MASK);
3590 } else {
3591 netif_rx(skb);
3592 }
3593#endif /* CONFIG_E1000_NAPI */
3594 netdev->last_rx = jiffies;
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003595#ifdef CONFIG_E1000_MQ
3596 rx_ring->rx_stats.packets++;
3597 rx_ring->rx_stats.bytes += length;
3598#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599
3600next_desc:
3601 rx_desc->status = 0;
3602 buffer_info->skb = NULL;
3603 if(unlikely(++i == rx_ring->count)) i = 0;
3604
3605 rx_desc = E1000_RX_DESC(*rx_ring, i);
3606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 rx_ring->next_to_clean = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003608 adapter->alloc_rx_buf(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609
3610 return cleaned;
3611}
3612
3613/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003614 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3615 * @adapter: board private structure
3616 **/
3617
3618static boolean_t
3619#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003620e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3621 struct e1000_rx_ring *rx_ring,
3622 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003623#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003624e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3625 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003626#endif
3627{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003628 union e1000_rx_desc_packet_split *rx_desc;
3629 struct net_device *netdev = adapter->netdev;
3630 struct pci_dev *pdev = adapter->pdev;
3631 struct e1000_buffer *buffer_info;
3632 struct e1000_ps_page *ps_page;
3633 struct e1000_ps_page_dma *ps_page_dma;
3634 struct sk_buff *skb;
3635 unsigned int i, j;
3636 uint32_t length, staterr;
3637 boolean_t cleaned = FALSE;
3638
3639 i = rx_ring->next_to_clean;
3640 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003641 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003642
3643 while(staterr & E1000_RXD_STAT_DD) {
3644 buffer_info = &rx_ring->buffer_info[i];
3645 ps_page = &rx_ring->ps_page[i];
3646 ps_page_dma = &rx_ring->ps_page_dma[i];
3647#ifdef CONFIG_E1000_NAPI
3648 if(unlikely(*work_done >= work_to_do))
3649 break;
3650 (*work_done)++;
3651#endif
3652 cleaned = TRUE;
3653 pci_unmap_single(pdev, buffer_info->dma,
3654 buffer_info->length,
3655 PCI_DMA_FROMDEVICE);
3656
3657 skb = buffer_info->skb;
3658
3659 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3660 E1000_DBG("%s: Packet Split buffers didn't pick up"
3661 " the full packet\n", netdev->name);
3662 dev_kfree_skb_irq(skb);
3663 goto next_desc;
3664 }
3665
3666 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3667 dev_kfree_skb_irq(skb);
3668 goto next_desc;
3669 }
3670
3671 length = le16_to_cpu(rx_desc->wb.middle.length0);
3672
3673 if(unlikely(!length)) {
3674 E1000_DBG("%s: Last part of the packet spanning"
3675 " multiple descriptors\n", netdev->name);
3676 dev_kfree_skb_irq(skb);
3677 goto next_desc;
3678 }
3679
3680 /* Good Receive */
3681 skb_put(skb, length);
3682
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003683 for(j = 0; j < adapter->rx_ps_pages; j++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003684 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3685 break;
3686
3687 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3688 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3689 ps_page_dma->ps_page_dma[j] = 0;
3690 skb_shinfo(skb)->frags[j].page =
3691 ps_page->ps_page[j];
3692 ps_page->ps_page[j] = NULL;
3693 skb_shinfo(skb)->frags[j].page_offset = 0;
3694 skb_shinfo(skb)->frags[j].size = length;
3695 skb_shinfo(skb)->nr_frags++;
3696 skb->len += length;
3697 skb->data_len += length;
3698 }
3699
3700 e1000_rx_checksum(adapter, staterr,
3701 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3702 skb->protocol = eth_type_trans(skb, netdev);
3703
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003704 if(likely(rx_desc->wb.upper.header_status &
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003705 E1000_RXDPS_HDRSTAT_HDRSP)) {
3706 adapter->rx_hdr_split++;
3707#ifdef HAVE_RX_ZERO_COPY
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003708 skb_shinfo(skb)->zero_copy = TRUE;
3709#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003710 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003711#ifdef CONFIG_E1000_NAPI
3712 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3713 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003714 le16_to_cpu(rx_desc->wb.middle.vlan) &
3715 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003716 } else {
3717 netif_receive_skb(skb);
3718 }
3719#else /* CONFIG_E1000_NAPI */
3720 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3721 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003722 le16_to_cpu(rx_desc->wb.middle.vlan) &
3723 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003724 } else {
3725 netif_rx(skb);
3726 }
3727#endif /* CONFIG_E1000_NAPI */
3728 netdev->last_rx = jiffies;
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003729#ifdef CONFIG_E1000_MQ
3730 rx_ring->rx_stats.packets++;
3731 rx_ring->rx_stats.bytes += length;
3732#endif
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003733
3734next_desc:
3735 rx_desc->wb.middle.status_error &= ~0xFF;
3736 buffer_info->skb = NULL;
3737 if(unlikely(++i == rx_ring->count)) i = 0;
3738
3739 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003740 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003741 }
3742 rx_ring->next_to_clean = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003743 adapter->alloc_rx_buf(adapter, rx_ring);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003744
3745 return cleaned;
3746}
3747
3748/**
3749 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 * @adapter: address of board private structure
3751 **/
3752
3753static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003754e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3755 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 struct net_device *netdev = adapter->netdev;
3758 struct pci_dev *pdev = adapter->pdev;
3759 struct e1000_rx_desc *rx_desc;
3760 struct e1000_buffer *buffer_info;
3761 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003762 unsigned int i;
3763 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764
3765 i = rx_ring->next_to_use;
3766 buffer_info = &rx_ring->buffer_info[i];
3767
3768 while(!buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 skb = dev_alloc_skb(bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07003770
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 if(unlikely(!skb)) {
3772 /* Better luck next round */
3773 break;
3774 }
3775
Malli Chilakala26483452005-04-28 19:44:46 -07003776 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3778 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003779 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3780 "at %p\n", bufsz, skb->data);
3781 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 skb = dev_alloc_skb(bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07003783 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 if (!skb) {
3785 dev_kfree_skb(oldskb);
3786 break;
3787 }
Malli Chilakala26483452005-04-28 19:44:46 -07003788
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3790 /* give up */
3791 dev_kfree_skb(skb);
3792 dev_kfree_skb(oldskb);
3793 break; /* while !buffer_info->skb */
3794 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07003795 /* Use new allocation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 dev_kfree_skb(oldskb);
3797 }
3798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 /* Make buffer alignment 2 beyond a 16 byte boundary
3800 * this will result in a 16 byte aligned IP header after
3801 * the 14 byte MAC header is removed
3802 */
3803 skb_reserve(skb, NET_IP_ALIGN);
3804
3805 skb->dev = netdev;
3806
3807 buffer_info->skb = skb;
3808 buffer_info->length = adapter->rx_buffer_len;
3809 buffer_info->dma = pci_map_single(pdev,
3810 skb->data,
3811 adapter->rx_buffer_len,
3812 PCI_DMA_FROMDEVICE);
3813
Malli Chilakala26483452005-04-28 19:44:46 -07003814 /* Fix for errata 23, can't cross 64kB boundary */
3815 if (!e1000_check_64k_bound(adapter,
3816 (void *)(unsigned long)buffer_info->dma,
3817 adapter->rx_buffer_len)) {
3818 DPRINTK(RX_ERR, ERR,
3819 "dma align check failed: %u bytes at %p\n",
3820 adapter->rx_buffer_len,
3821 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 dev_kfree_skb(skb);
3823 buffer_info->skb = NULL;
3824
Malli Chilakala26483452005-04-28 19:44:46 -07003825 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 adapter->rx_buffer_len,
3827 PCI_DMA_FROMDEVICE);
3828
3829 break; /* while !buffer_info->skb */
3830 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 rx_desc = E1000_RX_DESC(*rx_ring, i);
3832 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3833
3834 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3835 /* Force memory writes to complete before letting h/w
3836 * know there are new descriptors to fetch. (Only
3837 * applicable for weak-ordered memory model archs,
3838 * such as IA-64). */
3839 wmb();
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003840 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 }
3842
3843 if(unlikely(++i == rx_ring->count)) i = 0;
3844 buffer_info = &rx_ring->buffer_info[i];
3845 }
3846
3847 rx_ring->next_to_use = i;
3848}
3849
3850/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003851 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3852 * @adapter: address of board private structure
3853 **/
3854
3855static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003856e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3857 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003858{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003859 struct net_device *netdev = adapter->netdev;
3860 struct pci_dev *pdev = adapter->pdev;
3861 union e1000_rx_desc_packet_split *rx_desc;
3862 struct e1000_buffer *buffer_info;
3863 struct e1000_ps_page *ps_page;
3864 struct e1000_ps_page_dma *ps_page_dma;
3865 struct sk_buff *skb;
3866 unsigned int i, j;
3867
3868 i = rx_ring->next_to_use;
3869 buffer_info = &rx_ring->buffer_info[i];
3870 ps_page = &rx_ring->ps_page[i];
3871 ps_page_dma = &rx_ring->ps_page_dma[i];
3872
3873 while(!buffer_info->skb) {
3874 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3875
3876 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003877 if (j < adapter->rx_ps_pages) {
3878 if (likely(!ps_page->ps_page[j])) {
3879 ps_page->ps_page[j] =
3880 alloc_page(GFP_ATOMIC);
3881 if (unlikely(!ps_page->ps_page[j]))
3882 goto no_buffers;
3883 ps_page_dma->ps_page_dma[j] =
3884 pci_map_page(pdev,
3885 ps_page->ps_page[j],
3886 0, PAGE_SIZE,
3887 PCI_DMA_FROMDEVICE);
3888 }
3889 /* Refresh the desc even if buffer_addrs didn't
3890 * change because each write-back erases
3891 * this info.
3892 */
3893 rx_desc->read.buffer_addr[j+1] =
3894 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3895 } else
3896 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003897 }
3898
3899 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3900
3901 if(unlikely(!skb))
3902 break;
3903
3904 /* Make buffer alignment 2 beyond a 16 byte boundary
3905 * this will result in a 16 byte aligned IP header after
3906 * the 14 byte MAC header is removed
3907 */
3908 skb_reserve(skb, NET_IP_ALIGN);
3909
3910 skb->dev = netdev;
3911
3912 buffer_info->skb = skb;
3913 buffer_info->length = adapter->rx_ps_bsize0;
3914 buffer_info->dma = pci_map_single(pdev, skb->data,
3915 adapter->rx_ps_bsize0,
3916 PCI_DMA_FROMDEVICE);
3917
3918 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
3919
3920 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3921 /* Force memory writes to complete before letting h/w
3922 * know there are new descriptors to fetch. (Only
3923 * applicable for weak-ordered memory model archs,
3924 * such as IA-64). */
3925 wmb();
3926 /* Hardware increments by 16 bytes, but packet split
3927 * descriptors are 32 bytes...so we increment tail
3928 * twice as much.
3929 */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003930 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003931 }
3932
3933 if(unlikely(++i == rx_ring->count)) i = 0;
3934 buffer_info = &rx_ring->buffer_info[i];
3935 ps_page = &rx_ring->ps_page[i];
3936 ps_page_dma = &rx_ring->ps_page_dma[i];
3937 }
3938
3939no_buffers:
3940 rx_ring->next_to_use = i;
3941}
3942
3943/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
3945 * @adapter:
3946 **/
3947
3948static void
3949e1000_smartspeed(struct e1000_adapter *adapter)
3950{
3951 uint16_t phy_status;
3952 uint16_t phy_ctrl;
3953
3954 if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
3955 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
3956 return;
3957
3958 if(adapter->smartspeed == 0) {
3959 /* If Master/Slave config fault is asserted twice,
3960 * we assume back-to-back */
3961 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3962 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3963 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
3964 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
3965 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3966 if(phy_ctrl & CR_1000T_MS_ENABLE) {
3967 phy_ctrl &= ~CR_1000T_MS_ENABLE;
3968 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
3969 phy_ctrl);
3970 adapter->smartspeed++;
3971 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3972 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
3973 &phy_ctrl)) {
3974 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3975 MII_CR_RESTART_AUTO_NEG);
3976 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
3977 phy_ctrl);
3978 }
3979 }
3980 return;
3981 } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
3982 /* If still no link, perhaps using 2/3 pair cable */
3983 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
3984 phy_ctrl |= CR_1000T_MS_ENABLE;
3985 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
3986 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
3987 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
3988 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
3989 MII_CR_RESTART_AUTO_NEG);
3990 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
3991 }
3992 }
3993 /* Restart process after E1000_SMARTSPEED_MAX iterations */
3994 if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
3995 adapter->smartspeed = 0;
3996}
3997
3998/**
3999 * e1000_ioctl -
4000 * @netdev:
4001 * @ifreq:
4002 * @cmd:
4003 **/
4004
4005static int
4006e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4007{
4008 switch (cmd) {
4009 case SIOCGMIIPHY:
4010 case SIOCGMIIREG:
4011 case SIOCSMIIREG:
4012 return e1000_mii_ioctl(netdev, ifr, cmd);
4013 default:
4014 return -EOPNOTSUPP;
4015 }
4016}
4017
4018/**
4019 * e1000_mii_ioctl -
4020 * @netdev:
4021 * @ifreq:
4022 * @cmd:
4023 **/
4024
4025static int
4026e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4027{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004028 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 struct mii_ioctl_data *data = if_mii(ifr);
4030 int retval;
4031 uint16_t mii_reg;
4032 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004033 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034
4035 if(adapter->hw.media_type != e1000_media_type_copper)
4036 return -EOPNOTSUPP;
4037
4038 switch (cmd) {
4039 case SIOCGMIIPHY:
4040 data->phy_id = adapter->hw.phy_addr;
4041 break;
4042 case SIOCGMIIREG:
Malli Chilakala97876fc2005-06-17 17:40:19 -07004043 if(!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004045 spin_lock_irqsave(&adapter->stats_lock, flags);
4046 if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4047 &data->val_out)) {
4048 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004050 }
4051 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 break;
4053 case SIOCSMIIREG:
Malli Chilakala97876fc2005-06-17 17:40:19 -07004054 if(!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004056 if(data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 return -EFAULT;
4058 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004059 spin_lock_irqsave(&adapter->stats_lock, flags);
4060 if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
4061 mii_reg)) {
4062 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004064 }
4065 if(adapter->hw.phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 switch (data->reg_num) {
4067 case PHY_CTRL:
4068 if(mii_reg & MII_CR_POWER_DOWN)
4069 break;
4070 if(mii_reg & MII_CR_AUTO_NEG_EN) {
4071 adapter->hw.autoneg = 1;
4072 adapter->hw.autoneg_advertised = 0x2F;
4073 } else {
4074 if (mii_reg & 0x40)
4075 spddplx = SPEED_1000;
4076 else if (mii_reg & 0x2000)
4077 spddplx = SPEED_100;
4078 else
4079 spddplx = SPEED_10;
4080 spddplx += (mii_reg & 0x100)
4081 ? FULL_DUPLEX :
4082 HALF_DUPLEX;
4083 retval = e1000_set_spd_dplx(adapter,
4084 spddplx);
Malli Chilakala97876fc2005-06-17 17:40:19 -07004085 if(retval) {
4086 spin_unlock_irqrestore(
4087 &adapter->stats_lock,
4088 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004090 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 }
4092 if(netif_running(adapter->netdev)) {
4093 e1000_down(adapter);
4094 e1000_up(adapter);
4095 } else
4096 e1000_reset(adapter);
4097 break;
4098 case M88E1000_PHY_SPEC_CTRL:
4099 case M88E1000_EXT_PHY_SPEC_CTRL:
Malli Chilakala97876fc2005-06-17 17:40:19 -07004100 if(e1000_phy_reset(&adapter->hw)) {
4101 spin_unlock_irqrestore(
4102 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105 break;
4106 }
4107 } else {
4108 switch (data->reg_num) {
4109 case PHY_CTRL:
4110 if(mii_reg & MII_CR_POWER_DOWN)
4111 break;
4112 if(netif_running(adapter->netdev)) {
4113 e1000_down(adapter);
4114 e1000_up(adapter);
4115 } else
4116 e1000_reset(adapter);
4117 break;
4118 }
4119 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004120 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 break;
4122 default:
4123 return -EOPNOTSUPP;
4124 }
4125 return E1000_SUCCESS;
4126}
4127
4128void
4129e1000_pci_set_mwi(struct e1000_hw *hw)
4130{
4131 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004132 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133
Malli Chilakala26483452005-04-28 19:44:46 -07004134 if(ret_val)
4135 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136}
4137
4138void
4139e1000_pci_clear_mwi(struct e1000_hw *hw)
4140{
4141 struct e1000_adapter *adapter = hw->back;
4142
4143 pci_clear_mwi(adapter->pdev);
4144}
4145
4146void
4147e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4148{
4149 struct e1000_adapter *adapter = hw->back;
4150
4151 pci_read_config_word(adapter->pdev, reg, value);
4152}
4153
4154void
4155e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4156{
4157 struct e1000_adapter *adapter = hw->back;
4158
4159 pci_write_config_word(adapter->pdev, reg, *value);
4160}
4161
4162uint32_t
4163e1000_io_read(struct e1000_hw *hw, unsigned long port)
4164{
4165 return inl(port);
4166}
4167
4168void
4169e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4170{
4171 outl(value, port);
4172}
4173
4174static void
4175e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4176{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004177 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 uint32_t ctrl, rctl;
4179
4180 e1000_irq_disable(adapter);
4181 adapter->vlgrp = grp;
4182
4183 if(grp) {
4184 /* enable VLAN tag insert/strip */
4185 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4186 ctrl |= E1000_CTRL_VME;
4187 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4188
4189 /* enable VLAN receive filtering */
4190 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4191 rctl |= E1000_RCTL_VFE;
4192 rctl &= ~E1000_RCTL_CFIEN;
4193 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004194 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 } else {
4196 /* disable VLAN tag insert/strip */
4197 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4198 ctrl &= ~E1000_CTRL_VME;
4199 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4200
4201 /* disable VLAN filtering */
4202 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4203 rctl &= ~E1000_RCTL_VFE;
4204 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004205 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4206 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4207 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 }
4210
4211 e1000_irq_enable(adapter);
4212}
4213
4214static void
4215e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4216{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004217 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 uint32_t vfta, index;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004219 if((adapter->hw.mng_cookie.status &
4220 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4221 (vid == adapter->mng_vlan_id))
4222 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 /* add VID to filter table */
4224 index = (vid >> 5) & 0x7F;
4225 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4226 vfta |= (1 << (vid & 0x1F));
4227 e1000_write_vfta(&adapter->hw, index, vfta);
4228}
4229
4230static void
4231e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4232{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004233 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 uint32_t vfta, index;
4235
4236 e1000_irq_disable(adapter);
4237
4238 if(adapter->vlgrp)
4239 adapter->vlgrp->vlan_devices[vid] = NULL;
4240
4241 e1000_irq_enable(adapter);
4242
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004243 if((adapter->hw.mng_cookie.status &
4244 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4245 (vid == adapter->mng_vlan_id))
4246 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 /* remove VID from filter table */
4248 index = (vid >> 5) & 0x7F;
4249 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4250 vfta &= ~(1 << (vid & 0x1F));
4251 e1000_write_vfta(&adapter->hw, index, vfta);
4252}
4253
4254static void
4255e1000_restore_vlan(struct e1000_adapter *adapter)
4256{
4257 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4258
4259 if(adapter->vlgrp) {
4260 uint16_t vid;
4261 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4262 if(!adapter->vlgrp->vlan_devices[vid])
4263 continue;
4264 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4265 }
4266 }
4267}
4268
4269int
4270e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4271{
4272 adapter->hw.autoneg = 0;
4273
Malli Chilakala69213682005-06-17 17:44:20 -07004274 /* Fiber NICs only allow 1000 gbps Full duplex */
4275 if((adapter->hw.media_type == e1000_media_type_fiber) &&
4276 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4277 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4278 return -EINVAL;
4279 }
4280
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 switch(spddplx) {
4282 case SPEED_10 + DUPLEX_HALF:
4283 adapter->hw.forced_speed_duplex = e1000_10_half;
4284 break;
4285 case SPEED_10 + DUPLEX_FULL:
4286 adapter->hw.forced_speed_duplex = e1000_10_full;
4287 break;
4288 case SPEED_100 + DUPLEX_HALF:
4289 adapter->hw.forced_speed_duplex = e1000_100_half;
4290 break;
4291 case SPEED_100 + DUPLEX_FULL:
4292 adapter->hw.forced_speed_duplex = e1000_100_full;
4293 break;
4294 case SPEED_1000 + DUPLEX_FULL:
4295 adapter->hw.autoneg = 1;
4296 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4297 break;
4298 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4299 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004300 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 return -EINVAL;
4302 }
4303 return 0;
4304}
4305
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004306#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004308e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309{
4310 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004311 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004312 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313 uint32_t wufc = adapter->wol;
4314
4315 netif_device_detach(netdev);
4316
4317 if(netif_running(netdev))
4318 e1000_down(adapter);
4319
4320 status = E1000_READ_REG(&adapter->hw, STATUS);
4321 if(status & E1000_STATUS_LU)
4322 wufc &= ~E1000_WUFC_LNKC;
4323
4324 if(wufc) {
4325 e1000_setup_rctl(adapter);
4326 e1000_set_multi(netdev);
4327
4328 /* turn on all-multi mode if wake on multicast is enabled */
4329 if(adapter->wol & E1000_WUFC_MC) {
4330 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4331 rctl |= E1000_RCTL_MPE;
4332 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4333 }
4334
4335 if(adapter->hw.mac_type >= e1000_82540) {
4336 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4337 /* advertise wake from D3Cold */
4338 #define E1000_CTRL_ADVD3WUC 0x00100000
4339 /* phy power management enable */
4340 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4341 ctrl |= E1000_CTRL_ADVD3WUC |
4342 E1000_CTRL_EN_PHY_PWR_MGMT;
4343 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4344 }
4345
4346 if(adapter->hw.media_type == e1000_media_type_fiber ||
4347 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4348 /* keep the laser running in D3 */
4349 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4350 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4351 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4352 }
4353
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004354 /* Allow time for pending master requests to run */
4355 e1000_disable_pciex_master(&adapter->hw);
4356
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4358 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4359 pci_enable_wake(pdev, 3, 1);
4360 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
4361 } else {
4362 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4363 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4364 pci_enable_wake(pdev, 3, 0);
4365 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
4366 }
4367
4368 pci_save_state(pdev);
4369
4370 if(adapter->hw.mac_type >= e1000_82540 &&
4371 adapter->hw.media_type == e1000_media_type_copper) {
4372 manc = E1000_READ_REG(&adapter->hw, MANC);
4373 if(manc & E1000_MANC_SMBUS_EN) {
4374 manc |= E1000_MANC_ARP_EN;
4375 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4376 pci_enable_wake(pdev, 3, 1);
4377 pci_enable_wake(pdev, 4, 1); /* 4 == D3 cold */
4378 }
4379 }
4380
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004381 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4382 * would have already happened in close and is redundant. */
4383 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004384
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 pci_disable_device(pdev);
Pavel Machek829ca9a2005-09-03 15:56:56 -07004386 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387
4388 return 0;
4389}
4390
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391static int
4392e1000_resume(struct pci_dev *pdev)
4393{
4394 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004395 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004396 uint32_t manc, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397
Pavel Machek829ca9a2005-09-03 15:56:56 -07004398 pci_set_power_state(pdev, PCI_D0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 pci_restore_state(pdev);
Malli Chilakala2b028932005-06-17 17:46:06 -07004400 ret_val = pci_enable_device(pdev);
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004401 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402
Pavel Machek829ca9a2005-09-03 15:56:56 -07004403 pci_enable_wake(pdev, PCI_D3hot, 0);
4404 pci_enable_wake(pdev, PCI_D3cold, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405
4406 e1000_reset(adapter);
4407 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4408
4409 if(netif_running(netdev))
4410 e1000_up(adapter);
4411
4412 netif_device_attach(netdev);
4413
4414 if(adapter->hw.mac_type >= e1000_82540 &&
4415 adapter->hw.media_type == e1000_media_type_copper) {
4416 manc = E1000_READ_REG(&adapter->hw, MANC);
4417 manc &= ~(E1000_MANC_ARP_EN);
4418 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4419 }
4420
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004421 /* If the controller is 82573 and f/w is AMT, do not set
4422 * DRV_LOAD until the interface is up. For all other cases,
4423 * let the f/w know that the h/w is now under the control
4424 * of the driver. */
4425 if (adapter->hw.mac_type != e1000_82573 ||
4426 !e1000_check_mng_mode(&adapter->hw))
4427 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004428
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 return 0;
4430}
4431#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432#ifdef CONFIG_NET_POLL_CONTROLLER
4433/*
4434 * Polling 'interrupt' - used by things like netconsole to send skbs
4435 * without having to re-enable interrupts. It's not called while
4436 * the interrupt routine is executing.
4437 */
4438static void
Malli Chilakala26483452005-04-28 19:44:46 -07004439e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004441 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 disable_irq(adapter->pdev->irq);
4443 e1000_intr(adapter->pdev->irq, netdev, NULL);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004444 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445 enable_irq(adapter->pdev->irq);
4446}
4447#endif
4448
4449/* e1000_main.c */