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