blob: 439f41338291a2bb065ee2d938e233d9b053eb96 [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 Abdullad33a73c82006-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.
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500114 * 0.59: 30 Oct 2006: Added support for recoverable error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 * Known bugs:
117 * We suspect that on some hardware no TX done interrupts are generated.
118 * This means recovery from netif_stop_queue only happens if the hw timer
119 * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
120 * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
121 * If your hardware reliably generates tx done interrupts, then you can remove
122 * DEV_NEED_TIMERIRQ from the driver_data flags.
123 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
124 * superfluous timer interrupts from the nic.
125 */
Stephen Hemmingere27cdba2006-07-31 20:37:19 -0700126#ifdef CONFIG_FORCEDETH_NAPI
127#define DRIVERNAPI "-NAPI"
128#else
129#define DRIVERNAPI
130#endif
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500131#define FORCEDETH_VERSION "0.59"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#define DRV_NAME "forcedeth"
133
134#include <linux/module.h>
135#include <linux/types.h>
136#include <linux/pci.h>
137#include <linux/interrupt.h>
138#include <linux/netdevice.h>
139#include <linux/etherdevice.h>
140#include <linux/delay.h>
141#include <linux/spinlock.h>
142#include <linux/ethtool.h>
143#include <linux/timer.h>
144#include <linux/skbuff.h>
145#include <linux/mii.h>
146#include <linux/random.h>
147#include <linux/init.h>
Manfred Spraul22c6d142005-04-19 21:17:09 +0200148#include <linux/if_vlan.h>
Matthias Gehre910638a2006-03-28 01:56:48 -0800149#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151#include <asm/irq.h>
152#include <asm/io.h>
153#include <asm/uaccess.h>
154#include <asm/system.h>
155
156#if 0
157#define dprintk printk
158#else
159#define dprintk(x...) do { } while (0)
160#endif
161
162
163/*
164 * Hardware access:
165 */
166
Manfred Spraulc2dba062005-07-31 18:29:47 +0200167#define DEV_NEED_TIMERIRQ 0x0001 /* set the timer irq flag in the irq mask */
168#define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */
169#define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */
Manfred Spraulee733622005-07-31 18:32:26 +0200170#define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400171#define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500172#define DEV_HAS_VLAN 0x0020 /* device supports vlan tagging and striping */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500173#define DEV_HAS_MSI 0x0040 /* device supports MSI */
174#define DEV_HAS_MSI_X 0x0080 /* device supports MSI-X */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400175#define DEV_HAS_POWER_CNTRL 0x0100 /* device supports power savings */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400176#define DEV_HAS_PAUSEFRAME_TX 0x0200 /* device supports tx pause frames */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400177#define DEV_HAS_STATISTICS 0x0400 /* device supports hw statistics */
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400178#define DEV_HAS_TEST_EXTENDED 0x0800 /* device supports extended diagnostic test */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500179#define DEV_HAS_MGMT_UNIT 0x1000 /* device supports management unit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181enum {
182 NvRegIrqStatus = 0x000,
183#define NVREG_IRQSTAT_MIIEVENT 0x040
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500184#define NVREG_IRQSTAT_MASK 0x81ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 NvRegIrqMask = 0x004,
186#define NVREG_IRQ_RX_ERROR 0x0001
187#define NVREG_IRQ_RX 0x0002
188#define NVREG_IRQ_RX_NOBUF 0x0004
189#define NVREG_IRQ_TX_ERR 0x0008
Manfred Spraulc2dba062005-07-31 18:29:47 +0200190#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#define NVREG_IRQ_TIMER 0x0020
192#define NVREG_IRQ_LINK 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500193#define NVREG_IRQ_RX_FORCED 0x0080
194#define NVREG_IRQ_TX_FORCED 0x0100
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500195#define NVREG_IRQ_RECOVER_ERROR 0x8000
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500196#define NVREG_IRQMASK_THROUGHPUT 0x00df
197#define NVREG_IRQMASK_CPU 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500198#define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
199#define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED)
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500200#define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200201
202#define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500203 NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RX_FORCED| \
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500204 NVREG_IRQ_TX_FORCED|NVREG_IRQ_RECOVER_ERROR))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 NvRegUnknownSetupReg6 = 0x008,
207#define NVREG_UNKSETUP6_VAL 3
208
209/*
210 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
211 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
212 */
213 NvRegPollingInterval = 0x00c,
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500214#define NVREG_POLL_DEFAULT_THROUGHPUT 970
215#define NVREG_POLL_DEFAULT_CPU 13
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500216 NvRegMSIMap0 = 0x020,
217 NvRegMSIMap1 = 0x024,
218 NvRegMSIIrqMask = 0x030,
219#define NVREG_MSI_VECTOR_0_ENABLED 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 NvRegMisc1 = 0x080,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400221#define NVREG_MISC1_PAUSE_TX 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define NVREG_MISC1_HD 0x02
223#define NVREG_MISC1_FORCE 0x3b0f3c
224
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400225 NvRegMacReset = 0x3c,
226#define NVREG_MAC_RESET_ASSERT 0x0F3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 NvRegTransmitterControl = 0x084,
228#define NVREG_XMITCTL_START 0x01
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500229#define NVREG_XMITCTL_MGMT_ST 0x40000000
230#define NVREG_XMITCTL_SYNC_MASK 0x000f0000
231#define NVREG_XMITCTL_SYNC_NOT_READY 0x0
232#define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
233#define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
234#define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
235#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
236#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
237#define NVREG_XMITCTL_HOST_LOADED 0x00004000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 NvRegTransmitterStatus = 0x088,
239#define NVREG_XMITSTAT_BUSY 0x01
240
241 NvRegPacketFilterFlags = 0x8c,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400242#define NVREG_PFF_PAUSE_RX 0x08
243#define NVREG_PFF_ALWAYS 0x7F0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define NVREG_PFF_PROMISC 0x80
245#define NVREG_PFF_MYADDR 0x20
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400246#define NVREG_PFF_LOOPBACK 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 NvRegOffloadConfig = 0x90,
249#define NVREG_OFFLOAD_HOMEPHY 0x601
250#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
251 NvRegReceiverControl = 0x094,
252#define NVREG_RCVCTL_START 0x01
253 NvRegReceiverStatus = 0x98,
254#define NVREG_RCVSTAT_BUSY 0x01
255
256 NvRegRandomSeed = 0x9c,
257#define NVREG_RNDSEED_MASK 0x00ff
258#define NVREG_RNDSEED_FORCE 0x7f00
259#define NVREG_RNDSEED_FORCE2 0x2d00
260#define NVREG_RNDSEED_FORCE3 0x7400
261
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400262 NvRegTxDeferral = 0xA0,
263#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
264#define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
265#define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
266 NvRegRxDeferral = 0xA4,
267#define NVREG_RX_DEFERRAL_DEFAULT 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 NvRegMacAddrA = 0xA8,
269 NvRegMacAddrB = 0xAC,
270 NvRegMulticastAddrA = 0xB0,
271#define NVREG_MCASTADDRA_FORCE 0x01
272 NvRegMulticastAddrB = 0xB4,
273 NvRegMulticastMaskA = 0xB8,
274 NvRegMulticastMaskB = 0xBC,
275
276 NvRegPhyInterface = 0xC0,
277#define PHY_RGMII 0x10000000
278
279 NvRegTxRingPhysAddr = 0x100,
280 NvRegRxRingPhysAddr = 0x104,
281 NvRegRingSizes = 0x108,
282#define NVREG_RINGSZ_TXSHIFT 0
283#define NVREG_RINGSZ_RXSHIFT 16
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400284 NvRegTransmitPoll = 0x10c,
285#define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 NvRegLinkSpeed = 0x110,
287#define NVREG_LINKSPEED_FORCE 0x10000
288#define NVREG_LINKSPEED_10 1000
289#define NVREG_LINKSPEED_100 100
290#define NVREG_LINKSPEED_1000 50
291#define NVREG_LINKSPEED_MASK (0xFFF)
292 NvRegUnknownSetupReg5 = 0x130,
293#define NVREG_UNKSETUP5_BIT31 (1<<31)
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400294 NvRegTxWatermark = 0x13c,
295#define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
296#define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
297#define NVREG_TX_WM_DESC2_3_1000 0xfe08000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 NvRegTxRxControl = 0x144,
299#define NVREG_TXRXCTL_KICK 0x0001
300#define NVREG_TXRXCTL_BIT1 0x0002
301#define NVREG_TXRXCTL_BIT2 0x0004
302#define NVREG_TXRXCTL_IDLE 0x0008
303#define NVREG_TXRXCTL_RESET 0x0010
304#define NVREG_TXRXCTL_RXCHECK 0x0400
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400305#define NVREG_TXRXCTL_DESC_1 0
306#define NVREG_TXRXCTL_DESC_2 0x02100
307#define NVREG_TXRXCTL_DESC_3 0x02200
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500308#define NVREG_TXRXCTL_VLANSTRIP 0x00040
309#define NVREG_TXRXCTL_VLANINS 0x00080
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500310 NvRegTxRingPhysAddrHigh = 0x148,
311 NvRegRxRingPhysAddrHigh = 0x14C,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400312 NvRegTxPauseFrame = 0x170,
313#define NVREG_TX_PAUSEFRAME_DISABLE 0x1ff0080
314#define NVREG_TX_PAUSEFRAME_ENABLE 0x0c00030
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 NvRegMIIStatus = 0x180,
316#define NVREG_MIISTAT_ERROR 0x0001
317#define NVREG_MIISTAT_LINKCHANGE 0x0008
318#define NVREG_MIISTAT_MASK 0x000f
319#define NVREG_MIISTAT_MASK2 0x000f
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500320 NvRegMIIMask = 0x184,
321#define NVREG_MII_LINKCHANGE 0x0008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 NvRegAdapterControl = 0x188,
324#define NVREG_ADAPTCTL_START 0x02
325#define NVREG_ADAPTCTL_LINKUP 0x04
326#define NVREG_ADAPTCTL_PHYVALID 0x40000
327#define NVREG_ADAPTCTL_RUNNING 0x100000
328#define NVREG_ADAPTCTL_PHYSHIFT 24
329 NvRegMIISpeed = 0x18c,
330#define NVREG_MIISPEED_BIT8 (1<<8)
331#define NVREG_MIIDELAY 5
332 NvRegMIIControl = 0x190,
333#define NVREG_MIICTL_INUSE 0x08000
334#define NVREG_MIICTL_WRITE 0x00400
335#define NVREG_MIICTL_ADDRSHIFT 5
336 NvRegMIIData = 0x194,
337 NvRegWakeUpFlags = 0x200,
338#define NVREG_WAKEUPFLAGS_VAL 0x7770
339#define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
340#define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
341#define NVREG_WAKEUPFLAGS_D3SHIFT 12
342#define NVREG_WAKEUPFLAGS_D2SHIFT 8
343#define NVREG_WAKEUPFLAGS_D1SHIFT 4
344#define NVREG_WAKEUPFLAGS_D0SHIFT 0
345#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
346#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
347#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
348#define NVREG_WAKEUPFLAGS_ENABLE 0x1111
349
350 NvRegPatternCRC = 0x204,
351 NvRegPatternMask = 0x208,
352 NvRegPowerCap = 0x268,
353#define NVREG_POWERCAP_D3SUPP (1<<30)
354#define NVREG_POWERCAP_D2SUPP (1<<26)
355#define NVREG_POWERCAP_D1SUPP (1<<25)
356 NvRegPowerState = 0x26c,
357#define NVREG_POWERSTATE_POWEREDUP 0x8000
358#define NVREG_POWERSTATE_VALID 0x0100
359#define NVREG_POWERSTATE_MASK 0x0003
360#define NVREG_POWERSTATE_D0 0x0000
361#define NVREG_POWERSTATE_D1 0x0001
362#define NVREG_POWERSTATE_D2 0x0002
363#define NVREG_POWERSTATE_D3 0x0003
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400364 NvRegTxCnt = 0x280,
365 NvRegTxZeroReXmt = 0x284,
366 NvRegTxOneReXmt = 0x288,
367 NvRegTxManyReXmt = 0x28c,
368 NvRegTxLateCol = 0x290,
369 NvRegTxUnderflow = 0x294,
370 NvRegTxLossCarrier = 0x298,
371 NvRegTxExcessDef = 0x29c,
372 NvRegTxRetryErr = 0x2a0,
373 NvRegRxFrameErr = 0x2a4,
374 NvRegRxExtraByte = 0x2a8,
375 NvRegRxLateCol = 0x2ac,
376 NvRegRxRunt = 0x2b0,
377 NvRegRxFrameTooLong = 0x2b4,
378 NvRegRxOverflow = 0x2b8,
379 NvRegRxFCSErr = 0x2bc,
380 NvRegRxFrameAlignErr = 0x2c0,
381 NvRegRxLenErr = 0x2c4,
382 NvRegRxUnicast = 0x2c8,
383 NvRegRxMulticast = 0x2cc,
384 NvRegRxBroadcast = 0x2d0,
385 NvRegTxDef = 0x2d4,
386 NvRegTxFrame = 0x2d8,
387 NvRegRxCnt = 0x2dc,
388 NvRegTxPause = 0x2e0,
389 NvRegRxPause = 0x2e4,
390 NvRegRxDropFrame = 0x2e8,
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500391 NvRegVlanControl = 0x300,
392#define NVREG_VLANCONTROL_ENABLE 0x2000
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500393 NvRegMSIXMap0 = 0x3e0,
394 NvRegMSIXMap1 = 0x3e4,
395 NvRegMSIXIrqStatus = 0x3f0,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400396
397 NvRegPowerState2 = 0x600,
398#define NVREG_POWERSTATE2_POWERUP_MASK 0x0F11
399#define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400};
401
402/* Big endian: should work, but is untested */
403struct ring_desc {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700404 __le32 buf;
405 __le32 flaglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406};
407
Manfred Spraulee733622005-07-31 18:32:26 +0200408struct ring_desc_ex {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700409 __le32 bufhigh;
410 __le32 buflow;
411 __le32 txvlan;
412 __le32 flaglen;
Manfred Spraulee733622005-07-31 18:32:26 +0200413};
414
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700415union ring_type {
Manfred Spraulee733622005-07-31 18:32:26 +0200416 struct ring_desc* orig;
417 struct ring_desc_ex* ex;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700418};
Manfred Spraulee733622005-07-31 18:32:26 +0200419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define FLAG_MASK_V1 0xffff0000
421#define FLAG_MASK_V2 0xffffc000
422#define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
423#define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
424
425#define NV_TX_LASTPACKET (1<<16)
426#define NV_TX_RETRYERROR (1<<19)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200427#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#define NV_TX_DEFERRED (1<<26)
429#define NV_TX_CARRIERLOST (1<<27)
430#define NV_TX_LATECOLLISION (1<<28)
431#define NV_TX_UNDERFLOW (1<<29)
432#define NV_TX_ERROR (1<<30)
433#define NV_TX_VALID (1<<31)
434
435#define NV_TX2_LASTPACKET (1<<29)
436#define NV_TX2_RETRYERROR (1<<18)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200437#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438#define NV_TX2_DEFERRED (1<<25)
439#define NV_TX2_CARRIERLOST (1<<26)
440#define NV_TX2_LATECOLLISION (1<<27)
441#define NV_TX2_UNDERFLOW (1<<28)
442/* error and valid are the same for both */
443#define NV_TX2_ERROR (1<<30)
444#define NV_TX2_VALID (1<<31)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400445#define NV_TX2_TSO (1<<28)
446#define NV_TX2_TSO_SHIFT 14
Ayaz Abdullafa454592006-01-05 22:45:45 -0800447#define NV_TX2_TSO_MAX_SHIFT 14
448#define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400449#define NV_TX2_CHECKSUM_L3 (1<<27)
450#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500452#define NV_TX3_VLAN_TAG_PRESENT (1<<18)
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#define NV_RX_DESCRIPTORVALID (1<<16)
455#define NV_RX_MISSEDFRAME (1<<17)
456#define NV_RX_SUBSTRACT1 (1<<18)
457#define NV_RX_ERROR1 (1<<23)
458#define NV_RX_ERROR2 (1<<24)
459#define NV_RX_ERROR3 (1<<25)
460#define NV_RX_ERROR4 (1<<26)
461#define NV_RX_CRCERR (1<<27)
462#define NV_RX_OVERFLOW (1<<28)
463#define NV_RX_FRAMINGERR (1<<29)
464#define NV_RX_ERROR (1<<30)
465#define NV_RX_AVAIL (1<<31)
466
467#define NV_RX2_CHECKSUMMASK (0x1C000000)
468#define NV_RX2_CHECKSUMOK1 (0x10000000)
469#define NV_RX2_CHECKSUMOK2 (0x14000000)
470#define NV_RX2_CHECKSUMOK3 (0x18000000)
471#define NV_RX2_DESCRIPTORVALID (1<<29)
472#define NV_RX2_SUBSTRACT1 (1<<25)
473#define NV_RX2_ERROR1 (1<<18)
474#define NV_RX2_ERROR2 (1<<19)
475#define NV_RX2_ERROR3 (1<<20)
476#define NV_RX2_ERROR4 (1<<21)
477#define NV_RX2_CRCERR (1<<22)
478#define NV_RX2_OVERFLOW (1<<23)
479#define NV_RX2_FRAMINGERR (1<<24)
480/* error and avail are the same for both */
481#define NV_RX2_ERROR (1<<30)
482#define NV_RX2_AVAIL (1<<31)
483
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500484#define NV_RX3_VLAN_TAG_PRESENT (1<<16)
485#define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487/* Miscelaneous hardware related defines: */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400488#define NV_PCI_REGSZ_VER1 0x270
489#define NV_PCI_REGSZ_VER2 0x604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491/* various timeout delays: all in usec */
492#define NV_TXRX_RESET_DELAY 4
493#define NV_TXSTOP_DELAY1 10
494#define NV_TXSTOP_DELAY1MAX 500000
495#define NV_TXSTOP_DELAY2 100
496#define NV_RXSTOP_DELAY1 10
497#define NV_RXSTOP_DELAY1MAX 500000
498#define NV_RXSTOP_DELAY2 100
499#define NV_SETUP5_DELAY 5
500#define NV_SETUP5_DELAYMAX 50000
501#define NV_POWERUP_DELAY 5
502#define NV_POWERUP_DELAYMAX 5000
503#define NV_MIIBUSY_DELAY 50
504#define NV_MIIPHY_DELAY 10
505#define NV_MIIPHY_DELAYMAX 10000
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400506#define NV_MAC_RESET_DELAY 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508#define NV_WAKEUPPATTERNS 5
509#define NV_WAKEUPMASKENTRIES 4
510
511/* General driver defaults */
512#define NV_WATCHDOG_TIMEO (5*HZ)
513
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400514#define RX_RING_DEFAULT 128
515#define TX_RING_DEFAULT 256
516#define RX_RING_MIN 128
517#define TX_RING_MIN 64
518#define RING_MAX_DESC_VER_1 1024
519#define RING_MAX_DESC_VER_2_3 16384
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400520/*
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400521 * Difference between the get and put pointers for the tx ring.
522 * This is used to throttle the amount of data outstanding in the
523 * tx ring.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400525#define TX_LIMIT_DIFFERENCE 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200528#define NV_RX_HEADERS (64)
529/* even more slack. */
530#define NV_RX_ALLOC_PAD (64)
531
532/* maximum mtu size */
533#define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
534#define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536#define OOM_REFILL (1+HZ/20)
537#define POLL_WAIT (1+HZ/100)
538#define LINK_TIMEOUT (3*HZ)
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400539#define STATS_INTERVAL (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400541/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400543 * The nic supports three different descriptor types:
544 * - DESC_VER_1: Original
545 * - DESC_VER_2: support for jumbo frames.
546 * - DESC_VER_3: 64-bit format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400548#define DESC_VER_1 1
549#define DESC_VER_2 2
550#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552/* PHY defines */
553#define PHY_OUI_MARVELL 0x5043
554#define PHY_OUI_CICADA 0x03f1
555#define PHYID1_OUI_MASK 0x03ff
556#define PHYID1_OUI_SHFT 6
557#define PHYID2_OUI_MASK 0xfc00
558#define PHYID2_OUI_SHFT 10
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400559#define PHYID2_MODEL_MASK 0x03f0
560#define PHY_MODEL_MARVELL_E3016 0x220
561#define PHY_MARVELL_E3016_INITMASK 0x0300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#define PHY_INIT1 0x0f000
563#define PHY_INIT2 0x0e00
564#define PHY_INIT3 0x01000
565#define PHY_INIT4 0x0200
566#define PHY_INIT5 0x0004
567#define PHY_INIT6 0x02000
568#define PHY_GIGABIT 0x0100
569
570#define PHY_TIMEOUT 0x1
571#define PHY_ERROR 0x2
572
573#define PHY_100 0x1
574#define PHY_1000 0x2
575#define PHY_HALF 0x100
576
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400577#define NV_PAUSEFRAME_RX_CAPABLE 0x0001
578#define NV_PAUSEFRAME_TX_CAPABLE 0x0002
579#define NV_PAUSEFRAME_RX_ENABLE 0x0004
580#define NV_PAUSEFRAME_TX_ENABLE 0x0008
Ayaz Abdullab6d07732006-06-10 22:47:42 -0400581#define NV_PAUSEFRAME_RX_REQ 0x0010
582#define NV_PAUSEFRAME_TX_REQ 0x0020
583#define NV_PAUSEFRAME_AUTONEG 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500585/* MSI/MSI-X defines */
586#define NV_MSI_X_MAX_VECTORS 8
587#define NV_MSI_X_VECTORS_MASK 0x000f
588#define NV_MSI_CAPABLE 0x0010
589#define NV_MSI_X_CAPABLE 0x0020
590#define NV_MSI_ENABLED 0x0040
591#define NV_MSI_X_ENABLED 0x0080
592
593#define NV_MSI_X_VECTOR_ALL 0x0
594#define NV_MSI_X_VECTOR_RX 0x0
595#define NV_MSI_X_VECTOR_TX 0x1
596#define NV_MSI_X_VECTOR_OTHER 0x2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400598/* statistics */
599struct nv_ethtool_str {
600 char name[ETH_GSTRING_LEN];
601};
602
603static const struct nv_ethtool_str nv_estats_str[] = {
604 { "tx_bytes" },
605 { "tx_zero_rexmt" },
606 { "tx_one_rexmt" },
607 { "tx_many_rexmt" },
608 { "tx_late_collision" },
609 { "tx_fifo_errors" },
610 { "tx_carrier_errors" },
611 { "tx_excess_deferral" },
612 { "tx_retry_error" },
613 { "tx_deferral" },
614 { "tx_packets" },
615 { "tx_pause" },
616 { "rx_frame_error" },
617 { "rx_extra_byte" },
618 { "rx_late_collision" },
619 { "rx_runt" },
620 { "rx_frame_too_long" },
621 { "rx_over_errors" },
622 { "rx_crc_errors" },
623 { "rx_frame_align_error" },
624 { "rx_length_error" },
625 { "rx_unicast" },
626 { "rx_multicast" },
627 { "rx_broadcast" },
628 { "rx_bytes" },
629 { "rx_pause" },
630 { "rx_drop_frame" },
631 { "rx_packets" },
632 { "rx_errors_total" }
633};
634
635struct nv_ethtool_stats {
636 u64 tx_bytes;
637 u64 tx_zero_rexmt;
638 u64 tx_one_rexmt;
639 u64 tx_many_rexmt;
640 u64 tx_late_collision;
641 u64 tx_fifo_errors;
642 u64 tx_carrier_errors;
643 u64 tx_excess_deferral;
644 u64 tx_retry_error;
645 u64 tx_deferral;
646 u64 tx_packets;
647 u64 tx_pause;
648 u64 rx_frame_error;
649 u64 rx_extra_byte;
650 u64 rx_late_collision;
651 u64 rx_runt;
652 u64 rx_frame_too_long;
653 u64 rx_over_errors;
654 u64 rx_crc_errors;
655 u64 rx_frame_align_error;
656 u64 rx_length_error;
657 u64 rx_unicast;
658 u64 rx_multicast;
659 u64 rx_broadcast;
660 u64 rx_bytes;
661 u64 rx_pause;
662 u64 rx_drop_frame;
663 u64 rx_packets;
664 u64 rx_errors_total;
665};
666
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400667/* diagnostics */
668#define NV_TEST_COUNT_BASE 3
669#define NV_TEST_COUNT_EXTENDED 4
670
671static const struct nv_ethtool_str nv_etests_str[] = {
672 { "link (online/offline)" },
673 { "register (offline) " },
674 { "interrupt (offline) " },
675 { "loopback (offline) " }
676};
677
678struct register_test {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700679 __le32 reg;
680 __le32 mask;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400681};
682
683static const struct register_test nv_registers_test[] = {
684 { NvRegUnknownSetupReg6, 0x01 },
685 { NvRegMisc1, 0x03c },
686 { NvRegOffloadConfig, 0x03ff },
687 { NvRegMulticastAddrA, 0xffffffff },
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400688 { NvRegTxWatermark, 0x0ff },
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400689 { NvRegWakeUpFlags, 0x07777 },
690 { 0,0 }
691};
692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693/*
694 * SMP locking:
695 * All hardware access under dev->priv->lock, except the performance
696 * critical parts:
697 * - rx is (pseudo-) lockless: it relies on the single-threading provided
698 * by the arch code for interrupts.
Herbert Xu932ff272006-06-09 12:20:56 -0700699 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 * needs dev->priv->lock :-(
Herbert Xu932ff272006-06-09 12:20:56 -0700701 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 */
703
704/* in dev: base, irq */
705struct fe_priv {
706 spinlock_t lock;
707
708 /* General data:
709 * Locking: spin_lock(&np->lock); */
710 struct net_device_stats stats;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400711 struct nv_ethtool_stats estats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 int in_shutdown;
713 u32 linkspeed;
714 int duplex;
715 int autoneg;
716 int fixed_mode;
717 int phyaddr;
718 int wolenabled;
719 unsigned int phy_oui;
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400720 unsigned int phy_model;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 u16 gigabit;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400722 int intr_test;
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500723 int recover_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 /* General data: RO fields */
726 dma_addr_t ring_addr;
727 struct pci_dev *pci_dev;
728 u32 orig_mac[2];
729 u32 irqmask;
730 u32 desc_ver;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400731 u32 txrxctl_bits;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500732 u32 vlanctl_bits;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400733 u32 driver_data;
734 u32 register_size;
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -0400735 int rx_csum;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500736 u32 mac_in_use;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 void __iomem *base;
739
740 /* rx specific fields.
741 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
742 */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700743 union ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 unsigned int cur_rx, refill_rx;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400745 struct sk_buff **rx_skbuff;
746 dma_addr_t *rx_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200748 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 struct timer_list oom_kick;
750 struct timer_list nic_poll;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400751 struct timer_list stats_poll;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500752 u32 nic_poll_irq;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400753 int rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 /* media detection workaround.
756 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
757 */
758 int need_linktimer;
759 unsigned long link_timeout;
760 /*
761 * tx specific fields.
762 */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700763 union ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 unsigned int next_tx, nic_tx;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400765 struct sk_buff **tx_skbuff;
766 dma_addr_t *tx_dma;
767 unsigned int *tx_dma_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 u32 tx_flags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400769 int tx_ring_size;
770 int tx_limit_start;
771 int tx_limit_stop;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500772
773 /* vlan fields */
774 struct vlan_group *vlangrp;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500775
776 /* msi/msi-x fields */
777 u32 msi_flags;
778 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400779
780 /* flow control */
781 u32 pause_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782};
783
784/*
785 * Maximum number of loops until we assume that a bit in the irq mask
786 * is stuck. Overridable with module param.
787 */
788static int max_interrupt_work = 5;
789
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500790/*
791 * Optimization can be either throuput mode or cpu mode
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400792 *
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500793 * Throughput Mode: Every tx and rx packet will generate an interrupt.
794 * CPU Mode: Interrupts are controlled by a timer.
795 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400796enum {
797 NV_OPTIMIZATION_MODE_THROUGHPUT,
798 NV_OPTIMIZATION_MODE_CPU
799};
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500800static int optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
801
802/*
803 * Poll interval for timer irq
804 *
805 * This interval determines how frequent an interrupt is generated.
806 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
807 * Min = 0, and Max = 65535
808 */
809static int poll_interval = -1;
810
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500811/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400812 * MSI interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500813 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400814enum {
815 NV_MSI_INT_DISABLED,
816 NV_MSI_INT_ENABLED
817};
818static int msi = NV_MSI_INT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500819
820/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400821 * MSIX interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500822 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400823enum {
824 NV_MSIX_INT_DISABLED,
825 NV_MSIX_INT_ENABLED
826};
827static int msix = NV_MSIX_INT_ENABLED;
828
829/*
830 * DMA 64bit
831 */
832enum {
833 NV_DMA_64BIT_DISABLED,
834 NV_DMA_64BIT_ENABLED
835};
836static int dma_64bit = NV_DMA_64BIT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838static inline struct fe_priv *get_nvpriv(struct net_device *dev)
839{
840 return netdev_priv(dev);
841}
842
843static inline u8 __iomem *get_hwbase(struct net_device *dev)
844{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400845 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
848static inline void pci_push(u8 __iomem *base)
849{
850 /* force out pending posted writes */
851 readl(base);
852}
853
854static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
855{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700856 return le32_to_cpu(prd->flaglen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
858}
859
Manfred Spraulee733622005-07-31 18:32:26 +0200860static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
861{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700862 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
Manfred Spraulee733622005-07-31 18:32:26 +0200863}
864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
866 int delay, int delaymax, const char *msg)
867{
868 u8 __iomem *base = get_hwbase(dev);
869
870 pci_push(base);
871 do {
872 udelay(delay);
873 delaymax -= delay;
874 if (delaymax < 0) {
875 if (msg)
876 printk(msg);
877 return 1;
878 }
879 } while ((readl(base + offset) & mask) != target);
880 return 0;
881}
882
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500883#define NV_SETUP_RX_RING 0x01
884#define NV_SETUP_TX_RING 0x02
885
886static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
887{
888 struct fe_priv *np = get_nvpriv(dev);
889 u8 __iomem *base = get_hwbase(dev);
890
891 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
892 if (rxtx_flags & NV_SETUP_RX_RING) {
893 writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr);
894 }
895 if (rxtx_flags & NV_SETUP_TX_RING) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400896 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 -0500897 }
898 } else {
899 if (rxtx_flags & NV_SETUP_RX_RING) {
900 writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr);
901 writel((u32) (cpu_to_le64(np->ring_addr) >> 32), base + NvRegRxRingPhysAddrHigh);
902 }
903 if (rxtx_flags & NV_SETUP_TX_RING) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400904 writel((u32) cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
905 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 -0500906 }
907 }
908}
909
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400910static void free_rings(struct net_device *dev)
911{
912 struct fe_priv *np = get_nvpriv(dev);
913
914 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700915 if (np->rx_ring.orig)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400916 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
917 np->rx_ring.orig, np->ring_addr);
918 } else {
919 if (np->rx_ring.ex)
920 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
921 np->rx_ring.ex, np->ring_addr);
922 }
923 if (np->rx_skbuff)
924 kfree(np->rx_skbuff);
925 if (np->rx_dma)
926 kfree(np->rx_dma);
927 if (np->tx_skbuff)
928 kfree(np->tx_skbuff);
929 if (np->tx_dma)
930 kfree(np->tx_dma);
931 if (np->tx_dma_len)
932 kfree(np->tx_dma_len);
933}
934
Ayaz Abdulla84b39322006-05-20 14:59:48 -0700935static int using_multi_irqs(struct net_device *dev)
936{
937 struct fe_priv *np = get_nvpriv(dev);
938
939 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
940 ((np->msi_flags & NV_MSI_X_ENABLED) &&
941 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
942 return 0;
943 else
944 return 1;
945}
946
947static void nv_enable_irq(struct net_device *dev)
948{
949 struct fe_priv *np = get_nvpriv(dev);
950
951 if (!using_multi_irqs(dev)) {
952 if (np->msi_flags & NV_MSI_X_ENABLED)
953 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
954 else
955 enable_irq(dev->irq);
956 } else {
957 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
958 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
959 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
960 }
961}
962
963static void nv_disable_irq(struct net_device *dev)
964{
965 struct fe_priv *np = get_nvpriv(dev);
966
967 if (!using_multi_irqs(dev)) {
968 if (np->msi_flags & NV_MSI_X_ENABLED)
969 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
970 else
971 disable_irq(dev->irq);
972 } else {
973 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
974 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
975 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
976 }
977}
978
979/* In MSIX mode, a write to irqmask behaves as XOR */
980static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
981{
982 u8 __iomem *base = get_hwbase(dev);
983
984 writel(mask, base + NvRegIrqMask);
985}
986
987static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
988{
989 struct fe_priv *np = get_nvpriv(dev);
990 u8 __iomem *base = get_hwbase(dev);
991
992 if (np->msi_flags & NV_MSI_X_ENABLED) {
993 writel(mask, base + NvRegIrqMask);
994 } else {
995 if (np->msi_flags & NV_MSI_ENABLED)
996 writel(0, base + NvRegMSIIrqMask);
997 writel(0, base + NvRegIrqMask);
998 }
999}
1000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001#define MII_READ (-1)
1002/* mii_rw: read/write a register on the PHY.
1003 *
1004 * Caller must guarantee serialization
1005 */
1006static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1007{
1008 u8 __iomem *base = get_hwbase(dev);
1009 u32 reg;
1010 int retval;
1011
1012 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
1013
1014 reg = readl(base + NvRegMIIControl);
1015 if (reg & NVREG_MIICTL_INUSE) {
1016 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1017 udelay(NV_MIIBUSY_DELAY);
1018 }
1019
1020 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1021 if (value != MII_READ) {
1022 writel(value, base + NvRegMIIData);
1023 reg |= NVREG_MIICTL_WRITE;
1024 }
1025 writel(reg, base + NvRegMIIControl);
1026
1027 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
1028 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
1029 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n",
1030 dev->name, miireg, addr);
1031 retval = -1;
1032 } else if (value != MII_READ) {
1033 /* it was a write operation - fewer failures are detectable */
1034 dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
1035 dev->name, value, miireg, addr);
1036 retval = 0;
1037 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
1038 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n",
1039 dev->name, miireg, addr);
1040 retval = -1;
1041 } else {
1042 retval = readl(base + NvRegMIIData);
1043 dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
1044 dev->name, miireg, addr, retval);
1045 }
1046
1047 return retval;
1048}
1049
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001050static int phy_reset(struct net_device *dev, u32 bmcr_setup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001052 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 u32 miicontrol;
1054 unsigned int tries = 0;
1055
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001056 miicontrol = BMCR_RESET | bmcr_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) {
1058 return -1;
1059 }
1060
1061 /* wait for 500ms */
1062 msleep(500);
1063
1064 /* must wait till reset is deasserted */
1065 while (miicontrol & BMCR_RESET) {
1066 msleep(10);
1067 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1068 /* FIXME: 100 tries seem excessive */
1069 if (tries++ > 100)
1070 return -1;
1071 }
1072 return 0;
1073}
1074
1075static int phy_init(struct net_device *dev)
1076{
1077 struct fe_priv *np = get_nvpriv(dev);
1078 u8 __iomem *base = get_hwbase(dev);
1079 u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg;
1080
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001081 /* phy errata for E3016 phy */
1082 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1083 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1084 reg &= ~PHY_MARVELL_E3016_INITMASK;
1085 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
1086 printk(KERN_INFO "%s: phy write to errata reg failed.\n", pci_name(np->pci_dev));
1087 return PHY_ERROR;
1088 }
1089 }
1090
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 /* set advertise register */
1092 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001093 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|ADVERTISE_PAUSE_ASYM|ADVERTISE_PAUSE_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
1095 printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev));
1096 return PHY_ERROR;
1097 }
1098
1099 /* get phy interface type */
1100 phyinterface = readl(base + NvRegPhyInterface);
1101
1102 /* see if gigabit phy */
1103 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1104 if (mii_status & PHY_GIGABIT) {
1105 np->gigabit = PHY_GIGABIT;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001106 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 mii_control_1000 &= ~ADVERTISE_1000HALF;
1108 if (phyinterface & PHY_RGMII)
1109 mii_control_1000 |= ADVERTISE_1000FULL;
1110 else
1111 mii_control_1000 &= ~ADVERTISE_1000FULL;
1112
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001113 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1115 return PHY_ERROR;
1116 }
1117 }
1118 else
1119 np->gigabit = 0;
1120
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001121 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1122 mii_control |= BMCR_ANENABLE;
1123
1124 /* reset the phy
1125 * (certain phys need bmcr to be setup with reset)
1126 */
1127 if (phy_reset(dev, mii_control)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev));
1129 return PHY_ERROR;
1130 }
1131
1132 /* phy vendor specific configuration */
1133 if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) {
1134 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
1135 phy_reserved &= ~(PHY_INIT1 | PHY_INIT2);
1136 phy_reserved |= (PHY_INIT3 | PHY_INIT4);
1137 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) {
1138 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1139 return PHY_ERROR;
1140 }
1141 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1142 phy_reserved |= PHY_INIT5;
1143 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) {
1144 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1145 return PHY_ERROR;
1146 }
1147 }
1148 if (np->phy_oui == PHY_OUI_CICADA) {
1149 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
1150 phy_reserved |= PHY_INIT6;
1151 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) {
1152 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1153 return PHY_ERROR;
1154 }
1155 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001156 /* some phys clear out pause advertisment on reset, set it back */
1157 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
1159 /* restart auto negotiation */
1160 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1161 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
1162 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
1163 return PHY_ERROR;
1164 }
1165
1166 return 0;
1167}
1168
1169static void nv_start_rx(struct net_device *dev)
1170{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001171 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 u8 __iomem *base = get_hwbase(dev);
1173
1174 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
1175 /* Already running? Stop it. */
1176 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
1177 writel(0, base + NvRegReceiverControl);
1178 pci_push(base);
1179 }
1180 writel(np->linkspeed, base + NvRegLinkSpeed);
1181 pci_push(base);
1182 writel(NVREG_RCVCTL_START, base + NvRegReceiverControl);
1183 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
1184 dev->name, np->duplex, np->linkspeed);
1185 pci_push(base);
1186}
1187
1188static void nv_stop_rx(struct net_device *dev)
1189{
1190 u8 __iomem *base = get_hwbase(dev);
1191
1192 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
1193 writel(0, base + NvRegReceiverControl);
1194 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1195 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
1196 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
1197
1198 udelay(NV_RXSTOP_DELAY2);
1199 writel(0, base + NvRegLinkSpeed);
1200}
1201
1202static void nv_start_tx(struct net_device *dev)
1203{
1204 u8 __iomem *base = get_hwbase(dev);
1205
1206 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
1207 writel(NVREG_XMITCTL_START, base + NvRegTransmitterControl);
1208 pci_push(base);
1209}
1210
1211static void nv_stop_tx(struct net_device *dev)
1212{
1213 u8 __iomem *base = get_hwbase(dev);
1214
1215 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
1216 writel(0, base + NvRegTransmitterControl);
1217 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1218 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
1219 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
1220
1221 udelay(NV_TXSTOP_DELAY2);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04001222 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
1225static void nv_txrx_reset(struct net_device *dev)
1226{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001227 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 u8 __iomem *base = get_hwbase(dev);
1229
1230 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001231 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 pci_push(base);
1233 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001234 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 pci_push(base);
1236}
1237
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001238static void nv_mac_reset(struct net_device *dev)
1239{
1240 struct fe_priv *np = netdev_priv(dev);
1241 u8 __iomem *base = get_hwbase(dev);
1242
1243 dprintk(KERN_DEBUG "%s: nv_mac_reset\n", dev->name);
1244 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1245 pci_push(base);
1246 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1247 pci_push(base);
1248 udelay(NV_MAC_RESET_DELAY);
1249 writel(0, base + NvRegMacReset);
1250 pci_push(base);
1251 udelay(NV_MAC_RESET_DELAY);
1252 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1253 pci_push(base);
1254}
1255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256/*
1257 * nv_get_stats: dev->get_stats function
1258 * Get latest stats value from the nic.
1259 * Called with read_lock(&dev_base_lock) held for read -
1260 * only synchronized against unregister_netdevice.
1261 */
1262static struct net_device_stats *nv_get_stats(struct net_device *dev)
1263{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001264 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 /* It seems that the nic always generates interrupts and doesn't
1267 * accumulate errors internally. Thus the current values in np->stats
1268 * are already up to date.
1269 */
1270 return &np->stats;
1271}
1272
1273/*
1274 * nv_alloc_rx: fill rx ring entries.
1275 * Return 1 if the allocations for the skbs failed and the
1276 * rx engine is without Available descriptors
1277 */
1278static int nv_alloc_rx(struct net_device *dev)
1279{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001280 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 unsigned int refill_rx = np->refill_rx;
1282 int nr;
1283
1284 while (np->cur_rx != refill_rx) {
1285 struct sk_buff *skb;
1286
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001287 nr = refill_rx % np->rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 if (np->rx_skbuff[nr] == NULL) {
1289
Manfred Sprauld81c0982005-07-31 18:20:30 +02001290 skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 if (!skb)
1292 break;
1293
1294 skb->dev = dev;
1295 np->rx_skbuff[nr] = skb;
1296 } else {
1297 skb = np->rx_skbuff[nr];
1298 }
Manfred Spraul18360982005-12-24 14:19:24 +01001299 np->rx_dma[nr] = pci_map_single(np->pci_dev, skb->data,
1300 skb->end-skb->data, PCI_DMA_FROMDEVICE);
Manfred Spraulee733622005-07-31 18:32:26 +02001301 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001302 np->rx_ring.orig[nr].buf = cpu_to_le32(np->rx_dma[nr]);
Manfred Spraulee733622005-07-31 18:32:26 +02001303 wmb();
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001304 np->rx_ring.orig[nr].flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
Manfred Spraulee733622005-07-31 18:32:26 +02001305 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001306 np->rx_ring.ex[nr].bufhigh = cpu_to_le64(np->rx_dma[nr]) >> 32;
1307 np->rx_ring.ex[nr].buflow = cpu_to_le64(np->rx_dma[nr]) & 0x0FFFFFFFF;
Manfred Spraulee733622005-07-31 18:32:26 +02001308 wmb();
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001309 np->rx_ring.ex[nr].flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
Manfred Spraulee733622005-07-31 18:32:26 +02001310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 dprintk(KERN_DEBUG "%s: nv_alloc_rx: Packet %d marked as Available\n",
1312 dev->name, refill_rx);
1313 refill_rx++;
1314 }
1315 np->refill_rx = refill_rx;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001316 if (np->cur_rx - refill_rx == np->rx_ring_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 return 1;
1318 return 0;
1319}
1320
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001321/* If rx bufs are exhausted called after 50ms to attempt to refresh */
1322#ifdef CONFIG_FORCEDETH_NAPI
1323static void nv_do_rx_refill(unsigned long data)
1324{
1325 struct net_device *dev = (struct net_device *) data;
1326
1327 /* Just reschedule NAPI rx processing */
1328 netif_rx_schedule(dev);
1329}
1330#else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331static void nv_do_rx_refill(unsigned long data)
1332{
1333 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001334 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001336 if (!using_multi_irqs(dev)) {
1337 if (np->msi_flags & NV_MSI_X_ENABLED)
1338 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1339 else
1340 disable_irq(dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001341 } else {
1342 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 if (nv_alloc_rx(dev)) {
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001345 spin_lock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 if (!np->in_shutdown)
1347 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001348 spin_unlock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001350 if (!using_multi_irqs(dev)) {
1351 if (np->msi_flags & NV_MSI_X_ENABLED)
1352 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1353 else
1354 enable_irq(dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001355 } else {
1356 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001359#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001361static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001362{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001363 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001364 int i;
1365
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001366 np->cur_rx = np->rx_ring_size;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001367 np->refill_rx = 0;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001368 for (i = 0; i < np->rx_ring_size; i++)
Manfred Spraulee733622005-07-31 18:32:26 +02001369 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001370 np->rx_ring.orig[i].flaglen = 0;
Manfred Spraulee733622005-07-31 18:32:26 +02001371 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001372 np->rx_ring.ex[i].flaglen = 0;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001373}
1374
1375static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001377 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 int i;
1379
1380 np->next_tx = np->nic_tx = 0;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001381 for (i = 0; i < np->tx_ring_size; i++) {
Manfred Spraulee733622005-07-31 18:32:26 +02001382 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001383 np->tx_ring.orig[i].flaglen = 0;
Manfred Spraulee733622005-07-31 18:32:26 +02001384 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001385 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001386 np->tx_skbuff[i] = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001387 np->tx_dma[i] = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001388 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001389}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Manfred Sprauld81c0982005-07-31 18:20:30 +02001391static int nv_init_ring(struct net_device *dev)
1392{
1393 nv_init_tx(dev);
1394 nv_init_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 return nv_alloc_rx(dev);
1396}
1397
Ayaz Abdullafa454592006-01-05 22:45:45 -08001398static int nv_release_txskb(struct net_device *dev, unsigned int skbnr)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001399{
1400 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001401
1402 dprintk(KERN_INFO "%s: nv_release_txskb for skbnr %d\n",
1403 dev->name, skbnr);
1404
1405 if (np->tx_dma[skbnr]) {
1406 pci_unmap_page(np->pci_dev, np->tx_dma[skbnr],
1407 np->tx_dma_len[skbnr],
1408 PCI_DMA_TODEVICE);
1409 np->tx_dma[skbnr] = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001410 }
Ayaz Abdullafa454592006-01-05 22:45:45 -08001411
1412 if (np->tx_skbuff[skbnr]) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001413 dev_kfree_skb_any(np->tx_skbuff[skbnr]);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001414 np->tx_skbuff[skbnr] = NULL;
1415 return 1;
1416 } else {
1417 return 0;
1418 }
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001419}
1420
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421static void nv_drain_tx(struct net_device *dev)
1422{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001423 struct fe_priv *np = netdev_priv(dev);
1424 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001425
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001426 for (i = 0; i < np->tx_ring_size; i++) {
Manfred Spraulee733622005-07-31 18:32:26 +02001427 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001428 np->tx_ring.orig[i].flaglen = 0;
Manfred Spraulee733622005-07-31 18:32:26 +02001429 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001430 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001431 if (nv_release_txskb(dev, i))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 np->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 }
1434}
1435
1436static void nv_drain_rx(struct net_device *dev)
1437{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001438 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 int i;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001440 for (i = 0; i < np->rx_ring_size; i++) {
Manfred Spraulee733622005-07-31 18:32:26 +02001441 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001442 np->rx_ring.orig[i].flaglen = 0;
Manfred Spraulee733622005-07-31 18:32:26 +02001443 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001444 np->rx_ring.ex[i].flaglen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 wmb();
1446 if (np->rx_skbuff[i]) {
1447 pci_unmap_single(np->pci_dev, np->rx_dma[i],
Manfred Spraul18360982005-12-24 14:19:24 +01001448 np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 PCI_DMA_FROMDEVICE);
1450 dev_kfree_skb(np->rx_skbuff[i]);
1451 np->rx_skbuff[i] = NULL;
1452 }
1453 }
1454}
1455
1456static void drain_ring(struct net_device *dev)
1457{
1458 nv_drain_tx(dev);
1459 nv_drain_rx(dev);
1460}
1461
1462/*
1463 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07001464 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 */
1466static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1467{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001468 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001469 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001470 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
1471 unsigned int fragments = skb_shinfo(skb)->nr_frags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001472 unsigned int nr = (np->next_tx - 1) % np->tx_ring_size;
1473 unsigned int start_nr = np->next_tx % np->tx_ring_size;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001474 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001475 u32 offset = 0;
1476 u32 bcnt;
1477 u32 size = skb->len-skb->data_len;
1478 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001479 u32 tx_flags_vlan = 0;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001480
1481 /* add fragments to entries count */
1482 for (i = 0; i < fragments; i++) {
1483 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1484 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
1487 spin_lock_irq(&np->lock);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001488
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001489 if ((np->next_tx - np->nic_tx + entries - 1) > np->tx_limit_stop) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001490 spin_unlock_irq(&np->lock);
1491 netif_stop_queue(dev);
1492 return NETDEV_TX_BUSY;
1493 }
1494
Ayaz Abdullafa454592006-01-05 22:45:45 -08001495 /* setup the header buffer */
1496 do {
1497 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001498 nr = (nr + 1) % np->tx_ring_size;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001499
1500 np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
1501 PCI_DMA_TODEVICE);
1502 np->tx_dma_len[nr] = bcnt;
1503
1504 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001505 np->tx_ring.orig[nr].buf = cpu_to_le32(np->tx_dma[nr]);
1506 np->tx_ring.orig[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001507 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001508 np->tx_ring.ex[nr].bufhigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1509 np->tx_ring.ex[nr].buflow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1510 np->tx_ring.ex[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001511 }
1512 tx_flags = np->tx_flags;
1513 offset += bcnt;
1514 size -= bcnt;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001515 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001516
1517 /* setup the fragments */
1518 for (i = 0; i < fragments; i++) {
1519 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1520 u32 size = frag->size;
1521 offset = 0;
1522
1523 do {
1524 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001525 nr = (nr + 1) % np->tx_ring_size;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001526
1527 np->tx_dma[nr] = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
1528 PCI_DMA_TODEVICE);
1529 np->tx_dma_len[nr] = bcnt;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001530
1531 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001532 np->tx_ring.orig[nr].buf = cpu_to_le32(np->tx_dma[nr]);
1533 np->tx_ring.orig[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001534 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001535 np->tx_ring.ex[nr].bufhigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1536 np->tx_ring.ex[nr].buflow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1537 np->tx_ring.ex[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001538 }
Ayaz Abdullafa454592006-01-05 22:45:45 -08001539 offset += bcnt;
1540 size -= bcnt;
1541 } while (size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001542 }
1543
Ayaz Abdullafa454592006-01-05 22:45:45 -08001544 /* set last fragment flag */
1545 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001546 np->tx_ring.orig[nr].flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001547 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001548 np->tx_ring.ex[nr].flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001549 }
1550
1551 np->tx_skbuff[nr] = skb;
1552
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001553#ifdef NETIF_F_TSO
Herbert Xu89114af2006-07-08 13:34:32 -07001554 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07001555 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02001556 else
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001557#endif
Patrick McHardy84fa7932006-08-29 16:44:56 -07001558 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
1559 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001560
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001561 /* vlan tag */
1562 if (np->vlangrp && vlan_tx_tag_present(skb)) {
1563 tx_flags_vlan = NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb);
1564 }
1565
Ayaz Abdullafa454592006-01-05 22:45:45 -08001566 /* set tx flags */
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001567 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001568 np->tx_ring.orig[start_nr].flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001569 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001570 np->tx_ring.ex[start_nr].txvlan = cpu_to_le32(tx_flags_vlan);
1571 np->tx_ring.ex[start_nr].flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001572 }
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001573
Ayaz Abdullafa454592006-01-05 22:45:45 -08001574 dprintk(KERN_DEBUG "%s: nv_start_xmit: packet %d (entries %d) queued for transmission. tx_flags_extra: %x\n",
1575 dev->name, np->next_tx, entries, tx_flags_extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 {
1577 int j;
1578 for (j=0; j<64; j++) {
1579 if ((j%16) == 0)
1580 dprintk("\n%03x:", j);
1581 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
1582 }
1583 dprintk("\n");
1584 }
1585
Ayaz Abdullafa454592006-01-05 22:45:45 -08001586 np->next_tx += entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
1588 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 spin_unlock_irq(&np->lock);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001590 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 pci_push(get_hwbase(dev));
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001592 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593}
1594
1595/*
1596 * nv_tx_done: check for completed packets, release the skbs.
1597 *
1598 * Caller must own np->lock.
1599 */
1600static void nv_tx_done(struct net_device *dev)
1601{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001602 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001603 u32 flags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001604 unsigned int i;
1605 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
1607 while (np->nic_tx != np->next_tx) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001608 i = np->nic_tx % np->tx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
Manfred Spraulee733622005-07-31 18:32:26 +02001610 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001611 flags = le32_to_cpu(np->tx_ring.orig[i].flaglen);
Manfred Spraulee733622005-07-31 18:32:26 +02001612 else
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001613 flags = le32_to_cpu(np->tx_ring.ex[i].flaglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001615 dprintk(KERN_DEBUG "%s: nv_tx_done: looking at packet %d, flags 0x%x.\n",
1616 dev->name, np->nic_tx, flags);
1617 if (flags & NV_TX_VALID)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 break;
1619 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001620 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001621 skb = np->tx_skbuff[i];
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001622 if (flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION|
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001623 NV_TX_UNDERFLOW|NV_TX_ERROR)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001624 if (flags & NV_TX_UNDERFLOW)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001625 np->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001626 if (flags & NV_TX_CARRIERLOST)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001627 np->stats.tx_carrier_errors++;
1628 np->stats.tx_errors++;
1629 } else {
1630 np->stats.tx_packets++;
1631 np->stats.tx_bytes += skb->len;
1632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 }
1634 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001635 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001636 skb = np->tx_skbuff[i];
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001637 if (flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION|
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001638 NV_TX2_UNDERFLOW|NV_TX2_ERROR)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001639 if (flags & NV_TX2_UNDERFLOW)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001640 np->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001641 if (flags & NV_TX2_CARRIERLOST)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001642 np->stats.tx_carrier_errors++;
1643 np->stats.tx_errors++;
1644 } else {
1645 np->stats.tx_packets++;
1646 np->stats.tx_bytes += skb->len;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 }
1649 }
Ayaz Abdullafa454592006-01-05 22:45:45 -08001650 nv_release_txskb(dev, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 np->nic_tx++;
1652 }
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001653 if (np->next_tx - np->nic_tx < np->tx_limit_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 netif_wake_queue(dev);
1655}
1656
1657/*
1658 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07001659 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 */
1661static void nv_tx_timeout(struct net_device *dev)
1662{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001663 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001665 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001667 if (np->msi_flags & NV_MSI_X_ENABLED)
1668 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
1669 else
1670 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
1671
1672 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Manfred Spraulc2dba062005-07-31 18:29:47 +02001674 {
1675 int i;
1676
1677 printk(KERN_INFO "%s: Ring at %lx: next %d nic %d\n",
1678 dev->name, (unsigned long)np->ring_addr,
1679 np->next_tx, np->nic_tx);
1680 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001681 for (i=0;i<=np->register_size;i+= 32) {
Manfred Spraulc2dba062005-07-31 18:29:47 +02001682 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
1683 i,
1684 readl(base + i + 0), readl(base + i + 4),
1685 readl(base + i + 8), readl(base + i + 12),
1686 readl(base + i + 16), readl(base + i + 20),
1687 readl(base + i + 24), readl(base + i + 28));
1688 }
1689 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001690 for (i=0;i<np->tx_ring_size;i+= 4) {
Manfred Spraulee733622005-07-31 18:32:26 +02001691 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1692 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001693 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001694 le32_to_cpu(np->tx_ring.orig[i].buf),
1695 le32_to_cpu(np->tx_ring.orig[i].flaglen),
1696 le32_to_cpu(np->tx_ring.orig[i+1].buf),
1697 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
1698 le32_to_cpu(np->tx_ring.orig[i+2].buf),
1699 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
1700 le32_to_cpu(np->tx_ring.orig[i+3].buf),
1701 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02001702 } else {
1703 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001704 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001705 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
1706 le32_to_cpu(np->tx_ring.ex[i].buflow),
1707 le32_to_cpu(np->tx_ring.ex[i].flaglen),
1708 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
1709 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
1710 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
1711 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
1712 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
1713 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
1714 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
1715 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
1716 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02001717 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02001718 }
1719 }
1720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 spin_lock_irq(&np->lock);
1722
1723 /* 1) stop tx engine */
1724 nv_stop_tx(dev);
1725
1726 /* 2) check that the packets were not sent already: */
1727 nv_tx_done(dev);
1728
1729 /* 3) if there are dead entries: clear everything */
1730 if (np->next_tx != np->nic_tx) {
1731 printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name);
1732 nv_drain_tx(dev);
1733 np->next_tx = np->nic_tx = 0;
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001734 setup_hw_rings(dev, NV_SETUP_TX_RING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 netif_wake_queue(dev);
1736 }
1737
1738 /* 4) restart tx engine */
1739 nv_start_tx(dev);
1740 spin_unlock_irq(&np->lock);
1741}
1742
Manfred Spraul22c6d142005-04-19 21:17:09 +02001743/*
1744 * Called when the nic notices a mismatch between the actual data len on the
1745 * wire and the len indicated in the 802 header
1746 */
1747static int nv_getlen(struct net_device *dev, void *packet, int datalen)
1748{
1749 int hdrlen; /* length of the 802 header */
1750 int protolen; /* length as stored in the proto field */
1751
1752 /* 1) calculate len according to header */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001753 if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
Manfred Spraul22c6d142005-04-19 21:17:09 +02001754 protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto );
1755 hdrlen = VLAN_HLEN;
1756 } else {
1757 protolen = ntohs( ((struct ethhdr *)packet)->h_proto);
1758 hdrlen = ETH_HLEN;
1759 }
1760 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
1761 dev->name, datalen, protolen, hdrlen);
1762 if (protolen > ETH_DATA_LEN)
1763 return datalen; /* Value in proto field not a len, no checks possible */
1764
1765 protolen += hdrlen;
1766 /* consistency checks: */
1767 if (datalen > ETH_ZLEN) {
1768 if (datalen >= protolen) {
1769 /* more data on wire than in 802 header, trim of
1770 * additional data.
1771 */
1772 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1773 dev->name, protolen);
1774 return protolen;
1775 } else {
1776 /* less data on wire than mentioned in header.
1777 * Discard the packet.
1778 */
1779 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
1780 dev->name);
1781 return -1;
1782 }
1783 } else {
1784 /* short packet. Accept only if 802 values are also short */
1785 if (protolen > ETH_ZLEN) {
1786 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
1787 dev->name);
1788 return -1;
1789 }
1790 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1791 dev->name, datalen);
1792 return datalen;
1793 }
1794}
1795
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001796static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001798 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001799 u32 flags;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001800 u32 vlanflags = 0;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001801 int count;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001802
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001803 for (count = 0; count < limit; ++count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 struct sk_buff *skb;
1805 int len;
1806 int i;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001807 if (np->cur_rx - np->refill_rx >= np->rx_ring_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 break; /* we scanned the whole ring - do not continue */
1809
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001810 i = np->cur_rx % np->rx_ring_size;
Manfred Spraulee733622005-07-31 18:32:26 +02001811 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001812 flags = le32_to_cpu(np->rx_ring.orig[i].flaglen);
Manfred Spraulee733622005-07-31 18:32:26 +02001813 len = nv_descr_getlength(&np->rx_ring.orig[i], np->desc_ver);
1814 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001815 flags = le32_to_cpu(np->rx_ring.ex[i].flaglen);
Manfred Spraulee733622005-07-31 18:32:26 +02001816 len = nv_descr_getlength_ex(&np->rx_ring.ex[i], np->desc_ver);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001817 vlanflags = le32_to_cpu(np->rx_ring.ex[i].buflow);
Manfred Spraulee733622005-07-31 18:32:26 +02001818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001820 dprintk(KERN_DEBUG "%s: nv_rx_process: looking at packet %d, flags 0x%x.\n",
1821 dev->name, np->cur_rx, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001823 if (flags & NV_RX_AVAIL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 break; /* still owned by hardware, */
1825
1826 /*
1827 * the packet is for us - immediately tear down the pci mapping.
1828 * TODO: check if a prefetch of the first cacheline improves
1829 * the performance.
1830 */
1831 pci_unmap_single(np->pci_dev, np->rx_dma[i],
Manfred Spraul18360982005-12-24 14:19:24 +01001832 np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 PCI_DMA_FROMDEVICE);
1834
1835 {
1836 int j;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001837 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 for (j=0; j<64; j++) {
1839 if ((j%16) == 0)
1840 dprintk("\n%03x:", j);
1841 dprintk(" %02x", ((unsigned char*)np->rx_skbuff[i]->data)[j]);
1842 }
1843 dprintk("\n");
1844 }
1845 /* look at what we actually got: */
1846 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001847 if (!(flags & NV_RX_DESCRIPTORVALID))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 goto next_pkt;
1849
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001850 if (flags & NV_RX_ERROR) {
1851 if (flags & NV_RX_MISSEDFRAME) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001852 np->stats.rx_missed_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 np->stats.rx_errors++;
1854 goto next_pkt;
1855 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001856 if (flags & (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3)) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001857 np->stats.rx_errors++;
1858 goto next_pkt;
1859 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001860 if (flags & NV_RX_CRCERR) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001861 np->stats.rx_crc_errors++;
1862 np->stats.rx_errors++;
1863 goto next_pkt;
1864 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001865 if (flags & NV_RX_OVERFLOW) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001866 np->stats.rx_over_errors++;
1867 np->stats.rx_errors++;
1868 goto next_pkt;
1869 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001870 if (flags & NV_RX_ERROR4) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001871 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1872 if (len < 0) {
1873 np->stats.rx_errors++;
1874 goto next_pkt;
1875 }
1876 }
1877 /* framing errors are soft errors. */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001878 if (flags & NV_RX_FRAMINGERR) {
1879 if (flags & NV_RX_SUBSTRACT1) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001880 len--;
1881 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02001882 }
1883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001885 if (!(flags & NV_RX2_DESCRIPTORVALID))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 goto next_pkt;
1887
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001888 if (flags & NV_RX2_ERROR) {
1889 if (flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 np->stats.rx_errors++;
1891 goto next_pkt;
1892 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001893 if (flags & NV_RX2_CRCERR) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001894 np->stats.rx_crc_errors++;
1895 np->stats.rx_errors++;
1896 goto next_pkt;
1897 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001898 if (flags & NV_RX2_OVERFLOW) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001899 np->stats.rx_over_errors++;
1900 np->stats.rx_errors++;
1901 goto next_pkt;
1902 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001903 if (flags & NV_RX2_ERROR4) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001904 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1905 if (len < 0) {
1906 np->stats.rx_errors++;
1907 goto next_pkt;
1908 }
1909 }
1910 /* framing errors are soft errors */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001911 if (flags & NV_RX2_FRAMINGERR) {
1912 if (flags & NV_RX2_SUBSTRACT1) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001913 len--;
1914 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02001915 }
1916 }
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04001917 if (np->rx_csum) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001918 flags &= NV_RX2_CHECKSUMMASK;
1919 if (flags == NV_RX2_CHECKSUMOK1 ||
1920 flags == NV_RX2_CHECKSUMOK2 ||
1921 flags == NV_RX2_CHECKSUMOK3) {
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04001922 dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name);
1923 np->rx_skbuff[i]->ip_summed = CHECKSUM_UNNECESSARY;
1924 } else {
1925 dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name);
1926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 }
1928 }
1929 /* got a valid packet - forward it to the network core */
1930 skb = np->rx_skbuff[i];
1931 np->rx_skbuff[i] = NULL;
1932
1933 skb_put(skb, len);
1934 skb->protocol = eth_type_trans(skb, dev);
1935 dprintk(KERN_DEBUG "%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n",
1936 dev->name, np->cur_rx, len, skb->protocol);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001937#ifdef CONFIG_FORCEDETH_NAPI
1938 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
1939 vlan_hwaccel_receive_skb(skb, np->vlangrp,
1940 vlanflags & NV_RX3_VLAN_TAG_MASK);
1941 else
1942 netif_receive_skb(skb);
1943#else
1944 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
1945 vlan_hwaccel_rx(skb, np->vlangrp,
1946 vlanflags & NV_RX3_VLAN_TAG_MASK);
1947 else
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001948 netif_rx(skb);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001949#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 dev->last_rx = jiffies;
1951 np->stats.rx_packets++;
1952 np->stats.rx_bytes += len;
1953next_pkt:
1954 np->cur_rx++;
1955 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001956
1957 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958}
1959
Manfred Sprauld81c0982005-07-31 18:20:30 +02001960static void set_bufsize(struct net_device *dev)
1961{
1962 struct fe_priv *np = netdev_priv(dev);
1963
1964 if (dev->mtu <= ETH_DATA_LEN)
1965 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
1966 else
1967 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
1968}
1969
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970/*
1971 * nv_change_mtu: dev->change_mtu function
1972 * Called with dev_base_lock held for read.
1973 */
1974static int nv_change_mtu(struct net_device *dev, int new_mtu)
1975{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001976 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001977 int old_mtu;
1978
1979 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001981
1982 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001984
1985 /* return early if the buffer sizes will not change */
1986 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
1987 return 0;
1988 if (old_mtu == new_mtu)
1989 return 0;
1990
1991 /* synchronized against open : rtnl_lock() held by caller */
1992 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01001993 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001994 /*
1995 * It seems that the nic preloads valid ring entries into an
1996 * internal buffer. The procedure for flushing everything is
1997 * guessed, there is probably a simpler approach.
1998 * Changing the MTU is a rare event, it shouldn't matter.
1999 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002000 nv_disable_irq(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002001 netif_tx_lock_bh(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002002 spin_lock(&np->lock);
2003 /* stop engines */
2004 nv_stop_rx(dev);
2005 nv_stop_tx(dev);
2006 nv_txrx_reset(dev);
2007 /* drain rx queue */
2008 nv_drain_rx(dev);
2009 nv_drain_tx(dev);
2010 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002011 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002012 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02002013 if (!np->in_shutdown)
2014 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2015 }
2016 /* reinit nic view of the rx queue */
2017 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002018 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002019 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02002020 base + NvRegRingSizes);
2021 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002022 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002023 pci_push(base);
2024
2025 /* restart rx engine */
2026 nv_start_rx(dev);
2027 nv_start_tx(dev);
2028 spin_unlock(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002029 netif_tx_unlock_bh(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002030 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002031 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 return 0;
2033}
2034
Manfred Spraul72b31782005-07-31 18:33:34 +02002035static void nv_copy_mac_to_hw(struct net_device *dev)
2036{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002037 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002038 u32 mac[2];
2039
2040 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
2041 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
2042 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
2043
2044 writel(mac[0], base + NvRegMacAddrA);
2045 writel(mac[1], base + NvRegMacAddrB);
2046}
2047
2048/*
2049 * nv_set_mac_address: dev->set_mac_address function
2050 * Called with rtnl_lock() held.
2051 */
2052static int nv_set_mac_address(struct net_device *dev, void *addr)
2053{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002054 struct fe_priv *np = netdev_priv(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002055 struct sockaddr *macaddr = (struct sockaddr*)addr;
2056
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002057 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02002058 return -EADDRNOTAVAIL;
2059
2060 /* synchronized against open : rtnl_lock() held by caller */
2061 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
2062
2063 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07002064 netif_tx_lock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002065 spin_lock_irq(&np->lock);
2066
2067 /* stop rx engine */
2068 nv_stop_rx(dev);
2069
2070 /* set mac address */
2071 nv_copy_mac_to_hw(dev);
2072
2073 /* restart rx engine */
2074 nv_start_rx(dev);
2075 spin_unlock_irq(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002076 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002077 } else {
2078 nv_copy_mac_to_hw(dev);
2079 }
2080 return 0;
2081}
2082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083/*
2084 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07002085 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 */
2087static void nv_set_multicast(struct net_device *dev)
2088{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002089 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 u8 __iomem *base = get_hwbase(dev);
2091 u32 addr[2];
2092 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002093 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
2095 memset(addr, 0, sizeof(addr));
2096 memset(mask, 0, sizeof(mask));
2097
2098 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002099 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002101 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
2103 if (dev->flags & IFF_ALLMULTI || dev->mc_list) {
2104 u32 alwaysOff[2];
2105 u32 alwaysOn[2];
2106
2107 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
2108 if (dev->flags & IFF_ALLMULTI) {
2109 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
2110 } else {
2111 struct dev_mc_list *walk;
2112
2113 walk = dev->mc_list;
2114 while (walk != NULL) {
2115 u32 a, b;
2116 a = le32_to_cpu(*(u32 *) walk->dmi_addr);
2117 b = le16_to_cpu(*(u16 *) (&walk->dmi_addr[4]));
2118 alwaysOn[0] &= a;
2119 alwaysOff[0] &= ~a;
2120 alwaysOn[1] &= b;
2121 alwaysOff[1] &= ~b;
2122 walk = walk->next;
2123 }
2124 }
2125 addr[0] = alwaysOn[0];
2126 addr[1] = alwaysOn[1];
2127 mask[0] = alwaysOn[0] | alwaysOff[0];
2128 mask[1] = alwaysOn[1] | alwaysOff[1];
2129 }
2130 }
2131 addr[0] |= NVREG_MCASTADDRA_FORCE;
2132 pff |= NVREG_PFF_ALWAYS;
2133 spin_lock_irq(&np->lock);
2134 nv_stop_rx(dev);
2135 writel(addr[0], base + NvRegMulticastAddrA);
2136 writel(addr[1], base + NvRegMulticastAddrB);
2137 writel(mask[0], base + NvRegMulticastMaskA);
2138 writel(mask[1], base + NvRegMulticastMaskB);
2139 writel(pff, base + NvRegPacketFilterFlags);
2140 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
2141 dev->name);
2142 nv_start_rx(dev);
2143 spin_unlock_irq(&np->lock);
2144}
2145
Adrian Bunkc7985052006-06-22 12:03:29 +02002146static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002147{
2148 struct fe_priv *np = netdev_priv(dev);
2149 u8 __iomem *base = get_hwbase(dev);
2150
2151 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
2152
2153 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
2154 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
2155 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
2156 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
2157 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2158 } else {
2159 writel(pff, base + NvRegPacketFilterFlags);
2160 }
2161 }
2162 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
2163 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
2164 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
2165 writel(NVREG_TX_PAUSEFRAME_ENABLE, base + NvRegTxPauseFrame);
2166 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
2167 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2168 } else {
2169 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
2170 writel(regmisc, base + NvRegMisc1);
2171 }
2172 }
2173}
2174
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002175/**
2176 * nv_update_linkspeed: Setup the MAC according to the link partner
2177 * @dev: Network device to be configured
2178 *
2179 * The function queries the PHY and checks if there is a link partner.
2180 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
2181 * set to 10 MBit HD.
2182 *
2183 * The function returns 0 if there is no link partner and 1 if there is
2184 * a good link partner.
2185 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186static int nv_update_linkspeed(struct net_device *dev)
2187{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002188 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002190 int adv = 0;
2191 int lpa = 0;
2192 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 int newls = np->linkspeed;
2194 int newdup = np->duplex;
2195 int mii_status;
2196 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002197 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
2199 /* BMSR_LSTATUS is latched, read it twice:
2200 * we want the current value.
2201 */
2202 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2203 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2204
2205 if (!(mii_status & BMSR_LSTATUS)) {
2206 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
2207 dev->name);
2208 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2209 newdup = 0;
2210 retval = 0;
2211 goto set_speed;
2212 }
2213
2214 if (np->autoneg == 0) {
2215 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
2216 dev->name, np->fixed_mode);
2217 if (np->fixed_mode & LPA_100FULL) {
2218 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2219 newdup = 1;
2220 } else if (np->fixed_mode & LPA_100HALF) {
2221 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2222 newdup = 0;
2223 } else if (np->fixed_mode & LPA_10FULL) {
2224 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2225 newdup = 1;
2226 } else {
2227 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2228 newdup = 0;
2229 }
2230 retval = 1;
2231 goto set_speed;
2232 }
2233 /* check auto negotiation is complete */
2234 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
2235 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
2236 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2237 newdup = 0;
2238 retval = 0;
2239 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
2240 goto set_speed;
2241 }
2242
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002243 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2244 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
2245 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
2246 dev->name, adv, lpa);
2247
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 retval = 1;
2249 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002250 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
2251 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
2253 if ((control_1000 & ADVERTISE_1000FULL) &&
2254 (status_1000 & LPA_1000FULL)) {
2255 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
2256 dev->name);
2257 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
2258 newdup = 1;
2259 goto set_speed;
2260 }
2261 }
2262
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002264 adv_lpa = lpa & adv;
2265 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2267 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002268 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2270 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002271 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2273 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002274 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2276 newdup = 0;
2277 } else {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002278 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, adv_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2280 newdup = 0;
2281 }
2282
2283set_speed:
2284 if (np->duplex == newdup && np->linkspeed == newls)
2285 return retval;
2286
2287 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
2288 dev->name, np->linkspeed, np->duplex, newls, newdup);
2289
2290 np->duplex = newdup;
2291 np->linkspeed = newls;
2292
2293 if (np->gigabit == PHY_GIGABIT) {
2294 phyreg = readl(base + NvRegRandomSeed);
2295 phyreg &= ~(0x3FF00);
2296 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
2297 phyreg |= NVREG_RNDSEED_FORCE3;
2298 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
2299 phyreg |= NVREG_RNDSEED_FORCE2;
2300 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
2301 phyreg |= NVREG_RNDSEED_FORCE;
2302 writel(phyreg, base + NvRegRandomSeed);
2303 }
2304
2305 phyreg = readl(base + NvRegPhyInterface);
2306 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
2307 if (np->duplex == 0)
2308 phyreg |= PHY_HALF;
2309 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
2310 phyreg |= PHY_100;
2311 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2312 phyreg |= PHY_1000;
2313 writel(phyreg, base + NvRegPhyInterface);
2314
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002315 if (phyreg & PHY_RGMII) {
2316 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2317 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
2318 else
2319 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
2320 } else {
2321 txreg = NVREG_TX_DEFERRAL_DEFAULT;
2322 }
2323 writel(txreg, base + NvRegTxDeferral);
2324
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04002325 if (np->desc_ver == DESC_VER_1) {
2326 txreg = NVREG_TX_WM_DESC1_DEFAULT;
2327 } else {
2328 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2329 txreg = NVREG_TX_WM_DESC2_3_1000;
2330 else
2331 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
2332 }
2333 writel(txreg, base + NvRegTxWatermark);
2334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
2336 base + NvRegMisc1);
2337 pci_push(base);
2338 writel(np->linkspeed, base + NvRegLinkSpeed);
2339 pci_push(base);
2340
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002341 pause_flags = 0;
2342 /* setup pause frame */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002343 if (np->duplex != 0) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002344 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
2345 adv_pause = adv & (ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM);
2346 lpa_pause = lpa & (LPA_PAUSE_CAP| LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002347
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002348 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002349 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002350 if (lpa_pause & LPA_PAUSE_CAP) {
2351 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2352 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2353 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2354 }
2355 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002356 case ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002357 if (lpa_pause == (LPA_PAUSE_CAP| LPA_PAUSE_ASYM))
2358 {
2359 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2360 }
2361 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002362 case ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002363 if (lpa_pause & LPA_PAUSE_CAP)
2364 {
2365 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2366 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2367 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2368 }
2369 if (lpa_pause == LPA_PAUSE_ASYM)
2370 {
2371 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2372 }
2373 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002374 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002375 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002376 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002377 }
2378 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002379 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002380
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 return retval;
2382}
2383
2384static void nv_linkchange(struct net_device *dev)
2385{
2386 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002387 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 netif_carrier_on(dev);
2389 printk(KERN_INFO "%s: link up.\n", dev->name);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002390 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 } else {
2393 if (netif_carrier_ok(dev)) {
2394 netif_carrier_off(dev);
2395 printk(KERN_INFO "%s: link down.\n", dev->name);
2396 nv_stop_rx(dev);
2397 }
2398 }
2399}
2400
2401static void nv_link_irq(struct net_device *dev)
2402{
2403 u8 __iomem *base = get_hwbase(dev);
2404 u32 miistat;
2405
2406 miistat = readl(base + NvRegMIIStatus);
2407 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
2408 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
2409
2410 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
2411 nv_linkchange(dev);
2412 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
2413}
2414
David Howells7d12e782006-10-05 14:55:46 +01002415static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416{
2417 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002418 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 u8 __iomem *base = get_hwbase(dev);
2420 u32 events;
2421 int i;
2422
2423 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
2424
2425 for (i=0; ; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002426 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
2427 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2428 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2429 } else {
2430 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2431 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
2432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 pci_push(base);
2434 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2435 if (!(events & np->irqmask))
2436 break;
2437
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002438 spin_lock(&np->lock);
2439 nv_tx_done(dev);
2440 spin_unlock(&np->lock);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 if (events & NVREG_IRQ_LINK) {
2443 spin_lock(&np->lock);
2444 nv_link_irq(dev);
2445 spin_unlock(&np->lock);
2446 }
2447 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
2448 spin_lock(&np->lock);
2449 nv_linkchange(dev);
2450 spin_unlock(&np->lock);
2451 np->link_timeout = jiffies + LINK_TIMEOUT;
2452 }
2453 if (events & (NVREG_IRQ_TX_ERR)) {
2454 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2455 dev->name, events);
2456 }
2457 if (events & (NVREG_IRQ_UNKNOWN)) {
2458 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2459 dev->name, events);
2460 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05002461 if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) {
2462 spin_lock(&np->lock);
2463 /* disable interrupts on the nic */
2464 if (!(np->msi_flags & NV_MSI_X_ENABLED))
2465 writel(0, base + NvRegIrqMask);
2466 else
2467 writel(np->irqmask, base + NvRegIrqMask);
2468 pci_push(base);
2469
2470 if (!np->in_shutdown) {
2471 np->nic_poll_irq = np->irqmask;
2472 np->recover_error = 1;
2473 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2474 }
2475 spin_unlock(&np->lock);
2476 break;
2477 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002478#ifdef CONFIG_FORCEDETH_NAPI
2479 if (events & NVREG_IRQ_RX_ALL) {
2480 netif_rx_schedule(dev);
2481
2482 /* Disable furthur receive irq's */
2483 spin_lock(&np->lock);
2484 np->irqmask &= ~NVREG_IRQ_RX_ALL;
2485
2486 if (np->msi_flags & NV_MSI_X_ENABLED)
2487 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2488 else
2489 writel(np->irqmask, base + NvRegIrqMask);
2490 spin_unlock(&np->lock);
2491 }
2492#else
2493 nv_rx_process(dev, dev->weight);
2494 if (nv_alloc_rx(dev)) {
2495 spin_lock(&np->lock);
2496 if (!np->in_shutdown)
2497 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2498 spin_unlock(&np->lock);
2499 }
2500#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 if (i > max_interrupt_work) {
2502 spin_lock(&np->lock);
2503 /* disable interrupts on the nic */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002504 if (!(np->msi_flags & NV_MSI_X_ENABLED))
2505 writel(0, base + NvRegIrqMask);
2506 else
2507 writel(np->irqmask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 pci_push(base);
2509
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002510 if (!np->in_shutdown) {
2511 np->nic_poll_irq = np->irqmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
2515 spin_unlock(&np->lock);
2516 break;
2517 }
2518
2519 }
2520 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
2521
2522 return IRQ_RETVAL(i);
2523}
2524
David Howells7d12e782006-10-05 14:55:46 +01002525static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002526{
2527 struct net_device *dev = (struct net_device *) data;
2528 struct fe_priv *np = netdev_priv(dev);
2529 u8 __iomem *base = get_hwbase(dev);
2530 u32 events;
2531 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002532 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002533
2534 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
2535
2536 for (i=0; ; i++) {
2537 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
2538 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
2539 pci_push(base);
2540 dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
2541 if (!(events & np->irqmask))
2542 break;
2543
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002544 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002545 nv_tx_done(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002546 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002547
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002548 if (events & (NVREG_IRQ_TX_ERR)) {
2549 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2550 dev->name, events);
2551 }
2552 if (i > max_interrupt_work) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002553 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002554 /* disable interrupts on the nic */
2555 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
2556 pci_push(base);
2557
2558 if (!np->in_shutdown) {
2559 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
2560 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2561 }
2562 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002563 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002564 break;
2565 }
2566
2567 }
2568 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
2569
2570 return IRQ_RETVAL(i);
2571}
2572
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002573#ifdef CONFIG_FORCEDETH_NAPI
2574static int nv_napi_poll(struct net_device *dev, int *budget)
2575{
2576 int pkts, limit = min(*budget, dev->quota);
2577 struct fe_priv *np = netdev_priv(dev);
2578 u8 __iomem *base = get_hwbase(dev);
2579
2580 pkts = nv_rx_process(dev, limit);
2581
2582 if (nv_alloc_rx(dev)) {
2583 spin_lock_irq(&np->lock);
2584 if (!np->in_shutdown)
2585 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2586 spin_unlock_irq(&np->lock);
2587 }
2588
2589 if (pkts < limit) {
2590 /* all done, no more packets present */
2591 netif_rx_complete(dev);
2592
2593 /* re-enable receive interrupts */
2594 spin_lock_irq(&np->lock);
2595 np->irqmask |= NVREG_IRQ_RX_ALL;
2596 if (np->msi_flags & NV_MSI_X_ENABLED)
2597 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2598 else
2599 writel(np->irqmask, base + NvRegIrqMask);
2600 spin_unlock_irq(&np->lock);
2601 return 0;
2602 } else {
2603 /* used up our quantum, so reschedule */
2604 dev->quota -= pkts;
2605 *budget -= pkts;
2606 return 1;
2607 }
2608}
2609#endif
2610
2611#ifdef CONFIG_FORCEDETH_NAPI
David Howells7d12e782006-10-05 14:55:46 +01002612static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002613{
2614 struct net_device *dev = (struct net_device *) data;
2615 u8 __iomem *base = get_hwbase(dev);
2616 u32 events;
2617
2618 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
2619 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
2620
2621 if (events) {
2622 netif_rx_schedule(dev);
2623 /* disable receive interrupts on the nic */
2624 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2625 pci_push(base);
2626 }
2627 return IRQ_HANDLED;
2628}
2629#else
David Howells7d12e782006-10-05 14:55:46 +01002630static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002631{
2632 struct net_device *dev = (struct net_device *) data;
2633 struct fe_priv *np = netdev_priv(dev);
2634 u8 __iomem *base = get_hwbase(dev);
2635 u32 events;
2636 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002637 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002638
2639 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name);
2640
2641 for (i=0; ; i++) {
2642 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
2643 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
2644 pci_push(base);
2645 dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
2646 if (!(events & np->irqmask))
2647 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002648
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002649 nv_rx_process(dev, dev->weight);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002650 if (nv_alloc_rx(dev)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002651 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002652 if (!np->in_shutdown)
2653 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002654 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002655 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002656
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002657 if (i > max_interrupt_work) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002658 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002659 /* disable interrupts on the nic */
2660 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2661 pci_push(base);
2662
2663 if (!np->in_shutdown) {
2664 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
2665 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2666 }
2667 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002668 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002669 break;
2670 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002671 }
2672 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
2673
2674 return IRQ_RETVAL(i);
2675}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002676#endif
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002677
David Howells7d12e782006-10-05 14:55:46 +01002678static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002679{
2680 struct net_device *dev = (struct net_device *) data;
2681 struct fe_priv *np = netdev_priv(dev);
2682 u8 __iomem *base = get_hwbase(dev);
2683 u32 events;
2684 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002685 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002686
2687 dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
2688
2689 for (i=0; ; i++) {
2690 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
2691 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
2692 pci_push(base);
2693 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2694 if (!(events & np->irqmask))
2695 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002696
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002697 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002698 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002699 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002700 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002701 }
2702 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002703 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002704 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002705 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002706 np->link_timeout = jiffies + LINK_TIMEOUT;
2707 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05002708 if (events & NVREG_IRQ_RECOVER_ERROR) {
2709 spin_lock_irq(&np->lock);
2710 /* disable interrupts on the nic */
2711 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
2712 pci_push(base);
2713
2714 if (!np->in_shutdown) {
2715 np->nic_poll_irq |= NVREG_IRQ_OTHER;
2716 np->recover_error = 1;
2717 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2718 }
2719 spin_unlock_irq(&np->lock);
2720 break;
2721 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002722 if (events & (NVREG_IRQ_UNKNOWN)) {
2723 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2724 dev->name, events);
2725 }
2726 if (i > max_interrupt_work) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002727 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002728 /* disable interrupts on the nic */
2729 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
2730 pci_push(base);
2731
2732 if (!np->in_shutdown) {
2733 np->nic_poll_irq |= NVREG_IRQ_OTHER;
2734 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2735 }
2736 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02002737 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002738 break;
2739 }
2740
2741 }
2742 dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
2743
2744 return IRQ_RETVAL(i);
2745}
2746
David Howells7d12e782006-10-05 14:55:46 +01002747static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002748{
2749 struct net_device *dev = (struct net_device *) data;
2750 struct fe_priv *np = netdev_priv(dev);
2751 u8 __iomem *base = get_hwbase(dev);
2752 u32 events;
2753
2754 dprintk(KERN_DEBUG "%s: nv_nic_irq_test\n", dev->name);
2755
2756 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
2757 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2758 writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus);
2759 } else {
2760 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2761 writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
2762 }
2763 pci_push(base);
2764 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2765 if (!(events & NVREG_IRQ_TIMER))
2766 return IRQ_RETVAL(0);
2767
2768 spin_lock(&np->lock);
2769 np->intr_test = 1;
2770 spin_unlock(&np->lock);
2771
2772 dprintk(KERN_DEBUG "%s: nv_nic_irq_test completed\n", dev->name);
2773
2774 return IRQ_RETVAL(1);
2775}
2776
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002777static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
2778{
2779 u8 __iomem *base = get_hwbase(dev);
2780 int i;
2781 u32 msixmap = 0;
2782
2783 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
2784 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
2785 * the remaining 8 interrupts.
2786 */
2787 for (i = 0; i < 8; i++) {
2788 if ((irqmask >> i) & 0x1) {
2789 msixmap |= vector << (i << 2);
2790 }
2791 }
2792 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
2793
2794 msixmap = 0;
2795 for (i = 0; i < 8; i++) {
2796 if ((irqmask >> (i + 8)) & 0x1) {
2797 msixmap |= vector << (i << 2);
2798 }
2799 }
2800 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
2801}
2802
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002803static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002804{
2805 struct fe_priv *np = get_nvpriv(dev);
2806 u8 __iomem *base = get_hwbase(dev);
2807 int ret = 1;
2808 int i;
2809
2810 if (np->msi_flags & NV_MSI_X_CAPABLE) {
2811 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
2812 np->msi_x_entry[i].entry = i;
2813 }
2814 if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) {
2815 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002816 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002817 /* Request irq for rx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002818 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 -04002819 printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret);
2820 pci_disable_msix(np->pci_dev);
2821 np->msi_flags &= ~NV_MSI_X_ENABLED;
2822 goto out_err;
2823 }
2824 /* Request irq for tx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002825 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 -04002826 printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret);
2827 pci_disable_msix(np->pci_dev);
2828 np->msi_flags &= ~NV_MSI_X_ENABLED;
2829 goto out_free_rx;
2830 }
2831 /* Request irq for link and timer handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002832 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 -04002833 printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret);
2834 pci_disable_msix(np->pci_dev);
2835 np->msi_flags &= ~NV_MSI_X_ENABLED;
2836 goto out_free_tx;
2837 }
2838 /* map interrupts to their respective vector */
2839 writel(0, base + NvRegMSIXMap0);
2840 writel(0, base + NvRegMSIXMap1);
2841 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
2842 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
2843 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
2844 } else {
2845 /* Request irq for all interrupts */
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002846 if ((!intr_test &&
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002847 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 -04002848 (intr_test &&
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002849 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 -04002850 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
2851 pci_disable_msix(np->pci_dev);
2852 np->msi_flags &= ~NV_MSI_X_ENABLED;
2853 goto out_err;
2854 }
2855
2856 /* map interrupts to vector 0 */
2857 writel(0, base + NvRegMSIXMap0);
2858 writel(0, base + NvRegMSIXMap1);
2859 }
2860 }
2861 }
2862 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
2863 if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
2864 np->msi_flags |= NV_MSI_ENABLED;
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002865 if ((!intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
2866 (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 -04002867 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
2868 pci_disable_msi(np->pci_dev);
2869 np->msi_flags &= ~NV_MSI_ENABLED;
2870 goto out_err;
2871 }
2872
2873 /* map interrupts to vector 0 */
2874 writel(0, base + NvRegMSIMap0);
2875 writel(0, base + NvRegMSIMap1);
2876 /* enable msi vector 0 */
2877 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
2878 }
2879 }
2880 if (ret != 0) {
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07002881 if ((!intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
2882 (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 -04002883 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04002884
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04002885 }
2886
2887 return 0;
2888out_free_tx:
2889 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
2890out_free_rx:
2891 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
2892out_err:
2893 return 1;
2894}
2895
2896static void nv_free_irq(struct net_device *dev)
2897{
2898 struct fe_priv *np = get_nvpriv(dev);
2899 int i;
2900
2901 if (np->msi_flags & NV_MSI_X_ENABLED) {
2902 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
2903 free_irq(np->msi_x_entry[i].vector, dev);
2904 }
2905 pci_disable_msix(np->pci_dev);
2906 np->msi_flags &= ~NV_MSI_X_ENABLED;
2907 } else {
2908 free_irq(np->pci_dev->irq, dev);
2909 if (np->msi_flags & NV_MSI_ENABLED) {
2910 pci_disable_msi(np->pci_dev);
2911 np->msi_flags &= ~NV_MSI_ENABLED;
2912 }
2913 }
2914}
2915
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916static void nv_do_nic_poll(unsigned long data)
2917{
2918 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002919 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002921 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 /*
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002924 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 * reenable interrupts on the nic, we have to do this before calling
2926 * nv_nic_irq because that may decide to do otherwise
2927 */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002928
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002929 if (!using_multi_irqs(dev)) {
2930 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002931 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002932 else
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002933 disable_irq_lockdep(dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002934 mask = np->irqmask;
2935 } else {
2936 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002937 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002938 mask |= NVREG_IRQ_RX_ALL;
2939 }
2940 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002941 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002942 mask |= NVREG_IRQ_TX_ALL;
2943 }
2944 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002945 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002946 mask |= NVREG_IRQ_OTHER;
2947 }
2948 }
2949 np->nic_poll_irq = 0;
2950
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05002951 if (np->recover_error) {
2952 np->recover_error = 0;
2953 printk(KERN_INFO "forcedeth: MAC in recoverable error state\n");
2954 if (netif_running(dev)) {
2955 netif_tx_lock_bh(dev);
2956 spin_lock(&np->lock);
2957 /* stop engines */
2958 nv_stop_rx(dev);
2959 nv_stop_tx(dev);
2960 nv_txrx_reset(dev);
2961 /* drain rx queue */
2962 nv_drain_rx(dev);
2963 nv_drain_tx(dev);
2964 /* reinit driver view of the rx queue */
2965 set_bufsize(dev);
2966 if (nv_init_ring(dev)) {
2967 if (!np->in_shutdown)
2968 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2969 }
2970 /* reinit nic view of the rx queue */
2971 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
2972 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
2973 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
2974 base + NvRegRingSizes);
2975 pci_push(base);
2976 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2977 pci_push(base);
2978
2979 /* restart rx engine */
2980 nv_start_rx(dev);
2981 nv_start_tx(dev);
2982 spin_unlock(&np->lock);
2983 netif_tx_unlock_bh(dev);
2984 }
2985 }
2986
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002987 /* FIXME: Do we need synchronize_irq(dev->irq) here? */
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002988
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002989 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 pci_push(base);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002991
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002992 if (!using_multi_irqs(dev)) {
David Howells7d12e782006-10-05 14:55:46 +01002993 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002994 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002995 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002996 else
Ingo Molnar8688cfc2006-07-03 00:25:39 -07002997 enable_irq_lockdep(dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002998 } else {
2999 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01003000 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003001 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003002 }
3003 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01003004 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003005 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003006 }
3007 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
David Howells7d12e782006-10-05 14:55:46 +01003008 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003009 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003010 }
3011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012}
3013
Michal Schmidt2918c352005-05-12 19:42:06 -04003014#ifdef CONFIG_NET_POLL_CONTROLLER
3015static void nv_poll_controller(struct net_device *dev)
3016{
3017 nv_do_nic_poll((unsigned long) dev);
3018}
3019#endif
3020
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003021static void nv_do_stats_poll(unsigned long data)
3022{
3023 struct net_device *dev = (struct net_device *) data;
3024 struct fe_priv *np = netdev_priv(dev);
3025 u8 __iomem *base = get_hwbase(dev);
3026
3027 np->estats.tx_bytes += readl(base + NvRegTxCnt);
3028 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
3029 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
3030 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
3031 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
3032 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
3033 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
3034 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
3035 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
3036 np->estats.tx_deferral += readl(base + NvRegTxDef);
3037 np->estats.tx_packets += readl(base + NvRegTxFrame);
3038 np->estats.tx_pause += readl(base + NvRegTxPause);
3039 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
3040 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
3041 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
3042 np->estats.rx_runt += readl(base + NvRegRxRunt);
3043 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
3044 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
3045 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
3046 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
3047 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
3048 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
3049 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
3050 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
3051 np->estats.rx_bytes += readl(base + NvRegRxCnt);
3052 np->estats.rx_pause += readl(base + NvRegRxPause);
3053 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
3054 np->estats.rx_packets =
3055 np->estats.rx_unicast +
3056 np->estats.rx_multicast +
3057 np->estats.rx_broadcast;
3058 np->estats.rx_errors_total =
3059 np->estats.rx_crc_errors +
3060 np->estats.rx_over_errors +
3061 np->estats.rx_frame_error +
3062 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
3063 np->estats.rx_late_collision +
3064 np->estats.rx_runt +
3065 np->estats.rx_frame_too_long;
3066
3067 if (!np->in_shutdown)
3068 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
3069}
3070
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
3072{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003073 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 strcpy(info->driver, "forcedeth");
3075 strcpy(info->version, FORCEDETH_VERSION);
3076 strcpy(info->bus_info, pci_name(np->pci_dev));
3077}
3078
3079static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3080{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003081 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 wolinfo->supported = WAKE_MAGIC;
3083
3084 spin_lock_irq(&np->lock);
3085 if (np->wolenabled)
3086 wolinfo->wolopts = WAKE_MAGIC;
3087 spin_unlock_irq(&np->lock);
3088}
3089
3090static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3091{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003092 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003094 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003098 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003100 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003102 if (netif_running(dev)) {
3103 spin_lock_irq(&np->lock);
3104 writel(flags, base + NvRegWakeUpFlags);
3105 spin_unlock_irq(&np->lock);
3106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 return 0;
3108}
3109
3110static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3111{
3112 struct fe_priv *np = netdev_priv(dev);
3113 int adv;
3114
3115 spin_lock_irq(&np->lock);
3116 ecmd->port = PORT_MII;
3117 if (!netif_running(dev)) {
3118 /* We do not track link speed / duplex setting if the
3119 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003120 if (nv_update_linkspeed(dev)) {
3121 if (!netif_carrier_ok(dev))
3122 netif_carrier_on(dev);
3123 } else {
3124 if (netif_carrier_ok(dev))
3125 netif_carrier_off(dev);
3126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003128
3129 if (netif_carrier_ok(dev)) {
3130 switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 case NVREG_LINKSPEED_10:
3132 ecmd->speed = SPEED_10;
3133 break;
3134 case NVREG_LINKSPEED_100:
3135 ecmd->speed = SPEED_100;
3136 break;
3137 case NVREG_LINKSPEED_1000:
3138 ecmd->speed = SPEED_1000;
3139 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003140 }
3141 ecmd->duplex = DUPLEX_HALF;
3142 if (np->duplex)
3143 ecmd->duplex = DUPLEX_FULL;
3144 } else {
3145 ecmd->speed = -1;
3146 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
3149 ecmd->autoneg = np->autoneg;
3150
3151 ecmd->advertising = ADVERTISED_MII;
3152 if (np->autoneg) {
3153 ecmd->advertising |= ADVERTISED_Autoneg;
3154 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003155 if (adv & ADVERTISE_10HALF)
3156 ecmd->advertising |= ADVERTISED_10baseT_Half;
3157 if (adv & ADVERTISE_10FULL)
3158 ecmd->advertising |= ADVERTISED_10baseT_Full;
3159 if (adv & ADVERTISE_100HALF)
3160 ecmd->advertising |= ADVERTISED_100baseT_Half;
3161 if (adv & ADVERTISE_100FULL)
3162 ecmd->advertising |= ADVERTISED_100baseT_Full;
3163 if (np->gigabit == PHY_GIGABIT) {
3164 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3165 if (adv & ADVERTISE_1000FULL)
3166 ecmd->advertising |= ADVERTISED_1000baseT_Full;
3167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 ecmd->supported = (SUPPORTED_Autoneg |
3170 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
3171 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
3172 SUPPORTED_MII);
3173 if (np->gigabit == PHY_GIGABIT)
3174 ecmd->supported |= SUPPORTED_1000baseT_Full;
3175
3176 ecmd->phy_address = np->phyaddr;
3177 ecmd->transceiver = XCVR_EXTERNAL;
3178
3179 /* ignore maxtxpkt, maxrxpkt for now */
3180 spin_unlock_irq(&np->lock);
3181 return 0;
3182}
3183
3184static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3185{
3186 struct fe_priv *np = netdev_priv(dev);
3187
3188 if (ecmd->port != PORT_MII)
3189 return -EINVAL;
3190 if (ecmd->transceiver != XCVR_EXTERNAL)
3191 return -EINVAL;
3192 if (ecmd->phy_address != np->phyaddr) {
3193 /* TODO: support switching between multiple phys. Should be
3194 * trivial, but not enabled due to lack of test hardware. */
3195 return -EINVAL;
3196 }
3197 if (ecmd->autoneg == AUTONEG_ENABLE) {
3198 u32 mask;
3199
3200 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
3201 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
3202 if (np->gigabit == PHY_GIGABIT)
3203 mask |= ADVERTISED_1000baseT_Full;
3204
3205 if ((ecmd->advertising & mask) == 0)
3206 return -EINVAL;
3207
3208 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
3209 /* Note: autonegotiation disable, speed 1000 intentionally
3210 * forbidden - noone should need that. */
3211
3212 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
3213 return -EINVAL;
3214 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
3215 return -EINVAL;
3216 } else {
3217 return -EINVAL;
3218 }
3219
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003220 netif_carrier_off(dev);
3221 if (netif_running(dev)) {
3222 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003223 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003224 spin_lock(&np->lock);
3225 /* stop engines */
3226 nv_stop_rx(dev);
3227 nv_stop_tx(dev);
3228 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003229 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003230 }
3231
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 if (ecmd->autoneg == AUTONEG_ENABLE) {
3233 int adv, bmcr;
3234
3235 np->autoneg = 1;
3236
3237 /* advertise only what has been requested */
3238 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003239 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 if (ecmd->advertising & ADVERTISED_10baseT_Half)
3241 adv |= ADVERTISE_10HALF;
3242 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003243 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 if (ecmd->advertising & ADVERTISED_100baseT_Half)
3245 adv |= ADVERTISE_100HALF;
3246 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003247 adv |= ADVERTISE_100FULL;
3248 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
3249 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3250 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3251 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3253
3254 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003255 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 adv &= ~ADVERTISE_1000FULL;
3257 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
3258 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003259 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 }
3261
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003262 if (netif_running(dev))
3263 printk(KERN_INFO "%s: link down.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003265 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
3266 bmcr |= BMCR_ANENABLE;
3267 /* reset the phy in order for settings to stick,
3268 * and cause autoneg to start */
3269 if (phy_reset(dev, bmcr)) {
3270 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3271 return -EINVAL;
3272 }
3273 } else {
3274 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3275 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 } else {
3278 int adv, bmcr;
3279
3280 np->autoneg = 0;
3281
3282 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003283 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
3285 adv |= ADVERTISE_10HALF;
3286 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003287 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
3289 adv |= ADVERTISE_100HALF;
3290 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003291 adv |= ADVERTISE_100FULL;
3292 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
3293 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisments but disable tx pause */
3294 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3295 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3296 }
3297 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
3298 adv |= ADVERTISE_PAUSE_ASYM;
3299 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3302 np->fixed_mode = adv;
3303
3304 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003305 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003307 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 }
3309
3310 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003311 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
3312 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003314 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003316 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003317 /* reset the phy in order for forced mode settings to stick */
3318 if (phy_reset(dev, bmcr)) {
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003319 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3320 return -EINVAL;
3321 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003322 } else {
3323 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3324 if (netif_running(dev)) {
3325 /* Wait a bit and then reconfigure the nic. */
3326 udelay(10);
3327 nv_linkchange(dev);
3328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 }
3330 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003331
3332 if (netif_running(dev)) {
3333 nv_start_rx(dev);
3334 nv_start_tx(dev);
3335 nv_enable_irq(dev);
3336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
3338 return 0;
3339}
3340
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003341#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003342
3343static int nv_get_regs_len(struct net_device *dev)
3344{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04003345 struct fe_priv *np = netdev_priv(dev);
3346 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003347}
3348
3349static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
3350{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003351 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003352 u8 __iomem *base = get_hwbase(dev);
3353 u32 *rbuf = buf;
3354 int i;
3355
3356 regs->version = FORCEDETH_REGS_VER;
3357 spin_lock_irq(&np->lock);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04003358 for (i = 0;i <= np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003359 rbuf[i] = readl(base + i*sizeof(u32));
3360 spin_unlock_irq(&np->lock);
3361}
3362
3363static int nv_nway_reset(struct net_device *dev)
3364{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003365 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003366 int ret;
3367
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003368 if (np->autoneg) {
3369 int bmcr;
3370
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003371 netif_carrier_off(dev);
3372 if (netif_running(dev)) {
3373 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003374 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003375 spin_lock(&np->lock);
3376 /* stop engines */
3377 nv_stop_rx(dev);
3378 nv_stop_tx(dev);
3379 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003380 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003381 printk(KERN_INFO "%s: link down.\n", dev->name);
3382 }
3383
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003384 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003385 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
3386 bmcr |= BMCR_ANENABLE;
3387 /* reset the phy in order for settings to stick*/
3388 if (phy_reset(dev, bmcr)) {
3389 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3390 return -EINVAL;
3391 }
3392 } else {
3393 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3394 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3395 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003396
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003397 if (netif_running(dev)) {
3398 nv_start_rx(dev);
3399 nv_start_tx(dev);
3400 nv_enable_irq(dev);
3401 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003402 ret = 0;
3403 } else {
3404 ret = -EINVAL;
3405 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003406
3407 return ret;
3408}
3409
Zachary Amsden0674d592006-06-04 02:51:38 -07003410static int nv_set_tso(struct net_device *dev, u32 value)
3411{
3412 struct fe_priv *np = netdev_priv(dev);
3413
3414 if ((np->driver_data & DEV_HAS_CHECKSUM))
3415 return ethtool_op_set_tso(dev, value);
3416 else
Ayaz Abdulla6a788142006-06-10 22:47:26 -04003417 return -EOPNOTSUPP;
Zachary Amsden0674d592006-06-04 02:51:38 -07003418}
Zachary Amsden0674d592006-06-04 02:51:38 -07003419
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003420static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
3421{
3422 struct fe_priv *np = netdev_priv(dev);
3423
3424 ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
3425 ring->rx_mini_max_pending = 0;
3426 ring->rx_jumbo_max_pending = 0;
3427 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
3428
3429 ring->rx_pending = np->rx_ring_size;
3430 ring->rx_mini_pending = 0;
3431 ring->rx_jumbo_pending = 0;
3432 ring->tx_pending = np->tx_ring_size;
3433}
3434
3435static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
3436{
3437 struct fe_priv *np = netdev_priv(dev);
3438 u8 __iomem *base = get_hwbase(dev);
3439 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff, *rx_dma, *tx_dma, *tx_dma_len;
3440 dma_addr_t ring_addr;
3441
3442 if (ring->rx_pending < RX_RING_MIN ||
3443 ring->tx_pending < TX_RING_MIN ||
3444 ring->rx_mini_pending != 0 ||
3445 ring->rx_jumbo_pending != 0 ||
3446 (np->desc_ver == DESC_VER_1 &&
3447 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
3448 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
3449 (np->desc_ver != DESC_VER_1 &&
3450 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
3451 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
3452 return -EINVAL;
3453 }
3454
3455 /* allocate new rings */
3456 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3457 rxtx_ring = pci_alloc_consistent(np->pci_dev,
3458 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
3459 &ring_addr);
3460 } else {
3461 rxtx_ring = pci_alloc_consistent(np->pci_dev,
3462 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
3463 &ring_addr);
3464 }
3465 rx_skbuff = kmalloc(sizeof(struct sk_buff*) * ring->rx_pending, GFP_KERNEL);
3466 rx_dma = kmalloc(sizeof(dma_addr_t) * ring->rx_pending, GFP_KERNEL);
3467 tx_skbuff = kmalloc(sizeof(struct sk_buff*) * ring->tx_pending, GFP_KERNEL);
3468 tx_dma = kmalloc(sizeof(dma_addr_t) * ring->tx_pending, GFP_KERNEL);
3469 tx_dma_len = kmalloc(sizeof(unsigned int) * ring->tx_pending, GFP_KERNEL);
3470 if (!rxtx_ring || !rx_skbuff || !rx_dma || !tx_skbuff || !tx_dma || !tx_dma_len) {
3471 /* fall back to old rings */
3472 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003473 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003474 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
3475 rxtx_ring, ring_addr);
3476 } else {
3477 if (rxtx_ring)
3478 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
3479 rxtx_ring, ring_addr);
3480 }
3481 if (rx_skbuff)
3482 kfree(rx_skbuff);
3483 if (rx_dma)
3484 kfree(rx_dma);
3485 if (tx_skbuff)
3486 kfree(tx_skbuff);
3487 if (tx_dma)
3488 kfree(tx_dma);
3489 if (tx_dma_len)
3490 kfree(tx_dma_len);
3491 goto exit;
3492 }
3493
3494 if (netif_running(dev)) {
3495 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003496 netif_tx_lock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003497 spin_lock(&np->lock);
3498 /* stop engines */
3499 nv_stop_rx(dev);
3500 nv_stop_tx(dev);
3501 nv_txrx_reset(dev);
3502 /* drain queues */
3503 nv_drain_rx(dev);
3504 nv_drain_tx(dev);
3505 /* delete queues */
3506 free_rings(dev);
3507 }
3508
3509 /* set new values */
3510 np->rx_ring_size = ring->rx_pending;
3511 np->tx_ring_size = ring->tx_pending;
3512 np->tx_limit_stop = ring->tx_pending - TX_LIMIT_DIFFERENCE;
3513 np->tx_limit_start = ring->tx_pending - TX_LIMIT_DIFFERENCE - 1;
3514 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3515 np->rx_ring.orig = (struct ring_desc*)rxtx_ring;
3516 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
3517 } else {
3518 np->rx_ring.ex = (struct ring_desc_ex*)rxtx_ring;
3519 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
3520 }
3521 np->rx_skbuff = (struct sk_buff**)rx_skbuff;
3522 np->rx_dma = (dma_addr_t*)rx_dma;
3523 np->tx_skbuff = (struct sk_buff**)tx_skbuff;
3524 np->tx_dma = (dma_addr_t*)tx_dma;
3525 np->tx_dma_len = (unsigned int*)tx_dma_len;
3526 np->ring_addr = ring_addr;
3527
3528 memset(np->rx_skbuff, 0, sizeof(struct sk_buff*) * np->rx_ring_size);
3529 memset(np->rx_dma, 0, sizeof(dma_addr_t) * np->rx_ring_size);
3530 memset(np->tx_skbuff, 0, sizeof(struct sk_buff*) * np->tx_ring_size);
3531 memset(np->tx_dma, 0, sizeof(dma_addr_t) * np->tx_ring_size);
3532 memset(np->tx_dma_len, 0, sizeof(unsigned int) * np->tx_ring_size);
3533
3534 if (netif_running(dev)) {
3535 /* reinit driver view of the queues */
3536 set_bufsize(dev);
3537 if (nv_init_ring(dev)) {
3538 if (!np->in_shutdown)
3539 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3540 }
3541
3542 /* reinit nic view of the queues */
3543 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3544 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3545 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3546 base + NvRegRingSizes);
3547 pci_push(base);
3548 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3549 pci_push(base);
3550
3551 /* restart engines */
3552 nv_start_rx(dev);
3553 nv_start_tx(dev);
3554 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003555 netif_tx_unlock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003556 nv_enable_irq(dev);
3557 }
3558 return 0;
3559exit:
3560 return -ENOMEM;
3561}
3562
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003563static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
3564{
3565 struct fe_priv *np = netdev_priv(dev);
3566
3567 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
3568 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
3569 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
3570}
3571
3572static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
3573{
3574 struct fe_priv *np = netdev_priv(dev);
3575 int adv, bmcr;
3576
3577 if ((!np->autoneg && np->duplex == 0) ||
3578 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
3579 printk(KERN_INFO "%s: can not set pause settings when forced link is in half duplex.\n",
3580 dev->name);
3581 return -EINVAL;
3582 }
3583 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
3584 printk(KERN_INFO "%s: hardware does not support tx pause frames.\n", dev->name);
3585 return -EINVAL;
3586 }
3587
3588 netif_carrier_off(dev);
3589 if (netif_running(dev)) {
3590 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003591 netif_tx_lock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003592 spin_lock(&np->lock);
3593 /* stop engines */
3594 nv_stop_rx(dev);
3595 nv_stop_tx(dev);
3596 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003597 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003598 }
3599
3600 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
3601 if (pause->rx_pause)
3602 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
3603 if (pause->tx_pause)
3604 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
3605
3606 if (np->autoneg && pause->autoneg) {
3607 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
3608
3609 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3610 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3611 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
3612 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3613 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3614 adv |= ADVERTISE_PAUSE_ASYM;
3615 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3616
3617 if (netif_running(dev))
3618 printk(KERN_INFO "%s: link down.\n", dev->name);
3619 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3620 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3621 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3622 } else {
3623 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
3624 if (pause->rx_pause)
3625 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3626 if (pause->tx_pause)
3627 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3628
3629 if (!netif_running(dev))
3630 nv_update_linkspeed(dev);
3631 else
3632 nv_update_pause(dev, np->pause_flags);
3633 }
3634
3635 if (netif_running(dev)) {
3636 nv_start_rx(dev);
3637 nv_start_tx(dev);
3638 nv_enable_irq(dev);
3639 }
3640 return 0;
3641}
3642
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003643static u32 nv_get_rx_csum(struct net_device *dev)
3644{
3645 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04003646 return (np->rx_csum) != 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003647}
3648
3649static int nv_set_rx_csum(struct net_device *dev, u32 data)
3650{
3651 struct fe_priv *np = netdev_priv(dev);
3652 u8 __iomem *base = get_hwbase(dev);
3653 int retcode = 0;
3654
3655 if (np->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003656 if (data) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04003657 np->rx_csum = 1;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003658 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003659 } else {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04003660 np->rx_csum = 0;
3661 /* vlan is dependent on rx checksum offload */
3662 if (!(np->vlanctl_bits & NVREG_VLANCONTROL_ENABLE))
3663 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003664 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04003665 if (netif_running(dev)) {
3666 spin_lock_irq(&np->lock);
3667 writel(np->txrxctl_bits, base + NvRegTxRxControl);
3668 spin_unlock_irq(&np->lock);
3669 }
3670 } else {
3671 return -EINVAL;
3672 }
3673
3674 return retcode;
3675}
3676
3677static int nv_set_tx_csum(struct net_device *dev, u32 data)
3678{
3679 struct fe_priv *np = netdev_priv(dev);
3680
3681 if (np->driver_data & DEV_HAS_CHECKSUM)
3682 return ethtool_op_set_tx_hw_csum(dev, data);
3683 else
3684 return -EOPNOTSUPP;
3685}
3686
3687static int nv_set_sg(struct net_device *dev, u32 data)
3688{
3689 struct fe_priv *np = netdev_priv(dev);
3690
3691 if (np->driver_data & DEV_HAS_CHECKSUM)
3692 return ethtool_op_set_sg(dev, data);
3693 else
3694 return -EOPNOTSUPP;
3695}
3696
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003697static int nv_get_stats_count(struct net_device *dev)
3698{
3699 struct fe_priv *np = netdev_priv(dev);
3700
3701 if (np->driver_data & DEV_HAS_STATISTICS)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003702 return sizeof(struct nv_ethtool_stats)/sizeof(u64);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003703 else
3704 return 0;
3705}
3706
3707static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *buffer)
3708{
3709 struct fe_priv *np = netdev_priv(dev);
3710
3711 /* update stats */
3712 nv_do_stats_poll((unsigned long)dev);
3713
3714 memcpy(buffer, &np->estats, nv_get_stats_count(dev)*sizeof(u64));
3715}
3716
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003717static int nv_self_test_count(struct net_device *dev)
3718{
3719 struct fe_priv *np = netdev_priv(dev);
3720
3721 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
3722 return NV_TEST_COUNT_EXTENDED;
3723 else
3724 return NV_TEST_COUNT_BASE;
3725}
3726
3727static int nv_link_test(struct net_device *dev)
3728{
3729 struct fe_priv *np = netdev_priv(dev);
3730 int mii_status;
3731
3732 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3733 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3734
3735 /* check phy link status */
3736 if (!(mii_status & BMSR_LSTATUS))
3737 return 0;
3738 else
3739 return 1;
3740}
3741
3742static int nv_register_test(struct net_device *dev)
3743{
3744 u8 __iomem *base = get_hwbase(dev);
3745 int i = 0;
3746 u32 orig_read, new_read;
3747
3748 do {
3749 orig_read = readl(base + nv_registers_test[i].reg);
3750
3751 /* xor with mask to toggle bits */
3752 orig_read ^= nv_registers_test[i].mask;
3753
3754 writel(orig_read, base + nv_registers_test[i].reg);
3755
3756 new_read = readl(base + nv_registers_test[i].reg);
3757
3758 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
3759 return 0;
3760
3761 /* restore original value */
3762 orig_read ^= nv_registers_test[i].mask;
3763 writel(orig_read, base + nv_registers_test[i].reg);
3764
3765 } while (nv_registers_test[++i].reg != 0);
3766
3767 return 1;
3768}
3769
3770static int nv_interrupt_test(struct net_device *dev)
3771{
3772 struct fe_priv *np = netdev_priv(dev);
3773 u8 __iomem *base = get_hwbase(dev);
3774 int ret = 1;
3775 int testcnt;
3776 u32 save_msi_flags, save_poll_interval = 0;
3777
3778 if (netif_running(dev)) {
3779 /* free current irq */
3780 nv_free_irq(dev);
3781 save_poll_interval = readl(base+NvRegPollingInterval);
3782 }
3783
3784 /* flag to test interrupt handler */
3785 np->intr_test = 0;
3786
3787 /* setup test irq */
3788 save_msi_flags = np->msi_flags;
3789 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
3790 np->msi_flags |= 0x001; /* setup 1 vector */
3791 if (nv_request_irq(dev, 1))
3792 return 0;
3793
3794 /* setup timer interrupt */
3795 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
3796 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
3797
3798 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
3799
3800 /* wait for at least one interrupt */
3801 msleep(100);
3802
3803 spin_lock_irq(&np->lock);
3804
3805 /* flag should be set within ISR */
3806 testcnt = np->intr_test;
3807 if (!testcnt)
3808 ret = 2;
3809
3810 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
3811 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3812 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3813 else
3814 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3815
3816 spin_unlock_irq(&np->lock);
3817
3818 nv_free_irq(dev);
3819
3820 np->msi_flags = save_msi_flags;
3821
3822 if (netif_running(dev)) {
3823 writel(save_poll_interval, base + NvRegPollingInterval);
3824 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
3825 /* restore original irq */
3826 if (nv_request_irq(dev, 0))
3827 return 0;
3828 }
3829
3830 return ret;
3831}
3832
3833static int nv_loopback_test(struct net_device *dev)
3834{
3835 struct fe_priv *np = netdev_priv(dev);
3836 u8 __iomem *base = get_hwbase(dev);
3837 struct sk_buff *tx_skb, *rx_skb;
3838 dma_addr_t test_dma_addr;
3839 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003840 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003841 int len, i, pkt_len;
3842 u8 *pkt_data;
3843 u32 filter_flags = 0;
3844 u32 misc1_flags = 0;
3845 int ret = 1;
3846
3847 if (netif_running(dev)) {
3848 nv_disable_irq(dev);
3849 filter_flags = readl(base + NvRegPacketFilterFlags);
3850 misc1_flags = readl(base + NvRegMisc1);
3851 } else {
3852 nv_txrx_reset(dev);
3853 }
3854
3855 /* reinit driver view of the rx queue */
3856 set_bufsize(dev);
3857 nv_init_ring(dev);
3858
3859 /* setup hardware for loopback */
3860 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
3861 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
3862
3863 /* reinit nic view of the rx queue */
3864 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3865 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3866 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3867 base + NvRegRingSizes);
3868 pci_push(base);
3869
3870 /* restart rx engine */
3871 nv_start_rx(dev);
3872 nv_start_tx(dev);
3873
3874 /* setup packet for tx */
3875 pkt_len = ETH_DATA_LEN;
3876 tx_skb = dev_alloc_skb(pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07003877 if (!tx_skb) {
3878 printk(KERN_ERR "dev_alloc_skb() failed during loopback test"
3879 " of %s\n", dev->name);
3880 ret = 0;
3881 goto out;
3882 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003883 pkt_data = skb_put(tx_skb, pkt_len);
3884 for (i = 0; i < pkt_len; i++)
3885 pkt_data[i] = (u8)(i & 0xff);
3886 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
3887 tx_skb->end-tx_skb->data, PCI_DMA_FROMDEVICE);
3888
3889 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003890 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
3891 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 -04003892 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003893 np->tx_ring.ex[0].bufhigh = cpu_to_le64(test_dma_addr) >> 32;
3894 np->tx_ring.ex[0].buflow = cpu_to_le64(test_dma_addr) & 0x0FFFFFFFF;
3895 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 -04003896 }
3897 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3898 pci_push(get_hwbase(dev));
3899
3900 msleep(500);
3901
3902 /* check for rx of the packet */
3903 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003904 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003905 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
3906
3907 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003908 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003909 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
3910 }
3911
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003912 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003913 ret = 0;
3914 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003915 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003916 ret = 0;
3917 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003918 if (flags & NV_RX2_ERROR) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003919 ret = 0;
3920 }
3921 }
3922
3923 if (ret) {
3924 if (len != pkt_len) {
3925 ret = 0;
3926 dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n",
3927 dev->name, len, pkt_len);
3928 } else {
3929 rx_skb = np->rx_skbuff[0];
3930 for (i = 0; i < pkt_len; i++) {
3931 if (rx_skb->data[i] != (u8)(i & 0xff)) {
3932 ret = 0;
3933 dprintk(KERN_DEBUG "%s: loopback pattern check failed on byte %d\n",
3934 dev->name, i);
3935 break;
3936 }
3937 }
3938 }
3939 } else {
3940 dprintk(KERN_DEBUG "%s: loopback - did not receive test packet\n", dev->name);
3941 }
3942
3943 pci_unmap_page(np->pci_dev, test_dma_addr,
3944 tx_skb->end-tx_skb->data,
3945 PCI_DMA_TODEVICE);
3946 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07003947 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003948 /* stop engines */
3949 nv_stop_rx(dev);
3950 nv_stop_tx(dev);
3951 nv_txrx_reset(dev);
3952 /* drain rx queue */
3953 nv_drain_rx(dev);
3954 nv_drain_tx(dev);
3955
3956 if (netif_running(dev)) {
3957 writel(misc1_flags, base + NvRegMisc1);
3958 writel(filter_flags, base + NvRegPacketFilterFlags);
3959 nv_enable_irq(dev);
3960 }
3961
3962 return ret;
3963}
3964
3965static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
3966{
3967 struct fe_priv *np = netdev_priv(dev);
3968 u8 __iomem *base = get_hwbase(dev);
3969 int result;
3970 memset(buffer, 0, nv_self_test_count(dev)*sizeof(u64));
3971
3972 if (!nv_link_test(dev)) {
3973 test->flags |= ETH_TEST_FL_FAILED;
3974 buffer[0] = 1;
3975 }
3976
3977 if (test->flags & ETH_TEST_FL_OFFLINE) {
3978 if (netif_running(dev)) {
3979 netif_stop_queue(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003980 netif_poll_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003981 netif_tx_lock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003982 spin_lock_irq(&np->lock);
3983 nv_disable_hw_interrupts(dev, np->irqmask);
3984 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3985 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3986 } else {
3987 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3988 }
3989 /* stop engines */
3990 nv_stop_rx(dev);
3991 nv_stop_tx(dev);
3992 nv_txrx_reset(dev);
3993 /* drain rx queue */
3994 nv_drain_rx(dev);
3995 nv_drain_tx(dev);
3996 spin_unlock_irq(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003997 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003998 }
3999
4000 if (!nv_register_test(dev)) {
4001 test->flags |= ETH_TEST_FL_FAILED;
4002 buffer[1] = 1;
4003 }
4004
4005 result = nv_interrupt_test(dev);
4006 if (result != 1) {
4007 test->flags |= ETH_TEST_FL_FAILED;
4008 buffer[2] = 1;
4009 }
4010 if (result == 0) {
4011 /* bail out */
4012 return;
4013 }
4014
4015 if (!nv_loopback_test(dev)) {
4016 test->flags |= ETH_TEST_FL_FAILED;
4017 buffer[3] = 1;
4018 }
4019
4020 if (netif_running(dev)) {
4021 /* reinit driver view of the rx queue */
4022 set_bufsize(dev);
4023 if (nv_init_ring(dev)) {
4024 if (!np->in_shutdown)
4025 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4026 }
4027 /* reinit nic view of the rx queue */
4028 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4029 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4030 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4031 base + NvRegRingSizes);
4032 pci_push(base);
4033 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4034 pci_push(base);
4035 /* restart rx engine */
4036 nv_start_rx(dev);
4037 nv_start_tx(dev);
4038 netif_start_queue(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004039 netif_poll_enable(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004040 nv_enable_hw_interrupts(dev, np->irqmask);
4041 }
4042 }
4043}
4044
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004045static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
4046{
4047 switch (stringset) {
4048 case ETH_SS_STATS:
4049 memcpy(buffer, &nv_estats_str, nv_get_stats_count(dev)*sizeof(struct nv_ethtool_str));
4050 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004051 case ETH_SS_TEST:
4052 memcpy(buffer, &nv_etests_str, nv_self_test_count(dev)*sizeof(struct nv_ethtool_str));
4053 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004054 }
4055}
4056
Jeff Garzik7282d492006-09-13 14:30:00 -04004057static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 .get_drvinfo = nv_get_drvinfo,
4059 .get_link = ethtool_op_get_link,
4060 .get_wol = nv_get_wol,
4061 .set_wol = nv_set_wol,
4062 .get_settings = nv_get_settings,
4063 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004064 .get_regs_len = nv_get_regs_len,
4065 .get_regs = nv_get_regs,
4066 .nway_reset = nv_nway_reset,
John W. Linvillec704b852005-09-12 10:48:56 -04004067 .get_perm_addr = ethtool_op_get_perm_addr,
Zachary Amsden0674d592006-06-04 02:51:38 -07004068 .get_tso = ethtool_op_get_tso,
Ayaz Abdulla6a788142006-06-10 22:47:26 -04004069 .set_tso = nv_set_tso,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004070 .get_ringparam = nv_get_ringparam,
4071 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004072 .get_pauseparam = nv_get_pauseparam,
4073 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004074 .get_rx_csum = nv_get_rx_csum,
4075 .set_rx_csum = nv_set_rx_csum,
4076 .get_tx_csum = ethtool_op_get_tx_csum,
4077 .set_tx_csum = nv_set_tx_csum,
4078 .get_sg = ethtool_op_get_sg,
4079 .set_sg = nv_set_sg,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004080 .get_strings = nv_get_strings,
4081 .get_stats_count = nv_get_stats_count,
4082 .get_ethtool_stats = nv_get_ethtool_stats,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004083 .self_test_count = nv_self_test_count,
4084 .self_test = nv_self_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085};
4086
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004087static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
4088{
4089 struct fe_priv *np = get_nvpriv(dev);
4090
4091 spin_lock_irq(&np->lock);
4092
4093 /* save vlan group */
4094 np->vlangrp = grp;
4095
4096 if (grp) {
4097 /* enable vlan on MAC */
4098 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS;
4099 } else {
4100 /* disable vlan on MAC */
4101 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4102 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4103 }
4104
4105 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4106
4107 spin_unlock_irq(&np->lock);
4108};
4109
4110static void nv_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
4111{
4112 /* nothing to do */
4113};
4114
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004115/* The mgmt unit and driver use a semaphore to access the phy during init */
4116static int nv_mgmt_acquire_sema(struct net_device *dev)
4117{
4118 u8 __iomem *base = get_hwbase(dev);
4119 int i;
4120 u32 tx_ctrl, mgmt_sema;
4121
4122 for (i = 0; i < 10; i++) {
4123 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
4124 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
4125 break;
4126 msleep(500);
4127 }
4128
4129 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
4130 return 0;
4131
4132 for (i = 0; i < 2; i++) {
4133 tx_ctrl = readl(base + NvRegTransmitterControl);
4134 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
4135 writel(tx_ctrl, base + NvRegTransmitterControl);
4136
4137 /* verify that semaphore was acquired */
4138 tx_ctrl = readl(base + NvRegTransmitterControl);
4139 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
4140 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE))
4141 return 1;
4142 else
4143 udelay(50);
4144 }
4145
4146 return 0;
4147}
4148
4149/* Indicate to mgmt unit whether driver is loaded or not */
4150static void nv_mgmt_driver_loaded(struct net_device *dev, int loaded)
4151{
4152 u8 __iomem *base = get_hwbase(dev);
4153 u32 tx_ctrl;
4154
4155 tx_ctrl = readl(base + NvRegTransmitterControl);
4156 if (loaded)
4157 tx_ctrl |= NVREG_XMITCTL_HOST_LOADED;
4158 else
4159 tx_ctrl &= ~NVREG_XMITCTL_HOST_LOADED;
4160 writel(tx_ctrl, base + NvRegTransmitterControl);
4161}
4162
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163static int nv_open(struct net_device *dev)
4164{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004165 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004167 int ret = 1;
4168 int oom, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169
4170 dprintk(KERN_DEBUG "nv_open: begin\n");
4171
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004172 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004173 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4174 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4176 writel(0, base + NvRegMulticastAddrB);
4177 writel(0, base + NvRegMulticastMaskA);
4178 writel(0, base + NvRegMulticastMaskB);
4179 writel(0, base + NvRegPacketFilterFlags);
4180
4181 writel(0, base + NvRegTransmitterControl);
4182 writel(0, base + NvRegReceiverControl);
4183
4184 writel(0, base + NvRegAdapterControl);
4185
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004186 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
4187 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
4188
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004189 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02004190 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 oom = nv_init_ring(dev);
4192
4193 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004194 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 nv_txrx_reset(dev);
4196 writel(0, base + NvRegUnknownSetupReg6);
4197
4198 np->in_shutdown = 0;
4199
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004200 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05004201 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004202 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 base + NvRegRingSizes);
4204
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04004206 if (np->desc_ver == DESC_VER_1)
4207 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
4208 else
4209 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004210 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004211 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004213 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
4215 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
4216 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
4217
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004218 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4220 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
4221
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
4223 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
4224 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02004225 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226
4227 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
4228 get_random_bytes(&i, sizeof(i));
4229 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed);
Ayaz Abdulla9744e212006-07-06 16:45:58 -04004230 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
4231 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004232 if (poll_interval == -1) {
4233 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
4234 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
4235 else
4236 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4237 }
4238 else
4239 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4241 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
4242 base + NvRegAdapterControl);
4243 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004244 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004245 if (np->wolenabled)
4246 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247
4248 i = readl(base + NvRegPowerState);
4249 if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0)
4250 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
4251
4252 pci_push(base);
4253 udelay(10);
4254 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
4255
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004256 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 pci_push(base);
4258 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
4259 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4260 pci_push(base);
4261
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004262 if (nv_request_irq(dev, 0)) {
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004263 goto out_drain;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265
4266 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004267 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268
4269 spin_lock_irq(&np->lock);
4270 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4271 writel(0, base + NvRegMulticastAddrB);
4272 writel(0, base + NvRegMulticastMaskA);
4273 writel(0, base + NvRegMulticastMaskB);
4274 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
4275 /* One manual link speed update: Interrupts are enabled, future link
4276 * speed changes cause interrupts and are handled by nv_link_irq().
4277 */
4278 {
4279 u32 miistat;
4280 miistat = readl(base + NvRegMIIStatus);
4281 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
4282 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
4283 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02004284 /* set linkspeed to invalid value, thus force nv_update_linkspeed
4285 * to init hw */
4286 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 ret = nv_update_linkspeed(dev);
4288 nv_start_rx(dev);
4289 nv_start_tx(dev);
4290 netif_start_queue(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004291 netif_poll_enable(dev);
4292
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 if (ret) {
4294 netif_carrier_on(dev);
4295 } else {
4296 printk("%s: no link during initialization.\n", dev->name);
4297 netif_carrier_off(dev);
4298 }
4299 if (oom)
4300 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004301
4302 /* start statistics timer */
4303 if (np->driver_data & DEV_HAS_STATISTICS)
4304 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
4305
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 spin_unlock_irq(&np->lock);
4307
4308 return 0;
4309out_drain:
4310 drain_ring(dev);
4311 return ret;
4312}
4313
4314static int nv_close(struct net_device *dev)
4315{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004316 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 u8 __iomem *base;
4318
4319 spin_lock_irq(&np->lock);
4320 np->in_shutdown = 1;
4321 spin_unlock_irq(&np->lock);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004322 netif_poll_disable(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 synchronize_irq(dev->irq);
4324
4325 del_timer_sync(&np->oom_kick);
4326 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004327 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328
4329 netif_stop_queue(dev);
4330 spin_lock_irq(&np->lock);
4331 nv_stop_tx(dev);
4332 nv_stop_rx(dev);
4333 nv_txrx_reset(dev);
4334
4335 /* disable interrupts on the nic or we will lock up */
4336 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004337 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 pci_push(base);
4339 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
4340
4341 spin_unlock_irq(&np->lock);
4342
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004343 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344
4345 drain_ring(dev);
4346
4347 if (np->wolenabled)
4348 nv_start_rx(dev);
4349
4350 /* FIXME: power down nic */
4351
4352 return 0;
4353}
4354
4355static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
4356{
4357 struct net_device *dev;
4358 struct fe_priv *np;
4359 unsigned long addr;
4360 u8 __iomem *base;
4361 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004362 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004363 u32 phystate_orig = 0, phystate;
4364 int phyinitialized = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365
4366 dev = alloc_etherdev(sizeof(struct fe_priv));
4367 err = -ENOMEM;
4368 if (!dev)
4369 goto out;
4370
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004371 np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 np->pci_dev = pci_dev;
4373 spin_lock_init(&np->lock);
4374 SET_MODULE_OWNER(dev);
4375 SET_NETDEV_DEV(dev, &pci_dev->dev);
4376
4377 init_timer(&np->oom_kick);
4378 np->oom_kick.data = (unsigned long) dev;
4379 np->oom_kick.function = &nv_do_rx_refill; /* timer handler */
4380 init_timer(&np->nic_poll);
4381 np->nic_poll.data = (unsigned long) dev;
4382 np->nic_poll.function = &nv_do_nic_poll; /* timer handler */
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004383 init_timer(&np->stats_poll);
4384 np->stats_poll.data = (unsigned long) dev;
4385 np->stats_poll.function = &nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386
4387 err = pci_enable_device(pci_dev);
4388 if (err) {
4389 printk(KERN_INFO "forcedeth: pci_enable_dev failed (%d) for device %s\n",
4390 err, pci_name(pci_dev));
4391 goto out_free;
4392 }
4393
4394 pci_set_master(pci_dev);
4395
4396 err = pci_request_regions(pci_dev, DRV_NAME);
4397 if (err < 0)
4398 goto out_disable;
4399
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004400 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 -04004401 np->register_size = NV_PCI_REGSZ_VER2;
4402 else
4403 np->register_size = NV_PCI_REGSZ_VER1;
4404
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 err = -EINVAL;
4406 addr = 0;
4407 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
4408 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
4409 pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i),
4410 pci_resource_len(pci_dev, i),
4411 pci_resource_flags(pci_dev, i));
4412 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004413 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 addr = pci_resource_start(pci_dev, i);
4415 break;
4416 }
4417 }
4418 if (i == DEVICE_COUNT_RESOURCE) {
4419 printk(KERN_INFO "forcedeth: Couldn't find register window for device %s.\n",
4420 pci_name(pci_dev));
4421 goto out_relreg;
4422 }
4423
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004424 /* copy of driver data */
4425 np->driver_data = id->driver_data;
4426
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02004428 if (id->driver_data & DEV_HAS_HIGH_DMA) {
4429 /* packet format 3: supports 40-bit addressing */
4430 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004431 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04004432 if (dma_64bit) {
4433 if (pci_set_dma_mask(pci_dev, DMA_39BIT_MASK)) {
4434 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n",
4435 pci_name(pci_dev));
4436 } else {
4437 dev->features |= NETIF_F_HIGHDMA;
4438 printk(KERN_INFO "forcedeth: using HIGHDMA\n");
4439 }
4440 if (pci_set_consistent_dma_mask(pci_dev, DMA_39BIT_MASK)) {
4441 printk(KERN_INFO "forcedeth: 64-bit DMA (consistent) failed, using 32-bit ring buffers for device %s.\n",
4442 pci_name(pci_dev));
4443 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004444 }
Manfred Spraulee733622005-07-31 18:32:26 +02004445 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
4446 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004448 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02004449 } else {
4450 /* original packet format */
4451 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004452 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02004453 }
Manfred Spraulee733622005-07-31 18:32:26 +02004454
4455 np->pkt_limit = NV_PKTLIMIT_1;
4456 if (id->driver_data & DEV_HAS_LARGEDESC)
4457 np->pkt_limit = NV_PKTLIMIT_2;
4458
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004459 if (id->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004460 np->rx_csum = 1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004461 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004462 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
4463#ifdef NETIF_F_TSO
Ayaz Abdullafa454592006-01-05 22:45:45 -08004464 dev->features |= NETIF_F_TSO;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004465#endif
4466 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004467
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004468 np->vlanctl_bits = 0;
4469 if (id->driver_data & DEV_HAS_VLAN) {
4470 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
4471 dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
4472 dev->vlan_rx_register = nv_vlan_rx_register;
4473 dev->vlan_rx_kill_vid = nv_vlan_rx_kill_vid;
4474 }
4475
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004476 np->msi_flags = 0;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04004477 if ((id->driver_data & DEV_HAS_MSI) && msi) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004478 np->msi_flags |= NV_MSI_CAPABLE;
4479 }
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04004480 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004481 np->msi_flags |= NV_MSI_X_CAPABLE;
4482 }
4483
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004484 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004485 if (id->driver_data & DEV_HAS_PAUSEFRAME_TX) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004486 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004487 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04004488
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004489
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004491 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492 if (!np->base)
4493 goto out_relreg;
4494 dev->base_addr = (unsigned long)np->base;
Manfred Spraulee733622005-07-31 18:32:26 +02004495
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 dev->irq = pci_dev->irq;
Manfred Spraulee733622005-07-31 18:32:26 +02004497
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004498 np->rx_ring_size = RX_RING_DEFAULT;
4499 np->tx_ring_size = TX_RING_DEFAULT;
4500 np->tx_limit_stop = np->tx_ring_size - TX_LIMIT_DIFFERENCE;
4501 np->tx_limit_start = np->tx_ring_size - TX_LIMIT_DIFFERENCE - 1;
4502
Manfred Spraulee733622005-07-31 18:32:26 +02004503 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
4504 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004505 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02004506 &np->ring_addr);
4507 if (!np->rx_ring.orig)
4508 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004509 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02004510 } else {
4511 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004512 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02004513 &np->ring_addr);
4514 if (!np->rx_ring.ex)
4515 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004516 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02004517 }
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004518 np->rx_skbuff = kmalloc(sizeof(struct sk_buff*) * np->rx_ring_size, GFP_KERNEL);
4519 np->rx_dma = kmalloc(sizeof(dma_addr_t) * np->rx_ring_size, GFP_KERNEL);
4520 np->tx_skbuff = kmalloc(sizeof(struct sk_buff*) * np->tx_ring_size, GFP_KERNEL);
4521 np->tx_dma = kmalloc(sizeof(dma_addr_t) * np->tx_ring_size, GFP_KERNEL);
4522 np->tx_dma_len = kmalloc(sizeof(unsigned int) * np->tx_ring_size, GFP_KERNEL);
4523 if (!np->rx_skbuff || !np->rx_dma || !np->tx_skbuff || !np->tx_dma || !np->tx_dma_len)
4524 goto out_freering;
4525 memset(np->rx_skbuff, 0, sizeof(struct sk_buff*) * np->rx_ring_size);
4526 memset(np->rx_dma, 0, sizeof(dma_addr_t) * np->rx_ring_size);
4527 memset(np->tx_skbuff, 0, sizeof(struct sk_buff*) * np->tx_ring_size);
4528 memset(np->tx_dma, 0, sizeof(dma_addr_t) * np->tx_ring_size);
4529 memset(np->tx_dma_len, 0, sizeof(unsigned int) * np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530
4531 dev->open = nv_open;
4532 dev->stop = nv_close;
4533 dev->hard_start_xmit = nv_start_xmit;
4534 dev->get_stats = nv_get_stats;
4535 dev->change_mtu = nv_change_mtu;
Manfred Spraul72b31782005-07-31 18:33:34 +02004536 dev->set_mac_address = nv_set_mac_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 dev->set_multicast_list = nv_set_multicast;
Michal Schmidt2918c352005-05-12 19:42:06 -04004538#ifdef CONFIG_NET_POLL_CONTROLLER
4539 dev->poll_controller = nv_poll_controller;
4540#endif
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004541 dev->weight = 64;
4542#ifdef CONFIG_FORCEDETH_NAPI
4543 dev->poll = nv_napi_poll;
4544#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 SET_ETHTOOL_OPS(dev, &ops);
4546 dev->tx_timeout = nv_tx_timeout;
4547 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
4548
4549 pci_set_drvdata(pci_dev, dev);
4550
4551 /* read the mac address */
4552 base = get_hwbase(dev);
4553 np->orig_mac[0] = readl(base + NvRegMacAddrA);
4554 np->orig_mac[1] = readl(base + NvRegMacAddrB);
4555
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004556 /* check the workaround bit for correct mac address order */
4557 txreg = readl(base + NvRegTransmitPoll);
4558 if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
4559 /* mac address is already in correct order */
4560 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
4561 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
4562 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
4563 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
4564 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
4565 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
4566 } else {
4567 /* need to reverse mac address to correct order */
4568 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
4569 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
4570 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
4571 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
4572 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
4573 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
4574 /* set permanent address to be correct aswell */
4575 np->orig_mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
4576 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
4577 np->orig_mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
4578 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
4579 }
John W. Linvillec704b852005-09-12 10:48:56 -04004580 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581
John W. Linvillec704b852005-09-12 10:48:56 -04004582 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583 /*
4584 * Bad mac address. At least one bios sets the mac address
4585 * to 01:23:45:67:89:ab
4586 */
4587 printk(KERN_ERR "%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n",
4588 pci_name(pci_dev),
4589 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
4590 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
4591 printk(KERN_ERR "Please complain to your hardware vendor. Switching to a random MAC.\n");
4592 dev->dev_addr[0] = 0x00;
4593 dev->dev_addr[1] = 0x00;
4594 dev->dev_addr[2] = 0x6c;
4595 get_random_bytes(&dev->dev_addr[3], 3);
4596 }
4597
4598 dprintk(KERN_DEBUG "%s: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", pci_name(pci_dev),
4599 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
4600 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
4601
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004602 /* set mac address */
4603 nv_copy_mac_to_hw(dev);
4604
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 /* disable WOL */
4606 writel(0, base + NvRegWakeUpFlags);
4607 np->wolenabled = 0;
4608
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004609 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
4610 u8 revision_id;
4611 pci_read_config_byte(pci_dev, PCI_REVISION_ID, &revision_id);
4612
4613 /* take phy and nic out of low power mode */
4614 powerstate = readl(base + NvRegPowerState2);
4615 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
4616 if ((id->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 ||
4617 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_13) &&
4618 revision_id >= 0xA3)
4619 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
4620 writel(powerstate, base + NvRegPowerState2);
4621 }
4622
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004624 np->tx_flags = NV_TX_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 } else {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004626 np->tx_flags = NV_TX2_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004628 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004629 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004630 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
4631 np->msi_flags |= 0x0003;
4632 } else {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004633 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004634 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
4635 np->msi_flags |= 0x0001;
4636 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004637
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 if (id->driver_data & DEV_NEED_TIMERIRQ)
4639 np->irqmask |= NVREG_IRQ_TIMER;
4640 if (id->driver_data & DEV_NEED_LINKTIMER) {
4641 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
4642 np->need_linktimer = 1;
4643 np->link_timeout = jiffies + LINK_TIMEOUT;
4644 } else {
4645 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
4646 np->need_linktimer = 0;
4647 }
4648
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004649 /* clear phy state and temporarily halt phy interrupts */
4650 writel(0, base + NvRegMIIMask);
4651 phystate = readl(base + NvRegAdapterControl);
4652 if (phystate & NVREG_ADAPTCTL_RUNNING) {
4653 phystate_orig = 1;
4654 phystate &= ~NVREG_ADAPTCTL_RUNNING;
4655 writel(phystate, base + NvRegAdapterControl);
4656 }
4657 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
4658
4659 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
4660 writel(0x1, base + 0x204); pci_push(base);
4661 msleep(500);
4662 /* management unit running on the mac? */
4663 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST;
4664 if (np->mac_in_use) {
4665 u32 mgmt_sync;
4666 /* management unit setup the phy already? */
4667 mgmt_sync = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK;
4668 if (mgmt_sync == NVREG_XMITCTL_SYNC_NOT_READY) {
4669 if (!nv_mgmt_acquire_sema(dev)) {
4670 for (i = 0; i < 5000; i++) {
4671 msleep(1);
4672 mgmt_sync = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK;
4673 if (mgmt_sync == NVREG_XMITCTL_SYNC_NOT_READY)
4674 continue;
4675 if (mgmt_sync == NVREG_XMITCTL_SYNC_PHY_INIT)
4676 phyinitialized = 1;
4677 break;
4678 }
4679 } else {
4680 /* we need to init the phy */
4681 }
4682 } else if (mgmt_sync == NVREG_XMITCTL_SYNC_PHY_INIT) {
4683 /* phy is inited by SMU */
4684 phyinitialized = 1;
4685 } else {
4686 /* we need to init the phy */
4687 }
4688 }
4689 }
4690
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004692 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004694 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695
4696 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004697 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 spin_unlock_irq(&np->lock);
4699 if (id1 < 0 || id1 == 0xffff)
4700 continue;
4701 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004702 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 spin_unlock_irq(&np->lock);
4704 if (id2 < 0 || id2 == 0xffff)
4705 continue;
4706
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004707 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
4709 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
4710 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004711 pci_name(pci_dev), id1, id2, phyaddr);
4712 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 np->phy_oui = id1 | id2;
4714 break;
4715 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004716 if (i == 33) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717 printk(KERN_INFO "%s: open: Could not find a valid PHY.\n",
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05004718 pci_name(pci_dev));
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004719 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04004721
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004722 if (!phyinitialized) {
4723 /* reset it */
4724 phy_init(dev);
4725 }
4726
4727 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
4728 nv_mgmt_driver_loaded(dev, 1);
4729 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730
4731 /* set default link speed settings */
4732 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
4733 np->duplex = 0;
4734 np->autoneg = 1;
4735
4736 err = register_netdev(dev);
4737 if (err) {
4738 printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004739 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 }
4741 printk(KERN_INFO "%s: forcedeth.c: subsystem: %05x:%04x bound to %s\n",
4742 dev->name, pci_dev->subsystem_vendor, pci_dev->subsystem_device,
4743 pci_name(pci_dev));
4744
4745 return 0;
4746
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004747out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004748 if (phystate_orig)
4749 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
4750 if (np->mac_in_use)
4751 nv_mgmt_driver_loaded(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004753out_freering:
4754 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755out_unmap:
4756 iounmap(get_hwbase(dev));
4757out_relreg:
4758 pci_release_regions(pci_dev);
4759out_disable:
4760 pci_disable_device(pci_dev);
4761out_free:
4762 free_netdev(dev);
4763out:
4764 return err;
4765}
4766
4767static void __devexit nv_remove(struct pci_dev *pci_dev)
4768{
4769 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004770 struct fe_priv *np = netdev_priv(dev);
4771 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772
4773 unregister_netdev(dev);
4774
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004775 /* special op: write back the misordered MAC address - otherwise
4776 * the next nv_probe would see a wrong address.
4777 */
4778 writel(np->orig_mac[0], base + NvRegMacAddrA);
4779 writel(np->orig_mac[1], base + NvRegMacAddrB);
4780
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004781 if (np->mac_in_use)
4782 nv_mgmt_driver_loaded(dev, 0);
4783
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004785 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 iounmap(get_hwbase(dev));
4787 pci_release_regions(pci_dev);
4788 pci_disable_device(pci_dev);
4789 free_netdev(dev);
4790 pci_set_drvdata(pci_dev, NULL);
4791}
4792
Francois Romieua1893172006-10-10 14:33:27 -07004793#ifdef CONFIG_PM
4794static int nv_suspend(struct pci_dev *pdev, pm_message_t state)
4795{
4796 struct net_device *dev = pci_get_drvdata(pdev);
4797 struct fe_priv *np = netdev_priv(dev);
4798
4799 if (!netif_running(dev))
4800 goto out;
4801
4802 netif_device_detach(dev);
4803
4804 // Gross.
4805 nv_close(dev);
4806
4807 pci_save_state(pdev);
4808 pci_enable_wake(pdev, pci_choose_state(pdev, state), np->wolenabled);
4809 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4810out:
4811 return 0;
4812}
4813
4814static int nv_resume(struct pci_dev *pdev)
4815{
4816 struct net_device *dev = pci_get_drvdata(pdev);
4817 int rc = 0;
4818
4819 if (!netif_running(dev))
4820 goto out;
4821
4822 netif_device_attach(dev);
4823
4824 pci_set_power_state(pdev, PCI_D0);
4825 pci_restore_state(pdev);
4826 pci_enable_wake(pdev, PCI_D0, 0);
4827
4828 rc = nv_open(dev);
4829out:
4830 return rc;
4831}
4832#else
4833#define nv_suspend NULL
4834#define nv_resume NULL
4835#endif /* CONFIG_PM */
4836
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837static struct pci_device_id pci_tbl[] = {
4838 { /* nForce Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004839 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1),
Manfred Spraulc2dba062005-07-31 18:29:47 +02004840 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 },
4842 { /* nForce2 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004843 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2),
Manfred Spraulc2dba062005-07-31 18:29:47 +02004844 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 },
4846 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004847 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02004848 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849 },
4850 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004851 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004852 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853 },
4854 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004855 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004856 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 },
4858 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004859 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004860 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 },
4862 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004863 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004864 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 },
4866 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004867 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004868 .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 -07004869 },
4870 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004871 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004872 .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 -07004873 },
4874 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004875 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004876 .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 -07004877 },
4878 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004879 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004880 .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 +02004881 },
4882 { /* MCP51 Ethernet Controller */
4883 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004884 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02004886 { /* MCP51 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004887 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13),
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004888 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
Manfred Spraul9992d4a2005-06-05 17:36:11 +02004889 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02004890 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004891 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004892 .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 +02004893 },
4894 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004895 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004896 .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 +02004897 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04004898 { /* MCP61 Ethernet Controller */
4899 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_16),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004900 .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 -04004901 },
4902 { /* MCP61 Ethernet Controller */
4903 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_17),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004904 .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 -04004905 },
4906 { /* MCP61 Ethernet Controller */
4907 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_18),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004908 .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 -04004909 },
4910 { /* MCP61 Ethernet Controller */
4911 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_19),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004912 .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 -04004913 },
4914 { /* MCP65 Ethernet Controller */
4915 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004916 .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 -04004917 },
4918 { /* MCP65 Ethernet Controller */
4919 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004920 .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 -04004921 },
4922 { /* MCP65 Ethernet Controller */
4923 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004924 .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 -04004925 },
4926 { /* MCP65 Ethernet Controller */
4927 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004928 .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 -04004929 },
Ayaz Abdullaf4344842006-11-06 00:43:40 -08004930 { /* MCP67 Ethernet Controller */
4931 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24),
4932 .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,
4933 },
4934 { /* MCP67 Ethernet Controller */
4935 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_25),
4936 .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,
4937 },
4938 { /* MCP67 Ethernet Controller */
4939 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_26),
4940 .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,
4941 },
4942 { /* MCP67 Ethernet Controller */
4943 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27),
4944 .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,
4945 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946 {0,},
4947};
4948
4949static struct pci_driver driver = {
4950 .name = "forcedeth",
4951 .id_table = pci_tbl,
4952 .probe = nv_probe,
4953 .remove = __devexit_p(nv_remove),
Francois Romieua1893172006-10-10 14:33:27 -07004954 .suspend = nv_suspend,
4955 .resume = nv_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956};
4957
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958static int __init init_nic(void)
4959{
4960 printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION);
Jeff Garzik29917622006-08-19 17:48:59 -04004961 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962}
4963
4964static void __exit exit_nic(void)
4965{
4966 pci_unregister_driver(&driver);
4967}
4968
4969module_param(max_interrupt_work, int, 0);
4970MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004971module_param(optimization_mode, int, 0);
4972MODULE_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.");
4973module_param(poll_interval, int, 0);
4974MODULE_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 -04004975module_param(msi, int, 0);
4976MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
4977module_param(msix, int, 0);
4978MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
4979module_param(dma_64bit, int, 0);
4980MODULE_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 -07004981
4982MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
4983MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
4984MODULE_LICENSE("GPL");
4985
4986MODULE_DEVICE_TABLE(pci, pci_tbl);
4987
4988module_init(init_nic);
4989module_exit(exit_nic);