Module Name:    src
Committed By:   thorpej
Date:           Wed Jan 29 14:47:08 UTC 2020

Modified Files:
        src/sys/dev/ic: gem.c hd64570.c hme.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/dev/ic/gem.c
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/ic/hd64570.c
cvs rdiff -u -r1.105 -r1.106 src/sys/dev/ic/hme.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/gem.c
diff -u src/sys/dev/ic/gem.c:1.124 src/sys/dev/ic/gem.c:1.125
--- src/sys/dev/ic/gem.c:1.124	Tue Dec 24 05:00:19 2019
+++ src/sys/dev/ic/gem.c	Wed Jan 29 14:47:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: gem.c,v 1.124 2019/12/24 05:00:19 msaitoh Exp $ */
+/*	$NetBSD: gem.c,v 1.125 2020/01/29 14:47:08 thorpej Exp $ */
 
 /*
  *
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gem.c,v 1.124 2019/12/24 05:00:19 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gem.c,v 1.125 2020/01/29 14:47:08 thorpej Exp $");
 
 #include "opt_inet.h"
 
@@ -1642,15 +1642,17 @@ gem_tint(struct gem_softc *sc)
 	int progress = 0;
 	uint32_t v;
 
+	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
+
 	DPRINTF(sc, ("%s: gem_tint\n", device_xname(sc->sc_dev)));
 
 	/* Unload collision counters ... */
 	v = bus_space_read_4(t, mac, GEM_MAC_EXCESS_COLL_CNT) +
 	    bus_space_read_4(t, mac, GEM_MAC_LATE_COLL_CNT);
-	ifp->if_collisions += v +
+	if_statadd_ref(nsr, if_collisions, v +
 	    bus_space_read_4(t, mac, GEM_MAC_NORM_COLL_CNT) +
-	    bus_space_read_4(t, mac, GEM_MAC_FIRST_COLL_CNT);
-	ifp->if_oerrors += v;
+	    bus_space_read_4(t, mac, GEM_MAC_FIRST_COLL_CNT));
+	if_statadd_ref(nsr, if_oerrors, v);
 
 	/* ... then clear the hardware counters. */
 	bus_space_write_4(t, mac, GEM_MAC_NORM_COLL_CNT, 0);
@@ -1720,10 +1722,12 @@ gem_tint(struct gem_softc *sc)
 
 		SIMPLEQ_INSERT_TAIL(&sc->sc_txfreeq, txs, txs_q);
 
-		ifp->if_opackets++;
+		if_statinc_ref(nsr, if_opackets);
 		progress = 1;
 	}
 
