Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci - kill the carrier detect code. It's not usefull...



details:   https://anonhg.NetBSD.org/src/rev/e012a042ba42
branches:  trunk
changeset: 513568:e012a042ba42
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Fri Aug 03 16:53:08 2001 +0000

description:
- kill the carrier detect code. It's not usefull any more and can give
  false informations on a loaded ethernet segement.
- convert to bus_dma(9) (better late than never :)
- add proper le32toh/htole32 so that it works on big-endian system (tested
  on macppc).
Close PR kern/10327.

diffstat:

 sys/dev/pci/if_tl.c     |  426 ++++++++++++++++++++++++++++-------------------
 sys/dev/pci/if_tlregs.h |   22 +-
 sys/dev/pci/if_tlvar.h  |   12 +-
 3 files changed, 273 insertions(+), 187 deletions(-)

diffs (truncated from 795 to 300 lines):

diff -r 698240467013 -r e012a042ba42 sys/dev/pci/if_tl.c
--- a/sys/dev/pci/if_tl.c       Fri Aug 03 15:35:09 2001 +0000
+++ b/sys/dev/pci/if_tl.c       Fri Aug 03 16:53:08 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_tl.c,v 1.42 2001/07/07 16:46:35 thorpej Exp $       */
+/*     $NetBSD: if_tl.c,v 1.43 2001/08/03 16:53:08 bouyer Exp $        */
 
 /* XXX ALTQ XXX */
 
@@ -111,22 +111,11 @@
 #include <dev/pci/if_tlvar.h>
 #endif /* __NetBSD__ */
 
-#if defined(__NetBSD__) && defined(__alpha__)
-/* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */
-#undef vtophys
-#define        vtophys(va)     alpha_XXX_dmamap((vaddr_t)(va))
-#endif
-
 /* number of transmit/receive buffers */
 #ifndef TL_NBUF 
 #define TL_NBUF 10
 #endif
 
-/* number of seconds the link can be idle */
-#ifndef TL_IDLETIME
-#define TL_IDLETIME 10
-#endif
-
 static int tl_pci_match __P((struct device *, struct cfdata *, void *));
 static void tl_pci_attach __P((struct device *, struct device *, void *));
 static int tl_intr __P((void *));
@@ -141,7 +130,7 @@
 static void tl_reset __P((tl_softc_t*));
 static int  tl_init __P((tl_softc_t*));
 static void tl_restart __P((void  *));
-static int  tl_add_RxBuff __P((struct Rx_list*, struct mbuf*));
+static int  tl_add_RxBuff __P((tl_softc_t*, struct Rx_list*, struct mbuf*));
 static void tl_read_stats __P((tl_softc_t*));
 static void tl_ticks __P((void*));
 static int tl_multicast_hash __P((u_int8_t*));
@@ -265,6 +254,7 @@
 }
 
 static char *nullbuf = NULL;
+static bus_dmamap_t nullbuf_dmamap = NULL;
 
 static int
 tl_pci_match(parent, match, aux)
@@ -354,6 +344,7 @@
                    sc->sc_dev.dv_xname);
                return;
        }
+       sc->tl_dmatag = pa->pa_dmat;
 
        /* Enable the device. */
        csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
@@ -407,6 +398,10 @@
        }
        printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
 
+       /* init these pointers, so that tl_shutdown won't try to read them */
+       sc->Rx_list = NULL;
+       sc->Tx_list = NULL;
+
        /*
         * Add shutdown hook so that DMA is disabled prior to reboot. Not
         * doing do could allow DMA to corrupt kernel memory during the
@@ -487,9 +482,6 @@
        netsio_set(sc, TL_NETSIO_NMRST);
        DELAY(100000);
        sc->tl_mii.mii_media_status &= ~IFM_ACTIVE;
-       sc->tl_flags = 0;
-       sc->opkt = 0;
-       sc->stats_exesscoll = 0;
 }
 
 static void tl_shutdown(v)
@@ -517,26 +509,39 @@
        mii_down(&sc->tl_mii);
 
        /* deallocate memory allocations */
