[1/2] net/nfp: refactor the firmware load logic

Message ID 20240528012933.2345436-2-chaoyong.he@corigine.com (mailing list archive)
State Accepted
Delegated to: Ferruh Yigit
Headers
Series support new firmware name scheme |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He May 28, 2024, 1:29 a.m. UTC
  Refactor the firmware load logic, make it more specific and clear.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/nfp_ethdev.c | 66 ++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 37 deletions(-)
  

Patch

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index cdc946faff..771137db92 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -1081,16 +1081,18 @@  nfp_net_init(struct rte_eth_dev *eth_dev,
 
 static int
 nfp_fw_get_name(struct rte_pci_device *dev,
-		struct nfp_nsp *nsp,
-		char *card,
+		struct nfp_cpp *cpp,
+		struct nfp_eth_table *nfp_eth_table,
+		struct nfp_hwinfo *hwinfo,
 		char *fw_name,
 		size_t fw_size)
 {
 	char serial[40];
 	uint16_t interface;
+	char card_desc[100];
 	uint32_t cpp_serial_len;
+	const char *nfp_fw_model;
 	const uint8_t *cpp_serial;
-	struct nfp_cpp *cpp = nfp_nsp_cpp(nsp);
 
 	cpp_serial_len = nfp_cpp_serial(cpp, &cpp_serial);
 	if (cpp_serial_len != NFP_SERIAL_LEN)
@@ -1119,8 +1121,20 @@  nfp_fw_get_name(struct rte_pci_device *dev,
 	if (access(fw_name, F_OK) == 0)
 		return 0;
 
+	nfp_fw_model = nfp_hwinfo_lookup(hwinfo, "nffw.partno");
+	if (nfp_fw_model == NULL) {
+		nfp_fw_model = nfp_hwinfo_lookup(hwinfo, "assembly.partno");
+		if (nfp_fw_model == NULL) {
+			PMD_DRV_LOG(ERR, "firmware model NOT found");
+			return -EIO;
+		}
+	}
+
 	/* Finally try the card type and media */
-	snprintf(fw_name, fw_size, "%s/%s", DEFAULT_FW_PATH, card);
+	snprintf(card_desc, sizeof(card_desc), "nic_%s_%dx%d.nffw",
+			nfp_fw_model, nfp_eth_table->count,
+			nfp_eth_table->ports[0].speed / 1000);
+	snprintf(fw_name, fw_size, "%s/%s", DEFAULT_FW_PATH, card_desc);
 	PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
 	if (access(fw_name, F_OK) == 0)
 		return 0;
@@ -1364,49 +1378,20 @@  nfp_fw_setup(struct rte_pci_device *dev,
 {
 	int err;
 	char fw_name[125];
-	char card_desc[100];
 	struct nfp_nsp *nsp;
-	const char *nfp_fw_model;
-
-	nfp_fw_model = nfp_hwinfo_lookup(hwinfo, "nffw.partno");
-	if (nfp_fw_model == NULL)
-		nfp_fw_model = nfp_hwinfo_lookup(hwinfo, "assembly.partno");
-
-	if (nfp_fw_model != NULL) {
-		PMD_DRV_LOG(INFO, "firmware model found: %s", nfp_fw_model);
-	} else {
-		PMD_DRV_LOG(ERR, "firmware model NOT found");
-		return -EIO;
-	}
 
-	if (nfp_eth_table->count == 0 || nfp_eth_table->count > 8) {
-		PMD_DRV_LOG(ERR, "NFP ethernet table reports wrong ports: %u",
-				nfp_eth_table->count);
-		return -EIO;
+	err = nfp_fw_get_name(dev, cpp, nfp_eth_table, hwinfo, fw_name, sizeof(fw_name));
+	if (err != 0) {
+		PMD_DRV_LOG(ERR, "Can't find suitable firmware.");
+		return err;
 	}
 
-	PMD_DRV_LOG(INFO, "NFP ethernet port table reports %u ports",
-			nfp_eth_table->count);
-
-	PMD_DRV_LOG(INFO, "Port speed: %u", nfp_eth_table->ports[0].speed);
-
-	snprintf(card_desc, sizeof(card_desc), "nic_%s_%dx%d.nffw",
-			nfp_fw_model, nfp_eth_table->count,
-			nfp_eth_table->ports[0].speed / 1000);
-
 	nsp = nfp_nsp_open(cpp);
 	if (nsp == NULL) {
 		PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle");
 		return -EIO;
 	}
 
-	err = nfp_fw_get_name(dev, nsp, card_desc, fw_name, sizeof(fw_name));
-	if (err != 0) {
-		PMD_DRV_LOG(ERR, "Can't find suitable firmware.");
-		nfp_nsp_close(nsp);
-		return err;
-	}
-
 	if (multi_pf->enabled)
 		err = nfp_fw_reload_for_multi_pf(nsp, fw_name, cpp, dev_info, multi_pf,
 				force_reload_fw);
@@ -1853,6 +1838,13 @@  nfp_pf_init(struct rte_pci_device *pci_dev)
 		goto hwinfo_cleanup;
 	}
 
+	if (nfp_eth_table->count == 0 || nfp_eth_table->count > 8) {
+		PMD_INIT_LOG(ERR, "NFP ethernet table reports wrong ports: %u",
+				nfp_eth_table->count);
+		ret = -EIO;
+		goto eth_table_cleanup;
+	}
+
 	pf_dev->multi_pf.enabled = nfp_check_multi_pf_from_nsp(pci_dev, cpp);
 	pf_dev->multi_pf.function_id = function_id;