blob: 4107c6db711b5b6329a236f723ed1e05deea1942 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * forcedeth: Ethernet driver for NVIDIA nForce media access controllers.
3 *
4 * Note: This driver is a cleanroom reimplementation based on reverse
5 * engineered documentation written by Carl-Daniel Hailfinger
Ayaz Abdulla87046e52006-12-19 23:33:32 -05006 * and Andrew de Quincey.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * NVIDIA, nForce and other NVIDIA marks are trademarks or registered
9 * trademarks of NVIDIA Corporation in the United States and other
10 * countries.
11 *
Manfred Spraul18360982005-12-24 14:19:24 +010012 * Copyright (C) 2003,4,5 Manfred Spraul
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * Copyright (C) 2004 Andrew de Quincey (wol support)
14 * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane
15 * IRQ rate fixes, bigendian fixes, cleanups, verification)
Ayaz Abdullaf648d122008-01-13 16:02:57 -050016 * Copyright (c) 2004,2005,2006,2007,2008 NVIDIA Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 *
32 * Changelog:
33 * 0.01: 05 Oct 2003: First release that compiles without warnings.
34 * 0.02: 05 Oct 2003: Fix bug for nv_drain_tx: do not try to free NULL skbs.
35 * Check all PCI BARs for the register window.
36 * udelay added to mii_rw.
37 * 0.03: 06 Oct 2003: Initialize dev->irq.
38 * 0.04: 07 Oct 2003: Initialize np->lock, reduce handled irqs, add printks.
39 * 0.05: 09 Oct 2003: printk removed again, irq status print tx_timeout.
40 * 0.06: 10 Oct 2003: MAC Address read updated, pff flag generation updated,
41 * irq mask updated
42 * 0.07: 14 Oct 2003: Further irq mask updates.
43 * 0.08: 20 Oct 2003: rx_desc.Length initialization added, nv_alloc_rx refill
44 * added into irq handler, NULL check for drain_ring.
45 * 0.09: 20 Oct 2003: Basic link speed irq implementation. Only handle the
46 * requested interrupt sources.
47 * 0.10: 20 Oct 2003: First cleanup for release.
48 * 0.11: 21 Oct 2003: hexdump for tx added, rx buffer sizes increased.
49 * MAC Address init fix, set_multicast cleanup.
50 * 0.12: 23 Oct 2003: Cleanups for release.
51 * 0.13: 25 Oct 2003: Limit for concurrent tx packets increased to 10.
52 * Set link speed correctly. start rx before starting
53 * tx (nv_start_rx sets the link speed).
54 * 0.14: 25 Oct 2003: Nic dependant irq mask.
55 * 0.15: 08 Nov 2003: fix smp deadlock with set_multicast_list during
56 * open.
57 * 0.16: 15 Nov 2003: include file cleanup for ppc64, rx buffer size
58 * increased to 1628 bytes.
59 * 0.17: 16 Nov 2003: undo rx buffer size increase. Substract 1 from
60 * the tx length.
61 * 0.18: 17 Nov 2003: fix oops due to late initialization of dev_stats
62 * 0.19: 29 Nov 2003: Handle RxNoBuf, detect & handle invalid mac
63 * addresses, really stop rx if already running
64 * in nv_start_rx, clean up a bit.
65 * 0.20: 07 Dec 2003: alloc fixes
66 * 0.21: 12 Jan 2004: additional alloc fix, nic polling fix.
67 * 0.22: 19 Jan 2004: reprogram timer to a sane rate, avoid lockup
68 * on close.
69 * 0.23: 26 Jan 2004: various small cleanups
70 * 0.24: 27 Feb 2004: make driver even less anonymous in backtraces
71 * 0.25: 09 Mar 2004: wol support
72 * 0.26: 03 Jun 2004: netdriver specific annotation, sparse-related fixes
73 * 0.27: 19 Jun 2004: Gigabit support, new descriptor rings,
74 * added CK804/MCP04 device IDs, code fixes
75 * for registers, link status and other minor fixes.
76 * 0.28: 21 Jun 2004: Big cleanup, making driver mostly endian safe
77 * 0.29: 31 Aug 2004: Add backup timer for link change notification.
78 * 0.30: 25 Sep 2004: rx checksum support for nf 250 Gb. Add rx reset
79 * into nv_close, otherwise reenabling for wol can
80 * cause DMA to kfree'd memory.
81 * 0.31: 14 Nov 2004: ethtool support for getting/setting link
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050082 * capabilities.
Manfred Spraul22c6d142005-04-19 21:17:09 +020083 * 0.32: 16 Apr 2005: RX_ERROR4 handling added.
Manfred Spraul8f767fc2005-06-18 16:27:19 +020084 * 0.33: 16 May 2005: Support for MCP51 added.
85 * 0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics.
Manfred Spraulf49d16e2005-06-26 11:36:52 +020086 * 0.35: 26 Jun 2005: Support for MCP55 added.
Manfred Sprauldc8216c2005-07-31 18:26:05 +020087 * 0.36: 28 Jun 2005: Add jumbo frame support.
88 * 0.37: 10 Jul 2005: Additional ethtool support, cleanup of pci id list
Manfred Spraulc2dba062005-07-31 18:29:47 +020089 * 0.38: 16 Jul 2005: tx irq rewrite: Use global flags instead of
90 * per-packet flags.
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050091 * 0.39: 18 Jul 2005: Add 64bit descriptor support.
92 * 0.40: 19 Jul 2005: Add support for mac address change.
93 * 0.41: 30 Jul 2005: Write back original MAC in nv_close instead
Manfred Spraulb3df9f82005-07-31 18:38:58 +020094 * of nv_remove
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050095 * 0.42: 06 Aug 2005: Fix lack of link speed initialization
Manfred Spraul1b1b3c92005-08-06 23:47:55 +020096 * in the second (and later) nv_open call
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050097 * 0.43: 10 Aug 2005: Add support for tx checksum.
98 * 0.44: 20 Aug 2005: Add support for scatter gather and segmentation.
99 * 0.45: 18 Sep 2005: Remove nv_stop/start_rx from every link check
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500100 * 0.46: 20 Oct 2005: Add irq optimization modes.
Ayaz Abdulla7a33e452005-11-11 08:31:11 -0500101 * 0.47: 26 Oct 2005: Add phyaddr 0 in phy scan.
Manfred Spraul18360982005-12-24 14:19:24 +0100102 * 0.48: 24 Dec 2005: Disable TSO, bugfix for pci_map_single
Ayaz Abdullafa454592006-01-05 22:45:45 -0800103 * 0.49: 10 Dec 2005: Fix tso for large buffers.
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500104 * 0.50: 20 Jan 2006: Add 8021pq tagging support.
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500105 * 0.51: 20 Jan 2006: Add 64bit consistent memory allocation for rings.
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500106 * 0.52: 20 Jan 2006: Add MSI/MSIX support.
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400107 * 0.53: 19 Mar 2006: Fix init from low power mode and add hw reset.
Ayaz Abdulla84b39322006-05-20 14:59:48 -0700108 * 0.54: 21 Mar 2006: Fix spin locks for multi irqs and cleanup.
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400109 * 0.55: 22 Mar 2006: Add flow control (pause frame).
Ayaz Abdullaebe611a2006-06-10 22:48:24 -0400110 * 0.56: 22 Mar 2006: Additional ethtool config and moduleparam support.
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400111 * 0.57: 14 May 2006: Mac address set in probe/remove and order corrections.
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500112 * 0.58: 30 Oct 2006: Added support for sideband management unit.
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500113 * 0.59: 30 Oct 2006: Added support for recoverable error.
Ayaz Abdulla21828162007-01-23 12:27:21 -0500114 * 0.60: 20 Jan 2007: Code optimizations for rings, rx & tx data paths, and stats.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 * Known bugs:
117 * We suspect that on some hardware no TX done interrupts are generated.
118 * This means recovery from netif_stop_queue only happens if the hw timer
119 * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
120 * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
121 * If your hardware reliably generates tx done interrupts, then you can remove
122 * DEV_NEED_TIMERIRQ from the driver_data flags.
123 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
124 * superfluous timer interrupts from the nic.
125 */
Stephen Hemmingere27cdba2006-07-31 20:37:19 -0700126#ifdef CONFIG_FORCEDETH_NAPI
127#define DRIVERNAPI "-NAPI"
128#else
129#define DRIVERNAPI
130#endif
Jeff Garzik8148ff42007-10-16 20:56:09 -0400131#define FORCEDETH_VERSION "0.61"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#define DRV_NAME "forcedeth"
133
134#include <linux/module.h>
135#include <linux/types.h>
136#include <linux/pci.h>
137#include <linux/interrupt.h>
138#include <linux/netdevice.h>
139#include <linux/etherdevice.h>
140#include <linux/delay.h>
141#include <linux/spinlock.h>
142#include <linux/ethtool.h>
143#include <linux/timer.h>
144#include <linux/skbuff.h>
145#include <linux/mii.h>
146#include <linux/random.h>
147#include <linux/init.h>
Manfred Spraul22c6d142005-04-19 21:17:09 +0200148#include <linux/if_vlan.h>
Matthias Gehre910638a2006-03-28 01:56:48 -0800149#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151#include <asm/irq.h>
152#include <asm/io.h>
153#include <asm/uaccess.h>
154#include <asm/system.h>
155
156#if 0
157#define dprintk printk
158#else
159#define dprintk(x...) do { } while (0)
160#endif
161
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700162#define TX_WORK_PER_LOOP 64
163#define RX_WORK_PER_LOOP 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165/*
166 * Hardware access:
167 */
168
Manfred Spraulc2dba062005-07-31 18:29:47 +0200169#define DEV_NEED_TIMERIRQ 0x0001 /* set the timer irq flag in the irq mask */
170#define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */
171#define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */
Manfred Spraulee733622005-07-31 18:32:26 +0200172#define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400173#define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500174#define DEV_HAS_VLAN 0x0020 /* device supports vlan tagging and striping */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500175#define DEV_HAS_MSI 0x0040 /* device supports MSI */
176#define DEV_HAS_MSI_X 0x0080 /* device supports MSI-X */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400177#define DEV_HAS_POWER_CNTRL 0x0100 /* device supports power savings */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400178#define DEV_HAS_PAUSEFRAME_TX 0x0200 /* device supports tx pause frames */
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500179#define DEV_HAS_STATISTICS_V1 0x0400 /* device supports hw statistics version 1 */
180#define DEV_HAS_STATISTICS_V2 0x0800 /* device supports hw statistics version 2 */
181#define DEV_HAS_TEST_EXTENDED 0x1000 /* device supports extended diagnostic test */
182#define DEV_HAS_MGMT_UNIT 0x2000 /* device supports management unit */
Ayaz Abdullaef756b32007-07-26 23:46:00 -0400183#define DEV_HAS_CORRECT_MACADDR 0x4000 /* device supports correct mac address order */
Ayaz Abdullafd9b5582008-02-05 12:29:49 -0500184#define DEV_HAS_COLLISION_FIX 0x8000 /* device supports tx collision fix */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186enum {
187 NvRegIrqStatus = 0x000,
188#define NVREG_IRQSTAT_MIIEVENT 0x040
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500189#define NVREG_IRQSTAT_MASK 0x81ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 NvRegIrqMask = 0x004,
191#define NVREG_IRQ_RX_ERROR 0x0001
192#define NVREG_IRQ_RX 0x0002
193#define NVREG_IRQ_RX_NOBUF 0x0004
194#define NVREG_IRQ_TX_ERR 0x0008
Manfred Spraulc2dba062005-07-31 18:29:47 +0200195#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196#define NVREG_IRQ_TIMER 0x0020
197#define NVREG_IRQ_LINK 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500198#define NVREG_IRQ_RX_FORCED 0x0080
199#define NVREG_IRQ_TX_FORCED 0x0100
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500200#define NVREG_IRQ_RECOVER_ERROR 0x8000
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500201#define NVREG_IRQMASK_THROUGHPUT 0x00df
Ayaz Abdulla096a4582007-05-21 20:23:11 -0400202#define NVREG_IRQMASK_CPU 0x0060
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500203#define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
204#define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED)
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500205#define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200206
207#define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500208 NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RX_FORCED| \
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500209 NVREG_IRQ_TX_FORCED|NVREG_IRQ_RECOVER_ERROR))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 NvRegUnknownSetupReg6 = 0x008,
212#define NVREG_UNKSETUP6_VAL 3
213
214/*
215 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
216 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
217 */
218 NvRegPollingInterval = 0x00c,
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -0500219#define NVREG_POLL_DEFAULT_THROUGHPUT 970 /* backup tx cleanup if loop max reached */
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500220#define NVREG_POLL_DEFAULT_CPU 13
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500221 NvRegMSIMap0 = 0x020,
222 NvRegMSIMap1 = 0x024,
223 NvRegMSIIrqMask = 0x030,
224#define NVREG_MSI_VECTOR_0_ENABLED 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 NvRegMisc1 = 0x080,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400226#define NVREG_MISC1_PAUSE_TX 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#define NVREG_MISC1_HD 0x02
228#define NVREG_MISC1_FORCE 0x3b0f3c
229
Ayaz Abdulla0a626772008-01-13 16:02:42 -0500230 NvRegMacReset = 0x34,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400231#define NVREG_MAC_RESET_ASSERT 0x0F3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 NvRegTransmitterControl = 0x084,
233#define NVREG_XMITCTL_START 0x01
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500234#define NVREG_XMITCTL_MGMT_ST 0x40000000
235#define NVREG_XMITCTL_SYNC_MASK 0x000f0000
236#define NVREG_XMITCTL_SYNC_NOT_READY 0x0
237#define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
238#define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
239#define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
240#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
241#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
242#define NVREG_XMITCTL_HOST_LOADED 0x00004000
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500243#define NVREG_XMITCTL_TX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 NvRegTransmitterStatus = 0x088,
245#define NVREG_XMITSTAT_BUSY 0x01
246
247 NvRegPacketFilterFlags = 0x8c,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400248#define NVREG_PFF_PAUSE_RX 0x08
249#define NVREG_PFF_ALWAYS 0x7F0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250#define NVREG_PFF_PROMISC 0x80
251#define NVREG_PFF_MYADDR 0x20
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400252#define NVREG_PFF_LOOPBACK 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 NvRegOffloadConfig = 0x90,
255#define NVREG_OFFLOAD_HOMEPHY 0x601
256#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
257 NvRegReceiverControl = 0x094,
258#define NVREG_RCVCTL_START 0x01
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500259#define NVREG_RCVCTL_RX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 NvRegReceiverStatus = 0x98,
261#define NVREG_RCVSTAT_BUSY 0x01
262
263 NvRegRandomSeed = 0x9c,
264#define NVREG_RNDSEED_MASK 0x00ff
265#define NVREG_RNDSEED_FORCE 0x7f00
266#define NVREG_RNDSEED_FORCE2 0x2d00
267#define NVREG_RNDSEED_FORCE3 0x7400
268
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400269 NvRegTxDeferral = 0xA0,
Ayaz Abdullafd9b5582008-02-05 12:29:49 -0500270#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
271#define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
272#define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
273#define NVREG_TX_DEFERRAL_RGMII_STRETCH_10 0x16190f
274#define NVREG_TX_DEFERRAL_RGMII_STRETCH_100 0x16300f
275#define NVREG_TX_DEFERRAL_MII_STRETCH 0x152000
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400276 NvRegRxDeferral = 0xA4,
277#define NVREG_RX_DEFERRAL_DEFAULT 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 NvRegMacAddrA = 0xA8,
279 NvRegMacAddrB = 0xAC,
280 NvRegMulticastAddrA = 0xB0,
281#define NVREG_MCASTADDRA_FORCE 0x01
282 NvRegMulticastAddrB = 0xB4,
283 NvRegMulticastMaskA = 0xB8,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500284#define NVREG_MCASTMASKA_NONE 0xffffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 NvRegMulticastMaskB = 0xBC,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500286#define NVREG_MCASTMASKB_NONE 0xffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 NvRegPhyInterface = 0xC0,
289#define PHY_RGMII 0x10000000
290
291 NvRegTxRingPhysAddr = 0x100,
292 NvRegRxRingPhysAddr = 0x104,
293 NvRegRingSizes = 0x108,
294#define NVREG_RINGSZ_TXSHIFT 0
295#define NVREG_RINGSZ_RXSHIFT 16
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400296 NvRegTransmitPoll = 0x10c,
297#define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 NvRegLinkSpeed = 0x110,
299#define NVREG_LINKSPEED_FORCE 0x10000
300#define NVREG_LINKSPEED_10 1000
301#define NVREG_LINKSPEED_100 100
302#define NVREG_LINKSPEED_1000 50
303#define NVREG_LINKSPEED_MASK (0xFFF)
304 NvRegUnknownSetupReg5 = 0x130,
305#define NVREG_UNKSETUP5_BIT31 (1<<31)
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400306 NvRegTxWatermark = 0x13c,
307#define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
308#define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
309#define NVREG_TX_WM_DESC2_3_1000 0xfe08000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 NvRegTxRxControl = 0x144,
311#define NVREG_TXRXCTL_KICK 0x0001
312#define NVREG_TXRXCTL_BIT1 0x0002
313#define NVREG_TXRXCTL_BIT2 0x0004
314#define NVREG_TXRXCTL_IDLE 0x0008
315#define NVREG_TXRXCTL_RESET 0x0010
316#define NVREG_TXRXCTL_RXCHECK 0x0400
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400317#define NVREG_TXRXCTL_DESC_1 0
Ayaz Abdullad2f78412007-01-09 13:30:02 -0500318#define NVREG_TXRXCTL_DESC_2 0x002100
319#define NVREG_TXRXCTL_DESC_3 0xc02200
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500320#define NVREG_TXRXCTL_VLANSTRIP 0x00040
321#define NVREG_TXRXCTL_VLANINS 0x00080
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500322 NvRegTxRingPhysAddrHigh = 0x148,
323 NvRegRxRingPhysAddrHigh = 0x14C,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400324 NvRegTxPauseFrame = 0x170,
Ayaz Abdulla32fa8b22008-01-13 16:03:01 -0500325#define NVREG_TX_PAUSEFRAME_DISABLE 0x01ff0080
326#define NVREG_TX_PAUSEFRAME_ENABLE 0x01800010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 NvRegMIIStatus = 0x180,
328#define NVREG_MIISTAT_ERROR 0x0001
329#define NVREG_MIISTAT_LINKCHANGE 0x0008
Ayaz Abdullaeb798422008-02-04 15:14:04 -0500330#define NVREG_MIISTAT_MASK_RW 0x0007
331#define NVREG_MIISTAT_MASK_ALL 0x000f
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500332 NvRegMIIMask = 0x184,
333#define NVREG_MII_LINKCHANGE 0x0008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 NvRegAdapterControl = 0x188,
336#define NVREG_ADAPTCTL_START 0x02
337#define NVREG_ADAPTCTL_LINKUP 0x04
338#define NVREG_ADAPTCTL_PHYVALID 0x40000
339#define NVREG_ADAPTCTL_RUNNING 0x100000
340#define NVREG_ADAPTCTL_PHYSHIFT 24
341 NvRegMIISpeed = 0x18c,
342#define NVREG_MIISPEED_BIT8 (1<<8)
343#define NVREG_MIIDELAY 5
344 NvRegMIIControl = 0x190,
345#define NVREG_MIICTL_INUSE 0x08000
346#define NVREG_MIICTL_WRITE 0x00400
347#define NVREG_MIICTL_ADDRSHIFT 5
348 NvRegMIIData = 0x194,
349 NvRegWakeUpFlags = 0x200,
350#define NVREG_WAKEUPFLAGS_VAL 0x7770
351#define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
352#define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
353#define NVREG_WAKEUPFLAGS_D3SHIFT 12
354#define NVREG_WAKEUPFLAGS_D2SHIFT 8
355#define NVREG_WAKEUPFLAGS_D1SHIFT 4
356#define NVREG_WAKEUPFLAGS_D0SHIFT 0
357#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
358#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
359#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
360#define NVREG_WAKEUPFLAGS_ENABLE 0x1111
361
362 NvRegPatternCRC = 0x204,
363 NvRegPatternMask = 0x208,
364 NvRegPowerCap = 0x268,
365#define NVREG_POWERCAP_D3SUPP (1<<30)
366#define NVREG_POWERCAP_D2SUPP (1<<26)
367#define NVREG_POWERCAP_D1SUPP (1<<25)
368 NvRegPowerState = 0x26c,
369#define NVREG_POWERSTATE_POWEREDUP 0x8000
370#define NVREG_POWERSTATE_VALID 0x0100
371#define NVREG_POWERSTATE_MASK 0x0003
372#define NVREG_POWERSTATE_D0 0x0000
373#define NVREG_POWERSTATE_D1 0x0001
374#define NVREG_POWERSTATE_D2 0x0002
375#define NVREG_POWERSTATE_D3 0x0003
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400376 NvRegTxCnt = 0x280,
377 NvRegTxZeroReXmt = 0x284,
378 NvRegTxOneReXmt = 0x288,
379 NvRegTxManyReXmt = 0x28c,
380 NvRegTxLateCol = 0x290,
381 NvRegTxUnderflow = 0x294,
382 NvRegTxLossCarrier = 0x298,
383 NvRegTxExcessDef = 0x29c,
384 NvRegTxRetryErr = 0x2a0,
385 NvRegRxFrameErr = 0x2a4,
386 NvRegRxExtraByte = 0x2a8,
387 NvRegRxLateCol = 0x2ac,
388 NvRegRxRunt = 0x2b0,
389 NvRegRxFrameTooLong = 0x2b4,
390 NvRegRxOverflow = 0x2b8,
391 NvRegRxFCSErr = 0x2bc,
392 NvRegRxFrameAlignErr = 0x2c0,
393 NvRegRxLenErr = 0x2c4,
394 NvRegRxUnicast = 0x2c8,
395 NvRegRxMulticast = 0x2cc,
396 NvRegRxBroadcast = 0x2d0,
397 NvRegTxDef = 0x2d4,
398 NvRegTxFrame = 0x2d8,
399 NvRegRxCnt = 0x2dc,
400 NvRegTxPause = 0x2e0,
401 NvRegRxPause = 0x2e4,
402 NvRegRxDropFrame = 0x2e8,
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500403 NvRegVlanControl = 0x300,
404#define NVREG_VLANCONTROL_ENABLE 0x2000
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500405 NvRegMSIXMap0 = 0x3e0,
406 NvRegMSIXMap1 = 0x3e4,
407 NvRegMSIXIrqStatus = 0x3f0,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400408
409 NvRegPowerState2 = 0x600,
410#define NVREG_POWERSTATE2_POWERUP_MASK 0x0F11
411#define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412};
413
414/* Big endian: should work, but is untested */
415struct ring_desc {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700416 __le32 buf;
417 __le32 flaglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418};
419
Manfred Spraulee733622005-07-31 18:32:26 +0200420struct ring_desc_ex {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700421 __le32 bufhigh;
422 __le32 buflow;
423 __le32 txvlan;
424 __le32 flaglen;
Manfred Spraulee733622005-07-31 18:32:26 +0200425};
426
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700427union ring_type {
Manfred Spraulee733622005-07-31 18:32:26 +0200428 struct ring_desc* orig;
429 struct ring_desc_ex* ex;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700430};
Manfred Spraulee733622005-07-31 18:32:26 +0200431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define FLAG_MASK_V1 0xffff0000
433#define FLAG_MASK_V2 0xffffc000
434#define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
435#define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
436
437#define NV_TX_LASTPACKET (1<<16)
438#define NV_TX_RETRYERROR (1<<19)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200439#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NV_TX_DEFERRED (1<<26)
441#define NV_TX_CARRIERLOST (1<<27)
442#define NV_TX_LATECOLLISION (1<<28)
443#define NV_TX_UNDERFLOW (1<<29)
444#define NV_TX_ERROR (1<<30)
445#define NV_TX_VALID (1<<31)
446
447#define NV_TX2_LASTPACKET (1<<29)
448#define NV_TX2_RETRYERROR (1<<18)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200449#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define NV_TX2_DEFERRED (1<<25)
451#define NV_TX2_CARRIERLOST (1<<26)
452#define NV_TX2_LATECOLLISION (1<<27)
453#define NV_TX2_UNDERFLOW (1<<28)
454/* error and valid are the same for both */
455#define NV_TX2_ERROR (1<<30)
456#define NV_TX2_VALID (1<<31)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400457#define NV_TX2_TSO (1<<28)
458#define NV_TX2_TSO_SHIFT 14
Ayaz Abdullafa454592006-01-05 22:45:45 -0800459#define NV_TX2_TSO_MAX_SHIFT 14
460#define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400461#define NV_TX2_CHECKSUM_L3 (1<<27)
462#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500464#define NV_TX3_VLAN_TAG_PRESENT (1<<18)
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define NV_RX_DESCRIPTORVALID (1<<16)
467#define NV_RX_MISSEDFRAME (1<<17)
468#define NV_RX_SUBSTRACT1 (1<<18)
469#define NV_RX_ERROR1 (1<<23)
470#define NV_RX_ERROR2 (1<<24)
471#define NV_RX_ERROR3 (1<<25)
472#define NV_RX_ERROR4 (1<<26)
473#define NV_RX_CRCERR (1<<27)
474#define NV_RX_OVERFLOW (1<<28)
475#define NV_RX_FRAMINGERR (1<<29)
476#define NV_RX_ERROR (1<<30)
477#define NV_RX_AVAIL (1<<31)
478
479#define NV_RX2_CHECKSUMMASK (0x1C000000)
Ayaz Abdullabfaffe82008-01-13 16:02:55 -0500480#define NV_RX2_CHECKSUM_IP (0x10000000)
481#define NV_RX2_CHECKSUM_IP_TCP (0x14000000)
482#define NV_RX2_CHECKSUM_IP_UDP (0x18000000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#define NV_RX2_DESCRIPTORVALID (1<<29)
484#define NV_RX2_SUBSTRACT1 (1<<25)
485#define NV_RX2_ERROR1 (1<<18)
486#define NV_RX2_ERROR2 (1<<19)
487#define NV_RX2_ERROR3 (1<<20)
488#define NV_RX2_ERROR4 (1<<21)
489#define NV_RX2_CRCERR (1<<22)
490#define NV_RX2_OVERFLOW (1<<23)
491#define NV_RX2_FRAMINGERR (1<<24)
492/* error and avail are the same for both */
493#define NV_RX2_ERROR (1<<30)
494#define NV_RX2_AVAIL (1<<31)
495
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500496#define NV_RX3_VLAN_TAG_PRESENT (1<<16)
497#define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499/* Miscelaneous hardware related defines: */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400500#define NV_PCI_REGSZ_VER1 0x270
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500501#define NV_PCI_REGSZ_VER2 0x2d4
502#define NV_PCI_REGSZ_VER3 0x604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504/* various timeout delays: all in usec */
505#define NV_TXRX_RESET_DELAY 4
506#define NV_TXSTOP_DELAY1 10
507#define NV_TXSTOP_DELAY1MAX 500000
508#define NV_TXSTOP_DELAY2 100
509#define NV_RXSTOP_DELAY1 10
510#define NV_RXSTOP_DELAY1MAX 500000
511#define NV_RXSTOP_DELAY2 100
512#define NV_SETUP5_DELAY 5
513#define NV_SETUP5_DELAYMAX 50000
514#define NV_POWERUP_DELAY 5
515#define NV_POWERUP_DELAYMAX 5000
516#define NV_MIIBUSY_DELAY 50
517#define NV_MIIPHY_DELAY 10
518#define NV_MIIPHY_DELAYMAX 10000
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400519#define NV_MAC_RESET_DELAY 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521#define NV_WAKEUPPATTERNS 5
522#define NV_WAKEUPMASKENTRIES 4
523
524/* General driver defaults */
525#define NV_WATCHDOG_TIMEO (5*HZ)
526
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400527#define RX_RING_DEFAULT 128
528#define TX_RING_DEFAULT 256
529#define RX_RING_MIN 128
530#define TX_RING_MIN 64
531#define RING_MAX_DESC_VER_1 1024
532#define RING_MAX_DESC_VER_2_3 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200535#define NV_RX_HEADERS (64)
536/* even more slack. */
537#define NV_RX_ALLOC_PAD (64)
538
539/* maximum mtu size */
540#define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
541#define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543#define OOM_REFILL (1+HZ/20)
544#define POLL_WAIT (1+HZ/100)
545#define LINK_TIMEOUT (3*HZ)
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400546#define STATS_INTERVAL (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400548/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400550 * The nic supports three different descriptor types:
551 * - DESC_VER_1: Original
552 * - DESC_VER_2: support for jumbo frames.
553 * - DESC_VER_3: 64-bit format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400555#define DESC_VER_1 1
556#define DESC_VER_2 2
557#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559/* PHY defines */
560#define PHY_OUI_MARVELL 0x5043
561#define PHY_OUI_CICADA 0x03f1
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400562#define PHY_OUI_VITESSE 0x01c1
Willy Tarreauba685fb2007-08-23 21:35:41 +0200563#define PHY_OUI_REALTEK 0x0732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564#define PHYID1_OUI_MASK 0x03ff
565#define PHYID1_OUI_SHFT 6
566#define PHYID2_OUI_MASK 0xfc00
567#define PHYID2_OUI_SHFT 10
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400568#define PHYID2_MODEL_MASK 0x03f0
569#define PHY_MODEL_MARVELL_E3016 0x220
570#define PHY_MARVELL_E3016_INITMASK 0x0300
Ayaz Abdulla14a67f32007-07-15 06:50:28 -0400571#define PHY_CICADA_INIT1 0x0f000
572#define PHY_CICADA_INIT2 0x0e00
573#define PHY_CICADA_INIT3 0x01000
574#define PHY_CICADA_INIT4 0x0200
575#define PHY_CICADA_INIT5 0x0004
576#define PHY_CICADA_INIT6 0x02000
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400577#define PHY_VITESSE_INIT_REG1 0x1f
578#define PHY_VITESSE_INIT_REG2 0x10
579#define PHY_VITESSE_INIT_REG3 0x11
580#define PHY_VITESSE_INIT_REG4 0x12
581#define PHY_VITESSE_INIT_MSK1 0xc
582#define PHY_VITESSE_INIT_MSK2 0x0180
583#define PHY_VITESSE_INIT1 0x52b5
584#define PHY_VITESSE_INIT2 0xaf8a
585#define PHY_VITESSE_INIT3 0x8
586#define PHY_VITESSE_INIT4 0x8f8a
587#define PHY_VITESSE_INIT5 0xaf86
588#define PHY_VITESSE_INIT6 0x8f86
589#define PHY_VITESSE_INIT7 0xaf82
590#define PHY_VITESSE_INIT8 0x0100
591#define PHY_VITESSE_INIT9 0x8f82
592#define PHY_VITESSE_INIT10 0x0
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400593#define PHY_REALTEK_INIT_REG1 0x1f
594#define PHY_REALTEK_INIT_REG2 0x19
595#define PHY_REALTEK_INIT_REG3 0x13
596#define PHY_REALTEK_INIT1 0x0000
597#define PHY_REALTEK_INIT2 0x8e00
598#define PHY_REALTEK_INIT3 0x0001
599#define PHY_REALTEK_INIT4 0xad17
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601#define PHY_GIGABIT 0x0100
602
603#define PHY_TIMEOUT 0x1
604#define PHY_ERROR 0x2
605
606#define PHY_100 0x1
607#define PHY_1000 0x2
608#define PHY_HALF 0x100
609
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400610#define NV_PAUSEFRAME_RX_CAPABLE 0x0001
611#define NV_PAUSEFRAME_TX_CAPABLE 0x0002
612#define NV_PAUSEFRAME_RX_ENABLE 0x0004
613#define NV_PAUSEFRAME_TX_ENABLE 0x0008
Ayaz Abdullab6d07732006-06-10 22:47:42 -0400614#define NV_PAUSEFRAME_RX_REQ 0x0010
615#define NV_PAUSEFRAME_TX_REQ 0x0020
616#define NV_PAUSEFRAME_AUTONEG 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500618/* MSI/MSI-X defines */
619#define NV_MSI_X_MAX_VECTORS 8
620#define NV_MSI_X_VECTORS_MASK 0x000f
621#define NV_MSI_CAPABLE 0x0010
622#define NV_MSI_X_CAPABLE 0x0020
623#define NV_MSI_ENABLED 0x0040
624#define NV_MSI_X_ENABLED 0x0080
625
626#define NV_MSI_X_VECTOR_ALL 0x0
627#define NV_MSI_X_VECTOR_RX 0x0
628#define NV_MSI_X_VECTOR_TX 0x1
629#define NV_MSI_X_VECTOR_OTHER 0x2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Ayaz Abdullab2976d22008-02-04 15:13:59 -0500631#define NV_RESTART_TX 0x1
632#define NV_RESTART_RX 0x2
633
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400634/* statistics */
635struct nv_ethtool_str {
636 char name[ETH_GSTRING_LEN];
637};
638
639static const struct nv_ethtool_str nv_estats_str[] = {
640 { "tx_bytes" },
641 { "tx_zero_rexmt" },
642 { "tx_one_rexmt" },
643 { "tx_many_rexmt" },
644 { "tx_late_collision" },
645 { "tx_fifo_errors" },
646 { "tx_carrier_errors" },
647 { "tx_excess_deferral" },
648 { "tx_retry_error" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400649 { "rx_frame_error" },
650 { "rx_extra_byte" },
651 { "rx_late_collision" },
652 { "rx_runt" },
653 { "rx_frame_too_long" },
654 { "rx_over_errors" },
655 { "rx_crc_errors" },
656 { "rx_frame_align_error" },
657 { "rx_length_error" },
658 { "rx_unicast" },
659 { "rx_multicast" },
660 { "rx_broadcast" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400661 { "rx_packets" },
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500662 { "rx_errors_total" },
663 { "tx_errors_total" },
664
665 /* version 2 stats */
666 { "tx_deferral" },
667 { "tx_packets" },
668 { "rx_bytes" },
669 { "tx_pause" },
670 { "rx_pause" },
671 { "rx_drop_frame" }
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400672};
673
674struct nv_ethtool_stats {
675 u64 tx_bytes;
676 u64 tx_zero_rexmt;
677 u64 tx_one_rexmt;
678 u64 tx_many_rexmt;
679 u64 tx_late_collision;
680 u64 tx_fifo_errors;
681 u64 tx_carrier_errors;
682 u64 tx_excess_deferral;
683 u64 tx_retry_error;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400684 u64 rx_frame_error;
685 u64 rx_extra_byte;
686 u64 rx_late_collision;
687 u64 rx_runt;
688 u64 rx_frame_too_long;
689 u64 rx_over_errors;
690 u64 rx_crc_errors;
691 u64 rx_frame_align_error;
692 u64 rx_length_error;
693 u64 rx_unicast;
694 u64 rx_multicast;
695 u64 rx_broadcast;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400696 u64 rx_packets;
697 u64 rx_errors_total;
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500698 u64 tx_errors_total;
699
700 /* version 2 stats */
701 u64 tx_deferral;
702 u64 tx_packets;
703 u64 rx_bytes;
704 u64 tx_pause;
705 u64 rx_pause;
706 u64 rx_drop_frame;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400707};
708
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500709#define NV_DEV_STATISTICS_V2_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64))
710#define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6)
711
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400712/* diagnostics */
713#define NV_TEST_COUNT_BASE 3
714#define NV_TEST_COUNT_EXTENDED 4
715
716static const struct nv_ethtool_str nv_etests_str[] = {
717 { "link (online/offline)" },
718 { "register (offline) " },
719 { "interrupt (offline) " },
720 { "loopback (offline) " }
721};
722
723struct register_test {
Al Viro5bb7ea22007-12-09 16:06:41 +0000724 __u32 reg;
725 __u32 mask;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400726};
727
728static const struct register_test nv_registers_test[] = {
729 { NvRegUnknownSetupReg6, 0x01 },
730 { NvRegMisc1, 0x03c },
731 { NvRegOffloadConfig, 0x03ff },
732 { NvRegMulticastAddrA, 0xffffffff },
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400733 { NvRegTxWatermark, 0x0ff },
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400734 { NvRegWakeUpFlags, 0x07777 },
735 { 0,0 }
736};
737
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500738struct nv_skb_map {
739 struct sk_buff *skb;
740 dma_addr_t dma;
741 unsigned int dma_len;
742};
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744/*
745 * SMP locking:
746 * All hardware access under dev->priv->lock, except the performance
747 * critical parts:
748 * - rx is (pseudo-) lockless: it relies on the single-threading provided
749 * by the arch code for interrupts.
Herbert Xu932ff272006-06-09 12:20:56 -0700750 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 * needs dev->priv->lock :-(
Herbert Xu932ff272006-06-09 12:20:56 -0700752 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 */
754
755/* in dev: base, irq */
756struct fe_priv {
757 spinlock_t lock;
758
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700759 struct net_device *dev;
760 struct napi_struct napi;
761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 /* General data:
763 * Locking: spin_lock(&np->lock); */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400764 struct nv_ethtool_stats estats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 int in_shutdown;
766 u32 linkspeed;
767 int duplex;
768 int autoneg;
769 int fixed_mode;
770 int phyaddr;
771 int wolenabled;
772 unsigned int phy_oui;
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400773 unsigned int phy_model;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 u16 gigabit;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400775 int intr_test;
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500776 int recover_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 /* General data: RO fields */
779 dma_addr_t ring_addr;
780 struct pci_dev *pci_dev;
781 u32 orig_mac[2];
782 u32 irqmask;
783 u32 desc_ver;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400784 u32 txrxctl_bits;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500785 u32 vlanctl_bits;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400786 u32 driver_data;
787 u32 register_size;
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -0400788 int rx_csum;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500789 u32 mac_in_use;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 void __iomem *base;
792
793 /* rx specific fields.
794 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
795 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500796 union ring_type get_rx, put_rx, first_rx, last_rx;
797 struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
798 struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
799 struct nv_skb_map *rx_skb;
800
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700801 union ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200803 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 struct timer_list oom_kick;
805 struct timer_list nic_poll;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400806 struct timer_list stats_poll;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500807 u32 nic_poll_irq;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400808 int rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
810 /* media detection workaround.
811 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
812 */
813 int need_linktimer;
814 unsigned long link_timeout;
815 /*
816 * tx specific fields.
817 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500818 union ring_type get_tx, put_tx, first_tx, last_tx;
819 struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
820 struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
821 struct nv_skb_map *tx_skb;
822
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700823 union ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 u32 tx_flags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400825 int tx_ring_size;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -0500826 int tx_stop;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500827
828 /* vlan fields */
829 struct vlan_group *vlangrp;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500830
831 /* msi/msi-x fields */
832 u32 msi_flags;
833 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400834
835 /* flow control */
836 u32 pause_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837};
838
839/*
840 * Maximum number of loops until we assume that a bit in the irq mask
841 * is stuck. Overridable with module param.
842 */
843static int max_interrupt_work = 5;
844
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500845/*
846 * Optimization can be either throuput mode or cpu mode
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400847 *
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500848 * Throughput Mode: Every tx and rx packet will generate an interrupt.
849 * CPU Mode: Interrupts are controlled by a timer.
850 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400851enum {
852 NV_OPTIMIZATION_MODE_THROUGHPUT,
853 NV_OPTIMIZATION_MODE_CPU
854};
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500855static int optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
856
857/*
858 * Poll interval for timer irq
859 *
860 * This interval determines how frequent an interrupt is generated.
861 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
862 * Min = 0, and Max = 65535
863 */
864static int poll_interval = -1;
865
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500866/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400867 * MSI interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500868 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400869enum {
870 NV_MSI_INT_DISABLED,
871 NV_MSI_INT_ENABLED
872};
873static int msi = NV_MSI_INT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500874
875/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400876 * MSIX interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500877 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400878enum {
879 NV_MSIX_INT_DISABLED,
880 NV_MSIX_INT_ENABLED
881};
Ayaz Abdullacaf96462007-02-20 03:34:40 -0500882static int msix = NV_MSIX_INT_DISABLED;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400883
884/*
885 * DMA 64bit
886 */
887enum {
888 NV_DMA_64BIT_DISABLED,
889 NV_DMA_64BIT_ENABLED
890};
891static int dma_64bit = NV_DMA_64BIT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893static inline struct fe_priv *get_nvpriv(struct net_device *dev)
894{
895 return netdev_priv(dev);
896}
897
898static inline u8 __iomem *get_hwbase(struct net_device *dev)
899{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400900 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
903static inline void pci_push(u8 __iomem *base)
904{
905 /* force out pending posted writes */
906 readl(base);
907}
908
909static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
910{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700911 return le32_to_cpu(prd->flaglen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
913}
914
Manfred Spraulee733622005-07-31 18:32:26 +0200915static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
916{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700917 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
Manfred Spraulee733622005-07-31 18:32:26 +0200918}
919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
921 int delay, int delaymax, const char *msg)
922{
923 u8 __iomem *base = get_hwbase(dev);
924
925 pci_push(base);
926 do {
927 udelay(delay);
928 delaymax -= delay;
929 if (delaymax < 0) {
930 if (msg)
931 printk(msg);
932 return 1;
933 }
934 } while ((readl(base + offset) & mask) != target);
935 return 0;
936}
937
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500938#define NV_SETUP_RX_RING 0x01
939#define NV_SETUP_TX_RING 0x02
940
Al Viro5bb7ea22007-12-09 16:06:41 +0000941static inline u32 dma_low(dma_addr_t addr)
942{
943 return addr;
944}
945
946static inline u32 dma_high(dma_addr_t addr)
947{
948 return addr>>31>>1; /* 0 if 32bit, shift down by 32 if 64bit */
949}
950
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500951static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
952{
953 struct fe_priv *np = get_nvpriv(dev);
954 u8 __iomem *base = get_hwbase(dev);
955
956 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
957 if (rxtx_flags & NV_SETUP_RX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000958 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500959 }
960 if (rxtx_flags & NV_SETUP_TX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000961 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500962 }
963 } else {
964 if (rxtx_flags & NV_SETUP_RX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000965 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
966 writel(dma_high(np->ring_addr), base + NvRegRxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500967 }
968 if (rxtx_flags & NV_SETUP_TX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000969 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
970 writel(dma_high(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500971 }
972 }
973}
974
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400975static void free_rings(struct net_device *dev)
976{
977 struct fe_priv *np = get_nvpriv(dev);
978
979 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700980 if (np->rx_ring.orig)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400981 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
982 np->rx_ring.orig, np->ring_addr);
983 } else {
984 if (np->rx_ring.ex)
985 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
986 np->rx_ring.ex, np->ring_addr);
987 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500988 if (np->rx_skb)
989 kfree(np->rx_skb);
990 if (np->tx_skb)
991 kfree(np->tx_skb);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400992}
993
Ayaz Abdulla84b39322006-05-20 14:59:48 -0700994static int using_multi_irqs(struct net_device *dev)
995{
996 struct fe_priv *np = get_nvpriv(dev);
997
998 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
999 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1000 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
1001 return 0;
1002 else
1003 return 1;
1004}
1005
1006static void nv_enable_irq(struct net_device *dev)
1007{
1008 struct fe_priv *np = get_nvpriv(dev);
1009
1010 if (!using_multi_irqs(dev)) {
1011 if (np->msi_flags & NV_MSI_X_ENABLED)
1012 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1013 else
Manfred Spraula7475902007-10-17 21:52:33 +02001014 enable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001015 } else {
1016 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1017 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1018 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1019 }
1020}
1021
1022static void nv_disable_irq(struct net_device *dev)
1023{
1024 struct fe_priv *np = get_nvpriv(dev);
1025
1026 if (!using_multi_irqs(dev)) {
1027 if (np->msi_flags & NV_MSI_X_ENABLED)
1028 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1029 else
Manfred Spraula7475902007-10-17 21:52:33 +02001030 disable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001031 } else {
1032 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1033 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1034 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1035 }
1036}
1037
1038/* In MSIX mode, a write to irqmask behaves as XOR */
1039static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
1040{
1041 u8 __iomem *base = get_hwbase(dev);
1042
1043 writel(mask, base + NvRegIrqMask);
1044}
1045
1046static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
1047{
1048 struct fe_priv *np = get_nvpriv(dev);
1049 u8 __iomem *base = get_hwbase(dev);
1050
1051 if (np->msi_flags & NV_MSI_X_ENABLED) {
1052 writel(mask, base + NvRegIrqMask);
1053 } else {
1054 if (np->msi_flags & NV_MSI_ENABLED)
1055 writel(0, base + NvRegMSIIrqMask);
1056 writel(0, base + NvRegIrqMask);
1057 }
1058}
1059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060#define MII_READ (-1)
1061/* mii_rw: read/write a register on the PHY.
1062 *
1063 * Caller must guarantee serialization
1064 */
1065static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1066{
1067 u8 __iomem *base = get_hwbase(dev);
1068 u32 reg;
1069 int retval;
1070
Ayaz Abdullaeb798422008-02-04 15:14:04 -05001071 writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 reg = readl(base + NvRegMIIControl);
1074 if (reg & NVREG_MIICTL_INUSE) {
1075 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1076 udelay(NV_MIIBUSY_DELAY);
1077 }
1078
1079 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1080 if (value != MII_READ) {
1081 writel(value, base + NvRegMIIData);
1082 reg |= NVREG_MIICTL_WRITE;
1083 }
1084 writel(reg, base + NvRegMIIControl);
1085
1086 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
1087 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
1088 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n",
1089 dev->name, miireg, addr);
1090 retval = -1;
1091 } else if (value != MII_READ) {
1092 /* it was a write operation - fewer failures are detectable */
1093 dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
1094 dev->name, value, miireg, addr);
1095 retval = 0;
1096 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
1097 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n",
1098 dev->name, miireg, addr);
1099 retval = -1;
1100 } else {
1101 retval = readl(base + NvRegMIIData);
1102 dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
1103 dev->name, miireg, addr, retval);
1104 }
1105
1106 return retval;
1107}
1108
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001109static int phy_reset(struct net_device *dev, u32 bmcr_setup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001111 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 u32 miicontrol;
1113 unsigned int tries = 0;
1114
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001115 miicontrol = BMCR_RESET | bmcr_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) {
1117 return -1;
1118 }
1119
1120 /* wait for 500ms */
1121 msleep(500);
1122
1123 /* must wait till reset is deasserted */
1124 while (miicontrol & BMCR_RESET) {
1125 msleep(10);
1126 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1127 /* FIXME: 100 tries seem excessive */
1128 if (tries++ > 100)
1129 return -1;
1130 }
1131 return 0;
1132}
1133
1134static int phy_init(struct net_device *dev)
1135{
1136 struct fe_priv *np = get_nvpriv(dev);
1137 u8 __iomem *base = get_hwbase(dev);
1138 u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg;
1139
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001140 /* phy errata for E3016 phy */
1141 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1142 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1143 reg &= ~PHY_MARVELL_E3016_INITMASK;
1144 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
1145 printk(KERN_INFO "%s: phy write to errata reg failed.\n", pci_name(np->pci_dev));
1146 return PHY_ERROR;
1147 }
1148 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001149 if (np->phy_oui == PHY_OUI_REALTEK) {
1150 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1151 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1152 return PHY_ERROR;
1153 }
1154 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1155 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1156 return PHY_ERROR;
1157 }
1158 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1159 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1160 return PHY_ERROR;
1161 }
1162 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1163 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1164 return PHY_ERROR;
1165 }
1166 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1167 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1168 return PHY_ERROR;
1169 }
1170 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 /* set advertise register */
1173 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001174 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|ADVERTISE_PAUSE_ASYM|ADVERTISE_PAUSE_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
1176 printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev));
1177 return PHY_ERROR;
1178 }
1179
1180 /* get phy interface type */
1181 phyinterface = readl(base + NvRegPhyInterface);
1182
1183 /* see if gigabit phy */
1184 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1185 if (mii_status & PHY_GIGABIT) {
1186 np->gigabit = PHY_GIGABIT;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001187 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 mii_control_1000 &= ~ADVERTISE_1000HALF;
1189 if (phyinterface & PHY_RGMII)
1190 mii_control_1000 |= ADVERTISE_1000FULL;
1191 else
1192 mii_control_1000 &= ~ADVERTISE_1000FULL;
1193
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001194 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1196 return PHY_ERROR;
1197 }
1198 }
1199 else
1200 np->gigabit = 0;
1201
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001202 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1203 mii_control |= BMCR_ANENABLE;
1204
1205 /* reset the phy
1206 * (certain phys need bmcr to be setup with reset)
1207 */
1208 if (phy_reset(dev, mii_control)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev));
1210 return PHY_ERROR;
1211 }
1212
1213 /* phy vendor specific configuration */
1214 if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) {
1215 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
Ayaz Abdulla14a67f32007-07-15 06:50:28 -04001216 phy_reserved &= ~(PHY_CICADA_INIT1 | PHY_CICADA_INIT2);
1217 phy_reserved |= (PHY_CICADA_INIT3 | PHY_CICADA_INIT4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) {
1219 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1220 return PHY_ERROR;
1221 }
1222 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
Ayaz Abdulla14a67f32007-07-15 06:50:28 -04001223 phy_reserved |= PHY_CICADA_INIT5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) {
1225 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1226 return PHY_ERROR;
1227 }
1228 }
1229 if (np->phy_oui == PHY_OUI_CICADA) {
1230 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
Ayaz Abdulla14a67f32007-07-15 06:50:28 -04001231 phy_reserved |= PHY_CICADA_INIT6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) {
1233 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1234 return PHY_ERROR;
1235 }
1236 }
Ayaz Abdullad215d8a2007-07-15 06:50:53 -04001237 if (np->phy_oui == PHY_OUI_VITESSE) {
1238 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT1)) {
1239 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1240 return PHY_ERROR;
1241 }
1242 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT2)) {
1243 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1244 return PHY_ERROR;
1245 }
1246 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1247 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1248 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1249 return PHY_ERROR;
1250 }
1251 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1252 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1253 phy_reserved |= PHY_VITESSE_INIT3;
1254 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1255 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1256 return PHY_ERROR;
1257 }
1258 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT4)) {
1259 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1260 return PHY_ERROR;
1261 }
1262 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT5)) {
1263 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1264 return PHY_ERROR;
1265 }
1266 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1267 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1268 phy_reserved |= PHY_VITESSE_INIT3;
1269 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1270 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1271 return PHY_ERROR;
1272 }
1273 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1274 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1275 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1276 return PHY_ERROR;
1277 }
1278 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT6)) {
1279 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1280 return PHY_ERROR;
1281 }
1282 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT7)) {
1283 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1284 return PHY_ERROR;
1285 }
1286 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1287 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1288 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1289 return PHY_ERROR;
1290 }
1291 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1292 phy_reserved &= ~PHY_VITESSE_INIT_MSK2;
1293 phy_reserved |= PHY_VITESSE_INIT8;
1294 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1295 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1296 return PHY_ERROR;
1297 }
1298 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT9)) {
1299 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1300 return PHY_ERROR;
1301 }
1302 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT10)) {
1303 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1304 return PHY_ERROR;
1305 }
1306 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001307 if (np->phy_oui == PHY_OUI_REALTEK) {
1308 /* reset could have cleared these out, set them back */
1309 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1310 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1311 return PHY_ERROR;
1312 }
1313 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1314 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1315 return PHY_ERROR;
1316 }
1317 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1318 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1319 return PHY_ERROR;
1320 }
1321 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1322 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1323 return PHY_ERROR;
1324 }
1325 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1326 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1327 return PHY_ERROR;
1328 }
1329 }
1330
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001331 /* some phys clear out pause advertisment on reset, set it back */
1332 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 /* restart auto negotiation */
1335 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1336 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
1337 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
1338 return PHY_ERROR;
1339 }
1340
1341 return 0;
1342}
1343
1344static void nv_start_rx(struct net_device *dev)
1345{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001346 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001348 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
1350 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
1351 /* Already running? Stop it. */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001352 if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
1353 rx_ctrl &= ~NVREG_RCVCTL_START;
1354 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 pci_push(base);
1356 }
1357 writel(np->linkspeed, base + NvRegLinkSpeed);
1358 pci_push(base);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001359 rx_ctrl |= NVREG_RCVCTL_START;
1360 if (np->mac_in_use)
1361 rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN;
1362 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
1364 dev->name, np->duplex, np->linkspeed);
1365 pci_push(base);
1366}
1367
1368static void nv_stop_rx(struct net_device *dev)
1369{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001370 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001372 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
1374 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001375 if (!np->mac_in_use)
1376 rx_ctrl &= ~NVREG_RCVCTL_START;
1377 else
1378 rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN;
1379 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1381 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
1382 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
1383
1384 udelay(NV_RXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001385 if (!np->mac_in_use)
1386 writel(0, base + NvRegLinkSpeed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387}
1388
1389static void nv_start_tx(struct net_device *dev)
1390{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001391 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001393 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
1395 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001396 tx_ctrl |= NVREG_XMITCTL_START;
1397 if (np->mac_in_use)
1398 tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN;
1399 writel(tx_ctrl, base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 pci_push(base);
1401}
1402
1403static void nv_stop_tx(struct net_device *dev)
1404{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001405 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001407 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
1409 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001410 if (!np->mac_in_use)
1411 tx_ctrl &= ~NVREG_XMITCTL_START;
1412 else
1413 tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN;
1414 writel(tx_ctrl, base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1416 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
1417 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
1418
1419 udelay(NV_TXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001420 if (!np->mac_in_use)
1421 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
1422 base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423}
1424
1425static void nv_txrx_reset(struct net_device *dev)
1426{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001427 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 u8 __iomem *base = get_hwbase(dev);
1429
1430 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001431 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 pci_push(base);
1433 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001434 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 pci_push(base);
1436}
1437
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001438static void nv_mac_reset(struct net_device *dev)
1439{
1440 struct fe_priv *np = netdev_priv(dev);
1441 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001442 u32 temp1, temp2, temp3;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001443
1444 dprintk(KERN_DEBUG "%s: nv_mac_reset\n", dev->name);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001445
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001446 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1447 pci_push(base);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001448
1449 /* save registers since they will be cleared on reset */
1450 temp1 = readl(base + NvRegMacAddrA);
1451 temp2 = readl(base + NvRegMacAddrB);
1452 temp3 = readl(base + NvRegTransmitPoll);
1453
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001454 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1455 pci_push(base);
1456 udelay(NV_MAC_RESET_DELAY);
1457 writel(0, base + NvRegMacReset);
1458 pci_push(base);
1459 udelay(NV_MAC_RESET_DELAY);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001460
1461 /* restore saved registers */
1462 writel(temp1, base + NvRegMacAddrA);
1463 writel(temp2, base + NvRegMacAddrB);
1464 writel(temp3, base + NvRegTransmitPoll);
1465
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001466 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1467 pci_push(base);
1468}
1469
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001470static void nv_get_hw_stats(struct net_device *dev)
1471{
1472 struct fe_priv *np = netdev_priv(dev);
1473 u8 __iomem *base = get_hwbase(dev);
1474
1475 np->estats.tx_bytes += readl(base + NvRegTxCnt);
1476 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
1477 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
1478 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
1479 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
1480 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
1481 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
1482 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
1483 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
1484 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
1485 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
1486 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
1487 np->estats.rx_runt += readl(base + NvRegRxRunt);
1488 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
1489 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
1490 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
1491 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
1492 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
1493 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
1494 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
1495 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
1496 np->estats.rx_packets =
1497 np->estats.rx_unicast +
1498 np->estats.rx_multicast +
1499 np->estats.rx_broadcast;
1500 np->estats.rx_errors_total =
1501 np->estats.rx_crc_errors +
1502 np->estats.rx_over_errors +
1503 np->estats.rx_frame_error +
1504 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
1505 np->estats.rx_late_collision +
1506 np->estats.rx_runt +
1507 np->estats.rx_frame_too_long;
1508 np->estats.tx_errors_total =
1509 np->estats.tx_late_collision +
1510 np->estats.tx_fifo_errors +
1511 np->estats.tx_carrier_errors +
1512 np->estats.tx_excess_deferral +
1513 np->estats.tx_retry_error;
1514
1515 if (np->driver_data & DEV_HAS_STATISTICS_V2) {
1516 np->estats.tx_deferral += readl(base + NvRegTxDef);
1517 np->estats.tx_packets += readl(base + NvRegTxFrame);
1518 np->estats.rx_bytes += readl(base + NvRegRxCnt);
1519 np->estats.tx_pause += readl(base + NvRegTxPause);
1520 np->estats.rx_pause += readl(base + NvRegRxPause);
1521 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
1522 }
1523}
1524
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525/*
1526 * nv_get_stats: dev->get_stats function
1527 * Get latest stats value from the nic.
1528 * Called with read_lock(&dev_base_lock) held for read -
1529 * only synchronized against unregister_netdevice.
1530 */
1531static struct net_device_stats *nv_get_stats(struct net_device *dev)
1532{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001533 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Ayaz Abdulla21828162007-01-23 12:27:21 -05001535 /* If the nic supports hw counters then retrieve latest values */
1536 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2)) {
1537 nv_get_hw_stats(dev);
1538
1539 /* copy to net_device stats */
Jeff Garzik8148ff42007-10-16 20:56:09 -04001540 dev->stats.tx_bytes = np->estats.tx_bytes;
1541 dev->stats.tx_fifo_errors = np->estats.tx_fifo_errors;
1542 dev->stats.tx_carrier_errors = np->estats.tx_carrier_errors;
1543 dev->stats.rx_crc_errors = np->estats.rx_crc_errors;
1544 dev->stats.rx_over_errors = np->estats.rx_over_errors;
1545 dev->stats.rx_errors = np->estats.rx_errors_total;
1546 dev->stats.tx_errors = np->estats.tx_errors_total;
Ayaz Abdulla21828162007-01-23 12:27:21 -05001547 }
Jeff Garzik8148ff42007-10-16 20:56:09 -04001548
1549 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550}
1551
1552/*
1553 * nv_alloc_rx: fill rx ring entries.
1554 * Return 1 if the allocations for the skbs failed and the
1555 * rx engine is without Available descriptors
1556 */
1557static int nv_alloc_rx(struct net_device *dev)
1558{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001559 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001560 struct ring_desc* less_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001562 less_rx = np->get_rx.orig;
1563 if (less_rx-- == np->first_rx.orig)
1564 less_rx = np->last_rx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001565
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001566 while (np->put_rx.orig != less_rx) {
1567 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001568 if (skb) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001569 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001570 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1571 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001572 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001573 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001574 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001575 np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
1576 wmb();
1577 np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001578 if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001579 np->put_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001580 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001581 np->put_rx_ctx = np->first_rx_ctx;
1582 } else {
1583 return 1;
1584 }
1585 }
1586 return 0;
1587}
1588
1589static int nv_alloc_rx_optimized(struct net_device *dev)
1590{
1591 struct fe_priv *np = netdev_priv(dev);
1592 struct ring_desc_ex* less_rx;
1593
1594 less_rx = np->get_rx.ex;
1595 if (less_rx-- == np->first_rx.ex)
1596 less_rx = np->last_rx.ex;
1597
1598 while (np->put_rx.ex != less_rx) {
1599 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
1600 if (skb) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001601 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001602 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1603 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001604 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001605 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001606 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Al Viro5bb7ea22007-12-09 16:06:41 +00001607 np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
1608 np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001609 wmb();
1610 np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001611 if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001612 np->put_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001613 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001614 np->put_rx_ctx = np->first_rx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 } else {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001616 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 return 0;
1620}
1621
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001622/* If rx bufs are exhausted called after 50ms to attempt to refresh */
1623#ifdef CONFIG_FORCEDETH_NAPI
1624static void nv_do_rx_refill(unsigned long data)
1625{
1626 struct net_device *dev = (struct net_device *) data;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001627 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001628
1629 /* Just reschedule NAPI rx processing */
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001630 netif_rx_schedule(dev, &np->napi);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001631}
1632#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633static void nv_do_rx_refill(unsigned long data)
1634{
1635 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001636 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001637 int retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001639 if (!using_multi_irqs(dev)) {
1640 if (np->msi_flags & NV_MSI_X_ENABLED)
1641 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1642 else
Manfred Spraula7475902007-10-17 21:52:33 +02001643 disable_irq(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001644 } else {
1645 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1646 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001647 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1648 retcode = nv_alloc_rx(dev);
1649 else
1650 retcode = nv_alloc_rx_optimized(dev);
1651 if (retcode) {
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001652 spin_lock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 if (!np->in_shutdown)
1654 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001655 spin_unlock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001657 if (!using_multi_irqs(dev)) {
1658 if (np->msi_flags & NV_MSI_X_ENABLED)
1659 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1660 else
Manfred Spraula7475902007-10-17 21:52:33 +02001661 enable_irq(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001662 } else {
1663 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001666#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001668static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001669{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001670 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001671 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001672 np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
1673 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1674 np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
1675 else
1676 np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
1677 np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
1678 np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
Manfred Sprauld81c0982005-07-31 18:20:30 +02001679
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001680 for (i = 0; i < np->rx_ring_size; i++) {
1681 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001682 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001683 np->rx_ring.orig[i].buf = 0;
1684 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001685 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001686 np->rx_ring.ex[i].txvlan = 0;
1687 np->rx_ring.ex[i].bufhigh = 0;
1688 np->rx_ring.ex[i].buflow = 0;
1689 }
1690 np->rx_skb[i].skb = NULL;
1691 np->rx_skb[i].dma = 0;
1692 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001693}
1694
1695static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001697 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001699 np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
1700 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1701 np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
1702 else
1703 np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
1704 np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
1705 np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001707 for (i = 0; i < np->tx_ring_size; i++) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001708 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001709 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001710 np->tx_ring.orig[i].buf = 0;
1711 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001712 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001713 np->tx_ring.ex[i].txvlan = 0;
1714 np->tx_ring.ex[i].bufhigh = 0;
1715 np->tx_ring.ex[i].buflow = 0;
1716 }
1717 np->tx_skb[i].skb = NULL;
1718 np->tx_skb[i].dma = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001719 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001720}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Manfred Sprauld81c0982005-07-31 18:20:30 +02001722static int nv_init_ring(struct net_device *dev)
1723{
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001724 struct fe_priv *np = netdev_priv(dev);
1725
Manfred Sprauld81c0982005-07-31 18:20:30 +02001726 nv_init_tx(dev);
1727 nv_init_rx(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001728 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1729 return nv_alloc_rx(dev);
1730 else
1731 return nv_alloc_rx_optimized(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001734static int nv_release_txskb(struct net_device *dev, struct nv_skb_map* tx_skb)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001735{
1736 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001737
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001738 if (tx_skb->dma) {
1739 pci_unmap_page(np->pci_dev, tx_skb->dma,
1740 tx_skb->dma_len,
Ayaz Abdullafa454592006-01-05 22:45:45 -08001741 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001742 tx_skb->dma = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001743 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001744 if (tx_skb->skb) {
1745 dev_kfree_skb_any(tx_skb->skb);
1746 tx_skb->skb = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001747 return 1;
1748 } else {
1749 return 0;
1750 }
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001751}
1752
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753static void nv_drain_tx(struct net_device *dev)
1754{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001755 struct fe_priv *np = netdev_priv(dev);
1756 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001757
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001758 for (i = 0; i < np->tx_ring_size; i++) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001759 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001760 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001761 np->tx_ring.orig[i].buf = 0;
1762 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001763 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001764 np->tx_ring.ex[i].txvlan = 0;
1765 np->tx_ring.ex[i].bufhigh = 0;
1766 np->tx_ring.ex[i].buflow = 0;
1767 }
1768 if (nv_release_txskb(dev, &np->tx_skb[i]))
Jeff Garzik8148ff42007-10-16 20:56:09 -04001769 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 }
1771}
1772
1773static void nv_drain_rx(struct net_device *dev)
1774{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001775 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001777
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001778 for (i = 0; i < np->rx_ring_size; i++) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001779 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001780 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001781 np->rx_ring.orig[i].buf = 0;
1782 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001783 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001784 np->rx_ring.ex[i].txvlan = 0;
1785 np->rx_ring.ex[i].bufhigh = 0;
1786 np->rx_ring.ex[i].buflow = 0;
1787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 wmb();
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001789 if (np->rx_skb[i].skb) {
1790 pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001791 (skb_end_pointer(np->rx_skb[i].skb) -
1792 np->rx_skb[i].skb->data),
1793 PCI_DMA_FROMDEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001794 dev_kfree_skb(np->rx_skb[i].skb);
1795 np->rx_skb[i].skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 }
1797 }
1798}
1799
1800static void drain_ring(struct net_device *dev)
1801{
1802 nv_drain_tx(dev);
1803 nv_drain_rx(dev);
1804}
1805
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001806static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
1807{
1808 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
1809}
1810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811/*
1812 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07001813 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 */
1815static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1816{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001817 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001818 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001819 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
1820 unsigned int fragments = skb_shinfo(skb)->nr_frags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001821 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001822 u32 offset = 0;
1823 u32 bcnt;
1824 u32 size = skb->len-skb->data_len;
1825 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001826 u32 empty_slots;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001827 struct ring_desc* put_tx;
1828 struct ring_desc* start_tx;
1829 struct ring_desc* prev_tx;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001830 struct nv_skb_map* prev_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001831
1832 /* add fragments to entries count */
1833 for (i = 0; i < fragments; i++) {
1834 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1835 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001838 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001839 if (unlikely(empty_slots <= entries)) {
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05001840 spin_lock_irq(&np->lock);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001841 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001842 np->tx_stop = 1;
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05001843 spin_unlock_irq(&np->lock);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001844 return NETDEV_TX_BUSY;
1845 }
1846
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001847 start_tx = put_tx = np->put_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001848
Ayaz Abdullafa454592006-01-05 22:45:45 -08001849 /* setup the header buffer */
1850 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001851 prev_tx = put_tx;
1852 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001853 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001854 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
Ayaz Abdullafa454592006-01-05 22:45:45 -08001855 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001856 np->put_tx_ctx->dma_len = bcnt;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001857 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
1858 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001859
Ayaz Abdullafa454592006-01-05 22:45:45 -08001860 tx_flags = np->tx_flags;
1861 offset += bcnt;
1862 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001863 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001864 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001865 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001866 np->put_tx_ctx = np->first_tx_ctx;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001867 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001868
1869 /* setup the fragments */
1870 for (i = 0; i < fragments; i++) {
1871 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1872 u32 size = frag->size;
1873 offset = 0;
1874
1875 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001876 prev_tx = put_tx;
1877 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001878 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001879 np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
1880 PCI_DMA_TODEVICE);
1881 np->put_tx_ctx->dma_len = bcnt;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001882 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
1883 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001884
Ayaz Abdullafa454592006-01-05 22:45:45 -08001885 offset += bcnt;
1886 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001887 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001888 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001889 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001890 np->put_tx_ctx = np->first_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001891 } while (size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001892 }
1893
Ayaz Abdullafa454592006-01-05 22:45:45 -08001894 /* set last fragment flag */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001895 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001896
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001897 /* save skb in this slot's context area */
1898 prev_tx_ctx->skb = skb;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001899
Herbert Xu89114af2006-07-08 13:34:32 -07001900 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07001901 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02001902 else
Arjan van de Ven1d39ed52006-12-12 14:06:23 +01001903 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
Patrick McHardy84fa7932006-08-29 16:44:56 -07001904 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001905
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05001906 spin_lock_irq(&np->lock);
1907
Ayaz Abdullafa454592006-01-05 22:45:45 -08001908 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001909 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
1910 np->put_tx.orig = put_tx;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001911
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05001912 spin_unlock_irq(&np->lock);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001913
1914 dprintk(KERN_DEBUG "%s: nv_start_xmit: entries %d queued for transmission. tx_flags_extra: %x\n",
1915 dev->name, entries, tx_flags_extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 {
1917 int j;
1918 for (j=0; j<64; j++) {
1919 if ((j%16) == 0)
1920 dprintk("\n%03x:", j);
1921 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
1922 }
1923 dprintk("\n");
1924 }
1925
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 dev->trans_start = jiffies;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001927 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001928 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929}
1930
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001931static int nv_start_xmit_optimized(struct sk_buff *skb, struct net_device *dev)
1932{
1933 struct fe_priv *np = netdev_priv(dev);
1934 u32 tx_flags = 0;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001935 u32 tx_flags_extra;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001936 unsigned int fragments = skb_shinfo(skb)->nr_frags;
1937 unsigned int i;
1938 u32 offset = 0;
1939 u32 bcnt;
1940 u32 size = skb->len-skb->data_len;
1941 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1942 u32 empty_slots;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001943 struct ring_desc_ex* put_tx;
1944 struct ring_desc_ex* start_tx;
1945 struct ring_desc_ex* prev_tx;
1946 struct nv_skb_map* prev_tx_ctx;
1947
1948 /* add fragments to entries count */
1949 for (i = 0; i < fragments; i++) {
1950 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1951 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1952 }
1953
1954 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001955 if (unlikely(empty_slots <= entries)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001956 spin_lock_irq(&np->lock);
1957 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001958 np->tx_stop = 1;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001959 spin_unlock_irq(&np->lock);
1960 return NETDEV_TX_BUSY;
1961 }
1962
1963 start_tx = put_tx = np->put_tx.ex;
1964
1965 /* setup the header buffer */
1966 do {
1967 prev_tx = put_tx;
1968 prev_tx_ctx = np->put_tx_ctx;
1969 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
1970 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
1971 PCI_DMA_TODEVICE);
1972 np->put_tx_ctx->dma_len = bcnt;
Al Viro5bb7ea22007-12-09 16:06:41 +00001973 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
1974 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001975 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001976
1977 tx_flags = NV_TX2_VALID;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001978 offset += bcnt;
1979 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001980 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001981 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001982 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001983 np->put_tx_ctx = np->first_tx_ctx;
1984 } while (size);
1985
1986 /* setup the fragments */
1987 for (i = 0; i < fragments; i++) {
1988 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1989 u32 size = frag->size;
1990 offset = 0;
1991
1992 do {
1993 prev_tx = put_tx;
1994 prev_tx_ctx = np->put_tx_ctx;
1995 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
1996 np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
1997 PCI_DMA_TODEVICE);
1998 np->put_tx_ctx->dma_len = bcnt;
Al Viro5bb7ea22007-12-09 16:06:41 +00001999 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2000 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002001 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002002
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002003 offset += bcnt;
2004 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002005 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002006 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002007 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002008 np->put_tx_ctx = np->first_tx_ctx;
2009 } while (size);
2010 }
2011
2012 /* set last fragment flag */
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002013 prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002014
2015 /* save skb in this slot's context area */
2016 prev_tx_ctx->skb = skb;
2017
2018 if (skb_is_gso(skb))
2019 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
2020 else
2021 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
2022 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
2023
2024 /* vlan tag */
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002025 if (likely(!np->vlangrp)) {
2026 start_tx->txvlan = 0;
2027 } else {
2028 if (vlan_tx_tag_present(skb))
2029 start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb));
2030 else
2031 start_tx->txvlan = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002032 }
2033
2034 spin_lock_irq(&np->lock);
2035
2036 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002037 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
2038 np->put_tx.ex = put_tx;
2039
2040 spin_unlock_irq(&np->lock);
2041
2042 dprintk(KERN_DEBUG "%s: nv_start_xmit_optimized: entries %d queued for transmission. tx_flags_extra: %x\n",
2043 dev->name, entries, tx_flags_extra);
2044 {
2045 int j;
2046 for (j=0; j<64; j++) {
2047 if ((j%16) == 0)
2048 dprintk("\n%03x:", j);
2049 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
2050 }
2051 dprintk("\n");
2052 }
2053
2054 dev->trans_start = jiffies;
2055 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002056 return NETDEV_TX_OK;
2057}
2058
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059/*
2060 * nv_tx_done: check for completed packets, release the skbs.
2061 *
2062 * Caller must own np->lock.
2063 */
2064static void nv_tx_done(struct net_device *dev)
2065{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002066 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002067 u32 flags;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002068 struct ring_desc* orig_get_tx = np->get_tx.orig;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002070 while ((np->get_tx.orig != np->put_tx.orig) &&
2071 !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002073 dprintk(KERN_DEBUG "%s: nv_tx_done: flags 0x%x.\n",
2074 dev->name, flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002075
2076 pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma,
2077 np->get_tx_ctx->dma_len,
2078 PCI_DMA_TODEVICE);
2079 np->get_tx_ctx->dma = 0;
2080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002082 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002083 if (flags & NV_TX_ERROR) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002084 if (flags & NV_TX_UNDERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002085 dev->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002086 if (flags & NV_TX_CARRIERLOST)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002087 dev->stats.tx_carrier_errors++;
2088 dev->stats.tx_errors++;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002089 } else {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002090 dev->stats.tx_packets++;
2091 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002092 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002093 dev_kfree_skb_any(np->get_tx_ctx->skb);
2094 np->get_tx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 }
2096 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002097 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002098 if (flags & NV_TX2_ERROR) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002099 if (flags & NV_TX2_UNDERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002100 dev->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002101 if (flags & NV_TX2_CARRIERLOST)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002102 dev->stats.tx_carrier_errors++;
2103 dev->stats.tx_errors++;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002104 } else {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002105 dev->stats.tx_packets++;
2106 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002107 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002108 dev_kfree_skb_any(np->get_tx_ctx->skb);
2109 np->get_tx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 }
2111 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002112 if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002113 np->get_tx.orig = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002114 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002115 np->get_tx_ctx = np->first_tx_ctx;
2116 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002117 if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002118 np->tx_stop = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002119 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002120 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002121}
2122
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002123static void nv_tx_done_optimized(struct net_device *dev, int limit)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002124{
2125 struct fe_priv *np = netdev_priv(dev);
2126 u32 flags;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002127 struct ring_desc_ex* orig_get_tx = np->get_tx.ex;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002128
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002129 while ((np->get_tx.ex != np->put_tx.ex) &&
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002130 !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX_VALID) &&
2131 (limit-- > 0)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002132
2133 dprintk(KERN_DEBUG "%s: nv_tx_done_optimized: flags 0x%x.\n",
2134 dev->name, flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002135
2136 pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma,
2137 np->get_tx_ctx->dma_len,
2138 PCI_DMA_TODEVICE);
2139 np->get_tx_ctx->dma = 0;
2140
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002141 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla21828162007-01-23 12:27:21 -05002142 if (!(flags & NV_TX2_ERROR))
Jeff Garzik8148ff42007-10-16 20:56:09 -04002143 dev->stats.tx_packets++;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002144 dev_kfree_skb_any(np->get_tx_ctx->skb);
2145 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002146 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002147 if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002148 np->get_tx.ex = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002149 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002150 np->get_tx_ctx = np->first_tx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002152 if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002153 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156}
2157
2158/*
2159 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07002160 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 */
2162static void nv_tx_timeout(struct net_device *dev)
2163{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002164 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002166 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002168 if (np->msi_flags & NV_MSI_X_ENABLED)
2169 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2170 else
2171 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2172
2173 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Manfred Spraulc2dba062005-07-31 18:29:47 +02002175 {
2176 int i;
2177
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002178 printk(KERN_INFO "%s: Ring at %lx\n",
2179 dev->name, (unsigned long)np->ring_addr);
Manfred Spraulc2dba062005-07-31 18:29:47 +02002180 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04002181 for (i=0;i<=np->register_size;i+= 32) {
Manfred Spraulc2dba062005-07-31 18:29:47 +02002182 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
2183 i,
2184 readl(base + i + 0), readl(base + i + 4),
2185 readl(base + i + 8), readl(base + i + 12),
2186 readl(base + i + 16), readl(base + i + 20),
2187 readl(base + i + 24), readl(base + i + 28));
2188 }
2189 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002190 for (i=0;i<np->tx_ring_size;i+= 4) {
Manfred Spraulee733622005-07-31 18:32:26 +02002191 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
2192 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002193 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002194 le32_to_cpu(np->tx_ring.orig[i].buf),
2195 le32_to_cpu(np->tx_ring.orig[i].flaglen),
2196 le32_to_cpu(np->tx_ring.orig[i+1].buf),
2197 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
2198 le32_to_cpu(np->tx_ring.orig[i+2].buf),
2199 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
2200 le32_to_cpu(np->tx_ring.orig[i+3].buf),
2201 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02002202 } else {
2203 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002204 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002205 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
2206 le32_to_cpu(np->tx_ring.ex[i].buflow),
2207 le32_to_cpu(np->tx_ring.ex[i].flaglen),
2208 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
2209 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
2210 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
2211 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
2212 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
2213 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
2214 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
2215 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
2216 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02002217 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02002218 }
2219 }
2220
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 spin_lock_irq(&np->lock);
2222
2223 /* 1) stop tx engine */
2224 nv_stop_tx(dev);
2225
2226 /* 2) check that the packets were not sent already: */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002227 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
2228 nv_tx_done(dev);
2229 else
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002230 nv_tx_done_optimized(dev, np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
2232 /* 3) if there are dead entries: clear everything */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002233 if (np->get_tx_ctx != np->put_tx_ctx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name);
2235 nv_drain_tx(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002236 nv_init_tx(dev);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002237 setup_hw_rings(dev, NV_SETUP_TX_RING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 }
2239
Ayaz Abdulla3ba4d092007-03-23 05:50:02 -05002240 netif_wake_queue(dev);
2241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 /* 4) restart tx engine */
2243 nv_start_tx(dev);
2244 spin_unlock_irq(&np->lock);
2245}
2246
Manfred Spraul22c6d142005-04-19 21:17:09 +02002247/*
2248 * Called when the nic notices a mismatch between the actual data len on the
2249 * wire and the len indicated in the 802 header
2250 */
2251static int nv_getlen(struct net_device *dev, void *packet, int datalen)
2252{
2253 int hdrlen; /* length of the 802 header */
2254 int protolen; /* length as stored in the proto field */
2255
2256 /* 1) calculate len according to header */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002257 if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
Manfred Spraul22c6d142005-04-19 21:17:09 +02002258 protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto );
2259 hdrlen = VLAN_HLEN;
2260 } else {
2261 protolen = ntohs( ((struct ethhdr *)packet)->h_proto);
2262 hdrlen = ETH_HLEN;
2263 }
2264 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
2265 dev->name, datalen, protolen, hdrlen);
2266 if (protolen > ETH_DATA_LEN)
2267 return datalen; /* Value in proto field not a len, no checks possible */
2268
2269 protolen += hdrlen;
2270 /* consistency checks: */
2271 if (datalen > ETH_ZLEN) {
2272 if (datalen >= protolen) {
2273 /* more data on wire than in 802 header, trim of
2274 * additional data.
2275 */
2276 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2277 dev->name, protolen);
2278 return protolen;
2279 } else {
2280 /* less data on wire than mentioned in header.
2281 * Discard the packet.
2282 */
2283 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
2284 dev->name);
2285 return -1;
2286 }
2287 } else {
2288 /* short packet. Accept only if 802 values are also short */
2289 if (protolen > ETH_ZLEN) {
2290 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
2291 dev->name);
2292 return -1;
2293 }
2294 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2295 dev->name, datalen);
2296 return datalen;
2297 }
2298}
2299
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002300static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002302 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002303 u32 flags;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002304 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002305 struct sk_buff *skb;
2306 int len;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002307
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002308 while((np->get_rx.orig != np->put_rx.orig) &&
2309 !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002310 (rx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002312 dprintk(KERN_DEBUG "%s: nv_rx_process: flags 0x%x.\n",
2313 dev->name, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 /*
2316 * the packet is for us - immediately tear down the pci mapping.
2317 * TODO: check if a prefetch of the first cacheline improves
2318 * the performance.
2319 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002320 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2321 np->get_rx_ctx->dma_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 PCI_DMA_FROMDEVICE);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002323 skb = np->get_rx_ctx->skb;
2324 np->get_rx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326 {
2327 int j;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002328 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 for (j=0; j<64; j++) {
2330 if ((j%16) == 0)
2331 dprintk("\n%03x:", j);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002332 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 }
2334 dprintk("\n");
2335 }
2336 /* look at what we actually got: */
2337 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002338 if (likely(flags & NV_RX_DESCRIPTORVALID)) {
2339 len = flags & LEN_MASK_V1;
2340 if (unlikely(flags & NV_RX_ERROR)) {
2341 if (flags & NV_RX_ERROR4) {
2342 len = nv_getlen(dev, skb->data, len);
2343 if (len < 0) {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002344 dev->stats.rx_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002345 dev_kfree_skb(skb);
2346 goto next_pkt;
2347 }
2348 }
2349 /* framing errors are soft errors */
2350 else if (flags & NV_RX_FRAMINGERR) {
2351 if (flags & NV_RX_SUBSTRACT1) {
2352 len--;
2353 }
2354 }
2355 /* the rest are hard errors */
2356 else {
2357 if (flags & NV_RX_MISSEDFRAME)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002358 dev->stats.rx_missed_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002359 if (flags & NV_RX_CRCERR)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002360 dev->stats.rx_crc_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002361 if (flags & NV_RX_OVERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002362 dev->stats.rx_over_errors++;
2363 dev->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002364 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002365 goto next_pkt;
2366 }
2367 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002368 } else {
2369 dev_kfree_skb(skb);
2370 goto next_pkt;
Manfred Spraul22c6d142005-04-19 21:17:09 +02002371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 } else {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002373 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2374 len = flags & LEN_MASK_V2;
2375 if (unlikely(flags & NV_RX2_ERROR)) {
2376 if (flags & NV_RX2_ERROR4) {
2377 len = nv_getlen(dev, skb->data, len);
2378 if (len < 0) {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002379 dev->stats.rx_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002380 dev_kfree_skb(skb);
2381 goto next_pkt;
2382 }
2383 }
2384 /* framing errors are soft errors */
2385 else if (flags & NV_RX2_FRAMINGERR) {
2386 if (flags & NV_RX2_SUBSTRACT1) {
2387 len--;
2388 }
2389 }
2390 /* the rest are hard errors */
2391 else {
2392 if (flags & NV_RX2_CRCERR)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002393 dev->stats.rx_crc_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002394 if (flags & NV_RX2_OVERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002395 dev->stats.rx_over_errors++;
2396 dev->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002397 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002398 goto next_pkt;
2399 }
2400 }
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002401 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2402 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002403 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002404 } else {
2405 dev_kfree_skb(skb);
2406 goto next_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 }
2408 }
2409 /* got a valid packet - forward it to the network core */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 skb_put(skb, len);
2411 skb->protocol = eth_type_trans(skb, dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002412 dprintk(KERN_DEBUG "%s: nv_rx_process: %d bytes, proto %d accepted.\n",
2413 dev->name, len, skb->protocol);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002414#ifdef CONFIG_FORCEDETH_NAPI
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002415 netif_receive_skb(skb);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002416#else
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002417 netif_rx(skb);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002418#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 dev->last_rx = jiffies;
Jeff Garzik8148ff42007-10-16 20:56:09 -04002420 dev->stats.rx_packets++;
2421 dev->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002423 if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002424 np->get_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002425 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002426 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002427
2428 rx_work++;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002429 }
2430
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002431 return rx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002432}
2433
2434static int nv_rx_process_optimized(struct net_device *dev, int limit)
2435{
2436 struct fe_priv *np = netdev_priv(dev);
2437 u32 flags;
2438 u32 vlanflags = 0;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002439 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002440 struct sk_buff *skb;
2441 int len;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002442
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002443 while((np->get_rx.ex != np->put_rx.ex) &&
2444 !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
Ingo Molnarc1b71512007-10-17 12:18:23 +02002445 (rx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002446
2447 dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: flags 0x%x.\n",
2448 dev->name, flags);
2449
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002450 /*
2451 * the packet is for us - immediately tear down the pci mapping.
2452 * TODO: check if a prefetch of the first cacheline improves
2453 * the performance.
2454 */
2455 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2456 np->get_rx_ctx->dma_len,
2457 PCI_DMA_FROMDEVICE);
2458 skb = np->get_rx_ctx->skb;
2459 np->get_rx_ctx->skb = NULL;
2460
2461 {
2462 int j;
2463 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
2464 for (j=0; j<64; j++) {
2465 if ((j%16) == 0)
2466 dprintk("\n%03x:", j);
2467 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
2468 }
2469 dprintk("\n");
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002470 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002471 /* look at what we actually got: */
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002472 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2473 len = flags & LEN_MASK_V2;
2474 if (unlikely(flags & NV_RX2_ERROR)) {
2475 if (flags & NV_RX2_ERROR4) {
2476 len = nv_getlen(dev, skb->data, len);
2477 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002478 dev_kfree_skb(skb);
2479 goto next_pkt;
2480 }
2481 }
2482 /* framing errors are soft errors */
2483 else if (flags & NV_RX2_FRAMINGERR) {
2484 if (flags & NV_RX2_SUBSTRACT1) {
2485 len--;
2486 }
2487 }
2488 /* the rest are hard errors */
2489 else {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002490 dev_kfree_skb(skb);
2491 goto next_pkt;
2492 }
2493 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002494
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002495 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2496 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002497 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002498
2499 /* got a valid packet - forward it to the network core */
2500 skb_put(skb, len);
2501 skb->protocol = eth_type_trans(skb, dev);
2502 prefetch(skb->data);
2503
2504 dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: %d bytes, proto %d accepted.\n",
2505 dev->name, len, skb->protocol);
2506
2507 if (likely(!np->vlangrp)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002508#ifdef CONFIG_FORCEDETH_NAPI
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002509 netif_receive_skb(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002510#else
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002511 netif_rx(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002512#endif
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002513 } else {
2514 vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
2515 if (vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
2516#ifdef CONFIG_FORCEDETH_NAPI
2517 vlan_hwaccel_receive_skb(skb, np->vlangrp,
2518 vlanflags & NV_RX3_VLAN_TAG_MASK);
2519#else
2520 vlan_hwaccel_rx(skb, np->vlangrp,
2521 vlanflags & NV_RX3_VLAN_TAG_MASK);
2522#endif
2523 } else {
2524#ifdef CONFIG_FORCEDETH_NAPI
2525 netif_receive_skb(skb);
2526#else
2527 netif_rx(skb);
2528#endif
2529 }
2530 }
2531
2532 dev->last_rx = jiffies;
Jeff Garzik8148ff42007-10-16 20:56:09 -04002533 dev->stats.rx_packets++;
2534 dev->stats.rx_bytes += len;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002535 } else {
2536 dev_kfree_skb(skb);
2537 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002538next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002539 if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002540 np->get_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002541 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002542 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002543
2544 rx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002546
Ingo Molnarc1b71512007-10-17 12:18:23 +02002547 return rx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548}
2549
Manfred Sprauld81c0982005-07-31 18:20:30 +02002550static void set_bufsize(struct net_device *dev)
2551{
2552 struct fe_priv *np = netdev_priv(dev);
2553
2554 if (dev->mtu <= ETH_DATA_LEN)
2555 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
2556 else
2557 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
2558}
2559
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560/*
2561 * nv_change_mtu: dev->change_mtu function
2562 * Called with dev_base_lock held for read.
2563 */
2564static int nv_change_mtu(struct net_device *dev, int new_mtu)
2565{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002566 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002567 int old_mtu;
2568
2569 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002571
2572 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002574
2575 /* return early if the buffer sizes will not change */
2576 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
2577 return 0;
2578 if (old_mtu == new_mtu)
2579 return 0;
2580
2581 /* synchronized against open : rtnl_lock() held by caller */
2582 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002583 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002584 /*
2585 * It seems that the nic preloads valid ring entries into an
2586 * internal buffer. The procedure for flushing everything is
2587 * guessed, there is probably a simpler approach.
2588 * Changing the MTU is a rare event, it shouldn't matter.
2589 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002590 nv_disable_irq(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002591 netif_tx_lock_bh(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002592 spin_lock(&np->lock);
2593 /* stop engines */
2594 nv_stop_rx(dev);
2595 nv_stop_tx(dev);
2596 nv_txrx_reset(dev);
2597 /* drain rx queue */
2598 nv_drain_rx(dev);
2599 nv_drain_tx(dev);
2600 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002601 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002602 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02002603 if (!np->in_shutdown)
2604 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2605 }
2606 /* reinit nic view of the rx queue */
2607 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002608 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002609 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02002610 base + NvRegRingSizes);
2611 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002612 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002613 pci_push(base);
2614
2615 /* restart rx engine */
2616 nv_start_rx(dev);
2617 nv_start_tx(dev);
2618 spin_unlock(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002619 netif_tx_unlock_bh(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002620 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 return 0;
2623}
2624
Manfred Spraul72b31782005-07-31 18:33:34 +02002625static void nv_copy_mac_to_hw(struct net_device *dev)
2626{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002627 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002628 u32 mac[2];
2629
2630 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
2631 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
2632 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
2633
2634 writel(mac[0], base + NvRegMacAddrA);
2635 writel(mac[1], base + NvRegMacAddrB);
2636}
2637
2638/*
2639 * nv_set_mac_address: dev->set_mac_address function
2640 * Called with rtnl_lock() held.
2641 */
2642static int nv_set_mac_address(struct net_device *dev, void *addr)
2643{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002644 struct fe_priv *np = netdev_priv(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002645 struct sockaddr *macaddr = (struct sockaddr*)addr;
2646
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002647 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02002648 return -EADDRNOTAVAIL;
2649
2650 /* synchronized against open : rtnl_lock() held by caller */
2651 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
2652
2653 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07002654 netif_tx_lock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002655 spin_lock_irq(&np->lock);
2656
2657 /* stop rx engine */
2658 nv_stop_rx(dev);
2659
2660 /* set mac address */
2661 nv_copy_mac_to_hw(dev);
2662
2663 /* restart rx engine */
2664 nv_start_rx(dev);
2665 spin_unlock_irq(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002666 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002667 } else {
2668 nv_copy_mac_to_hw(dev);
2669 }
2670 return 0;
2671}
2672
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673/*
2674 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07002675 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 */
2677static void nv_set_multicast(struct net_device *dev)
2678{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002679 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 u8 __iomem *base = get_hwbase(dev);
2681 u32 addr[2];
2682 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002683 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
2685 memset(addr, 0, sizeof(addr));
2686 memset(mask, 0, sizeof(mask));
2687
2688 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002689 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002691 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
2693 if (dev->flags & IFF_ALLMULTI || dev->mc_list) {
2694 u32 alwaysOff[2];
2695 u32 alwaysOn[2];
2696
2697 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
2698 if (dev->flags & IFF_ALLMULTI) {
2699 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
2700 } else {
2701 struct dev_mc_list *walk;
2702
2703 walk = dev->mc_list;
2704 while (walk != NULL) {
2705 u32 a, b;
Al Viro5bb7ea22007-12-09 16:06:41 +00002706 a = le32_to_cpu(*(__le32 *) walk->dmi_addr);
2707 b = le16_to_cpu(*(__le16 *) (&walk->dmi_addr[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 alwaysOn[0] &= a;
2709 alwaysOff[0] &= ~a;
2710 alwaysOn[1] &= b;
2711 alwaysOff[1] &= ~b;
2712 walk = walk->next;
2713 }
2714 }
2715 addr[0] = alwaysOn[0];
2716 addr[1] = alwaysOn[1];
2717 mask[0] = alwaysOn[0] | alwaysOff[0];
2718 mask[1] = alwaysOn[1] | alwaysOff[1];
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05002719 } else {
2720 mask[0] = NVREG_MCASTMASKA_NONE;
2721 mask[1] = NVREG_MCASTMASKB_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 }
2723 }
2724 addr[0] |= NVREG_MCASTADDRA_FORCE;
2725 pff |= NVREG_PFF_ALWAYS;
2726 spin_lock_irq(&np->lock);
2727 nv_stop_rx(dev);
2728 writel(addr[0], base + NvRegMulticastAddrA);
2729 writel(addr[1], base + NvRegMulticastAddrB);
2730 writel(mask[0], base + NvRegMulticastMaskA);
2731 writel(mask[1], base + NvRegMulticastMaskB);
2732 writel(pff, base + NvRegPacketFilterFlags);
2733 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
2734 dev->name);
2735 nv_start_rx(dev);
2736 spin_unlock_irq(&np->lock);
2737}
2738
Adrian Bunkc7985052006-06-22 12:03:29 +02002739static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002740{
2741 struct fe_priv *np = netdev_priv(dev);
2742 u8 __iomem *base = get_hwbase(dev);
2743
2744 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
2745
2746 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
2747 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
2748 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
2749 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
2750 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2751 } else {
2752 writel(pff, base + NvRegPacketFilterFlags);
2753 }
2754 }
2755 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
2756 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
2757 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
2758 writel(NVREG_TX_PAUSEFRAME_ENABLE, base + NvRegTxPauseFrame);
2759 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
2760 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2761 } else {
2762 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
2763 writel(regmisc, base + NvRegMisc1);
2764 }
2765 }
2766}
2767
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002768/**
2769 * nv_update_linkspeed: Setup the MAC according to the link partner
2770 * @dev: Network device to be configured
2771 *
2772 * The function queries the PHY and checks if there is a link partner.
2773 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
2774 * set to 10 MBit HD.
2775 *
2776 * The function returns 0 if there is no link partner and 1 if there is
2777 * a good link partner.
2778 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779static int nv_update_linkspeed(struct net_device *dev)
2780{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002781 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002783 int adv = 0;
2784 int lpa = 0;
2785 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 int newls = np->linkspeed;
2787 int newdup = np->duplex;
2788 int mii_status;
2789 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002790 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Ayaz Abdullab2976d22008-02-04 15:13:59 -05002791 u32 txrxFlags = 0;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05002792 u32 phy_exp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
2794 /* BMSR_LSTATUS is latched, read it twice:
2795 * we want the current value.
2796 */
2797 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2798 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2799
2800 if (!(mii_status & BMSR_LSTATUS)) {
2801 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
2802 dev->name);
2803 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2804 newdup = 0;
2805 retval = 0;
2806 goto set_speed;
2807 }
2808
2809 if (np->autoneg == 0) {
2810 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
2811 dev->name, np->fixed_mode);
2812 if (np->fixed_mode & LPA_100FULL) {
2813 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2814 newdup = 1;
2815 } else if (np->fixed_mode & LPA_100HALF) {
2816 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2817 newdup = 0;
2818 } else if (np->fixed_mode & LPA_10FULL) {
2819 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2820 newdup = 1;
2821 } else {
2822 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2823 newdup = 0;
2824 }
2825 retval = 1;
2826 goto set_speed;
2827 }
2828 /* check auto negotiation is complete */
2829 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
2830 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
2831 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2832 newdup = 0;
2833 retval = 0;
2834 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
2835 goto set_speed;
2836 }
2837
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002838 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2839 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
2840 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
2841 dev->name, adv, lpa);
2842
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 retval = 1;
2844 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002845 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
2846 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
2848 if ((control_1000 & ADVERTISE_1000FULL) &&
2849 (status_1000 & LPA_1000FULL)) {
2850 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
2851 dev->name);
2852 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
2853 newdup = 1;
2854 goto set_speed;
2855 }
2856 }
2857
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002859 adv_lpa = lpa & adv;
2860 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2862 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002863 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2865 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002866 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2868 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002869 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2871 newdup = 0;
2872 } else {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002873 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, adv_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2875 newdup = 0;
2876 }
2877
2878set_speed:
2879 if (np->duplex == newdup && np->linkspeed == newls)
2880 return retval;
2881
2882 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
2883 dev->name, np->linkspeed, np->duplex, newls, newdup);
2884
2885 np->duplex = newdup;
2886 np->linkspeed = newls;
2887
Ayaz Abdullab2976d22008-02-04 15:13:59 -05002888 /* The transmitter and receiver must be restarted for safe update */
2889 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
2890 txrxFlags |= NV_RESTART_TX;
2891 nv_stop_tx(dev);
2892 }
2893 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
2894 txrxFlags |= NV_RESTART_RX;
2895 nv_stop_rx(dev);
2896 }
2897
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 if (np->gigabit == PHY_GIGABIT) {
2899 phyreg = readl(base + NvRegRandomSeed);
2900 phyreg &= ~(0x3FF00);
2901 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
2902 phyreg |= NVREG_RNDSEED_FORCE3;
2903 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
2904 phyreg |= NVREG_RNDSEED_FORCE2;
2905 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
2906 phyreg |= NVREG_RNDSEED_FORCE;
2907 writel(phyreg, base + NvRegRandomSeed);
2908 }
2909
2910 phyreg = readl(base + NvRegPhyInterface);
2911 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
2912 if (np->duplex == 0)
2913 phyreg |= PHY_HALF;
2914 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
2915 phyreg |= PHY_100;
2916 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2917 phyreg |= PHY_1000;
2918 writel(phyreg, base + NvRegPhyInterface);
2919
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05002920 phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002921 if (phyreg & PHY_RGMII) {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05002922 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) {
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002923 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05002924 } else {
2925 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) {
2926 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10)
2927 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10;
2928 else
2929 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100;
2930 } else {
2931 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
2932 }
2933 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002934 } else {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05002935 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX))
2936 txreg = NVREG_TX_DEFERRAL_MII_STRETCH;
2937 else
2938 txreg = NVREG_TX_DEFERRAL_DEFAULT;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002939 }
2940 writel(txreg, base + NvRegTxDeferral);
2941
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04002942 if (np->desc_ver == DESC_VER_1) {
2943 txreg = NVREG_TX_WM_DESC1_DEFAULT;
2944 } else {
2945 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2946 txreg = NVREG_TX_WM_DESC2_3_1000;
2947 else
2948 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
2949 }
2950 writel(txreg, base + NvRegTxWatermark);
2951
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
2953 base + NvRegMisc1);
2954 pci_push(base);
2955 writel(np->linkspeed, base + NvRegLinkSpeed);
2956 pci_push(base);
2957
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002958 pause_flags = 0;
2959 /* setup pause frame */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002960 if (np->duplex != 0) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002961 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
2962 adv_pause = adv & (ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM);
2963 lpa_pause = lpa & (LPA_PAUSE_CAP| LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002964
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002965 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002966 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002967 if (lpa_pause & LPA_PAUSE_CAP) {
2968 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2969 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2970 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2971 }
2972 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002973 case ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002974 if (lpa_pause == (LPA_PAUSE_CAP| LPA_PAUSE_ASYM))
2975 {
2976 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2977 }
2978 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002979 case ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002980 if (lpa_pause & LPA_PAUSE_CAP)
2981 {
2982 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2983 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2984 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2985 }
2986 if (lpa_pause == LPA_PAUSE_ASYM)
2987 {
2988 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2989 }
2990 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002991 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002992 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002993 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002994 }
2995 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002996 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002997
Ayaz Abdullab2976d22008-02-04 15:13:59 -05002998 if (txrxFlags & NV_RESTART_TX)
2999 nv_start_tx(dev);
3000 if (txrxFlags & NV_RESTART_RX)
3001 nv_start_rx(dev);
3002
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 return retval;
3004}
3005
3006static void nv_linkchange(struct net_device *dev)
3007{
3008 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003009 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 netif_carrier_on(dev);
3011 printk(KERN_INFO "%s: link up.\n", dev->name);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003012 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 } else {
3015 if (netif_carrier_ok(dev)) {
3016 netif_carrier_off(dev);
3017 printk(KERN_INFO "%s: link down.\n", dev->name);
3018 nv_stop_rx(dev);
3019 }
3020 }
3021}
3022
3023static void nv_link_irq(struct net_device *dev)
3024{
3025 u8 __iomem *base = get_hwbase(dev);
3026 u32 miistat;
3027
3028 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05003029 writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
3031
3032 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
3033 nv_linkchange(dev);
3034 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
3035}
3036
David Howells7d12e782006-10-05 14:55:46 +01003037static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038{
3039 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003040 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 u8 __iomem *base = get_hwbase(dev);
3042 u32 events;
3043 int i;
3044
3045 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
3046
3047 for (i=0; ; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003048 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3049 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3050 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3051 } else {
3052 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3053 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3056 if (!(events & np->irqmask))
3057 break;
3058
Ayaz Abdullaa971c322005-11-11 08:30:38 -05003059 spin_lock(&np->lock);
3060 nv_tx_done(dev);
3061 spin_unlock(&np->lock);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003062
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003063#ifdef CONFIG_FORCEDETH_NAPI
3064 if (events & NVREG_IRQ_RX_ALL) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003065 netif_rx_schedule(dev, &np->napi);
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003066
3067 /* Disable furthur receive irq's */
3068 spin_lock(&np->lock);
3069 np->irqmask &= ~NVREG_IRQ_RX_ALL;
3070
3071 if (np->msi_flags & NV_MSI_X_ENABLED)
3072 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3073 else
3074 writel(np->irqmask, base + NvRegIrqMask);
3075 spin_unlock(&np->lock);
3076 }
3077#else
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003078 if (nv_rx_process(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003079 if (unlikely(nv_alloc_rx(dev))) {
3080 spin_lock(&np->lock);
3081 if (!np->in_shutdown)
3082 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3083 spin_unlock(&np->lock);
3084 }
3085 }
3086#endif
3087 if (unlikely(events & NVREG_IRQ_LINK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 spin_lock(&np->lock);
3089 nv_link_irq(dev);
3090 spin_unlock(&np->lock);
3091 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003092 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 spin_lock(&np->lock);
3094 nv_linkchange(dev);
3095 spin_unlock(&np->lock);
3096 np->link_timeout = jiffies + LINK_TIMEOUT;
3097 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003098 if (unlikely(events & (NVREG_IRQ_TX_ERR))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
3100 dev->name, events);
3101 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003102 if (unlikely(events & (NVREG_IRQ_UNKNOWN))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
3104 dev->name, events);
3105 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003106 if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) {
3107 spin_lock(&np->lock);
3108 /* disable interrupts on the nic */
3109 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3110 writel(0, base + NvRegIrqMask);
3111 else
3112 writel(np->irqmask, base + NvRegIrqMask);
3113 pci_push(base);
3114
3115 if (!np->in_shutdown) {
3116 np->nic_poll_irq = np->irqmask;
3117 np->recover_error = 1;
3118 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3119 }
3120 spin_unlock(&np->lock);
3121 break;
3122 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003123 if (unlikely(i > max_interrupt_work)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 spin_lock(&np->lock);
3125 /* disable interrupts on the nic */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003126 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3127 writel(0, base + NvRegIrqMask);
3128 else
3129 writel(np->irqmask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 pci_push(base);
3131
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003132 if (!np->in_shutdown) {
3133 np->nic_poll_irq = np->irqmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003135 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 spin_unlock(&np->lock);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003137 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 break;
3139 }
3140
3141 }
3142 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
3143
3144 return IRQ_RETVAL(i);
3145}
3146
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003147/**
3148 * All _optimized functions are used to help increase performance
3149 * (reduce CPU and increase throughput). They use descripter version 3,
3150 * compiler directives, and reduce memory accesses.
3151 */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003152static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
3153{
3154 struct net_device *dev = (struct net_device *) data;
3155 struct fe_priv *np = netdev_priv(dev);
3156 u8 __iomem *base = get_hwbase(dev);
3157 u32 events;
3158 int i;
3159
3160 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized\n", dev->name);
3161
3162 for (i=0; ; i++) {
3163 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3164 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3165 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3166 } else {
3167 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3168 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3169 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003170 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3171 if (!(events & np->irqmask))
3172 break;
3173
3174 spin_lock(&np->lock);
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003175 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003176 spin_unlock(&np->lock);
3177
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003178#ifdef CONFIG_FORCEDETH_NAPI
3179 if (events & NVREG_IRQ_RX_ALL) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003180 netif_rx_schedule(dev, &np->napi);
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003181
3182 /* Disable furthur receive irq's */
3183 spin_lock(&np->lock);
3184 np->irqmask &= ~NVREG_IRQ_RX_ALL;
3185
3186 if (np->msi_flags & NV_MSI_X_ENABLED)
3187 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3188 else
3189 writel(np->irqmask, base + NvRegIrqMask);
3190 spin_unlock(&np->lock);
3191 }
3192#else
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003193 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003194 if (unlikely(nv_alloc_rx_optimized(dev))) {
3195 spin_lock(&np->lock);
3196 if (!np->in_shutdown)
3197 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3198 spin_unlock(&np->lock);
3199 }
3200 }
3201#endif
3202 if (unlikely(events & NVREG_IRQ_LINK)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003203 spin_lock(&np->lock);
3204 nv_link_irq(dev);
3205 spin_unlock(&np->lock);
3206 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003207 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003208 spin_lock(&np->lock);
3209 nv_linkchange(dev);
3210 spin_unlock(&np->lock);
3211 np->link_timeout = jiffies + LINK_TIMEOUT;
3212 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003213 if (unlikely(events & (NVREG_IRQ_TX_ERR))) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003214 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
3215 dev->name, events);
3216 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003217 if (unlikely(events & (NVREG_IRQ_UNKNOWN))) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003218 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
3219 dev->name, events);
3220 }
3221 if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) {
3222 spin_lock(&np->lock);
3223 /* disable interrupts on the nic */
3224 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3225 writel(0, base + NvRegIrqMask);
3226 else
3227 writel(np->irqmask, base + NvRegIrqMask);
3228 pci_push(base);
3229
3230 if (!np->in_shutdown) {
3231 np->nic_poll_irq = np->irqmask;
3232 np->recover_error = 1;
3233 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3234 }
3235 spin_unlock(&np->lock);
3236 break;
3237 }
3238
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003239 if (unlikely(i > max_interrupt_work)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003240 spin_lock(&np->lock);
3241 /* disable interrupts on the nic */
3242 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3243 writel(0, base + NvRegIrqMask);
3244 else
3245 writel(np->irqmask, base + NvRegIrqMask);
3246 pci_push(base);
3247
3248 if (!np->in_shutdown) {
3249 np->nic_poll_irq = np->irqmask;
3250 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3251 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003252 spin_unlock(&np->lock);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003253 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003254 break;
3255 }
3256
3257 }
3258 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized completed\n", dev->name);
3259
3260 return IRQ_RETVAL(i);
3261}
3262
David Howells7d12e782006-10-05 14:55:46 +01003263static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003264{
3265 struct net_device *dev = (struct net_device *) data;
3266 struct fe_priv *np = netdev_priv(dev);
3267 u8 __iomem *base = get_hwbase(dev);
3268 u32 events;
3269 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003270 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003271
3272 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
3273
3274 for (i=0; ; i++) {
3275 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
3276 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003277 dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
3278 if (!(events & np->irqmask))
3279 break;
3280
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003281 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003282 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003283 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003284
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003285 if (unlikely(events & (NVREG_IRQ_TX_ERR))) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003286 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
3287 dev->name, events);
3288 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003289 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003290 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003291 /* disable interrupts on the nic */
3292 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
3293 pci_push(base);
3294
3295 if (!np->in_shutdown) {
3296 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
3297 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3298 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003299 spin_unlock_irqrestore(&np->lock, flags);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003300 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003301 break;
3302 }
3303
3304 }
3305 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
3306
3307 return IRQ_RETVAL(i);
3308}
3309
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003310#ifdef CONFIG_FORCEDETH_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003311static int nv_napi_poll(struct napi_struct *napi, int budget)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003312{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003313 struct fe_priv *np = container_of(napi, struct fe_priv, napi);
3314 struct net_device *dev = np->dev;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003315 u8 __iomem *base = get_hwbase(dev);
Francois Romieud15e9c42006-12-17 23:03:15 +01003316 unsigned long flags;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003317 int pkts, retcode;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003318
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003319 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003320 pkts = nv_rx_process(dev, budget);
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003321 retcode = nv_alloc_rx(dev);
3322 } else {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003323 pkts = nv_rx_process_optimized(dev, budget);
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003324 retcode = nv_alloc_rx_optimized(dev);
3325 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003326
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003327 if (retcode) {
Francois Romieud15e9c42006-12-17 23:03:15 +01003328 spin_lock_irqsave(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003329 if (!np->in_shutdown)
3330 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Francois Romieud15e9c42006-12-17 23:03:15 +01003331 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003332 }
3333
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003334 if (pkts < budget) {
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003335 /* re-enable receive interrupts */
Francois Romieud15e9c42006-12-17 23:03:15 +01003336 spin_lock_irqsave(&np->lock, flags);
3337
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003338 __netif_rx_complete(dev, napi);
3339
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003340 np->irqmask |= NVREG_IRQ_RX_ALL;
3341 if (np->msi_flags & NV_MSI_X_ENABLED)
3342 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3343 else
3344 writel(np->irqmask, base + NvRegIrqMask);
Francois Romieud15e9c42006-12-17 23:03:15 +01003345
3346 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003347 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003348 return pkts;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003349}
3350#endif
3351
3352#ifdef CONFIG_FORCEDETH_NAPI
David Howells7d12e782006-10-05 14:55:46 +01003353static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003354{
3355 struct net_device *dev = (struct net_device *) data;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003356 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003357 u8 __iomem *base = get_hwbase(dev);
3358 u32 events;
3359
3360 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
3361 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
3362
3363 if (events) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003364 netif_rx_schedule(dev, &np->napi);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003365 /* disable receive interrupts on the nic */
3366 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3367 pci_push(base);
3368 }
3369 return IRQ_HANDLED;
3370}
3371#else
David Howells7d12e782006-10-05 14:55:46 +01003372static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003373{
3374 struct net_device *dev = (struct net_device *) data;
3375 struct fe_priv *np = netdev_priv(dev);
3376 u8 __iomem *base = get_hwbase(dev);
3377 u32 events;
3378 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003379 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003380
3381 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name);
3382
3383 for (i=0; ; i++) {
3384 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
3385 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003386 dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
3387 if (!(events & np->irqmask))
3388 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003389
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003390 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003391 if (unlikely(nv_alloc_rx_optimized(dev))) {
3392 spin_lock_irqsave(&np->lock, flags);
3393 if (!np->in_shutdown)
3394 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3395 spin_unlock_irqrestore(&np->lock, flags);
3396 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003397 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003398
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003399 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003400 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003401 /* disable interrupts on the nic */
3402 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3403 pci_push(base);
3404
3405 if (!np->in_shutdown) {
3406 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
3407 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3408 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003409 spin_unlock_irqrestore(&np->lock, flags);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003410 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003411 break;
3412 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003413 }
3414 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
3415
3416 return IRQ_RETVAL(i);
3417}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003418#endif
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003419
David Howells7d12e782006-10-05 14:55:46 +01003420static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003421{
3422 struct net_device *dev = (struct net_device *) data;
3423 struct fe_priv *np = netdev_priv(dev);
3424 u8 __iomem *base = get_hwbase(dev);
3425 u32 events;
3426 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003427 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003428
3429 dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
3430
3431 for (i=0; ; i++) {
3432 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
3433 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003434 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3435 if (!(events & np->irqmask))
3436 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003437
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003438 /* check tx in case we reached max loop limit in tx isr */
3439 spin_lock_irqsave(&np->lock, flags);
3440 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3441 spin_unlock_irqrestore(&np->lock, flags);
3442
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003443 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003444 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003445 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003446 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003447 }
3448 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003449 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003450 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003451 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003452 np->link_timeout = jiffies + LINK_TIMEOUT;
3453 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003454 if (events & NVREG_IRQ_RECOVER_ERROR) {
3455 spin_lock_irq(&np->lock);
3456 /* disable interrupts on the nic */
3457 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3458 pci_push(base);
3459
3460 if (!np->in_shutdown) {
3461 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3462 np->recover_error = 1;
3463 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3464 }
3465 spin_unlock_irq(&np->lock);
3466 break;
3467 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003468 if (events & (NVREG_IRQ_UNKNOWN)) {
3469 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
3470 dev->name, events);
3471 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003472 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003473 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003474 /* disable interrupts on the nic */
3475 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3476 pci_push(base);
3477
3478 if (!np->in_shutdown) {
3479 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3480 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3481 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003482 spin_unlock_irqrestore(&np->lock, flags);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003483 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003484 break;
3485 }
3486
3487 }
3488 dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
3489
3490 return IRQ_RETVAL(i);
3491}
3492
David Howells7d12e782006-10-05 14:55:46 +01003493static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003494{
3495 struct net_device *dev = (struct net_device *) data;
3496 struct fe_priv *np = netdev_priv(dev);
3497 u8 __iomem *base = get_hwbase(dev);
3498 u32 events;
3499
3500 dprintk(KERN_DEBUG "%s: nv_nic_irq_test\n", dev->name);
3501
3502 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3503 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3504 writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus);
3505 } else {
3506 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3507 writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
3508 }
3509 pci_push(base);
3510 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3511 if (!(events & NVREG_IRQ_TIMER))
3512 return IRQ_RETVAL(0);
3513
3514 spin_lock(&np->lock);
3515 np->intr_test = 1;
3516 spin_unlock(&np->lock);
3517
3518 dprintk(KERN_DEBUG "%s: nv_nic_irq_test completed\n", dev->name);
3519
3520 return IRQ_RETVAL(1);
3521}
3522
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003523static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
3524{
3525 u8 __iomem *base = get_hwbase(dev);
3526 int i;
3527 u32 msixmap = 0;
3528
3529 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
3530 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
3531 * the remaining 8 interrupts.
3532 */
3533 for (i = 0; i < 8; i++) {
3534 if ((irqmask >> i) & 0x1) {
3535 msixmap |= vector << (i << 2);
3536 }
3537 }
3538 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
3539
3540 msixmap = 0;
3541 for (i = 0; i < 8; i++) {
3542 if ((irqmask >> (i + 8)) & 0x1) {
3543 msixmap |= vector << (i << 2);
3544 }
3545 }
3546 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
3547}
3548
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003549static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003550{
3551 struct fe_priv *np = get_nvpriv(dev);
3552 u8 __iomem *base = get_hwbase(dev);
3553 int ret = 1;
3554 int i;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003555 irqreturn_t (*handler)(int foo, void *data);
3556
3557 if (intr_test) {
3558 handler = nv_nic_irq_test;
3559 } else {
3560 if (np->desc_ver == DESC_VER_3)
3561 handler = nv_nic_irq_optimized;
3562 else
3563 handler = nv_nic_irq;
3564 }
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003565
3566 if (np->msi_flags & NV_MSI_X_CAPABLE) {
3567 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
3568 np->msi_x_entry[i].entry = i;
3569 }
3570 if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) {
3571 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003572 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003573 /* Request irq for rx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07003574 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, &nv_nic_irq_rx, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003575 printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret);
3576 pci_disable_msix(np->pci_dev);
3577 np->msi_flags &= ~NV_MSI_X_ENABLED;
3578 goto out_err;
3579 }
3580 /* Request irq for tx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07003581 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, &nv_nic_irq_tx, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003582 printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret);
3583 pci_disable_msix(np->pci_dev);
3584 np->msi_flags &= ~NV_MSI_X_ENABLED;
3585 goto out_free_rx;
3586 }
3587 /* Request irq for link and timer handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07003588 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector, &nv_nic_irq_other, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003589 printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret);
3590 pci_disable_msix(np->pci_dev);
3591 np->msi_flags &= ~NV_MSI_X_ENABLED;
3592 goto out_free_tx;
3593 }
3594 /* map interrupts to their respective vector */
3595 writel(0, base + NvRegMSIXMap0);
3596 writel(0, base + NvRegMSIXMap1);
3597 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
3598 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
3599 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
3600 } else {
3601 /* Request irq for all interrupts */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003602 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, handler, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003603 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
3604 pci_disable_msix(np->pci_dev);
3605 np->msi_flags &= ~NV_MSI_X_ENABLED;
3606 goto out_err;
3607 }
3608
3609 /* map interrupts to vector 0 */
3610 writel(0, base + NvRegMSIXMap0);
3611 writel(0, base + NvRegMSIXMap1);
3612 }
3613 }
3614 }
3615 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
3616 if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
3617 np->msi_flags |= NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003618 dev->irq = np->pci_dev->irq;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003619 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003620 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
3621 pci_disable_msi(np->pci_dev);
3622 np->msi_flags &= ~NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003623 dev->irq = np->pci_dev->irq;
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003624 goto out_err;
3625 }
3626
3627 /* map interrupts to vector 0 */
3628 writel(0, base + NvRegMSIMap0);
3629 writel(0, base + NvRegMSIMap1);
3630 /* enable msi vector 0 */
3631 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3632 }
3633 }
3634 if (ret != 0) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003635 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003636 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003637
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003638 }
3639
3640 return 0;
3641out_free_tx:
3642 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
3643out_free_rx:
3644 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
3645out_err:
3646 return 1;
3647}
3648
3649static void nv_free_irq(struct net_device *dev)
3650{
3651 struct fe_priv *np = get_nvpriv(dev);
3652 int i;
3653
3654 if (np->msi_flags & NV_MSI_X_ENABLED) {
3655 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
3656 free_irq(np->msi_x_entry[i].vector, dev);
3657 }
3658 pci_disable_msix(np->pci_dev);
3659 np->msi_flags &= ~NV_MSI_X_ENABLED;
3660 } else {
3661 free_irq(np->pci_dev->irq, dev);
3662 if (np->msi_flags & NV_MSI_ENABLED) {
3663 pci_disable_msi(np->pci_dev);
3664 np->msi_flags &= ~NV_MSI_ENABLED;
3665 }
3666 }
3667}
3668
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669static void nv_do_nic_poll(unsigned long data)
3670{
3671 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003672 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003674 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 /*
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003677 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 * reenable interrupts on the nic, we have to do this before calling
3679 * nv_nic_irq because that may decide to do otherwise
3680 */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003681
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003682 if (!using_multi_irqs(dev)) {
3683 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003684 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003685 else
Manfred Spraula7475902007-10-17 21:52:33 +02003686 disable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003687 mask = np->irqmask;
3688 } else {
3689 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003690 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003691 mask |= NVREG_IRQ_RX_ALL;
3692 }
3693 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003694 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003695 mask |= NVREG_IRQ_TX_ALL;
3696 }
3697 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003698 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003699 mask |= NVREG_IRQ_OTHER;
3700 }
3701 }
3702 np->nic_poll_irq = 0;
3703
Manfred Spraula7475902007-10-17 21:52:33 +02003704 /* disable_irq() contains synchronize_irq, thus no irq handler can run now */
3705
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003706 if (np->recover_error) {
3707 np->recover_error = 0;
3708 printk(KERN_INFO "forcedeth: MAC in recoverable error state\n");
3709 if (netif_running(dev)) {
3710 netif_tx_lock_bh(dev);
3711 spin_lock(&np->lock);
3712 /* stop engines */
3713 nv_stop_rx(dev);
3714 nv_stop_tx(dev);
3715 nv_txrx_reset(dev);
3716 /* drain rx queue */
3717 nv_drain_rx(dev);
3718 nv_drain_tx(dev);
3719 /* reinit driver view of the rx queue */
3720 set_bufsize(dev);
3721 if (nv_init_ring(dev)) {
3722 if (!np->in_shutdown)
3723 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3724 }
3725 /* reinit nic view of the rx queue */
3726 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3727 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3728 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3729 base + NvRegRingSizes);
3730 pci_push(base);
3731 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3732 pci_push(base);
3733
3734 /* restart rx engine */
3735 nv_start_rx(dev);
3736 nv_start_tx(dev);
3737 spin_unlock(&np->lock);
3738 netif_tx_unlock_bh(dev);
3739 }
3740 }
3741
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003742
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003743 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 pci_push(base);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003745
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003746 if (!using_multi_irqs(dev)) {
Ayaz Abdullafcc5f262007-03-23 05:49:37 -05003747 if (np->desc_ver == DESC_VER_3)
3748 nv_nic_irq_optimized(0, dev);
3749 else
3750 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003751 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003752 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003753 else
Manfred Spraula7475902007-10-17 21:52:33 +02003754 enable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003755 } else {
3756 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01003757 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003758 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003759 }
3760 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01003761 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003762 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003763 }
3764 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
David Howells7d12e782006-10-05 14:55:46 +01003765 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003766 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003767 }
3768 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769}
3770
Michal Schmidt2918c352005-05-12 19:42:06 -04003771#ifdef CONFIG_NET_POLL_CONTROLLER
3772static void nv_poll_controller(struct net_device *dev)
3773{
3774 nv_do_nic_poll((unsigned long) dev);
3775}
3776#endif
3777
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003778static void nv_do_stats_poll(unsigned long data)
3779{
3780 struct net_device *dev = (struct net_device *) data;
3781 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003782
Ayaz Abdulla57fff692007-01-23 12:27:00 -05003783 nv_get_hw_stats(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003784
3785 if (!np->in_shutdown)
3786 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
3787}
3788
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
3790{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003791 struct fe_priv *np = netdev_priv(dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04003792 strcpy(info->driver, DRV_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 strcpy(info->version, FORCEDETH_VERSION);
3794 strcpy(info->bus_info, pci_name(np->pci_dev));
3795}
3796
3797static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3798{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003799 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 wolinfo->supported = WAKE_MAGIC;
3801
3802 spin_lock_irq(&np->lock);
3803 if (np->wolenabled)
3804 wolinfo->wolopts = WAKE_MAGIC;
3805 spin_unlock_irq(&np->lock);
3806}
3807
3808static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3809{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003810 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003812 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003816 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003818 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003820 if (netif_running(dev)) {
3821 spin_lock_irq(&np->lock);
3822 writel(flags, base + NvRegWakeUpFlags);
3823 spin_unlock_irq(&np->lock);
3824 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 return 0;
3826}
3827
3828static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3829{
3830 struct fe_priv *np = netdev_priv(dev);
3831 int adv;
3832
3833 spin_lock_irq(&np->lock);
3834 ecmd->port = PORT_MII;
3835 if (!netif_running(dev)) {
3836 /* We do not track link speed / duplex setting if the
3837 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003838 if (nv_update_linkspeed(dev)) {
3839 if (!netif_carrier_ok(dev))
3840 netif_carrier_on(dev);
3841 } else {
3842 if (netif_carrier_ok(dev))
3843 netif_carrier_off(dev);
3844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003846
3847 if (netif_carrier_ok(dev)) {
3848 switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 case NVREG_LINKSPEED_10:
3850 ecmd->speed = SPEED_10;
3851 break;
3852 case NVREG_LINKSPEED_100:
3853 ecmd->speed = SPEED_100;
3854 break;
3855 case NVREG_LINKSPEED_1000:
3856 ecmd->speed = SPEED_1000;
3857 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003858 }
3859 ecmd->duplex = DUPLEX_HALF;
3860 if (np->duplex)
3861 ecmd->duplex = DUPLEX_FULL;
3862 } else {
3863 ecmd->speed = -1;
3864 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866
3867 ecmd->autoneg = np->autoneg;
3868
3869 ecmd->advertising = ADVERTISED_MII;
3870 if (np->autoneg) {
3871 ecmd->advertising |= ADVERTISED_Autoneg;
3872 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003873 if (adv & ADVERTISE_10HALF)
3874 ecmd->advertising |= ADVERTISED_10baseT_Half;
3875 if (adv & ADVERTISE_10FULL)
3876 ecmd->advertising |= ADVERTISED_10baseT_Full;
3877 if (adv & ADVERTISE_100HALF)
3878 ecmd->advertising |= ADVERTISED_100baseT_Half;
3879 if (adv & ADVERTISE_100FULL)
3880 ecmd->advertising |= ADVERTISED_100baseT_Full;
3881 if (np->gigabit == PHY_GIGABIT) {
3882 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3883 if (adv & ADVERTISE_1000FULL)
3884 ecmd->advertising |= ADVERTISED_1000baseT_Full;
3885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 ecmd->supported = (SUPPORTED_Autoneg |
3888 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
3889 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
3890 SUPPORTED_MII);
3891 if (np->gigabit == PHY_GIGABIT)
3892 ecmd->supported |= SUPPORTED_1000baseT_Full;
3893
3894 ecmd->phy_address = np->phyaddr;
3895 ecmd->transceiver = XCVR_EXTERNAL;
3896
3897 /* ignore maxtxpkt, maxrxpkt for now */
3898 spin_unlock_irq(&np->lock);
3899 return 0;
3900}
3901
3902static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3903{
3904 struct fe_priv *np = netdev_priv(dev);
3905
3906 if (ecmd->port != PORT_MII)
3907 return -EINVAL;
3908 if (ecmd->transceiver != XCVR_EXTERNAL)
3909 return -EINVAL;
3910 if (ecmd->phy_address != np->phyaddr) {
3911 /* TODO: support switching between multiple phys. Should be
3912 * trivial, but not enabled due to lack of test hardware. */
3913 return -EINVAL;
3914 }
3915 if (ecmd->autoneg == AUTONEG_ENABLE) {
3916 u32 mask;
3917
3918 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
3919 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
3920 if (np->gigabit == PHY_GIGABIT)
3921 mask |= ADVERTISED_1000baseT_Full;
3922
3923 if ((ecmd->advertising & mask) == 0)
3924 return -EINVAL;
3925
3926 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
3927 /* Note: autonegotiation disable, speed 1000 intentionally
3928 * forbidden - noone should need that. */
3929
3930 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
3931 return -EINVAL;
3932 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
3933 return -EINVAL;
3934 } else {
3935 return -EINVAL;
3936 }
3937
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003938 netif_carrier_off(dev);
3939 if (netif_running(dev)) {
3940 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003941 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003942 spin_lock(&np->lock);
3943 /* stop engines */
3944 nv_stop_rx(dev);
3945 nv_stop_tx(dev);
3946 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003947 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003948 }
3949
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 if (ecmd->autoneg == AUTONEG_ENABLE) {
3951 int adv, bmcr;
3952
3953 np->autoneg = 1;
3954
3955 /* advertise only what has been requested */
3956 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003957 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958 if (ecmd->advertising & ADVERTISED_10baseT_Half)
3959 adv |= ADVERTISE_10HALF;
3960 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003961 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 if (ecmd->advertising & ADVERTISED_100baseT_Half)
3963 adv |= ADVERTISE_100HALF;
3964 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003965 adv |= ADVERTISE_100FULL;
3966 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
3967 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3968 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3969 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3971
3972 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003973 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 adv &= ~ADVERTISE_1000FULL;
3975 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
3976 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003977 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 }
3979
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003980 if (netif_running(dev))
3981 printk(KERN_INFO "%s: link down.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003983 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
3984 bmcr |= BMCR_ANENABLE;
3985 /* reset the phy in order for settings to stick,
3986 * and cause autoneg to start */
3987 if (phy_reset(dev, bmcr)) {
3988 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3989 return -EINVAL;
3990 }
3991 } else {
3992 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3993 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 } else {
3996 int adv, bmcr;
3997
3998 np->autoneg = 0;
3999
4000 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004001 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
4003 adv |= ADVERTISE_10HALF;
4004 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004005 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
4007 adv |= ADVERTISE_100HALF;
4008 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004009 adv |= ADVERTISE_100FULL;
4010 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4011 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisments but disable tx pause */
4012 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4013 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4014 }
4015 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
4016 adv |= ADVERTISE_PAUSE_ASYM;
4017 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4020 np->fixed_mode = adv;
4021
4022 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004023 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004025 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 }
4027
4028 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004029 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
4030 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004032 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004034 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004035 /* reset the phy in order for forced mode settings to stick */
4036 if (phy_reset(dev, bmcr)) {
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004037 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4038 return -EINVAL;
4039 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004040 } else {
4041 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4042 if (netif_running(dev)) {
4043 /* Wait a bit and then reconfigure the nic. */
4044 udelay(10);
4045 nv_linkchange(dev);
4046 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 }
4048 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004049
4050 if (netif_running(dev)) {
4051 nv_start_rx(dev);
4052 nv_start_tx(dev);
4053 nv_enable_irq(dev);
4054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055
4056 return 0;
4057}
4058
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004059#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004060
4061static int nv_get_regs_len(struct net_device *dev)
4062{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004063 struct fe_priv *np = netdev_priv(dev);
4064 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004065}
4066
4067static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
4068{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004069 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004070 u8 __iomem *base = get_hwbase(dev);
4071 u32 *rbuf = buf;
4072 int i;
4073
4074 regs->version = FORCEDETH_REGS_VER;
4075 spin_lock_irq(&np->lock);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004076 for (i = 0;i <= np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004077 rbuf[i] = readl(base + i*sizeof(u32));
4078 spin_unlock_irq(&np->lock);
4079}
4080
4081static int nv_nway_reset(struct net_device *dev)
4082{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004083 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004084 int ret;
4085
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004086 if (np->autoneg) {
4087 int bmcr;
4088
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004089 netif_carrier_off(dev);
4090 if (netif_running(dev)) {
4091 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004092 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004093 spin_lock(&np->lock);
4094 /* stop engines */
4095 nv_stop_rx(dev);
4096 nv_stop_tx(dev);
4097 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004098 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004099 printk(KERN_INFO "%s: link down.\n", dev->name);
4100 }
4101
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004102 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004103 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4104 bmcr |= BMCR_ANENABLE;
4105 /* reset the phy in order for settings to stick*/
4106 if (phy_reset(dev, bmcr)) {
4107 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4108 return -EINVAL;
4109 }
4110 } else {
4111 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4112 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4113 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004114
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004115 if (netif_running(dev)) {
4116 nv_start_rx(dev);
4117 nv_start_tx(dev);
4118 nv_enable_irq(dev);
4119 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004120 ret = 0;
4121 } else {
4122 ret = -EINVAL;
4123 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004124
4125 return ret;
4126}
4127
Zachary Amsden0674d592006-06-04 02:51:38 -07004128static int nv_set_tso(struct net_device *dev, u32 value)
4129{
4130 struct fe_priv *np = netdev_priv(dev);
4131
4132 if ((np->driver_data & DEV_HAS_CHECKSUM))
4133 return ethtool_op_set_tso(dev, value);
4134 else
Ayaz Abdulla6a788142006-06-10 22:47:26 -04004135 return -EOPNOTSUPP;
Zachary Amsden0674d592006-06-04 02:51:38 -07004136}
Zachary Amsden0674d592006-06-04 02:51:38 -07004137
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004138static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4139{
4140 struct fe_priv *np = netdev_priv(dev);
4141
4142 ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4143 ring->rx_mini_max_pending = 0;
4144 ring->rx_jumbo_max_pending = 0;
4145 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4146
4147 ring->rx_pending = np->rx_ring_size;
4148 ring->rx_mini_pending = 0;
4149 ring->rx_jumbo_pending = 0;
4150 ring->tx_pending = np->tx_ring_size;
4151}
4152
4153static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4154{
4155 struct fe_priv *np = netdev_priv(dev);
4156 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004157 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004158 dma_addr_t ring_addr;
4159
4160 if (ring->rx_pending < RX_RING_MIN ||
4161 ring->tx_pending < TX_RING_MIN ||
4162 ring->rx_mini_pending != 0 ||
4163 ring->rx_jumbo_pending != 0 ||
4164 (np->desc_ver == DESC_VER_1 &&
4165 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
4166 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
4167 (np->desc_ver != DESC_VER_1 &&
4168 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
4169 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
4170 return -EINVAL;
4171 }
4172
4173 /* allocate new rings */
4174 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
4175 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4176 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4177 &ring_addr);
4178 } else {
4179 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4180 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4181 &ring_addr);
4182 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004183 rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
4184 tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
4185 if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004186 /* fall back to old rings */
4187 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004188 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004189 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4190 rxtx_ring, ring_addr);
4191 } else {
4192 if (rxtx_ring)
4193 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4194 rxtx_ring, ring_addr);
4195 }
4196 if (rx_skbuff)
4197 kfree(rx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004198 if (tx_skbuff)
4199 kfree(tx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004200 goto exit;
4201 }
4202
4203 if (netif_running(dev)) {
4204 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004205 netif_tx_lock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004206 spin_lock(&np->lock);
4207 /* stop engines */
4208 nv_stop_rx(dev);
4209 nv_stop_tx(dev);
4210 nv_txrx_reset(dev);
4211 /* drain queues */
4212 nv_drain_rx(dev);
4213 nv_drain_tx(dev);
4214 /* delete queues */
4215 free_rings(dev);
4216 }
4217
4218 /* set new values */
4219 np->rx_ring_size = ring->rx_pending;
4220 np->tx_ring_size = ring->tx_pending;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004221 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
4222 np->rx_ring.orig = (struct ring_desc*)rxtx_ring;
4223 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4224 } else {
4225 np->rx_ring.ex = (struct ring_desc_ex*)rxtx_ring;
4226 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4227 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004228 np->rx_skb = (struct nv_skb_map*)rx_skbuff;
4229 np->tx_skb = (struct nv_skb_map*)tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004230 np->ring_addr = ring_addr;
4231
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004232 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4233 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004234
4235 if (netif_running(dev)) {
4236 /* reinit driver view of the queues */
4237 set_bufsize(dev);
4238 if (nv_init_ring(dev)) {
4239 if (!np->in_shutdown)
4240 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4241 }
4242
4243 /* reinit nic view of the queues */
4244 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4245 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4246 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4247 base + NvRegRingSizes);
4248 pci_push(base);
4249 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4250 pci_push(base);
4251
4252 /* restart engines */
4253 nv_start_rx(dev);
4254 nv_start_tx(dev);
4255 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004256 netif_tx_unlock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004257 nv_enable_irq(dev);
4258 }
4259 return 0;
4260exit:
4261 return -ENOMEM;
4262}
4263
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004264static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4265{
4266 struct fe_priv *np = netdev_priv(dev);
4267
4268 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
4269 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
4270 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
4271}
4272
4273static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4274{
4275 struct fe_priv *np = netdev_priv(dev);
4276 int adv, bmcr;
4277
4278 if ((!np->autoneg && np->duplex == 0) ||
4279 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
4280 printk(KERN_INFO "%s: can not set pause settings when forced link is in half duplex.\n",
4281 dev->name);
4282 return -EINVAL;
4283 }
4284 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
4285 printk(KERN_INFO "%s: hardware does not support tx pause frames.\n", dev->name);
4286 return -EINVAL;
4287 }
4288
4289 netif_carrier_off(dev);
4290 if (netif_running(dev)) {
4291 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004292 netif_tx_lock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004293 spin_lock(&np->lock);
4294 /* stop engines */
4295 nv_stop_rx(dev);
4296 nv_stop_tx(dev);
4297 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004298 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004299 }
4300
4301 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
4302 if (pause->rx_pause)
4303 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
4304 if (pause->tx_pause)
4305 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
4306
4307 if (np->autoneg && pause->autoneg) {
4308 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
4309
4310 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4311 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
4312 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
4313 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4314 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4315 adv |= ADVERTISE_PAUSE_ASYM;
4316 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4317
4318 if (netif_running(dev))
4319 printk(KERN_INFO "%s: link down.\n", dev->name);
4320 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4321 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4322 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4323 } else {
4324 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4325 if (pause->rx_pause)
4326 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4327 if (pause->tx_pause)
4328 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4329
4330 if (!netif_running(dev))
4331 nv_update_linkspeed(dev);
4332 else
4333 nv_update_pause(dev, np->pause_flags);
4334 }
4335
4336 if (netif_running(dev)) {
4337 nv_start_rx(dev);
4338 nv_start_tx(dev);
4339 nv_enable_irq(dev);
4340 }
4341 return 0;
4342}
4343
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004344static u32 nv_get_rx_csum(struct net_device *dev)
4345{
4346 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004347 return (np->rx_csum) != 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004348}
4349
4350static int nv_set_rx_csum(struct net_device *dev, u32 data)
4351{
4352 struct fe_priv *np = netdev_priv(dev);
4353 u8 __iomem *base = get_hwbase(dev);
4354 int retcode = 0;
4355
4356 if (np->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004357 if (data) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004358 np->rx_csum = 1;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004359 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004360 } else {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004361 np->rx_csum = 0;
4362 /* vlan is dependent on rx checksum offload */
4363 if (!(np->vlanctl_bits & NVREG_VLANCONTROL_ENABLE))
4364 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004365 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004366 if (netif_running(dev)) {
4367 spin_lock_irq(&np->lock);
4368 writel(np->txrxctl_bits, base + NvRegTxRxControl);
4369 spin_unlock_irq(&np->lock);
4370 }
4371 } else {
4372 return -EINVAL;
4373 }
4374
4375 return retcode;
4376}
4377
4378static int nv_set_tx_csum(struct net_device *dev, u32 data)
4379{
4380 struct fe_priv *np = netdev_priv(dev);
4381
4382 if (np->driver_data & DEV_HAS_CHECKSUM)
4383 return ethtool_op_set_tx_hw_csum(dev, data);
4384 else
4385 return -EOPNOTSUPP;
4386}
4387
4388static int nv_set_sg(struct net_device *dev, u32 data)
4389{
4390 struct fe_priv *np = netdev_priv(dev);
4391
4392 if (np->driver_data & DEV_HAS_CHECKSUM)
4393 return ethtool_op_set_sg(dev, data);
4394 else
4395 return -EOPNOTSUPP;
4396}
4397
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004398static int nv_get_sset_count(struct net_device *dev, int sset)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004399{
4400 struct fe_priv *np = netdev_priv(dev);
4401
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004402 switch (sset) {
4403 case ETH_SS_TEST:
4404 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
4405 return NV_TEST_COUNT_EXTENDED;
4406 else
4407 return NV_TEST_COUNT_BASE;
4408 case ETH_SS_STATS:
4409 if (np->driver_data & DEV_HAS_STATISTICS_V1)
4410 return NV_DEV_STATISTICS_V1_COUNT;
4411 else if (np->driver_data & DEV_HAS_STATISTICS_V2)
4412 return NV_DEV_STATISTICS_V2_COUNT;
4413 else
4414 return 0;
4415 default:
4416 return -EOPNOTSUPP;
4417 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004418}
4419
4420static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *buffer)
4421{
4422 struct fe_priv *np = netdev_priv(dev);
4423
4424 /* update stats */
4425 nv_do_stats_poll((unsigned long)dev);
4426
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004427 memcpy(buffer, &np->estats, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004428}
4429
4430static int nv_link_test(struct net_device *dev)
4431{
4432 struct fe_priv *np = netdev_priv(dev);
4433 int mii_status;
4434
4435 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4436 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4437
4438 /* check phy link status */
4439 if (!(mii_status & BMSR_LSTATUS))
4440 return 0;
4441 else
4442 return 1;
4443}
4444
4445static int nv_register_test(struct net_device *dev)
4446{
4447 u8 __iomem *base = get_hwbase(dev);
4448 int i = 0;
4449 u32 orig_read, new_read;
4450
4451 do {
4452 orig_read = readl(base + nv_registers_test[i].reg);
4453
4454 /* xor with mask to toggle bits */
4455 orig_read ^= nv_registers_test[i].mask;
4456
4457 writel(orig_read, base + nv_registers_test[i].reg);
4458
4459 new_read = readl(base + nv_registers_test[i].reg);
4460
4461 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
4462 return 0;
4463
4464 /* restore original value */
4465 orig_read ^= nv_registers_test[i].mask;
4466 writel(orig_read, base + nv_registers_test[i].reg);
4467
4468 } while (nv_registers_test[++i].reg != 0);
4469
4470 return 1;
4471}
4472
4473static int nv_interrupt_test(struct net_device *dev)
4474{
4475 struct fe_priv *np = netdev_priv(dev);
4476 u8 __iomem *base = get_hwbase(dev);
4477 int ret = 1;
4478 int testcnt;
4479 u32 save_msi_flags, save_poll_interval = 0;
4480
4481 if (netif_running(dev)) {
4482 /* free current irq */
4483 nv_free_irq(dev);
4484 save_poll_interval = readl(base+NvRegPollingInterval);
4485 }
4486
4487 /* flag to test interrupt handler */
4488 np->intr_test = 0;
4489
4490 /* setup test irq */
4491 save_msi_flags = np->msi_flags;
4492 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
4493 np->msi_flags |= 0x001; /* setup 1 vector */
4494 if (nv_request_irq(dev, 1))
4495 return 0;
4496
4497 /* setup timer interrupt */
4498 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4499 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4500
4501 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4502
4503 /* wait for at least one interrupt */
4504 msleep(100);
4505
4506 spin_lock_irq(&np->lock);
4507
4508 /* flag should be set within ISR */
4509 testcnt = np->intr_test;
4510 if (!testcnt)
4511 ret = 2;
4512
4513 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4514 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4515 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4516 else
4517 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4518
4519 spin_unlock_irq(&np->lock);
4520
4521 nv_free_irq(dev);
4522
4523 np->msi_flags = save_msi_flags;
4524
4525 if (netif_running(dev)) {
4526 writel(save_poll_interval, base + NvRegPollingInterval);
4527 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4528 /* restore original irq */
4529 if (nv_request_irq(dev, 0))
4530 return 0;
4531 }
4532
4533 return ret;
4534}
4535
4536static int nv_loopback_test(struct net_device *dev)
4537{
4538 struct fe_priv *np = netdev_priv(dev);
4539 u8 __iomem *base = get_hwbase(dev);
4540 struct sk_buff *tx_skb, *rx_skb;
4541 dma_addr_t test_dma_addr;
4542 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004543 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004544 int len, i, pkt_len;
4545 u8 *pkt_data;
4546 u32 filter_flags = 0;
4547 u32 misc1_flags = 0;
4548 int ret = 1;
4549
4550 if (netif_running(dev)) {
4551 nv_disable_irq(dev);
4552 filter_flags = readl(base + NvRegPacketFilterFlags);
4553 misc1_flags = readl(base + NvRegMisc1);
4554 } else {
4555 nv_txrx_reset(dev);
4556 }
4557
4558 /* reinit driver view of the rx queue */
4559 set_bufsize(dev);
4560 nv_init_ring(dev);
4561
4562 /* setup hardware for loopback */
4563 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
4564 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
4565
4566 /* reinit nic view of the rx queue */
4567 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4568 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4569 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4570 base + NvRegRingSizes);
4571 pci_push(base);
4572
4573 /* restart rx engine */
4574 nv_start_rx(dev);
4575 nv_start_tx(dev);
4576
4577 /* setup packet for tx */
4578 pkt_len = ETH_DATA_LEN;
4579 tx_skb = dev_alloc_skb(pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07004580 if (!tx_skb) {
4581 printk(KERN_ERR "dev_alloc_skb() failed during loopback test"
4582 " of %s\n", dev->name);
4583 ret = 0;
4584 goto out;
4585 }
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03004586 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
4587 skb_tailroom(tx_skb),
4588 PCI_DMA_FROMDEVICE);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004589 pkt_data = skb_put(tx_skb, pkt_len);
4590 for (i = 0; i < pkt_len; i++)
4591 pkt_data[i] = (u8)(i & 0xff);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004592
4593 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004594 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
4595 np->tx_ring.orig[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004596 } else {
Al Viro5bb7ea22007-12-09 16:06:41 +00004597 np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr));
4598 np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr));
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004599 np->tx_ring.ex[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004600 }
4601 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4602 pci_push(get_hwbase(dev));
4603
4604 msleep(500);
4605
4606 /* check for rx of the packet */
4607 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004608 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004609 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
4610
4611 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004612 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004613 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
4614 }
4615
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004616 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004617 ret = 0;
4618 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004619 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004620 ret = 0;
4621 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004622 if (flags & NV_RX2_ERROR) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004623 ret = 0;
4624 }
4625 }
4626
4627 if (ret) {
4628 if (len != pkt_len) {
4629 ret = 0;
4630 dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n",
4631 dev->name, len, pkt_len);
4632 } else {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004633 rx_skb = np->rx_skb[0].skb;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004634 for (i = 0; i < pkt_len; i++) {
4635 if (rx_skb->data[i] != (u8)(i & 0xff)) {
4636 ret = 0;
4637 dprintk(KERN_DEBUG "%s: loopback pattern check failed on byte %d\n",
4638 dev->name, i);
4639 break;
4640 }
4641 }
4642 }
4643 } else {
4644 dprintk(KERN_DEBUG "%s: loopback - did not receive test packet\n", dev->name);
4645 }
4646
4647 pci_unmap_page(np->pci_dev, test_dma_addr,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07004648 (skb_end_pointer(tx_skb) - tx_skb->data),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004649 PCI_DMA_TODEVICE);
4650 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07004651 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004652 /* stop engines */
4653 nv_stop_rx(dev);
4654 nv_stop_tx(dev);
4655 nv_txrx_reset(dev);
4656 /* drain rx queue */
4657 nv_drain_rx(dev);
4658 nv_drain_tx(dev);
4659
4660 if (netif_running(dev)) {
4661 writel(misc1_flags, base + NvRegMisc1);
4662 writel(filter_flags, base + NvRegPacketFilterFlags);
4663 nv_enable_irq(dev);
4664 }
4665
4666 return ret;
4667}
4668
4669static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
4670{
4671 struct fe_priv *np = netdev_priv(dev);
4672 u8 __iomem *base = get_hwbase(dev);
4673 int result;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004674 memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004675
4676 if (!nv_link_test(dev)) {
4677 test->flags |= ETH_TEST_FL_FAILED;
4678 buffer[0] = 1;
4679 }
4680
4681 if (test->flags & ETH_TEST_FL_OFFLINE) {
4682 if (netif_running(dev)) {
4683 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004684#ifdef CONFIG_FORCEDETH_NAPI
4685 napi_disable(&np->napi);
4686#endif
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004687 netif_tx_lock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004688 spin_lock_irq(&np->lock);
4689 nv_disable_hw_interrupts(dev, np->irqmask);
4690 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
4691 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4692 } else {
4693 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4694 }
4695 /* stop engines */
4696 nv_stop_rx(dev);
4697 nv_stop_tx(dev);
4698 nv_txrx_reset(dev);
4699 /* drain rx queue */
4700 nv_drain_rx(dev);
4701 nv_drain_tx(dev);
4702 spin_unlock_irq(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004703 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004704 }
4705
4706 if (!nv_register_test(dev)) {
4707 test->flags |= ETH_TEST_FL_FAILED;
4708 buffer[1] = 1;
4709 }
4710
4711 result = nv_interrupt_test(dev);
4712 if (result != 1) {
4713 test->flags |= ETH_TEST_FL_FAILED;
4714 buffer[2] = 1;
4715 }
4716 if (result == 0) {
4717 /* bail out */
4718 return;
4719 }
4720
4721 if (!nv_loopback_test(dev)) {
4722 test->flags |= ETH_TEST_FL_FAILED;
4723 buffer[3] = 1;
4724 }
4725
4726 if (netif_running(dev)) {
4727 /* reinit driver view of the rx queue */
4728 set_bufsize(dev);
4729 if (nv_init_ring(dev)) {
4730 if (!np->in_shutdown)
4731 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4732 }
4733 /* reinit nic view of the rx queue */
4734 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4735 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4736 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4737 base + NvRegRingSizes);
4738 pci_push(base);
4739 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4740 pci_push(base);
4741 /* restart rx engine */
4742 nv_start_rx(dev);
4743 nv_start_tx(dev);
4744 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004745#ifdef CONFIG_FORCEDETH_NAPI
4746 napi_enable(&np->napi);
4747#endif
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004748 nv_enable_hw_interrupts(dev, np->irqmask);
4749 }
4750 }
4751}
4752
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004753static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
4754{
4755 switch (stringset) {
4756 case ETH_SS_STATS:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004757 memcpy(buffer, &nv_estats_str, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(struct nv_ethtool_str));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004758 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004759 case ETH_SS_TEST:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004760 memcpy(buffer, &nv_etests_str, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(struct nv_ethtool_str));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004761 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004762 }
4763}
4764
Jeff Garzik7282d492006-09-13 14:30:00 -04004765static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 .get_drvinfo = nv_get_drvinfo,
4767 .get_link = ethtool_op_get_link,
4768 .get_wol = nv_get_wol,
4769 .set_wol = nv_set_wol,
4770 .get_settings = nv_get_settings,
4771 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004772 .get_regs_len = nv_get_regs_len,
4773 .get_regs = nv_get_regs,
4774 .nway_reset = nv_nway_reset,
Ayaz Abdulla6a788142006-06-10 22:47:26 -04004775 .set_tso = nv_set_tso,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004776 .get_ringparam = nv_get_ringparam,
4777 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004778 .get_pauseparam = nv_get_pauseparam,
4779 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004780 .get_rx_csum = nv_get_rx_csum,
4781 .set_rx_csum = nv_set_rx_csum,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004782 .set_tx_csum = nv_set_tx_csum,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004783 .set_sg = nv_set_sg,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004784 .get_strings = nv_get_strings,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004785 .get_ethtool_stats = nv_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004786 .get_sset_count = nv_get_sset_count,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004787 .self_test = nv_self_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788};
4789
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004790static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
4791{
4792 struct fe_priv *np = get_nvpriv(dev);
4793
4794 spin_lock_irq(&np->lock);
4795
4796 /* save vlan group */
4797 np->vlangrp = grp;
4798
4799 if (grp) {
4800 /* enable vlan on MAC */
4801 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS;
4802 } else {
4803 /* disable vlan on MAC */
4804 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4805 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4806 }
4807
4808 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4809
4810 spin_unlock_irq(&np->lock);
Stephen Hemminger25805dc2007-06-01 09:44:01 -07004811}
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004812
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004813/* The mgmt unit and driver use a semaphore to access the phy during init */
4814static int nv_mgmt_acquire_sema(struct net_device *dev)
4815{
4816 u8 __iomem *base = get_hwbase(dev);
4817 int i;
4818 u32 tx_ctrl, mgmt_sema;
4819
4820 for (i = 0; i < 10; i++) {
4821 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
4822 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
4823 break;
4824 msleep(500);
4825 }
4826
4827 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
4828 return 0;
4829
4830 for (i = 0; i < 2; i++) {
4831 tx_ctrl = readl(base + NvRegTransmitterControl);
4832 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
4833 writel(tx_ctrl, base + NvRegTransmitterControl);
4834
4835 /* verify that semaphore was acquired */
4836 tx_ctrl = readl(base + NvRegTransmitterControl);
4837 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
4838 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE))
4839 return 1;
4840 else
4841 udelay(50);
4842 }
4843
4844 return 0;
4845}
4846
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847static int nv_open(struct net_device *dev)
4848{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004849 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004851 int ret = 1;
4852 int oom, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853
4854 dprintk(KERN_DEBUG "nv_open: begin\n");
4855
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004856 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004857 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4858 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4860 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05004861 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
4862 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 writel(0, base + NvRegPacketFilterFlags);
4864
4865 writel(0, base + NvRegTransmitterControl);
4866 writel(0, base + NvRegReceiverControl);
4867
4868 writel(0, base + NvRegAdapterControl);
4869
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004870 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
4871 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
4872
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004873 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02004874 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875 oom = nv_init_ring(dev);
4876
4877 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004878 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 nv_txrx_reset(dev);
4880 writel(0, base + NvRegUnknownSetupReg6);
4881
4882 np->in_shutdown = 0;
4883
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004884 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05004885 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004886 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 base + NvRegRingSizes);
4888
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04004890 if (np->desc_ver == DESC_VER_1)
4891 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
4892 else
4893 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004894 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004895 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004897 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
4899 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
4900 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
4901
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004902 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05004904 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
4907 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
4908 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02004909 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910
4911 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
4912 get_random_bytes(&i, sizeof(i));
4913 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed);
Ayaz Abdulla9744e212006-07-06 16:45:58 -04004914 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
4915 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004916 if (poll_interval == -1) {
4917 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
4918 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
4919 else
4920 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4921 }
4922 else
4923 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4925 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
4926 base + NvRegAdapterControl);
4927 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004928 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004929 if (np->wolenabled)
4930 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931
4932 i = readl(base + NvRegPowerState);
4933 if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0)
4934 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
4935
4936 pci_push(base);
4937 udelay(10);
4938 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
4939
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004940 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 pci_push(base);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05004942 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4944 pci_push(base);
4945
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004946 if (nv_request_irq(dev, 0)) {
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004947 goto out_drain;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949
4950 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004951 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952
4953 spin_lock_irq(&np->lock);
4954 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4955 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05004956 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
4957 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
4959 /* One manual link speed update: Interrupts are enabled, future link
4960 * speed changes cause interrupts and are handled by nv_link_irq().
4961 */
4962 {
4963 u32 miistat;
4964 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05004965 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
4967 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02004968 /* set linkspeed to invalid value, thus force nv_update_linkspeed
4969 * to init hw */
4970 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 ret = nv_update_linkspeed(dev);
4972 nv_start_rx(dev);
4973 nv_start_tx(dev);
4974 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004975#ifdef CONFIG_FORCEDETH_NAPI
4976 napi_enable(&np->napi);
4977#endif
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004978
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 if (ret) {
4980 netif_carrier_on(dev);
4981 } else {
Ed Swierkf7ab6972007-09-28 22:42:13 -07004982 printk(KERN_INFO "%s: no link during initialization.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983 netif_carrier_off(dev);
4984 }
4985 if (oom)
4986 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004987
4988 /* start statistics timer */
Ayaz Abdulla57fff692007-01-23 12:27:00 -05004989 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2))
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004990 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
4991
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 spin_unlock_irq(&np->lock);
4993
4994 return 0;
4995out_drain:
4996 drain_ring(dev);
4997 return ret;
4998}
4999
5000static int nv_close(struct net_device *dev)
5001{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005002 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 u8 __iomem *base;
5004
5005 spin_lock_irq(&np->lock);
5006 np->in_shutdown = 1;
5007 spin_unlock_irq(&np->lock);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005008#ifdef CONFIG_FORCEDETH_NAPI
5009 napi_disable(&np->napi);
5010#endif
Manfred Spraula7475902007-10-17 21:52:33 +02005011 synchronize_irq(np->pci_dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012
5013 del_timer_sync(&np->oom_kick);
5014 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005015 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016
5017 netif_stop_queue(dev);
5018 spin_lock_irq(&np->lock);
5019 nv_stop_tx(dev);
5020 nv_stop_rx(dev);
5021 nv_txrx_reset(dev);
5022
5023 /* disable interrupts on the nic or we will lock up */
5024 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005025 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026 pci_push(base);
5027 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
5028
5029 spin_unlock_irq(&np->lock);
5030
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005031 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032
5033 drain_ring(dev);
5034
Tim Mann2cc49a52007-06-14 13:16:38 -07005035 if (np->wolenabled) {
5036 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037 nv_start_rx(dev);
Tim Mann2cc49a52007-06-14 13:16:38 -07005038 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039
5040 /* FIXME: power down nic */
5041
5042 return 0;
5043}
5044
5045static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
5046{
5047 struct net_device *dev;
5048 struct fe_priv *np;
5049 unsigned long addr;
5050 u8 __iomem *base;
5051 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005052 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005053 u32 phystate_orig = 0, phystate;
5054 int phyinitialized = 0;
Joe Perches0795af52007-10-03 17:59:30 -07005055 DECLARE_MAC_BUF(mac);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005056 static int printed_version;
5057
5058 if (!printed_version++)
5059 printk(KERN_INFO "%s: Reverse Engineered nForce ethernet"
5060 " driver. Version %s.\n", DRV_NAME, FORCEDETH_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061
5062 dev = alloc_etherdev(sizeof(struct fe_priv));
5063 err = -ENOMEM;
5064 if (!dev)
5065 goto out;
5066
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005067 np = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005068 np->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 np->pci_dev = pci_dev;
5070 spin_lock_init(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 SET_NETDEV_DEV(dev, &pci_dev->dev);
5072
5073 init_timer(&np->oom_kick);
5074 np->oom_kick.data = (unsigned long) dev;
5075 np->oom_kick.function = &nv_do_rx_refill; /* timer handler */
5076 init_timer(&np->nic_poll);
5077 np->nic_poll.data = (unsigned long) dev;
5078 np->nic_poll.function = &nv_do_nic_poll; /* timer handler */
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005079 init_timer(&np->stats_poll);
5080 np->stats_poll.data = (unsigned long) dev;
5081 np->stats_poll.function = &nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082
5083 err = pci_enable_device(pci_dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005084 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086
5087 pci_set_master(pci_dev);
5088
5089 err = pci_request_regions(pci_dev, DRV_NAME);
5090 if (err < 0)
5091 goto out_disable;
5092
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005093 if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V2))
5094 np->register_size = NV_PCI_REGSZ_VER3;
5095 else if (id->driver_data & DEV_HAS_STATISTICS_V1)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005096 np->register_size = NV_PCI_REGSZ_VER2;
5097 else
5098 np->register_size = NV_PCI_REGSZ_VER1;
5099
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100 err = -EINVAL;
5101 addr = 0;
5102 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
5103 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
5104 pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i),
5105 pci_resource_len(pci_dev, i),
5106 pci_resource_flags(pci_dev, i));
5107 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005108 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 addr = pci_resource_start(pci_dev, i);
5110 break;
5111 }
5112 }
5113 if (i == DEVICE_COUNT_RESOURCE) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005114 dev_printk(KERN_INFO, &pci_dev->dev,
5115 "Couldn't find register window\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 goto out_relreg;
5117 }
5118
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005119 /* copy of driver data */
5120 np->driver_data = id->driver_data;
5121
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02005123 if (id->driver_data & DEV_HAS_HIGH_DMA) {
5124 /* packet format 3: supports 40-bit addressing */
5125 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005126 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005127 if (dma_64bit) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005128 if (pci_set_dma_mask(pci_dev, DMA_39BIT_MASK))
5129 dev_printk(KERN_INFO, &pci_dev->dev,
5130 "64-bit DMA failed, using 32-bit addressing\n");
5131 else
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005132 dev->features |= NETIF_F_HIGHDMA;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005133 if (pci_set_consistent_dma_mask(pci_dev, DMA_39BIT_MASK)) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005134 dev_printk(KERN_INFO, &pci_dev->dev,
5135 "64-bit DMA (consistent) failed, using 32-bit ring buffers\n");
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005136 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005137 }
Manfred Spraulee733622005-07-31 18:32:26 +02005138 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
5139 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005141 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02005142 } else {
5143 /* original packet format */
5144 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005145 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02005146 }
Manfred Spraulee733622005-07-31 18:32:26 +02005147
5148 np->pkt_limit = NV_PKTLIMIT_1;
5149 if (id->driver_data & DEV_HAS_LARGEDESC)
5150 np->pkt_limit = NV_PKTLIMIT_2;
5151
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005152 if (id->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04005153 np->rx_csum = 1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005154 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005155 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
Ayaz Abdullafa454592006-01-05 22:45:45 -08005156 dev->features |= NETIF_F_TSO;
Ayaz Abdulla21828162007-01-23 12:27:21 -05005157 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005158
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005159 np->vlanctl_bits = 0;
5160 if (id->driver_data & DEV_HAS_VLAN) {
5161 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
5162 dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
5163 dev->vlan_rx_register = nv_vlan_rx_register;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005164 }
5165
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005166 np->msi_flags = 0;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005167 if ((id->driver_data & DEV_HAS_MSI) && msi) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005168 np->msi_flags |= NV_MSI_CAPABLE;
5169 }
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005170 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005171 np->msi_flags |= NV_MSI_X_CAPABLE;
5172 }
5173
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005174 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005175 if (id->driver_data & DEV_HAS_PAUSEFRAME_TX) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005176 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005177 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005178
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005179
Linus Torvalds1da177e2005-04-16 15:20:36 -07005180 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005181 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 if (!np->base)
5183 goto out_relreg;
5184 dev->base_addr = (unsigned long)np->base;
Manfred Spraulee733622005-07-31 18:32:26 +02005185
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186 dev->irq = pci_dev->irq;
Manfred Spraulee733622005-07-31 18:32:26 +02005187
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005188 np->rx_ring_size = RX_RING_DEFAULT;
5189 np->tx_ring_size = TX_RING_DEFAULT;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005190
Manfred Spraulee733622005-07-31 18:32:26 +02005191 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
5192 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005193 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005194 &np->ring_addr);
5195 if (!np->rx_ring.orig)
5196 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005197 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005198 } else {
5199 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005200 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005201 &np->ring_addr);
5202 if (!np->rx_ring.ex)
5203 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005204 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005205 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005206 np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
5207 np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005208 if (!np->rx_skb || !np->tx_skb)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005209 goto out_freering;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210
5211 dev->open = nv_open;
5212 dev->stop = nv_close;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05005213 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
5214 dev->hard_start_xmit = nv_start_xmit;
5215 else
5216 dev->hard_start_xmit = nv_start_xmit_optimized;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217 dev->get_stats = nv_get_stats;
5218 dev->change_mtu = nv_change_mtu;
Manfred Spraul72b31782005-07-31 18:33:34 +02005219 dev->set_mac_address = nv_set_mac_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 dev->set_multicast_list = nv_set_multicast;
Michal Schmidt2918c352005-05-12 19:42:06 -04005221#ifdef CONFIG_NET_POLL_CONTROLLER
5222 dev->poll_controller = nv_poll_controller;
5223#endif
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005224#ifdef CONFIG_FORCEDETH_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005225 netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005226#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 SET_ETHTOOL_OPS(dev, &ops);
5228 dev->tx_timeout = nv_tx_timeout;
5229 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
5230
5231 pci_set_drvdata(pci_dev, dev);
5232
5233 /* read the mac address */
5234 base = get_hwbase(dev);
5235 np->orig_mac[0] = readl(base + NvRegMacAddrA);
5236 np->orig_mac[1] = readl(base + NvRegMacAddrB);
5237
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005238 /* check the workaround bit for correct mac address order */
5239 txreg = readl(base + NvRegTransmitPoll);
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005240 if ((txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) ||
5241 (id->driver_data & DEV_HAS_CORRECT_MACADDR)) {
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005242 /* mac address is already in correct order */
5243 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5244 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5245 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5246 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5247 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5248 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5249 } else {
5250 /* need to reverse mac address to correct order */
5251 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5252 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5253 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5254 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5255 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5256 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005257 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
5258 }
John W. Linvillec704b852005-09-12 10:48:56 -04005259 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005260
John W. Linvillec704b852005-09-12 10:48:56 -04005261 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 /*
5263 * Bad mac address. At least one bios sets the mac address
5264 * to 01:23:45:67:89:ab
5265 */
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005266 dev_printk(KERN_ERR, &pci_dev->dev,
5267 "Invalid Mac address detected: %s\n",
5268 print_mac(mac, dev->dev_addr));
5269 dev_printk(KERN_ERR, &pci_dev->dev,
5270 "Please complain to your hardware vendor. Switching to a random MAC.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 dev->dev_addr[0] = 0x00;
5272 dev->dev_addr[1] = 0x00;
5273 dev->dev_addr[2] = 0x6c;
5274 get_random_bytes(&dev->dev_addr[3], 3);
5275 }
5276
Joe Perches0795af52007-10-03 17:59:30 -07005277 dprintk(KERN_DEBUG "%s: MAC Address %s\n",
5278 pci_name(pci_dev), print_mac(mac, dev->dev_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005280 /* set mac address */
5281 nv_copy_mac_to_hw(dev);
5282
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283 /* disable WOL */
5284 writel(0, base + NvRegWakeUpFlags);
5285 np->wolenabled = 0;
5286
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005287 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005288
5289 /* take phy and nic out of low power mode */
5290 powerstate = readl(base + NvRegPowerState2);
5291 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
5292 if ((id->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 ||
5293 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_13) &&
Auke Kok44c10132007-06-08 15:46:36 -07005294 pci_dev->revision >= 0xA3)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005295 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
5296 writel(powerstate, base + NvRegPowerState2);
5297 }
5298
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005300 np->tx_flags = NV_TX_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301 } else {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005302 np->tx_flags = NV_TX2_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005304 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005305 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005306 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5307 np->msi_flags |= 0x0003;
5308 } else {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005309 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005310 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5311 np->msi_flags |= 0x0001;
5312 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005313
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314 if (id->driver_data & DEV_NEED_TIMERIRQ)
5315 np->irqmask |= NVREG_IRQ_TIMER;
5316 if (id->driver_data & DEV_NEED_LINKTIMER) {
5317 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
5318 np->need_linktimer = 1;
5319 np->link_timeout = jiffies + LINK_TIMEOUT;
5320 } else {
5321 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
5322 np->need_linktimer = 0;
5323 }
5324
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005325 /* clear phy state and temporarily halt phy interrupts */
5326 writel(0, base + NvRegMIIMask);
5327 phystate = readl(base + NvRegAdapterControl);
5328 if (phystate & NVREG_ADAPTCTL_RUNNING) {
5329 phystate_orig = 1;
5330 phystate &= ~NVREG_ADAPTCTL_RUNNING;
5331 writel(phystate, base + NvRegAdapterControl);
5332 }
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005333 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005334
5335 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005336 /* management unit running on the mac? */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005337 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) {
5338 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST;
5339 dprintk(KERN_INFO "%s: mgmt unit is running. mac in use %x.\n", pci_name(pci_dev), np->mac_in_use);
Ayaz Abdulla9e555932007-11-21 15:02:58 -08005340 if (nv_mgmt_acquire_sema(dev)) {
5341 /* management unit setup the phy already? */
5342 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5343 NVREG_XMITCTL_SYNC_PHY_INIT) {
5344 /* phy is inited by mgmt unit */
5345 phyinitialized = 1;
5346 dprintk(KERN_INFO "%s: Phy already initialized by mgmt unit.\n", pci_name(pci_dev));
5347 } else {
5348 /* we need to init the phy */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005349 }
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005350 }
5351 }
5352 }
5353
Linus Torvalds1da177e2005-04-16 15:20:36 -07005354 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005355 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005357 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358
5359 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005360 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 spin_unlock_irq(&np->lock);
5362 if (id1 < 0 || id1 == 0xffff)
5363 continue;
5364 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005365 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005366 spin_unlock_irq(&np->lock);
5367 if (id2 < 0 || id2 == 0xffff)
5368 continue;
5369
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04005370 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005371 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
5372 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
5373 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005374 pci_name(pci_dev), id1, id2, phyaddr);
5375 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376 np->phy_oui = id1 | id2;
5377 break;
5378 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005379 if (i == 33) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005380 dev_printk(KERN_INFO, &pci_dev->dev,
5381 "open: Could not find a valid PHY.\n");
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005382 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005384
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005385 if (!phyinitialized) {
5386 /* reset it */
5387 phy_init(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005388 } else {
5389 /* see if it is a gigabit phy */
5390 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
5391 if (mii_status & PHY_GIGABIT) {
5392 np->gigabit = PHY_GIGABIT;
5393 }
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005395
5396 /* set default link speed settings */
5397 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
5398 np->duplex = 0;
5399 np->autoneg = 1;
5400
5401 err = register_netdev(dev);
5402 if (err) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005403 dev_printk(KERN_INFO, &pci_dev->dev,
5404 "unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005405 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 }
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005407
5408 dev_printk(KERN_INFO, &pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, "
5409 "addr %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
5410 dev->name,
5411 np->phy_oui,
5412 np->phyaddr,
5413 dev->dev_addr[0],
5414 dev->dev_addr[1],
5415 dev->dev_addr[2],
5416 dev->dev_addr[3],
5417 dev->dev_addr[4],
5418 dev->dev_addr[5]);
5419
5420 dev_printk(KERN_INFO, &pci_dev->dev, "%s%s%s%s%s%s%s%s%s%sdesc-v%u\n",
5421 dev->features & NETIF_F_HIGHDMA ? "highdma " : "",
5422 dev->features & (NETIF_F_HW_CSUM | NETIF_F_SG) ?
5423 "csum " : "",
5424 dev->features & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX) ?
5425 "vlan " : "",
5426 id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "",
5427 id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "",
5428 id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "",
5429 np->gigabit == PHY_GIGABIT ? "gbit " : "",
5430 np->need_linktimer ? "lnktim " : "",
5431 np->msi_flags & NV_MSI_CAPABLE ? "msi " : "",
5432 np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "",
5433 np->desc_ver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005434
5435 return 0;
5436
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005437out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005438 if (phystate_orig)
5439 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005441out_freering:
5442 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005443out_unmap:
5444 iounmap(get_hwbase(dev));
5445out_relreg:
5446 pci_release_regions(pci_dev);
5447out_disable:
5448 pci_disable_device(pci_dev);
5449out_free:
5450 free_netdev(dev);
5451out:
5452 return err;
5453}
5454
5455static void __devexit nv_remove(struct pci_dev *pci_dev)
5456{
5457 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005458 struct fe_priv *np = netdev_priv(dev);
5459 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460
5461 unregister_netdev(dev);
5462
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005463 /* special op: write back the misordered MAC address - otherwise
5464 * the next nv_probe would see a wrong address.
5465 */
5466 writel(np->orig_mac[0], base + NvRegMacAddrA);
5467 writel(np->orig_mac[1], base + NvRegMacAddrB);
Björn Steinbrink2e3884b2008-01-07 23:22:53 -08005468 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
5469 base + NvRegTransmitPoll);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005470
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005472 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005473 iounmap(get_hwbase(dev));
5474 pci_release_regions(pci_dev);
5475 pci_disable_device(pci_dev);
5476 free_netdev(dev);
5477 pci_set_drvdata(pci_dev, NULL);
5478}
5479
Francois Romieua1893172006-10-10 14:33:27 -07005480#ifdef CONFIG_PM
5481static int nv_suspend(struct pci_dev *pdev, pm_message_t state)
5482{
5483 struct net_device *dev = pci_get_drvdata(pdev);
5484 struct fe_priv *np = netdev_priv(dev);
5485
5486 if (!netif_running(dev))
5487 goto out;
5488
5489 netif_device_detach(dev);
5490
5491 // Gross.
5492 nv_close(dev);
5493
5494 pci_save_state(pdev);
5495 pci_enable_wake(pdev, pci_choose_state(pdev, state), np->wolenabled);
5496 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5497out:
5498 return 0;
5499}
5500
5501static int nv_resume(struct pci_dev *pdev)
5502{
5503 struct net_device *dev = pci_get_drvdata(pdev);
5504 int rc = 0;
5505
5506 if (!netif_running(dev))
5507 goto out;
5508
5509 netif_device_attach(dev);
5510
5511 pci_set_power_state(pdev, PCI_D0);
5512 pci_restore_state(pdev);
5513 pci_enable_wake(pdev, PCI_D0, 0);
5514
5515 rc = nv_open(dev);
5516out:
5517 return rc;
5518}
5519#else
5520#define nv_suspend NULL
5521#define nv_resume NULL
5522#endif /* CONFIG_PM */
5523
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524static struct pci_device_id pci_tbl[] = {
5525 { /* nForce Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005526 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005527 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005528 },
5529 { /* nForce2 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005530 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005531 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 },
5533 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005534 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005535 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536 },
5537 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005538 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005539 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540 },
5541 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005542 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005543 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005544 },
5545 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005546 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005547 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005548 },
5549 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005550 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005551 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005552 },
5553 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005554 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005555 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005556 },
5557 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005558 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005559 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005560 },
5561 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005562 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005563 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005564 },
5565 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005566 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005567 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005568 },
5569 { /* MCP51 Ethernet Controller */
5570 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005571 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005572 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02005573 { /* MCP51 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005574 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005575 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1,
Manfred Spraul9992d4a2005-06-05 17:36:11 +02005576 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02005577 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005578 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005579 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02005580 },
5581 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005582 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005583 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02005584 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005585 { /* MCP61 Ethernet Controller */
5586 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_16),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005587 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005588 },
5589 { /* MCP61 Ethernet Controller */
5590 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_17),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005591 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005592 },
5593 { /* MCP61 Ethernet Controller */
5594 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_18),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005595 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005596 },
5597 { /* MCP61 Ethernet Controller */
5598 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_19),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005599 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005600 },
5601 { /* MCP65 Ethernet Controller */
5602 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005603 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005604 },
5605 { /* MCP65 Ethernet Controller */
5606 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005607 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005608 },
5609 { /* MCP65 Ethernet Controller */
5610 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005611 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005612 },
5613 { /* MCP65 Ethernet Controller */
5614 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005615 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005616 },
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005617 { /* MCP67 Ethernet Controller */
5618 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005619 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005620 },
5621 { /* MCP67 Ethernet Controller */
5622 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_25),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005623 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005624 },
5625 { /* MCP67 Ethernet Controller */
5626 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_26),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005627 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005628 },
5629 { /* MCP67 Ethernet Controller */
5630 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27),
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005631 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005632 },
Ayaz Abdulla13986612007-07-22 20:43:26 -04005633 { /* MCP73 Ethernet Controller */
5634 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_28),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005635 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04005636 },
5637 { /* MCP73 Ethernet Controller */
5638 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_29),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005639 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04005640 },
5641 { /* MCP73 Ethernet Controller */
5642 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_30),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005643 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04005644 },
5645 { /* MCP73 Ethernet Controller */
5646 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_31),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005647 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04005648 },
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005649 { /* MCP77 Ethernet Controller */
5650 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_32),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005651 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005652 },
5653 { /* MCP77 Ethernet Controller */
5654 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_33),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005655 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005656 },
5657 { /* MCP77 Ethernet Controller */
5658 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_34),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005659 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005660 },
5661 { /* MCP77 Ethernet Controller */
5662 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_35),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005663 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005664 },
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005665 { /* MCP79 Ethernet Controller */
5666 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_36),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005667 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005668 },
5669 { /* MCP79 Ethernet Controller */
5670 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_37),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005671 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005672 },
5673 { /* MCP79 Ethernet Controller */
5674 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_38),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005675 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005676 },
5677 { /* MCP79 Ethernet Controller */
5678 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_39),
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05005679 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005680 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005681 {0,},
5682};
5683
5684static struct pci_driver driver = {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005685 .name = DRV_NAME,
5686 .id_table = pci_tbl,
5687 .probe = nv_probe,
5688 .remove = __devexit_p(nv_remove),
5689 .suspend = nv_suspend,
5690 .resume = nv_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691};
5692
Linus Torvalds1da177e2005-04-16 15:20:36 -07005693static int __init init_nic(void)
5694{
Jeff Garzik29917622006-08-19 17:48:59 -04005695 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005696}
5697
5698static void __exit exit_nic(void)
5699{
5700 pci_unregister_driver(&driver);
5701}
5702
5703module_param(max_interrupt_work, int, 0);
5704MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005705module_param(optimization_mode, int, 0);
5706MODULE_PARM_DESC(optimization_mode, "In throughput mode (0), every tx & rx packet will generate an interrupt. In CPU mode (1), interrupts are controlled by a timer.");
5707module_param(poll_interval, int, 0);
5708MODULE_PARM_DESC(poll_interval, "Interval determines how frequent timer interrupt is generated by [(time_in_micro_secs * 100) / (2^10)]. Min is 0 and Max is 65535.");
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005709module_param(msi, int, 0);
5710MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
5711module_param(msix, int, 0);
5712MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
5713module_param(dma_64bit, int, 0);
5714MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005715
5716MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
5717MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
5718MODULE_LICENSE("GPL");
5719
5720MODULE_DEVICE_TABLE(pci, pci_tbl);
5721
5722module_init(init_nic);
5723module_exit(exit_nic);