From patchwork Sat Jul 16 07:34:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 12919962 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1261EC43334 for ; Sat, 16 Jul 2022 07:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=shPL8vIhIvOhdmR2gRXEOT4ZyWz1oALRAGrVh6KATKk=; b=v1XvG4KEe0etQ+nzPQEchEm8ta awHenwRUUJMWJV+RvBFKbigNXPJqucgaO2HpdWZFRpgr8Y21n1NsVUG1CeeBVYYbsJsgqgQ/Yfo71 vAo5oz76unvJYEq/CvbKSmVS4Mri6mojXKq9tYgaRysnrtb6JNmEvh1czWKAdDUmaE9ehWW/jkrzA uUEBHXFN0uMPda0n1AZQUzc/Bn4rfHQT7rSAeHWz2+k2eBRMG1wwBsStUBXma39fb/H9NOcETPAGX nSMv3n2fn4MgqpTmpvXV5ayeKPO2cApaJfEgLnSsr7n5koHvY4q8LYE/KA32OCq/yciK7tc+wVHn/ TiyKagDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCcKM-00ET69-Uy; Sat, 16 Jul 2022 07:35:02 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCcKK-00ET3d-Az for linux-mediatek@lists.infradead.org; Sat, 16 Jul 2022 07:35:01 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 84ACA60C61; Sat, 16 Jul 2022 07:34:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6AC7C34114; Sat, 16 Jul 2022 07:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657956898; bh=+Xn6F79/iHikq4VckzZP3r+YfKxQAY1XBQehjgjmxTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k1VZCm5yK5Zte7GtdsfhV8ZpXFRBG6t9KTLNtzudWekG9yvR/eIwTh5jqGGhs5o3I KsbF+egy9Uuyqc43EqI+H3s39L7NPUqVHiDpbHnEgyQ4qjS1PSe1CtHwBDzzFDzG85 ZtSs2YzgA4SoaHOrEoC98pGZQRJbuApj0vTrlHL9u62Fj173+B8FL6n/GUPOayYzo/ P/y4wRmvLx4J5nbVZWd6Cg5trUlK/5i3xaO7OkA/8jZkZmR8O6A6N7fSGj4XSvwm2t t7D1FFErinh2EV95plp9Ac7x53L84GJPOglCSW7viPJpsBH0ruIQvINI0V3jtXEJEL Wk4bypmOMYBWw== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: nbd@nbd.name, john@phrozen.org, sean.wang@mediatek.com, Mark-MC.Lee@mediatek.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com, linux-mediatek@lists.infradead.org, ilias.apalodimas@linaro.org, lorenzo.bianconi@redhat.com, jbrouer@redhat.com Subject: [PATCH v3 net-next 3/5] net: ethernet: mtk_eth_soc: introduce xdp ethtool counters Date: Sat, 16 Jul 2022 09:34:29 +0200 Message-Id: <0efedf80284fc07bbbc82652b5495bdcf0c89e20.1657956652.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220716_003500_489695_CDD7E215 X-CRM114-Status: GOOD ( 13.47 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Report xdp stats through ethtool Signed-off-by: Lorenzo Bianconi --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 32 ++++++++++++++++++--- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 12 ++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index bc3a7dcab207..e4715b6cc978 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -34,6 +34,10 @@ MODULE_PARM_DESC(msg_level, "Message level (-1=defaults,0=none,...,16=all)"); #define MTK_ETHTOOL_STAT(x) { #x, \ offsetof(struct mtk_hw_stats, x) / sizeof(u64) } +#define MTK_ETHTOOL_XDP_STAT(x) { #x, \ + offsetof(struct mtk_hw_stats, xdp_stats.x) / \ + sizeof(u64) } + static const struct mtk_reg_map mtk_reg_map = { .tx_irq_mask = 0x1a1c, .tx_irq_status = 0x1a18, @@ -141,6 +145,13 @@ static const struct mtk_ethtool_stats { MTK_ETHTOOL_STAT(rx_long_errors), MTK_ETHTOOL_STAT(rx_checksum_errors), MTK_ETHTOOL_STAT(rx_flow_control_packets), + MTK_ETHTOOL_XDP_STAT(rx_xdp_redirect), + MTK_ETHTOOL_XDP_STAT(rx_xdp_pass), + MTK_ETHTOOL_XDP_STAT(rx_xdp_drop), + MTK_ETHTOOL_XDP_STAT(rx_xdp_tx), + MTK_ETHTOOL_XDP_STAT(rx_xdp_tx_errors), + MTK_ETHTOOL_XDP_STAT(tx_xdp_xmit), + MTK_ETHTOOL_XDP_STAT(tx_xdp_xmit_errors), }; static const char * const mtk_clks_source_name[] = { @@ -1498,6 +1509,9 @@ static u32 mtk_xdp_run(struct mtk_eth *eth, struct mtk_rx_ring *ring, struct xdp_buff *xdp, struct net_device *dev) { struct bpf_prog *prog = rcu_dereference(eth->prog); + struct mtk_mac *mac = netdev_priv(dev); + struct mtk_hw_stats *hw_stats = mac->hw_stats; + u64 *count = &hw_stats->xdp_stats.rx_xdp_drop; u32 act; if (!prog) @@ -1506,11 +1520,16 @@ static u32 mtk_xdp_run(struct mtk_eth *eth, struct mtk_rx_ring *ring, act = bpf_prog_run_xdp(prog, xdp); switch (act) { case XDP_PASS: - return XDP_PASS; + count = &hw_stats->xdp_stats.rx_xdp_pass; + goto update_stats; case XDP_REDIRECT: - if (unlikely(xdp_do_redirect(dev, xdp, prog))) + if (unlikely(xdp_do_redirect(dev, xdp, prog))) { + act = XDP_DROP; break; - return XDP_REDIRECT; + } + + count = &hw_stats->xdp_stats.rx_xdp_redirect; + goto update_stats; default: bpf_warn_invalid_xdp_action(dev, prog, act); fallthrough; @@ -1523,7 +1542,12 @@ static u32 mtk_xdp_run(struct mtk_eth *eth, struct mtk_rx_ring *ring, page_pool_put_full_page(ring->page_pool, virt_to_head_page(xdp->data), true); - return XDP_DROP; +update_stats: + u64_stats_update_begin(&hw_stats->syncp); + *count = *count + 1; + u64_stats_update_end(&hw_stats->syncp); + + return act; } static int mtk_poll_rx(struct napi_struct *napi, int budget, diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index cfb7aeda3f49..2775da1a6ec3 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -570,6 +570,16 @@ struct mtk_tx_dma_v2 { struct mtk_eth; struct mtk_mac; +struct mtk_xdp_stats { + u64 rx_xdp_redirect; + u64 rx_xdp_pass; + u64 rx_xdp_drop; + u64 rx_xdp_tx; + u64 rx_xdp_tx_errors; + u64 tx_xdp_xmit; + u64 tx_xdp_xmit_errors; +}; + /* struct mtk_hw_stats - the structure that holds the traffic statistics. * @stats_lock: make sure that stats operations are atomic * @reg_offset: the status register offset of the SoC @@ -593,6 +603,8 @@ struct mtk_hw_stats { u64 rx_checksum_errors; u64 rx_flow_control_packets; + struct mtk_xdp_stats xdp_stats; + spinlock_t stats_lock; u32 reg_offset; struct u64_stats_sync syncp;