blob: 53a9cca06905f6e036c6ce3dc087551ed001c880 [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),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800100 INTEL_E1000_ETHERNET_DEVICE(0x1099),
Mallikarjuna R Chilakala07b8fed2005-10-19 10:40:08 -0400101 INTEL_E1000_ETHERNET_DEVICE(0x109A),
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800102 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 /* required last entry */
104 {0,}
105};
106
107MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
108
109int e1000_up(struct e1000_adapter *adapter);
110void e1000_down(struct e1000_adapter *adapter);
111void e1000_reset(struct e1000_adapter *adapter);
112int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400113int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
114int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
115void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
116void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100117static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
118 struct e1000_tx_ring *txdr);
119static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
120 struct e1000_rx_ring *rxdr);
121static void e1000_free_tx_resources(struct e1000_adapter *adapter,
122 struct e1000_tx_ring *tx_ring);
123static void e1000_free_rx_resources(struct e1000_adapter *adapter,
124 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125void e1000_update_stats(struct e1000_adapter *adapter);
126
127/* Local Function Prototypes */
128
129static int e1000_init_module(void);
130static void e1000_exit_module(void);
131static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
132static void __devexit e1000_remove(struct pci_dev *pdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400133static int e1000_alloc_queues(struct e1000_adapter *adapter);
134#ifdef CONFIG_E1000_MQ
135static void e1000_setup_queue_mapping(struct e1000_adapter *adapter);
136#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137static int e1000_sw_init(struct e1000_adapter *adapter);
138static int e1000_open(struct net_device *netdev);
139static int e1000_close(struct net_device *netdev);
140static void e1000_configure_tx(struct e1000_adapter *adapter);
141static void e1000_configure_rx(struct e1000_adapter *adapter);
142static void e1000_setup_rctl(struct e1000_adapter *adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400143static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
144static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
145static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
146 struct e1000_tx_ring *tx_ring);
147static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
148 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149static void e1000_set_multi(struct net_device *netdev);
150static void e1000_update_phy_info(unsigned long data);
151static void e1000_watchdog(unsigned long data);
152static void e1000_watchdog_task(struct e1000_adapter *adapter);
153static void e1000_82547_tx_fifo_stall(unsigned long data);
154static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
155static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
156static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
157static int e1000_set_mac(struct net_device *netdev, void *p);
158static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400159static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
160 struct e1000_tx_ring *tx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400162static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400164 struct e1000_rx_ring *rx_ring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 int *work_done, int work_to_do);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700166static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400167 struct e1000_rx_ring *rx_ring,
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700168 int *work_done, int work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400170static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
171 struct e1000_rx_ring *rx_ring);
172static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
173 struct e1000_rx_ring *rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400175static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800176 struct e1000_rx_ring *rx_ring,
177 int cleaned_count);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400178static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800179 struct e1000_rx_ring *rx_ring,
180 int cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
182static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
183 int cmd);
184void e1000_set_ethtool_ops(struct net_device *netdev);
185static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
186static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
187static void e1000_tx_timeout(struct net_device *dev);
188static void e1000_tx_timeout_task(struct net_device *dev);
189static void e1000_smartspeed(struct e1000_adapter *adapter);
190static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
191 struct sk_buff *skb);
192
193static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
194static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
195static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
196static void e1000_restore_vlan(struct e1000_adapter *adapter);
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#ifdef CONFIG_PM
Ashutosh Naik977e74b2005-10-28 15:14:53 -0700199static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200static int e1000_resume(struct pci_dev *pdev);
201#endif
202
203#ifdef CONFIG_NET_POLL_CONTROLLER
204/* for netdump / net console */
205static void e1000_netpoll (struct net_device *netdev);
206#endif
207
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400208#ifdef CONFIG_E1000_MQ
209/* for multiple Rx queues */
210void e1000_rx_schedule(void *data);
211#endif
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213/* Exported from other modules */
214
215extern void e1000_check_options(struct e1000_adapter *adapter);
216
217static struct pci_driver e1000_driver = {
218 .name = e1000_driver_name,
219 .id_table = e1000_pci_tbl,
220 .probe = e1000_probe,
221 .remove = __devexit_p(e1000_remove),
222 /* Power Managment Hooks */
223#ifdef CONFIG_PM
224 .suspend = e1000_suspend,
225 .resume = e1000_resume
226#endif
227};
228
229MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
230MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
231MODULE_LICENSE("GPL");
232MODULE_VERSION(DRV_VERSION);
233
234static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
235module_param(debug, int, 0);
236MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
237
238/**
239 * e1000_init_module - Driver Registration Routine
240 *
241 * e1000_init_module is the first routine called when the driver is
242 * loaded. All it does is register with the PCI subsystem.
243 **/
244
245static int __init
246e1000_init_module(void)
247{
248 int ret;
249 printk(KERN_INFO "%s - version %s\n",
250 e1000_driver_string, e1000_driver_version);
251
252 printk(KERN_INFO "%s\n", e1000_copyright);
253
254 ret = pci_module_init(&e1000_driver);
Tony Luck8b378de2005-07-28 01:07:38 -0700255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 return ret;
257}
258
259module_init(e1000_init_module);
260
261/**
262 * e1000_exit_module - Driver Exit Cleanup Routine
263 *
264 * e1000_exit_module is called just before the driver is removed
265 * from memory.
266 **/
267
268static void __exit
269e1000_exit_module(void)
270{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 pci_unregister_driver(&e1000_driver);
272}
273
274module_exit(e1000_exit_module);
275
276/**
277 * e1000_irq_disable - Mask off interrupt generation on the NIC
278 * @adapter: board private structure
279 **/
280
281static inline void
282e1000_irq_disable(struct e1000_adapter *adapter)
283{
284 atomic_inc(&adapter->irq_sem);
285 E1000_WRITE_REG(&adapter->hw, IMC, ~0);
286 E1000_WRITE_FLUSH(&adapter->hw);
287 synchronize_irq(adapter->pdev->irq);
288}
289
290/**
291 * e1000_irq_enable - Enable default interrupt generation settings
292 * @adapter: board private structure
293 **/
294
295static inline void
296e1000_irq_enable(struct e1000_adapter *adapter)
297{
298 if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
299 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
300 E1000_WRITE_FLUSH(&adapter->hw);
301 }
302}
Adrian Bunk3ad2cc62005-10-30 16:53:34 +0100303
304static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700305e1000_update_mng_vlan(struct e1000_adapter *adapter)
306{
307 struct net_device *netdev = adapter->netdev;
308 uint16_t vid = adapter->hw.mng_cookie.vlan_id;
309 uint16_t old_vid = adapter->mng_vlan_id;
310 if(adapter->vlgrp) {
311 if(!adapter->vlgrp->vlan_devices[vid]) {
312 if(adapter->hw.mng_cookie.status &
313 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
314 e1000_vlan_rx_add_vid(netdev, vid);
315 adapter->mng_vlan_id = vid;
316 } else
317 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
318
319 if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
320 (vid != old_vid) &&
321 !adapter->vlgrp->vlan_devices[old_vid])
322 e1000_vlan_rx_kill_vid(netdev, old_vid);
323 }
324 }
325}
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800326
327/**
328 * e1000_release_hw_control - release control of the h/w to f/w
329 * @adapter: address of board private structure
330 *
331 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
332 * For ASF and Pass Through versions of f/w this means that the
333 * driver is no longer loaded. For AMT version (only with 82573) i
334 * of the f/w this means that the netowrk i/f is closed.
335 *
336 **/
337
338static inline void
339e1000_release_hw_control(struct e1000_adapter *adapter)
340{
341 uint32_t ctrl_ext;
342 uint32_t swsm;
343
344 /* Let firmware taken over control of h/w */
345 switch (adapter->hw.mac_type) {
346 case e1000_82571:
347 case e1000_82572:
348 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
349 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
350 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
351 break;
352 case e1000_82573:
353 swsm = E1000_READ_REG(&adapter->hw, SWSM);
354 E1000_WRITE_REG(&adapter->hw, SWSM,
355 swsm & ~E1000_SWSM_DRV_LOAD);
356 default:
357 break;
358 }
359}
360
361/**
362 * e1000_get_hw_control - get control of the h/w from f/w
363 * @adapter: address of board private structure
364 *
365 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
366 * For ASF and Pass Through versions of f/w this means that
367 * the driver is loaded. For AMT version (only with 82573)
368 * of the f/w this means that the netowrk i/f is open.
369 *
370 **/
371
372static inline void
373e1000_get_hw_control(struct e1000_adapter *adapter)
374{
375 uint32_t ctrl_ext;
376 uint32_t swsm;
377 /* Let firmware know the driver has taken over */
378 switch (adapter->hw.mac_type) {
379 case e1000_82571:
380 case e1000_82572:
381 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
382 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
383 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
384 break;
385 case e1000_82573:
386 swsm = E1000_READ_REG(&adapter->hw, SWSM);
387 E1000_WRITE_REG(&adapter->hw, SWSM,
388 swsm | E1000_SWSM_DRV_LOAD);
389 break;
390 default:
391 break;
392 }
393}
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395int
396e1000_up(struct e1000_adapter *adapter)
397{
398 struct net_device *netdev = adapter->netdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400399 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 /* hardware has been reset, we need to reload some things */
402
403 /* Reset the PHY if it was previously powered down */
404 if(adapter->hw.media_type == e1000_media_type_copper) {
405 uint16_t mii_reg;
406 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
407 if(mii_reg & MII_CR_POWER_DOWN)
408 e1000_phy_reset(&adapter->hw);
409 }
410
411 e1000_set_multi(netdev);
412
413 e1000_restore_vlan(adapter);
414
415 e1000_configure_tx(adapter);
416 e1000_setup_rctl(adapter);
417 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800418 /* call E1000_DESC_UNUSED which always leaves
419 * at least 1 descriptor unused to make sure
420 * next_to_use != next_to_clean */
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800421 for (i = 0; i < adapter->num_rx_queues; i++) {
Jeff Kirsher72d64a42006-01-12 16:51:19 -0800422 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
Jeff Kirshera292ca62006-01-12 16:51:30 -0800423 adapter->alloc_rx_buf(adapter, ring,
424 E1000_DESC_UNUSED(ring));
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700427#ifdef CONFIG_PCI_MSI
428 if(adapter->hw.mac_type > e1000_82547_rev_2) {
429 adapter->have_msi = TRUE;
430 if((err = pci_enable_msi(adapter->pdev))) {
431 DPRINTK(PROBE, ERR,
432 "Unable to allocate MSI interrupt Error: %d\n", err);
433 adapter->have_msi = FALSE;
434 }
435 }
436#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if((err = request_irq(adapter->pdev->irq, &e1000_intr,
438 SA_SHIRQ | SA_SAMPLE_RANDOM,
Malli Chilakala26483452005-04-28 19:44:46 -0700439 netdev->name, netdev))) {
440 DPRINTK(PROBE, ERR,
441 "Unable to allocate interrupt Error: %d\n", err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return err;
Malli Chilakala26483452005-04-28 19:44:46 -0700443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800445#ifdef CONFIG_E1000_MQ
446 e1000_setup_queue_mapping(adapter);
447#endif
448
449 adapter->tx_queue_len = netdev->tx_queue_len;
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 mod_timer(&adapter->watchdog_timer, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453#ifdef CONFIG_E1000_NAPI
454 netif_poll_enable(netdev);
455#endif
Malli Chilakala5de55622005-04-28 19:39:30 -0700456 e1000_irq_enable(adapter);
457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return 0;
459}
460
461void
462e1000_down(struct e1000_adapter *adapter)
463{
464 struct net_device *netdev = adapter->netdev;
Jeff Kirsher57128192006-01-12 16:50:28 -0800465 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
466 e1000_check_mng_mode(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 e1000_irq_disable(adapter);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400469#ifdef CONFIG_E1000_MQ
470 while (atomic_read(&adapter->rx_sched_call_data.count) != 0);
471#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 free_irq(adapter->pdev->irq, netdev);
Malli Chilakalafa4f7ef2005-04-28 19:39:13 -0700473#ifdef CONFIG_PCI_MSI
474 if(adapter->hw.mac_type > e1000_82547_rev_2 &&
475 adapter->have_msi == TRUE)
476 pci_disable_msi(adapter->pdev);
477#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 del_timer_sync(&adapter->tx_fifo_stall_timer);
479 del_timer_sync(&adapter->watchdog_timer);
480 del_timer_sync(&adapter->phy_info_timer);
481
482#ifdef CONFIG_E1000_NAPI
483 netif_poll_disable(netdev);
484#endif
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800485 netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 adapter->link_speed = 0;
487 adapter->link_duplex = 0;
488 netif_carrier_off(netdev);
489 netif_stop_queue(netdev);
490
491 e1000_reset(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400492 e1000_clean_all_tx_rings(adapter);
493 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Jeff Kirsher57128192006-01-12 16:50:28 -0800495 /* Power down the PHY so no link is implied when interface is down *
496 * The PHY cannot be powered down if any of the following is TRUE *
497 * (a) WoL is enabled
498 * (b) AMT is active
499 * (c) SoL/IDER session is active */
500 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700501 adapter->hw.media_type == e1000_media_type_copper &&
Jeff Kirsher57128192006-01-12 16:50:28 -0800502 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
503 !mng_mode_enabled &&
504 !e1000_check_phy_reset_block(&adapter->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 uint16_t mii_reg;
506 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
507 mii_reg |= MII_CR_POWER_DOWN;
508 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
Malli Chilakala4e48a2b2005-04-28 19:39:53 -0700509 mdelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511}
512
513void
514e1000_reset(struct e1000_adapter *adapter)
515{
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700516 uint32_t pba, manc;
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700517 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 /* Repartition Pba for greater than 9k mtu
520 * To take effect CTRL.RST is required.
521 */
522
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700523 switch (adapter->hw.mac_type) {
524 case e1000_82547:
Malli Chilakala0e6ef3e2005-04-28 19:44:14 -0700525 case e1000_82547_rev_2:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700526 pba = E1000_PBA_30K;
527 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400528 case e1000_82571:
529 case e1000_82572:
530 pba = E1000_PBA_38K;
531 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700532 case e1000_82573:
533 pba = E1000_PBA_12K;
534 break;
535 default:
536 pba = E1000_PBA_48K;
537 break;
538 }
539
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700540 if((adapter->hw.mac_type != e1000_82573) &&
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800541 (adapter->netdev->mtu > E1000_RXBUFFER_8192))
Malli Chilakala1125ecb2005-04-28 19:44:25 -0700542 pba -= 8; /* allocate more FIFO for Tx */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700543
544
545 if(adapter->hw.mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 adapter->tx_fifo_head = 0;
547 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
548 adapter->tx_fifo_size =
549 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
550 atomic_set(&adapter->tx_fifo_stall, 0);
551 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 E1000_WRITE_REG(&adapter->hw, PBA, pba);
554
555 /* flow control settings */
Jeff Kirsherf11b7f82006-01-12 16:50:51 -0800556 /* Set the FC high water mark to 90% of the FIFO size.
557 * Required to clear last 3 LSB */
558 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
559
560 adapter->hw.fc_high_water = fc_high_water_mark;
561 adapter->hw.fc_low_water = fc_high_water_mark - 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
563 adapter->hw.fc_send_xon = 1;
564 adapter->hw.fc = adapter->hw.original_fc;
565
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700566 /* Allow time for pending master requests to run */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 e1000_reset_hw(&adapter->hw);
568 if(adapter->hw.mac_type >= e1000_82544)
569 E1000_WRITE_REG(&adapter->hw, WUC, 0);
570 if(e1000_init_hw(&adapter->hw))
571 DPRINTK(PROBE, ERR, "Hardware Error\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700572 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
574 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
575
576 e1000_reset_adaptive(&adapter->hw);
577 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700578 if (adapter->en_mng_pt) {
579 manc = E1000_READ_REG(&adapter->hw, MANC);
580 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
581 E1000_WRITE_REG(&adapter->hw, MANC, manc);
582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583}
584
585/**
586 * e1000_probe - Device Initialization Routine
587 * @pdev: PCI device information struct
588 * @ent: entry in e1000_pci_tbl
589 *
590 * Returns 0 on success, negative on failure
591 *
592 * e1000_probe initializes an adapter identified by a pci_dev structure.
593 * The OS initialization, configuring of the adapter private structure,
594 * and a hardware reset occur.
595 **/
596
597static int __devinit
598e1000_probe(struct pci_dev *pdev,
599 const struct pci_device_id *ent)
600{
601 struct net_device *netdev;
602 struct e1000_adapter *adapter;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700603 unsigned long mmio_start, mmio_len;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 static int cards_found = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700606 int i, err, pci_using_dac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 uint16_t eeprom_data;
608 uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 if((err = pci_enable_device(pdev)))
610 return err;
611
612 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
613 pci_using_dac = 1;
614 } else {
615 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
616 E1000_ERR("No usable DMA configuration, aborting\n");
617 return err;
618 }
619 pci_using_dac = 0;
620 }
621
622 if((err = pci_request_regions(pdev, e1000_driver_name)))
623 return err;
624
625 pci_set_master(pdev);
626
627 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
628 if(!netdev) {
629 err = -ENOMEM;
630 goto err_alloc_etherdev;
631 }
632
633 SET_MODULE_OWNER(netdev);
634 SET_NETDEV_DEV(netdev, &pdev->dev);
635
636 pci_set_drvdata(pdev, netdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700637 adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 adapter->netdev = netdev;
639 adapter->pdev = pdev;
640 adapter->hw.back = adapter;
641 adapter->msg_enable = (1 << debug) - 1;
642
643 mmio_start = pci_resource_start(pdev, BAR_0);
644 mmio_len = pci_resource_len(pdev, BAR_0);
645
646 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
647 if(!adapter->hw.hw_addr) {
648 err = -EIO;
649 goto err_ioremap;
650 }
651
652 for(i = BAR_1; i <= BAR_5; i++) {
653 if(pci_resource_len(pdev, i) == 0)
654 continue;
655 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
656 adapter->hw.io_base = pci_resource_start(pdev, i);
657 break;
658 }
659 }
660
661 netdev->open = &e1000_open;
662 netdev->stop = &e1000_close;
663 netdev->hard_start_xmit = &e1000_xmit_frame;
664 netdev->get_stats = &e1000_get_stats;
665 netdev->set_multicast_list = &e1000_set_multi;
666 netdev->set_mac_address = &e1000_set_mac;
667 netdev->change_mtu = &e1000_change_mtu;
668 netdev->do_ioctl = &e1000_ioctl;
669 e1000_set_ethtool_ops(netdev);
670 netdev->tx_timeout = &e1000_tx_timeout;
671 netdev->watchdog_timeo = 5 * HZ;
672#ifdef CONFIG_E1000_NAPI
673 netdev->poll = &e1000_clean;
674 netdev->weight = 64;
675#endif
676 netdev->vlan_rx_register = e1000_vlan_rx_register;
677 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
678 netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
679#ifdef CONFIG_NET_POLL_CONTROLLER
680 netdev->poll_controller = e1000_netpoll;
681#endif
682 strcpy(netdev->name, pci_name(pdev));
683
684 netdev->mem_start = mmio_start;
685 netdev->mem_end = mmio_start + mmio_len;
686 netdev->base_addr = adapter->hw.io_base;
687
688 adapter->bd_number = cards_found;
689
690 /* setup the private structure */
691
692 if((err = e1000_sw_init(adapter)))
693 goto err_sw_init;
694
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700695 if((err = e1000_check_phy_reset_block(&adapter->hw)))
696 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if(adapter->hw.mac_type >= e1000_82543) {
699 netdev->features = NETIF_F_SG |
700 NETIF_F_HW_CSUM |
701 NETIF_F_HW_VLAN_TX |
702 NETIF_F_HW_VLAN_RX |
703 NETIF_F_HW_VLAN_FILTER;
704 }
705
706#ifdef NETIF_F_TSO
707 if((adapter->hw.mac_type >= e1000_82544) &&
708 (adapter->hw.mac_type != e1000_82547))
709 netdev->features |= NETIF_F_TSO;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700710
711#ifdef NETIF_F_TSO_IPV6
712 if(adapter->hw.mac_type > e1000_82547_rev_2)
713 netdev->features |= NETIF_F_TSO_IPV6;
714#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#endif
716 if(pci_using_dac)
717 netdev->features |= NETIF_F_HIGHDMA;
718
719 /* hard_start_xmit is safe against parallel locking */
720 netdev->features |= NETIF_F_LLTX;
721
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700722 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
723
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 /* before reading the EEPROM, reset the controller to
725 * put the device in a known good starting state */
726
727 e1000_reset_hw(&adapter->hw);
728
729 /* make sure the EEPROM is good */
730
731 if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
732 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
733 err = -EIO;
734 goto err_eeprom;
735 }
736
737 /* copy the MAC address out of the EEPROM */
738
Malli Chilakala26483452005-04-28 19:44:46 -0700739 if(e1000_read_mac_addr(&adapter->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
741 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
John W. Linville9beb0ac2005-09-12 10:48:55 -0400742 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
John W. Linville9beb0ac2005-09-12 10:48:55 -0400744 if(!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
746 err = -EIO;
747 goto err_eeprom;
748 }
749
750 e1000_read_part_num(&adapter->hw, &(adapter->part_num));
751
752 e1000_get_bus_info(&adapter->hw);
753
754 init_timer(&adapter->tx_fifo_stall_timer);
755 adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
756 adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
757
758 init_timer(&adapter->watchdog_timer);
759 adapter->watchdog_timer.function = &e1000_watchdog;
760 adapter->watchdog_timer.data = (unsigned long) adapter;
761
762 INIT_WORK(&adapter->watchdog_task,
763 (void (*)(void *))e1000_watchdog_task, adapter);
764
765 init_timer(&adapter->phy_info_timer);
766 adapter->phy_info_timer.function = &e1000_update_phy_info;
767 adapter->phy_info_timer.data = (unsigned long) adapter;
768
769 INIT_WORK(&adapter->tx_timeout_task,
770 (void (*)(void *))e1000_tx_timeout_task, netdev);
771
772 /* we're going to reset, so assume we have no link for now */
773
774 netif_carrier_off(netdev);
775 netif_stop_queue(netdev);
776
777 e1000_check_options(adapter);
778
779 /* Initial Wake on LAN setting
780 * If APM wake is enabled in the EEPROM,
781 * enable the ACPI Magic Packet filter
782 */
783
784 switch(adapter->hw.mac_type) {
785 case e1000_82542_rev2_0:
786 case e1000_82542_rev2_1:
787 case e1000_82543:
788 break;
789 case e1000_82544:
790 e1000_read_eeprom(&adapter->hw,
791 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
792 eeprom_apme_mask = E1000_EEPROM_82544_APM;
793 break;
794 case e1000_82546:
795 case e1000_82546_rev_3:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500796 case e1000_82571:
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800797 if(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 e1000_read_eeprom(&adapter->hw,
799 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
800 break;
801 }
802 /* Fall Through */
803 default:
804 e1000_read_eeprom(&adapter->hw,
805 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
806 break;
807 }
808 if(eeprom_data & eeprom_apme_mask)
809 adapter->wol |= E1000_WUFC_MAG;
810
Jeff Kirsherfb3d47d2006-01-12 16:51:25 -0800811 /* print bus type/speed/width info */
812 {
813 struct e1000_hw *hw = &adapter->hw;
814 DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
815 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
816 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
817 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
818 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
819 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
820 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
821 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
822 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
823 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
824 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
825 "32-bit"));
826 }
827
828 for (i = 0; i < 6; i++)
829 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 /* reset the hardware with the new settings */
832 e1000_reset(adapter);
833
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800834 /* If the controller is 82573 and f/w is AMT, do not set
835 * DRV_LOAD until the interface is up. For all other cases,
836 * let the f/w know that the h/w is now under the control
837 * of the driver. */
838 if (adapter->hw.mac_type != e1000_82573 ||
839 !e1000_check_mng_mode(&adapter->hw))
840 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700841
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 strcpy(netdev->name, "eth%d");
843 if((err = register_netdev(netdev)))
844 goto err_register;
845
846 DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
847
848 cards_found++;
849 return 0;
850
851err_register:
852err_sw_init:
853err_eeprom:
854 iounmap(adapter->hw.hw_addr);
855err_ioremap:
856 free_netdev(netdev);
857err_alloc_etherdev:
858 pci_release_regions(pdev);
859 return err;
860}
861
862/**
863 * e1000_remove - Device Removal Routine
864 * @pdev: PCI device information struct
865 *
866 * e1000_remove is called by the PCI subsystem to alert the driver
867 * that it should release a PCI device. The could be caused by a
868 * Hot-Plug event, or because the driver is going to be removed from
869 * memory.
870 **/
871
872static void __devexit
873e1000_remove(struct pci_dev *pdev)
874{
875 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -0700876 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800877 uint32_t manc;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400878#ifdef CONFIG_E1000_NAPI
879 int i;
880#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Jeff Garzikbe2b28e2005-10-04 07:13:43 -0400882 flush_scheduled_work();
883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 if(adapter->hw.mac_type >= e1000_82540 &&
885 adapter->hw.media_type == e1000_media_type_copper) {
886 manc = E1000_READ_REG(&adapter->hw, MANC);
887 if(manc & E1000_MANC_SMBUS_EN) {
888 manc |= E1000_MANC_ARP_EN;
889 E1000_WRITE_REG(&adapter->hw, MANC, manc);
890 }
891 }
892
Jeff Kirsherb55ccb32006-01-12 16:50:30 -0800893 /* Release control of h/w to f/w. If f/w is AMT enabled, this
894 * would have already happened in close and is redundant. */
895 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 unregister_netdev(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400898#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800899 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400900 __dev_put(&adapter->polling_netdev[i]);
901#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700903 if(!e1000_check_phy_reset_block(&adapter->hw))
904 e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400906 kfree(adapter->tx_ring);
907 kfree(adapter->rx_ring);
908#ifdef CONFIG_E1000_NAPI
909 kfree(adapter->polling_netdev);
910#endif
911
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 iounmap(adapter->hw.hw_addr);
913 pci_release_regions(pdev);
914
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400915#ifdef CONFIG_E1000_MQ
916 free_percpu(adapter->cpu_netdev);
917 free_percpu(adapter->cpu_tx_ring);
918#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 free_netdev(netdev);
920
921 pci_disable_device(pdev);
922}
923
924/**
925 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
926 * @adapter: board private structure to initialize
927 *
928 * e1000_sw_init initializes the Adapter private data structure.
929 * Fields are initialized based on PCI device information and
930 * OS network device settings (MTU size).
931 **/
932
933static int __devinit
934e1000_sw_init(struct e1000_adapter *adapter)
935{
936 struct e1000_hw *hw = &adapter->hw;
937 struct net_device *netdev = adapter->netdev;
938 struct pci_dev *pdev = adapter->pdev;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400939#ifdef CONFIG_E1000_NAPI
940 int i;
941#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943 /* PCI config space info */
944
945 hw->vendor_id = pdev->vendor;
946 hw->device_id = pdev->device;
947 hw->subsystem_vendor_id = pdev->subsystem_vendor;
948 hw->subsystem_id = pdev->subsystem_device;
949
950 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
951
952 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
953
954 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700955 adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 hw->max_frame_size = netdev->mtu +
957 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
958 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
959
960 /* identify the MAC */
961
962 if(e1000_set_mac_type(hw)) {
963 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
964 return -EIO;
965 }
966
967 /* initialize eeprom parameters */
968
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700969 if(e1000_init_eeprom_params(hw)) {
970 E1000_ERR("EEPROM initialization failed\n");
971 return -EIO;
972 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
974 switch(hw->mac_type) {
975 default:
976 break;
977 case e1000_82541:
978 case e1000_82547:
979 case e1000_82541_rev_2:
980 case e1000_82547_rev_2:
981 hw->phy_init_script = 1;
982 break;
983 }
984
985 e1000_set_media_type(hw);
986
987 hw->wait_autoneg_complete = FALSE;
988 hw->tbi_compatibility_en = TRUE;
989 hw->adaptive_ifs = TRUE;
990
991 /* Copper options */
992
993 if(hw->media_type == e1000_media_type_copper) {
994 hw->mdix = AUTO_ALL_MODES;
995 hw->disable_polarity_correction = FALSE;
996 hw->master_slave = E1000_MASTER_SLAVE;
997 }
998
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -0400999#ifdef CONFIG_E1000_MQ
1000 /* Number of supported queues */
1001 switch (hw->mac_type) {
1002 case e1000_82571:
1003 case e1000_82572:
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001004 /* These controllers support 2 tx queues, but with a single
1005 * qdisc implementation, multiple tx queues aren't quite as
1006 * interesting. If we can find a logical way of mapping
1007 * flows to a queue, then perhaps we can up the num_tx_queue
1008 * count back to its default. Until then, we run the risk of
1009 * terrible performance due to SACK overload. */
1010 adapter->num_tx_queues = 1;
1011 adapter->num_rx_queues = 2;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001012 break;
1013 default:
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001014 adapter->num_tx_queues = 1;
1015 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001016 break;
1017 }
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001018 adapter->num_rx_queues = min(adapter->num_rx_queues, num_online_cpus());
1019 adapter->num_tx_queues = min(adapter->num_tx_queues, num_online_cpus());
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001020 DPRINTK(DRV, INFO, "Multiqueue Enabled: Rx Queue count = %u %s\n",
1021 adapter->num_rx_queues,
1022 ((adapter->num_rx_queues == 1)
1023 ? ((num_online_cpus() > 1)
1024 ? "(due to unsupported feature in current adapter)"
1025 : "(due to unsupported system configuration)")
1026 : ""));
1027 DPRINTK(DRV, INFO, "Multiqueue Enabled: Tx Queue count = %u\n",
1028 adapter->num_tx_queues);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001029#else
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001030 adapter->num_tx_queues = 1;
1031 adapter->num_rx_queues = 1;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001032#endif
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001033
1034 if (e1000_alloc_queues(adapter)) {
1035 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1036 return -ENOMEM;
1037 }
1038
1039#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001040 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001041 adapter->polling_netdev[i].priv = adapter;
1042 adapter->polling_netdev[i].poll = &e1000_clean;
1043 adapter->polling_netdev[i].weight = 64;
1044 dev_hold(&adapter->polling_netdev[i]);
1045 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1046 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001047 spin_lock_init(&adapter->tx_queue_lock);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001048#endif
1049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 atomic_set(&adapter->irq_sem, 1);
1051 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
1053 return 0;
1054}
1055
1056/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001057 * e1000_alloc_queues - Allocate memory for all rings
1058 * @adapter: board private structure to initialize
1059 *
1060 * We allocate one ring per queue at run-time since we don't know the
1061 * number of queues at compile-time. The polling_netdev array is
1062 * intended for Multiqueue, but should work fine with a single queue.
1063 **/
1064
1065static int __devinit
1066e1000_alloc_queues(struct e1000_adapter *adapter)
1067{
1068 int size;
1069
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001070 size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001071 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1072 if (!adapter->tx_ring)
1073 return -ENOMEM;
1074 memset(adapter->tx_ring, 0, size);
1075
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001076 size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001077 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1078 if (!adapter->rx_ring) {
1079 kfree(adapter->tx_ring);
1080 return -ENOMEM;
1081 }
1082 memset(adapter->rx_ring, 0, size);
1083
1084#ifdef CONFIG_E1000_NAPI
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001085 size = sizeof(struct net_device) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001086 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1087 if (!adapter->polling_netdev) {
1088 kfree(adapter->tx_ring);
1089 kfree(adapter->rx_ring);
1090 return -ENOMEM;
1091 }
1092 memset(adapter->polling_netdev, 0, size);
1093#endif
1094
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001095#ifdef CONFIG_E1000_MQ
1096 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1097 adapter->rx_sched_call_data.info = adapter->netdev;
1098
1099 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1100 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1101#endif
1102
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001103 return E1000_SUCCESS;
1104}
1105
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001106#ifdef CONFIG_E1000_MQ
1107static void __devinit
1108e1000_setup_queue_mapping(struct e1000_adapter *adapter)
1109{
1110 int i, cpu;
1111
1112 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1113 adapter->rx_sched_call_data.info = adapter->netdev;
1114 cpus_clear(adapter->rx_sched_call_data.cpumask);
1115
1116 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1117 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1118
1119 lock_cpu_hotplug();
1120 i = 0;
1121 for_each_online_cpu(cpu) {
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001122 *per_cpu_ptr(adapter->cpu_tx_ring, cpu) = &adapter->tx_ring[i % adapter->num_tx_queues];
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001123 /* This is incomplete because we'd like to assign separate
1124 * physical cpus to these netdev polling structures and
1125 * avoid saturating a subset of cpus.
1126 */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001127 if (i < adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001128 *per_cpu_ptr(adapter->cpu_netdev, cpu) = &adapter->polling_netdev[i];
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001129 adapter->rx_ring[i].cpu = cpu;
1130 cpu_set(cpu, adapter->cpumask);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001131 } else
1132 *per_cpu_ptr(adapter->cpu_netdev, cpu) = NULL;
1133
1134 i++;
1135 }
1136 unlock_cpu_hotplug();
1137}
1138#endif
1139
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001140/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 * e1000_open - Called when a network interface is made active
1142 * @netdev: network interface device structure
1143 *
1144 * Returns 0 on success, negative value on failure
1145 *
1146 * The open entry point is called when a network interface is made
1147 * active by the system (IFF_UP). At this point all resources needed
1148 * for transmit and receive operations are allocated, the interrupt
1149 * handler is registered with the OS, the watchdog timer is started,
1150 * and the stack is notified that the interface is ready.
1151 **/
1152
1153static int
1154e1000_open(struct net_device *netdev)
1155{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001156 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 int err;
1158
1159 /* allocate transmit descriptors */
1160
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001161 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 goto err_setup_tx;
1163
1164 /* allocate receive descriptors */
1165
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001166 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 goto err_setup_rx;
1168
1169 if((err = e1000_up(adapter)))
1170 goto err_up;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001171 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1172 if((adapter->hw.mng_cookie.status &
1173 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1174 e1000_update_mng_vlan(adapter);
1175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001177 /* If AMT is enabled, let the firmware know that the network
1178 * interface is now open */
1179 if (adapter->hw.mac_type == e1000_82573 &&
1180 e1000_check_mng_mode(&adapter->hw))
1181 e1000_get_hw_control(adapter);
1182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 return E1000_SUCCESS;
1184
1185err_up:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001186 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187err_setup_rx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001188 e1000_free_all_tx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189err_setup_tx:
1190 e1000_reset(adapter);
1191
1192 return err;
1193}
1194
1195/**
1196 * e1000_close - Disables a network interface
1197 * @netdev: network interface device structure
1198 *
1199 * Returns 0, this is not allowed to fail
1200 *
1201 * The close entry point is called when an interface is de-activated
1202 * by the OS. The hardware is still under the drivers control, but
1203 * needs to be disabled. A global MAC reset is issued to stop the
1204 * hardware, and all transmit and receive resources are freed.
1205 **/
1206
1207static int
1208e1000_close(struct net_device *netdev)
1209{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001210 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 e1000_down(adapter);
1213
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001214 e1000_free_all_tx_resources(adapter);
1215 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001217 if((adapter->hw.mng_cookie.status &
1218 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1219 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1220 }
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08001221
1222 /* If AMT is enabled, let the firmware know that the network
1223 * interface is now closed */
1224 if (adapter->hw.mac_type == e1000_82573 &&
1225 e1000_check_mng_mode(&adapter->hw))
1226 e1000_release_hw_control(adapter);
1227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 return 0;
1229}
1230
1231/**
1232 * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1233 * @adapter: address of board private structure
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001234 * @start: address of beginning of memory
1235 * @len: length of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 **/
1237static inline boolean_t
1238e1000_check_64k_bound(struct e1000_adapter *adapter,
1239 void *start, unsigned long len)
1240{
1241 unsigned long begin = (unsigned long) start;
1242 unsigned long end = begin + len;
1243
Malli Chilakala26483452005-04-28 19:44:46 -07001244 /* First rev 82545 and 82546 need to not allow any memory
1245 * write location to cross 64k boundary due to errata 23 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 if (adapter->hw.mac_type == e1000_82545 ||
Malli Chilakala26483452005-04-28 19:44:46 -07001247 adapter->hw.mac_type == e1000_82546) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1249 }
1250
1251 return TRUE;
1252}
1253
1254/**
1255 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1256 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001257 * @txdr: tx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 *
1259 * Return 0 on success, negative on failure
1260 **/
1261
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001262static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001263e1000_setup_tx_resources(struct e1000_adapter *adapter,
1264 struct e1000_tx_ring *txdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 struct pci_dev *pdev = adapter->pdev;
1267 int size;
1268
1269 size = sizeof(struct e1000_buffer) * txdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001270
1271 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 if(!txdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001273 DPRINTK(PROBE, ERR,
1274 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 return -ENOMEM;
1276 }
1277 memset(txdr->buffer_info, 0, size);
1278
1279 /* round up to nearest 4K */
1280
1281 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1282 E1000_ROUNDUP(txdr->size, 4096);
1283
1284 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1285 if(!txdr->desc) {
1286setup_tx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 vfree(txdr->buffer_info);
Malli Chilakala26483452005-04-28 19:44:46 -07001288 DPRINTK(PROBE, ERR,
1289 "Unable to allocate memory for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 return -ENOMEM;
1291 }
1292
Malli Chilakala26483452005-04-28 19:44:46 -07001293 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1295 void *olddesc = txdr->desc;
1296 dma_addr_t olddma = txdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001297 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1298 "at %p\n", txdr->size, txdr->desc);
1299 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 if(!txdr->desc) {
Malli Chilakala26483452005-04-28 19:44:46 -07001302 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1304 goto setup_tx_desc_die;
1305 }
1306
1307 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1308 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001309 pci_free_consistent(pdev, txdr->size, txdr->desc,
1310 txdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1312 DPRINTK(PROBE, ERR,
Malli Chilakala26483452005-04-28 19:44:46 -07001313 "Unable to allocate aligned memory "
1314 "for the transmit descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 vfree(txdr->buffer_info);
1316 return -ENOMEM;
1317 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001318 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1320 }
1321 }
1322 memset(txdr->desc, 0, txdr->size);
1323
1324 txdr->next_to_use = 0;
1325 txdr->next_to_clean = 0;
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001326 spin_lock_init(&txdr->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 return 0;
1329}
1330
1331/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001332 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1333 * (Descriptors) for all queues
1334 * @adapter: board private structure
1335 *
1336 * If this function returns with an error, then it's possible one or
1337 * more of the rings is populated (while the rest are not). It is the
1338 * callers duty to clean those orphaned rings.
1339 *
1340 * Return 0 on success, negative on failure
1341 **/
1342
1343int
1344e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1345{
1346 int i, err = 0;
1347
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001348 for (i = 0; i < adapter->num_tx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001349 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1350 if (err) {
1351 DPRINTK(PROBE, ERR,
1352 "Allocation for Tx Queue %u failed\n", i);
1353 break;
1354 }
1355 }
1356
1357 return err;
1358}
1359
1360/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1362 * @adapter: board private structure
1363 *
1364 * Configure the Tx unit of the MAC after a reset.
1365 **/
1366
1367static void
1368e1000_configure_tx(struct e1000_adapter *adapter)
1369{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001370 uint64_t tdba;
1371 struct e1000_hw *hw = &adapter->hw;
1372 uint32_t tdlen, tctl, tipg, tarc;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001373 uint32_t ipgr1, ipgr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
1375 /* Setup the HW Tx Head and Tail descriptor pointers */
1376
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001377 switch (adapter->num_tx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001378 case 2:
1379 tdba = adapter->tx_ring[1].dma;
1380 tdlen = adapter->tx_ring[1].count *
1381 sizeof(struct e1000_tx_desc);
1382 E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
1383 E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
1384 E1000_WRITE_REG(hw, TDLEN1, tdlen);
1385 E1000_WRITE_REG(hw, TDH1, 0);
1386 E1000_WRITE_REG(hw, TDT1, 0);
1387 adapter->tx_ring[1].tdh = E1000_TDH1;
1388 adapter->tx_ring[1].tdt = E1000_TDT1;
1389 /* Fall Through */
1390 case 1:
1391 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001392 tdba = adapter->tx_ring[0].dma;
1393 tdlen = adapter->tx_ring[0].count *
1394 sizeof(struct e1000_tx_desc);
1395 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1396 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1397 E1000_WRITE_REG(hw, TDLEN, tdlen);
1398 E1000_WRITE_REG(hw, TDH, 0);
1399 E1000_WRITE_REG(hw, TDT, 0);
1400 adapter->tx_ring[0].tdh = E1000_TDH;
1401 adapter->tx_ring[0].tdt = E1000_TDT;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001402 break;
1403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
1405 /* Set the default values for the Tx Inter Packet Gap timer */
1406
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001407 if (hw->media_type == e1000_media_type_fiber ||
1408 hw->media_type == e1000_media_type_internal_serdes)
1409 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1410 else
1411 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1412
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001413 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 case e1000_82542_rev2_0:
1415 case e1000_82542_rev2_1:
1416 tipg = DEFAULT_82542_TIPG_IPGT;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001417 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1418 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 break;
1420 default:
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001421 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1422 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1423 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001425 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1426 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001427 E1000_WRITE_REG(hw, TIPG, tipg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
1429 /* Set the Tx Interrupt Delay register */
1430
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001431 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1432 if (hw->mac_type >= e1000_82540)
1433 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
1435 /* Program the Transmit Control Register */
1436
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001437 tctl = E1000_READ_REG(hw, TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
1439 tctl &= ~E1000_TCTL_CT;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001440 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1442
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001443 E1000_WRITE_REG(hw, TCTL, tctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001445 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1446 tarc = E1000_READ_REG(hw, TARC0);
1447 tarc |= ((1 << 25) | (1 << 21));
1448 E1000_WRITE_REG(hw, TARC0, tarc);
1449 tarc = E1000_READ_REG(hw, TARC1);
1450 tarc |= (1 << 25);
1451 if (tctl & E1000_TCTL_MULR)
1452 tarc &= ~(1 << 28);
1453 else
1454 tarc |= (1 << 28);
1455 E1000_WRITE_REG(hw, TARC1, tarc);
1456 }
1457
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001458 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
1460 /* Setup Transmit Descriptor Settings for eop descriptor */
1461 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1462 E1000_TXD_CMD_IFCS;
1463
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001464 if (hw->mac_type < e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1466 else
1467 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1468
1469 /* Cache if we're 82544 running in PCI-X because we'll
1470 * need this to apply a workaround later in the send path. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001471 if (hw->mac_type == e1000_82544 &&
1472 hw->bus_type == e1000_bus_type_pcix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 adapter->pcix_82544 = 1;
1474}
1475
1476/**
1477 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1478 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001479 * @rxdr: rx descriptor ring (for a specific queue) to setup
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 *
1481 * Returns 0 on success, negative on failure
1482 **/
1483
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001484static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001485e1000_setup_rx_resources(struct e1000_adapter *adapter,
1486 struct e1000_rx_ring *rxdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 struct pci_dev *pdev = adapter->pdev;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001489 int size, desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
1491 size = sizeof(struct e1000_buffer) * rxdr->count;
Ravikiran G Thirumalaia7ec15d2005-10-28 15:14:49 -07001492 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001493 if (!rxdr->buffer_info) {
Malli Chilakala26483452005-04-28 19:44:46 -07001494 DPRINTK(PROBE, ERR,
1495 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 return -ENOMEM;
1497 }
1498 memset(rxdr->buffer_info, 0, size);
1499
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001500 size = sizeof(struct e1000_ps_page) * rxdr->count;
1501 rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1502 if(!rxdr->ps_page) {
1503 vfree(rxdr->buffer_info);
1504 DPRINTK(PROBE, ERR,
1505 "Unable to allocate memory for the receive descriptor ring\n");
1506 return -ENOMEM;
1507 }
1508 memset(rxdr->ps_page, 0, size);
1509
1510 size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1511 rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1512 if(!rxdr->ps_page_dma) {
1513 vfree(rxdr->buffer_info);
1514 kfree(rxdr->ps_page);
1515 DPRINTK(PROBE, ERR,
1516 "Unable to allocate memory for the receive descriptor ring\n");
1517 return -ENOMEM;
1518 }
1519 memset(rxdr->ps_page_dma, 0, size);
1520
1521 if(adapter->hw.mac_type <= e1000_82547_rev_2)
1522 desc_len = sizeof(struct e1000_rx_desc);
1523 else
1524 desc_len = sizeof(union e1000_rx_desc_packet_split);
1525
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 /* Round up to nearest 4K */
1527
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001528 rxdr->size = rxdr->count * desc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 E1000_ROUNDUP(rxdr->size, 4096);
1530
1531 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1532
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001533 if (!rxdr->desc) {
1534 DPRINTK(PROBE, ERR,
1535 "Unable to allocate memory for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536setup_rx_desc_die:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 vfree(rxdr->buffer_info);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001538 kfree(rxdr->ps_page);
1539 kfree(rxdr->ps_page_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 return -ENOMEM;
1541 }
1542
Malli Chilakala26483452005-04-28 19:44:46 -07001543 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1545 void *olddesc = rxdr->desc;
1546 dma_addr_t olddma = rxdr->dma;
Malli Chilakala26483452005-04-28 19:44:46 -07001547 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1548 "at %p\n", rxdr->size, rxdr->desc);
1549 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
Malli Chilakala26483452005-04-28 19:44:46 -07001551 /* Failed allocation, critical failure */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001552 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001554 DPRINTK(PROBE, ERR,
1555 "Unable to allocate memory "
1556 "for the receive descriptor ring\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 goto setup_rx_desc_die;
1558 }
1559
1560 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1561 /* give up */
Malli Chilakala26483452005-04-28 19:44:46 -07001562 pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1563 rxdr->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
Malli Chilakala26483452005-04-28 19:44:46 -07001565 DPRINTK(PROBE, ERR,
1566 "Unable to allocate aligned memory "
1567 "for the receive descriptor ring\n");
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001568 goto setup_rx_desc_die;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07001570 /* Free old allocation, new allocation was successful */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1572 }
1573 }
1574 memset(rxdr->desc, 0, rxdr->size);
1575
1576 rxdr->next_to_clean = 0;
1577 rxdr->next_to_use = 0;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08001578 rxdr->rx_skb_top = NULL;
1579 rxdr->rx_skb_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
1581 return 0;
1582}
1583
1584/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001585 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1586 * (Descriptors) for all queues
1587 * @adapter: board private structure
1588 *
1589 * If this function returns with an error, then it's possible one or
1590 * more of the rings is populated (while the rest are not). It is the
1591 * callers duty to clean those orphaned rings.
1592 *
1593 * Return 0 on success, negative on failure
1594 **/
1595
1596int
1597e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1598{
1599 int i, err = 0;
1600
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001601 for (i = 0; i < adapter->num_rx_queues; i++) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001602 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1603 if (err) {
1604 DPRINTK(PROBE, ERR,
1605 "Allocation for Rx Queue %u failed\n", i);
1606 break;
1607 }
1608 }
1609
1610 return err;
1611}
1612
1613/**
Malli Chilakala26483452005-04-28 19:44:46 -07001614 * e1000_setup_rctl - configure the receive control registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 * @adapter: Board private structure
1616 **/
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001617#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1618 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619static void
1620e1000_setup_rctl(struct e1000_adapter *adapter)
1621{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001622 uint32_t rctl, rfctl;
1623 uint32_t psrctl = 0;
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001624#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001625 uint32_t pages = 0;
1626#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
1628 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1629
1630 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1631
1632 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1633 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1634 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1635
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001636 if (adapter->hw.mac_type > e1000_82543)
1637 rctl |= E1000_RCTL_SECRC;
1638
1639 if (adapter->hw.tbi_compatibility_on == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 rctl |= E1000_RCTL_SBP;
1641 else
1642 rctl &= ~E1000_RCTL_SBP;
1643
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001644 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1645 rctl &= ~E1000_RCTL_LPE;
1646 else
1647 rctl |= E1000_RCTL_LPE;
1648
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 /* Setup buffer sizes */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001650 if(adapter->hw.mac_type >= e1000_82571) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001651 /* We can now specify buffers in 1K increments.
1652 * BSIZE and BSEX are ignored in this case. */
1653 rctl |= adapter->rx_buffer_len << 0x11;
1654 } else {
1655 rctl &= ~E1000_RCTL_SZ_4096;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08001656 rctl &= ~E1000_RCTL_BSEX;
1657 rctl |= E1000_RCTL_SZ_2048;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001658 }
1659
Jesse Brandeburg35ec56b2006-01-18 13:01:30 -08001660#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001661 /* 82571 and greater support packet-split where the protocol
1662 * header is placed in skb->data and the packet data is
1663 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1664 * In the case of a non-split, skb->data is linearly filled,
1665 * followed by the page buffers. Therefore, skb->data is
1666 * sized to hold the largest protocol header.
1667 */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001668 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1669 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1670 PAGE_SIZE <= 16384)
1671 adapter->rx_ps_pages = pages;
1672 else
1673 adapter->rx_ps_pages = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001674#endif
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001675 if (adapter->rx_ps_pages) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001676 /* Configure extra packet-split registers */
1677 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1678 rfctl |= E1000_RFCTL_EXTEN;
1679 /* disable IPv6 packet split support */
1680 rfctl |= E1000_RFCTL_IPV6_DIS;
1681 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1682
1683 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1684
1685 psrctl |= adapter->rx_ps_bsize0 >>
1686 E1000_PSRCTL_BSIZE0_SHIFT;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001687
1688 switch (adapter->rx_ps_pages) {
1689 case 3:
1690 psrctl |= PAGE_SIZE <<
1691 E1000_PSRCTL_BSIZE3_SHIFT;
1692 case 2:
1693 psrctl |= PAGE_SIZE <<
1694 E1000_PSRCTL_BSIZE2_SHIFT;
1695 case 1:
1696 psrctl |= PAGE_SIZE >>
1697 E1000_PSRCTL_BSIZE1_SHIFT;
1698 break;
1699 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001700
1701 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 }
1703
1704 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1705}
1706
1707/**
1708 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1709 * @adapter: board private structure
1710 *
1711 * Configure the Rx unit of the MAC after a reset.
1712 **/
1713
1714static void
1715e1000_configure_rx(struct e1000_adapter *adapter)
1716{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001717 uint64_t rdba;
1718 struct e1000_hw *hw = &adapter->hw;
1719 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1720#ifdef CONFIG_E1000_MQ
1721 uint32_t reta, mrqc;
1722 int i;
1723#endif
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001724
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001725 if (adapter->rx_ps_pages) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001726 rdlen = adapter->rx_ring[0].count *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001727 sizeof(union e1000_rx_desc_packet_split);
1728 adapter->clean_rx = e1000_clean_rx_irq_ps;
1729 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1730 } else {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001731 rdlen = adapter->rx_ring[0].count *
1732 sizeof(struct e1000_rx_desc);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001733 adapter->clean_rx = e1000_clean_rx_irq;
1734 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 /* disable receives while setting up the descriptors */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001738 rctl = E1000_READ_REG(hw, RCTL);
1739 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741 /* set the Receive Delay Timer Register */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001742 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001744 if (hw->mac_type >= e1000_82540) {
1745 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 if(adapter->itr > 1)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001747 E1000_WRITE_REG(hw, ITR,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 1000000000 / (adapter->itr * 256));
1749 }
1750
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001751 if (hw->mac_type >= e1000_82571) {
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001752 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001753 /* Reset delay timers after every interrupt */
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001754 ctrl_ext |= E1000_CTRL_EXT_CANC;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001755#ifdef CONFIG_E1000_NAPI
1756 /* Auto-Mask interrupts upon ICR read. */
1757 ctrl_ext |= E1000_CTRL_EXT_IAME;
1758#endif
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001759 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08001760 E1000_WRITE_REG(hw, IAM, ~0);
Mallikarjuna R Chilakala2ae76d92005-10-04 07:04:22 -04001761 E1000_WRITE_FLUSH(hw);
1762 }
1763
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001764 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1765 * the Base and Length of the Rx Descriptor Ring */
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001766 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001767#ifdef CONFIG_E1000_MQ
1768 case 2:
1769 rdba = adapter->rx_ring[1].dma;
1770 E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
1771 E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
1772 E1000_WRITE_REG(hw, RDLEN1, rdlen);
1773 E1000_WRITE_REG(hw, RDH1, 0);
1774 E1000_WRITE_REG(hw, RDT1, 0);
1775 adapter->rx_ring[1].rdh = E1000_RDH1;
1776 adapter->rx_ring[1].rdt = E1000_RDT1;
1777 /* Fall Through */
1778#endif
1779 case 1:
1780 default:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001781 rdba = adapter->rx_ring[0].dma;
1782 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1783 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1784 E1000_WRITE_REG(hw, RDLEN, rdlen);
1785 E1000_WRITE_REG(hw, RDH, 0);
1786 E1000_WRITE_REG(hw, RDT, 0);
1787 adapter->rx_ring[0].rdh = E1000_RDH;
1788 adapter->rx_ring[0].rdt = E1000_RDT;
1789 break;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001790 }
1791
1792#ifdef CONFIG_E1000_MQ
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001793 if (adapter->num_rx_queues > 1) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001794 uint32_t random[10];
1795
1796 get_random_bytes(&random[0], 40);
1797
1798 if (hw->mac_type <= e1000_82572) {
1799 E1000_WRITE_REG(hw, RSSIR, 0);
1800 E1000_WRITE_REG(hw, RSSIM, 0);
1801 }
1802
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001803 switch (adapter->num_rx_queues) {
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001804 case 2:
1805 default:
1806 reta = 0x00800080;
1807 mrqc = E1000_MRQC_ENABLE_RSS_2Q;
1808 break;
1809 }
1810
1811 /* Fill out redirection table */
1812 for (i = 0; i < 32; i++)
1813 E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
1814 /* Fill out hash function seeds */
1815 for (i = 0; i < 10; i++)
1816 E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
1817
1818 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1819 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1820 E1000_WRITE_REG(hw, MRQC, mrqc);
1821 }
1822
1823 /* Multiqueue and packet checksumming are mutually exclusive. */
1824 if (hw->mac_type >= e1000_82571) {
1825 rxcsum = E1000_READ_REG(hw, RXCSUM);
1826 rxcsum |= E1000_RXCSUM_PCSD;
1827 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1828 }
1829
1830#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
1832 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001833 if (hw->mac_type >= e1000_82543) {
1834 rxcsum = E1000_READ_REG(hw, RXCSUM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001835 if(adapter->rx_csum == TRUE) {
1836 rxcsum |= E1000_RXCSUM_TUOFL;
1837
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001838 /* Enable 82571 IPv4 payload checksum for UDP fragments
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001839 * Must be used in conjunction with packet-split. */
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04001840 if ((hw->mac_type >= e1000_82571) &&
1841 (adapter->rx_ps_pages)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001842 rxcsum |= E1000_RXCSUM_IPPCSE;
1843 }
1844 } else {
1845 rxcsum &= ~E1000_RXCSUM_TUOFL;
1846 /* don't need to clear IPPCSE as it defaults to 0 */
1847 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001848 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 }
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04001850#endif /* CONFIG_E1000_MQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001852 if (hw->mac_type == e1000_82573)
1853 E1000_WRITE_REG(hw, ERT, 0x0100);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001854
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 /* Enable Receives */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001856 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857}
1858
1859/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001860 * e1000_free_tx_resources - Free Tx Resources per Queue
1861 * @adapter: board private structure
1862 * @tx_ring: Tx descriptor ring for a specific queue
1863 *
1864 * Free all transmit software resources
1865 **/
1866
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001867static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001868e1000_free_tx_resources(struct e1000_adapter *adapter,
1869 struct e1000_tx_ring *tx_ring)
1870{
1871 struct pci_dev *pdev = adapter->pdev;
1872
1873 e1000_clean_tx_ring(adapter, tx_ring);
1874
1875 vfree(tx_ring->buffer_info);
1876 tx_ring->buffer_info = NULL;
1877
1878 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1879
1880 tx_ring->desc = NULL;
1881}
1882
1883/**
1884 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 * @adapter: board private structure
1886 *
1887 * Free all transmit software resources
1888 **/
1889
1890void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001891e1000_free_all_tx_resources(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001893 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001895 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001896 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897}
1898
1899static inline void
1900e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1901 struct e1000_buffer *buffer_info)
1902{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 if(buffer_info->dma) {
Malli Chilakala26483452005-04-28 19:44:46 -07001904 pci_unmap_page(adapter->pdev,
1905 buffer_info->dma,
1906 buffer_info->length,
1907 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 }
Jeff Kirsher8241e352006-01-12 16:51:34 -08001909 if (buffer_info->skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 dev_kfree_skb_any(buffer_info->skb);
Jeff Kirsher8241e352006-01-12 16:51:34 -08001911 memset(buffer_info, 0, sizeof(struct e1000_buffer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912}
1913
1914/**
1915 * e1000_clean_tx_ring - Free Tx Buffers
1916 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001917 * @tx_ring: ring to be cleaned
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 **/
1919
1920static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001921e1000_clean_tx_ring(struct e1000_adapter *adapter,
1922 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 struct e1000_buffer *buffer_info;
1925 unsigned long size;
1926 unsigned int i;
1927
1928 /* Free all the Tx ring sk_buffs */
1929
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 for(i = 0; i < tx_ring->count; i++) {
1931 buffer_info = &tx_ring->buffer_info[i];
1932 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1933 }
1934
1935 size = sizeof(struct e1000_buffer) * tx_ring->count;
1936 memset(tx_ring->buffer_info, 0, size);
1937
1938 /* Zero out the descriptor ring */
1939
1940 memset(tx_ring->desc, 0, tx_ring->size);
1941
1942 tx_ring->next_to_use = 0;
1943 tx_ring->next_to_clean = 0;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001944 tx_ring->last_tx_tso = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001946 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1947 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1948}
1949
1950/**
1951 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1952 * @adapter: board private structure
1953 **/
1954
1955static void
1956e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1957{
1958 int i;
1959
Jeff Kirsherf56799e2006-01-12 16:50:39 -08001960 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001961 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962}
1963
1964/**
1965 * e1000_free_rx_resources - Free Rx Resources
1966 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001967 * @rx_ring: ring to clean the resources from
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 *
1969 * Free all receive software resources
1970 **/
1971
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01001972static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001973e1000_free_rx_resources(struct e1000_adapter *adapter,
1974 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 struct pci_dev *pdev = adapter->pdev;
1977
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001978 e1000_clean_rx_ring(adapter, rx_ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
1980 vfree(rx_ring->buffer_info);
1981 rx_ring->buffer_info = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001982 kfree(rx_ring->ps_page);
1983 rx_ring->ps_page = NULL;
1984 kfree(rx_ring->ps_page_dma);
1985 rx_ring->ps_page_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
1987 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
1988
1989 rx_ring->desc = NULL;
1990}
1991
1992/**
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001993 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 * @adapter: board private structure
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001995 *
1996 * Free all receive software resources
1997 **/
1998
1999void
2000e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2001{
2002 int i;
2003
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002004 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002005 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2006}
2007
2008/**
2009 * e1000_clean_rx_ring - Free Rx Buffers per Queue
2010 * @adapter: board private structure
2011 * @rx_ring: ring to free buffers from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 **/
2013
2014static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002015e1000_clean_rx_ring(struct e1000_adapter *adapter,
2016 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 struct e1000_buffer *buffer_info;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002019 struct e1000_ps_page *ps_page;
2020 struct e1000_ps_page_dma *ps_page_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 struct pci_dev *pdev = adapter->pdev;
2022 unsigned long size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002023 unsigned int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
2025 /* Free all the Rx ring sk_buffs */
2026
2027 for(i = 0; i < rx_ring->count; i++) {
2028 buffer_info = &rx_ring->buffer_info[i];
2029 if(buffer_info->skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 pci_unmap_single(pdev,
2031 buffer_info->dma,
2032 buffer_info->length,
2033 PCI_DMA_FROMDEVICE);
2034
2035 dev_kfree_skb(buffer_info->skb);
2036 buffer_info->skb = NULL;
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002037 }
2038 ps_page = &rx_ring->ps_page[i];
2039 ps_page_dma = &rx_ring->ps_page_dma[i];
2040 for (j = 0; j < adapter->rx_ps_pages; j++) {
2041 if (!ps_page->ps_page[j]) break;
2042 pci_unmap_page(pdev,
2043 ps_page_dma->ps_page_dma[j],
2044 PAGE_SIZE, PCI_DMA_FROMDEVICE);
2045 ps_page_dma->ps_page_dma[j] = 0;
2046 put_page(ps_page->ps_page[j]);
2047 ps_page->ps_page[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 }
2049 }
2050
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08002051 /* there also may be some cached data in our adapter */
2052 if (rx_ring->rx_skb_top) {
2053 dev_kfree_skb(rx_ring->rx_skb_top);
2054
2055 /* rx_skb_prev will be wiped out by rx_skb_top */
2056 rx_ring->rx_skb_top = NULL;
2057 rx_ring->rx_skb_prev = NULL;
2058 }
2059
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 size = sizeof(struct e1000_buffer) * rx_ring->count;
2062 memset(rx_ring->buffer_info, 0, size);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002063 size = sizeof(struct e1000_ps_page) * rx_ring->count;
2064 memset(rx_ring->ps_page, 0, size);
2065 size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2066 memset(rx_ring->ps_page_dma, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068 /* Zero out the descriptor ring */
2069
2070 memset(rx_ring->desc, 0, rx_ring->size);
2071
2072 rx_ring->next_to_clean = 0;
2073 rx_ring->next_to_use = 0;
2074
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002075 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2076 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2077}
2078
2079/**
2080 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2081 * @adapter: board private structure
2082 **/
2083
2084static void
2085e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2086{
2087 int i;
2088
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002089 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002090 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
2093/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2094 * and memory write and invalidate disabled for certain operations
2095 */
2096static void
2097e1000_enter_82542_rst(struct e1000_adapter *adapter)
2098{
2099 struct net_device *netdev = adapter->netdev;
2100 uint32_t rctl;
2101
2102 e1000_pci_clear_mwi(&adapter->hw);
2103
2104 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2105 rctl |= E1000_RCTL_RST;
2106 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2107 E1000_WRITE_FLUSH(&adapter->hw);
2108 mdelay(5);
2109
2110 if(netif_running(netdev))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002111 e1000_clean_all_rx_rings(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112}
2113
2114static void
2115e1000_leave_82542_rst(struct e1000_adapter *adapter)
2116{
2117 struct net_device *netdev = adapter->netdev;
2118 uint32_t rctl;
2119
2120 rctl = E1000_READ_REG(&adapter->hw, RCTL);
2121 rctl &= ~E1000_RCTL_RST;
2122 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2123 E1000_WRITE_FLUSH(&adapter->hw);
2124 mdelay(5);
2125
2126 if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2127 e1000_pci_set_mwi(&adapter->hw);
2128
2129 if(netif_running(netdev)) {
2130 e1000_configure_rx(adapter);
Jeff Kirsher72d64a42006-01-12 16:51:19 -08002131 /* No need to loop, because 82542 supports only 1 queue */
2132 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2133 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 }
2135}
2136
2137/**
2138 * e1000_set_mac - Change the Ethernet Address of the NIC
2139 * @netdev: network interface device structure
2140 * @p: pointer to an address structure
2141 *
2142 * Returns 0 on success, negative on failure
2143 **/
2144
2145static int
2146e1000_set_mac(struct net_device *netdev, void *p)
2147{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002148 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 struct sockaddr *addr = p;
2150
2151 if(!is_valid_ether_addr(addr->sa_data))
2152 return -EADDRNOTAVAIL;
2153
2154 /* 82542 2.0 needs to be in reset to write receive address registers */
2155
2156 if(adapter->hw.mac_type == e1000_82542_rev2_0)
2157 e1000_enter_82542_rst(adapter);
2158
2159 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2160 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2161
2162 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2163
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002164 /* With 82571 controllers, LAA may be overwritten (with the default)
2165 * due to controller reset from the other port. */
2166 if (adapter->hw.mac_type == e1000_82571) {
2167 /* activate the work around */
2168 adapter->hw.laa_is_present = 1;
2169
2170 /* Hold a copy of the LAA in RAR[14] This is done so that
2171 * between the time RAR[0] gets clobbered and the time it
2172 * gets fixed (in e1000_watchdog), the actual LAA is in one
2173 * of the RARs and no incoming packets directed to this port
2174 * are dropped. Eventaully the LAA will be in RAR[0] and
2175 * RAR[14] */
2176 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2177 E1000_RAR_ENTRIES - 1);
2178 }
2179
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 if(adapter->hw.mac_type == e1000_82542_rev2_0)
2181 e1000_leave_82542_rst(adapter);
2182
2183 return 0;
2184}
2185
2186/**
2187 * e1000_set_multi - Multicast and Promiscuous mode set
2188 * @netdev: network interface device structure
2189 *
2190 * The set_multi entry point is called whenever the multicast address
2191 * list or the network interface flags are updated. This routine is
2192 * responsible for configuring the hardware for proper multicast,
2193 * promiscuous mode, and all-multi behavior.
2194 **/
2195
2196static void
2197e1000_set_multi(struct net_device *netdev)
2198{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002199 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 struct e1000_hw *hw = &adapter->hw;
2201 struct dev_mc_list *mc_ptr;
2202 uint32_t rctl;
2203 uint32_t hash_value;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002204 int i, rar_entries = E1000_RAR_ENTRIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002206 /* reserve RAR[14] for LAA over-write work-around */
2207 if (adapter->hw.mac_type == e1000_82571)
2208 rar_entries--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
Malli Chilakala26483452005-04-28 19:44:46 -07002210 /* Check for Promiscuous and All Multicast modes */
2211
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 rctl = E1000_READ_REG(hw, RCTL);
2213
2214 if(netdev->flags & IFF_PROMISC) {
2215 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2216 } else if(netdev->flags & IFF_ALLMULTI) {
2217 rctl |= E1000_RCTL_MPE;
2218 rctl &= ~E1000_RCTL_UPE;
2219 } else {
2220 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2221 }
2222
2223 E1000_WRITE_REG(hw, RCTL, rctl);
2224
2225 /* 82542 2.0 needs to be in reset to write receive address registers */
2226
2227 if(hw->mac_type == e1000_82542_rev2_0)
2228 e1000_enter_82542_rst(adapter);
2229
2230 /* load the first 14 multicast address into the exact filters 1-14
2231 * RAR 0 is used for the station MAC adddress
2232 * if there are not 14 addresses, go ahead and clear the filters
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002233 * -- with 82571 controllers only 0-13 entries are filled here
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 */
2235 mc_ptr = netdev->mc_list;
2236
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002237 for(i = 1; i < rar_entries; i++) {
2238 if (mc_ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2240 mc_ptr = mc_ptr->next;
2241 } else {
2242 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2243 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2244 }
2245 }
2246
2247 /* clear the old settings from the multicast hash table */
2248
2249 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2250 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2251
2252 /* load any remaining addresses into the hash table */
2253
2254 for(; mc_ptr; mc_ptr = mc_ptr->next) {
2255 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2256 e1000_mta_set(hw, hash_value);
2257 }
2258
2259 if(hw->mac_type == e1000_82542_rev2_0)
2260 e1000_leave_82542_rst(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261}
2262
2263/* Need to wait a few seconds after link up to get diagnostic information from
2264 * the phy */
2265
2266static void
2267e1000_update_phy_info(unsigned long data)
2268{
2269 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2270 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2271}
2272
2273/**
2274 * e1000_82547_tx_fifo_stall - Timer Call-back
2275 * @data: pointer to adapter cast into an unsigned long
2276 **/
2277
2278static void
2279e1000_82547_tx_fifo_stall(unsigned long data)
2280{
2281 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2282 struct net_device *netdev = adapter->netdev;
2283 uint32_t tctl;
2284
2285 if(atomic_read(&adapter->tx_fifo_stall)) {
2286 if((E1000_READ_REG(&adapter->hw, TDT) ==
2287 E1000_READ_REG(&adapter->hw, TDH)) &&
2288 (E1000_READ_REG(&adapter->hw, TDFT) ==
2289 E1000_READ_REG(&adapter->hw, TDFH)) &&
2290 (E1000_READ_REG(&adapter->hw, TDFTS) ==
2291 E1000_READ_REG(&adapter->hw, TDFHS))) {
2292 tctl = E1000_READ_REG(&adapter->hw, TCTL);
2293 E1000_WRITE_REG(&adapter->hw, TCTL,
2294 tctl & ~E1000_TCTL_EN);
2295 E1000_WRITE_REG(&adapter->hw, TDFT,
2296 adapter->tx_head_addr);
2297 E1000_WRITE_REG(&adapter->hw, TDFH,
2298 adapter->tx_head_addr);
2299 E1000_WRITE_REG(&adapter->hw, TDFTS,
2300 adapter->tx_head_addr);
2301 E1000_WRITE_REG(&adapter->hw, TDFHS,
2302 adapter->tx_head_addr);
2303 E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2304 E1000_WRITE_FLUSH(&adapter->hw);
2305
2306 adapter->tx_fifo_head = 0;
2307 atomic_set(&adapter->tx_fifo_stall, 0);
2308 netif_wake_queue(netdev);
2309 } else {
2310 mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2311 }
2312 }
2313}
2314
2315/**
2316 * e1000_watchdog - Timer Call-back
2317 * @data: pointer to adapter cast into an unsigned long
2318 **/
2319static void
2320e1000_watchdog(unsigned long data)
2321{
2322 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2323
2324 /* Do the rest outside of interrupt context */
2325 schedule_work(&adapter->watchdog_task);
2326}
2327
2328static void
2329e1000_watchdog_task(struct e1000_adapter *adapter)
2330{
2331 struct net_device *netdev = adapter->netdev;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002332 struct e1000_tx_ring *txdr = adapter->tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 uint32_t link;
2334
2335 e1000_check_for_link(&adapter->hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002336 if (adapter->hw.mac_type == e1000_82573) {
2337 e1000_enable_tx_pkt_filtering(&adapter->hw);
2338 if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2339 e1000_update_mng_vlan(adapter);
2340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
2342 if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2343 !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2344 link = !adapter->hw.serdes_link_down;
2345 else
2346 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2347
2348 if(link) {
2349 if(!netif_carrier_ok(netdev)) {
2350 e1000_get_speed_and_duplex(&adapter->hw,
2351 &adapter->link_speed,
2352 &adapter->link_duplex);
2353
2354 DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2355 adapter->link_speed,
2356 adapter->link_duplex == FULL_DUPLEX ?
2357 "Full Duplex" : "Half Duplex");
2358
Jeff Kirsher66a2b0a2006-01-12 16:50:53 -08002359 /* tweak tx_queue_len according to speed/duplex */
2360 netdev->tx_queue_len = adapter->tx_queue_len;
2361 adapter->tx_timeout_factor = 1;
2362 if (adapter->link_duplex == HALF_DUPLEX) {
2363 switch (adapter->link_speed) {
2364 case SPEED_10:
2365 netdev->tx_queue_len = 10;
2366 adapter->tx_timeout_factor = 8;
2367 break;
2368 case SPEED_100:
2369 netdev->tx_queue_len = 100;
2370 break;
2371 }
2372 }
2373
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 netif_carrier_on(netdev);
2375 netif_wake_queue(netdev);
2376 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2377 adapter->smartspeed = 0;
2378 }
2379 } else {
2380 if(netif_carrier_ok(netdev)) {
2381 adapter->link_speed = 0;
2382 adapter->link_duplex = 0;
2383 DPRINTK(LINK, INFO, "NIC Link is Down\n");
2384 netif_carrier_off(netdev);
2385 netif_stop_queue(netdev);
2386 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2387 }
2388
2389 e1000_smartspeed(adapter);
2390 }
2391
2392 e1000_update_stats(adapter);
2393
2394 adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2395 adapter->tpt_old = adapter->stats.tpt;
2396 adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2397 adapter->colc_old = adapter->stats.colc;
2398
2399 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2400 adapter->gorcl_old = adapter->stats.gorcl;
2401 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2402 adapter->gotcl_old = adapter->stats.gotcl;
2403
2404 e1000_update_adaptive(&adapter->hw);
2405
Jeff Kirsherf56799e2006-01-12 16:50:39 -08002406#ifdef CONFIG_E1000_MQ
2407 txdr = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2408#endif
2409 if (!netif_carrier_ok(netdev)) {
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002410 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 /* We've lost link, so the controller stops DMA,
2412 * but we've got queued Tx work that's never going
2413 * to get done, so reset controller to flush Tx.
2414 * (Do the reset outside of interrupt context). */
2415 schedule_work(&adapter->tx_timeout_task);
2416 }
2417 }
2418
2419 /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2420 if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2421 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2422 * asymmetrical Tx or Rx gets ITR=8000; everyone
2423 * else is between 2000-8000. */
2424 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2425 uint32_t dif = (adapter->gotcl > adapter->gorcl ?
2426 adapter->gotcl - adapter->gorcl :
2427 adapter->gorcl - adapter->gotcl) / 10000;
2428 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2429 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2430 }
2431
2432 /* Cause software interrupt to ensure rx ring is cleaned */
2433 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2434
Malli Chilakala26483452005-04-28 19:44:46 -07002435 /* Force detection of hung controller every watchdog period */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 adapter->detect_tx_hung = TRUE;
2437
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002438 /* With 82571 controllers, LAA may be overwritten due to controller
2439 * reset from the other port. Set the appropriate LAA in RAR[0] */
2440 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2441 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2442
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 /* Reset the timer */
2444 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2445}
2446
2447#define E1000_TX_FLAGS_CSUM 0x00000001
2448#define E1000_TX_FLAGS_VLAN 0x00000002
2449#define E1000_TX_FLAGS_TSO 0x00000004
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002450#define E1000_TX_FLAGS_IPV4 0x00000008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2452#define E1000_TX_FLAGS_VLAN_SHIFT 16
2453
2454static inline int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002455e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2456 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457{
2458#ifdef NETIF_F_TSO
2459 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002460 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 unsigned int i;
2462 uint32_t cmd_length = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002463 uint16_t ipcse = 0, tucse, mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2465 int err;
2466
2467 if(skb_shinfo(skb)->tso_size) {
2468 if (skb_header_cloned(skb)) {
2469 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2470 if (err)
2471 return err;
2472 }
2473
2474 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2475 mss = skb_shinfo(skb)->tso_size;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002476 if(skb->protocol == ntohs(ETH_P_IP)) {
2477 skb->nh.iph->tot_len = 0;
2478 skb->nh.iph->check = 0;
2479 skb->h.th->check =
2480 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2481 skb->nh.iph->daddr,
2482 0,
2483 IPPROTO_TCP,
2484 0);
2485 cmd_length = E1000_TXD_CMD_IP;
2486 ipcse = skb->h.raw - skb->data - 1;
2487#ifdef NETIF_F_TSO_IPV6
2488 } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
2489 skb->nh.ipv6h->payload_len = 0;
2490 skb->h.th->check =
2491 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2492 &skb->nh.ipv6h->daddr,
2493 0,
2494 IPPROTO_TCP,
2495 0);
2496 ipcse = 0;
2497#endif
2498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 ipcss = skb->nh.raw - skb->data;
2500 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 tucss = skb->h.raw - skb->data;
2502 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2503 tucse = 0;
2504
2505 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002506 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002508 i = tx_ring->next_to_use;
2509 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002510 buffer_info = &tx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
2512 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2513 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2514 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2515 context_desc->upper_setup.tcp_fields.tucss = tucss;
2516 context_desc->upper_setup.tcp_fields.tucso = tucso;
2517 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2518 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2519 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2520 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2521
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002522 buffer_info->time_stamp = jiffies;
2523
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002524 if (++i == tx_ring->count) i = 0;
2525 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
Jeff Kirsher8241e352006-01-12 16:51:34 -08002527 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 }
2529#endif
2530
Jeff Kirsher8241e352006-01-12 16:51:34 -08002531 return FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532}
2533
2534static inline boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002535e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2536 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537{
2538 struct e1000_context_desc *context_desc;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002539 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 unsigned int i;
2541 uint8_t css;
2542
2543 if(likely(skb->ip_summed == CHECKSUM_HW)) {
2544 css = skb->h.raw - skb->data;
2545
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002546 i = tx_ring->next_to_use;
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002547 buffer_info = &tx_ring->buffer_info[i];
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002548 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
2550 context_desc->upper_setup.tcp_fields.tucss = css;
2551 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2552 context_desc->upper_setup.tcp_fields.tucse = 0;
2553 context_desc->tcp_seg_setup.data = 0;
2554 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2555
Jeff Kirsher545c67c2006-01-12 16:50:25 -08002556 buffer_info->time_stamp = jiffies;
2557
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002558 if (unlikely(++i == tx_ring->count)) i = 0;
2559 tx_ring->next_to_use = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
2561 return TRUE;
2562 }
2563
2564 return FALSE;
2565}
2566
2567#define E1000_MAX_TXD_PWR 12
2568#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2569
2570static inline int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002571e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2572 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2573 unsigned int nr_frags, unsigned int mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 struct e1000_buffer *buffer_info;
2576 unsigned int len = skb->len;
2577 unsigned int offset = 0, size, count = 0, i;
2578 unsigned int f;
2579 len -= skb->data_len;
2580
2581 i = tx_ring->next_to_use;
2582
2583 while(len) {
2584 buffer_info = &tx_ring->buffer_info[i];
2585 size = min(len, max_per_txd);
2586#ifdef NETIF_F_TSO
Jeff Kirsherfd803242005-12-13 00:06:22 -05002587 /* Workaround for Controller erratum --
2588 * descriptor for non-tso packet in a linear SKB that follows a
2589 * tso gets written back prematurely before the data is fully
2590 * DMAd to the controller */
2591 if (!skb->data_len && tx_ring->last_tx_tso &&
2592 !skb_shinfo(skb)->tso_size) {
2593 tx_ring->last_tx_tso = 0;
2594 size -= 4;
2595 }
2596
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 /* Workaround for premature desc write-backs
2598 * in TSO mode. Append 4-byte sentinel desc */
2599 if(unlikely(mss && !nr_frags && size == len && size > 8))
2600 size -= 4;
2601#endif
Malli Chilakala97338bd2005-04-28 19:41:46 -07002602 /* work-around for errata 10 and it applies
2603 * to all controllers in PCI-X mode
2604 * The fix is to make sure that the first descriptor of a
2605 * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2606 */
2607 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2608 (size > 2015) && count == 0))
2609 size = 2015;
2610
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 /* Workaround for potential 82544 hang in PCI-X. Avoid
2612 * terminating buffers within evenly-aligned dwords. */
2613 if(unlikely(adapter->pcix_82544 &&
2614 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2615 size > 4))
2616 size -= 4;
2617
2618 buffer_info->length = size;
2619 buffer_info->dma =
2620 pci_map_single(adapter->pdev,
2621 skb->data + offset,
2622 size,
2623 PCI_DMA_TODEVICE);
2624 buffer_info->time_stamp = jiffies;
2625
2626 len -= size;
2627 offset += size;
2628 count++;
2629 if(unlikely(++i == tx_ring->count)) i = 0;
2630 }
2631
2632 for(f = 0; f < nr_frags; f++) {
2633 struct skb_frag_struct *frag;
2634
2635 frag = &skb_shinfo(skb)->frags[f];
2636 len = frag->size;
2637 offset = frag->page_offset;
2638
2639 while(len) {
2640 buffer_info = &tx_ring->buffer_info[i];
2641 size = min(len, max_per_txd);
2642#ifdef NETIF_F_TSO
2643 /* Workaround for premature desc write-backs
2644 * in TSO mode. Append 4-byte sentinel desc */
2645 if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2646 size -= 4;
2647#endif
2648 /* Workaround for potential 82544 hang in PCI-X.
2649 * Avoid terminating buffers within evenly-aligned
2650 * dwords. */
2651 if(unlikely(adapter->pcix_82544 &&
2652 !((unsigned long)(frag->page+offset+size-1) & 4) &&
2653 size > 4))
2654 size -= 4;
2655
2656 buffer_info->length = size;
2657 buffer_info->dma =
2658 pci_map_page(adapter->pdev,
2659 frag->page,
2660 offset,
2661 size,
2662 PCI_DMA_TODEVICE);
2663 buffer_info->time_stamp = jiffies;
2664
2665 len -= size;
2666 offset += size;
2667 count++;
2668 if(unlikely(++i == tx_ring->count)) i = 0;
2669 }
2670 }
2671
2672 i = (i == 0) ? tx_ring->count - 1 : i - 1;
2673 tx_ring->buffer_info[i].skb = skb;
2674 tx_ring->buffer_info[first].next_to_watch = i;
2675
2676 return count;
2677}
2678
2679static inline void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002680e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2681 int tx_flags, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 struct e1000_tx_desc *tx_desc = NULL;
2684 struct e1000_buffer *buffer_info;
2685 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2686 unsigned int i;
2687
2688 if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2689 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2690 E1000_TXD_CMD_TSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002691 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2692
2693 if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
2694 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 }
2696
2697 if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2698 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2699 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2700 }
2701
2702 if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2703 txd_lower |= E1000_TXD_CMD_VLE;
2704 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2705 }
2706
2707 i = tx_ring->next_to_use;
2708
2709 while(count--) {
2710 buffer_info = &tx_ring->buffer_info[i];
2711 tx_desc = E1000_TX_DESC(*tx_ring, i);
2712 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2713 tx_desc->lower.data =
2714 cpu_to_le32(txd_lower | buffer_info->length);
2715 tx_desc->upper.data = cpu_to_le32(txd_upper);
2716 if(unlikely(++i == tx_ring->count)) i = 0;
2717 }
2718
2719 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2720
2721 /* Force memory writes to complete before letting h/w
2722 * know there are new descriptors to fetch. (Only
2723 * applicable for weak-ordered memory model archs,
2724 * such as IA-64). */
2725 wmb();
2726
2727 tx_ring->next_to_use = i;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002728 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729}
2730
2731/**
2732 * 82547 workaround to avoid controller hang in half-duplex environment.
2733 * The workaround is to avoid queuing a large packet that would span
2734 * the internal Tx FIFO ring boundary by notifying the stack to resend
2735 * the packet at a later time. This gives the Tx FIFO an opportunity to
2736 * flush all packets. When that occurs, we reset the Tx FIFO pointers
2737 * to the beginning of the Tx FIFO.
2738 **/
2739
2740#define E1000_FIFO_HDR 0x10
2741#define E1000_82547_PAD_LEN 0x3E0
2742
2743static inline int
2744e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2745{
2746 uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2747 uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2748
2749 E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2750
2751 if(adapter->link_duplex != HALF_DUPLEX)
2752 goto no_fifo_stall_required;
2753
2754 if(atomic_read(&adapter->tx_fifo_stall))
2755 return 1;
2756
2757 if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2758 atomic_set(&adapter->tx_fifo_stall, 1);
2759 return 1;
2760 }
2761
2762no_fifo_stall_required:
2763 adapter->tx_fifo_head += skb_fifo_len;
2764 if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
2765 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2766 return 0;
2767}
2768
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002769#define MINIMUM_DHCP_PACKET_SIZE 282
2770static inline int
2771e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2772{
2773 struct e1000_hw *hw = &adapter->hw;
2774 uint16_t length, offset;
2775 if(vlan_tx_tag_present(skb)) {
2776 if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2777 ( adapter->hw.mng_cookie.status &
2778 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2779 return 0;
2780 }
Jesse Brandeburga174fd82005-11-29 19:23:59 -08002781 if ((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002782 struct ethhdr *eth = (struct ethhdr *) skb->data;
2783 if((htons(ETH_P_IP) == eth->h_proto)) {
2784 const struct iphdr *ip =
2785 (struct iphdr *)((uint8_t *)skb->data+14);
2786 if(IPPROTO_UDP == ip->protocol) {
2787 struct udphdr *udp =
2788 (struct udphdr *)((uint8_t *)ip +
2789 (ip->ihl << 2));
2790 if(ntohs(udp->dest) == 67) {
2791 offset = (uint8_t *)udp + 8 - skb->data;
2792 length = skb->len - offset;
2793
2794 return e1000_mng_write_dhcp_info(hw,
2795 (uint8_t *)udp + 8,
2796 length);
2797 }
2798 }
2799 }
2800 }
2801 return 0;
2802}
2803
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2805static int
2806e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2807{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002808 struct e1000_adapter *adapter = netdev_priv(netdev);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002809 struct e1000_tx_ring *tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2811 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2812 unsigned int tx_flags = 0;
2813 unsigned int len = skb->len;
2814 unsigned long flags;
2815 unsigned int nr_frags = 0;
2816 unsigned int mss = 0;
2817 int count = 0;
2818 int tso;
2819 unsigned int f;
2820 len -= skb->data_len;
2821
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002822#ifdef CONFIG_E1000_MQ
2823 tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2824#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002825 tx_ring = adapter->tx_ring;
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04002826#endif
2827
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002828 if (unlikely(skb->len <= 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 dev_kfree_skb_any(skb);
2830 return NETDEV_TX_OK;
2831 }
2832
2833#ifdef NETIF_F_TSO
2834 mss = skb_shinfo(skb)->tso_size;
Malli Chilakala26483452005-04-28 19:44:46 -07002835 /* The controller does a simple calculation to
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 * make sure there is enough room in the FIFO before
2837 * initiating the DMA for each buffer. The calc is:
2838 * 4 = ceil(buffer len/mss). To make sure we don't
2839 * overrun the FIFO, adjust the max buffer len if mss
2840 * drops. */
2841 if(mss) {
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002842 uint8_t hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 max_per_txd = min(mss << 2, max_per_txd);
2844 max_txd_pwr = fls(max_per_txd) - 1;
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002845
2846 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2847 * points to just header, pull a few bytes of payload from
2848 * frags into skb->data */
2849 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2850 if (skb->data_len && (hdr_len == (skb->len - skb->data_len)) &&
2851 (adapter->hw.mac_type == e1000_82571 ||
2852 adapter->hw.mac_type == e1000_82572)) {
Jeff Kirsherd74bbd32006-01-12 16:51:07 -08002853 unsigned int pull_size;
2854 pull_size = min((unsigned int)4, skb->data_len);
2855 if (!__pskb_pull_tail(skb, pull_size)) {
2856 printk(KERN_ERR "__pskb_pull_tail failed.\n");
2857 dev_kfree_skb_any(skb);
2858 return -EFAULT;
2859 }
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002860 len = skb->len - skb->data_len;
2861 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 }
2863
2864 if((mss) || (skb->ip_summed == CHECKSUM_HW))
Jeff Kirsher9a3056d2006-01-12 16:50:23 -08002865 /* reserve a descriptor for the offload context */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 count++;
Malli Chilakala26483452005-04-28 19:44:46 -07002867 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868#else
2869 if(skb->ip_summed == CHECKSUM_HW)
2870 count++;
2871#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05002872
2873#ifdef NETIF_F_TSO
2874 /* Controller Erratum workaround */
2875 if (!skb->data_len && tx_ring->last_tx_tso &&
2876 !skb_shinfo(skb)->tso_size)
2877 count++;
2878#endif
2879
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 count += TXD_USE_COUNT(len, max_txd_pwr);
2881
2882 if(adapter->pcix_82544)
2883 count++;
2884
Malli Chilakala97338bd2005-04-28 19:41:46 -07002885 /* work-around for errata 10 and it applies to all controllers
2886 * in PCI-X mode, so add one more descriptor to the count
2887 */
2888 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2889 (len > 2015)))
2890 count++;
2891
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 nr_frags = skb_shinfo(skb)->nr_frags;
2893 for(f = 0; f < nr_frags; f++)
2894 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2895 max_txd_pwr);
2896 if(adapter->pcix_82544)
2897 count += nr_frags;
2898
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002899 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2900 e1000_transfer_dhcp_info(adapter, skb);
2901
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002902 local_irq_save(flags);
2903 if (!spin_trylock(&tx_ring->tx_lock)) {
2904 /* Collision - tell upper layer to requeue */
2905 local_irq_restore(flags);
2906 return NETDEV_TX_LOCKED;
2907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
2909 /* need: count + 2 desc gap to keep tail from touching
2910 * head, otherwise try next time */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002911 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 netif_stop_queue(netdev);
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_BUSY;
2915 }
2916
2917 if(unlikely(adapter->hw.mac_type == e1000_82547)) {
2918 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2919 netif_stop_queue(netdev);
2920 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002921 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 return NETDEV_TX_BUSY;
2923 }
2924 }
2925
2926 if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2927 tx_flags |= E1000_TX_FLAGS_VLAN;
2928 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2929 }
2930
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002931 first = tx_ring->next_to_use;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002933 tso = e1000_tso(adapter, tx_ring, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 if (tso < 0) {
2935 dev_kfree_skb_any(skb);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002936 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 return NETDEV_TX_OK;
2938 }
2939
Jeff Kirsherfd803242005-12-13 00:06:22 -05002940 if (likely(tso)) {
2941 tx_ring->last_tx_tso = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 tx_flags |= E1000_TX_FLAGS_TSO;
Jeff Kirsherfd803242005-12-13 00:06:22 -05002943 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 tx_flags |= E1000_TX_FLAGS_CSUM;
2945
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002946 /* Old method was to assume IPv4 packet by default if TSO was enabled.
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04002947 * 82571 hardware supports TSO capabilities for IPv6 as well...
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002948 * no longer assume, we must. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002949 if (likely(skb->protocol == ntohs(ETH_P_IP)))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002950 tx_flags |= E1000_TX_FLAGS_IPV4;
2951
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002952 e1000_tx_queue(adapter, tx_ring, tx_flags,
2953 e1000_tx_map(adapter, tx_ring, skb, first,
2954 max_per_txd, nr_frags, mss));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
2956 netdev->trans_start = jiffies;
2957
2958 /* Make sure there is space in the ring for the next send. */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002959 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 netif_stop_queue(netdev);
2961
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04002962 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 return NETDEV_TX_OK;
2964}
2965
2966/**
2967 * e1000_tx_timeout - Respond to a Tx Hang
2968 * @netdev: network interface device structure
2969 **/
2970
2971static void
2972e1000_tx_timeout(struct net_device *netdev)
2973{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002974 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
2976 /* Do the reset outside of interrupt context */
2977 schedule_work(&adapter->tx_timeout_task);
2978}
2979
2980static void
2981e1000_tx_timeout_task(struct net_device *netdev)
2982{
Malli Chilakala60490fe2005-06-17 17:41:45 -07002983 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08002985 adapter->tx_timeout_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 e1000_down(adapter);
2987 e1000_up(adapter);
2988}
2989
2990/**
2991 * e1000_get_stats - Get System Network Statistics
2992 * @netdev: network interface device structure
2993 *
2994 * Returns the address of the device statistics structure.
2995 * The statistics are actually updated from the timer callback.
2996 **/
2997
2998static struct net_device_stats *
2999e1000_get_stats(struct net_device *netdev)
3000{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003001 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003003 /* only return the current stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 return &adapter->net_stats;
3005}
3006
3007/**
3008 * e1000_change_mtu - Change the Maximum Transfer Unit
3009 * @netdev: network interface device structure
3010 * @new_mtu: new value for maximum frame size
3011 *
3012 * Returns 0 on success, negative on failure
3013 **/
3014
3015static int
3016e1000_change_mtu(struct net_device *netdev, int new_mtu)
3017{
Malli Chilakala60490fe2005-06-17 17:41:45 -07003018 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3020
3021 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3022 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3023 DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04003024 return -EINVAL;
3025 }
3026
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003027 /* Adapter-specific max frame size limits. */
3028 switch (adapter->hw.mac_type) {
3029 case e1000_82542_rev2_0:
3030 case e1000_82542_rev2_1:
3031 case e1000_82573:
3032 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3033 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003034 return -EINVAL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003035 }
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003036 break;
3037 case e1000_82571:
3038 case e1000_82572:
3039#define MAX_STD_JUMBO_FRAME_SIZE 9234
3040 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3041 DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3042 return -EINVAL;
3043 }
3044 break;
3045 default:
3046 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3047 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003048 }
3049
Jeff Kirsher997f5cb2006-01-12 16:50:55 -08003050 /* since the driver code now supports splitting a packet across
3051 * multiple descriptors, most of the fifo related limitations on
3052 * jumbo frame traffic have gone away.
3053 * simply use 2k descriptors for everything.
3054 *
3055 * NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3056 * means we reserve 2 more, this pushes us to allocate from the next
3057 * larger slab size
3058 * i.e. RXBUFFER_2048 --> size-4096 slab */
3059
3060 /* recent hardware supports 1KB granularity */
3061 if (adapter->hw.mac_type > e1000_82547_rev_2) {
3062 adapter->rx_buffer_len =
3063 ((max_frame < E1000_RXBUFFER_2048) ?
3064 max_frame : E1000_RXBUFFER_2048);
3065 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
3066 } else
3067 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3068
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003069 netdev->mtu = new_mtu;
3070
3071 if(netif_running(netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 e1000_down(adapter);
3073 e1000_up(adapter);
3074 }
3075
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 adapter->hw.max_frame_size = max_frame;
3077
3078 return 0;
3079}
3080
3081/**
3082 * e1000_update_stats - Update the board statistics counters
3083 * @adapter: board private structure
3084 **/
3085
3086void
3087e1000_update_stats(struct e1000_adapter *adapter)
3088{
3089 struct e1000_hw *hw = &adapter->hw;
3090 unsigned long flags;
3091 uint16_t phy_tmp;
3092
3093#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3094
3095 spin_lock_irqsave(&adapter->stats_lock, flags);
3096
3097 /* these counters are modified from e1000_adjust_tbi_stats,
3098 * called from the interrupt context, so they must only
3099 * be written while holding adapter->stats_lock
3100 */
3101
3102 adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3103 adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3104 adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3105 adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3106 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3107 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3108 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3109 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3110 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3111 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3112 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3113 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3114 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3115
3116 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3117 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3118 adapter->stats.scc += E1000_READ_REG(hw, SCC);
3119 adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3120 adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3121 adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3122 adapter->stats.dc += E1000_READ_REG(hw, DC);
3123 adapter->stats.sec += E1000_READ_REG(hw, SEC);
3124 adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3125 adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3126 adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3127 adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3128 adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3129 adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3130 adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3131 adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3132 adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3133 adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3134 adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3135 adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3136 adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3137 adapter->stats.torl += E1000_READ_REG(hw, TORL);
3138 adapter->stats.torh += E1000_READ_REG(hw, TORH);
3139 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3140 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3141 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3142 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3143 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3144 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3145 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3146 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3147 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3148 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3149 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3150
3151 /* used for adaptive IFS */
3152
3153 hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3154 adapter->stats.tpt += hw->tx_packet_delta;
3155 hw->collision_delta = E1000_READ_REG(hw, COLC);
3156 adapter->stats.colc += hw->collision_delta;
3157
3158 if(hw->mac_type >= e1000_82543) {
3159 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3160 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3161 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3162 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3163 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3164 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3165 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003166 if(hw->mac_type > e1000_82547_rev_2) {
3167 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3168 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3169 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3170 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3171 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3172 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3173 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3174 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3175 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
3178 /* Fill out the OS statistics structure */
3179
3180 adapter->net_stats.rx_packets = adapter->stats.gprc;
3181 adapter->net_stats.tx_packets = adapter->stats.gptc;
3182 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3183 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3184 adapter->net_stats.multicast = adapter->stats.mprc;
3185 adapter->net_stats.collisions = adapter->stats.colc;
3186
3187 /* Rx Errors */
3188
3189 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3190 adapter->stats.crcerrs + adapter->stats.algnerrc +
Jeff Kirsher6b7660c2006-01-12 16:50:35 -08003191 adapter->stats.rlec + adapter->stats.cexterr;
3192 adapter->net_stats.rx_dropped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3194 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3195 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3197
3198 /* Tx Errors */
3199
3200 adapter->net_stats.tx_errors = adapter->stats.ecol +
3201 adapter->stats.latecol;
3202 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3203 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3204 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3205
3206 /* Tx Dropped needs to be maintained elsewhere */
3207
3208 /* Phy Stats */
3209
3210 if(hw->media_type == e1000_media_type_copper) {
3211 if((adapter->link_speed == SPEED_1000) &&
3212 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3213 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3214 adapter->phy_stats.idle_errors += phy_tmp;
3215 }
3216
3217 if((hw->mac_type <= e1000_82546) &&
3218 (hw->phy_type == e1000_phy_m88) &&
3219 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3220 adapter->phy_stats.receive_errors += phy_tmp;
3221 }
3222
3223 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3224}
3225
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003226#ifdef CONFIG_E1000_MQ
3227void
3228e1000_rx_schedule(void *data)
3229{
3230 struct net_device *poll_dev, *netdev = data;
3231 struct e1000_adapter *adapter = netdev->priv;
3232 int this_cpu = get_cpu();
3233
3234 poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
3235 if (poll_dev == NULL) {
3236 put_cpu();
3237 return;
3238 }
3239
3240 if (likely(netif_rx_schedule_prep(poll_dev)))
3241 __netif_rx_schedule(poll_dev);
3242 else
3243 e1000_irq_enable(adapter);
3244
3245 put_cpu();
3246}
3247#endif
3248
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249/**
3250 * e1000_intr - Interrupt Handler
3251 * @irq: interrupt number
3252 * @data: pointer to a network interface device structure
3253 * @pt_regs: CPU registers structure
3254 **/
3255
3256static irqreturn_t
3257e1000_intr(int irq, void *data, struct pt_regs *regs)
3258{
3259 struct net_device *netdev = data;
Malli Chilakala60490fe2005-06-17 17:41:45 -07003260 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 struct e1000_hw *hw = &adapter->hw;
3262 uint32_t icr = E1000_READ_REG(hw, ICR);
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003263#ifndef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003264 int i;
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003265#else
3266 /* Interrupt Auto-Mask...upon reading ICR,
3267 * interrupts are masked. No need for the
3268 * IMC write, but it does mean we should
3269 * account for it ASAP. */
3270 if (likely(hw->mac_type >= e1000_82571))
3271 atomic_inc(&adapter->irq_sem);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003272#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003274 if (unlikely(!icr)) {
3275#ifdef CONFIG_E1000_NAPI
3276 if (hw->mac_type >= e1000_82571)
3277 e1000_irq_enable(adapter);
3278#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 return IRQ_NONE; /* Not our interrupt */
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
3282 if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3283 hw->get_link_status = 1;
3284 mod_timer(&adapter->watchdog_timer, jiffies);
3285 }
3286
3287#ifdef CONFIG_E1000_NAPI
Jeff Kirsher1e613fd2006-01-12 16:51:16 -08003288 if (unlikely(hw->mac_type < e1000_82571)) {
3289 atomic_inc(&adapter->irq_sem);
3290 E1000_WRITE_REG(hw, IMC, ~0);
3291 E1000_WRITE_FLUSH(hw);
3292 }
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003293#ifdef CONFIG_E1000_MQ
3294 if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
Jeff Kirsherf56799e2006-01-12 16:50:39 -08003295 /* We must setup the cpumask once count == 0 since
3296 * each cpu bit is cleared when the work is done. */
3297 adapter->rx_sched_call_data.cpumask = adapter->cpumask;
3298 atomic_add(adapter->num_rx_queues - 1, &adapter->irq_sem);
3299 atomic_set(&adapter->rx_sched_call_data.count,
3300 adapter->num_rx_queues);
Mallikarjuna R Chilakala24025e4ec2005-10-04 07:03:23 -04003301 smp_call_async_mask(&adapter->rx_sched_call_data);
3302 } else {
3303 printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 }
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003305#else /* if !CONFIG_E1000_MQ */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003306 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3307 __netif_rx_schedule(&adapter->polling_netdev[0]);
3308 else
3309 e1000_irq_enable(adapter);
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003310#endif /* CONFIG_E1000_MQ */
3311
3312#else /* if !CONFIG_E1000_NAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 /* Writing IMC and IMS is needed for 82547.
3314 Due to Hub Link bus being occupied, an interrupt
3315 de-assertion message is not able to be sent.
3316 When an interrupt assertion message is generated later,
3317 two messages are re-ordered and sent out.
3318 That causes APIC to think 82547 is in de-assertion
3319 state, while 82547 is in assertion state, resulting
3320 in dead lock. Writing IMC forces 82547 into
3321 de-assertion state.
3322 */
3323 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
3324 atomic_inc(&adapter->irq_sem);
Malli Chilakala26483452005-04-28 19:44:46 -07003325 E1000_WRITE_REG(hw, IMC, ~0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 }
3327
3328 for(i = 0; i < E1000_MAX_INTR; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003329 if(unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3330 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 break;
3332
3333 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3334 e1000_irq_enable(adapter);
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003335
Jeff Garzikbe2b28e2005-10-04 07:13:43 -04003336#endif /* CONFIG_E1000_NAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
3338 return IRQ_HANDLED;
3339}
3340
3341#ifdef CONFIG_E1000_NAPI
3342/**
3343 * e1000_clean - NAPI Rx polling callback
3344 * @adapter: board private structure
3345 **/
3346
3347static int
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003348e1000_clean(struct net_device *poll_dev, int *budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003350 struct e1000_adapter *adapter;
3351 int work_to_do = min(*budget, poll_dev->quota);
Jeff Kirsher38bd3b22006-01-12 16:51:37 -08003352 int tx_cleaned = 0, i = 0, work_done = 0;
Malli Chilakala26483452005-04-28 19:44:46 -07003353
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003354 /* Must NOT use netdev_priv macro here. */
3355 adapter = poll_dev->priv;
3356
3357 /* Keep link state information with original netdev */
3358 if (!netif_carrier_ok(adapter->netdev))
3359 goto quit_polling;
3360
3361 while (poll_dev != &adapter->polling_netdev[i]) {
3362 i++;
Jeff Kirsherf56799e2006-01-12 16:50:39 -08003363 if (unlikely(i == adapter->num_rx_queues))
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003364 BUG();
3365 }
3366
Jeff Kirsher8241e352006-01-12 16:51:34 -08003367 if (likely(adapter->num_tx_queues == 1)) {
3368 /* e1000_clean is called per-cpu. This lock protects
3369 * tx_ring[0] from being cleaned by multiple cpus
3370 * simultaneously. A failure obtaining the lock means
3371 * tx_ring[0] is currently being cleaned anyway. */
3372 if (spin_trylock(&adapter->tx_queue_lock)) {
3373 tx_cleaned = e1000_clean_tx_irq(adapter,
3374 &adapter->tx_ring[0]);
3375 spin_unlock(&adapter->tx_queue_lock);
3376 }
3377 } else
3378 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3379
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003380 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3381 &work_done, work_to_do);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382
3383 *budget -= work_done;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003384 poll_dev->quota -= work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385
Malli Chilakala2b028932005-06-17 17:46:06 -07003386 /* If no Tx and not enough Rx work done, exit the polling mode */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003387 if((!tx_cleaned && (work_done == 0)) ||
3388 !netif_running(adapter->netdev)) {
3389quit_polling:
3390 netif_rx_complete(poll_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 e1000_irq_enable(adapter);
3392 return 0;
3393 }
3394
3395 return 1;
3396}
3397
3398#endif
3399/**
3400 * e1000_clean_tx_irq - Reclaim resources after transmit completes
3401 * @adapter: board private structure
3402 **/
3403
3404static boolean_t
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003405e1000_clean_tx_irq(struct e1000_adapter *adapter,
3406 struct e1000_tx_ring *tx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 struct net_device *netdev = adapter->netdev;
3409 struct e1000_tx_desc *tx_desc, *eop_desc;
3410 struct e1000_buffer *buffer_info;
3411 unsigned int i, eop;
3412 boolean_t cleaned = FALSE;
3413
3414 i = tx_ring->next_to_clean;
3415 eop = tx_ring->buffer_info[i].next_to_watch;
3416 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3417
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003418 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 for(cleaned = FALSE; !cleaned; ) {
3420 tx_desc = E1000_TX_DESC(*tx_ring, i);
3421 buffer_info = &tx_ring->buffer_info[i];
3422 cleaned = (i == eop);
3423
Jeff Kirsher8241e352006-01-12 16:51:34 -08003424#ifdef CONFIG_E1000_MQ
3425 tx_ring->tx_stats.bytes += buffer_info->length;
3426#endif
Jeff Kirsherfd803242005-12-13 00:06:22 -05003427 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
Jeff Kirsher8241e352006-01-12 16:51:34 -08003428 memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 if(unlikely(++i == tx_ring->count)) i = 0;
3431 }
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003432
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003433#ifdef CONFIG_E1000_MQ
3434 tx_ring->tx_stats.packets++;
3435#endif
3436
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 eop = tx_ring->buffer_info[i].next_to_watch;
3438 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3439 }
3440
3441 tx_ring->next_to_clean = i;
3442
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003443 spin_lock(&tx_ring->tx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444
3445 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
3446 netif_carrier_ok(netdev)))
3447 netif_wake_queue(netdev);
3448
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003449 spin_unlock(&tx_ring->tx_lock);
Malli Chilakala26483452005-04-28 19:44:46 -07003450
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003451 if (adapter->detect_tx_hung) {
Malli Chilakala26483452005-04-28 19:44:46 -07003452 /* Detect a transmit hang in hardware, this serializes the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 * check with the clearing of time_stamp and movement of i */
3454 adapter->detect_tx_hung = FALSE;
Jeff Kirsher392137f2006-01-12 16:50:57 -08003455 if (tx_ring->buffer_info[eop].dma &&
3456 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3457 adapter->tx_timeout_factor * HZ)
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003458 && !(E1000_READ_REG(&adapter->hw, STATUS) &
Jeff Kirsher392137f2006-01-12 16:50:57 -08003459 E1000_STATUS_TXOFF)) {
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003460
3461 /* detected Tx unit hang */
Malli Chilakalac6963ef2005-06-17 17:42:07 -07003462 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003463 " Tx Queue <%lu>\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003464 " TDH <%x>\n"
3465 " TDT <%x>\n"
3466 " next_to_use <%x>\n"
3467 " next_to_clean <%x>\n"
3468 "buffer_info[next_to_clean]\n"
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003469 " time_stamp <%lx>\n"
3470 " next_to_watch <%x>\n"
3471 " jiffies <%lx>\n"
3472 " next_to_watch.status <%x>\n",
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003473 (unsigned long)((tx_ring - adapter->tx_ring) /
3474 sizeof(struct e1000_tx_ring)),
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003475 readl(adapter->hw.hw_addr + tx_ring->tdh),
3476 readl(adapter->hw.hw_addr + tx_ring->tdt),
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003477 tx_ring->next_to_use,
Jeff Kirsher392137f2006-01-12 16:50:57 -08003478 tx_ring->next_to_clean,
3479 tx_ring->buffer_info[eop].time_stamp,
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003480 eop,
3481 jiffies,
3482 eop_desc->upper.fields.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 netif_stop_queue(netdev);
Malli Chilakala70b8f1e2005-04-28 19:40:40 -07003484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 return cleaned;
3487}
3488
3489/**
3490 * e1000_rx_checksum - Receive Checksum Offload for 82543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003491 * @adapter: board private structure
3492 * @status_err: receive descriptor status and error fields
3493 * @csum: receive descriptor csum field
3494 * @sk_buff: socket buffer with received data
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 **/
3496
3497static inline void
3498e1000_rx_checksum(struct e1000_adapter *adapter,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003499 uint32_t status_err, uint32_t csum,
3500 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003502 uint16_t status = (uint16_t)status_err;
3503 uint8_t errors = (uint8_t)(status_err >> 24);
3504 skb->ip_summed = CHECKSUM_NONE;
3505
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 /* 82543 or newer only */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003507 if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 /* Ignore Checksum bit is set */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003509 if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
3510 /* TCP/UDP checksum error bit is set */
3511 if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
3512 /* let the stack verify checksum errors */
3513 adapter->hw_csum_err++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 return;
3515 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003516 /* TCP/UDP Checksum has not been calculated */
3517 if(adapter->hw.mac_type <= e1000_82547_rev_2) {
3518 if(!(status & E1000_RXD_STAT_TCPCS))
3519 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003521 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3522 return;
3523 }
3524 /* It must be a TCP or UDP packet with a valid checksum */
3525 if (likely(status & E1000_RXD_STAT_TCPCS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 /* TCP checksum is good */
3527 skb->ip_summed = CHECKSUM_UNNECESSARY;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003528 } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3529 /* IP fragment with UDP payload */
3530 /* Hardware complements the payload checksum, so we undo it
3531 * and then put the value in host order for further stack use.
3532 */
3533 csum = ntohl(csum ^ 0xFFFF);
3534 skb->csum = csum;
3535 skb->ip_summed = CHECKSUM_HW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003537 adapter->hw_csum_good++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538}
3539
3540/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003541 * e1000_clean_rx_irq - Send received data up the network stack; legacy
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 * @adapter: board private structure
3543 **/
3544
3545static boolean_t
3546#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003547e1000_clean_rx_irq(struct e1000_adapter *adapter,
3548 struct e1000_rx_ring *rx_ring,
3549 int *work_done, int work_to_do)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003551e1000_clean_rx_irq(struct e1000_adapter *adapter,
3552 struct e1000_rx_ring *rx_ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553#endif
3554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 struct net_device *netdev = adapter->netdev;
3556 struct pci_dev *pdev = adapter->pdev;
3557 struct e1000_rx_desc *rx_desc;
3558 struct e1000_buffer *buffer_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 unsigned long flags;
3560 uint32_t length;
3561 uint8_t last_byte;
3562 unsigned int i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003563 int cleaned_count = 0;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003564 boolean_t cleaned = FALSE, multi_descriptor = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565
3566 i = rx_ring->next_to_clean;
3567 rx_desc = E1000_RX_DESC(*rx_ring, i);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003568 buffer_info = &rx_ring->buffer_info[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003570 while (rx_desc->status & E1000_RXD_STAT_DD) {
3571 struct sk_buff *skb;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003572 u8 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573#ifdef CONFIG_E1000_NAPI
3574 if(*work_done >= work_to_do)
3575 break;
3576 (*work_done)++;
3577#endif
Jeff Kirshera292ca62006-01-12 16:51:30 -08003578 status = rx_desc->status;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003579 skb = buffer_info->skb;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003580 cleaned = TRUE;
3581 cleaned_count++;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003582 pci_unmap_single(pdev,
3583 buffer_info->dma,
3584 buffer_info->length,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 PCI_DMA_FROMDEVICE);
3586
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 length = le16_to_cpu(rx_desc->length);
3588
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003589 skb_put(skb, length);
3590
3591 if (!(status & E1000_RXD_STAT_EOP)) {
3592 if (!rx_ring->rx_skb_top) {
3593 rx_ring->rx_skb_top = skb;
3594 rx_ring->rx_skb_top->len = length;
3595 rx_ring->rx_skb_prev = skb;
3596 } else {
3597 if (skb_shinfo(rx_ring->rx_skb_top)->frag_list) {
3598 rx_ring->rx_skb_prev->next = skb;
3599 skb->prev = rx_ring->rx_skb_prev;
3600 } else {
3601 skb_shinfo(rx_ring->rx_skb_top)->frag_list = skb;
3602 }
3603 rx_ring->rx_skb_prev = skb;
3604 rx_ring->rx_skb_top->data_len += length;
3605 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 goto next_desc;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003607 } else {
3608 if (rx_ring->rx_skb_top) {
3609 if (skb_shinfo(rx_ring->rx_skb_top)
3610 ->frag_list) {
3611 rx_ring->rx_skb_prev->next = skb;
3612 skb->prev = rx_ring->rx_skb_prev;
3613 } else
3614 skb_shinfo(rx_ring->rx_skb_top)
3615 ->frag_list = skb;
3616
3617 rx_ring->rx_skb_top->data_len += length;
3618 rx_ring->rx_skb_top->len +=
3619 rx_ring->rx_skb_top->data_len;
3620
3621 skb = rx_ring->rx_skb_top;
3622 multi_descriptor = TRUE;
3623 rx_ring->rx_skb_top = NULL;
3624 rx_ring->rx_skb_prev = NULL;
3625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 }
3627
3628 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3629 last_byte = *(skb->data + length - 1);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003630 if (TBI_ACCEPT(&adapter->hw, status,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 rx_desc->errors, length, last_byte)) {
3632 spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Kirshera292ca62006-01-12 16:51:30 -08003633 e1000_tbi_adjust_stats(&adapter->hw,
3634 &adapter->stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 length, skb->data);
3636 spin_unlock_irqrestore(&adapter->stats_lock,
3637 flags);
3638 length--;
3639 } else {
3640 dev_kfree_skb_irq(skb);
3641 goto next_desc;
3642 }
3643 }
3644
Jeff Kirshera292ca62006-01-12 16:51:30 -08003645 /* code added for copybreak, this should improve
3646 * performance for small packets with large amounts
3647 * of reassembly being done in the stack */
3648#define E1000_CB_LENGTH 256
3649 if ((length < E1000_CB_LENGTH) &&
3650 !rx_ring->rx_skb_top &&
3651 /* or maybe (status & E1000_RXD_STAT_EOP) && */
3652 !multi_descriptor) {
3653 struct sk_buff *new_skb =
3654 dev_alloc_skb(length + NET_IP_ALIGN);
3655 if (new_skb) {
3656 skb_reserve(new_skb, NET_IP_ALIGN);
3657 new_skb->dev = netdev;
3658 memcpy(new_skb->data - NET_IP_ALIGN,
3659 skb->data - NET_IP_ALIGN,
3660 length + NET_IP_ALIGN);
3661 /* save the skb in buffer_info as good */
3662 buffer_info->skb = skb;
3663 skb = new_skb;
3664 skb_put(skb, length);
3665 }
3666 }
3667
3668 /* end copybreak code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669
3670 /* Receive Checksum Offload */
Jeff Kirshera292ca62006-01-12 16:51:30 -08003671 e1000_rx_checksum(adapter,
3672 (uint32_t)(status) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003673 ((uint32_t)(rx_desc->errors) << 24),
3674 rx_desc->csum, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 skb->protocol = eth_type_trans(skb, netdev);
3676#ifdef CONFIG_E1000_NAPI
3677 if(unlikely(adapter->vlgrp &&
Jeff Kirshera292ca62006-01-12 16:51:30 -08003678 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003680 le16_to_cpu(rx_desc->special) &
3681 E1000_RXD_SPC_VLAN_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 } else {
3683 netif_receive_skb(skb);
3684 }
3685#else /* CONFIG_E1000_NAPI */
3686 if(unlikely(adapter->vlgrp &&
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003687 (status & E1000_RXD_STAT_VP))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 vlan_hwaccel_rx(skb, adapter->vlgrp,
3689 le16_to_cpu(rx_desc->special) &
3690 E1000_RXD_SPC_VLAN_MASK);
3691 } else {
3692 netif_rx(skb);
3693 }
3694#endif /* CONFIG_E1000_NAPI */
3695 netdev->last_rx = jiffies;
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003696#ifdef CONFIG_E1000_MQ
3697 rx_ring->rx_stats.packets++;
3698 rx_ring->rx_stats.bytes += length;
3699#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700
3701next_desc:
3702 rx_desc->status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003704 /* return some buffers to hardware, one at a time is too slow */
3705 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3706 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3707 cleaned_count = 0;
3708 }
3709
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003712
3713 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3714 if (cleaned_count)
3715 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716
3717 return cleaned;
3718}
3719
3720/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003721 * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3722 * @adapter: board private structure
3723 **/
3724
3725static boolean_t
3726#ifdef CONFIG_E1000_NAPI
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003727e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3728 struct e1000_rx_ring *rx_ring,
3729 int *work_done, int work_to_do)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003730#else
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003731e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3732 struct e1000_rx_ring *rx_ring)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003733#endif
3734{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003735 union e1000_rx_desc_packet_split *rx_desc;
3736 struct net_device *netdev = adapter->netdev;
3737 struct pci_dev *pdev = adapter->pdev;
3738 struct e1000_buffer *buffer_info;
3739 struct e1000_ps_page *ps_page;
3740 struct e1000_ps_page_dma *ps_page_dma;
3741 struct sk_buff *skb;
3742 unsigned int i, j;
3743 uint32_t length, staterr;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003744 int cleaned_count = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003745 boolean_t cleaned = FALSE;
3746
3747 i = rx_ring->next_to_clean;
3748 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
Malli Chilakala683a38f2005-06-17 17:43:25 -07003749 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003750
3751 while(staterr & E1000_RXD_STAT_DD) {
3752 buffer_info = &rx_ring->buffer_info[i];
3753 ps_page = &rx_ring->ps_page[i];
3754 ps_page_dma = &rx_ring->ps_page_dma[i];
3755#ifdef CONFIG_E1000_NAPI
3756 if(unlikely(*work_done >= work_to_do))
3757 break;
3758 (*work_done)++;
3759#endif
3760 cleaned = TRUE;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003761 cleaned_count++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003762 pci_unmap_single(pdev, buffer_info->dma,
3763 buffer_info->length,
3764 PCI_DMA_FROMDEVICE);
3765
3766 skb = buffer_info->skb;
3767
3768 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3769 E1000_DBG("%s: Packet Split buffers didn't pick up"
3770 " the full packet\n", netdev->name);
3771 dev_kfree_skb_irq(skb);
3772 goto next_desc;
3773 }
3774
3775 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3776 dev_kfree_skb_irq(skb);
3777 goto next_desc;
3778 }
3779
3780 length = le16_to_cpu(rx_desc->wb.middle.length0);
3781
3782 if(unlikely(!length)) {
3783 E1000_DBG("%s: Last part of the packet spanning"
3784 " multiple descriptors\n", netdev->name);
3785 dev_kfree_skb_irq(skb);
3786 goto next_desc;
3787 }
3788
3789 /* Good Receive */
3790 skb_put(skb, length);
3791
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003792 for(j = 0; j < adapter->rx_ps_pages; j++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003793 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3794 break;
3795
3796 pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3797 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3798 ps_page_dma->ps_page_dma[j] = 0;
3799 skb_shinfo(skb)->frags[j].page =
3800 ps_page->ps_page[j];
3801 ps_page->ps_page[j] = NULL;
3802 skb_shinfo(skb)->frags[j].page_offset = 0;
3803 skb_shinfo(skb)->frags[j].size = length;
3804 skb_shinfo(skb)->nr_frags++;
3805 skb->len += length;
3806 skb->data_len += length;
3807 }
3808
3809 e1000_rx_checksum(adapter, staterr,
3810 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3811 skb->protocol = eth_type_trans(skb, netdev);
3812
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003813 if(likely(rx_desc->wb.upper.header_status &
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003814 E1000_RXDPS_HDRSTAT_HDRSP))
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04003815 adapter->rx_hdr_split++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003816#ifdef CONFIG_E1000_NAPI
3817 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3818 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003819 le16_to_cpu(rx_desc->wb.middle.vlan) &
3820 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003821 } else {
3822 netif_receive_skb(skb);
3823 }
3824#else /* CONFIG_E1000_NAPI */
3825 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3826 vlan_hwaccel_rx(skb, adapter->vlgrp,
Malli Chilakala683a38f2005-06-17 17:43:25 -07003827 le16_to_cpu(rx_desc->wb.middle.vlan) &
3828 E1000_RXD_SPC_VLAN_MASK);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003829 } else {
3830 netif_rx(skb);
3831 }
3832#endif /* CONFIG_E1000_NAPI */
3833 netdev->last_rx = jiffies;
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08003834#ifdef CONFIG_E1000_MQ
3835 rx_ring->rx_stats.packets++;
3836 rx_ring->rx_stats.bytes += length;
3837#endif
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003838
3839next_desc:
3840 rx_desc->wb.middle.status_error &= ~0xFF;
3841 buffer_info->skb = NULL;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003842
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003843 /* return some buffers to hardware, one at a time is too slow */
3844 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3845 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3846 cleaned_count = 0;
3847 }
3848
Malli Chilakala683a38f2005-06-17 17:43:25 -07003849 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003850 }
3851 rx_ring->next_to_clean = i;
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003852
3853 cleaned_count = E1000_DESC_UNUSED(rx_ring);
3854 if (cleaned_count)
3855 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003856
3857 return cleaned;
3858}
3859
3860/**
3861 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 * @adapter: address of board private structure
3863 **/
3864
3865static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003866e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003867 struct e1000_rx_ring *rx_ring,
Jeff Kirshera292ca62006-01-12 16:51:30 -08003868 int cleaned_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 struct net_device *netdev = adapter->netdev;
3871 struct pci_dev *pdev = adapter->pdev;
3872 struct e1000_rx_desc *rx_desc;
3873 struct e1000_buffer *buffer_info;
3874 struct sk_buff *skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003875 unsigned int i;
3876 unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877
3878 i = rx_ring->next_to_use;
3879 buffer_info = &rx_ring->buffer_info[i];
3880
Jeff Kirshera292ca62006-01-12 16:51:30 -08003881 while (cleaned_count--) {
3882 if (!(skb = buffer_info->skb))
3883 skb = dev_alloc_skb(bufsz);
3884 else {
3885 skb_trim(skb, 0);
3886 goto map_skb;
3887 }
3888
Malli Chilakala26483452005-04-28 19:44:46 -07003889
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 if(unlikely(!skb)) {
3891 /* Better luck next round */
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003892 adapter->alloc_rx_buff_failed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 break;
3894 }
3895
Malli Chilakala26483452005-04-28 19:44:46 -07003896 /* Fix for errata 23, can't cross 64kB boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3898 struct sk_buff *oldskb = skb;
Malli Chilakala26483452005-04-28 19:44:46 -07003899 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3900 "at %p\n", bufsz, skb->data);
3901 /* Try again, without freeing the previous */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 skb = dev_alloc_skb(bufsz);
Malli Chilakala26483452005-04-28 19:44:46 -07003903 /* Failed allocation, critical failure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 if (!skb) {
3905 dev_kfree_skb(oldskb);
3906 break;
3907 }
Malli Chilakala26483452005-04-28 19:44:46 -07003908
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3910 /* give up */
3911 dev_kfree_skb(skb);
3912 dev_kfree_skb(oldskb);
3913 break; /* while !buffer_info->skb */
3914 } else {
Malli Chilakala26483452005-04-28 19:44:46 -07003915 /* Use new allocation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 dev_kfree_skb(oldskb);
3917 }
3918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 /* Make buffer alignment 2 beyond a 16 byte boundary
3920 * this will result in a 16 byte aligned IP header after
3921 * the 14 byte MAC header is removed
3922 */
3923 skb_reserve(skb, NET_IP_ALIGN);
3924
3925 skb->dev = netdev;
3926
3927 buffer_info->skb = skb;
3928 buffer_info->length = adapter->rx_buffer_len;
Jeff Kirshera292ca62006-01-12 16:51:30 -08003929map_skb:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 buffer_info->dma = pci_map_single(pdev,
3931 skb->data,
3932 adapter->rx_buffer_len,
3933 PCI_DMA_FROMDEVICE);
3934
Malli Chilakala26483452005-04-28 19:44:46 -07003935 /* Fix for errata 23, can't cross 64kB boundary */
3936 if (!e1000_check_64k_bound(adapter,
3937 (void *)(unsigned long)buffer_info->dma,
3938 adapter->rx_buffer_len)) {
3939 DPRINTK(RX_ERR, ERR,
3940 "dma align check failed: %u bytes at %p\n",
3941 adapter->rx_buffer_len,
3942 (void *)(unsigned long)buffer_info->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 dev_kfree_skb(skb);
3944 buffer_info->skb = NULL;
3945
Malli Chilakala26483452005-04-28 19:44:46 -07003946 pci_unmap_single(pdev, buffer_info->dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 adapter->rx_buffer_len,
3948 PCI_DMA_FROMDEVICE);
3949
3950 break; /* while !buffer_info->skb */
3951 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 rx_desc = E1000_RX_DESC(*rx_ring, i);
3953 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3954
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 if(unlikely(++i == rx_ring->count)) i = 0;
3956 buffer_info = &rx_ring->buffer_info[i];
3957 }
3958
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08003959 if (likely(rx_ring->next_to_use != i)) {
3960 rx_ring->next_to_use = i;
3961 if (unlikely(i-- == 0))
3962 i = (rx_ring->count - 1);
3963
3964 /* Force memory writes to complete before letting h/w
3965 * know there are new descriptors to fetch. (Only
3966 * applicable for weak-ordered memory model archs,
3967 * such as IA-64). */
3968 wmb();
3969 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3970 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971}
3972
3973/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003974 * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3975 * @adapter: address of board private structure
3976 **/
3977
3978static void
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04003979e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003980 struct e1000_rx_ring *rx_ring,
3981 int cleaned_count)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003982{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003983 struct net_device *netdev = adapter->netdev;
3984 struct pci_dev *pdev = adapter->pdev;
3985 union e1000_rx_desc_packet_split *rx_desc;
3986 struct e1000_buffer *buffer_info;
3987 struct e1000_ps_page *ps_page;
3988 struct e1000_ps_page_dma *ps_page_dma;
3989 struct sk_buff *skb;
3990 unsigned int i, j;
3991
3992 i = rx_ring->next_to_use;
3993 buffer_info = &rx_ring->buffer_info[i];
3994 ps_page = &rx_ring->ps_page[i];
3995 ps_page_dma = &rx_ring->ps_page_dma[i];
3996
Jeff Kirsher72d64a42006-01-12 16:51:19 -08003997 while (cleaned_count--) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003998 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3999
4000 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004001 if (j < adapter->rx_ps_pages) {
4002 if (likely(!ps_page->ps_page[j])) {
4003 ps_page->ps_page[j] =
4004 alloc_page(GFP_ATOMIC);
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004005 if (unlikely(!ps_page->ps_page[j])) {
4006 adapter->alloc_rx_buff_failed++;
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004007 goto no_buffers;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004008 }
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -04004009 ps_page_dma->ps_page_dma[j] =
4010 pci_map_page(pdev,
4011 ps_page->ps_page[j],
4012 0, PAGE_SIZE,
4013 PCI_DMA_FROMDEVICE);
4014 }
4015 /* Refresh the desc even if buffer_addrs didn't
4016 * change because each write-back erases
4017 * this info.
4018 */
4019 rx_desc->read.buffer_addr[j+1] =
4020 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
4021 } else
4022 rx_desc->read.buffer_addr[j+1] = ~0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004023 }
4024
4025 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4026
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004027 if (unlikely(!skb)) {
4028 adapter->alloc_rx_buff_failed++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004029 break;
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004030 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004031
4032 /* Make buffer alignment 2 beyond a 16 byte boundary
4033 * this will result in a 16 byte aligned IP header after
4034 * the 14 byte MAC header is removed
4035 */
4036 skb_reserve(skb, NET_IP_ALIGN);
4037
4038 skb->dev = netdev;
4039
4040 buffer_info->skb = skb;
4041 buffer_info->length = adapter->rx_ps_bsize0;
4042 buffer_info->dma = pci_map_single(pdev, skb->data,
4043 adapter->rx_ps_bsize0,
4044 PCI_DMA_FROMDEVICE);
4045
4046 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4047
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004048 if(unlikely(++i == rx_ring->count)) i = 0;
4049 buffer_info = &rx_ring->buffer_info[i];
4050 ps_page = &rx_ring->ps_page[i];
4051 ps_page_dma = &rx_ring->ps_page_dma[i];
4052 }
4053
4054no_buffers:
Jesse Brandeburgb92ff8e2006-01-18 13:01:32 -08004055 if (likely(rx_ring->next_to_use != i)) {
4056 rx_ring->next_to_use = i;
4057 if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
4058
4059 /* Force memory writes to complete before letting h/w
4060 * know there are new descriptors to fetch. (Only
4061 * applicable for weak-ordered memory model archs,
4062 * such as IA-64). */
4063 wmb();
4064 /* Hardware increments by 16 bytes, but packet split
4065 * descriptors are 32 bytes...so we increment tail
4066 * twice as much.
4067 */
4068 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4069 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004070}
4071
4072/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4074 * @adapter:
4075 **/
4076
4077static void
4078e1000_smartspeed(struct e1000_adapter *adapter)
4079{
4080 uint16_t phy_status;
4081 uint16_t phy_ctrl;
4082
4083 if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4084 !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4085 return;
4086
4087 if(adapter->smartspeed == 0) {
4088 /* If Master/Slave config fault is asserted twice,
4089 * we assume back-to-back */
4090 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4091 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4092 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4093 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4094 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4095 if(phy_ctrl & CR_1000T_MS_ENABLE) {
4096 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4097 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4098 phy_ctrl);
4099 adapter->smartspeed++;
4100 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
4101 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4102 &phy_ctrl)) {
4103 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4104 MII_CR_RESTART_AUTO_NEG);
4105 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4106 phy_ctrl);
4107 }
4108 }
4109 return;
4110 } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4111 /* If still no link, perhaps using 2/3 pair cable */
4112 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4113 phy_ctrl |= CR_1000T_MS_ENABLE;
4114 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4115 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
4116 !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4117 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4118 MII_CR_RESTART_AUTO_NEG);
4119 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4120 }
4121 }
4122 /* Restart process after E1000_SMARTSPEED_MAX iterations */
4123 if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4124 adapter->smartspeed = 0;
4125}
4126
4127/**
4128 * e1000_ioctl -
4129 * @netdev:
4130 * @ifreq:
4131 * @cmd:
4132 **/
4133
4134static int
4135e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4136{
4137 switch (cmd) {
4138 case SIOCGMIIPHY:
4139 case SIOCGMIIREG:
4140 case SIOCSMIIREG:
4141 return e1000_mii_ioctl(netdev, ifr, cmd);
4142 default:
4143 return -EOPNOTSUPP;
4144 }
4145}
4146
4147/**
4148 * e1000_mii_ioctl -
4149 * @netdev:
4150 * @ifreq:
4151 * @cmd:
4152 **/
4153
4154static int
4155e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4156{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004157 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158 struct mii_ioctl_data *data = if_mii(ifr);
4159 int retval;
4160 uint16_t mii_reg;
4161 uint16_t spddplx;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004162 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163
4164 if(adapter->hw.media_type != e1000_media_type_copper)
4165 return -EOPNOTSUPP;
4166
4167 switch (cmd) {
4168 case SIOCGMIIPHY:
4169 data->phy_id = adapter->hw.phy_addr;
4170 break;
4171 case SIOCGMIIREG:
Malli Chilakala97876fc2005-06-17 17:40:19 -07004172 if(!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004174 spin_lock_irqsave(&adapter->stats_lock, flags);
4175 if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4176 &data->val_out)) {
4177 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004179 }
4180 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 break;
4182 case SIOCSMIIREG:
Malli Chilakala97876fc2005-06-17 17:40:19 -07004183 if(!capable(CAP_NET_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 return -EPERM;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004185 if(data->reg_num & ~(0x1F))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 return -EFAULT;
4187 mii_reg = data->val_in;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004188 spin_lock_irqsave(&adapter->stats_lock, flags);
4189 if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
4190 mii_reg)) {
4191 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004193 }
4194 if(adapter->hw.phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 switch (data->reg_num) {
4196 case PHY_CTRL:
4197 if(mii_reg & MII_CR_POWER_DOWN)
4198 break;
4199 if(mii_reg & MII_CR_AUTO_NEG_EN) {
4200 adapter->hw.autoneg = 1;
4201 adapter->hw.autoneg_advertised = 0x2F;
4202 } else {
4203 if (mii_reg & 0x40)
4204 spddplx = SPEED_1000;
4205 else if (mii_reg & 0x2000)
4206 spddplx = SPEED_100;
4207 else
4208 spddplx = SPEED_10;
4209 spddplx += (mii_reg & 0x100)
4210 ? FULL_DUPLEX :
4211 HALF_DUPLEX;
4212 retval = e1000_set_spd_dplx(adapter,
4213 spddplx);
Malli Chilakala97876fc2005-06-17 17:40:19 -07004214 if(retval) {
4215 spin_unlock_irqrestore(
4216 &adapter->stats_lock,
4217 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 return retval;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004219 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 }
4221 if(netif_running(adapter->netdev)) {
4222 e1000_down(adapter);
4223 e1000_up(adapter);
4224 } else
4225 e1000_reset(adapter);
4226 break;
4227 case M88E1000_PHY_SPEC_CTRL:
4228 case M88E1000_EXT_PHY_SPEC_CTRL:
Malli Chilakala97876fc2005-06-17 17:40:19 -07004229 if(e1000_phy_reset(&adapter->hw)) {
4230 spin_unlock_irqrestore(
4231 &adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 return -EIO;
Malli Chilakala97876fc2005-06-17 17:40:19 -07004233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 break;
4235 }
4236 } else {
4237 switch (data->reg_num) {
4238 case PHY_CTRL:
4239 if(mii_reg & MII_CR_POWER_DOWN)
4240 break;
4241 if(netif_running(adapter->netdev)) {
4242 e1000_down(adapter);
4243 e1000_up(adapter);
4244 } else
4245 e1000_reset(adapter);
4246 break;
4247 }
4248 }
Malli Chilakala97876fc2005-06-17 17:40:19 -07004249 spin_unlock_irqrestore(&adapter->stats_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 break;
4251 default:
4252 return -EOPNOTSUPP;
4253 }
4254 return E1000_SUCCESS;
4255}
4256
4257void
4258e1000_pci_set_mwi(struct e1000_hw *hw)
4259{
4260 struct e1000_adapter *adapter = hw->back;
Malli Chilakala26483452005-04-28 19:44:46 -07004261 int ret_val = pci_set_mwi(adapter->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262
Malli Chilakala26483452005-04-28 19:44:46 -07004263 if(ret_val)
4264 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265}
4266
4267void
4268e1000_pci_clear_mwi(struct e1000_hw *hw)
4269{
4270 struct e1000_adapter *adapter = hw->back;
4271
4272 pci_clear_mwi(adapter->pdev);
4273}
4274
4275void
4276e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4277{
4278 struct e1000_adapter *adapter = hw->back;
4279
4280 pci_read_config_word(adapter->pdev, reg, value);
4281}
4282
4283void
4284e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4285{
4286 struct e1000_adapter *adapter = hw->back;
4287
4288 pci_write_config_word(adapter->pdev, reg, *value);
4289}
4290
4291uint32_t
4292e1000_io_read(struct e1000_hw *hw, unsigned long port)
4293{
4294 return inl(port);
4295}
4296
4297void
4298e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4299{
4300 outl(value, port);
4301}
4302
4303static void
4304e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4305{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004306 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 uint32_t ctrl, rctl;
4308
4309 e1000_irq_disable(adapter);
4310 adapter->vlgrp = grp;
4311
4312 if(grp) {
4313 /* enable VLAN tag insert/strip */
4314 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4315 ctrl |= E1000_CTRL_VME;
4316 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4317
4318 /* enable VLAN receive filtering */
4319 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4320 rctl |= E1000_RCTL_VFE;
4321 rctl &= ~E1000_RCTL_CFIEN;
4322 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004323 e1000_update_mng_vlan(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 } else {
4325 /* disable VLAN tag insert/strip */
4326 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4327 ctrl &= ~E1000_CTRL_VME;
4328 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4329
4330 /* disable VLAN filtering */
4331 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4332 rctl &= ~E1000_RCTL_VFE;
4333 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004334 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4335 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4336 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 }
4339
4340 e1000_irq_enable(adapter);
4341}
4342
4343static void
4344e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4345{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004346 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 uint32_t vfta, index;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004348 if((adapter->hw.mng_cookie.status &
4349 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4350 (vid == adapter->mng_vlan_id))
4351 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 /* add VID to filter table */
4353 index = (vid >> 5) & 0x7F;
4354 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4355 vfta |= (1 << (vid & 0x1F));
4356 e1000_write_vfta(&adapter->hw, index, vfta);
4357}
4358
4359static void
4360e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4361{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004362 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363 uint32_t vfta, index;
4364
4365 e1000_irq_disable(adapter);
4366
4367 if(adapter->vlgrp)
4368 adapter->vlgrp->vlan_devices[vid] = NULL;
4369
4370 e1000_irq_enable(adapter);
4371
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004372 if((adapter->hw.mng_cookie.status &
4373 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
Jeff Kirsherff147012006-01-12 16:51:10 -08004374 (vid == adapter->mng_vlan_id)) {
4375 /* release control to f/w */
4376 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004377 return;
Jeff Kirsherff147012006-01-12 16:51:10 -08004378 }
4379
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 /* remove VID from filter table */
4381 index = (vid >> 5) & 0x7F;
4382 vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4383 vfta &= ~(1 << (vid & 0x1F));
4384 e1000_write_vfta(&adapter->hw, index, vfta);
4385}
4386
4387static void
4388e1000_restore_vlan(struct e1000_adapter *adapter)
4389{
4390 e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4391
4392 if(adapter->vlgrp) {
4393 uint16_t vid;
4394 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4395 if(!adapter->vlgrp->vlan_devices[vid])
4396 continue;
4397 e1000_vlan_rx_add_vid(adapter->netdev, vid);
4398 }
4399 }
4400}
4401
4402int
4403e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4404{
4405 adapter->hw.autoneg = 0;
4406
Malli Chilakala69213682005-06-17 17:44:20 -07004407 /* Fiber NICs only allow 1000 gbps Full duplex */
4408 if((adapter->hw.media_type == e1000_media_type_fiber) &&
4409 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4410 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4411 return -EINVAL;
4412 }
4413
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 switch(spddplx) {
4415 case SPEED_10 + DUPLEX_HALF:
4416 adapter->hw.forced_speed_duplex = e1000_10_half;
4417 break;
4418 case SPEED_10 + DUPLEX_FULL:
4419 adapter->hw.forced_speed_duplex = e1000_10_full;
4420 break;
4421 case SPEED_100 + DUPLEX_HALF:
4422 adapter->hw.forced_speed_duplex = e1000_100_half;
4423 break;
4424 case SPEED_100 + DUPLEX_FULL:
4425 adapter->hw.forced_speed_duplex = e1000_100_full;
4426 break;
4427 case SPEED_1000 + DUPLEX_FULL:
4428 adapter->hw.autoneg = 1;
4429 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4430 break;
4431 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4432 default:
Malli Chilakala26483452005-04-28 19:44:46 -07004433 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434 return -EINVAL;
4435 }
4436 return 0;
4437}
4438
Martin J. Blighb6a1d5f2005-10-28 15:14:44 -07004439#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440static int
Pavel Machek829ca9a2005-09-03 15:56:56 -07004441e1000_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442{
4443 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004444 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004445 uint32_t ctrl, ctrl_ext, rctl, manc, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 uint32_t wufc = adapter->wol;
Jeff Kirsher240b1712006-01-12 16:51:28 -08004447 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448
4449 netif_device_detach(netdev);
4450
4451 if(netif_running(netdev))
4452 e1000_down(adapter);
4453
4454 status = E1000_READ_REG(&adapter->hw, STATUS);
4455 if(status & E1000_STATUS_LU)
4456 wufc &= ~E1000_WUFC_LNKC;
4457
4458 if(wufc) {
4459 e1000_setup_rctl(adapter);
4460 e1000_set_multi(netdev);
4461
4462 /* turn on all-multi mode if wake on multicast is enabled */
4463 if(adapter->wol & E1000_WUFC_MC) {
4464 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4465 rctl |= E1000_RCTL_MPE;
4466 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4467 }
4468
4469 if(adapter->hw.mac_type >= e1000_82540) {
4470 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4471 /* advertise wake from D3Cold */
4472 #define E1000_CTRL_ADVD3WUC 0x00100000
4473 /* phy power management enable */
4474 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4475 ctrl |= E1000_CTRL_ADVD3WUC |
4476 E1000_CTRL_EN_PHY_PWR_MGMT;
4477 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4478 }
4479
4480 if(adapter->hw.media_type == e1000_media_type_fiber ||
4481 adapter->hw.media_type == e1000_media_type_internal_serdes) {
4482 /* keep the laser running in D3 */
4483 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4484 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4485 E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4486 }
4487
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004488 /* Allow time for pending master requests to run */
4489 e1000_disable_pciex_master(&adapter->hw);
4490
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4492 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004493 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4494 if (retval)
4495 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4496 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4497 if (retval)
4498 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 } else {
4500 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4501 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004502 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4503 if (retval)
4504 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4505 retval = pci_enable_wake(pdev, PCI_D3cold, 0); /* 4 == D3 cold */
4506 if (retval)
4507 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 }
4509
4510 pci_save_state(pdev);
4511
4512 if(adapter->hw.mac_type >= e1000_82540 &&
4513 adapter->hw.media_type == e1000_media_type_copper) {
4514 manc = E1000_READ_REG(&adapter->hw, MANC);
4515 if(manc & E1000_MANC_SMBUS_EN) {
4516 manc |= E1000_MANC_ARP_EN;
4517 E1000_WRITE_REG(&adapter->hw, MANC, manc);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004518 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4519 if (retval)
4520 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4521 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4522 if (retval)
4523 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 }
4525 }
4526
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004527 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4528 * would have already happened in close and is redundant. */
4529 e1000_release_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004530
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531 pci_disable_device(pdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004532
4533 retval = pci_set_power_state(pdev, pci_choose_state(pdev, state));
4534 if (retval)
4535 DPRINTK(PROBE, ERR, "Error in setting power state\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536
4537 return 0;
4538}
4539
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540static int
4541e1000_resume(struct pci_dev *pdev)
4542{
4543 struct net_device *netdev = pci_get_drvdata(pdev);
Malli Chilakala60490fe2005-06-17 17:41:45 -07004544 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher240b1712006-01-12 16:51:28 -08004545 int retval;
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004546 uint32_t manc, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547
Jeff Kirsher240b1712006-01-12 16:51:28 -08004548 retval = pci_set_power_state(pdev, PCI_D0);
4549 if (retval)
4550 DPRINTK(PROBE, ERR, "Error in setting power state\n");
Malli Chilakala2b028932005-06-17 17:46:06 -07004551 ret_val = pci_enable_device(pdev);
Malli Chilakalaa4cb8472005-04-28 19:41:28 -07004552 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553
Jeff Kirsher240b1712006-01-12 16:51:28 -08004554 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4555 if (retval)
4556 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4557 retval = pci_enable_wake(pdev, PCI_D3cold, 0);
4558 if (retval)
4559 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560
4561 e1000_reset(adapter);
4562 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4563
4564 if(netif_running(netdev))
4565 e1000_up(adapter);
4566
4567 netif_device_attach(netdev);
4568
4569 if(adapter->hw.mac_type >= e1000_82540 &&
4570 adapter->hw.media_type == e1000_media_type_copper) {
4571 manc = E1000_READ_REG(&adapter->hw, MANC);
4572 manc &= ~(E1000_MANC_ARP_EN);
4573 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4574 }
4575
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08004576 /* If the controller is 82573 and f/w is AMT, do not set
4577 * DRV_LOAD until the interface is up. For all other cases,
4578 * let the f/w know that the h/w is now under the control
4579 * of the driver. */
4580 if (adapter->hw.mac_type != e1000_82573 ||
4581 !e1000_check_mng_mode(&adapter->hw))
4582 e1000_get_hw_control(adapter);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004583
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 return 0;
4585}
4586#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587#ifdef CONFIG_NET_POLL_CONTROLLER
4588/*
4589 * Polling 'interrupt' - used by things like netconsole to send skbs
4590 * without having to re-enable interrupts. It's not called while
4591 * the interrupt routine is executing.
4592 */
4593static void
Malli Chilakala26483452005-04-28 19:44:46 -07004594e1000_netpoll(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595{
Malli Chilakala60490fe2005-06-17 17:41:45 -07004596 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 disable_irq(adapter->pdev->irq);
4598 e1000_intr(adapter->pdev->irq, netdev, NULL);
Andrew Mortonc4cfe562005-10-15 00:32:29 -07004599 e1000_clean_tx_irq(adapter, adapter->tx_ring);
Jeff Kirshere8da8be2006-01-12 16:51:14 -08004600#ifndef CONFIG_E1000_NAPI
4601 adapter->clean_rx(adapter, adapter->rx_ring);
4602#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 enable_irq(adapter->pdev->irq);
4604}
4605#endif
4606
4607/* e1000_main.c */