Module Name:    src
Committed By:   thorpej
Date:           Wed Jan 29 14:17:27 UTC 2020

Modified Files:
        src/sys/dev/ic: elink3.c elinkxl.c

Log Message:
Adopt <net/if_stats.h>.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/dev/ic/elink3.c
cvs rdiff -u -r1.133 -r1.134 src/sys/dev/ic/elinkxl.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/dev/ic/elink3.c
diff -u src/sys/dev/ic/elink3.c:1.149 src/sys/dev/ic/elink3.c:1.150
--- src/sys/dev/ic/elink3.c:1.149	Wed May 29 06:17:28 2019
+++ src/sys/dev/ic/elink3.c	Wed Jan 29 14:17:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: elink3.c,v 1.149 2019/05/29 06:17:28 msaitoh Exp $	*/
+/*	$NetBSD: elink3.c,v 1.150 2020/01/29 14:17:27 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: elink3.c,v 1.149 2019/05/29 06:17:28 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: elink3.c,v 1.150 2020/01/29 14:17:27 thorpej Exp $");
 
 #include "opt_inet.h"
 
@@ -1123,7 +1123,7 @@ startagain:
 	 */
 	if (len + pad > ETHER_MAX_LEN) {
 		/* packet is obviously too large: toss it */
-		++ifp->if_oerrors;
+		if_statinc(ifp, if_oerrors);
 		IFQ_DEQUEUE(&ifp->if_snd, m0);
 		m_freem(m0);
 		goto readcheck;
@@ -1229,7 +1229,7 @@ startagain:
 
 	splx(sh);
 
-	++ifp->if_opackets;
+	if_statinc(ifp, if_opackets);
 
 readcheck:
 	if ((bus_space_read_2(iot, ioh, ep_w1_reg(sc, ELINK_W1_RX_STATUS)) &
@@ -1318,6 +1318,7 @@ eptxstat(struct ep_softc *sc)
 {
 	bus_space_tag_t iot = sc->sc_iot;
 	bus_space_handle_t ioh = sc->sc_ioh;
+	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
 	int i;
 
 	/*
@@ -1330,13 +1331,13 @@ eptxstat(struct ep_softc *sc)
 		    0x0);
 
 		if (i & TXS_JABBER) {
-			++sc->sc_ethercom.ec_if.if_oerrors;
+			if_statinc(ifp, if_oerrors);
 			if (sc->sc_ethercom.ec_if.if_flags & IFF_DEBUG)
 				printf("%s: jabber (%x)\n",
 				       device_xname(sc->sc_dev), i);
 			epreset(sc);
 		} else if (i & TXS_UNDERRUN) {
-			++sc->sc_ethercom.ec_if.if_oerrors;
+			if_statinc(ifp, if_oerrors);
 			if (sc->sc_ethercom.ec_if.if_flags & IFF_DEBUG)
 				printf("%s: fifo underrun (%x) @%d\n",
 				       device_xname(sc->sc_dev), i,
@@ -1347,7 +1348,7 @@ eptxstat(struct ep_softc *sc)
 			sc->tx_succ_ok = 0;
 			epreset(sc);
 		} else if (i & TXS_MAX_COLLISION) {
-			++sc->sc_ethercom.ec_if.if_collisions;
+			if_statinc(ifp, if_collisions);
 			bus_space_write_2(iot, ioh, ELINK_COMMAND, TX_ENABLE);
 			sc->sc_ethercom.ec_if.if_flags &= ~IFF_OACTIVE;
 		} else
@@ -1472,7 +1473,7 @@ again:
 		return;
 
 	if (len & ERR_RX) {
-		++ifp->if_ierrors;
+		if_statinc(ifp, if_ierrors);
 		goto abort;
 	}
 
@@ -1481,7 +1482,7 @@ again:
 	/* Pull packet off interface. */
 	m = epget(sc, len);
 	if (m == 0) {
-		ifp->if_ierrors++;
+		if_statinc(ifp, if_ierrors);
 		goto abort;
 	}
 
@@ -1713,7 +1714,7 @@ epwatchdog(struct ifnet *ifp)
 	struct ep_softc *sc = ifp->if_softc;
 
 	log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
-	++sc->sc_ethercom.ec_if.if_oerrors;
+	if_statinc(ifp, if_oerrors);
 
 	epreset(sc);
 }

Index: src/sys/dev/ic/elinkxl.c
diff -u src/sys/dev/ic/elinkxl.c:1.133 src/sys/dev/ic/elinkxl.c:1.134
--- src/sys/dev/ic/elinkxl.c:1.133	Wed Oct 30 07:26:28 2019
+++ src/sys/dev/ic/elinkxl.c	Wed Jan 29 14:17:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: elinkxl.c,v 1.133 2019/10/30 07:26:28 msaitoh Exp $	*/
+/*	$NetBSD: elinkxl.c,v 1.134 2020/01/29 14:17:27 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: elinkxl.c,v 1.133 2019/10/30 07:26:28 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: elinkxl.c,v 1.134 2020/01/29 14:17:27 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -86,7 +86,6 @@ void ex_read(struct ex_softc *);
 void ex_reset(struct ex_softc *);
 void ex_set_mc(struct ex_softc *);
 void ex_getstats(struct ex_softc *);
-void ex_printstats(struct ex_softc *);
 void ex_tick(void *);
 
 static int ex_eeprom_busy(struct ex_softc *);
@@ -814,7 +813,7 @@ ex_txstat(struct ex_softc *sc)
 		/* Resetting takes a while and we will do more than wait. */
 
 		ifp->if_flags &= ~IFF_OACTIVE;
-		++sc->sc_ethercom.ec_if.if_oerrors;
+		if_statinc(ifp, if_oerrors);
 		aprint_error_dev(sc->sc_dev, "%s%s%s",
 		    (err & TXS_UNDERRUN) ? " transmit underrun" : "",
 		    (err & TXS_JABBER) ? " jabber" : "",
@@ -834,7 +833,7 @@ ex_txstat(struct ex_softc *sc)
 		}
 		aprint_error("\n");
 		if (err & TXS_MAX_COLLISION)
-			++sc->sc_ethercom.ec_if.if_collisions;
+			if_statinc(ifp, if_collisions);
 
 		/* Wait for TX_RESET to finish. */
 		ex_waitcmd(sc);
@@ -843,7 +842,7 @@ ex_txstat(struct ex_softc *sc)
 		ex_setup_tx(sc);
 	} else {
 		if (err & TXS_MAX_COLLISION)
-			++sc->sc_ethercom.ec_if.if_collisions;
+			if_statinc(ifp, if_collisions);
 		sc->sc_ethercom.ec_if.if_flags &= ~IFF_OACTIVE;
 	}
 
@@ -1367,7 +1366,7 @@ ex_intr(void *arg)
 					    ((sc->sc_ethercom.ec_capenable &
 					    ETHERCAP_VLAN_MTU) ?
 					    EX_UPD_ERR_VLAN : EX_UPD_ERR)) {
-						ifp->if_ierrors++;
+						if_statinc(ifp, if_ierrors);
 						m_freem(m);
 						goto rcvloop;
 					}
@@ -1485,18 +1484,26 @@ ex_getstats(struct ex_softc *sc)
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
 	uint8_t upperok;
 
+	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
+
 	GO_WINDOW(6);
 	upperok = bus_space_read_1(iot, ioh, UPPER_FRAMES_OK);
-	ifp->if_opackets += bus_space_read_1(iot, ioh, TX_FRAMES_OK);
-	ifp->if_opackets += (upperok & 0x30) << 4;
-	ifp->if_ierrors += bus_space_read_1(iot, ioh, RX_OVERRUNS);
-	ifp->if_collisions += bus_space_read_1(iot, ioh, TX_COLLISIONS);
+	if_statadd_ref(nsr, if_opackets,
+	    bus_space_read_1(iot, ioh, TX_FRAMES_OK));
+	if_statadd_ref(nsr, if_opackets, (upperok & 0x30) << 4);
+	if_statadd_ref(nsr, if_ierrors,
+	    bus_space_read_1(iot, ioh, RX_OVERRUNS));
+	if_statadd_ref(nsr, if_collisions,
+	    bus_space_read_1(iot, ioh, TX_COLLISIONS));
 	/*
 	 * There seems to be no way to get the exact number of collisions,
 	 * this is the number that occurred at the very least.
 	 */
-	ifp->if_collisions += 2 * bus_space_read_1(iot, ioh,
-	    TX_AFTER_X_COLLISIONS);
+	if_statadd_ref(nsr, if_collisions,
+	    2 * bus_space_read_1(iot, ioh, TX_AFTER_X_COLLISIONS));
+
+	IF_STAT_PUTREF(ifp);
+
 	/*
 	 * Interface byte counts are counted by ether_input() and
 	 * ether_output(), so don't accumulate them here.  Just
@@ -1520,21 +1527,6 @@ ex_getstats(struct ex_softc *sc)
 }
 
 void
-ex_printstats(struct ex_softc *sc)
-{
-	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
-
-	ex_getstats(sc);
-	printf("in %llu out %llu ierror %llu oerror %llu ibytes %llu obytes "
-	    "%llu\n", (unsigned long long)ifp->if_ipackets,
-	    (unsigned long long)ifp->if_opackets,
-	    (unsigned long long)ifp->if_ierrors,
-	    (unsigned long long)ifp->if_oerrors,
-	    (unsigned long long)ifp->if_ibytes,
-	    (unsigned long long)ifp->if_obytes);
-}
-
-void
 ex_tick(void *arg)
 {
 	struct ex_softc *sc = arg;
@@ -1580,7 +1572,7 @@ ex_watchdog(struct ifnet *ifp)
 	struct ex_softc *sc = ifp->if_softc;
 
 	log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
-	++sc->sc_ethercom.ec_if.if_oerrors;
+	if_statinc(ifp, if_oerrors);
 
 	ex_reset(sc);
 	ex_init(ifp);

Reply via email to