if_le_isa.c revision 1.1 1 /* $NetBSD: if_le_isa.c,v 1.1 1996/05/07 01:50:05 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Ralph Campbell and Rick Macklem.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
40 */
41
42 #include "bpfilter.h"
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/mbuf.h>
47 #include <sys/syslog.h>
48 #include <sys/socket.h>
49 #include <sys/device.h>
50
51 #include <net/if.h>
52
53 #ifdef INET
54 #include <netinet/in.h>
55 #include <netinet/if_ether.h>
56 #endif
57
58 #include <vm/vm.h>
59
60 #include <machine/cpu.h>
61 #include <machine/pio.h>
62
63 #include <dev/isa/isareg.h>
64 #include <dev/isa/isavar.h>
65 #include <dev/isa/isadmavar.h>
66 #include <i386/isa/isa_machdep.h>
67
68 #include <dev/ic/am7990reg.h>
69 #include <dev/ic/am7990var.h>
70
71 #include <dev/isa/if_levar.h>
72
73 static char *card_type[] =
74 { "unknown", "BICC Isolan", "NE2100", "DEPCA", "PCnet-ISA" };
75
76 int le_isa_probe __P((struct device *, void *, void *));
77 void le_isa_attach __P((struct device *, struct device *, void *));
78
79 struct cfattach le_isa_ca = {
80 sizeof(struct le_softc), le_isa_probe, le_isa_attach
81 };
82
83 int depca_isa_probe __P((struct le_softc *, struct isa_attach_args *));
84 int ne2100_isa_probe __P((struct le_softc *, struct isa_attach_args *));
85 int bicc_isa_probe __P((struct le_softc *, struct isa_attach_args *));
86 int lance_isa_probe __P((struct am7990_softc *));
87
88 int le_isa_intredge __P((void *));
89
90 hide void le_isa_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
91 hide u_int16_t le_isa_rdcsr __P((struct am7990_softc *, u_int16_t));
92
93 hide void
94 le_isa_wrcsr(sc, port, val)
95 struct am7990_softc *sc;
96 u_int16_t port, val;
97 {
98
99 outw(((struct le_softc *)sc)->sc_rap, port);
100 outw(((struct le_softc *)sc)->sc_rdp, val);
101 }
102
103 hide u_int16_t
104 le_isa_rdcsr(sc, port)
105 struct am7990_softc *sc;
106 u_int16_t port;
107 {
108 u_int16_t val;
109
110 outw(((struct le_softc *)sc)->sc_rap, port);
111 val = inw(((struct le_softc *)sc)->sc_rdp);
112 return (val);
113 }
114
115 int
116 le_isa_probe(parent, match, aux)
117 struct device *parent;
118 void *match, *aux;
119 {
120 struct le_softc *lesc = match;
121 struct isa_attach_args *ia = aux;
122
123 if (bicc_isa_probe(lesc, ia))
124 return (1);
125 if (ne2100_isa_probe(lesc, ia))
126 return (1);
127 if (depca_isa_probe(lesc, ia))
128 return (1);
129
130 return (0);
131 }
132
133 int
134 depca_isa_probe(lesc, ia)
135 struct le_softc *lesc;
136 struct isa_attach_args *ia;
137 {
138 struct am7990_softc *sc = &lesc->sc_am7990;
139 int iobase = ia->ia_iobase, port;
140 u_long sum, rom_sum;
141 u_char x;
142 int i;
143
144 lesc->sc_rap = iobase + DEPCA_RAP;
145 lesc->sc_rdp = iobase + DEPCA_RDP;
146 lesc->sc_card = DEPCA;
147
148 if (lance_isa_probe(sc) == 0)
149 return 0;
150
151 outb(iobase + DEPCA_CSR, DEPCA_CSR_DUM);
152
153 /*
154 * Extract the physical MAC address from the ROM.
155 *
156 * The address PROM is 32 bytes wide, and we access it through
157 * a single I/O port. On each read, it rotates to the next
158 * position. We find the ethernet address by looking for a
159 * particular sequence of bytes (0xff, 0x00, 0x55, 0xaa, 0xff,
160 * 0x00, 0x55, 0xaa), and then reading the next 8 bytes (the
161 * ethernet address and a checksum).
162 *
163 * It appears that the PROM can be at one of two locations, so
164 * we just try both.
165 */
166 port = iobase + DEPCA_ADP;
167 for (i = 0; i < 32; i++)
168 if (inb(port) == 0xff && inb(port) == 0x00 &&
169 inb(port) == 0x55 && inb(port) == 0xaa &&
170 inb(port) == 0xff && inb(port) == 0x00 &&
171 inb(port) == 0x55 && inb(port) == 0xaa)
172 goto found;
173 port = iobase + DEPCA_ADP + 1;
174 for (i = 0; i < 32; i++)
175 if (inb(port) == 0xff && inb(port) == 0x00 &&
176 inb(port) == 0x55 && inb(port) == 0xaa &&
177 inb(port) == 0xff && inb(port) == 0x00 &&
178 inb(port) == 0x55 && inb(port) == 0xaa)
179 goto found;
180 printf("%s: address not found\n", sc->sc_dev.dv_xname);
181 return 0;
182
183 found:
184 for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++)
185 sc->sc_arpcom.ac_enaddr[i] = inb(port);
186
187 #if 0
188 sum =
189 (sc->sc_arpcom.ac_enaddr[0] << 2) +
190 (sc->sc_arpcom.ac_enaddr[1] << 10) +
191 (sc->sc_arpcom.ac_enaddr[2] << 1) +
192 (sc->sc_arpcom.ac_enaddr[3] << 9) +
193 (sc->sc_arpcom.ac_enaddr[4] << 0) +
194 (sc->sc_arpcom.ac_enaddr[5] << 8);
195 sum = (sum & 0xffff) + (sum >> 16);
196 sum = (sum & 0xffff) + (sum >> 16);
197
198 rom_sum = inb(port);
199 rom_sum |= inb(port) << 8;
200
201 if (sum != rom_sum) {
202 printf("%s: checksum mismatch; calculated %04x != read %04x",
203 sc->sc_dev.dv_xname, sum, rom_sum);
204 return 0;
205 }
206 #endif
207
208 outb(iobase + DEPCA_CSR, DEPCA_CSR_NORMAL);
209
210 ia->ia_iosize = 16;
211 ia->ia_drq = DRQUNK;
212 return 1;
213 }
214
215 int
216 ne2100_isa_probe(lesc, ia)
217 struct le_softc *lesc;
218 struct isa_attach_args *ia;
219 {
220 struct am7990_softc *sc = &lesc->sc_am7990;
221 int iobase = ia->ia_iobase;
222 int i;
223
224 lesc->sc_rap = iobase + NE2100_RAP;
225 lesc->sc_rdp = iobase + NE2100_RDP;
226 lesc->sc_card = NE2100;
227
228 if (lance_isa_probe(sc) == 0)
229 return 0;
230
231 /*
232 * Extract the physical MAC address from the ROM.
233 */
234 for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++)
235 sc->sc_arpcom.ac_enaddr[i] = inb(iobase + i);
236
237 ia->ia_iosize = 24;
238 return 1;
239 }
240
241 int
242 bicc_isa_probe(lesc, ia)
243 struct le_softc *lesc;
244 struct isa_attach_args *ia;
245 {
246 struct am7990_softc *sc = &lesc->sc_am7990;
247 int iobase = ia->ia_iobase;
248 int i;
249
250 lesc->sc_rap = iobase + BICC_RAP;
251 lesc->sc_rdp = iobase + BICC_RDP;
252 lesc->sc_card = BICC;
253
254 if (lance_isa_probe(sc) == 0)
255 return 0;
256
257 /*
258 * Extract the physical MAC address from the ROM.
259 */
260 for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++)
261 sc->sc_arpcom.ac_enaddr[i] = inb(iobase + i * 2);
262
263 ia->ia_iosize = 16;
264 return 1;
265 }
266
267 /*
268 * Determine which chip is present on the card.
269 */
270 int
271 lance_isa_probe(sc)
272 struct am7990_softc *sc;
273 {
274
275 /* Stop the LANCE chip and put it in a known state. */
276 le_isa_wrcsr(sc, LE_CSR0, LE_C0_STOP);
277 delay(100);
278
279 if (le_isa_rdcsr(sc, LE_CSR0) != LE_C0_STOP)
280 return 0;
281
282 le_isa_wrcsr(sc, LE_CSR3, sc->sc_conf3);
283 return 1;
284 }
285
286 void
287 le_isa_attach(parent, self, aux)
288 struct device *parent, *self;
289 void *aux;
290 {
291 struct le_softc *lesc = (void *)self;
292 struct am7990_softc *sc = &lesc->sc_am7990;
293 struct isa_attach_args *ia = aux;
294
295 printf(": %s Ethernet\n", sc->sc_dev.dv_xname,
296 card_type[lesc->sc_card]);
297
298 if (lesc->sc_card == DEPCA) {
299 u_char *mem, val;
300 int i;
301
302 mem = sc->sc_mem = ISA_HOLE_VADDR(ia->ia_maddr);
303
304 val = 0xff;
305 for (;;) {
306 for (i = 0; i < ia->ia_msize; i++)
307 mem[i] = val;
308 for (i = 0; i < ia->ia_msize; i++)
309 if (mem[i] != val) {
310 printf("%s: failed to clear memory\n",
311 sc->sc_dev.dv_xname);
312 return;
313 }
314 if (val == 0x00)
315 break;
316 val -= 0x55;
317 }
318
319 sc->sc_conf3 = LE_C3_ACON;
320 sc->sc_addr = 0;
321 sc->sc_memsize = ia->ia_msize;
322 } else {
323 sc->sc_mem = malloc(16384, M_DEVBUF, M_NOWAIT);
324 if (sc->sc_mem == 0) {
325 printf("%s: couldn't allocate memory for card\n",
326 sc->sc_dev.dv_xname);
327 return;
328 }
329
330 sc->sc_conf3 = 0;
331 sc->sc_addr = kvtop(sc->sc_mem);
332 sc->sc_memsize = 16384;
333 }
334
335 sc->sc_copytodesc = am7990_copytobuf_contig;
336 sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
337 sc->sc_copytobuf = am7990_copytobuf_contig;
338 sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
339 sc->sc_zerobuf = am7990_zerobuf_contig;
340
341 sc->sc_rdcsr = le_isa_rdcsr;
342 sc->sc_wrcsr = le_isa_wrcsr;
343 sc->sc_hwinit = NULL;
344
345 printf("%s", sc->sc_dev.dv_xname);
346 am7990_config(sc);
347
348 if (ia->ia_drq != DRQUNK)
349 isa_dmacascade(ia->ia_drq);
350
351 lesc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
352 IPL_NET, le_isa_intredge, sc);
353 }
354
355 /*
356 * Controller interrupt.
357 */
358 le_isa_intredge(arg)
359 void *arg;
360 {
361
362 if (am7990_intr(arg) == 0)
363 return (0);
364 for (;;)
365 if (am7990_intr(arg) == 0)
366 return (1);
367 }
368