Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp699551imm; Wed, 4 Jul 2018 04:32:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdbNv7lXubpdfmXUcU7STslWxHA69zv+mU7Q8M8JhLzGum/NFTk6Q5MZV2KYGU7E9hGDah8 X-Received: by 2002:a65:608b:: with SMTP id t11-v6mr1565193pgu.259.1530703956872; Wed, 04 Jul 2018 04:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530703956; cv=none; d=google.com; s=arc-20160816; b=NH2rgWEJ5daseZFZ2+IMykDUWCrcXRyvFxz1tPdSbHj9m9zET7N4RGQ4zRrtFa+Twi N5QQ03E57EEtQwsnHw6g5z0aA48XHqodpWv6E0KF5Orn7tvKbR+blh1g+iEVnosWQD5K MHcZO/9rXRqsuv/2gh5FheEyq5gEnHmWxRCB1u3nq1ILUkwfptoWQvtXa91Rz3hNhA5K bONPmyq2vTFvLyhlo0AV6c0JrZr/vD93/0FhuGoLUWCOT4OLqEURrYvnaQkauLlBvS3K 7JdKBaQ4o4+GIuId6MmOVsVEaOe6zHuS4GBxIVw6pskw/wJldejs0tmTErqgTsM0yOM5 AZdw== 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:arc-authentication-results; bh=bPgrMm00tuvDbyFvDpF3rLW5JHWHNPM3NuMIZX2O834=; b=k+N0dyfSbPb2qKm4W7SpbDy+usA4nWhWM7ls13vfNXuCdM49yKGoc136dkhQZeP0ch WH8qY/cxV/+avo3NlFrV3MdU9NlUL9WQ/HgSb/yu8smnofjk/iL/W1Umgx0rvqIT76oV mdjkPRwpNydi8fddANVLnluxPUWJAmbCagKHBJj5gxfWtUUvl4u37XoBjCHdQKXheMjN snpvtO1W4BLGXUFy7JCs1SA87AxDx1n9RZ50o2dzrrsKg+4DGbg8JW0w3yIOTTaOSGQp Y4KN7l6WgWgHDufIQNlxRKEy2iMBU/QaoGHpxjix4nK0aGvXLELaKtE2H+XDBqeXGIJ+ g+qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 7-v6si3348866plc.179.2018.07.04.04.32.20; Wed, 04 Jul 2018 04:32:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S934244AbeGDLb0 (ORCPT + 99 others); Wed, 4 Jul 2018 07:31:26 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:46016 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933596AbeGDLbX (ORCPT ); Wed, 4 Jul 2018 07:31:23 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with ESMTPS (AES256-SHA encrypted); 4 Jul 2018 14:34:06 +0300 Received: from dev-l-vrt-136.mtl.labs.mlnx (dev-l-vrt-136.mtl.labs.mlnx [10.134.136.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w64BVHsb031345; Wed, 4 Jul 2018 14:31:17 +0300 Received: from dev-l-vrt-136.mtl.labs.mlnx (localhost [127.0.0.1]) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7) with ESMTP id w64BVH3m024642; Wed, 4 Jul 2018 14:31:17 +0300 Received: (from moshe@localhost) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7/Submit) id w64BVG9S024641; Wed, 4 Jul 2018 14:31:16 +0300 From: Moshe Shemesh To: "David S. Miller" Cc: Vasundhara Volam , Jiri Pirko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Moshe Shemesh Subject: [PATCH net-next 04/10] devlink: Add support for get/set driverinit value Date: Wed, 4 Jul 2018 14:30:31 +0300 Message-Id: <1530703837-24563-5-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1530703837-24563-1-git-send-email-moshe@mellanox.com> References: <1530703837-24563-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 "driverinit" configuration mode value is held by devlink to enable the driver query the value after reload. Two additional functions added to help the driver get/set the value from/to devlink: devlink_param_driverinit_value_set() and devlink_param_driverinit_value_get(). Signed-off-by: Moshe Shemesh Signed-off-by: Jiri Pirko --- include/net/devlink.h | 18 ++++++++++++ net/core/devlink.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index 8806275..3302e43 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -503,6 +503,10 @@ int devlink_params_register(struct devlink *devlink, void devlink_params_unregister(struct devlink *devlink, const struct devlink_param *params, size_t params_count); +int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, + union devlink_param_value *init_val); +int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, + union devlink_param_value init_val); #else @@ -711,6 +715,20 @@ static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, } +static inline int +devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, + union devlink_param_value *init_val) +{ + return -EOPNOTSUPP; +} + +static inline int +devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, + union devlink_param_value init_val) +{ + return -EOPNOTSUPP; +} + #endif #endif /* _NET_DEVLINK_H_ */ diff --git a/net/core/devlink.c b/net/core/devlink.c index 0cd7a42..3af08f4 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -2645,6 +2645,17 @@ static int devlink_param_driver_verify(const struct devlink_param *param) return NULL; } +static struct devlink_param_item * +devlink_param_find_by_id(struct list_head *param_list, u32 param_id) +{ + struct devlink_param_item *param_item; + + list_for_each_entry(param_item, param_list, list) + if (param_item->param->id == param_id) + return param_item; + return NULL; +} + static bool devlink_param_cmode_is_supported(const struct devlink_param *param, enum devlink_param_cmode cmode) @@ -3966,6 +3977,72 @@ void devlink_params_unregister(struct devlink *devlink, } EXPORT_SYMBOL_GPL(devlink_params_unregister); +/** + * devlink_param_driverinit_value_get - get configuration parameter + * value for driver initializing + * + * @devlink: devlink + * @param_id: parameter ID + * @init_val: value of parameter in driverinit configuration mode + * + * This function should be used by the driver to get driverinit + * configuration for initialization after reload command. + */ +int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, + union devlink_param_value *init_val) +{ + struct devlink_param_item *param_item; + + if (!devlink->ops || !devlink->ops->reload) + return -EOPNOTSUPP; + + param_item = devlink_param_find_by_id(&devlink->param_list, param_id); + if (!param_item) + return -EINVAL; + + if (!param_item->driverinit_value_valid || + !devlink_param_cmode_is_supported(param_item->param, + DEVLINK_PARAM_CMODE_DRIVERINIT)) + return -EOPNOTSUPP; + + *init_val = param_item->driverinit_value; + + return 0; +} +EXPORT_SYMBOL_GPL(devlink_param_driverinit_value_get); + +/** + * devlink_param_driverinit_value_set - set value of configuration + * parameter for driverinit + * configuration mode + * + * @devlink: devlink + * @param_id: parameter ID + * @init_val: value of parameter to set for driverinit configuration mode + * + * This function should be used by the driver to set driverinit + * configuration mode default value. + */ +int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, + union devlink_param_value init_val) +{ + struct devlink_param_item *param_item; + + param_item = devlink_param_find_by_id(&devlink->param_list, param_id); + if (!param_item) + return -EINVAL; + + if (!devlink_param_cmode_is_supported(param_item->param, + DEVLINK_PARAM_CMODE_DRIVERINIT)) + return -EOPNOTSUPP; + + param_item->driverinit_value = init_val; + param_item->driverinit_value_valid = true; + + return 0; +} +EXPORT_SYMBOL_GPL(devlink_param_driverinit_value_set); + static int __init devlink_module_init(void) { return genl_register_family(&devlink_nl_family); -- 1.8.3.1