[v2,6/8] net/nfp: unify CPP acquire method

Message ID 20240419052349.1294696-7-chaoyong.he@corigine.com (mailing list archive)
State Accepted
Delegated to: Ferruh Yigit
Headers
Series [v2,1/8] net/nfp: fix resource leak of secondary process |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He April 19, 2024, 5:23 a.m. UTC
  Getting CPP from 'struct nfp_net_hw' is not right in multiple process
user case. Modify the data structure and related logic to get it from
process private data structure.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Signed-off-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/flower/nfp_flower.c           |  4 ---
 .../net/nfp/flower/nfp_flower_representor.c   |  2 +-
 drivers/net/nfp/nfp_ethdev.c                  | 31 +++-------------
 drivers/net/nfp/nfp_net_common.c              | 36 ++++++++-----------
 drivers/net/nfp/nfp_net_common.h              |  3 +-
 5 files changed, 22 insertions(+), 54 deletions(-)
  

Patch

diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c
index 80874e23de..83249feedb 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -707,7 +707,6 @@  nfp_init_app_fw_flower(struct nfp_net_hw_priv *hw_priv)
 	/* Fill in the PF vNIC and populate app struct */
 	app_fw_flower->pf_hw = pf_hw;
 	pf_hw->super.ctrl_bar = pf_dev->ctrl_bar;
-	pf_hw->cpp = pf_dev->cpp;
 
 	ret = nfp_flower_init_vnic_common(hw_priv, pf_hw, "pf_vnic");
 	if (ret != 0) {
@@ -730,9 +729,6 @@  nfp_init_app_fw_flower(struct nfp_net_hw_priv *hw_priv)
 		goto pf_cpp_area_cleanup;
 	}
 
