Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp163142lqg; Fri, 26 Apr 2024 11:35:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUShP8ezOVy0K9cer+K9MegBGsSh/nJya4uZN5ngavNQmnIZd33xnsqCN2u/5FICw6Ive/axcwHUyokIxv7iat2IUkiTL8AEtvANbERqg== X-Google-Smtp-Source: AGHT+IFO7TWokN3lxNzEk044TvS3AjWW/mOuy01ll/N2V3colMQufMimD5taOfNIapkQVchwrpeY X-Received: by 2002:a17:903:2b07:b0:1eb:e89:d68a with SMTP id mc7-20020a1709032b0700b001eb0e89d68amr2828431plb.5.1714156534695; Fri, 26 Apr 2024 11:35:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714156534; cv=pass; d=google.com; s=arc-20160816; b=lbK1RGV5h+s+mzgFlvYx1jjecXZ28NBFMISHtsy/DDDyerzYzw5TODjD63rFC1XFFp Tt2POPrQzhp8D2tGZg4P2lOsa+yNUPlHoA4QL6iu7izdNXhIKpyQ2w4rUu3tu5z02NyP 5KfurvGUscS8+C0j3jgIECwbuh4c5bt71q7TcgyfDQafsYgXHUNTLVqGMcKtp0GQT2XF Ce5kGwYPznY+ENgV+u2ErHHo0Ugo4sjwetHHfSM1EBfYRSwh1lZAcBXLw0f21PfQVY1D E5V014Z/uHkfslaPyzEw5HkN0M+qXjbhGMQcXH/mZOHE/ClADpeqy7WaP6kWo3j0jZXI V3sQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FvWkUDJTV88ioDILsOGCqcHdicMQ5/7lOhgwRuMptVU=; fh=aDTS+bpspYtECWIZkV9sc23CsXTIDr2sIkz0LRDYvxk=; b=fjBZw14ALjByxrQSYxxubaMoO7Ywpuw7d9hYynqYdNxNVHyIq5jiY3zmfdCN/Au8OJ FezVYc0VGqQPj78BywKjjYmauQgSPOJdhGIhVQnMs7yP5JporxYlE9zPC9UfM6oSdwLS v4PZE1r9iUOK83pMijrkpPeDgVa26R67b9XLxbNa14Kyb2KarHk+y8JLs5d6gNpcBKJJ VsaB2d6iOlw1UqZjxshoLpc+LBNy/pV8B6PQO2zftghDx8jOP6132VZ8jh4WBf4YLXAb zD/pkuSiaLUZndUSje4QujwdbZzIyJsiWdqPmr+kL2TrwGZE2R/JzYlmCQCkPXiuXk02 zTZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=PS19TAq3; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-160576-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160576-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p16-20020a1709027ed000b001eafa3d0248si1950813plb.598.2024.04.26.11.35.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 11:35:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160576-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=PS19TAq3; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-160576-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160576-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4D16FB20FAA for ; Fri, 26 Apr 2024 18:35:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8BE532745D; Fri, 26 Apr 2024 18:34:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="PS19TAq3" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 503FB2134B for ; Fri, 26 Apr 2024 18:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714156453; cv=none; b=g8f3gmXB1eOFoQx5oPBYmNX4sQVIaN3AA3HHAnANdA7z7L1yKmB4vxdHOiSi9IXvO5olSNnqpzCAlNVOFT02Fb4BZdW6ELYK7ji8XDWTzcdt3+rwrD0olF557EXx4KwD/13NzriC6hlN3I+dh/47HGAVBmjhmC0YdU4KHioQrGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714156453; c=relaxed/simple; bh=MLuvGJ/zA1iclcyHt/GxmXZCz5tS19mI8X3ZFBvh8do=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uXM5O8R7+oRwIxhrUMkxVpCW5L35EDXN2UDKEEpMngvMI/w+H+oAF9ypocSQu7uvgfol4hTIVwNkFJAbjtrdUjUa8Q4Hlo6lKWwAnTbbLJb2J2MBODvurR2lklR0NjtLuSkqd9cB10UOTtCBbagPb2oeDjFfTePOgF9Tn7NcoWY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=PS19TAq3; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1e8fce77bb2so19293315ad.0 for ; Fri, 26 Apr 2024 11:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1714156451; x=1714761251; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FvWkUDJTV88ioDILsOGCqcHdicMQ5/7lOhgwRuMptVU=; b=PS19TAq3fZDuOmElwvm4aY25ENEM+vR9XOJEbtlR79rMVLfExkKE6Uvdbv8KmpW09j a5ztdq/SlHm4DXkzwTnKWl3y3YmCri8fBi2T7vvAqqDM4TdiSTFKA8I83JMXcW4LBF3V tP9zfEduvPwtYPXBp1Ys7sj6odRVHm3eW4Qv8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714156451; x=1714761251; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FvWkUDJTV88ioDILsOGCqcHdicMQ5/7lOhgwRuMptVU=; b=QjklNIiV25MtS5V6qoVNxsmL4TEpz0c8mIShIEjEWF0iddF6TCoQ6F2FehuabCgTNY 7bt9w8tWOGE2QqIg3ASK2jBei/QmqgXDQteC2iA+7YFggmbjLwKbXaluqCRchMCoRJV4 REh3tMzKHHXSD3hi68WQClYUTkBEpdlvCB3B1OCPC2SaIfs14mO924LlovyXWu0yxDte f3LAF15bo7afKrZhLdH38Sj1ObjI2hKaHRr3n9qISsIwrkXjlPGDeWhQCDzY6qMASS7B BjTd59Wj3yUQOa/ma5FWjahIMlnV31OHfLbit6OArBYQ50yw/dn12dgPoNOAQmH1ANUl 5Pjw== X-Gm-Message-State: AOJu0YygXvLx9yDYNcp4CeiYCMEgmY1EfuovClLB08ruG8qfEkLeuqj2 9chZKLodgBlrOJfehW53hl4zUmwLODNu/yBYQSn+8ilGoGDbYFNNmZWWQ7xPfmi7T+HO9Feed8+ LjftpzzcPDlicluVrNsqGlSpYTs/E0mGUn7QncuVKN8vETT3Q8xnmC5cOQUgmpFILAmWE0DE3dW VwgkHbButX8rpz/7Qf5Q+C8f8PvhgzHZixBBGFGz2l3Kg= X-Received: by 2002:a17:902:c40f:b0:1e9:cf94:5bea with SMTP id k15-20020a170902c40f00b001e9cf945beamr4414909plk.35.1714156451222; Fri, 26 Apr 2024 11:34:11 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id j23-20020a170902759700b001deecb4f897sm15713152pll.100.2024.04.26.11.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 11:34:10 -0700 (PDT) From: Joe Damato To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, tariqt@nvidia.com, saeedm@nvidia.com Cc: mkarsten@uwaterloo.ca, gal@nvidia.com, nalramli@fastly.com, Joe Damato , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-rdma@vger.kernel.org (open list:MELLANOX MLX4 core VPI driver) Subject: [PATCH net-next v2 3/3] net/mlx4: support per-queue statistics via netlink Date: Fri, 26 Apr 2024 18:33:55 +0000 Message-Id: <20240426183355.500364-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240426183355.500364-1-jdamato@fastly.com> References: <20240426183355.500364-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Make mlx4 compatible with the newly added netlink queue stats API. Signed-off-by: Joe Damato Tested-by: Martin Karsten --- .../net/ethernet/mellanox/mlx4/en_netdev.c | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c index 5d3fde63b273..6875f8c5103a 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -3099,6 +3100,83 @@ void mlx4_en_set_stats_bitmap(struct mlx4_dev *dev, last_i += NUM_PHY_STATS; } +static void mlx4_get_queue_stats_rx(struct net_device *dev, int i, + struct netdev_queue_stats_rx *stats) +{ + struct mlx4_en_priv *priv = netdev_priv(dev); + const struct mlx4_en_rx_ring *ring; + + spin_lock_bh(&priv->stats_lock); + + if (!priv->port_up || mlx4_is_master(priv->mdev->dev)) + goto out_unlock; + + if (i < 0 || i >= priv->rx_ring_num) + goto out_unlock; + + ring = priv->rx_ring[i]; + stats->packets = READ_ONCE(ring->packets); + stats->bytes = READ_ONCE(ring->bytes); + stats->alloc_fail = READ_ONCE(ring->dropped); + +out_unlock: + spin_unlock_bh(&priv->stats_lock); +} + +static void mlx4_get_queue_stats_tx(struct net_device *dev, int i, + struct netdev_queue_stats_tx *stats) +{ + struct mlx4_en_priv *priv = netdev_priv(dev); + const struct mlx4_en_tx_ring *ring; + + spin_lock_bh(&priv->stats_lock); + + if (!priv->port_up || mlx4_is_master(priv->mdev->dev)) + goto out_unlock; + + if (i < 0 || i >= priv->tx_ring_num[TX]) + goto out_unlock; + + ring = priv->tx_ring[TX][i]; + stats->packets = READ_ONCE(ring->packets); + stats->bytes = READ_ONCE(ring->bytes); + +out_unlock: + spin_unlock_bh(&priv->stats_lock); +} + +static void mlx4_get_base_stats(struct net_device *dev, + struct netdev_queue_stats_rx *rx, + struct netdev_queue_stats_tx *tx) +{ + struct mlx4_en_priv *priv = netdev_priv(dev); + + spin_lock_bh(&priv->stats_lock); + + if (!priv->port_up || mlx4_is_master(priv->mdev->dev)) + goto out_unlock; + + if (priv->rx_ring_num) { + rx->packets = 0; + rx->bytes = 0; + rx->alloc_fail = 0; + } + + if (priv->tx_ring_num[TX]) { + tx->packets = 0; + tx->bytes = 0; + } + +out_unlock: + spin_unlock_bh(&priv->stats_lock); +} + +static const struct netdev_stat_ops mlx4_stat_ops = { + .get_queue_stats_rx = mlx4_get_queue_stats_rx, + .get_queue_stats_tx = mlx4_get_queue_stats_tx, + .get_base_stats = mlx4_get_base_stats, +}; + int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, struct mlx4_en_port_profile *prof) { @@ -3262,6 +3340,7 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, netif_set_real_num_tx_queues(dev, priv->tx_ring_num[TX]); netif_set_real_num_rx_queues(dev, priv->rx_ring_num); + dev->stat_ops = &mlx4_stat_ops; dev->ethtool_ops = &mlx4_en_ethtool_ops; /* -- 2.25.1