Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4744354pjb; Mon, 27 Jul 2020 04:09:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysEPDTnYzyd/Bff/C1842iulqlqgpNO5L2A2KNh/3i0Bt/kav+Ejx+V4DKCTVUDGXIPYGy X-Received: by 2002:a50:f10c:: with SMTP id w12mr18007363edl.202.1595848181458; Mon, 27 Jul 2020 04:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595848181; cv=none; d=google.com; s=arc-20160816; b=K1LlcPtdI6z0Bh2SApkBYajGp3LGJYIjqtXqNbnvkot+HnnQxXcUH0OvAsm4NsF5Vh rpxxhfG1ie/0lY6drI/EuyOssLA87Qwo/gC0B9CPGU2VVW/zFAqfKlLz1mF0SY6qVPgl X6rtpdS+x9VlTpAHUAEhIaUvQ27RdJ8HpaqrzJznzuLl4zp1HvHvVNNiFvWd7Ylpp8/+ P4xaBeTuAaLQBQUMGh7H9b510Tstvtxi+7RRHVQmWY94AoWlr1cgKbmvNCrkbJA2wGWR LL26G7GOguMHb31IiS6+0vKCj/N5jzG8fPPHeo8+lfCUy66hOksYUjYe6H2/gFJPbyRd myAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=fp/F1AtqApcqINzZ594n+XCu7JYGhy/qzJg+zYnSLOY=; b=LPPF2bVQ5fQokKQ0O+BVAd1fqfiEHD/U+7NYmBogRfbYj0ed84ugBdS17Jg9miN3V/ NHy+cisBNFywMeZwpsIBJEVDotNFQRozCLoU8sjD7YzmOGbybvU9LZA8752n1koZ7YOu r2q9DOJ2gz7+dtyctC7+7zYAnJM4eclp5NwDdrSgmD/s6Faw5KKg6o+vRnAkwyuynPpt Jlet5btgEptGE1xWqf4bSwrIkhuO2anCQkMvBmeXCD49AGMTw8K4Mtk4PJnpkI2hA7y1 h+8MQbu9vpVLj4Lvv4Y0ytGfH3EynWehRyHTnU7KsqRn2p6ZyEYddYP/OK3T8FhdX3e9 JCEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt18si108888edb.340.2020.07.27.04.09.18; Mon, 27 Jul 2020 04:09:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728697AbgG0LHw (ORCPT + 99 others); Mon, 27 Jul 2020 07:07:52 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:40695 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728115AbgG0LGR (ORCPT ); Mon, 27 Jul 2020 07:06:17 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with SMTP; 27 Jul 2020 14:06:12 +0300 Received: from dev-l-vrt-135.mtl.labs.mlnx (dev-l-vrt-135.mtl.labs.mlnx [10.234.135.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 06RB6Bn5022176; Mon, 27 Jul 2020 14:06:11 +0300 Received: from dev-l-vrt-135.mtl.labs.mlnx (localhost [127.0.0.1]) by dev-l-vrt-135.mtl.labs.mlnx (8.15.2/8.15.2/Debian-10) with ESMTP id 06RB6BIK002386; Mon, 27 Jul 2020 14:06:11 +0300 Received: (from moshe@localhost) by dev-l-vrt-135.mtl.labs.mlnx (8.15.2/8.15.2/Submit) id 06RB6B3W002385; Mon, 27 Jul 2020 14:06:11 +0300 From: Moshe Shemesh To: "David S. Miller" , Jiri Pirko , Vasundhara Volam Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Moshe Shemesh Subject: [PATCH net-next RFC 02/13] devlink: Add reload levels data to dev get Date: Mon, 27 Jul 2020 14:02:22 +0300 Message-Id: <1595847753-2234-3-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1595847753-2234-1-git-send-email-moshe@mellanox.com> References: <1595847753-2234-1-git-send-email-moshe@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Expose devlink reload supported levels and driver's default level to the user through devlink dev get command. Examples: $ devlink dev show pci/0000:82:00.0: reload_levels_info: default_level driver supported_levels: driver fw_reset fw_live_patch pci/0000:82:00.1: reload_levels_info: default_level driver supported_levels: driver fw_reset fw_live_patch $ devlink dev show -jp { "dev": { "pci/0000:82:00.0": { "reload_levels_info": { "default_level": "driver", "supported_levels": [ "driver","fw_reset","fw_live_patch" ] } }, "pci/0000:82:00.1": { "reload_levels_info": { "default_level": "driver", "supported_levels": [ "driver","fw_reset","fw_live_patch" ] } } } } Signed-off-by: Moshe Shemesh --- include/uapi/linux/devlink.h | 3 +++ net/core/devlink.c | 38 +++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index fa5f66db5012..249e921ff106 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -476,6 +476,9 @@ enum devlink_attr { DEVLINK_ATTR_PORT_SPLITTABLE, /* u8 */ DEVLINK_ATTR_RELOAD_LEVEL, /* u8 */ + DEVLINK_ATTR_RELOAD_DEFAULT_LEVEL, /* u8 */ + DEVLINK_ATTR_RELOAD_SUPPORTED_LEVELS, /* nested */ + DEVLINK_ATTR_RELOAD_LEVELS_INFO, /* nested */ /* add new attributes above here, update the policy in devlink.c */ diff --git a/net/core/devlink.c b/net/core/devlink.c index 31b367a1612d..f1812fc620d4 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -462,6 +462,11 @@ static int devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink) return 0; } +static bool devlink_reload_supported(struct devlink *devlink) +{ + return devlink->ops->reload_down && devlink->ops->reload_up; +} + static bool devlink_reload_level_is_supported(struct devlink *devlink, enum devlink_reload_level level) { @@ -472,7 +477,9 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink, enum devlink_command cmd, u32 portid, u32 seq, int flags) { + struct nlattr *reload_levels_info, *supported_levels; void *hdr; + int i; hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd); if (!hdr) @@ -483,9 +490,35 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink, if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_FAILED, devlink->reload_failed)) goto nla_put_failure; + if (devlink_reload_supported(devlink)) { + reload_levels_info = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_LEVELS_INFO); + if (!reload_levels_info) + goto nla_put_failure; + if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_DEFAULT_LEVEL, + devlink->ops->default_reload_level)) + goto reload_levels_info_nest_cancel; + + supported_levels = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_SUPPORTED_LEVELS); + if (!supported_levels) + goto reload_levels_info_nest_cancel; + + for (i = 0; i <= DEVLINK_RELOAD_LEVEL_MAX; i++) { + if (!devlink_reload_level_is_supported(devlink, i)) + continue; + if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_LEVEL, i)) + goto supported_levels_nest_cancel; + } + nla_nest_end(msg, supported_levels); + nla_nest_end(msg, reload_levels_info); + } + genlmsg_end(msg, hdr); return 0; +supported_levels_nest_cancel: + nla_nest_cancel(msg, supported_levels); +reload_levels_info_nest_cancel: + nla_nest_cancel(msg, reload_levels_info); nla_put_failure: genlmsg_cancel(msg, hdr); return -EMSGSIZE; @@ -2943,11 +2976,6 @@ static void devlink_reload_netns_change(struct devlink *devlink, DEVLINK_CMD_PARAM_NEW); } -static bool devlink_reload_supported(const struct devlink *devlink) -{ - return devlink->ops->reload_down && devlink->ops->reload_up; -} - static void devlink_reload_failed_set(struct devlink *devlink, bool reload_failed) { -- 2.17.1