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