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