if_fe_cbus.c revision 66235
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 66235 2000-09-22 09:59:23Z nyan $ 23 */ 24 25#include "opt_fe.h" 26#include "opt_inet.h" 27#include "opt_ipx.h" 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/kernel.h> 32#include <sys/socket.h> 33#include <sys/module.h> 34#include <machine/clock.h> 35 36#include <sys/bus.h> 37#include <machine/bus.h> 38#include <sys/rman.h> 39#include <machine/resource.h> 40 41#include <net/ethernet.h> 42#include <net/if.h> 43#include <net/if_mib.h> 44#include <net/if_media.h> 45 46#include <netinet/in.h> 47#include <netinet/if_ether.h> 48 49#include <i386/isa/ic/mb86960.h> 50#include <dev/fe/if_fereg.h> 51#include <dev/fe/if_fevar.h> 52 53/* 54 * Cbus specific code. 55 */ 56static int fe_isa_probe(device_t); 57static int fe_isa_attach(device_t); 58 59static device_method_t fe_isa_methods[] = { 60 /* Device interface */ 61 DEVMETHOD(device_probe, fe_isa_probe), 62 DEVMETHOD(device_attach, fe_isa_attach), 63 64 { 0, 0 } 65}; 66 67static driver_t fe_isa_driver = { 68 "fe", 69 fe_isa_methods, 70 sizeof (struct fe_softc) 71}; 72 73DRIVER_MODULE(fe, isa, fe_isa_driver, fe_devclass, 0, 0); 74 75 76static int fe98_alloc_port(device_t, int); 77 78static int fe_probe_re1000(device_t); 79static int fe_probe_cnet9ne(device_t); 80static int fe_probe_rex(device_t); 81static int fe_probe_ssi(device_t); 82static int fe_probe_jli(device_t); 83static int fe_probe_lnx(device_t); 84static int fe_probe_gwy(device_t); 85static int fe_probe_ubn(device_t); 86 87/* 88 * Determine if the device is present at a specified I/O address. The 89 * main entry to the driver. 90 */ 91 92static int 93fe_isa_probe(device_t dev) 94{ 95 struct fe_softc * sc; 96 int error; 97 98 /* Prepare for the softc struct. */ 99 sc = device_get_softc(dev); 100 sc->sc_unit = device_get_unit(dev); 101 102 /* Probe for supported boards. */ 103#ifdef PC98 104 if ((error = fe_probe_re1000(dev)) == 0) 105 goto end; 106 fe_release_resource(dev); 107 108 if ((error = fe_probe_cnet9ne(dev)) == 0) 109 goto end; 110 fe_release_resource(dev); 111 112 if ((error = fe_probe_rex(dev)) == 0) 113 goto end; 114 fe_release_resource(dev); 115#endif 116 117 if ((error = fe_probe_ssi(dev)) == 0) 118 goto end; 119 fe_release_resource(dev); 120 121 if ((error = fe_probe_jli(dev)) == 0) 122 goto end; 123 fe_release_resource(dev); 124 125 if ((error = fe_probe_lnx(dev)) == 0) 126 goto end; 127 fe_release_resource(dev); 128 129 if ((error = fe_probe_ubn(dev)) == 0) 130 goto end; 131 fe_release_resource(dev); 132 133 if ((error = fe_probe_gwy(dev)) == 0) 134 goto end; 135 fe_release_resource(dev); 136 137end: 138 if (error == 0) 139 error = fe_alloc_irq(dev, 0); 140 141 fe_release_resource(dev); 142 return (error); 143} 144 145static int 146fe_isa_attach(device_t dev) 147{ 148 struct fe_softc *sc = device_get_softc(dev); 149 150 if (sc->port_used) 151 fe98_alloc_port(dev, sc->type); 152 fe_alloc_irq(dev, 0); 153 154 return fe_attach(dev); 155} 156 157 158/* Generic I/O address table */ 159static bus_addr_t ioaddr_generic[MAXREGISTERS] = { 160 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007, 161 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f, 162 0x010, 0x011, 0x012, 0x013, 0x014, 0x015, 0x016, 0x017, 163 0x018, 0x019, 0x01a, 0x01b, 0x01c, 0x01d, 0x01e, 0x01f, 164}; 165 166/* I/O address table for RE1000/1000Plus */ 167static bus_addr_t ioaddr_re1000[MAXREGISTERS] = { 168 0x0000, 0x0001, 0x0200, 0x0201, 0x0400, 0x0401, 0x0600, 0x0601, 169 0x0800, 0x0801, 0x0a00, 0x0a01, 0x0c00, 0x0c01, 0x0e00, 0x0e01, 170 0x1000, 0x1200, 0x1400, 0x1600, 0x1800, 0x1a00, 0x1c00, 0x1e00, 171 0x1001, 0x1201, 0x1401, 0x1601, 0x1801, 0x1a01, 0x1c01, 0x1e01, 172}; 173 174/* I/O address table for CNET9NE */ 175static bus_addr_t ioaddr_cnet9ne[MAXREGISTERS] = { 176 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007, 177 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f, 178 0x400, 0x402, 0x404, 0x406, 0x408, 0x40a, 0x40c, 0x40e, 179 0x401, 0x403, 0x405, 0x407, 0x409, 0x40b, 0x40d, 0x40f, 180}; 181 182/* I/O address table for LAC-98 */ 183static bus_addr_t ioaddr_lnx[MAXREGISTERS] = { 184 0x000, 0x002, 0x004, 0x006, 0x008, 0x00a, 0x00c, 0x00e, 185 0x100, 0x102, 0x104, 0x106, 0x108, 0x10a, 0x10c, 0x10e, 186 0x200, 0x202, 0x204, 0x206, 0x208, 0x20a, 0x20c, 0x20e, 187 0x300, 0x302, 0x304, 0x306, 0x308, 0x30a, 0x30c, 0x30e, 188}; 189 190/* I/O address table for Access/PC N98C+ */ 191static bus_addr_t ioaddr_ubn[MAXREGISTERS] = { 192 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007, 193 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f, 194 0x200, 0x201, 0x202, 0x203, 0x204, 0x205, 0x206, 0x207, 195 0x208, 0x209, 0x20a, 0x20b, 0x20c, 0x20d, 0x20e, 0x20f, 196}; 197 198/* I/O address table for REX-9880 */ 199static bus_addr_t ioaddr_rex[MAXREGISTERS] = { 200 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007, 201 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f, 202 0x100, 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 203 0x108, 0x109, 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 204}; 205 206static int 207fe98_alloc_port(device_t dev, int type) 208{ 209 struct fe_softc *sc = device_get_softc(dev); 210 struct resource *res; 211 bus_addr_t *iat; 212 int size, rid; 213 214 switch (type) { 215 case FE_TYPE_RE1000: 216 iat = ioaddr_re1000; 217 size = MAXREGISTERS; 218 break; 219 case FE_TYPE_CNET9NE: 220 iat = &ioaddr_cnet9ne[16]; 221 size = 16; 222 break; 223 case FE_TYPE_SSI: 224 iat = ioaddr_generic; 225 size = MAXREGISTERS; 226 break; 227 case FE_TYPE_LNX: 228 iat = ioaddr_lnx; 229 size = MAXREGISTERS; 230 break; 231 case FE_TYPE_GWY: 232 iat = ioaddr_generic; 233 size = MAXREGISTERS; 234 break; 235 case FE_TYPE_UBN: 236 iat = ioaddr_ubn; 237 size = MAXREGISTERS; 238 break; 239 case FE_TYPE_REX: 240 iat = ioaddr_rex; 241 size = MAXREGISTERS; 242 break; 243 default: 244 iat = ioaddr_generic; 245 size = MAXREGISTERS; 246 break; 247 } 248 249 rid = 0; 250 res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, 251 iat, size, RF_ACTIVE); 252 if (res == NULL) 253 return ENOENT; 254 255 switch (type) { 256 case FE_TYPE_CNET9NE: 257 iat = ioaddr_cnet9ne; 258 size = MAXREGISTERS; 259 break; 260 } 261 262 isa_load_resourcev(res, iat, size); 263 264 sc->type = type; 265 sc->port_used = size; 266 sc->port_res = res; 267 sc->iot = rman_get_bustag(res); 268 sc->ioh = rman_get_bushandle(res); 269 return (0); 270} 271 272 273/* 274 * Probe and initialization for Allied-Telesis RE1000 series. 275 */ 276static void 277fe_init_re1000(struct fe_softc *sc) 278{ 279 /* Setup IRQ control register on the ASIC. */ 280 fe_outb(sc, FE_RE1000_IRQCONF, sc->priv_info); 281} 282 283static int 284fe_probe_re1000(device_t dev) 285{ 286 struct fe_softc *sc = device_get_softc(dev); 287 int i, n; 288 u_long iobase, irq; 289 u_char sum; 290 291 static struct fe_simple_probe_struct probe_table [] = { 292 { FE_DLCR2, 0x58, 0x00 }, 293 { FE_DLCR4, 0x08, 0x00 }, 294 { 0 } 295 }; 296 297 /* See if the specified I/O address is possible for RE1000. */ 298 /* [01]D[02468ACE] are allowed. */ 299 if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0) 300 return ENXIO; 301 if ((iobase & ~0x10E) != 0xD0) 302 return ENXIO; 303 304 if (fe98_alloc_port(dev, FE_TYPE_RE1000)) 305 return ENXIO; 306 307 /* Fill the softc struct with default values. */ 308 fe_softc_defaults(sc); 309 310 /* See if the card is on its address. */ 311 if (!fe_simple_probe(sc, probe_table)) 312 return ENXIO; 313 314 /* Get our station address from EEPROM. */ 315 fe_inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN); 316 317 /* Make sure it is Allied-Telesis's. */ 318 if (!valid_Ether_p(sc->sc_enaddr, 0x0000F4)) 319 return ENXIO; 320#if 1 321 /* Calculate checksum. */ 322 sum = fe_inb(sc, 0x1e); 323 for (i = 0; i < ETHER_ADDR_LEN; i++) 324 sum ^= sc->sc_enaddr[i]; 325 if (sum != 0) 326 return ENXIO; 327#endif 328 /* Setup the board type. */ 329 sc->typestr = "RE1000"; 330 331 /* This looks like an RE1000 board. It requires an 332 explicit IRQ setting in config. Make sure we have one, 333 determining an appropriate value for the IRQ control 334 register. */ 335 irq = 0; 336 bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL); 337 switch (irq) { 338 case 3: n = 0x10; break; 339 case 5: n = 0x20; break; 340 case 6: n = 0x40; break; 341 case 12: n = 0x80; break; 342 default: 343 fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12"); 344 return ENXIO; 345 } 346 sc->priv_info = (fe_inb(sc, FE_RE1000_IRQCONF) & 0x0f) | n; 347 348 /* Setup hooks. We need a special initialization procedure. */ 349 sc->init = fe_init_re1000; 350 351 return 0; 352} 353 354/* JLI sub-probe for Allied-Telesis RE1000Plus/ME1500 series. */ 355static u_short const * 356fe_probe_jli_re1000p(struct fe_softc * sc, u_char const * eeprom) 357{ 358 int i; 359 static u_short const irqmaps_re1000p [4] = { 3, 5, 6, 12 }; 360 361 /* Make sure the EEPROM contains Allied-Telesis bit pattern. */ 362 if (eeprom[1] != 0xFF) return NULL; 363 for (i = 2; i < 8; i++) if (eeprom[i] != 0xFF) return NULL; 364 for (i = 14; i < 24; i++) if (eeprom[i] != 0xFF) return NULL; 365 366 /* Get our station address from EEPROM, and make sure the 367 EEPROM contains Allied-Telesis's address. */ 368 bcopy(eeprom + 8, sc->sc_enaddr, ETHER_ADDR_LEN); 369 if (!valid_Ether_p(sc->sc_enaddr, 0x0000F4)) 370 return NULL; 371 372 /* I don't know any sub-model identification. */ 373 sc->typestr = "RE1000Plus/ME1500"; 374 375 /* Returns the IRQ table for the RE1000Plus. */ 376 return irqmaps_re1000p; 377} 378 379 380/* 381 * Probe for Allied-Telesis RE1000Plus/ME1500 series. 382 */ 383static int 384fe_probe_jli(device_t dev) 385{ 386 struct fe_softc *sc = device_get_softc(dev); 387 int i, n, xirq, error; 388 u_long iobase, irq; 389 u_char eeprom [JLI_EEPROM_SIZE]; 390 u_short const * irqmap; 391 392 static u_short const baseaddr [8] = 393 { 0x1D6, 0x1D8, 0x1DA, 0x1D4, 0x0D4, 0x0D2, 0x0D8, 0x0D0 }; 394 static struct fe_simple_probe_struct const probe_table [] = { 395 /* { FE_DLCR1, 0x20, 0x00 }, Doesn't work. */ 396 { FE_DLCR2, 0x50, 0x00 }, 397 { FE_DLCR4, 0x08, 0x00 }, 398 /* { FE_DLCR5, 0x80, 0x00 }, Doesn't work. */ 399#if 0 400 { FE_BMPR16, 0x1B, 0x00 }, 401 { FE_BMPR17, 0x7F, 0x00 }, 402#endif 403 { 0 } 404 }; 405 406 /* 407 * See if the specified address is possible for MB86965A JLI mode. 408 */ 409 if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0) 410 return ENXIO; 411 for (i = 0; i < 8; i++) { 412 if (baseaddr[i] == iobase) 413 break; 414 } 415 if (i == 8) 416 return ENXIO; 417 418 if (fe98_alloc_port(dev, FE_TYPE_RE1000)) 419 return ENXIO; 420 421 /* Fill the softc struct with default values. */ 422 fe_softc_defaults(sc); 423 424 /* 425 * We should test if MB86965A is on the base address now. 426 * Unfortunately, it is very hard to probe it reliably, since 427 * we have no way to reset the chip under software control. 428 * On cold boot, we could check the "signature" bit patterns 429 * described in the Fujitsu document. On warm boot, however, 430 * we can predict almost nothing about register values. 431 */ 432 if (!fe_simple_probe(sc, probe_table)) 433 return ENXIO; 434 435 /* Check if our I/O address matches config info on 86965. */ 436 n = (fe_inb(sc, FE_BMPR19) & FE_B19_ADDR) >> FE_B19_ADDR_SHIFT; 437 if (baseaddr[n] != iobase) 438 return ENXIO; 439 440 /* 441 * We are now almost sure we have an MB86965 at the given 442 * address. So, read EEPROM through it. We have to write 443 * into LSI registers to read from EEPROM. I want to avoid it 444 * at this stage, but I cannot test the presence of the chip 445 * any further without reading EEPROM. FIXME. 446 */ 447 fe_read_eeprom_jli(sc, eeprom); 448 449 /* Make sure that config info in EEPROM and 86965 agree. */ 450 if (eeprom[FE_EEPROM_CONF] != fe_inb(sc, FE_BMPR19)) 451 return ENXIO; 452 453 /* Use 86965 media selection scheme, unless othewise 454 specified. It is "AUTO always" and "select with BMPR13". 455 This behaviour covers most of the 86965 based board (as 456 minimum requirements.) It is backward compatible with 457 previous versions, also. */ 458 sc->mbitmap = MB_HA; 459 sc->defmedia = MB_HA; 460 sc->msel = fe_msel_965; 461 462 /* Perform board-specific probe. */ 463 if ((irqmap = fe_probe_jli_re1000p(sc, eeprom)) == NULL) 464 return ENXIO; 465 466 /* Find the IRQ read from EEPROM. */ 467 n = (fe_inb(sc, FE_BMPR19) & FE_B19_IRQ) >> FE_B19_IRQ_SHIFT; 468 xirq = irqmap[n]; 469 470 /* Try to determine IRQ setting. */ 471 error = bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL); 472 if (error && xirq == NO_IRQ) { 473 /* The device must be configured with an explicit IRQ. */ 474 device_printf(dev, "IRQ auto-detection does not work\n"); 475 return ENXIO; 476 } else if (error && xirq != NO_IRQ) { 477 /* Just use the probed IRQ value. */ 478 bus_set_resource(dev, SYS_RES_IRQ, 0, xirq, 1); 479 } else if (!error && xirq == NO_IRQ) { 480 /* No problem. Go ahead. */ 481 } else if (irq == xirq) { 482 /* Good. Go ahead. */ 483 } else { 484 /* User must be warned in this case. */ 485 sc->stability |= UNSTABLE_IRQ; 486 } 487 488 /* Setup a hook, which resets te 86965 when the driver is being 489 initialized. This may solve a nasty bug. FIXME. */ 490 sc->init = fe_init_jli; 491 492 return 0; 493} 494 495 496/* 497 * Probe and initialization for Contec C-NET(9N)E series. 498 */ 499 500/* TODO: Should be in "if_fereg.h" */ 501#define FE_CNET9NE_INTR 0x10 /* Interrupt Mask? */ 502 503static void 504fe_init_cnet9ne(struct fe_softc *sc) 505{ 506 /* Enable interrupt? FIXME. */ 507 fe_outb(sc, FE_CNET9NE_INTR, 0x10); 508} 509 510static int 511fe_probe_cnet9ne (device_t dev) 512{ 513 struct fe_softc *sc = device_get_softc(dev); 514 u_long iobase, irq; 515 516 static struct fe_simple_probe_struct probe_table [] = { 517 { FE_DLCR2, 0x58, 0x00 }, 518 { FE_DLCR4, 0x08, 0x00 }, 519 { 0 } 520 }; 521 522 /* See if the specified I/O address is possible for C-NET(9N)E. */ 523 if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0) 524 return ENXIO; 525 if (iobase != 0x73D0) 526 return ENXIO; 527 528 if (fe98_alloc_port(dev, FE_TYPE_CNET9NE)) 529 return ENXIO; 530 531 /* Fill the softc struct with default values. */ 532 fe_softc_defaults(sc); 533 534 /* See if the card is on its address. */ 535 if (!fe_simple_probe(sc, probe_table)) 536 return ENXIO; 537 538 /* Get our station address from EEPROM. */ 539 fe_inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN); 540 541 /* Make sure it is Contec's. */ 542 if (!valid_Ether_p(sc->sc_enaddr, 0x00804C)) 543 return ENXIO; 544 545 /* Determine the card type. */ 546 if (sc->sc_enaddr[3] == 0x06) { 547 sc->typestr = "C-NET(9N)C"; 548 549 /* We seems to need our own IDENT bits... FIXME. */ 550 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE; 551 552 /* C-NET(9N)C requires an explicit IRQ to work. */ 553 if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0) { 554 fe_irq_failure(sc->typestr, sc->sc_unit, NO_IRQ, NULL); 555 return ENXIO; 556 } 557 } else { 558 sc->typestr = "C-NET(9N)E"; 559 560 /* C-NET(9N)E works only IRQ5. */ 561 if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0) 562 return ENXIO; 563 if (irq != 5) { 564 fe_irq_failure(sc->typestr, sc->sc_unit, irq, "5"); 565 return ENXIO; 566 } 567 568 /* We need an init hook to initialize ASIC before we start. */ 569 sc->init = fe_init_cnet9ne; 570 } 571 572 /* C-NET(9N)E has 64KB SRAM. */ 573 sc->proto_dlcr6 = FE_D6_BUFSIZ_64KB | FE_D6_TXBSIZ_2x4KB 574 | FE_D6_BBW_WORD | FE_D6_SBW_WORD | FE_D6_SRAM; 575 576 return 0; 577} 578 579 580/* 581 * Probe for Contec C-NET(98)P2 series. 582 * (Logitec LAN-98TP/LAN-98T25P - parhaps) 583 */ 584static int 585fe_probe_ssi(device_t dev) 586{ 587 struct fe_softc *sc = device_get_softc(dev); 588 u_long iobase, irq; 589 590 u_char eeprom [SSI_EEPROM_SIZE]; 591 static struct fe_simple_probe_struct probe_table [] = { 592 { FE_DLCR2, 0x08, 0x00 }, 593 { FE_DLCR4, 0x08, 0x00 }, 594 { 0 } 595 }; 596 static u_short const irqmap[] = { 597 /* INT0 INT1 INT2 */ 598 NO_IRQ, NO_IRQ, NO_IRQ, 3, NO_IRQ, 5, 6, NO_IRQ, 599 NO_IRQ, 9, 10, NO_IRQ, 12, 13, NO_IRQ, NO_IRQ, 600 /* INT3 INT41 INT5 INT6 */ 601 }; 602 603 /* See if the specified I/O address is possible for 78Q8377A. */ 604 /* [0-D]3D0 are allowed. */ 605 if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0) 606 return ENXIO; 607 if ((iobase & 0xFFF) != 0x3D0) 608 return ENXIO; 609 610 if (fe98_alloc_port(dev, FE_TYPE_SSI)) 611 return ENXIO; 612 613 /* Fill the softc struct with default values. */ 614 fe_softc_defaults(sc); 615 616 /* See if the card is on its address. */ 617 if (!fe_simple_probe(sc, probe_table)) 618 return ENXIO; 619 620 /* We now have to read the config EEPROM. We should be very 621 careful, since doing so destroys a register. (Remember, we 622 are not yet sure we have a C-NET(98)P2 board here.) Don't 623 remember to select BMPRs bofore reading EEPROM, since other 624 register bank may be selected before the probe() is called. */ 625 fe_read_eeprom_ssi(sc, eeprom); 626 627 /* Make sure the Ethernet (MAC) station address is of Contec's. */ 628 if (!valid_Ether_p(eeprom + FE_SSI_EEP_ADDR, 0x00804C)) 629 return ENXIO; 630 bcopy(eeprom + FE_SSI_EEP_ADDR, sc->sc_enaddr, ETHER_ADDR_LEN); 631 632 /* Setup the board type. */ 633 sc->typestr = "C-NET(98)P2"; 634 635 /* Get IRQ configuration from EEPROM. */ 636 irq = irqmap[eeprom[FE_SSI_EEP_IRQ]]; 637 if (irq == NO_IRQ) { 638 fe_irq_failure(sc->typestr, sc->sc_unit, irq, 639 "3/5/6/9/10/12/13"); 640 return ENXIO; 641 } 642 bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1); 643 644 /* Get Duplex-mode configuration from EEPROM. */ 645 sc->proto_dlcr4 |= (eeprom[FE_SSI_EEP_DUPLEX] & FE_D4_DSC); 646 647 /* Fill softc struct accordingly. */ 648 sc->mbitmap = MB_HT; 649 sc->defmedia = MB_HT; 650 651 return 0; 652} 653 654 655/* 656 * Probe for TDK LAC-98012/013/025/9N011 - parhaps. 657 */ 658static int 659fe_probe_lnx(device_t dev) 660{ 661#ifndef FE_8BIT_SUPPORT 662 device_printf(dev, 663 "skip LAC-98012/013(only 16-bit cards are supported)\n"); 664 return ENXIO; 665#else 666 struct fe_softc *sc = device_get_softc(dev); 667 668 u_long iobase, irq; 669 u_char eeprom [LNX_EEPROM_SIZE]; 670 671 static struct fe_simple_probe_struct probe_table [] = { 672 { FE_DLCR2, 0x58, 0x00 }, 673 { FE_DLCR4, 0x08, 0x00 }, 674 { 0 } 675 }; 676 677 /* See if the specified I/O address is possible for TDK/LANX boards. */ 678 /* 0D0, 4D0, 8D0, and CD0 are allowed. */ 679 if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, NULL) != 0) 680 return ENXIO; 681 if ((iobase & ~0xC00) != 0xD0) 682 return ENXIO; 683 684 if (fe98_alloc_port(dev, FE_TYPE_LNX)) 685 return ENXIO; 686 687 /* Fill the softc struct with default values. */ 688 fe_softc_defaults(sc); 689 690 /* See if the card is on its address. */ 691 if (!fe_simple_probe(sc, probe_table)) 692 return ENXIO; 693 694 /* We now have to read the config EEPROM. We should be very 695 careful, since doing so destroys a register. (Remember, we 696 are not yet sure we have a LAC-98012/98013 board here.) */ 697 fe_read_eeprom_lnx(sc, eeprom); 698 699 /* Make sure the Ethernet (MAC) station address is of TDK/LANX's. */ 700 if (!valid_Ether_p(eeprom, 0x008098)) 701 return ENXIO; 702 bcopy(eeprom, sc->sc_enaddr, ETHER_ADDR_LEN); 703 704 /* Setup the board type. */ 705 sc->typestr = "LAC-98012/98013"; 706 707 /* This looks like a TDK/LANX board. It requires an 708 explicit IRQ setting in config. Make sure we have one, 709 determining an appropriate value for the IRQ control 710 register. */ 711 irq = 0; 712 if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL) != 0) 713 return ENXIO; 714 switch (irq) { 715 case 3 : sc->priv_info = 0x10 | LNX_CLK_LO | LNX_SDA_HI; break; 716 case 5 : sc->priv_info = 0x20 | LNX_CLK_LO | LNX_SDA_HI; break; 717 case 6 : sc->priv_info = 0x40 | LNX_CLK_LO | LNX_SDA_HI; break; 718 case 12: sc->priv_info = 0x80 | LNX_CLK_LO | LNX_SDA_HI; break; 719 default: 720 fe_irq_failure(sc->typestr, sc->sc_unit, irq, "3/5/6/12"); 721 return ENXIO; 722 } 723 724 /* LAC-98's system bus width is 8-bit. */ 725 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x2KB 726 | FE_D6_BBW_BYTE | FE_D6_SBW_BYTE | FE_D6_SRAM_150ns; 727 728 /* Setup hooks. We need a special initialization procedure. */ 729 sc->init = fe_init_lnx; 730 731 return 0; 732#endif /* FE_8BIT_SUPPORT */ 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