if_fea.c revision 46332
1#warning "fix if_fea.c! - newbus casualty" 2#if 0 3/*- 4 * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. The name of the author may not be used to endorse or promote products 13 * derived from this software withough specific prior written permission 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $Id: if_fea.c,v 1.13 1999/01/12 00:36:27 eivind Exp $ 27 */ 28 29/* 30 * DEC PDQ FDDI Controller 31 * 32 * This module support the DEFEA EISA FDDI Controller. 33 */ 34 35#include <sys/param.h> 36#include <sys/kernel.h> 37#include <sys/socket.h> 38#if defined(__bsdi__) || defined(__NetBSD__) 39#include <sys/device.h> 40#endif 41 42#include <net/if.h> 43#include <net/if_arp.h> 44 45#if defined(__FreeBSD__) 46#include <i386/eisa/eisaconf.h> 47#include <dev/pdq/pdqvar.h> 48#include <dev/pdq/pdqreg.h> 49#elif defined(__bsdi__) 50#include <i386/isa/isa.h> 51#include <i386/isa/icu.h> 52#include <i386/isa/dma.h> 53#include <i386/isa/isavar.h> 54#include <i386/eisa/eisa.h> 55#include <dev/pdq/pdqvar.h> 56#include <dev/pdq/pdqreg.h> 57#elif defined(__NetBSD__) 58#include <machine/cpu.h> 59#include <machine/bus.h> 60 61#include <dev/ic/pdqvar.h> 62#include <dev/ic/pdqreg.h> 63 64#include <dev/eisa/eisareg.h> 65#include <dev/eisa/eisavar.h> 66#include <dev/eisa/eisadevs.h> 67#endif 68 69/* 70 * 71 */ 72 73#define DEFEA_IRQS 0x0000FBA9U 74 75#if defined(__FreeBSD__) 76static pdq_softc_t *pdqs_eisa[16]; 77#define PDQ_EISA_UNIT_TO_SOFTC(unit) (pdqs_eisa[unit]) 78#define DEFEA_INTRENABLE 0x8 /* level interrupt */ 79#define pdq_eisa_ifwatchdog NULL 80#define DEFEA_DECODE_IRQ(n) ((DEFEA_IRQS >> ((n) << 2)) & 0x0f) 81 82#elif defined(__bsdi__) 83extern struct cfdriver feacd; 84#define PDQ_EISA_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)feacd.cd_devs[unit]) 85#define DEFEA_INTRENABLE 0x28 /* edge interrupt */ 86static const int pdq_eisa_irqs[4] = { IRQ9, IRQ10, IRQ11, IRQ15 }; 87#define DEFEA_DECODE_IRQ(n) (pdq_eisa_irqs[(n)]) 88 89#elif defined(__NetBSD__) 90#define DEFEA_INTRENABLE 0x8 /* level interrupt */ 91#define pdq_eisa_ifwatchdog NULL 92#define DEFEA_DECODE_IRQ(n) ((DEFEA_IRQS >> ((n) << 2)) & 0x0f) 93 94#else 95#error unknown system 96#endif 97 98#ifndef pdq_eisa_ifwatchdog 99static ifnet_ret_t 100pdq_eisa_ifwatchdog( 101 int unit) 102{ 103 pdq_ifwatchdog(&PDQ_EISA_UNIT_TO_SOFTC(unit)->sc_if); 104} 105#endif 106 107static void 108pdq_eisa_subprobe( 109 pdq_bus_t bc, 110 pdq_bus_ioport_t iobase, 111 pdq_uint32_t *maddr, 112 pdq_uint32_t *msize, 113 pdq_uint32_t *irq) 114{ 115 if (irq != NULL) 116 *irq = DEFEA_DECODE_IRQ(PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_IO_CONFIG_STAT_0) & 3); 117 *maddr = (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_CMP_0) << 8) 118 | (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_CMP_1) << 16); 119 *msize = (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_MASK_0) + 4) << 8; 120} 121 122static void 123pdq_eisa_devinit( 124 pdq_softc_t *sc) 125{ 126 pdq_uint8_t data; 127 128 /* 129 * Do the standard initialization for the DEFEA registers. 130 */ 131 PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_FUNCTION_CTRL, 0x23); 132 PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CMP_1_1, (sc->sc_iobase >> 8) & 0xF0); 133 PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CMP_0_1, (sc->sc_iobase >> 8) & 0xF0); 134 PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_SLOT_CTRL, 0x01); 135 data = PDQ_OS_IORD_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF); 136#if defined(PDQ_IOMAPPED) 137 PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF, data & ~1); 138#else 139 PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF, data | 1); 140#endif 141 data = PDQ_OS_IORD_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CONFIG_STAT_0); 142 PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CONFIG_STAT_0, data | DEFEA_INTRENABLE); 143} 144 145#if defined(__FreeBSD__) 146static void pdq_eisa_shutdown(int howto, void *sc); 147static int pdq_eisa_probe(void); 148static int pdq_eisa_attach(struct eisa_device *ed); 149 150static unsigned long pdq_eisa_unit; 151 152static struct eisa_driver pdq_eisa_driver = { 153 "fea", pdq_eisa_probe, pdq_eisa_attach, NULL, &pdq_eisa_unit 154}; 155 156DATA_SET(eisadriver_set, pdq_eisa_driver); 157 158 159static const char * 160pdq_eisa_match( 161 eisa_id_t type) 162{ 163 if ((type >> 8) == 0x10a330) 164 return ("DEC DEFEA EISA FDDI Controller"); 165 return NULL; 166} 167 168static int 169pdq_eisa_probe( 170 void) 171{ 172 struct eisa_device *ed = NULL; 173 int count; 174 175 for (count = 0; (ed = eisa_match_dev(ed, pdq_eisa_match)) != NULL; count++) { 176 pdq_bus_ioport_t iobase = ed->ioconf.slot * EISA_SLOT_SIZE; 177 pdq_uint32_t irq, maddr, msize; 178 179 eisa_add_iospace(ed, iobase, 0x200, RESVADDR_NONE); 180 pdq_eisa_subprobe(PDQ_BUS_EISA, iobase, &maddr, &msize, &irq); 181 eisa_add_mspace(ed, maddr, msize, RESVADDR_NONE); 182 eisa_add_intr(ed, irq); 183 eisa_registerdev(ed, &pdq_eisa_driver); 184 } 185 return count; 186} 187 188static void 189pdq_eisa_interrupt( 190 void *arg) 191{ 192 pdq_softc_t * const sc = (pdq_softc_t *) arg; 193 (void) pdq_interrupt(sc->sc_pdq); 194} 195 196static int 197pdq_eisa_attach( 198 struct eisa_device *ed) 199{ 200 pdq_softc_t *sc; 201 resvaddr_t *iospace; 202 resvaddr_t *mspace; 203 int irq; 204 205 if (TAILQ_FIRST(&ed->ioconf.irqs) == NULL) 206 return (-1); 207 208 irq = TAILQ_FIRST(&ed->ioconf.irqs)->irq_no; 209 210 sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT); 211 if (sc == NULL) { 212 printf("fea%ld: malloc failed!\n", ed->unit); 213 return -1; 214 } 215 pdqs_eisa[ed->unit] = sc; 216 217 bzero(sc, sizeof(pdq_softc_t)); /* Zero out the softc*/ 218 sc->sc_if.if_name = "fea"; 219 sc->sc_if.if_unit = ed->unit; 220 221 if ((iospace = ed->ioconf.ioaddrs.lh_first) == NULL) { 222 printf("fea%d: no iospace??\n", sc->sc_if.if_unit); 223 return -1; 224 } 225 if ((mspace = ed->ioconf.maddrs.lh_first) == NULL) { 226 printf("fea%d: no memory space??\n", sc->sc_if.if_unit); 227 return -1; 228 } 229 230 sc->sc_iobase = (pdq_bus_ioport_t) iospace->addr; 231 sc->sc_membase = (pdq_bus_memaddr_t) pmap_mapdev(mspace->addr, mspace->size); 232 if (sc->sc_membase == NULL) { 233 printf("fea%d: failed to map memory 0x%lx-0x%lx!\n", 234 sc->sc_if.if_unit, mspace->addr, mspace->addr + mspace->size - 1); 235 return -1; 236 } 237 238 eisa_reg_start(ed); 239 if (eisa_reg_iospace(ed, iospace)) { 240 printf("fea%d: failed to register iospace 0x%lx-0x%lx!\n", 241 sc->sc_if.if_unit, iospace->addr, iospace->addr + iospace->size - 1); 242 return -1; 243 } 244 if (eisa_reg_mspace(ed, mspace)) { 245 printf("fea%d: failed to register memory 0x%lx-0x%lx!\n", 246 sc->sc_if.if_unit, mspace->addr, mspace->addr + mspace->size - 1); 247 return -1; 248 } 249 250 if (eisa_reg_intr(ed, irq, pdq_eisa_interrupt, sc, &net_imask, 1)) { 251 printf("fea%d: interrupt registration failed\n", sc->sc_if.if_unit); 252 return -1; 253 } 254 255 eisa_reg_end(ed); 256 257 pdq_eisa_devinit(sc); 258 sc->sc_pdq = pdq_initialize(PDQ_BUS_EISA, sc->sc_membase, 259 sc->sc_if.if_name, sc->sc_if.if_unit, 260 (void *) sc, PDQ_DEFEA); 261 if (sc->sc_pdq == NULL) { 262 printf("fea%d: initialization failed\n", sc->sc_if.if_unit); 263 return -1; 264 } 265 266 if (eisa_enable_intr(ed, irq)) { 267 printf("fea%d: failed to enable interrupt\n", sc->sc_if.if_unit); 268 return -1; 269 } 270 271 bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6); 272 pdq_ifattach(sc, pdq_eisa_ifwatchdog); 273 at_shutdown(pdq_eisa_shutdown, (void *) sc, SHUTDOWN_POST_SYNC); 274 275 return 0; 276} 277 278static void 279pdq_eisa_shutdown( 280 int howto, 281 void *sc) 282{ 283 pdq_hwreset(((pdq_softc_t *)sc)->sc_pdq); 284} 285#endif /* __FreeBSD__ */ 286 287#if defined(__bsdi__) 288static int 289pdq_eisa_probe( 290 struct device *parent, 291 struct cfdata *cf, 292 void *aux) 293{ 294 struct isa_attach_args *ia = (struct isa_attach_args *) aux; 295 int slot; 296 pdq_uint32_t irq, maddr, msize; 297 298 if (isa_bustype != BUS_EISA) 299 return 0; 300 301 if ((slot = eisa_match(cf, ia)) == 0) 302 return 0; 303 ia->ia_iobase = slot << 12; 304 ia->ia_iosize = EISA_NPORT; 305 eisa_slotalloc(slot); 306 307 pdq_eisa_subprobe(PDQ_BUS_EISA, ia->ia_iobase, &maddr, &msize, &irq); 308 if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) { 309 printf("fea%d: error: desired IRQ of %d does not match device's actual IRQ (%d),\n", 310 cf->cf_unit, 311 ffs(ia->ia_irq) - 1, ffs(irq) - 1); 312 return 0; 313 } 314 if (ia->ia_irq == IRQUNK) { 315 if ((ia->ia_irq = isa_irqalloc(irq)) == 0) { 316 if ((ia->ia_irq = isa_irqalloc(IRQ9|IRQ10|IRQ11|IRQ15)) == 0) { 317 printf("fea%d: error: IRQ %d is already in use\n", cf->cf_unit, 318 ffs(irq) - 1); 319 return 0; 320 } 321 irq = PDQ_OS_IORD_8(PDQ_BUS_EISA, ia->ia_iobase, PDQ_EISA_IO_CONFIG_STAT_0) & ~3; 322 switch (ia->ia_irq) { 323 case IRQ9: irq |= 0; 324 case IRQ10: irq |= 1; 325 case IRQ11: irq |= 2; 326 case IRQ15: irq |= 3; 327 } 328 PDQ_OS_IOWR_8(PDQ_BUS_EISA, ia->ia_iobase, PDQ_EISA_IO_CONFIG_STAT_0, irq); 329 } 330 } 331 if (maddr == 0) { 332 printf("fea%d: error: memory not enabled! ECU reconfiguration required\n", 333 cf->cf_unit); 334 return 0; 335 } 336 337 /* EISA bus masters don't use host DMA channels */ 338 ia->ia_drq = DRQNONE; 339 340 ia->ia_maddr = (caddr_t) maddr; 341 ia->ia_msize = msize; 342 return 1; 343} 344 345static void 346pdq_eisa_attach( 347 struct device *parent, 348 struct device *self, 349 void *aux) 350{ 351 pdq_softc_t *sc = (pdq_softc_t *) self; 352 register struct isa_attach_args *ia = (struct isa_attach_args *) aux; 353 register struct ifnet *ifp = &sc->sc_if; 354 355 sc->sc_if.if_unit = sc->sc_dev.dv_unit; 356 sc->sc_if.if_name = "fea"; 357 sc->sc_if.if_flags = 0; 358 359 sc->sc_iobase = ia->ia_iobase; 360 361 pdq_eisa_devinit(sc); 362 sc->sc_pdq = pdq_initialize(PDQ_BUS_EISA, 363 (pdq_bus_memaddr_t) ISA_HOLE_VADDR(ia->ia_maddr), 364 sc->sc_if.if_name, sc->sc_if.if_unit, 365 (void *) sc, PDQ_DEFEA); 366 if (sc->sc_pdq == NULL) { 367 printf("fea%d: initialization failed\n", sc->sc_if.if_unit); 368 return; 369 } 370 371 bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6); 372 373 pdq_ifattach(sc, pdq_eisa_ifwatchdog); 374 375 isa_establish(&sc->sc_id, &sc->sc_dev); 376 377 sc->sc_ih.ih_fun = pdq_interrupt; 378 sc->sc_ih.ih_arg = (void *) sc->sc_pdq; 379 intr_establish(ia->ia_irq, &sc->sc_ih, DV_NET); 380 381 sc->sc_ats.func = (void (*)(void *)) pdq_hwreset; 382 sc->sc_ats.arg = (void *) sc->sc_pdq; 383 atshutdown(&sc->sc_ats, ATSH_ADD); 384} 385 386static char *pdq_eisa_ids[] = { 387 "DEC3001", /* 0x0130A310 */ 388 "DEC3002", /* 0x0230A310 */ 389 "DEC3003", /* 0x0330A310 */ 390 "DEC3004", /* 0x0430A310 */ 391}; 392 393struct cfdriver feacd = { 394 0, "fea", pdq_eisa_probe, pdq_eisa_attach, DV_IFNET, sizeof(pdq_softc_t), 395 pdq_eisa_ids 396}; 397#endif /* __bsdi__ */ 398 399#if defined(__NetBSD__) 400static int 401pdq_eisa_match( 402 struct device *parent, 403 void *match, 404 void *aux) 405{ 406 const struct eisa_attach_args * const ea = (struct eisa_attach_args *) aux; 407 408 if (strncmp(ea->ea_idstring, "DEC300", 6) == 0) 409 return 1; 410 411 return 0; 412} 413 414static void 415pdq_eisa_attach( 416 struct device *parent, 417 struct device *self, 418 void *aux) 419{ 420 pdq_softc_t * const sc = (pdq_softc_t *) self; 421 struct eisa_attach_args * const ea = (struct eisa_attach_args *) aux; 422 pdq_uint32_t irq, maddr, msize; 423 eisa_intr_handle_t ih; 424 const char *intrstr; 425 426 sc->sc_bc = ea->ea_bc; 427 bcopy(sc->sc_dev.dv_xname, sc->sc_if.if_xname, IFNAMSIZ); 428 sc->sc_if.if_flags = 0; 429 sc->sc_if.if_softc = sc; 430 431 if (bus_io_map(sc->sc_bc, EISA_SLOT_ADDR(ea->ea_slot), EISA_SLOT_SIZE, &sc->sc_iobase)) { 432 printf("\n%s: failed to map I/O!\n", sc->sc_dev.dv_xname); 433 return; 434 } 435 436 pdq_eisa_subprobe(sc->sc_bc, sc->sc_iobase, &maddr, &msize, &irq); 437 438#if !defined(PDQ_IOMAPPED) 439 if (maddr == 0 || msize == 0) { 440 printf("\n%s: error: memory not enabled! ECU reconfiguration required\n", 441 sc->sc_dev.dv_xname); 442 return; 443 } 444 445 if (bus_mem_map(sc->sc_bc, maddr, msize, 0, &sc->sc_membase)) { 446 bus_io_unmap(sc->sc_bc, sc->sc_iobase, EISA_SLOT_SIZE); 447 printf("\n%s: failed to map memory (0x%x-0x%x)!\n", 448 sc->sc_dev.dv_xname, maddr, maddr + msize - 1); 449 return; 450 } 451#endif 452 pdq_eisa_devinit(sc); 453 sc->sc_pdq = pdq_initialize(sc->sc_bc, sc->sc_membase, 454 sc->sc_if.if_xname, 0, 455 (void *) sc, PDQ_DEFEA); 456 if (sc->sc_pdq == NULL) { 457 printf("%s: initialization failed\n", sc->sc_dev.dv_xname); 458 return; 459 } 460 461 bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6); 462 463 pdq_ifattach(sc, pdq_eisa_ifwatchdog); 464 465 if (eisa_intr_map(ea->ea_ec, irq, &ih)) { 466 printf("%s: couldn't map interrupt (%d)\n", sc->sc_dev.dv_xname, irq); 467 return; 468 } 469 intrstr = eisa_intr_string(ea->ea_ec, ih); 470 sc->sc_ih = eisa_intr_establish(ea->ea_ec, ih, IST_LEVEL, IPL_NET, 471 (int (*)(void *)) pdq_interrupt, sc->sc_pdq); 472 if (sc->sc_ih == NULL) { 473 printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname); 474 if (intrstr != NULL) 475 printf(" at %s", intrstr); 476 printf("\n"); 477 return; 478 } 479 sc->sc_ats = shutdownhook_establish((void (*)(void *)) pdq_hwreset, sc->sc_pdq); 480 if (sc->sc_ats == NULL) 481 printf("%s: warning: couldn't establish shutdown hook\n", self->dv_xname); 482#if !defined(PDQ_IOMAPPED) 483 printf("%s: using iomem 0x%x-0x%x\n", sc->sc_dev.dv_xname, maddr, maddr + msize - 1); 484#endif 485 if (intrstr != NULL) 486 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr); 487} 488 489struct cfattach fea_ca = { 490 sizeof(pdq_softc_t), pdq_eisa_match, pdq_eisa_attach 491}; 492 493struct cfdriver fea_cd = { 494 0, "fea", DV_IFNET 495}; 496#endif 497#endif 498