2 * forcedeth: Ethernet driver for NVIDIA nForce media access controllers.
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.
9 * NVIDIA, nForce and other NVIDIA marks are trademarks or registered
10 * trademarks of NVIDIA Corporation in the United States and other
13 * Copyright (C) 2003,4,5 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
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.
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.
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
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,
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
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
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
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
84 * 0.32: 16 Apr 2005: RX_ERROR4 handling added.
85 * 0.33: 16 May 2005: Support for MCP51 added.
86 * 0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics.
87 * 0.35: 26 Jun 2005: Support for MCP55 added.
88 * 0.36: 28 Jun 2005: Add jumbo frame support.
89 * 0.37: 10 Jul 2005: Additional ethtool support, cleanup of pci id list
90 * 0.38: 16 Jul 2005: tx irq rewrite: Use global flags instead of
92 * 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
96 * 0.42: 06 Aug 2005: Fix lack of link speed initialization
97 * in the second (and later) nv_open call
98 * 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
101 * 0.46: 20 Oct 2005: Add irq optimization modes.
102 * 0.47: 26 Oct 2005: Add phyaddr 0 in phy scan.
103 * 0.48: 24 Dec 2005: Disable TSO, bugfix for pci_map_single
104 * 0.49: 10 Dec 2005: Fix tso for large buffers.
105 * 0.50: 20 Jan 2006: Add 8021pq tagging support.
106 * 0.51: 20 Jan 2006: Add 64bit consistent memory allocation for rings.
107 * 0.52: 20 Jan 2006: Add MSI/MSIX support.
110 * We suspect that on some hardware no TX done interrupts are generated.
111 * This means recovery from netif_stop_queue only happens if the hw timer
112 * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
113 * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
114 * If your hardware reliably generates tx done interrupts, then you can remove
115 * DEV_NEED_TIMERIRQ from the driver_data flags.
116 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
117 * superfluous timer interrupts from the nic.
119 #define FORCEDETH_VERSION "0.52"
120 #define DRV_NAME "forcedeth"
122 #include <linux/module.h>
123 #include <linux/types.h>
124 #include <linux/pci.h>
125 #include <linux/interrupt.h>
126 #include <linux/netdevice.h>
127 #include <linux/etherdevice.h>
128 #include <linux/delay.h>
129 #include <linux/spinlock.h>
130 #include <linux/ethtool.h>
131 #include <linux/timer.h>
132 #include <linux/skbuff.h>
133 #include <linux/mii.h>
134 #include <linux/random.h>
135 #include <linux/init.h>
136 #include <linux/if_vlan.h>
137 #include <linux/dma-mapping.h>
141 #include <asm/uaccess.h>
142 #include <asm/system.h>
145 #define dprintk printk
147 #define dprintk(x...) do { } while (0)
155 #define DEV_NEED_TIMERIRQ 0x0001 /* set the timer irq flag in the irq mask */
156 #define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */
157 #define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */
158 #define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */
159 #define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */
160 #define DEV_HAS_VLAN 0x0020 /* device supports vlan tagging and striping */
161 #define DEV_HAS_MSI 0x0040 /* device supports MSI */
162 #define DEV_HAS_MSI_X 0x0080 /* device supports MSI-X */
165 NvRegIrqStatus = 0x000,
166 #define NVREG_IRQSTAT_MIIEVENT 0x040
167 #define NVREG_IRQSTAT_MASK 0x1ff
168 NvRegIrqMask = 0x004,
169 #define NVREG_IRQ_RX_ERROR 0x0001
170 #define NVREG_IRQ_RX 0x0002
171 #define NVREG_IRQ_RX_NOBUF 0x0004
172 #define NVREG_IRQ_TX_ERR 0x0008
173 #define NVREG_IRQ_TX_OK 0x0010
174 #define NVREG_IRQ_TIMER 0x0020
175 #define NVREG_IRQ_LINK 0x0040
176 #define NVREG_IRQ_RX_FORCED 0x0080
177 #define NVREG_IRQ_TX_FORCED 0x0100
178 #define NVREG_IRQMASK_THROUGHPUT 0x00df
179 #define NVREG_IRQMASK_CPU 0x0040
180 #define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
181 #define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED)
182 #define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK)
184 #define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \
185 NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RX_FORCED| \
186 NVREG_IRQ_TX_FORCED))
188 NvRegUnknownSetupReg6 = 0x008,
189 #define NVREG_UNKSETUP6_VAL 3
192 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
193 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
195 NvRegPollingInterval = 0x00c,
196 #define NVREG_POLL_DEFAULT_THROUGHPUT 970
197 #define NVREG_POLL_DEFAULT_CPU 13
198 NvRegMSIMap0 = 0x020,
199 NvRegMSIMap1 = 0x024,
200 NvRegMSIIrqMask = 0x030,
201 #define NVREG_MSI_VECTOR_0_ENABLED 0x01
203 #define NVREG_MISC1_HD 0x02
204 #define NVREG_MISC1_FORCE 0x3b0f3c
206 NvRegTransmitterControl = 0x084,
207 #define NVREG_XMITCTL_START 0x01
208 NvRegTransmitterStatus = 0x088,
209 #define NVREG_XMITSTAT_BUSY 0x01
211 NvRegPacketFilterFlags = 0x8c,
212 #define NVREG_PFF_ALWAYS 0x7F0008
213 #define NVREG_PFF_PROMISC 0x80
214 #define NVREG_PFF_MYADDR 0x20
216 NvRegOffloadConfig = 0x90,
217 #define NVREG_OFFLOAD_HOMEPHY 0x601
218 #define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
219 NvRegReceiverControl = 0x094,
220 #define NVREG_RCVCTL_START 0x01
221 NvRegReceiverStatus = 0x98,
222 #define NVREG_RCVSTAT_BUSY 0x01
224 NvRegRandomSeed = 0x9c,
225 #define NVREG_RNDSEED_MASK 0x00ff
226 #define NVREG_RNDSEED_FORCE 0x7f00
227 #define NVREG_RNDSEED_FORCE2 0x2d00
228 #define NVREG_RNDSEED_FORCE3 0x7400
230 NvRegUnknownSetupReg1 = 0xA0,
231 #define NVREG_UNKSETUP1_VAL 0x16070f
232 NvRegUnknownSetupReg2 = 0xA4,
233 #define NVREG_UNKSETUP2_VAL 0x16
234 NvRegMacAddrA = 0xA8,
235 NvRegMacAddrB = 0xAC,
236 NvRegMulticastAddrA = 0xB0,
237 #define NVREG_MCASTADDRA_FORCE 0x01
238 NvRegMulticastAddrB = 0xB4,
239 NvRegMulticastMaskA = 0xB8,
240 NvRegMulticastMaskB = 0xBC,
242 NvRegPhyInterface = 0xC0,
243 #define PHY_RGMII 0x10000000
245 NvRegTxRingPhysAddr = 0x100,
246 NvRegRxRingPhysAddr = 0x104,
247 NvRegRingSizes = 0x108,
248 #define NVREG_RINGSZ_TXSHIFT 0
249 #define NVREG_RINGSZ_RXSHIFT 16
250 NvRegUnknownTransmitterReg = 0x10c,
251 NvRegLinkSpeed = 0x110,
252 #define NVREG_LINKSPEED_FORCE 0x10000
253 #define NVREG_LINKSPEED_10 1000
254 #define NVREG_LINKSPEED_100 100
255 #define NVREG_LINKSPEED_1000 50
256 #define NVREG_LINKSPEED_MASK (0xFFF)
257 NvRegUnknownSetupReg5 = 0x130,
258 #define NVREG_UNKSETUP5_BIT31 (1<<31)
259 NvRegUnknownSetupReg3 = 0x13c,
260 #define NVREG_UNKSETUP3_VAL1 0x200010
261 NvRegTxRxControl = 0x144,
262 #define NVREG_TXRXCTL_KICK 0x0001
263 #define NVREG_TXRXCTL_BIT1 0x0002
264 #define NVREG_TXRXCTL_BIT2 0x0004
265 #define NVREG_TXRXCTL_IDLE 0x0008
266 #define NVREG_TXRXCTL_RESET 0x0010
267 #define NVREG_TXRXCTL_RXCHECK 0x0400
268 #define NVREG_TXRXCTL_DESC_1 0
269 #define NVREG_TXRXCTL_DESC_2 0x02100
270 #define NVREG_TXRXCTL_DESC_3 0x02200
271 #define NVREG_TXRXCTL_VLANSTRIP 0x00040
272 #define NVREG_TXRXCTL_VLANINS 0x00080
273 NvRegTxRingPhysAddrHigh = 0x148,
274 NvRegRxRingPhysAddrHigh = 0x14C,
275 NvRegMIIStatus = 0x180,
276 #define NVREG_MIISTAT_ERROR 0x0001
277 #define NVREG_MIISTAT_LINKCHANGE 0x0008
278 #define NVREG_MIISTAT_MASK 0x000f
279 #define NVREG_MIISTAT_MASK2 0x000f
280 NvRegUnknownSetupReg4 = 0x184,
281 #define NVREG_UNKSETUP4_VAL 8
283 NvRegAdapterControl = 0x188,
284 #define NVREG_ADAPTCTL_START 0x02
285 #define NVREG_ADAPTCTL_LINKUP 0x04
286 #define NVREG_ADAPTCTL_PHYVALID 0x40000
287 #define NVREG_ADAPTCTL_RUNNING 0x100000
288 #define NVREG_ADAPTCTL_PHYSHIFT 24
289 NvRegMIISpeed = 0x18c,
290 #define NVREG_MIISPEED_BIT8 (1<<8)
291 #define NVREG_MIIDELAY 5
292 NvRegMIIControl = 0x190,
293 #define NVREG_MIICTL_INUSE 0x08000
294 #define NVREG_MIICTL_WRITE 0x00400
295 #define NVREG_MIICTL_ADDRSHIFT 5
296 NvRegMIIData = 0x194,
297 NvRegWakeUpFlags = 0x200,
298 #define NVREG_WAKEUPFLAGS_VAL 0x7770
299 #define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
300 #define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
301 #define NVREG_WAKEUPFLAGS_D3SHIFT 12
302 #define NVREG_WAKEUPFLAGS_D2SHIFT 8
303 #define NVREG_WAKEUPFLAGS_D1SHIFT 4
304 #define NVREG_WAKEUPFLAGS_D0SHIFT 0
305 #define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
306 #define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
307 #define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
308 #define NVREG_WAKEUPFLAGS_ENABLE 0x1111
310 NvRegPatternCRC = 0x204,
311 NvRegPatternMask = 0x208,
312 NvRegPowerCap = 0x268,
313 #define NVREG_POWERCAP_D3SUPP (1<<30)
314 #define NVREG_POWERCAP_D2SUPP (1<<26)
315 #define NVREG_POWERCAP_D1SUPP (1<<25)
316 NvRegPowerState = 0x26c,
317 #define NVREG_POWERSTATE_POWEREDUP 0x8000
318 #define NVREG_POWERSTATE_VALID 0x0100
319 #define NVREG_POWERSTATE_MASK 0x0003
320 #define NVREG_POWERSTATE_D0 0x0000
321 #define NVREG_POWERSTATE_D1 0x0001
322 #define NVREG_POWERSTATE_D2 0x0002
323 #define NVREG_POWERSTATE_D3 0x0003
324 NvRegVlanControl = 0x300,
325 #define NVREG_VLANCONTROL_ENABLE 0x2000
326 NvRegMSIXMap0 = 0x3e0,
327 NvRegMSIXMap1 = 0x3e4,
328 NvRegMSIXIrqStatus = 0x3f0,
331 /* Big endian: should work, but is untested */
337 struct ring_desc_ex {
338 u32 PacketBufferHigh;
344 typedef union _ring_type {
345 struct ring_desc* orig;
346 struct ring_desc_ex* ex;
349 #define FLAG_MASK_V1 0xffff0000
350 #define FLAG_MASK_V2 0xffffc000
351 #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
352 #define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
354 #define NV_TX_LASTPACKET (1<<16)
355 #define NV_TX_RETRYERROR (1<<19)
356 #define NV_TX_FORCED_INTERRUPT (1<<24)
357 #define NV_TX_DEFERRED (1<<26)
358 #define NV_TX_CARRIERLOST (1<<27)
359 #define NV_TX_LATECOLLISION (1<<28)
360 #define NV_TX_UNDERFLOW (1<<29)
361 #define NV_TX_ERROR (1<<30)
362 #define NV_TX_VALID (1<<31)
364 #define NV_TX2_LASTPACKET (1<<29)
365 #define NV_TX2_RETRYERROR (1<<18)
366 #define NV_TX2_FORCED_INTERRUPT (1<<30)
367 #define NV_TX2_DEFERRED (1<<25)
368 #define NV_TX2_CARRIERLOST (1<<26)
369 #define NV_TX2_LATECOLLISION (1<<27)
370 #define NV_TX2_UNDERFLOW (1<<28)
371 /* error and valid are the same for both */
372 #define NV_TX2_ERROR (1<<30)
373 #define NV_TX2_VALID (1<<31)
374 #define NV_TX2_TSO (1<<28)
375 #define NV_TX2_TSO_SHIFT 14
376 #define NV_TX2_TSO_MAX_SHIFT 14
377 #define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
378 #define NV_TX2_CHECKSUM_L3 (1<<27)
379 #define NV_TX2_CHECKSUM_L4 (1<<26)
381 #define NV_TX3_VLAN_TAG_PRESENT (1<<18)
383 #define NV_RX_DESCRIPTORVALID (1<<16)
384 #define NV_RX_MISSEDFRAME (1<<17)
385 #define NV_RX_SUBSTRACT1 (1<<18)
386 #define NV_RX_ERROR1 (1<<23)
387 #define NV_RX_ERROR2 (1<<24)
388 #define NV_RX_ERROR3 (1<<25)
389 #define NV_RX_ERROR4 (1<<26)
390 #define NV_RX_CRCERR (1<<27)
391 #define NV_RX_OVERFLOW (1<<28)
392 #define NV_RX_FRAMINGERR (1<<29)
393 #define NV_RX_ERROR (1<<30)
394 #define NV_RX_AVAIL (1<<31)
396 #define NV_RX2_CHECKSUMMASK (0x1C000000)
397 #define NV_RX2_CHECKSUMOK1 (0x10000000)
398 #define NV_RX2_CHECKSUMOK2 (0x14000000)
399 #define NV_RX2_CHECKSUMOK3 (0x18000000)
400 #define NV_RX2_DESCRIPTORVALID (1<<29)
401 #define NV_RX2_SUBSTRACT1 (1<<25)
402 #define NV_RX2_ERROR1 (1<<18)
403 #define NV_RX2_ERROR2 (1<<19)
404 #define NV_RX2_ERROR3 (1<<20)
405 #define NV_RX2_ERROR4 (1<<21)
406 #define NV_RX2_CRCERR (1<<22)
407 #define NV_RX2_OVERFLOW (1<<23)
408 #define NV_RX2_FRAMINGERR (1<<24)
409 /* error and avail are the same for both */
410 #define NV_RX2_ERROR (1<<30)
411 #define NV_RX2_AVAIL (1<<31)
413 #define NV_RX3_VLAN_TAG_PRESENT (1<<16)
414 #define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
416 /* Miscelaneous hardware related defines: */
417 #define NV_PCI_REGSZ 0x270
419 /* various timeout delays: all in usec */
420 #define NV_TXRX_RESET_DELAY 4
421 #define NV_TXSTOP_DELAY1 10
422 #define NV_TXSTOP_DELAY1MAX 500000
423 #define NV_TXSTOP_DELAY2 100
424 #define NV_RXSTOP_DELAY1 10
425 #define NV_RXSTOP_DELAY1MAX 500000
426 #define NV_RXSTOP_DELAY2 100
427 #define NV_SETUP5_DELAY 5
428 #define NV_SETUP5_DELAYMAX 50000
429 #define NV_POWERUP_DELAY 5
430 #define NV_POWERUP_DELAYMAX 5000
431 #define NV_MIIBUSY_DELAY 50
432 #define NV_MIIPHY_DELAY 10
433 #define NV_MIIPHY_DELAYMAX 10000
435 #define NV_WAKEUPPATTERNS 5
436 #define NV_WAKEUPMASKENTRIES 4
438 /* General driver defaults */
439 #define NV_WATCHDOG_TIMEO (5*HZ)
444 * If your nic mysteriously hangs then try to reduce the limits
445 * to 1/0: It might be required to set NV_TX_LASTPACKET in the
446 * last valid ring entry. But this would be impossible to
447 * implement - probably a disassembly error.
449 #define TX_LIMIT_STOP 255
450 #define TX_LIMIT_START 254
452 /* rx/tx mac addr + type + vlan + align + slack*/
453 #define NV_RX_HEADERS (64)
454 /* even more slack. */
455 #define NV_RX_ALLOC_PAD (64)
457 /* maximum mtu size */
458 #define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
459 #define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
461 #define OOM_REFILL (1+HZ/20)
462 #define POLL_WAIT (1+HZ/100)
463 #define LINK_TIMEOUT (3*HZ)
467 * The nic supports three different descriptor types:
468 * - DESC_VER_1: Original
469 * - DESC_VER_2: support for jumbo frames.
470 * - DESC_VER_3: 64-bit format.
477 #define PHY_OUI_MARVELL 0x5043
478 #define PHY_OUI_CICADA 0x03f1
479 #define PHYID1_OUI_MASK 0x03ff
480 #define PHYID1_OUI_SHFT 6
481 #define PHYID2_OUI_MASK 0xfc00
482 #define PHYID2_OUI_SHFT 10
483 #define PHY_INIT1 0x0f000
484 #define PHY_INIT2 0x0e00
485 #define PHY_INIT3 0x01000
486 #define PHY_INIT4 0x0200
487 #define PHY_INIT5 0x0004
488 #define PHY_INIT6 0x02000
489 #define PHY_GIGABIT 0x0100
491 #define PHY_TIMEOUT 0x1
492 #define PHY_ERROR 0x2
496 #define PHY_HALF 0x100
498 /* FIXME: MII defines that should be added to <linux/mii.h> */
499 #define MII_1000BT_CR 0x09
500 #define MII_1000BT_SR 0x0a
501 #define ADVERTISE_1000FULL 0x0200
502 #define ADVERTISE_1000HALF 0x0100
503 #define LPA_1000FULL 0x0800
504 #define LPA_1000HALF 0x0400
506 /* MSI/MSI-X defines */
507 #define NV_MSI_X_MAX_VECTORS 8
508 #define NV_MSI_X_VECTORS_MASK 0x000f
509 #define NV_MSI_CAPABLE 0x0010
510 #define NV_MSI_X_CAPABLE 0x0020
511 #define NV_MSI_ENABLED 0x0040
512 #define NV_MSI_X_ENABLED 0x0080
514 #define NV_MSI_X_VECTOR_ALL 0x0
515 #define NV_MSI_X_VECTOR_RX 0x0
516 #define NV_MSI_X_VECTOR_TX 0x1
517 #define NV_MSI_X_VECTOR_OTHER 0x2
521 * All hardware access under dev->priv->lock, except the performance
523 * - rx is (pseudo-) lockless: it relies on the single-threading provided
524 * by the arch code for interrupts.
525 * - tx setup is lockless: it relies on dev->xmit_lock. Actual submission
526 * needs dev->priv->lock :-(
527 * - set_multicast_list: preparation lockless, relies on dev->xmit_lock.
530 /* in dev: base, irq */
535 * Locking: spin_lock(&np->lock); */
536 struct net_device_stats stats;
544 unsigned int phy_oui;
547 /* General data: RO fields */
548 dma_addr_t ring_addr;
549 struct pci_dev *pci_dev;
558 /* rx specific fields.
559 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
562 unsigned int cur_rx, refill_rx;
563 struct sk_buff *rx_skbuff[RX_RING];
564 dma_addr_t rx_dma[RX_RING];
565 unsigned int rx_buf_sz;
566 unsigned int pkt_limit;
567 struct timer_list oom_kick;
568 struct timer_list nic_poll;
571 /* media detection workaround.
572 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
575 unsigned long link_timeout;
577 * tx specific fields.
580 unsigned int next_tx, nic_tx;
581 struct sk_buff *tx_skbuff[TX_RING];
582 dma_addr_t tx_dma[TX_RING];
583 unsigned int tx_dma_len[TX_RING];
587 struct vlan_group *vlangrp;
589 /* msi/msi-x fields */
591 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
595 * Maximum number of loops until we assume that a bit in the irq mask
596 * is stuck. Overridable with module param.
598 static int max_interrupt_work = 5;
601 * Optimization can be either throuput mode or cpu mode
603 * Throughput Mode: Every tx and rx packet will generate an interrupt.
604 * CPU Mode: Interrupts are controlled by a timer.
606 #define NV_OPTIMIZATION_MODE_THROUGHPUT 0
607 #define NV_OPTIMIZATION_MODE_CPU 1
608 static int optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
611 * Poll interval for timer irq
613 * This interval determines how frequent an interrupt is generated.
614 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
615 * Min = 0, and Max = 65535
617 static int poll_interval = -1;
620 * Disable MSI interrupts
622 static int disable_msi = 0;
625 * Disable MSIX interrupts
627 static int disable_msix = 0;
629 static inline struct fe_priv *get_nvpriv(struct net_device *dev)
631 return netdev_priv(dev);
634 static inline u8 __iomem *get_hwbase(struct net_device *dev)
636 return ((struct fe_priv *)netdev_priv(dev))->base;
639 static inline void pci_push(u8 __iomem *base)
641 /* force out pending posted writes */
645 static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
647 return le32_to_cpu(prd->FlagLen)
648 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
651 static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
653 return le32_to_cpu(prd->FlagLen) & LEN_MASK_V2;
656 static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
657 int delay, int delaymax, const char *msg)
659 u8 __iomem *base = get_hwbase(dev);
670 } while ((readl(base + offset) & mask) != target);
674 #define NV_SETUP_RX_RING 0x01
675 #define NV_SETUP_TX_RING 0x02
677 static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
679 struct fe_priv *np = get_nvpriv(dev);
680 u8 __iomem *base = get_hwbase(dev);
682 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
683 if (rxtx_flags & NV_SETUP_RX_RING) {
684 writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr);
686 if (rxtx_flags & NV_SETUP_TX_RING) {
687 writel((u32) cpu_to_le64(np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
690 if (rxtx_flags & NV_SETUP_RX_RING) {
691 writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr);
692 writel((u32) (cpu_to_le64(np->ring_addr) >> 32), base + NvRegRxRingPhysAddrHigh);
694 if (rxtx_flags & NV_SETUP_TX_RING) {
695 writel((u32) cpu_to_le64(np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
696 writel((u32) (cpu_to_le64(np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)) >> 32), base + NvRegTxRingPhysAddrHigh);
701 #define MII_READ (-1)
702 /* mii_rw: read/write a register on the PHY.
704 * Caller must guarantee serialization
706 static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
708 u8 __iomem *base = get_hwbase(dev);
712 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
714 reg = readl(base + NvRegMIIControl);
715 if (reg & NVREG_MIICTL_INUSE) {
716 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
717 udelay(NV_MIIBUSY_DELAY);
720 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
721 if (value != MII_READ) {
722 writel(value, base + NvRegMIIData);
723 reg |= NVREG_MIICTL_WRITE;
725 writel(reg, base + NvRegMIIControl);
727 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
728 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
729 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n",
730 dev->name, miireg, addr);
732 } else if (value != MII_READ) {
733 /* it was a write operation - fewer failures are detectable */
734 dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
735 dev->name, value, miireg, addr);
737 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
738 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n",
739 dev->name, miireg, addr);
742 retval = readl(base + NvRegMIIData);
743 dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
744 dev->name, miireg, addr, retval);
750 static int phy_reset(struct net_device *dev)
752 struct fe_priv *np = netdev_priv(dev);
754 unsigned int tries = 0;
756 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
757 miicontrol |= BMCR_RESET;
758 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) {
765 /* must wait till reset is deasserted */
766 while (miicontrol & BMCR_RESET) {
768 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
769 /* FIXME: 100 tries seem excessive */
776 static int phy_init(struct net_device *dev)
778 struct fe_priv *np = get_nvpriv(dev);
779 u8 __iomem *base = get_hwbase(dev);
780 u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg;
782 /* set advertise register */
783 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
784 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|0x800|0x400);
785 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
786 printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev));
790 /* get phy interface type */
791 phyinterface = readl(base + NvRegPhyInterface);
793 /* see if gigabit phy */
794 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
795 if (mii_status & PHY_GIGABIT) {
796 np->gigabit = PHY_GIGABIT;
797 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
798 mii_control_1000 &= ~ADVERTISE_1000HALF;
799 if (phyinterface & PHY_RGMII)
800 mii_control_1000 |= ADVERTISE_1000FULL;
802 mii_control_1000 &= ~ADVERTISE_1000FULL;
804 if (mii_rw(dev, np->phyaddr, MII_1000BT_CR, mii_control_1000)) {
805 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
813 if (phy_reset(dev)) {
814 printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev));
818 /* phy vendor specific configuration */
819 if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) {
820 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
821 phy_reserved &= ~(PHY_INIT1 | PHY_INIT2);
822 phy_reserved |= (PHY_INIT3 | PHY_INIT4);
823 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) {
824 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
827 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
828 phy_reserved |= PHY_INIT5;
829 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) {
830 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
834 if (np->phy_oui == PHY_OUI_CICADA) {
835 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
836 phy_reserved |= PHY_INIT6;
837 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) {
838 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
843 /* restart auto negotiation */
844 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
845 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
846 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
853 static void nv_start_rx(struct net_device *dev)
855 struct fe_priv *np = netdev_priv(dev);
856 u8 __iomem *base = get_hwbase(dev);
858 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
859 /* Already running? Stop it. */
860 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
861 writel(0, base + NvRegReceiverControl);
864 writel(np->linkspeed, base + NvRegLinkSpeed);
866 writel(NVREG_RCVCTL_START, base + NvRegReceiverControl);
867 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
868 dev->name, np->duplex, np->linkspeed);
872 static void nv_stop_rx(struct net_device *dev)
874 u8 __iomem *base = get_hwbase(dev);
876 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
877 writel(0, base + NvRegReceiverControl);
878 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
879 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
880 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
882 udelay(NV_RXSTOP_DELAY2);
883 writel(0, base + NvRegLinkSpeed);
886 static void nv_start_tx(struct net_device *dev)
888 u8 __iomem *base = get_hwbase(dev);
890 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
891 writel(NVREG_XMITCTL_START, base + NvRegTransmitterControl);
895 static void nv_stop_tx(struct net_device *dev)
897 u8 __iomem *base = get_hwbase(dev);
899 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
900 writel(0, base + NvRegTransmitterControl);
901 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
902 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
903 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
905 udelay(NV_TXSTOP_DELAY2);
906 writel(0, base + NvRegUnknownTransmitterReg);
909 static void nv_txrx_reset(struct net_device *dev)
911 struct fe_priv *np = netdev_priv(dev);
912 u8 __iomem *base = get_hwbase(dev);
914 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
915 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
917 udelay(NV_TXRX_RESET_DELAY);
918 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
923 * nv_get_stats: dev->get_stats function
924 * Get latest stats value from the nic.
925 * Called with read_lock(&dev_base_lock) held for read -
926 * only synchronized against unregister_netdevice.
928 static struct net_device_stats *nv_get_stats(struct net_device *dev)
930 struct fe_priv *np = netdev_priv(dev);
932 /* It seems that the nic always generates interrupts and doesn't
933 * accumulate errors internally. Thus the current values in np->stats
934 * are already up to date.
940 * nv_alloc_rx: fill rx ring entries.
941 * Return 1 if the allocations for the skbs failed and the
942 * rx engine is without Available descriptors
944 static int nv_alloc_rx(struct net_device *dev)
946 struct fe_priv *np = netdev_priv(dev);
947 unsigned int refill_rx = np->refill_rx;
950 while (np->cur_rx != refill_rx) {
953 nr = refill_rx % RX_RING;
954 if (np->rx_skbuff[nr] == NULL) {
956 skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
961 np->rx_skbuff[nr] = skb;
963 skb = np->rx_skbuff[nr];
965 np->rx_dma[nr] = pci_map_single(np->pci_dev, skb->data,
966 skb->end-skb->data, PCI_DMA_FROMDEVICE);
967 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
968 np->rx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->rx_dma[nr]);
970 np->rx_ring.orig[nr].FlagLen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
972 np->rx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->rx_dma[nr]) >> 32;
973 np->rx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->rx_dma[nr]) & 0x0FFFFFFFF;
975 np->rx_ring.ex[nr].FlagLen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
977 dprintk(KERN_DEBUG "%s: nv_alloc_rx: Packet %d marked as Available\n",
978 dev->name, refill_rx);
981 np->refill_rx = refill_rx;
982 if (np->cur_rx - refill_rx == RX_RING)
987 static void nv_do_rx_refill(unsigned long data)
989 struct net_device *dev = (struct net_device *) data;
990 struct fe_priv *np = netdev_priv(dev);
993 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
994 ((np->msi_flags & NV_MSI_X_ENABLED) &&
995 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1))) {
996 disable_irq(dev->irq);
998 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1000 if (nv_alloc_rx(dev)) {
1001 spin_lock(&np->lock);
1002 if (!np->in_shutdown)
1003 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
1004 spin_unlock(&np->lock);
1006 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
1007 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1008 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1))) {
1009 enable_irq(dev->irq);
1011 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1015 static void nv_init_rx(struct net_device *dev)
1017 struct fe_priv *np = netdev_priv(dev);
1020 np->cur_rx = RX_RING;
1022 for (i = 0; i < RX_RING; i++)
1023 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1024 np->rx_ring.orig[i].FlagLen = 0;
1026 np->rx_ring.ex[i].FlagLen = 0;
1029 static void nv_init_tx(struct net_device *dev)
1031 struct fe_priv *np = netdev_priv(dev);
1034 np->next_tx = np->nic_tx = 0;
1035 for (i = 0; i < TX_RING; i++) {
1036 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1037 np->tx_ring.orig[i].FlagLen = 0;
1039 np->tx_ring.ex[i].FlagLen = 0;
1040 np->tx_skbuff[i] = NULL;
1045 static int nv_init_ring(struct net_device *dev)
1049 return nv_alloc_rx(dev);
1052 static int nv_release_txskb(struct net_device *dev, unsigned int skbnr)
1054 struct fe_priv *np = netdev_priv(dev);
1056 dprintk(KERN_INFO "%s: nv_release_txskb for skbnr %d\n",
1059 if (np->tx_dma[skbnr]) {
1060 pci_unmap_page(np->pci_dev, np->tx_dma[skbnr],
1061 np->tx_dma_len[skbnr],
1063 np->tx_dma[skbnr] = 0;
1066 if (np->tx_skbuff[skbnr]) {
1067 dev_kfree_skb_any(np->tx_skbuff[skbnr]);
1068 np->tx_skbuff[skbnr] = NULL;
1075 static void nv_drain_tx(struct net_device *dev)
1077 struct fe_priv *np = netdev_priv(dev);
1080 for (i = 0; i < TX_RING; i++) {
1081 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1082 np->tx_ring.orig[i].FlagLen = 0;
1084 np->tx_ring.ex[i].FlagLen = 0;
1085 if (nv_release_txskb(dev, i))
1086 np->stats.tx_dropped++;
1090 static void nv_drain_rx(struct net_device *dev)
1092 struct fe_priv *np = netdev_priv(dev);
1094 for (i = 0; i < RX_RING; i++) {
1095 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1096 np->rx_ring.orig[i].FlagLen = 0;
1098 np->rx_ring.ex[i].FlagLen = 0;
1100 if (np->rx_skbuff[i]) {
1101 pci_unmap_single(np->pci_dev, np->rx_dma[i],
1102 np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
1103 PCI_DMA_FROMDEVICE);
1104 dev_kfree_skb(np->rx_skbuff[i]);
1105 np->rx_skbuff[i] = NULL;
1110 static void drain_ring(struct net_device *dev)
1117 * nv_start_xmit: dev->hard_start_xmit function
1118 * Called with dev->xmit_lock held.
1120 static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1122 struct fe_priv *np = netdev_priv(dev);
1124 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
1125 unsigned int fragments = skb_shinfo(skb)->nr_frags;
1126 unsigned int nr = (np->next_tx - 1) % TX_RING;
1127 unsigned int start_nr = np->next_tx % TX_RING;
1131 u32 size = skb->len-skb->data_len;
1132 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1133 u32 tx_flags_vlan = 0;
1135 /* add fragments to entries count */
1136 for (i = 0; i < fragments; i++) {
1137 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1138 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1141 spin_lock_irq(&np->lock);
1143 if ((np->next_tx - np->nic_tx + entries - 1) > TX_LIMIT_STOP) {
1144 spin_unlock_irq(&np->lock);
1145 netif_stop_queue(dev);
1146 return NETDEV_TX_BUSY;
1149 /* setup the header buffer */
1151 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
1152 nr = (nr + 1) % TX_RING;
1154 np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
1156 np->tx_dma_len[nr] = bcnt;
1158 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1159 np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]);
1160 np->tx_ring.orig[nr].FlagLen = cpu_to_le32((bcnt-1) | tx_flags);
1162 np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1163 np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1164 np->tx_ring.ex[nr].FlagLen = cpu_to_le32((bcnt-1) | tx_flags);
1166 tx_flags = np->tx_flags;
1171 /* setup the fragments */
1172 for (i = 0; i < fragments; i++) {
1173 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1174 u32 size = frag->size;
1178 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
1179 nr = (nr + 1) % TX_RING;
1181 np->tx_dma[nr] = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
1183 np->tx_dma_len[nr] = bcnt;
1185 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1186 np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]);
1187 np->tx_ring.orig[nr].FlagLen = cpu_to_le32((bcnt-1) | tx_flags);
1189 np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1190 np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1191 np->tx_ring.ex[nr].FlagLen = cpu_to_le32((bcnt-1) | tx_flags);
1198 /* set last fragment flag */
1199 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1200 np->tx_ring.orig[nr].FlagLen |= cpu_to_le32(tx_flags_extra);
1202 np->tx_ring.ex[nr].FlagLen |= cpu_to_le32(tx_flags_extra);
1205 np->tx_skbuff[nr] = skb;
1208 if (skb_shinfo(skb)->tso_size)
1209 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->tso_size << NV_TX2_TSO_SHIFT);
1212 tx_flags_extra = (skb->ip_summed == CHECKSUM_HW ? (NV_TX2_CHECKSUM_L3|NV_TX2_CHECKSUM_L4) : 0);
1215 if (np->vlangrp && vlan_tx_tag_present(skb)) {
1216 tx_flags_vlan = NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb);
1220 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1221 np->tx_ring.orig[start_nr].FlagLen |= cpu_to_le32(tx_flags | tx_flags_extra);
1223 np->tx_ring.ex[start_nr].TxVlan = cpu_to_le32(tx_flags_vlan);
1224 np->tx_ring.ex[start_nr].FlagLen |= cpu_to_le32(tx_flags | tx_flags_extra);
1227 dprintk(KERN_DEBUG "%s: nv_start_xmit: packet %d (entries %d) queued for transmission. tx_flags_extra: %x\n",
1228 dev->name, np->next_tx, entries, tx_flags_extra);
1231 for (j=0; j<64; j++) {
1233 dprintk("\n%03x:", j);
1234 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
1239 np->next_tx += entries;
1241 dev->trans_start = jiffies;
1242 spin_unlock_irq(&np->lock);
1243 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
1244 pci_push(get_hwbase(dev));
1245 return NETDEV_TX_OK;
1249 * nv_tx_done: check for completed packets, release the skbs.
1251 * Caller must own np->lock.
1253 static void nv_tx_done(struct net_device *dev)
1255 struct fe_priv *np = netdev_priv(dev);
1258 struct sk_buff *skb;
1260 while (np->nic_tx != np->next_tx) {
1261 i = np->nic_tx % TX_RING;
1263 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1264 Flags = le32_to_cpu(np->tx_ring.orig[i].FlagLen);
1266 Flags = le32_to_cpu(np->tx_ring.ex[i].FlagLen);
1268 dprintk(KERN_DEBUG "%s: nv_tx_done: looking at packet %d, Flags 0x%x.\n",
1269 dev->name, np->nic_tx, Flags);
1270 if (Flags & NV_TX_VALID)
1272 if (np->desc_ver == DESC_VER_1) {
1273 if (Flags & NV_TX_LASTPACKET) {
1274 skb = np->tx_skbuff[i];
1275 if (Flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION|
1276 NV_TX_UNDERFLOW|NV_TX_ERROR)) {
1277 if (Flags & NV_TX_UNDERFLOW)
1278 np->stats.tx_fifo_errors++;
1279 if (Flags & NV_TX_CARRIERLOST)
1280 np->stats.tx_carrier_errors++;
1281 np->stats.tx_errors++;
1283 np->stats.tx_packets++;
1284 np->stats.tx_bytes += skb->len;
1288 if (Flags & NV_TX2_LASTPACKET) {
1289 skb = np->tx_skbuff[i];
1290 if (Flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION|
1291 NV_TX2_UNDERFLOW|NV_TX2_ERROR)) {
1292 if (Flags & NV_TX2_UNDERFLOW)
1293 np->stats.tx_fifo_errors++;
1294 if (Flags & NV_TX2_CARRIERLOST)
1295 np->stats.tx_carrier_errors++;
1296 np->stats.tx_errors++;
1298 np->stats.tx_packets++;
1299 np->stats.tx_bytes += skb->len;
1303 nv_release_txskb(dev, i);
1306 if (np->next_tx - np->nic_tx < TX_LIMIT_START)
1307 netif_wake_queue(dev);
1311 * nv_tx_timeout: dev->tx_timeout function
1312 * Called with dev->xmit_lock held.
1314 static void nv_tx_timeout(struct net_device *dev)
1316 struct fe_priv *np = netdev_priv(dev);
1317 u8 __iomem *base = get_hwbase(dev);
1320 if (np->msi_flags & NV_MSI_X_ENABLED)
1321 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
1323 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
1325 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status);
1330 printk(KERN_INFO "%s: Ring at %lx: next %d nic %d\n",
1331 dev->name, (unsigned long)np->ring_addr,
1332 np->next_tx, np->nic_tx);
1333 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
1334 for (i=0;i<0x400;i+= 32) {
1335 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
1337 readl(base + i + 0), readl(base + i + 4),
1338 readl(base + i + 8), readl(base + i + 12),
1339 readl(base + i + 16), readl(base + i + 20),
1340 readl(base + i + 24), readl(base + i + 28));
1342 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
1343 for (i=0;i<TX_RING;i+= 4) {
1344 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1345 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
1347 le32_to_cpu(np->tx_ring.orig[i].PacketBuffer),
1348 le32_to_cpu(np->tx_ring.orig[i].FlagLen),
1349 le32_to_cpu(np->tx_ring.orig[i+1].PacketBuffer),
1350 le32_to_cpu(np->tx_ring.orig[i+1].FlagLen),
1351 le32_to_cpu(np->tx_ring.orig[i+2].PacketBuffer),
1352 le32_to_cpu(np->tx_ring.orig[i+2].FlagLen),
1353 le32_to_cpu(np->tx_ring.orig[i+3].PacketBuffer),
1354 le32_to_cpu(np->tx_ring.orig[i+3].FlagLen));
1356 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
1358 le32_to_cpu(np->tx_ring.ex[i].PacketBufferHigh),
1359 le32_to_cpu(np->tx_ring.ex[i].PacketBufferLow),
1360 le32_to_cpu(np->tx_ring.ex[i].FlagLen),
1361 le32_to_cpu(np->tx_ring.ex[i+1].PacketBufferHigh),
1362 le32_to_cpu(np->tx_ring.ex[i+1].PacketBufferLow),
1363 le32_to_cpu(np->tx_ring.ex[i+1].FlagLen),
1364 le32_to_cpu(np->tx_ring.ex[i+2].PacketBufferHigh),
1365 le32_to_cpu(np->tx_ring.ex[i+2].PacketBufferLow),
1366 le32_to_cpu(np->tx_ring.ex[i+2].FlagLen),
1367 le32_to_cpu(np->tx_ring.ex[i+3].PacketBufferHigh),
1368 le32_to_cpu(np->tx_ring.ex[i+3].PacketBufferLow),
1369 le32_to_cpu(np->tx_ring.ex[i+3].FlagLen));
1374 spin_lock_irq(&np->lock);
1376 /* 1) stop tx engine */
1379 /* 2) check that the packets were not sent already: */
1382 /* 3) if there are dead entries: clear everything */
1383 if (np->next_tx != np->nic_tx) {
1384 printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name);
1386 np->next_tx = np->nic_tx = 0;
1387 setup_hw_rings(dev, NV_SETUP_TX_RING);
1388 netif_wake_queue(dev);
1391 /* 4) restart tx engine */
1393 spin_unlock_irq(&np->lock);
1397 * Called when the nic notices a mismatch between the actual data len on the
1398 * wire and the len indicated in the 802 header
1400 static int nv_getlen(struct net_device *dev, void *packet, int datalen)
1402 int hdrlen; /* length of the 802 header */
1403 int protolen; /* length as stored in the proto field */
1405 /* 1) calculate len according to header */
1406 if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
1407 protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto );
1410 protolen = ntohs( ((struct ethhdr *)packet)->h_proto);
1413 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
1414 dev->name, datalen, protolen, hdrlen);
1415 if (protolen > ETH_DATA_LEN)
1416 return datalen; /* Value in proto field not a len, no checks possible */
1419 /* consistency checks: */
1420 if (datalen > ETH_ZLEN) {
1421 if (datalen >= protolen) {
1422 /* more data on wire than in 802 header, trim of
1425 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1426 dev->name, protolen);
1429 /* less data on wire than mentioned in header.
1430 * Discard the packet.
1432 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
1437 /* short packet. Accept only if 802 values are also short */
1438 if (protolen > ETH_ZLEN) {
1439 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
1443 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1444 dev->name, datalen);
1449 static void nv_rx_process(struct net_device *dev)
1451 struct fe_priv *np = netdev_priv(dev);
1457 struct sk_buff *skb;
1460 if (np->cur_rx - np->refill_rx >= RX_RING)
1461 break; /* we scanned the whole ring - do not continue */
1463 i = np->cur_rx % RX_RING;
1464 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1465 Flags = le32_to_cpu(np->rx_ring.orig[i].FlagLen);
1466 len = nv_descr_getlength(&np->rx_ring.orig[i], np->desc_ver);
1468 Flags = le32_to_cpu(np->rx_ring.ex[i].FlagLen);
1469 len = nv_descr_getlength_ex(&np->rx_ring.ex[i], np->desc_ver);
1470 vlanflags = le32_to_cpu(np->rx_ring.ex[i].PacketBufferLow);
1473 dprintk(KERN_DEBUG "%s: nv_rx_process: looking at packet %d, Flags 0x%x.\n",
1474 dev->name, np->cur_rx, Flags);
1476 if (Flags & NV_RX_AVAIL)
1477 break; /* still owned by hardware, */
1480 * the packet is for us - immediately tear down the pci mapping.
1481 * TODO: check if a prefetch of the first cacheline improves
1484 pci_unmap_single(np->pci_dev, np->rx_dma[i],
1485 np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
1486 PCI_DMA_FROMDEVICE);
1490 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",Flags);
1491 for (j=0; j<64; j++) {
1493 dprintk("\n%03x:", j);
1494 dprintk(" %02x", ((unsigned char*)np->rx_skbuff[i]->data)[j]);
1498 /* look at what we actually got: */
1499 if (np->desc_ver == DESC_VER_1) {
1500 if (!(Flags & NV_RX_DESCRIPTORVALID))
1503 if (Flags & NV_RX_ERROR) {
1504 if (Flags & NV_RX_MISSEDFRAME) {
1505 np->stats.rx_missed_errors++;
1506 np->stats.rx_errors++;
1509 if (Flags & (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3)) {
1510 np->stats.rx_errors++;
1513 if (Flags & NV_RX_CRCERR) {
1514 np->stats.rx_crc_errors++;
1515 np->stats.rx_errors++;
1518 if (Flags & NV_RX_OVERFLOW) {
1519 np->stats.rx_over_errors++;
1520 np->stats.rx_errors++;
1523 if (Flags & NV_RX_ERROR4) {
1524 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1526 np->stats.rx_errors++;
1530 /* framing errors are soft errors. */
1531 if (Flags & NV_RX_FRAMINGERR) {
1532 if (Flags & NV_RX_SUBSTRACT1) {
1538 if (!(Flags & NV_RX2_DESCRIPTORVALID))
1541 if (Flags & NV_RX2_ERROR) {
1542 if (Flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) {
1543 np->stats.rx_errors++;
1546 if (Flags & NV_RX2_CRCERR) {
1547 np->stats.rx_crc_errors++;
1548 np->stats.rx_errors++;
1551 if (Flags & NV_RX2_OVERFLOW) {
1552 np->stats.rx_over_errors++;
1553 np->stats.rx_errors++;
1556 if (Flags & NV_RX2_ERROR4) {
1557 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1559 np->stats.rx_errors++;
1563 /* framing errors are soft errors */
1564 if (Flags & NV_RX2_FRAMINGERR) {
1565 if (Flags & NV_RX2_SUBSTRACT1) {
1570 Flags &= NV_RX2_CHECKSUMMASK;
1571 if (Flags == NV_RX2_CHECKSUMOK1 ||
1572 Flags == NV_RX2_CHECKSUMOK2 ||
1573 Flags == NV_RX2_CHECKSUMOK3) {
1574 dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name);
1575 np->rx_skbuff[i]->ip_summed = CHECKSUM_UNNECESSARY;
1577 dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name);
1580 /* got a valid packet - forward it to the network core */
1581 skb = np->rx_skbuff[i];
1582 np->rx_skbuff[i] = NULL;
1585 skb->protocol = eth_type_trans(skb, dev);
1586 dprintk(KERN_DEBUG "%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n",
1587 dev->name, np->cur_rx, len, skb->protocol);
1588 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT)) {
1589 vlan_hwaccel_rx(skb, np->vlangrp, vlanflags & NV_RX3_VLAN_TAG_MASK);
1593 dev->last_rx = jiffies;
1594 np->stats.rx_packets++;
1595 np->stats.rx_bytes += len;
1601 static void set_bufsize(struct net_device *dev)
1603 struct fe_priv *np = netdev_priv(dev);
1605 if (dev->mtu <= ETH_DATA_LEN)
1606 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
1608 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
1612 * nv_change_mtu: dev->change_mtu function
1613 * Called with dev_base_lock held for read.
1615 static int nv_change_mtu(struct net_device *dev, int new_mtu)
1617 struct fe_priv *np = netdev_priv(dev);
1620 if (new_mtu < 64 || new_mtu > np->pkt_limit)
1626 /* return early if the buffer sizes will not change */
1627 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
1629 if (old_mtu == new_mtu)
1632 /* synchronized against open : rtnl_lock() held by caller */
1633 if (netif_running(dev)) {
1634 u8 __iomem *base = get_hwbase(dev);
1636 * It seems that the nic preloads valid ring entries into an
1637 * internal buffer. The procedure for flushing everything is
1638 * guessed, there is probably a simpler approach.
1639 * Changing the MTU is a rare event, it shouldn't matter.
1641 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
1642 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1643 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1))) {
1644 disable_irq(dev->irq);
1646 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1647 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1648 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1650 spin_lock_bh(&dev->xmit_lock);
1651 spin_lock(&np->lock);
1656 /* drain rx queue */
1659 /* reinit driver view of the rx queue */
1662 /* alloc new rx buffers */
1664 if (nv_alloc_rx(dev)) {
1665 if (!np->in_shutdown)
1666 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
1668 /* reinit nic view of the rx queue */
1669 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
1670 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
1671 writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT),
1672 base + NvRegRingSizes);
1674 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
1677 /* restart rx engine */
1680 spin_unlock(&np->lock);
1681 spin_unlock_bh(&dev->xmit_lock);
1682 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
1683 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1684 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1))) {
1685 enable_irq(dev->irq);
1687 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1688 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1689 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1695 static void nv_copy_mac_to_hw(struct net_device *dev)
1697 u8 __iomem *base = get_hwbase(dev);
1700 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
1701 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
1702 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
1704 writel(mac[0], base + NvRegMacAddrA);
1705 writel(mac[1], base + NvRegMacAddrB);
1709 * nv_set_mac_address: dev->set_mac_address function
1710 * Called with rtnl_lock() held.
1712 static int nv_set_mac_address(struct net_device *dev, void *addr)
1714 struct fe_priv *np = netdev_priv(dev);
1715 struct sockaddr *macaddr = (struct sockaddr*)addr;
1717 if(!is_valid_ether_addr(macaddr->sa_data))
1718 return -EADDRNOTAVAIL;
1720 /* synchronized against open : rtnl_lock() held by caller */
1721 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
1723 if (netif_running(dev)) {
1724 spin_lock_bh(&dev->xmit_lock);
1725 spin_lock_irq(&np->lock);
1727 /* stop rx engine */
1730 /* set mac address */
1731 nv_copy_mac_to_hw(dev);
1733 /* restart rx engine */
1735 spin_unlock_irq(&np->lock);
1736 spin_unlock_bh(&dev->xmit_lock);
1738 nv_copy_mac_to_hw(dev);
1744 * nv_set_multicast: dev->set_multicast function
1745 * Called with dev->xmit_lock held.
1747 static void nv_set_multicast(struct net_device *dev)
1749 struct fe_priv *np = netdev_priv(dev);
1750 u8 __iomem *base = get_hwbase(dev);
1755 memset(addr, 0, sizeof(addr));
1756 memset(mask, 0, sizeof(mask));
1758 if (dev->flags & IFF_PROMISC) {
1759 printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
1760 pff = NVREG_PFF_PROMISC;
1762 pff = NVREG_PFF_MYADDR;
1764 if (dev->flags & IFF_ALLMULTI || dev->mc_list) {
1768 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
1769 if (dev->flags & IFF_ALLMULTI) {
1770 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
1772 struct dev_mc_list *walk;
1774 walk = dev->mc_list;
1775 while (walk != NULL) {
1777 a = le32_to_cpu(*(u32 *) walk->dmi_addr);
1778 b = le16_to_cpu(*(u16 *) (&walk->dmi_addr[4]));
1786 addr[0] = alwaysOn[0];
1787 addr[1] = alwaysOn[1];
1788 mask[0] = alwaysOn[0] | alwaysOff[0];
1789 mask[1] = alwaysOn[1] | alwaysOff[1];
1792 addr[0] |= NVREG_MCASTADDRA_FORCE;
1793 pff |= NVREG_PFF_ALWAYS;
1794 spin_lock_irq(&np->lock);
1796 writel(addr[0], base + NvRegMulticastAddrA);
1797 writel(addr[1], base + NvRegMulticastAddrB);
1798 writel(mask[0], base + NvRegMulticastMaskA);
1799 writel(mask[1], base + NvRegMulticastMaskB);
1800 writel(pff, base + NvRegPacketFilterFlags);
1801 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
1804 spin_unlock_irq(&np->lock);
1808 * nv_update_linkspeed: Setup the MAC according to the link partner
1809 * @dev: Network device to be configured
1811 * The function queries the PHY and checks if there is a link partner.
1812 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
1813 * set to 10 MBit HD.
1815 * The function returns 0 if there is no link partner and 1 if there is
1816 * a good link partner.
1818 static int nv_update_linkspeed(struct net_device *dev)
1820 struct fe_priv *np = netdev_priv(dev);
1821 u8 __iomem *base = get_hwbase(dev);
1823 int newls = np->linkspeed;
1824 int newdup = np->duplex;
1827 u32 control_1000, status_1000, phyreg;
1829 /* BMSR_LSTATUS is latched, read it twice:
1830 * we want the current value.
1832 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1833 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1835 if (!(mii_status & BMSR_LSTATUS)) {
1836 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
1838 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1844 if (np->autoneg == 0) {
1845 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
1846 dev->name, np->fixed_mode);
1847 if (np->fixed_mode & LPA_100FULL) {
1848 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
1850 } else if (np->fixed_mode & LPA_100HALF) {
1851 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
1853 } else if (np->fixed_mode & LPA_10FULL) {
1854 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1857 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1863 /* check auto negotiation is complete */
1864 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
1865 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
1866 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1869 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
1874 if (np->gigabit == PHY_GIGABIT) {
1875 control_1000 = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
1876 status_1000 = mii_rw(dev, np->phyaddr, MII_1000BT_SR, MII_READ);
1878 if ((control_1000 & ADVERTISE_1000FULL) &&
1879 (status_1000 & LPA_1000FULL)) {
1880 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
1882 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
1888 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
1889 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
1890 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
1891 dev->name, adv, lpa);
1893 /* FIXME: handle parallel detection properly */
1895 if (lpa & LPA_100FULL) {
1896 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
1898 } else if (lpa & LPA_100HALF) {
1899 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
1901 } else if (lpa & LPA_10FULL) {
1902 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1904 } else if (lpa & LPA_10HALF) {
1905 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1908 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, lpa);
1909 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
1914 if (np->duplex == newdup && np->linkspeed == newls)
1917 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
1918 dev->name, np->linkspeed, np->duplex, newls, newdup);
1920 np->duplex = newdup;
1921 np->linkspeed = newls;
1923 if (np->gigabit == PHY_GIGABIT) {
1924 phyreg = readl(base + NvRegRandomSeed);
1925 phyreg &= ~(0x3FF00);
1926 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
1927 phyreg |= NVREG_RNDSEED_FORCE3;
1928 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
1929 phyreg |= NVREG_RNDSEED_FORCE2;
1930 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
1931 phyreg |= NVREG_RNDSEED_FORCE;
1932 writel(phyreg, base + NvRegRandomSeed);
1935 phyreg = readl(base + NvRegPhyInterface);
1936 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
1937 if (np->duplex == 0)
1939 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
1941 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
1943 writel(phyreg, base + NvRegPhyInterface);
1945 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
1948 writel(np->linkspeed, base + NvRegLinkSpeed);
1954 static void nv_linkchange(struct net_device *dev)
1956 if (nv_update_linkspeed(dev)) {
1957 if (!netif_carrier_ok(dev)) {
1958 netif_carrier_on(dev);
1959 printk(KERN_INFO "%s: link up.\n", dev->name);
1963 if (netif_carrier_ok(dev)) {
1964 netif_carrier_off(dev);
1965 printk(KERN_INFO "%s: link down.\n", dev->name);
1971 static void nv_link_irq(struct net_device *dev)
1973 u8 __iomem *base = get_hwbase(dev);
1976 miistat = readl(base + NvRegMIIStatus);
1977 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
1978 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
1980 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
1982 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
1985 static irqreturn_t nv_nic_irq(int foo, void *data, struct pt_regs *regs)
1987 struct net_device *dev = (struct net_device *) data;
1988 struct fe_priv *np = netdev_priv(dev);
1989 u8 __iomem *base = get_hwbase(dev);
1993 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
1996 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
1997 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
1998 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2000 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2001 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
2004 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2005 if (!(events & np->irqmask))
2008 spin_lock(&np->lock);
2010 spin_unlock(&np->lock);
2013 if (nv_alloc_rx(dev)) {
2014 spin_lock(&np->lock);
2015 if (!np->in_shutdown)
2016 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2017 spin_unlock(&np->lock);
2020 if (events & NVREG_IRQ_LINK) {
2021 spin_lock(&np->lock);
2023 spin_unlock(&np->lock);
2025 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
2026 spin_lock(&np->lock);
2028 spin_unlock(&np->lock);
2029 np->link_timeout = jiffies + LINK_TIMEOUT;
2031 if (events & (NVREG_IRQ_TX_ERR)) {
2032 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2035 if (events & (NVREG_IRQ_UNKNOWN)) {
2036 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2039 if (i > max_interrupt_work) {
2040 spin_lock(&np->lock);
2041 /* disable interrupts on the nic */
2042 if (!(np->msi_flags & NV_MSI_X_ENABLED))
2043 writel(0, base + NvRegIrqMask);
2045 writel(np->irqmask, base + NvRegIrqMask);
2048 if (!np->in_shutdown) {
2049 np->nic_poll_irq = np->irqmask;
2050 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2052 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
2053 spin_unlock(&np->lock);
2058 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
2060 return IRQ_RETVAL(i);
2063 static irqreturn_t nv_nic_irq_tx(int foo, void *data, struct pt_regs *regs)
2065 struct net_device *dev = (struct net_device *) data;
2066 struct fe_priv *np = netdev_priv(dev);
2067 u8 __iomem *base = get_hwbase(dev);
2071 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
2074 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
2075 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
2077 dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
2078 if (!(events & np->irqmask))
2081 spin_lock(&np->lock);
2083 spin_unlock(&np->lock);
2085 if (events & (NVREG_IRQ_TX_ERR)) {
2086 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2089 if (i > max_interrupt_work) {
2090 spin_lock(&np->lock);
2091 /* disable interrupts on the nic */
2092 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
2095 if (!np->in_shutdown) {
2096 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
2097 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2099 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
2100 spin_unlock(&np->lock);
2105 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
2107 return IRQ_RETVAL(i);
2110 static irqreturn_t nv_nic_irq_rx(int foo, void *data, struct pt_regs *regs)
2112 struct net_device *dev = (struct net_device *) data;
2113 struct fe_priv *np = netdev_priv(dev);
2114 u8 __iomem *base = get_hwbase(dev);
2118 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name);
2121 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
2122 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
2124 dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
2125 if (!(events & np->irqmask))
2129 if (nv_alloc_rx(dev)) {
2130 spin_lock(&np->lock);
2131 if (!np->in_shutdown)
2132 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2133 spin_unlock(&np->lock);
2136 if (i > max_interrupt_work) {
2137 spin_lock(&np->lock);
2138 /* disable interrupts on the nic */
2139 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2142 if (!np->in_shutdown) {
2143 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
2144 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2146 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
2147 spin_unlock(&np->lock);
2152 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
2154 return IRQ_RETVAL(i);
2157 static irqreturn_t nv_nic_irq_other(int foo, void *data, struct pt_regs *regs)
2159 struct net_device *dev = (struct net_device *) data;
2160 struct fe_priv *np = netdev_priv(dev);
2161 u8 __iomem *base = get_hwbase(dev);
2165 dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
2168 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
2169 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
2171 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2172 if (!(events & np->irqmask))
2175 if (events & NVREG_IRQ_LINK) {
2176 spin_lock(&np->lock);
2178 spin_unlock(&np->lock);
2180 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
2181 spin_lock(&np->lock);
2183 spin_unlock(&np->lock);
2184 np->link_timeout = jiffies + LINK_TIMEOUT;
2186 if (events & (NVREG_IRQ_UNKNOWN)) {
2187 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2190 if (i > max_interrupt_work) {
2191 spin_lock(&np->lock);
2192 /* disable interrupts on the nic */
2193 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
2196 if (!np->in_shutdown) {
2197 np->nic_poll_irq |= NVREG_IRQ_OTHER;
2198 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2200 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
2201 spin_unlock(&np->lock);
2206 dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
2208 return IRQ_RETVAL(i);
2211 static void nv_do_nic_poll(unsigned long data)
2213 struct net_device *dev = (struct net_device *) data;
2214 struct fe_priv *np = netdev_priv(dev);
2215 u8 __iomem *base = get_hwbase(dev);
2219 * First disable irq(s) and then
2220 * reenable interrupts on the nic, we have to do this before calling
2221 * nv_nic_irq because that may decide to do otherwise
2224 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
2225 ((np->msi_flags & NV_MSI_X_ENABLED) &&
2226 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1))) {
2227 disable_irq(dev->irq);
2230 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
2231 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
2232 mask |= NVREG_IRQ_RX_ALL;
2234 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
2235 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
2236 mask |= NVREG_IRQ_TX_ALL;
2238 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
2239 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
2240 mask |= NVREG_IRQ_OTHER;
2243 np->nic_poll_irq = 0;
2245 /* FIXME: Do we need synchronize_irq(dev->irq) here? */
2247 writel(mask, base + NvRegIrqMask);
2250 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
2251 ((np->msi_flags & NV_MSI_X_ENABLED) &&
2252 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1))) {
2253 nv_nic_irq((int) 0, (void *) data, (struct pt_regs *) NULL);
2254 enable_irq(dev->irq);
2256 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
2257 nv_nic_irq_rx((int) 0, (void *) data, (struct pt_regs *) NULL);
2258 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
2260 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
2261 nv_nic_irq_tx((int) 0, (void *) data, (struct pt_regs *) NULL);
2262 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
2264 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
2265 nv_nic_irq_other((int) 0, (void *) data, (struct pt_regs *) NULL);
2266 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
2271 #ifdef CONFIG_NET_POLL_CONTROLLER
2272 static void nv_poll_controller(struct net_device *dev)
2274 nv_do_nic_poll((unsigned long) dev);
2278 static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2280 struct fe_priv *np = netdev_priv(dev);
2281 strcpy(info->driver, "forcedeth");
2282 strcpy(info->version, FORCEDETH_VERSION);
2283 strcpy(info->bus_info, pci_name(np->pci_dev));
2286 static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
2288 struct fe_priv *np = netdev_priv(dev);
2289 wolinfo->supported = WAKE_MAGIC;
2291 spin_lock_irq(&np->lock);
2293 wolinfo->wolopts = WAKE_MAGIC;
2294 spin_unlock_irq(&np->lock);
2297 static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
2299 struct fe_priv *np = netdev_priv(dev);
2300 u8 __iomem *base = get_hwbase(dev);
2302 spin_lock_irq(&np->lock);
2303 if (wolinfo->wolopts == 0) {
2304 writel(0, base + NvRegWakeUpFlags);
2307 if (wolinfo->wolopts & WAKE_MAGIC) {
2308 writel(NVREG_WAKEUPFLAGS_ENABLE, base + NvRegWakeUpFlags);
2311 spin_unlock_irq(&np->lock);
2315 static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2317 struct fe_priv *np = netdev_priv(dev);
2320 spin_lock_irq(&np->lock);
2321 ecmd->port = PORT_MII;
2322 if (!netif_running(dev)) {
2323 /* We do not track link speed / duplex setting if the
2324 * interface is disabled. Force a link check */
2325 nv_update_linkspeed(dev);
2327 switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) {
2328 case NVREG_LINKSPEED_10:
2329 ecmd->speed = SPEED_10;
2331 case NVREG_LINKSPEED_100:
2332 ecmd->speed = SPEED_100;
2334 case NVREG_LINKSPEED_1000:
2335 ecmd->speed = SPEED_1000;
2338 ecmd->duplex = DUPLEX_HALF;
2340 ecmd->duplex = DUPLEX_FULL;
2342 ecmd->autoneg = np->autoneg;
2344 ecmd->advertising = ADVERTISED_MII;
2346 ecmd->advertising |= ADVERTISED_Autoneg;
2347 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2349 adv = np->fixed_mode;
2351 if (adv & ADVERTISE_10HALF)
2352 ecmd->advertising |= ADVERTISED_10baseT_Half;
2353 if (adv & ADVERTISE_10FULL)
2354 ecmd->advertising |= ADVERTISED_10baseT_Full;
2355 if (adv & ADVERTISE_100HALF)
2356 ecmd->advertising |= ADVERTISED_100baseT_Half;
2357 if (adv & ADVERTISE_100FULL)
2358 ecmd->advertising |= ADVERTISED_100baseT_Full;
2359 if (np->autoneg && np->gigabit == PHY_GIGABIT) {
2360 adv = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
2361 if (adv & ADVERTISE_1000FULL)
2362 ecmd->advertising |= ADVERTISED_1000baseT_Full;
2365 ecmd->supported = (SUPPORTED_Autoneg |
2366 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
2367 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
2369 if (np->gigabit == PHY_GIGABIT)
2370 ecmd->supported |= SUPPORTED_1000baseT_Full;
2372 ecmd->phy_address = np->phyaddr;
2373 ecmd->transceiver = XCVR_EXTERNAL;
2375 /* ignore maxtxpkt, maxrxpkt for now */
2376 spin_unlock_irq(&np->lock);
2380 static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
2382 struct fe_priv *np = netdev_priv(dev);
2384 if (ecmd->port != PORT_MII)
2386 if (ecmd->transceiver != XCVR_EXTERNAL)
2388 if (ecmd->phy_address != np->phyaddr) {
2389 /* TODO: support switching between multiple phys. Should be
2390 * trivial, but not enabled due to lack of test hardware. */
2393 if (ecmd->autoneg == AUTONEG_ENABLE) {
2396 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
2397 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
2398 if (np->gigabit == PHY_GIGABIT)
2399 mask |= ADVERTISED_1000baseT_Full;
2401 if ((ecmd->advertising & mask) == 0)
2404 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
2405 /* Note: autonegotiation disable, speed 1000 intentionally
2406 * forbidden - noone should need that. */
2408 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
2410 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
2416 spin_lock_irq(&np->lock);
2417 if (ecmd->autoneg == AUTONEG_ENABLE) {
2422 /* advertise only what has been requested */
2423 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2424 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
2425 if (ecmd->advertising & ADVERTISED_10baseT_Half)
2426 adv |= ADVERTISE_10HALF;
2427 if (ecmd->advertising & ADVERTISED_10baseT_Full)
2428 adv |= ADVERTISE_10FULL;
2429 if (ecmd->advertising & ADVERTISED_100baseT_Half)
2430 adv |= ADVERTISE_100HALF;
2431 if (ecmd->advertising & ADVERTISED_100baseT_Full)
2432 adv |= ADVERTISE_100FULL;
2433 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
2435 if (np->gigabit == PHY_GIGABIT) {
2436 adv = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
2437 adv &= ~ADVERTISE_1000FULL;
2438 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
2439 adv |= ADVERTISE_1000FULL;
2440 mii_rw(dev, np->phyaddr, MII_1000BT_CR, adv);
2443 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
2444 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
2445 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
2452 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2453 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
2454 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
2455 adv |= ADVERTISE_10HALF;
2456 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
2457 adv |= ADVERTISE_10FULL;
2458 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
2459 adv |= ADVERTISE_100HALF;
2460 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
2461 adv |= ADVERTISE_100FULL;
2462 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
2463 np->fixed_mode = adv;
2465 if (np->gigabit == PHY_GIGABIT) {
2466 adv = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ);
2467 adv &= ~ADVERTISE_1000FULL;
2468 mii_rw(dev, np->phyaddr, MII_1000BT_CR, adv);
2471 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
2472 bmcr |= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_FULLDPLX);
2473 if (adv & (ADVERTISE_10FULL|ADVERTISE_100FULL))
2474 bmcr |= BMCR_FULLDPLX;
2475 if (adv & (ADVERTISE_100HALF|ADVERTISE_100FULL))
2476 bmcr |= BMCR_SPEED100;
2477 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
2479 if (netif_running(dev)) {
2480 /* Wait a bit and then reconfigure the nic. */
2485 spin_unlock_irq(&np->lock);
2490 #define FORCEDETH_REGS_VER 1
2491 #define FORCEDETH_REGS_SIZE 0x400 /* 256 32-bit registers */
2493 static int nv_get_regs_len(struct net_device *dev)
2495 return FORCEDETH_REGS_SIZE;
2498 static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
2500 struct fe_priv *np = netdev_priv(dev);
2501 u8 __iomem *base = get_hwbase(dev);
2505 regs->version = FORCEDETH_REGS_VER;
2506 spin_lock_irq(&np->lock);
2507 for (i=0;i<FORCEDETH_REGS_SIZE/sizeof(u32);i++)
2508 rbuf[i] = readl(base + i*sizeof(u32));
2509 spin_unlock_irq(&np->lock);
2512 static int nv_nway_reset(struct net_device *dev)
2514 struct fe_priv *np = netdev_priv(dev);
2517 spin_lock_irq(&np->lock);
2521 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
2522 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
2523 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
2529 spin_unlock_irq(&np->lock);
2534 static struct ethtool_ops ops = {
2535 .get_drvinfo = nv_get_drvinfo,
2536 .get_link = ethtool_op_get_link,
2537 .get_wol = nv_get_wol,
2538 .set_wol = nv_set_wol,
2539 .get_settings = nv_get_settings,
2540 .set_settings = nv_set_settings,
2541 .get_regs_len = nv_get_regs_len,
2542 .get_regs = nv_get_regs,
2543 .nway_reset = nv_nway_reset,
2544 .get_perm_addr = ethtool_op_get_perm_addr,
2547 static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
2549 struct fe_priv *np = get_nvpriv(dev);
2551 spin_lock_irq(&np->lock);
2553 /* save vlan group */
2557 /* enable vlan on MAC */
2558 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS;
2560 /* disable vlan on MAC */
2561 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
2562 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
2565 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2567 spin_unlock_irq(&np->lock);
2570 static void nv_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2575 static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
2577 u8 __iomem *base = get_hwbase(dev);
2581 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
2582 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
2583 * the remaining 8 interrupts.
2585 for (i = 0; i < 8; i++) {
2586 if ((irqmask >> i) & 0x1) {
2587 msixmap |= vector << (i << 2);
2590 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
2593 for (i = 0; i < 8; i++) {
2594 if ((irqmask >> (i + 8)) & 0x1) {
2595 msixmap |= vector << (i << 2);
2598 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
2601 static int nv_open(struct net_device *dev)
2603 struct fe_priv *np = netdev_priv(dev);
2604 u8 __iomem *base = get_hwbase(dev);
2608 dprintk(KERN_DEBUG "nv_open: begin\n");
2610 /* 1) erase previous misconfiguration */
2611 /* 4.1-1: stop adapter: ignored, 4.3 seems to be overkill */
2612 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
2613 writel(0, base + NvRegMulticastAddrB);
2614 writel(0, base + NvRegMulticastMaskA);
2615 writel(0, base + NvRegMulticastMaskB);
2616 writel(0, base + NvRegPacketFilterFlags);
2618 writel(0, base + NvRegTransmitterControl);
2619 writel(0, base + NvRegReceiverControl);
2621 writel(0, base + NvRegAdapterControl);
2623 /* 2) initialize descriptor rings */
2625 oom = nv_init_ring(dev);
2627 writel(0, base + NvRegLinkSpeed);
2628 writel(0, base + NvRegUnknownTransmitterReg);
2630 writel(0, base + NvRegUnknownSetupReg6);
2632 np->in_shutdown = 0;
2634 /* 3) set mac address */
2635 nv_copy_mac_to_hw(dev);
2637 /* 4) give hw rings */
2638 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
2639 writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT),
2640 base + NvRegRingSizes);
2642 /* 5) continue setup */
2643 writel(np->linkspeed, base + NvRegLinkSpeed);
2644 writel(NVREG_UNKSETUP3_VAL1, base + NvRegUnknownSetupReg3);
2645 writel(np->txrxctl_bits, base + NvRegTxRxControl);
2646 writel(np->vlanctl_bits, base + NvRegVlanControl);
2648 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
2649 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
2650 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
2651 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
2653 writel(0, base + NvRegUnknownSetupReg4);
2654 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2655 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
2657 /* 6) continue setup */
2658 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
2659 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
2660 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
2661 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
2663 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
2664 get_random_bytes(&i, sizeof(i));
2665 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed);
2666 writel(NVREG_UNKSETUP1_VAL, base + NvRegUnknownSetupReg1);
2667 writel(NVREG_UNKSETUP2_VAL, base + NvRegUnknownSetupReg2);
2668 if (poll_interval == -1) {
2669 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
2670 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
2672 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
2675 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
2676 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
2677 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
2678 base + NvRegAdapterControl);
2679 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
2680 writel(NVREG_UNKSETUP4_VAL, base + NvRegUnknownSetupReg4);
2681 writel(NVREG_WAKEUPFLAGS_VAL, base + NvRegWakeUpFlags);
2683 i = readl(base + NvRegPowerState);
2684 if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0)
2685 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
2689 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
2691 writel(0, base + NvRegIrqMask);
2693 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
2694 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2697 if (np->msi_flags & NV_MSI_X_CAPABLE) {
2698 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
2699 np->msi_x_entry[i].entry = i;
2701 if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) {
2702 np->msi_flags |= NV_MSI_X_ENABLED;
2703 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) {
2704 /* Request irq for rx handling */
2705 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, &nv_nic_irq_rx, SA_SHIRQ, dev->name, dev) != 0) {
2706 printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret);
2707 pci_disable_msix(np->pci_dev);
2708 np->msi_flags &= ~NV_MSI_X_ENABLED;
2711 /* Request irq for tx handling */
2712 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, &nv_nic_irq_tx, SA_SHIRQ, dev->name, dev) != 0) {
2713 printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret);
2714 pci_disable_msix(np->pci_dev);
2715 np->msi_flags &= ~NV_MSI_X_ENABLED;
2718 /* Request irq for link and timer handling */
2719 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector, &nv_nic_irq_other, SA_SHIRQ, dev->name, dev) != 0) {
2720 printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret);
2721 pci_disable_msix(np->pci_dev);
2722 np->msi_flags &= ~NV_MSI_X_ENABLED;
2726 /* map interrupts to their respective vector */
2727 writel(0, base + NvRegMSIXMap0);
2728 writel(0, base + NvRegMSIXMap1);
2729 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
2730 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
2731 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
2733 /* Request irq for all interrupts */
2734 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, &nv_nic_irq, SA_SHIRQ, dev->name, dev) != 0) {
2735 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
2736 pci_disable_msix(np->pci_dev);
2737 np->msi_flags &= ~NV_MSI_X_ENABLED;
2741 /* map interrupts to vector 0 */
2742 writel(0, base + NvRegMSIXMap0);
2743 writel(0, base + NvRegMSIXMap1);
2747 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
2748 if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
2749 np->msi_flags |= NV_MSI_ENABLED;
2750 if (request_irq(np->pci_dev->irq, &nv_nic_irq, SA_SHIRQ, dev->name, dev) != 0) {
2751 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
2752 pci_disable_msi(np->pci_dev);
2753 np->msi_flags &= ~NV_MSI_ENABLED;
2757 /* map interrupts to vector 0 */
2758 writel(0, base + NvRegMSIMap0);
2759 writel(0, base + NvRegMSIMap1);
2760 /* enable msi vector 0 */
2761 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
2765 if (request_irq(np->pci_dev->irq, &nv_nic_irq, SA_SHIRQ, dev->name, dev) != 0)
2769 /* ask for interrupts */
2770 writel(np->irqmask, base + NvRegIrqMask);
2772 spin_lock_irq(&np->lock);
2773 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
2774 writel(0, base + NvRegMulticastAddrB);
2775 writel(0, base + NvRegMulticastMaskA);
2776 writel(0, base + NvRegMulticastMaskB);
2777 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
2778 /* One manual link speed update: Interrupts are enabled, future link
2779 * speed changes cause interrupts and are handled by nv_link_irq().
2783 miistat = readl(base + NvRegMIIStatus);
2784 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
2785 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
2787 /* set linkspeed to invalid value, thus force nv_update_linkspeed
2790 ret = nv_update_linkspeed(dev);
2793 netif_start_queue(dev);
2795 netif_carrier_on(dev);
2797 printk("%s: no link during initialization.\n", dev->name);
2798 netif_carrier_off(dev);
2801 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2802 spin_unlock_irq(&np->lock);
2810 static int nv_close(struct net_device *dev)
2812 struct fe_priv *np = netdev_priv(dev);
2816 spin_lock_irq(&np->lock);
2817 np->in_shutdown = 1;
2818 spin_unlock_irq(&np->lock);
2819 synchronize_irq(dev->irq);
2821 del_timer_sync(&np->oom_kick);
2822 del_timer_sync(&np->nic_poll);
2824 netif_stop_queue(dev);
2825 spin_lock_irq(&np->lock);
2830 /* disable interrupts on the nic or we will lock up */
2831 base = get_hwbase(dev);
2832 if (np->msi_flags & NV_MSI_X_ENABLED) {
2833 writel(np->irqmask, base + NvRegIrqMask);
2835 if (np->msi_flags & NV_MSI_ENABLED)
2836 writel(0, base + NvRegMSIIrqMask);
2837 writel(0, base + NvRegIrqMask);
2840 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
2842 spin_unlock_irq(&np->lock);
2844 if (np->msi_flags & NV_MSI_X_ENABLED) {
2845 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
2846 free_irq(np->msi_x_entry[i].vector, dev);
2848 pci_disable_msix(np->pci_dev);
2849 np->msi_flags &= ~NV_MSI_X_ENABLED;
2851 free_irq(np->pci_dev->irq, dev);
2852 if (np->msi_flags & NV_MSI_ENABLED) {
2853 pci_disable_msi(np->pci_dev);
2854 np->msi_flags &= ~NV_MSI_ENABLED;
2863 /* special op: write back the misordered MAC address - otherwise
2864 * the next nv_probe would see a wrong address.
2866 writel(np->orig_mac[0], base + NvRegMacAddrA);
2867 writel(np->orig_mac[1], base + NvRegMacAddrB);
2869 /* FIXME: power down nic */
2874 static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
2876 struct net_device *dev;
2882 dev = alloc_etherdev(sizeof(struct fe_priv));
2887 np = netdev_priv(dev);
2888 np->pci_dev = pci_dev;
2889 spin_lock_init(&np->lock);
2890 SET_MODULE_OWNER(dev);
2891 SET_NETDEV_DEV(dev, &pci_dev->dev);
2893 init_timer(&np->oom_kick);
2894 np->oom_kick.data = (unsigned long) dev;
2895 np->oom_kick.function = &nv_do_rx_refill; /* timer handler */
2896 init_timer(&np->nic_poll);
2897 np->nic_poll.data = (unsigned long) dev;
2898 np->nic_poll.function = &nv_do_nic_poll; /* timer handler */
2900 err = pci_enable_device(pci_dev);
2902 printk(KERN_INFO "forcedeth: pci_enable_dev failed (%d) for device %s\n",
2903 err, pci_name(pci_dev));
2907 pci_set_master(pci_dev);
2909 err = pci_request_regions(pci_dev, DRV_NAME);
2915 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
2916 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
2917 pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i),
2918 pci_resource_len(pci_dev, i),
2919 pci_resource_flags(pci_dev, i));
2920 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
2921 pci_resource_len(pci_dev, i) >= NV_PCI_REGSZ) {
2922 addr = pci_resource_start(pci_dev, i);
2926 if (i == DEVICE_COUNT_RESOURCE) {
2927 printk(KERN_INFO "forcedeth: Couldn't find register window for device %s.\n",
2932 /* handle different descriptor versions */
2933 if (id->driver_data & DEV_HAS_HIGH_DMA) {
2934 /* packet format 3: supports 40-bit addressing */
2935 np->desc_ver = DESC_VER_3;
2936 if (pci_set_dma_mask(pci_dev, DMA_39BIT_MASK)) {
2937 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n",
2940 if (pci_set_consistent_dma_mask(pci_dev, 0x0000007fffffffffULL)) {
2941 printk(KERN_INFO "forcedeth: 64-bit DMA (consistent) failed for device %s.\n",
2945 dev->features |= NETIF_F_HIGHDMA;
2946 printk(KERN_INFO "forcedeth: using HIGHDMA\n");
2949 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
2950 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
2951 /* packet format 2: supports jumbo frames */
2952 np->desc_ver = DESC_VER_2;
2953 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
2955 /* original packet format */
2956 np->desc_ver = DESC_VER_1;
2957 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
2960 np->pkt_limit = NV_PKTLIMIT_1;
2961 if (id->driver_data & DEV_HAS_LARGEDESC)
2962 np->pkt_limit = NV_PKTLIMIT_2;
2964 if (id->driver_data & DEV_HAS_CHECKSUM) {
2965 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
2966 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
2968 dev->features |= NETIF_F_TSO;
2972 np->vlanctl_bits = 0;
2973 if (id->driver_data & DEV_HAS_VLAN) {
2974 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
2975 dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
2976 dev->vlan_rx_register = nv_vlan_rx_register;
2977 dev->vlan_rx_kill_vid = nv_vlan_rx_kill_vid;
2981 if ((id->driver_data & DEV_HAS_MSI) && !disable_msi) {
2982 np->msi_flags |= NV_MSI_CAPABLE;
2984 if ((id->driver_data & DEV_HAS_MSI_X) && !disable_msix) {
2985 np->msi_flags |= NV_MSI_X_CAPABLE;
2989 np->base = ioremap(addr, NV_PCI_REGSZ);
2992 dev->base_addr = (unsigned long)np->base;
2994 dev->irq = pci_dev->irq;
2996 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
2997 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
2998 sizeof(struct ring_desc) * (RX_RING + TX_RING),
3000 if (!np->rx_ring.orig)
3002 np->tx_ring.orig = &np->rx_ring.orig[RX_RING];
3004 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
3005 sizeof(struct ring_desc_ex) * (RX_RING + TX_RING),
3007 if (!np->rx_ring.ex)
3009 np->tx_ring.ex = &np->rx_ring.ex[RX_RING];
3012 dev->open = nv_open;
3013 dev->stop = nv_close;
3014 dev->hard_start_xmit = nv_start_xmit;
3015 dev->get_stats = nv_get_stats;
3016 dev->change_mtu = nv_change_mtu;
3017 dev->set_mac_address = nv_set_mac_address;
3018 dev->set_multicast_list = nv_set_multicast;
3019 #ifdef CONFIG_NET_POLL_CONTROLLER
3020 dev->poll_controller = nv_poll_controller;
3022 SET_ETHTOOL_OPS(dev, &ops);
3023 dev->tx_timeout = nv_tx_timeout;
3024 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
3026 pci_set_drvdata(pci_dev, dev);
3028 /* read the mac address */
3029 base = get_hwbase(dev);
3030 np->orig_mac[0] = readl(base + NvRegMacAddrA);
3031 np->orig_mac[1] = readl(base + NvRegMacAddrB);
3033 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
3034 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
3035 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
3036 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
3037 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
3038 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
3039 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
3041 if (!is_valid_ether_addr(dev->perm_addr)) {
3043 * Bad mac address. At least one bios sets the mac address
3044 * to 01:23:45:67:89:ab
3046 printk(KERN_ERR "%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n",
3048 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
3049 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
3050 printk(KERN_ERR "Please complain to your hardware vendor. Switching to a random MAC.\n");
3051 dev->dev_addr[0] = 0x00;
3052 dev->dev_addr[1] = 0x00;
3053 dev->dev_addr[2] = 0x6c;
3054 get_random_bytes(&dev->dev_addr[3], 3);
3057 dprintk(KERN_DEBUG "%s: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", pci_name(pci_dev),
3058 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
3059 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
3062 writel(0, base + NvRegWakeUpFlags);
3065 if (np->desc_ver == DESC_VER_1) {
3066 np->tx_flags = NV_TX_VALID;
3068 np->tx_flags = NV_TX2_VALID;
3070 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) {
3071 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
3072 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
3073 np->msi_flags |= 0x0003;
3075 np->irqmask = NVREG_IRQMASK_CPU;
3076 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
3077 np->msi_flags |= 0x0001;
3080 if (id->driver_data & DEV_NEED_TIMERIRQ)
3081 np->irqmask |= NVREG_IRQ_TIMER;
3082 if (id->driver_data & DEV_NEED_LINKTIMER) {
3083 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
3084 np->need_linktimer = 1;
3085 np->link_timeout = jiffies + LINK_TIMEOUT;
3087 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
3088 np->need_linktimer = 0;
3091 /* find a suitable phy */
3092 for (i = 1; i <= 32; i++) {
3094 int phyaddr = i & 0x1F;
3096 spin_lock_irq(&np->lock);
3097 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
3098 spin_unlock_irq(&np->lock);
3099 if (id1 < 0 || id1 == 0xffff)
3101 spin_lock_irq(&np->lock);
3102 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
3103 spin_unlock_irq(&np->lock);
3104 if (id2 < 0 || id2 == 0xffff)
3107 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
3108 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
3109 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
3110 pci_name(pci_dev), id1, id2, phyaddr);
3111 np->phyaddr = phyaddr;
3112 np->phy_oui = id1 | id2;
3116 printk(KERN_INFO "%s: open: Could not find a valid PHY.\n",
3124 /* set default link speed settings */
3125 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3129 err = register_netdev(dev);
3131 printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
3134 printk(KERN_INFO "%s: forcedeth.c: subsystem: %05x:%04x bound to %s\n",
3135 dev->name, pci_dev->subsystem_vendor, pci_dev->subsystem_device,
3141 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
3142 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING),
3143 np->rx_ring.orig, np->ring_addr);
3145 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (RX_RING + TX_RING),
3146 np->rx_ring.ex, np->ring_addr);
3147 pci_set_drvdata(pci_dev, NULL);
3149 iounmap(get_hwbase(dev));
3151 pci_release_regions(pci_dev);
3153 pci_disable_device(pci_dev);
3160 static void __devexit nv_remove(struct pci_dev *pci_dev)
3162 struct net_device *dev = pci_get_drvdata(pci_dev);
3163 struct fe_priv *np = netdev_priv(dev);
3165 unregister_netdev(dev);
3167 /* free all structures */
3168 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
3169 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING), np->rx_ring.orig, np->ring_addr);
3171 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (RX_RING + TX_RING), np->rx_ring.ex, np->ring_addr);
3172 iounmap(get_hwbase(dev));
3173 pci_release_regions(pci_dev);
3174 pci_disable_device(pci_dev);
3176 pci_set_drvdata(pci_dev, NULL);
3179 static struct pci_device_id pci_tbl[] = {
3180 { /* nForce Ethernet Controller */
3181 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1),
3182 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
3184 { /* nForce2 Ethernet Controller */
3185 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2),
3186 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
3188 { /* nForce3 Ethernet Controller */
3189 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3),
3190 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
3192 { /* nForce3 Ethernet Controller */
3193 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4),
3194 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
3196 { /* nForce3 Ethernet Controller */
3197 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5),
3198 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
3200 { /* nForce3 Ethernet Controller */
3201 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6),
3202 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
3204 { /* nForce3 Ethernet Controller */
3205 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7),
3206 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
3208 { /* CK804 Ethernet Controller */
3209 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
3210 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
3212 { /* CK804 Ethernet Controller */
3213 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
3214 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
3216 { /* MCP04 Ethernet Controller */
3217 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
3218 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
3220 { /* MCP04 Ethernet Controller */
3221 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
3222 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
3224 { /* MCP51 Ethernet Controller */
3225 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
3226 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA,
3228 { /* MCP51 Ethernet Controller */
3229 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13),
3230 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA,
3232 { /* MCP55 Ethernet Controller */
3233 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
3234 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X,
3236 { /* MCP55 Ethernet Controller */
3237 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
3238 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X,
3243 static struct pci_driver driver = {
3244 .name = "forcedeth",
3245 .id_table = pci_tbl,
3247 .remove = __devexit_p(nv_remove),
3251 static int __init init_nic(void)
3253 printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION);
3254 return pci_module_init(&driver);
3257 static void __exit exit_nic(void)
3259 pci_unregister_driver(&driver);
3262 module_param(max_interrupt_work, int, 0);
3263 MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
3264 module_param(optimization_mode, int, 0);
3265 MODULE_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.");
3266 module_param(poll_interval, int, 0);
3267 MODULE_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.");
3268 module_param(disable_msi, int, 0);
3269 MODULE_PARM_DESC(disable_msi, "Disable MSI interrupts by setting to 1.");
3270 module_param(disable_msix, int, 0);
3271 MODULE_PARM_DESC(disable_msix, "Disable MSIX interrupts by setting to 1.");
3273 MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
3274 MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
3275 MODULE_LICENSE("GPL");
3277 MODULE_DEVICE_TABLE(pci, pci_tbl);
3279 module_init(init_nic);
3280 module_exit(exit_nic);