Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Pull in Jason Wright's latest changes to the "hme...



details:   https://anonhg.NetBSD.org/src/rev/9e3e1e16b3e1
branches:  trunk
changeset: 518163:9e3e1e16b3e1
user:      tron <tron%NetBSD.org@localhost>
date:      Sun Nov 25 22:12:01 2001 +0000

description:
Pull in Jason Wright's latest changes to the "hme" driver from OpenBSD.
This supports direct DMA from and into mbuf cluster, and VLAN
handling is done a bit differently.

diffstat:

 sys/dev/ic/hme.c    |  764 ++++++++++++++++++++++++---------------------------
 sys/dev/ic/hmereg.h |   33 +-
 sys/dev/ic/hmevar.h |   32 +-
 3 files changed, 388 insertions(+), 441 deletions(-)

diffs (truncated from 1257 to 300 lines):

diff -r e3d693b55a01 -r 9e3e1e16b3e1 sys/dev/ic/hme.c
--- a/sys/dev/ic/hme.c  Sun Nov 25 19:15:46 2001 +0000
+++ b/sys/dev/ic/hme.c  Sun Nov 25 22:12:01 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hme.c,v 1.25 2001/11/13 13:14:37 lukem Exp $   */
+/*     $NetBSD: hme.c,v 1.26 2001/11/25 22:12:01 tron Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -41,14 +41,15 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.25 2001/11/13 13:14:37 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.26 2001/11/25 22:12:01 tron Exp $");
 
-#define HMEDEBUG
+#undef HMEDEBUG
 
 #include "opt_inet.h"
 #include "opt_ns.h"
 #include "bpfilter.h"
 #include "rnd.h"
+#include "vlan.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -92,9 +93,15 @@
 
 #include <machine/bus.h>
 
+#if NVLAN > 0
+#include <net/if_vlan_var.h>
+#endif
+
 #include <dev/ic/hmereg.h>
 #include <dev/ic/hmevar.h>
 
+#define        HME_RX_OFFSET   2
+
 void           hme_start __P((struct ifnet *));
 void           hme_stop __P((struct hme_softc *));
 int            hme_ioctl __P((struct ifnet *, u_long, caddr_t));
@@ -106,6 +113,8 @@
 void           hme_mifinit __P((struct hme_softc *));
 void           hme_reset __P((struct hme_softc *));
 void           hme_setladrf __P((struct hme_softc *));
+int            hme_newbuf __P((struct hme_softc *, struct hme_sxd *, int));
+int            hme_encap __P((struct hme_softc *, struct mbuf *, int *));
 
 /* MII methods & callbacks */
 static int     hme_mii_readreg __P((struct device *, int, int));
@@ -115,21 +124,10 @@
 int            hme_mediachange __P((struct ifnet *));
 void           hme_mediastatus __P((struct ifnet *, struct ifmediareq *));
 
-struct mbuf    *hme_get __P((struct hme_softc *, int, int));
-int            hme_put __P((struct hme_softc *, int, struct mbuf *));
-void           hme_read __P((struct hme_softc *, int, int));
 int            hme_eint __P((struct hme_softc *, u_int));
 int            hme_rint __P((struct hme_softc *));
 int            hme_tint __P((struct hme_softc *));
 
-static int     ether_cmp __P((u_char *, u_char *));
-
-/* Default buffer copy routines */
-void   hme_copytobuf_contig __P((struct hme_softc *, void *, int, int));
-void   hme_copyfrombuf_contig __P((struct hme_softc *, void *, int, int));
-void   hme_zerobuf_contig __P((struct hme_softc *, int, int));
-
-
 void
 hme_config(sc)
        struct hme_softc *sc;
@@ -140,7 +138,7 @@
        bus_dma_tag_t dmatag = sc->sc_dmatag;
        bus_dma_segment_t seg;
        bus_size_t size;
