All of lore.kernel.org
 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>
Subject: [PATCH v2 3/3] net/nfp: add force reload firmware option
Date: Fri,  1 Mar 2024 16:42:44 +0800	[thread overview]
Message-ID: <20240301084244.190484-4-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240301084244.190484-1-chaoyong.he@corigine.com>

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

Add an option to force reload the firmware.

This option can be ignored in some case, for example:
When using a 2 port NFP card and both with this reload firmware option,
only the first one will cause the firmware reload and the second one
will be ignored.

Signed-off-by: Peng Zhang <peng.zhang@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
---
 doc/guides/nics/nfp.rst          |  21 +++++++
 drivers/net/nfp/nfp_ethdev.c     | 104 +++++++++++++++++++++++++++----
 drivers/net/nfp/nfp_net_common.h |   8 +++
 3 files changed, 121 insertions(+), 12 deletions(-)

diff --git a/doc/guides/nics/nfp.rst b/doc/guides/nics/nfp.rst
index fee1860f4a..4f2be0856c 100644
--- a/doc/guides/nics/nfp.rst
+++ b/doc/guides/nics/nfp.rst
@@ -225,6 +225,27 @@ The ctrl vNIC service handles various control messages, for example, the
 creation and configuration of representor port, the pattern and action of flow
 rules, the statistics of flow rules, etc.
 
+NFP devargs
+-----------
+
+- ``force_reload_fw`` (default **0**)
+
+   The NFP PF PMD supports force reload the firmware and ignore the firmware
+   version. For example, user can force a PF with PCI ID 0000:af:00.0 reload
+   firmware by:
+
+   .. code-block:: console
+
+      -a af:00.0,force_reload_fw=1 -- -i
+
+   .. Note::
+
+      This parameter can be ignored in some case.
+
+      For example: when using a 2 port NFP card and both with this reload
+      firmware option, only the first one will cause the firmware reload and
+      the second one will be ignored.
+
 Metadata Format
 ---------------
 
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 902a62a86b..8c38b4e134 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -9,6 +9,7 @@
 
 #include <eal_firmware.h>
 #include <rte_alarm.h>
+#include <rte_kvargs.h>
 
 #include "flower/nfp_flower.h"
 #include "nfd3/nfp_nfd3.h"
@@ -31,6 +32,71 @@
 #define NFP_NET_APP_CAP_SP_INDIFF       RTE_BIT64(0) /* Indifferent to port speed */
 
 #define NFP_PF_DRIVER_NAME net_nfp_pf
