From owner-svn-src-head@FreeBSD.ORG Sun Feb 22 19:25:59 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B14C79B8; Sun, 22 Feb 2015 19:25:59 +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 91DB7A4A; Sun, 22 Feb 2015 19:25:59 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1MJPxIW012211; Sun, 22 Feb 2015 19:25:59 GMT (envelope-from arybchik@FreeBSD.org) Received: (from arybchik@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1MJPwq9012206; Sun, 22 Feb 2015 19:25:58 GMT (envelope-from arybchik@FreeBSD.org) Message-Id: <201502221925.t1MJPwq9012206@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: arybchik set sender to arybchik@FreeBSD.org using -f From: Andrew Rybchenko Date: Sun, 22 Feb 2015 19:25:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r279184 - head/sys/dev/sfxge X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Feb 2015 19:25:59 -0000 Author: arybchik Date: Sun Feb 22 19:25:57 2015 New Revision: 279184 URL: https://svnweb.freebsd.org/changeset/base/279184 Log: sfxge: implement if_get_counter callback Sponsored by: Solarflare Communications, Inc. Approved by: gnn (mentor) Modified: head/sys/dev/sfxge/sfxge.c head/sys/dev/sfxge/sfxge.h head/sys/dev/sfxge/sfxge_port.c head/sys/dev/sfxge/sfxge_tx.c head/sys/dev/sfxge/sfxge_tx.h Modified: head/sys/dev/sfxge/sfxge.c ============================================================================== --- head/sys/dev/sfxge/sfxge.c Sun Feb 22 19:24:08 2015 (r279183) +++ head/sys/dev/sfxge/sfxge.c Sun Feb 22 19:25:57 2015 (r279184) @@ -61,10 +61,10 @@ __FBSDID("$FreeBSD$"); #define SFXGE_CAP (IFCAP_VLAN_MTU | \ IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM | IFCAP_TSO | \ IFCAP_JUMBO_MTU | IFCAP_LRO | \ - IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE) + IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWSTATS) #define SFXGE_CAP_ENABLE SFXGE_CAP #define SFXGE_CAP_FIXED (IFCAP_VLAN_MTU | IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM | \ - IFCAP_JUMBO_MTU | IFCAP_LINKSTATE) + IFCAP_JUMBO_MTU | IFCAP_LINKSTATE | IFCAP_HWSTATS) MALLOC_DEFINE(M_SFXGE, "sfxge", "Solarflare 10GigE driver"); @@ -343,6 +343,8 @@ sfxge_ifnet_init(struct ifnet *ifp, stru mtx_init(&sc->tx_lock, sc->tx_lock_name, NULL, MTX_DEF); #endif + ifp->if_get_counter = sfxge_get_counter; + if ((rc = sfxge_port_ifmedia_init(sc)) != 0) goto fail; Modified: head/sys/dev/sfxge/sfxge.h ============================================================================== --- head/sys/dev/sfxge/sfxge.h Sun Feb 22 19:24:08 2015 (r279183) +++ head/sys/dev/sfxge/sfxge.h Sun Feb 22 19:25:57 2015 (r279184) @@ -324,6 +324,7 @@ extern void sfxge_mac_link_update(struct efx_link_mode_t mode); extern int sfxge_mac_filter_set(struct sfxge_softc *sc); extern int sfxge_port_ifmedia_init(struct sfxge_softc *sc); +extern uint64_t sfxge_get_counter(struct ifnet *ifp, ift_counter c); #define SFXGE_MAX_MTU (9 * 1024) Modified: head/sys/dev/sfxge/sfxge_port.c ============================================================================== --- head/sys/dev/sfxge/sfxge_port.c Sun Feb 22 19:24:08 2015 (r279183) +++ head/sys/dev/sfxge/sfxge_port.c Sun Feb 22 19:25:57 2015 (r279184) @@ -85,6 +85,68 @@ out: return (rc); } +uint64_t +sfxge_get_counter(struct ifnet *ifp, ift_counter c) +{ + struct sfxge_softc *sc = ifp->if_softc; + uint64_t *mac_stats; + uint64_t val; + + SFXGE_PORT_LOCK(&sc->port); + + /* Ignore error and use old values */ + (void)sfxge_mac_stat_update(sc); + + mac_stats = (uint64_t *)sc->port.mac_stats.decode_buf; + + switch (c) { + case IFCOUNTER_IPACKETS: + val = mac_stats[EFX_MAC_RX_PKTS]; + break; + case IFCOUNTER_IERRORS: + val = mac_stats[EFX_MAC_RX_ERRORS]; + break; + case IFCOUNTER_OPACKETS: + val = mac_stats[EFX_MAC_TX_PKTS]; + break; + case IFCOUNTER_OERRORS: + val = mac_stats[EFX_MAC_TX_ERRORS]; + break; + case IFCOUNTER_COLLISIONS: + val = mac_stats[EFX_MAC_TX_SGL_COL_PKTS] + + mac_stats[EFX_MAC_TX_MULT_COL_PKTS] + + mac_stats[EFX_MAC_TX_EX_COL_PKTS] + + mac_stats[EFX_MAC_TX_LATE_COL_PKTS]; + break; + case IFCOUNTER_IBYTES: + val = mac_stats[EFX_MAC_RX_OCTETS]; + break; + case IFCOUNTER_OBYTES: + val = mac_stats[EFX_MAC_TX_OCTETS]; + break; + case IFCOUNTER_OMCASTS: + val = mac_stats[EFX_MAC_TX_MULTICST_PKTS] + + mac_stats[EFX_MAC_TX_BRDCST_PKTS]; + break; + case IFCOUNTER_OQDROPS: + SFXGE_PORT_UNLOCK(&sc->port); + return (sfxge_tx_get_drops(sc)); + case IFCOUNTER_IMCASTS: + /* if_imcasts is maintained in net/if_ethersubr.c */ + case IFCOUNTER_IQDROPS: + /* if_iqdrops is maintained in net/if_ethersubr.c */ + case IFCOUNTER_NOPROTO: + /* if_noproto is maintained in net/if_ethersubr.c */ + default: + SFXGE_PORT_UNLOCK(&sc->port); + return (if_get_counter_default(ifp, c)); + } + + SFXGE_PORT_UNLOCK(&sc->port); + + return (val); +} + static int sfxge_mac_stat_handler(SYSCTL_HANDLER_ARGS) { Modified: head/sys/dev/sfxge/sfxge_tx.c ============================================================================== --- head/sys/dev/sfxge/sfxge_tx.c Sun Feb 22 19:24:08 2015 (r279183) +++ head/sys/dev/sfxge/sfxge_tx.c Sun Feb 22 19:25:57 2015 (r279184) @@ -1566,6 +1566,29 @@ sfxge_tx_stat_init(struct sfxge_softc *s } } +uint64_t +sfxge_tx_get_drops(struct sfxge_softc *sc) +{ + unsigned int index; + uint64_t drops = 0; + struct sfxge_txq *txq; + + /* Sum across all TX queues */ + for (index = 0; index < sc->txq_count; index++) { + txq = sc->txq[index]; + /* + * In theory, txq->put_overflow and txq->netdown_drops + * should use atomic operation and other should be + * obtained under txq lock, but it is just statistics. + */ + drops += txq->drops + txq->get_overflow + + txq->get_non_tcp_overflow + + txq->put_overflow + txq->netdown_drops + + txq->tso_pdrop_too_many + txq->tso_pdrop_no_rsrc; + } + return (drops); +} + void sfxge_tx_fini(struct sfxge_softc *sc) { Modified: head/sys/dev/sfxge/sfxge_tx.h ============================================================================== --- head/sys/dev/sfxge/sfxge_tx.h Sun Feb 22 19:24:08 2015 (r279183) +++ head/sys/dev/sfxge/sfxge_tx.h Sun Feb 22 19:25:57 2015 (r279184) @@ -217,6 +217,7 @@ struct sfxge_txq { struct sfxge_evq; extern int sfxge_tx_packet_add(struct sfxge_txq *, struct mbuf *); +extern uint64_t sfxge_tx_get_drops(struct sfxge_softc *sc); extern int sfxge_tx_init(struct sfxge_softc *sc); extern void sfxge_tx_fini(struct sfxge_softc *sc);