Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/qbus Some updates to the DEUNA driver:



details:   https://anonhg.NetBSD.org/src/rev/dd5ccd6fe704
branches:  trunk
changeset: 486772:dd5ccd6fe704
user:      ragge <ragge%NetBSD.org@localhost>
date:      Sun May 28 17:23:44 2000 +0000

description:
Some updates to the DEUNA driver:
- Change the transmit logic to send from a pre-allocated buffer instead
  of doing DMA out of the mbufs directly. Timing shows that it takes
  4 times longer to map in the mbufs via the sgmap routines instead of
  just copying the data! This must be fixed sometine in the future.
- A bunch of other minor fixes.

diffstat:

 sys/dev/qbus/if_de.c    |  404 ++++++++++++++++++++++++++---------------------
 sys/dev/qbus/if_dereg.h |    9 +-
 2 files changed, 223 insertions(+), 190 deletions(-)

diffs (truncated from 772 to 300 lines):

diff -r 618700becc8f -r dd5ccd6fe704 sys/dev/qbus/if_de.c
--- a/sys/dev/qbus/if_de.c      Sun May 28 16:23:55 2000 +0000
+++ b/sys/dev/qbus/if_de.c      Sun May 28 17:23:44 2000 +0000
@@ -1,5 +1,4 @@
-/*     $NetBSD: if_de.c,v 1.1 2000/04/30 11:43:26 ragge Exp $  */
-
+/*     $NetBSD: if_de.c,v 1.2 2000/05/28 17:23:44 ragge Exp $  */
 /*
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * Copyright (c) 2000 Ludd, University of Lule}, Sweden.
@@ -43,7 +42,7 @@
  *     Lou Salkind
  *     New York University
  *
- *     Rewritten by Ragge 000430 to match new world.
+ *     Rewritten by Ragge 30 April 2000 to match new world.
  *
  * TODO:
  *     timeout routine (get statistics)
@@ -51,7 +50,7 @@
 
 #include "opt_inet.h"
 #include "opt_iso.h"
-#include "opt_ns.h"
+#include "bpfilter.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -73,15 +72,9 @@
 #include <netinet/if_inarp.h>
 #endif
 
-#ifdef NS
-#include <netns/ns.h>
-#include <netns/ns_if.h>
-#endif
-
-#ifdef ISO
-#include <netiso/iso.h>
-#include <netiso/iso_var.h>
-extern char all_es_snpa[], all_is_snpa[];
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#include <net/bpfdesc.h>
 #endif
 
 #include <machine/bus.h>
@@ -96,8 +89,7 @@
  * registers, and there is only 496 on one unibus...
  */
 #define NRCV   10      /* number of receive buffers (must be > 1) */
-#define NXMT   20      /* number of transmit buffers */
-#define NFRAGS 8       /* Number of frags per transmit buffer */
+#define NXMT   10      /* number of transmit buffers */
 
 /*
  * Structure containing the elements that must be in DMA-safe memory.
@@ -108,6 +100,7 @@
        struct  de_ring dc_xrent[NXMT]; /* transmit ring entrys */
        struct  de_ring dc_rrent[NRCV]; /* receive ring entrys */
        struct  de_udbbuf dc_udbbuf;    /* UNIBUS data buffer */
+       char    dc_xbuf[NXMT][ETHER_MAX_LEN];
        /* end mapped area */
 };
 
@@ -127,36 +120,38 @@
        struct  device sc_dev;          /* Configuration common part */
        struct  ethercom sc_ec;         /* Ethernet common part */
 #define sc_if  sc_ec.ec_if             /* network-visible interface */
-       int     sc_flags;
-#define DSF_RUNNING    2               /* board is enabled */
-#define DSF_SETADDR    4               /* physical address is changed */
        bus_space_tag_t sc_iot;
        bus_addr_t sc_ioh;
        bus_dma_tag_t sc_dmat;
+       bus_dmamap_t sc_cmap;
        struct de_cdata *sc_dedata;     /* Control structure */
        struct de_cdata *sc_pdedata;    /* Bus-mapped control structure */
-       bus_dmamap_t sc_xmtmap[NXMT];   /* unibus receive maps */
-       bus_dmamap_t sc_rcvmap[NRCV];   /* unibus xmt maps */
+#ifdef notdef
+       bus_dmamap_t sc_xmtmap[NXMT];   /* unibus xmit maps */
        struct mbuf *sc_txmbuf[NXMT];
+#endif
+       bus_dmamap_t sc_rcvmap[NRCV];   /* unibus receive maps */
        struct mbuf *sc_rxmbuf[NRCV];
