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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61664C433EF for ; Tue, 23 Nov 2021 16:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235767AbhKWQoy (ORCPT ); Tue, 23 Nov 2021 11:44:54 -0500 Received: from mga09.intel.com ([134.134.136.24]:6540 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233467AbhKWQoq (ORCPT ); Tue, 23 Nov 2021 11:44:46 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10177"; a="234880016" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="234880016" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:41:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="606869170" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga004.jf.intel.com with ESMTP; 23 Nov 2021 08:41:19 -0800 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 1ANGf4Wh016784; Tue, 23 Nov 2021 16:41:16 GMT From: Alexander Lobakin To: "David S. Miller" , Jakub Kicinski Cc: Alexander Lobakin , Jesse Brandeburg , Michal Swiatkowski , Maciej Fijalkowski , Jonathan Corbet , Shay Agroskin , Arthur Kiyanovski , David Arinzon , Noam Dagan , Saeed Bishara , Ioana Ciornei , Claudiu Manoil , Tony Nguyen , Thomas Petazzoni , Marcin Wojtas , Russell King , Saeed Mahameed , Leon Romanovsky , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , John Fastabend , Edward Cree , Martin Habets , "Michael S. Tsirkin" , Jason Wang , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Lorenzo Bianconi , Yajun Deng , Sergey Ryazanov , David Ahern , Andrei Vagin , Johannes Berg , Vladimir Oltean , Cong Wang , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, bpf@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v2 net-next 05/26] enetc: implement generic XDP stats callbacks Date: Tue, 23 Nov 2021 17:39:34 +0100 Message-Id: <20211123163955.154512-6-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211123163955.154512-1-alexandr.lobakin@intel.com> References: <20211123163955.154512-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similarly to dpaa2, enetc stores 5 per-channel counters for XDP. Add necessary callbacks to be able to access them using new generic XDP stats infra. Signed-off-by: Alexander Lobakin Reviewed-by: Jesse Brandeburg --- drivers/net/ethernet/freescale/enetc/enetc.c | 48 +++++++++++++++++++ drivers/net/ethernet/freescale/enetc/enetc.h | 3 ++ .../net/ethernet/freescale/enetc/enetc_pf.c | 2 + 3 files changed, 53 insertions(+) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 504e12554079..ec62765377a7 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -2575,6 +2575,54 @@ struct net_device_stats *enetc_get_stats(struct net_device *ndev) return stats; } +int enetc_get_xdp_stats_nch(const struct net_device *ndev, u32 attr_id) +{ + const struct enetc_ndev_priv *priv = netdev_priv(ndev); + + switch (attr_id) { + case IFLA_XDP_XSTATS_TYPE_XDP: + return max(priv->num_rx_rings, priv->num_tx_rings); + default: + return -EOPNOTSUPP; + } +} + +int enetc_get_xdp_stats(const struct net_device *ndev, u32 attr_id, + void *attr_data) +{ + struct ifla_xdp_stats *xdp_iter, *xdp_stats = attr_data; + const struct enetc_ndev_priv *priv = netdev_priv(ndev); + const struct enetc_ring_stats *stats; + u32 i; + + switch (attr_id) { + case IFLA_XDP_XSTATS_TYPE_XDP: + break; + default: + return -EOPNOTSUPP; + } + + for (i = 0; i < priv->num_tx_rings; i++) { + stats = &priv->tx_ring[i]->stats; + xdp_iter = xdp_stats + i; + + xdp_iter->tx = stats->xdp_tx; + xdp_iter->tx_errors = stats->xdp_tx_drops; + } + + for (i = 0; i < priv->num_rx_rings; i++) { + stats = &priv->rx_ring[i]->stats; + xdp_iter = xdp_stats + i; + + xdp_iter->drop = stats->xdp_drops; + xdp_iter->redirect = stats->xdp_redirect; + xdp_iter->redirect_errors = stats->xdp_redirect_failures; + xdp_iter->redirect_errors += stats->xdp_redirect_sg; + } + + return 0; +} + static int enetc_set_rss(struct net_device *ndev, int en) { struct enetc_ndev_priv *priv = netdev_priv(ndev); diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index fb39e406b7fc..8f175f0194e3 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -389,6 +389,9 @@ void enetc_start(struct net_device *ndev); void enetc_stop(struct net_device *ndev); netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev); struct net_device_stats *enetc_get_stats(struct net_device *ndev); +int enetc_get_xdp_stats_nch(const struct net_device *ndev, u32 attr_id); +int enetc_get_xdp_stats(const struct net_device *ndev, u32 attr_id, + void *attr_data); int enetc_set_features(struct net_device *ndev, netdev_features_t features); int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd); diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index fe6a544f37f0..c7776b842a91 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -729,6 +729,8 @@ static const struct net_device_ops enetc_ndev_ops = { .ndo_stop = enetc_close, .ndo_start_xmit = enetc_xmit, .ndo_get_stats = enetc_get_stats, + .ndo_get_xdp_stats_nch = enetc_get_xdp_stats_nch, + .ndo_get_xdp_stats = enetc_get_xdp_stats, .ndo_set_mac_address = enetc_pf_set_mac_addr, .ndo_set_rx_mode = enetc_pf_set_rx_mode, .ndo_vlan_rx_add_vid = enetc_vlan_rx_add_vid, -- 2.33.1