blob: 731d0d7b2f37bccf0e99d488be1149ff192661c0 [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 *
13 * Copyright (C) 2003,4 Manfred Spraul
14 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 *
103 * Known bugs:
104 * We suspect that on some hardware no TX done interrupts are generated.
105 * This means recovery from netif_stop_queue only happens if the hw timer
106 * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
107 * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
108 * If your hardware reliably generates tx done interrupts, then you can remove
109 * DEV_NEED_TIMERIRQ from the driver_data flags.
110 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
111 * superfluous timer interrupts from the nic.
112 */
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500113#define FORCEDETH_VERSION "0.46"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define DRV_NAME "forcedeth"
115
116#include <linux/module.h>
117#include <linux/types.h>
118#include <linux/pci.h>
119#include <linux/interrupt.h>
120#include <linux/netdevice.h>
121#include <linux/etherdevice.h>
122#include <linux/delay.h>
123#include <linux/spinlock.h>
124#include <linux/ethtool.h>
125#include <linux/timer.h>
126#include <linux/skbuff.h>
127#include <linux/mii.h>
128#include <linux/random.h>
129#include <linux/init.h>
Manfred Spraul22c6d142005-04-19 21:17:09 +0200130#include <linux/if_vlan.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132#include <asm/irq.h>
133#include <asm/io.h>
134#include <asm/uaccess.h>
135#include <asm/system.h>
136
137#if 0
138#define dprintk printk
139#else
140#define dprintk(x...) do { } while (0)
141#endif
142
143
144/*
145 * Hardware access:
146 */
147
Manfred Spraulc2dba062005-07-31 18:29:47 +0200148#define DEV_NEED_TIMERIRQ 0x0001 /* set the timer irq flag in the irq mask */
149#define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */
150#define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */
Manfred Spraulee733622005-07-31 18:32:26 +0200151#define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400152#define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154enum {
155 NvRegIrqStatus = 0x000,
156#define NVREG_IRQSTAT_MIIEVENT 0x040
157#define NVREG_IRQSTAT_MASK 0x1ff
158 NvRegIrqMask = 0x004,
159#define NVREG_IRQ_RX_ERROR 0x0001
160#define NVREG_IRQ_RX 0x0002
161#define NVREG_IRQ_RX_NOBUF 0x0004
162#define NVREG_IRQ_TX_ERR 0x0008
Manfred Spraulc2dba062005-07-31 18:29:47 +0200163#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#define NVREG_IRQ_TIMER 0x0020
165#define NVREG_IRQ_LINK 0x0040
Manfred Spraulc2dba062005-07-31 18:29:47 +0200166#define NVREG_IRQ_TX_ERROR 0x0080
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#define NVREG_IRQ_TX1 0x0100
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500168#define NVREG_IRQMASK_THROUGHPUT 0x00df
169#define NVREG_IRQMASK_CPU 0x0040
Manfred Spraulc2dba062005-07-31 18:29:47 +0200170
171#define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \
172 NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_TX_ERROR| \
173 NVREG_IRQ_TX1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 NvRegUnknownSetupReg6 = 0x008,
176#define NVREG_UNKSETUP6_VAL 3
177
178/*
179 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
180 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
181 */
182 NvRegPollingInterval = 0x00c,
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500183#define NVREG_POLL_DEFAULT_THROUGHPUT 970
184#define NVREG_POLL_DEFAULT_CPU 13
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 NvRegMisc1 = 0x080,
186#define NVREG_MISC1_HD 0x02
187#define NVREG_MISC1_FORCE 0x3b0f3c
188
189 NvRegTransmitterControl = 0x084,
190#define NVREG_XMITCTL_START 0x01
191 NvRegTransmitterStatus = 0x088,
192#define NVREG_XMITSTAT_BUSY 0x01
193
194 NvRegPacketFilterFlags = 0x8c,
195#define NVREG_PFF_ALWAYS 0x7F0008
196#define NVREG_PFF_PROMISC 0x80
197#define NVREG_PFF_MYADDR 0x20
198
199 NvRegOffloadConfig = 0x90,
200#define NVREG_OFFLOAD_HOMEPHY 0x601
201#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
202 NvRegReceiverControl = 0x094,
203#define NVREG_RCVCTL_START 0x01
204 NvRegReceiverStatus = 0x98,
205#define NVREG_RCVSTAT_BUSY 0x01
206
207 NvRegRandomSeed = 0x9c,
208#define NVREG_RNDSEED_MASK 0x00ff
209#define NVREG_RNDSEED_FORCE 0x7f00
210#define NVREG_RNDSEED_FORCE2 0x2d00
211#define NVREG_RNDSEED_FORCE3 0x7400
212
213 NvRegUnknownSetupReg1 = 0xA0,
214#define NVREG_UNKSETUP1_VAL 0x16070f
215 NvRegUnknownSetupReg2 = 0xA4,
216#define NVREG_UNKSETUP2_VAL 0x16
217 NvRegMacAddrA = 0xA8,
218 NvRegMacAddrB = 0xAC,
219 NvRegMulticastAddrA = 0xB0,
220#define NVREG_MCASTADDRA_FORCE 0x01
221 NvRegMulticastAddrB = 0xB4,
222 NvRegMulticastMaskA = 0xB8,
223 NvRegMulticastMaskB = 0xBC,
224
225 NvRegPhyInterface = 0xC0,
226#define PHY_RGMII 0x10000000
227
228 NvRegTxRingPhysAddr = 0x100,
229 NvRegRxRingPhysAddr = 0x104,
230 NvRegRingSizes = 0x108,
231#define NVREG_RINGSZ_TXSHIFT 0
232#define NVREG_RINGSZ_RXSHIFT 16
233 NvRegUnknownTransmitterReg = 0x10c,
234 NvRegLinkSpeed = 0x110,
235#define NVREG_LINKSPEED_FORCE 0x10000
236#define NVREG_LINKSPEED_10 1000
237#define NVREG_LINKSPEED_100 100
238#define NVREG_LINKSPEED_1000 50
239#define NVREG_LINKSPEED_MASK (0xFFF)
240 NvRegUnknownSetupReg5 = 0x130,
241#define NVREG_UNKSETUP5_BIT31 (1<<31)
242 NvRegUnknownSetupReg3 = 0x13c,
243#define NVREG_UNKSETUP3_VAL1 0x200010
244 NvRegTxRxControl = 0x144,
245#define NVREG_TXRXCTL_KICK 0x0001
246#define NVREG_TXRXCTL_BIT1 0x0002
247#define NVREG_TXRXCTL_BIT2 0x0004
248#define NVREG_TXRXCTL_IDLE 0x0008
249#define NVREG_TXRXCTL_RESET 0x0010
250#define NVREG_TXRXCTL_RXCHECK 0x0400
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400251#define NVREG_TXRXCTL_DESC_1 0
252#define NVREG_TXRXCTL_DESC_2 0x02100
253#define NVREG_TXRXCTL_DESC_3 0x02200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 NvRegMIIStatus = 0x180,
255#define NVREG_MIISTAT_ERROR 0x0001
256#define NVREG_MIISTAT_LINKCHANGE 0x0008
257#define NVREG_MIISTAT_MASK 0x000f
258#define NVREG_MIISTAT_MASK2 0x000f
259 NvRegUnknownSetupReg4 = 0x184,
260#define NVREG_UNKSETUP4_VAL 8
261
262 NvRegAdapterControl = 0x188,
263#define NVREG_ADAPTCTL_START 0x02
264#define NVREG_ADAPTCTL_LINKUP 0x04
265#define NVREG_ADAPTCTL_PHYVALID 0x40000
266#define NVREG_ADAPTCTL_RUNNING 0x100000
267#define NVREG_ADAPTCTL_PHYSHIFT 24
268 NvRegMIISpeed = 0x18c,
269#define NVREG_MIISPEED_BIT8 (1<<8)
270#define NVREG_MIIDELAY 5
271 NvRegMIIControl = 0x190,
272#define NVREG_MIICTL_INUSE 0x08000
273#define NVREG_MIICTL_WRITE 0x00400
274#define NVREG_MIICTL_ADDRSHIFT 5
275 NvRegMIIData = 0x194,
276 NvRegWakeUpFlags = 0x200,
277#define NVREG_WAKEUPFLAGS_VAL 0x7770
278#define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
279#define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
280#define NVREG_WAKEUPFLAGS_D3SHIFT 12
281#define NVREG_WAKEUPFLAGS_D2SHIFT 8
282#define NVREG_WAKEUPFLAGS_D1SHIFT 4
283#define NVREG_WAKEUPFLAGS_D0SHIFT 0
284#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
285#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
286#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
287#define NVREG_WAKEUPFLAGS_ENABLE 0x1111
288
289 NvRegPatternCRC = 0x204,
290 NvRegPatternMask = 0x208,
291 NvRegPowerCap = 0x268,
292#define NVREG_POWERCAP_D3SUPP (1<<30)
293#define NVREG_POWERCAP_D2SUPP (1<<26)
294#define NVREG_POWERCAP_D1SUPP (1<<25)
295 NvRegPowerState = 0x26c,
296#define NVREG_POWERSTATE_POWEREDUP 0x8000
297#define NVREG_POWERSTATE_VALID 0x0100
298#define NVREG_POWERSTATE_MASK 0x0003
299#define NVREG_POWERSTATE_D0 0x0000
300#define NVREG_POWERSTATE_D1 0x0001
301#define NVREG_POWERSTATE_D2 0x0002
302#define NVREG_POWERSTATE_D3 0x0003
303};
304
305/* Big endian: should work, but is untested */
306struct ring_desc {
307 u32 PacketBuffer;
308 u32 FlagLen;
309};
310
Manfred Spraulee733622005-07-31 18:32:26 +0200311struct ring_desc_ex {
312 u32 PacketBufferHigh;
313 u32 PacketBufferLow;
314 u32 Reserved;
315 u32 FlagLen;
316};
317
318typedef union _ring_type {
319 struct ring_desc* orig;
320 struct ring_desc_ex* ex;
321} ring_type;
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#define FLAG_MASK_V1 0xffff0000
324#define FLAG_MASK_V2 0xffffc000
325#define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
326#define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
327
328#define NV_TX_LASTPACKET (1<<16)
329#define NV_TX_RETRYERROR (1<<19)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200330#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331#define NV_TX_DEFERRED (1<<26)
332#define NV_TX_CARRIERLOST (1<<27)
333#define NV_TX_LATECOLLISION (1<<28)
334#define NV_TX_UNDERFLOW (1<<29)
335#define NV_TX_ERROR (1<<30)
336#define NV_TX_VALID (1<<31)
337
338#define NV_TX2_LASTPACKET (1<<29)
339#define NV_TX2_RETRYERROR (1<<18)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200340#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#define NV_TX2_DEFERRED (1<<25)
342#define NV_TX2_CARRIERLOST (1<<26)
343#define NV_TX2_LATECOLLISION (1<<27)
344#define NV_TX2_UNDERFLOW (1<<28)
345/* error and valid are the same for both */
346#define NV_TX2_ERROR (1<<30)
347#define NV_TX2_VALID (1<<31)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400348#define NV_TX2_TSO (1<<28)
349#define NV_TX2_TSO_SHIFT 14
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400350#define NV_TX2_CHECKSUM_L3 (1<<27)
351#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353#define NV_RX_DESCRIPTORVALID (1<<16)
354#define NV_RX_MISSEDFRAME (1<<17)
355#define NV_RX_SUBSTRACT1 (1<<18)
356#define NV_RX_ERROR1 (1<<23)
357#define NV_RX_ERROR2 (1<<24)
358#define NV_RX_ERROR3 (1<<25)
359#define NV_RX_ERROR4 (1<<26)
360#define NV_RX_CRCERR (1<<27)
361#define NV_RX_OVERFLOW (1<<28)
362#define NV_RX_FRAMINGERR (1<<29)
363#define NV_RX_ERROR (1<<30)
364#define NV_RX_AVAIL (1<<31)
365
366#define NV_RX2_CHECKSUMMASK (0x1C000000)
367#define NV_RX2_CHECKSUMOK1 (0x10000000)
368#define NV_RX2_CHECKSUMOK2 (0x14000000)
369#define NV_RX2_CHECKSUMOK3 (0x18000000)
370#define NV_RX2_DESCRIPTORVALID (1<<29)
371#define NV_RX2_SUBSTRACT1 (1<<25)
372#define NV_RX2_ERROR1 (1<<18)
373#define NV_RX2_ERROR2 (1<<19)
374#define NV_RX2_ERROR3 (1<<20)
375#define NV_RX2_ERROR4 (1<<21)
376#define NV_RX2_CRCERR (1<<22)
377#define NV_RX2_OVERFLOW (1<<23)
378#define NV_RX2_FRAMINGERR (1<<24)
379/* error and avail are the same for both */
380#define NV_RX2_ERROR (1<<30)
381#define NV_RX2_AVAIL (1<<31)
382
383/* Miscelaneous hardware related defines: */
384#define NV_PCI_REGSZ 0x270
385
386/* various timeout delays: all in usec */
387#define NV_TXRX_RESET_DELAY 4
388#define NV_TXSTOP_DELAY1 10
389#define NV_TXSTOP_DELAY1MAX 500000
390#define NV_TXSTOP_DELAY2 100
391#define NV_RXSTOP_DELAY1 10
392#define NV_RXSTOP_DELAY1MAX 500000
393#define NV_RXSTOP_DELAY2 100
394#define NV_SETUP5_DELAY 5
395#define NV_SETUP5_DELAYMAX 50000
396#define NV_POWERUP_DELAY 5
397#define NV_POWERUP_DELAYMAX 5000
398#define NV_MIIBUSY_DELAY 50
399#define NV_MIIPHY_DELAY 10
400#define NV_MIIPHY_DELAYMAX 10000
401
402#define NV_WAKEUPPATTERNS 5
403#define NV_WAKEUPMASKENTRIES 4
404
405/* General driver defaults */
406#define NV_WATCHDOG_TIMEO (5*HZ)
407
408#define RX_RING 128
409#define TX_RING 64
410/*
411 * If your nic mysteriously hangs then try to reduce the limits
412 * to 1/0: It might be required to set NV_TX_LASTPACKET in the
413 * last valid ring entry. But this would be impossible to
414 * implement - probably a disassembly error.
415 */
416#define TX_LIMIT_STOP 63
417#define TX_LIMIT_START 62
418
419/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200420#define NV_RX_HEADERS (64)
421/* even more slack. */
422#define NV_RX_ALLOC_PAD (64)
423
424/* maximum mtu size */
425#define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
426#define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428#define OOM_REFILL (1+HZ/20)
429#define POLL_WAIT (1+HZ/100)
430#define LINK_TIMEOUT (3*HZ)
431
432/*
433 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400434 * The nic supports three different descriptor types:
435 * - DESC_VER_1: Original
436 * - DESC_VER_2: support for jumbo frames.
437 * - DESC_VER_3: 64-bit format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400439#define DESC_VER_1 1
440#define DESC_VER_2 2
441#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443/* PHY defines */
444#define PHY_OUI_MARVELL 0x5043
445#define PHY_OUI_CICADA 0x03f1
446#define PHYID1_OUI_MASK 0x03ff
447#define PHYID1_OUI_SHFT 6
448#define PHYID2_OUI_MASK 0xfc00
449#define PHYID2_OUI_SHFT 10
450#define PHY_INIT1 0x0f000
451#define PHY_INIT2 0x0e00
452#define PHY_INIT3 0x01000
453#define PHY_INIT4 0x0200
454#define PHY_INIT5 0x0004
455#define PHY_INIT6 0x02000
456#define PHY_GIGABIT 0x0100
457
458#define PHY_TIMEOUT 0x1
459#define PHY_ERROR 0x2
460
461#define PHY_100 0x1
462#define PHY_1000 0x2
463#define PHY_HALF 0x100
464
465/* FIXME: MII defines that should be added to <linux/mii.h> */
466#define MII_1000BT_CR 0x09
467#define MII_1000BT_SR 0x0a
468#define ADVERTISE_1000FULL 0x0200
469#define ADVERTISE_1000HALF 0x0100
470#define LPA_1000FULL 0x0800
471#define LPA_1000HALF 0x0400
472
473
474/*
475 * SMP locking:
476 * All hardware access under dev->priv->lock, except the performance
477 * critical parts:
478 * - rx is (pseudo-) lockless: it relies on the single-threading provided
479 * by the arch code for interrupts.
480 * - tx setup is lockless: it relies on dev->xmit_lock. Actual submission
481 * needs dev->priv->lock :-(
482 * - set_multicast_list: preparation lockless, relies on dev->xmit_lock.
483 */
484
485/* in dev: base, irq */
486struct fe_priv {
487 spinlock_t lock;
488
489 /* General data:
490 * Locking: spin_lock(&np->lock); */
491 struct net_device_stats stats;
492 int in_shutdown;
493 u32 linkspeed;
494 int duplex;
495 int autoneg;
496 int fixed_mode;
497 int phyaddr;
498 int wolenabled;
499 unsigned int phy_oui;
500 u16 gigabit;
501
502 /* General data: RO fields */
503 dma_addr_t ring_addr;
504 struct pci_dev *pci_dev;
505 u32 orig_mac[2];
506 u32 irqmask;
507 u32 desc_ver;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400508 u32 txrxctl_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 void __iomem *base;
511
512 /* rx specific fields.
513 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
514 */
Manfred Spraulee733622005-07-31 18:32:26 +0200515 ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 unsigned int cur_rx, refill_rx;
517 struct sk_buff *rx_skbuff[RX_RING];
518 dma_addr_t rx_dma[RX_RING];
519 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200520 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 struct timer_list oom_kick;
522 struct timer_list nic_poll;
523
524 /* media detection workaround.
525 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
526 */
527 int need_linktimer;
528 unsigned long link_timeout;
529 /*
530 * tx specific fields.
531 */
Manfred Spraulee733622005-07-31 18:32:26 +0200532 ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 unsigned int next_tx, nic_tx;
534 struct sk_buff *tx_skbuff[TX_RING];
535 dma_addr_t tx_dma[TX_RING];
536 u32 tx_flags;
537};
538
539/*
540 * Maximum number of loops until we assume that a bit in the irq mask
541 * is stuck. Overridable with module param.
542 */
543static int max_interrupt_work = 5;
544
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500545/*
546 * Optimization can be either throuput mode or cpu mode
547 *
548 * Throughput Mode: Every tx and rx packet will generate an interrupt.
549 * CPU Mode: Interrupts are controlled by a timer.
550 */
551#define NV_OPTIMIZATION_MODE_THROUGHPUT 0
552#define NV_OPTIMIZATION_MODE_CPU 1
553static int optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
554
555/*
556 * Poll interval for timer irq
557 *
558 * This interval determines how frequent an interrupt is generated.
559 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
560 * Min = 0, and Max = 65535
561 */
562static int poll_interval = -1;
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564static inline struct fe_priv *get_nvpriv(struct net_device *dev)
565{
566 return netdev_priv(dev);
567}
568
569static inline u8 __iomem *get_hwbase(struct net_device *dev)
570{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400571 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572}
573
574static inline void pci_push(u8 __iomem *base)
575{
576 /* force out pending posted writes */
577 readl(base);
578}
579
580static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
581{
582 return le32_to_cpu(prd->FlagLen)
583 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
584}
585
Manfred Spraulee733622005-07-31 18:32:26 +0200586static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
587{
588 return le32_to_cpu(prd->FlagLen) & LEN_MASK_V2;
589}
590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
592 int delay, int delaymax, const char *msg)
593{
594 u8 __iomem *base = get_hwbase(dev);
595
596 pci_push(base);
597 do {
598 udelay(delay);
599 delaymax -= delay;
600 if (delaymax < 0) {
601 if (msg)
602 printk(msg);
603 return 1;
604 }
605 } while ((readl(base + offset) & mask) != target);
606 return 0;
607}
608
609#define MII_READ (-1)
610/* mii_rw: read/write a register on the PHY.
611 *
612 * Caller must guarantee serialization
613 */
614static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
615{
616 u8 __iomem *base = get_hwbase(dev);
617 u32 reg;
618 int retval;
619
620 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
621
622 reg = readl(base + NvRegMIIControl);
623 if (reg & NVREG_MIICTL_INUSE) {
624 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
625 udelay(NV_MIIBUSY_DELAY);
626 }
627
628 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
629 if (value != MII_READ) {
630 writel(value, base + NvRegMIIData);
631 reg |= NVREG_MIICTL_WRITE;
632 }
633 writel(reg, base + NvRegMIIControl);
634
635 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
636 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
637 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n",
638 dev->name, miireg, addr);
639 retval = -1;
640 } else if (value != MII_READ) {
641 /* it was a write operation - fewer failures are detectable */
642 dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
643 dev->name, value, miireg, addr);
644 retval = 0;
645 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
646 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n",
647 dev->name, miireg, addr);
648 retval = -1;
649 } else {
650 retval = readl(base + NvRegMIIData);
651 dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
652 dev->name, miireg, addr, retval);
653 }
654
655 return retval;
656}
657
658static int phy_reset(struct net_device *dev)
659{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400660 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 u32 miicontrol;
662 unsigned int tries = 0;
663
664 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
665 miicontrol |= BMCR_RESET;
666 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) {
667 return -1;
668 }
669
670 /* wait for 500ms */
671 msleep(500);
672
673 /* must wait till reset is deasserted */
674 while (miicontrol & BMCR_RESET) {
675 msleep(10);
676 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
677 /* FIXME: 100 tries seem excessive */
678 if (tries++ > 100)
679 return -1;
680 }
681 return 0;
682}
683
684static int phy_init(struct net_device *dev)
685{
686 struct fe_priv *np = get_nvpriv(dev);
687 u8 __iomem *base = get_hwbase(dev);
688 u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg;
689
690 /* set advertise register */
691 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
692 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|0x800|0x400);
693 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
694 printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev));
695 return PHY_ERROR;
696 }
697
698 /* get phy interface type */
699 phyinterface = readl(base + NvRegPhyInterface);
700
701 /* see if gigabit phy */
702 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
703 if (mii_status & PHY_GIGABIT) {
704 np->gigabit = PHY_GIGABIT;
705 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
706 mii_control_1000 &= ~ADVERTISE_1000HALF;
707 if (phyinterface & PHY_RGMII)
708 mii_control_1000 |= ADVERTISE_1000FULL;
709 else
710 mii_control_1000 &= ~ADVERTISE_1000FULL;
711
712 if (mii_rw(dev, np->phyaddr, MII_1000BT_CR, mii_control_1000)) {
713 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
714 return PHY_ERROR;
715 }
716 }
717 else
718 np->gigabit = 0;
719
720 /* reset the phy */
721 if (phy_reset(dev)) {
722 printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev));
723 return PHY_ERROR;
724 }
725
726 /* phy vendor specific configuration */
727 if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) {
728 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
729 phy_reserved &= ~(PHY_INIT1 | PHY_INIT2);
730 phy_reserved |= (PHY_INIT3 | PHY_INIT4);
731 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) {
732 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
733 return PHY_ERROR;
734 }
735 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
736 phy_reserved |= PHY_INIT5;
737 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) {
738 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
739 return PHY_ERROR;
740 }
741 }
742 if (np->phy_oui == PHY_OUI_CICADA) {
743 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
744 phy_reserved |= PHY_INIT6;
745 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) {
746 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
747 return PHY_ERROR;
748 }
749 }
750
751 /* restart auto negotiation */
752 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
753 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
754 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
755 return PHY_ERROR;
756 }
757
758 return 0;
759}
760
761static void nv_start_rx(struct net_device *dev)
762{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400763 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 u8 __iomem *base = get_hwbase(dev);
765
766 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
767 /* Already running? Stop it. */
768 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
769 writel(0, base + NvRegReceiverControl);
770 pci_push(base);
771 }
772 writel(np->linkspeed, base + NvRegLinkSpeed);
773 pci_push(base);
774 writel(NVREG_RCVCTL_START, base + NvRegReceiverControl);
775 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
776 dev->name, np->duplex, np->linkspeed);
777 pci_push(base);
778}
779
780static void nv_stop_rx(struct net_device *dev)
781{
782 u8 __iomem *base = get_hwbase(dev);
783
784 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
785 writel(0, base + NvRegReceiverControl);
786 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
787 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
788 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
789
790 udelay(NV_RXSTOP_DELAY2);
791 writel(0, base + NvRegLinkSpeed);
792}
793
794static void nv_start_tx(struct net_device *dev)
795{
796 u8 __iomem *base = get_hwbase(dev);
797
798 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
799 writel(NVREG_XMITCTL_START, base + NvRegTransmitterControl);
800 pci_push(base);
801}
802
803static void nv_stop_tx(struct net_device *dev)
804{
805 u8 __iomem *base = get_hwbase(dev);
806
807 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
808 writel(0, base + NvRegTransmitterControl);
809 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
810 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
811 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
812
813 udelay(NV_TXSTOP_DELAY2);
814 writel(0, base + NvRegUnknownTransmitterReg);
815}
816
817static void nv_txrx_reset(struct net_device *dev)
818{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400819 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 u8 __iomem *base = get_hwbase(dev);
821
822 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400823 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 pci_push(base);
825 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400826 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 pci_push(base);
828}
829
830/*
831 * nv_get_stats: dev->get_stats function
832 * Get latest stats value from the nic.
833 * Called with read_lock(&dev_base_lock) held for read -
834 * only synchronized against unregister_netdevice.
835 */
836static struct net_device_stats *nv_get_stats(struct net_device *dev)
837{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400838 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 /* It seems that the nic always generates interrupts and doesn't
841 * accumulate errors internally. Thus the current values in np->stats
842 * are already up to date.
843 */
844 return &np->stats;
845}
846
847/*
848 * nv_alloc_rx: fill rx ring entries.
849 * Return 1 if the allocations for the skbs failed and the
850 * rx engine is without Available descriptors
851 */
852static int nv_alloc_rx(struct net_device *dev)
853{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400854 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 unsigned int refill_rx = np->refill_rx;
856 int nr;
857
858 while (np->cur_rx != refill_rx) {
859 struct sk_buff *skb;
860
861 nr = refill_rx % RX_RING;
862 if (np->rx_skbuff[nr] == NULL) {
863
Manfred Sprauld81c0982005-07-31 18:20:30 +0200864 skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if (!skb)
866 break;
867
868 skb->dev = dev;
869 np->rx_skbuff[nr] = skb;
870 } else {
871 skb = np->rx_skbuff[nr];
872 }
873 np->rx_dma[nr] = pci_map_single(np->pci_dev, skb->data, skb->len,
874 PCI_DMA_FROMDEVICE);
Manfred Spraulee733622005-07-31 18:32:26 +0200875 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
876 np->rx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->rx_dma[nr]);
877 wmb();
878 np->rx_ring.orig[nr].FlagLen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
879 } else {
880 np->rx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->rx_dma[nr]) >> 32;
881 np->rx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->rx_dma[nr]) & 0x0FFFFFFFF;
882 wmb();
883 np->rx_ring.ex[nr].FlagLen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
884 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 dprintk(KERN_DEBUG "%s: nv_alloc_rx: Packet %d marked as Available\n",
886 dev->name, refill_rx);
887 refill_rx++;
888 }
889 np->refill_rx = refill_rx;
890 if (np->cur_rx - refill_rx == RX_RING)
891 return 1;
892 return 0;
893}
894
895static void nv_do_rx_refill(unsigned long data)
896{
897 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400898 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
900 disable_irq(dev->irq);
901 if (nv_alloc_rx(dev)) {
902 spin_lock(&np->lock);
903 if (!np->in_shutdown)
904 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
905 spin_unlock(&np->lock);
906 }
907 enable_irq(dev->irq);
908}
909
Manfred Sprauld81c0982005-07-31 18:20:30 +0200910static void nv_init_rx(struct net_device *dev)
911{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400912 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +0200913 int i;
914
915 np->cur_rx = RX_RING;
916 np->refill_rx = 0;
917 for (i = 0; i < RX_RING; i++)
Manfred Spraulee733622005-07-31 18:32:26 +0200918 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
919 np->rx_ring.orig[i].FlagLen = 0;
920 else
921 np->rx_ring.ex[i].FlagLen = 0;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200922}
923
924static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400926 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 int i;
928
929 np->next_tx = np->nic_tx = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400930 for (i = 0; i < TX_RING; i++) {
Manfred Spraulee733622005-07-31 18:32:26 +0200931 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
932 np->tx_ring.orig[i].FlagLen = 0;
933 else
934 np->tx_ring.ex[i].FlagLen = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400935 np->tx_skbuff[i] = NULL;
936 }
Manfred Sprauld81c0982005-07-31 18:20:30 +0200937}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Manfred Sprauld81c0982005-07-31 18:20:30 +0200939static int nv_init_ring(struct net_device *dev)
940{
941 nv_init_tx(dev);
942 nv_init_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return nv_alloc_rx(dev);
944}
945
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400946static void nv_release_txskb(struct net_device *dev, unsigned int skbnr)
947{
948 struct fe_priv *np = netdev_priv(dev);
949 struct sk_buff *skb = np->tx_skbuff[skbnr];
950 unsigned int j, entry, fragments;
951
952 dprintk(KERN_INFO "%s: nv_release_txskb for skbnr %d, skb %p\n",
953 dev->name, skbnr, np->tx_skbuff[skbnr]);
954
955 entry = skbnr;
956 if ((fragments = skb_shinfo(skb)->nr_frags) != 0) {
957 for (j = fragments; j >= 1; j--) {
958 skb_frag_t *frag = &skb_shinfo(skb)->frags[j-1];
959 pci_unmap_page(np->pci_dev, np->tx_dma[entry],
960 frag->size,
961 PCI_DMA_TODEVICE);
962 entry = (entry - 1) % TX_RING;
963 }
964 }
965 pci_unmap_single(np->pci_dev, np->tx_dma[entry],
966 skb->len - skb->data_len,
967 PCI_DMA_TODEVICE);
968 dev_kfree_skb_irq(skb);
969 np->tx_skbuff[skbnr] = NULL;
970}
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972static void nv_drain_tx(struct net_device *dev)
973{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400974 struct fe_priv *np = netdev_priv(dev);
975 unsigned int i;
976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 for (i = 0; i < TX_RING; i++) {
Manfred Spraulee733622005-07-31 18:32:26 +0200978 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
979 np->tx_ring.orig[i].FlagLen = 0;
980 else
981 np->tx_ring.ex[i].FlagLen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 if (np->tx_skbuff[i]) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400983 nv_release_txskb(dev, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 np->stats.tx_dropped++;
985 }
986 }
987}
988
989static void nv_drain_rx(struct net_device *dev)
990{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400991 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 int i;
993 for (i = 0; i < RX_RING; i++) {
Manfred Spraulee733622005-07-31 18:32:26 +0200994 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
995 np->rx_ring.orig[i].FlagLen = 0;
996 else
997 np->rx_ring.ex[i].FlagLen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 wmb();
999 if (np->rx_skbuff[i]) {
1000 pci_unmap_single(np->pci_dev, np->rx_dma[i],
1001 np->rx_skbuff[i]->len,
1002 PCI_DMA_FROMDEVICE);
1003 dev_kfree_skb(np->rx_skbuff[i]);
1004 np->rx_skbuff[i] = NULL;
1005 }
1006 }
1007}
1008
1009static void drain_ring(struct net_device *dev)
1010{
1011 nv_drain_tx(dev);
1012 nv_drain_rx(dev);
1013}
1014
1015/*
1016 * nv_start_xmit: dev->hard_start_xmit function
1017 * Called with dev->xmit_lock held.
1018 */
1019static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1020{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001021 struct fe_priv *np = netdev_priv(dev);
1022 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
1023 unsigned int fragments = skb_shinfo(skb)->nr_frags;
1024 unsigned int nr = (np->next_tx + fragments) % TX_RING;
1025 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
1027 spin_lock_irq(&np->lock);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001028
1029 if ((np->next_tx - np->nic_tx + fragments) > TX_LIMIT_STOP) {
1030 spin_unlock_irq(&np->lock);
1031 netif_stop_queue(dev);
1032 return NETDEV_TX_BUSY;
1033 }
1034
1035 np->tx_skbuff[nr] = skb;
1036
1037 if (fragments) {
1038 dprintk(KERN_DEBUG "%s: nv_start_xmit: buffer contains %d fragments\n", dev->name, fragments);
1039 /* setup descriptors in reverse order */
1040 for (i = fragments; i >= 1; i--) {
1041 skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1];
1042 np->tx_dma[nr] = pci_map_page(np->pci_dev, frag->page, frag->page_offset, frag->size,
1043 PCI_DMA_TODEVICE);
1044
1045 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1046 np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]);
1047 np->tx_ring.orig[nr].FlagLen = cpu_to_le32( (frag->size-1) | np->tx_flags | tx_flags_extra);
1048 } else {
1049 np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1050 np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1051 np->tx_ring.ex[nr].FlagLen = cpu_to_le32( (frag->size-1) | np->tx_flags | tx_flags_extra);
1052 }
1053
1054 nr = (nr - 1) % TX_RING;
1055
1056 if (np->desc_ver == DESC_VER_1)
1057 tx_flags_extra &= ~NV_TX_LASTPACKET;
1058 else
1059 tx_flags_extra &= ~NV_TX2_LASTPACKET;
1060 }
1061 }
1062
1063#ifdef NETIF_F_TSO
1064 if (skb_shinfo(skb)->tso_size)
1065 tx_flags_extra |= NV_TX2_TSO | (skb_shinfo(skb)->tso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02001066 else
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001067#endif
1068 tx_flags_extra |= (skb->ip_summed == CHECKSUM_HW ? (NV_TX2_CHECKSUM_L3|NV_TX2_CHECKSUM_L4) : 0);
1069
1070 np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data, skb->len-skb->data_len,
1071 PCI_DMA_TODEVICE);
1072
1073 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1074 np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]);
1075 np->tx_ring.orig[nr].FlagLen = cpu_to_le32( (skb->len-skb->data_len-1) | np->tx_flags | tx_flags_extra);
1076 } else {
1077 np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1078 np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1079 np->tx_ring.ex[nr].FlagLen = cpu_to_le32( (skb->len-skb->data_len-1) | np->tx_flags | tx_flags_extra);
1080 }
1081
1082 dprintk(KERN_DEBUG "%s: nv_start_xmit: packet packet %d queued for transmission. tx_flags_extra: %x\n",
1083 dev->name, np->next_tx, tx_flags_extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 {
1085 int j;
1086 for (j=0; j<64; j++) {
1087 if ((j%16) == 0)
1088 dprintk("\n%03x:", j);
1089 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
1090 }
1091 dprintk("\n");
1092 }
1093
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001094 np->next_tx += 1 + fragments;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 spin_unlock_irq(&np->lock);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001098 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 pci_push(get_hwbase(dev));
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001100 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101}
1102
1103/*
1104 * nv_tx_done: check for completed packets, release the skbs.
1105 *
1106 * Caller must own np->lock.
1107 */
1108static void nv_tx_done(struct net_device *dev)
1109{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001110 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 u32 Flags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001112 unsigned int i;
1113 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 while (np->nic_tx != np->next_tx) {
1116 i = np->nic_tx % TX_RING;
1117
Manfred Spraulee733622005-07-31 18:32:26 +02001118 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1119 Flags = le32_to_cpu(np->tx_ring.orig[i].FlagLen);
1120 else
1121 Flags = le32_to_cpu(np->tx_ring.ex[i].FlagLen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 dprintk(KERN_DEBUG "%s: nv_tx_done: looking at packet %d, Flags 0x%x.\n",
1124 dev->name, np->nic_tx, Flags);
1125 if (Flags & NV_TX_VALID)
1126 break;
1127 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001128 if (Flags & NV_TX_LASTPACKET) {
1129 skb = np->tx_skbuff[i];
1130 if (Flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION|
1131 NV_TX_UNDERFLOW|NV_TX_ERROR)) {
1132 if (Flags & NV_TX_UNDERFLOW)
1133 np->stats.tx_fifo_errors++;
1134 if (Flags & NV_TX_CARRIERLOST)
1135 np->stats.tx_carrier_errors++;
1136 np->stats.tx_errors++;
1137 } else {
1138 np->stats.tx_packets++;
1139 np->stats.tx_bytes += skb->len;
1140 }
1141 nv_release_txskb(dev, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 }
1143 } else {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001144 if (Flags & NV_TX2_LASTPACKET) {
1145 skb = np->tx_skbuff[i];
1146 if (Flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION|
1147 NV_TX2_UNDERFLOW|NV_TX2_ERROR)) {
1148 if (Flags & NV_TX2_UNDERFLOW)
1149 np->stats.tx_fifo_errors++;
1150 if (Flags & NV_TX2_CARRIERLOST)
1151 np->stats.tx_carrier_errors++;
1152 np->stats.tx_errors++;
1153 } else {
1154 np->stats.tx_packets++;
1155 np->stats.tx_bytes += skb->len;
1156 }
1157 nv_release_txskb(dev, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 }
1159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 np->nic_tx++;
1161 }
1162 if (np->next_tx - np->nic_tx < TX_LIMIT_START)
1163 netif_wake_queue(dev);
1164}
1165
1166/*
1167 * nv_tx_timeout: dev->tx_timeout function
1168 * Called with dev->xmit_lock held.
1169 */
1170static void nv_tx_timeout(struct net_device *dev)
1171{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001172 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 u8 __iomem *base = get_hwbase(dev);
1174
Manfred Spraulc2dba062005-07-31 18:29:47 +02001175 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK);
1177
Manfred Spraulc2dba062005-07-31 18:29:47 +02001178 {
1179 int i;
1180
1181 printk(KERN_INFO "%s: Ring at %lx: next %d nic %d\n",
1182 dev->name, (unsigned long)np->ring_addr,
1183 np->next_tx, np->nic_tx);
1184 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
1185 for (i=0;i<0x400;i+= 32) {
1186 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
1187 i,
1188 readl(base + i + 0), readl(base + i + 4),
1189 readl(base + i + 8), readl(base + i + 12),
1190 readl(base + i + 16), readl(base + i + 20),
1191 readl(base + i + 24), readl(base + i + 28));
1192 }
1193 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
1194 for (i=0;i<TX_RING;i+= 4) {
Manfred Spraulee733622005-07-31 18:32:26 +02001195 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1196 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
1197 i,
1198 le32_to_cpu(np->tx_ring.orig[i].PacketBuffer),
1199 le32_to_cpu(np->tx_ring.orig[i].FlagLen),
1200 le32_to_cpu(np->tx_ring.orig[i+1].PacketBuffer),
1201 le32_to_cpu(np->tx_ring.orig[i+1].FlagLen),
1202 le32_to_cpu(np->tx_ring.orig[i+2].PacketBuffer),
1203 le32_to_cpu(np->tx_ring.orig[i+2].FlagLen),
1204 le32_to_cpu(np->tx_ring.orig[i+3].PacketBuffer),
1205 le32_to_cpu(np->tx_ring.orig[i+3].FlagLen));
1206 } else {
1207 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
1208 i,
1209 le32_to_cpu(np->tx_ring.ex[i].PacketBufferHigh),
1210 le32_to_cpu(np->tx_ring.ex[i].PacketBufferLow),
1211 le32_to_cpu(np->tx_ring.ex[i].FlagLen),
1212 le32_to_cpu(np->tx_ring.ex[i+1].PacketBufferHigh),
1213 le32_to_cpu(np->tx_ring.ex[i+1].PacketBufferLow),
1214 le32_to_cpu(np->tx_ring.ex[i+1].FlagLen),
1215 le32_to_cpu(np->tx_ring.ex[i+2].PacketBufferHigh),
1216 le32_to_cpu(np->tx_ring.ex[i+2].PacketBufferLow),
1217 le32_to_cpu(np->tx_ring.ex[i+2].FlagLen),
1218 le32_to_cpu(np->tx_ring.ex[i+3].PacketBufferHigh),
1219 le32_to_cpu(np->tx_ring.ex[i+3].PacketBufferLow),
1220 le32_to_cpu(np->tx_ring.ex[i+3].FlagLen));
1221 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02001222 }
1223 }
1224
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 spin_lock_irq(&np->lock);
1226
1227 /* 1) stop tx engine */
1228 nv_stop_tx(dev);
1229
1230 /* 2) check that the packets were not sent already: */
1231 nv_tx_done(dev);
1232
1233 /* 3) if there are dead entries: clear everything */
1234 if (np->next_tx != np->nic_tx) {
1235 printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name);
1236 nv_drain_tx(dev);
1237 np->next_tx = np->nic_tx = 0;
Manfred Spraulee733622005-07-31 18:32:26 +02001238 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1239 writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
1240 else
1241 writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 netif_wake_queue(dev);
1243 }
1244
1245 /* 4) restart tx engine */
1246 nv_start_tx(dev);
1247 spin_unlock_irq(&np->lock);
1248}
1249
Manfred Spraul22c6d142005-04-19 21:17:09 +02001250/*
1251 * Called when the nic notices a mismatch between the actual data len on the
1252 * wire and the len indicated in the 802 header
1253 */
1254static int nv_getlen(struct net_device *dev, void *packet, int datalen)
1255{
1256 int hdrlen; /* length of the 802 header */
1257 int protolen; /* length as stored in the proto field */
1258
1259 /* 1) calculate len according to header */
1260 if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
1261 protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto );
1262 hdrlen = VLAN_HLEN;
1263 } else {
1264 protolen = ntohs( ((struct ethhdr *)packet)->h_proto);
1265 hdrlen = ETH_HLEN;
1266 }
1267 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
1268 dev->name, datalen, protolen, hdrlen);
1269 if (protolen > ETH_DATA_LEN)
1270 return datalen; /* Value in proto field not a len, no checks possible */
1271
1272 protolen += hdrlen;
1273 /* consistency checks: */
1274 if (datalen > ETH_ZLEN) {
1275 if (datalen >= protolen) {
1276 /* more data on wire than in 802 header, trim of
1277 * additional data.
1278 */
1279 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1280 dev->name, protolen);
1281 return protolen;
1282 } else {
1283 /* less data on wire than mentioned in header.
1284 * Discard the packet.
1285 */
1286 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
1287 dev->name);
1288 return -1;
1289 }
1290 } else {
1291 /* short packet. Accept only if 802 values are also short */
1292 if (protolen > ETH_ZLEN) {
1293 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
1294 dev->name);
1295 return -1;
1296 }
1297 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1298 dev->name, datalen);
1299 return datalen;
1300 }
1301}
1302
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303static void nv_rx_process(struct net_device *dev)
1304{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001305 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 u32 Flags;
1307
1308 for (;;) {
1309 struct sk_buff *skb;
1310 int len;
1311 int i;
1312 if (np->cur_rx - np->refill_rx >= RX_RING)
1313 break; /* we scanned the whole ring - do not continue */
1314
1315 i = np->cur_rx % RX_RING;
Manfred Spraulee733622005-07-31 18:32:26 +02001316 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1317 Flags = le32_to_cpu(np->rx_ring.orig[i].FlagLen);
1318 len = nv_descr_getlength(&np->rx_ring.orig[i], np->desc_ver);
1319 } else {
1320 Flags = le32_to_cpu(np->rx_ring.ex[i].FlagLen);
1321 len = nv_descr_getlength_ex(&np->rx_ring.ex[i], np->desc_ver);
1322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
1324 dprintk(KERN_DEBUG "%s: nv_rx_process: looking at packet %d, Flags 0x%x.\n",
1325 dev->name, np->cur_rx, Flags);
1326
1327 if (Flags & NV_RX_AVAIL)
1328 break; /* still owned by hardware, */
1329
1330 /*
1331 * the packet is for us - immediately tear down the pci mapping.
1332 * TODO: check if a prefetch of the first cacheline improves
1333 * the performance.
1334 */
1335 pci_unmap_single(np->pci_dev, np->rx_dma[i],
1336 np->rx_skbuff[i]->len,
1337 PCI_DMA_FROMDEVICE);
1338
1339 {
1340 int j;
1341 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",Flags);
1342 for (j=0; j<64; j++) {
1343 if ((j%16) == 0)
1344 dprintk("\n%03x:", j);
1345 dprintk(" %02x", ((unsigned char*)np->rx_skbuff[i]->data)[j]);
1346 }
1347 dprintk("\n");
1348 }
1349 /* look at what we actually got: */
1350 if (np->desc_ver == DESC_VER_1) {
1351 if (!(Flags & NV_RX_DESCRIPTORVALID))
1352 goto next_pkt;
1353
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001354 if (Flags & NV_RX_ERROR) {
1355 if (Flags & NV_RX_MISSEDFRAME) {
1356 np->stats.rx_missed_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 np->stats.rx_errors++;
1358 goto next_pkt;
1359 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001360 if (Flags & (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3)) {
1361 np->stats.rx_errors++;
1362 goto next_pkt;
1363 }
1364 if (Flags & NV_RX_CRCERR) {
1365 np->stats.rx_crc_errors++;
1366 np->stats.rx_errors++;
1367 goto next_pkt;
1368 }
1369 if (Flags & NV_RX_OVERFLOW) {
1370 np->stats.rx_over_errors++;
1371 np->stats.rx_errors++;
1372 goto next_pkt;
1373 }
1374 if (Flags & NV_RX_ERROR4) {
1375 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1376 if (len < 0) {
1377 np->stats.rx_errors++;
1378 goto next_pkt;
1379 }
1380 }
1381 /* framing errors are soft errors. */
1382 if (Flags & NV_RX_FRAMINGERR) {
1383 if (Flags & NV_RX_SUBSTRACT1) {
1384 len--;
1385 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02001386 }
1387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 } else {
1389 if (!(Flags & NV_RX2_DESCRIPTORVALID))
1390 goto next_pkt;
1391
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001392 if (Flags & NV_RX2_ERROR) {
1393 if (Flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 np->stats.rx_errors++;
1395 goto next_pkt;
1396 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001397 if (Flags & NV_RX2_CRCERR) {
1398 np->stats.rx_crc_errors++;
1399 np->stats.rx_errors++;
1400 goto next_pkt;
1401 }
1402 if (Flags & NV_RX2_OVERFLOW) {
1403 np->stats.rx_over_errors++;
1404 np->stats.rx_errors++;
1405 goto next_pkt;
1406 }
1407 if (Flags & NV_RX2_ERROR4) {
1408 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1409 if (len < 0) {
1410 np->stats.rx_errors++;
1411 goto next_pkt;
1412 }
1413 }
1414 /* framing errors are soft errors */
1415 if (Flags & NV_RX2_FRAMINGERR) {
1416 if (Flags & NV_RX2_SUBSTRACT1) {
1417 len--;
1418 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02001419 }
1420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 Flags &= NV_RX2_CHECKSUMMASK;
1422 if (Flags == NV_RX2_CHECKSUMOK1 ||
1423 Flags == NV_RX2_CHECKSUMOK2 ||
1424 Flags == NV_RX2_CHECKSUMOK3) {
1425 dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name);
1426 np->rx_skbuff[i]->ip_summed = CHECKSUM_UNNECESSARY;
1427 } else {
1428 dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name);
1429 }
1430 }
1431 /* got a valid packet - forward it to the network core */
1432 skb = np->rx_skbuff[i];
1433 np->rx_skbuff[i] = NULL;
1434
1435 skb_put(skb, len);
1436 skb->protocol = eth_type_trans(skb, dev);
1437 dprintk(KERN_DEBUG "%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n",
1438 dev->name, np->cur_rx, len, skb->protocol);
1439 netif_rx(skb);
1440 dev->last_rx = jiffies;
1441 np->stats.rx_packets++;
1442 np->stats.rx_bytes += len;
1443next_pkt:
1444 np->cur_rx++;
1445 }
1446}
1447
Manfred Sprauld81c0982005-07-31 18:20:30 +02001448static void set_bufsize(struct net_device *dev)
1449{
1450 struct fe_priv *np = netdev_priv(dev);
1451
1452 if (dev->mtu <= ETH_DATA_LEN)
1453 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
1454 else
1455 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
1456}
1457
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458/*
1459 * nv_change_mtu: dev->change_mtu function
1460 * Called with dev_base_lock held for read.
1461 */
1462static int nv_change_mtu(struct net_device *dev, int new_mtu)
1463{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001464 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001465 int old_mtu;
1466
1467 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001469
1470 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02001472
1473 /* return early if the buffer sizes will not change */
1474 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
1475 return 0;
1476 if (old_mtu == new_mtu)
1477 return 0;
1478
1479 /* synchronized against open : rtnl_lock() held by caller */
1480 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01001481 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001482 /*
1483 * It seems that the nic preloads valid ring entries into an
1484 * internal buffer. The procedure for flushing everything is
1485 * guessed, there is probably a simpler approach.
1486 * Changing the MTU is a rare event, it shouldn't matter.
1487 */
1488 disable_irq(dev->irq);
1489 spin_lock_bh(&dev->xmit_lock);
1490 spin_lock(&np->lock);
1491 /* stop engines */
1492 nv_stop_rx(dev);
1493 nv_stop_tx(dev);
1494 nv_txrx_reset(dev);
1495 /* drain rx queue */
1496 nv_drain_rx(dev);
1497 nv_drain_tx(dev);
1498 /* reinit driver view of the rx queue */
1499 nv_init_rx(dev);
1500 nv_init_tx(dev);
1501 /* alloc new rx buffers */
1502 set_bufsize(dev);
1503 if (nv_alloc_rx(dev)) {
1504 if (!np->in_shutdown)
1505 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
1506 }
1507 /* reinit nic view of the rx queue */
1508 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
1509 writel((u32) np->ring_addr, base + NvRegRxRingPhysAddr);
Manfred Spraulee733622005-07-31 18:32:26 +02001510 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1511 writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
1512 else
1513 writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001514 writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT),
1515 base + NvRegRingSizes);
1516 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001517 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001518 pci_push(base);
1519
1520 /* restart rx engine */
1521 nv_start_rx(dev);
1522 nv_start_tx(dev);
1523 spin_unlock(&np->lock);
1524 spin_unlock_bh(&dev->xmit_lock);
1525 enable_irq(dev->irq);
1526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 return 0;
1528}
1529
Manfred Spraul72b31782005-07-31 18:33:34 +02001530static void nv_copy_mac_to_hw(struct net_device *dev)
1531{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01001532 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02001533 u32 mac[2];
1534
1535 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
1536 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
1537 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
1538
1539 writel(mac[0], base + NvRegMacAddrA);
1540 writel(mac[1], base + NvRegMacAddrB);
1541}
1542
1543/*
1544 * nv_set_mac_address: dev->set_mac_address function
1545 * Called with rtnl_lock() held.
1546 */
1547static int nv_set_mac_address(struct net_device *dev, void *addr)
1548{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001549 struct fe_priv *np = netdev_priv(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02001550 struct sockaddr *macaddr = (struct sockaddr*)addr;
1551
1552 if(!is_valid_ether_addr(macaddr->sa_data))
1553 return -EADDRNOTAVAIL;
1554
1555 /* synchronized against open : rtnl_lock() held by caller */
1556 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
1557
1558 if (netif_running(dev)) {
1559 spin_lock_bh(&dev->xmit_lock);
1560 spin_lock_irq(&np->lock);
1561
1562 /* stop rx engine */
1563 nv_stop_rx(dev);
1564
1565 /* set mac address */
1566 nv_copy_mac_to_hw(dev);
1567
1568 /* restart rx engine */
1569 nv_start_rx(dev);
1570 spin_unlock_irq(&np->lock);
1571 spin_unlock_bh(&dev->xmit_lock);
1572 } else {
1573 nv_copy_mac_to_hw(dev);
1574 }
1575 return 0;
1576}
1577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578/*
1579 * nv_set_multicast: dev->set_multicast function
1580 * Called with dev->xmit_lock held.
1581 */
1582static void nv_set_multicast(struct net_device *dev)
1583{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001584 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 u8 __iomem *base = get_hwbase(dev);
1586 u32 addr[2];
1587 u32 mask[2];
1588 u32 pff;
1589
1590 memset(addr, 0, sizeof(addr));
1591 memset(mask, 0, sizeof(mask));
1592
1593 if (dev->flags & IFF_PROMISC) {
1594 printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
1595 pff = NVREG_PFF_PROMISC;
1596 } else {
1597 pff = NVREG_PFF_MYADDR;
1598
1599 if (dev->flags & IFF_ALLMULTI || dev->mc_list) {
1600 u32 alwaysOff[2];
1601 u32 alwaysOn[2];
1602
1603 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
1604 if (dev->flags & IFF_ALLMULTI) {
1605 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
1606 } else {
1607 struct dev_mc_list *walk;
1608
1609 walk = dev->mc_list;
1610 while (walk != NULL) {
1611 u32 a, b;
1612 a = le32_to_cpu(*(u32 *) walk->dmi_addr);
1613 b = le16_to_cpu(*(u16 *) (&walk->dmi_addr[4]));
1614 alwaysOn[0] &= a;
1615 alwaysOff[0] &= ~a;
1616 alwaysOn[1] &= b;
1617 alwaysOff[1] &= ~b;
1618 walk = walk->next;
1619 }
1620 }
1621 addr[0] = alwaysOn[0];
1622 addr[1] = alwaysOn[1];
1623 mask[0] = alwaysOn[0] | alwaysOff[0];
1624 mask[1] = alwaysOn[1] | alwaysOff[1];
1625 }
1626 }
1627 addr[0] |= NVREG_MCASTADDRA_FORCE;
1628 pff |= NVREG_PFF_ALWAYS;
1629 spin_lock_irq(&np->lock);
1630 nv_stop_rx(dev);
1631 writel(addr[0], base + NvRegMulticastAddrA);
1632 writel(addr[1], base + NvRegMulticastAddrB);
1633 writel(mask[0], base + NvRegMulticastMaskA);
1634 writel(mask[1], base + NvRegMulticastMaskB);
1635 writel(pff, base + NvRegPacketFilterFlags);
1636 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
1637 dev->name);
1638 nv_start_rx(dev);
1639 spin_unlock_irq(&np->lock);
1640}
1641
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05001642/**
1643 * nv_update_linkspeed: Setup the MAC according to the link partner
1644 * @dev: Network device to be configured
1645 *
1646 * The function queries the PHY and checks if there is a link partner.
1647 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
1648 * set to 10 MBit HD.
1649 *
1650 * The function returns 0 if there is no link partner and 1 if there is
1651 * a good link partner.
1652 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653static int nv_update_linkspeed(struct net_device *dev)
1654{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001655 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 u8 __iomem *base = get_hwbase(dev);
1657 int adv, lpa;
1658 int newls = np->linkspeed;
1659 int newdup = np->duplex;
1660 int mii_status;
1661 int retval = 0;
1662 u32 control_1000, status_1000, phyreg;
1663
1664 /* BMSR_LSTATUS is latched, read it twice:
1665 * we want the current value.
1666 */
1667 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1668 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1669
1670 if (!(mii_status & BMSR_LSTATUS)) {
1671 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
1672 dev->name);
1673 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1674 newdup = 0;
1675 retval = 0;
1676 goto set_speed;
1677 }
1678
1679 if (np->autoneg == 0) {
1680 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
1681 dev->name, np->fixed_mode);
1682 if (np->fixed_mode & LPA_100FULL) {
1683 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
1684 newdup = 1;
1685 } else if (np->fixed_mode & LPA_100HALF) {
1686 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
1687 newdup = 0;
1688 } else if (np->fixed_mode & LPA_10FULL) {
1689 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1690 newdup = 1;
1691 } else {
1692 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1693 newdup = 0;
1694 }
1695 retval = 1;
1696 goto set_speed;
1697 }
1698 /* check auto negotiation is complete */
1699 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
1700 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
1701 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1702 newdup = 0;
1703 retval = 0;
1704 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
1705 goto set_speed;
1706 }
1707
1708 retval = 1;
1709 if (np->gigabit == PHY_GIGABIT) {
1710 control_1000 = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
1711 status_1000 = mii_rw(dev, np->phyaddr, MII_1000BT_SR, MII_READ);
1712
1713 if ((control_1000 & ADVERTISE_1000FULL) &&
1714 (status_1000 & LPA_1000FULL)) {
1715 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
1716 dev->name);
1717 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
1718 newdup = 1;
1719 goto set_speed;
1720 }
1721 }
1722
1723 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
1724 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
1725 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
1726 dev->name, adv, lpa);
1727
1728 /* FIXME: handle parallel detection properly */
1729 lpa = lpa & adv;
1730 if (lpa & LPA_100FULL) {
1731 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
1732 newdup = 1;
1733 } else if (lpa & LPA_100HALF) {
1734 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
1735 newdup = 0;
1736 } else if (lpa & LPA_10FULL) {
1737 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1738 newdup = 1;
1739 } else if (lpa & LPA_10HALF) {
1740 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1741 newdup = 0;
1742 } else {
1743 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, lpa);
1744 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1745 newdup = 0;
1746 }
1747
1748set_speed:
1749 if (np->duplex == newdup && np->linkspeed == newls)
1750 return retval;
1751
1752 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
1753 dev->name, np->linkspeed, np->duplex, newls, newdup);
1754
1755 np->duplex = newdup;
1756 np->linkspeed = newls;
1757
1758 if (np->gigabit == PHY_GIGABIT) {
1759 phyreg = readl(base + NvRegRandomSeed);
1760 phyreg &= ~(0x3FF00);
1761 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
1762 phyreg |= NVREG_RNDSEED_FORCE3;
1763 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
1764 phyreg |= NVREG_RNDSEED_FORCE2;
1765 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
1766 phyreg |= NVREG_RNDSEED_FORCE;
1767 writel(phyreg, base + NvRegRandomSeed);
1768 }
1769
1770 phyreg = readl(base + NvRegPhyInterface);
1771 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
1772 if (np->duplex == 0)
1773 phyreg |= PHY_HALF;
1774 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
1775 phyreg |= PHY_100;
1776 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
1777 phyreg |= PHY_1000;
1778 writel(phyreg, base + NvRegPhyInterface);
1779
1780 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
1781 base + NvRegMisc1);
1782 pci_push(base);
1783 writel(np->linkspeed, base + NvRegLinkSpeed);
1784 pci_push(base);
1785
1786 return retval;
1787}
1788
1789static void nv_linkchange(struct net_device *dev)
1790{
1791 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05001792 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 netif_carrier_on(dev);
1794 printk(KERN_INFO "%s: link up.\n", dev->name);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05001795 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 } else {
1798 if (netif_carrier_ok(dev)) {
1799 netif_carrier_off(dev);
1800 printk(KERN_INFO "%s: link down.\n", dev->name);
1801 nv_stop_rx(dev);
1802 }
1803 }
1804}
1805
1806static void nv_link_irq(struct net_device *dev)
1807{
1808 u8 __iomem *base = get_hwbase(dev);
1809 u32 miistat;
1810
1811 miistat = readl(base + NvRegMIIStatus);
1812 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
1813 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
1814
1815 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
1816 nv_linkchange(dev);
1817 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
1818}
1819
1820static irqreturn_t nv_nic_irq(int foo, void *data, struct pt_regs *regs)
1821{
1822 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001823 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 u8 __iomem *base = get_hwbase(dev);
1825 u32 events;
1826 int i;
1827
1828 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
1829
1830 for (i=0; ; i++) {
1831 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
1832 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
1833 pci_push(base);
1834 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
1835 if (!(events & np->irqmask))
1836 break;
1837
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001838 spin_lock(&np->lock);
1839 nv_tx_done(dev);
1840 spin_unlock(&np->lock);
1841
1842 nv_rx_process(dev);
1843 if (nv_alloc_rx(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 spin_lock(&np->lock);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001845 if (!np->in_shutdown)
1846 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 spin_unlock(&np->lock);
1848 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05001849
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 if (events & NVREG_IRQ_LINK) {
1851 spin_lock(&np->lock);
1852 nv_link_irq(dev);
1853 spin_unlock(&np->lock);
1854 }
1855 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
1856 spin_lock(&np->lock);
1857 nv_linkchange(dev);
1858 spin_unlock(&np->lock);
1859 np->link_timeout = jiffies + LINK_TIMEOUT;
1860 }
1861 if (events & (NVREG_IRQ_TX_ERR)) {
1862 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
1863 dev->name, events);
1864 }
1865 if (events & (NVREG_IRQ_UNKNOWN)) {
1866 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
1867 dev->name, events);
1868 }
1869 if (i > max_interrupt_work) {
1870 spin_lock(&np->lock);
1871 /* disable interrupts on the nic */
1872 writel(0, base + NvRegIrqMask);
1873 pci_push(base);
1874
1875 if (!np->in_shutdown)
1876 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
1877 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
1878 spin_unlock(&np->lock);
1879 break;
1880 }
1881
1882 }
1883 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
1884
1885 return IRQ_RETVAL(i);
1886}
1887
1888static void nv_do_nic_poll(unsigned long data)
1889{
1890 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001891 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 u8 __iomem *base = get_hwbase(dev);
1893
1894 disable_irq(dev->irq);
1895 /* FIXME: Do we need synchronize_irq(dev->irq) here? */
1896 /*
1897 * reenable interrupts on the nic, we have to do this before calling
1898 * nv_nic_irq because that may decide to do otherwise
1899 */
1900 writel(np->irqmask, base + NvRegIrqMask);
1901 pci_push(base);
1902 nv_nic_irq((int) 0, (void *) data, (struct pt_regs *) NULL);
1903 enable_irq(dev->irq);
1904}
1905
Michal Schmidt2918c352005-05-12 19:42:06 -04001906#ifdef CONFIG_NET_POLL_CONTROLLER
1907static void nv_poll_controller(struct net_device *dev)
1908{
1909 nv_do_nic_poll((unsigned long) dev);
1910}
1911#endif
1912
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1914{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001915 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 strcpy(info->driver, "forcedeth");
1917 strcpy(info->version, FORCEDETH_VERSION);
1918 strcpy(info->bus_info, pci_name(np->pci_dev));
1919}
1920
1921static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
1922{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001923 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 wolinfo->supported = WAKE_MAGIC;
1925
1926 spin_lock_irq(&np->lock);
1927 if (np->wolenabled)
1928 wolinfo->wolopts = WAKE_MAGIC;
1929 spin_unlock_irq(&np->lock);
1930}
1931
1932static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
1933{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001934 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 u8 __iomem *base = get_hwbase(dev);
1936
1937 spin_lock_irq(&np->lock);
1938 if (wolinfo->wolopts == 0) {
1939 writel(0, base + NvRegWakeUpFlags);
1940 np->wolenabled = 0;
1941 }
1942 if (wolinfo->wolopts & WAKE_MAGIC) {
1943 writel(NVREG_WAKEUPFLAGS_ENABLE, base + NvRegWakeUpFlags);
1944 np->wolenabled = 1;
1945 }
1946 spin_unlock_irq(&np->lock);
1947 return 0;
1948}
1949
1950static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1951{
1952 struct fe_priv *np = netdev_priv(dev);
1953 int adv;
1954
1955 spin_lock_irq(&np->lock);
1956 ecmd->port = PORT_MII;
1957 if (!netif_running(dev)) {
1958 /* We do not track link speed / duplex setting if the
1959 * interface is disabled. Force a link check */
1960 nv_update_linkspeed(dev);
1961 }
1962 switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) {
1963 case NVREG_LINKSPEED_10:
1964 ecmd->speed = SPEED_10;
1965 break;
1966 case NVREG_LINKSPEED_100:
1967 ecmd->speed = SPEED_100;
1968 break;
1969 case NVREG_LINKSPEED_1000:
1970 ecmd->speed = SPEED_1000;
1971 break;
1972 }
1973 ecmd->duplex = DUPLEX_HALF;
1974 if (np->duplex)
1975 ecmd->duplex = DUPLEX_FULL;
1976
1977 ecmd->autoneg = np->autoneg;
1978
1979 ecmd->advertising = ADVERTISED_MII;
1980 if (np->autoneg) {
1981 ecmd->advertising |= ADVERTISED_Autoneg;
1982 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
1983 } else {
1984 adv = np->fixed_mode;
1985 }
1986 if (adv & ADVERTISE_10HALF)
1987 ecmd->advertising |= ADVERTISED_10baseT_Half;
1988 if (adv & ADVERTISE_10FULL)
1989 ecmd->advertising |= ADVERTISED_10baseT_Full;
1990 if (adv & ADVERTISE_100HALF)
1991 ecmd->advertising |= ADVERTISED_100baseT_Half;
1992 if (adv & ADVERTISE_100FULL)
1993 ecmd->advertising |= ADVERTISED_100baseT_Full;
1994 if (np->autoneg && np->gigabit == PHY_GIGABIT) {
1995 adv = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
1996 if (adv & ADVERTISE_1000FULL)
1997 ecmd->advertising |= ADVERTISED_1000baseT_Full;
1998 }
1999
2000 ecmd->supported = (SUPPORTED_Autoneg |
2001 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
2002 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
2003 SUPPORTED_MII);
2004 if (np->gigabit == PHY_GIGABIT)
2005 ecmd->supported |= SUPPORTED_1000baseT_Full;
2006
2007 ecmd->phy_address = np->phyaddr;
2008 ecmd->transceiver = XCVR_EXTERNAL;
2009
2010 /* ignore maxtxpkt, maxrxpkt for now */
2011 spin_unlock_irq(&np->lock);
2012 return 0;
2013}
2014
2015static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2016{
2017 struct fe_priv *np = netdev_priv(dev);
2018
2019 if (ecmd->port != PORT_MII)
2020 return -EINVAL;
2021 if (ecmd->transceiver != XCVR_EXTERNAL)
2022 return -EINVAL;
2023 if (ecmd->phy_address != np->phyaddr) {
2024 /* TODO: support switching between multiple phys. Should be
2025 * trivial, but not enabled due to lack of test hardware. */
2026 return -EINVAL;
2027 }
2028 if (ecmd->autoneg == AUTONEG_ENABLE) {
2029 u32 mask;
2030
2031 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
2032 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
2033 if (np->gigabit == PHY_GIGABIT)
2034 mask |= ADVERTISED_1000baseT_Full;
2035
2036 if ((ecmd->advertising & mask) == 0)
2037 return -EINVAL;
2038
2039 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
2040 /* Note: autonegotiation disable, speed 1000 intentionally
2041 * forbidden - noone should need that. */
2042
2043 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
2044 return -EINVAL;
2045 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2046 return -EINVAL;
2047 } else {
2048 return -EINVAL;
2049 }
2050
2051 spin_lock_irq(&np->lock);
2052 if (ecmd->autoneg == AUTONEG_ENABLE) {
2053 int adv, bmcr;
2054
2055 np->autoneg = 1;
2056
2057 /* advertise only what has been requested */
2058 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2059 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
2060 if (ecmd->advertising & ADVERTISED_10baseT_Half)
2061 adv |= ADVERTISE_10HALF;
2062 if (ecmd->advertising & ADVERTISED_10baseT_Full)
2063 adv |= ADVERTISE_10FULL;
2064 if (ecmd->advertising & ADVERTISED_100baseT_Half)
2065 adv |= ADVERTISE_100HALF;
2066 if (ecmd->advertising & ADVERTISED_100baseT_Full)
2067 adv |= ADVERTISE_100FULL;
2068 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
2069
2070 if (np->gigabit == PHY_GIGABIT) {
2071 adv = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
2072 adv &= ~ADVERTISE_1000FULL;
2073 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
2074 adv |= ADVERTISE_1000FULL;
2075 mii_rw(dev, np->phyaddr, MII_1000BT_CR, adv);
2076 }
2077
2078 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
2079 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
2080 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
2081
2082 } else {
2083 int adv, bmcr;
2084
2085 np->autoneg = 0;
2086
2087 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2088 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
2089 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
2090 adv |= ADVERTISE_10HALF;
2091 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
2092 adv |= ADVERTISE_10FULL;
2093 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
2094 adv |= ADVERTISE_100HALF;
2095 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
2096 adv |= ADVERTISE_100FULL;
2097 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
2098 np->fixed_mode = adv;
2099
2100 if (np->gigabit == PHY_GIGABIT) {
2101 adv = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
2102 adv &= ~ADVERTISE_1000FULL;
2103 mii_rw(dev, np->phyaddr, MII_1000BT_CR, adv);
2104 }
2105
2106 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
2107 bmcr |= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_FULLDPLX);
2108 if (adv & (ADVERTISE_10FULL|ADVERTISE_100FULL))
2109 bmcr |= BMCR_FULLDPLX;
2110 if (adv & (ADVERTISE_100HALF|ADVERTISE_100FULL))
2111 bmcr |= BMCR_SPEED100;
2112 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
2113
2114 if (netif_running(dev)) {
2115 /* Wait a bit and then reconfigure the nic. */
2116 udelay(10);
2117 nv_linkchange(dev);
2118 }
2119 }
2120 spin_unlock_irq(&np->lock);
2121
2122 return 0;
2123}
2124
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002125#define FORCEDETH_REGS_VER 1
2126#define FORCEDETH_REGS_SIZE 0x400 /* 256 32-bit registers */
2127
2128static int nv_get_regs_len(struct net_device *dev)
2129{
2130 return FORCEDETH_REGS_SIZE;
2131}
2132
2133static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
2134{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002135 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002136 u8 __iomem *base = get_hwbase(dev);
2137 u32 *rbuf = buf;
2138 int i;
2139
2140 regs->version = FORCEDETH_REGS_VER;
2141 spin_lock_irq(&np->lock);
2142 for (i=0;i<FORCEDETH_REGS_SIZE/sizeof(u32);i++)
2143 rbuf[i] = readl(base + i*sizeof(u32));
2144 spin_unlock_irq(&np->lock);
2145}
2146
2147static int nv_nway_reset(struct net_device *dev)
2148{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002149 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002150 int ret;
2151
2152 spin_lock_irq(&np->lock);
2153 if (np->autoneg) {
2154 int bmcr;
2155
2156 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
2157 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
2158 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
2159
2160 ret = 0;
2161 } else {
2162 ret = -EINVAL;
2163 }
2164 spin_unlock_irq(&np->lock);
2165
2166 return ret;
2167}
2168
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169static struct ethtool_ops ops = {
2170 .get_drvinfo = nv_get_drvinfo,
2171 .get_link = ethtool_op_get_link,
2172 .get_wol = nv_get_wol,
2173 .set_wol = nv_set_wol,
2174 .get_settings = nv_get_settings,
2175 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002176 .get_regs_len = nv_get_regs_len,
2177 .get_regs = nv_get_regs,
2178 .nway_reset = nv_nway_reset,
John W. Linvillec704b852005-09-12 10:48:56 -04002179 .get_perm_addr = ethtool_op_get_perm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180};
2181
2182static int nv_open(struct net_device *dev)
2183{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002184 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 u8 __iomem *base = get_hwbase(dev);
2186 int ret, oom, i;
2187
2188 dprintk(KERN_DEBUG "nv_open: begin\n");
2189
2190 /* 1) erase previous misconfiguration */
2191 /* 4.1-1: stop adapter: ignored, 4.3 seems to be overkill */
2192 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
2193 writel(0, base + NvRegMulticastAddrB);
2194 writel(0, base + NvRegMulticastMaskA);
2195 writel(0, base + NvRegMulticastMaskB);
2196 writel(0, base + NvRegPacketFilterFlags);
2197
2198 writel(0, base + NvRegTransmitterControl);
2199 writel(0, base + NvRegReceiverControl);
2200
2201 writel(0, base + NvRegAdapterControl);
2202
2203 /* 2) initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002204 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 oom = nv_init_ring(dev);
2206
2207 writel(0, base + NvRegLinkSpeed);
2208 writel(0, base + NvRegUnknownTransmitterReg);
2209 nv_txrx_reset(dev);
2210 writel(0, base + NvRegUnknownSetupReg6);
2211
2212 np->in_shutdown = 0;
2213
2214 /* 3) set mac address */
Manfred Spraul72b31782005-07-31 18:33:34 +02002215 nv_copy_mac_to_hw(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
2217 /* 4) give hw rings */
2218 writel((u32) np->ring_addr, base + NvRegRxRingPhysAddr);
Manfred Spraulee733622005-07-31 18:32:26 +02002219 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
2220 writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
2221 else
2222 writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT),
2224 base + NvRegRingSizes);
2225
2226 /* 5) continue setup */
2227 writel(np->linkspeed, base + NvRegLinkSpeed);
2228 writel(NVREG_UNKSETUP3_VAL1, base + NvRegUnknownSetupReg3);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002229 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002231 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
2233 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
2234 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
2235
2236 writel(0, base + NvRegUnknownSetupReg4);
2237 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2238 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
2239
2240 /* 6) continue setup */
2241 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
2242 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
2243 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002244 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
2246 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
2247 get_random_bytes(&i, sizeof(i));
2248 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed);
2249 writel(NVREG_UNKSETUP1_VAL, base + NvRegUnknownSetupReg1);
2250 writel(NVREG_UNKSETUP2_VAL, base + NvRegUnknownSetupReg2);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002251 if (poll_interval == -1) {
2252 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
2253 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
2254 else
2255 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
2256 }
2257 else
2258 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
2260 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
2261 base + NvRegAdapterControl);
2262 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
2263 writel(NVREG_UNKSETUP4_VAL, base + NvRegUnknownSetupReg4);
2264 writel(NVREG_WAKEUPFLAGS_VAL, base + NvRegWakeUpFlags);
2265
2266 i = readl(base + NvRegPowerState);
2267 if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0)
2268 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
2269
2270 pci_push(base);
2271 udelay(10);
2272 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
2273
2274 writel(0, base + NvRegIrqMask);
2275 pci_push(base);
2276 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
2277 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2278 pci_push(base);
2279
2280 ret = request_irq(dev->irq, &nv_nic_irq, SA_SHIRQ, dev->name, dev);
2281 if (ret)
2282 goto out_drain;
2283
2284 /* ask for interrupts */
2285 writel(np->irqmask, base + NvRegIrqMask);
2286
2287 spin_lock_irq(&np->lock);
2288 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
2289 writel(0, base + NvRegMulticastAddrB);
2290 writel(0, base + NvRegMulticastMaskA);
2291 writel(0, base + NvRegMulticastMaskB);
2292 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
2293 /* One manual link speed update: Interrupts are enabled, future link
2294 * speed changes cause interrupts and are handled by nv_link_irq().
2295 */
2296 {
2297 u32 miistat;
2298 miistat = readl(base + NvRegMIIStatus);
2299 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
2300 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
2301 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02002302 /* set linkspeed to invalid value, thus force nv_update_linkspeed
2303 * to init hw */
2304 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 ret = nv_update_linkspeed(dev);
2306 nv_start_rx(dev);
2307 nv_start_tx(dev);
2308 netif_start_queue(dev);
2309 if (ret) {
2310 netif_carrier_on(dev);
2311 } else {
2312 printk("%s: no link during initialization.\n", dev->name);
2313 netif_carrier_off(dev);
2314 }
2315 if (oom)
2316 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2317 spin_unlock_irq(&np->lock);
2318
2319 return 0;
2320out_drain:
2321 drain_ring(dev);
2322 return ret;
2323}
2324
2325static int nv_close(struct net_device *dev)
2326{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002327 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 u8 __iomem *base;
2329
2330 spin_lock_irq(&np->lock);
2331 np->in_shutdown = 1;
2332 spin_unlock_irq(&np->lock);
2333 synchronize_irq(dev->irq);
2334
2335 del_timer_sync(&np->oom_kick);
2336 del_timer_sync(&np->nic_poll);
2337
2338 netif_stop_queue(dev);
2339 spin_lock_irq(&np->lock);
2340 nv_stop_tx(dev);
2341 nv_stop_rx(dev);
2342 nv_txrx_reset(dev);
2343
2344 /* disable interrupts on the nic or we will lock up */
2345 base = get_hwbase(dev);
2346 writel(0, base + NvRegIrqMask);
2347 pci_push(base);
2348 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
2349
2350 spin_unlock_irq(&np->lock);
2351
2352 free_irq(dev->irq, dev);
2353
2354 drain_ring(dev);
2355
2356 if (np->wolenabled)
2357 nv_start_rx(dev);
2358
Manfred Spraulb3df9f82005-07-31 18:38:58 +02002359 /* special op: write back the misordered MAC address - otherwise
2360 * the next nv_probe would see a wrong address.
2361 */
2362 writel(np->orig_mac[0], base + NvRegMacAddrA);
2363 writel(np->orig_mac[1], base + NvRegMacAddrB);
2364
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 /* FIXME: power down nic */
2366
2367 return 0;
2368}
2369
2370static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
2371{
2372 struct net_device *dev;
2373 struct fe_priv *np;
2374 unsigned long addr;
2375 u8 __iomem *base;
2376 int err, i;
2377
2378 dev = alloc_etherdev(sizeof(struct fe_priv));
2379 err = -ENOMEM;
2380 if (!dev)
2381 goto out;
2382
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002383 np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 np->pci_dev = pci_dev;
2385 spin_lock_init(&np->lock);
2386 SET_MODULE_OWNER(dev);
2387 SET_NETDEV_DEV(dev, &pci_dev->dev);
2388
2389 init_timer(&np->oom_kick);
2390 np->oom_kick.data = (unsigned long) dev;
2391 np->oom_kick.function = &nv_do_rx_refill; /* timer handler */
2392 init_timer(&np->nic_poll);
2393 np->nic_poll.data = (unsigned long) dev;
2394 np->nic_poll.function = &nv_do_nic_poll; /* timer handler */
2395
2396 err = pci_enable_device(pci_dev);
2397 if (err) {
2398 printk(KERN_INFO "forcedeth: pci_enable_dev failed (%d) for device %s\n",
2399 err, pci_name(pci_dev));
2400 goto out_free;
2401 }
2402
2403 pci_set_master(pci_dev);
2404
2405 err = pci_request_regions(pci_dev, DRV_NAME);
2406 if (err < 0)
2407 goto out_disable;
2408
2409 err = -EINVAL;
2410 addr = 0;
2411 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
2412 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
2413 pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i),
2414 pci_resource_len(pci_dev, i),
2415 pci_resource_flags(pci_dev, i));
2416 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
2417 pci_resource_len(pci_dev, i) >= NV_PCI_REGSZ) {
2418 addr = pci_resource_start(pci_dev, i);
2419 break;
2420 }
2421 }
2422 if (i == DEVICE_COUNT_RESOURCE) {
2423 printk(KERN_INFO "forcedeth: Couldn't find register window for device %s.\n",
2424 pci_name(pci_dev));
2425 goto out_relreg;
2426 }
2427
2428 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02002429 if (id->driver_data & DEV_HAS_HIGH_DMA) {
2430 /* packet format 3: supports 40-bit addressing */
2431 np->desc_ver = DESC_VER_3;
2432 if (pci_set_dma_mask(pci_dev, 0x0000007fffffffffULL)) {
2433 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n",
2434 pci_name(pci_dev));
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002435 } else {
2436 dev->features |= NETIF_F_HIGHDMA;
Manfred Spraulee733622005-07-31 18:32:26 +02002437 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002438 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Manfred Spraulee733622005-07-31 18:32:26 +02002439 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
2440 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002442 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02002443 } else {
2444 /* original packet format */
2445 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002446 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002447 }
Manfred Spraulee733622005-07-31 18:32:26 +02002448
2449 np->pkt_limit = NV_PKTLIMIT_1;
2450 if (id->driver_data & DEV_HAS_LARGEDESC)
2451 np->pkt_limit = NV_PKTLIMIT_2;
2452
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002453 if (id->driver_data & DEV_HAS_CHECKSUM) {
2454 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002455 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
2456#ifdef NETIF_F_TSO
2457 dev->features |= NETIF_F_TSO;
2458#endif
2459 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002460
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 err = -ENOMEM;
2462 np->base = ioremap(addr, NV_PCI_REGSZ);
2463 if (!np->base)
2464 goto out_relreg;
2465 dev->base_addr = (unsigned long)np->base;
Manfred Spraulee733622005-07-31 18:32:26 +02002466
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 dev->irq = pci_dev->irq;
Manfred Spraulee733622005-07-31 18:32:26 +02002468
2469 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
2470 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
2471 sizeof(struct ring_desc) * (RX_RING + TX_RING),
2472 &np->ring_addr);
2473 if (!np->rx_ring.orig)
2474 goto out_unmap;
2475 np->tx_ring.orig = &np->rx_ring.orig[RX_RING];
2476 } else {
2477 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
2478 sizeof(struct ring_desc_ex) * (RX_RING + TX_RING),
2479 &np->ring_addr);
2480 if (!np->rx_ring.ex)
2481 goto out_unmap;
2482 np->tx_ring.ex = &np->rx_ring.ex[RX_RING];
2483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
2485 dev->open = nv_open;
2486 dev->stop = nv_close;
2487 dev->hard_start_xmit = nv_start_xmit;
2488 dev->get_stats = nv_get_stats;
2489 dev->change_mtu = nv_change_mtu;
Manfred Spraul72b31782005-07-31 18:33:34 +02002490 dev->set_mac_address = nv_set_mac_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 dev->set_multicast_list = nv_set_multicast;
Michal Schmidt2918c352005-05-12 19:42:06 -04002492#ifdef CONFIG_NET_POLL_CONTROLLER
2493 dev->poll_controller = nv_poll_controller;
2494#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 SET_ETHTOOL_OPS(dev, &ops);
2496 dev->tx_timeout = nv_tx_timeout;
2497 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
2498
2499 pci_set_drvdata(pci_dev, dev);
2500
2501 /* read the mac address */
2502 base = get_hwbase(dev);
2503 np->orig_mac[0] = readl(base + NvRegMacAddrA);
2504 np->orig_mac[1] = readl(base + NvRegMacAddrB);
2505
2506 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
2507 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
2508 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
2509 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
2510 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
2511 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
John W. Linvillec704b852005-09-12 10:48:56 -04002512 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513
John W. Linvillec704b852005-09-12 10:48:56 -04002514 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 /*
2516 * Bad mac address. At least one bios sets the mac address
2517 * to 01:23:45:67:89:ab
2518 */
2519 printk(KERN_ERR "%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n",
2520 pci_name(pci_dev),
2521 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2522 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
2523 printk(KERN_ERR "Please complain to your hardware vendor. Switching to a random MAC.\n");
2524 dev->dev_addr[0] = 0x00;
2525 dev->dev_addr[1] = 0x00;
2526 dev->dev_addr[2] = 0x6c;
2527 get_random_bytes(&dev->dev_addr[3], 3);
2528 }
2529
2530 dprintk(KERN_DEBUG "%s: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", pci_name(pci_dev),
2531 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2532 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
2533
2534 /* disable WOL */
2535 writel(0, base + NvRegWakeUpFlags);
2536 np->wolenabled = 0;
2537
2538 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002539 np->tx_flags = NV_TX_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 } else {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002541 np->tx_flags = NV_TX2_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002543 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
2544 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
2545 else
2546 np->irqmask = NVREG_IRQMASK_CPU;
2547
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 if (id->driver_data & DEV_NEED_TIMERIRQ)
2549 np->irqmask |= NVREG_IRQ_TIMER;
2550 if (id->driver_data & DEV_NEED_LINKTIMER) {
2551 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
2552 np->need_linktimer = 1;
2553 np->link_timeout = jiffies + LINK_TIMEOUT;
2554 } else {
2555 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
2556 np->need_linktimer = 0;
2557 }
2558
2559 /* find a suitable phy */
2560 for (i = 1; i < 32; i++) {
2561 int id1, id2;
2562
2563 spin_lock_irq(&np->lock);
2564 id1 = mii_rw(dev, i, MII_PHYSID1, MII_READ);
2565 spin_unlock_irq(&np->lock);
2566 if (id1 < 0 || id1 == 0xffff)
2567 continue;
2568 spin_lock_irq(&np->lock);
2569 id2 = mii_rw(dev, i, MII_PHYSID2, MII_READ);
2570 spin_unlock_irq(&np->lock);
2571 if (id2 < 0 || id2 == 0xffff)
2572 continue;
2573
2574 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
2575 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
2576 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
2577 pci_name(pci_dev), id1, id2, i);
2578 np->phyaddr = i;
2579 np->phy_oui = id1 | id2;
2580 break;
2581 }
2582 if (i == 32) {
2583 /* PHY in isolate mode? No phy attached and user wants to
2584 * test loopback? Very odd, but can be correct.
2585 */
2586 printk(KERN_INFO "%s: open: Could not find a valid PHY.\n",
2587 pci_name(pci_dev));
2588 }
2589
2590 if (i != 32) {
2591 /* reset it */
2592 phy_init(dev);
2593 }
2594
2595 /* set default link speed settings */
2596 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2597 np->duplex = 0;
2598 np->autoneg = 1;
2599
2600 err = register_netdev(dev);
2601 if (err) {
2602 printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
2603 goto out_freering;
2604 }
2605 printk(KERN_INFO "%s: forcedeth.c: subsystem: %05x:%04x bound to %s\n",
2606 dev->name, pci_dev->subsystem_vendor, pci_dev->subsystem_device,
2607 pci_name(pci_dev));
2608
2609 return 0;
2610
2611out_freering:
Manfred Spraulee733622005-07-31 18:32:26 +02002612 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
2613 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING),
2614 np->rx_ring.orig, np->ring_addr);
2615 else
2616 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (RX_RING + TX_RING),
2617 np->rx_ring.ex, np->ring_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 pci_set_drvdata(pci_dev, NULL);
2619out_unmap:
2620 iounmap(get_hwbase(dev));
2621out_relreg:
2622 pci_release_regions(pci_dev);
2623out_disable:
2624 pci_disable_device(pci_dev);
2625out_free:
2626 free_netdev(dev);
2627out:
2628 return err;
2629}
2630
2631static void __devexit nv_remove(struct pci_dev *pci_dev)
2632{
2633 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002634 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
2636 unregister_netdev(dev);
2637
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 /* free all structures */
Manfred Spraulee733622005-07-31 18:32:26 +02002639 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
2640 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING), np->rx_ring.orig, np->ring_addr);
2641 else
2642 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (RX_RING + TX_RING), np->rx_ring.ex, np->ring_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 iounmap(get_hwbase(dev));
2644 pci_release_regions(pci_dev);
2645 pci_disable_device(pci_dev);
2646 free_netdev(dev);
2647 pci_set_drvdata(pci_dev, NULL);
2648}
2649
2650static struct pci_device_id pci_tbl[] = {
2651 { /* nForce Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002652 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1),
Manfred Spraulc2dba062005-07-31 18:29:47 +02002653 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 },
2655 { /* nForce2 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002656 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2),
Manfred Spraulc2dba062005-07-31 18:29:47 +02002657 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 },
2659 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002660 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02002661 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 },
2663 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002664 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002665 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 },
2667 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002668 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002669 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 },
2671 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002672 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002673 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 },
2675 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002676 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002677 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 },
2679 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002680 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002681 .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 -07002682 },
2683 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002684 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002685 .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 -07002686 },
2687 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002688 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002689 .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 -07002690 },
2691 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002692 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002693 .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 +02002694 },
2695 { /* MCP51 Ethernet Controller */
2696 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
Manfred Spraulee733622005-07-31 18:32:26 +02002697 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02002699 { /* MCP51 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002700 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13),
Manfred Spraulee733622005-07-31 18:32:26 +02002701 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA,
Manfred Spraul9992d4a2005-06-05 17:36:11 +02002702 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02002703 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002704 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002705 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02002706 },
2707 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02002708 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002709 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02002710 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 {0,},
2712};
2713
2714static struct pci_driver driver = {
2715 .name = "forcedeth",
2716 .id_table = pci_tbl,
2717 .probe = nv_probe,
2718 .remove = __devexit_p(nv_remove),
2719};
2720
2721
2722static int __init init_nic(void)
2723{
2724 printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION);
2725 return pci_module_init(&driver);
2726}
2727
2728static void __exit exit_nic(void)
2729{
2730 pci_unregister_driver(&driver);
2731}
2732
2733module_param(max_interrupt_work, int, 0);
2734MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002735module_param(optimization_mode, int, 0);
2736MODULE_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.");
2737module_param(poll_interval, int, 0);
2738MODULE_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.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
2740MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
2741MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
2742MODULE_LICENSE("GPL");
2743
2744MODULE_DEVICE_TABLE(pci, pci_tbl);
2745
2746module_init(init_nic);
2747module_exit(exit_nic);