+	IF_STAT_PUTREF(ifp);
+
 #if 0
 	DPRINTF(sc, ("gem_tint: GEM_TX_STATE_MACHINE %x "
 		"GEM_TX_DATA_PTR %" PRIx64 "GEM_TX_COMPLETION %" PRIx32 "\n",
@@ -1810,7 +1814,7 @@ gem_rint(struct gem_softc *sc)
 		progress++;
 
 		if (rxstat & GEM_RD_BAD_CRC) {
-			ifp->if_ierrors++;
+			if_statinc(ifp, if_ierrors);
 			aprint_error_dev(sc->sc_dev,
 			    "receive error: CRC error\n");
 			GEM_INIT_RXDESC(sc, i);
@@ -1840,7 +1844,7 @@ gem_rint(struct gem_softc *sc)
 		m = rxs->rxs_mbuf;
 		if (gem_add_rxbuf(sc, i) != 0) {
 			GEM_COUNTER_INCR(sc, sc_ev_rxnobuf);
-			ifp->if_ierrors++;
+			if_statinc(ifp, if_ierrors);
 			aprint_error_dev(sc->sc_dev,
 			    "receive error: RX no buffer space\n");
 			GEM_INIT_RXDESC(sc, i);
@@ -1979,11 +1983,11 @@ swcsum:
 		sc->sc_rxptr, bus_space_read_4(t, h, GEM_RX_COMPLETION)));
 
 	/* Read error counters ... */
-	ifp->if_ierrors +=
+	if_statadd(ifp, if_ierrors,
 	    bus_space_read_4(t, h, GEM_MAC_RX_LEN_ERR_CNT) +
 	    bus_space_read_4(t, h, GEM_MAC_RX_ALIGN_ERR) +
 	    bus_space_read_4(t, h, GEM_MAC_RX_CRC_ERR_CNT) +
-	    bus_space_read_4(t, h, GEM_MAC_RX_CODE_VIOL);
+	    bus_space_read_4(t, h, GEM_MAC_RX_CODE_VIOL));
 
 	/* ... then clear the hardware counters. */
 	bus_space_write_4(t, h, GEM_MAC_RX_LEN_ERR_CNT, 0);
@@ -2222,7 +2226,7 @@ gem_intr(void *v)
 		 * RX FIFO write and read pointers.
 		 */
 		if (rxstat & GEM_MAC_RX_OVERFLOW) {
-			ifp->if_ierrors++;
+			if_statinc(ifp, if_ierrors);
 			aprint_error_dev(sc->sc_dev,
 			    "receive error: RX overflow sc->rxptr %d, complete %d\n", sc->sc_rxptr, bus_space_read_4(t, h, GEM_RX_COMPLETION));
 			sc->sc_rx_fifo_wr_ptr =
@@ -2324,7 +2328,7 @@ gem_watchdog(struct ifnet *ifp)
 		bus_space_read_4(sc->sc_bustag, sc->sc_h1, GEM_MAC_RX_CONFIG)));
 
 	log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
-	++ifp->if_oerrors;
+	if_statinc(ifp, if_oerrors);
 
 	/* Try to get more packets going. */
 	gem_init(ifp);

Index: src/sys/dev/ic/hd64570.c
diff -u src/sys/dev/ic/hd64570.c:1.54 src/sys/dev/ic/hd64570.c:1.55
--- src/sys/dev/ic/hd64570.c:1.54	Tue Jun 26 06:48:00 2018
+++ src/sys/dev/ic/hd64570.c	Wed Jan 29 14:47:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hd64570.c,v 1.54 2018/06/26 06:48:00 msaitoh Exp $	*/
+/*	$NetBSD: hd64570.c,v 1.55 2020/01/29 14:47:08 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1999 Christian E. Hopps
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hd64570.c,v 1.54 2018/06/26 06:48:00 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hd64570.c,v 1.55 2020/01/29 14:47:08 thorpej Exp $");
 
 #include "opt_inet.h"
 
@@ -878,15 +878,18 @@ sca_output(
 			IF_ENQUEUE(ifq, m);
 	} else
 		IFQ_ENQUEUE(&ifp->if_snd, m, error);
+	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
 	if (error != 0) {
+		if_statinc_ref(nsr, if_oerrors);
+		if_statinc_ref(nsr, if_collisions);
+		IF_STAT_PUTREF(ifp);
 		splx(s);
-		ifp->if_oerrors++;
-		ifp->if_collisions++;
 		return (error);
 	}
-	ifp->if_obytes += len;
+	if_statadd_ref(nsr, if_obytes, len);
 	if (mflags & M_MCAST)
-		ifp->if_omcasts++;
+		if_statinc_ref(nsr, if_omcasts);
+	IF_STAT_PUTREF(ifp);
 
 	sca_start(ifp);
 	splx(s);
@@ -1113,7 +1116,7 @@ X
 	sca_desc_write_buflen(sc, desc, len);
 	sca_desc_write_stat(sc, desc, SCA_DESC_EOM);
 
-	ifp->if_opackets++;
+	if_statinc(ifp, if_opackets);
 
 	/*
 	 * Pass packet to bpf if there is a listener.
@@ -1490,7 +1493,7 @@ sca_frame_avail(sca_port_t *scp)
 			 * consider an error condition the end
 			 * of a frame
 			 */
-			scp->sp_if.if_ierrors++;
+			if_statinc(&scp->sp_if, if_ierrors);
 			toolong = 0;
 			continue;
 		}
@@ -1509,7 +1512,7 @@ sca_frame_avail(sca_port_t *scp)
 			 * we currently don't deal with frames
 			 * larger than a single buffer (fixed MTU)
 			 */
