Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pcmcia add Xircom 16-bit PCMCIA driver (from OpenBSD)



details:   https://anonhg.NetBSD.org/src/rev/056a61a0adfc
branches:  trunk
changeset: 480336:056a61a0adfc
user:      joda <joda%NetBSD.org@localhost>
date:      Sun Jan 09 17:10:43 2000 +0000

description:
add Xircom 16-bit PCMCIA driver (from OpenBSD)

diffstat:

 sys/dev/pcmcia/if_xe.c    |  1592 +++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pcmcia/if_xereg.h |   305 ++++++++
 2 files changed, 1897 insertions(+), 0 deletions(-)

diffs (truncated from 1905 to 300 lines):

diff -r f33d9274555b -r 056a61a0adfc sys/dev/pcmcia/if_xe.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pcmcia/if_xe.c    Sun Jan 09 17:10:43 2000 +0000
@@ -0,0 +1,1592 @@
+/*     $OpenBSD: if_xe.c,v 1.9 1999/09/16 11:28:42 niklas Exp $        */
+
+/*
+ * Copyright (c) 1999 Niklas Hallqvist, C Stone, Job de Haas
+ * 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 Niklas Hallqvist,
+ *     C Stone and Job de Haas.
+ * 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.
+ */
+
+/*
+ * A driver for Xircom ethernet PC-cards.
+ *
+ * The driver has been inspired by the xirc2ps_cs.c driver found in Linux'
+ * PCMCIA package written by Werner Koch <werner.koch%guug.de@localhost>:
+ * [xirc2ps_cs.c wk 14.04.97] (1.31 1998/12/09 19:32:55)
+ * I will note that no code was used verbatim from that driver as it is under
+ * the much too strong GNU General Public License, it was only used as a
+ * "specification" of sorts.
+ * Other inspirations have been if_fxp.c, if_ep_pcmcia.c and elink3.c as
+ * they were found in OpenBSD 2.4.
+ */
+
+#include "bpfilter.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/ioctl.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/syslog.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_types.h>
+
+#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
+
+#ifdef IPX
+#include <netipx/ipx.h>
+#include <netipx/ipx_if.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
+
+#define ETHER_MIN_LEN 64
+#define ETHER_CRC_LEN 4
+
+/*
+ * Maximum number of bytes to read per interrupt.  Linux recommends
+ * somewhere between 2000-22000.
+ * XXX This is currently a hard maximum.
+ */
+#define MAX_BYTES_INTR 12000
+
+#include <dev/mii/miivar.h>
+
+#include <dev/pcmcia/pcmciareg.h>
+#include <dev/pcmcia/pcmciavar.h>
+#include <dev/pcmcia/pcmciadevs.h>
+#include <dev/pcmcia/if_xereg.h>
+
+#ifdef __GNUC__
+#define INLINE __inline
+#else
+#define INLINE
+#endif /* __GNUC__ */
+
+#ifdef XEDEBUG
+
+#define XED_CONFIG     0x1
+#define XED_MII                0x2
+#define XED_INTR       0x4
+#define XED_FIFO       0x8
+
+#ifndef XEDEBUG_DEF
+#define XEDEBUG_DEF    (XED_CONFIG|XED_INTR)
+#endif /* XEDEBUG_DEF */
+
+int xedebug = XEDEBUG_DEF;
+
+#define DPRINTF(cat, x) if (xedebug & (cat)) printf x
+
+#else  /* XEDEBUG */
+#define DPRINTF(cat, x) (void)0
+#endif /* XEDEBUG */
+
+int    xe_pcmcia_match __P((struct device *, void *, void *));
+void   xe_pcmcia_attach __P((struct device *, struct device *, void *));
+int    xe_pcmcia_detach __P((struct device *, int));
+int    xe_pcmcia_activate __P((struct device *, enum devact));
+
+/*
+ * In case this chipset ever turns up out of pcmcia attachments (very
+ * unlikely) do the driver splitup.
+ */
+struct xe_softc {
+       struct  device sc_dev;                  /* Generic device info */
+       u_int32_t       sc_flags;               /* Misc. flags */
+       void    *sc_ih;                         /* Interrupt handler */
+       struct  arpcom sc_arpcom;               /* Ethernet common part */
+       struct  ifmedia sc_media;               /* Media control */
+       struct  mii_data sc_mii;                /* MII media information */
+       int     sc_all_mcasts;                  /* Receive all multicasts */
+       bus_space_tag_t sc_bst;                 /* Bus cookie */
+       bus_space_handle_t      sc_bsh;         /* Bus I/O handle */
+       bus_addr_t      sc_offset;              /* Offset of registers */
+       u_int8_t        sc_rev;                 /* Chip revision */
+};
+
+#define XEF_MOHAWK     0x001
+#define XEF_DINGO      0x002
+#define XEF_MODEM      0x004
+#define XEF_UNSUPPORTED 0x008
+#define XEF_CE         0x010
+#define XEF_CE2                0x020
+#define XEF_CE3                0x040
+#define XEF_CE33       0x080
+#define XEF_CE56       0x100
+
+struct xe_pcmcia_softc {
+       struct  xe_softc sc_xe;                 /* Generic device info */
+       struct  pcmcia_mem_handle sc_pcmh;      /* PCMCIA memspace info */
+       int     sc_mem_window;                  /* mem window */
+       struct  pcmcia_io_handle sc_pcioh;      /* iospace info */
+       int     sc_io_window;                   /* io window info */
+       struct  pcmcia_function *sc_pf;         /* PCMCIA function */
+};
+
+/* Autoconfig definition of driver back-end */
+struct cfdriver xe_cd = {
+       NULL, "xe", DV_IFNET
+};
+
+struct cfattach xe_pcmcia_ca = {
+       sizeof (struct xe_pcmcia_softc), xe_pcmcia_match, xe_pcmcia_attach,
+       xe_pcmcia_detach, xe_pcmcia_activate
+};
+
+void   xe_cycle_power __P((struct xe_softc *));
+int    xe_ether_ioctl __P((struct ifnet *, u_long cmd, caddr_t));
+void   xe_full_reset __P((struct xe_softc *));
+void   xe_init __P((struct xe_softc *));
+int    xe_intr __P((void *));
+int    xe_ioctl __P((struct ifnet *, u_long, caddr_t));
+int    xe_mdi_read __P((struct device *, int, int));
+void   xe_mdi_write __P((struct device *, int, int, int));
+int    xe_mediachange __P((struct ifnet *));
+void   xe_mediastatus __P((struct ifnet *, struct ifmediareq *));
+int    xe_pcmcia_funce_enaddr __P((struct device *, u_int8_t *));
+u_int32_t xe_pcmcia_interpret_manfid __P((struct device *));
+int    xe_pcmcia_lan_nid_ciscallback __P((struct pcmcia_tuple *, void *));
+int    xe_pcmcia_manfid_ciscallback __P((struct pcmcia_tuple *, void *));
+u_int16_t xe_get __P((struct xe_softc *));
+void   xe_reset __P((struct xe_softc *));
+void   xe_set_address __P((struct xe_softc *));
+void   xe_start __P((struct ifnet *));
+void   xe_statchg __P((struct device *));
+void   xe_stop __P((struct xe_softc *));
+void   xe_watchdog __P((struct ifnet *));
+#ifdef XEDEBUG
+void   xe_reg_dump __P((struct xe_softc *));
+#endif /* XEDEBUG */
+
+int
+xe_pcmcia_match(parent, match, aux)
+       struct device *parent;
+       void *match, *aux;
+{
+       struct pcmcia_attach_args *pa = aux;
+       
+       if (pa->pf->function != PCMCIA_FUNCTION_NETWORK)
+               return (0);
+
+       switch (pa->manufacturer) {
+       case PCMCIA_VENDOR_COMPAQ:
+       case PCMCIA_VENDOR_COMPAQ2:
+       case PCMCIA_VENDOR_INTEL:
+               return (0);
+
+       case PCMCIA_VENDOR_XIRCOM:
+               /* XXX Per-productid checking here. */
+               return (1);
+
+       default:
+               return (0);
+       }
+}
+
+void
+xe_pcmcia_attach(parent, self, aux)
+       struct device *parent, *self;
+       void *aux;
+{
+       struct xe_pcmcia_softc *psc = (struct xe_pcmcia_softc *)self;
+       struct xe_softc *sc = &psc->sc_xe;
+       struct pcmcia_attach_args *pa = aux;
+       struct pcmcia_function *pf = pa->pf;
+       struct pcmcia_config_entry *cfe;
+       struct ifnet *ifp;
+       u_int8_t myla[ETHER_ADDR_LEN], *enaddr = NULL;
+       int state = 0;
+       struct pcmcia_mem_handle pcmh;
+       int ccr_window;
+       bus_addr_t ccr_offset;
+
+
+       psc->sc_pf = pf;
+
+#if 0
+       /* Figure out what card we are. */
+       sc->sc_flags = xe_pcmcia_interpret_manfid(parent);
+#endif
+       if (sc->sc_flags & XEF_UNSUPPORTED) {
+               printf(": card unsupported\n");
+               goto bad;
+       }
+
+       /* Tell the pcmcia framework where the CCR is. */
+       pf->ccr_base = 0x800;
+       pf->ccr_mask = 0x67;
+
+       /* Fake a cfe. */
+       SIMPLEQ_FIRST(&pa->pf->cfe_head) = cfe = (struct pcmcia_config_entry *)
+           malloc(sizeof *cfe, M_DEVBUF, M_NOWAIT);
+       if (!cfe) {
+               printf(": function enable failed\n");
+               return;
+       }
+       bzero(cfe, sizeof *cfe);
+
+       /*
+        * XXX Use preprocessor symbols instead.
+        * Enable ethernet & its interrupts, wiring them to -INT
+        * No I/O base.
+        */
+       cfe->number = 0x5;
+       cfe->flags = 0;         /* XXX Check! */
+       cfe->iftype = PCMCIA_IFTYPE_IO;
+       cfe->num_iospace = 0;
+       cfe->num_memspace = 0;
+       cfe->irqmask = 0x8eb0;
+
+       /* Enable the card. */
+       pcmcia_function_init(pa->pf, cfe);
+       if (pcmcia_function_enable(pa->pf)) {
+               printf(": function enable failed\n");
+               goto bad;
+       }
+
+       state++;
+
+       if (pcmcia_io_alloc(pa->pf, 0, 16, 16, &psc->sc_pcioh)) {
+               printf(": io allocation failed\n");
+               goto bad;



Home | Main Index | Thread Index | Old Index