1 /*-
2  * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
3  *
4  * This software may be used, modified, copied, distributed, and sold, in
5  * both source and binary form provided that the above copyright, these
6  * terms and the following disclaimer are retained.  The name of the author
7  * and/or the contributor may not be used to endorse or promote products
8  * derived from this software without specific prior written permission.
9  *
10  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
11  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
12  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
14  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
15  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
16  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
17  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
19  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
20  * SUCH DAMAGE.
21  *
22  */
23 
24 #include <sys/cdefs.h>
25 __FBSDID("$FreeBSD: stable/9/sys/dev/fe/if_fe_cbus.c 179959 2008-06-23 18:16:25Z jhb $");
26 
27 #include <sys/param.h>
28 #include <sys/systm.h>
29 #include <sys/kernel.h>
30 #include <sys/socket.h>
31 #include <sys/module.h>
32 
33 #include <sys/bus.h>
34 #include <machine/bus.h>
35 #include <sys/rman.h>
36 
37 #include <net/ethernet.h>
38 #include <net/if.h>
39 #include <net/if_mib.h>
40 #include <net/if_media.h>
41 
42 #include <netinet/in.h>
43 #include <netinet/if_ether.h>
44 
45 #include <dev/fe/mb86960.h>
46 #include <dev/fe/if_fereg.h>
47 #include <dev/fe/if_fevar.h>
48 
49 #include <isa/isavar.h>
50 
51 /*
52  *	Cbus specific code.
53  */
54 static int fe_isa_probe(device_t);
55 static int fe_isa_attach(device_t);
56 
57 static struct isa_pnp_id fe_ids[] = {
58 	{ 0x101ee0d,	NULL },		/* CON0101 - Contec C-NET(98)P2-T */
59 	{ 0,		NULL }
60 };
61 
62 static device_method_t fe_isa_methods[] = {
63 	/* Device interface */
64 	DEVMETHOD(device_probe,		fe_isa_probe),
65 	DEVMETHOD(device_attach,	fe_isa_attach),
66 
67 	{ 0, 0 }
68 };
69 
70 static driver_t fe_isa_driver = {
71 	"fe",
72 	fe_isa_methods,
73 	sizeof (struct fe_softc)
74 };
75 
76 DRIVER_MODULE(fe, isa, fe_isa_driver, fe_devclass, 0, 0);
77 
78 
79 static int fe98_alloc_port(device_t, int);
80 
81 static int fe_probe_re1000(device_t);
82 static int fe_probe_cnet9ne(device_t);
83 static int fe_probe_rex(device_t);
84 static int fe_probe_ssi(device_t);
85 static int fe_probe_jli(device_t);
86 static int fe_probe_lnx(device_t);
87 static int fe_probe_gwy(device_t);
88 static int fe_probe_ubn(device_t);
89 
90 /*
91  * Determine if the device is present at a specified I/O address.  The
92  * main entry to the driver.
93  */
94 static int
fe_isa_probe(device_t dev)95 fe_isa_probe(device_t dev)
96 {
97 	struct fe_softc *sc;
98 	int error;
99 
100 	/* Prepare for the softc struct.  */
101 	sc = device_get_softc(dev);
102 	sc->sc_unit = device_get_unit(dev);
103 
104 	/* Check isapnp ids */
105 	error = ISA_PNP_PROBE(device_get_parent(dev), dev, fe_ids);
106 
107 	/* If the card had a PnP ID that didn't match any we know about */
108 	if (error == ENXIO)
109 		goto end;
110 
111 	/* If we had some other problem. */
112 	if (!(error == 0 || error == ENOENT))
113 		goto end;
114 
115 	/* Probe for supported boards.  */
116 	if ((error = fe_probe_re1000(dev)) == 0)
117 		goto end;
118 	fe_release_resource(dev);
119 
120 	if ((error = fe_probe_cnet9ne(dev)) == 0)
121 		goto end;
122 	fe_release_resource(dev);
123 
124 	if ((error = fe_probe_rex(dev)) == 0)
125 		goto end;
126 	fe_release_resource(dev);
127 
128 	if ((error = fe_probe_ssi(dev)) == 0)
129 		goto end;
130 	fe_release_resource(dev);
131 
132 	if ((error = fe_probe_jli(dev)) == 0)
133 		goto end;
134 	fe_release_resource(dev);
135 
136 	if ((error = fe_probe_lnx(dev)) == 0)
137 		goto end;
138 	fe_release_resource(dev);
139 
140 	if ((error = fe_probe_ubn(dev)) == 0)
141 		goto end;
142 	fe_release_resource(dev);
143 
144 	if ((error = fe_probe_gwy(dev)) == 0)
145 		goto end;
146 	fe_release_resource(dev);
147 
148 end:
149 	if (error == 0)
150 		error = fe_alloc_irq(dev, 0);
151 
152 	fe_release_resource(dev);
153 	return (error);
154 }
155 
156 static int
fe_isa_attach(device_t dev)157 fe_isa_attach(device_t dev)
158 {
159 	struct fe_softc *sc = device_get_softc(dev);
160 
161 	if (sc->port_used)
162 		fe98_alloc_port(dev, sc->type);
163 	fe_alloc_irq(dev, 0);
164 
165 	return fe_attach(dev);
166 }
167 
168 
169 /* Generic I/O address table */
170 static bus_addr_t ioaddr_generic[MAXREGISTERS] = {
171 	0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
172 	0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
173 	0x010, 0x011, 0x012, 0x013, 0x014, 0x015, 0x016, 0x017,
174 	0x018, 0x019, 0x01a, 0x01b, 0x01c, 0x01d, 0x01e, 0x01f,
175 };
176 
177 /* I/O address table for RE1000/1000Plus */
178 static bus_addr_t ioaddr_re1000[MAXREGISTERS] = {
179 	0x0000, 0x0001, 0x0200, 0x0201, 0x0400, 0x0401, 0x0600, 0x0601,
180 	0x0800, 0x0801, 0x0a00, 0x0a01, 0x0c00, 0x0c01, 0x0e00, 0x0e01,
181 	0x1000, 0x1200, 0x1400, 0x1600, 0x1800, 0x1a00, 0x1c00, 0x1e00,
182 	0x1001, 0x1201, 0x1401, 0x1601, 0x1801, 0x1a01, 0x1c01, 0x1e01,
183 };
184 
185 /* I/O address table for CNET9NE */
186 static bus_addr_t ioaddr_cnet9ne[MAXREGISTERS] = {
187 	0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
188 	0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
189 	0x400, 0x402, 0x404, 0x406, 0x408, 0x40a, 0x40c, 0x40e,
190 	0x401, 0x403, 0x405, 0x407, 0x409, 0x40b, 0x40d, 0x40f,
191 };
192 
193 /* I/O address table for LAC-98 */
194 static bus_addr_t ioaddr_lnx[MAXREGISTERS] = {
195 	0x000, 0x002, 0x004, 0x006, 0x008, 0x00a, 0x00c, 0x00e,
196 	0x100, 0x102, 0x104, 0x106, 0x108, 0x10a, 0x10c, 0x10e,
197 	0x200, 0x202, 0x204, 0x206, 0x208, 0x20a, 0x20c, 0x20e,
198 	0x300, 0x302, 0x304, 0x306, 0x308, 0x30a, 0x30c, 0x30e,
199 };
200 
201 /* I/O address table for Access/PC N98C+ */
202 static bus_addr_t ioaddr_ubn[MAXREGISTERS] = {
203 	0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
204 	0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
205 	0x200, 0x201, 0x202, 0x203, 0x204, 0x205, 0x206, 0x207,
206 	0x208, 0x209, 0x20a, 0x20b, 0x20c, 0x20d, 0x20e, 0x20f,
207 };
208 
209 /* I/O address table for REX-9880 */
210 static bus_addr_t ioaddr_rex[MAXREGISTERS] = {
211 	0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
212 	0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
213 	0x100, 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107,
214 	0x108, 0x109, 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f,
215 };
216 
217 static int
fe98_alloc_port(device_t dev,int type)218 fe98_alloc_port(device_t dev, int type)
219 {
220 	struct fe_softc *sc = device_get_softc(dev);
221 	struct resource *res;
222 	bus_addr_t *iat;
223 	int size, rid;
224 
225 	switch (type) {
226 	case FE_TYPE_RE1000:
227 		iat = ioaddr_re1000;
228 		size = MAXREGISTERS;
229 		break;
230 	case FE_TYPE_CNET9NE:
231 		iat = ioaddr_cnet9ne;
232 		size = MAXREGISTERS;
233 		break;
234 	case FE_TYPE_SSI:
235 		iat = ioaddr_generic;
236 		size = MAXREGISTERS;
237 		break;
238 	case FE_TYPE_LNX:
239 		iat = ioaddr_lnx;
240 		size = MAXREGISTERS;
241 		break;
242 	case FE_TYPE_GWY:
243 		iat = ioaddr_generic;
244 		size = MAXREGISTERS;
245 		break;
246 	case FE_TYPE_UBN:
247 		iat = ioaddr_ubn;
248 		size = MAXREGISTERS;
249 		break;
250 	case FE_TYPE_REX:
251 		iat = ioaddr_rex;
252 		size = MAXREGISTERS;
253 		break;
254 	default:
255 		iat = ioaddr_generic;
256 		size = MAXREGISTERS;
257 		break;
258 	}
259 
260 	rid = 0;
261 	res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid,
262 				  iat, size, RF_ACTIVE);
263 	if (res == NULL)
264 		return ENOENT;
265 
266 	isa_load_resourcev(res, iat, size);
267 
268 	sc->type = type;
269 	sc->port_used = size;
270 	sc->port_res = res;
271 	return (0);
272 }
273 
274 
275 /*
276  * Probe and initialization for Allied-Telesis RE1000 series.
277  */
278 static void
fe_init_re1000(struct fe_softc * sc)279 fe_init_re1000(struct fe_softc *sc)
280 {
281 	/* Setup IRQ control register on the ASIC.  */
282 	fe_outb(sc, FE_RE1000_IRQCONF, sc->priv_info);
283 }
284 
285 static int
fe_probe_re1000(device_t dev)286 fe_probe_re1000(device_t dev)
287 {
288 	struct fe_softc *sc = device_get_softc(dev);
289 	int i, n;
290 	u_long iobase, irq;
291 	u_char sum;
292 
293 	static struct fe_simple_probe_struct probe_table [] = {
294 		{ FE_DLCR2, 0x58, 0x00 },
295 		{ FE_DLCR4, 0x08, 0x00 },
296 		{ 0 }
297 	};
298 
299 	/* See if the specified I/O address is possible for RE1000.  */
300 	/* [01]D[02468ACE] are allowed.  */
301 	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
302 		return ENXIO;
303 	if ((iobase & ~0x10E) != 0xD0)
304 		return ENXIO;
305 
306 	if (fe98_alloc_port(dev, FE_TYPE_RE1000))
307 		return ENXIO;
308 
309 	/* Fill the softc struct with default values.  */
310 	fe_softc_defaults(sc);
311 
312 	/* See if the card is on its address.  */
313 	if (!fe_simple_probe(sc, probe_table))
314 		return ENXIO;
315 
316 	/* Get our station address from EEPROM.  */
317 	fe_inblk(sc, 0x18, sc->enaddr, ETHER_ADDR_LEN);
318 
319 	/* Make sure it is Allied-Telesis's.  */
320 	if (!fe_valid_Ether_p(sc->enaddr, 0x0000F4))
321 		return ENXIO;
322 #if 1
323 	/* Calculate checksum.  */
324 	sum = fe_inb(sc, 0x1e);
325 	for (i = 0; i < ETHER_ADDR_LEN; i++)
326 		sum ^= sc->enaddr[i];
327 	if (sum != 0)
328 		return ENXIO;
329 #endif
330 	/* Setup the board type.  */
331 	sc->typestr = "RE1000";
332 
333 	/* This looks like an RE1000 board.  It requires an
334 	   explicit IRQ setting in config.  Make sure we have one,
335 	   determining an appropriate value for the IRQ control
336 	   register.  */
337 	irq = 0;
338 	bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
339 	switch (irq) {
340 	case 3:  n = 0x10; break;
341 	case 5:  n = 0x20; break;
342 	case 6:  n = 0x40; break;
343 	case 12: n = 0x80; break;
344 	default:
345 		fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12");
346 		return ENXIO;
347 	}
348 	sc->priv_info = (fe_inb(sc, FE_RE1000_IRQCONF) & 0x0f) | n;
349 
350 	/* Setup hooks.  We need a special initialization procedure.  */
351 	sc->init = fe_init_re1000;
352 
353 	return 0;
354 }
355 
356 /* JLI sub-probe for Allied-Telesis RE1000Plus/ME1500 series.  */
357 static u_short const *
fe_probe_jli_re1000p(struct fe_softc * sc,u_char const * eeprom)358 fe_probe_jli_re1000p(struct fe_softc * sc, u_char const * eeprom)
359 {
360 	int i;
361 	static u_short const irqmaps_re1000p [4] = { 3, 5, 6, 12 };
362 
363 	/* Make sure the EEPROM contains Allied-Telesis bit pattern.  */
364 	if (eeprom[1] != 0xFF) return NULL;
365 	for (i =  2; i <  8; i++) if (eeprom[i] != 0xFF) return NULL;
366 	for (i = 14; i < 24; i++) if (eeprom[i] != 0xFF) return NULL;
367 
368 	/* Get our station address from EEPROM, and make sure the
369            EEPROM contains Allied-Telesis's address.  */
370 	bcopy(eeprom + 8, sc->enaddr, ETHER_ADDR_LEN);
371 	if (!fe_valid_Ether_p(sc->enaddr, 0x0000F4))
372 		return NULL;
373 
374 	/* I don't know any sub-model identification.  */
375 	sc->typestr = "RE1000Plus/ME1500";
376 
377 	/* Returns the IRQ table for the RE1000Plus.  */
378 	return irqmaps_re1000p;
379 }
380 
381 
382 /*
383  * Probe for Allied-Telesis RE1000Plus/ME1500 series.
384  */
385 static int
fe_probe_jli(device_t dev)386 fe_probe_jli(device_t dev)
387 {
388 	struct fe_softc *sc = device_get_softc(dev);
389 	int i, n, xirq, error;
390 	u_long iobase, irq;
391 	u_char eeprom [JLI_EEPROM_SIZE];
392 	u_short const * irqmap;
393 
394 	static u_short const baseaddr [8] =
395 		{ 0x1D6, 0x1D8, 0x1DA, 0x1D4, 0x0D4, 0x0D2, 0x0D8, 0x0D0 };
396 	static struct fe_simple_probe_struct const probe_table [] = {
397 	/*	{ FE_DLCR1,  0x20, 0x00 },	Doesn't work. */
398 		{ FE_DLCR2,  0x50, 0x00 },
399 		{ FE_DLCR4,  0x08, 0x00 },
400 	/*	{ FE_DLCR5,  0x80, 0x00 },	Doesn't work. */
401 #if 0
402 		{ FE_BMPR16, 0x1B, 0x00 },
403 		{ FE_BMPR17, 0x7F, 0x00 },
404 #endif
405 		{ 0 }
406 	};
407 
408 	/*
409 	 * See if the specified address is possible for MB86965A JLI mode.
410 	 */
411 	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
412 		return ENXIO;
413 	for (i = 0; i < 8; i++) {
414 		if (baseaddr[i] == iobase)
415 			break;
416 	}
417 	if (i == 8)
418 		return ENXIO;
419 
420 	if (fe98_alloc_port(dev, FE_TYPE_RE1000))
421 		return ENXIO;
422 
423 	/* Fill the softc struct with default values.  */
424 	fe_softc_defaults(sc);
425 
426 	/*
427 	 * We should test if MB86965A is on the base address now.
428 	 * Unfortunately, it is very hard to probe it reliably, since
429 	 * we have no way to reset the chip under software control.
430 	 * On cold boot, we could check the "signature" bit patterns
431 	 * described in the Fujitsu document.  On warm boot, however,
432 	 * we can predict almost nothing about register values.
433 	 */
434 	if (!fe_simple_probe(sc, probe_table))
435 		return ENXIO;
436 
437 	/* Check if our I/O address matches config info on 86965.  */
438 	n = (fe_inb(sc, FE_BMPR19) & FE_B19_ADDR) >> FE_B19_ADDR_SHIFT;
439 	if (baseaddr[n] != iobase)
440 		return ENXIO;
441 
442 	/*
443 	 * We are now almost sure we have an MB86965 at the given
444 	 * address.  So, read EEPROM through it.  We have to write
445 	 * into LSI registers to read from EEPROM.  I want to avoid it
446 	 * at this stage, but I cannot test the presence of the chip
447 	 * any further without reading EEPROM.  FIXME.
448 	 */
449 	fe_read_eeprom_jli(sc, eeprom);
450 
451 	/* Make sure that config info in EEPROM and 86965 agree.  */
452 	if (eeprom[FE_EEPROM_CONF] != fe_inb(sc, FE_BMPR19))
453 		return ENXIO;
454 
455 	/* Use 86965 media selection scheme, unless othewise
456            specified.  It is "AUTO always" and "select with BMPR13".
457            This behaviour covers most of the 86965 based board (as
458            minimum requirements.)  It is backward compatible with
459            previous versions, also.  */
460 	sc->mbitmap = MB_HA;
461 	sc->defmedia = MB_HA;
462 	sc->msel = fe_msel_965;
463 
464 	/* Perform board-specific probe.  */
465 	if ((irqmap = fe_probe_jli_re1000p(sc, eeprom)) == NULL)
466 		return ENXIO;
467 
468 	/* Find the IRQ read from EEPROM.  */
469 	n = (fe_inb(sc, FE_BMPR19) & FE_B19_IRQ) >> FE_B19_IRQ_SHIFT;
470 	xirq = irqmap[n];
471 
472 	/* Try to determine IRQ setting.  */
473 	error = bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
474 	if (error && xirq == NO_IRQ) {
475 		/* The device must be configured with an explicit IRQ.  */
476 		device_printf(dev, "IRQ auto-detection does not work\n");
477 		return ENXIO;
478 	} else if (error && xirq != NO_IRQ) {
479 		/* Just use the probed IRQ value.  */
480 		bus_set_resource(dev, SYS_RES_IRQ, 0, xirq, 1);
481 	} else if (!error && xirq == NO_IRQ) {
482 		/* No problem.  Go ahead.  */
483 	} else if (irq == xirq) {
484 		/* Good.  Go ahead.  */
485 	} else {
486 		/* User must be warned in this case.  */
487 		sc->stability |= UNSTABLE_IRQ;
488 	}
489 
490 	/* Setup a hook, which resets te 86965 when the driver is being
491            initialized.  This may solve a nasty bug.  FIXME.  */
492 	sc->init = fe_init_jli;
493 
494 	return 0;
495 }
496 
497 
498 /*
499  * Probe and initialization for Contec C-NET(9N)E series.
500  */
501 
502 /* TODO: Should be in "if_fereg.h" */
503 #define FE_CNET9NE_INTR		0x10		/* Interrupt Mask? */
504 
505 static void
fe_init_cnet9ne(struct fe_softc * sc)506 fe_init_cnet9ne(struct fe_softc *sc)
507 {
508 	/* Enable interrupt?  FIXME.  */
509 	fe_outb(sc, FE_CNET9NE_INTR, 0x10);
510 }
511 
512 static int
fe_probe_cnet9ne(device_t dev)513 fe_probe_cnet9ne (device_t dev)
514 {
515 	struct fe_softc *sc = device_get_softc(dev);
516 	u_long iobase, irq;
517 
518 	static struct fe_simple_probe_struct probe_table [] = {
519 		{ FE_DLCR2, 0x58, 0x00 },
520 		{ FE_DLCR4, 0x08, 0x00 },
521 		{ 0 }
522 	};
523 
524 	/* See if the specified I/O address is possible for C-NET(9N)E.  */
525 	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
526 		return ENXIO;
527 	if (iobase != 0x73D0)
528 		return ENXIO;
529 
530 	if (fe98_alloc_port(dev, FE_TYPE_CNET9NE))
531 		return ENXIO;
532 
533 	/* Fill the softc struct with default values.  */
534 	fe_softc_defaults(sc);
535 
536 	/* See if the card is on its address.  */
537 	if (!fe_simple_probe(sc, probe_table))
538 		return ENXIO;
539 
540 	/* Get our station address from EEPROM.  */
541 	fe_inblk(sc, 0x18, sc->enaddr, ETHER_ADDR_LEN);
542 
543 	/* Make sure it is Contec's.  */
544 	if (!fe_valid_Ether_p(sc->enaddr, 0x00804C))
545 		return ENXIO;
546 
547 	/* Determine the card type.  */
548 	if (sc->enaddr[3] == 0x06) {
549 		sc->typestr = "C-NET(9N)C";
550 
551 		/* We seems to need our own IDENT bits...  FIXME.  */
552 		sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
553 
554 		/* C-NET(9N)C requires an explicit IRQ to work.  */
555 		if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0) {
556 			fe_irq_failure(sc->typestr, sc->sc_unit, NO_IRQ, NULL);
557 			return ENXIO;
558 		}
559 	} else {
560 		sc->typestr = "C-NET(9N)E";
561 
562 		/* C-NET(9N)E works only IRQ5.  */
563 		if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0)
564 			return ENXIO;
565 		if (irq != 5) {
566 			fe_irq_failure(sc->typestr, sc->sc_unit, irq, "5");
567 			return ENXIO;
568 		}
569 
570 		/* We need an init hook to initialize ASIC before we start.  */
571 		sc->init = fe_init_cnet9ne;
572 	}
573 
574 	/* C-NET(9N)E has 64KB SRAM.  */
575 	sc->proto_dlcr6 = FE_D6_BUFSIZ_64KB | FE_D6_TXBSIZ_2x4KB
576 			| FE_D6_BBW_WORD | FE_D6_SBW_WORD | FE_D6_SRAM;
577 
578 	return 0;
579 }
580 
581 
582 /*
583  * Probe for Contec C-NET(98)P2 series.
584  * (Logitec LAN-98TP/LAN-98T25P - parhaps)
585  */
586 static int
fe_probe_ssi(device_t dev)587 fe_probe_ssi(device_t dev)
588 {
589 	struct fe_softc *sc = device_get_softc(dev);
590 	u_long iobase, irq;
591 
592 	u_char eeprom [SSI_EEPROM_SIZE];
593 	static struct fe_simple_probe_struct probe_table [] = {
594 		{ FE_DLCR2, 0x08, 0x00 },
595 		{ FE_DLCR4, 0x08, 0x00 },
596 		{ 0 }
597 	};
598 	static u_short const irqmap[] = {
599 		/*                        INT0          INT1    INT2       */
600 		NO_IRQ, NO_IRQ, NO_IRQ,      3, NO_IRQ,    5,      6, NO_IRQ,
601 		NO_IRQ,      9,     10, NO_IRQ,     12,   13, NO_IRQ, NO_IRQ,
602 		/*        INT3   INT41            INT5  INT6               */
603 	};
604 
605 	/* See if the specified I/O address is possible for 78Q8377A.  */
606 	/* [0-D]3D0 are allowed.  */
607 	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
608 		return ENXIO;
609 	if ((iobase & 0xFFF) != 0x3D0)
610 		return ENXIO;
611 
612 	if (fe98_alloc_port(dev, FE_TYPE_SSI))
613 		return ENXIO;
614 
615 	/* Fill the softc struct with default values.  */
616 	fe_softc_defaults(sc);
617 
618 	/* See if the card is on its address.  */
619 	if (!fe_simple_probe(sc, probe_table))
620 		return ENXIO;
621 
622 	/* We now have to read the config EEPROM.  We should be very
623            careful, since doing so destroys a register.  (Remember, we
624            are not yet sure we have a C-NET(98)P2 board here.)  Don't
625            remember to select BMPRs bofore reading EEPROM, since other
626            register bank may be selected before the probe() is called.  */
627 	fe_read_eeprom_ssi(sc, eeprom);
628 
629 	/* Make sure the Ethernet (MAC) station address is of Contec's.  */
630 	if (!fe_valid_Ether_p(eeprom + FE_SSI_EEP_ADDR, 0x00804C))
631 		return ENXIO;
632 	bcopy(eeprom + FE_SSI_EEP_ADDR, sc->enaddr, ETHER_ADDR_LEN);
633 
634 	/* Setup the board type.  */
635         sc->typestr = "C-NET(98)P2";
636 
637 	/* Non-PnP mode, set static resource from eeprom. */
638 	if (!isa_get_vendorid(dev)) {
639 		/* Get IRQ configuration from EEPROM.  */
640 		irq = irqmap[eeprom[FE_SSI_EEP_IRQ]];
641 		if (irq == NO_IRQ) {
642 			fe_irq_failure(sc->typestr, sc->sc_unit, irq,
643 				       "3/5/6/9/10/12/13");
644 			return ENXIO;
645 		}
646 		bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1);
647 	}
648 
649 	/* Get Duplex-mode configuration from EEPROM.  */
650 	sc->proto_dlcr4 |= (eeprom[FE_SSI_EEP_DUPLEX] & FE_D4_DSC);
651 
652 	/* Fill softc struct accordingly.  */
653 	sc->mbitmap = MB_HT;
654 	sc->defmedia = MB_HT;
655 
656 	return 0;
657 }
658 
659 
660 /*
661  * Probe for TDK LAC-98012/013/025/9N011 - parhaps.
662  */
663 static int
fe_probe_lnx(device_t dev)664 fe_probe_lnx(device_t dev)
665 {
666 	struct fe_softc *sc = device_get_softc(dev);
667 
668 	u_long iobase, irq;
669 	u_char eeprom [LNX_EEPROM_SIZE];
670 
671 	static struct fe_simple_probe_struct probe_table [] = {
672 		{ FE_DLCR2, 0x58, 0x00 },
673 		{ FE_DLCR4, 0x08, 0x00 },
674 		{ 0 }
675 	};
676 
677 	/* See if the specified I/O address is possible for TDK/LANX boards. */
678 	/* 0D0, 4D0, 8D0, and CD0 are allowed.  */
679 	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
680 		return ENXIO;
681 	if ((iobase & ~0xC00) != 0xD0)
682 		return ENXIO;
683 
684 	if (fe98_alloc_port(dev, FE_TYPE_LNX))
685 		return ENXIO;
686 
687 	/* Fill the softc struct with default values.  */
688 	fe_softc_defaults(sc);
689 
690 	/* See if the card is on its address.  */
691 	if (!fe_simple_probe(sc, probe_table))
692 		return ENXIO;
693 
694 	/* We now have to read the config EEPROM.  We should be very
695            careful, since doing so destroys a register.  (Remember, we
696            are not yet sure we have a LAC-98012/98013 board here.)  */
697 	fe_read_eeprom_lnx(sc, eeprom);
698 
699 	/* Make sure the Ethernet (MAC) station address is of TDK/LANX's.  */
700 	if (!fe_valid_Ether_p(eeprom, 0x008098))
701 		return ENXIO;
702 	bcopy(eeprom, sc->enaddr, ETHER_ADDR_LEN);
703 
704 	/* Setup the board type.  */
705 	sc->typestr = "LAC-98012/98013";
706 
707 	/* This looks like a TDK/LANX board.  It requires an
708 	   explicit IRQ setting in config.  Make sure we have one,
709 	   determining an appropriate value for the IRQ control
710 	   register.  */
711 	irq = 0;
712 	if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0)
713 		return ENXIO;
714 	switch (irq) {
715 	case 3 : sc->priv_info = 0x10 | LNX_CLK_LO | LNX_SDA_HI; break;
716 	case 5 : sc->priv_info = 0x20 | LNX_CLK_LO | LNX_SDA_HI; break;
717 	case 6 : sc->priv_info = 0x40 | LNX_CLK_LO | LNX_SDA_HI; break;
718 	case 12: sc->priv_info = 0x80 | LNX_CLK_LO | LNX_SDA_HI; break;
719 	default:
720 		fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12");
721 		return ENXIO;
722 	}
723 
724 	/* LAC-98's system bus width is 8-bit.  */
725 	sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x2KB
726 			| FE_D6_BBW_BYTE | FE_D6_SBW_BYTE | FE_D6_SRAM_150ns;
727 
728 	/* Setup hooks.  We need a special initialization procedure.  */
729 	sc->init = fe_init_lnx;
730 
731 	return 0;
732 }
733 
734 
735 /*
736  * Probe for Gateway Communications' old cards.
737  * (both as Generic MB86960 probe routine)
738  */
739 static int
fe_probe_gwy(device_t dev)740 fe_probe_gwy(device_t dev)
741 {
742 	struct fe_softc *sc = device_get_softc(dev);
743 
744 	static struct fe_simple_probe_struct probe_table [] = {
745 	    /*	{ FE_DLCR2, 0x70, 0x00 }, */
746 		{ FE_DLCR2, 0x58, 0x00 },
747 		{ FE_DLCR4, 0x08, 0x00 },
748 		{ 0 }
749 	};
750 
751 	/*
752 	 * XXX
753 	 * I'm not sure which address is possible, so accepts any.
754 	 */
755 
756 	if (fe98_alloc_port(dev, FE_TYPE_GWY))
757 		return ENXIO;
758 
759 	/* Fill the softc struct with default values.  */
760 	fe_softc_defaults(sc);
761 
762 	/* See if the card is on its address.  */
763 	if (!fe_simple_probe(sc, probe_table))
764 		return ENXIO;
765 
766 	/* Get our station address from EEPROM. */
767 	fe_inblk(sc, 0x18, sc->enaddr, ETHER_ADDR_LEN);
768 	if (!fe_valid_Ether_p(sc->enaddr, 0x000000))
769 		return ENXIO;
770 
771 	/* Determine the card type.  */
772 	sc->typestr = "Generic MB86960 Ethernet";
773 	if (fe_valid_Ether_p(sc->enaddr, 0x000061))
774 		sc->typestr = "Gateway Ethernet (Fujitsu chipset)";
775 
776 	/* Gateway's board requires an explicit IRQ to work, since it
777 	   is not possible to probe the setting of jumpers.  */
778 	if (bus_get_resource(dev, SYS_RES_IRQ, 0, NULL, NULL) != 0) {
779 		fe_irq_failure(sc->typestr, sc->sc_unit, NO_IRQ, NULL);
780 		return ENXIO;
781 	}
782 
783 	return 0;
784 }
785 
786 
787 /*
788  * Probe for Ungermann-Bass Access/PC N98C+(Model 85152).
789  */
790 static int
fe_probe_ubn(device_t dev)791 fe_probe_ubn(device_t dev)
792 {
793 	struct fe_softc *sc = device_get_softc(dev);
794 
795 	u_char sum, save7;
796 	u_long iobase, irq;
797 	int i;
798 	static struct fe_simple_probe_struct const probe_table [] = {
799 		{ FE_DLCR2, 0x58, 0x00 },
800 		{ FE_DLCR4, 0x08, 0x00 },
801 		{ 0 }
802 	};
803 
804 	/* See if the specified I/O address is possible for Access/PC.  */
805 	/* [01][048C]D0 are allowed.  */
806 	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
807 		return ENXIO;
808 	if ((iobase & ~0x1C00) != 0xD0)
809 		return ENXIO;
810 
811 	if (fe98_alloc_port(dev, FE_TYPE_UBN))
812 		return ENXIO;
813 
814 	/* Fill the softc struct with default values.  */
815 	fe_softc_defaults(sc);
816 
817 	/* Simple probe.  */
818 	if (!fe_simple_probe(sc, probe_table))
819 		return ENXIO;
820 
821 	/* NOTE: Access/NOTE N98 sometimes freeze when reading station
822 	   address.  In case of using it togather with C-NET(9N)C,
823 	   this problem usually happens.
824 	   Writing DLCR7 prevents freezing, but I don't know why.  FIXME.  */
825 
826 	/* Save the current value for the DLCR7 register we are about
827 	   to destroy.  */
828 	save7 = fe_inb(sc, FE_DLCR7);
829 	fe_outb(sc, FE_DLCR7,
830 		sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
831 
832 	/* Get our station address form ID ROM and make sure it is UBN's.  */
833 	fe_inblk(sc, 0x18, sc->enaddr, ETHER_ADDR_LEN);
834 	if (!fe_valid_Ether_p(sc->enaddr, 0x00DD01))
835 		goto fail_ubn;
836 #if 1
837 	/* Calculate checksum.  */
838 	sum = fe_inb(sc, 0x1e);
839 	for (i = 0; i < ETHER_ADDR_LEN; i++)
840 		sum ^= sc->enaddr[i];
841 	if (sum != 0)
842 		goto fail_ubn;
843 #endif
844 
845 	/* Setup the board type.  */
846 	sc->typestr = "Access/PC";
847 
848 	/* This looks like an AccessPC/N98C+ board.  It requires an
849 	   explicit IRQ setting in config.  Make sure we have one,
850 	   determining an appropriate value for the IRQ control
851 	   register.  */
852 	irq = 0;
853 	bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
854 	switch (irq) {
855 	case 3:  sc->priv_info = 0x01; break;
856 	case 5:  sc->priv_info = 0x02; break;
857 	case 6:  sc->priv_info = 0x04; break;
858 	case 12: sc->priv_info = 0x08; break;
859 	default:
860 		fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12");
861 		goto fail_ubn;
862 	}
863 
864 	/* Setup hooks.  We need a special initialization procedure.  */
865 	sc->init = fe_init_ubn;
866 
867 	return 0;
868 
869 fail_ubn:
870 	fe_outb(sc, FE_DLCR7, save7);
871 	return ENXIO;
872 }
873 
874 
875 /*
876  * REX boards(non-JLI type) support routine.
877  */
878 
879 #define REX_EEPROM_SIZE	32
880 #define REX_DAT	0x01
881 
882 static void
fe_read_eeprom_rex(struct fe_softc * sc,u_char * data)883 fe_read_eeprom_rex(struct fe_softc *sc, u_char *data)
884 {
885 	int i;
886 	u_char bit, val;
887 	u_char save16;
888 
889 	save16 = fe_inb(sc, 0x10);
890 
891 	/* Issue a start condition.  */
892 	val = fe_inb(sc, 0x10) & 0xf0;
893 	fe_outb(sc, 0x10, val);
894 
895 	(void) fe_inb(sc, 0x10);
896 	(void) fe_inb(sc, 0x10);
897 	(void) fe_inb(sc, 0x10);
898 	(void) fe_inb(sc, 0x10);
899 
900 	/* Read bytes from EEPROM.  */
901 	for (i = 0; i < REX_EEPROM_SIZE; i++) {
902 		/* Read a byte and store it into the buffer.  */
903 		val = 0x00;
904 		for (bit = 0x01; bit != 0x00; bit <<= 1)
905 			if (fe_inb(sc, 0x10) & REX_DAT)
906 				val |= bit;
907 		*data++ = val;
908 	}
909 
910 	fe_outb(sc, 0x10, save16);
911 
912 #if 1
913 	/* Report what we got.  */
914 	if (bootverbose) {
915 		data -= REX_EEPROM_SIZE;
916 		for (i = 0; i < REX_EEPROM_SIZE; i += 16) {
917 			printf("fe%d: EEPROM(REX):%3x: %16D\n",
918 			       sc->sc_unit, i, data + i, " ");
919 		}
920 	}
921 #endif
922 }
923 
924 
925 static void
fe_init_rex(struct fe_softc * sc)926 fe_init_rex(struct fe_softc *sc)
927 {
928 	/* Setup IRQ control register on the ASIC.  */
929 	fe_outb(sc, 0x10, sc->priv_info);
930 }
931 
932 /*
933  * Probe for RATOC REX-9880/81/82/83 series.
934  */
935 static int
fe_probe_rex(device_t dev)936 fe_probe_rex(device_t dev)
937 {
938 	struct fe_softc *sc = device_get_softc(dev);
939 
940 	int i;
941 	u_long iobase, irq;
942 	u_char eeprom [REX_EEPROM_SIZE];
943 
944 	static struct fe_simple_probe_struct probe_table [] = {
945 		{ FE_DLCR2, 0x58, 0x00 },
946 		{ FE_DLCR4, 0x08, 0x00 },
947 		{ 0 }
948 	};
949 
950 	/* See if the specified I/O address is possible for REX-9880.  */
951 	/* 6[46CE]D0 are allowed.  */
952 	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
953 		return ENXIO;
954 	if ((iobase & ~0xA00) != 0x64D0)
955 		return ENXIO;
956 
957 	if (fe98_alloc_port(dev, FE_TYPE_REX))
958 		return ENXIO;
959 
960 	/* Fill the softc struct with default values.  */
961 	fe_softc_defaults(sc);
962 
963 	/* See if the card is on its address.  */
964 	if (!fe_simple_probe(sc, probe_table))
965 		return ENXIO;
966 
967 	/* We now have to read the config EEPROM.  We should be very
968            careful, since doing so destroys a register.  (Remember, we
969            are not yet sure we have a REX-9880 board here.)  */
970 	fe_read_eeprom_rex(sc, eeprom);
971 	for (i = 0; i < ETHER_ADDR_LEN; i++)
972 		sc->enaddr[i] = eeprom[7 - i];
973 
974 	/* Make sure it is RATOC's.  */
975 	if (!fe_valid_Ether_p(sc->enaddr, 0x00C0D0) &&
976 	    !fe_valid_Ether_p(sc->enaddr, 0x00803D))
977 		return 0;
978 
979 	/* Setup the board type.  */
980 	sc->typestr = "REX-9880/9883";
981 
982 	/* This looks like a REX-9880 board.  It requires an
983 	   explicit IRQ setting in config.  Make sure we have one,
984 	   determining an appropriate value for the IRQ control
985 	   register.  */
986 	irq = 0;
987 	bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
988 	switch (irq) {
989 	case 3:  sc->priv_info = 0x10; break;
990 	case 5:  sc->priv_info = 0x20; break;
991 	case 6:  sc->priv_info = 0x40; break;
992 	case 12: sc->priv_info = 0x80; break;
993 	default:
994 		fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12");
995 		return ENXIO;
996 	}
997 
998 	/* Setup hooks.  We need a special initialization procedure.  */
999 	sc->init = fe_init_rex;
1000 
1001 	/* REX-9880 has 64KB SRAM.  */
1002 	sc->proto_dlcr6 = FE_D6_BUFSIZ_64KB | FE_D6_TXBSIZ_2x4KB
1003 			| FE_D6_BBW_WORD | FE_D6_SBW_WORD | FE_D6_SRAM;
1004 #if 1
1005 	sc->proto_dlcr7 |= FE_D7_EOPPOL;	/* XXX */
1006 #endif
1007 
1008 	return 0;
1009 }
1010