+#define NFP_PF_FORCE_RELOAD_FW   "force_reload_fw"
+
+static int
+nfp_devarg_handle_int(const char *key,
+		const char *value,
+		void *extra_args)
+{
+	char *end_ptr;
+	uint64_t *num = extra_args;
+
+	if (value == NULL)
+		return -EPERM;
+
+	*num = strtoul(value, &end_ptr, 10);
+	if (*num == ULONG_MAX) {
+		PMD_DRV_LOG(ERR, "%s: '%s' is not a valid param", key, value);
+		return -ERANGE;
+	} else if (value == end_ptr) {
+		return -EPERM;
+	}
+
+	return 0;
+}
+
+static void
+nfp_devarg_parse_force_reload_fw(struct rte_kvargs *kvlist,
+		bool *force_reload_fw)
+{
+	int ret;
+	uint64_t value;
+
+
+	if (rte_kvargs_count(kvlist, NFP_PF_FORCE_RELOAD_FW) != 1)
+		return;
+
+	ret = rte_kvargs_process(kvlist, NFP_PF_FORCE_RELOAD_FW, &nfp_devarg_handle_int, &value);
+	if (ret != 0)
+		return;
+
+	if (value == 1)
+		*force_reload_fw = true;
+	else if (value == 0)
+		*force_reload_fw = false;
+	else
+		PMD_DRV_LOG(ERR, "The param does not work, the format is %s=0/1",
+				NFP_PF_FORCE_RELOAD_FW);
+}
+
+static void
+nfp_devargs_parse(struct nfp_devargs *nfp_devargs_param,
+		const struct rte_devargs *devargs)
+{
+	struct rte_kvargs *kvlist;
+
+	if (devargs == NULL)
+		return;
+
+	kvlist = rte_kvargs_parse(devargs->args, NULL);
+	if (kvlist == NULL)
+		return;
+
+	nfp_devarg_parse_force_reload_fw(kvlist, &nfp_devargs_param->force_reload_fw);
+
+	rte_kvargs_free(kvlist);
+}
 
 static void
 nfp_net_pf_read_mac(struct nfp_app_fw_nic *app_fw_nic,
@@ -1116,7 +1182,8 @@ nfp_fw_reload(struct nfp_nsp *nsp,
 
 static bool
 nfp_fw_skip_load(const struct nfp_dev_info *dev_info,
-		struct nfp_multi_pf *multi_pf)
+		struct nfp_multi_pf *multi_pf,
+		bool *reload_fw)
 {
 	uint8_t i;
 	uint64_t tmp_beat;
@@ -1150,6 +1217,11 @@ nfp_fw_skip_load(const struct nfp_dev_info *dev_info,
 				in_use++;
 				abnormal--;
 				beat[port_num] = 0;
+				if (*reload_fw) {
+					*reload_fw = false;
+					PMD_DRV_LOG(ERR, "The param %s does not work",
+							NFP_PF_FORCE_RELOAD_FW);
+				}
 			}
 		}
 
@@ -1168,12 +1240,13 @@ nfp_fw_skip_load(const struct nfp_dev_info *dev_info,
 static int
 nfp_fw_reload_for_single_pf(struct nfp_nsp *nsp,
 		char *fw_name,
-		struct nfp_cpp *cpp)
+		struct nfp_cpp *cpp,
+		bool force_reload_fw)
 {
 	int ret;
 	bool fw_changed = true;
 
-	if (nfp_nsp_fw_loaded(nsp)) {
+	if (nfp_nsp_fw_loaded(nsp) && !force_reload_fw) {
 		ret = nfp_fw_check_change(cpp, fw_name, &fw_changed);
 		if (ret != 0)
 			return ret;
@@ -1194,11 +1267,13 @@ 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)
+		struct nfp_multi_pf *multi_pf,
+		bool force_reload_fw)
 {
 	int err;
 	bool fw_changed = true;
 	bool skip_load_fw = false;
+	bool reload_fw = force_reload_fw;
 
 	err = nfp_net_keepalive_init(cpp, multi_pf);
 	if (err != 0) {
@@ -1212,16 +1287,16 @@ nfp_fw_reload_for_multi_pf(struct nfp_nsp *nsp,
 		goto keepalive_uninit;
 	}
 
-	if (nfp_nsp_fw_loaded(nsp)) {
+	if (nfp_nsp_fw_loaded(nsp) && !reload_fw) {
 		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 (!fw_changed || reload_fw)
+		skip_load_fw = nfp_fw_skip_load(dev_info, multi_pf, &reload_fw);
 
-	if (skip_load_fw)
+	if (skip_load_fw && !reload_fw)
 		return 0;
 
 	err = nfp_fw_reload(nsp, fw_name);
@@ -1246,7 +1321,8 @@ nfp_fw_setup(struct rte_pci_device *dev,
 		struct nfp_eth_table *nfp_eth_table,
 		struct nfp_hwinfo *hwinfo,
 		const struct nfp_dev_info *dev_info,
-		struct nfp_multi_pf *multi_pf)
+		struct nfp_multi_pf *multi_pf,
+		bool force_reload_fw)
 {
 	int err;
 	char fw_name[125];
@@ -1294,9 +1370,10 @@ nfp_fw_setup(struct rte_pci_device *dev,
 	}
 
 	if (multi_pf->enabled)
-		err = nfp_fw_reload_for_multi_pf(nsp, fw_name, cpp, dev_info, multi_pf);
+		err = nfp_fw_reload_for_multi_pf(nsp, fw_name, cpp, dev_info, multi_pf,
+				force_reload_fw);
 	else
-		err = nfp_fw_reload_for_single_pf(nsp, fw_name, cpp);
+		err = nfp_fw_reload_for_single_pf(nsp, fw_name, cpp, force_reload_fw);
 
 	nfp_nsp_close(nsp);
 	return err;
@@ -1769,8 +1846,10 @@ nfp_pf_init(struct rte_pci_device *pci_dev)
 		nfp_eth_set_configured(cpp, index, 0);
 	}
 
+	nfp_devargs_parse(&pf_dev->devargs, pci_dev->device.devargs);
+
 	if (nfp_fw_setup(pci_dev, cpp, nfp_eth_table, hwinfo,
-			dev_info, &pf_dev->multi_pf) != 0) {
+			dev_info, &pf_dev->multi_pf, pf_dev->devargs.force_reload_fw) != 0) {
 		PMD_INIT_LOG(ERR, "Error when uploading firmware");
 		ret = -EIO;
 		goto eth_table_cleanup;
@@ -2151,3 +2230,4 @@ static struct rte_pci_driver rte_nfp_net_pf_pmd = {
 RTE_PMD_REGISTER_PCI(NFP_PF_DRIVER_NAME, rte_nfp_net_pf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(NFP_PF_DRIVER_NAME, pci_id_nfp_pf_net_map);
 RTE_PMD_REGISTER_KMOD_DEP(NFP_PF_DRIVER_NAME, "* igb_uio | uio_pci_generic | vfio");
+RTE_PMD_REGISTER_PARAM_STRING(NFP_PF_DRIVER_NAME, NFP_PF_FORCE_RELOAD_FW "=<0|1>");
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index 9c46bfd4f6..628c0d3491 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -94,6 +94,11 @@ struct nfp_process_share {
 	struct nfp_flower_service *fl_service;
 };
 
+struct nfp_devargs {
+	/** Force reload firmware */
+	bool force_reload_fw;
+};
+
 struct nfp_pf_dev {
 	/** Backpointer to associated pci device */
 	struct rte_pci_device *pci_dev;
@@ -129,6 +134,9 @@ struct nfp_pf_dev {
 	/** Synchronized info */
 	struct nfp_sync *sync;
 	struct nfp_process_share process_share;
+
+	/** NFP devarg param */
+	struct nfp_devargs devargs;
 };
 
 #define NFP_NET_FLOW_LIMIT    1024
-- 
2.39.1


  parent reply	other threads:[~2024-03-01  8:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 11:15 [PATCH 0/3] reload the firmware as needed Chaoyong He
2024-02-27 11:15 ` [PATCH 1/3] net/nfp: add the elf module Chaoyong He
2024-02-28 16:50   ` Ferruh Yigit
2024-03-01  2:38     ` Chaoyong He
2024-02-28 22:18   ` Stephen Hemminger
2024-03-01 17:22     ` Ferruh Yigit
2024-03-04  1:13       ` Chaoyong He
2024-03-04  8:50         ` Ferruh Yigit
2024-02-27 11:15 ` [PATCH 2/3] net/nfp: reload the firmware only when firmware changed Chaoyong He
2024-02-27 11:15 ` [PATCH 3/3] net/nfp: add force reload firmware option Chaoyong He
2024-02-28 16:53   ` Ferruh Yigit
2024-03-01  2:06     ` Chaoyong He
2024-03-01  8:42 ` [PATCH v2 0/3] reload the firmware as needed Chaoyong He
2024-03-01  8:42   ` [PATCH v2 1/3] net/nfp: add the elf module Chaoyong He
2024-03-01  8:42   ` [PATCH v2 2/3] net/nfp: reload the firmware only when firmware changed Chaoyong He
2024-03-01  8:42   ` Chaoyong He [this message]
2024-03-04 13:28   ` [PATCH v2 0/3] reload the firmware as needed 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=20240301084244.190484-4-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.