Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Chipset driver for TROPIC based Token-Ring cards.



details:   https://anonhg.NetBSD.org/src/rev/6d69b6845ee3
branches:  trunk
changeset: 467299:6d69b6845ee3
user:      bad <bad%NetBSD.org@localhost>
date:      Mon Mar 22 22:21:26 1999 +0000

description:
Chipset driver for TROPIC based Token-Ring cards.
Frontends for IBM and 3COM ISA cards.

By Onno van der Linden <onno%simplex.nl@localhost>.

diffstat:

 sys/dev/ic/tropic.c           |  1649 +++++++++++++++++++++++++++++++++++++++++
 sys/dev/ic/tropicreg.h        |   573 ++++++++++++++
 sys/dev/ic/tropicvar.h        |   116 ++
 sys/dev/isa/if_tr_isa.c       |   299 +++++++
 sys/dev/isa/if_tribm_isa.c    |   171 ++++
 sys/dev/isa/if_trtcm_isa.c    |   354 ++++++++
 sys/dev/isapnp/if_tr_isapnp.c |   206 +++++
 7 files changed, 3368 insertions(+), 0 deletions(-)

diffs (truncated from 3396 to 300 lines):

diff -r 502302147310 -r 6d69b6845ee3 sys/dev/ic/tropic.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/tropic.c       Mon Mar 22 22:21:26 1999 +0000
@@ -0,0 +1,1649 @@
+/* 
+ * Ported to NetBSD by Onno van der Linden
+ * Many thanks to Larry Lile for sending me the IBM TROPIC documentation.
+ *
+ * Mach Operating System
+ * Copyright (c) 1991 Carnegie Mellon University
+ * Copyright (c) 1991 IBM Corporation 
+ * All Rights Reserved.
+ * 
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation,
+ * and that the name IBM not be used in advertising or publicity 
+ * pertaining to distribution of the software without specific, written
+ * prior permission.
+ * 
+ * CARNEGIE MELLON AND IBM ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON AND IBM DISCLAIM ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ * 
+ * Carnegie Mellon requests users of this software to return to
+ * 
+ *  Software Distribution Coordinator  or  Software.Distribution%CS.CMU.EDU@localhost
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ * 
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+#include "opt_inet.h"
+#include "opt_ns.h"
+#include "bpfilter.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/buf.h>
+#include <sys/socket.h>
+#include <sys/syslog.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+#include <sys/device.h>
+
+#include <net/if.h>
+#include <net/if_llc.h>
+#include <net/if_ether.h>
+#include <net/if_media.h>
+#include <net/netisr.h>
+#include <net/route.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/if_inarp.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/in_var.h>
+#include <net/if_token.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/cpu.h>
+#include <machine/bus.h>
+
+#include <dev/ic/tropicreg.h>
+#include <dev/ic/tropicvar.h>
+
+void   tr_rint __P((struct tr_softc *));
+void   tr_xint __P((struct tr_softc *));
+void   tr_oldxint __P((struct tr_softc *));
+struct mbuf *tr_get __P((struct tr_softc *, int, struct ifnet *));
+void   tr_opensap __P((struct tr_softc *, u_char));
+void   tr_timeout __P((void *));
+int    tr_mbcopy __P((struct tr_softc *, bus_size_t, struct mbuf *));
+void   tr_bcopy __P((struct tr_softc *, u_char *, int));
+void   tr_start __P((struct ifnet *));
+void   tr_oldstart __P((struct ifnet *));
+void   tr_watchdog __P((struct ifnet *));
+int    tr_mediachange __P((struct ifnet *));
+void   tr_mediastatus __P((struct ifnet *, struct ifmediareq *));
+int    tropic_mediachange __P((struct tr_softc *));
+void   tropic_mediastatus __P((struct tr_softc *, struct ifmediareq *));
+
+/*
+ * TODO:
+ * clean up tr_intr: more subroutines
+ * IFF_LINK0 == IFM_TOK_SRCRT change to link flag implies media flag change
+ * IFF_LINK1 == IFM_TOK_ALLR  change to link flag implies media flag change
+ * XXX Create receive_done queue to kill "ASB not free", but does this ever
+ * XXX happen ?
+ */
+
+static int media[] = {
+       IFM_TOKEN | IFM_TOK_UTP4,
+       IFM_TOKEN | IFM_TOK_STP4,
+       IFM_TOKEN | IFM_TOK_UTP16,
+       IFM_TOKEN | IFM_TOK_STP16,
+       IFM_TOKEN | IFM_TOK_UTP4,
+       IFM_TOKEN | IFM_TOK_UTP16,
+       IFM_TOKEN | IFM_TOK_STP4,
+       IFM_TOKEN | IFM_TOK_STP16
+};
+
+int
+tropic_mediachange(sc)
+       struct tr_softc *sc;
+{
+       if (IFM_TYPE(sc->sc_media.ifm_media) != IFM_TOKEN)
+               return EINVAL;
+
+       switch (IFM_SUBTYPE(sc->sc_media.ifm_media)) {
+       case IFM_TOK_STP16:
+       case IFM_TOK_UTP16:
+               if ((sc->sc_init_status & RSP_16) == 0) {
+                       tr_reset(sc);
+                       if (tr_setspeed(sc, 16) == 0)
+                               sc->sc_init_status |= RSP_16;
+                       else
+                               return EINVAL;
+                       tr_init(sc);
+                       tr_sleep(sc);
+               }
+               break;
+       case IFM_TOK_STP4:
+       case IFM_TOK_UTP4:
+               if ((sc->sc_init_status & RSP_16) != 0) {
+                       tr_reset(sc);
+                       if (tr_setspeed(sc, 4) == 0)
+                               sc->sc_init_status &= ~RSP_16;
+                       else
+                               return EINVAL;
+                       tr_init(sc);
+                       tr_sleep(sc);
+               }
+               break;
+       }
+/*
+ * XXX Handle Early Token Release !!!!
+ */
+       return 0;
+}
+
+void
+tropic_mediastatus(sc, ifmr)
+       struct tr_softc *sc;
+       struct ifmediareq *ifmr;
+{
+       struct ifmedia  *ifm = &sc->sc_media;
+
+       ifmr->ifm_active = ifm->ifm_cur->ifm_media;
+}
+
+int
+tr_config(sc)
+       struct tr_softc *sc;
+{
+       int     nmedia, *mediaptr, *defmediaptr;
+       int     i, temp;
+       u_int8_t myaddr[ISO88025_ADDR_LEN];
+       struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+
+       for (i = 0, temp = 0; i < ISO88025_ADDR_LEN; i++, temp += 4) {
+               myaddr[i] = (MM_INB(sc, (TR_MAC_OFFSET + temp)) & 0xf) << 4;
+               myaddr[i] |= MM_INB(sc, (TR_MAC_OFFSET + temp + 2)) & 0xf;
+       }
+
+       sc->sc_init_status = SRB_INB(sc, sc->sc_srb, SRB_INIT_STATUS);
+
+/*
+ * MAX_MACFRAME_SIZE = DHB_SIZE - 6
+ * IPMTU = MAX_MACFRAME_SIZE - (14 + 18 + 8)
+ * (14 = header, 18 = sroute, 8 = llcsnap)
+ */
+
+       /* XXX should depend on sc_resvdmem. */
+       if (MM_INB(sc, TR_RAM_OFFSET) == 0xB && sc->sc_memsize == 65536)
+               for (i = 0; i < 512; i++)
+                       SR_OUTB(sc, 0xfe00 + i, 0);
+
+       if (sc->sc_init_status & FAST_PATH_TRANSMIT) {
+               bus_size_t cfg_resp;
+               bus_size_t srb;
+               int     nbuf = 0;
+
+               srb = sc->sc_srb;
+               cfg_resp = sc->sc_srb;
+
+               for (i=0; i < SRB_CFP_CMDSIZE; i++)
+                       SRB_OUTB(sc, sc->sc_srb, i, 0);
+
+               SRB_OUTB(sc, srb, SRB_CMD, DIR_CONFIG_FAST_PATH_RAM);
+
+               switch (sc->sc_memsize) {
+               case 65536:
+                       nbuf = 58;
+                       sc->sc_maxmtu = IPMTU_4MBIT_MAX;
+                       break;
+               case 32768:
+                       nbuf = 29;
+                       sc->sc_maxmtu = IPMTU_4MBIT_MAX;
+                       break;
+               case 16384:
+                       nbuf = 13;
+                       sc->sc_maxmtu = IPMTU_4MBIT_MAX;
+                       break;
+               case 8192:
+                       nbuf = 5;
+                       sc->sc_maxmtu = ISO88025_MTU;
+               }
+
+               sc->sc_minbuf = ((sc->sc_maxmtu + 511) / 512) + 1;
+               sc->sc_nbuf = nbuf;
+               sc->sc_xmit_head = sc->sc_xmit_tail = 0;
+               SRB_OUTW(sc, srb, SRB_CFP_RAMSIZE,
+                   (16 + (nbuf * FP_BUF_LEN) / 8));
+               SRB_OUTW(sc, srb, SRB_CFP_BUFSIZE, FP_BUF_LEN);
+
+               /* tell adapter: command in SRB */
+               ACA_SETB(sc, ACA_ISRA_o, CMD_IN_SRB);
+
+               for (i = 0; i < 30000; i++) {
+                       if (ACA_RDB(sc, ACA_ISRP_o) & SRB_RESP_INT)
+                               break;
+                       delay(100);
+               }
+
+               if ((ACA_RDB(sc, ACA_ISRP_o) & SRB_RESP_INT) == 0) {
+                       printf("No response for fast path cfg\n");
+                       return 1;
+               }
+
+               ACA_RSTB(sc, ACA_ISRP_o, ~(SRB_RESP_INT));
+
+
+               if ((SRB_INB(sc, cfg_resp, SRB_RETCODE) != 0)) {
+                       printf("cfg fast path returned: %02x\n",
+                               SRB_INB(sc, cfg_resp, SRB_RETCODE));
+                       return 1;
+               }
+
+               sc->sc_txca = SRB_INW(sc, cfg_resp, SRB_CFPRESP_FPXMIT);
+               sc->sc_srb = SRB_INW(sc, cfg_resp, SRB_CFPRESP_SRBADDR);
+/*
+ *  Create circular queues caching the buffer pointers ?
+ */
+       }
+       else {
+               switch (sc->sc_memsize) {
+               case 8192:
+                       sc->sc_dhb4maxsz = 2048;
+                       sc->sc_dhb16maxsz = 2048;
+                       break;
+               case 16384:
+                       sc->sc_dhb4maxsz = 4096;
+                       sc->sc_dhb16maxsz = 4096;
+                       break;
+               case 32768:
+                       sc->sc_dhb4maxsz = 4464;
+                       sc->sc_dhb16maxsz = 8192;
+                       break;
+               case 65536:
+                       sc->sc_dhb4maxsz = 4464;
+                       sc->sc_dhb16maxsz = 8192;
+                       break;
+               }
+               switch (MM_INB(sc, TR_DHB4_OFFSET)) {
+               case 0xF:
+                       if (sc->sc_dhb4maxsz > 2048)
+                               sc->sc_dhb4maxsz = 2048;
+                       break;
+               case 0xE:
+                       if (sc->sc_dhb4maxsz > 4096)
+                               sc->sc_dhb4maxsz = 4096;
+                       break;
+               case 0xD:
+                       if (sc->sc_dhb4maxsz > 4464)
+                               sc->sc_dhb4maxsz = 4464;
+                       break;
+               }
+
+               switch (MM_INB(sc, TR_DHB16_OFFSET)) {
+               case 0xF:
+                       if (sc->sc_dhb16maxsz > 2048)



Home | Main Index | Thread Index | Old Index