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, Chaoyong He <chaoyong.he@corigine.com>,
	Long Wu <long.wu@corigine.com>,
	Peng Zhang <peng.zhang@corigine.com>
Subject: [PATCH 2/3] net/nfp: add two APIs of the NSP module
Date: Tue,  3 Sep 2024 13:52:38 +0800	[thread overview]
Message-ID: <20240903055239.2642656-3-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240903055239.2642656-1-chaoyong.he@corigine.com>

Add two APIs of the NSP module, also modify the logic to use the
argument to control the log switch for NSP command.

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/nfpcore/nfp_nsp.c | 86 ++++++++++++++++++++++++++++++-
 drivers/net/nfp/nfpcore/nfp_nsp.h | 15 ++++++
 2 files changed, 100 insertions(+), 1 deletion(-)

diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c
index 7dfb472723..2ac39b10b5 100644
--- a/drivers/net/nfp/nfpcore/nfp_nsp.c
+++ b/drivers/net/nfp/nfpcore/nfp_nsp.c
@@ -60,6 +60,8 @@
 #define NFP_FW_LOAD_RET_MAJOR   GENMASK_ULL(15, 8)
 #define NFP_FW_LOAD_RET_MINOR   GENMASK_ULL(23, 16)
 
+#define NFP_HWINFO_LOOKUP_SIZE  GENMASK_ULL(11, 0)
+
 enum nfp_nsp_cmd {
 	SPCODE_NOOP             = 0, /* No operation */
 	SPCODE_SOFT_RESET       = 1, /* Soft reset the NFP */
@@ -477,7 +479,9 @@ nfp_nsp_command_buf_def(struct nfp_nsp *nsp,
 			FIELD_PREP(NSP_BUFFER_ADDRESS, cpp_buf);
 	ret = nfp_nsp_command_real(nsp, &arg->arg);
 	if (ret < 0) {
-		PMD_DRV_LOG(ERR, "NSP command failed");
+		if (!arg->arg.error_quiet)
+			PMD_DRV_LOG(ERR, "NSP command failed");
+
 		return ret;
 	}
 
@@ -755,3 +759,83 @@ nfp_nsp_read_media(struct nfp_nsp *state,
 
 	return nfp_nsp_command_buf(state, &media);
 }
+
+int
+nfp_nsp_load_stored_fw(struct nfp_nsp *state)
+{
+	int ret;
+	struct nfp_nsp_command_buf_arg fw_stored = {
+		{
+			.code     = SPCODE_FW_STORED,
+			.error_cb = nfp_nsp_load_fw_extended_msg,
+		},
+	};
+
+	ret = nfp_nsp_command_buf(state, &fw_stored);
+	if (ret < 0)
+		return ret;
+
+	nfp_nsp_load_fw_extended_msg(state, ret);
+
+	return 0;
+}
+
+static int
+nfp_nsp_hwinfo_lookup_real(struct nfp_nsp *state,
+		void *buf,
+		size_t size,
+		bool optional)
+{
+	struct nfp_nsp_command_buf_arg hwinfo_lookup = {
+		{
+			.code   = SPCODE_HWINFO_LOOKUP,
+			.option = size,
+			.error_quiet = optional,
+		},
+		.in_buf = buf,
+		.in_size = size,
+		.out_buf  = buf,
+		.out_size = size,
+	};
+
+	return nfp_nsp_command_buf(state, &hwinfo_lookup);
+}
+
+int
+nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state,
+		void *buf,
+		size_t size,
+		const char *default_val)
+{
+	int ret;
+	size_t min_size;
+
+	if (strnlen(default_val, size) == size) {
+		PMD_DRV_LOG(ERR, "NSP HWinfo default value not NULL terminated");
+		return -EINVAL;
+	}
+
+	if (!nfp_nsp_has_hwinfo_lookup(state))
+		goto default_return;
+
+	min_size = RTE_MIN(size, NFP_HWINFO_LOOKUP_SIZE);
+	ret = nfp_nsp_hwinfo_lookup_real(state, buf, min_size, true);
+	if (ret != 0) {
+		if (ret == -ENOENT)
+			goto default_return;
+
+		PMD_DRV_LOG(ERR, "NSP HWinfo lookup failed: %d", ret);
+		return ret;
+	}
+
+	if (strnlen(buf, min_size) == min_size) {
+		PMD_DRV_LOG(ERR, "NSP HWinfo value not NULL terminated");
+		return -EINVAL;
+	}
+
+	return 0;
+
+default_return:
+	strlcpy(buf, default_val, size);
+	return 0;
+}
diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h
index 003cdc5fa3..cfb5066fc9 100644
--- a/drivers/net/nfp/nfpcore/nfp_nsp.h
+++ b/drivers/net/nfp/nfpcore/nfp_nsp.h
@@ -8,6 +8,18 @@
 
 #include "nfp_cpp.h"
 
+/* Defines the valid values of the 'abi_drv_reset' hwinfo key */
+#define NFP_NSP_DRV_RESET_DISK                  0
+#define NFP_NSP_DRV_RESET_ALWAYS                1
+#define NFP_NSP_DRV_RESET_NEVER                 2
+#define NFP_NSP_DRV_RESET_DEFAULT               "0"
+
+/* Defines the valid values of the 'app_fw_from_flash' hwinfo key */
+#define NFP_NSP_APP_FW_LOAD_DISK                0
+#define NFP_NSP_APP_FW_LOAD_FLASH               1
+#define NFP_NSP_APP_FW_LOAD_PREF                2
+#define NFP_NSP_APP_FW_LOAD_DEFAULT             "2"
+
 struct nfp_nsp;
 
 struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp);
@@ -225,6 +237,9 @@ enum nfp_nsp_sensor_id {
 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
 		uint32_t *val);
 bool nfp_nsp_fw_loaded(struct nfp_nsp *state);
+int nfp_nsp_load_stored_fw(struct nfp_nsp *state);
+int nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state,
+		void *buf, size_t size, const char *default_val);
 
 /* The buf used to receive bitmap of link modes */
 struct nfp_eth_media_buf {
-- 
2.39.1


  parent reply	other threads:[~2024-09-03  5:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-03  5:52 [PATCH 0/3] support load firmware from flash Chaoyong He
2024-09-03  5:52 ` [PATCH 1/3] net/nfp: fix potential problem on certain version BSP Chaoyong He
2024-09-03  5:52 ` Chaoyong He [this message]
2024-09-03  5:52 ` [PATCH 3/3] net/nfp: support load firmware from flash Chaoyong He
2024-10-04  6:15 ` [PATCH 0/3] " 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=20240903055239.2642656-3-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).