DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Peng Zhang <peng.zhang@corigine.com>,
	Chaoyong He <chaoyong.he@corigine.com>,
	Long Wu <long.wu@corigine.com>
Subject: [PATCH 11/23] net/nfp: get the VF configuration
Date: Wed, 19 Jun 2024 17:58:18 +0800	[thread overview]
Message-ID: <20240619095830.3479757-12-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240619095830.3479757-1-chaoyong.he@corigine.com>

From: Peng Zhang <peng.zhang@corigine.com>

Add the data field and related logic to get the VF configuration
from firmware and store them.

Signed-off-by: Peng Zhang <peng.zhang@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
---
 drivers/net/nfp/nfp_ethdev.c     | 106 +++++++++++++++++++++++++++++++
 drivers/net/nfp/nfp_net_common.h |   5 ++
 2 files changed, 111 insertions(+)

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 177e5d1e06..e67ff3a0a0 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -10,6 +10,7 @@
 #include <eal_firmware.h>
 #include <rte_alarm.h>
 #include <rte_kvargs.h>
+#include <rte_pci.h>
 
 #include "flower/nfp_flower.h"
 #include "nfd3/nfp_nfd3.h"
@@ -1858,6 +1859,103 @@ nfp_fw_app_primary_init(struct nfp_net_hw_priv *hw_priv)
 	return 0;
 }
 
+static int
+nfp_pf_get_max_vf(struct nfp_pf_dev *pf_dev)
+{
+	int ret;
+	uint32_t max_vfs;
+
+	max_vfs = nfp_rtsym_read_le(pf_dev->sym_tbl, "nfd_vf_cfg_max_vfs", &ret);
+	if (ret != 0)
+		return ret;
+
+	pf_dev->max_vfs = max_vfs;
+
+	return 0;
+}
+
+static int
+nfp_pf_get_sriov_vf(struct nfp_pf_dev *pf_dev,
+		const struct nfp_dev_info *dev_info)
+{
+	int ret;
+	off_t pos;
+	uint16_t offset;
+	uint16_t sriov_vf;
+
+	/* For 3800 single-PF and 4000 card */
+	if (!pf_dev->multi_pf.enabled) {
+		pf_dev->sriov_vf = pf_dev->max_vfs;
+		return 0;
+	}
+
+	pos = rte_pci_find_ext_capability(pf_dev->pci_dev, RTE_PCI_EXT_CAP_ID_SRIOV);
+	if (pos == 0) {
+		PMD_INIT_LOG(ERR, "Can not get the pci sriov cap");
+		return -EIO;
+	}
+
+	/*
+	 * Management firmware ensures that sriov capability registers
+	 * are initialized correctly.
+	 */
+	ret = rte_pci_read_config(pf_dev->pci_dev, &sriov_vf, sizeof(sriov_vf),
+			pos + RTE_PCI_SRIOV_TOTAL_VF);
+	if (ret < 0) {
+		PMD_INIT_LOG(ERR, "Can not read the sriov toatl VF");
+		return -EIO;
+	}
+
+	/* Offset of first VF is relative to its PF. */
+	ret = rte_pci_read_config(pf_dev->pci_dev, &offset, sizeof(offset),
+			pos + RTE_PCI_SRIOV_VF_OFFSET);
+	if (ret < 0) {
+		PMD_INIT_LOG(ERR, "Can not get the VF offset");
+		return -EIO;
+	}
+
+	offset += pf_dev->multi_pf.function_id;
+	if (offset < dev_info->pf_num_per_unit)
+		return -ERANGE;
+
+	offset -= dev_info->pf_num_per_unit;
+	if (offset >= pf_dev->max_vfs || offset + sriov_vf > pf_dev->max_vfs) {
+		PMD_INIT_LOG(ERR, "The pci allocate VF is more than the MAX VF");
+		return -ERANGE;
+	}
+
+	pf_dev->sriov_vf = sriov_vf;
+
+	return 0;
+}
+
+static int
+nfp_net_get_vf_info(struct nfp_pf_dev *pf_dev,
+		const struct nfp_dev_info *dev_info)
+{
+	int ret;
+
+	ret = nfp_pf_get_max_vf(pf_dev);
+	if (ret != 0) {
+		if (ret != -ENOENT) {
+			PMD_INIT_LOG(ERR, "Read max VFs failed");
+			return ret;
+		}
+
+		PMD_INIT_LOG(WARNING, "The firmware can not support read max VFs");
+		return 0;
+	}
+
+	if (pf_dev->max_vfs == 0)
+		return 0;
+
+	ret = nfp_pf_get_sriov_vf(pf_dev, dev_info);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 static int
 nfp_pf_init(struct rte_pci_device *pci_dev)
 {
@@ -2020,6 +2118,14 @@ nfp_pf_init(struct rte_pci_device *pci_dev)
 		goto sym_tbl_cleanup;
 	}
 
+	/* Get the VF info */
+	ret = nfp_net_get_vf_info(pf_dev, dev_info);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "Failed to get VF info.");
+		ret = -EIO;
+		goto sym_tbl_cleanup;
+	}
+
 	/* Configure access to tx/rx vNIC BARs */
 	addr = nfp_qcp_queue_offset(dev_info, 0);
 	cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0);
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index 5c48b94d38..7efd0161af 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -141,6 +141,11 @@ struct nfp_pf_dev {
 	/** NFP devarg param */
 	struct nfp_devargs devargs;
 
+	/** Number of VFs supported by firmware shared by all PFs */
+	uint16_t max_vfs;
+	/** Number of VFs supported by firmware for this PF */
+	uint16_t sriov_vf;
+
 	uint8_t total_phyports;
 };
 
