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 7/8] net/nfp: reload the firmware only when firmware changed
Date: Mon, 15 Jan 2024 10:54:18 +0800	[thread overview]
Message-ID: <20240115025419.2447759-8-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240115025419.2447759-1-chaoyong.he@corigine.com>

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

Add the interfaces of getting firmware build time from BSP
and ELF file, only reloading the firmware when the build
time is different, which means the firmware has changed.

This will accelerate the average startup time for both
multi-PF and single-PF firmware.

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     | 86 ++++++++++++++++++++++++++++----
 drivers/net/nfp/nfp_net_common.c | 17 +++++++
 drivers/net/nfp/nfp_net_common.h |  2 +
 3 files changed, 94 insertions(+), 11 deletions(-)

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 46bb09a211..22edf11253 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -19,6 +19,7 @@
 #include "nfpcore/nfp_nsp.h"
 #include "nfpcore/nfp6000_pcie.h"
 #include "nfpcore/nfp_resource.h"
+#include "nfpcore/nfp_elf.h"
 
 #include "nfp_cpp_bridge.h"
 #include "nfp_ipsec.h"
@@ -1067,6 +1068,36 @@ nfp_fw_unload(struct nfp_cpp *cpp)
 	nfp_nsp_close(nsp);
 }
 
+/* 0 is firmware not change, 1 is firmware changed, < 0 has error */
+static int
+nfp_fw_check_change(struct nfp_cpp *cpp,
+		char *fw_name,
+		bool *fw_changed)
+{
+	int ret;
+	struct nfp_net_hw hw;
+	uint32_t new_buildtime = 0;
+	uint32_t old_buildtime = 0;
+
+	ret = nfp_elf_get_fw_buildtime(&new_buildtime, fw_name);
+	if (ret < 0)
+		return ret;
+
+	hw.cpp = cpp;
+	nfp_net_get_fw_buildtime(&hw, &old_buildtime);
+	if (new_buildtime != old_buildtime) {
+		PMD_DRV_LOG(INFO, "FW version is changed, new %u, old %u",
+				new_buildtime, old_buildtime);
+		*fw_changed = true;
+	} else {
+		PMD_DRV_LOG(INFO, "FW version is not changed, build_time is %u.",
+				new_buildtime);
+		*fw_changed = false;
+	}
+
+	return 0;
+}
+
 static int
 nfp_fw_reload(struct nfp_nsp *nsp,
 		char *fw_name)
@@ -1132,15 +1163,39 @@ nfp_fw_skip_load(const struct nfp_dev_info *dev_info,
 
 	return false;
 }
