Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pcmcia IBM Tropic Token Ring PCMCIA attachment. XXX ...



details:   https://anonhg.NetBSD.org/src/rev/09820814c851
branches:  trunk
changeset: 487850:09820814c851
user:      soren <soren%NetBSD.org@localhost>
date:      Tue Jun 13 20:03:47 2000 +0000

description:
IBM Tropic Token Ring PCMCIA attachment. XXX Needs work.
Many thanks to Onno van der Linden for his help in getting this working.

diffstat:

 sys/dev/pcmcia/if_tr_pcmcia.c |  313 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 313 insertions(+), 0 deletions(-)

diffs (truncated from 317 to 300 lines):

diff -r 11c96083b0ce -r 09820814c851 sys/dev/pcmcia/if_tr_pcmcia.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pcmcia/if_tr_pcmcia.c     Tue Jun 13 20:03:47 2000 +0000
@@ -0,0 +1,313 @@
+/*     $NetBSD: if_tr_pcmcia.c,v 1.1 2000/06/13 20:03:47 soren Exp $   */
+
+/*
+ * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
+ * Copyright (c) 2000 Onno van der Linden.  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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *  This product includes software developed by Manuel Bouyer.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without 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.
+ */
+
+/*
+ * PCMCIA attachment for the following Tropic-based cards.
+ *
+ * o IBM Token Ring 16/4 Credit Card Adapter
+ * o IBM Token Ring Auto 16/4 Credit Card Adapter
+ * o IBM Turbo 16/4 Token Ring PC Card
+ */
+
+#include "opt_inet.h"
+#include "opt_ns.h"
+#include "bpfilter.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/callout.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+#include <sys/syslog.h>
+#include <sys/select.h>
+#include <sys/device.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_ether.h>
+#include <net/if_media.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#include <net/bpfdesc.h>
+#endif
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/ic/tropicreg.h>
+#include <dev/ic/tropicvar.h>
+
+#include <dev/pcmcia/pcmciareg.h>
+#include <dev/pcmcia/pcmciavar.h>
+#include <dev/pcmcia/pcmciadevs.h>
+
+#define TR_SRAM_SIZE   (16 * 1024)     /* Really 64KB, but conserve iomem. */
+
+/*
+ * XXX How do host/PCMCIA/cbb memory spaces actually relate?
+ */
+#ifndef TR_PCMCIA_SRAM_ADDR
+#define TR_PCMCIA_SRAM_ADDR    0xc8000
+#endif
+#ifndef TR_PCMCIA_MMIO_ADDR
+#define TR_PCMCIA_MMIO_ADDR    0xcc000
+#endif
+
+struct tr_pcmcia_softc {
+       struct  tr_softc sc_tr;
+
+       struct  pcmcia_io_handle sc_pioh;
+       int     sc_pio_window;
+       struct  pcmcia_mem_handle sc_sramh;
+       int     sc_sram_window;
+       struct  pcmcia_mem_handle sc_mmioh;
+       int     sc_mmio_window;
+       struct  pcmcia_function *sc_pf;
+};
+
+static int     tr_pcmcia_match(struct device *, struct cfdata *, void *);
+static void    tr_pcmcia_attach(struct device *, struct device *, void *);
+static int     tr_pcmcia_detach(struct device *, int);
+static int     tr_pcmcia_enable(struct tr_softc *);
+static void    tr_pcmcia_disable(struct tr_softc *);
+static void    tr_pcmcia_setup(struct tr_softc *);
+
+struct cfattach tr_pcmcia_ca = {
+       sizeof(struct tr_pcmcia_softc),
+       tr_pcmcia_match,
+       tr_pcmcia_attach,
+       tr_pcmcia_detach,
+       tr_activate
+};
+
+static int
+tr_pcmcia_match(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void *aux;
+{
+       struct pcmcia_attach_args *pa = aux;
+
+       if (pa->manufacturer == PCMCIA_VENDOR_IBM)
+               switch (pa->product) {
+               case PCMCIA_PRODUCT_IBM_TROPIC:
+                       return 1;
+               }
+
+       return 0;
+}
+
+static void
+tr_pcmcia_attach(parent, self, aux)
+       struct device *parent;
+       struct device *self;
+       void *aux;
+{
+       struct tr_pcmcia_softc *psc = (void *)self;
+       struct tr_softc *sc = &psc->sc_tr;
+       struct pcmcia_attach_args *pa = aux;
+       struct pcmcia_config_entry *cfe;
+       bus_addr_t offset;
+
+       psc->sc_pf = pa->pf;
+       cfe = pa->pf->cfe_head.sqh_first;
+
+       pcmcia_function_init(pa->pf, cfe);
+
+       if (pcmcia_function_enable(pa->pf) != 0) {
+               printf(": function enable failed\n");
+               return;
+       }
+
+       if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
+           cfe->iospace[0].length, cfe->iospace[0].length, &psc->sc_pioh) != 0)
+               printf(": can't allocate pio space\n");
+       if (pcmcia_io_map(psc->sc_pf, PCMCIA_WIDTH_IO8, 0,      /* XXX _AUTO? */
+           cfe->iospace[0].length, &psc->sc_pioh, &psc->sc_pio_window) != 0) {
+               printf(": can't map pio space\n");
+               pcmcia_io_free(psc->sc_pf, &psc->sc_pioh);
+               return;
+       }
+
+       if (pcmcia_mem_alloc(psc->sc_pf, TR_SRAM_SIZE, &psc->sc_sramh) != 0) {
+           printf(": can't allocate sram space\n");
+               pcmcia_io_unmap(psc->sc_pf, psc->sc_pio_window);
+               pcmcia_io_free(psc->sc_pf, &psc->sc_pioh);
+               return;
+       }
+        if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_COMMON, TR_PCMCIA_SRAM_ADDR,
+           TR_SRAM_SIZE, &psc->sc_sramh, &offset, &psc->sc_sram_window) != 0) {
+                printf(": can't map sram space\n");
+               pcmcia_mem_free(psc->sc_pf, &psc->sc_sramh);
+               pcmcia_io_unmap(psc->sc_pf, psc->sc_pio_window);
+               pcmcia_io_free(psc->sc_pf, &psc->sc_pioh);
+                return;
+        }
+
+       if (pcmcia_mem_alloc(psc->sc_pf, TR_MMIO_SIZE, &psc->sc_mmioh) != 0) {
+               pcmcia_mem_unmap(psc->sc_pf, psc->sc_sram_window);
+               pcmcia_mem_free(psc->sc_pf, &psc->sc_sramh);
+               pcmcia_io_unmap(psc->sc_pf, psc->sc_pio_window);
+               pcmcia_io_free(psc->sc_pf, &psc->sc_pioh);
+               printf(": can't allocate mmio space\n");
+               return;
+       }
+        if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_COMMON, TR_PCMCIA_MMIO_ADDR,
+           TR_MMIO_SIZE, &psc->sc_mmioh, &offset, &psc->sc_mmio_window) != 0) {
+               pcmcia_mem_free(psc->sc_pf, &psc->sc_mmioh);
+               pcmcia_mem_unmap(psc->sc_pf, psc->sc_sram_window);
+               pcmcia_mem_free(psc->sc_pf, &psc->sc_sramh);
+               pcmcia_io_unmap(psc->sc_pf, psc->sc_pio_window);
+               pcmcia_io_free(psc->sc_pf, &psc->sc_pioh);
+                printf(": can't map mmio space\n");
+                return;
+        }
+
+       sc->sc_piot = psc->sc_pioh.iot;
+       sc->sc_pioh = psc->sc_pioh.ioh;
+        sc->sc_memt = psc->sc_sramh.memt;
+        sc->sc_sramh = psc->sc_sramh.memh;
+        sc->sc_mmioh = psc->sc_mmioh.memh;
+        sc->sc_memwinsz = TR_SRAM_SIZE;
+        sc->sc_memsize = TR_SRAM_SIZE;
+        sc->sc_memreserved = 0;
+        sc->sc_aca = TR_ACA_OFFSET;
+       sc->sc_maddr = TR_PCMCIA_SRAM_ADDR;
+       sc->sc_mediastatus = NULL;
+       sc->sc_mediachange = NULL;
+       sc->sc_enable = tr_pcmcia_enable;
+       sc->sc_disable = tr_pcmcia_disable;
+
+       printf(": %s\n", PCMCIA_STR_IBM_TROPIC);
+
+       tr_pcmcia_setup(sc);
+       if (tr_reset(sc) == 0)
+               (void)tr_attach(sc);
+
+       pcmcia_function_disable(pa->pf);
+       sc->sc_enabled = 0;
+}
+
+static int
+tr_pcmcia_enable(sc)
+       struct tr_softc *sc;
+{
+       struct tr_pcmcia_softc *psc = (struct tr_pcmcia_softc *) sc;
+       int ret;
+
+       sc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, tr_intr, psc);
+       if (sc->sc_ih == NULL) {
+               printf("%s: couldn't establish interrupt\n",
+                       psc->sc_tr.sc_dev.dv_xname);
+               return 1;
+       }
+
+        ret = pcmcia_function_enable(psc->sc_pf);
+       if (ret != 0)
+               return ret;
+
+       tr_pcmcia_setup(sc);
+
+       if (tr_reset(sc))
+               return 1;
+       if (tr_config(sc))
+               return 1;
+
+       return 0;
+}
+
+static void
+tr_pcmcia_disable(sc)
+       struct tr_softc *sc;
+{
+       struct tr_pcmcia_softc *psc = (struct tr_pcmcia_softc *) sc;
+
+       pcmcia_function_disable(psc->sc_pf);
+       pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
+}
+
+int
+tr_pcmcia_detach(self, flags)
+       struct device *self;
+       int flags;
+{
+       struct tr_pcmcia_softc *psc = (struct tr_pcmcia_softc *)self;
+       int rv;
+
+       rv = tr_detach(self, flags);
+
+       if (rv == 0) { 
+               pcmcia_mem_unmap(psc->sc_pf, psc->sc_mmio_window);
+               pcmcia_mem_free(psc->sc_pf, &psc->sc_mmioh);
+               pcmcia_mem_unmap(psc->sc_pf, psc->sc_sram_window);
+               pcmcia_mem_free(psc->sc_pf, &psc->sc_sramh);
+               pcmcia_io_unmap(psc->sc_pf, psc->sc_pio_window);
+               pcmcia_io_free(psc->sc_pf, &psc->sc_pioh);
+       }
+
+       return rv;
+}
+
+static void
+tr_pcmcia_setup(sc)



Home | Main Index | Thread Index | Old Index