Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Sep 2014 10:47:57 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r272169 - head/sys/dev/ti
Message-ID:  <201409261047.s8QAlvNG092241@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Fri Sep 26 10:47:57 2014
New Revision: 272169
URL: http://svnweb.freebsd.org/changeset/base/272169

Log:
  - 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]

Modified:
  head/sys/dev/ti/if_ti.c

Modified: head/sys/dev/ti/if_ti.c
==============================================================================
--- head/sys/dev/ti/if_ti.c	Fri Sep 26 09:54:57 2014	(r272168)
+++ head/sys/dev/ti/if_ti.c	Fri Sep 26 10:47:57 2014	(r272169)
@@ -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;
 
-	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);
+	switch (cnt) {
+	case IFCOUNTER_COLLISIONS:
+	    {
+		struct ti_softc *sc;
+		struct ti_stats *s;
+		uint64_t rv;
 
-	s = &sc->ti_rdata.ti_info->ti_stats;
-	ifp->if_collisions += (s->dot3StatsSingleCollisionFrames +
-	   s->dot3StatsMultipleCollisionFrames +
-	   s->dot3StatsExcessiveCollisions + s->dot3StatsLateCollisions) -
-	    ifp->if_collisions;
+		sc = if_getsoftc(ifp);
+		s = &sc->ti_rdata.ti_info->ti_stats;
 
-	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, 
 		    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);
 }
 
 /*



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