Skip to content

Commit c5ba43d

Browse files
hechaoyongferruhy
authored andcommitted
net/nfp: add two functions of the NSP module
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 <[email protected]> Reviewed-by: Long Wu <[email protected]> Reviewed-by: Peng Zhang <[email protected]>
1 parent 6257ac1 commit c5ba43d

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

drivers/net/nfp/nfpcore/nfp_nsp.c

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
#define NFP_FW_LOAD_RET_MAJOR GENMASK_ULL(15, 8)
6161
#define NFP_FW_LOAD_RET_MINOR GENMASK_ULL(23, 16)
6262

63+
#define NFP_HWINFO_LOOKUP_SIZE GENMASK_ULL(11, 0)
64+
6365
enum nfp_nsp_cmd {
6466
SPCODE_NOOP = 0, /* No operation */
6567
SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */
@@ -477,7 +479,9 @@ nfp_nsp_command_buf_def(struct nfp_nsp *nsp,
477479
FIELD_PREP(NSP_BUFFER_ADDRESS, cpp_buf);
478480
ret = nfp_nsp_command_real(nsp, &arg->arg);
479481
if (ret < 0) {
480-
PMD_DRV_LOG(ERR, "NSP command failed");
482+
if (!arg->arg.error_quiet)
483+
PMD_DRV_LOG(ERR, "NSP command failed");
484+
481485
return ret;
482486
}
483487

@@ -755,3 +759,83 @@ nfp_nsp_read_media(struct nfp_nsp *state,
755759

756760
return nfp_nsp_command_buf(state, &media);
757761
}
762+
763+
int
764+
nfp_nsp_load_stored_fw(struct nfp_nsp *state)
765+
{
766+
int ret;
767+
struct nfp_nsp_command_buf_arg fw_stored = {
768+
{
769+
.code = SPCODE_FW_STORED,
770+
.error_cb = nfp_nsp_load_fw_extended_msg,
771+
},
772+
};
773+
774+
ret = nfp_nsp_command_buf(state, &fw_stored);
775+
if (ret < 0)
776+
return ret;
777+
778+
nfp_nsp_load_fw_extended_msg(state, ret);
779+
780+
return 0;
781+
}
782+
783+
static int
784+
nfp_nsp_hwinfo_lookup_real(struct nfp_nsp *state,
785+
void *buf,
786+
size_t size,
787+
bool optional)
788+
{
789+
struct nfp_nsp_command_buf_arg hwinfo_lookup = {
790+
{
791+
.code = SPCODE_HWINFO_LOOKUP,
792+
.option = size,
793+
.error_quiet = optional,
794+
},
795+
.in_buf = buf,
796+
.in_size = size,
797+
.out_buf = buf,
798+
.out_size = size,
799+
};
800+
801+
return nfp_nsp_command_buf(state, &hwinfo_lookup);
802+
}
803+
804+
int
805+
nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state,
806+
void *buf,
807+
size_t size,
808+
const char *default_val)
809+
{
810+
int ret;
811+
size_t min_size;
812+
813+
if (strnlen(default_val, size) == size) {
814+
PMD_DRV_LOG(ERR, "NSP HWinfo default value not NULL terminated");
815+
return -EINVAL;
816+
}
817+
818+
if (!nfp_nsp_has_hwinfo_lookup(state))
819+
goto default_return;
820+
821+
min_size = RTE_MIN(size, NFP_HWINFO_LOOKUP_SIZE);
822+
ret = nfp_nsp_hwinfo_lookup_real(state, buf, min_size, true);
823+
if (ret != 0) {
824+
if (ret == -ENOENT)
825+
goto default_return;
826+
827+
PMD_DRV_LOG(ERR, "NSP HWinfo lookup failed: %d", ret);
828+
return ret;
829+
}
830+
831+
if (strnlen(buf, min_size) == min_size) {
832+
PMD_DRV_LOG(ERR, "NSP HWinfo value not NULL terminated");
833+
return -EINVAL;
834+
}
835+
836+
return 0;
837+
838+
default_return:
839+
strlcpy(buf, default_val, size);
840+
return 0;
841+
}

drivers/net/nfp/nfpcore/nfp_nsp.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88

99
#include "nfp_cpp.h"
1010

11+
/* Defines the valid values of the 'abi_drv_reset' hwinfo key */
12+
#define NFP_NSP_DRV_RESET_DISK 0
13+
#define NFP_NSP_DRV_RESET_ALWAYS 1
14+
#define NFP_NSP_DRV_RESET_NEVER 2
15+
#define NFP_NSP_DRV_RESET_DEFAULT "0"
16+
17+
/* Defines the valid values of the 'app_fw_from_flash' hwinfo key */
18+
#define NFP_NSP_APP_FW_LOAD_DISK 0
19+
#define NFP_NSP_APP_FW_LOAD_FLASH 1
20+
#define NFP_NSP_APP_FW_LOAD_PREF 2
21+
#define NFP_NSP_APP_FW_LOAD_DEFAULT "2"
22+
1123
struct nfp_nsp;
1224

1325
struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp);
@@ -225,6 +237,9 @@ enum nfp_nsp_sensor_id {
225237
int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
226238
uint32_t *val);
227239
bool nfp_nsp_fw_loaded(struct nfp_nsp *state);
240+
int nfp_nsp_load_stored_fw(struct nfp_nsp *state);
241+
int nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state,
242+
void *buf, size_t size, const char *default_val);
228243

229244
/* The buf used to receive bitmap of link modes */
230245
struct nfp_eth_media_buf {

0 commit comments

Comments
 (0)