-       int rseg, error;
+       int rseg, error, i;
 
        /*
         * HME common initialization.
@@ -163,9 +161,6 @@
         * the maximum bus burst size:
         *      sc_burst
         *
-        * (notyet:DMA capable memory for the ring descriptors & packet buffers:
-        *      rb_membase, rb_dmabase)
-        *
         * the local Ethernet address:
         *      sc_enaddr
         *
@@ -175,60 +170,60 @@
        hme_stop(sc);
 
 
-       /*
-        * Allocate descriptors and buffers
-        * XXX - do all this differently.. and more configurably,
-        * eg. use things as `dma_load_mbuf()' on transmit,
-        *     and a pool of `EXTMEM' mbufs (with buffers DMA-mapped
-        *     all the time) on the reveiver side.
-        *
-        * Note: receive buffers must be 64-byte aligned.
-        * Also, apparently, the buffers must extend to a DMA burst
-        * boundary beyond the maximum packet size.
-        */
-#define _HME_NDESC     128
-#define _HME_BUFSZ     1600
-
-       /* Note: the # of descriptors must be a multiple of 16 */
-       sc->sc_rb.rb_ntbuf = _HME_NDESC;
-       sc->sc_rb.rb_nrbuf = _HME_NDESC;
+       for (i = 0; i < HME_TX_RING_SIZE; i++) {
+               if (bus_dmamap_create(sc->sc_dmatag, MCLBYTES, 1,
+                   MCLBYTES, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
+                   &sc->sc_txd[i].sd_map) != 0) {
+                       sc->sc_txd[i].sd_map = NULL;
+                       goto fail;
+               }
+       }
+       for (i = 0; i < HME_RX_RING_SIZE; i++) {
+               if (bus_dmamap_create(sc->sc_dmatag, MCLBYTES, 1,
+                   MCLBYTES, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
+                   &sc->sc_rxd[i].sd_map) != 0) {
+                       sc->sc_rxd[i].sd_map = NULL;
+                       goto fail;
+               }
+       }
+       if (bus_dmamap_create(sc->sc_dmatag, MCLBYTES, 1, MCLBYTES, 0,
+           BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &sc->sc_rxmap_spare) != 0) {
+               sc->sc_rxmap_spare = NULL;
+               goto fail;
+       }
 
        /*
         * Allocate DMA capable memory
         * Buffer descriptors must be aligned on a 2048 byte boundary;
         * take this into account when calculating the size. Note that
         * the maximum number of descriptors (256) occupies 2048 bytes,
-        * so we allocate that much regardless of _HME_NDESC.
+        * so we allocate that much regardless of the number of descriptors.
         */
-       size =  2048 +                                  /* TX descriptors */
-               2048 +                                  /* RX descriptors */
-               sc->sc_rb.rb_ntbuf * _HME_BUFSZ +       /* TX buffers */
-               sc->sc_rb.rb_nrbuf * _HME_BUFSZ;        /* TX buffers */
+       size = (HME_XD_SIZE * HME_RX_RING_MAX) +        /* RX descriptors */
+           (HME_XD_SIZE * HME_TX_RING_MAX);            /* TX descriptors */
 
        /* Allocate DMA buffer */
-       if ((error = bus_dmamem_alloc(dmatag, size,
-                                     2048, 0,
-                                     &seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
+       if ((error = bus_dmamem_alloc(dmatag, size, 2048, 0, &seg, 1, &rseg,
+           BUS_DMA_NOWAIT)) != 0) {
                printf("%s: DMA buffer alloc error %d\n",
-                       sc->sc_dev.dv_xname, error);
+                   sc->sc_dev.dv_xname, error);
                return;
        }
 
        /* Map DMA memory in CPU addressable space */
        if ((error = bus_dmamem_map(dmatag, &seg, rseg, size,
-                                   &sc->sc_rb.rb_membase,
-                                   BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
+           &sc->sc_rb.rb_membase, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
                printf("%s: DMA buffer map error %d\n",
-                       sc->sc_dev.dv_xname, error);
+                   sc->sc_dev.dv_xname, error);
                bus_dmamap_unload(dmatag, sc->sc_dmamap);
                bus_dmamem_free(dmatag, &seg, rseg);
                return;
        }
 
        if ((error = bus_dmamap_create(dmatag, size, 1, size, 0,
-                                   BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) {
+           BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) {
                printf("%s: DMA map create error %d\n",
-                       sc->sc_dev.dv_xname, error);
+                   sc->sc_dev.dv_xname, error);
                return;
        }
 
@@ -237,7 +232,7 @@
            sc->sc_rb.rb_membase, size, NULL,
            BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
                printf("%s: DMA buffer map load error %d\n",
-                       sc->sc_dev.dv_xname, error);
+                   sc->sc_dev.dv_xname, error);
                bus_dmamem_free(dmatag, &seg, rseg);
                return;
        }
@@ -267,7 +262,7 @@
        hme_mifinit(sc);
 
        mii_attach(&sc->sc_dev, mii, 0xffffffff,
-                       MII_PHY_ANY, MII_OFFSET_ANY, 0);
+           MII_PHY_ANY, MII_OFFSET_ANY, 0);
 
        child = LIST_FIRST(&mii->mii_phys);
        if (child == NULL) {
@@ -290,10 +285,10 @@
                         */
                        if (child->mii_phy > 1 || child->mii_inst > 1) {
                                printf("%s: cannot accomodate MII device %s"
-                                      " at phy %d, instance %d\n",
-                                      sc->sc_dev.dv_xname,
-                                      child->mii_dev.dv_xname,
-                                      child->mii_phy, child->mii_inst);
+                                   " at phy %d, instance %d\n",
+                                   sc->sc_dev.dv_xname,
+                                   child->mii_dev.dv_xname,
+                                   child->mii_phy, child->mii_inst);
                                continue;
                        }
 
@@ -307,9 +302,6 @@
                ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_AUTO);
        }
 
