From 0353415eb65187e8208dfdf6475b77c433e9d904 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Fri, 26 Sep 2014 10:47:57 +0000 Subject: [PATCH] - Mechanically convert to if_inc_counter() the rest of counters. - Do not set if_collisions on interrupt, read them in ti_get_counter(). - Add missing bus_dmamap_sync(BUS_DMASYNC_PREREAD) in ti_ioctl2(). [1] Submitted by: mav [1] --- sys/dev/ti/if_ti.c | 71 ++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/sys/dev/ti/if_ti.c b/sys/dev/ti/if_ti.c index fa63aa9543bb..7d0fc9d318f5 100644 --- a/sys/dev/ti/if_ti.c +++ b/sys/dev/ti/if_ti.c @@ -184,13 +184,13 @@ static int ti_detach(device_t); static void ti_txeof(struct ti_softc *); static void ti_rxeof(struct ti_softc *); -static void ti_stats_update(struct ti_softc *); static int ti_encap(struct ti_softc *, struct mbuf **); static void ti_intr(void *); static void ti_start(struct ifnet *); static void ti_start_locked(struct ifnet *); static int ti_ioctl(struct ifnet *, u_long, caddr_t); +static uint64_t ti_get_counter(struct ifnet *, ift_counter); static void ti_init(void *); static void ti_init_locked(void *); static void ti_init2(struct ti_softc *); @@ -959,8 +959,6 @@ ti_handle_events(struct ti_softc *sc) ti_init2(sc); break; case TI_EV_STATS_UPDATED: - ti_stats_update(sc); - break; case TI_EV_RESET_JUMBO_RING: case TI_EV_MCAST_UPDATED: /* Who cares. */ @@ -2505,6 +2503,7 @@ ti_attach(device_t dev) ifp->if_ioctl = ti_ioctl; ifp->if_start = ti_start; ifp->if_init = ti_init; + ifp->if_get_counter = ti_get_counter; ifp->if_baudrate = IF_Gbps(1UL); ifp->if_snd.ifq_drv_maxlen = TI_TX_RING_CNT - 1; IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen); @@ -2803,12 +2802,12 @@ ti_rxeof(struct ti_softc *sc) m = sc->ti_cdata.ti_rx_jumbo_chain[rxidx]; #ifndef TI_SF_BUF_JUMBO if (cur_rx->ti_flags & TI_BDFLAG_ERROR) { - ifp->if_ierrors++; + if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); ti_discard_jumbo(sc, rxidx); continue; } if (ti_newbuf_jumbo(sc, rxidx, NULL) != 0) { - ifp->if_iqdrops++; + if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); ti_discard_jumbo(sc, rxidx); continue; } @@ -2820,12 +2819,12 @@ ti_rxeof(struct ti_softc *sc) BUS_DMASYNC_POSTREAD); bus_dmamap_unload(sc->ti_cdata.ti_rx_jumbo_tag, map); if (cur_rx->ti_flags & TI_BDFLAG_ERROR) { - ifp->if_ierrors++; + if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); ti_newbuf_jumbo(sc, sc->ti_jumbo, m); continue; } if (ti_newbuf_jumbo(sc, sc->ti_jumbo, NULL) == ENOBUFS) { - ifp->if_iqdrops++; + if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); ti_newbuf_jumbo(sc, sc->ti_jumbo, m); continue; } @@ -2842,12 +2841,12 @@ ti_rxeof(struct ti_softc *sc) TI_INC(sc->ti_mini, TI_MINI_RX_RING_CNT); m = sc->ti_cdata.ti_rx_mini_chain[rxidx]; if (cur_rx->ti_flags & TI_BDFLAG_ERROR) { - ifp->if_ierrors++; + if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); ti_discard_mini(sc, rxidx); continue; } if (ti_newbuf_mini(sc, rxidx) != 0) { - ifp->if_iqdrops++; + if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); ti_discard_mini(sc, rxidx); continue; } @@ -2857,12 +2856,12 @@ ti_rxeof(struct ti_softc *sc) TI_INC(sc->ti_std, TI_STD_RX_RING_CNT); m = sc->ti_cdata.ti_rx_std_chain[rxidx]; if (cur_rx->ti_flags & TI_BDFLAG_ERROR) { - ifp->if_ierrors++; + if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); ti_discard_std(sc, rxidx); continue; } if (ti_newbuf_std(sc, rxidx) != 0) { - ifp->if_iqdrops++; + if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); ti_discard_std(sc, rxidx); continue; } @@ -2870,7 +2869,7 @@ ti_rxeof(struct ti_softc *sc) } m->m_pkthdr.len = ti_len; - ifp->if_ipackets++; + if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); m->m_pkthdr.rcvif = ifp; if (ifp->if_capenable & IFCAP_RXCSUM) { @@ -2961,7 +2960,7 @@ ti_txeof(struct ti_softc *sc) BUS_DMASYNC_POSTWRITE); bus_dmamap_unload(sc->ti_cdata.ti_tx_tag, txd->tx_dmamap); - ifp->if_opackets++; + if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); m_freem(txd->tx_m); txd->tx_m = NULL; STAILQ_REMOVE_HEAD(&sc->ti_cdata.ti_txbusyq, tx_q); @@ -3016,27 +3015,35 @@ ti_intr(void *xsc) TI_UNLOCK(sc); } -static void -ti_stats_update(struct ti_softc *sc) +static uint64_t +ti_get_counter(struct ifnet *ifp, ift_counter cnt) { - struct ifnet *ifp; - struct ti_stats *s; - ifp = sc->ti_ifp; + switch (cnt) { + case IFCOUNTER_COLLISIONS: + { + struct ti_softc *sc; + struct ti_stats *s; + uint64_t rv; - if (sc->ti_stat_ticks == 0) - return; - bus_dmamap_sync(sc->ti_cdata.ti_gib_tag, sc->ti_cdata.ti_gib_map, - BUS_DMASYNC_POSTREAD); + sc = if_getsoftc(ifp); + s = &sc->ti_rdata.ti_info->ti_stats; - s = &sc->ti_rdata.ti_info->ti_stats; - ifp->if_collisions += (s->dot3StatsSingleCollisionFrames + - s->dot3StatsMultipleCollisionFrames + - s->dot3StatsExcessiveCollisions + s->dot3StatsLateCollisions) - - ifp->if_collisions; - - bus_dmamap_sync(sc->ti_cdata.ti_gib_tag, sc->ti_cdata.ti_gib_map, - BUS_DMASYNC_PREREAD); + TI_LOCK(sc); + bus_dmamap_sync(sc->ti_cdata.ti_gib_tag, + sc->ti_cdata.ti_gib_map, BUS_DMASYNC_POSTREAD); + rv = s->dot3StatsSingleCollisionFrames + + s->dot3StatsMultipleCollisionFrames + + s->dot3StatsExcessiveCollisions + + s->dot3StatsLateCollisions; + bus_dmamap_sync(sc->ti_cdata.ti_gib_tag, + sc->ti_cdata.ti_gib_map, BUS_DMASYNC_PREREAD); + TI_UNLOCK(sc); + return (rv); + } + default: + return (if_get_counter_default(ifp, cnt)); + } } /* @@ -3662,6 +3669,8 @@ ti_ioctl2(struct cdev *dev, u_long cmd, caddr_t addr, int flag, sc->ti_cdata.ti_gib_map, BUS_DMASYNC_POSTREAD); bcopy(&sc->ti_rdata.ti_info->ti_stats, outstats, sizeof(struct ti_stats)); + bus_dmamap_sync(sc->ti_cdata.ti_gib_tag, + sc->ti_cdata.ti_gib_map, BUS_DMASYNC_PREREAD); TI_UNLOCK(sc); break; } @@ -3917,7 +3926,7 @@ ti_watchdog(void *arg) ifp->if_drv_flags &= ~IFF_DRV_RUNNING; ti_init_locked(sc); - ifp->if_oerrors++; + if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); } /*