-       int sc_nexttx;
-       int sc_nextrx;
-       int sc_inq;
-       int sc_lastack;
+       int sc_nexttx;                  /* next tx descriptor to put data on */
+       int sc_nextrx;                  /* next rx descriptor for recv */
+       int sc_inq;                     /* # if xmit packets in queue */
+       int sc_lastack;                 /* Last handled rx descriptor */
+       void *sc_sh;                    /* shutdownhook cookie */
 };
 
 static int dematch(struct device *, struct cfdata *, void *);
 static void deattach(struct device *, struct device *, void *);
-static int dewait(struct de_softc *, char *);
+static void dewait(struct de_softc *, char *);
 static void deinit(struct de_softc *);
 static int deioctl(struct ifnet *, u_long, caddr_t);
 static void dereset(struct device *);
 static void destart(struct ifnet *);
 static void derecv(struct de_softc *);
 static void dexmit(struct de_softc *);
-static void de_setaddr(u_char *, struct de_softc *);
 static void deintr(void *);
 static int de_add_rxbuf(struct de_softc *, int);
+static void desetup(struct de_softc *sc);
+static void deshutdown(void *);
 
 struct cfattach de_ca = {
        sizeof(struct de_softc), dematch, deattach
@@ -185,8 +180,8 @@
        struct de_softc *sc = (struct de_softc *)self;
        struct ifnet *ifp = &sc->sc_if;
        u_int8_t myaddr[ETHER_ADDR_LEN];
+       int csr1, rseg, error, i;
        bus_dma_segment_t seg;
-       int csr1, rseg, error, i;
        char *c;
 
        sc->sc_iot = ua->ua_iot;
@@ -213,7 +208,7 @@
        DE_WCSR(DE_PCSR0, 0);           /* reset INTE */
        DELAY(100);
        DE_WCSR(DE_PCSR0, PCSR0_RSET);
-       (void)dewait(sc, "reset");
+       dewait(sc, "reset");
 
        if ((error = bus_dmamem_alloc(sc->sc_dmat,
            sizeof(struct de_cdata), NBPG, 0, &seg, 1, &rseg,
@@ -229,13 +224,33 @@
                goto fail_1;
        }
 
+       if ((error = bus_dmamap_create(sc->sc_dmat, sizeof(struct de_cdata),
+           1, sizeof(struct de_cdata), 0, BUS_DMA_NOWAIT,
+           &sc->sc_cmap)) != 0) {
+               printf(": unable to create control data DMA map, error = %d\n",
+                   error);
+               goto fail_2;
+       }
+
+       if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cmap,
+           sc->sc_dedata, sizeof(struct de_cdata), NULL,
+           BUS_DMA_NOWAIT)) != 0) {
+               printf(": unable to load control data DMA map, error = %d\n",
+                   error);
+               goto fail_3;
+       }
+
+       bzero(sc->sc_dedata, sizeof(struct de_cdata));
+       sc->sc_pdedata = (struct de_cdata *)sc->sc_cmap->dm_segs[0].ds_addr;
+
+#ifdef notdef
        /*
         * Create the transmit descriptor DMA maps.
         *
         * XXX - should allocate transmit map pages when needed, not here.
         */
        for (i = 0; i < NXMT; i++) {
-               if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, NFRAGS,
+               if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
                    MCLBYTES, 0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW,
                    &sc->sc_xmtmap[i]))) {
                        printf(": unable to create tx DMA map %d, error = %d\n",
@@ -243,13 +258,14 @@
                        goto fail_4;
                }
        }
+#endif
 
        /*
         * Create receive buffer DMA maps.
         */
        for (i = 0; i < NRCV; i++) {
                if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
-                   MCLBYTES, 0, BUS_DMA_NOWAIT,
+                   MCLBYTES, 0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW,
                    &sc->sc_rcvmap[i]))) {
                        printf(": unable to create rx DMA map %d, error = %d\n",
                            i, error);
@@ -268,23 +284,20 @@
                }
        }
 
-       bzero(sc->sc_dedata, sizeof(struct de_cdata));
-       sc->sc_pdedata = (struct de_cdata *)seg.ds_addr;
-
        /*
         * Tell the DEUNA about our PCB
         */
        DE_WCSR(DE_PCSR2, LOWORD(sc->sc_pdedata));
        DE_WCSR(DE_PCSR3, HIWORD(sc->sc_pdedata));
        DE_WLOW(CMD_GETPCBB);
-       (void)dewait(sc, "pcbb");
+       dewait(sc, "pcbb");
 
        sc->sc_dedata->dc_pcbb.pcbb0 = FC_RDPHYAD;
        DE_WLOW(CMD_GETCMD);
