Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic Adopt <net/if_stats.h>.



details:   https://anonhg.NetBSD.org/src/rev/38af3dfc2e58
branches:  trunk
changeset: 744314:38af3dfc2e58
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Jan 29 14:47:08 2020 +0000

description:
Adopt <net/if_stats.h>.

diffstat:

 sys/dev/ic/gem.c     |  28 ++++++++++++++++------------
 sys/dev/ic/hd64570.c |  39 +++++++++++++++++++++------------------
 sys/dev/ic/hme.c     |  38 ++++++++++++++++++++++----------------
 sys/dev/ic/i82557.c  |  22 +++++++++++++---------
 sys/dev/ic/i82586.c  |  28 ++++++++++++++--------------
 sys/dev/ic/i82596.c  |   9 +++++----
 sys/dev/ic/lan9118.c |  20 ++++++++++----------
 sys/dev/ic/lemac.c   |  20 ++++++++++----------
 8 files changed, 111 insertions(+), 93 deletions(-)

diffs (truncated from 743 to 300 lines):

diff -r da282817d78b -r 38af3dfc2e58 sys/dev/ic/gem.c
--- a/sys/dev/ic/gem.c  Wed Jan 29 14:41:57 2020 +0000
+++ b/sys/dev/ic/gem.c  Wed Jan 29 14:47:08 2020 +0000
@@ -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 @@
        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 @@
 
                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 @@
                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 @@
                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 @@
                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 @@
                 * 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 @@
                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);
diff -r da282817d78b -r 38af3dfc2e58 sys/dev/ic/hd64570.c
--- a/sys/dev/ic/hd64570.c      Wed Jan 29 14:41:57 2020 +0000
+++ b/sys/dev/ic/hd64570.c      Wed Jan 29 14:47:08 2020 +0000
@@ -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 @@
                        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 @@
        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 @@
                         * 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 @@
                         * 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 @@
         * 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 @@
 
        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_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 @@
                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 @@
                                    ("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_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 @@
                schednetisr(isr);
        } else {
                IF_DROP(ifq);
-               scp->sp_if.if_iqdrops++;
+               if_statinc(&scp->sp_if, if_iqdrops);
                goto dropit;
        }
        return;
diff -r da282817d78b -r 38af3dfc2e58 sys/dev/ic/hme.c
--- a/sys/dev/ic/hme.c  Wed Jan 29 14:41:57 2020 +0000
+++ b/sys/dev/ic/hme.c  Wed Jan 29 14:47:08 2020 +0000
@@ -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 @@
                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 @@
        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) +



Home | Main Index | Thread Index | Old Index