blob: 5472d12122b4345b448ebffd959549a0c8304fcb [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
6 * and Andrew de Quincey. It's neither supported nor endorsed
7 * by NVIDIA Corp. Use at your own risk.
8 *
9 * NVIDIA, nForce and other NVIDIA marks are trademarks or registered
10 * trademarks of NVIDIA Corporation in the United States and other
11 * countries.
12 *
Manfred Spraul18360982005-12-24 14:19:24 +010013 * Copyright (C) 2003,4,5 Manfred Spraul
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * Copyright (C) 2004 Andrew de Quincey (wol support)
15 * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane
16 * IRQ rate fixes, bigendian fixes, cleanups, verification)
17 * Copyright (c) 2004 NVIDIA Corporation
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 *
33 * Changelog:
34 * 0.01: 05 Oct 2003: First release that compiles without warnings.
35 * 0.02: 05 Oct 2003: Fix bug for nv_drain_tx: do not try to free NULL skbs.
36 * Check all PCI BARs for the register window.
37 * udelay added to mii_rw.
38 * 0.03: 06 Oct 2003: Initialize dev->irq.
39 * 0.04: 07 Oct 2003: Initialize np->lock, reduce handled irqs, add printks.
40 * 0.05: 09 Oct 2003: printk removed again, irq status print tx_timeout.
41 * 0.06: 10 Oct 2003: MAC Address read updated, pff flag generation updated,
42 * irq mask updated
43 * 0.07: 14 Oct 2003: Further irq mask updates.
44 * 0.08: 20 Oct 2003: rx_desc.Length initialization added, nv_alloc_rx refill
45 * added into irq handler, NULL check for drain_ring.
46 * 0.09: 20 Oct 2003: Basic link speed irq implementation. Only handle the
47 * requested interrupt sources.
48 * 0.10: 20 Oct 2003: First cleanup for release.
49 * 0.11: 21 Oct 2003: hexdump for tx added, rx buffer sizes increased.
50 * MAC Address init fix, set_multicast cleanup.
51 * 0.12: 23 Oct 2003: Cleanups for release.
52 * 0.13: 25 Oct 2003: Limit for concurrent tx packets increased to 10.
53 * Set link speed correctly. start rx before starting
54 * tx (nv_start_rx sets the link speed).
55 * 0.14: 25 Oct 2003: Nic dependant irq mask.
56 * 0.15: 08 Nov 2003: fix smp deadlock with set_multicast_list during
57 * open.
58 * 0.16: 15 Nov 2003: include file cleanup for ppc64, rx buffer size
59 * increased to 1628 bytes.
60 * 0.17: 16 Nov 2003: undo rx buffer size increase. Substract 1 from
61 * the tx length.
62 * 0.18: 17 Nov 2003: fix oops due to late initialization of dev_stats
63 * 0.19: 29 Nov 2003: Handle RxNoBuf, detect & handle invalid mac
64 * addresses, really stop rx if already running
65 * in nv_start_rx, clean up a bit.
66 * 0.20: 07 Dec 2003: alloc fixes
67 * 0.21: 12 Jan 2004: additional alloc fix, nic polling fix.
68 * 0.22: 19 Jan 2004: reprogram timer to a sane rate, avoid lockup
69 * on close.
70 * 0.23: 26 Jan 2004: various small cleanups
71 * 0.24: 27 Feb 2004: make driver even less anonymous in backtraces
72 * 0.25: 09 Mar 2004: wol support
73 * 0.26: 03 Jun 2004: netdriver specific annotation, sparse-related fixes
74 * 0.27: 19 Jun 2004: Gigabit support, new descriptor rings,
75 * added CK804/MCP04 device IDs, code fixes
76 * for registers, link status and other minor fixes.
77 * 0.28: 21 Jun 2004: Big cleanup, making driver mostly endian safe
78 * 0.29: 31 Aug 2004: Add backup timer for link change notification.
79 * 0.30: 25 Sep 2004: rx checksum support for nf 250 Gb. Add rx reset
80 * into nv_close, otherwise reenabling for wol can
81 * cause DMA to kfree'd memory.
82 * 0.31: 14 Nov 2004: ethtool support for getting/setting link
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050083 * capabilities.
Manfred Spraul22c6d142005-04-19 21:17:09 +020084 * 0.32: 16 Apr 2005: RX_ERROR4 handling added.
Manfred Spraul8f767fc2005-06-18 16:27:19 +020085 * 0.33: 16 May 2005: Support for MCP51 added.
86 * 0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics.
Manfred Spraulf49d16e2005-06-26 11:36:52 +020087 * 0.35: 26 Jun 2005: Support for MCP55 added.
Manfred Sprauldc8216c2005-07-31 18:26:05 +020088 * 0.36: 28 Jun 2005: Add jumbo frame support.
89 * 0.37: 10 Jul 2005: Additional ethtool support, cleanup of pci id list
Manfred Spraulc2dba062005-07-31 18:29:47 +020090 * 0.38: 16 Jul 2005: tx irq rewrite: Use global flags instead of
91 * per-packet flags.
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050092 * 0.39: 18 Jul 2005: Add 64bit descriptor support.
93 * 0.40: 19 Jul 2005: Add support for mac address change.
94 * 0.41: 30 Jul 2005: Write back original MAC in nv_close instead
Manfred Spraulb3df9f82005-07-31 18:38:58 +020095 * of nv_remove
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050096 * 0.42: 06 Aug 2005: Fix lack of link speed initialization
Manfred Spraul1b1b3c92005-08-06 23:47:55 +020097 * in the second (and later) nv_open call
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050098 * 0.43: 10 Aug 2005: Add support for tx checksum.
99 * 0.44: 20 Aug 2005: Add support for scatter gather and segmentation.
100 * 0.45: 18 Sep 2005: Remove nv_stop/start_rx from every link check
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500101 * 0.46: 20 Oct 2005: Add irq optimization modes.
Ayaz Abdulla7a33e452005-11-11 08:31:11 -0500102 * 0.47: 26 Oct 2005: Add phyaddr 0 in phy scan.
Manfred Spraul18360982005-12-24 14:19:24 +0100103 * 0.48: 24 Dec 2005: Disable TSO, bugfix for pci_map_single
Ayaz Abdullafa454592006-01-05 22:45:45 -0800104 * 0.49: 10 Dec 2005: Fix tso for large buffers.
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500105 * 0.50: 20 Jan 2006: Add 8021pq tagging support.
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500106 * 0.51: 20 Jan 2006: Add 64bit consistent memory allocation for rings.
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500107 * 0.52: 20 Jan 2006: Add MSI/MSIX support.
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400108 * 0.53: 19 Mar 2006: Fix init from low power mode and add hw reset.
Ayaz Abdulla84b39322006-05-20 14:59:48 -0700109 * 0.54: 21 Mar 2006: Fix spin locks for multi irqs and cleanup.
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400110 * 0.55: 22 Mar 2006: Add flow control (pause frame).
Ayaz Abdullaebe611a2006-06-10 22:48:24 -0400111 * 0.56: 22 Mar 2006: Additional ethtool config and moduleparam support.
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400112 * 0.57: 14 May 2006: Mac address set in probe/remove and order corrections.
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500113 * 0.58: 30 Oct 2006: Added support for sideband management unit.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 *
115 * Known bugs:
116 * We suspect that on some hardware no TX done interrupts are generated.
117 * This means recovery from netif_stop_queue only happens if the hw timer
118 * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
119 * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
120 * If your hardware reliably generates tx done interrupts, then you can remove
121 * DEV_NEED_TIMERIRQ from the driver_data flags.
122 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
123 * superfluous timer interrupts from the nic.
124 */
Stephen Hemmingere27cdba2006-07-31 20:37:19 -0700125#ifdef CONFIG_FORCEDETH_NAPI
126#define DRIVERNAPI "-NAPI"
127#else
128#define DRIVERNAPI
129#endif
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500130#define FORCEDETH_VERSION "0.58"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define DRV_NAME "forcedeth"
132
133#include <linux/module.h>
134#include <linux/types.h>
135#include <linux/pci.h>
136#include <linux/interrupt.h>
137#include <linux/netdevice.h>
138#include <linux/etherdevice.h>
139#include <linux/delay.h>
140#include <linux/spinlock.h>
141#include <linux/ethtool.h>
142#include <linux/timer.h>
143#include <linux/skbuff.h>
144#include <linux/mii.h>
145#include <linux/random.h>
146#include <linux/init.h>
Manfred Spraul22c6d142005-04-19 21:17:09 +0200147#include <linux/if_vlan.h>
Matthias Gehre910638a2006-03-28 01:56:48 -0800148#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150#include <asm/irq.h>
151#include <asm/io.h>
152#include <asm/uaccess.h>
153#include <asm/system.h>
154
155#if 0
156#define dprintk printk
157#else
158#define dprintk(x...) do { } while (0)
159#endif
160
161
162/*
163 * Hardware access:
164 */
165
Manfred Spraulc2dba062005-07-31 18:29:47 +0200166#define DEV_NEED_TIMERIRQ 0x0001 /* set the timer irq flag in the irq mask */
167#define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */
168#define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */
Manfred Spraulee733622005-07-31 18:32:26 +0200169#define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400170#define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500171#define DEV_HAS_VLAN 0x0020 /* device supports vlan tagging and striping */
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500172#define DEV_HAS_MSI 0x0040 /* device supports MSI */
173#define DEV_HAS_MSI_X 0x0080 /* device supports MSI-X */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400174#define DEV_HAS_POWER_CNTRL 0x0100 /* device supports power savings */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400175#define DEV_HAS_PAUSEFRAME_TX 0x0200 /* device supports tx pause frames */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400176#define DEV_HAS_STATISTICS 0x0400 /* device supports hw statistics */
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400177#define DEV_HAS_TEST_EXTENDED 0x0800 /* device supports extended diagnostic test */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500178#define DEV_HAS_MGMT_UNIT 0x1000 /* device supports management unit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180enum {
181 NvRegIrqStatus = 0x000,
182#define NVREG_IRQSTAT_MIIEVENT 0x040
183#define NVREG_IRQSTAT_MASK 0x1ff
184 NvRegIrqMask = 0x004,
185#define NVREG_IRQ_RX_ERROR 0x0001
186#define NVREG_IRQ_RX 0x0002
187#define NVREG_IRQ_RX_NOBUF 0x0004
188#define NVREG_IRQ_TX_ERR 0x0008
Manfred Spraulc2dba062005-07-31 18:29:47 +0200189#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#define NVREG_IRQ_TIMER 0x0020
191#define NVREG_IRQ_LINK 0x0040
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500192#define NVREG_IRQ_RX_FORCED 0x0080
193#define NVREG_IRQ_TX_FORCED 0x0100
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500194#define NVREG_IRQMASK_THROUGHPUT 0x00df
195#define NVREG_IRQMASK_CPU 0x0040
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500196#define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
197#define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED)
198#define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200199
200#define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500201 NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RX_FORCED| \
202 NVREG_IRQ_TX_FORCED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 NvRegUnknownSetupReg6 = 0x008,
205#define NVREG_UNKSETUP6_VAL 3
206
207/*
208 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
209 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
210 */
211 NvRegPollingInterval = 0x00c,
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500212#define NVREG_POLL_DEFAULT_THROUGHPUT 970
213#define NVREG_POLL_DEFAULT_CPU 13
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500214 NvRegMSIMap0 = 0x020,
215 NvRegMSIMap1 = 0x024,
216 NvRegMSIIrqMask = 0x030,
217#define NVREG_MSI_VECTOR_0_ENABLED 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 NvRegMisc1 = 0x080,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400219#define NVREG_MISC1_PAUSE_TX 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#define NVREG_MISC1_HD 0x02
221#define NVREG_MISC1_FORCE 0x3b0f3c
222
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400223 NvRegMacReset = 0x3c,
224#define NVREG_MAC_RESET_ASSERT 0x0F3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 NvRegTransmitterControl = 0x084,
226#define NVREG_XMITCTL_START 0x01
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500227#define NVREG_XMITCTL_MGMT_ST 0x40000000
228#define NVREG_XMITCTL_SYNC_MASK 0x000f0000
229#define NVREG_XMITCTL_SYNC_NOT_READY 0x0
230#define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
231#define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
232#define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
233#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
234#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
235#define NVREG_XMITCTL_HOST_LOADED 0x00004000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 NvRegTransmitterStatus = 0x088,
237#define NVREG_XMITSTAT_BUSY 0x01
238
239 NvRegPacketFilterFlags = 0x8c,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400240#define NVREG_PFF_PAUSE_RX 0x08
241#define NVREG_PFF_ALWAYS 0x7F0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define NVREG_PFF_PROMISC 0x80
243#define NVREG_PFF_MYADDR 0x20
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400244#define NVREG_PFF_LOOPBACK 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 NvRegOffloadConfig = 0x90,
247#define NVREG_OFFLOAD_HOMEPHY 0x601
248#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
249 NvRegReceiverControl = 0x094,
250#define NVREG_RCVCTL_START 0x01
251 NvRegReceiverStatus = 0x98,
252#define NVREG_RCVSTAT_BUSY 0x01
253
254 NvRegRandomSeed = 0x9c,
255#define NVREG_RNDSEED_MASK 0x00ff
256#define NVREG_RNDSEED_FORCE 0x7f00
257#define NVREG_RNDSEED_FORCE2 0x2d00
258#define NVREG_RNDSEED_FORCE3 0x7400
259
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400260 NvRegTxDeferral = 0xA0,
261#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
262#define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
263#define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
264 NvRegRxDeferral = 0xA4,
265#define NVREG_RX_DEFERRAL_DEFAULT 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 NvRegMacAddrA = 0xA8,
267 NvRegMacAddrB = 0xAC,
268 NvRegMulticastAddrA = 0xB0,
269#define NVREG_MCASTADDRA_FORCE 0x01
270 NvRegMulticastAddrB = 0xB4,
271 NvRegMulticastMaskA = 0xB8,
272 NvRegMulticastMaskB = 0xBC,
273
274 NvRegPhyInterface = 0xC0,
275#define PHY_RGMII 0x10000000
276
277 NvRegTxRingPhysAddr = 0x100,
278 NvRegRxRingPhysAddr = 0x104,
279 NvRegRingSizes = 0x108,
280#define NVREG_RINGSZ_TXSHIFT 0
281#define NVREG_RINGSZ_RXSHIFT 16
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400282 NvRegTransmitPoll = 0x10c,
283#define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 NvRegLinkSpeed = 0x110,
285#define NVREG_LINKSPEED_FORCE 0x10000
286#define NVREG_LINKSPEED_10 1000
287#define NVREG_LINKSPEED_100 100
288#define NVREG_LINKSPEED_1000 50
289#define NVREG_LINKSPEED_MASK (0xFFF)
290 NvRegUnknownSetupReg5 = 0x130,
291#define NVREG_UNKSETUP5_BIT31 (1<<31)
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400292 NvRegTxWatermark = 0x13c,
293#define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
294#define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
295#define NVREG_TX_WM_DESC2_3_1000 0xfe08000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 NvRegTxRxControl = 0x144,
297#define NVREG_TXRXCTL_KICK 0x0001
298#define NVREG_TXRXCTL_BIT1 0x0002
299#define NVREG_TXRXCTL_BIT2 0x0004
300#define NVREG_TXRXCTL_IDLE 0x0008
301#define NVREG_TXRXCTL_RESET 0x0010
302#define NVREG_TXRXCTL_RXCHECK 0x0400
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400303#define NVREG_TXRXCTL_DESC_1 0
304#define NVREG_TXRXCTL_DESC_2 0x02100
305#define NVREG_TXRXCTL_DESC_3 0x02200
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500306#define NVREG_TXRXCTL_VLANSTRIP 0x00040
307#define NVREG_TXRXCTL_VLANINS 0x00080
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500308 NvRegTxRingPhysAddrHigh = 0x148,
309 NvRegRxRingPhysAddrHigh = 0x14C,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400310 NvRegTxPauseFrame = 0x170,
311#define NVREG_TX_PAUSEFRAME_DISABLE 0x1ff0080
312#define NVREG_TX_PAUSEFRAME_ENABLE 0x0c00030
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 NvRegMIIStatus = 0x180,
314#define NVREG_MIISTAT_ERROR 0x0001
315#define NVREG_MIISTAT_LINKCHANGE 0x0008
316#define NVREG_MIISTAT_MASK 0x000f
317#define NVREG_MIISTAT_MASK2 0x000f
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500318 NvRegMIIMask = 0x184,
319#define NVREG_MII_LINKCHANGE 0x0008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 NvRegAdapterControl = 0x188,
322#define NVREG_ADAPTCTL_START 0x02
323#define NVREG_ADAPTCTL_LINKUP 0x04
324#define NVREG_ADAPTCTL_PHYVALID 0x40000
325#define NVREG_ADAPTCTL_RUNNING 0x100000
326#define NVREG_ADAPTCTL_PHYSHIFT 24
327 NvRegMIISpeed = 0x18c,
328#define NVREG_MIISPEED_BIT8 (1<<8)
329#define NVREG_MIIDELAY 5
330 NvRegMIIControl = 0x190,
331#define NVREG_MIICTL_INUSE 0x08000
332#define NVREG_MIICTL_WRITE 0x00400
333#define NVREG_MIICTL_ADDRSHIFT 5
334 NvRegMIIData = 0x194,
335 NvRegWakeUpFlags = 0x200,
336#define NVREG_WAKEUPFLAGS_VAL 0x7770
337#define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
338#define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
339#define NVREG_WAKEUPFLAGS_D3SHIFT 12
340#define NVREG_WAKEUPFLAGS_D2SHIFT 8
341#define NVREG_WAKEUPFLAGS_D1SHIFT 4
342#define NVREG_WAKEUPFLAGS_D0SHIFT 0
343#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
344#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
345#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
346#define NVREG_WAKEUPFLAGS_ENABLE 0x1111
347
348 NvRegPatternCRC = 0x204,
349 NvRegPatternMask = 0x208,
350 NvRegPowerCap = 0x268,
351#define NVREG_POWERCAP_D3SUPP (1<<30)
352#define NVREG_POWERCAP_D2SUPP (1<<26)
353#define NVREG_POWERCAP_D1SUPP (1<<25)
354 NvRegPowerState = 0x26c,
355#define NVREG_POWERSTATE_POWEREDUP 0x8000
356#define NVREG_POWERSTATE_VALID 0x0100
357#define NVREG_POWERSTATE_MASK 0x0003
358#define NVREG_POWERSTATE_D0 0x0000
359#define NVREG_POWERSTATE_D1 0x0001
360#define NVREG_POWERSTATE_D2 0x0002
361#define NVREG_POWERSTATE_D3 0x0003
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400362 NvRegTxCnt = 0x280,
363 NvRegTxZeroReXmt = 0x284,
364 NvRegTxOneReXmt = 0x288,
365 NvRegTxManyReXmt = 0x28c,
366 NvRegTxLateCol = 0x290,
367 NvRegTxUnderflow = 0x294,
368 NvRegTxLossCarrier = 0x298,
369 NvRegTxExcessDef = 0x29c,
370 NvRegTxRetryErr = 0x2a0,
371 NvRegRxFrameErr = 0x2a4,
372 NvRegRxExtraByte = 0x2a8,
373 NvRegRxLateCol = 0x2ac,
374 NvRegRxRunt = 0x2b0,
375 NvRegRxFrameTooLong = 0x2b4,
376 NvRegRxOverflow = 0x2b8,
377 NvRegRxFCSErr = 0x2bc,
378 NvRegRxFrameAlignErr = 0x2c0,
379 NvRegRxLenErr = 0x2c4,
380 NvRegRxUnicast = 0x2c8,
381 NvRegRxMulticast = 0x2cc,
382 NvRegRxBroadcast = 0x2d0,
383 NvRegTxDef = 0x2d4,
384 NvRegTxFrame = 0x2d8,
385 NvRegRxCnt = 0x2dc,
386 NvRegTxPause = 0x2e0,
387 NvRegRxPause = 0x2e4,
388 NvRegRxDropFrame = 0x2e8,
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500389 NvRegVlanControl = 0x300,
390#define NVREG_VLANCONTROL_ENABLE 0x2000
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500391 NvRegMSIXMap0 = 0x3e0,
392 NvRegMSIXMap1 = 0x3e4,
393 NvRegMSIXIrqStatus = 0x3f0,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400394
395 NvRegPowerState2 = 0x600,
396#define NVREG_POWERSTATE2_POWERUP_MASK 0x0F11
397#define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398};
399
400/* Big endian: should work, but is untested */
401struct ring_desc {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700402 __le32 buf;
403 __le32 flaglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404};
405
Manfred Spraulee733622005-07-31 18:32:26 +0200406struct ring_desc_ex {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700407 __le32 bufhigh;
408 __le32 buflow;
409 __le32 txvlan;
410 __le32 flaglen;
Manfred Spraulee733622005-07-31 18:32:26 +0200411};
412
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700413union ring_type {
Manfred Spraulee733622005-07-31 18:32:26 +0200414 struct ring_desc* orig;
415 struct ring_desc_ex* ex;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700416};
Manfred Spraulee733622005-07-31 18:32:26 +0200417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#define FLAG_MASK_V1 0xffff0000
419#define FLAG_MASK_V2 0xffffc000
420#define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
421#define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
422
423#define NV_TX_LASTPACKET (1<<16)
424#define NV_TX_RETRYERROR (1<<19)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200425#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NV_TX_DEFERRED (1<<26)
427#define NV_TX_CARRIERLOST (1<<27)
428#define NV_TX_LATECOLLISION (1<<28)
429#define NV_TX_UNDERFLOW (1<<29)
430#define NV_TX_ERROR (1<<30)
431#define NV_TX_VALID (1<<31)
432
433#define NV_TX2_LASTPACKET (1<<29)
434#define NV_TX2_RETRYERROR (1<<18)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200435#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NV_TX2_DEFERRED (1<<25)
437#define NV_TX2_CARRIERLOST (1<<26)
438#define NV_TX2_LATECOLLISION (1<<27)
439#define NV_TX2_UNDERFLOW (1<<28)
440/* error and valid are the same for both */
441#define NV_TX2_ERROR (1<<30)
442#define NV_TX2_VALID (1<<31)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400443#define NV_TX2_TSO (1<<28)
444#define NV_TX2_TSO_SHIFT 14
Ayaz Abdullafa454592006-01-05 22:45:45 -0800445#define NV_TX2_TSO_MAX_SHIFT 14
446#define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400447#define NV_TX2_CHECKSUM_L3 (1<<27)
448#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500450#define NV_TX3_VLAN_TAG_PRESENT (1<<18)
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#define NV_RX_DESCRIPTORVALID (1<<16)
453#define NV_RX_MISSEDFRAME (1<<17)
454#define NV_RX_SUBSTRACT1 (1<<18)
455#define NV_RX_ERROR1 (1<<23)
456#define NV_RX_ERROR2 (1<<24)
457#define NV_RX_ERROR3 (1<<25)
458#define NV_RX_ERROR4 (1<<26)
459#define NV_RX_CRCERR (1<<27)
460#define NV_RX_OVERFLOW (1<<28)
461#define NV_RX_FRAMINGERR (1<<29)
462#define NV_RX_ERROR (1<<30)
463#define NV_RX_AVAIL (1<<31)
464
465#define NV_RX2_CHECKSUMMASK (0x1C000000)
466#define NV_RX2_CHECKSUMOK1 (0x10000000)
467#define NV_RX2_CHECKSUMOK2 (0x14000000)
468#define NV_RX2_CHECKSUMOK3 (0x18000000)
469#define NV_RX2_DESCRIPTORVALID (1<<29)
470#define NV_RX2_SUBSTRACT1 (1<<25)
471#define NV_RX2_ERROR1 (1<<18)
472#define NV_RX2_ERROR2 (1<<19)
473#define NV_RX2_ERROR3 (1<<20)
474#define NV_RX2_ERROR4 (1<<21)
475#define NV_RX2_CRCERR (1<<22)
476#define NV_RX2_OVERFLOW (1<<23)
477#define NV_RX2_FRAMINGERR (1<<24)
478/* error and avail are the same for both */
479#define NV_RX2_ERROR (1<<30)
480#define NV_RX2_AVAIL (1<<31)
481
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500482#define NV_RX3_VLAN_TAG_PRESENT (1<<16)
483#define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485/* Miscelaneous hardware related defines: */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400486#define NV_PCI_REGSZ_VER1 0x270
487#define NV_PCI_REGSZ_VER2 0x604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489/* various timeout delays: all in usec */
490#define NV_TXRX_RESET_DELAY 4
491#define NV_TXSTOP_DELAY1 10
492#define NV_TXSTOP_DELAY1MAX 500000
493#define NV_TXSTOP_DELAY2 100
494#define NV_RXSTOP_DELAY1 10
495#define NV_RXSTOP_DELAY1MAX 500000
496#define NV_RXSTOP_DELAY2 100
497#define NV_SETUP5_DELAY 5
498#define NV_SETUP5_DELAYMAX 50000
499#define NV_POWERUP_DELAY 5
500#define NV_POWERUP_DELAYMAX 5000
501#define NV_MIIBUSY_DELAY 50
502#define NV_MIIPHY_DELAY 10
503#define NV_MIIPHY_DELAYMAX 10000
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400504#define NV_MAC_RESET_DELAY 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506#define NV_WAKEUPPATTERNS 5
507#define NV_WAKEUPMASKENTRIES 4
508
509/* General driver defaults */
510#define NV_WATCHDOG_TIMEO (5*HZ)
511
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400512#define RX_RING_DEFAULT 128
513#define TX_RING_DEFAULT 256
514#define RX_RING_MIN 128
515#define TX_RING_MIN 64
516#define RING_MAX_DESC_VER_1 1024
517#define RING_MAX_DESC_VER_2_3 16384
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400518/*
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400519 * Difference between the get and put pointers for the tx ring.
520 * This is used to throttle the amount of data outstanding in the
521 * tx ring.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400523#define TX_LIMIT_DIFFERENCE 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200526#define NV_RX_HEADERS (64)
527/* even more slack. */
528#define NV_RX_ALLOC_PAD (64)
529
530/* maximum mtu size */
531#define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
532#define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534#define OOM_REFILL (1+HZ/20)
535#define POLL_WAIT (1+HZ/100)
536#define LINK_TIMEOUT (3*HZ)
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400537#define STATS_INTERVAL (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400539/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400541 * The nic supports three different descriptor types:
542 * - DESC_VER_1: Original
543 * - DESC_VER_2: support for jumbo frames.
544 * - DESC_VER_3: 64-bit format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400546#define DESC_VER_1 1
547#define DESC_VER_2 2
548#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550/* PHY defines */
551#define PHY_OUI_MARVELL 0x5043
552#define PHY_OUI_CICADA 0x03f1
553#define PHYID1_OUI_MASK 0x03ff
554#define PHYID1_OUI_SHFT 6
555#define PHYID2_OUI_MASK 0xfc00
556#define PHYID2_OUI_SHFT 10
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400557#define PHYID2_MODEL_MASK 0x03f0
558#define PHY_MODEL_MARVELL_E3016 0x220
559#define PHY_MARVELL_E3016_INITMASK 0x0300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define PHY_INIT1 0x0f000
561#define PHY_INIT2 0x0e00
562#define PHY_INIT3 0x01000
563#define PHY_INIT4 0x0200
564#define PHY_INIT5 0x0004
565#define PHY_INIT6 0x02000
566#define PHY_GIGABIT 0x0100
567
568#define PHY_TIMEOUT 0x1
569#define PHY_ERROR 0x2
570
571#define PHY_100 0x1
572#define PHY_1000 0x2
573#define PHY_HALF 0x100
574
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400575#define NV_PAUSEFRAME_RX_CAPABLE 0x0001
576#define NV_PAUSEFRAME_TX_CAPABLE 0x0002
577#define NV_PAUSEFRAME_RX_ENABLE 0x0004
578#define NV_PAUSEFRAME_TX_ENABLE 0x0008
Ayaz Abdullab6d07732006-06-10 22:47:42 -0400579#define NV_PAUSEFRAME_RX_REQ 0x0010
580#define NV_PAUSEFRAME_TX_REQ 0x0020
581#define NV_PAUSEFRAME_AUTONEG 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500583/* MSI/MSI-X defines */
584#define NV_MSI_X_MAX_VECTORS 8
585#define NV_MSI_X_VECTORS_MASK 0x000f
586#define NV_MSI_CAPABLE 0x0010
587#define NV_MSI_X_CAPABLE 0x0020
588#define NV_MSI_ENABLED 0x0040
589#define NV_MSI_X_ENABLED 0x0080
590
591#define NV_MSI_X_VECTOR_ALL 0x0
592#define NV_MSI_X_VECTOR_RX 0x0
593#define NV_MSI_X_VECTOR_TX 0x1
594#define NV_MSI_X_VECTOR_OTHER 0x2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400596/* statistics */
597struct nv_ethtool_str {
598 char name[ETH_GSTRING_LEN];
599};
600
601static const struct nv_ethtool_str nv_estats_str[] = {
602 { "tx_bytes" },
603 { "tx_zero_rexmt" },
604 { "tx_one_rexmt" },
605 { "tx_many_rexmt" },
606 { "tx_late_collision" },
607 { "tx_fifo_errors" },
608 { "tx_carrier_errors" },
609 { "tx_excess_deferral" },
610 { "tx_retry_error" },
611 { "tx_deferral" },
612 { "tx_packets" },
613 { "tx_pause" },
614 { "rx_frame_error" },
615 { "rx_extra_byte" },
616 { "rx_late_collision" },
617 { "rx_runt" },
618 { "rx_frame_too_long" },
619 { "rx_over_errors" },
620 { "rx_crc_errors" },
621 { "rx_frame_align_error" },
622 { "rx_length_error" },
623 { "rx_unicast" },
624 { "rx_multicast" },
625 { "rx_broadcast" },
626 { "rx_bytes" },
627 { "rx_pause" },
628 { "rx_drop_frame" },
629 { "rx_packets" },
630 { "rx_errors_total" }
631};
632
633struct nv_ethtool_stats {
634 u64 tx_bytes;
635 u64 tx_zero_rexmt;
636 u64 tx_one_rexmt;
637 u64 tx_many_rexmt;
638 u64 tx_late_collision;
639 u64 tx_fifo_errors;
640 u64 tx_carrier_errors;
641 u64 tx_excess_deferral;
642 u64 tx_retry_error;
643 u64 tx_deferral;
644 u64 tx_packets;
645 u64 tx_pause;
646 u64 rx_frame_error;
647 u64 rx_extra_byte;
648 u64 rx_late_collision;
649 u64 rx_runt;
650 u64 rx_frame_too_long;
651 u64 rx_over_errors;
652 u64 rx_crc_errors;
653 u64 rx_frame_align_error;
654 u64 rx_length_error;
655 u64 rx_unicast;
656 u64 rx_multicast;
657 u64 rx_broadcast;
658 u64 rx_bytes;
659 u64 rx_pause;
660 u64 rx_drop_frame;
661 u64 rx_packets;
662 u64 rx_errors_total;
663};
664
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400665/* diagnostics */
666#define NV_TEST_COUNT_BASE 3
667#define NV_TEST_COUNT_EXTENDED 4
668
669static const struct nv_ethtool_str nv_etests_str[] = {
670 { "link (online/offline)" },
671 { "register (offline) " },
672 { "interrupt (offline) " },
673 { "loopback (offline) " }
674};
675
676struct register_test {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700677 __le32 reg;
678 __le32 mask;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400679};
680
681static const struct register_test nv_registers_test[] = {
682 { NvRegUnknownSetupReg6, 0x01 },
683 { NvRegMisc1, 0x03c },
684 { NvRegOffloadConfig, 0x03ff },
685 { NvRegMulticastAddrA, 0xffffffff },
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400686 { NvRegTxWatermark, 0x0ff },
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400687 { NvRegWakeUpFlags, 0x07777 },
688 { 0,0 }
689};
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691/*
692 * SMP locking:
693 * All hardware access under dev->priv->lock, except the performance
694 * critical parts:
695 * - rx is (pseudo-) lockless: it relies on the single-threading provided
696 * by the arch code for interrupts.
Herbert Xu932ff272006-06-09 12:20:56 -0700697 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 * needs dev->priv->lock :-(
Herbert Xu932ff272006-06-09 12:20:56 -0700699 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 */
701
702/* in dev: base, irq */
703struct fe_priv {
704 spinlock_t lock;
705
706 /* General data:
707 * Locking: spin_lock(&np->lock); */
708 struct net_device_stats stats;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400709 struct nv_ethtool_stats estats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 int in_shutdown;
711 u32 linkspeed;
712 int duplex;
713 int autoneg;
714 int fixed_mode;
715 int phyaddr;
716 int wolenabled;
717 unsigned int phy_oui;
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400718 unsigned int phy_model;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 u16 gigabit;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400720 int intr_test;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 /* General data: RO fields */
723 dma_addr_t ring_addr;
724 struct pci_dev *pci_dev;
725 u32 orig_mac[2];
726 u32 irqmask;
727 u32 desc_ver;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400728 u32 txrxctl_bits;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500729 u32 vlanctl_bits;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400730 u32 driver_data;
731 u32 register_size;
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -0400732 int rx_csum;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500733 u32 mac_in_use;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 void __iomem *base;
736
737 /* rx specific fields.
738 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
739 */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700740 union ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 unsigned int cur_rx, refill_rx;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400742 struct sk_buff **rx_skbuff;
743 dma_addr_t *rx_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200745 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 struct timer_list oom_kick;
747 struct timer_list nic_poll;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400748 struct timer_list stats_poll;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500749 u32 nic_poll_irq;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400750 int rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 /* media detection workaround.
753 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
754 */
755 int need_linktimer;
756 unsigned long link_timeout;
757 /*
758 * tx specific fields.
759 */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700760 union ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 unsigned int next_tx, nic_tx;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400762 struct sk_buff **tx_skbuff;
763 dma_addr_t *tx_dma;
764 unsigned int *tx_dma_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 u32 tx_flags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400766 int tx_ring_size;
767 int tx_limit_start;
768 int tx_limit_stop;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500769
770 /* vlan fields */
771 struct vlan_group *vlangrp;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500772
773 /* msi/msi-x fields */
774 u32 msi_flags;
775 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400776
777 /* flow control */
778 u32 pause_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779};
780
781/*
782 * Maximum number of loops until we assume that a bit in the irq mask
783 * is stuck. Overridable with module param.
784 */
785static int max_interrupt_work = 5;
786
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500787/*
788 * Optimization can be either throuput mode or cpu mode
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400789 *
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500790 * Throughput Mode: Every tx and rx packet will generate an interrupt.
791 * CPU Mode: Interrupts are controlled by a timer.
792 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400793enum {
794 NV_OPTIMIZATION_MODE_THROUGHPUT,
795 NV_OPTIMIZATION_MODE_CPU
796};
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500797static int optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
798
799/*
800 * Poll interval for timer irq
801 *
802 * This interval determines how frequent an interrupt is generated.
803 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
804 * Min = 0, and Max = 65535
805 */
806static int poll_interval = -1;
807
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500808/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400809 * MSI interrupts
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500810 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400811enum {
812 NV_MSI_INT_DISABLED,
813 NV_MSI_INT_ENABLED
814};
815static int msi = NV_MSI_INT_ENABLED;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500816
817/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400818 * MSIX interrupts
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500819 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400820enum {
821 NV_MSIX_INT_DISABLED,
822 NV_MSIX_INT_ENABLED
823};
824static int msix = NV_MSIX_INT_ENABLED;
825
826/*
827 * DMA 64bit
828 */
829enum {
830 NV_DMA_64BIT_DISABLED,
831 NV_DMA_64BIT_ENABLED
832};
833static int dma_64bit = NV_DMA_64BIT_ENABLED;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -0500834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835static inline struct fe_priv *get_nvpriv(struct net_device *dev)
836{
837 return netdev_priv(dev);
838}
839
840static inline u8 __iomem *get_hwbase(struct net_device *dev)
841{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400842 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
845static inline void pci_push(u8 __iomem *base)
846{
847 /* force out pending posted writes */
848 readl(base);
849}
850
851static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
852{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700853 return le32_to_cpu(prd->flaglen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
855}
856
Manfred Spraulee733622005-07-31 18:32:26 +0200857static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
858{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700859 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
Manfred Spraulee733622005-07-31 18:32:26 +0200860}
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
863 int delay, int delaymax, const char *msg)
864{
865 u8 __iomem *base = get_hwbase(dev);
866
867 pci_push(base);
868 do {
869 udelay(delay);
870 delaymax -= delay;
871 if (delaymax < 0) {
872 if (msg)
873 printk(msg);
874 return 1;
875 }
876 } while ((readl(base + offset) & mask) != target);
877 return 0;
878}
879
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500880#define NV_SETUP_RX_RING 0x01
881#define NV_SETUP_TX_RING 0x02
882
883static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
884{
885 struct fe_priv *np = get_nvpriv(dev);
886 u8 __iomem *base = get_hwbase(dev);
887
888 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
889 if (rxtx_flags & NV_SETUP_RX_RING) {
890 writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr);
891 }
892 if (rxtx_flags & NV_SETUP_TX_RING) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400893 writel((u32) cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500894 }
895 } else {
896 if (rxtx_flags & NV_SETUP_RX_RING) {
897 writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr);
898 writel((u32) (cpu_to_le64(np->ring_addr) >> 32), base + NvRegRxRingPhysAddrHigh);
899 }
900 if (rxtx_flags & NV_SETUP_TX_RING) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400901 writel((u32) cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
902 writel((u32) (cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)) >> 32), base + NvRegTxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500903 }
904 }
905}
906
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400907static void free_rings(struct net_device *dev)
908{
909 struct fe_priv *np = get_nvpriv(dev);
910
911 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700912 if (np->rx_ring.orig)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400913 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
914 np->rx_ring.orig, np->ring_addr);
915 } else {
916 if (np->rx_ring.ex)
917 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
918 np->rx_ring.ex, np->ring_addr);
919 }
920 if (np->rx_skbuff)
921 kfree(np->rx_skbuff);
922 if (np->rx_dma)
923 kfree(np->rx_dma);
924 if (np->tx_skbuff)
925 kfree(np->tx_skbuff);
926 if (np->tx_dma)
927 kfree(np->tx_dma);
928 if (np->tx_dma_len)
929 kfree(np->tx_dma_len);
930}
931
Ayaz Abdulla84b39322006-05-20 14:59:48 -0700932static int using_multi_irqs(struct net_device *dev)
933{
934 struct fe_priv *np = get_nvpriv(dev);
935
936 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
937 ((np->msi_flags & NV_MSI_X_ENABLED) &&
938 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
939 return 0;
940 else
941 return 1;
942}
943
944static void nv_enable_irq(struct net_device *dev)
945{
946 struct fe_priv *np = get_nvpriv(dev);
947
948 if (!using_multi_irqs(dev)) {
949 if (np->msi_flags & NV_MSI_X_ENABLED)
950 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
951 else
952 enable_irq(dev->irq);
953 } else {
954 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
955 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
956 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
957 }
958}
959
960static void nv_disable_irq(struct net_device *dev)
961{
962 struct fe_priv *np = get_nvpriv(dev);
963
964 if (!using_multi_irqs(dev)) {
965 if (np->msi_flags & NV_MSI_X_ENABLED)
966 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
967 else
968 disable_irq(dev->irq);
969 } else {
970 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
971 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
972 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
973 }
974}
975
976/* In MSIX mode, a write to irqmask behaves as XOR */
977static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
978{
979 u8 __iomem *base = get_hwbase(dev);
980
981 writel(mask, base + NvRegIrqMask);
982}
983
984static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
985{
986 struct fe_priv *np = get_nvpriv(dev);
987 u8 __iomem *base = get_hwbase(dev);
988
989 if (np->msi_flags & NV_MSI_X_ENABLED) {
990 writel(mask, base + NvRegIrqMask);
991 } else {
992 if (np->msi_flags & NV_MSI_ENABLED)
993 writel(0, base + NvRegMSIIrqMask);
994 writel(0, base + NvRegIrqMask);
995 }
996}
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998#define MII_READ (-1)
999/* mii_rw: read/write a register on the PHY.
1000 *
1001 * Caller must guarantee serialization
1002 */
1003static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1004{
1005 u8 __iomem *base = get_hwbase(dev);
1006 u32 reg;
1007 int retval;
1008
1009 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
1010
1011 reg = readl(base + NvRegMIIControl);
1012 if (reg & NVREG_MIICTL_INUSE) {
1013 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1014 udelay(NV_MIIBUSY_DELAY);
1015 }
1016
1017 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1018 if (value != MII_READ) {
1019 writel(value, base + NvRegMIIData);
1020 reg |= NVREG_MIICTL_WRITE;
1021 }
1022 writel(reg, base + NvRegMIIControl);
1023
1024 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
1025 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
1026 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n",
1027 dev->name, miireg, addr);
1028 retval = -1;
1029 } else if (value != MII_READ) {
1030 /* it was a write operation - fewer failures are detectable */
1031 dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
1032 dev->name, value, miireg, addr);
1033 retval = 0;
1034 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
1035 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n",
1036 dev->name, miireg, addr);
1037 retval = -1;
1038 } else {
1039 retval = readl(base + NvRegMIIData);
1040 dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
1041 dev->name, miireg, addr, retval);
1042 }
1043
1044 return retval;
1045}
1046
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001047static int phy_reset(struct net_device *dev, u32 bmcr_setup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001049 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 u32 miicontrol;
1051 unsigned int tries = 0;
1052
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001053 miicontrol = BMCR_RESET | bmcr_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) {
1055 return -1;
1056 }
1057
1058 /* wait for 500ms */
1059 msleep(500);
1060
1061 /* must wait till reset is deasserted */
1062 while (miicontrol & BMCR_RESET) {
1063 msleep(10);
1064 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1065 /* FIXME: 100 tries seem excessive */
1066 if (tries++ > 100)
1067 return -1;
1068 }
1069 return 0;
1070}
1071
1072static int phy_init(struct net_device *dev)
1073{
1074 struct fe_priv *np = get_nvpriv(dev);
1075 u8 __iomem *base = get_hwbase(dev);
1076 u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg;
1077
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001078 /* phy errata for E3016 phy */
1079 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1080 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1081 reg &= ~PHY_MARVELL_E3016_INITMASK;
1082 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
1083 printk(KERN_INFO "%s: phy write to errata reg failed.\n", pci_name(np->pci_dev));
1084 return PHY_ERROR;
1085 }
1086 }
1087
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 /* set advertise register */
1089 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001090 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|ADVERTISE_PAUSE_ASYM|ADVERTISE_PAUSE_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
1092 printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev));
1093 return PHY_ERROR;
1094 }
1095
1096 /* get phy interface type */
1097 phyinterface = readl(base + NvRegPhyInterface);
1098
1099 /* see if gigabit phy */
1100 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1101 if (mii_status & PHY_GIGABIT) {
1102 np->gigabit = PHY_GIGABIT;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001103 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 mii_control_1000 &= ~ADVERTISE_1000HALF;
1105 if (phyinterface & PHY_RGMII)
1106 mii_control_1000 |= ADVERTISE_1000FULL;
1107 else
1108 mii_control_1000 &= ~ADVERTISE_1000FULL;
1109
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001110 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1112 return PHY_ERROR;
1113 }
1114 }
1115 else
1116 np->gigabit = 0;
1117
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001118 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1119 mii_control |= BMCR_ANENABLE;
1120
1121 /* reset the phy
1122 * (certain phys need bmcr to be setup with reset)
1123 */
1124 if (phy_reset(dev, mii_control)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev));
1126 return PHY_ERROR;
1127 }
1128
1129 /* phy vendor specific configuration */
1130 if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) {
1131 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
1132 phy_reserved &= ~(PHY_INIT1 | PHY_INIT2);
1133 phy_reserved |= (PHY_INIT3 | PHY_INIT4);
1134 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) {
1135 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1136 return PHY_ERROR;
1137 }
1138 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1139 phy_reserved |= PHY_INIT5;
1140 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) {
1141 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1142 return PHY_ERROR;
1143 }
1144 }
1145 if (np->phy_oui == PHY_OUI_CICADA) {
1146 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
1147 phy_reserved |= PHY_INIT6;
1148 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) {
1149 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1150 return PHY_ERROR;
1151 }
1152 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001153 /* some phys clear out pause advertisment on reset, set it back */
1154 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
1156 /* restart auto negotiation */
1157 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1158 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
1159 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
1160 return PHY_ERROR;
1161 }
1162
1163 return 0;
1164}
1165
1166static void nv_start_rx(struct net_device *dev)
1167{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001168 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 u8 __iomem *base = get_hwbase(dev);
1170
1171 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
1172 /* Already running? Stop it. */
1173 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
1174 writel(0, base + NvRegReceiverControl);
1175 pci_push(base);
1176 }
1177 writel(np->linkspeed, base + NvRegLinkSpeed);
1178 pci_push(base);
1179 writel(NVREG_RCVCTL_START, base + NvRegReceiverControl);
1180 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
1181 dev->name, np->duplex, np->linkspeed);
1182 pci_push(base);
1183}
1184
1185static void nv_stop_rx(struct net_device *dev)
1186{
1187 u8 __iomem *base = get_hwbase(dev);
1188
1189 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
1190 writel(0, base + NvRegReceiverControl);
1191 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1192 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
1193 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
1194
1195 udelay(NV_RXSTOP_DELAY2);
1196 writel(0, base + NvRegLinkSpeed);
1197}
1198
1199static void nv_start_tx(struct net_device *dev)
1200{
1201 u8 __iomem *base = get_hwbase(dev);
1202
1203 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
1204 writel(NVREG_XMITCTL_START, base + NvRegTransmitterControl);
1205 pci_push(base);
1206}
1207
1208static void nv_stop_tx(struct net_device *dev)
1209{
1210 u8 __iomem *base = get_hwbase(dev);
1211
1212 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
1213 writel(0, base + NvRegTransmitterControl);
1214 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1215 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
1216 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
1217
1218 udelay(NV_TXSTOP_DELAY2);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04001219 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
1222static void nv_txrx_reset(struct net_device *dev)
1223{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001224 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 u8 __iomem *base = get_hwbase(dev);
1226
1227 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001228 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 pci_push(base);
1230 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001231 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 pci_push(base);
1233}
1234
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001235static void nv_mac_reset(struct net_device *dev)
1236{
1237 struct fe_priv *np = netdev_priv(dev);
1238 u8 __iomem *base = get_hwbase(dev);
1239
1240 dprintk(KERN_DEBUG "%s: nv_mac_reset\n", dev->name);
1241 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1242 pci_push(base);
1243 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1244 pci_push(base);
1245 udelay(NV_MAC_RESET_DELAY);
1246 writel(0, base + NvRegMacReset);
1247 pci_push(base);
1248 udelay(NV_MAC_RESET_DELAY);
1249 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1250 pci_push(base);
1251}
1252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253/*
1254 * nv_get_stats: dev->get_stats function
1255 * Get latest stats value from the nic.
1256 * Called with read_lock(&dev_base_lock) held for read -
1257 * only synchronized against unregister_netdevice.
1258 */
1259static struct net_device_stats *nv_get_stats(struct net_device *dev)
1260{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001261 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263 /* It seems that the nic always generates interrupts and doesn't
1264 * accumulate errors internally. Thus the current values in np->stats
1265 * are already up to date.
1266 */
1267 return &np->stats;
1268}
1269
1270/*
1271 * nv_alloc_rx: fill rx ring entries.
1272 * Return 1 if the allocations for the skbs failed and the
1273 * rx engine is without Available descriptors
1274 */
1275static int nv_alloc_rx(struct net_device *dev)
1276{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001277 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 unsigned int refill_rx = np->refill_rx;
1279 int nr;
1280
1281 while (np->cur_rx != refill_rx) {
1282 struct sk_buff *skb;
1283
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001284 nr = refill_rx % np->rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 if (np->rx_skbuff[nr] == NULL) {
1286
Manfred Sprauld81c0982005-07-31 18:20:30 +02001287 skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 if (!skb)
1289 break;
1290
1291 skb->dev = dev;
1292 np->rx_skbuff[nr] = skb;
1293 } else {
1294 skb = np->rx_skbuff[nr];
1295 }
Manfred Spraul18360982005-12-24 14:19:24 +01001296 np->rx_dma[nr] = pci_map_single(np->pci_dev, skb->data,
1297 skb->end-skb->data, PCI_DMA_FROMDEVICE);
Manfred Spraulee733622005-07-31 18:32:26 +02001298 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001299 np->rx_ring.orig[nr].buf = cpu_to_le32(np->rx_dma[nr]);
Manfred Spraulee733622005-07-31 18:32:26 +02001300 wmb();
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001301 np->rx_ring.orig[nr].flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
Manfred Spraulee733622005-07-31 18:32:26 +02001302 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001303 np->rx_ring.ex[nr].bufhigh = cpu_to_le64(np->rx_dma[nr]) >> 32;
1304 np->rx_ring.ex[nr].buflow = cpu_to_le64(np->rx_dma[nr]) & 0x0FFFFFFFF;
Manfred Spraulee733622005-07-31 18:32:26 +02001305 wmb();
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001306 np->rx_ring.ex[nr].flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
Manfred Spraulee733622005-07-31 18:32:26 +02001307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 dprintk(KERN_DEBUG "%s: nv_alloc_rx: Packet %d marked as Available\n",
1309 dev->name, refill_rx);
1310 refill_rx++;
1311 }
1312 np->refill_rx = refill_rx;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001313 if (np->cur_rx - refill_rx == np->rx_ring_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 return 1;
1315 return 0;
1316}
1317
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001318/* If rx bufs are exhausted called after 50ms to attempt to refresh */
1319#ifdef CONFIG_FORCEDETH_NAPI
1320static void nv_do_rx_refill(unsigned long data)
1321{
1322 struct net_device *dev = (struct net_device *) data;
1323
1324 /* Just reschedule NAPI rx processing */
1325 netif_rx_schedule(dev);
1326}
1327#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328static void nv_do_rx_refill(unsigned long data)
1329{
1330 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001331 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001333 if (!using_multi_irqs(dev)) {
1334 if (np->msi_flags & NV_MSI_X_ENABLED)
1335 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1336 else
1337 disable_irq(dev->irq);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05001338 } else {
1339 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 if (nv_alloc_rx(dev)) {
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001342 spin_lock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 if (!np->in_shutdown)
1344 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001345 spin_unlock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001347 if (!using_multi_irqs(dev)) {
1348 if (np->msi_flags & NV_MSI_X_ENABLED)
1349 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1350 else
1351 enable_irq(dev->irq);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05001352 } else {
1353 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001356#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001358static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001359{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001360 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001361 int i;
1362
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001363 np->cur_rx = np->rx_ring_size;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001364 np->refill_rx = 0;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001365 for (i = 0; i < np->rx_ring_size; i++)
Manfred Spraulee733622005-07-31 18:32:26 +02001366 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001367 np->rx_ring.orig[i].flaglen = 0;
Manfred Spraulee733622005-07-31 18:32:26 +02001368 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001369 np->rx_ring.ex[i].flaglen = 0;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001370}
1371
1372static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001374 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 int i;
1376
1377 np->next_tx = np->nic_tx = 0;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001378 for (i = 0; i < np->tx_ring_size; i++) {
Manfred Spraulee733622005-07-31 18:32:26 +02001379 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001380 np->tx_ring.orig[i].flaglen = 0;
Manfred Spraulee733622005-07-31 18:32:26 +02001381 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001382 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001383 np->tx_skbuff[i] = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001384 np->tx_dma[i] = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001385 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001386}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Manfred Sprauld81c0982005-07-31 18:20:30 +02001388static int nv_init_ring(struct net_device *dev)
1389{
1390 nv_init_tx(dev);
1391 nv_init_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 return nv_alloc_rx(dev);
1393}
1394
Ayaz Abdullafa454592006-01-05 22:45:45 -08001395static int nv_release_txskb(struct net_device *dev, unsigned int skbnr)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001396{
1397 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001398
1399 dprintk(KERN_INFO "%s: nv_release_txskb for skbnr %d\n",
1400 dev->name, skbnr);
1401
1402 if (np->tx_dma[skbnr]) {
1403 pci_unmap_page(np->pci_dev, np->tx_dma[skbnr],
1404 np->tx_dma_len[skbnr],
1405 PCI_DMA_TODEVICE);
1406 np->tx_dma[skbnr] = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001407 }
Ayaz Abdullafa454592006-01-05 22:45:45 -08001408
1409 if (np->tx_skbuff[skbnr]) {
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05001410 dev_kfree_skb_any(np->tx_skbuff[skbnr]);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001411 np->tx_skbuff[skbnr] = NULL;
1412 return 1;
1413 } else {
1414 return 0;
1415 }
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001416}
1417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418static void nv_drain_tx(struct net_device *dev)
1419{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001420 struct fe_priv *np = netdev_priv(dev);
1421 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001422
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001423 for (i = 0; i < np->tx_ring_size; i++) {
Manfred Spraulee733622005-07-31 18:32:26 +02001424 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001425 np->tx_ring.orig[i].flaglen = 0;
Manfred Spraulee733622005-07-31 18:32:26 +02001426 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001427 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001428 if (nv_release_txskb(dev, i))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 np->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431}
1432
1433static void nv_drain_rx(struct net_device *dev)
1434{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001435 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 int i;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001437 for (i = 0; i < np->rx_ring_size; i++) {
Manfred Spraulee733622005-07-31 18:32:26 +02001438 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001439 np->rx_ring.orig[i].flaglen = 0;
Manfred Spraulee733622005-07-31 18:32:26 +02001440 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001441 np->rx_ring.ex[i].flaglen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 wmb();
1443 if (np->rx_skbuff[i]) {
1444 pci_unmap_single(np->pci_dev, np->rx_dma[i],
Manfred Spraul18360982005-12-24 14:19:24 +01001445 np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 PCI_DMA_FROMDEVICE);
1447 dev_kfree_skb(np->rx_skbuff[i]);
1448 np->rx_skbuff[i] = NULL;
1449 }
1450 }
1451}
1452
1453static void drain_ring(struct net_device *dev)
1454{
1455 nv_drain_tx(dev);
1456 nv_drain_rx(dev);
1457}
1458
1459/*
1460 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07001461 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 */
1463static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1464{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001465 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001466 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001467 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
1468 unsigned int fragments = skb_shinfo(skb)->nr_frags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001469 unsigned int nr = (np->next_tx - 1) % np->tx_ring_size;
1470 unsigned int start_nr = np->next_tx % np->tx_ring_size;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001471 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001472 u32 offset = 0;
1473 u32 bcnt;
1474 u32 size = skb->len-skb->data_len;
1475 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001476 u32 tx_flags_vlan = 0;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001477
1478 /* add fragments to entries count */
1479 for (i = 0; i < fragments; i++) {
1480 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1481 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
1484 spin_lock_irq(&np->lock);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001485
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001486 if ((np->next_tx - np->nic_tx + entries - 1) > np->tx_limit_stop) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001487 spin_unlock_irq(&np->lock);
1488 netif_stop_queue(dev);
1489 return NETDEV_TX_BUSY;
1490 }
1491
Ayaz Abdullafa454592006-01-05 22:45:45 -08001492 /* setup the header buffer */
1493 do {
1494 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001495 nr = (nr + 1) % np->tx_ring_size;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001496
1497 np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
1498 PCI_DMA_TODEVICE);
1499 np->tx_dma_len[nr] = bcnt;
1500
1501 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001502 np->tx_ring.orig[nr].buf = cpu_to_le32(np->tx_dma[nr]);
1503 np->tx_ring.orig[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001504 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001505 np->tx_ring.ex[nr].bufhigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1506 np->tx_ring.ex[nr].buflow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1507 np->tx_ring.ex[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001508 }
1509 tx_flags = np->tx_flags;
1510 offset += bcnt;
1511 size -= bcnt;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001512 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001513
1514 /* setup the fragments */
1515 for (i = 0; i < fragments; i++) {
1516 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1517 u32 size = frag->size;
1518 offset = 0;
1519
1520 do {
1521 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001522 nr = (nr + 1) % np->tx_ring_size;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001523
1524 np->tx_dma[nr] = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
1525 PCI_DMA_TODEVICE);
1526 np->tx_dma_len[nr] = bcnt;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001527
1528 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001529 np->tx_ring.orig[nr].buf = cpu_to_le32(np->tx_dma[nr]);
1530 np->tx_ring.orig[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001531 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001532 np->tx_ring.ex[nr].bufhigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1533 np->tx_ring.ex[nr].buflow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1534 np->tx_ring.ex[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001535 }
Ayaz Abdullafa454592006-01-05 22:45:45 -08001536 offset += bcnt;
1537 size -= bcnt;
1538 } while (size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001539 }
1540
Ayaz Abdullafa454592006-01-05 22:45:45 -08001541 /* set last fragment flag */
1542 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001543 np->tx_ring.orig[nr].flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001544 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001545 np->tx_ring.ex[nr].flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001546 }
1547
1548 np->tx_skbuff[nr] = skb;
1549
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001550#ifdef NETIF_F_TSO
Herbert Xu89114af2006-07-08 13:34:32 -07001551 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07001552 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02001553 else
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001554#endif
Patrick McHardy84fa7932006-08-29 16:44:56 -07001555 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
1556 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001557
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001558 /* vlan tag */
1559 if (np->vlangrp && vlan_tx_tag_present(skb)) {
1560 tx_flags_vlan = NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb);
1561 }
1562
Ayaz Abdullafa454592006-01-05 22:45:45 -08001563 /* set tx flags */
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001564 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001565 np->tx_ring.orig[start_nr].flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001566 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001567 np->tx_ring.ex[start_nr].txvlan = cpu_to_le32(tx_flags_vlan);
1568 np->tx_ring.ex[start_nr].flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001569 }
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001570
Ayaz Abdullafa454592006-01-05 22:45:45 -08001571 dprintk(KERN_DEBUG "%s: nv_start_xmit: packet %d (entries %d) queued for transmission. tx_flags_extra: %x\n",
1572 dev->name, np->next_tx, entries, tx_flags_extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 {
1574 int j;
1575 for (j=0; j<64; j++) {
1576 if ((j%16) == 0)
1577 dprintk("\n%03x:", j);
1578 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
1579 }
1580 dprintk("\n");
1581 }
1582
Ayaz Abdullafa454592006-01-05 22:45:45 -08001583 np->next_tx += entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 spin_unlock_irq(&np->lock);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001587 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 pci_push(get_hwbase(dev));
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001589 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
1592/*
1593 * nv_tx_done: check for completed packets, release the skbs.
1594 *
1595 * Caller must own np->lock.
1596 */
1597static void nv_tx_done(struct net_device *dev)
1598{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001599 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001600 u32 flags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001601 unsigned int i;
1602 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
1604 while (np->nic_tx != np->next_tx) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001605 i = np->nic_tx % np->tx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
Manfred Spraulee733622005-07-31 18:32:26 +02001607 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001608 flags = le32_to_cpu(np->tx_ring.orig[i].flaglen);
Manfred Spraulee733622005-07-31 18:32:26 +02001609 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001610 flags = le32_to_cpu(np->tx_ring.ex[i].flaglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001612 dprintk(KERN_DEBUG "%s: nv_tx_done: looking at packet %d, flags 0x%x.\n",
1613 dev->name, np->nic_tx, flags);
1614 if (flags & NV_TX_VALID)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 break;
1616 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001617 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001618 skb = np->tx_skbuff[i];
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001619 if (flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION|
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001620 NV_TX_UNDERFLOW|NV_TX_ERROR)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001621 if (flags & NV_TX_UNDERFLOW)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001622 np->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001623 if (flags & NV_TX_CARRIERLOST)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001624 np->stats.tx_carrier_errors++;
1625 np->stats.tx_errors++;
1626 } else {
1627 np->stats.tx_packets++;
1628 np->stats.tx_bytes += skb->len;
1629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 }
1631 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001632 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001633 skb = np->tx_skbuff[i];
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001634 if (flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION|
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001635 NV_TX2_UNDERFLOW|NV_TX2_ERROR)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001636 if (flags & NV_TX2_UNDERFLOW)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001637 np->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001638 if (flags & NV_TX2_CARRIERLOST)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001639 np->stats.tx_carrier_errors++;
1640 np->stats.tx_errors++;
1641 } else {
1642 np->stats.tx_packets++;
1643 np->stats.tx_bytes += skb->len;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 }
1646 }
Ayaz Abdullafa454592006-01-05 22:45:45 -08001647 nv_release_txskb(dev, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 np->nic_tx++;
1649 }
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001650 if (np->next_tx - np->nic_tx < np->tx_limit_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 netif_wake_queue(dev);
1652}
1653
1654/*
1655 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07001656 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 */
1658static void nv_tx_timeout(struct net_device *dev)
1659{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001660 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05001662 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05001664 if (np->msi_flags & NV_MSI_X_ENABLED)
1665 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
1666 else
1667 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
1668
1669 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Manfred Spraulc2dba062005-07-31 18:29:47 +02001671 {
1672 int i;
1673
1674 printk(KERN_INFO "%s: Ring at %lx: next %d nic %d\n",
1675 dev->name, (unsigned long)np->ring_addr,
1676 np->next_tx, np->nic_tx);
1677 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001678 for (i=0;i<=np->register_size;i+= 32) {
Manfred Spraulc2dba062005-07-31 18:29:47 +02001679 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
1680 i,
1681 readl(base + i + 0), readl(base + i + 4),
1682 readl(base + i + 8), readl(base + i + 12),
1683 readl(base + i + 16), readl(base + i + 20),
1684 readl(base + i + 24), readl(base + i + 28));
1685 }
1686 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001687 for (i=0;i<np->tx_ring_size;i+= 4) {
Manfred Spraulee733622005-07-31 18:32:26 +02001688 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1689 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001690 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001691 le32_to_cpu(np->tx_ring.orig[i].buf),
1692 le32_to_cpu(np->tx_ring.orig[i].flaglen),
1693 le32_to_cpu(np->tx_ring.orig[i+1].buf),
1694 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
1695 le32_to_cpu(np->tx_ring.orig[i+2].buf),
1696 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
1697 le32_to_cpu(np->tx_ring.orig[i+3].buf),
1698 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02001699 } else {
1700 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001701 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001702 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
1703 le32_to_cpu(np->tx_ring.ex[i].buflow),
1704 le32_to_cpu(np->tx_ring.ex[i].flaglen),
1705 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
1706 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
1707 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
1708 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
1709 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
1710 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
1711 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
1712 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
1713 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02001714 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02001715 }
1716 }
1717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 spin_lock_irq(&np->lock);
1719
1720 /* 1) stop tx engine */
1721 nv_stop_tx(dev);
1722
1723 /* 2) check that the packets were not sent already: */
1724 nv_tx_done(dev);
1725
1726 /* 3) if there are dead entries: clear everything */
1727 if (np->next_tx != np->nic_tx) {
1728 printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name);
1729 nv_drain_tx(dev);
1730 np->next_tx = np->nic_tx = 0;
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001731 setup_hw_rings(dev, NV_SETUP_TX_RING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 netif_wake_queue(dev);
1733 }
1734
1735 /* 4) restart tx engine */
1736 nv_start_tx(dev);
1737 spin_unlock_irq(&np->lock);
1738}
1739
Manfred Spraul22c6d142005-04-19 21:17:09 +02001740/*
1741 * Called when the nic notices a mismatch between the actual data len on the
1742 * wire and the len indicated in the 802 header
1743 */
1744static int nv_getlen(struct net_device *dev, void *packet, int datalen)
1745{
1746 int hdrlen; /* length of the 802 header */
1747 int protolen; /* length as stored in the proto field */
1748
1749 /* 1) calculate len according to header */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001750 if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
Manfred Spraul22c6d142005-04-19 21:17:09 +02001751 protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto );
1752 hdrlen = VLAN_HLEN;
1753 } else {
1754 protolen = ntohs( ((struct ethhdr *)packet)->h_proto);
1755 hdrlen = ETH_HLEN;
1756 }
1757 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
1758 dev->name, datalen, protolen, hdrlen);
1759 if (protolen > ETH_DATA_LEN)
1760 return datalen; /* Value in proto field not a len, no checks possible */
1761
1762 protolen += hdrlen;
1763 /* consistency checks: */
1764 if (datalen > ETH_ZLEN) {
1765 if (datalen >= protolen) {
1766 /* more data on wire than in 802 header, trim of
1767 * additional data.
1768 */
1769 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1770 dev->name, protolen);
1771 return protolen;
1772 } else {
1773 /* less data on wire than mentioned in header.
1774 * Discard the packet.
1775 */
1776 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
1777 dev->name);
1778 return -1;
1779 }
1780 } else {
1781 /* short packet. Accept only if 802 values are also short */
1782 if (protolen > ETH_ZLEN) {
1783 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
1784 dev->name);
1785 return -1;
1786 }
1787 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1788 dev->name, datalen);
1789 return datalen;
1790 }
1791}
1792
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001793static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001795 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001796 u32 flags;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001797 u32 vlanflags = 0;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001798 int count;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001799
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001800 for (count = 0; count < limit; ++count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 struct sk_buff *skb;
1802 int len;
1803 int i;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001804 if (np->cur_rx - np->refill_rx >= np->rx_ring_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 break; /* we scanned the whole ring - do not continue */
1806
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001807 i = np->cur_rx % np->rx_ring_size;
Manfred Spraulee733622005-07-31 18:32:26 +02001808 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001809 flags = le32_to_cpu(np->rx_ring.orig[i].flaglen);
Manfred Spraulee733622005-07-31 18:32:26 +02001810 len = nv_descr_getlength(&np->rx_ring.orig[i], np->desc_ver);
1811 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001812 flags = le32_to_cpu(np->rx_ring.ex[i].flaglen);
Manfred Spraulee733622005-07-31 18:32:26 +02001813 len = nv_descr_getlength_ex(&np->rx_ring.ex[i], np->desc_ver);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001814 vlanflags = le32_to_cpu(np->rx_ring.ex[i].buflow);
Manfred Spraulee733622005-07-31 18:32:26 +02001815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001817 dprintk(KERN_DEBUG "%s: nv_rx_process: looking at packet %d, flags 0x%x.\n",
1818 dev->name, np->cur_rx, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001820 if (flags & NV_RX_AVAIL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 break; /* still owned by hardware, */
1822
1823 /*
1824 * the packet is for us - immediately tear down the pci mapping.
1825 * TODO: check if a prefetch of the first cacheline improves
1826 * the performance.
1827 */
1828 pci_unmap_single(np->pci_dev, np->rx_dma[i],
Manfred Spraul18360982005-12-24 14:19:24 +01001829 np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 PCI_DMA_FROMDEVICE);
1831
1832 {
1833 int j;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001834 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 for (j=0; j<64; j++) {
1836 if ((j%16) == 0)
1837 dprintk("\n%03x:", j);
1838 dprintk(" %02x", ((unsigned char*)np->rx_skbuff[i]->data)[j]);
1839 }
1840 dprintk("\n");
1841 }
1842 /* look at what we actually got: */
1843 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001844 if (!(flags & NV_RX_DESCRIPTORVALID))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 goto next_pkt;
1846
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001847 if (flags & NV_RX_ERROR) {
1848 if (flags & NV_RX_MISSEDFRAME) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001849 np->stats.rx_missed_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 np->stats.rx_errors++;
1851 goto next_pkt;
1852 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001853 if (flags & (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3)) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001854 np->stats.rx_errors++;
1855 goto next_pkt;
1856 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001857 if (flags & NV_RX_CRCERR) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001858 np->stats.rx_crc_errors++;
1859 np->stats.rx_errors++;
1860 goto next_pkt;
1861 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001862 if (flags & NV_RX_OVERFLOW) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001863 np->stats.rx_over_errors++;
1864 np->stats.rx_errors++;
1865 goto next_pkt;
1866 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001867 if (flags & NV_RX_ERROR4) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001868 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1869 if (len < 0) {
1870 np->stats.rx_errors++;
1871 goto next_pkt;
1872 }
1873 }
1874 /* framing errors are soft errors. */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001875 if (flags & NV_RX_FRAMINGERR) {
1876 if (flags & NV_RX_SUBSTRACT1) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001877 len--;
1878 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02001879 }
1880 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001882 if (!(flags & NV_RX2_DESCRIPTORVALID))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 goto next_pkt;
1884
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001885 if (flags & NV_RX2_ERROR) {
1886 if (flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 np->stats.rx_errors++;
1888 goto next_pkt;
1889 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001890 if (flags & NV_RX2_CRCERR) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001891 np->stats.rx_crc_errors++;
1892 np->stats.rx_errors++;
1893 goto next_pkt;
1894 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001895 if (flags & NV_RX2_OVERFLOW) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001896 np->stats.rx_over_errors++;
1897 np->stats.rx_errors++;
1898 goto next_pkt;
1899 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001900 if (flags & NV_RX2_ERROR4) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001901 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1902 if (len < 0) {
1903 np->stats.rx_errors++;
1904 goto next_pkt;
1905 }
1906 }
1907 /* framing errors are soft errors */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001908 if (flags & NV_RX2_FRAMINGERR) {
1909 if (flags & NV_RX2_SUBSTRACT1) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001910 len--;
1911 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02001912 }
1913 }
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04001914 if (np->rx_csum) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001915 flags &= NV_RX2_CHECKSUMMASK;
1916 if (flags == NV_RX2_CHECKSUMOK1 ||
1917 flags == NV_RX2_CHECKSUMOK2 ||
1918 flags == NV_RX2_CHECKSUMOK3) {
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04001919 dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name);
1920 np->rx_skbuff[i]->ip_summed = CHECKSUM_UNNECESSARY;
1921 } else {
1922 dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name);
1923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 }
1925 }
1926 /* got a valid packet - forward it to the network core */
1927 skb = np->rx_skbuff[i];
1928 np->rx_skbuff[i] = NULL;
1929
1930 skb_put(skb, len);
1931 skb->protocol = eth_type_trans(skb, dev);
1932 dprintk(KERN_DEBUG "%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n",
1933 dev->name, np->cur_rx, len, skb->protocol);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001934#ifdef CONFIG_FORCEDETH_NAPI
1935 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
1936 vlan_hwaccel_receive_skb(skb, np->vlangrp,
1937 vlanflags & NV_RX3_VLAN_TAG_MASK);
1938 else
1939 netif_receive_skb(skb);
1940#else
1941 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
1942 vlan_hwaccel_rx(skb, np->vlangrp,
1943 vlanflags & NV_RX3_VLAN_TAG_MASK);
1944 else
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001945 netif_rx(skb);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001946#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 dev->last_rx = jiffies;
1948 np->stats.rx_packets++;
1949 np->stats.rx_bytes += len;
1950next_pkt:
1951 np->cur_rx++;
1952 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001953
1954 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955}
1956
Manfred Sprauld81c0982005-07-31 18:20:30 +02001957static void set_bufsize(struct net_device *dev)
1958{
1959 struct fe_priv *np = netdev_priv(dev);
1960
1961 if (dev->mtu <= ETH_DATA_LEN)
1962 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
1963 else
1964 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
1965}
1966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967/*
1968 * nv_change_mtu: dev->change_mtu function
1969 * Called with dev_base_lock held for read.
1970 */
1971static int nv_change_mtu(struct net_device *dev, int new_mtu)
1972{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001973 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001974 int old_mtu;
1975
1976 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001978
1979 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001981
1982 /* return early if the buffer sizes will not change */
1983 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
1984 return 0;
1985 if (old_mtu == new_mtu)
1986 return 0;
1987
1988 /* synchronized against open : rtnl_lock() held by caller */
1989 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01001990 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001991 /*
1992 * It seems that the nic preloads valid ring entries into an
1993 * internal buffer. The procedure for flushing everything is
1994 * guessed, there is probably a simpler approach.
1995 * Changing the MTU is a rare event, it shouldn't matter.
1996 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001997 nv_disable_irq(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07001998 netif_tx_lock_bh(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001999 spin_lock(&np->lock);
2000 /* stop engines */
2001 nv_stop_rx(dev);
2002 nv_stop_tx(dev);
2003 nv_txrx_reset(dev);
2004 /* drain rx queue */
2005 nv_drain_rx(dev);
2006 nv_drain_tx(dev);
2007 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002008 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002009 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02002010 if (!np->in_shutdown)
2011 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2012 }
2013 /* reinit nic view of the rx queue */
2014 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002015 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002016 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02002017 base + NvRegRingSizes);
2018 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002019 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002020 pci_push(base);
2021
2022 /* restart rx engine */
2023 nv_start_rx(dev);
2024 nv_start_tx(dev);
2025 spin_unlock(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002026 netif_tx_unlock_bh(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002027 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 return 0;
2030}
2031
Manfred Spraul72b31782005-07-31 18:33:34 +02002032static void nv_copy_mac_to_hw(struct net_device *dev)
2033{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002034 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002035 u32 mac[2];
2036
2037 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
2038 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
2039 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
2040
2041 writel(mac[0], base + NvRegMacAddrA);
2042 writel(mac[1], base + NvRegMacAddrB);
2043}
2044
2045/*
2046 * nv_set_mac_address: dev->set_mac_address function
2047 * Called with rtnl_lock() held.
2048 */
2049static int nv_set_mac_address(struct net_device *dev, void *addr)
2050{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002051 struct fe_priv *np = netdev_priv(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002052 struct sockaddr *macaddr = (struct sockaddr*)addr;
2053
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002054 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02002055 return -EADDRNOTAVAIL;
2056
2057 /* synchronized against open : rtnl_lock() held by caller */
2058 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
2059
2060 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07002061 netif_tx_lock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002062 spin_lock_irq(&np->lock);
2063
2064 /* stop rx engine */
2065 nv_stop_rx(dev);
2066
2067 /* set mac address */
2068 nv_copy_mac_to_hw(dev);
2069
2070 /* restart rx engine */
2071 nv_start_rx(dev);
2072 spin_unlock_irq(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002073 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002074 } else {
2075 nv_copy_mac_to_hw(dev);
2076 }
2077 return 0;
2078}
2079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080/*
2081 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07002082 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 */
2084static void nv_set_multicast(struct net_device *dev)
2085{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002086 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 u8 __iomem *base = get_hwbase(dev);
2088 u32 addr[2];
2089 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002090 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
2092 memset(addr, 0, sizeof(addr));
2093 memset(mask, 0, sizeof(mask));
2094
2095 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002096 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002098 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
2100 if (dev->flags & IFF_ALLMULTI || dev->mc_list) {
2101 u32 alwaysOff[2];
2102 u32 alwaysOn[2];
2103
2104 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
2105 if (dev->flags & IFF_ALLMULTI) {
2106 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
2107 } else {
2108 struct dev_mc_list *walk;
2109
2110 walk = dev->mc_list;
2111 while (walk != NULL) {
2112 u32 a, b;
2113 a = le32_to_cpu(*(u32 *) walk->dmi_addr);
2114 b = le16_to_cpu(*(u16 *) (&walk->dmi_addr[4]));
2115 alwaysOn[0] &= a;
2116 alwaysOff[0] &= ~a;
2117 alwaysOn[1] &= b;
2118 alwaysOff[1] &= ~b;
2119 walk = walk->next;
2120 }
2121 }
2122 addr[0] = alwaysOn[0];
2123 addr[1] = alwaysOn[1];
2124 mask[0] = alwaysOn[0] | alwaysOff[0];
2125 mask[1] = alwaysOn[1] | alwaysOff[1];
2126 }
2127 }
2128 addr[0] |= NVREG_MCASTADDRA_FORCE;
2129 pff |= NVREG_PFF_ALWAYS;
2130 spin_lock_irq(&np->lock);
2131 nv_stop_rx(dev);
2132 writel(addr[0], base + NvRegMulticastAddrA);
2133 writel(addr[1], base + NvRegMulticastAddrB);
2134 writel(mask[0], base + NvRegMulticastMaskA);
2135 writel(mask[1], base + NvRegMulticastMaskB);
2136 writel(pff, base + NvRegPacketFilterFlags);
2137 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
2138 dev->name);
2139 nv_start_rx(dev);
2140 spin_unlock_irq(&np->lock);
2141}
2142
Adrian Bunkc7985052006-06-22 12:03:29 +02002143static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002144{
2145 struct fe_priv *np = netdev_priv(dev);
2146 u8 __iomem *base = get_hwbase(dev);
2147
2148 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
2149
2150 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
2151 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
2152 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
2153 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
2154 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2155 } else {
2156 writel(pff, base + NvRegPacketFilterFlags);
2157 }
2158 }
2159 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
2160 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
2161 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
2162 writel(NVREG_TX_PAUSEFRAME_ENABLE, base + NvRegTxPauseFrame);
2163 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
2164 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2165 } else {
2166 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
2167 writel(regmisc, base + NvRegMisc1);
2168 }
2169 }
2170}
2171
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002172/**
2173 * nv_update_linkspeed: Setup the MAC according to the link partner
2174 * @dev: Network device to be configured
2175 *
2176 * The function queries the PHY and checks if there is a link partner.
2177 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
2178 * set to 10 MBit HD.
2179 *
2180 * The function returns 0 if there is no link partner and 1 if there is
2181 * a good link partner.
2182 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183static int nv_update_linkspeed(struct net_device *dev)
2184{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002185 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002187 int adv = 0;
2188 int lpa = 0;
2189 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 int newls = np->linkspeed;
2191 int newdup = np->duplex;
2192 int mii_status;
2193 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002194 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196 /* BMSR_LSTATUS is latched, read it twice:
2197 * we want the current value.
2198 */
2199 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2200 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2201
2202 if (!(mii_status & BMSR_LSTATUS)) {
2203 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
2204 dev->name);
2205 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2206 newdup = 0;
2207 retval = 0;
2208 goto set_speed;
2209 }
2210
2211 if (np->autoneg == 0) {
2212 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
2213 dev->name, np->fixed_mode);
2214 if (np->fixed_mode & LPA_100FULL) {
2215 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2216 newdup = 1;
2217 } else if (np->fixed_mode & LPA_100HALF) {
2218 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2219 newdup = 0;
2220 } else if (np->fixed_mode & LPA_10FULL) {
2221 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2222 newdup = 1;
2223 } else {
2224 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2225 newdup = 0;
2226 }
2227 retval = 1;
2228 goto set_speed;
2229 }
2230 /* check auto negotiation is complete */
2231 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
2232 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
2233 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2234 newdup = 0;
2235 retval = 0;
2236 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
2237 goto set_speed;
2238 }
2239
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002240 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2241 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
2242 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
2243 dev->name, adv, lpa);
2244
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 retval = 1;
2246 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002247 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
2248 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
2250 if ((control_1000 & ADVERTISE_1000FULL) &&
2251 (status_1000 & LPA_1000FULL)) {
2252 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
2253 dev->name);
2254 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
2255 newdup = 1;
2256 goto set_speed;
2257 }
2258 }
2259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002261 adv_lpa = lpa & adv;
2262 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2264 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002265 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2267 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002268 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2270 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002271 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2273 newdup = 0;
2274 } else {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002275 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, adv_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2277 newdup = 0;
2278 }
2279
2280set_speed:
2281 if (np->duplex == newdup && np->linkspeed == newls)
2282 return retval;
2283
2284 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
2285 dev->name, np->linkspeed, np->duplex, newls, newdup);
2286
2287 np->duplex = newdup;
2288 np->linkspeed = newls;
2289
2290 if (np->gigabit == PHY_GIGABIT) {
2291 phyreg = readl(base + NvRegRandomSeed);
2292 phyreg &= ~(0x3FF00);
2293 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
2294 phyreg |= NVREG_RNDSEED_FORCE3;
2295 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
2296 phyreg |= NVREG_RNDSEED_FORCE2;
2297 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
2298 phyreg |= NVREG_RNDSEED_FORCE;
2299 writel(phyreg, base + NvRegRandomSeed);
2300 }
2301
2302 phyreg = readl(base + NvRegPhyInterface);
2303 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
2304 if (np->duplex == 0)
2305 phyreg |= PHY_HALF;
2306 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
2307 phyreg |= PHY_100;
2308 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2309 phyreg |= PHY_1000;
2310 writel(phyreg, base + NvRegPhyInterface);
2311
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002312 if (phyreg & PHY_RGMII) {
2313 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2314 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
2315 else
2316 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
2317 } else {
2318 txreg = NVREG_TX_DEFERRAL_DEFAULT;
2319 }
2320 writel(txreg, base + NvRegTxDeferral);
2321
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04002322 if (np->desc_ver == DESC_VER_1) {
2323 txreg = NVREG_TX_WM_DESC1_DEFAULT;
2324 } else {
2325 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2326 txreg = NVREG_TX_WM_DESC2_3_1000;
2327 else
2328 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
2329 }
2330 writel(txreg, base + NvRegTxWatermark);
2331
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
2333 base + NvRegMisc1);
2334 pci_push(base);
2335 writel(np->linkspeed, base + NvRegLinkSpeed);
2336 pci_push(base);
2337
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002338 pause_flags = 0;
2339 /* setup pause frame */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002340 if (np->duplex != 0) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002341 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
2342 adv_pause = adv & (ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM);
2343 lpa_pause = lpa & (LPA_PAUSE_CAP| LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002344
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002345 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002346 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002347 if (lpa_pause & LPA_PAUSE_CAP) {
2348 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2349 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2350 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2351 }
2352 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002353 case ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002354 if (lpa_pause == (LPA_PAUSE_CAP| LPA_PAUSE_ASYM))
2355 {
2356 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2357 }
2358 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002359 case ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002360 if (lpa_pause & LPA_PAUSE_CAP)
2361 {
2362 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2363 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2364 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2365 }
2366 if (lpa_pause == LPA_PAUSE_ASYM)
2367 {
2368 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2369 }
2370 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002371 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002372 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002373 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002374 }
2375 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002376 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 return retval;
2379}
2380
2381static void nv_linkchange(struct net_device *dev)
2382{
2383 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002384 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 netif_carrier_on(dev);
2386 printk(KERN_INFO "%s: link up.\n", dev->name);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002387 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 } else {
2390 if (netif_carrier_ok(dev)) {
2391 netif_carrier_off(dev);
2392 printk(KERN_INFO "%s: link down.\n", dev->name);
2393 nv_stop_rx(dev);
2394 }
2395 }
2396}
2397
2398static void nv_link_irq(struct net_device *dev)
2399{
2400 u8 __iomem *base = get_hwbase(dev);
2401 u32 miistat;
2402
2403 miistat = readl(base + NvRegMIIStatus);
2404 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
2405 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
2406
2407 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
2408 nv_linkchange(dev);
2409 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
2410}
2411
David Howells7d12e782006-10-05 14:55:46 +01002412static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413{
2414 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002415 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 u8 __iomem *base = get_hwbase(dev);
2417 u32 events;
2418 int i;
2419
2420 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
2421
2422 for (i=0; ; i++) {
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002423 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
2424 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2425 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2426 } else {
2427 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2428 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
2429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 pci_push(base);
2431 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2432 if (!(events & np->irqmask))
2433 break;
2434
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002435 spin_lock(&np->lock);
2436 nv_tx_done(dev);
2437 spin_unlock(&np->lock);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002438
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 if (events & NVREG_IRQ_LINK) {
2440 spin_lock(&np->lock);
2441 nv_link_irq(dev);
2442 spin_unlock(&np->lock);
2443 }
2444 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
2445 spin_lock(&np->lock);
2446 nv_linkchange(dev);
2447 spin_unlock(&np->lock);
2448 np->link_timeout = jiffies + LINK_TIMEOUT;
2449 }
2450 if (events & (NVREG_IRQ_TX_ERR)) {
2451 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2452 dev->name, events);
2453 }
2454 if (events & (NVREG_IRQ_UNKNOWN)) {
2455 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2456 dev->name, events);
2457 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002458#ifdef CONFIG_FORCEDETH_NAPI
2459 if (events & NVREG_IRQ_RX_ALL) {
2460 netif_rx_schedule(dev);
2461
2462 /* Disable furthur receive irq's */
2463 spin_lock(&np->lock);
2464 np->irqmask &= ~NVREG_IRQ_RX_ALL;
2465
2466 if (np->msi_flags & NV_MSI_X_ENABLED)
2467 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2468 else
2469 writel(np->irqmask, base + NvRegIrqMask);
2470 spin_unlock(&np->lock);
2471 }
2472#else
2473 nv_rx_process(dev, dev->weight);
2474 if (nv_alloc_rx(dev)) {
2475 spin_lock(&np->lock);
2476 if (!np->in_shutdown)
2477 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2478 spin_unlock(&np->lock);
2479 }
2480#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 if (i > max_interrupt_work) {
2482 spin_lock(&np->lock);
2483 /* disable interrupts on the nic */
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002484 if (!(np->msi_flags & NV_MSI_X_ENABLED))
2485 writel(0, base + NvRegIrqMask);
2486 else
2487 writel(np->irqmask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 pci_push(base);
2489
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002490 if (!np->in_shutdown) {
2491 np->nic_poll_irq = np->irqmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
2495 spin_unlock(&np->lock);
2496 break;
2497 }
2498
2499 }
2500 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
2501
2502 return IRQ_RETVAL(i);
2503}
2504
David Howells7d12e782006-10-05 14:55:46 +01002505static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002506{
2507 struct net_device *dev = (struct net_device *) data;
2508 struct fe_priv *np = netdev_priv(dev);
2509 u8 __iomem *base = get_hwbase(dev);
2510 u32 events;
2511 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002512 unsigned long flags;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002513
2514 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
2515
2516 for (i=0; ; i++) {
2517 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
2518 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
2519 pci_push(base);
2520 dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
2521 if (!(events & np->irqmask))
2522 break;
2523
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002524 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002525 nv_tx_done(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002526 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002527
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002528 if (events & (NVREG_IRQ_TX_ERR)) {
2529 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2530 dev->name, events);
2531 }
2532 if (i > max_interrupt_work) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002533 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002534 /* disable interrupts on the nic */
2535 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
2536 pci_push(base);
2537
2538 if (!np->in_shutdown) {
2539 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
2540 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2541 }
2542 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002543 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002544 break;
2545 }
2546
2547 }
2548 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
2549
2550 return IRQ_RETVAL(i);
2551}
2552
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002553#ifdef CONFIG_FORCEDETH_NAPI
2554static int nv_napi_poll(struct net_device *dev, int *budget)
2555{
2556 int pkts, limit = min(*budget, dev->quota);
2557 struct fe_priv *np = netdev_priv(dev);
2558 u8 __iomem *base = get_hwbase(dev);
2559
2560 pkts = nv_rx_process(dev, limit);
2561
2562 if (nv_alloc_rx(dev)) {
2563 spin_lock_irq(&np->lock);
2564 if (!np->in_shutdown)
2565 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2566 spin_unlock_irq(&np->lock);
2567 }
2568
2569 if (pkts < limit) {
2570 /* all done, no more packets present */
2571 netif_rx_complete(dev);
2572
2573 /* re-enable receive interrupts */
2574 spin_lock_irq(&np->lock);
2575 np->irqmask |= NVREG_IRQ_RX_ALL;
2576 if (np->msi_flags & NV_MSI_X_ENABLED)
2577 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2578 else
2579 writel(np->irqmask, base + NvRegIrqMask);
2580 spin_unlock_irq(&np->lock);
2581 return 0;
2582 } else {
2583 /* used up our quantum, so reschedule */
2584 dev->quota -= pkts;
2585 *budget -= pkts;
2586 return 1;
2587 }
2588}
2589#endif
2590
2591#ifdef CONFIG_FORCEDETH_NAPI
David Howells7d12e782006-10-05 14:55:46 +01002592static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002593{
2594 struct net_device *dev = (struct net_device *) data;
2595 u8 __iomem *base = get_hwbase(dev);
2596 u32 events;
2597
2598 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
2599 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
2600
2601 if (events) {
2602 netif_rx_schedule(dev);
2603 /* disable receive interrupts on the nic */
2604 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2605 pci_push(base);
2606 }
2607 return IRQ_HANDLED;
2608}
2609#else
David Howells7d12e782006-10-05 14:55:46 +01002610static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002611{
2612 struct net_device *dev = (struct net_device *) data;
2613 struct fe_priv *np = netdev_priv(dev);
2614 u8 __iomem *base = get_hwbase(dev);
2615 u32 events;
2616 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002617 unsigned long flags;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002618
2619 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name);
2620
2621 for (i=0; ; i++) {
2622 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
2623 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
2624 pci_push(base);
2625 dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
2626 if (!(events & np->irqmask))
2627 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002628
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002629 nv_rx_process(dev, dev->weight);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002630 if (nv_alloc_rx(dev)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002631 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002632 if (!np->in_shutdown)
2633 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002634 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002635 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002636
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002637 if (i > max_interrupt_work) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002638 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002639 /* disable interrupts on the nic */
2640 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2641 pci_push(base);
2642
2643 if (!np->in_shutdown) {
2644 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
2645 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2646 }
2647 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002648 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002649 break;
2650 }
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002651 }
2652 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
2653
2654 return IRQ_RETVAL(i);
2655}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002656#endif
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002657
David Howells7d12e782006-10-05 14:55:46 +01002658static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002659{
2660 struct net_device *dev = (struct net_device *) data;
2661 struct fe_priv *np = netdev_priv(dev);
2662 u8 __iomem *base = get_hwbase(dev);
2663 u32 events;
2664 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002665 unsigned long flags;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002666
2667 dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
2668
2669 for (i=0; ; i++) {
2670 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
2671 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
2672 pci_push(base);
2673 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2674 if (!(events & np->irqmask))
2675 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002676
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002677 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002678 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002679 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002680 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002681 }
2682 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002683 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002684 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002685 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002686 np->link_timeout = jiffies + LINK_TIMEOUT;
2687 }
2688 if (events & (NVREG_IRQ_UNKNOWN)) {
2689 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2690 dev->name, events);
2691 }
2692 if (i > max_interrupt_work) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002693 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002694 /* disable interrupts on the nic */
2695 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
2696 pci_push(base);
2697
2698 if (!np->in_shutdown) {
2699 np->nic_poll_irq |= NVREG_IRQ_OTHER;
2700 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2701 }
2702 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002703 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002704 break;
2705 }
2706
2707 }
2708 dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
2709
2710 return IRQ_RETVAL(i);
2711}
2712
David Howells7d12e782006-10-05 14:55:46 +01002713static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002714{
2715 struct net_device *dev = (struct net_device *) data;
2716 struct fe_priv *np = netdev_priv(dev);
2717 u8 __iomem *base = get_hwbase(dev);
2718 u32 events;
2719
2720 dprintk(KERN_DEBUG "%s: nv_nic_irq_test\n", dev->name);
2721
2722 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
2723 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2724 writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus);
2725 } else {
2726 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2727 writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
2728 }
2729 pci_push(base);
2730 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2731 if (!(events & NVREG_IRQ_TIMER))
2732 return IRQ_RETVAL(0);
2733
2734 spin_lock(&np->lock);
2735 np->intr_test = 1;
2736 spin_unlock(&np->lock);
2737
2738 dprintk(KERN_DEBUG "%s: nv_nic_irq_test completed\n", dev->name);
2739
2740 return IRQ_RETVAL(1);
2741}
2742
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002743static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
2744{
2745 u8 __iomem *base = get_hwbase(dev);
2746 int i;
2747 u32 msixmap = 0;
2748
2749 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
2750 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
2751 * the remaining 8 interrupts.
2752 */
2753 for (i = 0; i < 8; i++) {
2754 if ((irqmask >> i) & 0x1) {
2755 msixmap |= vector << (i << 2);
2756 }
2757 }
2758 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
2759
2760 msixmap = 0;
2761 for (i = 0; i < 8; i++) {
2762 if ((irqmask >> (i + 8)) & 0x1) {
2763 msixmap |= vector << (i << 2);
2764 }
2765 }
2766 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
2767}
2768
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002769static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002770{
2771 struct fe_priv *np = get_nvpriv(dev);
2772 u8 __iomem *base = get_hwbase(dev);
2773 int ret = 1;
2774 int i;
2775
2776 if (np->msi_flags & NV_MSI_X_CAPABLE) {
2777 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
2778 np->msi_x_entry[i].entry = i;
2779 }
2780 if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) {
2781 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002782 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002783 /* Request irq for rx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002784 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 -04002785 printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret);
2786 pci_disable_msix(np->pci_dev);
2787 np->msi_flags &= ~NV_MSI_X_ENABLED;
2788 goto out_err;
2789 }
2790 /* Request irq for tx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002791 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 -04002792 printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret);
2793 pci_disable_msix(np->pci_dev);
2794 np->msi_flags &= ~NV_MSI_X_ENABLED;
2795 goto out_free_rx;
2796 }
2797 /* Request irq for link and timer handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002798 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 -04002799 printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret);
2800 pci_disable_msix(np->pci_dev);
2801 np->msi_flags &= ~NV_MSI_X_ENABLED;
2802 goto out_free_tx;
2803 }
2804 /* map interrupts to their respective vector */
2805 writel(0, base + NvRegMSIXMap0);
2806 writel(0, base + NvRegMSIXMap1);
2807 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
2808 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
2809 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
2810 } else {
2811 /* Request irq for all interrupts */
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002812 if ((!intr_test &&
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002813 request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002814 (intr_test &&
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002815 request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, &nv_nic_irq_test, IRQF_SHARED, dev->name, dev) != 0)) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002816 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
2817 pci_disable_msix(np->pci_dev);
2818 np->msi_flags &= ~NV_MSI_X_ENABLED;
2819 goto out_err;
2820 }
2821
2822 /* map interrupts to vector 0 */
2823 writel(0, base + NvRegMSIXMap0);
2824 writel(0, base + NvRegMSIXMap1);
2825 }
2826 }
2827 }
2828 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
2829 if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
2830 np->msi_flags |= NV_MSI_ENABLED;
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002831 if ((!intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
2832 (intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq_test, IRQF_SHARED, dev->name, dev) != 0)) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002833 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
2834 pci_disable_msi(np->pci_dev);
2835 np->msi_flags &= ~NV_MSI_ENABLED;
2836 goto out_err;
2837 }
2838
2839 /* map interrupts to vector 0 */
2840 writel(0, base + NvRegMSIMap0);
2841 writel(0, base + NvRegMSIMap1);
2842 /* enable msi vector 0 */
2843 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
2844 }
2845 }
2846 if (ret != 0) {
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002847 if ((!intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
2848 (intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq_test, IRQF_SHARED, dev->name, dev) != 0))
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002849 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002850
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002851 }
2852
2853 return 0;
2854out_free_tx:
2855 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
2856out_free_rx:
2857 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
2858out_err:
2859 return 1;
2860}
2861
2862static void nv_free_irq(struct net_device *dev)
2863{
2864 struct fe_priv *np = get_nvpriv(dev);
2865 int i;
2866
2867 if (np->msi_flags & NV_MSI_X_ENABLED) {
2868 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
2869 free_irq(np->msi_x_entry[i].vector, dev);
2870 }
2871 pci_disable_msix(np->pci_dev);
2872 np->msi_flags &= ~NV_MSI_X_ENABLED;
2873 } else {
2874 free_irq(np->pci_dev->irq, dev);
2875 if (np->msi_flags & NV_MSI_ENABLED) {
2876 pci_disable_msi(np->pci_dev);
2877 np->msi_flags &= ~NV_MSI_ENABLED;
2878 }
2879 }
2880}
2881
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882static void nv_do_nic_poll(unsigned long data)
2883{
2884 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002885 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002887 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 /*
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002890 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 * reenable interrupts on the nic, we have to do this before calling
2892 * nv_nic_irq because that may decide to do otherwise
2893 */
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002894
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002895 if (!using_multi_irqs(dev)) {
2896 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002897 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002898 else
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002899 disable_irq_lockdep(dev->irq);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002900 mask = np->irqmask;
2901 } else {
2902 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002903 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002904 mask |= NVREG_IRQ_RX_ALL;
2905 }
2906 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002907 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002908 mask |= NVREG_IRQ_TX_ALL;
2909 }
2910 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002911 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002912 mask |= NVREG_IRQ_OTHER;
2913 }
2914 }
2915 np->nic_poll_irq = 0;
2916
2917 /* FIXME: Do we need synchronize_irq(dev->irq) here? */
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002918
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002919 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 pci_push(base);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002921
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002922 if (!using_multi_irqs(dev)) {
David Howells7d12e782006-10-05 14:55:46 +01002923 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002924 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002925 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002926 else
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002927 enable_irq_lockdep(dev->irq);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002928 } else {
2929 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01002930 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002931 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002932 }
2933 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01002934 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002935 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002936 }
2937 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
David Howells7d12e782006-10-05 14:55:46 +01002938 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002939 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05002940 }
2941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942}
2943
Michal Schmidt2918c352005-05-12 19:42:06 -04002944#ifdef CONFIG_NET_POLL_CONTROLLER
2945static void nv_poll_controller(struct net_device *dev)
2946{
2947 nv_do_nic_poll((unsigned long) dev);
2948}
2949#endif
2950
Ayaz Abdulla52da3572006-06-10 22:48:04 -04002951static void nv_do_stats_poll(unsigned long data)
2952{
2953 struct net_device *dev = (struct net_device *) data;
2954 struct fe_priv *np = netdev_priv(dev);
2955 u8 __iomem *base = get_hwbase(dev);
2956
2957 np->estats.tx_bytes += readl(base + NvRegTxCnt);
2958 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
2959 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
2960 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
2961 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
2962 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
2963 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
2964 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
2965 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
2966 np->estats.tx_deferral += readl(base + NvRegTxDef);
2967 np->estats.tx_packets += readl(base + NvRegTxFrame);
2968 np->estats.tx_pause += readl(base + NvRegTxPause);
2969 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
2970 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
2971 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
2972 np->estats.rx_runt += readl(base + NvRegRxRunt);
2973 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
2974 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
2975 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
2976 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
2977 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
2978 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
2979 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
2980 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
2981 np->estats.rx_bytes += readl(base + NvRegRxCnt);
2982 np->estats.rx_pause += readl(base + NvRegRxPause);
2983 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
2984 np->estats.rx_packets =
2985 np->estats.rx_unicast +
2986 np->estats.rx_multicast +
2987 np->estats.rx_broadcast;
2988 np->estats.rx_errors_total =
2989 np->estats.rx_crc_errors +
2990 np->estats.rx_over_errors +
2991 np->estats.rx_frame_error +
2992 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
2993 np->estats.rx_late_collision +
2994 np->estats.rx_runt +
2995 np->estats.rx_frame_too_long;
2996
2997 if (!np->in_shutdown)
2998 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
2999}
3000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
3002{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003003 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 strcpy(info->driver, "forcedeth");
3005 strcpy(info->version, FORCEDETH_VERSION);
3006 strcpy(info->bus_info, pci_name(np->pci_dev));
3007}
3008
3009static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3010{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003011 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 wolinfo->supported = WAKE_MAGIC;
3013
3014 spin_lock_irq(&np->lock);
3015 if (np->wolenabled)
3016 wolinfo->wolopts = WAKE_MAGIC;
3017 spin_unlock_irq(&np->lock);
3018}
3019
3020static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3021{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003022 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003024 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003028 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003030 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003032 if (netif_running(dev)) {
3033 spin_lock_irq(&np->lock);
3034 writel(flags, base + NvRegWakeUpFlags);
3035 spin_unlock_irq(&np->lock);
3036 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 return 0;
3038}
3039
3040static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3041{
3042 struct fe_priv *np = netdev_priv(dev);
3043 int adv;
3044
3045 spin_lock_irq(&np->lock);
3046 ecmd->port = PORT_MII;
3047 if (!netif_running(dev)) {
3048 /* We do not track link speed / duplex setting if the
3049 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003050 if (nv_update_linkspeed(dev)) {
3051 if (!netif_carrier_ok(dev))
3052 netif_carrier_on(dev);
3053 } else {
3054 if (netif_carrier_ok(dev))
3055 netif_carrier_off(dev);
3056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003058
3059 if (netif_carrier_ok(dev)) {
3060 switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 case NVREG_LINKSPEED_10:
3062 ecmd->speed = SPEED_10;
3063 break;
3064 case NVREG_LINKSPEED_100:
3065 ecmd->speed = SPEED_100;
3066 break;
3067 case NVREG_LINKSPEED_1000:
3068 ecmd->speed = SPEED_1000;
3069 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003070 }
3071 ecmd->duplex = DUPLEX_HALF;
3072 if (np->duplex)
3073 ecmd->duplex = DUPLEX_FULL;
3074 } else {
3075 ecmd->speed = -1;
3076 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078
3079 ecmd->autoneg = np->autoneg;
3080
3081 ecmd->advertising = ADVERTISED_MII;
3082 if (np->autoneg) {
3083 ecmd->advertising |= ADVERTISED_Autoneg;
3084 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003085 if (adv & ADVERTISE_10HALF)
3086 ecmd->advertising |= ADVERTISED_10baseT_Half;
3087 if (adv & ADVERTISE_10FULL)
3088 ecmd->advertising |= ADVERTISED_10baseT_Full;
3089 if (adv & ADVERTISE_100HALF)
3090 ecmd->advertising |= ADVERTISED_100baseT_Half;
3091 if (adv & ADVERTISE_100FULL)
3092 ecmd->advertising |= ADVERTISED_100baseT_Full;
3093 if (np->gigabit == PHY_GIGABIT) {
3094 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3095 if (adv & ADVERTISE_1000FULL)
3096 ecmd->advertising |= ADVERTISED_1000baseT_Full;
3097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 ecmd->supported = (SUPPORTED_Autoneg |
3100 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
3101 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
3102 SUPPORTED_MII);
3103 if (np->gigabit == PHY_GIGABIT)
3104 ecmd->supported |= SUPPORTED_1000baseT_Full;
3105
3106 ecmd->phy_address = np->phyaddr;
3107 ecmd->transceiver = XCVR_EXTERNAL;
3108
3109 /* ignore maxtxpkt, maxrxpkt for now */
3110 spin_unlock_irq(&np->lock);
3111 return 0;
3112}
3113
3114static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3115{
3116 struct fe_priv *np = netdev_priv(dev);
3117
3118 if (ecmd->port != PORT_MII)
3119 return -EINVAL;
3120 if (ecmd->transceiver != XCVR_EXTERNAL)
3121 return -EINVAL;
3122 if (ecmd->phy_address != np->phyaddr) {
3123 /* TODO: support switching between multiple phys. Should be
3124 * trivial, but not enabled due to lack of test hardware. */
3125 return -EINVAL;
3126 }
3127 if (ecmd->autoneg == AUTONEG_ENABLE) {
3128 u32 mask;
3129
3130 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
3131 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
3132 if (np->gigabit == PHY_GIGABIT)
3133 mask |= ADVERTISED_1000baseT_Full;
3134
3135 if ((ecmd->advertising & mask) == 0)
3136 return -EINVAL;
3137
3138 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
3139 /* Note: autonegotiation disable, speed 1000 intentionally
3140 * forbidden - noone should need that. */
3141
3142 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
3143 return -EINVAL;
3144 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
3145 return -EINVAL;
3146 } else {
3147 return -EINVAL;
3148 }
3149
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003150 netif_carrier_off(dev);
3151 if (netif_running(dev)) {
3152 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003153 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003154 spin_lock(&np->lock);
3155 /* stop engines */
3156 nv_stop_rx(dev);
3157 nv_stop_tx(dev);
3158 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003159 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003160 }
3161
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 if (ecmd->autoneg == AUTONEG_ENABLE) {
3163 int adv, bmcr;
3164
3165 np->autoneg = 1;
3166
3167 /* advertise only what has been requested */
3168 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003169 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 if (ecmd->advertising & ADVERTISED_10baseT_Half)
3171 adv |= ADVERTISE_10HALF;
3172 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003173 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 if (ecmd->advertising & ADVERTISED_100baseT_Half)
3175 adv |= ADVERTISE_100HALF;
3176 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003177 adv |= ADVERTISE_100FULL;
3178 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
3179 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3180 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3181 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3183
3184 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003185 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 adv &= ~ADVERTISE_1000FULL;
3187 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
3188 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003189 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 }
3191
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003192 if (netif_running(dev))
3193 printk(KERN_INFO "%s: link down.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003195 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
3196 bmcr |= BMCR_ANENABLE;
3197 /* reset the phy in order for settings to stick,
3198 * and cause autoneg to start */
3199 if (phy_reset(dev, bmcr)) {
3200 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3201 return -EINVAL;
3202 }
3203 } else {
3204 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3205 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 } else {
3208 int adv, bmcr;
3209
3210 np->autoneg = 0;
3211
3212 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003213 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
3215 adv |= ADVERTISE_10HALF;
3216 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003217 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
3219 adv |= ADVERTISE_100HALF;
3220 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003221 adv |= ADVERTISE_100FULL;
3222 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
3223 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisments but disable tx pause */
3224 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3225 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3226 }
3227 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
3228 adv |= ADVERTISE_PAUSE_ASYM;
3229 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3232 np->fixed_mode = adv;
3233
3234 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003235 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003237 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 }
3239
3240 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003241 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
3242 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003244 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003246 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003247 /* reset the phy in order for forced mode settings to stick */
3248 if (phy_reset(dev, bmcr)) {
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003249 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3250 return -EINVAL;
3251 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003252 } else {
3253 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3254 if (netif_running(dev)) {
3255 /* Wait a bit and then reconfigure the nic. */
3256 udelay(10);
3257 nv_linkchange(dev);
3258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 }
3260 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003261
3262 if (netif_running(dev)) {
3263 nv_start_rx(dev);
3264 nv_start_tx(dev);
3265 nv_enable_irq(dev);
3266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267
3268 return 0;
3269}
3270
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003271#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003272
3273static int nv_get_regs_len(struct net_device *dev)
3274{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04003275 struct fe_priv *np = netdev_priv(dev);
3276 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003277}
3278
3279static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
3280{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003281 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003282 u8 __iomem *base = get_hwbase(dev);
3283 u32 *rbuf = buf;
3284 int i;
3285
3286 regs->version = FORCEDETH_REGS_VER;
3287 spin_lock_irq(&np->lock);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04003288 for (i = 0;i <= np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003289 rbuf[i] = readl(base + i*sizeof(u32));
3290 spin_unlock_irq(&np->lock);
3291}
3292
3293static int nv_nway_reset(struct net_device *dev)
3294{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003295 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003296 int ret;
3297
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003298 if (np->autoneg) {
3299 int bmcr;
3300
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003301 netif_carrier_off(dev);
3302 if (netif_running(dev)) {
3303 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003304 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003305 spin_lock(&np->lock);
3306 /* stop engines */
3307 nv_stop_rx(dev);
3308 nv_stop_tx(dev);
3309 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003310 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003311 printk(KERN_INFO "%s: link down.\n", dev->name);
3312 }
3313
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003314 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003315 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
3316 bmcr |= BMCR_ANENABLE;
3317 /* reset the phy in order for settings to stick*/
3318 if (phy_reset(dev, bmcr)) {
3319 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3320 return -EINVAL;
3321 }
3322 } else {
3323 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3324 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3325 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003326
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003327 if (netif_running(dev)) {
3328 nv_start_rx(dev);
3329 nv_start_tx(dev);
3330 nv_enable_irq(dev);
3331 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003332 ret = 0;
3333 } else {
3334 ret = -EINVAL;
3335 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003336
3337 return ret;
3338}
3339
Zachary Amsden0674d592006-06-04 02:51:38 -07003340static int nv_set_tso(struct net_device *dev, u32 value)
3341{
3342 struct fe_priv *np = netdev_priv(dev);
3343
3344 if ((np->driver_data & DEV_HAS_CHECKSUM))
3345 return ethtool_op_set_tso(dev, value);
3346 else
Ayaz Abdulla6a788142006-06-10 22:47:26 -04003347 return -EOPNOTSUPP;
Zachary Amsden0674d592006-06-04 02:51:38 -07003348}
Zachary Amsden0674d592006-06-04 02:51:38 -07003349
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003350static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
3351{
3352 struct fe_priv *np = netdev_priv(dev);
3353
3354 ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
3355 ring->rx_mini_max_pending = 0;
3356 ring->rx_jumbo_max_pending = 0;
3357 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
3358
3359 ring->rx_pending = np->rx_ring_size;
3360 ring->rx_mini_pending = 0;
3361 ring->rx_jumbo_pending = 0;
3362 ring->tx_pending = np->tx_ring_size;
3363}
3364
3365static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
3366{
3367 struct fe_priv *np = netdev_priv(dev);
3368 u8 __iomem *base = get_hwbase(dev);
3369 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff, *rx_dma, *tx_dma, *tx_dma_len;
3370 dma_addr_t ring_addr;
3371
3372 if (ring->rx_pending < RX_RING_MIN ||
3373 ring->tx_pending < TX_RING_MIN ||
3374 ring->rx_mini_pending != 0 ||
3375 ring->rx_jumbo_pending != 0 ||
3376 (np->desc_ver == DESC_VER_1 &&
3377 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
3378 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
3379 (np->desc_ver != DESC_VER_1 &&
3380 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
3381 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
3382 return -EINVAL;
3383 }
3384
3385 /* allocate new rings */
3386 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3387 rxtx_ring = pci_alloc_consistent(np->pci_dev,
3388 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
3389 &ring_addr);
3390 } else {
3391 rxtx_ring = pci_alloc_consistent(np->pci_dev,
3392 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
3393 &ring_addr);
3394 }
3395 rx_skbuff = kmalloc(sizeof(struct sk_buff*) * ring->rx_pending, GFP_KERNEL);
3396 rx_dma = kmalloc(sizeof(dma_addr_t) * ring->rx_pending, GFP_KERNEL);
3397 tx_skbuff = kmalloc(sizeof(struct sk_buff*) * ring->tx_pending, GFP_KERNEL);
3398 tx_dma = kmalloc(sizeof(dma_addr_t) * ring->tx_pending, GFP_KERNEL);
3399 tx_dma_len = kmalloc(sizeof(unsigned int) * ring->tx_pending, GFP_KERNEL);
3400 if (!rxtx_ring || !rx_skbuff || !rx_dma || !tx_skbuff || !tx_dma || !tx_dma_len) {
3401 /* fall back to old rings */
3402 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003403 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003404 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
3405 rxtx_ring, ring_addr);
3406 } else {
3407 if (rxtx_ring)
3408 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
3409 rxtx_ring, ring_addr);
3410 }
3411 if (rx_skbuff)
3412 kfree(rx_skbuff);
3413 if (rx_dma)
3414 kfree(rx_dma);
3415 if (tx_skbuff)
3416 kfree(tx_skbuff);
3417 if (tx_dma)
3418 kfree(tx_dma);
3419 if (tx_dma_len)
3420 kfree(tx_dma_len);
3421 goto exit;
3422 }
3423
3424 if (netif_running(dev)) {
3425 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003426 netif_tx_lock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003427 spin_lock(&np->lock);
3428 /* stop engines */
3429 nv_stop_rx(dev);
3430 nv_stop_tx(dev);
3431 nv_txrx_reset(dev);
3432 /* drain queues */
3433 nv_drain_rx(dev);
3434 nv_drain_tx(dev);
3435 /* delete queues */
3436 free_rings(dev);
3437 }
3438
3439 /* set new values */
3440 np->rx_ring_size = ring->rx_pending;
3441 np->tx_ring_size = ring->tx_pending;
3442 np->tx_limit_stop = ring->tx_pending - TX_LIMIT_DIFFERENCE;
3443 np->tx_limit_start = ring->tx_pending - TX_LIMIT_DIFFERENCE - 1;
3444 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3445 np->rx_ring.orig = (struct ring_desc*)rxtx_ring;
3446 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
3447 } else {
3448 np->rx_ring.ex = (struct ring_desc_ex*)rxtx_ring;
3449 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
3450 }
3451 np->rx_skbuff = (struct sk_buff**)rx_skbuff;
3452 np->rx_dma = (dma_addr_t*)rx_dma;
3453 np->tx_skbuff = (struct sk_buff**)tx_skbuff;
3454 np->tx_dma = (dma_addr_t*)tx_dma;
3455 np->tx_dma_len = (unsigned int*)tx_dma_len;
3456 np->ring_addr = ring_addr;
3457
3458 memset(np->rx_skbuff, 0, sizeof(struct sk_buff*) * np->rx_ring_size);
3459 memset(np->rx_dma, 0, sizeof(dma_addr_t) * np->rx_ring_size);
3460 memset(np->tx_skbuff, 0, sizeof(struct sk_buff*) * np->tx_ring_size);
3461 memset(np->tx_dma, 0, sizeof(dma_addr_t) * np->tx_ring_size);
3462 memset(np->tx_dma_len, 0, sizeof(unsigned int) * np->tx_ring_size);
3463
3464 if (netif_running(dev)) {
3465 /* reinit driver view of the queues */
3466 set_bufsize(dev);
3467 if (nv_init_ring(dev)) {
3468 if (!np->in_shutdown)
3469 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3470 }
3471
3472 /* reinit nic view of the queues */
3473 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3474 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3475 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3476 base + NvRegRingSizes);
3477 pci_push(base);
3478 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3479 pci_push(base);
3480
3481 /* restart engines */
3482 nv_start_rx(dev);
3483 nv_start_tx(dev);
3484 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003485 netif_tx_unlock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003486 nv_enable_irq(dev);
3487 }
3488 return 0;
3489exit:
3490 return -ENOMEM;
3491}
3492
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003493static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
3494{
3495 struct fe_priv *np = netdev_priv(dev);
3496
3497 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
3498 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
3499 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
3500}
3501
3502static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
3503{
3504 struct fe_priv *np = netdev_priv(dev);
3505 int adv, bmcr;
3506
3507 if ((!np->autoneg && np->duplex == 0) ||
3508 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
3509 printk(KERN_INFO "%s: can not set pause settings when forced link is in half duplex.\n",
3510 dev->name);
3511 return -EINVAL;
3512 }
3513 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
3514 printk(KERN_INFO "%s: hardware does not support tx pause frames.\n", dev->name);
3515 return -EINVAL;
3516 }
3517
3518 netif_carrier_off(dev);
3519 if (netif_running(dev)) {
3520 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003521 netif_tx_lock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003522 spin_lock(&np->lock);
3523 /* stop engines */
3524 nv_stop_rx(dev);
3525 nv_stop_tx(dev);
3526 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003527 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003528 }
3529
3530 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
3531 if (pause->rx_pause)
3532 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
3533 if (pause->tx_pause)
3534 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
3535
3536 if (np->autoneg && pause->autoneg) {
3537 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
3538
3539 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3540 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3541 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
3542 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3543 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3544 adv |= ADVERTISE_PAUSE_ASYM;
3545 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3546
3547 if (netif_running(dev))
3548 printk(KERN_INFO "%s: link down.\n", dev->name);
3549 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3550 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3551 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3552 } else {
3553 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
3554 if (pause->rx_pause)
3555 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3556 if (pause->tx_pause)
3557 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3558
3559 if (!netif_running(dev))
3560 nv_update_linkspeed(dev);
3561 else
3562 nv_update_pause(dev, np->pause_flags);
3563 }
3564
3565 if (netif_running(dev)) {
3566 nv_start_rx(dev);
3567 nv_start_tx(dev);
3568 nv_enable_irq(dev);
3569 }
3570 return 0;
3571}
3572
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003573static u32 nv_get_rx_csum(struct net_device *dev)
3574{
3575 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04003576 return (np->rx_csum) != 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003577}
3578
3579static int nv_set_rx_csum(struct net_device *dev, u32 data)
3580{
3581 struct fe_priv *np = netdev_priv(dev);
3582 u8 __iomem *base = get_hwbase(dev);
3583 int retcode = 0;
3584
3585 if (np->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003586 if (data) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04003587 np->rx_csum = 1;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003588 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003589 } else {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04003590 np->rx_csum = 0;
3591 /* vlan is dependent on rx checksum offload */
3592 if (!(np->vlanctl_bits & NVREG_VLANCONTROL_ENABLE))
3593 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003594 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003595 if (netif_running(dev)) {
3596 spin_lock_irq(&np->lock);
3597 writel(np->txrxctl_bits, base + NvRegTxRxControl);
3598 spin_unlock_irq(&np->lock);
3599 }
3600 } else {
3601 return -EINVAL;
3602 }
3603
3604 return retcode;
3605}
3606
3607static int nv_set_tx_csum(struct net_device *dev, u32 data)
3608{
3609 struct fe_priv *np = netdev_priv(dev);
3610
3611 if (np->driver_data & DEV_HAS_CHECKSUM)
3612 return ethtool_op_set_tx_hw_csum(dev, data);
3613 else
3614 return -EOPNOTSUPP;
3615}
3616
3617static int nv_set_sg(struct net_device *dev, u32 data)
3618{
3619 struct fe_priv *np = netdev_priv(dev);
3620
3621 if (np->driver_data & DEV_HAS_CHECKSUM)
3622 return ethtool_op_set_sg(dev, data);
3623 else
3624 return -EOPNOTSUPP;
3625}
3626
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003627static int nv_get_stats_count(struct net_device *dev)
3628{
3629 struct fe_priv *np = netdev_priv(dev);
3630
3631 if (np->driver_data & DEV_HAS_STATISTICS)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003632 return sizeof(struct nv_ethtool_stats)/sizeof(u64);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003633 else
3634 return 0;
3635}
3636
3637static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *buffer)
3638{
3639 struct fe_priv *np = netdev_priv(dev);
3640
3641 /* update stats */
3642 nv_do_stats_poll((unsigned long)dev);
3643
3644 memcpy(buffer, &np->estats, nv_get_stats_count(dev)*sizeof(u64));
3645}
3646
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003647static int nv_self_test_count(struct net_device *dev)
3648{
3649 struct fe_priv *np = netdev_priv(dev);
3650
3651 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
3652 return NV_TEST_COUNT_EXTENDED;
3653 else
3654 return NV_TEST_COUNT_BASE;
3655}
3656
3657static int nv_link_test(struct net_device *dev)
3658{
3659 struct fe_priv *np = netdev_priv(dev);
3660 int mii_status;
3661
3662 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3663 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3664
3665 /* check phy link status */
3666 if (!(mii_status & BMSR_LSTATUS))
3667 return 0;
3668 else
3669 return 1;
3670}
3671
3672static int nv_register_test(struct net_device *dev)
3673{
3674 u8 __iomem *base = get_hwbase(dev);
3675 int i = 0;
3676 u32 orig_read, new_read;
3677
3678 do {
3679 orig_read = readl(base + nv_registers_test[i].reg);
3680
3681 /* xor with mask to toggle bits */
3682 orig_read ^= nv_registers_test[i].mask;
3683
3684 writel(orig_read, base + nv_registers_test[i].reg);
3685
3686 new_read = readl(base + nv_registers_test[i].reg);
3687
3688 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
3689 return 0;
3690
3691 /* restore original value */
3692 orig_read ^= nv_registers_test[i].mask;
3693 writel(orig_read, base + nv_registers_test[i].reg);
3694
3695 } while (nv_registers_test[++i].reg != 0);
3696
3697 return 1;
3698}
3699
3700static int nv_interrupt_test(struct net_device *dev)
3701{
3702 struct fe_priv *np = netdev_priv(dev);
3703 u8 __iomem *base = get_hwbase(dev);
3704 int ret = 1;
3705 int testcnt;
3706 u32 save_msi_flags, save_poll_interval = 0;
3707
3708 if (netif_running(dev)) {
3709 /* free current irq */
3710 nv_free_irq(dev);
3711 save_poll_interval = readl(base+NvRegPollingInterval);
3712 }
3713
3714 /* flag to test interrupt handler */
3715 np->intr_test = 0;
3716
3717 /* setup test irq */
3718 save_msi_flags = np->msi_flags;
3719 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
3720 np->msi_flags |= 0x001; /* setup 1 vector */
3721 if (nv_request_irq(dev, 1))
3722 return 0;
3723
3724 /* setup timer interrupt */
3725 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
3726 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
3727
3728 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
3729
3730 /* wait for at least one interrupt */
3731 msleep(100);
3732
3733 spin_lock_irq(&np->lock);
3734
3735 /* flag should be set within ISR */
3736 testcnt = np->intr_test;
3737 if (!testcnt)
3738 ret = 2;
3739
3740 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
3741 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3742 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3743 else
3744 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3745
3746 spin_unlock_irq(&np->lock);
3747
3748 nv_free_irq(dev);
3749
3750 np->msi_flags = save_msi_flags;
3751
3752 if (netif_running(dev)) {
3753 writel(save_poll_interval, base + NvRegPollingInterval);
3754 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
3755 /* restore original irq */
3756 if (nv_request_irq(dev, 0))
3757 return 0;
3758 }
3759
3760 return ret;
3761}
3762
3763static int nv_loopback_test(struct net_device *dev)
3764{
3765 struct fe_priv *np = netdev_priv(dev);
3766 u8 __iomem *base = get_hwbase(dev);
3767 struct sk_buff *tx_skb, *rx_skb;
3768 dma_addr_t test_dma_addr;
3769 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003770 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003771 int len, i, pkt_len;
3772 u8 *pkt_data;
3773 u32 filter_flags = 0;
3774 u32 misc1_flags = 0;
3775 int ret = 1;
3776
3777 if (netif_running(dev)) {
3778 nv_disable_irq(dev);
3779 filter_flags = readl(base + NvRegPacketFilterFlags);
3780 misc1_flags = readl(base + NvRegMisc1);
3781 } else {
3782 nv_txrx_reset(dev);
3783 }
3784
3785 /* reinit driver view of the rx queue */
3786 set_bufsize(dev);
3787 nv_init_ring(dev);
3788
3789 /* setup hardware for loopback */
3790 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
3791 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
3792
3793 /* reinit nic view of the rx queue */
3794 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3795 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3796 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3797 base + NvRegRingSizes);
3798 pci_push(base);
3799
3800 /* restart rx engine */
3801 nv_start_rx(dev);
3802 nv_start_tx(dev);
3803
3804 /* setup packet for tx */
3805 pkt_len = ETH_DATA_LEN;
3806 tx_skb = dev_alloc_skb(pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07003807 if (!tx_skb) {
3808 printk(KERN_ERR "dev_alloc_skb() failed during loopback test"
3809 " of %s\n", dev->name);
3810 ret = 0;
3811 goto out;
3812 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003813 pkt_data = skb_put(tx_skb, pkt_len);
3814 for (i = 0; i < pkt_len; i++)
3815 pkt_data[i] = (u8)(i & 0xff);
3816 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
3817 tx_skb->end-tx_skb->data, PCI_DMA_FROMDEVICE);
3818
3819 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003820 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
3821 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 -04003822 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003823 np->tx_ring.ex[0].bufhigh = cpu_to_le64(test_dma_addr) >> 32;
3824 np->tx_ring.ex[0].buflow = cpu_to_le64(test_dma_addr) & 0x0FFFFFFFF;
3825 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 -04003826 }
3827 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3828 pci_push(get_hwbase(dev));
3829
3830 msleep(500);
3831
3832 /* check for rx of the packet */
3833 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003834 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003835 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
3836
3837 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003838 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003839 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
3840 }
3841
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003842 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003843 ret = 0;
3844 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003845 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003846 ret = 0;
3847 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003848 if (flags & NV_RX2_ERROR) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003849 ret = 0;
3850 }
3851 }
3852
3853 if (ret) {
3854 if (len != pkt_len) {
3855 ret = 0;
3856 dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n",
3857 dev->name, len, pkt_len);
3858 } else {
3859 rx_skb = np->rx_skbuff[0];
3860 for (i = 0; i < pkt_len; i++) {
3861 if (rx_skb->data[i] != (u8)(i & 0xff)) {
3862 ret = 0;
3863 dprintk(KERN_DEBUG "%s: loopback pattern check failed on byte %d\n",
3864 dev->name, i);
3865 break;
3866 }
3867 }
3868 }
3869 } else {
3870 dprintk(KERN_DEBUG "%s: loopback - did not receive test packet\n", dev->name);
3871 }
3872
3873 pci_unmap_page(np->pci_dev, test_dma_addr,
3874 tx_skb->end-tx_skb->data,
3875 PCI_DMA_TODEVICE);
3876 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07003877 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003878 /* stop engines */
3879 nv_stop_rx(dev);
3880 nv_stop_tx(dev);
3881 nv_txrx_reset(dev);
3882 /* drain rx queue */
3883 nv_drain_rx(dev);
3884 nv_drain_tx(dev);
3885
3886 if (netif_running(dev)) {
3887 writel(misc1_flags, base + NvRegMisc1);
3888 writel(filter_flags, base + NvRegPacketFilterFlags);
3889 nv_enable_irq(dev);
3890 }
3891
3892 return ret;
3893}
3894
3895static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
3896{
3897 struct fe_priv *np = netdev_priv(dev);
3898 u8 __iomem *base = get_hwbase(dev);
3899 int result;
3900 memset(buffer, 0, nv_self_test_count(dev)*sizeof(u64));
3901
3902 if (!nv_link_test(dev)) {
3903 test->flags |= ETH_TEST_FL_FAILED;
3904 buffer[0] = 1;
3905 }
3906
3907 if (test->flags & ETH_TEST_FL_OFFLINE) {
3908 if (netif_running(dev)) {
3909 netif_stop_queue(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003910 netif_poll_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003911 netif_tx_lock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003912 spin_lock_irq(&np->lock);
3913 nv_disable_hw_interrupts(dev, np->irqmask);
3914 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3915 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3916 } else {
3917 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3918 }
3919 /* stop engines */
3920 nv_stop_rx(dev);
3921 nv_stop_tx(dev);
3922 nv_txrx_reset(dev);
3923 /* drain rx queue */
3924 nv_drain_rx(dev);
3925 nv_drain_tx(dev);
3926 spin_unlock_irq(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003927 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003928 }
3929
3930 if (!nv_register_test(dev)) {
3931 test->flags |= ETH_TEST_FL_FAILED;
3932 buffer[1] = 1;
3933 }
3934
3935 result = nv_interrupt_test(dev);
3936 if (result != 1) {
3937 test->flags |= ETH_TEST_FL_FAILED;
3938 buffer[2] = 1;
3939 }
3940 if (result == 0) {
3941 /* bail out */
3942 return;
3943 }
3944
3945 if (!nv_loopback_test(dev)) {
3946 test->flags |= ETH_TEST_FL_FAILED;
3947 buffer[3] = 1;
3948 }
3949
3950 if (netif_running(dev)) {
3951 /* reinit driver view of the rx queue */
3952 set_bufsize(dev);
3953 if (nv_init_ring(dev)) {
3954 if (!np->in_shutdown)
3955 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3956 }
3957 /* reinit nic view of the rx queue */
3958 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3959 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3960 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3961 base + NvRegRingSizes);
3962 pci_push(base);
3963 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3964 pci_push(base);
3965 /* restart rx engine */
3966 nv_start_rx(dev);
3967 nv_start_tx(dev);
3968 netif_start_queue(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003969 netif_poll_enable(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003970 nv_enable_hw_interrupts(dev, np->irqmask);
3971 }
3972 }
3973}
3974
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003975static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
3976{
3977 switch (stringset) {
3978 case ETH_SS_STATS:
3979 memcpy(buffer, &nv_estats_str, nv_get_stats_count(dev)*sizeof(struct nv_ethtool_str));
3980 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003981 case ETH_SS_TEST:
3982 memcpy(buffer, &nv_etests_str, nv_self_test_count(dev)*sizeof(struct nv_ethtool_str));
3983 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003984 }
3985}
3986
Jeff Garzik7282d492006-09-13 14:30:00 -04003987static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 .get_drvinfo = nv_get_drvinfo,
3989 .get_link = ethtool_op_get_link,
3990 .get_wol = nv_get_wol,
3991 .set_wol = nv_set_wol,
3992 .get_settings = nv_get_settings,
3993 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003994 .get_regs_len = nv_get_regs_len,
3995 .get_regs = nv_get_regs,
3996 .nway_reset = nv_nway_reset,
John W. Linvillec704b852005-09-12 10:48:56 -04003997 .get_perm_addr = ethtool_op_get_perm_addr,
Zachary Amsden0674d592006-06-04 02:51:38 -07003998 .get_tso = ethtool_op_get_tso,
Ayaz Abdulla6a788142006-06-10 22:47:26 -04003999 .set_tso = nv_set_tso,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004000 .get_ringparam = nv_get_ringparam,
4001 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004002 .get_pauseparam = nv_get_pauseparam,
4003 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004004 .get_rx_csum = nv_get_rx_csum,
4005 .set_rx_csum = nv_set_rx_csum,
4006 .get_tx_csum = ethtool_op_get_tx_csum,
4007 .set_tx_csum = nv_set_tx_csum,
4008 .get_sg = ethtool_op_get_sg,
4009 .set_sg = nv_set_sg,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004010 .get_strings = nv_get_strings,
4011 .get_stats_count = nv_get_stats_count,
4012 .get_ethtool_stats = nv_get_ethtool_stats,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004013 .self_test_count = nv_self_test_count,
4014 .self_test = nv_self_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015};
4016
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004017static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
4018{
4019 struct fe_priv *np = get_nvpriv(dev);
4020
4021 spin_lock_irq(&np->lock);
4022
4023 /* save vlan group */
4024 np->vlangrp = grp;
4025
4026 if (grp) {
4027 /* enable vlan on MAC */
4028 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS;
4029 } else {
4030 /* disable vlan on MAC */
4031 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4032 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4033 }
4034
4035 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4036
4037 spin_unlock_irq(&np->lock);
4038};
4039
4040static void nv_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
4041{
4042 /* nothing to do */
4043};
4044
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004045/* The mgmt unit and driver use a semaphore to access the phy during init */
4046static int nv_mgmt_acquire_sema(struct net_device *dev)
4047{
4048 u8 __iomem *base = get_hwbase(dev);
4049 int i;
4050 u32 tx_ctrl, mgmt_sema;
4051
4052 for (i = 0; i < 10; i++) {
4053 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
4054 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
4055 break;
4056 msleep(500);
4057 }
4058
4059 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
4060 return 0;
4061
4062 for (i = 0; i < 2; i++) {
4063 tx_ctrl = readl(base + NvRegTransmitterControl);
4064 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
4065 writel(tx_ctrl, base + NvRegTransmitterControl);
4066
4067 /* verify that semaphore was acquired */
4068 tx_ctrl = readl(base + NvRegTransmitterControl);
4069 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
4070 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE))
4071 return 1;
4072 else
4073 udelay(50);
4074 }
4075
4076 return 0;
4077}
4078
4079/* Indicate to mgmt unit whether driver is loaded or not */
4080static void nv_mgmt_driver_loaded(struct net_device *dev, int loaded)
4081{
4082 u8 __iomem *base = get_hwbase(dev);
4083 u32 tx_ctrl;
4084
4085 tx_ctrl = readl(base + NvRegTransmitterControl);
4086 if (loaded)
4087 tx_ctrl |= NVREG_XMITCTL_HOST_LOADED;
4088 else
4089 tx_ctrl &= ~NVREG_XMITCTL_HOST_LOADED;
4090 writel(tx_ctrl, base + NvRegTransmitterControl);
4091}
4092
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093static int nv_open(struct net_device *dev)
4094{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004095 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05004097 int ret = 1;
4098 int oom, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099
4100 dprintk(KERN_DEBUG "nv_open: begin\n");
4101
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004102 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004103 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4104 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4106 writel(0, base + NvRegMulticastAddrB);
4107 writel(0, base + NvRegMulticastMaskA);
4108 writel(0, base + NvRegMulticastMaskB);
4109 writel(0, base + NvRegPacketFilterFlags);
4110
4111 writel(0, base + NvRegTransmitterControl);
4112 writel(0, base + NvRegReceiverControl);
4113
4114 writel(0, base + NvRegAdapterControl);
4115
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004116 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
4117 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
4118
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004119 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02004120 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 oom = nv_init_ring(dev);
4122
4123 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004124 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 nv_txrx_reset(dev);
4126 writel(0, base + NvRegUnknownSetupReg6);
4127
4128 np->in_shutdown = 0;
4129
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004130 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05004131 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004132 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 base + NvRegRingSizes);
4134
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04004136 if (np->desc_ver == DESC_VER_1)
4137 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
4138 else
4139 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004140 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004141 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004143 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
4145 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
4146 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
4147
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004148 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4150 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
4151
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
4153 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
4154 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02004155 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156
4157 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
4158 get_random_bytes(&i, sizeof(i));
4159 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed);
Ayaz Abdulla9744e212006-07-06 16:45:58 -04004160 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
4161 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004162 if (poll_interval == -1) {
4163 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
4164 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
4165 else
4166 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4167 }
4168 else
4169 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4171 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
4172 base + NvRegAdapterControl);
4173 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004174 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004175 if (np->wolenabled)
4176 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177
4178 i = readl(base + NvRegPowerState);
4179 if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0)
4180 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
4181
4182 pci_push(base);
4183 udelay(10);
4184 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
4185
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004186 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 pci_push(base);
4188 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
4189 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4190 pci_push(base);
4191
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004192 if (nv_request_irq(dev, 0)) {
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004193 goto out_drain;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05004194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195
4196 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004197 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198
4199 spin_lock_irq(&np->lock);
4200 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4201 writel(0, base + NvRegMulticastAddrB);
4202 writel(0, base + NvRegMulticastMaskA);
4203 writel(0, base + NvRegMulticastMaskB);
4204 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
4205 /* One manual link speed update: Interrupts are enabled, future link
4206 * speed changes cause interrupts and are handled by nv_link_irq().
4207 */
4208 {
4209 u32 miistat;
4210 miistat = readl(base + NvRegMIIStatus);
4211 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
4212 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
4213 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02004214 /* set linkspeed to invalid value, thus force nv_update_linkspeed
4215 * to init hw */
4216 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 ret = nv_update_linkspeed(dev);
4218 nv_start_rx(dev);
4219 nv_start_tx(dev);
4220 netif_start_queue(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004221 netif_poll_enable(dev);
4222
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 if (ret) {
4224 netif_carrier_on(dev);
4225 } else {
4226 printk("%s: no link during initialization.\n", dev->name);
4227 netif_carrier_off(dev);
4228 }
4229 if (oom)
4230 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004231
4232 /* start statistics timer */
4233 if (np->driver_data & DEV_HAS_STATISTICS)
4234 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
4235
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 spin_unlock_irq(&np->lock);
4237
4238 return 0;
4239out_drain:
4240 drain_ring(dev);
4241 return ret;
4242}
4243
4244static int nv_close(struct net_device *dev)
4245{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004246 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 u8 __iomem *base;
4248
4249 spin_lock_irq(&np->lock);
4250 np->in_shutdown = 1;
4251 spin_unlock_irq(&np->lock);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004252 netif_poll_disable(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 synchronize_irq(dev->irq);
4254
4255 del_timer_sync(&np->oom_kick);
4256 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004257 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258
4259 netif_stop_queue(dev);
4260 spin_lock_irq(&np->lock);
4261 nv_stop_tx(dev);
4262 nv_stop_rx(dev);
4263 nv_txrx_reset(dev);
4264
4265 /* disable interrupts on the nic or we will lock up */
4266 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004267 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 pci_push(base);
4269 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
4270
4271 spin_unlock_irq(&np->lock);
4272
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004273 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274
4275 drain_ring(dev);
4276
4277 if (np->wolenabled)
4278 nv_start_rx(dev);
4279
4280 /* FIXME: power down nic */
4281
4282 return 0;
4283}
4284
4285static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
4286{
4287 struct net_device *dev;
4288 struct fe_priv *np;
4289 unsigned long addr;
4290 u8 __iomem *base;
4291 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004292 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004293 u32 phystate_orig = 0, phystate;
4294 int phyinitialized = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295
4296 dev = alloc_etherdev(sizeof(struct fe_priv));
4297 err = -ENOMEM;
4298 if (!dev)
4299 goto out;
4300
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004301 np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 np->pci_dev = pci_dev;
4303 spin_lock_init(&np->lock);
4304 SET_MODULE_OWNER(dev);
4305 SET_NETDEV_DEV(dev, &pci_dev->dev);
4306
4307 init_timer(&np->oom_kick);
4308 np->oom_kick.data = (unsigned long) dev;
4309 np->oom_kick.function = &nv_do_rx_refill; /* timer handler */
4310 init_timer(&np->nic_poll);
4311 np->nic_poll.data = (unsigned long) dev;
4312 np->nic_poll.function = &nv_do_nic_poll; /* timer handler */
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004313 init_timer(&np->stats_poll);
4314 np->stats_poll.data = (unsigned long) dev;
4315 np->stats_poll.function = &nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316
4317 err = pci_enable_device(pci_dev);
4318 if (err) {
4319 printk(KERN_INFO "forcedeth: pci_enable_dev failed (%d) for device %s\n",
4320 err, pci_name(pci_dev));
4321 goto out_free;
4322 }
4323
4324 pci_set_master(pci_dev);
4325
4326 err = pci_request_regions(pci_dev, DRV_NAME);
4327 if (err < 0)
4328 goto out_disable;
4329
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004330 if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS))
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004331 np->register_size = NV_PCI_REGSZ_VER2;
4332 else
4333 np->register_size = NV_PCI_REGSZ_VER1;
4334
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 err = -EINVAL;
4336 addr = 0;
4337 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
4338 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
4339 pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i),
4340 pci_resource_len(pci_dev, i),
4341 pci_resource_flags(pci_dev, i));
4342 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004343 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344 addr = pci_resource_start(pci_dev, i);
4345 break;
4346 }
4347 }
4348 if (i == DEVICE_COUNT_RESOURCE) {
4349 printk(KERN_INFO "forcedeth: Couldn't find register window for device %s.\n",
4350 pci_name(pci_dev));
4351 goto out_relreg;
4352 }
4353
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004354 /* copy of driver data */
4355 np->driver_data = id->driver_data;
4356
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02004358 if (id->driver_data & DEV_HAS_HIGH_DMA) {
4359 /* packet format 3: supports 40-bit addressing */
4360 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004361 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04004362 if (dma_64bit) {
4363 if (pci_set_dma_mask(pci_dev, DMA_39BIT_MASK)) {
4364 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n",
4365 pci_name(pci_dev));
4366 } else {
4367 dev->features |= NETIF_F_HIGHDMA;
4368 printk(KERN_INFO "forcedeth: using HIGHDMA\n");
4369 }
4370 if (pci_set_consistent_dma_mask(pci_dev, DMA_39BIT_MASK)) {
4371 printk(KERN_INFO "forcedeth: 64-bit DMA (consistent) failed, using 32-bit ring buffers for device %s.\n",
4372 pci_name(pci_dev));
4373 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004374 }
Manfred Spraulee733622005-07-31 18:32:26 +02004375 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
4376 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004378 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02004379 } else {
4380 /* original packet format */
4381 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004382 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02004383 }
Manfred Spraulee733622005-07-31 18:32:26 +02004384
4385 np->pkt_limit = NV_PKTLIMIT_1;
4386 if (id->driver_data & DEV_HAS_LARGEDESC)
4387 np->pkt_limit = NV_PKTLIMIT_2;
4388
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004389 if (id->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004390 np->rx_csum = 1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004391 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004392 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
4393#ifdef NETIF_F_TSO
Ayaz Abdullafa454592006-01-05 22:45:45 -08004394 dev->features |= NETIF_F_TSO;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004395#endif
4396 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004397
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004398 np->vlanctl_bits = 0;
4399 if (id->driver_data & DEV_HAS_VLAN) {
4400 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
4401 dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
4402 dev->vlan_rx_register = nv_vlan_rx_register;
4403 dev->vlan_rx_kill_vid = nv_vlan_rx_kill_vid;
4404 }
4405
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05004406 np->msi_flags = 0;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04004407 if ((id->driver_data & DEV_HAS_MSI) && msi) {
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05004408 np->msi_flags |= NV_MSI_CAPABLE;
4409 }
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04004410 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05004411 np->msi_flags |= NV_MSI_X_CAPABLE;
4412 }
4413
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004414 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004415 if (id->driver_data & DEV_HAS_PAUSEFRAME_TX) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004416 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004417 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04004418
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004419
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004421 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 if (!np->base)
4423 goto out_relreg;
4424 dev->base_addr = (unsigned long)np->base;
Manfred Spraulee733622005-07-31 18:32:26 +02004425
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 dev->irq = pci_dev->irq;
Manfred Spraulee733622005-07-31 18:32:26 +02004427
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004428 np->rx_ring_size = RX_RING_DEFAULT;
4429 np->tx_ring_size = TX_RING_DEFAULT;
4430 np->tx_limit_stop = np->tx_ring_size - TX_LIMIT_DIFFERENCE;
4431 np->tx_limit_start = np->tx_ring_size - TX_LIMIT_DIFFERENCE - 1;
4432
Manfred Spraulee733622005-07-31 18:32:26 +02004433 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
4434 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004435 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02004436 &np->ring_addr);
4437 if (!np->rx_ring.orig)
4438 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004439 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02004440 } else {
4441 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004442 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02004443 &np->ring_addr);
4444 if (!np->rx_ring.ex)
4445 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004446 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02004447 }
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004448 np->rx_skbuff = kmalloc(sizeof(struct sk_buff*) * np->rx_ring_size, GFP_KERNEL);
4449 np->rx_dma = kmalloc(sizeof(dma_addr_t) * np->rx_ring_size, GFP_KERNEL);
4450 np->tx_skbuff = kmalloc(sizeof(struct sk_buff*) * np->tx_ring_size, GFP_KERNEL);
4451 np->tx_dma = kmalloc(sizeof(dma_addr_t) * np->tx_ring_size, GFP_KERNEL);
4452 np->tx_dma_len = kmalloc(sizeof(unsigned int) * np->tx_ring_size, GFP_KERNEL);
4453 if (!np->rx_skbuff || !np->rx_dma || !np->tx_skbuff || !np->tx_dma || !np->tx_dma_len)
4454 goto out_freering;
4455 memset(np->rx_skbuff, 0, sizeof(struct sk_buff*) * np->rx_ring_size);
4456 memset(np->rx_dma, 0, sizeof(dma_addr_t) * np->rx_ring_size);
4457 memset(np->tx_skbuff, 0, sizeof(struct sk_buff*) * np->tx_ring_size);
4458 memset(np->tx_dma, 0, sizeof(dma_addr_t) * np->tx_ring_size);
4459 memset(np->tx_dma_len, 0, sizeof(unsigned int) * np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460
4461 dev->open = nv_open;
4462 dev->stop = nv_close;
4463 dev->hard_start_xmit = nv_start_xmit;
4464 dev->get_stats = nv_get_stats;
4465 dev->change_mtu = nv_change_mtu;
Manfred Spraul72b31782005-07-31 18:33:34 +02004466 dev->set_mac_address = nv_set_mac_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 dev->set_multicast_list = nv_set_multicast;
Michal Schmidt2918c352005-05-12 19:42:06 -04004468#ifdef CONFIG_NET_POLL_CONTROLLER
4469 dev->poll_controller = nv_poll_controller;
4470#endif
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004471 dev->weight = 64;
4472#ifdef CONFIG_FORCEDETH_NAPI
4473 dev->poll = nv_napi_poll;
4474#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 SET_ETHTOOL_OPS(dev, &ops);
4476 dev->tx_timeout = nv_tx_timeout;
4477 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
4478
4479 pci_set_drvdata(pci_dev, dev);
4480
4481 /* read the mac address */
4482 base = get_hwbase(dev);
4483 np->orig_mac[0] = readl(base + NvRegMacAddrA);
4484 np->orig_mac[1] = readl(base + NvRegMacAddrB);
4485
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004486 /* check the workaround bit for correct mac address order */
4487 txreg = readl(base + NvRegTransmitPoll);
4488 if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
4489 /* mac address is already in correct order */
4490 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
4491 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
4492 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
4493 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
4494 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
4495 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
4496 } else {
4497 /* need to reverse mac address to correct order */
4498 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
4499 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
4500 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
4501 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
4502 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
4503 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
4504 /* set permanent address to be correct aswell */
4505 np->orig_mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
4506 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
4507 np->orig_mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
4508 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
4509 }
John W. Linvillec704b852005-09-12 10:48:56 -04004510 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511
John W. Linvillec704b852005-09-12 10:48:56 -04004512 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 /*
4514 * Bad mac address. At least one bios sets the mac address
4515 * to 01:23:45:67:89:ab
4516 */
4517 printk(KERN_ERR "%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n",
4518 pci_name(pci_dev),
4519 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
4520 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
4521 printk(KERN_ERR "Please complain to your hardware vendor. Switching to a random MAC.\n");
4522 dev->dev_addr[0] = 0x00;
4523 dev->dev_addr[1] = 0x00;
4524 dev->dev_addr[2] = 0x6c;
4525 get_random_bytes(&dev->dev_addr[3], 3);
4526 }
4527
4528 dprintk(KERN_DEBUG "%s: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", pci_name(pci_dev),
4529 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
4530 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
4531
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004532 /* set mac address */
4533 nv_copy_mac_to_hw(dev);
4534
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535 /* disable WOL */
4536 writel(0, base + NvRegWakeUpFlags);
4537 np->wolenabled = 0;
4538
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004539 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
4540 u8 revision_id;
4541 pci_read_config_byte(pci_dev, PCI_REVISION_ID, &revision_id);
4542
4543 /* take phy and nic out of low power mode */
4544 powerstate = readl(base + NvRegPowerState2);
4545 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
4546 if ((id->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 ||
4547 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_13) &&
4548 revision_id >= 0xA3)
4549 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
4550 writel(powerstate, base + NvRegPowerState2);
4551 }
4552
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004554 np->tx_flags = NV_TX_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555 } else {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004556 np->tx_flags = NV_TX2_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 }
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05004558 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004559 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05004560 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
4561 np->msi_flags |= 0x0003;
4562 } else {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004563 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c2006-02-04 13:13:31 -05004564 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
4565 np->msi_flags |= 0x0001;
4566 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004567
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 if (id->driver_data & DEV_NEED_TIMERIRQ)
4569 np->irqmask |= NVREG_IRQ_TIMER;
4570 if (id->driver_data & DEV_NEED_LINKTIMER) {
4571 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
4572 np->need_linktimer = 1;
4573 np->link_timeout = jiffies + LINK_TIMEOUT;
4574 } else {
4575 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
4576 np->need_linktimer = 0;
4577 }
4578
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004579 /* clear phy state and temporarily halt phy interrupts */
4580 writel(0, base + NvRegMIIMask);
4581 phystate = readl(base + NvRegAdapterControl);
4582 if (phystate & NVREG_ADAPTCTL_RUNNING) {
4583 phystate_orig = 1;
4584 phystate &= ~NVREG_ADAPTCTL_RUNNING;
4585 writel(phystate, base + NvRegAdapterControl);
4586 }
4587 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
4588
4589 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
4590 writel(0x1, base + 0x204); pci_push(base);
4591 msleep(500);
4592 /* management unit running on the mac? */
4593 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST;
4594 if (np->mac_in_use) {
4595 u32 mgmt_sync;
4596 /* management unit setup the phy already? */
4597 mgmt_sync = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK;
4598 if (mgmt_sync == NVREG_XMITCTL_SYNC_NOT_READY) {
4599 if (!nv_mgmt_acquire_sema(dev)) {
4600 for (i = 0; i < 5000; i++) {
4601 msleep(1);
4602 mgmt_sync = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK;
4603 if (mgmt_sync == NVREG_XMITCTL_SYNC_NOT_READY)
4604 continue;
4605 if (mgmt_sync == NVREG_XMITCTL_SYNC_PHY_INIT)
4606 phyinitialized = 1;
4607 break;
4608 }
4609 } else {
4610 /* we need to init the phy */
4611 }
4612 } else if (mgmt_sync == NVREG_XMITCTL_SYNC_PHY_INIT) {
4613 /* phy is inited by SMU */
4614 phyinitialized = 1;
4615 } else {
4616 /* we need to init the phy */
4617 }
4618 }
4619 }
4620
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004622 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004624 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625
4626 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004627 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 spin_unlock_irq(&np->lock);
4629 if (id1 < 0 || id1 == 0xffff)
4630 continue;
4631 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004632 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 spin_unlock_irq(&np->lock);
4634 if (id2 < 0 || id2 == 0xffff)
4635 continue;
4636
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004637 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
4639 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
4640 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004641 pci_name(pci_dev), id1, id2, phyaddr);
4642 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643 np->phy_oui = id1 | id2;
4644 break;
4645 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004646 if (i == 33) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 printk(KERN_INFO "%s: open: Could not find a valid PHY.\n",
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004648 pci_name(pci_dev));
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004649 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04004651
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004652 if (!phyinitialized) {
4653 /* reset it */
4654 phy_init(dev);
4655 }
4656
4657 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
4658 nv_mgmt_driver_loaded(dev, 1);
4659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660
4661 /* set default link speed settings */
4662 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
4663 np->duplex = 0;
4664 np->autoneg = 1;
4665
4666 err = register_netdev(dev);
4667 if (err) {
4668 printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004669 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 }
4671 printk(KERN_INFO "%s: forcedeth.c: subsystem: %05x:%04x bound to %s\n",
4672 dev->name, pci_dev->subsystem_vendor, pci_dev->subsystem_device,
4673 pci_name(pci_dev));
4674
4675 return 0;
4676
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004677out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004678 if (phystate_orig)
4679 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
4680 if (np->mac_in_use)
4681 nv_mgmt_driver_loaded(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004683out_freering:
4684 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685out_unmap:
4686 iounmap(get_hwbase(dev));
4687out_relreg:
4688 pci_release_regions(pci_dev);
4689out_disable:
4690 pci_disable_device(pci_dev);
4691out_free:
4692 free_netdev(dev);
4693out:
4694 return err;
4695}
4696
4697static void __devexit nv_remove(struct pci_dev *pci_dev)
4698{
4699 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004700 struct fe_priv *np = netdev_priv(dev);
4701 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702
4703 unregister_netdev(dev);
4704
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004705 /* special op: write back the misordered MAC address - otherwise
4706 * the next nv_probe would see a wrong address.
4707 */
4708 writel(np->orig_mac[0], base + NvRegMacAddrA);
4709 writel(np->orig_mac[1], base + NvRegMacAddrB);
4710
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004711 if (np->mac_in_use)
4712 nv_mgmt_driver_loaded(dev, 0);
4713
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004715 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 iounmap(get_hwbase(dev));
4717 pci_release_regions(pci_dev);
4718 pci_disable_device(pci_dev);
4719 free_netdev(dev);
4720 pci_set_drvdata(pci_dev, NULL);
4721}
4722
Francois Romieua1893172006-10-10 14:33:27 -07004723#ifdef CONFIG_PM
4724static int nv_suspend(struct pci_dev *pdev, pm_message_t state)
4725{
4726 struct net_device *dev = pci_get_drvdata(pdev);
4727 struct fe_priv *np = netdev_priv(dev);
4728
4729 if (!netif_running(dev))
4730 goto out;
4731
4732 netif_device_detach(dev);
4733
4734 // Gross.
4735 nv_close(dev);
4736
4737 pci_save_state(pdev);
4738 pci_enable_wake(pdev, pci_choose_state(pdev, state), np->wolenabled);
4739 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4740out:
4741 return 0;
4742}
4743
4744static int nv_resume(struct pci_dev *pdev)
4745{
4746 struct net_device *dev = pci_get_drvdata(pdev);
4747 int rc = 0;
4748
4749 if (!netif_running(dev))
4750 goto out;
4751
4752 netif_device_attach(dev);
4753
4754 pci_set_power_state(pdev, PCI_D0);
4755 pci_restore_state(pdev);
4756 pci_enable_wake(pdev, PCI_D0, 0);
4757
4758 rc = nv_open(dev);
4759out:
4760 return rc;
4761}
4762#else
4763#define nv_suspend NULL
4764#define nv_resume NULL
4765#endif /* CONFIG_PM */
4766
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767static struct pci_device_id pci_tbl[] = {
4768 { /* nForce Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004769 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1),
Manfred Spraulc2dba062005-07-31 18:29:47 +02004770 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771 },
4772 { /* nForce2 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004773 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2),
Manfred Spraulc2dba062005-07-31 18:29:47 +02004774 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 },
4776 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004777 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02004778 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779 },
4780 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004781 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004782 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 },
4784 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004785 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004786 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 },
4788 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004789 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004790 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791 },
4792 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004793 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004794 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 },
4796 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004797 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004798 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 },
4800 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004801 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004802 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 },
4804 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004805 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004806 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807 },
4808 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004809 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004810 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004811 },
4812 { /* MCP51 Ethernet Controller */
4813 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004814 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02004816 { /* MCP51 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004817 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13),
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004818 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
Manfred Spraul9992d4a2005-06-05 17:36:11 +02004819 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02004820 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004821 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004822 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02004823 },
4824 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004825 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004826 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02004827 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004828 { /* MCP61 Ethernet Controller */
4829 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_16),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004830 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004831 },
4832 { /* MCP61 Ethernet Controller */
4833 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_17),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004834 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004835 },
4836 { /* MCP61 Ethernet Controller */
4837 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_18),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004838 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004839 },
4840 { /* MCP61 Ethernet Controller */
4841 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_19),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004842 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004843 },
4844 { /* MCP65 Ethernet Controller */
4845 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004846 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004847 },
4848 { /* MCP65 Ethernet Controller */
4849 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004850 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004851 },
4852 { /* MCP65 Ethernet Controller */
4853 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004854 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004855 },
4856 { /* MCP65 Ethernet Controller */
4857 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004858 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004859 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860 {0,},
4861};
4862
4863static struct pci_driver driver = {
4864 .name = "forcedeth",
4865 .id_table = pci_tbl,
4866 .probe = nv_probe,
4867 .remove = __devexit_p(nv_remove),
Francois Romieua1893172006-10-10 14:33:27 -07004868 .suspend = nv_suspend,
4869 .resume = nv_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870};
4871
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872static int __init init_nic(void)
4873{
4874 printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION);
Jeff Garzik29917622006-08-19 17:48:59 -04004875 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876}
4877
4878static void __exit exit_nic(void)
4879{
4880 pci_unregister_driver(&driver);
4881}
4882
4883module_param(max_interrupt_work, int, 0);
4884MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004885module_param(optimization_mode, int, 0);
4886MODULE_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.");
4887module_param(poll_interval, int, 0);
4888MODULE_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 -04004889module_param(msi, int, 0);
4890MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
4891module_param(msix, int, 0);
4892MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
4893module_param(dma_64bit, int, 0);
4894MODULE_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 -07004895
4896MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
4897MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
4898MODULE_LICENSE("GPL");
4899
4900MODULE_DEVICE_TABLE(pci, pci_tbl);
4901
4902module_init(init_nic);
4903module_exit(exit_nic);