]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/fe/if_fe_isa.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / fe / if_fe_isa.c
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$");
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  *      ISA specific code.
53  */
54 static int fe_isa_probe(device_t);
55 static int fe_isa_attach(device_t);
56
57 static device_method_t fe_isa_methods[] = {
58         /* Device interface */
59         DEVMETHOD(device_probe,         fe_isa_probe),
60         DEVMETHOD(device_attach,        fe_isa_attach),
61
62         { 0, 0 }
63 };
64
65 static driver_t fe_isa_driver = {
66         "fe",
67         fe_isa_methods,
68         sizeof (struct fe_softc)
69 };
70
71 DRIVER_MODULE(fe, isa, fe_isa_driver, fe_devclass, 0, 0);
72
73
74 static int fe_probe_ssi(device_t);
75 static int fe_probe_jli(device_t);
76 static int fe_probe_fmv(device_t);
77 static int fe_probe_lnx(device_t);
78 static int fe_probe_gwy(device_t);
79 static int fe_probe_ubn(device_t);
80
81 /*
82  * Determine if the device is present at a specified I/O address.  The
83  * main entry to the driver.
84  */
85 static int
86 fe_isa_probe(device_t dev)
87 {
88         struct fe_softc *sc;
89         int error;
90
91         /* Check isapnp ids */
92         if (isa_get_vendorid(dev))
93                 return (ENXIO);
94
95         /* Prepare for the softc struct.  */
96         sc = device_get_softc(dev);
97         sc->sc_unit = device_get_unit(dev);
98
99         /* Probe for supported boards.  */
100         if ((error = fe_probe_ssi(dev)) == 0)
101                 goto end;
102         fe_release_resource(dev);
103
104         if ((error = fe_probe_jli(dev)) == 0)
105                 goto end;
106         fe_release_resource(dev);
107
108         if ((error = fe_probe_fmv(dev)) == 0)
109                 goto end;
110         fe_release_resource(dev);
111
112         if ((error = fe_probe_lnx(dev)) == 0)
113                 goto end;
114         fe_release_resource(dev);
115
116         if ((error = fe_probe_ubn(dev)) == 0)
117                 goto end;
118         fe_release_resource(dev);
119
120         if ((error = fe_probe_gwy(dev)) == 0)
121                 goto end;
122         fe_release_resource(dev);
123
124 end:
125         if (error == 0)
126                 error = fe_alloc_irq(dev, 0);
127
128         fe_release_resource(dev);
129         return (error);
130 }
131
132 static int
133 fe_isa_attach(device_t dev)
134 {
135         struct fe_softc *sc = device_get_softc(dev);
136
137         if (sc->port_used)
138                 fe_alloc_port(dev, sc->port_used);
139         fe_alloc_irq(dev, 0);
140
141         return fe_attach(dev);
142 }
143
144
145 /*
146  * Probe and initialization for Fujitsu FMV-180 series boards
147  */
148
149 static void
150 fe_init_fmv(struct fe_softc *sc)
151 {
152         /* Initialize ASIC.  */
153         fe_outb(sc, FE_FMV3, 0);
154         fe_outb(sc, FE_FMV10, 0);
155
156 #if 0
157         /* "Refresh" hardware configuration.  FIXME.  */
158         fe_outb(sc, FE_FMV2, fe_inb(sc, FE_FMV2));
159 #endif
160
161         /* Turn the "master interrupt control" flag of ASIC on.  */
162         fe_outb(sc, FE_FMV3, FE_FMV3_IRQENB);
163 }
164
165 static void
166 fe_msel_fmv184(struct fe_softc *sc)
167 {
168         u_char port;
169
170         /* FMV-184 has a special "register" to switch between AUI/BNC.
171            Determine the value to write into the register, based on the
172            user-specified media selection.  */
173         port = (IFM_SUBTYPE(sc->media.ifm_media) == IFM_10_2) ? 0x00 : 0x01;
174
175         /* The register is #5 on exntesion register bank...
176            (Details of the register layout is not yet discovered.)  */
177         fe_outb(sc, 0x1B, 0x46);        /* ??? */
178         fe_outb(sc, 0x1E, 0x04);        /* select ex-reg #4.  */
179         fe_outb(sc, 0x1F, 0xC8);        /* ??? */
180         fe_outb(sc, 0x1E, 0x05);        /* select ex-reg #5.  */
181         fe_outb(sc, 0x1F, port);        /* Switch the media.  */
182         fe_outb(sc, 0x1E, 0x04);        /* select ex-reg #4.  */
183         fe_outb(sc, 0x1F, 0x00);        /* ??? */
184         fe_outb(sc, 0x1B, 0x00);        /* ??? */
185
186         /* Make sure to select "external tranceiver" on MB86964.  */
187         fe_outb(sc, FE_BMPR13, sc->proto_bmpr13 | FE_B13_PORT_AUI);
188 }
189
190 static int
191 fe_probe_fmv(device_t dev)
192 {
193         struct fe_softc *sc = device_get_softc(dev);
194         int n;
195         u_long iobase, irq;
196
197         static u_short const irqmap [ 4 ] = { 3, 7, 10, 15 };
198
199         static struct fe_simple_probe_struct const probe_table [] = {
200                 { FE_DLCR2, 0x71, 0x00 },
201                 { FE_DLCR4, 0x08, 0x00 },
202
203                 { FE_FMV0, 0x78, 0x50 },        /* ERRDY+PRRDY */
204                 { FE_FMV1, 0xB0, 0x00 },        /* FMV-183/4 has 0x48 bits. */
205                 { FE_FMV3, 0x7F, 0x00 },
206
207                 { 0 }
208         };
209
210         /* Board subtypes; it lists known FMV-180 variants.  */
211         struct subtype {
212                 u_short mcode;
213                 u_short mbitmap;
214                 u_short defmedia;
215                 char const * str;
216         };
217         static struct subtype const typelist [] = {
218             { 0x0005, MB_HA|MB_HT|MB_H5, MB_HA, "FMV-181"               },
219             { 0x0105, MB_HA|MB_HT|MB_H5, MB_HA, "FMV-181A"              },
220             { 0x0003, MB_HM,             MB_HM, "FMV-182"               },
221             { 0x0103, MB_HM,             MB_HM, "FMV-182A"              },
222             { 0x0804, MB_HT,             MB_HT, "FMV-183"               },
223             { 0x0C04, MB_HT,             MB_HT, "FMV-183 (on-board)"    },
224             { 0x0803, MB_H2|MB_H5,       MB_H2, "FMV-184"               },
225             { 0,      MB_HA,             MB_HA, "unknown FMV-180 (?)"   },
226         };
227         struct subtype const * type;
228
229         /* Media indicator and "Hardware revision ID"  */
230         u_short mcode;
231
232         /* See if the specified address is possible for FMV-180
233            series.  220, 240, 260, 280, 2A0, 2C0, 300, and 340 are
234            allowed for all boards, and 200, 2E0, 320, 360, 380, 3A0,
235            3C0, and 3E0 for PnP boards.  */
236         if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
237                 return ENXIO;
238         if ((iobase & ~0x1E0) != 0x200)
239                 return ENXIO;
240
241         /* FMV-180 occupies 32 I/O addresses. */
242         if (fe_alloc_port(dev, 32))
243                 return ENXIO;
244
245         /* Setup an I/O address mapping table and some others.  */
246         fe_softc_defaults(sc);
247
248         /* Simple probe.  */
249         if (!fe_simple_probe(sc, probe_table))
250                 return ENXIO;
251
252         /* Get our station address from EEPROM, and make sure it is
253            Fujitsu's.  */
254         fe_inblk(sc, FE_FMV4, sc->enaddr, ETHER_ADDR_LEN);
255         if (!fe_valid_Ether_p(sc->enaddr, 0x00000E))
256                 return ENXIO;
257
258         /* Find the supported media and "hardware revision" to know
259            the model identification.  */
260         mcode = (fe_inb(sc, FE_FMV0) & FE_FMV0_MEDIA)
261              | ((fe_inb(sc, FE_FMV1) & FE_FMV1_REV) << 8);
262
263         /* Determine the card type.  */
264         for (type = typelist; type->mcode != 0; type++) {
265                 if (type->mcode == mcode)
266                         break;
267         }
268         if (type->mcode == 0) {
269                 /* Unknown card type...  Hope the driver works.  */
270                 sc->stability |= UNSTABLE_TYPE;
271                 if (bootverbose) {
272                         device_printf(dev, "unknown config: %x-%x-%x-%x\n",
273                                       fe_inb(sc, FE_FMV0),
274                                       fe_inb(sc, FE_FMV1),
275                                       fe_inb(sc, FE_FMV2),
276                                       fe_inb(sc, FE_FMV3));
277                 }
278         }
279
280         /* Setup the board type and media information.  */
281         sc->type = FE_TYPE_FMV;
282         sc->typestr = type->str;
283         sc->mbitmap = type->mbitmap;
284         sc->defmedia = type->defmedia;
285         sc->msel = fe_msel_965;
286
287         if (type->mbitmap == (MB_H2 | MB_H5)) {
288                 /* FMV184 requires a special media selection procedure.  */
289                 sc->msel = fe_msel_fmv184;
290         }
291
292         /*
293          * An FMV-180 has been probed.
294          * Determine which IRQ to be used.
295          *
296          * In this version, we give a priority to the kernel config file.
297          * If the EEPROM and config don't match, say it to the user for
298          * an attention.
299          */
300         n = (fe_inb(sc, FE_FMV2) & FE_FMV2_IRS) >> FE_FMV2_IRS_SHIFT;
301
302         irq = 0;
303         bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
304         if (irq == NO_IRQ) {
305                 /* Just use the probed value.  */
306                 bus_set_resource(dev, SYS_RES_IRQ, 0, irqmap[n], 1);
307         } else if (irq != irqmap[n]) {
308                 /* Don't match.  */
309                 sc->stability |= UNSTABLE_IRQ;
310         }
311
312         /* We need an init hook to initialize ASIC before we start.  */
313         sc->init = fe_init_fmv;
314
315         return 0;
316 }
317
318 /*
319  * Fujitsu MB86965 JLI mode probe routines.
320  *
321  * 86965 has a special operating mode called JLI (mode 0), under which
322  * the chip interfaces with ISA bus with a software-programmable
323  * configuration.  (The Fujitsu document calls the feature "Plug and
324  * play," but it is not compatible with the ISA-PnP spec. designed by
325  * Intel and Microsoft.)  Ethernet cards designed to use JLI are
326  * almost same, but there are two things which require board-specific
327  * probe routines: EEPROM layout and IRQ pin connection.
328  *
329  * JLI provides a handy way to access EEPROM which should contains the
330  * chip configuration information (such as I/O port address) as well
331  * as Ethernet station (MAC) address.  The chip configuration info. is
332  * stored on a fixed location.  However, the station address can be
333  * located anywhere in the EEPROM; it is up to the board designer to
334  * determine the location.  (The manual just says "somewhere in the
335  * EEPROM.")  The fe driver must somehow find out the correct
336  * location.
337  *
338  * Another problem resides in the IRQ pin connection.  JLI provides a
339  * user to choose an IRQ from up to four predefined IRQs.  The 86965
340  * chip has a register to select one out of the four possibilities.
341  * However, the selection is against the four IRQ pins on the chip.
342  * (So-called IRQ-A, -B, -C and -D.)  It is (again) up to the board
343  * designer to determine which pin to connect which IRQ line on the
344  * ISA bus.  We need a vendor (or model, for some vendor) specific IRQ
345  * mapping table.
346  * 
347  * The routine fe_probe_jli() provides all probe and initialization
348  * processes which are common to all JLI implementation, and sub-probe
349  * routines supply board-specific actions.
350  *
351  * JLI sub-probe routine has the following template:
352  *
353  *      u_short const * func (struct fe_softc * sc, u_char const * eeprom);
354  *
355  * where eeprom is a pointer to an array of 32 byte data read from the
356  * config EEPROM on the board.  It retuns an IRQ mapping table for the
357  * board, when the corresponding implementation is detected.  It
358  * returns a NULL otherwise.
359  * 
360  * Primary purpose of the functin is to analize the config EEPROM,
361  * determine if it matches with the pattern of that of supported card,
362  * and extract necessary information from it.  One of the information
363  * expected to be extracted from EEPROM is the Ethernet station (MAC)
364  * address, which must be set to the softc table of the interface by
365  * the board-specific routine.
366  */
367
368 /* JLI sub-probe for Allied-Telesyn/Allied-Telesis AT1700/RE2000 series.  */
369 static u_short const *
370 fe_probe_jli_ati(struct fe_softc * sc, u_char const * eeprom)
371 {
372         int i;
373         static u_short const irqmaps_ati [4][4] =
374         {
375                 {  3,  4,  5,  9 },
376                 { 10, 11, 12, 15 },
377                 {  3, 11,  5, 15 },
378                 { 10, 11, 14, 15 },
379         };
380
381         /* Make sure the EEPROM contains Allied-Telesis/Allied-Telesyn
382            bit pattern.  */
383         if (eeprom[1] != 0x00) return NULL;
384         for (i =  2; i <  8; i++) if (eeprom[i] != 0xFF) return NULL;
385         for (i = 14; i < 24; i++) if (eeprom[i] != 0xFF) return NULL;
386
387         /* Get our station address from EEPROM, and make sure the
388            EEPROM contains ATI's address.  */
389         bcopy(eeprom + 8, sc->enaddr, ETHER_ADDR_LEN);
390         if (!fe_valid_Ether_p(sc->enaddr, 0x0000F4))
391                 return NULL;
392
393         /*
394          * The following model identification codes are stolen
395          * from the NetBSD port of the fe driver.  My reviewers
396          * suggested minor revision.
397          */
398
399         /* Determine the card type.  */
400         switch (eeprom[FE_ATI_EEP_MODEL]) {
401           case FE_ATI_MODEL_AT1700T:
402                 sc->typestr = "AT-1700T/RE2001";
403                 sc->mbitmap = MB_HT;
404                 sc->defmedia = MB_HT;
405                 break;
406           case FE_ATI_MODEL_AT1700BT:
407                 sc->typestr = "AT-1700BT/RE2003";
408                 sc->mbitmap = MB_HA | MB_HT | MB_H2;
409                 break;
410           case FE_ATI_MODEL_AT1700FT:
411                 sc->typestr = "AT-1700FT/RE2009";
412                 sc->mbitmap = MB_HA | MB_HT | MB_HF;
413                 break;
414           case FE_ATI_MODEL_AT1700AT:
415                 sc->typestr = "AT-1700AT/RE2005";
416                 sc->mbitmap = MB_HA | MB_HT | MB_H5;
417                 break;
418           default:
419                 sc->typestr = "unknown AT-1700/RE2000";
420                 sc->stability |= UNSTABLE_TYPE | UNSTABLE_IRQ;
421                 break;
422         }
423         sc->type = FE_TYPE_JLI;
424
425 #if 0
426         /* Should we extract default media from eeprom?  Linux driver
427            for AT1700 does it, although previous releases of FreeBSD
428            don't.  FIXME.  */
429         /* Determine the default media selection from the config
430            EEPROM.  The byte at offset EEP_MEDIA is believed to
431            contain BMPR13 value to be set.  We just ignore STP bit or
432            squelch bit, since we don't support those.  (It is
433            intentional.)  */
434         switch (eeprom[FE_ATI_EEP_MEDIA] & FE_B13_PORT) {
435             case FE_B13_AUTO:
436                 sc->defmedia = MB_HA;
437                 break;
438             case FE_B13_TP:
439                 sc->defmedia = MB_HT;
440                 break;
441             case FE_B13_AUI:
442                 sc->defmedia = sc->mbitmap & (MB_H2|MB_H5|MB_H5); /*XXX*/
443                 break;
444             default:        
445                 sc->defmedia = MB_HA;
446                 break;
447         }
448
449         /* Make sure the default media is compatible with the supported
450            ones.  */
451         if ((sc->defmedia & sc->mbitmap) == 0) {
452                 if (sc->defmedia == MB_HA) {
453                         sc->defmedia = MB_HT;
454                 } else {
455                         sc->defmedia = MB_HA;
456                 }
457         }
458 #endif  
459
460         /*
461          * Try to determine IRQ settings.
462          * Different models use different ranges of IRQs.
463          */
464         switch ((eeprom[FE_ATI_EEP_REVISION] & 0xf0)
465                |(eeprom[FE_ATI_EEP_MAGIC]    & 0x04)) {
466             case 0x30: case 0x34: return irqmaps_ati[3];
467             case 0x10: case 0x14:
468             case 0x50: case 0x54: return irqmaps_ati[2];
469             case 0x44: case 0x64: return irqmaps_ati[1];
470             default:              return irqmaps_ati[0];
471         }
472 }
473
474 /* JLI sub-probe and msel hook for ICL Ethernet.  */
475 static void
476 fe_msel_icl(struct fe_softc *sc)
477 {
478         u_char d4;
479
480         /* Switch between UTP and "external tranceiver" as always.  */    
481         fe_msel_965(sc);
482
483         /* The board needs one more bit (on DLCR4) be set appropriately.  */
484         if (IFM_SUBTYPE(sc->media.ifm_media) == IFM_10_5) {
485                 d4 = sc->proto_dlcr4 | FE_D4_CNTRL;
486         } else {
487                 d4 = sc->proto_dlcr4 & ~FE_D4_CNTRL;
488         }
489         fe_outb(sc, FE_DLCR4, d4);
490 }
491
492 static u_short const *
493 fe_probe_jli_icl(struct fe_softc * sc, u_char const * eeprom)
494 {
495         int i;
496         u_short defmedia;
497         u_char d6;
498         static u_short const irqmap_icl [4] = { 9, 10, 5, 15 };
499
500         /* Make sure the EEPROM contains ICL bit pattern.  */
501         for (i = 24; i < 39; i++) {
502             if (eeprom[i] != 0x20 && (eeprom[i] & 0xF0) != 0x30) return NULL;
503         }
504         for (i = 112; i < 122; i++) {
505             if (eeprom[i] != 0x20 && (eeprom[i] & 0xF0) != 0x30) return NULL;
506         }
507
508         /* Make sure the EEPROM contains ICL's permanent station
509            address.  If it isn't, probably this board is not an
510            ICL's.  */
511         if (!fe_valid_Ether_p(eeprom+122, 0x00004B))
512                 return NULL;
513
514         /* Check if the "configured" Ethernet address in the EEPROM is
515            valid.  Use it if it is, or use the "permanent" address instead.  */
516         if (fe_valid_Ether_p(eeprom+4, 0x020000)) {
517                 /* The configured address is valid.  Use it.  */
518                 bcopy(eeprom+4, sc->enaddr, ETHER_ADDR_LEN);
519         } else {
520                 /* The configured address is invalid.  Use permanent.  */
521                 bcopy(eeprom+122, sc->enaddr, ETHER_ADDR_LEN);
522         }
523
524         /* Determine model and supported media.  */
525         switch (eeprom[0x5E]) {
526             case 0:
527                 sc->typestr = "EtherTeam16i/COMBO";
528                 sc->mbitmap = MB_HA | MB_HT | MB_H5 | MB_H2;
529                 break;
530             case 1:
531                 sc->typestr = "EtherTeam16i/TP";
532                 sc->mbitmap = MB_HT;
533                 break;
534             case 2:
535                 sc->typestr = "EtherTeam16i/ErgoPro";
536                 sc->mbitmap = MB_HA | MB_HT | MB_H5;
537                 break;
538             case 4:
539                 sc->typestr = "EtherTeam16i/DUO";
540                 sc->mbitmap = MB_HA | MB_HT | MB_H2;
541                 break;
542             default:
543                 sc->typestr = "EtherTeam16i";
544                 sc->stability |= UNSTABLE_TYPE;
545                 if (bootverbose) {
546                     printf("fe%d: unknown model code %02x for EtherTeam16i\n",
547                            sc->sc_unit, eeprom[0x5E]);
548                 }
549                 break;
550         }
551         sc->type = FE_TYPE_JLI;
552
553         /* I'm not sure the following msel hook is required by all
554            models or COMBO only...  FIXME.  */
555         sc->msel = fe_msel_icl;
556
557         /* Make the configured media selection the default media.  */
558         switch (eeprom[0x28]) {
559             case 0: defmedia = MB_HA; break;
560             case 1: defmedia = MB_H5; break;
561             case 2: defmedia = MB_HT; break;
562             case 3: defmedia = MB_H2; break;
563             default: 
564                 if (bootverbose) {
565                         printf("fe%d: unknown default media: %02x\n",
566                                sc->sc_unit, eeprom[0x28]);
567                 }
568                 defmedia = MB_HA;
569                 break;
570         }
571
572         /* Make sure the default media is compatible with the
573            supported media.  */
574         if ((defmedia & sc->mbitmap) == 0) {
575                 if (bootverbose) {
576                         printf("fe%d: default media adjusted\n", sc->sc_unit);
577                 }
578                 defmedia = sc->mbitmap;
579         }
580
581         /* Keep the determined default media.  */
582         sc->defmedia = defmedia;
583
584         /* ICL has "fat" models.  We have to program 86965 to properly
585            reflect the hardware.  */
586         d6 = sc->proto_dlcr6 & ~(FE_D6_BUFSIZ | FE_D6_BBW);
587         switch ((eeprom[0x61] << 8) | eeprom[0x60]) {
588             case 0x2008: d6 |= FE_D6_BUFSIZ_32KB | FE_D6_BBW_BYTE; break;
589             case 0x4010: d6 |= FE_D6_BUFSIZ_64KB | FE_D6_BBW_WORD; break;
590             default:
591                 /* We can't support it, since we don't know which bits
592                    to set in DLCR6.  */
593                 printf("fe%d: unknown SRAM config for ICL\n", sc->sc_unit);
594                 return NULL;
595         }
596         sc->proto_dlcr6 = d6;
597
598         /* Returns the IRQ table for the ICL board.  */
599         return irqmap_icl;
600 }
601
602 /* JLI sub-probe for RATOC REX-5586/5587.  */
603 static u_short const *
604 fe_probe_jli_rex(struct fe_softc * sc, u_char const * eeprom)
605 {
606         int i;
607         static u_short const irqmap_rex [4] = { 3, 4, 5, NO_IRQ };
608
609         /* Make sure the EEPROM contains RATOC's config pattern.  */
610         if (eeprom[1] != eeprom[0]) return NULL;
611         for (i = 8; i < 32; i++) if (eeprom[i] != 0xFF) return NULL;
612
613         /* Get our station address from EEPROM.  Note that RATOC
614            stores it "byte-swapped" in each word.  (I don't know why.)
615            So, we just can't use bcopy().*/
616         sc->enaddr[0] = eeprom[3];
617         sc->enaddr[1] = eeprom[2];
618         sc->enaddr[2] = eeprom[5];
619         sc->enaddr[3] = eeprom[4];
620         sc->enaddr[4] = eeprom[7];
621         sc->enaddr[5] = eeprom[6];
622
623         /* Make sure the EEPROM contains RATOC's station address.  */
624         if (!fe_valid_Ether_p(sc->enaddr, 0x00C0D0))
625                 return NULL;
626
627         /* I don't know any sub-model identification.  */
628         sc->type = FE_TYPE_JLI;
629         sc->typestr = "REX-5586/5587";
630
631         /* Returns the IRQ for the RATOC board.  */
632         return irqmap_rex;
633 }
634
635 /* JLI sub-probe for Unknown board.  */
636 static u_short const *
637 fe_probe_jli_unk(struct fe_softc * sc, u_char const * eeprom)
638 {
639         int i, n, romsize;
640         static u_short const irqmap [4] = { NO_IRQ, NO_IRQ, NO_IRQ, NO_IRQ };
641
642         /* The generic JLI probe considered this board has an 86965
643            in JLI mode, but any other board-specific routines could
644            not find the matching implementation.  So, we "guess" the
645            location by looking for a bit pattern which looks like a
646            MAC address.  */
647
648         /* Determine how large the EEPROM is.  */
649         for (romsize = JLI_EEPROM_SIZE/2; romsize > 16; romsize >>= 1) {
650                 for (i = 0; i < romsize; i++) {
651                         if (eeprom[i] != eeprom[i+romsize])
652                                 break;
653                 }
654                 if (i < romsize)
655                         break;
656         }
657         romsize <<= 1;
658
659         /* Look for a bit pattern which looks like a MAC address.  */
660         for (n = 2; n <= romsize - ETHER_ADDR_LEN; n += 2) {
661                 if (!fe_valid_Ether_p(eeprom + n, 0x000000))
662                         continue;
663         }
664
665         /* If no reasonable address was found, we can't go further.  */
666         if (n > romsize - ETHER_ADDR_LEN)
667                 return NULL;
668
669         /* Extract our (guessed) station address.  */
670         bcopy(eeprom+n, sc->enaddr, ETHER_ADDR_LEN);
671
672         /* We are not sure what type of board it is... */
673         sc->type = FE_TYPE_JLI;
674         sc->typestr = "(unknown JLI)";
675         sc->stability |= UNSTABLE_TYPE | UNSTABLE_MAC;
676
677         /* Returns the totally unknown IRQ mapping table.  */
678         return irqmap;
679 }
680
681 /*
682  * Probe and initialization for all JLI implementations.
683  */
684
685 static int
686 fe_probe_jli(device_t dev)
687 {
688         struct fe_softc *sc = device_get_softc(dev);
689         int i, n, error, xirq;
690         u_long iobase, irq;
691         u_char eeprom [JLI_EEPROM_SIZE];
692         u_short const * irqmap;
693
694         static u_short const baseaddr [8] =
695                 { 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300 };
696         static struct fe_simple_probe_struct const probe_table [] = {
697                 { FE_DLCR1,  0x20, 0x00 },
698                 { FE_DLCR2,  0x50, 0x00 },
699                 { FE_DLCR4,  0x08, 0x00 },
700                 { FE_DLCR5,  0x80, 0x00 },
701 #if 0
702                 { FE_BMPR16, 0x1B, 0x00 },
703                 { FE_BMPR17, 0x7F, 0x00 },
704 #endif
705                 { 0 }
706         };
707
708         /*
709          * See if the specified address is possible for MB86965A JLI mode.
710          */
711         if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
712                 return ENXIO;
713         for (i = 0; i < 8; i++) {
714                 if (baseaddr[i] == iobase)
715                         break;
716         }
717         if (i == 8)
718                 return ENXIO;
719
720         /* 86965 JLI occupies 32 I/O addresses. */
721         if (fe_alloc_port(dev, 32))
722                 return ENXIO;
723
724         /* Fill the softc struct with reasonable default.  */
725         fe_softc_defaults(sc);
726
727         /*
728          * We should test if MB86965A is on the base address now.
729          * Unfortunately, it is very hard to probe it reliably, since
730          * we have no way to reset the chip under software control.
731          * On cold boot, we could check the "signature" bit patterns
732          * described in the Fujitsu document.  On warm boot, however,
733          * we can predict almost nothing about register values.
734          */
735         if (!fe_simple_probe(sc, probe_table))
736                 return ENXIO;
737
738         /* Check if our I/O address matches config info on 86965.  */
739         n = (fe_inb(sc, FE_BMPR19) & FE_B19_ADDR) >> FE_B19_ADDR_SHIFT;
740         if (baseaddr[n] != iobase)
741                 return ENXIO;
742
743         /*
744          * We are now almost sure we have an MB86965 at the given
745          * address.  So, read EEPROM through it.  We have to write
746          * into LSI registers to read from EEPROM.  I want to avoid it
747          * at this stage, but I cannot test the presence of the chip
748          * any further without reading EEPROM.  FIXME.
749          */
750         fe_read_eeprom_jli(sc, eeprom);
751
752         /* Make sure that config info in EEPROM and 86965 agree.  */
753         if (eeprom[FE_EEPROM_CONF] != fe_inb(sc, FE_BMPR19))
754                 return ENXIO;
755
756         /* Use 86965 media selection scheme, unless othewise
757            specified.  It is "AUTO always" and "select with BMPR13."
758            This behaviour covers most of the 86965 based board (as
759            minimum requirements.)  It is backward compatible with
760            previous versions, also.  */
761         sc->mbitmap = MB_HA;
762         sc->defmedia = MB_HA;
763         sc->msel = fe_msel_965;
764
765         /* Perform board-specific probe, one by one.  Note that the
766            order of probe is important and should not be changed
767            arbitrarily.  */
768         if ((irqmap = fe_probe_jli_ati(sc, eeprom)) == NULL
769          && (irqmap = fe_probe_jli_rex(sc, eeprom)) == NULL
770          && (irqmap = fe_probe_jli_icl(sc, eeprom)) == NULL
771          && (irqmap = fe_probe_jli_unk(sc, eeprom)) == NULL)
772                 return ENXIO;
773
774         /* Find the IRQ read from EEPROM.  */
775         n = (fe_inb(sc, FE_BMPR19) & FE_B19_IRQ) >> FE_B19_IRQ_SHIFT;
776         xirq = irqmap[n];
777
778         /* Try to determine IRQ setting.  */
779         error = bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
780         if (error && xirq == NO_IRQ) {
781                 /* The device must be configured with an explicit IRQ.  */
782                 device_printf(dev, "IRQ auto-detection does not work\n");
783                 return ENXIO;
784         } else if (error && xirq != NO_IRQ) {
785                 /* Just use the probed IRQ value.  */
786                 bus_set_resource(dev, SYS_RES_IRQ, 0, xirq, 1);
787         } else if (!error && xirq == NO_IRQ) {
788                 /* No problem.  Go ahead.  */
789         } else if (irq == xirq) {
790                 /* Good.  Go ahead.  */
791         } else {
792                 /* User must be warned in this case.  */
793                 sc->stability |= UNSTABLE_IRQ;
794         }
795
796         /* Setup a hook, which resets te 86965 when the driver is being
797            initialized.  This may solve a nasty bug.  FIXME.  */
798         sc->init = fe_init_jli;
799
800         return 0;
801 }
802
803 /* Probe for TDK LAK-AX031, which is an SSi 78Q8377A based board.  */
804 static int
805 fe_probe_ssi(device_t dev)
806 {
807         struct fe_softc *sc = device_get_softc(dev);
808         u_long iobase, irq;
809
810         u_char eeprom [SSI_EEPROM_SIZE];
811         static struct fe_simple_probe_struct probe_table [] = {
812                 { FE_DLCR2, 0x08, 0x00 },
813                 { FE_DLCR4, 0x08, 0x00 },
814                 { 0 }
815         };
816
817         /* See if the specified I/O address is possible for 78Q8377A.  */
818         if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
819                 return ENXIO;
820         if ((iobase & ~0x3F0) != 0x000)
821                 return ENXIO;
822
823         /* We have 16 registers.  */
824         if (fe_alloc_port(dev, 16))
825                 return ENXIO;
826
827         /* Fill the softc struct with default values.  */
828         fe_softc_defaults(sc);
829
830         /* See if the card is on its address.  */
831         if (!fe_simple_probe(sc, probe_table))
832                 return ENXIO;
833
834         /* We now have to read the config EEPROM.  We should be very
835            careful, since doing so destroys a register.  (Remember, we
836            are not yet sure we have a LAK-AX031 board here.)  Don't
837            remember to select BMPRs bofore reading EEPROM, since other
838            register bank may be selected before the probe() is called.  */
839         fe_read_eeprom_ssi(sc, eeprom);
840
841         /* Make sure the Ethernet (MAC) station address is of TDK's.  */
842         if (!fe_valid_Ether_p(eeprom+FE_SSI_EEP_ADDR, 0x008098))
843                 return ENXIO;
844         bcopy(eeprom + FE_SSI_EEP_ADDR, sc->enaddr, ETHER_ADDR_LEN);
845
846         /* This looks like a TDK-AX031 board.  It requires an explicit
847            IRQ setting in config, since we currently don't know how we
848            can find the IRQ value assigned by ISA PnP manager.  */
849         if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0) {
850                 fe_irq_failure("LAK-AX031", sc->sc_unit, NO_IRQ, NULL);
851                 return ENXIO;
852         }
853
854         /* Fill softc struct accordingly.  */
855         sc->type = FE_TYPE_SSI;
856         sc->typestr = "LAK-AX031";
857         sc->mbitmap = MB_HT;
858         sc->defmedia = MB_HT;
859
860         return 0;
861 }
862
863 /*
864  * Probe and initialization for TDK/LANX LAC-AX012/013 boards.
865  */
866 static int
867 fe_probe_lnx(device_t dev)
868 {
869         struct fe_softc *sc = device_get_softc(dev);
870         u_long iobase, irq;
871
872         u_char eeprom [LNX_EEPROM_SIZE];
873         static struct fe_simple_probe_struct probe_table [] = {
874                 { FE_DLCR2, 0x58, 0x00 },
875                 { FE_DLCR4, 0x08, 0x00 },
876                 { 0 }
877         };
878
879         /* See if the specified I/O address is possible for TDK/LANX boards. */
880         /* 300, 320, 340, and 360 are allowed.  */
881         if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
882                 return ENXIO;
883         if ((iobase & ~0x060) != 0x300)
884                 return ENXIO;
885
886         /* We have 32 registers.  */
887         if (fe_alloc_port(dev, 32))
888                 return ENXIO;
889
890         /* Fill the softc struct with default values.  */
891         fe_softc_defaults(sc);
892
893         /* See if the card is on its address.  */
894         if (!fe_simple_probe(sc, probe_table))
895                 return ENXIO;
896
897         /* We now have to read the config EEPROM.  We should be very
898            careful, since doing so destroys a register.  (Remember, we
899            are not yet sure we have a LAC-AX012/AX013 board here.)  */
900         fe_read_eeprom_lnx(sc, eeprom);
901
902         /* Make sure the Ethernet (MAC) station address is of TDK/LANX's.  */
903         if (!fe_valid_Ether_p(eeprom, 0x008098))
904                 return ENXIO;
905         bcopy(eeprom, sc->enaddr, ETHER_ADDR_LEN);
906
907         /* This looks like a TDK/LANX board.  It requires an
908            explicit IRQ setting in config.  Make sure we have one,
909            determining an appropriate value for the IRQ control
910            register.  */
911         irq = 0;
912         bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
913         switch (irq) {
914         case 3: sc->priv_info = 0x40 | LNX_CLK_LO | LNX_SDA_HI; break;
915         case 4: sc->priv_info = 0x20 | LNX_CLK_LO | LNX_SDA_HI; break;
916         case 5: sc->priv_info = 0x10 | LNX_CLK_LO | LNX_SDA_HI; break;
917         case 9: sc->priv_info = 0x80 | LNX_CLK_LO | LNX_SDA_HI; break;
918         default:
919                 fe_irq_failure("LAC-AX012/AX013", sc->sc_unit, irq, "3/4/5/9");
920                 return ENXIO;
921         }
922
923         /* Fill softc struct accordingly.  */
924         sc->type = FE_TYPE_LNX;
925         sc->typestr = "LAC-AX012/AX013";
926         sc->init = fe_init_lnx;
927
928         return 0;
929 }
930
931 /*
932  * Probe and initialization for Gateway Communications' old cards.
933  */
934 static int
935 fe_probe_gwy(device_t dev)
936 {
937         struct fe_softc *sc = device_get_softc(dev);
938         u_long iobase, irq;
939
940         static struct fe_simple_probe_struct probe_table [] = {
941             /*  { FE_DLCR2, 0x70, 0x00 }, */
942                 { FE_DLCR2, 0x58, 0x00 },
943                 { FE_DLCR4, 0x08, 0x00 },
944                 { 0 }
945         };
946
947         /* See if the specified I/O address is possible for Gateway boards.  */
948         if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
949                 return ENXIO;
950         if ((iobase & ~0x1E0) != 0x200)
951                 return ENXIO;
952
953         /* That's all.  The card occupies 32 I/O addresses, as always.  */
954         if (fe_alloc_port(dev, 32))
955                 return ENXIO;
956
957         /* Setup an I/O address mapping table and some others.  */
958         fe_softc_defaults(sc);
959
960         /* See if the card is on its address.  */
961         if (!fe_simple_probe(sc, probe_table))
962                 return ENXIO;
963
964         /* Get our station address from EEPROM. */
965         fe_inblk(sc, 0x18, sc->enaddr, ETHER_ADDR_LEN);
966
967         /* Make sure it is Gateway Communication's.  */
968         if (!fe_valid_Ether_p(sc->enaddr, 0x000061))
969                 return ENXIO;
970
971         /* Gateway's board requires an explicit IRQ to work, since it
972            is not possible to probe the setting of jumpers.  */
973         if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0) {
974                 fe_irq_failure("Gateway Ethernet", sc->sc_unit, NO_IRQ, NULL);
975                 return ENXIO;
976         }
977
978         /* Fill softc struct accordingly.  */
979         sc->type = FE_TYPE_GWY;
980         sc->typestr = "Gateway Ethernet (Fujitsu chipset)";
981
982         return 0;
983 }
984
985 /* Probe and initialization for Ungermann-Bass Network
986    K.K. "Access/PC" boards.  */
987 static int
988 fe_probe_ubn(device_t dev)
989 {
990         struct fe_softc *sc = device_get_softc(dev);
991         u_long iobase, irq;
992 #if 0
993         u_char sum;
994 #endif
995         static struct fe_simple_probe_struct const probe_table [] = {
996                 { FE_DLCR2, 0x58, 0x00 },
997                 { FE_DLCR4, 0x08, 0x00 },
998                 { 0 }
999         };
1000
1001         /* See if the specified I/O address is possible for AccessPC/ISA.  */
1002         if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0)
1003                 return ENXIO;
1004         if ((iobase & ~0x0E0) != 0x300)
1005                 return ENXIO;
1006
1007         /* We have 32 registers.  */
1008         if (fe_alloc_port(dev, 32))
1009                 return ENXIO;
1010
1011         /* Setup an I/O address mapping table and some others.  */
1012         fe_softc_defaults(sc);
1013
1014         /* Simple probe.  */
1015         if (!fe_simple_probe(sc, probe_table))
1016                 return ENXIO;
1017
1018         /* Get our station address form ID ROM and make sure it is UBN's.  */
1019         fe_inblk(sc, 0x18, sc->enaddr, ETHER_ADDR_LEN);
1020         if (!fe_valid_Ether_p(sc->enaddr, 0x00DD01))
1021                 return ENXIO;
1022 #if 0
1023         /* Calculate checksum.  */
1024         sum = fe_inb(sc, 0x1e);
1025         for (i = 0; i < ETHER_ADDR_LEN; i++) {
1026                 sum ^= sc->enaddr[i];
1027         }
1028         if (sum != 0)
1029                 return ENXIO;
1030 #endif
1031         /* This looks like an AccessPC/ISA board.  It requires an
1032            explicit IRQ setting in config.  Make sure we have one,
1033            determining an appropriate value for the IRQ control
1034            register.  */
1035         irq = 0;
1036         bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL);
1037         switch (irq) {
1038         case 3:  sc->priv_info = 0x02; break;
1039         case 4:  sc->priv_info = 0x04; break;
1040         case 5:  sc->priv_info = 0x08; break;
1041         case 10: sc->priv_info = 0x10; break;
1042         default:
1043                 fe_irq_failure("Access/PC", sc->sc_unit, irq, "3/4/5/10");
1044                 return ENXIO;
1045         }
1046
1047         /* Fill softc struct accordingly.  */
1048         sc->type = FE_TYPE_UBN;
1049         sc->typestr = "Access/PC";
1050         sc->init = fe_init_ubn;
1051
1052         return 0;
1053 }