-			scp->sp_if.if_ierrors++;
+			if_statinc(&scp->sp_if, if_ierrors);
 			toolong = 1;
 		}
 		SCA_DPRINTF(SCA_DEBUG_RX, ("RX: idx %d no EOM\n",
@@ -1557,7 +1560,7 @@ sca_frame_process(sca_port_t *scp)
 	 * skip packets that are too short
 	 */
 	if (len < sizeof(struct hdlc_header)) {
-		scp->sp_if.if_ierrors++;
+		if_statinc(&scp->sp_if, if_ierrors);
 		return;
 	}
 
@@ -1578,7 +1581,7 @@ sca_frame_process(sca_port_t *scp)
 
 	bpf_mtap_softint(&scp->sp_if, m);
 
-	scp->sp_if.if_ipackets++;
+	if_statinc(&scp->sp_if, if_ipackets);
 
 	hdlc = mtod(m, struct hdlc_header *);
 	switch (ntohs(hdlc->h_proto)) {
@@ -1610,7 +1613,7 @@ sca_frame_process(sca_port_t *scp)
 			SCA_DPRINTF(SCA_DEBUG_CISCO,
 				    ("short CISCO packet %d, wanted %d\n",
 				     len, CISCO_PKT_LEN));
-			scp->sp_if.if_ierrors++;
+			if_statinc(&scp->sp_if, if_ierrors);
 			goto dropit;
 		}
 
@@ -1627,12 +1630,12 @@ sca_frame_process(sca_port_t *scp)
 		switch (ntohl(cisco->type)) {
 		case CISCO_ADDR_REQ:
 			printf("Got CISCO addr_req, ignoring\n");
-			scp->sp_if.if_ierrors++;
+			if_statinc(&scp->sp_if, if_ierrors);
 			goto dropit;
 
 		case CISCO_ADDR_REPLY:
 			printf("Got CISCO addr_reply, ignoring\n");
-			scp->sp_if.if_ierrors++;
+			if_statinc(&scp->sp_if, if_ierrors);
 			goto dropit;
 
 		case CISCO_KEEPALIVE_REQ:
@@ -1677,7 +1680,7 @@ sca_frame_process(sca_port_t *scp)
 				    ("Unknown CISCO keepalive protocol 0x%04x\n",
 				     ntohl(cisco->type)));
 
-			scp->sp_if.if_noproto++;
+			if_statinc(&scp->sp_if, if_noproto);
 			goto dropit;
 		}
 		return;
@@ -1685,14 +1688,14 @@ sca_frame_process(sca_port_t *scp)
 		SCA_DPRINTF(SCA_DEBUG_RX,
 			    ("Unknown/unexpected ethertype 0x%04x\n",
 			     ntohs(hdlc->h_proto)));
-		scp->sp_if.if_noproto++;
+		if_statinc(&scp->sp_if, if_noproto);
 		goto dropit;
 	}
 
 	/* Queue the packet */
 	if (__predict_true(pktq)) {
 		if (__predict_false(!pktq_enqueue(pktq, m, 0))) {
-			scp->sp_if.if_iqdrops++;
+			if_statinc(&scp->sp_if, if_iqdrops);
 			goto dropit;
 		}
 		return;
@@ -1702,7 +1705,7 @@ sca_frame_process(sca_port_t *scp)
 		schednetisr(isr);
 	} else {
 		IF_DROP(ifq);
-		scp->sp_if.if_iqdrops++;
+		if_statinc(&scp->sp_if, if_iqdrops);
 		goto dropit;
 	}
 	return;

Index: src/sys/dev/ic/hme.c
diff -u src/sys/dev/ic/hme.c:1.105 src/sys/dev/ic/hme.c:1.106
--- src/sys/dev/ic/hme.c:1.105	Tue May 28 07:41:48 2019
+++ src/sys/dev/ic/hme.c	Wed Jan 29 14:47:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hme.c,v 1.105 2019/05/28 07:41:48 msaitoh Exp $	*/
+/*	$NetBSD: hme.c,v 1.106 2020/01/29 14:47:08 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.105 2019/05/28 07:41:48 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.106 2020/01/29 14:47:08 thorpej Exp $");
 
 /* #define HMEDEBUG */
 
