Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/next68k add receive ethernet bpf tap



details:   https://anonhg.NetBSD.org/src/rev/7770613868ee
branches:  trunk
changeset: 508646:7770613868ee
user:      dbj <dbj%NetBSD.org@localhost>
date:      Mon Apr 16 14:12:12 2001 +0000

description:
add receive ethernet bpf tap
keep receive ethernet crc and set M_HASFCS
change bus_dma MD fields to keep xfer_len for entire map
  instead of per segment
turn off automatic dma restarts in preparation for changing
  scsi driver to handle them.
add dma debugging routines to keep history of dma states
tweak checking for unusual dma limit register

diffstat:

 sys/arch/next68k/dev/esp.c         |    9 +-
 sys/arch/next68k/dev/mb8795.c      |   39 +++---
 sys/arch/next68k/dev/nextdma.c     |  227 +++++++++++++++++++++++++-----------
 sys/arch/next68k/include/bus_dma.h |    9 +-
 4 files changed, 185 insertions(+), 99 deletions(-)

diffs (truncated from 561 to 300 lines):

diff -r be6301238eca -r 7770613868ee sys/arch/next68k/dev/esp.c
--- a/sys/arch/next68k/dev/esp.c        Mon Apr 16 13:45:31 2001 +0000
+++ b/sys/arch/next68k/dev/esp.c        Mon Apr 16 14:12:12 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: esp.c,v 1.32 2001/04/07 11:29:50 dbj Exp $     */
+/*     $NetBSD: esp.c,v 1.33 2001/04/16 14:12:12 dbj Exp $     */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -1051,20 +1051,19 @@
        }
 #endif
 