+static int
+nfp_fw_reload_for_single_pf(struct nfp_nsp *nsp,
+		char *fw_name,
+		struct nfp_cpp *cpp)
+{
+	int err;
+	bool fw_changed = true;
+
+	if (nfp_nsp_fw_loaded(nsp)) {
+		err = nfp_fw_check_change(cpp, fw_name, &fw_changed);
+		if (err < 0)
+			return err;
+	}
+
+	if (!fw_changed)
+		return 0;
+
+	err = nfp_fw_reload(nsp, fw_name);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
 
 static int
-nfp_fw_reload_for_multipf(struct nfp_nsp *nsp,
+nfp_fw_reload_for_multi_pf(struct nfp_nsp *nsp,
 		char *fw_name,
 		struct nfp_cpp *cpp,
 		const struct nfp_dev_info *dev_info,
 		struct nfp_multi_pf *multi_pf)
 {
 	int err;
+	bool fw_changed = true;
 	bool skip_load_fw = false;
 
 	err = nfp_net_keepalive_init(cpp, multi_pf);
@@ -1151,27 +1206,36 @@ nfp_fw_reload_for_multipf(struct nfp_nsp *nsp,
 
 	err = nfp_net_keepalive_start(multi_pf);
 	if (err != 0) {
-		nfp_net_keepalive_uninit(multi_pf);
 		PMD_DRV_LOG(ERR, "NFP write beat failed");
-		return err;
+		goto keepalive_uninit;
 	}
 
-	if (nfp_nsp_fw_loaded(nsp))
+	if (nfp_nsp_fw_loaded(nsp)) {
+		err = nfp_fw_check_change(cpp, fw_name, &fw_changed);
+		if (err < 0)
+			goto keepalive_stop;
+	}
+
+	if (!fw_changed)
 		skip_load_fw = nfp_fw_skip_load(dev_info, multi_pf);
 
 	if (skip_load_fw)
 		return 0;
 
 	err = nfp_fw_reload(nsp, fw_name);
-	if (err != 0) {
-		nfp_net_keepalive_stop(multi_pf);
-		nfp_net_keepalive_uninit(multi_pf);
-		return err;
-	}
+	if (err != 0)
+		goto keepalive_stop;
 
 	nfp_net_keepalive_clear_others(dev_info, multi_pf);
 
 	return 0;
+
+keepalive_stop:
+	nfp_net_keepalive_stop(multi_pf);
+keepalive_uninit:
+	nfp_net_keepalive_uninit(multi_pf);
+
+	return err;
 }
 
 static int
@@ -1228,9 +1292,9 @@ nfp_fw_setup(struct rte_pci_device *dev,
 	}
 
 	if (multi_pf->enabled)
-		err = nfp_fw_reload_for_multipf(nsp, fw_name, cpp, dev_info, multi_pf);
+		err = nfp_fw_reload_for_multi_pf(nsp, fw_name, cpp, dev_info, multi_pf);
 	else
-		err = nfp_fw_reload(nsp, fw_name);
+		err = nfp_fw_reload_for_single_pf(nsp, fw_name, cpp);
 
 	nfp_nsp_close(nsp);
 	return err;
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index a438eb5871..7b8c175a36 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -2090,6 +2090,23 @@ nfp_net_get_nsp_info(struct nfp_net_hw *hw,
 	nfp_nsp_close(nsp);
 }
 
+void
+nfp_net_get_fw_buildtime(struct nfp_net_hw *hw,
+		uint32_t *mip_buildtime)
+{
+	struct nfp_mip *mip;
+
+	mip = nfp_mip_open(hw->cpp);
+	if (mip == NULL) {
+		*mip_buildtime = 0;
+		return;
+	}
+
+	*mip_buildtime = nfp_mip_buildtime(mip);
+
+	nfp_mip_close(mip);
+}
+
 static void
 nfp_net_get_mip_name(struct nfp_net_hw *hw,
 		char *mip_name)
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index 66c900e3b8..69d17cae17 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -295,6 +295,8 @@ 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_buildtime(struct nfp_net_hw *hw,
+		uint32_t *fw_buildtimes);
 
 #define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\
 	((struct nfp_app_fw_nic *)app_fw_priv)
-- 
2.39.1


  parent reply	other threads:[~2024-01-15  2:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-15  2:54 [PATCH 0/8] optimize the firmware loading process Chaoyong He
2024-01-15  2:54 ` [PATCH 1/8] net/nfp: add the interface for getting the firmware name Chaoyong He
2024-01-15  2:54 ` [PATCH 2/8] net/nfp: speed up the firmware loading process Chaoyong He
2024-01-15  2:54 ` [PATCH 3/8] net/nfp: optimize loading the firmware process Chaoyong He
2024-01-15  2:54 ` [PATCH 4/8] net/nfp: enlarge the range of skipping loading the firmware Chaoyong He
2024-01-15  2:54 ` [PATCH 5/8] net/nfp: add the step of clearing the beat time Chaoyong He
2024-01-15  2:54 ` [PATCH 6/8] net/nfp: add the elf module Chaoyong He
2024-01-15  2:54 ` Chaoyong He [this message]
2024-01-15  2:54 ` [PATCH 8/8] net/nfp: simplify the port name for multiple PFs Chaoyong He
2024-01-22 15:08 ` [PATCH 0/8] optimize the firmware loading process Ferruh Yigit
2024-01-23  1:46   ` Chaoyong He
2024-01-23  9:14     ` Ferruh Yigit
2024-01-23 11:27       ` Chaoyong He
2024-01-23 11:42         ` Ferruh Yigit
2024-01-26  8:25           ` Chaoyong He
2024-01-23 15:18 ` 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=20240115025419.2447759-8-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).