From patchwork Tue Jun 28 16:44:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikas Gupta X-Patchwork-Id: 12898571 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D38BC433EF for ; Tue, 28 Jun 2022 16:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233472AbiF1Quv (ORCPT ); Tue, 28 Jun 2022 12:50:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239258AbiF1Qrz (ORCPT ); Tue, 28 Jun 2022 12:47:55 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5BF763FD for ; Tue, 28 Jun 2022 09:45:01 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id x138so9842100pfc.3 for ; Tue, 28 Jun 2022 09:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=diaLOWfqH70m/oNEk8XGs5SC46ekZdW7Tharnp3vSAc=; b=AE8KY4OS+VV0NeMKe0kTsCljtao8pDF3Ub3p2AawYbNFE4Vxn3XBgMhY+507cKLRYj 8LETLwkfheJPJXwbgOsy4R8vQSVZHjmPMTFSTy0IMPwG/YEk/2eSn2LDEmBVasVPFIkg 5Nsbq0CLfM0BPtavtEefuvMHvCuIlk0ddG9rg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=diaLOWfqH70m/oNEk8XGs5SC46ekZdW7Tharnp3vSAc=; b=qRZCUDk72yEW7iu52cuThiCYwJKKWq1gBWSEyVF7DQwrxpL694U8bZNRSQ9hPA01My 8xwmMSBXlJSzMFACubXm/sF63fsPE9BuN4K0CAwbb8ATVovGZvfN+PJqU4Ovnma1WV4E oFLmwf9Q6LDOcHX1MDQ6maoRC57k5gf9etXVmd9gncPbrnrzLxEATxEwQjUsTnFYkv/5 pfRd0CcUwSY1K+2f9b3QJrxqAZaI5nwKJ5av4STQwczXSLQf2JKVDGRElgDvdI0MAaDn BG45DloSjdm58b0D1XW+WS/blMgshkLQ/RDErjaClJMxB/IzXj2tL5EY2dmytT+Nkw9+ IA4Q== X-Gm-Message-State: AJIora+yISvHCwgfgo60mtNdkh/S+fAornn5a17yrN/sulEX9FRcMSvI 3Ak/VFCxfg9e5aSlrYWFTFdiYg== X-Google-Smtp-Source: AGRyM1uXElI8EURNfKfPjeapOAC1GvrGlL3XQkTxKDV9TsxSEdBWeed57dxZVLoJtkI2Efyx/ExUgQ== X-Received: by 2002:a63:494:0:b0:40d:9ebf:6e86 with SMTP id 142-20020a630494000000b0040d9ebf6e86mr18856201pge.253.1656434701207; Tue, 28 Jun 2022 09:45:01 -0700 (PDT) Received: from rahul_yocto_ubuntu18.ibn.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id cb14-20020a056a00430e00b0051bbe085f16sm9630866pfb.104.2022.06.28.09.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 09:45:00 -0700 (PDT) From: Vikas Gupta To: jiri@nvidia.com, dsahern@kernel.org, stephen@networkplumber.org Cc: kuba@kernel.org, netdev@vger.kernel.org, edumazet@google.com, michael.chan@broadcom.com, andrew.gospodarek@broadcom.com, Vikas Gupta Subject: [PATCH iproute2-next v1 1/2] Update kernel header Date: Tue, 28 Jun 2022 22:14:46 +0530 Message-Id: <20220628164447.45202-2-vikas.gupta@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220628164447.45202-1-vikas.gupta@broadcom.com> References: <20220628164447.45202-1-vikas.gupta@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Signed-off-by: Vikas Gupta --- 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, From patchwork Tue Jun 28 16:44:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikas Gupta X-Patchwork-Id: 12898570 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0780ECCA47E for ; Tue, 28 Jun 2022 16:50:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232533AbiF1Qur (ORCPT ); Tue, 28 Jun 2022 12:50:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239619AbiF1QsC (ORCPT ); Tue, 28 Jun 2022 12:48:02 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B862AC67 for ; Tue, 28 Jun 2022 09:45:05 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id 184so12699551pga.12 for ; Tue, 28 Jun 2022 09:45:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SgJi6HSRfulEjVLhuwzr6sRMTQYrmglBqBwGYR1LzqU=; b=A6SnXln0ApqsIbpcBxBpUewKg4JGRH8vBhO4xil4qje8ns4FG1slYB2U7lXl/DZV9U so/8dz7QHgQFjihT79tJWUX6bdG/V9H7aK/FjFmDpkUHeoMVmqHgpD4Yl5wNluJyo1ia mfFKCW/vrwAJmUrLLZX3PmLcH8ArO2T2UerwI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SgJi6HSRfulEjVLhuwzr6sRMTQYrmglBqBwGYR1LzqU=; b=ekArz2/9L4GN7ZUSaVxHNr3aph3Uuqt27v/tQnNz3bnrAgYJPM3SAHczFyuocQfIJ0 Fk5mgpJ9Sjg12eML1XIIZc/uuLNHje2EJPfY7lk6XlSW4ukW9K14NWY9GS/UKvLfBW2u hY/TP/0SV0vGPD1PJF2raHzDnJz2G+z1gENDNrJqChrZIml55LANLqDAycpzGTN4LEan ZJshScDXKPm5pxuQ1lry8odjCa1prqYd2bnWdFki+Kd87D5rusUStxCqJ92sw9PadLd+ y9FVfRZZ32i5ZuGWa23Yc97+GPPDWHXHZgS8oY5eTBWvDV7WCQ2v48TlCUiPY+ruSAbc vp5g== X-Gm-Message-State: AJIora9f9aqCaj1lLxigZk3d9fxYpozX9ASiCVAgTVExPnJGdJ6MSa4Z 8mCmIZuUZdSQDMKbc396v+icbQ== X-Google-Smtp-Source: AGRyM1sHBmQkr6yDLMWd/GA+NEBcITdCLLgd2hkYzJHTQpIfX1nR3rvAbs3uYK/aJNFPEm3sOzVmEg== X-Received: by 2002:a63:4d5:0:b0:40d:77fd:cff8 with SMTP id 204-20020a6304d5000000b0040d77fdcff8mr18204748pge.361.1656434704611; Tue, 28 Jun 2022 09:45:04 -0700 (PDT) Received: from rahul_yocto_ubuntu18.ibn.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id cb14-20020a056a00430e00b0051bbe085f16sm9630866pfb.104.2022.06.28.09.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 09:45:03 -0700 (PDT) From: Vikas Gupta To: jiri@nvidia.com, dsahern@kernel.org, stephen@networkplumber.org Cc: kuba@kernel.org, netdev@vger.kernel.org, edumazet@google.com, michael.chan@broadcom.com, andrew.gospodarek@broadcom.com, Vikas Gupta Subject: [PATCH iproute2-next v1 2/2] devlink: add support for running selftests Date: Tue, 28 Jun 2022 22:14:47 +0530 Message-Id: <20220628164447.45202-3-vikas.gupta@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220628164447.45202-1-vikas.gupta@broadcom.com> References: <20220628164447.45202-1-vikas.gupta@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com 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 --- 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;