Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp97168lqo; Thu, 9 May 2024 13:52:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXne9UJ1dR0m4xhQqtKJOXRWoxiFf5c2hiKOXc/qpzUGSJ2WkQyxfLH4x5TePcD7mnE362C63zu7ACfhy2hBBL9cfhMrtvP9S8a8gStWQ== X-Google-Smtp-Source: AGHT+IG4xI0sylGzvzR2D7cNUofufGLK3gd3q0YvA3eQsrdlzkhUPZcCyewvdrvfgsnaKjE5InHL X-Received: by 2002:a05:6a20:244c:b0:1af:ccd8:c11c with SMTP id adf61e73a8af0-1afde10e30amr1144729637.29.1715287940213; Thu, 09 May 2024 13:52:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715287940; cv=pass; d=google.com; s=arc-20160816; b=hvCC4qm+wKXuut9uK3R/hMpomV6uNfvmH7F+kJ4qJAM5OSoT2n/1Se4sYWDdU3kPFs AEIutSVuStpiP04XabnaB/PUfPsi5zvFnOL7BWyKk4QW/h01XtG4e2l7QWfs6It1dzkA vZGIvnw9IZmO1liahZM8UC3A1EqGPVOkXjXW10VIUGThsnTwGzaROz3rBm7PD3gjiwOc 7ORjCjmGWzPFGa8don3GbkP0X+VGA36Q3C8+koAxkthl0s9gmzN0y48EzPHG019I8P8Q KYbk0H3yYfJsNgroY90YVepitGzIk6iPZpuraNQgK3/gmcozpc/6FJnP/Dj6VSXfizYu eLQg== 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=No8/jmvB2lIMy6tK61c0Wm+y+Z2VaVEhQDXdDb8ENDg=; fh=7D277dvSYbSMIMnwgfRc7huvydmITLCRdKfl6wh4SaA=; b=Tm2zPekFk+s8hFWGcMd3Hjd/z6JofmFbPcuB8+zeM5iHwYxrpk/wYqvf+7/Q8Lul++ IEOBOTG7/JvYRF1jTeA6FHiLy+v7Wr6du9Kkl/9qv/K8NO9gR9PBmUieywok3h9cpZOq PPUJ+Iwz5UFp2DyGH6ZO2+NjRdxdcEHJ45eddru4YSna72Cq4+gKR7etZP5cnCwAm13z 7iZ5+mApGolzddb/BaqzO3kzaclVlA27hRv1E0fMzQLP1RZA87N/a/qjk2xhl8U5lxtC fI7Enwp/ijY6QompVAXTlD9LRGqreElXruzNrpwIBwKT6qJOLA0xoyaCik4nDxsteuhD QxVg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=jXh2kqeU; 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-174956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63412863ed9si2113817a12.685.2024.05.09.13.52.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 13:52:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=jXh2kqeU; 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-174956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174956-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C907728153A for ; Thu, 9 May 2024 20:52:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7498B80C1D; Thu, 9 May 2024 20:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="jXh2kqeU" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 52CDD8594C for ; Thu, 9 May 2024 20:51:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715287874; cv=none; b=ltyBi2f+RYy8UGs8yf3U+yv3XgjSshOd/jBfWd0L0OCiXNF3vTObFkMND7rtfe1cLWp3zh1hOQDzALXeg1UY23dfuiP8aCNs7QmEtnQzEO8UinlEg7UUlddMCAKfyqhB1ZnLpKeoV0H0nOrKqcP3Q3ByfyaFap585TxtNSNOqhY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715287874; c=relaxed/simple; bh=jh0q0ulQ5LcPy3XQUg0Ue3n4pGfewvXGaX+N3ICGH+Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bGEDKufsvxZR7Km5+K35YRookfADO/ilEs7e7tW4BbqoF3JU2hhny2ABmaOYQoFC+7lQ94HPjmMHauWxdPtk5b/nnsDnn80/IGCo8Ln0O3SqM1A/FboMPV1bkzDpswcOuAqmW8CF5ptF/XH//vVaBgEwcQtCelBpDN9MIDIeo1Y= 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=jXh2kqeU; arc=none smtp.client-ip=209.85.214.177 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-f177.google.com with SMTP id d9443c01a7336-1e83a2a4f2cso8219855ad.1 for ; Thu, 09 May 2024 13:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1715287869; x=1715892669; 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=No8/jmvB2lIMy6tK61c0Wm+y+Z2VaVEhQDXdDb8ENDg=; b=jXh2kqeUaVQ0nhfXGHTIL23aws5KMCR8Yscd7r1sehBwfSwQRHDjCnXqcnG0IRr0oH 3a+hKH2nHUvzXiXJA9/y/H35CGqSW2LAh6Wx5h13meATPrwl3nalSImdxrrhXHWILNuv 4JPlAyjSq+MMJEmRPYcZXa80RgNMRcWQWZ1i8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715287869; x=1715892669; 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=No8/jmvB2lIMy6tK61c0Wm+y+Z2VaVEhQDXdDb8ENDg=; b=rjgk6kTy2f8b8RllptdGNjokgXDUrbBU+cvzh5pUrMJG7gjTQFDlapT5Qjq9rQnNRH ZPlpxTdrQwi509/Thc7PqwGb46q6N+q22BHmY1iSFFZc239Jo4scpUnrqxdfG5R/V305 MMcvIuLvZojUACgjFuI1CdLP4WeGYomV+r0kDgkUJ9dMQ/q5ovlKR40TjWbeo6to7eV8 4VUezAjcSx2TU+uRqDrRGPJXC3oVbGOzmn1DRiqbK8z/wp54/dE1QJnkoHwCOABYJThe 8F3qVePAWyHgC7PdhfzxK+IRDywQxh1/iUTX2ipY2LB2oY7rBDq6dmuxFplogvLBjyQU JHXw== X-Gm-Message-State: AOJu0YxvM3ystQaMTz0vDWzQOPUsaloAVlIU5DpxkMAGWlzdtg7G+mRo aiUcSJZ6+QzdZVEW9LHiLu3g4AN3WEQisDgq4Uyh5QEkrOHmFOmvAktAVGQHIgWIC2LKF093WqM KYoLNcVCqPMoz7EcmFgPMSASPOLSgM64oxjXypS94+t8tPs7x+4W0tJBqznUfbVEXUNjFTGejzz WCbR33NTqp1WhkvhmelK9TE+FzVaVqkLhckeEbcrH/ouo= X-Received: by 2002:a17:902:f812:b0:1eb:1474:5ef5 with SMTP id d9443c01a7336-1ef43d2ea72mr6154495ad.33.1715287868873; Thu, 09 May 2024 13:51:08 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0badb959sm18677365ad.85.2024.05.09.13.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 13:51:08 -0700 (PDT) From: Joe Damato To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: mkarsten@uwaterloo.ca, nalramli@fastly.com, Joe Damato , Tariq Toukan , "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 v4 3/3] net/mlx4: support per-queue statistics via netlink Date: Thu, 9 May 2024 20:50:56 +0000 Message-Id: <20240509205057.246191-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240509205057.246191-1-jdamato@fastly.com> References: <20240509205057.246191-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 | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c index 4c089cfa027a..fd79e957b5d8 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,77 @@ 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; + + ring = priv->rx_ring[i]; + stats->packets = READ_ONCE(ring->packets); + stats->bytes = READ_ONCE(ring->bytes); + stats->alloc_fail = READ_ONCE(ring->alloc_fail); + +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; + + 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 +3334,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