if_ed_cbus.c revision 67172
1/* 2 * Copyright (c) 1995, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD: head/sys/dev/ed/if_ed_cbus.c 67172 2000-10-15 20:23:27Z msmith $ 28 */ 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/socket.h> 33#include <sys/kernel.h> 34 35#include <sys/module.h> 36#include <sys/bus.h> 37#include <machine/bus.h> 38#ifdef PC98 39#include <sys/rman.h> 40#include <machine/resource.h> 41#include <machine/clock.h> 42#include <machine/md_var.h> 43#endif 44 45#include <net/ethernet.h> 46#include <net/if.h> 47#include <net/if_arp.h> 48#include <net/if_mib.h> 49 50#include <isa/isavar.h> 51#include <isa/pnpvar.h> 52 53#include <dev/ed/if_edvar.h> 54#ifdef PC98 55#include <dev/ed/if_edreg.h> 56#include <dev/ed/if_ed98.h> 57 58static int ed98_alloc_port __P((device_t, int)); 59static int ed98_alloc_memory __P((device_t, int)); 60static int ed_pio_testmem __P((struct ed_softc *, int, int, int)); 61static int ed_probe_SIC98 __P((device_t, int, int)); 62static int ed_probe_CNET98 __P((device_t, int, int)); 63static int ed_probe_CNET98EL __P((device_t, int, int)); 64static int ed_probe_NEC77 __P((device_t, int, int)); 65static int ed_probe_NW98X __P((device_t, int, int)); 66static int ed_probe_SB98 __P((device_t, int, int)); 67static int ed_probe_EZ98 __P((device_t, int, int)); 68static int ed98_probe_Novell __P((device_t, int, int)); 69static int ed98_probe_generic8390 __P((struct ed_softc *)); 70static void ed_reset_CNET98 __P((struct ed_softc *, int)); 71static void ed_winsel_CNET98 __P((struct ed_softc *, u_short)); 72static void ed_get_SB98 __P((struct ed_softc *)); 73#endif 74 75static int ed_isa_probe __P((device_t)); 76static int ed_isa_attach __P((device_t)); 77 78static struct isa_pnp_id ed_ids[] = { 79#ifdef PC98 80/* TODO - list up PnP boards for PC-98 */ 81 { 0, NULL } 82#endif 83}; 84 85static int 86ed_isa_probe(dev) 87 device_t dev; 88{ 89 struct ed_softc *sc = device_get_softc(dev); 90 int flags = device_get_flags(dev); 91 int error = 0; 92 93 bzero(sc, sizeof(struct ed_softc)); 94#ifdef PC98 95 sc->type = ED_TYPE98(flags); 96#ifdef ED_DEBUG 97 device_printf(dev, "ed_isa_probe: sc->type=%x\n", sc->type); 98#endif 99#endif 100 101 /* Check isapnp ids */ 102 error = ISA_PNP_PROBE(device_get_parent(dev), dev, ed_ids); 103#ifdef ED_DEBUG 104 device_printf(dev, "ed_isa_probe: ISA_PNP_PROBE returns %d\n", error); 105#endif 106 107 /* If the card had a PnP ID that didn't match any we know about */ 108 if (error == ENXIO) { 109 goto end; 110 } 111 112 /* If we had some other problem. */ 113 if (!(error == 0 || error == ENOENT)) { 114 goto end; 115 } 116 117 /* Heuristic probes */ 118#ifdef ED_DEBUG 119 device_printf(dev, "ed_isa_probe: Heuristic probes start\n"); 120#endif 121#ifdef PC98 122 switch (sc->type) { 123 case ED_TYPE98_GENERIC: 124 /* 125 * CAUTION! 126 * sc->type of these boards are overwritten by PC/AT's value. 127 */ 128 129 /* 130 * SMC EtherEZ98 131 */ 132 error = ed_probe_EZ98(dev, 0, flags); 133 if (error == 0) { 134 goto end; 135 } 136 137 ed_release_resources(dev); 138 139 /* 140 * Allied Telesis CenterCom LA-98-T 141 */ 142 error = ed_probe_Novell(dev, 0, flags); 143 if (error == 0) { 144 goto end; 145 } 146 147 break; 148 149 /* 150 * NE2000-like boards probe routine 151 */ 152 case ED_TYPE98_BDN: 153 /* 154 * ELECOM LANEED LD-BDN 155 * PLANET SMART COM 98 EN-2298 156 */ 157 case ED_TYPE98_LGY: 158 /* 159 * MELCO LGY-98, IND-SP, IND-SS 160 * MACNICA NE2098 161 */ 162 case ED_TYPE98_ICM: 163 /* 164 * ICM DT-ET-25, DT-ET-T5, IF-2766ET, IF-2771ET 165 * D-Link DE-298P, DE-298 166 */ 167 case ED_TYPE98_EGY: 168 /* 169 * MELCO EGY-98 170 * Contec C-NET(98)E-A, C-NET(98)L-A 171 */ 172 case ED_TYPE98_108: 173 /* 174 * NEC PC-9801-107,108 175 */ 176 case ED_TYPE98_NC5098: 177 /* 178 * NextCom NC5098 179 */ 180 181 error = ed98_probe_Novell(dev, 0, flags); 182 183 break; 184 185 /* 186 * other boards with special probe routine 187 */ 188 case ED_TYPE98_SIC: 189 /* 190 * Allied Telesis SIC-98 191 */ 192 error = ed_probe_SIC98(dev, 0, flags); 193 194 break; 195 196 case ED_TYPE98_CNET98EL: 197 /* 198 * Contec C-NET(98)E/L 199 */ 200 error = ed_probe_CNET98EL(dev, 0, flags); 201 202 break; 203 204 case ED_TYPE98_CNET98: 205 /* 206 * Contec C-NET(98) 207 */ 208 error = ed_probe_CNET98(dev, 0, flags); 209 210 break; 211 212 case ED_TYPE98_LA98: 213 /* 214 * IO-DATA LA/T-98 215 * NEC PC-9801-77,78 216 */ 217 error = ed_probe_NEC77(dev, 0, flags); 218 219 break; 220 221 case ED_TYPE98_NW98X: 222 /* 223 * Networld EC/EP-98X 224 */ 225 error = ed_probe_NW98X(dev, 0, flags); 226 227 break; 228 229 case ED_TYPE98_SB98: 230 /* 231 * Soliton SB-9801 232 * Fujikura FN-9801 233 */ 234 235 error = ed_probe_SB98(dev, 0, flags); 236 237 break; 238 } 239#endif 240 241end: 242#ifdef ED_DEBUG 243 device_printf(dev, "ed_isa_probe: end, error=%d\n", error); 244#endif 245 if (error == 0) 246 error = ed_alloc_irq(dev, 0, 0); 247 248 ed_release_resources(dev); 249 return (error); 250} 251 252static int 253ed_isa_attach(dev) 254 device_t dev; 255{ 256 struct ed_softc *sc = device_get_softc(dev); 257 int flags = device_get_flags(dev); 258 int error; 259 260 if (sc->port_used > 0) { 261#ifdef PC98 262 if (ED_TYPE98(flags) == ED_TYPE98_GENERIC) { 263 ed_alloc_port(dev, sc->port_rid, sc->port_used); 264 } else { 265 ed98_alloc_port(dev, sc->port_rid); 266 } 267#endif 268 } 269 if (sc->mem_used) 270 ed_alloc_memory(dev, sc->mem_rid, sc->mem_used); 271 272 ed_alloc_irq(dev, sc->irq_rid, 0); 273 274 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, 275 edintr, sc, &sc->irq_handle); 276 if (error) { 277 ed_release_resources(dev); 278 return (error); 279 } 280 281 return ed_attach(sc, device_get_unit(dev), flags); 282} 283 284static device_method_t ed_isa_methods[] = { 285 /* Device interface */ 286 DEVMETHOD(device_probe, ed_isa_probe), 287 DEVMETHOD(device_attach, ed_isa_attach), 288 289 { 0, 0 } 290}; 291 292static driver_t ed_isa_driver = { 293 "ed", 294 ed_isa_methods, 295 sizeof(struct ed_softc) 296}; 297 298static devclass_t ed_isa_devclass; 299 300DRIVER_MODULE(if_ed, isa, ed_isa_driver, ed_isa_devclass, 0, 0); 301 302#ifdef PC98 303/* 304 * Interrupt conversion table for EtherEZ98 305 */ 306static unsigned short ed_EZ98_intr_val[] = { 307 0, 308 3, 309 5, 310 6, 311 0, 312 9, 313 12, 314 13 315}; 316 317static int 318ed_probe_EZ98(dev, port_rid, flags) 319 device_t dev; 320 int port_rid; 321 int flags; 322{ 323 struct ed_softc *sc = device_get_softc(dev); 324 int error; 325 static unsigned short *intr_vals[] = {NULL, ed_EZ98_intr_val}; 326 327 error = ed_alloc_port(dev, port_rid, ED_EZ98_IO_PORTS); 328 if (error) { 329 return (error); 330 } 331 332 sc->asic_offset = ED_EZ98_ASIC_OFFSET; 333 sc->nic_offset = ED_EZ98_NIC_OFFSET; 334 335 return ed_probe_WD80x3_generic(dev, flags, intr_vals); 336} 337 338/* 339 * I/O conversion tables 340 */ 341 342/* LGY-98, ICM, C-NET(98)E/L */ 343static bus_addr_t ed98_ioaddr_generic[] = { 344 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 345}; 346 347/* 348 * Definitions for Contec C-NET(98)E/L 349 */ 350#define ED_CNET98EL_ICR 2 /* Interrupt Configuration Register */ 351 352#define ED_CNET98EL_ICR_IRQ3 0x01 353#define ED_CNET98EL_ICR_IRQ5 0x02 354#define ED_CNET98EL_ICR_IRQ6 0x04 355#define ED_CNET98EL_ICR_IRQ12 0x20 356 357#define ED_CNET98EL_IMR 4 /* Interrupt Mask Register */ 358#define ED_CNET98EL_ISR 5 /* Interrupt Status Register */ 359 360/* EGY-98 */ 361static bus_addr_t ed98_ioaddr_egy98[] = { 362 0, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 363 0x100, 0x102, 0x104, 0x106, 0x108, 0x10a, 0x10c, 0x10e 364}; 365 366/* SIC-98 */ 367static bus_addr_t ed98_ioaddr_sic98[] = { 368 0x0000, 0x0200, 0x0400, 0x0600, 0x0800, 0x0a00, 0x0c00, 0x0e00, 369 0x1000, 0x1200, 0x1400, 0x1600, 0x1800, 0x1a00, 0x1c00, 0x1e00 370}; 371 372/* LA/T-98, LD-BDN, PC-9801-77, SB-9801 */ 373static bus_addr_t ed98_ioaddr_la98[] = { 374 0x0000, 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000, 375 0x8000, 0x9000, 0xa000, 0xb000, 0xc000, 0xd000, 0xe000, 0xf000, 376 0x0100 /* for NEC 77(see below) */ 377}; 378 379/* 380 * Definitions for NEC PC-9801-77 381 */ 382#define ED_NEC77_IRQ 16 /* Interrupt Configuration Register */ 383 384#define ED_NEC77_IRQ3 0x04 385#define ED_NEC77_IRQ5 0x06 386#define ED_NEC77_IRQ6 0x08 387#define ED_NEC77_IRQ12 0x0a 388#define ED_NEC77_IRQ13 0x02 389 390/* 391 * Definitions for Soliton SB-9801 392 */ 393#define ED_SB98_CFG 1 /* Board configuration */ 394 395#define ED_SB98_CFG_IRQ3 0x00 396#define ED_SB98_CFG_IRQ5 0x04 397#define ED_SB98_CFG_IRQ6 0x08 398#define ED_SB98_CFG_IRQ12 0x0c 399#define ED_SB98_CFG_ALTPORT 0x40 /* use EXTERNAL media */ 400#define ED_SB98_CFG_ENABLE 0xa0 /* enable configuration */ 401 402#define ED_SB98_EEPENA 2 /* EEPROM access enable */ 403 404#define ED_SB98_EEPENA_DISABLE 0x00 405#define ED_SB98_EEPENA_ENABLE 0x01 406 407#define ED_SB98_EEP 3 /* EEPROM access */ 408 409#define ED_SB98_EEP_SDA 0x01 /* Serial Data */ 410#define ED_SB98_EEP_SCL 0x02 /* Serial Clock */ 411#define ED_SB98_EEP_READ 0x01 /* Read Command */ 412 413#define ED_SB98_EEP_DELAY 300 414 415#define ED_SB98_ADDRESS 0x01 /* Station Address(1-6) */ 416 417#define ED_SB98_POLARITY 4 /* Polarity */ 418 419/* PC-9801-108 */ 420static bus_addr_t ed98_ioaddr_nec108[] = { 421 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, 422 0x1000, 0x1002, 0x1004, 0x1006, 0x1008, 0x100a, 0x100c, 0x100e 423}; 424 425/* C-NET(98) */ 426static bus_addr_t ed98_ioaddr_cnet98[] = { 427 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, 428 0x0400, 0x0402, 0x0404, 0x0406, 0x0408, 0x040a, 0x040c, 0x040e 429}; 430 431/* 432 * Definitions for Contec C-NET(98) 433 */ 434#define ED_CNET98_MAP_REG0L 0 /* MAPPING register0 Low */ 435#define ED_CNET98_MAP_REG1L 1 /* MAPPING register1 Low */ 436#define ED_CNET98_MAP_REG2L 2 /* MAPPING register2 Low */ 437#define ED_CNET98_MAP_REG3L 3 /* MAPPING register3 Low */ 438#define ED_CNET98_MAP_REG0H 4 /* MAPPING register0 Hi */ 439#define ED_CNET98_MAP_REG1H 5 /* MAPPING register1 Hi */ 440#define ED_CNET98_MAP_REG2H 6 /* MAPPING register2 Hi */ 441#define ED_CNET98_MAP_REG3H 7 /* MAPPING register3 Hi */ 442#define ED_CNET98_WIN_REG 8 /* Window register */ 443#define ED_CNET98_INT_LEV 9 /* Init level register */ 444 445#define ED_CNET98_INT_IRQ3 0x01 /* INT 0 */ 446#define ED_CNET98_INT_IRQ5 0x02 /* INT 1 */ 447#define ED_CNET98_INT_IRQ6 0x04 /* INT 2 */ 448#define ED_CNET98_INT_IRQ9 0x08 /* INT 3 */ 449#define ED_CNET98_INT_IRQ12 0x20 /* INT 5 */ 450#define ED_CNET98_INT_IRQ13 0x40 /* INT 6 */ 451 452#define ED_CNET98_INT_REQ 10 /* Init request register */ 453#define ED_CNET98_INT_MASK 11 /* Init mask register */ 454#define ED_CNET98_INT_STAT 12 /* Init status register */ 455#define ED_CNET98_INT_CLR 12 /* Init clear register */ 456#define ED_CNET98_RESERVE1 13 457#define ED_CNET98_RESERVE2 14 458#define ED_CNET98_RESERVE3 15 459 460/* EC/EP-98X, NC5098 */ 461static bus_addr_t ed98_ioaddr_nw98x[] = { 462 0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 463 0x0800, 0x0900, 0x0a00, 0x0b00, 0x0c00, 0x0d00, 0x0e00, 0x0f00, 464 0x1000 /* for EC/EP-98X(see below) */ 465}; 466 467/* 468 * Definitions for Networld EC/EP-98X 469 */ 470#define ED_NW98X_IRQ 16 /* Interrupt Configuration Register */ 471 472#define ED_NW98X_IRQ3 0x04 473#define ED_NW98X_IRQ5 0x06 474#define ED_NW98X_IRQ6 0x08 475#define ED_NW98X_IRQ12 0x0a 476#define ED_NW98X_IRQ13 0x02 477 478/* NC5098 ASIC */ 479static bus_addr_t ed98_asic_nc5098[] = { 480/* DATA ENADDR RESET */ 481 0x0000, 0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x4000, 482 0, 0, 0, 0, 0, 0, 0, 0 483}; 484 485/* 486 * Definitions for NextCom NC5098 487 */ 488#define ED_NC5098_ENADDR 1 /* Station Address(1-6) */ 489 490/* 491 * Allocate a port resource with the given resource id. 492 */ 493static int 494ed98_alloc_port(dev, rid) 495 device_t dev; 496 int rid; 497{ 498 struct ed_softc *sc = device_get_softc(dev); 499 struct resource *res; 500 int error; 501 bus_addr_t *io_nic, *io_asic, adj; 502 static bus_addr_t io_res[ED_NOVELL_IO_PORTS + 1]; 503 int i, n; 504 int offset, reset, data; 505 506 /* Set i/o table for resource manager */ 507 io_nic = io_asic = ed98_ioaddr_generic; 508 offset = ED_NOVELL_ASIC_OFFSET; 509 reset = ED_NOVELL_RESET; 510 data = ED_NOVELL_DATA; 511 n = ED_NOVELL_IO_PORTS; 512 513 switch (sc->type) { 514 case ED_TYPE98_LGY: 515 io_asic = ed98_ioaddr_egy98; /* XXX - Yes, we use egy98 */ 516 offset = 0x0200; 517 reset = 8; 518 break; 519 520 case ED_TYPE98_EGY: 521 io_nic = io_asic = ed98_ioaddr_egy98; 522 offset = 0x0200; 523 reset = 8; 524 break; 525 526 case ED_TYPE98_ICM: 527 offset = 0x0100; 528 break; 529 530 case ED_TYPE98_BDN: 531 io_nic = io_asic = ed98_ioaddr_la98; 532 offset = 0x0100; 533 reset = 0x0c; 534 break; 535 536 case ED_TYPE98_SIC: 537 io_nic = io_asic = ed98_ioaddr_sic98; 538 offset = 0x2000; 539 n = 16+1; 540 break; 541 542 case ED_TYPE98_108: 543 io_nic = io_asic = ed98_ioaddr_nec108; 544 offset = 0x0888; /* XXX - overwritten after */ 545 reset = 1; 546 n = 16; /* XXX - does not set ASIC i/o here */ 547 break; 548 549 case ED_TYPE98_LA98: 550 io_nic = io_asic = ed98_ioaddr_la98; 551 offset = 0x0100; 552 break; 553 554 case ED_TYPE98_CNET98EL: 555 offset = 0x0400; 556 data = 0x0e; 557 break; 558 559 case ED_TYPE98_CNET98: 560 /* XXX - Yes, we use generic i/o here */ 561 offset = 0x0400; 562 break; 563 564 case ED_TYPE98_NW98X: 565 io_nic = io_asic = ed98_ioaddr_nw98x; 566 offset = 0x1000; 567 break; 568 569 case ED_TYPE98_SB98: 570 io_nic = io_asic = ed98_ioaddr_la98; 571 offset = 0x0400; 572 reset = 7; 573 break; 574 575 case ED_TYPE98_NC5098: 576 io_nic = ed98_ioaddr_nw98x; 577 io_asic = ed98_asic_nc5098; 578 offset = 0x2000; 579 reset = 7; 580 n = 16+8; /* XXX */ 581 break; 582 } 583 584 bcopy(io_nic, io_res, sizeof(io_nic[0]) * ED_NOVELL_ASIC_OFFSET); 585 for (i = ED_NOVELL_ASIC_OFFSET; i < ED_NOVELL_IO_PORTS; i++) { 586 io_res[i] = io_asic[i - ED_NOVELL_ASIC_OFFSET] + offset; 587 } 588 589 res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, 590 io_res, n, RF_ACTIVE); 591 if (!res) { 592 return (ENOENT); 593 } 594 595 sc->port_rid = rid; 596 sc->port_res = res; 597 sc->port_used = n; 598 599 /* Re-map i/o table if needed */ 600 switch (sc->type) { 601 case ED_TYPE98_LA98: 602 case ED_TYPE98_NW98X: 603 io_res[n] = io_asic[n - ED_NOVELL_ASIC_OFFSET] + offset; 604 n++; 605 break; 606 607 case ED_TYPE98_108: 608 adj = (rman_get_start(res) & 0xf000) / 2; 609 offset = (offset | adj) - rman_get_start(res); 610 611 for (n = ED_NOVELL_ASIC_OFFSET; n < ED_NOVELL_IO_PORTS; n++) { 612 io_res[n] = io_asic[n - ED_NOVELL_ASIC_OFFSET] + offset; 613 } 614 break; 615 616 case ED_TYPE98_CNET98: 617 io_nic = io_asic = ed98_ioaddr_cnet98; 618 offset = 1; 619 620 bcopy(io_nic, io_res, sizeof(io_nic[0]) * ED_NOVELL_ASIC_OFFSET); 621 for (n = ED_NOVELL_ASIC_OFFSET; n < ED_NOVELL_IO_PORTS; n++) { 622 io_res[n] = io_asic[n - ED_NOVELL_ASIC_OFFSET] + offset; 623 } 624 break; 625 626 case ED_TYPE98_NC5098: 627 n = ED_NOVELL_IO_PORTS; 628 break; 629 } 630 631 if (reset != ED_NOVELL_RESET) { 632 io_res[ED_NOVELL_ASIC_OFFSET + ED_NOVELL_RESET] = 633 io_res[ED_NOVELL_ASIC_OFFSET + reset]; 634 } 635 if (data != ED_NOVELL_DATA) { 636 io_res[ED_NOVELL_ASIC_OFFSET + ED_NOVELL_DATA] = 637 io_res[ED_NOVELL_ASIC_OFFSET + data]; 638#if 0 639 io_res[ED_NOVELL_ASIC_OFFSET + ED_NOVELL_DATA + 1] = 640 io_res[ED_NOVELL_ASIC_OFFSET + data + 1]; 641#endif 642 } 643 644 error = isa_load_resourcev(res, io_res, n); 645 if (error != 0) { 646 return (ENOENT); 647 } 648#ifdef ED_DEBUG 649 device_printf(dev, "ed98_alloc_port: i/o ports = %d\n", n); 650 for (i = 0; i < n; i++) { 651 printf("%x,", io_res[i]); 652 } 653 printf("\n"); 654#endif 655 return (0); 656} 657 658static int 659ed98_alloc_memory(dev, rid) 660 device_t dev; 661 int rid; 662{ 663 struct ed_softc *sc = device_get_softc(dev); 664 int error; 665 u_long conf_maddr, conf_msize; 666 667 error = bus_get_resource(dev, SYS_RES_MEMORY, 0, 668 &conf_maddr, &conf_msize); 669 if (error) { 670 return (error); 671 } 672 673 if ((conf_maddr == 0) || (conf_msize == 0)) { 674 return (ENXIO); 675 } 676 677 error = ed_alloc_memory(dev, rid, (int) conf_msize); 678 if (error) { 679 return (error); 680 } 681 682 sc->mem_start = (caddr_t) rman_get_virtual(sc->mem_res); 683 sc->mem_size = conf_msize; 684 685 return (0); 686} 687 688/* 689 * Generic probe routine for testing for the existance of a DS8390. 690 * Must be called after the NIC has just been reset. This routine 691 * works by looking at certain register values that are guaranteed 692 * to be initialized a certain way after power-up or reset. Seems 693 * not to currently work on the 83C690. 694 * 695 * Specifically: 696 * 697 * Register reset bits set bits 698 * Command Register (CR) TXP, STA RD2, STP 699 * Interrupt Status (ISR) RST 700 * Interrupt Mask (IMR) All bits 701 * Data Control (DCR) LAS 702 * Transmit Config. (TCR) LB1, LB0 703 * 704 * XXX - We only check the CR register. 705 * 706 * Return 1 if 8390 was found, 0 if not. 707 */ 708 709static int 710ed98_probe_generic8390(sc) 711 struct ed_softc *sc; 712{ 713 u_char tmp = ed_nic_inb(sc, ED_P0_CR); 714#ifdef DIAGNOSTIC 715 printf("ed?: inb(ED_P0_CR)=%x\n", tmp); 716#endif 717 if ((tmp & (ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)) != 718 (ED_CR_RD2 | ED_CR_STP)) { 719 return (0); 720 } 721 722 (void) ed_nic_inb(sc, ED_P0_ISR); 723 724 return (1); 725} 726 727static int 728ed98_probe_Novell(dev, port_rid, flags) 729 device_t dev; 730 int port_rid; 731 int flags; 732{ 733 struct ed_softc *sc = device_get_softc(dev); 734 int error; 735 int n; 736 u_char romdata[ETHER_ADDR_LEN * 2], tmp; 737 738#ifdef ED_DEBUG 739 device_printf(dev, "ed98_probe_Novell: start\n"); 740#endif 741 error = ed98_alloc_port(dev, port_rid); 742 if (error) { 743 return (error); 744 } 745 746 sc->asic_offset = ED_NOVELL_ASIC_OFFSET; 747 sc->nic_offset = ED_NOVELL_NIC_OFFSET; 748 749 /* Reset the board */ 750#ifdef ED_DEBUG 751 device_printf(dev, "ed98_probe_Novell: reset\n"); 752#endif 753 switch (sc->type) { 754#if 1 /* XXX - I'm not sure this is really necessary... */ 755 case ED_TYPE98_BDN: 756 tmp = ed_asic_inb(sc, ED_NOVELL_RESET); 757 ed_asic_outb(sc, ED_NOVELL_RESET, (tmp & 0xf0) | 0x08); 758 ed_nic_outb(sc, 0x04, tmp); 759 (void) ed_asic_inb(sc, 0x08); 760 ed_asic_outb(sc, 0x08, tmp); 761 ed_asic_outb(sc, 0x08, tmp & 0x7f); 762 break; 763#endif 764 case ED_TYPE98_NC5098: 765 ed_asic_outb(sc, ED_NOVELL_RESET, 0x00); 766 DELAY(5000); 767 ed_asic_outb(sc, ED_NOVELL_RESET, 0x01); 768 break; 769 770 default: 771 tmp = ed_asic_inb(sc, ED_NOVELL_RESET); 772 773 /* 774 * I don't know if this is necessary; probably cruft leftover from 775 * Clarkson packet driver code. Doesn't do a thing on the boards I've 776 * tested. -DG [note that a outb(0x84, 0) seems to work here, and is 777 * non-invasive...but some boards don't seem to reset and I don't have 778 * complete documentation on what the 'right' thing to do is...so we 779 * do the invasive thing for now. Yuck.] 780 */ 781 ed_asic_outb(sc, ED_NOVELL_RESET, tmp); 782 break; 783 } 784 DELAY(5000); 785 786 /* 787 * This is needed because some NE clones apparently don't reset the 788 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX 789 * - this makes the probe invasive! ...Done against my better 790 * judgement. -DLG 791 */ 792 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP); 793 DELAY(5000); 794 795 /* Make sure that we really have an 8390 based board */ 796 if (!ed98_probe_generic8390(sc)) { 797 return (ENXIO); 798 } 799 800 /* Test memory via PIO */ 801#ifdef ED_DEBUG 802 device_printf(dev, "ed98_probe_Novell: test memory\n"); 803#endif 804 sc->cr_proto = ED_CR_RD2; 805 if (!ed_pio_testmem(sc, 8192, 0, flags) 806 && !ed_pio_testmem(sc, 16384, 1, flags)) { 807 return (ENXIO); 808 } 809 810 /* Setup the board type */ 811#ifdef ED_DEBUG 812 device_printf(dev, "ed98_probe_Novell: board type\n"); 813#endif 814 switch (sc->type) { 815 case ED_TYPE98_BDN: 816 sc->type_str = "LD-BDN"; 817 break; 818 case ED_TYPE98_EGY: 819 sc->type_str = "EGY-98"; 820 break; 821 case ED_TYPE98_LGY: 822 sc->type_str = "LGY-98"; 823 break; 824 case ED_TYPE98_ICM: 825 sc->type_str = "ICM"; 826 break; 827 case ED_TYPE98_108: 828 sc->type_str = "PC-9801-108"; 829 break; 830 case ED_TYPE98_LA98: 831 sc->type_str = "LA-98"; 832 break; 833 case ED_TYPE98_NW98X: 834 sc->type_str = "NW98X"; 835 break; 836 case ED_TYPE98_NC5098: 837 sc->type_str = "NC5098"; 838 break; 839 default: 840 sc->type_str = NULL; 841 break; 842 } 843 844 /* Get station address */ 845 switch (sc->type) { 846 case ED_TYPE98_NC5098: 847 for (n = 0; n < ETHER_ADDR_LEN; n++) { 848 sc->arpcom.ac_enaddr[n] = 849 ed_asic_inb(sc, ED_NC5098_ENADDR + n); 850 } 851 break; 852 853 default: 854 ed_pio_readmem(sc, 0, romdata, sizeof(romdata)); 855 for (n = 0; n < ETHER_ADDR_LEN; n++) { 856 sc->arpcom.ac_enaddr[n] = 857 romdata[n * (sc->isa16bit + 1)]; 858 } 859 break; 860 } 861 862 /* clear any pending interrupts that might have occurred above */ 863 ed_nic_outb(sc, ED_P0_ISR, 0xff); 864 865 return (0); 866} 867 868/* 869 * Probe and vendor-specific initialization routine for SIC-98 boards 870 */ 871static int 872ed_probe_SIC98(dev, port_rid, flags) 873 device_t dev; 874 int port_rid; 875 int flags; 876{ 877 struct ed_softc *sc = device_get_softc(dev); 878 int error; 879 int i; 880 u_char sum; 881 882 /* 883 * Setup card RAM and I/O address 884 * Kernel Virtual to segment C0000-DFFFF???? 885 */ 886 error = ed98_alloc_port(dev, port_rid); 887 if (error) { 888 return (error); 889 } 890 891 sc->asic_offset = ED_NOVELL_ASIC_OFFSET; 892 sc->nic_offset = ED_NOVELL_NIC_OFFSET; 893 894 error = ed98_alloc_memory(dev, 0); 895 if (error) { 896 return (error); 897 } 898 899 /* Reset card to force it into a known state. */ 900 ed_asic_outb(sc, 0, 0x00); 901 DELAY(100); 902 if (ED_TYPE98SUB(flags) == 0) { 903 /* SIC-98/SIU-98 */ 904 ed_asic_outb(sc, 0, 0x94); 905 DELAY(100); 906 ed_asic_outb(sc, 0, 0x94); 907 } else { 908 /* SIU-98-D */ 909 ed_asic_outb(sc, 0, 0x80); 910 DELAY(100); 911 ed_asic_outb(sc, 0, 0x94); 912 DELAY(100); 913 ed_asic_outb(sc, 0, 0x9e); 914 } 915 DELAY(100); 916 917 /* 918 * Here we check the card ROM, if the checksum passes, and the 919 * type code and ethernet address check out, then we know we have 920 * an SIC card. 921 */ 922 sum = sc->mem_start[6 * 2]; 923 for (i = 0; i < ETHER_ADDR_LEN; i++) { 924 sum ^= (sc->arpcom.ac_enaddr[i] = sc->mem_start[i * 2]); 925 } 926#ifdef ED_DEBUG 927 device_printf(dev, "ed_probe_sic98: got address %6D\n", 928 sc->arpcom.ac_enaddr, ":"); 929#endif 930 if (sum != 0) { 931 return (ENXIO); 932 } 933 if ((sc->arpcom.ac_enaddr[0] | sc->arpcom.ac_enaddr[1] | 934 sc->arpcom.ac_enaddr[2]) == 0) { 935 return (ENXIO); 936 } 937 938 sc->vendor = ED_VENDOR_MISC; 939 sc->type_str = "SIC98"; 940 sc->isa16bit = 1; 941 sc->cr_proto = 0; 942 943 /* 944 * SIC RAM page 0x0000-0x3fff(or 0x7fff) 945 */ 946 if (ED_TYPE98SUB(flags) == 0) { 947 ed_asic_outb(sc, 0, 0x90); 948 } else { 949 ed_asic_outb(sc, 0, 0x8e); 950 } 951 DELAY(100); 952 953 /* 954 * clear interface memory, then sum to make sure its valid 955 */ 956 bzero(sc->mem_start, sc->mem_size); 957 958 for (i = 0; i < sc->mem_size; i++) { 959 if (sc->mem_start[i]) { 960 device_printf(dev, "failed to clear shared memory " 961 "at %lx - check configuration\n", 962 kvtop(sc->mem_start + i)); 963 964 return (ENXIO); 965 } 966 } 967 968 sc->mem_shared = 1; 969 sc->mem_end = sc->mem_start + sc->mem_size; 970 971 /* 972 * allocate one xmit buffer if < 16k, two buffers otherwise 973 */ 974 if ((sc->mem_size < 16384) || (flags & ED_FLAGS_NO_MULTI_BUFFERING)) { 975 sc->txb_cnt = 1; 976 } else { 977 sc->txb_cnt = 2; 978 } 979 sc->tx_page_start = 0; 980 981 sc->rec_page_start = sc->tx_page_start + ED_TXBUF_SIZE * sc->txb_cnt; 982 sc->rec_page_stop = sc->tx_page_start + sc->mem_size / ED_PAGE_SIZE; 983 984 sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE; 985 986 return (0); 987} 988 989/* 990 * Contec C-NET(98) series support routines 991 */ 992static void 993ed_reset_CNET98(sc, flags) 994 struct ed_softc *sc; 995 int flags; 996{ 997 u_short init_addr = ED_CNET98_INIT; 998 u_char tmp; 999 1000 /* Choose initial register address */ 1001 if (ED_TYPE98SUB(flags) != 0) { 1002 init_addr = ED_CNET98_INIT2; 1003 } 1004#ifdef ED_DEBUG 1005 printf("ed?: initial register=%x\n", init_addr); 1006#endif 1007 /* 1008 * Reset the board to force it into a known state. 1009 */ 1010 outb(init_addr, 0x00); /* request */ 1011 DELAY(5000); 1012 outb(init_addr, 0x01); /* cancel */ 1013 DELAY(5000); 1014 1015 /* 1016 * Set I/O address(A15-12) and cpu type 1017 * 1018 * AAAAIXXC(8bit) 1019 * AAAA: A15-A12, I: I/O enable, XX: reserved, C: CPU type 1020 * 1021 * CPU type is 1:80286 or higher, 0:not. 1022 * But FreeBSD runs under i386 or higher, thus it must be 1. 1023 */ 1024 tmp = (rman_get_start(sc->port_res) & 0xf000) >> 8; 1025 tmp |= (0x08 | 0x01); 1026#ifdef ED_DEBUG 1027 printf("ed?: outb(%x, %x)\n", init_addr + 2, tmp); 1028#endif 1029 outb(init_addr + 2, tmp); 1030 DELAY(5000); 1031 1032 /* 1033 * This is needed because some NE clones apparently don't reset the 1034 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX 1035 * - this makes the probe invasive! ...Done against my better 1036 * judgement. -DLG 1037 */ 1038 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP); 1039 DELAY(5000); 1040} 1041 1042static void 1043ed_winsel_CNET98(sc, bank) 1044 struct ed_softc *sc; 1045 u_short bank; 1046{ 1047 u_char mem = (kvtop(sc->mem_start) >> 12) & 0xff; 1048 1049 /* 1050 * Disable window memory 1051 * bit7 is 0:disable 1052 */ 1053 ed_asic_outb(sc, ED_CNET98_WIN_REG, mem & 0x7f); 1054 DELAY(10); 1055 1056 /* 1057 * Select window address 1058 * FreeBSD address 0xf00xxxxx 1059 */ 1060 ed_asic_outb(sc, ED_CNET98_MAP_REG0L, bank & 0xff); 1061 DELAY(10); 1062 ed_asic_outb(sc, ED_CNET98_MAP_REG0H, (bank >> 8) & 0xff); 1063 DELAY(10); 1064 ed_asic_outb(sc, ED_CNET98_MAP_REG1L, 0x00); 1065 DELAY(10); 1066 ed_asic_outb(sc, ED_CNET98_MAP_REG1H, 0x41); 1067 DELAY(10); 1068 ed_asic_outb(sc, ED_CNET98_MAP_REG2L, 0x00); 1069 DELAY(10); 1070 ed_asic_outb(sc, ED_CNET98_MAP_REG2H, 0x42); 1071 DELAY(10); 1072 ed_asic_outb(sc, ED_CNET98_MAP_REG3L, 0x00); 1073 DELAY(10); 1074 ed_asic_outb(sc, ED_CNET98_MAP_REG3H, 0x43); 1075 DELAY(10); 1076 1077 /* 1078 * Enable window memory(16Kbyte) 1079 * bit7 is 1:enable 1080 */ 1081#ifdef ED_DEBUG 1082 printf("ed?: window start address=%x\n", mem); 1083#endif 1084 ed_asic_outb(sc, ED_CNET98_WIN_REG, mem); 1085 DELAY(10); 1086} 1087 1088/* 1089 * Probe and vendor-specific initialization routine for C-NET(98) boards 1090 */ 1091static int 1092ed_probe_CNET98(dev, port_rid, flags) 1093 device_t dev; 1094 int port_rid; 1095 int flags; 1096{ 1097 struct ed_softc *sc = device_get_softc(dev); 1098 int error; 1099 u_char tmp; 1100 u_long conf_irq, junk; 1101 int i; 1102#ifdef DIAGNOSTIC 1103 u_char tmp_s; 1104#endif 1105 1106 error = ed98_alloc_port(dev, port_rid); 1107 if (error) { 1108 return (error); 1109 } 1110 1111 sc->asic_offset = ED_NOVELL_ASIC_OFFSET; 1112 sc->nic_offset = ED_NOVELL_NIC_OFFSET; 1113 1114 error = ed98_alloc_memory(dev, 0); 1115 if (error) { 1116 return (error); 1117 } 1118 1119 /* Check I/O address. 0x[a-f]3d0 are allowed. */ 1120 if (((rman_get_start(sc->port_res) & 0x0fff) != 0x03d0) 1121 || ((rman_get_start(sc->port_res) & 0xf000) < (u_short) 0xa000)) { 1122#ifdef DIAGNOSTIC 1123 device_printf(dev, "Invalid i/o port configuration (0x%x) " 1124 "must be %s for %s\n", rman_get_start(sc->port_res), 1125 "0x[a-f]3d0", "CNET98"); 1126#endif 1127 return (ENXIO); 1128 } 1129 1130#ifdef DIAGNOSTIC 1131 /* Check window area address */ 1132 tmp_s = kvtop(sc->mem_start) >> 12; 1133 if (tmp_s < 0x80) { 1134 device_printf(dev, "Please change window address(0x%x)\n", 1135 kvtop(sc->mem_start)); 1136 return (ENXIO); 1137 } 1138 1139 tmp_s &= 0x0f; 1140 tmp = rman_get_start(sc->port_res) >> 12; 1141 if ((tmp_s <= tmp) && (tmp < (tmp_s + 4))) { 1142 device_printf(dev, "Please change iobase address(0x%x) " 1143 "or window address(0x%x)\n", 1144 rman_get_start(sc->port_res), kvtop(sc->mem_start)); 1145 return (ENXIO); 1146 } 1147#endif 1148 /* Reset the board */ 1149 ed_reset_CNET98(sc, flags); 1150 1151 /* 1152 * This is needed because some NE clones apparently don't reset the 1153 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX 1154 * - this makes the probe invasive! ...Done against my better 1155 * judgement. -DLG 1156 */ 1157 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP); 1158 DELAY(5000); 1159 1160 /* Make sure that we really have an 8390 based board */ 1161 if (!ed98_probe_generic8390(sc)) { 1162 return (ENXIO); 1163 } 1164 1165 /* 1166 * Set window ethernet address area 1167 * board memory base 0x480000 data 256byte 1168 */ 1169 ed_winsel_CNET98(sc, 0x4800); 1170 1171 /* 1172 * Get station address from on-board ROM 1173 */ 1174 bcopy(sc->mem_start, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 1175 1176 sc->vendor = ED_VENDOR_MISC; 1177 sc->type_str = "CNET98"; 1178 sc->isa16bit = 0; 1179 sc->cr_proto = ED_CR_RD2; 1180 1181 /* 1182 * Set window buffer memory area 1183 * board memory base 0x400000 data 16kbyte 1184 */ 1185 ed_winsel_CNET98(sc, 0x4000); 1186 1187 /* 1188 * clear interface memory, then sum to make sure its valid 1189 */ 1190 bzero(sc->mem_start, sc->mem_size); 1191 1192 for (i = 0; i < sc->mem_size; i++) { 1193 if (sc->mem_start[i]) { 1194 device_printf(dev, "failed to clear shared memory " 1195 "at %lx - check configuration\n", 1196 kvtop(sc->mem_start + i)); 1197 1198 return (ENXIO); 1199 } 1200 } 1201 1202 sc->mem_shared = 1; 1203 sc->mem_end = sc->mem_start + sc->mem_size; 1204 1205 sc->txb_cnt = 1; /* XXX */ 1206 sc->tx_page_start = 0; 1207 1208 sc->rec_page_start = sc->tx_page_start + ED_TXBUF_SIZE; 1209 sc->rec_page_stop = sc->tx_page_start + sc->mem_size / ED_PAGE_SIZE; 1210 1211 sc->mem_ring = sc->mem_start + ED_PAGE_SIZE * ED_TXBUF_SIZE; 1212 1213 /* 1214 * Set interrupt level 1215 */ 1216 error = bus_get_resource(dev, SYS_RES_IRQ, 0, 1217 &conf_irq, &junk); 1218 if (error) 1219 return (error); 1220 1221 switch (conf_irq) { 1222 case 3: 1223 tmp = ED_CNET98_INT_IRQ3; 1224 break; 1225 case 5: 1226 tmp = ED_CNET98_INT_IRQ5; 1227 break; 1228 case 6: 1229 tmp = ED_CNET98_INT_IRQ6; 1230 break; 1231 case 9: 1232 tmp = ED_CNET98_INT_IRQ9; 1233 break; 1234 case 12: 1235 tmp = ED_CNET98_INT_IRQ12; 1236 break; 1237 case 13: 1238 tmp = ED_CNET98_INT_IRQ13; 1239 break; 1240 default: 1241 device_printf(dev, "Invalid irq configuration (%ld) must be " 1242 "%s for %s\n", conf_irq, "3,5,6,9,12,13", "CNET98"); 1243 return (ENXIO); 1244 } 1245 ed_asic_outb(sc, ED_CNET98_INT_LEV, tmp); 1246 DELAY(1000); 1247 /* 1248 * Set interrupt mask. 1249 * bit7:1 all interrupt mask 1250 * bit1:1 timer interrupt mask 1251 * bit0:0 NS controler interrupt enable 1252 */ 1253 ed_asic_outb(sc, ED_CNET98_INT_MASK, 0x7e); 1254 DELAY(1000); 1255 1256 return (0); 1257} 1258 1259/* 1260 * Probe and vendor-specific initialization routine for C-NET(98)E/L boards 1261 */ 1262static int 1263ed_probe_CNET98EL(dev, port_rid, flags) 1264 device_t dev; 1265 int port_rid; 1266 int flags; 1267{ 1268 struct ed_softc *sc = device_get_softc(dev); 1269 int error; 1270 int i; 1271 u_char romdata[ETHER_ADDR_LEN * 2], tmp; 1272 u_long conf_irq, junk; 1273 1274 error = ed98_alloc_port(dev, port_rid); 1275 if (error) { 1276 return (error); 1277 } 1278 1279 sc->asic_offset = ED_NOVELL_ASIC_OFFSET; 1280 sc->nic_offset = ED_NOVELL_NIC_OFFSET; 1281 1282 /* Check I/O address. 0x[0-f]3d0 are allowed. */ 1283 if ((rman_get_start(sc->port_res) & 0x0fff) != 0x03d0) { 1284#ifdef DIAGNOSTIC 1285 device_printf(dev, "Invalid i/o port configuration (0x%x) " 1286 "must be %s for %s\n", rman_get_start(sc->port_res), 1287 "0x?3d0", "CNET98E/L"); 1288#endif 1289 return (ENXIO); 1290 } 1291 1292 /* Reset the board */ 1293 ed_reset_CNET98(sc, flags); 1294 1295 /* 1296 * This is needed because some NE clones apparently don't reset the 1297 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX 1298 * - this makes the probe invasive! ...Done against my better 1299 * judgement. -DLG 1300 */ 1301 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP); 1302 DELAY(5000); 1303 1304 /* Make sure that we really have an 8390 based board */ 1305 if (!ed98_probe_generic8390(sc)) { 1306 return (ENXIO); 1307 } 1308 1309 /* Test memory via PIO */ 1310 sc->cr_proto = ED_CR_RD2; 1311 if (!ed_pio_testmem(sc, ED_CNET98EL_PAGE_OFFSET, 1, flags)) { 1312 return (ENXIO); 1313 } 1314 1315 /* This looks like a C-NET(98)E/L board. */ 1316 sc->type_str = "CNET98E/L"; 1317 1318 /* 1319 * Set IRQ. C-NET(98)E/L only allows a choice of irq 3,5,6. 1320 */ 1321 error = bus_get_resource(dev, SYS_RES_IRQ, 0, 1322 &conf_irq, &junk); 1323 if (error) { 1324 return (error); 1325 } 1326 1327 switch (conf_irq) { 1328 case 3: 1329 tmp = ED_CNET98EL_ICR_IRQ3; 1330 break; 1331 case 5: 1332 tmp = ED_CNET98EL_ICR_IRQ5; 1333 break; 1334 case 6: 1335 tmp = ED_CNET98EL_ICR_IRQ6; 1336 break; 1337#if 0 1338 case 12: 1339 tmp = ED_CNET98EL_ICR_IRQ12; 1340 break; 1341#endif 1342 default: 1343 device_printf(dev, "Invalid irq configuration (%ld) must be " 1344 "%s for %s\n", conf_irq, "3,5,6", "CNET98E/L"); 1345 return (ENXIO); 1346 } 1347 ed_asic_outb(sc, ED_CNET98EL_ICR, tmp); 1348 ed_asic_outb(sc, ED_CNET98EL_IMR, 0x7e); 1349 1350 /* Get station address from on-board ROM */ 1351 ed_pio_readmem(sc, 16384, romdata, sizeof(romdata)); 1352 for (i = 0; i < ETHER_ADDR_LEN; i++) { 1353 sc->arpcom.ac_enaddr[i] = romdata[i * 2]; 1354 } 1355 1356 /* clear any pending interrupts that might have occurred above */ 1357 ed_nic_outb(sc, ED_P0_ISR, 0xff); 1358 1359 return (0); 1360} 1361 1362/* 1363 * Probe and vendor-specific initialization routine for PC-9801-77 boards 1364 */ 1365static int 1366ed_probe_NEC77(dev, port_rid, flags) 1367 device_t dev; 1368 int port_rid; 1369 int flags; 1370{ 1371 struct ed_softc *sc = device_get_softc(dev); 1372 int error; 1373 u_char tmp; 1374 u_long conf_irq, junk; 1375 1376 error = ed98_probe_Novell(dev, port_rid, flags); 1377 if (error) { 1378 return (error); 1379 } 1380 1381 /* LA/T-98 does not need IRQ setting. */ 1382 if (ED_TYPE98SUB(flags) == 0) { 1383 return (0); 1384 } 1385 1386 /* 1387 * Set IRQ. PC-9801-77 only allows a choice of irq 3,5,6,12,13. 1388 */ 1389 error = bus_get_resource(dev, SYS_RES_IRQ, 0, 1390 &conf_irq, &junk); 1391 if (error) { 1392 return (error); 1393 } 1394 1395 switch (conf_irq) { 1396 case 3: 1397 tmp = ED_NEC77_IRQ3; 1398 break; 1399 case 5: 1400 tmp = ED_NEC77_IRQ5; 1401 break; 1402 case 6: 1403 tmp = ED_NEC77_IRQ6; 1404 break; 1405 case 12: 1406 tmp = ED_NEC77_IRQ12; 1407 break; 1408 case 13: 1409 tmp = ED_NEC77_IRQ13; 1410 break; 1411 default: 1412 device_printf(dev, "Invalid irq configuration (%ld) must be " 1413 "%s for %s\n", conf_irq, "3,5,6,12,13", "PC-9801-77"); 1414 return (ENXIO); 1415 } 1416 ed_asic_outb(sc, ED_NEC77_IRQ, tmp); 1417 1418 return (0); 1419} 1420 1421/* 1422 * Probe and vendor-specific initialization routine for EC/EP-98X boards 1423 */ 1424static int 1425ed_probe_NW98X(dev, port_rid, flags) 1426 device_t dev; 1427 int port_rid; 1428 int flags; 1429{ 1430 struct ed_softc *sc = device_get_softc(dev); 1431 int error; 1432 u_char tmp; 1433 u_long conf_irq, junk; 1434 1435 error = ed98_probe_Novell(dev, port_rid, flags); 1436 if (error) { 1437 return (error); 1438 } 1439 1440 /* Networld 98X3 does not need IRQ setting. */ 1441 if (ED_TYPE98SUB(flags) == 0) { 1442 return (0); 1443 } 1444 1445 /* 1446 * Set IRQ. EC/EP-98X only allows a choice of irq 3,5,6,12,13. 1447 */ 1448 error = bus_get_resource(dev, SYS_RES_IRQ, 0, 1449 &conf_irq, &junk); 1450 if (error) { 1451 return (error); 1452 } 1453 1454 switch (conf_irq) { 1455 case 3: 1456 tmp = ED_NW98X_IRQ3; 1457 break; 1458 case 5: 1459 tmp = ED_NW98X_IRQ5; 1460 break; 1461 case 6: 1462 tmp = ED_NW98X_IRQ6; 1463 break; 1464 case 12: 1465 tmp = ED_NW98X_IRQ12; 1466 break; 1467 case 13: 1468 tmp = ED_NW98X_IRQ13; 1469 break; 1470 default: 1471 device_printf(dev, "Invalid irq configuration (%ld) must be " 1472 "%s for %s\n", conf_irq, "3,5,6,12,13", "EC/EP-98X"); 1473 return (ENXIO); 1474 } 1475 ed_asic_outb(sc, ED_NW98X_IRQ, tmp); 1476 1477 return (0); 1478} 1479 1480/* 1481 * Read SB-9801 station address from Serial Two-Wire EEPROM 1482 */ 1483static void 1484ed_get_SB98(sc) 1485 struct ed_softc *sc; 1486{ 1487 int i, j; 1488 u_char mask, val; 1489 1490 /* enable EEPROM acceess */ 1491 ed_asic_outb(sc, ED_SB98_EEPENA, ED_SB98_EEPENA_ENABLE); 1492 1493 /* output start command */ 1494 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA | ED_SB98_EEP_SCL); 1495 DELAY(ED_SB98_EEP_DELAY); 1496 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SCL); 1497 DELAY(ED_SB98_EEP_DELAY); 1498 1499 /* output address (7bit) */ 1500 for (mask = 0x40; mask != 0; mask >>= 1) { 1501 val = 0; 1502 if (ED_SB98_ADDRESS & mask) 1503 val = ED_SB98_EEP_SDA; 1504 ed_asic_outb(sc, ED_SB98_EEP, val); 1505 DELAY(ED_SB98_EEP_DELAY); 1506 ed_asic_outb(sc, ED_SB98_EEP, val | ED_SB98_EEP_SCL); 1507 DELAY(ED_SB98_EEP_DELAY); 1508 } 1509 1510 /* output READ command */ 1511 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_READ); 1512 DELAY(ED_SB98_EEP_DELAY); 1513 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_READ | ED_SB98_EEP_SCL); 1514 DELAY(ED_SB98_EEP_DELAY); 1515 1516 /* read station address */ 1517 for (i = 0; i < ETHER_ADDR_LEN; i++) { 1518 /* output ACK */ 1519 ed_asic_outb(sc, ED_SB98_EEP, 0); 1520 DELAY(ED_SB98_EEP_DELAY); 1521 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SCL); 1522 DELAY(ED_SB98_EEP_DELAY); 1523 1524 val = 0; 1525 for (j = 0; j < 8; j++) { 1526 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA); 1527 DELAY(ED_SB98_EEP_DELAY); 1528 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA | ED_SB98_EEP_SCL); 1529 DELAY(ED_SB98_EEP_DELAY); 1530 val <<= 1; 1531 val |= (ed_asic_inb(sc, ED_SB98_EEP) & ED_SB98_EEP_SDA); 1532 DELAY(ED_SB98_EEP_DELAY); 1533 } 1534 sc->arpcom.ac_enaddr[i] = val; 1535 } 1536 1537 /* output Last ACK */ 1538 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA); 1539 DELAY(ED_SB98_EEP_DELAY); 1540 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA | ED_SB98_EEP_SCL); 1541 DELAY(ED_SB98_EEP_DELAY); 1542 1543 /* output stop command */ 1544 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SCL); 1545 DELAY(ED_SB98_EEP_DELAY); 1546 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA | ED_SB98_EEP_SCL); 1547 DELAY(ED_SB98_EEP_DELAY); 1548 1549 /* disable EEPROM access */ 1550 ed_asic_outb(sc, ED_SB98_EEPENA, ED_SB98_EEPENA_DISABLE); 1551} 1552 1553/* 1554 * Probe and vendor-specific initialization routine for SB-9801 boards 1555 */ 1556static int 1557ed_probe_SB98(dev, port_rid, flags) 1558 device_t dev; 1559 int port_rid; 1560 int flags; 1561{ 1562 struct ed_softc *sc = device_get_softc(dev); 1563 int error; 1564 u_char tmp; 1565 u_long conf_irq, junk; 1566 1567 error = ed98_alloc_port(dev, port_rid); 1568 if (error) { 1569 return (error); 1570 } 1571 1572 sc->asic_offset = ED_NOVELL_ASIC_OFFSET; 1573 sc->nic_offset = ED_NOVELL_NIC_OFFSET; 1574 1575 /* Check I/O address. 00d[02468ace] are allowed. */ 1576 if ((rman_get_start(sc->port_res) & ~0x000e) != 0x00d0) { 1577#ifdef DIAGNOSTIC 1578 device_printf(dev, "Invalid i/o port configuration (0x%x) " 1579 "must be %s for %s\n", rman_get_start(sc->port_res), 1580 "0xd?", "SB9801"); 1581#endif 1582 return (ENXIO); 1583 } 1584 1585 /* Write I/O port address and read 4 times */ 1586 outb(ED_SB98_IO_INHIBIT, rman_get_start(sc->port_res) & 0xff); 1587 (void) inb(ED_SB98_IO_INHIBIT); DELAY(300); 1588 (void) inb(ED_SB98_IO_INHIBIT); DELAY(300); 1589 (void) inb(ED_SB98_IO_INHIBIT); DELAY(300); 1590 (void) inb(ED_SB98_IO_INHIBIT); DELAY(300); 1591 1592 /* 1593 * Check IRQ. Soliton SB-9801 only allows a choice of 1594 * irq 3,5,6,12 1595 */ 1596 error = bus_get_resource(dev, SYS_RES_IRQ, 0, 1597 &conf_irq, &junk); 1598 if (error) { 1599 return (error); 1600 } 1601 1602 switch (conf_irq) { 1603 case 3: 1604 tmp = ED_SB98_CFG_IRQ3; 1605 break; 1606 case 5: 1607 tmp = ED_SB98_CFG_IRQ5; 1608 break; 1609 case 6: 1610 tmp = ED_SB98_CFG_IRQ6; 1611 break; 1612 case 12: 1613 tmp = ED_SB98_CFG_IRQ12; 1614 break; 1615 default: 1616 device_printf(dev, "Invalid irq configuration (%ld) must be " 1617 "%s for %s\n", conf_irq, "3,5,6,12", "SB9801"); 1618 return (ENXIO); 1619 } 1620 1621 if (flags & ED_FLAGS_DISABLE_TRANCEIVER) { 1622 tmp |= ED_SB98_CFG_ALTPORT; 1623 } 1624 ed_asic_outb(sc, ED_SB98_CFG, ED_SB98_CFG_ENABLE | tmp); 1625 ed_asic_outb(sc, ED_SB98_POLARITY, 0x01); 1626 1627 /* Reset the board. */ 1628 ed_asic_outb(sc, ED_NOVELL_RESET, 0x7a); 1629 DELAY(300); 1630 ed_asic_outb(sc, ED_NOVELL_RESET, 0x79); 1631 DELAY(300); 1632 1633 /* 1634 * This is needed because some NE clones apparently don't reset the 1635 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX 1636 * - this makes the probe invasive! ...Done against my better 1637 * judgement. -DLG 1638 */ 1639 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP); 1640 DELAY(5000); 1641 1642 /* Make sure that we really have an 8390 based board */ 1643 if (!ed98_probe_generic8390(sc)) { 1644 return (ENXIO); 1645 } 1646 1647 /* Test memory via PIO */ 1648 sc->cr_proto = ED_CR_RD2; 1649 if (!ed_pio_testmem(sc, 16384, 1, flags)) { 1650 return (ENXIO); 1651 } 1652 1653 /* This looks like an SB9801 board. */ 1654 sc->type_str = "SB9801"; 1655 1656 /* Get station address */ 1657 ed_get_SB98(sc); 1658 1659 /* clear any pending interrupts that might have occurred above */ 1660 ed_nic_outb(sc, ED_P0_ISR, 0xff); 1661 1662 return (0); 1663} 1664 1665/* 1666 * Test the ability to read and write to the NIC memory. 1667 */ 1668static int 1669ed_pio_testmem(sc, page_offset, isa16bit, flags) 1670 struct ed_softc *sc; 1671 int page_offset; 1672 int isa16bit; 1673 int flags; 1674{ 1675 u_long memsize; 1676 static char test_pattern[32] = "THIS is A memory TEST pattern"; 1677 char test_buffer[32]; 1678#ifdef DIAGNOSTIC 1679 int page_end; 1680#endif 1681 1682 sc->vendor = ED_VENDOR_NOVELL; 1683 sc->mem_shared = 0; 1684 sc->isa16bit = isa16bit; 1685 1686 /* 8k of memory plus an additional 8k if 16bit */ 1687 memsize = (isa16bit ? 16384 : 8192); 1688 1689 /* 1690 * This prevents packets from being stored in the NIC memory when the 1691 * readmem routine turns on the start bit in the CR. 1692 */ 1693 ed_nic_outb(sc, ED_P0_RCR, ED_RCR_MON); 1694 1695 /* Initialize DCR for byte/word operations */ 1696 if (isa16bit) { 1697 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS); 1698 } else { 1699 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS); 1700 } 1701 ed_nic_outb(sc, ED_P0_PSTART, page_offset / ED_PAGE_SIZE); 1702 ed_nic_outb(sc, ED_P0_PSTOP, (page_offset + memsize) / ED_PAGE_SIZE); 1703#ifdef ED_DEBUG 1704 printf("ed?: ed_pio_testmem: page start=%x, end=%x", 1705 page_offset, page_offset + memsize); 1706#endif 1707 1708 /* 1709 * Write a test pattern. If this fails, then we don't know 1710 * what this board is. 1711 */ 1712 ed_pio_writemem(sc, test_pattern, page_offset, sizeof(test_pattern)); 1713 ed_pio_readmem(sc, page_offset, test_buffer, sizeof(test_pattern)); 1714 1715 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) { 1716#ifdef ED_DEBUG 1717 printf("ed?: ed_pio_testmem: bcmp(page %x) NG", 1718 page_offset); 1719#endif 1720 return (0); 1721 } 1722 1723#ifdef DIAGNOSTIC 1724 /* Check the bottom. */ 1725 page_end = page_offset + memsize - ED_PAGE_SIZE; 1726 ed_pio_writemem(sc, test_pattern, page_end, sizeof(test_pattern)); 1727 ed_pio_readmem(sc, page_end, test_buffer, sizeof(test_pattern)); 1728 1729 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) { 1730#ifdef ED_DEBUG 1731 printf("ed?: ed_pio_testmem: bcmp(page %x) NG", 1732 page_end); 1733#endif 1734 return (0); 1735 } 1736#endif 1737 sc->mem_size = memsize; 1738 sc->mem_start = (char *) page_offset; 1739 sc->mem_end = sc->mem_start + memsize; 1740 sc->tx_page_start = page_offset / ED_PAGE_SIZE; 1741 1742 /* 1743 * Use one xmit buffer if < 16k, two buffers otherwise (if not told 1744 * otherwise). 1745 */ 1746 if ((memsize < 16384) || (flags & ED_FLAGS_NO_MULTI_BUFFERING)) { 1747 sc->txb_cnt = 1; 1748 } else { 1749 sc->txb_cnt = 2; 1750 } 1751 1752 sc->rec_page_start = sc->tx_page_start + sc->txb_cnt * ED_TXBUF_SIZE; 1753 sc->rec_page_stop = sc->tx_page_start + memsize / ED_PAGE_SIZE; 1754 1755 sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE; 1756 1757 return (1); 1758} 1759#endif /* PC98 */ 1760