if_fe_cbus.c revision 68566
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 68566 2000-11-10 14:05:47Z 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[16];
226		size = 16;
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	switch (type) {
261	case FE_TYPE_CNET9NE:
262		iat = ioaddr_cnet9ne;
263		size = MAXREGISTERS;
264		break;
265	}
266
267	isa_load_resourcev(res, iat, size);
268
269	sc->type = type;
270	sc->port_used = size;
271	sc->port_res = res;
272	sc->iot = rman_get_bustag(res);
273	sc->ioh = rman_get_bushandle(res);
274	return (0);
275}
276
277
278/*
279 * Probe and initialization for Allied-Telesis RE1000 series.
280 */
281static void
282fe_init_re1000(struct fe_softc *sc)
283{
284	/* Setup IRQ control register on the ASIC.  */
285	fe_outb(sc, FE_RE1000_IRQCONF, sc->priv_info);
286}
287
288static int
289fe_probe_re1000(device_t dev)
290{
291	struct fe_softc *sc = device_get_softc(dev);
292	int i, n;
293	u_long iobase, irq;
294	u_char sum;
295
296	static struct fe_simple_probe_struct probe_table [] = {
297		{ FE_DLCR2, 0x58, 0x00 },
298		{ FE_DLCR4, 0x08, 0x00 },
299		{ 0 }
300	};
301
302	/* See if the specified I/O address is possible for RE1000.  */
303	/* [01]D[02468ACE] are allowed.  */
304	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
305		return ENXIO;
306	if ((iobase & ~0x10E) != 0xD0)
307		return ENXIO;
308
309	if (fe98_alloc_port(dev, FE_TYPE_RE1000))
310		return ENXIO;
311
312	/* Fill the softc struct with default values.  */
313	fe_softc_defaults(sc);
314
315	/* See if the card is on its address.  */
316	if (!fe_simple_probe(sc, probe_table))
317		return ENXIO;
318
319	/* Get our station address from EEPROM.  */
320	fe_inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN);
321
322	/* Make sure it is Allied-Telesis's.  */
323	if (!valid_Ether_p(sc->sc_enaddr, 0x0000F4))
324		return ENXIO;
325#if 1
326	/* Calculate checksum.  */
327	sum = fe_inb(sc, 0x1e);
328	for (i = 0; i < ETHER_ADDR_LEN; i++)
329		sum ^= sc->sc_enaddr[i];
330	if (sum != 0)
331		return ENXIO;
332#endif
333	/* Setup the board type.  */
334	sc->typestr = "RE1000";
335
336	/* This looks like an RE1000 board.  It requires an
337	   explicit IRQ setting in config.  Make sure we have one,
338	   determining an appropriate value for the IRQ control
339	   register.  */
340	irq = 0;
341	bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
342	switch (irq) {
343	case 3:  n = 0x10; break;
344	case 5:  n = 0x20; break;
345	case 6:  n = 0x40; break;
346	case 12: n = 0x80; break;
347	default:
348		fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12");
349		return ENXIO;
350	}
351	sc->priv_info = (fe_inb(sc, FE_RE1000_IRQCONF) & 0x0f) | n;
352
353	/* Setup hooks.  We need a special initialization procedure.  */
354	sc->init = fe_init_re1000;
355
356	return 0;
357}
358
359/* JLI sub-probe for Allied-Telesis RE1000Plus/ME1500 series.  */
360static u_short const *
361fe_probe_jli_re1000p(struct fe_softc * sc, u_char const * eeprom)
362{
363	int i;
364	static u_short const irqmaps_re1000p [4] = { 3, 5, 6, 12 };
365
366	/* Make sure the EEPROM contains Allied-Telesis bit pattern.  */
367	if (eeprom[1] != 0xFF) return NULL;
368	for (i =  2; i <  8; i++) if (eeprom[i] != 0xFF) return NULL;
369	for (i = 14; i < 24; i++) if (eeprom[i] != 0xFF) return NULL;
370
371	/* Get our station address from EEPROM, and make sure the
372           EEPROM contains Allied-Telesis's address.  */
373	bcopy(eeprom + 8, sc->sc_enaddr, ETHER_ADDR_LEN);
374	if (!valid_Ether_p(sc->sc_enaddr, 0x0000F4))
375		return NULL;
376
377	/* I don't know any sub-model identification.  */
378	sc->typestr = "RE1000Plus/ME1500";
379
380	/* Returns the IRQ table for the RE1000Plus.  */
381	return irqmaps_re1000p;
382}
383
384
385/*
386 * Probe for Allied-Telesis RE1000Plus/ME1500 series.
387 */
388static int
389fe_probe_jli(device_t dev)
390{
391	struct fe_softc *sc = device_get_softc(dev);
392	int i, n, xirq, error;
393	u_long iobase, irq;
394	u_char eeprom [JLI_EEPROM_SIZE];
395	u_short const * irqmap;
396
397	static u_short const baseaddr [8] =
398		{ 0x1D6, 0x1D8, 0x1DA, 0x1D4, 0x0D4, 0x0D2, 0x0D8, 0x0D0 };
399	static struct fe_simple_probe_struct const probe_table [] = {
400	/*	{ FE_DLCR1,  0x20, 0x00 },	Doesn't work. */
401		{ FE_DLCR2,  0x50, 0x00 },
402		{ FE_DLCR4,  0x08, 0x00 },
403	/*	{ FE_DLCR5,  0x80, 0x00 },	Doesn't work. */
404#if 0
405		{ FE_BMPR16, 0x1B, 0x00 },
406		{ FE_BMPR17, 0x7F, 0x00 },
407#endif
408		{ 0 }
409	};
410
411	/*
412	 * See if the specified address is possible for MB86965A JLI mode.
413	 */
414	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
415		return ENXIO;
416	for (i = 0; i < 8; i++) {
417		if (baseaddr[i] == iobase)
418			break;
419	}
420	if (i == 8)
421		return ENXIO;
422
423	if (fe98_alloc_port(dev, FE_TYPE_RE1000))
424		return ENXIO;
425
426	/* Fill the softc struct with default values.  */
427	fe_softc_defaults(sc);
428
429	/*
430	 * We should test if MB86965A is on the base address now.
431	 * Unfortunately, it is very hard to probe it reliably, since
432	 * we have no way to reset the chip under software control.
433	 * On cold boot, we could check the "signature" bit patterns
434	 * described in the Fujitsu document.  On warm boot, however,
435	 * we can predict almost nothing about register values.
436	 */
437	if (!fe_simple_probe(sc, probe_table))
438		return ENXIO;
439
440	/* Check if our I/O address matches config info on 86965.  */
441	n = (fe_inb(sc, FE_BMPR19) & FE_B19_ADDR) >> FE_B19_ADDR_SHIFT;
442	if (baseaddr[n] != iobase)
443		return ENXIO;
444
445	/*
446	 * We are now almost sure we have an MB86965 at the given
447	 * address.  So, read EEPROM through it.  We have to write
448	 * into LSI registers to read from EEPROM.  I want to avoid it
449	 * at this stage, but I cannot test the presence of the chip
450	 * any further without reading EEPROM.  FIXME.
451	 */
452	fe_read_eeprom_jli(sc, eeprom);
453
454	/* Make sure that config info in EEPROM and 86965 agree.  */
455	if (eeprom[FE_EEPROM_CONF] != fe_inb(sc, FE_BMPR19))
456		return ENXIO;
457
458	/* Use 86965 media selection scheme, unless othewise
459           specified.  It is "AUTO always" and "select with BMPR13".
460           This behaviour covers most of the 86965 based board (as
461           minimum requirements.)  It is backward compatible with
462           previous versions, also.  */
463	sc->mbitmap = MB_HA;
464	sc->defmedia = MB_HA;
465	sc->msel = fe_msel_965;
466
467	/* Perform board-specific probe.  */
468	if ((irqmap = fe_probe_jli_re1000p(sc, eeprom)) == NULL)
469		return ENXIO;
470
471	/* Find the IRQ read from EEPROM.  */
472	n = (fe_inb(sc, FE_BMPR19) & FE_B19_IRQ) >> FE_B19_IRQ_SHIFT;
473	xirq = irqmap[n];
474
475	/* Try to determine IRQ setting.  */
476	error = bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
477	if (error && xirq == NO_IRQ) {
478		/* The device must be configured with an explicit IRQ.  */
479		device_printf(dev, "IRQ auto-detection does not work\n");
480		return ENXIO;
481	} else if (error && xirq != NO_IRQ) {
482		/* Just use the probed IRQ value.  */
483		bus_set_resource(dev, SYS_RES_IRQ, 0, xirq, 1);
484	} else if (!error && xirq == NO_IRQ) {
485		/* No problem.  Go ahead.  */
486	} else if (irq == xirq) {
487		/* Good.  Go ahead.  */
488	} else {
489		/* User must be warned in this case.  */
490		sc->stability |= UNSTABLE_IRQ;
491	}
492
493	/* Setup a hook, which resets te 86965 when the driver is being
494           initialized.  This may solve a nasty bug.  FIXME.  */
495	sc->init = fe_init_jli;
496
497	return 0;
498}
499
500
501/*
502 * Probe and initialization for Contec C-NET(9N)E series.
503 */
504
505/* TODO: Should be in "if_fereg.h" */
506#define FE_CNET9NE_INTR		0x10		/* Interrupt Mask? */
507
508static void
509fe_init_cnet9ne(struct fe_softc *sc)
510{
511	/* Enable interrupt?  FIXME.  */
512	fe_outb(sc, FE_CNET9NE_INTR, 0x10);
513}
514
515static int
516fe_probe_cnet9ne (device_t dev)
517{
518	struct fe_softc *sc = device_get_softc(dev);
519	u_long iobase, irq;
520
521	static struct fe_simple_probe_struct probe_table [] = {
522		{ FE_DLCR2, 0x58, 0x00 },
523		{ FE_DLCR4, 0x08, 0x00 },
524		{ 0 }
525	};
526
527	/* See if the specified I/O address is possible for C-NET(9N)E.  */
528	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
529		return ENXIO;
530	if (iobase != 0x73D0)
531		return ENXIO;
532
533	if (fe98_alloc_port(dev, FE_TYPE_CNET9NE))
534		return ENXIO;
535
536	/* Fill the softc struct with default values.  */
537	fe_softc_defaults(sc);
538
539	/* See if the card is on its address.  */
540	if (!fe_simple_probe(sc, probe_table))
541		return ENXIO;
542
543	/* Get our station address from EEPROM.  */
544	fe_inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN);
545
546	/* Make sure it is Contec's.  */
547	if (!valid_Ether_p(sc->sc_enaddr, 0x00804C))
548		return ENXIO;
549
550	/* Determine the card type.  */
551	if (sc->sc_enaddr[3] == 0x06) {
552		sc->typestr = "C-NET(9N)C";
553
554		/* We seems to need our own IDENT bits...  FIXME.  */
555		sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
556
557		/* C-NET(9N)C requires an explicit IRQ to work.  */
558		if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0) {
559			fe_irq_failure(sc->typestr, sc->sc_unit, NO_IRQ, NULL);
560			return ENXIO;
561		}
562	} else {
563		sc->typestr = "C-NET(9N)E";
564
565		/* C-NET(9N)E works only IRQ5.  */
566		if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0)
567			return ENXIO;
568		if (irq != 5) {
569			fe_irq_failure(sc->typestr, sc->sc_unit, irq, "5");
570			return ENXIO;
571		}
572
573		/* We need an init hook to initialize ASIC before we start.  */
574		sc->init = fe_init_cnet9ne;
575	}
576
577	/* C-NET(9N)E has 64KB SRAM.  */
578	sc->proto_dlcr6 = FE_D6_BUFSIZ_64KB | FE_D6_TXBSIZ_2x4KB
579			| FE_D6_BBW_WORD | FE_D6_SBW_WORD | FE_D6_SRAM;
580
581	return 0;
582}
583
584
585/*
586 * Probe for Contec C-NET(98)P2 series.
587 * (Logitec LAN-98TP/LAN-98T25P - parhaps)
588 */
589static int
590fe_probe_ssi(device_t dev)
591{
592	struct fe_softc *sc = device_get_softc(dev);
593	u_long iobase, irq;
594
595	u_char eeprom [SSI_EEPROM_SIZE];
596	static struct fe_simple_probe_struct probe_table [] = {
597		{ FE_DLCR2, 0x08, 0x00 },
598		{ FE_DLCR4, 0x08, 0x00 },
599		{ 0 }
600	};
601	static u_short const irqmap[] = {
602		/*                        INT0          INT1    INT2       */
603		NO_IRQ, NO_IRQ, NO_IRQ,      3, NO_IRQ,    5,      6, NO_IRQ,
604		NO_IRQ,      9,     10, NO_IRQ,     12,   13, NO_IRQ, NO_IRQ,
605		/*        INT3   INT41            INT5  INT6               */
606	};
607
608	/* See if the specified I/O address is possible for 78Q8377A.  */
609	/* [0-D]3D0 are allowed.  */
610	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
611		return ENXIO;
612	if ((iobase & 0xFFF) != 0x3D0)
613		return ENXIO;
614
615	if (fe98_alloc_port(dev, FE_TYPE_SSI))
616		return ENXIO;
617
618	/* Fill the softc struct with default values.  */
619	fe_softc_defaults(sc);
620
621	/* See if the card is on its address.  */
622	if (!fe_simple_probe(sc, probe_table))
623		return ENXIO;
624
625	/* We now have to read the config EEPROM.  We should be very
626           careful, since doing so destroys a register.  (Remember, we
627           are not yet sure we have a C-NET(98)P2 board here.)  Don't
628           remember to select BMPRs bofore reading EEPROM, since other
629           register bank may be selected before the probe() is called.  */
630	fe_read_eeprom_ssi(sc, eeprom);
631
632	/* Make sure the Ethernet (MAC) station address is of Contec's.  */
633	if (!valid_Ether_p(eeprom + FE_SSI_EEP_ADDR, 0x00804C))
634		return ENXIO;
635	bcopy(eeprom + FE_SSI_EEP_ADDR, sc->sc_enaddr, ETHER_ADDR_LEN);
636
637	/* Setup the board type.  */
638        sc->typestr = "C-NET(98)P2";
639
640	/* Get IRQ configuration from EEPROM.  */
641	irq = irqmap[eeprom[FE_SSI_EEP_IRQ]];
642	if (irq == NO_IRQ) {
643		fe_irq_failure(sc->typestr, sc->sc_unit, irq,
644			       "3/5/6/9/10/12/13");
645		return ENXIO;
646	}
647	bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1);
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 */
663static int
664fe_probe_lnx(device_t dev)
665{
666#ifndef FE_8BIT_SUPPORT
667	device_printf(dev,
668		      "skip LAC-98012/013(only 16-bit cards are supported)\n");
669	return ENXIO;
670#else
671	struct fe_softc *sc = device_get_softc(dev);
672
673	u_long iobase, irq;
674	u_char eeprom [LNX_EEPROM_SIZE];
675
676	static struct fe_simple_probe_struct probe_table [] = {
677		{ FE_DLCR2, 0x58, 0x00 },
678		{ FE_DLCR4, 0x08, 0x00 },
679		{ 0 }
680	};
681
682	/* See if the specified I/O address is possible for TDK/LANX boards. */
683	/* 0D0, 4D0, 8D0, and CD0 are allowed.  */
684	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
685		return ENXIO;
686	if ((iobase & ~0xC00) != 0xD0)
687		return ENXIO;
688
689	if (fe98_alloc_port(dev, FE_TYPE_LNX))
690		return ENXIO;
691
692	/* Fill the softc struct with default values.  */
693	fe_softc_defaults(sc);
694
695	/* See if the card is on its address.  */
696	if (!fe_simple_probe(sc, probe_table))
697		return ENXIO;
698
699	/* We now have to read the config EEPROM.  We should be very
700           careful, since doing so destroys a register.  (Remember, we
701           are not yet sure we have a LAC-98012/98013 board here.)  */
702	fe_read_eeprom_lnx(sc, eeprom);
703
704	/* Make sure the Ethernet (MAC) station address is of TDK/LANX's.  */
705	if (!valid_Ether_p(eeprom, 0x008098))
706		return ENXIO;
707	bcopy(eeprom, sc->sc_enaddr, ETHER_ADDR_LEN);
708
709	/* Setup the board type.  */
710	sc->typestr = "LAC-98012/98013";
711
712	/* This looks like a TDK/LANX board.  It requires an
713	   explicit IRQ setting in config.  Make sure we have one,
714	   determining an appropriate value for the IRQ control
715	   register.  */
716	irq = 0;
717	if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0)
718		return ENXIO;
719	switch (irq) {
720	case 3 : sc->priv_info = 0x10 | LNX_CLK_LO | LNX_SDA_HI; break;
721	case 5 : sc->priv_info = 0x20 | LNX_CLK_LO | LNX_SDA_HI; break;
722	case 6 : sc->priv_info = 0x40 | LNX_CLK_LO | LNX_SDA_HI; break;
723	case 12: sc->priv_info = 0x80 | LNX_CLK_LO | LNX_SDA_HI; break;
724	default:
725		fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12");
726		return ENXIO;
727	}
728
729	/* LAC-98's system bus width is 8-bit.  */
730	sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x2KB
731			| FE_D6_BBW_BYTE | FE_D6_SBW_BYTE | FE_D6_SRAM_150ns;
732
733	/* Setup hooks.  We need a special initialization procedure.  */
734	sc->init = fe_init_lnx;
735
736	return 0;
737#endif /* FE_8BIT_SUPPORT */
738}
739
740
741/*
742 * Probe for Gateway Communications' old cards.
743 * (both as Generic MB86960 probe routine)
744 */
745static int
746fe_probe_gwy(device_t dev)
747{
748	struct fe_softc *sc = device_get_softc(dev);
749
750	static struct fe_simple_probe_struct probe_table [] = {
751	    /*	{ FE_DLCR2, 0x70, 0x00 }, */
752		{ FE_DLCR2, 0x58, 0x00 },
753		{ FE_DLCR4, 0x08, 0x00 },
754		{ 0 }
755	};
756
757	/*
758	 * XXX
759	 * I'm not sure which address is possible, so accepts any.
760	 */
761
762	if (fe98_alloc_port(dev, FE_TYPE_GWY))
763		return ENXIO;
764
765	/* Fill the softc struct with default values.  */
766	fe_softc_defaults(sc);
767
768	/* See if the card is on its address.  */
769	if (!fe_simple_probe(sc, probe_table))
770		return ENXIO;
771
772	/* Get our station address from EEPROM. */
773	fe_inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN);
774	if (!valid_Ether_p(sc->sc_enaddr, 0x000000))
775		return ENXIO;
776
777	/* Determine the card type.  */
778	sc->typestr = "Generic MB86960 Ethernet";
779	if (valid_Ether_p(sc->sc_enaddr, 0x000061))
780		sc->typestr = "Gateway Ethernet (Fujitsu chipset)";
781
782	/* Gateway's board requires an explicit IRQ to work, since it
783	   is not possible to probe the setting of jumpers.  */
784	if (bus_get_resource(dev, SYS_RES_IRQ, 0, NULL, NULL) != 0) {
785		fe_irq_failure(sc->typestr, sc->sc_unit, NO_IRQ, NULL);
786		return ENXIO;
787	}
788
789	return 0;
790}
791
792
793/*
794 * Probe for Ungermann-Bass Access/PC N98C+(Model 85152).
795 */
796static int
797fe_probe_ubn(device_t dev)
798{
799	struct fe_softc *sc = device_get_softc(dev);
800
801	u_char sum, save7;
802	u_long iobase, irq;
803	int i;
804	static struct fe_simple_probe_struct const probe_table [] = {
805		{ FE_DLCR2, 0x58, 0x00 },
806		{ FE_DLCR4, 0x08, 0x00 },
807		{ 0 }
808	};
809
810	/* See if the specified I/O address is possible for Access/PC.  */
811	/* [01][048C]D0 are allowed.  */
812	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
813		return ENXIO;
814	if ((iobase & ~0x1C00) != 0xD0)
815		return ENXIO;
816
817	if (fe98_alloc_port(dev, FE_TYPE_UBN))
818		return ENXIO;
819
820	/* Fill the softc struct with default values.  */
821	fe_softc_defaults(sc);
822
823	/* Simple probe.  */
824	if (!fe_simple_probe(sc, probe_table))
825		return ENXIO;
826
827	/* NOTE: Access/NOTE N98 sometimes freeze when reading station
828	   address.  In case of using it togather with C-NET(9N)C,
829	   this problem usually happens.
830	   Writing DLCR7 prevents freezing, but I don't know why.  FIXME.  */
831
832	/* Save the current value for the DLCR7 register we are about
833	   to destroy.  */
834	save7 = fe_inb(sc, FE_DLCR7);
835	fe_outb(sc, FE_DLCR7,
836		sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
837
838	/* Get our station address form ID ROM and make sure it is UBN's.  */
839	fe_inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN);
840	if (!valid_Ether_p(sc->sc_enaddr, 0x00DD01))
841		goto fail_ubn;
842#if 1
843	/* Calculate checksum.  */
844	sum = fe_inb(sc, 0x1e);
845	for (i = 0; i < ETHER_ADDR_LEN; i++)
846		sum ^= sc->sc_enaddr[i];
847	if (sum != 0)
848		goto fail_ubn;
849#endif
850
851	/* Setup the board type.  */
852	sc->typestr = "Access/PC";
853
854	/* This looks like an AccessPC/N98C+ board.  It requires an
855	   explicit IRQ setting in config.  Make sure we have one,
856	   determining an appropriate value for the IRQ control
857	   register.  */
858	irq = 0;
859	bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
860	switch (irq) {
861	case 3:  sc->priv_info = 0x01; break;
862	case 5:  sc->priv_info = 0x02; break;
863	case 6:  sc->priv_info = 0x04; break;
864	case 12: sc->priv_info = 0x08; break;
865	default:
866		fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12");
867		goto fail_ubn;
868	}
869
870	/* Setup hooks.  We need a special initialization procedure.  */
871	sc->init = fe_init_ubn;
872
873	return 0;
874
875fail_ubn:
876	fe_outb(sc, FE_DLCR7, save7);
877	return ENXIO;
878}
879
880
881/*
882 * REX boards(non-JLI type) support routine.
883 */
884
885#define REX_EEPROM_SIZE	32
886#define REX_DAT	0x01
887
888static void
889fe_read_eeprom_rex(struct fe_softc *sc, u_char *data)
890{
891	int i;
892	u_char bit, val;
893	u_char save16;
894
895	save16 = fe_inb(sc, 0x10);
896
897	/* Issue a start condition.  */
898	val = fe_inb(sc, 0x10) & 0xf0;
899	fe_outb(sc, 0x10, val);
900
901	(void) fe_inb(sc, 0x10);
902	(void) fe_inb(sc, 0x10);
903	(void) fe_inb(sc, 0x10);
904	(void) fe_inb(sc, 0x10);
905
906	/* Read bytes from EEPROM.  */
907	for (i = 0; i < REX_EEPROM_SIZE; i++) {
908		/* Read a byte and store it into the buffer.  */
909		val = 0x00;
910		for (bit = 0x01; bit != 0x00; bit <<= 1)
911			if (fe_inb(sc, 0x10) & REX_DAT)
912				val |= bit;
913		*data++ = val;
914	}
915
916	fe_outb(sc, 0x10, save16);
917
918#if 1
919	/* Report what we got.  */
920	if (bootverbose) {
921		data -= REX_EEPROM_SIZE;
922		for (i = 0; i < REX_EEPROM_SIZE; i += 16) {
923			printf("fe%d: EEPROM(REX):%3x: %16D\n",
924			       sc->sc_unit, i, data + i, " ");
925		}
926	}
927#endif
928}
929
930
931static void
932fe_init_rex(struct fe_softc *sc)
933{
934	/* Setup IRQ control register on the ASIC.  */
935	fe_outb(sc, 0x10, sc->priv_info);
936}
937
938/*
939 * Probe for RATOC REX-9880/81/82/83 series.
940 */
941static int
942fe_probe_rex(device_t dev)
943{
944	struct fe_softc *sc = device_get_softc(dev);
945
946	int i;
947	u_long iobase, irq;
948	u_char eeprom [REX_EEPROM_SIZE];
949
950	static struct fe_simple_probe_struct probe_table [] = {
951		{ FE_DLCR2, 0x58, 0x00 },
952		{ FE_DLCR4, 0x08, 0x00 },
953		{ 0 }
954	};
955
956	/* See if the specified I/O address is possible for REX-9880.  */
957	/* 6[46CE]D0 are allowed.  */
958	if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
959		return ENXIO;
960	if ((iobase & ~0xA00) != 0x64D0)
961		return ENXIO;
962
963	if (fe98_alloc_port(dev, FE_TYPE_REX))
964		return ENXIO;
965
966	/* Fill the softc struct with default values.  */
967	fe_softc_defaults(sc);
968
969	/* See if the card is on its address.  */
970	if (!fe_simple_probe(sc, probe_table))
971		return ENXIO;
972
973	/* We now have to read the config EEPROM.  We should be very
974           careful, since doing so destroys a register.  (Remember, we
975           are not yet sure we have a REX-9880 board here.)  */
976	fe_read_eeprom_rex(sc, eeprom);
977	for (i = 0; i < ETHER_ADDR_LEN; i++)
978		sc->sc_enaddr[i] = eeprom[7 - i];
979
980	/* Make sure it is RATOC's.  */
981	if (!valid_Ether_p(sc->sc_enaddr, 0x00C0D0) &&
982	    !valid_Ether_p(sc->sc_enaddr, 0x00803D))
983		return 0;
984
985	/* Setup the board type.  */
986	sc->typestr = "REX-9880/9883";
987
988	/* This looks like a REX-9880 board.  It requires an
989	   explicit IRQ setting in config.  Make sure we have one,
990	   determining an appropriate value for the IRQ control
991	   register.  */
992	irq = 0;
993	bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
994	switch (irq) {
995	case 3:  sc->priv_info = 0x10; break;
996	case 5:  sc->priv_info = 0x20; break;
997	case 6:  sc->priv_info = 0x40; break;
998	case 12: sc->priv_info = 0x80; break;
999	default:
1000		fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12");
1001		return ENXIO;
1002	}
1003
1004	/* Setup hooks.  We need a special initialization procedure.  */
1005	sc->init = fe_init_rex;
1006
1007	/* REX-9880 has 64KB SRAM.  */
1008	sc->proto_dlcr6 = FE_D6_BUFSIZ_64KB | FE_D6_TXBSIZ_2x4KB
1009			| FE_D6_BBW_WORD | FE_D6_SBW_WORD | FE_D6_SRAM;
1010#if 1
1011	sc->proto_dlcr7 |= FE_D7_EOPPOL;	/* XXX */
1012#endif
1013
1014	return 0;
1015}
1016