1997-01-17 23:19:49 +00:00
|
|
|
/*-
|
|
|
|
* 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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1997-01-17 23:19:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DEC PDQ FDDI Controller
|
|
|
|
*
|
|
|
|
* This module support the DEFEA EISA FDDI Controller.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1999-07-10 19:46:08 +00:00
|
|
|
#include <sys/systm.h>
|
1997-01-17 23:19:49 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
2002-03-29 11:22:22 +00:00
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
2002-03-29 11:22:22 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/fddi.h>
|
|
|
|
|
2000-01-14 07:14:17 +00:00
|
|
|
#include <dev/eisa/eisaconf.h>
|
2002-03-29 11:22:22 +00:00
|
|
|
|
|
|
|
#include <dev/pdq/pdq_freebsd.h>
|
1997-01-17 23:19:49 +00:00
|
|
|
#include <dev/pdq/pdqreg.h>
|
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static void pdq_eisa_subprobe (pdq_bus_t, u_int32_t, u_int32_t *, u_int32_t *, u_int32_t *);
|
|
|
|
static void pdq_eisa_devinit (pdq_softc_t *);
|
|
|
|
static const char * pdq_eisa_match (eisa_id_t);
|
2002-03-29 11:22:22 +00:00
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static int pdq_eisa_probe (device_t);
|
|
|
|
static int pdq_eisa_attach (device_t);
|
2002-03-29 11:22:22 +00:00
|
|
|
static int pdq_eisa_detach (device_t);
|
2002-03-20 02:08:01 +00:00
|
|
|
static int pdq_eisa_shutdown (device_t);
|
2002-03-29 11:22:22 +00:00
|
|
|
static void pdq_eisa_ifintr (void *);
|
1997-01-17 23:19:49 +00:00
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
#define DEFEA_IRQS 0x0000FBA9U
|
1997-01-17 23:19:49 +00:00
|
|
|
|
|
|
|
#define DEFEA_INTRENABLE 0x8 /* level interrupt */
|
|
|
|
#define DEFEA_DECODE_IRQ(n) ((DEFEA_IRQS >> ((n) << 2)) & 0x0f)
|
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
#define EISA_DEVICE_ID_DEC_DEC3001 0x10a33001
|
|
|
|
#define EISA_DEVICE_ID_DEC_DEC3002 0x10a33002
|
|
|
|
#define EISA_DEVICE_ID_DEC_DEC3003 0x10a33003
|
|
|
|
#define EISA_DEVICE_ID_DEC_DEC3004 0x10a33004
|
1997-01-17 23:19:49 +00:00
|
|
|
|
|
|
|
static void
|
1999-07-10 19:46:08 +00:00
|
|
|
pdq_eisa_subprobe(bc, iobase, maddr, msize, irq)
|
|
|
|
pdq_bus_t bc;
|
|
|
|
u_int32_t iobase;
|
|
|
|
u_int32_t *maddr;
|
|
|
|
u_int32_t *msize;
|
|
|
|
u_int32_t *irq;
|
1997-01-17 23:19:49 +00:00
|
|
|
{
|
1999-07-10 19:46:08 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
return;
|
1997-01-17 23:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-07-10 19:46:08 +00:00
|
|
|
pdq_eisa_devinit (sc)
|
|
|
|
pdq_softc_t *sc;
|
1997-01-17 23:19:49 +00:00
|
|
|
{
|
1999-07-10 19:46:08 +00:00
|
|
|
pdq_uint8_t data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the standard initialization for the DEFEA registers.
|
|
|
|
*/
|
2002-03-29 11:22:22 +00:00
|
|
|
PDQ_OS_IOWR_8(sc->io_bst, sc->io_bsh, PDQ_EISA_FUNCTION_CTRL, 0x23);
|
|
|
|
PDQ_OS_IOWR_8(sc->io_bst, sc->io_bsh, PDQ_EISA_IO_CMP_1_1, (sc->io_bsh >> 8) & 0xF0);
|
|
|
|
PDQ_OS_IOWR_8(sc->io_bst, sc->io_bsh, PDQ_EISA_IO_CMP_0_1, (sc->io_bsh >> 8) & 0xF0);
|
|
|
|
PDQ_OS_IOWR_8(sc->io_bst, sc->io_bsh, PDQ_EISA_SLOT_CTRL, 0x01);
|
|
|
|
data = PDQ_OS_IORD_8(sc->io_bst, sc->io_bsh, PDQ_EISA_BURST_HOLDOFF);
|
1997-01-17 23:19:49 +00:00
|
|
|
#if defined(PDQ_IOMAPPED)
|
2002-03-29 11:22:22 +00:00
|
|
|
PDQ_OS_IOWR_8(sc->io_bst, sc->io_bsh, PDQ_EISA_BURST_HOLDOFF, data & ~1);
|
1997-01-17 23:19:49 +00:00
|
|
|
#else
|
2002-03-29 11:22:22 +00:00
|
|
|
PDQ_OS_IOWR_8(sc->io_bst, sc->io_bsh, PDQ_EISA_BURST_HOLDOFF, data | 1);
|
1997-01-17 23:19:49 +00:00
|
|
|
#endif
|
2002-03-29 11:22:22 +00:00
|
|
|
data = PDQ_OS_IORD_8(sc->io_bst, sc->io_bsh, PDQ_EISA_IO_CONFIG_STAT_0);
|
|
|
|
PDQ_OS_IOWR_8(sc->io_bst, sc->io_bsh, PDQ_EISA_IO_CONFIG_STAT_0, data | DEFEA_INTRENABLE);
|
1997-01-17 23:19:49 +00:00
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
return;
|
|
|
|
}
|
1997-01-17 23:19:49 +00:00
|
|
|
|
1997-09-14 11:28:30 +00:00
|
|
|
static const char *
|
1999-07-10 19:46:08 +00:00
|
|
|
pdq_eisa_match (type)
|
|
|
|
eisa_id_t type;
|
1997-01-17 23:19:49 +00:00
|
|
|
{
|
1999-07-10 19:46:08 +00:00
|
|
|
switch (type) {
|
|
|
|
case EISA_DEVICE_ID_DEC_DEC3001:
|
|
|
|
case EISA_DEVICE_ID_DEC_DEC3002:
|
|
|
|
case EISA_DEVICE_ID_DEC_DEC3003:
|
|
|
|
case EISA_DEVICE_ID_DEC_DEC3004:
|
|
|
|
return ("DEC FDDIcontroller/EISA Adapter");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (NULL);
|
1997-01-17 23:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-07-10 19:46:08 +00:00
|
|
|
pdq_eisa_probe (dev)
|
|
|
|
device_t dev;
|
1997-01-17 23:19:49 +00:00
|
|
|
{
|
1999-07-10 19:46:08 +00:00
|
|
|
const char *desc;
|
|
|
|
u_int32_t iobase;
|
|
|
|
u_int32_t irq;
|
|
|
|
u_int32_t maddr;
|
|
|
|
u_int32_t msize;
|
|
|
|
|
|
|
|
u_int32_t eisa_id = eisa_get_id(dev);;
|
|
|
|
|
|
|
|
desc = pdq_eisa_match(eisa_id);
|
|
|
|
if (!desc) {
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
1997-01-17 23:19:49 +00:00
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
device_set_desc(dev, desc);
|
1997-01-17 23:19:49 +00:00
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
iobase = eisa_get_slot(dev) * EISA_SLOT_SIZE;
|
2002-03-29 11:22:22 +00:00
|
|
|
pdq_eisa_subprobe(SYS_RES_IOPORT, iobase, &maddr, &msize, &irq);
|
1997-01-17 23:19:49 +00:00
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
eisa_add_iospace(dev, iobase, 0x200, RESVADDR_NONE);
|
|
|
|
eisa_add_mspace(dev, maddr, msize, RESVADDR_NONE);
|
1999-08-01 22:57:09 +00:00
|
|
|
eisa_add_intr(dev, irq, EISA_TRIGGER_LEVEL);
|
1999-07-10 19:46:08 +00:00
|
|
|
|
|
|
|
return (0);
|
1997-01-17 23:19:49 +00:00
|
|
|
}
|
|
|
|
|
2002-03-29 11:22:22 +00:00
|
|
|
static void
|
|
|
|
pdq_eisa_ifintr(arg)
|
|
|
|
void * arg;
|
1997-01-17 23:19:49 +00:00
|
|
|
{
|
2002-03-29 11:22:22 +00:00
|
|
|
device_t dev;
|
|
|
|
pdq_softc_t * sc;
|
|
|
|
|
|
|
|
dev = (device_t)arg;
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
PDQ_LOCK(sc);
|
1999-07-10 19:46:08 +00:00
|
|
|
(void) pdq_interrupt(sc->sc_pdq);
|
2002-03-29 11:22:22 +00:00
|
|
|
PDQ_LOCK(sc);
|
1997-09-21 21:35:24 +00:00
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
return;
|
1997-01-17 23:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-07-10 19:46:08 +00:00
|
|
|
pdq_eisa_attach (dev)
|
2002-03-29 11:22:22 +00:00
|
|
|
device_t dev;
|
1997-01-17 23:19:49 +00:00
|
|
|
{
|
2002-03-29 11:22:22 +00:00
|
|
|
pdq_softc_t * sc;
|
|
|
|
struct ifnet * ifp;
|
|
|
|
int error;
|
1997-01-17 23:19:49 +00:00
|
|
|
|
2002-03-29 11:22:22 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
1997-01-17 23:19:49 +00:00
|
|
|
|
2002-03-29 11:22:22 +00:00
|
|
|
sc->dev = dev;
|
|
|
|
|
|
|
|
sc->io_rid = 0;
|
|
|
|
sc->io_type = SYS_RES_IOPORT;
|
|
|
|
sc->io = bus_alloc_resource(dev, sc->io_type, &sc->io_rid,
|
|
|
|
0, ~0, 1, RF_ACTIVE);
|
|
|
|
if (!sc->io) {
|
|
|
|
device_printf(dev, "Unable to allocate I/O space resource.\n");
|
|
|
|
error = ENXIO;
|
1999-07-10 19:46:08 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2002-03-29 11:22:22 +00:00
|
|
|
sc->io_bsh = rman_get_bushandle(sc->io);
|
|
|
|
sc->io_bst = rman_get_bustag(sc->io);
|
|
|
|
|
|
|
|
sc->mem_rid = 0;
|
|
|
|
sc->mem_type = SYS_RES_MEMORY;
|
|
|
|
sc->mem = bus_alloc_resource(dev, sc->mem_type, &sc->mem_rid,
|
|
|
|
0, ~0, 1, RF_ACTIVE);
|
|
|
|
if (!sc->mem) {
|
|
|
|
device_printf(dev, "Unable to allocate memory resource.\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
sc->mem_bsh = rman_get_bushandle(sc->mem);
|
|
|
|
sc->mem_bst = rman_get_bustag(sc->mem);
|
|
|
|
|
|
|
|
sc->irq_rid = 0;
|
|
|
|
sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
|
|
|
|
0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
if (!sc->irq) {
|
|
|
|
device_printf(dev, "Unable to allocate interrupt resource.\n");
|
|
|
|
error = ENXIO;
|
1999-07-10 19:46:08 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1997-01-17 23:19:49 +00:00
|
|
|
|
2002-03-29 11:22:22 +00:00
|
|
|
ifp->if_name = "fea";
|
|
|
|
ifp->if_unit = device_get_unit(dev);
|
1999-07-10 19:46:08 +00:00
|
|
|
|
|
|
|
pdq_eisa_devinit(sc);
|
2002-03-29 11:22:22 +00:00
|
|
|
sc->sc_pdq = pdq_initialize(sc->mem_bst, sc->mem_bsh,
|
|
|
|
ifp->if_name, ifp->if_unit,
|
|
|
|
(void *)sc, PDQ_DEFEA);
|
1999-07-10 19:46:08 +00:00
|
|
|
if (sc->sc_pdq == NULL) {
|
2002-03-29 11:22:22 +00:00
|
|
|
device_printf(dev, "Initialization failed.\n");
|
|
|
|
error = ENXIO;
|
1999-07-10 19:46:08 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1997-01-17 23:19:49 +00:00
|
|
|
|
2002-03-29 11:22:22 +00:00
|
|
|
error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
|
|
|
|
pdq_eisa_ifintr, dev, &sc->irq_ih);
|
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "Failed to setup interrupt handler.\n");
|
|
|
|
error = ENXIO;
|
1999-07-10 19:46:08 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1997-01-17 23:19:49 +00:00
|
|
|
|
2002-03-29 11:22:22 +00:00
|
|
|
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes,
|
|
|
|
(caddr_t) sc->arpcom.ac_enaddr, FDDI_ADDR_LEN);
|
|
|
|
pdq_ifattach(sc);
|
1997-01-17 23:19:49 +00:00
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
return (0);
|
|
|
|
bad:
|
2002-03-29 11:22:22 +00:00
|
|
|
pdq_free(dev);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pdq_eisa_detach (dev)
|
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
pdq_softc_t * sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
pdq_ifdetach(sc);
|
|
|
|
|
|
|
|
return (0);
|
1997-01-17 23:19:49 +00:00
|
|
|
}
|
|
|
|
|
1999-07-31 00:43:48 +00:00
|
|
|
static int
|
|
|
|
pdq_eisa_shutdown(dev)
|
|
|
|
device_t dev;
|
1997-01-17 23:19:49 +00:00
|
|
|
{
|
2002-03-29 11:22:22 +00:00
|
|
|
pdq_softc_t * sc;
|
1999-07-31 00:43:48 +00:00
|
|
|
|
2002-03-29 11:22:22 +00:00
|
|
|
sc = device_get_softc(dev);
|
1999-07-31 00:43:48 +00:00
|
|
|
pdq_hwreset(sc->sc_pdq);
|
|
|
|
|
|
|
|
return (0);
|
1997-01-17 23:19:49 +00:00
|
|
|
}
|
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
static device_method_t pdq_eisa_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, pdq_eisa_probe),
|
|
|
|
DEVMETHOD(device_attach, pdq_eisa_attach),
|
2002-03-29 11:22:22 +00:00
|
|
|
DEVMETHOD(device_attach, pdq_eisa_detach),
|
1999-07-31 00:43:48 +00:00
|
|
|
DEVMETHOD(device_shutdown, pdq_eisa_shutdown),
|
1999-07-10 19:46:08 +00:00
|
|
|
|
|
|
|
{ 0, 0 }
|
1997-01-17 23:19:49 +00:00
|
|
|
};
|
|
|
|
|
1999-07-10 19:46:08 +00:00
|
|
|
static driver_t pdq_eisa_driver = {
|
|
|
|
"fea",
|
|
|
|
pdq_eisa_methods,
|
|
|
|
sizeof(pdq_softc_t),
|
1997-01-17 23:19:49 +00:00
|
|
|
};
|
1999-07-10 19:46:08 +00:00
|
|
|
|
2002-03-29 11:22:22 +00:00
|
|
|
DRIVER_MODULE(if_fea, eisa, pdq_eisa_driver, pdq_devclass, 0, 0);
|
|
|
|
/* MODULE_DEPEND(if_fea, eisa, 1, 1, 1); */
|
|
|
|
MODULE_DEPEND(if_fea, fddi, 1, 1, 1);
|