-	/* Now populate the ctrl vNIC */
-	ctrl_hw->cpp = pf_dev->cpp;
-
 	ret = nfp_flower_init_ctrl_vnic(app_fw_flower, hw_priv);
 	if (ret != 0) {
 		PMD_INIT_LOG(ERR, "Could not initialize flower ctrl vNIC");
diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index 934f078dca..0e19723f57 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -826,7 +826,7 @@  nfp_flower_repr_alloc(struct nfp_app_fw_flower *app_fw_flower,
 	 */
 	for (i = 0; i < app_fw_flower->num_vf_reprs; i++) {
 		flower_repr.repr_type = NFP_REPR_TYPE_VF;
-		flower_repr.port_id = nfp_get_pcie_port_id(app_fw_flower->pf_hw->cpp,
+		flower_repr.port_id = nfp_get_pcie_port_id(hw_priv->pf_dev->cpp,
 				NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF, i, 0);
 		flower_repr.nfp_idx = 0;
 		flower_repr.vf_id = i;
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 38fe153ab4..258b617eb2 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -224,7 +224,7 @@  nfp_net_speed_configure(struct rte_eth_dev *dev)
 		}
 	}
 
-	nsp = nfp_eth_config_start(net_hw->cpp, eth_port->index);
+	nsp = nfp_eth_config_start(hw_priv->pf_dev->cpp, eth_port->index);
 	if (nsp == NULL) {
 		PMD_DRV_LOG(ERR, "Couldn't get NSP.");
 		return -EIO;
@@ -267,7 +267,6 @@  nfp_net_start(struct rte_eth_dev *dev)
 	uint16_t i;
 	struct nfp_hw *hw;
 	uint32_t new_ctrl;
-	struct nfp_cpp *cpp;
 	uint32_t update = 0;
 	uint32_t cap_extend;
 	uint32_t intr_vector;
@@ -402,13 +401,8 @@  nfp_net_start(struct rte_eth_dev *dev)
 		goto error;
 	}
 
-	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-		cpp = net_hw->cpp;
-	else
-		cpp = pf_dev->cpp;
-
 	/* Configure the physical port up */
-	nfp_eth_set_configured(cpp, net_hw->nfp_idx, 1);
+	nfp_eth_set_configured(pf_dev->cpp, net_hw->nfp_idx, 1);
 
 	for (i = 0; i < dev->data->nb_rx_queues; i++)
 		dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
@@ -440,38 +434,26 @@  nfp_net_start(struct rte_eth_dev *dev)
 static int
 nfp_net_set_link_up(struct rte_eth_dev *dev)
 {
-	struct nfp_cpp *cpp;
 	struct nfp_net_hw *hw;
 	struct nfp_net_hw_priv *hw_priv;
 
 	hw = dev->data->dev_private;
 	hw_priv = dev->process_private;
 
-	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-		cpp = hw->cpp;
-	else
-		cpp = hw_priv->pf_dev->cpp;
-
-	return nfp_eth_set_configured(cpp, hw->nfp_idx, 1);
+	return nfp_eth_set_configured(hw_priv->pf_dev->cpp, hw->nfp_idx, 1);
 }
 
 /* Set the link down. */
 static int
 nfp_net_set_link_down(struct rte_eth_dev *dev)
 {
-	struct nfp_cpp *cpp;
 	struct nfp_net_hw *hw;
 	struct nfp_net_hw_priv *hw_priv;
 
 	hw = dev->data->dev_private;
 	hw_priv = dev->process_private;
 
-	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-		cpp = hw->cpp;
-	else
-		cpp = hw_priv->pf_dev->cpp;
-
-	return nfp_eth_set_configured(cpp, hw->nfp_idx, 0);
+	return nfp_eth_set_configured(hw_priv->pf_dev->cpp, hw->nfp_idx, 0);
 }
 
 static uint8_t
@@ -1178,7 +1160,6 @@  nfp_fw_check_change(struct nfp_cpp *cpp,
 		bool *fw_changed)
 {
 	int ret;
-	struct nfp_net_hw hw;
 	uint32_t new_version = 0;
 	uint32_t old_version = 0;
 
@@ -1186,8 +1167,7 @@  nfp_fw_check_change(struct nfp_cpp *cpp,
 	if (ret != 0)
 		return ret;
 
-	hw.cpp = cpp;
-	nfp_net_get_fw_version(&hw, &old_version);
+	nfp_net_get_fw_version(cpp, &old_version);
 
 	if (new_version != old_version) {
 		PMD_DRV_LOG(INFO, "FW version is changed, new %u, old %u",
@@ -1600,7 +1580,6 @@  nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
 		/* Add this device to the PF's array of physical ports */
 		app_fw_nic->ports[id] = hw;
 
-		hw->cpp = pf_dev->cpp;
 		hw->eth_dev = eth_dev;
 		hw->idx = id;
 		hw->nfp_idx = nfp_eth_table->ports[id].index;
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 8cc8b77318..7541afa235 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -695,7 +695,7 @@  nfp_net_speed_aneg_update(struct rte_eth_dev *dev,
 
 	/* Compare whether the current status has changed. */
 	if (dev->data->dev_link.link_status != link->link_status) {
-		nfp_eth_table = nfp_eth_read_ports(hw->cpp);
+		nfp_eth_table = nfp_eth_read_ports(hw_priv->pf_dev->cpp);
 		if (nfp_eth_table == NULL) {
 			PMD_DRV_LOG(DEBUG, "Error reading NFP ethernet table.");
 			return -EIO;
@@ -2094,12 +2094,12 @@  nfp_net_cfg_read_version(struct nfp_net_hw *hw)
 }
 
 static void
-nfp_net_get_nsp_info(struct nfp_net_hw *hw,
+nfp_net_get_nsp_info(struct nfp_net_hw_priv *hw_priv,
 		char *nsp_version)
 {
 	struct nfp_nsp *nsp;
 
-	nsp = nfp_nsp_open(hw->cpp);
+	nsp = nfp_nsp_open(hw_priv->pf_dev->cpp);
 	if (nsp == NULL)
 		return;
 
@@ -2111,12 +2111,12 @@  nfp_net_get_nsp_info(struct nfp_net_hw *hw,
 }
 
 void
-nfp_net_get_fw_version(struct nfp_net_hw *hw,
+nfp_net_get_fw_version(struct nfp_cpp *cpp,
 		uint32_t *mip_version)
 {
 	struct nfp_mip *mip;
 
-	mip = nfp_mip_open(hw->cpp);
+	mip = nfp_mip_open(cpp);
 	if (mip == NULL) {
 		*mip_version = 0;
 		return;
@@ -2128,12 +2128,12 @@  nfp_net_get_fw_version(struct nfp_net_hw *hw,
 }
 
 static void
-nfp_net_get_mip_name(struct nfp_net_hw *hw,
+nfp_net_get_mip_name(struct nfp_net_hw_priv *hw_priv,
 		char *mip_name)
 {
 	struct nfp_mip *mip;
 
-	mip = nfp_mip_open(hw->cpp);
+	mip = nfp_mip_open(hw_priv->pf_dev->cpp);
 	if (mip == NULL)
 		return;
 
@@ -2185,8 +2185,8 @@  nfp_net_firmware_version_get(struct rte_eth_dev *dev,
 		snprintf(vnic_version, FW_VER_LEN, "*");
 	}
 
-	nfp_net_get_nsp_info(hw, nsp_version);
-	nfp_net_get_mip_name(hw, mip_name);
+	nfp_net_get_nsp_info(hw_priv, nsp_version);
+	nfp_net_get_mip_name(hw_priv, mip_name);
 	nfp_net_get_app_name(hw_priv, app_name);
 
 	snprintf(fw_version, FW_VER_LEN, "%s %s %s %s",
@@ -2220,7 +2220,6 @@  nfp_net_is_valid_nfd_version(struct nfp_net_fw_ver version)
 int
 nfp_net_stop(struct rte_eth_dev *dev)
 {
-	struct nfp_cpp *cpp;
 	struct nfp_net_hw *hw;
 	struct nfp_net_hw_priv *hw_priv;
 
@@ -2233,12 +2232,7 @@  nfp_net_stop(struct rte_eth_dev *dev)
 	nfp_net_stop_tx_queue(dev);
 	nfp_net_stop_rx_queue(dev);
 
-	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-		cpp = hw->cpp;
-	else
-		cpp = hw_priv->pf_dev->cpp;
-
-	nfp_eth_set_configured(cpp, hw->nfp_idx, 0);
+	nfp_eth_set_configured(hw_priv->pf_dev->cpp, hw->nfp_idx, 0);
 
 	return 0;
 }
@@ -2285,7 +2279,7 @@  nfp_net_flow_ctrl_get(struct rte_eth_dev *dev,
 }
 
 static int
-nfp_net_pause_frame_set(struct nfp_net_hw *net_hw,
+nfp_net_pause_frame_set(struct nfp_net_hw_priv *hw_priv,
 		struct nfp_eth_table_port *eth_port,
 		enum rte_eth_fc_mode mode)
 {
@@ -2293,7 +2287,7 @@  nfp_net_pause_frame_set(struct nfp_net_hw *net_hw,
 	bool flag;
 	struct nfp_nsp *nsp;
 
-	nsp = nfp_eth_config_start(net_hw->cpp, eth_port->index);
+	nsp = nfp_eth_config_start(hw_priv->pf_dev->cpp, eth_port->index);
 	if (nsp == NULL) {
 		PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle.");
 		return -EIO;
@@ -2350,7 +2344,7 @@  nfp_net_flow_ctrl_set(struct rte_eth_dev *dev,
 	if (set_mode == original_mode)
 		return 0;
 
-	ret = nfp_net_pause_frame_set(net_hw, eth_port, set_mode);
+	ret = nfp_net_pause_frame_set(hw_priv, eth_port, set_mode);
 	if (ret != 0)
 		return ret;
 
@@ -2438,7 +2432,7 @@  nfp_net_fec_get(struct rte_eth_dev *dev,
 		return -EINVAL;
 
 	if (dev->data->dev_link.link_status == RTE_ETH_LINK_DOWN) {
-		nfp_eth_table = nfp_eth_read_ports(hw->cpp);
+		nfp_eth_table = nfp_eth_read_ports(hw_priv->pf_dev->cpp);
 		hw_priv->pf_dev->nfp_eth_table->ports[hw->idx] = nfp_eth_table->ports[hw->idx];
 		free(nfp_eth_table);
 	}
@@ -2520,5 +2514,5 @@  nfp_net_fec_set(struct rte_eth_dev *dev,
 		return -EIO;
 	}
 
-	return nfp_eth_set_fec(hw->cpp, eth_port->index, fec);
+	return nfp_eth_set_fec(hw_priv->pf_dev->cpp, eth_port->index, fec);
 }
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index 31deeb43ce..40f314af0a 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -201,7 +201,6 @@  struct nfp_net_hw {
 	struct rte_eth_stats eth_stats_base;
 	struct rte_eth_xstat *eth_xstats_base;
 
-	struct nfp_cpp *cpp;
 	struct nfp_cpp_area *ctrl_area;
 	struct nfp_cpp_area *mac_stats_area;
 	uint8_t *mac_stats_bar;
@@ -322,7 +321,7 @@  int nfp_net_fec_get(struct rte_eth_dev *dev,
 		uint32_t *fec_capa);
 int nfp_net_fec_set(struct rte_eth_dev *dev,
 		uint32_t fec_capa);
-void nfp_net_get_fw_version(struct nfp_net_hw *hw,
+void nfp_net_get_fw_version(struct nfp_cpp *cpp,
 		uint32_t *fw_version);
 int nfp_net_txrwb_alloc(struct rte_eth_dev *eth_dev);
 void nfp_net_txrwb_free(struct rte_eth_dev *eth_dev);