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