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 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.
87 * We suspect that on some hardware no TX done interrupts are generated.
88 * This means recovery from netif_stop_queue only happens if the hw timer
89 * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
90 * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
91 * If your hardware reliably generates tx done interrupts, then you can remove
92 * DEV_NEED_TIMERIRQ from the driver_data flags.
93 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
94 * superfluous timer interrupts from the nic.
96 #define FORCEDETH_VERSION "0.32"
97 #define DRV_NAME "forcedeth"
99 #include <linux/module.h>
100 #include <linux/types.h>
101 #include <linux/pci.h>
102 #include <linux/interrupt.h>
103 #include <linux/netdevice.h>
104 #include <linux/etherdevice.h>
105 #include <linux/delay.h>
106 #include <linux/spinlock.h>
107 #include <linux/ethtool.h>
108 #include <linux/timer.h>
109 #include <linux/skbuff.h>
110 #include <linux/mii.h>
111 #include <linux/random.h>
112 #include <linux/init.h>
113 #include <linux/if_vlan.h>
117 #include <asm/uaccess.h>
118 #include <asm/system.h>
121 #define dprintk printk
123 #define dprintk(x...) do { } while (0)
131 #define DEV_NEED_LASTPACKET1 0x0001 /* set LASTPACKET1 in tx flags */
132 #define DEV_IRQMASK_1 0x0002 /* use NVREG_IRQMASK_WANTED_1 for irq mask */
133 #define DEV_IRQMASK_2 0x0004 /* use NVREG_IRQMASK_WANTED_2 for irq mask */
134 #define DEV_NEED_TIMERIRQ 0x0008 /* set the timer irq flag in the irq mask */
135 #define DEV_NEED_LINKTIMER 0x0010 /* poll link settings. Relies on the timer irq */
138 NvRegIrqStatus
= 0x000,
139 #define NVREG_IRQSTAT_MIIEVENT 0x040
140 #define NVREG_IRQSTAT_MASK 0x1ff
141 NvRegIrqMask
= 0x004,
142 #define NVREG_IRQ_RX_ERROR 0x0001
143 #define NVREG_IRQ_RX 0x0002
144 #define NVREG_IRQ_RX_NOBUF 0x0004
145 #define NVREG_IRQ_TX_ERR 0x0008
146 #define NVREG_IRQ_TX2 0x0010
147 #define NVREG_IRQ_TIMER 0x0020
148 #define NVREG_IRQ_LINK 0x0040
149 #define NVREG_IRQ_TX1 0x0100
150 #define NVREG_IRQMASK_WANTED_1 0x005f
151 #define NVREG_IRQMASK_WANTED_2 0x0147
152 #define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR|NVREG_IRQ_TX2|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_TX1))
154 NvRegUnknownSetupReg6
= 0x008,
155 #define NVREG_UNKSETUP6_VAL 3
158 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
159 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
161 NvRegPollingInterval
= 0x00c,
162 #define NVREG_POLL_DEFAULT 970
164 #define NVREG_MISC1_HD 0x02
165 #define NVREG_MISC1_FORCE 0x3b0f3c
167 NvRegTransmitterControl
= 0x084,
168 #define NVREG_XMITCTL_START 0x01
169 NvRegTransmitterStatus
= 0x088,
170 #define NVREG_XMITSTAT_BUSY 0x01
172 NvRegPacketFilterFlags
= 0x8c,
173 #define NVREG_PFF_ALWAYS 0x7F0008
174 #define NVREG_PFF_PROMISC 0x80
175 #define NVREG_PFF_MYADDR 0x20
177 NvRegOffloadConfig
= 0x90,
178 #define NVREG_OFFLOAD_HOMEPHY 0x601
179 #define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
180 NvRegReceiverControl
= 0x094,
181 #define NVREG_RCVCTL_START 0x01
182 NvRegReceiverStatus
= 0x98,
183 #define NVREG_RCVSTAT_BUSY 0x01
185 NvRegRandomSeed
= 0x9c,
186 #define NVREG_RNDSEED_MASK 0x00ff
187 #define NVREG_RNDSEED_FORCE 0x7f00
188 #define NVREG_RNDSEED_FORCE2 0x2d00
189 #define NVREG_RNDSEED_FORCE3 0x7400
191 NvRegUnknownSetupReg1
= 0xA0,
192 #define NVREG_UNKSETUP1_VAL 0x16070f
193 NvRegUnknownSetupReg2
= 0xA4,
194 #define NVREG_UNKSETUP2_VAL 0x16
195 NvRegMacAddrA
= 0xA8,
196 NvRegMacAddrB
= 0xAC,
197 NvRegMulticastAddrA
= 0xB0,
198 #define NVREG_MCASTADDRA_FORCE 0x01
199 NvRegMulticastAddrB
= 0xB4,
200 NvRegMulticastMaskA
= 0xB8,
201 NvRegMulticastMaskB
= 0xBC,
203 NvRegPhyInterface
= 0xC0,
204 #define PHY_RGMII 0x10000000
206 NvRegTxRingPhysAddr
= 0x100,
207 NvRegRxRingPhysAddr
= 0x104,
208 NvRegRingSizes
= 0x108,
209 #define NVREG_RINGSZ_TXSHIFT 0
210 #define NVREG_RINGSZ_RXSHIFT 16
211 NvRegUnknownTransmitterReg
= 0x10c,
212 NvRegLinkSpeed
= 0x110,
213 #define NVREG_LINKSPEED_FORCE 0x10000
214 #define NVREG_LINKSPEED_10 1000
215 #define NVREG_LINKSPEED_100 100
216 #define NVREG_LINKSPEED_1000 50
217 #define NVREG_LINKSPEED_MASK (0xFFF)
218 NvRegUnknownSetupReg5
= 0x130,
219 #define NVREG_UNKSETUP5_BIT31 (1<<31)
220 NvRegUnknownSetupReg3
= 0x13c,
221 #define NVREG_UNKSETUP3_VAL1 0x200010
222 NvRegTxRxControl
= 0x144,
223 #define NVREG_TXRXCTL_KICK 0x0001
224 #define NVREG_TXRXCTL_BIT1 0x0002
225 #define NVREG_TXRXCTL_BIT2 0x0004
226 #define NVREG_TXRXCTL_IDLE 0x0008
227 #define NVREG_TXRXCTL_RESET 0x0010
228 #define NVREG_TXRXCTL_RXCHECK 0x0400
229 NvRegMIIStatus
= 0x180,
230 #define NVREG_MIISTAT_ERROR 0x0001
231 #define NVREG_MIISTAT_LINKCHANGE 0x0008
232 #define NVREG_MIISTAT_MASK 0x000f
233 #define NVREG_MIISTAT_MASK2 0x000f
234 NvRegUnknownSetupReg4
= 0x184,
235 #define NVREG_UNKSETUP4_VAL 8
237 NvRegAdapterControl
= 0x188,
238 #define NVREG_ADAPTCTL_START 0x02
239 #define NVREG_ADAPTCTL_LINKUP 0x04
240 #define NVREG_ADAPTCTL_PHYVALID 0x40000
241 #define NVREG_ADAPTCTL_RUNNING 0x100000
242 #define NVREG_ADAPTCTL_PHYSHIFT 24
243 NvRegMIISpeed
= 0x18c,
244 #define NVREG_MIISPEED_BIT8 (1<<8)
245 #define NVREG_MIIDELAY 5
246 NvRegMIIControl
= 0x190,
247 #define NVREG_MIICTL_INUSE 0x08000
248 #define NVREG_MIICTL_WRITE 0x00400
249 #define NVREG_MIICTL_ADDRSHIFT 5
250 NvRegMIIData
= 0x194,
251 NvRegWakeUpFlags
= 0x200,
252 #define NVREG_WAKEUPFLAGS_VAL 0x7770
253 #define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
254 #define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
255 #define NVREG_WAKEUPFLAGS_D3SHIFT 12
256 #define NVREG_WAKEUPFLAGS_D2SHIFT 8
257 #define NVREG_WAKEUPFLAGS_D1SHIFT 4
258 #define NVREG_WAKEUPFLAGS_D0SHIFT 0
259 #define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
260 #define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
261 #define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
262 #define NVREG_WAKEUPFLAGS_ENABLE 0x1111
264 NvRegPatternCRC
= 0x204,
265 NvRegPatternMask
= 0x208,
266 NvRegPowerCap
= 0x268,
267 #define NVREG_POWERCAP_D3SUPP (1<<30)
268 #define NVREG_POWERCAP_D2SUPP (1<<26)
269 #define NVREG_POWERCAP_D1SUPP (1<<25)
270 NvRegPowerState
= 0x26c,
271 #define NVREG_POWERSTATE_POWEREDUP 0x8000
272 #define NVREG_POWERSTATE_VALID 0x0100
273 #define NVREG_POWERSTATE_MASK 0x0003
274 #define NVREG_POWERSTATE_D0 0x0000
275 #define NVREG_POWERSTATE_D1 0x0001
276 #define NVREG_POWERSTATE_D2 0x0002
277 #define NVREG_POWERSTATE_D3 0x0003
280 /* Big endian: should work, but is untested */
286 #define FLAG_MASK_V1 0xffff0000
287 #define FLAG_MASK_V2 0xffffc000
288 #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
289 #define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
291 #define NV_TX_LASTPACKET (1<<16)
292 #define NV_TX_RETRYERROR (1<<19)
293 #define NV_TX_LASTPACKET1 (1<<24)
294 #define NV_TX_DEFERRED (1<<26)
295 #define NV_TX_CARRIERLOST (1<<27)
296 #define NV_TX_LATECOLLISION (1<<28)
297 #define NV_TX_UNDERFLOW (1<<29)
298 #define NV_TX_ERROR (1<<30)
299 #define NV_TX_VALID (1<<31)
301 #define NV_TX2_LASTPACKET (1<<29)
302 #define NV_TX2_RETRYERROR (1<<18)
303 #define NV_TX2_LASTPACKET1 (1<<23)
304 #define NV_TX2_DEFERRED (1<<25)
305 #define NV_TX2_CARRIERLOST (1<<26)
306 #define NV_TX2_LATECOLLISION (1<<27)
307 #define NV_TX2_UNDERFLOW (1<<28)
308 /* error and valid are the same for both */
309 #define NV_TX2_ERROR (1<<30)
310 #define NV_TX2_VALID (1<<31)
312 #define NV_RX_DESCRIPTORVALID (1<<16)
313 #define NV_RX_MISSEDFRAME (1<<17)
314 #define NV_RX_SUBSTRACT1 (1<<18)
315 #define NV_RX_ERROR1 (1<<23)
316 #define NV_RX_ERROR2 (1<<24)
317 #define NV_RX_ERROR3 (1<<25)
318 #define NV_RX_ERROR4 (1<<26)
319 #define NV_RX_CRCERR (1<<27)
320 #define NV_RX_OVERFLOW (1<<28)
321 #define NV_RX_FRAMINGERR (1<<29)
322 #define NV_RX_ERROR (1<<30)
323 #define NV_RX_AVAIL (1<<31)
325 #define NV_RX2_CHECKSUMMASK (0x1C000000)
326 #define NV_RX2_CHECKSUMOK1 (0x10000000)
327 #define NV_RX2_CHECKSUMOK2 (0x14000000)
328 #define NV_RX2_CHECKSUMOK3 (0x18000000)
329 #define NV_RX2_DESCRIPTORVALID (1<<29)
330 #define NV_RX2_SUBSTRACT1 (1<<25)
331 #define NV_RX2_ERROR1 (1<<18)
332 #define NV_RX2_ERROR2 (1<<19)
333 #define NV_RX2_ERROR3 (1<<20)
334 #define NV_RX2_ERROR4 (1<<21)
335 #define NV_RX2_CRCERR (1<<22)
336 #define NV_RX2_OVERFLOW (1<<23)
337 #define NV_RX2_FRAMINGERR (1<<24)
338 /* error and avail are the same for both */
339 #define NV_RX2_ERROR (1<<30)
340 #define NV_RX2_AVAIL (1<<31)
342 /* Miscelaneous hardware related defines: */
343 #define NV_PCI_REGSZ 0x270
345 /* various timeout delays: all in usec */
346 #define NV_TXRX_RESET_DELAY 4
347 #define NV_TXSTOP_DELAY1 10
348 #define NV_TXSTOP_DELAY1MAX 500000
349 #define NV_TXSTOP_DELAY2 100
350 #define NV_RXSTOP_DELAY1 10
351 #define NV_RXSTOP_DELAY1MAX 500000
352 #define NV_RXSTOP_DELAY2 100
353 #define NV_SETUP5_DELAY 5
354 #define NV_SETUP5_DELAYMAX 50000
355 #define NV_POWERUP_DELAY 5
356 #define NV_POWERUP_DELAYMAX 5000
357 #define NV_MIIBUSY_DELAY 50
358 #define NV_MIIPHY_DELAY 10
359 #define NV_MIIPHY_DELAYMAX 10000
361 #define NV_WAKEUPPATTERNS 5
362 #define NV_WAKEUPMASKENTRIES 4
364 /* General driver defaults */
365 #define NV_WATCHDOG_TIMEO (5*HZ)
370 * If your nic mysteriously hangs then try to reduce the limits
371 * to 1/0: It might be required to set NV_TX_LASTPACKET in the
372 * last valid ring entry. But this would be impossible to
373 * implement - probably a disassembly error.
375 #define TX_LIMIT_STOP 63
376 #define TX_LIMIT_START 62
378 /* rx/tx mac addr + type + vlan + align + slack*/
379 #define RX_NIC_BUFSIZE (ETH_DATA_LEN + 64)
380 /* even more slack */
381 #define RX_ALLOC_BUFSIZE (ETH_DATA_LEN + 128)
383 #define OOM_REFILL (1+HZ/20)
384 #define POLL_WAIT (1+HZ/100)
385 #define LINK_TIMEOUT (3*HZ)
389 * This field has two purposes:
390 * - Newer nics uses a different ring layout. The layout is selected by
391 * comparing np->desc_ver with DESC_VER_xy.
392 * - It contains bits that are forced on when writing to NvRegTxRxControl.
394 #define DESC_VER_1 0x0
395 #define DESC_VER_2 (0x02100|NVREG_TXRXCTL_RXCHECK)
398 #define PHY_OUI_MARVELL 0x5043
399 #define PHY_OUI_CICADA 0x03f1
400 #define PHYID1_OUI_MASK 0x03ff
401 #define PHYID1_OUI_SHFT 6
402 #define PHYID2_OUI_MASK 0xfc00
403 #define PHYID2_OUI_SHFT 10
404 #define PHY_INIT1 0x0f000
405 #define PHY_INIT2 0x0e00
406 #define PHY_INIT3 0x01000
407 #define PHY_INIT4 0x0200
408 #define PHY_INIT5 0x0004
409 #define PHY_INIT6 0x02000
410 #define PHY_GIGABIT 0x0100
412 #define PHY_TIMEOUT 0x1
413 #define PHY_ERROR 0x2
417 #define PHY_HALF 0x100
419 /* FIXME: MII defines that should be added to <linux/mii.h> */
420 #define MII_1000BT_CR 0x09
421 #define MII_1000BT_SR 0x0a
422 #define ADVERTISE_1000FULL 0x0200
423 #define ADVERTISE_1000HALF 0x0100
424 #define LPA_1000FULL 0x0800
425 #define LPA_1000HALF 0x0400
430 * All hardware access under dev->priv->lock, except the performance
432 * - rx is (pseudo-) lockless: it relies on the single-threading provided
433 * by the arch code for interrupts.
434 * - tx setup is lockless: it relies on dev->xmit_lock. Actual submission
435 * needs dev->priv->lock :-(
436 * - set_multicast_list: preparation lockless, relies on dev->xmit_lock.
439 /* in dev: base, irq */
444 * Locking: spin_lock(&np->lock); */
445 struct net_device_stats stats
;
453 unsigned int phy_oui
;
456 /* General data: RO fields */
457 dma_addr_t ring_addr
;
458 struct pci_dev
*pci_dev
;
465 /* rx specific fields.
466 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
468 struct ring_desc
*rx_ring
;
469 unsigned int cur_rx
, refill_rx
;
470 struct sk_buff
*rx_skbuff
[RX_RING
];
471 dma_addr_t rx_dma
[RX_RING
];
472 unsigned int rx_buf_sz
;
473 struct timer_list oom_kick
;
474 struct timer_list nic_poll
;
476 /* media detection workaround.
477 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
480 unsigned long link_timeout
;
482 * tx specific fields.
484 struct ring_desc
*tx_ring
;
485 unsigned int next_tx
, nic_tx
;
486 struct sk_buff
*tx_skbuff
[TX_RING
];
487 dma_addr_t tx_dma
[TX_RING
];
492 * Maximum number of loops until we assume that a bit in the irq mask
493 * is stuck. Overridable with module param.
495 static int max_interrupt_work
= 5;
497 static inline struct fe_priv
*get_nvpriv(struct net_device
*dev
)
499 return netdev_priv(dev
);
502 static inline u8 __iomem
*get_hwbase(struct net_device
*dev
)
504 return get_nvpriv(dev
)->base
;
507 static inline void pci_push(u8 __iomem
*base
)
509 /* force out pending posted writes */
513 static inline u32
nv_descr_getlength(struct ring_desc
*prd
, u32 v
)
515 return le32_to_cpu(prd
->FlagLen
)
516 & ((v
== DESC_VER_1
) ? LEN_MASK_V1
: LEN_MASK_V2
);
519 static int reg_delay(struct net_device
*dev
, int offset
, u32 mask
, u32 target
,
520 int delay
, int delaymax
, const char *msg
)
522 u8 __iomem
*base
= get_hwbase(dev
);
533 } while ((readl(base
+ offset
) & mask
) != target
);
537 #define MII_READ (-1)
538 /* mii_rw: read/write a register on the PHY.
540 * Caller must guarantee serialization
542 static int mii_rw(struct net_device
*dev
, int addr
, int miireg
, int value
)
544 u8 __iomem
*base
= get_hwbase(dev
);
548 writel(NVREG_MIISTAT_MASK
, base
+ NvRegMIIStatus
);
550 reg
= readl(base
+ NvRegMIIControl
);
551 if (reg
& NVREG_MIICTL_INUSE
) {
552 writel(NVREG_MIICTL_INUSE
, base
+ NvRegMIIControl
);
553 udelay(NV_MIIBUSY_DELAY
);
556 reg
= (addr
<< NVREG_MIICTL_ADDRSHIFT
) | miireg
;
557 if (value
!= MII_READ
) {
558 writel(value
, base
+ NvRegMIIData
);
559 reg
|= NVREG_MIICTL_WRITE
;
561 writel(reg
, base
+ NvRegMIIControl
);
563 if (reg_delay(dev
, NvRegMIIControl
, NVREG_MIICTL_INUSE
, 0,
564 NV_MIIPHY_DELAY
, NV_MIIPHY_DELAYMAX
, NULL
)) {
565 dprintk(KERN_DEBUG
"%s: mii_rw of reg %d at PHY %d timed out.\n",
566 dev
->name
, miireg
, addr
);
568 } else if (value
!= MII_READ
) {
569 /* it was a write operation - fewer failures are detectable */
570 dprintk(KERN_DEBUG
"%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
571 dev
->name
, value
, miireg
, addr
);
573 } else if (readl(base
+ NvRegMIIStatus
) & NVREG_MIISTAT_ERROR
) {
574 dprintk(KERN_DEBUG
"%s: mii_rw of reg %d at PHY %d failed.\n",
575 dev
->name
, miireg
, addr
);
578 retval
= readl(base
+ NvRegMIIData
);
579 dprintk(KERN_DEBUG
"%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
580 dev
->name
, miireg
, addr
, retval
);
586 static int phy_reset(struct net_device
*dev
)
588 struct fe_priv
*np
= get_nvpriv(dev
);
590 unsigned int tries
= 0;
592 miicontrol
= mii_rw(dev
, np
->phyaddr
, MII_BMCR
, MII_READ
);
593 miicontrol
|= BMCR_RESET
;
594 if (mii_rw(dev
, np
->phyaddr
, MII_BMCR
, miicontrol
)) {
601 /* must wait till reset is deasserted */
602 while (miicontrol
& BMCR_RESET
) {
604 miicontrol
= mii_rw(dev
, np
->phyaddr
, MII_BMCR
, MII_READ
);
605 /* FIXME: 100 tries seem excessive */
612 static int phy_init(struct net_device
*dev
)
614 struct fe_priv
*np
= get_nvpriv(dev
);
615 u8 __iomem
*base
= get_hwbase(dev
);
616 u32 phyinterface
, phy_reserved
, mii_status
, mii_control
, mii_control_1000
,reg
;
618 /* set advertise register */
619 reg
= mii_rw(dev
, np
->phyaddr
, MII_ADVERTISE
, MII_READ
);
620 reg
|= (ADVERTISE_10HALF
|ADVERTISE_10FULL
|ADVERTISE_100HALF
|ADVERTISE_100FULL
|0x800|0x400);
621 if (mii_rw(dev
, np
->phyaddr
, MII_ADVERTISE
, reg
)) {
622 printk(KERN_INFO
"%s: phy write to advertise failed.\n", pci_name(np
->pci_dev
));
626 /* get phy interface type */
627 phyinterface
= readl(base
+ NvRegPhyInterface
);
629 /* see if gigabit phy */
630 mii_status
= mii_rw(dev
, np
->phyaddr
, MII_BMSR
, MII_READ
);
631 if (mii_status
& PHY_GIGABIT
) {
632 np
->gigabit
= PHY_GIGABIT
;
633 mii_control_1000
= mii_rw(dev
, np
->phyaddr
, MII_1000BT_CR
, MII_READ
);
634 mii_control_1000
&= ~ADVERTISE_1000HALF
;
635 if (phyinterface
& PHY_RGMII
)
636 mii_control_1000
|= ADVERTISE_1000FULL
;
638 mii_control_1000
&= ~ADVERTISE_1000FULL
;
640 if (mii_rw(dev
, np
->phyaddr
, MII_1000BT_CR
, mii_control_1000
)) {
641 printk(KERN_INFO
"%s: phy init failed.\n", pci_name(np
->pci_dev
));
649 if (phy_reset(dev
)) {
650 printk(KERN_INFO
"%s: phy reset failed\n", pci_name(np
->pci_dev
));
654 /* phy vendor specific configuration */
655 if ((np
->phy_oui
== PHY_OUI_CICADA
) && (phyinterface
& PHY_RGMII
) ) {
656 phy_reserved
= mii_rw(dev
, np
->phyaddr
, MII_RESV1
, MII_READ
);
657 phy_reserved
&= ~(PHY_INIT1
| PHY_INIT2
);
658 phy_reserved
|= (PHY_INIT3
| PHY_INIT4
);
659 if (mii_rw(dev
, np
->phyaddr
, MII_RESV1
, phy_reserved
)) {
660 printk(KERN_INFO
"%s: phy init failed.\n", pci_name(np
->pci_dev
));
663 phy_reserved
= mii_rw(dev
, np
->phyaddr
, MII_NCONFIG
, MII_READ
);
664 phy_reserved
|= PHY_INIT5
;
665 if (mii_rw(dev
, np
->phyaddr
, MII_NCONFIG
, phy_reserved
)) {
666 printk(KERN_INFO
"%s: phy init failed.\n", pci_name(np
->pci_dev
));
670 if (np
->phy_oui
== PHY_OUI_CICADA
) {
671 phy_reserved
= mii_rw(dev
, np
->phyaddr
, MII_SREVISION
, MII_READ
);
672 phy_reserved
|= PHY_INIT6
;
673 if (mii_rw(dev
, np
->phyaddr
, MII_SREVISION
, phy_reserved
)) {
674 printk(KERN_INFO
"%s: phy init failed.\n", pci_name(np
->pci_dev
));
679 /* restart auto negotiation */
680 mii_control
= mii_rw(dev
, np
->phyaddr
, MII_BMCR
, MII_READ
);
681 mii_control
|= (BMCR_ANRESTART
| BMCR_ANENABLE
);
682 if (mii_rw(dev
, np
->phyaddr
, MII_BMCR
, mii_control
)) {
689 static void nv_start_rx(struct net_device
*dev
)
691 struct fe_priv
*np
= get_nvpriv(dev
);
692 u8 __iomem
*base
= get_hwbase(dev
);
694 dprintk(KERN_DEBUG
"%s: nv_start_rx\n", dev
->name
);
695 /* Already running? Stop it. */
696 if (readl(base
+ NvRegReceiverControl
) & NVREG_RCVCTL_START
) {
697 writel(0, base
+ NvRegReceiverControl
);
700 writel(np
->linkspeed
, base
+ NvRegLinkSpeed
);
702 writel(NVREG_RCVCTL_START
, base
+ NvRegReceiverControl
);
703 dprintk(KERN_DEBUG
"%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
704 dev
->name
, np
->duplex
, np
->linkspeed
);
708 static void nv_stop_rx(struct net_device
*dev
)
710 u8 __iomem
*base
= get_hwbase(dev
);
712 dprintk(KERN_DEBUG
"%s: nv_stop_rx\n", dev
->name
);
713 writel(0, base
+ NvRegReceiverControl
);
714 reg_delay(dev
, NvRegReceiverStatus
, NVREG_RCVSTAT_BUSY
, 0,
715 NV_RXSTOP_DELAY1
, NV_RXSTOP_DELAY1MAX
,
716 KERN_INFO
"nv_stop_rx: ReceiverStatus remained busy");
718 udelay(NV_RXSTOP_DELAY2
);
719 writel(0, base
+ NvRegLinkSpeed
);
722 static void nv_start_tx(struct net_device
*dev
)
724 u8 __iomem
*base
= get_hwbase(dev
);
726 dprintk(KERN_DEBUG
"%s: nv_start_tx\n", dev
->name
);
727 writel(NVREG_XMITCTL_START
, base
+ NvRegTransmitterControl
);
731 static void nv_stop_tx(struct net_device
*dev
)
733 u8 __iomem
*base
= get_hwbase(dev
);
735 dprintk(KERN_DEBUG
"%s: nv_stop_tx\n", dev
->name
);
736 writel(0, base
+ NvRegTransmitterControl
);
737 reg_delay(dev
, NvRegTransmitterStatus
, NVREG_XMITSTAT_BUSY
, 0,
738 NV_TXSTOP_DELAY1
, NV_TXSTOP_DELAY1MAX
,
739 KERN_INFO
"nv_stop_tx: TransmitterStatus remained busy");
741 udelay(NV_TXSTOP_DELAY2
);
742 writel(0, base
+ NvRegUnknownTransmitterReg
);
745 static void nv_txrx_reset(struct net_device
*dev
)
747 struct fe_priv
*np
= get_nvpriv(dev
);
748 u8 __iomem
*base
= get_hwbase(dev
);
750 dprintk(KERN_DEBUG
"%s: nv_txrx_reset\n", dev
->name
);
751 writel(NVREG_TXRXCTL_BIT2
| NVREG_TXRXCTL_RESET
| np
->desc_ver
, base
+ NvRegTxRxControl
);
753 udelay(NV_TXRX_RESET_DELAY
);
754 writel(NVREG_TXRXCTL_BIT2
| np
->desc_ver
, base
+ NvRegTxRxControl
);
759 * nv_get_stats: dev->get_stats function
760 * Get latest stats value from the nic.
761 * Called with read_lock(&dev_base_lock) held for read -
762 * only synchronized against unregister_netdevice.
764 static struct net_device_stats
*nv_get_stats(struct net_device
*dev
)
766 struct fe_priv
*np
= get_nvpriv(dev
);
768 /* It seems that the nic always generates interrupts and doesn't
769 * accumulate errors internally. Thus the current values in np->stats
770 * are already up to date.
776 * nv_alloc_rx: fill rx ring entries.
777 * Return 1 if the allocations for the skbs failed and the
778 * rx engine is without Available descriptors
780 static int nv_alloc_rx(struct net_device
*dev
)
782 struct fe_priv
*np
= get_nvpriv(dev
);
783 unsigned int refill_rx
= np
->refill_rx
;
786 while (np
->cur_rx
!= refill_rx
) {
789 nr
= refill_rx
% RX_RING
;
790 if (np
->rx_skbuff
[nr
] == NULL
) {
792 skb
= dev_alloc_skb(RX_ALLOC_BUFSIZE
);
797 np
->rx_skbuff
[nr
] = skb
;
799 skb
= np
->rx_skbuff
[nr
];
801 np
->rx_dma
[nr
] = pci_map_single(np
->pci_dev
, skb
->data
, skb
->len
,
803 np
->rx_ring
[nr
].PacketBuffer
= cpu_to_le32(np
->rx_dma
[nr
]);
805 np
->rx_ring
[nr
].FlagLen
= cpu_to_le32(RX_NIC_BUFSIZE
| NV_RX_AVAIL
);
806 dprintk(KERN_DEBUG
"%s: nv_alloc_rx: Packet %d marked as Available\n",
807 dev
->name
, refill_rx
);
810 np
->refill_rx
= refill_rx
;
811 if (np
->cur_rx
- refill_rx
== RX_RING
)
816 static void nv_do_rx_refill(unsigned long data
)
818 struct net_device
*dev
= (struct net_device
*) data
;
819 struct fe_priv
*np
= get_nvpriv(dev
);
821 disable_irq(dev
->irq
);
822 if (nv_alloc_rx(dev
)) {
823 spin_lock(&np
->lock
);
824 if (!np
->in_shutdown
)
825 mod_timer(&np
->oom_kick
, jiffies
+ OOM_REFILL
);
826 spin_unlock(&np
->lock
);
828 enable_irq(dev
->irq
);
831 static int nv_init_ring(struct net_device
*dev
)
833 struct fe_priv
*np
= get_nvpriv(dev
);
836 np
->next_tx
= np
->nic_tx
= 0;
837 for (i
= 0; i
< TX_RING
; i
++)
838 np
->tx_ring
[i
].FlagLen
= 0;
840 np
->cur_rx
= RX_RING
;
842 for (i
= 0; i
< RX_RING
; i
++)
843 np
->rx_ring
[i
].FlagLen
= 0;
844 return nv_alloc_rx(dev
);
847 static void nv_drain_tx(struct net_device
*dev
)
849 struct fe_priv
*np
= get_nvpriv(dev
);
851 for (i
= 0; i
< TX_RING
; i
++) {
852 np
->tx_ring
[i
].FlagLen
= 0;
853 if (np
->tx_skbuff
[i
]) {
854 pci_unmap_single(np
->pci_dev
, np
->tx_dma
[i
],
855 np
->tx_skbuff
[i
]->len
,
857 dev_kfree_skb(np
->tx_skbuff
[i
]);
858 np
->tx_skbuff
[i
] = NULL
;
859 np
->stats
.tx_dropped
++;
864 static void nv_drain_rx(struct net_device
*dev
)
866 struct fe_priv
*np
= get_nvpriv(dev
);
868 for (i
= 0; i
< RX_RING
; i
++) {
869 np
->rx_ring
[i
].FlagLen
= 0;
871 if (np
->rx_skbuff
[i
]) {
872 pci_unmap_single(np
->pci_dev
, np
->rx_dma
[i
],
873 np
->rx_skbuff
[i
]->len
,
875 dev_kfree_skb(np
->rx_skbuff
[i
]);
876 np
->rx_skbuff
[i
] = NULL
;
881 static void drain_ring(struct net_device
*dev
)
888 * nv_start_xmit: dev->hard_start_xmit function
889 * Called with dev->xmit_lock held.
891 static int nv_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
893 struct fe_priv
*np
= get_nvpriv(dev
);
894 int nr
= np
->next_tx
% TX_RING
;
896 np
->tx_skbuff
[nr
] = skb
;
897 np
->tx_dma
[nr
] = pci_map_single(np
->pci_dev
, skb
->data
,skb
->len
,
900 np
->tx_ring
[nr
].PacketBuffer
= cpu_to_le32(np
->tx_dma
[nr
]);
902 spin_lock_irq(&np
->lock
);
904 np
->tx_ring
[nr
].FlagLen
= cpu_to_le32( (skb
->len
-1) | np
->tx_flags
);
905 dprintk(KERN_DEBUG
"%s: nv_start_xmit: packet packet %d queued for transmission.\n",
906 dev
->name
, np
->next_tx
);
909 for (j
=0; j
<64; j
++) {
911 dprintk("\n%03x:", j
);
912 dprintk(" %02x", ((unsigned char*)skb
->data
)[j
]);
919 dev
->trans_start
= jiffies
;
920 if (np
->next_tx
- np
->nic_tx
>= TX_LIMIT_STOP
)
921 netif_stop_queue(dev
);
922 spin_unlock_irq(&np
->lock
);
923 writel(NVREG_TXRXCTL_KICK
|np
->desc_ver
, get_hwbase(dev
) + NvRegTxRxControl
);
924 pci_push(get_hwbase(dev
));
929 * nv_tx_done: check for completed packets, release the skbs.
931 * Caller must own np->lock.
933 static void nv_tx_done(struct net_device
*dev
)
935 struct fe_priv
*np
= get_nvpriv(dev
);
939 while (np
->nic_tx
!= np
->next_tx
) {
940 i
= np
->nic_tx
% TX_RING
;
942 Flags
= le32_to_cpu(np
->tx_ring
[i
].FlagLen
);
944 dprintk(KERN_DEBUG
"%s: nv_tx_done: looking at packet %d, Flags 0x%x.\n",
945 dev
->name
, np
->nic_tx
, Flags
);
946 if (Flags
& NV_TX_VALID
)
948 if (np
->desc_ver
== DESC_VER_1
) {
949 if (Flags
& (NV_TX_RETRYERROR
|NV_TX_CARRIERLOST
|NV_TX_LATECOLLISION
|
950 NV_TX_UNDERFLOW
|NV_TX_ERROR
)) {
951 if (Flags
& NV_TX_UNDERFLOW
)
952 np
->stats
.tx_fifo_errors
++;
953 if (Flags
& NV_TX_CARRIERLOST
)
954 np
->stats
.tx_carrier_errors
++;
955 np
->stats
.tx_errors
++;
957 np
->stats
.tx_packets
++;
958 np
->stats
.tx_bytes
+= np
->tx_skbuff
[i
]->len
;
961 if (Flags
& (NV_TX2_RETRYERROR
|NV_TX2_CARRIERLOST
|NV_TX2_LATECOLLISION
|
962 NV_TX2_UNDERFLOW
|NV_TX2_ERROR
)) {
963 if (Flags
& NV_TX2_UNDERFLOW
)
964 np
->stats
.tx_fifo_errors
++;
965 if (Flags
& NV_TX2_CARRIERLOST
)
966 np
->stats
.tx_carrier_errors
++;
967 np
->stats
.tx_errors
++;
969 np
->stats
.tx_packets
++;
970 np
->stats
.tx_bytes
+= np
->tx_skbuff
[i
]->len
;
973 pci_unmap_single(np
->pci_dev
, np
->tx_dma
[i
],
974 np
->tx_skbuff
[i
]->len
,
976 dev_kfree_skb_irq(np
->tx_skbuff
[i
]);
977 np
->tx_skbuff
[i
] = NULL
;
980 if (np
->next_tx
- np
->nic_tx
< TX_LIMIT_START
)
981 netif_wake_queue(dev
);
985 * nv_tx_timeout: dev->tx_timeout function
986 * Called with dev->xmit_lock held.
988 static void nv_tx_timeout(struct net_device
*dev
)
990 struct fe_priv
*np
= get_nvpriv(dev
);
991 u8 __iomem
*base
= get_hwbase(dev
);
993 dprintk(KERN_DEBUG
"%s: Got tx_timeout. irq: %08x\n", dev
->name
,
994 readl(base
+ NvRegIrqStatus
) & NVREG_IRQSTAT_MASK
);
996 spin_lock_irq(&np
->lock
);
998 /* 1) stop tx engine */
1001 /* 2) check that the packets were not sent already: */
1004 /* 3) if there are dead entries: clear everything */
1005 if (np
->next_tx
!= np
->nic_tx
) {
1006 printk(KERN_DEBUG
"%s: tx_timeout: dead entries!\n", dev
->name
);
1008 np
->next_tx
= np
->nic_tx
= 0;
1009 writel((u32
) (np
->ring_addr
+ RX_RING
*sizeof(struct ring_desc
)), base
+ NvRegTxRingPhysAddr
);
1010 netif_wake_queue(dev
);
1013 /* 4) restart tx engine */
1015 spin_unlock_irq(&np
->lock
);
1019 * Called when the nic notices a mismatch between the actual data len on the
1020 * wire and the len indicated in the 802 header
1022 static int nv_getlen(struct net_device
*dev
, void *packet
, int datalen
)
1024 int hdrlen
; /* length of the 802 header */
1025 int protolen
; /* length as stored in the proto field */
1027 /* 1) calculate len according to header */
1028 if ( ((struct vlan_ethhdr
*)packet
)->h_vlan_proto
== __constant_htons(ETH_P_8021Q
)) {
1029 protolen
= ntohs( ((struct vlan_ethhdr
*)packet
)->h_vlan_encapsulated_proto
);
1032 protolen
= ntohs( ((struct ethhdr
*)packet
)->h_proto
);
1035 dprintk(KERN_DEBUG
"%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
1036 dev
->name
, datalen
, protolen
, hdrlen
);
1037 if (protolen
> ETH_DATA_LEN
)
1038 return datalen
; /* Value in proto field not a len, no checks possible */
1041 /* consistency checks: */
1042 if (datalen
> ETH_ZLEN
) {
1043 if (datalen
>= protolen
) {
1044 /* more data on wire than in 802 header, trim of
1047 dprintk(KERN_DEBUG
"%s: nv_getlen: accepting %d bytes.\n",
1048 dev
->name
, protolen
);
1051 /* less data on wire than mentioned in header.
1052 * Discard the packet.
1054 dprintk(KERN_DEBUG
"%s: nv_getlen: discarding long packet.\n",
1059 /* short packet. Accept only if 802 values are also short */
1060 if (protolen
> ETH_ZLEN
) {
1061 dprintk(KERN_DEBUG
"%s: nv_getlen: discarding short packet.\n",
1065 dprintk(KERN_DEBUG
"%s: nv_getlen: accepting %d bytes.\n",
1066 dev
->name
, datalen
);
1071 static void nv_rx_process(struct net_device
*dev
)
1073 struct fe_priv
*np
= get_nvpriv(dev
);
1077 struct sk_buff
*skb
;
1080 if (np
->cur_rx
- np
->refill_rx
>= RX_RING
)
1081 break; /* we scanned the whole ring - do not continue */
1083 i
= np
->cur_rx
% RX_RING
;
1084 Flags
= le32_to_cpu(np
->rx_ring
[i
].FlagLen
);
1085 len
= nv_descr_getlength(&np
->rx_ring
[i
], np
->desc_ver
);
1087 dprintk(KERN_DEBUG
"%s: nv_rx_process: looking at packet %d, Flags 0x%x.\n",
1088 dev
->name
, np
->cur_rx
, Flags
);
1090 if (Flags
& NV_RX_AVAIL
)
1091 break; /* still owned by hardware, */
1094 * the packet is for us - immediately tear down the pci mapping.
1095 * TODO: check if a prefetch of the first cacheline improves
1098 pci_unmap_single(np
->pci_dev
, np
->rx_dma
[i
],
1099 np
->rx_skbuff
[i
]->len
,
1100 PCI_DMA_FROMDEVICE
);
1104 dprintk(KERN_DEBUG
"Dumping packet (flags 0x%x).",Flags
);
1105 for (j
=0; j
<64; j
++) {
1107 dprintk("\n%03x:", j
);
1108 dprintk(" %02x", ((unsigned char*)np
->rx_skbuff
[i
]->data
)[j
]);
1112 /* look at what we actually got: */
1113 if (np
->desc_ver
== DESC_VER_1
) {
1114 if (!(Flags
& NV_RX_DESCRIPTORVALID
))
1117 if (Flags
& NV_RX_MISSEDFRAME
) {
1118 np
->stats
.rx_missed_errors
++;
1119 np
->stats
.rx_errors
++;
1122 if (Flags
& (NV_RX_ERROR1
|NV_RX_ERROR2
|NV_RX_ERROR3
)) {
1123 np
->stats
.rx_errors
++;
1126 if (Flags
& NV_RX_CRCERR
) {
1127 np
->stats
.rx_crc_errors
++;
1128 np
->stats
.rx_errors
++;
1131 if (Flags
& NV_RX_OVERFLOW
) {
1132 np
->stats
.rx_over_errors
++;
1133 np
->stats
.rx_errors
++;
1136 if (Flags
& NV_RX_ERROR4
) {
1137 len
= nv_getlen(dev
, np
->rx_skbuff
[i
]->data
, len
);
1139 np
->stats
.rx_errors
++;
1143 /* framing errors are soft errors. */
1144 if (Flags
& NV_RX_FRAMINGERR
) {
1145 if (Flags
& NV_RX_SUBSTRACT1
) {
1150 if (!(Flags
& NV_RX2_DESCRIPTORVALID
))
1153 if (Flags
& (NV_RX2_ERROR1
|NV_RX2_ERROR2
|NV_RX2_ERROR3
)) {
1154 np
->stats
.rx_errors
++;
1157 if (Flags
& NV_RX2_CRCERR
) {
1158 np
->stats
.rx_crc_errors
++;
1159 np
->stats
.rx_errors
++;
1162 if (Flags
& NV_RX2_OVERFLOW
) {
1163 np
->stats
.rx_over_errors
++;
1164 np
->stats
.rx_errors
++;
1167 if (Flags
& NV_RX2_ERROR4
) {
1168 len
= nv_getlen(dev
, np
->rx_skbuff
[i
]->data
, len
);
1170 np
->stats
.rx_errors
++;
1174 /* framing errors are soft errors */
1175 if (Flags
& NV_RX2_FRAMINGERR
) {
1176 if (Flags
& NV_RX2_SUBSTRACT1
) {
1180 Flags
&= NV_RX2_CHECKSUMMASK
;
1181 if (Flags
== NV_RX2_CHECKSUMOK1
||
1182 Flags
== NV_RX2_CHECKSUMOK2
||
1183 Flags
== NV_RX2_CHECKSUMOK3
) {
1184 dprintk(KERN_DEBUG
"%s: hw checksum hit!.\n", dev
->name
);
1185 np
->rx_skbuff
[i
]->ip_summed
= CHECKSUM_UNNECESSARY
;
1187 dprintk(KERN_DEBUG
"%s: hwchecksum miss!.\n", dev
->name
);
1190 /* got a valid packet - forward it to the network core */
1191 skb
= np
->rx_skbuff
[i
];
1192 np
->rx_skbuff
[i
] = NULL
;
1195 skb
->protocol
= eth_type_trans(skb
, dev
);
1196 dprintk(KERN_DEBUG
"%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n",
1197 dev
->name
, np
->cur_rx
, len
, skb
->protocol
);
1199 dev
->last_rx
= jiffies
;
1200 np
->stats
.rx_packets
++;
1201 np
->stats
.rx_bytes
+= len
;
1208 * nv_change_mtu: dev->change_mtu function
1209 * Called with dev_base_lock held for read.
1211 static int nv_change_mtu(struct net_device
*dev
, int new_mtu
)
1213 if (new_mtu
> ETH_DATA_LEN
)
1220 * nv_set_multicast: dev->set_multicast function
1221 * Called with dev->xmit_lock held.
1223 static void nv_set_multicast(struct net_device
*dev
)
1225 struct fe_priv
*np
= get_nvpriv(dev
);
1226 u8 __iomem
*base
= get_hwbase(dev
);
1231 memset(addr
, 0, sizeof(addr
));
1232 memset(mask
, 0, sizeof(mask
));
1234 if (dev
->flags
& IFF_PROMISC
) {
1235 printk(KERN_NOTICE
"%s: Promiscuous mode enabled.\n", dev
->name
);
1236 pff
= NVREG_PFF_PROMISC
;
1238 pff
= NVREG_PFF_MYADDR
;
1240 if (dev
->flags
& IFF_ALLMULTI
|| dev
->mc_list
) {
1244 alwaysOn
[0] = alwaysOn
[1] = alwaysOff
[0] = alwaysOff
[1] = 0xffffffff;
1245 if (dev
->flags
& IFF_ALLMULTI
) {
1246 alwaysOn
[0] = alwaysOn
[1] = alwaysOff
[0] = alwaysOff
[1] = 0;
1248 struct dev_mc_list
*walk
;
1250 walk
= dev
->mc_list
;
1251 while (walk
!= NULL
) {
1253 a
= le32_to_cpu(*(u32
*) walk
->dmi_addr
);
1254 b
= le16_to_cpu(*(u16
*) (&walk
->dmi_addr
[4]));
1262 addr
[0] = alwaysOn
[0];
1263 addr
[1] = alwaysOn
[1];
1264 mask
[0] = alwaysOn
[0] | alwaysOff
[0];
1265 mask
[1] = alwaysOn
[1] | alwaysOff
[1];
1268 addr
[0] |= NVREG_MCASTADDRA_FORCE
;
1269 pff
|= NVREG_PFF_ALWAYS
;
1270 spin_lock_irq(&np
->lock
);
1272 writel(addr
[0], base
+ NvRegMulticastAddrA
);
1273 writel(addr
[1], base
+ NvRegMulticastAddrB
);
1274 writel(mask
[0], base
+ NvRegMulticastMaskA
);
1275 writel(mask
[1], base
+ NvRegMulticastMaskB
);
1276 writel(pff
, base
+ NvRegPacketFilterFlags
);
1277 dprintk(KERN_INFO
"%s: reconfiguration for multicast lists.\n",
1280 spin_unlock_irq(&np
->lock
);
1283 static int nv_update_linkspeed(struct net_device
*dev
)
1285 struct fe_priv
*np
= get_nvpriv(dev
);
1286 u8 __iomem
*base
= get_hwbase(dev
);
1288 int newls
= np
->linkspeed
;
1289 int newdup
= np
->duplex
;
1292 u32 control_1000
, status_1000
, phyreg
;
1294 /* BMSR_LSTATUS is latched, read it twice:
1295 * we want the current value.
1297 mii_rw(dev
, np
->phyaddr
, MII_BMSR
, MII_READ
);
1298 mii_status
= mii_rw(dev
, np
->phyaddr
, MII_BMSR
, MII_READ
);
1300 if (!(mii_status
& BMSR_LSTATUS
)) {
1301 dprintk(KERN_DEBUG
"%s: no link detected by phy - falling back to 10HD.\n",
1303 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_10
;
1309 if (np
->autoneg
== 0) {
1310 dprintk(KERN_DEBUG
"%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
1311 dev
->name
, np
->fixed_mode
);
1312 if (np
->fixed_mode
& LPA_100FULL
) {
1313 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_100
;
1315 } else if (np
->fixed_mode
& LPA_100HALF
) {
1316 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_100
;
1318 } else if (np
->fixed_mode
& LPA_10FULL
) {
1319 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_10
;
1322 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_10
;
1328 /* check auto negotiation is complete */
1329 if (!(mii_status
& BMSR_ANEGCOMPLETE
)) {
1330 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
1331 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_10
;
1334 dprintk(KERN_DEBUG
"%s: autoneg not completed - falling back to 10HD.\n", dev
->name
);
1339 if (np
->gigabit
== PHY_GIGABIT
) {
1340 control_1000
= mii_rw(dev
, np
->phyaddr
, MII_1000BT_CR
, MII_READ
);
1341 status_1000
= mii_rw(dev
, np
->phyaddr
, MII_1000BT_SR
, MII_READ
);
1343 if ((control_1000
& ADVERTISE_1000FULL
) &&
1344 (status_1000
& LPA_1000FULL
)) {
1345 dprintk(KERN_DEBUG
"%s: nv_update_linkspeed: GBit ethernet detected.\n",
1347 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_1000
;
1353 adv
= mii_rw(dev
, np
->phyaddr
, MII_ADVERTISE
, MII_READ
);
1354 lpa
= mii_rw(dev
, np
->phyaddr
, MII_LPA
, MII_READ
);
1355 dprintk(KERN_DEBUG
"%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
1356 dev
->name
, adv
, lpa
);
1358 /* FIXME: handle parallel detection properly */
1360 if (lpa
& LPA_100FULL
) {
1361 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_100
;
1363 } else if (lpa
& LPA_100HALF
) {
1364 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_100
;
1366 } else if (lpa
& LPA_10FULL
) {
1367 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_10
;
1369 } else if (lpa
& LPA_10HALF
) {
1370 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_10
;
1373 dprintk(KERN_DEBUG
"%s: bad ability %04x - falling back to 10HD.\n", dev
->name
, lpa
);
1374 newls
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_10
;
1379 if (np
->duplex
== newdup
&& np
->linkspeed
== newls
)
1382 dprintk(KERN_INFO
"%s: changing link setting from %d/%d to %d/%d.\n",
1383 dev
->name
, np
->linkspeed
, np
->duplex
, newls
, newdup
);
1385 np
->duplex
= newdup
;
1386 np
->linkspeed
= newls
;
1388 if (np
->gigabit
== PHY_GIGABIT
) {
1389 phyreg
= readl(base
+ NvRegRandomSeed
);
1390 phyreg
&= ~(0x3FF00);
1391 if ((np
->linkspeed
& 0xFFF) == NVREG_LINKSPEED_10
)
1392 phyreg
|= NVREG_RNDSEED_FORCE3
;
1393 else if ((np
->linkspeed
& 0xFFF) == NVREG_LINKSPEED_100
)
1394 phyreg
|= NVREG_RNDSEED_FORCE2
;
1395 else if ((np
->linkspeed
& 0xFFF) == NVREG_LINKSPEED_1000
)
1396 phyreg
|= NVREG_RNDSEED_FORCE
;
1397 writel(phyreg
, base
+ NvRegRandomSeed
);
1400 phyreg
= readl(base
+ NvRegPhyInterface
);
1401 phyreg
&= ~(PHY_HALF
|PHY_100
|PHY_1000
);
1402 if (np
->duplex
== 0)
1404 if ((np
->linkspeed
& NVREG_LINKSPEED_MASK
) == NVREG_LINKSPEED_100
)
1406 else if ((np
->linkspeed
& NVREG_LINKSPEED_MASK
) == NVREG_LINKSPEED_1000
)
1408 writel(phyreg
, base
+ NvRegPhyInterface
);
1410 writel(NVREG_MISC1_FORCE
| ( np
->duplex
? 0 : NVREG_MISC1_HD
),
1413 writel(np
->linkspeed
, base
+ NvRegLinkSpeed
);
1419 static void nv_linkchange(struct net_device
*dev
)
1421 if (nv_update_linkspeed(dev
)) {
1422 if (netif_carrier_ok(dev
)) {
1425 netif_carrier_on(dev
);
1426 printk(KERN_INFO
"%s: link up.\n", dev
->name
);
1430 if (netif_carrier_ok(dev
)) {
1431 netif_carrier_off(dev
);
1432 printk(KERN_INFO
"%s: link down.\n", dev
->name
);
1438 static void nv_link_irq(struct net_device
*dev
)
1440 u8 __iomem
*base
= get_hwbase(dev
);
1443 miistat
= readl(base
+ NvRegMIIStatus
);
1444 writel(NVREG_MIISTAT_MASK
, base
+ NvRegMIIStatus
);
1445 dprintk(KERN_INFO
"%s: link change irq, status 0x%x.\n", dev
->name
, miistat
);
1447 if (miistat
& (NVREG_MIISTAT_LINKCHANGE
))
1449 dprintk(KERN_DEBUG
"%s: link change notification done.\n", dev
->name
);
1452 static irqreturn_t
nv_nic_irq(int foo
, void *data
, struct pt_regs
*regs
)
1454 struct net_device
*dev
= (struct net_device
*) data
;
1455 struct fe_priv
*np
= get_nvpriv(dev
);
1456 u8 __iomem
*base
= get_hwbase(dev
);
1460 dprintk(KERN_DEBUG
"%s: nv_nic_irq\n", dev
->name
);
1463 events
= readl(base
+ NvRegIrqStatus
) & NVREG_IRQSTAT_MASK
;
1464 writel(NVREG_IRQSTAT_MASK
, base
+ NvRegIrqStatus
);
1466 dprintk(KERN_DEBUG
"%s: irq: %08x\n", dev
->name
, events
);
1467 if (!(events
& np
->irqmask
))
1470 if (events
& (NVREG_IRQ_TX1
|NVREG_IRQ_TX2
|NVREG_IRQ_TX_ERR
)) {
1471 spin_lock(&np
->lock
);
1473 spin_unlock(&np
->lock
);
1476 if (events
& (NVREG_IRQ_RX_ERROR
|NVREG_IRQ_RX
|NVREG_IRQ_RX_NOBUF
)) {
1478 if (nv_alloc_rx(dev
)) {
1479 spin_lock(&np
->lock
);
1480 if (!np
->in_shutdown
)
1481 mod_timer(&np
->oom_kick
, jiffies
+ OOM_REFILL
);
1482 spin_unlock(&np
->lock
);
1486 if (events
& NVREG_IRQ_LINK
) {
1487 spin_lock(&np
->lock
);
1489 spin_unlock(&np
->lock
);
1491 if (np
->need_linktimer
&& time_after(jiffies
, np
->link_timeout
)) {
1492 spin_lock(&np
->lock
);
1494 spin_unlock(&np
->lock
);
1495 np
->link_timeout
= jiffies
+ LINK_TIMEOUT
;
1497 if (events
& (NVREG_IRQ_TX_ERR
)) {
1498 dprintk(KERN_DEBUG
"%s: received irq with events 0x%x. Probably TX fail.\n",
1501 if (events
& (NVREG_IRQ_UNKNOWN
)) {
1502 printk(KERN_DEBUG
"%s: received irq with unknown events 0x%x. Please report\n",
1505 if (i
> max_interrupt_work
) {
1506 spin_lock(&np
->lock
);
1507 /* disable interrupts on the nic */
1508 writel(0, base
+ NvRegIrqMask
);
1511 if (!np
->in_shutdown
)
1512 mod_timer(&np
->nic_poll
, jiffies
+ POLL_WAIT
);
1513 printk(KERN_DEBUG
"%s: too many iterations (%d) in nv_nic_irq.\n", dev
->name
, i
);
1514 spin_unlock(&np
->lock
);
1519 dprintk(KERN_DEBUG
"%s: nv_nic_irq completed\n", dev
->name
);
1521 return IRQ_RETVAL(i
);
1524 static void nv_do_nic_poll(unsigned long data
)
1526 struct net_device
*dev
= (struct net_device
*) data
;
1527 struct fe_priv
*np
= get_nvpriv(dev
);
1528 u8 __iomem
*base
= get_hwbase(dev
);
1530 disable_irq(dev
->irq
);
1531 /* FIXME: Do we need synchronize_irq(dev->irq) here? */
1533 * reenable interrupts on the nic, we have to do this before calling
1534 * nv_nic_irq because that may decide to do otherwise
1536 writel(np
->irqmask
, base
+ NvRegIrqMask
);
1538 nv_nic_irq((int) 0, (void *) data
, (struct pt_regs
*) NULL
);
1539 enable_irq(dev
->irq
);
1542 #ifdef CONFIG_NET_POLL_CONTROLLER
1543 static void nv_poll_controller(struct net_device
*dev
)
1545 nv_do_nic_poll((unsigned long) dev
);
1549 static void nv_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1551 struct fe_priv
*np
= get_nvpriv(dev
);
1552 strcpy(info
->driver
, "forcedeth");
1553 strcpy(info
->version
, FORCEDETH_VERSION
);
1554 strcpy(info
->bus_info
, pci_name(np
->pci_dev
));
1557 static void nv_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wolinfo
)
1559 struct fe_priv
*np
= get_nvpriv(dev
);
1560 wolinfo
->supported
= WAKE_MAGIC
;
1562 spin_lock_irq(&np
->lock
);
1564 wolinfo
->wolopts
= WAKE_MAGIC
;
1565 spin_unlock_irq(&np
->lock
);
1568 static int nv_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wolinfo
)
1570 struct fe_priv
*np
= get_nvpriv(dev
);
1571 u8 __iomem
*base
= get_hwbase(dev
);
1573 spin_lock_irq(&np
->lock
);
1574 if (wolinfo
->wolopts
== 0) {
1575 writel(0, base
+ NvRegWakeUpFlags
);
1578 if (wolinfo
->wolopts
& WAKE_MAGIC
) {
1579 writel(NVREG_WAKEUPFLAGS_ENABLE
, base
+ NvRegWakeUpFlags
);
1582 spin_unlock_irq(&np
->lock
);
1586 static int nv_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1588 struct fe_priv
*np
= netdev_priv(dev
);
1591 spin_lock_irq(&np
->lock
);
1592 ecmd
->port
= PORT_MII
;
1593 if (!netif_running(dev
)) {
1594 /* We do not track link speed / duplex setting if the
1595 * interface is disabled. Force a link check */
1596 nv_update_linkspeed(dev
);
1598 switch(np
->linkspeed
& (NVREG_LINKSPEED_MASK
)) {
1599 case NVREG_LINKSPEED_10
:
1600 ecmd
->speed
= SPEED_10
;
1602 case NVREG_LINKSPEED_100
:
1603 ecmd
->speed
= SPEED_100
;
1605 case NVREG_LINKSPEED_1000
:
1606 ecmd
->speed
= SPEED_1000
;
1609 ecmd
->duplex
= DUPLEX_HALF
;
1611 ecmd
->duplex
= DUPLEX_FULL
;
1613 ecmd
->autoneg
= np
->autoneg
;
1615 ecmd
->advertising
= ADVERTISED_MII
;
1617 ecmd
->advertising
|= ADVERTISED_Autoneg
;
1618 adv
= mii_rw(dev
, np
->phyaddr
, MII_ADVERTISE
, MII_READ
);
1620 adv
= np
->fixed_mode
;
1622 if (adv
& ADVERTISE_10HALF
)
1623 ecmd
->advertising
|= ADVERTISED_10baseT_Half
;
1624 if (adv
& ADVERTISE_10FULL
)
1625 ecmd
->advertising
|= ADVERTISED_10baseT_Full
;
1626 if (adv
& ADVERTISE_100HALF
)
1627 ecmd
->advertising
|= ADVERTISED_100baseT_Half
;
1628 if (adv
& ADVERTISE_100FULL
)
1629 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
1630 if (np
->autoneg
&& np
->gigabit
== PHY_GIGABIT
) {
1631 adv
= mii_rw(dev
, np
->phyaddr
, MII_1000BT_CR
, MII_READ
);
1632 if (adv
& ADVERTISE_1000FULL
)
1633 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
1636 ecmd
->supported
= (SUPPORTED_Autoneg
|
1637 SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
|
1638 SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
|
1640 if (np
->gigabit
== PHY_GIGABIT
)
1641 ecmd
->supported
|= SUPPORTED_1000baseT_Full
;
1643 ecmd
->phy_address
= np
->phyaddr
;
1644 ecmd
->transceiver
= XCVR_EXTERNAL
;
1646 /* ignore maxtxpkt, maxrxpkt for now */
1647 spin_unlock_irq(&np
->lock
);
1651 static int nv_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1653 struct fe_priv
*np
= netdev_priv(dev
);
1655 if (ecmd
->port
!= PORT_MII
)
1657 if (ecmd
->transceiver
!= XCVR_EXTERNAL
)
1659 if (ecmd
->phy_address
!= np
->phyaddr
) {
1660 /* TODO: support switching between multiple phys. Should be
1661 * trivial, but not enabled due to lack of test hardware. */
1664 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
1667 mask
= ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
|
1668 ADVERTISED_100baseT_Half
| ADVERTISED_100baseT_Full
;
1669 if (np
->gigabit
== PHY_GIGABIT
)
1670 mask
|= ADVERTISED_1000baseT_Full
;
1672 if ((ecmd
->advertising
& mask
) == 0)
1675 } else if (ecmd
->autoneg
== AUTONEG_DISABLE
) {
1676 /* Note: autonegotiation disable, speed 1000 intentionally
1677 * forbidden - noone should need that. */
1679 if (ecmd
->speed
!= SPEED_10
&& ecmd
->speed
!= SPEED_100
)
1681 if (ecmd
->duplex
!= DUPLEX_HALF
&& ecmd
->duplex
!= DUPLEX_FULL
)
1687 spin_lock_irq(&np
->lock
);
1688 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
1693 /* advertise only what has been requested */
1694 adv
= mii_rw(dev
, np
->phyaddr
, MII_ADVERTISE
, MII_READ
);
1695 adv
&= ~(ADVERTISE_ALL
| ADVERTISE_100BASE4
);
1696 if (ecmd
->advertising
& ADVERTISED_10baseT_Half
)
1697 adv
|= ADVERTISE_10HALF
;
1698 if (ecmd
->advertising
& ADVERTISED_10baseT_Full
)
1699 adv
|= ADVERTISE_10FULL
;
1700 if (ecmd
->advertising
& ADVERTISED_100baseT_Half
)
1701 adv
|= ADVERTISE_100HALF
;
1702 if (ecmd
->advertising
& ADVERTISED_100baseT_Full
)
1703 adv
|= ADVERTISE_100FULL
;
1704 mii_rw(dev
, np
->phyaddr
, MII_ADVERTISE
, adv
);
1706 if (np
->gigabit
== PHY_GIGABIT
) {
1707 adv
= mii_rw(dev
, np
->phyaddr
, MII_1000BT_CR
, MII_READ
);
1708 adv
&= ~ADVERTISE_1000FULL
;
1709 if (ecmd
->advertising
& ADVERTISED_1000baseT_Full
)
1710 adv
|= ADVERTISE_1000FULL
;
1711 mii_rw(dev
, np
->phyaddr
, MII_1000BT_CR
, adv
);
1714 bmcr
= mii_rw(dev
, np
->phyaddr
, MII_BMCR
, MII_READ
);
1715 bmcr
|= (BMCR_ANENABLE
| BMCR_ANRESTART
);
1716 mii_rw(dev
, np
->phyaddr
, MII_BMCR
, bmcr
);
1723 adv
= mii_rw(dev
, np
->phyaddr
, MII_ADVERTISE
, MII_READ
);
1724 adv
&= ~(ADVERTISE_ALL
| ADVERTISE_100BASE4
);
1725 if (ecmd
->speed
== SPEED_10
&& ecmd
->duplex
== DUPLEX_HALF
)
1726 adv
|= ADVERTISE_10HALF
;
1727 if (ecmd
->speed
== SPEED_10
&& ecmd
->duplex
== DUPLEX_FULL
)
1728 adv
|= ADVERTISE_10FULL
;
1729 if (ecmd
->speed
== SPEED_100
&& ecmd
->duplex
== DUPLEX_HALF
)
1730 adv
|= ADVERTISE_100HALF
;
1731 if (ecmd
->speed
== SPEED_100
&& ecmd
->duplex
== DUPLEX_FULL
)
1732 adv
|= ADVERTISE_100FULL
;
1733 mii_rw(dev
, np
->phyaddr
, MII_ADVERTISE
, adv
);
1734 np
->fixed_mode
= adv
;
1736 if (np
->gigabit
== PHY_GIGABIT
) {
1737 adv
= mii_rw(dev
, np
->phyaddr
, MII_1000BT_CR
, MII_READ
);
1738 adv
&= ~ADVERTISE_1000FULL
;
1739 mii_rw(dev
, np
->phyaddr
, MII_1000BT_CR
, adv
);
1742 bmcr
= mii_rw(dev
, np
->phyaddr
, MII_BMCR
, MII_READ
);
1743 bmcr
|= ~(BMCR_ANENABLE
|BMCR_SPEED100
|BMCR_FULLDPLX
);
1744 if (adv
& (ADVERTISE_10FULL
|ADVERTISE_100FULL
))
1745 bmcr
|= BMCR_FULLDPLX
;
1746 if (adv
& (ADVERTISE_100HALF
|ADVERTISE_100FULL
))
1747 bmcr
|= BMCR_SPEED100
;
1748 mii_rw(dev
, np
->phyaddr
, MII_BMCR
, bmcr
);
1750 if (netif_running(dev
)) {
1751 /* Wait a bit and then reconfigure the nic. */
1756 spin_unlock_irq(&np
->lock
);
1761 static struct ethtool_ops ops
= {
1762 .get_drvinfo
= nv_get_drvinfo
,
1763 .get_link
= ethtool_op_get_link
,
1764 .get_wol
= nv_get_wol
,
1765 .set_wol
= nv_set_wol
,
1766 .get_settings
= nv_get_settings
,
1767 .set_settings
= nv_set_settings
,
1770 static int nv_open(struct net_device
*dev
)
1772 struct fe_priv
*np
= get_nvpriv(dev
);
1773 u8 __iomem
*base
= get_hwbase(dev
);
1776 dprintk(KERN_DEBUG
"nv_open: begin\n");
1778 /* 1) erase previous misconfiguration */
1779 /* 4.1-1: stop adapter: ignored, 4.3 seems to be overkill */
1780 writel(NVREG_MCASTADDRA_FORCE
, base
+ NvRegMulticastAddrA
);
1781 writel(0, base
+ NvRegMulticastAddrB
);
1782 writel(0, base
+ NvRegMulticastMaskA
);
1783 writel(0, base
+ NvRegMulticastMaskB
);
1784 writel(0, base
+ NvRegPacketFilterFlags
);
1786 writel(0, base
+ NvRegTransmitterControl
);
1787 writel(0, base
+ NvRegReceiverControl
);
1789 writel(0, base
+ NvRegAdapterControl
);
1791 /* 2) initialize descriptor rings */
1792 oom
= nv_init_ring(dev
);
1794 writel(0, base
+ NvRegLinkSpeed
);
1795 writel(0, base
+ NvRegUnknownTransmitterReg
);
1797 writel(0, base
+ NvRegUnknownSetupReg6
);
1799 np
->in_shutdown
= 0;
1801 /* 3) set mac address */
1805 mac
[0] = (dev
->dev_addr
[0] << 0) + (dev
->dev_addr
[1] << 8) +
1806 (dev
->dev_addr
[2] << 16) + (dev
->dev_addr
[3] << 24);
1807 mac
[1] = (dev
->dev_addr
[4] << 0) + (dev
->dev_addr
[5] << 8);
1809 writel(mac
[0], base
+ NvRegMacAddrA
);
1810 writel(mac
[1], base
+ NvRegMacAddrB
);
1813 /* 4) give hw rings */
1814 writel((u32
) np
->ring_addr
, base
+ NvRegRxRingPhysAddr
);
1815 writel((u32
) (np
->ring_addr
+ RX_RING
*sizeof(struct ring_desc
)), base
+ NvRegTxRingPhysAddr
);
1816 writel( ((RX_RING
-1) << NVREG_RINGSZ_RXSHIFT
) + ((TX_RING
-1) << NVREG_RINGSZ_TXSHIFT
),
1817 base
+ NvRegRingSizes
);
1819 /* 5) continue setup */
1820 writel(np
->linkspeed
, base
+ NvRegLinkSpeed
);
1821 writel(NVREG_UNKSETUP3_VAL1
, base
+ NvRegUnknownSetupReg3
);
1822 writel(np
->desc_ver
, base
+ NvRegTxRxControl
);
1824 writel(NVREG_TXRXCTL_BIT1
|np
->desc_ver
, base
+ NvRegTxRxControl
);
1825 reg_delay(dev
, NvRegUnknownSetupReg5
, NVREG_UNKSETUP5_BIT31
, NVREG_UNKSETUP5_BIT31
,
1826 NV_SETUP5_DELAY
, NV_SETUP5_DELAYMAX
,
1827 KERN_INFO
"open: SetupReg5, Bit 31 remained off\n");
1829 writel(0, base
+ NvRegUnknownSetupReg4
);
1830 writel(NVREG_IRQSTAT_MASK
, base
+ NvRegIrqStatus
);
1831 writel(NVREG_MIISTAT_MASK2
, base
+ NvRegMIIStatus
);
1833 /* 6) continue setup */
1834 writel(NVREG_MISC1_FORCE
| NVREG_MISC1_HD
, base
+ NvRegMisc1
);
1835 writel(readl(base
+ NvRegTransmitterStatus
), base
+ NvRegTransmitterStatus
);
1836 writel(NVREG_PFF_ALWAYS
, base
+ NvRegPacketFilterFlags
);
1837 writel(NVREG_OFFLOAD_NORMAL
, base
+ NvRegOffloadConfig
);
1839 writel(readl(base
+ NvRegReceiverStatus
), base
+ NvRegReceiverStatus
);
1840 get_random_bytes(&i
, sizeof(i
));
1841 writel(NVREG_RNDSEED_FORCE
| (i
&NVREG_RNDSEED_MASK
), base
+ NvRegRandomSeed
);
1842 writel(NVREG_UNKSETUP1_VAL
, base
+ NvRegUnknownSetupReg1
);
1843 writel(NVREG_UNKSETUP2_VAL
, base
+ NvRegUnknownSetupReg2
);
1844 writel(NVREG_POLL_DEFAULT
, base
+ NvRegPollingInterval
);
1845 writel(NVREG_UNKSETUP6_VAL
, base
+ NvRegUnknownSetupReg6
);
1846 writel((np
->phyaddr
<< NVREG_ADAPTCTL_PHYSHIFT
)|NVREG_ADAPTCTL_PHYVALID
|NVREG_ADAPTCTL_RUNNING
,
1847 base
+ NvRegAdapterControl
);
1848 writel(NVREG_MIISPEED_BIT8
|NVREG_MIIDELAY
, base
+ NvRegMIISpeed
);
1849 writel(NVREG_UNKSETUP4_VAL
, base
+ NvRegUnknownSetupReg4
);
1850 writel(NVREG_WAKEUPFLAGS_VAL
, base
+ NvRegWakeUpFlags
);
1852 i
= readl(base
+ NvRegPowerState
);
1853 if ( (i
& NVREG_POWERSTATE_POWEREDUP
) == 0)
1854 writel(NVREG_POWERSTATE_POWEREDUP
|i
, base
+ NvRegPowerState
);
1858 writel(readl(base
+ NvRegPowerState
) | NVREG_POWERSTATE_VALID
, base
+ NvRegPowerState
);
1860 writel(0, base
+ NvRegIrqMask
);
1862 writel(NVREG_MIISTAT_MASK2
, base
+ NvRegMIIStatus
);
1863 writel(NVREG_IRQSTAT_MASK
, base
+ NvRegIrqStatus
);
1866 ret
= request_irq(dev
->irq
, &nv_nic_irq
, SA_SHIRQ
, dev
->name
, dev
);
1870 /* ask for interrupts */
1871 writel(np
->irqmask
, base
+ NvRegIrqMask
);
1873 spin_lock_irq(&np
->lock
);
1874 writel(NVREG_MCASTADDRA_FORCE
, base
+ NvRegMulticastAddrA
);
1875 writel(0, base
+ NvRegMulticastAddrB
);
1876 writel(0, base
+ NvRegMulticastMaskA
);
1877 writel(0, base
+ NvRegMulticastMaskB
);
1878 writel(NVREG_PFF_ALWAYS
|NVREG_PFF_MYADDR
, base
+ NvRegPacketFilterFlags
);
1879 /* One manual link speed update: Interrupts are enabled, future link
1880 * speed changes cause interrupts and are handled by nv_link_irq().
1884 miistat
= readl(base
+ NvRegMIIStatus
);
1885 writel(NVREG_MIISTAT_MASK
, base
+ NvRegMIIStatus
);
1886 dprintk(KERN_INFO
"startup: got 0x%08x.\n", miistat
);
1888 ret
= nv_update_linkspeed(dev
);
1891 netif_start_queue(dev
);
1893 netif_carrier_on(dev
);
1895 printk("%s: no link during initialization.\n", dev
->name
);
1896 netif_carrier_off(dev
);
1899 mod_timer(&np
->oom_kick
, jiffies
+ OOM_REFILL
);
1900 spin_unlock_irq(&np
->lock
);
1908 static int nv_close(struct net_device
*dev
)
1910 struct fe_priv
*np
= get_nvpriv(dev
);
1913 spin_lock_irq(&np
->lock
);
1914 np
->in_shutdown
= 1;
1915 spin_unlock_irq(&np
->lock
);
1916 synchronize_irq(dev
->irq
);
1918 del_timer_sync(&np
->oom_kick
);
1919 del_timer_sync(&np
->nic_poll
);
1921 netif_stop_queue(dev
);
1922 spin_lock_irq(&np
->lock
);
1927 /* disable interrupts on the nic or we will lock up */
1928 base
= get_hwbase(dev
);
1929 writel(0, base
+ NvRegIrqMask
);
1931 dprintk(KERN_INFO
"%s: Irqmask is zero again\n", dev
->name
);
1933 spin_unlock_irq(&np
->lock
);
1935 free_irq(dev
->irq
, dev
);
1942 /* FIXME: power down nic */
1947 static int __devinit
nv_probe(struct pci_dev
*pci_dev
, const struct pci_device_id
*id
)
1949 struct net_device
*dev
;
1955 dev
= alloc_etherdev(sizeof(struct fe_priv
));
1960 np
= get_nvpriv(dev
);
1961 np
->pci_dev
= pci_dev
;
1962 spin_lock_init(&np
->lock
);
1963 SET_MODULE_OWNER(dev
);
1964 SET_NETDEV_DEV(dev
, &pci_dev
->dev
);
1966 init_timer(&np
->oom_kick
);
1967 np
->oom_kick
.data
= (unsigned long) dev
;
1968 np
->oom_kick
.function
= &nv_do_rx_refill
; /* timer handler */
1969 init_timer(&np
->nic_poll
);
1970 np
->nic_poll
.data
= (unsigned long) dev
;
1971 np
->nic_poll
.function
= &nv_do_nic_poll
; /* timer handler */
1973 err
= pci_enable_device(pci_dev
);
1975 printk(KERN_INFO
"forcedeth: pci_enable_dev failed (%d) for device %s\n",
1976 err
, pci_name(pci_dev
));
1980 pci_set_master(pci_dev
);
1982 err
= pci_request_regions(pci_dev
, DRV_NAME
);
1988 for (i
= 0; i
< DEVICE_COUNT_RESOURCE
; i
++) {
1989 dprintk(KERN_DEBUG
"%s: resource %d start %p len %ld flags 0x%08lx.\n",
1990 pci_name(pci_dev
), i
, (void*)pci_resource_start(pci_dev
, i
),
1991 pci_resource_len(pci_dev
, i
),
1992 pci_resource_flags(pci_dev
, i
));
1993 if (pci_resource_flags(pci_dev
, i
) & IORESOURCE_MEM
&&
1994 pci_resource_len(pci_dev
, i
) >= NV_PCI_REGSZ
) {
1995 addr
= pci_resource_start(pci_dev
, i
);
1999 if (i
== DEVICE_COUNT_RESOURCE
) {
2000 printk(KERN_INFO
"forcedeth: Couldn't find register window for device %s.\n",
2005 /* handle different descriptor versions */
2006 if (pci_dev
->device
== PCI_DEVICE_ID_NVIDIA_NVENET_1
||
2007 pci_dev
->device
== PCI_DEVICE_ID_NVIDIA_NVENET_2
||
2008 pci_dev
->device
== PCI_DEVICE_ID_NVIDIA_NVENET_3
)
2009 np
->desc_ver
= DESC_VER_1
;
2011 np
->desc_ver
= DESC_VER_2
;
2014 np
->base
= ioremap(addr
, NV_PCI_REGSZ
);
2017 dev
->base_addr
= (unsigned long)np
->base
;
2018 dev
->irq
= pci_dev
->irq
;
2019 np
->rx_ring
= pci_alloc_consistent(pci_dev
, sizeof(struct ring_desc
) * (RX_RING
+ TX_RING
),
2023 np
->tx_ring
= &np
->rx_ring
[RX_RING
];
2025 dev
->open
= nv_open
;
2026 dev
->stop
= nv_close
;
2027 dev
->hard_start_xmit
= nv_start_xmit
;
2028 dev
->get_stats
= nv_get_stats
;
2029 dev
->change_mtu
= nv_change_mtu
;
2030 dev
->set_multicast_list
= nv_set_multicast
;
2031 #ifdef CONFIG_NET_POLL_CONTROLLER
2032 dev
->poll_controller
= nv_poll_controller
;
2034 SET_ETHTOOL_OPS(dev
, &ops
);
2035 dev
->tx_timeout
= nv_tx_timeout
;
2036 dev
->watchdog_timeo
= NV_WATCHDOG_TIMEO
;
2038 pci_set_drvdata(pci_dev
, dev
);
2040 /* read the mac address */
2041 base
= get_hwbase(dev
);
2042 np
->orig_mac
[0] = readl(base
+ NvRegMacAddrA
);
2043 np
->orig_mac
[1] = readl(base
+ NvRegMacAddrB
);
2045 dev
->dev_addr
[0] = (np
->orig_mac
[1] >> 8) & 0xff;
2046 dev
->dev_addr
[1] = (np
->orig_mac
[1] >> 0) & 0xff;
2047 dev
->dev_addr
[2] = (np
->orig_mac
[0] >> 24) & 0xff;
2048 dev
->dev_addr
[3] = (np
->orig_mac
[0] >> 16) & 0xff;
2049 dev
->dev_addr
[4] = (np
->orig_mac
[0] >> 8) & 0xff;
2050 dev
->dev_addr
[5] = (np
->orig_mac
[0] >> 0) & 0xff;
2052 if (!is_valid_ether_addr(dev
->dev_addr
)) {
2054 * Bad mac address. At least one bios sets the mac address
2055 * to 01:23:45:67:89:ab
2057 printk(KERN_ERR
"%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n",
2059 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
2060 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
2061 printk(KERN_ERR
"Please complain to your hardware vendor. Switching to a random MAC.\n");
2062 dev
->dev_addr
[0] = 0x00;
2063 dev
->dev_addr
[1] = 0x00;
2064 dev
->dev_addr
[2] = 0x6c;
2065 get_random_bytes(&dev
->dev_addr
[3], 3);
2068 dprintk(KERN_DEBUG
"%s: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", pci_name(pci_dev
),
2069 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
2070 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
2073 writel(0, base
+ NvRegWakeUpFlags
);
2076 if (np
->desc_ver
== DESC_VER_1
) {
2077 np
->tx_flags
= NV_TX_LASTPACKET
|NV_TX_VALID
;
2078 if (id
->driver_data
& DEV_NEED_LASTPACKET1
)
2079 np
->tx_flags
|= NV_TX_LASTPACKET1
;
2081 np
->tx_flags
= NV_TX2_LASTPACKET
|NV_TX2_VALID
;
2082 if (id
->driver_data
& DEV_NEED_LASTPACKET1
)
2083 np
->tx_flags
|= NV_TX2_LASTPACKET1
;
2085 if (id
->driver_data
& DEV_IRQMASK_1
)
2086 np
->irqmask
= NVREG_IRQMASK_WANTED_1
;
2087 if (id
->driver_data
& DEV_IRQMASK_2
)
2088 np
->irqmask
= NVREG_IRQMASK_WANTED_2
;
2089 if (id
->driver_data
& DEV_NEED_TIMERIRQ
)
2090 np
->irqmask
|= NVREG_IRQ_TIMER
;
2091 if (id
->driver_data
& DEV_NEED_LINKTIMER
) {
2092 dprintk(KERN_INFO
"%s: link timer on.\n", pci_name(pci_dev
));
2093 np
->need_linktimer
= 1;
2094 np
->link_timeout
= jiffies
+ LINK_TIMEOUT
;
2096 dprintk(KERN_INFO
"%s: link timer off.\n", pci_name(pci_dev
));
2097 np
->need_linktimer
= 0;
2100 /* find a suitable phy */
2101 for (i
= 1; i
< 32; i
++) {
2104 spin_lock_irq(&np
->lock
);
2105 id1
= mii_rw(dev
, i
, MII_PHYSID1
, MII_READ
);
2106 spin_unlock_irq(&np
->lock
);
2107 if (id1
< 0 || id1
== 0xffff)
2109 spin_lock_irq(&np
->lock
);
2110 id2
= mii_rw(dev
, i
, MII_PHYSID2
, MII_READ
);
2111 spin_unlock_irq(&np
->lock
);
2112 if (id2
< 0 || id2
== 0xffff)
2115 id1
= (id1
& PHYID1_OUI_MASK
) << PHYID1_OUI_SHFT
;
2116 id2
= (id2
& PHYID2_OUI_MASK
) >> PHYID2_OUI_SHFT
;
2117 dprintk(KERN_DEBUG
"%s: open: Found PHY %04x:%04x at address %d.\n",
2118 pci_name(pci_dev
), id1
, id2
, i
);
2120 np
->phy_oui
= id1
| id2
;
2124 /* PHY in isolate mode? No phy attached and user wants to
2125 * test loopback? Very odd, but can be correct.
2127 printk(KERN_INFO
"%s: open: Could not find a valid PHY.\n",
2136 /* set default link speed settings */
2137 np
->linkspeed
= NVREG_LINKSPEED_FORCE
|NVREG_LINKSPEED_10
;
2141 err
= register_netdev(dev
);
2143 printk(KERN_INFO
"forcedeth: unable to register netdev: %d\n", err
);
2146 printk(KERN_INFO
"%s: forcedeth.c: subsystem: %05x:%04x bound to %s\n",
2147 dev
->name
, pci_dev
->subsystem_vendor
, pci_dev
->subsystem_device
,
2153 pci_free_consistent(np
->pci_dev
, sizeof(struct ring_desc
) * (RX_RING
+ TX_RING
),
2154 np
->rx_ring
, np
->ring_addr
);
2155 pci_set_drvdata(pci_dev
, NULL
);
2157 iounmap(get_hwbase(dev
));
2159 pci_release_regions(pci_dev
);
2161 pci_disable_device(pci_dev
);
2168 static void __devexit
nv_remove(struct pci_dev
*pci_dev
)
2170 struct net_device
*dev
= pci_get_drvdata(pci_dev
);
2171 struct fe_priv
*np
= get_nvpriv(dev
);
2172 u8 __iomem
*base
= get_hwbase(dev
);
2174 unregister_netdev(dev
);
2176 /* special op: write back the misordered MAC address - otherwise
2177 * the next nv_probe would see a wrong address.
2179 writel(np
->orig_mac
[0], base
+ NvRegMacAddrA
);
2180 writel(np
->orig_mac
[1], base
+ NvRegMacAddrB
);
2182 /* free all structures */
2183 pci_free_consistent(np
->pci_dev
, sizeof(struct ring_desc
) * (RX_RING
+ TX_RING
), np
->rx_ring
, np
->ring_addr
);
2184 iounmap(get_hwbase(dev
));
2185 pci_release_regions(pci_dev
);
2186 pci_disable_device(pci_dev
);
2188 pci_set_drvdata(pci_dev
, NULL
);
2191 static struct pci_device_id pci_tbl
[] = {
2192 { /* nForce Ethernet Controller */
2193 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2194 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_1
,
2195 .subvendor
= PCI_ANY_ID
,
2196 .subdevice
= PCI_ANY_ID
,
2197 .driver_data
= DEV_IRQMASK_1
|DEV_NEED_TIMERIRQ
|DEV_NEED_LINKTIMER
,
2199 { /* nForce2 Ethernet Controller */
2200 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2201 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_2
,
2202 .subvendor
= PCI_ANY_ID
,
2203 .subdevice
= PCI_ANY_ID
,
2204 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
|DEV_NEED_LINKTIMER
,
2206 { /* nForce3 Ethernet Controller */
2207 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2208 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_3
,
2209 .subvendor
= PCI_ANY_ID
,
2210 .subdevice
= PCI_ANY_ID
,
2211 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
|DEV_NEED_LINKTIMER
,
2213 { /* nForce3 Ethernet Controller */
2214 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2215 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_4
,
2216 .subvendor
= PCI_ANY_ID
,
2217 .subdevice
= PCI_ANY_ID
,
2218 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
,
2220 { /* nForce3 Ethernet Controller */
2221 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2222 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_5
,
2223 .subvendor
= PCI_ANY_ID
,
2224 .subdevice
= PCI_ANY_ID
,
2225 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
,
2227 { /* nForce3 Ethernet Controller */
2228 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2229 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_6
,
2230 .subvendor
= PCI_ANY_ID
,
2231 .subdevice
= PCI_ANY_ID
,
2232 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
,
2234 { /* nForce3 Ethernet Controller */
2235 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2236 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_7
,
2237 .subvendor
= PCI_ANY_ID
,
2238 .subdevice
= PCI_ANY_ID
,
2239 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
,
2241 { /* CK804 Ethernet Controller */
2242 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2243 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_8
,
2244 .subvendor
= PCI_ANY_ID
,
2245 .subdevice
= PCI_ANY_ID
,
2246 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
,
2248 { /* CK804 Ethernet Controller */
2249 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2250 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_9
,
2251 .subvendor
= PCI_ANY_ID
,
2252 .subdevice
= PCI_ANY_ID
,
2253 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
,
2255 { /* MCP04 Ethernet Controller */
2256 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2257 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_10
,
2258 .subvendor
= PCI_ANY_ID
,
2259 .subdevice
= PCI_ANY_ID
,
2260 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
,
2262 { /* MCP04 Ethernet Controller */
2263 .vendor
= PCI_VENDOR_ID_NVIDIA
,
2264 .device
= PCI_DEVICE_ID_NVIDIA_NVENET_11
,
2265 .subvendor
= PCI_ANY_ID
,
2266 .subdevice
= PCI_ANY_ID
,
2267 .driver_data
= DEV_NEED_LASTPACKET1
|DEV_IRQMASK_2
|DEV_NEED_TIMERIRQ
,
2272 static struct pci_driver driver
= {
2273 .name
= "forcedeth",
2274 .id_table
= pci_tbl
,
2276 .remove
= __devexit_p(nv_remove
),
2280 static int __init
init_nic(void)
2282 printk(KERN_INFO
"forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION
);
2283 return pci_module_init(&driver
);
2286 static void __exit
exit_nic(void)
2288 pci_unregister_driver(&driver
);
2291 module_param(max_interrupt_work
, int, 0);
2292 MODULE_PARM_DESC(max_interrupt_work
, "forcedeth maximum events handled per interrupt");
2294 MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
2295 MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
2296 MODULE_LICENSE("GPL");
2298 MODULE_DEVICE_TABLE(pci
, pci_tbl
);
2300 module_init(init_nic
);
2301 module_exit(exit_nic
);