1*1b8adde7SWilliam Kucharski /**************************************************************************
2*1b8adde7SWilliam Kucharski * forcedeth.c -- Etherboot device driver for the NVIDIA nForce
3*1b8adde7SWilliam Kucharski * media access controllers.
4*1b8adde7SWilliam Kucharski *
5*1b8adde7SWilliam Kucharski * Note: This driver is based on the Linux driver that was based on
6*1b8adde7SWilliam Kucharski * a cleanroom reimplementation which was based on reverse
7*1b8adde7SWilliam Kucharski * engineered documentation written by Carl-Daniel Hailfinger
8*1b8adde7SWilliam Kucharski * and Andrew de Quincey. It's neither supported nor endorsed
9*1b8adde7SWilliam Kucharski * by NVIDIA Corp. Use at your own risk.
10*1b8adde7SWilliam Kucharski *
11*1b8adde7SWilliam Kucharski * Written 2004 by Timothy Legge <tlegge@rogers.com>
12*1b8adde7SWilliam Kucharski *
13*1b8adde7SWilliam Kucharski * This program is free software; you can redistribute it and/or modify
14*1b8adde7SWilliam Kucharski * it under the terms of the GNU General Public License as published by
15*1b8adde7SWilliam Kucharski * the Free Software Foundation; either version 2 of the License, or
16*1b8adde7SWilliam Kucharski * (at your option) any later version.
17*1b8adde7SWilliam Kucharski *
18*1b8adde7SWilliam Kucharski * This program is distributed in the hope that it will be useful,
19*1b8adde7SWilliam Kucharski * but WITHOUT ANY WARRANTY; without even the implied warranty of
20*1b8adde7SWilliam Kucharski * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21*1b8adde7SWilliam Kucharski * GNU General Public License for more details.
22*1b8adde7SWilliam Kucharski *
23*1b8adde7SWilliam Kucharski * You should have received a copy of the GNU General Public License
24*1b8adde7SWilliam Kucharski * along with this program; if not, write to the Free Software
25*1b8adde7SWilliam Kucharski * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*1b8adde7SWilliam Kucharski *
27*1b8adde7SWilliam Kucharski * Portions of this code based on:
28*1b8adde7SWilliam Kucharski * forcedeth: Ethernet driver for NVIDIA nForce media access controllers:
29*1b8adde7SWilliam Kucharski *
30*1b8adde7SWilliam Kucharski * (C) 2003 Manfred Spraul
31*1b8adde7SWilliam Kucharski * See Linux Driver for full information
32*1b8adde7SWilliam Kucharski *
33*1b8adde7SWilliam Kucharski * Linux Driver Version 0.22, 19 Jan 2004
34*1b8adde7SWilliam Kucharski *
35*1b8adde7SWilliam Kucharski *
36*1b8adde7SWilliam Kucharski * REVISION HISTORY:
37*1b8adde7SWilliam Kucharski * ================
38*1b8adde7SWilliam Kucharski * v1.0 01-31-2004 timlegge Initial port of Linux driver
39*1b8adde7SWilliam Kucharski * v1.1 02-03-2004 timlegge Large Clean up, first release
40*1b8adde7SWilliam Kucharski *
41*1b8adde7SWilliam Kucharski * Indent Options: indent -kr -i8
42*1b8adde7SWilliam Kucharski ***************************************************************************/
43*1b8adde7SWilliam Kucharski
44*1b8adde7SWilliam Kucharski /* to get some global routines like printf */
45*1b8adde7SWilliam Kucharski #include "etherboot.h"
46*1b8adde7SWilliam Kucharski /* to get the interface to the body of the program */
47*1b8adde7SWilliam Kucharski #include "nic.h"
48*1b8adde7SWilliam Kucharski /* to get the PCI support functions, if this is a PCI NIC */
49*1b8adde7SWilliam Kucharski #include "pci.h"
50*1b8adde7SWilliam Kucharski /* Include timer support functions */
51*1b8adde7SWilliam Kucharski #include "timer.h"
52*1b8adde7SWilliam Kucharski
53*1b8adde7SWilliam Kucharski #define drv_version "v1.1"
54*1b8adde7SWilliam Kucharski #define drv_date "02-03-2004"
55*1b8adde7SWilliam Kucharski
56*1b8adde7SWilliam Kucharski //#define TFTM_DEBUG
57*1b8adde7SWilliam Kucharski #ifdef TFTM_DEBUG
58*1b8adde7SWilliam Kucharski #define dprintf(x) printf x
59*1b8adde7SWilliam Kucharski #else
60*1b8adde7SWilliam Kucharski #define dprintf(x)
61*1b8adde7SWilliam Kucharski #endif
62*1b8adde7SWilliam Kucharski
63*1b8adde7SWilliam Kucharski typedef unsigned char u8;
64*1b8adde7SWilliam Kucharski typedef signed char s8;
65*1b8adde7SWilliam Kucharski typedef unsigned short u16;
66*1b8adde7SWilliam Kucharski typedef signed short s16;
67*1b8adde7SWilliam Kucharski typedef unsigned int u32;
68*1b8adde7SWilliam Kucharski typedef signed int s32;
69*1b8adde7SWilliam Kucharski
70*1b8adde7SWilliam Kucharski /* Condensed operations for readability. */
71*1b8adde7SWilliam Kucharski #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
72*1b8adde7SWilliam Kucharski #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
73*1b8adde7SWilliam Kucharski
74*1b8adde7SWilliam Kucharski unsigned long BASE;
75*1b8adde7SWilliam Kucharski /* NIC specific static variables go here */
76*1b8adde7SWilliam Kucharski
77*1b8adde7SWilliam Kucharski
78*1b8adde7SWilliam Kucharski /*
79*1b8adde7SWilliam Kucharski * Hardware access:
80*1b8adde7SWilliam Kucharski */
81*1b8adde7SWilliam Kucharski
82*1b8adde7SWilliam Kucharski #define DEV_NEED_LASTPACKET1 0x0001
83*1b8adde7SWilliam Kucharski #define DEV_IRQMASK_1 0x0002
84*1b8adde7SWilliam Kucharski #define DEV_IRQMASK_2 0x0004
85*1b8adde7SWilliam Kucharski #define DEV_NEED_TIMERIRQ 0x0008
86*1b8adde7SWilliam Kucharski
87*1b8adde7SWilliam Kucharski enum {
88*1b8adde7SWilliam Kucharski NvRegIrqStatus = 0x000,
89*1b8adde7SWilliam Kucharski #define NVREG_IRQSTAT_MIIEVENT 0040
90*1b8adde7SWilliam Kucharski #define NVREG_IRQSTAT_MASK 0x1ff
91*1b8adde7SWilliam Kucharski NvRegIrqMask = 0x004,
92*1b8adde7SWilliam Kucharski #define NVREG_IRQ_RX 0x0002
93*1b8adde7SWilliam Kucharski #define NVREG_IRQ_RX_NOBUF 0x0004
94*1b8adde7SWilliam Kucharski #define NVREG_IRQ_TX_ERR 0x0008
95*1b8adde7SWilliam Kucharski #define NVREG_IRQ_TX2 0x0010
96*1b8adde7SWilliam Kucharski #define NVREG_IRQ_TIMER 0x0020
97*1b8adde7SWilliam Kucharski #define NVREG_IRQ_LINK 0x0040
98*1b8adde7SWilliam Kucharski #define NVREG_IRQ_TX1 0x0100
99*1b8adde7SWilliam Kucharski #define NVREG_IRQMASK_WANTED_1 0x005f
100*1b8adde7SWilliam Kucharski #define NVREG_IRQMASK_WANTED_2 0x0147
101*1b8adde7SWilliam Kucharski #define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR|NVREG_IRQ_TX2|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_TX1))
102*1b8adde7SWilliam Kucharski
103*1b8adde7SWilliam Kucharski NvRegUnknownSetupReg6 = 0x008,
104*1b8adde7SWilliam Kucharski #define NVREG_UNKSETUP6_VAL 3
105*1b8adde7SWilliam Kucharski
106*1b8adde7SWilliam Kucharski /*
107*1b8adde7SWilliam Kucharski * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
108*1b8adde7SWilliam Kucharski * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
109*1b8adde7SWilliam Kucharski */
110*1b8adde7SWilliam Kucharski NvRegPollingInterval = 0x00c,
111*1b8adde7SWilliam Kucharski #define NVREG_POLL_DEFAULT 970
112*1b8adde7SWilliam Kucharski NvRegMisc1 = 0x080,
113*1b8adde7SWilliam Kucharski #define NVREG_MISC1_HD 0x02
114*1b8adde7SWilliam Kucharski #define NVREG_MISC1_FORCE 0x3b0f3c
115*1b8adde7SWilliam Kucharski
116*1b8adde7SWilliam Kucharski NvRegTransmitterControl = 0x084,
117*1b8adde7SWilliam Kucharski #define NVREG_XMITCTL_START 0x01
118*1b8adde7SWilliam Kucharski NvRegTransmitterStatus = 0x088,
119*1b8adde7SWilliam Kucharski #define NVREG_XMITSTAT_BUSY 0x01
120*1b8adde7SWilliam Kucharski
121*1b8adde7SWilliam Kucharski NvRegPacketFilterFlags = 0x8c,
122*1b8adde7SWilliam Kucharski #define NVREG_PFF_ALWAYS 0x7F0008
123*1b8adde7SWilliam Kucharski #define NVREG_PFF_PROMISC 0x80
124*1b8adde7SWilliam Kucharski #define NVREG_PFF_MYADDR 0x20
125*1b8adde7SWilliam Kucharski
126*1b8adde7SWilliam Kucharski NvRegOffloadConfig = 0x90,
127*1b8adde7SWilliam Kucharski #define NVREG_OFFLOAD_HOMEPHY 0x601
128*1b8adde7SWilliam Kucharski #define NVREG_OFFLOAD_NORMAL 0x5ee
129*1b8adde7SWilliam Kucharski NvRegReceiverControl = 0x094,
130*1b8adde7SWilliam Kucharski #define NVREG_RCVCTL_START 0x01
131*1b8adde7SWilliam Kucharski NvRegReceiverStatus = 0x98,
132*1b8adde7SWilliam Kucharski #define NVREG_RCVSTAT_BUSY 0x01
133*1b8adde7SWilliam Kucharski
134*1b8adde7SWilliam Kucharski NvRegRandomSeed = 0x9c,
135*1b8adde7SWilliam Kucharski #define NVREG_RNDSEED_MASK 0x00ff
136*1b8adde7SWilliam Kucharski #define NVREG_RNDSEED_FORCE 0x7f00
137*1b8adde7SWilliam Kucharski
138*1b8adde7SWilliam Kucharski NvRegUnknownSetupReg1 = 0xA0,
139*1b8adde7SWilliam Kucharski #define NVREG_UNKSETUP1_VAL 0x16070f
140*1b8adde7SWilliam Kucharski NvRegUnknownSetupReg2 = 0xA4,
141*1b8adde7SWilliam Kucharski #define NVREG_UNKSETUP2_VAL 0x16
142*1b8adde7SWilliam Kucharski NvRegMacAddrA = 0xA8,
143*1b8adde7SWilliam Kucharski NvRegMacAddrB = 0xAC,
144*1b8adde7SWilliam Kucharski NvRegMulticastAddrA = 0xB0,
145*1b8adde7SWilliam Kucharski #define NVREG_MCASTADDRA_FORCE 0x01
146*1b8adde7SWilliam Kucharski NvRegMulticastAddrB = 0xB4,
147*1b8adde7SWilliam Kucharski NvRegMulticastMaskA = 0xB8,
148*1b8adde7SWilliam Kucharski NvRegMulticastMaskB = 0xBC,
149*1b8adde7SWilliam Kucharski
150*1b8adde7SWilliam Kucharski NvRegTxRingPhysAddr = 0x100,
151*1b8adde7SWilliam Kucharski NvRegRxRingPhysAddr = 0x104,
152*1b8adde7SWilliam Kucharski NvRegRingSizes = 0x108,
153*1b8adde7SWilliam Kucharski #define NVREG_RINGSZ_TXSHIFT 0
154*1b8adde7SWilliam Kucharski #define NVREG_RINGSZ_RXSHIFT 16
155*1b8adde7SWilliam Kucharski NvRegUnknownTransmitterReg = 0x10c,
156*1b8adde7SWilliam Kucharski NvRegLinkSpeed = 0x110,
157*1b8adde7SWilliam Kucharski #define NVREG_LINKSPEED_FORCE 0x10000
158*1b8adde7SWilliam Kucharski #define NVREG_LINKSPEED_10 10
159*1b8adde7SWilliam Kucharski #define NVREG_LINKSPEED_100 100
160*1b8adde7SWilliam Kucharski #define NVREG_LINKSPEED_1000 1000
161*1b8adde7SWilliam Kucharski NvRegUnknownSetupReg5 = 0x130,
162*1b8adde7SWilliam Kucharski #define NVREG_UNKSETUP5_BIT31 (1<<31)
163*1b8adde7SWilliam Kucharski NvRegUnknownSetupReg3 = 0x134,
164*1b8adde7SWilliam Kucharski #define NVREG_UNKSETUP3_VAL1 0x200010
165*1b8adde7SWilliam Kucharski NvRegTxRxControl = 0x144,
166*1b8adde7SWilliam Kucharski #define NVREG_TXRXCTL_KICK 0x0001
167*1b8adde7SWilliam Kucharski #define NVREG_TXRXCTL_BIT1 0x0002
168*1b8adde7SWilliam Kucharski #define NVREG_TXRXCTL_BIT2 0x0004
169*1b8adde7SWilliam Kucharski #define NVREG_TXRXCTL_IDLE 0x0008
170*1b8adde7SWilliam Kucharski #define NVREG_TXRXCTL_RESET 0x0010
171*1b8adde7SWilliam Kucharski NvRegMIIStatus = 0x180,
172*1b8adde7SWilliam Kucharski #define NVREG_MIISTAT_ERROR 0x0001
173*1b8adde7SWilliam Kucharski #define NVREG_MIISTAT_LINKCHANGE 0x0008
174*1b8adde7SWilliam Kucharski #define NVREG_MIISTAT_MASK 0x000f
175*1b8adde7SWilliam Kucharski #define NVREG_MIISTAT_MASK2 0x000f
176*1b8adde7SWilliam Kucharski NvRegUnknownSetupReg4 = 0x184,
177*1b8adde7SWilliam Kucharski #define NVREG_UNKSETUP4_VAL 8
178*1b8adde7SWilliam Kucharski
179*1b8adde7SWilliam Kucharski NvRegAdapterControl = 0x188,
180*1b8adde7SWilliam Kucharski #define NVREG_ADAPTCTL_START 0x02
181*1b8adde7SWilliam Kucharski #define NVREG_ADAPTCTL_LINKUP 0x04
182*1b8adde7SWilliam Kucharski #define NVREG_ADAPTCTL_PHYVALID 0x4000
183*1b8adde7SWilliam Kucharski #define NVREG_ADAPTCTL_RUNNING 0x100000
184*1b8adde7SWilliam Kucharski #define NVREG_ADAPTCTL_PHYSHIFT 24
185*1b8adde7SWilliam Kucharski NvRegMIISpeed = 0x18c,
186*1b8adde7SWilliam Kucharski #define NVREG_MIISPEED_BIT8 (1<<8)
187*1b8adde7SWilliam Kucharski #define NVREG_MIIDELAY 5
188*1b8adde7SWilliam Kucharski NvRegMIIControl = 0x190,
189*1b8adde7SWilliam Kucharski #define NVREG_MIICTL_INUSE 0x10000
190*1b8adde7SWilliam Kucharski #define NVREG_MIICTL_WRITE 0x08000
191*1b8adde7SWilliam Kucharski #define NVREG_MIICTL_ADDRSHIFT 5
192*1b8adde7SWilliam Kucharski NvRegMIIData = 0x194,
193*1b8adde7SWilliam Kucharski NvRegWakeUpFlags = 0x200,
194*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_VAL 0x7770
195*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
196*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
197*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_D3SHIFT 12
198*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_D2SHIFT 8
199*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_D1SHIFT 4
200*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_D0SHIFT 0
201*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
202*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
203*1b8adde7SWilliam Kucharski #define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
204*1b8adde7SWilliam Kucharski
205*1b8adde7SWilliam Kucharski NvRegPatternCRC = 0x204,
206*1b8adde7SWilliam Kucharski NvRegPatternMask = 0x208,
207*1b8adde7SWilliam Kucharski NvRegPowerCap = 0x268,
208*1b8adde7SWilliam Kucharski #define NVREG_POWERCAP_D3SUPP (1<<30)
209*1b8adde7SWilliam Kucharski #define NVREG_POWERCAP_D2SUPP (1<<26)
210*1b8adde7SWilliam Kucharski #define NVREG_POWERCAP_D1SUPP (1<<25)
211*1b8adde7SWilliam Kucharski NvRegPowerState = 0x26c,
212*1b8adde7SWilliam Kucharski #define NVREG_POWERSTATE_POWEREDUP 0x8000
213*1b8adde7SWilliam Kucharski #define NVREG_POWERSTATE_VALID 0x0100
214*1b8adde7SWilliam Kucharski #define NVREG_POWERSTATE_MASK 0x0003
215*1b8adde7SWilliam Kucharski #define NVREG_POWERSTATE_D0 0x0000
216*1b8adde7SWilliam Kucharski #define NVREG_POWERSTATE_D1 0x0001
217*1b8adde7SWilliam Kucharski #define NVREG_POWERSTATE_D2 0x0002
218*1b8adde7SWilliam Kucharski #define NVREG_POWERSTATE_D3 0x0003
219*1b8adde7SWilliam Kucharski };
220*1b8adde7SWilliam Kucharski
221*1b8adde7SWilliam Kucharski
222*1b8adde7SWilliam Kucharski
223*1b8adde7SWilliam Kucharski #define NV_TX_LASTPACKET (1<<0)
224*1b8adde7SWilliam Kucharski #define NV_TX_RETRYERROR (1<<3)
225*1b8adde7SWilliam Kucharski #define NV_TX_LASTPACKET1 (1<<8)
226*1b8adde7SWilliam Kucharski #define NV_TX_DEFERRED (1<<10)
227*1b8adde7SWilliam Kucharski #define NV_TX_CARRIERLOST (1<<11)
228*1b8adde7SWilliam Kucharski #define NV_TX_LATECOLLISION (1<<12)
229*1b8adde7SWilliam Kucharski #define NV_TX_UNDERFLOW (1<<13)
230*1b8adde7SWilliam Kucharski #define NV_TX_ERROR (1<<14)
231*1b8adde7SWilliam Kucharski #define NV_TX_VALID (1<<15)
232*1b8adde7SWilliam Kucharski
233*1b8adde7SWilliam Kucharski #define NV_RX_DESCRIPTORVALID (1<<0)
234*1b8adde7SWilliam Kucharski #define NV_RX_MISSEDFRAME (1<<1)
235*1b8adde7SWilliam Kucharski #define NV_RX_SUBSTRACT1 (1<<3)
236*1b8adde7SWilliam Kucharski #define NV_RX_ERROR1 (1<<7)
237*1b8adde7SWilliam Kucharski #define NV_RX_ERROR2 (1<<8)
238*1b8adde7SWilliam Kucharski #define NV_RX_ERROR3 (1<<9)
239*1b8adde7SWilliam Kucharski #define NV_RX_ERROR4 (1<<10)
240*1b8adde7SWilliam Kucharski #define NV_RX_CRCERR (1<<11)
241*1b8adde7SWilliam Kucharski #define NV_RX_OVERFLOW (1<<12)
242*1b8adde7SWilliam Kucharski #define NV_RX_FRAMINGERR (1<<13)
243*1b8adde7SWilliam Kucharski #define NV_RX_ERROR (1<<14)
244*1b8adde7SWilliam Kucharski #define NV_RX_AVAIL (1<<15)
245*1b8adde7SWilliam Kucharski
246*1b8adde7SWilliam Kucharski /* Miscelaneous hardware related defines: */
247*1b8adde7SWilliam Kucharski #define NV_PCI_REGSZ 0x270
248*1b8adde7SWilliam Kucharski
249*1b8adde7SWilliam Kucharski /* various timeout delays: all in usec */
250*1b8adde7SWilliam Kucharski #define NV_TXRX_RESET_DELAY 4
251*1b8adde7SWilliam Kucharski #define NV_TXSTOP_DELAY1 10
252*1b8adde7SWilliam Kucharski #define NV_TXSTOP_DELAY1MAX 500000
253*1b8adde7SWilliam Kucharski #define NV_TXSTOP_DELAY2 100
254*1b8adde7SWilliam Kucharski #define NV_RXSTOP_DELAY1 10
255*1b8adde7SWilliam Kucharski #define NV_RXSTOP_DELAY1MAX 500000
256*1b8adde7SWilliam Kucharski #define NV_RXSTOP_DELAY2 100
257*1b8adde7SWilliam Kucharski #define NV_SETUP5_DELAY 5
258*1b8adde7SWilliam Kucharski #define NV_SETUP5_DELAYMAX 50000
259*1b8adde7SWilliam Kucharski #define NV_POWERUP_DELAY 5
260*1b8adde7SWilliam Kucharski #define NV_POWERUP_DELAYMAX 5000
261*1b8adde7SWilliam Kucharski #define NV_MIIBUSY_DELAY 50
262*1b8adde7SWilliam Kucharski #define NV_MIIPHY_DELAY 10
263*1b8adde7SWilliam Kucharski #define NV_MIIPHY_DELAYMAX 10000
264*1b8adde7SWilliam Kucharski
265*1b8adde7SWilliam Kucharski #define NV_WAKEUPPATTERNS 5
266*1b8adde7SWilliam Kucharski #define NV_WAKEUPMASKENTRIES 4
267*1b8adde7SWilliam Kucharski
268*1b8adde7SWilliam Kucharski /* General driver defaults */
269*1b8adde7SWilliam Kucharski #define NV_WATCHDOG_TIMEO (2*HZ)
270*1b8adde7SWilliam Kucharski #define DEFAULT_MTU 1500 /* also maximum supported, at least for now */
271*1b8adde7SWilliam Kucharski
272*1b8adde7SWilliam Kucharski #define RX_RING 4
273*1b8adde7SWilliam Kucharski #define TX_RING 2
274*1b8adde7SWilliam Kucharski /* limited to 1 packet until we understand NV_TX_LASTPACKET */
275*1b8adde7SWilliam Kucharski #define TX_LIMIT_STOP 10
276*1b8adde7SWilliam Kucharski #define TX_LIMIT_START 5
277*1b8adde7SWilliam Kucharski
278*1b8adde7SWilliam Kucharski /* rx/tx mac addr + type + vlan + align + slack*/
279*1b8adde7SWilliam Kucharski #define RX_NIC_BUFSIZE (DEFAULT_MTU + 64)
280*1b8adde7SWilliam Kucharski /* even more slack */
281*1b8adde7SWilliam Kucharski #define RX_ALLOC_BUFSIZE (DEFAULT_MTU + 128)
282*1b8adde7SWilliam Kucharski
283*1b8adde7SWilliam Kucharski #define OOM_REFILL (1+HZ/20)
284*1b8adde7SWilliam Kucharski #define POLL_WAIT (1+HZ/100)
285*1b8adde7SWilliam Kucharski
286*1b8adde7SWilliam Kucharski struct ring_desc {
287*1b8adde7SWilliam Kucharski u32 PacketBuffer;
288*1b8adde7SWilliam Kucharski u16 Length;
289*1b8adde7SWilliam Kucharski u16 Flags;
290*1b8adde7SWilliam Kucharski };
291*1b8adde7SWilliam Kucharski
292*1b8adde7SWilliam Kucharski
293*1b8adde7SWilliam Kucharski /* Define the TX Descriptor */
294*1b8adde7SWilliam Kucharski static struct ring_desc tx_ring[TX_RING];
295*1b8adde7SWilliam Kucharski
296*1b8adde7SWilliam Kucharski /* Create a static buffer of size RX_BUF_SZ for each
297*1b8adde7SWilliam Kucharski TX Descriptor. All descriptors point to a
298*1b8adde7SWilliam Kucharski part of this buffer */
299*1b8adde7SWilliam Kucharski static unsigned char txb[TX_RING * RX_NIC_BUFSIZE];
300*1b8adde7SWilliam Kucharski
301*1b8adde7SWilliam Kucharski /* Define the TX Descriptor */
302*1b8adde7SWilliam Kucharski static struct ring_desc rx_ring[RX_RING];
303*1b8adde7SWilliam Kucharski
304*1b8adde7SWilliam Kucharski /* Create a static buffer of size RX_BUF_SZ for each
305*1b8adde7SWilliam Kucharski RX Descriptor All descriptors point to a
306*1b8adde7SWilliam Kucharski part of this buffer */
307*1b8adde7SWilliam Kucharski static unsigned char rxb[RX_RING * RX_NIC_BUFSIZE];
308*1b8adde7SWilliam Kucharski
309*1b8adde7SWilliam Kucharski /* Private Storage for the NIC */
310*1b8adde7SWilliam Kucharski struct forcedeth_private {
311*1b8adde7SWilliam Kucharski /* General data:
312*1b8adde7SWilliam Kucharski * Locking: spin_lock(&np->lock); */
313*1b8adde7SWilliam Kucharski int in_shutdown;
314*1b8adde7SWilliam Kucharski u32 linkspeed;
315*1b8adde7SWilliam Kucharski int duplex;
316*1b8adde7SWilliam Kucharski int phyaddr;
317*1b8adde7SWilliam Kucharski
318*1b8adde7SWilliam Kucharski /* General data: RO fields */
319*1b8adde7SWilliam Kucharski u8 *ring_addr;
320*1b8adde7SWilliam Kucharski u32 orig_mac[2];
321*1b8adde7SWilliam Kucharski u32 irqmask;
322*1b8adde7SWilliam Kucharski /* rx specific fields.
323*1b8adde7SWilliam Kucharski * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
324*1b8adde7SWilliam Kucharski */
325*1b8adde7SWilliam Kucharski struct ring_desc *rx_ring;
326*1b8adde7SWilliam Kucharski unsigned int cur_rx, refill_rx;
327*1b8adde7SWilliam Kucharski struct sk_buff *rx_skbuff[RX_RING];
328*1b8adde7SWilliam Kucharski u32 rx_dma[RX_RING];
329*1b8adde7SWilliam Kucharski unsigned int rx_buf_sz;
330*1b8adde7SWilliam Kucharski
331*1b8adde7SWilliam Kucharski /*
332*1b8adde7SWilliam Kucharski * tx specific fields.
333*1b8adde7SWilliam Kucharski */
334*1b8adde7SWilliam Kucharski struct ring_desc *tx_ring;
335*1b8adde7SWilliam Kucharski unsigned int next_tx, nic_tx;
336*1b8adde7SWilliam Kucharski struct sk_buff *tx_skbuff[TX_RING];
337*1b8adde7SWilliam Kucharski u32 tx_dma[TX_RING];
338*1b8adde7SWilliam Kucharski u16 tx_flags;
339*1b8adde7SWilliam Kucharski } npx;
340*1b8adde7SWilliam Kucharski
341*1b8adde7SWilliam Kucharski static struct forcedeth_private *np;
342*1b8adde7SWilliam Kucharski
pci_push(u8 * base)343*1b8adde7SWilliam Kucharski static inline void pci_push(u8 * base)
344*1b8adde7SWilliam Kucharski {
345*1b8adde7SWilliam Kucharski /* force out pending posted writes */
346*1b8adde7SWilliam Kucharski readl(base);
347*1b8adde7SWilliam Kucharski }
reg_delay(int offset,u32 mask,u32 target,int delay,int delaymax,const char * msg)348*1b8adde7SWilliam Kucharski static int reg_delay(int offset, u32 mask,
349*1b8adde7SWilliam Kucharski u32 target, int delay, int delaymax, const char *msg)
350*1b8adde7SWilliam Kucharski {
351*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
352*1b8adde7SWilliam Kucharski
353*1b8adde7SWilliam Kucharski pci_push(base);
354*1b8adde7SWilliam Kucharski do {
355*1b8adde7SWilliam Kucharski udelay(delay);
356*1b8adde7SWilliam Kucharski delaymax -= delay;
357*1b8adde7SWilliam Kucharski if (delaymax < 0) {
358*1b8adde7SWilliam Kucharski if (msg)
359*1b8adde7SWilliam Kucharski printf(msg);
360*1b8adde7SWilliam Kucharski return 1;
361*1b8adde7SWilliam Kucharski }
362*1b8adde7SWilliam Kucharski } while ((readl(base + offset) & mask) != target);
363*1b8adde7SWilliam Kucharski return 0;
364*1b8adde7SWilliam Kucharski }
365*1b8adde7SWilliam Kucharski
366*1b8adde7SWilliam Kucharski #define MII_READ (-1)
367*1b8adde7SWilliam Kucharski #define MII_PHYSID1 0x02 /* PHYS ID 1 */
368*1b8adde7SWilliam Kucharski #define MII_PHYSID2 0x03 /* PHYS ID 2 */
369*1b8adde7SWilliam Kucharski #define MII_BMCR 0x00 /* Basic mode control register */
370*1b8adde7SWilliam Kucharski #define MII_BMSR 0x01 /* Basic mode status register */
371*1b8adde7SWilliam Kucharski #define MII_ADVERTISE 0x04 /* Advertisement control reg */
372*1b8adde7SWilliam Kucharski #define MII_LPA 0x05 /* Link partner ability reg */
373*1b8adde7SWilliam Kucharski
374*1b8adde7SWilliam Kucharski #define BMSR_ANEGCOMPLETE 0x0020 /* Auto-negotiation complete */
375*1b8adde7SWilliam Kucharski
376*1b8adde7SWilliam Kucharski /* Link partner ability register. */
377*1b8adde7SWilliam Kucharski #define LPA_SLCT 0x001f /* Same as advertise selector */
378*1b8adde7SWilliam Kucharski #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
379*1b8adde7SWilliam Kucharski #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
380*1b8adde7SWilliam Kucharski #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
381*1b8adde7SWilliam Kucharski #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
382*1b8adde7SWilliam Kucharski #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
383*1b8adde7SWilliam Kucharski #define LPA_RESV 0x1c00 /* Unused... */
384*1b8adde7SWilliam Kucharski #define LPA_RFAULT 0x2000 /* Link partner faulted */
385*1b8adde7SWilliam Kucharski #define LPA_LPACK 0x4000 /* Link partner acked us */
386*1b8adde7SWilliam Kucharski #define LPA_NPAGE 0x8000 /* Next page bit */
387*1b8adde7SWilliam Kucharski
388*1b8adde7SWilliam Kucharski /* mii_rw: read/write a register on the PHY.
389*1b8adde7SWilliam Kucharski *
390*1b8adde7SWilliam Kucharski * Caller must guarantee serialization
391*1b8adde7SWilliam Kucharski */
mii_rw(struct nic * nic __unused,int addr,int miireg,int value)392*1b8adde7SWilliam Kucharski static int mii_rw(struct nic *nic __unused, int addr, int miireg,
393*1b8adde7SWilliam Kucharski int value)
394*1b8adde7SWilliam Kucharski {
395*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
396*1b8adde7SWilliam Kucharski int was_running;
397*1b8adde7SWilliam Kucharski u32 reg;
398*1b8adde7SWilliam Kucharski int retval;
399*1b8adde7SWilliam Kucharski
400*1b8adde7SWilliam Kucharski writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
401*1b8adde7SWilliam Kucharski was_running = 0;
402*1b8adde7SWilliam Kucharski reg = readl(base + NvRegAdapterControl);
403*1b8adde7SWilliam Kucharski if (reg & NVREG_ADAPTCTL_RUNNING) {
404*1b8adde7SWilliam Kucharski was_running = 1;
405*1b8adde7SWilliam Kucharski writel(reg & ~NVREG_ADAPTCTL_RUNNING,
406*1b8adde7SWilliam Kucharski base + NvRegAdapterControl);
407*1b8adde7SWilliam Kucharski }
408*1b8adde7SWilliam Kucharski reg = readl(base + NvRegMIIControl);
409*1b8adde7SWilliam Kucharski if (reg & NVREG_MIICTL_INUSE) {
410*1b8adde7SWilliam Kucharski writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
411*1b8adde7SWilliam Kucharski udelay(NV_MIIBUSY_DELAY);
412*1b8adde7SWilliam Kucharski }
413*1b8adde7SWilliam Kucharski
414*1b8adde7SWilliam Kucharski reg =
415*1b8adde7SWilliam Kucharski NVREG_MIICTL_INUSE | (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
416*1b8adde7SWilliam Kucharski if (value != MII_READ) {
417*1b8adde7SWilliam Kucharski writel(value, base + NvRegMIIData);
418*1b8adde7SWilliam Kucharski reg |= NVREG_MIICTL_WRITE;
419*1b8adde7SWilliam Kucharski }
420*1b8adde7SWilliam Kucharski writel(reg, base + NvRegMIIControl);
421*1b8adde7SWilliam Kucharski
422*1b8adde7SWilliam Kucharski if (reg_delay(NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
423*1b8adde7SWilliam Kucharski NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
424*1b8adde7SWilliam Kucharski dprintf(("mii_rw of reg %d at PHY %d timed out.\n",
425*1b8adde7SWilliam Kucharski miireg, addr));
426*1b8adde7SWilliam Kucharski retval = -1;
427*1b8adde7SWilliam Kucharski } else if (value != MII_READ) {
428*1b8adde7SWilliam Kucharski /* it was a write operation - fewer failures are detectable */
429*1b8adde7SWilliam Kucharski dprintf(("mii_rw wrote 0x%x to reg %d at PHY %d\n",
430*1b8adde7SWilliam Kucharski value, miireg, addr));
431*1b8adde7SWilliam Kucharski retval = 0;
432*1b8adde7SWilliam Kucharski } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
433*1b8adde7SWilliam Kucharski dprintf(("mii_rw of reg %d at PHY %d failed.\n",
434*1b8adde7SWilliam Kucharski miireg, addr));
435*1b8adde7SWilliam Kucharski retval = -1;
436*1b8adde7SWilliam Kucharski } else {
437*1b8adde7SWilliam Kucharski /* FIXME: why is that required? */
438*1b8adde7SWilliam Kucharski udelay(50);
439*1b8adde7SWilliam Kucharski retval = readl(base + NvRegMIIData);
440*1b8adde7SWilliam Kucharski dprintf(("mii_rw read from reg %d at PHY %d: 0x%x.\n",
441*1b8adde7SWilliam Kucharski miireg, addr, retval));
442*1b8adde7SWilliam Kucharski }
443*1b8adde7SWilliam Kucharski if (was_running) {
444*1b8adde7SWilliam Kucharski reg = readl(base + NvRegAdapterControl);
445*1b8adde7SWilliam Kucharski writel(reg | NVREG_ADAPTCTL_RUNNING,
446*1b8adde7SWilliam Kucharski base + NvRegAdapterControl);
447*1b8adde7SWilliam Kucharski }
448*1b8adde7SWilliam Kucharski return retval;
449*1b8adde7SWilliam Kucharski }
450*1b8adde7SWilliam Kucharski
start_rx(struct nic * nic __unused)451*1b8adde7SWilliam Kucharski static void start_rx(struct nic *nic __unused)
452*1b8adde7SWilliam Kucharski {
453*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
454*1b8adde7SWilliam Kucharski
455*1b8adde7SWilliam Kucharski dprintf(("start_rx\n"));
456*1b8adde7SWilliam Kucharski /* Already running? Stop it. */
457*1b8adde7SWilliam Kucharski if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
458*1b8adde7SWilliam Kucharski writel(0, base + NvRegReceiverControl);
459*1b8adde7SWilliam Kucharski pci_push(base);
460*1b8adde7SWilliam Kucharski }
461*1b8adde7SWilliam Kucharski writel(np->linkspeed, base + NvRegLinkSpeed);
462*1b8adde7SWilliam Kucharski pci_push(base);
463*1b8adde7SWilliam Kucharski writel(NVREG_RCVCTL_START, base + NvRegReceiverControl);
464*1b8adde7SWilliam Kucharski pci_push(base);
465*1b8adde7SWilliam Kucharski }
466*1b8adde7SWilliam Kucharski
stop_rx(void)467*1b8adde7SWilliam Kucharski static void stop_rx(void)
468*1b8adde7SWilliam Kucharski {
469*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
470*1b8adde7SWilliam Kucharski
471*1b8adde7SWilliam Kucharski dprintf(("stop_rx\n"));
472*1b8adde7SWilliam Kucharski writel(0, base + NvRegReceiverControl);
473*1b8adde7SWilliam Kucharski reg_delay(NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
474*1b8adde7SWilliam Kucharski NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
475*1b8adde7SWilliam Kucharski "stop_rx: ReceiverStatus remained busy");
476*1b8adde7SWilliam Kucharski
477*1b8adde7SWilliam Kucharski udelay(NV_RXSTOP_DELAY2);
478*1b8adde7SWilliam Kucharski writel(0, base + NvRegLinkSpeed);
479*1b8adde7SWilliam Kucharski }
480*1b8adde7SWilliam Kucharski
start_tx(struct nic * nic __unused)481*1b8adde7SWilliam Kucharski static void start_tx(struct nic *nic __unused)
482*1b8adde7SWilliam Kucharski {
483*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
484*1b8adde7SWilliam Kucharski
485*1b8adde7SWilliam Kucharski dprintf(("start_tx\n"));
486*1b8adde7SWilliam Kucharski writel(NVREG_XMITCTL_START, base + NvRegTransmitterControl);
487*1b8adde7SWilliam Kucharski pci_push(base);
488*1b8adde7SWilliam Kucharski }
489*1b8adde7SWilliam Kucharski
stop_tx(void)490*1b8adde7SWilliam Kucharski static void stop_tx(void)
491*1b8adde7SWilliam Kucharski {
492*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
493*1b8adde7SWilliam Kucharski
494*1b8adde7SWilliam Kucharski dprintf(("stop_tx\n"));
495*1b8adde7SWilliam Kucharski writel(0, base + NvRegTransmitterControl);
496*1b8adde7SWilliam Kucharski reg_delay(NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
497*1b8adde7SWilliam Kucharski NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
498*1b8adde7SWilliam Kucharski "stop_tx: TransmitterStatus remained busy");
499*1b8adde7SWilliam Kucharski
500*1b8adde7SWilliam Kucharski udelay(NV_TXSTOP_DELAY2);
501*1b8adde7SWilliam Kucharski writel(0, base + NvRegUnknownTransmitterReg);
502*1b8adde7SWilliam Kucharski }
503*1b8adde7SWilliam Kucharski
504*1b8adde7SWilliam Kucharski
txrx_reset(struct nic * nic __unused)505*1b8adde7SWilliam Kucharski static void txrx_reset(struct nic *nic __unused)
506*1b8adde7SWilliam Kucharski {
507*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
508*1b8adde7SWilliam Kucharski
509*1b8adde7SWilliam Kucharski dprintf(("txrx_reset\n"));
510*1b8adde7SWilliam Kucharski writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET,
511*1b8adde7SWilliam Kucharski base + NvRegTxRxControl);
512*1b8adde7SWilliam Kucharski pci_push(base);
513*1b8adde7SWilliam Kucharski udelay(NV_TXRX_RESET_DELAY);
514*1b8adde7SWilliam Kucharski writel(NVREG_TXRXCTL_BIT2, base + NvRegTxRxControl);
515*1b8adde7SWilliam Kucharski pci_push(base);
516*1b8adde7SWilliam Kucharski }
517*1b8adde7SWilliam Kucharski
518*1b8adde7SWilliam Kucharski /*
519*1b8adde7SWilliam Kucharski * alloc_rx: fill rx ring entries.
520*1b8adde7SWilliam Kucharski * Return 1 if the allocations for the skbs failed and the
521*1b8adde7SWilliam Kucharski * rx engine is without Available descriptors
522*1b8adde7SWilliam Kucharski */
alloc_rx(struct nic * nic __unused)523*1b8adde7SWilliam Kucharski static int alloc_rx(struct nic *nic __unused)
524*1b8adde7SWilliam Kucharski {
525*1b8adde7SWilliam Kucharski unsigned int refill_rx = np->refill_rx;
526*1b8adde7SWilliam Kucharski int i;
527*1b8adde7SWilliam Kucharski //while (np->cur_rx != refill_rx) {
528*1b8adde7SWilliam Kucharski for (i = 0; i < RX_RING; i++) {
529*1b8adde7SWilliam Kucharski //int nr = refill_rx % RX_RING;
530*1b8adde7SWilliam Kucharski rx_ring[i].PacketBuffer =
531*1b8adde7SWilliam Kucharski virt_to_le32desc(&rxb[i * RX_NIC_BUFSIZE]);
532*1b8adde7SWilliam Kucharski rx_ring[i].Length = cpu_to_le16(RX_NIC_BUFSIZE);
533*1b8adde7SWilliam Kucharski wmb();
534*1b8adde7SWilliam Kucharski rx_ring[i].Flags = cpu_to_le16(NV_RX_AVAIL);
535*1b8adde7SWilliam Kucharski /* printf("alloc_rx: Packet %d marked as Available\n",
536*1b8adde7SWilliam Kucharski refill_rx); */
537*1b8adde7SWilliam Kucharski refill_rx++;
538*1b8adde7SWilliam Kucharski }
539*1b8adde7SWilliam Kucharski np->refill_rx = refill_rx;
540*1b8adde7SWilliam Kucharski if (np->cur_rx - refill_rx == RX_RING)
541*1b8adde7SWilliam Kucharski return 1;
542*1b8adde7SWilliam Kucharski return 0;
543*1b8adde7SWilliam Kucharski }
544*1b8adde7SWilliam Kucharski
update_linkspeed(struct nic * nic)545*1b8adde7SWilliam Kucharski static int update_linkspeed(struct nic *nic)
546*1b8adde7SWilliam Kucharski {
547*1b8adde7SWilliam Kucharski int adv, lpa, newdup;
548*1b8adde7SWilliam Kucharski u32 newls;
549*1b8adde7SWilliam Kucharski adv = mii_rw(nic, np->phyaddr, MII_ADVERTISE, MII_READ);
550*1b8adde7SWilliam Kucharski lpa = mii_rw(nic, np->phyaddr, MII_LPA, MII_READ);
551*1b8adde7SWilliam Kucharski dprintf(("update_linkspeed: PHY advertises 0x%hX, lpa 0x%hX.\n",
552*1b8adde7SWilliam Kucharski adv, lpa));
553*1b8adde7SWilliam Kucharski
554*1b8adde7SWilliam Kucharski /* FIXME: handle parallel detection properly, handle gigabit ethernet */
555*1b8adde7SWilliam Kucharski lpa = lpa & adv;
556*1b8adde7SWilliam Kucharski if (lpa & LPA_100FULL) {
557*1b8adde7SWilliam Kucharski newls = NVREG_LINKSPEED_FORCE | NVREG_LINKSPEED_100;
558*1b8adde7SWilliam Kucharski newdup = 1;
559*1b8adde7SWilliam Kucharski } else if (lpa & LPA_100HALF) {
560*1b8adde7SWilliam Kucharski newls = NVREG_LINKSPEED_FORCE | NVREG_LINKSPEED_100;
561*1b8adde7SWilliam Kucharski newdup = 0;
562*1b8adde7SWilliam Kucharski } else if (lpa & LPA_10FULL) {
563*1b8adde7SWilliam Kucharski newls = NVREG_LINKSPEED_FORCE | NVREG_LINKSPEED_10;
564*1b8adde7SWilliam Kucharski newdup = 1;
565*1b8adde7SWilliam Kucharski } else if (lpa & LPA_10HALF) {
566*1b8adde7SWilliam Kucharski newls = NVREG_LINKSPEED_FORCE | NVREG_LINKSPEED_10;
567*1b8adde7SWilliam Kucharski newdup = 0;
568*1b8adde7SWilliam Kucharski } else {
569*1b8adde7SWilliam Kucharski printf("bad ability %hX - falling back to 10HD.\n", lpa);
570*1b8adde7SWilliam Kucharski newls = NVREG_LINKSPEED_FORCE | NVREG_LINKSPEED_10;
571*1b8adde7SWilliam Kucharski newdup = 0;
572*1b8adde7SWilliam Kucharski }
573*1b8adde7SWilliam Kucharski if (np->duplex != newdup || np->linkspeed != newls) {
574*1b8adde7SWilliam Kucharski np->duplex = newdup;
575*1b8adde7SWilliam Kucharski np->linkspeed = newls;
576*1b8adde7SWilliam Kucharski return 1;
577*1b8adde7SWilliam Kucharski }
578*1b8adde7SWilliam Kucharski return 0;
579*1b8adde7SWilliam Kucharski }
580*1b8adde7SWilliam Kucharski
581*1b8adde7SWilliam Kucharski
582*1b8adde7SWilliam Kucharski
init_ring(struct nic * nic)583*1b8adde7SWilliam Kucharski static int init_ring(struct nic *nic)
584*1b8adde7SWilliam Kucharski {
585*1b8adde7SWilliam Kucharski int i;
586*1b8adde7SWilliam Kucharski
587*1b8adde7SWilliam Kucharski np->next_tx = np->nic_tx = 0;
588*1b8adde7SWilliam Kucharski for (i = 0; i < TX_RING; i++) {
589*1b8adde7SWilliam Kucharski tx_ring[i].Flags = 0;
590*1b8adde7SWilliam Kucharski }
591*1b8adde7SWilliam Kucharski
592*1b8adde7SWilliam Kucharski np->cur_rx = 0;
593*1b8adde7SWilliam Kucharski np->refill_rx = 0;
594*1b8adde7SWilliam Kucharski for (i = 0; i < RX_RING; i++) {
595*1b8adde7SWilliam Kucharski rx_ring[i].Flags = 0;
596*1b8adde7SWilliam Kucharski }
597*1b8adde7SWilliam Kucharski return alloc_rx(nic);
598*1b8adde7SWilliam Kucharski }
599*1b8adde7SWilliam Kucharski
set_multicast(struct nic * nic)600*1b8adde7SWilliam Kucharski static void set_multicast(struct nic *nic)
601*1b8adde7SWilliam Kucharski {
602*1b8adde7SWilliam Kucharski
603*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
604*1b8adde7SWilliam Kucharski u32 addr[2];
605*1b8adde7SWilliam Kucharski u32 mask[2];
606*1b8adde7SWilliam Kucharski u32 pff;
607*1b8adde7SWilliam Kucharski u32 alwaysOff[2];
608*1b8adde7SWilliam Kucharski u32 alwaysOn[2];
609*1b8adde7SWilliam Kucharski
610*1b8adde7SWilliam Kucharski memset(addr, 0, sizeof(addr));
611*1b8adde7SWilliam Kucharski memset(mask, 0, sizeof(mask));
612*1b8adde7SWilliam Kucharski
613*1b8adde7SWilliam Kucharski pff = NVREG_PFF_MYADDR;
614*1b8adde7SWilliam Kucharski
615*1b8adde7SWilliam Kucharski alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
616*1b8adde7SWilliam Kucharski
617*1b8adde7SWilliam Kucharski addr[0] = alwaysOn[0];
618*1b8adde7SWilliam Kucharski addr[1] = alwaysOn[1];
619*1b8adde7SWilliam Kucharski mask[0] = alwaysOn[0] | alwaysOff[0];
620*1b8adde7SWilliam Kucharski mask[1] = alwaysOn[1] | alwaysOff[1];
621*1b8adde7SWilliam Kucharski
622*1b8adde7SWilliam Kucharski addr[0] |= NVREG_MCASTADDRA_FORCE;
623*1b8adde7SWilliam Kucharski pff |= NVREG_PFF_ALWAYS;
624*1b8adde7SWilliam Kucharski stop_rx();
625*1b8adde7SWilliam Kucharski writel(addr[0], base + NvRegMulticastAddrA);
626*1b8adde7SWilliam Kucharski writel(addr[1], base + NvRegMulticastAddrB);
627*1b8adde7SWilliam Kucharski writel(mask[0], base + NvRegMulticastMaskA);
628*1b8adde7SWilliam Kucharski writel(mask[1], base + NvRegMulticastMaskB);
629*1b8adde7SWilliam Kucharski writel(pff, base + NvRegPacketFilterFlags);
630*1b8adde7SWilliam Kucharski start_rx(nic);
631*1b8adde7SWilliam Kucharski }
632*1b8adde7SWilliam Kucharski
633*1b8adde7SWilliam Kucharski /**************************************************************************
634*1b8adde7SWilliam Kucharski RESET - Reset the NIC to prepare for use
635*1b8adde7SWilliam Kucharski ***************************************************************************/
forcedeth_reset(struct nic * nic)636*1b8adde7SWilliam Kucharski static int forcedeth_reset(struct nic *nic)
637*1b8adde7SWilliam Kucharski {
638*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
639*1b8adde7SWilliam Kucharski int ret, oom, i;
640*1b8adde7SWilliam Kucharski ret = 0;
641*1b8adde7SWilliam Kucharski dprintf(("forcedeth: open\n"));
642*1b8adde7SWilliam Kucharski
643*1b8adde7SWilliam Kucharski /* 1) erase previous misconfiguration */
644*1b8adde7SWilliam Kucharski /* 4.1-1: stop adapter: ignored, 4.3 seems to be overkill */
645*1b8adde7SWilliam Kucharski writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
646*1b8adde7SWilliam Kucharski writel(0, base + NvRegMulticastAddrB);
647*1b8adde7SWilliam Kucharski writel(0, base + NvRegMulticastMaskA);
648*1b8adde7SWilliam Kucharski writel(0, base + NvRegMulticastMaskB);
649*1b8adde7SWilliam Kucharski writel(0, base + NvRegPacketFilterFlags);
650*1b8adde7SWilliam Kucharski writel(0, base + NvRegAdapterControl);
651*1b8adde7SWilliam Kucharski writel(0, base + NvRegLinkSpeed);
652*1b8adde7SWilliam Kucharski writel(0, base + NvRegUnknownTransmitterReg);
653*1b8adde7SWilliam Kucharski txrx_reset(nic);
654*1b8adde7SWilliam Kucharski writel(0, base + NvRegUnknownSetupReg6);
655*1b8adde7SWilliam Kucharski
656*1b8adde7SWilliam Kucharski /* 2) initialize descriptor rings */
657*1b8adde7SWilliam Kucharski np->in_shutdown = 0;
658*1b8adde7SWilliam Kucharski oom = init_ring(nic);
659*1b8adde7SWilliam Kucharski
660*1b8adde7SWilliam Kucharski /* 3) set mac address */
661*1b8adde7SWilliam Kucharski {
662*1b8adde7SWilliam Kucharski u32 mac[2];
663*1b8adde7SWilliam Kucharski
664*1b8adde7SWilliam Kucharski mac[0] =
665*1b8adde7SWilliam Kucharski (nic->node_addr[0] << 0) + (nic->node_addr[1] << 8) +
666*1b8adde7SWilliam Kucharski (nic->node_addr[2] << 16) + (nic->node_addr[3] << 24);
667*1b8adde7SWilliam Kucharski mac[1] =
668*1b8adde7SWilliam Kucharski (nic->node_addr[4] << 0) + (nic->node_addr[5] << 8);
669*1b8adde7SWilliam Kucharski
670*1b8adde7SWilliam Kucharski writel(mac[0], base + NvRegMacAddrA);
671*1b8adde7SWilliam Kucharski writel(mac[1], base + NvRegMacAddrB);
672*1b8adde7SWilliam Kucharski }
673*1b8adde7SWilliam Kucharski
674*1b8adde7SWilliam Kucharski /* 4) continue setup */
675*1b8adde7SWilliam Kucharski np->linkspeed = NVREG_LINKSPEED_FORCE | NVREG_LINKSPEED_10;
676*1b8adde7SWilliam Kucharski np->duplex = 0;
677*1b8adde7SWilliam Kucharski writel(NVREG_UNKSETUP3_VAL1, base + NvRegUnknownSetupReg3);
678*1b8adde7SWilliam Kucharski writel(0, base + NvRegTxRxControl);
679*1b8adde7SWilliam Kucharski pci_push(base);
680*1b8adde7SWilliam Kucharski writel(NVREG_TXRXCTL_BIT1, base + NvRegTxRxControl);
681*1b8adde7SWilliam Kucharski
682*1b8adde7SWilliam Kucharski reg_delay(NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31,
683*1b8adde7SWilliam Kucharski NVREG_UNKSETUP5_BIT31, NV_SETUP5_DELAY,
684*1b8adde7SWilliam Kucharski NV_SETUP5_DELAYMAX,
685*1b8adde7SWilliam Kucharski "open: SetupReg5, Bit 31 remained off\n");
686*1b8adde7SWilliam Kucharski writel(0, base + NvRegUnknownSetupReg4);
687*1b8adde7SWilliam Kucharski
688*1b8adde7SWilliam Kucharski /* 5) Find a suitable PHY */
689*1b8adde7SWilliam Kucharski writel(NVREG_MIISPEED_BIT8 | NVREG_MIIDELAY, base + NvRegMIISpeed);
690*1b8adde7SWilliam Kucharski for (i = 1; i < 32; i++) {
691*1b8adde7SWilliam Kucharski int id1, id2;
692*1b8adde7SWilliam Kucharski
693*1b8adde7SWilliam Kucharski id1 = mii_rw(nic, i, MII_PHYSID1, MII_READ);
694*1b8adde7SWilliam Kucharski if (id1 < 0)
695*1b8adde7SWilliam Kucharski continue;
696*1b8adde7SWilliam Kucharski id2 = mii_rw(nic, i, MII_PHYSID2, MII_READ);
697*1b8adde7SWilliam Kucharski if (id2 < 0)
698*1b8adde7SWilliam Kucharski continue;
699*1b8adde7SWilliam Kucharski dprintf(("open: Found PHY %04x:%04x at address %d.\n",
700*1b8adde7SWilliam Kucharski id1, id2, i));
701*1b8adde7SWilliam Kucharski np->phyaddr = i;
702*1b8adde7SWilliam Kucharski
703*1b8adde7SWilliam Kucharski update_linkspeed(nic);
704*1b8adde7SWilliam Kucharski
705*1b8adde7SWilliam Kucharski break;
706*1b8adde7SWilliam Kucharski }
707*1b8adde7SWilliam Kucharski if (i == 32) {
708*1b8adde7SWilliam Kucharski printf("open: failing due to lack of suitable PHY.\n");
709*1b8adde7SWilliam Kucharski ret = -1;
710*1b8adde7SWilliam Kucharski goto out_drain;
711*1b8adde7SWilliam Kucharski }
712*1b8adde7SWilliam Kucharski
713*1b8adde7SWilliam Kucharski printf("%d-Mbs Link, %s-Duplex\n",
714*1b8adde7SWilliam Kucharski np->linkspeed & NVREG_LINKSPEED_10 ? 10 : 100,
715*1b8adde7SWilliam Kucharski np->duplex ? "Full" : "Half");
716*1b8adde7SWilliam Kucharski /* 6) continue setup */
717*1b8adde7SWilliam Kucharski writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
718*1b8adde7SWilliam Kucharski base + NvRegMisc1);
719*1b8adde7SWilliam Kucharski writel(readl(base + NvRegTransmitterStatus),
720*1b8adde7SWilliam Kucharski base + NvRegTransmitterStatus);
721*1b8adde7SWilliam Kucharski writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
722*1b8adde7SWilliam Kucharski writel(NVREG_OFFLOAD_NORMAL, base + NvRegOffloadConfig);
723*1b8adde7SWilliam Kucharski
724*1b8adde7SWilliam Kucharski writel(readl(base + NvRegReceiverStatus),
725*1b8adde7SWilliam Kucharski base + NvRegReceiverStatus);
726*1b8adde7SWilliam Kucharski
727*1b8adde7SWilliam Kucharski /* FIXME: I cheated and used the calculator to get a random number */
728*1b8adde7SWilliam Kucharski i = 75963081;
729*1b8adde7SWilliam Kucharski writel(NVREG_RNDSEED_FORCE | (i & NVREG_RNDSEED_MASK),
730*1b8adde7SWilliam Kucharski base + NvRegRandomSeed);
731*1b8adde7SWilliam Kucharski writel(NVREG_UNKSETUP1_VAL, base + NvRegUnknownSetupReg1);
732*1b8adde7SWilliam Kucharski writel(NVREG_UNKSETUP2_VAL, base + NvRegUnknownSetupReg2);
733*1b8adde7SWilliam Kucharski writel(NVREG_POLL_DEFAULT, base + NvRegPollingInterval);
734*1b8adde7SWilliam Kucharski writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
735*1b8adde7SWilliam Kucharski writel((np->
736*1b8adde7SWilliam Kucharski phyaddr << NVREG_ADAPTCTL_PHYSHIFT) |
737*1b8adde7SWilliam Kucharski NVREG_ADAPTCTL_PHYVALID, base + NvRegAdapterControl);
738*1b8adde7SWilliam Kucharski writel(NVREG_UNKSETUP4_VAL, base + NvRegUnknownSetupReg4);
739*1b8adde7SWilliam Kucharski writel(NVREG_WAKEUPFLAGS_VAL, base + NvRegWakeUpFlags);
740*1b8adde7SWilliam Kucharski
741*1b8adde7SWilliam Kucharski /* 7) start packet processing */
742*1b8adde7SWilliam Kucharski writel((u32) virt_to_le32desc(&rx_ring[0]),
743*1b8adde7SWilliam Kucharski base + NvRegRxRingPhysAddr);
744*1b8adde7SWilliam Kucharski writel((u32) virt_to_le32desc(&tx_ring[0]),
745*1b8adde7SWilliam Kucharski base + NvRegTxRingPhysAddr);
746*1b8adde7SWilliam Kucharski
747*1b8adde7SWilliam Kucharski
748*1b8adde7SWilliam Kucharski writel(((RX_RING - 1) << NVREG_RINGSZ_RXSHIFT) +
749*1b8adde7SWilliam Kucharski ((TX_RING - 1) << NVREG_RINGSZ_TXSHIFT),
750*1b8adde7SWilliam Kucharski base + NvRegRingSizes);
751*1b8adde7SWilliam Kucharski
752*1b8adde7SWilliam Kucharski i = readl(base + NvRegPowerState);
753*1b8adde7SWilliam Kucharski if ((i & NVREG_POWERSTATE_POWEREDUP) == 0) {
754*1b8adde7SWilliam Kucharski writel(NVREG_POWERSTATE_POWEREDUP | i,
755*1b8adde7SWilliam Kucharski base + NvRegPowerState);
756*1b8adde7SWilliam Kucharski }
757*1b8adde7SWilliam Kucharski pci_push(base);
758*1b8adde7SWilliam Kucharski udelay(10);
759*1b8adde7SWilliam Kucharski writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID,
760*1b8adde7SWilliam Kucharski base + NvRegPowerState);
761*1b8adde7SWilliam Kucharski writel(NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
762*1b8adde7SWilliam Kucharski
763*1b8adde7SWilliam Kucharski writel(0, base + NvRegIrqMask);
764*1b8adde7SWilliam Kucharski pci_push(base);
765*1b8adde7SWilliam Kucharski writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
766*1b8adde7SWilliam Kucharski pci_push(base);
767*1b8adde7SWilliam Kucharski writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
768*1b8adde7SWilliam Kucharski writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
769*1b8adde7SWilliam Kucharski pci_push(base);
770*1b8adde7SWilliam Kucharski /*
771*1b8adde7SWilliam Kucharski writel(np->irqmask, base + NvRegIrqMask);
772*1b8adde7SWilliam Kucharski */
773*1b8adde7SWilliam Kucharski writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
774*1b8adde7SWilliam Kucharski writel(0, base + NvRegMulticastAddrB);
775*1b8adde7SWilliam Kucharski writel(0, base + NvRegMulticastMaskA);
776*1b8adde7SWilliam Kucharski writel(0, base + NvRegMulticastMaskB);
777*1b8adde7SWilliam Kucharski writel(NVREG_PFF_ALWAYS | NVREG_PFF_MYADDR,
778*1b8adde7SWilliam Kucharski base + NvRegPacketFilterFlags);
779*1b8adde7SWilliam Kucharski
780*1b8adde7SWilliam Kucharski set_multicast(nic);
781*1b8adde7SWilliam Kucharski //start_rx(nic);
782*1b8adde7SWilliam Kucharski start_tx(nic);
783*1b8adde7SWilliam Kucharski
784*1b8adde7SWilliam Kucharski if (!
785*1b8adde7SWilliam Kucharski (mii_rw(nic, np->phyaddr, MII_BMSR, MII_READ) &
786*1b8adde7SWilliam Kucharski BMSR_ANEGCOMPLETE)) {
787*1b8adde7SWilliam Kucharski printf("no link during initialization.\n");
788*1b8adde7SWilliam Kucharski }
789*1b8adde7SWilliam Kucharski
790*1b8adde7SWilliam Kucharski udelay(10000);
791*1b8adde7SWilliam Kucharski out_drain:
792*1b8adde7SWilliam Kucharski return ret;
793*1b8adde7SWilliam Kucharski }
794*1b8adde7SWilliam Kucharski
795*1b8adde7SWilliam Kucharski //extern void hex_dump(const char *data, const unsigned int len);
796*1b8adde7SWilliam Kucharski
797*1b8adde7SWilliam Kucharski /**************************************************************************
798*1b8adde7SWilliam Kucharski POLL - Wait for a frame
799*1b8adde7SWilliam Kucharski ***************************************************************************/
forcedeth_poll(struct nic * nic,int retrieve)800*1b8adde7SWilliam Kucharski static int forcedeth_poll(struct nic *nic, int retrieve)
801*1b8adde7SWilliam Kucharski {
802*1b8adde7SWilliam Kucharski /* return true if there's an ethernet packet ready to read */
803*1b8adde7SWilliam Kucharski /* nic->packet should contain data on return */
804*1b8adde7SWilliam Kucharski /* nic->packetlen should contain length of data */
805*1b8adde7SWilliam Kucharski
806*1b8adde7SWilliam Kucharski struct ring_desc *prd;
807*1b8adde7SWilliam Kucharski int len;
808*1b8adde7SWilliam Kucharski int i;
809*1b8adde7SWilliam Kucharski
810*1b8adde7SWilliam Kucharski i = np->cur_rx % RX_RING;
811*1b8adde7SWilliam Kucharski prd = &rx_ring[i];
812*1b8adde7SWilliam Kucharski
813*1b8adde7SWilliam Kucharski if ( ! (prd->Flags & cpu_to_le16(NV_RX_DESCRIPTORVALID)) ) {
814*1b8adde7SWilliam Kucharski return 0;
815*1b8adde7SWilliam Kucharski }
816*1b8adde7SWilliam Kucharski
817*1b8adde7SWilliam Kucharski if ( ! retrieve ) return 1;
818*1b8adde7SWilliam Kucharski
819*1b8adde7SWilliam Kucharski /* got a valid packet - forward it to the network core */
820*1b8adde7SWilliam Kucharski len = cpu_to_le16(prd->Length);
821*1b8adde7SWilliam Kucharski nic->packetlen = len;
822*1b8adde7SWilliam Kucharski //hex_dump(rxb + (i * RX_NIC_BUFSIZE), len);
823*1b8adde7SWilliam Kucharski memcpy(nic->packet, rxb +
824*1b8adde7SWilliam Kucharski (i * RX_NIC_BUFSIZE), nic->packetlen);
825*1b8adde7SWilliam Kucharski
826*1b8adde7SWilliam Kucharski wmb();
827*1b8adde7SWilliam Kucharski np->cur_rx++;
828*1b8adde7SWilliam Kucharski alloc_rx(nic);
829*1b8adde7SWilliam Kucharski return 1;
830*1b8adde7SWilliam Kucharski }
831*1b8adde7SWilliam Kucharski
832*1b8adde7SWilliam Kucharski
833*1b8adde7SWilliam Kucharski /**************************************************************************
834*1b8adde7SWilliam Kucharski TRANSMIT - Transmit a frame
835*1b8adde7SWilliam Kucharski ***************************************************************************/
forcedeth_transmit(struct nic * nic,const char * d,unsigned int t,unsigned int s,const char * p)836*1b8adde7SWilliam Kucharski static void forcedeth_transmit(struct nic *nic, const char *d, /* Destination */
837*1b8adde7SWilliam Kucharski unsigned int t, /* Type */
838*1b8adde7SWilliam Kucharski unsigned int s, /* size */
839*1b8adde7SWilliam Kucharski const char *p)
840*1b8adde7SWilliam Kucharski { /* Packet */
841*1b8adde7SWilliam Kucharski /* send the packet to destination */
842*1b8adde7SWilliam Kucharski u8 *ptxb;
843*1b8adde7SWilliam Kucharski u16 nstype;
844*1b8adde7SWilliam Kucharski //u16 status;
845*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
846*1b8adde7SWilliam Kucharski int nr = np->next_tx % TX_RING;
847*1b8adde7SWilliam Kucharski
848*1b8adde7SWilliam Kucharski /* point to the current txb incase multiple tx_rings are used */
849*1b8adde7SWilliam Kucharski ptxb = txb + (nr * RX_NIC_BUFSIZE);
850*1b8adde7SWilliam Kucharski //np->tx_skbuff[nr] = ptxb;
851*1b8adde7SWilliam Kucharski
852*1b8adde7SWilliam Kucharski /* copy the packet to ring buffer */
853*1b8adde7SWilliam Kucharski memcpy(ptxb, d, ETH_ALEN); /* dst */
854*1b8adde7SWilliam Kucharski memcpy(ptxb + ETH_ALEN, nic->node_addr, ETH_ALEN); /* src */
855*1b8adde7SWilliam Kucharski nstype = htons((u16) t); /* type */
856*1b8adde7SWilliam Kucharski memcpy(ptxb + 2 * ETH_ALEN, (u8 *) & nstype, 2); /* type */
857*1b8adde7SWilliam Kucharski memcpy(ptxb + ETH_HLEN, p, s);
858*1b8adde7SWilliam Kucharski
859*1b8adde7SWilliam Kucharski s += ETH_HLEN;
860*1b8adde7SWilliam Kucharski while (s < ETH_ZLEN) /* pad to min length */
861*1b8adde7SWilliam Kucharski ptxb[s++] = '\0';
862*1b8adde7SWilliam Kucharski
863*1b8adde7SWilliam Kucharski tx_ring[nr].PacketBuffer = (u32) virt_to_le32desc(ptxb);
864*1b8adde7SWilliam Kucharski tx_ring[nr].Length = cpu_to_le16(s - 1);
865*1b8adde7SWilliam Kucharski
866*1b8adde7SWilliam Kucharski wmb();
867*1b8adde7SWilliam Kucharski tx_ring[nr].Flags = np->tx_flags;
868*1b8adde7SWilliam Kucharski
869*1b8adde7SWilliam Kucharski writel(NVREG_TXRXCTL_KICK, base + NvRegTxRxControl);
870*1b8adde7SWilliam Kucharski pci_push(base);
871*1b8adde7SWilliam Kucharski tx_ring[nr].Flags = np->tx_flags;
872*1b8adde7SWilliam Kucharski np->next_tx++;
873*1b8adde7SWilliam Kucharski }
874*1b8adde7SWilliam Kucharski
875*1b8adde7SWilliam Kucharski /**************************************************************************
876*1b8adde7SWilliam Kucharski DISABLE - Turn off ethernet interface
877*1b8adde7SWilliam Kucharski ***************************************************************************/
forcedeth_disable(struct dev * dev __unused)878*1b8adde7SWilliam Kucharski static void forcedeth_disable(struct dev *dev __unused)
879*1b8adde7SWilliam Kucharski {
880*1b8adde7SWilliam Kucharski /* put the card in its initial state */
881*1b8adde7SWilliam Kucharski /* This function serves 3 purposes.
882*1b8adde7SWilliam Kucharski * This disables DMA and interrupts so we don't receive
883*1b8adde7SWilliam Kucharski * unexpected packets or interrupts from the card after
884*1b8adde7SWilliam Kucharski * etherboot has finished.
885*1b8adde7SWilliam Kucharski * This frees resources so etherboot may use
886*1b8adde7SWilliam Kucharski * this driver on another interface
887*1b8adde7SWilliam Kucharski * This allows etherboot to reinitialize the interface
888*1b8adde7SWilliam Kucharski * if something is something goes wrong.
889*1b8adde7SWilliam Kucharski */
890*1b8adde7SWilliam Kucharski u8 *base = (u8 *) BASE;
891*1b8adde7SWilliam Kucharski np->in_shutdown = 1;
892*1b8adde7SWilliam Kucharski stop_tx();
893*1b8adde7SWilliam Kucharski stop_rx();
894*1b8adde7SWilliam Kucharski
895*1b8adde7SWilliam Kucharski /* disable interrupts on the nic or we will lock up */
896*1b8adde7SWilliam Kucharski writel(0, base + NvRegIrqMask);
897*1b8adde7SWilliam Kucharski pci_push(base);
898*1b8adde7SWilliam Kucharski dprintf(("Irqmask is zero again\n"));
899*1b8adde7SWilliam Kucharski
900*1b8adde7SWilliam Kucharski /* specia op:o write back the misordered MAC address - otherwise
901*1b8adde7SWilliam Kucharski * the next probe_nic would see a wrong address.
902*1b8adde7SWilliam Kucharski */
903*1b8adde7SWilliam Kucharski writel(np->orig_mac[0], base + NvRegMacAddrA);
904*1b8adde7SWilliam Kucharski writel(np->orig_mac[1], base + NvRegMacAddrB);
905*1b8adde7SWilliam Kucharski }
906*1b8adde7SWilliam Kucharski
907*1b8adde7SWilliam Kucharski /**************************************************************************
908*1b8adde7SWilliam Kucharski IRQ - Enable, Disable, or Force interrupts
909*1b8adde7SWilliam Kucharski ***************************************************************************/
forcedeth_irq(struct nic * nic __unused,irq_action_t action __unused)910*1b8adde7SWilliam Kucharski static void forcedeth_irq(struct nic *nic __unused, irq_action_t action __unused)
911*1b8adde7SWilliam Kucharski {
912*1b8adde7SWilliam Kucharski switch ( action ) {
913*1b8adde7SWilliam Kucharski case DISABLE :
914*1b8adde7SWilliam Kucharski break;
915*1b8adde7SWilliam Kucharski case ENABLE :
916*1b8adde7SWilliam Kucharski break;
917*1b8adde7SWilliam Kucharski case FORCE :
918*1b8adde7SWilliam Kucharski break;
919*1b8adde7SWilliam Kucharski }
920*1b8adde7SWilliam Kucharski }
921*1b8adde7SWilliam Kucharski
922*1b8adde7SWilliam Kucharski /**************************************************************************
923*1b8adde7SWilliam Kucharski PROBE - Look for an adapter, this routine's visible to the outside
924*1b8adde7SWilliam Kucharski ***************************************************************************/
925*1b8adde7SWilliam Kucharski #define IORESOURCE_MEM 0x00000200
926*1b8adde7SWilliam Kucharski #define board_found 1
927*1b8adde7SWilliam Kucharski #define valid_link 0
forcedeth_probe(struct dev * dev,struct pci_device * pci)928*1b8adde7SWilliam Kucharski static int forcedeth_probe(struct dev *dev, struct pci_device *pci)
929*1b8adde7SWilliam Kucharski {
930*1b8adde7SWilliam Kucharski struct nic *nic = (struct nic *) dev;
931*1b8adde7SWilliam Kucharski unsigned long addr;
932*1b8adde7SWilliam Kucharski int sz;
933*1b8adde7SWilliam Kucharski u8 *base;
934*1b8adde7SWilliam Kucharski
935*1b8adde7SWilliam Kucharski if (pci->ioaddr == 0)
936*1b8adde7SWilliam Kucharski return 0;
937*1b8adde7SWilliam Kucharski
938*1b8adde7SWilliam Kucharski printf("forcedeth.c: Found %s, vendor=0x%hX, device=0x%hX\n",
939*1b8adde7SWilliam Kucharski pci->name, pci->vendor, pci->dev_id);
940*1b8adde7SWilliam Kucharski
941*1b8adde7SWilliam Kucharski nic->irqno = 0;
942*1b8adde7SWilliam Kucharski nic->ioaddr = pci->ioaddr & ~3;
943*1b8adde7SWilliam Kucharski
944*1b8adde7SWilliam Kucharski /* point to private storage */
945*1b8adde7SWilliam Kucharski np = &npx;
946*1b8adde7SWilliam Kucharski
947*1b8adde7SWilliam Kucharski adjust_pci_device(pci);
948*1b8adde7SWilliam Kucharski
949*1b8adde7SWilliam Kucharski addr = pci_bar_start(pci, PCI_BASE_ADDRESS_0);
950*1b8adde7SWilliam Kucharski sz = pci_bar_size(pci, PCI_BASE_ADDRESS_0);
951*1b8adde7SWilliam Kucharski
952*1b8adde7SWilliam Kucharski /* BASE is used throughout to address the card */
953*1b8adde7SWilliam Kucharski BASE = (unsigned long) ioremap(addr, sz);
954*1b8adde7SWilliam Kucharski if (!BASE)
955*1b8adde7SWilliam Kucharski return 0;
956*1b8adde7SWilliam Kucharski //rx_ring[0] = rx_ring;
957*1b8adde7SWilliam Kucharski //tx_ring[0] = tx_ring;
958*1b8adde7SWilliam Kucharski
959*1b8adde7SWilliam Kucharski /* read the mac address */
960*1b8adde7SWilliam Kucharski base = (u8 *) BASE;
961*1b8adde7SWilliam Kucharski np->orig_mac[0] = readl(base + NvRegMacAddrA);
962*1b8adde7SWilliam Kucharski np->orig_mac[1] = readl(base + NvRegMacAddrB);
963*1b8adde7SWilliam Kucharski
964*1b8adde7SWilliam Kucharski nic->node_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
965*1b8adde7SWilliam Kucharski nic->node_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
966*1b8adde7SWilliam Kucharski nic->node_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
967*1b8adde7SWilliam Kucharski nic->node_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
968*1b8adde7SWilliam Kucharski nic->node_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
969*1b8adde7SWilliam Kucharski nic->node_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
970*1b8adde7SWilliam Kucharski #ifdef LINUX
971*1b8adde7SWilliam Kucharski if (!is_valid_ether_addr(dev->dev_addr)) {
972*1b8adde7SWilliam Kucharski /*
973*1b8adde7SWilliam Kucharski * Bad mac address. At least one bios sets the mac address
974*1b8adde7SWilliam Kucharski * to 01:23:45:67:89:ab
975*1b8adde7SWilliam Kucharski */
976*1b8adde7SWilliam Kucharski printk(KERN_ERR
977*1b8adde7SWilliam Kucharski "%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n",
978*1b8adde7SWilliam Kucharski pci_name(pci_dev), dev->dev_addr[0],
979*1b8adde7SWilliam Kucharski dev->dev_addr[1], dev->dev_addr[2],
980*1b8adde7SWilliam Kucharski dev->dev_addr[3], dev->dev_addr[4],
981*1b8adde7SWilliam Kucharski dev->dev_addr[5]);
982*1b8adde7SWilliam Kucharski printk(KERN_ERR
983*1b8adde7SWilliam Kucharski "Please complain to your hardware vendor. Switching to a random MAC.\n");
984*1b8adde7SWilliam Kucharski dev->dev_addr[0] = 0x00;
985*1b8adde7SWilliam Kucharski dev->dev_addr[1] = 0x00;
986*1b8adde7SWilliam Kucharski dev->dev_addr[2] = 0x6c;
987*1b8adde7SWilliam Kucharski get_random_bytes(&dev->dev_addr[3], 3);
988*1b8adde7SWilliam Kucharski }
989*1b8adde7SWilliam Kucharski #endif
990*1b8adde7SWilliam Kucharski printf("%s: MAC Address %!, ", pci->name, nic->node_addr);
991*1b8adde7SWilliam Kucharski
992*1b8adde7SWilliam Kucharski np->tx_flags =
993*1b8adde7SWilliam Kucharski cpu_to_le16(NV_TX_LASTPACKET | NV_TX_LASTPACKET1 |
994*1b8adde7SWilliam Kucharski NV_TX_VALID);
995*1b8adde7SWilliam Kucharski switch (pci->dev_id) {
996*1b8adde7SWilliam Kucharski case 0x01C3: // nforce
997*1b8adde7SWilliam Kucharski np->irqmask = NVREG_IRQMASK_WANTED_2;
998*1b8adde7SWilliam Kucharski np->irqmask |= NVREG_IRQ_TIMER;
999*1b8adde7SWilliam Kucharski break;
1000*1b8adde7SWilliam Kucharski case 0x0066: // nforce2
1001*1b8adde7SWilliam Kucharski np->tx_flags |= cpu_to_le16(NV_TX_LASTPACKET1);
1002*1b8adde7SWilliam Kucharski np->irqmask = NVREG_IRQMASK_WANTED_2;
1003*1b8adde7SWilliam Kucharski np->irqmask |= NVREG_IRQ_TIMER;
1004*1b8adde7SWilliam Kucharski break;
1005*1b8adde7SWilliam Kucharski case 0x00D6: // nforce3
1006*1b8adde7SWilliam Kucharski np->tx_flags |= cpu_to_le16(NV_TX_LASTPACKET1);
1007*1b8adde7SWilliam Kucharski np->irqmask = NVREG_IRQMASK_WANTED_2;
1008*1b8adde7SWilliam Kucharski np->irqmask |= NVREG_IRQ_TIMER;
1009*1b8adde7SWilliam Kucharski
1010*1b8adde7SWilliam Kucharski }
1011*1b8adde7SWilliam Kucharski dprintf(("%s: forcedeth.c: subsystem: %hX:%hX bound to %s\n",
1012*1b8adde7SWilliam Kucharski pci->name, pci->vendor, pci->dev_id, pci->name));
1013*1b8adde7SWilliam Kucharski
1014*1b8adde7SWilliam Kucharski forcedeth_reset(nic);
1015*1b8adde7SWilliam Kucharski // if (board_found && valid_link)
1016*1b8adde7SWilliam Kucharski /* point to NIC specific routines */
1017*1b8adde7SWilliam Kucharski dev->disable = forcedeth_disable;
1018*1b8adde7SWilliam Kucharski nic->poll = forcedeth_poll;
1019*1b8adde7SWilliam Kucharski nic->transmit = forcedeth_transmit;
1020*1b8adde7SWilliam Kucharski nic->irq = forcedeth_irq;
1021*1b8adde7SWilliam Kucharski return 1;
1022*1b8adde7SWilliam Kucharski // }
1023*1b8adde7SWilliam Kucharski /* else */
1024*1b8adde7SWilliam Kucharski }
1025*1b8adde7SWilliam Kucharski
1026*1b8adde7SWilliam Kucharski static struct pci_id forcedeth_nics[] = {
1027*1b8adde7SWilliam Kucharski PCI_ROM(0x10de, 0x01C3, "nforce", "nForce Ethernet Controller"),
1028*1b8adde7SWilliam Kucharski PCI_ROM(0x10de, 0x0066, "nforce2", "nForce2 Ethernet Controller"),
1029*1b8adde7SWilliam Kucharski PCI_ROM(0x10de, 0x00D6, "nforce3", "nForce3 Ethernet Controller"),
1030*1b8adde7SWilliam Kucharski };
1031*1b8adde7SWilliam Kucharski
1032*1b8adde7SWilliam Kucharski struct pci_driver forcedeth_driver = {
1033*1b8adde7SWilliam Kucharski .type = NIC_DRIVER,
1034*1b8adde7SWilliam Kucharski .name = "forcedeth",
1035*1b8adde7SWilliam Kucharski .probe = forcedeth_probe,
1036*1b8adde7SWilliam Kucharski .ids = forcedeth_nics,
1037*1b8adde7SWilliam Kucharski .id_count = sizeof(forcedeth_nics) / sizeof(forcedeth_nics[0]),
1038*1b8adde7SWilliam Kucharski .class = 0,
1039*1b8adde7SWilliam Kucharski };
1040