From patchwork Thu Aug 18 13:00:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12947008 X-Patchwork-Delegate: kuba@kernel.org 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 1A26DC00140 for ; Thu, 18 Aug 2022 13:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244856AbiHRNAx (ORCPT ); Thu, 18 Aug 2022 09:00:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244858AbiHRNAs (ORCPT ); Thu, 18 Aug 2022 09:00:48 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4FAE61DA7 for ; Thu, 18 Aug 2022 06:00:46 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id o22so1769033edc.10 for ; Thu, 18 Aug 2022 06:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=JuNykuC5qgbCOArm6ZMuGXDf4Qj1U786SQLmL0SdI8I=; b=PhaMQA8y/zl6lpzsAmwhvQNGTgMgNJ4WTzmB7PYx7VR/O24Rq2pJsSXJE1zVKz4DTO MiFWBbicpW5g4XlF9YrjZl+31qLdb7L/m3aOxwv0dOTeTmCelK73Pke3rXNFDispbk14 7Jle/BAdL+Mv4Jpg+zJ+0unM8izbAhxX0y9pcq4AZPPhz92GfTmTB7loJSapD/kxpRaC 8sH3aFz9jxREujXj8T4/qsv9PtUS3o4K7NjIO8XknkzuHrGzyYRHsokCVi0BLqZM8Nqb ebPRkFrVadoEqdQ6DWf+6J4lxKcD0VmpyRsb6qYgNFCF9SGLGHY7/O1HYlWrzgk8ZxOc Vg8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=JuNykuC5qgbCOArm6ZMuGXDf4Qj1U786SQLmL0SdI8I=; b=YDGmxEMEnNImXSfxpcTaMgIu83+ucpzuHdnFiEmh0GClsOvWtBW48/9O+AnORQfvmC uUeoJ+bc+bAu/8OOOae37stMEgD2rcw3ln0u/BTiUII2DEP89074CQv75BwVtL3DySbV 0K7ptrkhD7iIfxyBmlcG9YNXgGpLWD4OxofyNnMi2x5fIqfBc5YawfsT2vXiaQD1vf5H +QQR9wxEFY6pdCbJrRsGO3uUb26ISWXKunP90nGSMNeRDD69OgoozOjEHfNz/ZZbevqs d5CoB8kRQpn+u4d+1bRKCo+VWMfdL89TWlNsKVenLBJKIVwcSG8ZeK3fS2ARub/D74WA MZBQ== X-Gm-Message-State: ACgBeo0BBu6C8oQejwXPfohaxq3gR8zkJBAkahiXC5EiuhIvAxLHpsoE IX2/smWf5ucepHOVc0K82EmPZK6h49qBTsHz X-Google-Smtp-Source: AA6agR6Uyc6GcUn1S/w9tFuVIhDWkmEyz6qtCnqGXXgfi/RNCob4UOGQHmWSYpikPiv4ir8MHKrnWQ== X-Received: by 2002:a05:6402:94f:b0:445:e951:be6e with SMTP id h15-20020a056402094f00b00445e951be6emr2109043edz.112.1660827645060; Thu, 18 Aug 2022 06:00:45 -0700 (PDT) Received: from localhost ([86.61.181.4]) by smtp.gmail.com with ESMTPSA id h10-20020aa7c60a000000b0043cc2c9f5adsm1128265edq.40.2022.08.18.06.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 06:00:44 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, idosch@nvidia.com, pabeni@redhat.com, edumazet@google.com, saeedm@nvidia.com, jacob.e.keller@intel.com, vikas.gupta@broadcom.com, gospo@broadcom.com Subject: [patch net-next 1/4] net: devlink: extend info_get() version put to indicate a flash component Date: Thu, 18 Aug 2022 15:00:39 +0200 Message-Id: <20220818130042.535762-2-jiri@resnulli.us> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220818130042.535762-1-jiri@resnulli.us> References: <20220818130042.535762-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Limit the acceptance of component name passed to cmd_flash_update() to match one of the versions returned by info_get(), marked by version type. This makes things clearer and enforces 1:1 mapping between exposed version and accepted flash component. Whenever the driver is called by his info_get() op, it may put multiple version names and values to the netlink message. Extend by additional helper devlink_info_version_running_put_ext() that allows to specify a version type that indicates when particular version name represents a flash component. Use this indication during cmd_flash_update() execution by calling info_get() with different "req" context. That causes info_get() to lookup the component name instead of filling-up the netlink message. Fix the only component user which is netdevsim. It uses component named "fw.mgmt" in selftests. Remove now outdated "UPDATE_COMPONENT" flag. Signed-off-by: Jiri Pirko --- drivers/net/netdevsim/dev.c | 12 +++- include/net/devlink.h | 15 ++++- net/core/devlink.c | 128 ++++++++++++++++++++++++++++++------ 3 files changed, 129 insertions(+), 26 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index e88f783c297e..cea130490dea 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -984,7 +984,14 @@ static int nsim_dev_info_get(struct devlink *devlink, struct devlink_info_req *req, struct netlink_ext_ack *extack) { - return devlink_info_driver_name_put(req, DRV_NAME); + int err; + + err = devlink_info_driver_name_put(req, DRV_NAME); + if (err) + return err; + + return devlink_info_version_running_put_ext(req, "fw.mgmt", "10.20.30", + DEVLINK_INFO_VERSION_TYPE_COMPONENT); } #define NSIM_DEV_FLASH_SIZE 500000 @@ -1312,8 +1319,7 @@ nsim_dev_devlink_trap_drop_counter_get(struct devlink *devlink, static const struct devlink_ops nsim_dev_devlink_ops = { .eswitch_mode_set = nsim_devlink_eswitch_mode_set, .eswitch_mode_get = nsim_devlink_eswitch_mode_get, - .supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT | - DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK, + .supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK, .reload_actions = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT), .reload_down = nsim_dev_reload_down, .reload_up = nsim_dev_reload_up, diff --git a/include/net/devlink.h b/include/net/devlink.h index 119ed1ffb988..9bf4f03feca6 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -624,8 +624,7 @@ struct devlink_flash_update_params { u32 overwrite_mask; }; -#define DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT BIT(0) -#define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK BIT(1) +#define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK BIT(0) struct devlink_region; struct devlink_info_req; @@ -1714,6 +1713,14 @@ int devlink_info_driver_name_put(struct devlink_info_req *req, const char *name); int devlink_info_board_serial_number_put(struct devlink_info_req *req, const char *bsn); + +enum devlink_info_version_type { + DEVLINK_INFO_VERSION_TYPE_NONE, + DEVLINK_INFO_VERSION_TYPE_COMPONENT, /* May be used as flash update + * component by name. + */ +}; + int devlink_info_version_fixed_put(struct devlink_info_req *req, const char *version_name, const char *version_value); @@ -1723,6 +1730,10 @@ int devlink_info_version_stored_put(struct devlink_info_req *req, int devlink_info_version_running_put(struct devlink_info_req *req, const char *version_name, const char *version_value); +int devlink_info_version_running_put_ext(struct devlink_info_req *req, + const char *version_name, + const char *version_value, + enum devlink_info_version_type version_type); int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg); int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg); diff --git a/net/core/devlink.c b/net/core/devlink.c index b50bcc18b8d9..17b78123ad9d 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -4742,10 +4742,76 @@ void devlink_flash_update_timeout_notify(struct devlink *devlink, } EXPORT_SYMBOL_GPL(devlink_flash_update_timeout_notify); +struct devlink_info_req { + struct sk_buff *msg; + void (*version_cb)(const char *version_name, + enum devlink_info_version_type version_type, + void *version_cb_priv); + void *version_cb_priv; +}; + +struct devlink_flash_component_lookup_ctx { + const char *lookup_name; + bool lookup_name_found; +}; + +static void +devlink_flash_component_lookup_cb(const char *version_name, + enum devlink_info_version_type version_type, + void *version_cb_priv) +{ + struct devlink_flash_component_lookup_ctx *lookup_ctx = version_cb_priv; + + if (version_type != DEVLINK_INFO_VERSION_TYPE_COMPONENT || + lookup_ctx->lookup_name_found) + return; + + lookup_ctx->lookup_name_found = + !strcmp(lookup_ctx->lookup_name, version_name); +} + +static int devlink_flash_component_get(struct devlink *devlink, + struct nlattr *nla_component, + const char **p_component, + struct netlink_ext_ack *extack) +{ + struct devlink_flash_component_lookup_ctx lookup_ctx = {}; + struct devlink_info_req req = {}; + const char *component; + int ret; + + if (!nla_component) + return 0; + + component = nla_data(nla_component); + + if (!devlink->ops->info_get) { + NL_SET_ERR_MSG_ATTR(extack, nla_component, + "component update is not supported by this device"); + return -EOPNOTSUPP; + } + + lookup_ctx.lookup_name = component; + req.version_cb = devlink_flash_component_lookup_cb; + req.version_cb_priv = &lookup_ctx; + + ret = devlink->ops->info_get(devlink, &req, NULL); + if (ret) + return ret; + + if (!lookup_ctx.lookup_name_found) { + NL_SET_ERR_MSG_ATTR(extack, nla_component, + "selected component is not supported by this device"); + return -EINVAL; + } + *p_component = component; + return 0; +} + static int devlink_nl_cmd_flash_update(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *nla_component, *nla_overwrite_mask, *nla_file_name; + struct nlattr *nla_overwrite_mask, *nla_file_name; struct devlink_flash_update_params params = {}; struct devlink *devlink = info->user_ptr[0]; const char *file_name; @@ -4758,17 +4824,13 @@ static int devlink_nl_cmd_flash_update(struct sk_buff *skb, if (!info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME]) return -EINVAL; - supported_params = devlink->ops->supported_flash_update_params; + ret = devlink_flash_component_get(devlink, + info->attrs[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT], + ¶ms.component, info->extack); + if (ret) + return ret; - nla_component = info->attrs[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]; - if (nla_component) { - if (!(supported_params & DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT)) { - NL_SET_ERR_MSG_ATTR(info->extack, nla_component, - "component update is not supported by this device"); - return -EOPNOTSUPP; - } - params.component = nla_data(nla_component); - } + supported_params = devlink->ops->supported_flash_update_params; nla_overwrite_mask = info->attrs[DEVLINK_ATTR_FLASH_UPDATE_OVERWRITE_MASK]; if (nla_overwrite_mask) { @@ -6553,18 +6615,18 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb, return err; } -struct devlink_info_req { - struct sk_buff *msg; -}; - int devlink_info_driver_name_put(struct devlink_info_req *req, const char *name) { + if (!req->msg) + return 0; return nla_put_string(req->msg, DEVLINK_ATTR_INFO_DRIVER_NAME, name); } EXPORT_SYMBOL_GPL(devlink_info_driver_name_put); int devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn) { + if (!req->msg) + return 0; return nla_put_string(req->msg, DEVLINK_ATTR_INFO_SERIAL_NUMBER, sn); } EXPORT_SYMBOL_GPL(devlink_info_serial_number_put); @@ -6572,6 +6634,8 @@ EXPORT_SYMBOL_GPL(devlink_info_serial_number_put); int devlink_info_board_serial_number_put(struct devlink_info_req *req, const char *bsn) { + if (!req->msg) + return 0; return nla_put_string(req->msg, DEVLINK_ATTR_INFO_BOARD_SERIAL_NUMBER, bsn); } @@ -6579,11 +6643,19 @@ EXPORT_SYMBOL_GPL(devlink_info_board_serial_number_put); static int devlink_info_version_put(struct devlink_info_req *req, int attr, const char *version_name, - const char *version_value) + const char *version_value, + enum devlink_info_version_type version_type) { struct nlattr *nest; int err; + if (req->version_cb) + req->version_cb(version_name, version_type, + req->version_cb_priv); + + if (!req->msg) + return 0; + nest = nla_nest_start_noflag(req->msg, attr); if (!nest) return -EMSGSIZE; @@ -6612,7 +6684,8 @@ int devlink_info_version_fixed_put(struct devlink_info_req *req, const char *version_value) { return devlink_info_version_put(req, DEVLINK_ATTR_INFO_VERSION_FIXED, - version_name, version_value); + version_name, version_value, + DEVLINK_INFO_VERSION_TYPE_NONE); } EXPORT_SYMBOL_GPL(devlink_info_version_fixed_put); @@ -6621,7 +6694,8 @@ int devlink_info_version_stored_put(struct devlink_info_req *req, const char *version_value) { return devlink_info_version_put(req, DEVLINK_ATTR_INFO_VERSION_STORED, - version_name, version_value); + version_name, version_value, + DEVLINK_INFO_VERSION_TYPE_NONE); } EXPORT_SYMBOL_GPL(devlink_info_version_stored_put); @@ -6630,16 +6704,28 @@ int devlink_info_version_running_put(struct devlink_info_req *req, const char *version_value) { return devlink_info_version_put(req, DEVLINK_ATTR_INFO_VERSION_RUNNING, - version_name, version_value); + version_name, version_value, + DEVLINK_INFO_VERSION_TYPE_NONE); } EXPORT_SYMBOL_GPL(devlink_info_version_running_put); +int devlink_info_version_running_put_ext(struct devlink_info_req *req, + const char *version_name, + const char *version_value, + enum devlink_info_version_type version_type) +{ + return devlink_info_version_put(req, DEVLINK_ATTR_INFO_VERSION_RUNNING, + version_name, version_value, + version_type); +} +EXPORT_SYMBOL_GPL(devlink_info_version_running_put_ext); + static int devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink, enum devlink_command cmd, u32 portid, u32 seq, int flags, struct netlink_ext_ack *extack) { - struct devlink_info_req req; + struct devlink_info_req req = {}; void *hdr; int err; @@ -12306,8 +12392,8 @@ EXPORT_SYMBOL_GPL(devl_trap_policers_unregister); static void __devlink_compat_running_version(struct devlink *devlink, char *buf, size_t len) { + struct devlink_info_req req = {}; const struct nlattr *nlattr; - struct devlink_info_req req; struct sk_buff *msg; int rem, err; From patchwork Thu Aug 18 13:00:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12947007 X-Patchwork-Delegate: kuba@kernel.org 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 5E372C28B2B for ; Thu, 18 Aug 2022 13:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244867AbiHRNAz (ORCPT ); Thu, 18 Aug 2022 09:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244859AbiHRNAs (ORCPT ); Thu, 18 Aug 2022 09:00:48 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02B3E6747A for ; Thu, 18 Aug 2022 06:00:47 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id s11so1766489edd.13 for ; Thu, 18 Aug 2022 06:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=hE3TQw40VsNVsq40Dxz5mY7v5/vs4c2dK5Xb3FNaFbo=; b=VDH52EDGBrXu3+sSPlM683iuH2sZAh5WfORZfl83Vk1m0Enuun2Lx8sSGmaF1u4P7S IHOEZON4zescv6Y0/xvWEHhXuzetTexO/I6Dt+c0O76Z3uDyyarVfnrxx8elq7kS48mg S63t95goOAJ8NVvL8WZLOsGlhkVfbmts4bsc5dh1BPaWIZkscdCfwWuNWFjGf757aJSe IYYTYrr9yhU6SLG5NnBIYaQFfUZM3doEmNKehs0OK6deCUhwaDXrWz4ChEb20K+//C2r JMX1LaFf5URqKpuOrbS/RKgUcnyaDc01eaNioWy1v7d+X0RJuoVNKvCgDpFFHg3qahz1 ut9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=hE3TQw40VsNVsq40Dxz5mY7v5/vs4c2dK5Xb3FNaFbo=; b=Jm98WcI9hHFn4ta0Xoh7WqWoW7Jix9qX+U1PbohvBg9qgyHng1tAS0N8jsKMy0PF0R CzTDUPS8YqQupOrYv0AmpJQvqo3glGyZxC+61I1uPDkgRzIEbbx5zJt01Fxs1KPNy6FC hGHspLOFhMx8lUU1KE7ZDNr4F0s7Iz7LKM8AmEL0MhEbuJFgN08aXvqnr6qgGcAPl+wn P9/zPud+VivL4d6uiEQVp/g6MNgcDk7fQYotPdSCec0Z9VEYy1kmQwNp5aBu8e1cr91+ 4d/Pww8q21SdFKCAheyOm3ZGXVQ9jUpu3oUqJIXmHMxY4nGWwkx9x/5P5HiW3f8c/PBf rLkQ== X-Gm-Message-State: ACgBeo3p83onPYWacuwpR4SdSuwJgFBfk5ZRJIfdonPimz9fgo8CPH6C kqv0Z1c9k6TAAR0n+JjGTlDz/DlWwsLKq5M4 X-Google-Smtp-Source: AA6agR4h7TBBeLSXcrmNKJPWdZc4NMVsAyzP2Y4gieIiNvrCqx3nRyaLffY/8pZwJdqqkZtLebv+jA== X-Received: by 2002:a05:6402:4442:b0:43b:c866:21be with SMTP id o2-20020a056402444200b0043bc86621bemr2289102edb.28.1660827646377; Thu, 18 Aug 2022 06:00:46 -0700 (PDT) Received: from localhost ([86.61.181.4]) by smtp.gmail.com with ESMTPSA id bj5-20020a170906b04500b007307c4c8a5dsm813290ejb.58.2022.08.18.06.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 06:00:45 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, idosch@nvidia.com, pabeni@redhat.com, edumazet@google.com, saeedm@nvidia.com, jacob.e.keller@intel.com, vikas.gupta@broadcom.com, gospo@broadcom.com Subject: [patch net-next 2/4] net: devlink: expose the info about version representing a component Date: Thu, 18 Aug 2022 15:00:40 +0200 Message-Id: <20220818130042.535762-3-jiri@resnulli.us> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220818130042.535762-1-jiri@resnulli.us> References: <20220818130042.535762-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko If certain version exposed by a driver is marked to be representing a component, expose this info to the user. Example: $ devlink dev info netdevsim/netdevsim10: driver netdevsim versions: running: fw.mgmt 10.20.30 flash_components: fw.mgmt Signed-off-by: Jiri Pirko --- include/uapi/linux/devlink.h | 2 ++ net/core/devlink.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 2f24b53a87a5..7f2874189188 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -607,6 +607,8 @@ enum devlink_attr { DEVLINK_ATTR_SELFTESTS, /* nested */ + DEVLINK_ATTR_INFO_VERSION_IS_COMPONENT, /* u8 0 or 1 */ + /* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX, diff --git a/net/core/devlink.c b/net/core/devlink.c index 17b78123ad9d..23a5fd92ecaa 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -6670,6 +6670,11 @@ static int devlink_info_version_put(struct devlink_info_req *req, int attr, if (err) goto nla_put_failure; + err = nla_put_u8(req->msg, DEVLINK_ATTR_INFO_VERSION_IS_COMPONENT, + version_type == DEVLINK_INFO_VERSION_TYPE_COMPONENT); + if (err) + goto nla_put_failure; + nla_nest_end(req->msg, nest); return 0; From patchwork Thu Aug 18 13:00:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12947009 X-Patchwork-Delegate: kuba@kernel.org 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 21247C28B2B for ; Thu, 18 Aug 2022 13:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244873AbiHRNA5 (ORCPT ); Thu, 18 Aug 2022 09:00:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244404AbiHRNAu (ORCPT ); Thu, 18 Aug 2022 09:00:50 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FC54647D8 for ; Thu, 18 Aug 2022 06:00:49 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id gb36so3068053ejc.10 for ; Thu, 18 Aug 2022 06:00:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=QxBeqW2Zs3D42dOk1H+4v0ECrd4LauaTQntluiG28Uc=; b=fYaE9oVGcM5AhZNvi63uW8rLjRXX384RnmJrWYUWpZBivwxBMpscjvoFgxTxZ8Y+Ec mMd4V9yQI81jlVUHwglmlBHaCvym0WlL8UcGKPwC6bJ2ftEAl1Sjrde2ANX2Ej9F2D14 UksOtafU4LeNrZVSMLSWpYVnBMtPestdyi7CFUIc6251Yb/5OrhozbcnmUIrLhOlxhW/ J8nH6UgIuCv+ZsMrWAh5cU5uvWlMsSLM8USRVc2Y6Lfj7tzfZ6WWUmM3/i51zSw3iwNj UMTDpOCPYrhxjcI4mhCSkIjO8ce6fgb7Ruzlxqjwf8YhwG95+iBp3CLlYXvUWVdsiHyI ZEJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=QxBeqW2Zs3D42dOk1H+4v0ECrd4LauaTQntluiG28Uc=; b=2fxtZhE0ROJiLed4mSAJPTn2LYWCzeLo+QKtrNJkCZkfal6y47lIi/MQZA0itjp7d7 0LLoeintxh+VW6tA6hSOSZk3bNCYgo812zrU7H3MV8FzmI+wPOLDtM9eMsaw9kiH0Ygd 8/CvfX3zjrnraiMIlBLnPLSo4BDWTFcpWA05CWDNewJEO3D0NypR3iv6ufCDSZRVrTnY JAQAme1u/F/PNBcph+qE5YIcCx5tfdvMMtetA5QXVhkpvQIwwFJ2AtVxOrQsbIKSsUyL GJtyIYCl9Iz3i7hu0OmrtDlK5Y7zt/XpuvLXcfRlqdH4VEQmP3kpdix7oACtKXYsJ+Z2 eC/g== X-Gm-Message-State: ACgBeo0s2GFvLZyDE9sMkEe8yJqgcliIcjVJsoSvWx4/Seat96FbY1i6 OHCdoITDUvS2H78Gil7ljmFj/mVHXxCI2hC+ X-Google-Smtp-Source: AA6agR5+1vZokPOpLcJyPisnq40TZgxZygw8z/Cz6o8QEOo3z87i2c6o38kUXSpiy6FfhTWJx5OEvA== X-Received: by 2002:a17:906:9b09:b0:730:c38c:e11c with SMTP id eo9-20020a1709069b0900b00730c38ce11cmr1786043ejc.684.1660827647691; Thu, 18 Aug 2022 06:00:47 -0700 (PDT) Received: from localhost ([86.61.181.4]) by smtp.gmail.com with ESMTPSA id gg23-20020a170906e29700b00732a5b339afsm828301ejb.92.2022.08.18.06.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 06:00:47 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, idosch@nvidia.com, pabeni@redhat.com, edumazet@google.com, saeedm@nvidia.com, jacob.e.keller@intel.com, vikas.gupta@broadcom.com, gospo@broadcom.com Subject: [patch net-next 3/4] netdevsim: expose version of default flash target Date: Thu, 18 Aug 2022 15:00:41 +0200 Message-Id: <20220818130042.535762-4-jiri@resnulli.us> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220818130042.535762-1-jiri@resnulli.us> References: <20220818130042.535762-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Add version named "fw" to represent version of default flash target. Example: $ devlink dev info netdevsim/netdevsim10: driver netdevsim versions: running: fw.mgmt 10.20.30 fw 11.22.33 flash_components: fw.mgmt Signed-off-by: Jiri Pirko --- drivers/net/netdevsim/dev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index cea130490dea..97281b6aa41f 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -990,8 +990,12 @@ static int nsim_dev_info_get(struct devlink *devlink, if (err) return err; - return devlink_info_version_running_put_ext(req, "fw.mgmt", "10.20.30", - DEVLINK_INFO_VERSION_TYPE_COMPONENT); + err = devlink_info_version_running_put_ext(req, "fw.mgmt", "10.20.30", + DEVLINK_INFO_VERSION_TYPE_COMPONENT); + if (err) + return err; + + return devlink_info_version_running_put(req, "fw", "11.22.33"); } #define NSIM_DEV_FLASH_SIZE 500000 From patchwork Thu Aug 18 13:00:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12947010 X-Patchwork-Delegate: kuba@kernel.org 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 669F7C00140 for ; Thu, 18 Aug 2022 13:01:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244627AbiHRNA7 (ORCPT ); Thu, 18 Aug 2022 09:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244864AbiHRNAw (ORCPT ); Thu, 18 Aug 2022 09:00:52 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC3574BB1 for ; Thu, 18 Aug 2022 06:00:51 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id y13so3053995ejp.13 for ; Thu, 18 Aug 2022 06:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=rkpsaBkB9p4iPG3YdyRDOTbtXlIb/IwRVf73wz/63iQ=; b=GUIu6ExWtv/BdFIeuBJz52vBIRjWCyKD8xI6K7nuOE3r17ZsLUnefpVxErXIJvzHap mdkGad7oZ79yG7eeKhdLMqbokxNJHPXrU3s5ck8hKzLkNY7ylK1vVmfb7CeYUgtp/Eeu 0P2y+/jvk3TShRWSXWXKgmkQd8zQmueXgiSNmwEJx9b8cdJXlMnozuTYmWZGhhMJxt6z 4Ovmt+TN001SsgROJQLnZ7oQDAnXxTlcoIlWbcaiohs6WptsxN89JeW8F6zSpFcRifXi u8YjNsbsiQwTgZ5cWn42ttXa3vcvyGaLk2TKKN/GSaOagICnNj6FeTsqhrCpjM1djxrW xCBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=rkpsaBkB9p4iPG3YdyRDOTbtXlIb/IwRVf73wz/63iQ=; b=0DaDnnz3TEqBllQIub5ORnhmQP3A3QF8vpTHj29dN0Ce0kolcJjik3c7KXk9fk3AJ9 jLLMfFD7G2Q0m7bodH7jrv1BO6hS03NGwS7npw1rwdAGGZq+D/b10cxKDX7ypVfU8wQm gdcdS7KttXvClDfxw8QUZeW3/LZUcFemOLKrpO8XINoIFSwrvSUnkiwDNFSXNfYjjuJo s1OQa02wPnG3lcBMsYJxP4biVL58CUgR8O3l460l9B5jCkGXmx1/TvyYc5C+9GEffyzv 4QEhcNhpxiBYJodwHufh5NvSgb96QSwq1kW2sSTPFhm+HF5KrYKjhJepo5IuEZoV6W7O bLAw== X-Gm-Message-State: ACgBeo0ZEyOO0pp8W5lZ/DF33kf/Jk5sbfdPKaSdZD8AxvVt23ws7Zn2 wx7PVYOmSMzwbds2axdcGndff54D1NRX8qjs X-Google-Smtp-Source: AA6agR4XJOe/rTs+2NXL+Ehba0PfXhNDRFfpqWaKHaYnp4brO3y0XNw083JnGPOtS1NeHBLeqZZsVg== X-Received: by 2002:a17:906:98c9:b0:73c:5d9b:3425 with SMTP id zd9-20020a17090698c900b0073c5d9b3425mr340204ejb.77.1660827649519; Thu, 18 Aug 2022 06:00:49 -0700 (PDT) Received: from localhost ([86.61.181.4]) by smtp.gmail.com with ESMTPSA id c9-20020a17090618a900b007313a25e56esm807987ejf.29.2022.08.18.06.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 06:00:48 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, idosch@nvidia.com, pabeni@redhat.com, edumazet@google.com, saeedm@nvidia.com, jacob.e.keller@intel.com, vikas.gupta@broadcom.com, gospo@broadcom.com Subject: [patch net-next 4/4] net: devlink: expose default flash update target Date: Thu, 18 Aug 2022 15:00:42 +0200 Message-Id: <20220818130042.535762-5-jiri@resnulli.us> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220818130042.535762-1-jiri@resnulli.us> References: <20220818130042.535762-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Allow driver to mark certain version obtained by info_get() op as "flash update default". Expose this information to user which allows him to understand what version is going to be affected if he does flash update without specifying the component. Implement this in netdevsim. Example: $ devlink dev info netdevsim/netdevsim10: driver netdevsim versions: running: fw.mgmt 10.20.30 fw 11.22.33 flash_components: fw.mgmt flash_update_default fw Signed-off-by: Jiri Pirko --- drivers/net/netdevsim/dev.c | 3 ++- include/net/devlink.h | 3 +++ include/uapi/linux/devlink.h | 1 + net/core/devlink.c | 12 ++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 97281b6aa41f..f999b9477a26 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -995,7 +995,8 @@ static int nsim_dev_info_get(struct devlink *devlink, if (err) return err; - return devlink_info_version_running_put(req, "fw", "11.22.33"); + return devlink_info_version_running_put_ext(req, "fw", "11.22.33", + DEVLINK_INFO_VERSION_TYPE_FLASH_UPDATE_DEFAULT); } #define NSIM_DEV_FLASH_SIZE 500000 diff --git a/include/net/devlink.h b/include/net/devlink.h index 9bf4f03feca6..bfe988a56067 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1719,6 +1719,9 @@ enum devlink_info_version_type { DEVLINK_INFO_VERSION_TYPE_COMPONENT, /* May be used as flash update * component by name. */ + DEVLINK_INFO_VERSION_TYPE_FLASH_UPDATE_DEFAULT, /* Is default flash + * update target. + */ }; int devlink_info_version_fixed_put(struct devlink_info_req *req, diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 7f2874189188..01e348177f60 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -608,6 +608,7 @@ enum devlink_attr { DEVLINK_ATTR_SELFTESTS, /* nested */ DEVLINK_ATTR_INFO_VERSION_IS_COMPONENT, /* u8 0 or 1 */ + DEVLINK_ATTR_INFO_VERSION_IS_FLASH_UPDATE_DEFAULT, /* u8 0 or 1 */ /* add new attributes above here, update the policy in devlink.c */ diff --git a/net/core/devlink.c b/net/core/devlink.c index 23a5fd92ecaa..de583fb2ed12 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -4748,6 +4748,7 @@ struct devlink_info_req { enum devlink_info_version_type version_type, void *version_cb_priv); void *version_cb_priv; + unsigned int flash_update_default_count; }; struct devlink_flash_component_lookup_ctx { @@ -6656,6 +6657,12 @@ static int devlink_info_version_put(struct devlink_info_req *req, int attr, if (!req->msg) return 0; + if (version_type == DEVLINK_INFO_VERSION_TYPE_FLASH_UPDATE_DEFAULT) { + if (WARN_ON(req->flash_update_default_count++)) + /* Max one flash update default is allowed. */ + return -EINVAL; + } + nest = nla_nest_start_noflag(req->msg, attr); if (!nest) return -EMSGSIZE; @@ -6675,6 +6682,11 @@ static int devlink_info_version_put(struct devlink_info_req *req, int attr, if (err) goto nla_put_failure; + err = nla_put_u8(req->msg, DEVLINK_ATTR_INFO_VERSION_IS_FLASH_UPDATE_DEFAULT, + version_type == DEVLINK_INFO_VERSION_TYPE_FLASH_UPDATE_DEFAULT); + if (err) + goto nla_put_failure; + nla_nest_end(req->msg, nest); return 0;