Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp10489lqd; Tue, 23 Apr 2024 12:50:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXE5UgxMq3ohX8Tej0Qjc2WCsQbRpwTMZ/pY2q/1Zd6dCrKCVGvN/RMZJf8kGYeyIS6FXNyOcwd6d342rWjBdNZ0l/pLGTYiVjVmjcHPQ== X-Google-Smtp-Source: AGHT+IE/85+KDM7UhaL2HI5p2+EVb6ITR07YkzY7tJISwiUjaLnhCbUPGWNYSi7E430uEGNWrv0k X-Received: by 2002:a17:906:c49:b0:a55:b345:63ec with SMTP id t9-20020a1709060c4900b00a55b34563ecmr201430ejf.15.1713901848364; Tue, 23 Apr 2024 12:50:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713901848; cv=pass; d=google.com; s=arc-20160816; b=kU0WTokGlcIEqThv0Jjb4gJgkZmeb7Z46Tbijki1luMJBMFGbYpFpSogYrKfege3px bGLNRFDwbCxytgKQD03LF4JrhiLw/zUL8HVRak66nlCiA8LTwvjrPakzB/avRIp3/C+f ededKukh4mNhfc4YoJauCoKNAVFUvb1eL+m/JJ4uPT6b6V0tJThE7FzzWYQBF301LRW1 9ifP8F4jxoQSbdxMI5d9epS8ypkZr7+eH2HGQgJUuPSYz4jHeOpc16zTD6G4JYNyL2J6 ZJFmFMhj0TUwAUgptv+QqlBGRD/pgqJ6Wl8ZNmKunpCqfXkszV2sGl+nPhPbK7FLoILZ OjlA== 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=xVn2/16u03FLjFZk8aJRPJceLU2TpVvTdEBl2UjSyh4=; fh=aDTS+bpspYtECWIZkV9sc23CsXTIDr2sIkz0LRDYvxk=; b=LYymLCh9g2r5MH7BAoRtZYPmIa9FCvGCKvN/vioRMH5Vo4BVgvTCY3vcGTuz2sdLM4 +elaua/G3UN5vFn7A37TYlebZiJOKKit9XyPAUoQD/ix2YAE7k9WlRxb82wuT6ET4BT/ HkkH8/dXbqPyXVn+Uzx+O7BwcP+8Mnee9thUhYIXx7+ZCw+7jQ8VTq+/WPKpt4J3S9N9 JrZh3dZogg1sSkmpmJqlkZ2xiF7uh0v/0+TV7iHzBhkKqjp8NBD0Gm8zixYsmNqsxjK8 wkfToz6aw7tit9/2B8hTVh4hXsUre6WKxVPDDCO8qHktbW2nutqes8NctXBxuWyvrGBA 7vcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=CN2stkCg; 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-155821-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155821-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f9-20020a1709067f8900b00a55b5c66cb0si2947274ejr.54.2024.04.23.12.50.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 12:50:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155821-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=CN2stkCg; 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-155821-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155821-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D701D1F236AD for ; Tue, 23 Apr 2024 19:50:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D508143864; Tue, 23 Apr 2024 19:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="CN2stkCg" Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 E1302142E60 for ; Tue, 23 Apr 2024 19:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713901783; cv=none; b=ezrC0dzUv6lTdEAglnxxDfBBS/b+Mii4psSogKUgkpGPL4ZvVh9nlSaT9mcv3jwYMwrE67t0nxYgQ98tEkuDwIWSKYMVFYyKnBfnF4RYTgGBKSOrDPTaVoDqGvKujOZPhpSyPEmpTfKv3Q8+5/nNxG2ah7iHEKv+n+5SsIK0w5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713901783; c=relaxed/simple; bh=Ia0r0BSwe8QIUJufAJclFiQc0GFm4DiTWN09Y106Hm8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i9FQF1iOgjhCc4M6BMCrExcoOZD/OBD3YEg7bpwk2t/A4AQXVH04zqR+FRRvWt88ja04Plb1HiP5xwss1WiftwwCO0Na/Tboa1QEjr23bKC7Qq6OjnCwSP70+PoJ2HWZCA/wQyLkyZmPuC2nHkrU/UJN56vwwYFvPyN8DecNQMY= 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=CN2stkCg; arc=none smtp.client-ip=209.85.210.182 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-pf1-f182.google.com with SMTP id d2e1a72fcca58-6ed691fb83eso4829866b3a.1 for ; Tue, 23 Apr 2024 12:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1713901781; x=1714506581; 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=xVn2/16u03FLjFZk8aJRPJceLU2TpVvTdEBl2UjSyh4=; b=CN2stkCgehZlulLdHqvj4QacpGOOalxpFaExf6HABiOhoqahuJ8NZIgWGYxRpWhL0E P2XMn1Pf11viDCxJ3SC222bNo9qeAfphBqcbqucYlwivRd/+RQLb0/R1vMVR0k4E6Bpe M8/UbE/xbCWBgnC8dL6OjZw+eNODMo9P/utfQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713901781; x=1714506581; 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=xVn2/16u03FLjFZk8aJRPJceLU2TpVvTdEBl2UjSyh4=; b=dnSZH12xNnDprWyDH4iY4kcI5MdYbUbJWnsKekvuqcVShqlo44NgMoUrG1Cz8hfCmo X/vSeunooUBBXZi52FZDZADGF45r02xo8Li/YtCtr9yabf8lrB9hoquPYwAwjlyVtEkt VklKzheLFYKQzU2CGsVXGpRqp/Ac2HUY1O/l0SI9yEBHJ2+N7tCEpRpXBSuziIt5zOhU 5tvX14FBZJ63SVmJzxegjDLuJLBZEnluRXwSxg6cayJxhruzMceub3R1U7Z+ZZzIDoFx 2YQiYruw2cGwThW3txAWMC3wJVeTgEzMvGRh0vk+efSzdbfytOdgv9kdq3ILnz/ONDoW r4cQ== X-Gm-Message-State: AOJu0Yx2Axt1dQ+z5cKzmAflwzElm39MZYD4cMNBneJ9AfMGzrBmnQp1 /aBGztS4gDWzgKAa7CbtMmp5idD+3spVY8alwANfoEYaVB9vC7pMWgjNjFFawZXaTImC9b4QUzI 7N9t+bm9/84xXtQMi3HBFUkmr8aUJcFZHPjr4YKDMWeulw5JdE0ZbkpAiXzKHKUhUKQdwthn6Ua HosqmmCIgfXcHVRFutTAosPfA+GJCRJWPmB2HPAkDkOCw= X-Received: by 2002:a05:6a20:974a:b0:1ad:746:b15a with SMTP id hs10-20020a056a20974a00b001ad0746b15amr349392pzc.47.1713901780830; Tue, 23 Apr 2024 12:49:40 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id q3-20020a056a00084300b006ecc6c1c67asm9995672pfk.215.2024.04.23.12.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 12:49:40 -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 3/3] net/mlx4: support per-queue statistics via netlink Date: Tue, 23 Apr 2024 19:49:30 +0000 Message-Id: <20240423194931.97013-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240423194931.97013-1-jdamato@fastly.com> References: <20240423194931.97013-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 | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c index 5d3fde63b273..c7f04d4820c6 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,95 @@ 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; + + stats->packets = 0xff; + stats->bytes = 0xff; + stats->alloc_fail = 0xff; + + spin_lock_bh(&priv->stats_lock); + + if (!priv->port_up || mlx4_is_master(priv->mdev->dev)) + 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; + + stats->packets = 0xff; + stats->bytes = 0xff; + + spin_lock_bh(&priv->stats_lock); + + if (!priv->port_up || mlx4_is_master(priv->mdev->dev)) + 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); + int i; + + rx->packets = 0xff; + rx->bytes = 0xff; + rx->alloc_fail = 0xff; + tx->packets = 0xff; + tx->bytes = 0xff; + + spin_lock_bh(&priv->stats_lock); + + if (!priv->port_up || mlx4_is_master(priv->mdev->dev)) + goto out_unlock; + + for (i = 0; i < priv->rx_ring_num; i++) { + const struct mlx4_en_rx_ring *ring = priv->rx_ring[i]; + + rx->packets += READ_ONCE(ring->packets); + rx->bytes += READ_ONCE(ring->bytes); + rx->alloc_fail += READ_ONCE(ring->dropped); + } + + for (i = 0; i < priv->tx_ring_num[TX]; i++) { + const struct mlx4_en_tx_ring *ring = priv->tx_ring[TX][i]; + + tx->packets += READ_ONCE(ring->packets); + tx->bytes += READ_ONCE(ring->bytes); + } + +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 +3352,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