-       /* claim 802.1q capability */
-       sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
-
        /* Attach the interface. */
        if_attach(ifp);
        ether_ifattach(ifp, sc->sc_enaddr);
@@ -318,21 +310,23 @@
        if (sc->sc_sh == NULL)
                panic("hme_config: can't establish shutdownhook");
 
-#if 0
-       printf("%s: %d receive buffers, %d transmit buffers\n",
-           sc->sc_dev.dv_xname, sc->sc_nrbuf, sc->sc_ntbuf);
-       sc->sc_rbufaddr = malloc(sc->sc_nrbuf * sizeof(int), M_DEVBUF,
-                                       M_WAITOK);
-       sc->sc_tbufaddr = malloc(sc->sc_ntbuf * sizeof(int), M_DEVBUF,
-                                       M_WAITOK);
-#endif
-
 #if NRND > 0
        rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
                          RND_TYPE_NET, 0);
 #endif
 
        callout_init(&sc->sc_tick_ch);
+       return;
+
+fail:
+       if (sc->sc_rxmap_spare != NULL)
+               bus_dmamap_destroy(sc->sc_dmatag, sc->sc_rxmap_spare);
+       for (i = 0; i < HME_TX_RING_SIZE; i++)
+               if (sc->sc_txd[i].sd_map != NULL)
+                       bus_dmamap_destroy(sc->sc_dmatag, sc->sc_txd[i].sd_map);
+       for (i = 0; i < HME_RX_RING_SIZE; i++)
+               if (sc->sc_rxd[i].sd_map != NULL)
+                       bus_dmamap_destroy(sc->sc_dmatag, sc->sc_rxd[i].sd_map);
 }
 
 void
@@ -340,9 +334,29 @@
        void *arg;
 {
        struct hme_softc *sc = arg;
+       struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+       bus_space_tag_t t = sc->sc_bustag;
+       bus_space_handle_t mac = sc->sc_mac;
        int s;
 
        s = splnet();
+       /*
+        * Unload collision counters
+        */
+       ifp->if_collisions +=
+           bus_space_read_4(t, mac, HME_MACI_NCCNT) +
+           bus_space_read_4(t, mac, HME_MACI_FCCNT) +
+           bus_space_read_4(t, mac, HME_MACI_EXCNT) +
+           bus_space_read_4(t, mac, HME_MACI_LTCNT);
+
+       /*
+        * then clear the hardware counters.
+        */
+       bus_space_write_4(t, mac, HME_MACI_NCCNT, 0);
+       bus_space_write_4(t, mac, HME_MACI_FCCNT, 0);
+       bus_space_write_4(t, mac, HME_MACI_EXCNT, 0);
+       bus_space_write_4(t, mac, HME_MACI_LTCNT, 0);
+
        mii_tick(&sc->sc_mii);
        splx(s);
 
@@ -373,7 +387,7 @@
 
        /* Reset transmitter and receiver */
        bus_space_write_4(t, seb, HME_SEBI_RESET,
-                         (HME_SEB_RESET_ETX | HME_SEB_RESET_ERX));
+           (HME_SEB_RESET_ETX | HME_SEB_RESET_ERX));
 
        for (n = 0; n < 20; n++) {
                u_int32_t v = bus_space_read_4(t, seb, HME_SEBI_RESET);



Home | Main Index | Thread Index | Old Index