summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormdodd <mdodd@FreeBSD.org>2002-06-03 09:16:52 +0000
committermdodd <mdodd@FreeBSD.org>2002-06-03 09:16:52 +0000
commit67912834859799368dba542bd95e8c42d02abe82 (patch)
treef602b11a3cb7ab78dbb421184db14467f248d166
parent50437cfa685a53287190566c1c3b89197e9d92a0 (diff)
downloadFreeBSD-src-67912834859799368dba542bd95e8c42d02abe82.zip
FreeBSD-src-67912834859799368dba542bd95e8c42d02abe82.tar.gz
Quick and dirty convert to newbus. (Eventually 'eni.c' should go away.)
Module loads and unloads properly. Thanks to Richard Hodges <rh@matriplex.com> for donating the hardware to allow me to work on this driver.
-rw-r--r--sys/dev/hea/eni.c39
-rw-r--r--sys/dev/hea/eni.h4
-rw-r--r--sys/dev/hea/eni_buffer.c5
-rw-r--r--sys/dev/hea/hea_freebsd.c357
-rw-r--r--sys/dev/hea/hea_freebsd.h59
-rw-r--r--sys/dev/hea/hea_pci.c224
6 files changed, 670 insertions, 18 deletions
diff --git a/sys/dev/hea/eni.c b/sys/dev/hea/eni.c
index 804eca3..d1b2ef3 100644
--- a/sys/dev/hea/eni.c
+++ b/sys/dev/hea/eni.c
@@ -47,6 +47,10 @@
#include <sys/syslog.h>
#include <sys/eventhandler.h>
#include <net/if.h>
+
+#include <sys/bus.h>
+#include <sys/conf.h>
+
#include <netatm/port.h>
#include <netatm/queue.h>
#include <netatm/atm.h>
@@ -58,6 +62,9 @@
#include <netatm/atm_pcb.h>
#include <netatm/atm_var.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
#include <dev/hea/eni_stats.h>
#include <dev/hea/eni.h>
#include <dev/hea/eni_var.h>
@@ -66,25 +73,26 @@
__RCSID("@(#) $FreeBSD$");
#endif
-#ifndef COMPAT_OLDPCI
-#error "The eni device requires the old pci compatibility shims"
-#endif
-
/*
* Typedef local functions
*/
+#if 0
static const char *eni_pci_probe(pcici_t, pcidi_t);
static void eni_pci_attach(pcici_t, int);
+#endif
static int eni_get_ack(Eni_unit *);
static int eni_get_sebyte(Eni_unit *);
-static void eni_read_seeprom(Eni_unit *);
+void eni_read_seeprom(Eni_unit *);
+#if 0
#if BSD < 199506
static int eni_pci_shutdown(struct kern_devconf *, int);
#else
static void eni_pci_shutdown(void *, int);
#endif
static void eni_pci_reset(Eni_unit *);
+#endif
+#if 0
/*
* Used by kernel to return number of claimed devices
*/
@@ -134,6 +142,7 @@ eni_pci_probe ( pcici_t config_id, pcidi_t device_id )
return ( NULL );
}
+#endif
/*
* The ENI-155p adapter uses an ATMEL AT24C01 serial EEPROM to store
@@ -149,8 +158,8 @@ eni_pci_probe ( pcici_t config_id, pcidi_t device_id )
*/
#define WRITE_SEEPROM() ( \
{ \
- (void) pci_conf_write ( eup->eu_pcitag, SEEPROM, \
- eup->eu_sevar ); \
+ (void) pci_write_config(eup->eu_pcitag, SEEPROM, \
+ eup->eu_sevar, 4); \
DELAY(SEPROM_DELAY); \
} \
)
@@ -216,7 +225,7 @@ eni_pci_probe ( pcici_t config_id, pcidi_t device_id )
*
*/
static int
-eni_get_ack ( eup )
+eni_get_ack (eup)
Eni_unit *eup;
{
int ack;
@@ -225,14 +234,14 @@ eni_get_ack ( eup )
/*
* Read DATA line from SEPROM
*/
- eup->eu_sevar = pci_conf_read ( eup->eu_pcitag, SEEPROM );
+ eup->eu_sevar = pci_read_config(eup->eu_pcitag, SEEPROM, 4);
DELAY ( SEPROM_DELAY );
ack = eup->eu_sevar & SEPROM_DATA;
eup->eu_sevar &= ~SEPROM_CLK;
- WRITE_SEEPROM ();
+ WRITE_SEEPROM();
eup->eu_sevar |= SEPROM_DATA;
- WRITE_SEEPROM ();
+ WRITE_SEEPROM();
return ( ack );
}
@@ -255,7 +264,7 @@ eni_get_ack ( eup )
*
*/
static int
-eni_get_sebyte( eup )
+eni_get_sebyte(eup)
Eni_unit *eup;
{
int i;
@@ -273,7 +282,7 @@ eni_get_sebyte( eup )
/*
* Read DATA line from SEPROM
*/
- data = pci_conf_read ( eup->eu_pcitag, SEEPROM );
+ data = pci_read_config(eup->eu_pcitag, SEEPROM, 4);
DELAY ( SEPROM_DELAY );
/* (Possibly) mask bit into accumulating value */
if ( data & SEPROM_DATA )
@@ -298,7 +307,7 @@ eni_get_sebyte( eup )
* none
*
*/
-static void
+void
eni_read_seeprom ( eup )
Eni_unit *eup;
{
@@ -352,6 +361,7 @@ eni_read_seeprom ( eup )
return;
}
+#if 0
/*
* The kernel has found a device which we are willing to support.
* We are now being called to do any necessary work to make the
@@ -687,3 +697,4 @@ eni_pci_shutdown ( eup, howto )
}
#endif /* BSD < 199506 */
#endif
+#endif
diff --git a/sys/dev/hea/eni.h b/sys/dev/hea/eni.h
index 76b4c9c..54bb04f 100644
--- a/sys/dev/hea/eni.h
+++ b/sys/dev/hea/eni.h
@@ -442,9 +442,7 @@ struct mbd {
*/
struct eni_unit {
Cmn_unit eu_cmn; /* Common unit stuff */
-#ifdef COMPAT_OLDPCI
- pcici_t eu_pcitag; /* PCI tag */
-#endif
+ void * eu_pcitag; /* PCI tag */
Eni_mem eu_base; /* Adapter memory base */
Eni_mem eu_ram; /* Adapter RAM */
u_long eu_ramsize;
diff --git a/sys/dev/hea/eni_buffer.c b/sys/dev/hea/eni_buffer.c
index d1946f0..026ce5d 100644
--- a/sys/dev/hea/eni_buffer.c
+++ b/sys/dev/hea/eni_buffer.c
@@ -38,7 +38,10 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/socket.h>
+#include <sys/malloc.h>
+
#include <net/if.h>
+
#include <netatm/port.h>
#include <netatm/queue.h>
#include <netatm/atm.h>
@@ -316,7 +319,7 @@ eni_allocate_buffer ( eup, size )
Mbd *etmp;
/* larger then we need - split it */
- etmp = (Mbd *)KM_ALLOC(sizeof(Mbd), M_DEVBUF, M_NOWAIT );
+ etmp = (Mbd *)malloc(sizeof(Mbd), M_DEVBUF, M_NOWAIT);
if ( etmp == (Mbd *)NULL ) {
/*
* Couldn't allocate new descriptor. Indicate
diff --git a/sys/dev/hea/hea_freebsd.c b/sys/dev/hea/hea_freebsd.c
new file mode 100644
index 0000000..c8b0f83
--- /dev/null
+++ b/sys/dev/hea/hea_freebsd.c
@@ -0,0 +1,357 @@
+/*-
+ * Copyright (c) 2002 Matthew N. Dodd <winter@jurai.net>
+ * 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. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ *
+ * ===================================
+ * HARP | Host ATM Research Platform
+ * ===================================
+ *
+ *
+ * This Host ATM Research Platform ("HARP") file (the "Software") is
+ * made available by Network Computing Services, Inc. ("NetworkCS")
+ * "AS IS". NetworkCS does not provide maintenance, improvements or
+ * support of any kind.
+ *
+ * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
+ * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
+ * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
+ * In no event shall NetworkCS be responsible for any damages, including
+ * but not limited to consequential damages, arising from or relating to
+ * any use of the Software or related support.
+ *
+ * Copyright 1994-1998 Network Computing Services, Inc.
+ *
+ * Copies of this Software may be made, however, the above copyright
+ * notice must be reproduced on all copies.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+
+#include <sys/bus.h>
+#include <sys/conf.h>
+
+#include <sys/module.h>
+#include <machine/bus_memio.h>
+#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
+
+#include <net/if.h>
+#include <netatm/port.h>
+#include <netatm/queue.h>
+#include <netatm/atm.h>
+#include <netatm/atm_sys.h>
+#include <netatm/atm_sap.h>
+#include <netatm/atm_cm.h>
+#include <netatm/atm_if.h>
+#include <netatm/atm_stack.h>
+#include <netatm/atm_pcb.h>
+#include <netatm/atm_var.h>
+
+#include <dev/hea/eni_stats.h>
+#include <dev/hea/eni.h>
+#include <dev/hea/eni_suni.h>
+#include <dev/hea/eni_var.h>
+
+#include <dev/hea/hea_freebsd.h>
+
+devclass_t hea_devclass;
+
+int
+hea_alloc (device_t dev)
+{
+ struct hea_softc *sc;
+ int error;
+
+ sc = (struct hea_softc *)device_get_softc(dev);
+ error = 0;
+
+ sc->mem = bus_alloc_resource(dev, sc->mem_type, &sc->mem_rid,
+ 0, ~0, 1, RF_ACTIVE);
+ if (sc->mem == NULL) {
+ device_printf(dev, "Unable to allocate memory resource.\n");
+ error = ENXIO;
+ goto fail;
+ }
+
+ sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
+ 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
+ if (sc->irq == NULL) {
+ device_printf(dev, "Unable to allocate interrupt resource.\n");
+ error = ENXIO;
+ goto fail;
+ }
+
+ mtx_init(&sc->mtx, device_get_nameunit(dev), "Interrupt lock", MTX_DEF|MTX_RECURSE);
+
+fail:
+ return (error);
+}
+
+int
+hea_free (device_t dev)
+{
+ struct hea_softc *sc;
+
+ sc = (struct hea_softc *)device_get_softc(dev);
+ if (sc->mem)
+ bus_release_resource(dev, sc->mem_type, sc->mem_rid, sc->mem);
+ if (sc->irq_ih)
+ bus_teardown_intr(dev, sc->irq, sc->irq_ih);
+ if (sc->irq)
+ bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq);
+
+ /*
+ * Destroy the mutex.
+ */
+ if (mtx_initialized(&sc->mtx) != 0)
+ mtx_destroy(&sc->mtx);
+
+ return (0);
+}
+
+int
+hea_attach (device_t dev)
+{
+ struct hea_softc *sc;
+ Eni_unit *eup;
+ int error;
+ long val;
+
+ sc = (struct hea_softc *)device_get_softc(dev);
+ eup = &sc->eup;
+ error = 0;
+
+ /*
+ * Start initializing it
+ */
+ eup->eu_unit = device_get_unit(dev);
+ eup->eu_mtu = ENI_IFF_MTU;
+ eup->eu_pcitag = dev;
+ eup->eu_ioctl = eni_atm_ioctl;
+ eup->eu_instvcc = eni_instvcc;
+ eup->eu_openvcc = eni_openvcc;
+ eup->eu_closevcc = eni_closevcc;
+ eup->eu_output = eni_output;
+ eup->eu_vcc_pool = &eni_vcc_pool;
+ eup->eu_nif_pool = &eni_nif_pool;
+
+ /*
+ * Map memory structures into adapter space
+ */
+ eup->eu_suni = (Eni_mem)(eup->eu_base + SUNI_OFFSET);
+ eup->eu_midway = (Eni_mem)(eup->eu_base + MIDWAY_OFFSET);
+ eup->eu_vcitbl = (VCI_Table *)(eup->eu_base + VCITBL_OFFSET);
+ eup->eu_rxdma = (Eni_mem)(eup->eu_base + RXQUEUE_OFFSET);
+ eup->eu_txdma = (Eni_mem)(eup->eu_base + TXQUEUE_OFFSET);
+ eup->eu_svclist = (Eni_mem)(eup->eu_base + SVCLIST_OFFSET);
+ eup->eu_servread = 0;
+
+ /*
+ * Reset the midway chip
+ */
+ eup->eu_midway[MIDWAY_ID] = MIDWAY_RESET;
+
+ /*
+ * Size and test adapter memory. Initialize our adapter memory
+ * allocater.
+ */
+ if (eni_init_memory(eup) < 0) {
+ /*
+ * Adapter memory test failed. Clean up and
+ * return.
+ */
+ device_printf(dev, "memory test failed.\n");
+ error = ENXIO;
+ goto fail;
+ }
+
+ /*
+ * Read the contents of the SEEPROM
+ */
+ eni_read_seeprom(eup);
+ /*
+ * Copy MAC address to PIF and config structures
+ */
+ bcopy((caddr_t)&eup->eu_seeprom[SEPROM_MAC_OFF],
+ (caddr_t)&eup->eu_pif.pif_macaddr,
+ sizeof(struct mac_addr));
+ eup->eu_config.ac_macaddr = eup->eu_pif.pif_macaddr;
+
+ /*
+ * Copy serial number into config space
+ */
+ eup->eu_config.ac_serial =
+ ntohl(*(u_long *)&eup->eu_seeprom[SEPROM_SN_OFF]);
+
+ /*
+ * Setup some of the adapter configuration
+ */
+ /*
+ * Get MIDWAY ID
+ */
+ val = eup->eu_midway[MIDWAY_ID];
+ eup->eu_config.ac_vendor = VENDOR_ENI;
+ eup->eu_config.ac_vendapi = VENDAPI_ENI_1;
+ eup->eu_config.ac_device = DEV_ENI_155P;
+ eup->eu_config.ac_media = val & MEDIA_MASK ? MEDIA_UTP155 : MEDIA_OC3C;
+ eup->eu_pif.pif_pcr = ATM_PCR_OC3C;
+
+ /*
+ * Make a hw version number from the ID register values.
+ * Format: {Midway ID}.{Mother board ID}.{Daughter board ID}
+ */
+ snprintf(eup->eu_config.ac_hard_vers,
+ sizeof(eup->eu_config.ac_hard_vers),
+ "%ld/%ld/%ld",
+ (val >> ID_SHIFT) & ID_MASK,
+ (val >> MID_SHIFT) & MID_MASK,
+ (val >> DID_SHIFT) & DID_MASK );
+
+ /*
+ * There is no software version number
+ */
+ eup->eu_config.ac_firm_vers[0] = '\0';
+
+ /*
+ * Save device ram info for user-level programs
+ * NOTE: This really points to start of EEPROM
+ * and includes all the device registers in the
+ * lower 2 Megabytes.
+ */
+ eup->eu_config.ac_ram = (long)eup->eu_base;
+ eup->eu_config.ac_ramsize = eup->eu_ramsize + ENI_REG_SIZE;
+
+ /*
+ * Setup max VPI/VCI values
+ */
+ eup->eu_pif.pif_maxvpi = ENI_MAX_VPI;
+ eup->eu_pif.pif_maxvci = ENI_MAX_VCI;
+
+ /*
+ * Register this interface with ATM core services
+ */
+ error = atm_physif_register((Cmn_unit *)eup, ENI_DEV_NAME, eni_services);
+ if (error)
+ goto fail;
+
+ eni_units[device_get_unit(dev)] = eup;
+
+ /*
+ * Initialize driver processing
+ */
+ error = eni_init(eup);
+ if (error) {
+ device_printf(dev, "adapter init failed.\n");
+ goto fail;
+ }
+
+fail:
+ return (error);
+}
+
+int
+hea_detach (device_t dev)
+{
+ struct hea_softc *sc;
+ Eni_unit *eup;
+ int error;
+
+ sc = (struct hea_softc *)device_get_softc(dev);
+ eup = &sc->eup;
+ error = 0;
+
+ /*
+ * De-Register this interface with ATM core services
+ */
+ error = atm_physif_deregister((Cmn_unit *)eup);
+
+ /*
+ * Reset the board.
+ */
+ hea_reset(dev);
+
+ hea_free(dev);
+
+ return (error);
+}
+
+void
+hea_intr (void * arg)
+{
+ struct hea_softc *sc;
+
+ sc = (struct hea_softc *)arg;
+
+ HEA_LOCK(sc);
+ eni_intr(&sc->eup);
+ HEA_UNLOCK(sc);
+
+ return;
+}
+
+void
+hea_reset (device_t dev)
+{
+ struct hea_softc *sc;
+ Eni_unit *eup;
+
+ sc = (struct hea_softc *)device_get_softc(dev);
+ eup = &sc->eup;
+
+ /*
+ * We should really close down any open VCI's and
+ * release all memory (TX and RX) buffers. For now,
+ * we assume we're shutting the card down for good.
+ */
+
+ if (eup->eu_midway) {
+ /*
+ * Issue RESET command to Midway chip
+ */
+ eup->eu_midway[MIDWAY_ID] = MIDWAY_RESET;
+
+ /*
+ * Delay to allow everything to terminate
+ */
+ DELAY(MIDWAY_DELAY);
+ }
+
+ return;
+}
diff --git a/sys/dev/hea/hea_freebsd.h b/sys/dev/hea/hea_freebsd.h
new file mode 100644
index 0000000..42e24ff
--- /dev/null
+++ b/sys/dev/hea/hea_freebsd.h
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 2002 Matthew N. Dodd <winter@jurai.net>
+ * 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. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD$
+ */
+
+struct hea_softc {
+ device_t dev;
+
+ struct resource * mem;
+ int mem_rid;
+ int mem_type;
+
+ struct resource * irq;
+ int irq_rid;
+ void * irq_ih;
+
+ struct mtx mtx;
+
+ Eni_unit eup;
+};
+
+#define HEA_LOCK(_sc) mtx_lock(&(_sc)->mtx)
+#define HEA_UNLOCK(_sc) mtx_unlock(&(_sc)->mtx)
+
+extern devclass_t hea_devclass;
+
+int hea_alloc (device_t);
+int hea_free (device_t);
+
+int hea_attach (device_t);
+int hea_detach (device_t);
+
+void hea_intr (void *);
+void hea_reset (device_t);
+
+void eni_read_seeprom(Eni_unit *);
diff --git a/sys/dev/hea/hea_pci.c b/sys/dev/hea/hea_pci.c
new file mode 100644
index 0000000..391db8b
--- /dev/null
+++ b/sys/dev/hea/hea_pci.c
@@ -0,0 +1,224 @@
+/*-
+ * Copyright (c) 2002 Matthew N. Dodd <winter@jurai.net>
+ * 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. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ *
+ * ===================================
+ * HARP | Host ATM Research Platform
+ * ===================================
+ *
+ *
+ * This Host ATM Research Platform ("HARP") file (the "Software") is
+ * made available by Network Computing Services, Inc. ("NetworkCS")
+ * "AS IS". NetworkCS does not provide maintenance, improvements or
+ * support of any kind.
+ *
+ * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
+ * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
+ * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
+ * In no event shall NetworkCS be responsible for any damages, including
+ * but not limited to consequential damages, arising from or relating to
+ * any use of the Software or related support.
+ *
+ * Copyright 1994-1998 Network Computing Services, Inc.
+ *
+ * Copies of this Software may be made, however, the above copyright
+ * notice must be reproduced on all copies.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+
+#include <sys/bus.h>
+#include <sys/conf.h>
+
+#include <sys/module.h>
+#include <machine/bus_memio.h>
+#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
+
+#include <net/if.h>
+#include <netatm/port.h>
+#include <netatm/queue.h>
+#include <netatm/atm.h>
+#include <netatm/atm_sys.h>
+#include <netatm/atm_sap.h>
+#include <netatm/atm_cm.h>
+#include <netatm/atm_if.h>
+#include <netatm/atm_stack.h>
+#include <netatm/atm_pcb.h>
+#include <netatm/atm_var.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#include <dev/hea/eni_stats.h>
+#include <dev/hea/eni.h>
+#include <dev/hea/eni_suni.h>
+#include <dev/hea/eni_var.h>
+
+#include <dev/hea/hea_freebsd.h>
+
+static int hea_pci_probe(device_t);
+static int hea_pci_attach(device_t);
+
+#define ENI_VENDORID 0x111A
+#define ENI_DEVICEID 0x0002
+
+struct hea_pci_type {
+ u_int16_t vid;
+ u_int16_t did;
+ char * name;
+} hea_pci_devs[] = {
+ { ENI_VENDORID, ENI_DEVICEID, "Efficent Networks ENI ATM Adapter" },
+ { 0, 0, NULL },
+};
+
+static int
+hea_pci_probe (dev)
+ device_t dev;
+{
+ struct hea_pci_type * t = hea_pci_devs;
+
+ while (t->name != NULL) {
+ if ((pci_get_vendor(dev) == t->vid) &&
+ (pci_get_device(dev) == t->did)) {
+ device_set_desc(dev, t->name);
+ return(0);
+ }
+ t++;
+ }
+
+ return(ENXIO);
+}
+
+static int
+hea_pci_attach (dev)
+ device_t dev;
+{
+ struct hea_softc *sc;
+ Eni_unit *eup;
+ u_int32_t command;
+ vm_offset_t va;
+ int error;
+
+ sc = device_get_softc(dev);
+ eup = &sc->eup;
+ error = 0;
+
+ pci_enable_busmaster(dev);
+ pci_enable_io(dev, SYS_RES_MEMORY);
+
+ command = pci_read_config(dev, PCIR_COMMAND, 2);
+ if ((command & PCIM_CMD_BUSMASTEREN) == 0) {
+ device_printf(dev, "Unable to enable PCI busmastering.\n");
+ error = ENXIO;
+ goto fail;
+ }
+ if ((command & PCIM_CMD_MEMEN) == 0) {
+ device_printf(dev, "Unable to enable PCI memory resources.\n");
+ error = ENXIO;
+ goto fail;
+ }
+
+ sc->mem_rid = PCIR_MAPS;
+ sc->mem_type = SYS_RES_MEMORY;
+ sc->irq_rid = 0;
+
+ error = hea_alloc(dev);
+ if (error) {
+ device_printf(dev, "hea_alloc() failed.\n");
+ goto fail;
+ }
+
+ va = (vm_offset_t) rman_get_virtual(sc->mem);
+
+ eup->eu_base = (Eni_mem)va;
+ eup->eu_ram = (Eni_mem)(eup->eu_base + RAM_OFFSET);
+
+ /*
+ * Convert Endianess on DMA
+ */
+ command = pci_read_config(dev, PCI_CONTROL_REG, 4);
+ command |= ENDIAN_SWAP_DMA;
+ pci_write_config(dev, PCI_CONTROL_REG, command, 4);
+
+ /*
+ * Map interrupt in
+ */
+ error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
+ hea_intr, sc, &sc->irq_ih);
+ if (error) {
+ device_printf(dev, "Interrupt handler setup failed.\n");
+ goto fail;
+ }
+
+ eup->eu_config.ac_bustype = BUS_PCI;
+ eup->eu_config.ac_busslot = (pci_get_bus(dev) << 8)| pci_get_slot(dev);
+
+ error = hea_attach(dev);
+ if (error) {
+ device_printf(dev, "hea_attach() failed.\n");
+ goto fail;
+ }
+
+ return (0);
+fail:
+
+ hea_detach(dev);
+
+ return (error);
+}
+
+static device_method_t hea_pci_methods[] = {
+ DEVMETHOD(device_probe, hea_pci_probe),
+ DEVMETHOD(device_attach, hea_pci_attach),
+
+ DEVMETHOD(device_detach, hea_detach),
+
+ { 0, 0 }
+};
+
+static driver_t hea_pci_driver = {
+ "hea",
+ hea_pci_methods,
+ sizeof(struct hea_softc)
+};
+
+DRIVER_MODULE(hea, pci, hea_pci_driver, hea_devclass, 0, 0);
+MODULE_DEPEND(hea, pci, 1, 1, 1);
OpenPOWER on IntegriCloud