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