From patchwork Wed Apr 10 04:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13623533 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 398D1C8E0 for ; Wed, 10 Apr 2024 04:39:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712723986; cv=none; b=bh/Pd79uADMIb6vLyLtXxO7Gd9nfTY7pLe+QbxwwAdcnuEUic4ZIUtzR6AGfMLT2AgQbGwr5BDw7Op+sSyxVhN3bvoitEHmv2BvCSn3RIMsi/ykTrDERNKdm8CwUSdX6DfHa2DhHbaKQ2LBDgZk6d3LMILL3y4mhxeYtfIwBLu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712723986; c=relaxed/simple; bh=+aWoCTLRMEia/7VjS+8wDfmv4sTpAQMvPaISA6TV6lQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uj17Nue7vSGunnoD2tV7Wx8bTbdNn2qzEO6e0VmxkCz2syOlb6nm1UNQGFvBgqi3X+MMDEX9g9s+rYhiar+IFKjahbFZItcZWe7NACocV2E/z8hVLsWop39cNLDdRrmc8M7diNiTbZJq2ZhLFYKoKd1ewngExedXLVjuuMgAYcY= 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=qjfLpDzr; arc=none smtp.client-ip=209.85.216.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="qjfLpDzr" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2a2c9903ef0so4407179a91.3 for ; Tue, 09 Apr 2024 21:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1712723984; x=1713328784; 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=5x0y6JOjRs9D46M/YJwxsoJQEODb8B73PIsmrjKpgsY=; b=qjfLpDzrIuZLnXsMmjOKRmjEK0xn+SlbIQ855rvr2bUrzeDoUJm1wAuLikBW3cnXJ5 C4J29jzUXlzYOwFxMvJ9WxB2EBGadsT1+/gxXLTnktW4N1zJkOrTwP+pPXxt5PUdlVf5 r9/nVUzaZvVYgEr2Cyw1rfSMUD3fNJp1BcquU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712723984; x=1713328784; 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=5x0y6JOjRs9D46M/YJwxsoJQEODb8B73PIsmrjKpgsY=; b=OgUoayHTK74KgZmkepe/ecapEeejG3PfpVhOLjoqMrqs8GYCPh7ayGvORPlLK4lqsI AQRzC2F7Mql7e9p9qMOUMRLQCuOU0RhngzD+PHpvXMWHxlylxsmmYoP4VXOMQ5WUzjWH 7mFoebzxNRM0GXGGCPFFziftTTwgYjib9gddZxy1AxiL5TShA+rnZtU4Zpozfwlbe/i7 WyT3MMY5M/45axjsbI8+mIGtEr2Ijl6pizaqbnw03eB/cf38RkpAMBHeP4HrF8BzqL3t 7B53MwOpABKoZIvMnFrq7LTYi7zRiJPxsijQx5WZxVgRXpJl89mlv2a8aTM6JAD8JaB9 +maQ== X-Forwarded-Encrypted: i=1; AJvYcCUkgL72LrlepHFV/vDqnbbBR21ZVtJkT8Pwtbr4N8W1Cd1qEilCEFwzn42ovvX941XGCCKKPWbc+tP6dCBkj2bPjNllxSyW X-Gm-Message-State: AOJu0YyYWj5iZIGVPmnqwv67zv4o9waI+S7g6LtNSUSNIx6i/X3PzIRu aVjiuqHtQPFyGLijWuDs5NGlMK5EAsJV5+qQMYLeZ1zk+I7e1shQJnzzV72iQhM= X-Google-Smtp-Source: AGHT+IEk7YATwthbk+mb9fqMLJPGxEBJa32KoCGCBl7Dyq/xvT3FTYwVMeMq3y3WDq6N/pse9NqSxQ== X-Received: by 2002:a17:90b:2287:b0:2a5:d7ed:2d18 with SMTP id kx7-20020a17090b228700b002a5d7ed2d18mr329439pjb.20.1712723984438; Tue, 09 Apr 2024 21:39:44 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id gn4-20020a17090ac78400b002a5d71d48e8sm260773pjb.39.2024.04.09.21.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 21:39:44 -0700 (PDT) From: Joe Damato To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com, nalramli@fastly.com, Joe Damato , Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [intel-next 1/2] net/i40e: link NAPI instances to queues and IRQs Date: Wed, 10 Apr 2024 04:39:34 +0000 Message-Id: <20240410043936.206169-2-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240410043936.206169-1-jdamato@fastly.com> References: <20240410043936.206169-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Make i40e compatible with the newly added netlink queue GET APIs. $ ./cli.py --spec ../../../Documentation/netlink/specs/netdev.yaml \ --do queue-get --json '{"ifindex": 3, "id": 1, "type": "rx"}' {'id': 1, 'ifindex': 3, 'napi-id': 162, 'type': 'rx'} $ ./cli.py --spec ../../../Documentation/netlink/specs/netdev.yaml \ --do napi-get --json '{"id": 162}' {'id': 162, 'ifindex': 3, 'irq': 136} The above output suggests that irq 136 was allocated for queue 1, which has a NAPI ID of 162. To double check this is correct, the IRQ to queue mapping can be verified by checking /proc/interrupts: $ cat /proc/interrupts | grep 136\: | \ awk '{print "irq: " $1 " name " $76}' irq: 136: name i40e-vlan300-TxRx-1 Suggests that queue 1 has IRQ 136, as expected. Signed-off-by: Joe Damato --- drivers/net/ethernet/intel/i40e/i40e.h | 2 + drivers/net/ethernet/intel/i40e/i40e_main.c | 58 +++++++++++++++++++++ drivers/net/ethernet/intel/i40e/i40e_txrx.c | 4 ++ 3 files changed, 64 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h index 2fbabcdb5bb5..5900ed5c7170 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -1267,6 +1267,8 @@ int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); int i40e_open(struct net_device *netdev); int i40e_close(struct net_device *netdev); int i40e_vsi_open(struct i40e_vsi *vsi); +void i40e_queue_set_napi(struct i40e_vsi *vsi, unsigned int queue_index, + enum netdev_queue_type type, struct napi_struct *napi); void i40e_vlan_stripping_disable(struct i40e_vsi *vsi); int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid); int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid); diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 0bdcdea0be3e..6384a0c73a05 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -3448,6 +3448,58 @@ static struct xsk_buff_pool *i40e_xsk_pool(struct i40e_ring *ring) return xsk_get_pool_from_qid(ring->vsi->netdev, qid); } +/** + * __i40e_queue_set_napi - Set the napi instance for the queue + * @dev: device to which NAPI and queue belong + * @queue_index: Index of queue + * @type: queue type as RX or TX + * @napi: NAPI context + * @locked: is the rtnl_lock already held + * + * Set the napi instance for the queue. Caller indicates the lock status. + */ +static void +__i40e_queue_set_napi(struct net_device *dev, unsigned int queue_index, + enum netdev_queue_type type, struct napi_struct *napi, + bool locked) +{ + if (!locked) + rtnl_lock(); + netif_queue_set_napi(dev, queue_index, type, napi); + if (!locked) + rtnl_unlock(); +} + +/** + * i40e_queue_set_napi - Set the napi instance for the queue + * @vsi: VSI being configured + * @queue_index: Index of queue + * @type: queue type as RX or TX + * @napi: NAPI context + * + * Set the napi instance for the queue. The rtnl lock state is derived from the + * execution path. + */ +void +i40e_queue_set_napi(struct i40e_vsi *vsi, unsigned int queue_index, + enum netdev_queue_type type, struct napi_struct *napi) +{ + struct i40e_pf *pf = vsi->back; + + if (!vsi->netdev) + return; + + if (current_work() == &pf->service_task || + test_bit(__I40E_PF_RESET_REQUESTED, pf->state) || + test_bit(__I40E_DOWN, pf->state) || + test_bit(__I40E_SUSPENDED, pf->state)) + __i40e_queue_set_napi(vsi->netdev, queue_index, type, napi, + false); + else + __i40e_queue_set_napi(vsi->netdev, queue_index, type, napi, + true); +} + /** * i40e_configure_tx_ring - Configure a transmit ring context and rest * @ring: The Tx ring to configure @@ -3558,6 +3610,8 @@ static int i40e_configure_tx_ring(struct i40e_ring *ring) /* cache tail off for easier writes later */ ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); + i40e_queue_set_napi(vsi, ring->queue_index, NETDEV_QUEUE_TYPE_TX, + &ring->q_vector->napi); return 0; } @@ -3716,6 +3770,8 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring) ring->queue_index, pf_q); } + i40e_queue_set_napi(vsi, ring->queue_index, NETDEV_QUEUE_TYPE_RX, + &ring->q_vector->napi); return 0; } @@ -4178,6 +4234,8 @@ static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) q_vector->affinity_notify.notify = i40e_irq_affinity_notify; q_vector->affinity_notify.release = i40e_irq_affinity_release; irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); + netif_napi_set_irq(&q_vector->napi, q_vector->irq_num); + /* Spread affinity hints out across online CPUs. * * get_cpu_mask returns a static constant mask with diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c index 64d198ed166b..d380885ff26d 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c @@ -821,6 +821,8 @@ void i40e_clean_tx_ring(struct i40e_ring *tx_ring) void i40e_free_tx_resources(struct i40e_ring *tx_ring) { i40e_clean_tx_ring(tx_ring); + i40e_queue_set_napi(tx_ring->vsi, tx_ring->queue_index, + NETDEV_QUEUE_TYPE_TX, NULL); kfree(tx_ring->tx_bi); tx_ring->tx_bi = NULL; @@ -1526,6 +1528,8 @@ void i40e_clean_rx_ring(struct i40e_ring *rx_ring) void i40e_free_rx_resources(struct i40e_ring *rx_ring) { i40e_clean_rx_ring(rx_ring); + i40e_queue_set_napi(rx_ring->vsi, rx_ring->queue_index, + NETDEV_QUEUE_TYPE_RX, NULL); if (rx_ring->vsi->type == I40E_VSI_MAIN) xdp_rxq_info_unreg(&rx_ring->xdp_rxq); rx_ring->xdp_prog = NULL; From patchwork Wed Apr 10 04:39:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13623534 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 B6F3D10A11 for ; Wed, 10 Apr 2024 04:39:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712723988; cv=none; b=ZsZafwGWZL8FpZEkCRyHjlKPxawmGel6sNhGNUmILN8wS559O/y8/wBMuOha19023KTwhG1fnLUTpeMNPJeDFDRIS4rJR0CYXhlVdrKJADnQRX7Mk1vh0A1lS3BkwA24TyT4znNJAj/0/ylHyORDezupPvyWFGb4AmJqgCN7zI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712723988; c=relaxed/simple; bh=qADNludrHn0nc/n3sXykDX8DmQnp4rVQ8oPh8FnxDb4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KjOe7LLaeYbrY/A6GQrneiEM8Kk4/zUL38zKgH/kiMN4tQ6gNXB0oCDSHHSBraQtkFSY2Ys4FJYqJAg5sNXu8ZVhGIBLXYUML8KqR+u9+w+Ca2Oa0FgmusLPx5KgMKTqpaSpRD8KtYQb/saKJo5TiluSel9LX/zNU2ovSq84JjE= 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=Z9ymBpcj; arc=none smtp.client-ip=209.85.216.54 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="Z9ymBpcj" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2a526803fccso1818178a91.1 for ; Tue, 09 Apr 2024 21:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1712723986; x=1713328786; 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=i0AdTuh0LPKFRBexJVBgnFt0ViqxZ8bYbsSVukVY5u0=; b=Z9ymBpcjJb5ixTl2KWhRChOFhFvIeAjf1FNJb/fllmPbhalanmUUdBkC1eIcecJtkb jU27Dj7ZoSIOnPy37p/TH8V6+Iwhiwz3qg/OxdYDvEnW+6HaIP0w07TXQ1sEr7jgw3Tu GH+Nm7qUtduX6rIeaJK1Dcxt6b5G6H9apHTC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712723986; x=1713328786; 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=i0AdTuh0LPKFRBexJVBgnFt0ViqxZ8bYbsSVukVY5u0=; b=DMwHvfqNG0ly0a6EeemUheKg8or22cYlZ2wm/m5EFv/74ACQg8y8pjI/zEEEQrXr6L 8n7/HHHf0NUcdZiK7y6fSG74JvS6aVAO4i9p6ux3Ud2aB+JO8zcAc6EkQ2iaoNLh4/Ju /dfdZfpbGqOn7UTabf9wGsNfdT4CeCoRIpyyiRKxxN/jVSaLMS9Y4PeUrRHX+1NFO9an Twxb8L/CjDhp4Qa9Apj0wllYpBOf2vW/d/y5u6bLLfZRIrkUVOBf5or2yOod/9xcXREh wFM2hfHpr8YNLqjcEQxCBDzNgUL7mLoRiatmzij9u+WCV0kXIvZ/Tdgk0EQQme8R4LVr S8AA== X-Forwarded-Encrypted: i=1; AJvYcCXHzK6kwFs+D2GIlvdASHOZex0b99dHgceyDOr5X3tmzxz1TOgzVyZRCCrIBFs3mQcVPHtghcAqVyFyKOzWKm/SCuK+uHal X-Gm-Message-State: AOJu0YxMcYNLGcmu2Tgp3yLbPryWwAAs3rO2kRXXrILDEK4JaCgGJWzV S72QQKoVCYUi73opvwfgZfiTacNRU5VxTdL5izvdPg02BV+NMUbv1Tkct6JmKkY= X-Google-Smtp-Source: AGHT+IHCyg7IsSIZZPCE6CWyUBvBJNPmvz99+2Xq8imlDAOCx7E9BrLRdX6eCg6d+6LVmmu7blclnw== X-Received: by 2002:a17:90a:f690:b0:2a5:74ab:7f52 with SMTP id cl16-20020a17090af69000b002a574ab7f52mr1570409pjb.16.1712723985964; Tue, 09 Apr 2024 21:39:45 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id gn4-20020a17090ac78400b002a5d71d48e8sm260773pjb.39.2024.04.09.21.39.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 21:39:45 -0700 (PDT) From: Joe Damato To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com, nalramli@fastly.com, Joe Damato , Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [intel-next 2/2] net/i40e: add support for per queue netlink stats Date: Wed, 10 Apr 2024 04:39:35 +0000 Message-Id: <20240410043936.206169-3-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240410043936.206169-1-jdamato@fastly.com> References: <20240410043936.206169-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Make i40e compatible with the newly added netlink per queue stats. $ ./cli.py --spec ../../../Documentation/netlink/specs/netdev.yaml \ --dump qstats-get --json '{"scope": "queue"}' [{'ifindex': 3, 'queue-id': 0, 'queue-type': 'rx', 'rx-alloc-fail': 0, 'rx-bytes': 45540208, 'rx-packets': 57112}, {'ifindex': 3, 'queue-id': 1, 'queue-type': 'rx', 'rx-alloc-fail': 0, 'rx-bytes': 8717844, 'rx-packets': 31256}, ... Comparing to ethtool to verify: $ ethtool -S eth3 | egrep 'rx-[01]\.' rx-0.packets: 57112 rx-0.bytes: 45540208 rx-1.packets: 31256 rx-1.bytes: 8717844 Signed-off-by: Joe Damato --- drivers/net/ethernet/intel/i40e/i40e_main.c | 102 ++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 6384a0c73a05..40574f54a380 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -515,6 +516,100 @@ static void i40e_get_netdev_stats_struct(struct net_device *netdev, stats->rx_length_errors = vsi_stats->rx_length_errors; } +static void i40e_get_queue_stats_rx(struct net_device *dev, int i, + struct netdev_queue_stats_rx *stats) +{ + struct i40e_netdev_priv *np = netdev_priv(dev); + struct i40e_vsi *vsi = np->vsi; + struct i40e_ring *ring; + unsigned int start; + + stats->bytes = 0xff; + stats->packets = 0xff; + stats->alloc_fail = 0xff; + + if (test_bit(__I40E_VSI_DOWN, vsi->state)) + return; + + if (!vsi->rx_rings) + return; + + rcu_read_lock(); + ring = READ_ONCE(vsi->rx_rings[i]); + if (ring) { + do { + start = u64_stats_fetch_begin(&ring->syncp); + stats->packets = ring->stats.packets; + stats->bytes = ring->stats.bytes; + stats->alloc_fail = ring->rx_stats.alloc_page_failed; + } while (u64_stats_fetch_retry(&ring->syncp, start)); + } + rcu_read_unlock(); +} + +static void i40e_get_queue_stats_tx(struct net_device *dev, int i, + struct netdev_queue_stats_tx *stats) +{ + struct i40e_netdev_priv *np = netdev_priv(dev); + struct i40e_vsi *vsi = np->vsi; + struct i40e_ring *ring; + unsigned int start; + + stats->bytes = 0xff; + stats->packets = 0xff; + + if (test_bit(__I40E_VSI_DOWN, vsi->state)) + return; + + if (!vsi->tx_rings) + return; + + rcu_read_lock(); + ring = READ_ONCE(vsi->tx_rings[i]); + if (ring) { + do { + start = u64_stats_fetch_begin(&ring->syncp); + stats->packets = ring->stats.packets; + stats->bytes = ring->stats.bytes; + } while (u64_stats_fetch_retry(&ring->syncp, start)); + } + rcu_read_unlock(); +} + +static void i40e_get_base_stats(struct net_device *dev, + struct netdev_queue_stats_rx *rx, + struct netdev_queue_stats_tx *tx) +{ + struct i40e_netdev_priv *np = netdev_priv(dev); + struct rtnl_link_stats64 stats = {0}; + struct i40e_vsi *vsi = np->vsi; + + rx->bytes = 0xff; + rx->packets = 0xff; + rx->alloc_fail = 0xff; + + tx->bytes = 0xff; + tx->packets = 0xff; + + if (test_bit(__I40E_VSI_DOWN, vsi->state)) + return; + + if (!vsi->tx_rings) + return; + + if (!vsi->num_queue_pairs) + return; + + i40e_get_netdev_stats_struct(dev, &stats); + + rx->bytes = stats.rx_bytes; + rx->packets = stats.rx_packets; + rx->alloc_fail = vsi->rx_buf_failed; + + tx->bytes = stats.tx_bytes; + tx->packets = stats.tx_packets; +} + /** * i40e_vsi_reset_stats - Resets all stats of the given vsi * @vsi: the VSI to have its stats reset @@ -13693,6 +13788,12 @@ static const struct net_device_ops i40e_netdev_ops = { .ndo_dfwd_del_station = i40e_fwd_del, }; +static const struct netdev_stat_ops i40e_stat_ops = { + .get_queue_stats_rx = i40e_get_queue_stats_rx, + .get_queue_stats_tx = i40e_get_queue_stats_tx, + .get_base_stats = i40e_get_base_stats, +}; + /** * i40e_config_netdev - Setup the netdev flags * @vsi: the VSI being configured @@ -13854,6 +13955,7 @@ static int i40e_config_netdev(struct i40e_vsi *vsi) /* Setup netdev TC information */ i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); + netdev->stat_ops = &i40e_stat_ops; netdev->netdev_ops = &i40e_netdev_ops; netdev->watchdog_timeo = 5 * HZ; i40e_set_ethtool_ops(netdev);