-       for (i=0; i< TL_NBUF; i++) {
-               if (sc->Rx_list[i].m)
-                       m_freem(sc->Rx_list[i].m);
-               sc->Rx_list[i].m = NULL;
+       if (sc->Rx_list) {
+               for (i=0; i< TL_NBUF; i++) {
+                       if (sc->Rx_list[i].m) {
+                               bus_dmamap_unload(sc->tl_dmatag,
+                                   sc->Rx_list[i].m_dmamap);
+                               m_freem(sc->Rx_list[i].m);
+                       }
+                       sc->Rx_list[i].m = NULL;
+               }
+               free(sc->Rx_list, M_DEVBUF);
+               sc->Rx_list = NULL;
+               bus_dmamap_unload(sc->tl_dmatag, sc->Rx_dmamap);
+               bus_dmamem_free(sc->tl_dmatag, sc->Rx_dmamap->dm_segs,
+                   sc->Rx_dmamap->dm_nsegs);
+               sc->hw_Rx_list = NULL;
+               while ((Tx = sc->active_Tx) != NULL) {
+                       Tx->hw_list->stat = 0;
+                       bus_dmamap_unload(sc->tl_dmatag, Tx->m_dmamap);
+                       m_freem(Tx->m);
+                       sc->active_Tx = Tx->next;
+                       Tx->next = sc->Free_Tx;
+                       sc->Free_Tx = Tx;
+               }
+               sc->last_Tx = NULL;
+               free(sc->Tx_list, M_DEVBUF);
+               sc->Tx_list = NULL;
+               bus_dmamem_free(sc->tl_dmatag, sc->Tx_dmamap->dm_segs,
+                   sc->Tx_dmamap->dm_nsegs);
+               bus_dmamap_unload(sc->tl_dmatag, sc->Tx_dmamap);
+               sc->hw_Tx_list = NULL;
        }
-       free(sc->Rx_list, M_DEVBUF);
-       sc->Rx_list = NULL;
-       while ((Tx = sc->active_Tx) != NULL) {
-               Tx->hw_list.stat = 0;
-               m_freem(Tx->m);
-               sc->active_Tx = Tx->next;
-               Tx->next = sc->Free_Tx;
-               sc->Free_Tx = Tx;
-       }
-       sc->last_Tx = NULL;
-       free(sc->Tx_list, M_DEVBUF);
-       sc->Tx_list = NULL;
        sc->tl_if.if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
        sc->tl_mii.mii_media_status &= ~IFM_ACTIVE;
-       sc->tl_flags = 0;
 }
 
 static void tl_restart(v)