-       (void)dewait(sc, "read addr ");
+       dewait(sc, "read addr ");
 
        bcopy((caddr_t)&sc->sc_dedata->dc_pcbb.pcbb2, myaddr, sizeof (myaddr));
-       printf("%s: %s, hardware address %s\n", c, sc->sc_dev.dv_xname,
+       printf("\n%s: %s, hardware address %s\n", sc->sc_dev.dv_xname, c,
                ether_sprintf(myaddr));
 
        uba_intr_establish(ua->ua_icookie, ua->ua_cvec, deintr, sc);
@@ -300,6 +313,7 @@
 #if NBPFILTER > 0
        bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
 #endif
+       sc->sc_sh = shutdownhook_establish(deshutdown, sc);
        return;
 
        /*
@@ -309,20 +323,26 @@
 fail_6:
        for (i = 0; i < NRCV; i++) {
                if (sc->sc_rxmbuf[i] != NULL) {
-                       bus_dmamap_unload(sc->sc_dmat, sc->sc_xmtmap[i]);
+                       bus_dmamap_unload(sc->sc_dmat, sc->sc_rcvmap[i]);
                        m_freem(sc->sc_rxmbuf[i]);
                }
        }
 fail_5:
        for (i = 0; i < NRCV; i++) {
+               if (sc->sc_rcvmap[i] != NULL)
+                       bus_dmamap_destroy(sc->sc_dmat, sc->sc_rcvmap[i]);
+       }
+#ifdef notdef
+fail_4: 
+       for (i = 0; i < NXMT; i++) {
                if (sc->sc_xmtmap[i] != NULL)
                        bus_dmamap_destroy(sc->sc_dmat, sc->sc_xmtmap[i]);
        }
-fail_4: 
-       for (i = 0; i < NXMT; i++) {
-               if (sc->sc_rcvmap[i] != NULL)
-                       bus_dmamap_destroy(sc->sc_dmat, sc->sc_rcvmap[i]);
-       }
+       bus_dmamap_unload(sc->sc_dmat, sc->sc_cmap);
+#endif
+fail_3:
+       bus_dmamap_destroy(sc->sc_dmat, sc->sc_cmap);
+fail_2:
        bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->sc_dedata,
            sizeof(struct de_cdata));
 fail_1:
@@ -340,9 +360,8 @@
        struct de_softc *sc = (void *)dev;
 
        sc->sc_if.if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
-       sc->sc_flags &= ~DSF_RUNNING;
        DE_WCSR(DE_PCSR0, PCSR0_RSET);
-       (void)dewait(sc, "reset");
+       dewait(sc, "reset");
        deinit(sc);
 }
 
@@ -353,10 +372,10 @@
 void
 deinit(struct de_softc *sc)
 {
-       struct de_cdata *dc;
+       struct de_cdata *dc, *pdc;
        int s, i;
 
-       if (sc->sc_flags & DSF_RUNNING)
+       if (sc->sc_if.if_flags & IFF_RUNNING)
                return;
        /*
         * Tell the DEUNA about our PCB
@@ -366,42 +385,36 @@
        DE_WLOW(0);             /* reset INTE */
        DELAY(500);
        DE_WLOW(CMD_GETPCBB);
-       (void)dewait(sc, "pcbb");
+       dewait(sc, "pcbb");
 
        dc = sc->sc_dedata;
+       pdc = sc->sc_pdedata;
        /* set the transmit and receive ring header addresses */
        dc->dc_pcbb.pcbb0 = FC_WTRING;
-       dc->dc_pcbb.pcbb2 = LOWORD(&sc->sc_pdedata->dc_udbbuf);
-       dc->dc_pcbb.pcbb2 = HIWORD(&sc->sc_pdedata->dc_udbbuf);
+       dc->dc_pcbb.pcbb2 = LOWORD(&pdc->dc_udbbuf);
+       dc->dc_pcbb.pcbb4 = HIWORD(&pdc->dc_udbbuf);
 
-       dc->dc_udbbuf.b_tdrbl = LOWORD(&sc->sc_pdedata->dc_xrent[0]);
-       dc->dc_udbbuf.b_tdrbh = HIWORD(&sc->sc_pdedata->dc_xrent[0]);
+       dc->dc_udbbuf.b_tdrbl = LOWORD(&pdc->dc_xrent[0]);
+       dc->dc_udbbuf.b_tdrbh = HIWORD(&pdc->dc_xrent[0]);
        dc->dc_udbbuf.b_telen = sizeof (struct de_ring) / sizeof(u_int16_t);
        dc->dc_udbbuf.b_trlen = NXMT;
-       dc->dc_udbbuf.b_rdrbl = LOWORD(&sc->sc_pdedata->dc_rrent[0]);



Home | Main Index | Thread Index | Old Index