Module Name:    src
Committed By:   simonb
Date:           Sun Mar 31 12:47:33 UTC 2019

Modified Files:
        src/sys/arch/mips/sibyte/dev: sbmac.c

Log Message:
Allocate memory for for the ethernet DMA descriptor rings aligned to a
cache line boundary, as documented in the chip documentation.

Fixes SiByte ethernet which hasn't worked since the 8kB page size switch
(and just happened to work previously because the descriptor rings were
the same size as a page and so were allocated on a page boundary).


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/mips/sibyte/dev/sbmac.c

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/mips/sibyte/dev/sbmac.c
diff -u src/sys/arch/mips/sibyte/dev/sbmac.c:1.55 src/sys/arch/mips/sibyte/dev/sbmac.c:1.56
--- src/sys/arch/mips/sibyte/dev/sbmac.c:1.55	Tue Mar  5 08:25:02 2019
+++ src/sys/arch/mips/sibyte/dev/sbmac.c	Sun Mar 31 12:47:33 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sbmac.c,v 1.55 2019/03/05 08:25:02 msaitoh Exp $ */
+/* $NetBSD: sbmac.c,v 1.56 2019/03/31 12:47:33 simonb Exp $ */
 
 /*
  * Copyright 2000, 2001, 2004
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sbmac.c,v 1.55 2019/03/05 08:25:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sbmac.c,v 1.56 2019/03/31 12:47:33 simonb Exp $");
 
 #include "opt_inet.h"
 #include "opt_ns.h"
@@ -42,7 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: sbmac.c,v 1.
 #include <sys/systm.h>
 #include <sys/sockio.h>
 #include <sys/mbuf.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/kernel.h>
 #include <sys/socket.h>
 #include <sys/queue.h>
@@ -102,10 +102,9 @@ typedef enum { sbmac_state_uninit, sbmac
 
 #define	SBDMA_NEXTBUF(d, f)	((f + 1) & (d)->sbdma_dscr_mask)
 
-#define	CACHELINESIZE 32
-#define	NUMCACHEBLKS(x) (((x)+CACHELINESIZE-1)/CACHELINESIZE)
-#define	KMALLOC(x) malloc((x), M_DEVBUF, M_DONTWAIT)
-#define	KVTOPHYS(x) kvtophys((vaddr_t)(x))
+#define	CACHELINESIZE	32
+#define	NUMCACHEBLKS(x)	(((x)+CACHELINESIZE-1)/CACHELINESIZE)
+#define	KVTOPHYS(x)	kvtophys((vaddr_t)(x))
 
 #ifdef SBMACDEBUG
 #define	dprintf(x)	printf x
@@ -380,6 +379,8 @@ static void
 sbdma_initctx(sbmacdma_t *d, struct sbmac_softc *sc, int chan, int txrx,
     int maxdescr)
 {
+	uintptr_t ptr;
+
 	/*
 	 * Save away interesting stuff in the structure
 	 */
@@ -404,16 +405,15 @@ sbdma_initctx(sbmacdma_t *d, struct sbma
 	    R_MAC_DMA_REGISTER(txrx, chan, R_MAC_DMA_CUR_DSCRADDR));
 
 	/*
-	 * Allocate memory for the ring
+	 * Allocate memory for the ring.  This must be aligned to a
+	 * 32-byte cache line boundary on pass1 or pass2 silicon.
 	 */
 
 	d->sbdma_maxdescr = maxdescr;
 	d->sbdma_dscr_mask = d->sbdma_maxdescr - 1;
-
-	d->sbdma_dscrtable = (sbdmadscr_t *)
-	    KMALLOC(d->sbdma_maxdescr * sizeof(sbdmadscr_t));
-
-	memset(d->sbdma_dscrtable, 0, d->sbdma_maxdescr*sizeof(sbdmadscr_t));
+	ptr = (uintptr_t)kmem_zalloc(d->sbdma_maxdescr * sizeof(sbdmadscr_t) +
+	    CACHELINESIZE - 1, KM_SLEEP);
+	d->sbdma_dscrtable = (sbdmadscr_t *)roundup2(ptr, CACHELINESIZE);
 
 	d->sbdma_dscrtable_phys = KVTOPHYS(d->sbdma_dscrtable);
 
@@ -422,9 +422,7 @@ sbdma_initctx(sbmacdma_t *d, struct sbma
 	 */
 
 	d->sbdma_ctxtable = (struct mbuf **)
-	    KMALLOC(d->sbdma_maxdescr*sizeof(struct mbuf *));
-
-	memset(d->sbdma_ctxtable, 0, d->sbdma_maxdescr*sizeof(struct mbuf *));
+	    kmem_zalloc(d->sbdma_maxdescr * sizeof(struct mbuf *), KM_SLEEP);
 }
 
 /*

Reply via email to