@@ -862,14 +862,14 @@ hme_read(struct hme_softc *sc, int ix, u
 		printf("%s: invalid packet size %d; dropping\n",
 		    device_xname(sc->sc_dev), len);
 #endif
-		ifp->if_ierrors++;
+		if_statinc(ifp, if_ierrors);
 		return;
 	}
 
 	/* Pull packet off interface. */
 	m = hme_get(sc, ix, flags);
 	if (m == 0) {
-		ifp->if_ierrors++;
+		if_statinc(ifp, if_ierrors);
 		return;
 	}
 
@@ -976,15 +976,17 @@ hme_tint(struct hme_softc *sc)
 	bus_space_handle_t mac = sc->sc_mac;
 	unsigned int ri, txflags;
 
+	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
+
 	/*
 	 * Unload collision counters
 	 */
-	ifp->if_collisions +=
+	if_statadd_ref(nsr, if_collisions,
 		bus_space_read_4(t, mac, HME_MACI_NCCNT) +
-		bus_space_read_4(t, mac, HME_MACI_FCCNT);
-	ifp->if_oerrors +=
+		bus_space_read_4(t, mac, HME_MACI_FCCNT));
+	if_statadd_ref(nsr, if_oerrors,
 		bus_space_read_4(t, mac, HME_MACI_EXCNT) +
-		bus_space_read_4(t, mac, HME_MACI_LTCNT);
+		bus_space_read_4(t, mac, HME_MACI_LTCNT));
 
 	/*
 	 * then clear the hardware counters.
@@ -1007,7 +1009,7 @@ hme_tint(struct hme_softc *sc)
 			break;
 
 		ifp->if_flags &= ~IFF_OACTIVE;
-		ifp->if_opackets++;
+		if_statinc_ref(nsr, if_opackets);
 
 		if (++ri == sc->sc_rb.rb_ntbuf)
 			ri = 0;
@@ -1015,6 +1017,8 @@ hme_tint(struct hme_softc *sc)
 		--sc->sc_rb.rb_td_nbusy;
 	}
 
+	IF_STAT_PUTREF(ifp);
+
 	/* Update ring */
 	sc->sc_rb.rb_tdtail = ri;
 
@@ -1067,11 +1071,11 @@ hme_rint(struct hme_softc *sc)
 	sc->sc_rb.rb_rdtail = ri;
 
 	/* Read error counters ... */
-	ifp->if_ierrors +=
+	if_statadd(ifp, if_ierrors,
 	    bus_space_read_4(t, mac, HME_MACI_STAT_LCNT) +
 	    bus_space_read_4(t, mac, HME_MACI_STAT_ACNT) +
 	    bus_space_read_4(t, mac, HME_MACI_STAT_CCNT) +
-	    bus_space_read_4(t, mac, HME_MACI_STAT_CVCNT);
+	    bus_space_read_4(t, mac, HME_MACI_STAT_CVCNT));
 
 	/* ... then clear the hardware counters. */
 	bus_space_write_4(t, mac, HME_MACI_STAT_LCNT, 0);
@@ -1100,14 +1104,16 @@ hme_eint(struct hme_softc *sc, u_int sta
 	}
 
 	/* Receive error counters rolled over */
+	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
 	if (status & HME_SEB_STAT_ACNTEXP)
-		ifp->if_ierrors += 0xff;
+		if_statadd_ref(nsr, if_ierrors, 0xff);
 	if (status & HME_SEB_STAT_CCNTEXP)
-		ifp->if_ierrors += 0xff;
+		if_statadd_ref(nsr, if_ierrors, 0xff);
 	if (status & HME_SEB_STAT_LCNTEXP)
-		ifp->if_ierrors += 0xff;
+		if_statadd_ref(nsr, if_ierrors, 0xff);
 	if (status & HME_SEB_STAT_CVCNTEXP)
-		ifp->if_ierrors += 0xff;
+		if_statadd_ref(nsr, if_ierrors, 0xff);
+	IF_STAT_PUTREF(ifp);
 
 	/* RXTERR locks up the interface, so do a reset */
 	if (status & HME_SEB_STAT_RXTERR)
@@ -1151,7 +1157,7 @@ hme_watchdog(struct ifnet *ifp)
 	struct hme_softc *sc = ifp->if_softc;
 
 	log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
-	++ifp->if_oerrors;
+	if_statinc(ifp, if_oerrors);
 
 	hme_reset(sc);
 }

Reply via email to