mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
Finally import the 960801 of Matt Thomas' DEC FDDI driver. I'm
importing it onto a vendor branch first, in the hope that this will make future maintenance easier. The conflicts are (hopefully) unimportant. More commits that actually bring this into the source tree will follow. Submitted by: Matt Thomas (thomas@lkg.dec.com)
This commit is contained in:
parent
ac8fc3346d
commit
b05ee6a563
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MATT_THOMAS/; revision=21826
537
sys/dev/pdq/if_fea.c
Normal file
537
sys/dev/pdq/if_fea.c
Normal file
@ -0,0 +1,537 @@
|
||||
/*-
|
||||
* Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software withough specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: if_fea.c,v 1.7 1996/07/31 21:38:44 thomas Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* DEC PDQ FDDI Controller
|
||||
*
|
||||
* This module support the DEFEA EISA FDDI Controller.
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/malloc.h>
|
||||
#if defined(__FreeBSD__)
|
||||
#include <sys/devconf.h>
|
||||
#elif defined(__bsdi__) || defined(__NetBSD__)
|
||||
#include <sys/device.h>
|
||||
#endif
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_types.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include "bpfilter.h"
|
||||
#if NBPFILTER > 0
|
||||
#include <net/bpf.h>
|
||||
#include <net/bpfdesc.h>
|
||||
#endif
|
||||
|
||||
#ifdef INET
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <netinet/if_fddi.h>
|
||||
#else
|
||||
#include <net/if_fddi.h>
|
||||
#endif
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_kern.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <i386/eisa/eisaconf.h>
|
||||
#include <i386/isa/icu.h>
|
||||
#include <dev/pdq/pdqvar.h>
|
||||
#include <dev/pdq/pdqreg.h>
|
||||
#elif defined(__bsdi__)
|
||||
#include <i386/isa/isa.h>
|
||||
#include <i386/isa/icu.h>
|
||||
#include <i386/isa/dma.h>
|
||||
#include <i386/isa/isavar.h>
|
||||
#include <i386/eisa/eisa.h>
|
||||
#include <dev/pdq/pdqvar.h>
|
||||
#include <dev/pdq/pdqreg.h>
|
||||
#elif defined(__NetBSD__)
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <dev/ic/pdqvar.h>
|
||||
#include <dev/ic/pdqreg.h>
|
||||
|
||||
#include <dev/eisa/eisareg.h>
|
||||
#include <dev/eisa/eisavar.h>
|
||||
#include <dev/eisa/eisadevs.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define DEFEA_IRQS 0x0000FBA9U
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
static pdq_softc_t *pdqs_eisa[16];
|
||||
#define PDQ_EISA_UNIT_TO_SOFTC(unit) (pdqs_eisa[unit])
|
||||
#define DEFEA_INTRENABLE 0x8 /* level interrupt */
|
||||
#define pdq_eisa_ifwatchdog NULL
|
||||
#define DEFEA_DECODE_IRQ(n) ((DEFEA_IRQS >> ((n) << 2)) & 0x0f)
|
||||
|
||||
#elif defined(__bsdi__)
|
||||
extern struct cfdriver feacd;
|
||||
#define PDQ_EISA_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)feacd.cd_devs[unit])
|
||||
#define DEFEA_INTRENABLE 0x28 /* edge interrupt */
|
||||
static const int pdq_eisa_irqs[4] = { IRQ9, IRQ10, IRQ11, IRQ15 };
|
||||
#define DEFEA_DECODE_IRQ(n) (pdq_eisa_irqs[(n)])
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
#define DEFEA_INTRENABLE 0x8 /* level interrupt */
|
||||
#define pdq_eisa_ifwatchdog NULL
|
||||
#define DEFEA_DECODE_IRQ(n) ((DEFEA_IRQS >> ((n) << 2)) & 0x0f)
|
||||
|
||||
#else
|
||||
#error unknown system
|
||||
#endif
|
||||
|
||||
#ifndef pdq_eisa_ifwatchdog
|
||||
static ifnet_ret_t
|
||||
pdq_eisa_ifwatchdog(
|
||||
int unit)
|
||||
{
|
||||
pdq_ifwatchdog(&PDQ_EISA_UNIT_TO_SOFTC(unit)->sc_if);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
pdq_eisa_subprobe(
|
||||
pdq_bus_t bc,
|
||||
pdq_bus_ioport_t iobase,
|
||||
pdq_uint32_t *maddr,
|
||||
pdq_uint32_t *msize,
|
||||
pdq_uint32_t *irq)
|
||||
{
|
||||
if (irq != NULL)
|
||||
*irq = DEFEA_DECODE_IRQ(PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_IO_CONFIG_STAT_0) & 3);
|
||||
*maddr = (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_CMP_0) << 8)
|
||||
| (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_CMP_1) << 16);
|
||||
*msize = (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_MASK_0) + 4) << 8;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_eisa_devinit(
|
||||
pdq_softc_t *sc)
|
||||
{
|
||||
pdq_uint8_t data;
|
||||
|
||||
/*
|
||||
* Do the standard initialization for the DEFEA registers.
|
||||
*/
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_FUNCTION_CTRL, 0x23);
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CMP_1_1, (sc->sc_iobase >> 8) & 0xF0);
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CMP_0_1, (sc->sc_iobase >> 8) & 0xF0);
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_SLOT_CTRL, 0x01);
|
||||
data = PDQ_OS_IORD_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF);
|
||||
#if defined(PDQ_IOMAPPED)
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF, data & ~1);
|
||||
#else
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF, data | 1);
|
||||
#endif
|
||||
data = PDQ_OS_IORD_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CONFIG_STAT_0);
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CONFIG_STAT_0, data | DEFEA_INTRENABLE);
|
||||
}
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
static int pdq_eisa_shutdown(struct kern_devconf *kdc, int force);
|
||||
static int pdq_eisa_probe(void);
|
||||
static int pdq_eisa_attach(struct eisa_device *ed);
|
||||
|
||||
static unsigned long pdq_eisa_unit;
|
||||
|
||||
static struct eisa_driver pdq_eisa_driver = {
|
||||
"fea", pdq_eisa_probe, pdq_eisa_attach, NULL, &pdq_eisa_unit
|
||||
};
|
||||
|
||||
DATA_SET(eisadriver_set, pdq_eisa_driver);
|
||||
|
||||
static struct kern_devconf kdc_pdq_eisa = {
|
||||
0, 0, 0, /* filled in by dev_attach */
|
||||
"fea", 0, { MDDT_EISA, 0, "net" },
|
||||
eisa_generic_externalize, 0, pdq_eisa_shutdown, EISA_EXTERNALLEN,
|
||||
&kdc_eisa0, /* parent */
|
||||
0, /* parentdata */
|
||||
DC_BUSY, /* host adapters are always ``in use'' */
|
||||
"DEC DEFEA EISA FDDI Controller",
|
||||
DC_CLS_NETIF
|
||||
};
|
||||
|
||||
static const char *
|
||||
pdq_eisa_match(
|
||||
eisa_id_t type)
|
||||
{
|
||||
if ((type >> 8) == 0x10a330)
|
||||
return kdc_pdq_eisa.kdc_description;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
pdq_eisa_probe(
|
||||
void)
|
||||
{
|
||||
struct eisa_device *ed = NULL;
|
||||
int count;
|
||||
|
||||
for (count = 0; (ed = eisa_match_dev(ed, pdq_eisa_match)) != NULL; count++) {
|
||||
pdq_bus_ioport_t iobase = ed->ioconf.slot * EISA_SLOT_SIZE;
|
||||
pdq_uint32_t irq, maddr, msize;
|
||||
|
||||
eisa_add_iospace(ed, iobase, 0x200, RESVADDR_NONE);
|
||||
pdq_eisa_subprobe(PDQ_BUS_EISA, iobase, &maddr, &msize, &irq);
|
||||
eisa_add_mspace(ed, maddr, msize, RESVADDR_NONE);
|
||||
eisa_add_intr(ed, irq);
|
||||
eisa_registerdev(ed, &pdq_eisa_driver, &kdc_pdq_eisa);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_eisa_interrupt(
|
||||
void *arg)
|
||||
{
|
||||
pdq_softc_t * const sc = (pdq_softc_t *) arg;
|
||||
(void) pdq_interrupt(sc->sc_pdq);
|
||||
}
|
||||
|
||||
static int
|
||||
pdq_eisa_attach(
|
||||
struct eisa_device *ed)
|
||||
{
|
||||
pdq_softc_t *sc;
|
||||
resvaddr_t *iospace;
|
||||
resvaddr_t *mspace;
|
||||
int irq = ffs(ed->ioconf.irq) - 1;
|
||||
|
||||
sc = (pdq_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_WAITOK);
|
||||
if (sc == NULL) {
|
||||
printf("fea%d: malloc failed!\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
pdqs_eisa[ed->unit] = sc;
|
||||
|
||||
bzero(sc, sizeof(pdq_softc_t)); /* Zero out the softc*/
|
||||
sc->sc_if.if_name = "fea";
|
||||
sc->sc_if.if_unit = ed->unit;
|
||||
|
||||
if ((iospace = ed->ioconf.ioaddrs.lh_first) == NULL) {
|
||||
printf("fea%d: no iospace??\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
if ((mspace = ed->ioconf.maddrs.lh_first) == NULL) {
|
||||
printf("fea%d: no memory space??\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sc->sc_iobase = (pdq_bus_ioport_t) iospace->addr;
|
||||
sc->sc_membase = (pdq_bus_memaddr_t) pmap_mapdev(mspace->addr, mspace->size);
|
||||
if (sc->sc_membase == NULL) {
|
||||
printf("fea%d: failed to map memory 0x%x-0x%x!\n",
|
||||
sc->sc_if.if_unit, mspace->addr, mspace->addr + mspace->size - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
eisa_reg_start(ed);
|
||||
if (eisa_reg_iospace(ed, iospace)) {
|
||||
printf("fea%d: failed to register iospace 0x%x-0x%x!\n",
|
||||
sc->sc_if.if_unit, iospace->addr, iospace->addr + iospace->size - 1);
|
||||
return -1;
|
||||
}
|
||||
if (eisa_reg_mspace(ed, mspace)) {
|
||||
printf("fea%d: failed to register memory 0x%x-0x%x!\n",
|
||||
sc->sc_if.if_unit, mspace->addr, mspace->addr + mspace->size - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (eisa_reg_intr(ed, irq, pdq_eisa_interrupt, sc, &net_imask, 1)) {
|
||||
printf("fea%d: interrupt registration failed\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
|
||||
eisa_reg_end(ed);
|
||||
|
||||
pdq_eisa_devinit(sc);
|
||||
sc->sc_pdq = pdq_initialize(PDQ_BUS_EISA, sc->sc_membase,
|
||||
sc->sc_if.if_name, sc->sc_if.if_unit,
|
||||
(void *) sc, PDQ_DEFEA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("fea%d: initialization failed\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (eisa_enable_intr(ed, irq)) {
|
||||
printf("fea%d: failed to enable interrupt\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
pdq_ifattach(sc, pdq_eisa_ifwatchdog);
|
||||
|
||||
ed->kdc->kdc_state = DC_BUSY; /* host adapters always busy */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
pdq_eisa_shutdown(
|
||||
struct kern_devconf *kdc,
|
||||
int force)
|
||||
{
|
||||
pdq_hwreset(PDQ_EISA_UNIT_TO_SOFTC(kdc->kdc_unit)->sc_pdq);
|
||||
(void) dev_detach(kdc);
|
||||
return 0;
|
||||
}
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
#if defined(__bsdi__)
|
||||
static int
|
||||
pdq_eisa_probe(
|
||||
struct device *parent,
|
||||
struct cfdata *cf,
|
||||
void *aux)
|
||||
{
|
||||
struct isa_attach_args *ia = (struct isa_attach_args *) aux;
|
||||
int slot;
|
||||
pdq_uint32_t irq, maddr, msize;
|
||||
|
||||
if (isa_bustype != BUS_EISA)
|
||||
return 0;
|
||||
|
||||
if ((slot = eisa_match(cf, ia)) == 0)
|
||||
return 0;
|
||||
ia->ia_iobase = slot << 12;
|
||||
ia->ia_iosize = EISA_NPORT;
|
||||
eisa_slotalloc(slot);
|
||||
|
||||
pdq_eisa_subprobe(PDQ_BUS_EISA, ia->ia_iobase, &maddr, &msize, &irq);
|
||||
if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) {
|
||||
printf("fea%d: error: desired IRQ of %d does not match device's actual IRQ (%d),\n",
|
||||
cf->cf_unit,
|
||||
ffs(ia->ia_irq) - 1, ffs(irq) - 1);
|
||||
return 0;
|
||||
}
|
||||
if (ia->ia_irq == IRQUNK) {
|
||||
if ((ia->ia_irq = isa_irqalloc(irq)) == 0) {
|
||||
if ((ia->ia_irq = isa_irqalloc(IRQ9|IRQ10|IRQ11|IRQ15)) == 0) {
|
||||
printf("fea%d: error: IRQ %d is already in use\n", cf->cf_unit,
|
||||
ffs(irq) - 1);
|
||||
return 0;
|
||||
}
|
||||
irq = PDQ_OS_IORD_8(PDQ_BUS_EISA, ia->ia_iobase, PDQ_EISA_IO_CONFIG_STAT_0) & ~3;
|
||||
switch (ia->ia_irq) {
|
||||
case IRQ9: irq |= 0;
|
||||
case IRQ10: irq |= 1;
|
||||
case IRQ11: irq |= 2;
|
||||
case IRQ15: irq |= 3;
|
||||
}
|
||||
PDQ_OS_IOWR_8(PDQ_BUS_EISA, ia->ia_iobase, PDQ_EISA_IO_CONFIG_STAT_0, irq);
|
||||
}
|
||||
}
|
||||
if (maddr == 0) {
|
||||
printf("fea%d: error: memory not enabled! ECU reconfiguration required\n",
|
||||
cf->cf_unit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EISA bus masters don't use host DMA channels */
|
||||
ia->ia_drq = DRQNONE;
|
||||
|
||||
ia->ia_maddr = (caddr_t) maddr;
|
||||
ia->ia_msize = msize;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_eisa_attach(
|
||||
struct device *parent,
|
||||
struct device *self,
|
||||
void *aux)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) self;
|
||||
register struct isa_attach_args *ia = (struct isa_attach_args *) aux;
|
||||
register struct ifnet *ifp = &sc->sc_if;
|
||||
|
||||
sc->sc_if.if_unit = sc->sc_dev.dv_unit;
|
||||
sc->sc_if.if_name = "fea";
|
||||
sc->sc_if.if_flags = 0;
|
||||
|
||||
sc->sc_iobase = ia->ia_iobase;
|
||||
|
||||
pdq_eisa_devinit(sc);
|
||||
sc->sc_pdq = pdq_initialize(PDQ_BUS_EISA,
|
||||
(pdq_bus_memaddr_t) ISA_HOLE_VADDR(ia->ia_maddr),
|
||||
sc->sc_if.if_name, sc->sc_if.if_unit,
|
||||
(void *) sc, PDQ_DEFEA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("fea%d: initialization failed\n", sc->sc_if.if_unit);
|
||||
return;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
|
||||
pdq_ifattach(sc, pdq_eisa_ifwatchdog);
|
||||
|
||||
isa_establish(&sc->sc_id, &sc->sc_dev);
|
||||
|
||||
sc->sc_ih.ih_fun = pdq_interrupt;
|
||||
sc->sc_ih.ih_arg = (void *) sc->sc_pdq;
|
||||
intr_establish(ia->ia_irq, &sc->sc_ih, DV_NET);
|
||||
|
||||
sc->sc_ats.func = (void (*)(void *)) pdq_hwreset;
|
||||
sc->sc_ats.arg = (void *) sc->sc_pdq;
|
||||
atshutdown(&sc->sc_ats, ATSH_ADD);
|
||||
}
|
||||
|
||||
static char *pdq_eisa_ids[] = {
|
||||
"DEC3001", /* 0x0130A310 */
|
||||
"DEC3002", /* 0x0230A310 */
|
||||
"DEC3003", /* 0x0330A310 */
|
||||
"DEC3004", /* 0x0430A310 */
|
||||
};
|
||||
|
||||
struct cfdriver feacd = {
|
||||
0, "fea", pdq_eisa_probe, pdq_eisa_attach, DV_IFNET, sizeof(pdq_softc_t),
|
||||
pdq_eisa_ids
|
||||
};
|
||||
#endif /* __bsdi__ */
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
static int
|
||||
pdq_eisa_match(
|
||||
struct device *parent,
|
||||
void *match,
|
||||
void *aux)
|
||||
{
|
||||
const struct eisa_attach_args * const ea = (struct eisa_attach_args *) aux;
|
||||
|
||||
if (strncmp(ea->ea_idstring, "DEC300", 6) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_eisa_attach(
|
||||
struct device *parent,
|
||||
struct device *self,
|
||||
void *aux)
|
||||
{
|
||||
pdq_softc_t * const sc = (pdq_softc_t *) self;
|
||||
struct eisa_attach_args * const ea = (struct eisa_attach_args *) aux;
|
||||
pdq_uint32_t irq, maddr, msize;
|
||||
eisa_intr_handle_t ih;
|
||||
const char *intrstr;
|
||||
|
||||
sc->sc_bc = ea->ea_bc;
|
||||
bcopy(sc->sc_dev.dv_xname, sc->sc_if.if_xname, IFNAMSIZ);
|
||||
sc->sc_if.if_flags = 0;
|
||||
sc->sc_if.if_softc = sc;
|
||||
|
||||
if (bus_io_map(sc->sc_bc, EISA_SLOT_ADDR(ea->ea_slot), EISA_SLOT_SIZE, &sc->sc_iobase)) {
|
||||
printf("\n%s: failed to map I/O!\n", sc->sc_dev.dv_xname);
|
||||
return;
|
||||
}
|
||||
|
||||
pdq_eisa_subprobe(sc->sc_bc, sc->sc_iobase, &maddr, &msize, &irq);
|
||||
|
||||
#if !defined(PDQ_IOMAPPED)
|
||||
if (maddr == 0 || msize == 0) {
|
||||
printf("\n%s: error: memory not enabled! ECU reconfiguration required\n",
|
||||
sc->sc_dev.dv_xname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bus_mem_map(sc->sc_bc, maddr, msize, 0, &sc->sc_membase)) {
|
||||
bus_io_unmap(sc->sc_bc, sc->sc_iobase, EISA_SLOT_SIZE);
|
||||
printf("\n%s: failed to map memory (0x%x-0x%x)!\n",
|
||||
sc->sc_dev.dv_xname, maddr, maddr + msize - 1);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
pdq_eisa_devinit(sc);
|
||||
sc->sc_pdq = pdq_initialize(sc->sc_bc, sc->sc_membase,
|
||||
sc->sc_if.if_xname, 0,
|
||||
(void *) sc, PDQ_DEFEA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("%s: initialization failed\n", sc->sc_dev.dv_xname);
|
||||
return;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
|
||||
pdq_ifattach(sc, pdq_eisa_ifwatchdog);
|
||||
|
||||
if (eisa_intr_map(ea->ea_ec, irq, &ih)) {
|
||||
printf("%s: couldn't map interrupt (%d)\n", sc->sc_dev.dv_xname, irq);
|
||||
return;
|
||||
}
|
||||
intrstr = eisa_intr_string(ea->ea_ec, ih);
|
||||
sc->sc_ih = eisa_intr_establish(ea->ea_ec, ih, IST_LEVEL, IPL_NET,
|
||||
(int (*)(void *)) pdq_interrupt, sc->sc_pdq);
|
||||
if (sc->sc_ih == NULL) {
|
||||
printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
|
||||
if (intrstr != NULL)
|
||||
printf(" at %s", intrstr);
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
sc->sc_ats = shutdownhook_establish((void (*)(void *)) pdq_hwreset, sc->sc_pdq);
|
||||
if (sc->sc_ats == NULL)
|
||||
printf("%s: warning: couldn't establish shutdown hook\n", self->dv_xname);
|
||||
#if !defined(PDQ_IOMAPPED)
|
||||
printf("%s: using iomem 0x%x-0x%x\n", sc->sc_dev.dv_xname, maddr, maddr + msize - 1);
|
||||
#endif
|
||||
if (intrstr != NULL)
|
||||
printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
|
||||
}
|
||||
|
||||
struct cfattach fea_ca = {
|
||||
sizeof(pdq_softc_t), pdq_eisa_match, pdq_eisa_attach
|
||||
};
|
||||
|
||||
struct cfdriver fea_cd = {
|
||||
0, "fea", DV_IFNET
|
||||
};
|
||||
#endif
|
472
sys/dev/pdq/if_fpa.c
Normal file
472
sys/dev/pdq/if_fpa.c
Normal file
@ -0,0 +1,472 @@
|
||||
/*-
|
||||
* Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software withough specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: if_fpa.c,v 1.9 1996/07/31 21:38:44 thomas Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* DEC PDQ FDDI Controller; code for BSD derived operating systems
|
||||
*
|
||||
* This module supports the DEC DEFPA PCI FDDI Controller
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/malloc.h>
|
||||
#if defined(__FreeBSD__)
|
||||
#include <sys/devconf.h>
|
||||
#elif defined(__bsdi__) || defined(__NetBSD__)
|
||||
#include <sys/device.h>
|
||||
#endif
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_types.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include "bpfilter.h"
|
||||
#if NBPFILTER > 0
|
||||
#include <net/bpf.h>
|
||||
#include <net/bpfdesc.h>
|
||||
#endif
|
||||
|
||||
#ifdef INET
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#endif
|
||||
#if defined(__FreeBSD__)
|
||||
#include <netinet/if_fddi.h>
|
||||
#else
|
||||
#include <net/if_fddi.h>
|
||||
#endif
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_kern.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include "fpa.h"
|
||||
#include <pci/pcivar.h>
|
||||
#include <i386/isa/icu.h>
|
||||
#include <dev/pdq/pdqvar.h>
|
||||
#include <dev/pdq/pdqreg.h>
|
||||
#elif defined(__bsdi__)
|
||||
#include <i386/isa/isavar.h>
|
||||
#include <i386/isa/icu.h>
|
||||
#ifndef DRQNONE
|
||||
#define DRQNONE 0
|
||||
#endif
|
||||
#if _BSDI_VERSION < 199401
|
||||
#define IRQSHARE 0
|
||||
#endif
|
||||
#include <i386/pci/pci.h>
|
||||
#include <dev/pdq/pdqvar.h>
|
||||
#include <dev/pdq/pdqreg.h>
|
||||
#elif defined(__NetBSD__)
|
||||
#include <dev/pci/pcivar.h>
|
||||
#include <dev/ic/pdqvar.h>
|
||||
#include <dev/ic/pdqreg.h>
|
||||
#endif /* __NetBSD__ */
|
||||
|
||||
|
||||
#define DEC_VENDORID 0x1011
|
||||
#define DEFPA_CHIPID 0x000F
|
||||
#define PCI_VENDORID(x) ((x) & 0xFFFF)
|
||||
#define PCI_CHIPID(x) (((x) >> 16) & 0xFFFF)
|
||||
|
||||
#define DEFPA_LATENCY 0x88
|
||||
|
||||
#define PCI_CFLT 0x0C /* Configuration Latency */
|
||||
#define PCI_CBMA 0x10 /* Configuration Base Memory Address */
|
||||
#define PCI_CBIO 0x14 /* Configuration Base I/O Address */
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#if NFPA < 4
|
||||
#undef NFPA
|
||||
#define NFPA 4
|
||||
#endif
|
||||
static pdq_softc_t *pdqs_pci[NFPA];
|
||||
#define PDQ_PCI_UNIT_TO_SOFTC(unit) (pdqs_pci[unit])
|
||||
#if BSD >= 199506
|
||||
#define pdq_pci_ifwatchdog NULL
|
||||
#endif
|
||||
|
||||
#elif defined(__bsdi__)
|
||||
extern struct cfdriver fpacd;
|
||||
#define PDQ_PCI_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)fpacd.cd_devs[unit])
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
extern struct cfattach fpa_ca;
|
||||
extern struct cfdriver fpa_cd;
|
||||
#define PDQ_PCI_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)fpa_cd.cd_devs[unit])
|
||||
#define pdq_pci_ifwatchdog NULL
|
||||
#endif
|
||||
|
||||
#ifndef pdq_pci_ifwatchdog
|
||||
static ifnet_ret_t
|
||||
pdq_pci_ifwatchdog(
|
||||
int unit)
|
||||
{
|
||||
pdq_ifwatchdog(&PDQ_PCI_UNIT_TO_SOFTC(unit)->sc_if);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__) && BSD >= 199506
|
||||
static void
|
||||
pdq_pci_ifintr(
|
||||
void *arg)
|
||||
{
|
||||
(void) pdq_interrupt(((pdq_softc_t *) arg)->sc_pdq);
|
||||
}
|
||||
#else
|
||||
static int
|
||||
pdq_pci_ifintr(
|
||||
void *arg)
|
||||
{
|
||||
pdq_softc_t * const sc = (pdq_softc_t *) arg;
|
||||
#ifdef __FreeBSD__
|
||||
return pdq_interrupt(sc->sc_pdq);
|
||||
#elif defined(__bsdi__) || defined(__NetBSD__)
|
||||
(void) pdq_interrupt(sc->sc_pdq);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
#endif /* __FreeBSD && BSD */
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
/*
|
||||
* This is the PCI configuration support. Since the PDQ is available
|
||||
* on both EISA and PCI boards, one must be careful in how defines the
|
||||
* PDQ in the config file.
|
||||
*/
|
||||
static char *
|
||||
pdq_pci_probe(
|
||||
pcici_t config_id,
|
||||
pcidi_t device_id)
|
||||
{
|
||||
if (PCI_VENDORID(device_id) == DEC_VENDORID &&
|
||||
PCI_CHIPID(device_id) == DEFPA_CHIPID)
|
||||
return "Digital DEFPA PCI FDDI Controller";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_pci_attach(
|
||||
pcici_t config_id,
|
||||
int unit)
|
||||
{
|
||||
pdq_softc_t *sc;
|
||||
vm_offset_t va_csrs, pa_csrs;
|
||||
pdq_uint32_t data;
|
||||
|
||||
if (unit == NFPA) {
|
||||
printf("fpa%d: not configured; kernel is built for only %d device%s.\n",
|
||||
unit, NFPA, NFPA == 1 ? "" : "s");
|
||||
return;
|
||||
}
|
||||
|
||||
data = pci_conf_read(config_id, PCI_CFLT);
|
||||
if ((data & 0xFF00) < (DEFPA_LATENCY << 8)) {
|
||||
data &= ~0xFF00;
|
||||
data |= DEFPA_LATENCY << 8;
|
||||
pci_conf_write(config_id, PCI_CFLT, data);
|
||||
}
|
||||
|
||||
sc = (pdq_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT);
|
||||
if (sc == NULL)
|
||||
return;
|
||||
|
||||
bzero(sc, sizeof(pdq_softc_t)); /* Zero out the softc*/
|
||||
if (!pci_map_mem(config_id, PCI_CBMA, &va_csrs, &pa_csrs)) {
|
||||
free((void *) sc, M_DEVBUF);
|
||||
return;
|
||||
}
|
||||
|
||||
sc->sc_if.if_name = "fpa";
|
||||
sc->sc_if.if_unit = unit;
|
||||
sc->sc_membase = (pdq_bus_memaddr_t) va_csrs;
|
||||
sc->sc_pdq = pdq_initialize(PDQ_BUS_PCI, sc->sc_membase,
|
||||
sc->sc_if.if_name, sc->sc_if.if_unit,
|
||||
(void *) sc, PDQ_DEFPA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
free((void *) sc, M_DEVBUF);
|
||||
return;
|
||||
}
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
pdqs_pci[unit] = sc;
|
||||
pdq_ifattach(sc, pdq_pci_ifwatchdog);
|
||||
pci_map_int(config_id, pdq_pci_ifintr, (void*) sc, &net_imask);
|
||||
}
|
||||
|
||||
static int
|
||||
pdq_pci_shutdown(
|
||||
struct kern_devconf *kdc,
|
||||
int force)
|
||||
{
|
||||
if (kdc->kdc_unit < NFPA)
|
||||
pdq_hwreset(PDQ_PCI_UNIT_TO_SOFTC(kdc->kdc_unit)->sc_pdq);
|
||||
(void) dev_detach(kdc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u_long pdq_pci_count;
|
||||
|
||||
struct pci_device fpadevice = {
|
||||
"fpa",
|
||||
pdq_pci_probe,
|
||||
pdq_pci_attach,
|
||||
&pdq_pci_count,
|
||||
pdq_pci_shutdown,
|
||||
};
|
||||
|
||||
#ifdef DATA_SET
|
||||
DATA_SET (pcidevice_set, fpadevice);
|
||||
#endif
|
||||
#elif defined(__bsdi__)
|
||||
|
||||
static int
|
||||
pdq_pci_match(
|
||||
pci_devaddr_t *pa)
|
||||
{
|
||||
int irq;
|
||||
int id;
|
||||
|
||||
id = pci_inl(pa, PCI_VENDOR_ID);
|
||||
if (PCI_VENDORID(id) != DEC_VENDORID || PCI_CHIPID(id) != DEFPA_CHIPID)
|
||||
return 0;
|
||||
|
||||
irq = pci_inl(pa, PCI_I_LINE) & 0xFF;
|
||||
if (irq == 0 || irq >= 16)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
pdq_pci_probe(
|
||||
struct device *parent,
|
||||
struct cfdata *cf,
|
||||
void *aux)
|
||||
{
|
||||
struct isa_attach_args *ia = (struct isa_attach_args *) aux;
|
||||
pdq_uint32_t irq, data;
|
||||
pci_devaddr_t *pa;
|
||||
|
||||
pa = pci_scan(pdq_pci_match);
|
||||
if (pa == NULL)
|
||||
return 0;
|
||||
|
||||
irq = (1 << (pci_inl(pa, PCI_I_LINE) & 0xFF));
|
||||
|
||||
if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) {
|
||||
printf("fpa%d: error: desired IRQ of %d does not match device's actual IRQ of %d\n",
|
||||
cf->cf_unit,
|
||||
ffs(ia->ia_irq) - 1, ffs(irq) - 1);
|
||||
return 0;
|
||||
}
|
||||
if (ia->ia_irq == IRQUNK) {
|
||||
(void) isa_irqalloc(irq);
|
||||
ia->ia_irq = irq;
|
||||
}
|
||||
|
||||
/* PCI bus masters don't use host DMA channels */
|
||||
ia->ia_drq = DRQNONE;
|
||||
|
||||
/* Get the memory base address; assume the BIOS set it up correctly */
|
||||
ia->ia_maddr = (caddr_t) (pci_inl(pa, PCI_CBMA) & ~7);
|
||||
pci_outl(pa, PCI_CBMA, 0xFFFFFFFF);
|
||||
ia->ia_msize = ((~pci_inl(pa, PCI_CBMA)) | 7) + 1;
|
||||
pci_outl(pa, PCI_CBMA, (int) ia->ia_maddr);
|
||||
|
||||
/* Disable I/O space access */
|
||||
pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~1);
|
||||
ia->ia_iobase = 0;
|
||||
ia->ia_iosize = 0;
|
||||
|
||||
/* Make sure the latency timer is what the DEFPA likes */
|
||||
data = pci_inl(pa, PCI_CFLT);
|
||||
if ((data & 0xFF00) < (DEFPA_LATENCY << 8)) {
|
||||
data &= ~0xFF00;
|
||||
data |= DEFPA_LATENCY << 8;
|
||||
pci_outl(pa, PCI_CFLT, data);
|
||||
}
|
||||
ia->ia_irq |= IRQSHARE;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
pdq_pci_attach(
|
||||
struct device *parent,
|
||||
struct device *self,
|
||||
void *aux)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) self;
|
||||
register struct isa_attach_args *ia = (struct isa_attach_args *) aux;
|
||||
register struct ifnet *ifp = &sc->sc_if;
|
||||
int i;
|
||||
|
||||
sc->sc_if.if_unit = sc->sc_dev.dv_unit;
|
||||
sc->sc_if.if_name = "fpa";
|
||||
sc->sc_if.if_flags = 0;
|
||||
sc->sc_membase = (pdq_bus_memaddr_t) mapphys((vm_offset_t)ia->ia_maddr, ia->ia_msize);
|
||||
|
||||
sc->sc_pdq = pdq_initialize(PDQ_BUS_PCI, sc->sc_membase,
|
||||
sc->sc_if.if_name, sc->sc_if.if_unit,
|
||||
(void *) sc, PDQ_DEFPA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("fpa%d: initialization failed\n", sc->sc_if.if_unit);
|
||||
return;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
|
||||
pdq_ifattach(sc, pdq_pci_ifwatchdog);
|
||||
|
||||
isa_establish(&sc->sc_id, &sc->sc_dev);
|
||||
|
||||
sc->sc_ih.ih_fun = pdq_pci_ifintr;
|
||||
sc->sc_ih.ih_arg = (void *)sc;
|
||||
intr_establish(ia->ia_irq, &sc->sc_ih, DV_NET);
|
||||
|
||||
sc->sc_ats.func = (void (*)(void *)) pdq_hwreset;
|
||||
sc->sc_ats.arg = (void *) sc->sc_pdq;
|
||||
atshutdown(&sc->sc_ats, ATSH_ADD);
|
||||
}
|
||||
|
||||
struct cfdriver fpacd = {
|
||||
0, "fpa", pdq_pci_probe, pdq_pci_attach,
|
||||
#if _BSDI_VERSION >= 199401
|
||||
DV_IFNET,
|
||||
#endif
|
||||
sizeof(pdq_softc_t)
|
||||
};
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
|
||||
static int
|
||||
pdq_pci_match(
|
||||
struct device *parent,
|
||||
void *match,
|
||||
void *aux)
|
||||
{
|
||||
struct pci_attach_args *pa = (struct pci_attach_args *) aux;
|
||||
|
||||
if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID)
|
||||
return 0;
|
||||
if (PCI_CHIPID(pa->pa_id) == DEFPA_CHIPID)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_pci_attach(
|
||||
struct device * const parent,
|
||||
struct device * const self,
|
||||
void * const aux)
|
||||
{
|
||||
pdq_softc_t * const sc = (pdq_softc_t *) self;
|
||||
struct pci_attach_args * const pa = (struct pci_attach_args *) aux;
|
||||
pdq_uint32_t data;
|
||||
pci_intr_handle_t intrhandle;
|
||||
const char *intrstr;
|
||||
#ifdef PDQ_IOMAPPED
|
||||
bus_io_addr_t iobase;
|
||||
bus_io_size_t iosize;
|
||||
#else
|
||||
bus_mem_addr_t membase;
|
||||
bus_mem_size_t memsize;
|
||||
#endif
|
||||
|
||||
data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CFLT);
|
||||
if ((data & 0xFF00) < (DEFPA_LATENCY << 8)) {
|
||||
data &= ~0xFF00;
|
||||
data |= DEFPA_LATENCY << 8;
|
||||
pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_CFLT, data);
|
||||
}
|
||||
|
||||
sc->sc_bc = pa->pa_bc;
|
||||
bcopy(sc->sc_dev.dv_xname, sc->sc_if.if_xname, IFNAMSIZ);
|
||||
sc->sc_if.if_flags = 0;
|
||||
sc->sc_if.if_softc = sc;
|
||||
|
||||
#ifdef PDQ_IOMAPPED
|
||||
if (pci_io_find(pa->pa_pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize)
|
||||
|| bus_io_map(pa->pa_bc, iobase, iosize, &sc->sc_iobase))
|
||||
return;
|
||||
#else
|
||||
if (pci_mem_find(pa->pa_pc, pa->pa_tag, PCI_CBMA, &membase, &memsize, NULL)
|
||||
|| bus_mem_map(pa->pa_bc, membase, memsize, 0, &sc->sc_membase))
|
||||
return;
|
||||
#endif
|
||||
|
||||
sc->sc_pdq = pdq_initialize(sc->sc_bc, sc->sc_membase,
|
||||
sc->sc_if.if_xname, 0,
|
||||
(void *) sc, PDQ_DEFPA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("%s: initialization failed\n", sc->sc_dev.dv_xname);
|
||||
return;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
pdq_ifattach(sc, pdq_pci_ifwatchdog);
|
||||
|
||||
if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
|
||||
pa->pa_intrline, &intrhandle)) {
|
||||
printf("%s: couldn't map interrupt\n", self->dv_xname);
|
||||
return;
|
||||
}
|
||||
intrstr = pci_intr_string(pa->pa_pc, intrhandle);
|
||||
sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_NET, pdq_pci_ifintr, sc);
|
||||
if (sc->sc_ih == NULL) {
|
||||
printf("%s: couldn't establish interrupt", self->dv_xname);
|
||||
if (intrstr != NULL)
|
||||
printf(" at %s", intrstr);
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sc->sc_ats = shutdownhook_establish((void (*)(void *)) pdq_hwreset, sc->sc_pdq);
|
||||
if (sc->sc_ats == NULL)
|
||||
printf("%s: warning: couldn't establish shutdown hook\n", self->dv_xname);
|
||||
if (intrstr != NULL)
|
||||
printf("%s: interrupting at %s\n", self->dv_xname, intrstr);
|
||||
}
|
||||
|
||||
struct cfattach fpa_ca = {
|
||||
sizeof(pdq_softc_t), pdq_pci_match, pdq_pci_attach
|
||||
};
|
||||
|
||||
struct cfdriver fpa_cd = {
|
||||
0, "fpa", DV_IFNET
|
||||
};
|
||||
|
||||
#endif /* __NetBSD__ */
|
1584
sys/dev/pdq/pdq.c
Normal file
1584
sys/dev/pdq/pdq.c
Normal file
File diff suppressed because it is too large
Load Diff
404
sys/dev/pdq/pdq_ifsubr.c
Normal file
404
sys/dev/pdq/pdq_ifsubr.c
Normal file
@ -0,0 +1,404 @@
|
||||
/*-
|
||||
* Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software withough specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: pdq_ifsubr.c,v 1.8 1996/07/31 21:38:44 thomas Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* DEC PDQ FDDI Controller; code for BSD derived operating systems
|
||||
*
|
||||
* This module provide bus independent BSD specific O/S functions.
|
||||
* (ie. it provides an ifnet interface to the rest of the system)
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/malloc.h>
|
||||
#if defined(__FreeBSD__)
|
||||
#include <sys/devconf.h>
|
||||
#elif defined(__bsdi__) || defined(__NetBSD__)
|
||||
#include <sys/device.h>
|
||||
#endif
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_types.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include "bpfilter.h"
|
||||
#if NBPFILTER > 0
|
||||
#include <net/bpf.h>
|
||||
#include <net/bpfdesc.h>
|
||||
#endif
|
||||
|
||||
#ifdef INET
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#endif
|
||||
#if defined(__FreeBSD__)
|
||||
#include <netinet/if_fddi.h>
|
||||
#else
|
||||
#include <net/if_fddi.h>
|
||||
#endif
|
||||
|
||||
#if defined(__bsdi__)
|
||||
#include <i386/isa/isavar.h>
|
||||
#endif
|
||||
|
||||
#ifdef NS
|
||||
#include <netns/ns.h>
|
||||
#include <netns/ns_if.h>
|
||||
#endif
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_kern.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#include "pdqvar.h"
|
||||
#include "pdqreg.h"
|
||||
|
||||
#if defined(__bsdi__) && _BSDI_VERSION < 199506 /* XXX */
|
||||
static void
|
||||
arp_ifinit(
|
||||
struct arpcom *ac,
|
||||
struct ifaddr *ifa)
|
||||
{
|
||||
sc->sc_ac.ac_ipaddr = IA_SIN(ifa)->sin_addr;
|
||||
arpwhohas(&sc->sc_ac, &IA_SIN(ifa)->sin_addr);
|
||||
#if _BSDI_VERSION >= 199401
|
||||
ifa->ifa_rtrequest = arp_rtrequest;
|
||||
ifa->ifa_flags |= RTF_CLONING;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
pdq_ifinit(
|
||||
pdq_softc_t *sc)
|
||||
{
|
||||
if (sc->sc_if.if_flags & IFF_UP) {
|
||||
sc->sc_if.if_flags |= IFF_RUNNING;
|
||||
if (sc->sc_if.if_flags & IFF_PROMISC) {
|
||||
sc->sc_pdq->pdq_flags |= PDQ_PROMISC;
|
||||
} else {
|
||||
sc->sc_pdq->pdq_flags &= ~PDQ_PROMISC;
|
||||
}
|
||||
if (sc->sc_if.if_flags & IFF_ALLMULTI) {
|
||||
sc->sc_pdq->pdq_flags |= PDQ_ALLMULTI;
|
||||
} else {
|
||||
sc->sc_pdq->pdq_flags &= ~PDQ_ALLMULTI;
|
||||
}
|
||||
if (sc->sc_if.if_flags & IFF_LINK1) {
|
||||
sc->sc_pdq->pdq_flags |= PDQ_PASS_SMT;
|
||||
} else {
|
||||
sc->sc_pdq->pdq_flags &= ~PDQ_PASS_SMT;
|
||||
}
|
||||
sc->sc_pdq->pdq_flags |= PDQ_RUNNING;
|
||||
pdq_run(sc->sc_pdq);
|
||||
} else {
|
||||
sc->sc_if.if_flags &= ~IFF_RUNNING;
|
||||
sc->sc_pdq->pdq_flags &= ~PDQ_RUNNING;
|
||||
pdq_stop(sc->sc_pdq);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pdq_ifwatchdog(
|
||||
struct ifnet *ifp)
|
||||
{
|
||||
/*
|
||||
* No progress was made on the transmit queue for PDQ_OS_TX_TRANSMIT
|
||||
* seconds. Remove all queued packets.
|
||||
*/
|
||||
|
||||
ifp->if_flags &= ~IFF_OACTIVE;
|
||||
ifp->if_timer = 0;
|
||||
for (;;) {
|
||||
struct mbuf *m;
|
||||
IF_DEQUEUE(&ifp->if_snd, m);
|
||||
if (m == NULL)
|
||||
return;
|
||||
m_freem(m);
|
||||
}
|
||||
}
|
||||
|
||||
ifnet_ret_t
|
||||
pdq_ifstart(
|
||||
struct ifnet *ifp)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) ((caddr_t) ifp - offsetof(pdq_softc_t, sc_ac.ac_if));
|
||||
struct ifqueue *ifq = &ifp->if_snd;
|
||||
struct mbuf *m;
|
||||
int tx = 0;
|
||||
|
||||
if ((ifp->if_flags & IFF_RUNNING) == 0)
|
||||
return;
|
||||
|
||||
if (sc->sc_if.if_timer == 0)
|
||||
sc->sc_if.if_timer = PDQ_OS_TX_TIMEOUT;
|
||||
|
||||
if ((sc->sc_pdq->pdq_flags & PDQ_TXOK) == 0) {
|
||||
sc->sc_if.if_flags |= IFF_OACTIVE;
|
||||
return;
|
||||
}
|
||||
for (;; tx = 1) {
|
||||
IF_DEQUEUE(ifq, m);
|
||||
if (m == NULL)
|
||||
break;
|
||||
|
||||
if (pdq_queue_transmit_data(sc->sc_pdq, m) == PDQ_FALSE) {
|
||||
ifp->if_flags |= IFF_OACTIVE;
|
||||
IF_PREPEND(ifq, m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tx)
|
||||
PDQ_DO_TYPE2_PRODUCER(sc->sc_pdq);
|
||||
}
|
||||
|
||||
void
|
||||
pdq_os_receive_pdu(
|
||||
pdq_t *pdq,
|
||||
struct mbuf *m,
|
||||
size_t pktlen)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
|
||||
struct fddi_header *fh = mtod(m, struct fddi_header *);
|
||||
|
||||
sc->sc_if.if_ipackets++;
|
||||
#if NBPFILTER > 0
|
||||
if (sc->sc_bpf != NULL)
|
||||
PDQ_BPF_MTAP(sc, m);
|
||||
if ((fh->fddi_fc & (FDDIFC_L|FDDIFC_F)) != FDDIFC_LLC_ASYNC) {
|
||||
m_freem(m);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m->m_data += sizeof(struct fddi_header);
|
||||
m->m_len -= sizeof(struct fddi_header);
|
||||
m->m_pkthdr.len = pktlen - sizeof(struct fddi_header);
|
||||
m->m_pkthdr.rcvif = &sc->sc_if;
|
||||
fddi_input(&sc->sc_if, fh, m);
|
||||
}
|
||||
|
||||
void
|
||||
pdq_os_restart_transmitter(
|
||||
pdq_t *pdq)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
|
||||
sc->sc_if.if_flags &= ~IFF_OACTIVE;
|
||||
if (sc->sc_if.if_snd.ifq_head != NULL) {
|
||||
sc->sc_if.if_timer = PDQ_OS_TX_TIMEOUT;
|
||||
pdq_ifstart(&sc->sc_if);
|
||||
} else {
|
||||
sc->sc_if.if_timer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pdq_os_transmit_done(
|
||||
pdq_t *pdq,
|
||||
struct mbuf *m)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
|
||||
#if NBPFILTER > 0
|
||||
if (sc->sc_bpf != NULL)
|
||||
PDQ_BPF_MTAP(sc, m);
|
||||
#endif
|
||||
m_freem(m);
|
||||
sc->sc_if.if_opackets++;
|
||||
}
|
||||
|
||||
void
|
||||
pdq_os_addr_fill(
|
||||
pdq_t *pdq,
|
||||
pdq_lanaddr_t *addr,
|
||||
size_t num_addrs)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
|
||||
struct ether_multistep step;
|
||||
struct ether_multi *enm;
|
||||
|
||||
ETHER_FIRST_MULTI(step, &sc->sc_ac, enm);
|
||||
while (enm != NULL && num_addrs > 0) {
|
||||
((u_short *) addr->lanaddr_bytes)[0] = ((u_short *) enm->enm_addrlo)[0];
|
||||
((u_short *) addr->lanaddr_bytes)[1] = ((u_short *) enm->enm_addrlo)[1];
|
||||
((u_short *) addr->lanaddr_bytes)[2] = ((u_short *) enm->enm_addrlo)[2];
|
||||
ETHER_NEXT_MULTI(step, enm);
|
||||
addr++;
|
||||
num_addrs--;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
pdq_ifioctl(
|
||||
struct ifnet *ifp,
|
||||
ioctl_cmd_t cmd,
|
||||
caddr_t data)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) ((caddr_t) ifp - offsetof(pdq_softc_t, sc_ac.ac_if));
|
||||
int s, error = 0;
|
||||
|
||||
s = splimp();
|
||||
|
||||
switch (cmd) {
|
||||
case SIOCSIFADDR: {
|
||||
struct ifaddr *ifa = (struct ifaddr *)data;
|
||||
|
||||
ifp->if_flags |= IFF_UP;
|
||||
switch(ifa->ifa_addr->sa_family) {
|
||||
#if defined(INET)
|
||||
case AF_INET: {
|
||||
pdq_ifinit(sc);
|
||||
arp_ifinit(&sc->sc_ac, ifa);
|
||||
break;
|
||||
}
|
||||
#endif /* INET */
|
||||
|
||||
#if defined(NS)
|
||||
/* This magic copied from if_is.c; I don't use XNS,
|
||||
* so I have no way of telling if this actually
|
||||
* works or not.
|
||||
*/
|
||||
case AF_NS: {
|
||||
struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
|
||||
if (ns_nullhost(*ina)) {
|
||||
ina->x_host = *(union ns_host *)(sc->sc_ac.ac_enaddr);
|
||||
} else {
|
||||
ifp->if_flags &= ~IFF_RUNNING;
|
||||
bcopy((caddr_t)ina->x_host.c_host,
|
||||
(caddr_t)sc->sc_ac.ac_enaddr,
|
||||
sizeof sc->sc_ac.ac_enaddr);
|
||||
}
|
||||
|
||||
pdq_ifinit(sc);
|
||||
break;
|
||||
}
|
||||
#endif /* NS */
|
||||
|
||||
default: {
|
||||
pdq_ifinit(sc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SIOCGIFADDR: {
|
||||
struct ifreq *ifr = (struct ifreq *)data;
|
||||
bcopy((caddr_t) sc->sc_ac.ac_enaddr,
|
||||
(caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
|
||||
6);
|
||||
break;
|
||||
}
|
||||
|
||||
case SIOCSIFFLAGS: {
|
||||
pdq_ifinit(sc);
|
||||
break;
|
||||
}
|
||||
|
||||
case SIOCADDMULTI:
|
||||
case SIOCDELMULTI: {
|
||||
/*
|
||||
* Update multicast listeners
|
||||
*/
|
||||
if (cmd == SIOCADDMULTI)
|
||||
error = ether_addmulti((struct ifreq *)data, &sc->sc_ac);
|
||||
else
|
||||
error = ether_delmulti((struct ifreq *)data, &sc->sc_ac);
|
||||
|
||||
if (error == ENETRESET) {
|
||||
if (sc->sc_if.if_flags & IFF_RUNNING)
|
||||
pdq_run(sc->sc_pdq);
|
||||
error = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(SIOCSIFMTU)
|
||||
#if !defined(ifr_mtu)
|
||||
#define ifr_mtu ifr_metric
|
||||
#endif
|
||||
case SIOCSIFMTU: {
|
||||
struct ifreq *ifr = (struct ifreq *)data;
|
||||
/*
|
||||
* Set the interface MTU.
|
||||
*/
|
||||
if (ifr->ifr_mtu > FDDIMTU) {
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
ifp->if_mtu = ifr->ifr_mtu;
|
||||
break;
|
||||
}
|
||||
#endif /* SIOCSIFMTU */
|
||||
|
||||
default: {
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
splx(s);
|
||||
return error;
|
||||
}
|
||||
|
||||
#ifndef IFF_NOTRAILERS
|
||||
#define IFF_NOTRAILERS 0
|
||||
#endif
|
||||
|
||||
void
|
||||
pdq_ifattach(
|
||||
pdq_softc_t *sc,
|
||||
ifnet_ret_t (*ifwatchdog)(int unit))
|
||||
{
|
||||
struct ifnet *ifp = &sc->sc_if;
|
||||
|
||||
ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST;
|
||||
|
||||
#if (defined(__FreeBSD__) && BSD >= 199506) || defined(__NetBSD__)
|
||||
ifp->if_watchdog = pdq_ifwatchdog;
|
||||
#else
|
||||
ifp->if_watchdog = ifwatchdog;
|
||||
#endif
|
||||
|
||||
ifp->if_ioctl = pdq_ifioctl;
|
||||
ifp->if_output = fddi_output;
|
||||
ifp->if_start = pdq_ifstart;
|
||||
|
||||
if_attach(ifp);
|
||||
fddi_ifattach(ifp);
|
||||
#if NBPFILTER > 0
|
||||
PDQ_BPFATTACH(sc, DLT_FDDI, sizeof(struct fddi_header));
|
||||
#endif
|
||||
}
|
1065
sys/dev/pdq/pdqreg.h
Normal file
1065
sys/dev/pdq/pdqreg.h
Normal file
File diff suppressed because it is too large
Load Diff
351
sys/dev/pdq/pdqvar.h
Normal file
351
sys/dev/pdq/pdqvar.h
Normal file
@ -0,0 +1,351 @@
|
||||
/*-
|
||||
* Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software withough specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: pdqvar.h,v 1.19 1996/07/31 21:38:44 thomas Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* DEC PDQ FDDI Controller; PDQ O/S dependent definitions
|
||||
*
|
||||
* Written by Matt Thomas
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _PDQ_OS_H
|
||||
#define _PDQ_OS_H
|
||||
|
||||
#define PDQ_OS_TX_TIMEOUT 5 /* seconds */
|
||||
|
||||
typedef struct _pdq_t pdq_t;
|
||||
typedef struct _pdq_csrs_t pdq_csrs_t;
|
||||
typedef struct _pdq_pci_csrs_t pdq_pci_csrs_t;
|
||||
typedef struct _pdq_lanaddr_t pdq_lanaddr_t;
|
||||
typedef unsigned int pdq_uint32_t;
|
||||
typedef unsigned short pdq_uint16_t;
|
||||
typedef unsigned char pdq_uint8_t;
|
||||
typedef enum _pdq_boolean_t pdq_boolean_t;
|
||||
typedef enum _pdq_type_t pdq_type_t;
|
||||
typedef enum _pdq_state_t pdq_state_t;
|
||||
|
||||
enum _pdq_type_t {
|
||||
PDQ_DEFPA, /* PCI-bus */
|
||||
PDQ_DEFEA, /* EISA-bus */
|
||||
PDQ_DEFTA, /* TurboChannel */
|
||||
PDQ_DEFAA, /* FutureBus+ */
|
||||
PDQ_DEFQA /* Q-bus */
|
||||
};
|
||||
|
||||
#if defined(PDQTEST)
|
||||
#include <pdq_os_test.h>
|
||||
#elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__NetBSD__)
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#ifndef M_MCAST
|
||||
#include <sys/mbuf.h>
|
||||
#endif /* M_CAST */
|
||||
#include <sys/malloc.h>
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_kern.h>
|
||||
|
||||
#define PDQ_USE_MBUFS
|
||||
#if defined(__NetBSD__)
|
||||
#define PDQ_OS_PREFIX "%s: "
|
||||
#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name
|
||||
#else
|
||||
#define PDQ_OS_PREFIX "%s%d: "
|
||||
#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name, pdq->pdq_unit
|
||||
#endif
|
||||
#if defined(__FreeBSD__) && BSD >= 199506
|
||||
#define PDQ_OS_PAGESIZE PAGE_SIZE
|
||||
#else
|
||||
#define PDQ_OS_PAGESIZE NBPG
|
||||
#endif
|
||||
#define PDQ_OS_USEC_DELAY(n) DELAY(n)
|
||||
#define PDQ_OS_MEMZERO(p, n) bzero((caddr_t)(p), (n))
|
||||
#if defined(__NetBSD__) && defined(__alpha__)
|
||||
#define PDQ_OS_VA_TO_PA(pdq, p) (vtophys((vm_offset_t)p) | (pdq->pdq_type == PDQ_DEFTA ? 0 : 0x40000000))
|
||||
#else
|
||||
#define PDQ_OS_VA_TO_PA(pdq, p) vtophys(p)
|
||||
#endif
|
||||
#define PDQ_OS_MEMALLOC(n) malloc(n, M_DEVBUF, M_NOWAIT)
|
||||
#define PDQ_OS_MEMFREE(p, n) free((void *) p, M_DEVBUF)
|
||||
#ifdef __FreeBSD__
|
||||
#define PDQ_OS_MEMALLOC_CONTIG(n) vm_page_alloc_contig(n, 0, 0xffffffff, PAGE_SIZE)
|
||||
#define PDQ_OS_MEMFREE_CONTIG(p, n) kmem_free(kernel_map, (vm_offset_t) p, n)
|
||||
#else
|
||||
#define PDQ_OS_MEMALLOC_CONTIG(n) kmem_alloc(kernel_map, round_page(n))
|
||||
#define PDQ_OS_MEMFREE_CONTIG(p, n) kmem_free(kernel_map, (vm_offset_t) p, n)
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <vm/pmap.h>
|
||||
#include <vm/vm_extern.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#include <machine/clock.h>
|
||||
typedef void ifnet_ret_t;
|
||||
typedef int ioctl_cmd_t;
|
||||
typedef enum { PDQ_BUS_EISA, PDQ_BUS_PCI } pdq_bus_t;
|
||||
typedef u_int16_t pdq_bus_ioport_t;
|
||||
typedef volatile pdq_uint32_t *pdq_bus_memaddr_t;
|
||||
typedef pdq_bus_memaddr_t pdq_bus_memoffset_t;
|
||||
#if BSD >= 199506 /* __FreeBSD__ */
|
||||
#define PDQ_BPF_MTAP(sc, m) bpf_mtap(&(sc)->sc_if, m)
|
||||
#define PDQ_BPFATTACH(sc, t, s) bpfattach(&(sc)->sc_if, t, s)
|
||||
#endif
|
||||
|
||||
|
||||
#elif defined(__bsdi__)
|
||||
#include <machine/inline.h>
|
||||
typedef int ifnet_ret_t;
|
||||
typedef int ioctl_cmd_t;
|
||||
typedef enum { PDQ_BUS_EISA, PDQ_BUS_PCI } pdq_bus_t;
|
||||
typedef u_int16_t pdq_bus_ioport_t;
|
||||
typedef volatile pdq_uint32_t *pdq_bus_memaddr_t;
|
||||
typedef pdq_bus_memaddr_t pdq_bus_memoffset_t;
|
||||
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
#include <machine/bus.h>
|
||||
#include <machine/intr.h>
|
||||
#define PDQ_OS_PTR_FMT "%p"
|
||||
typedef void ifnet_ret_t;
|
||||
typedef u_long ioctl_cmd_t;
|
||||
typedef bus_chipset_tag_t pdq_bus_t;
|
||||
typedef bus_io_handle_t pdq_bus_ioport_t;
|
||||
#if defined(PDQ_IOMAPPED)
|
||||
typedef bus_io_handle_t pdq_bus_memaddr_t;
|
||||
#else
|
||||
typedef bus_mem_handle_t pdq_bus_memaddr_t;
|
||||
#endif
|
||||
typedef pdq_uint32_t pdq_bus_memoffset_t;
|
||||
#define PDQ_OS_IOMEM
|
||||
#define PDQ_OS_IORD_32(t, base, offset) bus_io_read_4 (t, base, offset)
|
||||
#define PDQ_OS_IOWR_32(t, base, offset, data) bus_io_write_4 (t, base, offset, data)
|
||||
#define PDQ_OS_IORD_8(t, base, offset) bus_io_read_1 (t, base, offset)
|
||||
#define PDQ_OS_IOWR_8(t, base, offset, data) bus_io_write_1 (t, base, offset, data)
|
||||
#define PDQ_OS_MEMRD_32(t, base, offset) bus_mem_read_4(t, base, offset)
|
||||
#define PDQ_OS_MEMWR_32(t, base, offset, data) bus_mem_write_4(t, base, offset, data)
|
||||
#define PDQ_CSR_OFFSET(base, offset) (0 + (offset)*sizeof(pdq_uint32_t))
|
||||
|
||||
#if defined(PDQ_IOMAPPED)
|
||||
#define PDQ_CSR_WRITE(csr, name, data) PDQ_OS_IOWR_32((csr)->csr_bus, (csr)->csr_base, (csr)->name, data)
|
||||
#define PDQ_CSR_READ(csr, name) PDQ_OS_IORD_32((csr)->csr_bus, (csr)->csr_base, (csr)->name)
|
||||
#else
|
||||
#define PDQ_CSR_WRITE(csr, name, data) PDQ_OS_MEMWR_32((csr)->csr_bus, (csr)->csr_base, (csr)->name, data)
|
||||
#define PDQ_CSR_READ(csr, name) PDQ_OS_MEMRD_32((csr)->csr_bus, (csr)->csr_base, (csr)->name)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(PDQ_BPF_MTAP)
|
||||
#define PDQ_BPF_MTAP(sc, m) bpf_mtap((sc)->sc_bpf, m)
|
||||
#endif
|
||||
|
||||
#if !defined(PDQ_BPFATTACH)
|
||||
#define PDQ_BPFATTACH(sc, t, s) bpfattach(&(sc)->sc_bpf, &(sc)->sc_if, t, s)
|
||||
#endif
|
||||
|
||||
#if !defined(PDQ_OS_PTR_FMT)
|
||||
#define PDQ_OS_PTR_FMT "0x%x"
|
||||
#endif
|
||||
|
||||
#if !defined(PDQ_OS_IOMEM)
|
||||
#define PDQ_OS_IORD_32(t, base, offset) inl((base) + (offset))
|
||||
#define PDQ_OS_IOWR_32(t, base, offset, data) outl((base) + (offset), data)
|
||||
#define PDQ_OS_IORD_8(t, base, offset) inb((base) + (offset))
|
||||
#define PDQ_OS_IOWR_8(t, base, offset, data) outb((base) + (offset), data)
|
||||
#define PDQ_OS_MEMRD_32(t, base, offset) (0 + *((base) + (offset)))
|
||||
#define PDQ_OS_MEMWR_32(t, base, offset, data) do *((base) + (offset)) = (data); while (0)
|
||||
#endif
|
||||
#ifndef PDQ_CSR_OFFSET
|
||||
#define PDQ_CSR_OFFSET(base, offset) (0 + (base) + (offset))
|
||||
#endif
|
||||
|
||||
#ifndef PDQ_CSR_WRITE
|
||||
#define PDQ_CSR_WRITE(csr, name, data) PDQ_OS_MEMWR_32((csr)->csr_bus, (csr)->name, 0, data)
|
||||
#define PDQ_CSR_READ(csr, name) PDQ_OS_MEMRD_32((csr)->csr_bus, (csr)->name, 0)
|
||||
#endif
|
||||
|
||||
#if !defined(PDQ_HWSUPPORT)
|
||||
|
||||
typedef struct {
|
||||
#if defined(__bsdi__)
|
||||
struct device sc_dev; /* base device */
|
||||
struct isadev sc_id; /* ISA device */
|
||||
struct intrhand sc_ih; /* interrupt vectoring */
|
||||
struct atshutdown sc_ats; /* shutdown routine */
|
||||
#elif defined(__NetBSD__)
|
||||
struct device sc_dev; /* base device */
|
||||
void *sc_ih; /* interrupt vectoring */
|
||||
void *sc_ats; /* shutdown hook */
|
||||
#elif defined(__FreeBSD__)
|
||||
struct kern_devconf *sc_kdc; /* freebsd cruft */
|
||||
#endif
|
||||
struct arpcom sc_ac;
|
||||
#define sc_if sc_ac.ac_if
|
||||
pdq_t *sc_pdq;
|
||||
#if defined(__alpha__) || defined(__i386__)
|
||||
pdq_bus_ioport_t sc_iobase;
|
||||
#endif
|
||||
#ifdef PDQ_IOMAPPED
|
||||
#define sc_membase sc_iobase
|
||||
#else
|
||||
pdq_bus_memaddr_t sc_membase;
|
||||
#endif
|
||||
pdq_bus_t sc_bc;
|
||||
#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
|
||||
#define sc_bpf sc_if.if_bpf
|
||||
#else
|
||||
caddr_t sc_bpf;
|
||||
#endif
|
||||
} pdq_softc_t;
|
||||
|
||||
|
||||
extern void pdq_ifreset(pdq_softc_t *sc);
|
||||
extern void pdq_ifinit(pdq_softc_t *sc);
|
||||
extern void pdq_ifwatchdog(struct ifnet *ifp);
|
||||
extern ifnet_ret_t pdq_ifstart(struct ifnet *ifp);
|
||||
extern int pdq_ifioctl(struct ifnet *ifp, ioctl_cmd_t cmd, caddr_t data);
|
||||
extern void pdq_ifattach(pdq_softc_t *sc, ifnet_ret_t (*ifwatchdog)(int unit));
|
||||
#endif /* !PDQ_HWSUPPORT */
|
||||
|
||||
|
||||
#elif defined(DLPI_PDQ)
|
||||
#include <sys/param.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/ddi.h>
|
||||
#include <sys/stream.h>
|
||||
|
||||
#define PDQ_USE_STREAMS
|
||||
#define PDQ_OS_PREFIX "%s board %d "
|
||||
#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name, pdq->pdq_unit
|
||||
|
||||
#define PDQ_OS_PAGESIZE PAGESIZE
|
||||
#define PDQ_OS_USEC_DELAY(n) drv_usecwait(n)
|
||||
#define PDQ_OS_MEMZERO(p, n) bzero((caddr_t)(p), (n))
|
||||
#define PDQ_OS_VA_TO_PA(pdq, p) vtop((caddr_t)p, NULL)
|
||||
#define PDQ_OS_MEMALLOC(n) kmem_zalloc(n, KM_NOSLEEP)
|
||||
#define PDQ_OS_MEMFREE(p, n) kmem_free((caddr_t) p, n)
|
||||
#define PDQ_OS_MEMALLOC_CONTIG(n) kmem_zalloc_physreq(n, decfddiphysreq_db, KM_NOSLEEP)
|
||||
#define PDQ_OS_MEMFREE_CONTIG(p, n) PDQ_OS_MEMFREE(p, n)
|
||||
|
||||
extern physreq_t *decfddiphysreq_db;
|
||||
extern physreq_t *decfddiphysreq_mblk;
|
||||
|
||||
#define PDQ_OS_DATABUF_ALLOC(b) ((void) (((b) = allocb_physreq(PDQ_OS_DATABUF_SIZE, BPRI_MED, decfddiphysreq_mblk)) && ((b)->b_wptr = (b)->b_rptr + PDQ_OS_DATABUF_SIZE)))
|
||||
|
||||
#define PDQ_OS_IORD_8(port) inb(port)
|
||||
#define PDQ_OS_IOWR_8(port, data) outb(port, data)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PDQ_USE_MBUFS
|
||||
#define PDQ_OS_DATABUF_SIZE (MCLBYTES)
|
||||
#define PDQ_OS_DATABUF_FREE(b) (m_freem(b))
|
||||
#define PDQ_OS_DATABUF_NEXT(b) ((b)->m_next)
|
||||
#define PDQ_OS_DATABUF_NEXT_SET(b, b1) ((b)->m_next = (b1))
|
||||
#define PDQ_OS_DATABUF_NEXTPKT(b) ((b)->m_nextpkt)
|
||||
#define PDQ_OS_DATABUF_NEXTPKT_SET(b, b1) ((b)->m_nextpkt = (b1))
|
||||
#define PDQ_OS_DATABUF_LEN(b) ((b)->m_len)
|
||||
#define PDQ_OS_DATABUF_LEN_SET(b, n) ((b)->m_len = (n))
|
||||
/* #define PDQ_OS_DATABUF_LEN_ADJ(b, n) ((b)->m_len += (n)) */
|
||||
#define PDQ_OS_DATABUF_PTR(b) (mtod((b), pdq_uint8_t *))
|
||||
#define PDQ_OS_DATABUF_ADJ(b, n) ((b)->m_data += (n), (b)->m_len -= (n))
|
||||
typedef struct mbuf PDQ_OS_DATABUF_T;
|
||||
|
||||
#define PDQ_OS_DATABUF_ALLOC(b) do { \
|
||||
PDQ_OS_DATABUF_T *x_m0; \
|
||||
MGETHDR(x_m0, M_DONTWAIT, MT_DATA); \
|
||||
if (x_m0 != NULL) { \
|
||||
MCLGET(x_m0, M_DONTWAIT); \
|
||||
if ((x_m0->m_flags & M_EXT) == 0) { \
|
||||
m_free(x_m0); \
|
||||
(b) = NULL; \
|
||||
} else { \
|
||||
(b) = x_m0; \
|
||||
x_m0->m_len = PDQ_OS_DATABUF_SIZE; \
|
||||
} \
|
||||
} else { \
|
||||
(b) = NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
#define PDQ_OS_DATABUF_RESET(b) ((b)->m_data = (b)->m_ext.ext_buf, (b)->m_len = MCLBYTES)
|
||||
#endif /* PDQ_USE_MBUFS */
|
||||
|
||||
#ifdef PDQ_USE_STREAMS
|
||||
#define PDQ_OS_DATABUF_SIZE (2048)
|
||||
#define PDQ_OS_DATABUF_FREE(b) (freemsg(b))
|
||||
#define PDQ_OS_DATABUF_NEXT(b) ((b)->b_cont)
|
||||
#define PDQ_OS_DATABUF_NEXT_SET(b, b1) ((b)->b_cont = (b1))
|
||||
#define PDQ_OS_DATABUF_NEXTPKT(b) ((b)->b_next)
|
||||
#define PDQ_OS_DATABUF_NEXTPKT_SET(b, b1) ((b)->b_next = (b1))
|
||||
#define PDQ_OS_DATABUF_LEN(b) ((b)->b_wptr - (b)->b_rptr)
|
||||
#define PDQ_OS_DATABUF_LEN_SET(b, n) ((b)->b_wptr = (b)->b_rptr + (n))
|
||||
/*#define PDQ_OS_DATABUF_LEN_ADJ(b, n) ((b)->b_wptr += (n))*/
|
||||
#define PDQ_OS_DATABUF_PTR(b) ((pdq_uint8_t *) (b)->b_rptr)
|
||||
#define PDQ_OS_DATABUF_ADJ(b, n) ((b)->b_rptr += (n))
|
||||
typedef mblk_t PDQ_OS_DATABUF_T;
|
||||
|
||||
#ifndef PDQ_OS_DATABUF_ALLOC
|
||||
#define PDQ_OS_DATABUF_ALLOC(b) ((void) (((b) = allocb(PDQ_OS_DATABUF_SIZE, BPRI_MED)) && ((b)->b_wptr = (b)->b_rptr + PDQ_OS_DATABUF_SIZE)))
|
||||
#endif /* PDQ_OS_DATABUF_ALLOC */
|
||||
#endif /* PDQ_USE_STREAMS */
|
||||
|
||||
#define PDQ_OS_TX_TRANSMIT 5
|
||||
|
||||
#define PDQ_OS_DATABUF_ENQUEUE(q, b) do { \
|
||||
PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
|
||||
if ((q)->q_tail == NULL) \
|
||||
(q)->q_head = (b); \
|
||||
else \
|
||||
PDQ_OS_DATABUF_NEXTPKT_SET(((PDQ_OS_DATABUF_T *)(q)->q_tail), b); \
|
||||
(q)->q_tail = (b); \
|
||||
} while (0)
|
||||
|
||||
#define PDQ_OS_DATABUF_DEQUEUE(q, b) do { \
|
||||
if (((b) = (PDQ_OS_DATABUF_T *) (q)->q_head) != NULL) { \
|
||||
if (((q)->q_head = PDQ_OS_DATABUF_NEXTPKT(b)) == NULL) \
|
||||
(q)->q_tail = NULL; \
|
||||
PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
extern void pdq_os_addr_fill(pdq_t *pdq, pdq_lanaddr_t *addrs, size_t numaddrs);
|
||||
extern void pdq_os_receive_pdu(pdq_t *, PDQ_OS_DATABUF_T *pdu, size_t pdulen);
|
||||
extern void pdq_os_restart_transmitter(pdq_t *pdq);
|
||||
extern void pdq_os_transmit_done(pdq_t *pdq, PDQ_OS_DATABUF_T *pdu);
|
||||
|
||||
extern pdq_boolean_t pdq_queue_transmit_data(pdq_t *pdq, PDQ_OS_DATABUF_T *pdu);
|
||||
extern void pdq_flush_transmitter(pdq_t *pdq);
|
||||
|
||||
extern void pdq_run(pdq_t *pdq);
|
||||
extern pdq_state_t pdq_stop(pdq_t *pdq);
|
||||
extern void pdq_hwreset(pdq_t *pdq);
|
||||
|
||||
extern int pdq_interrupt(pdq_t *pdq);
|
||||
extern pdq_t *pdq_initialize(pdq_bus_t bus, pdq_bus_memaddr_t csr_va,
|
||||
const char *name, int unit,
|
||||
void *ctx, pdq_type_t type);
|
||||
#endif /* _PDQ_OS_H */
|
537
sys/i386/eisa/if_fea.c
Normal file
537
sys/i386/eisa/if_fea.c
Normal file
@ -0,0 +1,537 @@
|
||||
/*-
|
||||
* Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software withough specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: if_fea.c,v 1.7 1996/07/31 21:38:44 thomas Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* DEC PDQ FDDI Controller
|
||||
*
|
||||
* This module support the DEFEA EISA FDDI Controller.
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/malloc.h>
|
||||
#if defined(__FreeBSD__)
|
||||
#include <sys/devconf.h>
|
||||
#elif defined(__bsdi__) || defined(__NetBSD__)
|
||||
#include <sys/device.h>
|
||||
#endif
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_types.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include "bpfilter.h"
|
||||
#if NBPFILTER > 0
|
||||
#include <net/bpf.h>
|
||||
#include <net/bpfdesc.h>
|
||||
#endif
|
||||
|
||||
#ifdef INET
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <netinet/if_fddi.h>
|
||||
#else
|
||||
#include <net/if_fddi.h>
|
||||
#endif
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_kern.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <i386/eisa/eisaconf.h>
|
||||
#include <i386/isa/icu.h>
|
||||
#include <dev/pdq/pdqvar.h>
|
||||
#include <dev/pdq/pdqreg.h>
|
||||
#elif defined(__bsdi__)
|
||||
#include <i386/isa/isa.h>
|
||||
#include <i386/isa/icu.h>
|
||||
#include <i386/isa/dma.h>
|
||||
#include <i386/isa/isavar.h>
|
||||
#include <i386/eisa/eisa.h>
|
||||
#include <dev/pdq/pdqvar.h>
|
||||
#include <dev/pdq/pdqreg.h>
|
||||
#elif defined(__NetBSD__)
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <dev/ic/pdqvar.h>
|
||||
#include <dev/ic/pdqreg.h>
|
||||
|
||||
#include <dev/eisa/eisareg.h>
|
||||
#include <dev/eisa/eisavar.h>
|
||||
#include <dev/eisa/eisadevs.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define DEFEA_IRQS 0x0000FBA9U
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
static pdq_softc_t *pdqs_eisa[16];
|
||||
#define PDQ_EISA_UNIT_TO_SOFTC(unit) (pdqs_eisa[unit])
|
||||
#define DEFEA_INTRENABLE 0x8 /* level interrupt */
|
||||
#define pdq_eisa_ifwatchdog NULL
|
||||
#define DEFEA_DECODE_IRQ(n) ((DEFEA_IRQS >> ((n) << 2)) & 0x0f)
|
||||
|
||||
#elif defined(__bsdi__)
|
||||
extern struct cfdriver feacd;
|
||||
#define PDQ_EISA_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)feacd.cd_devs[unit])
|
||||
#define DEFEA_INTRENABLE 0x28 /* edge interrupt */
|
||||
static const int pdq_eisa_irqs[4] = { IRQ9, IRQ10, IRQ11, IRQ15 };
|
||||
#define DEFEA_DECODE_IRQ(n) (pdq_eisa_irqs[(n)])
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
#define DEFEA_INTRENABLE 0x8 /* level interrupt */
|
||||
#define pdq_eisa_ifwatchdog NULL
|
||||
#define DEFEA_DECODE_IRQ(n) ((DEFEA_IRQS >> ((n) << 2)) & 0x0f)
|
||||
|
||||
#else
|
||||
#error unknown system
|
||||
#endif
|
||||
|
||||
#ifndef pdq_eisa_ifwatchdog
|
||||
static ifnet_ret_t
|
||||
pdq_eisa_ifwatchdog(
|
||||
int unit)
|
||||
{
|
||||
pdq_ifwatchdog(&PDQ_EISA_UNIT_TO_SOFTC(unit)->sc_if);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
pdq_eisa_subprobe(
|
||||
pdq_bus_t bc,
|
||||
pdq_bus_ioport_t iobase,
|
||||
pdq_uint32_t *maddr,
|
||||
pdq_uint32_t *msize,
|
||||
pdq_uint32_t *irq)
|
||||
{
|
||||
if (irq != NULL)
|
||||
*irq = DEFEA_DECODE_IRQ(PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_IO_CONFIG_STAT_0) & 3);
|
||||
*maddr = (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_CMP_0) << 8)
|
||||
| (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_CMP_1) << 16);
|
||||
*msize = (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_MASK_0) + 4) << 8;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_eisa_devinit(
|
||||
pdq_softc_t *sc)
|
||||
{
|
||||
pdq_uint8_t data;
|
||||
|
||||
/*
|
||||
* Do the standard initialization for the DEFEA registers.
|
||||
*/
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_FUNCTION_CTRL, 0x23);
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CMP_1_1, (sc->sc_iobase >> 8) & 0xF0);
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CMP_0_1, (sc->sc_iobase >> 8) & 0xF0);
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_SLOT_CTRL, 0x01);
|
||||
data = PDQ_OS_IORD_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF);
|
||||
#if defined(PDQ_IOMAPPED)
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF, data & ~1);
|
||||
#else
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF, data | 1);
|
||||
#endif
|
||||
data = PDQ_OS_IORD_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CONFIG_STAT_0);
|
||||
PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CONFIG_STAT_0, data | DEFEA_INTRENABLE);
|
||||
}
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
static int pdq_eisa_shutdown(struct kern_devconf *kdc, int force);
|
||||
static int pdq_eisa_probe(void);
|
||||
static int pdq_eisa_attach(struct eisa_device *ed);
|
||||
|
||||
static unsigned long pdq_eisa_unit;
|
||||
|
||||
static struct eisa_driver pdq_eisa_driver = {
|
||||
"fea", pdq_eisa_probe, pdq_eisa_attach, NULL, &pdq_eisa_unit
|
||||
};
|
||||
|
||||
DATA_SET(eisadriver_set, pdq_eisa_driver);
|
||||
|
||||
static struct kern_devconf kdc_pdq_eisa = {
|
||||
0, 0, 0, /* filled in by dev_attach */
|
||||
"fea", 0, { MDDT_EISA, 0, "net" },
|
||||
eisa_generic_externalize, 0, pdq_eisa_shutdown, EISA_EXTERNALLEN,
|
||||
&kdc_eisa0, /* parent */
|
||||
0, /* parentdata */
|
||||
DC_BUSY, /* host adapters are always ``in use'' */
|
||||
"DEC DEFEA EISA FDDI Controller",
|
||||
DC_CLS_NETIF
|
||||
};
|
||||
|
||||
static const char *
|
||||
pdq_eisa_match(
|
||||
eisa_id_t type)
|
||||
{
|
||||
if ((type >> 8) == 0x10a330)
|
||||
return kdc_pdq_eisa.kdc_description;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
pdq_eisa_probe(
|
||||
void)
|
||||
{
|
||||
struct eisa_device *ed = NULL;
|
||||
int count;
|
||||
|
||||
for (count = 0; (ed = eisa_match_dev(ed, pdq_eisa_match)) != NULL; count++) {
|
||||
pdq_bus_ioport_t iobase = ed->ioconf.slot * EISA_SLOT_SIZE;
|
||||
pdq_uint32_t irq, maddr, msize;
|
||||
|
||||
eisa_add_iospace(ed, iobase, 0x200, RESVADDR_NONE);
|
||||
pdq_eisa_subprobe(PDQ_BUS_EISA, iobase, &maddr, &msize, &irq);
|
||||
eisa_add_mspace(ed, maddr, msize, RESVADDR_NONE);
|
||||
eisa_add_intr(ed, irq);
|
||||
eisa_registerdev(ed, &pdq_eisa_driver, &kdc_pdq_eisa);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_eisa_interrupt(
|
||||
void *arg)
|
||||
{
|
||||
pdq_softc_t * const sc = (pdq_softc_t *) arg;
|
||||
(void) pdq_interrupt(sc->sc_pdq);
|
||||
}
|
||||
|
||||
static int
|
||||
pdq_eisa_attach(
|
||||
struct eisa_device *ed)
|
||||
{
|
||||
pdq_softc_t *sc;
|
||||
resvaddr_t *iospace;
|
||||
resvaddr_t *mspace;
|
||||
int irq = ffs(ed->ioconf.irq) - 1;
|
||||
|
||||
sc = (pdq_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_WAITOK);
|
||||
if (sc == NULL) {
|
||||
printf("fea%d: malloc failed!\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
pdqs_eisa[ed->unit] = sc;
|
||||
|
||||
bzero(sc, sizeof(pdq_softc_t)); /* Zero out the softc*/
|
||||
sc->sc_if.if_name = "fea";
|
||||
sc->sc_if.if_unit = ed->unit;
|
||||
|
||||
if ((iospace = ed->ioconf.ioaddrs.lh_first) == NULL) {
|
||||
printf("fea%d: no iospace??\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
if ((mspace = ed->ioconf.maddrs.lh_first) == NULL) {
|
||||
printf("fea%d: no memory space??\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sc->sc_iobase = (pdq_bus_ioport_t) iospace->addr;
|
||||
sc->sc_membase = (pdq_bus_memaddr_t) pmap_mapdev(mspace->addr, mspace->size);
|
||||
if (sc->sc_membase == NULL) {
|
||||
printf("fea%d: failed to map memory 0x%x-0x%x!\n",
|
||||
sc->sc_if.if_unit, mspace->addr, mspace->addr + mspace->size - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
eisa_reg_start(ed);
|
||||
if (eisa_reg_iospace(ed, iospace)) {
|
||||
printf("fea%d: failed to register iospace 0x%x-0x%x!\n",
|
||||
sc->sc_if.if_unit, iospace->addr, iospace->addr + iospace->size - 1);
|
||||
return -1;
|
||||
}
|
||||
if (eisa_reg_mspace(ed, mspace)) {
|
||||
printf("fea%d: failed to register memory 0x%x-0x%x!\n",
|
||||
sc->sc_if.if_unit, mspace->addr, mspace->addr + mspace->size - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (eisa_reg_intr(ed, irq, pdq_eisa_interrupt, sc, &net_imask, 1)) {
|
||||
printf("fea%d: interrupt registration failed\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
|
||||
eisa_reg_end(ed);
|
||||
|
||||
pdq_eisa_devinit(sc);
|
||||
sc->sc_pdq = pdq_initialize(PDQ_BUS_EISA, sc->sc_membase,
|
||||
sc->sc_if.if_name, sc->sc_if.if_unit,
|
||||
(void *) sc, PDQ_DEFEA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("fea%d: initialization failed\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (eisa_enable_intr(ed, irq)) {
|
||||
printf("fea%d: failed to enable interrupt\n", sc->sc_if.if_unit);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
pdq_ifattach(sc, pdq_eisa_ifwatchdog);
|
||||
|
||||
ed->kdc->kdc_state = DC_BUSY; /* host adapters always busy */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
pdq_eisa_shutdown(
|
||||
struct kern_devconf *kdc,
|
||||
int force)
|
||||
{
|
||||
pdq_hwreset(PDQ_EISA_UNIT_TO_SOFTC(kdc->kdc_unit)->sc_pdq);
|
||||
(void) dev_detach(kdc);
|
||||
return 0;
|
||||
}
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
#if defined(__bsdi__)
|
||||
static int
|
||||
pdq_eisa_probe(
|
||||
struct device *parent,
|
||||
struct cfdata *cf,
|
||||
void *aux)
|
||||
{
|
||||
struct isa_attach_args *ia = (struct isa_attach_args *) aux;
|
||||
int slot;
|
||||
pdq_uint32_t irq, maddr, msize;
|
||||
|
||||
if (isa_bustype != BUS_EISA)
|
||||
return 0;
|
||||
|
||||
if ((slot = eisa_match(cf, ia)) == 0)
|
||||
return 0;
|
||||
ia->ia_iobase = slot << 12;
|
||||
ia->ia_iosize = EISA_NPORT;
|
||||
eisa_slotalloc(slot);
|
||||
|
||||
pdq_eisa_subprobe(PDQ_BUS_EISA, ia->ia_iobase, &maddr, &msize, &irq);
|
||||
if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) {
|
||||
printf("fea%d: error: desired IRQ of %d does not match device's actual IRQ (%d),\n",
|
||||
cf->cf_unit,
|
||||
ffs(ia->ia_irq) - 1, ffs(irq) - 1);
|
||||
return 0;
|
||||
}
|
||||
if (ia->ia_irq == IRQUNK) {
|
||||
if ((ia->ia_irq = isa_irqalloc(irq)) == 0) {
|
||||
if ((ia->ia_irq = isa_irqalloc(IRQ9|IRQ10|IRQ11|IRQ15)) == 0) {
|
||||
printf("fea%d: error: IRQ %d is already in use\n", cf->cf_unit,
|
||||
ffs(irq) - 1);
|
||||
return 0;
|
||||
}
|
||||
irq = PDQ_OS_IORD_8(PDQ_BUS_EISA, ia->ia_iobase, PDQ_EISA_IO_CONFIG_STAT_0) & ~3;
|
||||
switch (ia->ia_irq) {
|
||||
case IRQ9: irq |= 0;
|
||||
case IRQ10: irq |= 1;
|
||||
case IRQ11: irq |= 2;
|
||||
case IRQ15: irq |= 3;
|
||||
}
|
||||
PDQ_OS_IOWR_8(PDQ_BUS_EISA, ia->ia_iobase, PDQ_EISA_IO_CONFIG_STAT_0, irq);
|
||||
}
|
||||
}
|
||||
if (maddr == 0) {
|
||||
printf("fea%d: error: memory not enabled! ECU reconfiguration required\n",
|
||||
cf->cf_unit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EISA bus masters don't use host DMA channels */
|
||||
ia->ia_drq = DRQNONE;
|
||||
|
||||
ia->ia_maddr = (caddr_t) maddr;
|
||||
ia->ia_msize = msize;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_eisa_attach(
|
||||
struct device *parent,
|
||||
struct device *self,
|
||||
void *aux)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) self;
|
||||
register struct isa_attach_args *ia = (struct isa_attach_args *) aux;
|
||||
register struct ifnet *ifp = &sc->sc_if;
|
||||
|
||||
sc->sc_if.if_unit = sc->sc_dev.dv_unit;
|
||||
sc->sc_if.if_name = "fea";
|
||||
sc->sc_if.if_flags = 0;
|
||||
|
||||
sc->sc_iobase = ia->ia_iobase;
|
||||
|
||||
pdq_eisa_devinit(sc);
|
||||
sc->sc_pdq = pdq_initialize(PDQ_BUS_EISA,
|
||||
(pdq_bus_memaddr_t) ISA_HOLE_VADDR(ia->ia_maddr),
|
||||
sc->sc_if.if_name, sc->sc_if.if_unit,
|
||||
(void *) sc, PDQ_DEFEA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("fea%d: initialization failed\n", sc->sc_if.if_unit);
|
||||
return;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
|
||||
pdq_ifattach(sc, pdq_eisa_ifwatchdog);
|
||||
|
||||
isa_establish(&sc->sc_id, &sc->sc_dev);
|
||||
|
||||
sc->sc_ih.ih_fun = pdq_interrupt;
|
||||
sc->sc_ih.ih_arg = (void *) sc->sc_pdq;
|
||||
intr_establish(ia->ia_irq, &sc->sc_ih, DV_NET);
|
||||
|
||||
sc->sc_ats.func = (void (*)(void *)) pdq_hwreset;
|
||||
sc->sc_ats.arg = (void *) sc->sc_pdq;
|
||||
atshutdown(&sc->sc_ats, ATSH_ADD);
|
||||
}
|
||||
|
||||
static char *pdq_eisa_ids[] = {
|
||||
"DEC3001", /* 0x0130A310 */
|
||||
"DEC3002", /* 0x0230A310 */
|
||||
"DEC3003", /* 0x0330A310 */
|
||||
"DEC3004", /* 0x0430A310 */
|
||||
};
|
||||
|
||||
struct cfdriver feacd = {
|
||||
0, "fea", pdq_eisa_probe, pdq_eisa_attach, DV_IFNET, sizeof(pdq_softc_t),
|
||||
pdq_eisa_ids
|
||||
};
|
||||
#endif /* __bsdi__ */
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
static int
|
||||
pdq_eisa_match(
|
||||
struct device *parent,
|
||||
void *match,
|
||||
void *aux)
|
||||
{
|
||||
const struct eisa_attach_args * const ea = (struct eisa_attach_args *) aux;
|
||||
|
||||
if (strncmp(ea->ea_idstring, "DEC300", 6) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_eisa_attach(
|
||||
struct device *parent,
|
||||
struct device *self,
|
||||
void *aux)
|
||||
{
|
||||
pdq_softc_t * const sc = (pdq_softc_t *) self;
|
||||
struct eisa_attach_args * const ea = (struct eisa_attach_args *) aux;
|
||||
pdq_uint32_t irq, maddr, msize;
|
||||
eisa_intr_handle_t ih;
|
||||
const char *intrstr;
|
||||
|
||||
sc->sc_bc = ea->ea_bc;
|
||||
bcopy(sc->sc_dev.dv_xname, sc->sc_if.if_xname, IFNAMSIZ);
|
||||
sc->sc_if.if_flags = 0;
|
||||
sc->sc_if.if_softc = sc;
|
||||
|
||||
if (bus_io_map(sc->sc_bc, EISA_SLOT_ADDR(ea->ea_slot), EISA_SLOT_SIZE, &sc->sc_iobase)) {
|
||||
printf("\n%s: failed to map I/O!\n", sc->sc_dev.dv_xname);
|
||||
return;
|
||||
}
|
||||
|
||||
pdq_eisa_subprobe(sc->sc_bc, sc->sc_iobase, &maddr, &msize, &irq);
|
||||
|
||||
#if !defined(PDQ_IOMAPPED)
|
||||
if (maddr == 0 || msize == 0) {
|
||||
printf("\n%s: error: memory not enabled! ECU reconfiguration required\n",
|
||||
sc->sc_dev.dv_xname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bus_mem_map(sc->sc_bc, maddr, msize, 0, &sc->sc_membase)) {
|
||||
bus_io_unmap(sc->sc_bc, sc->sc_iobase, EISA_SLOT_SIZE);
|
||||
printf("\n%s: failed to map memory (0x%x-0x%x)!\n",
|
||||
sc->sc_dev.dv_xname, maddr, maddr + msize - 1);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
pdq_eisa_devinit(sc);
|
||||
sc->sc_pdq = pdq_initialize(sc->sc_bc, sc->sc_membase,
|
||||
sc->sc_if.if_xname, 0,
|
||||
(void *) sc, PDQ_DEFEA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("%s: initialization failed\n", sc->sc_dev.dv_xname);
|
||||
return;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
|
||||
pdq_ifattach(sc, pdq_eisa_ifwatchdog);
|
||||
|
||||
if (eisa_intr_map(ea->ea_ec, irq, &ih)) {
|
||||
printf("%s: couldn't map interrupt (%d)\n", sc->sc_dev.dv_xname, irq);
|
||||
return;
|
||||
}
|
||||
intrstr = eisa_intr_string(ea->ea_ec, ih);
|
||||
sc->sc_ih = eisa_intr_establish(ea->ea_ec, ih, IST_LEVEL, IPL_NET,
|
||||
(int (*)(void *)) pdq_interrupt, sc->sc_pdq);
|
||||
if (sc->sc_ih == NULL) {
|
||||
printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
|
||||
if (intrstr != NULL)
|
||||
printf(" at %s", intrstr);
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
sc->sc_ats = shutdownhook_establish((void (*)(void *)) pdq_hwreset, sc->sc_pdq);
|
||||
if (sc->sc_ats == NULL)
|
||||
printf("%s: warning: couldn't establish shutdown hook\n", self->dv_xname);
|
||||
#if !defined(PDQ_IOMAPPED)
|
||||
printf("%s: using iomem 0x%x-0x%x\n", sc->sc_dev.dv_xname, maddr, maddr + msize - 1);
|
||||
#endif
|
||||
if (intrstr != NULL)
|
||||
printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
|
||||
}
|
||||
|
||||
struct cfattach fea_ca = {
|
||||
sizeof(pdq_softc_t), pdq_eisa_match, pdq_eisa_attach
|
||||
};
|
||||
|
||||
struct cfdriver fea_cd = {
|
||||
0, "fea", DV_IFNET
|
||||
};
|
||||
#endif
|
472
sys/pci/if_fpa.c
Normal file
472
sys/pci/if_fpa.c
Normal file
@ -0,0 +1,472 @@
|
||||
/*-
|
||||
* Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software withough specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: if_fpa.c,v 1.9 1996/07/31 21:38:44 thomas Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* DEC PDQ FDDI Controller; code for BSD derived operating systems
|
||||
*
|
||||
* This module supports the DEC DEFPA PCI FDDI Controller
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/malloc.h>
|
||||
#if defined(__FreeBSD__)
|
||||
#include <sys/devconf.h>
|
||||
#elif defined(__bsdi__) || defined(__NetBSD__)
|
||||
#include <sys/device.h>
|
||||
#endif
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_types.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include "bpfilter.h"
|
||||
#if NBPFILTER > 0
|
||||
#include <net/bpf.h>
|
||||
#include <net/bpfdesc.h>
|
||||
#endif
|
||||
|
||||
#ifdef INET
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#endif
|
||||
#if defined(__FreeBSD__)
|
||||
#include <netinet/if_fddi.h>
|
||||
#else
|
||||
#include <net/if_fddi.h>
|
||||
#endif
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_kern.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include "fpa.h"
|
||||
#include <pci/pcivar.h>
|
||||
#include <i386/isa/icu.h>
|
||||
#include <dev/pdq/pdqvar.h>
|
||||
#include <dev/pdq/pdqreg.h>
|
||||
#elif defined(__bsdi__)
|
||||
#include <i386/isa/isavar.h>
|
||||
#include <i386/isa/icu.h>
|
||||
#ifndef DRQNONE
|
||||
#define DRQNONE 0
|
||||
#endif
|
||||
#if _BSDI_VERSION < 199401
|
||||
#define IRQSHARE 0
|
||||
#endif
|
||||
#include <i386/pci/pci.h>
|
||||
#include <dev/pdq/pdqvar.h>
|
||||
#include <dev/pdq/pdqreg.h>
|
||||
#elif defined(__NetBSD__)
|
||||
#include <dev/pci/pcivar.h>
|
||||
#include <dev/ic/pdqvar.h>
|
||||
#include <dev/ic/pdqreg.h>
|
||||
#endif /* __NetBSD__ */
|
||||
|
||||
|
||||
#define DEC_VENDORID 0x1011
|
||||
#define DEFPA_CHIPID 0x000F
|
||||
#define PCI_VENDORID(x) ((x) & 0xFFFF)
|
||||
#define PCI_CHIPID(x) (((x) >> 16) & 0xFFFF)
|
||||
|
||||
#define DEFPA_LATENCY 0x88
|
||||
|
||||
#define PCI_CFLT 0x0C /* Configuration Latency */
|
||||
#define PCI_CBMA 0x10 /* Configuration Base Memory Address */
|
||||
#define PCI_CBIO 0x14 /* Configuration Base I/O Address */
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#if NFPA < 4
|
||||
#undef NFPA
|
||||
#define NFPA 4
|
||||
#endif
|
||||
static pdq_softc_t *pdqs_pci[NFPA];
|
||||
#define PDQ_PCI_UNIT_TO_SOFTC(unit) (pdqs_pci[unit])
|
||||
#if BSD >= 199506
|
||||
#define pdq_pci_ifwatchdog NULL
|
||||
#endif
|
||||
|
||||
#elif defined(__bsdi__)
|
||||
extern struct cfdriver fpacd;
|
||||
#define PDQ_PCI_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)fpacd.cd_devs[unit])
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
extern struct cfattach fpa_ca;
|
||||
extern struct cfdriver fpa_cd;
|
||||
#define PDQ_PCI_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)fpa_cd.cd_devs[unit])
|
||||
#define pdq_pci_ifwatchdog NULL
|
||||
#endif
|
||||
|
||||
#ifndef pdq_pci_ifwatchdog
|
||||
static ifnet_ret_t
|
||||
pdq_pci_ifwatchdog(
|
||||
int unit)
|
||||
{
|
||||
pdq_ifwatchdog(&PDQ_PCI_UNIT_TO_SOFTC(unit)->sc_if);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__) && BSD >= 199506
|
||||
static void
|
||||
pdq_pci_ifintr(
|
||||
void *arg)
|
||||
{
|
||||
(void) pdq_interrupt(((pdq_softc_t *) arg)->sc_pdq);
|
||||
}
|
||||
#else
|
||||
static int
|
||||
pdq_pci_ifintr(
|
||||
void *arg)
|
||||
{
|
||||
pdq_softc_t * const sc = (pdq_softc_t *) arg;
|
||||
#ifdef __FreeBSD__
|
||||
return pdq_interrupt(sc->sc_pdq);
|
||||
#elif defined(__bsdi__) || defined(__NetBSD__)
|
||||
(void) pdq_interrupt(sc->sc_pdq);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
#endif /* __FreeBSD && BSD */
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
/*
|
||||
* This is the PCI configuration support. Since the PDQ is available
|
||||
* on both EISA and PCI boards, one must be careful in how defines the
|
||||
* PDQ in the config file.
|
||||
*/
|
||||
static char *
|
||||
pdq_pci_probe(
|
||||
pcici_t config_id,
|
||||
pcidi_t device_id)
|
||||
{
|
||||
if (PCI_VENDORID(device_id) == DEC_VENDORID &&
|
||||
PCI_CHIPID(device_id) == DEFPA_CHIPID)
|
||||
return "Digital DEFPA PCI FDDI Controller";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_pci_attach(
|
||||
pcici_t config_id,
|
||||
int unit)
|
||||
{
|
||||
pdq_softc_t *sc;
|
||||
vm_offset_t va_csrs, pa_csrs;
|
||||
pdq_uint32_t data;
|
||||
|
||||
if (unit == NFPA) {
|
||||
printf("fpa%d: not configured; kernel is built for only %d device%s.\n",
|
||||
unit, NFPA, NFPA == 1 ? "" : "s");
|
||||
return;
|
||||
}
|
||||
|
||||
data = pci_conf_read(config_id, PCI_CFLT);
|
||||
if ((data & 0xFF00) < (DEFPA_LATENCY << 8)) {
|
||||
data &= ~0xFF00;
|
||||
data |= DEFPA_LATENCY << 8;
|
||||
pci_conf_write(config_id, PCI_CFLT, data);
|
||||
}
|
||||
|
||||
sc = (pdq_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT);
|
||||
if (sc == NULL)
|
||||
return;
|
||||
|
||||
bzero(sc, sizeof(pdq_softc_t)); /* Zero out the softc*/
|
||||
if (!pci_map_mem(config_id, PCI_CBMA, &va_csrs, &pa_csrs)) {
|
||||
free((void *) sc, M_DEVBUF);
|
||||
return;
|
||||
}
|
||||
|
||||
sc->sc_if.if_name = "fpa";
|
||||
sc->sc_if.if_unit = unit;
|
||||
sc->sc_membase = (pdq_bus_memaddr_t) va_csrs;
|
||||
sc->sc_pdq = pdq_initialize(PDQ_BUS_PCI, sc->sc_membase,
|
||||
sc->sc_if.if_name, sc->sc_if.if_unit,
|
||||
(void *) sc, PDQ_DEFPA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
free((void *) sc, M_DEVBUF);
|
||||
return;
|
||||
}
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
pdqs_pci[unit] = sc;
|
||||
pdq_ifattach(sc, pdq_pci_ifwatchdog);
|
||||
pci_map_int(config_id, pdq_pci_ifintr, (void*) sc, &net_imask);
|
||||
}
|
||||
|
||||
static int
|
||||
pdq_pci_shutdown(
|
||||
struct kern_devconf *kdc,
|
||||
int force)
|
||||
{
|
||||
if (kdc->kdc_unit < NFPA)
|
||||
pdq_hwreset(PDQ_PCI_UNIT_TO_SOFTC(kdc->kdc_unit)->sc_pdq);
|
||||
(void) dev_detach(kdc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u_long pdq_pci_count;
|
||||
|
||||
struct pci_device fpadevice = {
|
||||
"fpa",
|
||||
pdq_pci_probe,
|
||||
pdq_pci_attach,
|
||||
&pdq_pci_count,
|
||||
pdq_pci_shutdown,
|
||||
};
|
||||
|
||||
#ifdef DATA_SET
|
||||
DATA_SET (pcidevice_set, fpadevice);
|
||||
#endif
|
||||
#elif defined(__bsdi__)
|
||||
|
||||
static int
|
||||
pdq_pci_match(
|
||||
pci_devaddr_t *pa)
|
||||
{
|
||||
int irq;
|
||||
int id;
|
||||
|
||||
id = pci_inl(pa, PCI_VENDOR_ID);
|
||||
if (PCI_VENDORID(id) != DEC_VENDORID || PCI_CHIPID(id) != DEFPA_CHIPID)
|
||||
return 0;
|
||||
|
||||
irq = pci_inl(pa, PCI_I_LINE) & 0xFF;
|
||||
if (irq == 0 || irq >= 16)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
pdq_pci_probe(
|
||||
struct device *parent,
|
||||
struct cfdata *cf,
|
||||
void *aux)
|
||||
{
|
||||
struct isa_attach_args *ia = (struct isa_attach_args *) aux;
|
||||
pdq_uint32_t irq, data;
|
||||
pci_devaddr_t *pa;
|
||||
|
||||
pa = pci_scan(pdq_pci_match);
|
||||
if (pa == NULL)
|
||||
return 0;
|
||||
|
||||
irq = (1 << (pci_inl(pa, PCI_I_LINE) & 0xFF));
|
||||
|
||||
if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) {
|
||||
printf("fpa%d: error: desired IRQ of %d does not match device's actual IRQ of %d\n",
|
||||
cf->cf_unit,
|
||||
ffs(ia->ia_irq) - 1, ffs(irq) - 1);
|
||||
return 0;
|
||||
}
|
||||
if (ia->ia_irq == IRQUNK) {
|
||||
(void) isa_irqalloc(irq);
|
||||
ia->ia_irq = irq;
|
||||
}
|
||||
|
||||
/* PCI bus masters don't use host DMA channels */
|
||||
ia->ia_drq = DRQNONE;
|
||||
|
||||
/* Get the memory base address; assume the BIOS set it up correctly */
|
||||
ia->ia_maddr = (caddr_t) (pci_inl(pa, PCI_CBMA) & ~7);
|
||||
pci_outl(pa, PCI_CBMA, 0xFFFFFFFF);
|
||||
ia->ia_msize = ((~pci_inl(pa, PCI_CBMA)) | 7) + 1;
|
||||
pci_outl(pa, PCI_CBMA, (int) ia->ia_maddr);
|
||||
|
||||
/* Disable I/O space access */
|
||||
pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~1);
|
||||
ia->ia_iobase = 0;
|
||||
ia->ia_iosize = 0;
|
||||
|
||||
/* Make sure the latency timer is what the DEFPA likes */
|
||||
data = pci_inl(pa, PCI_CFLT);
|
||||
if ((data & 0xFF00) < (DEFPA_LATENCY << 8)) {
|
||||
data &= ~0xFF00;
|
||||
data |= DEFPA_LATENCY << 8;
|
||||
pci_outl(pa, PCI_CFLT, data);
|
||||
}
|
||||
ia->ia_irq |= IRQSHARE;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
pdq_pci_attach(
|
||||
struct device *parent,
|
||||
struct device *self,
|
||||
void *aux)
|
||||
{
|
||||
pdq_softc_t *sc = (pdq_softc_t *) self;
|
||||
register struct isa_attach_args *ia = (struct isa_attach_args *) aux;
|
||||
register struct ifnet *ifp = &sc->sc_if;
|
||||
int i;
|
||||
|
||||
sc->sc_if.if_unit = sc->sc_dev.dv_unit;
|
||||
sc->sc_if.if_name = "fpa";
|
||||
sc->sc_if.if_flags = 0;
|
||||
sc->sc_membase = (pdq_bus_memaddr_t) mapphys((vm_offset_t)ia->ia_maddr, ia->ia_msize);
|
||||
|
||||
sc->sc_pdq = pdq_initialize(PDQ_BUS_PCI, sc->sc_membase,
|
||||
sc->sc_if.if_name, sc->sc_if.if_unit,
|
||||
(void *) sc, PDQ_DEFPA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("fpa%d: initialization failed\n", sc->sc_if.if_unit);
|
||||
return;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
|
||||
pdq_ifattach(sc, pdq_pci_ifwatchdog);
|
||||
|
||||
isa_establish(&sc->sc_id, &sc->sc_dev);
|
||||
|
||||
sc->sc_ih.ih_fun = pdq_pci_ifintr;
|
||||
sc->sc_ih.ih_arg = (void *)sc;
|
||||
intr_establish(ia->ia_irq, &sc->sc_ih, DV_NET);
|
||||
|
||||
sc->sc_ats.func = (void (*)(void *)) pdq_hwreset;
|
||||
sc->sc_ats.arg = (void *) sc->sc_pdq;
|
||||
atshutdown(&sc->sc_ats, ATSH_ADD);
|
||||
}
|
||||
|
||||
struct cfdriver fpacd = {
|
||||
0, "fpa", pdq_pci_probe, pdq_pci_attach,
|
||||
#if _BSDI_VERSION >= 199401
|
||||
DV_IFNET,
|
||||
#endif
|
||||
sizeof(pdq_softc_t)
|
||||
};
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
|
||||
static int
|
||||
pdq_pci_match(
|
||||
struct device *parent,
|
||||
void *match,
|
||||
void *aux)
|
||||
{
|
||||
struct pci_attach_args *pa = (struct pci_attach_args *) aux;
|
||||
|
||||
if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID)
|
||||
return 0;
|
||||
if (PCI_CHIPID(pa->pa_id) == DEFPA_CHIPID)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pdq_pci_attach(
|
||||
struct device * const parent,
|
||||
struct device * const self,
|
||||
void * const aux)
|
||||
{
|
||||
pdq_softc_t * const sc = (pdq_softc_t *) self;
|
||||
struct pci_attach_args * const pa = (struct pci_attach_args *) aux;
|
||||
pdq_uint32_t data;
|
||||
pci_intr_handle_t intrhandle;
|
||||
const char *intrstr;
|
||||
#ifdef PDQ_IOMAPPED
|
||||
bus_io_addr_t iobase;
|
||||
bus_io_size_t iosize;
|
||||
#else
|
||||
bus_mem_addr_t membase;
|
||||
bus_mem_size_t memsize;
|
||||
#endif
|
||||
|
||||
data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CFLT);
|
||||
if ((data & 0xFF00) < (DEFPA_LATENCY << 8)) {
|
||||
data &= ~0xFF00;
|
||||
data |= DEFPA_LATENCY << 8;
|
||||
pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_CFLT, data);
|
||||
}
|
||||
|
||||
sc->sc_bc = pa->pa_bc;
|
||||
bcopy(sc->sc_dev.dv_xname, sc->sc_if.if_xname, IFNAMSIZ);
|
||||
sc->sc_if.if_flags = 0;
|
||||
sc->sc_if.if_softc = sc;
|
||||
|
||||
#ifdef PDQ_IOMAPPED
|
||||
if (pci_io_find(pa->pa_pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize)
|
||||
|| bus_io_map(pa->pa_bc, iobase, iosize, &sc->sc_iobase))
|
||||
return;
|
||||
#else
|
||||
if (pci_mem_find(pa->pa_pc, pa->pa_tag, PCI_CBMA, &membase, &memsize, NULL)
|
||||
|| bus_mem_map(pa->pa_bc, membase, memsize, 0, &sc->sc_membase))
|
||||
return;
|
||||
#endif
|
||||
|
||||
sc->sc_pdq = pdq_initialize(sc->sc_bc, sc->sc_membase,
|
||||
sc->sc_if.if_xname, 0,
|
||||
(void *) sc, PDQ_DEFPA);
|
||||
if (sc->sc_pdq == NULL) {
|
||||
printf("%s: initialization failed\n", sc->sc_dev.dv_xname);
|
||||
return;
|
||||
}
|
||||
|
||||
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
|
||||
pdq_ifattach(sc, pdq_pci_ifwatchdog);
|
||||
|
||||
if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
|
||||
pa->pa_intrline, &intrhandle)) {
|
||||
printf("%s: couldn't map interrupt\n", self->dv_xname);
|
||||
return;
|
||||
}
|
||||
intrstr = pci_intr_string(pa->pa_pc, intrhandle);
|
||||
sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_NET, pdq_pci_ifintr, sc);
|
||||
if (sc->sc_ih == NULL) {
|
||||
printf("%s: couldn't establish interrupt", self->dv_xname);
|
||||
if (intrstr != NULL)
|
||||
printf(" at %s", intrstr);
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sc->sc_ats = shutdownhook_establish((void (*)(void *)) pdq_hwreset, sc->sc_pdq);
|
||||
if (sc->sc_ats == NULL)
|
||||
printf("%s: warning: couldn't establish shutdown hook\n", self->dv_xname);
|
||||
if (intrstr != NULL)
|
||||
printf("%s: interrupting at %s\n", self->dv_xname, intrstr);
|
||||
}
|
||||
|
||||
struct cfattach fpa_ca = {
|
||||
sizeof(pdq_softc_t), pdq_pci_match, pdq_pci_attach
|
||||
};
|
||||
|
||||
struct cfdriver fpa_cd = {
|
||||
0, "fpa", DV_IFNET
|
||||
};
|
||||
|
||||
#endif /* __NetBSD__ */
|
Loading…
Reference in New Issue
Block a user