From owner-svn-src-all@FreeBSD.ORG Wed Sep 24 11:23:56 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 50E3B83E; Wed, 24 Sep 2014 11:23:56 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3BE24AED; Wed, 24 Sep 2014 11:23:56 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8OBNu0u024620; Wed, 24 Sep 2014 11:23:56 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8OBNutK024619; Wed, 24 Sep 2014 11:23:56 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201409241123.s8OBNutK024619@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Wed, 24 Sep 2014 11:23:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r272064 - head/sys/dev/et X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Sep 2014 11:23:56 -0000 Author: glebius Date: Wed Sep 24 11:23:55 2014 New Revision: 272064 URL: http://svnweb.freebsd.org/changeset/base/272064 Log: - Provide igb_get_counter() to return counters that are not collected, but taken from hardware. - Mechanically convert to if_inc_counter() the rest of counters. Modified: head/sys/dev/et/if_et.c Modified: head/sys/dev/et/if_et.c ============================================================================== --- head/sys/dev/et/if_et.c Wed Sep 24 09:59:48 2014 (r272063) +++ head/sys/dev/et/if_et.c Wed Sep 24 11:23:55 2014 (r272064) @@ -104,6 +104,7 @@ static int et_watchdog(struct et_softc * static int et_ifmedia_upd_locked(struct ifnet *); static int et_ifmedia_upd(struct ifnet *); static void et_ifmedia_sts(struct ifnet *, struct ifmediareq *); +static uint64_t et_get_counter(struct ifnet *, ift_counter); static void et_add_sysctls(struct et_softc *); static int et_sysctl_rx_intr_npkts(SYSCTL_HANDLER_ARGS); @@ -324,6 +325,7 @@ et_attach(device_t dev) ifp->if_init = et_init; ifp->if_ioctl = et_ioctl; ifp->if_start = et_start; + ifp->if_get_counter = et_get_counter; ifp->if_capabilities = IFCAP_TXCSUM | IFCAP_VLAN_MTU; ifp->if_capenable = ifp->if_capabilities; ifp->if_snd.ifq_drv_maxlen = ET_TX_NDESC - 1; @@ -1413,7 +1415,7 @@ et_start_locked(struct ifnet *ifp) if (et_encap(sc, &m_head)) { if (m_head == NULL) { - ifp->if_oerrors++; + if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); break; } IFQ_DRV_PREPEND(&ifp->if_snd, m_head); @@ -1465,7 +1467,7 @@ et_watchdog(struct et_softc *sc) if_printf(sc->ifp, "watchdog timed out (0x%08x) -- resetting\n", status); - sc->ifp->if_oerrors++; + if_inc_counter(sc->ifp, IFCOUNTER_OERRORS, 1); sc->ifp->if_drv_flags &= ~IFF_DRV_RUNNING; et_init_locked(sc); return (EJUSTRETURN); @@ -2093,12 +2095,12 @@ et_rxeof(struct et_softc *sc) CSR_WRITE_4(sc, ET_RXSTAT_POS, rxstat_pos); if (ring_idx >= ET_RX_NRING) { - ifp->if_ierrors++; + if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); if_printf(ifp, "invalid ring index %d\n", ring_idx); continue; } if (buf_idx >= ET_RX_NDESC) { - ifp->if_ierrors++; + if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); if_printf(ifp, "invalid buf index %d\n", buf_idx); continue; } @@ -2110,13 +2112,13 @@ et_rxeof(struct et_softc *sc) rbd->rbd_discard(rbd, buf_idx); } else if (rbd->rbd_newbuf(rbd, buf_idx) != 0) { /* No available mbufs, discard it. */ - ifp->if_iqdrops++; + if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); rbd->rbd_discard(rbd, buf_idx); } else { buflen -= ETHER_CRC_LEN; if (buflen < ETHER_HDR_LEN) { m_freem(m); - ifp->if_ierrors++; + if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); } else { m->m_pkthdr.len = m->m_len = buflen; m->m_pkthdr.rcvif = ifp; @@ -2625,7 +2627,6 @@ back: static void et_stats_update(struct et_softc *sc) { - struct ifnet *ifp; struct et_hw_stats *stats; stats = &sc->sc_stats; @@ -2675,18 +2676,35 @@ et_stats_update(struct et_softc *sc) stats->tx_oversize += CSR_READ_4(sc, ET_STAT_TX_OVERSIZE); stats->tx_undersize += CSR_READ_4(sc, ET_STAT_TX_UNDERSIZE); stats->tx_fragments += CSR_READ_4(sc, ET_STAT_TX_FRAG); +} - /* Update ifnet counters. */ - ifp = sc->ifp; - ifp->if_opackets = (u_long)stats->tx_frames; - ifp->if_collisions = stats->tx_total_colls; - ifp->if_oerrors = stats->tx_drop + stats->tx_jabbers + - stats->tx_crcerrs + stats->tx_excess_deferred + - stats->tx_late_colls; - ifp->if_ipackets = (u_long)stats->rx_frames; - ifp->if_ierrors = stats->rx_crcerrs + stats->rx_alignerrs + - stats->rx_lenerrs + stats->rx_codeerrs + stats->rx_cserrs + - stats->rx_runts + stats->rx_jabbers + stats->rx_drop; +static uint64_t +et_get_counter(struct ifnet *ifp, ift_counter cnt) +{ + struct et_softc *sc; + struct et_hw_stats *stats; + + sc = if_getsoftc(ifp); + stats = &sc->sc_stats; + + switch (cnt) { + case IFCOUNTER_OPACKETS: + return (stats->tx_frames); + case IFCOUNTER_COLLISIONS: + return (stats->tx_total_colls); + case IFCOUNTER_OERRORS: + return (stats->tx_drop + stats->tx_jabbers + + stats->tx_crcerrs + stats->tx_excess_deferred + + stats->tx_late_colls); + case IFCOUNTER_IPACKETS: + return (stats->rx_frames); + case IFCOUNTER_IERRORS: + return (stats->rx_crcerrs + stats->rx_alignerrs + + stats->rx_lenerrs + stats->rx_codeerrs + stats->rx_cserrs + + stats->rx_runts + stats->rx_jabbers + stats->rx_drop); + default: + return (if_get_counter_default(ifp, cnt)); + } } static int