From patchwork Tue Aug 3 16:36:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12416783 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE3A8C4338F for ; Tue, 3 Aug 2021 16:38:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A472261102 for ; Tue, 3 Aug 2021 16:38:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234835AbhHCQia (ORCPT ); Tue, 3 Aug 2021 12:38:30 -0400 Received: from mga04.intel.com ([192.55.52.120]:5348 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234477AbhHCQiD (ORCPT ); Tue, 3 Aug 2021 12:38:03 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10065"; a="211865584" X-IronPort-AV: E=Sophos;i="5.84,292,1620716400"; d="scan'208";a="211865584" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2021 09:37:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,292,1620716400"; d="scan'208";a="521316683" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga002.fm.intel.com with ESMTP; 03 Aug 2021 09:37:37 -0700 Received: from alobakin-mobl.ger.corp.intel.com (eflejszm-mobl2.ger.corp.intel.com [10.213.26.164]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 173GahF2029968; Tue, 3 Aug 2021 17:37:32 +0100 From: Alexander Lobakin To: "David S. Miller" , Jakub Kicinski Cc: Alexander Lobakin , Jesse Brandeburg , Lukasz Czapnik , Marcin Kubiak , Michal Kubiak , Michal Swiatkowski , Jonathan Corbet , Netanel Belgazal , Arthur Kiyanovski , Guy Tzalik , Saeed Bishara , Ioana Ciornei , Claudiu Manoil , Thomas Petazzoni , Marcin Wojtas , Russell King , Edward Cree , Martin Habets , "Michael S. Tsirkin" , Jason Wang , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Shay Agroskin , Sameeh Jubran , Alexander Duyck , Danielle Ratson , Ido Schimmel , Andrew Lunn , Vladyslav Tarasiuk , Arnd Bergmann , Andrew Morton , Jian Shen , Petr Vorel , Dan Murphy , Yangbo Lu , Michal Kubecek , Zheng Yongjun , Heiner Kallweit , YueHaibing , Johannes Berg , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Subject: [PATCH net-next 12/21] ethernet, mvpp2: convert to standard XDP stats Date: Tue, 3 Aug 2021 18:36:32 +0200 Message-Id: <20210803163641.3743-13-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210803163641.3743-1-alexandr.lobakin@intel.com> References: <20210803163641.3743-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Convert PPv2 driver to provide standard XDP statistics instead of custom-defined Ethtool stats. This also allows to greatly simplify stats filling code. In the same fashion as mvneta, the driver uses global XDP counters. Signed-off-by: Alexander Lobakin Reviewed-by: Jesse Brandeburg --- .../net/ethernet/marvell/mvpp2/mvpp2_main.c | 90 +++++-------------- 1 file changed, 20 insertions(+), 70 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index a3aee1a6d760..ed34f8fefced 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -1824,16 +1824,6 @@ static void mvpp2_port_loopback_set(struct mvpp2_port *port, writel(val, port->base + MVPP2_GMAC_CTRL_1_REG); } -enum { - ETHTOOL_XDP_REDIRECT, - ETHTOOL_XDP_PASS, - ETHTOOL_XDP_DROP, - ETHTOOL_XDP_TX, - ETHTOOL_XDP_TX_ERR, - ETHTOOL_XDP_XMIT, - ETHTOOL_XDP_XMIT_DROPS, -}; - struct mvpp2_ethtool_counter { unsigned int offset; const char string[ETH_GSTRING_LEN]; @@ -1926,21 +1916,10 @@ static const struct mvpp2_ethtool_counter mvpp2_ethtool_rxq_regs[] = { { MVPP2_RX_PKTS_BM_DROP_CTR, "rxq_%d_packets_bm_drops" }, }; -static const struct mvpp2_ethtool_counter mvpp2_ethtool_xdp[] = { - { ETHTOOL_XDP_REDIRECT, "rx_xdp_redirect", }, - { ETHTOOL_XDP_PASS, "rx_xdp_pass", }, - { ETHTOOL_XDP_DROP, "rx_xdp_drop", }, - { ETHTOOL_XDP_TX, "rx_xdp_tx", }, - { ETHTOOL_XDP_TX_ERR, "rx_xdp_tx_errors", }, - { ETHTOOL_XDP_XMIT, "tx_xdp_xmit", }, - { ETHTOOL_XDP_XMIT_DROPS, "tx_xdp_xmit_drops", }, -}; - #define MVPP2_N_ETHTOOL_STATS(ntxqs, nrxqs) (ARRAY_SIZE(mvpp2_ethtool_mib_regs) + \ ARRAY_SIZE(mvpp2_ethtool_port_regs) + \ (ARRAY_SIZE(mvpp2_ethtool_txq_regs) * (ntxqs)) + \ - (ARRAY_SIZE(mvpp2_ethtool_rxq_regs) * (nrxqs)) + \ - ARRAY_SIZE(mvpp2_ethtool_xdp)) + (ARRAY_SIZE(mvpp2_ethtool_rxq_regs) * (nrxqs))) static void mvpp2_ethtool_get_strings(struct net_device *netdev, u32 sset, u8 *data) @@ -1979,20 +1958,23 @@ static void mvpp2_ethtool_get_strings(struct net_device *netdev, u32 sset, data += ETH_GSTRING_LEN; } } - - for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_xdp); i++) { - strscpy(data, mvpp2_ethtool_xdp[i].string, - ETH_GSTRING_LEN); - data += ETH_GSTRING_LEN; - } } -static void -mvpp2_get_xdp_stats(struct mvpp2_port *port, struct mvpp2_pcpu_stats *xdp_stats) +static void mvpp2_ethtool_get_xdp_stats(struct net_device *dev, + struct ethtool_xdp_stats *xdp_stats) { + const struct mvpp2_port *port = netdev_priv(dev); unsigned int start; unsigned int cpu; + xdp_stats->redirect = 0; + xdp_stats->pass = 0; + xdp_stats->drop = 0; + xdp_stats->xmit = 0; + xdp_stats->xmit_drops = 0; + xdp_stats->tx = 0; + xdp_stats->tx_errors = 0; + /* Gather XDP Statistics */ for_each_possible_cpu(cpu) { struct mvpp2_pcpu_stats *cpu_stats; @@ -2016,20 +1998,18 @@ mvpp2_get_xdp_stats(struct mvpp2_port *port, struct mvpp2_pcpu_stats *xdp_stats) xdp_tx_err = cpu_stats->xdp_tx_err; } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start)); - xdp_stats->xdp_redirect += xdp_redirect; - xdp_stats->xdp_pass += xdp_pass; - xdp_stats->xdp_drop += xdp_drop; - xdp_stats->xdp_xmit += xdp_xmit; - xdp_stats->xdp_xmit_drops += xdp_xmit_drops; - xdp_stats->xdp_tx += xdp_tx; - xdp_stats->xdp_tx_err += xdp_tx_err; + xdp_stats->redirect += xdp_redirect; + xdp_stats->pass += xdp_pass; + xdp_stats->drop += xdp_drop; + xdp_stats->xmit += xdp_xmit; + xdp_stats->xmit_drops += xdp_xmit_drops; + xdp_stats->tx += xdp_tx; + xdp_stats->tx_errors += xdp_tx_err; } } static void mvpp2_read_stats(struct mvpp2_port *port) { - struct mvpp2_pcpu_stats xdp_stats = {}; - const struct mvpp2_ethtool_counter *s; u64 *pstats; int i, q; @@ -2057,37 +2037,6 @@ static void mvpp2_read_stats(struct mvpp2_port *port) *pstats++ += mvpp2_read_index(port->priv, port->first_rxq + q, mvpp2_ethtool_rxq_regs[i].offset); - - /* Gather XDP Statistics */ - mvpp2_get_xdp_stats(port, &xdp_stats); - - for (i = 0, s = mvpp2_ethtool_xdp; - s < mvpp2_ethtool_xdp + ARRAY_SIZE(mvpp2_ethtool_xdp); - s++, i++) { - switch (s->offset) { - case ETHTOOL_XDP_REDIRECT: - *pstats++ = xdp_stats.xdp_redirect; - break; - case ETHTOOL_XDP_PASS: - *pstats++ = xdp_stats.xdp_pass; - break; - case ETHTOOL_XDP_DROP: - *pstats++ = xdp_stats.xdp_drop; - break; - case ETHTOOL_XDP_TX: - *pstats++ = xdp_stats.xdp_tx; - break; - case ETHTOOL_XDP_TX_ERR: - *pstats++ = xdp_stats.xdp_tx_err; - break; - case ETHTOOL_XDP_XMIT: - *pstats++ = xdp_stats.xdp_xmit; - break; - case ETHTOOL_XDP_XMIT_DROPS: - *pstats++ = xdp_stats.xdp_xmit_drops; - break; - } - } } static void mvpp2_gather_hw_statistics(struct work_struct *work) @@ -5735,6 +5684,7 @@ static const struct ethtool_ops mvpp2_eth_tool_ops = { .set_rxfh = mvpp2_ethtool_set_rxfh, .get_rxfh_context = mvpp2_ethtool_get_rxfh_context, .set_rxfh_context = mvpp2_ethtool_set_rxfh_context, + .get_xdp_stats = mvpp2_ethtool_get_xdp_stats, }; /* Used for PPv2.1, or PPv2.2 with the old Device Tree binding that