4 Driver for the ne2000 ethernet cards. This file contains only the ne2000
5 specific code, the rest is in dp8390.c
7 Created: March 15, 1994 by Philip Homburg <philip@f-mnx.phicoh.com>
10 #include "../drivers.h"
12 #include <net/gen/ether.h>
13 #include <net/gen/eth_io.h>
26 #define MILLIS_TO_TICKS(m) (((m)*HZ/1000)+1)
28 _PROTOTYPE( typedef int (*testf_t
), (dpeth_t
*dep
, int pos
, u8_t
*pat
) );
30 u8_t pat0
[]= { 0x00, 0x00, 0x00, 0x00 };
31 u8_t pat1
[]= { 0xFF, 0xFF, 0xFF, 0xFF };
32 u8_t pat2
[]= { 0xA5, 0x5A, 0x69, 0x96 };
33 u8_t pat3
[]= { 0x96, 0x69, 0x5A, 0xA5 };
35 _PROTOTYPE( static int test_8
, (dpeth_t
*dep
, int pos
, u8_t
*pat
) );
36 _PROTOTYPE( static int test_16
, (dpeth_t
*dep
, int pos
, u8_t
*pat
) );
37 _PROTOTYPE( static void ne_stop
, (dpeth_t
*dep
) );
38 _PROTOTYPE( static void milli_delay
, (unsigned long millis
) );
40 /*===========================================================================*
42 *===========================================================================*/
51 dep
->de_dp8390_port
= dep
->de_base_port
+ NE_DP8390
;
53 /* We probe for an ne1000 or an ne2000 by testing whether the
54 * on board is reachable through the dp8390. Note that the
55 * ne1000 is an 8bit card and has a memory region distict from
59 for (dep
->de_16bit
= 0; dep
->de_16bit
< 2; dep
->de_16bit
++)
61 /* Reset the ethernet card */
62 byte
= inb_ne(dep
, NE_RESET
);
64 outb_ne(dep
, NE_RESET
, byte
);
67 /* Reset the dp8390 */
68 outb_reg0(dep
, DP_CR
, CR_STP
| CR_DM_ABORT
);
69 for (i
= 0; i
< 0x1000 && ((inb_reg0(dep
, DP_ISR
) & ISR_RST
) == 0); i
++)
72 /* Check if the dp8390 is really there */
73 if ((inb_reg0(dep
, DP_CR
) & (CR_STP
|CR_DM_ABORT
)) !=
79 /* Disable the receiver and init TCR and DCR. */
80 outb_reg0(dep
, DP_RCR
, RCR_MON
);
81 outb_reg0(dep
, DP_TCR
, TCR_NORMAL
);
84 outb_reg0(dep
, DP_DCR
, DCR_WORDWIDE
| DCR_8BYTES
|
89 outb_reg0(dep
, DP_DCR
, DCR_BYTEWIDE
| DCR_8BYTES
|
96 loc2
= NE2000_START
+ NE2000_SIZE
- 4;
102 loc2
= NE1000_START
+ NE1000_SIZE
- 4;
105 if (f(dep
, loc1
, pat0
) && f(dep
, loc1
, pat1
) &&
106 f(dep
, loc1
, pat2
) && f(dep
, loc1
, pat3
) &&
107 f(dep
, loc2
, pat0
) && f(dep
, loc2
, pat1
) &&
108 f(dep
, loc2
, pat2
) && f(dep
, loc2
, pat3
))
110 /* We don't need a memory segment */
113 dep
->de_initf
= ne_init
;
114 dep
->de_stopf
= ne_stop
;
122 /*===========================================================================*
124 *===========================================================================*/
131 /* Setup a transfer to get the ethernet address. */
133 outb_reg0(dep
, DP_RBCR0
, 6*2);
135 outb_reg0(dep
, DP_RBCR0
, 6);
136 outb_reg0(dep
, DP_RBCR1
, 0);
137 outb_reg0(dep
, DP_RSAR0
, 0);
138 outb_reg0(dep
, DP_RSAR1
, 0);
139 outb_reg0(dep
, DP_CR
, CR_DM_RR
| CR_PS_P0
| CR_STA
);
145 word
= inw_ne(dep
, NE_DATA
);
146 dep
->de_address
.ea_addr
[i
]= word
;
150 dep
->de_address
.ea_addr
[i
] = inb_ne(dep
, NE_DATA
);
153 dep
->de_data_port
= dep
->de_base_port
+ NE_DATA
;
156 dep
->de_ramsize
= NE2000_SIZE
;
157 dep
->de_offset_page
= NE2000_START
/ DP_PAGESIZE
;
161 dep
->de_ramsize
= NE1000_SIZE
;
162 dep
->de_offset_page
= NE1000_START
/ DP_PAGESIZE
;
165 /* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
166 sendq_nr
= dep
->de_ramsize
/ 0x2000;
169 else if (sendq_nr
> SENDQ_NR
)
171 dep
->de_sendq_nr
= sendq_nr
;
172 for (i
= 0; i
<sendq_nr
; i
++)
174 dep
->de_sendq
[i
].sq_sendpage
= dep
->de_offset_page
+
178 dep
->de_startpage
= dep
->de_offset_page
+ i
*SENDQ_PAGES
;
179 dep
->de_stoppage
= dep
->de_offset_page
+ dep
->de_ramsize
/ DP_PAGESIZE
;
181 /* Can't override the default IRQ. */
182 dep
->de_irq
&= ~DEI_DEFAULT
;
186 printf("%s: NE%d000 at %X:%d\n",
187 dep
->de_name
, dep
->de_16bit
? 2 : 1,
188 dep
->de_base_port
, dep
->de_irq
);
192 printf("%s: Novell NE%d000 ethernet card at I/O address "
193 "0x%X, memory size 0x%X, irq %d\n",
194 dep
->de_name
, dep
->de_16bit
? 2 : 1,
195 dep
->de_base_port
, dep
->de_ramsize
, dep
->de_irq
);
199 /*===========================================================================*
201 *===========================================================================*/
202 static int test_8(dep
, pos
, pat
)
211 outb_reg0(dep
, DP_ISR
, 0xFF);
213 /* Setup a transfer to put the pattern. */
214 outb_reg0(dep
, DP_RBCR0
, 4);
215 outb_reg0(dep
, DP_RBCR1
, 0);
216 outb_reg0(dep
, DP_RSAR0
, pos
& 0xFF);
217 outb_reg0(dep
, DP_RSAR1
, pos
>> 8);
218 outb_reg0(dep
, DP_CR
, CR_DM_RW
| CR_PS_P0
| CR_STA
);
221 outb_ne(dep
, NE_DATA
, pat
[i
]);
225 if (inb_reg0(dep
, DP_ISR
) & ISR_RDC
)
232 printf("%s: NE1000 remote DMA test failed\n",
238 outb_reg0(dep
, DP_RBCR0
, 4);
239 outb_reg0(dep
, DP_RBCR1
, 0);
240 outb_reg0(dep
, DP_RSAR0
, pos
& 0xFF);
241 outb_reg0(dep
, DP_RSAR1
, pos
>> 8);
242 outb_reg0(dep
, DP_CR
, CR_DM_RR
| CR_PS_P0
| CR_STA
);
245 buf
[i
]= inb_ne(dep
, NE_DATA
);
247 r
= (memcmp(buf
, pat
, 4) == 0);
251 /*===========================================================================*
253 *===========================================================================*/
254 static int test_16(dep
, pos
, pat
)
263 outb_reg0(dep
, DP_ISR
, 0xFF);
265 /* Setup a transfer to put the pattern. */
266 outb_reg0(dep
, DP_RBCR0
, 4);
267 outb_reg0(dep
, DP_RBCR1
, 0);
268 outb_reg0(dep
, DP_RSAR0
, pos
& 0xFF);
269 outb_reg0(dep
, DP_RSAR1
, pos
>> 8);
270 outb_reg0(dep
, DP_CR
, CR_DM_RW
| CR_PS_P0
| CR_STA
);
272 for (i
= 0; i
<4; i
+= 2)
274 outw_ne(dep
, NE_DATA
, *(u16_t
*)(pat
+i
));
279 if (inb_reg0(dep
, DP_ISR
) & ISR_RDC
)
286 printf("%s: NE2000 remote DMA test failed\n",
292 outb_reg0(dep
, DP_RBCR0
, 4);
293 outb_reg0(dep
, DP_RBCR1
, 0);
294 outb_reg0(dep
, DP_RSAR0
, pos
& 0xFF);
295 outb_reg0(dep
, DP_RSAR1
, pos
>> 8);
296 outb_reg0(dep
, DP_CR
, CR_DM_RR
| CR_PS_P0
| CR_STA
);
298 for (i
= 0; i
<4; i
+= 2)
300 *(u16_t
*)(buf
+i
)= inw_ne(dep
, NE_DATA
);
303 r
= (memcmp(buf
, pat
, 4) == 0);
307 /*===========================================================================*
309 *===========================================================================*/
310 static void ne_stop(dep
)
315 /* Reset the ethernet card */
316 byte
= inb_ne(dep
, NE_RESET
);
318 outb_ne(dep
, NE_RESET
, byte
);
321 static void milli_delay(unsigned long millis
)
323 tickdelay(MILLIS_TO_TICKS(millis
));
326 #endif /* ENABLE_NE2000 */
329 * $PchId: ne2000.c,v 1.10 2004/08/03 12:03:00 philip Exp $