-#ifdef DIAGNOSTIC
+#if defined(DIAGNOSTIC)
        {
                int i;
                for(i=0;i<map->dm_nsegs;i++) {
-                       if (map->dm_segs[i].ds_xfer_len != map->dm_segs[i].ds_len) {
+                       if (map->dm_xfer_len != map->dm_mapsize) {
                                printf("%s: map->dm_mapsize = %d\n", sc->sc_dev.dv_xname,map->dm_mapsize);
                                printf("%s: map->dm_nsegs = %d\n", sc->sc_dev.dv_xname,map->dm_nsegs);
+                               printf("%s: map->dm_xfer_len = %d\n", sc->sc_dev.dv_xname,map->dm_xfer_len);
                                for(i=0;i<map->dm_nsegs;i++) {
                                        printf("%s: map->dm_segs[%d].ds_addr = 0x%08lx\n",
                                                        sc->sc_dev.dv_xname,i,map->dm_segs[i].ds_addr);
                                        printf("%s: map->dm_segs[%d].ds_len = %d\n",
                                                        sc->sc_dev.dv_xname,i,map->dm_segs[i].ds_len);
-                                       printf("%s: map->dm_segs[%d].ds_xfer_len = %d\n",
-                                                       sc->sc_dev.dv_xname,i,map->dm_segs[i].ds_xfer_len);
                                }
                                panic("%s: incomplete dma transfer\n",sc->sc_dev.dv_xname);
                        }
diff -r be6301238eca -r 7770613868ee sys/arch/next68k/dev/mb8795.c
--- a/sys/arch/next68k/dev/mb8795.c     Mon Apr 16 13:45:31 2001 +0000
+++ b/sys/arch/next68k/dev/mb8795.c     Mon Apr 16 14:12:12 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mb8795.c,v 1.21 2001/04/02 05:29:43 dbj Exp $  */
+/*     $NetBSD: mb8795.c,v 1.22 2001/04/16 14:12:12 dbj Exp $  */
 /*
  * Copyright (c) 1998 Darrin B. Jewell
  * All rights reserved.
@@ -312,6 +312,10 @@
                        map = sc->sc_rx_dmamap[sc->sc_rx_handled_idx];
                        m = sc->sc_rx_mb_head[sc->sc_rx_handled_idx];
 
+                       m->m_pkthdr.len = m->m_len = map->dm_xfer_len;
+                       m->m_flags |= M_HASFCS;
+                       m->m_pkthdr.rcvif = ifp;
+
                        bus_dmamap_sync(sc->sc_rx_dmat, map,
                                        0, map->dm_mapsize, BUS_DMASYNC_POSTREAD);
 
@@ -322,22 +326,16 @@
                        sc->sc_rx_mb_head[sc->sc_rx_handled_idx] = 
                                        mb8795_rxdmamap_load(sc,map);
 
-                       /* Punt runt packets, these may be caused by dma restarts */
-                       /* @@@ assumes packet is all in first segment */
-                       if (map->dm_segs[0].ds_xfer_len < ETHER_MIN_LEN) {
+                       /* Punt runt packets
+                        * dma restarts create 0 length packets for example
+                        */
+                       if (m->m_len < ETHER_MIN_LEN) {
                                m_freem(m);
                                continue;
                        }
 
-                       /* Find receive length and chop off CRC */
-                       /* @@@ assumes packet is all in first segment
-                        */
-                       m->m_pkthdr.len = map->dm_segs[0].ds_xfer_len-4;
-                       m->m_len = map->dm_segs[0].ds_xfer_len-4;
-
-                       m->m_pkthdr.rcvif = ifp;
-
-                       /* enable interrupts while we process the packet */
+                       /* Find receive length, keep crc */
+                       /* enable dma interrupts while we process the packet */
                        splx(s);
 
 #if defined(XE_DEBUG)
@@ -350,7 +348,15 @@
                                xe_hex_dump(mtod(m,u_char *), m->m_pkthdr.len < 255 ? m->m_pkthdr.len : 128 );
                        }
 #endif
-               
+
+#if NBPFILTER > 0
+                       /*
+                        * Pass packet to bpf if there is a listener.
+                        */
+                       if (ifp->if_bpf)
+                               bpf_mtap(ifp->if_bpf, m);
+#endif
+
                        {
                                ifp->if_ipackets++;
 
@@ -933,11 +939,6 @@
 
   DPRINTF(("%s: mb8795_rxdma_shutdown(), restarting.\n",sc->sc_dev.dv_xname));
 
-#if 0
-       /* Back up the dma pointers to only those that are completed */
-       sc->sc_rx_loaded_idx = sc->sc_rx_completed_idx;
-#endif
-
        nextdma_start(sc->sc_rx_nd, DMACSR_SETREAD);
 }
 
diff -r be6301238eca -r 7770613868ee sys/arch/next68k/dev/nextdma.c
--- a/sys/arch/next68k/dev/nextdma.c    Mon Apr 16 13:45:31 2001 +0000
+++ b/sys/arch/next68k/dev/nextdma.c    Mon Apr 16 14:12:12 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nextdma.c,v 1.25 2001/04/07 13:02:55 dbj Exp $ */
+/*     $NetBSD: nextdma.c,v 1.26 2001/04/16 14:12:12 dbj Exp $ */
 /*
  * Copyright (c) 1998 Darrin B. Jewell
  * All rights reserved.
@@ -64,6 +64,85 @@
 #define DPRINTF(x)
 #endif
 
+#if defined(ND_DEBUG)
+int nextdma_debug_enetr_idx = 0;
+unsigned int nextdma_debug_enetr_state[100] = { 0 };
+int nextdma_debug_scsi_idx = 0;
+unsigned int nextdma_debug_scsi_state[100] = { 0 };
+
+void nextdma_debug_initstate(struct nextdma_config *nd);
+void nextdma_debug_savestate(struct nextdma_config *nd, unsigned int state);
+void nextdma_debug_scsi_dumpstate(void);
+void nextdma_debug_enetr_dumpstate(void);
+
+void
+nextdma_debug_initstate(struct nextdma_config *nd)
+{
+       switch(nd->nd_intr) {
+       case NEXT_I_ENETR_DMA:
+               memset(nextdma_debug_enetr_state,0,sizeof(nextdma_debug_enetr_state));
+               break;
+       case NEXT_I_SCSI_DMA:
+               memset(nextdma_debug_scsi_state,0,sizeof(nextdma_debug_scsi_state));
+               break;
+       }
+}
+
+void
+nextdma_debug_savestate(struct nextdma_config *nd, unsigned int state)
+{
+       switch(nd->nd_intr) {
+       case NEXT_I_ENETR_DMA:
+               nextdma_debug_enetr_state[nextdma_debug_enetr_idx++] = state;
+               nextdma_debug_enetr_idx %= (sizeof(nextdma_debug_enetr_state)/sizeof(unsigned int));
+               break;
+       case NEXT_I_SCSI_DMA:
+               nextdma_debug_scsi_state[nextdma_debug_scsi_idx++] = state;
+               nextdma_debug_scsi_idx %= (sizeof(nextdma_debug_scsi_state)/sizeof(unsigned int));
+               break;
+       }
+}
+
+void
+nextdma_debug_enetr_dumpstate(void)
+{
+       int i;
+       int s;
+       s = spldma();
+       i = nextdma_debug_enetr_idx;
+       do {
+               char sbuf[256];
+               if (nextdma_debug_enetr_state[i]) {
+                       bitmask_snprintf(nextdma_debug_enetr_state[i], DMACSR_BITS, sbuf, sizeof(sbuf));
+                       printf("DMA: 0x%02x state 0x%s\n",i,sbuf);
+               }
+               i++;
+               i %= (sizeof(nextdma_debug_enetr_state)/sizeof(unsigned int));
+       } while (i != nextdma_debug_enetr_idx);
+       splx(s);
+}
+
+void
+nextdma_debug_scsi_dumpstate(void)
+{
+       int i;
+       int s;
+       s = spldma();
+       i = nextdma_debug_scsi_idx;
+       do {
+               char sbuf[256];
+               if (nextdma_debug_scsi_state[i]) {
+                       bitmask_snprintf(nextdma_debug_scsi_state[i], DMACSR_BITS, sbuf, sizeof(sbuf));
+                       printf("DMA: 0x%02x state 0x%s\n",i,sbuf);
+               }
+               i++;
+               i %= (sizeof(nextdma_debug_scsi_state)/sizeof(unsigned int));
+       } while (i != nextdma_debug_scsi_idx);
+       splx(s);
+}
+#endif
+
+
 void next_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
                        bus_size_t, int));
 int next_dma_continue __P((struct nextdma_config *));
@@ -172,7 +251,10 @@
        if (nextdma_debug) next_dma_print(nd);
 #endif
 
-       /* @@@ clean up dma maps */
+       if ((nd->_nd_map) || (nd->_nd_map_cont)) {
+               /* @@@ clean up dma maps */
+               panic("DMA abort not implemented\n");
+       }
 
        nextdma_init(nd);
        splx(s);
@@ -200,6 +282,9 @@
                                        (++nd->_nd_idx_cont >= nd->_nd_map_cont->dm_nsegs))) {
                if (nd->nd_continue_cb) {
                        nd->_nd_map_cont = (*nd->nd_continue_cb)(nd->nd_cb_arg);
+                       if (nd->_nd_map_cont) {
+                               nd->_nd_map_cont->dm_xfer_len = 0;
+                       }
                } else {
                        nd->_nd_map_cont = 0;
                }
@@ -208,12 +293,6 @@
 
 #ifdef DIAGNOSTIC
        if (nd->_nd_map_cont) {
-               nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_xfer_len = 666666666;
-       }
-#endif
-
-#ifdef DIAGNOSTIC
-       if (nd->_nd_map_cont) {
                if (!DMA_BEGINALIGNED(nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr)) {
                        next_dma_print(nd);
                        panic("DMA request unaligned at start\n");
@@ -244,10 +323,6 @@
                dd_stop  = (nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr +
                                nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len);
 
-#ifdef DIAGNOSTIC
-               nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_xfer_len = 555555555;
-#endif
-
                if (nd->nd_intr == NEXT_I_ENETX_DMA) {
                        dd_stop |= 0x80000000;          /* Ethernet transmit needs secret magic */
                }
@@ -293,10 +368,6 @@
                dd_limit = (nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr +
                                nd->_nd_map->dm_segs[nd->_nd_idx].ds_len);
 
-#ifdef DIAGNOSTIC
-               nd->_nd_map->dm_segs[nd->_nd_idx].ds_xfer_len = 444444444;
-#endif
-
                if (nd->nd_intr == NEXT_I_ENETX_DMA) {
                        dd_limit |= 0x80000000; /* Ethernet transmit needs secret magic */
                }
@@ -378,12 +449,12 @@
                                nd->_nd_map->dm_mapsize);
                printf("NDMAP: nd->_nd_map->dm_nsegs = %d\n",
                                nd->_nd_map->dm_nsegs);
+               printf("NDMAP: nd->_nd_map->dm_xfer_len = %d\n",
+                               nd->_nd_map->dm_xfer_len);
                printf("NDMAP: nd->_nd_map->dm_segs[%d].ds_addr = 0x%08lx\n",
                                nd->_nd_idx,nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr);
                printf("NDMAP: nd->_nd_map->dm_segs[%d].ds_len = %d\n",
                                nd->_nd_idx,nd->_nd_map->dm_segs[nd->_nd_idx].ds_len);
-               printf("NDMAP: nd->_nd_map->dm_segs[%d].ds_xfer_len = %d\n",
-                               nd->_nd_idx,nd->_nd_map->dm_segs[nd->_nd_idx].ds_xfer_len);
                {
                        int i;
                        printf("NDMAP: Entire map;\n");
@@ -392,8 +463,6 @@
                                                i,nd->_nd_map->dm_segs[i].ds_addr);
                                printf("NDMAP:   nd->_nd_map->dm_segs[%d].ds_len = %d\n",
                                                i,nd->_nd_map->dm_segs[i].ds_len);
-                               printf("NDMAP:   nd->_nd_map->dm_segs[%d].ds_xfer_len = %d\n",
-                                               i,nd->_nd_map->dm_segs[i].ds_xfer_len);
                        }
                }
        } else {
@@ -404,12 +473,12 @@
                                nd->_nd_map_cont->dm_mapsize);
                printf("NDMAP: nd->_nd_map_cont->dm_nsegs = %d\n",
                                nd->_nd_map_cont->dm_nsegs);
+               printf("NDMAP: nd->_nd_map_cont->dm_xfer_len = %d\n",
+                               nd->_nd_map_cont->dm_xfer_len);
                printf("NDMAP: nd->_nd_map_cont->dm_segs[%d].ds_addr = 0x%08lx\n",
                                nd->_nd_idx_cont,nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr);
                printf("NDMAP: nd->_nd_map_cont->dm_segs[%d].ds_len = %d\n",
                                nd->_nd_idx_cont,nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len);
-               printf("NDMAP: nd->_nd_map_cont->dm_segs[%d].ds_xfer_len = %d\n",
-                               nd->_nd_idx_cont,nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_xfer_len);
                if (nd->_nd_map_cont != nd->_nd_map) {



Home | Main Index | Thread Index | Old Index