@@ -549,7 +554,10 @@
        tl_softc_t *sc;
 {
        struct ifnet *ifp = &sc->tl_if;
-       int i, s;
+       int i, s, error;
+       bus_dma_segment_t segs;
+       int nsegs;
+       char *errstring;
 
        s = splnet();
        /* cancel any pending IO */
@@ -586,52 +594,126 @@
        sc->Tx_list = malloc(sizeof(struct Tx_list) * TL_NBUF, M_DEVBUF,
            M_NOWAIT);
        if (sc->Rx_list == NULL || sc->Tx_list == NULL) {
-               printf("%s: out of memory for lists\n", sc->sc_dev.dv_xname);
-               sc->tl_if.if_flags &= ~IFF_UP;
-               splx(s);
-               return ENOMEM;
+               errstring = "out of memory for lists";
+               error = ENOMEM;
+               goto bad;
+       }
+       memset(sc->Rx_list, 0, sizeof(struct Rx_list) * TL_NBUF);
+       memset(sc->Tx_list, 0, sizeof(struct Tx_list) * TL_NBUF);
+       error = bus_dmamap_create(sc->tl_dmatag,
+           sizeof(struct tl_Rx_list) * TL_NBUF, 1,
+           sizeof(struct tl_Rx_list) * TL_NBUF, 0, BUS_DMA_WAITOK,
+           &sc->Rx_dmamap);
+       if (error == 0)
+               error = bus_dmamap_create(sc->tl_dmatag,
+                   sizeof(struct tl_Tx_list) * TL_NBUF, 1,
+                   sizeof(struct tl_Tx_list) * TL_NBUF, 0, BUS_DMA_WAITOK,
+                   &sc->Tx_dmamap);
+       if (error) {
+               errstring = "can't allocate DMA maps for lists";
+               goto bad;
        }
+       error = bus_dmamem_alloc(sc->tl_dmatag,
+           sizeof(struct tl_Rx_list) * TL_NBUF, 0, PAGE_SIZE,
+           &segs, 1, &nsegs, BUS_DMA_NOWAIT);
+       if (error == 0)
+               error = bus_dmamem_map(sc->tl_dmatag, &segs,  nsegs, 
+                   sizeof(struct tl_Rx_list) * TL_NBUF,
+                   (caddr_t*)&sc->hw_Rx_list,
+                   BUS_DMA_WAITOK | BUS_DMA_COHERENT);
+       if (error == 0)
+               error = bus_dmamap_load(sc->tl_dmatag, sc->Rx_dmamap,
+                   sc->hw_Rx_list, sizeof(struct tl_Rx_list) * TL_NBUF, NULL,
+                   BUS_DMA_WAITOK);
+       if (error == 0)
+               error = bus_dmamem_alloc(sc->tl_dmatag,
+                   sizeof(struct tl_Tx_list) * TL_NBUF, 0, PAGE_SIZE,
+                   &segs, 1, &nsegs, BUS_DMA_NOWAIT);
+       if (error == 0)
+               error = bus_dmamem_map(sc->tl_dmatag, &segs, nsegs, 
+                   sizeof(struct tl_Tx_list) * TL_NBUF,
+                   (caddr_t*)&sc->hw_Tx_list,
+                   BUS_DMA_WAITOK | BUS_DMA_COHERENT);
+       if (error == 0)
+               error = bus_dmamap_load(sc->tl_dmatag, sc->Tx_dmamap,
+                   sc->hw_Tx_list, sizeof(struct tl_Tx_list) * TL_NBUF, NULL,
+                   BUS_DMA_WAITOK);
+       if (error) {
+               errstring = "can't allocate DMA memory for lists";
+               goto bad;
+       }
+       memset(sc->hw_Rx_list, 0, sizeof(struct tl_Rx_list) * TL_NBUF);
+       memset(sc->hw_Tx_list, 0, sizeof(struct tl_Tx_list) * TL_NBUF);
        for (i=0; i< TL_NBUF; i++) {
-               if (tl_add_RxBuff(&sc->Rx_list[i], NULL) == 0) {
-                       printf("%s: out of mbuf for receive list\n",
-                           sc->sc_dev.dv_xname);
-                       sc->tl_if.if_flags &= ~IFF_UP;
-                       splx(s);
-                       return ENOMEM;
+               error = bus_dmamap_create(sc->tl_dmatag, MCLBYTES,
+                   1, MCLBYTES, 0, BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
+                   &sc->Rx_list[i].m_dmamap);
+               if (error == 0) {
+                       error = bus_dmamap_create(sc->tl_dmatag, MCLBYTES,
+                           TL_NSEG, MCLBYTES, 0,
+                           BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
+                           &sc->Tx_list[i].m_dmamap);
+               }
+               if (error) {
+                       errstring = "can't allocate DMA maps for mbufs";
+                       goto bad;
+               }
+               sc->Rx_list[i].hw_list = &sc->hw_Rx_list[i];
+               sc->Rx_list[i].hw_listaddr = sc->Rx_dmamap->dm_segs[0].ds_addr
+                   + sizeof(struct tl_Rx_list) * i;
+               sc->Tx_list[i].hw_list = &sc->hw_Tx_list[i];
+               sc->Tx_list[i].hw_listaddr = sc->Tx_dmamap->dm_segs[0].ds_addr
+                   + sizeof(struct tl_Tx_list) * i;
+               if (tl_add_RxBuff(sc, &sc->Rx_list[i], NULL) == 0) {
+                       errstring = "out of mbuf for receive list";
+                       error = ENOMEM;
+                       goto bad;
                }
                if (i > 0) { /* chain the list */
                        sc->Rx_list[i-1].next = &sc->Rx_list[i];
-                       sc->Rx_list[i-1].hw_list.fwd =
-                           vtophys((vaddr_t)&sc->Rx_list[i].hw_list);
-#ifdef DIAGNOSTIC
-                       if (sc->Rx_list[i-1].hw_list.fwd & 0x7)
-                               printf("%s: physical addr 0x%x of list not "
-                                   "properly aligned\n",
-                                   sc->sc_dev.dv_xname,
-                                   sc->Rx_list[i-1].hw_list.fwd);
-#endif
+                       sc->hw_Rx_list[i-1].fwd =
+                           htole32(sc->Rx_list[i].hw_listaddr);
                        sc->Tx_list[i-1].next = &sc->Tx_list[i];
                }
        }
+       sc->hw_Rx_list[TL_NBUF-1].fwd = 0;
        sc->Rx_list[TL_NBUF-1].next = NULL;
-       sc->Rx_list[TL_NBUF-1].hw_list.fwd = 0;
+       sc->hw_Tx_list[TL_NBUF-1].fwd = 0;
        sc->Tx_list[TL_NBUF-1].next = NULL;
 
        sc->active_Rx = &sc->Rx_list[0];
        sc->last_Rx   = &sc->Rx_list[TL_NBUF-1];
        sc->active_Tx = sc->last_Tx = NULL;
        sc->Free_Tx   = &sc->Tx_list[0];
+       bus_dmamap_sync(sc->tl_dmatag, sc->Rx_dmamap, 0,
+           sizeof(struct tl_Rx_list) * TL_NBUF,
+           BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
+       bus_dmamap_sync(sc->tl_dmatag, sc->Tx_dmamap, 0,
+           sizeof(struct tl_Tx_list) * TL_NBUF,
+           BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
 
-       if (nullbuf == NULL)
-               nullbuf = malloc(ETHER_MIN_TX, M_DEVBUF, M_NOWAIT);
        if (nullbuf == NULL) {
-               printf("%s: can't allocate space for pad buffer\n",
-                   sc->sc_dev.dv_xname);
-               sc->tl_if.if_flags &= ~IFF_UP;
-               splx(s);
-               return ENOMEM;
+               error = bus_dmamap_create(sc->tl_dmatag,
+                   ETHER_MIN_TX, 1,
+                   ETHER_MIN_TX, 0, BUS_DMA_WAITOK,
+                   &nullbuf_dmamap);
+               if (error == 0)
+                       error = bus_dmamem_alloc(sc->tl_dmatag, ETHER_MIN_TX, 0,
+                           PAGE_SIZE, &segs, 1, &nsegs, BUS_DMA_WAITOK);
+               if (error == 0)
+                       error = bus_dmamem_map(sc->tl_dmatag, &segs, nsegs, 
+                           ETHER_MIN_TX, (caddr_t*)&nullbuf, BUS_DMA_WAITOK);
+               if (error == 0)
+                       error = bus_dmamap_load(sc->tl_dmatag, nullbuf_dmamap,
+                           nullbuf, ETHER_MIN_TX, NULL, BUS_DMA_WAITOK);
+       }
+       if (error) {
+               errstring = "can't allocate space for pad buffer";
+               goto bad;
        }
        memset(nullbuf, 0, ETHER_MIN_TX);
+       bus_dmamap_sync(sc->tl_dmatag, nullbuf_dmamap, 0, ETHER_MIN_TX,
+           BUS_DMASYNC_PREWRITE);
 
        /* set media */



Home | Main Index | Thread Index | Old Index