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.
108 * 0.53: 19 Mar 2006: Fix init from low power mode and add hw reset.
109 * 0.54: 21 Mar 2006: Fix spin locks for multi irqs and cleanup.
110 * 0.55: 22 Mar 2006: Add flow control (pause frame).
111 * 0.56: 22 Mar 2006: Additional ethtool config and moduleparam support.
112 * 0.57: 14 May 2006: Mac address set in probe/remove and order corrections.
113 * 0.58: 30 Oct 2006: Added support for sideband management unit.
116 * We suspect that on some hardware no TX done interrupts are generated.
117 * This means recovery from netif_stop_queue only happens if the hw timer
118 * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
119 * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
120 * If your hardware reliably generates tx done interrupts, then you can remove
121 * DEV_NEED_TIMERIRQ from the driver_data flags.
122 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
123 * superfluous timer interrupts from the nic.
125 #ifdef CONFIG_FORCEDETH_NAPI
126 #define DRIVERNAPI "-NAPI"
130 #define FORCEDETH_VERSION "0.58"
131 #define DRV_NAME "forcedeth"
133 #include <linux/module.h>
134 #include <linux/types.h>
135 #include <linux/pci.h>
136 #include <linux/interrupt.h>
137 #include <linux/netdevice.h>
138 #include <linux/etherdevice.h>
139 #include <linux/delay.h>
140 #include <linux/spinlock.h>
141 #include <linux/ethtool.h>
142 #include <linux/timer.h>
143 #include <linux/skbuff.h>
144 #include <linux/mii.h>
145 #include <linux/random.h>
146 #include <linux/init.h>
147 #include <linux/if_vlan.h>
148 #include <linux/dma-mapping.h>
152 #include <asm/uaccess.h>
153 #include <asm/system.h>
156 #define dprintk printk
158 #define dprintk(x...) do { } while (0)
166 #define DEV_NEED_TIMERIRQ 0x0001 /* set the timer irq flag in the irq mask */
167 #define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */
168 #define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */
169 #define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */
170 #define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */
171 #define DEV_HAS_VLAN 0x0020 /* device supports vlan tagging and striping */
172 #define DEV_HAS_MSI 0x0040 /* device supports MSI */
173 #define DEV_HAS_MSI_X 0x0080 /* device supports MSI-X */
174 #define DEV_HAS_POWER_CNTRL 0x0100 /* device supports power savings */
175 #define DEV_HAS_PAUSEFRAME_TX 0x0200 /* device supports tx pause frames */
176 #define DEV_HAS_STATISTICS 0x0400 /* device supports hw statistics */
177 #define DEV_HAS_TEST_EXTENDED 0x0800 /* device supports extended diagnostic test */
178 #define DEV_HAS_MGMT_UNIT 0x1000 /* device supports management unit */
181 NvRegIrqStatus = 0x000,
182 #define NVREG_IRQSTAT_MIIEVENT 0x040
183 #define NVREG_IRQSTAT_MASK 0x1ff
184 NvRegIrqMask = 0x004,
185 #define NVREG_IRQ_RX_ERROR 0x0001
186 #define NVREG_IRQ_RX 0x0002
187 #define NVREG_IRQ_RX_NOBUF 0x0004
188 #define NVREG_IRQ_TX_ERR 0x0008
189 #define NVREG_IRQ_TX_OK 0x0010
190 #define NVREG_IRQ_TIMER 0x0020
191 #define NVREG_IRQ_LINK 0x0040
192 #define NVREG_IRQ_RX_FORCED 0x0080
193 #define NVREG_IRQ_TX_FORCED 0x0100
194 #define NVREG_IRQMASK_THROUGHPUT 0x00df
195 #define NVREG_IRQMASK_CPU 0x0040
196 #define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
197 #define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED)
198 #define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK)
200 #define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \
201 NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RX_FORCED| \
202 NVREG_IRQ_TX_FORCED))
204 NvRegUnknownSetupReg6 = 0x008,
205 #define NVREG_UNKSETUP6_VAL 3
208 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
209 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
211 NvRegPollingInterval = 0x00c,
212 #define NVREG_POLL_DEFAULT_THROUGHPUT 970
213 #define NVREG_POLL_DEFAULT_CPU 13
214 NvRegMSIMap0 = 0x020,
215 NvRegMSIMap1 = 0x024,
216 NvRegMSIIrqMask = 0x030,
217 #define NVREG_MSI_VECTOR_0_ENABLED 0x01
219 #define NVREG_MISC1_PAUSE_TX 0x01
220 #define NVREG_MISC1_HD 0x02
221 #define NVREG_MISC1_FORCE 0x3b0f3c
223 NvRegMacReset = 0x3c,
224 #define NVREG_MAC_RESET_ASSERT 0x0F3
225 NvRegTransmitterControl = 0x084,
226 #define NVREG_XMITCTL_START 0x01
227 #define NVREG_XMITCTL_MGMT_ST 0x40000000
228 #define NVREG_XMITCTL_SYNC_MASK 0x000f0000
229 #define NVREG_XMITCTL_SYNC_NOT_READY 0x0
230 #define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
231 #define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
232 #define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
233 #define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
234 #define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
235 #define NVREG_XMITCTL_HOST_LOADED 0x00004000
236 NvRegTransmitterStatus = 0x088,
237 #define NVREG_XMITSTAT_BUSY 0x01
239 NvRegPacketFilterFlags = 0x8c,
240 #define NVREG_PFF_PAUSE_RX 0x08
241 #define NVREG_PFF_ALWAYS 0x7F0000
242 #define NVREG_PFF_PROMISC 0x80
243 #define NVREG_PFF_MYADDR 0x20
244 #define NVREG_PFF_LOOPBACK 0x10
246 NvRegOffloadConfig = 0x90,
247 #define NVREG_OFFLOAD_HOMEPHY 0x601
248 #define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
249 NvRegReceiverControl = 0x094,
250 #define NVREG_RCVCTL_START 0x01
251 NvRegReceiverStatus = 0x98,
252 #define NVREG_RCVSTAT_BUSY 0x01
254 NvRegRandomSeed = 0x9c,
255 #define NVREG_RNDSEED_MASK 0x00ff
256 #define NVREG_RNDSEED_FORCE 0x7f00
257 #define NVREG_RNDSEED_FORCE2 0x2d00
258 #define NVREG_RNDSEED_FORCE3 0x7400
260 NvRegTxDeferral = 0xA0,
261 #define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
262 #define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
263 #define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
264 NvRegRxDeferral = 0xA4,
265 #define NVREG_RX_DEFERRAL_DEFAULT 0x16
266 NvRegMacAddrA = 0xA8,
267 NvRegMacAddrB = 0xAC,
268 NvRegMulticastAddrA = 0xB0,
269 #define NVREG_MCASTADDRA_FORCE 0x01
270 NvRegMulticastAddrB = 0xB4,
271 NvRegMulticastMaskA = 0xB8,
272 NvRegMulticastMaskB = 0xBC,
274 NvRegPhyInterface = 0xC0,
275 #define PHY_RGMII 0x10000000
277 NvRegTxRingPhysAddr = 0x100,
278 NvRegRxRingPhysAddr = 0x104,
279 NvRegRingSizes = 0x108,
280 #define NVREG_RINGSZ_TXSHIFT 0
281 #define NVREG_RINGSZ_RXSHIFT 16
282 NvRegTransmitPoll = 0x10c,
283 #define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
284 NvRegLinkSpeed = 0x110,
285 #define NVREG_LINKSPEED_FORCE 0x10000
286 #define NVREG_LINKSPEED_10 1000
287 #define NVREG_LINKSPEED_100 100
288 #define NVREG_LINKSPEED_1000 50
289 #define NVREG_LINKSPEED_MASK (0xFFF)
290 NvRegUnknownSetupReg5 = 0x130,
291 #define NVREG_UNKSETUP5_BIT31 (1<<31)
292 NvRegTxWatermark = 0x13c,
293 #define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
294 #define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
295 #define NVREG_TX_WM_DESC2_3_1000 0xfe08000
296 NvRegTxRxControl = 0x144,
297 #define NVREG_TXRXCTL_KICK 0x0001
298 #define NVREG_TXRXCTL_BIT1 0x0002
299 #define NVREG_TXRXCTL_BIT2 0x0004
300 #define NVREG_TXRXCTL_IDLE 0x0008
301 #define NVREG_TXRXCTL_RESET 0x0010
302 #define NVREG_TXRXCTL_RXCHECK 0x0400
303 #define NVREG_TXRXCTL_DESC_1 0
304 #define NVREG_TXRXCTL_DESC_2 0x02100
305 #define NVREG_TXRXCTL_DESC_3 0x02200
306 #define NVREG_TXRXCTL_VLANSTRIP 0x00040
307 #define NVREG_TXRXCTL_VLANINS 0x00080
308 NvRegTxRingPhysAddrHigh = 0x148,
309 NvRegRxRingPhysAddrHigh = 0x14C,
310 NvRegTxPauseFrame = 0x170,
311 #define NVREG_TX_PAUSEFRAME_DISABLE 0x1ff0080
312 #define NVREG_TX_PAUSEFRAME_ENABLE 0x0c00030
313 NvRegMIIStatus = 0x180,
314 #define NVREG_MIISTAT_ERROR 0x0001
315 #define NVREG_MIISTAT_LINKCHANGE 0x0008
316 #define NVREG_MIISTAT_MASK 0x000f
317 #define NVREG_MIISTAT_MASK2 0x000f
318 NvRegMIIMask = 0x184,
319 #define NVREG_MII_LINKCHANGE 0x0008
321 NvRegAdapterControl = 0x188,
322 #define NVREG_ADAPTCTL_START 0x02
323 #define NVREG_ADAPTCTL_LINKUP 0x04
324 #define NVREG_ADAPTCTL_PHYVALID 0x40000
325 #define NVREG_ADAPTCTL_RUNNING 0x100000
326 #define NVREG_ADAPTCTL_PHYSHIFT 24
327 NvRegMIISpeed = 0x18c,
328 #define NVREG_MIISPEED_BIT8 (1<<8)
329 #define NVREG_MIIDELAY 5
330 NvRegMIIControl = 0x190,
331 #define NVREG_MIICTL_INUSE 0x08000
332 #define NVREG_MIICTL_WRITE 0x00400
333 #define NVREG_MIICTL_ADDRSHIFT 5
334 NvRegMIIData = 0x194,
335 NvRegWakeUpFlags = 0x200,
336 #define NVREG_WAKEUPFLAGS_VAL 0x7770
337 #define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
338 #define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
339 #define NVREG_WAKEUPFLAGS_D3SHIFT 12
340 #define NVREG_WAKEUPFLAGS_D2SHIFT 8
341 #define NVREG_WAKEUPFLAGS_D1SHIFT 4
342 #define NVREG_WAKEUPFLAGS_D0SHIFT 0
343 #define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
344 #define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
345 #define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
346 #define NVREG_WAKEUPFLAGS_ENABLE 0x1111
348 NvRegPatternCRC = 0x204,
349 NvRegPatternMask = 0x208,
350 NvRegPowerCap = 0x268,
351 #define NVREG_POWERCAP_D3SUPP (1<<30)
352 #define NVREG_POWERCAP_D2SUPP (1<<26)
353 #define NVREG_POWERCAP_D1SUPP (1<<25)
354 NvRegPowerState = 0x26c,
355 #define NVREG_POWERSTATE_POWEREDUP 0x8000
356 #define NVREG_POWERSTATE_VALID 0x0100
357 #define NVREG_POWERSTATE_MASK 0x0003
358 #define NVREG_POWERSTATE_D0 0x0000
359 #define NVREG_POWERSTATE_D1 0x0001
360 #define NVREG_POWERSTATE_D2 0x0002
361 #define NVREG_POWERSTATE_D3 0x0003
363 NvRegTxZeroReXmt = 0x284,
364 NvRegTxOneReXmt = 0x288,
365 NvRegTxManyReXmt = 0x28c,
366 NvRegTxLateCol = 0x290,
367 NvRegTxUnderflow = 0x294,
368 NvRegTxLossCarrier = 0x298,
369 NvRegTxExcessDef = 0x29c,
370 NvRegTxRetryErr = 0x2a0,
371 NvRegRxFrameErr = 0x2a4,
372 NvRegRxExtraByte = 0x2a8,
373 NvRegRxLateCol = 0x2ac,
375 NvRegRxFrameTooLong = 0x2b4,
376 NvRegRxOverflow = 0x2b8,
377 NvRegRxFCSErr = 0x2bc,
378 NvRegRxFrameAlignErr = 0x2c0,
379 NvRegRxLenErr = 0x2c4,
380 NvRegRxUnicast = 0x2c8,
381 NvRegRxMulticast = 0x2cc,
382 NvRegRxBroadcast = 0x2d0,
384 NvRegTxFrame = 0x2d8,
386 NvRegTxPause = 0x2e0,
387 NvRegRxPause = 0x2e4,
388 NvRegRxDropFrame = 0x2e8,
389 NvRegVlanControl = 0x300,
390 #define NVREG_VLANCONTROL_ENABLE 0x2000
391 NvRegMSIXMap0 = 0x3e0,
392 NvRegMSIXMap1 = 0x3e4,
393 NvRegMSIXIrqStatus = 0x3f0,
395 NvRegPowerState2 = 0x600,
396 #define NVREG_POWERSTATE2_POWERUP_MASK 0x0F11
397 #define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
400 /* Big endian: should work, but is untested */
406 struct ring_desc_ex {
414 struct ring_desc* orig;
415 struct ring_desc_ex* ex;
418 #define FLAG_MASK_V1 0xffff0000
419 #define FLAG_MASK_V2 0xffffc000
420 #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
421 #define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
423 #define NV_TX_LASTPACKET (1<<16)
424 #define NV_TX_RETRYERROR (1<<19)
425 #define NV_TX_FORCED_INTERRUPT (1<<24)
426 #define NV_TX_DEFERRED (1<<26)
427 #define NV_TX_CARRIERLOST (1<<27)
428 #define NV_TX_LATECOLLISION (1<<28)
429 #define NV_TX_UNDERFLOW (1<<29)
430 #define NV_TX_ERROR (1<<30)
431 #define NV_TX_VALID (1<<31)
433 #define NV_TX2_LASTPACKET (1<<29)
434 #define NV_TX2_RETRYERROR (1<<18)
435 #define NV_TX2_FORCED_INTERRUPT (1<<30)
436 #define NV_TX2_DEFERRED (1<<25)
437 #define NV_TX2_CARRIERLOST (1<<26)
438 #define NV_TX2_LATECOLLISION (1<<27)
439 #define NV_TX2_UNDERFLOW (1<<28)
440 /* error and valid are the same for both */
441 #define NV_TX2_ERROR (1<<30)
442 #define NV_TX2_VALID (1<<31)
443 #define NV_TX2_TSO (1<<28)
444 #define NV_TX2_TSO_SHIFT 14
445 #define NV_TX2_TSO_MAX_SHIFT 14
446 #define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
447 #define NV_TX2_CHECKSUM_L3 (1<<27)
448 #define NV_TX2_CHECKSUM_L4 (1<<26)
450 #define NV_TX3_VLAN_TAG_PRESENT (1<<18)
452 #define NV_RX_DESCRIPTORVALID (1<<16)
453 #define NV_RX_MISSEDFRAME (1<<17)
454 #define NV_RX_SUBSTRACT1 (1<<18)
455 #define NV_RX_ERROR1 (1<<23)
456 #define NV_RX_ERROR2 (1<<24)
457 #define NV_RX_ERROR3 (1<<25)
458 #define NV_RX_ERROR4 (1<<26)
459 #define NV_RX_CRCERR (1<<27)
460 #define NV_RX_OVERFLOW (1<<28)
461 #define NV_RX_FRAMINGERR (1<<29)
462 #define NV_RX_ERROR (1<<30)
463 #define NV_RX_AVAIL (1<<31)
465 #define NV_RX2_CHECKSUMMASK (0x1C000000)
466 #define NV_RX2_CHECKSUMOK1 (0x10000000)
467 #define NV_RX2_CHECKSUMOK2 (0x14000000)
468 #define NV_RX2_CHECKSUMOK3 (0x18000000)
469 #define NV_RX2_DESCRIPTORVALID (1<<29)
470 #define NV_RX2_SUBSTRACT1 (1<<25)
471 #define NV_RX2_ERROR1 (1<<18)
472 #define NV_RX2_ERROR2 (1<<19)
473 #define NV_RX2_ERROR3 (1<<20)
474 #define NV_RX2_ERROR4 (1<<21)
475 #define NV_RX2_CRCERR (1<<22)
476 #define NV_RX2_OVERFLOW (1<<23)
477 #define NV_RX2_FRAMINGERR (1<<24)
478 /* error and avail are the same for both */
479 #define NV_RX2_ERROR (1<<30)
480 #define NV_RX2_AVAIL (1<<31)
482 #define NV_RX3_VLAN_TAG_PRESENT (1<<16)
483 #define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
485 /* Miscelaneous hardware related defines: */
486 #define NV_PCI_REGSZ_VER1 0x270
487 #define NV_PCI_REGSZ_VER2 0x604
489 /* various timeout delays: all in usec */
490 #define NV_TXRX_RESET_DELAY 4
491 #define NV_TXSTOP_DELAY1 10
492 #define NV_TXSTOP_DELAY1MAX 500000
493 #define NV_TXSTOP_DELAY2 100
494 #define NV_RXSTOP_DELAY1 10
495 #define NV_RXSTOP_DELAY1MAX 500000
496 #define NV_RXSTOP_DELAY2 100
497 #define NV_SETUP5_DELAY 5
498 #define NV_SETUP5_DELAYMAX 50000
499 #define NV_POWERUP_DELAY 5
500 #define NV_POWERUP_DELAYMAX 5000
501 #define NV_MIIBUSY_DELAY 50
502 #define NV_MIIPHY_DELAY 10
503 #define NV_MIIPHY_DELAYMAX 10000
504 #define NV_MAC_RESET_DELAY 64
506 #define NV_WAKEUPPATTERNS 5
507 #define NV_WAKEUPMASKENTRIES 4
509 /* General driver defaults */
510 #define NV_WATCHDOG_TIMEO (5*HZ)
512 #define RX_RING_DEFAULT 128
513 #define TX_RING_DEFAULT 256
514 #define RX_RING_MIN 128
515 #define TX_RING_MIN 64
516 #define RING_MAX_DESC_VER_1 1024
517 #define RING_MAX_DESC_VER_2_3 16384
519 * Difference between the get and put pointers for the tx ring.
520 * This is used to throttle the amount of data outstanding in the
523 #define TX_LIMIT_DIFFERENCE 1
525 /* rx/tx mac addr + type + vlan + align + slack*/
526 #define NV_RX_HEADERS (64)
527 /* even more slack. */
528 #define NV_RX_ALLOC_PAD (64)
530 /* maximum mtu size */
531 #define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
532 #define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
534 #define OOM_REFILL (1+HZ/20)
535 #define POLL_WAIT (1+HZ/100)
536 #define LINK_TIMEOUT (3*HZ)
537 #define STATS_INTERVAL (10*HZ)
541 * The nic supports three different descriptor types:
542 * - DESC_VER_1: Original
543 * - DESC_VER_2: support for jumbo frames.
544 * - DESC_VER_3: 64-bit format.
551 #define PHY_OUI_MARVELL 0x5043
552 #define PHY_OUI_CICADA 0x03f1
553 #define PHYID1_OUI_MASK 0x03ff
554 #define PHYID1_OUI_SHFT 6
555 #define PHYID2_OUI_MASK 0xfc00
556 #define PHYID2_OUI_SHFT 10
557 #define PHYID2_MODEL_MASK 0x03f0
558 #define PHY_MODEL_MARVELL_E3016 0x220
559 #define PHY_MARVELL_E3016_INITMASK 0x0300
560 #define PHY_INIT1 0x0f000
561 #define PHY_INIT2 0x0e00
562 #define PHY_INIT3 0x01000
563 #define PHY_INIT4 0x0200
564 #define PHY_INIT5 0x0004
565 #define PHY_INIT6 0x02000
566 #define PHY_GIGABIT 0x0100
568 #define PHY_TIMEOUT 0x1
569 #define PHY_ERROR 0x2
573 #define PHY_HALF 0x100
575 #define NV_PAUSEFRAME_RX_CAPABLE 0x0001
576 #define NV_PAUSEFRAME_TX_CAPABLE 0x0002
577 #define NV_PAUSEFRAME_RX_ENABLE 0x0004
578 #define NV_PAUSEFRAME_TX_ENABLE 0x0008
579 #define NV_PAUSEFRAME_RX_REQ 0x0010
580 #define NV_PAUSEFRAME_TX_REQ 0x0020
581 #define NV_PAUSEFRAME_AUTONEG 0x0040
583 /* MSI/MSI-X defines */
584 #define NV_MSI_X_MAX_VECTORS 8
585 #define NV_MSI_X_VECTORS_MASK 0x000f
586 #define NV_MSI_CAPABLE 0x0010
587 #define NV_MSI_X_CAPABLE 0x0020
588 #define NV_MSI_ENABLED 0x0040
589 #define NV_MSI_X_ENABLED 0x0080
591 #define NV_MSI_X_VECTOR_ALL 0x0
592 #define NV_MSI_X_VECTOR_RX 0x0
593 #define NV_MSI_X_VECTOR_TX 0x1
594 #define NV_MSI_X_VECTOR_OTHER 0x2
597 struct nv_ethtool_str {
598 char name[ETH_GSTRING_LEN];
601 static const struct nv_ethtool_str nv_estats_str[] = {
606 { "tx_late_collision" },
607 { "tx_fifo_errors" },
608 { "tx_carrier_errors" },
609 { "tx_excess_deferral" },
610 { "tx_retry_error" },
614 { "rx_frame_error" },
616 { "rx_late_collision" },
618 { "rx_frame_too_long" },
619 { "rx_over_errors" },
621 { "rx_frame_align_error" },
622 { "rx_length_error" },
630 { "rx_errors_total" }
633 struct nv_ethtool_stats {
638 u64 tx_late_collision;
640 u64 tx_carrier_errors;
641 u64 tx_excess_deferral;
648 u64 rx_late_collision;
650 u64 rx_frame_too_long;
653 u64 rx_frame_align_error;
666 #define NV_TEST_COUNT_BASE 3
667 #define NV_TEST_COUNT_EXTENDED 4
669 static const struct nv_ethtool_str nv_etests_str[] = {
670 { "link (online/offline)" },
671 { "register (offline) " },
672 { "interrupt (offline) " },
673 { "loopback (offline) " }
676 struct register_test {
681 static const struct register_test nv_registers_test[] = {
682 { NvRegUnknownSetupReg6, 0x01 },
683 { NvRegMisc1, 0x03c },
684 { NvRegOffloadConfig, 0x03ff },
685 { NvRegMulticastAddrA, 0xffffffff },
686 { NvRegTxWatermark, 0x0ff },
687 { NvRegWakeUpFlags, 0x07777 },
693 * All hardware access under dev->priv->lock, except the performance
695 * - rx is (pseudo-) lockless: it relies on the single-threading provided
696 * by the arch code for interrupts.
697 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
698 * needs dev->priv->lock :-(
699 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
702 /* in dev: base, irq */
707 * Locking: spin_lock(&np->lock); */
708 struct net_device_stats stats;
709 struct nv_ethtool_stats estats;
717 unsigned int phy_oui;
718 unsigned int phy_model;
722 /* General data: RO fields */
723 dma_addr_t ring_addr;
724 struct pci_dev *pci_dev;
737 /* rx specific fields.
738 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
740 union ring_type rx_ring;
741 unsigned int cur_rx, refill_rx;
742 struct sk_buff **rx_skbuff;
744 unsigned int rx_buf_sz;
745 unsigned int pkt_limit;
746 struct timer_list oom_kick;
747 struct timer_list nic_poll;
748 struct timer_list stats_poll;
752 /* media detection workaround.
753 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
756 unsigned long link_timeout;
758 * tx specific fields.
760 union ring_type tx_ring;
761 unsigned int next_tx, nic_tx;
762 struct sk_buff **tx_skbuff;
764 unsigned int *tx_dma_len;
771 struct vlan_group *vlangrp;
773 /* msi/msi-x fields */
775 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
782 * Maximum number of loops until we assume that a bit in the irq mask
783 * is stuck. Overridable with module param.
785 static int max_interrupt_work = 5;
788 * Optimization can be either throuput mode or cpu mode
790 * Throughput Mode: Every tx and rx packet will generate an interrupt.
791 * CPU Mode: Interrupts are controlled by a timer.
794 NV_OPTIMIZATION_MODE_THROUGHPUT,
795 NV_OPTIMIZATION_MODE_CPU
797 static int optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
800 * Poll interval for timer irq
802 * This interval determines how frequent an interrupt is generated.
803 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
804 * Min = 0, and Max = 65535
806 static int poll_interval = -1;
815 static int msi = NV_MSI_INT_ENABLED;
821 NV_MSIX_INT_DISABLED,
824 static int msix = NV_MSIX_INT_ENABLED;
830 NV_DMA_64BIT_DISABLED,
833 static int dma_64bit = NV_DMA_64BIT_ENABLED;
835 static inline struct fe_priv *get_nvpriv(struct net_device *dev)
837 return netdev_priv(dev);
840 static inline u8 __iomem *get_hwbase(struct net_device *dev)
842 return ((struct fe_priv *)netdev_priv(dev))->base;
845 static inline void pci_push(u8 __iomem *base)
847 /* force out pending posted writes */
851 static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
853 return le32_to_cpu(prd->flaglen)
854 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
857 static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
859 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
862 static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
863 int delay, int delaymax, const char *msg)
865 u8 __iomem *base = get_hwbase(dev);
876 } while ((readl(base + offset) & mask) != target);
880 #define NV_SETUP_RX_RING 0x01
881 #define NV_SETUP_TX_RING 0x02
883 static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
885 struct fe_priv *np = get_nvpriv(dev);
886 u8 __iomem *base = get_hwbase(dev);
888 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
889 if (rxtx_flags & NV_SETUP_RX_RING) {
890 writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr);
892 if (rxtx_flags & NV_SETUP_TX_RING) {
893 writel((u32) cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
896 if (rxtx_flags & NV_SETUP_RX_RING) {
897 writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr);
898 writel((u32) (cpu_to_le64(np->ring_addr) >> 32), base + NvRegRxRingPhysAddrHigh);
900 if (rxtx_flags & NV_SETUP_TX_RING) {
901 writel((u32) cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
902 writel((u32) (cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)) >> 32), base + NvRegTxRingPhysAddrHigh);
907 static void free_rings(struct net_device *dev)
909 struct fe_priv *np = get_nvpriv(dev);
911 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
912 if (np->rx_ring.orig)
913 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
914 np->rx_ring.orig, np->ring_addr);
917 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
918 np->rx_ring.ex, np->ring_addr);
921 kfree(np->rx_skbuff);
925 kfree(np->tx_skbuff);
929 kfree(np->tx_dma_len);
932 static int using_multi_irqs(struct net_device *dev)
934 struct fe_priv *np = get_nvpriv(dev);
936 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
937 ((np->msi_flags & NV_MSI_X_ENABLED) &&
938 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
944 static void nv_enable_irq(struct net_device *dev)
946 struct fe_priv *np = get_nvpriv(dev);
948 if (!using_multi_irqs(dev)) {
949 if (np->msi_flags & NV_MSI_X_ENABLED)
950 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
952 enable_irq(dev->irq);
954 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
955 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
956 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
960 static void nv_disable_irq(struct net_device *dev)
962 struct fe_priv *np = get_nvpriv(dev);
964 if (!using_multi_irqs(dev)) {
965 if (np->msi_flags & NV_MSI_X_ENABLED)
966 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
968 disable_irq(dev->irq);
970 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
971 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
972 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
976 /* In MSIX mode, a write to irqmask behaves as XOR */
977 static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
979 u8 __iomem *base = get_hwbase(dev);
981 writel(mask, base + NvRegIrqMask);
984 static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
986 struct fe_priv *np = get_nvpriv(dev);
987 u8 __iomem *base = get_hwbase(dev);
989 if (np->msi_flags & NV_MSI_X_ENABLED) {
990 writel(mask, base + NvRegIrqMask);
992 if (np->msi_flags & NV_MSI_ENABLED)
993 writel(0, base + NvRegMSIIrqMask);
994 writel(0, base + NvRegIrqMask);
998 #define MII_READ (-1)
999 /* mii_rw: read/write a register on the PHY.
1001 * Caller must guarantee serialization
1003 static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1005 u8 __iomem *base = get_hwbase(dev);
1009 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
1011 reg = readl(base + NvRegMIIControl);
1012 if (reg & NVREG_MIICTL_INUSE) {
1013 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1014 udelay(NV_MIIBUSY_DELAY);
1017 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1018 if (value != MII_READ) {
1019 writel(value, base + NvRegMIIData);
1020 reg |= NVREG_MIICTL_WRITE;
1022 writel(reg, base + NvRegMIIControl);
1024 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
1025 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
1026 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n",
1027 dev->name, miireg, addr);
1029 } else if (value != MII_READ) {
1030 /* it was a write operation - fewer failures are detectable */
1031 dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
1032 dev->name, value, miireg, addr);
1034 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
1035 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n",
1036 dev->name, miireg, addr);
1039 retval = readl(base + NvRegMIIData);
1040 dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
1041 dev->name, miireg, addr, retval);
1047 static int phy_reset(struct net_device *dev, u32 bmcr_setup)
1049 struct fe_priv *np = netdev_priv(dev);
1051 unsigned int tries = 0;
1053 miicontrol = BMCR_RESET | bmcr_setup;
1054 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) {
1058 /* wait for 500ms */
1061 /* must wait till reset is deasserted */
1062 while (miicontrol & BMCR_RESET) {
1064 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1065 /* FIXME: 100 tries seem excessive */
1072 static int phy_init(struct net_device *dev)
1074 struct fe_priv *np = get_nvpriv(dev);
1075 u8 __iomem *base = get_hwbase(dev);
1076 u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg;
1078 /* phy errata for E3016 phy */
1079 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1080 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1081 reg &= ~PHY_MARVELL_E3016_INITMASK;
1082 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
1083 printk(KERN_INFO "%s: phy write to errata reg failed.\n", pci_name(np->pci_dev));
1088 /* set advertise register */
1089 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
1090 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|ADVERTISE_PAUSE_ASYM|ADVERTISE_PAUSE_CAP);
1091 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
1092 printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev));
1096 /* get phy interface type */
1097 phyinterface = readl(base + NvRegPhyInterface);
1099 /* see if gigabit phy */
1100 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1101 if (mii_status & PHY_GIGABIT) {
1102 np->gigabit = PHY_GIGABIT;
1103 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
1104 mii_control_1000 &= ~ADVERTISE_1000HALF;
1105 if (phyinterface & PHY_RGMII)
1106 mii_control_1000 |= ADVERTISE_1000FULL;
1108 mii_control_1000 &= ~ADVERTISE_1000FULL;
1110 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
1111 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1118 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1119 mii_control |= BMCR_ANENABLE;
1122 * (certain phys need bmcr to be setup with reset)
1124 if (phy_reset(dev, mii_control)) {
1125 printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev));
1129 /* phy vendor specific configuration */
1130 if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) {
1131 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
1132 phy_reserved &= ~(PHY_INIT1 | PHY_INIT2);
1133 phy_reserved |= (PHY_INIT3 | PHY_INIT4);
1134 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) {
1135 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1138 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1139 phy_reserved |= PHY_INIT5;
1140 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) {
1141 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1145 if (np->phy_oui == PHY_OUI_CICADA) {
1146 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
1147 phy_reserved |= PHY_INIT6;
1148 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) {
1149 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1153 /* some phys clear out pause advertisment on reset, set it back */
1154 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
1156 /* restart auto negotiation */
1157 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1158 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
1159 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
1166 static void nv_start_rx(struct net_device *dev)
1168 struct fe_priv *np = netdev_priv(dev);
1169 u8 __iomem *base = get_hwbase(dev);
1171 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
1172 /* Already running? Stop it. */
1173 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
1174 writel(0, base + NvRegReceiverControl);
1177 writel(np->linkspeed, base + NvRegLinkSpeed);
1179 writel(NVREG_RCVCTL_START, base + NvRegReceiverControl);
1180 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
1181 dev->name, np->duplex, np->linkspeed);
1185 static void nv_stop_rx(struct net_device *dev)
1187 u8 __iomem *base = get_hwbase(dev);
1189 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
1190 writel(0, base + NvRegReceiverControl);
1191 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1192 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
1193 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
1195 udelay(NV_RXSTOP_DELAY2);
1196 writel(0, base + NvRegLinkSpeed);
1199 static void nv_start_tx(struct net_device *dev)
1201 u8 __iomem *base = get_hwbase(dev);
1203 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
1204 writel(NVREG_XMITCTL_START, base + NvRegTransmitterControl);
1208 static void nv_stop_tx(struct net_device *dev)
1210 u8 __iomem *base = get_hwbase(dev);
1212 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
1213 writel(0, base + NvRegTransmitterControl);
1214 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1215 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
1216 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
1218 udelay(NV_TXSTOP_DELAY2);
1219 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
1222 static void nv_txrx_reset(struct net_device *dev)
1224 struct fe_priv *np = netdev_priv(dev);
1225 u8 __iomem *base = get_hwbase(dev);
1227 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
1228 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1230 udelay(NV_TXRX_RESET_DELAY);
1231 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1235 static void nv_mac_reset(struct net_device *dev)
1237 struct fe_priv *np = netdev_priv(dev);
1238 u8 __iomem *base = get_hwbase(dev);
1240 dprintk(KERN_DEBUG "%s: nv_mac_reset\n", dev->name);
1241 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1243 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1245 udelay(NV_MAC_RESET_DELAY);
1246 writel(0, base + NvRegMacReset);
1248 udelay(NV_MAC_RESET_DELAY);
1249 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1254 * nv_get_stats: dev->get_stats function
1255 * Get latest stats value from the nic.
1256 * Called with read_lock(&dev_base_lock) held for read -
1257 * only synchronized against unregister_netdevice.
1259 static struct net_device_stats *nv_get_stats(struct net_device *dev)
1261 struct fe_priv *np = netdev_priv(dev);
1263 /* It seems that the nic always generates interrupts and doesn't
1264 * accumulate errors internally. Thus the current values in np->stats
1265 * are already up to date.
1271 * nv_alloc_rx: fill rx ring entries.
1272 * Return 1 if the allocations for the skbs failed and the
1273 * rx engine is without Available descriptors
1275 static int nv_alloc_rx(struct net_device *dev)
1277 struct fe_priv *np = netdev_priv(dev);
1278 unsigned int refill_rx = np->refill_rx;
1281 while (np->cur_rx != refill_rx) {
1282 struct sk_buff *skb;
1284 nr = refill_rx % np->rx_ring_size;
1285 if (np->rx_skbuff[nr] == NULL) {
1287 skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
1292 np->rx_skbuff[nr] = skb;
1294 skb = np->rx_skbuff[nr];
1296 np->rx_dma[nr] = pci_map_single(np->pci_dev, skb->data,
1297 skb->end-skb->data, PCI_DMA_FROMDEVICE);
1298 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1299 np->rx_ring.orig[nr].buf = cpu_to_le32(np->rx_dma[nr]);
1301 np->rx_ring.orig[nr].flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
1303 np->rx_ring.ex[nr].bufhigh = cpu_to_le64(np->rx_dma[nr]) >> 32;
1304 np->rx_ring.ex[nr].buflow = cpu_to_le64(np->rx_dma[nr]) & 0x0FFFFFFFF;
1306 np->rx_ring.ex[nr].flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
1308 dprintk(KERN_DEBUG "%s: nv_alloc_rx: Packet %d marked as Available\n",
1309 dev->name, refill_rx);
1312 np->refill_rx = refill_rx;
1313 if (np->cur_rx - refill_rx == np->rx_ring_size)
1318 /* If rx bufs are exhausted called after 50ms to attempt to refresh */
1319 #ifdef CONFIG_FORCEDETH_NAPI
1320 static void nv_do_rx_refill(unsigned long data)
1322 struct net_device *dev = (struct net_device *) data;
1324 /* Just reschedule NAPI rx processing */
1325 netif_rx_schedule(dev);
1328 static void nv_do_rx_refill(unsigned long data)
1330 struct net_device *dev = (struct net_device *) data;
1331 struct fe_priv *np = netdev_priv(dev);
1333 if (!using_multi_irqs(dev)) {
1334 if (np->msi_flags & NV_MSI_X_ENABLED)
1335 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1337 disable_irq(dev->irq);
1339 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1341 if (nv_alloc_rx(dev)) {
1342 spin_lock_irq(&np->lock);
1343 if (!np->in_shutdown)
1344 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
1345 spin_unlock_irq(&np->lock);
1347 if (!using_multi_irqs(dev)) {
1348 if (np->msi_flags & NV_MSI_X_ENABLED)
1349 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1351 enable_irq(dev->irq);
1353 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1358 static void nv_init_rx(struct net_device *dev)
1360 struct fe_priv *np = netdev_priv(dev);
1363 np->cur_rx = np->rx_ring_size;
1365 for (i = 0; i < np->rx_ring_size; i++)
1366 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1367 np->rx_ring.orig[i].flaglen = 0;
1369 np->rx_ring.ex[i].flaglen = 0;
1372 static void nv_init_tx(struct net_device *dev)
1374 struct fe_priv *np = netdev_priv(dev);
1377 np->next_tx = np->nic_tx = 0;
1378 for (i = 0; i < np->tx_ring_size; i++) {
1379 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1380 np->tx_ring.orig[i].flaglen = 0;
1382 np->tx_ring.ex[i].flaglen = 0;
1383 np->tx_skbuff[i] = NULL;
1388 static int nv_init_ring(struct net_device *dev)
1392 return nv_alloc_rx(dev);
1395 static int nv_release_txskb(struct net_device *dev, unsigned int skbnr)
1397 struct fe_priv *np = netdev_priv(dev);
1399 dprintk(KERN_INFO "%s: nv_release_txskb for skbnr %d\n",
1402 if (np->tx_dma[skbnr]) {
1403 pci_unmap_page(np->pci_dev, np->tx_dma[skbnr],
1404 np->tx_dma_len[skbnr],
1406 np->tx_dma[skbnr] = 0;
1409 if (np->tx_skbuff[skbnr]) {
1410 dev_kfree_skb_any(np->tx_skbuff[skbnr]);
1411 np->tx_skbuff[skbnr] = NULL;
1418 static void nv_drain_tx(struct net_device *dev)
1420 struct fe_priv *np = netdev_priv(dev);
1423 for (i = 0; i < np->tx_ring_size; i++) {
1424 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1425 np->tx_ring.orig[i].flaglen = 0;
1427 np->tx_ring.ex[i].flaglen = 0;
1428 if (nv_release_txskb(dev, i))
1429 np->stats.tx_dropped++;
1433 static void nv_drain_rx(struct net_device *dev)
1435 struct fe_priv *np = netdev_priv(dev);
1437 for (i = 0; i < np->rx_ring_size; i++) {
1438 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1439 np->rx_ring.orig[i].flaglen = 0;
1441 np->rx_ring.ex[i].flaglen = 0;
1443 if (np->rx_skbuff[i]) {
1444 pci_unmap_single(np->pci_dev, np->rx_dma[i],
1445 np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
1446 PCI_DMA_FROMDEVICE);
1447 dev_kfree_skb(np->rx_skbuff[i]);
1448 np->rx_skbuff[i] = NULL;
1453 static void drain_ring(struct net_device *dev)
1460 * nv_start_xmit: dev->hard_start_xmit function
1461 * Called with netif_tx_lock held.
1463 static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1465 struct fe_priv *np = netdev_priv(dev);
1467 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
1468 unsigned int fragments = skb_shinfo(skb)->nr_frags;
1469 unsigned int nr = (np->next_tx - 1) % np->tx_ring_size;
1470 unsigned int start_nr = np->next_tx % np->tx_ring_size;
1474 u32 size = skb->len-skb->data_len;
1475 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1476 u32 tx_flags_vlan = 0;
1478 /* add fragments to entries count */
1479 for (i = 0; i < fragments; i++) {
1480 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1481 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1484 spin_lock_irq(&np->lock);
1486 if ((np->next_tx - np->nic_tx + entries - 1) > np->tx_limit_stop) {
1487 spin_unlock_irq(&np->lock);
1488 netif_stop_queue(dev);
1489 return NETDEV_TX_BUSY;
1492 /* setup the header buffer */
1494 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
1495 nr = (nr + 1) % np->tx_ring_size;
1497 np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
1499 np->tx_dma_len[nr] = bcnt;
1501 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1502 np->tx_ring.orig[nr].buf = cpu_to_le32(np->tx_dma[nr]);
1503 np->tx_ring.orig[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
1505 np->tx_ring.ex[nr].bufhigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1506 np->tx_ring.ex[nr].buflow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1507 np->tx_ring.ex[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
1509 tx_flags = np->tx_flags;
1514 /* setup the fragments */
1515 for (i = 0; i < fragments; i++) {
1516 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1517 u32 size = frag->size;
1521 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
1522 nr = (nr + 1) % np->tx_ring_size;
1524 np->tx_dma[nr] = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
1526 np->tx_dma_len[nr] = bcnt;
1528 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1529 np->tx_ring.orig[nr].buf = cpu_to_le32(np->tx_dma[nr]);
1530 np->tx_ring.orig[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
1532 np->tx_ring.ex[nr].bufhigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1533 np->tx_ring.ex[nr].buflow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1534 np->tx_ring.ex[nr].flaglen = cpu_to_le32((bcnt-1) | tx_flags);
1541 /* set last fragment flag */
1542 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1543 np->tx_ring.orig[nr].flaglen |= cpu_to_le32(tx_flags_extra);
1545 np->tx_ring.ex[nr].flaglen |= cpu_to_le32(tx_flags_extra);
1548 np->tx_skbuff[nr] = skb;
1551 if (skb_is_gso(skb))
1552 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
1555 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
1556 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
1559 if (np->vlangrp && vlan_tx_tag_present(skb)) {
1560 tx_flags_vlan = NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb);
1564 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1565 np->tx_ring.orig[start_nr].flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
1567 np->tx_ring.ex[start_nr].txvlan = cpu_to_le32(tx_flags_vlan);
1568 np->tx_ring.ex[start_nr].flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
1571 dprintk(KERN_DEBUG "%s: nv_start_xmit: packet %d (entries %d) queued for transmission. tx_flags_extra: %x\n",
1572 dev->name, np->next_tx, entries, tx_flags_extra);
1575 for (j=0; j<64; j++) {
1577 dprintk("\n%03x:", j);
1578 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
1583 np->next_tx += entries;
1585 dev->trans_start = jiffies;
1586 spin_unlock_irq(&np->lock);
1587 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
1588 pci_push(get_hwbase(dev));
1589 return NETDEV_TX_OK;
1593 * nv_tx_done: check for completed packets, release the skbs.
1595 * Caller must own np->lock.
1597 static void nv_tx_done(struct net_device *dev)
1599 struct fe_priv *np = netdev_priv(dev);
1602 struct sk_buff *skb;
1604 while (np->nic_tx != np->next_tx) {
1605 i = np->nic_tx % np->tx_ring_size;
1607 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1608 flags = le32_to_cpu(np->tx_ring.orig[i].flaglen);
1610 flags = le32_to_cpu(np->tx_ring.ex[i].flaglen);
1612 dprintk(KERN_DEBUG "%s: nv_tx_done: looking at packet %d, flags 0x%x.\n",
1613 dev->name, np->nic_tx, flags);
1614 if (flags & NV_TX_VALID)
1616 if (np->desc_ver == DESC_VER_1) {
1617 if (flags & NV_TX_LASTPACKET) {
1618 skb = np->tx_skbuff[i];
1619 if (flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION|
1620 NV_TX_UNDERFLOW|NV_TX_ERROR)) {
1621 if (flags & NV_TX_UNDERFLOW)
1622 np->stats.tx_fifo_errors++;
1623 if (flags & NV_TX_CARRIERLOST)
1624 np->stats.tx_carrier_errors++;
1625 np->stats.tx_errors++;
1627 np->stats.tx_packets++;
1628 np->stats.tx_bytes += skb->len;
1632 if (flags & NV_TX2_LASTPACKET) {
1633 skb = np->tx_skbuff[i];
1634 if (flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION|
1635 NV_TX2_UNDERFLOW|NV_TX2_ERROR)) {
1636 if (flags & NV_TX2_UNDERFLOW)
1637 np->stats.tx_fifo_errors++;
1638 if (flags & NV_TX2_CARRIERLOST)
1639 np->stats.tx_carrier_errors++;
1640 np->stats.tx_errors++;
1642 np->stats.tx_packets++;
1643 np->stats.tx_bytes += skb->len;
1647 nv_release_txskb(dev, i);
1650 if (np->next_tx - np->nic_tx < np->tx_limit_start)
1651 netif_wake_queue(dev);
1655 * nv_tx_timeout: dev->tx_timeout function
1656 * Called with netif_tx_lock held.
1658 static void nv_tx_timeout(struct net_device *dev)
1660 struct fe_priv *np = netdev_priv(dev);
1661 u8 __iomem *base = get_hwbase(dev);
1664 if (np->msi_flags & NV_MSI_X_ENABLED)
1665 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
1667 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
1669 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status);
1674 printk(KERN_INFO "%s: Ring at %lx: next %d nic %d\n",
1675 dev->name, (unsigned long)np->ring_addr,
1676 np->next_tx, np->nic_tx);
1677 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
1678 for (i=0;i<=np->register_size;i+= 32) {
1679 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
1681 readl(base + i + 0), readl(base + i + 4),
1682 readl(base + i + 8), readl(base + i + 12),
1683 readl(base + i + 16), readl(base + i + 20),
1684 readl(base + i + 24), readl(base + i + 28));
1686 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
1687 for (i=0;i<np->tx_ring_size;i+= 4) {
1688 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1689 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
1691 le32_to_cpu(np->tx_ring.orig[i].buf),
1692 le32_to_cpu(np->tx_ring.orig[i].flaglen),
1693 le32_to_cpu(np->tx_ring.orig[i+1].buf),
1694 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
1695 le32_to_cpu(np->tx_ring.orig[i+2].buf),
1696 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
1697 le32_to_cpu(np->tx_ring.orig[i+3].buf),
1698 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
1700 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
1702 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
1703 le32_to_cpu(np->tx_ring.ex[i].buflow),
1704 le32_to_cpu(np->tx_ring.ex[i].flaglen),
1705 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
1706 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
1707 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
1708 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
1709 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
1710 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
1711 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
1712 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
1713 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
1718 spin_lock_irq(&np->lock);
1720 /* 1) stop tx engine */
1723 /* 2) check that the packets were not sent already: */
1726 /* 3) if there are dead entries: clear everything */
1727 if (np->next_tx != np->nic_tx) {
1728 printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name);
1730 np->next_tx = np->nic_tx = 0;
1731 setup_hw_rings(dev, NV_SETUP_TX_RING);
1732 netif_wake_queue(dev);
1735 /* 4) restart tx engine */
1737 spin_unlock_irq(&np->lock);
1741 * Called when the nic notices a mismatch between the actual data len on the
1742 * wire and the len indicated in the 802 header
1744 static int nv_getlen(struct net_device *dev, void *packet, int datalen)
1746 int hdrlen; /* length of the 802 header */
1747 int protolen; /* length as stored in the proto field */
1749 /* 1) calculate len according to header */
1750 if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
1751 protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto );
1754 protolen = ntohs( ((struct ethhdr *)packet)->h_proto);
1757 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
1758 dev->name, datalen, protolen, hdrlen);
1759 if (protolen > ETH_DATA_LEN)
1760 return datalen; /* Value in proto field not a len, no checks possible */
1763 /* consistency checks: */
1764 if (datalen > ETH_ZLEN) {
1765 if (datalen >= protolen) {
1766 /* more data on wire than in 802 header, trim of
1769 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1770 dev->name, protolen);
1773 /* less data on wire than mentioned in header.
1774 * Discard the packet.
1776 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
1781 /* short packet. Accept only if 802 values are also short */
1782 if (protolen > ETH_ZLEN) {
1783 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
1787 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
1788 dev->name, datalen);
1793 static int nv_rx_process(struct net_device *dev, int limit)
1795 struct fe_priv *np = netdev_priv(dev);
1800 for (count = 0; count < limit; ++count) {
1801 struct sk_buff *skb;
1804 if (np->cur_rx - np->refill_rx >= np->rx_ring_size)
1805 break; /* we scanned the whole ring - do not continue */
1807 i = np->cur_rx % np->rx_ring_size;
1808 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1809 flags = le32_to_cpu(np->rx_ring.orig[i].flaglen);
1810 len = nv_descr_getlength(&np->rx_ring.orig[i], np->desc_ver);
1812 flags = le32_to_cpu(np->rx_ring.ex[i].flaglen);
1813 len = nv_descr_getlength_ex(&np->rx_ring.ex[i], np->desc_ver);
1814 vlanflags = le32_to_cpu(np->rx_ring.ex[i].buflow);
1817 dprintk(KERN_DEBUG "%s: nv_rx_process: looking at packet %d, flags 0x%x.\n",
1818 dev->name, np->cur_rx, flags);
1820 if (flags & NV_RX_AVAIL)
1821 break; /* still owned by hardware, */
1824 * the packet is for us - immediately tear down the pci mapping.
1825 * TODO: check if a prefetch of the first cacheline improves
1828 pci_unmap_single(np->pci_dev, np->rx_dma[i],
1829 np->rx_skbuff[i]->end-np->rx_skbuff[i]->data,
1830 PCI_DMA_FROMDEVICE);
1834 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
1835 for (j=0; j<64; j++) {
1837 dprintk("\n%03x:", j);
1838 dprintk(" %02x", ((unsigned char*)np->rx_skbuff[i]->data)[j]);
1842 /* look at what we actually got: */
1843 if (np->desc_ver == DESC_VER_1) {
1844 if (!(flags & NV_RX_DESCRIPTORVALID))
1847 if (flags & NV_RX_ERROR) {
1848 if (flags & NV_RX_MISSEDFRAME) {
1849 np->stats.rx_missed_errors++;
1850 np->stats.rx_errors++;
1853 if (flags & (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3)) {
1854 np->stats.rx_errors++;
1857 if (flags & NV_RX_CRCERR) {
1858 np->stats.rx_crc_errors++;
1859 np->stats.rx_errors++;
1862 if (flags & NV_RX_OVERFLOW) {
1863 np->stats.rx_over_errors++;
1864 np->stats.rx_errors++;
1867 if (flags & NV_RX_ERROR4) {
1868 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1870 np->stats.rx_errors++;
1874 /* framing errors are soft errors. */
1875 if (flags & NV_RX_FRAMINGERR) {
1876 if (flags & NV_RX_SUBSTRACT1) {
1882 if (!(flags & NV_RX2_DESCRIPTORVALID))
1885 if (flags & NV_RX2_ERROR) {
1886 if (flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) {
1887 np->stats.rx_errors++;
1890 if (flags & NV_RX2_CRCERR) {
1891 np->stats.rx_crc_errors++;
1892 np->stats.rx_errors++;
1895 if (flags & NV_RX2_OVERFLOW) {
1896 np->stats.rx_over_errors++;
1897 np->stats.rx_errors++;
1900 if (flags & NV_RX2_ERROR4) {
1901 len = nv_getlen(dev, np->rx_skbuff[i]->data, len);
1903 np->stats.rx_errors++;
1907 /* framing errors are soft errors */
1908 if (flags & NV_RX2_FRAMINGERR) {
1909 if (flags & NV_RX2_SUBSTRACT1) {
1915 flags &= NV_RX2_CHECKSUMMASK;
1916 if (flags == NV_RX2_CHECKSUMOK1 ||
1917 flags == NV_RX2_CHECKSUMOK2 ||
1918 flags == NV_RX2_CHECKSUMOK3) {
1919 dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name);
1920 np->rx_skbuff[i]->ip_summed = CHECKSUM_UNNECESSARY;
1922 dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name);
1926 /* got a valid packet - forward it to the network core */
1927 skb = np->rx_skbuff[i];
1928 np->rx_skbuff[i] = NULL;
1931 skb->protocol = eth_type_trans(skb, dev);
1932 dprintk(KERN_DEBUG "%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n",
1933 dev->name, np->cur_rx, len, skb->protocol);
1934 #ifdef CONFIG_FORCEDETH_NAPI
1935 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
1936 vlan_hwaccel_receive_skb(skb, np->vlangrp,
1937 vlanflags & NV_RX3_VLAN_TAG_MASK);
1939 netif_receive_skb(skb);
1941 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
1942 vlan_hwaccel_rx(skb, np->vlangrp,
1943 vlanflags & NV_RX3_VLAN_TAG_MASK);
1947 dev->last_rx = jiffies;
1948 np->stats.rx_packets++;
1949 np->stats.rx_bytes += len;
1957 static void set_bufsize(struct net_device *dev)
1959 struct fe_priv *np = netdev_priv(dev);
1961 if (dev->mtu <= ETH_DATA_LEN)
1962 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
1964 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
1968 * nv_change_mtu: dev->change_mtu function
1969 * Called with dev_base_lock held for read.
1971 static int nv_change_mtu(struct net_device *dev, int new_mtu)
1973 struct fe_priv *np = netdev_priv(dev);
1976 if (new_mtu < 64 || new_mtu > np->pkt_limit)
1982 /* return early if the buffer sizes will not change */
1983 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
1985 if (old_mtu == new_mtu)
1988 /* synchronized against open : rtnl_lock() held by caller */
1989 if (netif_running(dev)) {
1990 u8 __iomem *base = get_hwbase(dev);
1992 * It seems that the nic preloads valid ring entries into an
1993 * internal buffer. The procedure for flushing everything is
1994 * guessed, there is probably a simpler approach.
1995 * Changing the MTU is a rare event, it shouldn't matter.
1997 nv_disable_irq(dev);
1998 netif_tx_lock_bh(dev);
1999 spin_lock(&np->lock);
2004 /* drain rx queue */
2007 /* reinit driver view of the rx queue */
2009 if (nv_init_ring(dev)) {
2010 if (!np->in_shutdown)
2011 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2013 /* reinit nic view of the rx queue */
2014 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
2015 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
2016 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
2017 base + NvRegRingSizes);
2019 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2022 /* restart rx engine */
2025 spin_unlock(&np->lock);
2026 netif_tx_unlock_bh(dev);
2032 static void nv_copy_mac_to_hw(struct net_device *dev)
2034 u8 __iomem *base = get_hwbase(dev);
2037 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
2038 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
2039 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
2041 writel(mac[0], base + NvRegMacAddrA);
2042 writel(mac[1], base + NvRegMacAddrB);
2046 * nv_set_mac_address: dev->set_mac_address function
2047 * Called with rtnl_lock() held.
2049 static int nv_set_mac_address(struct net_device *dev, void *addr)
2051 struct fe_priv *np = netdev_priv(dev);
2052 struct sockaddr *macaddr = (struct sockaddr*)addr;
2054 if (!is_valid_ether_addr(macaddr->sa_data))
2055 return -EADDRNOTAVAIL;
2057 /* synchronized against open : rtnl_lock() held by caller */
2058 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
2060 if (netif_running(dev)) {
2061 netif_tx_lock_bh(dev);
2062 spin_lock_irq(&np->lock);
2064 /* stop rx engine */
2067 /* set mac address */
2068 nv_copy_mac_to_hw(dev);
2070 /* restart rx engine */
2072 spin_unlock_irq(&np->lock);
2073 netif_tx_unlock_bh(dev);
2075 nv_copy_mac_to_hw(dev);
2081 * nv_set_multicast: dev->set_multicast function
2082 * Called with netif_tx_lock held.
2084 static void nv_set_multicast(struct net_device *dev)
2086 struct fe_priv *np = netdev_priv(dev);
2087 u8 __iomem *base = get_hwbase(dev);
2090 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
2092 memset(addr, 0, sizeof(addr));
2093 memset(mask, 0, sizeof(mask));
2095 if (dev->flags & IFF_PROMISC) {
2096 pff |= NVREG_PFF_PROMISC;
2098 pff |= NVREG_PFF_MYADDR;
2100 if (dev->flags & IFF_ALLMULTI || dev->mc_list) {
2104 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
2105 if (dev->flags & IFF_ALLMULTI) {
2106 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
2108 struct dev_mc_list *walk;
2110 walk = dev->mc_list;
2111 while (walk != NULL) {
2113 a = le32_to_cpu(*(u32 *) walk->dmi_addr);
2114 b = le16_to_cpu(*(u16 *) (&walk->dmi_addr[4]));
2122 addr[0] = alwaysOn[0];
2123 addr[1] = alwaysOn[1];
2124 mask[0] = alwaysOn[0] | alwaysOff[0];
2125 mask[1] = alwaysOn[1] | alwaysOff[1];
2128 addr[0] |= NVREG_MCASTADDRA_FORCE;
2129 pff |= NVREG_PFF_ALWAYS;
2130 spin_lock_irq(&np->lock);
2132 writel(addr[0], base + NvRegMulticastAddrA);
2133 writel(addr[1], base + NvRegMulticastAddrB);
2134 writel(mask[0], base + NvRegMulticastMaskA);
2135 writel(mask[1], base + NvRegMulticastMaskB);
2136 writel(pff, base + NvRegPacketFilterFlags);
2137 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
2140 spin_unlock_irq(&np->lock);
2143 static void nv_update_pause(struct net_device *dev, u32 pause_flags)
2145 struct fe_priv *np = netdev_priv(dev);
2146 u8 __iomem *base = get_hwbase(dev);
2148 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
2150 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
2151 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
2152 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
2153 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
2154 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2156 writel(pff, base + NvRegPacketFilterFlags);
2159 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
2160 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
2161 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
2162 writel(NVREG_TX_PAUSEFRAME_ENABLE, base + NvRegTxPauseFrame);
2163 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
2164 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2166 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
2167 writel(regmisc, base + NvRegMisc1);
2173 * nv_update_linkspeed: Setup the MAC according to the link partner
2174 * @dev: Network device to be configured
2176 * The function queries the PHY and checks if there is a link partner.
2177 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
2178 * set to 10 MBit HD.
2180 * The function returns 0 if there is no link partner and 1 if there is
2181 * a good link partner.
2183 static int nv_update_linkspeed(struct net_device *dev)
2185 struct fe_priv *np = netdev_priv(dev);
2186 u8 __iomem *base = get_hwbase(dev);
2189 int adv_lpa, adv_pause, lpa_pause;
2190 int newls = np->linkspeed;
2191 int newdup = np->duplex;
2194 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
2196 /* BMSR_LSTATUS is latched, read it twice:
2197 * we want the current value.
2199 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2200 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2202 if (!(mii_status & BMSR_LSTATUS)) {
2203 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
2205 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2211 if (np->autoneg == 0) {
2212 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
2213 dev->name, np->fixed_mode);
2214 if (np->fixed_mode & LPA_100FULL) {
2215 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2217 } else if (np->fixed_mode & LPA_100HALF) {
2218 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2220 } else if (np->fixed_mode & LPA_10FULL) {
2221 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2224 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2230 /* check auto negotiation is complete */
2231 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
2232 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
2233 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2236 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
2240 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2241 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
2242 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
2243 dev->name, adv, lpa);
2246 if (np->gigabit == PHY_GIGABIT) {
2247 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
2248 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
2250 if ((control_1000 & ADVERTISE_1000FULL) &&
2251 (status_1000 & LPA_1000FULL)) {
2252 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
2254 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
2260 /* FIXME: handle parallel detection properly */
2261 adv_lpa = lpa & adv;
2262 if (adv_lpa & LPA_100FULL) {
2263 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2265 } else if (adv_lpa & LPA_100HALF) {
2266 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2268 } else if (adv_lpa & LPA_10FULL) {
2269 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2271 } else if (adv_lpa & LPA_10HALF) {
2272 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2275 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, adv_lpa);
2276 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2281 if (np->duplex == newdup && np->linkspeed == newls)
2284 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
2285 dev->name, np->linkspeed, np->duplex, newls, newdup);
2287 np->duplex = newdup;
2288 np->linkspeed = newls;
2290 if (np->gigabit == PHY_GIGABIT) {
2291 phyreg = readl(base + NvRegRandomSeed);
2292 phyreg &= ~(0x3FF00);
2293 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
2294 phyreg |= NVREG_RNDSEED_FORCE3;
2295 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
2296 phyreg |= NVREG_RNDSEED_FORCE2;
2297 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
2298 phyreg |= NVREG_RNDSEED_FORCE;
2299 writel(phyreg, base + NvRegRandomSeed);
2302 phyreg = readl(base + NvRegPhyInterface);
2303 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
2304 if (np->duplex == 0)
2306 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
2308 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2310 writel(phyreg, base + NvRegPhyInterface);
2312 if (phyreg & PHY_RGMII) {
2313 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2314 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
2316 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
2318 txreg = NVREG_TX_DEFERRAL_DEFAULT;
2320 writel(txreg, base + NvRegTxDeferral);
2322 if (np->desc_ver == DESC_VER_1) {
2323 txreg = NVREG_TX_WM_DESC1_DEFAULT;
2325 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2326 txreg = NVREG_TX_WM_DESC2_3_1000;
2328 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
2330 writel(txreg, base + NvRegTxWatermark);
2332 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
2335 writel(np->linkspeed, base + NvRegLinkSpeed);
2339 /* setup pause frame */
2340 if (np->duplex != 0) {
2341 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
2342 adv_pause = adv & (ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM);
2343 lpa_pause = lpa & (LPA_PAUSE_CAP| LPA_PAUSE_ASYM);
2345 switch (adv_pause) {
2346 case ADVERTISE_PAUSE_CAP:
2347 if (lpa_pause & LPA_PAUSE_CAP) {
2348 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2349 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2350 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2353 case ADVERTISE_PAUSE_ASYM:
2354 if (lpa_pause == (LPA_PAUSE_CAP| LPA_PAUSE_ASYM))
2356 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2359 case ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM:
2360 if (lpa_pause & LPA_PAUSE_CAP)
2362 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2363 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2364 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2366 if (lpa_pause == LPA_PAUSE_ASYM)
2368 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2373 pause_flags = np->pause_flags;
2376 nv_update_pause(dev, pause_flags);
2381 static void nv_linkchange(struct net_device *dev)
2383 if (nv_update_linkspeed(dev)) {
2384 if (!netif_carrier_ok(dev)) {
2385 netif_carrier_on(dev);
2386 printk(KERN_INFO "%s: link up.\n", dev->name);
2390 if (netif_carrier_ok(dev)) {
2391 netif_carrier_off(dev);
2392 printk(KERN_INFO "%s: link down.\n", dev->name);
2398 static void nv_link_irq(struct net_device *dev)
2400 u8 __iomem *base = get_hwbase(dev);
2403 miistat = readl(base + NvRegMIIStatus);
2404 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
2405 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
2407 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
2409 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
2412 static irqreturn_t nv_nic_irq(int foo, void *data)
2414 struct net_device *dev = (struct net_device *) data;
2415 struct fe_priv *np = netdev_priv(dev);
2416 u8 __iomem *base = get_hwbase(dev);
2420 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
2423 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
2424 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2425 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2427 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2428 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
2431 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2432 if (!(events & np->irqmask))
2435 spin_lock(&np->lock);
2437 spin_unlock(&np->lock);
2439 if (events & NVREG_IRQ_LINK) {
2440 spin_lock(&np->lock);
2442 spin_unlock(&np->lock);
2444 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
2445 spin_lock(&np->lock);
2447 spin_unlock(&np->lock);
2448 np->link_timeout = jiffies + LINK_TIMEOUT;
2450 if (events & (NVREG_IRQ_TX_ERR)) {
2451 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2454 if (events & (NVREG_IRQ_UNKNOWN)) {
2455 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2458 #ifdef CONFIG_FORCEDETH_NAPI
2459 if (events & NVREG_IRQ_RX_ALL) {
2460 netif_rx_schedule(dev);
2462 /* Disable furthur receive irq's */
2463 spin_lock(&np->lock);
2464 np->irqmask &= ~NVREG_IRQ_RX_ALL;
2466 if (np->msi_flags & NV_MSI_X_ENABLED)
2467 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2469 writel(np->irqmask, base + NvRegIrqMask);
2470 spin_unlock(&np->lock);
2473 nv_rx_process(dev, dev->weight);
2474 if (nv_alloc_rx(dev)) {
2475 spin_lock(&np->lock);
2476 if (!np->in_shutdown)
2477 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2478 spin_unlock(&np->lock);
2481 if (i > max_interrupt_work) {
2482 spin_lock(&np->lock);
2483 /* disable interrupts on the nic */
2484 if (!(np->msi_flags & NV_MSI_X_ENABLED))
2485 writel(0, base + NvRegIrqMask);
2487 writel(np->irqmask, base + NvRegIrqMask);
2490 if (!np->in_shutdown) {
2491 np->nic_poll_irq = np->irqmask;
2492 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2494 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
2495 spin_unlock(&np->lock);
2500 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
2502 return IRQ_RETVAL(i);
2505 static irqreturn_t nv_nic_irq_tx(int foo, void *data)
2507 struct net_device *dev = (struct net_device *) data;
2508 struct fe_priv *np = netdev_priv(dev);
2509 u8 __iomem *base = get_hwbase(dev);
2512 unsigned long flags;
2514 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
2517 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
2518 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
2520 dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
2521 if (!(events & np->irqmask))
2524 spin_lock_irqsave(&np->lock, flags);
2526 spin_unlock_irqrestore(&np->lock, flags);
2528 if (events & (NVREG_IRQ_TX_ERR)) {
2529 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2532 if (i > max_interrupt_work) {
2533 spin_lock_irqsave(&np->lock, flags);
2534 /* disable interrupts on the nic */
2535 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
2538 if (!np->in_shutdown) {
2539 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
2540 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2542 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
2543 spin_unlock_irqrestore(&np->lock, flags);
2548 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
2550 return IRQ_RETVAL(i);
2553 #ifdef CONFIG_FORCEDETH_NAPI
2554 static int nv_napi_poll(struct net_device *dev, int *budget)
2556 int pkts, limit = min(*budget, dev->quota);
2557 struct fe_priv *np = netdev_priv(dev);
2558 u8 __iomem *base = get_hwbase(dev);
2560 pkts = nv_rx_process(dev, limit);
2562 if (nv_alloc_rx(dev)) {
2563 spin_lock_irq(&np->lock);
2564 if (!np->in_shutdown)
2565 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2566 spin_unlock_irq(&np->lock);
2570 /* all done, no more packets present */
2571 netif_rx_complete(dev);
2573 /* re-enable receive interrupts */
2574 spin_lock_irq(&np->lock);
2575 np->irqmask |= NVREG_IRQ_RX_ALL;
2576 if (np->msi_flags & NV_MSI_X_ENABLED)
2577 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2579 writel(np->irqmask, base + NvRegIrqMask);
2580 spin_unlock_irq(&np->lock);
2583 /* used up our quantum, so reschedule */
2591 #ifdef CONFIG_FORCEDETH_NAPI
2592 static irqreturn_t nv_nic_irq_rx(int foo, void *data)
2594 struct net_device *dev = (struct net_device *) data;
2595 u8 __iomem *base = get_hwbase(dev);
2598 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
2599 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
2602 netif_rx_schedule(dev);
2603 /* disable receive interrupts on the nic */
2604 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2610 static irqreturn_t nv_nic_irq_rx(int foo, void *data)
2612 struct net_device *dev = (struct net_device *) data;
2613 struct fe_priv *np = netdev_priv(dev);
2614 u8 __iomem *base = get_hwbase(dev);
2617 unsigned long flags;
2619 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name);
2622 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
2623 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
2625 dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
2626 if (!(events & np->irqmask))
2629 nv_rx_process(dev, dev->weight);
2630 if (nv_alloc_rx(dev)) {
2631 spin_lock_irqsave(&np->lock, flags);
2632 if (!np->in_shutdown)
2633 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2634 spin_unlock_irqrestore(&np->lock, flags);
2637 if (i > max_interrupt_work) {
2638 spin_lock_irqsave(&np->lock, flags);
2639 /* disable interrupts on the nic */
2640 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2643 if (!np->in_shutdown) {
2644 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
2645 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2647 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
2648 spin_unlock_irqrestore(&np->lock, flags);
2652 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
2654 return IRQ_RETVAL(i);
2658 static irqreturn_t nv_nic_irq_other(int foo, void *data)
2660 struct net_device *dev = (struct net_device *) data;
2661 struct fe_priv *np = netdev_priv(dev);
2662 u8 __iomem *base = get_hwbase(dev);
2665 unsigned long flags;
2667 dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
2670 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
2671 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
2673 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2674 if (!(events & np->irqmask))
2677 if (events & NVREG_IRQ_LINK) {
2678 spin_lock_irqsave(&np->lock, flags);
2680 spin_unlock_irqrestore(&np->lock, flags);
2682 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
2683 spin_lock_irqsave(&np->lock, flags);
2685 spin_unlock_irqrestore(&np->lock, flags);
2686 np->link_timeout = jiffies + LINK_TIMEOUT;
2688 if (events & (NVREG_IRQ_UNKNOWN)) {
2689 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2692 if (i > max_interrupt_work) {
2693 spin_lock_irqsave(&np->lock, flags);
2694 /* disable interrupts on the nic */
2695 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
2698 if (!np->in_shutdown) {
2699 np->nic_poll_irq |= NVREG_IRQ_OTHER;
2700 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2702 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
2703 spin_unlock_irqrestore(&np->lock, flags);
2708 dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
2710 return IRQ_RETVAL(i);
2713 static irqreturn_t nv_nic_irq_test(int foo, void *data)
2715 struct net_device *dev = (struct net_device *) data;
2716 struct fe_priv *np = netdev_priv(dev);
2717 u8 __iomem *base = get_hwbase(dev);
2720 dprintk(KERN_DEBUG "%s: nv_nic_irq_test\n", dev->name);
2722 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
2723 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2724 writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus);
2726 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2727 writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
2730 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2731 if (!(events & NVREG_IRQ_TIMER))
2732 return IRQ_RETVAL(0);
2734 spin_lock(&np->lock);
2736 spin_unlock(&np->lock);
2738 dprintk(KERN_DEBUG "%s: nv_nic_irq_test completed\n", dev->name);
2740 return IRQ_RETVAL(1);
2743 static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
2745 u8 __iomem *base = get_hwbase(dev);
2749 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
2750 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
2751 * the remaining 8 interrupts.
2753 for (i = 0; i < 8; i++) {
2754 if ((irqmask >> i) & 0x1) {
2755 msixmap |= vector << (i << 2);
2758 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
2761 for (i = 0; i < 8; i++) {
2762 if ((irqmask >> (i + 8)) & 0x1) {
2763 msixmap |= vector << (i << 2);
2766 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
2769 static int nv_request_irq(struct net_device *dev, int intr_test)
2771 struct fe_priv *np = get_nvpriv(dev);
2772 u8 __iomem *base = get_hwbase(dev);
2776 if (np->msi_flags & NV_MSI_X_CAPABLE) {
2777 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
2778 np->msi_x_entry[i].entry = i;
2780 if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) {
2781 np->msi_flags |= NV_MSI_X_ENABLED;
2782 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
2783 /* Request irq for rx handling */
2784 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, &nv_nic_irq_rx, IRQF_SHARED, dev->name, dev) != 0) {
2785 printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret);
2786 pci_disable_msix(np->pci_dev);
2787 np->msi_flags &= ~NV_MSI_X_ENABLED;
2790 /* Request irq for tx handling */
2791 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, &nv_nic_irq_tx, IRQF_SHARED, dev->name, dev) != 0) {
2792 printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret);
2793 pci_disable_msix(np->pci_dev);
2794 np->msi_flags &= ~NV_MSI_X_ENABLED;
2797 /* Request irq for link and timer handling */
2798 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector, &nv_nic_irq_other, IRQF_SHARED, dev->name, dev) != 0) {
2799 printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret);
2800 pci_disable_msix(np->pci_dev);
2801 np->msi_flags &= ~NV_MSI_X_ENABLED;
2804 /* map interrupts to their respective vector */
2805 writel(0, base + NvRegMSIXMap0);
2806 writel(0, base + NvRegMSIXMap1);
2807 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
2808 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
2809 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
2811 /* Request irq for all interrupts */
2813 request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
2815 request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, &nv_nic_irq_test, IRQF_SHARED, dev->name, dev) != 0)) {
2816 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
2817 pci_disable_msix(np->pci_dev);
2818 np->msi_flags &= ~NV_MSI_X_ENABLED;
2822 /* map interrupts to vector 0 */
2823 writel(0, base + NvRegMSIXMap0);
2824 writel(0, base + NvRegMSIXMap1);
2828 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
2829 if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
2830 np->msi_flags |= NV_MSI_ENABLED;
2831 if ((!intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
2832 (intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq_test, IRQF_SHARED, dev->name, dev) != 0)) {
2833 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
2834 pci_disable_msi(np->pci_dev);
2835 np->msi_flags &= ~NV_MSI_ENABLED;
2839 /* map interrupts to vector 0 */
2840 writel(0, base + NvRegMSIMap0);
2841 writel(0, base + NvRegMSIMap1);
2842 /* enable msi vector 0 */
2843 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
2847 if ((!intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq, IRQF_SHARED, dev->name, dev) != 0) ||
2848 (intr_test && request_irq(np->pci_dev->irq, &nv_nic_irq_test, IRQF_SHARED, dev->name, dev) != 0))
2855 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
2857 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
2862 static void nv_free_irq(struct net_device *dev)
2864 struct fe_priv *np = get_nvpriv(dev);
2867 if (np->msi_flags & NV_MSI_X_ENABLED) {
2868 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
2869 free_irq(np->msi_x_entry[i].vector, dev);
2871 pci_disable_msix(np->pci_dev);
2872 np->msi_flags &= ~NV_MSI_X_ENABLED;
2874 free_irq(np->pci_dev->irq, dev);
2875 if (np->msi_flags & NV_MSI_ENABLED) {
2876 pci_disable_msi(np->pci_dev);
2877 np->msi_flags &= ~NV_MSI_ENABLED;
2882 static void nv_do_nic_poll(unsigned long data)
2884 struct net_device *dev = (struct net_device *) data;
2885 struct fe_priv *np = netdev_priv(dev);
2886 u8 __iomem *base = get_hwbase(dev);
2890 * First disable irq(s) and then
2891 * reenable interrupts on the nic, we have to do this before calling
2892 * nv_nic_irq because that may decide to do otherwise
2895 if (!using_multi_irqs(dev)) {
2896 if (np->msi_flags & NV_MSI_X_ENABLED)
2897 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
2899 disable_irq_lockdep(dev->irq);
2902 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
2903 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
2904 mask |= NVREG_IRQ_RX_ALL;
2906 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
2907 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
2908 mask |= NVREG_IRQ_TX_ALL;
2910 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
2911 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
2912 mask |= NVREG_IRQ_OTHER;
2915 np->nic_poll_irq = 0;
2917 /* FIXME: Do we need synchronize_irq(dev->irq) here? */
2919 writel(mask, base + NvRegIrqMask);
2922 if (!using_multi_irqs(dev)) {
2924 if (np->msi_flags & NV_MSI_X_ENABLED)
2925 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
2927 enable_irq_lockdep(dev->irq);
2929 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
2930 nv_nic_irq_rx(0, dev);
2931 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
2933 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
2934 nv_nic_irq_tx(0, dev);
2935 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
2937 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
2938 nv_nic_irq_other(0, dev);
2939 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
2944 #ifdef CONFIG_NET_POLL_CONTROLLER
2945 static void nv_poll_controller(struct net_device *dev)
2947 nv_do_nic_poll((unsigned long) dev);
2951 static void nv_do_stats_poll(unsigned long data)
2953 struct net_device *dev = (struct net_device *) data;
2954 struct fe_priv *np = netdev_priv(dev);
2955 u8 __iomem *base = get_hwbase(dev);
2957 np->estats.tx_bytes += readl(base + NvRegTxCnt);
2958 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
2959 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
2960 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
2961 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
2962 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
2963 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
2964 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
2965 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
2966 np->estats.tx_deferral += readl(base + NvRegTxDef);
2967 np->estats.tx_packets += readl(base + NvRegTxFrame);
2968 np->estats.tx_pause += readl(base + NvRegTxPause);
2969 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
2970 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
2971 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
2972 np->estats.rx_runt += readl(base + NvRegRxRunt);
2973 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
2974 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
2975 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
2976 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
2977 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
2978 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
2979 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
2980 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
2981 np->estats.rx_bytes += readl(base + NvRegRxCnt);
2982 np->estats.rx_pause += readl(base + NvRegRxPause);
2983 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
2984 np->estats.rx_packets =
2985 np->estats.rx_unicast +
2986 np->estats.rx_multicast +
2987 np->estats.rx_broadcast;
2988 np->estats.rx_errors_total =
2989 np->estats.rx_crc_errors +
2990 np->estats.rx_over_errors +
2991 np->estats.rx_frame_error +
2992 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
2993 np->estats.rx_late_collision +
2994 np->estats.rx_runt +
2995 np->estats.rx_frame_too_long;
2997 if (!np->in_shutdown)
2998 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
3001 static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
3003 struct fe_priv *np = netdev_priv(dev);
3004 strcpy(info->driver, "forcedeth");
3005 strcpy(info->version, FORCEDETH_VERSION);
3006 strcpy(info->bus_info, pci_name(np->pci_dev));
3009 static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3011 struct fe_priv *np = netdev_priv(dev);
3012 wolinfo->supported = WAKE_MAGIC;
3014 spin_lock_irq(&np->lock);
3016 wolinfo->wolopts = WAKE_MAGIC;
3017 spin_unlock_irq(&np->lock);
3020 static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3022 struct fe_priv *np = netdev_priv(dev);
3023 u8 __iomem *base = get_hwbase(dev);
3026 if (wolinfo->wolopts == 0) {
3028 } else if (wolinfo->wolopts & WAKE_MAGIC) {
3030 flags = NVREG_WAKEUPFLAGS_ENABLE;
3032 if (netif_running(dev)) {
3033 spin_lock_irq(&np->lock);
3034 writel(flags, base + NvRegWakeUpFlags);
3035 spin_unlock_irq(&np->lock);
3040 static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3042 struct fe_priv *np = netdev_priv(dev);
3045 spin_lock_irq(&np->lock);
3046 ecmd->port = PORT_MII;
3047 if (!netif_running(dev)) {
3048 /* We do not track link speed / duplex setting if the
3049 * interface is disabled. Force a link check */
3050 if (nv_update_linkspeed(dev)) {
3051 if (!netif_carrier_ok(dev))
3052 netif_carrier_on(dev);
3054 if (netif_carrier_ok(dev))
3055 netif_carrier_off(dev);
3059 if (netif_carrier_ok(dev)) {
3060 switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) {
3061 case NVREG_LINKSPEED_10:
3062 ecmd->speed = SPEED_10;
3064 case NVREG_LINKSPEED_100:
3065 ecmd->speed = SPEED_100;
3067 case NVREG_LINKSPEED_1000:
3068 ecmd->speed = SPEED_1000;
3071 ecmd->duplex = DUPLEX_HALF;
3073 ecmd->duplex = DUPLEX_FULL;
3079 ecmd->autoneg = np->autoneg;
3081 ecmd->advertising = ADVERTISED_MII;
3083 ecmd->advertising |= ADVERTISED_Autoneg;
3084 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3085 if (adv & ADVERTISE_10HALF)
3086 ecmd->advertising |= ADVERTISED_10baseT_Half;
3087 if (adv & ADVERTISE_10FULL)
3088 ecmd->advertising |= ADVERTISED_10baseT_Full;
3089 if (adv & ADVERTISE_100HALF)
3090 ecmd->advertising |= ADVERTISED_100baseT_Half;
3091 if (adv & ADVERTISE_100FULL)
3092 ecmd->advertising |= ADVERTISED_100baseT_Full;
3093 if (np->gigabit == PHY_GIGABIT) {
3094 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3095 if (adv & ADVERTISE_1000FULL)
3096 ecmd->advertising |= ADVERTISED_1000baseT_Full;
3099 ecmd->supported = (SUPPORTED_Autoneg |
3100 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
3101 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
3103 if (np->gigabit == PHY_GIGABIT)
3104 ecmd->supported |= SUPPORTED_1000baseT_Full;
3106 ecmd->phy_address = np->phyaddr;
3107 ecmd->transceiver = XCVR_EXTERNAL;
3109 /* ignore maxtxpkt, maxrxpkt for now */
3110 spin_unlock_irq(&np->lock);
3114 static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3116 struct fe_priv *np = netdev_priv(dev);
3118 if (ecmd->port != PORT_MII)
3120 if (ecmd->transceiver != XCVR_EXTERNAL)
3122 if (ecmd->phy_address != np->phyaddr) {
3123 /* TODO: support switching between multiple phys. Should be
3124 * trivial, but not enabled due to lack of test hardware. */
3127 if (ecmd->autoneg == AUTONEG_ENABLE) {
3130 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
3131 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
3132 if (np->gigabit == PHY_GIGABIT)
3133 mask |= ADVERTISED_1000baseT_Full;
3135 if ((ecmd->advertising & mask) == 0)
3138 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
3139 /* Note: autonegotiation disable, speed 1000 intentionally
3140 * forbidden - noone should need that. */
3142 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
3144 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
3150 netif_carrier_off(dev);
3151 if (netif_running(dev)) {
3152 nv_disable_irq(dev);
3153 netif_tx_lock_bh(dev);
3154 spin_lock(&np->lock);
3158 spin_unlock(&np->lock);
3159 netif_tx_unlock_bh(dev);
3162 if (ecmd->autoneg == AUTONEG_ENABLE) {
3167 /* advertise only what has been requested */
3168 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3169 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3170 if (ecmd->advertising & ADVERTISED_10baseT_Half)
3171 adv |= ADVERTISE_10HALF;
3172 if (ecmd->advertising & ADVERTISED_10baseT_Full)
3173 adv |= ADVERTISE_10FULL;
3174 if (ecmd->advertising & ADVERTISED_100baseT_Half)
3175 adv |= ADVERTISE_100HALF;
3176 if (ecmd->advertising & ADVERTISED_100baseT_Full)
3177 adv |= ADVERTISE_100FULL;
3178 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
3179 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3180 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3181 adv |= ADVERTISE_PAUSE_ASYM;
3182 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3184 if (np->gigabit == PHY_GIGABIT) {
3185 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3186 adv &= ~ADVERTISE_1000FULL;
3187 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
3188 adv |= ADVERTISE_1000FULL;
3189 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
3192 if (netif_running(dev))
3193 printk(KERN_INFO "%s: link down.\n", dev->name);
3194 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3195 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
3196 bmcr |= BMCR_ANENABLE;
3197 /* reset the phy in order for settings to stick,
3198 * and cause autoneg to start */
3199 if (phy_reset(dev, bmcr)) {
3200 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3204 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3205 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3212 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3213 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3214 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
3215 adv |= ADVERTISE_10HALF;
3216 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
3217 adv |= ADVERTISE_10FULL;
3218 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
3219 adv |= ADVERTISE_100HALF;
3220 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
3221 adv |= ADVERTISE_100FULL;
3222 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
3223 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisments but disable tx pause */
3224 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3225 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3227 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
3228 adv |= ADVERTISE_PAUSE_ASYM;
3229 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3231 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3232 np->fixed_mode = adv;
3234 if (np->gigabit == PHY_GIGABIT) {
3235 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3236 adv &= ~ADVERTISE_1000FULL;
3237 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
3240 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3241 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
3242 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
3243 bmcr |= BMCR_FULLDPLX;
3244 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
3245 bmcr |= BMCR_SPEED100;
3246 if (np->phy_oui == PHY_OUI_MARVELL) {
3247 /* reset the phy in order for forced mode settings to stick */
3248 if (phy_reset(dev, bmcr)) {
3249 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3253 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3254 if (netif_running(dev)) {
3255 /* Wait a bit and then reconfigure the nic. */
3262 if (netif_running(dev)) {
3271 #define FORCEDETH_REGS_VER 1
3273 static int nv_get_regs_len(struct net_device *dev)
3275 struct fe_priv *np = netdev_priv(dev);
3276 return np->register_size;
3279 static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
3281 struct fe_priv *np = netdev_priv(dev);
3282 u8 __iomem *base = get_hwbase(dev);
3286 regs->version = FORCEDETH_REGS_VER;
3287 spin_lock_irq(&np->lock);
3288 for (i = 0;i <= np->register_size/sizeof(u32); i++)
3289 rbuf[i] = readl(base + i*sizeof(u32));
3290 spin_unlock_irq(&np->lock);
3293 static int nv_nway_reset(struct net_device *dev)
3295 struct fe_priv *np = netdev_priv(dev);
3301 netif_carrier_off(dev);
3302 if (netif_running(dev)) {
3303 nv_disable_irq(dev);
3304 netif_tx_lock_bh(dev);
3305 spin_lock(&np->lock);
3309 spin_unlock(&np->lock);
3310 netif_tx_unlock_bh(dev);
3311 printk(KERN_INFO "%s: link down.\n", dev->name);
3314 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3315 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
3316 bmcr |= BMCR_ANENABLE;
3317 /* reset the phy in order for settings to stick*/
3318 if (phy_reset(dev, bmcr)) {
3319 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3323 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3324 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3327 if (netif_running(dev)) {
3340 static int nv_set_tso(struct net_device *dev, u32 value)
3342 struct fe_priv *np = netdev_priv(dev);
3344 if ((np->driver_data & DEV_HAS_CHECKSUM))
3345 return ethtool_op_set_tso(dev, value);
3350 static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
3352 struct fe_priv *np = netdev_priv(dev);
3354 ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
3355 ring->rx_mini_max_pending = 0;
3356 ring->rx_jumbo_max_pending = 0;
3357 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
3359 ring->rx_pending = np->rx_ring_size;
3360 ring->rx_mini_pending = 0;
3361 ring->rx_jumbo_pending = 0;
3362 ring->tx_pending = np->tx_ring_size;
3365 static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
3367 struct fe_priv *np = netdev_priv(dev);
3368 u8 __iomem *base = get_hwbase(dev);
3369 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff, *rx_dma, *tx_dma, *tx_dma_len;
3370 dma_addr_t ring_addr;
3372 if (ring->rx_pending < RX_RING_MIN ||
3373 ring->tx_pending < TX_RING_MIN ||
3374 ring->rx_mini_pending != 0 ||
3375 ring->rx_jumbo_pending != 0 ||
3376 (np->desc_ver == DESC_VER_1 &&
3377 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
3378 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
3379 (np->desc_ver != DESC_VER_1 &&
3380 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
3381 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
3385 /* allocate new rings */
3386 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3387 rxtx_ring = pci_alloc_consistent(np->pci_dev,
3388 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
3391 rxtx_ring = pci_alloc_consistent(np->pci_dev,
3392 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
3395 rx_skbuff = kmalloc(sizeof(struct sk_buff*) * ring->rx_pending, GFP_KERNEL);
3396 rx_dma = kmalloc(sizeof(dma_addr_t) * ring->rx_pending, GFP_KERNEL);
3397 tx_skbuff = kmalloc(sizeof(struct sk_buff*) * ring->tx_pending, GFP_KERNEL);
3398 tx_dma = kmalloc(sizeof(dma_addr_t) * ring->tx_pending, GFP_KERNEL);
3399 tx_dma_len = kmalloc(sizeof(unsigned int) * ring->tx_pending, GFP_KERNEL);
3400 if (!rxtx_ring || !rx_skbuff || !rx_dma || !tx_skbuff || !tx_dma || !tx_dma_len) {
3401 /* fall back to old rings */
3402 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3404 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
3405 rxtx_ring, ring_addr);
3408 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
3409 rxtx_ring, ring_addr);
3424 if (netif_running(dev)) {
3425 nv_disable_irq(dev);
3426 netif_tx_lock_bh(dev);
3427 spin_lock(&np->lock);
3439 /* set new values */
3440 np->rx_ring_size = ring->rx_pending;
3441 np->tx_ring_size = ring->tx_pending;
3442 np->tx_limit_stop = ring->tx_pending - TX_LIMIT_DIFFERENCE;
3443 np->tx_limit_start = ring->tx_pending - TX_LIMIT_DIFFERENCE - 1;
3444 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3445 np->rx_ring.orig = (struct ring_desc*)rxtx_ring;
3446 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
3448 np->rx_ring.ex = (struct ring_desc_ex*)rxtx_ring;
3449 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
3451 np->rx_skbuff = (struct sk_buff**)rx_skbuff;
3452 np->rx_dma = (dma_addr_t*)rx_dma;
3453 np->tx_skbuff = (struct sk_buff**)tx_skbuff;
3454 np->tx_dma = (dma_addr_t*)tx_dma;
3455 np->tx_dma_len = (unsigned int*)tx_dma_len;
3456 np->ring_addr = ring_addr;
3458 memset(np->rx_skbuff, 0, sizeof(struct sk_buff*) * np->rx_ring_size);
3459 memset(np->rx_dma, 0, sizeof(dma_addr_t) * np->rx_ring_size);
3460 memset(np->tx_skbuff, 0, sizeof(struct sk_buff*) * np->tx_ring_size);
3461 memset(np->tx_dma, 0, sizeof(dma_addr_t) * np->tx_ring_size);
3462 memset(np->tx_dma_len, 0, sizeof(unsigned int) * np->tx_ring_size);
3464 if (netif_running(dev)) {
3465 /* reinit driver view of the queues */
3467 if (nv_init_ring(dev)) {
3468 if (!np->in_shutdown)
3469 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3472 /* reinit nic view of the queues */
3473 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3474 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3475 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3476 base + NvRegRingSizes);
3478 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3481 /* restart engines */
3484 spin_unlock(&np->lock);
3485 netif_tx_unlock_bh(dev);
3493 static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
3495 struct fe_priv *np = netdev_priv(dev);
3497 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
3498 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
3499 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
3502 static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
3504 struct fe_priv *np = netdev_priv(dev);
3507 if ((!np->autoneg && np->duplex == 0) ||
3508 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
3509 printk(KERN_INFO "%s: can not set pause settings when forced link is in half duplex.\n",
3513 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
3514 printk(KERN_INFO "%s: hardware does not support tx pause frames.\n", dev->name);
3518 netif_carrier_off(dev);
3519 if (netif_running(dev)) {
3520 nv_disable_irq(dev);
3521 netif_tx_lock_bh(dev);
3522 spin_lock(&np->lock);
3526 spin_unlock(&np->lock);
3527 netif_tx_unlock_bh(dev);
3530 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
3531 if (pause->rx_pause)
3532 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
3533 if (pause->tx_pause)
3534 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
3536 if (np->autoneg && pause->autoneg) {
3537 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
3539 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3540 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3541 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
3542 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3543 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3544 adv |= ADVERTISE_PAUSE_ASYM;
3545 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3547 if (netif_running(dev))
3548 printk(KERN_INFO "%s: link down.\n", dev->name);
3549 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3550 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3551 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3553 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
3554 if (pause->rx_pause)
3555 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3556 if (pause->tx_pause)
3557 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3559 if (!netif_running(dev))
3560 nv_update_linkspeed(dev);
3562 nv_update_pause(dev, np->pause_flags);
3565 if (netif_running(dev)) {
3573 static u32 nv_get_rx_csum(struct net_device *dev)
3575 struct fe_priv *np = netdev_priv(dev);
3576 return (np->rx_csum) != 0;
3579 static int nv_set_rx_csum(struct net_device *dev, u32 data)
3581 struct fe_priv *np = netdev_priv(dev);
3582 u8 __iomem *base = get_hwbase(dev);
3585 if (np->driver_data & DEV_HAS_CHECKSUM) {
3588 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
3591 /* vlan is dependent on rx checksum offload */
3592 if (!(np->vlanctl_bits & NVREG_VLANCONTROL_ENABLE))
3593 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
3595 if (netif_running(dev)) {
3596 spin_lock_irq(&np->lock);
3597 writel(np->txrxctl_bits, base + NvRegTxRxControl);
3598 spin_unlock_irq(&np->lock);
3607 static int nv_set_tx_csum(struct net_device *dev, u32 data)
3609 struct fe_priv *np = netdev_priv(dev);
3611 if (np->driver_data & DEV_HAS_CHECKSUM)
3612 return ethtool_op_set_tx_hw_csum(dev, data);
3617 static int nv_set_sg(struct net_device *dev, u32 data)
3619 struct fe_priv *np = netdev_priv(dev);
3621 if (np->driver_data & DEV_HAS_CHECKSUM)
3622 return ethtool_op_set_sg(dev, data);
3627 static int nv_get_stats_count(struct net_device *dev)
3629 struct fe_priv *np = netdev_priv(dev);
3631 if (np->driver_data & DEV_HAS_STATISTICS)
3632 return sizeof(struct nv_ethtool_stats)/sizeof(u64);
3637 static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *buffer)
3639 struct fe_priv *np = netdev_priv(dev);
3642 nv_do_stats_poll((unsigned long)dev);
3644 memcpy(buffer, &np->estats, nv_get_stats_count(dev)*sizeof(u64));
3647 static int nv_self_test_count(struct net_device *dev)
3649 struct fe_priv *np = netdev_priv(dev);
3651 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
3652 return NV_TEST_COUNT_EXTENDED;
3654 return NV_TEST_COUNT_BASE;
3657 static int nv_link_test(struct net_device *dev)
3659 struct fe_priv *np = netdev_priv(dev);
3662 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3663 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3665 /* check phy link status */
3666 if (!(mii_status & BMSR_LSTATUS))
3672 static int nv_register_test(struct net_device *dev)
3674 u8 __iomem *base = get_hwbase(dev);
3676 u32 orig_read, new_read;
3679 orig_read = readl(base + nv_registers_test[i].reg);
3681 /* xor with mask to toggle bits */
3682 orig_read ^= nv_registers_test[i].mask;
3684 writel(orig_read, base + nv_registers_test[i].reg);
3686 new_read = readl(base + nv_registers_test[i].reg);
3688 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
3691 /* restore original value */
3692 orig_read ^= nv_registers_test[i].mask;
3693 writel(orig_read, base + nv_registers_test[i].reg);
3695 } while (nv_registers_test[++i].reg != 0);
3700 static int nv_interrupt_test(struct net_device *dev)
3702 struct fe_priv *np = netdev_priv(dev);
3703 u8 __iomem *base = get_hwbase(dev);
3706 u32 save_msi_flags, save_poll_interval = 0;
3708 if (netif_running(dev)) {
3709 /* free current irq */
3711 save_poll_interval = readl(base+NvRegPollingInterval);
3714 /* flag to test interrupt handler */
3717 /* setup test irq */
3718 save_msi_flags = np->msi_flags;
3719 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
3720 np->msi_flags |= 0x001; /* setup 1 vector */
3721 if (nv_request_irq(dev, 1))
3724 /* setup timer interrupt */
3725 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
3726 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
3728 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
3730 /* wait for at least one interrupt */
3733 spin_lock_irq(&np->lock);
3735 /* flag should be set within ISR */
3736 testcnt = np->intr_test;
3740 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
3741 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3742 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3744 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3746 spin_unlock_irq(&np->lock);
3750 np->msi_flags = save_msi_flags;
3752 if (netif_running(dev)) {
3753 writel(save_poll_interval, base + NvRegPollingInterval);
3754 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
3755 /* restore original irq */
3756 if (nv_request_irq(dev, 0))
3763 static int nv_loopback_test(struct net_device *dev)
3765 struct fe_priv *np = netdev_priv(dev);
3766 u8 __iomem *base = get_hwbase(dev);
3767 struct sk_buff *tx_skb, *rx_skb;
3768 dma_addr_t test_dma_addr;
3769 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
3771 int len, i, pkt_len;
3773 u32 filter_flags = 0;
3774 u32 misc1_flags = 0;
3777 if (netif_running(dev)) {
3778 nv_disable_irq(dev);
3779 filter_flags = readl(base + NvRegPacketFilterFlags);
3780 misc1_flags = readl(base + NvRegMisc1);
3785 /* reinit driver view of the rx queue */
3789 /* setup hardware for loopback */
3790 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
3791 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
3793 /* reinit nic view of the rx queue */
3794 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3795 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3796 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3797 base + NvRegRingSizes);
3800 /* restart rx engine */
3804 /* setup packet for tx */
3805 pkt_len = ETH_DATA_LEN;
3806 tx_skb = dev_alloc_skb(pkt_len);
3808 printk(KERN_ERR "dev_alloc_skb() failed during loopback test"
3809 " of %s\n", dev->name);
3813 pkt_data = skb_put(tx_skb, pkt_len);
3814 for (i = 0; i < pkt_len; i++)
3815 pkt_data[i] = (u8)(i & 0xff);
3816 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
3817 tx_skb->end-tx_skb->data, PCI_DMA_FROMDEVICE);
3819 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3820 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
3821 np->tx_ring.orig[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
3823 np->tx_ring.ex[0].bufhigh = cpu_to_le64(test_dma_addr) >> 32;
3824 np->tx_ring.ex[0].buflow = cpu_to_le64(test_dma_addr) & 0x0FFFFFFFF;
3825 np->tx_ring.ex[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
3827 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3828 pci_push(get_hwbase(dev));
3832 /* check for rx of the packet */
3833 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3834 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
3835 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
3838 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
3839 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
3842 if (flags & NV_RX_AVAIL) {
3844 } else if (np->desc_ver == DESC_VER_1) {
3845 if (flags & NV_RX_ERROR)
3848 if (flags & NV_RX2_ERROR) {
3854 if (len != pkt_len) {
3856 dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n",
3857 dev->name, len, pkt_len);
3859 rx_skb = np->rx_skbuff[0];
3860 for (i = 0; i < pkt_len; i++) {
3861 if (rx_skb->data[i] != (u8)(i & 0xff)) {
3863 dprintk(KERN_DEBUG "%s: loopback pattern check failed on byte %d\n",
3870 dprintk(KERN_DEBUG "%s: loopback - did not receive test packet\n", dev->name);
3873 pci_unmap_page(np->pci_dev, test_dma_addr,
3874 tx_skb->end-tx_skb->data,
3876 dev_kfree_skb_any(tx_skb);
3882 /* drain rx queue */
3886 if (netif_running(dev)) {
3887 writel(misc1_flags, base + NvRegMisc1);
3888 writel(filter_flags, base + NvRegPacketFilterFlags);
3895 static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
3897 struct fe_priv *np = netdev_priv(dev);
3898 u8 __iomem *base = get_hwbase(dev);
3900 memset(buffer, 0, nv_self_test_count(dev)*sizeof(u64));
3902 if (!nv_link_test(dev)) {
3903 test->flags |= ETH_TEST_FL_FAILED;
3907 if (test->flags & ETH_TEST_FL_OFFLINE) {
3908 if (netif_running(dev)) {
3909 netif_stop_queue(dev);
3910 netif_poll_disable(dev);
3911 netif_tx_lock_bh(dev);
3912 spin_lock_irq(&np->lock);
3913 nv_disable_hw_interrupts(dev, np->irqmask);
3914 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3915 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3917 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
3923 /* drain rx queue */
3926 spin_unlock_irq(&np->lock);
3927 netif_tx_unlock_bh(dev);
3930 if (!nv_register_test(dev)) {
3931 test->flags |= ETH_TEST_FL_FAILED;
3935 result = nv_interrupt_test(dev);
3937 test->flags |= ETH_TEST_FL_FAILED;
3945 if (!nv_loopback_test(dev)) {
3946 test->flags |= ETH_TEST_FL_FAILED;
3950 if (netif_running(dev)) {
3951 /* reinit driver view of the rx queue */
3953 if (nv_init_ring(dev)) {
3954 if (!np->in_shutdown)
3955 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3957 /* reinit nic view of the rx queue */
3958 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3959 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3960 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3961 base + NvRegRingSizes);
3963 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3965 /* restart rx engine */
3968 netif_start_queue(dev);
3969 netif_poll_enable(dev);
3970 nv_enable_hw_interrupts(dev, np->irqmask);
3975 static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
3977 switch (stringset) {
3979 memcpy(buffer, &nv_estats_str, nv_get_stats_count(dev)*sizeof(struct nv_ethtool_str));
3982 memcpy(buffer, &nv_etests_str, nv_self_test_count(dev)*sizeof(struct nv_ethtool_str));
3987 static const struct ethtool_ops ops = {
3988 .get_drvinfo = nv_get_drvinfo,
3989 .get_link = ethtool_op_get_link,
3990 .get_wol = nv_get_wol,
3991 .set_wol = nv_set_wol,
3992 .get_settings = nv_get_settings,
3993 .set_settings = nv_set_settings,
3994 .get_regs_len = nv_get_regs_len,
3995 .get_regs = nv_get_regs,
3996 .nway_reset = nv_nway_reset,
3997 .get_perm_addr = ethtool_op_get_perm_addr,
3998 .get_tso = ethtool_op_get_tso,
3999 .set_tso = nv_set_tso,
4000 .get_ringparam = nv_get_ringparam,
4001 .set_ringparam = nv_set_ringparam,
4002 .get_pauseparam = nv_get_pauseparam,
4003 .set_pauseparam = nv_set_pauseparam,
4004 .get_rx_csum = nv_get_rx_csum,
4005 .set_rx_csum = nv_set_rx_csum,
4006 .get_tx_csum = ethtool_op_get_tx_csum,
4007 .set_tx_csum = nv_set_tx_csum,
4008 .get_sg = ethtool_op_get_sg,
4009 .set_sg = nv_set_sg,
4010 .get_strings = nv_get_strings,
4011 .get_stats_count = nv_get_stats_count,
4012 .get_ethtool_stats = nv_get_ethtool_stats,
4013 .self_test_count = nv_self_test_count,
4014 .self_test = nv_self_test,
4017 static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
4019 struct fe_priv *np = get_nvpriv(dev);
4021 spin_lock_irq(&np->lock);
4023 /* save vlan group */
4027 /* enable vlan on MAC */
4028 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS;
4030 /* disable vlan on MAC */
4031 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4032 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4035 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4037 spin_unlock_irq(&np->lock);
4040 static void nv_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
4045 /* The mgmt unit and driver use a semaphore to access the phy during init */
4046 static int nv_mgmt_acquire_sema(struct net_device *dev)
4048 u8 __iomem *base = get_hwbase(dev);
4050 u32 tx_ctrl, mgmt_sema;
4052 for (i = 0; i < 10; i++) {
4053 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
4054 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
4059 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
4062 for (i = 0; i < 2; i++) {
4063 tx_ctrl = readl(base + NvRegTransmitterControl);
4064 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
4065 writel(tx_ctrl, base + NvRegTransmitterControl);
4067 /* verify that semaphore was acquired */
4068 tx_ctrl = readl(base + NvRegTransmitterControl);
4069 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
4070 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE))
4079 /* Indicate to mgmt unit whether driver is loaded or not */
4080 static void nv_mgmt_driver_loaded(struct net_device *dev, int loaded)
4082 u8 __iomem *base = get_hwbase(dev);
4085 tx_ctrl = readl(base + NvRegTransmitterControl);
4087 tx_ctrl |= NVREG_XMITCTL_HOST_LOADED;
4089 tx_ctrl &= ~NVREG_XMITCTL_HOST_LOADED;
4090 writel(tx_ctrl, base + NvRegTransmitterControl);
4093 static int nv_open(struct net_device *dev)
4095 struct fe_priv *np = netdev_priv(dev);
4096 u8 __iomem *base = get_hwbase(dev);
4100 dprintk(KERN_DEBUG "nv_open: begin\n");
4102 /* erase previous misconfiguration */
4103 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4105 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4106 writel(0, base + NvRegMulticastAddrB);
4107 writel(0, base + NvRegMulticastMaskA);
4108 writel(0, base + NvRegMulticastMaskB);
4109 writel(0, base + NvRegPacketFilterFlags);
4111 writel(0, base + NvRegTransmitterControl);
4112 writel(0, base + NvRegReceiverControl);
4114 writel(0, base + NvRegAdapterControl);
4116 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
4117 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
4119 /* initialize descriptor rings */
4121 oom = nv_init_ring(dev);
4123 writel(0, base + NvRegLinkSpeed);
4124 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
4126 writel(0, base + NvRegUnknownSetupReg6);
4128 np->in_shutdown = 0;
4131 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4132 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4133 base + NvRegRingSizes);
4135 writel(np->linkspeed, base + NvRegLinkSpeed);
4136 if (np->desc_ver == DESC_VER_1)
4137 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
4139 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
4140 writel(np->txrxctl_bits, base + NvRegTxRxControl);
4141 writel(np->vlanctl_bits, base + NvRegVlanControl);
4143 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
4144 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
4145 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
4146 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
4148 writel(0, base + NvRegMIIMask);
4149 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4150 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
4152 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
4153 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
4154 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
4155 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4157 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
4158 get_random_bytes(&i, sizeof(i));
4159 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed);
4160 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
4161 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
4162 if (poll_interval == -1) {
4163 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
4164 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
4166 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4169 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
4170 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4171 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
4172 base + NvRegAdapterControl);
4173 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
4174 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
4176 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
4178 i = readl(base + NvRegPowerState);
4179 if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0)
4180 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
4184 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
4186 nv_disable_hw_interrupts(dev, np->irqmask);
4188 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
4189 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4192 if (nv_request_irq(dev, 0)) {
4196 /* ask for interrupts */
4197 nv_enable_hw_interrupts(dev, np->irqmask);
4199 spin_lock_irq(&np->lock);
4200 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4201 writel(0, base + NvRegMulticastAddrB);
4202 writel(0, base + NvRegMulticastMaskA);
4203 writel(0, base + NvRegMulticastMaskB);
4204 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
4205 /* One manual link speed update: Interrupts are enabled, future link
4206 * speed changes cause interrupts and are handled by nv_link_irq().
4210 miistat = readl(base + NvRegMIIStatus);
4211 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
4212 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
4214 /* set linkspeed to invalid value, thus force nv_update_linkspeed
4217 ret = nv_update_linkspeed(dev);
4220 netif_start_queue(dev);
4221 netif_poll_enable(dev);
4224 netif_carrier_on(dev);
4226 printk("%s: no link during initialization.\n", dev->name);
4227 netif_carrier_off(dev);
4230 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4232 /* start statistics timer */
4233 if (np->driver_data & DEV_HAS_STATISTICS)
4234 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
4236 spin_unlock_irq(&np->lock);
4244 static int nv_close(struct net_device *dev)
4246 struct fe_priv *np = netdev_priv(dev);
4249 spin_lock_irq(&np->lock);
4250 np->in_shutdown = 1;
4251 spin_unlock_irq(&np->lock);
4252 netif_poll_disable(dev);
4253 synchronize_irq(dev->irq);
4255 del_timer_sync(&np->oom_kick);
4256 del_timer_sync(&np->nic_poll);
4257 del_timer_sync(&np->stats_poll);
4259 netif_stop_queue(dev);
4260 spin_lock_irq(&np->lock);
4265 /* disable interrupts on the nic or we will lock up */
4266 base = get_hwbase(dev);
4267 nv_disable_hw_interrupts(dev, np->irqmask);
4269 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
4271 spin_unlock_irq(&np->lock);
4280 /* FIXME: power down nic */
4285 static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
4287 struct net_device *dev;
4292 u32 powerstate, txreg;
4293 u32 phystate_orig = 0, phystate;
4294 int phyinitialized = 0;
4296 dev = alloc_etherdev(sizeof(struct fe_priv));
4301 np = netdev_priv(dev);
4302 np->pci_dev = pci_dev;
4303 spin_lock_init(&np->lock);
4304 SET_MODULE_OWNER(dev);
4305 SET_NETDEV_DEV(dev, &pci_dev->dev);
4307 init_timer(&np->oom_kick);
4308 np->oom_kick.data = (unsigned long) dev;
4309 np->oom_kick.function = &nv_do_rx_refill; /* timer handler */
4310 init_timer(&np->nic_poll);
4311 np->nic_poll.data = (unsigned long) dev;
4312 np->nic_poll.function = &nv_do_nic_poll; /* timer handler */
4313 init_timer(&np->stats_poll);
4314 np->stats_poll.data = (unsigned long) dev;
4315 np->stats_poll.function = &nv_do_stats_poll; /* timer handler */
4317 err = pci_enable_device(pci_dev);
4319 printk(KERN_INFO "forcedeth: pci_enable_dev failed (%d) for device %s\n",
4320 err, pci_name(pci_dev));
4324 pci_set_master(pci_dev);
4326 err = pci_request_regions(pci_dev, DRV_NAME);
4330 if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS))
4331 np->register_size = NV_PCI_REGSZ_VER2;
4333 np->register_size = NV_PCI_REGSZ_VER1;
4337 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
4338 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
4339 pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i),
4340 pci_resource_len(pci_dev, i),
4341 pci_resource_flags(pci_dev, i));
4342 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
4343 pci_resource_len(pci_dev, i) >= np->register_size) {
4344 addr = pci_resource_start(pci_dev, i);
4348 if (i == DEVICE_COUNT_RESOURCE) {
4349 printk(KERN_INFO "forcedeth: Couldn't find register window for device %s.\n",
4354 /* copy of driver data */
4355 np->driver_data = id->driver_data;
4357 /* handle different descriptor versions */
4358 if (id->driver_data & DEV_HAS_HIGH_DMA) {
4359 /* packet format 3: supports 40-bit addressing */
4360 np->desc_ver = DESC_VER_3;
4361 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
4363 if (pci_set_dma_mask(pci_dev, DMA_39BIT_MASK)) {
4364 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n",
4367 dev->features |= NETIF_F_HIGHDMA;
4368 printk(KERN_INFO "forcedeth: using HIGHDMA\n");
4370 if (pci_set_consistent_dma_mask(pci_dev, DMA_39BIT_MASK)) {
4371 printk(KERN_INFO "forcedeth: 64-bit DMA (consistent) failed, using 32-bit ring buffers for device %s.\n",
4375 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
4376 /* packet format 2: supports jumbo frames */
4377 np->desc_ver = DESC_VER_2;
4378 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
4380 /* original packet format */
4381 np->desc_ver = DESC_VER_1;
4382 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
4385 np->pkt_limit = NV_PKTLIMIT_1;
4386 if (id->driver_data & DEV_HAS_LARGEDESC)
4387 np->pkt_limit = NV_PKTLIMIT_2;
4389 if (id->driver_data & DEV_HAS_CHECKSUM) {
4391 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
4392 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
4394 dev->features |= NETIF_F_TSO;
4398 np->vlanctl_bits = 0;
4399 if (id->driver_data & DEV_HAS_VLAN) {
4400 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
4401 dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
4402 dev->vlan_rx_register = nv_vlan_rx_register;
4403 dev->vlan_rx_kill_vid = nv_vlan_rx_kill_vid;
4407 if ((id->driver_data & DEV_HAS_MSI) && msi) {
4408 np->msi_flags |= NV_MSI_CAPABLE;
4410 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
4411 np->msi_flags |= NV_MSI_X_CAPABLE;
4414 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
4415 if (id->driver_data & DEV_HAS_PAUSEFRAME_TX) {
4416 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
4421 np->base = ioremap(addr, np->register_size);
4424 dev->base_addr = (unsigned long)np->base;
4426 dev->irq = pci_dev->irq;
4428 np->rx_ring_size = RX_RING_DEFAULT;
4429 np->tx_ring_size = TX_RING_DEFAULT;
4430 np->tx_limit_stop = np->tx_ring_size - TX_LIMIT_DIFFERENCE;
4431 np->tx_limit_start = np->tx_ring_size - TX_LIMIT_DIFFERENCE - 1;
4433 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
4434 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
4435 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
4437 if (!np->rx_ring.orig)
4439 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4441 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
4442 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
4444 if (!np->rx_ring.ex)
4446 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4448 np->rx_skbuff = kmalloc(sizeof(struct sk_buff*) * np->rx_ring_size, GFP_KERNEL);
4449 np->rx_dma = kmalloc(sizeof(dma_addr_t) * np->rx_ring_size, GFP_KERNEL);
4450 np->tx_skbuff = kmalloc(sizeof(struct sk_buff*) * np->tx_ring_size, GFP_KERNEL);
4451 np->tx_dma = kmalloc(sizeof(dma_addr_t) * np->tx_ring_size, GFP_KERNEL);
4452 np->tx_dma_len = kmalloc(sizeof(unsigned int) * np->tx_ring_size, GFP_KERNEL);
4453 if (!np->rx_skbuff || !np->rx_dma || !np->tx_skbuff || !np->tx_dma || !np->tx_dma_len)
4455 memset(np->rx_skbuff, 0, sizeof(struct sk_buff*) * np->rx_ring_size);
4456 memset(np->rx_dma, 0, sizeof(dma_addr_t) * np->rx_ring_size);
4457 memset(np->tx_skbuff, 0, sizeof(struct sk_buff*) * np->tx_ring_size);
4458 memset(np->tx_dma, 0, sizeof(dma_addr_t) * np->tx_ring_size);
4459 memset(np->tx_dma_len, 0, sizeof(unsigned int) * np->tx_ring_size);
4461 dev->open = nv_open;
4462 dev->stop = nv_close;
4463 dev->hard_start_xmit = nv_start_xmit;
4464 dev->get_stats = nv_get_stats;
4465 dev->change_mtu = nv_change_mtu;
4466 dev->set_mac_address = nv_set_mac_address;
4467 dev->set_multicast_list = nv_set_multicast;
4468 #ifdef CONFIG_NET_POLL_CONTROLLER
4469 dev->poll_controller = nv_poll_controller;
4472 #ifdef CONFIG_FORCEDETH_NAPI
4473 dev->poll = nv_napi_poll;
4475 SET_ETHTOOL_OPS(dev, &ops);
4476 dev->tx_timeout = nv_tx_timeout;
4477 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
4479 pci_set_drvdata(pci_dev, dev);
4481 /* read the mac address */
4482 base = get_hwbase(dev);
4483 np->orig_mac[0] = readl(base + NvRegMacAddrA);
4484 np->orig_mac[1] = readl(base + NvRegMacAddrB);
4486 /* check the workaround bit for correct mac address order */
4487 txreg = readl(base + NvRegTransmitPoll);
4488 if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
4489 /* mac address is already in correct order */
4490 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
4491 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
4492 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
4493 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
4494 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
4495 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
4497 /* need to reverse mac address to correct order */
4498 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
4499 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
4500 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
4501 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
4502 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
4503 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
4504 /* set permanent address to be correct aswell */
4505 np->orig_mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
4506 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
4507 np->orig_mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
4508 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
4510 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4512 if (!is_valid_ether_addr(dev->perm_addr)) {
4514 * Bad mac address. At least one bios sets the mac address
4515 * to 01:23:45:67:89:ab
4517 printk(KERN_ERR "%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n",
4519 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
4520 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
4521 printk(KERN_ERR "Please complain to your hardware vendor. Switching to a random MAC.\n");
4522 dev->dev_addr[0] = 0x00;
4523 dev->dev_addr[1] = 0x00;
4524 dev->dev_addr[2] = 0x6c;
4525 get_random_bytes(&dev->dev_addr[3], 3);
4528 dprintk(KERN_DEBUG "%s: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", pci_name(pci_dev),
4529 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
4530 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
4532 /* set mac address */
4533 nv_copy_mac_to_hw(dev);
4536 writel(0, base + NvRegWakeUpFlags);
4539 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
4541 pci_read_config_byte(pci_dev, PCI_REVISION_ID, &revision_id);
4543 /* take phy and nic out of low power mode */
4544 powerstate = readl(base + NvRegPowerState2);
4545 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
4546 if ((id->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 ||
4547 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_13) &&
4548 revision_id >= 0xA3)
4549 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
4550 writel(powerstate, base + NvRegPowerState2);
4553 if (np->desc_ver == DESC_VER_1) {
4554 np->tx_flags = NV_TX_VALID;
4556 np->tx_flags = NV_TX2_VALID;
4558 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) {
4559 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
4560 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
4561 np->msi_flags |= 0x0003;
4563 np->irqmask = NVREG_IRQMASK_CPU;
4564 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
4565 np->msi_flags |= 0x0001;
4568 if (id->driver_data & DEV_NEED_TIMERIRQ)
4569 np->irqmask |= NVREG_IRQ_TIMER;
4570 if (id->driver_data & DEV_NEED_LINKTIMER) {
4571 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
4572 np->need_linktimer = 1;
4573 np->link_timeout = jiffies + LINK_TIMEOUT;
4575 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
4576 np->need_linktimer = 0;
4579 /* clear phy state and temporarily halt phy interrupts */
4580 writel(0, base + NvRegMIIMask);
4581 phystate = readl(base + NvRegAdapterControl);
4582 if (phystate & NVREG_ADAPTCTL_RUNNING) {
4584 phystate &= ~NVREG_ADAPTCTL_RUNNING;
4585 writel(phystate, base + NvRegAdapterControl);
4587 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
4589 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
4590 writel(0x1, base + 0x204); pci_push(base);
4592 /* management unit running on the mac? */
4593 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST;
4594 if (np->mac_in_use) {
4596 /* management unit setup the phy already? */
4597 mgmt_sync = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK;
4598 if (mgmt_sync == NVREG_XMITCTL_SYNC_NOT_READY) {
4599 if (!nv_mgmt_acquire_sema(dev)) {
4600 for (i = 0; i < 5000; i++) {
4602 mgmt_sync = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK;
4603 if (mgmt_sync == NVREG_XMITCTL_SYNC_NOT_READY)
4605 if (mgmt_sync == NVREG_XMITCTL_SYNC_PHY_INIT)
4610 /* we need to init the phy */
4612 } else if (mgmt_sync == NVREG_XMITCTL_SYNC_PHY_INIT) {
4613 /* phy is inited by SMU */
4616 /* we need to init the phy */
4621 /* find a suitable phy */
4622 for (i = 1; i <= 32; i++) {
4624 int phyaddr = i & 0x1F;
4626 spin_lock_irq(&np->lock);
4627 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
4628 spin_unlock_irq(&np->lock);
4629 if (id1 < 0 || id1 == 0xffff)
4631 spin_lock_irq(&np->lock);
4632 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
4633 spin_unlock_irq(&np->lock);
4634 if (id2 < 0 || id2 == 0xffff)
4637 np->phy_model = id2 & PHYID2_MODEL_MASK;
4638 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
4639 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
4640 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
4641 pci_name(pci_dev), id1, id2, phyaddr);
4642 np->phyaddr = phyaddr;
4643 np->phy_oui = id1 | id2;
4647 printk(KERN_INFO "%s: open: Could not find a valid PHY.\n",
4652 if (!phyinitialized) {
4657 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
4658 nv_mgmt_driver_loaded(dev, 1);
4661 /* set default link speed settings */
4662 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
4666 err = register_netdev(dev);
4668 printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
4671 printk(KERN_INFO "%s: forcedeth.c: subsystem: %05x:%04x bound to %s\n",
4672 dev->name, pci_dev->subsystem_vendor, pci_dev->subsystem_device,
4679 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
4681 nv_mgmt_driver_loaded(dev, 0);
4682 pci_set_drvdata(pci_dev, NULL);
4686 iounmap(get_hwbase(dev));
4688 pci_release_regions(pci_dev);
4690 pci_disable_device(pci_dev);
4697 static void __devexit nv_remove(struct pci_dev *pci_dev)
4699 struct net_device *dev = pci_get_drvdata(pci_dev);
4700 struct fe_priv *np = netdev_priv(dev);
4701 u8 __iomem *base = get_hwbase(dev);
4703 unregister_netdev(dev);
4705 /* special op: write back the misordered MAC address - otherwise
4706 * the next nv_probe would see a wrong address.
4708 writel(np->orig_mac[0], base + NvRegMacAddrA);
4709 writel(np->orig_mac[1], base + NvRegMacAddrB);
4712 nv_mgmt_driver_loaded(dev, 0);
4714 /* free all structures */
4716 iounmap(get_hwbase(dev));
4717 pci_release_regions(pci_dev);
4718 pci_disable_device(pci_dev);
4720 pci_set_drvdata(pci_dev, NULL);
4724 static int nv_suspend(struct pci_dev *pdev, pm_message_t state)
4726 struct net_device *dev = pci_get_drvdata(pdev);
4727 struct fe_priv *np = netdev_priv(dev);
4729 if (!netif_running(dev))
4732 netif_device_detach(dev);
4737 pci_save_state(pdev);
4738 pci_enable_wake(pdev, pci_choose_state(pdev, state), np->wolenabled);
4739 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4744 static int nv_resume(struct pci_dev *pdev)
4746 struct net_device *dev = pci_get_drvdata(pdev);
4749 if (!netif_running(dev))
4752 netif_device_attach(dev);
4754 pci_set_power_state(pdev, PCI_D0);
4755 pci_restore_state(pdev);
4756 pci_enable_wake(pdev, PCI_D0, 0);
4763 #define nv_suspend NULL
4764 #define nv_resume NULL
4765 #endif /* CONFIG_PM */
4767 static struct pci_device_id pci_tbl[] = {
4768 { /* nForce Ethernet Controller */
4769 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1),
4770 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
4772 { /* nForce2 Ethernet Controller */
4773 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2),
4774 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
4776 { /* nForce3 Ethernet Controller */
4777 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3),
4778 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
4780 { /* nForce3 Ethernet Controller */
4781 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4),
4782 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
4784 { /* nForce3 Ethernet Controller */
4785 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5),
4786 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
4788 { /* nForce3 Ethernet Controller */
4789 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6),
4790 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
4792 { /* nForce3 Ethernet Controller */
4793 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7),
4794 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
4796 { /* CK804 Ethernet Controller */
4797 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
4798 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
4800 { /* CK804 Ethernet Controller */
4801 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
4802 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
4804 { /* MCP04 Ethernet Controller */
4805 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
4806 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
4808 { /* MCP04 Ethernet Controller */
4809 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
4810 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
4812 { /* MCP51 Ethernet Controller */
4813 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
4814 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
4816 { /* MCP51 Ethernet Controller */
4817 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13),
4818 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
4820 { /* MCP55 Ethernet Controller */
4821 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
4822 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4824 { /* MCP55 Ethernet Controller */
4825 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
4826 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4828 { /* MCP61 Ethernet Controller */
4829 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_16),
4830 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4832 { /* MCP61 Ethernet Controller */
4833 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_17),
4834 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4836 { /* MCP61 Ethernet Controller */
4837 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_18),
4838 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4840 { /* MCP61 Ethernet Controller */
4841 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_19),
4842 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4844 { /* MCP65 Ethernet Controller */
4845 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20),
4846 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4848 { /* MCP65 Ethernet Controller */
4849 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21),
4850 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4852 { /* MCP65 Ethernet Controller */
4853 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22),
4854 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4856 { /* MCP65 Ethernet Controller */
4857 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23),
4858 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
4863 static struct pci_driver driver = {
4864 .name = "forcedeth",
4865 .id_table = pci_tbl,
4867 .remove = __devexit_p(nv_remove),
4868 .suspend = nv_suspend,
4869 .resume = nv_resume,
4872 static int __init init_nic(void)
4874 printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION);
4875 return pci_register_driver(&driver);
4878 static void __exit exit_nic(void)
4880 pci_unregister_driver(&driver);
4883 module_param(max_interrupt_work, int, 0);
4884 MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
4885 module_param(optimization_mode, int, 0);
4886 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.");
4887 module_param(poll_interval, int, 0);
4888 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.");
4889 module_param(msi, int, 0);
4890 MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
4891 module_param(msix, int, 0);
4892 MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
4893 module_param(dma_64bit, int, 0);
4894 MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
4896 MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
4897 MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
4898 MODULE_LICENSE("GPL");
4900 MODULE_DEVICE_TABLE(pci, pci_tbl);
4902 module_init(init_nic);
4903 module_exit(exit_nic);