Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Jan 2021 17:32:36 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 3160b2d53b38 - stable/12 - mvneta: Fix 64-bit MIB reads
Message-ID:  <202101181732.10IHWa8A085251@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=3160b2d53b38224f39fc2a6d75dedde27dd9cc89

commit 3160b2d53b38224f39fc2a6d75dedde27dd9cc89
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-01-04 13:22:21 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-01-18 16:59:23 +0000

    mvneta: Fix 64-bit MIB reads
    
    It appears we must read MIB values as 2 4-byte words, lower address
    first.  A single 8-byte MIB read returns the value with the lower 4
    bytes copied into the upper 4 bytes, resulting in bogus byte counter
    values.
    
    Reviewed by:    mw
    Sponsored by:   Rubicon Communications, LLC (Netgate)
    Differential Revision:  https://reviews.freebsd.org/D27870
    
    (cherry picked from commit caf552a607191ffc798e3edb697ae99d5b15711a)
---
 sys/dev/neta/if_mvneta.c    | 36 ++++++++++++++++++------------------
 sys/dev/neta/if_mvnetavar.h |  4 +---
 2 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/sys/dev/neta/if_mvneta.c b/sys/dev/neta/if_mvneta.c
index 9b0b2384d74b..ac15057445ee 100644
--- a/sys/dev/neta/if_mvneta.c
+++ b/sys/dev/neta/if_mvneta.c
@@ -186,6 +186,7 @@ STATIC void sysctl_mvneta_init(struct mvneta_softc *);
 
 /* MIB */
 STATIC void mvneta_clear_mib(struct mvneta_softc *);
+STATIC uint64_t mvneta_read_mib(struct mvneta_softc *, int);
 STATIC void mvneta_update_mib(struct mvneta_softc *);
 
 /* Switch */
@@ -1079,7 +1080,7 @@ STATIC int
 mvneta_initreg(struct ifnet *ifp)
 {
 	struct mvneta_softc *sc;
-	int q, i;
+	int q;
 	uint32_t reg;
 
 	sc = ifp->if_softc;
@@ -1166,14 +1167,7 @@ mvneta_initreg(struct ifnet *ifp)
 	MVNETA_WRITE(sc, MVNETA_PXCX, reg);
 
 	/* clear MIB counter registers(clear by read) */
-	for (i = 0; i < nitems(mvneta_mib_list); i++) {
-		if (mvneta_mib_list[i].reg64)
-			MVNETA_READ_MIB_8(sc, mvneta_mib_list[i].regnum);
-		else
-			MVNETA_READ_MIB_4(sc, mvneta_mib_list[i].regnum);
-	}
-	MVNETA_READ(sc, MVNETA_PDFC);
-	MVNETA_READ(sc, MVNETA_POFC);
+	mvneta_clear_mib(sc);
 
 	/* Set SDC register except IPGINT bits */
 	reg  = MVNETA_SDC_RXBSZ_16_64BITWORDS;
@@ -3489,6 +3483,19 @@ sysctl_mvneta_init(struct mvneta_softc *sc)
 /*
  * MIB
  */
+STATIC uint64_t
+mvneta_read_mib(struct mvneta_softc *sc, int index)
+{
+	struct mvneta_mib_def *mib;
+	uint64_t val;
+
+	mib = &mvneta_mib_list[index];
+	val = MVNETA_READ_MIB(sc, mib->regnum);
+	if (mib->reg64)
+		val |= (uint64_t)MVNETA_READ_MIB(sc, mib->regnum + 4) << 32;
+	return (val);
+}
+
 STATIC void
 mvneta_clear_mib(struct mvneta_softc *sc)
 {
@@ -3497,10 +3504,7 @@ mvneta_clear_mib(struct mvneta_softc *sc)
 	KASSERT_SC_MTX(sc);
 
 	for (i = 0; i < nitems(mvneta_mib_list); i++) {
-		if (mvneta_mib_list[i].reg64)
-			MVNETA_READ_MIB_8(sc, mvneta_mib_list[i].regnum);
-		else
-			MVNETA_READ_MIB_4(sc, mvneta_mib_list[i].regnum);
+		(void)mvneta_read_mib(sc, i);
 		sc->sysctl_mib[i].counter = 0;
 	}
 	MVNETA_READ(sc, MVNETA_PDFC);
@@ -3520,11 +3524,7 @@ mvneta_update_mib(struct mvneta_softc *sc)
 
 	for (i = 0; i < nitems(mvneta_mib_list); i++) {
 
-		if (mvneta_mib_list[i].reg64)
-			val = MVNETA_READ_MIB_8(sc, mvneta_mib_list[i].regnum);
-		else
-			val = MVNETA_READ_MIB_4(sc, mvneta_mib_list[i].regnum);
-
+		val = mvneta_read_mib(sc, i);
 		if (val == 0)
 			continue;
 
diff --git a/sys/dev/neta/if_mvnetavar.h b/sys/dev/neta/if_mvnetavar.h
index 8ac37fb65bfd..ab1d476ef353 100644
--- a/sys/dev/neta/if_mvnetavar.h
+++ b/sys/dev/neta/if_mvnetavar.h
@@ -73,10 +73,8 @@
 #define	MVNETA_WRITE_REGION(sc, reg, val, c) \
 	bus_write_region_4((sc)->res[0], (reg), (val), (c))
 
-#define	MVNETA_READ_MIB_4(sc, reg) \
+#define	MVNETA_READ_MIB(sc, reg) \
 	bus_read_4((sc)->res[0], MVNETA_PORTMIB_BASE + (reg))
-#define	MVNETA_READ_MIB_8(sc, reg) \
-	bus_read_8((sc)->res[0], MVNETA_PORTMIB_BASE + (reg))
 
 #define	MVNETA_IS_LINKUP(sc) \
 	(MVNETA_READ((sc), MVNETA_PSR) & MVNETA_PSR_LINKUP)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101181732.10IHWa8A085251>