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