From patchwork Wed Aug 24 12:20:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12953364 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 DE112C00140 for ; Wed, 24 Aug 2022 12:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236696AbiHXMUS (ORCPT ); Wed, 24 Aug 2022 08:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234115AbiHXMUR (ORCPT ); Wed, 24 Aug 2022 08:20:17 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B94A51DA63 for ; Wed, 24 Aug 2022 05:20:15 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id q2so19671965edb.6 for ; Wed, 24 Aug 2022 05:20:15 -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=IbLQ2Yws+qV/E/TgSaYdSHADvbVeAsBq0GTLvE9fLfY=; b=izzxavC6rIJ2PoYDyoprVqqCSvkJ60UPNN2AQ35qKHH+F+uuOjdc7T1gh3I7Fg3qxk rWEMWpoAfQ4a1y9ScJTk/zWhGY3mF9T6sKdNEqe+c11qJzSs4S+AZjF+PbzvNyvnR9AJ ypC57XoinuzCDzcmnP/VHG6O/M2YwCecOpAWH7tY7V2U8lxU06wCzLOAsZfgl3NFED5g mXcRWPKxIJyGyLpkAt8JUjM14QOwCHNra5JawohppiZ3u8jpwhbD6xh74F/WUhpNcspG 1nRSfDbVMu1OTElfVVJfjcMv4XzXt5kPGV0SkIpIYzh80bOAtrx1P6F21f0VwQrgD9BU rQSg== 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=IbLQ2Yws+qV/E/TgSaYdSHADvbVeAsBq0GTLvE9fLfY=; b=Mnxf8d4k0AUMkSqWemZbO/nsjrIEe5twb8dEatatVXxnwxFtFJiBjhOw1UYUN73Sxk pN6ymynucxSvhOuo1JNKmI9hl3bu2eNeJzot5odt0xLbVnqB46YcH9y2AEUNp2jMQoaL N9ej/zkavhAxWR6StoKvc2388GLS2q3CcjkshkoY7XN/f/B7Yu9GqsOE+4MF9bYvyrH+ MSWE/SD8rpeWn+khTK21z8EszNaGuGSsyhqA14VmskYzMdJjycqrxVnL4QGMXEsiOHTP bGpggPeghuyDLaTZPnM44RG65wmjNjp8Ex9n2Ecm3duPyGEfBlP7IzSNRSJEDk+sceY5 eheA== X-Gm-Message-State: ACgBeo2ZIhw98TH+q9KzyArRnC2Ah7n2p6gNo41daOyrb0S0y4z8OScB zlid7Pl1Qdk6aPSU4zwczIPLP0ncV7hUL2HE X-Google-Smtp-Source: AA6agR6m9C9e1N3OcWoTDk4a43c7EMyoOkellRZBCYAcckN8J4HKw4qk5ZPZJndogkINdnzEZ7DzNg== X-Received: by 2002:aa7:c9c2:0:b0:440:b458:9403 with SMTP id i2-20020aa7c9c2000000b00440b4589403mr7456962edt.132.1661343614345; Wed, 24 Aug 2022 05:20:14 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id o24-20020a170906769800b0073d89c167a1sm1093728ejm.137.2022.08.24.05.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 05:20:13 -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 v3 1/3] net: devlink: extend info_get() version put to indicate a flash component Date: Wed, 24 Aug 2022 14:20:09 +0200 Message-Id: <20220824122011.1204330-2-jiri@resnulli.us> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220824122011.1204330-1-jiri@resnulli.us> References: <20220824122011.1204330-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 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/stored_put_ext() that allows to specify a version type that indicates when particular version name represents a flash component. This is going to be used in follow-up patch calling info_get() during flash update command checking if version with this the version type exists. Signed-off-by: Jiri Pirko --- v2->v3: - added "stored" variant v1->v2: - split from v1 patch "net: devlink: extend info_get() version put to indicate a flash component", no code changes --- include/net/devlink.h | 16 ++++++++++++++++ net/core/devlink.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 119ed1ffb988..f50a002e5023 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1714,15 +1714,31 @@ 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); int devlink_info_version_stored_put(struct devlink_info_req *req, const char *version_name, const char *version_value); +int devlink_info_version_stored_put_ext(struct devlink_info_req *req, + const char *version_name, + const char *version_value, + enum devlink_info_version_type version_type); 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..43c75b5ac039 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -6579,7 +6579,8 @@ 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; @@ -6612,7 +6613,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,19 +6623,43 @@ 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); +int devlink_info_version_stored_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_STORED, + version_name, version_value, + version_type); +} +EXPORT_SYMBOL_GPL(devlink_info_version_stored_put_ext); + int devlink_info_version_running_put(struct devlink_info_req *req, const char *version_name, 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, From patchwork Wed Aug 24 12:20:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12953366 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 D2268C32796 for ; Wed, 24 Aug 2022 12:20:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237231AbiHXMUW (ORCPT ); Wed, 24 Aug 2022 08:20:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237184AbiHXMUS (ORCPT ); Wed, 24 Aug 2022 08:20:18 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36F061EEFA for ; Wed, 24 Aug 2022 05:20:17 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id gt3so20729318ejb.12 for ; Wed, 24 Aug 2022 05:20:17 -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=vQnl5YjRf+KfqredliCAVuQyc46b4bvT5okXrAgMRd4=; b=L0zctd/B6bplcGEpTmj8SjtgBStIO8KXHDF8hLAng40UfX8bkCqSvvsB4x2CbyrcDV TUfJL5oNBaJDhp4FbjAuKyavSNXrZA+IGS03ffIp8uuZAUFdEIJ7TpTWQCfNJOodDCCS C8CGruicSnc58KnSmgb9Hsatx/5oM66ebl5C2mqNKj1Wl1EFFkAmjl3z8WV+DbF3OnNA buAS00LYRzUsYfU2dRXP+5ybvitQBeAYYMckWIEDO2LS/VW5pkfqoseo6VD22HeQg8iM AeVMA+Z3yNrpLIsvFiBbIxXbjZXf3WbEM20yk++7dDcR1H7b7RO12Ad1+rORJWvLKb/O snzw== 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=vQnl5YjRf+KfqredliCAVuQyc46b4bvT5okXrAgMRd4=; b=8PsgwDc8aoxorBedSDG96a/rZ5T5y1G1gUP5M3UF7smjXK3OF+RM3wDJGayrE+hgHF zj4UTiX0C50KMezq8QHxUUBrbUibmyoGtBDDG4DlHclBggTTcfcUatpRuGOMUZ/JP1tx U4tR5dhWqg5HftMvqAyNRc1kUQzux2Jn/8VXr0RT+Pz5Ib2+i8aVQzgVAUSR4QNvjVTG hT9Bqm8rcR2qZt/clsOgY/QAVd9lbvwmtQguXUgKj5KtO6n0/QGNLlcbFTMmO11VSeEZ TGSoFYAxp5FnQYBxd5Fa/b2lvkM/sMyAXhi8U+l3y7Z4/sKubThnjgqqnRXULhenkoSF kWHw== X-Gm-Message-State: ACgBeo0Kg/JYfwh+bbB8RqL/MaOalMWceEFNJ5G2QZmjRMw8Rqs4XD2T /y53aWKO5g/1YPNQraLxhix2jFfDEmo9AgD/ X-Google-Smtp-Source: AA6agR5lDS4rycIO+gyAzZI/Oqh4jNaH60pFRfDoVKIAhqzo7sqEjwWn93XiMhUXFr7SLkSSyxOJRg== X-Received: by 2002:a17:906:844f:b0:73d:56b6:7e3d with SMTP id e15-20020a170906844f00b0073d56b67e3dmr2795930ejy.545.1661343615786; Wed, 24 Aug 2022 05:20:15 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id 7-20020a170906300700b0073d71587fe5sm1155990ejz.10.2022.08.24.05.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 05:20:15 -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 v3 2/3] netdevsim: add version fw.mgmt info info_get() and mark as a component Date: Wed, 24 Aug 2022 14:20:10 +0200 Message-Id: <20220824122011.1204330-3-jiri@resnulli.us> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220824122011.1204330-1-jiri@resnulli.us> References: <20220824122011.1204330-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 Fix the only component user which is netdevsim. It uses component named "fw.mgmt" in selftests. So add this version to info_get() output with version type component. Signed-off-by: Jiri Pirko --- v2->v3: - added "stored" version v1->v2: - split from v1 patch "net: devlink: extend info_get() version put to indicate a flash component", no code changes --- drivers/net/netdevsim/dev.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index e88f783c297e..d6938faf6c8b 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -984,7 +984,17 @@ 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; + err = devlink_info_version_stored_put_ext(req, "fw.mgmt", "10.20.30", + DEVLINK_INFO_VERSION_TYPE_COMPONENT); + 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 From patchwork Wed Aug 24 12:20:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12953367 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 6B158C00140 for ; Wed, 24 Aug 2022 12:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237247AbiHXMUY (ORCPT ); Wed, 24 Aug 2022 08:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237265AbiHXMUU (ORCPT ); Wed, 24 Aug 2022 08:20:20 -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 D6A4420192 for ; Wed, 24 Aug 2022 05:20:18 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id z2so21816642edc.1 for ; Wed, 24 Aug 2022 05:20:18 -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=pgAeCgBhf5FJxHVnUiKHAxpN4juqeLh6EFvDB0D0zkQ=; b=w9lTw14pXJw3XdnDhjQr/xY06UhqDLug8upRpgyE588Svwgnv4Q7nhi1W7Xtv9dSxa EVwUW6sLXUyOAfNcsFDdbFrR6lzzyzHUgdeF0t0GY/2hmmcII9emDcVuBnfQuOMiIA23 r4mK+cXMana7t6B4dOrQFhNpn2izfAkbFjHVR+bJ4vnFT2+I54okhr+7OLuHbcEFVxx7 iAg2aTrcoYLAO3V+2DReDnrhf7uQKz1eSe3+fJv1ktOf8cPeIAeFNezwiJsxyKXKW8lx gbnZ6fDLd+pDnn9AwtqcCIfXSF2pGhHJhlnuV64L8lFkB1aE1YA5VxM0G3DW0+dWhCJ5 SPhQ== 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=pgAeCgBhf5FJxHVnUiKHAxpN4juqeLh6EFvDB0D0zkQ=; b=AkDztFNf2oQPcJo/YjR6vjP/SzuHUKVOh7eS+1do+QMMubE0d8sJ8051YlmG2V4yA6 b7aKjHXFSUWvQrLVLPYwrXWRkLkrSOPlA6qrkxmgENtnj6YAlAarDjfqWw8VhCjSVT4b gW8fj2QIMObNJPGXU4JRZWV/RgWK3xxkE2kubkEdKV/Bow72fzl8THNa5PM7z+hNpbhh kqY6ez67M2cyc6N2msTjDRIAmS7rmMcIawgwnduDJIsiJiNaL4fWm8hx92nLp3qBTmhK 8eoopbwjWKb7E5uZB6bYNDK5N+cwD8kyhCYawlwYNGI3WcaF6Ie4DiOYr3Jfy821AFx/ 2kew== X-Gm-Message-State: ACgBeo0K//kqsXWjmgIvo1+531sgGNHEF6YxP0jtcBU6d2z2tKwodEtZ s4JEKhhD+RerD0WRL5rplYbm1jpv9ASooxPo X-Google-Smtp-Source: AA6agR47n3tfqeUx2LroyS6vdP9O+M0nlR7xx4zDRuJj7fF9JfIgD0UqZNx0owN9NDqDPvw9K/1LBg== X-Received: by 2002:a05:6402:2b8d:b0:43a:5410:a9fc with SMTP id fj13-20020a0564022b8d00b0043a5410a9fcmr7513070edb.99.1661343617260; Wed, 24 Aug 2022 05:20:17 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id g18-20020a50d5d2000000b0044602e3dcd7sm2995702edj.95.2022.08.24.05.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 05:20:16 -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 v3 3/3] net: devlink: limit flash component name to match version returned by info_get() Date: Wed, 24 Aug 2022 14:20:11 +0200 Message-Id: <20220824122011.1204330-4-jiri@resnulli.us> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220824122011.1204330-1-jiri@resnulli.us> References: <20220824122011.1204330-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. Check VERSION_TYPE_COMPONENT version type 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. Remove "UPDATE_COMPONENT" flag which becomes used. Signed-off-by: Jiri Pirko --- v1->v2: - split from v1 patch "net: devlink: extend info_get() version put to indicate a flash component", no code changes --- drivers/net/netdevsim/dev.c | 3 +- include/net/devlink.h | 3 +- net/core/devlink.c | 105 ++++++++++++++++++++++++++++++------ 3 files changed, 90 insertions(+), 21 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index d6938faf6c8b..efea94c27880 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -1322,8 +1322,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 f50a002e5023..1f7026011856 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; diff --git a/net/core/devlink.c b/net/core/devlink.c index 43c75b5ac039..0f7078db1280 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); } @@ -6585,6 +6649,13 @@ static int devlink_info_version_put(struct devlink_info_req *req, int attr, 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; @@ -6665,7 +6736,7 @@ 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; @@ -12332,8 +12403,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;