Module Name: src
Committed By: christos
Date: Tue Mar 25 19:41:32 UTC 2014
Modified Files:
src/sys/arch/next68k/dev: esp.c if_xe.c nextdma.c nextdmavar.h
Log Message:
fix sprintf debugging mess.
To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/next68k/dev/esp.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/next68k/dev/if_xe.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/next68k/dev/nextdma.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/next68k/dev/nextdmavar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/next68k/dev/esp.c
diff -u src/sys/arch/next68k/dev/esp.c:1.60 src/sys/arch/next68k/dev/esp.c:1.61
--- src/sys/arch/next68k/dev/esp.c:1.60 Sat Oct 27 13:18:05 2012
+++ src/sys/arch/next68k/dev/esp.c Tue Mar 25 15:41:32 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: esp.c,v 1.60 2012/10/27 17:18:05 chs Exp $ */
+/* $NetBSD: esp.c,v 1.61 2014/03/25 19:41:32 christos Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.60 2012/10/27 17:18:05 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.61 2014/03/25 19:41:32 christos Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -118,10 +118,7 @@ __KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.60
#ifdef ESP_DEBUG
int esp_debug = 0;
#define DPRINTF(x) if (esp_debug) printf x;
-extern char *ndtracep;
-extern char ndtrace[];
-extern int ndtraceshow;
-#define NDTRACEIF(x) if (10 && ndtracep < (ndtrace + 8192)) do {x;} while (0)
+#define NDTRACEIF(x) if (10) do {x;} while (0)
#else
#define DPRINTF(x)
#define NDTRACEIF(x)
@@ -145,6 +142,7 @@ struct ncr53c9x_softc *esp_debug_sc = 0;
void esp_dma_store(struct ncr53c9x_softc *);
void esp_dma_print(struct ncr53c9x_softc *);
int esp_dma_nest = 0;
+int esptraceshow;
#endif
@@ -461,7 +459,7 @@ esp_dma_isintr(struct ncr53c9x_softc *sc
struct esp_softc *esc = (struct esp_softc *)sc;
if (INTR_OCCURRED(NEXT_I_SCSI)) {
- NDTRACEIF (*ndtracep++ = 'i');
+ NDTRACEIF (ndtrace_addc('i'));
NCR_WRITE_REG(sc, ESP_DCTL,
ESPDCTL_16MHZ | ESPDCTL_INTENB |
(esc->sc_datain ? ESPDCTL_DMARD : 0));
@@ -487,7 +485,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
r = 1;
- NDTRACEIF (*ndtracep++ = 'I');
+ NDTRACEIF (ndtrace_addc('I'));
if (r) {
/* printf ("esp_dma_isintr start\n"); */
{
@@ -513,14 +511,13 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
while (!nextdma_finished(nsc)) {
/* esp_dma_isactive(sc)) { */
- NDTRACEIF (*ndtracep++ = 'w');
+ NDTRACEIF (ndtrace_addc('w'));
NDTRACEIF (
- sprintf(ndtracep, "f%dm%dl%dw",
+ ndtrace_printf("f%dm%dl%dw",
NCR_READ_REG(sc, NCR_FFLAG) &
NCRFIFO_FF,
NCR_READ_REG((sc), NCR_TCM),
NCR_READ_REG((sc), NCR_TCL));
- ndtracep += strlen(ndtracep);
);
if (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF)
flushcount = 5;
@@ -535,7 +532,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
(nd_bsr4 (DD_CSR) & 0x08000000) == 0&&
++flushcount < 5) {
splx(s);
- NDTRACEIF (*ndtracep++ = 'F');
+ NDTRACEIF (ndtrace_addc('F'));
NCR_WRITE_REG(sc, ESP_DCTL,
ESPDCTL_FLUSH | ESPDCTL_16MHZ |
ESPDCTL_INTENB | ESPDCTL_DMAMOD |
@@ -550,7 +547,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
doze(0x32);
s = spldma();
}
- NDTRACEIF (*ndtracep++ = '0' + flushcount);
+ NDTRACEIF (ndtrace_addc('0' + flushcount));
if (flushcount > 4) {
int next;
int onext = 0;
@@ -563,18 +560,17 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
onext = next;
DELAY(50);
}
- NDTRACEIF (*ndtracep++ = 'R');
+ NDTRACEIF (ndtrace_addc('R'));
NCR_WRITE_REG(sc, ESP_DCTL,
ESPDCTL_16MHZ | ESPDCTL_INTENB);
NDTRACEIF (
- sprintf(ndtracep,
+ ndtrace_printf(
"ff:%d tcm:%d tcl:%d ",
NCR_READ_REG(sc, NCR_FFLAG)
& NCRFIFO_FF,
NCR_READ_REG((sc), NCR_TCM),
NCR_READ_REG((sc),
NCR_TCL));
- ndtracep += strlen (ndtracep);
);
s = spldma();
nextdma_reset (nsc);
@@ -585,7 +581,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
#ifdef DIAGNOSTIC
if (flushcount > 4) {
- NDTRACEIF (*ndtracep++ = '+');
+ NDTRACEIF (ndtrace_addc('+'));
printf("%s: unexpected flushcount"
" %d on %s\n",
device_xname(sc->sc_dev),
@@ -596,7 +592,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
if (!nextdma_finished(nsc)) {
/* esp_dma_isactive(sc)) { */
- NDTRACEIF (*ndtracep++ = '1');
+ NDTRACEIF (ndtrace_addc('1'));
}
flushcount = 0;
s = spldma();
@@ -618,7 +614,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
NCR_WRITE_REG(sc, ESP_DCTL,
ESPDCTL_16MHZ | ESPDCTL_INTENB |
(esc->sc_datain ? ESPDCTL_DMARD : 0));
- NDTRACEIF (*ndtracep++ = 'b');
+ NDTRACEIF (ndtrace_addc('b'));
while (esc->sc_datain != -1)
DELAY(50);
@@ -643,7 +639,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
16 ||
NCR_READ_REG((sc),
NCR_TCL) != 240)
- ndtraceshow++;
+ esptraceshow++;
#endif
}
xfer_len = esc->sc_dmasize - resid;
@@ -709,12 +705,11 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
}
NDTRACEIF(
- sprintf(ndtracep, "f%dm%dl%ds%dx%dr%dS",
+ ndtrace_printf("f%dm%dl%ds%dx%dr%dS",
NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF,
NCR_READ_REG((sc), NCR_TCM),
NCR_READ_REG((sc), NCR_TCL),
esc->sc_dmasize, (int)xfer_len, resid);
- ndtracep += strlen(ndtracep);
);
*esc->sc_dmaaddr += xfer_len;
@@ -724,7 +719,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
esc->sc_dmasize = 0;
}
- NDTRACEIF (*ndtracep++ = 'B');
+ NDTRACEIF (ndtrace_addc('B'));
sc->sc_espstat = NCR_READ_REG(sc, NCR_STAT) |
(sc->sc_espstat & NCRSTAT_INT);
@@ -803,7 +798,7 @@ esp_dma_setup(struct ncr53c9x_softc *sc,
{
struct esp_softc *esc = (struct esp_softc *)sc;
- NDTRACEIF (*ndtracep++ = 'h');
+ NDTRACEIF (ndtrace_addc('h'));
#ifdef DIAGNOSTIC
#ifdef ESP_DEBUG
/* if this is a read DMA, pre-fill the buffer with 0xdeadbeef
@@ -972,10 +967,12 @@ esp_dma_setup(struct ncr53c9x_softc *sc,
"_dm_segcnt = %d\n",
device_xname(sc->sc_dev),
esc->sc_main_dmamap->_dm_segcnt);
+#ifdef notdef
printf("%s: esc->sc_main_dmamap->"
"_dm_maxsegsz = %ld\n",
device_xname(sc->sc_dev),
esc->sc_main_dmamap->_dm_maxsegsz);
+#endif
printf("%s: esc->sc_main_dmamap->"
"_dm_boundary = %ld\n",
device_xname(sc->sc_dev),
@@ -1152,42 +1149,44 @@ void
esp_dma_store(struct ncr53c9x_softc *sc)
{
struct esp_softc *esc = (struct esp_softc *)sc;
- char *p = &esp_dma_dump[0];
+ char *p = esp_dma_dump;
+ size_t l = 0;
+ size_t len = sizeof(esp_dma_dump);
- p += sprintf(p, "%s: sc_datain=%d\n",
+ l += snprintf(p + l, len - l, "%s: sc_datain=%d\n",
device_xname(sc->sc_dev), esc->sc_datain);
- p += sprintf(p, "%s: sc_loaded=0x%08x\n",
+ l += snprintf(p + l, len - l, "%s: sc_loaded=0x%08x\n",
device_xname(sc->sc_dev), esc->sc_loaded);
if (esc->sc_dmaaddr) {
- p += sprintf(p, "%s: sc_dmaaddr=%p\n",
+ l += snprintf(p + l, len - l, "%s: sc_dmaaddr=%p\n",
device_xname(sc->sc_dev), *esc->sc_dmaaddr);
} else {
- p += sprintf(p, "%s: sc_dmaaddr=NULL\n",
+ l += snprintf(p + l, len - l, "%s: sc_dmaaddr=NULL\n",
device_xname(sc->sc_dev));
}
if (esc->sc_dmalen) {
- p += sprintf(p, "%s: sc_dmalen=0x%08x\n",
+ l += snprintf(p + l, len - l, "%s: sc_dmalen=0x%08x\n",
device_xname(sc->sc_dev), *esc->sc_dmalen);
} else {
- p += sprintf(p, "%s: sc_dmalen=NULL\n",
+ l += snprintf(p + l, len - l, "%s: sc_dmalen=NULL\n",
device_xname(sc->sc_dev));
}
- p += sprintf(p, "%s: sc_dmasize=0x%08x\n",
+ l += snprintf(p + l, len - l, "%s: sc_dmasize=0x%08x\n",
device_xname(sc->sc_dev), esc->sc_dmasize);
- p += sprintf(p, "%s: sc_begin = %p, sc_begin_size = 0x%08x\n",
+ l += snprintf(p + l, len - l, "%s: sc_begin = %p, sc_begin_size = 0x%08x\n",
device_xname(sc->sc_dev), esc->sc_begin, esc->sc_begin_size);
- p += sprintf(p, "%s: sc_main = %p, sc_main_size = 0x%08x\n",
+ l += snprintf(p + l, len - l, "%s: sc_main = %p, sc_main_size = 0x%08x\n",
device_xname(sc->sc_dev), esc->sc_main, esc->sc_main_size);
/* if (esc->sc_main) */ {
int i;
bus_dmamap_t map = esc->sc_main_dmamap;
- p += sprintf(p, "%s: sc_main_dmamap."
+ l += snprintf(p + l, len - l, "%s: sc_main_dmamap."
" mapsize = 0x%08lx, nsegs = %d\n",
device_xname(sc->sc_dev), map->dm_mapsize, map->dm_nsegs);
for(i = 0; i < map->dm_nsegs; i++) {
- p += sprintf(p, "%s:"
+ l += snprintf(p + l, len - l, "%s:"
" map->dm_segs[%d].ds_addr = 0x%08lx,"
" len = 0x%08lx\n",
device_xname(sc->sc_dev),
@@ -1195,16 +1194,16 @@ esp_dma_store(struct ncr53c9x_softc *sc)
map->dm_segs[i].ds_len);
}
}
- p += sprintf(p, "%s: sc_tail = %p, sc_tail_size = 0x%08x\n",
+ l += snprintf(p + l, len - l, "%s: sc_tail = %p, sc_tail_size = 0x%08x\n",
device_xname(sc->sc_dev), esc->sc_tail, esc->sc_tail_size);
/* if (esc->sc_tail) */ {
int i;
bus_dmamap_t map = esc->sc_tail_dmamap;
- p += sprintf(p, "%s: sc_tail_dmamap."
+ l += snprintf(p + l, len - l, "%s: sc_tail_dmamap."
" mapsize = 0x%08lx, nsegs = %d\n",
device_xname(sc->sc_dev), map->dm_mapsize, map->dm_nsegs);
for (i = 0; i < map->dm_nsegs; i++) {
- p += sprintf(p, "%s:"
+ l += snprintf(p + l, len - l, "%s:"
" map->dm_segs[%d].ds_addr = 0x%08lx,"
" len = 0x%08lx\n",
device_xname(sc->sc_dev),
@@ -1232,15 +1231,14 @@ esp_dma_go(struct ncr53c9x_softc *sc)
/* int s = spldma(); */
#ifdef ESP_DEBUG
- if (ndtracep != ndtrace) {
- if (ndtraceshow) {
- *ndtracep = '\0';
- printf("esp ndtrace: %s\n", ndtrace);
- ndtraceshow = 0;
+ if (!ndtrace_empty()) {
+ if (esptraceshow) {
+ printf("esp ndtrace: %s\n", ndtrace_get());
+ esptraceshow = 0;
} else {
DPRINTF(("X"));
}
- ndtracep = ndtrace;
+ ndtrace_reset();
}
#endif
@@ -1339,20 +1337,20 @@ esp_dma_go(struct ncr53c9x_softc *sc)
NDTRACEIF(
if (esc->sc_begin_size) {
- *ndtracep++ = '1';
- *ndtracep++ = 'A' + esc->sc_begin_size;
+ ndtrace_addc('1');
+ ndtrace_addc('A' + esc->sc_begin_size);
}
);
NDTRACEIF(
if (esc->sc_main_size) {
- *ndtracep++ = '2';
- *ndtracep++ = '0' + esc->sc_main_dmamap->dm_nsegs;
+ ndtrace_addc('2');
+ ndtrace_addc('0' + esc->sc_main_dmamap->dm_nsegs);
}
);
NDTRACEIF(
if (esc->sc_tail_size) {
- *ndtracep++ = '3';
- *ndtracep++ = 'A' + esc->sc_tail_size;
+ ndtrace_addc('3');
+ ndtrace_addc('A' + esc->sc_tail_size);
}
);
@@ -1399,33 +1397,33 @@ int esp_dma_int(void *arg)
struct nextdma_status *stat = &nsc->sc_stat;
unsigned int state;
- NDTRACEIF (*ndtracep++ = 'E');
+ NDTRACEIF (ndtrace_addc('E'));
state = nd_bsr4 (DD_CSR);
#if 1
NDTRACEIF (
if (state & DMACSR_COMPLETE)
- *ndtracep++ = 'c';
+ ndtrace_addc('c');
if (state & DMACSR_ENABLE)
- *ndtracep++ = 'e';
+ ndtrace_addc('e');
if (state & DMACSR_BUSEXC)
- *ndtracep++ = 'b';
+ ndtrace_addc('b');
if (state & DMACSR_READ)
- *ndtracep++ = 'r';
+ ndtrace_addc('r');
if (state & DMACSR_SUPDATE)
- *ndtracep++ = 's';
+ ndtrace_addc('s');
);
- NDTRACEIF (*ndtracep++ = 'E');
+ NDTRACEIF (ndtrace_addc('E'));
#ifdef ESP_DEBUG
if (0)
if ((state & DMACSR_BUSEXC) && (state & DMACSR_ENABLE))
- ndtraceshow++;
+ esptraceshow++;
if (0)
if ((state & DMACSR_SUPDATE))
- ndtraceshow++;
+ esptraceshow++;
#endif
#endif
@@ -1465,11 +1463,10 @@ int esp_dma_int(void *arg)
#if 0
#ifdef ESP_DEBUG
if (state & DMACSR_BUSEXC) {
- sprintf(ndtracep, "CE/BUSEXC: %08lX %08X %08X\n",
+ ndtrace_printf("CE/BUSEXC: %08lX %08X %08X\n",
(stat->nd_map->dm_segs[stat->nd_idx].ds_addr +
stat->nd_map->dm_segs[stat->nd_idx].ds_len),
l, s);
- ndtracep += strlen(ndtracep);
}
#endif
#endif
@@ -1514,14 +1511,12 @@ int esp_dma_int(void *arg)
(stat->nd_map_cont ? DMACSR_SETSUPDATE : 0));
#if 1
#ifdef ESP_DEBUG
- sprintf(ndtracep, "supdate ");
- ndtracep += strlen(ndtracep);
- sprintf(ndtracep, "%08X %08X %08X %08X ",
+ ndtrace_printf("supdate ");
+ ndtrace_printf("%08X %08X %08X %08X ",
nd_bsr4(DD_NEXT),
nd_bsr4(DD_LIMIT) & 0x7FFFFFFF,
nd_bsr4 (DD_START),
nd_bsr4 (DD_STOP) & 0x7FFFFFFF);
- ndtracep += strlen(ndtracep);
#endif
#endif
stat->nd_exception++;
@@ -1533,12 +1528,11 @@ int esp_dma_int(void *arg)
if (stat->nd_map) {
#if 1
#ifdef ESP_DEBUG
- sprintf(ndtracep, "%08X %08X %08X %08X ",
+ ndtrace_printf("%08X %08X %08X %08X ",
nd_bsr4 (DD_NEXT),
nd_bsr4 (DD_LIMIT) & 0x7FFFFFFF,
nd_bsr4 (DD_START),
nd_bsr4 (DD_STOP) & 0x7FFFFFFF);
- ndtracep += strlen(ndtracep);
#endif
#endif
@@ -1579,7 +1573,7 @@ int esp_dma_int(void *arg)
(state & DMACSR_READ ?
DMACSR_SETREAD : DMACSR_SETWRITE));
#ifdef ESP_DEBUG
- /* ndtraceshow++; */
+ /* esptraceshow++; */
#endif
stat->nd_exception++;
return 1;
@@ -1589,13 +1583,12 @@ int esp_dma_int(void *arg)
restart:
#if 1
#ifdef ESP_DEBUG
- sprintf(ndtracep, "restart %08lX %08lX\n",
+ ndtrace_printf("restart %08lX %08lX\n",
stat->nd_map->dm_segs[stat->nd_idx].ds_addr,
stat->nd_map->dm_segs[stat->nd_idx].ds_addr +
stat->nd_map->dm_segs[stat->nd_idx].ds_len);
if (stat->nd_map_cont) {
- sprintf(ndtracep + strlen(ndtracep) - 1,
- " %08lX %08lX\n",
+ ndtrace_printf(" %08lX %08lX\n",
stat->nd_map_cont->dm_segs[
stat->nd_idx_cont].ds_addr,
stat->nd_map_cont->dm_segs[
@@ -1603,7 +1596,6 @@ int esp_dma_int(void *arg)
stat->nd_map_cont->dm_segs[
stat->nd_idx_cont].ds_len);
}
- ndtracep += strlen(ndtracep);
#endif
#endif
nextdma_print(nsc);
@@ -1619,14 +1611,13 @@ int esp_dma_int(void *arg)
NCR_READ_REG(sc, NCR_STEP),
NCR_READ_REG(sc, NCR_INTR), state);
#ifdef ESP_DEBUG
- *ndtracep = '\0';
- printf("ndtrace: %s\n", ndtrace);
+ printf("ndtrace: %s\n", ndtrace_get());
#endif
panic("%s: busexc/supdate occurred."
" Please email this output to [email protected].",
device_xname(sc->sc_dev));
#ifdef ESP_DEBUG
- ndtraceshow++;
+ esptraceshow++;
#endif
} else {
nd_bsw4(DD_CSR, DMACSR_CLRCOMPLETE | DMACSR_RESET);
@@ -1644,7 +1635,7 @@ esp_dmacb_continue(void *arg)
struct ncr53c9x_softc *sc = arg;
struct esp_softc *esc = (struct esp_softc *)sc;
- NDTRACEIF (*ndtracep++ = 'x');
+ NDTRACEIF (ndtrace_addc('x'));
DPRINTF(("%s: DMA continue\n", device_xname(sc->sc_dev)));
#ifdef DIAGNOSTIC
@@ -1694,7 +1685,7 @@ esp_dmacb_completed(bus_dmamap_t map, vo
struct ncr53c9x_softc *sc = (struct ncr53c9x_softc *)arg;
struct esp_softc *esc = (struct esp_softc *)sc;
- NDTRACEIF (*ndtracep++ = 'X');
+ NDTRACEIF (ndtrace_addc('X'));
DPRINTF(("%s: DMA completed\n", device_xname(sc->sc_dev)));
#ifdef DIAGNOSTIC
@@ -1804,7 +1795,7 @@ esp_dmacb_shutdown(void *arg)
struct ncr53c9x_softc *sc = (struct ncr53c9x_softc *)arg;
struct esp_softc *esc = (struct esp_softc *)sc;
- NDTRACEIF (*ndtracep++ = 'S');
+ NDTRACEIF (ndtrace_addc('S'));
DPRINTF(("%s: DMA shutdown\n", device_xname(sc->sc_dev)));
if (esc->sc_loaded == 0)
@@ -1855,9 +1846,8 @@ esp_dmacb_shutdown(void *arg)
BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE));
bus_dmamap_unload(esc->sc_dma->sc_dmat, esc->sc_main_dmamap);
NDTRACEIF (
- sprintf(ndtracep, "m%ld",
+ ndtrace_printf("m%ld",
esc->sc_main_dmamap->dm_xfer_len);
- ndtracep += strlen(ndtracep);
);
}
@@ -1875,9 +1865,8 @@ esp_dmacb_shutdown(void *arg)
(esc->sc_begin_size + esc->sc_main_size));
}
NDTRACEIF (
- sprintf(ndtracep, "t%ld",
+ ndtrace_printf("t%ld",
esc->sc_tail_dmamap->dm_xfer_len);
- ndtracep += strlen(ndtracep);
);
}
Index: src/sys/arch/next68k/dev/if_xe.c
diff -u src/sys/arch/next68k/dev/if_xe.c:1.22 src/sys/arch/next68k/dev/if_xe.c:1.23
--- src/sys/arch/next68k/dev/if_xe.c:1.22 Sat Oct 27 13:18:05 2012
+++ src/sys/arch/next68k/dev/if_xe.c Tue Mar 25 15:41:32 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: if_xe.c,v 1.22 2012/10/27 17:18:05 chs Exp $ */
+/* $NetBSD: if_xe.c,v 1.23 2014/03/25 19:41:32 christos Exp $ */
/*
* Copyright (c) 1998 Darrin B. Jewell
* All rights reserved.
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_xe.c,v 1.22 2012/10/27 17:18:05 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xe.c,v 1.23 2014/03/25 19:41:32 christos Exp $");
#include "opt_inet.h"
@@ -70,13 +70,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_xe.c,v 1.
#ifdef XE_DEBUG
int xe_debug = 0;
#define DPRINTF(x) if (xe_debug) printf x;
-extern char *ndtracep;
-extern char ndtrace[];
-extern int ndtraceshow;
-#define NDTRACEIF(x) if (10 && ndtracep < (ndtrace + 8192)) do {x;} while (0)
#else
#define DPRINTF(x)
-#define NDTRACEIF(x)
#endif
#define PRINTF(x) printf x;
Index: src/sys/arch/next68k/dev/nextdma.c
diff -u src/sys/arch/next68k/dev/nextdma.c:1.48 src/sys/arch/next68k/dev/nextdma.c:1.49
--- src/sys/arch/next68k/dev/nextdma.c:1.48 Sat Oct 27 13:18:05 2012
+++ src/sys/arch/next68k/dev/nextdma.c Tue Mar 25 15:41:32 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: nextdma.c,v 1.48 2012/10/27 17:18:05 chs Exp $ */
+/* $NetBSD: nextdma.c,v 1.49 2014/03/25 19:41:32 christos Exp $ */
/*
* Copyright (c) 1998 Darrin B. Jewell
* All rights reserved.
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nextdma.c,v 1.48 2012/10/27 17:18:05 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nextdma.c,v 1.49 2014/03/25 19:41:32 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -68,16 +68,66 @@ extern int turbo;
#if defined(ND_DEBUG)
int nextdma_debug = 0;
#define DPRINTF(x) if (NEXTDMA_DEBUG) printf x;
-int ndtraceshow = 0;
-char ndtrace[8192+100];
-char *ndtracep = ndtrace;
-#define NDTRACEIF(x) if (10 && /* (nsc->sc_chan->nd_intr == NEXT_I_SCSI_DMA) && */ ndtracep < (ndtrace + 8192)) do {x;} while (0)
+int ndtrace_show = 0;
+char ndtrace_buf[8192+100];
+size_t ndtrace_len = 0;
+#define NDTRACEIF(x) if (10) do {x;} while (0)
#else
#define DPRINTF(x)
#define NDTRACEIF(x)
#endif
#define PRINTF(x) printf x
+void
+ndtrace_printf(const char *fmt, ...) {
+#ifdef ND_DEBUG
+ int len;
+ va_list ap;
+
+ va_start(ap, fmt);
+ len = vsnprintf(ndtrace_buf + ndtrace_len, sizeof(ndtrace_buf)
+ - ndtrace_len, fmt, ap);
+ va_end(ap);
+ ndtrace_len += len;
+#endif
+}
+
+int
+ndtrace_empty(void) {
+#ifdef ND_DEBUG
+ return ndtrace_len == 0;
+#else
+ return 1;
+#endif
+}
+
+void
+ndtrace_reset(void) {
+#ifdef ND_DEBUG
+ ndtrace_len = 0;
+#endif
+}
+
+void
+ndtrace_addc(int c) {
+#ifdef ND_DEBUG
+ if (ndtrace_len < sizeof(ndtrace_buf) - 1) {
+ ndtrace_buf[ndtrace_len++] = c;
+ ndtrace_buf[ndtrace_len] = '\0';
+ }
+#endif
+}
+
+const char *
+ndtrace_get(void) {
+#ifdef ND_DEBUG
+ return ndtrace_buf;
+#else
+ return NULL;
+#endif
+}
+
+
#if defined(ND_DEBUG)
int nextdma_debug_enetr_idx = 0;
unsigned int nextdma_debug_enetr_state[100] = { 0 };
@@ -293,7 +343,7 @@ nextdma_rotate(struct nextdma_softc *nsc
{
struct nextdma_status *stat = &nsc->sc_stat;
- NDTRACEIF (*ndtracep++ = 'r');
+ NDTRACEIF (ndtrace_addc('r'));
DPRINTF(("DMA nextdma_rotate()\n"));
/* Rotate the continue map into the current map */
@@ -339,7 +389,7 @@ nextdma_setup_curr_regs(struct nextdma_s
bus_addr_t dd_saved_limit;
struct nextdma_status *stat = &nsc->sc_stat;
- NDTRACEIF (*ndtracep++ = 'C');
+ NDTRACEIF (ndtrace_addc('C'));
DPRINTF(("DMA nextdma_setup_curr_regs()\n"));
if (stat->nd_map) {
@@ -360,8 +410,7 @@ nextdma_setup_curr_regs(struct nextdma_s
dd_saved_limit = dd_limit;
NDTRACEIF (if (stat->nd_map) {
- sprintf (ndtracep, "%ld", stat->nd_map->dm_segs[stat->nd_idx].ds_len);
- ndtracep += strlen (ndtracep);
+ ndtrace_printf("%ld", stat->nd_map->dm_segs[stat->nd_idx].ds_len);
});
if (!turbo && (nsc->sc_chan->nd_intr == NEXT_I_ENETX_DMA)) {
@@ -395,7 +444,7 @@ nextdma_setup_cont_regs(struct nextdma_s
bus_addr_t dd_saved_stop;
struct nextdma_status *stat = &nsc->sc_stat;
- NDTRACEIF (*ndtracep++ = 'c');
+ NDTRACEIF (ndtrace_addc('c'));
DPRINTF(("DMA nextdma_setup_regs()\n"));
if (stat->nd_map_cont) {
@@ -416,8 +465,7 @@ nextdma_setup_cont_regs(struct nextdma_s
dd_saved_stop = dd_stop;
NDTRACEIF (if (stat->nd_map_cont) {
- sprintf (ndtracep, "%ld", stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_len);
- ndtracep += strlen (ndtracep);
+ ndtrace_printf("%ld", stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_len);
});
nd_bsw4 (DD_START, dd_start);
@@ -483,7 +531,7 @@ nextdma_enet_intr(void *arg)
return 0;
/* Handle dma interrupts */
- NDTRACEIF (*ndtracep++ = 'D');
+ NDTRACEIF (ndtrace_addc('D'));
#ifdef ND_DEBUG
if (NEXTDMA_DEBUG) {
char sbuf[256];
@@ -655,10 +703,10 @@ nextdma_enet_intr(void *arg)
if (stat->nd_map_cont == NULL) {
KASSERT(stat->nd_idx+1 == stat->nd_map->dm_nsegs);
nd_bsw4 (DD_CSR, DMACSR_CLRCOMPLETE | dmadir);
- NDTRACEIF (*ndtracep++ = 'g');
+ NDTRACEIF (ndtrace_addc('g'));
} else {
nd_bsw4 (DD_CSR, DMACSR_CLRCOMPLETE | dmadir | DMACSR_SETSUPDATE);
- NDTRACEIF (*ndtracep++ = 'G');
+ NDTRACEIF (ndtrace_addc('G'));
}
} else {
DPRINTF(("DMA: a shutdown occurred\n"));
@@ -715,7 +763,7 @@ nextdma_start(struct nextdma_softc *nsc,
{
struct nextdma_status *stat = &nsc->sc_stat;
- NDTRACEIF (*ndtracep++ = 'n');
+ NDTRACEIF (ndtrace_addc('n'));
#ifdef DIAGNOSTIC
if (!nextdma_finished(nsc)) {
char sbuf[256];
Index: src/sys/arch/next68k/dev/nextdmavar.h
diff -u src/sys/arch/next68k/dev/nextdmavar.h:1.16 src/sys/arch/next68k/dev/nextdmavar.h:1.17
--- src/sys/arch/next68k/dev/nextdmavar.h:1.16 Sat Oct 27 13:18:07 2012
+++ src/sys/arch/next68k/dev/nextdmavar.h Tue Mar 25 15:41:32 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: nextdmavar.h,v 1.16 2012/10/27 17:18:07 chs Exp $ */
+/* $NetBSD: nextdmavar.h,v 1.17 2014/03/25 19:41:32 christos Exp $ */
/*
* Copyright (c) 1998 Darrin B. Jewell
* All rights reserved.
@@ -77,3 +77,9 @@ void nextdma_reset(struct nextdma_softc
void nextdma_print(struct nextdma_softc *);
struct nextdma_softc *nextdma_findchannel(const char *);
+
+void ndtrace_printf(const char *fmt, ...) __printflike(1, 2);
+int ndtrace_empty(void);
+void ndtrace_reset(void);
+void ndtrace_addc(int);
+const char *ndtrace_get(void);