* [PATCH iproute2-next v1 0/2] devlink: add support to run selftests
@ 2022-06-28 16:44 Vikas Gupta
2022-06-28 16:44 ` [PATCH iproute2-next v1 1/2] Update kernel header Vikas Gupta
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-06-28 16:44 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 635 bytes --]
Hi,
This patchset adds support in devlink to run selftests.
A related patchset for kernel has been pushed for review.
Below are the few examples for the commands.
$ devlink dev selftests run pci/0000:03:00.0 test flash
results:
flash test : failed
$ devlink dev selftests show pci/0000:03:00.0
device suuports:
flash test
Thanks,
Vikas
Vikas Gupta (2):
Update kernel header
devlink: add support for running selftests
devlink/devlink.c | 157 +++++++++++++++++++++++++++++++++++
include/uapi/linux/devlink.h | 24 ++++++
2 files changed, 181 insertions(+)
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v1 1/2] Update kernel header
2022-06-28 16:44 [PATCH iproute2-next v1 0/2] devlink: add support to run selftests Vikas Gupta
@ 2022-06-28 16:44 ` Vikas Gupta
2022-06-28 16:44 ` [PATCH iproute2-next v1 2/2] devlink: add support for running selftests Vikas Gupta
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-06-28 16:44 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 1784 bytes --]
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
---
include/uapi/linux/devlink.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index da0f1ba8..ea215b7f 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -136,6 +136,9 @@ enum devlink_command {
DEVLINK_CMD_LINECARD_NEW,
DEVLINK_CMD_LINECARD_DEL,
+ DEVLINK_CMD_SELFTESTS_SHOW,
+ DEVLINK_CMD_SELFTESTS_RUN,
+
/* add new commands above here */
__DEVLINK_CMD_MAX,
DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
@@ -276,6 +279,21 @@ enum {
#define DEVLINK_SUPPORTED_FLASH_OVERWRITE_SECTIONS \
(_BITUL(__DEVLINK_FLASH_OVERWRITE_MAX_BIT) - 1)
+/* Commonly used test cases. Drivers might interpret test bit
+ * in their own way and it may map single to multiple tests.
+ */
+enum {
+ DEVLINK_SELFTEST_FLASH_BIT,
+
+ __DEVLINK_SELFTEST_MAX_BIT,
+ DEVLINK_SELFTEST_MAX_BIT = __DEVLINK_SELFTEST_MAX_BIT - 1
+};
+
+#define DEVLINK_SELFTEST_FLASH _BITUL(DEVLINK_SELFTEST_FLASH_BIT)
+
+#define DEVLINK_SUPPORTED_SELFTESTS \
+ (_BITUL(__DEVLINK_SELFTEST_MAX_BIT) - 1)
+
/**
* enum devlink_trap_action - Packet trap action.
* @DEVLINK_TRAP_ACTION_DROP: Packet is dropped by the device and a copy is not
@@ -576,6 +594,12 @@ enum devlink_attr {
DEVLINK_ATTR_LINECARD_TYPE, /* string */
DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES, /* nested */
+ DEVLINK_ATTR_SELFTESTS_MASK, /* bitfield32 */
+ DEVLINK_ATTR_TEST_NAMES, /* nested */
+ DEVLINK_ATTR_TEST_NAME, /* string */
+ DEVLINK_ATTR_TEST_RESULTS, /* nested */
+ DEVLINK_ATTR_TEST_RESULT, /* nested */
+ DEVLINK_ATTR_TEST_RESULT_VAL, /* u8 */
/* add new attributes above here, update the policy in devlink.c */
__DEVLINK_ATTR_MAX,
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v1 2/2] devlink: add support for running selftests
2022-06-28 16:44 [PATCH iproute2-next v1 0/2] devlink: add support to run selftests Vikas Gupta
2022-06-28 16:44 ` [PATCH iproute2-next v1 1/2] Update kernel header Vikas Gupta
@ 2022-06-28 16:44 ` Vikas Gupta
2022-06-29 11:37 ` [PATCH iproute2-next v1 0/2] devlink: add support to run selftests Ido Schimmel
2022-07-07 18:31 ` [PATCH iproute2-next v2 0/3] " Vikas Gupta
3 siblings, 0 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-06-28 16:44 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 7660 bytes --]
Add command and helper APIs to run selfests.
Also add a seltest for flash on the device.
Examples:
$ devlink dev selftests run pci/0000:03:00.0 test flash
results:
flash test : failed
$ devlink dev selftests show pci/0000:03:00.0
device suuports:
flash test
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
---
devlink/devlink.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 157 insertions(+)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index ddf430bb..2f7c4ff9 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -294,6 +294,7 @@ static void ifname_map_free(struct ifname_map *ifname_map)
#define DL_OPT_PORT_FN_RATE_TX_MAX BIT(49)
#define DL_OPT_PORT_FN_RATE_NODE_NAME BIT(50)
#define DL_OPT_PORT_FN_RATE_PARENT BIT(51)
+#define DL_OPT_SELFTESTS BIT(52)
struct dl_opts {
uint64_t present; /* flags of present items */
@@ -344,6 +345,7 @@ struct dl_opts {
uint32_t overwrite_mask;
enum devlink_reload_action reload_action;
enum devlink_reload_limit reload_limit;
+ uint32_t selftests_mask;
uint32_t port_controller;
uint32_t port_sfnumber;
uint16_t port_flavour;
@@ -1401,6 +1403,19 @@ static struct str_num_map port_fn_opstate_map[] = {
{ .str = NULL, }
};
+static int selftests_get(const char *testname, uint32_t *mask)
+{
+ if (strcmp(testname, "flash") == 0) {
+ *mask |= DEVLINK_SELFTEST_FLASH;
+ } else if (strcmp(testname, "all") == 0) {
+ *mask = DEVLINK_SUPPORTED_SELFTESTS;
+ } else {
+ pr_err("Unknown selftest \"%s\"\n", testname);
+ return -EINVAL;
+ }
+ return 0;
+}
+
static int port_flavour_parse(const char *flavour, uint16_t *value)
{
int num;
@@ -1490,6 +1505,7 @@ static const struct dl_args_metadata dl_args_required[] = {
{DL_OPT_PORT_FUNCTION_HW_ADDR, "Port function's hardware address is expected."},
{DL_OPT_PORT_FLAVOUR, "Port flavour is expected."},
{DL_OPT_PORT_PFNUMBER, "Port PCI PF number is expected."},
+ {DL_OPT_SELFTESTS, "Test name is expected"},
};
static int dl_args_finding_required_validate(uint64_t o_required,
@@ -1793,6 +1809,20 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
return err;
o_found |= DL_OPT_FLASH_OVERWRITE;
+ } else if (dl_argv_match(dl, "test") &&
+ (o_all & DL_OPT_SELFTESTS)) {
+ const char *testname;
+
+ dl_arg_inc(dl);
+ err = dl_argv_str(dl, &testname);
+ if( err)
+ return err;
+ err = selftests_get(testname,
+ &opts->selftests_mask);
+ if (err)
+ return err;
+ o_found |= DL_OPT_SELFTESTS;
+
} else if (dl_argv_match(dl, "reporter") &&
(o_all & DL_OPT_HEALTH_REPORTER_NAME)) {
dl_arg_inc(dl);
@@ -2063,6 +2093,17 @@ dl_reload_limits_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
mnl_attr_put(nlh, DEVLINK_ATTR_RELOAD_LIMITS, sizeof(limits), &limits);
}
+static void
+dl_selftests_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
+{
+ struct nla_bitfield32 selftests_mask;
+ selftests_mask.selector = DEVLINK_SUPPORTED_SELFTESTS;
+ selftests_mask.value = opts->selftests_mask;
+
+ mnl_attr_put(nlh, DEVLINK_ATTR_SELFTESTS_MASK,
+ sizeof(selftests_mask), &selftests_mask);
+}
+
static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
{
struct dl_opts *opts = &dl->opts;
@@ -2157,6 +2198,8 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
opts->flash_component);
if (opts->present & DL_OPT_FLASH_OVERWRITE)
dl_flash_update_overwrite_put(nlh, opts);
+ if (opts->present & DL_OPT_SELFTESTS)
+ dl_selftests_put(nlh, opts);
if (opts->present & DL_OPT_HEALTH_REPORTER_NAME)
mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME,
opts->reporter_name);
@@ -2285,6 +2328,8 @@ static void cmd_dev_help(void)
pr_err(" [ action { driver_reinit | fw_activate } ] [ limit no_reset ]\n");
pr_err(" devlink dev info [ DEV ]\n");
pr_err(" devlink dev flash DEV file PATH [ component NAME ] [ overwrite SECTION ]\n");
+ pr_err(" devlink dev selftests show DEV\n");
+ pr_err(" devlink dev selftests run DEV test {flash | all}\n");
}
static bool cmp_arr_last_handle(struct dl *dl, const char *bus_name,
@@ -3904,6 +3949,115 @@ err_socket:
return err;
}
+static int cmd_dev_selftests_show_tests(const struct nlmsghdr *nlh, void *data)
+{
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+ struct nlattr *test_name_attr;
+ struct dl *dl = data;
+
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+ if (!tb[DEVLINK_ATTR_TEST_NAMES]) {
+ return MNL_CB_ERROR;
+ }
+
+ pr_out_array_start(dl, "device supports");
+
+ mnl_attr_for_each_nested(test_name_attr, tb[DEVLINK_ATTR_TEST_NAMES]) {
+ pr_out_entry_start(dl);
+ check_indent_newline(dl);
+ print_string(PRINT_ANY, NULL, "%s",
+ mnl_attr_get_str(test_name_attr));
+ pr_out_entry_end(dl);
+ }
+
+ pr_out_array_end(dl);
+ return 0;
+}
+
+static int cmd_dev_selftests_result_show(const struct nlmsghdr *nlh, void *data)
+{
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+ struct nlattr *test_res[DEVLINK_ATTR_MAX + 1] = {};
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+ struct nlattr *nla_header;
+ struct dl *dl = data;
+ int err = 0;
+
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+ if (!tb[DEVLINK_ATTR_TEST_RESULTS]) {
+ return MNL_CB_ERROR;
+ }
+
+ pr_out_array_start(dl, "results");
+
+ mnl_attr_for_each_nested(nla_header, tb[DEVLINK_ATTR_TEST_RESULTS]) {
+ err = mnl_attr_parse_nested(nla_header, attr_cb, test_res);
+ if (err != MNL_CB_OK)
+ goto err_result_show;
+ pr_out_entry_start(dl);
+ check_indent_newline(dl);
+ print_string(PRINT_ANY, NULL, "%s : ",
+ mnl_attr_get_str(test_res[DEVLINK_ATTR_TEST_NAME]));
+ print_string(PRINT_ANY, NULL, " %s",
+ mnl_attr_get_u8(test_res[DEVLINK_ATTR_TEST_RESULT_VAL]) ? "passed" : "failed");
+ pr_out_entry_end(dl);
+ }
+
+err_result_show:
+ pr_out_array_end(dl);
+ return err;
+}
+
+static int cmd_dev_selftests_run(struct dl *dl)
+{
+ struct nlmsghdr *nlh;
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
+ int err;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SELFTESTS_RUN, flags);
+
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_SELFTESTS, 0);
+ if (err)
+ return err;
+
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_selftests_result_show, dl);
+ return err;
+}
+
+static int cmd_dev_selftests_show(struct dl *dl)
+{
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
+ struct nlmsghdr *nlh;
+ int err;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SELFTESTS_SHOW, flags);
+
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
+ if (err)
+ return err;
+
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_selftests_show_tests, dl);
+ return err;
+}
+
+static int cmd_dev_selftests(struct dl *dl)
+{
+ if (dl_argv_match(dl, "help")) {
+ cmd_dev_help();
+ return 0;
+ } else if (dl_argv_match(dl, "show") ||
+ dl_argv_match(dl, "list") || dl_no_arg(dl)) {
+ dl_arg_inc(dl);
+ return cmd_dev_selftests_show(dl);
+ } else if (dl_argv_match(dl, "run")) {
+ dl_arg_inc(dl);
+ return cmd_dev_selftests_run(dl);
+ }
+ pr_err("Command \"%s\" not found\n", dl_argv(dl));
+ return -ENOENT;
+}
+
static int cmd_dev(struct dl *dl)
{
if (dl_argv_match(dl, "help")) {
@@ -3928,6 +4082,9 @@ static int cmd_dev(struct dl *dl)
} else if (dl_argv_match(dl, "flash")) {
dl_arg_inc(dl);
return cmd_dev_flash(dl);
+ } else if (dl_argv_match(dl, "selftests")) {
+ dl_arg_inc(dl);
+ return cmd_dev_selftests(dl);
}
pr_err("Command \"%s\" not found\n", dl_argv(dl));
return -ENOENT;
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH iproute2-next v1 0/2] devlink: add support to run selftests
2022-06-28 16:44 [PATCH iproute2-next v1 0/2] devlink: add support to run selftests Vikas Gupta
2022-06-28 16:44 ` [PATCH iproute2-next v1 1/2] Update kernel header Vikas Gupta
2022-06-28 16:44 ` [PATCH iproute2-next v1 2/2] devlink: add support for running selftests Vikas Gupta
@ 2022-06-29 11:37 ` Ido Schimmel
2022-07-07 18:31 ` [PATCH iproute2-next v2 0/3] " Vikas Gupta
3 siblings, 0 replies; 13+ messages in thread
From: Ido Schimmel @ 2022-06-29 11:37 UTC (permalink / raw)
To: Vikas Gupta
Cc: jiri, dsahern, stephen, kuba, netdev, edumazet, michael.chan,
andrew.gospodarek
On Tue, Jun 28, 2022 at 10:14:45PM +0530, Vikas Gupta wrote:
> devlink/devlink.c | 157 +++++++++++++++++++++++++++++++++++
> include/uapi/linux/devlink.h | 24 ++++++
> 2 files changed, 181 insertions(+)
Please update the man pages and bash completion
(bash-completion/devlink) in the next version
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v2 0/3] devlink: add support to run selftests
2022-06-28 16:44 [PATCH iproute2-next v1 0/2] devlink: add support to run selftests Vikas Gupta
` (2 preceding siblings ...)
2022-06-29 11:37 ` [PATCH iproute2-next v1 0/2] devlink: add support to run selftests Ido Schimmel
@ 2022-07-07 18:31 ` Vikas Gupta
2022-07-07 18:31 ` [PATCH iproute2-next v2 1/3] devlink: update the devlink.h Vikas Gupta
` (4 more replies)
3 siblings, 5 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-07-07 18:31 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 937 bytes --]
Hi,
This patchset adds support in devlink to run selftests.
A related patchset for kernel has been pushed for review.
Below are the few examples for the commands.
Examples:
$ devlink dev selftests run pci/0000:03:00.0 test flash
selftests results:
flash failed
$ devlink dev selftests show pci/0000:03:00.0
supported selftests:
flash
changes from:
v1->v2
a) Changes required to implement command due to changes
in kernel patch (under review).
b) Added commands descriptions in devlink-dev man page.
Thanks,
Vikas
Vikas Gupta (3):
devlink: update the devlink.h
devlink: add support for running selftests
devlink : update man page for new commands
devlink/devlink.c | 193 +++++++++++++++++++++++++++++++++++
include/uapi/linux/devlink.h | 26 +++++
man/man8/devlink-dev.8 | 46 +++++++++
3 files changed, 265 insertions(+)
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v2 1/3] devlink: update the devlink.h
2022-07-07 18:31 ` [PATCH iproute2-next v2 0/3] " Vikas Gupta
@ 2022-07-07 18:31 ` Vikas Gupta
2022-07-07 18:31 ` [PATCH iproute2-next v2 2/3] devlink: add support for running selftests Vikas Gupta
` (3 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-07-07 18:31 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 1854 bytes --]
update the devlink.h to comaptible with net-next kernel.
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
---
include/uapi/linux/devlink.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index da0f1ba8..281aa1fa 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -136,6 +136,9 @@ enum devlink_command {
DEVLINK_CMD_LINECARD_NEW,
DEVLINK_CMD_LINECARD_DEL,
+ DEVLINK_CMD_SELFTESTS_SHOW,
+ DEVLINK_CMD_SELFTESTS_RUN,
+
/* add new commands above here */
__DEVLINK_CMD_MAX,
DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
@@ -276,6 +279,25 @@ enum {
#define DEVLINK_SUPPORTED_FLASH_OVERWRITE_SECTIONS \
(_BITUL(__DEVLINK_FLASH_OVERWRITE_MAX_BIT) - 1)
+/* Commonly used test cases */
+enum {
+ DEVLINK_SELFTEST_FLASH_BIT,
+
+ __DEVLINK_SELFTEST_MAX_BIT,
+ DEVLINK_SELFTEST_MAX_BIT = __DEVLINK_SELFTEST_MAX_BIT - 1
+};
+
+#define DEVLINK_SELFTEST_FLASH _BITUL(DEVLINK_SELFTEST_FLASH_BIT)
+
+#define DEVLINK_SELFTESTS_MASK \
+ (_BITUL(__DEVLINK_SELFTEST_MAX_BIT) - 1)
+
+enum {
+ DEVLINK_SELFTEST_SKIP,
+ DEVLINK_SELFTEST_PASS,
+ DEVLINK_SELFTEST_FAIL
+};
+
/**
* enum devlink_trap_action - Packet trap action.
* @DEVLINK_TRAP_ACTION_DROP: Packet is dropped by the device and a copy is not
@@ -576,6 +598,10 @@ enum devlink_attr {
DEVLINK_ATTR_LINECARD_TYPE, /* string */
DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES, /* nested */
+ DEVLINK_ATTR_SELFTESTS_MASK, /* u32 */
+ DEVLINK_ATTR_TEST_RESULT, /* nested */
+ DEVLINK_ATTR_TEST_NAME, /* string */
+ DEVLINK_ATTR_TEST_RESULT_VAL, /* u8 */
/* add new attributes above here, update the policy in devlink.c */
__DEVLINK_ATTR_MAX,
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v2 2/3] devlink: add support for running selftests
2022-07-07 18:31 ` [PATCH iproute2-next v2 0/3] " Vikas Gupta
2022-07-07 18:31 ` [PATCH iproute2-next v2 1/3] devlink: update the devlink.h Vikas Gupta
@ 2022-07-07 18:31 ` Vikas Gupta
2022-07-07 18:31 ` [PATCH iproute2-next v2 3/3] devlink : update man page for new commands Vikas Gupta
` (2 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-07-07 18:31 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 8525 bytes --]
Add command and helper APIs to run selfests.
Also add a seltest for flash on the device.
Examples:
$ devlink dev selftests run pci/0000:03:00.0 test flash
selftests results:
flash failed
$ devlink dev selftests show pci/0000:03:00.0
supported selftests:
flash
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
---
devlink/devlink.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 193 insertions(+)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index ddf430bb..ebd33f9d 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -294,6 +294,7 @@ static void ifname_map_free(struct ifname_map *ifname_map)
#define DL_OPT_PORT_FN_RATE_TX_MAX BIT(49)
#define DL_OPT_PORT_FN_RATE_NODE_NAME BIT(50)
#define DL_OPT_PORT_FN_RATE_PARENT BIT(51)
+#define DL_OPT_SELFTESTS BIT(52)
struct dl_opts {
uint64_t present; /* flags of present items */
@@ -344,6 +345,7 @@ struct dl_opts {
uint32_t overwrite_mask;
enum devlink_reload_action reload_action;
enum devlink_reload_limit reload_limit;
+ uint32_t selftests_mask;
uint32_t port_controller;
uint32_t port_sfnumber;
uint16_t port_flavour;
@@ -693,6 +695,7 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
[DEVLINK_ATTR_TRAP_POLICER_ID] = MNL_TYPE_U32,
[DEVLINK_ATTR_TRAP_POLICER_RATE] = MNL_TYPE_U64,
[DEVLINK_ATTR_TRAP_POLICER_BURST] = MNL_TYPE_U64,
+ [DEVLINK_ATTR_TEST_RESULT] = MNL_TYPE_NESTED
};
static const enum mnl_attr_data_type
@@ -1401,6 +1404,19 @@ static struct str_num_map port_fn_opstate_map[] = {
{ .str = NULL, }
};
+static int selftests_get(const char *testname, uint32_t *mask)
+{
+ if (strcmp(testname, "flash") == 0) {
+ *mask |= DEVLINK_SELFTEST_FLASH;
+ } else if (strcmp(testname, "all") == 0) {
+ *mask = DEVLINK_SELFTESTS_MASK;
+ } else {
+ pr_err("Unknown selftest \"%s\"\n", testname);
+ return -EINVAL;
+ }
+ return 0;
+}
+
static int port_flavour_parse(const char *flavour, uint16_t *value)
{
int num;
@@ -1490,6 +1506,7 @@ static const struct dl_args_metadata dl_args_required[] = {
{DL_OPT_PORT_FUNCTION_HW_ADDR, "Port function's hardware address is expected."},
{DL_OPT_PORT_FLAVOUR, "Port flavour is expected."},
{DL_OPT_PORT_PFNUMBER, "Port PCI PF number is expected."},
+ {DL_OPT_SELFTESTS, "Test name is expected"},
};
static int dl_args_finding_required_validate(uint64_t o_required,
@@ -1793,6 +1810,20 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
return err;
o_found |= DL_OPT_FLASH_OVERWRITE;
+ } else if (dl_argv_match(dl, "test") &&
+ (o_all & DL_OPT_SELFTESTS)) {
+ const char *testname;
+
+ dl_arg_inc(dl);
+ err = dl_argv_str(dl, &testname);
+ if (err)
+ return err;
+ err = selftests_get(testname,
+ &opts->selftests_mask);
+ if (err)
+ return err;
+ o_found |= DL_OPT_SELFTESTS;
+
} else if (dl_argv_match(dl, "reporter") &&
(o_all & DL_OPT_HEALTH_REPORTER_NAME)) {
dl_arg_inc(dl);
@@ -2063,6 +2094,17 @@ dl_reload_limits_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
mnl_attr_put(nlh, DEVLINK_ATTR_RELOAD_LIMITS, sizeof(limits), &limits);
}
+static void
+dl_selftests_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
+{
+ uint32_t selftests_mask;
+
+ selftests_mask = opts->selftests_mask;
+
+ mnl_attr_put(nlh, DEVLINK_ATTR_SELFTESTS_MASK,
+ sizeof(selftests_mask), &selftests_mask);
+}
+
static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
{
struct dl_opts *opts = &dl->opts;
@@ -2157,6 +2199,8 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
opts->flash_component);
if (opts->present & DL_OPT_FLASH_OVERWRITE)
dl_flash_update_overwrite_put(nlh, opts);
+ if (opts->present & DL_OPT_SELFTESTS)
+ dl_selftests_put(nlh, opts);
if (opts->present & DL_OPT_HEALTH_REPORTER_NAME)
mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME,
opts->reporter_name);
@@ -2285,6 +2329,8 @@ static void cmd_dev_help(void)
pr_err(" [ action { driver_reinit | fw_activate } ] [ limit no_reset ]\n");
pr_err(" devlink dev info [ DEV ]\n");
pr_err(" devlink dev flash DEV file PATH [ component NAME ] [ overwrite SECTION ]\n");
+ pr_err(" devlink dev selftests show DEV\n");
+ pr_err(" devlink dev selftests run DEV test { TESTNAME | all }\n");
}
static bool cmp_arr_last_handle(struct dl *dl, const char *bus_name,
@@ -3904,6 +3950,150 @@ err_socket:
return err;
}
+static int cmd_dev_selftests_show_tests(const struct nlmsghdr *nlh, void *data)
+{
+ struct nlattr *version;
+ struct dl *dl = data;
+ int avail = 0;
+
+ mnl_attr_for_each(version, nlh, sizeof(struct genlmsghdr)) {
+ int type = mnl_attr_get_type(version);
+
+ if (type == DEVLINK_ATTR_BUS_NAME || type == DEVLINK_ATTR_DEV_NAME)
+ continue;
+
+ if (type != DEVLINK_ATTR_TEST_NAME)
+ return MNL_CB_ERROR;
+
+ if (!avail) {
+ pr_out_object_start(dl, "supported selftests");
+ avail = 1;
+ }
+
+ check_indent_newline(dl);
+ print_string(PRINT_ANY, NULL, "%s", mnl_attr_get_str(version));
+ if (!dl->json_output)
+ __pr_out_newline();
+ }
+
+ if (avail)
+ pr_out_object_end(dl);
+
+ return MNL_CB_OK;
+}
+
+static const char *selftest_result_to_str(uint8_t res)
+{
+ switch (res) {
+ case DEVLINK_SELFTEST_SKIP:
+ return "skipped";
+ case DEVLINK_SELFTEST_PASS:
+ return "passed";
+ case DEVLINK_SELFTEST_FAIL:
+ return "failed";
+ default:
+ return "unknown";
+ }
+}
+
+static int cmd_dev_selftests_result_show(const struct nlmsghdr *nlh, void *data)
+{
+ struct nlattr *version;
+ struct dl *dl = data;
+ int avail = 0;
+
+ mnl_attr_for_each(version, nlh, sizeof(struct genlmsghdr)) {
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+ int type = mnl_attr_get_type(version);
+ const char *test_name;
+ const char *test_res;
+ uint8_t res_val;
+ int err;
+
+ if (type == DEVLINK_ATTR_BUS_NAME || type == DEVLINK_ATTR_DEV_NAME)
+ continue;
+
+ if (type != DEVLINK_ATTR_TEST_RESULT)
+ return MNL_CB_ERROR;
+
+ err = mnl_attr_parse_nested(version, attr_cb, tb);
+ if (err != MNL_CB_OK)
+ return MNL_CB_ERROR;
+
+ if (!tb[DEVLINK_ATTR_TEST_NAME] ||
+ !tb[DEVLINK_ATTR_TEST_RESULT_VAL])
+ return MNL_CB_ERROR;
+
+ if (!avail) {
+ pr_out_object_start(dl, "selftests results");
+ avail = 1;
+ }
+
+ test_name = mnl_attr_get_str(tb[DEVLINK_ATTR_TEST_NAME]);
+ res_val = mnl_attr_get_u8(tb[DEVLINK_ATTR_TEST_RESULT_VAL]);
+ test_res = selftest_result_to_str(res_val);
+
+ check_indent_newline(dl);
+ print_string_name_value(test_name, test_res);
+ if (!dl->json_output)
+ __pr_out_newline();
+ }
+
+ if (avail)
+ pr_out_object_end(dl);
+
+ return MNL_CB_OK;
+}
+
+static int cmd_dev_selftests_run(struct dl *dl)
+{
+ struct nlmsghdr *nlh;
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
+ int err;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SELFTESTS_RUN, flags);
+
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_SELFTESTS, 0);
+ if (err)
+ return err;
+
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_selftests_result_show, dl);
+ return err;
+}
+
+static int cmd_dev_selftests_show(struct dl *dl)
+{
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
+ struct nlmsghdr *nlh;
+ int err;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SELFTESTS_SHOW, flags);
+
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
+ if (err)
+ return err;
+
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_selftests_show_tests, dl);
+ return err;
+}
+
+static int cmd_dev_selftests(struct dl *dl)
+{
+ if (dl_argv_match(dl, "help")) {
+ cmd_dev_help();
+ return 0;
+ } else if (dl_argv_match(dl, "show") ||
+ dl_argv_match(dl, "list") || dl_no_arg(dl)) {
+ dl_arg_inc(dl);
+ return cmd_dev_selftests_show(dl);
+ } else if (dl_argv_match(dl, "run")) {
+ dl_arg_inc(dl);
+ return cmd_dev_selftests_run(dl);
+ }
+ pr_err("Command \"%s\" not found\n", dl_argv(dl));
+ return -ENOENT;
+}
+
static int cmd_dev(struct dl *dl)
{
if (dl_argv_match(dl, "help")) {
@@ -3928,6 +4118,9 @@ static int cmd_dev(struct dl *dl)
} else if (dl_argv_match(dl, "flash")) {
dl_arg_inc(dl);
return cmd_dev_flash(dl);
+ } else if (dl_argv_match(dl, "selftests")) {
+ dl_arg_inc(dl);
+ return cmd_dev_selftests(dl);
}
pr_err("Command \"%s\" not found\n", dl_argv(dl));
return -ENOENT;
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v2 3/3] devlink : update man page for new commands
2022-07-07 18:31 ` [PATCH iproute2-next v2 0/3] " Vikas Gupta
2022-07-07 18:31 ` [PATCH iproute2-next v2 1/3] devlink: update the devlink.h Vikas Gupta
2022-07-07 18:31 ` [PATCH iproute2-next v2 2/3] devlink: add support for running selftests Vikas Gupta
@ 2022-07-07 18:31 ` Vikas Gupta
2022-07-10 8:56 ` [PATCH iproute2-next v2 0/3] devlink: add support to run selftests Ido Schimmel
2022-07-18 6:22 ` [PATCH iproute2-next v3 0/3] devlink: add support to run selftest Vikas Gupta
4 siblings, 0 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-07-07 18:31 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 1861 bytes --]
Update the man page for newly added selftests commands.
Examples:
devlink dev selftests run pci/0000:03:00.0 test flash
devlink dev selftests show pci/0000:03:00.0
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
---
man/man8/devlink-dev.8 | 46 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
index 6906e509..057551a8 100644
--- a/man/man8/devlink-dev.8
+++ b/man/man8/devlink-dev.8
@@ -85,6 +85,16 @@ devlink-dev \- devlink device configuration
.I ID
]
+.ti -8
+.B devlink dev selftests show
+.I DEV
+
+.ti -8
+.B devlink dev selftests run
+.I DEV
+.B test
+.I TESTNAME
+
.SH "DESCRIPTION"
.SS devlink dev show - display devlink device attributes
@@ -249,6 +259,32 @@ should match the component names from
.B "devlink dev info"
and may be driver-dependent.
+.SS devlink dev selftests show - shows supported selftests on devlink device.
+
+.PP
+.I "DEV"
+- specifies the devlink device.
+
+.SS devlink dev selftests run - runs selftests on devlink device.
+
+.PP
+.I "DEV"
+- specifies the devlink device to execute selftests.
+
+.B test
+{
+.BI " TESTNAME "
+|
+.B " all "
+}
+- The value of
+.I TESTNAME
+should match the test names from
+.B "devlink dev selftests show".
+OR Pass option
+.B "all"
+to execute all the selftests on the devlink device.
+
.SH "EXAMPLES"
.PP
devlink dev show
@@ -296,6 +332,16 @@ Flashing 100%
.br
Flashing done
.RE
+.PP
+devlink dev selftests show pci/0000:01:00.0
+.RS 4
+Shows the supported selftests by the devlink device.
+.RE
+.PP
+devlink dev selftests run pci/0000:01:00.0 test flash
+.RS 4
+Perform a flash test on the devlink device.
+.RE
.SH SEE ALSO
.BR devlink (8),
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH iproute2-next v2 0/3] devlink: add support to run selftests
2022-07-07 18:31 ` [PATCH iproute2-next v2 0/3] " Vikas Gupta
` (2 preceding siblings ...)
2022-07-07 18:31 ` [PATCH iproute2-next v2 3/3] devlink : update man page for new commands Vikas Gupta
@ 2022-07-10 8:56 ` Ido Schimmel
2022-07-18 6:22 ` [PATCH iproute2-next v3 0/3] devlink: add support to run selftest Vikas Gupta
4 siblings, 0 replies; 13+ messages in thread
From: Ido Schimmel @ 2022-07-10 8:56 UTC (permalink / raw)
To: Vikas Gupta
Cc: jiri, dsahern, stephen, kuba, netdev, edumazet, michael.chan,
andrew.gospodarek
On Fri, Jul 08, 2022 at 12:01:13AM +0530, Vikas Gupta wrote:
> devlink/devlink.c | 193 +++++++++++++++++++++++++++++++++++
> include/uapi/linux/devlink.h | 26 +++++
> man/man8/devlink-dev.8 | 46 +++++++++
> 3 files changed, 265 insertions(+)
What about bash completion [1]?
[1] https://lore.kernel.org/netdev/Yrw5d9jqe8%2FJCIbj@shredder/
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v3 0/3] devlink: add support to run selftest
2022-07-07 18:31 ` [PATCH iproute2-next v2 0/3] " Vikas Gupta
` (3 preceding siblings ...)
2022-07-10 8:56 ` [PATCH iproute2-next v2 0/3] devlink: add support to run selftests Ido Schimmel
@ 2022-07-18 6:22 ` Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 1/3] devlink: update the devlink.h Vikas Gupta
` (2 more replies)
4 siblings, 3 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-07-18 6:22 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 1121 bytes --]
Hi,
This patchset adds support in devlink to run selftests.
A related patchset for kernel has been pushed for review.
Below are the few examples for the commands.
Examples:
$ devlink dev selftests run pci/0000:03:00.0 test flash
pci/0000:03:00.0
flash failed
$ devlink dev selftests show pci/0000:03:00.0
pci/0000:03:00.0
flash
changes from:
v2->v3
a) Update the implementation of commands according to
the latest patch set of kernel devlink patch.
b) Added bash-completion.
v1->v2
a) Changes required to implement command due to changes
in kernel patch (under review).
b) Added commands descriptions in devlink-dev man page.
Thanks,
Vikas
Vikas Gupta (3):
devlink: update the devlink.h
devlink: add support for running selftests
devlink : update man page and bash-completion for new commands
bash-completion/devlink | 21 ++-
devlink/devlink.c | 292 +++++++++++++++++++++++++++++++++++
include/uapi/linux/devlink.h | 29 ++++
man/man8/devlink-dev.8 | 47 ++++++
4 files changed, 388 insertions(+), 1 deletion(-)
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v3 1/3] devlink: update the devlink.h
2022-07-18 6:22 ` [PATCH iproute2-next v3 0/3] devlink: add support to run selftest Vikas Gupta
@ 2022-07-18 6:22 ` Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 2/3] devlink: add support for running selftests Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 3/3] devlink : update man page and bash-completion for new commands Vikas Gupta
2 siblings, 0 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-07-18 6:22 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 2068 bytes --]
update the devlink.h to comaptible with net-next kernel.
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
---
include/uapi/linux/devlink.h | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index da0f1ba8..efa8af0e 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -136,6 +136,9 @@ enum devlink_command {
DEVLINK_CMD_LINECARD_NEW,
DEVLINK_CMD_LINECARD_DEL,
+ DEVLINK_CMD_SELFTESTS_LIST, /* can dump */
+ DEVLINK_CMD_SELFTESTS_RUN,
+
/* add new commands above here */
__DEVLINK_CMD_MAX,
DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
@@ -276,6 +279,31 @@ enum {
#define DEVLINK_SUPPORTED_FLASH_OVERWRITE_SECTIONS \
(_BITUL(__DEVLINK_FLASH_OVERWRITE_MAX_BIT) - 1)
+/* Commonly used test cases */
+enum devlink_selftest_attr {
+ DEVLINK_SELFTEST_ATTR_UNSPEC,
+ DEVLINK_SELFTEST_ATTR_FLASH, /* flag */
+
+ __DEVLINK_SELFTEST_ATTR_MAX,
+ DEVLINK_SELFTEST_ATTR_MAX = __DEVLINK_SELFTEST_ATTR_MAX - 1
+};
+
+enum devlink_selftest_result {
+ DEVLINK_SELFTEST_SKIP,
+ DEVLINK_SELFTEST_PASS,
+ DEVLINK_SELFTEST_FAIL
+};
+
+enum devlink_selftest_result_attr {
+ DEVLINK_SELFTEST_ATTR_RESULT_UNSPEC,
+ DEVLINK_SELFTEST_ATTR_RESULT, /* nested */
+ DEVLINK_SELFTEST_ATTR_TEST_ID, /* u32, devlink_selftest_attr */
+ DEVLINK_SELFTEST_ATTR_TEST_STATUS, /* u8, devlink_selftest_result */
+
+ __DEVLINK_SELFTEST_ATTR_RES_MAX,
+ DEVLINK_SELFTEST_ATTR_RES_MAX = __DEVLINK_SELFTEST_ATTR_RES_MAX - 1
+};
+
/**
* enum devlink_trap_action - Packet trap action.
* @DEVLINK_TRAP_ACTION_DROP: Packet is dropped by the device and a copy is not
@@ -576,6 +604,7 @@ enum devlink_attr {
DEVLINK_ATTR_LINECARD_TYPE, /* string */
DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES, /* nested */
+ DEVLINK_ATTR_SELFTESTS_INFO, /* nested */
/* add new attributes above here, update the policy in devlink.c */
__DEVLINK_ATTR_MAX,
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v3 2/3] devlink: add support for running selftests
2022-07-18 6:22 ` [PATCH iproute2-next v3 0/3] devlink: add support to run selftest Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 1/3] devlink: update the devlink.h Vikas Gupta
@ 2022-07-18 6:22 ` Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 3/3] devlink : update man page and bash-completion for new commands Vikas Gupta
2 siblings, 0 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-07-18 6:22 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 11182 bytes --]
Add command and helper APIs to run selfests.
Also add a seltest for flash on the device.
Examples:
$ devlink dev selftests run pci/0000:03:00.0 test flash
pci/0000:03:00.0
flash failed
$ devlink dev selftests show pci/0000:03:00.0
pci/0000:03:00.0
flash
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
---
devlink/devlink.c | 292 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 292 insertions(+)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index ddf430bb..36982332 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -294,6 +294,7 @@ static void ifname_map_free(struct ifname_map *ifname_map)
#define DL_OPT_PORT_FN_RATE_TX_MAX BIT(49)
#define DL_OPT_PORT_FN_RATE_NODE_NAME BIT(50)
#define DL_OPT_PORT_FN_RATE_PARENT BIT(51)
+#define DL_OPT_SELFTESTS BIT(52)
struct dl_opts {
uint64_t present; /* flags of present items */
@@ -344,6 +345,7 @@ struct dl_opts {
uint32_t overwrite_mask;
enum devlink_reload_action reload_action;
enum devlink_reload_limit reload_limit;
+ bool test_ids[DEVLINK_SELFTEST_ATTR_MAX + 1];
uint32_t port_controller;
uint32_t port_sfnumber;
uint16_t port_flavour;
@@ -693,6 +695,7 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
[DEVLINK_ATTR_TRAP_POLICER_ID] = MNL_TYPE_U32,
[DEVLINK_ATTR_TRAP_POLICER_RATE] = MNL_TYPE_U64,
[DEVLINK_ATTR_TRAP_POLICER_BURST] = MNL_TYPE_U64,
+ [DEVLINK_ATTR_SELFTESTS_INFO] = MNL_TYPE_NESTED,
};
static const enum mnl_attr_data_type
@@ -1401,6 +1404,17 @@ static struct str_num_map port_fn_opstate_map[] = {
{ .str = NULL, }
};
+static int selftests_get(const char *testname, bool *test_ids)
+{
+ if (strcmp(testname, "flash") == 0) {
+ test_ids[0] = 1;
+ } else {
+ pr_err("Unknown selftest \"%s\"\n", testname);
+ return -EINVAL;
+ }
+ return 0;
+}
+
static int port_flavour_parse(const char *flavour, uint16_t *value)
{
int num;
@@ -1490,6 +1504,7 @@ static const struct dl_args_metadata dl_args_required[] = {
{DL_OPT_PORT_FUNCTION_HW_ADDR, "Port function's hardware address is expected."},
{DL_OPT_PORT_FLAVOUR, "Port flavour is expected."},
{DL_OPT_PORT_PFNUMBER, "Port PCI PF number is expected."},
+ {DL_OPT_SELFTESTS, "Test name is expected"},
};
static int dl_args_finding_required_validate(uint64_t o_required,
@@ -1793,6 +1808,20 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
return err;
o_found |= DL_OPT_FLASH_OVERWRITE;
+ } else if (dl_argv_match(dl, "test") &&
+ (o_all & DL_OPT_SELFTESTS)) {
+ const char *testname;
+
+ dl_arg_inc(dl);
+ err = dl_argv_str(dl, &testname);
+ if (err)
+ return err;
+ err = selftests_get(testname,
+ opts->test_ids);
+ if (err)
+ return err;
+ o_found |= DL_OPT_SELFTESTS;
+
} else if (dl_argv_match(dl, "reporter") &&
(o_all & DL_OPT_HEALTH_REPORTER_NAME)) {
dl_arg_inc(dl);
@@ -2063,6 +2092,32 @@ dl_reload_limits_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
mnl_attr_put(nlh, DEVLINK_ATTR_RELOAD_LIMITS, sizeof(limits), &limits);
}
+static void
+dl_selftests_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
+{
+ bool test_sel = false;
+ struct nlattr *nest;
+ int test_id;
+
+ nest = mnl_attr_nest_start(nlh, DEVLINK_ATTR_SELFTESTS_INFO);
+
+ for (test_id = 1; test_id < DEVLINK_SELFTEST_ATTR_MAX + 1 &&
+ opts->test_ids[test_id]; test_id++) {
+ if (opts->test_ids[test_id]) {
+ test_sel = true;
+ mnl_attr_put(nlh, test_id, 0, NULL);
+ }
+ }
+
+ /* No test selcted from user, select all */
+ if (!test_sel) {
+ for (test_id = 1; test_id < DEVLINK_SELFTEST_ATTR_MAX + 1; test_id++)
+ mnl_attr_put(nlh, test_id, 0, NULL);
+ }
+
+ mnl_attr_nest_end(nlh, nest);
+}
+
static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
{
struct dl_opts *opts = &dl->opts;
@@ -2157,6 +2212,8 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
opts->flash_component);
if (opts->present & DL_OPT_FLASH_OVERWRITE)
dl_flash_update_overwrite_put(nlh, opts);
+ if (opts->present & DL_OPT_SELFTESTS)
+ dl_selftests_put(nlh, opts);
if (opts->present & DL_OPT_HEALTH_REPORTER_NAME)
mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME,
opts->reporter_name);
@@ -2285,6 +2342,8 @@ static void cmd_dev_help(void)
pr_err(" [ action { driver_reinit | fw_activate } ] [ limit no_reset ]\n");
pr_err(" devlink dev info [ DEV ]\n");
pr_err(" devlink dev flash DEV file PATH [ component NAME ] [ overwrite SECTION ]\n");
+ pr_err(" devlink dev selftests show [DEV]\n");
+ pr_err(" devlink dev selftests run DEV [test TESTNAME ]\n");
}
static bool cmp_arr_last_handle(struct dl *dl, const char *bus_name,
@@ -3904,6 +3963,236 @@ err_socket:
return err;
}
+static const char *devlink_get_selftests_name(int test_id)
+{
+ switch (test_id) {
+ case DEVLINK_SELFTEST_ATTR_FLASH:
+ return "flash";
+ default:
+ return "unknown";
+ }
+}
+
+static const enum mnl_attr_data_type
+devlink_selftests_list_policy[DEVLINK_SELFTEST_ATTR_MAX + 1] = {
+ [DEVLINK_SELFTEST_ATTR_FLASH] = MNL_TYPE_FLAG,
+};
+
+static int selftests_list_attr_cb(const struct nlattr *attr, void *data)
+{
+ const struct nlattr **tb = data;
+ int type;
+
+ if (mnl_attr_type_valid(attr, DEVLINK_SELFTEST_ATTR_MAX) < 0)
+ return MNL_CB_OK;
+
+ type = mnl_attr_get_type(attr);
+ if (mnl_attr_validate(attr, devlink_selftests_list_policy[type]) < 0)
+ return MNL_CB_ERROR;
+
+ tb[type] = attr;
+ return MNL_CB_OK;
+}
+
+static int cmd_dev_selftests_show_tests(const struct nlmsghdr *nlh, void *data)
+{
+ struct nlattr *nla_value[DEVLINK_SELFTEST_ATTR_MAX + 1] = {};
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+ struct dl *dl = data;
+ int avail = 0;
+ int err;
+ int i;
+
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+ !tb[DEVLINK_ATTR_SELFTESTS_INFO])
+ return MNL_CB_ERROR;
+
+ err = mnl_attr_parse_nested(tb[DEVLINK_ATTR_SELFTESTS_INFO],
+ selftests_list_attr_cb, nla_value);
+ if (err != MNL_CB_OK)
+ return MNL_CB_ERROR;
+
+ for (i = 1; i < DEVLINK_SELFTEST_ATTR_MAX + 1; i++) {
+ if (!(nla_value[i]))
+ continue;
+
+ if (!avail) {
+ __pr_out_handle_start(dl, tb, true, false);
+ __pr_out_indent_inc();
+ if (!dl->json_output)
+ __pr_out_newline();
+ avail = 1;
+ }
+
+ check_indent_newline(dl);
+ print_string(PRINT_ANY, NULL, "%s", devlink_get_selftests_name(i));
+ if (!dl->json_output)
+ __pr_out_newline();
+ }
+
+ if (avail) {
+ __pr_out_indent_dec();
+ pr_out_handle_end(dl);
+ }
+
+ return MNL_CB_OK;
+}
+
+static const char *selftest_result_to_str(uint8_t res)
+{
+ switch (res) {
+ case DEVLINK_SELFTEST_SKIP:
+ return "skipped";
+ case DEVLINK_SELFTEST_PASS:
+ return "passed";
+ case DEVLINK_SELFTEST_FAIL:
+ return "failed";
+ default:
+ return "unknown";
+ }
+}
+
+static const enum mnl_attr_data_type
+devlink_selftests_result_policy[DEVLINK_SELFTEST_ATTR_RES_MAX + 1] = {
+ [DEVLINK_SELFTEST_ATTR_RESULT] = MNL_TYPE_NESTED,
+ [DEVLINK_SELFTEST_ATTR_TEST_ID] = MNL_TYPE_U32,
+ [DEVLINK_SELFTEST_ATTR_TEST_STATUS] = MNL_TYPE_U8,
+};
+
+static int selftests_result_attr_cb(const struct nlattr *attr, void *data)
+{
+ const struct nlattr **tb = data;
+ int type;
+
+ if (mnl_attr_type_valid(attr, DEVLINK_SELFTEST_ATTR_RES_MAX) < 0)
+ return MNL_CB_OK;
+
+ type = mnl_attr_get_type(attr);
+ if (mnl_attr_validate(attr, devlink_selftests_result_policy[type]) < 0)
+ return MNL_CB_ERROR;
+
+ tb[type] = attr;
+ return MNL_CB_OK;
+}
+
+static int cmd_dev_selftests_result_show(const struct nlmsghdr *nlh, void *data)
+{
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+ struct nlattr *test_attr;
+ struct dl *dl = data;
+ int avail = 0;
+
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+ !tb[DEVLINK_ATTR_SELFTESTS_INFO])
+ return MNL_CB_ERROR;
+
+ mnl_attr_for_each_nested(test_attr,
+ tb[DEVLINK_ATTR_SELFTESTS_INFO]) {
+ struct nlattr *nla_value[DEVLINK_ATTR_MAX + 1] = {};
+ uint8_t test_res;
+ int test_id;
+ int err;
+
+ err = mnl_attr_parse_nested(test_attr,
+ selftests_result_attr_cb, nla_value);
+ if (err != MNL_CB_OK)
+ return MNL_CB_ERROR;
+
+ if (!nla_value[DEVLINK_SELFTEST_ATTR_TEST_ID] ||
+ !nla_value[DEVLINK_SELFTEST_ATTR_TEST_STATUS])
+ return MNL_CB_ERROR;
+
+ if (!avail) {
+ __pr_out_handle_start(dl, tb, true, false);
+ __pr_out_indent_inc();
+ avail = 1;
+ if (!dl->json_output)
+ __pr_out_newline();
+ }
+
+ test_id = mnl_attr_get_u32(nla_value[DEVLINK_SELFTEST_ATTR_TEST_ID]);
+ test_res = mnl_attr_get_u8(nla_value[DEVLINK_SELFTEST_ATTR_TEST_STATUS]);
+
+ check_indent_newline(dl);
+ print_string_name_value(devlink_get_selftests_name(test_id),
+ selftest_result_to_str(test_res));
+ if (!dl->json_output)
+ __pr_out_newline();
+ }
+
+ if (avail) {
+ __pr_out_indent_dec();
+ pr_out_handle_end(dl);
+ }
+
+ return MNL_CB_OK;
+}
+
+static int cmd_dev_selftests_run(struct dl *dl)
+{
+ struct nlmsghdr *nlh;
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
+ int err;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SELFTESTS_RUN, flags);
+
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SELFTESTS);
+ if (err)
+ return err;
+
+ if (!(dl->opts.present & DL_OPT_SELFTESTS))
+ dl_selftests_put(nlh, &dl->opts);
+
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_selftests_result_show, dl);
+ return err;
+}
+
+static int cmd_dev_selftests_show(struct dl *dl)
+{
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
+ struct nlmsghdr *nlh;
+ int err;
+
+ if (dl_argc(dl) == 0)
+ flags |= NLM_F_DUMP;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_SELFTESTS_LIST, flags);
+
+ if (dl_argc(dl) > 0) {
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
+ if (err)
+ return err;
+ }
+
+ pr_out_section_start(dl, "selftests");
+ err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_dev_selftests_show_tests, dl);
+ pr_out_section_end(dl);
+ return err;
+}
+
+static int cmd_dev_selftests(struct dl *dl)
+{
+ if (dl_argv_match(dl, "help")) {
+ cmd_dev_help();
+ return 0;
+ } else if (dl_argv_match(dl, "show") ||
+ dl_argv_match(dl, "list") || dl_no_arg(dl)) {
+ dl_arg_inc(dl);
+ return cmd_dev_selftests_show(dl);
+ } else if (dl_argv_match(dl, "run")) {
+ dl_arg_inc(dl);
+ return cmd_dev_selftests_run(dl);
+ }
+ pr_err("Command \"%s\" not found\n", dl_argv(dl));
+ return -ENOENT;
+}
+
static int cmd_dev(struct dl *dl)
{
if (dl_argv_match(dl, "help")) {
@@ -3928,6 +4217,9 @@ static int cmd_dev(struct dl *dl)
} else if (dl_argv_match(dl, "flash")) {
dl_arg_inc(dl);
return cmd_dev_flash(dl);
+ } else if (dl_argv_match(dl, "selftests")) {
+ dl_arg_inc(dl);
+ return cmd_dev_selftests(dl);
}
pr_err("Command \"%s\" not found\n", dl_argv(dl));
return -ENOENT;
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH iproute2-next v3 3/3] devlink : update man page and bash-completion for new commands
2022-07-18 6:22 ` [PATCH iproute2-next v3 0/3] devlink: add support to run selftest Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 1/3] devlink: update the devlink.h Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 2/3] devlink: add support for running selftests Vikas Gupta
@ 2022-07-18 6:22 ` Vikas Gupta
2 siblings, 0 replies; 13+ messages in thread
From: Vikas Gupta @ 2022-07-18 6:22 UTC (permalink / raw)
To: jiri, dsahern, stephen
Cc: kuba, netdev, edumazet, michael.chan, andrew.gospodarek,
Vikas Gupta
[-- Attachment #1: Type: text/plain, Size: 2883 bytes --]
Update the man page for newly added selftests commands.
Examples:
devlink dev selftests run pci/0000:03:00.0 test flash
devlink dev selftests show pci/0000:03:00.0
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
---
bash-completion/devlink | 21 +++++++++++++++++-
man/man8/devlink-dev.8 | 47 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/bash-completion/devlink b/bash-completion/devlink
index 361be9fe..d0d13fdf 100644
--- a/bash-completion/devlink
+++ b/bash-completion/devlink
@@ -262,6 +262,25 @@ _devlink_dev_flash()
esac
}
+# Completion for devlink dev selftests
+_devlink_dev_selftests()
+{
+ case "$cword" in
+ 3)
+ COMPREPLY=( $( compgen -W "show run" -- "$cur" ) )
+ return
+ ;;
+ 4)
+ _devlink_direct_complete "dev"
+ return
+ ;;
+ 5)
+ COMPREPLY=( $( compgen -W "test" -- "$cur" ) )
+ return
+ ;;
+ esac
+}
+
# Completion for devlink dev
_devlink_dev()
{
@@ -274,7 +293,7 @@ _devlink_dev()
fi
return
;;
- eswitch|param)
+ eswitch|param|selftests)
_devlink_dev_$command
return
;;
diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
index 6906e509..71a1ef18 100644
--- a/man/man8/devlink-dev.8
+++ b/man/man8/devlink-dev.8
@@ -85,6 +85,20 @@ devlink-dev \- devlink device configuration
.I ID
]
+.ti -8
+.B devlink dev selftests show
+[
+.I DEV
+]
+
+.ti -8
+.B devlink dev selftests run
+.I DEV
+[
+.B test
+.RI "{ " TESTNAME " }"
+]
+
.SH "DESCRIPTION"
.SS devlink dev show - display devlink device attributes
@@ -249,6 +263,29 @@ should match the component names from
.B "devlink dev info"
and may be driver-dependent.
+.SS devlink dev selftests show - shows supported selftests on devlink device.
+
+.PP
+.I "DEV"
+- specifies the devlink device.
+If this argument is omitted selftests for all devlink devices are listed.
+
+.SS devlink dev selftests run - runs selftests on devlink device.
+
+.PP
+.I "DEV"
+- specifies the devlink device to execute selftests.
+
+.B test
+{
+.RI { " TESTNAME " }
+}
+- The value of
+.I TESTNAME
+should match the test names from
+.B "devlink dev selftests show".
+to execute all the selftests on the devlink device.
+
.SH "EXAMPLES"
.PP
devlink dev show
@@ -296,6 +333,16 @@ Flashing 100%
.br
Flashing done
.RE
+.PP
+devlink dev selftests show pci/0000:01:00.0
+.RS 4
+Shows the supported selftests by the devlink device.
+.RE
+.PP
+devlink dev selftests run pci/0000:01:00.0 test flash
+.RS 4
+Perform a flash test on the devlink device.
+.RE
.SH SEE ALSO
.BR devlink (8),
--
2.31.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]
^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2022-07-18 6:23 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-28 16:44 [PATCH iproute2-next v1 0/2] devlink: add support to run selftests Vikas Gupta
2022-06-28 16:44 ` [PATCH iproute2-next v1 1/2] Update kernel header Vikas Gupta
2022-06-28 16:44 ` [PATCH iproute2-next v1 2/2] devlink: add support for running selftests Vikas Gupta
2022-06-29 11:37 ` [PATCH iproute2-next v1 0/2] devlink: add support to run selftests Ido Schimmel
2022-07-07 18:31 ` [PATCH iproute2-next v2 0/3] " Vikas Gupta
2022-07-07 18:31 ` [PATCH iproute2-next v2 1/3] devlink: update the devlink.h Vikas Gupta
2022-07-07 18:31 ` [PATCH iproute2-next v2 2/3] devlink: add support for running selftests Vikas Gupta
2022-07-07 18:31 ` [PATCH iproute2-next v2 3/3] devlink : update man page for new commands Vikas Gupta
2022-07-10 8:56 ` [PATCH iproute2-next v2 0/3] devlink: add support to run selftests Ido Schimmel
2022-07-18 6:22 ` [PATCH iproute2-next v3 0/3] devlink: add support to run selftest Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 1/3] devlink: update the devlink.h Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 2/3] devlink: add support for running selftests Vikas Gupta
2022-07-18 6:22 ` [PATCH iproute2-next v3 3/3] devlink : update man page and bash-completion for new commands Vikas Gupta
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).