blob: 980c2c229a71d5fa9a0b59c5921ad61aaf627f16 [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
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -0500169#define DEV_NEED_TIMERIRQ 0x00001 /* set the timer irq flag in the irq mask */
170#define DEV_NEED_LINKTIMER 0x00002 /* poll link settings. Relies on the timer irq */
171#define DEV_HAS_LARGEDESC 0x00004 /* device supports jumbo frames and needs packet format 2 */
172#define DEV_HAS_HIGH_DMA 0x00008 /* device supports 64bit dma */
173#define DEV_HAS_CHECKSUM 0x00010 /* device supports tx and rx checksum offloads */
174#define DEV_HAS_VLAN 0x00020 /* device supports vlan tagging and striping */
175#define DEV_HAS_MSI 0x00040 /* device supports MSI */
176#define DEV_HAS_MSI_X 0x00080 /* device supports MSI-X */
177#define DEV_HAS_POWER_CNTRL 0x00100 /* device supports power savings */
178#define DEV_HAS_STATISTICS_V1 0x00200 /* device supports hw statistics version 1 */
179#define DEV_HAS_STATISTICS_V2 0x00400 /* device supports hw statistics version 2 */
180#define DEV_HAS_TEST_EXTENDED 0x00800 /* device supports extended diagnostic test */
181#define DEV_HAS_MGMT_UNIT 0x01000 /* device supports management unit */
182#define DEV_HAS_CORRECT_MACADDR 0x02000 /* device supports correct mac address order */
183#define DEV_HAS_COLLISION_FIX 0x04000 /* device supports tx collision fix */
184#define DEV_HAS_PAUSEFRAME_TX_V1 0x08000 /* device supports tx pause frames version 1 */
185#define DEV_HAS_PAUSEFRAME_TX_V2 0x10000 /* device supports tx pause frames version 2 */
186#define DEV_HAS_PAUSEFRAME_TX_V3 0x20000 /* device supports tx pause frames version 3 */
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500187#define DEV_NEED_TX_LIMIT 0x40000 /* device needs to limit tx */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189enum {
190 NvRegIrqStatus = 0x000,
191#define NVREG_IRQSTAT_MIIEVENT 0x040
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500192#define NVREG_IRQSTAT_MASK 0x81ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 NvRegIrqMask = 0x004,
194#define NVREG_IRQ_RX_ERROR 0x0001
195#define NVREG_IRQ_RX 0x0002
196#define NVREG_IRQ_RX_NOBUF 0x0004
197#define NVREG_IRQ_TX_ERR 0x0008
Manfred Spraulc2dba062005-07-31 18:29:47 +0200198#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#define NVREG_IRQ_TIMER 0x0020
200#define NVREG_IRQ_LINK 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500201#define NVREG_IRQ_RX_FORCED 0x0080
202#define NVREG_IRQ_TX_FORCED 0x0100
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500203#define NVREG_IRQ_RECOVER_ERROR 0x8000
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500204#define NVREG_IRQMASK_THROUGHPUT 0x00df
Ayaz Abdulla096a4582007-05-21 20:23:11 -0400205#define NVREG_IRQMASK_CPU 0x0060
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500206#define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
207#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 -0500208#define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200209
210#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 -0500211 NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RX_FORCED| \
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500212 NVREG_IRQ_TX_FORCED|NVREG_IRQ_RECOVER_ERROR))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 NvRegUnknownSetupReg6 = 0x008,
215#define NVREG_UNKSETUP6_VAL 3
216
217/*
218 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
219 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
220 */
221 NvRegPollingInterval = 0x00c,
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -0500222#define NVREG_POLL_DEFAULT_THROUGHPUT 970 /* backup tx cleanup if loop max reached */
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500223#define NVREG_POLL_DEFAULT_CPU 13
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500224 NvRegMSIMap0 = 0x020,
225 NvRegMSIMap1 = 0x024,
226 NvRegMSIIrqMask = 0x030,
227#define NVREG_MSI_VECTOR_0_ENABLED 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 NvRegMisc1 = 0x080,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400229#define NVREG_MISC1_PAUSE_TX 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#define NVREG_MISC1_HD 0x02
231#define NVREG_MISC1_FORCE 0x3b0f3c
232
Ayaz Abdulla0a626772008-01-13 16:02:42 -0500233 NvRegMacReset = 0x34,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400234#define NVREG_MAC_RESET_ASSERT 0x0F3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 NvRegTransmitterControl = 0x084,
236#define NVREG_XMITCTL_START 0x01
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500237#define NVREG_XMITCTL_MGMT_ST 0x40000000
238#define NVREG_XMITCTL_SYNC_MASK 0x000f0000
239#define NVREG_XMITCTL_SYNC_NOT_READY 0x0
240#define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
241#define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
242#define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
243#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
244#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
245#define NVREG_XMITCTL_HOST_LOADED 0x00004000
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500246#define NVREG_XMITCTL_TX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 NvRegTransmitterStatus = 0x088,
248#define NVREG_XMITSTAT_BUSY 0x01
249
250 NvRegPacketFilterFlags = 0x8c,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400251#define NVREG_PFF_PAUSE_RX 0x08
252#define NVREG_PFF_ALWAYS 0x7F0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253#define NVREG_PFF_PROMISC 0x80
254#define NVREG_PFF_MYADDR 0x20
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400255#define NVREG_PFF_LOOPBACK 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 NvRegOffloadConfig = 0x90,
258#define NVREG_OFFLOAD_HOMEPHY 0x601
259#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
260 NvRegReceiverControl = 0x094,
261#define NVREG_RCVCTL_START 0x01
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500262#define NVREG_RCVCTL_RX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 NvRegReceiverStatus = 0x98,
264#define NVREG_RCVSTAT_BUSY 0x01
265
266 NvRegRandomSeed = 0x9c,
267#define NVREG_RNDSEED_MASK 0x00ff
268#define NVREG_RNDSEED_FORCE 0x7f00
269#define NVREG_RNDSEED_FORCE2 0x2d00
270#define NVREG_RNDSEED_FORCE3 0x7400
271
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400272 NvRegTxDeferral = 0xA0,
Ayaz Abdullafd9b5582008-02-05 12:29:49 -0500273#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
274#define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
275#define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
276#define NVREG_TX_DEFERRAL_RGMII_STRETCH_10 0x16190f
277#define NVREG_TX_DEFERRAL_RGMII_STRETCH_100 0x16300f
278#define NVREG_TX_DEFERRAL_MII_STRETCH 0x152000
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400279 NvRegRxDeferral = 0xA4,
280#define NVREG_RX_DEFERRAL_DEFAULT 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 NvRegMacAddrA = 0xA8,
282 NvRegMacAddrB = 0xAC,
283 NvRegMulticastAddrA = 0xB0,
284#define NVREG_MCASTADDRA_FORCE 0x01
285 NvRegMulticastAddrB = 0xB4,
286 NvRegMulticastMaskA = 0xB8,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500287#define NVREG_MCASTMASKA_NONE 0xffffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 NvRegMulticastMaskB = 0xBC,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500289#define NVREG_MCASTMASKB_NONE 0xffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 NvRegPhyInterface = 0xC0,
292#define PHY_RGMII 0x10000000
293
294 NvRegTxRingPhysAddr = 0x100,
295 NvRegRxRingPhysAddr = 0x104,
296 NvRegRingSizes = 0x108,
297#define NVREG_RINGSZ_TXSHIFT 0
298#define NVREG_RINGSZ_RXSHIFT 16
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400299 NvRegTransmitPoll = 0x10c,
300#define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 NvRegLinkSpeed = 0x110,
302#define NVREG_LINKSPEED_FORCE 0x10000
303#define NVREG_LINKSPEED_10 1000
304#define NVREG_LINKSPEED_100 100
305#define NVREG_LINKSPEED_1000 50
306#define NVREG_LINKSPEED_MASK (0xFFF)
307 NvRegUnknownSetupReg5 = 0x130,
308#define NVREG_UNKSETUP5_BIT31 (1<<31)
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400309 NvRegTxWatermark = 0x13c,
310#define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
311#define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
312#define NVREG_TX_WM_DESC2_3_1000 0xfe08000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 NvRegTxRxControl = 0x144,
314#define NVREG_TXRXCTL_KICK 0x0001
315#define NVREG_TXRXCTL_BIT1 0x0002
316#define NVREG_TXRXCTL_BIT2 0x0004
317#define NVREG_TXRXCTL_IDLE 0x0008
318#define NVREG_TXRXCTL_RESET 0x0010
319#define NVREG_TXRXCTL_RXCHECK 0x0400
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400320#define NVREG_TXRXCTL_DESC_1 0
Ayaz Abdullad2f78412007-01-09 13:30:02 -0500321#define NVREG_TXRXCTL_DESC_2 0x002100
322#define NVREG_TXRXCTL_DESC_3 0xc02200
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500323#define NVREG_TXRXCTL_VLANSTRIP 0x00040
324#define NVREG_TXRXCTL_VLANINS 0x00080
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500325 NvRegTxRingPhysAddrHigh = 0x148,
326 NvRegRxRingPhysAddrHigh = 0x14C,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400327 NvRegTxPauseFrame = 0x170,
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -0500328#define NVREG_TX_PAUSEFRAME_DISABLE 0x0fff0080
329#define NVREG_TX_PAUSEFRAME_ENABLE_V1 0x01800010
330#define NVREG_TX_PAUSEFRAME_ENABLE_V2 0x056003f0
331#define NVREG_TX_PAUSEFRAME_ENABLE_V3 0x09f00880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 NvRegMIIStatus = 0x180,
333#define NVREG_MIISTAT_ERROR 0x0001
334#define NVREG_MIISTAT_LINKCHANGE 0x0008
Ayaz Abdullaeb798422008-02-04 15:14:04 -0500335#define NVREG_MIISTAT_MASK_RW 0x0007
336#define NVREG_MIISTAT_MASK_ALL 0x000f
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500337 NvRegMIIMask = 0x184,
338#define NVREG_MII_LINKCHANGE 0x0008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 NvRegAdapterControl = 0x188,
341#define NVREG_ADAPTCTL_START 0x02
342#define NVREG_ADAPTCTL_LINKUP 0x04
343#define NVREG_ADAPTCTL_PHYVALID 0x40000
344#define NVREG_ADAPTCTL_RUNNING 0x100000
345#define NVREG_ADAPTCTL_PHYSHIFT 24
346 NvRegMIISpeed = 0x18c,
347#define NVREG_MIISPEED_BIT8 (1<<8)
348#define NVREG_MIIDELAY 5
349 NvRegMIIControl = 0x190,
350#define NVREG_MIICTL_INUSE 0x08000
351#define NVREG_MIICTL_WRITE 0x00400
352#define NVREG_MIICTL_ADDRSHIFT 5
353 NvRegMIIData = 0x194,
354 NvRegWakeUpFlags = 0x200,
355#define NVREG_WAKEUPFLAGS_VAL 0x7770
356#define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
357#define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
358#define NVREG_WAKEUPFLAGS_D3SHIFT 12
359#define NVREG_WAKEUPFLAGS_D2SHIFT 8
360#define NVREG_WAKEUPFLAGS_D1SHIFT 4
361#define NVREG_WAKEUPFLAGS_D0SHIFT 0
362#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
363#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
364#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
365#define NVREG_WAKEUPFLAGS_ENABLE 0x1111
366
367 NvRegPatternCRC = 0x204,
368 NvRegPatternMask = 0x208,
369 NvRegPowerCap = 0x268,
370#define NVREG_POWERCAP_D3SUPP (1<<30)
371#define NVREG_POWERCAP_D2SUPP (1<<26)
372#define NVREG_POWERCAP_D1SUPP (1<<25)
373 NvRegPowerState = 0x26c,
374#define NVREG_POWERSTATE_POWEREDUP 0x8000
375#define NVREG_POWERSTATE_VALID 0x0100
376#define NVREG_POWERSTATE_MASK 0x0003
377#define NVREG_POWERSTATE_D0 0x0000
378#define NVREG_POWERSTATE_D1 0x0001
379#define NVREG_POWERSTATE_D2 0x0002
380#define NVREG_POWERSTATE_D3 0x0003
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400381 NvRegTxCnt = 0x280,
382 NvRegTxZeroReXmt = 0x284,
383 NvRegTxOneReXmt = 0x288,
384 NvRegTxManyReXmt = 0x28c,
385 NvRegTxLateCol = 0x290,
386 NvRegTxUnderflow = 0x294,
387 NvRegTxLossCarrier = 0x298,
388 NvRegTxExcessDef = 0x29c,
389 NvRegTxRetryErr = 0x2a0,
390 NvRegRxFrameErr = 0x2a4,
391 NvRegRxExtraByte = 0x2a8,
392 NvRegRxLateCol = 0x2ac,
393 NvRegRxRunt = 0x2b0,
394 NvRegRxFrameTooLong = 0x2b4,
395 NvRegRxOverflow = 0x2b8,
396 NvRegRxFCSErr = 0x2bc,
397 NvRegRxFrameAlignErr = 0x2c0,
398 NvRegRxLenErr = 0x2c4,
399 NvRegRxUnicast = 0x2c8,
400 NvRegRxMulticast = 0x2cc,
401 NvRegRxBroadcast = 0x2d0,
402 NvRegTxDef = 0x2d4,
403 NvRegTxFrame = 0x2d8,
404 NvRegRxCnt = 0x2dc,
405 NvRegTxPause = 0x2e0,
406 NvRegRxPause = 0x2e4,
407 NvRegRxDropFrame = 0x2e8,
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500408 NvRegVlanControl = 0x300,
409#define NVREG_VLANCONTROL_ENABLE 0x2000
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500410 NvRegMSIXMap0 = 0x3e0,
411 NvRegMSIXMap1 = 0x3e4,
412 NvRegMSIXIrqStatus = 0x3f0,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400413
414 NvRegPowerState2 = 0x600,
415#define NVREG_POWERSTATE2_POWERUP_MASK 0x0F11
416#define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417};
418
419/* Big endian: should work, but is untested */
420struct ring_desc {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700421 __le32 buf;
422 __le32 flaglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423};
424
Manfred Spraulee733622005-07-31 18:32:26 +0200425struct ring_desc_ex {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700426 __le32 bufhigh;
427 __le32 buflow;
428 __le32 txvlan;
429 __le32 flaglen;
Manfred Spraulee733622005-07-31 18:32:26 +0200430};
431
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700432union ring_type {
Manfred Spraulee733622005-07-31 18:32:26 +0200433 struct ring_desc* orig;
434 struct ring_desc_ex* ex;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700435};
Manfred Spraulee733622005-07-31 18:32:26 +0200436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define FLAG_MASK_V1 0xffff0000
438#define FLAG_MASK_V2 0xffffc000
439#define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
440#define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
441
442#define NV_TX_LASTPACKET (1<<16)
443#define NV_TX_RETRYERROR (1<<19)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200444#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NV_TX_DEFERRED (1<<26)
446#define NV_TX_CARRIERLOST (1<<27)
447#define NV_TX_LATECOLLISION (1<<28)
448#define NV_TX_UNDERFLOW (1<<29)
449#define NV_TX_ERROR (1<<30)
450#define NV_TX_VALID (1<<31)
451
452#define NV_TX2_LASTPACKET (1<<29)
453#define NV_TX2_RETRYERROR (1<<18)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200454#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NV_TX2_DEFERRED (1<<25)
456#define NV_TX2_CARRIERLOST (1<<26)
457#define NV_TX2_LATECOLLISION (1<<27)
458#define NV_TX2_UNDERFLOW (1<<28)
459/* error and valid are the same for both */
460#define NV_TX2_ERROR (1<<30)
461#define NV_TX2_VALID (1<<31)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400462#define NV_TX2_TSO (1<<28)
463#define NV_TX2_TSO_SHIFT 14
Ayaz Abdullafa454592006-01-05 22:45:45 -0800464#define NV_TX2_TSO_MAX_SHIFT 14
465#define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400466#define NV_TX2_CHECKSUM_L3 (1<<27)
467#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500469#define NV_TX3_VLAN_TAG_PRESENT (1<<18)
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#define NV_RX_DESCRIPTORVALID (1<<16)
472#define NV_RX_MISSEDFRAME (1<<17)
473#define NV_RX_SUBSTRACT1 (1<<18)
474#define NV_RX_ERROR1 (1<<23)
475#define NV_RX_ERROR2 (1<<24)
476#define NV_RX_ERROR3 (1<<25)
477#define NV_RX_ERROR4 (1<<26)
478#define NV_RX_CRCERR (1<<27)
479#define NV_RX_OVERFLOW (1<<28)
480#define NV_RX_FRAMINGERR (1<<29)
481#define NV_RX_ERROR (1<<30)
482#define NV_RX_AVAIL (1<<31)
483
484#define NV_RX2_CHECKSUMMASK (0x1C000000)
Ayaz Abdullabfaffe82008-01-13 16:02:55 -0500485#define NV_RX2_CHECKSUM_IP (0x10000000)
486#define NV_RX2_CHECKSUM_IP_TCP (0x14000000)
487#define NV_RX2_CHECKSUM_IP_UDP (0x18000000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NV_RX2_DESCRIPTORVALID (1<<29)
489#define NV_RX2_SUBSTRACT1 (1<<25)
490#define NV_RX2_ERROR1 (1<<18)
491#define NV_RX2_ERROR2 (1<<19)
492#define NV_RX2_ERROR3 (1<<20)
493#define NV_RX2_ERROR4 (1<<21)
494#define NV_RX2_CRCERR (1<<22)
495#define NV_RX2_OVERFLOW (1<<23)
496#define NV_RX2_FRAMINGERR (1<<24)
497/* error and avail are the same for both */
498#define NV_RX2_ERROR (1<<30)
499#define NV_RX2_AVAIL (1<<31)
500
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500501#define NV_RX3_VLAN_TAG_PRESENT (1<<16)
502#define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504/* Miscelaneous hardware related defines: */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400505#define NV_PCI_REGSZ_VER1 0x270
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500506#define NV_PCI_REGSZ_VER2 0x2d4
507#define NV_PCI_REGSZ_VER3 0x604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509/* various timeout delays: all in usec */
510#define NV_TXRX_RESET_DELAY 4
511#define NV_TXSTOP_DELAY1 10
512#define NV_TXSTOP_DELAY1MAX 500000
513#define NV_TXSTOP_DELAY2 100
514#define NV_RXSTOP_DELAY1 10
515#define NV_RXSTOP_DELAY1MAX 500000
516#define NV_RXSTOP_DELAY2 100
517#define NV_SETUP5_DELAY 5
518#define NV_SETUP5_DELAYMAX 50000
519#define NV_POWERUP_DELAY 5
520#define NV_POWERUP_DELAYMAX 5000
521#define NV_MIIBUSY_DELAY 50
522#define NV_MIIPHY_DELAY 10
523#define NV_MIIPHY_DELAYMAX 10000
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400524#define NV_MAC_RESET_DELAY 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526#define NV_WAKEUPPATTERNS 5
527#define NV_WAKEUPMASKENTRIES 4
528
529/* General driver defaults */
530#define NV_WATCHDOG_TIMEO (5*HZ)
531
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400532#define RX_RING_DEFAULT 128
533#define TX_RING_DEFAULT 256
534#define RX_RING_MIN 128
535#define TX_RING_MIN 64
536#define RING_MAX_DESC_VER_1 1024
537#define RING_MAX_DESC_VER_2_3 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200540#define NV_RX_HEADERS (64)
541/* even more slack. */
542#define NV_RX_ALLOC_PAD (64)
543
544/* maximum mtu size */
545#define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
546#define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548#define OOM_REFILL (1+HZ/20)
549#define POLL_WAIT (1+HZ/100)
550#define LINK_TIMEOUT (3*HZ)
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400551#define STATS_INTERVAL (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400553/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400555 * The nic supports three different descriptor types:
556 * - DESC_VER_1: Original
557 * - DESC_VER_2: support for jumbo frames.
558 * - DESC_VER_3: 64-bit format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400560#define DESC_VER_1 1
561#define DESC_VER_2 2
562#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564/* PHY defines */
565#define PHY_OUI_MARVELL 0x5043
566#define PHY_OUI_CICADA 0x03f1
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400567#define PHY_OUI_VITESSE 0x01c1
Willy Tarreauba685fb2007-08-23 21:35:41 +0200568#define PHY_OUI_REALTEK 0x0732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#define PHYID1_OUI_MASK 0x03ff
570#define PHYID1_OUI_SHFT 6
571#define PHYID2_OUI_MASK 0xfc00
572#define PHYID2_OUI_SHFT 10
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400573#define PHYID2_MODEL_MASK 0x03f0
574#define PHY_MODEL_MARVELL_E3016 0x220
575#define PHY_MARVELL_E3016_INITMASK 0x0300
Ayaz Abdulla14a67f32007-07-15 06:50:28 -0400576#define PHY_CICADA_INIT1 0x0f000
577#define PHY_CICADA_INIT2 0x0e00
578#define PHY_CICADA_INIT3 0x01000
579#define PHY_CICADA_INIT4 0x0200
580#define PHY_CICADA_INIT5 0x0004
581#define PHY_CICADA_INIT6 0x02000
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400582#define PHY_VITESSE_INIT_REG1 0x1f
583#define PHY_VITESSE_INIT_REG2 0x10
584#define PHY_VITESSE_INIT_REG3 0x11
585#define PHY_VITESSE_INIT_REG4 0x12
586#define PHY_VITESSE_INIT_MSK1 0xc
587#define PHY_VITESSE_INIT_MSK2 0x0180
588#define PHY_VITESSE_INIT1 0x52b5
589#define PHY_VITESSE_INIT2 0xaf8a
590#define PHY_VITESSE_INIT3 0x8
591#define PHY_VITESSE_INIT4 0x8f8a
592#define PHY_VITESSE_INIT5 0xaf86
593#define PHY_VITESSE_INIT6 0x8f86
594#define PHY_VITESSE_INIT7 0xaf82
595#define PHY_VITESSE_INIT8 0x0100
596#define PHY_VITESSE_INIT9 0x8f82
597#define PHY_VITESSE_INIT10 0x0
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400598#define PHY_REALTEK_INIT_REG1 0x1f
599#define PHY_REALTEK_INIT_REG2 0x19
600#define PHY_REALTEK_INIT_REG3 0x13
601#define PHY_REALTEK_INIT1 0x0000
602#define PHY_REALTEK_INIT2 0x8e00
603#define PHY_REALTEK_INIT3 0x0001
604#define PHY_REALTEK_INIT4 0xad17
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#define PHY_GIGABIT 0x0100
607
608#define PHY_TIMEOUT 0x1
609#define PHY_ERROR 0x2
610
611#define PHY_100 0x1
612#define PHY_1000 0x2
613#define PHY_HALF 0x100
614
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400615#define NV_PAUSEFRAME_RX_CAPABLE 0x0001
616#define NV_PAUSEFRAME_TX_CAPABLE 0x0002
617#define NV_PAUSEFRAME_RX_ENABLE 0x0004
618#define NV_PAUSEFRAME_TX_ENABLE 0x0008
Ayaz Abdullab6d07732006-06-10 22:47:42 -0400619#define NV_PAUSEFRAME_RX_REQ 0x0010
620#define NV_PAUSEFRAME_TX_REQ 0x0020
621#define NV_PAUSEFRAME_AUTONEG 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500623/* MSI/MSI-X defines */
624#define NV_MSI_X_MAX_VECTORS 8
625#define NV_MSI_X_VECTORS_MASK 0x000f
626#define NV_MSI_CAPABLE 0x0010
627#define NV_MSI_X_CAPABLE 0x0020
628#define NV_MSI_ENABLED 0x0040
629#define NV_MSI_X_ENABLED 0x0080
630
631#define NV_MSI_X_VECTOR_ALL 0x0
632#define NV_MSI_X_VECTOR_RX 0x0
633#define NV_MSI_X_VECTOR_TX 0x1
634#define NV_MSI_X_VECTOR_OTHER 0x2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Ayaz Abdullab2976d22008-02-04 15:13:59 -0500636#define NV_RESTART_TX 0x1
637#define NV_RESTART_RX 0x2
638
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500639#define NV_TX_LIMIT_COUNT 16
640
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400641/* statistics */
642struct nv_ethtool_str {
643 char name[ETH_GSTRING_LEN];
644};
645
646static const struct nv_ethtool_str nv_estats_str[] = {
647 { "tx_bytes" },
648 { "tx_zero_rexmt" },
649 { "tx_one_rexmt" },
650 { "tx_many_rexmt" },
651 { "tx_late_collision" },
652 { "tx_fifo_errors" },
653 { "tx_carrier_errors" },
654 { "tx_excess_deferral" },
655 { "tx_retry_error" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400656 { "rx_frame_error" },
657 { "rx_extra_byte" },
658 { "rx_late_collision" },
659 { "rx_runt" },
660 { "rx_frame_too_long" },
661 { "rx_over_errors" },
662 { "rx_crc_errors" },
663 { "rx_frame_align_error" },
664 { "rx_length_error" },
665 { "rx_unicast" },
666 { "rx_multicast" },
667 { "rx_broadcast" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400668 { "rx_packets" },
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500669 { "rx_errors_total" },
670 { "tx_errors_total" },
671
672 /* version 2 stats */
673 { "tx_deferral" },
674 { "tx_packets" },
675 { "rx_bytes" },
676 { "tx_pause" },
677 { "rx_pause" },
678 { "rx_drop_frame" }
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400679};
680
681struct nv_ethtool_stats {
682 u64 tx_bytes;
683 u64 tx_zero_rexmt;
684 u64 tx_one_rexmt;
685 u64 tx_many_rexmt;
686 u64 tx_late_collision;
687 u64 tx_fifo_errors;
688 u64 tx_carrier_errors;
689 u64 tx_excess_deferral;
690 u64 tx_retry_error;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400691 u64 rx_frame_error;
692 u64 rx_extra_byte;
693 u64 rx_late_collision;
694 u64 rx_runt;
695 u64 rx_frame_too_long;
696 u64 rx_over_errors;
697 u64 rx_crc_errors;
698 u64 rx_frame_align_error;
699 u64 rx_length_error;
700 u64 rx_unicast;
701 u64 rx_multicast;
702 u64 rx_broadcast;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400703 u64 rx_packets;
704 u64 rx_errors_total;
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500705 u64 tx_errors_total;
706
707 /* version 2 stats */
708 u64 tx_deferral;
709 u64 tx_packets;
710 u64 rx_bytes;
711 u64 tx_pause;
712 u64 rx_pause;
713 u64 rx_drop_frame;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400714};
715
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500716#define NV_DEV_STATISTICS_V2_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64))
717#define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6)
718
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400719/* diagnostics */
720#define NV_TEST_COUNT_BASE 3
721#define NV_TEST_COUNT_EXTENDED 4
722
723static const struct nv_ethtool_str nv_etests_str[] = {
724 { "link (online/offline)" },
725 { "register (offline) " },
726 { "interrupt (offline) " },
727 { "loopback (offline) " }
728};
729
730struct register_test {
Al Viro5bb7ea22007-12-09 16:06:41 +0000731 __u32 reg;
732 __u32 mask;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400733};
734
735static const struct register_test nv_registers_test[] = {
736 { NvRegUnknownSetupReg6, 0x01 },
737 { NvRegMisc1, 0x03c },
738 { NvRegOffloadConfig, 0x03ff },
739 { NvRegMulticastAddrA, 0xffffffff },
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400740 { NvRegTxWatermark, 0x0ff },
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400741 { NvRegWakeUpFlags, 0x07777 },
742 { 0,0 }
743};
744
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500745struct nv_skb_map {
746 struct sk_buff *skb;
747 dma_addr_t dma;
748 unsigned int dma_len;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500749 struct ring_desc_ex *first_tx_desc;
750 struct nv_skb_map *next_tx_ctx;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500751};
752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753/*
754 * SMP locking:
755 * All hardware access under dev->priv->lock, except the performance
756 * critical parts:
757 * - rx is (pseudo-) lockless: it relies on the single-threading provided
758 * by the arch code for interrupts.
Herbert Xu932ff272006-06-09 12:20:56 -0700759 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 * needs dev->priv->lock :-(
Herbert Xu932ff272006-06-09 12:20:56 -0700761 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 */
763
764/* in dev: base, irq */
765struct fe_priv {
766 spinlock_t lock;
767
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700768 struct net_device *dev;
769 struct napi_struct napi;
770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 /* General data:
772 * Locking: spin_lock(&np->lock); */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400773 struct nv_ethtool_stats estats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 int in_shutdown;
775 u32 linkspeed;
776 int duplex;
777 int autoneg;
778 int fixed_mode;
779 int phyaddr;
780 int wolenabled;
781 unsigned int phy_oui;
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400782 unsigned int phy_model;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 u16 gigabit;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400784 int intr_test;
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500785 int recover_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 /* General data: RO fields */
788 dma_addr_t ring_addr;
789 struct pci_dev *pci_dev;
790 u32 orig_mac[2];
791 u32 irqmask;
792 u32 desc_ver;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400793 u32 txrxctl_bits;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500794 u32 vlanctl_bits;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400795 u32 driver_data;
796 u32 register_size;
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -0400797 int rx_csum;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500798 u32 mac_in_use;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 void __iomem *base;
801
802 /* rx specific fields.
803 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
804 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500805 union ring_type get_rx, put_rx, first_rx, last_rx;
806 struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
807 struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
808 struct nv_skb_map *rx_skb;
809
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700810 union ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200812 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 struct timer_list oom_kick;
814 struct timer_list nic_poll;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400815 struct timer_list stats_poll;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500816 u32 nic_poll_irq;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400817 int rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 /* media detection workaround.
820 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
821 */
822 int need_linktimer;
823 unsigned long link_timeout;
824 /*
825 * tx specific fields.
826 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500827 union ring_type get_tx, put_tx, first_tx, last_tx;
828 struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
829 struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
830 struct nv_skb_map *tx_skb;
831
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700832 union ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 u32 tx_flags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400834 int tx_ring_size;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500835 int tx_limit;
836 u32 tx_pkts_in_progress;
837 struct nv_skb_map *tx_change_owner;
838 struct nv_skb_map *tx_end_flip;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -0500839 int tx_stop;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500840
841 /* vlan fields */
842 struct vlan_group *vlangrp;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500843
844 /* msi/msi-x fields */
845 u32 msi_flags;
846 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400847
848 /* flow control */
849 u32 pause_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850};
851
852/*
853 * Maximum number of loops until we assume that a bit in the irq mask
854 * is stuck. Overridable with module param.
855 */
856static int max_interrupt_work = 5;
857
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500858/*
859 * Optimization can be either throuput mode or cpu mode
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400860 *
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500861 * Throughput Mode: Every tx and rx packet will generate an interrupt.
862 * CPU Mode: Interrupts are controlled by a timer.
863 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400864enum {
865 NV_OPTIMIZATION_MODE_THROUGHPUT,
866 NV_OPTIMIZATION_MODE_CPU
867};
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500868static int optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
869
870/*
871 * Poll interval for timer irq
872 *
873 * This interval determines how frequent an interrupt is generated.
874 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
875 * Min = 0, and Max = 65535
876 */
877static int poll_interval = -1;
878
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500879/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400880 * MSI interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500881 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400882enum {
883 NV_MSI_INT_DISABLED,
884 NV_MSI_INT_ENABLED
885};
886static int msi = NV_MSI_INT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500887
888/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400889 * MSIX interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500890 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400891enum {
892 NV_MSIX_INT_DISABLED,
893 NV_MSIX_INT_ENABLED
894};
Ayaz Abdullacaf96462007-02-20 03:34:40 -0500895static int msix = NV_MSIX_INT_DISABLED;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400896
897/*
898 * DMA 64bit
899 */
900enum {
901 NV_DMA_64BIT_DISABLED,
902 NV_DMA_64BIT_ENABLED
903};
904static int dma_64bit = NV_DMA_64BIT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906static inline struct fe_priv *get_nvpriv(struct net_device *dev)
907{
908 return netdev_priv(dev);
909}
910
911static inline u8 __iomem *get_hwbase(struct net_device *dev)
912{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400913 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914}
915
916static inline void pci_push(u8 __iomem *base)
917{
918 /* force out pending posted writes */
919 readl(base);
920}
921
922static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
923{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700924 return le32_to_cpu(prd->flaglen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
926}
927
Manfred Spraulee733622005-07-31 18:32:26 +0200928static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
929{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700930 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
Manfred Spraulee733622005-07-31 18:32:26 +0200931}
932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
934 int delay, int delaymax, const char *msg)
935{
936 u8 __iomem *base = get_hwbase(dev);
937
938 pci_push(base);
939 do {
940 udelay(delay);
941 delaymax -= delay;
942 if (delaymax < 0) {
943 if (msg)
944 printk(msg);
945 return 1;
946 }
947 } while ((readl(base + offset) & mask) != target);
948 return 0;
949}
950
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500951#define NV_SETUP_RX_RING 0x01
952#define NV_SETUP_TX_RING 0x02
953
Al Viro5bb7ea22007-12-09 16:06:41 +0000954static inline u32 dma_low(dma_addr_t addr)
955{
956 return addr;
957}
958
959static inline u32 dma_high(dma_addr_t addr)
960{
961 return addr>>31>>1; /* 0 if 32bit, shift down by 32 if 64bit */
962}
963
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500964static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
965{
966 struct fe_priv *np = get_nvpriv(dev);
967 u8 __iomem *base = get_hwbase(dev);
968
969 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
970 if (rxtx_flags & NV_SETUP_RX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000971 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500972 }
973 if (rxtx_flags & NV_SETUP_TX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000974 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500975 }
976 } else {
977 if (rxtx_flags & NV_SETUP_RX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000978 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
979 writel(dma_high(np->ring_addr), base + NvRegRxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500980 }
981 if (rxtx_flags & NV_SETUP_TX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000982 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
983 writel(dma_high(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500984 }
985 }
986}
987
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400988static void free_rings(struct net_device *dev)
989{
990 struct fe_priv *np = get_nvpriv(dev);
991
992 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700993 if (np->rx_ring.orig)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400994 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
995 np->rx_ring.orig, np->ring_addr);
996 } else {
997 if (np->rx_ring.ex)
998 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
999 np->rx_ring.ex, np->ring_addr);
1000 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001001 if (np->rx_skb)
1002 kfree(np->rx_skb);
1003 if (np->tx_skb)
1004 kfree(np->tx_skb);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001005}
1006
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001007static int using_multi_irqs(struct net_device *dev)
1008{
1009 struct fe_priv *np = get_nvpriv(dev);
1010
1011 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
1012 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1013 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
1014 return 0;
1015 else
1016 return 1;
1017}
1018
1019static void nv_enable_irq(struct net_device *dev)
1020{
1021 struct fe_priv *np = get_nvpriv(dev);
1022
1023 if (!using_multi_irqs(dev)) {
1024 if (np->msi_flags & NV_MSI_X_ENABLED)
1025 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1026 else
Manfred Spraula7475902007-10-17 21:52:33 +02001027 enable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001028 } else {
1029 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1030 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1031 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1032 }
1033}
1034
1035static void nv_disable_irq(struct net_device *dev)
1036{
1037 struct fe_priv *np = get_nvpriv(dev);
1038
1039 if (!using_multi_irqs(dev)) {
1040 if (np->msi_flags & NV_MSI_X_ENABLED)
1041 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1042 else
Manfred Spraula7475902007-10-17 21:52:33 +02001043 disable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001044 } else {
1045 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1046 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1047 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1048 }
1049}
1050
1051/* In MSIX mode, a write to irqmask behaves as XOR */
1052static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
1053{
1054 u8 __iomem *base = get_hwbase(dev);
1055
1056 writel(mask, base + NvRegIrqMask);
1057}
1058
1059static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
1060{
1061 struct fe_priv *np = get_nvpriv(dev);
1062 u8 __iomem *base = get_hwbase(dev);
1063
1064 if (np->msi_flags & NV_MSI_X_ENABLED) {
1065 writel(mask, base + NvRegIrqMask);
1066 } else {
1067 if (np->msi_flags & NV_MSI_ENABLED)
1068 writel(0, base + NvRegMSIIrqMask);
1069 writel(0, base + NvRegIrqMask);
1070 }
1071}
1072
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073#define MII_READ (-1)
1074/* mii_rw: read/write a register on the PHY.
1075 *
1076 * Caller must guarantee serialization
1077 */
1078static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1079{
1080 u8 __iomem *base = get_hwbase(dev);
1081 u32 reg;
1082 int retval;
1083
Ayaz Abdullaeb798422008-02-04 15:14:04 -05001084 writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
1086 reg = readl(base + NvRegMIIControl);
1087 if (reg & NVREG_MIICTL_INUSE) {
1088 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1089 udelay(NV_MIIBUSY_DELAY);
1090 }
1091
1092 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1093 if (value != MII_READ) {
1094 writel(value, base + NvRegMIIData);
1095 reg |= NVREG_MIICTL_WRITE;
1096 }
1097 writel(reg, base + NvRegMIIControl);
1098
1099 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
1100 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
1101 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n",
1102 dev->name, miireg, addr);
1103 retval = -1;
1104 } else if (value != MII_READ) {
1105 /* it was a write operation - fewer failures are detectable */
1106 dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
1107 dev->name, value, miireg, addr);
1108 retval = 0;
1109 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
1110 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n",
1111 dev->name, miireg, addr);
1112 retval = -1;
1113 } else {
1114 retval = readl(base + NvRegMIIData);
1115 dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
1116 dev->name, miireg, addr, retval);
1117 }
1118
1119 return retval;
1120}
1121
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001122static int phy_reset(struct net_device *dev, u32 bmcr_setup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001124 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 u32 miicontrol;
1126 unsigned int tries = 0;
1127
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001128 miicontrol = BMCR_RESET | bmcr_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) {
1130 return -1;
1131 }
1132
1133 /* wait for 500ms */
1134 msleep(500);
1135
1136 /* must wait till reset is deasserted */
1137 while (miicontrol & BMCR_RESET) {
1138 msleep(10);
1139 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1140 /* FIXME: 100 tries seem excessive */
1141 if (tries++ > 100)
1142 return -1;
1143 }
1144 return 0;
1145}
1146
1147static int phy_init(struct net_device *dev)
1148{
1149 struct fe_priv *np = get_nvpriv(dev);
1150 u8 __iomem *base = get_hwbase(dev);
1151 u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg;
1152
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001153 /* phy errata for E3016 phy */
1154 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1155 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1156 reg &= ~PHY_MARVELL_E3016_INITMASK;
1157 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
1158 printk(KERN_INFO "%s: phy write to errata reg failed.\n", pci_name(np->pci_dev));
1159 return PHY_ERROR;
1160 }
1161 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001162 if (np->phy_oui == PHY_OUI_REALTEK) {
1163 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1164 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1165 return PHY_ERROR;
1166 }
1167 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1168 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1169 return PHY_ERROR;
1170 }
1171 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1172 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1173 return PHY_ERROR;
1174 }
1175 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1176 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1177 return PHY_ERROR;
1178 }
1179 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1180 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1181 return PHY_ERROR;
1182 }
1183 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001184
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 /* set advertise register */
1186 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001187 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|ADVERTISE_PAUSE_ASYM|ADVERTISE_PAUSE_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
1189 printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev));
1190 return PHY_ERROR;
1191 }
1192
1193 /* get phy interface type */
1194 phyinterface = readl(base + NvRegPhyInterface);
1195
1196 /* see if gigabit phy */
1197 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1198 if (mii_status & PHY_GIGABIT) {
1199 np->gigabit = PHY_GIGABIT;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001200 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 mii_control_1000 &= ~ADVERTISE_1000HALF;
1202 if (phyinterface & PHY_RGMII)
1203 mii_control_1000 |= ADVERTISE_1000FULL;
1204 else
1205 mii_control_1000 &= ~ADVERTISE_1000FULL;
1206
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001207 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1209 return PHY_ERROR;
1210 }
1211 }
1212 else
1213 np->gigabit = 0;
1214
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001215 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1216 mii_control |= BMCR_ANENABLE;
1217
1218 /* reset the phy
1219 * (certain phys need bmcr to be setup with reset)
1220 */
1221 if (phy_reset(dev, mii_control)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev));
1223 return PHY_ERROR;
1224 }
1225
1226 /* phy vendor specific configuration */
1227 if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) {
1228 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
Ayaz Abdulla14a67f32007-07-15 06:50:28 -04001229 phy_reserved &= ~(PHY_CICADA_INIT1 | PHY_CICADA_INIT2);
1230 phy_reserved |= (PHY_CICADA_INIT3 | PHY_CICADA_INIT4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) {
1232 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1233 return PHY_ERROR;
1234 }
1235 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
Ayaz Abdulla14a67f32007-07-15 06:50:28 -04001236 phy_reserved |= PHY_CICADA_INIT5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) {
1238 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1239 return PHY_ERROR;
1240 }
1241 }
1242 if (np->phy_oui == PHY_OUI_CICADA) {
1243 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
Ayaz Abdulla14a67f32007-07-15 06:50:28 -04001244 phy_reserved |= PHY_CICADA_INIT6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) {
1246 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1247 return PHY_ERROR;
1248 }
1249 }
Ayaz Abdullad215d8a2007-07-15 06:50:53 -04001250 if (np->phy_oui == PHY_OUI_VITESSE) {
1251 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT1)) {
1252 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1253 return PHY_ERROR;
1254 }
1255 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT2)) {
1256 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1257 return PHY_ERROR;
1258 }
1259 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1260 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1261 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1262 return PHY_ERROR;
1263 }
1264 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1265 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1266 phy_reserved |= PHY_VITESSE_INIT3;
1267 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1268 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1269 return PHY_ERROR;
1270 }
1271 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT4)) {
1272 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1273 return PHY_ERROR;
1274 }
1275 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT5)) {
1276 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1277 return PHY_ERROR;
1278 }
1279 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1280 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1281 phy_reserved |= PHY_VITESSE_INIT3;
1282 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
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_REG3, MII_READ);
1287 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1288 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1289 return PHY_ERROR;
1290 }
1291 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT6)) {
1292 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1293 return PHY_ERROR;
1294 }
1295 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT7)) {
1296 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1297 return PHY_ERROR;
1298 }
1299 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1300 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1301 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1302 return PHY_ERROR;
1303 }
1304 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1305 phy_reserved &= ~PHY_VITESSE_INIT_MSK2;
1306 phy_reserved |= PHY_VITESSE_INIT8;
1307 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1308 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1309 return PHY_ERROR;
1310 }
1311 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT9)) {
1312 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1313 return PHY_ERROR;
1314 }
1315 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT10)) {
1316 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1317 return PHY_ERROR;
1318 }
1319 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001320 if (np->phy_oui == PHY_OUI_REALTEK) {
1321 /* reset could have cleared these out, set them back */
1322 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1323 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1324 return PHY_ERROR;
1325 }
1326 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1327 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1328 return PHY_ERROR;
1329 }
1330 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1331 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1332 return PHY_ERROR;
1333 }
1334 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1335 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1336 return PHY_ERROR;
1337 }
1338 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1339 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1340 return PHY_ERROR;
1341 }
1342 }
1343
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001344 /* some phys clear out pause advertisment on reset, set it back */
1345 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
1347 /* restart auto negotiation */
1348 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1349 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
1350 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
1351 return PHY_ERROR;
1352 }
1353
1354 return 0;
1355}
1356
1357static void nv_start_rx(struct net_device *dev)
1358{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001359 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001361 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
1363 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
1364 /* Already running? Stop it. */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001365 if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
1366 rx_ctrl &= ~NVREG_RCVCTL_START;
1367 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 pci_push(base);
1369 }
1370 writel(np->linkspeed, base + NvRegLinkSpeed);
1371 pci_push(base);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001372 rx_ctrl |= NVREG_RCVCTL_START;
1373 if (np->mac_in_use)
1374 rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN;
1375 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
1377 dev->name, np->duplex, np->linkspeed);
1378 pci_push(base);
1379}
1380
1381static void nv_stop_rx(struct net_device *dev)
1382{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001383 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001385 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001388 if (!np->mac_in_use)
1389 rx_ctrl &= ~NVREG_RCVCTL_START;
1390 else
1391 rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN;
1392 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1394 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
1395 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
1396
1397 udelay(NV_RXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001398 if (!np->mac_in_use)
1399 writel(0, base + NvRegLinkSpeed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400}
1401
1402static void nv_start_tx(struct net_device *dev)
1403{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001404 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001406 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
1408 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001409 tx_ctrl |= NVREG_XMITCTL_START;
1410 if (np->mac_in_use)
1411 tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN;
1412 writel(tx_ctrl, base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 pci_push(base);
1414}
1415
1416static void nv_stop_tx(struct net_device *dev)
1417{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001418 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001420 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
1422 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001423 if (!np->mac_in_use)
1424 tx_ctrl &= ~NVREG_XMITCTL_START;
1425 else
1426 tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN;
1427 writel(tx_ctrl, base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1429 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
1430 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
1431
1432 udelay(NV_TXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001433 if (!np->mac_in_use)
1434 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
1435 base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436}
1437
1438static void nv_txrx_reset(struct net_device *dev)
1439{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001440 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 u8 __iomem *base = get_hwbase(dev);
1442
1443 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001444 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 pci_push(base);
1446 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001447 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 pci_push(base);
1449}
1450
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001451static void nv_mac_reset(struct net_device *dev)
1452{
1453 struct fe_priv *np = netdev_priv(dev);
1454 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001455 u32 temp1, temp2, temp3;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001456
1457 dprintk(KERN_DEBUG "%s: nv_mac_reset\n", dev->name);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001458
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001459 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1460 pci_push(base);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001461
1462 /* save registers since they will be cleared on reset */
1463 temp1 = readl(base + NvRegMacAddrA);
1464 temp2 = readl(base + NvRegMacAddrB);
1465 temp3 = readl(base + NvRegTransmitPoll);
1466
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001467 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1468 pci_push(base);
1469 udelay(NV_MAC_RESET_DELAY);
1470 writel(0, base + NvRegMacReset);
1471 pci_push(base);
1472 udelay(NV_MAC_RESET_DELAY);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001473
1474 /* restore saved registers */
1475 writel(temp1, base + NvRegMacAddrA);
1476 writel(temp2, base + NvRegMacAddrB);
1477 writel(temp3, base + NvRegTransmitPoll);
1478
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001479 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1480 pci_push(base);
1481}
1482
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001483static void nv_get_hw_stats(struct net_device *dev)
1484{
1485 struct fe_priv *np = netdev_priv(dev);
1486 u8 __iomem *base = get_hwbase(dev);
1487
1488 np->estats.tx_bytes += readl(base + NvRegTxCnt);
1489 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
1490 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
1491 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
1492 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
1493 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
1494 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
1495 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
1496 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
1497 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
1498 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
1499 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
1500 np->estats.rx_runt += readl(base + NvRegRxRunt);
1501 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
1502 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
1503 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
1504 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
1505 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
1506 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
1507 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
1508 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
1509 np->estats.rx_packets =
1510 np->estats.rx_unicast +
1511 np->estats.rx_multicast +
1512 np->estats.rx_broadcast;
1513 np->estats.rx_errors_total =
1514 np->estats.rx_crc_errors +
1515 np->estats.rx_over_errors +
1516 np->estats.rx_frame_error +
1517 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
1518 np->estats.rx_late_collision +
1519 np->estats.rx_runt +
1520 np->estats.rx_frame_too_long;
1521 np->estats.tx_errors_total =
1522 np->estats.tx_late_collision +
1523 np->estats.tx_fifo_errors +
1524 np->estats.tx_carrier_errors +
1525 np->estats.tx_excess_deferral +
1526 np->estats.tx_retry_error;
1527
1528 if (np->driver_data & DEV_HAS_STATISTICS_V2) {
1529 np->estats.tx_deferral += readl(base + NvRegTxDef);
1530 np->estats.tx_packets += readl(base + NvRegTxFrame);
1531 np->estats.rx_bytes += readl(base + NvRegRxCnt);
1532 np->estats.tx_pause += readl(base + NvRegTxPause);
1533 np->estats.rx_pause += readl(base + NvRegRxPause);
1534 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
1535 }
1536}
1537
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538/*
1539 * nv_get_stats: dev->get_stats function
1540 * Get latest stats value from the nic.
1541 * Called with read_lock(&dev_base_lock) held for read -
1542 * only synchronized against unregister_netdevice.
1543 */
1544static struct net_device_stats *nv_get_stats(struct net_device *dev)
1545{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001546 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Ayaz Abdulla21828162007-01-23 12:27:21 -05001548 /* If the nic supports hw counters then retrieve latest values */
1549 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2)) {
1550 nv_get_hw_stats(dev);
1551
1552 /* copy to net_device stats */
Jeff Garzik8148ff42007-10-16 20:56:09 -04001553 dev->stats.tx_bytes = np->estats.tx_bytes;
1554 dev->stats.tx_fifo_errors = np->estats.tx_fifo_errors;
1555 dev->stats.tx_carrier_errors = np->estats.tx_carrier_errors;
1556 dev->stats.rx_crc_errors = np->estats.rx_crc_errors;
1557 dev->stats.rx_over_errors = np->estats.rx_over_errors;
1558 dev->stats.rx_errors = np->estats.rx_errors_total;
1559 dev->stats.tx_errors = np->estats.tx_errors_total;
Ayaz Abdulla21828162007-01-23 12:27:21 -05001560 }
Jeff Garzik8148ff42007-10-16 20:56:09 -04001561
1562 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
1565/*
1566 * nv_alloc_rx: fill rx ring entries.
1567 * Return 1 if the allocations for the skbs failed and the
1568 * rx engine is without Available descriptors
1569 */
1570static int nv_alloc_rx(struct net_device *dev)
1571{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001572 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001573 struct ring_desc* less_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001575 less_rx = np->get_rx.orig;
1576 if (less_rx-- == np->first_rx.orig)
1577 less_rx = np->last_rx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001578
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001579 while (np->put_rx.orig != less_rx) {
1580 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001581 if (skb) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001582 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001583 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1584 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001585 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001586 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001587 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001588 np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
1589 wmb();
1590 np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001591 if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001592 np->put_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001593 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001594 np->put_rx_ctx = np->first_rx_ctx;
1595 } else {
1596 return 1;
1597 }
1598 }
1599 return 0;
1600}
1601
1602static int nv_alloc_rx_optimized(struct net_device *dev)
1603{
1604 struct fe_priv *np = netdev_priv(dev);
1605 struct ring_desc_ex* less_rx;
1606
1607 less_rx = np->get_rx.ex;
1608 if (less_rx-- == np->first_rx.ex)
1609 less_rx = np->last_rx.ex;
1610
1611 while (np->put_rx.ex != less_rx) {
1612 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
1613 if (skb) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001614 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001615 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1616 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001617 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001618 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001619 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Al Viro5bb7ea22007-12-09 16:06:41 +00001620 np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
1621 np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001622 wmb();
1623 np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001624 if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001625 np->put_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001626 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001627 np->put_rx_ctx = np->first_rx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 } else {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001629 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 return 0;
1633}
1634
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001635/* If rx bufs are exhausted called after 50ms to attempt to refresh */
1636#ifdef CONFIG_FORCEDETH_NAPI
1637static void nv_do_rx_refill(unsigned long data)
1638{
1639 struct net_device *dev = (struct net_device *) data;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001640 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001641
1642 /* Just reschedule NAPI rx processing */
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001643 netif_rx_schedule(dev, &np->napi);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001644}
1645#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646static void nv_do_rx_refill(unsigned long data)
1647{
1648 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001649 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001650 int retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001652 if (!using_multi_irqs(dev)) {
1653 if (np->msi_flags & NV_MSI_X_ENABLED)
1654 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1655 else
Manfred Spraula7475902007-10-17 21:52:33 +02001656 disable_irq(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001657 } else {
1658 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1659 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001660 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1661 retcode = nv_alloc_rx(dev);
1662 else
1663 retcode = nv_alloc_rx_optimized(dev);
1664 if (retcode) {
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001665 spin_lock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 if (!np->in_shutdown)
1667 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001668 spin_unlock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001670 if (!using_multi_irqs(dev)) {
1671 if (np->msi_flags & NV_MSI_X_ENABLED)
1672 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1673 else
Manfred Spraula7475902007-10-17 21:52:33 +02001674 enable_irq(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001675 } else {
1676 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1677 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001679#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001681static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001682{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001683 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001684 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001685 np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
1686 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1687 np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
1688 else
1689 np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
1690 np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
1691 np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
Manfred Sprauld81c0982005-07-31 18:20:30 +02001692
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001693 for (i = 0; i < np->rx_ring_size; i++) {
1694 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001695 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001696 np->rx_ring.orig[i].buf = 0;
1697 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001698 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001699 np->rx_ring.ex[i].txvlan = 0;
1700 np->rx_ring.ex[i].bufhigh = 0;
1701 np->rx_ring.ex[i].buflow = 0;
1702 }
1703 np->rx_skb[i].skb = NULL;
1704 np->rx_skb[i].dma = 0;
1705 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001706}
1707
1708static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001710 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001712 np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
1713 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1714 np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
1715 else
1716 np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
1717 np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
1718 np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001719 np->tx_pkts_in_progress = 0;
1720 np->tx_change_owner = NULL;
1721 np->tx_end_flip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001723 for (i = 0; i < np->tx_ring_size; i++) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001724 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001725 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001726 np->tx_ring.orig[i].buf = 0;
1727 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001728 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001729 np->tx_ring.ex[i].txvlan = 0;
1730 np->tx_ring.ex[i].bufhigh = 0;
1731 np->tx_ring.ex[i].buflow = 0;
1732 }
1733 np->tx_skb[i].skb = NULL;
1734 np->tx_skb[i].dma = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001735 np->tx_skb[i].dma_len = 0;
1736 np->tx_skb[i].first_tx_desc = NULL;
1737 np->tx_skb[i].next_tx_ctx = NULL;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001738 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001739}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Manfred Sprauld81c0982005-07-31 18:20:30 +02001741static int nv_init_ring(struct net_device *dev)
1742{
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001743 struct fe_priv *np = netdev_priv(dev);
1744
Manfred Sprauld81c0982005-07-31 18:20:30 +02001745 nv_init_tx(dev);
1746 nv_init_rx(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001747 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1748 return nv_alloc_rx(dev);
1749 else
1750 return nv_alloc_rx_optimized(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001753static int nv_release_txskb(struct net_device *dev, struct nv_skb_map* tx_skb)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001754{
1755 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001756
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001757 if (tx_skb->dma) {
1758 pci_unmap_page(np->pci_dev, tx_skb->dma,
1759 tx_skb->dma_len,
Ayaz Abdullafa454592006-01-05 22:45:45 -08001760 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001761 tx_skb->dma = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001762 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001763 if (tx_skb->skb) {
1764 dev_kfree_skb_any(tx_skb->skb);
1765 tx_skb->skb = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001766 return 1;
1767 } else {
1768 return 0;
1769 }
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001770}
1771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772static void nv_drain_tx(struct net_device *dev)
1773{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001774 struct fe_priv *np = netdev_priv(dev);
1775 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001776
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001777 for (i = 0; i < np->tx_ring_size; i++) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001778 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001779 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001780 np->tx_ring.orig[i].buf = 0;
1781 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001782 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001783 np->tx_ring.ex[i].txvlan = 0;
1784 np->tx_ring.ex[i].bufhigh = 0;
1785 np->tx_ring.ex[i].buflow = 0;
1786 }
1787 if (nv_release_txskb(dev, &np->tx_skb[i]))
Jeff Garzik8148ff42007-10-16 20:56:09 -04001788 dev->stats.tx_dropped++;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001789 np->tx_skb[i].dma = 0;
1790 np->tx_skb[i].dma_len = 0;
1791 np->tx_skb[i].first_tx_desc = NULL;
1792 np->tx_skb[i].next_tx_ctx = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001794 np->tx_pkts_in_progress = 0;
1795 np->tx_change_owner = NULL;
1796 np->tx_end_flip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797}
1798
1799static void nv_drain_rx(struct net_device *dev)
1800{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001801 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001803
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001804 for (i = 0; i < np->rx_ring_size; i++) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001805 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001806 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001807 np->rx_ring.orig[i].buf = 0;
1808 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001809 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001810 np->rx_ring.ex[i].txvlan = 0;
1811 np->rx_ring.ex[i].bufhigh = 0;
1812 np->rx_ring.ex[i].buflow = 0;
1813 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 wmb();
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001815 if (np->rx_skb[i].skb) {
1816 pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001817 (skb_end_pointer(np->rx_skb[i].skb) -
1818 np->rx_skb[i].skb->data),
1819 PCI_DMA_FROMDEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001820 dev_kfree_skb(np->rx_skb[i].skb);
1821 np->rx_skb[i].skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 }
1823 }
1824}
1825
1826static void drain_ring(struct net_device *dev)
1827{
1828 nv_drain_tx(dev);
1829 nv_drain_rx(dev);
1830}
1831
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001832static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
1833{
1834 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
1835}
1836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837/*
1838 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07001839 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 */
1841static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1842{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001843 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001844 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001845 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
1846 unsigned int fragments = skb_shinfo(skb)->nr_frags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001847 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001848 u32 offset = 0;
1849 u32 bcnt;
1850 u32 size = skb->len-skb->data_len;
1851 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001852 u32 empty_slots;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001853 struct ring_desc* put_tx;
1854 struct ring_desc* start_tx;
1855 struct ring_desc* prev_tx;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001856 struct nv_skb_map* prev_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07001857 unsigned long flags;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001858
1859 /* add fragments to entries count */
1860 for (i = 0; i < fragments; i++) {
1861 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1862 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001865 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001866 if (unlikely(empty_slots <= entries)) {
Ingo Molnarbd6ca632008-03-28 14:41:30 -07001867 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001868 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001869 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07001870 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001871 return NETDEV_TX_BUSY;
1872 }
1873
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001874 start_tx = put_tx = np->put_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001875
Ayaz Abdullafa454592006-01-05 22:45:45 -08001876 /* setup the header buffer */
1877 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001878 prev_tx = put_tx;
1879 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001880 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001881 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
Ayaz Abdullafa454592006-01-05 22:45:45 -08001882 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001883 np->put_tx_ctx->dma_len = bcnt;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001884 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
1885 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001886
Ayaz Abdullafa454592006-01-05 22:45:45 -08001887 tx_flags = np->tx_flags;
1888 offset += bcnt;
1889 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001890 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001891 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001892 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001893 np->put_tx_ctx = np->first_tx_ctx;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001894 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001895
1896 /* setup the fragments */
1897 for (i = 0; i < fragments; i++) {
1898 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1899 u32 size = frag->size;
1900 offset = 0;
1901
1902 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001903 prev_tx = put_tx;
1904 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001905 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001906 np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
1907 PCI_DMA_TODEVICE);
1908 np->put_tx_ctx->dma_len = bcnt;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001909 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
1910 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001911
Ayaz Abdullafa454592006-01-05 22:45:45 -08001912 offset += bcnt;
1913 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001914 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001915 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001916 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001917 np->put_tx_ctx = np->first_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001918 } while (size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001919 }
1920
Ayaz Abdullafa454592006-01-05 22:45:45 -08001921 /* set last fragment flag */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001922 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001923
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001924 /* save skb in this slot's context area */
1925 prev_tx_ctx->skb = skb;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001926
Herbert Xu89114af2006-07-08 13:34:32 -07001927 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07001928 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02001929 else
Arjan van de Ven1d39ed52006-12-12 14:06:23 +01001930 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
Patrick McHardy84fa7932006-08-29 16:44:56 -07001931 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001932
Ingo Molnarbd6ca632008-03-28 14:41:30 -07001933 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05001934
Ayaz Abdullafa454592006-01-05 22:45:45 -08001935 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001936 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
1937 np->put_tx.orig = put_tx;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001938
Ingo Molnarbd6ca632008-03-28 14:41:30 -07001939 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001940
1941 dprintk(KERN_DEBUG "%s: nv_start_xmit: entries %d queued for transmission. tx_flags_extra: %x\n",
1942 dev->name, entries, tx_flags_extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 {
1944 int j;
1945 for (j=0; j<64; j++) {
1946 if ((j%16) == 0)
1947 dprintk("\n%03x:", j);
1948 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
1949 }
1950 dprintk("\n");
1951 }
1952
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 dev->trans_start = jiffies;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001954 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001955 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956}
1957
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001958static int nv_start_xmit_optimized(struct sk_buff *skb, struct net_device *dev)
1959{
1960 struct fe_priv *np = netdev_priv(dev);
1961 u32 tx_flags = 0;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001962 u32 tx_flags_extra;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001963 unsigned int fragments = skb_shinfo(skb)->nr_frags;
1964 unsigned int i;
1965 u32 offset = 0;
1966 u32 bcnt;
1967 u32 size = skb->len-skb->data_len;
1968 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1969 u32 empty_slots;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001970 struct ring_desc_ex* put_tx;
1971 struct ring_desc_ex* start_tx;
1972 struct ring_desc_ex* prev_tx;
1973 struct nv_skb_map* prev_tx_ctx;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001974 struct nv_skb_map* start_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07001975 unsigned long flags;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001976
1977 /* add fragments to entries count */
1978 for (i = 0; i < fragments; i++) {
1979 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1980 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1981 }
1982
1983 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05001984 if (unlikely(empty_slots <= entries)) {
Ingo Molnarbd6ca632008-03-28 14:41:30 -07001985 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001986 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001987 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07001988 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001989 return NETDEV_TX_BUSY;
1990 }
1991
1992 start_tx = put_tx = np->put_tx.ex;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001993 start_tx_ctx = np->put_tx_ctx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001994
1995 /* setup the header buffer */
1996 do {
1997 prev_tx = put_tx;
1998 prev_tx_ctx = np->put_tx_ctx;
1999 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2000 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
2001 PCI_DMA_TODEVICE);
2002 np->put_tx_ctx->dma_len = bcnt;
Al Viro5bb7ea22007-12-09 16:06:41 +00002003 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2004 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002005 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002006
2007 tx_flags = NV_TX2_VALID;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002008 offset += bcnt;
2009 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002010 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002011 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002012 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002013 np->put_tx_ctx = np->first_tx_ctx;
2014 } while (size);
2015
2016 /* setup the fragments */
2017 for (i = 0; i < fragments; i++) {
2018 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2019 u32 size = frag->size;
2020 offset = 0;
2021
2022 do {
2023 prev_tx = put_tx;
2024 prev_tx_ctx = np->put_tx_ctx;
2025 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2026 np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
2027 PCI_DMA_TODEVICE);
2028 np->put_tx_ctx->dma_len = bcnt;
Al Viro5bb7ea22007-12-09 16:06:41 +00002029 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2030 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002031 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002032
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002033 offset += bcnt;
2034 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002035 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002036 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002037 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002038 np->put_tx_ctx = np->first_tx_ctx;
2039 } while (size);
2040 }
2041
2042 /* set last fragment flag */
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002043 prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002044
2045 /* save skb in this slot's context area */
2046 prev_tx_ctx->skb = skb;
2047
2048 if (skb_is_gso(skb))
2049 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
2050 else
2051 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
2052 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
2053
2054 /* vlan tag */
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002055 if (likely(!np->vlangrp)) {
2056 start_tx->txvlan = 0;
2057 } else {
2058 if (vlan_tx_tag_present(skb))
2059 start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb));
2060 else
2061 start_tx->txvlan = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002062 }
2063
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002064 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002065
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002066 if (np->tx_limit) {
2067 /* Limit the number of outstanding tx. Setup all fragments, but
2068 * do not set the VALID bit on the first descriptor. Save a pointer
2069 * to that descriptor and also for next skb_map element.
2070 */
2071
2072 if (np->tx_pkts_in_progress == NV_TX_LIMIT_COUNT) {
2073 if (!np->tx_change_owner)
2074 np->tx_change_owner = start_tx_ctx;
2075
2076 /* remove VALID bit */
2077 tx_flags &= ~NV_TX2_VALID;
2078 start_tx_ctx->first_tx_desc = start_tx;
2079 start_tx_ctx->next_tx_ctx = np->put_tx_ctx;
2080 np->tx_end_flip = np->put_tx_ctx;
2081 } else {
2082 np->tx_pkts_in_progress++;
2083 }
2084 }
2085
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002086 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002087 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
2088 np->put_tx.ex = put_tx;
2089
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002090 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002091
2092 dprintk(KERN_DEBUG "%s: nv_start_xmit_optimized: entries %d queued for transmission. tx_flags_extra: %x\n",
2093 dev->name, entries, tx_flags_extra);
2094 {
2095 int j;
2096 for (j=0; j<64; j++) {
2097 if ((j%16) == 0)
2098 dprintk("\n%03x:", j);
2099 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
2100 }
2101 dprintk("\n");
2102 }
2103
2104 dev->trans_start = jiffies;
2105 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002106 return NETDEV_TX_OK;
2107}
2108
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002109static inline void nv_tx_flip_ownership(struct net_device *dev)
2110{
2111 struct fe_priv *np = netdev_priv(dev);
2112
2113 np->tx_pkts_in_progress--;
2114 if (np->tx_change_owner) {
2115 __le32 flaglen = le32_to_cpu(np->tx_change_owner->first_tx_desc->flaglen);
2116 flaglen |= NV_TX2_VALID;
2117 np->tx_change_owner->first_tx_desc->flaglen = cpu_to_le32(flaglen);
2118 np->tx_pkts_in_progress++;
2119
2120 np->tx_change_owner = np->tx_change_owner->next_tx_ctx;
2121 if (np->tx_change_owner == np->tx_end_flip)
2122 np->tx_change_owner = NULL;
2123
2124 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2125 }
2126}
2127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128/*
2129 * nv_tx_done: check for completed packets, release the skbs.
2130 *
2131 * Caller must own np->lock.
2132 */
2133static void nv_tx_done(struct net_device *dev)
2134{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002135 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002136 u32 flags;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002137 struct ring_desc* orig_get_tx = np->get_tx.orig;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002139 while ((np->get_tx.orig != np->put_tx.orig) &&
2140 !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002142 dprintk(KERN_DEBUG "%s: nv_tx_done: flags 0x%x.\n",
2143 dev->name, flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002144
2145 pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma,
2146 np->get_tx_ctx->dma_len,
2147 PCI_DMA_TODEVICE);
2148 np->get_tx_ctx->dma = 0;
2149
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002151 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002152 if (flags & NV_TX_ERROR) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002153 if (flags & NV_TX_UNDERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002154 dev->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002155 if (flags & NV_TX_CARRIERLOST)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002156 dev->stats.tx_carrier_errors++;
2157 dev->stats.tx_errors++;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002158 } else {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002159 dev->stats.tx_packets++;
2160 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002161 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002162 dev_kfree_skb_any(np->get_tx_ctx->skb);
2163 np->get_tx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 }
2165 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002166 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002167 if (flags & NV_TX2_ERROR) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002168 if (flags & NV_TX2_UNDERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002169 dev->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002170 if (flags & NV_TX2_CARRIERLOST)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002171 dev->stats.tx_carrier_errors++;
2172 dev->stats.tx_errors++;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002173 } else {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002174 dev->stats.tx_packets++;
2175 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002176 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002177 dev_kfree_skb_any(np->get_tx_ctx->skb);
2178 np->get_tx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 }
2180 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002181 if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002182 np->get_tx.orig = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002183 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002184 np->get_tx_ctx = np->first_tx_ctx;
2185 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002186 if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002187 np->tx_stop = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002188 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002189 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002190}
2191
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002192static void nv_tx_done_optimized(struct net_device *dev, int limit)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002193{
2194 struct fe_priv *np = netdev_priv(dev);
2195 u32 flags;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002196 struct ring_desc_ex* orig_get_tx = np->get_tx.ex;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002197
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002198 while ((np->get_tx.ex != np->put_tx.ex) &&
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002199 !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX_VALID) &&
2200 (limit-- > 0)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002201
2202 dprintk(KERN_DEBUG "%s: nv_tx_done_optimized: flags 0x%x.\n",
2203 dev->name, flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002204
2205 pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma,
2206 np->get_tx_ctx->dma_len,
2207 PCI_DMA_TODEVICE);
2208 np->get_tx_ctx->dma = 0;
2209
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002210 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla21828162007-01-23 12:27:21 -05002211 if (!(flags & NV_TX2_ERROR))
Jeff Garzik8148ff42007-10-16 20:56:09 -04002212 dev->stats.tx_packets++;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002213 dev_kfree_skb_any(np->get_tx_ctx->skb);
2214 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002215
2216 if (np->tx_limit) {
2217 nv_tx_flip_ownership(dev);
2218 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002219 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002220 if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002221 np->get_tx.ex = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002222 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002223 np->get_tx_ctx = np->first_tx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002225 if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002226 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
2231/*
2232 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07002233 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 */
2235static void nv_tx_timeout(struct net_device *dev)
2236{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002237 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002239 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002241 if (np->msi_flags & NV_MSI_X_ENABLED)
2242 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2243 else
2244 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2245
2246 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Manfred Spraulc2dba062005-07-31 18:29:47 +02002248 {
2249 int i;
2250
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002251 printk(KERN_INFO "%s: Ring at %lx\n",
2252 dev->name, (unsigned long)np->ring_addr);
Manfred Spraulc2dba062005-07-31 18:29:47 +02002253 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04002254 for (i=0;i<=np->register_size;i+= 32) {
Manfred Spraulc2dba062005-07-31 18:29:47 +02002255 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
2256 i,
2257 readl(base + i + 0), readl(base + i + 4),
2258 readl(base + i + 8), readl(base + i + 12),
2259 readl(base + i + 16), readl(base + i + 20),
2260 readl(base + i + 24), readl(base + i + 28));
2261 }
2262 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002263 for (i=0;i<np->tx_ring_size;i+= 4) {
Manfred Spraulee733622005-07-31 18:32:26 +02002264 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
2265 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002266 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002267 le32_to_cpu(np->tx_ring.orig[i].buf),
2268 le32_to_cpu(np->tx_ring.orig[i].flaglen),
2269 le32_to_cpu(np->tx_ring.orig[i+1].buf),
2270 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
2271 le32_to_cpu(np->tx_ring.orig[i+2].buf),
2272 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
2273 le32_to_cpu(np->tx_ring.orig[i+3].buf),
2274 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02002275 } else {
2276 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002277 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002278 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
2279 le32_to_cpu(np->tx_ring.ex[i].buflow),
2280 le32_to_cpu(np->tx_ring.ex[i].flaglen),
2281 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
2282 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
2283 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
2284 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
2285 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
2286 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
2287 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
2288 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
2289 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02002290 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02002291 }
2292 }
2293
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 spin_lock_irq(&np->lock);
2295
2296 /* 1) stop tx engine */
2297 nv_stop_tx(dev);
2298
2299 /* 2) check that the packets were not sent already: */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002300 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
2301 nv_tx_done(dev);
2302 else
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002303 nv_tx_done_optimized(dev, np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
2305 /* 3) if there are dead entries: clear everything */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002306 if (np->get_tx_ctx != np->put_tx_ctx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name);
2308 nv_drain_tx(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002309 nv_init_tx(dev);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002310 setup_hw_rings(dev, NV_SETUP_TX_RING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 }
2312
Ayaz Abdulla3ba4d092007-03-23 05:50:02 -05002313 netif_wake_queue(dev);
2314
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 /* 4) restart tx engine */
2316 nv_start_tx(dev);
2317 spin_unlock_irq(&np->lock);
2318}
2319
Manfred Spraul22c6d142005-04-19 21:17:09 +02002320/*
2321 * Called when the nic notices a mismatch between the actual data len on the
2322 * wire and the len indicated in the 802 header
2323 */
2324static int nv_getlen(struct net_device *dev, void *packet, int datalen)
2325{
2326 int hdrlen; /* length of the 802 header */
2327 int protolen; /* length as stored in the proto field */
2328
2329 /* 1) calculate len according to header */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002330 if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
Manfred Spraul22c6d142005-04-19 21:17:09 +02002331 protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto );
2332 hdrlen = VLAN_HLEN;
2333 } else {
2334 protolen = ntohs( ((struct ethhdr *)packet)->h_proto);
2335 hdrlen = ETH_HLEN;
2336 }
2337 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
2338 dev->name, datalen, protolen, hdrlen);
2339 if (protolen > ETH_DATA_LEN)
2340 return datalen; /* Value in proto field not a len, no checks possible */
2341
2342 protolen += hdrlen;
2343 /* consistency checks: */
2344 if (datalen > ETH_ZLEN) {
2345 if (datalen >= protolen) {
2346 /* more data on wire than in 802 header, trim of
2347 * additional data.
2348 */
2349 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2350 dev->name, protolen);
2351 return protolen;
2352 } else {
2353 /* less data on wire than mentioned in header.
2354 * Discard the packet.
2355 */
2356 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
2357 dev->name);
2358 return -1;
2359 }
2360 } else {
2361 /* short packet. Accept only if 802 values are also short */
2362 if (protolen > ETH_ZLEN) {
2363 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
2364 dev->name);
2365 return -1;
2366 }
2367 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2368 dev->name, datalen);
2369 return datalen;
2370 }
2371}
2372
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002373static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002375 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002376 u32 flags;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002377 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002378 struct sk_buff *skb;
2379 int len;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002380
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002381 while((np->get_rx.orig != np->put_rx.orig) &&
2382 !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002383 (rx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002385 dprintk(KERN_DEBUG "%s: nv_rx_process: flags 0x%x.\n",
2386 dev->name, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 /*
2389 * the packet is for us - immediately tear down the pci mapping.
2390 * TODO: check if a prefetch of the first cacheline improves
2391 * the performance.
2392 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002393 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2394 np->get_rx_ctx->dma_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 PCI_DMA_FROMDEVICE);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002396 skb = np->get_rx_ctx->skb;
2397 np->get_rx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
2399 {
2400 int j;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002401 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 for (j=0; j<64; j++) {
2403 if ((j%16) == 0)
2404 dprintk("\n%03x:", j);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002405 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 }
2407 dprintk("\n");
2408 }
2409 /* look at what we actually got: */
2410 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002411 if (likely(flags & NV_RX_DESCRIPTORVALID)) {
2412 len = flags & LEN_MASK_V1;
2413 if (unlikely(flags & NV_RX_ERROR)) {
2414 if (flags & NV_RX_ERROR4) {
2415 len = nv_getlen(dev, skb->data, len);
2416 if (len < 0) {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002417 dev->stats.rx_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002418 dev_kfree_skb(skb);
2419 goto next_pkt;
2420 }
2421 }
2422 /* framing errors are soft errors */
2423 else if (flags & NV_RX_FRAMINGERR) {
2424 if (flags & NV_RX_SUBSTRACT1) {
2425 len--;
2426 }
2427 }
2428 /* the rest are hard errors */
2429 else {
2430 if (flags & NV_RX_MISSEDFRAME)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002431 dev->stats.rx_missed_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002432 if (flags & NV_RX_CRCERR)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002433 dev->stats.rx_crc_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002434 if (flags & NV_RX_OVERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002435 dev->stats.rx_over_errors++;
2436 dev->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002437 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002438 goto next_pkt;
2439 }
2440 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002441 } else {
2442 dev_kfree_skb(skb);
2443 goto next_pkt;
Manfred Spraul22c6d142005-04-19 21:17:09 +02002444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 } else {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002446 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2447 len = flags & LEN_MASK_V2;
2448 if (unlikely(flags & NV_RX2_ERROR)) {
2449 if (flags & NV_RX2_ERROR4) {
2450 len = nv_getlen(dev, skb->data, len);
2451 if (len < 0) {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002452 dev->stats.rx_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002453 dev_kfree_skb(skb);
2454 goto next_pkt;
2455 }
2456 }
2457 /* framing errors are soft errors */
2458 else if (flags & NV_RX2_FRAMINGERR) {
2459 if (flags & NV_RX2_SUBSTRACT1) {
2460 len--;
2461 }
2462 }
2463 /* the rest are hard errors */
2464 else {
2465 if (flags & NV_RX2_CRCERR)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002466 dev->stats.rx_crc_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002467 if (flags & NV_RX2_OVERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002468 dev->stats.rx_over_errors++;
2469 dev->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002470 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002471 goto next_pkt;
2472 }
2473 }
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002474 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2475 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002476 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002477 } else {
2478 dev_kfree_skb(skb);
2479 goto next_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 }
2481 }
2482 /* got a valid packet - forward it to the network core */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 skb_put(skb, len);
2484 skb->protocol = eth_type_trans(skb, dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002485 dprintk(KERN_DEBUG "%s: nv_rx_process: %d bytes, proto %d accepted.\n",
2486 dev->name, len, skb->protocol);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002487#ifdef CONFIG_FORCEDETH_NAPI
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002488 netif_receive_skb(skb);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002489#else
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002490 netif_rx(skb);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002491#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 dev->last_rx = jiffies;
Jeff Garzik8148ff42007-10-16 20:56:09 -04002493 dev->stats.rx_packets++;
2494 dev->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002496 if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002497 np->get_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002498 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002499 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002500
2501 rx_work++;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002502 }
2503
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002504 return rx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002505}
2506
2507static int nv_rx_process_optimized(struct net_device *dev, int limit)
2508{
2509 struct fe_priv *np = netdev_priv(dev);
2510 u32 flags;
2511 u32 vlanflags = 0;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002512 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002513 struct sk_buff *skb;
2514 int len;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002515
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002516 while((np->get_rx.ex != np->put_rx.ex) &&
2517 !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
Ingo Molnarc1b71512007-10-17 12:18:23 +02002518 (rx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002519
2520 dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: flags 0x%x.\n",
2521 dev->name, flags);
2522
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002523 /*
2524 * the packet is for us - immediately tear down the pci mapping.
2525 * TODO: check if a prefetch of the first cacheline improves
2526 * the performance.
2527 */
2528 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2529 np->get_rx_ctx->dma_len,
2530 PCI_DMA_FROMDEVICE);
2531 skb = np->get_rx_ctx->skb;
2532 np->get_rx_ctx->skb = NULL;
2533
2534 {
2535 int j;
2536 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
2537 for (j=0; j<64; j++) {
2538 if ((j%16) == 0)
2539 dprintk("\n%03x:", j);
2540 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
2541 }
2542 dprintk("\n");
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002543 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002544 /* look at what we actually got: */
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002545 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2546 len = flags & LEN_MASK_V2;
2547 if (unlikely(flags & NV_RX2_ERROR)) {
2548 if (flags & NV_RX2_ERROR4) {
2549 len = nv_getlen(dev, skb->data, len);
2550 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002551 dev_kfree_skb(skb);
2552 goto next_pkt;
2553 }
2554 }
2555 /* framing errors are soft errors */
2556 else if (flags & NV_RX2_FRAMINGERR) {
2557 if (flags & NV_RX2_SUBSTRACT1) {
2558 len--;
2559 }
2560 }
2561 /* the rest are hard errors */
2562 else {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002563 dev_kfree_skb(skb);
2564 goto next_pkt;
2565 }
2566 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002567
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002568 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2569 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002570 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002571
2572 /* got a valid packet - forward it to the network core */
2573 skb_put(skb, len);
2574 skb->protocol = eth_type_trans(skb, dev);
2575 prefetch(skb->data);
2576
2577 dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: %d bytes, proto %d accepted.\n",
2578 dev->name, len, skb->protocol);
2579
2580 if (likely(!np->vlangrp)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002581#ifdef CONFIG_FORCEDETH_NAPI
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002582 netif_receive_skb(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002583#else
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002584 netif_rx(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002585#endif
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002586 } else {
2587 vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
2588 if (vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
2589#ifdef CONFIG_FORCEDETH_NAPI
2590 vlan_hwaccel_receive_skb(skb, np->vlangrp,
2591 vlanflags & NV_RX3_VLAN_TAG_MASK);
2592#else
2593 vlan_hwaccel_rx(skb, np->vlangrp,
2594 vlanflags & NV_RX3_VLAN_TAG_MASK);
2595#endif
2596 } else {
2597#ifdef CONFIG_FORCEDETH_NAPI
2598 netif_receive_skb(skb);
2599#else
2600 netif_rx(skb);
2601#endif
2602 }
2603 }
2604
2605 dev->last_rx = jiffies;
Jeff Garzik8148ff42007-10-16 20:56:09 -04002606 dev->stats.rx_packets++;
2607 dev->stats.rx_bytes += len;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002608 } else {
2609 dev_kfree_skb(skb);
2610 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002611next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002612 if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002613 np->get_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002614 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002615 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002616
2617 rx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002619
Ingo Molnarc1b71512007-10-17 12:18:23 +02002620 return rx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621}
2622
Manfred Sprauld81c0982005-07-31 18:20:30 +02002623static void set_bufsize(struct net_device *dev)
2624{
2625 struct fe_priv *np = netdev_priv(dev);
2626
2627 if (dev->mtu <= ETH_DATA_LEN)
2628 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
2629 else
2630 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
2631}
2632
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633/*
2634 * nv_change_mtu: dev->change_mtu function
2635 * Called with dev_base_lock held for read.
2636 */
2637static int nv_change_mtu(struct net_device *dev, int new_mtu)
2638{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002639 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002640 int old_mtu;
2641
2642 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002644
2645 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002647
2648 /* return early if the buffer sizes will not change */
2649 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
2650 return 0;
2651 if (old_mtu == new_mtu)
2652 return 0;
2653
2654 /* synchronized against open : rtnl_lock() held by caller */
2655 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002656 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002657 /*
2658 * It seems that the nic preloads valid ring entries into an
2659 * internal buffer. The procedure for flushing everything is
2660 * guessed, there is probably a simpler approach.
2661 * Changing the MTU is a rare event, it shouldn't matter.
2662 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002663 nv_disable_irq(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002664 netif_tx_lock_bh(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002665 spin_lock(&np->lock);
2666 /* stop engines */
2667 nv_stop_rx(dev);
2668 nv_stop_tx(dev);
2669 nv_txrx_reset(dev);
2670 /* drain rx queue */
2671 nv_drain_rx(dev);
2672 nv_drain_tx(dev);
2673 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002674 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002675 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02002676 if (!np->in_shutdown)
2677 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2678 }
2679 /* reinit nic view of the rx queue */
2680 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002681 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002682 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02002683 base + NvRegRingSizes);
2684 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002685 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002686 pci_push(base);
2687
2688 /* restart rx engine */
2689 nv_start_rx(dev);
2690 nv_start_tx(dev);
2691 spin_unlock(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002692 netif_tx_unlock_bh(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002693 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 return 0;
2696}
2697
Manfred Spraul72b31782005-07-31 18:33:34 +02002698static void nv_copy_mac_to_hw(struct net_device *dev)
2699{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002700 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002701 u32 mac[2];
2702
2703 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
2704 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
2705 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
2706
2707 writel(mac[0], base + NvRegMacAddrA);
2708 writel(mac[1], base + NvRegMacAddrB);
2709}
2710
2711/*
2712 * nv_set_mac_address: dev->set_mac_address function
2713 * Called with rtnl_lock() held.
2714 */
2715static int nv_set_mac_address(struct net_device *dev, void *addr)
2716{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002717 struct fe_priv *np = netdev_priv(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002718 struct sockaddr *macaddr = (struct sockaddr*)addr;
2719
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002720 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02002721 return -EADDRNOTAVAIL;
2722
2723 /* synchronized against open : rtnl_lock() held by caller */
2724 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
2725
2726 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07002727 netif_tx_lock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002728 spin_lock_irq(&np->lock);
2729
2730 /* stop rx engine */
2731 nv_stop_rx(dev);
2732
2733 /* set mac address */
2734 nv_copy_mac_to_hw(dev);
2735
2736 /* restart rx engine */
2737 nv_start_rx(dev);
2738 spin_unlock_irq(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002739 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002740 } else {
2741 nv_copy_mac_to_hw(dev);
2742 }
2743 return 0;
2744}
2745
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746/*
2747 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07002748 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 */
2750static void nv_set_multicast(struct net_device *dev)
2751{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002752 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 u8 __iomem *base = get_hwbase(dev);
2754 u32 addr[2];
2755 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002756 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
2758 memset(addr, 0, sizeof(addr));
2759 memset(mask, 0, sizeof(mask));
2760
2761 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002762 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002764 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765
2766 if (dev->flags & IFF_ALLMULTI || dev->mc_list) {
2767 u32 alwaysOff[2];
2768 u32 alwaysOn[2];
2769
2770 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
2771 if (dev->flags & IFF_ALLMULTI) {
2772 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
2773 } else {
2774 struct dev_mc_list *walk;
2775
2776 walk = dev->mc_list;
2777 while (walk != NULL) {
2778 u32 a, b;
Al Viro5bb7ea22007-12-09 16:06:41 +00002779 a = le32_to_cpu(*(__le32 *) walk->dmi_addr);
2780 b = le16_to_cpu(*(__le16 *) (&walk->dmi_addr[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 alwaysOn[0] &= a;
2782 alwaysOff[0] &= ~a;
2783 alwaysOn[1] &= b;
2784 alwaysOff[1] &= ~b;
2785 walk = walk->next;
2786 }
2787 }
2788 addr[0] = alwaysOn[0];
2789 addr[1] = alwaysOn[1];
2790 mask[0] = alwaysOn[0] | alwaysOff[0];
2791 mask[1] = alwaysOn[1] | alwaysOff[1];
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05002792 } else {
2793 mask[0] = NVREG_MCASTMASKA_NONE;
2794 mask[1] = NVREG_MCASTMASKB_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 }
2796 }
2797 addr[0] |= NVREG_MCASTADDRA_FORCE;
2798 pff |= NVREG_PFF_ALWAYS;
2799 spin_lock_irq(&np->lock);
2800 nv_stop_rx(dev);
2801 writel(addr[0], base + NvRegMulticastAddrA);
2802 writel(addr[1], base + NvRegMulticastAddrB);
2803 writel(mask[0], base + NvRegMulticastMaskA);
2804 writel(mask[1], base + NvRegMulticastMaskB);
2805 writel(pff, base + NvRegPacketFilterFlags);
2806 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
2807 dev->name);
2808 nv_start_rx(dev);
2809 spin_unlock_irq(&np->lock);
2810}
2811
Adrian Bunkc7985052006-06-22 12:03:29 +02002812static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002813{
2814 struct fe_priv *np = netdev_priv(dev);
2815 u8 __iomem *base = get_hwbase(dev);
2816
2817 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
2818
2819 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
2820 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
2821 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
2822 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
2823 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2824 } else {
2825 writel(pff, base + NvRegPacketFilterFlags);
2826 }
2827 }
2828 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
2829 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
2830 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05002831 u32 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V1;
2832 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V2)
2833 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V2;
2834 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)
2835 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V3;
2836 writel(pause_enable, base + NvRegTxPauseFrame);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002837 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
2838 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2839 } else {
2840 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
2841 writel(regmisc, base + NvRegMisc1);
2842 }
2843 }
2844}
2845
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002846/**
2847 * nv_update_linkspeed: Setup the MAC according to the link partner
2848 * @dev: Network device to be configured
2849 *
2850 * The function queries the PHY and checks if there is a link partner.
2851 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
2852 * set to 10 MBit HD.
2853 *
2854 * The function returns 0 if there is no link partner and 1 if there is
2855 * a good link partner.
2856 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857static int nv_update_linkspeed(struct net_device *dev)
2858{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002859 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002861 int adv = 0;
2862 int lpa = 0;
2863 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 int newls = np->linkspeed;
2865 int newdup = np->duplex;
2866 int mii_status;
2867 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002868 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Ayaz Abdullab2976d22008-02-04 15:13:59 -05002869 u32 txrxFlags = 0;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05002870 u32 phy_exp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871
2872 /* BMSR_LSTATUS is latched, read it twice:
2873 * we want the current value.
2874 */
2875 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2876 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2877
2878 if (!(mii_status & BMSR_LSTATUS)) {
2879 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
2880 dev->name);
2881 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2882 newdup = 0;
2883 retval = 0;
2884 goto set_speed;
2885 }
2886
2887 if (np->autoneg == 0) {
2888 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
2889 dev->name, np->fixed_mode);
2890 if (np->fixed_mode & LPA_100FULL) {
2891 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2892 newdup = 1;
2893 } else if (np->fixed_mode & LPA_100HALF) {
2894 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2895 newdup = 0;
2896 } else if (np->fixed_mode & LPA_10FULL) {
2897 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2898 newdup = 1;
2899 } else {
2900 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2901 newdup = 0;
2902 }
2903 retval = 1;
2904 goto set_speed;
2905 }
2906 /* check auto negotiation is complete */
2907 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
2908 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
2909 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2910 newdup = 0;
2911 retval = 0;
2912 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
2913 goto set_speed;
2914 }
2915
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002916 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2917 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
2918 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
2919 dev->name, adv, lpa);
2920
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 retval = 1;
2922 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002923 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
2924 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925
2926 if ((control_1000 & ADVERTISE_1000FULL) &&
2927 (status_1000 & LPA_1000FULL)) {
2928 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
2929 dev->name);
2930 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
2931 newdup = 1;
2932 goto set_speed;
2933 }
2934 }
2935
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002937 adv_lpa = lpa & adv;
2938 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2940 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002941 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2943 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002944 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2946 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002947 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2949 newdup = 0;
2950 } else {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002951 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, adv_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2953 newdup = 0;
2954 }
2955
2956set_speed:
2957 if (np->duplex == newdup && np->linkspeed == newls)
2958 return retval;
2959
2960 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
2961 dev->name, np->linkspeed, np->duplex, newls, newdup);
2962
2963 np->duplex = newdup;
2964 np->linkspeed = newls;
2965
Ayaz Abdullab2976d22008-02-04 15:13:59 -05002966 /* The transmitter and receiver must be restarted for safe update */
2967 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
2968 txrxFlags |= NV_RESTART_TX;
2969 nv_stop_tx(dev);
2970 }
2971 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
2972 txrxFlags |= NV_RESTART_RX;
2973 nv_stop_rx(dev);
2974 }
2975
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 if (np->gigabit == PHY_GIGABIT) {
2977 phyreg = readl(base + NvRegRandomSeed);
2978 phyreg &= ~(0x3FF00);
2979 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
2980 phyreg |= NVREG_RNDSEED_FORCE3;
2981 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
2982 phyreg |= NVREG_RNDSEED_FORCE2;
2983 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
2984 phyreg |= NVREG_RNDSEED_FORCE;
2985 writel(phyreg, base + NvRegRandomSeed);
2986 }
2987
2988 phyreg = readl(base + NvRegPhyInterface);
2989 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
2990 if (np->duplex == 0)
2991 phyreg |= PHY_HALF;
2992 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
2993 phyreg |= PHY_100;
2994 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2995 phyreg |= PHY_1000;
2996 writel(phyreg, base + NvRegPhyInterface);
2997
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05002998 phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002999 if (phyreg & PHY_RGMII) {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003000 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) {
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003001 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003002 } else {
3003 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) {
3004 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10)
3005 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10;
3006 else
3007 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100;
3008 } else {
3009 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3010 }
3011 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003012 } else {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003013 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX))
3014 txreg = NVREG_TX_DEFERRAL_MII_STRETCH;
3015 else
3016 txreg = NVREG_TX_DEFERRAL_DEFAULT;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003017 }
3018 writel(txreg, base + NvRegTxDeferral);
3019
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04003020 if (np->desc_ver == DESC_VER_1) {
3021 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3022 } else {
3023 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3024 txreg = NVREG_TX_WM_DESC2_3_1000;
3025 else
3026 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3027 }
3028 writel(txreg, base + NvRegTxWatermark);
3029
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
3031 base + NvRegMisc1);
3032 pci_push(base);
3033 writel(np->linkspeed, base + NvRegLinkSpeed);
3034 pci_push(base);
3035
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003036 pause_flags = 0;
3037 /* setup pause frame */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003038 if (np->duplex != 0) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003039 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
3040 adv_pause = adv & (ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM);
3041 lpa_pause = lpa & (LPA_PAUSE_CAP| LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003042
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003043 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003044 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003045 if (lpa_pause & LPA_PAUSE_CAP) {
3046 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3047 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3048 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3049 }
3050 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003051 case ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003052 if (lpa_pause == (LPA_PAUSE_CAP| LPA_PAUSE_ASYM))
3053 {
3054 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3055 }
3056 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003057 case ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003058 if (lpa_pause & LPA_PAUSE_CAP)
3059 {
3060 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3061 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3062 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3063 }
3064 if (lpa_pause == LPA_PAUSE_ASYM)
3065 {
3066 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3067 }
3068 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003069 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003070 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003071 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003072 }
3073 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003074 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003075
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003076 if (txrxFlags & NV_RESTART_TX)
3077 nv_start_tx(dev);
3078 if (txrxFlags & NV_RESTART_RX)
3079 nv_start_rx(dev);
3080
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 return retval;
3082}
3083
3084static void nv_linkchange(struct net_device *dev)
3085{
3086 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003087 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 netif_carrier_on(dev);
3089 printk(KERN_INFO "%s: link up.\n", dev->name);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003090 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 } else {
3093 if (netif_carrier_ok(dev)) {
3094 netif_carrier_off(dev);
3095 printk(KERN_INFO "%s: link down.\n", dev->name);
3096 nv_stop_rx(dev);
3097 }
3098 }
3099}
3100
3101static void nv_link_irq(struct net_device *dev)
3102{
3103 u8 __iomem *base = get_hwbase(dev);
3104 u32 miistat;
3105
3106 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05003107 writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
3109
3110 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
3111 nv_linkchange(dev);
3112 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
3113}
3114
David Howells7d12e782006-10-05 14:55:46 +01003115static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116{
3117 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003118 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 u8 __iomem *base = get_hwbase(dev);
3120 u32 events;
3121 int i;
3122
3123 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
3124
3125 for (i=0; ; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003126 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3127 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3128 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3129 } else {
3130 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3131 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3134 if (!(events & np->irqmask))
3135 break;
3136
Ayaz Abdullaa971c322005-11-11 08:30:38 -05003137 spin_lock(&np->lock);
3138 nv_tx_done(dev);
3139 spin_unlock(&np->lock);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003140
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003141#ifdef CONFIG_FORCEDETH_NAPI
3142 if (events & NVREG_IRQ_RX_ALL) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003143 netif_rx_schedule(dev, &np->napi);
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003144
3145 /* Disable furthur receive irq's */
3146 spin_lock(&np->lock);
3147 np->irqmask &= ~NVREG_IRQ_RX_ALL;
3148
3149 if (np->msi_flags & NV_MSI_X_ENABLED)
3150 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3151 else
3152 writel(np->irqmask, base + NvRegIrqMask);
3153 spin_unlock(&np->lock);
3154 }
3155#else
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003156 if (nv_rx_process(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003157 if (unlikely(nv_alloc_rx(dev))) {
3158 spin_lock(&np->lock);
3159 if (!np->in_shutdown)
3160 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3161 spin_unlock(&np->lock);
3162 }
3163 }
3164#endif
3165 if (unlikely(events & NVREG_IRQ_LINK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 spin_lock(&np->lock);
3167 nv_link_irq(dev);
3168 spin_unlock(&np->lock);
3169 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003170 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 spin_lock(&np->lock);
3172 nv_linkchange(dev);
3173 spin_unlock(&np->lock);
3174 np->link_timeout = jiffies + LINK_TIMEOUT;
3175 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003176 if (unlikely(events & (NVREG_IRQ_TX_ERR))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
3178 dev->name, events);
3179 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003180 if (unlikely(events & (NVREG_IRQ_UNKNOWN))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
3182 dev->name, events);
3183 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003184 if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) {
3185 spin_lock(&np->lock);
3186 /* disable interrupts on the nic */
3187 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3188 writel(0, base + NvRegIrqMask);
3189 else
3190 writel(np->irqmask, base + NvRegIrqMask);
3191 pci_push(base);
3192
3193 if (!np->in_shutdown) {
3194 np->nic_poll_irq = np->irqmask;
3195 np->recover_error = 1;
3196 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3197 }
3198 spin_unlock(&np->lock);
3199 break;
3200 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003201 if (unlikely(i > max_interrupt_work)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 spin_lock(&np->lock);
3203 /* disable interrupts on the nic */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003204 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3205 writel(0, base + NvRegIrqMask);
3206 else
3207 writel(np->irqmask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 pci_push(base);
3209
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003210 if (!np->in_shutdown) {
3211 np->nic_poll_irq = np->irqmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 spin_unlock(&np->lock);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003215 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 break;
3217 }
3218
3219 }
3220 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
3221
3222 return IRQ_RETVAL(i);
3223}
3224
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003225/**
3226 * All _optimized functions are used to help increase performance
3227 * (reduce CPU and increase throughput). They use descripter version 3,
3228 * compiler directives, and reduce memory accesses.
3229 */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003230static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
3231{
3232 struct net_device *dev = (struct net_device *) data;
3233 struct fe_priv *np = netdev_priv(dev);
3234 u8 __iomem *base = get_hwbase(dev);
3235 u32 events;
3236 int i;
3237
3238 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized\n", dev->name);
3239
3240 for (i=0; ; i++) {
3241 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3242 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3243 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3244 } else {
3245 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3246 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3247 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003248 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3249 if (!(events & np->irqmask))
3250 break;
3251
3252 spin_lock(&np->lock);
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003253 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003254 spin_unlock(&np->lock);
3255
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003256#ifdef CONFIG_FORCEDETH_NAPI
3257 if (events & NVREG_IRQ_RX_ALL) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003258 netif_rx_schedule(dev, &np->napi);
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003259
3260 /* Disable furthur receive irq's */
3261 spin_lock(&np->lock);
3262 np->irqmask &= ~NVREG_IRQ_RX_ALL;
3263
3264 if (np->msi_flags & NV_MSI_X_ENABLED)
3265 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3266 else
3267 writel(np->irqmask, base + NvRegIrqMask);
3268 spin_unlock(&np->lock);
3269 }
3270#else
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003271 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003272 if (unlikely(nv_alloc_rx_optimized(dev))) {
3273 spin_lock(&np->lock);
3274 if (!np->in_shutdown)
3275 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3276 spin_unlock(&np->lock);
3277 }
3278 }
3279#endif
3280 if (unlikely(events & NVREG_IRQ_LINK)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003281 spin_lock(&np->lock);
3282 nv_link_irq(dev);
3283 spin_unlock(&np->lock);
3284 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003285 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003286 spin_lock(&np->lock);
3287 nv_linkchange(dev);
3288 spin_unlock(&np->lock);
3289 np->link_timeout = jiffies + LINK_TIMEOUT;
3290 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003291 if (unlikely(events & (NVREG_IRQ_TX_ERR))) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003292 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
3293 dev->name, events);
3294 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003295 if (unlikely(events & (NVREG_IRQ_UNKNOWN))) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003296 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
3297 dev->name, events);
3298 }
3299 if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) {
3300 spin_lock(&np->lock);
3301 /* disable interrupts on the nic */
3302 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3303 writel(0, base + NvRegIrqMask);
3304 else
3305 writel(np->irqmask, base + NvRegIrqMask);
3306 pci_push(base);
3307
3308 if (!np->in_shutdown) {
3309 np->nic_poll_irq = np->irqmask;
3310 np->recover_error = 1;
3311 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3312 }
3313 spin_unlock(&np->lock);
3314 break;
3315 }
3316
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003317 if (unlikely(i > max_interrupt_work)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003318 spin_lock(&np->lock);
3319 /* disable interrupts on the nic */
3320 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3321 writel(0, base + NvRegIrqMask);
3322 else
3323 writel(np->irqmask, base + NvRegIrqMask);
3324 pci_push(base);
3325
3326 if (!np->in_shutdown) {
3327 np->nic_poll_irq = np->irqmask;
3328 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3329 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003330 spin_unlock(&np->lock);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003331 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003332 break;
3333 }
3334
3335 }
3336 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized completed\n", dev->name);
3337
3338 return IRQ_RETVAL(i);
3339}
3340
David Howells7d12e782006-10-05 14:55:46 +01003341static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003342{
3343 struct net_device *dev = (struct net_device *) data;
3344 struct fe_priv *np = netdev_priv(dev);
3345 u8 __iomem *base = get_hwbase(dev);
3346 u32 events;
3347 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003348 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003349
3350 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
3351
3352 for (i=0; ; i++) {
3353 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
3354 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003355 dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
3356 if (!(events & np->irqmask))
3357 break;
3358
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003359 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003360 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003361 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003362
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003363 if (unlikely(events & (NVREG_IRQ_TX_ERR))) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003364 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
3365 dev->name, events);
3366 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003367 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003368 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003369 /* disable interrupts on the nic */
3370 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
3371 pci_push(base);
3372
3373 if (!np->in_shutdown) {
3374 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
3375 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3376 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003377 spin_unlock_irqrestore(&np->lock, flags);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003378 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003379 break;
3380 }
3381
3382 }
3383 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
3384
3385 return IRQ_RETVAL(i);
3386}
3387
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003388#ifdef CONFIG_FORCEDETH_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003389static int nv_napi_poll(struct napi_struct *napi, int budget)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003390{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003391 struct fe_priv *np = container_of(napi, struct fe_priv, napi);
3392 struct net_device *dev = np->dev;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003393 u8 __iomem *base = get_hwbase(dev);
Francois Romieud15e9c42006-12-17 23:03:15 +01003394 unsigned long flags;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003395 int pkts, retcode;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003396
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003397 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003398 pkts = nv_rx_process(dev, budget);
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003399 retcode = nv_alloc_rx(dev);
3400 } else {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003401 pkts = nv_rx_process_optimized(dev, budget);
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003402 retcode = nv_alloc_rx_optimized(dev);
3403 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003404
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003405 if (retcode) {
Francois Romieud15e9c42006-12-17 23:03:15 +01003406 spin_lock_irqsave(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003407 if (!np->in_shutdown)
3408 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Francois Romieud15e9c42006-12-17 23:03:15 +01003409 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003410 }
3411
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003412 if (pkts < budget) {
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003413 /* re-enable receive interrupts */
Francois Romieud15e9c42006-12-17 23:03:15 +01003414 spin_lock_irqsave(&np->lock, flags);
3415
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003416 __netif_rx_complete(dev, napi);
3417
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003418 np->irqmask |= NVREG_IRQ_RX_ALL;
3419 if (np->msi_flags & NV_MSI_X_ENABLED)
3420 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3421 else
3422 writel(np->irqmask, base + NvRegIrqMask);
Francois Romieud15e9c42006-12-17 23:03:15 +01003423
3424 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003425 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003426 return pkts;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003427}
3428#endif
3429
3430#ifdef CONFIG_FORCEDETH_NAPI
David Howells7d12e782006-10-05 14:55:46 +01003431static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003432{
3433 struct net_device *dev = (struct net_device *) data;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003434 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003435 u8 __iomem *base = get_hwbase(dev);
3436 u32 events;
3437
3438 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
3439 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
3440
3441 if (events) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003442 netif_rx_schedule(dev, &np->napi);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003443 /* disable receive interrupts on the nic */
3444 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3445 pci_push(base);
3446 }
3447 return IRQ_HANDLED;
3448}
3449#else
David Howells7d12e782006-10-05 14:55:46 +01003450static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003451{
3452 struct net_device *dev = (struct net_device *) data;
3453 struct fe_priv *np = netdev_priv(dev);
3454 u8 __iomem *base = get_hwbase(dev);
3455 u32 events;
3456 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003457 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003458
3459 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name);
3460
3461 for (i=0; ; i++) {
3462 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
3463 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003464 dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
3465 if (!(events & np->irqmask))
3466 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003467
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003468 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003469 if (unlikely(nv_alloc_rx_optimized(dev))) {
3470 spin_lock_irqsave(&np->lock, flags);
3471 if (!np->in_shutdown)
3472 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3473 spin_unlock_irqrestore(&np->lock, flags);
3474 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003475 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003476
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003477 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003478 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003479 /* disable interrupts on the nic */
3480 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3481 pci_push(base);
3482
3483 if (!np->in_shutdown) {
3484 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
3485 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3486 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003487 spin_unlock_irqrestore(&np->lock, flags);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003488 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003489 break;
3490 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003491 }
3492 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
3493
3494 return IRQ_RETVAL(i);
3495}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003496#endif
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003497
David Howells7d12e782006-10-05 14:55:46 +01003498static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003499{
3500 struct net_device *dev = (struct net_device *) data;
3501 struct fe_priv *np = netdev_priv(dev);
3502 u8 __iomem *base = get_hwbase(dev);
3503 u32 events;
3504 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003505 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003506
3507 dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
3508
3509 for (i=0; ; i++) {
3510 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
3511 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003512 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3513 if (!(events & np->irqmask))
3514 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003515
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003516 /* check tx in case we reached max loop limit in tx isr */
3517 spin_lock_irqsave(&np->lock, flags);
3518 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3519 spin_unlock_irqrestore(&np->lock, flags);
3520
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003521 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003522 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003523 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003524 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003525 }
3526 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003527 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003528 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003529 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003530 np->link_timeout = jiffies + LINK_TIMEOUT;
3531 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003532 if (events & NVREG_IRQ_RECOVER_ERROR) {
3533 spin_lock_irq(&np->lock);
3534 /* disable interrupts on the nic */
3535 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3536 pci_push(base);
3537
3538 if (!np->in_shutdown) {
3539 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3540 np->recover_error = 1;
3541 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3542 }
3543 spin_unlock_irq(&np->lock);
3544 break;
3545 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003546 if (events & (NVREG_IRQ_UNKNOWN)) {
3547 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
3548 dev->name, events);
3549 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003550 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003551 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003552 /* disable interrupts on the nic */
3553 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3554 pci_push(base);
3555
3556 if (!np->in_shutdown) {
3557 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3558 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3559 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003560 spin_unlock_irqrestore(&np->lock, flags);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003561 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003562 break;
3563 }
3564
3565 }
3566 dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
3567
3568 return IRQ_RETVAL(i);
3569}
3570
David Howells7d12e782006-10-05 14:55:46 +01003571static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003572{
3573 struct net_device *dev = (struct net_device *) data;
3574 struct fe_priv *np = netdev_priv(dev);
3575 u8 __iomem *base = get_hwbase(dev);
3576 u32 events;
3577
3578 dprintk(KERN_DEBUG "%s: nv_nic_irq_test\n", dev->name);
3579
3580 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3581 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3582 writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus);
3583 } else {
3584 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3585 writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
3586 }
3587 pci_push(base);
3588 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3589 if (!(events & NVREG_IRQ_TIMER))
3590 return IRQ_RETVAL(0);
3591
3592 spin_lock(&np->lock);
3593 np->intr_test = 1;
3594 spin_unlock(&np->lock);
3595
3596 dprintk(KERN_DEBUG "%s: nv_nic_irq_test completed\n", dev->name);
3597
3598 return IRQ_RETVAL(1);
3599}
3600
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003601static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
3602{
3603 u8 __iomem *base = get_hwbase(dev);
3604 int i;
3605 u32 msixmap = 0;
3606
3607 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
3608 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
3609 * the remaining 8 interrupts.
3610 */
3611 for (i = 0; i < 8; i++) {
3612 if ((irqmask >> i) & 0x1) {
3613 msixmap |= vector << (i << 2);
3614 }
3615 }
3616 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
3617
3618 msixmap = 0;
3619 for (i = 0; i < 8; i++) {
3620 if ((irqmask >> (i + 8)) & 0x1) {
3621 msixmap |= vector << (i << 2);
3622 }
3623 }
3624 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
3625}
3626
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003627static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003628{
3629 struct fe_priv *np = get_nvpriv(dev);
3630 u8 __iomem *base = get_hwbase(dev);
3631 int ret = 1;
3632 int i;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003633 irqreturn_t (*handler)(int foo, void *data);
3634
3635 if (intr_test) {
3636 handler = nv_nic_irq_test;
3637 } else {
3638 if (np->desc_ver == DESC_VER_3)
3639 handler = nv_nic_irq_optimized;
3640 else
3641 handler = nv_nic_irq;
3642 }
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003643
3644 if (np->msi_flags & NV_MSI_X_CAPABLE) {
3645 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
3646 np->msi_x_entry[i].entry = i;
3647 }
3648 if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) {
3649 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003650 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003651 /* Request irq for rx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07003652 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 -04003653 printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret);
3654 pci_disable_msix(np->pci_dev);
3655 np->msi_flags &= ~NV_MSI_X_ENABLED;
3656 goto out_err;
3657 }
3658 /* Request irq for tx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07003659 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 -04003660 printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret);
3661 pci_disable_msix(np->pci_dev);
3662 np->msi_flags &= ~NV_MSI_X_ENABLED;
3663 goto out_free_rx;
3664 }
3665 /* Request irq for link and timer handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07003666 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 -04003667 printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret);
3668 pci_disable_msix(np->pci_dev);
3669 np->msi_flags &= ~NV_MSI_X_ENABLED;
3670 goto out_free_tx;
3671 }
3672 /* map interrupts to their respective vector */
3673 writel(0, base + NvRegMSIXMap0);
3674 writel(0, base + NvRegMSIXMap1);
3675 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
3676 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
3677 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
3678 } else {
3679 /* Request irq for all interrupts */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003680 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 -04003681 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
3682 pci_disable_msix(np->pci_dev);
3683 np->msi_flags &= ~NV_MSI_X_ENABLED;
3684 goto out_err;
3685 }
3686
3687 /* map interrupts to vector 0 */
3688 writel(0, base + NvRegMSIXMap0);
3689 writel(0, base + NvRegMSIXMap1);
3690 }
3691 }
3692 }
3693 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
3694 if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
3695 np->msi_flags |= NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003696 dev->irq = np->pci_dev->irq;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003697 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003698 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
3699 pci_disable_msi(np->pci_dev);
3700 np->msi_flags &= ~NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003701 dev->irq = np->pci_dev->irq;
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003702 goto out_err;
3703 }
3704
3705 /* map interrupts to vector 0 */
3706 writel(0, base + NvRegMSIMap0);
3707 writel(0, base + NvRegMSIMap1);
3708 /* enable msi vector 0 */
3709 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3710 }
3711 }
3712 if (ret != 0) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003713 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003714 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003715
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003716 }
3717
3718 return 0;
3719out_free_tx:
3720 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
3721out_free_rx:
3722 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
3723out_err:
3724 return 1;
3725}
3726
3727static void nv_free_irq(struct net_device *dev)
3728{
3729 struct fe_priv *np = get_nvpriv(dev);
3730 int i;
3731
3732 if (np->msi_flags & NV_MSI_X_ENABLED) {
3733 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
3734 free_irq(np->msi_x_entry[i].vector, dev);
3735 }
3736 pci_disable_msix(np->pci_dev);
3737 np->msi_flags &= ~NV_MSI_X_ENABLED;
3738 } else {
3739 free_irq(np->pci_dev->irq, dev);
3740 if (np->msi_flags & NV_MSI_ENABLED) {
3741 pci_disable_msi(np->pci_dev);
3742 np->msi_flags &= ~NV_MSI_ENABLED;
3743 }
3744 }
3745}
3746
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747static void nv_do_nic_poll(unsigned long data)
3748{
3749 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003750 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003752 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 /*
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003755 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 * reenable interrupts on the nic, we have to do this before calling
3757 * nv_nic_irq because that may decide to do otherwise
3758 */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003759
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003760 if (!using_multi_irqs(dev)) {
3761 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003762 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003763 else
Manfred Spraula7475902007-10-17 21:52:33 +02003764 disable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003765 mask = np->irqmask;
3766 } else {
3767 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003768 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003769 mask |= NVREG_IRQ_RX_ALL;
3770 }
3771 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003772 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003773 mask |= NVREG_IRQ_TX_ALL;
3774 }
3775 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003776 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003777 mask |= NVREG_IRQ_OTHER;
3778 }
3779 }
3780 np->nic_poll_irq = 0;
3781
Manfred Spraula7475902007-10-17 21:52:33 +02003782 /* disable_irq() contains synchronize_irq, thus no irq handler can run now */
3783
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003784 if (np->recover_error) {
3785 np->recover_error = 0;
3786 printk(KERN_INFO "forcedeth: MAC in recoverable error state\n");
3787 if (netif_running(dev)) {
3788 netif_tx_lock_bh(dev);
3789 spin_lock(&np->lock);
3790 /* stop engines */
3791 nv_stop_rx(dev);
3792 nv_stop_tx(dev);
3793 nv_txrx_reset(dev);
3794 /* drain rx queue */
3795 nv_drain_rx(dev);
3796 nv_drain_tx(dev);
3797 /* reinit driver view of the rx queue */
3798 set_bufsize(dev);
3799 if (nv_init_ring(dev)) {
3800 if (!np->in_shutdown)
3801 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3802 }
3803 /* reinit nic view of the rx queue */
3804 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3805 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3806 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3807 base + NvRegRingSizes);
3808 pci_push(base);
3809 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3810 pci_push(base);
3811
3812 /* restart rx engine */
3813 nv_start_rx(dev);
3814 nv_start_tx(dev);
3815 spin_unlock(&np->lock);
3816 netif_tx_unlock_bh(dev);
3817 }
3818 }
3819
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003820
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003821 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 pci_push(base);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003823
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003824 if (!using_multi_irqs(dev)) {
Ayaz Abdullafcc5f262007-03-23 05:49:37 -05003825 if (np->desc_ver == DESC_VER_3)
3826 nv_nic_irq_optimized(0, dev);
3827 else
3828 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003829 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003830 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003831 else
Manfred Spraula7475902007-10-17 21:52:33 +02003832 enable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003833 } else {
3834 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01003835 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003836 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003837 }
3838 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01003839 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003840 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003841 }
3842 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
David Howells7d12e782006-10-05 14:55:46 +01003843 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003844 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003845 }
3846 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847}
3848
Michal Schmidt2918c352005-05-12 19:42:06 -04003849#ifdef CONFIG_NET_POLL_CONTROLLER
3850static void nv_poll_controller(struct net_device *dev)
3851{
3852 nv_do_nic_poll((unsigned long) dev);
3853}
3854#endif
3855
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003856static void nv_do_stats_poll(unsigned long data)
3857{
3858 struct net_device *dev = (struct net_device *) data;
3859 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003860
Ayaz Abdulla57fff692007-01-23 12:27:00 -05003861 nv_get_hw_stats(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003862
3863 if (!np->in_shutdown)
3864 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
3865}
3866
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
3868{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003869 struct fe_priv *np = netdev_priv(dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04003870 strcpy(info->driver, DRV_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 strcpy(info->version, FORCEDETH_VERSION);
3872 strcpy(info->bus_info, pci_name(np->pci_dev));
3873}
3874
3875static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3876{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003877 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878 wolinfo->supported = WAKE_MAGIC;
3879
3880 spin_lock_irq(&np->lock);
3881 if (np->wolenabled)
3882 wolinfo->wolopts = WAKE_MAGIC;
3883 spin_unlock_irq(&np->lock);
3884}
3885
3886static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3887{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003888 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003890 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003894 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003896 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003898 if (netif_running(dev)) {
3899 spin_lock_irq(&np->lock);
3900 writel(flags, base + NvRegWakeUpFlags);
3901 spin_unlock_irq(&np->lock);
3902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 return 0;
3904}
3905
3906static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3907{
3908 struct fe_priv *np = netdev_priv(dev);
3909 int adv;
3910
3911 spin_lock_irq(&np->lock);
3912 ecmd->port = PORT_MII;
3913 if (!netif_running(dev)) {
3914 /* We do not track link speed / duplex setting if the
3915 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003916 if (nv_update_linkspeed(dev)) {
3917 if (!netif_carrier_ok(dev))
3918 netif_carrier_on(dev);
3919 } else {
3920 if (netif_carrier_ok(dev))
3921 netif_carrier_off(dev);
3922 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003924
3925 if (netif_carrier_ok(dev)) {
3926 switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 case NVREG_LINKSPEED_10:
3928 ecmd->speed = SPEED_10;
3929 break;
3930 case NVREG_LINKSPEED_100:
3931 ecmd->speed = SPEED_100;
3932 break;
3933 case NVREG_LINKSPEED_1000:
3934 ecmd->speed = SPEED_1000;
3935 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003936 }
3937 ecmd->duplex = DUPLEX_HALF;
3938 if (np->duplex)
3939 ecmd->duplex = DUPLEX_FULL;
3940 } else {
3941 ecmd->speed = -1;
3942 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944
3945 ecmd->autoneg = np->autoneg;
3946
3947 ecmd->advertising = ADVERTISED_MII;
3948 if (np->autoneg) {
3949 ecmd->advertising |= ADVERTISED_Autoneg;
3950 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003951 if (adv & ADVERTISE_10HALF)
3952 ecmd->advertising |= ADVERTISED_10baseT_Half;
3953 if (adv & ADVERTISE_10FULL)
3954 ecmd->advertising |= ADVERTISED_10baseT_Full;
3955 if (adv & ADVERTISE_100HALF)
3956 ecmd->advertising |= ADVERTISED_100baseT_Half;
3957 if (adv & ADVERTISE_100FULL)
3958 ecmd->advertising |= ADVERTISED_100baseT_Full;
3959 if (np->gigabit == PHY_GIGABIT) {
3960 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3961 if (adv & ADVERTISE_1000FULL)
3962 ecmd->advertising |= ADVERTISED_1000baseT_Full;
3963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 ecmd->supported = (SUPPORTED_Autoneg |
3966 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
3967 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
3968 SUPPORTED_MII);
3969 if (np->gigabit == PHY_GIGABIT)
3970 ecmd->supported |= SUPPORTED_1000baseT_Full;
3971
3972 ecmd->phy_address = np->phyaddr;
3973 ecmd->transceiver = XCVR_EXTERNAL;
3974
3975 /* ignore maxtxpkt, maxrxpkt for now */
3976 spin_unlock_irq(&np->lock);
3977 return 0;
3978}
3979
3980static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3981{
3982 struct fe_priv *np = netdev_priv(dev);
3983
3984 if (ecmd->port != PORT_MII)
3985 return -EINVAL;
3986 if (ecmd->transceiver != XCVR_EXTERNAL)
3987 return -EINVAL;
3988 if (ecmd->phy_address != np->phyaddr) {
3989 /* TODO: support switching between multiple phys. Should be
3990 * trivial, but not enabled due to lack of test hardware. */
3991 return -EINVAL;
3992 }
3993 if (ecmd->autoneg == AUTONEG_ENABLE) {
3994 u32 mask;
3995
3996 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
3997 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
3998 if (np->gigabit == PHY_GIGABIT)
3999 mask |= ADVERTISED_1000baseT_Full;
4000
4001 if ((ecmd->advertising & mask) == 0)
4002 return -EINVAL;
4003
4004 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
4005 /* Note: autonegotiation disable, speed 1000 intentionally
4006 * forbidden - noone should need that. */
4007
4008 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
4009 return -EINVAL;
4010 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
4011 return -EINVAL;
4012 } else {
4013 return -EINVAL;
4014 }
4015
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004016 netif_carrier_off(dev);
4017 if (netif_running(dev)) {
4018 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004019 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004020 spin_lock(&np->lock);
4021 /* stop engines */
4022 nv_stop_rx(dev);
4023 nv_stop_tx(dev);
4024 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004025 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004026 }
4027
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 if (ecmd->autoneg == AUTONEG_ENABLE) {
4029 int adv, bmcr;
4030
4031 np->autoneg = 1;
4032
4033 /* advertise only what has been requested */
4034 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004035 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 if (ecmd->advertising & ADVERTISED_10baseT_Half)
4037 adv |= ADVERTISE_10HALF;
4038 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004039 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 if (ecmd->advertising & ADVERTISED_100baseT_Half)
4041 adv |= ADVERTISE_100HALF;
4042 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004043 adv |= ADVERTISE_100FULL;
4044 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
4045 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4046 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4047 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4049
4050 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004051 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 adv &= ~ADVERTISE_1000FULL;
4053 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
4054 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004055 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 }
4057
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004058 if (netif_running(dev))
4059 printk(KERN_INFO "%s: link down.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004061 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4062 bmcr |= BMCR_ANENABLE;
4063 /* reset the phy in order for settings to stick,
4064 * and cause autoneg to start */
4065 if (phy_reset(dev, bmcr)) {
4066 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4067 return -EINVAL;
4068 }
4069 } else {
4070 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4071 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 } else {
4074 int adv, bmcr;
4075
4076 np->autoneg = 0;
4077
4078 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004079 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
4081 adv |= ADVERTISE_10HALF;
4082 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004083 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
4085 adv |= ADVERTISE_100HALF;
4086 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004087 adv |= ADVERTISE_100FULL;
4088 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4089 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisments but disable tx pause */
4090 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4091 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4092 }
4093 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
4094 adv |= ADVERTISE_PAUSE_ASYM;
4095 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4096 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4098 np->fixed_mode = adv;
4099
4100 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004101 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004103 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 }
4105
4106 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004107 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
4108 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004110 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004112 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004113 /* reset the phy in order for forced mode settings to stick */
4114 if (phy_reset(dev, bmcr)) {
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004115 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4116 return -EINVAL;
4117 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004118 } else {
4119 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4120 if (netif_running(dev)) {
4121 /* Wait a bit and then reconfigure the nic. */
4122 udelay(10);
4123 nv_linkchange(dev);
4124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 }
4126 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004127
4128 if (netif_running(dev)) {
4129 nv_start_rx(dev);
4130 nv_start_tx(dev);
4131 nv_enable_irq(dev);
4132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133
4134 return 0;
4135}
4136
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004137#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004138
4139static int nv_get_regs_len(struct net_device *dev)
4140{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004141 struct fe_priv *np = netdev_priv(dev);
4142 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004143}
4144
4145static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
4146{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004147 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004148 u8 __iomem *base = get_hwbase(dev);
4149 u32 *rbuf = buf;
4150 int i;
4151
4152 regs->version = FORCEDETH_REGS_VER;
4153 spin_lock_irq(&np->lock);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004154 for (i = 0;i <= np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004155 rbuf[i] = readl(base + i*sizeof(u32));
4156 spin_unlock_irq(&np->lock);
4157}
4158
4159static int nv_nway_reset(struct net_device *dev)
4160{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004161 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004162 int ret;
4163
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004164 if (np->autoneg) {
4165 int bmcr;
4166
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004167 netif_carrier_off(dev);
4168 if (netif_running(dev)) {
4169 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004170 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004171 spin_lock(&np->lock);
4172 /* stop engines */
4173 nv_stop_rx(dev);
4174 nv_stop_tx(dev);
4175 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004176 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004177 printk(KERN_INFO "%s: link down.\n", dev->name);
4178 }
4179
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004180 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004181 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4182 bmcr |= BMCR_ANENABLE;
4183 /* reset the phy in order for settings to stick*/
4184 if (phy_reset(dev, bmcr)) {
4185 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4186 return -EINVAL;
4187 }
4188 } else {
4189 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4190 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4191 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004192
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004193 if (netif_running(dev)) {
4194 nv_start_rx(dev);
4195 nv_start_tx(dev);
4196 nv_enable_irq(dev);
4197 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004198 ret = 0;
4199 } else {
4200 ret = -EINVAL;
4201 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004202
4203 return ret;
4204}
4205
Zachary Amsden0674d592006-06-04 02:51:38 -07004206static int nv_set_tso(struct net_device *dev, u32 value)
4207{
4208 struct fe_priv *np = netdev_priv(dev);
4209
4210 if ((np->driver_data & DEV_HAS_CHECKSUM))
4211 return ethtool_op_set_tso(dev, value);
4212 else
Ayaz Abdulla6a788142006-06-10 22:47:26 -04004213 return -EOPNOTSUPP;
Zachary Amsden0674d592006-06-04 02:51:38 -07004214}
Zachary Amsden0674d592006-06-04 02:51:38 -07004215
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004216static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4217{
4218 struct fe_priv *np = netdev_priv(dev);
4219
4220 ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4221 ring->rx_mini_max_pending = 0;
4222 ring->rx_jumbo_max_pending = 0;
4223 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4224
4225 ring->rx_pending = np->rx_ring_size;
4226 ring->rx_mini_pending = 0;
4227 ring->rx_jumbo_pending = 0;
4228 ring->tx_pending = np->tx_ring_size;
4229}
4230
4231static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4232{
4233 struct fe_priv *np = netdev_priv(dev);
4234 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004235 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004236 dma_addr_t ring_addr;
4237
4238 if (ring->rx_pending < RX_RING_MIN ||
4239 ring->tx_pending < TX_RING_MIN ||
4240 ring->rx_mini_pending != 0 ||
4241 ring->rx_jumbo_pending != 0 ||
4242 (np->desc_ver == DESC_VER_1 &&
4243 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
4244 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
4245 (np->desc_ver != DESC_VER_1 &&
4246 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
4247 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
4248 return -EINVAL;
4249 }
4250
4251 /* allocate new rings */
4252 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
4253 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4254 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4255 &ring_addr);
4256 } else {
4257 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4258 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4259 &ring_addr);
4260 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004261 rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
4262 tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
4263 if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004264 /* fall back to old rings */
4265 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004266 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004267 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4268 rxtx_ring, ring_addr);
4269 } else {
4270 if (rxtx_ring)
4271 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4272 rxtx_ring, ring_addr);
4273 }
4274 if (rx_skbuff)
4275 kfree(rx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004276 if (tx_skbuff)
4277 kfree(tx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004278 goto exit;
4279 }
4280
4281 if (netif_running(dev)) {
4282 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004283 netif_tx_lock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004284 spin_lock(&np->lock);
4285 /* stop engines */
4286 nv_stop_rx(dev);
4287 nv_stop_tx(dev);
4288 nv_txrx_reset(dev);
4289 /* drain queues */
4290 nv_drain_rx(dev);
4291 nv_drain_tx(dev);
4292 /* delete queues */
4293 free_rings(dev);
4294 }
4295
4296 /* set new values */
4297 np->rx_ring_size = ring->rx_pending;
4298 np->tx_ring_size = ring->tx_pending;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004299 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
4300 np->rx_ring.orig = (struct ring_desc*)rxtx_ring;
4301 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4302 } else {
4303 np->rx_ring.ex = (struct ring_desc_ex*)rxtx_ring;
4304 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4305 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004306 np->rx_skb = (struct nv_skb_map*)rx_skbuff;
4307 np->tx_skb = (struct nv_skb_map*)tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004308 np->ring_addr = ring_addr;
4309
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004310 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4311 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004312
4313 if (netif_running(dev)) {
4314 /* reinit driver view of the queues */
4315 set_bufsize(dev);
4316 if (nv_init_ring(dev)) {
4317 if (!np->in_shutdown)
4318 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4319 }
4320
4321 /* reinit nic view of the queues */
4322 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4323 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4324 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4325 base + NvRegRingSizes);
4326 pci_push(base);
4327 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4328 pci_push(base);
4329
4330 /* restart engines */
4331 nv_start_rx(dev);
4332 nv_start_tx(dev);
4333 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004334 netif_tx_unlock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004335 nv_enable_irq(dev);
4336 }
4337 return 0;
4338exit:
4339 return -ENOMEM;
4340}
4341
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004342static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4343{
4344 struct fe_priv *np = netdev_priv(dev);
4345
4346 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
4347 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
4348 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
4349}
4350
4351static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4352{
4353 struct fe_priv *np = netdev_priv(dev);
4354 int adv, bmcr;
4355
4356 if ((!np->autoneg && np->duplex == 0) ||
4357 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
4358 printk(KERN_INFO "%s: can not set pause settings when forced link is in half duplex.\n",
4359 dev->name);
4360 return -EINVAL;
4361 }
4362 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
4363 printk(KERN_INFO "%s: hardware does not support tx pause frames.\n", dev->name);
4364 return -EINVAL;
4365 }
4366
4367 netif_carrier_off(dev);
4368 if (netif_running(dev)) {
4369 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004370 netif_tx_lock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004371 spin_lock(&np->lock);
4372 /* stop engines */
4373 nv_stop_rx(dev);
4374 nv_stop_tx(dev);
4375 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004376 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004377 }
4378
4379 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
4380 if (pause->rx_pause)
4381 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
4382 if (pause->tx_pause)
4383 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
4384
4385 if (np->autoneg && pause->autoneg) {
4386 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
4387
4388 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4389 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
4390 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
4391 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4392 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4393 adv |= ADVERTISE_PAUSE_ASYM;
4394 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4395
4396 if (netif_running(dev))
4397 printk(KERN_INFO "%s: link down.\n", dev->name);
4398 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4399 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4400 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4401 } else {
4402 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4403 if (pause->rx_pause)
4404 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4405 if (pause->tx_pause)
4406 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4407
4408 if (!netif_running(dev))
4409 nv_update_linkspeed(dev);
4410 else
4411 nv_update_pause(dev, np->pause_flags);
4412 }
4413
4414 if (netif_running(dev)) {
4415 nv_start_rx(dev);
4416 nv_start_tx(dev);
4417 nv_enable_irq(dev);
4418 }
4419 return 0;
4420}
4421
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004422static u32 nv_get_rx_csum(struct net_device *dev)
4423{
4424 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004425 return (np->rx_csum) != 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004426}
4427
4428static int nv_set_rx_csum(struct net_device *dev, u32 data)
4429{
4430 struct fe_priv *np = netdev_priv(dev);
4431 u8 __iomem *base = get_hwbase(dev);
4432 int retcode = 0;
4433
4434 if (np->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004435 if (data) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004436 np->rx_csum = 1;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004437 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004438 } else {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004439 np->rx_csum = 0;
4440 /* vlan is dependent on rx checksum offload */
4441 if (!(np->vlanctl_bits & NVREG_VLANCONTROL_ENABLE))
4442 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004443 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004444 if (netif_running(dev)) {
4445 spin_lock_irq(&np->lock);
4446 writel(np->txrxctl_bits, base + NvRegTxRxControl);
4447 spin_unlock_irq(&np->lock);
4448 }
4449 } else {
4450 return -EINVAL;
4451 }
4452
4453 return retcode;
4454}
4455
4456static int nv_set_tx_csum(struct net_device *dev, u32 data)
4457{
4458 struct fe_priv *np = netdev_priv(dev);
4459
4460 if (np->driver_data & DEV_HAS_CHECKSUM)
4461 return ethtool_op_set_tx_hw_csum(dev, data);
4462 else
4463 return -EOPNOTSUPP;
4464}
4465
4466static int nv_set_sg(struct net_device *dev, u32 data)
4467{
4468 struct fe_priv *np = netdev_priv(dev);
4469
4470 if (np->driver_data & DEV_HAS_CHECKSUM)
4471 return ethtool_op_set_sg(dev, data);
4472 else
4473 return -EOPNOTSUPP;
4474}
4475
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004476static int nv_get_sset_count(struct net_device *dev, int sset)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004477{
4478 struct fe_priv *np = netdev_priv(dev);
4479
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004480 switch (sset) {
4481 case ETH_SS_TEST:
4482 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
4483 return NV_TEST_COUNT_EXTENDED;
4484 else
4485 return NV_TEST_COUNT_BASE;
4486 case ETH_SS_STATS:
4487 if (np->driver_data & DEV_HAS_STATISTICS_V1)
4488 return NV_DEV_STATISTICS_V1_COUNT;
4489 else if (np->driver_data & DEV_HAS_STATISTICS_V2)
4490 return NV_DEV_STATISTICS_V2_COUNT;
4491 else
4492 return 0;
4493 default:
4494 return -EOPNOTSUPP;
4495 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004496}
4497
4498static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *buffer)
4499{
4500 struct fe_priv *np = netdev_priv(dev);
4501
4502 /* update stats */
4503 nv_do_stats_poll((unsigned long)dev);
4504
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004505 memcpy(buffer, &np->estats, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004506}
4507
4508static int nv_link_test(struct net_device *dev)
4509{
4510 struct fe_priv *np = netdev_priv(dev);
4511 int mii_status;
4512
4513 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4514 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4515
4516 /* check phy link status */
4517 if (!(mii_status & BMSR_LSTATUS))
4518 return 0;
4519 else
4520 return 1;
4521}
4522
4523static int nv_register_test(struct net_device *dev)
4524{
4525 u8 __iomem *base = get_hwbase(dev);
4526 int i = 0;
4527 u32 orig_read, new_read;
4528
4529 do {
4530 orig_read = readl(base + nv_registers_test[i].reg);
4531
4532 /* xor with mask to toggle bits */
4533 orig_read ^= nv_registers_test[i].mask;
4534
4535 writel(orig_read, base + nv_registers_test[i].reg);
4536
4537 new_read = readl(base + nv_registers_test[i].reg);
4538
4539 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
4540 return 0;
4541
4542 /* restore original value */
4543 orig_read ^= nv_registers_test[i].mask;
4544 writel(orig_read, base + nv_registers_test[i].reg);
4545
4546 } while (nv_registers_test[++i].reg != 0);
4547
4548 return 1;
4549}
4550
4551static int nv_interrupt_test(struct net_device *dev)
4552{
4553 struct fe_priv *np = netdev_priv(dev);
4554 u8 __iomem *base = get_hwbase(dev);
4555 int ret = 1;
4556 int testcnt;
4557 u32 save_msi_flags, save_poll_interval = 0;
4558
4559 if (netif_running(dev)) {
4560 /* free current irq */
4561 nv_free_irq(dev);
4562 save_poll_interval = readl(base+NvRegPollingInterval);
4563 }
4564
4565 /* flag to test interrupt handler */
4566 np->intr_test = 0;
4567
4568 /* setup test irq */
4569 save_msi_flags = np->msi_flags;
4570 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
4571 np->msi_flags |= 0x001; /* setup 1 vector */
4572 if (nv_request_irq(dev, 1))
4573 return 0;
4574
4575 /* setup timer interrupt */
4576 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4577 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4578
4579 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4580
4581 /* wait for at least one interrupt */
4582 msleep(100);
4583
4584 spin_lock_irq(&np->lock);
4585
4586 /* flag should be set within ISR */
4587 testcnt = np->intr_test;
4588 if (!testcnt)
4589 ret = 2;
4590
4591 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4592 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4593 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4594 else
4595 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4596
4597 spin_unlock_irq(&np->lock);
4598
4599 nv_free_irq(dev);
4600
4601 np->msi_flags = save_msi_flags;
4602
4603 if (netif_running(dev)) {
4604 writel(save_poll_interval, base + NvRegPollingInterval);
4605 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4606 /* restore original irq */
4607 if (nv_request_irq(dev, 0))
4608 return 0;
4609 }
4610
4611 return ret;
4612}
4613
4614static int nv_loopback_test(struct net_device *dev)
4615{
4616 struct fe_priv *np = netdev_priv(dev);
4617 u8 __iomem *base = get_hwbase(dev);
4618 struct sk_buff *tx_skb, *rx_skb;
4619 dma_addr_t test_dma_addr;
4620 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004621 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004622 int len, i, pkt_len;
4623 u8 *pkt_data;
4624 u32 filter_flags = 0;
4625 u32 misc1_flags = 0;
4626 int ret = 1;
4627
4628 if (netif_running(dev)) {
4629 nv_disable_irq(dev);
4630 filter_flags = readl(base + NvRegPacketFilterFlags);
4631 misc1_flags = readl(base + NvRegMisc1);
4632 } else {
4633 nv_txrx_reset(dev);
4634 }
4635
4636 /* reinit driver view of the rx queue */
4637 set_bufsize(dev);
4638 nv_init_ring(dev);
4639
4640 /* setup hardware for loopback */
4641 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
4642 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
4643
4644 /* reinit nic view of the rx queue */
4645 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4646 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4647 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4648 base + NvRegRingSizes);
4649 pci_push(base);
4650
4651 /* restart rx engine */
4652 nv_start_rx(dev);
4653 nv_start_tx(dev);
4654
4655 /* setup packet for tx */
4656 pkt_len = ETH_DATA_LEN;
4657 tx_skb = dev_alloc_skb(pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07004658 if (!tx_skb) {
4659 printk(KERN_ERR "dev_alloc_skb() failed during loopback test"
4660 " of %s\n", dev->name);
4661 ret = 0;
4662 goto out;
4663 }
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03004664 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
4665 skb_tailroom(tx_skb),
4666 PCI_DMA_FROMDEVICE);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004667 pkt_data = skb_put(tx_skb, pkt_len);
4668 for (i = 0; i < pkt_len; i++)
4669 pkt_data[i] = (u8)(i & 0xff);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004670
4671 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004672 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
4673 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 -04004674 } else {
Al Viro5bb7ea22007-12-09 16:06:41 +00004675 np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr));
4676 np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr));
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004677 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 -04004678 }
4679 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4680 pci_push(get_hwbase(dev));
4681
4682 msleep(500);
4683
4684 /* check for rx of the packet */
4685 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004686 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004687 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
4688
4689 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004690 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004691 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
4692 }
4693
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004694 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004695 ret = 0;
4696 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004697 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004698 ret = 0;
4699 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004700 if (flags & NV_RX2_ERROR) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004701 ret = 0;
4702 }
4703 }
4704
4705 if (ret) {
4706 if (len != pkt_len) {
4707 ret = 0;
4708 dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n",
4709 dev->name, len, pkt_len);
4710 } else {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004711 rx_skb = np->rx_skb[0].skb;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004712 for (i = 0; i < pkt_len; i++) {
4713 if (rx_skb->data[i] != (u8)(i & 0xff)) {
4714 ret = 0;
4715 dprintk(KERN_DEBUG "%s: loopback pattern check failed on byte %d\n",
4716 dev->name, i);
4717 break;
4718 }
4719 }
4720 }
4721 } else {
4722 dprintk(KERN_DEBUG "%s: loopback - did not receive test packet\n", dev->name);
4723 }
4724
4725 pci_unmap_page(np->pci_dev, test_dma_addr,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07004726 (skb_end_pointer(tx_skb) - tx_skb->data),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004727 PCI_DMA_TODEVICE);
4728 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07004729 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004730 /* stop engines */
4731 nv_stop_rx(dev);
4732 nv_stop_tx(dev);
4733 nv_txrx_reset(dev);
4734 /* drain rx queue */
4735 nv_drain_rx(dev);
4736 nv_drain_tx(dev);
4737
4738 if (netif_running(dev)) {
4739 writel(misc1_flags, base + NvRegMisc1);
4740 writel(filter_flags, base + NvRegPacketFilterFlags);
4741 nv_enable_irq(dev);
4742 }
4743
4744 return ret;
4745}
4746
4747static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
4748{
4749 struct fe_priv *np = netdev_priv(dev);
4750 u8 __iomem *base = get_hwbase(dev);
4751 int result;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004752 memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004753
4754 if (!nv_link_test(dev)) {
4755 test->flags |= ETH_TEST_FL_FAILED;
4756 buffer[0] = 1;
4757 }
4758
4759 if (test->flags & ETH_TEST_FL_OFFLINE) {
4760 if (netif_running(dev)) {
4761 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004762#ifdef CONFIG_FORCEDETH_NAPI
4763 napi_disable(&np->napi);
4764#endif
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004765 netif_tx_lock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004766 spin_lock_irq(&np->lock);
4767 nv_disable_hw_interrupts(dev, np->irqmask);
4768 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
4769 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4770 } else {
4771 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4772 }
4773 /* stop engines */
4774 nv_stop_rx(dev);
4775 nv_stop_tx(dev);
4776 nv_txrx_reset(dev);
4777 /* drain rx queue */
4778 nv_drain_rx(dev);
4779 nv_drain_tx(dev);
4780 spin_unlock_irq(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004781 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004782 }
4783
4784 if (!nv_register_test(dev)) {
4785 test->flags |= ETH_TEST_FL_FAILED;
4786 buffer[1] = 1;
4787 }
4788
4789 result = nv_interrupt_test(dev);
4790 if (result != 1) {
4791 test->flags |= ETH_TEST_FL_FAILED;
4792 buffer[2] = 1;
4793 }
4794 if (result == 0) {
4795 /* bail out */
4796 return;
4797 }
4798
4799 if (!nv_loopback_test(dev)) {
4800 test->flags |= ETH_TEST_FL_FAILED;
4801 buffer[3] = 1;
4802 }
4803
4804 if (netif_running(dev)) {
4805 /* reinit driver view of the rx queue */
4806 set_bufsize(dev);
4807 if (nv_init_ring(dev)) {
4808 if (!np->in_shutdown)
4809 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4810 }
4811 /* reinit nic view of the rx queue */
4812 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4813 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4814 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4815 base + NvRegRingSizes);
4816 pci_push(base);
4817 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4818 pci_push(base);
4819 /* restart rx engine */
4820 nv_start_rx(dev);
4821 nv_start_tx(dev);
4822 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07004823#ifdef CONFIG_FORCEDETH_NAPI
4824 napi_enable(&np->napi);
4825#endif
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004826 nv_enable_hw_interrupts(dev, np->irqmask);
4827 }
4828 }
4829}
4830
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004831static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
4832{
4833 switch (stringset) {
4834 case ETH_SS_STATS:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004835 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 -04004836 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004837 case ETH_SS_TEST:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004838 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 -04004839 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004840 }
4841}
4842
Jeff Garzik7282d492006-09-13 14:30:00 -04004843static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 .get_drvinfo = nv_get_drvinfo,
4845 .get_link = ethtool_op_get_link,
4846 .get_wol = nv_get_wol,
4847 .set_wol = nv_set_wol,
4848 .get_settings = nv_get_settings,
4849 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004850 .get_regs_len = nv_get_regs_len,
4851 .get_regs = nv_get_regs,
4852 .nway_reset = nv_nway_reset,
Ayaz Abdulla6a788142006-06-10 22:47:26 -04004853 .set_tso = nv_set_tso,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004854 .get_ringparam = nv_get_ringparam,
4855 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004856 .get_pauseparam = nv_get_pauseparam,
4857 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004858 .get_rx_csum = nv_get_rx_csum,
4859 .set_rx_csum = nv_set_rx_csum,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004860 .set_tx_csum = nv_set_tx_csum,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004861 .set_sg = nv_set_sg,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004862 .get_strings = nv_get_strings,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004863 .get_ethtool_stats = nv_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004864 .get_sset_count = nv_get_sset_count,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004865 .self_test = nv_self_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866};
4867
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004868static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
4869{
4870 struct fe_priv *np = get_nvpriv(dev);
4871
4872 spin_lock_irq(&np->lock);
4873
4874 /* save vlan group */
4875 np->vlangrp = grp;
4876
4877 if (grp) {
4878 /* enable vlan on MAC */
4879 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS;
4880 } else {
4881 /* disable vlan on MAC */
4882 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4883 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4884 }
4885
4886 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4887
4888 spin_unlock_irq(&np->lock);
Stephen Hemminger25805dc2007-06-01 09:44:01 -07004889}
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004890
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004891/* The mgmt unit and driver use a semaphore to access the phy during init */
4892static int nv_mgmt_acquire_sema(struct net_device *dev)
4893{
4894 u8 __iomem *base = get_hwbase(dev);
4895 int i;
4896 u32 tx_ctrl, mgmt_sema;
4897
4898 for (i = 0; i < 10; i++) {
4899 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
4900 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
4901 break;
4902 msleep(500);
4903 }
4904
4905 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
4906 return 0;
4907
4908 for (i = 0; i < 2; i++) {
4909 tx_ctrl = readl(base + NvRegTransmitterControl);
4910 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
4911 writel(tx_ctrl, base + NvRegTransmitterControl);
4912
4913 /* verify that semaphore was acquired */
4914 tx_ctrl = readl(base + NvRegTransmitterControl);
4915 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
4916 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE))
4917 return 1;
4918 else
4919 udelay(50);
4920 }
4921
4922 return 0;
4923}
4924
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925static int nv_open(struct net_device *dev)
4926{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004927 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004929 int ret = 1;
4930 int oom, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931
4932 dprintk(KERN_DEBUG "nv_open: begin\n");
4933
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004934 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004935 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4936 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4938 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05004939 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
4940 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 writel(0, base + NvRegPacketFilterFlags);
4942
4943 writel(0, base + NvRegTransmitterControl);
4944 writel(0, base + NvRegReceiverControl);
4945
4946 writel(0, base + NvRegAdapterControl);
4947
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004948 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
4949 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
4950
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004951 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02004952 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953 oom = nv_init_ring(dev);
4954
4955 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004956 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 nv_txrx_reset(dev);
4958 writel(0, base + NvRegUnknownSetupReg6);
4959
4960 np->in_shutdown = 0;
4961
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004962 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05004963 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004964 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965 base + NvRegRingSizes);
4966
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04004968 if (np->desc_ver == DESC_VER_1)
4969 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
4970 else
4971 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004972 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004973 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004975 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
4977 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
4978 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
4979
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004980 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05004982 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
4985 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
4986 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02004987 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988
4989 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
4990 get_random_bytes(&i, sizeof(i));
4991 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed);
Ayaz Abdulla9744e212006-07-06 16:45:58 -04004992 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
4993 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004994 if (poll_interval == -1) {
4995 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
4996 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
4997 else
4998 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4999 }
5000 else
5001 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
5003 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
5004 base + NvRegAdapterControl);
5005 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005006 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04005007 if (np->wolenabled)
5008 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009
5010 i = readl(base + NvRegPowerState);
5011 if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0)
5012 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
5013
5014 pci_push(base);
5015 udelay(10);
5016 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
5017
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005018 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 pci_push(base);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005020 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5022 pci_push(base);
5023
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005024 if (nv_request_irq(dev, 0)) {
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005025 goto out_drain;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005026 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027
5028 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005029 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030
5031 spin_lock_irq(&np->lock);
5032 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5033 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005034 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5035 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
5037 /* One manual link speed update: Interrupts are enabled, future link
5038 * speed changes cause interrupts and are handled by nv_link_irq().
5039 */
5040 {
5041 u32 miistat;
5042 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005043 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
5045 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02005046 /* set linkspeed to invalid value, thus force nv_update_linkspeed
5047 * to init hw */
5048 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049 ret = nv_update_linkspeed(dev);
5050 nv_start_rx(dev);
5051 nv_start_tx(dev);
5052 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005053#ifdef CONFIG_FORCEDETH_NAPI
5054 napi_enable(&np->napi);
5055#endif
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005056
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057 if (ret) {
5058 netif_carrier_on(dev);
5059 } else {
Ed Swierkf7ab6972007-09-28 22:42:13 -07005060 printk(KERN_INFO "%s: no link during initialization.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061 netif_carrier_off(dev);
5062 }
5063 if (oom)
5064 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005065
5066 /* start statistics timer */
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005067 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2))
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005068 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
5069
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070 spin_unlock_irq(&np->lock);
5071
5072 return 0;
5073out_drain:
5074 drain_ring(dev);
5075 return ret;
5076}
5077
5078static int nv_close(struct net_device *dev)
5079{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005080 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 u8 __iomem *base;
5082
5083 spin_lock_irq(&np->lock);
5084 np->in_shutdown = 1;
5085 spin_unlock_irq(&np->lock);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005086#ifdef CONFIG_FORCEDETH_NAPI
5087 napi_disable(&np->napi);
5088#endif
Manfred Spraula7475902007-10-17 21:52:33 +02005089 synchronize_irq(np->pci_dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090
5091 del_timer_sync(&np->oom_kick);
5092 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005093 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094
5095 netif_stop_queue(dev);
5096 spin_lock_irq(&np->lock);
5097 nv_stop_tx(dev);
5098 nv_stop_rx(dev);
5099 nv_txrx_reset(dev);
5100
5101 /* disable interrupts on the nic or we will lock up */
5102 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005103 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 pci_push(base);
5105 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
5106
5107 spin_unlock_irq(&np->lock);
5108
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005109 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110
5111 drain_ring(dev);
5112
Tim Mann2cc49a52007-06-14 13:16:38 -07005113 if (np->wolenabled) {
5114 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115 nv_start_rx(dev);
Tim Mann2cc49a52007-06-14 13:16:38 -07005116 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117
5118 /* FIXME: power down nic */
5119
5120 return 0;
5121}
5122
5123static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
5124{
5125 struct net_device *dev;
5126 struct fe_priv *np;
5127 unsigned long addr;
5128 u8 __iomem *base;
5129 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005130 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005131 u32 phystate_orig = 0, phystate;
5132 int phyinitialized = 0;
Joe Perches0795af52007-10-03 17:59:30 -07005133 DECLARE_MAC_BUF(mac);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005134 static int printed_version;
5135
5136 if (!printed_version++)
5137 printk(KERN_INFO "%s: Reverse Engineered nForce ethernet"
5138 " driver. Version %s.\n", DRV_NAME, FORCEDETH_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139
5140 dev = alloc_etherdev(sizeof(struct fe_priv));
5141 err = -ENOMEM;
5142 if (!dev)
5143 goto out;
5144
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005145 np = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005146 np->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147 np->pci_dev = pci_dev;
5148 spin_lock_init(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149 SET_NETDEV_DEV(dev, &pci_dev->dev);
5150
5151 init_timer(&np->oom_kick);
5152 np->oom_kick.data = (unsigned long) dev;
5153 np->oom_kick.function = &nv_do_rx_refill; /* timer handler */
5154 init_timer(&np->nic_poll);
5155 np->nic_poll.data = (unsigned long) dev;
5156 np->nic_poll.function = &nv_do_nic_poll; /* timer handler */
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005157 init_timer(&np->stats_poll);
5158 np->stats_poll.data = (unsigned long) dev;
5159 np->stats_poll.function = &nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160
5161 err = pci_enable_device(pci_dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005162 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164
5165 pci_set_master(pci_dev);
5166
5167 err = pci_request_regions(pci_dev, DRV_NAME);
5168 if (err < 0)
5169 goto out_disable;
5170
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005171 if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V2))
5172 np->register_size = NV_PCI_REGSZ_VER3;
5173 else if (id->driver_data & DEV_HAS_STATISTICS_V1)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005174 np->register_size = NV_PCI_REGSZ_VER2;
5175 else
5176 np->register_size = NV_PCI_REGSZ_VER1;
5177
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178 err = -EINVAL;
5179 addr = 0;
5180 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
5181 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
5182 pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i),
5183 pci_resource_len(pci_dev, i),
5184 pci_resource_flags(pci_dev, i));
5185 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005186 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187 addr = pci_resource_start(pci_dev, i);
5188 break;
5189 }
5190 }
5191 if (i == DEVICE_COUNT_RESOURCE) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005192 dev_printk(KERN_INFO, &pci_dev->dev,
5193 "Couldn't find register window\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194 goto out_relreg;
5195 }
5196
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005197 /* copy of driver data */
5198 np->driver_data = id->driver_data;
5199
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02005201 if (id->driver_data & DEV_HAS_HIGH_DMA) {
5202 /* packet format 3: supports 40-bit addressing */
5203 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005204 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005205 if (dma_64bit) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005206 if (pci_set_dma_mask(pci_dev, DMA_39BIT_MASK))
5207 dev_printk(KERN_INFO, &pci_dev->dev,
5208 "64-bit DMA failed, using 32-bit addressing\n");
5209 else
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005210 dev->features |= NETIF_F_HIGHDMA;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005211 if (pci_set_consistent_dma_mask(pci_dev, DMA_39BIT_MASK)) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005212 dev_printk(KERN_INFO, &pci_dev->dev,
5213 "64-bit DMA (consistent) failed, using 32-bit ring buffers\n");
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005214 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005215 }
Manfred Spraulee733622005-07-31 18:32:26 +02005216 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
5217 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005219 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02005220 } else {
5221 /* original packet format */
5222 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005223 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02005224 }
Manfred Spraulee733622005-07-31 18:32:26 +02005225
5226 np->pkt_limit = NV_PKTLIMIT_1;
5227 if (id->driver_data & DEV_HAS_LARGEDESC)
5228 np->pkt_limit = NV_PKTLIMIT_2;
5229
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005230 if (id->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04005231 np->rx_csum = 1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005232 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005233 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
Ayaz Abdullafa454592006-01-05 22:45:45 -08005234 dev->features |= NETIF_F_TSO;
Ayaz Abdulla21828162007-01-23 12:27:21 -05005235 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005236
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005237 np->vlanctl_bits = 0;
5238 if (id->driver_data & DEV_HAS_VLAN) {
5239 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
5240 dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
5241 dev->vlan_rx_register = nv_vlan_rx_register;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005242 }
5243
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005244 np->msi_flags = 0;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005245 if ((id->driver_data & DEV_HAS_MSI) && msi) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005246 np->msi_flags |= NV_MSI_CAPABLE;
5247 }
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005248 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005249 np->msi_flags |= NV_MSI_X_CAPABLE;
5250 }
5251
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005252 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005253 if ((id->driver_data & DEV_HAS_PAUSEFRAME_TX_V1) ||
5254 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) ||
5255 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005256 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005257 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005258
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005259
Linus Torvalds1da177e2005-04-16 15:20:36 -07005260 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005261 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 if (!np->base)
5263 goto out_relreg;
5264 dev->base_addr = (unsigned long)np->base;
Manfred Spraulee733622005-07-31 18:32:26 +02005265
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266 dev->irq = pci_dev->irq;
Manfred Spraulee733622005-07-31 18:32:26 +02005267
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005268 np->rx_ring_size = RX_RING_DEFAULT;
5269 np->tx_ring_size = TX_RING_DEFAULT;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005270
Manfred Spraulee733622005-07-31 18:32:26 +02005271 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
5272 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005273 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005274 &np->ring_addr);
5275 if (!np->rx_ring.orig)
5276 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005277 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005278 } else {
5279 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005280 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005281 &np->ring_addr);
5282 if (!np->rx_ring.ex)
5283 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005284 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005285 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005286 np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
5287 np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005288 if (!np->rx_skb || !np->tx_skb)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005289 goto out_freering;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290
5291 dev->open = nv_open;
5292 dev->stop = nv_close;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05005293 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
5294 dev->hard_start_xmit = nv_start_xmit;
5295 else
5296 dev->hard_start_xmit = nv_start_xmit_optimized;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 dev->get_stats = nv_get_stats;
5298 dev->change_mtu = nv_change_mtu;
Manfred Spraul72b31782005-07-31 18:33:34 +02005299 dev->set_mac_address = nv_set_mac_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300 dev->set_multicast_list = nv_set_multicast;
Michal Schmidt2918c352005-05-12 19:42:06 -04005301#ifdef CONFIG_NET_POLL_CONTROLLER
5302 dev->poll_controller = nv_poll_controller;
5303#endif
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005304#ifdef CONFIG_FORCEDETH_NAPI
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005305 netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005306#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307 SET_ETHTOOL_OPS(dev, &ops);
5308 dev->tx_timeout = nv_tx_timeout;
5309 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
5310
5311 pci_set_drvdata(pci_dev, dev);
5312
5313 /* read the mac address */
5314 base = get_hwbase(dev);
5315 np->orig_mac[0] = readl(base + NvRegMacAddrA);
5316 np->orig_mac[1] = readl(base + NvRegMacAddrB);
5317
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005318 /* check the workaround bit for correct mac address order */
5319 txreg = readl(base + NvRegTransmitPoll);
Ayaz Abdullaef756b32007-07-26 23:46:00 -04005320 if ((txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) ||
5321 (id->driver_data & DEV_HAS_CORRECT_MACADDR)) {
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005322 /* mac address is already in correct order */
5323 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5324 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5325 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5326 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5327 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5328 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5329 } else {
5330 /* need to reverse mac address to correct order */
5331 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5332 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5333 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5334 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5335 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5336 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005337 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
5338 }
John W. Linvillec704b852005-09-12 10:48:56 -04005339 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340
John W. Linvillec704b852005-09-12 10:48:56 -04005341 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342 /*
5343 * Bad mac address. At least one bios sets the mac address
5344 * to 01:23:45:67:89:ab
5345 */
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005346 dev_printk(KERN_ERR, &pci_dev->dev,
5347 "Invalid Mac address detected: %s\n",
5348 print_mac(mac, dev->dev_addr));
5349 dev_printk(KERN_ERR, &pci_dev->dev,
5350 "Please complain to your hardware vendor. Switching to a random MAC.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 dev->dev_addr[0] = 0x00;
5352 dev->dev_addr[1] = 0x00;
5353 dev->dev_addr[2] = 0x6c;
5354 get_random_bytes(&dev->dev_addr[3], 3);
5355 }
5356
Joe Perches0795af52007-10-03 17:59:30 -07005357 dprintk(KERN_DEBUG "%s: MAC Address %s\n",
5358 pci_name(pci_dev), print_mac(mac, dev->dev_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005360 /* set mac address */
5361 nv_copy_mac_to_hw(dev);
5362
Linus Torvalds1da177e2005-04-16 15:20:36 -07005363 /* disable WOL */
5364 writel(0, base + NvRegWakeUpFlags);
5365 np->wolenabled = 0;
5366
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005367 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005368
5369 /* take phy and nic out of low power mode */
5370 powerstate = readl(base + NvRegPowerState2);
5371 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
5372 if ((id->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 ||
5373 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_13) &&
Auke Kok44c10132007-06-08 15:46:36 -07005374 pci_dev->revision >= 0xA3)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005375 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
5376 writel(powerstate, base + NvRegPowerState2);
5377 }
5378
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005380 np->tx_flags = NV_TX_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381 } else {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005382 np->tx_flags = NV_TX2_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005384 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005385 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005386 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5387 np->msi_flags |= 0x0003;
5388 } else {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005389 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005390 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5391 np->msi_flags |= 0x0001;
5392 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005393
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394 if (id->driver_data & DEV_NEED_TIMERIRQ)
5395 np->irqmask |= NVREG_IRQ_TIMER;
5396 if (id->driver_data & DEV_NEED_LINKTIMER) {
5397 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
5398 np->need_linktimer = 1;
5399 np->link_timeout = jiffies + LINK_TIMEOUT;
5400 } else {
5401 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
5402 np->need_linktimer = 0;
5403 }
5404
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005405 /* Limit the number of tx's outstanding for hw bug */
5406 if (id->driver_data & DEV_NEED_TX_LIMIT) {
5407 np->tx_limit = 1;
5408 if ((id->device == PCI_DEVICE_ID_NVIDIA_NVENET_32 ||
5409 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_33 ||
5410 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_34 ||
5411 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_35 ||
5412 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_36 ||
5413 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_37 ||
5414 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_38 ||
5415 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_39) &&
5416 pci_dev->revision >= 0xA2)
5417 np->tx_limit = 0;
5418 }
5419
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005420 /* clear phy state and temporarily halt phy interrupts */
5421 writel(0, base + NvRegMIIMask);
5422 phystate = readl(base + NvRegAdapterControl);
5423 if (phystate & NVREG_ADAPTCTL_RUNNING) {
5424 phystate_orig = 1;
5425 phystate &= ~NVREG_ADAPTCTL_RUNNING;
5426 writel(phystate, base + NvRegAdapterControl);
5427 }
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005428 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005429
5430 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005431 /* management unit running on the mac? */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005432 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) {
5433 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST;
5434 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 -08005435 if (nv_mgmt_acquire_sema(dev)) {
5436 /* management unit setup the phy already? */
5437 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5438 NVREG_XMITCTL_SYNC_PHY_INIT) {
5439 /* phy is inited by mgmt unit */
5440 phyinitialized = 1;
5441 dprintk(KERN_INFO "%s: Phy already initialized by mgmt unit.\n", pci_name(pci_dev));
5442 } else {
5443 /* we need to init the phy */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005444 }
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005445 }
5446 }
5447 }
5448
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005450 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005452 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005453
5454 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005455 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456 spin_unlock_irq(&np->lock);
5457 if (id1 < 0 || id1 == 0xffff)
5458 continue;
5459 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005460 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005461 spin_unlock_irq(&np->lock);
5462 if (id2 < 0 || id2 == 0xffff)
5463 continue;
5464
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04005465 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005466 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
5467 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
5468 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005469 pci_name(pci_dev), id1, id2, phyaddr);
5470 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471 np->phy_oui = id1 | id2;
5472 break;
5473 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005474 if (i == 33) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005475 dev_printk(KERN_INFO, &pci_dev->dev,
5476 "open: Could not find a valid PHY.\n");
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005477 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005479
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005480 if (!phyinitialized) {
5481 /* reset it */
5482 phy_init(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005483 } else {
5484 /* see if it is a gigabit phy */
5485 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
5486 if (mii_status & PHY_GIGABIT) {
5487 np->gigabit = PHY_GIGABIT;
5488 }
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005490
5491 /* set default link speed settings */
5492 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
5493 np->duplex = 0;
5494 np->autoneg = 1;
5495
5496 err = register_netdev(dev);
5497 if (err) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005498 dev_printk(KERN_INFO, &pci_dev->dev,
5499 "unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005500 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005501 }
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005502
5503 dev_printk(KERN_INFO, &pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, "
5504 "addr %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
5505 dev->name,
5506 np->phy_oui,
5507 np->phyaddr,
5508 dev->dev_addr[0],
5509 dev->dev_addr[1],
5510 dev->dev_addr[2],
5511 dev->dev_addr[3],
5512 dev->dev_addr[4],
5513 dev->dev_addr[5]);
5514
5515 dev_printk(KERN_INFO, &pci_dev->dev, "%s%s%s%s%s%s%s%s%s%sdesc-v%u\n",
5516 dev->features & NETIF_F_HIGHDMA ? "highdma " : "",
5517 dev->features & (NETIF_F_HW_CSUM | NETIF_F_SG) ?
5518 "csum " : "",
5519 dev->features & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX) ?
5520 "vlan " : "",
5521 id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "",
5522 id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "",
5523 id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "",
5524 np->gigabit == PHY_GIGABIT ? "gbit " : "",
5525 np->need_linktimer ? "lnktim " : "",
5526 np->msi_flags & NV_MSI_CAPABLE ? "msi " : "",
5527 np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "",
5528 np->desc_ver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529
5530 return 0;
5531
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005532out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005533 if (phystate_orig)
5534 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005536out_freering:
5537 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538out_unmap:
5539 iounmap(get_hwbase(dev));
5540out_relreg:
5541 pci_release_regions(pci_dev);
5542out_disable:
5543 pci_disable_device(pci_dev);
5544out_free:
5545 free_netdev(dev);
5546out:
5547 return err;
5548}
5549
5550static void __devexit nv_remove(struct pci_dev *pci_dev)
5551{
5552 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005553 struct fe_priv *np = netdev_priv(dev);
5554 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005555
5556 unregister_netdev(dev);
5557
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005558 /* special op: write back the misordered MAC address - otherwise
5559 * the next nv_probe would see a wrong address.
5560 */
5561 writel(np->orig_mac[0], base + NvRegMacAddrA);
5562 writel(np->orig_mac[1], base + NvRegMacAddrB);
Björn Steinbrink2e3884b2008-01-07 23:22:53 -08005563 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
5564 base + NvRegTransmitPoll);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005565
Linus Torvalds1da177e2005-04-16 15:20:36 -07005566 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005567 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005568 iounmap(get_hwbase(dev));
5569 pci_release_regions(pci_dev);
5570 pci_disable_device(pci_dev);
5571 free_netdev(dev);
5572 pci_set_drvdata(pci_dev, NULL);
5573}
5574
Francois Romieua1893172006-10-10 14:33:27 -07005575#ifdef CONFIG_PM
5576static int nv_suspend(struct pci_dev *pdev, pm_message_t state)
5577{
5578 struct net_device *dev = pci_get_drvdata(pdev);
5579 struct fe_priv *np = netdev_priv(dev);
5580
5581 if (!netif_running(dev))
5582 goto out;
5583
5584 netif_device_detach(dev);
5585
5586 // Gross.
5587 nv_close(dev);
5588
5589 pci_save_state(pdev);
5590 pci_enable_wake(pdev, pci_choose_state(pdev, state), np->wolenabled);
5591 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5592out:
5593 return 0;
5594}
5595
5596static int nv_resume(struct pci_dev *pdev)
5597{
5598 struct net_device *dev = pci_get_drvdata(pdev);
5599 int rc = 0;
5600
5601 if (!netif_running(dev))
5602 goto out;
5603
5604 netif_device_attach(dev);
5605
5606 pci_set_power_state(pdev, PCI_D0);
5607 pci_restore_state(pdev);
5608 pci_enable_wake(pdev, PCI_D0, 0);
5609
5610 rc = nv_open(dev);
5611out:
5612 return rc;
5613}
5614#else
5615#define nv_suspend NULL
5616#define nv_resume NULL
5617#endif /* CONFIG_PM */
5618
Linus Torvalds1da177e2005-04-16 15:20:36 -07005619static struct pci_device_id pci_tbl[] = {
5620 { /* nForce Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005621 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005622 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005623 },
5624 { /* nForce2 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005625 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005626 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005627 },
5628 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005629 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005630 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005631 },
5632 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005633 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005634 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005635 },
5636 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005637 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005638 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005639 },
5640 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005641 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005642 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005643 },
5644 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005645 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005646 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005647 },
5648 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005649 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005650 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005651 },
5652 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005653 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005654 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005655 },
5656 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005657 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005658 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005659 },
5660 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005661 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005662 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005663 },
5664 { /* MCP51 Ethernet Controller */
5665 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005666 .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 -07005667 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02005668 { /* MCP51 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005669 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13),
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005670 .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 +02005671 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02005672 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005673 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005674 .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_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02005675 },
5676 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005677 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005678 .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_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02005679 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005680 { /* MCP61 Ethernet Controller */
5681 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_16),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005682 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005683 },
5684 { /* MCP61 Ethernet Controller */
5685 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_17),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005686 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005687 },
5688 { /* MCP61 Ethernet Controller */
5689 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_18),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005690 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005691 },
5692 { /* MCP61 Ethernet Controller */
5693 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_19),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005694 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005695 },
5696 { /* MCP65 Ethernet Controller */
5697 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005698 .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_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_NEED_TX_LIMIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005699 },
5700 { /* MCP65 Ethernet Controller */
5701 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005702 .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_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005703 },
5704 { /* MCP65 Ethernet Controller */
5705 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005706 .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_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005707 },
5708 { /* MCP65 Ethernet Controller */
5709 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005710 .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_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005711 },
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005712 { /* MCP67 Ethernet Controller */
5713 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005714 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005715 },
5716 { /* MCP67 Ethernet Controller */
5717 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_25),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005718 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005719 },
5720 { /* MCP67 Ethernet Controller */
5721 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_26),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005722 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005723 },
5724 { /* MCP67 Ethernet Controller */
5725 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005726 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005727 },
Ayaz Abdulla13986612007-07-22 20:43:26 -04005728 { /* MCP73 Ethernet Controller */
5729 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_28),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005730 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|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 -04005731 },
5732 { /* MCP73 Ethernet Controller */
5733 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_29),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005734 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|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 -04005735 },
5736 { /* MCP73 Ethernet Controller */
5737 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_30),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005738 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|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 -04005739 },
5740 { /* MCP73 Ethernet Controller */
5741 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_31),
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005742 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|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 -04005743 },
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005744 { /* MCP77 Ethernet Controller */
5745 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_32),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005746 .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_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005747 },
5748 { /* MCP77 Ethernet Controller */
5749 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_33),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005750 .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_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005751 },
5752 { /* MCP77 Ethernet Controller */
5753 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_34),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005754 .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_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005755 },
5756 { /* MCP77 Ethernet Controller */
5757 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_35),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005758 .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_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04005759 },
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005760 { /* MCP79 Ethernet Controller */
5761 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_36),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005762 .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_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005763 },
5764 { /* MCP79 Ethernet Controller */
5765 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_37),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005766 .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_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005767 },
5768 { /* MCP79 Ethernet Controller */
5769 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_38),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005770 .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_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005771 },
5772 { /* MCP79 Ethernet Controller */
5773 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_39),
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005774 .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_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05005775 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 {0,},
5777};
5778
5779static struct pci_driver driver = {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005780 .name = DRV_NAME,
5781 .id_table = pci_tbl,
5782 .probe = nv_probe,
5783 .remove = __devexit_p(nv_remove),
5784 .suspend = nv_suspend,
5785 .resume = nv_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005786};
5787
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788static int __init init_nic(void)
5789{
Jeff Garzik29917622006-08-19 17:48:59 -04005790 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005791}
5792
5793static void __exit exit_nic(void)
5794{
5795 pci_unregister_driver(&driver);
5796}
5797
5798module_param(max_interrupt_work, int, 0);
5799MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005800module_param(optimization_mode, int, 0);
5801MODULE_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.");
5802module_param(poll_interval, int, 0);
5803MODULE_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 -04005804module_param(msi, int, 0);
5805MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
5806module_param(msix, int, 0);
5807MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
5808module_param(dma_64bit, int, 0);
5809MODULE_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 -07005810
5811MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
5812MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
5813MODULE_LICENSE("GPL");
5814
5815MODULE_DEVICE_TABLE(pci, pci_tbl);
5816
5817module_init(init_nic);
5818module_exit(exit_nic);