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