-- 
2.39.1


  parent reply	other threads:[~2024-06-19 10:00 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19  9:58 [PATCH 00/23] support flower firmware with multiple PF Chaoyong He
2024-06-19  9:58 ` [PATCH 01/23] net/nfp: fix dereference of null pointer Chaoyong He
2024-07-07 18:56   ` Ferruh Yigit
2024-07-08  1:35     ` Chaoyong He
2024-06-19  9:58 ` [PATCH 02/23] net/nfp: disable ctrl VNIC queues Chaoyong He
2024-06-19  9:58 ` [PATCH 03/23] net/nfp: fix dereference of null pointer Chaoyong He
2024-06-19  9:58 ` [PATCH 04/23] net/nfp: fix repeat disable the port Chaoyong He
2024-06-19  9:58 ` [PATCH 05/23] net/nfp: fix repeat set the speed configure Chaoyong He
2024-06-19  9:58 ` [PATCH 06/23] net/nfp: make the logic simpler by adding local variable Chaoyong He
2024-06-19  9:58 ` [PATCH 07/23] net/nfp: rename the variable name Chaoyong He
2024-06-19  9:58 ` [PATCH 08/23] net/nfp: export function ID get interface Chaoyong He
2024-06-19  9:58 ` [PATCH 09/23] net/nfp: extract total phyports Chaoyong He
2024-06-19  9:58 ` [PATCH 10/23] net/nfp: extract the initialize helper function Chaoyong He
2024-06-19  9:58 ` Chaoyong He [this message]
2024-06-19  9:58 ` [PATCH 12/23] net/nfp: refactor the logic of flower service Chaoyong He
2024-06-19  9:58 ` [PATCH 13/23] net/nfp: get the first VF ID of the PF Chaoyong He
2024-06-19  9:58 ` [PATCH 14/23] net/nfp: add the helper function to map rtsym with offset Chaoyong He
2024-06-19  9:58 ` [PATCH 15/23] net/nfp: add the VF table to record the VF information Chaoyong He
2024-06-19  9:58 ` [PATCH 16/23] net/nfp: support configuration of VF numbers Chaoyong He
2024-06-19  9:58 ` [PATCH 17/23] net/nfp: configure the VF queue Chaoyong He
2024-06-19  9:58 ` [PATCH 18/23] net/nfp: add check for numbers of VF representor port Chaoyong He
2024-06-19  9:58 ` [PATCH 19/23] net/nfp: add support of ring pop and push Chaoyong He
2024-06-19  9:58 ` [PATCH 20/23] net/nfp: add resource share mode of host context Chaoyong He
2024-06-19  9:58 ` [PATCH 21/23] net/nfp: add resource share mode of mask ID Chaoyong He
2024-06-19  9:58 ` [PATCH 22/23] net/nfp: add device active command for nsp service Chaoyong He
2024-06-19  9:58 ` [PATCH 23/23] net/nfp: add support of flower firmware with multiple PF Chaoyong He
2024-07-07 18:56 ` [PATCH 00/23] support " Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240619095830.3479757-12-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=long.wu@corigine.com \
    --cc=oss-drivers@corigine.com \
    --cc=peng.zhang@corigine.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).