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 CB86CC433EF for ; Tue, 23 Nov 2021 16:41:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235333AbhKWQoj (ORCPT ); Tue, 23 Nov 2021 11:44:39 -0500 Received: from mga17.intel.com ([192.55.52.151]:39357 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234887AbhKWQoe (ORCPT ); Tue, 23 Nov 2021 11:44:34 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10177"; a="215767236" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="215767236" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:41:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="474813286" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga002.jf.intel.com with ESMTP; 23 Nov 2021 08:41:14 -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 1ANGf4Wf016784; Tue, 23 Nov 2021 16:41:11 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 03/26] ena: implement generic XDP statistics callbacks Date: Tue, 23 Nov 2021 17:39:32 +0100 Message-Id: <20211123163955.154512-4-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 ena driver has 6 XDP counters collected per-channel. Add callbacks for getting the number of channels and those counters using generic XDP stats infra. Signed-off-by: Alexander Lobakin Reviewed-by: Jesse Brandeburg --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 7d5d885d85d5..83e9b85cc998 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -3313,12 +3313,65 @@ static void ena_get_stats64(struct net_device *netdev, stats->tx_errors = 0; } +static int ena_get_xdp_stats_nch(const struct net_device *netdev, u32 attr_id) +{ + const struct ena_adapter *adapter = netdev_priv(netdev); + + switch (attr_id) { + case IFLA_XDP_XSTATS_TYPE_XDP: + return adapter->num_io_queues; + default: + return -EOPNOTSUPP; + } +} + +static int ena_get_xdp_stats(const struct net_device *netdev, u32 attr_id, + void *attr_data) +{ + const struct ena_adapter *adapter = netdev_priv(netdev); + struct ifla_xdp_stats *xdp_stats = attr_data; + u32 i; + + switch (attr_id) { + case IFLA_XDP_XSTATS_TYPE_XDP: + break; + default: + return -EOPNOTSUPP; + } + + for (i = 0; i < adapter->num_io_queues; i++) { + const struct u64_stats_sync *syncp; + const struct ena_stats_rx *stats; + u32 start; + + stats = &adapter->rx_ring[i].rx_stats; + syncp = &adapter->rx_ring[i].syncp; + + do { + start = u64_stats_fetch_begin_irq(syncp); + + xdp_stats->drop = stats->xdp_drop; + xdp_stats->pass = stats->xdp_pass; + xdp_stats->tx = stats->xdp_tx; + xdp_stats->redirect = stats->xdp_redirect; + xdp_stats->aborted = stats->xdp_aborted; + xdp_stats->invalid = stats->xdp_invalid; + } while (u64_stats_fetch_retry_irq(syncp, start)); + + xdp_stats++; + } + + return 0; +} + static const struct net_device_ops ena_netdev_ops = { .ndo_open = ena_open, .ndo_stop = ena_close, .ndo_start_xmit = ena_start_xmit, .ndo_select_queue = ena_select_queue, .ndo_get_stats64 = ena_get_stats64, + .ndo_get_xdp_stats_nch = ena_get_xdp_stats_nch, + .ndo_get_xdp_stats = ena_get_xdp_stats, .ndo_tx_timeout = ena_tx_timeout, .ndo_change_mtu = ena_change_mtu, .ndo_set_mac_address = NULL, -- 2.33.1