[PATCH 15/23] net/nfp: add the VF table to record the VF information

Chaoyong He chaoyong.he at corigine.com
Wed Jun 19 11:58:22 CEST 2024


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

In multiple PF case, different VF of different PF has
different VF configure, so need add the VF table to record
the VF information.

Signed-off-by: Peng Zhang <peng.zhang at corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he at corigine.com>
Reviewed-by: Long Wu <long.wu at corigine.com>
---
 drivers/common/nfp/nfp_common_ctrl.h |  8 ++++
 drivers/net/nfp/nfp_ethdev.c         | 64 +++++++++++++++++++++++++++-
 drivers/net/nfp/nfp_net_common.h     |  9 ++++
 3 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/drivers/common/nfp/nfp_common_ctrl.h b/drivers/common/nfp/nfp_common_ctrl.h
index 6badf769fc..e108720ff6 100644
--- a/drivers/common/nfp/nfp_common_ctrl.h
+++ b/drivers/common/nfp/nfp_common_ctrl.h
@@ -13,6 +13,14 @@
  */
 #define NFP_NET_CFG_BAR_SZ              (32 * 1024)
 
+/*
+ * Configuration sriov VF.
+ * The configuration memory begins with a mailbox region for communication with
+ * the firmware followed by individual VF entries.
+ */
+#define NFP_NET_VF_CFG_SZ               16
+#define NFP_NET_VF_CFG_MB_SZ            16
+
 /*
  * @NFP_NET_TXR_MAX:         Maximum number of TX rings
  * @NFP_NET_TXR_MASK:        Mask for TX rings
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 482d23eb5c..dc3890ef53 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -633,6 +633,16 @@ nfp_uninit_app_fw_nic(struct nfp_pf_dev *pf_dev)
 	rte_free(pf_dev->app_fw_priv);
 }
 
+static void
+nfp_net_vf_config_uninit(struct nfp_pf_dev *pf_dev)
+{
+	if (pf_dev->sriov_vf == 0)
+		return;
+
+	nfp_cpp_area_release_free(pf_dev->vf_cfg_tbl_area);
+	nfp_cpp_area_release_free(pf_dev->vf_area);
+}
+
 void
 nfp_pf_uninit(struct nfp_net_hw_priv *hw_priv)
 {
@@ -640,6 +650,7 @@ nfp_pf_uninit(struct nfp_net_hw_priv *hw_priv)
 
 	if (pf_dev->devargs.cpp_service_enable)
 		nfp_disable_cpp_service(pf_dev);
+	nfp_net_vf_config_uninit(pf_dev);
 	nfp_cpp_area_release_free(pf_dev->mac_stats_area);
 	nfp_cpp_area_release_free(pf_dev->qc_area);
 	free(pf_dev->sym_tbl);
@@ -1957,6 +1968,47 @@ nfp_net_get_vf_info(struct nfp_pf_dev *pf_dev,
 	return 0;
 }
 
+static int
+nfp_net_vf_config_init(struct nfp_pf_dev *pf_dev)
+{
+	int ret = 0;
+	uint32_t min_size;
+	char vf_bar_name[RTE_ETH_NAME_MAX_LEN];
+	char vf_cfg_name[RTE_ETH_NAME_MAX_LEN];
+
+	if (pf_dev->sriov_vf == 0)
+		return 0;
+
+	min_size = NFP_NET_CFG_BAR_SZ * pf_dev->sriov_vf;
+	snprintf(vf_bar_name, sizeof(vf_bar_name), "_pf%d_net_vf_bar",
+			pf_dev->multi_pf.function_id);
+	pf_dev->vf_bar = nfp_rtsym_map_offset(pf_dev->sym_tbl, vf_bar_name,
+			NFP_NET_CFG_BAR_SZ * pf_dev->vf_base_id,
+			min_size, &pf_dev->vf_area);
+	if (pf_dev->vf_bar == NULL) {
+		PMD_INIT_LOG(ERR, "Failed to get vf cfg.");
+		return -EIO;
+	}
+
+	min_size = NFP_NET_VF_CFG_SZ * pf_dev->sriov_vf + NFP_NET_VF_CFG_MB_SZ;
+	snprintf(vf_cfg_name, sizeof(vf_cfg_name), "_pf%d_net_vf_cfg2",
+			pf_dev->multi_pf.function_id);
+	pf_dev->vf_cfg_tbl_bar = nfp_rtsym_map(pf_dev->sym_tbl, vf_cfg_name,
+			min_size, &pf_dev->vf_cfg_tbl_area);
+	if (pf_dev->vf_cfg_tbl_bar == NULL) {
+		PMD_INIT_LOG(ERR, "Failed to get vf configure table.");
+		ret = -EIO;
+		goto vf_bar_cleanup;
+	}
+
+	return 0;
+
+vf_bar_cleanup:
+	nfp_cpp_area_release_free(pf_dev->vf_area);
+
+	return ret;
+}
+
 static int
 nfp_pf_init(struct rte_pci_device *pci_dev)
 {
@@ -2149,6 +2201,12 @@ nfp_pf_init(struct rte_pci_device *pci_dev)
 		goto hwqueues_cleanup;
 	}
 
+	ret = nfp_net_vf_config_init(pf_dev);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "Failed to init VF config.");
+		goto mac_stats_cleanup;
+	}
+
 	hw_priv->pf_dev = pf_dev;
 	hw_priv->dev_info = dev_info;
 
@@ -2159,7 +2217,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev)
 	ret = nfp_fw_app_primary_init(hw_priv);
 	if (ret != 0) {
 		PMD_INIT_LOG(ERR, "Failed to init hw app primary.");
-		goto mac_stats_cleanup;
+		goto vf_cfg_tbl_cleanup;
 	}
 
 	/* Register the CPP bridge service here for primary use */
@@ -2167,12 +2225,14 @@ nfp_pf_init(struct rte_pci_device *pci_dev)
 		ret = nfp_enable_cpp_service(pf_dev);
 		if (ret != 0) {
 			PMD_INIT_LOG(ERR, "Enable CPP service failed.");
-			goto hwqueues_cleanup;
+			goto vf_cfg_tbl_cleanup;
 		}
 	}
 
 	return 0;
 
+vf_cfg_tbl_cleanup:
+	nfp_net_vf_config_uninit(pf_dev);
 mac_stats_cleanup:
 	nfp_cpp_area_release_free(pf_dev->mac_stats_area);
 hwqueues_cleanup:
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index d3c70a21d4..c4d469599f 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -117,6 +117,15 @@ struct nfp_pf_dev {
 	struct nfp_cpp_area *ctrl_area;
 	struct nfp_cpp_area *qc_area;
 
+	/** Pointer to the CPP area for the VF configuration BAR */
+	struct nfp_cpp_area *vf_area;
+	/** Pointer to mapped VF configuration area */
+	uint8_t *vf_bar;
+	/** Pointer to the CPP area for the VF config table */
+	struct nfp_cpp_area *vf_cfg_tbl_area;
+	/** Pointer to mapped VF config table */
+	uint8_t *vf_cfg_tbl_bar;
+
 	uint8_t *qc_bar;
 
 	struct nfp_cpp_area *mac_stats_area;
-- 
2.39.1



More information about the dev mailing list